]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.4.4-201207080925.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.4.4-201207080925.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 058320d..817f7ad 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 a69245b..6d145f4 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 340ee49..4238ced 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 effff47..bbb8295 100644
11298 --- a/arch/x86/include/asm/pgtable-3level.h
11299 +++ b/arch/x86/include/asm/pgtable-3level.h
11300 @@ -31,6 +31,56 @@ static inline void native_set_pte(pte_t *ptep, pte_t pte)
11301 ptep->pte_low = pte.pte_low;
11302 }
11303
11304 +#define __HAVE_ARCH_READ_PMD_ATOMIC
11305 +/*
11306 + * pte_offset_map_lock on 32bit PAE kernels was reading the pmd_t with
11307 + * a "*pmdp" dereference done by gcc. Problem is, in certain places
11308 + * where pte_offset_map_lock is called, concurrent page faults are
11309 + * allowed, if the mmap_sem is hold for reading. An example is mincore
11310 + * vs page faults vs MADV_DONTNEED. On the page fault side
11311 + * pmd_populate rightfully does a set_64bit, but if we're reading the
11312 + * pmd_t with a "*pmdp" on the mincore side, a SMP race can happen
11313 + * because gcc will not read the 64bit of the pmd atomically. To fix
11314 + * this all places running pmd_offset_map_lock() while holding the
11315 + * mmap_sem in read mode, shall read the pmdp pointer using this
11316 + * function to know if the pmd is null nor not, and in turn to know if
11317 + * they can run pmd_offset_map_lock or pmd_trans_huge or other pmd
11318 + * operations.
11319 + *
11320 + * Without THP if the mmap_sem is hold for reading, the
11321 + * pmd can only transition from null to not null while read_pmd_atomic runs.
11322 + * So there's no need of literally reading it atomically.
11323 + *
11324 + * With THP if the mmap_sem is hold for reading, the pmd can become
11325 + * THP or null or point to a pte (and in turn become "stable") at any
11326 + * time under read_pmd_atomic, so it's mandatory to read it atomically
11327 + * with cmpxchg8b.
11328 + */
11329 +#ifndef CONFIG_TRANSPARENT_HUGEPAGE
11330 +static inline pmd_t read_pmd_atomic(pmd_t *pmdp)
11331 +{
11332 + pmdval_t ret;
11333 + u32 *tmp = (u32 *)pmdp;
11334 +
11335 + ret = (pmdval_t) (*tmp);
11336 + if (ret) {
11337 + /*
11338 + * If the low part is null, we must not read the high part
11339 + * or we can end up with a partial pmd.
11340 + */
11341 + smp_rmb();
11342 + ret |= ((pmdval_t)*(tmp + 1)) << 32;
11343 + }
11344 +
11345 + return __pmd(ret);
11346 +}
11347 +#else /* CONFIG_TRANSPARENT_HUGEPAGE */
11348 +static inline pmd_t read_pmd_atomic(pmd_t *pmdp)
11349 +{
11350 + return __pmd(atomic64_read((atomic64_t *)pmdp));
11351 +}
11352 +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
11353 +
11354 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11355 {
11356 set_64bit((unsigned long long *)(ptep), native_pte_val(pte));
11357 @@ -38,12 +88,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11358
11359 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11360 {
11361 + pax_open_kernel();
11362 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11363 + pax_close_kernel();
11364 }
11365
11366 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11367 {
11368 + pax_open_kernel();
11369 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11370 + pax_close_kernel();
11371 }
11372
11373 /*
11374 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11375 index 49afb3f..91a8c63 100644
11376 --- a/arch/x86/include/asm/pgtable.h
11377 +++ b/arch/x86/include/asm/pgtable.h
11378 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11379
11380 #ifndef __PAGETABLE_PUD_FOLDED
11381 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11382 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11383 #define pgd_clear(pgd) native_pgd_clear(pgd)
11384 #endif
11385
11386 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11387
11388 #define arch_end_context_switch(prev) do {} while(0)
11389
11390 +#define pax_open_kernel() native_pax_open_kernel()
11391 +#define pax_close_kernel() native_pax_close_kernel()
11392 #endif /* CONFIG_PARAVIRT */
11393
11394 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
11395 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11396 +
11397 +#ifdef CONFIG_PAX_KERNEXEC
11398 +static inline unsigned long native_pax_open_kernel(void)
11399 +{
11400 + unsigned long cr0;
11401 +
11402 + preempt_disable();
11403 + barrier();
11404 + cr0 = read_cr0() ^ X86_CR0_WP;
11405 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
11406 + write_cr0(cr0);
11407 + return cr0 ^ X86_CR0_WP;
11408 +}
11409 +
11410 +static inline unsigned long native_pax_close_kernel(void)
11411 +{
11412 + unsigned long cr0;
11413 +
11414 + cr0 = read_cr0() ^ X86_CR0_WP;
11415 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11416 + write_cr0(cr0);
11417 + barrier();
11418 + preempt_enable_no_resched();
11419 + return cr0 ^ X86_CR0_WP;
11420 +}
11421 +#else
11422 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
11423 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
11424 +#endif
11425 +
11426 /*
11427 * The following only work if pte_present() is true.
11428 * Undefined behaviour if not..
11429 */
11430 +static inline int pte_user(pte_t pte)
11431 +{
11432 + return pte_val(pte) & _PAGE_USER;
11433 +}
11434 +
11435 static inline int pte_dirty(pte_t pte)
11436 {
11437 return pte_flags(pte) & _PAGE_DIRTY;
11438 @@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11439 return pte_clear_flags(pte, _PAGE_RW);
11440 }
11441
11442 +static inline pte_t pte_mkread(pte_t pte)
11443 +{
11444 + return __pte(pte_val(pte) | _PAGE_USER);
11445 +}
11446 +
11447 static inline pte_t pte_mkexec(pte_t pte)
11448 {
11449 - return pte_clear_flags(pte, _PAGE_NX);
11450 +#ifdef CONFIG_X86_PAE
11451 + if (__supported_pte_mask & _PAGE_NX)
11452 + return pte_clear_flags(pte, _PAGE_NX);
11453 + else
11454 +#endif
11455 + return pte_set_flags(pte, _PAGE_USER);
11456 +}
11457 +
11458 +static inline pte_t pte_exprotect(pte_t pte)
11459 +{
11460 +#ifdef CONFIG_X86_PAE
11461 + if (__supported_pte_mask & _PAGE_NX)
11462 + return pte_set_flags(pte, _PAGE_NX);
11463 + else
11464 +#endif
11465 + return pte_clear_flags(pte, _PAGE_USER);
11466 }
11467
11468 static inline pte_t pte_mkdirty(pte_t pte)
11469 @@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11470 #endif
11471
11472 #ifndef __ASSEMBLY__
11473 +
11474 +#ifdef CONFIG_PAX_PER_CPU_PGD
11475 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11476 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11477 +{
11478 + return cpu_pgd[cpu];
11479 +}
11480 +#endif
11481 +
11482 #include <linux/mm_types.h>
11483
11484 static inline int pte_none(pte_t pte)
11485 @@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11486
11487 static inline int pgd_bad(pgd_t pgd)
11488 {
11489 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11490 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11491 }
11492
11493 static inline int pgd_none(pgd_t pgd)
11494 @@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
11495 * pgd_offset() returns a (pgd_t *)
11496 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11497 */
11498 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11499 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11500 +
11501 +#ifdef CONFIG_PAX_PER_CPU_PGD
11502 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11503 +#endif
11504 +
11505 /*
11506 * a shortcut which implies the use of the kernel's pgd, instead
11507 * of a process's
11508 @@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
11509 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11510 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11511
11512 +#ifdef CONFIG_X86_32
11513 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11514 +#else
11515 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11516 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11517 +
11518 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11519 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11520 +#else
11521 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11522 +#endif
11523 +
11524 +#endif
11525 +
11526 #ifndef __ASSEMBLY__
11527
11528 extern int direct_gbpages;
11529 @@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11530 * dst and src can be on the same page, but the range must not overlap,
11531 * and must not cross a page boundary.
11532 */
11533 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11534 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11535 {
11536 - memcpy(dst, src, count * sizeof(pgd_t));
11537 + pax_open_kernel();
11538 + while (count--)
11539 + *dst++ = *src++;
11540 + pax_close_kernel();
11541 }
11542
11543 +#ifdef CONFIG_PAX_PER_CPU_PGD
11544 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11545 +#endif
11546 +
11547 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11548 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11549 +#else
11550 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11551 +#endif
11552
11553 #include <asm-generic/pgtable.h>
11554 #endif /* __ASSEMBLY__ */
11555 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11556 index 0c92113..34a77c6 100644
11557 --- a/arch/x86/include/asm/pgtable_32.h
11558 +++ b/arch/x86/include/asm/pgtable_32.h
11559 @@ -25,9 +25,6 @@
11560 struct mm_struct;
11561 struct vm_area_struct;
11562
11563 -extern pgd_t swapper_pg_dir[1024];
11564 -extern pgd_t initial_page_table[1024];
11565 -
11566 static inline void pgtable_cache_init(void) { }
11567 static inline void check_pgt_cache(void) { }
11568 void paging_init(void);
11569 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11570 # include <asm/pgtable-2level.h>
11571 #endif
11572
11573 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11574 +extern pgd_t initial_page_table[PTRS_PER_PGD];
11575 +#ifdef CONFIG_X86_PAE
11576 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11577 +#endif
11578 +
11579 #if defined(CONFIG_HIGHPTE)
11580 #define pte_offset_map(dir, address) \
11581 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11582 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11583 /* Clear a kernel PTE and flush it from the TLB */
11584 #define kpte_clear_flush(ptep, vaddr) \
11585 do { \
11586 + pax_open_kernel(); \
11587 pte_clear(&init_mm, (vaddr), (ptep)); \
11588 + pax_close_kernel(); \
11589 __flush_tlb_one((vaddr)); \
11590 } while (0)
11591
11592 @@ -74,6 +79,9 @@ do { \
11593
11594 #endif /* !__ASSEMBLY__ */
11595
11596 +#define HAVE_ARCH_UNMAPPED_AREA
11597 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11598 +
11599 /*
11600 * kern_addr_valid() is (1) for FLATMEM and (0) for
11601 * SPARSEMEM and DISCONTIGMEM
11602 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11603 index ed5903b..c7fe163 100644
11604 --- a/arch/x86/include/asm/pgtable_32_types.h
11605 +++ b/arch/x86/include/asm/pgtable_32_types.h
11606 @@ -8,7 +8,7 @@
11607 */
11608 #ifdef CONFIG_X86_PAE
11609 # include <asm/pgtable-3level_types.h>
11610 -# define PMD_SIZE (1UL << PMD_SHIFT)
11611 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11612 # define PMD_MASK (~(PMD_SIZE - 1))
11613 #else
11614 # include <asm/pgtable-2level_types.h>
11615 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11616 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11617 #endif
11618
11619 +#ifdef CONFIG_PAX_KERNEXEC
11620 +#ifndef __ASSEMBLY__
11621 +extern unsigned char MODULES_EXEC_VADDR[];
11622 +extern unsigned char MODULES_EXEC_END[];
11623 +#endif
11624 +#include <asm/boot.h>
11625 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11626 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11627 +#else
11628 +#define ktla_ktva(addr) (addr)
11629 +#define ktva_ktla(addr) (addr)
11630 +#endif
11631 +
11632 #define MODULES_VADDR VMALLOC_START
11633 #define MODULES_END VMALLOC_END
11634 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11635 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11636 index 975f709..9f779c9 100644
11637 --- a/arch/x86/include/asm/pgtable_64.h
11638 +++ b/arch/x86/include/asm/pgtable_64.h
11639 @@ -16,10 +16,14 @@
11640
11641 extern pud_t level3_kernel_pgt[512];
11642 extern pud_t level3_ident_pgt[512];
11643 +extern pud_t level3_vmalloc_start_pgt[512];
11644 +extern pud_t level3_vmalloc_end_pgt[512];
11645 +extern pud_t level3_vmemmap_pgt[512];
11646 +extern pud_t level2_vmemmap_pgt[512];
11647 extern pmd_t level2_kernel_pgt[512];
11648 extern pmd_t level2_fixmap_pgt[512];
11649 -extern pmd_t level2_ident_pgt[512];
11650 -extern pgd_t init_level4_pgt[];
11651 +extern pmd_t level2_ident_pgt[512*2];
11652 +extern pgd_t init_level4_pgt[512];
11653
11654 #define swapper_pg_dir init_level4_pgt
11655
11656 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11657
11658 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11659 {
11660 + pax_open_kernel();
11661 *pmdp = pmd;
11662 + pax_close_kernel();
11663 }
11664
11665 static inline void native_pmd_clear(pmd_t *pmd)
11666 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11667
11668 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11669 {
11670 + pax_open_kernel();
11671 *pudp = pud;
11672 + pax_close_kernel();
11673 }
11674
11675 static inline void native_pud_clear(pud_t *pud)
11676 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11677
11678 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11679 {
11680 + pax_open_kernel();
11681 + *pgdp = pgd;
11682 + pax_close_kernel();
11683 +}
11684 +
11685 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11686 +{
11687 *pgdp = pgd;
11688 }
11689
11690 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11691 index 766ea16..5b96cb3 100644
11692 --- a/arch/x86/include/asm/pgtable_64_types.h
11693 +++ b/arch/x86/include/asm/pgtable_64_types.h
11694 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11695 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11696 #define MODULES_END _AC(0xffffffffff000000, UL)
11697 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11698 +#define MODULES_EXEC_VADDR MODULES_VADDR
11699 +#define MODULES_EXEC_END MODULES_END
11700 +
11701 +#define ktla_ktva(addr) (addr)
11702 +#define ktva_ktla(addr) (addr)
11703
11704 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11705 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11706 index 013286a..8b42f4f 100644
11707 --- a/arch/x86/include/asm/pgtable_types.h
11708 +++ b/arch/x86/include/asm/pgtable_types.h
11709 @@ -16,13 +16,12 @@
11710 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11711 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11712 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11713 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11714 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11715 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11716 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11717 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11718 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11719 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11720 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11721 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11722 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11723 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11724
11725 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11726 @@ -40,7 +39,6 @@
11727 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11728 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11729 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11730 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11731 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11732 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11733 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11734 @@ -57,8 +55,10 @@
11735
11736 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11737 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11738 -#else
11739 +#elif defined(CONFIG_KMEMCHECK)
11740 #define _PAGE_NX (_AT(pteval_t, 0))
11741 +#else
11742 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11743 #endif
11744
11745 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11746 @@ -96,6 +96,9 @@
11747 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11748 _PAGE_ACCESSED)
11749
11750 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
11751 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
11752 +
11753 #define __PAGE_KERNEL_EXEC \
11754 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11755 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11756 @@ -106,7 +109,7 @@
11757 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11758 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11759 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11760 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11761 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11762 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11763 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11764 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11765 @@ -168,8 +171,8 @@
11766 * bits are combined, this will alow user to access the high address mapped
11767 * VDSO in the presence of CONFIG_COMPAT_VDSO
11768 */
11769 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11770 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11771 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11772 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11773 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11774 #endif
11775
11776 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11777 {
11778 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11779 }
11780 +#endif
11781
11782 +#if PAGETABLE_LEVELS == 3
11783 +#include <asm-generic/pgtable-nopud.h>
11784 +#endif
11785 +
11786 +#if PAGETABLE_LEVELS == 2
11787 +#include <asm-generic/pgtable-nopmd.h>
11788 +#endif
11789 +
11790 +#ifndef __ASSEMBLY__
11791 #if PAGETABLE_LEVELS > 3
11792 typedef struct { pudval_t pud; } pud_t;
11793
11794 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11795 return pud.pud;
11796 }
11797 #else
11798 -#include <asm-generic/pgtable-nopud.h>
11799 -
11800 static inline pudval_t native_pud_val(pud_t pud)
11801 {
11802 return native_pgd_val(pud.pgd);
11803 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11804 return pmd.pmd;
11805 }
11806 #else
11807 -#include <asm-generic/pgtable-nopmd.h>
11808 -
11809 static inline pmdval_t native_pmd_val(pmd_t pmd)
11810 {
11811 return native_pgd_val(pmd.pud.pgd);
11812 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11813
11814 extern pteval_t __supported_pte_mask;
11815 extern void set_nx(void);
11816 -extern int nx_enabled;
11817
11818 #define pgprot_writecombine pgprot_writecombine
11819 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11820 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11821 index 4fa7dcc..764e33a 100644
11822 --- a/arch/x86/include/asm/processor.h
11823 +++ b/arch/x86/include/asm/processor.h
11824 @@ -276,7 +276,7 @@ struct tss_struct {
11825
11826 } ____cacheline_aligned;
11827
11828 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11829 +extern struct tss_struct init_tss[NR_CPUS];
11830
11831 /*
11832 * Save the original ist values for checking stack pointers during debugging
11833 @@ -807,11 +807,18 @@ static inline void spin_lock_prefetch(const void *x)
11834 */
11835 #define TASK_SIZE PAGE_OFFSET
11836 #define TASK_SIZE_MAX TASK_SIZE
11837 +
11838 +#ifdef CONFIG_PAX_SEGMEXEC
11839 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11840 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11841 +#else
11842 #define STACK_TOP TASK_SIZE
11843 -#define STACK_TOP_MAX STACK_TOP
11844 +#endif
11845 +
11846 +#define STACK_TOP_MAX TASK_SIZE
11847
11848 #define INIT_THREAD { \
11849 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11850 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11851 .vm86_info = NULL, \
11852 .sysenter_cs = __KERNEL_CS, \
11853 .io_bitmap_ptr = NULL, \
11854 @@ -825,7 +832,7 @@ static inline void spin_lock_prefetch(const void *x)
11855 */
11856 #define INIT_TSS { \
11857 .x86_tss = { \
11858 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11859 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11860 .ss0 = __KERNEL_DS, \
11861 .ss1 = __KERNEL_CS, \
11862 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11863 @@ -836,11 +843,7 @@ static inline void spin_lock_prefetch(const void *x)
11864 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11865
11866 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11867 -#define KSTK_TOP(info) \
11868 -({ \
11869 - unsigned long *__ptr = (unsigned long *)(info); \
11870 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11871 -})
11872 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11873
11874 /*
11875 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11876 @@ -855,7 +858,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11877 #define task_pt_regs(task) \
11878 ({ \
11879 struct pt_regs *__regs__; \
11880 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11881 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11882 __regs__ - 1; \
11883 })
11884
11885 @@ -865,13 +868,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11886 /*
11887 * User space process size. 47bits minus one guard page.
11888 */
11889 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11890 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11891
11892 /* This decides where the kernel will search for a free chunk of vm
11893 * space during mmap's.
11894 */
11895 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11896 - 0xc0000000 : 0xFFFFe000)
11897 + 0xc0000000 : 0xFFFFf000)
11898
11899 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
11900 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11901 @@ -882,11 +885,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11902 #define STACK_TOP_MAX TASK_SIZE_MAX
11903
11904 #define INIT_THREAD { \
11905 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11906 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11907 }
11908
11909 #define INIT_TSS { \
11910 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11911 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11912 }
11913
11914 /*
11915 @@ -914,6 +917,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11916 */
11917 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11918
11919 +#ifdef CONFIG_PAX_SEGMEXEC
11920 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11921 +#endif
11922 +
11923 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11924
11925 /* Get/set a process' ability to use the timestamp counter instruction */
11926 @@ -976,12 +983,12 @@ extern bool cpu_has_amd_erratum(const int *);
11927
11928 void cpu_idle_wait(void);
11929
11930 -extern unsigned long arch_align_stack(unsigned long sp);
11931 +#define arch_align_stack(x) ((x) & ~0xfUL)
11932 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11933
11934 void default_idle(void);
11935 bool set_pm_idle_to_default(void);
11936
11937 -void stop_this_cpu(void *dummy);
11938 +void stop_this_cpu(void *dummy) __noreturn;
11939
11940 #endif /* _ASM_X86_PROCESSOR_H */
11941 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11942 index dcfde52..dbfea06 100644
11943 --- a/arch/x86/include/asm/ptrace.h
11944 +++ b/arch/x86/include/asm/ptrace.h
11945 @@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11946 }
11947
11948 /*
11949 - * user_mode_vm(regs) determines whether a register set came from user mode.
11950 + * user_mode(regs) determines whether a register set came from user mode.
11951 * This is true if V8086 mode was enabled OR if the register set was from
11952 * protected mode with RPL-3 CS value. This tricky test checks that with
11953 * one comparison. Many places in the kernel can bypass this full check
11954 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11955 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11956 + * be used.
11957 */
11958 -static inline int user_mode(struct pt_regs *regs)
11959 +static inline int user_mode_novm(struct pt_regs *regs)
11960 {
11961 #ifdef CONFIG_X86_32
11962 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11963 #else
11964 - return !!(regs->cs & 3);
11965 + return !!(regs->cs & SEGMENT_RPL_MASK);
11966 #endif
11967 }
11968
11969 -static inline int user_mode_vm(struct pt_regs *regs)
11970 +static inline int user_mode(struct pt_regs *regs)
11971 {
11972 #ifdef CONFIG_X86_32
11973 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11974 USER_RPL;
11975 #else
11976 - return user_mode(regs);
11977 + return user_mode_novm(regs);
11978 #endif
11979 }
11980
11981 @@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
11982 #ifdef CONFIG_X86_64
11983 static inline bool user_64bit_mode(struct pt_regs *regs)
11984 {
11985 + unsigned long cs = regs->cs & 0xffff;
11986 #ifndef CONFIG_PARAVIRT
11987 /*
11988 * On non-paravirt systems, this is the only long mode CPL 3
11989 * selector. We do not allow long mode selectors in the LDT.
11990 */
11991 - return regs->cs == __USER_CS;
11992 + return cs == __USER_CS;
11993 #else
11994 /* Headers are too twisted for this to go in paravirt.h. */
11995 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
11996 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
11997 #endif
11998 }
11999 #endif
12000 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
12001 index 92f29706..a79cbbb 100644
12002 --- a/arch/x86/include/asm/reboot.h
12003 +++ b/arch/x86/include/asm/reboot.h
12004 @@ -6,19 +6,19 @@
12005 struct pt_regs;
12006
12007 struct machine_ops {
12008 - void (*restart)(char *cmd);
12009 - void (*halt)(void);
12010 - void (*power_off)(void);
12011 + void (* __noreturn restart)(char *cmd);
12012 + void (* __noreturn halt)(void);
12013 + void (* __noreturn power_off)(void);
12014 void (*shutdown)(void);
12015 void (*crash_shutdown)(struct pt_regs *);
12016 - void (*emergency_restart)(void);
12017 -};
12018 + void (* __noreturn emergency_restart)(void);
12019 +} __no_const;
12020
12021 extern struct machine_ops machine_ops;
12022
12023 void native_machine_crash_shutdown(struct pt_regs *regs);
12024 void native_machine_shutdown(void);
12025 -void machine_real_restart(unsigned int type);
12026 +void machine_real_restart(unsigned int type) __noreturn;
12027 /* These must match dispatch_table in reboot_32.S */
12028 #define MRR_BIOS 0
12029 #define MRR_APM 1
12030 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
12031 index 2dbe4a7..ce1db00 100644
12032 --- a/arch/x86/include/asm/rwsem.h
12033 +++ b/arch/x86/include/asm/rwsem.h
12034 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
12035 {
12036 asm volatile("# beginning down_read\n\t"
12037 LOCK_PREFIX _ASM_INC "(%1)\n\t"
12038 +
12039 +#ifdef CONFIG_PAX_REFCOUNT
12040 + "jno 0f\n"
12041 + LOCK_PREFIX _ASM_DEC "(%1)\n"
12042 + "int $4\n0:\n"
12043 + _ASM_EXTABLE(0b, 0b)
12044 +#endif
12045 +
12046 /* adds 0x00000001 */
12047 " jns 1f\n"
12048 " call call_rwsem_down_read_failed\n"
12049 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
12050 "1:\n\t"
12051 " mov %1,%2\n\t"
12052 " add %3,%2\n\t"
12053 +
12054 +#ifdef CONFIG_PAX_REFCOUNT
12055 + "jno 0f\n"
12056 + "sub %3,%2\n"
12057 + "int $4\n0:\n"
12058 + _ASM_EXTABLE(0b, 0b)
12059 +#endif
12060 +
12061 " jle 2f\n\t"
12062 LOCK_PREFIX " cmpxchg %2,%0\n\t"
12063 " jnz 1b\n\t"
12064 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
12065 long tmp;
12066 asm volatile("# beginning down_write\n\t"
12067 LOCK_PREFIX " xadd %1,(%2)\n\t"
12068 +
12069 +#ifdef CONFIG_PAX_REFCOUNT
12070 + "jno 0f\n"
12071 + "mov %1,(%2)\n"
12072 + "int $4\n0:\n"
12073 + _ASM_EXTABLE(0b, 0b)
12074 +#endif
12075 +
12076 /* adds 0xffff0001, returns the old value */
12077 " test %1,%1\n\t"
12078 /* was the count 0 before? */
12079 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12080 long tmp;
12081 asm volatile("# beginning __up_read\n\t"
12082 LOCK_PREFIX " xadd %1,(%2)\n\t"
12083 +
12084 +#ifdef CONFIG_PAX_REFCOUNT
12085 + "jno 0f\n"
12086 + "mov %1,(%2)\n"
12087 + "int $4\n0:\n"
12088 + _ASM_EXTABLE(0b, 0b)
12089 +#endif
12090 +
12091 /* subtracts 1, returns the old value */
12092 " jns 1f\n\t"
12093 " call call_rwsem_wake\n" /* expects old value in %edx */
12094 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12095 long tmp;
12096 asm volatile("# beginning __up_write\n\t"
12097 LOCK_PREFIX " xadd %1,(%2)\n\t"
12098 +
12099 +#ifdef CONFIG_PAX_REFCOUNT
12100 + "jno 0f\n"
12101 + "mov %1,(%2)\n"
12102 + "int $4\n0:\n"
12103 + _ASM_EXTABLE(0b, 0b)
12104 +#endif
12105 +
12106 /* subtracts 0xffff0001, returns the old value */
12107 " jns 1f\n\t"
12108 " call call_rwsem_wake\n" /* expects old value in %edx */
12109 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12110 {
12111 asm volatile("# beginning __downgrade_write\n\t"
12112 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12113 +
12114 +#ifdef CONFIG_PAX_REFCOUNT
12115 + "jno 0f\n"
12116 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12117 + "int $4\n0:\n"
12118 + _ASM_EXTABLE(0b, 0b)
12119 +#endif
12120 +
12121 /*
12122 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12123 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12124 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12125 */
12126 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12127 {
12128 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12129 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12130 +
12131 +#ifdef CONFIG_PAX_REFCOUNT
12132 + "jno 0f\n"
12133 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
12134 + "int $4\n0:\n"
12135 + _ASM_EXTABLE(0b, 0b)
12136 +#endif
12137 +
12138 : "+m" (sem->count)
12139 : "er" (delta));
12140 }
12141 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12142 */
12143 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12144 {
12145 - return delta + xadd(&sem->count, delta);
12146 + return delta + xadd_check_overflow(&sem->count, delta);
12147 }
12148
12149 #endif /* __KERNEL__ */
12150 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12151 index 1654662..5af4157 100644
12152 --- a/arch/x86/include/asm/segment.h
12153 +++ b/arch/x86/include/asm/segment.h
12154 @@ -64,10 +64,15 @@
12155 * 26 - ESPFIX small SS
12156 * 27 - per-cpu [ offset to per-cpu data area ]
12157 * 28 - stack_canary-20 [ for stack protector ]
12158 - * 29 - unused
12159 - * 30 - unused
12160 + * 29 - PCI BIOS CS
12161 + * 30 - PCI BIOS DS
12162 * 31 - TSS for double fault handler
12163 */
12164 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12165 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12166 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12167 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12168 +
12169 #define GDT_ENTRY_TLS_MIN 6
12170 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12171
12172 @@ -79,6 +84,8 @@
12173
12174 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12175
12176 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12177 +
12178 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12179
12180 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12181 @@ -104,6 +111,12 @@
12182 #define __KERNEL_STACK_CANARY 0
12183 #endif
12184
12185 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12186 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12187 +
12188 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12189 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12190 +
12191 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12192
12193 /*
12194 @@ -141,7 +154,7 @@
12195 */
12196
12197 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12198 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12199 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12200
12201
12202 #else
12203 @@ -165,6 +178,8 @@
12204 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12205 #define __USER32_DS __USER_DS
12206
12207 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12208 +
12209 #define GDT_ENTRY_TSS 8 /* needs two entries */
12210 #define GDT_ENTRY_LDT 10 /* needs two entries */
12211 #define GDT_ENTRY_TLS_MIN 12
12212 @@ -185,6 +200,7 @@
12213 #endif
12214
12215 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12216 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12217 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12218 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12219 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12220 @@ -263,7 +279,7 @@ static inline unsigned long get_limit(unsigned long segment)
12221 {
12222 unsigned long __limit;
12223 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12224 - return __limit + 1;
12225 + return __limit;
12226 }
12227
12228 #endif /* !__ASSEMBLY__ */
12229 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12230 index 0434c40..1714bf0 100644
12231 --- a/arch/x86/include/asm/smp.h
12232 +++ b/arch/x86/include/asm/smp.h
12233 @@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
12234 /* cpus sharing the last level cache: */
12235 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
12236 DECLARE_PER_CPU(u16, cpu_llc_id);
12237 -DECLARE_PER_CPU(int, cpu_number);
12238 +DECLARE_PER_CPU(unsigned int, cpu_number);
12239
12240 static inline struct cpumask *cpu_sibling_mask(int cpu)
12241 {
12242 @@ -77,7 +77,7 @@ struct smp_ops {
12243
12244 void (*send_call_func_ipi)(const struct cpumask *mask);
12245 void (*send_call_func_single_ipi)(int cpu);
12246 -};
12247 +} __no_const;
12248
12249 /* Globals due to paravirt */
12250 extern void set_cpu_sibling_map(int cpu);
12251 @@ -192,14 +192,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12252 extern int safe_smp_processor_id(void);
12253
12254 #elif defined(CONFIG_X86_64_SMP)
12255 -#define raw_smp_processor_id() (percpu_read(cpu_number))
12256 -
12257 -#define stack_smp_processor_id() \
12258 -({ \
12259 - struct thread_info *ti; \
12260 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12261 - ti->cpu; \
12262 -})
12263 +#define raw_smp_processor_id() (percpu_read(cpu_number))
12264 +#define stack_smp_processor_id() raw_smp_processor_id()
12265 #define safe_smp_processor_id() smp_processor_id()
12266
12267 #endif
12268 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12269 index 76bfa2c..12d3fe7 100644
12270 --- a/arch/x86/include/asm/spinlock.h
12271 +++ b/arch/x86/include/asm/spinlock.h
12272 @@ -175,6 +175,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12273 static inline void arch_read_lock(arch_rwlock_t *rw)
12274 {
12275 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12276 +
12277 +#ifdef CONFIG_PAX_REFCOUNT
12278 + "jno 0f\n"
12279 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12280 + "int $4\n0:\n"
12281 + _ASM_EXTABLE(0b, 0b)
12282 +#endif
12283 +
12284 "jns 1f\n"
12285 "call __read_lock_failed\n\t"
12286 "1:\n"
12287 @@ -184,6 +192,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12288 static inline void arch_write_lock(arch_rwlock_t *rw)
12289 {
12290 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12291 +
12292 +#ifdef CONFIG_PAX_REFCOUNT
12293 + "jno 0f\n"
12294 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12295 + "int $4\n0:\n"
12296 + _ASM_EXTABLE(0b, 0b)
12297 +#endif
12298 +
12299 "jz 1f\n"
12300 "call __write_lock_failed\n\t"
12301 "1:\n"
12302 @@ -213,13 +229,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12303
12304 static inline void arch_read_unlock(arch_rwlock_t *rw)
12305 {
12306 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12307 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12308 +
12309 +#ifdef CONFIG_PAX_REFCOUNT
12310 + "jno 0f\n"
12311 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12312 + "int $4\n0:\n"
12313 + _ASM_EXTABLE(0b, 0b)
12314 +#endif
12315 +
12316 :"+m" (rw->lock) : : "memory");
12317 }
12318
12319 static inline void arch_write_unlock(arch_rwlock_t *rw)
12320 {
12321 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12322 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12323 +
12324 +#ifdef CONFIG_PAX_REFCOUNT
12325 + "jno 0f\n"
12326 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12327 + "int $4\n0:\n"
12328 + _ASM_EXTABLE(0b, 0b)
12329 +#endif
12330 +
12331 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12332 }
12333
12334 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12335 index b5d9533..41655fa 100644
12336 --- a/arch/x86/include/asm/stackprotector.h
12337 +++ b/arch/x86/include/asm/stackprotector.h
12338 @@ -47,7 +47,7 @@
12339 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12340 */
12341 #define GDT_STACK_CANARY_INIT \
12342 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12343 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12344
12345 /*
12346 * Initialize the stackprotector canary value.
12347 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12348
12349 static inline void load_stack_canary_segment(void)
12350 {
12351 -#ifdef CONFIG_X86_32
12352 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12353 asm volatile ("mov %0, %%gs" : : "r" (0));
12354 #endif
12355 }
12356 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12357 index 70bbe39..4ae2bd4 100644
12358 --- a/arch/x86/include/asm/stacktrace.h
12359 +++ b/arch/x86/include/asm/stacktrace.h
12360 @@ -11,28 +11,20 @@
12361
12362 extern int kstack_depth_to_print;
12363
12364 -struct thread_info;
12365 +struct task_struct;
12366 struct stacktrace_ops;
12367
12368 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12369 - unsigned long *stack,
12370 - unsigned long bp,
12371 - const struct stacktrace_ops *ops,
12372 - void *data,
12373 - unsigned long *end,
12374 - int *graph);
12375 +typedef unsigned long walk_stack_t(struct task_struct *task,
12376 + void *stack_start,
12377 + unsigned long *stack,
12378 + unsigned long bp,
12379 + const struct stacktrace_ops *ops,
12380 + void *data,
12381 + unsigned long *end,
12382 + int *graph);
12383
12384 -extern unsigned long
12385 -print_context_stack(struct thread_info *tinfo,
12386 - unsigned long *stack, unsigned long bp,
12387 - const struct stacktrace_ops *ops, void *data,
12388 - unsigned long *end, int *graph);
12389 -
12390 -extern unsigned long
12391 -print_context_stack_bp(struct thread_info *tinfo,
12392 - unsigned long *stack, unsigned long bp,
12393 - const struct stacktrace_ops *ops, void *data,
12394 - unsigned long *end, int *graph);
12395 +extern walk_stack_t print_context_stack;
12396 +extern walk_stack_t print_context_stack_bp;
12397
12398 /* Generic stack tracer with callbacks */
12399
12400 @@ -40,7 +32,7 @@ struct stacktrace_ops {
12401 void (*address)(void *data, unsigned long address, int reliable);
12402 /* On negative return stop dumping */
12403 int (*stack)(void *data, char *name);
12404 - walk_stack_t walk_stack;
12405 + walk_stack_t *walk_stack;
12406 };
12407
12408 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12409 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12410 index 4ec45b3..a4f0a8a 100644
12411 --- a/arch/x86/include/asm/switch_to.h
12412 +++ b/arch/x86/include/asm/switch_to.h
12413 @@ -108,7 +108,7 @@ do { \
12414 "call __switch_to\n\t" \
12415 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12416 __switch_canary \
12417 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
12418 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12419 "movq %%rax,%%rdi\n\t" \
12420 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12421 "jnz ret_from_fork\n\t" \
12422 @@ -119,7 +119,7 @@ do { \
12423 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12424 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12425 [_tif_fork] "i" (_TIF_FORK), \
12426 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
12427 + [thread_info] "m" (current_tinfo), \
12428 [current_task] "m" (current_task) \
12429 __switch_canary_iparam \
12430 : "memory", "cc" __EXTRA_CLOBBER)
12431 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12432 index 3fda9db4..4ca1c61 100644
12433 --- a/arch/x86/include/asm/sys_ia32.h
12434 +++ b/arch/x86/include/asm/sys_ia32.h
12435 @@ -40,7 +40,7 @@ asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *,
12436 struct old_sigaction32 __user *);
12437 asmlinkage long sys32_alarm(unsigned int);
12438
12439 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12440 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12441 asmlinkage long sys32_sysfs(int, u32, u32);
12442
12443 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12444 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12445 index ad6df8c..5e0cf6e 100644
12446 --- a/arch/x86/include/asm/thread_info.h
12447 +++ b/arch/x86/include/asm/thread_info.h
12448 @@ -10,6 +10,7 @@
12449 #include <linux/compiler.h>
12450 #include <asm/page.h>
12451 #include <asm/types.h>
12452 +#include <asm/percpu.h>
12453
12454 /*
12455 * low level task data that entry.S needs immediate access to
12456 @@ -24,7 +25,6 @@ struct exec_domain;
12457 #include <linux/atomic.h>
12458
12459 struct thread_info {
12460 - struct task_struct *task; /* main task structure */
12461 struct exec_domain *exec_domain; /* execution domain */
12462 __u32 flags; /* low level flags */
12463 __u32 status; /* thread synchronous flags */
12464 @@ -34,19 +34,13 @@ struct thread_info {
12465 mm_segment_t addr_limit;
12466 struct restart_block restart_block;
12467 void __user *sysenter_return;
12468 -#ifdef CONFIG_X86_32
12469 - unsigned long previous_esp; /* ESP of the previous stack in
12470 - case of nested (IRQ) stacks
12471 - */
12472 - __u8 supervisor_stack[0];
12473 -#endif
12474 + unsigned long lowest_stack;
12475 unsigned int sig_on_uaccess_error:1;
12476 unsigned int uaccess_err:1; /* uaccess failed */
12477 };
12478
12479 -#define INIT_THREAD_INFO(tsk) \
12480 +#define INIT_THREAD_INFO \
12481 { \
12482 - .task = &tsk, \
12483 .exec_domain = &default_exec_domain, \
12484 .flags = 0, \
12485 .cpu = 0, \
12486 @@ -57,7 +51,7 @@ struct thread_info {
12487 }, \
12488 }
12489
12490 -#define init_thread_info (init_thread_union.thread_info)
12491 +#define init_thread_info (init_thread_union.stack)
12492 #define init_stack (init_thread_union.stack)
12493
12494 #else /* !__ASSEMBLY__ */
12495 @@ -97,6 +91,7 @@ struct thread_info {
12496 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12497 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12498 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12499 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12500
12501 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12502 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12503 @@ -120,16 +115,18 @@ struct thread_info {
12504 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12505 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12506 #define _TIF_X32 (1 << TIF_X32)
12507 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12508
12509 /* work to do in syscall_trace_enter() */
12510 #define _TIF_WORK_SYSCALL_ENTRY \
12511 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12512 - _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12513 + _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12514 + _TIF_GRSEC_SETXID)
12515
12516 /* work to do in syscall_trace_leave() */
12517 #define _TIF_WORK_SYSCALL_EXIT \
12518 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12519 - _TIF_SYSCALL_TRACEPOINT)
12520 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12521
12522 /* work to do on interrupt/exception return */
12523 #define _TIF_WORK_MASK \
12524 @@ -139,7 +136,8 @@ struct thread_info {
12525
12526 /* work to do on any return to user space */
12527 #define _TIF_ALLWORK_MASK \
12528 - ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12529 + ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12530 + _TIF_GRSEC_SETXID)
12531
12532 /* Only used for 64 bit */
12533 #define _TIF_DO_NOTIFY_MASK \
12534 @@ -173,45 +171,40 @@ struct thread_info {
12535 ret; \
12536 })
12537
12538 -#ifdef CONFIG_X86_32
12539 -
12540 -#define STACK_WARN (THREAD_SIZE/8)
12541 -/*
12542 - * macros/functions for gaining access to the thread information structure
12543 - *
12544 - * preempt_count needs to be 1 initially, until the scheduler is functional.
12545 - */
12546 -#ifndef __ASSEMBLY__
12547 -
12548 -
12549 -/* how to get the current stack pointer from C */
12550 -register unsigned long current_stack_pointer asm("esp") __used;
12551 -
12552 -/* how to get the thread information struct from C */
12553 -static inline struct thread_info *current_thread_info(void)
12554 -{
12555 - return (struct thread_info *)
12556 - (current_stack_pointer & ~(THREAD_SIZE - 1));
12557 -}
12558 -
12559 -#else /* !__ASSEMBLY__ */
12560 -
12561 +#ifdef __ASSEMBLY__
12562 /* how to get the thread information struct from ASM */
12563 #define GET_THREAD_INFO(reg) \
12564 - movl $-THREAD_SIZE, reg; \
12565 - andl %esp, reg
12566 + mov PER_CPU_VAR(current_tinfo), reg
12567
12568 /* use this one if reg already contains %esp */
12569 -#define GET_THREAD_INFO_WITH_ESP(reg) \
12570 - andl $-THREAD_SIZE, reg
12571 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12572 +#else
12573 +/* how to get the thread information struct from C */
12574 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12575 +
12576 +static __always_inline struct thread_info *current_thread_info(void)
12577 +{
12578 + return percpu_read_stable(current_tinfo);
12579 +}
12580 +#endif
12581 +
12582 +#ifdef CONFIG_X86_32
12583 +
12584 +#define STACK_WARN (THREAD_SIZE/8)
12585 +/*
12586 + * macros/functions for gaining access to the thread information structure
12587 + *
12588 + * preempt_count needs to be 1 initially, until the scheduler is functional.
12589 + */
12590 +#ifndef __ASSEMBLY__
12591 +
12592 +/* how to get the current stack pointer from C */
12593 +register unsigned long current_stack_pointer asm("esp") __used;
12594
12595 #endif
12596
12597 #else /* X86_32 */
12598
12599 -#include <asm/percpu.h>
12600 -#define KERNEL_STACK_OFFSET (5*8)
12601 -
12602 /*
12603 * macros/functions for gaining access to the thread information structure
12604 * preempt_count needs to be 1 initially, until the scheduler is functional.
12605 @@ -219,27 +212,8 @@ static inline struct thread_info *current_thread_info(void)
12606 #ifndef __ASSEMBLY__
12607 DECLARE_PER_CPU(unsigned long, kernel_stack);
12608
12609 -static inline struct thread_info *current_thread_info(void)
12610 -{
12611 - struct thread_info *ti;
12612 - ti = (void *)(percpu_read_stable(kernel_stack) +
12613 - KERNEL_STACK_OFFSET - THREAD_SIZE);
12614 - return ti;
12615 -}
12616 -
12617 -#else /* !__ASSEMBLY__ */
12618 -
12619 -/* how to get the thread information struct from ASM */
12620 -#define GET_THREAD_INFO(reg) \
12621 - movq PER_CPU_VAR(kernel_stack),reg ; \
12622 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12623 -
12624 -/*
12625 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12626 - * a certain register (to be used in assembler memory operands).
12627 - */
12628 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12629 -
12630 +/* how to get the current stack pointer from C */
12631 +register unsigned long current_stack_pointer asm("rsp") __used;
12632 #endif
12633
12634 #endif /* !X86_32 */
12635 @@ -285,5 +259,16 @@ extern void arch_task_cache_init(void);
12636 extern void free_thread_info(struct thread_info *ti);
12637 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12638 #define arch_task_cache_init arch_task_cache_init
12639 +
12640 +#define __HAVE_THREAD_FUNCTIONS
12641 +#define task_thread_info(task) (&(task)->tinfo)
12642 +#define task_stack_page(task) ((task)->stack)
12643 +#define setup_thread_stack(p, org) do {} while (0)
12644 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12645 +
12646 +#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
12647 +extern struct task_struct *alloc_task_struct_node(int node);
12648 +extern void free_task_struct(struct task_struct *);
12649 +
12650 #endif
12651 #endif /* _ASM_X86_THREAD_INFO_H */
12652 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12653 index e054459..14bc8a7 100644
12654 --- a/arch/x86/include/asm/uaccess.h
12655 +++ b/arch/x86/include/asm/uaccess.h
12656 @@ -7,12 +7,15 @@
12657 #include <linux/compiler.h>
12658 #include <linux/thread_info.h>
12659 #include <linux/string.h>
12660 +#include <linux/sched.h>
12661 #include <asm/asm.h>
12662 #include <asm/page.h>
12663
12664 #define VERIFY_READ 0
12665 #define VERIFY_WRITE 1
12666
12667 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12668 +
12669 /*
12670 * The fs value determines whether argument validity checking should be
12671 * performed or not. If get_fs() == USER_DS, checking is performed, with
12672 @@ -28,7 +31,12 @@
12673
12674 #define get_ds() (KERNEL_DS)
12675 #define get_fs() (current_thread_info()->addr_limit)
12676 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12677 +void __set_fs(mm_segment_t x);
12678 +void set_fs(mm_segment_t x);
12679 +#else
12680 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12681 +#endif
12682
12683 #define segment_eq(a, b) ((a).seg == (b).seg)
12684
12685 @@ -76,7 +84,33 @@
12686 * checks that the pointer is in the user space range - after calling
12687 * this function, memory access functions may still return -EFAULT.
12688 */
12689 -#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12690 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12691 +#define access_ok(type, addr, size) \
12692 +({ \
12693 + long __size = size; \
12694 + unsigned long __addr = (unsigned long)addr; \
12695 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12696 + unsigned long __end_ao = __addr + __size - 1; \
12697 + bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
12698 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12699 + while(__addr_ao <= __end_ao) { \
12700 + char __c_ao; \
12701 + __addr_ao += PAGE_SIZE; \
12702 + if (__size > PAGE_SIZE) \
12703 + cond_resched(); \
12704 + if (__get_user(__c_ao, (char __user *)__addr)) \
12705 + break; \
12706 + if (type != VERIFY_WRITE) { \
12707 + __addr = __addr_ao; \
12708 + continue; \
12709 + } \
12710 + if (__put_user(__c_ao, (char __user *)__addr)) \
12711 + break; \
12712 + __addr = __addr_ao; \
12713 + } \
12714 + } \
12715 + __ret_ao; \
12716 +})
12717
12718 /*
12719 * The exception table consists of pairs of addresses: the first is the
12720 @@ -182,12 +216,20 @@ extern int __get_user_bad(void);
12721 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12722 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12723
12724 -
12725 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12726 +#define __copyuser_seg "gs;"
12727 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12728 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12729 +#else
12730 +#define __copyuser_seg
12731 +#define __COPYUSER_SET_ES
12732 +#define __COPYUSER_RESTORE_ES
12733 +#endif
12734
12735 #ifdef CONFIG_X86_32
12736 #define __put_user_asm_u64(x, addr, err, errret) \
12737 - asm volatile("1: movl %%eax,0(%2)\n" \
12738 - "2: movl %%edx,4(%2)\n" \
12739 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12740 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12741 "3:\n" \
12742 ".section .fixup,\"ax\"\n" \
12743 "4: movl %3,%0\n" \
12744 @@ -199,8 +241,8 @@ extern int __get_user_bad(void);
12745 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12746
12747 #define __put_user_asm_ex_u64(x, addr) \
12748 - asm volatile("1: movl %%eax,0(%1)\n" \
12749 - "2: movl %%edx,4(%1)\n" \
12750 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12751 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12752 "3:\n" \
12753 _ASM_EXTABLE(1b, 2b - 1b) \
12754 _ASM_EXTABLE(2b, 3b - 2b) \
12755 @@ -252,7 +294,7 @@ extern void __put_user_8(void);
12756 __typeof__(*(ptr)) __pu_val; \
12757 __chk_user_ptr(ptr); \
12758 might_fault(); \
12759 - __pu_val = x; \
12760 + __pu_val = (x); \
12761 switch (sizeof(*(ptr))) { \
12762 case 1: \
12763 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12764 @@ -373,7 +415,7 @@ do { \
12765 } while (0)
12766
12767 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12768 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12769 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12770 "2:\n" \
12771 ".section .fixup,\"ax\"\n" \
12772 "3: mov %3,%0\n" \
12773 @@ -381,7 +423,7 @@ do { \
12774 " jmp 2b\n" \
12775 ".previous\n" \
12776 _ASM_EXTABLE(1b, 3b) \
12777 - : "=r" (err), ltype(x) \
12778 + : "=r" (err), ltype (x) \
12779 : "m" (__m(addr)), "i" (errret), "0" (err))
12780
12781 #define __get_user_size_ex(x, ptr, size) \
12782 @@ -406,7 +448,7 @@ do { \
12783 } while (0)
12784
12785 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12786 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12787 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12788 "2:\n" \
12789 _ASM_EXTABLE(1b, 2b - 1b) \
12790 : ltype(x) : "m" (__m(addr)))
12791 @@ -423,13 +465,24 @@ do { \
12792 int __gu_err; \
12793 unsigned long __gu_val; \
12794 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12795 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12796 + (x) = (__typeof__(*(ptr)))__gu_val; \
12797 __gu_err; \
12798 })
12799
12800 /* FIXME: this hack is definitely wrong -AK */
12801 struct __large_struct { unsigned long buf[100]; };
12802 -#define __m(x) (*(struct __large_struct __user *)(x))
12803 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12804 +#define ____m(x) \
12805 +({ \
12806 + unsigned long ____x = (unsigned long)(x); \
12807 + if (____x < PAX_USER_SHADOW_BASE) \
12808 + ____x += PAX_USER_SHADOW_BASE; \
12809 + (void __user *)____x; \
12810 +})
12811 +#else
12812 +#define ____m(x) (x)
12813 +#endif
12814 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12815
12816 /*
12817 * Tell gcc we read from memory instead of writing: this is because
12818 @@ -437,7 +490,7 @@ struct __large_struct { unsigned long buf[100]; };
12819 * aliasing issues.
12820 */
12821 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12822 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12823 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12824 "2:\n" \
12825 ".section .fixup,\"ax\"\n" \
12826 "3: mov %3,%0\n" \
12827 @@ -445,10 +498,10 @@ struct __large_struct { unsigned long buf[100]; };
12828 ".previous\n" \
12829 _ASM_EXTABLE(1b, 3b) \
12830 : "=r"(err) \
12831 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12832 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12833
12834 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12835 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12836 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12837 "2:\n" \
12838 _ASM_EXTABLE(1b, 2b - 1b) \
12839 : : ltype(x), "m" (__m(addr)))
12840 @@ -487,8 +540,12 @@ struct __large_struct { unsigned long buf[100]; };
12841 * On error, the variable @x is set to zero.
12842 */
12843
12844 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12845 +#define __get_user(x, ptr) get_user((x), (ptr))
12846 +#else
12847 #define __get_user(x, ptr) \
12848 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12849 +#endif
12850
12851 /**
12852 * __put_user: - Write a simple value into user space, with less checking.
12853 @@ -510,8 +567,12 @@ struct __large_struct { unsigned long buf[100]; };
12854 * Returns zero on success, or -EFAULT on error.
12855 */
12856
12857 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12858 +#define __put_user(x, ptr) put_user((x), (ptr))
12859 +#else
12860 #define __put_user(x, ptr) \
12861 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12862 +#endif
12863
12864 #define __get_user_unaligned __get_user
12865 #define __put_user_unaligned __put_user
12866 @@ -529,7 +590,7 @@ struct __large_struct { unsigned long buf[100]; };
12867 #define get_user_ex(x, ptr) do { \
12868 unsigned long __gue_val; \
12869 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12870 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12871 + (x) = (__typeof__(*(ptr)))__gue_val; \
12872 } while (0)
12873
12874 #ifdef CONFIG_X86_WP_WORKS_OK
12875 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12876 index 8084bc7..3d6ec37 100644
12877 --- a/arch/x86/include/asm/uaccess_32.h
12878 +++ b/arch/x86/include/asm/uaccess_32.h
12879 @@ -11,15 +11,15 @@
12880 #include <asm/page.h>
12881
12882 unsigned long __must_check __copy_to_user_ll
12883 - (void __user *to, const void *from, unsigned long n);
12884 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12885 unsigned long __must_check __copy_from_user_ll
12886 - (void *to, const void __user *from, unsigned long n);
12887 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12888 unsigned long __must_check __copy_from_user_ll_nozero
12889 - (void *to, const void __user *from, unsigned long n);
12890 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12891 unsigned long __must_check __copy_from_user_ll_nocache
12892 - (void *to, const void __user *from, unsigned long n);
12893 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12894 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12895 - (void *to, const void __user *from, unsigned long n);
12896 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12897
12898 /**
12899 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12900 @@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12901 static __always_inline unsigned long __must_check
12902 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12903 {
12904 + if ((long)n < 0)
12905 + return n;
12906 +
12907 if (__builtin_constant_p(n)) {
12908 unsigned long ret;
12909
12910 @@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12911 return ret;
12912 }
12913 }
12914 + if (!__builtin_constant_p(n))
12915 + check_object_size(from, n, true);
12916 return __copy_to_user_ll(to, from, n);
12917 }
12918
12919 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12920 __copy_to_user(void __user *to, const void *from, unsigned long n)
12921 {
12922 might_fault();
12923 +
12924 return __copy_to_user_inatomic(to, from, n);
12925 }
12926
12927 static __always_inline unsigned long
12928 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12929 {
12930 + if ((long)n < 0)
12931 + return n;
12932 +
12933 /* Avoid zeroing the tail if the copy fails..
12934 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12935 * but as the zeroing behaviour is only significant when n is not
12936 @@ -137,6 +146,10 @@ static __always_inline unsigned long
12937 __copy_from_user(void *to, const void __user *from, unsigned long n)
12938 {
12939 might_fault();
12940 +
12941 + if ((long)n < 0)
12942 + return n;
12943 +
12944 if (__builtin_constant_p(n)) {
12945 unsigned long ret;
12946
12947 @@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12948 return ret;
12949 }
12950 }
12951 + if (!__builtin_constant_p(n))
12952 + check_object_size(to, n, false);
12953 return __copy_from_user_ll(to, from, n);
12954 }
12955
12956 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12957 const void __user *from, unsigned long n)
12958 {
12959 might_fault();
12960 +
12961 + if ((long)n < 0)
12962 + return n;
12963 +
12964 if (__builtin_constant_p(n)) {
12965 unsigned long ret;
12966
12967 @@ -181,15 +200,19 @@ static __always_inline unsigned long
12968 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12969 unsigned long n)
12970 {
12971 - return __copy_from_user_ll_nocache_nozero(to, from, n);
12972 + if ((long)n < 0)
12973 + return n;
12974 +
12975 + return __copy_from_user_ll_nocache_nozero(to, from, n);
12976 }
12977
12978 -unsigned long __must_check copy_to_user(void __user *to,
12979 - const void *from, unsigned long n);
12980 -unsigned long __must_check _copy_from_user(void *to,
12981 - const void __user *from,
12982 - unsigned long n);
12983 -
12984 +extern void copy_to_user_overflow(void)
12985 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12986 + __compiletime_error("copy_to_user() buffer size is not provably correct")
12987 +#else
12988 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
12989 +#endif
12990 +;
12991
12992 extern void copy_from_user_overflow(void)
12993 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12994 @@ -199,17 +222,61 @@ extern void copy_from_user_overflow(void)
12995 #endif
12996 ;
12997
12998 -static inline unsigned long __must_check copy_from_user(void *to,
12999 - const void __user *from,
13000 - unsigned long n)
13001 +/**
13002 + * copy_to_user: - Copy a block of data into user space.
13003 + * @to: Destination address, in user space.
13004 + * @from: Source address, in kernel space.
13005 + * @n: Number of bytes to copy.
13006 + *
13007 + * Context: User context only. This function may sleep.
13008 + *
13009 + * Copy data from kernel space to user space.
13010 + *
13011 + * Returns number of bytes that could not be copied.
13012 + * On success, this will be zero.
13013 + */
13014 +static inline unsigned long __must_check
13015 +copy_to_user(void __user *to, const void *from, unsigned long n)
13016 {
13017 - int sz = __compiletime_object_size(to);
13018 + size_t sz = __compiletime_object_size(from);
13019
13020 - if (likely(sz == -1 || sz >= n))
13021 - n = _copy_from_user(to, from, n);
13022 - else
13023 + if (unlikely(sz != (size_t)-1 && sz < n))
13024 + copy_to_user_overflow();
13025 + else if (access_ok(VERIFY_WRITE, to, n))
13026 + n = __copy_to_user(to, from, n);
13027 + return n;
13028 +}
13029 +
13030 +/**
13031 + * copy_from_user: - Copy a block of data from user space.
13032 + * @to: Destination address, in kernel space.
13033 + * @from: Source address, in user space.
13034 + * @n: Number of bytes to copy.
13035 + *
13036 + * Context: User context only. This function may sleep.
13037 + *
13038 + * Copy data from user space to kernel space.
13039 + *
13040 + * Returns number of bytes that could not be copied.
13041 + * On success, this will be zero.
13042 + *
13043 + * If some data could not be copied, this function will pad the copied
13044 + * data to the requested size using zero bytes.
13045 + */
13046 +static inline unsigned long __must_check
13047 +copy_from_user(void *to, const void __user *from, unsigned long n)
13048 +{
13049 + size_t sz = __compiletime_object_size(to);
13050 +
13051 + if (unlikely(sz != (size_t)-1 && sz < n))
13052 copy_from_user_overflow();
13053 -
13054 + else if (access_ok(VERIFY_READ, from, n))
13055 + n = __copy_from_user(to, from, n);
13056 + else if ((long)n > 0) {
13057 + if (!__builtin_constant_p(n))
13058 + check_object_size(to, n, false);
13059 + memset(to, 0, n);
13060 + }
13061 return n;
13062 }
13063
13064 @@ -230,7 +297,7 @@ static inline unsigned long __must_check copy_from_user(void *to,
13065 #define strlen_user(str) strnlen_user(str, LONG_MAX)
13066
13067 long strnlen_user(const char __user *str, long n);
13068 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13069 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13070 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13071 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13072
13073 #endif /* _ASM_X86_UACCESS_32_H */
13074 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
13075 index fcd4b6f..ef04f8f 100644
13076 --- a/arch/x86/include/asm/uaccess_64.h
13077 +++ b/arch/x86/include/asm/uaccess_64.h
13078 @@ -10,6 +10,9 @@
13079 #include <asm/alternative.h>
13080 #include <asm/cpufeature.h>
13081 #include <asm/page.h>
13082 +#include <asm/pgtable.h>
13083 +
13084 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
13085
13086 /*
13087 * Copy To/From Userspace
13088 @@ -17,12 +20,14 @@
13089
13090 /* Handles exceptions in both to and from, but doesn't do access_ok */
13091 __must_check unsigned long
13092 -copy_user_generic_string(void *to, const void *from, unsigned len);
13093 +copy_user_generic_string(void *to, const void *from, unsigned long len) __size_overflow(3);
13094 __must_check unsigned long
13095 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13096 +copy_user_generic_unrolled(void *to, const void *from, unsigned long len) __size_overflow(3);
13097
13098 static __always_inline __must_check unsigned long
13099 -copy_user_generic(void *to, const void *from, unsigned len)
13100 +copy_user_generic(void *to, const void *from, unsigned long len) __size_overflow(3);
13101 +static __always_inline __must_check unsigned long
13102 +copy_user_generic(void *to, const void *from, unsigned long len)
13103 {
13104 unsigned ret;
13105
13106 @@ -32,142 +37,238 @@ copy_user_generic(void *to, const void *from, unsigned len)
13107 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13108 "=d" (len)),
13109 "1" (to), "2" (from), "3" (len)
13110 - : "memory", "rcx", "r8", "r9", "r10", "r11");
13111 + : "memory", "rcx", "r8", "r9", "r11");
13112 return ret;
13113 }
13114
13115 +static __always_inline __must_check unsigned long
13116 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13117 +static __always_inline __must_check unsigned long
13118 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13119 __must_check unsigned long
13120 -_copy_to_user(void __user *to, const void *from, unsigned len);
13121 -__must_check unsigned long
13122 -_copy_from_user(void *to, const void __user *from, unsigned len);
13123 -__must_check unsigned long
13124 -copy_in_user(void __user *to, const void __user *from, unsigned len);
13125 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13126 +
13127 +extern void copy_to_user_overflow(void)
13128 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13129 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13130 +#else
13131 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13132 +#endif
13133 +;
13134 +
13135 +extern void copy_from_user_overflow(void)
13136 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13137 + __compiletime_error("copy_from_user() buffer size is not provably correct")
13138 +#else
13139 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
13140 +#endif
13141 +;
13142
13143 static inline unsigned long __must_check copy_from_user(void *to,
13144 const void __user *from,
13145 unsigned long n)
13146 {
13147 - int sz = __compiletime_object_size(to);
13148 -
13149 might_fault();
13150 - if (likely(sz == -1 || sz >= n))
13151 - n = _copy_from_user(to, from, n);
13152 -#ifdef CONFIG_DEBUG_VM
13153 - else
13154 - WARN(1, "Buffer overflow detected!\n");
13155 -#endif
13156 +
13157 + if (access_ok(VERIFY_READ, from, n))
13158 + n = __copy_from_user(to, from, n);
13159 + else if (n < INT_MAX) {
13160 + if (!__builtin_constant_p(n))
13161 + check_object_size(to, n, false);
13162 + memset(to, 0, n);
13163 + }
13164 return n;
13165 }
13166
13167 static __always_inline __must_check
13168 -int copy_to_user(void __user *dst, const void *src, unsigned size)
13169 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
13170 {
13171 might_fault();
13172
13173 - return _copy_to_user(dst, src, size);
13174 + if (access_ok(VERIFY_WRITE, dst, size))
13175 + size = __copy_to_user(dst, src, size);
13176 + return size;
13177 }
13178
13179 static __always_inline __must_check
13180 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
13181 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13182 {
13183 - int ret = 0;
13184 + size_t sz = __compiletime_object_size(dst);
13185 + unsigned ret = 0;
13186
13187 might_fault();
13188 - if (!__builtin_constant_p(size))
13189 - return copy_user_generic(dst, (__force void *)src, size);
13190 +
13191 + if (size > INT_MAX)
13192 + return size;
13193 +
13194 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13195 + if (!__access_ok(VERIFY_READ, src, size))
13196 + return size;
13197 +#endif
13198 +
13199 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13200 + copy_from_user_overflow();
13201 + return size;
13202 + }
13203 +
13204 + if (!__builtin_constant_p(size)) {
13205 + check_object_size(dst, size, false);
13206 +
13207 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13208 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13209 + src += PAX_USER_SHADOW_BASE;
13210 +#endif
13211 +
13212 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13213 + }
13214 switch (size) {
13215 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13216 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13217 ret, "b", "b", "=q", 1);
13218 return ret;
13219 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13220 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13221 ret, "w", "w", "=r", 2);
13222 return ret;
13223 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13224 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13225 ret, "l", "k", "=r", 4);
13226 return ret;
13227 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13228 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13229 ret, "q", "", "=r", 8);
13230 return ret;
13231 case 10:
13232 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13233 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13234 ret, "q", "", "=r", 10);
13235 if (unlikely(ret))
13236 return ret;
13237 __get_user_asm(*(u16 *)(8 + (char *)dst),
13238 - (u16 __user *)(8 + (char __user *)src),
13239 + (const u16 __user *)(8 + (const char __user *)src),
13240 ret, "w", "w", "=r", 2);
13241 return ret;
13242 case 16:
13243 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13244 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13245 ret, "q", "", "=r", 16);
13246 if (unlikely(ret))
13247 return ret;
13248 __get_user_asm(*(u64 *)(8 + (char *)dst),
13249 - (u64 __user *)(8 + (char __user *)src),
13250 + (const u64 __user *)(8 + (const char __user *)src),
13251 ret, "q", "", "=r", 8);
13252 return ret;
13253 default:
13254 - return copy_user_generic(dst, (__force void *)src, size);
13255 +
13256 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13257 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13258 + src += PAX_USER_SHADOW_BASE;
13259 +#endif
13260 +
13261 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13262 }
13263 }
13264
13265 static __always_inline __must_check
13266 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
13267 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13268 {
13269 - int ret = 0;
13270 + size_t sz = __compiletime_object_size(src);
13271 + unsigned ret = 0;
13272
13273 might_fault();
13274 - if (!__builtin_constant_p(size))
13275 - return copy_user_generic((__force void *)dst, src, size);
13276 +
13277 + if (size > INT_MAX)
13278 + return size;
13279 +
13280 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13281 + if (!__access_ok(VERIFY_WRITE, dst, size))
13282 + return size;
13283 +#endif
13284 +
13285 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13286 + copy_to_user_overflow();
13287 + return size;
13288 + }
13289 +
13290 + if (!__builtin_constant_p(size)) {
13291 + check_object_size(src, size, true);
13292 +
13293 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13294 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13295 + dst += PAX_USER_SHADOW_BASE;
13296 +#endif
13297 +
13298 + return copy_user_generic((__force_kernel void *)dst, src, size);
13299 + }
13300 switch (size) {
13301 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13302 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13303 ret, "b", "b", "iq", 1);
13304 return ret;
13305 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13306 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13307 ret, "w", "w", "ir", 2);
13308 return ret;
13309 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13310 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13311 ret, "l", "k", "ir", 4);
13312 return ret;
13313 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13314 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13315 ret, "q", "", "er", 8);
13316 return ret;
13317 case 10:
13318 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13319 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13320 ret, "q", "", "er", 10);
13321 if (unlikely(ret))
13322 return ret;
13323 asm("":::"memory");
13324 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13325 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13326 ret, "w", "w", "ir", 2);
13327 return ret;
13328 case 16:
13329 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13330 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13331 ret, "q", "", "er", 16);
13332 if (unlikely(ret))
13333 return ret;
13334 asm("":::"memory");
13335 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13336 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13337 ret, "q", "", "er", 8);
13338 return ret;
13339 default:
13340 - return copy_user_generic((__force void *)dst, src, size);
13341 +
13342 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13343 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13344 + dst += PAX_USER_SHADOW_BASE;
13345 +#endif
13346 +
13347 + return copy_user_generic((__force_kernel void *)dst, src, size);
13348 }
13349 }
13350
13351 static __always_inline __must_check
13352 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13353 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13354 {
13355 - int ret = 0;
13356 + unsigned ret = 0;
13357
13358 might_fault();
13359 - if (!__builtin_constant_p(size))
13360 - return copy_user_generic((__force void *)dst,
13361 - (__force void *)src, size);
13362 +
13363 + if (size > INT_MAX)
13364 + return size;
13365 +
13366 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13367 + if (!__access_ok(VERIFY_READ, src, size))
13368 + return size;
13369 + if (!__access_ok(VERIFY_WRITE, dst, size))
13370 + return size;
13371 +#endif
13372 +
13373 + if (!__builtin_constant_p(size)) {
13374 +
13375 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13376 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13377 + src += PAX_USER_SHADOW_BASE;
13378 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13379 + dst += PAX_USER_SHADOW_BASE;
13380 +#endif
13381 +
13382 + return copy_user_generic((__force_kernel void *)dst,
13383 + (__force_kernel const void *)src, size);
13384 + }
13385 switch (size) {
13386 case 1: {
13387 u8 tmp;
13388 - __get_user_asm(tmp, (u8 __user *)src,
13389 + __get_user_asm(tmp, (const u8 __user *)src,
13390 ret, "b", "b", "=q", 1);
13391 if (likely(!ret))
13392 __put_user_asm(tmp, (u8 __user *)dst,
13393 @@ -176,7 +277,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13394 }
13395 case 2: {
13396 u16 tmp;
13397 - __get_user_asm(tmp, (u16 __user *)src,
13398 + __get_user_asm(tmp, (const u16 __user *)src,
13399 ret, "w", "w", "=r", 2);
13400 if (likely(!ret))
13401 __put_user_asm(tmp, (u16 __user *)dst,
13402 @@ -186,7 +287,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13403
13404 case 4: {
13405 u32 tmp;
13406 - __get_user_asm(tmp, (u32 __user *)src,
13407 + __get_user_asm(tmp, (const u32 __user *)src,
13408 ret, "l", "k", "=r", 4);
13409 if (likely(!ret))
13410 __put_user_asm(tmp, (u32 __user *)dst,
13411 @@ -195,7 +296,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13412 }
13413 case 8: {
13414 u64 tmp;
13415 - __get_user_asm(tmp, (u64 __user *)src,
13416 + __get_user_asm(tmp, (const u64 __user *)src,
13417 ret, "q", "", "=r", 8);
13418 if (likely(!ret))
13419 __put_user_asm(tmp, (u64 __user *)dst,
13420 @@ -203,47 +304,92 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13421 return ret;
13422 }
13423 default:
13424 - return copy_user_generic((__force void *)dst,
13425 - (__force void *)src, size);
13426 +
13427 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13428 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13429 + src += PAX_USER_SHADOW_BASE;
13430 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13431 + dst += PAX_USER_SHADOW_BASE;
13432 +#endif
13433 +
13434 + return copy_user_generic((__force_kernel void *)dst,
13435 + (__force_kernel const void *)src, size);
13436 }
13437 }
13438
13439 __must_check long strnlen_user(const char __user *str, long n);
13440 __must_check long __strnlen_user(const char __user *str, long n);
13441 __must_check long strlen_user(const char __user *str);
13442 -__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13443 -__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13444 +__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13445 +__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13446
13447 static __must_check __always_inline int
13448 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13449 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13450 {
13451 - return copy_user_generic(dst, (__force const void *)src, size);
13452 + if (size > INT_MAX)
13453 + return size;
13454 +
13455 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13456 + if (!__access_ok(VERIFY_READ, src, size))
13457 + return size;
13458 +
13459 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13460 + src += PAX_USER_SHADOW_BASE;
13461 +#endif
13462 +
13463 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13464 }
13465
13466 -static __must_check __always_inline int
13467 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13468 +static __must_check __always_inline unsigned long
13469 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13470 {
13471 - return copy_user_generic((__force void *)dst, src, size);
13472 + if (size > INT_MAX)
13473 + return size;
13474 +
13475 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13476 + if (!__access_ok(VERIFY_WRITE, dst, size))
13477 + return size;
13478 +
13479 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13480 + dst += PAX_USER_SHADOW_BASE;
13481 +#endif
13482 +
13483 + return copy_user_generic((__force_kernel void *)dst, src, size);
13484 }
13485
13486 -extern long __copy_user_nocache(void *dst, const void __user *src,
13487 - unsigned size, int zerorest);
13488 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13489 + unsigned long size, int zerorest) __size_overflow(3);
13490
13491 -static inline int
13492 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13493 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13494 {
13495 might_sleep();
13496 +
13497 + if (size > INT_MAX)
13498 + return size;
13499 +
13500 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13501 + if (!__access_ok(VERIFY_READ, src, size))
13502 + return size;
13503 +#endif
13504 +
13505 return __copy_user_nocache(dst, src, size, 1);
13506 }
13507
13508 -static inline int
13509 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13510 - unsigned size)
13511 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13512 + unsigned long size)
13513 {
13514 + if (size > INT_MAX)
13515 + return size;
13516 +
13517 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13518 + if (!__access_ok(VERIFY_READ, src, size))
13519 + return size;
13520 +#endif
13521 +
13522 return __copy_user_nocache(dst, src, size, 0);
13523 }
13524
13525 -unsigned long
13526 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13527 +extern unsigned long
13528 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13529
13530 #endif /* _ASM_X86_UACCESS_64_H */
13531 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13532 index bb05228..d763d5b 100644
13533 --- a/arch/x86/include/asm/vdso.h
13534 +++ b/arch/x86/include/asm/vdso.h
13535 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13536 #define VDSO32_SYMBOL(base, name) \
13537 ({ \
13538 extern const char VDSO32_##name[]; \
13539 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13540 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13541 })
13542 #endif
13543
13544 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13545 index 764b66a..ad3cfc8 100644
13546 --- a/arch/x86/include/asm/x86_init.h
13547 +++ b/arch/x86/include/asm/x86_init.h
13548 @@ -29,7 +29,7 @@ struct x86_init_mpparse {
13549 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13550 void (*find_smp_config)(void);
13551 void (*get_smp_config)(unsigned int early);
13552 -};
13553 +} __no_const;
13554
13555 /**
13556 * struct x86_init_resources - platform specific resource related ops
13557 @@ -43,7 +43,7 @@ struct x86_init_resources {
13558 void (*probe_roms)(void);
13559 void (*reserve_resources)(void);
13560 char *(*memory_setup)(void);
13561 -};
13562 +} __no_const;
13563
13564 /**
13565 * struct x86_init_irqs - platform specific interrupt setup
13566 @@ -56,7 +56,7 @@ struct x86_init_irqs {
13567 void (*pre_vector_init)(void);
13568 void (*intr_init)(void);
13569 void (*trap_init)(void);
13570 -};
13571 +} __no_const;
13572
13573 /**
13574 * struct x86_init_oem - oem platform specific customizing functions
13575 @@ -66,7 +66,7 @@ struct x86_init_irqs {
13576 struct x86_init_oem {
13577 void (*arch_setup)(void);
13578 void (*banner)(void);
13579 -};
13580 +} __no_const;
13581
13582 /**
13583 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13584 @@ -77,7 +77,7 @@ struct x86_init_oem {
13585 */
13586 struct x86_init_mapping {
13587 void (*pagetable_reserve)(u64 start, u64 end);
13588 -};
13589 +} __no_const;
13590
13591 /**
13592 * struct x86_init_paging - platform specific paging functions
13593 @@ -87,7 +87,7 @@ struct x86_init_mapping {
13594 struct x86_init_paging {
13595 void (*pagetable_setup_start)(pgd_t *base);
13596 void (*pagetable_setup_done)(pgd_t *base);
13597 -};
13598 +} __no_const;
13599
13600 /**
13601 * struct x86_init_timers - platform specific timer setup
13602 @@ -102,7 +102,7 @@ struct x86_init_timers {
13603 void (*tsc_pre_init)(void);
13604 void (*timer_init)(void);
13605 void (*wallclock_init)(void);
13606 -};
13607 +} __no_const;
13608
13609 /**
13610 * struct x86_init_iommu - platform specific iommu setup
13611 @@ -110,7 +110,7 @@ struct x86_init_timers {
13612 */
13613 struct x86_init_iommu {
13614 int (*iommu_init)(void);
13615 -};
13616 +} __no_const;
13617
13618 /**
13619 * struct x86_init_pci - platform specific pci init functions
13620 @@ -124,7 +124,7 @@ struct x86_init_pci {
13621 int (*init)(void);
13622 void (*init_irq)(void);
13623 void (*fixup_irqs)(void);
13624 -};
13625 +} __no_const;
13626
13627 /**
13628 * struct x86_init_ops - functions for platform specific setup
13629 @@ -140,7 +140,7 @@ struct x86_init_ops {
13630 struct x86_init_timers timers;
13631 struct x86_init_iommu iommu;
13632 struct x86_init_pci pci;
13633 -};
13634 +} __no_const;
13635
13636 /**
13637 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13638 @@ -151,7 +151,7 @@ struct x86_cpuinit_ops {
13639 void (*setup_percpu_clockev)(void);
13640 void (*early_percpu_clock_init)(void);
13641 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13642 -};
13643 +} __no_const;
13644
13645 /**
13646 * struct x86_platform_ops - platform specific runtime functions
13647 @@ -177,7 +177,7 @@ struct x86_platform_ops {
13648 int (*i8042_detect)(void);
13649 void (*save_sched_clock_state)(void);
13650 void (*restore_sched_clock_state)(void);
13651 -};
13652 +} __no_const;
13653
13654 struct pci_dev;
13655
13656 @@ -186,7 +186,7 @@ struct x86_msi_ops {
13657 void (*teardown_msi_irq)(unsigned int irq);
13658 void (*teardown_msi_irqs)(struct pci_dev *dev);
13659 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13660 -};
13661 +} __no_const;
13662
13663 extern struct x86_init_ops x86_init;
13664 extern struct x86_cpuinit_ops x86_cpuinit;
13665 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13666 index c6ce245..ffbdab7 100644
13667 --- a/arch/x86/include/asm/xsave.h
13668 +++ b/arch/x86/include/asm/xsave.h
13669 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13670 {
13671 int err;
13672
13673 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13674 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13675 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13676 +#endif
13677 +
13678 /*
13679 * Clear the xsave header first, so that reserved fields are
13680 * initialized to zero.
13681 @@ -96,10 +101,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13682 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13683 {
13684 int err;
13685 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13686 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13687 u32 lmask = mask;
13688 u32 hmask = mask >> 32;
13689
13690 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13691 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13692 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13693 +#endif
13694 +
13695 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13696 "2:\n"
13697 ".section .fixup,\"ax\"\n"
13698 diff --git a/arch/x86/kernel/acpi/realmode/Makefile b/arch/x86/kernel/acpi/realmode/Makefile
13699 index 6a564ac..9b1340c 100644
13700 --- a/arch/x86/kernel/acpi/realmode/Makefile
13701 +++ b/arch/x86/kernel/acpi/realmode/Makefile
13702 @@ -41,6 +41,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D_WAKEUP -D__KERNEL__ \
13703 $(call cc-option, -fno-stack-protector) \
13704 $(call cc-option, -mpreferred-stack-boundary=2)
13705 KBUILD_CFLAGS += $(call cc-option, -m32)
13706 +ifdef CONSTIFY_PLUGIN
13707 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
13708 +endif
13709 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13710 GCOV_PROFILE := n
13711
13712 diff --git a/arch/x86/kernel/acpi/realmode/wakeup.S b/arch/x86/kernel/acpi/realmode/wakeup.S
13713 index b4fd836..4358fe3 100644
13714 --- a/arch/x86/kernel/acpi/realmode/wakeup.S
13715 +++ b/arch/x86/kernel/acpi/realmode/wakeup.S
13716 @@ -108,6 +108,9 @@ wakeup_code:
13717 /* Do any other stuff... */
13718
13719 #ifndef CONFIG_64BIT
13720 + /* Recheck NX bit overrides (64bit path does this in trampoline */
13721 + call verify_cpu
13722 +
13723 /* This could also be done in C code... */
13724 movl pmode_cr3, %eax
13725 movl %eax, %cr3
13726 @@ -131,6 +134,7 @@ wakeup_code:
13727 movl pmode_cr0, %eax
13728 movl %eax, %cr0
13729 jmp pmode_return
13730 +# include "../../verify_cpu.S"
13731 #else
13732 pushw $0
13733 pushw trampoline_segment
13734 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13735 index 146a49c..1b5338b 100644
13736 --- a/arch/x86/kernel/acpi/sleep.c
13737 +++ b/arch/x86/kernel/acpi/sleep.c
13738 @@ -98,8 +98,12 @@ int acpi_suspend_lowlevel(void)
13739 header->trampoline_segment = trampoline_address() >> 4;
13740 #ifdef CONFIG_SMP
13741 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13742 +
13743 + pax_open_kernel();
13744 early_gdt_descr.address =
13745 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13746 + pax_close_kernel();
13747 +
13748 initial_gs = per_cpu_offset(smp_processor_id());
13749 #endif
13750 initial_code = (unsigned long)wakeup_long64;
13751 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13752 index 7261083..5c12053 100644
13753 --- a/arch/x86/kernel/acpi/wakeup_32.S
13754 +++ b/arch/x86/kernel/acpi/wakeup_32.S
13755 @@ -30,13 +30,11 @@ wakeup_pmode_return:
13756 # and restore the stack ... but you need gdt for this to work
13757 movl saved_context_esp, %esp
13758
13759 - movl %cs:saved_magic, %eax
13760 - cmpl $0x12345678, %eax
13761 + cmpl $0x12345678, saved_magic
13762 jne bogus_magic
13763
13764 # jump to place where we left off
13765 - movl saved_eip, %eax
13766 - jmp *%eax
13767 + jmp *(saved_eip)
13768
13769 bogus_magic:
13770 jmp bogus_magic
13771 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13772 index 1f84794..e23f862 100644
13773 --- a/arch/x86/kernel/alternative.c
13774 +++ b/arch/x86/kernel/alternative.c
13775 @@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13776 */
13777 for (a = start; a < end; a++) {
13778 instr = (u8 *)&a->instr_offset + a->instr_offset;
13779 +
13780 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13781 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13782 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13783 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13784 +#endif
13785 +
13786 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13787 BUG_ON(a->replacementlen > a->instrlen);
13788 BUG_ON(a->instrlen > sizeof(insnbuf));
13789 @@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13790 for (poff = start; poff < end; poff++) {
13791 u8 *ptr = (u8 *)poff + *poff;
13792
13793 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13794 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13795 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13796 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13797 +#endif
13798 +
13799 if (!*poff || ptr < text || ptr >= text_end)
13800 continue;
13801 /* turn DS segment override prefix into lock prefix */
13802 - if (*ptr == 0x3e)
13803 + if (*ktla_ktva(ptr) == 0x3e)
13804 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13805 };
13806 mutex_unlock(&text_mutex);
13807 @@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13808 for (poff = start; poff < end; poff++) {
13809 u8 *ptr = (u8 *)poff + *poff;
13810
13811 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13812 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13813 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13814 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13815 +#endif
13816 +
13817 if (!*poff || ptr < text || ptr >= text_end)
13818 continue;
13819 /* turn lock prefix into DS segment override prefix */
13820 - if (*ptr == 0xf0)
13821 + if (*ktla_ktva(ptr) == 0xf0)
13822 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13823 };
13824 mutex_unlock(&text_mutex);
13825 @@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13826
13827 BUG_ON(p->len > MAX_PATCH_LEN);
13828 /* prep the buffer with the original instructions */
13829 - memcpy(insnbuf, p->instr, p->len);
13830 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13831 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13832 (unsigned long)p->instr, p->len);
13833
13834 @@ -568,7 +587,7 @@ void __init alternative_instructions(void)
13835 if (smp_alt_once)
13836 free_init_pages("SMP alternatives",
13837 (unsigned long)__smp_locks,
13838 - (unsigned long)__smp_locks_end);
13839 + PAGE_ALIGN((unsigned long)__smp_locks_end));
13840
13841 restart_nmi();
13842 }
13843 @@ -585,13 +604,17 @@ void __init alternative_instructions(void)
13844 * instructions. And on the local CPU you need to be protected again NMI or MCE
13845 * handlers seeing an inconsistent instruction while you patch.
13846 */
13847 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
13848 +void *__kprobes text_poke_early(void *addr, const void *opcode,
13849 size_t len)
13850 {
13851 unsigned long flags;
13852 local_irq_save(flags);
13853 - memcpy(addr, opcode, len);
13854 +
13855 + pax_open_kernel();
13856 + memcpy(ktla_ktva(addr), opcode, len);
13857 sync_core();
13858 + pax_close_kernel();
13859 +
13860 local_irq_restore(flags);
13861 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13862 that causes hangs on some VIA CPUs. */
13863 @@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13864 */
13865 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13866 {
13867 - unsigned long flags;
13868 - char *vaddr;
13869 + unsigned char *vaddr = ktla_ktva(addr);
13870 struct page *pages[2];
13871 - int i;
13872 + size_t i;
13873
13874 if (!core_kernel_text((unsigned long)addr)) {
13875 - pages[0] = vmalloc_to_page(addr);
13876 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13877 + pages[0] = vmalloc_to_page(vaddr);
13878 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13879 } else {
13880 - pages[0] = virt_to_page(addr);
13881 + pages[0] = virt_to_page(vaddr);
13882 WARN_ON(!PageReserved(pages[0]));
13883 - pages[1] = virt_to_page(addr + PAGE_SIZE);
13884 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13885 }
13886 BUG_ON(!pages[0]);
13887 - local_irq_save(flags);
13888 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13889 - if (pages[1])
13890 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13891 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13892 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13893 - clear_fixmap(FIX_TEXT_POKE0);
13894 - if (pages[1])
13895 - clear_fixmap(FIX_TEXT_POKE1);
13896 - local_flush_tlb();
13897 - sync_core();
13898 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
13899 - that causes hangs on some VIA CPUs. */
13900 + text_poke_early(addr, opcode, len);
13901 for (i = 0; i < len; i++)
13902 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13903 - local_irq_restore(flags);
13904 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13905 return addr;
13906 }
13907
13908 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13909 index edc2448..553e7c5 100644
13910 --- a/arch/x86/kernel/apic/apic.c
13911 +++ b/arch/x86/kernel/apic/apic.c
13912 @@ -184,7 +184,7 @@ int first_system_vector = 0xfe;
13913 /*
13914 * Debug level, exported for io_apic.c
13915 */
13916 -unsigned int apic_verbosity;
13917 +int apic_verbosity;
13918
13919 int pic_mode;
13920
13921 @@ -1917,7 +1917,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13922 apic_write(APIC_ESR, 0);
13923 v1 = apic_read(APIC_ESR);
13924 ack_APIC_irq();
13925 - atomic_inc(&irq_err_count);
13926 + atomic_inc_unchecked(&irq_err_count);
13927
13928 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13929 smp_processor_id(), v0 , v1);
13930 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13931 index e88300d..cd5a87a 100644
13932 --- a/arch/x86/kernel/apic/io_apic.c
13933 +++ b/arch/x86/kernel/apic/io_apic.c
13934 @@ -83,7 +83,9 @@ static struct io_apic_ops io_apic_ops = {
13935
13936 void __init set_io_apic_ops(const struct io_apic_ops *ops)
13937 {
13938 - io_apic_ops = *ops;
13939 + pax_open_kernel();
13940 + memcpy((void*)&io_apic_ops, ops, sizeof io_apic_ops);
13941 + pax_close_kernel();
13942 }
13943
13944 /*
13945 @@ -1135,7 +1137,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13946 }
13947 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13948
13949 -void lock_vector_lock(void)
13950 +void lock_vector_lock(void) __acquires(vector_lock)
13951 {
13952 /* Used to the online set of cpus does not change
13953 * during assign_irq_vector.
13954 @@ -1143,7 +1145,7 @@ void lock_vector_lock(void)
13955 raw_spin_lock(&vector_lock);
13956 }
13957
13958 -void unlock_vector_lock(void)
13959 +void unlock_vector_lock(void) __releases(vector_lock)
13960 {
13961 raw_spin_unlock(&vector_lock);
13962 }
13963 @@ -2549,7 +2551,7 @@ static void ack_apic_edge(struct irq_data *data)
13964 ack_APIC_irq();
13965 }
13966
13967 -atomic_t irq_mis_count;
13968 +atomic_unchecked_t irq_mis_count;
13969
13970 #ifdef CONFIG_GENERIC_PENDING_IRQ
13971 static inline bool ioapic_irqd_mask(struct irq_data *data, struct irq_cfg *cfg)
13972 @@ -2667,7 +2669,7 @@ static void ack_apic_level(struct irq_data *data)
13973 * at the cpu.
13974 */
13975 if (!(v & (1 << (i & 0x1f)))) {
13976 - atomic_inc(&irq_mis_count);
13977 + atomic_inc_unchecked(&irq_mis_count);
13978
13979 eoi_ioapic_irq(irq, cfg);
13980 }
13981 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13982 index 459e78c..f037006 100644
13983 --- a/arch/x86/kernel/apm_32.c
13984 +++ b/arch/x86/kernel/apm_32.c
13985 @@ -410,7 +410,7 @@ static DEFINE_MUTEX(apm_mutex);
13986 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13987 * even though they are called in protected mode.
13988 */
13989 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13990 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13991 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13992
13993 static const char driver_version[] = "1.16ac"; /* no spaces */
13994 @@ -588,7 +588,10 @@ static long __apm_bios_call(void *_call)
13995 BUG_ON(cpu != 0);
13996 gdt = get_cpu_gdt_table(cpu);
13997 save_desc_40 = gdt[0x40 / 8];
13998 +
13999 + pax_open_kernel();
14000 gdt[0x40 / 8] = bad_bios_desc;
14001 + pax_close_kernel();
14002
14003 apm_irq_save(flags);
14004 APM_DO_SAVE_SEGS;
14005 @@ -597,7 +600,11 @@ static long __apm_bios_call(void *_call)
14006 &call->esi);
14007 APM_DO_RESTORE_SEGS;
14008 apm_irq_restore(flags);
14009 +
14010 + pax_open_kernel();
14011 gdt[0x40 / 8] = save_desc_40;
14012 + pax_close_kernel();
14013 +
14014 put_cpu();
14015
14016 return call->eax & 0xff;
14017 @@ -664,7 +671,10 @@ static long __apm_bios_call_simple(void *_call)
14018 BUG_ON(cpu != 0);
14019 gdt = get_cpu_gdt_table(cpu);
14020 save_desc_40 = gdt[0x40 / 8];
14021 +
14022 + pax_open_kernel();
14023 gdt[0x40 / 8] = bad_bios_desc;
14024 + pax_close_kernel();
14025
14026 apm_irq_save(flags);
14027 APM_DO_SAVE_SEGS;
14028 @@ -672,7 +682,11 @@ static long __apm_bios_call_simple(void *_call)
14029 &call->eax);
14030 APM_DO_RESTORE_SEGS;
14031 apm_irq_restore(flags);
14032 +
14033 + pax_open_kernel();
14034 gdt[0x40 / 8] = save_desc_40;
14035 + pax_close_kernel();
14036 +
14037 put_cpu();
14038 return error;
14039 }
14040 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
14041 * code to that CPU.
14042 */
14043 gdt = get_cpu_gdt_table(0);
14044 +
14045 + pax_open_kernel();
14046 set_desc_base(&gdt[APM_CS >> 3],
14047 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
14048 set_desc_base(&gdt[APM_CS_16 >> 3],
14049 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
14050 set_desc_base(&gdt[APM_DS >> 3],
14051 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
14052 + pax_close_kernel();
14053
14054 proc_create("apm", 0, NULL, &apm_file_ops);
14055
14056 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
14057 index 68de2dc..1f3c720 100644
14058 --- a/arch/x86/kernel/asm-offsets.c
14059 +++ b/arch/x86/kernel/asm-offsets.c
14060 @@ -33,6 +33,8 @@ void common(void) {
14061 OFFSET(TI_status, thread_info, status);
14062 OFFSET(TI_addr_limit, thread_info, addr_limit);
14063 OFFSET(TI_preempt_count, thread_info, preempt_count);
14064 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
14065 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
14066
14067 BLANK();
14068 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
14069 @@ -53,8 +55,26 @@ void common(void) {
14070 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
14071 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
14072 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
14073 +
14074 +#ifdef CONFIG_PAX_KERNEXEC
14075 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
14076 #endif
14077
14078 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14079 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
14080 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
14081 +#ifdef CONFIG_X86_64
14082 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
14083 +#endif
14084 +#endif
14085 +
14086 +#endif
14087 +
14088 + BLANK();
14089 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
14090 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
14091 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
14092 +
14093 #ifdef CONFIG_XEN
14094 BLANK();
14095 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14096 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14097 index 1b4754f..fbb4227 100644
14098 --- a/arch/x86/kernel/asm-offsets_64.c
14099 +++ b/arch/x86/kernel/asm-offsets_64.c
14100 @@ -76,6 +76,7 @@ int main(void)
14101 BLANK();
14102 #undef ENTRY
14103
14104 + DEFINE(TSS_size, sizeof(struct tss_struct));
14105 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14106 BLANK();
14107
14108 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14109 index 6ab6aa2..8f71507 100644
14110 --- a/arch/x86/kernel/cpu/Makefile
14111 +++ b/arch/x86/kernel/cpu/Makefile
14112 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14113 CFLAGS_REMOVE_perf_event.o = -pg
14114 endif
14115
14116 -# Make sure load_percpu_segment has no stackprotector
14117 -nostackp := $(call cc-option, -fno-stack-protector)
14118 -CFLAGS_common.o := $(nostackp)
14119 -
14120 obj-y := intel_cacheinfo.o scattered.o topology.o
14121 obj-y += proc.o capflags.o powerflags.o common.o
14122 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
14123 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14124 index 146bb62..ac9c74a 100644
14125 --- a/arch/x86/kernel/cpu/amd.c
14126 +++ b/arch/x86/kernel/cpu/amd.c
14127 @@ -691,7 +691,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14128 unsigned int size)
14129 {
14130 /* AMD errata T13 (order #21922) */
14131 - if ((c->x86 == 6)) {
14132 + if (c->x86 == 6) {
14133 /* Duron Rev A0 */
14134 if (c->x86_model == 3 && c->x86_mask == 0)
14135 size = 64;
14136 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14137 index cf79302..b1b28ae 100644
14138 --- a/arch/x86/kernel/cpu/common.c
14139 +++ b/arch/x86/kernel/cpu/common.c
14140 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14141
14142 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14143
14144 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14145 -#ifdef CONFIG_X86_64
14146 - /*
14147 - * We need valid kernel segments for data and code in long mode too
14148 - * IRET will check the segment types kkeil 2000/10/28
14149 - * Also sysret mandates a special GDT layout
14150 - *
14151 - * TLS descriptors are currently at a different place compared to i386.
14152 - * Hopefully nobody expects them at a fixed place (Wine?)
14153 - */
14154 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14155 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14156 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14157 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14158 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14159 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14160 -#else
14161 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14162 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14163 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14164 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14165 - /*
14166 - * Segments used for calling PnP BIOS have byte granularity.
14167 - * They code segments and data segments have fixed 64k limits,
14168 - * the transfer segment sizes are set at run time.
14169 - */
14170 - /* 32-bit code */
14171 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14172 - /* 16-bit code */
14173 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14174 - /* 16-bit data */
14175 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14176 - /* 16-bit data */
14177 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14178 - /* 16-bit data */
14179 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14180 - /*
14181 - * The APM segments have byte granularity and their bases
14182 - * are set at run time. All have 64k limits.
14183 - */
14184 - /* 32-bit code */
14185 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14186 - /* 16-bit code */
14187 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14188 - /* data */
14189 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14190 -
14191 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14192 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14193 - GDT_STACK_CANARY_INIT
14194 -#endif
14195 -} };
14196 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14197 -
14198 static int __init x86_xsave_setup(char *s)
14199 {
14200 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14201 @@ -374,7 +320,7 @@ void switch_to_new_gdt(int cpu)
14202 {
14203 struct desc_ptr gdt_descr;
14204
14205 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14206 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14207 gdt_descr.size = GDT_SIZE - 1;
14208 load_gdt(&gdt_descr);
14209 /* Reload the per-cpu base */
14210 @@ -841,6 +787,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14211 /* Filter out anything that depends on CPUID levels we don't have */
14212 filter_cpuid_features(c, true);
14213
14214 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14215 + setup_clear_cpu_cap(X86_FEATURE_SEP);
14216 +#endif
14217 +
14218 /* If the model name is still unset, do table lookup. */
14219 if (!c->x86_model_id[0]) {
14220 const char *p;
14221 @@ -1021,10 +971,12 @@ static __init int setup_disablecpuid(char *arg)
14222 }
14223 __setup("clearcpuid=", setup_disablecpuid);
14224
14225 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14226 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
14227 +
14228 #ifdef CONFIG_X86_64
14229 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14230 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14231 - (unsigned long) nmi_idt_table };
14232 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14233
14234 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14235 irq_stack_union) __aligned(PAGE_SIZE);
14236 @@ -1038,7 +990,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14237 EXPORT_PER_CPU_SYMBOL(current_task);
14238
14239 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14240 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14241 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14242 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14243
14244 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14245 @@ -1126,7 +1078,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14246 {
14247 memset(regs, 0, sizeof(struct pt_regs));
14248 regs->fs = __KERNEL_PERCPU;
14249 - regs->gs = __KERNEL_STACK_CANARY;
14250 + savesegment(gs, regs->gs);
14251
14252 return regs;
14253 }
14254 @@ -1181,7 +1133,7 @@ void __cpuinit cpu_init(void)
14255 int i;
14256
14257 cpu = stack_smp_processor_id();
14258 - t = &per_cpu(init_tss, cpu);
14259 + t = init_tss + cpu;
14260 oist = &per_cpu(orig_ist, cpu);
14261
14262 #ifdef CONFIG_NUMA
14263 @@ -1207,7 +1159,7 @@ void __cpuinit cpu_init(void)
14264 switch_to_new_gdt(cpu);
14265 loadsegment(fs, 0);
14266
14267 - load_idt((const struct desc_ptr *)&idt_descr);
14268 + load_idt(&idt_descr);
14269
14270 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14271 syscall_init();
14272 @@ -1216,7 +1168,6 @@ void __cpuinit cpu_init(void)
14273 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14274 barrier();
14275
14276 - x86_configure_nx();
14277 if (cpu != 0)
14278 enable_x2apic();
14279
14280 @@ -1272,7 +1223,7 @@ void __cpuinit cpu_init(void)
14281 {
14282 int cpu = smp_processor_id();
14283 struct task_struct *curr = current;
14284 - struct tss_struct *t = &per_cpu(init_tss, cpu);
14285 + struct tss_struct *t = init_tss + cpu;
14286 struct thread_struct *thread = &curr->thread;
14287
14288 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14289 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14290 index 3e6ff6c..54b4992 100644
14291 --- a/arch/x86/kernel/cpu/intel.c
14292 +++ b/arch/x86/kernel/cpu/intel.c
14293 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14294 * Update the IDT descriptor and reload the IDT so that
14295 * it uses the read-only mapped virtual address.
14296 */
14297 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14298 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14299 load_idt(&idt_descr);
14300 }
14301 #endif
14302 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14303 index 61604ae..98250a5 100644
14304 --- a/arch/x86/kernel/cpu/mcheck/mce.c
14305 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
14306 @@ -42,6 +42,7 @@
14307 #include <asm/processor.h>
14308 #include <asm/mce.h>
14309 #include <asm/msr.h>
14310 +#include <asm/local.h>
14311
14312 #include "mce-internal.h"
14313
14314 @@ -250,7 +251,7 @@ static void print_mce(struct mce *m)
14315 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14316 m->cs, m->ip);
14317
14318 - if (m->cs == __KERNEL_CS)
14319 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14320 print_symbol("{%s}", m->ip);
14321 pr_cont("\n");
14322 }
14323 @@ -283,10 +284,10 @@ static void print_mce(struct mce *m)
14324
14325 #define PANIC_TIMEOUT 5 /* 5 seconds */
14326
14327 -static atomic_t mce_paniced;
14328 +static atomic_unchecked_t mce_paniced;
14329
14330 static int fake_panic;
14331 -static atomic_t mce_fake_paniced;
14332 +static atomic_unchecked_t mce_fake_paniced;
14333
14334 /* Panic in progress. Enable interrupts and wait for final IPI */
14335 static void wait_for_panic(void)
14336 @@ -310,7 +311,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14337 /*
14338 * Make sure only one CPU runs in machine check panic
14339 */
14340 - if (atomic_inc_return(&mce_paniced) > 1)
14341 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14342 wait_for_panic();
14343 barrier();
14344
14345 @@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14346 console_verbose();
14347 } else {
14348 /* Don't log too much for fake panic */
14349 - if (atomic_inc_return(&mce_fake_paniced) > 1)
14350 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14351 return;
14352 }
14353 /* First print corrected ones that are still unlogged */
14354 @@ -684,7 +685,7 @@ static int mce_timed_out(u64 *t)
14355 * might have been modified by someone else.
14356 */
14357 rmb();
14358 - if (atomic_read(&mce_paniced))
14359 + if (atomic_read_unchecked(&mce_paniced))
14360 wait_for_panic();
14361 if (!monarch_timeout)
14362 goto out;
14363 @@ -1535,7 +1536,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14364 }
14365
14366 /* Call the installed machine check handler for this CPU setup. */
14367 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
14368 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14369 unexpected_machine_check;
14370
14371 /*
14372 @@ -1558,7 +1559,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14373 return;
14374 }
14375
14376 + pax_open_kernel();
14377 machine_check_vector = do_machine_check;
14378 + pax_close_kernel();
14379
14380 __mcheck_cpu_init_generic();
14381 __mcheck_cpu_init_vendor(c);
14382 @@ -1572,7 +1575,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14383 */
14384
14385 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14386 -static int mce_chrdev_open_count; /* #times opened */
14387 +static local_t mce_chrdev_open_count; /* #times opened */
14388 static int mce_chrdev_open_exclu; /* already open exclusive? */
14389
14390 static int mce_chrdev_open(struct inode *inode, struct file *file)
14391 @@ -1580,7 +1583,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14392 spin_lock(&mce_chrdev_state_lock);
14393
14394 if (mce_chrdev_open_exclu ||
14395 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14396 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14397 spin_unlock(&mce_chrdev_state_lock);
14398
14399 return -EBUSY;
14400 @@ -1588,7 +1591,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14401
14402 if (file->f_flags & O_EXCL)
14403 mce_chrdev_open_exclu = 1;
14404 - mce_chrdev_open_count++;
14405 + local_inc(&mce_chrdev_open_count);
14406
14407 spin_unlock(&mce_chrdev_state_lock);
14408
14409 @@ -1599,7 +1602,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14410 {
14411 spin_lock(&mce_chrdev_state_lock);
14412
14413 - mce_chrdev_open_count--;
14414 + local_dec(&mce_chrdev_open_count);
14415 mce_chrdev_open_exclu = 0;
14416
14417 spin_unlock(&mce_chrdev_state_lock);
14418 @@ -2324,7 +2327,7 @@ struct dentry *mce_get_debugfs_dir(void)
14419 static void mce_reset(void)
14420 {
14421 cpu_missing = 0;
14422 - atomic_set(&mce_fake_paniced, 0);
14423 + atomic_set_unchecked(&mce_fake_paniced, 0);
14424 atomic_set(&mce_executing, 0);
14425 atomic_set(&mce_callin, 0);
14426 atomic_set(&global_nwo, 0);
14427 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14428 index 2d5454c..51987eb 100644
14429 --- a/arch/x86/kernel/cpu/mcheck/p5.c
14430 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
14431 @@ -11,6 +11,7 @@
14432 #include <asm/processor.h>
14433 #include <asm/mce.h>
14434 #include <asm/msr.h>
14435 +#include <asm/pgtable.h>
14436
14437 /* By default disabled */
14438 int mce_p5_enabled __read_mostly;
14439 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14440 if (!cpu_has(c, X86_FEATURE_MCE))
14441 return;
14442
14443 + pax_open_kernel();
14444 machine_check_vector = pentium_machine_check;
14445 + pax_close_kernel();
14446 /* Make sure the vector pointer is visible before we enable MCEs: */
14447 wmb();
14448
14449 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14450 index 2d7998f..17c9de1 100644
14451 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
14452 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14453 @@ -10,6 +10,7 @@
14454 #include <asm/processor.h>
14455 #include <asm/mce.h>
14456 #include <asm/msr.h>
14457 +#include <asm/pgtable.h>
14458
14459 /* Machine check handler for WinChip C6: */
14460 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14461 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14462 {
14463 u32 lo, hi;
14464
14465 + pax_open_kernel();
14466 machine_check_vector = winchip_machine_check;
14467 + pax_close_kernel();
14468 /* Make sure the vector pointer is visible before we enable MCEs: */
14469 wmb();
14470
14471 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14472 index 6b96110..0da73eb 100644
14473 --- a/arch/x86/kernel/cpu/mtrr/main.c
14474 +++ b/arch/x86/kernel/cpu/mtrr/main.c
14475 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14476 u64 size_or_mask, size_and_mask;
14477 static bool mtrr_aps_delayed_init;
14478
14479 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14480 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14481
14482 const struct mtrr_ops *mtrr_if;
14483
14484 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14485 index df5e41f..816c719 100644
14486 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14487 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14488 @@ -25,7 +25,7 @@ struct mtrr_ops {
14489 int (*validate_add_page)(unsigned long base, unsigned long size,
14490 unsigned int type);
14491 int (*have_wrcomb)(void);
14492 -};
14493 +} __do_const;
14494
14495 extern int generic_get_free_region(unsigned long base, unsigned long size,
14496 int replace_reg);
14497 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14498 index bb8e034..fb9020b 100644
14499 --- a/arch/x86/kernel/cpu/perf_event.c
14500 +++ b/arch/x86/kernel/cpu/perf_event.c
14501 @@ -1835,7 +1835,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14502 break;
14503
14504 perf_callchain_store(entry, frame.return_address);
14505 - fp = frame.next_frame;
14506 + fp = (const void __force_user *)frame.next_frame;
14507 }
14508 }
14509
14510 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14511 index 13ad899..f642b9a 100644
14512 --- a/arch/x86/kernel/crash.c
14513 +++ b/arch/x86/kernel/crash.c
14514 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14515 {
14516 #ifdef CONFIG_X86_32
14517 struct pt_regs fixed_regs;
14518 -#endif
14519
14520 -#ifdef CONFIG_X86_32
14521 - if (!user_mode_vm(regs)) {
14522 + if (!user_mode(regs)) {
14523 crash_fixup_ss_esp(&fixed_regs, regs);
14524 regs = &fixed_regs;
14525 }
14526 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14527 index 37250fe..bf2ec74 100644
14528 --- a/arch/x86/kernel/doublefault_32.c
14529 +++ b/arch/x86/kernel/doublefault_32.c
14530 @@ -11,7 +11,7 @@
14531
14532 #define DOUBLEFAULT_STACKSIZE (1024)
14533 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14534 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14535 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14536
14537 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14538
14539 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
14540 unsigned long gdt, tss;
14541
14542 store_gdt(&gdt_desc);
14543 - gdt = gdt_desc.address;
14544 + gdt = (unsigned long)gdt_desc.address;
14545
14546 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14547
14548 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14549 /* 0x2 bit is always set */
14550 .flags = X86_EFLAGS_SF | 0x2,
14551 .sp = STACK_START,
14552 - .es = __USER_DS,
14553 + .es = __KERNEL_DS,
14554 .cs = __KERNEL_CS,
14555 .ss = __KERNEL_DS,
14556 - .ds = __USER_DS,
14557 + .ds = __KERNEL_DS,
14558 .fs = __KERNEL_PERCPU,
14559
14560 .__cr3 = __pa_nodebug(swapper_pg_dir),
14561 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14562 index 1b81839..0b4e7b0 100644
14563 --- a/arch/x86/kernel/dumpstack.c
14564 +++ b/arch/x86/kernel/dumpstack.c
14565 @@ -2,6 +2,9 @@
14566 * Copyright (C) 1991, 1992 Linus Torvalds
14567 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14568 */
14569 +#ifdef CONFIG_GRKERNSEC_HIDESYM
14570 +#define __INCLUDED_BY_HIDESYM 1
14571 +#endif
14572 #include <linux/kallsyms.h>
14573 #include <linux/kprobes.h>
14574 #include <linux/uaccess.h>
14575 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14576 static void
14577 print_ftrace_graph_addr(unsigned long addr, void *data,
14578 const struct stacktrace_ops *ops,
14579 - struct thread_info *tinfo, int *graph)
14580 + struct task_struct *task, int *graph)
14581 {
14582 - struct task_struct *task;
14583 unsigned long ret_addr;
14584 int index;
14585
14586 if (addr != (unsigned long)return_to_handler)
14587 return;
14588
14589 - task = tinfo->task;
14590 index = task->curr_ret_stack;
14591
14592 if (!task->ret_stack || index < *graph)
14593 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14594 static inline void
14595 print_ftrace_graph_addr(unsigned long addr, void *data,
14596 const struct stacktrace_ops *ops,
14597 - struct thread_info *tinfo, int *graph)
14598 + struct task_struct *task, int *graph)
14599 { }
14600 #endif
14601
14602 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14603 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14604 */
14605
14606 -static inline int valid_stack_ptr(struct thread_info *tinfo,
14607 - void *p, unsigned int size, void *end)
14608 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14609 {
14610 - void *t = tinfo;
14611 if (end) {
14612 if (p < end && p >= (end-THREAD_SIZE))
14613 return 1;
14614 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14615 }
14616
14617 unsigned long
14618 -print_context_stack(struct thread_info *tinfo,
14619 +print_context_stack(struct task_struct *task, void *stack_start,
14620 unsigned long *stack, unsigned long bp,
14621 const struct stacktrace_ops *ops, void *data,
14622 unsigned long *end, int *graph)
14623 {
14624 struct stack_frame *frame = (struct stack_frame *)bp;
14625
14626 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14627 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14628 unsigned long addr;
14629
14630 addr = *stack;
14631 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14632 } else {
14633 ops->address(data, addr, 0);
14634 }
14635 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14636 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14637 }
14638 stack++;
14639 }
14640 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14641 EXPORT_SYMBOL_GPL(print_context_stack);
14642
14643 unsigned long
14644 -print_context_stack_bp(struct thread_info *tinfo,
14645 +print_context_stack_bp(struct task_struct *task, void *stack_start,
14646 unsigned long *stack, unsigned long bp,
14647 const struct stacktrace_ops *ops, void *data,
14648 unsigned long *end, int *graph)
14649 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14650 struct stack_frame *frame = (struct stack_frame *)bp;
14651 unsigned long *ret_addr = &frame->return_address;
14652
14653 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14654 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14655 unsigned long addr = *ret_addr;
14656
14657 if (!__kernel_text_address(addr))
14658 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14659 ops->address(data, addr, 1);
14660 frame = frame->next_frame;
14661 ret_addr = &frame->return_address;
14662 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14663 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14664 }
14665
14666 return (unsigned long)frame;
14667 @@ -189,7 +188,7 @@ void dump_stack(void)
14668
14669 bp = stack_frame(current, NULL);
14670 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14671 - current->pid, current->comm, print_tainted(),
14672 + task_pid_nr(current), current->comm, print_tainted(),
14673 init_utsname()->release,
14674 (int)strcspn(init_utsname()->version, " "),
14675 init_utsname()->version);
14676 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14677 }
14678 EXPORT_SYMBOL_GPL(oops_begin);
14679
14680 +extern void gr_handle_kernel_exploit(void);
14681 +
14682 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14683 {
14684 if (regs && kexec_should_crash(current))
14685 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14686 panic("Fatal exception in interrupt");
14687 if (panic_on_oops)
14688 panic("Fatal exception");
14689 - do_exit(signr);
14690 +
14691 + gr_handle_kernel_exploit();
14692 +
14693 + do_group_exit(signr);
14694 }
14695
14696 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14697 @@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14698
14699 show_registers(regs);
14700 #ifdef CONFIG_X86_32
14701 - if (user_mode_vm(regs)) {
14702 + if (user_mode(regs)) {
14703 sp = regs->sp;
14704 ss = regs->ss & 0xffff;
14705 } else {
14706 @@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14707 unsigned long flags = oops_begin();
14708 int sig = SIGSEGV;
14709
14710 - if (!user_mode_vm(regs))
14711 + if (!user_mode(regs))
14712 report_bug(regs->ip, regs);
14713
14714 if (__die(str, regs, err))
14715 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14716 index 88ec912..e95e935 100644
14717 --- a/arch/x86/kernel/dumpstack_32.c
14718 +++ b/arch/x86/kernel/dumpstack_32.c
14719 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14720 bp = stack_frame(task, regs);
14721
14722 for (;;) {
14723 - struct thread_info *context;
14724 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14725
14726 - context = (struct thread_info *)
14727 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14728 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14729 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14730
14731 - stack = (unsigned long *)context->previous_esp;
14732 - if (!stack)
14733 + if (stack_start == task_stack_page(task))
14734 break;
14735 + stack = *(unsigned long **)stack_start;
14736 if (ops->stack(data, "IRQ") < 0)
14737 break;
14738 touch_nmi_watchdog();
14739 @@ -87,7 +85,7 @@ void show_registers(struct pt_regs *regs)
14740 int i;
14741
14742 print_modules();
14743 - __show_regs(regs, !user_mode_vm(regs));
14744 + __show_regs(regs, !user_mode(regs));
14745
14746 printk(KERN_EMERG "Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14747 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14748 @@ -96,21 +94,22 @@ void show_registers(struct pt_regs *regs)
14749 * When in-kernel, we also print out the stack and code at the
14750 * time of the fault..
14751 */
14752 - if (!user_mode_vm(regs)) {
14753 + if (!user_mode(regs)) {
14754 unsigned int code_prologue = code_bytes * 43 / 64;
14755 unsigned int code_len = code_bytes;
14756 unsigned char c;
14757 u8 *ip;
14758 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14759
14760 printk(KERN_EMERG "Stack:\n");
14761 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14762
14763 printk(KERN_EMERG "Code: ");
14764
14765 - ip = (u8 *)regs->ip - code_prologue;
14766 + ip = (u8 *)regs->ip - code_prologue + cs_base;
14767 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14768 /* try starting at IP */
14769 - ip = (u8 *)regs->ip;
14770 + ip = (u8 *)regs->ip + cs_base;
14771 code_len = code_len - code_prologue + 1;
14772 }
14773 for (i = 0; i < code_len; i++, ip++) {
14774 @@ -119,7 +118,7 @@ void show_registers(struct pt_regs *regs)
14775 printk(KERN_CONT " Bad EIP value.");
14776 break;
14777 }
14778 - if (ip == (u8 *)regs->ip)
14779 + if (ip == (u8 *)regs->ip + cs_base)
14780 printk(KERN_CONT "<%02x> ", c);
14781 else
14782 printk(KERN_CONT "%02x ", c);
14783 @@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
14784 {
14785 unsigned short ud2;
14786
14787 + ip = ktla_ktva(ip);
14788 if (ip < PAGE_OFFSET)
14789 return 0;
14790 if (probe_kernel_address((unsigned short *)ip, ud2))
14791 @@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
14792
14793 return ud2 == 0x0b0f;
14794 }
14795 +
14796 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14797 +void pax_check_alloca(unsigned long size)
14798 +{
14799 + unsigned long sp = (unsigned long)&sp, stack_left;
14800 +
14801 + /* all kernel stacks are of the same size */
14802 + stack_left = sp & (THREAD_SIZE - 1);
14803 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14804 +}
14805 +EXPORT_SYMBOL(pax_check_alloca);
14806 +#endif
14807 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14808 index 17107bd..9623722 100644
14809 --- a/arch/x86/kernel/dumpstack_64.c
14810 +++ b/arch/x86/kernel/dumpstack_64.c
14811 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14812 unsigned long *irq_stack_end =
14813 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14814 unsigned used = 0;
14815 - struct thread_info *tinfo;
14816 int graph = 0;
14817 unsigned long dummy;
14818 + void *stack_start;
14819
14820 if (!task)
14821 task = current;
14822 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14823 * current stack address. If the stacks consist of nested
14824 * exceptions
14825 */
14826 - tinfo = task_thread_info(task);
14827 for (;;) {
14828 char *id;
14829 unsigned long *estack_end;
14830 +
14831 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14832 &used, &id);
14833
14834 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14835 if (ops->stack(data, id) < 0)
14836 break;
14837
14838 - bp = ops->walk_stack(tinfo, stack, bp, ops,
14839 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14840 data, estack_end, &graph);
14841 ops->stack(data, "<EOE>");
14842 /*
14843 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14844 * second-to-last pointer (index -2 to end) in the
14845 * exception stack:
14846 */
14847 + if ((u16)estack_end[-1] != __KERNEL_DS)
14848 + goto out;
14849 stack = (unsigned long *) estack_end[-2];
14850 continue;
14851 }
14852 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14853 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14854 if (ops->stack(data, "IRQ") < 0)
14855 break;
14856 - bp = ops->walk_stack(tinfo, stack, bp,
14857 + bp = ops->walk_stack(task, irq_stack, stack, bp,
14858 ops, data, irq_stack_end, &graph);
14859 /*
14860 * We link to the next stack (which would be
14861 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14862 /*
14863 * This handles the process stack:
14864 */
14865 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14866 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14867 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14868 +out:
14869 put_cpu();
14870 }
14871 EXPORT_SYMBOL(dump_trace);
14872 @@ -305,3 +309,50 @@ int is_valid_bugaddr(unsigned long ip)
14873
14874 return ud2 == 0x0b0f;
14875 }
14876 +
14877 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14878 +void pax_check_alloca(unsigned long size)
14879 +{
14880 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14881 + unsigned cpu, used;
14882 + char *id;
14883 +
14884 + /* check the process stack first */
14885 + stack_start = (unsigned long)task_stack_page(current);
14886 + stack_end = stack_start + THREAD_SIZE;
14887 + if (likely(stack_start <= sp && sp < stack_end)) {
14888 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
14889 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14890 + return;
14891 + }
14892 +
14893 + cpu = get_cpu();
14894 +
14895 + /* check the irq stacks */
14896 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14897 + stack_start = stack_end - IRQ_STACK_SIZE;
14898 + if (stack_start <= sp && sp < stack_end) {
14899 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14900 + put_cpu();
14901 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14902 + return;
14903 + }
14904 +
14905 + /* check the exception stacks */
14906 + used = 0;
14907 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14908 + stack_start = stack_end - EXCEPTION_STKSZ;
14909 + if (stack_end && stack_start <= sp && sp < stack_end) {
14910 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14911 + put_cpu();
14912 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14913 + return;
14914 + }
14915 +
14916 + put_cpu();
14917 +
14918 + /* unknown stack */
14919 + BUG();
14920 +}
14921 +EXPORT_SYMBOL(pax_check_alloca);
14922 +#endif
14923 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14924 index 9b9f18b..9fcaa04 100644
14925 --- a/arch/x86/kernel/early_printk.c
14926 +++ b/arch/x86/kernel/early_printk.c
14927 @@ -7,6 +7,7 @@
14928 #include <linux/pci_regs.h>
14929 #include <linux/pci_ids.h>
14930 #include <linux/errno.h>
14931 +#include <linux/sched.h>
14932 #include <asm/io.h>
14933 #include <asm/processor.h>
14934 #include <asm/fcntl.h>
14935 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14936 index 7b784f4..db6b628 100644
14937 --- a/arch/x86/kernel/entry_32.S
14938 +++ b/arch/x86/kernel/entry_32.S
14939 @@ -179,13 +179,146 @@
14940 /*CFI_REL_OFFSET gs, PT_GS*/
14941 .endm
14942 .macro SET_KERNEL_GS reg
14943 +
14944 +#ifdef CONFIG_CC_STACKPROTECTOR
14945 movl $(__KERNEL_STACK_CANARY), \reg
14946 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14947 + movl $(__USER_DS), \reg
14948 +#else
14949 + xorl \reg, \reg
14950 +#endif
14951 +
14952 movl \reg, %gs
14953 .endm
14954
14955 #endif /* CONFIG_X86_32_LAZY_GS */
14956
14957 -.macro SAVE_ALL
14958 +.macro pax_enter_kernel
14959 +#ifdef CONFIG_PAX_KERNEXEC
14960 + call pax_enter_kernel
14961 +#endif
14962 +.endm
14963 +
14964 +.macro pax_exit_kernel
14965 +#ifdef CONFIG_PAX_KERNEXEC
14966 + call pax_exit_kernel
14967 +#endif
14968 +.endm
14969 +
14970 +#ifdef CONFIG_PAX_KERNEXEC
14971 +ENTRY(pax_enter_kernel)
14972 +#ifdef CONFIG_PARAVIRT
14973 + pushl %eax
14974 + pushl %ecx
14975 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
14976 + mov %eax, %esi
14977 +#else
14978 + mov %cr0, %esi
14979 +#endif
14980 + bts $16, %esi
14981 + jnc 1f
14982 + mov %cs, %esi
14983 + cmp $__KERNEL_CS, %esi
14984 + jz 3f
14985 + ljmp $__KERNEL_CS, $3f
14986 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
14987 +2:
14988 +#ifdef CONFIG_PARAVIRT
14989 + mov %esi, %eax
14990 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14991 +#else
14992 + mov %esi, %cr0
14993 +#endif
14994 +3:
14995 +#ifdef CONFIG_PARAVIRT
14996 + popl %ecx
14997 + popl %eax
14998 +#endif
14999 + ret
15000 +ENDPROC(pax_enter_kernel)
15001 +
15002 +ENTRY(pax_exit_kernel)
15003 +#ifdef CONFIG_PARAVIRT
15004 + pushl %eax
15005 + pushl %ecx
15006 +#endif
15007 + mov %cs, %esi
15008 + cmp $__KERNEXEC_KERNEL_CS, %esi
15009 + jnz 2f
15010 +#ifdef CONFIG_PARAVIRT
15011 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
15012 + mov %eax, %esi
15013 +#else
15014 + mov %cr0, %esi
15015 +#endif
15016 + btr $16, %esi
15017 + ljmp $__KERNEL_CS, $1f
15018 +1:
15019 +#ifdef CONFIG_PARAVIRT
15020 + mov %esi, %eax
15021 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
15022 +#else
15023 + mov %esi, %cr0
15024 +#endif
15025 +2:
15026 +#ifdef CONFIG_PARAVIRT
15027 + popl %ecx
15028 + popl %eax
15029 +#endif
15030 + ret
15031 +ENDPROC(pax_exit_kernel)
15032 +#endif
15033 +
15034 +.macro pax_erase_kstack
15035 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15036 + call pax_erase_kstack
15037 +#endif
15038 +.endm
15039 +
15040 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15041 +/*
15042 + * ebp: thread_info
15043 + * ecx, edx: can be clobbered
15044 + */
15045 +ENTRY(pax_erase_kstack)
15046 + pushl %edi
15047 + pushl %eax
15048 +
15049 + mov TI_lowest_stack(%ebp), %edi
15050 + mov $-0xBEEF, %eax
15051 + std
15052 +
15053 +1: mov %edi, %ecx
15054 + and $THREAD_SIZE_asm - 1, %ecx
15055 + shr $2, %ecx
15056 + repne scasl
15057 + jecxz 2f
15058 +
15059 + cmp $2*16, %ecx
15060 + jc 2f
15061 +
15062 + mov $2*16, %ecx
15063 + repe scasl
15064 + jecxz 2f
15065 + jne 1b
15066 +
15067 +2: cld
15068 + mov %esp, %ecx
15069 + sub %edi, %ecx
15070 + shr $2, %ecx
15071 + rep stosl
15072 +
15073 + mov TI_task_thread_sp0(%ebp), %edi
15074 + sub $128, %edi
15075 + mov %edi, TI_lowest_stack(%ebp)
15076 +
15077 + popl %eax
15078 + popl %edi
15079 + ret
15080 +ENDPROC(pax_erase_kstack)
15081 +#endif
15082 +
15083 +.macro __SAVE_ALL _DS
15084 cld
15085 PUSH_GS
15086 pushl_cfi %fs
15087 @@ -208,7 +341,7 @@
15088 CFI_REL_OFFSET ecx, 0
15089 pushl_cfi %ebx
15090 CFI_REL_OFFSET ebx, 0
15091 - movl $(__USER_DS), %edx
15092 + movl $\_DS, %edx
15093 movl %edx, %ds
15094 movl %edx, %es
15095 movl $(__KERNEL_PERCPU), %edx
15096 @@ -216,6 +349,15 @@
15097 SET_KERNEL_GS %edx
15098 .endm
15099
15100 +.macro SAVE_ALL
15101 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15102 + __SAVE_ALL __KERNEL_DS
15103 + pax_enter_kernel
15104 +#else
15105 + __SAVE_ALL __USER_DS
15106 +#endif
15107 +.endm
15108 +
15109 .macro RESTORE_INT_REGS
15110 popl_cfi %ebx
15111 CFI_RESTORE ebx
15112 @@ -301,7 +443,7 @@ ENTRY(ret_from_fork)
15113 popfl_cfi
15114 jmp syscall_exit
15115 CFI_ENDPROC
15116 -END(ret_from_fork)
15117 +ENDPROC(ret_from_fork)
15118
15119 /*
15120 * Interrupt exit functions should be protected against kprobes
15121 @@ -335,7 +477,15 @@ resume_userspace_sig:
15122 andl $SEGMENT_RPL_MASK, %eax
15123 #endif
15124 cmpl $USER_RPL, %eax
15125 +
15126 +#ifdef CONFIG_PAX_KERNEXEC
15127 + jae resume_userspace
15128 +
15129 + pax_exit_kernel
15130 + jmp resume_kernel
15131 +#else
15132 jb resume_kernel # not returning to v8086 or userspace
15133 +#endif
15134
15135 ENTRY(resume_userspace)
15136 LOCKDEP_SYS_EXIT
15137 @@ -347,8 +497,8 @@ ENTRY(resume_userspace)
15138 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15139 # int/exception return?
15140 jne work_pending
15141 - jmp restore_all
15142 -END(ret_from_exception)
15143 + jmp restore_all_pax
15144 +ENDPROC(ret_from_exception)
15145
15146 #ifdef CONFIG_PREEMPT
15147 ENTRY(resume_kernel)
15148 @@ -363,7 +513,7 @@ need_resched:
15149 jz restore_all
15150 call preempt_schedule_irq
15151 jmp need_resched
15152 -END(resume_kernel)
15153 +ENDPROC(resume_kernel)
15154 #endif
15155 CFI_ENDPROC
15156 /*
15157 @@ -397,23 +547,34 @@ sysenter_past_esp:
15158 /*CFI_REL_OFFSET cs, 0*/
15159 /*
15160 * Push current_thread_info()->sysenter_return to the stack.
15161 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15162 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
15163 */
15164 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15165 + pushl_cfi $0
15166 CFI_REL_OFFSET eip, 0
15167
15168 pushl_cfi %eax
15169 SAVE_ALL
15170 + GET_THREAD_INFO(%ebp)
15171 + movl TI_sysenter_return(%ebp),%ebp
15172 + movl %ebp,PT_EIP(%esp)
15173 ENABLE_INTERRUPTS(CLBR_NONE)
15174
15175 /*
15176 * Load the potential sixth argument from user stack.
15177 * Careful about security.
15178 */
15179 + movl PT_OLDESP(%esp),%ebp
15180 +
15181 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15182 + mov PT_OLDSS(%esp),%ds
15183 +1: movl %ds:(%ebp),%ebp
15184 + push %ss
15185 + pop %ds
15186 +#else
15187 cmpl $__PAGE_OFFSET-3,%ebp
15188 jae syscall_fault
15189 1: movl (%ebp),%ebp
15190 +#endif
15191 +
15192 movl %ebp,PT_EBP(%esp)
15193 .section __ex_table,"a"
15194 .align 4
15195 @@ -436,12 +597,24 @@ sysenter_do_call:
15196 testl $_TIF_ALLWORK_MASK, %ecx
15197 jne sysexit_audit
15198 sysenter_exit:
15199 +
15200 +#ifdef CONFIG_PAX_RANDKSTACK
15201 + pushl_cfi %eax
15202 + movl %esp, %eax
15203 + call pax_randomize_kstack
15204 + popl_cfi %eax
15205 +#endif
15206 +
15207 + pax_erase_kstack
15208 +
15209 /* if something modifies registers it must also disable sysexit */
15210 movl PT_EIP(%esp), %edx
15211 movl PT_OLDESP(%esp), %ecx
15212 xorl %ebp,%ebp
15213 TRACE_IRQS_ON
15214 1: mov PT_FS(%esp), %fs
15215 +2: mov PT_DS(%esp), %ds
15216 +3: mov PT_ES(%esp), %es
15217 PTGS_TO_GS
15218 ENABLE_INTERRUPTS_SYSEXIT
15219
15220 @@ -458,6 +631,9 @@ sysenter_audit:
15221 movl %eax,%edx /* 2nd arg: syscall number */
15222 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15223 call __audit_syscall_entry
15224 +
15225 + pax_erase_kstack
15226 +
15227 pushl_cfi %ebx
15228 movl PT_EAX(%esp),%eax /* reload syscall number */
15229 jmp sysenter_do_call
15230 @@ -483,11 +659,17 @@ sysexit_audit:
15231
15232 CFI_ENDPROC
15233 .pushsection .fixup,"ax"
15234 -2: movl $0,PT_FS(%esp)
15235 +4: movl $0,PT_FS(%esp)
15236 + jmp 1b
15237 +5: movl $0,PT_DS(%esp)
15238 + jmp 1b
15239 +6: movl $0,PT_ES(%esp)
15240 jmp 1b
15241 .section __ex_table,"a"
15242 .align 4
15243 - .long 1b,2b
15244 + .long 1b,4b
15245 + .long 2b,5b
15246 + .long 3b,6b
15247 .popsection
15248 PTGS_TO_GS_EX
15249 ENDPROC(ia32_sysenter_target)
15250 @@ -520,6 +702,15 @@ syscall_exit:
15251 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15252 jne syscall_exit_work
15253
15254 +restore_all_pax:
15255 +
15256 +#ifdef CONFIG_PAX_RANDKSTACK
15257 + movl %esp, %eax
15258 + call pax_randomize_kstack
15259 +#endif
15260 +
15261 + pax_erase_kstack
15262 +
15263 restore_all:
15264 TRACE_IRQS_IRET
15265 restore_all_notrace:
15266 @@ -579,14 +770,34 @@ ldt_ss:
15267 * compensating for the offset by changing to the ESPFIX segment with
15268 * a base address that matches for the difference.
15269 */
15270 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15271 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15272 mov %esp, %edx /* load kernel esp */
15273 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15274 mov %dx, %ax /* eax: new kernel esp */
15275 sub %eax, %edx /* offset (low word is 0) */
15276 +#ifdef CONFIG_SMP
15277 + movl PER_CPU_VAR(cpu_number), %ebx
15278 + shll $PAGE_SHIFT_asm, %ebx
15279 + addl $cpu_gdt_table, %ebx
15280 +#else
15281 + movl $cpu_gdt_table, %ebx
15282 +#endif
15283 shr $16, %edx
15284 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15285 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15286 +
15287 +#ifdef CONFIG_PAX_KERNEXEC
15288 + mov %cr0, %esi
15289 + btr $16, %esi
15290 + mov %esi, %cr0
15291 +#endif
15292 +
15293 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15294 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15295 +
15296 +#ifdef CONFIG_PAX_KERNEXEC
15297 + bts $16, %esi
15298 + mov %esi, %cr0
15299 +#endif
15300 +
15301 pushl_cfi $__ESPFIX_SS
15302 pushl_cfi %eax /* new kernel esp */
15303 /* Disable interrupts, but do not irqtrace this section: we
15304 @@ -615,38 +826,30 @@ work_resched:
15305 movl TI_flags(%ebp), %ecx
15306 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15307 # than syscall tracing?
15308 - jz restore_all
15309 + jz restore_all_pax
15310 testb $_TIF_NEED_RESCHED, %cl
15311 jnz work_resched
15312
15313 work_notifysig: # deal with pending signals and
15314 # notify-resume requests
15315 + movl %esp, %eax
15316 #ifdef CONFIG_VM86
15317 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15318 - movl %esp, %eax
15319 - jne work_notifysig_v86 # returning to kernel-space or
15320 + jz 1f # returning to kernel-space or
15321 # vm86-space
15322 - TRACE_IRQS_ON
15323 - ENABLE_INTERRUPTS(CLBR_NONE)
15324 - xorl %edx, %edx
15325 - call do_notify_resume
15326 - jmp resume_userspace_sig
15327
15328 - ALIGN
15329 -work_notifysig_v86:
15330 pushl_cfi %ecx # save ti_flags for do_notify_resume
15331 call save_v86_state # %eax contains pt_regs pointer
15332 popl_cfi %ecx
15333 movl %eax, %esp
15334 -#else
15335 - movl %esp, %eax
15336 +1:
15337 #endif
15338 TRACE_IRQS_ON
15339 ENABLE_INTERRUPTS(CLBR_NONE)
15340 xorl %edx, %edx
15341 call do_notify_resume
15342 jmp resume_userspace_sig
15343 -END(work_pending)
15344 +ENDPROC(work_pending)
15345
15346 # perform syscall exit tracing
15347 ALIGN
15348 @@ -654,11 +857,14 @@ syscall_trace_entry:
15349 movl $-ENOSYS,PT_EAX(%esp)
15350 movl %esp, %eax
15351 call syscall_trace_enter
15352 +
15353 + pax_erase_kstack
15354 +
15355 /* What it returned is what we'll actually use. */
15356 cmpl $(NR_syscalls), %eax
15357 jnae syscall_call
15358 jmp syscall_exit
15359 -END(syscall_trace_entry)
15360 +ENDPROC(syscall_trace_entry)
15361
15362 # perform syscall exit tracing
15363 ALIGN
15364 @@ -671,20 +877,24 @@ syscall_exit_work:
15365 movl %esp, %eax
15366 call syscall_trace_leave
15367 jmp resume_userspace
15368 -END(syscall_exit_work)
15369 +ENDPROC(syscall_exit_work)
15370 CFI_ENDPROC
15371
15372 RING0_INT_FRAME # can't unwind into user space anyway
15373 syscall_fault:
15374 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15375 + push %ss
15376 + pop %ds
15377 +#endif
15378 GET_THREAD_INFO(%ebp)
15379 movl $-EFAULT,PT_EAX(%esp)
15380 jmp resume_userspace
15381 -END(syscall_fault)
15382 +ENDPROC(syscall_fault)
15383
15384 syscall_badsys:
15385 movl $-ENOSYS,PT_EAX(%esp)
15386 jmp resume_userspace
15387 -END(syscall_badsys)
15388 +ENDPROC(syscall_badsys)
15389 CFI_ENDPROC
15390 /*
15391 * End of kprobes section
15392 @@ -756,6 +966,36 @@ ENTRY(ptregs_clone)
15393 CFI_ENDPROC
15394 ENDPROC(ptregs_clone)
15395
15396 + ALIGN;
15397 +ENTRY(kernel_execve)
15398 + CFI_STARTPROC
15399 + pushl_cfi %ebp
15400 + sub $PT_OLDSS+4,%esp
15401 + pushl_cfi %edi
15402 + pushl_cfi %ecx
15403 + pushl_cfi %eax
15404 + lea 3*4(%esp),%edi
15405 + mov $PT_OLDSS/4+1,%ecx
15406 + xorl %eax,%eax
15407 + rep stosl
15408 + popl_cfi %eax
15409 + popl_cfi %ecx
15410 + popl_cfi %edi
15411 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15412 + pushl_cfi %esp
15413 + call sys_execve
15414 + add $4,%esp
15415 + CFI_ADJUST_CFA_OFFSET -4
15416 + GET_THREAD_INFO(%ebp)
15417 + test %eax,%eax
15418 + jz syscall_exit
15419 + add $PT_OLDSS+4,%esp
15420 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15421 + popl_cfi %ebp
15422 + ret
15423 + CFI_ENDPROC
15424 +ENDPROC(kernel_execve)
15425 +
15426 .macro FIXUP_ESPFIX_STACK
15427 /*
15428 * Switch back for ESPFIX stack to the normal zerobased stack
15429 @@ -765,8 +1005,15 @@ ENDPROC(ptregs_clone)
15430 * normal stack and adjusts ESP with the matching offset.
15431 */
15432 /* fixup the stack */
15433 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15434 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15435 +#ifdef CONFIG_SMP
15436 + movl PER_CPU_VAR(cpu_number), %ebx
15437 + shll $PAGE_SHIFT_asm, %ebx
15438 + addl $cpu_gdt_table, %ebx
15439 +#else
15440 + movl $cpu_gdt_table, %ebx
15441 +#endif
15442 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15443 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15444 shl $16, %eax
15445 addl %esp, %eax /* the adjusted stack pointer */
15446 pushl_cfi $__KERNEL_DS
15447 @@ -819,7 +1066,7 @@ vector=vector+1
15448 .endr
15449 2: jmp common_interrupt
15450 .endr
15451 -END(irq_entries_start)
15452 +ENDPROC(irq_entries_start)
15453
15454 .previous
15455 END(interrupt)
15456 @@ -867,7 +1114,7 @@ ENTRY(coprocessor_error)
15457 pushl_cfi $do_coprocessor_error
15458 jmp error_code
15459 CFI_ENDPROC
15460 -END(coprocessor_error)
15461 +ENDPROC(coprocessor_error)
15462
15463 ENTRY(simd_coprocessor_error)
15464 RING0_INT_FRAME
15465 @@ -888,7 +1135,7 @@ ENTRY(simd_coprocessor_error)
15466 #endif
15467 jmp error_code
15468 CFI_ENDPROC
15469 -END(simd_coprocessor_error)
15470 +ENDPROC(simd_coprocessor_error)
15471
15472 ENTRY(device_not_available)
15473 RING0_INT_FRAME
15474 @@ -896,7 +1143,7 @@ ENTRY(device_not_available)
15475 pushl_cfi $do_device_not_available
15476 jmp error_code
15477 CFI_ENDPROC
15478 -END(device_not_available)
15479 +ENDPROC(device_not_available)
15480
15481 #ifdef CONFIG_PARAVIRT
15482 ENTRY(native_iret)
15483 @@ -905,12 +1152,12 @@ ENTRY(native_iret)
15484 .align 4
15485 .long native_iret, iret_exc
15486 .previous
15487 -END(native_iret)
15488 +ENDPROC(native_iret)
15489
15490 ENTRY(native_irq_enable_sysexit)
15491 sti
15492 sysexit
15493 -END(native_irq_enable_sysexit)
15494 +ENDPROC(native_irq_enable_sysexit)
15495 #endif
15496
15497 ENTRY(overflow)
15498 @@ -919,7 +1166,7 @@ ENTRY(overflow)
15499 pushl_cfi $do_overflow
15500 jmp error_code
15501 CFI_ENDPROC
15502 -END(overflow)
15503 +ENDPROC(overflow)
15504
15505 ENTRY(bounds)
15506 RING0_INT_FRAME
15507 @@ -927,7 +1174,7 @@ ENTRY(bounds)
15508 pushl_cfi $do_bounds
15509 jmp error_code
15510 CFI_ENDPROC
15511 -END(bounds)
15512 +ENDPROC(bounds)
15513
15514 ENTRY(invalid_op)
15515 RING0_INT_FRAME
15516 @@ -935,7 +1182,7 @@ ENTRY(invalid_op)
15517 pushl_cfi $do_invalid_op
15518 jmp error_code
15519 CFI_ENDPROC
15520 -END(invalid_op)
15521 +ENDPROC(invalid_op)
15522
15523 ENTRY(coprocessor_segment_overrun)
15524 RING0_INT_FRAME
15525 @@ -943,35 +1190,35 @@ ENTRY(coprocessor_segment_overrun)
15526 pushl_cfi $do_coprocessor_segment_overrun
15527 jmp error_code
15528 CFI_ENDPROC
15529 -END(coprocessor_segment_overrun)
15530 +ENDPROC(coprocessor_segment_overrun)
15531
15532 ENTRY(invalid_TSS)
15533 RING0_EC_FRAME
15534 pushl_cfi $do_invalid_TSS
15535 jmp error_code
15536 CFI_ENDPROC
15537 -END(invalid_TSS)
15538 +ENDPROC(invalid_TSS)
15539
15540 ENTRY(segment_not_present)
15541 RING0_EC_FRAME
15542 pushl_cfi $do_segment_not_present
15543 jmp error_code
15544 CFI_ENDPROC
15545 -END(segment_not_present)
15546 +ENDPROC(segment_not_present)
15547
15548 ENTRY(stack_segment)
15549 RING0_EC_FRAME
15550 pushl_cfi $do_stack_segment
15551 jmp error_code
15552 CFI_ENDPROC
15553 -END(stack_segment)
15554 +ENDPROC(stack_segment)
15555
15556 ENTRY(alignment_check)
15557 RING0_EC_FRAME
15558 pushl_cfi $do_alignment_check
15559 jmp error_code
15560 CFI_ENDPROC
15561 -END(alignment_check)
15562 +ENDPROC(alignment_check)
15563
15564 ENTRY(divide_error)
15565 RING0_INT_FRAME
15566 @@ -979,7 +1226,7 @@ ENTRY(divide_error)
15567 pushl_cfi $do_divide_error
15568 jmp error_code
15569 CFI_ENDPROC
15570 -END(divide_error)
15571 +ENDPROC(divide_error)
15572
15573 #ifdef CONFIG_X86_MCE
15574 ENTRY(machine_check)
15575 @@ -988,7 +1235,7 @@ ENTRY(machine_check)
15576 pushl_cfi machine_check_vector
15577 jmp error_code
15578 CFI_ENDPROC
15579 -END(machine_check)
15580 +ENDPROC(machine_check)
15581 #endif
15582
15583 ENTRY(spurious_interrupt_bug)
15584 @@ -997,7 +1244,7 @@ ENTRY(spurious_interrupt_bug)
15585 pushl_cfi $do_spurious_interrupt_bug
15586 jmp error_code
15587 CFI_ENDPROC
15588 -END(spurious_interrupt_bug)
15589 +ENDPROC(spurious_interrupt_bug)
15590 /*
15591 * End of kprobes section
15592 */
15593 @@ -1112,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15594
15595 ENTRY(mcount)
15596 ret
15597 -END(mcount)
15598 +ENDPROC(mcount)
15599
15600 ENTRY(ftrace_caller)
15601 cmpl $0, function_trace_stop
15602 @@ -1141,7 +1388,7 @@ ftrace_graph_call:
15603 .globl ftrace_stub
15604 ftrace_stub:
15605 ret
15606 -END(ftrace_caller)
15607 +ENDPROC(ftrace_caller)
15608
15609 #else /* ! CONFIG_DYNAMIC_FTRACE */
15610
15611 @@ -1177,7 +1424,7 @@ trace:
15612 popl %ecx
15613 popl %eax
15614 jmp ftrace_stub
15615 -END(mcount)
15616 +ENDPROC(mcount)
15617 #endif /* CONFIG_DYNAMIC_FTRACE */
15618 #endif /* CONFIG_FUNCTION_TRACER */
15619
15620 @@ -1198,7 +1445,7 @@ ENTRY(ftrace_graph_caller)
15621 popl %ecx
15622 popl %eax
15623 ret
15624 -END(ftrace_graph_caller)
15625 +ENDPROC(ftrace_graph_caller)
15626
15627 .globl return_to_handler
15628 return_to_handler:
15629 @@ -1253,15 +1500,18 @@ error_code:
15630 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15631 REG_TO_PTGS %ecx
15632 SET_KERNEL_GS %ecx
15633 - movl $(__USER_DS), %ecx
15634 + movl $(__KERNEL_DS), %ecx
15635 movl %ecx, %ds
15636 movl %ecx, %es
15637 +
15638 + pax_enter_kernel
15639 +
15640 TRACE_IRQS_OFF
15641 movl %esp,%eax # pt_regs pointer
15642 call *%edi
15643 jmp ret_from_exception
15644 CFI_ENDPROC
15645 -END(page_fault)
15646 +ENDPROC(page_fault)
15647
15648 /*
15649 * Debug traps and NMI can happen at the one SYSENTER instruction
15650 @@ -1303,7 +1553,7 @@ debug_stack_correct:
15651 call do_debug
15652 jmp ret_from_exception
15653 CFI_ENDPROC
15654 -END(debug)
15655 +ENDPROC(debug)
15656
15657 /*
15658 * NMI is doubly nasty. It can happen _while_ we're handling
15659 @@ -1340,6 +1590,9 @@ nmi_stack_correct:
15660 xorl %edx,%edx # zero error code
15661 movl %esp,%eax # pt_regs pointer
15662 call do_nmi
15663 +
15664 + pax_exit_kernel
15665 +
15666 jmp restore_all_notrace
15667 CFI_ENDPROC
15668
15669 @@ -1376,12 +1629,15 @@ nmi_espfix_stack:
15670 FIXUP_ESPFIX_STACK # %eax == %esp
15671 xorl %edx,%edx # zero error code
15672 call do_nmi
15673 +
15674 + pax_exit_kernel
15675 +
15676 RESTORE_REGS
15677 lss 12+4(%esp), %esp # back to espfix stack
15678 CFI_ADJUST_CFA_OFFSET -24
15679 jmp irq_return
15680 CFI_ENDPROC
15681 -END(nmi)
15682 +ENDPROC(nmi)
15683
15684 ENTRY(int3)
15685 RING0_INT_FRAME
15686 @@ -1393,14 +1649,14 @@ ENTRY(int3)
15687 call do_int3
15688 jmp ret_from_exception
15689 CFI_ENDPROC
15690 -END(int3)
15691 +ENDPROC(int3)
15692
15693 ENTRY(general_protection)
15694 RING0_EC_FRAME
15695 pushl_cfi $do_general_protection
15696 jmp error_code
15697 CFI_ENDPROC
15698 -END(general_protection)
15699 +ENDPROC(general_protection)
15700
15701 #ifdef CONFIG_KVM_GUEST
15702 ENTRY(async_page_fault)
15703 @@ -1408,7 +1664,7 @@ ENTRY(async_page_fault)
15704 pushl_cfi $do_async_page_fault
15705 jmp error_code
15706 CFI_ENDPROC
15707 -END(async_page_fault)
15708 +ENDPROC(async_page_fault)
15709 #endif
15710
15711 /*
15712 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15713 index cdc79b5..4710a75 100644
15714 --- a/arch/x86/kernel/entry_64.S
15715 +++ b/arch/x86/kernel/entry_64.S
15716 @@ -56,6 +56,8 @@
15717 #include <asm/ftrace.h>
15718 #include <asm/percpu.h>
15719 #include <linux/err.h>
15720 +#include <asm/pgtable.h>
15721 +#include <asm/alternative-asm.h>
15722
15723 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15724 #include <linux/elf-em.h>
15725 @@ -69,8 +71,9 @@
15726 #ifdef CONFIG_FUNCTION_TRACER
15727 #ifdef CONFIG_DYNAMIC_FTRACE
15728 ENTRY(mcount)
15729 + pax_force_retaddr
15730 retq
15731 -END(mcount)
15732 +ENDPROC(mcount)
15733
15734 ENTRY(ftrace_caller)
15735 cmpl $0, function_trace_stop
15736 @@ -93,8 +96,9 @@ GLOBAL(ftrace_graph_call)
15737 #endif
15738
15739 GLOBAL(ftrace_stub)
15740 + pax_force_retaddr
15741 retq
15742 -END(ftrace_caller)
15743 +ENDPROC(ftrace_caller)
15744
15745 #else /* ! CONFIG_DYNAMIC_FTRACE */
15746 ENTRY(mcount)
15747 @@ -113,6 +117,7 @@ ENTRY(mcount)
15748 #endif
15749
15750 GLOBAL(ftrace_stub)
15751 + pax_force_retaddr
15752 retq
15753
15754 trace:
15755 @@ -122,12 +127,13 @@ trace:
15756 movq 8(%rbp), %rsi
15757 subq $MCOUNT_INSN_SIZE, %rdi
15758
15759 + pax_force_fptr ftrace_trace_function
15760 call *ftrace_trace_function
15761
15762 MCOUNT_RESTORE_FRAME
15763
15764 jmp ftrace_stub
15765 -END(mcount)
15766 +ENDPROC(mcount)
15767 #endif /* CONFIG_DYNAMIC_FTRACE */
15768 #endif /* CONFIG_FUNCTION_TRACER */
15769
15770 @@ -147,8 +153,9 @@ ENTRY(ftrace_graph_caller)
15771
15772 MCOUNT_RESTORE_FRAME
15773
15774 + pax_force_retaddr
15775 retq
15776 -END(ftrace_graph_caller)
15777 +ENDPROC(ftrace_graph_caller)
15778
15779 GLOBAL(return_to_handler)
15780 subq $24, %rsp
15781 @@ -164,6 +171,7 @@ GLOBAL(return_to_handler)
15782 movq 8(%rsp), %rdx
15783 movq (%rsp), %rax
15784 addq $24, %rsp
15785 + pax_force_fptr %rdi
15786 jmp *%rdi
15787 #endif
15788
15789 @@ -179,6 +187,282 @@ ENTRY(native_usergs_sysret64)
15790 ENDPROC(native_usergs_sysret64)
15791 #endif /* CONFIG_PARAVIRT */
15792
15793 + .macro ljmpq sel, off
15794 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15795 + .byte 0x48; ljmp *1234f(%rip)
15796 + .pushsection .rodata
15797 + .align 16
15798 + 1234: .quad \off; .word \sel
15799 + .popsection
15800 +#else
15801 + pushq $\sel
15802 + pushq $\off
15803 + lretq
15804 +#endif
15805 + .endm
15806 +
15807 + .macro pax_enter_kernel
15808 + pax_set_fptr_mask
15809 +#ifdef CONFIG_PAX_KERNEXEC
15810 + call pax_enter_kernel
15811 +#endif
15812 + .endm
15813 +
15814 + .macro pax_exit_kernel
15815 +#ifdef CONFIG_PAX_KERNEXEC
15816 + call pax_exit_kernel
15817 +#endif
15818 + .endm
15819 +
15820 +#ifdef CONFIG_PAX_KERNEXEC
15821 +ENTRY(pax_enter_kernel)
15822 + pushq %rdi
15823 +
15824 +#ifdef CONFIG_PARAVIRT
15825 + PV_SAVE_REGS(CLBR_RDI)
15826 +#endif
15827 +
15828 + GET_CR0_INTO_RDI
15829 + bts $16,%rdi
15830 + jnc 3f
15831 + mov %cs,%edi
15832 + cmp $__KERNEL_CS,%edi
15833 + jnz 2f
15834 +1:
15835 +
15836 +#ifdef CONFIG_PARAVIRT
15837 + PV_RESTORE_REGS(CLBR_RDI)
15838 +#endif
15839 +
15840 + popq %rdi
15841 + pax_force_retaddr
15842 + retq
15843 +
15844 +2: ljmpq __KERNEL_CS,1f
15845 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
15846 +4: SET_RDI_INTO_CR0
15847 + jmp 1b
15848 +ENDPROC(pax_enter_kernel)
15849 +
15850 +ENTRY(pax_exit_kernel)
15851 + pushq %rdi
15852 +
15853 +#ifdef CONFIG_PARAVIRT
15854 + PV_SAVE_REGS(CLBR_RDI)
15855 +#endif
15856 +
15857 + mov %cs,%rdi
15858 + cmp $__KERNEXEC_KERNEL_CS,%edi
15859 + jz 2f
15860 +1:
15861 +
15862 +#ifdef CONFIG_PARAVIRT
15863 + PV_RESTORE_REGS(CLBR_RDI);
15864 +#endif
15865 +
15866 + popq %rdi
15867 + pax_force_retaddr
15868 + retq
15869 +
15870 +2: GET_CR0_INTO_RDI
15871 + btr $16,%rdi
15872 + ljmpq __KERNEL_CS,3f
15873 +3: SET_RDI_INTO_CR0
15874 + jmp 1b
15875 +#ifdef CONFIG_PARAVIRT
15876 + PV_RESTORE_REGS(CLBR_RDI);
15877 +#endif
15878 +
15879 + popq %rdi
15880 + pax_force_retaddr
15881 + retq
15882 +ENDPROC(pax_exit_kernel)
15883 +#endif
15884 +
15885 + .macro pax_enter_kernel_user
15886 + pax_set_fptr_mask
15887 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15888 + call pax_enter_kernel_user
15889 +#endif
15890 + .endm
15891 +
15892 + .macro pax_exit_kernel_user
15893 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15894 + call pax_exit_kernel_user
15895 +#endif
15896 +#ifdef CONFIG_PAX_RANDKSTACK
15897 + pushq %rax
15898 + call pax_randomize_kstack
15899 + popq %rax
15900 +#endif
15901 + .endm
15902 +
15903 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15904 +ENTRY(pax_enter_kernel_user)
15905 + pushq %rdi
15906 + pushq %rbx
15907 +
15908 +#ifdef CONFIG_PARAVIRT
15909 + PV_SAVE_REGS(CLBR_RDI)
15910 +#endif
15911 +
15912 + GET_CR3_INTO_RDI
15913 + mov %rdi,%rbx
15914 + add $__START_KERNEL_map,%rbx
15915 + sub phys_base(%rip),%rbx
15916 +
15917 +#ifdef CONFIG_PARAVIRT
15918 + pushq %rdi
15919 + cmpl $0, pv_info+PARAVIRT_enabled
15920 + jz 1f
15921 + i = 0
15922 + .rept USER_PGD_PTRS
15923 + mov i*8(%rbx),%rsi
15924 + mov $0,%sil
15925 + lea i*8(%rbx),%rdi
15926 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15927 + i = i + 1
15928 + .endr
15929 + jmp 2f
15930 +1:
15931 +#endif
15932 +
15933 + i = 0
15934 + .rept USER_PGD_PTRS
15935 + movb $0,i*8(%rbx)
15936 + i = i + 1
15937 + .endr
15938 +
15939 +#ifdef CONFIG_PARAVIRT
15940 +2: popq %rdi
15941 +#endif
15942 + SET_RDI_INTO_CR3
15943 +
15944 +#ifdef CONFIG_PAX_KERNEXEC
15945 + GET_CR0_INTO_RDI
15946 + bts $16,%rdi
15947 + SET_RDI_INTO_CR0
15948 +#endif
15949 +
15950 +#ifdef CONFIG_PARAVIRT
15951 + PV_RESTORE_REGS(CLBR_RDI)
15952 +#endif
15953 +
15954 + popq %rbx
15955 + popq %rdi
15956 + pax_force_retaddr
15957 + retq
15958 +ENDPROC(pax_enter_kernel_user)
15959 +
15960 +ENTRY(pax_exit_kernel_user)
15961 + push %rdi
15962 +
15963 +#ifdef CONFIG_PARAVIRT
15964 + pushq %rbx
15965 + PV_SAVE_REGS(CLBR_RDI)
15966 +#endif
15967 +
15968 +#ifdef CONFIG_PAX_KERNEXEC
15969 + GET_CR0_INTO_RDI
15970 + btr $16,%rdi
15971 + SET_RDI_INTO_CR0
15972 +#endif
15973 +
15974 + GET_CR3_INTO_RDI
15975 + add $__START_KERNEL_map,%rdi
15976 + sub phys_base(%rip),%rdi
15977 +
15978 +#ifdef CONFIG_PARAVIRT
15979 + cmpl $0, pv_info+PARAVIRT_enabled
15980 + jz 1f
15981 + mov %rdi,%rbx
15982 + i = 0
15983 + .rept USER_PGD_PTRS
15984 + mov i*8(%rbx),%rsi
15985 + mov $0x67,%sil
15986 + lea i*8(%rbx),%rdi
15987 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15988 + i = i + 1
15989 + .endr
15990 + jmp 2f
15991 +1:
15992 +#endif
15993 +
15994 + i = 0
15995 + .rept USER_PGD_PTRS
15996 + movb $0x67,i*8(%rdi)
15997 + i = i + 1
15998 + .endr
15999 +
16000 +#ifdef CONFIG_PARAVIRT
16001 +2: PV_RESTORE_REGS(CLBR_RDI)
16002 + popq %rbx
16003 +#endif
16004 +
16005 + popq %rdi
16006 + pax_force_retaddr
16007 + retq
16008 +ENDPROC(pax_exit_kernel_user)
16009 +#endif
16010 +
16011 +.macro pax_erase_kstack
16012 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16013 + call pax_erase_kstack
16014 +#endif
16015 +.endm
16016 +
16017 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16018 +/*
16019 + * r11: thread_info
16020 + * rcx, rdx: can be clobbered
16021 + */
16022 +ENTRY(pax_erase_kstack)
16023 + pushq %rdi
16024 + pushq %rax
16025 + pushq %r11
16026 +
16027 + GET_THREAD_INFO(%r11)
16028 + mov TI_lowest_stack(%r11), %rdi
16029 + mov $-0xBEEF, %rax
16030 + std
16031 +
16032 +1: mov %edi, %ecx
16033 + and $THREAD_SIZE_asm - 1, %ecx
16034 + shr $3, %ecx
16035 + repne scasq
16036 + jecxz 2f
16037 +
16038 + cmp $2*8, %ecx
16039 + jc 2f
16040 +
16041 + mov $2*8, %ecx
16042 + repe scasq
16043 + jecxz 2f
16044 + jne 1b
16045 +
16046 +2: cld
16047 + mov %esp, %ecx
16048 + sub %edi, %ecx
16049 +
16050 + cmp $THREAD_SIZE_asm, %rcx
16051 + jb 3f
16052 + ud2
16053 +3:
16054 +
16055 + shr $3, %ecx
16056 + rep stosq
16057 +
16058 + mov TI_task_thread_sp0(%r11), %rdi
16059 + sub $256, %rdi
16060 + mov %rdi, TI_lowest_stack(%r11)
16061 +
16062 + popq %r11
16063 + popq %rax
16064 + popq %rdi
16065 + pax_force_retaddr
16066 + ret
16067 +ENDPROC(pax_erase_kstack)
16068 +#endif
16069
16070 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
16071 #ifdef CONFIG_TRACE_IRQFLAGS
16072 @@ -232,8 +516,8 @@ ENDPROC(native_usergs_sysret64)
16073 .endm
16074
16075 .macro UNFAKE_STACK_FRAME
16076 - addq $8*6, %rsp
16077 - CFI_ADJUST_CFA_OFFSET -(6*8)
16078 + addq $8*6 + ARG_SKIP, %rsp
16079 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
16080 .endm
16081
16082 /*
16083 @@ -320,7 +604,7 @@ ENDPROC(native_usergs_sysret64)
16084 movq %rsp, %rsi
16085
16086 leaq -RBP(%rsp),%rdi /* arg1 for handler */
16087 - testl $3, CS-RBP(%rsi)
16088 + testb $3, CS-RBP(%rsi)
16089 je 1f
16090 SWAPGS
16091 /*
16092 @@ -355,9 +639,10 @@ ENTRY(save_rest)
16093 movq_cfi r15, R15+16
16094 movq %r11, 8(%rsp) /* return address */
16095 FIXUP_TOP_OF_STACK %r11, 16
16096 + pax_force_retaddr
16097 ret
16098 CFI_ENDPROC
16099 -END(save_rest)
16100 +ENDPROC(save_rest)
16101
16102 /* save complete stack frame */
16103 .pushsection .kprobes.text, "ax"
16104 @@ -386,9 +671,10 @@ ENTRY(save_paranoid)
16105 js 1f /* negative -> in kernel */
16106 SWAPGS
16107 xorl %ebx,%ebx
16108 -1: ret
16109 +1: pax_force_retaddr_bts
16110 + ret
16111 CFI_ENDPROC
16112 -END(save_paranoid)
16113 +ENDPROC(save_paranoid)
16114 .popsection
16115
16116 /*
16117 @@ -410,7 +696,7 @@ ENTRY(ret_from_fork)
16118
16119 RESTORE_REST
16120
16121 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16122 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16123 jz retint_restore_args
16124
16125 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16126 @@ -420,7 +706,7 @@ ENTRY(ret_from_fork)
16127 jmp ret_from_sys_call # go to the SYSRET fastpath
16128
16129 CFI_ENDPROC
16130 -END(ret_from_fork)
16131 +ENDPROC(ret_from_fork)
16132
16133 /*
16134 * System call entry. Up to 6 arguments in registers are supported.
16135 @@ -456,7 +742,7 @@ END(ret_from_fork)
16136 ENTRY(system_call)
16137 CFI_STARTPROC simple
16138 CFI_SIGNAL_FRAME
16139 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16140 + CFI_DEF_CFA rsp,0
16141 CFI_REGISTER rip,rcx
16142 /*CFI_REGISTER rflags,r11*/
16143 SWAPGS_UNSAFE_STACK
16144 @@ -469,16 +755,18 @@ GLOBAL(system_call_after_swapgs)
16145
16146 movq %rsp,PER_CPU_VAR(old_rsp)
16147 movq PER_CPU_VAR(kernel_stack),%rsp
16148 + SAVE_ARGS 8*6,0
16149 + pax_enter_kernel_user
16150 /*
16151 * No need to follow this irqs off/on section - it's straight
16152 * and short:
16153 */
16154 ENABLE_INTERRUPTS(CLBR_NONE)
16155 - SAVE_ARGS 8,0
16156 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16157 movq %rcx,RIP-ARGOFFSET(%rsp)
16158 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16159 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16160 + GET_THREAD_INFO(%rcx)
16161 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16162 jnz tracesys
16163 system_call_fastpath:
16164 #if __SYSCALL_MASK == ~0
16165 @@ -488,7 +776,7 @@ system_call_fastpath:
16166 cmpl $__NR_syscall_max,%eax
16167 #endif
16168 ja badsys
16169 - movq %r10,%rcx
16170 + movq R10-ARGOFFSET(%rsp),%rcx
16171 call *sys_call_table(,%rax,8) # XXX: rip relative
16172 movq %rax,RAX-ARGOFFSET(%rsp)
16173 /*
16174 @@ -502,10 +790,13 @@ sysret_check:
16175 LOCKDEP_SYS_EXIT
16176 DISABLE_INTERRUPTS(CLBR_NONE)
16177 TRACE_IRQS_OFF
16178 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16179 + GET_THREAD_INFO(%rcx)
16180 + movl TI_flags(%rcx),%edx
16181 andl %edi,%edx
16182 jnz sysret_careful
16183 CFI_REMEMBER_STATE
16184 + pax_exit_kernel_user
16185 + pax_erase_kstack
16186 /*
16187 * sysretq will re-enable interrupts:
16188 */
16189 @@ -557,14 +848,18 @@ badsys:
16190 * jump back to the normal fast path.
16191 */
16192 auditsys:
16193 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
16194 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16195 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16196 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16197 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16198 movq %rax,%rsi /* 2nd arg: syscall number */
16199 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16200 call __audit_syscall_entry
16201 +
16202 + pax_erase_kstack
16203 +
16204 LOAD_ARGS 0 /* reload call-clobbered registers */
16205 + pax_set_fptr_mask
16206 jmp system_call_fastpath
16207
16208 /*
16209 @@ -585,7 +880,7 @@ sysret_audit:
16210 /* Do syscall tracing */
16211 tracesys:
16212 #ifdef CONFIG_AUDITSYSCALL
16213 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16214 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16215 jz auditsys
16216 #endif
16217 SAVE_REST
16218 @@ -593,12 +888,16 @@ tracesys:
16219 FIXUP_TOP_OF_STACK %rdi
16220 movq %rsp,%rdi
16221 call syscall_trace_enter
16222 +
16223 + pax_erase_kstack
16224 +
16225 /*
16226 * Reload arg registers from stack in case ptrace changed them.
16227 * We don't reload %rax because syscall_trace_enter() returned
16228 * the value it wants us to use in the table lookup.
16229 */
16230 LOAD_ARGS ARGOFFSET, 1
16231 + pax_set_fptr_mask
16232 RESTORE_REST
16233 #if __SYSCALL_MASK == ~0
16234 cmpq $__NR_syscall_max,%rax
16235 @@ -607,7 +906,7 @@ tracesys:
16236 cmpl $__NR_syscall_max,%eax
16237 #endif
16238 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16239 - movq %r10,%rcx /* fixup for C */
16240 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16241 call *sys_call_table(,%rax,8)
16242 movq %rax,RAX-ARGOFFSET(%rsp)
16243 /* Use IRET because user could have changed frame */
16244 @@ -628,6 +927,7 @@ GLOBAL(int_with_check)
16245 andl %edi,%edx
16246 jnz int_careful
16247 andl $~TS_COMPAT,TI_status(%rcx)
16248 + pax_erase_kstack
16249 jmp retint_swapgs
16250
16251 /* Either reschedule or signal or syscall exit tracking needed. */
16252 @@ -674,7 +974,7 @@ int_restore_rest:
16253 TRACE_IRQS_OFF
16254 jmp int_with_check
16255 CFI_ENDPROC
16256 -END(system_call)
16257 +ENDPROC(system_call)
16258
16259 /*
16260 * Certain special system calls that need to save a complete full stack frame.
16261 @@ -690,7 +990,7 @@ ENTRY(\label)
16262 call \func
16263 jmp ptregscall_common
16264 CFI_ENDPROC
16265 -END(\label)
16266 +ENDPROC(\label)
16267 .endm
16268
16269 PTREGSCALL stub_clone, sys_clone, %r8
16270 @@ -708,9 +1008,10 @@ ENTRY(ptregscall_common)
16271 movq_cfi_restore R12+8, r12
16272 movq_cfi_restore RBP+8, rbp
16273 movq_cfi_restore RBX+8, rbx
16274 + pax_force_retaddr
16275 ret $REST_SKIP /* pop extended registers */
16276 CFI_ENDPROC
16277 -END(ptregscall_common)
16278 +ENDPROC(ptregscall_common)
16279
16280 ENTRY(stub_execve)
16281 CFI_STARTPROC
16282 @@ -725,7 +1026,7 @@ ENTRY(stub_execve)
16283 RESTORE_REST
16284 jmp int_ret_from_sys_call
16285 CFI_ENDPROC
16286 -END(stub_execve)
16287 +ENDPROC(stub_execve)
16288
16289 /*
16290 * sigreturn is special because it needs to restore all registers on return.
16291 @@ -743,7 +1044,7 @@ ENTRY(stub_rt_sigreturn)
16292 RESTORE_REST
16293 jmp int_ret_from_sys_call
16294 CFI_ENDPROC
16295 -END(stub_rt_sigreturn)
16296 +ENDPROC(stub_rt_sigreturn)
16297
16298 #ifdef CONFIG_X86_X32_ABI
16299 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16300 @@ -812,7 +1113,7 @@ vector=vector+1
16301 2: jmp common_interrupt
16302 .endr
16303 CFI_ENDPROC
16304 -END(irq_entries_start)
16305 +ENDPROC(irq_entries_start)
16306
16307 .previous
16308 END(interrupt)
16309 @@ -832,6 +1133,16 @@ END(interrupt)
16310 subq $ORIG_RAX-RBP, %rsp
16311 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16312 SAVE_ARGS_IRQ
16313 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16314 + testb $3, CS(%rdi)
16315 + jnz 1f
16316 + pax_enter_kernel
16317 + jmp 2f
16318 +1: pax_enter_kernel_user
16319 +2:
16320 +#else
16321 + pax_enter_kernel
16322 +#endif
16323 call \func
16324 .endm
16325
16326 @@ -863,7 +1174,7 @@ ret_from_intr:
16327
16328 exit_intr:
16329 GET_THREAD_INFO(%rcx)
16330 - testl $3,CS-ARGOFFSET(%rsp)
16331 + testb $3,CS-ARGOFFSET(%rsp)
16332 je retint_kernel
16333
16334 /* Interrupt came from user space */
16335 @@ -885,12 +1196,15 @@ retint_swapgs: /* return to user-space */
16336 * The iretq could re-enable interrupts:
16337 */
16338 DISABLE_INTERRUPTS(CLBR_ANY)
16339 + pax_exit_kernel_user
16340 TRACE_IRQS_IRETQ
16341 SWAPGS
16342 jmp restore_args
16343
16344 retint_restore_args: /* return to kernel space */
16345 DISABLE_INTERRUPTS(CLBR_ANY)
16346 + pax_exit_kernel
16347 + pax_force_retaddr RIP-ARGOFFSET
16348 /*
16349 * The iretq could re-enable interrupts:
16350 */
16351 @@ -979,7 +1293,7 @@ ENTRY(retint_kernel)
16352 #endif
16353
16354 CFI_ENDPROC
16355 -END(common_interrupt)
16356 +ENDPROC(common_interrupt)
16357 /*
16358 * End of kprobes section
16359 */
16360 @@ -996,7 +1310,7 @@ ENTRY(\sym)
16361 interrupt \do_sym
16362 jmp ret_from_intr
16363 CFI_ENDPROC
16364 -END(\sym)
16365 +ENDPROC(\sym)
16366 .endm
16367
16368 #ifdef CONFIG_SMP
16369 @@ -1069,12 +1383,22 @@ ENTRY(\sym)
16370 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16371 call error_entry
16372 DEFAULT_FRAME 0
16373 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16374 + testb $3, CS(%rsp)
16375 + jnz 1f
16376 + pax_enter_kernel
16377 + jmp 2f
16378 +1: pax_enter_kernel_user
16379 +2:
16380 +#else
16381 + pax_enter_kernel
16382 +#endif
16383 movq %rsp,%rdi /* pt_regs pointer */
16384 xorl %esi,%esi /* no error code */
16385 call \do_sym
16386 jmp error_exit /* %ebx: no swapgs flag */
16387 CFI_ENDPROC
16388 -END(\sym)
16389 +ENDPROC(\sym)
16390 .endm
16391
16392 .macro paranoidzeroentry sym do_sym
16393 @@ -1086,15 +1410,25 @@ ENTRY(\sym)
16394 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16395 call save_paranoid
16396 TRACE_IRQS_OFF
16397 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16398 + testb $3, CS(%rsp)
16399 + jnz 1f
16400 + pax_enter_kernel
16401 + jmp 2f
16402 +1: pax_enter_kernel_user
16403 +2:
16404 +#else
16405 + pax_enter_kernel
16406 +#endif
16407 movq %rsp,%rdi /* pt_regs pointer */
16408 xorl %esi,%esi /* no error code */
16409 call \do_sym
16410 jmp paranoid_exit /* %ebx: no swapgs flag */
16411 CFI_ENDPROC
16412 -END(\sym)
16413 +ENDPROC(\sym)
16414 .endm
16415
16416 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16417 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16418 .macro paranoidzeroentry_ist sym do_sym ist
16419 ENTRY(\sym)
16420 INTR_FRAME
16421 @@ -1104,14 +1438,30 @@ ENTRY(\sym)
16422 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16423 call save_paranoid
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 xorl %esi,%esi /* no error code */
16437 +#ifdef CONFIG_SMP
16438 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16439 + lea init_tss(%r12), %r12
16440 +#else
16441 + lea init_tss(%rip), %r12
16442 +#endif
16443 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16444 call \do_sym
16445 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16446 jmp paranoid_exit /* %ebx: no swapgs flag */
16447 CFI_ENDPROC
16448 -END(\sym)
16449 +ENDPROC(\sym)
16450 .endm
16451
16452 .macro errorentry sym do_sym
16453 @@ -1122,13 +1472,23 @@ ENTRY(\sym)
16454 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16455 call error_entry
16456 DEFAULT_FRAME 0
16457 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16458 + testb $3, CS(%rsp)
16459 + jnz 1f
16460 + pax_enter_kernel
16461 + jmp 2f
16462 +1: pax_enter_kernel_user
16463 +2:
16464 +#else
16465 + pax_enter_kernel
16466 +#endif
16467 movq %rsp,%rdi /* pt_regs pointer */
16468 movq ORIG_RAX(%rsp),%rsi /* get error code */
16469 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16470 call \do_sym
16471 jmp error_exit /* %ebx: no swapgs flag */
16472 CFI_ENDPROC
16473 -END(\sym)
16474 +ENDPROC(\sym)
16475 .endm
16476
16477 /* error code is on the stack already */
16478 @@ -1141,13 +1501,23 @@ ENTRY(\sym)
16479 call save_paranoid
16480 DEFAULT_FRAME 0
16481 TRACE_IRQS_OFF
16482 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16483 + testb $3, CS(%rsp)
16484 + jnz 1f
16485 + pax_enter_kernel
16486 + jmp 2f
16487 +1: pax_enter_kernel_user
16488 +2:
16489 +#else
16490 + pax_enter_kernel
16491 +#endif
16492 movq %rsp,%rdi /* pt_regs pointer */
16493 movq ORIG_RAX(%rsp),%rsi /* get error code */
16494 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16495 call \do_sym
16496 jmp paranoid_exit /* %ebx: no swapgs flag */
16497 CFI_ENDPROC
16498 -END(\sym)
16499 +ENDPROC(\sym)
16500 .endm
16501
16502 zeroentry divide_error do_divide_error
16503 @@ -1177,9 +1547,10 @@ gs_change:
16504 2: mfence /* workaround */
16505 SWAPGS
16506 popfq_cfi
16507 + pax_force_retaddr
16508 ret
16509 CFI_ENDPROC
16510 -END(native_load_gs_index)
16511 +ENDPROC(native_load_gs_index)
16512
16513 .section __ex_table,"a"
16514 .align 8
16515 @@ -1201,13 +1572,14 @@ ENTRY(kernel_thread_helper)
16516 * Here we are in the child and the registers are set as they were
16517 * at kernel_thread() invocation in the parent.
16518 */
16519 + pax_force_fptr %rsi
16520 call *%rsi
16521 # exit
16522 mov %eax, %edi
16523 call do_exit
16524 ud2 # padding for call trace
16525 CFI_ENDPROC
16526 -END(kernel_thread_helper)
16527 +ENDPROC(kernel_thread_helper)
16528
16529 /*
16530 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16531 @@ -1234,11 +1606,11 @@ ENTRY(kernel_execve)
16532 RESTORE_REST
16533 testq %rax,%rax
16534 je int_ret_from_sys_call
16535 - RESTORE_ARGS
16536 UNFAKE_STACK_FRAME
16537 + pax_force_retaddr
16538 ret
16539 CFI_ENDPROC
16540 -END(kernel_execve)
16541 +ENDPROC(kernel_execve)
16542
16543 /* Call softirq on interrupt stack. Interrupts are off. */
16544 ENTRY(call_softirq)
16545 @@ -1256,9 +1628,10 @@ ENTRY(call_softirq)
16546 CFI_DEF_CFA_REGISTER rsp
16547 CFI_ADJUST_CFA_OFFSET -8
16548 decl PER_CPU_VAR(irq_count)
16549 + pax_force_retaddr
16550 ret
16551 CFI_ENDPROC
16552 -END(call_softirq)
16553 +ENDPROC(call_softirq)
16554
16555 #ifdef CONFIG_XEN
16556 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16557 @@ -1296,7 +1669,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16558 decl PER_CPU_VAR(irq_count)
16559 jmp error_exit
16560 CFI_ENDPROC
16561 -END(xen_do_hypervisor_callback)
16562 +ENDPROC(xen_do_hypervisor_callback)
16563
16564 /*
16565 * Hypervisor uses this for application faults while it executes.
16566 @@ -1355,7 +1728,7 @@ ENTRY(xen_failsafe_callback)
16567 SAVE_ALL
16568 jmp error_exit
16569 CFI_ENDPROC
16570 -END(xen_failsafe_callback)
16571 +ENDPROC(xen_failsafe_callback)
16572
16573 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16574 xen_hvm_callback_vector xen_evtchn_do_upcall
16575 @@ -1404,16 +1777,31 @@ ENTRY(paranoid_exit)
16576 TRACE_IRQS_OFF
16577 testl %ebx,%ebx /* swapgs needed? */
16578 jnz paranoid_restore
16579 - testl $3,CS(%rsp)
16580 + testb $3,CS(%rsp)
16581 jnz paranoid_userspace
16582 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16583 + pax_exit_kernel
16584 + TRACE_IRQS_IRETQ 0
16585 + SWAPGS_UNSAFE_STACK
16586 + RESTORE_ALL 8
16587 + pax_force_retaddr_bts
16588 + jmp irq_return
16589 +#endif
16590 paranoid_swapgs:
16591 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16592 + pax_exit_kernel_user
16593 +#else
16594 + pax_exit_kernel
16595 +#endif
16596 TRACE_IRQS_IRETQ 0
16597 SWAPGS_UNSAFE_STACK
16598 RESTORE_ALL 8
16599 jmp irq_return
16600 paranoid_restore:
16601 + pax_exit_kernel
16602 TRACE_IRQS_IRETQ 0
16603 RESTORE_ALL 8
16604 + pax_force_retaddr_bts
16605 jmp irq_return
16606 paranoid_userspace:
16607 GET_THREAD_INFO(%rcx)
16608 @@ -1442,7 +1830,7 @@ paranoid_schedule:
16609 TRACE_IRQS_OFF
16610 jmp paranoid_userspace
16611 CFI_ENDPROC
16612 -END(paranoid_exit)
16613 +ENDPROC(paranoid_exit)
16614
16615 /*
16616 * Exception entry point. This expects an error code/orig_rax on the stack.
16617 @@ -1469,12 +1857,13 @@ ENTRY(error_entry)
16618 movq_cfi r14, R14+8
16619 movq_cfi r15, R15+8
16620 xorl %ebx,%ebx
16621 - testl $3,CS+8(%rsp)
16622 + testb $3,CS+8(%rsp)
16623 je error_kernelspace
16624 error_swapgs:
16625 SWAPGS
16626 error_sti:
16627 TRACE_IRQS_OFF
16628 + pax_force_retaddr_bts
16629 ret
16630
16631 /*
16632 @@ -1501,7 +1890,7 @@ bstep_iret:
16633 movq %rcx,RIP+8(%rsp)
16634 jmp error_swapgs
16635 CFI_ENDPROC
16636 -END(error_entry)
16637 +ENDPROC(error_entry)
16638
16639
16640 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16641 @@ -1521,7 +1910,7 @@ ENTRY(error_exit)
16642 jnz retint_careful
16643 jmp retint_swapgs
16644 CFI_ENDPROC
16645 -END(error_exit)
16646 +ENDPROC(error_exit)
16647
16648 /*
16649 * Test if a given stack is an NMI stack or not.
16650 @@ -1579,9 +1968,11 @@ ENTRY(nmi)
16651 * If %cs was not the kernel segment, then the NMI triggered in user
16652 * space, which means it is definitely not nested.
16653 */
16654 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16655 + je 1f
16656 cmpl $__KERNEL_CS, 16(%rsp)
16657 jne first_nmi
16658 -
16659 +1:
16660 /*
16661 * Check the special variable on the stack to see if NMIs are
16662 * executing.
16663 @@ -1728,6 +2119,16 @@ end_repeat_nmi:
16664 */
16665 call save_paranoid
16666 DEFAULT_FRAME 0
16667 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16668 + testb $3, CS(%rsp)
16669 + jnz 1f
16670 + pax_enter_kernel
16671 + jmp 2f
16672 +1: pax_enter_kernel_user
16673 +2:
16674 +#else
16675 + pax_enter_kernel
16676 +#endif
16677 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16678 movq %rsp,%rdi
16679 movq $-1,%rsi
16680 @@ -1735,21 +2136,32 @@ end_repeat_nmi:
16681 testl %ebx,%ebx /* swapgs needed? */
16682 jnz nmi_restore
16683 nmi_swapgs:
16684 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16685 + pax_exit_kernel_user
16686 +#else
16687 + pax_exit_kernel
16688 +#endif
16689 SWAPGS_UNSAFE_STACK
16690 + RESTORE_ALL 8
16691 + /* Clear the NMI executing stack variable */
16692 + movq $0, 10*8(%rsp)
16693 + jmp irq_return
16694 nmi_restore:
16695 + pax_exit_kernel
16696 RESTORE_ALL 8
16697 + pax_force_retaddr_bts
16698 /* Clear the NMI executing stack variable */
16699 movq $0, 10*8(%rsp)
16700 jmp irq_return
16701 CFI_ENDPROC
16702 -END(nmi)
16703 +ENDPROC(nmi)
16704
16705 ENTRY(ignore_sysret)
16706 CFI_STARTPROC
16707 mov $-ENOSYS,%eax
16708 sysret
16709 CFI_ENDPROC
16710 -END(ignore_sysret)
16711 +ENDPROC(ignore_sysret)
16712
16713 /*
16714 * End of kprobes section
16715 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16716 index c9a281f..ce2f317 100644
16717 --- a/arch/x86/kernel/ftrace.c
16718 +++ b/arch/x86/kernel/ftrace.c
16719 @@ -126,7 +126,7 @@ static void *mod_code_ip; /* holds the IP to write to */
16720 static const void *mod_code_newcode; /* holds the text to write to the IP */
16721
16722 static unsigned nmi_wait_count;
16723 -static atomic_t nmi_update_count = ATOMIC_INIT(0);
16724 +static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
16725
16726 int ftrace_arch_read_dyn_info(char *buf, int size)
16727 {
16728 @@ -134,7 +134,7 @@ int ftrace_arch_read_dyn_info(char *buf, int size)
16729
16730 r = snprintf(buf, size, "%u %u",
16731 nmi_wait_count,
16732 - atomic_read(&nmi_update_count));
16733 + atomic_read_unchecked(&nmi_update_count));
16734 return r;
16735 }
16736
16737 @@ -177,8 +177,10 @@ void ftrace_nmi_enter(void)
16738
16739 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
16740 smp_rmb();
16741 + pax_open_kernel();
16742 ftrace_mod_code();
16743 - atomic_inc(&nmi_update_count);
16744 + pax_close_kernel();
16745 + atomic_inc_unchecked(&nmi_update_count);
16746 }
16747 /* Must have previous changes seen before executions */
16748 smp_mb();
16749 @@ -271,6 +273,8 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
16750 {
16751 unsigned char replaced[MCOUNT_INSN_SIZE];
16752
16753 + ip = ktla_ktva(ip);
16754 +
16755 /*
16756 * Note: Due to modules and __init, code can
16757 * disappear and change, we need to protect against faulting
16758 @@ -327,7 +331,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16759 unsigned char old[MCOUNT_INSN_SIZE], *new;
16760 int ret;
16761
16762 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16763 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16764 new = ftrace_call_replace(ip, (unsigned long)func);
16765 ret = ftrace_modify_code(ip, old, new);
16766
16767 @@ -353,6 +357,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16768 {
16769 unsigned char code[MCOUNT_INSN_SIZE];
16770
16771 + ip = ktla_ktva(ip);
16772 +
16773 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16774 return -EFAULT;
16775
16776 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16777 index 51ff186..9e77418 100644
16778 --- a/arch/x86/kernel/head32.c
16779 +++ b/arch/x86/kernel/head32.c
16780 @@ -19,6 +19,7 @@
16781 #include <asm/io_apic.h>
16782 #include <asm/bios_ebda.h>
16783 #include <asm/tlbflush.h>
16784 +#include <asm/boot.h>
16785
16786 static void __init i386_default_early_setup(void)
16787 {
16788 @@ -31,8 +32,7 @@ static void __init i386_default_early_setup(void)
16789
16790 void __init i386_start_kernel(void)
16791 {
16792 - memblock_reserve(__pa_symbol(&_text),
16793 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16794 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16795
16796 #ifdef CONFIG_BLK_DEV_INITRD
16797 /* Reserve INITRD */
16798 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16799 index ce0be7c..c41476e 100644
16800 --- a/arch/x86/kernel/head_32.S
16801 +++ b/arch/x86/kernel/head_32.S
16802 @@ -25,6 +25,12 @@
16803 /* Physical address */
16804 #define pa(X) ((X) - __PAGE_OFFSET)
16805
16806 +#ifdef CONFIG_PAX_KERNEXEC
16807 +#define ta(X) (X)
16808 +#else
16809 +#define ta(X) ((X) - __PAGE_OFFSET)
16810 +#endif
16811 +
16812 /*
16813 * References to members of the new_cpu_data structure.
16814 */
16815 @@ -54,11 +60,7 @@
16816 * and small than max_low_pfn, otherwise will waste some page table entries
16817 */
16818
16819 -#if PTRS_PER_PMD > 1
16820 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16821 -#else
16822 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16823 -#endif
16824 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16825
16826 /* Number of possible pages in the lowmem region */
16827 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16828 @@ -77,6 +79,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16829 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16830
16831 /*
16832 + * Real beginning of normal "text" segment
16833 + */
16834 +ENTRY(stext)
16835 +ENTRY(_stext)
16836 +
16837 +/*
16838 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16839 * %esi points to the real-mode code as a 32-bit pointer.
16840 * CS and DS must be 4 GB flat segments, but we don't depend on
16841 @@ -84,6 +92,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16842 * can.
16843 */
16844 __HEAD
16845 +
16846 +#ifdef CONFIG_PAX_KERNEXEC
16847 + jmp startup_32
16848 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16849 +.fill PAGE_SIZE-5,1,0xcc
16850 +#endif
16851 +
16852 ENTRY(startup_32)
16853 movl pa(stack_start),%ecx
16854
16855 @@ -105,6 +120,57 @@ ENTRY(startup_32)
16856 2:
16857 leal -__PAGE_OFFSET(%ecx),%esp
16858
16859 +#ifdef CONFIG_SMP
16860 + movl $pa(cpu_gdt_table),%edi
16861 + movl $__per_cpu_load,%eax
16862 + movw %ax,__KERNEL_PERCPU + 2(%edi)
16863 + rorl $16,%eax
16864 + movb %al,__KERNEL_PERCPU + 4(%edi)
16865 + movb %ah,__KERNEL_PERCPU + 7(%edi)
16866 + movl $__per_cpu_end - 1,%eax
16867 + subl $__per_cpu_start,%eax
16868 + movw %ax,__KERNEL_PERCPU + 0(%edi)
16869 +#endif
16870 +
16871 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16872 + movl $NR_CPUS,%ecx
16873 + movl $pa(cpu_gdt_table),%edi
16874 +1:
16875 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16876 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16877 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16878 + addl $PAGE_SIZE_asm,%edi
16879 + loop 1b
16880 +#endif
16881 +
16882 +#ifdef CONFIG_PAX_KERNEXEC
16883 + movl $pa(boot_gdt),%edi
16884 + movl $__LOAD_PHYSICAL_ADDR,%eax
16885 + movw %ax,__BOOT_CS + 2(%edi)
16886 + rorl $16,%eax
16887 + movb %al,__BOOT_CS + 4(%edi)
16888 + movb %ah,__BOOT_CS + 7(%edi)
16889 + rorl $16,%eax
16890 +
16891 + ljmp $(__BOOT_CS),$1f
16892 +1:
16893 +
16894 + movl $NR_CPUS,%ecx
16895 + movl $pa(cpu_gdt_table),%edi
16896 + addl $__PAGE_OFFSET,%eax
16897 +1:
16898 + movw %ax,__KERNEL_CS + 2(%edi)
16899 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16900 + rorl $16,%eax
16901 + movb %al,__KERNEL_CS + 4(%edi)
16902 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16903 + movb %ah,__KERNEL_CS + 7(%edi)
16904 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16905 + rorl $16,%eax
16906 + addl $PAGE_SIZE_asm,%edi
16907 + loop 1b
16908 +#endif
16909 +
16910 /*
16911 * Clear BSS first so that there are no surprises...
16912 */
16913 @@ -195,8 +261,11 @@ ENTRY(startup_32)
16914 movl %eax, pa(max_pfn_mapped)
16915
16916 /* Do early initialization of the fixmap area */
16917 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16918 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16919 +#ifdef CONFIG_COMPAT_VDSO
16920 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16921 +#else
16922 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16923 +#endif
16924 #else /* Not PAE */
16925
16926 page_pde_offset = (__PAGE_OFFSET >> 20);
16927 @@ -226,8 +295,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16928 movl %eax, pa(max_pfn_mapped)
16929
16930 /* Do early initialization of the fixmap area */
16931 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16932 - movl %eax,pa(initial_page_table+0xffc)
16933 +#ifdef CONFIG_COMPAT_VDSO
16934 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16935 +#else
16936 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16937 +#endif
16938 #endif
16939
16940 #ifdef CONFIG_PARAVIRT
16941 @@ -241,9 +313,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16942 cmpl $num_subarch_entries, %eax
16943 jae bad_subarch
16944
16945 - movl pa(subarch_entries)(,%eax,4), %eax
16946 - subl $__PAGE_OFFSET, %eax
16947 - jmp *%eax
16948 + jmp *pa(subarch_entries)(,%eax,4)
16949
16950 bad_subarch:
16951 WEAK(lguest_entry)
16952 @@ -255,10 +325,10 @@ WEAK(xen_entry)
16953 __INITDATA
16954
16955 subarch_entries:
16956 - .long default_entry /* normal x86/PC */
16957 - .long lguest_entry /* lguest hypervisor */
16958 - .long xen_entry /* Xen hypervisor */
16959 - .long default_entry /* Moorestown MID */
16960 + .long ta(default_entry) /* normal x86/PC */
16961 + .long ta(lguest_entry) /* lguest hypervisor */
16962 + .long ta(xen_entry) /* Xen hypervisor */
16963 + .long ta(default_entry) /* Moorestown MID */
16964 num_subarch_entries = (. - subarch_entries) / 4
16965 .previous
16966 #else
16967 @@ -312,6 +382,7 @@ default_entry:
16968 orl %edx,%eax
16969 movl %eax,%cr4
16970
16971 +#ifdef CONFIG_X86_PAE
16972 testb $X86_CR4_PAE, %al # check if PAE is enabled
16973 jz 6f
16974
16975 @@ -340,6 +411,9 @@ default_entry:
16976 /* Make changes effective */
16977 wrmsr
16978
16979 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
16980 +#endif
16981 +
16982 6:
16983
16984 /*
16985 @@ -443,7 +517,7 @@ is386: movl $2,%ecx # set MP
16986 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
16987 movl %eax,%ss # after changing gdt.
16988
16989 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
16990 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
16991 movl %eax,%ds
16992 movl %eax,%es
16993
16994 @@ -457,15 +531,22 @@ is386: movl $2,%ecx # set MP
16995 */
16996 cmpb $0,ready
16997 jne 1f
16998 - movl $gdt_page,%eax
16999 + movl $cpu_gdt_table,%eax
17000 movl $stack_canary,%ecx
17001 +#ifdef CONFIG_SMP
17002 + addl $__per_cpu_load,%ecx
17003 +#endif
17004 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
17005 shrl $16, %ecx
17006 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
17007 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
17008 1:
17009 -#endif
17010 movl $(__KERNEL_STACK_CANARY),%eax
17011 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17012 + movl $(__USER_DS),%eax
17013 +#else
17014 + xorl %eax,%eax
17015 +#endif
17016 movl %eax,%gs
17017
17018 xorl %eax,%eax # Clear LDT
17019 @@ -558,22 +639,22 @@ early_page_fault:
17020 jmp early_fault
17021
17022 early_fault:
17023 - cld
17024 #ifdef CONFIG_PRINTK
17025 + cmpl $1,%ss:early_recursion_flag
17026 + je hlt_loop
17027 + incl %ss:early_recursion_flag
17028 + cld
17029 pusha
17030 movl $(__KERNEL_DS),%eax
17031 movl %eax,%ds
17032 movl %eax,%es
17033 - cmpl $2,early_recursion_flag
17034 - je hlt_loop
17035 - incl early_recursion_flag
17036 movl %cr2,%eax
17037 pushl %eax
17038 pushl %edx /* trapno */
17039 pushl $fault_msg
17040 call printk
17041 +; call dump_stack
17042 #endif
17043 - call dump_stack
17044 hlt_loop:
17045 hlt
17046 jmp hlt_loop
17047 @@ -581,8 +662,11 @@ hlt_loop:
17048 /* This is the default interrupt "handler" :-) */
17049 ALIGN
17050 ignore_int:
17051 - cld
17052 #ifdef CONFIG_PRINTK
17053 + cmpl $2,%ss:early_recursion_flag
17054 + je hlt_loop
17055 + incl %ss:early_recursion_flag
17056 + cld
17057 pushl %eax
17058 pushl %ecx
17059 pushl %edx
17060 @@ -591,9 +675,6 @@ ignore_int:
17061 movl $(__KERNEL_DS),%eax
17062 movl %eax,%ds
17063 movl %eax,%es
17064 - cmpl $2,early_recursion_flag
17065 - je hlt_loop
17066 - incl early_recursion_flag
17067 pushl 16(%esp)
17068 pushl 24(%esp)
17069 pushl 32(%esp)
17070 @@ -622,29 +703,43 @@ ENTRY(initial_code)
17071 /*
17072 * BSS section
17073 */
17074 -__PAGE_ALIGNED_BSS
17075 - .align PAGE_SIZE
17076 #ifdef CONFIG_X86_PAE
17077 +.section .initial_pg_pmd,"a",@progbits
17078 initial_pg_pmd:
17079 .fill 1024*KPMDS,4,0
17080 #else
17081 +.section .initial_page_table,"a",@progbits
17082 ENTRY(initial_page_table)
17083 .fill 1024,4,0
17084 #endif
17085 +.section .initial_pg_fixmap,"a",@progbits
17086 initial_pg_fixmap:
17087 .fill 1024,4,0
17088 +.section .empty_zero_page,"a",@progbits
17089 ENTRY(empty_zero_page)
17090 .fill 4096,1,0
17091 +.section .swapper_pg_dir,"a",@progbits
17092 ENTRY(swapper_pg_dir)
17093 +#ifdef CONFIG_X86_PAE
17094 + .fill 4,8,0
17095 +#else
17096 .fill 1024,4,0
17097 +#endif
17098 +
17099 +/*
17100 + * The IDT has to be page-aligned to simplify the Pentium
17101 + * F0 0F bug workaround.. We have a special link segment
17102 + * for this.
17103 + */
17104 +.section .idt,"a",@progbits
17105 +ENTRY(idt_table)
17106 + .fill 256,8,0
17107
17108 /*
17109 * This starts the data section.
17110 */
17111 #ifdef CONFIG_X86_PAE
17112 -__PAGE_ALIGNED_DATA
17113 - /* Page-aligned for the benefit of paravirt? */
17114 - .align PAGE_SIZE
17115 +.section .initial_page_table,"a",@progbits
17116 ENTRY(initial_page_table)
17117 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17118 # if KPMDS == 3
17119 @@ -663,18 +758,27 @@ ENTRY(initial_page_table)
17120 # error "Kernel PMDs should be 1, 2 or 3"
17121 # endif
17122 .align PAGE_SIZE /* needs to be page-sized too */
17123 +
17124 +#ifdef CONFIG_PAX_PER_CPU_PGD
17125 +ENTRY(cpu_pgd)
17126 + .rept NR_CPUS
17127 + .fill 4,8,0
17128 + .endr
17129 +#endif
17130 +
17131 #endif
17132
17133 .data
17134 .balign 4
17135 ENTRY(stack_start)
17136 - .long init_thread_union+THREAD_SIZE
17137 + .long init_thread_union+THREAD_SIZE-8
17138
17139 +ready: .byte 0
17140 +
17141 +.section .rodata,"a",@progbits
17142 early_recursion_flag:
17143 .long 0
17144
17145 -ready: .byte 0
17146 -
17147 int_msg:
17148 .asciz "Unknown interrupt or fault at: %p %p %p\n"
17149
17150 @@ -707,7 +811,7 @@ fault_msg:
17151 .word 0 # 32 bit align gdt_desc.address
17152 boot_gdt_descr:
17153 .word __BOOT_DS+7
17154 - .long boot_gdt - __PAGE_OFFSET
17155 + .long pa(boot_gdt)
17156
17157 .word 0 # 32-bit align idt_desc.address
17158 idt_descr:
17159 @@ -718,7 +822,7 @@ idt_descr:
17160 .word 0 # 32 bit align gdt_desc.address
17161 ENTRY(early_gdt_descr)
17162 .word GDT_ENTRIES*8-1
17163 - .long gdt_page /* Overwritten for secondary CPUs */
17164 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
17165
17166 /*
17167 * The boot_gdt must mirror the equivalent in setup.S and is
17168 @@ -727,5 +831,65 @@ ENTRY(early_gdt_descr)
17169 .align L1_CACHE_BYTES
17170 ENTRY(boot_gdt)
17171 .fill GDT_ENTRY_BOOT_CS,8,0
17172 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17173 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17174 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17175 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17176 +
17177 + .align PAGE_SIZE_asm
17178 +ENTRY(cpu_gdt_table)
17179 + .rept NR_CPUS
17180 + .quad 0x0000000000000000 /* NULL descriptor */
17181 + .quad 0x0000000000000000 /* 0x0b reserved */
17182 + .quad 0x0000000000000000 /* 0x13 reserved */
17183 + .quad 0x0000000000000000 /* 0x1b reserved */
17184 +
17185 +#ifdef CONFIG_PAX_KERNEXEC
17186 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17187 +#else
17188 + .quad 0x0000000000000000 /* 0x20 unused */
17189 +#endif
17190 +
17191 + .quad 0x0000000000000000 /* 0x28 unused */
17192 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17193 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17194 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17195 + .quad 0x0000000000000000 /* 0x4b reserved */
17196 + .quad 0x0000000000000000 /* 0x53 reserved */
17197 + .quad 0x0000000000000000 /* 0x5b reserved */
17198 +
17199 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17200 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17201 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17202 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17203 +
17204 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17205 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17206 +
17207 + /*
17208 + * Segments used for calling PnP BIOS have byte granularity.
17209 + * The code segments and data segments have fixed 64k limits,
17210 + * the transfer segment sizes are set at run time.
17211 + */
17212 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
17213 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
17214 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
17215 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
17216 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
17217 +
17218 + /*
17219 + * The APM segments have byte granularity and their bases
17220 + * are set at run time. All have 64k limits.
17221 + */
17222 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17223 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17224 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
17225 +
17226 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17227 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17228 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17229 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17230 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17231 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17232 +
17233 + /* Be sure this is zeroed to avoid false validations in Xen */
17234 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17235 + .endr
17236 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17237 index 40f4eb3..6d24d9d 100644
17238 --- a/arch/x86/kernel/head_64.S
17239 +++ b/arch/x86/kernel/head_64.S
17240 @@ -19,6 +19,8 @@
17241 #include <asm/cache.h>
17242 #include <asm/processor-flags.h>
17243 #include <asm/percpu.h>
17244 +#include <asm/cpufeature.h>
17245 +#include <asm/alternative-asm.h>
17246
17247 #ifdef CONFIG_PARAVIRT
17248 #include <asm/asm-offsets.h>
17249 @@ -38,6 +40,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17250 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17251 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17252 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17253 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
17254 +L3_VMALLOC_START = pud_index(VMALLOC_START)
17255 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
17256 +L3_VMALLOC_END = pud_index(VMALLOC_END)
17257 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17258 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17259
17260 .text
17261 __HEAD
17262 @@ -85,35 +93,23 @@ startup_64:
17263 */
17264 addq %rbp, init_level4_pgt + 0(%rip)
17265 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17266 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17267 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17268 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17269 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17270
17271 addq %rbp, level3_ident_pgt + 0(%rip)
17272 +#ifndef CONFIG_XEN
17273 + addq %rbp, level3_ident_pgt + 8(%rip)
17274 +#endif
17275
17276 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17277 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17278 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17279 +
17280 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17281 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17282
17283 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17284 -
17285 - /* Add an Identity mapping if I am above 1G */
17286 - leaq _text(%rip), %rdi
17287 - andq $PMD_PAGE_MASK, %rdi
17288 -
17289 - movq %rdi, %rax
17290 - shrq $PUD_SHIFT, %rax
17291 - andq $(PTRS_PER_PUD - 1), %rax
17292 - jz ident_complete
17293 -
17294 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17295 - leaq level3_ident_pgt(%rip), %rbx
17296 - movq %rdx, 0(%rbx, %rax, 8)
17297 -
17298 - movq %rdi, %rax
17299 - shrq $PMD_SHIFT, %rax
17300 - andq $(PTRS_PER_PMD - 1), %rax
17301 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17302 - leaq level2_spare_pgt(%rip), %rbx
17303 - movq %rdx, 0(%rbx, %rax, 8)
17304 -ident_complete:
17305 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17306
17307 /*
17308 * Fixup the kernel text+data virtual addresses. Note that
17309 @@ -160,8 +156,8 @@ ENTRY(secondary_startup_64)
17310 * after the boot processor executes this code.
17311 */
17312
17313 - /* Enable PAE mode and PGE */
17314 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17315 + /* Enable PAE mode and PSE/PGE */
17316 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17317 movq %rax, %cr4
17318
17319 /* Setup early boot stage 4 level pagetables. */
17320 @@ -183,9 +179,17 @@ ENTRY(secondary_startup_64)
17321 movl $MSR_EFER, %ecx
17322 rdmsr
17323 btsl $_EFER_SCE, %eax /* Enable System Call */
17324 - btl $20,%edi /* No Execute supported? */
17325 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17326 jnc 1f
17327 btsl $_EFER_NX, %eax
17328 + leaq init_level4_pgt(%rip), %rdi
17329 +#ifndef CONFIG_EFI
17330 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17331 +#endif
17332 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17333 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17334 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17335 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17336 1: wrmsr /* Make changes effective */
17337
17338 /* Setup cr0 */
17339 @@ -247,6 +251,7 @@ ENTRY(secondary_startup_64)
17340 * jump. In addition we need to ensure %cs is set so we make this
17341 * a far return.
17342 */
17343 + pax_set_fptr_mask
17344 movq initial_code(%rip),%rax
17345 pushq $0 # fake return address to stop unwinder
17346 pushq $__KERNEL_CS # set correct cs
17347 @@ -269,7 +274,7 @@ ENTRY(secondary_startup_64)
17348 bad_address:
17349 jmp bad_address
17350
17351 - .section ".init.text","ax"
17352 + __INIT
17353 #ifdef CONFIG_EARLY_PRINTK
17354 .globl early_idt_handlers
17355 early_idt_handlers:
17356 @@ -314,18 +319,23 @@ ENTRY(early_idt_handler)
17357 #endif /* EARLY_PRINTK */
17358 1: hlt
17359 jmp 1b
17360 + .previous
17361
17362 #ifdef CONFIG_EARLY_PRINTK
17363 + __INITDATA
17364 early_recursion_flag:
17365 .long 0
17366 + .previous
17367
17368 + .section .rodata,"a",@progbits
17369 early_idt_msg:
17370 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17371 early_idt_ripmsg:
17372 .asciz "RIP %s\n"
17373 + .previous
17374 #endif /* CONFIG_EARLY_PRINTK */
17375 - .previous
17376
17377 + .section .rodata,"a",@progbits
17378 #define NEXT_PAGE(name) \
17379 .balign PAGE_SIZE; \
17380 ENTRY(name)
17381 @@ -338,7 +348,6 @@ ENTRY(name)
17382 i = i + 1 ; \
17383 .endr
17384
17385 - .data
17386 /*
17387 * This default setting generates an ident mapping at address 0x100000
17388 * and a mapping for the kernel that precisely maps virtual address
17389 @@ -349,13 +358,41 @@ NEXT_PAGE(init_level4_pgt)
17390 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17391 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17392 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17393 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
17394 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17395 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
17396 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17397 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17398 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17399 .org init_level4_pgt + L4_START_KERNEL*8, 0
17400 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17401 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17402
17403 +#ifdef CONFIG_PAX_PER_CPU_PGD
17404 +NEXT_PAGE(cpu_pgd)
17405 + .rept NR_CPUS
17406 + .fill 512,8,0
17407 + .endr
17408 +#endif
17409 +
17410 NEXT_PAGE(level3_ident_pgt)
17411 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17412 +#ifdef CONFIG_XEN
17413 .fill 511,8,0
17414 +#else
17415 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17416 + .fill 510,8,0
17417 +#endif
17418 +
17419 +NEXT_PAGE(level3_vmalloc_start_pgt)
17420 + .fill 512,8,0
17421 +
17422 +NEXT_PAGE(level3_vmalloc_end_pgt)
17423 + .fill 512,8,0
17424 +
17425 +NEXT_PAGE(level3_vmemmap_pgt)
17426 + .fill L3_VMEMMAP_START,8,0
17427 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17428
17429 NEXT_PAGE(level3_kernel_pgt)
17430 .fill L3_START_KERNEL,8,0
17431 @@ -363,20 +400,23 @@ NEXT_PAGE(level3_kernel_pgt)
17432 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17433 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17434
17435 +NEXT_PAGE(level2_vmemmap_pgt)
17436 + .fill 512,8,0
17437 +
17438 NEXT_PAGE(level2_fixmap_pgt)
17439 - .fill 506,8,0
17440 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17441 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17442 - .fill 5,8,0
17443 + .fill 507,8,0
17444 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17445 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17446 + .fill 4,8,0
17447
17448 -NEXT_PAGE(level1_fixmap_pgt)
17449 +NEXT_PAGE(level1_vsyscall_pgt)
17450 .fill 512,8,0
17451
17452 -NEXT_PAGE(level2_ident_pgt)
17453 - /* Since I easily can, map the first 1G.
17454 + /* Since I easily can, map the first 2G.
17455 * Don't set NX because code runs from these pages.
17456 */
17457 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17458 +NEXT_PAGE(level2_ident_pgt)
17459 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17460
17461 NEXT_PAGE(level2_kernel_pgt)
17462 /*
17463 @@ -389,37 +429,59 @@ NEXT_PAGE(level2_kernel_pgt)
17464 * If you want to increase this then increase MODULES_VADDR
17465 * too.)
17466 */
17467 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17468 - KERNEL_IMAGE_SIZE/PMD_SIZE)
17469 -
17470 -NEXT_PAGE(level2_spare_pgt)
17471 - .fill 512, 8, 0
17472 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17473
17474 #undef PMDS
17475 #undef NEXT_PAGE
17476
17477 - .data
17478 + .align PAGE_SIZE
17479 +ENTRY(cpu_gdt_table)
17480 + .rept NR_CPUS
17481 + .quad 0x0000000000000000 /* NULL descriptor */
17482 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17483 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
17484 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
17485 + .quad 0x00cffb000000ffff /* __USER32_CS */
17486 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17487 + .quad 0x00affb000000ffff /* __USER_CS */
17488 +
17489 +#ifdef CONFIG_PAX_KERNEXEC
17490 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17491 +#else
17492 + .quad 0x0 /* unused */
17493 +#endif
17494 +
17495 + .quad 0,0 /* TSS */
17496 + .quad 0,0 /* LDT */
17497 + .quad 0,0,0 /* three TLS descriptors */
17498 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
17499 + /* asm/segment.h:GDT_ENTRIES must match this */
17500 +
17501 + /* zero the remaining page */
17502 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17503 + .endr
17504 +
17505 .align 16
17506 .globl early_gdt_descr
17507 early_gdt_descr:
17508 .word GDT_ENTRIES*8-1
17509 early_gdt_descr_base:
17510 - .quad INIT_PER_CPU_VAR(gdt_page)
17511 + .quad cpu_gdt_table
17512
17513 ENTRY(phys_base)
17514 /* This must match the first entry in level2_kernel_pgt */
17515 .quad 0x0000000000000000
17516
17517 #include "../../x86/xen/xen-head.S"
17518 -
17519 - .section .bss, "aw", @nobits
17520 +
17521 + .section .rodata,"a",@progbits
17522 .align L1_CACHE_BYTES
17523 ENTRY(idt_table)
17524 - .skip IDT_ENTRIES * 16
17525 + .fill 512,8,0
17526
17527 .align L1_CACHE_BYTES
17528 ENTRY(nmi_idt_table)
17529 - .skip IDT_ENTRIES * 16
17530 + .fill 512,8,0
17531
17532 __PAGE_ALIGNED_BSS
17533 .align PAGE_SIZE
17534 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17535 index 9c3bd4a..e1d9b35 100644
17536 --- a/arch/x86/kernel/i386_ksyms_32.c
17537 +++ b/arch/x86/kernel/i386_ksyms_32.c
17538 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17539 EXPORT_SYMBOL(cmpxchg8b_emu);
17540 #endif
17541
17542 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
17543 +
17544 /* Networking helper routines. */
17545 EXPORT_SYMBOL(csum_partial_copy_generic);
17546 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17547 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17548
17549 EXPORT_SYMBOL(__get_user_1);
17550 EXPORT_SYMBOL(__get_user_2);
17551 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17552
17553 EXPORT_SYMBOL(csum_partial);
17554 EXPORT_SYMBOL(empty_zero_page);
17555 +
17556 +#ifdef CONFIG_PAX_KERNEXEC
17557 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17558 +#endif
17559 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17560 index 2d6e649..df6e1af 100644
17561 --- a/arch/x86/kernel/i387.c
17562 +++ b/arch/x86/kernel/i387.c
17563 @@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17564 static inline bool interrupted_user_mode(void)
17565 {
17566 struct pt_regs *regs = get_irq_regs();
17567 - return regs && user_mode_vm(regs);
17568 + return regs && user_mode(regs);
17569 }
17570
17571 /*
17572 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17573 index 36d1853..bf25736 100644
17574 --- a/arch/x86/kernel/i8259.c
17575 +++ b/arch/x86/kernel/i8259.c
17576 @@ -209,7 +209,7 @@ spurious_8259A_irq:
17577 "spurious 8259A interrupt: IRQ%d.\n", irq);
17578 spurious_irq_mask |= irqmask;
17579 }
17580 - atomic_inc(&irq_err_count);
17581 + atomic_inc_unchecked(&irq_err_count);
17582 /*
17583 * Theoretically we do not have to handle this IRQ,
17584 * but in Linux this does not cause problems and is
17585 diff --git a/arch/x86/kernel/init_task.c b/arch/x86/kernel/init_task.c
17586 index 43e9ccf..44ccf6f 100644
17587 --- a/arch/x86/kernel/init_task.c
17588 +++ b/arch/x86/kernel/init_task.c
17589 @@ -20,8 +20,7 @@ static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
17590 * way process stacks are handled. This is done by having a special
17591 * "init_task" linker map entry..
17592 */
17593 -union thread_union init_thread_union __init_task_data =
17594 - { INIT_THREAD_INFO(init_task) };
17595 +union thread_union init_thread_union __init_task_data;
17596
17597 /*
17598 * Initial task structure.
17599 @@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
17600 * section. Since TSS's are completely CPU-local, we want them
17601 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
17602 */
17603 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
17604 -
17605 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
17606 +EXPORT_SYMBOL(init_tss);
17607 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17608 index 8c96897..be66bfa 100644
17609 --- a/arch/x86/kernel/ioport.c
17610 +++ b/arch/x86/kernel/ioport.c
17611 @@ -6,6 +6,7 @@
17612 #include <linux/sched.h>
17613 #include <linux/kernel.h>
17614 #include <linux/capability.h>
17615 +#include <linux/security.h>
17616 #include <linux/errno.h>
17617 #include <linux/types.h>
17618 #include <linux/ioport.h>
17619 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17620
17621 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17622 return -EINVAL;
17623 +#ifdef CONFIG_GRKERNSEC_IO
17624 + if (turn_on && grsec_disable_privio) {
17625 + gr_handle_ioperm();
17626 + return -EPERM;
17627 + }
17628 +#endif
17629 if (turn_on && !capable(CAP_SYS_RAWIO))
17630 return -EPERM;
17631
17632 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17633 * because the ->io_bitmap_max value must match the bitmap
17634 * contents:
17635 */
17636 - tss = &per_cpu(init_tss, get_cpu());
17637 + tss = init_tss + get_cpu();
17638
17639 if (turn_on)
17640 bitmap_clear(t->io_bitmap_ptr, from, num);
17641 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17642 return -EINVAL;
17643 /* Trying to gain more privileges? */
17644 if (level > old) {
17645 +#ifdef CONFIG_GRKERNSEC_IO
17646 + if (grsec_disable_privio) {
17647 + gr_handle_iopl();
17648 + return -EPERM;
17649 + }
17650 +#endif
17651 if (!capable(CAP_SYS_RAWIO))
17652 return -EPERM;
17653 }
17654 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17655 index 3dafc60..aa8e9c4 100644
17656 --- a/arch/x86/kernel/irq.c
17657 +++ b/arch/x86/kernel/irq.c
17658 @@ -18,7 +18,7 @@
17659 #include <asm/mce.h>
17660 #include <asm/hw_irq.h>
17661
17662 -atomic_t irq_err_count;
17663 +atomic_unchecked_t irq_err_count;
17664
17665 /* Function pointer for generic interrupt vector handling */
17666 void (*x86_platform_ipi_callback)(void) = NULL;
17667 @@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17668 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17669 seq_printf(p, " Machine check polls\n");
17670 #endif
17671 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17672 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17673 #if defined(CONFIG_X86_IO_APIC)
17674 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17675 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17676 #endif
17677 return 0;
17678 }
17679 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17680
17681 u64 arch_irq_stat(void)
17682 {
17683 - u64 sum = atomic_read(&irq_err_count);
17684 + u64 sum = atomic_read_unchecked(&irq_err_count);
17685
17686 #ifdef CONFIG_X86_IO_APIC
17687 - sum += atomic_read(&irq_mis_count);
17688 + sum += atomic_read_unchecked(&irq_mis_count);
17689 #endif
17690 return sum;
17691 }
17692 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17693 index 58b7f27..e112d08 100644
17694 --- a/arch/x86/kernel/irq_32.c
17695 +++ b/arch/x86/kernel/irq_32.c
17696 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17697 __asm__ __volatile__("andl %%esp,%0" :
17698 "=r" (sp) : "0" (THREAD_SIZE - 1));
17699
17700 - return sp < (sizeof(struct thread_info) + STACK_WARN);
17701 + return sp < STACK_WARN;
17702 }
17703
17704 static void print_stack_overflow(void)
17705 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17706 * per-CPU IRQ handling contexts (thread information and stack)
17707 */
17708 union irq_ctx {
17709 - struct thread_info tinfo;
17710 - u32 stack[THREAD_SIZE/sizeof(u32)];
17711 + unsigned long previous_esp;
17712 + u32 stack[THREAD_SIZE/sizeof(u32)];
17713 } __attribute__((aligned(THREAD_SIZE)));
17714
17715 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17716 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17717 static inline int
17718 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17719 {
17720 - union irq_ctx *curctx, *irqctx;
17721 + union irq_ctx *irqctx;
17722 u32 *isp, arg1, arg2;
17723
17724 - curctx = (union irq_ctx *) current_thread_info();
17725 irqctx = __this_cpu_read(hardirq_ctx);
17726
17727 /*
17728 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17729 * handler) we can't do that and just have to keep using the
17730 * current stack (which is the irq stack already after all)
17731 */
17732 - if (unlikely(curctx == irqctx))
17733 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17734 return 0;
17735
17736 /* build the stack frame on the IRQ stack */
17737 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17738 - irqctx->tinfo.task = curctx->tinfo.task;
17739 - irqctx->tinfo.previous_esp = current_stack_pointer;
17740 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17741 + irqctx->previous_esp = current_stack_pointer;
17742
17743 - /* Copy the preempt_count so that the [soft]irq checks work. */
17744 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17745 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17746 + __set_fs(MAKE_MM_SEG(0));
17747 +#endif
17748
17749 if (unlikely(overflow))
17750 call_on_stack(print_stack_overflow, isp);
17751 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17752 : "0" (irq), "1" (desc), "2" (isp),
17753 "D" (desc->handle_irq)
17754 : "memory", "cc", "ecx");
17755 +
17756 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17757 + __set_fs(current_thread_info()->addr_limit);
17758 +#endif
17759 +
17760 return 1;
17761 }
17762
17763 @@ -121,29 +125,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17764 */
17765 void __cpuinit irq_ctx_init(int cpu)
17766 {
17767 - union irq_ctx *irqctx;
17768 -
17769 if (per_cpu(hardirq_ctx, cpu))
17770 return;
17771
17772 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17773 - THREAD_FLAGS,
17774 - THREAD_ORDER));
17775 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17776 - irqctx->tinfo.cpu = cpu;
17777 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17778 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17779 -
17780 - per_cpu(hardirq_ctx, cpu) = irqctx;
17781 -
17782 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17783 - THREAD_FLAGS,
17784 - THREAD_ORDER));
17785 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17786 - irqctx->tinfo.cpu = cpu;
17787 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17788 -
17789 - per_cpu(softirq_ctx, cpu) = irqctx;
17790 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17791 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17792
17793 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17794 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17795 @@ -152,7 +138,6 @@ void __cpuinit irq_ctx_init(int cpu)
17796 asmlinkage void do_softirq(void)
17797 {
17798 unsigned long flags;
17799 - struct thread_info *curctx;
17800 union irq_ctx *irqctx;
17801 u32 *isp;
17802
17803 @@ -162,15 +147,22 @@ asmlinkage void do_softirq(void)
17804 local_irq_save(flags);
17805
17806 if (local_softirq_pending()) {
17807 - curctx = current_thread_info();
17808 irqctx = __this_cpu_read(softirq_ctx);
17809 - irqctx->tinfo.task = curctx->task;
17810 - irqctx->tinfo.previous_esp = current_stack_pointer;
17811 + irqctx->previous_esp = current_stack_pointer;
17812
17813 /* build the stack frame on the softirq stack */
17814 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17815 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17816 +
17817 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17818 + __set_fs(MAKE_MM_SEG(0));
17819 +#endif
17820
17821 call_on_stack(__do_softirq, isp);
17822 +
17823 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17824 + __set_fs(current_thread_info()->addr_limit);
17825 +#endif
17826 +
17827 /*
17828 * Shouldn't happen, we returned above if in_interrupt():
17829 */
17830 @@ -191,7 +183,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17831 if (unlikely(!desc))
17832 return false;
17833
17834 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17835 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17836 if (unlikely(overflow))
17837 print_stack_overflow();
17838 desc->handle_irq(irq, desc);
17839 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17840 index d04d3ec..ea4b374 100644
17841 --- a/arch/x86/kernel/irq_64.c
17842 +++ b/arch/x86/kernel/irq_64.c
17843 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17844 u64 estack_top, estack_bottom;
17845 u64 curbase = (u64)task_stack_page(current);
17846
17847 - if (user_mode_vm(regs))
17848 + if (user_mode(regs))
17849 return;
17850
17851 if (regs->sp >= curbase + sizeof(struct thread_info) +
17852 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17853 index 1d5d31e..ab846ed 100644
17854 --- a/arch/x86/kernel/kdebugfs.c
17855 +++ b/arch/x86/kernel/kdebugfs.c
17856 @@ -28,6 +28,8 @@ struct setup_data_node {
17857 };
17858
17859 static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17860 + size_t count, loff_t *ppos) __size_overflow(3);
17861 +static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17862 size_t count, loff_t *ppos)
17863 {
17864 struct setup_data_node *node = file->private_data;
17865 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17866 index 8bfb614..2b3b35f 100644
17867 --- a/arch/x86/kernel/kgdb.c
17868 +++ b/arch/x86/kernel/kgdb.c
17869 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17870 #ifdef CONFIG_X86_32
17871 switch (regno) {
17872 case GDB_SS:
17873 - if (!user_mode_vm(regs))
17874 + if (!user_mode(regs))
17875 *(unsigned long *)mem = __KERNEL_DS;
17876 break;
17877 case GDB_SP:
17878 - if (!user_mode_vm(regs))
17879 + if (!user_mode(regs))
17880 *(unsigned long *)mem = kernel_stack_pointer(regs);
17881 break;
17882 case GDB_GS:
17883 @@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17884 case 'k':
17885 /* clear the trace bit */
17886 linux_regs->flags &= ~X86_EFLAGS_TF;
17887 - atomic_set(&kgdb_cpu_doing_single_step, -1);
17888 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17889
17890 /* set the trace bit if we're stepping */
17891 if (remcomInBuffer[0] == 's') {
17892 linux_regs->flags |= X86_EFLAGS_TF;
17893 - atomic_set(&kgdb_cpu_doing_single_step,
17894 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17895 raw_smp_processor_id());
17896 }
17897
17898 @@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17899
17900 switch (cmd) {
17901 case DIE_DEBUG:
17902 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17903 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17904 if (user_mode(regs))
17905 return single_step_cont(regs, args);
17906 break;
17907 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17908 index c5e410e..da6aaf9 100644
17909 --- a/arch/x86/kernel/kprobes-opt.c
17910 +++ b/arch/x86/kernel/kprobes-opt.c
17911 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17912 * Verify if the address gap is in 2GB range, because this uses
17913 * a relative jump.
17914 */
17915 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17916 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17917 if (abs(rel) > 0x7fffffff)
17918 return -ERANGE;
17919
17920 @@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17921 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17922
17923 /* Set probe function call */
17924 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17925 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17926
17927 /* Set returning jmp instruction at the tail of out-of-line buffer */
17928 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17929 - (u8 *)op->kp.addr + op->optinsn.size);
17930 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17931
17932 flush_icache_range((unsigned long) buf,
17933 (unsigned long) buf + TMPL_END_IDX +
17934 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17935 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17936
17937 /* Backup instructions which will be replaced by jump address */
17938 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17939 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17940 RELATIVE_ADDR_SIZE);
17941
17942 insn_buf[0] = RELATIVEJUMP_OPCODE;
17943 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17944 index e213fc8..d783ba4 100644
17945 --- a/arch/x86/kernel/kprobes.c
17946 +++ b/arch/x86/kernel/kprobes.c
17947 @@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17948 } __attribute__((packed)) *insn;
17949
17950 insn = (struct __arch_relative_insn *)from;
17951 +
17952 + pax_open_kernel();
17953 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17954 insn->op = op;
17955 + pax_close_kernel();
17956 }
17957
17958 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17959 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
17960 kprobe_opcode_t opcode;
17961 kprobe_opcode_t *orig_opcodes = opcodes;
17962
17963 - if (search_exception_tables((unsigned long)opcodes))
17964 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17965 return 0; /* Page fault may occur on this address. */
17966
17967 retry:
17968 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17969 /* Another subsystem puts a breakpoint, failed to recover */
17970 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
17971 return 0;
17972 + pax_open_kernel();
17973 memcpy(dest, insn.kaddr, insn.length);
17974 + pax_close_kernel();
17975
17976 #ifdef CONFIG_X86_64
17977 if (insn_rip_relative(&insn)) {
17978 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17979 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
17980 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
17981 disp = (u8 *) dest + insn_offset_displacement(&insn);
17982 + pax_open_kernel();
17983 *(s32 *) disp = (s32) newdisp;
17984 + pax_close_kernel();
17985 }
17986 #endif
17987 return insn.length;
17988 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17989 * nor set current_kprobe, because it doesn't use single
17990 * stepping.
17991 */
17992 - regs->ip = (unsigned long)p->ainsn.insn;
17993 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17994 preempt_enable_no_resched();
17995 return;
17996 }
17997 @@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17998 if (p->opcode == BREAKPOINT_INSTRUCTION)
17999 regs->ip = (unsigned long)p->addr;
18000 else
18001 - regs->ip = (unsigned long)p->ainsn.insn;
18002 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18003 }
18004
18005 /*
18006 @@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
18007 setup_singlestep(p, regs, kcb, 0);
18008 return 1;
18009 }
18010 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
18011 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
18012 /*
18013 * The breakpoint instruction was removed right
18014 * after we hit it. Another cpu has removed
18015 @@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
18016 " movq %rax, 152(%rsp)\n"
18017 RESTORE_REGS_STRING
18018 " popfq\n"
18019 +#ifdef KERNEXEC_PLUGIN
18020 + " btsq $63,(%rsp)\n"
18021 +#endif
18022 #else
18023 " pushf\n"
18024 SAVE_REGS_STRING
18025 @@ -765,7 +775,7 @@ static void __kprobes
18026 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
18027 {
18028 unsigned long *tos = stack_addr(regs);
18029 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
18030 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
18031 unsigned long orig_ip = (unsigned long)p->addr;
18032 kprobe_opcode_t *insn = p->ainsn.insn;
18033
18034 @@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
18035 struct die_args *args = data;
18036 int ret = NOTIFY_DONE;
18037
18038 - if (args->regs && user_mode_vm(args->regs))
18039 + if (args->regs && user_mode(args->regs))
18040 return ret;
18041
18042 switch (val) {
18043 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
18044 index ebc9873..1b9724b 100644
18045 --- a/arch/x86/kernel/ldt.c
18046 +++ b/arch/x86/kernel/ldt.c
18047 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
18048 if (reload) {
18049 #ifdef CONFIG_SMP
18050 preempt_disable();
18051 - load_LDT(pc);
18052 + load_LDT_nolock(pc);
18053 if (!cpumask_equal(mm_cpumask(current->mm),
18054 cpumask_of(smp_processor_id())))
18055 smp_call_function(flush_ldt, current->mm, 1);
18056 preempt_enable();
18057 #else
18058 - load_LDT(pc);
18059 + load_LDT_nolock(pc);
18060 #endif
18061 }
18062 if (oldsize) {
18063 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
18064 return err;
18065
18066 for (i = 0; i < old->size; i++)
18067 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
18068 + write_ldt_entry(new->ldt, i, old->ldt + i);
18069 return 0;
18070 }
18071
18072 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
18073 retval = copy_ldt(&mm->context, &old_mm->context);
18074 mutex_unlock(&old_mm->context.lock);
18075 }
18076 +
18077 + if (tsk == current) {
18078 + mm->context.vdso = 0;
18079 +
18080 +#ifdef CONFIG_X86_32
18081 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18082 + mm->context.user_cs_base = 0UL;
18083 + mm->context.user_cs_limit = ~0UL;
18084 +
18085 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18086 + cpus_clear(mm->context.cpu_user_cs_mask);
18087 +#endif
18088 +
18089 +#endif
18090 +#endif
18091 +
18092 + }
18093 +
18094 return retval;
18095 }
18096
18097 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18098 }
18099 }
18100
18101 +#ifdef CONFIG_PAX_SEGMEXEC
18102 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18103 + error = -EINVAL;
18104 + goto out_unlock;
18105 + }
18106 +#endif
18107 +
18108 fill_ldt(&ldt, &ldt_info);
18109 if (oldmode)
18110 ldt.avl = 0;
18111 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18112 index 5b19e4d..6476a76 100644
18113 --- a/arch/x86/kernel/machine_kexec_32.c
18114 +++ b/arch/x86/kernel/machine_kexec_32.c
18115 @@ -26,7 +26,7 @@
18116 #include <asm/cacheflush.h>
18117 #include <asm/debugreg.h>
18118
18119 -static void set_idt(void *newidt, __u16 limit)
18120 +static void set_idt(struct desc_struct *newidt, __u16 limit)
18121 {
18122 struct desc_ptr curidt;
18123
18124 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
18125 }
18126
18127
18128 -static void set_gdt(void *newgdt, __u16 limit)
18129 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18130 {
18131 struct desc_ptr curgdt;
18132
18133 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
18134 }
18135
18136 control_page = page_address(image->control_code_page);
18137 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18138 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18139
18140 relocate_kernel_ptr = control_page;
18141 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18142 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18143 index 0327e2b..e43737b 100644
18144 --- a/arch/x86/kernel/microcode_intel.c
18145 +++ b/arch/x86/kernel/microcode_intel.c
18146 @@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18147
18148 static int get_ucode_user(void *to, const void *from, size_t n)
18149 {
18150 - return copy_from_user(to, from, n);
18151 + return copy_from_user(to, (const void __force_user *)from, n);
18152 }
18153
18154 static enum ucode_state
18155 request_microcode_user(int cpu, const void __user *buf, size_t size)
18156 {
18157 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18158 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18159 }
18160
18161 static void microcode_fini_cpu(int cpu)
18162 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18163 index f21fd94..61565cd 100644
18164 --- a/arch/x86/kernel/module.c
18165 +++ b/arch/x86/kernel/module.c
18166 @@ -35,15 +35,60 @@
18167 #define DEBUGP(fmt...)
18168 #endif
18169
18170 -void *module_alloc(unsigned long size)
18171 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18172 {
18173 - if (PAGE_ALIGN(size) > MODULES_LEN)
18174 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18175 return NULL;
18176 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18177 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18178 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18179 -1, __builtin_return_address(0));
18180 }
18181
18182 +void *module_alloc(unsigned long size)
18183 +{
18184 +
18185 +#ifdef CONFIG_PAX_KERNEXEC
18186 + return __module_alloc(size, PAGE_KERNEL);
18187 +#else
18188 + return __module_alloc(size, PAGE_KERNEL_EXEC);
18189 +#endif
18190 +
18191 +}
18192 +
18193 +#ifdef CONFIG_PAX_KERNEXEC
18194 +#ifdef CONFIG_X86_32
18195 +void *module_alloc_exec(unsigned long size)
18196 +{
18197 + struct vm_struct *area;
18198 +
18199 + if (size == 0)
18200 + return NULL;
18201 +
18202 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18203 + return area ? area->addr : NULL;
18204 +}
18205 +EXPORT_SYMBOL(module_alloc_exec);
18206 +
18207 +void module_free_exec(struct module *mod, void *module_region)
18208 +{
18209 + vunmap(module_region);
18210 +}
18211 +EXPORT_SYMBOL(module_free_exec);
18212 +#else
18213 +void module_free_exec(struct module *mod, void *module_region)
18214 +{
18215 + module_free(mod, module_region);
18216 +}
18217 +EXPORT_SYMBOL(module_free_exec);
18218 +
18219 +void *module_alloc_exec(unsigned long size)
18220 +{
18221 + return __module_alloc(size, PAGE_KERNEL_RX);
18222 +}
18223 +EXPORT_SYMBOL(module_alloc_exec);
18224 +#endif
18225 +#endif
18226 +
18227 #ifdef CONFIG_X86_32
18228 int apply_relocate(Elf32_Shdr *sechdrs,
18229 const char *strtab,
18230 @@ -54,14 +99,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18231 unsigned int i;
18232 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18233 Elf32_Sym *sym;
18234 - uint32_t *location;
18235 + uint32_t *plocation, location;
18236
18237 DEBUGP("Applying relocate section %u to %u\n", relsec,
18238 sechdrs[relsec].sh_info);
18239 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18240 /* This is where to make the change */
18241 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18242 - + rel[i].r_offset;
18243 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18244 + location = (uint32_t)plocation;
18245 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18246 + plocation = ktla_ktva((void *)plocation);
18247 /* This is the symbol it is referring to. Note that all
18248 undefined symbols have been resolved. */
18249 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18250 @@ -70,11 +117,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18251 switch (ELF32_R_TYPE(rel[i].r_info)) {
18252 case R_386_32:
18253 /* We add the value into the location given */
18254 - *location += sym->st_value;
18255 + pax_open_kernel();
18256 + *plocation += sym->st_value;
18257 + pax_close_kernel();
18258 break;
18259 case R_386_PC32:
18260 /* Add the value, subtract its postition */
18261 - *location += sym->st_value - (uint32_t)location;
18262 + pax_open_kernel();
18263 + *plocation += sym->st_value - location;
18264 + pax_close_kernel();
18265 break;
18266 default:
18267 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
18268 @@ -119,21 +170,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18269 case R_X86_64_NONE:
18270 break;
18271 case R_X86_64_64:
18272 + pax_open_kernel();
18273 *(u64 *)loc = val;
18274 + pax_close_kernel();
18275 break;
18276 case R_X86_64_32:
18277 + pax_open_kernel();
18278 *(u32 *)loc = val;
18279 + pax_close_kernel();
18280 if (val != *(u32 *)loc)
18281 goto overflow;
18282 break;
18283 case R_X86_64_32S:
18284 + pax_open_kernel();
18285 *(s32 *)loc = val;
18286 + pax_close_kernel();
18287 if ((s64)val != *(s32 *)loc)
18288 goto overflow;
18289 break;
18290 case R_X86_64_PC32:
18291 val -= (u64)loc;
18292 + pax_open_kernel();
18293 *(u32 *)loc = val;
18294 + pax_close_kernel();
18295 +
18296 #if 0
18297 if ((s64)val != *(s32 *)loc)
18298 goto overflow;
18299 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18300 index 32856fa..ce95eaa 100644
18301 --- a/arch/x86/kernel/nmi.c
18302 +++ b/arch/x86/kernel/nmi.c
18303 @@ -507,6 +507,17 @@ static inline void nmi_nesting_postprocess(void)
18304 dotraplinkage notrace __kprobes void
18305 do_nmi(struct pt_regs *regs, long error_code)
18306 {
18307 +
18308 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18309 + if (!user_mode(regs)) {
18310 + unsigned long cs = regs->cs & 0xFFFF;
18311 + unsigned long ip = ktva_ktla(regs->ip);
18312 +
18313 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18314 + regs->ip = ip;
18315 + }
18316 +#endif
18317 +
18318 nmi_nesting_preprocess(regs);
18319
18320 nmi_enter();
18321 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18322 index 676b8c7..870ba04 100644
18323 --- a/arch/x86/kernel/paravirt-spinlocks.c
18324 +++ b/arch/x86/kernel/paravirt-spinlocks.c
18325 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18326 arch_spin_lock(lock);
18327 }
18328
18329 -struct pv_lock_ops pv_lock_ops = {
18330 +struct pv_lock_ops pv_lock_ops __read_only = {
18331 #ifdef CONFIG_SMP
18332 .spin_is_locked = __ticket_spin_is_locked,
18333 .spin_is_contended = __ticket_spin_is_contended,
18334 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18335 index ab13760..01218e0 100644
18336 --- a/arch/x86/kernel/paravirt.c
18337 +++ b/arch/x86/kernel/paravirt.c
18338 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18339 {
18340 return x;
18341 }
18342 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18343 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18344 +#endif
18345
18346 void __init default_banner(void)
18347 {
18348 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18349 if (opfunc == NULL)
18350 /* If there's no function, patch it with a ud2a (BUG) */
18351 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18352 - else if (opfunc == _paravirt_nop)
18353 + else if (opfunc == (void *)_paravirt_nop)
18354 /* If the operation is a nop, then nop the callsite */
18355 ret = paravirt_patch_nop();
18356
18357 /* identity functions just return their single argument */
18358 - else if (opfunc == _paravirt_ident_32)
18359 + else if (opfunc == (void *)_paravirt_ident_32)
18360 ret = paravirt_patch_ident_32(insnbuf, len);
18361 - else if (opfunc == _paravirt_ident_64)
18362 + else if (opfunc == (void *)_paravirt_ident_64)
18363 ret = paravirt_patch_ident_64(insnbuf, len);
18364 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18365 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18366 + ret = paravirt_patch_ident_64(insnbuf, len);
18367 +#endif
18368
18369 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18370 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18371 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18372 if (insn_len > len || start == NULL)
18373 insn_len = len;
18374 else
18375 - memcpy(insnbuf, start, insn_len);
18376 + memcpy(insnbuf, ktla_ktva(start), insn_len);
18377
18378 return insn_len;
18379 }
18380 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18381 preempt_enable();
18382 }
18383
18384 -struct pv_info pv_info = {
18385 +struct pv_info pv_info __read_only = {
18386 .name = "bare hardware",
18387 .paravirt_enabled = 0,
18388 .kernel_rpl = 0,
18389 @@ -315,16 +322,16 @@ struct pv_info pv_info = {
18390 #endif
18391 };
18392
18393 -struct pv_init_ops pv_init_ops = {
18394 +struct pv_init_ops pv_init_ops __read_only = {
18395 .patch = native_patch,
18396 };
18397
18398 -struct pv_time_ops pv_time_ops = {
18399 +struct pv_time_ops pv_time_ops __read_only = {
18400 .sched_clock = native_sched_clock,
18401 .steal_clock = native_steal_clock,
18402 };
18403
18404 -struct pv_irq_ops pv_irq_ops = {
18405 +struct pv_irq_ops pv_irq_ops __read_only = {
18406 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18407 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18408 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18409 @@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18410 #endif
18411 };
18412
18413 -struct pv_cpu_ops pv_cpu_ops = {
18414 +struct pv_cpu_ops pv_cpu_ops __read_only = {
18415 .cpuid = native_cpuid,
18416 .get_debugreg = native_get_debugreg,
18417 .set_debugreg = native_set_debugreg,
18418 @@ -397,21 +404,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18419 .end_context_switch = paravirt_nop,
18420 };
18421
18422 -struct pv_apic_ops pv_apic_ops = {
18423 +struct pv_apic_ops pv_apic_ops __read_only = {
18424 #ifdef CONFIG_X86_LOCAL_APIC
18425 .startup_ipi_hook = paravirt_nop,
18426 #endif
18427 };
18428
18429 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18430 +#ifdef CONFIG_X86_32
18431 +#ifdef CONFIG_X86_PAE
18432 +/* 64-bit pagetable entries */
18433 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18434 +#else
18435 /* 32-bit pagetable entries */
18436 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18437 +#endif
18438 #else
18439 /* 64-bit pagetable entries */
18440 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18441 #endif
18442
18443 -struct pv_mmu_ops pv_mmu_ops = {
18444 +struct pv_mmu_ops pv_mmu_ops __read_only = {
18445
18446 .read_cr2 = native_read_cr2,
18447 .write_cr2 = native_write_cr2,
18448 @@ -461,6 +473,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18449 .make_pud = PTE_IDENT,
18450
18451 .set_pgd = native_set_pgd,
18452 + .set_pgd_batched = native_set_pgd_batched,
18453 #endif
18454 #endif /* PAGETABLE_LEVELS >= 3 */
18455
18456 @@ -480,6 +493,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18457 },
18458
18459 .set_fixmap = native_set_fixmap,
18460 +
18461 +#ifdef CONFIG_PAX_KERNEXEC
18462 + .pax_open_kernel = native_pax_open_kernel,
18463 + .pax_close_kernel = native_pax_close_kernel,
18464 +#endif
18465 +
18466 };
18467
18468 EXPORT_SYMBOL_GPL(pv_time_ops);
18469 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18470 index 35ccf75..7a15747 100644
18471 --- a/arch/x86/kernel/pci-iommu_table.c
18472 +++ b/arch/x86/kernel/pci-iommu_table.c
18473 @@ -2,7 +2,7 @@
18474 #include <asm/iommu_table.h>
18475 #include <linux/string.h>
18476 #include <linux/kallsyms.h>
18477 -
18478 +#include <linux/sched.h>
18479
18480 #define DEBUG 1
18481
18482 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18483 index 1d92a5a..7bc8c29 100644
18484 --- a/arch/x86/kernel/process.c
18485 +++ b/arch/x86/kernel/process.c
18486 @@ -69,16 +69,33 @@ void free_thread_xstate(struct task_struct *tsk)
18487
18488 void free_thread_info(struct thread_info *ti)
18489 {
18490 - free_thread_xstate(ti->task);
18491 free_pages((unsigned long)ti, THREAD_ORDER);
18492 }
18493
18494 +static struct kmem_cache *task_struct_cachep;
18495 +
18496 void arch_task_cache_init(void)
18497 {
18498 - task_xstate_cachep =
18499 - kmem_cache_create("task_xstate", xstate_size,
18500 + /* create a slab on which task_structs can be allocated */
18501 + task_struct_cachep =
18502 + kmem_cache_create("task_struct", sizeof(struct task_struct),
18503 + ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
18504 +
18505 + task_xstate_cachep =
18506 + kmem_cache_create("task_xstate", xstate_size,
18507 __alignof__(union thread_xstate),
18508 - SLAB_PANIC | SLAB_NOTRACK, NULL);
18509 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18510 +}
18511 +
18512 +struct task_struct *alloc_task_struct_node(int node)
18513 +{
18514 + return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
18515 +}
18516 +
18517 +void free_task_struct(struct task_struct *task)
18518 +{
18519 + free_thread_xstate(task);
18520 + kmem_cache_free(task_struct_cachep, task);
18521 }
18522
18523 /*
18524 @@ -91,7 +108,7 @@ void exit_thread(void)
18525 unsigned long *bp = t->io_bitmap_ptr;
18526
18527 if (bp) {
18528 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18529 + struct tss_struct *tss = init_tss + get_cpu();
18530
18531 t->io_bitmap_ptr = NULL;
18532 clear_thread_flag(TIF_IO_BITMAP);
18533 @@ -127,7 +144,7 @@ void show_regs_common(void)
18534
18535 printk(KERN_CONT "\n");
18536 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
18537 - current->pid, current->comm, print_tainted(),
18538 + task_pid_nr(current), current->comm, print_tainted(),
18539 init_utsname()->release,
18540 (int)strcspn(init_utsname()->version, " "),
18541 init_utsname()->version);
18542 @@ -141,6 +158,9 @@ void flush_thread(void)
18543 {
18544 struct task_struct *tsk = current;
18545
18546 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18547 + loadsegment(gs, 0);
18548 +#endif
18549 flush_ptrace_hw_breakpoint(tsk);
18550 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18551 /*
18552 @@ -303,10 +323,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18553 regs.di = (unsigned long) arg;
18554
18555 #ifdef CONFIG_X86_32
18556 - regs.ds = __USER_DS;
18557 - regs.es = __USER_DS;
18558 + regs.ds = __KERNEL_DS;
18559 + regs.es = __KERNEL_DS;
18560 regs.fs = __KERNEL_PERCPU;
18561 - regs.gs = __KERNEL_STACK_CANARY;
18562 + savesegment(gs, regs.gs);
18563 #else
18564 regs.ss = __KERNEL_DS;
18565 #endif
18566 @@ -392,7 +412,7 @@ static void __exit_idle(void)
18567 void exit_idle(void)
18568 {
18569 /* idle loop has pid 0 */
18570 - if (current->pid)
18571 + if (task_pid_nr(current))
18572 return;
18573 __exit_idle();
18574 }
18575 @@ -501,7 +521,7 @@ bool set_pm_idle_to_default(void)
18576
18577 return ret;
18578 }
18579 -void stop_this_cpu(void *dummy)
18580 +__noreturn void stop_this_cpu(void *dummy)
18581 {
18582 local_irq_disable();
18583 /*
18584 @@ -743,16 +763,37 @@ static int __init idle_setup(char *str)
18585 }
18586 early_param("idle", idle_setup);
18587
18588 -unsigned long arch_align_stack(unsigned long sp)
18589 +#ifdef CONFIG_PAX_RANDKSTACK
18590 +void pax_randomize_kstack(struct pt_regs *regs)
18591 {
18592 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18593 - sp -= get_random_int() % 8192;
18594 - return sp & ~0xf;
18595 -}
18596 + struct thread_struct *thread = &current->thread;
18597 + unsigned long time;
18598
18599 -unsigned long arch_randomize_brk(struct mm_struct *mm)
18600 -{
18601 - unsigned long range_end = mm->brk + 0x02000000;
18602 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18603 -}
18604 + if (!randomize_va_space)
18605 + return;
18606 +
18607 + if (v8086_mode(regs))
18608 + return;
18609
18610 + rdtscl(time);
18611 +
18612 + /* P4 seems to return a 0 LSB, ignore it */
18613 +#ifdef CONFIG_MPENTIUM4
18614 + time &= 0x3EUL;
18615 + time <<= 2;
18616 +#elif defined(CONFIG_X86_64)
18617 + time &= 0xFUL;
18618 + time <<= 4;
18619 +#else
18620 + time &= 0x1FUL;
18621 + time <<= 3;
18622 +#endif
18623 +
18624 + thread->sp0 ^= time;
18625 + load_sp0(init_tss + smp_processor_id(), thread);
18626 +
18627 +#ifdef CONFIG_X86_64
18628 + percpu_write(kernel_stack, thread->sp0);
18629 +#endif
18630 +}
18631 +#endif
18632 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18633 index ae68473..7b0bb71 100644
18634 --- a/arch/x86/kernel/process_32.c
18635 +++ b/arch/x86/kernel/process_32.c
18636 @@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18637 unsigned long thread_saved_pc(struct task_struct *tsk)
18638 {
18639 return ((unsigned long *)tsk->thread.sp)[3];
18640 +//XXX return tsk->thread.eip;
18641 }
18642
18643 void __show_regs(struct pt_regs *regs, int all)
18644 @@ -73,15 +74,14 @@ void __show_regs(struct pt_regs *regs, int all)
18645 unsigned long sp;
18646 unsigned short ss, gs;
18647
18648 - if (user_mode_vm(regs)) {
18649 + if (user_mode(regs)) {
18650 sp = regs->sp;
18651 ss = regs->ss & 0xffff;
18652 - gs = get_user_gs(regs);
18653 } else {
18654 sp = kernel_stack_pointer(regs);
18655 savesegment(ss, ss);
18656 - savesegment(gs, gs);
18657 }
18658 + gs = get_user_gs(regs);
18659
18660 show_regs_common();
18661
18662 @@ -143,13 +143,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18663 struct task_struct *tsk;
18664 int err;
18665
18666 - childregs = task_pt_regs(p);
18667 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18668 *childregs = *regs;
18669 childregs->ax = 0;
18670 childregs->sp = sp;
18671
18672 p->thread.sp = (unsigned long) childregs;
18673 p->thread.sp0 = (unsigned long) (childregs+1);
18674 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18675
18676 p->thread.ip = (unsigned long) ret_from_fork;
18677
18678 @@ -240,7 +241,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18679 struct thread_struct *prev = &prev_p->thread,
18680 *next = &next_p->thread;
18681 int cpu = smp_processor_id();
18682 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18683 + struct tss_struct *tss = init_tss + cpu;
18684 fpu_switch_t fpu;
18685
18686 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18687 @@ -264,6 +265,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18688 */
18689 lazy_save_gs(prev->gs);
18690
18691 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18692 + __set_fs(task_thread_info(next_p)->addr_limit);
18693 +#endif
18694 +
18695 /*
18696 * Load the per-thread Thread-Local Storage descriptor.
18697 */
18698 @@ -294,6 +299,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18699 */
18700 arch_end_context_switch(next_p);
18701
18702 + percpu_write(current_task, next_p);
18703 + percpu_write(current_tinfo, &next_p->tinfo);
18704 +
18705 /*
18706 * Restore %gs if needed (which is common)
18707 */
18708 @@ -302,8 +310,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18709
18710 switch_fpu_finish(next_p, fpu);
18711
18712 - percpu_write(current_task, next_p);
18713 -
18714 return prev_p;
18715 }
18716
18717 @@ -333,4 +339,3 @@ unsigned long get_wchan(struct task_struct *p)
18718 } while (count++ < 16);
18719 return 0;
18720 }
18721 -
18722 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18723 index 43d8b48..c45d566 100644
18724 --- a/arch/x86/kernel/process_64.c
18725 +++ b/arch/x86/kernel/process_64.c
18726 @@ -162,8 +162,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18727 struct pt_regs *childregs;
18728 struct task_struct *me = current;
18729
18730 - childregs = ((struct pt_regs *)
18731 - (THREAD_SIZE + task_stack_page(p))) - 1;
18732 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18733 *childregs = *regs;
18734
18735 childregs->ax = 0;
18736 @@ -175,6 +174,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18737 p->thread.sp = (unsigned long) childregs;
18738 p->thread.sp0 = (unsigned long) (childregs+1);
18739 p->thread.usersp = me->thread.usersp;
18740 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18741
18742 set_tsk_thread_flag(p, TIF_FORK);
18743
18744 @@ -280,7 +280,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18745 struct thread_struct *prev = &prev_p->thread;
18746 struct thread_struct *next = &next_p->thread;
18747 int cpu = smp_processor_id();
18748 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18749 + struct tss_struct *tss = init_tss + cpu;
18750 unsigned fsindex, gsindex;
18751 fpu_switch_t fpu;
18752
18753 @@ -362,10 +362,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18754 prev->usersp = percpu_read(old_rsp);
18755 percpu_write(old_rsp, next->usersp);
18756 percpu_write(current_task, next_p);
18757 + percpu_write(current_tinfo, &next_p->tinfo);
18758
18759 - percpu_write(kernel_stack,
18760 - (unsigned long)task_stack_page(next_p) +
18761 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18762 + percpu_write(kernel_stack, next->sp0);
18763
18764 /*
18765 * Now maybe reload the debug registers and handle I/O bitmaps
18766 @@ -434,12 +433,11 @@ unsigned long get_wchan(struct task_struct *p)
18767 if (!p || p == current || p->state == TASK_RUNNING)
18768 return 0;
18769 stack = (unsigned long)task_stack_page(p);
18770 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18771 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18772 return 0;
18773 fp = *(u64 *)(p->thread.sp);
18774 do {
18775 - if (fp < (unsigned long)stack ||
18776 - fp >= (unsigned long)stack+THREAD_SIZE)
18777 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18778 return 0;
18779 ip = *(u64 *)(fp+8);
18780 if (!in_sched_functions(ip))
18781 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18782 index cf11783..e7ce551 100644
18783 --- a/arch/x86/kernel/ptrace.c
18784 +++ b/arch/x86/kernel/ptrace.c
18785 @@ -824,7 +824,7 @@ long arch_ptrace(struct task_struct *child, long request,
18786 unsigned long addr, unsigned long data)
18787 {
18788 int ret;
18789 - unsigned long __user *datap = (unsigned long __user *)data;
18790 + unsigned long __user *datap = (__force unsigned long __user *)data;
18791
18792 switch (request) {
18793 /* read the word at location addr in the USER area. */
18794 @@ -909,14 +909,14 @@ long arch_ptrace(struct task_struct *child, long request,
18795 if ((int) addr < 0)
18796 return -EIO;
18797 ret = do_get_thread_area(child, addr,
18798 - (struct user_desc __user *)data);
18799 + (__force struct user_desc __user *) data);
18800 break;
18801
18802 case PTRACE_SET_THREAD_AREA:
18803 if ((int) addr < 0)
18804 return -EIO;
18805 ret = do_set_thread_area(child, addr,
18806 - (struct user_desc __user *)data, 0);
18807 + (__force struct user_desc __user *) data, 0);
18808 break;
18809 #endif
18810
18811 @@ -1426,7 +1426,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18812 memset(info, 0, sizeof(*info));
18813 info->si_signo = SIGTRAP;
18814 info->si_code = si_code;
18815 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18816 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18817 }
18818
18819 void user_single_step_siginfo(struct task_struct *tsk,
18820 @@ -1455,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18821 # define IS_IA32 0
18822 #endif
18823
18824 +#ifdef CONFIG_GRKERNSEC_SETXID
18825 +extern void gr_delayed_cred_worker(void);
18826 +#endif
18827 +
18828 /*
18829 * We must return the syscall number to actually look up in the table.
18830 * This can be -1L to skip running any syscall at all.
18831 @@ -1463,6 +1467,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18832 {
18833 long ret = 0;
18834
18835 +#ifdef CONFIG_GRKERNSEC_SETXID
18836 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18837 + gr_delayed_cred_worker();
18838 +#endif
18839 +
18840 /*
18841 * If we stepped into a sysenter/syscall insn, it trapped in
18842 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18843 @@ -1506,6 +1515,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18844 {
18845 bool step;
18846
18847 +#ifdef CONFIG_GRKERNSEC_SETXID
18848 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18849 + gr_delayed_cred_worker();
18850 +#endif
18851 +
18852 audit_syscall_exit(regs);
18853
18854 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18855 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18856 index 42eb330..139955c 100644
18857 --- a/arch/x86/kernel/pvclock.c
18858 +++ b/arch/x86/kernel/pvclock.c
18859 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18860 return pv_tsc_khz;
18861 }
18862
18863 -static atomic64_t last_value = ATOMIC64_INIT(0);
18864 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18865
18866 void pvclock_resume(void)
18867 {
18868 - atomic64_set(&last_value, 0);
18869 + atomic64_set_unchecked(&last_value, 0);
18870 }
18871
18872 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18873 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18874 * updating at the same time, and one of them could be slightly behind,
18875 * making the assumption that last_value always go forward fail to hold.
18876 */
18877 - last = atomic64_read(&last_value);
18878 + last = atomic64_read_unchecked(&last_value);
18879 do {
18880 if (ret < last)
18881 return last;
18882 - last = atomic64_cmpxchg(&last_value, last, ret);
18883 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18884 } while (unlikely(last != ret));
18885
18886 return ret;
18887 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18888 index d840e69..98e9581 100644
18889 --- a/arch/x86/kernel/reboot.c
18890 +++ b/arch/x86/kernel/reboot.c
18891 @@ -35,7 +35,7 @@ void (*pm_power_off)(void);
18892 EXPORT_SYMBOL(pm_power_off);
18893
18894 static const struct desc_ptr no_idt = {};
18895 -static int reboot_mode;
18896 +static unsigned short reboot_mode;
18897 enum reboot_type reboot_type = BOOT_ACPI;
18898 int reboot_force;
18899
18900 @@ -335,13 +335,17 @@ core_initcall(reboot_init);
18901 extern const unsigned char machine_real_restart_asm[];
18902 extern const u64 machine_real_restart_gdt[3];
18903
18904 -void machine_real_restart(unsigned int type)
18905 +__noreturn void machine_real_restart(unsigned int type)
18906 {
18907 void *restart_va;
18908 unsigned long restart_pa;
18909 - void (*restart_lowmem)(unsigned int);
18910 + void (* __noreturn restart_lowmem)(unsigned int);
18911 u64 *lowmem_gdt;
18912
18913 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18914 + struct desc_struct *gdt;
18915 +#endif
18916 +
18917 local_irq_disable();
18918
18919 /* Write zero to CMOS register number 0x0f, which the BIOS POST
18920 @@ -367,14 +371,14 @@ void machine_real_restart(unsigned int type)
18921 boot)". This seems like a fairly standard thing that gets set by
18922 REBOOT.COM programs, and the previous reset routine did this
18923 too. */
18924 - *((unsigned short *)0x472) = reboot_mode;
18925 + *(unsigned short *)(__va(0x472)) = reboot_mode;
18926
18927 /* Patch the GDT in the low memory trampoline */
18928 lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt);
18929
18930 restart_va = TRAMPOLINE_SYM(machine_real_restart_asm);
18931 restart_pa = virt_to_phys(restart_va);
18932 - restart_lowmem = (void (*)(unsigned int))restart_pa;
18933 + restart_lowmem = (void *)restart_pa;
18934
18935 /* GDT[0]: GDT self-pointer */
18936 lowmem_gdt[0] =
18937 @@ -385,7 +389,33 @@ void machine_real_restart(unsigned int type)
18938 GDT_ENTRY(0x009b, restart_pa, 0xffff);
18939
18940 /* Jump to the identity-mapped low memory code */
18941 +
18942 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18943 + gdt = get_cpu_gdt_table(smp_processor_id());
18944 + pax_open_kernel();
18945 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18946 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18947 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18948 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
18949 +#endif
18950 +#ifdef CONFIG_PAX_KERNEXEC
18951 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18952 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18953 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18954 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18955 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18956 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18957 +#endif
18958 + pax_close_kernel();
18959 +#endif
18960 +
18961 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18962 + asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
18963 + unreachable();
18964 +#else
18965 restart_lowmem(type);
18966 +#endif
18967 +
18968 }
18969 #ifdef CONFIG_APM_MODULE
18970 EXPORT_SYMBOL(machine_real_restart);
18971 @@ -556,7 +586,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18972 * try to force a triple fault and then cycle between hitting the keyboard
18973 * controller and doing that
18974 */
18975 -static void native_machine_emergency_restart(void)
18976 +__noreturn static void native_machine_emergency_restart(void)
18977 {
18978 int i;
18979 int attempt = 0;
18980 @@ -680,13 +710,13 @@ void native_machine_shutdown(void)
18981 #endif
18982 }
18983
18984 -static void __machine_emergency_restart(int emergency)
18985 +static __noreturn void __machine_emergency_restart(int emergency)
18986 {
18987 reboot_emergency = emergency;
18988 machine_ops.emergency_restart();
18989 }
18990
18991 -static void native_machine_restart(char *__unused)
18992 +static __noreturn void native_machine_restart(char *__unused)
18993 {
18994 printk("machine restart\n");
18995
18996 @@ -695,7 +725,7 @@ static void native_machine_restart(char *__unused)
18997 __machine_emergency_restart(0);
18998 }
18999
19000 -static void native_machine_halt(void)
19001 +static __noreturn void native_machine_halt(void)
19002 {
19003 /* stop other cpus and apics */
19004 machine_shutdown();
19005 @@ -706,7 +736,7 @@ static void native_machine_halt(void)
19006 stop_this_cpu(NULL);
19007 }
19008
19009 -static void native_machine_power_off(void)
19010 +__noreturn static void native_machine_power_off(void)
19011 {
19012 if (pm_power_off) {
19013 if (!reboot_force)
19014 @@ -715,6 +745,7 @@ static void native_machine_power_off(void)
19015 }
19016 /* a fallback in case there is no PM info available */
19017 tboot_shutdown(TB_SHUTDOWN_HALT);
19018 + unreachable();
19019 }
19020
19021 struct machine_ops machine_ops = {
19022 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
19023 index 7a6f3b3..bed145d7 100644
19024 --- a/arch/x86/kernel/relocate_kernel_64.S
19025 +++ b/arch/x86/kernel/relocate_kernel_64.S
19026 @@ -11,6 +11,7 @@
19027 #include <asm/kexec.h>
19028 #include <asm/processor-flags.h>
19029 #include <asm/pgtable_types.h>
19030 +#include <asm/alternative-asm.h>
19031
19032 /*
19033 * Must be relocatable PIC code callable as a C function
19034 @@ -160,13 +161,14 @@ identity_mapped:
19035 xorq %rbp, %rbp
19036 xorq %r8, %r8
19037 xorq %r9, %r9
19038 - xorq %r10, %r9
19039 + xorq %r10, %r10
19040 xorq %r11, %r11
19041 xorq %r12, %r12
19042 xorq %r13, %r13
19043 xorq %r14, %r14
19044 xorq %r15, %r15
19045
19046 + pax_force_retaddr 0, 1
19047 ret
19048
19049 1:
19050 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
19051 index 1a29015..712f324 100644
19052 --- a/arch/x86/kernel/setup.c
19053 +++ b/arch/x86/kernel/setup.c
19054 @@ -447,7 +447,7 @@ static void __init parse_setup_data(void)
19055
19056 switch (data->type) {
19057 case SETUP_E820_EXT:
19058 - parse_e820_ext(data);
19059 + parse_e820_ext((struct setup_data __force_kernel *)data);
19060 break;
19061 case SETUP_DTB:
19062 add_dtb(pa_data);
19063 @@ -639,7 +639,7 @@ static void __init trim_bios_range(void)
19064 * area (640->1Mb) as ram even though it is not.
19065 * take them out.
19066 */
19067 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
19068 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
19069 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
19070 }
19071
19072 @@ -763,14 +763,14 @@ void __init setup_arch(char **cmdline_p)
19073
19074 if (!boot_params.hdr.root_flags)
19075 root_mountflags &= ~MS_RDONLY;
19076 - init_mm.start_code = (unsigned long) _text;
19077 - init_mm.end_code = (unsigned long) _etext;
19078 + init_mm.start_code = ktla_ktva((unsigned long) _text);
19079 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
19080 init_mm.end_data = (unsigned long) _edata;
19081 init_mm.brk = _brk_end;
19082
19083 - code_resource.start = virt_to_phys(_text);
19084 - code_resource.end = virt_to_phys(_etext)-1;
19085 - data_resource.start = virt_to_phys(_etext);
19086 + code_resource.start = virt_to_phys(ktla_ktva(_text));
19087 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
19088 + data_resource.start = virt_to_phys(_sdata);
19089 data_resource.end = virt_to_phys(_edata)-1;
19090 bss_resource.start = virt_to_phys(&__bss_start);
19091 bss_resource.end = virt_to_phys(&__bss_stop)-1;
19092 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
19093 index 5a98aa2..2f9288d 100644
19094 --- a/arch/x86/kernel/setup_percpu.c
19095 +++ b/arch/x86/kernel/setup_percpu.c
19096 @@ -21,19 +21,17 @@
19097 #include <asm/cpu.h>
19098 #include <asm/stackprotector.h>
19099
19100 -DEFINE_PER_CPU(int, cpu_number);
19101 +#ifdef CONFIG_SMP
19102 +DEFINE_PER_CPU(unsigned int, cpu_number);
19103 EXPORT_PER_CPU_SYMBOL(cpu_number);
19104 +#endif
19105
19106 -#ifdef CONFIG_X86_64
19107 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
19108 -#else
19109 -#define BOOT_PERCPU_OFFSET 0
19110 -#endif
19111
19112 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
19113 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
19114
19115 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
19116 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
19117 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19118 };
19119 EXPORT_SYMBOL(__per_cpu_offset);
19120 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
19121 {
19122 #ifdef CONFIG_X86_32
19123 struct desc_struct gdt;
19124 + unsigned long base = per_cpu_offset(cpu);
19125
19126 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19127 - 0x2 | DESCTYPE_S, 0x8);
19128 - gdt.s = 1;
19129 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19130 + 0x83 | DESCTYPE_S, 0xC);
19131 write_gdt_entry(get_cpu_gdt_table(cpu),
19132 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19133 #endif
19134 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
19135 /* alrighty, percpu areas up and running */
19136 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19137 for_each_possible_cpu(cpu) {
19138 +#ifdef CONFIG_CC_STACKPROTECTOR
19139 +#ifdef CONFIG_X86_32
19140 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
19141 +#endif
19142 +#endif
19143 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19144 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19145 per_cpu(cpu_number, cpu) = cpu;
19146 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
19147 */
19148 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
19149 #endif
19150 +#ifdef CONFIG_CC_STACKPROTECTOR
19151 +#ifdef CONFIG_X86_32
19152 + if (!cpu)
19153 + per_cpu(stack_canary.canary, cpu) = canary;
19154 +#endif
19155 +#endif
19156 /*
19157 * Up to this point, the boot CPU has been using .init.data
19158 * area. Reload any changed state for the boot CPU.
19159 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19160 index 115eac4..c0591d5 100644
19161 --- a/arch/x86/kernel/signal.c
19162 +++ b/arch/x86/kernel/signal.c
19163 @@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
19164 * Align the stack pointer according to the i386 ABI,
19165 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19166 */
19167 - sp = ((sp + 4) & -16ul) - 4;
19168 + sp = ((sp - 12) & -16ul) - 4;
19169 #else /* !CONFIG_X86_32 */
19170 sp = round_down(sp, 16) - 8;
19171 #endif
19172 @@ -241,11 +241,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19173 * Return an always-bogus address instead so we will die with SIGSEGV.
19174 */
19175 if (onsigstack && !likely(on_sig_stack(sp)))
19176 - return (void __user *)-1L;
19177 + return (__force void __user *)-1L;
19178
19179 /* save i387 state */
19180 if (used_math() && save_i387_xstate(*fpstate) < 0)
19181 - return (void __user *)-1L;
19182 + return (__force void __user *)-1L;
19183
19184 return (void __user *)sp;
19185 }
19186 @@ -300,9 +300,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19187 }
19188
19189 if (current->mm->context.vdso)
19190 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19191 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19192 else
19193 - restorer = &frame->retcode;
19194 + restorer = (void __user *)&frame->retcode;
19195 if (ka->sa.sa_flags & SA_RESTORER)
19196 restorer = ka->sa.sa_restorer;
19197
19198 @@ -316,7 +316,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19199 * reasons and because gdb uses it as a signature to notice
19200 * signal handler stack frames.
19201 */
19202 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19203 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19204
19205 if (err)
19206 return -EFAULT;
19207 @@ -370,7 +370,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19208 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19209
19210 /* Set up to return from userspace. */
19211 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19212 + if (current->mm->context.vdso)
19213 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19214 + else
19215 + restorer = (void __user *)&frame->retcode;
19216 if (ka->sa.sa_flags & SA_RESTORER)
19217 restorer = ka->sa.sa_restorer;
19218 put_user_ex(restorer, &frame->pretcode);
19219 @@ -382,7 +385,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19220 * reasons and because gdb uses it as a signature to notice
19221 * signal handler stack frames.
19222 */
19223 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19224 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19225 } put_user_catch(err);
19226
19227 if (err)
19228 @@ -773,7 +776,7 @@ static void do_signal(struct pt_regs *regs)
19229 * X86_32: vm86 regs switched out by assembly code before reaching
19230 * here, so testing against kernel CS suffices.
19231 */
19232 - if (!user_mode(regs))
19233 + if (!user_mode_novm(regs))
19234 return;
19235
19236 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
19237 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19238 index 6e1e406..edfb7cb 100644
19239 --- a/arch/x86/kernel/smpboot.c
19240 +++ b/arch/x86/kernel/smpboot.c
19241 @@ -699,17 +699,20 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)
19242 set_idle_for_cpu(cpu, c_idle.idle);
19243 do_rest:
19244 per_cpu(current_task, cpu) = c_idle.idle;
19245 + per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
19246 #ifdef CONFIG_X86_32
19247 /* Stack for startup_32 can be just as for start_secondary onwards */
19248 irq_ctx_init(cpu);
19249 #else
19250 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
19251 initial_gs = per_cpu_offset(cpu);
19252 - per_cpu(kernel_stack, cpu) =
19253 - (unsigned long)task_stack_page(c_idle.idle) -
19254 - KERNEL_STACK_OFFSET + THREAD_SIZE;
19255 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
19256 #endif
19257 +
19258 + pax_open_kernel();
19259 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19260 + pax_close_kernel();
19261 +
19262 initial_code = (unsigned long)start_secondary;
19263 stack_start = c_idle.idle->thread.sp;
19264
19265 @@ -851,6 +854,12 @@ int __cpuinit native_cpu_up(unsigned int cpu)
19266
19267 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19268
19269 +#ifdef CONFIG_PAX_PER_CPU_PGD
19270 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19271 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19272 + KERNEL_PGD_PTRS);
19273 +#endif
19274 +
19275 err = do_boot_cpu(apicid, cpu);
19276 if (err) {
19277 pr_debug("do_boot_cpu failed %d\n", err);
19278 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19279 index c346d11..d43b163 100644
19280 --- a/arch/x86/kernel/step.c
19281 +++ b/arch/x86/kernel/step.c
19282 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19283 struct desc_struct *desc;
19284 unsigned long base;
19285
19286 - seg &= ~7UL;
19287 + seg >>= 3;
19288
19289 mutex_lock(&child->mm->context.lock);
19290 - if (unlikely((seg >> 3) >= child->mm->context.size))
19291 + if (unlikely(seg >= child->mm->context.size))
19292 addr = -1L; /* bogus selector, access would fault */
19293 else {
19294 desc = child->mm->context.ldt + seg;
19295 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19296 addr += base;
19297 }
19298 mutex_unlock(&child->mm->context.lock);
19299 - }
19300 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19301 + addr = ktla_ktva(addr);
19302
19303 return addr;
19304 }
19305 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19306 unsigned char opcode[15];
19307 unsigned long addr = convert_ip_to_linear(child, regs);
19308
19309 + if (addr == -EINVAL)
19310 + return 0;
19311 +
19312 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19313 for (i = 0; i < copied; i++) {
19314 switch (opcode[i]) {
19315 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19316 index 0b0cb5f..db6b9ed 100644
19317 --- a/arch/x86/kernel/sys_i386_32.c
19318 +++ b/arch/x86/kernel/sys_i386_32.c
19319 @@ -24,17 +24,224 @@
19320
19321 #include <asm/syscalls.h>
19322
19323 -/*
19324 - * Do a system call from kernel instead of calling sys_execve so we
19325 - * end up with proper pt_regs.
19326 - */
19327 -int kernel_execve(const char *filename,
19328 - const char *const argv[],
19329 - const char *const envp[])
19330 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19331 {
19332 - long __res;
19333 - asm volatile ("int $0x80"
19334 - : "=a" (__res)
19335 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19336 - return __res;
19337 + unsigned long pax_task_size = TASK_SIZE;
19338 +
19339 +#ifdef CONFIG_PAX_SEGMEXEC
19340 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19341 + pax_task_size = SEGMEXEC_TASK_SIZE;
19342 +#endif
19343 +
19344 + if (len > pax_task_size || addr > pax_task_size - len)
19345 + return -EINVAL;
19346 +
19347 + return 0;
19348 +}
19349 +
19350 +unsigned long
19351 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
19352 + unsigned long len, unsigned long pgoff, unsigned long flags)
19353 +{
19354 + struct mm_struct *mm = current->mm;
19355 + struct vm_area_struct *vma;
19356 + unsigned long start_addr, pax_task_size = TASK_SIZE;
19357 +
19358 +#ifdef CONFIG_PAX_SEGMEXEC
19359 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19360 + pax_task_size = SEGMEXEC_TASK_SIZE;
19361 +#endif
19362 +
19363 + pax_task_size -= PAGE_SIZE;
19364 +
19365 + if (len > pax_task_size)
19366 + return -ENOMEM;
19367 +
19368 + if (flags & MAP_FIXED)
19369 + return addr;
19370 +
19371 +#ifdef CONFIG_PAX_RANDMMAP
19372 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19373 +#endif
19374 +
19375 + if (addr) {
19376 + addr = PAGE_ALIGN(addr);
19377 + if (pax_task_size - len >= addr) {
19378 + vma = find_vma(mm, addr);
19379 + if (check_heap_stack_gap(vma, addr, len))
19380 + return addr;
19381 + }
19382 + }
19383 + if (len > mm->cached_hole_size) {
19384 + start_addr = addr = mm->free_area_cache;
19385 + } else {
19386 + start_addr = addr = mm->mmap_base;
19387 + mm->cached_hole_size = 0;
19388 + }
19389 +
19390 +#ifdef CONFIG_PAX_PAGEEXEC
19391 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19392 + start_addr = 0x00110000UL;
19393 +
19394 +#ifdef CONFIG_PAX_RANDMMAP
19395 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19396 + start_addr += mm->delta_mmap & 0x03FFF000UL;
19397 +#endif
19398 +
19399 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19400 + start_addr = addr = mm->mmap_base;
19401 + else
19402 + addr = start_addr;
19403 + }
19404 +#endif
19405 +
19406 +full_search:
19407 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19408 + /* At this point: (!vma || addr < vma->vm_end). */
19409 + if (pax_task_size - len < addr) {
19410 + /*
19411 + * Start a new search - just in case we missed
19412 + * some holes.
19413 + */
19414 + if (start_addr != mm->mmap_base) {
19415 + start_addr = addr = mm->mmap_base;
19416 + mm->cached_hole_size = 0;
19417 + goto full_search;
19418 + }
19419 + return -ENOMEM;
19420 + }
19421 + if (check_heap_stack_gap(vma, addr, len))
19422 + break;
19423 + if (addr + mm->cached_hole_size < vma->vm_start)
19424 + mm->cached_hole_size = vma->vm_start - addr;
19425 + addr = vma->vm_end;
19426 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
19427 + start_addr = addr = mm->mmap_base;
19428 + mm->cached_hole_size = 0;
19429 + goto full_search;
19430 + }
19431 + }
19432 +
19433 + /*
19434 + * Remember the place where we stopped the search:
19435 + */
19436 + mm->free_area_cache = addr + len;
19437 + return addr;
19438 +}
19439 +
19440 +unsigned long
19441 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19442 + const unsigned long len, const unsigned long pgoff,
19443 + const unsigned long flags)
19444 +{
19445 + struct vm_area_struct *vma;
19446 + struct mm_struct *mm = current->mm;
19447 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19448 +
19449 +#ifdef CONFIG_PAX_SEGMEXEC
19450 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19451 + pax_task_size = SEGMEXEC_TASK_SIZE;
19452 +#endif
19453 +
19454 + pax_task_size -= PAGE_SIZE;
19455 +
19456 + /* requested length too big for entire address space */
19457 + if (len > pax_task_size)
19458 + return -ENOMEM;
19459 +
19460 + if (flags & MAP_FIXED)
19461 + return addr;
19462 +
19463 +#ifdef CONFIG_PAX_PAGEEXEC
19464 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19465 + goto bottomup;
19466 +#endif
19467 +
19468 +#ifdef CONFIG_PAX_RANDMMAP
19469 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19470 +#endif
19471 +
19472 + /* requesting a specific address */
19473 + if (addr) {
19474 + addr = PAGE_ALIGN(addr);
19475 + if (pax_task_size - len >= addr) {
19476 + vma = find_vma(mm, addr);
19477 + if (check_heap_stack_gap(vma, addr, len))
19478 + return addr;
19479 + }
19480 + }
19481 +
19482 + /* check if free_area_cache is useful for us */
19483 + if (len <= mm->cached_hole_size) {
19484 + mm->cached_hole_size = 0;
19485 + mm->free_area_cache = mm->mmap_base;
19486 + }
19487 +
19488 + /* either no address requested or can't fit in requested address hole */
19489 + addr = mm->free_area_cache;
19490 +
19491 + /* make sure it can fit in the remaining address space */
19492 + if (addr > len) {
19493 + vma = find_vma(mm, addr-len);
19494 + if (check_heap_stack_gap(vma, addr - len, len))
19495 + /* remember the address as a hint for next time */
19496 + return (mm->free_area_cache = addr-len);
19497 + }
19498 +
19499 + if (mm->mmap_base < len)
19500 + goto bottomup;
19501 +
19502 + addr = mm->mmap_base-len;
19503 +
19504 + do {
19505 + /*
19506 + * Lookup failure means no vma is above this address,
19507 + * else if new region fits below vma->vm_start,
19508 + * return with success:
19509 + */
19510 + vma = find_vma(mm, addr);
19511 + if (check_heap_stack_gap(vma, addr, len))
19512 + /* remember the address as a hint for next time */
19513 + return (mm->free_area_cache = addr);
19514 +
19515 + /* remember the largest hole we saw so far */
19516 + if (addr + mm->cached_hole_size < vma->vm_start)
19517 + mm->cached_hole_size = vma->vm_start - addr;
19518 +
19519 + /* try just below the current vma->vm_start */
19520 + addr = skip_heap_stack_gap(vma, len);
19521 + } while (!IS_ERR_VALUE(addr));
19522 +
19523 +bottomup:
19524 + /*
19525 + * A failed mmap() very likely causes application failure,
19526 + * so fall back to the bottom-up function here. This scenario
19527 + * can happen with large stack limits and large mmap()
19528 + * allocations.
19529 + */
19530 +
19531 +#ifdef CONFIG_PAX_SEGMEXEC
19532 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19533 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19534 + else
19535 +#endif
19536 +
19537 + mm->mmap_base = TASK_UNMAPPED_BASE;
19538 +
19539 +#ifdef CONFIG_PAX_RANDMMAP
19540 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19541 + mm->mmap_base += mm->delta_mmap;
19542 +#endif
19543 +
19544 + mm->free_area_cache = mm->mmap_base;
19545 + mm->cached_hole_size = ~0UL;
19546 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19547 + /*
19548 + * Restore the topdown base:
19549 + */
19550 + mm->mmap_base = base;
19551 + mm->free_area_cache = base;
19552 + mm->cached_hole_size = ~0UL;
19553 +
19554 + return addr;
19555 }
19556 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19557 index b4d3c39..82bb73b 100644
19558 --- a/arch/x86/kernel/sys_x86_64.c
19559 +++ b/arch/x86/kernel/sys_x86_64.c
19560 @@ -95,8 +95,8 @@ out:
19561 return error;
19562 }
19563
19564 -static void find_start_end(unsigned long flags, unsigned long *begin,
19565 - unsigned long *end)
19566 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
19567 + unsigned long *begin, unsigned long *end)
19568 {
19569 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19570 unsigned long new_begin;
19571 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19572 *begin = new_begin;
19573 }
19574 } else {
19575 - *begin = TASK_UNMAPPED_BASE;
19576 + *begin = mm->mmap_base;
19577 *end = TASK_SIZE;
19578 }
19579 }
19580 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19581 if (flags & MAP_FIXED)
19582 return addr;
19583
19584 - find_start_end(flags, &begin, &end);
19585 + find_start_end(mm, flags, &begin, &end);
19586
19587 if (len > end)
19588 return -ENOMEM;
19589
19590 +#ifdef CONFIG_PAX_RANDMMAP
19591 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19592 +#endif
19593 +
19594 if (addr) {
19595 addr = PAGE_ALIGN(addr);
19596 vma = find_vma(mm, addr);
19597 - if (end - len >= addr &&
19598 - (!vma || addr + len <= vma->vm_start))
19599 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19600 return addr;
19601 }
19602 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19603 @@ -172,7 +175,7 @@ full_search:
19604 }
19605 return -ENOMEM;
19606 }
19607 - if (!vma || addr + len <= vma->vm_start) {
19608 + if (check_heap_stack_gap(vma, addr, len)) {
19609 /*
19610 * Remember the place where we stopped the search:
19611 */
19612 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19613 {
19614 struct vm_area_struct *vma;
19615 struct mm_struct *mm = current->mm;
19616 - unsigned long addr = addr0, start_addr;
19617 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19618
19619 /* requested length too big for entire address space */
19620 if (len > TASK_SIZE)
19621 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19622 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19623 goto bottomup;
19624
19625 +#ifdef CONFIG_PAX_RANDMMAP
19626 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19627 +#endif
19628 +
19629 /* requesting a specific address */
19630 if (addr) {
19631 addr = PAGE_ALIGN(addr);
19632 - vma = find_vma(mm, addr);
19633 - if (TASK_SIZE - len >= addr &&
19634 - (!vma || addr + len <= vma->vm_start))
19635 - return addr;
19636 + if (TASK_SIZE - len >= addr) {
19637 + vma = find_vma(mm, addr);
19638 + if (check_heap_stack_gap(vma, addr, len))
19639 + return addr;
19640 + }
19641 }
19642
19643 /* check if free_area_cache is useful for us */
19644 @@ -240,7 +248,7 @@ try_again:
19645 * return with success:
19646 */
19647 vma = find_vma(mm, addr);
19648 - if (!vma || addr+len <= vma->vm_start)
19649 + if (check_heap_stack_gap(vma, addr, len))
19650 /* remember the address as a hint for next time */
19651 return mm->free_area_cache = addr;
19652
19653 @@ -249,8 +257,8 @@ try_again:
19654 mm->cached_hole_size = vma->vm_start - addr;
19655
19656 /* try just below the current vma->vm_start */
19657 - addr = vma->vm_start-len;
19658 - } while (len < vma->vm_start);
19659 + addr = skip_heap_stack_gap(vma, len);
19660 + } while (!IS_ERR_VALUE(addr));
19661
19662 fail:
19663 /*
19664 @@ -270,13 +278,21 @@ bottomup:
19665 * can happen with large stack limits and large mmap()
19666 * allocations.
19667 */
19668 + mm->mmap_base = TASK_UNMAPPED_BASE;
19669 +
19670 +#ifdef CONFIG_PAX_RANDMMAP
19671 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19672 + mm->mmap_base += mm->delta_mmap;
19673 +#endif
19674 +
19675 + mm->free_area_cache = mm->mmap_base;
19676 mm->cached_hole_size = ~0UL;
19677 - mm->free_area_cache = TASK_UNMAPPED_BASE;
19678 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19679 /*
19680 * Restore the topdown base:
19681 */
19682 - mm->free_area_cache = mm->mmap_base;
19683 + mm->mmap_base = base;
19684 + mm->free_area_cache = base;
19685 mm->cached_hole_size = ~0UL;
19686
19687 return addr;
19688 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19689 index 6410744..79758f0 100644
19690 --- a/arch/x86/kernel/tboot.c
19691 +++ b/arch/x86/kernel/tboot.c
19692 @@ -219,7 +219,7 @@ static int tboot_setup_sleep(void)
19693
19694 void tboot_shutdown(u32 shutdown_type)
19695 {
19696 - void (*shutdown)(void);
19697 + void (* __noreturn shutdown)(void);
19698
19699 if (!tboot_enabled())
19700 return;
19701 @@ -241,7 +241,7 @@ void tboot_shutdown(u32 shutdown_type)
19702
19703 switch_to_tboot_pt();
19704
19705 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19706 + shutdown = (void *)tboot->shutdown_entry;
19707 shutdown();
19708
19709 /* should not reach here */
19710 @@ -299,7 +299,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19711 return 0;
19712 }
19713
19714 -static atomic_t ap_wfs_count;
19715 +static atomic_unchecked_t ap_wfs_count;
19716
19717 static int tboot_wait_for_aps(int num_aps)
19718 {
19719 @@ -323,9 +323,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19720 {
19721 switch (action) {
19722 case CPU_DYING:
19723 - atomic_inc(&ap_wfs_count);
19724 + atomic_inc_unchecked(&ap_wfs_count);
19725 if (num_online_cpus() == 1)
19726 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19727 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19728 return NOTIFY_BAD;
19729 break;
19730 }
19731 @@ -344,7 +344,7 @@ static __init int tboot_late_init(void)
19732
19733 tboot_create_trampoline();
19734
19735 - atomic_set(&ap_wfs_count, 0);
19736 + atomic_set_unchecked(&ap_wfs_count, 0);
19737 register_hotcpu_notifier(&tboot_cpu_notifier);
19738
19739 acpi_os_set_prepare_sleep(&tboot_sleep);
19740 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19741 index c6eba2b..3303326 100644
19742 --- a/arch/x86/kernel/time.c
19743 +++ b/arch/x86/kernel/time.c
19744 @@ -31,9 +31,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19745 {
19746 unsigned long pc = instruction_pointer(regs);
19747
19748 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19749 + if (!user_mode(regs) && in_lock_functions(pc)) {
19750 #ifdef CONFIG_FRAME_POINTER
19751 - return *(unsigned long *)(regs->bp + sizeof(long));
19752 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19753 #else
19754 unsigned long *sp =
19755 (unsigned long *)kernel_stack_pointer(regs);
19756 @@ -42,11 +42,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19757 * or above a saved flags. Eflags has bits 22-31 zero,
19758 * kernel addresses don't.
19759 */
19760 +
19761 +#ifdef CONFIG_PAX_KERNEXEC
19762 + return ktla_ktva(sp[0]);
19763 +#else
19764 if (sp[0] >> 22)
19765 return sp[0];
19766 if (sp[1] >> 22)
19767 return sp[1];
19768 #endif
19769 +
19770 +#endif
19771 }
19772 return pc;
19773 }
19774 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19775 index 9d9d2f9..ed344e4 100644
19776 --- a/arch/x86/kernel/tls.c
19777 +++ b/arch/x86/kernel/tls.c
19778 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19779 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19780 return -EINVAL;
19781
19782 +#ifdef CONFIG_PAX_SEGMEXEC
19783 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19784 + return -EINVAL;
19785 +#endif
19786 +
19787 set_tls_desc(p, idx, &info, 1);
19788
19789 return 0;
19790 diff --git a/arch/x86/kernel/trampoline_32.S b/arch/x86/kernel/trampoline_32.S
19791 index 451c0a7..e57f551 100644
19792 --- a/arch/x86/kernel/trampoline_32.S
19793 +++ b/arch/x86/kernel/trampoline_32.S
19794 @@ -32,6 +32,12 @@
19795 #include <asm/segment.h>
19796 #include <asm/page_types.h>
19797
19798 +#ifdef CONFIG_PAX_KERNEXEC
19799 +#define ta(X) (X)
19800 +#else
19801 +#define ta(X) ((X) - __PAGE_OFFSET)
19802 +#endif
19803 +
19804 #ifdef CONFIG_SMP
19805
19806 .section ".x86_trampoline","a"
19807 @@ -62,7 +68,7 @@ r_base = .
19808 inc %ax # protected mode (PE) bit
19809 lmsw %ax # into protected mode
19810 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
19811 - ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
19812 + ljmpl $__BOOT_CS, $ta(startup_32_smp)
19813
19814 # These need to be in the same 64K segment as the above;
19815 # hence we don't use the boot_gdt_descr defined in head.S
19816 diff --git a/arch/x86/kernel/trampoline_64.S b/arch/x86/kernel/trampoline_64.S
19817 index 09ff517..df19fbff 100644
19818 --- a/arch/x86/kernel/trampoline_64.S
19819 +++ b/arch/x86/kernel/trampoline_64.S
19820 @@ -90,7 +90,7 @@ startup_32:
19821 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
19822 movl %eax, %ds
19823
19824 - movl $X86_CR4_PAE, %eax
19825 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
19826 movl %eax, %cr4 # Enable PAE mode
19827
19828 # Setup trampoline 4 level pagetables
19829 @@ -138,7 +138,7 @@ tidt:
19830 # so the kernel can live anywhere
19831 .balign 4
19832 tgdt:
19833 - .short tgdt_end - tgdt # gdt limit
19834 + .short tgdt_end - tgdt - 1 # gdt limit
19835 .long tgdt - r_base
19836 .short 0
19837 .quad 0x00cf9b000000ffff # __KERNEL32_CS
19838 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19839 index ff9281f1..30cb4ac 100644
19840 --- a/arch/x86/kernel/traps.c
19841 +++ b/arch/x86/kernel/traps.c
19842 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19843
19844 /* Do we ignore FPU interrupts ? */
19845 char ignore_fpu_irq;
19846 -
19847 -/*
19848 - * The IDT has to be page-aligned to simplify the Pentium
19849 - * F0 0F bug workaround.
19850 - */
19851 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19852 #endif
19853
19854 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19855 @@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19856 }
19857
19858 static void __kprobes
19859 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19860 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19861 long error_code, siginfo_t *info)
19862 {
19863 struct task_struct *tsk = current;
19864
19865 #ifdef CONFIG_X86_32
19866 - if (regs->flags & X86_VM_MASK) {
19867 + if (v8086_mode(regs)) {
19868 /*
19869 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19870 * On nmi (interrupt 2), do_trap should not be called.
19871 @@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19872 }
19873 #endif
19874
19875 - if (!user_mode(regs))
19876 + if (!user_mode_novm(regs))
19877 goto kernel_trap;
19878
19879 #ifdef CONFIG_X86_32
19880 @@ -148,7 +142,7 @@ trap_signal:
19881 printk_ratelimit()) {
19882 printk(KERN_INFO
19883 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19884 - tsk->comm, tsk->pid, str,
19885 + tsk->comm, task_pid_nr(tsk), str,
19886 regs->ip, regs->sp, error_code);
19887 print_vma_addr(" in ", regs->ip);
19888 printk("\n");
19889 @@ -165,8 +159,20 @@ kernel_trap:
19890 if (!fixup_exception(regs)) {
19891 tsk->thread.error_code = error_code;
19892 tsk->thread.trap_nr = trapnr;
19893 +
19894 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19895 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19896 + str = "PAX: suspicious stack segment fault";
19897 +#endif
19898 +
19899 die(str, regs, error_code);
19900 }
19901 +
19902 +#ifdef CONFIG_PAX_REFCOUNT
19903 + if (trapnr == 4)
19904 + pax_report_refcount_overflow(regs);
19905 +#endif
19906 +
19907 return;
19908
19909 #ifdef CONFIG_X86_32
19910 @@ -259,14 +265,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19911 conditional_sti(regs);
19912
19913 #ifdef CONFIG_X86_32
19914 - if (regs->flags & X86_VM_MASK)
19915 + if (v8086_mode(regs))
19916 goto gp_in_vm86;
19917 #endif
19918
19919 tsk = current;
19920 - if (!user_mode(regs))
19921 + if (!user_mode_novm(regs))
19922 goto gp_in_kernel;
19923
19924 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19925 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19926 + struct mm_struct *mm = tsk->mm;
19927 + unsigned long limit;
19928 +
19929 + down_write(&mm->mmap_sem);
19930 + limit = mm->context.user_cs_limit;
19931 + if (limit < TASK_SIZE) {
19932 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19933 + up_write(&mm->mmap_sem);
19934 + return;
19935 + }
19936 + up_write(&mm->mmap_sem);
19937 + }
19938 +#endif
19939 +
19940 tsk->thread.error_code = error_code;
19941 tsk->thread.trap_nr = X86_TRAP_GP;
19942
19943 @@ -299,6 +321,13 @@ gp_in_kernel:
19944 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19945 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19946 return;
19947 +
19948 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19949 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19950 + die("PAX: suspicious general protection fault", regs, error_code);
19951 + else
19952 +#endif
19953 +
19954 die("general protection fault", regs, error_code);
19955 }
19956
19957 @@ -425,7 +454,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19958 /* It's safe to allow irq's after DR6 has been saved */
19959 preempt_conditional_sti(regs);
19960
19961 - if (regs->flags & X86_VM_MASK) {
19962 + if (v8086_mode(regs)) {
19963 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
19964 X86_TRAP_DB);
19965 preempt_conditional_cli(regs);
19966 @@ -440,7 +469,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19967 * We already checked v86 mode above, so we can check for kernel mode
19968 * by just checking the CPL of CS.
19969 */
19970 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
19971 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19972 tsk->thread.debugreg6 &= ~DR_STEP;
19973 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19974 regs->flags &= ~X86_EFLAGS_TF;
19975 @@ -471,7 +500,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19976 return;
19977 conditional_sti(regs);
19978
19979 - if (!user_mode_vm(regs))
19980 + if (!user_mode(regs))
19981 {
19982 if (!fixup_exception(regs)) {
19983 task->thread.error_code = error_code;
19984 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19985 index b9242ba..50c5edd 100644
19986 --- a/arch/x86/kernel/verify_cpu.S
19987 +++ b/arch/x86/kernel/verify_cpu.S
19988 @@ -20,6 +20,7 @@
19989 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19990 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19991 * arch/x86/kernel/head_32.S: processor startup
19992 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19993 *
19994 * verify_cpu, returns the status of longmode and SSE in register %eax.
19995 * 0: Success 1: Failure
19996 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19997 index 255f58a..5e91150 100644
19998 --- a/arch/x86/kernel/vm86_32.c
19999 +++ b/arch/x86/kernel/vm86_32.c
20000 @@ -41,6 +41,7 @@
20001 #include <linux/ptrace.h>
20002 #include <linux/audit.h>
20003 #include <linux/stddef.h>
20004 +#include <linux/grsecurity.h>
20005
20006 #include <asm/uaccess.h>
20007 #include <asm/io.h>
20008 @@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
20009 do_exit(SIGSEGV);
20010 }
20011
20012 - tss = &per_cpu(init_tss, get_cpu());
20013 + tss = init_tss + get_cpu();
20014 current->thread.sp0 = current->thread.saved_sp0;
20015 current->thread.sysenter_cs = __KERNEL_CS;
20016 load_sp0(tss, &current->thread);
20017 @@ -210,6 +211,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
20018 struct task_struct *tsk;
20019 int tmp, ret = -EPERM;
20020
20021 +#ifdef CONFIG_GRKERNSEC_VM86
20022 + if (!capable(CAP_SYS_RAWIO)) {
20023 + gr_handle_vm86();
20024 + goto out;
20025 + }
20026 +#endif
20027 +
20028 tsk = current;
20029 if (tsk->thread.saved_sp0)
20030 goto out;
20031 @@ -240,6 +248,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
20032 int tmp, ret;
20033 struct vm86plus_struct __user *v86;
20034
20035 +#ifdef CONFIG_GRKERNSEC_VM86
20036 + if (!capable(CAP_SYS_RAWIO)) {
20037 + gr_handle_vm86();
20038 + ret = -EPERM;
20039 + goto out;
20040 + }
20041 +#endif
20042 +
20043 tsk = current;
20044 switch (cmd) {
20045 case VM86_REQUEST_IRQ:
20046 @@ -326,7 +342,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
20047 tsk->thread.saved_fs = info->regs32->fs;
20048 tsk->thread.saved_gs = get_user_gs(info->regs32);
20049
20050 - tss = &per_cpu(init_tss, get_cpu());
20051 + tss = init_tss + get_cpu();
20052 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
20053 if (cpu_has_sep)
20054 tsk->thread.sysenter_cs = 0;
20055 @@ -533,7 +549,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
20056 goto cannot_handle;
20057 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
20058 goto cannot_handle;
20059 - intr_ptr = (unsigned long __user *) (i << 2);
20060 + intr_ptr = (__force unsigned long __user *) (i << 2);
20061 if (get_user(segoffs, intr_ptr))
20062 goto cannot_handle;
20063 if ((segoffs >> 16) == BIOSSEG)
20064 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
20065 index 0f703f1..9e15f64 100644
20066 --- a/arch/x86/kernel/vmlinux.lds.S
20067 +++ b/arch/x86/kernel/vmlinux.lds.S
20068 @@ -26,6 +26,13 @@
20069 #include <asm/page_types.h>
20070 #include <asm/cache.h>
20071 #include <asm/boot.h>
20072 +#include <asm/segment.h>
20073 +
20074 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20075 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
20076 +#else
20077 +#define __KERNEL_TEXT_OFFSET 0
20078 +#endif
20079
20080 #undef i386 /* in case the preprocessor is a 32bit one */
20081
20082 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
20083
20084 PHDRS {
20085 text PT_LOAD FLAGS(5); /* R_E */
20086 +#ifdef CONFIG_X86_32
20087 + module PT_LOAD FLAGS(5); /* R_E */
20088 +#endif
20089 +#ifdef CONFIG_XEN
20090 + rodata PT_LOAD FLAGS(5); /* R_E */
20091 +#else
20092 + rodata PT_LOAD FLAGS(4); /* R__ */
20093 +#endif
20094 data PT_LOAD FLAGS(6); /* RW_ */
20095 -#ifdef CONFIG_X86_64
20096 + init.begin PT_LOAD FLAGS(6); /* RW_ */
20097 #ifdef CONFIG_SMP
20098 percpu PT_LOAD FLAGS(6); /* RW_ */
20099 #endif
20100 + text.init PT_LOAD FLAGS(5); /* R_E */
20101 + text.exit PT_LOAD FLAGS(5); /* R_E */
20102 init PT_LOAD FLAGS(7); /* RWE */
20103 -#endif
20104 note PT_NOTE FLAGS(0); /* ___ */
20105 }
20106
20107 SECTIONS
20108 {
20109 #ifdef CONFIG_X86_32
20110 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
20111 - phys_startup_32 = startup_32 - LOAD_OFFSET;
20112 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
20113 #else
20114 - . = __START_KERNEL;
20115 - phys_startup_64 = startup_64 - LOAD_OFFSET;
20116 + . = __START_KERNEL;
20117 #endif
20118
20119 /* Text and read-only data */
20120 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
20121 - _text = .;
20122 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20123 /* bootstrapping code */
20124 +#ifdef CONFIG_X86_32
20125 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20126 +#else
20127 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20128 +#endif
20129 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20130 + _text = .;
20131 HEAD_TEXT
20132 #ifdef CONFIG_X86_32
20133 . = ALIGN(PAGE_SIZE);
20134 @@ -108,13 +128,47 @@ SECTIONS
20135 IRQENTRY_TEXT
20136 *(.fixup)
20137 *(.gnu.warning)
20138 - /* End of text section */
20139 - _etext = .;
20140 } :text = 0x9090
20141
20142 - NOTES :text :note
20143 + . += __KERNEL_TEXT_OFFSET;
20144
20145 - EXCEPTION_TABLE(16) :text = 0x9090
20146 +#ifdef CONFIG_X86_32
20147 + . = ALIGN(PAGE_SIZE);
20148 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
20149 +
20150 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
20151 + MODULES_EXEC_VADDR = .;
20152 + BYTE(0)
20153 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
20154 + . = ALIGN(HPAGE_SIZE);
20155 + MODULES_EXEC_END = . - 1;
20156 +#endif
20157 +
20158 + } :module
20159 +#endif
20160 +
20161 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20162 + /* End of text section */
20163 + _etext = . - __KERNEL_TEXT_OFFSET;
20164 + }
20165 +
20166 +#ifdef CONFIG_X86_32
20167 + . = ALIGN(PAGE_SIZE);
20168 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20169 + *(.idt)
20170 + . = ALIGN(PAGE_SIZE);
20171 + *(.empty_zero_page)
20172 + *(.initial_pg_fixmap)
20173 + *(.initial_pg_pmd)
20174 + *(.initial_page_table)
20175 + *(.swapper_pg_dir)
20176 + } :rodata
20177 +#endif
20178 +
20179 + . = ALIGN(PAGE_SIZE);
20180 + NOTES :rodata :note
20181 +
20182 + EXCEPTION_TABLE(16) :rodata
20183
20184 #if defined(CONFIG_DEBUG_RODATA)
20185 /* .text should occupy whole number of pages */
20186 @@ -126,16 +180,20 @@ SECTIONS
20187
20188 /* Data */
20189 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20190 +
20191 +#ifdef CONFIG_PAX_KERNEXEC
20192 + . = ALIGN(HPAGE_SIZE);
20193 +#else
20194 + . = ALIGN(PAGE_SIZE);
20195 +#endif
20196 +
20197 /* Start of data section */
20198 _sdata = .;
20199
20200 /* init_task */
20201 INIT_TASK_DATA(THREAD_SIZE)
20202
20203 -#ifdef CONFIG_X86_32
20204 - /* 32 bit has nosave before _edata */
20205 NOSAVE_DATA
20206 -#endif
20207
20208 PAGE_ALIGNED_DATA(PAGE_SIZE)
20209
20210 @@ -176,12 +234,19 @@ SECTIONS
20211 #endif /* CONFIG_X86_64 */
20212
20213 /* Init code and data - will be freed after init */
20214 - . = ALIGN(PAGE_SIZE);
20215 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20216 + BYTE(0)
20217 +
20218 +#ifdef CONFIG_PAX_KERNEXEC
20219 + . = ALIGN(HPAGE_SIZE);
20220 +#else
20221 + . = ALIGN(PAGE_SIZE);
20222 +#endif
20223 +
20224 __init_begin = .; /* paired with __init_end */
20225 - }
20226 + } :init.begin
20227
20228 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20229 +#ifdef CONFIG_SMP
20230 /*
20231 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20232 * output PHDR, so the next output section - .init.text - should
20233 @@ -190,12 +255,27 @@ SECTIONS
20234 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20235 #endif
20236
20237 - INIT_TEXT_SECTION(PAGE_SIZE)
20238 -#ifdef CONFIG_X86_64
20239 - :init
20240 -#endif
20241 + . = ALIGN(PAGE_SIZE);
20242 + init_begin = .;
20243 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20244 + VMLINUX_SYMBOL(_sinittext) = .;
20245 + INIT_TEXT
20246 + VMLINUX_SYMBOL(_einittext) = .;
20247 + . = ALIGN(PAGE_SIZE);
20248 + } :text.init
20249
20250 - INIT_DATA_SECTION(16)
20251 + /*
20252 + * .exit.text is discard at runtime, not link time, to deal with
20253 + * references from .altinstructions and .eh_frame
20254 + */
20255 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20256 + EXIT_TEXT
20257 + . = ALIGN(16);
20258 + } :text.exit
20259 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20260 +
20261 + . = ALIGN(PAGE_SIZE);
20262 + INIT_DATA_SECTION(16) :init
20263
20264 /*
20265 * Code and data for a variety of lowlevel trampolines, to be
20266 @@ -269,19 +349,12 @@ SECTIONS
20267 }
20268
20269 . = ALIGN(8);
20270 - /*
20271 - * .exit.text is discard at runtime, not link time, to deal with
20272 - * references from .altinstructions and .eh_frame
20273 - */
20274 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20275 - EXIT_TEXT
20276 - }
20277
20278 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20279 EXIT_DATA
20280 }
20281
20282 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20283 +#ifndef CONFIG_SMP
20284 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20285 #endif
20286
20287 @@ -300,16 +373,10 @@ SECTIONS
20288 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20289 __smp_locks = .;
20290 *(.smp_locks)
20291 - . = ALIGN(PAGE_SIZE);
20292 __smp_locks_end = .;
20293 + . = ALIGN(PAGE_SIZE);
20294 }
20295
20296 -#ifdef CONFIG_X86_64
20297 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20298 - NOSAVE_DATA
20299 - }
20300 -#endif
20301 -
20302 /* BSS */
20303 . = ALIGN(PAGE_SIZE);
20304 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20305 @@ -325,6 +392,7 @@ SECTIONS
20306 __brk_base = .;
20307 . += 64 * 1024; /* 64k alignment slop space */
20308 *(.brk_reservation) /* areas brk users have reserved */
20309 + . = ALIGN(HPAGE_SIZE);
20310 __brk_limit = .;
20311 }
20312
20313 @@ -351,13 +419,12 @@ SECTIONS
20314 * for the boot processor.
20315 */
20316 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20317 -INIT_PER_CPU(gdt_page);
20318 INIT_PER_CPU(irq_stack_union);
20319
20320 /*
20321 * Build-time check on the image size:
20322 */
20323 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20324 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20325 "kernel image bigger than KERNEL_IMAGE_SIZE");
20326
20327 #ifdef CONFIG_SMP
20328 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20329 index 7515cf0..331a1a0 100644
20330 --- a/arch/x86/kernel/vsyscall_64.c
20331 +++ b/arch/x86/kernel/vsyscall_64.c
20332 @@ -54,15 +54,13 @@
20333 DEFINE_VVAR(int, vgetcpu_mode);
20334 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20335
20336 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20337 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20338
20339 static int __init vsyscall_setup(char *str)
20340 {
20341 if (str) {
20342 if (!strcmp("emulate", str))
20343 vsyscall_mode = EMULATE;
20344 - else if (!strcmp("native", str))
20345 - vsyscall_mode = NATIVE;
20346 else if (!strcmp("none", str))
20347 vsyscall_mode = NONE;
20348 else
20349 @@ -206,7 +204,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
20350
20351 tsk = current;
20352 if (seccomp_mode(&tsk->seccomp))
20353 - do_exit(SIGKILL);
20354 + do_group_exit(SIGKILL);
20355
20356 /*
20357 * With a real vsyscall, page faults cause SIGSEGV. We want to
20358 @@ -278,8 +276,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
20359 return true;
20360
20361 sigsegv:
20362 - force_sig(SIGSEGV, current);
20363 - return true;
20364 + do_group_exit(SIGKILL);
20365 }
20366
20367 /*
20368 @@ -332,10 +329,7 @@ void __init map_vsyscall(void)
20369 extern char __vvar_page;
20370 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20371
20372 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20373 - vsyscall_mode == NATIVE
20374 - ? PAGE_KERNEL_VSYSCALL
20375 - : PAGE_KERNEL_VVAR);
20376 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20377 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20378 (unsigned long)VSYSCALL_START);
20379
20380 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20381 index 9796c2f..f686fbf 100644
20382 --- a/arch/x86/kernel/x8664_ksyms_64.c
20383 +++ b/arch/x86/kernel/x8664_ksyms_64.c
20384 @@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
20385 EXPORT_SYMBOL(copy_user_generic_string);
20386 EXPORT_SYMBOL(copy_user_generic_unrolled);
20387 EXPORT_SYMBOL(__copy_user_nocache);
20388 -EXPORT_SYMBOL(_copy_from_user);
20389 -EXPORT_SYMBOL(_copy_to_user);
20390
20391 EXPORT_SYMBOL(copy_page);
20392 EXPORT_SYMBOL(clear_page);
20393 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20394 index e62728e..5fc3a07 100644
20395 --- a/arch/x86/kernel/xsave.c
20396 +++ b/arch/x86/kernel/xsave.c
20397 @@ -131,7 +131,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20398 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20399 return -EINVAL;
20400
20401 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20402 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20403 fx_sw_user->extended_size -
20404 FP_XSTATE_MAGIC2_SIZE));
20405 if (err)
20406 @@ -267,7 +267,7 @@ fx_only:
20407 * the other extended state.
20408 */
20409 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20410 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20411 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20412 }
20413
20414 /*
20415 @@ -296,7 +296,7 @@ int restore_i387_xstate(void __user *buf)
20416 if (use_xsave())
20417 err = restore_user_xstate(buf);
20418 else
20419 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
20420 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20421 buf);
20422 if (unlikely(err)) {
20423 /*
20424 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20425 index 9fed5be..18fd595 100644
20426 --- a/arch/x86/kvm/cpuid.c
20427 +++ b/arch/x86/kvm/cpuid.c
20428 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20429 struct kvm_cpuid2 *cpuid,
20430 struct kvm_cpuid_entry2 __user *entries)
20431 {
20432 - int r;
20433 + int r, i;
20434
20435 r = -E2BIG;
20436 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20437 goto out;
20438 r = -EFAULT;
20439 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20440 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20441 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20442 goto out;
20443 + for (i = 0; i < cpuid->nent; ++i) {
20444 + struct kvm_cpuid_entry2 cpuid_entry;
20445 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20446 + goto out;
20447 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
20448 + }
20449 vcpu->arch.cpuid_nent = cpuid->nent;
20450 kvm_apic_set_version(vcpu);
20451 kvm_x86_ops->cpuid_update(vcpu);
20452 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20453 struct kvm_cpuid2 *cpuid,
20454 struct kvm_cpuid_entry2 __user *entries)
20455 {
20456 - int r;
20457 + int r, i;
20458
20459 r = -E2BIG;
20460 if (cpuid->nent < vcpu->arch.cpuid_nent)
20461 goto out;
20462 r = -EFAULT;
20463 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20464 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20465 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20466 goto out;
20467 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20468 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20469 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20470 + goto out;
20471 + }
20472 return 0;
20473
20474 out:
20475 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20476 index 8375622..b7bca1a 100644
20477 --- a/arch/x86/kvm/emulate.c
20478 +++ b/arch/x86/kvm/emulate.c
20479 @@ -252,6 +252,7 @@ struct gprefix {
20480
20481 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20482 do { \
20483 + unsigned long _tmp; \
20484 __asm__ __volatile__ ( \
20485 _PRE_EFLAGS("0", "4", "2") \
20486 _op _suffix " %"_x"3,%1; " \
20487 @@ -266,8 +267,6 @@ struct gprefix {
20488 /* Raw emulation: instruction has two explicit operands. */
20489 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20490 do { \
20491 - unsigned long _tmp; \
20492 - \
20493 switch ((ctxt)->dst.bytes) { \
20494 case 2: \
20495 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20496 @@ -283,7 +282,6 @@ struct gprefix {
20497
20498 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20499 do { \
20500 - unsigned long _tmp; \
20501 switch ((ctxt)->dst.bytes) { \
20502 case 1: \
20503 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20504 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20505 index 8584322..17d5955 100644
20506 --- a/arch/x86/kvm/lapic.c
20507 +++ b/arch/x86/kvm/lapic.c
20508 @@ -54,7 +54,7 @@
20509 #define APIC_BUS_CYCLE_NS 1
20510
20511 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20512 -#define apic_debug(fmt, arg...)
20513 +#define apic_debug(fmt, arg...) do {} while (0)
20514
20515 #define APIC_LVT_NUM 6
20516 /* 14 is the version for Xeon and Pentium 8.4.8*/
20517 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20518 index df5a703..63748a7 100644
20519 --- a/arch/x86/kvm/paging_tmpl.h
20520 +++ b/arch/x86/kvm/paging_tmpl.h
20521 @@ -197,7 +197,7 @@ retry_walk:
20522 if (unlikely(kvm_is_error_hva(host_addr)))
20523 goto error;
20524
20525 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20526 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20527 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20528 goto error;
20529
20530 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20531 index e334389..6839087 100644
20532 --- a/arch/x86/kvm/svm.c
20533 +++ b/arch/x86/kvm/svm.c
20534 @@ -3509,7 +3509,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20535 int cpu = raw_smp_processor_id();
20536
20537 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20538 +
20539 + pax_open_kernel();
20540 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20541 + pax_close_kernel();
20542 +
20543 load_TR_desc();
20544 }
20545
20546 @@ -3887,6 +3891,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20547 #endif
20548 #endif
20549
20550 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20551 + __set_fs(current_thread_info()->addr_limit);
20552 +#endif
20553 +
20554 reload_tss(vcpu);
20555
20556 local_irq_disable();
20557 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20558 index 4ff0ab9..2ff68d3 100644
20559 --- a/arch/x86/kvm/vmx.c
20560 +++ b/arch/x86/kvm/vmx.c
20561 @@ -1303,7 +1303,11 @@ static void reload_tss(void)
20562 struct desc_struct *descs;
20563
20564 descs = (void *)gdt->address;
20565 +
20566 + pax_open_kernel();
20567 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20568 + pax_close_kernel();
20569 +
20570 load_TR_desc();
20571 }
20572
20573 @@ -2625,8 +2629,11 @@ static __init int hardware_setup(void)
20574 if (!cpu_has_vmx_flexpriority())
20575 flexpriority_enabled = 0;
20576
20577 - if (!cpu_has_vmx_tpr_shadow())
20578 - kvm_x86_ops->update_cr8_intercept = NULL;
20579 + if (!cpu_has_vmx_tpr_shadow()) {
20580 + pax_open_kernel();
20581 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20582 + pax_close_kernel();
20583 + }
20584
20585 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20586 kvm_disable_largepages();
20587 @@ -3642,7 +3649,7 @@ static void vmx_set_constant_host_state(void)
20588 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20589
20590 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20591 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20592 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20593
20594 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20595 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20596 @@ -6180,6 +6187,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20597 "jmp .Lkvm_vmx_return \n\t"
20598 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20599 ".Lkvm_vmx_return: "
20600 +
20601 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20602 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20603 + ".Lkvm_vmx_return2: "
20604 +#endif
20605 +
20606 /* Save guest registers, load host registers, keep flags */
20607 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20608 "pop %0 \n\t"
20609 @@ -6228,6 +6241,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20610 #endif
20611 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20612 [wordsize]"i"(sizeof(ulong))
20613 +
20614 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20615 + ,[cs]"i"(__KERNEL_CS)
20616 +#endif
20617 +
20618 : "cc", "memory"
20619 , R"ax", R"bx", R"di", R"si"
20620 #ifdef CONFIG_X86_64
20621 @@ -6256,7 +6274,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20622 }
20623 }
20624
20625 - asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
20626 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
20627 +
20628 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20629 + loadsegment(fs, __KERNEL_PERCPU);
20630 +#endif
20631 +
20632 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20633 + __set_fs(current_thread_info()->addr_limit);
20634 +#endif
20635 +
20636 vmx->loaded_vmcs->launched = 1;
20637
20638 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
20639 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20640 index 185a2b8..866d2a6 100644
20641 --- a/arch/x86/kvm/x86.c
20642 +++ b/arch/x86/kvm/x86.c
20643 @@ -1357,8 +1357,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20644 {
20645 struct kvm *kvm = vcpu->kvm;
20646 int lm = is_long_mode(vcpu);
20647 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20648 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20649 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20650 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20651 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20652 : kvm->arch.xen_hvm_config.blob_size_32;
20653 u32 page_num = data & ~PAGE_MASK;
20654 @@ -2213,6 +2213,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20655 if (n < msr_list.nmsrs)
20656 goto out;
20657 r = -EFAULT;
20658 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20659 + goto out;
20660 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20661 num_msrs_to_save * sizeof(u32)))
20662 goto out;
20663 @@ -2338,7 +2340,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20664 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20665 struct kvm_interrupt *irq)
20666 {
20667 - if (irq->irq < 0 || irq->irq >= 256)
20668 + if (irq->irq >= 256)
20669 return -EINVAL;
20670 if (irqchip_in_kernel(vcpu->kvm))
20671 return -ENXIO;
20672 @@ -4860,7 +4862,7 @@ static void kvm_set_mmio_spte_mask(void)
20673 kvm_mmu_set_mmio_spte_mask(mask);
20674 }
20675
20676 -int kvm_arch_init(void *opaque)
20677 +int kvm_arch_init(const void *opaque)
20678 {
20679 int r;
20680 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20681 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20682 index 642d880..44e0f3f 100644
20683 --- a/arch/x86/lguest/boot.c
20684 +++ b/arch/x86/lguest/boot.c
20685 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20686 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20687 * Launcher to reboot us.
20688 */
20689 -static void lguest_restart(char *reason)
20690 +static __noreturn void lguest_restart(char *reason)
20691 {
20692 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20693 + BUG();
20694 }
20695
20696 /*G:050
20697 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20698 index 00933d5..3a64af9 100644
20699 --- a/arch/x86/lib/atomic64_386_32.S
20700 +++ b/arch/x86/lib/atomic64_386_32.S
20701 @@ -48,6 +48,10 @@ BEGIN(read)
20702 movl (v), %eax
20703 movl 4(v), %edx
20704 RET_ENDP
20705 +BEGIN(read_unchecked)
20706 + movl (v), %eax
20707 + movl 4(v), %edx
20708 +RET_ENDP
20709 #undef v
20710
20711 #define v %esi
20712 @@ -55,6 +59,10 @@ BEGIN(set)
20713 movl %ebx, (v)
20714 movl %ecx, 4(v)
20715 RET_ENDP
20716 +BEGIN(set_unchecked)
20717 + movl %ebx, (v)
20718 + movl %ecx, 4(v)
20719 +RET_ENDP
20720 #undef v
20721
20722 #define v %esi
20723 @@ -70,6 +78,20 @@ RET_ENDP
20724 BEGIN(add)
20725 addl %eax, (v)
20726 adcl %edx, 4(v)
20727 +
20728 +#ifdef CONFIG_PAX_REFCOUNT
20729 + jno 0f
20730 + subl %eax, (v)
20731 + sbbl %edx, 4(v)
20732 + int $4
20733 +0:
20734 + _ASM_EXTABLE(0b, 0b)
20735 +#endif
20736 +
20737 +RET_ENDP
20738 +BEGIN(add_unchecked)
20739 + addl %eax, (v)
20740 + adcl %edx, 4(v)
20741 RET_ENDP
20742 #undef v
20743
20744 @@ -77,6 +99,24 @@ RET_ENDP
20745 BEGIN(add_return)
20746 addl (v), %eax
20747 adcl 4(v), %edx
20748 +
20749 +#ifdef CONFIG_PAX_REFCOUNT
20750 + into
20751 +1234:
20752 + _ASM_EXTABLE(1234b, 2f)
20753 +#endif
20754 +
20755 + movl %eax, (v)
20756 + movl %edx, 4(v)
20757 +
20758 +#ifdef CONFIG_PAX_REFCOUNT
20759 +2:
20760 +#endif
20761 +
20762 +RET_ENDP
20763 +BEGIN(add_return_unchecked)
20764 + addl (v), %eax
20765 + adcl 4(v), %edx
20766 movl %eax, (v)
20767 movl %edx, 4(v)
20768 RET_ENDP
20769 @@ -86,6 +126,20 @@ RET_ENDP
20770 BEGIN(sub)
20771 subl %eax, (v)
20772 sbbl %edx, 4(v)
20773 +
20774 +#ifdef CONFIG_PAX_REFCOUNT
20775 + jno 0f
20776 + addl %eax, (v)
20777 + adcl %edx, 4(v)
20778 + int $4
20779 +0:
20780 + _ASM_EXTABLE(0b, 0b)
20781 +#endif
20782 +
20783 +RET_ENDP
20784 +BEGIN(sub_unchecked)
20785 + subl %eax, (v)
20786 + sbbl %edx, 4(v)
20787 RET_ENDP
20788 #undef v
20789
20790 @@ -96,6 +150,27 @@ BEGIN(sub_return)
20791 sbbl $0, %edx
20792 addl (v), %eax
20793 adcl 4(v), %edx
20794 +
20795 +#ifdef CONFIG_PAX_REFCOUNT
20796 + into
20797 +1234:
20798 + _ASM_EXTABLE(1234b, 2f)
20799 +#endif
20800 +
20801 + movl %eax, (v)
20802 + movl %edx, 4(v)
20803 +
20804 +#ifdef CONFIG_PAX_REFCOUNT
20805 +2:
20806 +#endif
20807 +
20808 +RET_ENDP
20809 +BEGIN(sub_return_unchecked)
20810 + negl %edx
20811 + negl %eax
20812 + sbbl $0, %edx
20813 + addl (v), %eax
20814 + adcl 4(v), %edx
20815 movl %eax, (v)
20816 movl %edx, 4(v)
20817 RET_ENDP
20818 @@ -105,6 +180,20 @@ RET_ENDP
20819 BEGIN(inc)
20820 addl $1, (v)
20821 adcl $0, 4(v)
20822 +
20823 +#ifdef CONFIG_PAX_REFCOUNT
20824 + jno 0f
20825 + subl $1, (v)
20826 + sbbl $0, 4(v)
20827 + int $4
20828 +0:
20829 + _ASM_EXTABLE(0b, 0b)
20830 +#endif
20831 +
20832 +RET_ENDP
20833 +BEGIN(inc_unchecked)
20834 + addl $1, (v)
20835 + adcl $0, 4(v)
20836 RET_ENDP
20837 #undef v
20838
20839 @@ -114,6 +203,26 @@ BEGIN(inc_return)
20840 movl 4(v), %edx
20841 addl $1, %eax
20842 adcl $0, %edx
20843 +
20844 +#ifdef CONFIG_PAX_REFCOUNT
20845 + into
20846 +1234:
20847 + _ASM_EXTABLE(1234b, 2f)
20848 +#endif
20849 +
20850 + movl %eax, (v)
20851 + movl %edx, 4(v)
20852 +
20853 +#ifdef CONFIG_PAX_REFCOUNT
20854 +2:
20855 +#endif
20856 +
20857 +RET_ENDP
20858 +BEGIN(inc_return_unchecked)
20859 + movl (v), %eax
20860 + movl 4(v), %edx
20861 + addl $1, %eax
20862 + adcl $0, %edx
20863 movl %eax, (v)
20864 movl %edx, 4(v)
20865 RET_ENDP
20866 @@ -123,6 +232,20 @@ RET_ENDP
20867 BEGIN(dec)
20868 subl $1, (v)
20869 sbbl $0, 4(v)
20870 +
20871 +#ifdef CONFIG_PAX_REFCOUNT
20872 + jno 0f
20873 + addl $1, (v)
20874 + adcl $0, 4(v)
20875 + int $4
20876 +0:
20877 + _ASM_EXTABLE(0b, 0b)
20878 +#endif
20879 +
20880 +RET_ENDP
20881 +BEGIN(dec_unchecked)
20882 + subl $1, (v)
20883 + sbbl $0, 4(v)
20884 RET_ENDP
20885 #undef v
20886
20887 @@ -132,6 +255,26 @@ BEGIN(dec_return)
20888 movl 4(v), %edx
20889 subl $1, %eax
20890 sbbl $0, %edx
20891 +
20892 +#ifdef CONFIG_PAX_REFCOUNT
20893 + into
20894 +1234:
20895 + _ASM_EXTABLE(1234b, 2f)
20896 +#endif
20897 +
20898 + movl %eax, (v)
20899 + movl %edx, 4(v)
20900 +
20901 +#ifdef CONFIG_PAX_REFCOUNT
20902 +2:
20903 +#endif
20904 +
20905 +RET_ENDP
20906 +BEGIN(dec_return_unchecked)
20907 + movl (v), %eax
20908 + movl 4(v), %edx
20909 + subl $1, %eax
20910 + sbbl $0, %edx
20911 movl %eax, (v)
20912 movl %edx, 4(v)
20913 RET_ENDP
20914 @@ -143,6 +286,13 @@ BEGIN(add_unless)
20915 adcl %edx, %edi
20916 addl (v), %eax
20917 adcl 4(v), %edx
20918 +
20919 +#ifdef CONFIG_PAX_REFCOUNT
20920 + into
20921 +1234:
20922 + _ASM_EXTABLE(1234b, 2f)
20923 +#endif
20924 +
20925 cmpl %eax, %ecx
20926 je 3f
20927 1:
20928 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20929 1:
20930 addl $1, %eax
20931 adcl $0, %edx
20932 +
20933 +#ifdef CONFIG_PAX_REFCOUNT
20934 + into
20935 +1234:
20936 + _ASM_EXTABLE(1234b, 2f)
20937 +#endif
20938 +
20939 movl %eax, (v)
20940 movl %edx, 4(v)
20941 movl $1, %eax
20942 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20943 movl 4(v), %edx
20944 subl $1, %eax
20945 sbbl $0, %edx
20946 +
20947 +#ifdef CONFIG_PAX_REFCOUNT
20948 + into
20949 +1234:
20950 + _ASM_EXTABLE(1234b, 1f)
20951 +#endif
20952 +
20953 js 1f
20954 movl %eax, (v)
20955 movl %edx, 4(v)
20956 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20957 index f5cc9eb..51fa319 100644
20958 --- a/arch/x86/lib/atomic64_cx8_32.S
20959 +++ b/arch/x86/lib/atomic64_cx8_32.S
20960 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20961 CFI_STARTPROC
20962
20963 read64 %ecx
20964 + pax_force_retaddr
20965 ret
20966 CFI_ENDPROC
20967 ENDPROC(atomic64_read_cx8)
20968
20969 +ENTRY(atomic64_read_unchecked_cx8)
20970 + CFI_STARTPROC
20971 +
20972 + read64 %ecx
20973 + pax_force_retaddr
20974 + ret
20975 + CFI_ENDPROC
20976 +ENDPROC(atomic64_read_unchecked_cx8)
20977 +
20978 ENTRY(atomic64_set_cx8)
20979 CFI_STARTPROC
20980
20981 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20982 cmpxchg8b (%esi)
20983 jne 1b
20984
20985 + pax_force_retaddr
20986 ret
20987 CFI_ENDPROC
20988 ENDPROC(atomic64_set_cx8)
20989
20990 +ENTRY(atomic64_set_unchecked_cx8)
20991 + CFI_STARTPROC
20992 +
20993 +1:
20994 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
20995 + * are atomic on 586 and newer */
20996 + cmpxchg8b (%esi)
20997 + jne 1b
20998 +
20999 + pax_force_retaddr
21000 + ret
21001 + CFI_ENDPROC
21002 +ENDPROC(atomic64_set_unchecked_cx8)
21003 +
21004 ENTRY(atomic64_xchg_cx8)
21005 CFI_STARTPROC
21006
21007 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
21008 cmpxchg8b (%esi)
21009 jne 1b
21010
21011 + pax_force_retaddr
21012 ret
21013 CFI_ENDPROC
21014 ENDPROC(atomic64_xchg_cx8)
21015
21016 -.macro addsub_return func ins insc
21017 -ENTRY(atomic64_\func\()_return_cx8)
21018 +.macro addsub_return func ins insc unchecked=""
21019 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21020 CFI_STARTPROC
21021 SAVE ebp
21022 SAVE ebx
21023 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
21024 movl %edx, %ecx
21025 \ins\()l %esi, %ebx
21026 \insc\()l %edi, %ecx
21027 +
21028 +.ifb \unchecked
21029 +#ifdef CONFIG_PAX_REFCOUNT
21030 + into
21031 +2:
21032 + _ASM_EXTABLE(2b, 3f)
21033 +#endif
21034 +.endif
21035 +
21036 LOCK_PREFIX
21037 cmpxchg8b (%ebp)
21038 jne 1b
21039 -
21040 -10:
21041 movl %ebx, %eax
21042 movl %ecx, %edx
21043 +
21044 +.ifb \unchecked
21045 +#ifdef CONFIG_PAX_REFCOUNT
21046 +3:
21047 +#endif
21048 +.endif
21049 +
21050 RESTORE edi
21051 RESTORE esi
21052 RESTORE ebx
21053 RESTORE ebp
21054 + pax_force_retaddr
21055 ret
21056 CFI_ENDPROC
21057 -ENDPROC(atomic64_\func\()_return_cx8)
21058 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21059 .endm
21060
21061 addsub_return add add adc
21062 addsub_return sub sub sbb
21063 +addsub_return add add adc _unchecked
21064 +addsub_return sub sub sbb _unchecked
21065
21066 -.macro incdec_return func ins insc
21067 -ENTRY(atomic64_\func\()_return_cx8)
21068 +.macro incdec_return func ins insc unchecked=""
21069 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21070 CFI_STARTPROC
21071 SAVE ebx
21072
21073 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
21074 movl %edx, %ecx
21075 \ins\()l $1, %ebx
21076 \insc\()l $0, %ecx
21077 +
21078 +.ifb \unchecked
21079 +#ifdef CONFIG_PAX_REFCOUNT
21080 + into
21081 +2:
21082 + _ASM_EXTABLE(2b, 3f)
21083 +#endif
21084 +.endif
21085 +
21086 LOCK_PREFIX
21087 cmpxchg8b (%esi)
21088 jne 1b
21089
21090 -10:
21091 movl %ebx, %eax
21092 movl %ecx, %edx
21093 +
21094 +.ifb \unchecked
21095 +#ifdef CONFIG_PAX_REFCOUNT
21096 +3:
21097 +#endif
21098 +.endif
21099 +
21100 RESTORE ebx
21101 + pax_force_retaddr
21102 ret
21103 CFI_ENDPROC
21104 -ENDPROC(atomic64_\func\()_return_cx8)
21105 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21106 .endm
21107
21108 incdec_return inc add adc
21109 incdec_return dec sub sbb
21110 +incdec_return inc add adc _unchecked
21111 +incdec_return dec sub sbb _unchecked
21112
21113 ENTRY(atomic64_dec_if_positive_cx8)
21114 CFI_STARTPROC
21115 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
21116 movl %edx, %ecx
21117 subl $1, %ebx
21118 sbb $0, %ecx
21119 +
21120 +#ifdef CONFIG_PAX_REFCOUNT
21121 + into
21122 +1234:
21123 + _ASM_EXTABLE(1234b, 2f)
21124 +#endif
21125 +
21126 js 2f
21127 LOCK_PREFIX
21128 cmpxchg8b (%esi)
21129 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
21130 movl %ebx, %eax
21131 movl %ecx, %edx
21132 RESTORE ebx
21133 + pax_force_retaddr
21134 ret
21135 CFI_ENDPROC
21136 ENDPROC(atomic64_dec_if_positive_cx8)
21137 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
21138 movl %edx, %ecx
21139 addl %ebp, %ebx
21140 adcl %edi, %ecx
21141 +
21142 +#ifdef CONFIG_PAX_REFCOUNT
21143 + into
21144 +1234:
21145 + _ASM_EXTABLE(1234b, 3f)
21146 +#endif
21147 +
21148 LOCK_PREFIX
21149 cmpxchg8b (%esi)
21150 jne 1b
21151 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
21152 CFI_ADJUST_CFA_OFFSET -8
21153 RESTORE ebx
21154 RESTORE ebp
21155 + pax_force_retaddr
21156 ret
21157 4:
21158 cmpl %edx, 4(%esp)
21159 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21160 xorl %ecx, %ecx
21161 addl $1, %ebx
21162 adcl %edx, %ecx
21163 +
21164 +#ifdef CONFIG_PAX_REFCOUNT
21165 + into
21166 +1234:
21167 + _ASM_EXTABLE(1234b, 3f)
21168 +#endif
21169 +
21170 LOCK_PREFIX
21171 cmpxchg8b (%esi)
21172 jne 1b
21173 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21174 movl $1, %eax
21175 3:
21176 RESTORE ebx
21177 + pax_force_retaddr
21178 ret
21179 CFI_ENDPROC
21180 ENDPROC(atomic64_inc_not_zero_cx8)
21181 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21182 index 78d16a5..fbcf666 100644
21183 --- a/arch/x86/lib/checksum_32.S
21184 +++ b/arch/x86/lib/checksum_32.S
21185 @@ -28,7 +28,8 @@
21186 #include <linux/linkage.h>
21187 #include <asm/dwarf2.h>
21188 #include <asm/errno.h>
21189 -
21190 +#include <asm/segment.h>
21191 +
21192 /*
21193 * computes a partial checksum, e.g. for TCP/UDP fragments
21194 */
21195 @@ -296,9 +297,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21196
21197 #define ARGBASE 16
21198 #define FP 12
21199 -
21200 -ENTRY(csum_partial_copy_generic)
21201 +
21202 +ENTRY(csum_partial_copy_generic_to_user)
21203 CFI_STARTPROC
21204 +
21205 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21206 + pushl_cfi %gs
21207 + popl_cfi %es
21208 + jmp csum_partial_copy_generic
21209 +#endif
21210 +
21211 +ENTRY(csum_partial_copy_generic_from_user)
21212 +
21213 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21214 + pushl_cfi %gs
21215 + popl_cfi %ds
21216 +#endif
21217 +
21218 +ENTRY(csum_partial_copy_generic)
21219 subl $4,%esp
21220 CFI_ADJUST_CFA_OFFSET 4
21221 pushl_cfi %edi
21222 @@ -320,7 +336,7 @@ ENTRY(csum_partial_copy_generic)
21223 jmp 4f
21224 SRC(1: movw (%esi), %bx )
21225 addl $2, %esi
21226 -DST( movw %bx, (%edi) )
21227 +DST( movw %bx, %es:(%edi) )
21228 addl $2, %edi
21229 addw %bx, %ax
21230 adcl $0, %eax
21231 @@ -332,30 +348,30 @@ DST( movw %bx, (%edi) )
21232 SRC(1: movl (%esi), %ebx )
21233 SRC( movl 4(%esi), %edx )
21234 adcl %ebx, %eax
21235 -DST( movl %ebx, (%edi) )
21236 +DST( movl %ebx, %es:(%edi) )
21237 adcl %edx, %eax
21238 -DST( movl %edx, 4(%edi) )
21239 +DST( movl %edx, %es:4(%edi) )
21240
21241 SRC( movl 8(%esi), %ebx )
21242 SRC( movl 12(%esi), %edx )
21243 adcl %ebx, %eax
21244 -DST( movl %ebx, 8(%edi) )
21245 +DST( movl %ebx, %es:8(%edi) )
21246 adcl %edx, %eax
21247 -DST( movl %edx, 12(%edi) )
21248 +DST( movl %edx, %es:12(%edi) )
21249
21250 SRC( movl 16(%esi), %ebx )
21251 SRC( movl 20(%esi), %edx )
21252 adcl %ebx, %eax
21253 -DST( movl %ebx, 16(%edi) )
21254 +DST( movl %ebx, %es:16(%edi) )
21255 adcl %edx, %eax
21256 -DST( movl %edx, 20(%edi) )
21257 +DST( movl %edx, %es:20(%edi) )
21258
21259 SRC( movl 24(%esi), %ebx )
21260 SRC( movl 28(%esi), %edx )
21261 adcl %ebx, %eax
21262 -DST( movl %ebx, 24(%edi) )
21263 +DST( movl %ebx, %es:24(%edi) )
21264 adcl %edx, %eax
21265 -DST( movl %edx, 28(%edi) )
21266 +DST( movl %edx, %es:28(%edi) )
21267
21268 lea 32(%esi), %esi
21269 lea 32(%edi), %edi
21270 @@ -369,7 +385,7 @@ DST( movl %edx, 28(%edi) )
21271 shrl $2, %edx # This clears CF
21272 SRC(3: movl (%esi), %ebx )
21273 adcl %ebx, %eax
21274 -DST( movl %ebx, (%edi) )
21275 +DST( movl %ebx, %es:(%edi) )
21276 lea 4(%esi), %esi
21277 lea 4(%edi), %edi
21278 dec %edx
21279 @@ -381,12 +397,12 @@ DST( movl %ebx, (%edi) )
21280 jb 5f
21281 SRC( movw (%esi), %cx )
21282 leal 2(%esi), %esi
21283 -DST( movw %cx, (%edi) )
21284 +DST( movw %cx, %es:(%edi) )
21285 leal 2(%edi), %edi
21286 je 6f
21287 shll $16,%ecx
21288 SRC(5: movb (%esi), %cl )
21289 -DST( movb %cl, (%edi) )
21290 +DST( movb %cl, %es:(%edi) )
21291 6: addl %ecx, %eax
21292 adcl $0, %eax
21293 7:
21294 @@ -397,7 +413,7 @@ DST( movb %cl, (%edi) )
21295
21296 6001:
21297 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21298 - movl $-EFAULT, (%ebx)
21299 + movl $-EFAULT, %ss:(%ebx)
21300
21301 # zero the complete destination - computing the rest
21302 # is too much work
21303 @@ -410,11 +426,15 @@ DST( movb %cl, (%edi) )
21304
21305 6002:
21306 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21307 - movl $-EFAULT,(%ebx)
21308 + movl $-EFAULT,%ss:(%ebx)
21309 jmp 5000b
21310
21311 .previous
21312
21313 + pushl_cfi %ss
21314 + popl_cfi %ds
21315 + pushl_cfi %ss
21316 + popl_cfi %es
21317 popl_cfi %ebx
21318 CFI_RESTORE ebx
21319 popl_cfi %esi
21320 @@ -424,26 +444,43 @@ DST( movb %cl, (%edi) )
21321 popl_cfi %ecx # equivalent to addl $4,%esp
21322 ret
21323 CFI_ENDPROC
21324 -ENDPROC(csum_partial_copy_generic)
21325 +ENDPROC(csum_partial_copy_generic_to_user)
21326
21327 #else
21328
21329 /* Version for PentiumII/PPro */
21330
21331 #define ROUND1(x) \
21332 + nop; nop; nop; \
21333 SRC(movl x(%esi), %ebx ) ; \
21334 addl %ebx, %eax ; \
21335 - DST(movl %ebx, x(%edi) ) ;
21336 + DST(movl %ebx, %es:x(%edi)) ;
21337
21338 #define ROUND(x) \
21339 + nop; nop; nop; \
21340 SRC(movl x(%esi), %ebx ) ; \
21341 adcl %ebx, %eax ; \
21342 - DST(movl %ebx, x(%edi) ) ;
21343 + DST(movl %ebx, %es:x(%edi)) ;
21344
21345 #define ARGBASE 12
21346 -
21347 -ENTRY(csum_partial_copy_generic)
21348 +
21349 +ENTRY(csum_partial_copy_generic_to_user)
21350 CFI_STARTPROC
21351 +
21352 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21353 + pushl_cfi %gs
21354 + popl_cfi %es
21355 + jmp csum_partial_copy_generic
21356 +#endif
21357 +
21358 +ENTRY(csum_partial_copy_generic_from_user)
21359 +
21360 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21361 + pushl_cfi %gs
21362 + popl_cfi %ds
21363 +#endif
21364 +
21365 +ENTRY(csum_partial_copy_generic)
21366 pushl_cfi %ebx
21367 CFI_REL_OFFSET ebx, 0
21368 pushl_cfi %edi
21369 @@ -464,7 +501,7 @@ ENTRY(csum_partial_copy_generic)
21370 subl %ebx, %edi
21371 lea -1(%esi),%edx
21372 andl $-32,%edx
21373 - lea 3f(%ebx,%ebx), %ebx
21374 + lea 3f(%ebx,%ebx,2), %ebx
21375 testl %esi, %esi
21376 jmp *%ebx
21377 1: addl $64,%esi
21378 @@ -485,19 +522,19 @@ ENTRY(csum_partial_copy_generic)
21379 jb 5f
21380 SRC( movw (%esi), %dx )
21381 leal 2(%esi), %esi
21382 -DST( movw %dx, (%edi) )
21383 +DST( movw %dx, %es:(%edi) )
21384 leal 2(%edi), %edi
21385 je 6f
21386 shll $16,%edx
21387 5:
21388 SRC( movb (%esi), %dl )
21389 -DST( movb %dl, (%edi) )
21390 +DST( movb %dl, %es:(%edi) )
21391 6: addl %edx, %eax
21392 adcl $0, %eax
21393 7:
21394 .section .fixup, "ax"
21395 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21396 - movl $-EFAULT, (%ebx)
21397 + movl $-EFAULT, %ss:(%ebx)
21398 # zero the complete destination (computing the rest is too much work)
21399 movl ARGBASE+8(%esp),%edi # dst
21400 movl ARGBASE+12(%esp),%ecx # len
21401 @@ -505,10 +542,17 @@ DST( movb %dl, (%edi) )
21402 rep; stosb
21403 jmp 7b
21404 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21405 - movl $-EFAULT, (%ebx)
21406 + movl $-EFAULT, %ss:(%ebx)
21407 jmp 7b
21408 .previous
21409
21410 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21411 + pushl_cfi %ss
21412 + popl_cfi %ds
21413 + pushl_cfi %ss
21414 + popl_cfi %es
21415 +#endif
21416 +
21417 popl_cfi %esi
21418 CFI_RESTORE esi
21419 popl_cfi %edi
21420 @@ -517,7 +561,7 @@ DST( movb %dl, (%edi) )
21421 CFI_RESTORE ebx
21422 ret
21423 CFI_ENDPROC
21424 -ENDPROC(csum_partial_copy_generic)
21425 +ENDPROC(csum_partial_copy_generic_to_user)
21426
21427 #undef ROUND
21428 #undef ROUND1
21429 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21430 index f2145cf..cea889d 100644
21431 --- a/arch/x86/lib/clear_page_64.S
21432 +++ b/arch/x86/lib/clear_page_64.S
21433 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21434 movl $4096/8,%ecx
21435 xorl %eax,%eax
21436 rep stosq
21437 + pax_force_retaddr
21438 ret
21439 CFI_ENDPROC
21440 ENDPROC(clear_page_c)
21441 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21442 movl $4096,%ecx
21443 xorl %eax,%eax
21444 rep stosb
21445 + pax_force_retaddr
21446 ret
21447 CFI_ENDPROC
21448 ENDPROC(clear_page_c_e)
21449 @@ -43,6 +45,7 @@ ENTRY(clear_page)
21450 leaq 64(%rdi),%rdi
21451 jnz .Lloop
21452 nop
21453 + pax_force_retaddr
21454 ret
21455 CFI_ENDPROC
21456 .Lclear_page_end:
21457 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
21458
21459 #include <asm/cpufeature.h>
21460
21461 - .section .altinstr_replacement,"ax"
21462 + .section .altinstr_replacement,"a"
21463 1: .byte 0xeb /* jmp <disp8> */
21464 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21465 2: .byte 0xeb /* jmp <disp8> */
21466 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21467 index 1e572c5..2a162cd 100644
21468 --- a/arch/x86/lib/cmpxchg16b_emu.S
21469 +++ b/arch/x86/lib/cmpxchg16b_emu.S
21470 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21471
21472 popf
21473 mov $1, %al
21474 + pax_force_retaddr
21475 ret
21476
21477 not_same:
21478 popf
21479 xor %al,%al
21480 + pax_force_retaddr
21481 ret
21482
21483 CFI_ENDPROC
21484 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21485 index 6b34d04..dccb07f 100644
21486 --- a/arch/x86/lib/copy_page_64.S
21487 +++ b/arch/x86/lib/copy_page_64.S
21488 @@ -9,6 +9,7 @@ copy_page_c:
21489 CFI_STARTPROC
21490 movl $4096/8,%ecx
21491 rep movsq
21492 + pax_force_retaddr
21493 ret
21494 CFI_ENDPROC
21495 ENDPROC(copy_page_c)
21496 @@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21497
21498 ENTRY(copy_page)
21499 CFI_STARTPROC
21500 - subq $2*8,%rsp
21501 - CFI_ADJUST_CFA_OFFSET 2*8
21502 + subq $3*8,%rsp
21503 + CFI_ADJUST_CFA_OFFSET 3*8
21504 movq %rbx,(%rsp)
21505 CFI_REL_OFFSET rbx, 0
21506 movq %r12,1*8(%rsp)
21507 CFI_REL_OFFSET r12, 1*8
21508 + movq %r13,2*8(%rsp)
21509 + CFI_REL_OFFSET r13, 2*8
21510
21511 movl $(4096/64)-5,%ecx
21512 .p2align 4
21513 @@ -37,7 +40,7 @@ ENTRY(copy_page)
21514 movq 16 (%rsi), %rdx
21515 movq 24 (%rsi), %r8
21516 movq 32 (%rsi), %r9
21517 - movq 40 (%rsi), %r10
21518 + movq 40 (%rsi), %r13
21519 movq 48 (%rsi), %r11
21520 movq 56 (%rsi), %r12
21521
21522 @@ -48,7 +51,7 @@ ENTRY(copy_page)
21523 movq %rdx, 16 (%rdi)
21524 movq %r8, 24 (%rdi)
21525 movq %r9, 32 (%rdi)
21526 - movq %r10, 40 (%rdi)
21527 + movq %r13, 40 (%rdi)
21528 movq %r11, 48 (%rdi)
21529 movq %r12, 56 (%rdi)
21530
21531 @@ -67,7 +70,7 @@ ENTRY(copy_page)
21532 movq 16 (%rsi), %rdx
21533 movq 24 (%rsi), %r8
21534 movq 32 (%rsi), %r9
21535 - movq 40 (%rsi), %r10
21536 + movq 40 (%rsi), %r13
21537 movq 48 (%rsi), %r11
21538 movq 56 (%rsi), %r12
21539
21540 @@ -76,7 +79,7 @@ ENTRY(copy_page)
21541 movq %rdx, 16 (%rdi)
21542 movq %r8, 24 (%rdi)
21543 movq %r9, 32 (%rdi)
21544 - movq %r10, 40 (%rdi)
21545 + movq %r13, 40 (%rdi)
21546 movq %r11, 48 (%rdi)
21547 movq %r12, 56 (%rdi)
21548
21549 @@ -89,8 +92,11 @@ ENTRY(copy_page)
21550 CFI_RESTORE rbx
21551 movq 1*8(%rsp),%r12
21552 CFI_RESTORE r12
21553 - addq $2*8,%rsp
21554 - CFI_ADJUST_CFA_OFFSET -2*8
21555 + movq 2*8(%rsp),%r13
21556 + CFI_RESTORE r13
21557 + addq $3*8,%rsp
21558 + CFI_ADJUST_CFA_OFFSET -3*8
21559 + pax_force_retaddr
21560 ret
21561 .Lcopy_page_end:
21562 CFI_ENDPROC
21563 @@ -101,7 +107,7 @@ ENDPROC(copy_page)
21564
21565 #include <asm/cpufeature.h>
21566
21567 - .section .altinstr_replacement,"ax"
21568 + .section .altinstr_replacement,"a"
21569 1: .byte 0xeb /* jmp <disp8> */
21570 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21571 2:
21572 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21573 index 0248402..821c786 100644
21574 --- a/arch/x86/lib/copy_user_64.S
21575 +++ b/arch/x86/lib/copy_user_64.S
21576 @@ -16,6 +16,7 @@
21577 #include <asm/thread_info.h>
21578 #include <asm/cpufeature.h>
21579 #include <asm/alternative-asm.h>
21580 +#include <asm/pgtable.h>
21581
21582 /*
21583 * By placing feature2 after feature1 in altinstructions section, we logically
21584 @@ -29,7 +30,7 @@
21585 .byte 0xe9 /* 32bit jump */
21586 .long \orig-1f /* by default jump to orig */
21587 1:
21588 - .section .altinstr_replacement,"ax"
21589 + .section .altinstr_replacement,"a"
21590 2: .byte 0xe9 /* near jump with 32bit immediate */
21591 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21592 3: .byte 0xe9 /* near jump with 32bit immediate */
21593 @@ -71,47 +72,20 @@
21594 #endif
21595 .endm
21596
21597 -/* Standard copy_to_user with segment limit checking */
21598 -ENTRY(_copy_to_user)
21599 - CFI_STARTPROC
21600 - GET_THREAD_INFO(%rax)
21601 - movq %rdi,%rcx
21602 - addq %rdx,%rcx
21603 - jc bad_to_user
21604 - cmpq TI_addr_limit(%rax),%rcx
21605 - ja bad_to_user
21606 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21607 - copy_user_generic_unrolled,copy_user_generic_string, \
21608 - copy_user_enhanced_fast_string
21609 - CFI_ENDPROC
21610 -ENDPROC(_copy_to_user)
21611 -
21612 -/* Standard copy_from_user with segment limit checking */
21613 -ENTRY(_copy_from_user)
21614 - CFI_STARTPROC
21615 - GET_THREAD_INFO(%rax)
21616 - movq %rsi,%rcx
21617 - addq %rdx,%rcx
21618 - jc bad_from_user
21619 - cmpq TI_addr_limit(%rax),%rcx
21620 - ja bad_from_user
21621 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21622 - copy_user_generic_unrolled,copy_user_generic_string, \
21623 - copy_user_enhanced_fast_string
21624 - CFI_ENDPROC
21625 -ENDPROC(_copy_from_user)
21626 -
21627 .section .fixup,"ax"
21628 /* must zero dest */
21629 ENTRY(bad_from_user)
21630 bad_from_user:
21631 CFI_STARTPROC
21632 + testl %edx,%edx
21633 + js bad_to_user
21634 movl %edx,%ecx
21635 xorl %eax,%eax
21636 rep
21637 stosb
21638 bad_to_user:
21639 movl %edx,%eax
21640 + pax_force_retaddr
21641 ret
21642 CFI_ENDPROC
21643 ENDPROC(bad_from_user)
21644 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
21645 jz 17f
21646 1: movq (%rsi),%r8
21647 2: movq 1*8(%rsi),%r9
21648 -3: movq 2*8(%rsi),%r10
21649 +3: movq 2*8(%rsi),%rax
21650 4: movq 3*8(%rsi),%r11
21651 5: movq %r8,(%rdi)
21652 6: movq %r9,1*8(%rdi)
21653 -7: movq %r10,2*8(%rdi)
21654 +7: movq %rax,2*8(%rdi)
21655 8: movq %r11,3*8(%rdi)
21656 9: movq 4*8(%rsi),%r8
21657 10: movq 5*8(%rsi),%r9
21658 -11: movq 6*8(%rsi),%r10
21659 +11: movq 6*8(%rsi),%rax
21660 12: movq 7*8(%rsi),%r11
21661 13: movq %r8,4*8(%rdi)
21662 14: movq %r9,5*8(%rdi)
21663 -15: movq %r10,6*8(%rdi)
21664 +15: movq %rax,6*8(%rdi)
21665 16: movq %r11,7*8(%rdi)
21666 leaq 64(%rsi),%rsi
21667 leaq 64(%rdi),%rdi
21668 @@ -179,6 +153,7 @@ ENTRY(copy_user_generic_unrolled)
21669 decl %ecx
21670 jnz 21b
21671 23: xor %eax,%eax
21672 + pax_force_retaddr
21673 ret
21674
21675 .section .fixup,"ax"
21676 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
21677 3: rep
21678 movsb
21679 4: xorl %eax,%eax
21680 + pax_force_retaddr
21681 ret
21682
21683 .section .fixup,"ax"
21684 @@ -287,6 +263,7 @@ ENTRY(copy_user_enhanced_fast_string)
21685 1: rep
21686 movsb
21687 2: xorl %eax,%eax
21688 + pax_force_retaddr
21689 ret
21690
21691 .section .fixup,"ax"
21692 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21693 index cb0c112..e3a6895 100644
21694 --- a/arch/x86/lib/copy_user_nocache_64.S
21695 +++ b/arch/x86/lib/copy_user_nocache_64.S
21696 @@ -8,12 +8,14 @@
21697
21698 #include <linux/linkage.h>
21699 #include <asm/dwarf2.h>
21700 +#include <asm/alternative-asm.h>
21701
21702 #define FIX_ALIGNMENT 1
21703
21704 #include <asm/current.h>
21705 #include <asm/asm-offsets.h>
21706 #include <asm/thread_info.h>
21707 +#include <asm/pgtable.h>
21708
21709 .macro ALIGN_DESTINATION
21710 #ifdef FIX_ALIGNMENT
21711 @@ -50,6 +52,15 @@
21712 */
21713 ENTRY(__copy_user_nocache)
21714 CFI_STARTPROC
21715 +
21716 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21717 + mov $PAX_USER_SHADOW_BASE,%rcx
21718 + cmp %rcx,%rsi
21719 + jae 1f
21720 + add %rcx,%rsi
21721 +1:
21722 +#endif
21723 +
21724 cmpl $8,%edx
21725 jb 20f /* less then 8 bytes, go to byte copy loop */
21726 ALIGN_DESTINATION
21727 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
21728 jz 17f
21729 1: movq (%rsi),%r8
21730 2: movq 1*8(%rsi),%r9
21731 -3: movq 2*8(%rsi),%r10
21732 +3: movq 2*8(%rsi),%rax
21733 4: movq 3*8(%rsi),%r11
21734 5: movnti %r8,(%rdi)
21735 6: movnti %r9,1*8(%rdi)
21736 -7: movnti %r10,2*8(%rdi)
21737 +7: movnti %rax,2*8(%rdi)
21738 8: movnti %r11,3*8(%rdi)
21739 9: movq 4*8(%rsi),%r8
21740 10: movq 5*8(%rsi),%r9
21741 -11: movq 6*8(%rsi),%r10
21742 +11: movq 6*8(%rsi),%rax
21743 12: movq 7*8(%rsi),%r11
21744 13: movnti %r8,4*8(%rdi)
21745 14: movnti %r9,5*8(%rdi)
21746 -15: movnti %r10,6*8(%rdi)
21747 +15: movnti %rax,6*8(%rdi)
21748 16: movnti %r11,7*8(%rdi)
21749 leaq 64(%rsi),%rsi
21750 leaq 64(%rdi),%rdi
21751 @@ -98,6 +109,7 @@ ENTRY(__copy_user_nocache)
21752 jnz 21b
21753 23: xorl %eax,%eax
21754 sfence
21755 + pax_force_retaddr
21756 ret
21757
21758 .section .fixup,"ax"
21759 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21760 index fb903b7..c92b7f7 100644
21761 --- a/arch/x86/lib/csum-copy_64.S
21762 +++ b/arch/x86/lib/csum-copy_64.S
21763 @@ -8,6 +8,7 @@
21764 #include <linux/linkage.h>
21765 #include <asm/dwarf2.h>
21766 #include <asm/errno.h>
21767 +#include <asm/alternative-asm.h>
21768
21769 /*
21770 * Checksum copy with exception handling.
21771 @@ -228,6 +229,7 @@ ENTRY(csum_partial_copy_generic)
21772 CFI_RESTORE rbp
21773 addq $7*8, %rsp
21774 CFI_ADJUST_CFA_OFFSET -7*8
21775 + pax_force_retaddr 0, 1
21776 ret
21777 CFI_RESTORE_STATE
21778
21779 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21780 index 459b58a..9570bc7 100644
21781 --- a/arch/x86/lib/csum-wrappers_64.c
21782 +++ b/arch/x86/lib/csum-wrappers_64.c
21783 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21784 len -= 2;
21785 }
21786 }
21787 - isum = csum_partial_copy_generic((__force const void *)src,
21788 +
21789 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21790 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21791 + src += PAX_USER_SHADOW_BASE;
21792 +#endif
21793 +
21794 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
21795 dst, len, isum, errp, NULL);
21796 if (unlikely(*errp))
21797 goto out_err;
21798 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21799 }
21800
21801 *errp = 0;
21802 - return csum_partial_copy_generic(src, (void __force *)dst,
21803 +
21804 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21805 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21806 + dst += PAX_USER_SHADOW_BASE;
21807 +#endif
21808 +
21809 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21810 len, isum, NULL, errp);
21811 }
21812 EXPORT_SYMBOL(csum_partial_copy_to_user);
21813 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21814 index 51f1504..ddac4c1 100644
21815 --- a/arch/x86/lib/getuser.S
21816 +++ b/arch/x86/lib/getuser.S
21817 @@ -33,15 +33,38 @@
21818 #include <asm/asm-offsets.h>
21819 #include <asm/thread_info.h>
21820 #include <asm/asm.h>
21821 +#include <asm/segment.h>
21822 +#include <asm/pgtable.h>
21823 +#include <asm/alternative-asm.h>
21824 +
21825 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21826 +#define __copyuser_seg gs;
21827 +#else
21828 +#define __copyuser_seg
21829 +#endif
21830
21831 .text
21832 ENTRY(__get_user_1)
21833 CFI_STARTPROC
21834 +
21835 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21836 GET_THREAD_INFO(%_ASM_DX)
21837 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21838 jae bad_get_user
21839 -1: movzb (%_ASM_AX),%edx
21840 +
21841 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21842 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21843 + cmp %_ASM_DX,%_ASM_AX
21844 + jae 1234f
21845 + add %_ASM_DX,%_ASM_AX
21846 +1234:
21847 +#endif
21848 +
21849 +#endif
21850 +
21851 +1: __copyuser_seg movzb (%_ASM_AX),%edx
21852 xor %eax,%eax
21853 + pax_force_retaddr
21854 ret
21855 CFI_ENDPROC
21856 ENDPROC(__get_user_1)
21857 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21858 ENTRY(__get_user_2)
21859 CFI_STARTPROC
21860 add $1,%_ASM_AX
21861 +
21862 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21863 jc bad_get_user
21864 GET_THREAD_INFO(%_ASM_DX)
21865 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21866 jae bad_get_user
21867 -2: movzwl -1(%_ASM_AX),%edx
21868 +
21869 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21870 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21871 + cmp %_ASM_DX,%_ASM_AX
21872 + jae 1234f
21873 + add %_ASM_DX,%_ASM_AX
21874 +1234:
21875 +#endif
21876 +
21877 +#endif
21878 +
21879 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21880 xor %eax,%eax
21881 + pax_force_retaddr
21882 ret
21883 CFI_ENDPROC
21884 ENDPROC(__get_user_2)
21885 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21886 ENTRY(__get_user_4)
21887 CFI_STARTPROC
21888 add $3,%_ASM_AX
21889 +
21890 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21891 jc bad_get_user
21892 GET_THREAD_INFO(%_ASM_DX)
21893 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21894 jae bad_get_user
21895 -3: mov -3(%_ASM_AX),%edx
21896 +
21897 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21898 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21899 + cmp %_ASM_DX,%_ASM_AX
21900 + jae 1234f
21901 + add %_ASM_DX,%_ASM_AX
21902 +1234:
21903 +#endif
21904 +
21905 +#endif
21906 +
21907 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
21908 xor %eax,%eax
21909 + pax_force_retaddr
21910 ret
21911 CFI_ENDPROC
21912 ENDPROC(__get_user_4)
21913 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21914 GET_THREAD_INFO(%_ASM_DX)
21915 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21916 jae bad_get_user
21917 +
21918 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21919 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21920 + cmp %_ASM_DX,%_ASM_AX
21921 + jae 1234f
21922 + add %_ASM_DX,%_ASM_AX
21923 +1234:
21924 +#endif
21925 +
21926 4: movq -7(%_ASM_AX),%_ASM_DX
21927 xor %eax,%eax
21928 + pax_force_retaddr
21929 ret
21930 CFI_ENDPROC
21931 ENDPROC(__get_user_8)
21932 @@ -91,6 +152,7 @@ bad_get_user:
21933 CFI_STARTPROC
21934 xor %edx,%edx
21935 mov $(-EFAULT),%_ASM_AX
21936 + pax_force_retaddr
21937 ret
21938 CFI_ENDPROC
21939 END(bad_get_user)
21940 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21941 index b1e6c4b..21ae8fc 100644
21942 --- a/arch/x86/lib/insn.c
21943 +++ b/arch/x86/lib/insn.c
21944 @@ -21,6 +21,11 @@
21945 #include <linux/string.h>
21946 #include <asm/inat.h>
21947 #include <asm/insn.h>
21948 +#ifdef __KERNEL__
21949 +#include <asm/pgtable_types.h>
21950 +#else
21951 +#define ktla_ktva(addr) addr
21952 +#endif
21953
21954 /* Verify next sizeof(t) bytes can be on the same instruction */
21955 #define validate_next(t, insn, n) \
21956 @@ -49,8 +54,8 @@
21957 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21958 {
21959 memset(insn, 0, sizeof(*insn));
21960 - insn->kaddr = kaddr;
21961 - insn->next_byte = kaddr;
21962 + insn->kaddr = ktla_ktva(kaddr);
21963 + insn->next_byte = ktla_ktva(kaddr);
21964 insn->x86_64 = x86_64 ? 1 : 0;
21965 insn->opnd_bytes = 4;
21966 if (x86_64)
21967 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21968 index 05a95e7..326f2fa 100644
21969 --- a/arch/x86/lib/iomap_copy_64.S
21970 +++ b/arch/x86/lib/iomap_copy_64.S
21971 @@ -17,6 +17,7 @@
21972
21973 #include <linux/linkage.h>
21974 #include <asm/dwarf2.h>
21975 +#include <asm/alternative-asm.h>
21976
21977 /*
21978 * override generic version in lib/iomap_copy.c
21979 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21980 CFI_STARTPROC
21981 movl %edx,%ecx
21982 rep movsd
21983 + pax_force_retaddr
21984 ret
21985 CFI_ENDPROC
21986 ENDPROC(__iowrite32_copy)
21987 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21988 index 1c273be..da9cc0e 100644
21989 --- a/arch/x86/lib/memcpy_64.S
21990 +++ b/arch/x86/lib/memcpy_64.S
21991 @@ -33,6 +33,7 @@
21992 rep movsq
21993 movl %edx, %ecx
21994 rep movsb
21995 + pax_force_retaddr
21996 ret
21997 .Lmemcpy_e:
21998 .previous
21999 @@ -49,6 +50,7 @@
22000 movq %rdi, %rax
22001 movq %rdx, %rcx
22002 rep movsb
22003 + pax_force_retaddr
22004 ret
22005 .Lmemcpy_e_e:
22006 .previous
22007 @@ -76,13 +78,13 @@ ENTRY(memcpy)
22008 */
22009 movq 0*8(%rsi), %r8
22010 movq 1*8(%rsi), %r9
22011 - movq 2*8(%rsi), %r10
22012 + movq 2*8(%rsi), %rcx
22013 movq 3*8(%rsi), %r11
22014 leaq 4*8(%rsi), %rsi
22015
22016 movq %r8, 0*8(%rdi)
22017 movq %r9, 1*8(%rdi)
22018 - movq %r10, 2*8(%rdi)
22019 + movq %rcx, 2*8(%rdi)
22020 movq %r11, 3*8(%rdi)
22021 leaq 4*8(%rdi), %rdi
22022 jae .Lcopy_forward_loop
22023 @@ -105,12 +107,12 @@ ENTRY(memcpy)
22024 subq $0x20, %rdx
22025 movq -1*8(%rsi), %r8
22026 movq -2*8(%rsi), %r9
22027 - movq -3*8(%rsi), %r10
22028 + movq -3*8(%rsi), %rcx
22029 movq -4*8(%rsi), %r11
22030 leaq -4*8(%rsi), %rsi
22031 movq %r8, -1*8(%rdi)
22032 movq %r9, -2*8(%rdi)
22033 - movq %r10, -3*8(%rdi)
22034 + movq %rcx, -3*8(%rdi)
22035 movq %r11, -4*8(%rdi)
22036 leaq -4*8(%rdi), %rdi
22037 jae .Lcopy_backward_loop
22038 @@ -130,12 +132,13 @@ ENTRY(memcpy)
22039 */
22040 movq 0*8(%rsi), %r8
22041 movq 1*8(%rsi), %r9
22042 - movq -2*8(%rsi, %rdx), %r10
22043 + movq -2*8(%rsi, %rdx), %rcx
22044 movq -1*8(%rsi, %rdx), %r11
22045 movq %r8, 0*8(%rdi)
22046 movq %r9, 1*8(%rdi)
22047 - movq %r10, -2*8(%rdi, %rdx)
22048 + movq %rcx, -2*8(%rdi, %rdx)
22049 movq %r11, -1*8(%rdi, %rdx)
22050 + pax_force_retaddr
22051 retq
22052 .p2align 4
22053 .Lless_16bytes:
22054 @@ -148,6 +151,7 @@ ENTRY(memcpy)
22055 movq -1*8(%rsi, %rdx), %r9
22056 movq %r8, 0*8(%rdi)
22057 movq %r9, -1*8(%rdi, %rdx)
22058 + pax_force_retaddr
22059 retq
22060 .p2align 4
22061 .Lless_8bytes:
22062 @@ -161,6 +165,7 @@ ENTRY(memcpy)
22063 movl -4(%rsi, %rdx), %r8d
22064 movl %ecx, (%rdi)
22065 movl %r8d, -4(%rdi, %rdx)
22066 + pax_force_retaddr
22067 retq
22068 .p2align 4
22069 .Lless_3bytes:
22070 @@ -179,6 +184,7 @@ ENTRY(memcpy)
22071 movb %cl, (%rdi)
22072
22073 .Lend:
22074 + pax_force_retaddr
22075 retq
22076 CFI_ENDPROC
22077 ENDPROC(memcpy)
22078 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
22079 index ee16461..c39c199 100644
22080 --- a/arch/x86/lib/memmove_64.S
22081 +++ b/arch/x86/lib/memmove_64.S
22082 @@ -61,13 +61,13 @@ ENTRY(memmove)
22083 5:
22084 sub $0x20, %rdx
22085 movq 0*8(%rsi), %r11
22086 - movq 1*8(%rsi), %r10
22087 + movq 1*8(%rsi), %rcx
22088 movq 2*8(%rsi), %r9
22089 movq 3*8(%rsi), %r8
22090 leaq 4*8(%rsi), %rsi
22091
22092 movq %r11, 0*8(%rdi)
22093 - movq %r10, 1*8(%rdi)
22094 + movq %rcx, 1*8(%rdi)
22095 movq %r9, 2*8(%rdi)
22096 movq %r8, 3*8(%rdi)
22097 leaq 4*8(%rdi), %rdi
22098 @@ -81,10 +81,10 @@ ENTRY(memmove)
22099 4:
22100 movq %rdx, %rcx
22101 movq -8(%rsi, %rdx), %r11
22102 - lea -8(%rdi, %rdx), %r10
22103 + lea -8(%rdi, %rdx), %r9
22104 shrq $3, %rcx
22105 rep movsq
22106 - movq %r11, (%r10)
22107 + movq %r11, (%r9)
22108 jmp 13f
22109 .Lmemmove_end_forward:
22110
22111 @@ -95,14 +95,14 @@ ENTRY(memmove)
22112 7:
22113 movq %rdx, %rcx
22114 movq (%rsi), %r11
22115 - movq %rdi, %r10
22116 + movq %rdi, %r9
22117 leaq -8(%rsi, %rdx), %rsi
22118 leaq -8(%rdi, %rdx), %rdi
22119 shrq $3, %rcx
22120 std
22121 rep movsq
22122 cld
22123 - movq %r11, (%r10)
22124 + movq %r11, (%r9)
22125 jmp 13f
22126
22127 /*
22128 @@ -127,13 +127,13 @@ ENTRY(memmove)
22129 8:
22130 subq $0x20, %rdx
22131 movq -1*8(%rsi), %r11
22132 - movq -2*8(%rsi), %r10
22133 + movq -2*8(%rsi), %rcx
22134 movq -3*8(%rsi), %r9
22135 movq -4*8(%rsi), %r8
22136 leaq -4*8(%rsi), %rsi
22137
22138 movq %r11, -1*8(%rdi)
22139 - movq %r10, -2*8(%rdi)
22140 + movq %rcx, -2*8(%rdi)
22141 movq %r9, -3*8(%rdi)
22142 movq %r8, -4*8(%rdi)
22143 leaq -4*8(%rdi), %rdi
22144 @@ -151,11 +151,11 @@ ENTRY(memmove)
22145 * Move data from 16 bytes to 31 bytes.
22146 */
22147 movq 0*8(%rsi), %r11
22148 - movq 1*8(%rsi), %r10
22149 + movq 1*8(%rsi), %rcx
22150 movq -2*8(%rsi, %rdx), %r9
22151 movq -1*8(%rsi, %rdx), %r8
22152 movq %r11, 0*8(%rdi)
22153 - movq %r10, 1*8(%rdi)
22154 + movq %rcx, 1*8(%rdi)
22155 movq %r9, -2*8(%rdi, %rdx)
22156 movq %r8, -1*8(%rdi, %rdx)
22157 jmp 13f
22158 @@ -167,9 +167,9 @@ ENTRY(memmove)
22159 * Move data from 8 bytes to 15 bytes.
22160 */
22161 movq 0*8(%rsi), %r11
22162 - movq -1*8(%rsi, %rdx), %r10
22163 + movq -1*8(%rsi, %rdx), %r9
22164 movq %r11, 0*8(%rdi)
22165 - movq %r10, -1*8(%rdi, %rdx)
22166 + movq %r9, -1*8(%rdi, %rdx)
22167 jmp 13f
22168 10:
22169 cmpq $4, %rdx
22170 @@ -178,9 +178,9 @@ ENTRY(memmove)
22171 * Move data from 4 bytes to 7 bytes.
22172 */
22173 movl (%rsi), %r11d
22174 - movl -4(%rsi, %rdx), %r10d
22175 + movl -4(%rsi, %rdx), %r9d
22176 movl %r11d, (%rdi)
22177 - movl %r10d, -4(%rdi, %rdx)
22178 + movl %r9d, -4(%rdi, %rdx)
22179 jmp 13f
22180 11:
22181 cmp $2, %rdx
22182 @@ -189,9 +189,9 @@ ENTRY(memmove)
22183 * Move data from 2 bytes to 3 bytes.
22184 */
22185 movw (%rsi), %r11w
22186 - movw -2(%rsi, %rdx), %r10w
22187 + movw -2(%rsi, %rdx), %r9w
22188 movw %r11w, (%rdi)
22189 - movw %r10w, -2(%rdi, %rdx)
22190 + movw %r9w, -2(%rdi, %rdx)
22191 jmp 13f
22192 12:
22193 cmp $1, %rdx
22194 @@ -202,6 +202,7 @@ ENTRY(memmove)
22195 movb (%rsi), %r11b
22196 movb %r11b, (%rdi)
22197 13:
22198 + pax_force_retaddr
22199 retq
22200 CFI_ENDPROC
22201
22202 @@ -210,6 +211,7 @@ ENTRY(memmove)
22203 /* Forward moving data. */
22204 movq %rdx, %rcx
22205 rep movsb
22206 + pax_force_retaddr
22207 retq
22208 .Lmemmove_end_forward_efs:
22209 .previous
22210 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22211 index 2dcb380..963660a 100644
22212 --- a/arch/x86/lib/memset_64.S
22213 +++ b/arch/x86/lib/memset_64.S
22214 @@ -30,6 +30,7 @@
22215 movl %edx,%ecx
22216 rep stosb
22217 movq %r9,%rax
22218 + pax_force_retaddr
22219 ret
22220 .Lmemset_e:
22221 .previous
22222 @@ -52,6 +53,7 @@
22223 movq %rdx,%rcx
22224 rep stosb
22225 movq %r9,%rax
22226 + pax_force_retaddr
22227 ret
22228 .Lmemset_e_e:
22229 .previous
22230 @@ -59,7 +61,7 @@
22231 ENTRY(memset)
22232 ENTRY(__memset)
22233 CFI_STARTPROC
22234 - movq %rdi,%r10
22235 + movq %rdi,%r11
22236
22237 /* expand byte value */
22238 movzbl %sil,%ecx
22239 @@ -117,7 +119,8 @@ ENTRY(__memset)
22240 jnz .Lloop_1
22241
22242 .Lende:
22243 - movq %r10,%rax
22244 + movq %r11,%rax
22245 + pax_force_retaddr
22246 ret
22247
22248 CFI_RESTORE_STATE
22249 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22250 index c9f2d9b..e7fd2c0 100644
22251 --- a/arch/x86/lib/mmx_32.c
22252 +++ b/arch/x86/lib/mmx_32.c
22253 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22254 {
22255 void *p;
22256 int i;
22257 + unsigned long cr0;
22258
22259 if (unlikely(in_interrupt()))
22260 return __memcpy(to, from, len);
22261 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22262 kernel_fpu_begin();
22263
22264 __asm__ __volatile__ (
22265 - "1: prefetch (%0)\n" /* This set is 28 bytes */
22266 - " prefetch 64(%0)\n"
22267 - " prefetch 128(%0)\n"
22268 - " prefetch 192(%0)\n"
22269 - " prefetch 256(%0)\n"
22270 + "1: prefetch (%1)\n" /* This set is 28 bytes */
22271 + " prefetch 64(%1)\n"
22272 + " prefetch 128(%1)\n"
22273 + " prefetch 192(%1)\n"
22274 + " prefetch 256(%1)\n"
22275 "2: \n"
22276 ".section .fixup, \"ax\"\n"
22277 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22278 + "3: \n"
22279 +
22280 +#ifdef CONFIG_PAX_KERNEXEC
22281 + " movl %%cr0, %0\n"
22282 + " movl %0, %%eax\n"
22283 + " andl $0xFFFEFFFF, %%eax\n"
22284 + " movl %%eax, %%cr0\n"
22285 +#endif
22286 +
22287 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22288 +
22289 +#ifdef CONFIG_PAX_KERNEXEC
22290 + " movl %0, %%cr0\n"
22291 +#endif
22292 +
22293 " jmp 2b\n"
22294 ".previous\n"
22295 _ASM_EXTABLE(1b, 3b)
22296 - : : "r" (from));
22297 + : "=&r" (cr0) : "r" (from) : "ax");
22298
22299 for ( ; i > 5; i--) {
22300 __asm__ __volatile__ (
22301 - "1: prefetch 320(%0)\n"
22302 - "2: movq (%0), %%mm0\n"
22303 - " movq 8(%0), %%mm1\n"
22304 - " movq 16(%0), %%mm2\n"
22305 - " movq 24(%0), %%mm3\n"
22306 - " movq %%mm0, (%1)\n"
22307 - " movq %%mm1, 8(%1)\n"
22308 - " movq %%mm2, 16(%1)\n"
22309 - " movq %%mm3, 24(%1)\n"
22310 - " movq 32(%0), %%mm0\n"
22311 - " movq 40(%0), %%mm1\n"
22312 - " movq 48(%0), %%mm2\n"
22313 - " movq 56(%0), %%mm3\n"
22314 - " movq %%mm0, 32(%1)\n"
22315 - " movq %%mm1, 40(%1)\n"
22316 - " movq %%mm2, 48(%1)\n"
22317 - " movq %%mm3, 56(%1)\n"
22318 + "1: prefetch 320(%1)\n"
22319 + "2: movq (%1), %%mm0\n"
22320 + " movq 8(%1), %%mm1\n"
22321 + " movq 16(%1), %%mm2\n"
22322 + " movq 24(%1), %%mm3\n"
22323 + " movq %%mm0, (%2)\n"
22324 + " movq %%mm1, 8(%2)\n"
22325 + " movq %%mm2, 16(%2)\n"
22326 + " movq %%mm3, 24(%2)\n"
22327 + " movq 32(%1), %%mm0\n"
22328 + " movq 40(%1), %%mm1\n"
22329 + " movq 48(%1), %%mm2\n"
22330 + " movq 56(%1), %%mm3\n"
22331 + " movq %%mm0, 32(%2)\n"
22332 + " movq %%mm1, 40(%2)\n"
22333 + " movq %%mm2, 48(%2)\n"
22334 + " movq %%mm3, 56(%2)\n"
22335 ".section .fixup, \"ax\"\n"
22336 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22337 + "3:\n"
22338 +
22339 +#ifdef CONFIG_PAX_KERNEXEC
22340 + " movl %%cr0, %0\n"
22341 + " movl %0, %%eax\n"
22342 + " andl $0xFFFEFFFF, %%eax\n"
22343 + " movl %%eax, %%cr0\n"
22344 +#endif
22345 +
22346 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22347 +
22348 +#ifdef CONFIG_PAX_KERNEXEC
22349 + " movl %0, %%cr0\n"
22350 +#endif
22351 +
22352 " jmp 2b\n"
22353 ".previous\n"
22354 _ASM_EXTABLE(1b, 3b)
22355 - : : "r" (from), "r" (to) : "memory");
22356 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22357
22358 from += 64;
22359 to += 64;
22360 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22361 static void fast_copy_page(void *to, void *from)
22362 {
22363 int i;
22364 + unsigned long cr0;
22365
22366 kernel_fpu_begin();
22367
22368 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22369 * but that is for later. -AV
22370 */
22371 __asm__ __volatile__(
22372 - "1: prefetch (%0)\n"
22373 - " prefetch 64(%0)\n"
22374 - " prefetch 128(%0)\n"
22375 - " prefetch 192(%0)\n"
22376 - " prefetch 256(%0)\n"
22377 + "1: prefetch (%1)\n"
22378 + " prefetch 64(%1)\n"
22379 + " prefetch 128(%1)\n"
22380 + " prefetch 192(%1)\n"
22381 + " prefetch 256(%1)\n"
22382 "2: \n"
22383 ".section .fixup, \"ax\"\n"
22384 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22385 + "3: \n"
22386 +
22387 +#ifdef CONFIG_PAX_KERNEXEC
22388 + " movl %%cr0, %0\n"
22389 + " movl %0, %%eax\n"
22390 + " andl $0xFFFEFFFF, %%eax\n"
22391 + " movl %%eax, %%cr0\n"
22392 +#endif
22393 +
22394 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22395 +
22396 +#ifdef CONFIG_PAX_KERNEXEC
22397 + " movl %0, %%cr0\n"
22398 +#endif
22399 +
22400 " jmp 2b\n"
22401 ".previous\n"
22402 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22403 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22404
22405 for (i = 0; i < (4096-320)/64; i++) {
22406 __asm__ __volatile__ (
22407 - "1: prefetch 320(%0)\n"
22408 - "2: movq (%0), %%mm0\n"
22409 - " movntq %%mm0, (%1)\n"
22410 - " movq 8(%0), %%mm1\n"
22411 - " movntq %%mm1, 8(%1)\n"
22412 - " movq 16(%0), %%mm2\n"
22413 - " movntq %%mm2, 16(%1)\n"
22414 - " movq 24(%0), %%mm3\n"
22415 - " movntq %%mm3, 24(%1)\n"
22416 - " movq 32(%0), %%mm4\n"
22417 - " movntq %%mm4, 32(%1)\n"
22418 - " movq 40(%0), %%mm5\n"
22419 - " movntq %%mm5, 40(%1)\n"
22420 - " movq 48(%0), %%mm6\n"
22421 - " movntq %%mm6, 48(%1)\n"
22422 - " movq 56(%0), %%mm7\n"
22423 - " movntq %%mm7, 56(%1)\n"
22424 + "1: prefetch 320(%1)\n"
22425 + "2: movq (%1), %%mm0\n"
22426 + " movntq %%mm0, (%2)\n"
22427 + " movq 8(%1), %%mm1\n"
22428 + " movntq %%mm1, 8(%2)\n"
22429 + " movq 16(%1), %%mm2\n"
22430 + " movntq %%mm2, 16(%2)\n"
22431 + " movq 24(%1), %%mm3\n"
22432 + " movntq %%mm3, 24(%2)\n"
22433 + " movq 32(%1), %%mm4\n"
22434 + " movntq %%mm4, 32(%2)\n"
22435 + " movq 40(%1), %%mm5\n"
22436 + " movntq %%mm5, 40(%2)\n"
22437 + " movq 48(%1), %%mm6\n"
22438 + " movntq %%mm6, 48(%2)\n"
22439 + " movq 56(%1), %%mm7\n"
22440 + " movntq %%mm7, 56(%2)\n"
22441 ".section .fixup, \"ax\"\n"
22442 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22443 + "3:\n"
22444 +
22445 +#ifdef CONFIG_PAX_KERNEXEC
22446 + " movl %%cr0, %0\n"
22447 + " movl %0, %%eax\n"
22448 + " andl $0xFFFEFFFF, %%eax\n"
22449 + " movl %%eax, %%cr0\n"
22450 +#endif
22451 +
22452 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22453 +
22454 +#ifdef CONFIG_PAX_KERNEXEC
22455 + " movl %0, %%cr0\n"
22456 +#endif
22457 +
22458 " jmp 2b\n"
22459 ".previous\n"
22460 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22461 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22462
22463 from += 64;
22464 to += 64;
22465 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22466 static void fast_copy_page(void *to, void *from)
22467 {
22468 int i;
22469 + unsigned long cr0;
22470
22471 kernel_fpu_begin();
22472
22473 __asm__ __volatile__ (
22474 - "1: prefetch (%0)\n"
22475 - " prefetch 64(%0)\n"
22476 - " prefetch 128(%0)\n"
22477 - " prefetch 192(%0)\n"
22478 - " prefetch 256(%0)\n"
22479 + "1: prefetch (%1)\n"
22480 + " prefetch 64(%1)\n"
22481 + " prefetch 128(%1)\n"
22482 + " prefetch 192(%1)\n"
22483 + " prefetch 256(%1)\n"
22484 "2: \n"
22485 ".section .fixup, \"ax\"\n"
22486 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22487 + "3: \n"
22488 +
22489 +#ifdef CONFIG_PAX_KERNEXEC
22490 + " movl %%cr0, %0\n"
22491 + " movl %0, %%eax\n"
22492 + " andl $0xFFFEFFFF, %%eax\n"
22493 + " movl %%eax, %%cr0\n"
22494 +#endif
22495 +
22496 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22497 +
22498 +#ifdef CONFIG_PAX_KERNEXEC
22499 + " movl %0, %%cr0\n"
22500 +#endif
22501 +
22502 " jmp 2b\n"
22503 ".previous\n"
22504 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22505 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22506
22507 for (i = 0; i < 4096/64; i++) {
22508 __asm__ __volatile__ (
22509 - "1: prefetch 320(%0)\n"
22510 - "2: movq (%0), %%mm0\n"
22511 - " movq 8(%0), %%mm1\n"
22512 - " movq 16(%0), %%mm2\n"
22513 - " movq 24(%0), %%mm3\n"
22514 - " movq %%mm0, (%1)\n"
22515 - " movq %%mm1, 8(%1)\n"
22516 - " movq %%mm2, 16(%1)\n"
22517 - " movq %%mm3, 24(%1)\n"
22518 - " movq 32(%0), %%mm0\n"
22519 - " movq 40(%0), %%mm1\n"
22520 - " movq 48(%0), %%mm2\n"
22521 - " movq 56(%0), %%mm3\n"
22522 - " movq %%mm0, 32(%1)\n"
22523 - " movq %%mm1, 40(%1)\n"
22524 - " movq %%mm2, 48(%1)\n"
22525 - " movq %%mm3, 56(%1)\n"
22526 + "1: prefetch 320(%1)\n"
22527 + "2: movq (%1), %%mm0\n"
22528 + " movq 8(%1), %%mm1\n"
22529 + " movq 16(%1), %%mm2\n"
22530 + " movq 24(%1), %%mm3\n"
22531 + " movq %%mm0, (%2)\n"
22532 + " movq %%mm1, 8(%2)\n"
22533 + " movq %%mm2, 16(%2)\n"
22534 + " movq %%mm3, 24(%2)\n"
22535 + " movq 32(%1), %%mm0\n"
22536 + " movq 40(%1), %%mm1\n"
22537 + " movq 48(%1), %%mm2\n"
22538 + " movq 56(%1), %%mm3\n"
22539 + " movq %%mm0, 32(%2)\n"
22540 + " movq %%mm1, 40(%2)\n"
22541 + " movq %%mm2, 48(%2)\n"
22542 + " movq %%mm3, 56(%2)\n"
22543 ".section .fixup, \"ax\"\n"
22544 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22545 + "3:\n"
22546 +
22547 +#ifdef CONFIG_PAX_KERNEXEC
22548 + " movl %%cr0, %0\n"
22549 + " movl %0, %%eax\n"
22550 + " andl $0xFFFEFFFF, %%eax\n"
22551 + " movl %%eax, %%cr0\n"
22552 +#endif
22553 +
22554 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22555 +
22556 +#ifdef CONFIG_PAX_KERNEXEC
22557 + " movl %0, %%cr0\n"
22558 +#endif
22559 +
22560 " jmp 2b\n"
22561 ".previous\n"
22562 _ASM_EXTABLE(1b, 3b)
22563 - : : "r" (from), "r" (to) : "memory");
22564 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22565
22566 from += 64;
22567 to += 64;
22568 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22569 index 69fa106..adda88b 100644
22570 --- a/arch/x86/lib/msr-reg.S
22571 +++ b/arch/x86/lib/msr-reg.S
22572 @@ -3,6 +3,7 @@
22573 #include <asm/dwarf2.h>
22574 #include <asm/asm.h>
22575 #include <asm/msr.h>
22576 +#include <asm/alternative-asm.h>
22577
22578 #ifdef CONFIG_X86_64
22579 /*
22580 @@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
22581 CFI_STARTPROC
22582 pushq_cfi %rbx
22583 pushq_cfi %rbp
22584 - movq %rdi, %r10 /* Save pointer */
22585 + movq %rdi, %r9 /* Save pointer */
22586 xorl %r11d, %r11d /* Return value */
22587 movl (%rdi), %eax
22588 movl 4(%rdi), %ecx
22589 @@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
22590 movl 28(%rdi), %edi
22591 CFI_REMEMBER_STATE
22592 1: \op
22593 -2: movl %eax, (%r10)
22594 +2: movl %eax, (%r9)
22595 movl %r11d, %eax /* Return value */
22596 - movl %ecx, 4(%r10)
22597 - movl %edx, 8(%r10)
22598 - movl %ebx, 12(%r10)
22599 - movl %ebp, 20(%r10)
22600 - movl %esi, 24(%r10)
22601 - movl %edi, 28(%r10)
22602 + movl %ecx, 4(%r9)
22603 + movl %edx, 8(%r9)
22604 + movl %ebx, 12(%r9)
22605 + movl %ebp, 20(%r9)
22606 + movl %esi, 24(%r9)
22607 + movl %edi, 28(%r9)
22608 popq_cfi %rbp
22609 popq_cfi %rbx
22610 + pax_force_retaddr
22611 ret
22612 3:
22613 CFI_RESTORE_STATE
22614 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22615 index 36b0d15..d381858 100644
22616 --- a/arch/x86/lib/putuser.S
22617 +++ b/arch/x86/lib/putuser.S
22618 @@ -15,7 +15,9 @@
22619 #include <asm/thread_info.h>
22620 #include <asm/errno.h>
22621 #include <asm/asm.h>
22622 -
22623 +#include <asm/segment.h>
22624 +#include <asm/pgtable.h>
22625 +#include <asm/alternative-asm.h>
22626
22627 /*
22628 * __put_user_X
22629 @@ -29,52 +31,119 @@
22630 * as they get called from within inline assembly.
22631 */
22632
22633 -#define ENTER CFI_STARTPROC ; \
22634 - GET_THREAD_INFO(%_ASM_BX)
22635 -#define EXIT ret ; \
22636 +#define ENTER CFI_STARTPROC
22637 +#define EXIT pax_force_retaddr; ret ; \
22638 CFI_ENDPROC
22639
22640 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22641 +#define _DEST %_ASM_CX,%_ASM_BX
22642 +#else
22643 +#define _DEST %_ASM_CX
22644 +#endif
22645 +
22646 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22647 +#define __copyuser_seg gs;
22648 +#else
22649 +#define __copyuser_seg
22650 +#endif
22651 +
22652 .text
22653 ENTRY(__put_user_1)
22654 ENTER
22655 +
22656 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22657 + GET_THREAD_INFO(%_ASM_BX)
22658 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22659 jae bad_put_user
22660 -1: movb %al,(%_ASM_CX)
22661 +
22662 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22663 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22664 + cmp %_ASM_BX,%_ASM_CX
22665 + jb 1234f
22666 + xor %ebx,%ebx
22667 +1234:
22668 +#endif
22669 +
22670 +#endif
22671 +
22672 +1: __copyuser_seg movb %al,(_DEST)
22673 xor %eax,%eax
22674 EXIT
22675 ENDPROC(__put_user_1)
22676
22677 ENTRY(__put_user_2)
22678 ENTER
22679 +
22680 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22681 + GET_THREAD_INFO(%_ASM_BX)
22682 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22683 sub $1,%_ASM_BX
22684 cmp %_ASM_BX,%_ASM_CX
22685 jae bad_put_user
22686 -2: movw %ax,(%_ASM_CX)
22687 +
22688 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22689 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22690 + cmp %_ASM_BX,%_ASM_CX
22691 + jb 1234f
22692 + xor %ebx,%ebx
22693 +1234:
22694 +#endif
22695 +
22696 +#endif
22697 +
22698 +2: __copyuser_seg movw %ax,(_DEST)
22699 xor %eax,%eax
22700 EXIT
22701 ENDPROC(__put_user_2)
22702
22703 ENTRY(__put_user_4)
22704 ENTER
22705 +
22706 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22707 + GET_THREAD_INFO(%_ASM_BX)
22708 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22709 sub $3,%_ASM_BX
22710 cmp %_ASM_BX,%_ASM_CX
22711 jae bad_put_user
22712 -3: movl %eax,(%_ASM_CX)
22713 +
22714 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22715 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22716 + cmp %_ASM_BX,%_ASM_CX
22717 + jb 1234f
22718 + xor %ebx,%ebx
22719 +1234:
22720 +#endif
22721 +
22722 +#endif
22723 +
22724 +3: __copyuser_seg movl %eax,(_DEST)
22725 xor %eax,%eax
22726 EXIT
22727 ENDPROC(__put_user_4)
22728
22729 ENTRY(__put_user_8)
22730 ENTER
22731 +
22732 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22733 + GET_THREAD_INFO(%_ASM_BX)
22734 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22735 sub $7,%_ASM_BX
22736 cmp %_ASM_BX,%_ASM_CX
22737 jae bad_put_user
22738 -4: mov %_ASM_AX,(%_ASM_CX)
22739 +
22740 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22741 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22742 + cmp %_ASM_BX,%_ASM_CX
22743 + jb 1234f
22744 + xor %ebx,%ebx
22745 +1234:
22746 +#endif
22747 +
22748 +#endif
22749 +
22750 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
22751 #ifdef CONFIG_X86_32
22752 -5: movl %edx,4(%_ASM_CX)
22753 +5: __copyuser_seg movl %edx,4(_DEST)
22754 #endif
22755 xor %eax,%eax
22756 EXIT
22757 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22758 index 1cad221..de671ee 100644
22759 --- a/arch/x86/lib/rwlock.S
22760 +++ b/arch/x86/lib/rwlock.S
22761 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22762 FRAME
22763 0: LOCK_PREFIX
22764 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22765 +
22766 +#ifdef CONFIG_PAX_REFCOUNT
22767 + jno 1234f
22768 + LOCK_PREFIX
22769 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22770 + int $4
22771 +1234:
22772 + _ASM_EXTABLE(1234b, 1234b)
22773 +#endif
22774 +
22775 1: rep; nop
22776 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22777 jne 1b
22778 LOCK_PREFIX
22779 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22780 +
22781 +#ifdef CONFIG_PAX_REFCOUNT
22782 + jno 1234f
22783 + LOCK_PREFIX
22784 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22785 + int $4
22786 +1234:
22787 + _ASM_EXTABLE(1234b, 1234b)
22788 +#endif
22789 +
22790 jnz 0b
22791 ENDFRAME
22792 + pax_force_retaddr
22793 ret
22794 CFI_ENDPROC
22795 END(__write_lock_failed)
22796 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22797 FRAME
22798 0: LOCK_PREFIX
22799 READ_LOCK_SIZE(inc) (%__lock_ptr)
22800 +
22801 +#ifdef CONFIG_PAX_REFCOUNT
22802 + jno 1234f
22803 + LOCK_PREFIX
22804 + READ_LOCK_SIZE(dec) (%__lock_ptr)
22805 + int $4
22806 +1234:
22807 + _ASM_EXTABLE(1234b, 1234b)
22808 +#endif
22809 +
22810 1: rep; nop
22811 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22812 js 1b
22813 LOCK_PREFIX
22814 READ_LOCK_SIZE(dec) (%__lock_ptr)
22815 +
22816 +#ifdef CONFIG_PAX_REFCOUNT
22817 + jno 1234f
22818 + LOCK_PREFIX
22819 + READ_LOCK_SIZE(inc) (%__lock_ptr)
22820 + int $4
22821 +1234:
22822 + _ASM_EXTABLE(1234b, 1234b)
22823 +#endif
22824 +
22825 js 0b
22826 ENDFRAME
22827 + pax_force_retaddr
22828 ret
22829 CFI_ENDPROC
22830 END(__read_lock_failed)
22831 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22832 index 5dff5f0..cadebf4 100644
22833 --- a/arch/x86/lib/rwsem.S
22834 +++ b/arch/x86/lib/rwsem.S
22835 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22836 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22837 CFI_RESTORE __ASM_REG(dx)
22838 restore_common_regs
22839 + pax_force_retaddr
22840 ret
22841 CFI_ENDPROC
22842 ENDPROC(call_rwsem_down_read_failed)
22843 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22844 movq %rax,%rdi
22845 call rwsem_down_write_failed
22846 restore_common_regs
22847 + pax_force_retaddr
22848 ret
22849 CFI_ENDPROC
22850 ENDPROC(call_rwsem_down_write_failed)
22851 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22852 movq %rax,%rdi
22853 call rwsem_wake
22854 restore_common_regs
22855 -1: ret
22856 +1: pax_force_retaddr
22857 + ret
22858 CFI_ENDPROC
22859 ENDPROC(call_rwsem_wake)
22860
22861 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22862 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22863 CFI_RESTORE __ASM_REG(dx)
22864 restore_common_regs
22865 + pax_force_retaddr
22866 ret
22867 CFI_ENDPROC
22868 ENDPROC(call_rwsem_downgrade_wake)
22869 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22870 index a63efd6..ccecad8 100644
22871 --- a/arch/x86/lib/thunk_64.S
22872 +++ b/arch/x86/lib/thunk_64.S
22873 @@ -8,6 +8,7 @@
22874 #include <linux/linkage.h>
22875 #include <asm/dwarf2.h>
22876 #include <asm/calling.h>
22877 +#include <asm/alternative-asm.h>
22878
22879 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22880 .macro THUNK name, func, put_ret_addr_in_rdi=0
22881 @@ -41,5 +42,6 @@
22882 SAVE_ARGS
22883 restore:
22884 RESTORE_ARGS
22885 + pax_force_retaddr
22886 ret
22887 CFI_ENDPROC
22888 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22889 index ef2a6a5..3b28862 100644
22890 --- a/arch/x86/lib/usercopy_32.c
22891 +++ b/arch/x86/lib/usercopy_32.c
22892 @@ -41,10 +41,12 @@ do { \
22893 int __d0; \
22894 might_fault(); \
22895 __asm__ __volatile__( \
22896 + __COPYUSER_SET_ES \
22897 "0: rep; stosl\n" \
22898 " movl %2,%0\n" \
22899 "1: rep; stosb\n" \
22900 "2:\n" \
22901 + __COPYUSER_RESTORE_ES \
22902 ".section .fixup,\"ax\"\n" \
22903 "3: lea 0(%2,%0,4),%0\n" \
22904 " jmp 2b\n" \
22905 @@ -113,6 +115,7 @@ long strnlen_user(const char __user *s, long n)
22906 might_fault();
22907
22908 __asm__ __volatile__(
22909 + __COPYUSER_SET_ES
22910 " testl %0, %0\n"
22911 " jz 3f\n"
22912 " andl %0,%%ecx\n"
22913 @@ -121,6 +124,7 @@ long strnlen_user(const char __user *s, long n)
22914 " subl %%ecx,%0\n"
22915 " addl %0,%%eax\n"
22916 "1:\n"
22917 + __COPYUSER_RESTORE_ES
22918 ".section .fixup,\"ax\"\n"
22919 "2: xorl %%eax,%%eax\n"
22920 " jmp 1b\n"
22921 @@ -140,7 +144,7 @@ EXPORT_SYMBOL(strnlen_user);
22922
22923 #ifdef CONFIG_X86_INTEL_USERCOPY
22924 static unsigned long
22925 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
22926 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22927 {
22928 int d0, d1;
22929 __asm__ __volatile__(
22930 @@ -152,36 +156,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22931 " .align 2,0x90\n"
22932 "3: movl 0(%4), %%eax\n"
22933 "4: movl 4(%4), %%edx\n"
22934 - "5: movl %%eax, 0(%3)\n"
22935 - "6: movl %%edx, 4(%3)\n"
22936 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22937 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22938 "7: movl 8(%4), %%eax\n"
22939 "8: movl 12(%4),%%edx\n"
22940 - "9: movl %%eax, 8(%3)\n"
22941 - "10: movl %%edx, 12(%3)\n"
22942 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22943 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22944 "11: movl 16(%4), %%eax\n"
22945 "12: movl 20(%4), %%edx\n"
22946 - "13: movl %%eax, 16(%3)\n"
22947 - "14: movl %%edx, 20(%3)\n"
22948 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22949 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22950 "15: movl 24(%4), %%eax\n"
22951 "16: movl 28(%4), %%edx\n"
22952 - "17: movl %%eax, 24(%3)\n"
22953 - "18: movl %%edx, 28(%3)\n"
22954 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22955 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22956 "19: movl 32(%4), %%eax\n"
22957 "20: movl 36(%4), %%edx\n"
22958 - "21: movl %%eax, 32(%3)\n"
22959 - "22: movl %%edx, 36(%3)\n"
22960 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22961 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22962 "23: movl 40(%4), %%eax\n"
22963 "24: movl 44(%4), %%edx\n"
22964 - "25: movl %%eax, 40(%3)\n"
22965 - "26: movl %%edx, 44(%3)\n"
22966 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22967 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22968 "27: movl 48(%4), %%eax\n"
22969 "28: movl 52(%4), %%edx\n"
22970 - "29: movl %%eax, 48(%3)\n"
22971 - "30: movl %%edx, 52(%3)\n"
22972 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22973 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22974 "31: movl 56(%4), %%eax\n"
22975 "32: movl 60(%4), %%edx\n"
22976 - "33: movl %%eax, 56(%3)\n"
22977 - "34: movl %%edx, 60(%3)\n"
22978 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22979 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22980 " addl $-64, %0\n"
22981 " addl $64, %4\n"
22982 " addl $64, %3\n"
22983 @@ -191,10 +195,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22984 " shrl $2, %0\n"
22985 " andl $3, %%eax\n"
22986 " cld\n"
22987 + __COPYUSER_SET_ES
22988 "99: rep; movsl\n"
22989 "36: movl %%eax, %0\n"
22990 "37: rep; movsb\n"
22991 "100:\n"
22992 + __COPYUSER_RESTORE_ES
22993 ".section .fixup,\"ax\"\n"
22994 "101: lea 0(%%eax,%0,4),%0\n"
22995 " jmp 100b\n"
22996 @@ -247,46 +253,155 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22997 }
22998
22999 static unsigned long
23000 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
23001 +{
23002 + int d0, d1;
23003 + __asm__ __volatile__(
23004 + " .align 2,0x90\n"
23005 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
23006 + " cmpl $67, %0\n"
23007 + " jbe 3f\n"
23008 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
23009 + " .align 2,0x90\n"
23010 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
23011 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
23012 + "5: movl %%eax, 0(%3)\n"
23013 + "6: movl %%edx, 4(%3)\n"
23014 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
23015 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
23016 + "9: movl %%eax, 8(%3)\n"
23017 + "10: movl %%edx, 12(%3)\n"
23018 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
23019 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
23020 + "13: movl %%eax, 16(%3)\n"
23021 + "14: movl %%edx, 20(%3)\n"
23022 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
23023 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
23024 + "17: movl %%eax, 24(%3)\n"
23025 + "18: movl %%edx, 28(%3)\n"
23026 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
23027 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
23028 + "21: movl %%eax, 32(%3)\n"
23029 + "22: movl %%edx, 36(%3)\n"
23030 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
23031 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
23032 + "25: movl %%eax, 40(%3)\n"
23033 + "26: movl %%edx, 44(%3)\n"
23034 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
23035 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
23036 + "29: movl %%eax, 48(%3)\n"
23037 + "30: movl %%edx, 52(%3)\n"
23038 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
23039 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
23040 + "33: movl %%eax, 56(%3)\n"
23041 + "34: movl %%edx, 60(%3)\n"
23042 + " addl $-64, %0\n"
23043 + " addl $64, %4\n"
23044 + " addl $64, %3\n"
23045 + " cmpl $63, %0\n"
23046 + " ja 1b\n"
23047 + "35: movl %0, %%eax\n"
23048 + " shrl $2, %0\n"
23049 + " andl $3, %%eax\n"
23050 + " cld\n"
23051 + "99: rep; "__copyuser_seg" movsl\n"
23052 + "36: movl %%eax, %0\n"
23053 + "37: rep; "__copyuser_seg" movsb\n"
23054 + "100:\n"
23055 + ".section .fixup,\"ax\"\n"
23056 + "101: lea 0(%%eax,%0,4),%0\n"
23057 + " jmp 100b\n"
23058 + ".previous\n"
23059 + ".section __ex_table,\"a\"\n"
23060 + " .align 4\n"
23061 + " .long 1b,100b\n"
23062 + " .long 2b,100b\n"
23063 + " .long 3b,100b\n"
23064 + " .long 4b,100b\n"
23065 + " .long 5b,100b\n"
23066 + " .long 6b,100b\n"
23067 + " .long 7b,100b\n"
23068 + " .long 8b,100b\n"
23069 + " .long 9b,100b\n"
23070 + " .long 10b,100b\n"
23071 + " .long 11b,100b\n"
23072 + " .long 12b,100b\n"
23073 + " .long 13b,100b\n"
23074 + " .long 14b,100b\n"
23075 + " .long 15b,100b\n"
23076 + " .long 16b,100b\n"
23077 + " .long 17b,100b\n"
23078 + " .long 18b,100b\n"
23079 + " .long 19b,100b\n"
23080 + " .long 20b,100b\n"
23081 + " .long 21b,100b\n"
23082 + " .long 22b,100b\n"
23083 + " .long 23b,100b\n"
23084 + " .long 24b,100b\n"
23085 + " .long 25b,100b\n"
23086 + " .long 26b,100b\n"
23087 + " .long 27b,100b\n"
23088 + " .long 28b,100b\n"
23089 + " .long 29b,100b\n"
23090 + " .long 30b,100b\n"
23091 + " .long 31b,100b\n"
23092 + " .long 32b,100b\n"
23093 + " .long 33b,100b\n"
23094 + " .long 34b,100b\n"
23095 + " .long 35b,100b\n"
23096 + " .long 36b,100b\n"
23097 + " .long 37b,100b\n"
23098 + " .long 99b,101b\n"
23099 + ".previous"
23100 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
23101 + : "1"(to), "2"(from), "0"(size)
23102 + : "eax", "edx", "memory");
23103 + return size;
23104 +}
23105 +
23106 +static unsigned long
23107 +__copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size) __size_overflow(3);
23108 +static unsigned long
23109 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23110 {
23111 int d0, d1;
23112 __asm__ __volatile__(
23113 " .align 2,0x90\n"
23114 - "0: movl 32(%4), %%eax\n"
23115 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23116 " cmpl $67, %0\n"
23117 " jbe 2f\n"
23118 - "1: movl 64(%4), %%eax\n"
23119 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23120 " .align 2,0x90\n"
23121 - "2: movl 0(%4), %%eax\n"
23122 - "21: movl 4(%4), %%edx\n"
23123 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23124 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23125 " movl %%eax, 0(%3)\n"
23126 " movl %%edx, 4(%3)\n"
23127 - "3: movl 8(%4), %%eax\n"
23128 - "31: movl 12(%4),%%edx\n"
23129 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23130 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23131 " movl %%eax, 8(%3)\n"
23132 " movl %%edx, 12(%3)\n"
23133 - "4: movl 16(%4), %%eax\n"
23134 - "41: movl 20(%4), %%edx\n"
23135 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23136 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23137 " movl %%eax, 16(%3)\n"
23138 " movl %%edx, 20(%3)\n"
23139 - "10: movl 24(%4), %%eax\n"
23140 - "51: movl 28(%4), %%edx\n"
23141 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23142 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23143 " movl %%eax, 24(%3)\n"
23144 " movl %%edx, 28(%3)\n"
23145 - "11: movl 32(%4), %%eax\n"
23146 - "61: movl 36(%4), %%edx\n"
23147 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23148 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23149 " movl %%eax, 32(%3)\n"
23150 " movl %%edx, 36(%3)\n"
23151 - "12: movl 40(%4), %%eax\n"
23152 - "71: movl 44(%4), %%edx\n"
23153 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23154 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23155 " movl %%eax, 40(%3)\n"
23156 " movl %%edx, 44(%3)\n"
23157 - "13: movl 48(%4), %%eax\n"
23158 - "81: movl 52(%4), %%edx\n"
23159 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23160 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23161 " movl %%eax, 48(%3)\n"
23162 " movl %%edx, 52(%3)\n"
23163 - "14: movl 56(%4), %%eax\n"
23164 - "91: movl 60(%4), %%edx\n"
23165 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23166 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23167 " movl %%eax, 56(%3)\n"
23168 " movl %%edx, 60(%3)\n"
23169 " addl $-64, %0\n"
23170 @@ -298,9 +413,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23171 " shrl $2, %0\n"
23172 " andl $3, %%eax\n"
23173 " cld\n"
23174 - "6: rep; movsl\n"
23175 + "6: rep; "__copyuser_seg" movsl\n"
23176 " movl %%eax,%0\n"
23177 - "7: rep; movsb\n"
23178 + "7: rep; "__copyuser_seg" movsb\n"
23179 "8:\n"
23180 ".section .fixup,\"ax\"\n"
23181 "9: lea 0(%%eax,%0,4),%0\n"
23182 @@ -347,47 +462,49 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23183 */
23184
23185 static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23186 + const void __user *from, unsigned long size) __size_overflow(3);
23187 +static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23188 const void __user *from, unsigned long size)
23189 {
23190 int d0, d1;
23191
23192 __asm__ __volatile__(
23193 " .align 2,0x90\n"
23194 - "0: movl 32(%4), %%eax\n"
23195 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23196 " cmpl $67, %0\n"
23197 " jbe 2f\n"
23198 - "1: movl 64(%4), %%eax\n"
23199 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23200 " .align 2,0x90\n"
23201 - "2: movl 0(%4), %%eax\n"
23202 - "21: movl 4(%4), %%edx\n"
23203 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23204 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23205 " movnti %%eax, 0(%3)\n"
23206 " movnti %%edx, 4(%3)\n"
23207 - "3: movl 8(%4), %%eax\n"
23208 - "31: movl 12(%4),%%edx\n"
23209 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23210 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23211 " movnti %%eax, 8(%3)\n"
23212 " movnti %%edx, 12(%3)\n"
23213 - "4: movl 16(%4), %%eax\n"
23214 - "41: movl 20(%4), %%edx\n"
23215 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23216 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23217 " movnti %%eax, 16(%3)\n"
23218 " movnti %%edx, 20(%3)\n"
23219 - "10: movl 24(%4), %%eax\n"
23220 - "51: movl 28(%4), %%edx\n"
23221 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23222 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23223 " movnti %%eax, 24(%3)\n"
23224 " movnti %%edx, 28(%3)\n"
23225 - "11: movl 32(%4), %%eax\n"
23226 - "61: movl 36(%4), %%edx\n"
23227 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23228 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23229 " movnti %%eax, 32(%3)\n"
23230 " movnti %%edx, 36(%3)\n"
23231 - "12: movl 40(%4), %%eax\n"
23232 - "71: movl 44(%4), %%edx\n"
23233 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23234 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23235 " movnti %%eax, 40(%3)\n"
23236 " movnti %%edx, 44(%3)\n"
23237 - "13: movl 48(%4), %%eax\n"
23238 - "81: movl 52(%4), %%edx\n"
23239 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23240 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23241 " movnti %%eax, 48(%3)\n"
23242 " movnti %%edx, 52(%3)\n"
23243 - "14: movl 56(%4), %%eax\n"
23244 - "91: movl 60(%4), %%edx\n"
23245 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23246 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23247 " movnti %%eax, 56(%3)\n"
23248 " movnti %%edx, 60(%3)\n"
23249 " addl $-64, %0\n"
23250 @@ -400,9 +517,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23251 " shrl $2, %0\n"
23252 " andl $3, %%eax\n"
23253 " cld\n"
23254 - "6: rep; movsl\n"
23255 + "6: rep; "__copyuser_seg" movsl\n"
23256 " movl %%eax,%0\n"
23257 - "7: rep; movsb\n"
23258 + "7: rep; "__copyuser_seg" movsb\n"
23259 "8:\n"
23260 ".section .fixup,\"ax\"\n"
23261 "9: lea 0(%%eax,%0,4),%0\n"
23262 @@ -444,47 +561,49 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23263 }
23264
23265 static unsigned long __copy_user_intel_nocache(void *to,
23266 + const void __user *from, unsigned long size) __size_overflow(3);
23267 +static unsigned long __copy_user_intel_nocache(void *to,
23268 const void __user *from, unsigned long size)
23269 {
23270 int d0, d1;
23271
23272 __asm__ __volatile__(
23273 " .align 2,0x90\n"
23274 - "0: movl 32(%4), %%eax\n"
23275 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23276 " cmpl $67, %0\n"
23277 " jbe 2f\n"
23278 - "1: movl 64(%4), %%eax\n"
23279 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23280 " .align 2,0x90\n"
23281 - "2: movl 0(%4), %%eax\n"
23282 - "21: movl 4(%4), %%edx\n"
23283 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23284 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23285 " movnti %%eax, 0(%3)\n"
23286 " movnti %%edx, 4(%3)\n"
23287 - "3: movl 8(%4), %%eax\n"
23288 - "31: movl 12(%4),%%edx\n"
23289 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23290 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23291 " movnti %%eax, 8(%3)\n"
23292 " movnti %%edx, 12(%3)\n"
23293 - "4: movl 16(%4), %%eax\n"
23294 - "41: movl 20(%4), %%edx\n"
23295 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23296 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23297 " movnti %%eax, 16(%3)\n"
23298 " movnti %%edx, 20(%3)\n"
23299 - "10: movl 24(%4), %%eax\n"
23300 - "51: movl 28(%4), %%edx\n"
23301 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23302 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23303 " movnti %%eax, 24(%3)\n"
23304 " movnti %%edx, 28(%3)\n"
23305 - "11: movl 32(%4), %%eax\n"
23306 - "61: movl 36(%4), %%edx\n"
23307 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23308 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23309 " movnti %%eax, 32(%3)\n"
23310 " movnti %%edx, 36(%3)\n"
23311 - "12: movl 40(%4), %%eax\n"
23312 - "71: movl 44(%4), %%edx\n"
23313 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23314 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23315 " movnti %%eax, 40(%3)\n"
23316 " movnti %%edx, 44(%3)\n"
23317 - "13: movl 48(%4), %%eax\n"
23318 - "81: movl 52(%4), %%edx\n"
23319 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23320 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23321 " movnti %%eax, 48(%3)\n"
23322 " movnti %%edx, 52(%3)\n"
23323 - "14: movl 56(%4), %%eax\n"
23324 - "91: movl 60(%4), %%edx\n"
23325 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23326 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23327 " movnti %%eax, 56(%3)\n"
23328 " movnti %%edx, 60(%3)\n"
23329 " addl $-64, %0\n"
23330 @@ -497,9 +616,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23331 " shrl $2, %0\n"
23332 " andl $3, %%eax\n"
23333 " cld\n"
23334 - "6: rep; movsl\n"
23335 + "6: rep; "__copyuser_seg" movsl\n"
23336 " movl %%eax,%0\n"
23337 - "7: rep; movsb\n"
23338 + "7: rep; "__copyuser_seg" movsb\n"
23339 "8:\n"
23340 ".section .fixup,\"ax\"\n"
23341 "9: lea 0(%%eax,%0,4),%0\n"
23342 @@ -542,32 +661,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23343 */
23344 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23345 unsigned long size);
23346 -unsigned long __copy_user_intel(void __user *to, const void *from,
23347 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23348 + unsigned long size);
23349 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23350 unsigned long size);
23351 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23352 const void __user *from, unsigned long size);
23353 #endif /* CONFIG_X86_INTEL_USERCOPY */
23354
23355 /* Generic arbitrary sized copy. */
23356 -#define __copy_user(to, from, size) \
23357 +#define __copy_user(to, from, size, prefix, set, restore) \
23358 do { \
23359 int __d0, __d1, __d2; \
23360 __asm__ __volatile__( \
23361 + set \
23362 " cmp $7,%0\n" \
23363 " jbe 1f\n" \
23364 " movl %1,%0\n" \
23365 " negl %0\n" \
23366 " andl $7,%0\n" \
23367 " subl %0,%3\n" \
23368 - "4: rep; movsb\n" \
23369 + "4: rep; "prefix"movsb\n" \
23370 " movl %3,%0\n" \
23371 " shrl $2,%0\n" \
23372 " andl $3,%3\n" \
23373 " .align 2,0x90\n" \
23374 - "0: rep; movsl\n" \
23375 + "0: rep; "prefix"movsl\n" \
23376 " movl %3,%0\n" \
23377 - "1: rep; movsb\n" \
23378 + "1: rep; "prefix"movsb\n" \
23379 "2:\n" \
23380 + restore \
23381 ".section .fixup,\"ax\"\n" \
23382 "5: addl %3,%0\n" \
23383 " jmp 2b\n" \
23384 @@ -595,14 +718,14 @@ do { \
23385 " negl %0\n" \
23386 " andl $7,%0\n" \
23387 " subl %0,%3\n" \
23388 - "4: rep; movsb\n" \
23389 + "4: rep; "__copyuser_seg"movsb\n" \
23390 " movl %3,%0\n" \
23391 " shrl $2,%0\n" \
23392 " andl $3,%3\n" \
23393 " .align 2,0x90\n" \
23394 - "0: rep; movsl\n" \
23395 + "0: rep; "__copyuser_seg"movsl\n" \
23396 " movl %3,%0\n" \
23397 - "1: rep; movsb\n" \
23398 + "1: rep; "__copyuser_seg"movsb\n" \
23399 "2:\n" \
23400 ".section .fixup,\"ax\"\n" \
23401 "5: addl %3,%0\n" \
23402 @@ -688,9 +811,9 @@ survive:
23403 }
23404 #endif
23405 if (movsl_is_ok(to, from, n))
23406 - __copy_user(to, from, n);
23407 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23408 else
23409 - n = __copy_user_intel(to, from, n);
23410 + n = __generic_copy_to_user_intel(to, from, n);
23411 return n;
23412 }
23413 EXPORT_SYMBOL(__copy_to_user_ll);
23414 @@ -710,10 +833,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23415 unsigned long n)
23416 {
23417 if (movsl_is_ok(to, from, n))
23418 - __copy_user(to, from, n);
23419 + __copy_user(to, from, n, __copyuser_seg, "", "");
23420 else
23421 - n = __copy_user_intel((void __user *)to,
23422 - (const void *)from, n);
23423 + n = __generic_copy_from_user_intel(to, from, n);
23424 return n;
23425 }
23426 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23427 @@ -740,65 +862,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23428 if (n > 64 && cpu_has_xmm2)
23429 n = __copy_user_intel_nocache(to, from, n);
23430 else
23431 - __copy_user(to, from, n);
23432 + __copy_user(to, from, n, __copyuser_seg, "", "");
23433 #else
23434 - __copy_user(to, from, n);
23435 + __copy_user(to, from, n, __copyuser_seg, "", "");
23436 #endif
23437 return n;
23438 }
23439 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23440
23441 -/**
23442 - * copy_to_user: - Copy a block of data into user space.
23443 - * @to: Destination address, in user space.
23444 - * @from: Source address, in kernel space.
23445 - * @n: Number of bytes to copy.
23446 - *
23447 - * Context: User context only. This function may sleep.
23448 - *
23449 - * Copy data from kernel space to user space.
23450 - *
23451 - * Returns number of bytes that could not be copied.
23452 - * On success, this will be zero.
23453 - */
23454 -unsigned long
23455 -copy_to_user(void __user *to, const void *from, unsigned long n)
23456 -{
23457 - if (access_ok(VERIFY_WRITE, to, n))
23458 - n = __copy_to_user(to, from, n);
23459 - return n;
23460 -}
23461 -EXPORT_SYMBOL(copy_to_user);
23462 -
23463 -/**
23464 - * copy_from_user: - Copy a block of data from user space.
23465 - * @to: Destination address, in kernel space.
23466 - * @from: Source address, in user space.
23467 - * @n: Number of bytes to copy.
23468 - *
23469 - * Context: User context only. This function may sleep.
23470 - *
23471 - * Copy data from user space to kernel space.
23472 - *
23473 - * Returns number of bytes that could not be copied.
23474 - * On success, this will be zero.
23475 - *
23476 - * If some data could not be copied, this function will pad the copied
23477 - * data to the requested size using zero bytes.
23478 - */
23479 -unsigned long
23480 -_copy_from_user(void *to, const void __user *from, unsigned long n)
23481 -{
23482 - if (access_ok(VERIFY_READ, from, n))
23483 - n = __copy_from_user(to, from, n);
23484 - else
23485 - memset(to, 0, n);
23486 - return n;
23487 -}
23488 -EXPORT_SYMBOL(_copy_from_user);
23489 -
23490 void copy_from_user_overflow(void)
23491 {
23492 WARN(1, "Buffer overflow detected!\n");
23493 }
23494 EXPORT_SYMBOL(copy_from_user_overflow);
23495 +
23496 +void copy_to_user_overflow(void)
23497 +{
23498 + WARN(1, "Buffer overflow detected!\n");
23499 +}
23500 +EXPORT_SYMBOL(copy_to_user_overflow);
23501 +
23502 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23503 +void __set_fs(mm_segment_t x)
23504 +{
23505 + switch (x.seg) {
23506 + case 0:
23507 + loadsegment(gs, 0);
23508 + break;
23509 + case TASK_SIZE_MAX:
23510 + loadsegment(gs, __USER_DS);
23511 + break;
23512 + case -1UL:
23513 + loadsegment(gs, __KERNEL_DS);
23514 + break;
23515 + default:
23516 + BUG();
23517 + }
23518 + return;
23519 +}
23520 +EXPORT_SYMBOL(__set_fs);
23521 +
23522 +void set_fs(mm_segment_t x)
23523 +{
23524 + current_thread_info()->addr_limit = x;
23525 + __set_fs(x);
23526 +}
23527 +EXPORT_SYMBOL(set_fs);
23528 +#endif
23529 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23530 index 0d0326f..6a6155b 100644
23531 --- a/arch/x86/lib/usercopy_64.c
23532 +++ b/arch/x86/lib/usercopy_64.c
23533 @@ -16,6 +16,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23534 {
23535 long __d0;
23536 might_fault();
23537 +
23538 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23539 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23540 + addr += PAX_USER_SHADOW_BASE;
23541 +#endif
23542 +
23543 /* no memory constraint because it doesn't change any memory gcc knows
23544 about */
23545 asm volatile(
23546 @@ -100,12 +106,20 @@ long strlen_user(const char __user *s)
23547 }
23548 EXPORT_SYMBOL(strlen_user);
23549
23550 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23551 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23552 {
23553 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23554 - return copy_user_generic((__force void *)to, (__force void *)from, len);
23555 - }
23556 - return len;
23557 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23558 +
23559 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23560 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23561 + to += PAX_USER_SHADOW_BASE;
23562 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23563 + from += PAX_USER_SHADOW_BASE;
23564 +#endif
23565 +
23566 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23567 + }
23568 + return len;
23569 }
23570 EXPORT_SYMBOL(copy_in_user);
23571
23572 @@ -115,7 +129,7 @@ EXPORT_SYMBOL(copy_in_user);
23573 * it is not necessary to optimize tail handling.
23574 */
23575 unsigned long
23576 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23577 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23578 {
23579 char c;
23580 unsigned zero_len;
23581 @@ -132,3 +146,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23582 break;
23583 return len;
23584 }
23585 +
23586 +void copy_from_user_overflow(void)
23587 +{
23588 + WARN(1, "Buffer overflow detected!\n");
23589 +}
23590 +EXPORT_SYMBOL(copy_from_user_overflow);
23591 +
23592 +void copy_to_user_overflow(void)
23593 +{
23594 + WARN(1, "Buffer overflow detected!\n");
23595 +}
23596 +EXPORT_SYMBOL(copy_to_user_overflow);
23597 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23598 index 1fb85db..8b3540b 100644
23599 --- a/arch/x86/mm/extable.c
23600 +++ b/arch/x86/mm/extable.c
23601 @@ -8,7 +8,7 @@ int fixup_exception(struct pt_regs *regs)
23602 const struct exception_table_entry *fixup;
23603
23604 #ifdef CONFIG_PNPBIOS
23605 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23606 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23607 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23608 extern u32 pnp_bios_is_utter_crap;
23609 pnp_bios_is_utter_crap = 1;
23610 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23611 index 3ecfd1a..304d554 100644
23612 --- a/arch/x86/mm/fault.c
23613 +++ b/arch/x86/mm/fault.c
23614 @@ -13,11 +13,18 @@
23615 #include <linux/perf_event.h> /* perf_sw_event */
23616 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23617 #include <linux/prefetch.h> /* prefetchw */
23618 +#include <linux/unistd.h>
23619 +#include <linux/compiler.h>
23620
23621 #include <asm/traps.h> /* dotraplinkage, ... */
23622 #include <asm/pgalloc.h> /* pgd_*(), ... */
23623 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23624 #include <asm/fixmap.h> /* VSYSCALL_START */
23625 +#include <asm/tlbflush.h>
23626 +
23627 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23628 +#include <asm/stacktrace.h>
23629 +#endif
23630
23631 /*
23632 * Page fault error code bits:
23633 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23634 int ret = 0;
23635
23636 /* kprobe_running() needs smp_processor_id() */
23637 - if (kprobes_built_in() && !user_mode_vm(regs)) {
23638 + if (kprobes_built_in() && !user_mode(regs)) {
23639 preempt_disable();
23640 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23641 ret = 1;
23642 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23643 return !instr_lo || (instr_lo>>1) == 1;
23644 case 0x00:
23645 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23646 - if (probe_kernel_address(instr, opcode))
23647 + if (user_mode(regs)) {
23648 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23649 + return 0;
23650 + } else if (probe_kernel_address(instr, opcode))
23651 return 0;
23652
23653 *prefetch = (instr_lo == 0xF) &&
23654 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23655 while (instr < max_instr) {
23656 unsigned char opcode;
23657
23658 - if (probe_kernel_address(instr, opcode))
23659 + if (user_mode(regs)) {
23660 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23661 + break;
23662 + } else if (probe_kernel_address(instr, opcode))
23663 break;
23664
23665 instr++;
23666 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23667 force_sig_info(si_signo, &info, tsk);
23668 }
23669
23670 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23671 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23672 +#endif
23673 +
23674 +#ifdef CONFIG_PAX_EMUTRAMP
23675 +static int pax_handle_fetch_fault(struct pt_regs *regs);
23676 +#endif
23677 +
23678 +#ifdef CONFIG_PAX_PAGEEXEC
23679 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23680 +{
23681 + pgd_t *pgd;
23682 + pud_t *pud;
23683 + pmd_t *pmd;
23684 +
23685 + pgd = pgd_offset(mm, address);
23686 + if (!pgd_present(*pgd))
23687 + return NULL;
23688 + pud = pud_offset(pgd, address);
23689 + if (!pud_present(*pud))
23690 + return NULL;
23691 + pmd = pmd_offset(pud, address);
23692 + if (!pmd_present(*pmd))
23693 + return NULL;
23694 + return pmd;
23695 +}
23696 +#endif
23697 +
23698 DEFINE_SPINLOCK(pgd_lock);
23699 LIST_HEAD(pgd_list);
23700
23701 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23702 for (address = VMALLOC_START & PMD_MASK;
23703 address >= TASK_SIZE && address < FIXADDR_TOP;
23704 address += PMD_SIZE) {
23705 +
23706 +#ifdef CONFIG_PAX_PER_CPU_PGD
23707 + unsigned long cpu;
23708 +#else
23709 struct page *page;
23710 +#endif
23711
23712 spin_lock(&pgd_lock);
23713 +
23714 +#ifdef CONFIG_PAX_PER_CPU_PGD
23715 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23716 + pgd_t *pgd = get_cpu_pgd(cpu);
23717 + pmd_t *ret;
23718 +#else
23719 list_for_each_entry(page, &pgd_list, lru) {
23720 + pgd_t *pgd = page_address(page);
23721 spinlock_t *pgt_lock;
23722 pmd_t *ret;
23723
23724 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23725 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23726
23727 spin_lock(pgt_lock);
23728 - ret = vmalloc_sync_one(page_address(page), address);
23729 +#endif
23730 +
23731 + ret = vmalloc_sync_one(pgd, address);
23732 +
23733 +#ifndef CONFIG_PAX_PER_CPU_PGD
23734 spin_unlock(pgt_lock);
23735 +#endif
23736
23737 if (!ret)
23738 break;
23739 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23740 * an interrupt in the middle of a task switch..
23741 */
23742 pgd_paddr = read_cr3();
23743 +
23744 +#ifdef CONFIG_PAX_PER_CPU_PGD
23745 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23746 +#endif
23747 +
23748 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23749 if (!pmd_k)
23750 return -1;
23751 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23752 * happen within a race in page table update. In the later
23753 * case just flush:
23754 */
23755 +
23756 +#ifdef CONFIG_PAX_PER_CPU_PGD
23757 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23758 + pgd = pgd_offset_cpu(smp_processor_id(), address);
23759 +#else
23760 pgd = pgd_offset(current->active_mm, address);
23761 +#endif
23762 +
23763 pgd_ref = pgd_offset_k(address);
23764 if (pgd_none(*pgd_ref))
23765 return -1;
23766 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23767 static int is_errata100(struct pt_regs *regs, unsigned long address)
23768 {
23769 #ifdef CONFIG_X86_64
23770 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23771 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23772 return 1;
23773 #endif
23774 return 0;
23775 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23776 }
23777
23778 static const char nx_warning[] = KERN_CRIT
23779 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23780 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23781
23782 static void
23783 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23784 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23785 if (!oops_may_print())
23786 return;
23787
23788 - if (error_code & PF_INSTR) {
23789 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23790 unsigned int level;
23791
23792 pte_t *pte = lookup_address(address, &level);
23793
23794 if (pte && pte_present(*pte) && !pte_exec(*pte))
23795 - printk(nx_warning, current_uid());
23796 + printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
23797 }
23798
23799 +#ifdef CONFIG_PAX_KERNEXEC
23800 + if (init_mm.start_code <= address && address < init_mm.end_code) {
23801 + if (current->signal->curr_ip)
23802 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23803 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23804 + else
23805 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23806 + current->comm, task_pid_nr(current), current_uid(), current_euid());
23807 + }
23808 +#endif
23809 +
23810 printk(KERN_ALERT "BUG: unable to handle kernel ");
23811 if (address < PAGE_SIZE)
23812 printk(KERN_CONT "NULL pointer dereference");
23813 @@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23814 }
23815 #endif
23816
23817 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23818 + if (pax_is_fetch_fault(regs, error_code, address)) {
23819 +
23820 +#ifdef CONFIG_PAX_EMUTRAMP
23821 + switch (pax_handle_fetch_fault(regs)) {
23822 + case 2:
23823 + return;
23824 + }
23825 +#endif
23826 +
23827 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23828 + do_group_exit(SIGKILL);
23829 + }
23830 +#endif
23831 +
23832 if (unlikely(show_unhandled_signals))
23833 show_signal_msg(regs, error_code, address, tsk);
23834
23835 @@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23836 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23837 printk(KERN_ERR
23838 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23839 - tsk->comm, tsk->pid, address);
23840 + tsk->comm, task_pid_nr(tsk), address);
23841 code = BUS_MCEERR_AR;
23842 }
23843 #endif
23844 @@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23845 return 1;
23846 }
23847
23848 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23849 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23850 +{
23851 + pte_t *pte;
23852 + pmd_t *pmd;
23853 + spinlock_t *ptl;
23854 + unsigned char pte_mask;
23855 +
23856 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23857 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
23858 + return 0;
23859 +
23860 + /* PaX: it's our fault, let's handle it if we can */
23861 +
23862 + /* PaX: take a look at read faults before acquiring any locks */
23863 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23864 + /* instruction fetch attempt from a protected page in user mode */
23865 + up_read(&mm->mmap_sem);
23866 +
23867 +#ifdef CONFIG_PAX_EMUTRAMP
23868 + switch (pax_handle_fetch_fault(regs)) {
23869 + case 2:
23870 + return 1;
23871 + }
23872 +#endif
23873 +
23874 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23875 + do_group_exit(SIGKILL);
23876 + }
23877 +
23878 + pmd = pax_get_pmd(mm, address);
23879 + if (unlikely(!pmd))
23880 + return 0;
23881 +
23882 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23883 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23884 + pte_unmap_unlock(pte, ptl);
23885 + return 0;
23886 + }
23887 +
23888 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23889 + /* write attempt to a protected page in user mode */
23890 + pte_unmap_unlock(pte, ptl);
23891 + return 0;
23892 + }
23893 +
23894 +#ifdef CONFIG_SMP
23895 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23896 +#else
23897 + if (likely(address > get_limit(regs->cs)))
23898 +#endif
23899 + {
23900 + set_pte(pte, pte_mkread(*pte));
23901 + __flush_tlb_one(address);
23902 + pte_unmap_unlock(pte, ptl);
23903 + up_read(&mm->mmap_sem);
23904 + return 1;
23905 + }
23906 +
23907 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23908 +
23909 + /*
23910 + * PaX: fill DTLB with user rights and retry
23911 + */
23912 + __asm__ __volatile__ (
23913 + "orb %2,(%1)\n"
23914 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23915 +/*
23916 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23917 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23918 + * page fault when examined during a TLB load attempt. this is true not only
23919 + * for PTEs holding a non-present entry but also present entries that will
23920 + * raise a page fault (such as those set up by PaX, or the copy-on-write
23921 + * mechanism). in effect it means that we do *not* need to flush the TLBs
23922 + * for our target pages since their PTEs are simply not in the TLBs at all.
23923 +
23924 + * the best thing in omitting it is that we gain around 15-20% speed in the
23925 + * fast path of the page fault handler and can get rid of tracing since we
23926 + * can no longer flush unintended entries.
23927 + */
23928 + "invlpg (%0)\n"
23929 +#endif
23930 + __copyuser_seg"testb $0,(%0)\n"
23931 + "xorb %3,(%1)\n"
23932 + :
23933 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23934 + : "memory", "cc");
23935 + pte_unmap_unlock(pte, ptl);
23936 + up_read(&mm->mmap_sem);
23937 + return 1;
23938 +}
23939 +#endif
23940 +
23941 /*
23942 * Handle a spurious fault caused by a stale TLB entry.
23943 *
23944 @@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23945 static inline int
23946 access_error(unsigned long error_code, struct vm_area_struct *vma)
23947 {
23948 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23949 + return 1;
23950 +
23951 if (error_code & PF_WRITE) {
23952 /* write, present and write, not present: */
23953 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23954 @@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23955 {
23956 struct vm_area_struct *vma;
23957 struct task_struct *tsk;
23958 - unsigned long address;
23959 struct mm_struct *mm;
23960 int fault;
23961 int write = error_code & PF_WRITE;
23962 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23963 (write ? FAULT_FLAG_WRITE : 0);
23964
23965 - tsk = current;
23966 - mm = tsk->mm;
23967 -
23968 /* Get the faulting address: */
23969 - address = read_cr2();
23970 + unsigned long address = read_cr2();
23971 +
23972 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23973 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23974 + if (!search_exception_tables(regs->ip)) {
23975 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23976 + bad_area_nosemaphore(regs, error_code, address);
23977 + return;
23978 + }
23979 + if (address < PAX_USER_SHADOW_BASE) {
23980 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23981 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
23982 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
23983 + } else
23984 + address -= PAX_USER_SHADOW_BASE;
23985 + }
23986 +#endif
23987 +
23988 + tsk = current;
23989 + mm = tsk->mm;
23990
23991 /*
23992 * Detect and handle instructions that would cause a page fault for
23993 @@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23994 * User-mode registers count as a user access even for any
23995 * potential system fault or CPU buglet:
23996 */
23997 - if (user_mode_vm(regs)) {
23998 + if (user_mode(regs)) {
23999 local_irq_enable();
24000 error_code |= PF_USER;
24001 } else {
24002 @@ -1132,6 +1339,11 @@ retry:
24003 might_sleep();
24004 }
24005
24006 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24007 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
24008 + return;
24009 +#endif
24010 +
24011 vma = find_vma(mm, address);
24012 if (unlikely(!vma)) {
24013 bad_area(regs, error_code, address);
24014 @@ -1143,18 +1355,24 @@ retry:
24015 bad_area(regs, error_code, address);
24016 return;
24017 }
24018 - if (error_code & PF_USER) {
24019 - /*
24020 - * Accessing the stack below %sp is always a bug.
24021 - * The large cushion allows instructions like enter
24022 - * and pusha to work. ("enter $65535, $31" pushes
24023 - * 32 pointers and then decrements %sp by 65535.)
24024 - */
24025 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
24026 - bad_area(regs, error_code, address);
24027 - return;
24028 - }
24029 + /*
24030 + * Accessing the stack below %sp is always a bug.
24031 + * The large cushion allows instructions like enter
24032 + * and pusha to work. ("enter $65535, $31" pushes
24033 + * 32 pointers and then decrements %sp by 65535.)
24034 + */
24035 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
24036 + bad_area(regs, error_code, address);
24037 + return;
24038 }
24039 +
24040 +#ifdef CONFIG_PAX_SEGMEXEC
24041 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
24042 + bad_area(regs, error_code, address);
24043 + return;
24044 + }
24045 +#endif
24046 +
24047 if (unlikely(expand_stack(vma, address))) {
24048 bad_area(regs, error_code, address);
24049 return;
24050 @@ -1209,3 +1427,292 @@ good_area:
24051
24052 up_read(&mm->mmap_sem);
24053 }
24054 +
24055 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24056 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
24057 +{
24058 + struct mm_struct *mm = current->mm;
24059 + unsigned long ip = regs->ip;
24060 +
24061 + if (v8086_mode(regs))
24062 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24063 +
24064 +#ifdef CONFIG_PAX_PAGEEXEC
24065 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24066 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24067 + return true;
24068 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24069 + return true;
24070 + return false;
24071 + }
24072 +#endif
24073 +
24074 +#ifdef CONFIG_PAX_SEGMEXEC
24075 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24076 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24077 + return true;
24078 + return false;
24079 + }
24080 +#endif
24081 +
24082 + return false;
24083 +}
24084 +#endif
24085 +
24086 +#ifdef CONFIG_PAX_EMUTRAMP
24087 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24088 +{
24089 + int err;
24090 +
24091 + do { /* PaX: libffi trampoline emulation */
24092 + unsigned char mov, jmp;
24093 + unsigned int addr1, addr2;
24094 +
24095 +#ifdef CONFIG_X86_64
24096 + if ((regs->ip + 9) >> 32)
24097 + break;
24098 +#endif
24099 +
24100 + err = get_user(mov, (unsigned char __user *)regs->ip);
24101 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24102 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24103 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24104 +
24105 + if (err)
24106 + break;
24107 +
24108 + if (mov == 0xB8 && jmp == 0xE9) {
24109 + regs->ax = addr1;
24110 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24111 + return 2;
24112 + }
24113 + } while (0);
24114 +
24115 + do { /* PaX: gcc trampoline emulation #1 */
24116 + unsigned char mov1, mov2;
24117 + unsigned short jmp;
24118 + unsigned int addr1, addr2;
24119 +
24120 +#ifdef CONFIG_X86_64
24121 + if ((regs->ip + 11) >> 32)
24122 + break;
24123 +#endif
24124 +
24125 + err = get_user(mov1, (unsigned char __user *)regs->ip);
24126 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24127 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24128 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24129 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24130 +
24131 + if (err)
24132 + break;
24133 +
24134 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24135 + regs->cx = addr1;
24136 + regs->ax = addr2;
24137 + regs->ip = addr2;
24138 + return 2;
24139 + }
24140 + } while (0);
24141 +
24142 + do { /* PaX: gcc trampoline emulation #2 */
24143 + unsigned char mov, jmp;
24144 + unsigned int addr1, addr2;
24145 +
24146 +#ifdef CONFIG_X86_64
24147 + if ((regs->ip + 9) >> 32)
24148 + break;
24149 +#endif
24150 +
24151 + err = get_user(mov, (unsigned char __user *)regs->ip);
24152 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24153 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24154 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24155 +
24156 + if (err)
24157 + break;
24158 +
24159 + if (mov == 0xB9 && jmp == 0xE9) {
24160 + regs->cx = addr1;
24161 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24162 + return 2;
24163 + }
24164 + } while (0);
24165 +
24166 + return 1; /* PaX in action */
24167 +}
24168 +
24169 +#ifdef CONFIG_X86_64
24170 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24171 +{
24172 + int err;
24173 +
24174 + do { /* PaX: libffi trampoline emulation */
24175 + unsigned short mov1, mov2, jmp1;
24176 + unsigned char stcclc, jmp2;
24177 + unsigned long addr1, addr2;
24178 +
24179 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24180 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24181 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24182 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24183 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24184 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24185 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24186 +
24187 + if (err)
24188 + break;
24189 +
24190 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24191 + regs->r11 = addr1;
24192 + regs->r10 = addr2;
24193 + if (stcclc == 0xF8)
24194 + regs->flags &= ~X86_EFLAGS_CF;
24195 + else
24196 + regs->flags |= X86_EFLAGS_CF;
24197 + regs->ip = addr1;
24198 + return 2;
24199 + }
24200 + } while (0);
24201 +
24202 + do { /* PaX: gcc trampoline emulation #1 */
24203 + unsigned short mov1, mov2, jmp1;
24204 + unsigned char jmp2;
24205 + unsigned int addr1;
24206 + unsigned long addr2;
24207 +
24208 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24209 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24210 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24211 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24212 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24213 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24214 +
24215 + if (err)
24216 + break;
24217 +
24218 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24219 + regs->r11 = addr1;
24220 + regs->r10 = addr2;
24221 + regs->ip = addr1;
24222 + return 2;
24223 + }
24224 + } while (0);
24225 +
24226 + do { /* PaX: gcc trampoline emulation #2 */
24227 + unsigned short mov1, mov2, jmp1;
24228 + unsigned char jmp2;
24229 + unsigned long addr1, addr2;
24230 +
24231 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24232 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24233 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24234 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24235 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24236 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24237 +
24238 + if (err)
24239 + break;
24240 +
24241 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24242 + regs->r11 = addr1;
24243 + regs->r10 = addr2;
24244 + regs->ip = addr1;
24245 + return 2;
24246 + }
24247 + } while (0);
24248 +
24249 + return 1; /* PaX in action */
24250 +}
24251 +#endif
24252 +
24253 +/*
24254 + * PaX: decide what to do with offenders (regs->ip = fault address)
24255 + *
24256 + * returns 1 when task should be killed
24257 + * 2 when gcc trampoline was detected
24258 + */
24259 +static int pax_handle_fetch_fault(struct pt_regs *regs)
24260 +{
24261 + if (v8086_mode(regs))
24262 + return 1;
24263 +
24264 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24265 + return 1;
24266 +
24267 +#ifdef CONFIG_X86_32
24268 + return pax_handle_fetch_fault_32(regs);
24269 +#else
24270 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24271 + return pax_handle_fetch_fault_32(regs);
24272 + else
24273 + return pax_handle_fetch_fault_64(regs);
24274 +#endif
24275 +}
24276 +#endif
24277 +
24278 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24279 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24280 +{
24281 + long i;
24282 +
24283 + printk(KERN_ERR "PAX: bytes at PC: ");
24284 + for (i = 0; i < 20; i++) {
24285 + unsigned char c;
24286 + if (get_user(c, (unsigned char __force_user *)pc+i))
24287 + printk(KERN_CONT "?? ");
24288 + else
24289 + printk(KERN_CONT "%02x ", c);
24290 + }
24291 + printk("\n");
24292 +
24293 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24294 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
24295 + unsigned long c;
24296 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
24297 +#ifdef CONFIG_X86_32
24298 + printk(KERN_CONT "???????? ");
24299 +#else
24300 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24301 + printk(KERN_CONT "???????? ???????? ");
24302 + else
24303 + printk(KERN_CONT "???????????????? ");
24304 +#endif
24305 + } else {
24306 +#ifdef CONFIG_X86_64
24307 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24308 + printk(KERN_CONT "%08x ", (unsigned int)c);
24309 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24310 + } else
24311 +#endif
24312 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24313 + }
24314 + }
24315 + printk("\n");
24316 +}
24317 +#endif
24318 +
24319 +/**
24320 + * probe_kernel_write(): safely attempt to write to a location
24321 + * @dst: address to write to
24322 + * @src: pointer to the data that shall be written
24323 + * @size: size of the data chunk
24324 + *
24325 + * Safely write to address @dst from the buffer at @src. If a kernel fault
24326 + * happens, handle that and return -EFAULT.
24327 + */
24328 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24329 +{
24330 + long ret;
24331 + mm_segment_t old_fs = get_fs();
24332 +
24333 + set_fs(KERNEL_DS);
24334 + pagefault_disable();
24335 + pax_open_kernel();
24336 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24337 + pax_close_kernel();
24338 + pagefault_enable();
24339 + set_fs(old_fs);
24340 +
24341 + return ret ? -EFAULT : 0;
24342 +}
24343 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24344 index dd74e46..7d26398 100644
24345 --- a/arch/x86/mm/gup.c
24346 +++ b/arch/x86/mm/gup.c
24347 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24348 addr = start;
24349 len = (unsigned long) nr_pages << PAGE_SHIFT;
24350 end = start + len;
24351 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24352 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24353 (void __user *)start, len)))
24354 return 0;
24355
24356 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24357 index 6f31ee5..8ee4164 100644
24358 --- a/arch/x86/mm/highmem_32.c
24359 +++ b/arch/x86/mm/highmem_32.c
24360 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24361 idx = type + KM_TYPE_NR*smp_processor_id();
24362 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24363 BUG_ON(!pte_none(*(kmap_pte-idx)));
24364 +
24365 + pax_open_kernel();
24366 set_pte(kmap_pte-idx, mk_pte(page, prot));
24367 + pax_close_kernel();
24368 +
24369 arch_flush_lazy_mmu_mode();
24370
24371 return (void *)vaddr;
24372 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24373 index f6679a7..8f795a3 100644
24374 --- a/arch/x86/mm/hugetlbpage.c
24375 +++ b/arch/x86/mm/hugetlbpage.c
24376 @@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24377 struct hstate *h = hstate_file(file);
24378 struct mm_struct *mm = current->mm;
24379 struct vm_area_struct *vma;
24380 - unsigned long start_addr;
24381 + unsigned long start_addr, pax_task_size = TASK_SIZE;
24382 +
24383 +#ifdef CONFIG_PAX_SEGMEXEC
24384 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24385 + pax_task_size = SEGMEXEC_TASK_SIZE;
24386 +#endif
24387 +
24388 + pax_task_size -= PAGE_SIZE;
24389
24390 if (len > mm->cached_hole_size) {
24391 - start_addr = mm->free_area_cache;
24392 + start_addr = mm->free_area_cache;
24393 } else {
24394 - start_addr = TASK_UNMAPPED_BASE;
24395 - mm->cached_hole_size = 0;
24396 + start_addr = mm->mmap_base;
24397 + mm->cached_hole_size = 0;
24398 }
24399
24400 full_search:
24401 @@ -280,26 +287,27 @@ full_search:
24402
24403 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24404 /* At this point: (!vma || addr < vma->vm_end). */
24405 - if (TASK_SIZE - len < addr) {
24406 + if (pax_task_size - len < addr) {
24407 /*
24408 * Start a new search - just in case we missed
24409 * some holes.
24410 */
24411 - if (start_addr != TASK_UNMAPPED_BASE) {
24412 - start_addr = TASK_UNMAPPED_BASE;
24413 + if (start_addr != mm->mmap_base) {
24414 + start_addr = mm->mmap_base;
24415 mm->cached_hole_size = 0;
24416 goto full_search;
24417 }
24418 return -ENOMEM;
24419 }
24420 - if (!vma || addr + len <= vma->vm_start) {
24421 - mm->free_area_cache = addr + len;
24422 - return addr;
24423 - }
24424 + if (check_heap_stack_gap(vma, addr, len))
24425 + break;
24426 if (addr + mm->cached_hole_size < vma->vm_start)
24427 mm->cached_hole_size = vma->vm_start - addr;
24428 addr = ALIGN(vma->vm_end, huge_page_size(h));
24429 }
24430 +
24431 + mm->free_area_cache = addr + len;
24432 + return addr;
24433 }
24434
24435 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24436 @@ -310,9 +318,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24437 struct mm_struct *mm = current->mm;
24438 struct vm_area_struct *vma;
24439 unsigned long base = mm->mmap_base;
24440 - unsigned long addr = addr0;
24441 + unsigned long addr;
24442 unsigned long largest_hole = mm->cached_hole_size;
24443 - unsigned long start_addr;
24444
24445 /* don't allow allocations above current base */
24446 if (mm->free_area_cache > base)
24447 @@ -322,16 +329,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24448 largest_hole = 0;
24449 mm->free_area_cache = base;
24450 }
24451 -try_again:
24452 - start_addr = mm->free_area_cache;
24453
24454 /* make sure it can fit in the remaining address space */
24455 if (mm->free_area_cache < len)
24456 goto fail;
24457
24458 /* either no address requested or can't fit in requested address hole */
24459 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
24460 + addr = mm->free_area_cache - len;
24461 do {
24462 + addr &= huge_page_mask(h);
24463 /*
24464 * Lookup failure means no vma is above this address,
24465 * i.e. return with success:
24466 @@ -340,10 +346,10 @@ try_again:
24467 if (!vma)
24468 return addr;
24469
24470 - if (addr + len <= vma->vm_start) {
24471 + if (check_heap_stack_gap(vma, addr, len)) {
24472 /* remember the address as a hint for next time */
24473 - mm->cached_hole_size = largest_hole;
24474 - return (mm->free_area_cache = addr);
24475 + mm->cached_hole_size = largest_hole;
24476 + return (mm->free_area_cache = addr);
24477 } else if (mm->free_area_cache == vma->vm_end) {
24478 /* pull free_area_cache down to the first hole */
24479 mm->free_area_cache = vma->vm_start;
24480 @@ -352,29 +358,34 @@ try_again:
24481
24482 /* remember the largest hole we saw so far */
24483 if (addr + largest_hole < vma->vm_start)
24484 - largest_hole = vma->vm_start - addr;
24485 + largest_hole = vma->vm_start - addr;
24486
24487 /* try just below the current vma->vm_start */
24488 - addr = (vma->vm_start - len) & huge_page_mask(h);
24489 - } while (len <= vma->vm_start);
24490 + addr = skip_heap_stack_gap(vma, len);
24491 + } while (!IS_ERR_VALUE(addr));
24492
24493 fail:
24494 /*
24495 - * if hint left us with no space for the requested
24496 - * mapping then try again:
24497 - */
24498 - if (start_addr != base) {
24499 - mm->free_area_cache = base;
24500 - largest_hole = 0;
24501 - goto try_again;
24502 - }
24503 - /*
24504 * A failed mmap() very likely causes application failure,
24505 * so fall back to the bottom-up function here. This scenario
24506 * can happen with large stack limits and large mmap()
24507 * allocations.
24508 */
24509 - mm->free_area_cache = TASK_UNMAPPED_BASE;
24510 +
24511 +#ifdef CONFIG_PAX_SEGMEXEC
24512 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24513 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24514 + else
24515 +#endif
24516 +
24517 + mm->mmap_base = TASK_UNMAPPED_BASE;
24518 +
24519 +#ifdef CONFIG_PAX_RANDMMAP
24520 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24521 + mm->mmap_base += mm->delta_mmap;
24522 +#endif
24523 +
24524 + mm->free_area_cache = mm->mmap_base;
24525 mm->cached_hole_size = ~0UL;
24526 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24527 len, pgoff, flags);
24528 @@ -382,6 +393,7 @@ fail:
24529 /*
24530 * Restore the topdown base:
24531 */
24532 + mm->mmap_base = base;
24533 mm->free_area_cache = base;
24534 mm->cached_hole_size = ~0UL;
24535
24536 @@ -395,10 +407,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24537 struct hstate *h = hstate_file(file);
24538 struct mm_struct *mm = current->mm;
24539 struct vm_area_struct *vma;
24540 + unsigned long pax_task_size = TASK_SIZE;
24541
24542 if (len & ~huge_page_mask(h))
24543 return -EINVAL;
24544 - if (len > TASK_SIZE)
24545 +
24546 +#ifdef CONFIG_PAX_SEGMEXEC
24547 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24548 + pax_task_size = SEGMEXEC_TASK_SIZE;
24549 +#endif
24550 +
24551 + pax_task_size -= PAGE_SIZE;
24552 +
24553 + if (len > pax_task_size)
24554 return -ENOMEM;
24555
24556 if (flags & MAP_FIXED) {
24557 @@ -410,8 +431,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24558 if (addr) {
24559 addr = ALIGN(addr, huge_page_size(h));
24560 vma = find_vma(mm, addr);
24561 - if (TASK_SIZE - len >= addr &&
24562 - (!vma || addr + len <= vma->vm_start))
24563 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24564 return addr;
24565 }
24566 if (mm->get_unmapped_area == arch_get_unmapped_area)
24567 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24568 index 4f0cec7..00976ce 100644
24569 --- a/arch/x86/mm/init.c
24570 +++ b/arch/x86/mm/init.c
24571 @@ -16,6 +16,8 @@
24572 #include <asm/tlb.h>
24573 #include <asm/proto.h>
24574 #include <asm/dma.h> /* for MAX_DMA_PFN */
24575 +#include <asm/desc.h>
24576 +#include <asm/bios_ebda.h>
24577
24578 unsigned long __initdata pgt_buf_start;
24579 unsigned long __meminitdata pgt_buf_end;
24580 @@ -32,7 +34,7 @@ int direct_gbpages
24581 static void __init find_early_table_space(unsigned long end, int use_pse,
24582 int use_gbpages)
24583 {
24584 - unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
24585 + unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
24586 phys_addr_t base;
24587
24588 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
24589 @@ -311,10 +313,37 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24590 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24591 * mmio resources as well as potential bios/acpi data regions.
24592 */
24593 +
24594 +#ifdef CONFIG_GRKERNSEC_KMEM
24595 +static unsigned int ebda_start __read_only;
24596 +static unsigned int ebda_end __read_only;
24597 +#endif
24598 +
24599 int devmem_is_allowed(unsigned long pagenr)
24600 {
24601 +#ifdef CONFIG_GRKERNSEC_KMEM
24602 + /* allow BDA */
24603 + if (!pagenr)
24604 + return 1;
24605 + /* allow EBDA */
24606 + if (pagenr >= ebda_start && pagenr < ebda_end)
24607 + return 1;
24608 +#else
24609 + if (!pagenr)
24610 + return 1;
24611 +#ifdef CONFIG_VM86
24612 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24613 + return 1;
24614 +#endif
24615 +#endif
24616 +
24617 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24618 + return 1;
24619 +#ifdef CONFIG_GRKERNSEC_KMEM
24620 + /* throw out everything else below 1MB */
24621 if (pagenr <= 256)
24622 - return 1;
24623 + return 0;
24624 +#endif
24625 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24626 return 0;
24627 if (!page_is_ram(pagenr))
24628 @@ -371,8 +400,116 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24629 #endif
24630 }
24631
24632 +#ifdef CONFIG_GRKERNSEC_KMEM
24633 +static inline void gr_init_ebda(void)
24634 +{
24635 + unsigned int ebda_addr;
24636 + unsigned int ebda_size = 0;
24637 +
24638 + ebda_addr = get_bios_ebda();
24639 + if (ebda_addr) {
24640 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24641 + ebda_size <<= 10;
24642 + }
24643 + if (ebda_addr && ebda_size) {
24644 + ebda_start = ebda_addr >> PAGE_SHIFT;
24645 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24646 + } else {
24647 + ebda_start = 0x9f000 >> PAGE_SHIFT;
24648 + ebda_end = 0xa0000 >> PAGE_SHIFT;
24649 + }
24650 +}
24651 +#else
24652 +static inline void gr_init_ebda(void) { }
24653 +#endif
24654 +
24655 void free_initmem(void)
24656 {
24657 +#ifdef CONFIG_PAX_KERNEXEC
24658 +#ifdef CONFIG_X86_32
24659 + /* PaX: limit KERNEL_CS to actual size */
24660 + unsigned long addr, limit;
24661 + struct desc_struct d;
24662 + int cpu;
24663 +#else
24664 + pgd_t *pgd;
24665 + pud_t *pud;
24666 + pmd_t *pmd;
24667 + unsigned long addr, end;
24668 +#endif
24669 +#endif
24670 +
24671 + gr_init_ebda();
24672 +
24673 +#ifdef CONFIG_PAX_KERNEXEC
24674 +#ifdef CONFIG_X86_32
24675 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24676 + limit = (limit - 1UL) >> PAGE_SHIFT;
24677 +
24678 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24679 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24680 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24681 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24682 + }
24683 +
24684 + /* PaX: make KERNEL_CS read-only */
24685 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24686 + if (!paravirt_enabled())
24687 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24688 +/*
24689 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24690 + pgd = pgd_offset_k(addr);
24691 + pud = pud_offset(pgd, addr);
24692 + pmd = pmd_offset(pud, addr);
24693 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24694 + }
24695 +*/
24696 +#ifdef CONFIG_X86_PAE
24697 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24698 +/*
24699 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24700 + pgd = pgd_offset_k(addr);
24701 + pud = pud_offset(pgd, addr);
24702 + pmd = pmd_offset(pud, addr);
24703 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24704 + }
24705 +*/
24706 +#endif
24707 +
24708 +#ifdef CONFIG_MODULES
24709 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24710 +#endif
24711 +
24712 +#else
24713 + /* PaX: make kernel code/rodata read-only, rest non-executable */
24714 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24715 + pgd = pgd_offset_k(addr);
24716 + pud = pud_offset(pgd, addr);
24717 + pmd = pmd_offset(pud, addr);
24718 + if (!pmd_present(*pmd))
24719 + continue;
24720 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24721 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24722 + else
24723 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24724 + }
24725 +
24726 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24727 + end = addr + KERNEL_IMAGE_SIZE;
24728 + for (; addr < end; addr += PMD_SIZE) {
24729 + pgd = pgd_offset_k(addr);
24730 + pud = pud_offset(pgd, addr);
24731 + pmd = pmd_offset(pud, addr);
24732 + if (!pmd_present(*pmd))
24733 + continue;
24734 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24735 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24736 + }
24737 +#endif
24738 +
24739 + flush_tlb_all();
24740 +#endif
24741 +
24742 free_init_pages("unused kernel memory",
24743 (unsigned long)(&__init_begin),
24744 (unsigned long)(&__init_end));
24745 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24746 index 575d86f..4987469 100644
24747 --- a/arch/x86/mm/init_32.c
24748 +++ b/arch/x86/mm/init_32.c
24749 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24750 }
24751
24752 /*
24753 - * Creates a middle page table and puts a pointer to it in the
24754 - * given global directory entry. This only returns the gd entry
24755 - * in non-PAE compilation mode, since the middle layer is folded.
24756 - */
24757 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24758 -{
24759 - pud_t *pud;
24760 - pmd_t *pmd_table;
24761 -
24762 -#ifdef CONFIG_X86_PAE
24763 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24764 - if (after_bootmem)
24765 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24766 - else
24767 - pmd_table = (pmd_t *)alloc_low_page();
24768 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24769 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24770 - pud = pud_offset(pgd, 0);
24771 - BUG_ON(pmd_table != pmd_offset(pud, 0));
24772 -
24773 - return pmd_table;
24774 - }
24775 -#endif
24776 - pud = pud_offset(pgd, 0);
24777 - pmd_table = pmd_offset(pud, 0);
24778 -
24779 - return pmd_table;
24780 -}
24781 -
24782 -/*
24783 * Create a page table and place a pointer to it in a middle page
24784 * directory entry:
24785 */
24786 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24787 page_table = (pte_t *)alloc_low_page();
24788
24789 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24790 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24791 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24792 +#else
24793 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24794 +#endif
24795 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24796 }
24797
24798 return pte_offset_kernel(pmd, 0);
24799 }
24800
24801 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
24802 +{
24803 + pud_t *pud;
24804 + pmd_t *pmd_table;
24805 +
24806 + pud = pud_offset(pgd, 0);
24807 + pmd_table = pmd_offset(pud, 0);
24808 +
24809 + return pmd_table;
24810 +}
24811 +
24812 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24813 {
24814 int pgd_idx = pgd_index(vaddr);
24815 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24816 int pgd_idx, pmd_idx;
24817 unsigned long vaddr;
24818 pgd_t *pgd;
24819 + pud_t *pud;
24820 pmd_t *pmd;
24821 pte_t *pte = NULL;
24822
24823 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24824 pgd = pgd_base + pgd_idx;
24825
24826 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24827 - pmd = one_md_table_init(pgd);
24828 - pmd = pmd + pmd_index(vaddr);
24829 + pud = pud_offset(pgd, vaddr);
24830 + pmd = pmd_offset(pud, vaddr);
24831 +
24832 +#ifdef CONFIG_X86_PAE
24833 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24834 +#endif
24835 +
24836 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24837 pmd++, pmd_idx++) {
24838 pte = page_table_kmap_check(one_page_table_init(pmd),
24839 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24840 }
24841 }
24842
24843 -static inline int is_kernel_text(unsigned long addr)
24844 +static inline int is_kernel_text(unsigned long start, unsigned long end)
24845 {
24846 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24847 - return 1;
24848 - return 0;
24849 + if ((start > ktla_ktva((unsigned long)_etext) ||
24850 + end <= ktla_ktva((unsigned long)_stext)) &&
24851 + (start > ktla_ktva((unsigned long)_einittext) ||
24852 + end <= ktla_ktva((unsigned long)_sinittext)) &&
24853 +
24854 +#ifdef CONFIG_ACPI_SLEEP
24855 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24856 +#endif
24857 +
24858 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24859 + return 0;
24860 + return 1;
24861 }
24862
24863 /*
24864 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24865 unsigned long last_map_addr = end;
24866 unsigned long start_pfn, end_pfn;
24867 pgd_t *pgd_base = swapper_pg_dir;
24868 - int pgd_idx, pmd_idx, pte_ofs;
24869 + unsigned int pgd_idx, pmd_idx, pte_ofs;
24870 unsigned long pfn;
24871 pgd_t *pgd;
24872 + pud_t *pud;
24873 pmd_t *pmd;
24874 pte_t *pte;
24875 unsigned pages_2m, pages_4k;
24876 @@ -280,8 +281,13 @@ repeat:
24877 pfn = start_pfn;
24878 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24879 pgd = pgd_base + pgd_idx;
24880 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24881 - pmd = one_md_table_init(pgd);
24882 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24883 + pud = pud_offset(pgd, 0);
24884 + pmd = pmd_offset(pud, 0);
24885 +
24886 +#ifdef CONFIG_X86_PAE
24887 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24888 +#endif
24889
24890 if (pfn >= end_pfn)
24891 continue;
24892 @@ -293,14 +299,13 @@ repeat:
24893 #endif
24894 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24895 pmd++, pmd_idx++) {
24896 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24897 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24898
24899 /*
24900 * Map with big pages if possible, otherwise
24901 * create normal page tables:
24902 */
24903 if (use_pse) {
24904 - unsigned int addr2;
24905 pgprot_t prot = PAGE_KERNEL_LARGE;
24906 /*
24907 * first pass will use the same initial
24908 @@ -310,11 +315,7 @@ repeat:
24909 __pgprot(PTE_IDENT_ATTR |
24910 _PAGE_PSE);
24911
24912 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24913 - PAGE_OFFSET + PAGE_SIZE-1;
24914 -
24915 - if (is_kernel_text(addr) ||
24916 - is_kernel_text(addr2))
24917 + if (is_kernel_text(address, address + PMD_SIZE))
24918 prot = PAGE_KERNEL_LARGE_EXEC;
24919
24920 pages_2m++;
24921 @@ -331,7 +332,7 @@ repeat:
24922 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24923 pte += pte_ofs;
24924 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24925 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24926 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24927 pgprot_t prot = PAGE_KERNEL;
24928 /*
24929 * first pass will use the same initial
24930 @@ -339,7 +340,7 @@ repeat:
24931 */
24932 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24933
24934 - if (is_kernel_text(addr))
24935 + if (is_kernel_text(address, address + PAGE_SIZE))
24936 prot = PAGE_KERNEL_EXEC;
24937
24938 pages_4k++;
24939 @@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24940
24941 pud = pud_offset(pgd, va);
24942 pmd = pmd_offset(pud, va);
24943 - if (!pmd_present(*pmd))
24944 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
24945 break;
24946
24947 pte = pte_offset_kernel(pmd, va);
24948 @@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
24949
24950 static void __init pagetable_init(void)
24951 {
24952 - pgd_t *pgd_base = swapper_pg_dir;
24953 -
24954 - permanent_kmaps_init(pgd_base);
24955 + permanent_kmaps_init(swapper_pg_dir);
24956 }
24957
24958 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24959 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24960 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24961
24962 /* user-defined highmem size */
24963 @@ -734,6 +733,12 @@ void __init mem_init(void)
24964
24965 pci_iommu_alloc();
24966
24967 +#ifdef CONFIG_PAX_PER_CPU_PGD
24968 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24969 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24970 + KERNEL_PGD_PTRS);
24971 +#endif
24972 +
24973 #ifdef CONFIG_FLATMEM
24974 BUG_ON(!mem_map);
24975 #endif
24976 @@ -760,7 +765,7 @@ void __init mem_init(void)
24977 reservedpages++;
24978
24979 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24980 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
24981 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
24982 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
24983
24984 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
24985 @@ -801,10 +806,10 @@ void __init mem_init(void)
24986 ((unsigned long)&__init_end -
24987 (unsigned long)&__init_begin) >> 10,
24988
24989 - (unsigned long)&_etext, (unsigned long)&_edata,
24990 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
24991 + (unsigned long)&_sdata, (unsigned long)&_edata,
24992 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
24993
24994 - (unsigned long)&_text, (unsigned long)&_etext,
24995 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
24996 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
24997
24998 /*
24999 @@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
25000 if (!kernel_set_to_readonly)
25001 return;
25002
25003 + start = ktla_ktva(start);
25004 pr_debug("Set kernel text: %lx - %lx for read write\n",
25005 start, start+size);
25006
25007 @@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
25008 if (!kernel_set_to_readonly)
25009 return;
25010
25011 + start = ktla_ktva(start);
25012 pr_debug("Set kernel text: %lx - %lx for read only\n",
25013 start, start+size);
25014
25015 @@ -924,6 +931,7 @@ void mark_rodata_ro(void)
25016 unsigned long start = PFN_ALIGN(_text);
25017 unsigned long size = PFN_ALIGN(_etext) - start;
25018
25019 + start = ktla_ktva(start);
25020 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
25021 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
25022 size >> 10);
25023 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
25024 index fc18be0..e539653 100644
25025 --- a/arch/x86/mm/init_64.c
25026 +++ b/arch/x86/mm/init_64.c
25027 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
25028 * around without checking the pgd every time.
25029 */
25030
25031 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
25032 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
25033 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25034
25035 int force_personality32;
25036 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25037
25038 for (address = start; address <= end; address += PGDIR_SIZE) {
25039 const pgd_t *pgd_ref = pgd_offset_k(address);
25040 +
25041 +#ifdef CONFIG_PAX_PER_CPU_PGD
25042 + unsigned long cpu;
25043 +#else
25044 struct page *page;
25045 +#endif
25046
25047 if (pgd_none(*pgd_ref))
25048 continue;
25049
25050 spin_lock(&pgd_lock);
25051 +
25052 +#ifdef CONFIG_PAX_PER_CPU_PGD
25053 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25054 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
25055 +#else
25056 list_for_each_entry(page, &pgd_list, lru) {
25057 pgd_t *pgd;
25058 spinlock_t *pgt_lock;
25059 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25060 /* the pgt_lock only for Xen */
25061 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25062 spin_lock(pgt_lock);
25063 +#endif
25064
25065 if (pgd_none(*pgd))
25066 set_pgd(pgd, *pgd_ref);
25067 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25068 BUG_ON(pgd_page_vaddr(*pgd)
25069 != pgd_page_vaddr(*pgd_ref));
25070
25071 +#ifndef CONFIG_PAX_PER_CPU_PGD
25072 spin_unlock(pgt_lock);
25073 +#endif
25074 +
25075 }
25076 spin_unlock(&pgd_lock);
25077 }
25078 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
25079 {
25080 if (pgd_none(*pgd)) {
25081 pud_t *pud = (pud_t *)spp_getpage();
25082 - pgd_populate(&init_mm, pgd, pud);
25083 + pgd_populate_kernel(&init_mm, pgd, pud);
25084 if (pud != pud_offset(pgd, 0))
25085 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
25086 pud, pud_offset(pgd, 0));
25087 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
25088 {
25089 if (pud_none(*pud)) {
25090 pmd_t *pmd = (pmd_t *) spp_getpage();
25091 - pud_populate(&init_mm, pud, pmd);
25092 + pud_populate_kernel(&init_mm, pud, pmd);
25093 if (pmd != pmd_offset(pud, 0))
25094 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
25095 pmd, pmd_offset(pud, 0));
25096 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25097 pmd = fill_pmd(pud, vaddr);
25098 pte = fill_pte(pmd, vaddr);
25099
25100 + pax_open_kernel();
25101 set_pte(pte, new_pte);
25102 + pax_close_kernel();
25103
25104 /*
25105 * It's enough to flush this one mapping.
25106 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25107 pgd = pgd_offset_k((unsigned long)__va(phys));
25108 if (pgd_none(*pgd)) {
25109 pud = (pud_t *) spp_getpage();
25110 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25111 - _PAGE_USER));
25112 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25113 }
25114 pud = pud_offset(pgd, (unsigned long)__va(phys));
25115 if (pud_none(*pud)) {
25116 pmd = (pmd_t *) spp_getpage();
25117 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25118 - _PAGE_USER));
25119 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25120 }
25121 pmd = pmd_offset(pud, phys);
25122 BUG_ON(!pmd_none(*pmd));
25123 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
25124 if (pfn >= pgt_buf_top)
25125 panic("alloc_low_page: ran out of memory");
25126
25127 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25128 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25129 clear_page(adr);
25130 *phys = pfn * PAGE_SIZE;
25131 return adr;
25132 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
25133
25134 phys = __pa(virt);
25135 left = phys & (PAGE_SIZE - 1);
25136 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25137 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25138 adr = (void *)(((unsigned long)adr) | left);
25139
25140 return adr;
25141 @@ -545,7 +559,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25142 unmap_low_page(pmd);
25143
25144 spin_lock(&init_mm.page_table_lock);
25145 - pud_populate(&init_mm, pud, __va(pmd_phys));
25146 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25147 spin_unlock(&init_mm.page_table_lock);
25148 }
25149 __flush_tlb_all();
25150 @@ -591,7 +605,7 @@ kernel_physical_mapping_init(unsigned long start,
25151 unmap_low_page(pud);
25152
25153 spin_lock(&init_mm.page_table_lock);
25154 - pgd_populate(&init_mm, pgd, __va(pud_phys));
25155 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25156 spin_unlock(&init_mm.page_table_lock);
25157 pgd_changed = true;
25158 }
25159 @@ -683,6 +697,12 @@ void __init mem_init(void)
25160
25161 pci_iommu_alloc();
25162
25163 +#ifdef CONFIG_PAX_PER_CPU_PGD
25164 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25165 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25166 + KERNEL_PGD_PTRS);
25167 +#endif
25168 +
25169 /* clear_bss() already clear the empty_zero_page */
25170
25171 reservedpages = 0;
25172 @@ -843,8 +863,8 @@ int kern_addr_valid(unsigned long addr)
25173 static struct vm_area_struct gate_vma = {
25174 .vm_start = VSYSCALL_START,
25175 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25176 - .vm_page_prot = PAGE_READONLY_EXEC,
25177 - .vm_flags = VM_READ | VM_EXEC
25178 + .vm_page_prot = PAGE_READONLY,
25179 + .vm_flags = VM_READ
25180 };
25181
25182 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25183 @@ -878,7 +898,7 @@ int in_gate_area_no_mm(unsigned long addr)
25184
25185 const char *arch_vma_name(struct vm_area_struct *vma)
25186 {
25187 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25188 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25189 return "[vdso]";
25190 if (vma == &gate_vma)
25191 return "[vsyscall]";
25192 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25193 index 7b179b4..6bd1777 100644
25194 --- a/arch/x86/mm/iomap_32.c
25195 +++ b/arch/x86/mm/iomap_32.c
25196 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25197 type = kmap_atomic_idx_push();
25198 idx = type + KM_TYPE_NR * smp_processor_id();
25199 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25200 +
25201 + pax_open_kernel();
25202 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25203 + pax_close_kernel();
25204 +
25205 arch_flush_lazy_mmu_mode();
25206
25207 return (void *)vaddr;
25208 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25209 index be1ef57..55f0160 100644
25210 --- a/arch/x86/mm/ioremap.c
25211 +++ b/arch/x86/mm/ioremap.c
25212 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25213 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25214 int is_ram = page_is_ram(pfn);
25215
25216 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25217 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25218 return NULL;
25219 WARN_ON_ONCE(is_ram);
25220 }
25221 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25222
25223 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25224 if (page_is_ram(start >> PAGE_SHIFT))
25225 +#ifdef CONFIG_HIGHMEM
25226 + if ((start >> PAGE_SHIFT) < max_low_pfn)
25227 +#endif
25228 return __va(phys);
25229
25230 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25231 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25232 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25233
25234 static __initdata int after_paging_init;
25235 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25236 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25237
25238 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25239 {
25240 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25241 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25242
25243 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25244 - memset(bm_pte, 0, sizeof(bm_pte));
25245 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
25246 + pmd_populate_user(&init_mm, pmd, bm_pte);
25247
25248 /*
25249 * The boot-ioremap range spans multiple pmds, for which
25250 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25251 index d87dd6d..bf3fa66 100644
25252 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
25253 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25254 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25255 * memory (e.g. tracked pages)? For now, we need this to avoid
25256 * invoking kmemcheck for PnP BIOS calls.
25257 */
25258 - if (regs->flags & X86_VM_MASK)
25259 + if (v8086_mode(regs))
25260 return false;
25261 - if (regs->cs != __KERNEL_CS)
25262 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25263 return false;
25264
25265 pte = kmemcheck_pte_lookup(address);
25266 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25267 index 845df68..1d8d29f 100644
25268 --- a/arch/x86/mm/mmap.c
25269 +++ b/arch/x86/mm/mmap.c
25270 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25271 * Leave an at least ~128 MB hole with possible stack randomization.
25272 */
25273 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25274 -#define MAX_GAP (TASK_SIZE/6*5)
25275 +#define MAX_GAP (pax_task_size/6*5)
25276
25277 static int mmap_is_legacy(void)
25278 {
25279 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25280 return rnd << PAGE_SHIFT;
25281 }
25282
25283 -static unsigned long mmap_base(void)
25284 +static unsigned long mmap_base(struct mm_struct *mm)
25285 {
25286 unsigned long gap = rlimit(RLIMIT_STACK);
25287 + unsigned long pax_task_size = TASK_SIZE;
25288 +
25289 +#ifdef CONFIG_PAX_SEGMEXEC
25290 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25291 + pax_task_size = SEGMEXEC_TASK_SIZE;
25292 +#endif
25293
25294 if (gap < MIN_GAP)
25295 gap = MIN_GAP;
25296 else if (gap > MAX_GAP)
25297 gap = MAX_GAP;
25298
25299 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25300 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25301 }
25302
25303 /*
25304 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25305 * does, but not when emulating X86_32
25306 */
25307 -static unsigned long mmap_legacy_base(void)
25308 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
25309 {
25310 - if (mmap_is_ia32())
25311 + if (mmap_is_ia32()) {
25312 +
25313 +#ifdef CONFIG_PAX_SEGMEXEC
25314 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25315 + return SEGMEXEC_TASK_UNMAPPED_BASE;
25316 + else
25317 +#endif
25318 +
25319 return TASK_UNMAPPED_BASE;
25320 - else
25321 + } else
25322 return TASK_UNMAPPED_BASE + mmap_rnd();
25323 }
25324
25325 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25326 void arch_pick_mmap_layout(struct mm_struct *mm)
25327 {
25328 if (mmap_is_legacy()) {
25329 - mm->mmap_base = mmap_legacy_base();
25330 + mm->mmap_base = mmap_legacy_base(mm);
25331 +
25332 +#ifdef CONFIG_PAX_RANDMMAP
25333 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25334 + mm->mmap_base += mm->delta_mmap;
25335 +#endif
25336 +
25337 mm->get_unmapped_area = arch_get_unmapped_area;
25338 mm->unmap_area = arch_unmap_area;
25339 } else {
25340 - mm->mmap_base = mmap_base();
25341 + mm->mmap_base = mmap_base(mm);
25342 +
25343 +#ifdef CONFIG_PAX_RANDMMAP
25344 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25345 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25346 +#endif
25347 +
25348 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25349 mm->unmap_area = arch_unmap_area_topdown;
25350 }
25351 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25352 index dc0b727..dc9d71a 100644
25353 --- a/arch/x86/mm/mmio-mod.c
25354 +++ b/arch/x86/mm/mmio-mod.c
25355 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25356 break;
25357 default:
25358 {
25359 - unsigned char *ip = (unsigned char *)instptr;
25360 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25361 my_trace->opcode = MMIO_UNKNOWN_OP;
25362 my_trace->width = 0;
25363 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25364 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25365 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25366 void __iomem *addr)
25367 {
25368 - static atomic_t next_id;
25369 + static atomic_unchecked_t next_id;
25370 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25371 /* These are page-unaligned. */
25372 struct mmiotrace_map map = {
25373 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25374 .private = trace
25375 },
25376 .phys = offset,
25377 - .id = atomic_inc_return(&next_id)
25378 + .id = atomic_inc_return_unchecked(&next_id)
25379 };
25380 map.map_id = trace->id;
25381
25382 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25383 index b008656..773eac2 100644
25384 --- a/arch/x86/mm/pageattr-test.c
25385 +++ b/arch/x86/mm/pageattr-test.c
25386 @@ -36,7 +36,7 @@ enum {
25387
25388 static int pte_testbit(pte_t pte)
25389 {
25390 - return pte_flags(pte) & _PAGE_UNUSED1;
25391 + return pte_flags(pte) & _PAGE_CPA_TEST;
25392 }
25393
25394 struct split_state {
25395 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25396 index e1ebde3..b1e1db38 100644
25397 --- a/arch/x86/mm/pageattr.c
25398 +++ b/arch/x86/mm/pageattr.c
25399 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25400 */
25401 #ifdef CONFIG_PCI_BIOS
25402 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25403 - pgprot_val(forbidden) |= _PAGE_NX;
25404 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25405 #endif
25406
25407 /*
25408 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25409 * Does not cover __inittext since that is gone later on. On
25410 * 64bit we do not enforce !NX on the low mapping
25411 */
25412 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
25413 - pgprot_val(forbidden) |= _PAGE_NX;
25414 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25415 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25416
25417 +#ifdef CONFIG_DEBUG_RODATA
25418 /*
25419 * The .rodata section needs to be read-only. Using the pfn
25420 * catches all aliases.
25421 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25422 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25423 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25424 pgprot_val(forbidden) |= _PAGE_RW;
25425 +#endif
25426
25427 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25428 /*
25429 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25430 }
25431 #endif
25432
25433 +#ifdef CONFIG_PAX_KERNEXEC
25434 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25435 + pgprot_val(forbidden) |= _PAGE_RW;
25436 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25437 + }
25438 +#endif
25439 +
25440 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25441
25442 return prot;
25443 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25444 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25445 {
25446 /* change init_mm */
25447 + pax_open_kernel();
25448 set_pte_atomic(kpte, pte);
25449 +
25450 #ifdef CONFIG_X86_32
25451 if (!SHARED_KERNEL_PMD) {
25452 +
25453 +#ifdef CONFIG_PAX_PER_CPU_PGD
25454 + unsigned long cpu;
25455 +#else
25456 struct page *page;
25457 +#endif
25458
25459 +#ifdef CONFIG_PAX_PER_CPU_PGD
25460 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25461 + pgd_t *pgd = get_cpu_pgd(cpu);
25462 +#else
25463 list_for_each_entry(page, &pgd_list, lru) {
25464 - pgd_t *pgd;
25465 + pgd_t *pgd = (pgd_t *)page_address(page);
25466 +#endif
25467 +
25468 pud_t *pud;
25469 pmd_t *pmd;
25470
25471 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
25472 + pgd += pgd_index(address);
25473 pud = pud_offset(pgd, address);
25474 pmd = pmd_offset(pud, address);
25475 set_pte_atomic((pte_t *)pmd, pte);
25476 }
25477 }
25478 #endif
25479 + pax_close_kernel();
25480 }
25481
25482 static int
25483 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25484 index f6ff57b..481690f 100644
25485 --- a/arch/x86/mm/pat.c
25486 +++ b/arch/x86/mm/pat.c
25487 @@ -361,7 +361,7 @@ int free_memtype(u64 start, u64 end)
25488
25489 if (!entry) {
25490 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
25491 - current->comm, current->pid, start, end);
25492 + current->comm, task_pid_nr(current), start, end);
25493 return -EINVAL;
25494 }
25495
25496 @@ -492,8 +492,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25497 while (cursor < to) {
25498 if (!devmem_is_allowed(pfn)) {
25499 printk(KERN_INFO
25500 - "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
25501 - current->comm, from, to);
25502 + "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
25503 + current->comm, from, to, cursor);
25504 return 0;
25505 }
25506 cursor += PAGE_SIZE;
25507 @@ -557,7 +557,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25508 printk(KERN_INFO
25509 "%s:%d ioremap_change_attr failed %s "
25510 "for %Lx-%Lx\n",
25511 - current->comm, current->pid,
25512 + current->comm, task_pid_nr(current),
25513 cattr_name(flags),
25514 base, (unsigned long long)(base + size));
25515 return -EINVAL;
25516 @@ -593,7 +593,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25517 if (want_flags != flags) {
25518 printk(KERN_WARNING
25519 "%s:%d map pfn RAM range req %s for %Lx-%Lx, got %s\n",
25520 - current->comm, current->pid,
25521 + current->comm, task_pid_nr(current),
25522 cattr_name(want_flags),
25523 (unsigned long long)paddr,
25524 (unsigned long long)(paddr + size),
25525 @@ -615,7 +615,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25526 free_memtype(paddr, paddr + size);
25527 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25528 " for %Lx-%Lx, got %s\n",
25529 - current->comm, current->pid,
25530 + current->comm, task_pid_nr(current),
25531 cattr_name(want_flags),
25532 (unsigned long long)paddr,
25533 (unsigned long long)(paddr + size),
25534 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25535 index 9f0614d..92ae64a 100644
25536 --- a/arch/x86/mm/pf_in.c
25537 +++ b/arch/x86/mm/pf_in.c
25538 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25539 int i;
25540 enum reason_type rv = OTHERS;
25541
25542 - p = (unsigned char *)ins_addr;
25543 + p = (unsigned char *)ktla_ktva(ins_addr);
25544 p += skip_prefix(p, &prf);
25545 p += get_opcode(p, &opcode);
25546
25547 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25548 struct prefix_bits prf;
25549 int i;
25550
25551 - p = (unsigned char *)ins_addr;
25552 + p = (unsigned char *)ktla_ktva(ins_addr);
25553 p += skip_prefix(p, &prf);
25554 p += get_opcode(p, &opcode);
25555
25556 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25557 struct prefix_bits prf;
25558 int i;
25559
25560 - p = (unsigned char *)ins_addr;
25561 + p = (unsigned char *)ktla_ktva(ins_addr);
25562 p += skip_prefix(p, &prf);
25563 p += get_opcode(p, &opcode);
25564
25565 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25566 struct prefix_bits prf;
25567 int i;
25568
25569 - p = (unsigned char *)ins_addr;
25570 + p = (unsigned char *)ktla_ktva(ins_addr);
25571 p += skip_prefix(p, &prf);
25572 p += get_opcode(p, &opcode);
25573 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25574 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25575 struct prefix_bits prf;
25576 int i;
25577
25578 - p = (unsigned char *)ins_addr;
25579 + p = (unsigned char *)ktla_ktva(ins_addr);
25580 p += skip_prefix(p, &prf);
25581 p += get_opcode(p, &opcode);
25582 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25583 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25584 index 8573b83..4f3ed7e 100644
25585 --- a/arch/x86/mm/pgtable.c
25586 +++ b/arch/x86/mm/pgtable.c
25587 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25588 list_del(&page->lru);
25589 }
25590
25591 -#define UNSHARED_PTRS_PER_PGD \
25592 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25593 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25594 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25595
25596 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25597 +{
25598 + unsigned int count = USER_PGD_PTRS;
25599
25600 + while (count--)
25601 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25602 +}
25603 +#endif
25604 +
25605 +#ifdef CONFIG_PAX_PER_CPU_PGD
25606 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25607 +{
25608 + unsigned int count = USER_PGD_PTRS;
25609 +
25610 + while (count--) {
25611 + pgd_t pgd;
25612 +
25613 +#ifdef CONFIG_X86_64
25614 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25615 +#else
25616 + pgd = *src++;
25617 +#endif
25618 +
25619 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25620 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25621 +#endif
25622 +
25623 + *dst++ = pgd;
25624 + }
25625 +
25626 +}
25627 +#endif
25628 +
25629 +#ifdef CONFIG_X86_64
25630 +#define pxd_t pud_t
25631 +#define pyd_t pgd_t
25632 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25633 +#define pxd_free(mm, pud) pud_free((mm), (pud))
25634 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25635 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
25636 +#define PYD_SIZE PGDIR_SIZE
25637 +#else
25638 +#define pxd_t pmd_t
25639 +#define pyd_t pud_t
25640 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25641 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
25642 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25643 +#define pyd_offset(mm, address) pud_offset((mm), (address))
25644 +#define PYD_SIZE PUD_SIZE
25645 +#endif
25646 +
25647 +#ifdef CONFIG_PAX_PER_CPU_PGD
25648 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25649 +static inline void pgd_dtor(pgd_t *pgd) {}
25650 +#else
25651 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25652 {
25653 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25654 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25655 pgd_list_del(pgd);
25656 spin_unlock(&pgd_lock);
25657 }
25658 +#endif
25659
25660 /*
25661 * List of all pgd's needed for non-PAE so it can invalidate entries
25662 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25663 * -- wli
25664 */
25665
25666 -#ifdef CONFIG_X86_PAE
25667 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25668 /*
25669 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25670 * updating the top-level pagetable entries to guarantee the
25671 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25672 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25673 * and initialize the kernel pmds here.
25674 */
25675 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25676 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25677
25678 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25679 {
25680 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25681 */
25682 flush_tlb_mm(mm);
25683 }
25684 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25685 +#define PREALLOCATED_PXDS USER_PGD_PTRS
25686 #else /* !CONFIG_X86_PAE */
25687
25688 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25689 -#define PREALLOCATED_PMDS 0
25690 +#define PREALLOCATED_PXDS 0
25691
25692 #endif /* CONFIG_X86_PAE */
25693
25694 -static void free_pmds(pmd_t *pmds[])
25695 +static void free_pxds(pxd_t *pxds[])
25696 {
25697 int i;
25698
25699 - for(i = 0; i < PREALLOCATED_PMDS; i++)
25700 - if (pmds[i])
25701 - free_page((unsigned long)pmds[i]);
25702 + for(i = 0; i < PREALLOCATED_PXDS; i++)
25703 + if (pxds[i])
25704 + free_page((unsigned long)pxds[i]);
25705 }
25706
25707 -static int preallocate_pmds(pmd_t *pmds[])
25708 +static int preallocate_pxds(pxd_t *pxds[])
25709 {
25710 int i;
25711 bool failed = false;
25712
25713 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25714 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25715 - if (pmd == NULL)
25716 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25717 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25718 + if (pxd == NULL)
25719 failed = true;
25720 - pmds[i] = pmd;
25721 + pxds[i] = pxd;
25722 }
25723
25724 if (failed) {
25725 - free_pmds(pmds);
25726 + free_pxds(pxds);
25727 return -ENOMEM;
25728 }
25729
25730 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25731 * preallocate which never got a corresponding vma will need to be
25732 * freed manually.
25733 */
25734 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25735 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25736 {
25737 int i;
25738
25739 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25740 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25741 pgd_t pgd = pgdp[i];
25742
25743 if (pgd_val(pgd) != 0) {
25744 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25745 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25746
25747 - pgdp[i] = native_make_pgd(0);
25748 + set_pgd(pgdp + i, native_make_pgd(0));
25749
25750 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25751 - pmd_free(mm, pmd);
25752 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25753 + pxd_free(mm, pxd);
25754 }
25755 }
25756 }
25757
25758 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25759 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25760 {
25761 - pud_t *pud;
25762 + pyd_t *pyd;
25763 unsigned long addr;
25764 int i;
25765
25766 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25767 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25768 return;
25769
25770 - pud = pud_offset(pgd, 0);
25771 +#ifdef CONFIG_X86_64
25772 + pyd = pyd_offset(mm, 0L);
25773 +#else
25774 + pyd = pyd_offset(pgd, 0L);
25775 +#endif
25776
25777 - for (addr = i = 0; i < PREALLOCATED_PMDS;
25778 - i++, pud++, addr += PUD_SIZE) {
25779 - pmd_t *pmd = pmds[i];
25780 + for (addr = i = 0; i < PREALLOCATED_PXDS;
25781 + i++, pyd++, addr += PYD_SIZE) {
25782 + pxd_t *pxd = pxds[i];
25783
25784 if (i >= KERNEL_PGD_BOUNDARY)
25785 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25786 - sizeof(pmd_t) * PTRS_PER_PMD);
25787 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25788 + sizeof(pxd_t) * PTRS_PER_PMD);
25789
25790 - pud_populate(mm, pud, pmd);
25791 + pyd_populate(mm, pyd, pxd);
25792 }
25793 }
25794
25795 pgd_t *pgd_alloc(struct mm_struct *mm)
25796 {
25797 pgd_t *pgd;
25798 - pmd_t *pmds[PREALLOCATED_PMDS];
25799 + pxd_t *pxds[PREALLOCATED_PXDS];
25800
25801 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25802
25803 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25804
25805 mm->pgd = pgd;
25806
25807 - if (preallocate_pmds(pmds) != 0)
25808 + if (preallocate_pxds(pxds) != 0)
25809 goto out_free_pgd;
25810
25811 if (paravirt_pgd_alloc(mm) != 0)
25812 - goto out_free_pmds;
25813 + goto out_free_pxds;
25814
25815 /*
25816 * Make sure that pre-populating the pmds is atomic with
25817 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25818 spin_lock(&pgd_lock);
25819
25820 pgd_ctor(mm, pgd);
25821 - pgd_prepopulate_pmd(mm, pgd, pmds);
25822 + pgd_prepopulate_pxd(mm, pgd, pxds);
25823
25824 spin_unlock(&pgd_lock);
25825
25826 return pgd;
25827
25828 -out_free_pmds:
25829 - free_pmds(pmds);
25830 +out_free_pxds:
25831 + free_pxds(pxds);
25832 out_free_pgd:
25833 free_page((unsigned long)pgd);
25834 out:
25835 @@ -295,7 +356,7 @@ out:
25836
25837 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25838 {
25839 - pgd_mop_up_pmds(mm, pgd);
25840 + pgd_mop_up_pxds(mm, pgd);
25841 pgd_dtor(pgd);
25842 paravirt_pgd_free(mm, pgd);
25843 free_page((unsigned long)pgd);
25844 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25845 index a69bcb8..19068ab 100644
25846 --- a/arch/x86/mm/pgtable_32.c
25847 +++ b/arch/x86/mm/pgtable_32.c
25848 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25849 return;
25850 }
25851 pte = pte_offset_kernel(pmd, vaddr);
25852 +
25853 + pax_open_kernel();
25854 if (pte_val(pteval))
25855 set_pte_at(&init_mm, vaddr, pte, pteval);
25856 else
25857 pte_clear(&init_mm, vaddr, pte);
25858 + pax_close_kernel();
25859
25860 /*
25861 * It's enough to flush this one mapping.
25862 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25863 index 410531d..0f16030 100644
25864 --- a/arch/x86/mm/setup_nx.c
25865 +++ b/arch/x86/mm/setup_nx.c
25866 @@ -5,8 +5,10 @@
25867 #include <asm/pgtable.h>
25868 #include <asm/proto.h>
25869
25870 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25871 static int disable_nx __cpuinitdata;
25872
25873 +#ifndef CONFIG_PAX_PAGEEXEC
25874 /*
25875 * noexec = on|off
25876 *
25877 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25878 return 0;
25879 }
25880 early_param("noexec", noexec_setup);
25881 +#endif
25882 +
25883 +#endif
25884
25885 void __cpuinit x86_configure_nx(void)
25886 {
25887 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25888 if (cpu_has_nx && !disable_nx)
25889 __supported_pte_mask |= _PAGE_NX;
25890 else
25891 +#endif
25892 __supported_pte_mask &= ~_PAGE_NX;
25893 }
25894
25895 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25896 index d6c0418..06a0ad5 100644
25897 --- a/arch/x86/mm/tlb.c
25898 +++ b/arch/x86/mm/tlb.c
25899 @@ -65,7 +65,11 @@ void leave_mm(int cpu)
25900 BUG();
25901 cpumask_clear_cpu(cpu,
25902 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
25903 +
25904 +#ifndef CONFIG_PAX_PER_CPU_PGD
25905 load_cr3(swapper_pg_dir);
25906 +#endif
25907 +
25908 }
25909 EXPORT_SYMBOL_GPL(leave_mm);
25910
25911 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25912 index 877b9a1..a8ecf42 100644
25913 --- a/arch/x86/net/bpf_jit.S
25914 +++ b/arch/x86/net/bpf_jit.S
25915 @@ -9,6 +9,7 @@
25916 */
25917 #include <linux/linkage.h>
25918 #include <asm/dwarf2.h>
25919 +#include <asm/alternative-asm.h>
25920
25921 /*
25922 * Calling convention :
25923 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
25924 jle bpf_slow_path_word
25925 mov (SKBDATA,%rsi),%eax
25926 bswap %eax /* ntohl() */
25927 + pax_force_retaddr
25928 ret
25929
25930 sk_load_half:
25931 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
25932 jle bpf_slow_path_half
25933 movzwl (SKBDATA,%rsi),%eax
25934 rol $8,%ax # ntohs()
25935 + pax_force_retaddr
25936 ret
25937
25938 sk_load_byte:
25939 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
25940 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25941 jle bpf_slow_path_byte
25942 movzbl (SKBDATA,%rsi),%eax
25943 + pax_force_retaddr
25944 ret
25945
25946 /**
25947 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
25948 movzbl (SKBDATA,%rsi),%ebx
25949 and $15,%bl
25950 shl $2,%bl
25951 + pax_force_retaddr
25952 ret
25953
25954 /* rsi contains offset and can be scratched */
25955 @@ -109,6 +114,7 @@ bpf_slow_path_word:
25956 js bpf_error
25957 mov -12(%rbp),%eax
25958 bswap %eax
25959 + pax_force_retaddr
25960 ret
25961
25962 bpf_slow_path_half:
25963 @@ -117,12 +123,14 @@ bpf_slow_path_half:
25964 mov -12(%rbp),%ax
25965 rol $8,%ax
25966 movzwl %ax,%eax
25967 + pax_force_retaddr
25968 ret
25969
25970 bpf_slow_path_byte:
25971 bpf_slow_path_common(1)
25972 js bpf_error
25973 movzbl -12(%rbp),%eax
25974 + pax_force_retaddr
25975 ret
25976
25977 bpf_slow_path_byte_msh:
25978 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
25979 and $15,%al
25980 shl $2,%al
25981 xchg %eax,%ebx
25982 + pax_force_retaddr
25983 ret
25984
25985 #define sk_negative_common(SIZE) \
25986 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
25987 sk_negative_common(4)
25988 mov (%rax), %eax
25989 bswap %eax
25990 + pax_force_retaddr
25991 ret
25992
25993 bpf_slow_path_half_neg:
25994 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
25995 mov (%rax),%ax
25996 rol $8,%ax
25997 movzwl %ax,%eax
25998 + pax_force_retaddr
25999 ret
26000
26001 bpf_slow_path_byte_neg:
26002 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
26003 .globl sk_load_byte_negative_offset
26004 sk_negative_common(1)
26005 movzbl (%rax), %eax
26006 + pax_force_retaddr
26007 ret
26008
26009 bpf_slow_path_byte_msh_neg:
26010 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
26011 and $15,%al
26012 shl $2,%al
26013 xchg %eax,%ebx
26014 + pax_force_retaddr
26015 ret
26016
26017 bpf_error:
26018 @@ -197,4 +210,5 @@ bpf_error:
26019 xor %eax,%eax
26020 mov -8(%rbp),%rbx
26021 leaveq
26022 + pax_force_retaddr
26023 ret
26024 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
26025 index 0597f95..a12c36e 100644
26026 --- a/arch/x86/net/bpf_jit_comp.c
26027 +++ b/arch/x86/net/bpf_jit_comp.c
26028 @@ -120,6 +120,11 @@ static inline void bpf_flush_icache(void *start, void *end)
26029 set_fs(old_fs);
26030 }
26031
26032 +struct bpf_jit_work {
26033 + struct work_struct work;
26034 + void *image;
26035 +};
26036 +
26037 #define CHOOSE_LOAD_FUNC(K, func) \
26038 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
26039
26040 @@ -146,6 +151,10 @@ void bpf_jit_compile(struct sk_filter *fp)
26041 if (addrs == NULL)
26042 return;
26043
26044 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
26045 + if (!fp->work)
26046 + goto out;
26047 +
26048 /* Before first pass, make a rough estimation of addrs[]
26049 * each bpf instruction is translated to less than 64 bytes
26050 */
26051 @@ -589,17 +598,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26052 break;
26053 default:
26054 /* hmm, too complex filter, give up with jit compiler */
26055 - goto out;
26056 + goto error;
26057 }
26058 ilen = prog - temp;
26059 if (image) {
26060 if (unlikely(proglen + ilen > oldproglen)) {
26061 pr_err("bpb_jit_compile fatal error\n");
26062 - kfree(addrs);
26063 - module_free(NULL, image);
26064 - return;
26065 + module_free_exec(NULL, image);
26066 + goto error;
26067 }
26068 + pax_open_kernel();
26069 memcpy(image + proglen, temp, ilen);
26070 + pax_close_kernel();
26071 }
26072 proglen += ilen;
26073 addrs[i] = proglen;
26074 @@ -620,11 +630,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26075 break;
26076 }
26077 if (proglen == oldproglen) {
26078 - image = module_alloc(max_t(unsigned int,
26079 - proglen,
26080 - sizeof(struct work_struct)));
26081 + image = module_alloc_exec(proglen);
26082 if (!image)
26083 - goto out;
26084 + goto error;
26085 }
26086 oldproglen = proglen;
26087 }
26088 @@ -640,7 +648,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26089 bpf_flush_icache(image, image + proglen);
26090
26091 fp->bpf_func = (void *)image;
26092 - }
26093 + } else
26094 +error:
26095 + kfree(fp->work);
26096 +
26097 out:
26098 kfree(addrs);
26099 return;
26100 @@ -648,18 +659,20 @@ out:
26101
26102 static void jit_free_defer(struct work_struct *arg)
26103 {
26104 - module_free(NULL, arg);
26105 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
26106 + kfree(arg);
26107 }
26108
26109 /* run from softirq, we must use a work_struct to call
26110 - * module_free() from process context
26111 + * module_free_exec() from process context
26112 */
26113 void bpf_jit_free(struct sk_filter *fp)
26114 {
26115 if (fp->bpf_func != sk_run_filter) {
26116 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
26117 + struct work_struct *work = &fp->work->work;
26118
26119 INIT_WORK(work, jit_free_defer);
26120 + fp->work->image = fp->bpf_func;
26121 schedule_work(work);
26122 }
26123 }
26124 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26125 index d6aa6e8..266395a 100644
26126 --- a/arch/x86/oprofile/backtrace.c
26127 +++ b/arch/x86/oprofile/backtrace.c
26128 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
26129 struct stack_frame_ia32 *fp;
26130 unsigned long bytes;
26131
26132 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26133 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26134 if (bytes != sizeof(bufhead))
26135 return NULL;
26136
26137 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26138 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26139
26140 oprofile_add_trace(bufhead[0].return_address);
26141
26142 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26143 struct stack_frame bufhead[2];
26144 unsigned long bytes;
26145
26146 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26147 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26148 if (bytes != sizeof(bufhead))
26149 return NULL;
26150
26151 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26152 {
26153 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26154
26155 - if (!user_mode_vm(regs)) {
26156 + if (!user_mode(regs)) {
26157 unsigned long stack = kernel_stack_pointer(regs);
26158 if (depth)
26159 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26160 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26161 index 140942f..8a5cc55 100644
26162 --- a/arch/x86/pci/mrst.c
26163 +++ b/arch/x86/pci/mrst.c
26164 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
26165 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
26166 pci_mmcfg_late_init();
26167 pcibios_enable_irq = mrst_pci_irq_enable;
26168 - pci_root_ops = pci_mrst_ops;
26169 + pax_open_kernel();
26170 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26171 + pax_close_kernel();
26172 pci_soc_mode = 1;
26173 /* Continue with standard init */
26174 return 1;
26175 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26176 index da8fe05..7ee6704 100644
26177 --- a/arch/x86/pci/pcbios.c
26178 +++ b/arch/x86/pci/pcbios.c
26179 @@ -79,50 +79,93 @@ union bios32 {
26180 static struct {
26181 unsigned long address;
26182 unsigned short segment;
26183 -} bios32_indirect = { 0, __KERNEL_CS };
26184 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26185
26186 /*
26187 * Returns the entry point for the given service, NULL on error
26188 */
26189
26190 -static unsigned long bios32_service(unsigned long service)
26191 +static unsigned long __devinit bios32_service(unsigned long service)
26192 {
26193 unsigned char return_code; /* %al */
26194 unsigned long address; /* %ebx */
26195 unsigned long length; /* %ecx */
26196 unsigned long entry; /* %edx */
26197 unsigned long flags;
26198 + struct desc_struct d, *gdt;
26199
26200 local_irq_save(flags);
26201 - __asm__("lcall *(%%edi); cld"
26202 +
26203 + gdt = get_cpu_gdt_table(smp_processor_id());
26204 +
26205 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26206 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26207 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26208 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26209 +
26210 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26211 : "=a" (return_code),
26212 "=b" (address),
26213 "=c" (length),
26214 "=d" (entry)
26215 : "0" (service),
26216 "1" (0),
26217 - "D" (&bios32_indirect));
26218 + "D" (&bios32_indirect),
26219 + "r"(__PCIBIOS_DS)
26220 + : "memory");
26221 +
26222 + pax_open_kernel();
26223 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26224 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26225 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26226 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26227 + pax_close_kernel();
26228 +
26229 local_irq_restore(flags);
26230
26231 switch (return_code) {
26232 - case 0:
26233 - return address + entry;
26234 - case 0x80: /* Not present */
26235 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26236 - return 0;
26237 - default: /* Shouldn't happen */
26238 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26239 - service, return_code);
26240 + case 0: {
26241 + int cpu;
26242 + unsigned char flags;
26243 +
26244 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26245 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26246 + printk(KERN_WARNING "bios32_service: not valid\n");
26247 return 0;
26248 + }
26249 + address = address + PAGE_OFFSET;
26250 + length += 16UL; /* some BIOSs underreport this... */
26251 + flags = 4;
26252 + if (length >= 64*1024*1024) {
26253 + length >>= PAGE_SHIFT;
26254 + flags |= 8;
26255 + }
26256 +
26257 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26258 + gdt = get_cpu_gdt_table(cpu);
26259 + pack_descriptor(&d, address, length, 0x9b, flags);
26260 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26261 + pack_descriptor(&d, address, length, 0x93, flags);
26262 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26263 + }
26264 + return entry;
26265 + }
26266 + case 0x80: /* Not present */
26267 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26268 + return 0;
26269 + default: /* Shouldn't happen */
26270 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26271 + service, return_code);
26272 + return 0;
26273 }
26274 }
26275
26276 static struct {
26277 unsigned long address;
26278 unsigned short segment;
26279 -} pci_indirect = { 0, __KERNEL_CS };
26280 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26281
26282 -static int pci_bios_present;
26283 +static int pci_bios_present __read_only;
26284
26285 static int __devinit check_pcibios(void)
26286 {
26287 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26288 unsigned long flags, pcibios_entry;
26289
26290 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26291 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26292 + pci_indirect.address = pcibios_entry;
26293
26294 local_irq_save(flags);
26295 - __asm__(
26296 - "lcall *(%%edi); cld\n\t"
26297 + __asm__("movw %w6, %%ds\n\t"
26298 + "lcall *%%ss:(%%edi); cld\n\t"
26299 + "push %%ss\n\t"
26300 + "pop %%ds\n\t"
26301 "jc 1f\n\t"
26302 "xor %%ah, %%ah\n"
26303 "1:"
26304 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26305 "=b" (ebx),
26306 "=c" (ecx)
26307 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26308 - "D" (&pci_indirect)
26309 + "D" (&pci_indirect),
26310 + "r" (__PCIBIOS_DS)
26311 : "memory");
26312 local_irq_restore(flags);
26313
26314 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26315
26316 switch (len) {
26317 case 1:
26318 - __asm__("lcall *(%%esi); cld\n\t"
26319 + __asm__("movw %w6, %%ds\n\t"
26320 + "lcall *%%ss:(%%esi); cld\n\t"
26321 + "push %%ss\n\t"
26322 + "pop %%ds\n\t"
26323 "jc 1f\n\t"
26324 "xor %%ah, %%ah\n"
26325 "1:"
26326 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26327 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26328 "b" (bx),
26329 "D" ((long)reg),
26330 - "S" (&pci_indirect));
26331 + "S" (&pci_indirect),
26332 + "r" (__PCIBIOS_DS));
26333 /*
26334 * Zero-extend the result beyond 8 bits, do not trust the
26335 * BIOS having done it:
26336 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26337 *value &= 0xff;
26338 break;
26339 case 2:
26340 - __asm__("lcall *(%%esi); cld\n\t"
26341 + __asm__("movw %w6, %%ds\n\t"
26342 + "lcall *%%ss:(%%esi); cld\n\t"
26343 + "push %%ss\n\t"
26344 + "pop %%ds\n\t"
26345 "jc 1f\n\t"
26346 "xor %%ah, %%ah\n"
26347 "1:"
26348 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26349 : "1" (PCIBIOS_READ_CONFIG_WORD),
26350 "b" (bx),
26351 "D" ((long)reg),
26352 - "S" (&pci_indirect));
26353 + "S" (&pci_indirect),
26354 + "r" (__PCIBIOS_DS));
26355 /*
26356 * Zero-extend the result beyond 16 bits, do not trust the
26357 * BIOS having done it:
26358 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26359 *value &= 0xffff;
26360 break;
26361 case 4:
26362 - __asm__("lcall *(%%esi); cld\n\t"
26363 + __asm__("movw %w6, %%ds\n\t"
26364 + "lcall *%%ss:(%%esi); cld\n\t"
26365 + "push %%ss\n\t"
26366 + "pop %%ds\n\t"
26367 "jc 1f\n\t"
26368 "xor %%ah, %%ah\n"
26369 "1:"
26370 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26371 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26372 "b" (bx),
26373 "D" ((long)reg),
26374 - "S" (&pci_indirect));
26375 + "S" (&pci_indirect),
26376 + "r" (__PCIBIOS_DS));
26377 break;
26378 }
26379
26380 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26381
26382 switch (len) {
26383 case 1:
26384 - __asm__("lcall *(%%esi); cld\n\t"
26385 + __asm__("movw %w6, %%ds\n\t"
26386 + "lcall *%%ss:(%%esi); cld\n\t"
26387 + "push %%ss\n\t"
26388 + "pop %%ds\n\t"
26389 "jc 1f\n\t"
26390 "xor %%ah, %%ah\n"
26391 "1:"
26392 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26393 "c" (value),
26394 "b" (bx),
26395 "D" ((long)reg),
26396 - "S" (&pci_indirect));
26397 + "S" (&pci_indirect),
26398 + "r" (__PCIBIOS_DS));
26399 break;
26400 case 2:
26401 - __asm__("lcall *(%%esi); cld\n\t"
26402 + __asm__("movw %w6, %%ds\n\t"
26403 + "lcall *%%ss:(%%esi); cld\n\t"
26404 + "push %%ss\n\t"
26405 + "pop %%ds\n\t"
26406 "jc 1f\n\t"
26407 "xor %%ah, %%ah\n"
26408 "1:"
26409 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26410 "c" (value),
26411 "b" (bx),
26412 "D" ((long)reg),
26413 - "S" (&pci_indirect));
26414 + "S" (&pci_indirect),
26415 + "r" (__PCIBIOS_DS));
26416 break;
26417 case 4:
26418 - __asm__("lcall *(%%esi); cld\n\t"
26419 + __asm__("movw %w6, %%ds\n\t"
26420 + "lcall *%%ss:(%%esi); cld\n\t"
26421 + "push %%ss\n\t"
26422 + "pop %%ds\n\t"
26423 "jc 1f\n\t"
26424 "xor %%ah, %%ah\n"
26425 "1:"
26426 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26427 "c" (value),
26428 "b" (bx),
26429 "D" ((long)reg),
26430 - "S" (&pci_indirect));
26431 + "S" (&pci_indirect),
26432 + "r" (__PCIBIOS_DS));
26433 break;
26434 }
26435
26436 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26437
26438 DBG("PCI: Fetching IRQ routing table... ");
26439 __asm__("push %%es\n\t"
26440 + "movw %w8, %%ds\n\t"
26441 "push %%ds\n\t"
26442 "pop %%es\n\t"
26443 - "lcall *(%%esi); cld\n\t"
26444 + "lcall *%%ss:(%%esi); cld\n\t"
26445 "pop %%es\n\t"
26446 + "push %%ss\n\t"
26447 + "pop %%ds\n"
26448 "jc 1f\n\t"
26449 "xor %%ah, %%ah\n"
26450 "1:"
26451 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26452 "1" (0),
26453 "D" ((long) &opt),
26454 "S" (&pci_indirect),
26455 - "m" (opt)
26456 + "m" (opt),
26457 + "r" (__PCIBIOS_DS)
26458 : "memory");
26459 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26460 if (ret & 0xff00)
26461 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26462 {
26463 int ret;
26464
26465 - __asm__("lcall *(%%esi); cld\n\t"
26466 + __asm__("movw %w5, %%ds\n\t"
26467 + "lcall *%%ss:(%%esi); cld\n\t"
26468 + "push %%ss\n\t"
26469 + "pop %%ds\n"
26470 "jc 1f\n\t"
26471 "xor %%ah, %%ah\n"
26472 "1:"
26473 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26474 : "0" (PCIBIOS_SET_PCI_HW_INT),
26475 "b" ((dev->bus->number << 8) | dev->devfn),
26476 "c" ((irq << 8) | (pin + 10)),
26477 - "S" (&pci_indirect));
26478 + "S" (&pci_indirect),
26479 + "r" (__PCIBIOS_DS));
26480 return !(ret & 0xff00);
26481 }
26482 EXPORT_SYMBOL(pcibios_set_irq_routing);
26483 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26484 index 40e4469..1ab536e 100644
26485 --- a/arch/x86/platform/efi/efi_32.c
26486 +++ b/arch/x86/platform/efi/efi_32.c
26487 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26488 {
26489 struct desc_ptr gdt_descr;
26490
26491 +#ifdef CONFIG_PAX_KERNEXEC
26492 + struct desc_struct d;
26493 +#endif
26494 +
26495 local_irq_save(efi_rt_eflags);
26496
26497 load_cr3(initial_page_table);
26498 __flush_tlb_all();
26499
26500 +#ifdef CONFIG_PAX_KERNEXEC
26501 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26502 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26503 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26504 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26505 +#endif
26506 +
26507 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26508 gdt_descr.size = GDT_SIZE - 1;
26509 load_gdt(&gdt_descr);
26510 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26511 {
26512 struct desc_ptr gdt_descr;
26513
26514 +#ifdef CONFIG_PAX_KERNEXEC
26515 + struct desc_struct d;
26516 +
26517 + memset(&d, 0, sizeof d);
26518 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26519 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26520 +#endif
26521 +
26522 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26523 gdt_descr.size = GDT_SIZE - 1;
26524 load_gdt(&gdt_descr);
26525 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26526 index fbe66e6..c5c0dd2 100644
26527 --- a/arch/x86/platform/efi/efi_stub_32.S
26528 +++ b/arch/x86/platform/efi/efi_stub_32.S
26529 @@ -6,7 +6,9 @@
26530 */
26531
26532 #include <linux/linkage.h>
26533 +#include <linux/init.h>
26534 #include <asm/page_types.h>
26535 +#include <asm/segment.h>
26536
26537 /*
26538 * efi_call_phys(void *, ...) is a function with variable parameters.
26539 @@ -20,7 +22,7 @@
26540 * service functions will comply with gcc calling convention, too.
26541 */
26542
26543 -.text
26544 +__INIT
26545 ENTRY(efi_call_phys)
26546 /*
26547 * 0. The function can only be called in Linux kernel. So CS has been
26548 @@ -36,9 +38,11 @@ ENTRY(efi_call_phys)
26549 * The mapping of lower virtual memory has been created in prelog and
26550 * epilog.
26551 */
26552 - movl $1f, %edx
26553 - subl $__PAGE_OFFSET, %edx
26554 - jmp *%edx
26555 + movl $(__KERNEXEC_EFI_DS), %edx
26556 + mov %edx, %ds
26557 + mov %edx, %es
26558 + mov %edx, %ss
26559 + ljmp $(__KERNEXEC_EFI_CS),$1f-__PAGE_OFFSET
26560 1:
26561
26562 /*
26563 @@ -47,14 +51,8 @@ ENTRY(efi_call_phys)
26564 * parameter 2, ..., param n. To make things easy, we save the return
26565 * address of efi_call_phys in a global variable.
26566 */
26567 - popl %edx
26568 - movl %edx, saved_return_addr
26569 - /* get the function pointer into ECX*/
26570 - popl %ecx
26571 - movl %ecx, efi_rt_function_ptr
26572 - movl $2f, %edx
26573 - subl $__PAGE_OFFSET, %edx
26574 - pushl %edx
26575 + popl (saved_return_addr)
26576 + popl (efi_rt_function_ptr)
26577
26578 /*
26579 * 3. Clear PG bit in %CR0.
26580 @@ -73,9 +71,8 @@ ENTRY(efi_call_phys)
26581 /*
26582 * 5. Call the physical function.
26583 */
26584 - jmp *%ecx
26585 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
26586
26587 -2:
26588 /*
26589 * 6. After EFI runtime service returns, control will return to
26590 * following instruction. We'd better readjust stack pointer first.
26591 @@ -88,35 +85,32 @@ ENTRY(efi_call_phys)
26592 movl %cr0, %edx
26593 orl $0x80000000, %edx
26594 movl %edx, %cr0
26595 - jmp 1f
26596 -1:
26597 +
26598 /*
26599 * 8. Now restore the virtual mode from flat mode by
26600 * adding EIP with PAGE_OFFSET.
26601 */
26602 - movl $1f, %edx
26603 - jmp *%edx
26604 + ljmp $(__KERNEL_CS),$1f+__PAGE_OFFSET
26605 1:
26606 + movl $(__KERNEL_DS), %edx
26607 + mov %edx, %ds
26608 + mov %edx, %es
26609 + mov %edx, %ss
26610
26611 /*
26612 * 9. Balance the stack. And because EAX contain the return value,
26613 * we'd better not clobber it.
26614 */
26615 - leal efi_rt_function_ptr, %edx
26616 - movl (%edx), %ecx
26617 - pushl %ecx
26618 + pushl (efi_rt_function_ptr)
26619
26620 /*
26621 - * 10. Push the saved return address onto the stack and return.
26622 + * 10. Return to the saved return address.
26623 */
26624 - leal saved_return_addr, %edx
26625 - movl (%edx), %ecx
26626 - pushl %ecx
26627 - ret
26628 + jmpl *(saved_return_addr)
26629 ENDPROC(efi_call_phys)
26630 .previous
26631
26632 -.data
26633 +__INITDATA
26634 saved_return_addr:
26635 .long 0
26636 efi_rt_function_ptr:
26637 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26638 index 4c07cca..2c8427d 100644
26639 --- a/arch/x86/platform/efi/efi_stub_64.S
26640 +++ b/arch/x86/platform/efi/efi_stub_64.S
26641 @@ -7,6 +7,7 @@
26642 */
26643
26644 #include <linux/linkage.h>
26645 +#include <asm/alternative-asm.h>
26646
26647 #define SAVE_XMM \
26648 mov %rsp, %rax; \
26649 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
26650 call *%rdi
26651 addq $32, %rsp
26652 RESTORE_XMM
26653 + pax_force_retaddr 0, 1
26654 ret
26655 ENDPROC(efi_call0)
26656
26657 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
26658 call *%rdi
26659 addq $32, %rsp
26660 RESTORE_XMM
26661 + pax_force_retaddr 0, 1
26662 ret
26663 ENDPROC(efi_call1)
26664
26665 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
26666 call *%rdi
26667 addq $32, %rsp
26668 RESTORE_XMM
26669 + pax_force_retaddr 0, 1
26670 ret
26671 ENDPROC(efi_call2)
26672
26673 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
26674 call *%rdi
26675 addq $32, %rsp
26676 RESTORE_XMM
26677 + pax_force_retaddr 0, 1
26678 ret
26679 ENDPROC(efi_call3)
26680
26681 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
26682 call *%rdi
26683 addq $32, %rsp
26684 RESTORE_XMM
26685 + pax_force_retaddr 0, 1
26686 ret
26687 ENDPROC(efi_call4)
26688
26689 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
26690 call *%rdi
26691 addq $48, %rsp
26692 RESTORE_XMM
26693 + pax_force_retaddr 0, 1
26694 ret
26695 ENDPROC(efi_call5)
26696
26697 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
26698 call *%rdi
26699 addq $48, %rsp
26700 RESTORE_XMM
26701 + pax_force_retaddr 0, 1
26702 ret
26703 ENDPROC(efi_call6)
26704 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26705 index e31bcd8..f12dc46 100644
26706 --- a/arch/x86/platform/mrst/mrst.c
26707 +++ b/arch/x86/platform/mrst/mrst.c
26708 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26709 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26710 int sfi_mrtc_num;
26711
26712 -static void mrst_power_off(void)
26713 +static __noreturn void mrst_power_off(void)
26714 {
26715 + BUG();
26716 }
26717
26718 -static void mrst_reboot(void)
26719 +static __noreturn void mrst_reboot(void)
26720 {
26721 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26722 + BUG();
26723 }
26724
26725 /* parse all the mtimer info to a static mtimer array */
26726 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26727 index 218cdb1..fd55c08 100644
26728 --- a/arch/x86/power/cpu.c
26729 +++ b/arch/x86/power/cpu.c
26730 @@ -132,7 +132,7 @@ static void do_fpu_end(void)
26731 static void fix_processor_context(void)
26732 {
26733 int cpu = smp_processor_id();
26734 - struct tss_struct *t = &per_cpu(init_tss, cpu);
26735 + struct tss_struct *t = init_tss + cpu;
26736
26737 set_tss_desc(cpu, t); /*
26738 * This just modifies memory; should not be
26739 @@ -142,7 +142,9 @@ static void fix_processor_context(void)
26740 */
26741
26742 #ifdef CONFIG_X86_64
26743 + pax_open_kernel();
26744 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26745 + pax_close_kernel();
26746
26747 syscall_init(); /* This sets MSR_*STAR and related */
26748 #endif
26749 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
26750 index b685296..e00eb65 100644
26751 --- a/arch/x86/tools/relocs.c
26752 +++ b/arch/x86/tools/relocs.c
26753 @@ -12,10 +12,13 @@
26754 #include <regex.h>
26755 #include <tools/le_byteshift.h>
26756
26757 +#include "../../../include/generated/autoconf.h"
26758 +
26759 static void die(char *fmt, ...);
26760
26761 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
26762 static Elf32_Ehdr ehdr;
26763 +static Elf32_Phdr *phdr;
26764 static unsigned long reloc_count, reloc_idx;
26765 static unsigned long *relocs;
26766 static unsigned long reloc16_count, reloc16_idx;
26767 @@ -323,9 +326,39 @@ static void read_ehdr(FILE *fp)
26768 }
26769 }
26770
26771 +static void read_phdrs(FILE *fp)
26772 +{
26773 + unsigned int i;
26774 +
26775 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
26776 + if (!phdr) {
26777 + die("Unable to allocate %d program headers\n",
26778 + ehdr.e_phnum);
26779 + }
26780 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
26781 + die("Seek to %d failed: %s\n",
26782 + ehdr.e_phoff, strerror(errno));
26783 + }
26784 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
26785 + die("Cannot read ELF program headers: %s\n",
26786 + strerror(errno));
26787 + }
26788 + for(i = 0; i < ehdr.e_phnum; i++) {
26789 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
26790 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
26791 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
26792 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
26793 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
26794 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
26795 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
26796 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
26797 + }
26798 +
26799 +}
26800 +
26801 static void read_shdrs(FILE *fp)
26802 {
26803 - int i;
26804 + unsigned int i;
26805 Elf32_Shdr shdr;
26806
26807 secs = calloc(ehdr.e_shnum, sizeof(struct section));
26808 @@ -360,7 +393,7 @@ static void read_shdrs(FILE *fp)
26809
26810 static void read_strtabs(FILE *fp)
26811 {
26812 - int i;
26813 + unsigned int i;
26814 for (i = 0; i < ehdr.e_shnum; i++) {
26815 struct section *sec = &secs[i];
26816 if (sec->shdr.sh_type != SHT_STRTAB) {
26817 @@ -385,7 +418,7 @@ static void read_strtabs(FILE *fp)
26818
26819 static void read_symtabs(FILE *fp)
26820 {
26821 - int i,j;
26822 + unsigned int i,j;
26823 for (i = 0; i < ehdr.e_shnum; i++) {
26824 struct section *sec = &secs[i];
26825 if (sec->shdr.sh_type != SHT_SYMTAB) {
26826 @@ -418,7 +451,9 @@ static void read_symtabs(FILE *fp)
26827
26828 static void read_relocs(FILE *fp)
26829 {
26830 - int i,j;
26831 + unsigned int i,j;
26832 + uint32_t base;
26833 +
26834 for (i = 0; i < ehdr.e_shnum; i++) {
26835 struct section *sec = &secs[i];
26836 if (sec->shdr.sh_type != SHT_REL) {
26837 @@ -438,9 +473,22 @@ static void read_relocs(FILE *fp)
26838 die("Cannot read symbol table: %s\n",
26839 strerror(errno));
26840 }
26841 + base = 0;
26842 +
26843 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
26844 + for (j = 0; j < ehdr.e_phnum; j++) {
26845 + if (phdr[j].p_type != PT_LOAD )
26846 + continue;
26847 + 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)
26848 + continue;
26849 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
26850 + break;
26851 + }
26852 +#endif
26853 +
26854 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
26855 Elf32_Rel *rel = &sec->reltab[j];
26856 - rel->r_offset = elf32_to_cpu(rel->r_offset);
26857 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
26858 rel->r_info = elf32_to_cpu(rel->r_info);
26859 }
26860 }
26861 @@ -449,13 +497,13 @@ static void read_relocs(FILE *fp)
26862
26863 static void print_absolute_symbols(void)
26864 {
26865 - int i;
26866 + unsigned int i;
26867 printf("Absolute symbols\n");
26868 printf(" Num: Value Size Type Bind Visibility Name\n");
26869 for (i = 0; i < ehdr.e_shnum; i++) {
26870 struct section *sec = &secs[i];
26871 char *sym_strtab;
26872 - int j;
26873 + unsigned int j;
26874
26875 if (sec->shdr.sh_type != SHT_SYMTAB) {
26876 continue;
26877 @@ -482,14 +530,14 @@ static void print_absolute_symbols(void)
26878
26879 static void print_absolute_relocs(void)
26880 {
26881 - int i, printed = 0;
26882 + unsigned int i, printed = 0;
26883
26884 for (i = 0; i < ehdr.e_shnum; i++) {
26885 struct section *sec = &secs[i];
26886 struct section *sec_applies, *sec_symtab;
26887 char *sym_strtab;
26888 Elf32_Sym *sh_symtab;
26889 - int j;
26890 + unsigned int j;
26891 if (sec->shdr.sh_type != SHT_REL) {
26892 continue;
26893 }
26894 @@ -551,13 +599,13 @@ static void print_absolute_relocs(void)
26895 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26896 int use_real_mode)
26897 {
26898 - int i;
26899 + unsigned int i;
26900 /* Walk through the relocations */
26901 for (i = 0; i < ehdr.e_shnum; i++) {
26902 char *sym_strtab;
26903 Elf32_Sym *sh_symtab;
26904 struct section *sec_applies, *sec_symtab;
26905 - int j;
26906 + unsigned int j;
26907 struct section *sec = &secs[i];
26908
26909 if (sec->shdr.sh_type != SHT_REL) {
26910 @@ -581,6 +629,22 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26911 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
26912 r_type = ELF32_R_TYPE(rel->r_info);
26913
26914 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
26915 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
26916 + continue;
26917 +
26918 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
26919 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
26920 + if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
26921 + continue;
26922 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
26923 + continue;
26924 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
26925 + continue;
26926 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
26927 + continue;
26928 +#endif
26929 +
26930 shn_abs = sym->st_shndx == SHN_ABS;
26931
26932 switch (r_type) {
26933 @@ -674,7 +738,7 @@ static int write32(unsigned int v, FILE *f)
26934
26935 static void emit_relocs(int as_text, int use_real_mode)
26936 {
26937 - int i;
26938 + unsigned int i;
26939 /* Count how many relocations I have and allocate space for them. */
26940 reloc_count = 0;
26941 walk_relocs(count_reloc, use_real_mode);
26942 @@ -801,6 +865,7 @@ int main(int argc, char **argv)
26943 fname, strerror(errno));
26944 }
26945 read_ehdr(fp);
26946 + read_phdrs(fp);
26947 read_shdrs(fp);
26948 read_strtabs(fp);
26949 read_symtabs(fp);
26950 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
26951 index fd14be1..e3c79c0 100644
26952 --- a/arch/x86/vdso/Makefile
26953 +++ b/arch/x86/vdso/Makefile
26954 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
26955 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
26956 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
26957
26958 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26959 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26960 GCOV_PROFILE := n
26961
26962 #
26963 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
26964 index 66e6d93..587f435 100644
26965 --- a/arch/x86/vdso/vdso32-setup.c
26966 +++ b/arch/x86/vdso/vdso32-setup.c
26967 @@ -25,6 +25,7 @@
26968 #include <asm/tlbflush.h>
26969 #include <asm/vdso.h>
26970 #include <asm/proto.h>
26971 +#include <asm/mman.h>
26972
26973 enum {
26974 VDSO_DISABLED = 0,
26975 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
26976 void enable_sep_cpu(void)
26977 {
26978 int cpu = get_cpu();
26979 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26980 + struct tss_struct *tss = init_tss + cpu;
26981
26982 if (!boot_cpu_has(X86_FEATURE_SEP)) {
26983 put_cpu();
26984 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
26985 gate_vma.vm_start = FIXADDR_USER_START;
26986 gate_vma.vm_end = FIXADDR_USER_END;
26987 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
26988 - gate_vma.vm_page_prot = __P101;
26989 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
26990
26991 return 0;
26992 }
26993 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26994 if (compat)
26995 addr = VDSO_HIGH_BASE;
26996 else {
26997 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
26998 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
26999 if (IS_ERR_VALUE(addr)) {
27000 ret = addr;
27001 goto up_fail;
27002 }
27003 }
27004
27005 - current->mm->context.vdso = (void *)addr;
27006 + current->mm->context.vdso = addr;
27007
27008 if (compat_uses_vma || !compat) {
27009 /*
27010 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27011 }
27012
27013 current_thread_info()->sysenter_return =
27014 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27015 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27016
27017 up_fail:
27018 if (ret)
27019 - current->mm->context.vdso = NULL;
27020 + current->mm->context.vdso = 0;
27021
27022 up_write(&mm->mmap_sem);
27023
27024 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
27025
27026 const char *arch_vma_name(struct vm_area_struct *vma)
27027 {
27028 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27029 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27030 return "[vdso]";
27031 +
27032 +#ifdef CONFIG_PAX_SEGMEXEC
27033 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
27034 + return "[vdso]";
27035 +#endif
27036 +
27037 return NULL;
27038 }
27039
27040 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27041 * Check to see if the corresponding task was created in compat vdso
27042 * mode.
27043 */
27044 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
27045 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
27046 return &gate_vma;
27047 return NULL;
27048 }
27049 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
27050 index 00aaf04..4a26505 100644
27051 --- a/arch/x86/vdso/vma.c
27052 +++ b/arch/x86/vdso/vma.c
27053 @@ -16,8 +16,6 @@
27054 #include <asm/vdso.h>
27055 #include <asm/page.h>
27056
27057 -unsigned int __read_mostly vdso_enabled = 1;
27058 -
27059 extern char vdso_start[], vdso_end[];
27060 extern unsigned short vdso_sync_cpuid;
27061
27062 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27063 * unaligned here as a result of stack start randomization.
27064 */
27065 addr = PAGE_ALIGN(addr);
27066 - addr = align_addr(addr, NULL, ALIGN_VDSO);
27067
27068 return addr;
27069 }
27070 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
27071 unsigned size)
27072 {
27073 struct mm_struct *mm = current->mm;
27074 - unsigned long addr;
27075 + unsigned long addr = 0;
27076 int ret;
27077
27078 - if (!vdso_enabled)
27079 - return 0;
27080 -
27081 down_write(&mm->mmap_sem);
27082 +
27083 +#ifdef CONFIG_PAX_RANDMMAP
27084 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27085 +#endif
27086 +
27087 addr = vdso_addr(mm->start_stack, size);
27088 + addr = align_addr(addr, NULL, ALIGN_VDSO);
27089 addr = get_unmapped_area(NULL, addr, size, 0, 0);
27090 if (IS_ERR_VALUE(addr)) {
27091 ret = addr;
27092 goto up_fail;
27093 }
27094
27095 - current->mm->context.vdso = (void *)addr;
27096 + mm->context.vdso = addr;
27097
27098 ret = install_special_mapping(mm, addr, size,
27099 VM_READ|VM_EXEC|
27100 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
27101 pages);
27102 - if (ret) {
27103 - current->mm->context.vdso = NULL;
27104 - goto up_fail;
27105 - }
27106 + if (ret)
27107 + mm->context.vdso = 0;
27108
27109 up_fail:
27110 up_write(&mm->mmap_sem);
27111 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27112 vdsox32_size);
27113 }
27114 #endif
27115 -
27116 -static __init int vdso_setup(char *s)
27117 -{
27118 - vdso_enabled = simple_strtoul(s, NULL, 0);
27119 - return 0;
27120 -}
27121 -__setup("vdso=", vdso_setup);
27122 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27123 index 40edfc3..b4d80ac 100644
27124 --- a/arch/x86/xen/enlighten.c
27125 +++ b/arch/x86/xen/enlighten.c
27126 @@ -95,8 +95,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27127
27128 struct shared_info xen_dummy_shared_info;
27129
27130 -void *xen_initial_gdt;
27131 -
27132 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27133 __read_mostly int xen_have_vector_callback;
27134 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27135 @@ -1165,30 +1163,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27136 #endif
27137 };
27138
27139 -static void xen_reboot(int reason)
27140 +static __noreturn void xen_reboot(int reason)
27141 {
27142 struct sched_shutdown r = { .reason = reason };
27143
27144 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27145 - BUG();
27146 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27147 + BUG();
27148 }
27149
27150 -static void xen_restart(char *msg)
27151 +static __noreturn void xen_restart(char *msg)
27152 {
27153 xen_reboot(SHUTDOWN_reboot);
27154 }
27155
27156 -static void xen_emergency_restart(void)
27157 +static __noreturn void xen_emergency_restart(void)
27158 {
27159 xen_reboot(SHUTDOWN_reboot);
27160 }
27161
27162 -static void xen_machine_halt(void)
27163 +static __noreturn void xen_machine_halt(void)
27164 {
27165 xen_reboot(SHUTDOWN_poweroff);
27166 }
27167
27168 -static void xen_machine_power_off(void)
27169 +static __noreturn void xen_machine_power_off(void)
27170 {
27171 if (pm_power_off)
27172 pm_power_off();
27173 @@ -1291,7 +1289,17 @@ asmlinkage void __init xen_start_kernel(void)
27174 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27175
27176 /* Work out if we support NX */
27177 - x86_configure_nx();
27178 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27179 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27180 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27181 + unsigned l, h;
27182 +
27183 + __supported_pte_mask |= _PAGE_NX;
27184 + rdmsr(MSR_EFER, l, h);
27185 + l |= EFER_NX;
27186 + wrmsr(MSR_EFER, l, h);
27187 + }
27188 +#endif
27189
27190 xen_setup_features();
27191
27192 @@ -1322,13 +1330,6 @@ asmlinkage void __init xen_start_kernel(void)
27193
27194 machine_ops = xen_machine_ops;
27195
27196 - /*
27197 - * The only reliable way to retain the initial address of the
27198 - * percpu gdt_page is to remember it here, so we can go and
27199 - * mark it RW later, when the initial percpu area is freed.
27200 - */
27201 - xen_initial_gdt = &per_cpu(gdt_page, 0);
27202 -
27203 xen_smp_init();
27204
27205 #ifdef CONFIG_ACPI_NUMA
27206 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27207 index 69f5857..0699dc5 100644
27208 --- a/arch/x86/xen/mmu.c
27209 +++ b/arch/x86/xen/mmu.c
27210 @@ -1738,6 +1738,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27211 convert_pfn_mfn(init_level4_pgt);
27212 convert_pfn_mfn(level3_ident_pgt);
27213 convert_pfn_mfn(level3_kernel_pgt);
27214 + convert_pfn_mfn(level3_vmalloc_start_pgt);
27215 + convert_pfn_mfn(level3_vmalloc_end_pgt);
27216 + convert_pfn_mfn(level3_vmemmap_pgt);
27217
27218 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27219 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27220 @@ -1756,7 +1759,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27221 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27222 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27223 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27224 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27225 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27226 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27227 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27228 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27229 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27230 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27231
27232 @@ -1964,6 +1971,7 @@ static void __init xen_post_allocator_init(void)
27233 pv_mmu_ops.set_pud = xen_set_pud;
27234 #if PAGETABLE_LEVELS == 4
27235 pv_mmu_ops.set_pgd = xen_set_pgd;
27236 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27237 #endif
27238
27239 /* This will work as long as patching hasn't happened yet
27240 @@ -2045,6 +2053,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27241 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27242 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27243 .set_pgd = xen_set_pgd_hyper,
27244 + .set_pgd_batched = xen_set_pgd_hyper,
27245
27246 .alloc_pud = xen_alloc_pmd_init,
27247 .release_pud = xen_release_pmd_init,
27248 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27249 index 0503c0c..ceb2d16 100644
27250 --- a/arch/x86/xen/smp.c
27251 +++ b/arch/x86/xen/smp.c
27252 @@ -215,11 +215,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27253 {
27254 BUG_ON(smp_processor_id() != 0);
27255 native_smp_prepare_boot_cpu();
27256 -
27257 - /* We've switched to the "real" per-cpu gdt, so make sure the
27258 - old memory can be recycled */
27259 - make_lowmem_page_readwrite(xen_initial_gdt);
27260 -
27261 xen_filter_cpu_maps();
27262 xen_setup_vcpu_info_placement();
27263 }
27264 @@ -296,12 +291,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27265 gdt = get_cpu_gdt_table(cpu);
27266
27267 ctxt->flags = VGCF_IN_KERNEL;
27268 - ctxt->user_regs.ds = __USER_DS;
27269 - ctxt->user_regs.es = __USER_DS;
27270 + ctxt->user_regs.ds = __KERNEL_DS;
27271 + ctxt->user_regs.es = __KERNEL_DS;
27272 ctxt->user_regs.ss = __KERNEL_DS;
27273 #ifdef CONFIG_X86_32
27274 ctxt->user_regs.fs = __KERNEL_PERCPU;
27275 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27276 + savesegment(gs, ctxt->user_regs.gs);
27277 #else
27278 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27279 #endif
27280 @@ -352,13 +347,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu)
27281 int rc;
27282
27283 per_cpu(current_task, cpu) = idle;
27284 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27285 #ifdef CONFIG_X86_32
27286 irq_ctx_init(cpu);
27287 #else
27288 clear_tsk_thread_flag(idle, TIF_FORK);
27289 - per_cpu(kernel_stack, cpu) =
27290 - (unsigned long)task_stack_page(idle) -
27291 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27292 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27293 #endif
27294 xen_setup_runstate_info(cpu);
27295 xen_setup_timer(cpu);
27296 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27297 index b040b0e..8cc4fe0 100644
27298 --- a/arch/x86/xen/xen-asm_32.S
27299 +++ b/arch/x86/xen/xen-asm_32.S
27300 @@ -83,14 +83,14 @@ ENTRY(xen_iret)
27301 ESP_OFFSET=4 # bytes pushed onto stack
27302
27303 /*
27304 - * Store vcpu_info pointer for easy access. Do it this way to
27305 - * avoid having to reload %fs
27306 + * Store vcpu_info pointer for easy access.
27307 */
27308 #ifdef CONFIG_SMP
27309 - GET_THREAD_INFO(%eax)
27310 - movl TI_cpu(%eax), %eax
27311 - movl __per_cpu_offset(,%eax,4), %eax
27312 - mov xen_vcpu(%eax), %eax
27313 + push %fs
27314 + mov $(__KERNEL_PERCPU), %eax
27315 + mov %eax, %fs
27316 + mov PER_CPU_VAR(xen_vcpu), %eax
27317 + pop %fs
27318 #else
27319 movl xen_vcpu, %eax
27320 #endif
27321 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27322 index aaa7291..3f77960 100644
27323 --- a/arch/x86/xen/xen-head.S
27324 +++ b/arch/x86/xen/xen-head.S
27325 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
27326 #ifdef CONFIG_X86_32
27327 mov %esi,xen_start_info
27328 mov $init_thread_union+THREAD_SIZE,%esp
27329 +#ifdef CONFIG_SMP
27330 + movl $cpu_gdt_table,%edi
27331 + movl $__per_cpu_load,%eax
27332 + movw %ax,__KERNEL_PERCPU + 2(%edi)
27333 + rorl $16,%eax
27334 + movb %al,__KERNEL_PERCPU + 4(%edi)
27335 + movb %ah,__KERNEL_PERCPU + 7(%edi)
27336 + movl $__per_cpu_end - 1,%eax
27337 + subl $__per_cpu_start,%eax
27338 + movw %ax,__KERNEL_PERCPU + 0(%edi)
27339 +#endif
27340 #else
27341 mov %rsi,xen_start_info
27342 mov $init_thread_union+THREAD_SIZE,%rsp
27343 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27344 index b095739..8c17bcd 100644
27345 --- a/arch/x86/xen/xen-ops.h
27346 +++ b/arch/x86/xen/xen-ops.h
27347 @@ -10,8 +10,6 @@
27348 extern const char xen_hypervisor_callback[];
27349 extern const char xen_failsafe_callback[];
27350
27351 -extern void *xen_initial_gdt;
27352 -
27353 struct trap_info;
27354 void xen_copy_trap_info(struct trap_info *traps);
27355
27356 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27357 index 525bd3d..ef888b1 100644
27358 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
27359 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27360 @@ -119,9 +119,9 @@
27361 ----------------------------------------------------------------------*/
27362
27363 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27364 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27365 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27366 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27367 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27368
27369 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27370 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27371 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27372 index 2f33760..835e50a 100644
27373 --- a/arch/xtensa/variants/fsf/include/variant/core.h
27374 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
27375 @@ -11,6 +11,7 @@
27376 #ifndef _XTENSA_CORE_H
27377 #define _XTENSA_CORE_H
27378
27379 +#include <linux/const.h>
27380
27381 /****************************************************************************
27382 Parameters Useful for Any Code, USER or PRIVILEGED
27383 @@ -112,9 +113,9 @@
27384 ----------------------------------------------------------------------*/
27385
27386 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27387 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27388 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27389 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27390 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27391
27392 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27393 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27394 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27395 index af00795..2bb8105 100644
27396 --- a/arch/xtensa/variants/s6000/include/variant/core.h
27397 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
27398 @@ -11,6 +11,7 @@
27399 #ifndef _XTENSA_CORE_CONFIGURATION_H
27400 #define _XTENSA_CORE_CONFIGURATION_H
27401
27402 +#include <linux/const.h>
27403
27404 /****************************************************************************
27405 Parameters Useful for Any Code, USER or PRIVILEGED
27406 @@ -118,9 +119,9 @@
27407 ----------------------------------------------------------------------*/
27408
27409 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27410 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27411 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27412 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27413 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27414
27415 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27416 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27417 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27418 index 58916af..9cb880b 100644
27419 --- a/block/blk-iopoll.c
27420 +++ b/block/blk-iopoll.c
27421 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27422 }
27423 EXPORT_SYMBOL(blk_iopoll_complete);
27424
27425 -static void blk_iopoll_softirq(struct softirq_action *h)
27426 +static void blk_iopoll_softirq(void)
27427 {
27428 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27429 int rearm = 0, budget = blk_iopoll_budget;
27430 diff --git a/block/blk-map.c b/block/blk-map.c
27431 index 623e1cd..ca1e109 100644
27432 --- a/block/blk-map.c
27433 +++ b/block/blk-map.c
27434 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27435 if (!len || !kbuf)
27436 return -EINVAL;
27437
27438 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27439 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27440 if (do_copy)
27441 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27442 else
27443 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27444 index 467c8de..4bddc6d 100644
27445 --- a/block/blk-softirq.c
27446 +++ b/block/blk-softirq.c
27447 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27448 * Softirq action handler - move entries to local list and loop over them
27449 * while passing them to the queue registered handler.
27450 */
27451 -static void blk_done_softirq(struct softirq_action *h)
27452 +static void blk_done_softirq(void)
27453 {
27454 struct list_head *cpu_list, local_list;
27455
27456 diff --git a/block/bsg.c b/block/bsg.c
27457 index ff64ae3..593560c 100644
27458 --- a/block/bsg.c
27459 +++ b/block/bsg.c
27460 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27461 struct sg_io_v4 *hdr, struct bsg_device *bd,
27462 fmode_t has_write_perm)
27463 {
27464 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27465 + unsigned char *cmdptr;
27466 +
27467 if (hdr->request_len > BLK_MAX_CDB) {
27468 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27469 if (!rq->cmd)
27470 return -ENOMEM;
27471 - }
27472 + cmdptr = rq->cmd;
27473 + } else
27474 + cmdptr = tmpcmd;
27475
27476 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27477 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27478 hdr->request_len))
27479 return -EFAULT;
27480
27481 + if (cmdptr != rq->cmd)
27482 + memcpy(rq->cmd, cmdptr, hdr->request_len);
27483 +
27484 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27485 if (blk_verify_command(rq->cmd, has_write_perm))
27486 return -EPERM;
27487 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27488 index 7c668c8..db3521c 100644
27489 --- a/block/compat_ioctl.c
27490 +++ b/block/compat_ioctl.c
27491 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27492 err |= __get_user(f->spec1, &uf->spec1);
27493 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27494 err |= __get_user(name, &uf->name);
27495 - f->name = compat_ptr(name);
27496 + f->name = (void __force_kernel *)compat_ptr(name);
27497 if (err) {
27498 err = -EFAULT;
27499 goto out;
27500 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27501 index 6296b40..417c00f 100644
27502 --- a/block/partitions/efi.c
27503 +++ b/block/partitions/efi.c
27504 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27505 if (!gpt)
27506 return NULL;
27507
27508 + if (!le32_to_cpu(gpt->num_partition_entries))
27509 + return NULL;
27510 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27511 + if (!pte)
27512 + return NULL;
27513 +
27514 count = le32_to_cpu(gpt->num_partition_entries) *
27515 le32_to_cpu(gpt->sizeof_partition_entry);
27516 - if (!count)
27517 - return NULL;
27518 - pte = kzalloc(count, GFP_KERNEL);
27519 - if (!pte)
27520 - return NULL;
27521 -
27522 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27523 (u8 *) pte,
27524 count) < count) {
27525 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27526 index 260fa80..e8f3caf 100644
27527 --- a/block/scsi_ioctl.c
27528 +++ b/block/scsi_ioctl.c
27529 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27530 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27531 struct sg_io_hdr *hdr, fmode_t mode)
27532 {
27533 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27534 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27535 + unsigned char *cmdptr;
27536 +
27537 + if (rq->cmd != rq->__cmd)
27538 + cmdptr = rq->cmd;
27539 + else
27540 + cmdptr = tmpcmd;
27541 +
27542 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27543 return -EFAULT;
27544 +
27545 + if (cmdptr != rq->cmd)
27546 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27547 +
27548 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27549 return -EPERM;
27550
27551 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27552 int err;
27553 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27554 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27555 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27556 + unsigned char *cmdptr;
27557
27558 if (!sic)
27559 return -EINVAL;
27560 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27561 */
27562 err = -EFAULT;
27563 rq->cmd_len = cmdlen;
27564 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
27565 +
27566 + if (rq->cmd != rq->__cmd)
27567 + cmdptr = rq->cmd;
27568 + else
27569 + cmdptr = tmpcmd;
27570 +
27571 + if (copy_from_user(cmdptr, sic->data, cmdlen))
27572 goto error;
27573
27574 + if (rq->cmd != cmdptr)
27575 + memcpy(rq->cmd, cmdptr, cmdlen);
27576 +
27577 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27578 goto error;
27579
27580 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27581 index 671d4d6..5f24030 100644
27582 --- a/crypto/cryptd.c
27583 +++ b/crypto/cryptd.c
27584 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27585
27586 struct cryptd_blkcipher_request_ctx {
27587 crypto_completion_t complete;
27588 -};
27589 +} __no_const;
27590
27591 struct cryptd_hash_ctx {
27592 struct crypto_shash *child;
27593 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27594
27595 struct cryptd_aead_request_ctx {
27596 crypto_completion_t complete;
27597 -};
27598 +} __no_const;
27599
27600 static void cryptd_queue_worker(struct work_struct *work);
27601
27602 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27603 index e6defd8..c26a225 100644
27604 --- a/drivers/acpi/apei/cper.c
27605 +++ b/drivers/acpi/apei/cper.c
27606 @@ -38,12 +38,12 @@
27607 */
27608 u64 cper_next_record_id(void)
27609 {
27610 - static atomic64_t seq;
27611 + static atomic64_unchecked_t seq;
27612
27613 - if (!atomic64_read(&seq))
27614 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
27615 + if (!atomic64_read_unchecked(&seq))
27616 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27617
27618 - return atomic64_inc_return(&seq);
27619 + return atomic64_inc_return_unchecked(&seq);
27620 }
27621 EXPORT_SYMBOL_GPL(cper_next_record_id);
27622
27623 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27624 index 7586544..636a2f0 100644
27625 --- a/drivers/acpi/ec_sys.c
27626 +++ b/drivers/acpi/ec_sys.c
27627 @@ -12,6 +12,7 @@
27628 #include <linux/acpi.h>
27629 #include <linux/debugfs.h>
27630 #include <linux/module.h>
27631 +#include <linux/uaccess.h>
27632 #include "internal.h"
27633
27634 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27635 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27636 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27637 */
27638 unsigned int size = EC_SPACE_SIZE;
27639 - u8 *data = (u8 *) buf;
27640 + u8 data;
27641 loff_t init_off = *off;
27642 int err = 0;
27643
27644 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27645 size = count;
27646
27647 while (size) {
27648 - err = ec_read(*off, &data[*off - init_off]);
27649 + err = ec_read(*off, &data);
27650 if (err)
27651 return err;
27652 + if (put_user(data, &buf[*off - init_off]))
27653 + return -EFAULT;
27654 *off += 1;
27655 size--;
27656 }
27657 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27658
27659 unsigned int size = count;
27660 loff_t init_off = *off;
27661 - u8 *data = (u8 *) buf;
27662 int err = 0;
27663
27664 if (*off >= EC_SPACE_SIZE)
27665 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27666 }
27667
27668 while (size) {
27669 - u8 byte_write = data[*off - init_off];
27670 + u8 byte_write;
27671 + if (get_user(byte_write, &buf[*off - init_off]))
27672 + return -EFAULT;
27673 err = ec_write(*off, byte_write);
27674 if (err)
27675 return err;
27676 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27677 index 251c7b62..000462d 100644
27678 --- a/drivers/acpi/proc.c
27679 +++ b/drivers/acpi/proc.c
27680 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27681 size_t count, loff_t * ppos)
27682 {
27683 struct list_head *node, *next;
27684 - char strbuf[5];
27685 - char str[5] = "";
27686 - unsigned int len = count;
27687 + char strbuf[5] = {0};
27688
27689 - if (len > 4)
27690 - len = 4;
27691 - if (len < 0)
27692 + if (count > 4)
27693 + count = 4;
27694 + if (copy_from_user(strbuf, buffer, count))
27695 return -EFAULT;
27696 -
27697 - if (copy_from_user(strbuf, buffer, len))
27698 - return -EFAULT;
27699 - strbuf[len] = '\0';
27700 - sscanf(strbuf, "%s", str);
27701 + strbuf[count] = '\0';
27702
27703 mutex_lock(&acpi_device_lock);
27704 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27705 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27706 if (!dev->wakeup.flags.valid)
27707 continue;
27708
27709 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
27710 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27711 if (device_can_wakeup(&dev->dev)) {
27712 bool enable = !device_may_wakeup(&dev->dev);
27713 device_set_wakeup_enable(&dev->dev, enable);
27714 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27715 index 0734086..3ad3e4c 100644
27716 --- a/drivers/acpi/processor_driver.c
27717 +++ b/drivers/acpi/processor_driver.c
27718 @@ -556,7 +556,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27719 return 0;
27720 #endif
27721
27722 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27723 + BUG_ON(pr->id >= nr_cpu_ids);
27724
27725 /*
27726 * Buggy BIOS check
27727 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27728 index d31ee55..8363a8b 100644
27729 --- a/drivers/ata/libata-core.c
27730 +++ b/drivers/ata/libata-core.c
27731 @@ -4742,7 +4742,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27732 struct ata_port *ap;
27733 unsigned int tag;
27734
27735 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27736 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27737 ap = qc->ap;
27738
27739 qc->flags = 0;
27740 @@ -4758,7 +4758,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27741 struct ata_port *ap;
27742 struct ata_link *link;
27743
27744 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27745 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27746 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27747 ap = qc->ap;
27748 link = qc->dev->link;
27749 @@ -5822,6 +5822,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27750 return;
27751
27752 spin_lock(&lock);
27753 + pax_open_kernel();
27754
27755 for (cur = ops->inherits; cur; cur = cur->inherits) {
27756 void **inherit = (void **)cur;
27757 @@ -5835,8 +5836,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27758 if (IS_ERR(*pp))
27759 *pp = NULL;
27760
27761 - ops->inherits = NULL;
27762 + *(struct ata_port_operations **)&ops->inherits = NULL;
27763
27764 + pax_close_kernel();
27765 spin_unlock(&lock);
27766 }
27767
27768 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27769 index 3239517..343b5f6 100644
27770 --- a/drivers/ata/pata_arasan_cf.c
27771 +++ b/drivers/ata/pata_arasan_cf.c
27772 @@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27773 /* Handle platform specific quirks */
27774 if (pdata->quirk) {
27775 if (pdata->quirk & CF_BROKEN_PIO) {
27776 - ap->ops->set_piomode = NULL;
27777 + pax_open_kernel();
27778 + *(void **)&ap->ops->set_piomode = NULL;
27779 + pax_close_kernel();
27780 ap->pio_mask = 0;
27781 }
27782 if (pdata->quirk & CF_BROKEN_MWDMA)
27783 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27784 index f9b983a..887b9d8 100644
27785 --- a/drivers/atm/adummy.c
27786 +++ b/drivers/atm/adummy.c
27787 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27788 vcc->pop(vcc, skb);
27789 else
27790 dev_kfree_skb_any(skb);
27791 - atomic_inc(&vcc->stats->tx);
27792 + atomic_inc_unchecked(&vcc->stats->tx);
27793
27794 return 0;
27795 }
27796 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27797 index f8f41e0..1f987dd 100644
27798 --- a/drivers/atm/ambassador.c
27799 +++ b/drivers/atm/ambassador.c
27800 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27801 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27802
27803 // VC layer stats
27804 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27805 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27806
27807 // free the descriptor
27808 kfree (tx_descr);
27809 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27810 dump_skb ("<<<", vc, skb);
27811
27812 // VC layer stats
27813 - atomic_inc(&atm_vcc->stats->rx);
27814 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27815 __net_timestamp(skb);
27816 // end of our responsibility
27817 atm_vcc->push (atm_vcc, skb);
27818 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27819 } else {
27820 PRINTK (KERN_INFO, "dropped over-size frame");
27821 // should we count this?
27822 - atomic_inc(&atm_vcc->stats->rx_drop);
27823 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27824 }
27825
27826 } else {
27827 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
27828 }
27829
27830 if (check_area (skb->data, skb->len)) {
27831 - atomic_inc(&atm_vcc->stats->tx_err);
27832 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
27833 return -ENOMEM; // ?
27834 }
27835
27836 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
27837 index b22d71c..d6e1049 100644
27838 --- a/drivers/atm/atmtcp.c
27839 +++ b/drivers/atm/atmtcp.c
27840 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27841 if (vcc->pop) vcc->pop(vcc,skb);
27842 else dev_kfree_skb(skb);
27843 if (dev_data) return 0;
27844 - atomic_inc(&vcc->stats->tx_err);
27845 + atomic_inc_unchecked(&vcc->stats->tx_err);
27846 return -ENOLINK;
27847 }
27848 size = skb->len+sizeof(struct atmtcp_hdr);
27849 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27850 if (!new_skb) {
27851 if (vcc->pop) vcc->pop(vcc,skb);
27852 else dev_kfree_skb(skb);
27853 - atomic_inc(&vcc->stats->tx_err);
27854 + atomic_inc_unchecked(&vcc->stats->tx_err);
27855 return -ENOBUFS;
27856 }
27857 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
27858 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27859 if (vcc->pop) vcc->pop(vcc,skb);
27860 else dev_kfree_skb(skb);
27861 out_vcc->push(out_vcc,new_skb);
27862 - atomic_inc(&vcc->stats->tx);
27863 - atomic_inc(&out_vcc->stats->rx);
27864 + atomic_inc_unchecked(&vcc->stats->tx);
27865 + atomic_inc_unchecked(&out_vcc->stats->rx);
27866 return 0;
27867 }
27868
27869 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27870 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
27871 read_unlock(&vcc_sklist_lock);
27872 if (!out_vcc) {
27873 - atomic_inc(&vcc->stats->tx_err);
27874 + atomic_inc_unchecked(&vcc->stats->tx_err);
27875 goto done;
27876 }
27877 skb_pull(skb,sizeof(struct atmtcp_hdr));
27878 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27879 __net_timestamp(new_skb);
27880 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
27881 out_vcc->push(out_vcc,new_skb);
27882 - atomic_inc(&vcc->stats->tx);
27883 - atomic_inc(&out_vcc->stats->rx);
27884 + atomic_inc_unchecked(&vcc->stats->tx);
27885 + atomic_inc_unchecked(&out_vcc->stats->rx);
27886 done:
27887 if (vcc->pop) vcc->pop(vcc,skb);
27888 else dev_kfree_skb(skb);
27889 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
27890 index 2059ee4..faf51c7 100644
27891 --- a/drivers/atm/eni.c
27892 +++ b/drivers/atm/eni.c
27893 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
27894 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
27895 vcc->dev->number);
27896 length = 0;
27897 - atomic_inc(&vcc->stats->rx_err);
27898 + atomic_inc_unchecked(&vcc->stats->rx_err);
27899 }
27900 else {
27901 length = ATM_CELL_SIZE-1; /* no HEC */
27902 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27903 size);
27904 }
27905 eff = length = 0;
27906 - atomic_inc(&vcc->stats->rx_err);
27907 + atomic_inc_unchecked(&vcc->stats->rx_err);
27908 }
27909 else {
27910 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
27911 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27912 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
27913 vcc->dev->number,vcc->vci,length,size << 2,descr);
27914 length = eff = 0;
27915 - atomic_inc(&vcc->stats->rx_err);
27916 + atomic_inc_unchecked(&vcc->stats->rx_err);
27917 }
27918 }
27919 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
27920 @@ -767,7 +767,7 @@ rx_dequeued++;
27921 vcc->push(vcc,skb);
27922 pushed++;
27923 }
27924 - atomic_inc(&vcc->stats->rx);
27925 + atomic_inc_unchecked(&vcc->stats->rx);
27926 }
27927 wake_up(&eni_dev->rx_wait);
27928 }
27929 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
27930 PCI_DMA_TODEVICE);
27931 if (vcc->pop) vcc->pop(vcc,skb);
27932 else dev_kfree_skb_irq(skb);
27933 - atomic_inc(&vcc->stats->tx);
27934 + atomic_inc_unchecked(&vcc->stats->tx);
27935 wake_up(&eni_dev->tx_wait);
27936 dma_complete++;
27937 }
27938 @@ -1567,7 +1567,7 @@ tx_complete++;
27939 /*--------------------------------- entries ---------------------------------*/
27940
27941
27942 -static const char *media_name[] __devinitdata = {
27943 +static const char *media_name[] __devinitconst = {
27944 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
27945 "UTP", "05?", "06?", "07?", /* 4- 7 */
27946 "TAXI","09?", "10?", "11?", /* 8-11 */
27947 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
27948 index 86fed1b..6dc4721 100644
27949 --- a/drivers/atm/firestream.c
27950 +++ b/drivers/atm/firestream.c
27951 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
27952 }
27953 }
27954
27955 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27956 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27957
27958 fs_dprintk (FS_DEBUG_TXMEM, "i");
27959 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
27960 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27961 #endif
27962 skb_put (skb, qe->p1 & 0xffff);
27963 ATM_SKB(skb)->vcc = atm_vcc;
27964 - atomic_inc(&atm_vcc->stats->rx);
27965 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27966 __net_timestamp(skb);
27967 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
27968 atm_vcc->push (atm_vcc, skb);
27969 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27970 kfree (pe);
27971 }
27972 if (atm_vcc)
27973 - atomic_inc(&atm_vcc->stats->rx_drop);
27974 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27975 break;
27976 case 0x1f: /* Reassembly abort: no buffers. */
27977 /* Silently increment error counter. */
27978 if (atm_vcc)
27979 - atomic_inc(&atm_vcc->stats->rx_drop);
27980 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27981 break;
27982 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
27983 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
27984 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
27985 index 361f5ae..7fc552d 100644
27986 --- a/drivers/atm/fore200e.c
27987 +++ b/drivers/atm/fore200e.c
27988 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
27989 #endif
27990 /* check error condition */
27991 if (*entry->status & STATUS_ERROR)
27992 - atomic_inc(&vcc->stats->tx_err);
27993 + atomic_inc_unchecked(&vcc->stats->tx_err);
27994 else
27995 - atomic_inc(&vcc->stats->tx);
27996 + atomic_inc_unchecked(&vcc->stats->tx);
27997 }
27998 }
27999
28000 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28001 if (skb == NULL) {
28002 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
28003
28004 - atomic_inc(&vcc->stats->rx_drop);
28005 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28006 return -ENOMEM;
28007 }
28008
28009 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28010
28011 dev_kfree_skb_any(skb);
28012
28013 - atomic_inc(&vcc->stats->rx_drop);
28014 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28015 return -ENOMEM;
28016 }
28017
28018 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28019
28020 vcc->push(vcc, skb);
28021 - atomic_inc(&vcc->stats->rx);
28022 + atomic_inc_unchecked(&vcc->stats->rx);
28023
28024 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28025
28026 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
28027 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
28028 fore200e->atm_dev->number,
28029 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
28030 - atomic_inc(&vcc->stats->rx_err);
28031 + atomic_inc_unchecked(&vcc->stats->rx_err);
28032 }
28033 }
28034
28035 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
28036 goto retry_here;
28037 }
28038
28039 - atomic_inc(&vcc->stats->tx_err);
28040 + atomic_inc_unchecked(&vcc->stats->tx_err);
28041
28042 fore200e->tx_sat++;
28043 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
28044 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
28045 index b182c2f..1c6fa8a 100644
28046 --- a/drivers/atm/he.c
28047 +++ b/drivers/atm/he.c
28048 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28049
28050 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
28051 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
28052 - atomic_inc(&vcc->stats->rx_drop);
28053 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28054 goto return_host_buffers;
28055 }
28056
28057 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28058 RBRQ_LEN_ERR(he_dev->rbrq_head)
28059 ? "LEN_ERR" : "",
28060 vcc->vpi, vcc->vci);
28061 - atomic_inc(&vcc->stats->rx_err);
28062 + atomic_inc_unchecked(&vcc->stats->rx_err);
28063 goto return_host_buffers;
28064 }
28065
28066 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28067 vcc->push(vcc, skb);
28068 spin_lock(&he_dev->global_lock);
28069
28070 - atomic_inc(&vcc->stats->rx);
28071 + atomic_inc_unchecked(&vcc->stats->rx);
28072
28073 return_host_buffers:
28074 ++pdus_assembled;
28075 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28076 tpd->vcc->pop(tpd->vcc, tpd->skb);
28077 else
28078 dev_kfree_skb_any(tpd->skb);
28079 - atomic_inc(&tpd->vcc->stats->tx_err);
28080 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28081 }
28082 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28083 return;
28084 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28085 vcc->pop(vcc, skb);
28086 else
28087 dev_kfree_skb_any(skb);
28088 - atomic_inc(&vcc->stats->tx_err);
28089 + atomic_inc_unchecked(&vcc->stats->tx_err);
28090 return -EINVAL;
28091 }
28092
28093 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28094 vcc->pop(vcc, skb);
28095 else
28096 dev_kfree_skb_any(skb);
28097 - atomic_inc(&vcc->stats->tx_err);
28098 + atomic_inc_unchecked(&vcc->stats->tx_err);
28099 return -EINVAL;
28100 }
28101 #endif
28102 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28103 vcc->pop(vcc, skb);
28104 else
28105 dev_kfree_skb_any(skb);
28106 - atomic_inc(&vcc->stats->tx_err);
28107 + atomic_inc_unchecked(&vcc->stats->tx_err);
28108 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28109 return -ENOMEM;
28110 }
28111 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28112 vcc->pop(vcc, skb);
28113 else
28114 dev_kfree_skb_any(skb);
28115 - atomic_inc(&vcc->stats->tx_err);
28116 + atomic_inc_unchecked(&vcc->stats->tx_err);
28117 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28118 return -ENOMEM;
28119 }
28120 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28121 __enqueue_tpd(he_dev, tpd, cid);
28122 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28123
28124 - atomic_inc(&vcc->stats->tx);
28125 + atomic_inc_unchecked(&vcc->stats->tx);
28126
28127 return 0;
28128 }
28129 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28130 index 75fd691..2d20b14 100644
28131 --- a/drivers/atm/horizon.c
28132 +++ b/drivers/atm/horizon.c
28133 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28134 {
28135 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28136 // VC layer stats
28137 - atomic_inc(&vcc->stats->rx);
28138 + atomic_inc_unchecked(&vcc->stats->rx);
28139 __net_timestamp(skb);
28140 // end of our responsibility
28141 vcc->push (vcc, skb);
28142 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28143 dev->tx_iovec = NULL;
28144
28145 // VC layer stats
28146 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28147 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28148
28149 // free the skb
28150 hrz_kfree_skb (skb);
28151 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28152 index 1c05212..c28e200 100644
28153 --- a/drivers/atm/idt77252.c
28154 +++ b/drivers/atm/idt77252.c
28155 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28156 else
28157 dev_kfree_skb(skb);
28158
28159 - atomic_inc(&vcc->stats->tx);
28160 + atomic_inc_unchecked(&vcc->stats->tx);
28161 }
28162
28163 atomic_dec(&scq->used);
28164 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28165 if ((sb = dev_alloc_skb(64)) == NULL) {
28166 printk("%s: Can't allocate buffers for aal0.\n",
28167 card->name);
28168 - atomic_add(i, &vcc->stats->rx_drop);
28169 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28170 break;
28171 }
28172 if (!atm_charge(vcc, sb->truesize)) {
28173 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28174 card->name);
28175 - atomic_add(i - 1, &vcc->stats->rx_drop);
28176 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28177 dev_kfree_skb(sb);
28178 break;
28179 }
28180 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28181 ATM_SKB(sb)->vcc = vcc;
28182 __net_timestamp(sb);
28183 vcc->push(vcc, sb);
28184 - atomic_inc(&vcc->stats->rx);
28185 + atomic_inc_unchecked(&vcc->stats->rx);
28186
28187 cell += ATM_CELL_PAYLOAD;
28188 }
28189 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28190 "(CDC: %08x)\n",
28191 card->name, len, rpp->len, readl(SAR_REG_CDC));
28192 recycle_rx_pool_skb(card, rpp);
28193 - atomic_inc(&vcc->stats->rx_err);
28194 + atomic_inc_unchecked(&vcc->stats->rx_err);
28195 return;
28196 }
28197 if (stat & SAR_RSQE_CRC) {
28198 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28199 recycle_rx_pool_skb(card, rpp);
28200 - atomic_inc(&vcc->stats->rx_err);
28201 + atomic_inc_unchecked(&vcc->stats->rx_err);
28202 return;
28203 }
28204 if (skb_queue_len(&rpp->queue) > 1) {
28205 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28206 RXPRINTK("%s: Can't alloc RX skb.\n",
28207 card->name);
28208 recycle_rx_pool_skb(card, rpp);
28209 - atomic_inc(&vcc->stats->rx_err);
28210 + atomic_inc_unchecked(&vcc->stats->rx_err);
28211 return;
28212 }
28213 if (!atm_charge(vcc, skb->truesize)) {
28214 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28215 __net_timestamp(skb);
28216
28217 vcc->push(vcc, skb);
28218 - atomic_inc(&vcc->stats->rx);
28219 + atomic_inc_unchecked(&vcc->stats->rx);
28220
28221 return;
28222 }
28223 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28224 __net_timestamp(skb);
28225
28226 vcc->push(vcc, skb);
28227 - atomic_inc(&vcc->stats->rx);
28228 + atomic_inc_unchecked(&vcc->stats->rx);
28229
28230 if (skb->truesize > SAR_FB_SIZE_3)
28231 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28232 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28233 if (vcc->qos.aal != ATM_AAL0) {
28234 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28235 card->name, vpi, vci);
28236 - atomic_inc(&vcc->stats->rx_drop);
28237 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28238 goto drop;
28239 }
28240
28241 if ((sb = dev_alloc_skb(64)) == NULL) {
28242 printk("%s: Can't allocate buffers for AAL0.\n",
28243 card->name);
28244 - atomic_inc(&vcc->stats->rx_err);
28245 + atomic_inc_unchecked(&vcc->stats->rx_err);
28246 goto drop;
28247 }
28248
28249 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28250 ATM_SKB(sb)->vcc = vcc;
28251 __net_timestamp(sb);
28252 vcc->push(vcc, sb);
28253 - atomic_inc(&vcc->stats->rx);
28254 + atomic_inc_unchecked(&vcc->stats->rx);
28255
28256 drop:
28257 skb_pull(queue, 64);
28258 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28259
28260 if (vc == NULL) {
28261 printk("%s: NULL connection in send().\n", card->name);
28262 - atomic_inc(&vcc->stats->tx_err);
28263 + atomic_inc_unchecked(&vcc->stats->tx_err);
28264 dev_kfree_skb(skb);
28265 return -EINVAL;
28266 }
28267 if (!test_bit(VCF_TX, &vc->flags)) {
28268 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28269 - atomic_inc(&vcc->stats->tx_err);
28270 + atomic_inc_unchecked(&vcc->stats->tx_err);
28271 dev_kfree_skb(skb);
28272 return -EINVAL;
28273 }
28274 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28275 break;
28276 default:
28277 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28278 - atomic_inc(&vcc->stats->tx_err);
28279 + atomic_inc_unchecked(&vcc->stats->tx_err);
28280 dev_kfree_skb(skb);
28281 return -EINVAL;
28282 }
28283
28284 if (skb_shinfo(skb)->nr_frags != 0) {
28285 printk("%s: No scatter-gather yet.\n", card->name);
28286 - atomic_inc(&vcc->stats->tx_err);
28287 + atomic_inc_unchecked(&vcc->stats->tx_err);
28288 dev_kfree_skb(skb);
28289 return -EINVAL;
28290 }
28291 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28292
28293 err = queue_skb(card, vc, skb, oam);
28294 if (err) {
28295 - atomic_inc(&vcc->stats->tx_err);
28296 + atomic_inc_unchecked(&vcc->stats->tx_err);
28297 dev_kfree_skb(skb);
28298 return err;
28299 }
28300 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28301 skb = dev_alloc_skb(64);
28302 if (!skb) {
28303 printk("%s: Out of memory in send_oam().\n", card->name);
28304 - atomic_inc(&vcc->stats->tx_err);
28305 + atomic_inc_unchecked(&vcc->stats->tx_err);
28306 return -ENOMEM;
28307 }
28308 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28309 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28310 index d438601..8b98495 100644
28311 --- a/drivers/atm/iphase.c
28312 +++ b/drivers/atm/iphase.c
28313 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28314 status = (u_short) (buf_desc_ptr->desc_mode);
28315 if (status & (RX_CER | RX_PTE | RX_OFL))
28316 {
28317 - atomic_inc(&vcc->stats->rx_err);
28318 + atomic_inc_unchecked(&vcc->stats->rx_err);
28319 IF_ERR(printk("IA: bad packet, dropping it");)
28320 if (status & RX_CER) {
28321 IF_ERR(printk(" cause: packet CRC error\n");)
28322 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28323 len = dma_addr - buf_addr;
28324 if (len > iadev->rx_buf_sz) {
28325 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28326 - atomic_inc(&vcc->stats->rx_err);
28327 + atomic_inc_unchecked(&vcc->stats->rx_err);
28328 goto out_free_desc;
28329 }
28330
28331 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28332 ia_vcc = INPH_IA_VCC(vcc);
28333 if (ia_vcc == NULL)
28334 {
28335 - atomic_inc(&vcc->stats->rx_err);
28336 + atomic_inc_unchecked(&vcc->stats->rx_err);
28337 atm_return(vcc, skb->truesize);
28338 dev_kfree_skb_any(skb);
28339 goto INCR_DLE;
28340 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28341 if ((length > iadev->rx_buf_sz) || (length >
28342 (skb->len - sizeof(struct cpcs_trailer))))
28343 {
28344 - atomic_inc(&vcc->stats->rx_err);
28345 + atomic_inc_unchecked(&vcc->stats->rx_err);
28346 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28347 length, skb->len);)
28348 atm_return(vcc, skb->truesize);
28349 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28350
28351 IF_RX(printk("rx_dle_intr: skb push");)
28352 vcc->push(vcc,skb);
28353 - atomic_inc(&vcc->stats->rx);
28354 + atomic_inc_unchecked(&vcc->stats->rx);
28355 iadev->rx_pkt_cnt++;
28356 }
28357 INCR_DLE:
28358 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28359 {
28360 struct k_sonet_stats *stats;
28361 stats = &PRIV(_ia_dev[board])->sonet_stats;
28362 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28363 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28364 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28365 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28366 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28367 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28368 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28369 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28370 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28371 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28372 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28373 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28374 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28375 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28376 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28377 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28378 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28379 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28380 }
28381 ia_cmds.status = 0;
28382 break;
28383 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28384 if ((desc == 0) || (desc > iadev->num_tx_desc))
28385 {
28386 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28387 - atomic_inc(&vcc->stats->tx);
28388 + atomic_inc_unchecked(&vcc->stats->tx);
28389 if (vcc->pop)
28390 vcc->pop(vcc, skb);
28391 else
28392 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28393 ATM_DESC(skb) = vcc->vci;
28394 skb_queue_tail(&iadev->tx_dma_q, skb);
28395
28396 - atomic_inc(&vcc->stats->tx);
28397 + atomic_inc_unchecked(&vcc->stats->tx);
28398 iadev->tx_pkt_cnt++;
28399 /* Increment transaction counter */
28400 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28401
28402 #if 0
28403 /* add flow control logic */
28404 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28405 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28406 if (iavcc->vc_desc_cnt > 10) {
28407 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28408 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28409 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28410 index 68c7588..7036683 100644
28411 --- a/drivers/atm/lanai.c
28412 +++ b/drivers/atm/lanai.c
28413 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28414 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28415 lanai_endtx(lanai, lvcc);
28416 lanai_free_skb(lvcc->tx.atmvcc, skb);
28417 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28418 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28419 }
28420
28421 /* Try to fill the buffer - don't call unless there is backlog */
28422 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28423 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28424 __net_timestamp(skb);
28425 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28426 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28427 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28428 out:
28429 lvcc->rx.buf.ptr = end;
28430 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28431 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28432 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28433 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28434 lanai->stats.service_rxnotaal5++;
28435 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28436 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28437 return 0;
28438 }
28439 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28440 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28441 int bytes;
28442 read_unlock(&vcc_sklist_lock);
28443 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28444 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28445 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28446 lvcc->stats.x.aal5.service_trash++;
28447 bytes = (SERVICE_GET_END(s) * 16) -
28448 (((unsigned long) lvcc->rx.buf.ptr) -
28449 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28450 }
28451 if (s & SERVICE_STREAM) {
28452 read_unlock(&vcc_sklist_lock);
28453 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28454 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28455 lvcc->stats.x.aal5.service_stream++;
28456 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28457 "PDU on VCI %d!\n", lanai->number, vci);
28458 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28459 return 0;
28460 }
28461 DPRINTK("got rx crc error on vci %d\n", vci);
28462 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28463 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28464 lvcc->stats.x.aal5.service_rxcrc++;
28465 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28466 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28467 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28468 index 1c70c45..300718d 100644
28469 --- a/drivers/atm/nicstar.c
28470 +++ b/drivers/atm/nicstar.c
28471 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28472 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28473 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28474 card->index);
28475 - atomic_inc(&vcc->stats->tx_err);
28476 + atomic_inc_unchecked(&vcc->stats->tx_err);
28477 dev_kfree_skb_any(skb);
28478 return -EINVAL;
28479 }
28480 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28481 if (!vc->tx) {
28482 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28483 card->index);
28484 - atomic_inc(&vcc->stats->tx_err);
28485 + atomic_inc_unchecked(&vcc->stats->tx_err);
28486 dev_kfree_skb_any(skb);
28487 return -EINVAL;
28488 }
28489 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28490 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28491 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28492 card->index);
28493 - atomic_inc(&vcc->stats->tx_err);
28494 + atomic_inc_unchecked(&vcc->stats->tx_err);
28495 dev_kfree_skb_any(skb);
28496 return -EINVAL;
28497 }
28498
28499 if (skb_shinfo(skb)->nr_frags != 0) {
28500 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28501 - atomic_inc(&vcc->stats->tx_err);
28502 + atomic_inc_unchecked(&vcc->stats->tx_err);
28503 dev_kfree_skb_any(skb);
28504 return -EINVAL;
28505 }
28506 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28507 }
28508
28509 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28510 - atomic_inc(&vcc->stats->tx_err);
28511 + atomic_inc_unchecked(&vcc->stats->tx_err);
28512 dev_kfree_skb_any(skb);
28513 return -EIO;
28514 }
28515 - atomic_inc(&vcc->stats->tx);
28516 + atomic_inc_unchecked(&vcc->stats->tx);
28517
28518 return 0;
28519 }
28520 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28521 printk
28522 ("nicstar%d: Can't allocate buffers for aal0.\n",
28523 card->index);
28524 - atomic_add(i, &vcc->stats->rx_drop);
28525 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28526 break;
28527 }
28528 if (!atm_charge(vcc, sb->truesize)) {
28529 RXPRINTK
28530 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28531 card->index);
28532 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28533 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28534 dev_kfree_skb_any(sb);
28535 break;
28536 }
28537 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28538 ATM_SKB(sb)->vcc = vcc;
28539 __net_timestamp(sb);
28540 vcc->push(vcc, sb);
28541 - atomic_inc(&vcc->stats->rx);
28542 + atomic_inc_unchecked(&vcc->stats->rx);
28543 cell += ATM_CELL_PAYLOAD;
28544 }
28545
28546 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28547 if (iovb == NULL) {
28548 printk("nicstar%d: Out of iovec buffers.\n",
28549 card->index);
28550 - atomic_inc(&vcc->stats->rx_drop);
28551 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28552 recycle_rx_buf(card, skb);
28553 return;
28554 }
28555 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28556 small or large buffer itself. */
28557 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28558 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28559 - atomic_inc(&vcc->stats->rx_err);
28560 + atomic_inc_unchecked(&vcc->stats->rx_err);
28561 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28562 NS_MAX_IOVECS);
28563 NS_PRV_IOVCNT(iovb) = 0;
28564 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28565 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28566 card->index);
28567 which_list(card, skb);
28568 - atomic_inc(&vcc->stats->rx_err);
28569 + atomic_inc_unchecked(&vcc->stats->rx_err);
28570 recycle_rx_buf(card, skb);
28571 vc->rx_iov = NULL;
28572 recycle_iov_buf(card, iovb);
28573 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28574 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28575 card->index);
28576 which_list(card, skb);
28577 - atomic_inc(&vcc->stats->rx_err);
28578 + atomic_inc_unchecked(&vcc->stats->rx_err);
28579 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28580 NS_PRV_IOVCNT(iovb));
28581 vc->rx_iov = NULL;
28582 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28583 printk(" - PDU size mismatch.\n");
28584 else
28585 printk(".\n");
28586 - atomic_inc(&vcc->stats->rx_err);
28587 + atomic_inc_unchecked(&vcc->stats->rx_err);
28588 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28589 NS_PRV_IOVCNT(iovb));
28590 vc->rx_iov = NULL;
28591 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28592 /* skb points to a small buffer */
28593 if (!atm_charge(vcc, skb->truesize)) {
28594 push_rxbufs(card, skb);
28595 - atomic_inc(&vcc->stats->rx_drop);
28596 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28597 } else {
28598 skb_put(skb, len);
28599 dequeue_sm_buf(card, skb);
28600 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28601 ATM_SKB(skb)->vcc = vcc;
28602 __net_timestamp(skb);
28603 vcc->push(vcc, skb);
28604 - atomic_inc(&vcc->stats->rx);
28605 + atomic_inc_unchecked(&vcc->stats->rx);
28606 }
28607 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28608 struct sk_buff *sb;
28609 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28610 if (len <= NS_SMBUFSIZE) {
28611 if (!atm_charge(vcc, sb->truesize)) {
28612 push_rxbufs(card, sb);
28613 - atomic_inc(&vcc->stats->rx_drop);
28614 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28615 } else {
28616 skb_put(sb, len);
28617 dequeue_sm_buf(card, sb);
28618 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28619 ATM_SKB(sb)->vcc = vcc;
28620 __net_timestamp(sb);
28621 vcc->push(vcc, sb);
28622 - atomic_inc(&vcc->stats->rx);
28623 + atomic_inc_unchecked(&vcc->stats->rx);
28624 }
28625
28626 push_rxbufs(card, skb);
28627 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28628
28629 if (!atm_charge(vcc, skb->truesize)) {
28630 push_rxbufs(card, skb);
28631 - atomic_inc(&vcc->stats->rx_drop);
28632 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28633 } else {
28634 dequeue_lg_buf(card, skb);
28635 #ifdef NS_USE_DESTRUCTORS
28636 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28637 ATM_SKB(skb)->vcc = vcc;
28638 __net_timestamp(skb);
28639 vcc->push(vcc, skb);
28640 - atomic_inc(&vcc->stats->rx);
28641 + atomic_inc_unchecked(&vcc->stats->rx);
28642 }
28643
28644 push_rxbufs(card, sb);
28645 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28646 printk
28647 ("nicstar%d: Out of huge buffers.\n",
28648 card->index);
28649 - atomic_inc(&vcc->stats->rx_drop);
28650 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28651 recycle_iovec_rx_bufs(card,
28652 (struct iovec *)
28653 iovb->data,
28654 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28655 card->hbpool.count++;
28656 } else
28657 dev_kfree_skb_any(hb);
28658 - atomic_inc(&vcc->stats->rx_drop);
28659 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28660 } else {
28661 /* Copy the small buffer to the huge buffer */
28662 sb = (struct sk_buff *)iov->iov_base;
28663 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28664 #endif /* NS_USE_DESTRUCTORS */
28665 __net_timestamp(hb);
28666 vcc->push(vcc, hb);
28667 - atomic_inc(&vcc->stats->rx);
28668 + atomic_inc_unchecked(&vcc->stats->rx);
28669 }
28670 }
28671
28672 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28673 index 9851093..adb2b1e 100644
28674 --- a/drivers/atm/solos-pci.c
28675 +++ b/drivers/atm/solos-pci.c
28676 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28677 }
28678 atm_charge(vcc, skb->truesize);
28679 vcc->push(vcc, skb);
28680 - atomic_inc(&vcc->stats->rx);
28681 + atomic_inc_unchecked(&vcc->stats->rx);
28682 break;
28683
28684 case PKT_STATUS:
28685 @@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28686 vcc = SKB_CB(oldskb)->vcc;
28687
28688 if (vcc) {
28689 - atomic_inc(&vcc->stats->tx);
28690 + atomic_inc_unchecked(&vcc->stats->tx);
28691 solos_pop(vcc, oldskb);
28692 } else
28693 dev_kfree_skb_irq(oldskb);
28694 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28695 index 0215934..ce9f5b1 100644
28696 --- a/drivers/atm/suni.c
28697 +++ b/drivers/atm/suni.c
28698 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28699
28700
28701 #define ADD_LIMITED(s,v) \
28702 - atomic_add((v),&stats->s); \
28703 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28704 + atomic_add_unchecked((v),&stats->s); \
28705 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28706
28707
28708 static void suni_hz(unsigned long from_timer)
28709 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28710 index 5120a96..e2572bd 100644
28711 --- a/drivers/atm/uPD98402.c
28712 +++ b/drivers/atm/uPD98402.c
28713 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28714 struct sonet_stats tmp;
28715 int error = 0;
28716
28717 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28718 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28719 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28720 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28721 if (zero && !error) {
28722 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28723
28724
28725 #define ADD_LIMITED(s,v) \
28726 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28727 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28728 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28729 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28730 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28731 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28732
28733
28734 static void stat_event(struct atm_dev *dev)
28735 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28736 if (reason & uPD98402_INT_PFM) stat_event(dev);
28737 if (reason & uPD98402_INT_PCO) {
28738 (void) GET(PCOCR); /* clear interrupt cause */
28739 - atomic_add(GET(HECCT),
28740 + atomic_add_unchecked(GET(HECCT),
28741 &PRIV(dev)->sonet_stats.uncorr_hcs);
28742 }
28743 if ((reason & uPD98402_INT_RFO) &&
28744 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28745 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28746 uPD98402_INT_LOS),PIMR); /* enable them */
28747 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28748 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28749 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28750 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28751 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28752 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28753 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28754 return 0;
28755 }
28756
28757 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28758 index abe4e20..83c4727 100644
28759 --- a/drivers/atm/zatm.c
28760 +++ b/drivers/atm/zatm.c
28761 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28762 }
28763 if (!size) {
28764 dev_kfree_skb_irq(skb);
28765 - if (vcc) atomic_inc(&vcc->stats->rx_err);
28766 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28767 continue;
28768 }
28769 if (!atm_charge(vcc,skb->truesize)) {
28770 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28771 skb->len = size;
28772 ATM_SKB(skb)->vcc = vcc;
28773 vcc->push(vcc,skb);
28774 - atomic_inc(&vcc->stats->rx);
28775 + atomic_inc_unchecked(&vcc->stats->rx);
28776 }
28777 zout(pos & 0xffff,MTA(mbx));
28778 #if 0 /* probably a stupid idea */
28779 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28780 skb_queue_head(&zatm_vcc->backlog,skb);
28781 break;
28782 }
28783 - atomic_inc(&vcc->stats->tx);
28784 + atomic_inc_unchecked(&vcc->stats->tx);
28785 wake_up(&zatm_vcc->tx_wait);
28786 }
28787
28788 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28789 index 8493536..31adee0 100644
28790 --- a/drivers/base/devtmpfs.c
28791 +++ b/drivers/base/devtmpfs.c
28792 @@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
28793 if (!thread)
28794 return 0;
28795
28796 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28797 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28798 if (err)
28799 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28800 else
28801 diff --git a/drivers/base/node.c b/drivers/base/node.c
28802 index 90aa2a1..af1a177 100644
28803 --- a/drivers/base/node.c
28804 +++ b/drivers/base/node.c
28805 @@ -592,11 +592,9 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
28806 {
28807 int n;
28808
28809 - n = nodelist_scnprintf(buf, PAGE_SIZE, node_states[state]);
28810 - if (n > 0 && PAGE_SIZE > n + 1) {
28811 - *(buf + n++) = '\n';
28812 - *(buf + n++) = '\0';
28813 - }
28814 + n = nodelist_scnprintf(buf, PAGE_SIZE-2, node_states[state]);
28815 + buf[n++] = '\n';
28816 + buf[n] = '\0';
28817 return n;
28818 }
28819
28820 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28821 index 2a3e581..3d6a73f 100644
28822 --- a/drivers/base/power/wakeup.c
28823 +++ b/drivers/base/power/wakeup.c
28824 @@ -30,14 +30,14 @@ bool events_check_enabled;
28825 * They need to be modified together atomically, so it's better to use one
28826 * atomic variable to hold them both.
28827 */
28828 -static atomic_t combined_event_count = ATOMIC_INIT(0);
28829 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28830
28831 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28832 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28833
28834 static void split_counters(unsigned int *cnt, unsigned int *inpr)
28835 {
28836 - unsigned int comb = atomic_read(&combined_event_count);
28837 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
28838
28839 *cnt = (comb >> IN_PROGRESS_BITS);
28840 *inpr = comb & MAX_IN_PROGRESS;
28841 @@ -379,7 +379,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
28842 ws->last_time = ktime_get();
28843
28844 /* Increment the counter of events in progress. */
28845 - atomic_inc(&combined_event_count);
28846 + atomic_inc_unchecked(&combined_event_count);
28847 }
28848
28849 /**
28850 @@ -475,7 +475,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
28851 * Increment the counter of registered wakeup events and decrement the
28852 * couter of wakeup events in progress simultaneously.
28853 */
28854 - atomic_add(MAX_IN_PROGRESS, &combined_event_count);
28855 + atomic_add_unchecked(MAX_IN_PROGRESS, &combined_event_count);
28856 }
28857
28858 /**
28859 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
28860 index b0f553b..77b928b 100644
28861 --- a/drivers/block/cciss.c
28862 +++ b/drivers/block/cciss.c
28863 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
28864 int err;
28865 u32 cp;
28866
28867 + memset(&arg64, 0, sizeof(arg64));
28868 +
28869 err = 0;
28870 err |=
28871 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
28872 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
28873 while (!list_empty(&h->reqQ)) {
28874 c = list_entry(h->reqQ.next, CommandList_struct, list);
28875 /* can't do anything if fifo is full */
28876 - if ((h->access.fifo_full(h))) {
28877 + if ((h->access->fifo_full(h))) {
28878 dev_warn(&h->pdev->dev, "fifo full\n");
28879 break;
28880 }
28881 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
28882 h->Qdepth--;
28883
28884 /* Tell the controller execute command */
28885 - h->access.submit_command(h, c);
28886 + h->access->submit_command(h, c);
28887
28888 /* Put job onto the completed Q */
28889 addQ(&h->cmpQ, c);
28890 @@ -3443,17 +3445,17 @@ startio:
28891
28892 static inline unsigned long get_next_completion(ctlr_info_t *h)
28893 {
28894 - return h->access.command_completed(h);
28895 + return h->access->command_completed(h);
28896 }
28897
28898 static inline int interrupt_pending(ctlr_info_t *h)
28899 {
28900 - return h->access.intr_pending(h);
28901 + return h->access->intr_pending(h);
28902 }
28903
28904 static inline long interrupt_not_for_us(ctlr_info_t *h)
28905 {
28906 - return ((h->access.intr_pending(h) == 0) ||
28907 + return ((h->access->intr_pending(h) == 0) ||
28908 (h->interrupts_enabled == 0));
28909 }
28910
28911 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
28912 u32 a;
28913
28914 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
28915 - return h->access.command_completed(h);
28916 + return h->access->command_completed(h);
28917
28918 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
28919 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
28920 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
28921 trans_support & CFGTBL_Trans_use_short_tags);
28922
28923 /* Change the access methods to the performant access methods */
28924 - h->access = SA5_performant_access;
28925 + h->access = &SA5_performant_access;
28926 h->transMethod = CFGTBL_Trans_Performant;
28927
28928 return;
28929 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
28930 if (prod_index < 0)
28931 return -ENODEV;
28932 h->product_name = products[prod_index].product_name;
28933 - h->access = *(products[prod_index].access);
28934 + h->access = products[prod_index].access;
28935
28936 if (cciss_board_disabled(h)) {
28937 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
28938 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
28939 }
28940
28941 /* make sure the board interrupts are off */
28942 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28943 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28944 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
28945 if (rc)
28946 goto clean2;
28947 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
28948 * fake ones to scoop up any residual completions.
28949 */
28950 spin_lock_irqsave(&h->lock, flags);
28951 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28952 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28953 spin_unlock_irqrestore(&h->lock, flags);
28954 free_irq(h->intr[h->intr_mode], h);
28955 rc = cciss_request_irq(h, cciss_msix_discard_completions,
28956 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
28957 dev_info(&h->pdev->dev, "Board READY.\n");
28958 dev_info(&h->pdev->dev,
28959 "Waiting for stale completions to drain.\n");
28960 - h->access.set_intr_mask(h, CCISS_INTR_ON);
28961 + h->access->set_intr_mask(h, CCISS_INTR_ON);
28962 msleep(10000);
28963 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28964 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28965
28966 rc = controller_reset_failed(h->cfgtable);
28967 if (rc)
28968 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
28969 cciss_scsi_setup(h);
28970
28971 /* Turn the interrupts on so we can service requests */
28972 - h->access.set_intr_mask(h, CCISS_INTR_ON);
28973 + h->access->set_intr_mask(h, CCISS_INTR_ON);
28974
28975 /* Get the firmware version */
28976 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
28977 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
28978 kfree(flush_buf);
28979 if (return_code != IO_OK)
28980 dev_warn(&h->pdev->dev, "Error flushing cache\n");
28981 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28982 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28983 free_irq(h->intr[h->intr_mode], h);
28984 }
28985
28986 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
28987 index 7fda30e..eb5dfe0 100644
28988 --- a/drivers/block/cciss.h
28989 +++ b/drivers/block/cciss.h
28990 @@ -101,7 +101,7 @@ struct ctlr_info
28991 /* information about each logical volume */
28992 drive_info_struct *drv[CISS_MAX_LUN];
28993
28994 - struct access_method access;
28995 + struct access_method *access;
28996
28997 /* queue and queue Info */
28998 struct list_head reqQ;
28999 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
29000 index 9125bbe..eede5c8 100644
29001 --- a/drivers/block/cpqarray.c
29002 +++ b/drivers/block/cpqarray.c
29003 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29004 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
29005 goto Enomem4;
29006 }
29007 - hba[i]->access.set_intr_mask(hba[i], 0);
29008 + hba[i]->access->set_intr_mask(hba[i], 0);
29009 if (request_irq(hba[i]->intr, do_ida_intr,
29010 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
29011 {
29012 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29013 add_timer(&hba[i]->timer);
29014
29015 /* Enable IRQ now that spinlock and rate limit timer are set up */
29016 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29017 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29018
29019 for(j=0; j<NWD; j++) {
29020 struct gendisk *disk = ida_gendisk[i][j];
29021 @@ -694,7 +694,7 @@ DBGINFO(
29022 for(i=0; i<NR_PRODUCTS; i++) {
29023 if (board_id == products[i].board_id) {
29024 c->product_name = products[i].product_name;
29025 - c->access = *(products[i].access);
29026 + c->access = products[i].access;
29027 break;
29028 }
29029 }
29030 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
29031 hba[ctlr]->intr = intr;
29032 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
29033 hba[ctlr]->product_name = products[j].product_name;
29034 - hba[ctlr]->access = *(products[j].access);
29035 + hba[ctlr]->access = products[j].access;
29036 hba[ctlr]->ctlr = ctlr;
29037 hba[ctlr]->board_id = board_id;
29038 hba[ctlr]->pci_dev = NULL; /* not PCI */
29039 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
29040
29041 while((c = h->reqQ) != NULL) {
29042 /* Can't do anything if we're busy */
29043 - if (h->access.fifo_full(h) == 0)
29044 + if (h->access->fifo_full(h) == 0)
29045 return;
29046
29047 /* Get the first entry from the request Q */
29048 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
29049 h->Qdepth--;
29050
29051 /* Tell the controller to do our bidding */
29052 - h->access.submit_command(h, c);
29053 + h->access->submit_command(h, c);
29054
29055 /* Get onto the completion Q */
29056 addQ(&h->cmpQ, c);
29057 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29058 unsigned long flags;
29059 __u32 a,a1;
29060
29061 - istat = h->access.intr_pending(h);
29062 + istat = h->access->intr_pending(h);
29063 /* Is this interrupt for us? */
29064 if (istat == 0)
29065 return IRQ_NONE;
29066 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29067 */
29068 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
29069 if (istat & FIFO_NOT_EMPTY) {
29070 - while((a = h->access.command_completed(h))) {
29071 + while((a = h->access->command_completed(h))) {
29072 a1 = a; a &= ~3;
29073 if ((c = h->cmpQ) == NULL)
29074 {
29075 @@ -1449,11 +1449,11 @@ static int sendcmd(
29076 /*
29077 * Disable interrupt
29078 */
29079 - info_p->access.set_intr_mask(info_p, 0);
29080 + info_p->access->set_intr_mask(info_p, 0);
29081 /* Make sure there is room in the command FIFO */
29082 /* Actually it should be completely empty at this time. */
29083 for (i = 200000; i > 0; i--) {
29084 - temp = info_p->access.fifo_full(info_p);
29085 + temp = info_p->access->fifo_full(info_p);
29086 if (temp != 0) {
29087 break;
29088 }
29089 @@ -1466,7 +1466,7 @@ DBG(
29090 /*
29091 * Send the cmd
29092 */
29093 - info_p->access.submit_command(info_p, c);
29094 + info_p->access->submit_command(info_p, c);
29095 complete = pollcomplete(ctlr);
29096
29097 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29098 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29099 * we check the new geometry. Then turn interrupts back on when
29100 * we're done.
29101 */
29102 - host->access.set_intr_mask(host, 0);
29103 + host->access->set_intr_mask(host, 0);
29104 getgeometry(ctlr);
29105 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29106 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29107
29108 for(i=0; i<NWD; i++) {
29109 struct gendisk *disk = ida_gendisk[ctlr][i];
29110 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29111 /* Wait (up to 2 seconds) for a command to complete */
29112
29113 for (i = 200000; i > 0; i--) {
29114 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
29115 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
29116 if (done == 0) {
29117 udelay(10); /* a short fixed delay */
29118 } else
29119 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29120 index be73e9d..7fbf140 100644
29121 --- a/drivers/block/cpqarray.h
29122 +++ b/drivers/block/cpqarray.h
29123 @@ -99,7 +99,7 @@ struct ctlr_info {
29124 drv_info_t drv[NWD];
29125 struct proc_dir_entry *proc;
29126
29127 - struct access_method access;
29128 + struct access_method *access;
29129
29130 cmdlist_t *reqQ;
29131 cmdlist_t *cmpQ;
29132 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29133 index 8d68056..e67050f 100644
29134 --- a/drivers/block/drbd/drbd_int.h
29135 +++ b/drivers/block/drbd/drbd_int.h
29136 @@ -736,7 +736,7 @@ struct drbd_request;
29137 struct drbd_epoch {
29138 struct list_head list;
29139 unsigned int barrier_nr;
29140 - atomic_t epoch_size; /* increased on every request added. */
29141 + atomic_unchecked_t epoch_size; /* increased on every request added. */
29142 atomic_t active; /* increased on every req. added, and dec on every finished. */
29143 unsigned long flags;
29144 };
29145 @@ -1108,7 +1108,7 @@ struct drbd_conf {
29146 void *int_dig_in;
29147 void *int_dig_vv;
29148 wait_queue_head_t seq_wait;
29149 - atomic_t packet_seq;
29150 + atomic_unchecked_t packet_seq;
29151 unsigned int peer_seq;
29152 spinlock_t peer_seq_lock;
29153 unsigned int minor;
29154 @@ -1617,30 +1617,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29155
29156 static inline void drbd_tcp_cork(struct socket *sock)
29157 {
29158 - int __user val = 1;
29159 + int val = 1;
29160 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29161 - (char __user *)&val, sizeof(val));
29162 + (char __force_user *)&val, sizeof(val));
29163 }
29164
29165 static inline void drbd_tcp_uncork(struct socket *sock)
29166 {
29167 - int __user val = 0;
29168 + int val = 0;
29169 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29170 - (char __user *)&val, sizeof(val));
29171 + (char __force_user *)&val, sizeof(val));
29172 }
29173
29174 static inline void drbd_tcp_nodelay(struct socket *sock)
29175 {
29176 - int __user val = 1;
29177 + int val = 1;
29178 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29179 - (char __user *)&val, sizeof(val));
29180 + (char __force_user *)&val, sizeof(val));
29181 }
29182
29183 static inline void drbd_tcp_quickack(struct socket *sock)
29184 {
29185 - int __user val = 2;
29186 + int val = 2;
29187 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29188 - (char __user *)&val, sizeof(val));
29189 + (char __force_user *)&val, sizeof(val));
29190 }
29191
29192 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29193 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29194 index 211fc44..c5116f1 100644
29195 --- a/drivers/block/drbd/drbd_main.c
29196 +++ b/drivers/block/drbd/drbd_main.c
29197 @@ -2397,7 +2397,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29198 p.sector = sector;
29199 p.block_id = block_id;
29200 p.blksize = blksize;
29201 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29202 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29203
29204 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29205 return false;
29206 @@ -2696,7 +2696,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29207 p.sector = cpu_to_be64(req->sector);
29208 p.block_id = (unsigned long)req;
29209 p.seq_num = cpu_to_be32(req->seq_num =
29210 - atomic_add_return(1, &mdev->packet_seq));
29211 + atomic_add_return_unchecked(1, &mdev->packet_seq));
29212
29213 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29214
29215 @@ -2981,7 +2981,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29216 atomic_set(&mdev->unacked_cnt, 0);
29217 atomic_set(&mdev->local_cnt, 0);
29218 atomic_set(&mdev->net_cnt, 0);
29219 - atomic_set(&mdev->packet_seq, 0);
29220 + atomic_set_unchecked(&mdev->packet_seq, 0);
29221 atomic_set(&mdev->pp_in_use, 0);
29222 atomic_set(&mdev->pp_in_use_by_net, 0);
29223 atomic_set(&mdev->rs_sect_in, 0);
29224 @@ -3063,8 +3063,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29225 mdev->receiver.t_state);
29226
29227 /* no need to lock it, I'm the only thread alive */
29228 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29229 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29230 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29231 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29232 mdev->al_writ_cnt =
29233 mdev->bm_writ_cnt =
29234 mdev->read_cnt =
29235 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29236 index 946166e..356b39a 100644
29237 --- a/drivers/block/drbd/drbd_nl.c
29238 +++ b/drivers/block/drbd/drbd_nl.c
29239 @@ -2359,7 +2359,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29240 module_put(THIS_MODULE);
29241 }
29242
29243 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29244 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29245
29246 static unsigned short *
29247 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29248 @@ -2430,7 +2430,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29249 cn_reply->id.idx = CN_IDX_DRBD;
29250 cn_reply->id.val = CN_VAL_DRBD;
29251
29252 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29253 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29254 cn_reply->ack = 0; /* not used here. */
29255 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29256 (int)((char *)tl - (char *)reply->tag_list);
29257 @@ -2462,7 +2462,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29258 cn_reply->id.idx = CN_IDX_DRBD;
29259 cn_reply->id.val = CN_VAL_DRBD;
29260
29261 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29262 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29263 cn_reply->ack = 0; /* not used here. */
29264 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29265 (int)((char *)tl - (char *)reply->tag_list);
29266 @@ -2540,7 +2540,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29267 cn_reply->id.idx = CN_IDX_DRBD;
29268 cn_reply->id.val = CN_VAL_DRBD;
29269
29270 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29271 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29272 cn_reply->ack = 0; // not used here.
29273 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29274 (int)((char*)tl - (char*)reply->tag_list);
29275 @@ -2579,7 +2579,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29276 cn_reply->id.idx = CN_IDX_DRBD;
29277 cn_reply->id.val = CN_VAL_DRBD;
29278
29279 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29280 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29281 cn_reply->ack = 0; /* not used here. */
29282 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29283 (int)((char *)tl - (char *)reply->tag_list);
29284 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29285 index 43beaca..4a5b1dd 100644
29286 --- a/drivers/block/drbd/drbd_receiver.c
29287 +++ b/drivers/block/drbd/drbd_receiver.c
29288 @@ -894,7 +894,7 @@ retry:
29289 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29290 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29291
29292 - atomic_set(&mdev->packet_seq, 0);
29293 + atomic_set_unchecked(&mdev->packet_seq, 0);
29294 mdev->peer_seq = 0;
29295
29296 drbd_thread_start(&mdev->asender);
29297 @@ -985,7 +985,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29298 do {
29299 next_epoch = NULL;
29300
29301 - epoch_size = atomic_read(&epoch->epoch_size);
29302 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29303
29304 switch (ev & ~EV_CLEANUP) {
29305 case EV_PUT:
29306 @@ -1020,7 +1020,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29307 rv = FE_DESTROYED;
29308 } else {
29309 epoch->flags = 0;
29310 - atomic_set(&epoch->epoch_size, 0);
29311 + atomic_set_unchecked(&epoch->epoch_size, 0);
29312 /* atomic_set(&epoch->active, 0); is already zero */
29313 if (rv == FE_STILL_LIVE)
29314 rv = FE_RECYCLED;
29315 @@ -1191,14 +1191,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29316 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29317 drbd_flush(mdev);
29318
29319 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29320 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29321 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29322 if (epoch)
29323 break;
29324 }
29325
29326 epoch = mdev->current_epoch;
29327 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29328 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29329
29330 D_ASSERT(atomic_read(&epoch->active) == 0);
29331 D_ASSERT(epoch->flags == 0);
29332 @@ -1210,11 +1210,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29333 }
29334
29335 epoch->flags = 0;
29336 - atomic_set(&epoch->epoch_size, 0);
29337 + atomic_set_unchecked(&epoch->epoch_size, 0);
29338 atomic_set(&epoch->active, 0);
29339
29340 spin_lock(&mdev->epoch_lock);
29341 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29342 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29343 list_add(&epoch->list, &mdev->current_epoch->list);
29344 mdev->current_epoch = epoch;
29345 mdev->epochs++;
29346 @@ -1663,7 +1663,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29347 spin_unlock(&mdev->peer_seq_lock);
29348
29349 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29350 - atomic_inc(&mdev->current_epoch->epoch_size);
29351 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29352 return drbd_drain_block(mdev, data_size);
29353 }
29354
29355 @@ -1689,7 +1689,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29356
29357 spin_lock(&mdev->epoch_lock);
29358 e->epoch = mdev->current_epoch;
29359 - atomic_inc(&e->epoch->epoch_size);
29360 + atomic_inc_unchecked(&e->epoch->epoch_size);
29361 atomic_inc(&e->epoch->active);
29362 spin_unlock(&mdev->epoch_lock);
29363
29364 @@ -3885,7 +3885,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29365 D_ASSERT(list_empty(&mdev->done_ee));
29366
29367 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29368 - atomic_set(&mdev->current_epoch->epoch_size, 0);
29369 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29370 D_ASSERT(list_empty(&mdev->current_epoch->list));
29371 }
29372
29373 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29374 index bbca966..65e37dd 100644
29375 --- a/drivers/block/loop.c
29376 +++ b/drivers/block/loop.c
29377 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29378 mm_segment_t old_fs = get_fs();
29379
29380 set_fs(get_ds());
29381 - bw = file->f_op->write(file, buf, len, &pos);
29382 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29383 set_fs(old_fs);
29384 if (likely(bw == len))
29385 return 0;
29386 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29387 index ee94686..3e09ad3 100644
29388 --- a/drivers/char/Kconfig
29389 +++ b/drivers/char/Kconfig
29390 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29391
29392 config DEVKMEM
29393 bool "/dev/kmem virtual device support"
29394 - default y
29395 + default n
29396 + depends on !GRKERNSEC_KMEM
29397 help
29398 Say Y here if you want to support the /dev/kmem device. The
29399 /dev/kmem device is rarely used, but can be used for certain
29400 @@ -581,6 +582,7 @@ config DEVPORT
29401 bool
29402 depends on !M68K
29403 depends on ISA || PCI
29404 + depends on !GRKERNSEC_KMEM
29405 default y
29406
29407 source "drivers/s390/char/Kconfig"
29408 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29409 index 2e04433..22afc64 100644
29410 --- a/drivers/char/agp/frontend.c
29411 +++ b/drivers/char/agp/frontend.c
29412 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29413 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29414 return -EFAULT;
29415
29416 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29417 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29418 return -EFAULT;
29419
29420 client = agp_find_client_by_pid(reserve.pid);
29421 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29422 index 21cb980..f15107c 100644
29423 --- a/drivers/char/genrtc.c
29424 +++ b/drivers/char/genrtc.c
29425 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29426 switch (cmd) {
29427
29428 case RTC_PLL_GET:
29429 + memset(&pll, 0, sizeof(pll));
29430 if (get_rtc_pll(&pll))
29431 return -EINVAL;
29432 else
29433 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29434 index dfd7876..c0b0885 100644
29435 --- a/drivers/char/hpet.c
29436 +++ b/drivers/char/hpet.c
29437 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29438 }
29439
29440 static int
29441 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29442 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29443 struct hpet_info *info)
29444 {
29445 struct hpet_timer __iomem *timer;
29446 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29447 index 2c29942..604c5ba 100644
29448 --- a/drivers/char/ipmi/ipmi_msghandler.c
29449 +++ b/drivers/char/ipmi/ipmi_msghandler.c
29450 @@ -420,7 +420,7 @@ struct ipmi_smi {
29451 struct proc_dir_entry *proc_dir;
29452 char proc_dir_name[10];
29453
29454 - atomic_t stats[IPMI_NUM_STATS];
29455 + atomic_unchecked_t stats[IPMI_NUM_STATS];
29456
29457 /*
29458 * run_to_completion duplicate of smb_info, smi_info
29459 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29460
29461
29462 #define ipmi_inc_stat(intf, stat) \
29463 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29464 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29465 #define ipmi_get_stat(intf, stat) \
29466 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29467 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29468
29469 static int is_lan_addr(struct ipmi_addr *addr)
29470 {
29471 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29472 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29473 init_waitqueue_head(&intf->waitq);
29474 for (i = 0; i < IPMI_NUM_STATS; i++)
29475 - atomic_set(&intf->stats[i], 0);
29476 + atomic_set_unchecked(&intf->stats[i], 0);
29477
29478 intf->proc_dir = NULL;
29479
29480 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29481 index 1e638ff..a869ef5 100644
29482 --- a/drivers/char/ipmi/ipmi_si_intf.c
29483 +++ b/drivers/char/ipmi/ipmi_si_intf.c
29484 @@ -275,7 +275,7 @@ struct smi_info {
29485 unsigned char slave_addr;
29486
29487 /* Counters and things for the proc filesystem. */
29488 - atomic_t stats[SI_NUM_STATS];
29489 + atomic_unchecked_t stats[SI_NUM_STATS];
29490
29491 struct task_struct *thread;
29492
29493 @@ -284,9 +284,9 @@ struct smi_info {
29494 };
29495
29496 #define smi_inc_stat(smi, stat) \
29497 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29498 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29499 #define smi_get_stat(smi, stat) \
29500 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29501 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29502
29503 #define SI_MAX_PARMS 4
29504
29505 @@ -3209,7 +3209,7 @@ static int try_smi_init(struct smi_info *new_smi)
29506 atomic_set(&new_smi->req_events, 0);
29507 new_smi->run_to_completion = 0;
29508 for (i = 0; i < SI_NUM_STATS; i++)
29509 - atomic_set(&new_smi->stats[i], 0);
29510 + atomic_set_unchecked(&new_smi->stats[i], 0);
29511
29512 new_smi->interrupt_disabled = 1;
29513 atomic_set(&new_smi->stop_operation, 0);
29514 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29515 index 47ff7e4..0c7d340 100644
29516 --- a/drivers/char/mbcs.c
29517 +++ b/drivers/char/mbcs.c
29518 @@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29519 return 0;
29520 }
29521
29522 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29523 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29524 {
29525 .part_num = MBCS_PART_NUM,
29526 .mfg_num = MBCS_MFG_NUM,
29527 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29528 index d6e9d08..4493e89 100644
29529 --- a/drivers/char/mem.c
29530 +++ b/drivers/char/mem.c
29531 @@ -18,6 +18,7 @@
29532 #include <linux/raw.h>
29533 #include <linux/tty.h>
29534 #include <linux/capability.h>
29535 +#include <linux/security.h>
29536 #include <linux/ptrace.h>
29537 #include <linux/device.h>
29538 #include <linux/highmem.h>
29539 @@ -35,6 +36,10 @@
29540 # include <linux/efi.h>
29541 #endif
29542
29543 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29544 +extern const struct file_operations grsec_fops;
29545 +#endif
29546 +
29547 static inline unsigned long size_inside_page(unsigned long start,
29548 unsigned long size)
29549 {
29550 @@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29551
29552 while (cursor < to) {
29553 if (!devmem_is_allowed(pfn)) {
29554 +#ifdef CONFIG_GRKERNSEC_KMEM
29555 + gr_handle_mem_readwrite(from, to);
29556 +#else
29557 printk(KERN_INFO
29558 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29559 current->comm, from, to);
29560 +#endif
29561 return 0;
29562 }
29563 cursor += PAGE_SIZE;
29564 @@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29565 }
29566 return 1;
29567 }
29568 +#elif defined(CONFIG_GRKERNSEC_KMEM)
29569 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29570 +{
29571 + return 0;
29572 +}
29573 #else
29574 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29575 {
29576 @@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29577
29578 while (count > 0) {
29579 unsigned long remaining;
29580 + char *temp;
29581
29582 sz = size_inside_page(p, count);
29583
29584 @@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29585 if (!ptr)
29586 return -EFAULT;
29587
29588 - remaining = copy_to_user(buf, ptr, sz);
29589 +#ifdef CONFIG_PAX_USERCOPY
29590 + temp = kmalloc(sz, GFP_KERNEL);
29591 + if (!temp) {
29592 + unxlate_dev_mem_ptr(p, ptr);
29593 + return -ENOMEM;
29594 + }
29595 + memcpy(temp, ptr, sz);
29596 +#else
29597 + temp = ptr;
29598 +#endif
29599 +
29600 + remaining = copy_to_user(buf, temp, sz);
29601 +
29602 +#ifdef CONFIG_PAX_USERCOPY
29603 + kfree(temp);
29604 +#endif
29605 +
29606 unxlate_dev_mem_ptr(p, ptr);
29607 if (remaining)
29608 return -EFAULT;
29609 @@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29610 size_t count, loff_t *ppos)
29611 {
29612 unsigned long p = *ppos;
29613 - ssize_t low_count, read, sz;
29614 + ssize_t low_count, read, sz, err = 0;
29615 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29616 - int err = 0;
29617
29618 read = 0;
29619 if (p < (unsigned long) high_memory) {
29620 @@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29621 }
29622 #endif
29623 while (low_count > 0) {
29624 + char *temp;
29625 +
29626 sz = size_inside_page(p, low_count);
29627
29628 /*
29629 @@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29630 */
29631 kbuf = xlate_dev_kmem_ptr((char *)p);
29632
29633 - if (copy_to_user(buf, kbuf, sz))
29634 +#ifdef CONFIG_PAX_USERCOPY
29635 + temp = kmalloc(sz, GFP_KERNEL);
29636 + if (!temp)
29637 + return -ENOMEM;
29638 + memcpy(temp, kbuf, sz);
29639 +#else
29640 + temp = kbuf;
29641 +#endif
29642 +
29643 + err = copy_to_user(buf, temp, sz);
29644 +
29645 +#ifdef CONFIG_PAX_USERCOPY
29646 + kfree(temp);
29647 +#endif
29648 +
29649 + if (err)
29650 return -EFAULT;
29651 buf += sz;
29652 p += sz;
29653 @@ -867,6 +914,9 @@ static const struct memdev {
29654 #ifdef CONFIG_CRASH_DUMP
29655 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29656 #endif
29657 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29658 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29659 +#endif
29660 };
29661
29662 static int memory_open(struct inode *inode, struct file *filp)
29663 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29664 index 9df78e2..01ba9ae 100644
29665 --- a/drivers/char/nvram.c
29666 +++ b/drivers/char/nvram.c
29667 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29668
29669 spin_unlock_irq(&rtc_lock);
29670
29671 - if (copy_to_user(buf, contents, tmp - contents))
29672 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29673 return -EFAULT;
29674
29675 *ppos = i;
29676 diff --git a/drivers/char/random.c b/drivers/char/random.c
29677 index 4ec04a7..4a092ed 100644
29678 --- a/drivers/char/random.c
29679 +++ b/drivers/char/random.c
29680 @@ -261,8 +261,13 @@
29681 /*
29682 * Configuration information
29683 */
29684 +#ifdef CONFIG_GRKERNSEC_RANDNET
29685 +#define INPUT_POOL_WORDS 512
29686 +#define OUTPUT_POOL_WORDS 128
29687 +#else
29688 #define INPUT_POOL_WORDS 128
29689 #define OUTPUT_POOL_WORDS 32
29690 +#endif
29691 #define SEC_XFER_SIZE 512
29692 #define EXTRACT_SIZE 10
29693
29694 @@ -300,10 +305,17 @@ static struct poolinfo {
29695 int poolwords;
29696 int tap1, tap2, tap3, tap4, tap5;
29697 } poolinfo_table[] = {
29698 +#ifdef CONFIG_GRKERNSEC_RANDNET
29699 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29700 + { 512, 411, 308, 208, 104, 1 },
29701 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29702 + { 128, 103, 76, 51, 25, 1 },
29703 +#else
29704 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29705 { 128, 103, 76, 51, 25, 1 },
29706 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29707 { 32, 26, 20, 14, 7, 1 },
29708 +#endif
29709 #if 0
29710 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29711 { 2048, 1638, 1231, 819, 411, 1 },
29712 @@ -913,7 +925,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29713
29714 extract_buf(r, tmp);
29715 i = min_t(int, nbytes, EXTRACT_SIZE);
29716 - if (copy_to_user(buf, tmp, i)) {
29717 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29718 ret = -EFAULT;
29719 break;
29720 }
29721 @@ -1238,7 +1250,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29722 #include <linux/sysctl.h>
29723
29724 static int min_read_thresh = 8, min_write_thresh;
29725 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
29726 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29727 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29728 static char sysctl_bootid[16];
29729
29730 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
29731 index 45713f0..8286d21 100644
29732 --- a/drivers/char/sonypi.c
29733 +++ b/drivers/char/sonypi.c
29734 @@ -54,6 +54,7 @@
29735
29736 #include <asm/uaccess.h>
29737 #include <asm/io.h>
29738 +#include <asm/local.h>
29739
29740 #include <linux/sonypi.h>
29741
29742 @@ -490,7 +491,7 @@ static struct sonypi_device {
29743 spinlock_t fifo_lock;
29744 wait_queue_head_t fifo_proc_list;
29745 struct fasync_struct *fifo_async;
29746 - int open_count;
29747 + local_t open_count;
29748 int model;
29749 struct input_dev *input_jog_dev;
29750 struct input_dev *input_key_dev;
29751 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
29752 static int sonypi_misc_release(struct inode *inode, struct file *file)
29753 {
29754 mutex_lock(&sonypi_device.lock);
29755 - sonypi_device.open_count--;
29756 + local_dec(&sonypi_device.open_count);
29757 mutex_unlock(&sonypi_device.lock);
29758 return 0;
29759 }
29760 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
29761 {
29762 mutex_lock(&sonypi_device.lock);
29763 /* Flush input queue on first open */
29764 - if (!sonypi_device.open_count)
29765 + if (!local_read(&sonypi_device.open_count))
29766 kfifo_reset(&sonypi_device.fifo);
29767 - sonypi_device.open_count++;
29768 + local_inc(&sonypi_device.open_count);
29769 mutex_unlock(&sonypi_device.lock);
29770
29771 return 0;
29772 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
29773 index ad7c732..5aa8054 100644
29774 --- a/drivers/char/tpm/tpm.c
29775 +++ b/drivers/char/tpm/tpm.c
29776 @@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
29777 chip->vendor.req_complete_val)
29778 goto out_recv;
29779
29780 - if ((status == chip->vendor.req_canceled)) {
29781 + if (status == chip->vendor.req_canceled) {
29782 dev_err(chip->dev, "Operation Canceled\n");
29783 rc = -ECANCELED;
29784 goto out;
29785 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
29786 index 0636520..169c1d0 100644
29787 --- a/drivers/char/tpm/tpm_bios.c
29788 +++ b/drivers/char/tpm/tpm_bios.c
29789 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
29790 event = addr;
29791
29792 if ((event->event_type == 0 && event->event_size == 0) ||
29793 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
29794 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
29795 return NULL;
29796
29797 return addr;
29798 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
29799 return NULL;
29800
29801 if ((event->event_type == 0 && event->event_size == 0) ||
29802 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
29803 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
29804 return NULL;
29805
29806 (*pos)++;
29807 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
29808 int i;
29809
29810 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
29811 - seq_putc(m, data[i]);
29812 + if (!seq_putc(m, data[i]))
29813 + return -EFAULT;
29814
29815 return 0;
29816 }
29817 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
29818 log->bios_event_log_end = log->bios_event_log + len;
29819
29820 virt = acpi_os_map_memory(start, len);
29821 + if (!virt) {
29822 + kfree(log->bios_event_log);
29823 + log->bios_event_log = NULL;
29824 + return -EFAULT;
29825 + }
29826
29827 - memcpy(log->bios_event_log, virt, len);
29828 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
29829
29830 acpi_os_unmap_memory(virt, len);
29831 return 0;
29832 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
29833 index cdf2f54..e55c197 100644
29834 --- a/drivers/char/virtio_console.c
29835 +++ b/drivers/char/virtio_console.c
29836 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
29837 if (to_user) {
29838 ssize_t ret;
29839
29840 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
29841 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
29842 if (ret)
29843 return -EFAULT;
29844 } else {
29845 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
29846 if (!port_has_data(port) && !port->host_connected)
29847 return 0;
29848
29849 - return fill_readbuf(port, ubuf, count, true);
29850 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
29851 }
29852
29853 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
29854 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
29855 index 97f5064..202b6e6 100644
29856 --- a/drivers/edac/edac_pci_sysfs.c
29857 +++ b/drivers/edac/edac_pci_sysfs.c
29858 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
29859 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
29860 static int edac_pci_poll_msec = 1000; /* one second workq period */
29861
29862 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
29863 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
29864 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
29865 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
29866
29867 static struct kobject *edac_pci_top_main_kobj;
29868 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
29869 @@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29870 edac_printk(KERN_CRIT, EDAC_PCI,
29871 "Signaled System Error on %s\n",
29872 pci_name(dev));
29873 - atomic_inc(&pci_nonparity_count);
29874 + atomic_inc_unchecked(&pci_nonparity_count);
29875 }
29876
29877 if (status & (PCI_STATUS_PARITY)) {
29878 @@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29879 "Master Data Parity Error on %s\n",
29880 pci_name(dev));
29881
29882 - atomic_inc(&pci_parity_count);
29883 + atomic_inc_unchecked(&pci_parity_count);
29884 }
29885
29886 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29887 @@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29888 "Detected Parity Error on %s\n",
29889 pci_name(dev));
29890
29891 - atomic_inc(&pci_parity_count);
29892 + atomic_inc_unchecked(&pci_parity_count);
29893 }
29894 }
29895
29896 @@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29897 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
29898 "Signaled System Error on %s\n",
29899 pci_name(dev));
29900 - atomic_inc(&pci_nonparity_count);
29901 + atomic_inc_unchecked(&pci_nonparity_count);
29902 }
29903
29904 if (status & (PCI_STATUS_PARITY)) {
29905 @@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29906 "Master Data Parity Error on "
29907 "%s\n", pci_name(dev));
29908
29909 - atomic_inc(&pci_parity_count);
29910 + atomic_inc_unchecked(&pci_parity_count);
29911 }
29912
29913 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29914 @@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29915 "Detected Parity Error on %s\n",
29916 pci_name(dev));
29917
29918 - atomic_inc(&pci_parity_count);
29919 + atomic_inc_unchecked(&pci_parity_count);
29920 }
29921 }
29922 }
29923 @@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
29924 if (!check_pci_errors)
29925 return;
29926
29927 - before_count = atomic_read(&pci_parity_count);
29928 + before_count = atomic_read_unchecked(&pci_parity_count);
29929
29930 /* scan all PCI devices looking for a Parity Error on devices and
29931 * bridges.
29932 @@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
29933 /* Only if operator has selected panic on PCI Error */
29934 if (edac_pci_get_panic_on_pe()) {
29935 /* If the count is different 'after' from 'before' */
29936 - if (before_count != atomic_read(&pci_parity_count))
29937 + if (before_count != atomic_read_unchecked(&pci_parity_count))
29938 panic("EDAC: PCI Parity Error");
29939 }
29940 }
29941 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
29942 index c6074c5..88a9e2e 100644
29943 --- a/drivers/edac/mce_amd.h
29944 +++ b/drivers/edac/mce_amd.h
29945 @@ -82,7 +82,7 @@ extern const char * const ii_msgs[];
29946 struct amd_decoder_ops {
29947 bool (*dc_mce)(u16, u8);
29948 bool (*ic_mce)(u16, u8);
29949 -};
29950 +} __no_const;
29951
29952 void amd_report_gart_errors(bool);
29953 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
29954 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
29955 index cc595eb..4ec702a 100644
29956 --- a/drivers/firewire/core-card.c
29957 +++ b/drivers/firewire/core-card.c
29958 @@ -679,7 +679,7 @@ void fw_card_release(struct kref *kref)
29959
29960 void fw_core_remove_card(struct fw_card *card)
29961 {
29962 - struct fw_card_driver dummy_driver = dummy_driver_template;
29963 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
29964
29965 card->driver->update_phy_reg(card, 4,
29966 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
29967 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
29968 index 2e6b245..c3857d9 100644
29969 --- a/drivers/firewire/core-cdev.c
29970 +++ b/drivers/firewire/core-cdev.c
29971 @@ -1341,8 +1341,7 @@ static int init_iso_resource(struct client *client,
29972 int ret;
29973
29974 if ((request->channels == 0 && request->bandwidth == 0) ||
29975 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
29976 - request->bandwidth < 0)
29977 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
29978 return -EINVAL;
29979
29980 r = kmalloc(sizeof(*r), GFP_KERNEL);
29981 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
29982 index dea2dcc..a4fb978 100644
29983 --- a/drivers/firewire/core-transaction.c
29984 +++ b/drivers/firewire/core-transaction.c
29985 @@ -37,6 +37,7 @@
29986 #include <linux/timer.h>
29987 #include <linux/types.h>
29988 #include <linux/workqueue.h>
29989 +#include <linux/sched.h>
29990
29991 #include <asm/byteorder.h>
29992
29993 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
29994 index 9047f55..e47c7ff 100644
29995 --- a/drivers/firewire/core.h
29996 +++ b/drivers/firewire/core.h
29997 @@ -110,6 +110,7 @@ struct fw_card_driver {
29998
29999 int (*stop_iso)(struct fw_iso_context *ctx);
30000 };
30001 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30002
30003 void fw_card_initialize(struct fw_card *card,
30004 const struct fw_card_driver *driver, struct device *device);
30005 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
30006 index 153980b..4b4d046 100644
30007 --- a/drivers/firmware/dmi_scan.c
30008 +++ b/drivers/firmware/dmi_scan.c
30009 @@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
30010 }
30011 }
30012 else {
30013 - /*
30014 - * no iounmap() for that ioremap(); it would be a no-op, but
30015 - * it's so early in setup that sucker gets confused into doing
30016 - * what it shouldn't if we actually call it.
30017 - */
30018 p = dmi_ioremap(0xF0000, 0x10000);
30019 if (p == NULL)
30020 goto error;
30021 @@ -723,7 +718,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30022 if (buf == NULL)
30023 return -1;
30024
30025 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30026 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30027
30028 iounmap(buf);
30029 return 0;
30030 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30031 index 82d5c20..44a7177 100644
30032 --- a/drivers/gpio/gpio-vr41xx.c
30033 +++ b/drivers/gpio/gpio-vr41xx.c
30034 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30035 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30036 maskl, pendl, maskh, pendh);
30037
30038 - atomic_inc(&irq_err_count);
30039 + atomic_inc_unchecked(&irq_err_count);
30040
30041 return -EINVAL;
30042 }
30043 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30044 index 8111889..367b253 100644
30045 --- a/drivers/gpu/drm/drm_crtc_helper.c
30046 +++ b/drivers/gpu/drm/drm_crtc_helper.c
30047 @@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30048 struct drm_crtc *tmp;
30049 int crtc_mask = 1;
30050
30051 - WARN(!crtc, "checking null crtc?\n");
30052 + BUG_ON(!crtc);
30053
30054 dev = crtc->dev;
30055
30056 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30057 index 6116e3b..c29dd16 100644
30058 --- a/drivers/gpu/drm/drm_drv.c
30059 +++ b/drivers/gpu/drm/drm_drv.c
30060 @@ -316,7 +316,7 @@ module_exit(drm_core_exit);
30061 /**
30062 * Copy and IOCTL return string to user space
30063 */
30064 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30065 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30066 {
30067 int len;
30068
30069 @@ -399,7 +399,7 @@ long drm_ioctl(struct file *filp,
30070 return -ENODEV;
30071
30072 atomic_inc(&dev->ioctl_count);
30073 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30074 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30075 ++file_priv->ioctl_count;
30076
30077 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30078 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30079 index 123de28..43a0897 100644
30080 --- a/drivers/gpu/drm/drm_fops.c
30081 +++ b/drivers/gpu/drm/drm_fops.c
30082 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30083 }
30084
30085 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30086 - atomic_set(&dev->counts[i], 0);
30087 + atomic_set_unchecked(&dev->counts[i], 0);
30088
30089 dev->sigdata.lock = NULL;
30090
30091 @@ -138,8 +138,8 @@ int drm_open(struct inode *inode, struct file *filp)
30092
30093 retcode = drm_open_helper(inode, filp, dev);
30094 if (!retcode) {
30095 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30096 - if (!dev->open_count++)
30097 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30098 + if (local_inc_return(&dev->open_count) == 1)
30099 retcode = drm_setup(dev);
30100 }
30101 if (!retcode) {
30102 @@ -482,7 +482,7 @@ int drm_release(struct inode *inode, struct file *filp)
30103
30104 mutex_lock(&drm_global_mutex);
30105
30106 - DRM_DEBUG("open_count = %d\n", dev->open_count);
30107 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30108
30109 if (dev->driver->preclose)
30110 dev->driver->preclose(dev, file_priv);
30111 @@ -491,10 +491,10 @@ int drm_release(struct inode *inode, struct file *filp)
30112 * Begin inline drm_release
30113 */
30114
30115 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30116 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30117 task_pid_nr(current),
30118 (long)old_encode_dev(file_priv->minor->device),
30119 - dev->open_count);
30120 + local_read(&dev->open_count));
30121
30122 /* Release any auth tokens that might point to this file_priv,
30123 (do that under the drm_global_mutex) */
30124 @@ -584,8 +584,8 @@ int drm_release(struct inode *inode, struct file *filp)
30125 * End inline drm_release
30126 */
30127
30128 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30129 - if (!--dev->open_count) {
30130 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30131 + if (local_dec_and_test(&dev->open_count)) {
30132 if (atomic_read(&dev->ioctl_count)) {
30133 DRM_ERROR("Device busy: %d\n",
30134 atomic_read(&dev->ioctl_count));
30135 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30136 index c87dc96..326055d 100644
30137 --- a/drivers/gpu/drm/drm_global.c
30138 +++ b/drivers/gpu/drm/drm_global.c
30139 @@ -36,7 +36,7 @@
30140 struct drm_global_item {
30141 struct mutex mutex;
30142 void *object;
30143 - int refcount;
30144 + atomic_t refcount;
30145 };
30146
30147 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30148 @@ -49,7 +49,7 @@ void drm_global_init(void)
30149 struct drm_global_item *item = &glob[i];
30150 mutex_init(&item->mutex);
30151 item->object = NULL;
30152 - item->refcount = 0;
30153 + atomic_set(&item->refcount, 0);
30154 }
30155 }
30156
30157 @@ -59,7 +59,7 @@ void drm_global_release(void)
30158 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30159 struct drm_global_item *item = &glob[i];
30160 BUG_ON(item->object != NULL);
30161 - BUG_ON(item->refcount != 0);
30162 + BUG_ON(atomic_read(&item->refcount) != 0);
30163 }
30164 }
30165
30166 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30167 void *object;
30168
30169 mutex_lock(&item->mutex);
30170 - if (item->refcount == 0) {
30171 + if (atomic_read(&item->refcount) == 0) {
30172 item->object = kzalloc(ref->size, GFP_KERNEL);
30173 if (unlikely(item->object == NULL)) {
30174 ret = -ENOMEM;
30175 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30176 goto out_err;
30177
30178 }
30179 - ++item->refcount;
30180 + atomic_inc(&item->refcount);
30181 ref->object = item->object;
30182 object = item->object;
30183 mutex_unlock(&item->mutex);
30184 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30185 struct drm_global_item *item = &glob[ref->global_type];
30186
30187 mutex_lock(&item->mutex);
30188 - BUG_ON(item->refcount == 0);
30189 + BUG_ON(atomic_read(&item->refcount) == 0);
30190 BUG_ON(ref->object != item->object);
30191 - if (--item->refcount == 0) {
30192 + if (atomic_dec_and_test(&item->refcount)) {
30193 ref->release(ref);
30194 item->object = NULL;
30195 }
30196 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30197 index ab1162d..42587b2 100644
30198 --- a/drivers/gpu/drm/drm_info.c
30199 +++ b/drivers/gpu/drm/drm_info.c
30200 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30201 struct drm_local_map *map;
30202 struct drm_map_list *r_list;
30203
30204 - /* Hardcoded from _DRM_FRAME_BUFFER,
30205 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30206 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30207 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30208 + static const char * const types[] = {
30209 + [_DRM_FRAME_BUFFER] = "FB",
30210 + [_DRM_REGISTERS] = "REG",
30211 + [_DRM_SHM] = "SHM",
30212 + [_DRM_AGP] = "AGP",
30213 + [_DRM_SCATTER_GATHER] = "SG",
30214 + [_DRM_CONSISTENT] = "PCI",
30215 + [_DRM_GEM] = "GEM" };
30216 const char *type;
30217 int i;
30218
30219 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30220 map = r_list->map;
30221 if (!map)
30222 continue;
30223 - if (map->type < 0 || map->type > 5)
30224 + if (map->type >= ARRAY_SIZE(types))
30225 type = "??";
30226 else
30227 type = types[map->type];
30228 @@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30229 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30230 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30231 vma->vm_flags & VM_IO ? 'i' : '-',
30232 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30233 + 0);
30234 +#else
30235 vma->vm_pgoff);
30236 +#endif
30237
30238 #if defined(__i386__)
30239 pgprot = pgprot_val(vma->vm_page_prot);
30240 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30241 index 637fcc3..e890b33 100644
30242 --- a/drivers/gpu/drm/drm_ioc32.c
30243 +++ b/drivers/gpu/drm/drm_ioc32.c
30244 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30245 request = compat_alloc_user_space(nbytes);
30246 if (!access_ok(VERIFY_WRITE, request, nbytes))
30247 return -EFAULT;
30248 - list = (struct drm_buf_desc *) (request + 1);
30249 + list = (struct drm_buf_desc __user *) (request + 1);
30250
30251 if (__put_user(count, &request->count)
30252 || __put_user(list, &request->list))
30253 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30254 request = compat_alloc_user_space(nbytes);
30255 if (!access_ok(VERIFY_WRITE, request, nbytes))
30256 return -EFAULT;
30257 - list = (struct drm_buf_pub *) (request + 1);
30258 + list = (struct drm_buf_pub __user *) (request + 1);
30259
30260 if (__put_user(count, &request->count)
30261 || __put_user(list, &request->list))
30262 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30263 index cf85155..f2665cb 100644
30264 --- a/drivers/gpu/drm/drm_ioctl.c
30265 +++ b/drivers/gpu/drm/drm_ioctl.c
30266 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30267 stats->data[i].value =
30268 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30269 else
30270 - stats->data[i].value = atomic_read(&dev->counts[i]);
30271 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30272 stats->data[i].type = dev->types[i];
30273 }
30274
30275 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30276 index c79c713..2048588 100644
30277 --- a/drivers/gpu/drm/drm_lock.c
30278 +++ b/drivers/gpu/drm/drm_lock.c
30279 @@ -90,7 +90,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30280 if (drm_lock_take(&master->lock, lock->context)) {
30281 master->lock.file_priv = file_priv;
30282 master->lock.lock_time = jiffies;
30283 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30284 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30285 break; /* Got lock */
30286 }
30287
30288 @@ -161,7 +161,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30289 return -EINVAL;
30290 }
30291
30292 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30293 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30294
30295 if (drm_lock_free(&master->lock, lock->context)) {
30296 /* FIXME: Should really bail out here. */
30297 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30298 index aa454f8..6d38580 100644
30299 --- a/drivers/gpu/drm/drm_stub.c
30300 +++ b/drivers/gpu/drm/drm_stub.c
30301 @@ -512,7 +512,7 @@ void drm_unplug_dev(struct drm_device *dev)
30302
30303 drm_device_set_unplugged(dev);
30304
30305 - if (dev->open_count == 0) {
30306 + if (local_read(&dev->open_count) == 0) {
30307 drm_put_dev(dev);
30308 }
30309 mutex_unlock(&drm_global_mutex);
30310 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30311 index f920fb5..001c52d 100644
30312 --- a/drivers/gpu/drm/i810/i810_dma.c
30313 +++ b/drivers/gpu/drm/i810/i810_dma.c
30314 @@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30315 dma->buflist[vertex->idx],
30316 vertex->discard, vertex->used);
30317
30318 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30319 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30320 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30321 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30322 sarea_priv->last_enqueue = dev_priv->counter - 1;
30323 sarea_priv->last_dispatch = (int)hw_status[5];
30324
30325 @@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30326 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30327 mc->last_render);
30328
30329 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30330 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30331 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30332 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30333 sarea_priv->last_enqueue = dev_priv->counter - 1;
30334 sarea_priv->last_dispatch = (int)hw_status[5];
30335
30336 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30337 index c9339f4..f5e1b9d 100644
30338 --- a/drivers/gpu/drm/i810/i810_drv.h
30339 +++ b/drivers/gpu/drm/i810/i810_drv.h
30340 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30341 int page_flipping;
30342
30343 wait_queue_head_t irq_queue;
30344 - atomic_t irq_received;
30345 - atomic_t irq_emitted;
30346 + atomic_unchecked_t irq_received;
30347 + atomic_unchecked_t irq_emitted;
30348
30349 int front_offset;
30350 } drm_i810_private_t;
30351 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30352 index e6162a1..b2ff486 100644
30353 --- a/drivers/gpu/drm/i915/i915_debugfs.c
30354 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
30355 @@ -500,7 +500,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30356 I915_READ(GTIMR));
30357 }
30358 seq_printf(m, "Interrupts received: %d\n",
30359 - atomic_read(&dev_priv->irq_received));
30360 + atomic_read_unchecked(&dev_priv->irq_received));
30361 for (i = 0; i < I915_NUM_RINGS; i++) {
30362 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30363 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30364 @@ -1313,7 +1313,7 @@ static int i915_opregion(struct seq_file *m, void *unused)
30365 return ret;
30366
30367 if (opregion->header)
30368 - seq_write(m, opregion->header, OPREGION_SIZE);
30369 + seq_write(m, (const void __force_kernel *)opregion->header, OPREGION_SIZE);
30370
30371 mutex_unlock(&dev->struct_mutex);
30372
30373 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30374 index ba60f3c..e2dff7f 100644
30375 --- a/drivers/gpu/drm/i915/i915_dma.c
30376 +++ b/drivers/gpu/drm/i915/i915_dma.c
30377 @@ -1178,7 +1178,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30378 bool can_switch;
30379
30380 spin_lock(&dev->count_lock);
30381 - can_switch = (dev->open_count == 0);
30382 + can_switch = (local_read(&dev->open_count) == 0);
30383 spin_unlock(&dev->count_lock);
30384 return can_switch;
30385 }
30386 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30387 index 5fabc6c..0b08aa1 100644
30388 --- a/drivers/gpu/drm/i915/i915_drv.h
30389 +++ b/drivers/gpu/drm/i915/i915_drv.h
30390 @@ -240,7 +240,7 @@ struct drm_i915_display_funcs {
30391 /* render clock increase/decrease */
30392 /* display clock increase/decrease */
30393 /* pll clock increase/decrease */
30394 -};
30395 +} __no_const;
30396
30397 struct intel_device_info {
30398 u8 gen;
30399 @@ -350,7 +350,7 @@ typedef struct drm_i915_private {
30400 int current_page;
30401 int page_flipping;
30402
30403 - atomic_t irq_received;
30404 + atomic_unchecked_t irq_received;
30405
30406 /* protects the irq masks */
30407 spinlock_t irq_lock;
30408 @@ -937,7 +937,7 @@ struct drm_i915_gem_object {
30409 * will be page flipped away on the next vblank. When it
30410 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30411 */
30412 - atomic_t pending_flip;
30413 + atomic_unchecked_t pending_flip;
30414 };
30415
30416 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30417 @@ -1359,7 +1359,7 @@ extern int intel_setup_gmbus(struct drm_device *dev);
30418 extern void intel_teardown_gmbus(struct drm_device *dev);
30419 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30420 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30421 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30422 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30423 {
30424 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30425 }
30426 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30427 index de43194..a14c4cc 100644
30428 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30429 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30430 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30431 i915_gem_clflush_object(obj);
30432
30433 if (obj->base.pending_write_domain)
30434 - cd->flips |= atomic_read(&obj->pending_flip);
30435 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30436
30437 /* The actual obj->write_domain will be updated with
30438 * pending_write_domain after we emit the accumulated flush for all
30439 @@ -933,9 +933,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30440
30441 static int
30442 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30443 - int count)
30444 + unsigned int count)
30445 {
30446 - int i;
30447 + unsigned int i;
30448
30449 for (i = 0; i < count; i++) {
30450 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30451 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30452 index f57e5cf..c82f79d 100644
30453 --- a/drivers/gpu/drm/i915/i915_irq.c
30454 +++ b/drivers/gpu/drm/i915/i915_irq.c
30455 @@ -472,7 +472,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30456 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30457 struct drm_i915_master_private *master_priv;
30458
30459 - atomic_inc(&dev_priv->irq_received);
30460 + atomic_inc_unchecked(&dev_priv->irq_received);
30461
30462 /* disable master interrupt before clearing iir */
30463 de_ier = I915_READ(DEIER);
30464 @@ -563,7 +563,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30465 struct drm_i915_master_private *master_priv;
30466 u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT;
30467
30468 - atomic_inc(&dev_priv->irq_received);
30469 + atomic_inc_unchecked(&dev_priv->irq_received);
30470
30471 if (IS_GEN6(dev))
30472 bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT;
30473 @@ -1292,7 +1292,7 @@ static irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
30474 int ret = IRQ_NONE, pipe;
30475 bool blc_event = false;
30476
30477 - atomic_inc(&dev_priv->irq_received);
30478 + atomic_inc_unchecked(&dev_priv->irq_received);
30479
30480 iir = I915_READ(IIR);
30481
30482 @@ -1803,7 +1803,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30483 {
30484 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30485
30486 - atomic_set(&dev_priv->irq_received, 0);
30487 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30488
30489 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
30490 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
30491 @@ -1980,7 +1980,7 @@ static void i915_driver_irq_preinstall(struct drm_device * dev)
30492 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30493 int pipe;
30494
30495 - atomic_set(&dev_priv->irq_received, 0);
30496 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30497
30498 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
30499 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
30500 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30501 index d4d162f..e80037c 100644
30502 --- a/drivers/gpu/drm/i915/intel_display.c
30503 +++ b/drivers/gpu/drm/i915/intel_display.c
30504 @@ -2254,7 +2254,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
30505
30506 wait_event(dev_priv->pending_flip_queue,
30507 atomic_read(&dev_priv->mm.wedged) ||
30508 - atomic_read(&obj->pending_flip) == 0);
30509 + atomic_read_unchecked(&obj->pending_flip) == 0);
30510
30511 /* Big Hammer, we also need to ensure that any pending
30512 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30513 @@ -2919,7 +2919,7 @@ static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
30514 obj = to_intel_framebuffer(crtc->fb)->obj;
30515 dev_priv = crtc->dev->dev_private;
30516 wait_event(dev_priv->pending_flip_queue,
30517 - atomic_read(&obj->pending_flip) == 0);
30518 + atomic_read_unchecked(&obj->pending_flip) == 0);
30519 }
30520
30521 static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
30522 @@ -7286,7 +7286,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30523
30524 atomic_clear_mask(1 << intel_crtc->plane,
30525 &obj->pending_flip.counter);
30526 - if (atomic_read(&obj->pending_flip) == 0)
30527 + if (atomic_read_unchecked(&obj->pending_flip) == 0)
30528 wake_up(&dev_priv->pending_flip_queue);
30529
30530 schedule_work(&work->work);
30531 @@ -7582,7 +7582,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30532 /* Block clients from rendering to the new back buffer until
30533 * the flip occurs and the object is no longer visible.
30534 */
30535 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30536 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30537
30538 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30539 if (ret)
30540 @@ -7596,7 +7596,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30541 return 0;
30542
30543 cleanup_pending:
30544 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30545 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30546 drm_gem_object_unreference(&work->old_fb_obj->base);
30547 drm_gem_object_unreference(&obj->base);
30548 mutex_unlock(&dev->struct_mutex);
30549 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30550 index 54558a0..2d97005 100644
30551 --- a/drivers/gpu/drm/mga/mga_drv.h
30552 +++ b/drivers/gpu/drm/mga/mga_drv.h
30553 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30554 u32 clear_cmd;
30555 u32 maccess;
30556
30557 - atomic_t vbl_received; /**< Number of vblanks received. */
30558 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30559 wait_queue_head_t fence_queue;
30560 - atomic_t last_fence_retired;
30561 + atomic_unchecked_t last_fence_retired;
30562 u32 next_fence_to_post;
30563
30564 unsigned int fb_cpp;
30565 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30566 index 2581202..f230a8d9 100644
30567 --- a/drivers/gpu/drm/mga/mga_irq.c
30568 +++ b/drivers/gpu/drm/mga/mga_irq.c
30569 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30570 if (crtc != 0)
30571 return 0;
30572
30573 - return atomic_read(&dev_priv->vbl_received);
30574 + return atomic_read_unchecked(&dev_priv->vbl_received);
30575 }
30576
30577
30578 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30579 /* VBLANK interrupt */
30580 if (status & MGA_VLINEPEN) {
30581 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30582 - atomic_inc(&dev_priv->vbl_received);
30583 + atomic_inc_unchecked(&dev_priv->vbl_received);
30584 drm_handle_vblank(dev, 0);
30585 handled = 1;
30586 }
30587 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30588 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30589 MGA_WRITE(MGA_PRIMEND, prim_end);
30590
30591 - atomic_inc(&dev_priv->last_fence_retired);
30592 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
30593 DRM_WAKEUP(&dev_priv->fence_queue);
30594 handled = 1;
30595 }
30596 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30597 * using fences.
30598 */
30599 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30600 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30601 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30602 - *sequence) <= (1 << 23)));
30603
30604 *sequence = cur_fence;
30605 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30606 index 0be4a81..7464804 100644
30607 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30608 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30609 @@ -5329,7 +5329,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30610 struct bit_table {
30611 const char id;
30612 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30613 -};
30614 +} __no_const;
30615
30616 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30617
30618 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30619 index 3aef353..0ad1322 100644
30620 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30621 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30622 @@ -240,7 +240,7 @@ struct nouveau_channel {
30623 struct list_head pending;
30624 uint32_t sequence;
30625 uint32_t sequence_ack;
30626 - atomic_t last_sequence_irq;
30627 + atomic_unchecked_t last_sequence_irq;
30628 struct nouveau_vma vma;
30629 } fence;
30630
30631 @@ -321,7 +321,7 @@ struct nouveau_exec_engine {
30632 u32 handle, u16 class);
30633 void (*set_tile_region)(struct drm_device *dev, int i);
30634 void (*tlb_flush)(struct drm_device *, int engine);
30635 -};
30636 +} __no_const;
30637
30638 struct nouveau_instmem_engine {
30639 void *priv;
30640 @@ -343,13 +343,13 @@ struct nouveau_instmem_engine {
30641 struct nouveau_mc_engine {
30642 int (*init)(struct drm_device *dev);
30643 void (*takedown)(struct drm_device *dev);
30644 -};
30645 +} __no_const;
30646
30647 struct nouveau_timer_engine {
30648 int (*init)(struct drm_device *dev);
30649 void (*takedown)(struct drm_device *dev);
30650 uint64_t (*read)(struct drm_device *dev);
30651 -};
30652 +} __no_const;
30653
30654 struct nouveau_fb_engine {
30655 int num_tiles;
30656 @@ -590,7 +590,7 @@ struct nouveau_vram_engine {
30657 void (*put)(struct drm_device *, struct nouveau_mem **);
30658
30659 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30660 -};
30661 +} __no_const;
30662
30663 struct nouveau_engine {
30664 struct nouveau_instmem_engine instmem;
30665 @@ -739,7 +739,7 @@ struct drm_nouveau_private {
30666 struct drm_global_reference mem_global_ref;
30667 struct ttm_bo_global_ref bo_global_ref;
30668 struct ttm_bo_device bdev;
30669 - atomic_t validate_sequence;
30670 + atomic_unchecked_t validate_sequence;
30671 } ttm;
30672
30673 struct {
30674 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
30675 index c1dc20f..4df673c 100644
30676 --- a/drivers/gpu/drm/nouveau/nouveau_fence.c
30677 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
30678 @@ -85,7 +85,7 @@ nouveau_fence_update(struct nouveau_channel *chan)
30679 if (USE_REFCNT(dev))
30680 sequence = nvchan_rd32(chan, 0x48);
30681 else
30682 - sequence = atomic_read(&chan->fence.last_sequence_irq);
30683 + sequence = atomic_read_unchecked(&chan->fence.last_sequence_irq);
30684
30685 if (chan->fence.sequence_ack == sequence)
30686 goto out;
30687 @@ -538,7 +538,7 @@ nouveau_fence_channel_init(struct nouveau_channel *chan)
30688 return ret;
30689 }
30690
30691 - atomic_set(&chan->fence.last_sequence_irq, 0);
30692 + atomic_set_unchecked(&chan->fence.last_sequence_irq, 0);
30693 return 0;
30694 }
30695
30696 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30697 index ed52a6f..484acdc 100644
30698 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30699 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30700 @@ -314,7 +314,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30701 int trycnt = 0;
30702 int ret, i;
30703
30704 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30705 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30706 retry:
30707 if (++trycnt > 100000) {
30708 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30709 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30710 index c2a8511..4b996f9 100644
30711 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
30712 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30713 @@ -588,7 +588,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30714 bool can_switch;
30715
30716 spin_lock(&dev->count_lock);
30717 - can_switch = (dev->open_count == 0);
30718 + can_switch = (local_read(&dev->open_count) == 0);
30719 spin_unlock(&dev->count_lock);
30720 return can_switch;
30721 }
30722 diff --git a/drivers/gpu/drm/nouveau/nv04_graph.c b/drivers/gpu/drm/nouveau/nv04_graph.c
30723 index dbdea8e..cd6eeeb 100644
30724 --- a/drivers/gpu/drm/nouveau/nv04_graph.c
30725 +++ b/drivers/gpu/drm/nouveau/nv04_graph.c
30726 @@ -554,7 +554,7 @@ static int
30727 nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
30728 u32 class, u32 mthd, u32 data)
30729 {
30730 - atomic_set(&chan->fence.last_sequence_irq, data);
30731 + atomic_set_unchecked(&chan->fence.last_sequence_irq, data);
30732 return 0;
30733 }
30734
30735 diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
30736 index 2746402..c8dc4a4 100644
30737 --- a/drivers/gpu/drm/nouveau/nv50_sor.c
30738 +++ b/drivers/gpu/drm/nouveau/nv50_sor.c
30739 @@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
30740 }
30741
30742 if (nv_encoder->dcb->type == OUTPUT_DP) {
30743 - struct dp_train_func func = {
30744 + static struct dp_train_func func = {
30745 .link_set = nv50_sor_dp_link_set,
30746 .train_set = nv50_sor_dp_train_set,
30747 .train_adj = nv50_sor_dp_train_adj
30748 diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
30749 index 0247250..d2f6aaf 100644
30750 --- a/drivers/gpu/drm/nouveau/nvd0_display.c
30751 +++ b/drivers/gpu/drm/nouveau/nvd0_display.c
30752 @@ -1366,7 +1366,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
30753 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
30754
30755 if (nv_encoder->dcb->type == OUTPUT_DP) {
30756 - struct dp_train_func func = {
30757 + static struct dp_train_func func = {
30758 .link_set = nvd0_sor_dp_link_set,
30759 .train_set = nvd0_sor_dp_train_set,
30760 .train_adj = nvd0_sor_dp_train_adj
30761 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
30762 index bcac90b..53bfc76 100644
30763 --- a/drivers/gpu/drm/r128/r128_cce.c
30764 +++ b/drivers/gpu/drm/r128/r128_cce.c
30765 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
30766
30767 /* GH: Simple idle check.
30768 */
30769 - atomic_set(&dev_priv->idle_count, 0);
30770 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30771
30772 /* We don't support anything other than bus-mastering ring mode,
30773 * but the ring can be in either AGP or PCI space for the ring
30774 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
30775 index 930c71b..499aded 100644
30776 --- a/drivers/gpu/drm/r128/r128_drv.h
30777 +++ b/drivers/gpu/drm/r128/r128_drv.h
30778 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
30779 int is_pci;
30780 unsigned long cce_buffers_offset;
30781
30782 - atomic_t idle_count;
30783 + atomic_unchecked_t idle_count;
30784
30785 int page_flipping;
30786 int current_page;
30787 u32 crtc_offset;
30788 u32 crtc_offset_cntl;
30789
30790 - atomic_t vbl_received;
30791 + atomic_unchecked_t vbl_received;
30792
30793 u32 color_fmt;
30794 unsigned int front_offset;
30795 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
30796 index 429d5a0..7e899ed 100644
30797 --- a/drivers/gpu/drm/r128/r128_irq.c
30798 +++ b/drivers/gpu/drm/r128/r128_irq.c
30799 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
30800 if (crtc != 0)
30801 return 0;
30802
30803 - return atomic_read(&dev_priv->vbl_received);
30804 + return atomic_read_unchecked(&dev_priv->vbl_received);
30805 }
30806
30807 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30808 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30809 /* VBLANK interrupt */
30810 if (status & R128_CRTC_VBLANK_INT) {
30811 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
30812 - atomic_inc(&dev_priv->vbl_received);
30813 + atomic_inc_unchecked(&dev_priv->vbl_received);
30814 drm_handle_vblank(dev, 0);
30815 return IRQ_HANDLED;
30816 }
30817 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
30818 index a9e33ce..09edd4b 100644
30819 --- a/drivers/gpu/drm/r128/r128_state.c
30820 +++ b/drivers/gpu/drm/r128/r128_state.c
30821 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
30822
30823 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
30824 {
30825 - if (atomic_read(&dev_priv->idle_count) == 0)
30826 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
30827 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
30828 else
30829 - atomic_set(&dev_priv->idle_count, 0);
30830 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30831 }
30832
30833 #endif
30834 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
30835 index 5a82b6b..9e69c73 100644
30836 --- a/drivers/gpu/drm/radeon/mkregtable.c
30837 +++ b/drivers/gpu/drm/radeon/mkregtable.c
30838 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
30839 regex_t mask_rex;
30840 regmatch_t match[4];
30841 char buf[1024];
30842 - size_t end;
30843 + long end;
30844 int len;
30845 int done = 0;
30846 int r;
30847 unsigned o;
30848 struct offset *offset;
30849 char last_reg_s[10];
30850 - int last_reg;
30851 + unsigned long last_reg;
30852
30853 if (regcomp
30854 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
30855 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
30856 index 138b952..d74f9cb 100644
30857 --- a/drivers/gpu/drm/radeon/radeon.h
30858 +++ b/drivers/gpu/drm/radeon/radeon.h
30859 @@ -253,7 +253,7 @@ struct radeon_fence_driver {
30860 uint32_t scratch_reg;
30861 uint64_t gpu_addr;
30862 volatile uint32_t *cpu_addr;
30863 - atomic_t seq;
30864 + atomic_unchecked_t seq;
30865 uint32_t last_seq;
30866 unsigned long last_jiffies;
30867 unsigned long last_timeout;
30868 @@ -753,7 +753,7 @@ struct r600_blit_cp_primitives {
30869 int x2, int y2);
30870 void (*draw_auto)(struct radeon_device *rdev);
30871 void (*set_default_state)(struct radeon_device *rdev);
30872 -};
30873 +} __no_const;
30874
30875 struct r600_blit {
30876 struct mutex mutex;
30877 @@ -1246,7 +1246,7 @@ struct radeon_asic {
30878 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
30879 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
30880 } pflip;
30881 -};
30882 +} __no_const;
30883
30884 /*
30885 * Asic structures
30886 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
30887 index 5992502..c19c633 100644
30888 --- a/drivers/gpu/drm/radeon/radeon_device.c
30889 +++ b/drivers/gpu/drm/radeon/radeon_device.c
30890 @@ -691,7 +691,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
30891 bool can_switch;
30892
30893 spin_lock(&dev->count_lock);
30894 - can_switch = (dev->open_count == 0);
30895 + can_switch = (local_read(&dev->open_count) == 0);
30896 spin_unlock(&dev->count_lock);
30897 return can_switch;
30898 }
30899 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
30900 index a1b59ca..86f2d44 100644
30901 --- a/drivers/gpu/drm/radeon/radeon_drv.h
30902 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
30903 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
30904
30905 /* SW interrupt */
30906 wait_queue_head_t swi_queue;
30907 - atomic_t swi_emitted;
30908 + atomic_unchecked_t swi_emitted;
30909 int vblank_crtc;
30910 uint32_t irq_enable_reg;
30911 uint32_t r500_disp_irq_reg;
30912 diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
30913 index 4bd36a3..e66fe9c 100644
30914 --- a/drivers/gpu/drm/radeon/radeon_fence.c
30915 +++ b/drivers/gpu/drm/radeon/radeon_fence.c
30916 @@ -70,7 +70,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
30917 write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
30918 return 0;
30919 }
30920 - fence->seq = atomic_add_return(1, &rdev->fence_drv[fence->ring].seq);
30921 + fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv[fence->ring].seq);
30922 if (!rdev->ring[fence->ring].ready)
30923 /* FIXME: cp is not running assume everythings is done right
30924 * away
30925 @@ -405,7 +405,7 @@ int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring)
30926 }
30927 rdev->fence_drv[ring].cpu_addr = &rdev->wb.wb[index/4];
30928 rdev->fence_drv[ring].gpu_addr = rdev->wb.gpu_addr + index;
30929 - radeon_fence_write(rdev, atomic_read(&rdev->fence_drv[ring].seq), ring);
30930 + radeon_fence_write(rdev, atomic_read_unchecked(&rdev->fence_drv[ring].seq), ring);
30931 rdev->fence_drv[ring].initialized = true;
30932 DRM_INFO("fence driver on ring %d use gpu addr 0x%08Lx and cpu addr 0x%p\n",
30933 ring, rdev->fence_drv[ring].gpu_addr, rdev->fence_drv[ring].cpu_addr);
30934 @@ -418,7 +418,7 @@ static void radeon_fence_driver_init_ring(struct radeon_device *rdev, int ring)
30935 rdev->fence_drv[ring].scratch_reg = -1;
30936 rdev->fence_drv[ring].cpu_addr = NULL;
30937 rdev->fence_drv[ring].gpu_addr = 0;
30938 - atomic_set(&rdev->fence_drv[ring].seq, 0);
30939 + atomic_set_unchecked(&rdev->fence_drv[ring].seq, 0);
30940 INIT_LIST_HEAD(&rdev->fence_drv[ring].created);
30941 INIT_LIST_HEAD(&rdev->fence_drv[ring].emitted);
30942 INIT_LIST_HEAD(&rdev->fence_drv[ring].signaled);
30943 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
30944 index 48b7cea..342236f 100644
30945 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
30946 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
30947 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
30948 request = compat_alloc_user_space(sizeof(*request));
30949 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
30950 || __put_user(req32.param, &request->param)
30951 - || __put_user((void __user *)(unsigned long)req32.value,
30952 + || __put_user((unsigned long)req32.value,
30953 &request->value))
30954 return -EFAULT;
30955
30956 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
30957 index 00da384..32f972d 100644
30958 --- a/drivers/gpu/drm/radeon/radeon_irq.c
30959 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
30960 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
30961 unsigned int ret;
30962 RING_LOCALS;
30963
30964 - atomic_inc(&dev_priv->swi_emitted);
30965 - ret = atomic_read(&dev_priv->swi_emitted);
30966 + atomic_inc_unchecked(&dev_priv->swi_emitted);
30967 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
30968
30969 BEGIN_RING(4);
30970 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
30971 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
30972 drm_radeon_private_t *dev_priv =
30973 (drm_radeon_private_t *) dev->dev_private;
30974
30975 - atomic_set(&dev_priv->swi_emitted, 0);
30976 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
30977 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
30978
30979 dev->max_vblank_count = 0x001fffff;
30980 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
30981 index e8422ae..d22d4a8 100644
30982 --- a/drivers/gpu/drm/radeon/radeon_state.c
30983 +++ b/drivers/gpu/drm/radeon/radeon_state.c
30984 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
30985 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
30986 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
30987
30988 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30989 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30990 sarea_priv->nbox * sizeof(depth_boxes[0])))
30991 return -EFAULT;
30992
30993 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
30994 {
30995 drm_radeon_private_t *dev_priv = dev->dev_private;
30996 drm_radeon_getparam_t *param = data;
30997 - int value;
30998 + int value = 0;
30999
31000 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
31001
31002 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
31003 index f493c64..524ab6b 100644
31004 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
31005 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
31006 @@ -843,8 +843,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
31007 }
31008 if (unlikely(ttm_vm_ops == NULL)) {
31009 ttm_vm_ops = vma->vm_ops;
31010 - radeon_ttm_vm_ops = *ttm_vm_ops;
31011 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31012 + pax_open_kernel();
31013 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
31014 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31015 + pax_close_kernel();
31016 }
31017 vma->vm_ops = &radeon_ttm_vm_ops;
31018 return 0;
31019 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31020 index f2c3b9d..d5a376b 100644
31021 --- a/drivers/gpu/drm/radeon/rs690.c
31022 +++ b/drivers/gpu/drm/radeon/rs690.c
31023 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31024 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31025 rdev->pm.sideport_bandwidth.full)
31026 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31027 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31028 + read_delay_latency.full = dfixed_const(800 * 1000);
31029 read_delay_latency.full = dfixed_div(read_delay_latency,
31030 rdev->pm.igp_sideport_mclk);
31031 + a.full = dfixed_const(370);
31032 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31033 } else {
31034 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31035 rdev->pm.k8_bandwidth.full)
31036 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31037 index ebc6fac..a8313ed 100644
31038 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31039 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31040 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
31041 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31042 struct shrink_control *sc)
31043 {
31044 - static atomic_t start_pool = ATOMIC_INIT(0);
31045 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31046 unsigned i;
31047 - unsigned pool_offset = atomic_add_return(1, &start_pool);
31048 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31049 struct ttm_page_pool *pool;
31050 int shrink_pages = sc->nr_to_scan;
31051
31052 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31053 index 88edacc..1e5412b 100644
31054 --- a/drivers/gpu/drm/via/via_drv.h
31055 +++ b/drivers/gpu/drm/via/via_drv.h
31056 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31057 typedef uint32_t maskarray_t[5];
31058
31059 typedef struct drm_via_irq {
31060 - atomic_t irq_received;
31061 + atomic_unchecked_t irq_received;
31062 uint32_t pending_mask;
31063 uint32_t enable_mask;
31064 wait_queue_head_t irq_queue;
31065 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
31066 struct timeval last_vblank;
31067 int last_vblank_valid;
31068 unsigned usec_per_vblank;
31069 - atomic_t vbl_received;
31070 + atomic_unchecked_t vbl_received;
31071 drm_via_state_t hc_state;
31072 char pci_buf[VIA_PCI_BUF_SIZE];
31073 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31074 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31075 index d391f48..10c8ca3 100644
31076 --- a/drivers/gpu/drm/via/via_irq.c
31077 +++ b/drivers/gpu/drm/via/via_irq.c
31078 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31079 if (crtc != 0)
31080 return 0;
31081
31082 - return atomic_read(&dev_priv->vbl_received);
31083 + return atomic_read_unchecked(&dev_priv->vbl_received);
31084 }
31085
31086 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31087 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31088
31089 status = VIA_READ(VIA_REG_INTERRUPT);
31090 if (status & VIA_IRQ_VBLANK_PENDING) {
31091 - atomic_inc(&dev_priv->vbl_received);
31092 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31093 + atomic_inc_unchecked(&dev_priv->vbl_received);
31094 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31095 do_gettimeofday(&cur_vblank);
31096 if (dev_priv->last_vblank_valid) {
31097 dev_priv->usec_per_vblank =
31098 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31099 dev_priv->last_vblank = cur_vblank;
31100 dev_priv->last_vblank_valid = 1;
31101 }
31102 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31103 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31104 DRM_DEBUG("US per vblank is: %u\n",
31105 dev_priv->usec_per_vblank);
31106 }
31107 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31108
31109 for (i = 0; i < dev_priv->num_irqs; ++i) {
31110 if (status & cur_irq->pending_mask) {
31111 - atomic_inc(&cur_irq->irq_received);
31112 + atomic_inc_unchecked(&cur_irq->irq_received);
31113 DRM_WAKEUP(&cur_irq->irq_queue);
31114 handled = 1;
31115 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31116 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31117 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31118 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31119 masks[irq][4]));
31120 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31121 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31122 } else {
31123 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31124 (((cur_irq_sequence =
31125 - atomic_read(&cur_irq->irq_received)) -
31126 + atomic_read_unchecked(&cur_irq->irq_received)) -
31127 *sequence) <= (1 << 23)));
31128 }
31129 *sequence = cur_irq_sequence;
31130 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31131 }
31132
31133 for (i = 0; i < dev_priv->num_irqs; ++i) {
31134 - atomic_set(&cur_irq->irq_received, 0);
31135 + atomic_set_unchecked(&cur_irq->irq_received, 0);
31136 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31137 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31138 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31139 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31140 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31141 case VIA_IRQ_RELATIVE:
31142 irqwait->request.sequence +=
31143 - atomic_read(&cur_irq->irq_received);
31144 + atomic_read_unchecked(&cur_irq->irq_received);
31145 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31146 case VIA_IRQ_ABSOLUTE:
31147 break;
31148 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31149 index d0f2c07..9ebd9c3 100644
31150 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31151 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31152 @@ -263,7 +263,7 @@ struct vmw_private {
31153 * Fencing and IRQs.
31154 */
31155
31156 - atomic_t marker_seq;
31157 + atomic_unchecked_t marker_seq;
31158 wait_queue_head_t fence_queue;
31159 wait_queue_head_t fifo_queue;
31160 int fence_queue_waiters; /* Protected by hw_mutex */
31161 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31162 index a0c2f12..68ae6cb 100644
31163 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31164 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31165 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31166 (unsigned int) min,
31167 (unsigned int) fifo->capabilities);
31168
31169 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31170 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31171 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31172 vmw_marker_queue_init(&fifo->marker_queue);
31173 return vmw_fifo_send_fence(dev_priv, &dummy);
31174 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31175 if (reserveable)
31176 iowrite32(bytes, fifo_mem +
31177 SVGA_FIFO_RESERVED);
31178 - return fifo_mem + (next_cmd >> 2);
31179 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31180 } else {
31181 need_bounce = true;
31182 }
31183 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31184
31185 fm = vmw_fifo_reserve(dev_priv, bytes);
31186 if (unlikely(fm == NULL)) {
31187 - *seqno = atomic_read(&dev_priv->marker_seq);
31188 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31189 ret = -ENOMEM;
31190 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31191 false, 3*HZ);
31192 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31193 }
31194
31195 do {
31196 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31197 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31198 } while (*seqno == 0);
31199
31200 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31201 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31202 index cabc95f..14b3d77 100644
31203 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31204 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31205 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31206 * emitted. Then the fence is stale and signaled.
31207 */
31208
31209 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31210 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31211 > VMW_FENCE_WRAP);
31212
31213 return ret;
31214 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31215
31216 if (fifo_idle)
31217 down_read(&fifo_state->rwsem);
31218 - signal_seq = atomic_read(&dev_priv->marker_seq);
31219 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31220 ret = 0;
31221
31222 for (;;) {
31223 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31224 index 8a8725c..afed796 100644
31225 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31226 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31227 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31228 while (!vmw_lag_lt(queue, us)) {
31229 spin_lock(&queue->lock);
31230 if (list_empty(&queue->head))
31231 - seqno = atomic_read(&dev_priv->marker_seq);
31232 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31233 else {
31234 marker = list_first_entry(&queue->head,
31235 struct vmw_marker, head);
31236 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31237 index 4da66b4..e948655 100644
31238 --- a/drivers/hid/hid-core.c
31239 +++ b/drivers/hid/hid-core.c
31240 @@ -2063,7 +2063,7 @@ static bool hid_ignore(struct hid_device *hdev)
31241
31242 int hid_add_device(struct hid_device *hdev)
31243 {
31244 - static atomic_t id = ATOMIC_INIT(0);
31245 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31246 int ret;
31247
31248 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31249 @@ -2078,7 +2078,7 @@ int hid_add_device(struct hid_device *hdev)
31250 /* XXX hack, any other cleaner solution after the driver core
31251 * is converted to allow more than 20 bytes as the device name? */
31252 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31253 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31254 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31255
31256 hid_debug_register(hdev, dev_name(&hdev->dev));
31257 ret = device_add(&hdev->dev);
31258 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31259 index eec3291..8ed706b 100644
31260 --- a/drivers/hid/hid-wiimote-debug.c
31261 +++ b/drivers/hid/hid-wiimote-debug.c
31262 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31263 else if (size == 0)
31264 return -EIO;
31265
31266 - if (copy_to_user(u, buf, size))
31267 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
31268 return -EFAULT;
31269
31270 *off += size;
31271 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31272 index b1ec0e2..c295a61 100644
31273 --- a/drivers/hid/usbhid/hiddev.c
31274 +++ b/drivers/hid/usbhid/hiddev.c
31275 @@ -624,7 +624,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31276 break;
31277
31278 case HIDIOCAPPLICATION:
31279 - if (arg < 0 || arg >= hid->maxapplication)
31280 + if (arg >= hid->maxapplication)
31281 break;
31282
31283 for (i = 0; i < hid->maxcollection; i++)
31284 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31285 index 4065374..10ed7dc 100644
31286 --- a/drivers/hv/channel.c
31287 +++ b/drivers/hv/channel.c
31288 @@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31289 int ret = 0;
31290 int t;
31291
31292 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31293 - atomic_inc(&vmbus_connection.next_gpadl_handle);
31294 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31295 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31296
31297 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31298 if (ret)
31299 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31300 index 15956bd..ea34398 100644
31301 --- a/drivers/hv/hv.c
31302 +++ b/drivers/hv/hv.c
31303 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31304 u64 output_address = (output) ? virt_to_phys(output) : 0;
31305 u32 output_address_hi = output_address >> 32;
31306 u32 output_address_lo = output_address & 0xFFFFFFFF;
31307 - void *hypercall_page = hv_context.hypercall_page;
31308 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31309
31310 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31311 "=a"(hv_status_lo) : "d" (control_hi),
31312 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31313 index 699f0d8..f4f19250 100644
31314 --- a/drivers/hv/hyperv_vmbus.h
31315 +++ b/drivers/hv/hyperv_vmbus.h
31316 @@ -555,7 +555,7 @@ enum vmbus_connect_state {
31317 struct vmbus_connection {
31318 enum vmbus_connect_state conn_state;
31319
31320 - atomic_t next_gpadl_handle;
31321 + atomic_unchecked_t next_gpadl_handle;
31322
31323 /*
31324 * Represents channel interrupts. Each bit position represents a
31325 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31326 index a220e57..428f54d 100644
31327 --- a/drivers/hv/vmbus_drv.c
31328 +++ b/drivers/hv/vmbus_drv.c
31329 @@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31330 {
31331 int ret = 0;
31332
31333 - static atomic_t device_num = ATOMIC_INIT(0);
31334 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31335
31336 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31337 - atomic_inc_return(&device_num));
31338 + atomic_inc_return_unchecked(&device_num));
31339
31340 child_device_obj->device.bus = &hv_bus;
31341 child_device_obj->device.parent = &hv_acpi_dev->dev;
31342 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
31343 index 9140236..ceaef4e 100644
31344 --- a/drivers/hwmon/acpi_power_meter.c
31345 +++ b/drivers/hwmon/acpi_power_meter.c
31346 @@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
31347 return res;
31348
31349 temp /= 1000;
31350 - if (temp < 0)
31351 - return -EINVAL;
31352
31353 mutex_lock(&resource->lock);
31354 resource->trip[attr->index - 7] = temp;
31355 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31356 index 8b011d0..3de24a1 100644
31357 --- a/drivers/hwmon/sht15.c
31358 +++ b/drivers/hwmon/sht15.c
31359 @@ -166,7 +166,7 @@ struct sht15_data {
31360 int supply_uV;
31361 bool supply_uV_valid;
31362 struct work_struct update_supply_work;
31363 - atomic_t interrupt_handled;
31364 + atomic_unchecked_t interrupt_handled;
31365 };
31366
31367 /**
31368 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31369 return ret;
31370
31371 gpio_direction_input(data->pdata->gpio_data);
31372 - atomic_set(&data->interrupt_handled, 0);
31373 + atomic_set_unchecked(&data->interrupt_handled, 0);
31374
31375 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31376 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31377 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31378 /* Only relevant if the interrupt hasn't occurred. */
31379 - if (!atomic_read(&data->interrupt_handled))
31380 + if (!atomic_read_unchecked(&data->interrupt_handled))
31381 schedule_work(&data->read_work);
31382 }
31383 ret = wait_event_timeout(data->wait_queue,
31384 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31385
31386 /* First disable the interrupt */
31387 disable_irq_nosync(irq);
31388 - atomic_inc(&data->interrupt_handled);
31389 + atomic_inc_unchecked(&data->interrupt_handled);
31390 /* Then schedule a reading work struct */
31391 if (data->state != SHT15_READING_NOTHING)
31392 schedule_work(&data->read_work);
31393 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31394 * If not, then start the interrupt again - care here as could
31395 * have gone low in meantime so verify it hasn't!
31396 */
31397 - atomic_set(&data->interrupt_handled, 0);
31398 + atomic_set_unchecked(&data->interrupt_handled, 0);
31399 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31400 /* If still not occurred or another handler was scheduled */
31401 if (gpio_get_value(data->pdata->gpio_data)
31402 - || atomic_read(&data->interrupt_handled))
31403 + || atomic_read_unchecked(&data->interrupt_handled))
31404 return;
31405 }
31406
31407 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31408 index 378fcb5..5e91fa8 100644
31409 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
31410 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31411 @@ -43,7 +43,7 @@
31412 extern struct i2c_adapter amd756_smbus;
31413
31414 static struct i2c_adapter *s4882_adapter;
31415 -static struct i2c_algorithm *s4882_algo;
31416 +static i2c_algorithm_no_const *s4882_algo;
31417
31418 /* Wrapper access functions for multiplexed SMBus */
31419 static DEFINE_MUTEX(amd756_lock);
31420 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31421 index 29015eb..af2d8e9 100644
31422 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31423 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31424 @@ -41,7 +41,7 @@
31425 extern struct i2c_adapter *nforce2_smbus;
31426
31427 static struct i2c_adapter *s4985_adapter;
31428 -static struct i2c_algorithm *s4985_algo;
31429 +static i2c_algorithm_no_const *s4985_algo;
31430
31431 /* Wrapper access functions for multiplexed SMBus */
31432 static DEFINE_MUTEX(nforce2_lock);
31433 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31434 index d7a4833..7fae376 100644
31435 --- a/drivers/i2c/i2c-mux.c
31436 +++ b/drivers/i2c/i2c-mux.c
31437 @@ -28,7 +28,7 @@
31438 /* multiplexer per channel data */
31439 struct i2c_mux_priv {
31440 struct i2c_adapter adap;
31441 - struct i2c_algorithm algo;
31442 + i2c_algorithm_no_const algo;
31443
31444 struct i2c_adapter *parent;
31445 void *mux_dev; /* the mux chip/device */
31446 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31447 index 57d00ca..0145194 100644
31448 --- a/drivers/ide/aec62xx.c
31449 +++ b/drivers/ide/aec62xx.c
31450 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31451 .cable_detect = atp86x_cable_detect,
31452 };
31453
31454 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31455 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31456 { /* 0: AEC6210 */
31457 .name = DRV_NAME,
31458 .init_chipset = init_chipset_aec62xx,
31459 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31460 index 2c8016a..911a27c 100644
31461 --- a/drivers/ide/alim15x3.c
31462 +++ b/drivers/ide/alim15x3.c
31463 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31464 .dma_sff_read_status = ide_dma_sff_read_status,
31465 };
31466
31467 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
31468 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
31469 .name = DRV_NAME,
31470 .init_chipset = init_chipset_ali15x3,
31471 .init_hwif = init_hwif_ali15x3,
31472 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31473 index 3747b25..56fc995 100644
31474 --- a/drivers/ide/amd74xx.c
31475 +++ b/drivers/ide/amd74xx.c
31476 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31477 .udma_mask = udma, \
31478 }
31479
31480 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31481 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31482 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31483 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31484 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31485 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31486 index 15f0ead..cb43480 100644
31487 --- a/drivers/ide/atiixp.c
31488 +++ b/drivers/ide/atiixp.c
31489 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31490 .cable_detect = atiixp_cable_detect,
31491 };
31492
31493 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31494 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31495 { /* 0: IXP200/300/400/700 */
31496 .name = DRV_NAME,
31497 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31498 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31499 index 5f80312..d1fc438 100644
31500 --- a/drivers/ide/cmd64x.c
31501 +++ b/drivers/ide/cmd64x.c
31502 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31503 .dma_sff_read_status = ide_dma_sff_read_status,
31504 };
31505
31506 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31507 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31508 { /* 0: CMD643 */
31509 .name = DRV_NAME,
31510 .init_chipset = init_chipset_cmd64x,
31511 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31512 index 2c1e5f7..1444762 100644
31513 --- a/drivers/ide/cs5520.c
31514 +++ b/drivers/ide/cs5520.c
31515 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31516 .set_dma_mode = cs5520_set_dma_mode,
31517 };
31518
31519 -static const struct ide_port_info cyrix_chipset __devinitdata = {
31520 +static const struct ide_port_info cyrix_chipset __devinitconst = {
31521 .name = DRV_NAME,
31522 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31523 .port_ops = &cs5520_port_ops,
31524 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31525 index 4dc4eb9..49b40ad 100644
31526 --- a/drivers/ide/cs5530.c
31527 +++ b/drivers/ide/cs5530.c
31528 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31529 .udma_filter = cs5530_udma_filter,
31530 };
31531
31532 -static const struct ide_port_info cs5530_chipset __devinitdata = {
31533 +static const struct ide_port_info cs5530_chipset __devinitconst = {
31534 .name = DRV_NAME,
31535 .init_chipset = init_chipset_cs5530,
31536 .init_hwif = init_hwif_cs5530,
31537 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31538 index 5059faf..18d4c85 100644
31539 --- a/drivers/ide/cs5535.c
31540 +++ b/drivers/ide/cs5535.c
31541 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31542 .cable_detect = cs5535_cable_detect,
31543 };
31544
31545 -static const struct ide_port_info cs5535_chipset __devinitdata = {
31546 +static const struct ide_port_info cs5535_chipset __devinitconst = {
31547 .name = DRV_NAME,
31548 .port_ops = &cs5535_port_ops,
31549 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31550 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31551 index 847553f..3ffb49d 100644
31552 --- a/drivers/ide/cy82c693.c
31553 +++ b/drivers/ide/cy82c693.c
31554 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31555 .set_dma_mode = cy82c693_set_dma_mode,
31556 };
31557
31558 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
31559 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
31560 .name = DRV_NAME,
31561 .init_iops = init_iops_cy82c693,
31562 .port_ops = &cy82c693_port_ops,
31563 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31564 index 58c51cd..4aec3b8 100644
31565 --- a/drivers/ide/hpt366.c
31566 +++ b/drivers/ide/hpt366.c
31567 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31568 }
31569 };
31570
31571 -static const struct hpt_info hpt36x __devinitdata = {
31572 +static const struct hpt_info hpt36x __devinitconst = {
31573 .chip_name = "HPT36x",
31574 .chip_type = HPT36x,
31575 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31576 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31577 .timings = &hpt36x_timings
31578 };
31579
31580 -static const struct hpt_info hpt370 __devinitdata = {
31581 +static const struct hpt_info hpt370 __devinitconst = {
31582 .chip_name = "HPT370",
31583 .chip_type = HPT370,
31584 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31585 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31586 .timings = &hpt37x_timings
31587 };
31588
31589 -static const struct hpt_info hpt370a __devinitdata = {
31590 +static const struct hpt_info hpt370a __devinitconst = {
31591 .chip_name = "HPT370A",
31592 .chip_type = HPT370A,
31593 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31594 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31595 .timings = &hpt37x_timings
31596 };
31597
31598 -static const struct hpt_info hpt374 __devinitdata = {
31599 +static const struct hpt_info hpt374 __devinitconst = {
31600 .chip_name = "HPT374",
31601 .chip_type = HPT374,
31602 .udma_mask = ATA_UDMA5,
31603 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31604 .timings = &hpt37x_timings
31605 };
31606
31607 -static const struct hpt_info hpt372 __devinitdata = {
31608 +static const struct hpt_info hpt372 __devinitconst = {
31609 .chip_name = "HPT372",
31610 .chip_type = HPT372,
31611 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31612 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31613 .timings = &hpt37x_timings
31614 };
31615
31616 -static const struct hpt_info hpt372a __devinitdata = {
31617 +static const struct hpt_info hpt372a __devinitconst = {
31618 .chip_name = "HPT372A",
31619 .chip_type = HPT372A,
31620 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31621 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31622 .timings = &hpt37x_timings
31623 };
31624
31625 -static const struct hpt_info hpt302 __devinitdata = {
31626 +static const struct hpt_info hpt302 __devinitconst = {
31627 .chip_name = "HPT302",
31628 .chip_type = HPT302,
31629 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31630 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31631 .timings = &hpt37x_timings
31632 };
31633
31634 -static const struct hpt_info hpt371 __devinitdata = {
31635 +static const struct hpt_info hpt371 __devinitconst = {
31636 .chip_name = "HPT371",
31637 .chip_type = HPT371,
31638 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31639 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31640 .timings = &hpt37x_timings
31641 };
31642
31643 -static const struct hpt_info hpt372n __devinitdata = {
31644 +static const struct hpt_info hpt372n __devinitconst = {
31645 .chip_name = "HPT372N",
31646 .chip_type = HPT372N,
31647 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31648 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31649 .timings = &hpt37x_timings
31650 };
31651
31652 -static const struct hpt_info hpt302n __devinitdata = {
31653 +static const struct hpt_info hpt302n __devinitconst = {
31654 .chip_name = "HPT302N",
31655 .chip_type = HPT302N,
31656 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31657 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31658 .timings = &hpt37x_timings
31659 };
31660
31661 -static const struct hpt_info hpt371n __devinitdata = {
31662 +static const struct hpt_info hpt371n __devinitconst = {
31663 .chip_name = "HPT371N",
31664 .chip_type = HPT371N,
31665 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31666 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31667 .dma_sff_read_status = ide_dma_sff_read_status,
31668 };
31669
31670 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31671 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31672 { /* 0: HPT36x */
31673 .name = DRV_NAME,
31674 .init_chipset = init_chipset_hpt366,
31675 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31676 index 8126824..55a2798 100644
31677 --- a/drivers/ide/ide-cd.c
31678 +++ b/drivers/ide/ide-cd.c
31679 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31680 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31681 if ((unsigned long)buf & alignment
31682 || blk_rq_bytes(rq) & q->dma_pad_mask
31683 - || object_is_on_stack(buf))
31684 + || object_starts_on_stack(buf))
31685 drive->dma = 0;
31686 }
31687 }
31688 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31689 index 7f56b73..dab5b67 100644
31690 --- a/drivers/ide/ide-pci-generic.c
31691 +++ b/drivers/ide/ide-pci-generic.c
31692 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31693 .udma_mask = ATA_UDMA6, \
31694 }
31695
31696 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
31697 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
31698 /* 0: Unknown */
31699 DECLARE_GENERIC_PCI_DEV(0),
31700
31701 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31702 index 560e66d..d5dd180 100644
31703 --- a/drivers/ide/it8172.c
31704 +++ b/drivers/ide/it8172.c
31705 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31706 .set_dma_mode = it8172_set_dma_mode,
31707 };
31708
31709 -static const struct ide_port_info it8172_port_info __devinitdata = {
31710 +static const struct ide_port_info it8172_port_info __devinitconst = {
31711 .name = DRV_NAME,
31712 .port_ops = &it8172_port_ops,
31713 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31714 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31715 index 46816ba..1847aeb 100644
31716 --- a/drivers/ide/it8213.c
31717 +++ b/drivers/ide/it8213.c
31718 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31719 .cable_detect = it8213_cable_detect,
31720 };
31721
31722 -static const struct ide_port_info it8213_chipset __devinitdata = {
31723 +static const struct ide_port_info it8213_chipset __devinitconst = {
31724 .name = DRV_NAME,
31725 .enablebits = { {0x41, 0x80, 0x80} },
31726 .port_ops = &it8213_port_ops,
31727 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31728 index 2e3169f..c5611db 100644
31729 --- a/drivers/ide/it821x.c
31730 +++ b/drivers/ide/it821x.c
31731 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31732 .cable_detect = it821x_cable_detect,
31733 };
31734
31735 -static const struct ide_port_info it821x_chipset __devinitdata = {
31736 +static const struct ide_port_info it821x_chipset __devinitconst = {
31737 .name = DRV_NAME,
31738 .init_chipset = init_chipset_it821x,
31739 .init_hwif = init_hwif_it821x,
31740 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31741 index 74c2c4a..efddd7d 100644
31742 --- a/drivers/ide/jmicron.c
31743 +++ b/drivers/ide/jmicron.c
31744 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31745 .cable_detect = jmicron_cable_detect,
31746 };
31747
31748 -static const struct ide_port_info jmicron_chipset __devinitdata = {
31749 +static const struct ide_port_info jmicron_chipset __devinitconst = {
31750 .name = DRV_NAME,
31751 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31752 .port_ops = &jmicron_port_ops,
31753 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31754 index 95327a2..73f78d8 100644
31755 --- a/drivers/ide/ns87415.c
31756 +++ b/drivers/ide/ns87415.c
31757 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31758 .dma_sff_read_status = superio_dma_sff_read_status,
31759 };
31760
31761 -static const struct ide_port_info ns87415_chipset __devinitdata = {
31762 +static const struct ide_port_info ns87415_chipset __devinitconst = {
31763 .name = DRV_NAME,
31764 .init_hwif = init_hwif_ns87415,
31765 .tp_ops = &ns87415_tp_ops,
31766 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31767 index 1a53a4c..39edc66 100644
31768 --- a/drivers/ide/opti621.c
31769 +++ b/drivers/ide/opti621.c
31770 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31771 .set_pio_mode = opti621_set_pio_mode,
31772 };
31773
31774 -static const struct ide_port_info opti621_chipset __devinitdata = {
31775 +static const struct ide_port_info opti621_chipset __devinitconst = {
31776 .name = DRV_NAME,
31777 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31778 .port_ops = &opti621_port_ops,
31779 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31780 index 9546fe2..2e5ceb6 100644
31781 --- a/drivers/ide/pdc202xx_new.c
31782 +++ b/drivers/ide/pdc202xx_new.c
31783 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31784 .udma_mask = udma, \
31785 }
31786
31787 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
31788 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
31789 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
31790 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
31791 };
31792 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
31793 index 3a35ec6..5634510 100644
31794 --- a/drivers/ide/pdc202xx_old.c
31795 +++ b/drivers/ide/pdc202xx_old.c
31796 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
31797 .max_sectors = sectors, \
31798 }
31799
31800 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
31801 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
31802 { /* 0: PDC20246 */
31803 .name = DRV_NAME,
31804 .init_chipset = init_chipset_pdc202xx,
31805 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
31806 index 1892e81..fe0fd60 100644
31807 --- a/drivers/ide/piix.c
31808 +++ b/drivers/ide/piix.c
31809 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
31810 .udma_mask = udma, \
31811 }
31812
31813 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
31814 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
31815 /* 0: MPIIX */
31816 { /*
31817 * MPIIX actually has only a single IDE channel mapped to
31818 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
31819 index a6414a8..c04173e 100644
31820 --- a/drivers/ide/rz1000.c
31821 +++ b/drivers/ide/rz1000.c
31822 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
31823 }
31824 }
31825
31826 -static const struct ide_port_info rz1000_chipset __devinitdata = {
31827 +static const struct ide_port_info rz1000_chipset __devinitconst = {
31828 .name = DRV_NAME,
31829 .host_flags = IDE_HFLAG_NO_DMA,
31830 };
31831 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
31832 index 356b9b5..d4758eb 100644
31833 --- a/drivers/ide/sc1200.c
31834 +++ b/drivers/ide/sc1200.c
31835 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
31836 .dma_sff_read_status = ide_dma_sff_read_status,
31837 };
31838
31839 -static const struct ide_port_info sc1200_chipset __devinitdata = {
31840 +static const struct ide_port_info sc1200_chipset __devinitconst = {
31841 .name = DRV_NAME,
31842 .port_ops = &sc1200_port_ops,
31843 .dma_ops = &sc1200_dma_ops,
31844 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
31845 index b7f5b0c..9701038 100644
31846 --- a/drivers/ide/scc_pata.c
31847 +++ b/drivers/ide/scc_pata.c
31848 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
31849 .dma_sff_read_status = scc_dma_sff_read_status,
31850 };
31851
31852 -static const struct ide_port_info scc_chipset __devinitdata = {
31853 +static const struct ide_port_info scc_chipset __devinitconst = {
31854 .name = "sccIDE",
31855 .init_iops = init_iops_scc,
31856 .init_dma = scc_init_dma,
31857 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
31858 index 35fb8da..24d72ef 100644
31859 --- a/drivers/ide/serverworks.c
31860 +++ b/drivers/ide/serverworks.c
31861 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
31862 .cable_detect = svwks_cable_detect,
31863 };
31864
31865 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
31866 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
31867 { /* 0: OSB4 */
31868 .name = DRV_NAME,
31869 .init_chipset = init_chipset_svwks,
31870 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
31871 index ddeda44..46f7e30 100644
31872 --- a/drivers/ide/siimage.c
31873 +++ b/drivers/ide/siimage.c
31874 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
31875 .udma_mask = ATA_UDMA6, \
31876 }
31877
31878 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
31879 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
31880 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
31881 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
31882 };
31883 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
31884 index 4a00225..09e61b4 100644
31885 --- a/drivers/ide/sis5513.c
31886 +++ b/drivers/ide/sis5513.c
31887 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
31888 .cable_detect = sis_cable_detect,
31889 };
31890
31891 -static const struct ide_port_info sis5513_chipset __devinitdata = {
31892 +static const struct ide_port_info sis5513_chipset __devinitconst = {
31893 .name = DRV_NAME,
31894 .init_chipset = init_chipset_sis5513,
31895 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
31896 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
31897 index f21dc2a..d051cd2 100644
31898 --- a/drivers/ide/sl82c105.c
31899 +++ b/drivers/ide/sl82c105.c
31900 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
31901 .dma_sff_read_status = ide_dma_sff_read_status,
31902 };
31903
31904 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
31905 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
31906 .name = DRV_NAME,
31907 .init_chipset = init_chipset_sl82c105,
31908 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
31909 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
31910 index 864ffe0..863a5e9 100644
31911 --- a/drivers/ide/slc90e66.c
31912 +++ b/drivers/ide/slc90e66.c
31913 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
31914 .cable_detect = slc90e66_cable_detect,
31915 };
31916
31917 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
31918 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
31919 .name = DRV_NAME,
31920 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
31921 .port_ops = &slc90e66_port_ops,
31922 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
31923 index 4799d5c..1794678 100644
31924 --- a/drivers/ide/tc86c001.c
31925 +++ b/drivers/ide/tc86c001.c
31926 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
31927 .dma_sff_read_status = ide_dma_sff_read_status,
31928 };
31929
31930 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
31931 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
31932 .name = DRV_NAME,
31933 .init_hwif = init_hwif_tc86c001,
31934 .port_ops = &tc86c001_port_ops,
31935 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
31936 index 281c914..55ce1b8 100644
31937 --- a/drivers/ide/triflex.c
31938 +++ b/drivers/ide/triflex.c
31939 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
31940 .set_dma_mode = triflex_set_mode,
31941 };
31942
31943 -static const struct ide_port_info triflex_device __devinitdata = {
31944 +static const struct ide_port_info triflex_device __devinitconst = {
31945 .name = DRV_NAME,
31946 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
31947 .port_ops = &triflex_port_ops,
31948 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
31949 index 4b42ca0..e494a98 100644
31950 --- a/drivers/ide/trm290.c
31951 +++ b/drivers/ide/trm290.c
31952 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
31953 .dma_check = trm290_dma_check,
31954 };
31955
31956 -static const struct ide_port_info trm290_chipset __devinitdata = {
31957 +static const struct ide_port_info trm290_chipset __devinitconst = {
31958 .name = DRV_NAME,
31959 .init_hwif = init_hwif_trm290,
31960 .tp_ops = &trm290_tp_ops,
31961 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
31962 index f46f49c..eb77678 100644
31963 --- a/drivers/ide/via82cxxx.c
31964 +++ b/drivers/ide/via82cxxx.c
31965 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
31966 .cable_detect = via82cxxx_cable_detect,
31967 };
31968
31969 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
31970 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
31971 .name = DRV_NAME,
31972 .init_chipset = init_chipset_via82cxxx,
31973 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
31974 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
31975 index 73d4531..c90cd2d 100644
31976 --- a/drivers/ieee802154/fakehard.c
31977 +++ b/drivers/ieee802154/fakehard.c
31978 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
31979 phy->transmit_power = 0xbf;
31980
31981 dev->netdev_ops = &fake_ops;
31982 - dev->ml_priv = &fake_mlme;
31983 + dev->ml_priv = (void *)&fake_mlme;
31984
31985 priv = netdev_priv(dev);
31986 priv->phy = phy;
31987 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
31988 index c889aae..6cf5aa7 100644
31989 --- a/drivers/infiniband/core/cm.c
31990 +++ b/drivers/infiniband/core/cm.c
31991 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
31992
31993 struct cm_counter_group {
31994 struct kobject obj;
31995 - atomic_long_t counter[CM_ATTR_COUNT];
31996 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
31997 };
31998
31999 struct cm_counter_attribute {
32000 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
32001 struct ib_mad_send_buf *msg = NULL;
32002 int ret;
32003
32004 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32005 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32006 counter[CM_REQ_COUNTER]);
32007
32008 /* Quick state check to discard duplicate REQs. */
32009 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
32010 if (!cm_id_priv)
32011 return;
32012
32013 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32014 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32015 counter[CM_REP_COUNTER]);
32016 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32017 if (ret)
32018 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32019 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32020 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32021 spin_unlock_irq(&cm_id_priv->lock);
32022 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32023 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32024 counter[CM_RTU_COUNTER]);
32025 goto out;
32026 }
32027 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32028 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32029 dreq_msg->local_comm_id);
32030 if (!cm_id_priv) {
32031 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32032 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32033 counter[CM_DREQ_COUNTER]);
32034 cm_issue_drep(work->port, work->mad_recv_wc);
32035 return -EINVAL;
32036 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32037 case IB_CM_MRA_REP_RCVD:
32038 break;
32039 case IB_CM_TIMEWAIT:
32040 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32041 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32042 counter[CM_DREQ_COUNTER]);
32043 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32044 goto unlock;
32045 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32046 cm_free_msg(msg);
32047 goto deref;
32048 case IB_CM_DREQ_RCVD:
32049 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32050 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32051 counter[CM_DREQ_COUNTER]);
32052 goto unlock;
32053 default:
32054 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32055 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32056 cm_id_priv->msg, timeout)) {
32057 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32058 - atomic_long_inc(&work->port->
32059 + atomic_long_inc_unchecked(&work->port->
32060 counter_group[CM_RECV_DUPLICATES].
32061 counter[CM_MRA_COUNTER]);
32062 goto out;
32063 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32064 break;
32065 case IB_CM_MRA_REQ_RCVD:
32066 case IB_CM_MRA_REP_RCVD:
32067 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32068 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32069 counter[CM_MRA_COUNTER]);
32070 /* fall through */
32071 default:
32072 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32073 case IB_CM_LAP_IDLE:
32074 break;
32075 case IB_CM_MRA_LAP_SENT:
32076 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32077 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32078 counter[CM_LAP_COUNTER]);
32079 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32080 goto unlock;
32081 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32082 cm_free_msg(msg);
32083 goto deref;
32084 case IB_CM_LAP_RCVD:
32085 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32086 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32087 counter[CM_LAP_COUNTER]);
32088 goto unlock;
32089 default:
32090 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32091 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32092 if (cur_cm_id_priv) {
32093 spin_unlock_irq(&cm.lock);
32094 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32095 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32096 counter[CM_SIDR_REQ_COUNTER]);
32097 goto out; /* Duplicate message. */
32098 }
32099 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32100 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32101 msg->retries = 1;
32102
32103 - atomic_long_add(1 + msg->retries,
32104 + atomic_long_add_unchecked(1 + msg->retries,
32105 &port->counter_group[CM_XMIT].counter[attr_index]);
32106 if (msg->retries)
32107 - atomic_long_add(msg->retries,
32108 + atomic_long_add_unchecked(msg->retries,
32109 &port->counter_group[CM_XMIT_RETRIES].
32110 counter[attr_index]);
32111
32112 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32113 }
32114
32115 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32116 - atomic_long_inc(&port->counter_group[CM_RECV].
32117 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32118 counter[attr_id - CM_ATTR_ID_OFFSET]);
32119
32120 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32121 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32122 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32123
32124 return sprintf(buf, "%ld\n",
32125 - atomic_long_read(&group->counter[cm_attr->index]));
32126 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32127 }
32128
32129 static const struct sysfs_ops cm_counter_ops = {
32130 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32131 index 176c8f9..2627b62 100644
32132 --- a/drivers/infiniband/core/fmr_pool.c
32133 +++ b/drivers/infiniband/core/fmr_pool.c
32134 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
32135
32136 struct task_struct *thread;
32137
32138 - atomic_t req_ser;
32139 - atomic_t flush_ser;
32140 + atomic_unchecked_t req_ser;
32141 + atomic_unchecked_t flush_ser;
32142
32143 wait_queue_head_t force_wait;
32144 };
32145 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32146 struct ib_fmr_pool *pool = pool_ptr;
32147
32148 do {
32149 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32150 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32151 ib_fmr_batch_release(pool);
32152
32153 - atomic_inc(&pool->flush_ser);
32154 + atomic_inc_unchecked(&pool->flush_ser);
32155 wake_up_interruptible(&pool->force_wait);
32156
32157 if (pool->flush_function)
32158 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32159 }
32160
32161 set_current_state(TASK_INTERRUPTIBLE);
32162 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32163 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32164 !kthread_should_stop())
32165 schedule();
32166 __set_current_state(TASK_RUNNING);
32167 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32168 pool->dirty_watermark = params->dirty_watermark;
32169 pool->dirty_len = 0;
32170 spin_lock_init(&pool->pool_lock);
32171 - atomic_set(&pool->req_ser, 0);
32172 - atomic_set(&pool->flush_ser, 0);
32173 + atomic_set_unchecked(&pool->req_ser, 0);
32174 + atomic_set_unchecked(&pool->flush_ser, 0);
32175 init_waitqueue_head(&pool->force_wait);
32176
32177 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32178 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32179 }
32180 spin_unlock_irq(&pool->pool_lock);
32181
32182 - serial = atomic_inc_return(&pool->req_ser);
32183 + serial = atomic_inc_return_unchecked(&pool->req_ser);
32184 wake_up_process(pool->thread);
32185
32186 if (wait_event_interruptible(pool->force_wait,
32187 - atomic_read(&pool->flush_ser) - serial >= 0))
32188 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32189 return -EINTR;
32190
32191 return 0;
32192 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32193 } else {
32194 list_add_tail(&fmr->list, &pool->dirty_list);
32195 if (++pool->dirty_len >= pool->dirty_watermark) {
32196 - atomic_inc(&pool->req_ser);
32197 + atomic_inc_unchecked(&pool->req_ser);
32198 wake_up_process(pool->thread);
32199 }
32200 }
32201 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32202 index 40c8353..946b0e4 100644
32203 --- a/drivers/infiniband/hw/cxgb4/mem.c
32204 +++ b/drivers/infiniband/hw/cxgb4/mem.c
32205 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32206 int err;
32207 struct fw_ri_tpte tpt;
32208 u32 stag_idx;
32209 - static atomic_t key;
32210 + static atomic_unchecked_t key;
32211
32212 if (c4iw_fatal_error(rdev))
32213 return -EIO;
32214 @@ -135,7 +135,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32215 &rdev->resource.tpt_fifo_lock);
32216 if (!stag_idx)
32217 return -ENOMEM;
32218 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32219 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32220 }
32221 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32222 __func__, stag_state, type, pdid, stag_idx);
32223 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32224 index 79b3dbc..96e5fcc 100644
32225 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
32226 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32227 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32228 struct ib_atomic_eth *ateth;
32229 struct ipath_ack_entry *e;
32230 u64 vaddr;
32231 - atomic64_t *maddr;
32232 + atomic64_unchecked_t *maddr;
32233 u64 sdata;
32234 u32 rkey;
32235 u8 next;
32236 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32237 IB_ACCESS_REMOTE_ATOMIC)))
32238 goto nack_acc_unlck;
32239 /* Perform atomic OP and save result. */
32240 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32241 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32242 sdata = be64_to_cpu(ateth->swap_data);
32243 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32244 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32245 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32246 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32247 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32248 be64_to_cpu(ateth->compare_data),
32249 sdata);
32250 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32251 index 1f95bba..9530f87 100644
32252 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32253 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32254 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32255 unsigned long flags;
32256 struct ib_wc wc;
32257 u64 sdata;
32258 - atomic64_t *maddr;
32259 + atomic64_unchecked_t *maddr;
32260 enum ib_wc_status send_status;
32261
32262 /*
32263 @@ -382,11 +382,11 @@ again:
32264 IB_ACCESS_REMOTE_ATOMIC)))
32265 goto acc_err;
32266 /* Perform atomic OP and save result. */
32267 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32268 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32269 sdata = wqe->wr.wr.atomic.compare_add;
32270 *(u64 *) sqp->s_sge.sge.vaddr =
32271 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32272 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32273 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32274 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32275 sdata, wqe->wr.wr.atomic.swap);
32276 goto send_comp;
32277 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32278 index 7140199..da60063 100644
32279 --- a/drivers/infiniband/hw/nes/nes.c
32280 +++ b/drivers/infiniband/hw/nes/nes.c
32281 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32282 LIST_HEAD(nes_adapter_list);
32283 static LIST_HEAD(nes_dev_list);
32284
32285 -atomic_t qps_destroyed;
32286 +atomic_unchecked_t qps_destroyed;
32287
32288 static unsigned int ee_flsh_adapter;
32289 static unsigned int sysfs_nonidx_addr;
32290 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32291 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32292 struct nes_adapter *nesadapter = nesdev->nesadapter;
32293
32294 - atomic_inc(&qps_destroyed);
32295 + atomic_inc_unchecked(&qps_destroyed);
32296
32297 /* Free the control structures */
32298
32299 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32300 index c438e46..ca30356 100644
32301 --- a/drivers/infiniband/hw/nes/nes.h
32302 +++ b/drivers/infiniband/hw/nes/nes.h
32303 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32304 extern unsigned int wqm_quanta;
32305 extern struct list_head nes_adapter_list;
32306
32307 -extern atomic_t cm_connects;
32308 -extern atomic_t cm_accepts;
32309 -extern atomic_t cm_disconnects;
32310 -extern atomic_t cm_closes;
32311 -extern atomic_t cm_connecteds;
32312 -extern atomic_t cm_connect_reqs;
32313 -extern atomic_t cm_rejects;
32314 -extern atomic_t mod_qp_timouts;
32315 -extern atomic_t qps_created;
32316 -extern atomic_t qps_destroyed;
32317 -extern atomic_t sw_qps_destroyed;
32318 +extern atomic_unchecked_t cm_connects;
32319 +extern atomic_unchecked_t cm_accepts;
32320 +extern atomic_unchecked_t cm_disconnects;
32321 +extern atomic_unchecked_t cm_closes;
32322 +extern atomic_unchecked_t cm_connecteds;
32323 +extern atomic_unchecked_t cm_connect_reqs;
32324 +extern atomic_unchecked_t cm_rejects;
32325 +extern atomic_unchecked_t mod_qp_timouts;
32326 +extern atomic_unchecked_t qps_created;
32327 +extern atomic_unchecked_t qps_destroyed;
32328 +extern atomic_unchecked_t sw_qps_destroyed;
32329 extern u32 mh_detected;
32330 extern u32 mh_pauses_sent;
32331 extern u32 cm_packets_sent;
32332 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32333 extern u32 cm_packets_received;
32334 extern u32 cm_packets_dropped;
32335 extern u32 cm_packets_retrans;
32336 -extern atomic_t cm_listens_created;
32337 -extern atomic_t cm_listens_destroyed;
32338 +extern atomic_unchecked_t cm_listens_created;
32339 +extern atomic_unchecked_t cm_listens_destroyed;
32340 extern u32 cm_backlog_drops;
32341 -extern atomic_t cm_loopbacks;
32342 -extern atomic_t cm_nodes_created;
32343 -extern atomic_t cm_nodes_destroyed;
32344 -extern atomic_t cm_accel_dropped_pkts;
32345 -extern atomic_t cm_resets_recvd;
32346 -extern atomic_t pau_qps_created;
32347 -extern atomic_t pau_qps_destroyed;
32348 +extern atomic_unchecked_t cm_loopbacks;
32349 +extern atomic_unchecked_t cm_nodes_created;
32350 +extern atomic_unchecked_t cm_nodes_destroyed;
32351 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32352 +extern atomic_unchecked_t cm_resets_recvd;
32353 +extern atomic_unchecked_t pau_qps_created;
32354 +extern atomic_unchecked_t pau_qps_destroyed;
32355
32356 extern u32 int_mod_timer_init;
32357 extern u32 int_mod_cq_depth_256;
32358 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32359 index 71edfbb..15b62ae 100644
32360 --- a/drivers/infiniband/hw/nes/nes_cm.c
32361 +++ b/drivers/infiniband/hw/nes/nes_cm.c
32362 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32363 u32 cm_packets_retrans;
32364 u32 cm_packets_created;
32365 u32 cm_packets_received;
32366 -atomic_t cm_listens_created;
32367 -atomic_t cm_listens_destroyed;
32368 +atomic_unchecked_t cm_listens_created;
32369 +atomic_unchecked_t cm_listens_destroyed;
32370 u32 cm_backlog_drops;
32371 -atomic_t cm_loopbacks;
32372 -atomic_t cm_nodes_created;
32373 -atomic_t cm_nodes_destroyed;
32374 -atomic_t cm_accel_dropped_pkts;
32375 -atomic_t cm_resets_recvd;
32376 +atomic_unchecked_t cm_loopbacks;
32377 +atomic_unchecked_t cm_nodes_created;
32378 +atomic_unchecked_t cm_nodes_destroyed;
32379 +atomic_unchecked_t cm_accel_dropped_pkts;
32380 +atomic_unchecked_t cm_resets_recvd;
32381
32382 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32383 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32384 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32385
32386 static struct nes_cm_core *g_cm_core;
32387
32388 -atomic_t cm_connects;
32389 -atomic_t cm_accepts;
32390 -atomic_t cm_disconnects;
32391 -atomic_t cm_closes;
32392 -atomic_t cm_connecteds;
32393 -atomic_t cm_connect_reqs;
32394 -atomic_t cm_rejects;
32395 +atomic_unchecked_t cm_connects;
32396 +atomic_unchecked_t cm_accepts;
32397 +atomic_unchecked_t cm_disconnects;
32398 +atomic_unchecked_t cm_closes;
32399 +atomic_unchecked_t cm_connecteds;
32400 +atomic_unchecked_t cm_connect_reqs;
32401 +atomic_unchecked_t cm_rejects;
32402
32403 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32404 {
32405 @@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32406 kfree(listener);
32407 listener = NULL;
32408 ret = 0;
32409 - atomic_inc(&cm_listens_destroyed);
32410 + atomic_inc_unchecked(&cm_listens_destroyed);
32411 } else {
32412 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32413 }
32414 @@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32415 cm_node->rem_mac);
32416
32417 add_hte_node(cm_core, cm_node);
32418 - atomic_inc(&cm_nodes_created);
32419 + atomic_inc_unchecked(&cm_nodes_created);
32420
32421 return cm_node;
32422 }
32423 @@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32424 }
32425
32426 atomic_dec(&cm_core->node_cnt);
32427 - atomic_inc(&cm_nodes_destroyed);
32428 + atomic_inc_unchecked(&cm_nodes_destroyed);
32429 nesqp = cm_node->nesqp;
32430 if (nesqp) {
32431 nesqp->cm_node = NULL;
32432 @@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32433
32434 static void drop_packet(struct sk_buff *skb)
32435 {
32436 - atomic_inc(&cm_accel_dropped_pkts);
32437 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32438 dev_kfree_skb_any(skb);
32439 }
32440
32441 @@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32442 {
32443
32444 int reset = 0; /* whether to send reset in case of err.. */
32445 - atomic_inc(&cm_resets_recvd);
32446 + atomic_inc_unchecked(&cm_resets_recvd);
32447 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32448 " refcnt=%d\n", cm_node, cm_node->state,
32449 atomic_read(&cm_node->ref_count));
32450 @@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32451 rem_ref_cm_node(cm_node->cm_core, cm_node);
32452 return NULL;
32453 }
32454 - atomic_inc(&cm_loopbacks);
32455 + atomic_inc_unchecked(&cm_loopbacks);
32456 loopbackremotenode->loopbackpartner = cm_node;
32457 loopbackremotenode->tcp_cntxt.rcv_wscale =
32458 NES_CM_DEFAULT_RCV_WND_SCALE;
32459 @@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32460 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32461 else {
32462 rem_ref_cm_node(cm_core, cm_node);
32463 - atomic_inc(&cm_accel_dropped_pkts);
32464 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32465 dev_kfree_skb_any(skb);
32466 }
32467 break;
32468 @@ -2890,7 +2890,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32469
32470 if ((cm_id) && (cm_id->event_handler)) {
32471 if (issue_disconn) {
32472 - atomic_inc(&cm_disconnects);
32473 + atomic_inc_unchecked(&cm_disconnects);
32474 cm_event.event = IW_CM_EVENT_DISCONNECT;
32475 cm_event.status = disconn_status;
32476 cm_event.local_addr = cm_id->local_addr;
32477 @@ -2912,7 +2912,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32478 }
32479
32480 if (issue_close) {
32481 - atomic_inc(&cm_closes);
32482 + atomic_inc_unchecked(&cm_closes);
32483 nes_disconnect(nesqp, 1);
32484
32485 cm_id->provider_data = nesqp;
32486 @@ -3048,7 +3048,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32487
32488 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32489 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32490 - atomic_inc(&cm_accepts);
32491 + atomic_inc_unchecked(&cm_accepts);
32492
32493 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32494 netdev_refcnt_read(nesvnic->netdev));
32495 @@ -3250,7 +3250,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32496 struct nes_cm_core *cm_core;
32497 u8 *start_buff;
32498
32499 - atomic_inc(&cm_rejects);
32500 + atomic_inc_unchecked(&cm_rejects);
32501 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32502 loopback = cm_node->loopbackpartner;
32503 cm_core = cm_node->cm_core;
32504 @@ -3310,7 +3310,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32505 ntohl(cm_id->local_addr.sin_addr.s_addr),
32506 ntohs(cm_id->local_addr.sin_port));
32507
32508 - atomic_inc(&cm_connects);
32509 + atomic_inc_unchecked(&cm_connects);
32510 nesqp->active_conn = 1;
32511
32512 /* cache the cm_id in the qp */
32513 @@ -3416,7 +3416,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32514 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32515 return err;
32516 }
32517 - atomic_inc(&cm_listens_created);
32518 + atomic_inc_unchecked(&cm_listens_created);
32519 }
32520
32521 cm_id->add_ref(cm_id);
32522 @@ -3517,7 +3517,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32523
32524 if (nesqp->destroyed)
32525 return;
32526 - atomic_inc(&cm_connecteds);
32527 + atomic_inc_unchecked(&cm_connecteds);
32528 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32529 " local port 0x%04X. jiffies = %lu.\n",
32530 nesqp->hwqp.qp_id,
32531 @@ -3704,7 +3704,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32532
32533 cm_id->add_ref(cm_id);
32534 ret = cm_id->event_handler(cm_id, &cm_event);
32535 - atomic_inc(&cm_closes);
32536 + atomic_inc_unchecked(&cm_closes);
32537 cm_event.event = IW_CM_EVENT_CLOSE;
32538 cm_event.status = 0;
32539 cm_event.provider_data = cm_id->provider_data;
32540 @@ -3740,7 +3740,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32541 return;
32542 cm_id = cm_node->cm_id;
32543
32544 - atomic_inc(&cm_connect_reqs);
32545 + atomic_inc_unchecked(&cm_connect_reqs);
32546 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32547 cm_node, cm_id, jiffies);
32548
32549 @@ -3780,7 +3780,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32550 return;
32551 cm_id = cm_node->cm_id;
32552
32553 - atomic_inc(&cm_connect_reqs);
32554 + atomic_inc_unchecked(&cm_connect_reqs);
32555 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32556 cm_node, cm_id, jiffies);
32557
32558 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32559 index 3ba7be3..c81f6ff 100644
32560 --- a/drivers/infiniband/hw/nes/nes_mgt.c
32561 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
32562 @@ -40,8 +40,8 @@
32563 #include "nes.h"
32564 #include "nes_mgt.h"
32565
32566 -atomic_t pau_qps_created;
32567 -atomic_t pau_qps_destroyed;
32568 +atomic_unchecked_t pau_qps_created;
32569 +atomic_unchecked_t pau_qps_destroyed;
32570
32571 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32572 {
32573 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32574 {
32575 struct sk_buff *skb;
32576 unsigned long flags;
32577 - atomic_inc(&pau_qps_destroyed);
32578 + atomic_inc_unchecked(&pau_qps_destroyed);
32579
32580 /* Free packets that have not yet been forwarded */
32581 /* Lock is acquired by skb_dequeue when removing the skb */
32582 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32583 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32584 skb_queue_head_init(&nesqp->pau_list);
32585 spin_lock_init(&nesqp->pau_lock);
32586 - atomic_inc(&pau_qps_created);
32587 + atomic_inc_unchecked(&pau_qps_created);
32588 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32589 }
32590
32591 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32592 index f3a3ecf..57d311d 100644
32593 --- a/drivers/infiniband/hw/nes/nes_nic.c
32594 +++ b/drivers/infiniband/hw/nes/nes_nic.c
32595 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32596 target_stat_values[++index] = mh_detected;
32597 target_stat_values[++index] = mh_pauses_sent;
32598 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32599 - target_stat_values[++index] = atomic_read(&cm_connects);
32600 - target_stat_values[++index] = atomic_read(&cm_accepts);
32601 - target_stat_values[++index] = atomic_read(&cm_disconnects);
32602 - target_stat_values[++index] = atomic_read(&cm_connecteds);
32603 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32604 - target_stat_values[++index] = atomic_read(&cm_rejects);
32605 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32606 - target_stat_values[++index] = atomic_read(&qps_created);
32607 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32608 - target_stat_values[++index] = atomic_read(&qps_destroyed);
32609 - target_stat_values[++index] = atomic_read(&cm_closes);
32610 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32611 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32612 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32613 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32614 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32615 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32616 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32617 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32618 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32619 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32620 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32621 target_stat_values[++index] = cm_packets_sent;
32622 target_stat_values[++index] = cm_packets_bounced;
32623 target_stat_values[++index] = cm_packets_created;
32624 target_stat_values[++index] = cm_packets_received;
32625 target_stat_values[++index] = cm_packets_dropped;
32626 target_stat_values[++index] = cm_packets_retrans;
32627 - target_stat_values[++index] = atomic_read(&cm_listens_created);
32628 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32629 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32630 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32631 target_stat_values[++index] = cm_backlog_drops;
32632 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
32633 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
32634 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32635 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32636 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32637 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32638 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32639 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32640 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32641 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32642 target_stat_values[++index] = nesadapter->free_4kpbl;
32643 target_stat_values[++index] = nesadapter->free_256pbl;
32644 target_stat_values[++index] = int_mod_timer_init;
32645 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32646 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32647 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32648 - target_stat_values[++index] = atomic_read(&pau_qps_created);
32649 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32650 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32651 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32652 }
32653
32654 /**
32655 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32656 index 8b8812d..a5e1133 100644
32657 --- a/drivers/infiniband/hw/nes/nes_verbs.c
32658 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
32659 @@ -46,9 +46,9 @@
32660
32661 #include <rdma/ib_umem.h>
32662
32663 -atomic_t mod_qp_timouts;
32664 -atomic_t qps_created;
32665 -atomic_t sw_qps_destroyed;
32666 +atomic_unchecked_t mod_qp_timouts;
32667 +atomic_unchecked_t qps_created;
32668 +atomic_unchecked_t sw_qps_destroyed;
32669
32670 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32671
32672 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32673 if (init_attr->create_flags)
32674 return ERR_PTR(-EINVAL);
32675
32676 - atomic_inc(&qps_created);
32677 + atomic_inc_unchecked(&qps_created);
32678 switch (init_attr->qp_type) {
32679 case IB_QPT_RC:
32680 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32681 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32682 struct iw_cm_event cm_event;
32683 int ret = 0;
32684
32685 - atomic_inc(&sw_qps_destroyed);
32686 + atomic_inc_unchecked(&sw_qps_destroyed);
32687 nesqp->destroyed = 1;
32688
32689 /* Blow away the connection if it exists. */
32690 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32691 index 6b811e3..f8acf88 100644
32692 --- a/drivers/infiniband/hw/qib/qib.h
32693 +++ b/drivers/infiniband/hw/qib/qib.h
32694 @@ -51,6 +51,7 @@
32695 #include <linux/completion.h>
32696 #include <linux/kref.h>
32697 #include <linux/sched.h>
32698 +#include <linux/slab.h>
32699
32700 #include "qib_common.h"
32701 #include "qib_verbs.h"
32702 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32703 index da739d9..da1c7f4 100644
32704 --- a/drivers/input/gameport/gameport.c
32705 +++ b/drivers/input/gameport/gameport.c
32706 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32707 */
32708 static void gameport_init_port(struct gameport *gameport)
32709 {
32710 - static atomic_t gameport_no = ATOMIC_INIT(0);
32711 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32712
32713 __module_get(THIS_MODULE);
32714
32715 mutex_init(&gameport->drv_mutex);
32716 device_initialize(&gameport->dev);
32717 dev_set_name(&gameport->dev, "gameport%lu",
32718 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
32719 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32720 gameport->dev.bus = &gameport_bus;
32721 gameport->dev.release = gameport_release_port;
32722 if (gameport->parent)
32723 diff --git a/drivers/input/input.c b/drivers/input/input.c
32724 index 8921c61..f5cd63d 100644
32725 --- a/drivers/input/input.c
32726 +++ b/drivers/input/input.c
32727 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32728 */
32729 int input_register_device(struct input_dev *dev)
32730 {
32731 - static atomic_t input_no = ATOMIC_INIT(0);
32732 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32733 struct input_handler *handler;
32734 const char *path;
32735 int error;
32736 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32737 dev->setkeycode = input_default_setkeycode;
32738
32739 dev_set_name(&dev->dev, "input%ld",
32740 - (unsigned long) atomic_inc_return(&input_no) - 1);
32741 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32742
32743 error = device_add(&dev->dev);
32744 if (error)
32745 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32746 index b8d8611..7a4a04b 100644
32747 --- a/drivers/input/joystick/sidewinder.c
32748 +++ b/drivers/input/joystick/sidewinder.c
32749 @@ -30,6 +30,7 @@
32750 #include <linux/kernel.h>
32751 #include <linux/module.h>
32752 #include <linux/slab.h>
32753 +#include <linux/sched.h>
32754 #include <linux/init.h>
32755 #include <linux/input.h>
32756 #include <linux/gameport.h>
32757 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32758 index fd7a0d5..a4af10c 100644
32759 --- a/drivers/input/joystick/xpad.c
32760 +++ b/drivers/input/joystick/xpad.c
32761 @@ -710,7 +710,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32762
32763 static int xpad_led_probe(struct usb_xpad *xpad)
32764 {
32765 - static atomic_t led_seq = ATOMIC_INIT(0);
32766 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32767 long led_no;
32768 struct xpad_led *led;
32769 struct led_classdev *led_cdev;
32770 @@ -723,7 +723,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32771 if (!led)
32772 return -ENOMEM;
32773
32774 - led_no = (long)atomic_inc_return(&led_seq) - 1;
32775 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32776
32777 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32778 led->xpad = xpad;
32779 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32780 index 0110b5a..d3ad144 100644
32781 --- a/drivers/input/mousedev.c
32782 +++ b/drivers/input/mousedev.c
32783 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32784
32785 spin_unlock_irq(&client->packet_lock);
32786
32787 - if (copy_to_user(buffer, data, count))
32788 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
32789 return -EFAULT;
32790
32791 return count;
32792 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
32793 index d0f7533..fb8215b 100644
32794 --- a/drivers/input/serio/serio.c
32795 +++ b/drivers/input/serio/serio.c
32796 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
32797 */
32798 static void serio_init_port(struct serio *serio)
32799 {
32800 - static atomic_t serio_no = ATOMIC_INIT(0);
32801 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
32802
32803 __module_get(THIS_MODULE);
32804
32805 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
32806 mutex_init(&serio->drv_mutex);
32807 device_initialize(&serio->dev);
32808 dev_set_name(&serio->dev, "serio%ld",
32809 - (long)atomic_inc_return(&serio_no) - 1);
32810 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
32811 serio->dev.bus = &serio_bus;
32812 serio->dev.release = serio_release_port;
32813 serio->dev.groups = serio_device_attr_groups;
32814 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
32815 index b902794..fc7b85b 100644
32816 --- a/drivers/isdn/capi/capi.c
32817 +++ b/drivers/isdn/capi/capi.c
32818 @@ -83,8 +83,8 @@ struct capiminor {
32819
32820 struct capi20_appl *ap;
32821 u32 ncci;
32822 - atomic_t datahandle;
32823 - atomic_t msgid;
32824 + atomic_unchecked_t datahandle;
32825 + atomic_unchecked_t msgid;
32826
32827 struct tty_port port;
32828 int ttyinstop;
32829 @@ -397,7 +397,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
32830 capimsg_setu16(s, 2, mp->ap->applid);
32831 capimsg_setu8 (s, 4, CAPI_DATA_B3);
32832 capimsg_setu8 (s, 5, CAPI_RESP);
32833 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
32834 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
32835 capimsg_setu32(s, 8, mp->ncci);
32836 capimsg_setu16(s, 12, datahandle);
32837 }
32838 @@ -518,14 +518,14 @@ static void handle_minor_send(struct capiminor *mp)
32839 mp->outbytes -= len;
32840 spin_unlock_bh(&mp->outlock);
32841
32842 - datahandle = atomic_inc_return(&mp->datahandle);
32843 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
32844 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
32845 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32846 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32847 capimsg_setu16(skb->data, 2, mp->ap->applid);
32848 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
32849 capimsg_setu8 (skb->data, 5, CAPI_REQ);
32850 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
32851 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
32852 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
32853 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
32854 capimsg_setu16(skb->data, 16, len); /* Data length */
32855 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
32856 index 821f7ac..28d4030 100644
32857 --- a/drivers/isdn/hardware/avm/b1.c
32858 +++ b/drivers/isdn/hardware/avm/b1.c
32859 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
32860 }
32861 if (left) {
32862 if (t4file->user) {
32863 - if (copy_from_user(buf, dp, left))
32864 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32865 return -EFAULT;
32866 } else {
32867 memcpy(buf, dp, left);
32868 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
32869 }
32870 if (left) {
32871 if (config->user) {
32872 - if (copy_from_user(buf, dp, left))
32873 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32874 return -EFAULT;
32875 } else {
32876 memcpy(buf, dp, left);
32877 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
32878 index dd6b53a..19d9ee6 100644
32879 --- a/drivers/isdn/hardware/eicon/divasync.h
32880 +++ b/drivers/isdn/hardware/eicon/divasync.h
32881 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
32882 } diva_didd_add_adapter_t;
32883 typedef struct _diva_didd_remove_adapter {
32884 IDI_CALL p_request;
32885 -} diva_didd_remove_adapter_t;
32886 +} __no_const diva_didd_remove_adapter_t;
32887 typedef struct _diva_didd_read_adapter_array {
32888 void *buffer;
32889 dword length;
32890 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
32891 index d303e65..28bcb7b 100644
32892 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
32893 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
32894 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
32895 typedef struct _diva_os_idi_adapter_interface {
32896 diva_init_card_proc_t cleanup_adapter_proc;
32897 diva_cmd_card_proc_t cmd_proc;
32898 -} diva_os_idi_adapter_interface_t;
32899 +} __no_const diva_os_idi_adapter_interface_t;
32900
32901 typedef struct _diva_os_xdi_adapter {
32902 struct list_head link;
32903 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
32904 index e74df7c..03a03ba 100644
32905 --- a/drivers/isdn/icn/icn.c
32906 +++ b/drivers/isdn/icn/icn.c
32907 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
32908 if (count > len)
32909 count = len;
32910 if (user) {
32911 - if (copy_from_user(msg, buf, count))
32912 + if (count > sizeof msg || copy_from_user(msg, buf, count))
32913 return -EFAULT;
32914 } else
32915 memcpy(msg, buf, count);
32916 diff --git a/drivers/leds/leds-mc13783.c b/drivers/leds/leds-mc13783.c
32917 index 8bc4915..4cc6a2e 100644
32918 --- a/drivers/leds/leds-mc13783.c
32919 +++ b/drivers/leds/leds-mc13783.c
32920 @@ -280,7 +280,7 @@ static int __devinit mc13783_led_probe(struct platform_device *pdev)
32921 return -EINVAL;
32922 }
32923
32924 - led = kzalloc(sizeof(*led) * pdata->num_leds, GFP_KERNEL);
32925 + led = kcalloc(pdata->num_leds, sizeof(*led), GFP_KERNEL);
32926 if (led == NULL) {
32927 dev_err(&pdev->dev, "failed to alloc memory\n");
32928 return -ENOMEM;
32929 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
32930 index b5fdcb7..5b6c59f 100644
32931 --- a/drivers/lguest/core.c
32932 +++ b/drivers/lguest/core.c
32933 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
32934 * it's worked so far. The end address needs +1 because __get_vm_area
32935 * allocates an extra guard page, so we need space for that.
32936 */
32937 +
32938 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32939 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32940 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
32941 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32942 +#else
32943 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32944 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
32945 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32946 +#endif
32947 +
32948 if (!switcher_vma) {
32949 err = -ENOMEM;
32950 printk("lguest: could not map switcher pages high\n");
32951 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
32952 * Now the Switcher is mapped at the right address, we can't fail!
32953 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
32954 */
32955 - memcpy(switcher_vma->addr, start_switcher_text,
32956 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
32957 end_switcher_text - start_switcher_text);
32958
32959 printk(KERN_INFO "lguest: mapped switcher at %p\n",
32960 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
32961 index 3980903..ce25c5e 100644
32962 --- a/drivers/lguest/x86/core.c
32963 +++ b/drivers/lguest/x86/core.c
32964 @@ -59,7 +59,7 @@ static struct {
32965 /* Offset from where switcher.S was compiled to where we've copied it */
32966 static unsigned long switcher_offset(void)
32967 {
32968 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
32969 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
32970 }
32971
32972 /* This cpu's struct lguest_pages. */
32973 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
32974 * These copies are pretty cheap, so we do them unconditionally: */
32975 /* Save the current Host top-level page directory.
32976 */
32977 +
32978 +#ifdef CONFIG_PAX_PER_CPU_PGD
32979 + pages->state.host_cr3 = read_cr3();
32980 +#else
32981 pages->state.host_cr3 = __pa(current->mm->pgd);
32982 +#endif
32983 +
32984 /*
32985 * Set up the Guest's page tables to see this CPU's pages (and no
32986 * other CPU's pages).
32987 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
32988 * compiled-in switcher code and the high-mapped copy we just made.
32989 */
32990 for (i = 0; i < IDT_ENTRIES; i++)
32991 - default_idt_entries[i] += switcher_offset();
32992 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
32993
32994 /*
32995 * Set up the Switcher's per-cpu areas.
32996 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
32997 * it will be undisturbed when we switch. To change %cs and jump we
32998 * need this structure to feed to Intel's "lcall" instruction.
32999 */
33000 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33001 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33002 lguest_entry.segment = LGUEST_CS;
33003
33004 /*
33005 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33006 index 40634b0..4f5855e 100644
33007 --- a/drivers/lguest/x86/switcher_32.S
33008 +++ b/drivers/lguest/x86/switcher_32.S
33009 @@ -87,6 +87,7 @@
33010 #include <asm/page.h>
33011 #include <asm/segment.h>
33012 #include <asm/lguest.h>
33013 +#include <asm/processor-flags.h>
33014
33015 // We mark the start of the code to copy
33016 // It's placed in .text tho it's never run here
33017 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33018 // Changes type when we load it: damn Intel!
33019 // For after we switch over our page tables
33020 // That entry will be read-only: we'd crash.
33021 +
33022 +#ifdef CONFIG_PAX_KERNEXEC
33023 + mov %cr0, %edx
33024 + xor $X86_CR0_WP, %edx
33025 + mov %edx, %cr0
33026 +#endif
33027 +
33028 movl $(GDT_ENTRY_TSS*8), %edx
33029 ltr %dx
33030
33031 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33032 // Let's clear it again for our return.
33033 // The GDT descriptor of the Host
33034 // Points to the table after two "size" bytes
33035 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33036 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33037 // Clear "used" from type field (byte 5, bit 2)
33038 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33039 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33040 +
33041 +#ifdef CONFIG_PAX_KERNEXEC
33042 + mov %cr0, %eax
33043 + xor $X86_CR0_WP, %eax
33044 + mov %eax, %cr0
33045 +#endif
33046
33047 // Once our page table's switched, the Guest is live!
33048 // The Host fades as we run this final step.
33049 @@ -295,13 +309,12 @@ deliver_to_host:
33050 // I consulted gcc, and it gave
33051 // These instructions, which I gladly credit:
33052 leal (%edx,%ebx,8), %eax
33053 - movzwl (%eax),%edx
33054 - movl 4(%eax), %eax
33055 - xorw %ax, %ax
33056 - orl %eax, %edx
33057 + movl 4(%eax), %edx
33058 + movw (%eax), %dx
33059 // Now the address of the handler's in %edx
33060 // We call it now: its "iret" drops us home.
33061 - jmp *%edx
33062 + ljmp $__KERNEL_CS, $1f
33063 +1: jmp *%edx
33064
33065 // Every interrupt can come to us here
33066 // But we must truly tell each apart.
33067 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33068 index 20e5c2c..9e849a9 100644
33069 --- a/drivers/macintosh/macio_asic.c
33070 +++ b/drivers/macintosh/macio_asic.c
33071 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33072 * MacIO is matched against any Apple ID, it's probe() function
33073 * will then decide wether it applies or not
33074 */
33075 -static const struct pci_device_id __devinitdata pci_ids [] = { {
33076 +static const struct pci_device_id __devinitconst pci_ids [] = { {
33077 .vendor = PCI_VENDOR_ID_APPLE,
33078 .device = PCI_ANY_ID,
33079 .subvendor = PCI_ANY_ID,
33080 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33081 index 17e2b47..bcbeec4 100644
33082 --- a/drivers/md/bitmap.c
33083 +++ b/drivers/md/bitmap.c
33084 @@ -1823,7 +1823,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33085 chunk_kb ? "KB" : "B");
33086 if (bitmap->file) {
33087 seq_printf(seq, ", file: ");
33088 - seq_path(seq, &bitmap->file->f_path, " \t\n");
33089 + seq_path(seq, &bitmap->file->f_path, " \t\n\\");
33090 }
33091
33092 seq_printf(seq, "\n");
33093 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33094 index a1a3e6d..1918bfc 100644
33095 --- a/drivers/md/dm-ioctl.c
33096 +++ b/drivers/md/dm-ioctl.c
33097 @@ -1590,7 +1590,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33098 cmd == DM_LIST_VERSIONS_CMD)
33099 return 0;
33100
33101 - if ((cmd == DM_DEV_CREATE_CMD)) {
33102 + if (cmd == DM_DEV_CREATE_CMD) {
33103 if (!*param->name) {
33104 DMWARN("name not supplied when creating device");
33105 return -EINVAL;
33106 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33107 index d039de8..0cf5b87 100644
33108 --- a/drivers/md/dm-raid1.c
33109 +++ b/drivers/md/dm-raid1.c
33110 @@ -40,7 +40,7 @@ enum dm_raid1_error {
33111
33112 struct mirror {
33113 struct mirror_set *ms;
33114 - atomic_t error_count;
33115 + atomic_unchecked_t error_count;
33116 unsigned long error_type;
33117 struct dm_dev *dev;
33118 sector_t offset;
33119 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33120 struct mirror *m;
33121
33122 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33123 - if (!atomic_read(&m->error_count))
33124 + if (!atomic_read_unchecked(&m->error_count))
33125 return m;
33126
33127 return NULL;
33128 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33129 * simple way to tell if a device has encountered
33130 * errors.
33131 */
33132 - atomic_inc(&m->error_count);
33133 + atomic_inc_unchecked(&m->error_count);
33134
33135 if (test_and_set_bit(error_type, &m->error_type))
33136 return;
33137 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33138 struct mirror *m = get_default_mirror(ms);
33139
33140 do {
33141 - if (likely(!atomic_read(&m->error_count)))
33142 + if (likely(!atomic_read_unchecked(&m->error_count)))
33143 return m;
33144
33145 if (m-- == ms->mirror)
33146 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33147 {
33148 struct mirror *default_mirror = get_default_mirror(m->ms);
33149
33150 - return !atomic_read(&default_mirror->error_count);
33151 + return !atomic_read_unchecked(&default_mirror->error_count);
33152 }
33153
33154 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33155 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33156 */
33157 if (likely(region_in_sync(ms, region, 1)))
33158 m = choose_mirror(ms, bio->bi_sector);
33159 - else if (m && atomic_read(&m->error_count))
33160 + else if (m && atomic_read_unchecked(&m->error_count))
33161 m = NULL;
33162
33163 if (likely(m))
33164 @@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33165 }
33166
33167 ms->mirror[mirror].ms = ms;
33168 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33169 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33170 ms->mirror[mirror].error_type = 0;
33171 ms->mirror[mirror].offset = offset;
33172
33173 @@ -1351,7 +1351,7 @@ static void mirror_resume(struct dm_target *ti)
33174 */
33175 static char device_status_char(struct mirror *m)
33176 {
33177 - if (!atomic_read(&(m->error_count)))
33178 + if (!atomic_read_unchecked(&(m->error_count)))
33179 return 'A';
33180
33181 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33182 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33183 index 35c94ff..20d4c17 100644
33184 --- a/drivers/md/dm-stripe.c
33185 +++ b/drivers/md/dm-stripe.c
33186 @@ -20,7 +20,7 @@ struct stripe {
33187 struct dm_dev *dev;
33188 sector_t physical_start;
33189
33190 - atomic_t error_count;
33191 + atomic_unchecked_t error_count;
33192 };
33193
33194 struct stripe_c {
33195 @@ -193,7 +193,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33196 kfree(sc);
33197 return r;
33198 }
33199 - atomic_set(&(sc->stripe[i].error_count), 0);
33200 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33201 }
33202
33203 ti->private = sc;
33204 @@ -315,7 +315,7 @@ static int stripe_status(struct dm_target *ti,
33205 DMEMIT("%d ", sc->stripes);
33206 for (i = 0; i < sc->stripes; i++) {
33207 DMEMIT("%s ", sc->stripe[i].dev->name);
33208 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33209 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33210 'D' : 'A';
33211 }
33212 buffer[i] = '\0';
33213 @@ -362,8 +362,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33214 */
33215 for (i = 0; i < sc->stripes; i++)
33216 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33217 - atomic_inc(&(sc->stripe[i].error_count));
33218 - if (atomic_read(&(sc->stripe[i].error_count)) <
33219 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
33220 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33221 DM_IO_ERROR_THRESHOLD)
33222 schedule_work(&sc->trigger_event);
33223 }
33224 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33225 index 2e227fb..44ead1f 100644
33226 --- a/drivers/md/dm-table.c
33227 +++ b/drivers/md/dm-table.c
33228 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33229 if (!dev_size)
33230 return 0;
33231
33232 - if ((start >= dev_size) || (start + len > dev_size)) {
33233 + if ((start >= dev_size) || (len > dev_size - start)) {
33234 DMWARN("%s: %s too small for target: "
33235 "start=%llu, len=%llu, dev_size=%llu",
33236 dm_device_name(ti->table->md), bdevname(bdev, b),
33237 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33238 index 737d388..811ad5a 100644
33239 --- a/drivers/md/dm-thin-metadata.c
33240 +++ b/drivers/md/dm-thin-metadata.c
33241 @@ -432,7 +432,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33242
33243 pmd->info.tm = tm;
33244 pmd->info.levels = 2;
33245 - pmd->info.value_type.context = pmd->data_sm;
33246 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33247 pmd->info.value_type.size = sizeof(__le64);
33248 pmd->info.value_type.inc = data_block_inc;
33249 pmd->info.value_type.dec = data_block_dec;
33250 @@ -451,7 +451,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33251
33252 pmd->bl_info.tm = tm;
33253 pmd->bl_info.levels = 1;
33254 - pmd->bl_info.value_type.context = pmd->data_sm;
33255 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33256 pmd->bl_info.value_type.size = sizeof(__le64);
33257 pmd->bl_info.value_type.inc = data_block_inc;
33258 pmd->bl_info.value_type.dec = data_block_dec;
33259 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33260 index e24143c..ce2f21a1 100644
33261 --- a/drivers/md/dm.c
33262 +++ b/drivers/md/dm.c
33263 @@ -176,9 +176,9 @@ struct mapped_device {
33264 /*
33265 * Event handling.
33266 */
33267 - atomic_t event_nr;
33268 + atomic_unchecked_t event_nr;
33269 wait_queue_head_t eventq;
33270 - atomic_t uevent_seq;
33271 + atomic_unchecked_t uevent_seq;
33272 struct list_head uevent_list;
33273 spinlock_t uevent_lock; /* Protect access to uevent_list */
33274
33275 @@ -1845,8 +1845,8 @@ static struct mapped_device *alloc_dev(int minor)
33276 rwlock_init(&md->map_lock);
33277 atomic_set(&md->holders, 1);
33278 atomic_set(&md->open_count, 0);
33279 - atomic_set(&md->event_nr, 0);
33280 - atomic_set(&md->uevent_seq, 0);
33281 + atomic_set_unchecked(&md->event_nr, 0);
33282 + atomic_set_unchecked(&md->uevent_seq, 0);
33283 INIT_LIST_HEAD(&md->uevent_list);
33284 spin_lock_init(&md->uevent_lock);
33285
33286 @@ -1980,7 +1980,7 @@ static void event_callback(void *context)
33287
33288 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33289
33290 - atomic_inc(&md->event_nr);
33291 + atomic_inc_unchecked(&md->event_nr);
33292 wake_up(&md->eventq);
33293 }
33294
33295 @@ -2622,18 +2622,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33296
33297 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33298 {
33299 - return atomic_add_return(1, &md->uevent_seq);
33300 + return atomic_add_return_unchecked(1, &md->uevent_seq);
33301 }
33302
33303 uint32_t dm_get_event_nr(struct mapped_device *md)
33304 {
33305 - return atomic_read(&md->event_nr);
33306 + return atomic_read_unchecked(&md->event_nr);
33307 }
33308
33309 int dm_wait_event(struct mapped_device *md, int event_nr)
33310 {
33311 return wait_event_interruptible(md->eventq,
33312 - (event_nr != atomic_read(&md->event_nr)));
33313 + (event_nr != atomic_read_unchecked(&md->event_nr)));
33314 }
33315
33316 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33317 diff --git a/drivers/md/md.c b/drivers/md/md.c
33318 index 2b30ffd..bf789ce 100644
33319 --- a/drivers/md/md.c
33320 +++ b/drivers/md/md.c
33321 @@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33322 * start build, activate spare
33323 */
33324 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33325 -static atomic_t md_event_count;
33326 +static atomic_unchecked_t md_event_count;
33327 void md_new_event(struct mddev *mddev)
33328 {
33329 - atomic_inc(&md_event_count);
33330 + atomic_inc_unchecked(&md_event_count);
33331 wake_up(&md_event_waiters);
33332 }
33333 EXPORT_SYMBOL_GPL(md_new_event);
33334 @@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33335 */
33336 static void md_new_event_inintr(struct mddev *mddev)
33337 {
33338 - atomic_inc(&md_event_count);
33339 + atomic_inc_unchecked(&md_event_count);
33340 wake_up(&md_event_waiters);
33341 }
33342
33343 @@ -1526,7 +1526,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33344
33345 rdev->preferred_minor = 0xffff;
33346 rdev->data_offset = le64_to_cpu(sb->data_offset);
33347 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33348 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33349
33350 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33351 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33352 @@ -1745,7 +1745,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33353 else
33354 sb->resync_offset = cpu_to_le64(0);
33355
33356 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33357 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33358
33359 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33360 sb->size = cpu_to_le64(mddev->dev_sectors);
33361 @@ -2691,7 +2691,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33362 static ssize_t
33363 errors_show(struct md_rdev *rdev, char *page)
33364 {
33365 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33366 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33367 }
33368
33369 static ssize_t
33370 @@ -2700,7 +2700,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33371 char *e;
33372 unsigned long n = simple_strtoul(buf, &e, 10);
33373 if (*buf && (*e == 0 || *e == '\n')) {
33374 - atomic_set(&rdev->corrected_errors, n);
33375 + atomic_set_unchecked(&rdev->corrected_errors, n);
33376 return len;
33377 }
33378 return -EINVAL;
33379 @@ -3086,8 +3086,8 @@ int md_rdev_init(struct md_rdev *rdev)
33380 rdev->sb_loaded = 0;
33381 rdev->bb_page = NULL;
33382 atomic_set(&rdev->nr_pending, 0);
33383 - atomic_set(&rdev->read_errors, 0);
33384 - atomic_set(&rdev->corrected_errors, 0);
33385 + atomic_set_unchecked(&rdev->read_errors, 0);
33386 + atomic_set_unchecked(&rdev->corrected_errors, 0);
33387
33388 INIT_LIST_HEAD(&rdev->same_set);
33389 init_waitqueue_head(&rdev->blocked_wait);
33390 @@ -6738,7 +6738,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33391
33392 spin_unlock(&pers_lock);
33393 seq_printf(seq, "\n");
33394 - seq->poll_event = atomic_read(&md_event_count);
33395 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33396 return 0;
33397 }
33398 if (v == (void*)2) {
33399 @@ -6841,7 +6841,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33400 return error;
33401
33402 seq = file->private_data;
33403 - seq->poll_event = atomic_read(&md_event_count);
33404 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33405 return error;
33406 }
33407
33408 @@ -6855,7 +6855,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33409 /* always allow read */
33410 mask = POLLIN | POLLRDNORM;
33411
33412 - if (seq->poll_event != atomic_read(&md_event_count))
33413 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33414 mask |= POLLERR | POLLPRI;
33415 return mask;
33416 }
33417 @@ -6899,7 +6899,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33418 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33419 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33420 (int)part_stat_read(&disk->part0, sectors[1]) -
33421 - atomic_read(&disk->sync_io);
33422 + atomic_read_unchecked(&disk->sync_io);
33423 /* sync IO will cause sync_io to increase before the disk_stats
33424 * as sync_io is counted when a request starts, and
33425 * disk_stats is counted when it completes.
33426 diff --git a/drivers/md/md.h b/drivers/md/md.h
33427 index 1c2063c..9639970 100644
33428 --- a/drivers/md/md.h
33429 +++ b/drivers/md/md.h
33430 @@ -93,13 +93,13 @@ struct md_rdev {
33431 * only maintained for arrays that
33432 * support hot removal
33433 */
33434 - atomic_t read_errors; /* number of consecutive read errors that
33435 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
33436 * we have tried to ignore.
33437 */
33438 struct timespec last_read_error; /* monotonic time since our
33439 * last read error
33440 */
33441 - atomic_t corrected_errors; /* number of corrected read errors,
33442 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33443 * for reporting to userspace and storing
33444 * in superblock.
33445 */
33446 @@ -429,7 +429,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33447
33448 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33449 {
33450 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33451 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33452 }
33453
33454 struct md_personality
33455 diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
33456 index 50ed53b..4f29d7d 100644
33457 --- a/drivers/md/persistent-data/dm-space-map-checker.c
33458 +++ b/drivers/md/persistent-data/dm-space-map-checker.c
33459 @@ -159,7 +159,7 @@ static void ca_destroy(struct count_array *ca)
33460 /*----------------------------------------------------------------*/
33461
33462 struct sm_checker {
33463 - struct dm_space_map sm;
33464 + dm_space_map_no_const sm;
33465
33466 struct count_array old_counts;
33467 struct count_array counts;
33468 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33469 index fc469ba..2d91555 100644
33470 --- a/drivers/md/persistent-data/dm-space-map-disk.c
33471 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
33472 @@ -23,7 +23,7 @@
33473 * Space map interface.
33474 */
33475 struct sm_disk {
33476 - struct dm_space_map sm;
33477 + dm_space_map_no_const sm;
33478
33479 struct ll_disk ll;
33480 struct ll_disk old_ll;
33481 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33482 index e89ae5e..062e4c2 100644
33483 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
33484 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33485 @@ -43,7 +43,7 @@ struct block_op {
33486 };
33487
33488 struct sm_metadata {
33489 - struct dm_space_map sm;
33490 + dm_space_map_no_const sm;
33491
33492 struct ll_disk ll;
33493 struct ll_disk old_ll;
33494 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33495 index 1cbfc6b..56e1dbb 100644
33496 --- a/drivers/md/persistent-data/dm-space-map.h
33497 +++ b/drivers/md/persistent-data/dm-space-map.h
33498 @@ -60,6 +60,7 @@ struct dm_space_map {
33499 int (*root_size)(struct dm_space_map *sm, size_t *result);
33500 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33501 };
33502 +typedef struct dm_space_map __no_const dm_space_map_no_const;
33503
33504 /*----------------------------------------------------------------*/
33505
33506 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33507 index d7e9577..faa512f2 100644
33508 --- a/drivers/md/raid1.c
33509 +++ b/drivers/md/raid1.c
33510 @@ -1688,7 +1688,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33511 if (r1_sync_page_io(rdev, sect, s,
33512 bio->bi_io_vec[idx].bv_page,
33513 READ) != 0)
33514 - atomic_add(s, &rdev->corrected_errors);
33515 + atomic_add_unchecked(s, &rdev->corrected_errors);
33516 }
33517 sectors -= s;
33518 sect += s;
33519 @@ -1902,7 +1902,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33520 test_bit(In_sync, &rdev->flags)) {
33521 if (r1_sync_page_io(rdev, sect, s,
33522 conf->tmppage, READ)) {
33523 - atomic_add(s, &rdev->corrected_errors);
33524 + atomic_add_unchecked(s, &rdev->corrected_errors);
33525 printk(KERN_INFO
33526 "md/raid1:%s: read error corrected "
33527 "(%d sectors at %llu on %s)\n",
33528 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33529 index d037adb..ed17dc9 100644
33530 --- a/drivers/md/raid10.c
33531 +++ b/drivers/md/raid10.c
33532 @@ -1684,7 +1684,7 @@ static void end_sync_read(struct bio *bio, int error)
33533 /* The write handler will notice the lack of
33534 * R10BIO_Uptodate and record any errors etc
33535 */
33536 - atomic_add(r10_bio->sectors,
33537 + atomic_add_unchecked(r10_bio->sectors,
33538 &conf->mirrors[d].rdev->corrected_errors);
33539
33540 /* for reconstruct, we always reschedule after a read.
33541 @@ -2033,7 +2033,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33542 {
33543 struct timespec cur_time_mon;
33544 unsigned long hours_since_last;
33545 - unsigned int read_errors = atomic_read(&rdev->read_errors);
33546 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33547
33548 ktime_get_ts(&cur_time_mon);
33549
33550 @@ -2055,9 +2055,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33551 * overflowing the shift of read_errors by hours_since_last.
33552 */
33553 if (hours_since_last >= 8 * sizeof(read_errors))
33554 - atomic_set(&rdev->read_errors, 0);
33555 + atomic_set_unchecked(&rdev->read_errors, 0);
33556 else
33557 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33558 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33559 }
33560
33561 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33562 @@ -2111,8 +2111,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33563 return;
33564
33565 check_decay_read_errors(mddev, rdev);
33566 - atomic_inc(&rdev->read_errors);
33567 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
33568 + atomic_inc_unchecked(&rdev->read_errors);
33569 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33570 char b[BDEVNAME_SIZE];
33571 bdevname(rdev->bdev, b);
33572
33573 @@ -2120,7 +2120,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33574 "md/raid10:%s: %s: Raid device exceeded "
33575 "read_error threshold [cur %d:max %d]\n",
33576 mdname(mddev), b,
33577 - atomic_read(&rdev->read_errors), max_read_errors);
33578 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33579 printk(KERN_NOTICE
33580 "md/raid10:%s: %s: Failing raid device\n",
33581 mdname(mddev), b);
33582 @@ -2271,7 +2271,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33583 (unsigned long long)(
33584 sect + rdev->data_offset),
33585 bdevname(rdev->bdev, b));
33586 - atomic_add(s, &rdev->corrected_errors);
33587 + atomic_add_unchecked(s, &rdev->corrected_errors);
33588 }
33589
33590 rdev_dec_pending(rdev, mddev);
33591 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33592 index f351422..85c01bb 100644
33593 --- a/drivers/md/raid5.c
33594 +++ b/drivers/md/raid5.c
33595 @@ -1686,18 +1686,18 @@ static void raid5_end_read_request(struct bio * bi, int error)
33596 (unsigned long long)(sh->sector
33597 + rdev->data_offset),
33598 bdevname(rdev->bdev, b));
33599 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33600 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33601 clear_bit(R5_ReadError, &sh->dev[i].flags);
33602 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33603 }
33604 - if (atomic_read(&rdev->read_errors))
33605 - atomic_set(&rdev->read_errors, 0);
33606 + if (atomic_read_unchecked(&rdev->read_errors))
33607 + atomic_set_unchecked(&rdev->read_errors, 0);
33608 } else {
33609 const char *bdn = bdevname(rdev->bdev, b);
33610 int retry = 0;
33611
33612 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33613 - atomic_inc(&rdev->read_errors);
33614 + atomic_inc_unchecked(&rdev->read_errors);
33615 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33616 printk_ratelimited(
33617 KERN_WARNING
33618 @@ -1726,7 +1726,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33619 (unsigned long long)(sh->sector
33620 + rdev->data_offset),
33621 bdn);
33622 - else if (atomic_read(&rdev->read_errors)
33623 + else if (atomic_read_unchecked(&rdev->read_errors)
33624 > conf->max_nr_stripes)
33625 printk(KERN_WARNING
33626 "md/raid:%s: Too many read errors, failing device %s.\n",
33627 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33628 index d88c4aa..17c80b1 100644
33629 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33630 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33631 @@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
33632 .subvendor = _subvend, .subdevice = _subdev, \
33633 .driver_data = (unsigned long)&_driverdata }
33634
33635 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33636 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33637 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33638 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33639 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33640 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33641 index a7d876f..8c21b61 100644
33642 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
33643 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33644 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
33645 union {
33646 dmx_ts_cb ts;
33647 dmx_section_cb sec;
33648 - } cb;
33649 + } __no_const cb;
33650
33651 struct dvb_demux *demux;
33652 void *priv;
33653 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33654 index 00a6732..70a682e 100644
33655 --- a/drivers/media/dvb/dvb-core/dvbdev.c
33656 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
33657 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33658 const struct dvb_device *template, void *priv, int type)
33659 {
33660 struct dvb_device *dvbdev;
33661 - struct file_operations *dvbdevfops;
33662 + file_operations_no_const *dvbdevfops;
33663 struct device *clsdev;
33664 int minor;
33665 int id;
33666 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33667 index 3940bb0..fb3952a 100644
33668 --- a/drivers/media/dvb/dvb-usb/cxusb.c
33669 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
33670 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33671
33672 struct dib0700_adapter_state {
33673 int (*set_param_save) (struct dvb_frontend *);
33674 -};
33675 +} __no_const;
33676
33677 static int dib7070_set_param_override(struct dvb_frontend *fe)
33678 {
33679 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33680 index 451c5a7..649f711 100644
33681 --- a/drivers/media/dvb/dvb-usb/dw2102.c
33682 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
33683 @@ -95,7 +95,7 @@ struct su3000_state {
33684
33685 struct s6x0_state {
33686 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33687 -};
33688 +} __no_const;
33689
33690 /* debug */
33691 static int dvb_usb_dw2102_debug;
33692 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33693 index 404f63a..4796533 100644
33694 --- a/drivers/media/dvb/frontends/dib3000.h
33695 +++ b/drivers/media/dvb/frontends/dib3000.h
33696 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33697 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33698 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33699 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33700 -};
33701 +} __no_const;
33702
33703 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33704 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33705 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33706 index 7539a5d..06531a6 100644
33707 --- a/drivers/media/dvb/ngene/ngene-cards.c
33708 +++ b/drivers/media/dvb/ngene/ngene-cards.c
33709 @@ -478,7 +478,7 @@ static struct ngene_info ngene_info_m780 = {
33710
33711 /****************************************************************************/
33712
33713 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33714 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33715 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33716 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33717 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33718 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33719 index 16a089f..1661b11 100644
33720 --- a/drivers/media/radio/radio-cadet.c
33721 +++ b/drivers/media/radio/radio-cadet.c
33722 @@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33723 unsigned char readbuf[RDS_BUFFER];
33724 int i = 0;
33725
33726 + if (count > RDS_BUFFER)
33727 + return -EFAULT;
33728 mutex_lock(&dev->lock);
33729 if (dev->rdsstat == 0) {
33730 dev->rdsstat = 1;
33731 @@ -347,7 +349,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33732 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
33733 mutex_unlock(&dev->lock);
33734
33735 - if (copy_to_user(data, readbuf, i))
33736 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
33737 return -EFAULT;
33738 return i;
33739 }
33740 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
33741 index 9cde353..8c6a1c3 100644
33742 --- a/drivers/media/video/au0828/au0828.h
33743 +++ b/drivers/media/video/au0828/au0828.h
33744 @@ -191,7 +191,7 @@ struct au0828_dev {
33745
33746 /* I2C */
33747 struct i2c_adapter i2c_adap;
33748 - struct i2c_algorithm i2c_algo;
33749 + i2c_algorithm_no_const i2c_algo;
33750 struct i2c_client i2c_client;
33751 u32 i2c_rc;
33752
33753 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
33754 index 04bf662..e0ac026 100644
33755 --- a/drivers/media/video/cx88/cx88-alsa.c
33756 +++ b/drivers/media/video/cx88/cx88-alsa.c
33757 @@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
33758 * Only boards with eeprom and byte 1 at eeprom=1 have it
33759 */
33760
33761 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
33762 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
33763 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33764 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33765 {0, }
33766 diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
33767 index 88cf9d9..bbc4b2c 100644
33768 --- a/drivers/media/video/omap/omap_vout.c
33769 +++ b/drivers/media/video/omap/omap_vout.c
33770 @@ -64,7 +64,6 @@ enum omap_vout_channels {
33771 OMAP_VIDEO2,
33772 };
33773
33774 -static struct videobuf_queue_ops video_vbq_ops;
33775 /* Variables configurable through module params*/
33776 static u32 video1_numbuffers = 3;
33777 static u32 video2_numbuffers = 3;
33778 @@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
33779 {
33780 struct videobuf_queue *q;
33781 struct omap_vout_device *vout = NULL;
33782 + static struct videobuf_queue_ops video_vbq_ops = {
33783 + .buf_setup = omap_vout_buffer_setup,
33784 + .buf_prepare = omap_vout_buffer_prepare,
33785 + .buf_release = omap_vout_buffer_release,
33786 + .buf_queue = omap_vout_buffer_queue,
33787 + };
33788
33789 vout = video_drvdata(file);
33790 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
33791 @@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
33792 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
33793
33794 q = &vout->vbq;
33795 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
33796 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
33797 - video_vbq_ops.buf_release = omap_vout_buffer_release;
33798 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
33799 spin_lock_init(&vout->vbq_lock);
33800
33801 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
33802 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33803 index 305e6aa..0143317 100644
33804 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33805 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33806 @@ -196,7 +196,7 @@ struct pvr2_hdw {
33807
33808 /* I2C stuff */
33809 struct i2c_adapter i2c_adap;
33810 - struct i2c_algorithm i2c_algo;
33811 + i2c_algorithm_no_const i2c_algo;
33812 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
33813 int i2c_cx25840_hack_state;
33814 int i2c_linked;
33815 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
33816 index 02194c0..091733b 100644
33817 --- a/drivers/media/video/timblogiw.c
33818 +++ b/drivers/media/video/timblogiw.c
33819 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
33820
33821 /* Platform device functions */
33822
33823 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33824 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
33825 .vidioc_querycap = timblogiw_querycap,
33826 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
33827 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
33828 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33829 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
33830 };
33831
33832 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
33833 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
33834 .owner = THIS_MODULE,
33835 .open = timblogiw_open,
33836 .release = timblogiw_close,
33837 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
33838 index a5c591f..db692a3 100644
33839 --- a/drivers/message/fusion/mptbase.c
33840 +++ b/drivers/message/fusion/mptbase.c
33841 @@ -6754,8 +6754,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
33842 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
33843 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33844
33845 +#ifdef CONFIG_GRKERNSEC_HIDESYM
33846 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
33847 +#else
33848 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33849 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33850 +#endif
33851 +
33852 /*
33853 * Rounding UP to nearest 4-kB boundary here...
33854 */
33855 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
33856 index 551262e..7551198 100644
33857 --- a/drivers/message/fusion/mptsas.c
33858 +++ b/drivers/message/fusion/mptsas.c
33859 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
33860 return 0;
33861 }
33862
33863 +static inline void
33864 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33865 +{
33866 + if (phy_info->port_details) {
33867 + phy_info->port_details->rphy = rphy;
33868 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33869 + ioc->name, rphy));
33870 + }
33871 +
33872 + if (rphy) {
33873 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33874 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33875 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33876 + ioc->name, rphy, rphy->dev.release));
33877 + }
33878 +}
33879 +
33880 /* no mutex */
33881 static void
33882 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
33883 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
33884 return NULL;
33885 }
33886
33887 -static inline void
33888 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33889 -{
33890 - if (phy_info->port_details) {
33891 - phy_info->port_details->rphy = rphy;
33892 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33893 - ioc->name, rphy));
33894 - }
33895 -
33896 - if (rphy) {
33897 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33898 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33899 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33900 - ioc->name, rphy, rphy->dev.release));
33901 - }
33902 -}
33903 -
33904 static inline struct sas_port *
33905 mptsas_get_port(struct mptsas_phyinfo *phy_info)
33906 {
33907 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
33908 index 0c3ced7..1fe34ec 100644
33909 --- a/drivers/message/fusion/mptscsih.c
33910 +++ b/drivers/message/fusion/mptscsih.c
33911 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
33912
33913 h = shost_priv(SChost);
33914
33915 - if (h) {
33916 - if (h->info_kbuf == NULL)
33917 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33918 - return h->info_kbuf;
33919 - h->info_kbuf[0] = '\0';
33920 + if (!h)
33921 + return NULL;
33922
33923 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33924 - h->info_kbuf[size-1] = '\0';
33925 - }
33926 + if (h->info_kbuf == NULL)
33927 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33928 + return h->info_kbuf;
33929 + h->info_kbuf[0] = '\0';
33930 +
33931 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33932 + h->info_kbuf[size-1] = '\0';
33933
33934 return h->info_kbuf;
33935 }
33936 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
33937 index 6d115c7..58ff7fd 100644
33938 --- a/drivers/message/i2o/i2o_proc.c
33939 +++ b/drivers/message/i2o/i2o_proc.c
33940 @@ -255,13 +255,6 @@ static char *scsi_devices[] = {
33941 "Array Controller Device"
33942 };
33943
33944 -static char *chtostr(u8 * chars, int n)
33945 -{
33946 - char tmp[256];
33947 - tmp[0] = 0;
33948 - return strncat(tmp, (char *)chars, n);
33949 -}
33950 -
33951 static int i2o_report_query_status(struct seq_file *seq, int block_status,
33952 char *group)
33953 {
33954 @@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
33955
33956 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
33957 seq_printf(seq, "%-#8x", ddm_table.module_id);
33958 - seq_printf(seq, "%-29s",
33959 - chtostr(ddm_table.module_name_version, 28));
33960 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
33961 seq_printf(seq, "%9d ", ddm_table.data_size);
33962 seq_printf(seq, "%8d", ddm_table.code_size);
33963
33964 @@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
33965
33966 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
33967 seq_printf(seq, "%-#8x", dst->module_id);
33968 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
33969 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
33970 + seq_printf(seq, "%-.28s", dst->module_name_version);
33971 + seq_printf(seq, "%-.8s", dst->date);
33972 seq_printf(seq, "%8d ", dst->module_size);
33973 seq_printf(seq, "%8d ", dst->mpb_size);
33974 seq_printf(seq, "0x%04x", dst->module_flags);
33975 @@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
33976 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
33977 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
33978 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
33979 - seq_printf(seq, "Vendor info : %s\n",
33980 - chtostr((u8 *) (work32 + 2), 16));
33981 - seq_printf(seq, "Product info : %s\n",
33982 - chtostr((u8 *) (work32 + 6), 16));
33983 - seq_printf(seq, "Description : %s\n",
33984 - chtostr((u8 *) (work32 + 10), 16));
33985 - seq_printf(seq, "Product rev. : %s\n",
33986 - chtostr((u8 *) (work32 + 14), 8));
33987 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
33988 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
33989 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
33990 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
33991
33992 seq_printf(seq, "Serial number : ");
33993 print_serial_number(seq, (u8 *) (work32 + 16),
33994 @@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
33995 }
33996
33997 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
33998 - seq_printf(seq, "Module name : %s\n",
33999 - chtostr(result.module_name, 24));
34000 - seq_printf(seq, "Module revision : %s\n",
34001 - chtostr(result.module_rev, 8));
34002 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
34003 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34004
34005 seq_printf(seq, "Serial number : ");
34006 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34007 @@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34008 return 0;
34009 }
34010
34011 - seq_printf(seq, "Device name : %s\n",
34012 - chtostr(result.device_name, 64));
34013 - seq_printf(seq, "Service name : %s\n",
34014 - chtostr(result.service_name, 64));
34015 - seq_printf(seq, "Physical name : %s\n",
34016 - chtostr(result.physical_location, 64));
34017 - seq_printf(seq, "Instance number : %s\n",
34018 - chtostr(result.instance_number, 4));
34019 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
34020 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
34021 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34022 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34023
34024 return 0;
34025 }
34026 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34027 index a8c08f3..155fe3d 100644
34028 --- a/drivers/message/i2o/iop.c
34029 +++ b/drivers/message/i2o/iop.c
34030 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34031
34032 spin_lock_irqsave(&c->context_list_lock, flags);
34033
34034 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34035 - atomic_inc(&c->context_list_counter);
34036 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34037 + atomic_inc_unchecked(&c->context_list_counter);
34038
34039 - entry->context = atomic_read(&c->context_list_counter);
34040 + entry->context = atomic_read_unchecked(&c->context_list_counter);
34041
34042 list_add(&entry->list, &c->context_list);
34043
34044 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34045
34046 #if BITS_PER_LONG == 64
34047 spin_lock_init(&c->context_list_lock);
34048 - atomic_set(&c->context_list_counter, 0);
34049 + atomic_set_unchecked(&c->context_list_counter, 0);
34050 INIT_LIST_HEAD(&c->context_list);
34051 #endif
34052
34053 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34054 index 7ce65f4..e66e9bc 100644
34055 --- a/drivers/mfd/abx500-core.c
34056 +++ b/drivers/mfd/abx500-core.c
34057 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34058
34059 struct abx500_device_entry {
34060 struct list_head list;
34061 - struct abx500_ops ops;
34062 + abx500_ops_no_const ops;
34063 struct device *dev;
34064 };
34065
34066 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34067 index a9223ed..4127b13 100644
34068 --- a/drivers/mfd/janz-cmodio.c
34069 +++ b/drivers/mfd/janz-cmodio.c
34070 @@ -13,6 +13,7 @@
34071
34072 #include <linux/kernel.h>
34073 #include <linux/module.h>
34074 +#include <linux/slab.h>
34075 #include <linux/init.h>
34076 #include <linux/pci.h>
34077 #include <linux/interrupt.h>
34078 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34079 index a981e2a..5ca0c8b 100644
34080 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
34081 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34082 @@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34083 * the lid is closed. This leads to interrupts as soon as a little move
34084 * is done.
34085 */
34086 - atomic_inc(&lis3->count);
34087 + atomic_inc_unchecked(&lis3->count);
34088
34089 wake_up_interruptible(&lis3->misc_wait);
34090 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34091 @@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34092 if (lis3->pm_dev)
34093 pm_runtime_get_sync(lis3->pm_dev);
34094
34095 - atomic_set(&lis3->count, 0);
34096 + atomic_set_unchecked(&lis3->count, 0);
34097 return 0;
34098 }
34099
34100 @@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34101 add_wait_queue(&lis3->misc_wait, &wait);
34102 while (true) {
34103 set_current_state(TASK_INTERRUPTIBLE);
34104 - data = atomic_xchg(&lis3->count, 0);
34105 + data = atomic_xchg_unchecked(&lis3->count, 0);
34106 if (data)
34107 break;
34108
34109 @@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34110 struct lis3lv02d, miscdev);
34111
34112 poll_wait(file, &lis3->misc_wait, wait);
34113 - if (atomic_read(&lis3->count))
34114 + if (atomic_read_unchecked(&lis3->count))
34115 return POLLIN | POLLRDNORM;
34116 return 0;
34117 }
34118 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34119 index 2b1482a..5d33616 100644
34120 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
34121 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34122 @@ -266,7 +266,7 @@ struct lis3lv02d {
34123 struct input_polled_dev *idev; /* input device */
34124 struct platform_device *pdev; /* platform device */
34125 struct regulator_bulk_data regulators[2];
34126 - atomic_t count; /* interrupt count after last read */
34127 + atomic_unchecked_t count; /* interrupt count after last read */
34128 union axis_conversion ac; /* hw -> logical axis */
34129 int mapped_btns[3];
34130
34131 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34132 index 2f30bad..c4c13d0 100644
34133 --- a/drivers/misc/sgi-gru/gruhandles.c
34134 +++ b/drivers/misc/sgi-gru/gruhandles.c
34135 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34136 unsigned long nsec;
34137
34138 nsec = CLKS2NSEC(clks);
34139 - atomic_long_inc(&mcs_op_statistics[op].count);
34140 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
34141 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34142 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34143 if (mcs_op_statistics[op].max < nsec)
34144 mcs_op_statistics[op].max = nsec;
34145 }
34146 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34147 index 950dbe9..eeef0f8 100644
34148 --- a/drivers/misc/sgi-gru/gruprocfs.c
34149 +++ b/drivers/misc/sgi-gru/gruprocfs.c
34150 @@ -32,9 +32,9 @@
34151
34152 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34153
34154 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34155 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34156 {
34157 - unsigned long val = atomic_long_read(v);
34158 + unsigned long val = atomic_long_read_unchecked(v);
34159
34160 seq_printf(s, "%16lu %s\n", val, id);
34161 }
34162 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34163
34164 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34165 for (op = 0; op < mcsop_last; op++) {
34166 - count = atomic_long_read(&mcs_op_statistics[op].count);
34167 - total = atomic_long_read(&mcs_op_statistics[op].total);
34168 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34169 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34170 max = mcs_op_statistics[op].max;
34171 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34172 count ? total / count : 0, max);
34173 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34174 index 5c3ce24..4915ccb 100644
34175 --- a/drivers/misc/sgi-gru/grutables.h
34176 +++ b/drivers/misc/sgi-gru/grutables.h
34177 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34178 * GRU statistics.
34179 */
34180 struct gru_stats_s {
34181 - atomic_long_t vdata_alloc;
34182 - atomic_long_t vdata_free;
34183 - atomic_long_t gts_alloc;
34184 - atomic_long_t gts_free;
34185 - atomic_long_t gms_alloc;
34186 - atomic_long_t gms_free;
34187 - atomic_long_t gts_double_allocate;
34188 - atomic_long_t assign_context;
34189 - atomic_long_t assign_context_failed;
34190 - atomic_long_t free_context;
34191 - atomic_long_t load_user_context;
34192 - atomic_long_t load_kernel_context;
34193 - atomic_long_t lock_kernel_context;
34194 - atomic_long_t unlock_kernel_context;
34195 - atomic_long_t steal_user_context;
34196 - atomic_long_t steal_kernel_context;
34197 - atomic_long_t steal_context_failed;
34198 - atomic_long_t nopfn;
34199 - atomic_long_t asid_new;
34200 - atomic_long_t asid_next;
34201 - atomic_long_t asid_wrap;
34202 - atomic_long_t asid_reuse;
34203 - atomic_long_t intr;
34204 - atomic_long_t intr_cbr;
34205 - atomic_long_t intr_tfh;
34206 - atomic_long_t intr_spurious;
34207 - atomic_long_t intr_mm_lock_failed;
34208 - atomic_long_t call_os;
34209 - atomic_long_t call_os_wait_queue;
34210 - atomic_long_t user_flush_tlb;
34211 - atomic_long_t user_unload_context;
34212 - atomic_long_t user_exception;
34213 - atomic_long_t set_context_option;
34214 - atomic_long_t check_context_retarget_intr;
34215 - atomic_long_t check_context_unload;
34216 - atomic_long_t tlb_dropin;
34217 - atomic_long_t tlb_preload_page;
34218 - atomic_long_t tlb_dropin_fail_no_asid;
34219 - atomic_long_t tlb_dropin_fail_upm;
34220 - atomic_long_t tlb_dropin_fail_invalid;
34221 - atomic_long_t tlb_dropin_fail_range_active;
34222 - atomic_long_t tlb_dropin_fail_idle;
34223 - atomic_long_t tlb_dropin_fail_fmm;
34224 - atomic_long_t tlb_dropin_fail_no_exception;
34225 - atomic_long_t tfh_stale_on_fault;
34226 - atomic_long_t mmu_invalidate_range;
34227 - atomic_long_t mmu_invalidate_page;
34228 - atomic_long_t flush_tlb;
34229 - atomic_long_t flush_tlb_gru;
34230 - atomic_long_t flush_tlb_gru_tgh;
34231 - atomic_long_t flush_tlb_gru_zero_asid;
34232 + atomic_long_unchecked_t vdata_alloc;
34233 + atomic_long_unchecked_t vdata_free;
34234 + atomic_long_unchecked_t gts_alloc;
34235 + atomic_long_unchecked_t gts_free;
34236 + atomic_long_unchecked_t gms_alloc;
34237 + atomic_long_unchecked_t gms_free;
34238 + atomic_long_unchecked_t gts_double_allocate;
34239 + atomic_long_unchecked_t assign_context;
34240 + atomic_long_unchecked_t assign_context_failed;
34241 + atomic_long_unchecked_t free_context;
34242 + atomic_long_unchecked_t load_user_context;
34243 + atomic_long_unchecked_t load_kernel_context;
34244 + atomic_long_unchecked_t lock_kernel_context;
34245 + atomic_long_unchecked_t unlock_kernel_context;
34246 + atomic_long_unchecked_t steal_user_context;
34247 + atomic_long_unchecked_t steal_kernel_context;
34248 + atomic_long_unchecked_t steal_context_failed;
34249 + atomic_long_unchecked_t nopfn;
34250 + atomic_long_unchecked_t asid_new;
34251 + atomic_long_unchecked_t asid_next;
34252 + atomic_long_unchecked_t asid_wrap;
34253 + atomic_long_unchecked_t asid_reuse;
34254 + atomic_long_unchecked_t intr;
34255 + atomic_long_unchecked_t intr_cbr;
34256 + atomic_long_unchecked_t intr_tfh;
34257 + atomic_long_unchecked_t intr_spurious;
34258 + atomic_long_unchecked_t intr_mm_lock_failed;
34259 + atomic_long_unchecked_t call_os;
34260 + atomic_long_unchecked_t call_os_wait_queue;
34261 + atomic_long_unchecked_t user_flush_tlb;
34262 + atomic_long_unchecked_t user_unload_context;
34263 + atomic_long_unchecked_t user_exception;
34264 + atomic_long_unchecked_t set_context_option;
34265 + atomic_long_unchecked_t check_context_retarget_intr;
34266 + atomic_long_unchecked_t check_context_unload;
34267 + atomic_long_unchecked_t tlb_dropin;
34268 + atomic_long_unchecked_t tlb_preload_page;
34269 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34270 + atomic_long_unchecked_t tlb_dropin_fail_upm;
34271 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
34272 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
34273 + atomic_long_unchecked_t tlb_dropin_fail_idle;
34274 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
34275 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34276 + atomic_long_unchecked_t tfh_stale_on_fault;
34277 + atomic_long_unchecked_t mmu_invalidate_range;
34278 + atomic_long_unchecked_t mmu_invalidate_page;
34279 + atomic_long_unchecked_t flush_tlb;
34280 + atomic_long_unchecked_t flush_tlb_gru;
34281 + atomic_long_unchecked_t flush_tlb_gru_tgh;
34282 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34283
34284 - atomic_long_t copy_gpa;
34285 - atomic_long_t read_gpa;
34286 + atomic_long_unchecked_t copy_gpa;
34287 + atomic_long_unchecked_t read_gpa;
34288
34289 - atomic_long_t mesq_receive;
34290 - atomic_long_t mesq_receive_none;
34291 - atomic_long_t mesq_send;
34292 - atomic_long_t mesq_send_failed;
34293 - atomic_long_t mesq_noop;
34294 - atomic_long_t mesq_send_unexpected_error;
34295 - atomic_long_t mesq_send_lb_overflow;
34296 - atomic_long_t mesq_send_qlimit_reached;
34297 - atomic_long_t mesq_send_amo_nacked;
34298 - atomic_long_t mesq_send_put_nacked;
34299 - atomic_long_t mesq_page_overflow;
34300 - atomic_long_t mesq_qf_locked;
34301 - atomic_long_t mesq_qf_noop_not_full;
34302 - atomic_long_t mesq_qf_switch_head_failed;
34303 - atomic_long_t mesq_qf_unexpected_error;
34304 - atomic_long_t mesq_noop_unexpected_error;
34305 - atomic_long_t mesq_noop_lb_overflow;
34306 - atomic_long_t mesq_noop_qlimit_reached;
34307 - atomic_long_t mesq_noop_amo_nacked;
34308 - atomic_long_t mesq_noop_put_nacked;
34309 - atomic_long_t mesq_noop_page_overflow;
34310 + atomic_long_unchecked_t mesq_receive;
34311 + atomic_long_unchecked_t mesq_receive_none;
34312 + atomic_long_unchecked_t mesq_send;
34313 + atomic_long_unchecked_t mesq_send_failed;
34314 + atomic_long_unchecked_t mesq_noop;
34315 + atomic_long_unchecked_t mesq_send_unexpected_error;
34316 + atomic_long_unchecked_t mesq_send_lb_overflow;
34317 + atomic_long_unchecked_t mesq_send_qlimit_reached;
34318 + atomic_long_unchecked_t mesq_send_amo_nacked;
34319 + atomic_long_unchecked_t mesq_send_put_nacked;
34320 + atomic_long_unchecked_t mesq_page_overflow;
34321 + atomic_long_unchecked_t mesq_qf_locked;
34322 + atomic_long_unchecked_t mesq_qf_noop_not_full;
34323 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
34324 + atomic_long_unchecked_t mesq_qf_unexpected_error;
34325 + atomic_long_unchecked_t mesq_noop_unexpected_error;
34326 + atomic_long_unchecked_t mesq_noop_lb_overflow;
34327 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
34328 + atomic_long_unchecked_t mesq_noop_amo_nacked;
34329 + atomic_long_unchecked_t mesq_noop_put_nacked;
34330 + atomic_long_unchecked_t mesq_noop_page_overflow;
34331
34332 };
34333
34334 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34335 tghop_invalidate, mcsop_last};
34336
34337 struct mcs_op_statistic {
34338 - atomic_long_t count;
34339 - atomic_long_t total;
34340 + atomic_long_unchecked_t count;
34341 + atomic_long_unchecked_t total;
34342 unsigned long max;
34343 };
34344
34345 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34346
34347 #define STAT(id) do { \
34348 if (gru_options & OPT_STATS) \
34349 - atomic_long_inc(&gru_stats.id); \
34350 + atomic_long_inc_unchecked(&gru_stats.id); \
34351 } while (0)
34352
34353 #ifdef CONFIG_SGI_GRU_DEBUG
34354 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34355 index c862cd4..0d176fe 100644
34356 --- a/drivers/misc/sgi-xp/xp.h
34357 +++ b/drivers/misc/sgi-xp/xp.h
34358 @@ -288,7 +288,7 @@ struct xpc_interface {
34359 xpc_notify_func, void *);
34360 void (*received) (short, int, void *);
34361 enum xp_retval (*partid_to_nasids) (short, void *);
34362 -};
34363 +} __no_const;
34364
34365 extern struct xpc_interface xpc_interface;
34366
34367 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34368 index b94d5f7..7f494c5 100644
34369 --- a/drivers/misc/sgi-xp/xpc.h
34370 +++ b/drivers/misc/sgi-xp/xpc.h
34371 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
34372 void (*received_payload) (struct xpc_channel *, void *);
34373 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34374 };
34375 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34376
34377 /* struct xpc_partition act_state values (for XPC HB) */
34378
34379 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34380 /* found in xpc_main.c */
34381 extern struct device *xpc_part;
34382 extern struct device *xpc_chan;
34383 -extern struct xpc_arch_operations xpc_arch_ops;
34384 +extern xpc_arch_operations_no_const xpc_arch_ops;
34385 extern int xpc_disengage_timelimit;
34386 extern int xpc_disengage_timedout;
34387 extern int xpc_activate_IRQ_rcvd;
34388 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34389 index 8d082b4..aa749ae 100644
34390 --- a/drivers/misc/sgi-xp/xpc_main.c
34391 +++ b/drivers/misc/sgi-xp/xpc_main.c
34392 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34393 .notifier_call = xpc_system_die,
34394 };
34395
34396 -struct xpc_arch_operations xpc_arch_ops;
34397 +xpc_arch_operations_no_const xpc_arch_ops;
34398
34399 /*
34400 * Timer function to enforce the timelimit on the partition disengage.
34401 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34402 index 69ef0be..f3ef91e 100644
34403 --- a/drivers/mmc/host/sdhci-pci.c
34404 +++ b/drivers/mmc/host/sdhci-pci.c
34405 @@ -652,7 +652,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34406 .probe = via_probe,
34407 };
34408
34409 -static const struct pci_device_id pci_ids[] __devinitdata = {
34410 +static const struct pci_device_id pci_ids[] __devinitconst = {
34411 {
34412 .vendor = PCI_VENDOR_ID_RICOH,
34413 .device = PCI_DEVICE_ID_RICOH_R5C822,
34414 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34415 index a4eb8b5..8c0628f 100644
34416 --- a/drivers/mtd/devices/doc2000.c
34417 +++ b/drivers/mtd/devices/doc2000.c
34418 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34419
34420 /* The ECC will not be calculated correctly if less than 512 is written */
34421 /* DBB-
34422 - if (len != 0x200 && eccbuf)
34423 + if (len != 0x200)
34424 printk(KERN_WARNING
34425 "ECC needs a full sector write (adr: %lx size %lx)\n",
34426 (long) to, (long) len);
34427 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34428 index a9e57d6..c6d8731 100644
34429 --- a/drivers/mtd/nand/denali.c
34430 +++ b/drivers/mtd/nand/denali.c
34431 @@ -26,6 +26,7 @@
34432 #include <linux/pci.h>
34433 #include <linux/mtd/mtd.h>
34434 #include <linux/module.h>
34435 +#include <linux/slab.h>
34436
34437 #include "denali.h"
34438
34439 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34440 index 51b9d6a..52af9a7 100644
34441 --- a/drivers/mtd/nftlmount.c
34442 +++ b/drivers/mtd/nftlmount.c
34443 @@ -24,6 +24,7 @@
34444 #include <asm/errno.h>
34445 #include <linux/delay.h>
34446 #include <linux/slab.h>
34447 +#include <linux/sched.h>
34448 #include <linux/mtd/mtd.h>
34449 #include <linux/mtd/nand.h>
34450 #include <linux/mtd/nftl.h>
34451 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34452 index 6762dc4..9956862 100644
34453 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
34454 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34455 @@ -2859,7 +2859,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34456 */
34457
34458 #define ATL2_PARAM(X, desc) \
34459 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34460 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34461 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34462 MODULE_PARM_DESC(X, desc);
34463 #else
34464 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34465 index 61a7670..7da6e34 100644
34466 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34467 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34468 @@ -483,7 +483,7 @@ struct bnx2x_rx_mode_obj {
34469
34470 int (*wait_comp)(struct bnx2x *bp,
34471 struct bnx2x_rx_mode_ramrod_params *p);
34472 -};
34473 +} __no_const;
34474
34475 /********************** Set multicast group ***********************************/
34476
34477 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34478 index 93865f8..5448741 100644
34479 --- a/drivers/net/ethernet/broadcom/tg3.h
34480 +++ b/drivers/net/ethernet/broadcom/tg3.h
34481 @@ -140,6 +140,7 @@
34482 #define CHIPREV_ID_5750_A0 0x4000
34483 #define CHIPREV_ID_5750_A1 0x4001
34484 #define CHIPREV_ID_5750_A3 0x4003
34485 +#define CHIPREV_ID_5750_C1 0x4201
34486 #define CHIPREV_ID_5750_C2 0x4202
34487 #define CHIPREV_ID_5752_A0_HW 0x5000
34488 #define CHIPREV_ID_5752_A0 0x6000
34489 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34490 index c4e8643..0979484 100644
34491 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34492 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34493 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34494 */
34495 struct l2t_skb_cb {
34496 arp_failure_handler_func arp_failure_handler;
34497 -};
34498 +} __no_const;
34499
34500 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34501
34502 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34503 index 18b106c..2b38d36 100644
34504 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
34505 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34506 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34507 for (i=0; i<ETH_ALEN; i++) {
34508 tmp.addr[i] = dev->dev_addr[i];
34509 }
34510 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34511 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34512 break;
34513
34514 case DE4X5_SET_HWADDR: /* Set the hardware address */
34515 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34516 spin_lock_irqsave(&lp->lock, flags);
34517 memcpy(&statbuf, &lp->pktStats, ioc->len);
34518 spin_unlock_irqrestore(&lp->lock, flags);
34519 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
34520 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34521 return -EFAULT;
34522 break;
34523 }
34524 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34525 index ed7d1dc..d426748 100644
34526 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
34527 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34528 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34529 {NULL}};
34530
34531
34532 -static const char *block_name[] __devinitdata = {
34533 +static const char *block_name[] __devinitconst = {
34534 "21140 non-MII",
34535 "21140 MII PHY",
34536 "21142 Serial PHY",
34537 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34538 index 2ac6fff..2d127d0 100644
34539 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34540 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34541 @@ -236,7 +236,7 @@ struct pci_id_info {
34542 int drv_flags; /* Driver use, intended as capability flags. */
34543 };
34544
34545 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34546 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34547 { /* Sometime a Level-One switch card. */
34548 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34549 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34550 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34551 index d783f4f..97fa1b0 100644
34552 --- a/drivers/net/ethernet/dlink/sundance.c
34553 +++ b/drivers/net/ethernet/dlink/sundance.c
34554 @@ -218,7 +218,7 @@ enum {
34555 struct pci_id_info {
34556 const char *name;
34557 };
34558 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34559 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34560 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34561 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34562 {"D-Link DFE-580TX 4 port Server Adapter"},
34563 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34564 index 528a886..e6a98a3 100644
34565 --- a/drivers/net/ethernet/emulex/benet/be_main.c
34566 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
34567 @@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34568
34569 if (wrapped)
34570 newacc += 65536;
34571 - ACCESS_ONCE(*acc) = newacc;
34572 + ACCESS_ONCE_RW(*acc) = newacc;
34573 }
34574
34575 void be_parse_stats(struct be_adapter *adapter)
34576 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34577 index 16b0704..d2c07d7 100644
34578 --- a/drivers/net/ethernet/faraday/ftgmac100.c
34579 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
34580 @@ -31,6 +31,8 @@
34581 #include <linux/netdevice.h>
34582 #include <linux/phy.h>
34583 #include <linux/platform_device.h>
34584 +#include <linux/interrupt.h>
34585 +#include <linux/irqreturn.h>
34586 #include <net/ip.h>
34587
34588 #include "ftgmac100.h"
34589 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34590 index 829b109..4ae5f6a 100644
34591 --- a/drivers/net/ethernet/faraday/ftmac100.c
34592 +++ b/drivers/net/ethernet/faraday/ftmac100.c
34593 @@ -31,6 +31,8 @@
34594 #include <linux/module.h>
34595 #include <linux/netdevice.h>
34596 #include <linux/platform_device.h>
34597 +#include <linux/interrupt.h>
34598 +#include <linux/irqreturn.h>
34599
34600 #include "ftmac100.h"
34601
34602 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34603 index 1637b98..c42f87b 100644
34604 --- a/drivers/net/ethernet/fealnx.c
34605 +++ b/drivers/net/ethernet/fealnx.c
34606 @@ -150,7 +150,7 @@ struct chip_info {
34607 int flags;
34608 };
34609
34610 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
34611 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
34612 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34613 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
34614 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34615 diff --git a/drivers/net/ethernet/intel/e1000e/e1000.h b/drivers/net/ethernet/intel/e1000e/e1000.h
34616 index b83897f..b2d970f 100644
34617 --- a/drivers/net/ethernet/intel/e1000e/e1000.h
34618 +++ b/drivers/net/ethernet/intel/e1000e/e1000.h
34619 @@ -181,7 +181,7 @@ struct e1000_info;
34620 #define E1000_TXDCTL_DMA_BURST_ENABLE \
34621 (E1000_TXDCTL_GRAN | /* set descriptor granularity */ \
34622 E1000_TXDCTL_COUNT_DESC | \
34623 - (5 << 16) | /* wthresh must be +1 more than desired */\
34624 + (1 << 16) | /* wthresh must be +1 more than desired */\
34625 (1 << 8) | /* hthresh */ \
34626 0x1f) /* pthresh */
34627
34628 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34629 index f82ecf5..7d59ecb 100644
34630 --- a/drivers/net/ethernet/intel/e1000e/hw.h
34631 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
34632 @@ -784,6 +784,7 @@ struct e1000_mac_operations {
34633 void (*config_collision_dist)(struct e1000_hw *);
34634 s32 (*read_mac_addr)(struct e1000_hw *);
34635 };
34636 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34637
34638 /*
34639 * When to use various PHY register access functions:
34640 @@ -824,6 +825,7 @@ struct e1000_phy_operations {
34641 void (*power_up)(struct e1000_hw *);
34642 void (*power_down)(struct e1000_hw *);
34643 };
34644 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34645
34646 /* Function pointers for the NVM. */
34647 struct e1000_nvm_operations {
34648 @@ -836,9 +838,10 @@ struct e1000_nvm_operations {
34649 s32 (*validate)(struct e1000_hw *);
34650 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34651 };
34652 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34653
34654 struct e1000_mac_info {
34655 - struct e1000_mac_operations ops;
34656 + e1000_mac_operations_no_const ops;
34657 u8 addr[ETH_ALEN];
34658 u8 perm_addr[ETH_ALEN];
34659
34660 @@ -879,7 +882,7 @@ struct e1000_mac_info {
34661 };
34662
34663 struct e1000_phy_info {
34664 - struct e1000_phy_operations ops;
34665 + e1000_phy_operations_no_const ops;
34666
34667 enum e1000_phy_type type;
34668
34669 @@ -913,7 +916,7 @@ struct e1000_phy_info {
34670 };
34671
34672 struct e1000_nvm_info {
34673 - struct e1000_nvm_operations ops;
34674 + e1000_nvm_operations_no_const ops;
34675
34676 enum e1000_nvm_type type;
34677 enum e1000_nvm_override override;
34678 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
34679 index f67cbd3..cef9e3d 100644
34680 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
34681 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
34682 @@ -314,6 +314,7 @@ struct e1000_mac_operations {
34683 s32 (*read_mac_addr)(struct e1000_hw *);
34684 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
34685 };
34686 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34687
34688 struct e1000_phy_operations {
34689 s32 (*acquire)(struct e1000_hw *);
34690 @@ -330,6 +331,7 @@ struct e1000_phy_operations {
34691 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
34692 s32 (*write_reg)(struct e1000_hw *, u32, u16);
34693 };
34694 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34695
34696 struct e1000_nvm_operations {
34697 s32 (*acquire)(struct e1000_hw *);
34698 @@ -339,6 +341,7 @@ struct e1000_nvm_operations {
34699 s32 (*update)(struct e1000_hw *);
34700 s32 (*validate)(struct e1000_hw *);
34701 };
34702 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34703
34704 struct e1000_info {
34705 s32 (*get_invariants)(struct e1000_hw *);
34706 @@ -350,7 +353,7 @@ struct e1000_info {
34707 extern const struct e1000_info e1000_82575_info;
34708
34709 struct e1000_mac_info {
34710 - struct e1000_mac_operations ops;
34711 + e1000_mac_operations_no_const ops;
34712
34713 u8 addr[6];
34714 u8 perm_addr[6];
34715 @@ -388,7 +391,7 @@ struct e1000_mac_info {
34716 };
34717
34718 struct e1000_phy_info {
34719 - struct e1000_phy_operations ops;
34720 + e1000_phy_operations_no_const ops;
34721
34722 enum e1000_phy_type type;
34723
34724 @@ -423,7 +426,7 @@ struct e1000_phy_info {
34725 };
34726
34727 struct e1000_nvm_info {
34728 - struct e1000_nvm_operations ops;
34729 + e1000_nvm_operations_no_const ops;
34730 enum e1000_nvm_type type;
34731 enum e1000_nvm_override override;
34732
34733 @@ -468,6 +471,7 @@ struct e1000_mbx_operations {
34734 s32 (*check_for_ack)(struct e1000_hw *, u16);
34735 s32 (*check_for_rst)(struct e1000_hw *, u16);
34736 };
34737 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34738
34739 struct e1000_mbx_stats {
34740 u32 msgs_tx;
34741 @@ -479,7 +483,7 @@ struct e1000_mbx_stats {
34742 };
34743
34744 struct e1000_mbx_info {
34745 - struct e1000_mbx_operations ops;
34746 + e1000_mbx_operations_no_const ops;
34747 struct e1000_mbx_stats stats;
34748 u32 timeout;
34749 u32 usec_delay;
34750 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
34751 index 57db3c6..aa825fc 100644
34752 --- a/drivers/net/ethernet/intel/igbvf/vf.h
34753 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
34754 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
34755 s32 (*read_mac_addr)(struct e1000_hw *);
34756 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
34757 };
34758 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34759
34760 struct e1000_mac_info {
34761 - struct e1000_mac_operations ops;
34762 + e1000_mac_operations_no_const ops;
34763 u8 addr[6];
34764 u8 perm_addr[6];
34765
34766 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
34767 s32 (*check_for_ack)(struct e1000_hw *);
34768 s32 (*check_for_rst)(struct e1000_hw *);
34769 };
34770 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34771
34772 struct e1000_mbx_stats {
34773 u32 msgs_tx;
34774 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
34775 };
34776
34777 struct e1000_mbx_info {
34778 - struct e1000_mbx_operations ops;
34779 + e1000_mbx_operations_no_const ops;
34780 struct e1000_mbx_stats stats;
34781 u32 timeout;
34782 u32 usec_delay;
34783 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34784 index 8636e83..ab9bbc3 100644
34785 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34786 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34787 @@ -2710,6 +2710,7 @@ struct ixgbe_eeprom_operations {
34788 s32 (*update_checksum)(struct ixgbe_hw *);
34789 u16 (*calc_checksum)(struct ixgbe_hw *);
34790 };
34791 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
34792
34793 struct ixgbe_mac_operations {
34794 s32 (*init_hw)(struct ixgbe_hw *);
34795 @@ -2773,6 +2774,7 @@ struct ixgbe_mac_operations {
34796 /* Manageability interface */
34797 s32 (*set_fw_drv_ver)(struct ixgbe_hw *, u8, u8, u8, u8);
34798 };
34799 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34800
34801 struct ixgbe_phy_operations {
34802 s32 (*identify)(struct ixgbe_hw *);
34803 @@ -2792,9 +2794,10 @@ struct ixgbe_phy_operations {
34804 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
34805 s32 (*check_overtemp)(struct ixgbe_hw *);
34806 };
34807 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
34808
34809 struct ixgbe_eeprom_info {
34810 - struct ixgbe_eeprom_operations ops;
34811 + ixgbe_eeprom_operations_no_const ops;
34812 enum ixgbe_eeprom_type type;
34813 u32 semaphore_delay;
34814 u16 word_size;
34815 @@ -2804,7 +2807,7 @@ struct ixgbe_eeprom_info {
34816
34817 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
34818 struct ixgbe_mac_info {
34819 - struct ixgbe_mac_operations ops;
34820 + ixgbe_mac_operations_no_const ops;
34821 enum ixgbe_mac_type type;
34822 u8 addr[ETH_ALEN];
34823 u8 perm_addr[ETH_ALEN];
34824 @@ -2832,7 +2835,7 @@ struct ixgbe_mac_info {
34825 };
34826
34827 struct ixgbe_phy_info {
34828 - struct ixgbe_phy_operations ops;
34829 + ixgbe_phy_operations_no_const ops;
34830 struct mdio_if_info mdio;
34831 enum ixgbe_phy_type type;
34832 u32 id;
34833 @@ -2860,6 +2863,7 @@ struct ixgbe_mbx_operations {
34834 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
34835 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
34836 };
34837 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34838
34839 struct ixgbe_mbx_stats {
34840 u32 msgs_tx;
34841 @@ -2871,7 +2875,7 @@ struct ixgbe_mbx_stats {
34842 };
34843
34844 struct ixgbe_mbx_info {
34845 - struct ixgbe_mbx_operations ops;
34846 + ixgbe_mbx_operations_no_const ops;
34847 struct ixgbe_mbx_stats stats;
34848 u32 timeout;
34849 u32 usec_delay;
34850 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
34851 index 25c951d..cc7cf33 100644
34852 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
34853 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
34854 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
34855 s32 (*clear_vfta)(struct ixgbe_hw *);
34856 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
34857 };
34858 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34859
34860 enum ixgbe_mac_type {
34861 ixgbe_mac_unknown = 0,
34862 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
34863 };
34864
34865 struct ixgbe_mac_info {
34866 - struct ixgbe_mac_operations ops;
34867 + ixgbe_mac_operations_no_const ops;
34868 u8 addr[6];
34869 u8 perm_addr[6];
34870
34871 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
34872 s32 (*check_for_ack)(struct ixgbe_hw *);
34873 s32 (*check_for_rst)(struct ixgbe_hw *);
34874 };
34875 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34876
34877 struct ixgbe_mbx_stats {
34878 u32 msgs_tx;
34879 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
34880 };
34881
34882 struct ixgbe_mbx_info {
34883 - struct ixgbe_mbx_operations ops;
34884 + ixgbe_mbx_operations_no_const ops;
34885 struct ixgbe_mbx_stats stats;
34886 u32 timeout;
34887 u32 udelay;
34888 diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
34889 index 8bb05b4..074796f 100644
34890 --- a/drivers/net/ethernet/mellanox/mlx4/main.c
34891 +++ b/drivers/net/ethernet/mellanox/mlx4/main.c
34892 @@ -41,6 +41,7 @@
34893 #include <linux/slab.h>
34894 #include <linux/io-mapping.h>
34895 #include <linux/delay.h>
34896 +#include <linux/sched.h>
34897
34898 #include <linux/mlx4/device.h>
34899 #include <linux/mlx4/doorbell.h>
34900 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
34901 index 5046a64..71ca936 100644
34902 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
34903 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
34904 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
34905 void (*link_down)(struct __vxge_hw_device *devh);
34906 void (*crit_err)(struct __vxge_hw_device *devh,
34907 enum vxge_hw_event type, u64 ext_data);
34908 -};
34909 +} __no_const;
34910
34911 /*
34912 * struct __vxge_hw_blockpool_entry - Block private data structure
34913 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34914 index 4a518a3..936b334 100644
34915 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34916 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34917 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
34918 struct vxge_hw_mempool_dma *dma_object,
34919 u32 index,
34920 u32 is_last);
34921 -};
34922 +} __no_const;
34923
34924 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
34925 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
34926 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
34927 index ce6b44d..74f10c2 100644
34928 --- a/drivers/net/ethernet/realtek/r8169.c
34929 +++ b/drivers/net/ethernet/realtek/r8169.c
34930 @@ -708,17 +708,17 @@ struct rtl8169_private {
34931 struct mdio_ops {
34932 void (*write)(void __iomem *, int, int);
34933 int (*read)(void __iomem *, int);
34934 - } mdio_ops;
34935 + } __no_const mdio_ops;
34936
34937 struct pll_power_ops {
34938 void (*down)(struct rtl8169_private *);
34939 void (*up)(struct rtl8169_private *);
34940 - } pll_power_ops;
34941 + } __no_const pll_power_ops;
34942
34943 struct jumbo_ops {
34944 void (*enable)(struct rtl8169_private *);
34945 void (*disable)(struct rtl8169_private *);
34946 - } jumbo_ops;
34947 + } __no_const jumbo_ops;
34948
34949 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
34950 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
34951 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
34952 index a9deda8..5507c31 100644
34953 --- a/drivers/net/ethernet/sis/sis190.c
34954 +++ b/drivers/net/ethernet/sis/sis190.c
34955 @@ -1620,7 +1620,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
34956 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
34957 struct net_device *dev)
34958 {
34959 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
34960 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
34961 struct sis190_private *tp = netdev_priv(dev);
34962 struct pci_dev *isa_bridge;
34963 u8 reg, tmp8;
34964 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
34965 index c07cfe9..81cbf7e 100644
34966 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
34967 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
34968 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
34969
34970 writel(value, ioaddr + MMC_CNTRL);
34971
34972 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
34973 - MMC_CNTRL, value);
34974 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
34975 +// MMC_CNTRL, value);
34976 }
34977
34978 /* To mask all all interrupts.*/
34979 diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
34980 index 48d56da..a27e46c 100644
34981 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
34982 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
34983 @@ -1584,7 +1584,7 @@ static const struct file_operations stmmac_rings_status_fops = {
34984 .open = stmmac_sysfs_ring_open,
34985 .read = seq_read,
34986 .llseek = seq_lseek,
34987 - .release = seq_release,
34988 + .release = single_release,
34989 };
34990
34991 static int stmmac_sysfs_dma_cap_read(struct seq_file *seq, void *v)
34992 @@ -1656,7 +1656,7 @@ static const struct file_operations stmmac_dma_cap_fops = {
34993 .open = stmmac_sysfs_dma_cap_open,
34994 .read = seq_read,
34995 .llseek = seq_lseek,
34996 - .release = seq_release,
34997 + .release = single_release,
34998 };
34999
35000 static int stmmac_init_fs(struct net_device *dev)
35001 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35002 index c358245..8c1de63 100644
35003 --- a/drivers/net/hyperv/hyperv_net.h
35004 +++ b/drivers/net/hyperv/hyperv_net.h
35005 @@ -98,7 +98,7 @@ struct rndis_device {
35006
35007 enum rndis_device_state state;
35008 bool link_state;
35009 - atomic_t new_req_id;
35010 + atomic_unchecked_t new_req_id;
35011
35012 spinlock_t request_lock;
35013 struct list_head req_list;
35014 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35015 index d6be64b..5d97e3b 100644
35016 --- a/drivers/net/hyperv/rndis_filter.c
35017 +++ b/drivers/net/hyperv/rndis_filter.c
35018 @@ -97,7 +97,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35019 * template
35020 */
35021 set = &rndis_msg->msg.set_req;
35022 - set->req_id = atomic_inc_return(&dev->new_req_id);
35023 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35024
35025 /* Add to the request list */
35026 spin_lock_irqsave(&dev->request_lock, flags);
35027 @@ -648,7 +648,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35028
35029 /* Setup the rndis set */
35030 halt = &request->request_msg.msg.halt_req;
35031 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35032 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35033
35034 /* Ignore return since this msg is optional. */
35035 rndis_filter_send_request(dev, request);
35036 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
35037 index cb8fd50..003ec38 100644
35038 --- a/drivers/net/macvtap.c
35039 +++ b/drivers/net/macvtap.c
35040 @@ -528,6 +528,8 @@ static int zerocopy_sg_from_iovec(struct sk_buff *skb, const struct iovec *from,
35041 }
35042 base = (unsigned long)from->iov_base + offset1;
35043 size = ((base & ~PAGE_MASK) + len + ~PAGE_MASK) >> PAGE_SHIFT;
35044 + if (i + size >= MAX_SKB_FRAGS)
35045 + return -EFAULT;
35046 num_pages = get_user_pages_fast(base, size, 0, &page[i]);
35047 if ((num_pages != size) ||
35048 (num_pages > MAX_SKB_FRAGS - skb_shinfo(skb)->nr_frags))
35049 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35050 index 21d7151..8034208 100644
35051 --- a/drivers/net/ppp/ppp_generic.c
35052 +++ b/drivers/net/ppp/ppp_generic.c
35053 @@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35054 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35055 struct ppp_stats stats;
35056 struct ppp_comp_stats cstats;
35057 - char *vers;
35058
35059 switch (cmd) {
35060 case SIOCGPPPSTATS:
35061 @@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35062 break;
35063
35064 case SIOCGPPPVER:
35065 - vers = PPP_VERSION;
35066 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35067 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35068 break;
35069 err = 0;
35070 break;
35071 diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
35072 index b715e6b..6d2490f 100644
35073 --- a/drivers/net/tokenring/abyss.c
35074 +++ b/drivers/net/tokenring/abyss.c
35075 @@ -450,10 +450,12 @@ static struct pci_driver abyss_driver = {
35076
35077 static int __init abyss_init (void)
35078 {
35079 - abyss_netdev_ops = tms380tr_netdev_ops;
35080 + pax_open_kernel();
35081 + memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35082
35083 - abyss_netdev_ops.ndo_open = abyss_open;
35084 - abyss_netdev_ops.ndo_stop = abyss_close;
35085 + *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
35086 + *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
35087 + pax_close_kernel();
35088
35089 return pci_register_driver(&abyss_driver);
35090 }
35091 diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
35092 index 28adcdf..ae82f35 100644
35093 --- a/drivers/net/tokenring/madgemc.c
35094 +++ b/drivers/net/tokenring/madgemc.c
35095 @@ -742,9 +742,11 @@ static struct mca_driver madgemc_driver = {
35096
35097 static int __init madgemc_init (void)
35098 {
35099 - madgemc_netdev_ops = tms380tr_netdev_ops;
35100 - madgemc_netdev_ops.ndo_open = madgemc_open;
35101 - madgemc_netdev_ops.ndo_stop = madgemc_close;
35102 + pax_open_kernel();
35103 + memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35104 + *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
35105 + *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
35106 + pax_close_kernel();
35107
35108 return mca_register_driver (&madgemc_driver);
35109 }
35110 diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
35111 index 62d90e4..9d84237 100644
35112 --- a/drivers/net/tokenring/proteon.c
35113 +++ b/drivers/net/tokenring/proteon.c
35114 @@ -352,9 +352,11 @@ static int __init proteon_init(void)
35115 struct platform_device *pdev;
35116 int i, num = 0, err = 0;
35117
35118 - proteon_netdev_ops = tms380tr_netdev_ops;
35119 - proteon_netdev_ops.ndo_open = proteon_open;
35120 - proteon_netdev_ops.ndo_stop = tms380tr_close;
35121 + pax_open_kernel();
35122 + memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35123 + *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
35124 + *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
35125 + pax_close_kernel();
35126
35127 err = platform_driver_register(&proteon_driver);
35128 if (err)
35129 diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
35130 index ee11e93..c8f19c7 100644
35131 --- a/drivers/net/tokenring/skisa.c
35132 +++ b/drivers/net/tokenring/skisa.c
35133 @@ -362,9 +362,11 @@ static int __init sk_isa_init(void)
35134 struct platform_device *pdev;
35135 int i, num = 0, err = 0;
35136
35137 - sk_isa_netdev_ops = tms380tr_netdev_ops;
35138 - sk_isa_netdev_ops.ndo_open = sk_isa_open;
35139 - sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35140 + pax_open_kernel();
35141 + memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35142 + *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
35143 + *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35144 + pax_close_kernel();
35145
35146 err = platform_driver_register(&sk_isa_driver);
35147 if (err)
35148 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35149 index 2d2a688..35f2372 100644
35150 --- a/drivers/net/usb/hso.c
35151 +++ b/drivers/net/usb/hso.c
35152 @@ -71,7 +71,7 @@
35153 #include <asm/byteorder.h>
35154 #include <linux/serial_core.h>
35155 #include <linux/serial.h>
35156 -
35157 +#include <asm/local.h>
35158
35159 #define MOD_AUTHOR "Option Wireless"
35160 #define MOD_DESCRIPTION "USB High Speed Option driver"
35161 @@ -257,7 +257,7 @@ struct hso_serial {
35162
35163 /* from usb_serial_port */
35164 struct tty_struct *tty;
35165 - int open_count;
35166 + local_t open_count;
35167 spinlock_t serial_lock;
35168
35169 int (*write_data) (struct hso_serial *serial);
35170 @@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35171 struct urb *urb;
35172
35173 urb = serial->rx_urb[0];
35174 - if (serial->open_count > 0) {
35175 + if (local_read(&serial->open_count) > 0) {
35176 count = put_rxbuf_data(urb, serial);
35177 if (count == -1)
35178 return;
35179 @@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35180 DUMP1(urb->transfer_buffer, urb->actual_length);
35181
35182 /* Anyone listening? */
35183 - if (serial->open_count == 0)
35184 + if (local_read(&serial->open_count) == 0)
35185 return;
35186
35187 if (status == 0) {
35188 @@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35189 spin_unlock_irq(&serial->serial_lock);
35190
35191 /* check for port already opened, if not set the termios */
35192 - serial->open_count++;
35193 - if (serial->open_count == 1) {
35194 + if (local_inc_return(&serial->open_count) == 1) {
35195 serial->rx_state = RX_IDLE;
35196 /* Force default termio settings */
35197 _hso_serial_set_termios(tty, NULL);
35198 @@ -1324,7 +1323,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35199 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35200 if (result) {
35201 hso_stop_serial_device(serial->parent);
35202 - serial->open_count--;
35203 + local_dec(&serial->open_count);
35204 kref_put(&serial->parent->ref, hso_serial_ref_free);
35205 }
35206 } else {
35207 @@ -1361,10 +1360,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35208
35209 /* reset the rts and dtr */
35210 /* do the actual close */
35211 - serial->open_count--;
35212 + local_dec(&serial->open_count);
35213
35214 - if (serial->open_count <= 0) {
35215 - serial->open_count = 0;
35216 + if (local_read(&serial->open_count) <= 0) {
35217 + local_set(&serial->open_count, 0);
35218 spin_lock_irq(&serial->serial_lock);
35219 if (serial->tty == tty) {
35220 serial->tty->driver_data = NULL;
35221 @@ -1446,7 +1445,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35222
35223 /* the actual setup */
35224 spin_lock_irqsave(&serial->serial_lock, flags);
35225 - if (serial->open_count)
35226 + if (local_read(&serial->open_count))
35227 _hso_serial_set_termios(tty, old);
35228 else
35229 tty->termios = old;
35230 @@ -1905,7 +1904,7 @@ static void intr_callback(struct urb *urb)
35231 D1("Pending read interrupt on port %d\n", i);
35232 spin_lock(&serial->serial_lock);
35233 if (serial->rx_state == RX_IDLE &&
35234 - serial->open_count > 0) {
35235 + local_read(&serial->open_count) > 0) {
35236 /* Setup and send a ctrl req read on
35237 * port i */
35238 if (!serial->rx_urb_filled[0]) {
35239 @@ -3098,7 +3097,7 @@ static int hso_resume(struct usb_interface *iface)
35240 /* Start all serial ports */
35241 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35242 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35243 - if (dev2ser(serial_table[i])->open_count) {
35244 + if (local_read(&dev2ser(serial_table[i])->open_count)) {
35245 result =
35246 hso_start_serial_device(serial_table[i], GFP_NOIO);
35247 hso_kick_transmit(dev2ser(serial_table[i]));
35248 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35249 index c54b7d37..af1f359 100644
35250 --- a/drivers/net/wireless/ath/ath.h
35251 +++ b/drivers/net/wireless/ath/ath.h
35252 @@ -119,6 +119,7 @@ struct ath_ops {
35253 void (*write_flush) (void *);
35254 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35255 };
35256 +typedef struct ath_ops __no_const ath_ops_no_const;
35257
35258 struct ath_common;
35259 struct ath_bus_ops;
35260 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35261 index aa2abaf..5f5152d 100644
35262 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35263 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35264 @@ -183,8 +183,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35265 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35266 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35267
35268 - ACCESS_ONCE(ads->ds_link) = i->link;
35269 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35270 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
35271 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35272
35273 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35274 ctl6 = SM(i->keytype, AR_EncrType);
35275 @@ -198,26 +198,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35276
35277 if ((i->is_first || i->is_last) &&
35278 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35279 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35280 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35281 | set11nTries(i->rates, 1)
35282 | set11nTries(i->rates, 2)
35283 | set11nTries(i->rates, 3)
35284 | (i->dur_update ? AR_DurUpdateEna : 0)
35285 | SM(0, AR_BurstDur);
35286
35287 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35288 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35289 | set11nRate(i->rates, 1)
35290 | set11nRate(i->rates, 2)
35291 | set11nRate(i->rates, 3);
35292 } else {
35293 - ACCESS_ONCE(ads->ds_ctl2) = 0;
35294 - ACCESS_ONCE(ads->ds_ctl3) = 0;
35295 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35296 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35297 }
35298
35299 if (!i->is_first) {
35300 - ACCESS_ONCE(ads->ds_ctl0) = 0;
35301 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35302 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35303 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35304 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35305 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35306 return;
35307 }
35308
35309 @@ -242,7 +242,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35310 break;
35311 }
35312
35313 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35314 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35315 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35316 | SM(i->txpower, AR_XmitPower)
35317 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35318 @@ -252,19 +252,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35319 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35320 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35321
35322 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35323 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35324 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35325 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35326
35327 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35328 return;
35329
35330 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35331 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35332 | set11nPktDurRTSCTS(i->rates, 1);
35333
35334 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35335 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35336 | set11nPktDurRTSCTS(i->rates, 3);
35337
35338 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35339 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35340 | set11nRateFlags(i->rates, 1)
35341 | set11nRateFlags(i->rates, 2)
35342 | set11nRateFlags(i->rates, 3)
35343 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35344 index a66a13b..0ef399e 100644
35345 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35346 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35347 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35348 (i->qcu << AR_TxQcuNum_S) | desc_len;
35349
35350 checksum += val;
35351 - ACCESS_ONCE(ads->info) = val;
35352 + ACCESS_ONCE_RW(ads->info) = val;
35353
35354 checksum += i->link;
35355 - ACCESS_ONCE(ads->link) = i->link;
35356 + ACCESS_ONCE_RW(ads->link) = i->link;
35357
35358 checksum += i->buf_addr[0];
35359 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35360 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35361 checksum += i->buf_addr[1];
35362 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35363 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35364 checksum += i->buf_addr[2];
35365 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35366 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35367 checksum += i->buf_addr[3];
35368 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35369 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35370
35371 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35372 - ACCESS_ONCE(ads->ctl3) = val;
35373 + ACCESS_ONCE_RW(ads->ctl3) = val;
35374 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35375 - ACCESS_ONCE(ads->ctl5) = val;
35376 + ACCESS_ONCE_RW(ads->ctl5) = val;
35377 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35378 - ACCESS_ONCE(ads->ctl7) = val;
35379 + ACCESS_ONCE_RW(ads->ctl7) = val;
35380 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35381 - ACCESS_ONCE(ads->ctl9) = val;
35382 + ACCESS_ONCE_RW(ads->ctl9) = val;
35383
35384 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35385 - ACCESS_ONCE(ads->ctl10) = checksum;
35386 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
35387
35388 if (i->is_first || i->is_last) {
35389 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35390 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35391 | set11nTries(i->rates, 1)
35392 | set11nTries(i->rates, 2)
35393 | set11nTries(i->rates, 3)
35394 | (i->dur_update ? AR_DurUpdateEna : 0)
35395 | SM(0, AR_BurstDur);
35396
35397 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35398 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35399 | set11nRate(i->rates, 1)
35400 | set11nRate(i->rates, 2)
35401 | set11nRate(i->rates, 3);
35402 } else {
35403 - ACCESS_ONCE(ads->ctl13) = 0;
35404 - ACCESS_ONCE(ads->ctl14) = 0;
35405 + ACCESS_ONCE_RW(ads->ctl13) = 0;
35406 + ACCESS_ONCE_RW(ads->ctl14) = 0;
35407 }
35408
35409 ads->ctl20 = 0;
35410 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35411
35412 ctl17 = SM(i->keytype, AR_EncrType);
35413 if (!i->is_first) {
35414 - ACCESS_ONCE(ads->ctl11) = 0;
35415 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35416 - ACCESS_ONCE(ads->ctl15) = 0;
35417 - ACCESS_ONCE(ads->ctl16) = 0;
35418 - ACCESS_ONCE(ads->ctl17) = ctl17;
35419 - ACCESS_ONCE(ads->ctl18) = 0;
35420 - ACCESS_ONCE(ads->ctl19) = 0;
35421 + ACCESS_ONCE_RW(ads->ctl11) = 0;
35422 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35423 + ACCESS_ONCE_RW(ads->ctl15) = 0;
35424 + ACCESS_ONCE_RW(ads->ctl16) = 0;
35425 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35426 + ACCESS_ONCE_RW(ads->ctl18) = 0;
35427 + ACCESS_ONCE_RW(ads->ctl19) = 0;
35428 return;
35429 }
35430
35431 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35432 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35433 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35434 | SM(i->txpower, AR_XmitPower)
35435 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35436 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35437 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35438 ctl12 |= SM(val, AR_PAPRDChainMask);
35439
35440 - ACCESS_ONCE(ads->ctl12) = ctl12;
35441 - ACCESS_ONCE(ads->ctl17) = ctl17;
35442 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35443 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35444
35445 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35446 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35447 | set11nPktDurRTSCTS(i->rates, 1);
35448
35449 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35450 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35451 | set11nPktDurRTSCTS(i->rates, 3);
35452
35453 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35454 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35455 | set11nRateFlags(i->rates, 1)
35456 | set11nRateFlags(i->rates, 2)
35457 | set11nRateFlags(i->rates, 3)
35458 | SM(i->rtscts_rate, AR_RTSCTSRate);
35459
35460 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35461 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35462 }
35463
35464 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35465 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35466 index e88f182..4e57f5d 100644
35467 --- a/drivers/net/wireless/ath/ath9k/hw.h
35468 +++ b/drivers/net/wireless/ath/ath9k/hw.h
35469 @@ -614,7 +614,7 @@ struct ath_hw_private_ops {
35470
35471 /* ANI */
35472 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35473 -};
35474 +} __no_const;
35475
35476 /**
35477 * struct ath_hw_ops - callbacks used by hardware code and driver code
35478 @@ -644,7 +644,7 @@ struct ath_hw_ops {
35479 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35480 struct ath_hw_antcomb_conf *antconf);
35481
35482 -};
35483 +} __no_const;
35484
35485 struct ath_nf_limits {
35486 s16 max;
35487 @@ -664,7 +664,7 @@ enum ath_cal_list {
35488 #define AH_FASTCC 0x4
35489
35490 struct ath_hw {
35491 - struct ath_ops reg_ops;
35492 + ath_ops_no_const reg_ops;
35493
35494 struct ieee80211_hw *hw;
35495 struct ath_common common;
35496 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35497 index af00e2c..ab04d34 100644
35498 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35499 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35500 @@ -545,7 +545,7 @@ struct phy_func_ptr {
35501 void (*carrsuppr)(struct brcms_phy *);
35502 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35503 void (*detach)(struct brcms_phy *);
35504 -};
35505 +} __no_const;
35506
35507 struct brcms_phy {
35508 struct brcms_phy_pub pubpi_ro;
35509 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35510 index faec404..a5277f1 100644
35511 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
35512 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35513 @@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35514 */
35515 if (il3945_mod_params.disable_hw_scan) {
35516 D_INFO("Disabling hw_scan\n");
35517 - il3945_mac_ops.hw_scan = NULL;
35518 + pax_open_kernel();
35519 + *(void **)&il3945_mac_ops.hw_scan = NULL;
35520 + pax_close_kernel();
35521 }
35522
35523 D_INFO("*** LOAD DRIVER ***\n");
35524 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35525 index b7ce6a6..5649756 100644
35526 --- a/drivers/net/wireless/mac80211_hwsim.c
35527 +++ b/drivers/net/wireless/mac80211_hwsim.c
35528 @@ -1721,9 +1721,11 @@ static int __init init_mac80211_hwsim(void)
35529 return -EINVAL;
35530
35531 if (fake_hw_scan) {
35532 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35533 - mac80211_hwsim_ops.sw_scan_start = NULL;
35534 - mac80211_hwsim_ops.sw_scan_complete = NULL;
35535 + pax_open_kernel();
35536 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35537 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35538 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35539 + pax_close_kernel();
35540 }
35541
35542 spin_lock_init(&hwsim_radio_lock);
35543 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35544 index 35225e9..95e6bf9 100644
35545 --- a/drivers/net/wireless/mwifiex/main.h
35546 +++ b/drivers/net/wireless/mwifiex/main.h
35547 @@ -537,7 +537,7 @@ struct mwifiex_if_ops {
35548 void (*cleanup_mpa_buf) (struct mwifiex_adapter *);
35549 int (*cmdrsp_complete) (struct mwifiex_adapter *, struct sk_buff *);
35550 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35551 -};
35552 +} __no_const;
35553
35554 struct mwifiex_adapter {
35555 u8 iface_type;
35556 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35557 index d66e298..55b0a89 100644
35558 --- a/drivers/net/wireless/rndis_wlan.c
35559 +++ b/drivers/net/wireless/rndis_wlan.c
35560 @@ -1278,7 +1278,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35561
35562 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35563
35564 - if (rts_threshold < 0 || rts_threshold > 2347)
35565 + if (rts_threshold > 2347)
35566 rts_threshold = 2347;
35567
35568 tmp = cpu_to_le32(rts_threshold);
35569 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
35570 index c264dfa..08ee30e 100644
35571 --- a/drivers/net/wireless/rt2x00/rt2x00.h
35572 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
35573 @@ -396,7 +396,7 @@ struct rt2x00_intf {
35574 * for hardware which doesn't support hardware
35575 * sequence counting.
35576 */
35577 - atomic_t seqno;
35578 + atomic_unchecked_t seqno;
35579 };
35580
35581 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
35582 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
35583 index 50f92d5..f3afc41 100644
35584 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
35585 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
35586 @@ -229,9 +229,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
35587 * sequence counter given by mac80211.
35588 */
35589 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
35590 - seqno = atomic_add_return(0x10, &intf->seqno);
35591 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
35592 else
35593 - seqno = atomic_read(&intf->seqno);
35594 + seqno = atomic_read_unchecked(&intf->seqno);
35595
35596 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
35597 hdr->seq_ctrl |= cpu_to_le16(seqno);
35598 diff --git a/drivers/net/wireless/wl1251/wl1251.h b/drivers/net/wireless/wl1251/wl1251.h
35599 index 9d8f581..0f6589e 100644
35600 --- a/drivers/net/wireless/wl1251/wl1251.h
35601 +++ b/drivers/net/wireless/wl1251/wl1251.h
35602 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
35603 void (*reset)(struct wl1251 *wl);
35604 void (*enable_irq)(struct wl1251 *wl);
35605 void (*disable_irq)(struct wl1251 *wl);
35606 -};
35607 +} __no_const;
35608
35609 struct wl1251 {
35610 struct ieee80211_hw *hw;
35611 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
35612 index f34b5b2..b5abb9f 100644
35613 --- a/drivers/oprofile/buffer_sync.c
35614 +++ b/drivers/oprofile/buffer_sync.c
35615 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
35616 if (cookie == NO_COOKIE)
35617 offset = pc;
35618 if (cookie == INVALID_COOKIE) {
35619 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35620 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35621 offset = pc;
35622 }
35623 if (cookie != last_cookie) {
35624 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
35625 /* add userspace sample */
35626
35627 if (!mm) {
35628 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
35629 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
35630 return 0;
35631 }
35632
35633 cookie = lookup_dcookie(mm, s->eip, &offset);
35634
35635 if (cookie == INVALID_COOKIE) {
35636 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35637 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35638 return 0;
35639 }
35640
35641 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
35642 /* ignore backtraces if failed to add a sample */
35643 if (state == sb_bt_start) {
35644 state = sb_bt_ignore;
35645 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
35646 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
35647 }
35648 }
35649 release_mm(mm);
35650 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
35651 index c0cc4e7..44d4e54 100644
35652 --- a/drivers/oprofile/event_buffer.c
35653 +++ b/drivers/oprofile/event_buffer.c
35654 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
35655 }
35656
35657 if (buffer_pos == buffer_size) {
35658 - atomic_inc(&oprofile_stats.event_lost_overflow);
35659 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
35660 return;
35661 }
35662
35663 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
35664 index ed2c3ec..deda85a 100644
35665 --- a/drivers/oprofile/oprof.c
35666 +++ b/drivers/oprofile/oprof.c
35667 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
35668 if (oprofile_ops.switch_events())
35669 return;
35670
35671 - atomic_inc(&oprofile_stats.multiplex_counter);
35672 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
35673 start_switch_worker();
35674 }
35675
35676 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
35677 index 917d28e..d62d981 100644
35678 --- a/drivers/oprofile/oprofile_stats.c
35679 +++ b/drivers/oprofile/oprofile_stats.c
35680 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
35681 cpu_buf->sample_invalid_eip = 0;
35682 }
35683
35684 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
35685 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
35686 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
35687 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
35688 - atomic_set(&oprofile_stats.multiplex_counter, 0);
35689 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
35690 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
35691 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
35692 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
35693 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
35694 }
35695
35696
35697 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
35698 index 38b6fc0..b5cbfce 100644
35699 --- a/drivers/oprofile/oprofile_stats.h
35700 +++ b/drivers/oprofile/oprofile_stats.h
35701 @@ -13,11 +13,11 @@
35702 #include <linux/atomic.h>
35703
35704 struct oprofile_stat_struct {
35705 - atomic_t sample_lost_no_mm;
35706 - atomic_t sample_lost_no_mapping;
35707 - atomic_t bt_lost_no_mapping;
35708 - atomic_t event_lost_overflow;
35709 - atomic_t multiplex_counter;
35710 + atomic_unchecked_t sample_lost_no_mm;
35711 + atomic_unchecked_t sample_lost_no_mapping;
35712 + atomic_unchecked_t bt_lost_no_mapping;
35713 + atomic_unchecked_t event_lost_overflow;
35714 + atomic_unchecked_t multiplex_counter;
35715 };
35716
35717 extern struct oprofile_stat_struct oprofile_stats;
35718 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
35719 index 849357c..b83c1e0 100644
35720 --- a/drivers/oprofile/oprofilefs.c
35721 +++ b/drivers/oprofile/oprofilefs.c
35722 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
35723
35724
35725 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
35726 - char const *name, atomic_t *val)
35727 + char const *name, atomic_unchecked_t *val)
35728 {
35729 return __oprofilefs_create_file(sb, root, name,
35730 &atomic_ro_fops, 0444, val);
35731 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
35732 index 3f56bc0..707d642 100644
35733 --- a/drivers/parport/procfs.c
35734 +++ b/drivers/parport/procfs.c
35735 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
35736
35737 *ppos += len;
35738
35739 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
35740 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
35741 }
35742
35743 #ifdef CONFIG_PARPORT_1284
35744 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
35745
35746 *ppos += len;
35747
35748 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
35749 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
35750 }
35751 #endif /* IEEE1284.3 support. */
35752
35753 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
35754 index 9fff878..ad0ad53 100644
35755 --- a/drivers/pci/hotplug/cpci_hotplug.h
35756 +++ b/drivers/pci/hotplug/cpci_hotplug.h
35757 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
35758 int (*hardware_test) (struct slot* slot, u32 value);
35759 u8 (*get_power) (struct slot* slot);
35760 int (*set_power) (struct slot* slot, int value);
35761 -};
35762 +} __no_const;
35763
35764 struct cpci_hp_controller {
35765 unsigned int irq;
35766 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
35767 index 76ba8a1..20ca857 100644
35768 --- a/drivers/pci/hotplug/cpqphp_nvram.c
35769 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
35770 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
35771
35772 void compaq_nvram_init (void __iomem *rom_start)
35773 {
35774 +
35775 +#ifndef CONFIG_PAX_KERNEXEC
35776 if (rom_start) {
35777 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
35778 }
35779 +#endif
35780 +
35781 dbg("int15 entry = %p\n", compaq_int15_entry_point);
35782
35783 /* initialize our int15 lock */
35784 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
35785 index b500840..d7159d3 100644
35786 --- a/drivers/pci/pcie/aspm.c
35787 +++ b/drivers/pci/pcie/aspm.c
35788 @@ -27,9 +27,9 @@
35789 #define MODULE_PARAM_PREFIX "pcie_aspm."
35790
35791 /* Note: those are not register definitions */
35792 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
35793 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
35794 -#define ASPM_STATE_L1 (4) /* L1 state */
35795 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
35796 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
35797 +#define ASPM_STATE_L1 (4U) /* L1 state */
35798 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
35799 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
35800
35801 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
35802 index 5e1ca3c..08082fe 100644
35803 --- a/drivers/pci/probe.c
35804 +++ b/drivers/pci/probe.c
35805 @@ -215,7 +215,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
35806 u16 orig_cmd;
35807 struct pci_bus_region region;
35808
35809 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
35810 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
35811
35812 if (!dev->mmio_always_on) {
35813 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
35814 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
35815 index 27911b5..5b6db88 100644
35816 --- a/drivers/pci/proc.c
35817 +++ b/drivers/pci/proc.c
35818 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
35819 static int __init pci_proc_init(void)
35820 {
35821 struct pci_dev *dev = NULL;
35822 +
35823 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
35824 +#ifdef CONFIG_GRKERNSEC_PROC_USER
35825 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
35826 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
35827 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
35828 +#endif
35829 +#else
35830 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
35831 +#endif
35832 proc_create("devices", 0, proc_bus_pci_dir,
35833 &proc_bus_pci_dev_operations);
35834 proc_initialized = 1;
35835 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
35836 index d68c000..f6094ca 100644
35837 --- a/drivers/platform/x86/thinkpad_acpi.c
35838 +++ b/drivers/platform/x86/thinkpad_acpi.c
35839 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
35840 return 0;
35841 }
35842
35843 -void static hotkey_mask_warn_incomplete_mask(void)
35844 +static void hotkey_mask_warn_incomplete_mask(void)
35845 {
35846 /* log only what the user can fix... */
35847 const u32 wantedmask = hotkey_driver_mask &
35848 @@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
35849 }
35850 }
35851
35852 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35853 - struct tp_nvram_state *newn,
35854 - const u32 event_mask)
35855 -{
35856 -
35857 #define TPACPI_COMPARE_KEY(__scancode, __member) \
35858 do { \
35859 if ((event_mask & (1 << __scancode)) && \
35860 @@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35861 tpacpi_hotkey_send_key(__scancode); \
35862 } while (0)
35863
35864 - void issue_volchange(const unsigned int oldvol,
35865 - const unsigned int newvol)
35866 - {
35867 - unsigned int i = oldvol;
35868 +static void issue_volchange(const unsigned int oldvol,
35869 + const unsigned int newvol,
35870 + const u32 event_mask)
35871 +{
35872 + unsigned int i = oldvol;
35873
35874 - while (i > newvol) {
35875 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35876 - i--;
35877 - }
35878 - while (i < newvol) {
35879 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35880 - i++;
35881 - }
35882 + while (i > newvol) {
35883 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35884 + i--;
35885 }
35886 + while (i < newvol) {
35887 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35888 + i++;
35889 + }
35890 +}
35891
35892 - void issue_brightnesschange(const unsigned int oldbrt,
35893 - const unsigned int newbrt)
35894 - {
35895 - unsigned int i = oldbrt;
35896 +static void issue_brightnesschange(const unsigned int oldbrt,
35897 + const unsigned int newbrt,
35898 + const u32 event_mask)
35899 +{
35900 + unsigned int i = oldbrt;
35901
35902 - while (i > newbrt) {
35903 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35904 - i--;
35905 - }
35906 - while (i < newbrt) {
35907 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35908 - i++;
35909 - }
35910 + while (i > newbrt) {
35911 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35912 + i--;
35913 + }
35914 + while (i < newbrt) {
35915 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35916 + i++;
35917 }
35918 +}
35919
35920 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35921 + struct tp_nvram_state *newn,
35922 + const u32 event_mask)
35923 +{
35924 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
35925 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
35926 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
35927 @@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35928 oldn->volume_level != newn->volume_level) {
35929 /* recently muted, or repeated mute keypress, or
35930 * multiple presses ending in mute */
35931 - issue_volchange(oldn->volume_level, newn->volume_level);
35932 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35933 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
35934 }
35935 } else {
35936 @@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35937 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35938 }
35939 if (oldn->volume_level != newn->volume_level) {
35940 - issue_volchange(oldn->volume_level, newn->volume_level);
35941 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35942 } else if (oldn->volume_toggle != newn->volume_toggle) {
35943 /* repeated vol up/down keypress at end of scale ? */
35944 if (newn->volume_level == 0)
35945 @@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35946 /* handle brightness */
35947 if (oldn->brightness_level != newn->brightness_level) {
35948 issue_brightnesschange(oldn->brightness_level,
35949 - newn->brightness_level);
35950 + newn->brightness_level,
35951 + event_mask);
35952 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
35953 /* repeated key presses that didn't change state */
35954 if (newn->brightness_level == 0)
35955 @@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35956 && !tp_features.bright_unkfw)
35957 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35958 }
35959 +}
35960
35961 #undef TPACPI_COMPARE_KEY
35962 #undef TPACPI_MAY_SEND_KEY
35963 -}
35964
35965 /*
35966 * Polling driver
35967 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
35968 index 769d265..a3a05ca 100644
35969 --- a/drivers/pnp/pnpbios/bioscalls.c
35970 +++ b/drivers/pnp/pnpbios/bioscalls.c
35971 @@ -58,7 +58,7 @@ do { \
35972 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
35973 } while(0)
35974
35975 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
35976 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
35977 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
35978
35979 /*
35980 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
35981
35982 cpu = get_cpu();
35983 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
35984 +
35985 + pax_open_kernel();
35986 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
35987 + pax_close_kernel();
35988
35989 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
35990 spin_lock_irqsave(&pnp_bios_lock, flags);
35991 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
35992 :"memory");
35993 spin_unlock_irqrestore(&pnp_bios_lock, flags);
35994
35995 + pax_open_kernel();
35996 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
35997 + pax_close_kernel();
35998 +
35999 put_cpu();
36000
36001 /* If we get here and this is set then the PnP BIOS faulted on us. */
36002 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36003 return status;
36004 }
36005
36006 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
36007 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36008 {
36009 int i;
36010
36011 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36012 pnp_bios_callpoint.offset = header->fields.pm16offset;
36013 pnp_bios_callpoint.segment = PNP_CS16;
36014
36015 + pax_open_kernel();
36016 +
36017 for_each_possible_cpu(i) {
36018 struct desc_struct *gdt = get_cpu_gdt_table(i);
36019 if (!gdt)
36020 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36021 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36022 (unsigned long)__va(header->fields.pm16dseg));
36023 }
36024 +
36025 + pax_close_kernel();
36026 }
36027 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36028 index b0ecacb..7c9da2e 100644
36029 --- a/drivers/pnp/resource.c
36030 +++ b/drivers/pnp/resource.c
36031 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36032 return 1;
36033
36034 /* check if the resource is valid */
36035 - if (*irq < 0 || *irq > 15)
36036 + if (*irq > 15)
36037 return 0;
36038
36039 /* check if the resource is reserved */
36040 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36041 return 1;
36042
36043 /* check if the resource is valid */
36044 - if (*dma < 0 || *dma == 4 || *dma > 7)
36045 + if (*dma == 4 || *dma > 7)
36046 return 0;
36047
36048 /* check if the resource is reserved */
36049 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36050 index 222ccd8..6275fa5 100644
36051 --- a/drivers/power/bq27x00_battery.c
36052 +++ b/drivers/power/bq27x00_battery.c
36053 @@ -72,7 +72,7 @@
36054 struct bq27x00_device_info;
36055 struct bq27x00_access_methods {
36056 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36057 -};
36058 +} __no_const;
36059
36060 enum bq27x00_chip { BQ27000, BQ27500 };
36061
36062 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36063 index 4c5b053..104263e 100644
36064 --- a/drivers/regulator/max8660.c
36065 +++ b/drivers/regulator/max8660.c
36066 @@ -385,8 +385,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36067 max8660->shadow_regs[MAX8660_OVER1] = 5;
36068 } else {
36069 /* Otherwise devices can be toggled via software */
36070 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
36071 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
36072 + pax_open_kernel();
36073 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36074 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36075 + pax_close_kernel();
36076 }
36077
36078 /*
36079 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36080 index 845aa22..99ec402 100644
36081 --- a/drivers/regulator/mc13892-regulator.c
36082 +++ b/drivers/regulator/mc13892-regulator.c
36083 @@ -574,10 +574,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36084 }
36085 mc13xxx_unlock(mc13892);
36086
36087 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36088 + pax_open_kernel();
36089 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36090 = mc13892_vcam_set_mode;
36091 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36092 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36093 = mc13892_vcam_get_mode;
36094 + pax_close_kernel();
36095
36096 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36097 ARRAY_SIZE(mc13892_regulators));
36098 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36099 index cace6d3..f623fda 100644
36100 --- a/drivers/rtc/rtc-dev.c
36101 +++ b/drivers/rtc/rtc-dev.c
36102 @@ -14,6 +14,7 @@
36103 #include <linux/module.h>
36104 #include <linux/rtc.h>
36105 #include <linux/sched.h>
36106 +#include <linux/grsecurity.h>
36107 #include "rtc-core.h"
36108
36109 static dev_t rtc_devt;
36110 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36111 if (copy_from_user(&tm, uarg, sizeof(tm)))
36112 return -EFAULT;
36113
36114 + gr_log_timechange();
36115 +
36116 return rtc_set_time(rtc, &tm);
36117
36118 case RTC_PIE_ON:
36119 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36120 index 3fcf627..f334910 100644
36121 --- a/drivers/scsi/aacraid/aacraid.h
36122 +++ b/drivers/scsi/aacraid/aacraid.h
36123 @@ -492,7 +492,7 @@ struct adapter_ops
36124 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36125 /* Administrative operations */
36126 int (*adapter_comm)(struct aac_dev * dev, int comm);
36127 -};
36128 +} __no_const;
36129
36130 /*
36131 * Define which interrupt handler needs to be installed
36132 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36133 index 0d279c44..3d25a97 100644
36134 --- a/drivers/scsi/aacraid/linit.c
36135 +++ b/drivers/scsi/aacraid/linit.c
36136 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36137 #elif defined(__devinitconst)
36138 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36139 #else
36140 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36141 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36142 #endif
36143 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36144 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36145 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36146 index ff80552..1c4120c 100644
36147 --- a/drivers/scsi/aic94xx/aic94xx_init.c
36148 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
36149 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36150 .lldd_ata_set_dmamode = asd_set_dmamode,
36151 };
36152
36153 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36154 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36155 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36156 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36157 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36158 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36159 index 4ad7e36..d004679 100644
36160 --- a/drivers/scsi/bfa/bfa.h
36161 +++ b/drivers/scsi/bfa/bfa.h
36162 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
36163 u32 *end);
36164 int cpe_vec_q0;
36165 int rme_vec_q0;
36166 -};
36167 +} __no_const;
36168 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36169
36170 struct bfa_faa_cbfn_s {
36171 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36172 index f0f80e2..8ec946b 100644
36173 --- a/drivers/scsi/bfa/bfa_fcpim.c
36174 +++ b/drivers/scsi/bfa/bfa_fcpim.c
36175 @@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36176
36177 bfa_iotag_attach(fcp);
36178
36179 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36180 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36181 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36182 (fcp->num_itns * sizeof(struct bfa_itn_s));
36183 memset(fcp->itn_arr, 0,
36184 @@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36185 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36186 {
36187 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36188 - struct bfa_itn_s *itn;
36189 + bfa_itn_s_no_const *itn;
36190
36191 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36192 itn->isr = isr;
36193 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36194 index 36f26da..38a34a8 100644
36195 --- a/drivers/scsi/bfa/bfa_fcpim.h
36196 +++ b/drivers/scsi/bfa/bfa_fcpim.h
36197 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
36198 struct bfa_itn_s {
36199 bfa_isr_func_t isr;
36200 };
36201 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36202
36203 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36204 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36205 @@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36206 struct list_head iotag_tio_free_q; /* free IO resources */
36207 struct list_head iotag_unused_q; /* unused IO resources*/
36208 struct bfa_iotag_s *iotag_arr;
36209 - struct bfa_itn_s *itn_arr;
36210 + bfa_itn_s_no_const *itn_arr;
36211 int num_ioim_reqs;
36212 int num_fwtio_reqs;
36213 int num_itns;
36214 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36215 index 1a99d4b..e85d64b 100644
36216 --- a/drivers/scsi/bfa/bfa_ioc.h
36217 +++ b/drivers/scsi/bfa/bfa_ioc.h
36218 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36219 bfa_ioc_disable_cbfn_t disable_cbfn;
36220 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36221 bfa_ioc_reset_cbfn_t reset_cbfn;
36222 -};
36223 +} __no_const;
36224
36225 /*
36226 * IOC event notification mechanism.
36227 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36228 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36229 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36230 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36231 -};
36232 +} __no_const;
36233
36234 /*
36235 * Queue element to wait for room in request queue. FIFO order is
36236 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36237 index a3a056a..b9bbc2f 100644
36238 --- a/drivers/scsi/hosts.c
36239 +++ b/drivers/scsi/hosts.c
36240 @@ -42,7 +42,7 @@
36241 #include "scsi_logging.h"
36242
36243
36244 -static atomic_t scsi_host_next_hn; /* host_no for next new host */
36245 +static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
36246
36247
36248 static void scsi_host_cls_release(struct device *dev)
36249 @@ -360,7 +360,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36250 * subtract one because we increment first then return, but we need to
36251 * know what the next host number was before increment
36252 */
36253 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36254 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36255 shost->dma_channel = 0xff;
36256
36257 /* These three are default values which can be overridden */
36258 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36259 index 500e20d..ebd3059 100644
36260 --- a/drivers/scsi/hpsa.c
36261 +++ b/drivers/scsi/hpsa.c
36262 @@ -521,7 +521,7 @@ static inline u32 next_command(struct ctlr_info *h)
36263 u32 a;
36264
36265 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36266 - return h->access.command_completed(h);
36267 + return h->access->command_completed(h);
36268
36269 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36270 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36271 @@ -3002,7 +3002,7 @@ static void start_io(struct ctlr_info *h)
36272 while (!list_empty(&h->reqQ)) {
36273 c = list_entry(h->reqQ.next, struct CommandList, list);
36274 /* can't do anything if fifo is full */
36275 - if ((h->access.fifo_full(h))) {
36276 + if ((h->access->fifo_full(h))) {
36277 dev_warn(&h->pdev->dev, "fifo full\n");
36278 break;
36279 }
36280 @@ -3012,7 +3012,7 @@ static void start_io(struct ctlr_info *h)
36281 h->Qdepth--;
36282
36283 /* Tell the controller execute command */
36284 - h->access.submit_command(h, c);
36285 + h->access->submit_command(h, c);
36286
36287 /* Put job onto the completed Q */
36288 addQ(&h->cmpQ, c);
36289 @@ -3021,17 +3021,17 @@ static void start_io(struct ctlr_info *h)
36290
36291 static inline unsigned long get_next_completion(struct ctlr_info *h)
36292 {
36293 - return h->access.command_completed(h);
36294 + return h->access->command_completed(h);
36295 }
36296
36297 static inline bool interrupt_pending(struct ctlr_info *h)
36298 {
36299 - return h->access.intr_pending(h);
36300 + return h->access->intr_pending(h);
36301 }
36302
36303 static inline long interrupt_not_for_us(struct ctlr_info *h)
36304 {
36305 - return (h->access.intr_pending(h) == 0) ||
36306 + return (h->access->intr_pending(h) == 0) ||
36307 (h->interrupts_enabled == 0);
36308 }
36309
36310 @@ -3930,7 +3930,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36311 if (prod_index < 0)
36312 return -ENODEV;
36313 h->product_name = products[prod_index].product_name;
36314 - h->access = *(products[prod_index].access);
36315 + h->access = products[prod_index].access;
36316
36317 if (hpsa_board_disabled(h->pdev)) {
36318 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36319 @@ -4175,7 +4175,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36320
36321 assert_spin_locked(&lockup_detector_lock);
36322 remove_ctlr_from_lockup_detector_list(h);
36323 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36324 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36325 spin_lock_irqsave(&h->lock, flags);
36326 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36327 spin_unlock_irqrestore(&h->lock, flags);
36328 @@ -4355,7 +4355,7 @@ reinit_after_soft_reset:
36329 }
36330
36331 /* make sure the board interrupts are off */
36332 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36333 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36334
36335 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36336 goto clean2;
36337 @@ -4389,7 +4389,7 @@ reinit_after_soft_reset:
36338 * fake ones to scoop up any residual completions.
36339 */
36340 spin_lock_irqsave(&h->lock, flags);
36341 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36342 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36343 spin_unlock_irqrestore(&h->lock, flags);
36344 free_irq(h->intr[h->intr_mode], h);
36345 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36346 @@ -4408,9 +4408,9 @@ reinit_after_soft_reset:
36347 dev_info(&h->pdev->dev, "Board READY.\n");
36348 dev_info(&h->pdev->dev,
36349 "Waiting for stale completions to drain.\n");
36350 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36351 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36352 msleep(10000);
36353 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36354 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36355
36356 rc = controller_reset_failed(h->cfgtable);
36357 if (rc)
36358 @@ -4431,7 +4431,7 @@ reinit_after_soft_reset:
36359 }
36360
36361 /* Turn the interrupts on so we can service requests */
36362 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36363 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36364
36365 hpsa_hba_inquiry(h);
36366 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36367 @@ -4483,7 +4483,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36368 * To write all data in the battery backed cache to disks
36369 */
36370 hpsa_flush_cache(h);
36371 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36372 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36373 free_irq(h->intr[h->intr_mode], h);
36374 #ifdef CONFIG_PCI_MSI
36375 if (h->msix_vector)
36376 @@ -4657,7 +4657,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36377 return;
36378 }
36379 /* Change the access methods to the performant access methods */
36380 - h->access = SA5_performant_access;
36381 + h->access = &SA5_performant_access;
36382 h->transMethod = CFGTBL_Trans_Performant;
36383 }
36384
36385 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36386 index 7b28d54..952f23a 100644
36387 --- a/drivers/scsi/hpsa.h
36388 +++ b/drivers/scsi/hpsa.h
36389 @@ -72,7 +72,7 @@ struct ctlr_info {
36390 unsigned int msix_vector;
36391 unsigned int msi_vector;
36392 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36393 - struct access_method access;
36394 + struct access_method *access;
36395
36396 /* queue and queue Info */
36397 struct list_head reqQ;
36398 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36399 index f2df059..a3a9930 100644
36400 --- a/drivers/scsi/ips.h
36401 +++ b/drivers/scsi/ips.h
36402 @@ -1027,7 +1027,7 @@ typedef struct {
36403 int (*intr)(struct ips_ha *);
36404 void (*enableint)(struct ips_ha *);
36405 uint32_t (*statupd)(struct ips_ha *);
36406 -} ips_hw_func_t;
36407 +} __no_const ips_hw_func_t;
36408
36409 typedef struct ips_ha {
36410 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36411 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36412 index aceffad..c35c08d 100644
36413 --- a/drivers/scsi/libfc/fc_exch.c
36414 +++ b/drivers/scsi/libfc/fc_exch.c
36415 @@ -105,12 +105,12 @@ struct fc_exch_mgr {
36416 * all together if not used XXX
36417 */
36418 struct {
36419 - atomic_t no_free_exch;
36420 - atomic_t no_free_exch_xid;
36421 - atomic_t xid_not_found;
36422 - atomic_t xid_busy;
36423 - atomic_t seq_not_found;
36424 - atomic_t non_bls_resp;
36425 + atomic_unchecked_t no_free_exch;
36426 + atomic_unchecked_t no_free_exch_xid;
36427 + atomic_unchecked_t xid_not_found;
36428 + atomic_unchecked_t xid_busy;
36429 + atomic_unchecked_t seq_not_found;
36430 + atomic_unchecked_t non_bls_resp;
36431 } stats;
36432 };
36433
36434 @@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36435 /* allocate memory for exchange */
36436 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36437 if (!ep) {
36438 - atomic_inc(&mp->stats.no_free_exch);
36439 + atomic_inc_unchecked(&mp->stats.no_free_exch);
36440 goto out;
36441 }
36442 memset(ep, 0, sizeof(*ep));
36443 @@ -780,7 +780,7 @@ out:
36444 return ep;
36445 err:
36446 spin_unlock_bh(&pool->lock);
36447 - atomic_inc(&mp->stats.no_free_exch_xid);
36448 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36449 mempool_free(ep, mp->ep_pool);
36450 return NULL;
36451 }
36452 @@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36453 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36454 ep = fc_exch_find(mp, xid);
36455 if (!ep) {
36456 - atomic_inc(&mp->stats.xid_not_found);
36457 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36458 reject = FC_RJT_OX_ID;
36459 goto out;
36460 }
36461 @@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36462 ep = fc_exch_find(mp, xid);
36463 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36464 if (ep) {
36465 - atomic_inc(&mp->stats.xid_busy);
36466 + atomic_inc_unchecked(&mp->stats.xid_busy);
36467 reject = FC_RJT_RX_ID;
36468 goto rel;
36469 }
36470 @@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36471 }
36472 xid = ep->xid; /* get our XID */
36473 } else if (!ep) {
36474 - atomic_inc(&mp->stats.xid_not_found);
36475 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36476 reject = FC_RJT_RX_ID; /* XID not found */
36477 goto out;
36478 }
36479 @@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36480 } else {
36481 sp = &ep->seq;
36482 if (sp->id != fh->fh_seq_id) {
36483 - atomic_inc(&mp->stats.seq_not_found);
36484 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36485 if (f_ctl & FC_FC_END_SEQ) {
36486 /*
36487 * Update sequence_id based on incoming last
36488 @@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36489
36490 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36491 if (!ep) {
36492 - atomic_inc(&mp->stats.xid_not_found);
36493 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36494 goto out;
36495 }
36496 if (ep->esb_stat & ESB_ST_COMPLETE) {
36497 - atomic_inc(&mp->stats.xid_not_found);
36498 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36499 goto rel;
36500 }
36501 if (ep->rxid == FC_XID_UNKNOWN)
36502 ep->rxid = ntohs(fh->fh_rx_id);
36503 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36504 - atomic_inc(&mp->stats.xid_not_found);
36505 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36506 goto rel;
36507 }
36508 if (ep->did != ntoh24(fh->fh_s_id) &&
36509 ep->did != FC_FID_FLOGI) {
36510 - atomic_inc(&mp->stats.xid_not_found);
36511 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36512 goto rel;
36513 }
36514 sof = fr_sof(fp);
36515 @@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36516 sp->ssb_stat |= SSB_ST_RESP;
36517 sp->id = fh->fh_seq_id;
36518 } else if (sp->id != fh->fh_seq_id) {
36519 - atomic_inc(&mp->stats.seq_not_found);
36520 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36521 goto rel;
36522 }
36523
36524 @@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36525 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36526
36527 if (!sp)
36528 - atomic_inc(&mp->stats.xid_not_found);
36529 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36530 else
36531 - atomic_inc(&mp->stats.non_bls_resp);
36532 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
36533
36534 fc_frame_free(fp);
36535 }
36536 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36537 index 441d88a..689ad71 100644
36538 --- a/drivers/scsi/libsas/sas_ata.c
36539 +++ b/drivers/scsi/libsas/sas_ata.c
36540 @@ -529,7 +529,7 @@ static struct ata_port_operations sas_sata_ops = {
36541 .postreset = ata_std_postreset,
36542 .error_handler = ata_std_error_handler,
36543 .post_internal_cmd = sas_ata_post_internal,
36544 - .qc_defer = ata_std_qc_defer,
36545 + .qc_defer = ata_std_qc_defer,
36546 .qc_prep = ata_noop_qc_prep,
36547 .qc_issue = sas_ata_qc_issue,
36548 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36549 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36550 index 3a1ffdd..8eb7c71 100644
36551 --- a/drivers/scsi/lpfc/lpfc.h
36552 +++ b/drivers/scsi/lpfc/lpfc.h
36553 @@ -413,7 +413,7 @@ struct lpfc_vport {
36554 struct dentry *debug_nodelist;
36555 struct dentry *vport_debugfs_root;
36556 struct lpfc_debugfs_trc *disc_trc;
36557 - atomic_t disc_trc_cnt;
36558 + atomic_unchecked_t disc_trc_cnt;
36559 #endif
36560 uint8_t stat_data_enabled;
36561 uint8_t stat_data_blocked;
36562 @@ -826,8 +826,8 @@ struct lpfc_hba {
36563 struct timer_list fabric_block_timer;
36564 unsigned long bit_flags;
36565 #define FABRIC_COMANDS_BLOCKED 0
36566 - atomic_t num_rsrc_err;
36567 - atomic_t num_cmd_success;
36568 + atomic_unchecked_t num_rsrc_err;
36569 + atomic_unchecked_t num_cmd_success;
36570 unsigned long last_rsrc_error_time;
36571 unsigned long last_ramp_down_time;
36572 unsigned long last_ramp_up_time;
36573 @@ -863,7 +863,7 @@ struct lpfc_hba {
36574
36575 struct dentry *debug_slow_ring_trc;
36576 struct lpfc_debugfs_trc *slow_ring_trc;
36577 - atomic_t slow_ring_trc_cnt;
36578 + atomic_unchecked_t slow_ring_trc_cnt;
36579 /* iDiag debugfs sub-directory */
36580 struct dentry *idiag_root;
36581 struct dentry *idiag_pci_cfg;
36582 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
36583 index af04b0d..8f1a97e 100644
36584 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
36585 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
36586 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
36587
36588 #include <linux/debugfs.h>
36589
36590 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36591 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36592 static unsigned long lpfc_debugfs_start_time = 0L;
36593
36594 /* iDiag */
36595 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
36596 lpfc_debugfs_enable = 0;
36597
36598 len = 0;
36599 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
36600 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
36601 (lpfc_debugfs_max_disc_trc - 1);
36602 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
36603 dtp = vport->disc_trc + i;
36604 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
36605 lpfc_debugfs_enable = 0;
36606
36607 len = 0;
36608 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
36609 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
36610 (lpfc_debugfs_max_slow_ring_trc - 1);
36611 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
36612 dtp = phba->slow_ring_trc + i;
36613 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
36614 !vport || !vport->disc_trc)
36615 return;
36616
36617 - index = atomic_inc_return(&vport->disc_trc_cnt) &
36618 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
36619 (lpfc_debugfs_max_disc_trc - 1);
36620 dtp = vport->disc_trc + index;
36621 dtp->fmt = fmt;
36622 dtp->data1 = data1;
36623 dtp->data2 = data2;
36624 dtp->data3 = data3;
36625 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36626 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36627 dtp->jif = jiffies;
36628 #endif
36629 return;
36630 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
36631 !phba || !phba->slow_ring_trc)
36632 return;
36633
36634 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
36635 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
36636 (lpfc_debugfs_max_slow_ring_trc - 1);
36637 dtp = phba->slow_ring_trc + index;
36638 dtp->fmt = fmt;
36639 dtp->data1 = data1;
36640 dtp->data2 = data2;
36641 dtp->data3 = data3;
36642 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36643 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36644 dtp->jif = jiffies;
36645 #endif
36646 return;
36647 @@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36648 "slow_ring buffer\n");
36649 goto debug_failed;
36650 }
36651 - atomic_set(&phba->slow_ring_trc_cnt, 0);
36652 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
36653 memset(phba->slow_ring_trc, 0,
36654 (sizeof(struct lpfc_debugfs_trc) *
36655 lpfc_debugfs_max_slow_ring_trc));
36656 @@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36657 "buffer\n");
36658 goto debug_failed;
36659 }
36660 - atomic_set(&vport->disc_trc_cnt, 0);
36661 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
36662
36663 snprintf(name, sizeof(name), "discovery_trace");
36664 vport->debug_disc_trc =
36665 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
36666 index 9598fdc..7e9f3d9 100644
36667 --- a/drivers/scsi/lpfc/lpfc_init.c
36668 +++ b/drivers/scsi/lpfc/lpfc_init.c
36669 @@ -10266,8 +10266,10 @@ lpfc_init(void)
36670 "misc_register returned with status %d", error);
36671
36672 if (lpfc_enable_npiv) {
36673 - lpfc_transport_functions.vport_create = lpfc_vport_create;
36674 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36675 + pax_open_kernel();
36676 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
36677 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36678 + pax_close_kernel();
36679 }
36680 lpfc_transport_template =
36681 fc_attach_transport(&lpfc_transport_functions);
36682 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
36683 index 88f3a83..686d3fa 100644
36684 --- a/drivers/scsi/lpfc/lpfc_scsi.c
36685 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
36686 @@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
36687 uint32_t evt_posted;
36688
36689 spin_lock_irqsave(&phba->hbalock, flags);
36690 - atomic_inc(&phba->num_rsrc_err);
36691 + atomic_inc_unchecked(&phba->num_rsrc_err);
36692 phba->last_rsrc_error_time = jiffies;
36693
36694 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
36695 @@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
36696 unsigned long flags;
36697 struct lpfc_hba *phba = vport->phba;
36698 uint32_t evt_posted;
36699 - atomic_inc(&phba->num_cmd_success);
36700 + atomic_inc_unchecked(&phba->num_cmd_success);
36701
36702 if (vport->cfg_lun_queue_depth <= queue_depth)
36703 return;
36704 @@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36705 unsigned long num_rsrc_err, num_cmd_success;
36706 int i;
36707
36708 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
36709 - num_cmd_success = atomic_read(&phba->num_cmd_success);
36710 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
36711 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
36712
36713 vports = lpfc_create_vport_work_array(phba);
36714 if (vports != NULL)
36715 @@ -417,8 +417,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36716 }
36717 }
36718 lpfc_destroy_vport_work_array(phba, vports);
36719 - atomic_set(&phba->num_rsrc_err, 0);
36720 - atomic_set(&phba->num_cmd_success, 0);
36721 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
36722 + atomic_set_unchecked(&phba->num_cmd_success, 0);
36723 }
36724
36725 /**
36726 @@ -452,8 +452,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
36727 }
36728 }
36729 lpfc_destroy_vport_work_array(phba, vports);
36730 - atomic_set(&phba->num_rsrc_err, 0);
36731 - atomic_set(&phba->num_cmd_success, 0);
36732 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
36733 + atomic_set_unchecked(&phba->num_cmd_success, 0);
36734 }
36735
36736 /**
36737 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
36738 index ea8a0b4..812a124 100644
36739 --- a/drivers/scsi/pmcraid.c
36740 +++ b/drivers/scsi/pmcraid.c
36741 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
36742 res->scsi_dev = scsi_dev;
36743 scsi_dev->hostdata = res;
36744 res->change_detected = 0;
36745 - atomic_set(&res->read_failures, 0);
36746 - atomic_set(&res->write_failures, 0);
36747 + atomic_set_unchecked(&res->read_failures, 0);
36748 + atomic_set_unchecked(&res->write_failures, 0);
36749 rc = 0;
36750 }
36751 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
36752 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
36753
36754 /* If this was a SCSI read/write command keep count of errors */
36755 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
36756 - atomic_inc(&res->read_failures);
36757 + atomic_inc_unchecked(&res->read_failures);
36758 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
36759 - atomic_inc(&res->write_failures);
36760 + atomic_inc_unchecked(&res->write_failures);
36761
36762 if (!RES_IS_GSCSI(res->cfg_entry) &&
36763 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
36764 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
36765 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36766 * hrrq_id assigned here in queuecommand
36767 */
36768 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36769 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36770 pinstance->num_hrrq;
36771 cmd->cmd_done = pmcraid_io_done;
36772
36773 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
36774 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36775 * hrrq_id assigned here in queuecommand
36776 */
36777 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36778 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36779 pinstance->num_hrrq;
36780
36781 if (request_size) {
36782 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
36783
36784 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
36785 /* add resources only after host is added into system */
36786 - if (!atomic_read(&pinstance->expose_resources))
36787 + if (!atomic_read_unchecked(&pinstance->expose_resources))
36788 return;
36789
36790 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
36791 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
36792 init_waitqueue_head(&pinstance->reset_wait_q);
36793
36794 atomic_set(&pinstance->outstanding_cmds, 0);
36795 - atomic_set(&pinstance->last_message_id, 0);
36796 - atomic_set(&pinstance->expose_resources, 0);
36797 + atomic_set_unchecked(&pinstance->last_message_id, 0);
36798 + atomic_set_unchecked(&pinstance->expose_resources, 0);
36799
36800 INIT_LIST_HEAD(&pinstance->free_res_q);
36801 INIT_LIST_HEAD(&pinstance->used_res_q);
36802 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
36803 /* Schedule worker thread to handle CCN and take care of adding and
36804 * removing devices to OS
36805 */
36806 - atomic_set(&pinstance->expose_resources, 1);
36807 + atomic_set_unchecked(&pinstance->expose_resources, 1);
36808 schedule_work(&pinstance->worker_q);
36809 return rc;
36810
36811 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
36812 index e1d150f..6c6df44 100644
36813 --- a/drivers/scsi/pmcraid.h
36814 +++ b/drivers/scsi/pmcraid.h
36815 @@ -748,7 +748,7 @@ struct pmcraid_instance {
36816 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
36817
36818 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
36819 - atomic_t last_message_id;
36820 + atomic_unchecked_t last_message_id;
36821
36822 /* configuration table */
36823 struct pmcraid_config_table *cfg_table;
36824 @@ -777,7 +777,7 @@ struct pmcraid_instance {
36825 atomic_t outstanding_cmds;
36826
36827 /* should add/delete resources to mid-layer now ?*/
36828 - atomic_t expose_resources;
36829 + atomic_unchecked_t expose_resources;
36830
36831
36832
36833 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
36834 struct pmcraid_config_table_entry_ext cfg_entry_ext;
36835 };
36836 struct scsi_device *scsi_dev; /* Link scsi_device structure */
36837 - atomic_t read_failures; /* count of failed READ commands */
36838 - atomic_t write_failures; /* count of failed WRITE commands */
36839 + atomic_unchecked_t read_failures; /* count of failed READ commands */
36840 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
36841
36842 /* To indicate add/delete/modify during CCN */
36843 u8 change_detected;
36844 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
36845 index a244303..6015eb7 100644
36846 --- a/drivers/scsi/qla2xxx/qla_def.h
36847 +++ b/drivers/scsi/qla2xxx/qla_def.h
36848 @@ -2264,7 +2264,7 @@ struct isp_operations {
36849 int (*start_scsi) (srb_t *);
36850 int (*abort_isp) (struct scsi_qla_host *);
36851 int (*iospace_config)(struct qla_hw_data*);
36852 -};
36853 +} __no_const;
36854
36855 /* MSI-X Support *************************************************************/
36856
36857 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
36858 index 7f2492e..5113877 100644
36859 --- a/drivers/scsi/qla4xxx/ql4_def.h
36860 +++ b/drivers/scsi/qla4xxx/ql4_def.h
36861 @@ -268,7 +268,7 @@ struct ddb_entry {
36862 * (4000 only) */
36863 atomic_t relogin_timer; /* Max Time to wait for
36864 * relogin to complete */
36865 - atomic_t relogin_retry_count; /* Num of times relogin has been
36866 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
36867 * retried */
36868 uint32_t default_time2wait; /* Default Min time between
36869 * relogins (+aens) */
36870 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
36871 index ee47820..a83b1f4 100644
36872 --- a/drivers/scsi/qla4xxx/ql4_os.c
36873 +++ b/drivers/scsi/qla4xxx/ql4_os.c
36874 @@ -2551,12 +2551,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
36875 */
36876 if (!iscsi_is_session_online(cls_sess)) {
36877 /* Reset retry relogin timer */
36878 - atomic_inc(&ddb_entry->relogin_retry_count);
36879 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
36880 DEBUG2(ql4_printk(KERN_INFO, ha,
36881 "%s: index[%d] relogin timed out-retrying"
36882 " relogin (%d), retry (%d)\n", __func__,
36883 ddb_entry->fw_ddb_index,
36884 - atomic_read(&ddb_entry->relogin_retry_count),
36885 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
36886 ddb_entry->default_time2wait + 4));
36887 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
36888 atomic_set(&ddb_entry->retry_relogin_timer,
36889 @@ -4453,7 +4453,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
36890
36891 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
36892 atomic_set(&ddb_entry->relogin_timer, 0);
36893 - atomic_set(&ddb_entry->relogin_retry_count, 0);
36894 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
36895 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
36896 ddb_entry->default_relogin_timeout =
36897 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
36898 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
36899 index 07322ec..91ccc23 100644
36900 --- a/drivers/scsi/scsi.c
36901 +++ b/drivers/scsi/scsi.c
36902 @@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
36903 unsigned long timeout;
36904 int rtn = 0;
36905
36906 - atomic_inc(&cmd->device->iorequest_cnt);
36907 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36908
36909 /* check if the device is still usable */
36910 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
36911 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
36912 index 4037fd5..a19fcc7 100644
36913 --- a/drivers/scsi/scsi_lib.c
36914 +++ b/drivers/scsi/scsi_lib.c
36915 @@ -1415,7 +1415,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
36916 shost = sdev->host;
36917 scsi_init_cmd_errh(cmd);
36918 cmd->result = DID_NO_CONNECT << 16;
36919 - atomic_inc(&cmd->device->iorequest_cnt);
36920 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36921
36922 /*
36923 * SCSI request completion path will do scsi_device_unbusy(),
36924 @@ -1441,9 +1441,9 @@ static void scsi_softirq_done(struct request *rq)
36925
36926 INIT_LIST_HEAD(&cmd->eh_entry);
36927
36928 - atomic_inc(&cmd->device->iodone_cnt);
36929 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
36930 if (cmd->result)
36931 - atomic_inc(&cmd->device->ioerr_cnt);
36932 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
36933
36934 disposition = scsi_decide_disposition(cmd);
36935 if (disposition != SUCCESS &&
36936 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
36937 index 04c2a27..9d8bd66 100644
36938 --- a/drivers/scsi/scsi_sysfs.c
36939 +++ b/drivers/scsi/scsi_sysfs.c
36940 @@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
36941 char *buf) \
36942 { \
36943 struct scsi_device *sdev = to_scsi_device(dev); \
36944 - unsigned long long count = atomic_read(&sdev->field); \
36945 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
36946 return snprintf(buf, 20, "0x%llx\n", count); \
36947 } \
36948 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
36949 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
36950 index 84a1fdf..693b0d6 100644
36951 --- a/drivers/scsi/scsi_tgt_lib.c
36952 +++ b/drivers/scsi/scsi_tgt_lib.c
36953 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
36954 int err;
36955
36956 dprintk("%lx %u\n", uaddr, len);
36957 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
36958 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
36959 if (err) {
36960 /*
36961 * TODO: need to fixup sg_tablesize, max_segment_size,
36962 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
36963 index 80fbe2a..efa223b 100644
36964 --- a/drivers/scsi/scsi_transport_fc.c
36965 +++ b/drivers/scsi/scsi_transport_fc.c
36966 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
36967 * Netlink Infrastructure
36968 */
36969
36970 -static atomic_t fc_event_seq;
36971 +static atomic_unchecked_t fc_event_seq;
36972
36973 /**
36974 * fc_get_event_number - Obtain the next sequential FC event number
36975 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
36976 u32
36977 fc_get_event_number(void)
36978 {
36979 - return atomic_add_return(1, &fc_event_seq);
36980 + return atomic_add_return_unchecked(1, &fc_event_seq);
36981 }
36982 EXPORT_SYMBOL(fc_get_event_number);
36983
36984 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
36985 {
36986 int error;
36987
36988 - atomic_set(&fc_event_seq, 0);
36989 + atomic_set_unchecked(&fc_event_seq, 0);
36990
36991 error = transport_class_register(&fc_host_class);
36992 if (error)
36993 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
36994 char *cp;
36995
36996 *val = simple_strtoul(buf, &cp, 0);
36997 - if ((*cp && (*cp != '\n')) || (*val < 0))
36998 + if (*cp && (*cp != '\n'))
36999 return -EINVAL;
37000 /*
37001 * Check for overflow; dev_loss_tmo is u32
37002 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37003 index 1cf640e..78e9014 100644
37004 --- a/drivers/scsi/scsi_transport_iscsi.c
37005 +++ b/drivers/scsi/scsi_transport_iscsi.c
37006 @@ -79,7 +79,7 @@ struct iscsi_internal {
37007 struct transport_container session_cont;
37008 };
37009
37010 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37011 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37012 static struct workqueue_struct *iscsi_eh_timer_workq;
37013
37014 static DEFINE_IDA(iscsi_sess_ida);
37015 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37016 int err;
37017
37018 ihost = shost->shost_data;
37019 - session->sid = atomic_add_return(1, &iscsi_session_nr);
37020 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37021
37022 if (target_id == ISCSI_MAX_TARGET) {
37023 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37024 @@ -2940,7 +2940,7 @@ static __init int iscsi_transport_init(void)
37025 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37026 ISCSI_TRANSPORT_VERSION);
37027
37028 - atomic_set(&iscsi_session_nr, 0);
37029 + atomic_set_unchecked(&iscsi_session_nr, 0);
37030
37031 err = class_register(&iscsi_transport_class);
37032 if (err)
37033 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37034 index 21a045e..ec89e03 100644
37035 --- a/drivers/scsi/scsi_transport_srp.c
37036 +++ b/drivers/scsi/scsi_transport_srp.c
37037 @@ -33,7 +33,7 @@
37038 #include "scsi_transport_srp_internal.h"
37039
37040 struct srp_host_attrs {
37041 - atomic_t next_port_id;
37042 + atomic_unchecked_t next_port_id;
37043 };
37044 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37045
37046 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37047 struct Scsi_Host *shost = dev_to_shost(dev);
37048 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37049
37050 - atomic_set(&srp_host->next_port_id, 0);
37051 + atomic_set_unchecked(&srp_host->next_port_id, 0);
37052 return 0;
37053 }
37054
37055 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37056 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37057 rport->roles = ids->roles;
37058
37059 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37060 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37061 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37062
37063 transport_setup_device(&rport->dev);
37064 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37065 index eacd46b..e3f4d62 100644
37066 --- a/drivers/scsi/sg.c
37067 +++ b/drivers/scsi/sg.c
37068 @@ -1077,7 +1077,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37069 sdp->disk->disk_name,
37070 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37071 NULL,
37072 - (char *)arg);
37073 + (char __user *)arg);
37074 case BLKTRACESTART:
37075 return blk_trace_startstop(sdp->device->request_queue, 1);
37076 case BLKTRACESTOP:
37077 @@ -2312,7 +2312,7 @@ struct sg_proc_leaf {
37078 const struct file_operations * fops;
37079 };
37080
37081 -static struct sg_proc_leaf sg_proc_leaf_arr[] = {
37082 +static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
37083 {"allow_dio", &adio_fops},
37084 {"debug", &debug_fops},
37085 {"def_reserved_size", &dressz_fops},
37086 @@ -2332,7 +2332,7 @@ sg_proc_init(void)
37087 if (!sg_proc_sgp)
37088 return 1;
37089 for (k = 0; k < num_leaves; ++k) {
37090 - struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
37091 + const struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
37092 umode_t mask = leaf->fops->write ? S_IRUGO | S_IWUSR : S_IRUGO;
37093 proc_create(leaf->name, mask, sg_proc_sgp, leaf->fops);
37094 }
37095 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37096 index 3d8f662..070f1a5 100644
37097 --- a/drivers/spi/spi.c
37098 +++ b/drivers/spi/spi.c
37099 @@ -1361,7 +1361,7 @@ int spi_bus_unlock(struct spi_master *master)
37100 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37101
37102 /* portable code must never pass more than 32 bytes */
37103 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37104 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37105
37106 static u8 *buf;
37107
37108 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37109 index d91751f..a3a9e36 100644
37110 --- a/drivers/staging/octeon/ethernet-rx.c
37111 +++ b/drivers/staging/octeon/ethernet-rx.c
37112 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37113 /* Increment RX stats for virtual ports */
37114 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37115 #ifdef CONFIG_64BIT
37116 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37117 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37118 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37119 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37120 #else
37121 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37122 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37123 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37124 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37125 #endif
37126 }
37127 netif_receive_skb(skb);
37128 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37129 dev->name);
37130 */
37131 #ifdef CONFIG_64BIT
37132 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37133 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37134 #else
37135 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37136 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37137 #endif
37138 dev_kfree_skb_irq(skb);
37139 }
37140 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37141 index 60cba81..71eb239 100644
37142 --- a/drivers/staging/octeon/ethernet.c
37143 +++ b/drivers/staging/octeon/ethernet.c
37144 @@ -259,11 +259,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37145 * since the RX tasklet also increments it.
37146 */
37147 #ifdef CONFIG_64BIT
37148 - atomic64_add(rx_status.dropped_packets,
37149 - (atomic64_t *)&priv->stats.rx_dropped);
37150 + atomic64_add_unchecked(rx_status.dropped_packets,
37151 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37152 #else
37153 - atomic_add(rx_status.dropped_packets,
37154 - (atomic_t *)&priv->stats.rx_dropped);
37155 + atomic_add_unchecked(rx_status.dropped_packets,
37156 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37157 #endif
37158 }
37159
37160 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37161 index d3d8727..f9327bb8 100644
37162 --- a/drivers/staging/rtl8712/rtl871x_io.h
37163 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37164 @@ -108,7 +108,7 @@ struct _io_ops {
37165 u8 *pmem);
37166 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37167 u8 *pmem);
37168 -};
37169 +} __no_const;
37170
37171 struct io_req {
37172 struct list_head list;
37173 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37174 index c7b5e8b..783d6cb 100644
37175 --- a/drivers/staging/sbe-2t3e3/netdev.c
37176 +++ b/drivers/staging/sbe-2t3e3/netdev.c
37177 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37178 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37179
37180 if (rlen)
37181 - if (copy_to_user(data, &resp, rlen))
37182 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37183 return -EFAULT;
37184
37185 return 0;
37186 diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c
37187 index 42cdafe..2769103 100644
37188 --- a/drivers/staging/speakup/speakup_soft.c
37189 +++ b/drivers/staging/speakup/speakup_soft.c
37190 @@ -241,11 +241,11 @@ static ssize_t softsynth_read(struct file *fp, char *buf, size_t count,
37191 break;
37192 } else if (!initialized) {
37193 if (*init) {
37194 - ch = *init;
37195 init++;
37196 } else {
37197 initialized = 1;
37198 }
37199 + ch = *init;
37200 } else {
37201 ch = synth_buffer_getc();
37202 }
37203 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37204 index c7b888c..c94be93 100644
37205 --- a/drivers/staging/usbip/usbip_common.h
37206 +++ b/drivers/staging/usbip/usbip_common.h
37207 @@ -289,7 +289,7 @@ struct usbip_device {
37208 void (*shutdown)(struct usbip_device *);
37209 void (*reset)(struct usbip_device *);
37210 void (*unusable)(struct usbip_device *);
37211 - } eh_ops;
37212 + } __no_const eh_ops;
37213 };
37214
37215 /* usbip_common.c */
37216 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37217 index 88b3298..3783eee 100644
37218 --- a/drivers/staging/usbip/vhci.h
37219 +++ b/drivers/staging/usbip/vhci.h
37220 @@ -88,7 +88,7 @@ struct vhci_hcd {
37221 unsigned resuming:1;
37222 unsigned long re_timeout;
37223
37224 - atomic_t seqnum;
37225 + atomic_unchecked_t seqnum;
37226
37227 /*
37228 * NOTE:
37229 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37230 index dca9bf1..80735c9 100644
37231 --- a/drivers/staging/usbip/vhci_hcd.c
37232 +++ b/drivers/staging/usbip/vhci_hcd.c
37233 @@ -488,7 +488,7 @@ static void vhci_tx_urb(struct urb *urb)
37234 return;
37235 }
37236
37237 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37238 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37239 if (priv->seqnum == 0xffff)
37240 dev_info(&urb->dev->dev, "seqnum max\n");
37241
37242 @@ -740,7 +740,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37243 return -ENOMEM;
37244 }
37245
37246 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37247 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37248 if (unlink->seqnum == 0xffff)
37249 pr_info("seqnum max\n");
37250
37251 @@ -928,7 +928,7 @@ static int vhci_start(struct usb_hcd *hcd)
37252 vdev->rhport = rhport;
37253 }
37254
37255 - atomic_set(&vhci->seqnum, 0);
37256 + atomic_set_unchecked(&vhci->seqnum, 0);
37257 spin_lock_init(&vhci->lock);
37258
37259 hcd->power_budget = 0; /* no limit */
37260 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37261 index f5fba732..210a16c 100644
37262 --- a/drivers/staging/usbip/vhci_rx.c
37263 +++ b/drivers/staging/usbip/vhci_rx.c
37264 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37265 if (!urb) {
37266 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37267 pr_info("max seqnum %d\n",
37268 - atomic_read(&the_controller->seqnum));
37269 + atomic_read_unchecked(&the_controller->seqnum));
37270 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37271 return;
37272 }
37273 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37274 index 7735027..30eed13 100644
37275 --- a/drivers/staging/vt6655/hostap.c
37276 +++ b/drivers/staging/vt6655/hostap.c
37277 @@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
37278 *
37279 */
37280
37281 +static net_device_ops_no_const apdev_netdev_ops;
37282 +
37283 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37284 {
37285 PSDevice apdev_priv;
37286 struct net_device *dev = pDevice->dev;
37287 int ret;
37288 - const struct net_device_ops apdev_netdev_ops = {
37289 - .ndo_start_xmit = pDevice->tx_80211,
37290 - };
37291
37292 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37293
37294 @@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37295 *apdev_priv = *pDevice;
37296 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37297
37298 + /* only half broken now */
37299 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37300 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37301
37302 pDevice->apdev->type = ARPHRD_IEEE80211;
37303 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37304 index 51b5adf..098e320 100644
37305 --- a/drivers/staging/vt6656/hostap.c
37306 +++ b/drivers/staging/vt6656/hostap.c
37307 @@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
37308 *
37309 */
37310
37311 +static net_device_ops_no_const apdev_netdev_ops;
37312 +
37313 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37314 {
37315 PSDevice apdev_priv;
37316 struct net_device *dev = pDevice->dev;
37317 int ret;
37318 - const struct net_device_ops apdev_netdev_ops = {
37319 - .ndo_start_xmit = pDevice->tx_80211,
37320 - };
37321
37322 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37323
37324 @@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37325 *apdev_priv = *pDevice;
37326 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37327
37328 + /* only half broken now */
37329 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37330 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37331
37332 pDevice->apdev->type = ARPHRD_IEEE80211;
37333 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37334 index 7843dfd..3db105f 100644
37335 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
37336 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37337 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37338
37339 struct usbctlx_completor {
37340 int (*complete) (struct usbctlx_completor *);
37341 -};
37342 +} __no_const;
37343
37344 static int
37345 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37346 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37347 index 1ca66ea..76f1343 100644
37348 --- a/drivers/staging/zcache/tmem.c
37349 +++ b/drivers/staging/zcache/tmem.c
37350 @@ -39,7 +39,7 @@
37351 * A tmem host implementation must use this function to register callbacks
37352 * for memory allocation.
37353 */
37354 -static struct tmem_hostops tmem_hostops;
37355 +static tmem_hostops_no_const tmem_hostops;
37356
37357 static void tmem_objnode_tree_init(void);
37358
37359 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37360 * A tmem host implementation must use this function to register
37361 * callbacks for a page-accessible memory (PAM) implementation
37362 */
37363 -static struct tmem_pamops tmem_pamops;
37364 +static tmem_pamops_no_const tmem_pamops;
37365
37366 void tmem_register_pamops(struct tmem_pamops *m)
37367 {
37368 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37369 index 0d4aa82..f7832d4 100644
37370 --- a/drivers/staging/zcache/tmem.h
37371 +++ b/drivers/staging/zcache/tmem.h
37372 @@ -180,6 +180,7 @@ struct tmem_pamops {
37373 void (*new_obj)(struct tmem_obj *);
37374 int (*replace_in_obj)(void *, struct tmem_obj *);
37375 };
37376 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37377 extern void tmem_register_pamops(struct tmem_pamops *m);
37378
37379 /* memory allocation methods provided by the host implementation */
37380 @@ -189,6 +190,7 @@ struct tmem_hostops {
37381 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37382 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37383 };
37384 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37385 extern void tmem_register_hostops(struct tmem_hostops *m);
37386
37387 /* core tmem accessor functions */
37388 diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
37389 index f015839..b15dfc4 100644
37390 --- a/drivers/target/target_core_tmr.c
37391 +++ b/drivers/target/target_core_tmr.c
37392 @@ -327,7 +327,7 @@ static void core_tmr_drain_task_list(
37393 cmd->se_tfo->get_task_tag(cmd), cmd->pr_res_key,
37394 cmd->t_task_list_num,
37395 atomic_read(&cmd->t_task_cdbs_left),
37396 - atomic_read(&cmd->t_task_cdbs_sent),
37397 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37398 (cmd->transport_state & CMD_T_ACTIVE) != 0,
37399 (cmd->transport_state & CMD_T_STOP) != 0,
37400 (cmd->transport_state & CMD_T_SENT) != 0);
37401 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37402 index 443704f..92d3517 100644
37403 --- a/drivers/target/target_core_transport.c
37404 +++ b/drivers/target/target_core_transport.c
37405 @@ -1355,7 +1355,7 @@ struct se_device *transport_add_device_to_core_hba(
37406 spin_lock_init(&dev->se_port_lock);
37407 spin_lock_init(&dev->se_tmr_lock);
37408 spin_lock_init(&dev->qf_cmd_lock);
37409 - atomic_set(&dev->dev_ordered_id, 0);
37410 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
37411
37412 se_dev_set_default_attribs(dev, dev_limits);
37413
37414 @@ -1542,7 +1542,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37415 * Used to determine when ORDERED commands should go from
37416 * Dormant to Active status.
37417 */
37418 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37419 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37420 smp_mb__after_atomic_inc();
37421 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37422 cmd->se_ordered_id, cmd->sam_task_attr,
37423 @@ -1956,7 +1956,7 @@ void transport_generic_request_failure(struct se_cmd *cmd)
37424 " CMD_T_ACTIVE: %d CMD_T_STOP: %d CMD_T_SENT: %d\n",
37425 cmd->t_task_list_num,
37426 atomic_read(&cmd->t_task_cdbs_left),
37427 - atomic_read(&cmd->t_task_cdbs_sent),
37428 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37429 atomic_read(&cmd->t_task_cdbs_ex_left),
37430 (cmd->transport_state & CMD_T_ACTIVE) != 0,
37431 (cmd->transport_state & CMD_T_STOP) != 0,
37432 @@ -2216,9 +2216,9 @@ check_depth:
37433 cmd = task->task_se_cmd;
37434 spin_lock_irqsave(&cmd->t_state_lock, flags);
37435 task->task_flags |= (TF_ACTIVE | TF_SENT);
37436 - atomic_inc(&cmd->t_task_cdbs_sent);
37437 + atomic_inc_unchecked(&cmd->t_task_cdbs_sent);
37438
37439 - if (atomic_read(&cmd->t_task_cdbs_sent) ==
37440 + if (atomic_read_unchecked(&cmd->t_task_cdbs_sent) ==
37441 cmd->t_task_list_num)
37442 cmd->transport_state |= CMD_T_SENT;
37443
37444 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37445 index 3436436..772237b 100644
37446 --- a/drivers/tty/hvc/hvcs.c
37447 +++ b/drivers/tty/hvc/hvcs.c
37448 @@ -83,6 +83,7 @@
37449 #include <asm/hvcserver.h>
37450 #include <asm/uaccess.h>
37451 #include <asm/vio.h>
37452 +#include <asm/local.h>
37453
37454 /*
37455 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37456 @@ -270,7 +271,7 @@ struct hvcs_struct {
37457 unsigned int index;
37458
37459 struct tty_struct *tty;
37460 - int open_count;
37461 + local_t open_count;
37462
37463 /*
37464 * Used to tell the driver kernel_thread what operations need to take
37465 @@ -422,7 +423,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37466
37467 spin_lock_irqsave(&hvcsd->lock, flags);
37468
37469 - if (hvcsd->open_count > 0) {
37470 + if (local_read(&hvcsd->open_count) > 0) {
37471 spin_unlock_irqrestore(&hvcsd->lock, flags);
37472 printk(KERN_INFO "HVCS: vterm state unchanged. "
37473 "The hvcs device node is still in use.\n");
37474 @@ -1138,7 +1139,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37475 if ((retval = hvcs_partner_connect(hvcsd)))
37476 goto error_release;
37477
37478 - hvcsd->open_count = 1;
37479 + local_set(&hvcsd->open_count, 1);
37480 hvcsd->tty = tty;
37481 tty->driver_data = hvcsd;
37482
37483 @@ -1172,7 +1173,7 @@ fast_open:
37484
37485 spin_lock_irqsave(&hvcsd->lock, flags);
37486 kref_get(&hvcsd->kref);
37487 - hvcsd->open_count++;
37488 + local_inc(&hvcsd->open_count);
37489 hvcsd->todo_mask |= HVCS_SCHED_READ;
37490 spin_unlock_irqrestore(&hvcsd->lock, flags);
37491
37492 @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37493 hvcsd = tty->driver_data;
37494
37495 spin_lock_irqsave(&hvcsd->lock, flags);
37496 - if (--hvcsd->open_count == 0) {
37497 + if (local_dec_and_test(&hvcsd->open_count)) {
37498
37499 vio_disable_interrupts(hvcsd->vdev);
37500
37501 @@ -1242,10 +1243,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37502 free_irq(irq, hvcsd);
37503 kref_put(&hvcsd->kref, destroy_hvcs_struct);
37504 return;
37505 - } else if (hvcsd->open_count < 0) {
37506 + } else if (local_read(&hvcsd->open_count) < 0) {
37507 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37508 " is missmanaged.\n",
37509 - hvcsd->vdev->unit_address, hvcsd->open_count);
37510 + hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
37511 }
37512
37513 spin_unlock_irqrestore(&hvcsd->lock, flags);
37514 @@ -1261,7 +1262,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37515
37516 spin_lock_irqsave(&hvcsd->lock, flags);
37517 /* Preserve this so that we know how many kref refs to put */
37518 - temp_open_count = hvcsd->open_count;
37519 + temp_open_count = local_read(&hvcsd->open_count);
37520
37521 /*
37522 * Don't kref put inside the spinlock because the destruction
37523 @@ -1276,7 +1277,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37524 hvcsd->tty->driver_data = NULL;
37525 hvcsd->tty = NULL;
37526
37527 - hvcsd->open_count = 0;
37528 + local_set(&hvcsd->open_count, 0);
37529
37530 /* This will drop any buffered data on the floor which is OK in a hangup
37531 * scenario. */
37532 @@ -1347,7 +1348,7 @@ static int hvcs_write(struct tty_struct *tty,
37533 * the middle of a write operation? This is a crummy place to do this
37534 * but we want to keep it all in the spinlock.
37535 */
37536 - if (hvcsd->open_count <= 0) {
37537 + if (local_read(&hvcsd->open_count) <= 0) {
37538 spin_unlock_irqrestore(&hvcsd->lock, flags);
37539 return -ENODEV;
37540 }
37541 @@ -1421,7 +1422,7 @@ static int hvcs_write_room(struct tty_struct *tty)
37542 {
37543 struct hvcs_struct *hvcsd = tty->driver_data;
37544
37545 - if (!hvcsd || hvcsd->open_count <= 0)
37546 + if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
37547 return 0;
37548
37549 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
37550 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
37551 index 4daf962..b4a2281 100644
37552 --- a/drivers/tty/ipwireless/tty.c
37553 +++ b/drivers/tty/ipwireless/tty.c
37554 @@ -29,6 +29,7 @@
37555 #include <linux/tty_driver.h>
37556 #include <linux/tty_flip.h>
37557 #include <linux/uaccess.h>
37558 +#include <asm/local.h>
37559
37560 #include "tty.h"
37561 #include "network.h"
37562 @@ -51,7 +52,7 @@ struct ipw_tty {
37563 int tty_type;
37564 struct ipw_network *network;
37565 struct tty_struct *linux_tty;
37566 - int open_count;
37567 + local_t open_count;
37568 unsigned int control_lines;
37569 struct mutex ipw_tty_mutex;
37570 int tx_bytes_queued;
37571 @@ -117,10 +118,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37572 mutex_unlock(&tty->ipw_tty_mutex);
37573 return -ENODEV;
37574 }
37575 - if (tty->open_count == 0)
37576 + if (local_read(&tty->open_count) == 0)
37577 tty->tx_bytes_queued = 0;
37578
37579 - tty->open_count++;
37580 + local_inc(&tty->open_count);
37581
37582 tty->linux_tty = linux_tty;
37583 linux_tty->driver_data = tty;
37584 @@ -136,9 +137,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37585
37586 static void do_ipw_close(struct ipw_tty *tty)
37587 {
37588 - tty->open_count--;
37589 -
37590 - if (tty->open_count == 0) {
37591 + if (local_dec_return(&tty->open_count) == 0) {
37592 struct tty_struct *linux_tty = tty->linux_tty;
37593
37594 if (linux_tty != NULL) {
37595 @@ -159,7 +158,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
37596 return;
37597
37598 mutex_lock(&tty->ipw_tty_mutex);
37599 - if (tty->open_count == 0) {
37600 + if (local_read(&tty->open_count) == 0) {
37601 mutex_unlock(&tty->ipw_tty_mutex);
37602 return;
37603 }
37604 @@ -188,7 +187,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
37605 return;
37606 }
37607
37608 - if (!tty->open_count) {
37609 + if (!local_read(&tty->open_count)) {
37610 mutex_unlock(&tty->ipw_tty_mutex);
37611 return;
37612 }
37613 @@ -230,7 +229,7 @@ static int ipw_write(struct tty_struct *linux_tty,
37614 return -ENODEV;
37615
37616 mutex_lock(&tty->ipw_tty_mutex);
37617 - if (!tty->open_count) {
37618 + if (!local_read(&tty->open_count)) {
37619 mutex_unlock(&tty->ipw_tty_mutex);
37620 return -EINVAL;
37621 }
37622 @@ -270,7 +269,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
37623 if (!tty)
37624 return -ENODEV;
37625
37626 - if (!tty->open_count)
37627 + if (!local_read(&tty->open_count))
37628 return -EINVAL;
37629
37630 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
37631 @@ -312,7 +311,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
37632 if (!tty)
37633 return 0;
37634
37635 - if (!tty->open_count)
37636 + if (!local_read(&tty->open_count))
37637 return 0;
37638
37639 return tty->tx_bytes_queued;
37640 @@ -393,7 +392,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
37641 if (!tty)
37642 return -ENODEV;
37643
37644 - if (!tty->open_count)
37645 + if (!local_read(&tty->open_count))
37646 return -EINVAL;
37647
37648 return get_control_lines(tty);
37649 @@ -409,7 +408,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
37650 if (!tty)
37651 return -ENODEV;
37652
37653 - if (!tty->open_count)
37654 + if (!local_read(&tty->open_count))
37655 return -EINVAL;
37656
37657 return set_control_lines(tty, set, clear);
37658 @@ -423,7 +422,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
37659 if (!tty)
37660 return -ENODEV;
37661
37662 - if (!tty->open_count)
37663 + if (!local_read(&tty->open_count))
37664 return -EINVAL;
37665
37666 /* FIXME: Exactly how is the tty object locked here .. */
37667 @@ -572,7 +571,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
37668 against a parallel ioctl etc */
37669 mutex_lock(&ttyj->ipw_tty_mutex);
37670 }
37671 - while (ttyj->open_count)
37672 + while (local_read(&ttyj->open_count))
37673 do_ipw_close(ttyj);
37674 ipwireless_disassociate_network_ttys(network,
37675 ttyj->channel_idx);
37676 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
37677 index c43b683..0a88f1c 100644
37678 --- a/drivers/tty/n_gsm.c
37679 +++ b/drivers/tty/n_gsm.c
37680 @@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
37681 kref_init(&dlci->ref);
37682 mutex_init(&dlci->mutex);
37683 dlci->fifo = &dlci->_fifo;
37684 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
37685 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
37686 kfree(dlci);
37687 return NULL;
37688 }
37689 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
37690 index 94b6eda..15f7cec 100644
37691 --- a/drivers/tty/n_tty.c
37692 +++ b/drivers/tty/n_tty.c
37693 @@ -2122,6 +2122,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
37694 {
37695 *ops = tty_ldisc_N_TTY;
37696 ops->owner = NULL;
37697 - ops->refcount = ops->flags = 0;
37698 + atomic_set(&ops->refcount, 0);
37699 + ops->flags = 0;
37700 }
37701 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
37702 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
37703 index eeae7fa..177a743 100644
37704 --- a/drivers/tty/pty.c
37705 +++ b/drivers/tty/pty.c
37706 @@ -707,8 +707,10 @@ static void __init unix98_pty_init(void)
37707 panic("Couldn't register Unix98 pts driver");
37708
37709 /* Now create the /dev/ptmx special device */
37710 + pax_open_kernel();
37711 tty_default_fops(&ptmx_fops);
37712 - ptmx_fops.open = ptmx_open;
37713 + *(void **)&ptmx_fops.open = ptmx_open;
37714 + pax_close_kernel();
37715
37716 cdev_init(&ptmx_cdev, &ptmx_fops);
37717 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
37718 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
37719 index 2b42a01..32a2ed3 100644
37720 --- a/drivers/tty/serial/kgdboc.c
37721 +++ b/drivers/tty/serial/kgdboc.c
37722 @@ -24,8 +24,9 @@
37723 #define MAX_CONFIG_LEN 40
37724
37725 static struct kgdb_io kgdboc_io_ops;
37726 +static struct kgdb_io kgdboc_io_ops_console;
37727
37728 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
37729 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
37730 static int configured = -1;
37731
37732 static char config[MAX_CONFIG_LEN];
37733 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
37734 kgdboc_unregister_kbd();
37735 if (configured == 1)
37736 kgdb_unregister_io_module(&kgdboc_io_ops);
37737 + else if (configured == 2)
37738 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
37739 }
37740
37741 static int configure_kgdboc(void)
37742 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
37743 int err;
37744 char *cptr = config;
37745 struct console *cons;
37746 + int is_console = 0;
37747
37748 err = kgdboc_option_setup(config);
37749 if (err || !strlen(config) || isspace(config[0]))
37750 goto noconfig;
37751
37752 err = -ENODEV;
37753 - kgdboc_io_ops.is_console = 0;
37754 kgdb_tty_driver = NULL;
37755
37756 kgdboc_use_kms = 0;
37757 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
37758 int idx;
37759 if (cons->device && cons->device(cons, &idx) == p &&
37760 idx == tty_line) {
37761 - kgdboc_io_ops.is_console = 1;
37762 + is_console = 1;
37763 break;
37764 }
37765 cons = cons->next;
37766 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
37767 kgdb_tty_line = tty_line;
37768
37769 do_register:
37770 - err = kgdb_register_io_module(&kgdboc_io_ops);
37771 + if (is_console) {
37772 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
37773 + configured = 2;
37774 + } else {
37775 + err = kgdb_register_io_module(&kgdboc_io_ops);
37776 + configured = 1;
37777 + }
37778 if (err)
37779 goto noconfig;
37780
37781 - configured = 1;
37782 -
37783 return 0;
37784
37785 noconfig:
37786 @@ -213,7 +220,7 @@ noconfig:
37787 static int __init init_kgdboc(void)
37788 {
37789 /* Already configured? */
37790 - if (configured == 1)
37791 + if (configured >= 1)
37792 return 0;
37793
37794 return configure_kgdboc();
37795 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
37796 if (config[len - 1] == '\n')
37797 config[len - 1] = '\0';
37798
37799 - if (configured == 1)
37800 + if (configured >= 1)
37801 cleanup_kgdboc();
37802
37803 /* Go and configure with the new params. */
37804 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
37805 .post_exception = kgdboc_post_exp_handler,
37806 };
37807
37808 +static struct kgdb_io kgdboc_io_ops_console = {
37809 + .name = "kgdboc",
37810 + .read_char = kgdboc_get_char,
37811 + .write_char = kgdboc_put_char,
37812 + .pre_exception = kgdboc_pre_exp_handler,
37813 + .post_exception = kgdboc_post_exp_handler,
37814 + .is_console = 1
37815 +};
37816 +
37817 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
37818 /* This is only available if kgdboc is a built in for early debugging */
37819 static int __init kgdboc_early_init(char *opt)
37820 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
37821 index 05728894..b9d44c6 100644
37822 --- a/drivers/tty/sysrq.c
37823 +++ b/drivers/tty/sysrq.c
37824 @@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
37825 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
37826 size_t count, loff_t *ppos)
37827 {
37828 - if (count) {
37829 + if (count && capable(CAP_SYS_ADMIN)) {
37830 char c;
37831
37832 if (get_user(c, buf))
37833 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
37834 index d939bd7..33d92cd 100644
37835 --- a/drivers/tty/tty_io.c
37836 +++ b/drivers/tty/tty_io.c
37837 @@ -3278,7 +3278,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
37838
37839 void tty_default_fops(struct file_operations *fops)
37840 {
37841 - *fops = tty_fops;
37842 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
37843 }
37844
37845 /*
37846 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
37847 index 24b95db..9c078d0 100644
37848 --- a/drivers/tty/tty_ldisc.c
37849 +++ b/drivers/tty/tty_ldisc.c
37850 @@ -57,7 +57,7 @@ static void put_ldisc(struct tty_ldisc *ld)
37851 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
37852 struct tty_ldisc_ops *ldo = ld->ops;
37853
37854 - ldo->refcount--;
37855 + atomic_dec(&ldo->refcount);
37856 module_put(ldo->owner);
37857 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
37858
37859 @@ -92,7 +92,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
37860 spin_lock_irqsave(&tty_ldisc_lock, flags);
37861 tty_ldiscs[disc] = new_ldisc;
37862 new_ldisc->num = disc;
37863 - new_ldisc->refcount = 0;
37864 + atomic_set(&new_ldisc->refcount, 0);
37865 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
37866
37867 return ret;
37868 @@ -120,7 +120,7 @@ int tty_unregister_ldisc(int disc)
37869 return -EINVAL;
37870
37871 spin_lock_irqsave(&tty_ldisc_lock, flags);
37872 - if (tty_ldiscs[disc]->refcount)
37873 + if (atomic_read(&tty_ldiscs[disc]->refcount))
37874 ret = -EBUSY;
37875 else
37876 tty_ldiscs[disc] = NULL;
37877 @@ -141,7 +141,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
37878 if (ldops) {
37879 ret = ERR_PTR(-EAGAIN);
37880 if (try_module_get(ldops->owner)) {
37881 - ldops->refcount++;
37882 + atomic_inc(&ldops->refcount);
37883 ret = ldops;
37884 }
37885 }
37886 @@ -154,7 +154,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
37887 unsigned long flags;
37888
37889 spin_lock_irqsave(&tty_ldisc_lock, flags);
37890 - ldops->refcount--;
37891 + atomic_dec(&ldops->refcount);
37892 module_put(ldops->owner);
37893 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
37894 }
37895 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
37896 index 3b0c4e3..f98a992 100644
37897 --- a/drivers/tty/vt/keyboard.c
37898 +++ b/drivers/tty/vt/keyboard.c
37899 @@ -663,6 +663,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
37900 kbd->kbdmode == VC_OFF) &&
37901 value != KVAL(K_SAK))
37902 return; /* SAK is allowed even in raw mode */
37903 +
37904 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
37905 + {
37906 + void *func = fn_handler[value];
37907 + if (func == fn_show_state || func == fn_show_ptregs ||
37908 + func == fn_show_mem)
37909 + return;
37910 + }
37911 +#endif
37912 +
37913 fn_handler[value](vc);
37914 }
37915
37916 @@ -1812,9 +1822,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
37917 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
37918 return -EFAULT;
37919
37920 - if (!capable(CAP_SYS_TTY_CONFIG))
37921 - perm = 0;
37922 -
37923 switch (cmd) {
37924 case KDGKBENT:
37925 /* Ensure another thread doesn't free it under us */
37926 @@ -1829,6 +1836,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
37927 spin_unlock_irqrestore(&kbd_event_lock, flags);
37928 return put_user(val, &user_kbe->kb_value);
37929 case KDSKBENT:
37930 + if (!capable(CAP_SYS_TTY_CONFIG))
37931 + perm = 0;
37932 +
37933 if (!perm)
37934 return -EPERM;
37935 if (!i && v == K_NOSUCHMAP) {
37936 @@ -1919,9 +1929,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
37937 int i, j, k;
37938 int ret;
37939
37940 - if (!capable(CAP_SYS_TTY_CONFIG))
37941 - perm = 0;
37942 -
37943 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
37944 if (!kbs) {
37945 ret = -ENOMEM;
37946 @@ -1955,6 +1962,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
37947 kfree(kbs);
37948 return ((p && *p) ? -EOVERFLOW : 0);
37949 case KDSKBSENT:
37950 + if (!capable(CAP_SYS_TTY_CONFIG))
37951 + perm = 0;
37952 +
37953 if (!perm) {
37954 ret = -EPERM;
37955 goto reterr;
37956 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
37957 index a783d53..cb30d94 100644
37958 --- a/drivers/uio/uio.c
37959 +++ b/drivers/uio/uio.c
37960 @@ -25,6 +25,7 @@
37961 #include <linux/kobject.h>
37962 #include <linux/cdev.h>
37963 #include <linux/uio_driver.h>
37964 +#include <asm/local.h>
37965
37966 #define UIO_MAX_DEVICES (1U << MINORBITS)
37967
37968 @@ -32,10 +33,10 @@ struct uio_device {
37969 struct module *owner;
37970 struct device *dev;
37971 int minor;
37972 - atomic_t event;
37973 + atomic_unchecked_t event;
37974 struct fasync_struct *async_queue;
37975 wait_queue_head_t wait;
37976 - int vma_count;
37977 + local_t vma_count;
37978 struct uio_info *info;
37979 struct kobject *map_dir;
37980 struct kobject *portio_dir;
37981 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
37982 struct device_attribute *attr, char *buf)
37983 {
37984 struct uio_device *idev = dev_get_drvdata(dev);
37985 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
37986 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
37987 }
37988
37989 static struct device_attribute uio_class_attributes[] = {
37990 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
37991 {
37992 struct uio_device *idev = info->uio_dev;
37993
37994 - atomic_inc(&idev->event);
37995 + atomic_inc_unchecked(&idev->event);
37996 wake_up_interruptible(&idev->wait);
37997 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
37998 }
37999 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
38000 }
38001
38002 listener->dev = idev;
38003 - listener->event_count = atomic_read(&idev->event);
38004 + listener->event_count = atomic_read_unchecked(&idev->event);
38005 filep->private_data = listener;
38006
38007 if (idev->info->open) {
38008 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
38009 return -EIO;
38010
38011 poll_wait(filep, &idev->wait, wait);
38012 - if (listener->event_count != atomic_read(&idev->event))
38013 + if (listener->event_count != atomic_read_unchecked(&idev->event))
38014 return POLLIN | POLLRDNORM;
38015 return 0;
38016 }
38017 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
38018 do {
38019 set_current_state(TASK_INTERRUPTIBLE);
38020
38021 - event_count = atomic_read(&idev->event);
38022 + event_count = atomic_read_unchecked(&idev->event);
38023 if (event_count != listener->event_count) {
38024 if (copy_to_user(buf, &event_count, count))
38025 retval = -EFAULT;
38026 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
38027 static void uio_vma_open(struct vm_area_struct *vma)
38028 {
38029 struct uio_device *idev = vma->vm_private_data;
38030 - idev->vma_count++;
38031 + local_inc(&idev->vma_count);
38032 }
38033
38034 static void uio_vma_close(struct vm_area_struct *vma)
38035 {
38036 struct uio_device *idev = vma->vm_private_data;
38037 - idev->vma_count--;
38038 + local_dec(&idev->vma_count);
38039 }
38040
38041 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38042 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
38043 idev->owner = owner;
38044 idev->info = info;
38045 init_waitqueue_head(&idev->wait);
38046 - atomic_set(&idev->event, 0);
38047 + atomic_set_unchecked(&idev->event, 0);
38048
38049 ret = uio_get_minor(idev);
38050 if (ret)
38051 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
38052 index 98b89fe..aff824e 100644
38053 --- a/drivers/usb/atm/cxacru.c
38054 +++ b/drivers/usb/atm/cxacru.c
38055 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
38056 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
38057 if (ret < 2)
38058 return -EINVAL;
38059 - if (index < 0 || index > 0x7f)
38060 + if (index > 0x7f)
38061 return -EINVAL;
38062 pos += tmp;
38063
38064 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
38065 index d3448ca..d2864ca 100644
38066 --- a/drivers/usb/atm/usbatm.c
38067 +++ b/drivers/usb/atm/usbatm.c
38068 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38069 if (printk_ratelimit())
38070 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
38071 __func__, vpi, vci);
38072 - atomic_inc(&vcc->stats->rx_err);
38073 + atomic_inc_unchecked(&vcc->stats->rx_err);
38074 return;
38075 }
38076
38077 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38078 if (length > ATM_MAX_AAL5_PDU) {
38079 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
38080 __func__, length, vcc);
38081 - atomic_inc(&vcc->stats->rx_err);
38082 + atomic_inc_unchecked(&vcc->stats->rx_err);
38083 goto out;
38084 }
38085
38086 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38087 if (sarb->len < pdu_length) {
38088 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
38089 __func__, pdu_length, sarb->len, vcc);
38090 - atomic_inc(&vcc->stats->rx_err);
38091 + atomic_inc_unchecked(&vcc->stats->rx_err);
38092 goto out;
38093 }
38094
38095 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
38096 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
38097 __func__, vcc);
38098 - atomic_inc(&vcc->stats->rx_err);
38099 + atomic_inc_unchecked(&vcc->stats->rx_err);
38100 goto out;
38101 }
38102
38103 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38104 if (printk_ratelimit())
38105 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
38106 __func__, length);
38107 - atomic_inc(&vcc->stats->rx_drop);
38108 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38109 goto out;
38110 }
38111
38112 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38113
38114 vcc->push(vcc, skb);
38115
38116 - atomic_inc(&vcc->stats->rx);
38117 + atomic_inc_unchecked(&vcc->stats->rx);
38118 out:
38119 skb_trim(sarb, 0);
38120 }
38121 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
38122 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
38123
38124 usbatm_pop(vcc, skb);
38125 - atomic_inc(&vcc->stats->tx);
38126 + atomic_inc_unchecked(&vcc->stats->tx);
38127
38128 skb = skb_dequeue(&instance->sndqueue);
38129 }
38130 @@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
38131 if (!left--)
38132 return sprintf(page,
38133 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
38134 - atomic_read(&atm_dev->stats.aal5.tx),
38135 - atomic_read(&atm_dev->stats.aal5.tx_err),
38136 - atomic_read(&atm_dev->stats.aal5.rx),
38137 - atomic_read(&atm_dev->stats.aal5.rx_err),
38138 - atomic_read(&atm_dev->stats.aal5.rx_drop));
38139 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
38140 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
38141 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
38142 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
38143 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
38144
38145 if (!left--) {
38146 if (instance->disconnected)
38147 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
38148 index d956965..4179a77 100644
38149 --- a/drivers/usb/core/devices.c
38150 +++ b/drivers/usb/core/devices.c
38151 @@ -126,7 +126,7 @@ static const char format_endpt[] =
38152 * time it gets called.
38153 */
38154 static struct device_connect_event {
38155 - atomic_t count;
38156 + atomic_unchecked_t count;
38157 wait_queue_head_t wait;
38158 } device_event = {
38159 .count = ATOMIC_INIT(1),
38160 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
38161
38162 void usbfs_conn_disc_event(void)
38163 {
38164 - atomic_add(2, &device_event.count);
38165 + atomic_add_unchecked(2, &device_event.count);
38166 wake_up(&device_event.wait);
38167 }
38168
38169 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
38170
38171 poll_wait(file, &device_event.wait, wait);
38172
38173 - event_count = atomic_read(&device_event.count);
38174 + event_count = atomic_read_unchecked(&device_event.count);
38175 if (file->f_version != event_count) {
38176 file->f_version = event_count;
38177 return POLLIN | POLLRDNORM;
38178 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
38179 index 1fc8f12..20647c1 100644
38180 --- a/drivers/usb/early/ehci-dbgp.c
38181 +++ b/drivers/usb/early/ehci-dbgp.c
38182 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
38183
38184 #ifdef CONFIG_KGDB
38185 static struct kgdb_io kgdbdbgp_io_ops;
38186 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
38187 +static struct kgdb_io kgdbdbgp_io_ops_console;
38188 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
38189 #else
38190 #define dbgp_kgdb_mode (0)
38191 #endif
38192 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
38193 .write_char = kgdbdbgp_write_char,
38194 };
38195
38196 +static struct kgdb_io kgdbdbgp_io_ops_console = {
38197 + .name = "kgdbdbgp",
38198 + .read_char = kgdbdbgp_read_char,
38199 + .write_char = kgdbdbgp_write_char,
38200 + .is_console = 1
38201 +};
38202 +
38203 static int kgdbdbgp_wait_time;
38204
38205 static int __init kgdbdbgp_parse_config(char *str)
38206 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
38207 ptr++;
38208 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
38209 }
38210 - kgdb_register_io_module(&kgdbdbgp_io_ops);
38211 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
38212 + if (early_dbgp_console.index != -1)
38213 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
38214 + else
38215 + kgdb_register_io_module(&kgdbdbgp_io_ops);
38216
38217 return 0;
38218 }
38219 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
38220 index d6bea3e..60b250e 100644
38221 --- a/drivers/usb/wusbcore/wa-hc.h
38222 +++ b/drivers/usb/wusbcore/wa-hc.h
38223 @@ -192,7 +192,7 @@ struct wahc {
38224 struct list_head xfer_delayed_list;
38225 spinlock_t xfer_list_lock;
38226 struct work_struct xfer_work;
38227 - atomic_t xfer_id_count;
38228 + atomic_unchecked_t xfer_id_count;
38229 };
38230
38231
38232 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
38233 INIT_LIST_HEAD(&wa->xfer_delayed_list);
38234 spin_lock_init(&wa->xfer_list_lock);
38235 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
38236 - atomic_set(&wa->xfer_id_count, 1);
38237 + atomic_set_unchecked(&wa->xfer_id_count, 1);
38238 }
38239
38240 /**
38241 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
38242 index 57c01ab..8a05959 100644
38243 --- a/drivers/usb/wusbcore/wa-xfer.c
38244 +++ b/drivers/usb/wusbcore/wa-xfer.c
38245 @@ -296,7 +296,7 @@ out:
38246 */
38247 static void wa_xfer_id_init(struct wa_xfer *xfer)
38248 {
38249 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
38250 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
38251 }
38252
38253 /*
38254 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
38255 index 51e4c1e..9d87e2a 100644
38256 --- a/drivers/vhost/vhost.c
38257 +++ b/drivers/vhost/vhost.c
38258 @@ -632,7 +632,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
38259 return 0;
38260 }
38261
38262 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
38263 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
38264 {
38265 struct file *eventfp, *filep = NULL,
38266 *pollstart = NULL, *pollstop = NULL;
38267 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
38268 index b0b2ac3..89a4399 100644
38269 --- a/drivers/video/aty/aty128fb.c
38270 +++ b/drivers/video/aty/aty128fb.c
38271 @@ -148,7 +148,7 @@ enum {
38272 };
38273
38274 /* Must match above enum */
38275 -static const char *r128_family[] __devinitdata = {
38276 +static const char *r128_family[] __devinitconst = {
38277 "AGP",
38278 "PCI",
38279 "PRO AGP",
38280 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
38281 index 5c3960d..15cf8fc 100644
38282 --- a/drivers/video/fbcmap.c
38283 +++ b/drivers/video/fbcmap.c
38284 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
38285 rc = -ENODEV;
38286 goto out;
38287 }
38288 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
38289 - !info->fbops->fb_setcmap)) {
38290 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
38291 rc = -EINVAL;
38292 goto out1;
38293 }
38294 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
38295 index c6ce416..3b9b642 100644
38296 --- a/drivers/video/fbmem.c
38297 +++ b/drivers/video/fbmem.c
38298 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38299 image->dx += image->width + 8;
38300 }
38301 } else if (rotate == FB_ROTATE_UD) {
38302 - for (x = 0; x < num && image->dx >= 0; x++) {
38303 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
38304 info->fbops->fb_imageblit(info, image);
38305 image->dx -= image->width + 8;
38306 }
38307 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38308 image->dy += image->height + 8;
38309 }
38310 } else if (rotate == FB_ROTATE_CCW) {
38311 - for (x = 0; x < num && image->dy >= 0; x++) {
38312 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
38313 info->fbops->fb_imageblit(info, image);
38314 image->dy -= image->height + 8;
38315 }
38316 @@ -1157,7 +1157,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
38317 return -EFAULT;
38318 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
38319 return -EINVAL;
38320 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
38321 + if (con2fb.framebuffer >= FB_MAX)
38322 return -EINVAL;
38323 if (!registered_fb[con2fb.framebuffer])
38324 request_module("fb%d", con2fb.framebuffer);
38325 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
38326 index 5a5d092..265c5ed 100644
38327 --- a/drivers/video/geode/gx1fb_core.c
38328 +++ b/drivers/video/geode/gx1fb_core.c
38329 @@ -29,7 +29,7 @@ static int crt_option = 1;
38330 static char panel_option[32] = "";
38331
38332 /* Modes relevant to the GX1 (taken from modedb.c) */
38333 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
38334 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
38335 /* 640x480-60 VESA */
38336 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
38337 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
38338 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
38339 index 0fad23f..0e9afa4 100644
38340 --- a/drivers/video/gxt4500.c
38341 +++ b/drivers/video/gxt4500.c
38342 @@ -156,7 +156,7 @@ struct gxt4500_par {
38343 static char *mode_option;
38344
38345 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
38346 -static const struct fb_videomode defaultmode __devinitdata = {
38347 +static const struct fb_videomode defaultmode __devinitconst = {
38348 .refresh = 60,
38349 .xres = 1280,
38350 .yres = 1024,
38351 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
38352 return 0;
38353 }
38354
38355 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
38356 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
38357 .id = "IBM GXT4500P",
38358 .type = FB_TYPE_PACKED_PIXELS,
38359 .visual = FB_VISUAL_PSEUDOCOLOR,
38360 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
38361 index 7672d2e..b56437f 100644
38362 --- a/drivers/video/i810/i810_accel.c
38363 +++ b/drivers/video/i810/i810_accel.c
38364 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
38365 }
38366 }
38367 printk("ringbuffer lockup!!!\n");
38368 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
38369 i810_report_error(mmio);
38370 par->dev_flags |= LOCKUP;
38371 info->pixmap.scan_align = 1;
38372 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
38373 index b83f361..2b05a91 100644
38374 --- a/drivers/video/i810/i810_main.c
38375 +++ b/drivers/video/i810/i810_main.c
38376 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
38377 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
38378
38379 /* PCI */
38380 -static const char *i810_pci_list[] __devinitdata = {
38381 +static const char *i810_pci_list[] __devinitconst = {
38382 "Intel(R) 810 Framebuffer Device" ,
38383 "Intel(R) 810-DC100 Framebuffer Device" ,
38384 "Intel(R) 810E Framebuffer Device" ,
38385 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
38386 index de36693..3c63fc2 100644
38387 --- a/drivers/video/jz4740_fb.c
38388 +++ b/drivers/video/jz4740_fb.c
38389 @@ -136,7 +136,7 @@ struct jzfb {
38390 uint32_t pseudo_palette[16];
38391 };
38392
38393 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
38394 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
38395 .id = "JZ4740 FB",
38396 .type = FB_TYPE_PACKED_PIXELS,
38397 .visual = FB_VISUAL_TRUECOLOR,
38398 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
38399 index 3c14e43..eafa544 100644
38400 --- a/drivers/video/logo/logo_linux_clut224.ppm
38401 +++ b/drivers/video/logo/logo_linux_clut224.ppm
38402 @@ -1,1604 +1,1123 @@
38403 P3
38404 -# Standard 224-color Linux logo
38405 80 80
38406 255
38407 - 0 0 0 0 0 0 0 0 0 0 0 0
38408 - 0 0 0 0 0 0 0 0 0 0 0 0
38409 - 0 0 0 0 0 0 0 0 0 0 0 0
38410 - 0 0 0 0 0 0 0 0 0 0 0 0
38411 - 0 0 0 0 0 0 0 0 0 0 0 0
38412 - 0 0 0 0 0 0 0 0 0 0 0 0
38413 - 0 0 0 0 0 0 0 0 0 0 0 0
38414 - 0 0 0 0 0 0 0 0 0 0 0 0
38415 - 0 0 0 0 0 0 0 0 0 0 0 0
38416 - 6 6 6 6 6 6 10 10 10 10 10 10
38417 - 10 10 10 6 6 6 6 6 6 6 6 6
38418 - 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0
38425 - 0 0 0 0 0 0 0 0 0 0 0 0
38426 - 0 0 0 0 0 0 0 0 0 0 0 0
38427 - 0 0 0 0 0 0 0 0 0 0 0 0
38428 - 0 0 0 0 0 0 0 0 0 0 0 0
38429 - 0 0 0 0 0 0 0 0 0 0 0 0
38430 - 0 0 0 0 0 0 0 0 0 0 0 0
38431 - 0 0 0 0 0 0 0 0 0 0 0 0
38432 - 0 0 0 0 0 0 0 0 0 0 0 0
38433 - 0 0 0 0 0 0 0 0 0 0 0 0
38434 - 0 0 0 0 0 0 0 0 0 0 0 0
38435 - 0 0 0 6 6 6 10 10 10 14 14 14
38436 - 22 22 22 26 26 26 30 30 30 34 34 34
38437 - 30 30 30 30 30 30 26 26 26 18 18 18
38438 - 14 14 14 10 10 10 6 6 6 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 0 0 0 0 0 0 0 0 0
38445 - 0 0 0 0 0 0 0 0 0 0 0 0
38446 - 0 0 0 0 0 0 0 0 0 0 0 0
38447 - 0 0 0 0 0 0 0 0 0 0 0 0
38448 - 0 0 0 0 0 1 0 0 1 0 0 0
38449 - 0 0 0 0 0 0 0 0 0 0 0 0
38450 - 0 0 0 0 0 0 0 0 0 0 0 0
38451 - 0 0 0 0 0 0 0 0 0 0 0 0
38452 - 0 0 0 0 0 0 0 0 0 0 0 0
38453 - 0 0 0 0 0 0 0 0 0 0 0 0
38454 - 0 0 0 0 0 0 0 0 0 0 0 0
38455 - 6 6 6 14 14 14 26 26 26 42 42 42
38456 - 54 54 54 66 66 66 78 78 78 78 78 78
38457 - 78 78 78 74 74 74 66 66 66 54 54 54
38458 - 42 42 42 26 26 26 18 18 18 10 10 10
38459 - 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
38465 - 0 0 0 0 0 0 0 0 0 0 0 0
38466 - 0 0 0 0 0 0 0 0 0 0 0 0
38467 - 0 0 0 0 0 0 0 0 0 0 0 0
38468 - 0 0 1 0 0 0 0 0 0 0 0 0
38469 - 0 0 0 0 0 0 0 0 0 0 0 0
38470 - 0 0 0 0 0 0 0 0 0 0 0 0
38471 - 0 0 0 0 0 0 0 0 0 0 0 0
38472 - 0 0 0 0 0 0 0 0 0 0 0 0
38473 - 0 0 0 0 0 0 0 0 0 0 0 0
38474 - 0 0 0 0 0 0 0 0 0 10 10 10
38475 - 22 22 22 42 42 42 66 66 66 86 86 86
38476 - 66 66 66 38 38 38 38 38 38 22 22 22
38477 - 26 26 26 34 34 34 54 54 54 66 66 66
38478 - 86 86 86 70 70 70 46 46 46 26 26 26
38479 - 14 14 14 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
38485 - 0 0 0 0 0 0 0 0 0 0 0 0
38486 - 0 0 0 0 0 0 0 0 0 0 0 0
38487 - 0 0 0 0 0 0 0 0 0 0 0 0
38488 - 0 0 1 0 0 1 0 0 1 0 0 0
38489 - 0 0 0 0 0 0 0 0 0 0 0 0
38490 - 0 0 0 0 0 0 0 0 0 0 0 0
38491 - 0 0 0 0 0 0 0 0 0 0 0 0
38492 - 0 0 0 0 0 0 0 0 0 0 0 0
38493 - 0 0 0 0 0 0 0 0 0 0 0 0
38494 - 0 0 0 0 0 0 10 10 10 26 26 26
38495 - 50 50 50 82 82 82 58 58 58 6 6 6
38496 - 2 2 6 2 2 6 2 2 6 2 2 6
38497 - 2 2 6 2 2 6 2 2 6 2 2 6
38498 - 6 6 6 54 54 54 86 86 86 66 66 66
38499 - 38 38 38 18 18 18 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
38505 - 0 0 0 0 0 0 0 0 0 0 0 0
38506 - 0 0 0 0 0 0 0 0 0 0 0 0
38507 - 0 0 0 0 0 0 0 0 0 0 0 0
38508 - 0 0 0 0 0 0 0 0 0 0 0 0
38509 - 0 0 0 0 0 0 0 0 0 0 0 0
38510 - 0 0 0 0 0 0 0 0 0 0 0 0
38511 - 0 0 0 0 0 0 0 0 0 0 0 0
38512 - 0 0 0 0 0 0 0 0 0 0 0 0
38513 - 0 0 0 0 0 0 0 0 0 0 0 0
38514 - 0 0 0 6 6 6 22 22 22 50 50 50
38515 - 78 78 78 34 34 34 2 2 6 2 2 6
38516 - 2 2 6 2 2 6 2 2 6 2 2 6
38517 - 2 2 6 2 2 6 2 2 6 2 2 6
38518 - 2 2 6 2 2 6 6 6 6 70 70 70
38519 - 78 78 78 46 46 46 22 22 22 6 6 6
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 0 0 0
38524 - 0 0 0 0 0 0 0 0 0 0 0 0
38525 - 0 0 0 0 0 0 0 0 0 0 0 0
38526 - 0 0 0 0 0 0 0 0 0 0 0 0
38527 - 0 0 0 0 0 0 0 0 0 0 0 0
38528 - 0 0 1 0 0 1 0 0 1 0 0 0
38529 - 0 0 0 0 0 0 0 0 0 0 0 0
38530 - 0 0 0 0 0 0 0 0 0 0 0 0
38531 - 0 0 0 0 0 0 0 0 0 0 0 0
38532 - 0 0 0 0 0 0 0 0 0 0 0 0
38533 - 0 0 0 0 0 0 0 0 0 0 0 0
38534 - 6 6 6 18 18 18 42 42 42 82 82 82
38535 - 26 26 26 2 2 6 2 2 6 2 2 6
38536 - 2 2 6 2 2 6 2 2 6 2 2 6
38537 - 2 2 6 2 2 6 2 2 6 14 14 14
38538 - 46 46 46 34 34 34 6 6 6 2 2 6
38539 - 42 42 42 78 78 78 42 42 42 18 18 18
38540 - 6 6 6 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 0 0 0
38544 - 0 0 0 0 0 0 0 0 0 0 0 0
38545 - 0 0 0 0 0 0 0 0 0 0 0 0
38546 - 0 0 0 0 0 0 0 0 0 0 0 0
38547 - 0 0 0 0 0 0 0 0 0 0 0 0
38548 - 0 0 1 0 0 0 0 0 1 0 0 0
38549 - 0 0 0 0 0 0 0 0 0 0 0 0
38550 - 0 0 0 0 0 0 0 0 0 0 0 0
38551 - 0 0 0 0 0 0 0 0 0 0 0 0
38552 - 0 0 0 0 0 0 0 0 0 0 0 0
38553 - 0 0 0 0 0 0 0 0 0 0 0 0
38554 - 10 10 10 30 30 30 66 66 66 58 58 58
38555 - 2 2 6 2 2 6 2 2 6 2 2 6
38556 - 2 2 6 2 2 6 2 2 6 2 2 6
38557 - 2 2 6 2 2 6 2 2 6 26 26 26
38558 - 86 86 86 101 101 101 46 46 46 10 10 10
38559 - 2 2 6 58 58 58 70 70 70 34 34 34
38560 - 10 10 10 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 0 0 0
38564 - 0 0 0 0 0 0 0 0 0 0 0 0
38565 - 0 0 0 0 0 0 0 0 0 0 0 0
38566 - 0 0 0 0 0 0 0 0 0 0 0 0
38567 - 0 0 0 0 0 0 0 0 0 0 0 0
38568 - 0 0 1 0 0 1 0 0 1 0 0 0
38569 - 0 0 0 0 0 0 0 0 0 0 0 0
38570 - 0 0 0 0 0 0 0 0 0 0 0 0
38571 - 0 0 0 0 0 0 0 0 0 0 0 0
38572 - 0 0 0 0 0 0 0 0 0 0 0 0
38573 - 0 0 0 0 0 0 0 0 0 0 0 0
38574 - 14 14 14 42 42 42 86 86 86 10 10 10
38575 - 2 2 6 2 2 6 2 2 6 2 2 6
38576 - 2 2 6 2 2 6 2 2 6 2 2 6
38577 - 2 2 6 2 2 6 2 2 6 30 30 30
38578 - 94 94 94 94 94 94 58 58 58 26 26 26
38579 - 2 2 6 6 6 6 78 78 78 54 54 54
38580 - 22 22 22 6 6 6 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 0 0 0
38584 - 0 0 0 0 0 0 0 0 0 0 0 0
38585 - 0 0 0 0 0 0 0 0 0 0 0 0
38586 - 0 0 0 0 0 0 0 0 0 0 0 0
38587 - 0 0 0 0 0 0 0 0 0 0 0 0
38588 - 0 0 0 0 0 0 0 0 0 0 0 0
38589 - 0 0 0 0 0 0 0 0 0 0 0 0
38590 - 0 0 0 0 0 0 0 0 0 0 0 0
38591 - 0 0 0 0 0 0 0 0 0 0 0 0
38592 - 0 0 0 0 0 0 0 0 0 0 0 0
38593 - 0 0 0 0 0 0 0 0 0 6 6 6
38594 - 22 22 22 62 62 62 62 62 62 2 2 6
38595 - 2 2 6 2 2 6 2 2 6 2 2 6
38596 - 2 2 6 2 2 6 2 2 6 2 2 6
38597 - 2 2 6 2 2 6 2 2 6 26 26 26
38598 - 54 54 54 38 38 38 18 18 18 10 10 10
38599 - 2 2 6 2 2 6 34 34 34 82 82 82
38600 - 38 38 38 14 14 14 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 0 0 0
38604 - 0 0 0 0 0 0 0 0 0 0 0 0
38605 - 0 0 0 0 0 0 0 0 0 0 0 0
38606 - 0 0 0 0 0 0 0 0 0 0 0 0
38607 - 0 0 0 0 0 0 0 0 0 0 0 0
38608 - 0 0 0 0 0 1 0 0 1 0 0 0
38609 - 0 0 0 0 0 0 0 0 0 0 0 0
38610 - 0 0 0 0 0 0 0 0 0 0 0 0
38611 - 0 0 0 0 0 0 0 0 0 0 0 0
38612 - 0 0 0 0 0 0 0 0 0 0 0 0
38613 - 0 0 0 0 0 0 0 0 0 6 6 6
38614 - 30 30 30 78 78 78 30 30 30 2 2 6
38615 - 2 2 6 2 2 6 2 2 6 2 2 6
38616 - 2 2 6 2 2 6 2 2 6 2 2 6
38617 - 2 2 6 2 2 6 2 2 6 10 10 10
38618 - 10 10 10 2 2 6 2 2 6 2 2 6
38619 - 2 2 6 2 2 6 2 2 6 78 78 78
38620 - 50 50 50 18 18 18 6 6 6 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 0 0 0
38624 - 0 0 0 0 0 0 0 0 0 0 0 0
38625 - 0 0 0 0 0 0 0 0 0 0 0 0
38626 - 0 0 0 0 0 0 0 0 0 0 0 0
38627 - 0 0 0 0 0 0 0 0 0 0 0 0
38628 - 0 0 1 0 0 0 0 0 0 0 0 0
38629 - 0 0 0 0 0 0 0 0 0 0 0 0
38630 - 0 0 0 0 0 0 0 0 0 0 0 0
38631 - 0 0 0 0 0 0 0 0 0 0 0 0
38632 - 0 0 0 0 0 0 0 0 0 0 0 0
38633 - 0 0 0 0 0 0 0 0 0 10 10 10
38634 - 38 38 38 86 86 86 14 14 14 2 2 6
38635 - 2 2 6 2 2 6 2 2 6 2 2 6
38636 - 2 2 6 2 2 6 2 2 6 2 2 6
38637 - 2 2 6 2 2 6 2 2 6 2 2 6
38638 - 2 2 6 2 2 6 2 2 6 2 2 6
38639 - 2 2 6 2 2 6 2 2 6 54 54 54
38640 - 66 66 66 26 26 26 6 6 6 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 0 0 0
38644 - 0 0 0 0 0 0 0 0 0 0 0 0
38645 - 0 0 0 0 0 0 0 0 0 0 0 0
38646 - 0 0 0 0 0 0 0 0 0 0 0 0
38647 - 0 0 0 0 0 0 0 0 0 0 0 0
38648 - 0 0 0 0 0 1 0 0 1 0 0 0
38649 - 0 0 0 0 0 0 0 0 0 0 0 0
38650 - 0 0 0 0 0 0 0 0 0 0 0 0
38651 - 0 0 0 0 0 0 0 0 0 0 0 0
38652 - 0 0 0 0 0 0 0 0 0 0 0 0
38653 - 0 0 0 0 0 0 0 0 0 14 14 14
38654 - 42 42 42 82 82 82 2 2 6 2 2 6
38655 - 2 2 6 6 6 6 10 10 10 2 2 6
38656 - 2 2 6 2 2 6 2 2 6 2 2 6
38657 - 2 2 6 2 2 6 2 2 6 6 6 6
38658 - 14 14 14 10 10 10 2 2 6 2 2 6
38659 - 2 2 6 2 2 6 2 2 6 18 18 18
38660 - 82 82 82 34 34 34 10 10 10 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 0 0 0
38664 - 0 0 0 0 0 0 0 0 0 0 0 0
38665 - 0 0 0 0 0 0 0 0 0 0 0 0
38666 - 0 0 0 0 0 0 0 0 0 0 0 0
38667 - 0 0 0 0 0 0 0 0 0 0 0 0
38668 - 0 0 1 0 0 0 0 0 0 0 0 0
38669 - 0 0 0 0 0 0 0 0 0 0 0 0
38670 - 0 0 0 0 0 0 0 0 0 0 0 0
38671 - 0 0 0 0 0 0 0 0 0 0 0 0
38672 - 0 0 0 0 0 0 0 0 0 0 0 0
38673 - 0 0 0 0 0 0 0 0 0 14 14 14
38674 - 46 46 46 86 86 86 2 2 6 2 2 6
38675 - 6 6 6 6 6 6 22 22 22 34 34 34
38676 - 6 6 6 2 2 6 2 2 6 2 2 6
38677 - 2 2 6 2 2 6 18 18 18 34 34 34
38678 - 10 10 10 50 50 50 22 22 22 2 2 6
38679 - 2 2 6 2 2 6 2 2 6 10 10 10
38680 - 86 86 86 42 42 42 14 14 14 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 0 0 0
38684 - 0 0 0 0 0 0 0 0 0 0 0 0
38685 - 0 0 0 0 0 0 0 0 0 0 0 0
38686 - 0 0 0 0 0 0 0 0 0 0 0 0
38687 - 0 0 0 0 0 0 0 0 0 0 0 0
38688 - 0 0 1 0 0 1 0 0 1 0 0 0
38689 - 0 0 0 0 0 0 0 0 0 0 0 0
38690 - 0 0 0 0 0 0 0 0 0 0 0 0
38691 - 0 0 0 0 0 0 0 0 0 0 0 0
38692 - 0 0 0 0 0 0 0 0 0 0 0 0
38693 - 0 0 0 0 0 0 0 0 0 14 14 14
38694 - 46 46 46 86 86 86 2 2 6 2 2 6
38695 - 38 38 38 116 116 116 94 94 94 22 22 22
38696 - 22 22 22 2 2 6 2 2 6 2 2 6
38697 - 14 14 14 86 86 86 138 138 138 162 162 162
38698 -154 154 154 38 38 38 26 26 26 6 6 6
38699 - 2 2 6 2 2 6 2 2 6 2 2 6
38700 - 86 86 86 46 46 46 14 14 14 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 0 0 0
38704 - 0 0 0 0 0 0 0 0 0 0 0 0
38705 - 0 0 0 0 0 0 0 0 0 0 0 0
38706 - 0 0 0 0 0 0 0 0 0 0 0 0
38707 - 0 0 0 0 0 0 0 0 0 0 0 0
38708 - 0 0 0 0 0 0 0 0 0 0 0 0
38709 - 0 0 0 0 0 0 0 0 0 0 0 0
38710 - 0 0 0 0 0 0 0 0 0 0 0 0
38711 - 0 0 0 0 0 0 0 0 0 0 0 0
38712 - 0 0 0 0 0 0 0 0 0 0 0 0
38713 - 0 0 0 0 0 0 0 0 0 14 14 14
38714 - 46 46 46 86 86 86 2 2 6 14 14 14
38715 -134 134 134 198 198 198 195 195 195 116 116 116
38716 - 10 10 10 2 2 6 2 2 6 6 6 6
38717 -101 98 89 187 187 187 210 210 210 218 218 218
38718 -214 214 214 134 134 134 14 14 14 6 6 6
38719 - 2 2 6 2 2 6 2 2 6 2 2 6
38720 - 86 86 86 50 50 50 18 18 18 6 6 6
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 0 0 0
38724 - 0 0 0 0 0 0 0 0 0 0 0 0
38725 - 0 0 0 0 0 0 0 0 0 0 0 0
38726 - 0 0 0 0 0 0 0 0 0 0 0 0
38727 - 0 0 0 0 0 0 0 0 1 0 0 0
38728 - 0 0 1 0 0 1 0 0 1 0 0 0
38729 - 0 0 0 0 0 0 0 0 0 0 0 0
38730 - 0 0 0 0 0 0 0 0 0 0 0 0
38731 - 0 0 0 0 0 0 0 0 0 0 0 0
38732 - 0 0 0 0 0 0 0 0 0 0 0 0
38733 - 0 0 0 0 0 0 0 0 0 14 14 14
38734 - 46 46 46 86 86 86 2 2 6 54 54 54
38735 -218 218 218 195 195 195 226 226 226 246 246 246
38736 - 58 58 58 2 2 6 2 2 6 30 30 30
38737 -210 210 210 253 253 253 174 174 174 123 123 123
38738 -221 221 221 234 234 234 74 74 74 2 2 6
38739 - 2 2 6 2 2 6 2 2 6 2 2 6
38740 - 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0
38744 - 0 0 0 0 0 0 0 0 0 0 0 0
38745 - 0 0 0 0 0 0 0 0 0 0 0 0
38746 - 0 0 0 0 0 0 0 0 0 0 0 0
38747 - 0 0 0 0 0 0 0 0 0 0 0 0
38748 - 0 0 0 0 0 0 0 0 0 0 0 0
38749 - 0 0 0 0 0 0 0 0 0 0 0 0
38750 - 0 0 0 0 0 0 0 0 0 0 0 0
38751 - 0 0 0 0 0 0 0 0 0 0 0 0
38752 - 0 0 0 0 0 0 0 0 0 0 0 0
38753 - 0 0 0 0 0 0 0 0 0 14 14 14
38754 - 46 46 46 82 82 82 2 2 6 106 106 106
38755 -170 170 170 26 26 26 86 86 86 226 226 226
38756 -123 123 123 10 10 10 14 14 14 46 46 46
38757 -231 231 231 190 190 190 6 6 6 70 70 70
38758 - 90 90 90 238 238 238 158 158 158 2 2 6
38759 - 2 2 6 2 2 6 2 2 6 2 2 6
38760 - 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0
38764 - 0 0 0 0 0 0 0 0 0 0 0 0
38765 - 0 0 0 0 0 0 0 0 0 0 0 0
38766 - 0 0 0 0 0 0 0 0 0 0 0 0
38767 - 0 0 0 0 0 0 0 0 1 0 0 0
38768 - 0 0 1 0 0 1 0 0 1 0 0 0
38769 - 0 0 0 0 0 0 0 0 0 0 0 0
38770 - 0 0 0 0 0 0 0 0 0 0 0 0
38771 - 0 0 0 0 0 0 0 0 0 0 0 0
38772 - 0 0 0 0 0 0 0 0 0 0 0 0
38773 - 0 0 0 0 0 0 0 0 0 14 14 14
38774 - 42 42 42 86 86 86 6 6 6 116 116 116
38775 -106 106 106 6 6 6 70 70 70 149 149 149
38776 -128 128 128 18 18 18 38 38 38 54 54 54
38777 -221 221 221 106 106 106 2 2 6 14 14 14
38778 - 46 46 46 190 190 190 198 198 198 2 2 6
38779 - 2 2 6 2 2 6 2 2 6 2 2 6
38780 - 74 74 74 62 62 62 22 22 22 6 6 6
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 0 0 0
38784 - 0 0 0 0 0 0 0 0 0 0 0 0
38785 - 0 0 0 0 0 0 0 0 0 0 0 0
38786 - 0 0 0 0 0 0 0 0 0 0 0 0
38787 - 0 0 0 0 0 0 0 0 1 0 0 0
38788 - 0 0 1 0 0 0 0 0 1 0 0 0
38789 - 0 0 0 0 0 0 0 0 0 0 0 0
38790 - 0 0 0 0 0 0 0 0 0 0 0 0
38791 - 0 0 0 0 0 0 0 0 0 0 0 0
38792 - 0 0 0 0 0 0 0 0 0 0 0 0
38793 - 0 0 0 0 0 0 0 0 0 14 14 14
38794 - 42 42 42 94 94 94 14 14 14 101 101 101
38795 -128 128 128 2 2 6 18 18 18 116 116 116
38796 -118 98 46 121 92 8 121 92 8 98 78 10
38797 -162 162 162 106 106 106 2 2 6 2 2 6
38798 - 2 2 6 195 195 195 195 195 195 6 6 6
38799 - 2 2 6 2 2 6 2 2 6 2 2 6
38800 - 74 74 74 62 62 62 22 22 22 6 6 6
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 0 0 0
38804 - 0 0 0 0 0 0 0 0 0 0 0 0
38805 - 0 0 0 0 0 0 0 0 0 0 0 0
38806 - 0 0 0 0 0 0 0 0 0 0 0 0
38807 - 0 0 0 0 0 0 0 0 1 0 0 1
38808 - 0 0 1 0 0 0 0 0 1 0 0 0
38809 - 0 0 0 0 0 0 0 0 0 0 0 0
38810 - 0 0 0 0 0 0 0 0 0 0 0 0
38811 - 0 0 0 0 0 0 0 0 0 0 0 0
38812 - 0 0 0 0 0 0 0 0 0 0 0 0
38813 - 0 0 0 0 0 0 0 0 0 10 10 10
38814 - 38 38 38 90 90 90 14 14 14 58 58 58
38815 -210 210 210 26 26 26 54 38 6 154 114 10
38816 -226 170 11 236 186 11 225 175 15 184 144 12
38817 -215 174 15 175 146 61 37 26 9 2 2 6
38818 - 70 70 70 246 246 246 138 138 138 2 2 6
38819 - 2 2 6 2 2 6 2 2 6 2 2 6
38820 - 70 70 70 66 66 66 26 26 26 6 6 6
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 0 0 0
38824 - 0 0 0 0 0 0 0 0 0 0 0 0
38825 - 0 0 0 0 0 0 0 0 0 0 0 0
38826 - 0 0 0 0 0 0 0 0 0 0 0 0
38827 - 0 0 0 0 0 0 0 0 0 0 0 0
38828 - 0 0 0 0 0 0 0 0 0 0 0 0
38829 - 0 0 0 0 0 0 0 0 0 0 0 0
38830 - 0 0 0 0 0 0 0 0 0 0 0 0
38831 - 0 0 0 0 0 0 0 0 0 0 0 0
38832 - 0 0 0 0 0 0 0 0 0 0 0 0
38833 - 0 0 0 0 0 0 0 0 0 10 10 10
38834 - 38 38 38 86 86 86 14 14 14 10 10 10
38835 -195 195 195 188 164 115 192 133 9 225 175 15
38836 -239 182 13 234 190 10 232 195 16 232 200 30
38837 -245 207 45 241 208 19 232 195 16 184 144 12
38838 -218 194 134 211 206 186 42 42 42 2 2 6
38839 - 2 2 6 2 2 6 2 2 6 2 2 6
38840 - 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0
38844 - 0 0 0 0 0 0 0 0 0 0 0 0
38845 - 0 0 0 0 0 0 0 0 0 0 0 0
38846 - 0 0 0 0 0 0 0 0 0 0 0 0
38847 - 0 0 0 0 0 0 0 0 0 0 0 0
38848 - 0 0 0 0 0 0 0 0 0 0 0 0
38849 - 0 0 0 0 0 0 0 0 0 0 0 0
38850 - 0 0 0 0 0 0 0 0 0 0 0 0
38851 - 0 0 0 0 0 0 0 0 0 0 0 0
38852 - 0 0 0 0 0 0 0 0 0 0 0 0
38853 - 0 0 0 0 0 0 0 0 0 10 10 10
38854 - 34 34 34 86 86 86 14 14 14 2 2 6
38855 -121 87 25 192 133 9 219 162 10 239 182 13
38856 -236 186 11 232 195 16 241 208 19 244 214 54
38857 -246 218 60 246 218 38 246 215 20 241 208 19
38858 -241 208 19 226 184 13 121 87 25 2 2 6
38859 - 2 2 6 2 2 6 2 2 6 2 2 6
38860 - 50 50 50 82 82 82 34 34 34 10 10 10
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 0 0 0
38864 - 0 0 0 0 0 0 0 0 0 0 0 0
38865 - 0 0 0 0 0 0 0 0 0 0 0 0
38866 - 0 0 0 0 0 0 0 0 0 0 0 0
38867 - 0 0 0 0 0 0 0 0 0 0 0 0
38868 - 0 0 0 0 0 0 0 0 0 0 0 0
38869 - 0 0 0 0 0 0 0 0 0 0 0 0
38870 - 0 0 0 0 0 0 0 0 0 0 0 0
38871 - 0 0 0 0 0 0 0 0 0 0 0 0
38872 - 0 0 0 0 0 0 0 0 0 0 0 0
38873 - 0 0 0 0 0 0 0 0 0 10 10 10
38874 - 34 34 34 82 82 82 30 30 30 61 42 6
38875 -180 123 7 206 145 10 230 174 11 239 182 13
38876 -234 190 10 238 202 15 241 208 19 246 218 74
38877 -246 218 38 246 215 20 246 215 20 246 215 20
38878 -226 184 13 215 174 15 184 144 12 6 6 6
38879 - 2 2 6 2 2 6 2 2 6 2 2 6
38880 - 26 26 26 94 94 94 42 42 42 14 14 14
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 0 0 0
38884 - 0 0 0 0 0 0 0 0 0 0 0 0
38885 - 0 0 0 0 0 0 0 0 0 0 0 0
38886 - 0 0 0 0 0 0 0 0 0 0 0 0
38887 - 0 0 0 0 0 0 0 0 0 0 0 0
38888 - 0 0 0 0 0 0 0 0 0 0 0 0
38889 - 0 0 0 0 0 0 0 0 0 0 0 0
38890 - 0 0 0 0 0 0 0 0 0 0 0 0
38891 - 0 0 0 0 0 0 0 0 0 0 0 0
38892 - 0 0 0 0 0 0 0 0 0 0 0 0
38893 - 0 0 0 0 0 0 0 0 0 10 10 10
38894 - 30 30 30 78 78 78 50 50 50 104 69 6
38895 -192 133 9 216 158 10 236 178 12 236 186 11
38896 -232 195 16 241 208 19 244 214 54 245 215 43
38897 -246 215 20 246 215 20 241 208 19 198 155 10
38898 -200 144 11 216 158 10 156 118 10 2 2 6
38899 - 2 2 6 2 2 6 2 2 6 2 2 6
38900 - 6 6 6 90 90 90 54 54 54 18 18 18
38901 - 6 6 6 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 0 0 0 0 0 0
38904 - 0 0 0 0 0 0 0 0 0 0 0 0
38905 - 0 0 0 0 0 0 0 0 0 0 0 0
38906 - 0 0 0 0 0 0 0 0 0 0 0 0
38907 - 0 0 0 0 0 0 0 0 0 0 0 0
38908 - 0 0 0 0 0 0 0 0 0 0 0 0
38909 - 0 0 0 0 0 0 0 0 0 0 0 0
38910 - 0 0 0 0 0 0 0 0 0 0 0 0
38911 - 0 0 0 0 0 0 0 0 0 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 10 10 10
38914 - 30 30 30 78 78 78 46 46 46 22 22 22
38915 -137 92 6 210 162 10 239 182 13 238 190 10
38916 -238 202 15 241 208 19 246 215 20 246 215 20
38917 -241 208 19 203 166 17 185 133 11 210 150 10
38918 -216 158 10 210 150 10 102 78 10 2 2 6
38919 - 6 6 6 54 54 54 14 14 14 2 2 6
38920 - 2 2 6 62 62 62 74 74 74 30 30 30
38921 - 10 10 10 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 0 0 0 0 0 0
38924 - 0 0 0 0 0 0 0 0 0 0 0 0
38925 - 0 0 0 0 0 0 0 0 0 0 0 0
38926 - 0 0 0 0 0 0 0 0 0 0 0 0
38927 - 0 0 0 0 0 0 0 0 0 0 0 0
38928 - 0 0 0 0 0 0 0 0 0 0 0 0
38929 - 0 0 0 0 0 0 0 0 0 0 0 0
38930 - 0 0 0 0 0 0 0 0 0 0 0 0
38931 - 0 0 0 0 0 0 0 0 0 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 10 10 10
38934 - 34 34 34 78 78 78 50 50 50 6 6 6
38935 - 94 70 30 139 102 15 190 146 13 226 184 13
38936 -232 200 30 232 195 16 215 174 15 190 146 13
38937 -168 122 10 192 133 9 210 150 10 213 154 11
38938 -202 150 34 182 157 106 101 98 89 2 2 6
38939 - 2 2 6 78 78 78 116 116 116 58 58 58
38940 - 2 2 6 22 22 22 90 90 90 46 46 46
38941 - 18 18 18 6 6 6 0 0 0 0 0 0
38942 - 0 0 0 0 0 0 0 0 0 0 0 0
38943 - 0 0 0 0 0 0 0 0 0 0 0 0
38944 - 0 0 0 0 0 0 0 0 0 0 0 0
38945 - 0 0 0 0 0 0 0 0 0 0 0 0
38946 - 0 0 0 0 0 0 0 0 0 0 0 0
38947 - 0 0 0 0 0 0 0 0 0 0 0 0
38948 - 0 0 0 0 0 0 0 0 0 0 0 0
38949 - 0 0 0 0 0 0 0 0 0 0 0 0
38950 - 0 0 0 0 0 0 0 0 0 0 0 0
38951 - 0 0 0 0 0 0 0 0 0 0 0 0
38952 - 0 0 0 0 0 0 0 0 0 0 0 0
38953 - 0 0 0 0 0 0 0 0 0 10 10 10
38954 - 38 38 38 86 86 86 50 50 50 6 6 6
38955 -128 128 128 174 154 114 156 107 11 168 122 10
38956 -198 155 10 184 144 12 197 138 11 200 144 11
38957 -206 145 10 206 145 10 197 138 11 188 164 115
38958 -195 195 195 198 198 198 174 174 174 14 14 14
38959 - 2 2 6 22 22 22 116 116 116 116 116 116
38960 - 22 22 22 2 2 6 74 74 74 70 70 70
38961 - 30 30 30 10 10 10 0 0 0 0 0 0
38962 - 0 0 0 0 0 0 0 0 0 0 0 0
38963 - 0 0 0 0 0 0 0 0 0 0 0 0
38964 - 0 0 0 0 0 0 0 0 0 0 0 0
38965 - 0 0 0 0 0 0 0 0 0 0 0 0
38966 - 0 0 0 0 0 0 0 0 0 0 0 0
38967 - 0 0 0 0 0 0 0 0 0 0 0 0
38968 - 0 0 0 0 0 0 0 0 0 0 0 0
38969 - 0 0 0 0 0 0 0 0 0 0 0 0
38970 - 0 0 0 0 0 0 0 0 0 0 0 0
38971 - 0 0 0 0 0 0 0 0 0 0 0 0
38972 - 0 0 0 0 0 0 0 0 0 0 0 0
38973 - 0 0 0 0 0 0 6 6 6 18 18 18
38974 - 50 50 50 101 101 101 26 26 26 10 10 10
38975 -138 138 138 190 190 190 174 154 114 156 107 11
38976 -197 138 11 200 144 11 197 138 11 192 133 9
38977 -180 123 7 190 142 34 190 178 144 187 187 187
38978 -202 202 202 221 221 221 214 214 214 66 66 66
38979 - 2 2 6 2 2 6 50 50 50 62 62 62
38980 - 6 6 6 2 2 6 10 10 10 90 90 90
38981 - 50 50 50 18 18 18 6 6 6 0 0 0
38982 - 0 0 0 0 0 0 0 0 0 0 0 0
38983 - 0 0 0 0 0 0 0 0 0 0 0 0
38984 - 0 0 0 0 0 0 0 0 0 0 0 0
38985 - 0 0 0 0 0 0 0 0 0 0 0 0
38986 - 0 0 0 0 0 0 0 0 0 0 0 0
38987 - 0 0 0 0 0 0 0 0 0 0 0 0
38988 - 0 0 0 0 0 0 0 0 0 0 0 0
38989 - 0 0 0 0 0 0 0 0 0 0 0 0
38990 - 0 0 0 0 0 0 0 0 0 0 0 0
38991 - 0 0 0 0 0 0 0 0 0 0 0 0
38992 - 0 0 0 0 0 0 0 0 0 0 0 0
38993 - 0 0 0 0 0 0 10 10 10 34 34 34
38994 - 74 74 74 74 74 74 2 2 6 6 6 6
38995 -144 144 144 198 198 198 190 190 190 178 166 146
38996 -154 121 60 156 107 11 156 107 11 168 124 44
38997 -174 154 114 187 187 187 190 190 190 210 210 210
38998 -246 246 246 253 253 253 253 253 253 182 182 182
38999 - 6 6 6 2 2 6 2 2 6 2 2 6
39000 - 2 2 6 2 2 6 2 2 6 62 62 62
39001 - 74 74 74 34 34 34 14 14 14 0 0 0
39002 - 0 0 0 0 0 0 0 0 0 0 0 0
39003 - 0 0 0 0 0 0 0 0 0 0 0 0
39004 - 0 0 0 0 0 0 0 0 0 0 0 0
39005 - 0 0 0 0 0 0 0 0 0 0 0 0
39006 - 0 0 0 0 0 0 0 0 0 0 0 0
39007 - 0 0 0 0 0 0 0 0 0 0 0 0
39008 - 0 0 0 0 0 0 0 0 0 0 0 0
39009 - 0 0 0 0 0 0 0 0 0 0 0 0
39010 - 0 0 0 0 0 0 0 0 0 0 0 0
39011 - 0 0 0 0 0 0 0 0 0 0 0 0
39012 - 0 0 0 0 0 0 0 0 0 0 0 0
39013 - 0 0 0 10 10 10 22 22 22 54 54 54
39014 - 94 94 94 18 18 18 2 2 6 46 46 46
39015 -234 234 234 221 221 221 190 190 190 190 190 190
39016 -190 190 190 187 187 187 187 187 187 190 190 190
39017 -190 190 190 195 195 195 214 214 214 242 242 242
39018 -253 253 253 253 253 253 253 253 253 253 253 253
39019 - 82 82 82 2 2 6 2 2 6 2 2 6
39020 - 2 2 6 2 2 6 2 2 6 14 14 14
39021 - 86 86 86 54 54 54 22 22 22 6 6 6
39022 - 0 0 0 0 0 0 0 0 0 0 0 0
39023 - 0 0 0 0 0 0 0 0 0 0 0 0
39024 - 0 0 0 0 0 0 0 0 0 0 0 0
39025 - 0 0 0 0 0 0 0 0 0 0 0 0
39026 - 0 0 0 0 0 0 0 0 0 0 0 0
39027 - 0 0 0 0 0 0 0 0 0 0 0 0
39028 - 0 0 0 0 0 0 0 0 0 0 0 0
39029 - 0 0 0 0 0 0 0 0 0 0 0 0
39030 - 0 0 0 0 0 0 0 0 0 0 0 0
39031 - 0 0 0 0 0 0 0 0 0 0 0 0
39032 - 0 0 0 0 0 0 0 0 0 0 0 0
39033 - 6 6 6 18 18 18 46 46 46 90 90 90
39034 - 46 46 46 18 18 18 6 6 6 182 182 182
39035 -253 253 253 246 246 246 206 206 206 190 190 190
39036 -190 190 190 190 190 190 190 190 190 190 190 190
39037 -206 206 206 231 231 231 250 250 250 253 253 253
39038 -253 253 253 253 253 253 253 253 253 253 253 253
39039 -202 202 202 14 14 14 2 2 6 2 2 6
39040 - 2 2 6 2 2 6 2 2 6 2 2 6
39041 - 42 42 42 86 86 86 42 42 42 18 18 18
39042 - 6 6 6 0 0 0 0 0 0 0 0 0
39043 - 0 0 0 0 0 0 0 0 0 0 0 0
39044 - 0 0 0 0 0 0 0 0 0 0 0 0
39045 - 0 0 0 0 0 0 0 0 0 0 0 0
39046 - 0 0 0 0 0 0 0 0 0 0 0 0
39047 - 0 0 0 0 0 0 0 0 0 0 0 0
39048 - 0 0 0 0 0 0 0 0 0 0 0 0
39049 - 0 0 0 0 0 0 0 0 0 0 0 0
39050 - 0 0 0 0 0 0 0 0 0 0 0 0
39051 - 0 0 0 0 0 0 0 0 0 0 0 0
39052 - 0 0 0 0 0 0 0 0 0 6 6 6
39053 - 14 14 14 38 38 38 74 74 74 66 66 66
39054 - 2 2 6 6 6 6 90 90 90 250 250 250
39055 -253 253 253 253 253 253 238 238 238 198 198 198
39056 -190 190 190 190 190 190 195 195 195 221 221 221
39057 -246 246 246 253 253 253 253 253 253 253 253 253
39058 -253 253 253 253 253 253 253 253 253 253 253 253
39059 -253 253 253 82 82 82 2 2 6 2 2 6
39060 - 2 2 6 2 2 6 2 2 6 2 2 6
39061 - 2 2 6 78 78 78 70 70 70 34 34 34
39062 - 14 14 14 6 6 6 0 0 0 0 0 0
39063 - 0 0 0 0 0 0 0 0 0 0 0 0
39064 - 0 0 0 0 0 0 0 0 0 0 0 0
39065 - 0 0 0 0 0 0 0 0 0 0 0 0
39066 - 0 0 0 0 0 0 0 0 0 0 0 0
39067 - 0 0 0 0 0 0 0 0 0 0 0 0
39068 - 0 0 0 0 0 0 0 0 0 0 0 0
39069 - 0 0 0 0 0 0 0 0 0 0 0 0
39070 - 0 0 0 0 0 0 0 0 0 0 0 0
39071 - 0 0 0 0 0 0 0 0 0 0 0 0
39072 - 0 0 0 0 0 0 0 0 0 14 14 14
39073 - 34 34 34 66 66 66 78 78 78 6 6 6
39074 - 2 2 6 18 18 18 218 218 218 253 253 253
39075 -253 253 253 253 253 253 253 253 253 246 246 246
39076 -226 226 226 231 231 231 246 246 246 253 253 253
39077 -253 253 253 253 253 253 253 253 253 253 253 253
39078 -253 253 253 253 253 253 253 253 253 253 253 253
39079 -253 253 253 178 178 178 2 2 6 2 2 6
39080 - 2 2 6 2 2 6 2 2 6 2 2 6
39081 - 2 2 6 18 18 18 90 90 90 62 62 62
39082 - 30 30 30 10 10 10 0 0 0 0 0 0
39083 - 0 0 0 0 0 0 0 0 0 0 0 0
39084 - 0 0 0 0 0 0 0 0 0 0 0 0
39085 - 0 0 0 0 0 0 0 0 0 0 0 0
39086 - 0 0 0 0 0 0 0 0 0 0 0 0
39087 - 0 0 0 0 0 0 0 0 0 0 0 0
39088 - 0 0 0 0 0 0 0 0 0 0 0 0
39089 - 0 0 0 0 0 0 0 0 0 0 0 0
39090 - 0 0 0 0 0 0 0 0 0 0 0 0
39091 - 0 0 0 0 0 0 0 0 0 0 0 0
39092 - 0 0 0 0 0 0 10 10 10 26 26 26
39093 - 58 58 58 90 90 90 18 18 18 2 2 6
39094 - 2 2 6 110 110 110 253 253 253 253 253 253
39095 -253 253 253 253 253 253 253 253 253 253 253 253
39096 -250 250 250 253 253 253 253 253 253 253 253 253
39097 -253 253 253 253 253 253 253 253 253 253 253 253
39098 -253 253 253 253 253 253 253 253 253 253 253 253
39099 -253 253 253 231 231 231 18 18 18 2 2 6
39100 - 2 2 6 2 2 6 2 2 6 2 2 6
39101 - 2 2 6 2 2 6 18 18 18 94 94 94
39102 - 54 54 54 26 26 26 10 10 10 0 0 0
39103 - 0 0 0 0 0 0 0 0 0 0 0 0
39104 - 0 0 0 0 0 0 0 0 0 0 0 0
39105 - 0 0 0 0 0 0 0 0 0 0 0 0
39106 - 0 0 0 0 0 0 0 0 0 0 0 0
39107 - 0 0 0 0 0 0 0 0 0 0 0 0
39108 - 0 0 0 0 0 0 0 0 0 0 0 0
39109 - 0 0 0 0 0 0 0 0 0 0 0 0
39110 - 0 0 0 0 0 0 0 0 0 0 0 0
39111 - 0 0 0 0 0 0 0 0 0 0 0 0
39112 - 0 0 0 6 6 6 22 22 22 50 50 50
39113 - 90 90 90 26 26 26 2 2 6 2 2 6
39114 - 14 14 14 195 195 195 250 250 250 253 253 253
39115 -253 253 253 253 253 253 253 253 253 253 253 253
39116 -253 253 253 253 253 253 253 253 253 253 253 253
39117 -253 253 253 253 253 253 253 253 253 253 253 253
39118 -253 253 253 253 253 253 253 253 253 253 253 253
39119 -250 250 250 242 242 242 54 54 54 2 2 6
39120 - 2 2 6 2 2 6 2 2 6 2 2 6
39121 - 2 2 6 2 2 6 2 2 6 38 38 38
39122 - 86 86 86 50 50 50 22 22 22 6 6 6
39123 - 0 0 0 0 0 0 0 0 0 0 0 0
39124 - 0 0 0 0 0 0 0 0 0 0 0 0
39125 - 0 0 0 0 0 0 0 0 0 0 0 0
39126 - 0 0 0 0 0 0 0 0 0 0 0 0
39127 - 0 0 0 0 0 0 0 0 0 0 0 0
39128 - 0 0 0 0 0 0 0 0 0 0 0 0
39129 - 0 0 0 0 0 0 0 0 0 0 0 0
39130 - 0 0 0 0 0 0 0 0 0 0 0 0
39131 - 0 0 0 0 0 0 0 0 0 0 0 0
39132 - 6 6 6 14 14 14 38 38 38 82 82 82
39133 - 34 34 34 2 2 6 2 2 6 2 2 6
39134 - 42 42 42 195 195 195 246 246 246 253 253 253
39135 -253 253 253 253 253 253 253 253 253 250 250 250
39136 -242 242 242 242 242 242 250 250 250 253 253 253
39137 -253 253 253 253 253 253 253 253 253 253 253 253
39138 -253 253 253 250 250 250 246 246 246 238 238 238
39139 -226 226 226 231 231 231 101 101 101 6 6 6
39140 - 2 2 6 2 2 6 2 2 6 2 2 6
39141 - 2 2 6 2 2 6 2 2 6 2 2 6
39142 - 38 38 38 82 82 82 42 42 42 14 14 14
39143 - 6 6 6 0 0 0 0 0 0 0 0 0
39144 - 0 0 0 0 0 0 0 0 0 0 0 0
39145 - 0 0 0 0 0 0 0 0 0 0 0 0
39146 - 0 0 0 0 0 0 0 0 0 0 0 0
39147 - 0 0 0 0 0 0 0 0 0 0 0 0
39148 - 0 0 0 0 0 0 0 0 0 0 0 0
39149 - 0 0 0 0 0 0 0 0 0 0 0 0
39150 - 0 0 0 0 0 0 0 0 0 0 0 0
39151 - 0 0 0 0 0 0 0 0 0 0 0 0
39152 - 10 10 10 26 26 26 62 62 62 66 66 66
39153 - 2 2 6 2 2 6 2 2 6 6 6 6
39154 - 70 70 70 170 170 170 206 206 206 234 234 234
39155 -246 246 246 250 250 250 250 250 250 238 238 238
39156 -226 226 226 231 231 231 238 238 238 250 250 250
39157 -250 250 250 250 250 250 246 246 246 231 231 231
39158 -214 214 214 206 206 206 202 202 202 202 202 202
39159 -198 198 198 202 202 202 182 182 182 18 18 18
39160 - 2 2 6 2 2 6 2 2 6 2 2 6
39161 - 2 2 6 2 2 6 2 2 6 2 2 6
39162 - 2 2 6 62 62 62 66 66 66 30 30 30
39163 - 10 10 10 0 0 0 0 0 0 0 0 0
39164 - 0 0 0 0 0 0 0 0 0 0 0 0
39165 - 0 0 0 0 0 0 0 0 0 0 0 0
39166 - 0 0 0 0 0 0 0 0 0 0 0 0
39167 - 0 0 0 0 0 0 0 0 0 0 0 0
39168 - 0 0 0 0 0 0 0 0 0 0 0 0
39169 - 0 0 0 0 0 0 0 0 0 0 0 0
39170 - 0 0 0 0 0 0 0 0 0 0 0 0
39171 - 0 0 0 0 0 0 0 0 0 0 0 0
39172 - 14 14 14 42 42 42 82 82 82 18 18 18
39173 - 2 2 6 2 2 6 2 2 6 10 10 10
39174 - 94 94 94 182 182 182 218 218 218 242 242 242
39175 -250 250 250 253 253 253 253 253 253 250 250 250
39176 -234 234 234 253 253 253 253 253 253 253 253 253
39177 -253 253 253 253 253 253 253 253 253 246 246 246
39178 -238 238 238 226 226 226 210 210 210 202 202 202
39179 -195 195 195 195 195 195 210 210 210 158 158 158
39180 - 6 6 6 14 14 14 50 50 50 14 14 14
39181 - 2 2 6 2 2 6 2 2 6 2 2 6
39182 - 2 2 6 6 6 6 86 86 86 46 46 46
39183 - 18 18 18 6 6 6 0 0 0 0 0 0
39184 - 0 0 0 0 0 0 0 0 0 0 0 0
39185 - 0 0 0 0 0 0 0 0 0 0 0 0
39186 - 0 0 0 0 0 0 0 0 0 0 0 0
39187 - 0 0 0 0 0 0 0 0 0 0 0 0
39188 - 0 0 0 0 0 0 0 0 0 0 0 0
39189 - 0 0 0 0 0 0 0 0 0 0 0 0
39190 - 0 0 0 0 0 0 0 0 0 0 0 0
39191 - 0 0 0 0 0 0 0 0 0 6 6 6
39192 - 22 22 22 54 54 54 70 70 70 2 2 6
39193 - 2 2 6 10 10 10 2 2 6 22 22 22
39194 -166 166 166 231 231 231 250 250 250 253 253 253
39195 -253 253 253 253 253 253 253 253 253 250 250 250
39196 -242 242 242 253 253 253 253 253 253 253 253 253
39197 -253 253 253 253 253 253 253 253 253 253 253 253
39198 -253 253 253 253 253 253 253 253 253 246 246 246
39199 -231 231 231 206 206 206 198 198 198 226 226 226
39200 - 94 94 94 2 2 6 6 6 6 38 38 38
39201 - 30 30 30 2 2 6 2 2 6 2 2 6
39202 - 2 2 6 2 2 6 62 62 62 66 66 66
39203 - 26 26 26 10 10 10 0 0 0 0 0 0
39204 - 0 0 0 0 0 0 0 0 0 0 0 0
39205 - 0 0 0 0 0 0 0 0 0 0 0 0
39206 - 0 0 0 0 0 0 0 0 0 0 0 0
39207 - 0 0 0 0 0 0 0 0 0 0 0 0
39208 - 0 0 0 0 0 0 0 0 0 0 0 0
39209 - 0 0 0 0 0 0 0 0 0 0 0 0
39210 - 0 0 0 0 0 0 0 0 0 0 0 0
39211 - 0 0 0 0 0 0 0 0 0 10 10 10
39212 - 30 30 30 74 74 74 50 50 50 2 2 6
39213 - 26 26 26 26 26 26 2 2 6 106 106 106
39214 -238 238 238 253 253 253 253 253 253 253 253 253
39215 -253 253 253 253 253 253 253 253 253 253 253 253
39216 -253 253 253 253 253 253 253 253 253 253 253 253
39217 -253 253 253 253 253 253 253 253 253 253 253 253
39218 -253 253 253 253 253 253 253 253 253 253 253 253
39219 -253 253 253 246 246 246 218 218 218 202 202 202
39220 -210 210 210 14 14 14 2 2 6 2 2 6
39221 - 30 30 30 22 22 22 2 2 6 2 2 6
39222 - 2 2 6 2 2 6 18 18 18 86 86 86
39223 - 42 42 42 14 14 14 0 0 0 0 0 0
39224 - 0 0 0 0 0 0 0 0 0 0 0 0
39225 - 0 0 0 0 0 0 0 0 0 0 0 0
39226 - 0 0 0 0 0 0 0 0 0 0 0 0
39227 - 0 0 0 0 0 0 0 0 0 0 0 0
39228 - 0 0 0 0 0 0 0 0 0 0 0 0
39229 - 0 0 0 0 0 0 0 0 0 0 0 0
39230 - 0 0 0 0 0 0 0 0 0 0 0 0
39231 - 0 0 0 0 0 0 0 0 0 14 14 14
39232 - 42 42 42 90 90 90 22 22 22 2 2 6
39233 - 42 42 42 2 2 6 18 18 18 218 218 218
39234 -253 253 253 253 253 253 253 253 253 253 253 253
39235 -253 253 253 253 253 253 253 253 253 253 253 253
39236 -253 253 253 253 253 253 253 253 253 253 253 253
39237 -253 253 253 253 253 253 253 253 253 253 253 253
39238 -253 253 253 253 253 253 253 253 253 253 253 253
39239 -253 253 253 253 253 253 250 250 250 221 221 221
39240 -218 218 218 101 101 101 2 2 6 14 14 14
39241 - 18 18 18 38 38 38 10 10 10 2 2 6
39242 - 2 2 6 2 2 6 2 2 6 78 78 78
39243 - 58 58 58 22 22 22 6 6 6 0 0 0
39244 - 0 0 0 0 0 0 0 0 0 0 0 0
39245 - 0 0 0 0 0 0 0 0 0 0 0 0
39246 - 0 0 0 0 0 0 0 0 0 0 0 0
39247 - 0 0 0 0 0 0 0 0 0 0 0 0
39248 - 0 0 0 0 0 0 0 0 0 0 0 0
39249 - 0 0 0 0 0 0 0 0 0 0 0 0
39250 - 0 0 0 0 0 0 0 0 0 0 0 0
39251 - 0 0 0 0 0 0 6 6 6 18 18 18
39252 - 54 54 54 82 82 82 2 2 6 26 26 26
39253 - 22 22 22 2 2 6 123 123 123 253 253 253
39254 -253 253 253 253 253 253 253 253 253 253 253 253
39255 -253 253 253 253 253 253 253 253 253 253 253 253
39256 -253 253 253 253 253 253 253 253 253 253 253 253
39257 -253 253 253 253 253 253 253 253 253 253 253 253
39258 -253 253 253 253 253 253 253 253 253 253 253 253
39259 -253 253 253 253 253 253 253 253 253 250 250 250
39260 -238 238 238 198 198 198 6 6 6 38 38 38
39261 - 58 58 58 26 26 26 38 38 38 2 2 6
39262 - 2 2 6 2 2 6 2 2 6 46 46 46
39263 - 78 78 78 30 30 30 10 10 10 0 0 0
39264 - 0 0 0 0 0 0 0 0 0 0 0 0
39265 - 0 0 0 0 0 0 0 0 0 0 0 0
39266 - 0 0 0 0 0 0 0 0 0 0 0 0
39267 - 0 0 0 0 0 0 0 0 0 0 0 0
39268 - 0 0 0 0 0 0 0 0 0 0 0 0
39269 - 0 0 0 0 0 0 0 0 0 0 0 0
39270 - 0 0 0 0 0 0 0 0 0 0 0 0
39271 - 0 0 0 0 0 0 10 10 10 30 30 30
39272 - 74 74 74 58 58 58 2 2 6 42 42 42
39273 - 2 2 6 22 22 22 231 231 231 253 253 253
39274 -253 253 253 253 253 253 253 253 253 253 253 253
39275 -253 253 253 253 253 253 253 253 253 250 250 250
39276 -253 253 253 253 253 253 253 253 253 253 253 253
39277 -253 253 253 253 253 253 253 253 253 253 253 253
39278 -253 253 253 253 253 253 253 253 253 253 253 253
39279 -253 253 253 253 253 253 253 253 253 253 253 253
39280 -253 253 253 246 246 246 46 46 46 38 38 38
39281 - 42 42 42 14 14 14 38 38 38 14 14 14
39282 - 2 2 6 2 2 6 2 2 6 6 6 6
39283 - 86 86 86 46 46 46 14 14 14 0 0 0
39284 - 0 0 0 0 0 0 0 0 0 0 0 0
39285 - 0 0 0 0 0 0 0 0 0 0 0 0
39286 - 0 0 0 0 0 0 0 0 0 0 0 0
39287 - 0 0 0 0 0 0 0 0 0 0 0 0
39288 - 0 0 0 0 0 0 0 0 0 0 0 0
39289 - 0 0 0 0 0 0 0 0 0 0 0 0
39290 - 0 0 0 0 0 0 0 0 0 0 0 0
39291 - 0 0 0 6 6 6 14 14 14 42 42 42
39292 - 90 90 90 18 18 18 18 18 18 26 26 26
39293 - 2 2 6 116 116 116 253 253 253 253 253 253
39294 -253 253 253 253 253 253 253 253 253 253 253 253
39295 -253 253 253 253 253 253 250 250 250 238 238 238
39296 -253 253 253 253 253 253 253 253 253 253 253 253
39297 -253 253 253 253 253 253 253 253 253 253 253 253
39298 -253 253 253 253 253 253 253 253 253 253 253 253
39299 -253 253 253 253 253 253 253 253 253 253 253 253
39300 -253 253 253 253 253 253 94 94 94 6 6 6
39301 - 2 2 6 2 2 6 10 10 10 34 34 34
39302 - 2 2 6 2 2 6 2 2 6 2 2 6
39303 - 74 74 74 58 58 58 22 22 22 6 6 6
39304 - 0 0 0 0 0 0 0 0 0 0 0 0
39305 - 0 0 0 0 0 0 0 0 0 0 0 0
39306 - 0 0 0 0 0 0 0 0 0 0 0 0
39307 - 0 0 0 0 0 0 0 0 0 0 0 0
39308 - 0 0 0 0 0 0 0 0 0 0 0 0
39309 - 0 0 0 0 0 0 0 0 0 0 0 0
39310 - 0 0 0 0 0 0 0 0 0 0 0 0
39311 - 0 0 0 10 10 10 26 26 26 66 66 66
39312 - 82 82 82 2 2 6 38 38 38 6 6 6
39313 - 14 14 14 210 210 210 253 253 253 253 253 253
39314 -253 253 253 253 253 253 253 253 253 253 253 253
39315 -253 253 253 253 253 253 246 246 246 242 242 242
39316 -253 253 253 253 253 253 253 253 253 253 253 253
39317 -253 253 253 253 253 253 253 253 253 253 253 253
39318 -253 253 253 253 253 253 253 253 253 253 253 253
39319 -253 253 253 253 253 253 253 253 253 253 253 253
39320 -253 253 253 253 253 253 144 144 144 2 2 6
39321 - 2 2 6 2 2 6 2 2 6 46 46 46
39322 - 2 2 6 2 2 6 2 2 6 2 2 6
39323 - 42 42 42 74 74 74 30 30 30 10 10 10
39324 - 0 0 0 0 0 0 0 0 0 0 0 0
39325 - 0 0 0 0 0 0 0 0 0 0 0 0
39326 - 0 0 0 0 0 0 0 0 0 0 0 0
39327 - 0 0 0 0 0 0 0 0 0 0 0 0
39328 - 0 0 0 0 0 0 0 0 0 0 0 0
39329 - 0 0 0 0 0 0 0 0 0 0 0 0
39330 - 0 0 0 0 0 0 0 0 0 0 0 0
39331 - 6 6 6 14 14 14 42 42 42 90 90 90
39332 - 26 26 26 6 6 6 42 42 42 2 2 6
39333 - 74 74 74 250 250 250 253 253 253 253 253 253
39334 -253 253 253 253 253 253 253 253 253 253 253 253
39335 -253 253 253 253 253 253 242 242 242 242 242 242
39336 -253 253 253 253 253 253 253 253 253 253 253 253
39337 -253 253 253 253 253 253 253 253 253 253 253 253
39338 -253 253 253 253 253 253 253 253 253 253 253 253
39339 -253 253 253 253 253 253 253 253 253 253 253 253
39340 -253 253 253 253 253 253 182 182 182 2 2 6
39341 - 2 2 6 2 2 6 2 2 6 46 46 46
39342 - 2 2 6 2 2 6 2 2 6 2 2 6
39343 - 10 10 10 86 86 86 38 38 38 10 10 10
39344 - 0 0 0 0 0 0 0 0 0 0 0 0
39345 - 0 0 0 0 0 0 0 0 0 0 0 0
39346 - 0 0 0 0 0 0 0 0 0 0 0 0
39347 - 0 0 0 0 0 0 0 0 0 0 0 0
39348 - 0 0 0 0 0 0 0 0 0 0 0 0
39349 - 0 0 0 0 0 0 0 0 0 0 0 0
39350 - 0 0 0 0 0 0 0 0 0 0 0 0
39351 - 10 10 10 26 26 26 66 66 66 82 82 82
39352 - 2 2 6 22 22 22 18 18 18 2 2 6
39353 -149 149 149 253 253 253 253 253 253 253 253 253
39354 -253 253 253 253 253 253 253 253 253 253 253 253
39355 -253 253 253 253 253 253 234 234 234 242 242 242
39356 -253 253 253 253 253 253 253 253 253 253 253 253
39357 -253 253 253 253 253 253 253 253 253 253 253 253
39358 -253 253 253 253 253 253 253 253 253 253 253 253
39359 -253 253 253 253 253 253 253 253 253 253 253 253
39360 -253 253 253 253 253 253 206 206 206 2 2 6
39361 - 2 2 6 2 2 6 2 2 6 38 38 38
39362 - 2 2 6 2 2 6 2 2 6 2 2 6
39363 - 6 6 6 86 86 86 46 46 46 14 14 14
39364 - 0 0 0 0 0 0 0 0 0 0 0 0
39365 - 0 0 0 0 0 0 0 0 0 0 0 0
39366 - 0 0 0 0 0 0 0 0 0 0 0 0
39367 - 0 0 0 0 0 0 0 0 0 0 0 0
39368 - 0 0 0 0 0 0 0 0 0 0 0 0
39369 - 0 0 0 0 0 0 0 0 0 0 0 0
39370 - 0 0 0 0 0 0 0 0 0 6 6 6
39371 - 18 18 18 46 46 46 86 86 86 18 18 18
39372 - 2 2 6 34 34 34 10 10 10 6 6 6
39373 -210 210 210 253 253 253 253 253 253 253 253 253
39374 -253 253 253 253 253 253 253 253 253 253 253 253
39375 -253 253 253 253 253 253 234 234 234 242 242 242
39376 -253 253 253 253 253 253 253 253 253 253 253 253
39377 -253 253 253 253 253 253 253 253 253 253 253 253
39378 -253 253 253 253 253 253 253 253 253 253 253 253
39379 -253 253 253 253 253 253 253 253 253 253 253 253
39380 -253 253 253 253 253 253 221 221 221 6 6 6
39381 - 2 2 6 2 2 6 6 6 6 30 30 30
39382 - 2 2 6 2 2 6 2 2 6 2 2 6
39383 - 2 2 6 82 82 82 54 54 54 18 18 18
39384 - 6 6 6 0 0 0 0 0 0 0 0 0
39385 - 0 0 0 0 0 0 0 0 0 0 0 0
39386 - 0 0 0 0 0 0 0 0 0 0 0 0
39387 - 0 0 0 0 0 0 0 0 0 0 0 0
39388 - 0 0 0 0 0 0 0 0 0 0 0 0
39389 - 0 0 0 0 0 0 0 0 0 0 0 0
39390 - 0 0 0 0 0 0 0 0 0 10 10 10
39391 - 26 26 26 66 66 66 62 62 62 2 2 6
39392 - 2 2 6 38 38 38 10 10 10 26 26 26
39393 -238 238 238 253 253 253 253 253 253 253 253 253
39394 -253 253 253 253 253 253 253 253 253 253 253 253
39395 -253 253 253 253 253 253 231 231 231 238 238 238
39396 -253 253 253 253 253 253 253 253 253 253 253 253
39397 -253 253 253 253 253 253 253 253 253 253 253 253
39398 -253 253 253 253 253 253 253 253 253 253 253 253
39399 -253 253 253 253 253 253 253 253 253 253 253 253
39400 -253 253 253 253 253 253 231 231 231 6 6 6
39401 - 2 2 6 2 2 6 10 10 10 30 30 30
39402 - 2 2 6 2 2 6 2 2 6 2 2 6
39403 - 2 2 6 66 66 66 58 58 58 22 22 22
39404 - 6 6 6 0 0 0 0 0 0 0 0 0
39405 - 0 0 0 0 0 0 0 0 0 0 0 0
39406 - 0 0 0 0 0 0 0 0 0 0 0 0
39407 - 0 0 0 0 0 0 0 0 0 0 0 0
39408 - 0 0 0 0 0 0 0 0 0 0 0 0
39409 - 0 0 0 0 0 0 0 0 0 0 0 0
39410 - 0 0 0 0 0 0 0 0 0 10 10 10
39411 - 38 38 38 78 78 78 6 6 6 2 2 6
39412 - 2 2 6 46 46 46 14 14 14 42 42 42
39413 -246 246 246 253 253 253 253 253 253 253 253 253
39414 -253 253 253 253 253 253 253 253 253 253 253 253
39415 -253 253 253 253 253 253 231 231 231 242 242 242
39416 -253 253 253 253 253 253 253 253 253 253 253 253
39417 -253 253 253 253 253 253 253 253 253 253 253 253
39418 -253 253 253 253 253 253 253 253 253 253 253 253
39419 -253 253 253 253 253 253 253 253 253 253 253 253
39420 -253 253 253 253 253 253 234 234 234 10 10 10
39421 - 2 2 6 2 2 6 22 22 22 14 14 14
39422 - 2 2 6 2 2 6 2 2 6 2 2 6
39423 - 2 2 6 66 66 66 62 62 62 22 22 22
39424 - 6 6 6 0 0 0 0 0 0 0 0 0
39425 - 0 0 0 0 0 0 0 0 0 0 0 0
39426 - 0 0 0 0 0 0 0 0 0 0 0 0
39427 - 0 0 0 0 0 0 0 0 0 0 0 0
39428 - 0 0 0 0 0 0 0 0 0 0 0 0
39429 - 0 0 0 0 0 0 0 0 0 0 0 0
39430 - 0 0 0 0 0 0 6 6 6 18 18 18
39431 - 50 50 50 74 74 74 2 2 6 2 2 6
39432 - 14 14 14 70 70 70 34 34 34 62 62 62
39433 -250 250 250 253 253 253 253 253 253 253 253 253
39434 -253 253 253 253 253 253 253 253 253 253 253 253
39435 -253 253 253 253 253 253 231 231 231 246 246 246
39436 -253 253 253 253 253 253 253 253 253 253 253 253
39437 -253 253 253 253 253 253 253 253 253 253 253 253
39438 -253 253 253 253 253 253 253 253 253 253 253 253
39439 -253 253 253 253 253 253 253 253 253 253 253 253
39440 -253 253 253 253 253 253 234 234 234 14 14 14
39441 - 2 2 6 2 2 6 30 30 30 2 2 6
39442 - 2 2 6 2 2 6 2 2 6 2 2 6
39443 - 2 2 6 66 66 66 62 62 62 22 22 22
39444 - 6 6 6 0 0 0 0 0 0 0 0 0
39445 - 0 0 0 0 0 0 0 0 0 0 0 0
39446 - 0 0 0 0 0 0 0 0 0 0 0 0
39447 - 0 0 0 0 0 0 0 0 0 0 0 0
39448 - 0 0 0 0 0 0 0 0 0 0 0 0
39449 - 0 0 0 0 0 0 0 0 0 0 0 0
39450 - 0 0 0 0 0 0 6 6 6 18 18 18
39451 - 54 54 54 62 62 62 2 2 6 2 2 6
39452 - 2 2 6 30 30 30 46 46 46 70 70 70
39453 -250 250 250 253 253 253 253 253 253 253 253 253
39454 -253 253 253 253 253 253 253 253 253 253 253 253
39455 -253 253 253 253 253 253 231 231 231 246 246 246
39456 -253 253 253 253 253 253 253 253 253 253 253 253
39457 -253 253 253 253 253 253 253 253 253 253 253 253
39458 -253 253 253 253 253 253 253 253 253 253 253 253
39459 -253 253 253 253 253 253 253 253 253 253 253 253
39460 -253 253 253 253 253 253 226 226 226 10 10 10
39461 - 2 2 6 6 6 6 30 30 30 2 2 6
39462 - 2 2 6 2 2 6 2 2 6 2 2 6
39463 - 2 2 6 66 66 66 58 58 58 22 22 22
39464 - 6 6 6 0 0 0 0 0 0 0 0 0
39465 - 0 0 0 0 0 0 0 0 0 0 0 0
39466 - 0 0 0 0 0 0 0 0 0 0 0 0
39467 - 0 0 0 0 0 0 0 0 0 0 0 0
39468 - 0 0 0 0 0 0 0 0 0 0 0 0
39469 - 0 0 0 0 0 0 0 0 0 0 0 0
39470 - 0 0 0 0 0 0 6 6 6 22 22 22
39471 - 58 58 58 62 62 62 2 2 6 2 2 6
39472 - 2 2 6 2 2 6 30 30 30 78 78 78
39473 -250 250 250 253 253 253 253 253 253 253 253 253
39474 -253 253 253 253 253 253 253 253 253 253 253 253
39475 -253 253 253 253 253 253 231 231 231 246 246 246
39476 -253 253 253 253 253 253 253 253 253 253 253 253
39477 -253 253 253 253 253 253 253 253 253 253 253 253
39478 -253 253 253 253 253 253 253 253 253 253 253 253
39479 -253 253 253 253 253 253 253 253 253 253 253 253
39480 -253 253 253 253 253 253 206 206 206 2 2 6
39481 - 22 22 22 34 34 34 18 14 6 22 22 22
39482 - 26 26 26 18 18 18 6 6 6 2 2 6
39483 - 2 2 6 82 82 82 54 54 54 18 18 18
39484 - 6 6 6 0 0 0 0 0 0 0 0 0
39485 - 0 0 0 0 0 0 0 0 0 0 0 0
39486 - 0 0 0 0 0 0 0 0 0 0 0 0
39487 - 0 0 0 0 0 0 0 0 0 0 0 0
39488 - 0 0 0 0 0 0 0 0 0 0 0 0
39489 - 0 0 0 0 0 0 0 0 0 0 0 0
39490 - 0 0 0 0 0 0 6 6 6 26 26 26
39491 - 62 62 62 106 106 106 74 54 14 185 133 11
39492 -210 162 10 121 92 8 6 6 6 62 62 62
39493 -238 238 238 253 253 253 253 253 253 253 253 253
39494 -253 253 253 253 253 253 253 253 253 253 253 253
39495 -253 253 253 253 253 253 231 231 231 246 246 246
39496 -253 253 253 253 253 253 253 253 253 253 253 253
39497 -253 253 253 253 253 253 253 253 253 253 253 253
39498 -253 253 253 253 253 253 253 253 253 253 253 253
39499 -253 253 253 253 253 253 253 253 253 253 253 253
39500 -253 253 253 253 253 253 158 158 158 18 18 18
39501 - 14 14 14 2 2 6 2 2 6 2 2 6
39502 - 6 6 6 18 18 18 66 66 66 38 38 38
39503 - 6 6 6 94 94 94 50 50 50 18 18 18
39504 - 6 6 6 0 0 0 0 0 0 0 0 0
39505 - 0 0 0 0 0 0 0 0 0 0 0 0
39506 - 0 0 0 0 0 0 0 0 0 0 0 0
39507 - 0 0 0 0 0 0 0 0 0 0 0 0
39508 - 0 0 0 0 0 0 0 0 0 0 0 0
39509 - 0 0 0 0 0 0 0 0 0 6 6 6
39510 - 10 10 10 10 10 10 18 18 18 38 38 38
39511 - 78 78 78 142 134 106 216 158 10 242 186 14
39512 -246 190 14 246 190 14 156 118 10 10 10 10
39513 - 90 90 90 238 238 238 253 253 253 253 253 253
39514 -253 253 253 253 253 253 253 253 253 253 253 253
39515 -253 253 253 253 253 253 231 231 231 250 250 250
39516 -253 253 253 253 253 253 253 253 253 253 253 253
39517 -253 253 253 253 253 253 253 253 253 253 253 253
39518 -253 253 253 253 253 253 253 253 253 253 253 253
39519 -253 253 253 253 253 253 253 253 253 246 230 190
39520 -238 204 91 238 204 91 181 142 44 37 26 9
39521 - 2 2 6 2 2 6 2 2 6 2 2 6
39522 - 2 2 6 2 2 6 38 38 38 46 46 46
39523 - 26 26 26 106 106 106 54 54 54 18 18 18
39524 - 6 6 6 0 0 0 0 0 0 0 0 0
39525 - 0 0 0 0 0 0 0 0 0 0 0 0
39526 - 0 0 0 0 0 0 0 0 0 0 0 0
39527 - 0 0 0 0 0 0 0 0 0 0 0 0
39528 - 0 0 0 0 0 0 0 0 0 0 0 0
39529 - 0 0 0 6 6 6 14 14 14 22 22 22
39530 - 30 30 30 38 38 38 50 50 50 70 70 70
39531 -106 106 106 190 142 34 226 170 11 242 186 14
39532 -246 190 14 246 190 14 246 190 14 154 114 10
39533 - 6 6 6 74 74 74 226 226 226 253 253 253
39534 -253 253 253 253 253 253 253 253 253 253 253 253
39535 -253 253 253 253 253 253 231 231 231 250 250 250
39536 -253 253 253 253 253 253 253 253 253 253 253 253
39537 -253 253 253 253 253 253 253 253 253 253 253 253
39538 -253 253 253 253 253 253 253 253 253 253 253 253
39539 -253 253 253 253 253 253 253 253 253 228 184 62
39540 -241 196 14 241 208 19 232 195 16 38 30 10
39541 - 2 2 6 2 2 6 2 2 6 2 2 6
39542 - 2 2 6 6 6 6 30 30 30 26 26 26
39543 -203 166 17 154 142 90 66 66 66 26 26 26
39544 - 6 6 6 0 0 0 0 0 0 0 0 0
39545 - 0 0 0 0 0 0 0 0 0 0 0 0
39546 - 0 0 0 0 0 0 0 0 0 0 0 0
39547 - 0 0 0 0 0 0 0 0 0 0 0 0
39548 - 0 0 0 0 0 0 0 0 0 0 0 0
39549 - 6 6 6 18 18 18 38 38 38 58 58 58
39550 - 78 78 78 86 86 86 101 101 101 123 123 123
39551 -175 146 61 210 150 10 234 174 13 246 186 14
39552 -246 190 14 246 190 14 246 190 14 238 190 10
39553 -102 78 10 2 2 6 46 46 46 198 198 198
39554 -253 253 253 253 253 253 253 253 253 253 253 253
39555 -253 253 253 253 253 253 234 234 234 242 242 242
39556 -253 253 253 253 253 253 253 253 253 253 253 253
39557 -253 253 253 253 253 253 253 253 253 253 253 253
39558 -253 253 253 253 253 253 253 253 253 253 253 253
39559 -253 253 253 253 253 253 253 253 253 224 178 62
39560 -242 186 14 241 196 14 210 166 10 22 18 6
39561 - 2 2 6 2 2 6 2 2 6 2 2 6
39562 - 2 2 6 2 2 6 6 6 6 121 92 8
39563 -238 202 15 232 195 16 82 82 82 34 34 34
39564 - 10 10 10 0 0 0 0 0 0 0 0 0
39565 - 0 0 0 0 0 0 0 0 0 0 0 0
39566 - 0 0 0 0 0 0 0 0 0 0 0 0
39567 - 0 0 0 0 0 0 0 0 0 0 0 0
39568 - 0 0 0 0 0 0 0 0 0 0 0 0
39569 - 14 14 14 38 38 38 70 70 70 154 122 46
39570 -190 142 34 200 144 11 197 138 11 197 138 11
39571 -213 154 11 226 170 11 242 186 14 246 190 14
39572 -246 190 14 246 190 14 246 190 14 246 190 14
39573 -225 175 15 46 32 6 2 2 6 22 22 22
39574 -158 158 158 250 250 250 253 253 253 253 253 253
39575 -253 253 253 253 253 253 253 253 253 253 253 253
39576 -253 253 253 253 253 253 253 253 253 253 253 253
39577 -253 253 253 253 253 253 253 253 253 253 253 253
39578 -253 253 253 253 253 253 253 253 253 253 253 253
39579 -253 253 253 250 250 250 242 242 242 224 178 62
39580 -239 182 13 236 186 11 213 154 11 46 32 6
39581 - 2 2 6 2 2 6 2 2 6 2 2 6
39582 - 2 2 6 2 2 6 61 42 6 225 175 15
39583 -238 190 10 236 186 11 112 100 78 42 42 42
39584 - 14 14 14 0 0 0 0 0 0 0 0 0
39585 - 0 0 0 0 0 0 0 0 0 0 0 0
39586 - 0 0 0 0 0 0 0 0 0 0 0 0
39587 - 0 0 0 0 0 0 0 0 0 0 0 0
39588 - 0 0 0 0 0 0 0 0 0 6 6 6
39589 - 22 22 22 54 54 54 154 122 46 213 154 11
39590 -226 170 11 230 174 11 226 170 11 226 170 11
39591 -236 178 12 242 186 14 246 190 14 246 190 14
39592 -246 190 14 246 190 14 246 190 14 246 190 14
39593 -241 196 14 184 144 12 10 10 10 2 2 6
39594 - 6 6 6 116 116 116 242 242 242 253 253 253
39595 -253 253 253 253 253 253 253 253 253 253 253 253
39596 -253 253 253 253 253 253 253 253 253 253 253 253
39597 -253 253 253 253 253 253 253 253 253 253 253 253
39598 -253 253 253 253 253 253 253 253 253 253 253 253
39599 -253 253 253 231 231 231 198 198 198 214 170 54
39600 -236 178 12 236 178 12 210 150 10 137 92 6
39601 - 18 14 6 2 2 6 2 2 6 2 2 6
39602 - 6 6 6 70 47 6 200 144 11 236 178 12
39603 -239 182 13 239 182 13 124 112 88 58 58 58
39604 - 22 22 22 6 6 6 0 0 0 0 0 0
39605 - 0 0 0 0 0 0 0 0 0 0 0 0
39606 - 0 0 0 0 0 0 0 0 0 0 0 0
39607 - 0 0 0 0 0 0 0 0 0 0 0 0
39608 - 0 0 0 0 0 0 0 0 0 10 10 10
39609 - 30 30 30 70 70 70 180 133 36 226 170 11
39610 -239 182 13 242 186 14 242 186 14 246 186 14
39611 -246 190 14 246 190 14 246 190 14 246 190 14
39612 -246 190 14 246 190 14 246 190 14 246 190 14
39613 -246 190 14 232 195 16 98 70 6 2 2 6
39614 - 2 2 6 2 2 6 66 66 66 221 221 221
39615 -253 253 253 253 253 253 253 253 253 253 253 253
39616 -253 253 253 253 253 253 253 253 253 253 253 253
39617 -253 253 253 253 253 253 253 253 253 253 253 253
39618 -253 253 253 253 253 253 253 253 253 253 253 253
39619 -253 253 253 206 206 206 198 198 198 214 166 58
39620 -230 174 11 230 174 11 216 158 10 192 133 9
39621 -163 110 8 116 81 8 102 78 10 116 81 8
39622 -167 114 7 197 138 11 226 170 11 239 182 13
39623 -242 186 14 242 186 14 162 146 94 78 78 78
39624 - 34 34 34 14 14 14 6 6 6 0 0 0
39625 - 0 0 0 0 0 0 0 0 0 0 0 0
39626 - 0 0 0 0 0 0 0 0 0 0 0 0
39627 - 0 0 0 0 0 0 0 0 0 0 0 0
39628 - 0 0 0 0 0 0 0 0 0 6 6 6
39629 - 30 30 30 78 78 78 190 142 34 226 170 11
39630 -239 182 13 246 190 14 246 190 14 246 190 14
39631 -246 190 14 246 190 14 246 190 14 246 190 14
39632 -246 190 14 246 190 14 246 190 14 246 190 14
39633 -246 190 14 241 196 14 203 166 17 22 18 6
39634 - 2 2 6 2 2 6 2 2 6 38 38 38
39635 -218 218 218 253 253 253 253 253 253 253 253 253
39636 -253 253 253 253 253 253 253 253 253 253 253 253
39637 -253 253 253 253 253 253 253 253 253 253 253 253
39638 -253 253 253 253 253 253 253 253 253 253 253 253
39639 -250 250 250 206 206 206 198 198 198 202 162 69
39640 -226 170 11 236 178 12 224 166 10 210 150 10
39641 -200 144 11 197 138 11 192 133 9 197 138 11
39642 -210 150 10 226 170 11 242 186 14 246 190 14
39643 -246 190 14 246 186 14 225 175 15 124 112 88
39644 - 62 62 62 30 30 30 14 14 14 6 6 6
39645 - 0 0 0 0 0 0 0 0 0 0 0 0
39646 - 0 0 0 0 0 0 0 0 0 0 0 0
39647 - 0 0 0 0 0 0 0 0 0 0 0 0
39648 - 0 0 0 0 0 0 0 0 0 10 10 10
39649 - 30 30 30 78 78 78 174 135 50 224 166 10
39650 -239 182 13 246 190 14 246 190 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 241 196 14 139 102 15
39654 - 2 2 6 2 2 6 2 2 6 2 2 6
39655 - 78 78 78 250 250 250 253 253 253 253 253 253
39656 -253 253 253 253 253 253 253 253 253 253 253 253
39657 -253 253 253 253 253 253 253 253 253 253 253 253
39658 -253 253 253 253 253 253 253 253 253 253 253 253
39659 -250 250 250 214 214 214 198 198 198 190 150 46
39660 -219 162 10 236 178 12 234 174 13 224 166 10
39661 -216 158 10 213 154 11 213 154 11 216 158 10
39662 -226 170 11 239 182 13 246 190 14 246 190 14
39663 -246 190 14 246 190 14 242 186 14 206 162 42
39664 -101 101 101 58 58 58 30 30 30 14 14 14
39665 - 6 6 6 0 0 0 0 0 0 0 0 0
39666 - 0 0 0 0 0 0 0 0 0 0 0 0
39667 - 0 0 0 0 0 0 0 0 0 0 0 0
39668 - 0 0 0 0 0 0 0 0 0 10 10 10
39669 - 30 30 30 74 74 74 174 135 50 216 158 10
39670 -236 178 12 246 190 14 246 190 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 241 196 14 226 184 13
39674 - 61 42 6 2 2 6 2 2 6 2 2 6
39675 - 22 22 22 238 238 238 253 253 253 253 253 253
39676 -253 253 253 253 253 253 253 253 253 253 253 253
39677 -253 253 253 253 253 253 253 253 253 253 253 253
39678 -253 253 253 253 253 253 253 253 253 253 253 253
39679 -253 253 253 226 226 226 187 187 187 180 133 36
39680 -216 158 10 236 178 12 239 182 13 236 178 12
39681 -230 174 11 226 170 11 226 170 11 230 174 11
39682 -236 178 12 242 186 14 246 190 14 246 190 14
39683 -246 190 14 246 190 14 246 186 14 239 182 13
39684 -206 162 42 106 106 106 66 66 66 34 34 34
39685 - 14 14 14 6 6 6 0 0 0 0 0 0
39686 - 0 0 0 0 0 0 0 0 0 0 0 0
39687 - 0 0 0 0 0 0 0 0 0 0 0 0
39688 - 0 0 0 0 0 0 0 0 0 6 6 6
39689 - 26 26 26 70 70 70 163 133 67 213 154 11
39690 -236 178 12 246 190 14 246 190 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 241 196 14
39694 -190 146 13 18 14 6 2 2 6 2 2 6
39695 - 46 46 46 246 246 246 253 253 253 253 253 253
39696 -253 253 253 253 253 253 253 253 253 253 253 253
39697 -253 253 253 253 253 253 253 253 253 253 253 253
39698 -253 253 253 253 253 253 253 253 253 253 253 253
39699 -253 253 253 221 221 221 86 86 86 156 107 11
39700 -216 158 10 236 178 12 242 186 14 246 186 14
39701 -242 186 14 239 182 13 239 182 13 242 186 14
39702 -242 186 14 246 186 14 246 190 14 246 190 14
39703 -246 190 14 246 190 14 246 190 14 246 190 14
39704 -242 186 14 225 175 15 142 122 72 66 66 66
39705 - 30 30 30 10 10 10 0 0 0 0 0 0
39706 - 0 0 0 0 0 0 0 0 0 0 0 0
39707 - 0 0 0 0 0 0 0 0 0 0 0 0
39708 - 0 0 0 0 0 0 0 0 0 6 6 6
39709 - 26 26 26 70 70 70 163 133 67 210 150 10
39710 -236 178 12 246 190 14 246 190 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 246 190 14
39714 -232 195 16 121 92 8 34 34 34 106 106 106
39715 -221 221 221 253 253 253 253 253 253 253 253 253
39716 -253 253 253 253 253 253 253 253 253 253 253 253
39717 -253 253 253 253 253 253 253 253 253 253 253 253
39718 -253 253 253 253 253 253 253 253 253 253 253 253
39719 -242 242 242 82 82 82 18 14 6 163 110 8
39720 -216 158 10 236 178 12 242 186 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 190 14 246 190 14 242 186 14 163 133 67
39725 - 46 46 46 18 18 18 6 6 6 0 0 0
39726 - 0 0 0 0 0 0 0 0 0 0 0 0
39727 - 0 0 0 0 0 0 0 0 0 0 0 0
39728 - 0 0 0 0 0 0 0 0 0 10 10 10
39729 - 30 30 30 78 78 78 163 133 67 210 150 10
39730 -236 178 12 246 186 14 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 246 190 14 246 190 14 246 190 14
39734 -241 196 14 215 174 15 190 178 144 253 253 253
39735 -253 253 253 253 253 253 253 253 253 253 253 253
39736 -253 253 253 253 253 253 253 253 253 253 253 253
39737 -253 253 253 253 253 253 253 253 253 253 253 253
39738 -253 253 253 253 253 253 253 253 253 218 218 218
39739 - 58 58 58 2 2 6 22 18 6 167 114 7
39740 -216 158 10 236 178 12 246 186 14 246 190 14
39741 -246 190 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 246 186 14 242 186 14 190 150 46
39745 - 54 54 54 22 22 22 6 6 6 0 0 0
39746 - 0 0 0 0 0 0 0 0 0 0 0 0
39747 - 0 0 0 0 0 0 0 0 0 0 0 0
39748 - 0 0 0 0 0 0 0 0 0 14 14 14
39749 - 38 38 38 86 86 86 180 133 36 213 154 11
39750 -236 178 12 246 186 14 246 190 14 246 190 14
39751 -246 190 14 246 190 14 246 190 14 246 190 14
39752 -246 190 14 246 190 14 246 190 14 246 190 14
39753 -246 190 14 246 190 14 246 190 14 246 190 14
39754 -246 190 14 232 195 16 190 146 13 214 214 214
39755 -253 253 253 253 253 253 253 253 253 253 253 253
39756 -253 253 253 253 253 253 253 253 253 253 253 253
39757 -253 253 253 253 253 253 253 253 253 253 253 253
39758 -253 253 253 250 250 250 170 170 170 26 26 26
39759 - 2 2 6 2 2 6 37 26 9 163 110 8
39760 -219 162 10 239 182 13 246 186 14 246 190 14
39761 -246 190 14 246 190 14 246 190 14 246 190 14
39762 -246 190 14 246 190 14 246 190 14 246 190 14
39763 -246 190 14 246 190 14 246 190 14 246 190 14
39764 -246 186 14 236 178 12 224 166 10 142 122 72
39765 - 46 46 46 18 18 18 6 6 6 0 0 0
39766 - 0 0 0 0 0 0 0 0 0 0 0 0
39767 - 0 0 0 0 0 0 0 0 0 0 0 0
39768 - 0 0 0 0 0 0 6 6 6 18 18 18
39769 - 50 50 50 109 106 95 192 133 9 224 166 10
39770 -242 186 14 246 190 14 246 190 14 246 190 14
39771 -246 190 14 246 190 14 246 190 14 246 190 14
39772 -246 190 14 246 190 14 246 190 14 246 190 14
39773 -246 190 14 246 190 14 246 190 14 246 190 14
39774 -242 186 14 226 184 13 210 162 10 142 110 46
39775 -226 226 226 253 253 253 253 253 253 253 253 253
39776 -253 253 253 253 253 253 253 253 253 253 253 253
39777 -253 253 253 253 253 253 253 253 253 253 253 253
39778 -198 198 198 66 66 66 2 2 6 2 2 6
39779 - 2 2 6 2 2 6 50 34 6 156 107 11
39780 -219 162 10 239 182 13 246 186 14 246 190 14
39781 -246 190 14 246 190 14 246 190 14 246 190 14
39782 -246 190 14 246 190 14 246 190 14 246 190 14
39783 -246 190 14 246 190 14 246 190 14 242 186 14
39784 -234 174 13 213 154 11 154 122 46 66 66 66
39785 - 30 30 30 10 10 10 0 0 0 0 0 0
39786 - 0 0 0 0 0 0 0 0 0 0 0 0
39787 - 0 0 0 0 0 0 0 0 0 0 0 0
39788 - 0 0 0 0 0 0 6 6 6 22 22 22
39789 - 58 58 58 154 121 60 206 145 10 234 174 13
39790 -242 186 14 246 186 14 246 190 14 246 190 14
39791 -246 190 14 246 190 14 246 190 14 246 190 14
39792 -246 190 14 246 190 14 246 190 14 246 190 14
39793 -246 190 14 246 190 14 246 190 14 246 190 14
39794 -246 186 14 236 178 12 210 162 10 163 110 8
39795 - 61 42 6 138 138 138 218 218 218 250 250 250
39796 -253 253 253 253 253 253 253 253 253 250 250 250
39797 -242 242 242 210 210 210 144 144 144 66 66 66
39798 - 6 6 6 2 2 6 2 2 6 2 2 6
39799 - 2 2 6 2 2 6 61 42 6 163 110 8
39800 -216 158 10 236 178 12 246 190 14 246 190 14
39801 -246 190 14 246 190 14 246 190 14 246 190 14
39802 -246 190 14 246 190 14 246 190 14 246 190 14
39803 -246 190 14 239 182 13 230 174 11 216 158 10
39804 -190 142 34 124 112 88 70 70 70 38 38 38
39805 - 18 18 18 6 6 6 0 0 0 0 0 0
39806 - 0 0 0 0 0 0 0 0 0 0 0 0
39807 - 0 0 0 0 0 0 0 0 0 0 0 0
39808 - 0 0 0 0 0 0 6 6 6 22 22 22
39809 - 62 62 62 168 124 44 206 145 10 224 166 10
39810 -236 178 12 239 182 13 242 186 14 242 186 14
39811 -246 186 14 246 190 14 246 190 14 246 190 14
39812 -246 190 14 246 190 14 246 190 14 246 190 14
39813 -246 190 14 246 190 14 246 190 14 246 190 14
39814 -246 190 14 236 178 12 216 158 10 175 118 6
39815 - 80 54 7 2 2 6 6 6 6 30 30 30
39816 - 54 54 54 62 62 62 50 50 50 38 38 38
39817 - 14 14 14 2 2 6 2 2 6 2 2 6
39818 - 2 2 6 2 2 6 2 2 6 2 2 6
39819 - 2 2 6 6 6 6 80 54 7 167 114 7
39820 -213 154 11 236 178 12 246 190 14 246 190 14
39821 -246 190 14 246 190 14 246 190 14 246 190 14
39822 -246 190 14 242 186 14 239 182 13 239 182 13
39823 -230 174 11 210 150 10 174 135 50 124 112 88
39824 - 82 82 82 54 54 54 34 34 34 18 18 18
39825 - 6 6 6 0 0 0 0 0 0 0 0 0
39826 - 0 0 0 0 0 0 0 0 0 0 0 0
39827 - 0 0 0 0 0 0 0 0 0 0 0 0
39828 - 0 0 0 0 0 0 6 6 6 18 18 18
39829 - 50 50 50 158 118 36 192 133 9 200 144 11
39830 -216 158 10 219 162 10 224 166 10 226 170 11
39831 -230 174 11 236 178 12 239 182 13 239 182 13
39832 -242 186 14 246 186 14 246 190 14 246 190 14
39833 -246 190 14 246 190 14 246 190 14 246 190 14
39834 -246 186 14 230 174 11 210 150 10 163 110 8
39835 -104 69 6 10 10 10 2 2 6 2 2 6
39836 - 2 2 6 2 2 6 2 2 6 2 2 6
39837 - 2 2 6 2 2 6 2 2 6 2 2 6
39838 - 2 2 6 2 2 6 2 2 6 2 2 6
39839 - 2 2 6 6 6 6 91 60 6 167 114 7
39840 -206 145 10 230 174 11 242 186 14 246 190 14
39841 -246 190 14 246 190 14 246 186 14 242 186 14
39842 -239 182 13 230 174 11 224 166 10 213 154 11
39843 -180 133 36 124 112 88 86 86 86 58 58 58
39844 - 38 38 38 22 22 22 10 10 10 6 6 6
39845 - 0 0 0 0 0 0 0 0 0 0 0 0
39846 - 0 0 0 0 0 0 0 0 0 0 0 0
39847 - 0 0 0 0 0 0 0 0 0 0 0 0
39848 - 0 0 0 0 0 0 0 0 0 14 14 14
39849 - 34 34 34 70 70 70 138 110 50 158 118 36
39850 -167 114 7 180 123 7 192 133 9 197 138 11
39851 -200 144 11 206 145 10 213 154 11 219 162 10
39852 -224 166 10 230 174 11 239 182 13 242 186 14
39853 -246 186 14 246 186 14 246 186 14 246 186 14
39854 -239 182 13 216 158 10 185 133 11 152 99 6
39855 -104 69 6 18 14 6 2 2 6 2 2 6
39856 - 2 2 6 2 2 6 2 2 6 2 2 6
39857 - 2 2 6 2 2 6 2 2 6 2 2 6
39858 - 2 2 6 2 2 6 2 2 6 2 2 6
39859 - 2 2 6 6 6 6 80 54 7 152 99 6
39860 -192 133 9 219 162 10 236 178 12 239 182 13
39861 -246 186 14 242 186 14 239 182 13 236 178 12
39862 -224 166 10 206 145 10 192 133 9 154 121 60
39863 - 94 94 94 62 62 62 42 42 42 22 22 22
39864 - 14 14 14 6 6 6 0 0 0 0 0 0
39865 - 0 0 0 0 0 0 0 0 0 0 0 0
39866 - 0 0 0 0 0 0 0 0 0 0 0 0
39867 - 0 0 0 0 0 0 0 0 0 0 0 0
39868 - 0 0 0 0 0 0 0 0 0 6 6 6
39869 - 18 18 18 34 34 34 58 58 58 78 78 78
39870 -101 98 89 124 112 88 142 110 46 156 107 11
39871 -163 110 8 167 114 7 175 118 6 180 123 7
39872 -185 133 11 197 138 11 210 150 10 219 162 10
39873 -226 170 11 236 178 12 236 178 12 234 174 13
39874 -219 162 10 197 138 11 163 110 8 130 83 6
39875 - 91 60 6 10 10 10 2 2 6 2 2 6
39876 - 18 18 18 38 38 38 38 38 38 38 38 38
39877 - 38 38 38 38 38 38 38 38 38 38 38 38
39878 - 38 38 38 38 38 38 26 26 26 2 2 6
39879 - 2 2 6 6 6 6 70 47 6 137 92 6
39880 -175 118 6 200 144 11 219 162 10 230 174 11
39881 -234 174 13 230 174 11 219 162 10 210 150 10
39882 -192 133 9 163 110 8 124 112 88 82 82 82
39883 - 50 50 50 30 30 30 14 14 14 6 6 6
39884 - 0 0 0 0 0 0 0 0 0 0 0 0
39885 - 0 0 0 0 0 0 0 0 0 0 0 0
39886 - 0 0 0 0 0 0 0 0 0 0 0 0
39887 - 0 0 0 0 0 0 0 0 0 0 0 0
39888 - 0 0 0 0 0 0 0 0 0 0 0 0
39889 - 6 6 6 14 14 14 22 22 22 34 34 34
39890 - 42 42 42 58 58 58 74 74 74 86 86 86
39891 -101 98 89 122 102 70 130 98 46 121 87 25
39892 -137 92 6 152 99 6 163 110 8 180 123 7
39893 -185 133 11 197 138 11 206 145 10 200 144 11
39894 -180 123 7 156 107 11 130 83 6 104 69 6
39895 - 50 34 6 54 54 54 110 110 110 101 98 89
39896 - 86 86 86 82 82 82 78 78 78 78 78 78
39897 - 78 78 78 78 78 78 78 78 78 78 78 78
39898 - 78 78 78 82 82 82 86 86 86 94 94 94
39899 -106 106 106 101 101 101 86 66 34 124 80 6
39900 -156 107 11 180 123 7 192 133 9 200 144 11
39901 -206 145 10 200 144 11 192 133 9 175 118 6
39902 -139 102 15 109 106 95 70 70 70 42 42 42
39903 - 22 22 22 10 10 10 0 0 0 0 0 0
39904 - 0 0 0 0 0 0 0 0 0 0 0 0
39905 - 0 0 0 0 0 0 0 0 0 0 0 0
39906 - 0 0 0 0 0 0 0 0 0 0 0 0
39907 - 0 0 0 0 0 0 0 0 0 0 0 0
39908 - 0 0 0 0 0 0 0 0 0 0 0 0
39909 - 0 0 0 0 0 0 6 6 6 10 10 10
39910 - 14 14 14 22 22 22 30 30 30 38 38 38
39911 - 50 50 50 62 62 62 74 74 74 90 90 90
39912 -101 98 89 112 100 78 121 87 25 124 80 6
39913 -137 92 6 152 99 6 152 99 6 152 99 6
39914 -138 86 6 124 80 6 98 70 6 86 66 30
39915 -101 98 89 82 82 82 58 58 58 46 46 46
39916 - 38 38 38 34 34 34 34 34 34 34 34 34
39917 - 34 34 34 34 34 34 34 34 34 34 34 34
39918 - 34 34 34 34 34 34 38 38 38 42 42 42
39919 - 54 54 54 82 82 82 94 86 76 91 60 6
39920 -134 86 6 156 107 11 167 114 7 175 118 6
39921 -175 118 6 167 114 7 152 99 6 121 87 25
39922 -101 98 89 62 62 62 34 34 34 18 18 18
39923 - 6 6 6 0 0 0 0 0 0 0 0 0
39924 - 0 0 0 0 0 0 0 0 0 0 0 0
39925 - 0 0 0 0 0 0 0 0 0 0 0 0
39926 - 0 0 0 0 0 0 0 0 0 0 0 0
39927 - 0 0 0 0 0 0 0 0 0 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 0 0 0
39930 - 0 0 0 6 6 6 6 6 6 10 10 10
39931 - 18 18 18 22 22 22 30 30 30 42 42 42
39932 - 50 50 50 66 66 66 86 86 86 101 98 89
39933 -106 86 58 98 70 6 104 69 6 104 69 6
39934 -104 69 6 91 60 6 82 62 34 90 90 90
39935 - 62 62 62 38 38 38 22 22 22 14 14 14
39936 - 10 10 10 10 10 10 10 10 10 10 10 10
39937 - 10 10 10 10 10 10 6 6 6 10 10 10
39938 - 10 10 10 10 10 10 10 10 10 14 14 14
39939 - 22 22 22 42 42 42 70 70 70 89 81 66
39940 - 80 54 7 104 69 6 124 80 6 137 92 6
39941 -134 86 6 116 81 8 100 82 52 86 86 86
39942 - 58 58 58 30 30 30 14 14 14 6 6 6
39943 - 0 0 0 0 0 0 0 0 0 0 0 0
39944 - 0 0 0 0 0 0 0 0 0 0 0 0
39945 - 0 0 0 0 0 0 0 0 0 0 0 0
39946 - 0 0 0 0 0 0 0 0 0 0 0 0
39947 - 0 0 0 0 0 0 0 0 0 0 0 0
39948 - 0 0 0 0 0 0 0 0 0 0 0 0
39949 - 0 0 0 0 0 0 0 0 0 0 0 0
39950 - 0 0 0 0 0 0 0 0 0 0 0 0
39951 - 0 0 0 6 6 6 10 10 10 14 14 14
39952 - 18 18 18 26 26 26 38 38 38 54 54 54
39953 - 70 70 70 86 86 86 94 86 76 89 81 66
39954 - 89 81 66 86 86 86 74 74 74 50 50 50
39955 - 30 30 30 14 14 14 6 6 6 0 0 0
39956 - 0 0 0 0 0 0 0 0 0 0 0 0
39957 - 0 0 0 0 0 0 0 0 0 0 0 0
39958 - 0 0 0 0 0 0 0 0 0 0 0 0
39959 - 6 6 6 18 18 18 34 34 34 58 58 58
39960 - 82 82 82 89 81 66 89 81 66 89 81 66
39961 - 94 86 66 94 86 76 74 74 74 50 50 50
39962 - 26 26 26 14 14 14 6 6 6 0 0 0
39963 - 0 0 0 0 0 0 0 0 0 0 0 0
39964 - 0 0 0 0 0 0 0 0 0 0 0 0
39965 - 0 0 0 0 0 0 0 0 0 0 0 0
39966 - 0 0 0 0 0 0 0 0 0 0 0 0
39967 - 0 0 0 0 0 0 0 0 0 0 0 0
39968 - 0 0 0 0 0 0 0 0 0 0 0 0
39969 - 0 0 0 0 0 0 0 0 0 0 0 0
39970 - 0 0 0 0 0 0 0 0 0 0 0 0
39971 - 0 0 0 0 0 0 0 0 0 0 0 0
39972 - 6 6 6 6 6 6 14 14 14 18 18 18
39973 - 30 30 30 38 38 38 46 46 46 54 54 54
39974 - 50 50 50 42 42 42 30 30 30 18 18 18
39975 - 10 10 10 0 0 0 0 0 0 0 0 0
39976 - 0 0 0 0 0 0 0 0 0 0 0 0
39977 - 0 0 0 0 0 0 0 0 0 0 0 0
39978 - 0 0 0 0 0 0 0 0 0 0 0 0
39979 - 0 0 0 6 6 6 14 14 14 26 26 26
39980 - 38 38 38 50 50 50 58 58 58 58 58 58
39981 - 54 54 54 42 42 42 30 30 30 18 18 18
39982 - 10 10 10 0 0 0 0 0 0 0 0 0
39983 - 0 0 0 0 0 0 0 0 0 0 0 0
39984 - 0 0 0 0 0 0 0 0 0 0 0 0
39985 - 0 0 0 0 0 0 0 0 0 0 0 0
39986 - 0 0 0 0 0 0 0 0 0 0 0 0
39987 - 0 0 0 0 0 0 0 0 0 0 0 0
39988 - 0 0 0 0 0 0 0 0 0 0 0 0
39989 - 0 0 0 0 0 0 0 0 0 0 0 0
39990 - 0 0 0 0 0 0 0 0 0 0 0 0
39991 - 0 0 0 0 0 0 0 0 0 0 0 0
39992 - 0 0 0 0 0 0 0 0 0 6 6 6
39993 - 6 6 6 10 10 10 14 14 14 18 18 18
39994 - 18 18 18 14 14 14 10 10 10 6 6 6
39995 - 0 0 0 0 0 0 0 0 0 0 0 0
39996 - 0 0 0 0 0 0 0 0 0 0 0 0
39997 - 0 0 0 0 0 0 0 0 0 0 0 0
39998 - 0 0 0 0 0 0 0 0 0 0 0 0
39999 - 0 0 0 0 0 0 0 0 0 6 6 6
40000 - 14 14 14 18 18 18 22 22 22 22 22 22
40001 - 18 18 18 14 14 14 10 10 10 6 6 6
40002 - 0 0 0 0 0 0 0 0 0 0 0 0
40003 - 0 0 0 0 0 0 0 0 0 0 0 0
40004 - 0 0 0 0 0 0 0 0 0 0 0 0
40005 - 0 0 0 0 0 0 0 0 0 0 0 0
40006 - 0 0 0 0 0 0 0 0 0 0 0 0
40007 +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 4 4 4 4 4 4 4 4 4
40026 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
40031 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40032 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
40040 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40041 +4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
40045 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40046 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40047 +4 4 4 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 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40054 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40055 +4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
40059 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40060 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40061 +4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
40067 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40068 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40069 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
40072 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40073 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40074 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40075 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40081 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40082 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40083 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40084 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40085 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40086 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40087 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40088 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40089 +4 4 4 4 4 4 4 4 4 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 4 4 4
40094 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40095 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
40096 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
40097 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40098 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40099 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40100 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
40101 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40102 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
40103 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
40108 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40109 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
40110 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
40111 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40112 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40113 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40114 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
40115 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
40116 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
40117 +1 1 1 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
40122 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40123 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
40124 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
40125 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40126 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40127 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40128 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
40129 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
40130 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
40131 +2 2 2 2 1 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40136 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
40137 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
40138 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
40139 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
40140 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40141 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40142 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
40143 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
40144 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
40145 +37 51 59 2 0 0 1 1 1 4 5 5 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 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40150 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
40151 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
40152 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
40153 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
40154 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40155 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
40156 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
40157 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
40158 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
40159 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 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 4 4 4 4 4 4
40163 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40164 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
40165 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
40166 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
40167 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
40168 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
40169 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
40170 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
40171 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
40172 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
40173 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40177 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
40178 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
40179 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
40180 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
40181 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
40182 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
40183 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
40184 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
40185 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
40186 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
40187 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
40188 +4 4 4 4 4 4
40189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40191 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
40192 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
40193 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
40194 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
40195 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
40196 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
40197 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
40198 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
40199 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
40200 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
40201 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
40202 +4 4 4 4 4 4
40203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40205 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
40206 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
40207 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
40208 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
40209 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
40210 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
40211 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
40212 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
40213 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
40214 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
40215 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40216 +4 4 4 4 4 4
40217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40219 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
40220 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
40221 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
40222 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
40223 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
40224 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
40225 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
40226 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
40227 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
40228 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
40229 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
40230 +4 4 4 4 4 4
40231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40232 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
40233 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
40234 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
40235 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
40236 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
40237 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
40238 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
40239 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
40240 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
40241 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
40242 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
40243 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
40244 +4 4 4 4 4 4
40245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40246 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
40247 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
40248 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
40249 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
40250 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
40251 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
40252 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
40253 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
40254 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
40255 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
40256 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
40257 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
40258 +0 0 0 4 4 4
40259 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40260 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
40261 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
40262 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
40263 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
40264 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
40265 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
40266 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
40267 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
40268 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
40269 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
40270 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
40271 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
40272 +2 0 0 0 0 0
40273 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
40274 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
40275 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
40276 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
40277 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
40278 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
40279 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
40280 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
40281 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
40282 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
40283 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
40284 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
40285 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
40286 +37 38 37 0 0 0
40287 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40288 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
40289 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
40290 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
40291 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
40292 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
40293 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
40294 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
40295 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
40296 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
40297 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
40298 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
40299 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
40300 +85 115 134 4 0 0
40301 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
40302 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
40303 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
40304 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
40305 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
40306 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
40307 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
40308 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
40309 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
40310 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
40311 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
40312 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
40313 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
40314 +60 73 81 4 0 0
40315 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
40316 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
40317 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
40318 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
40319 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
40320 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
40321 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
40322 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
40323 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
40324 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
40325 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
40326 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
40327 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
40328 +16 19 21 4 0 0
40329 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
40330 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
40331 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
40332 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
40333 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
40334 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
40335 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
40336 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
40337 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
40338 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
40339 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
40340 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
40341 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
40342 +4 0 0 4 3 3
40343 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
40344 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
40345 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
40346 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
40347 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
40348 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
40349 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
40350 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
40351 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
40352 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
40353 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
40354 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
40355 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
40356 +3 2 2 4 4 4
40357 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
40358 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
40359 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
40360 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40361 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
40362 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
40363 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
40364 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
40365 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
40366 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
40367 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
40368 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
40369 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
40370 +4 4 4 4 4 4
40371 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
40372 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
40373 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
40374 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
40375 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
40376 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
40377 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
40378 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
40379 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
40380 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
40381 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
40382 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
40383 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
40384 +4 4 4 4 4 4
40385 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
40386 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
40387 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
40388 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
40389 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
40390 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
40391 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
40392 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
40393 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
40394 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
40395 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
40396 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
40397 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
40398 +5 5 5 5 5 5
40399 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
40400 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
40401 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
40402 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
40403 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
40404 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40405 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
40406 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
40407 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
40408 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
40409 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
40410 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
40411 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
40412 +5 5 5 4 4 4
40413 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
40414 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
40415 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
40416 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
40417 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40418 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
40419 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
40420 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
40421 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
40422 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
40423 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
40424 +4 0 0 4 0 0 5 5 5 5 5 5 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 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
40428 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
40429 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
40430 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
40431 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
40432 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40433 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40434 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
40435 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
40436 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
40437 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
40438 +3 3 3 5 5 5 6 6 6 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 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
40442 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
40443 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
40444 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
40445 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40446 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
40447 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
40448 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
40449 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
40450 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
40451 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 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 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
40456 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
40457 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
40458 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
40459 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40460 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40461 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40462 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
40463 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
40464 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
40465 +6 6 6 4 0 0 4 0 0 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 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
40470 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
40471 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
40472 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
40473 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40474 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
40475 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
40476 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
40477 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
40478 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
40479 +4 0 0 4 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 157 156 157 163 162 163 153 152 153
40484 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
40485 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
40486 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
40487 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40488 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
40489 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
40490 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
40491 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
40492 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
40493 +6 6 6 4 0 0 6 6 6 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 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
40498 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
40499 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
40500 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
40501 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40502 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
40503 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
40504 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
40505 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
40506 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
40507 +4 0 0 3 2 2 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 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
40512 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
40513 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
40514 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
40515 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
40516 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
40517 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
40518 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
40519 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
40520 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
40521 +4 0 0 4 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 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
40526 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
40527 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
40528 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
40529 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40530 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
40531 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
40532 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
40533 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
40534 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
40535 +4 0 0 4 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 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
40540 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
40541 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
40542 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
40543 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40544 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
40545 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
40546 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
40547 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
40548 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
40549 +4 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 174 174 174 177 184 187 167 166 167
40554 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
40555 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
40556 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
40557 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40558 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
40559 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
40560 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
40561 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
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 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
40568 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
40569 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
40570 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
40571 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
40572 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
40573 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
40574 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
40575 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
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 174 174 174 177 184 187 174 174 174
40582 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
40583 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
40584 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
40585 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40586 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
40587 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
40588 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
40589 +4 4 4 5 5 5 3 3 3 2 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 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
40596 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
40597 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
40598 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
40599 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
40600 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
40601 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
40602 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
40603 +4 4 4 5 5 5 3 3 3 0 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 174 174 174 190 197 201 174 174 174
40610 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
40611 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
40612 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
40613 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
40614 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
40615 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
40616 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
40617 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
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 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
40624 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
40625 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
40626 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
40627 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
40628 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
40629 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
40630 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
40631 +4 4 4 5 5 5 3 3 3 0 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 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
40638 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
40639 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
40640 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
40641 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
40642 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
40643 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
40644 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
40645 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
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 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
40652 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
40653 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
40654 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
40655 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
40656 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
40657 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
40658 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
40659 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
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 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40666 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
40667 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
40668 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
40669 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
40670 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
40671 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
40672 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
40673 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
40674 +137 136 137 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 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
40680 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
40681 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
40682 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
40683 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
40684 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
40685 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40686 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
40687 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40688 +137 136 137 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 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40694 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
40695 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
40696 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
40697 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
40698 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
40699 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40700 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
40701 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
40702 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
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 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
40708 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
40709 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
40710 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
40711 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
40712 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
40713 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
40714 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
40715 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
40716 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40717 +0 0 0 3 3 3 5 5 5 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 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40722 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
40723 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
40724 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
40725 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
40726 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
40727 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
40728 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
40729 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
40730 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40731 +0 0 0 3 3 3 5 5 5 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 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
40736 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
40737 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
40738 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
40739 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
40740 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
40741 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
40742 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
40743 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
40744 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40745 +0 0 0 3 3 3 5 5 5 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 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40750 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
40751 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
40752 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
40753 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
40754 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
40755 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
40756 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
40757 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
40758 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40759 +0 0 0 3 3 3 5 5 5 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 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
40764 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
40765 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
40766 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
40767 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
40768 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
40769 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
40770 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
40771 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
40772 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
40773 +0 0 0 3 3 3 5 5 5 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 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
40778 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
40779 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
40780 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
40781 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
40782 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
40783 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
40784 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
40785 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
40786 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
40787 +0 0 0 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 0 0 4 0 0 60 73 81 193 200 203 220 221 221
40792 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
40793 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
40794 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
40795 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
40796 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
40797 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40798 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
40799 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
40800 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
40801 +4 3 3 5 5 5 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 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
40806 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
40807 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
40808 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
40809 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
40810 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
40811 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
40812 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
40813 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
40814 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
40815 +5 5 5 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 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
40820 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
40821 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
40822 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
40823 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
40824 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
40825 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
40826 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
40827 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
40828 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
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 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
40834 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
40835 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
40836 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
40837 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
40838 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
40839 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
40840 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
40841 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
40842 +13 16 17 4 0 0 4 0 0 4 3 3 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 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
40848 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
40849 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
40850 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
40851 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
40852 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
40853 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
40854 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
40855 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
40856 +4 0 0 4 0 0 5 5 5 5 5 5 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 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
40862 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
40863 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
40864 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
40865 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
40866 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
40867 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
40868 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
40869 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
40870 +4 3 3 5 5 5 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 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
40876 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
40877 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
40878 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
40879 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
40880 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
40881 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
40882 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
40883 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
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 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
40890 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
40891 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
40892 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
40893 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
40894 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
40895 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
40896 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
40897 +4 0 0 4 0 0 4 0 0 6 6 6 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 5 5 5 4 3 3 5 5 5 6 6 6
40904 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
40905 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
40906 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
40907 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
40908 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
40909 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
40910 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
40911 +4 0 0 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 5 5 5 5 5 5 4 3 3 6 6 6
40918 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
40919 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
40920 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
40921 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
40922 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
40923 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
40924 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
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 5 5 5 4 3 3
40932 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
40933 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
40934 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
40935 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
40936 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
40937 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
40938 +6 6 6 4 0 0 4 0 0 4 3 3 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 5 5 5
40946 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
40947 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
40948 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
40949 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
40950 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
40951 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
40952 +4 0 0 4 3 3 6 6 6 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 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
40961 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
40962 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
40963 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
40964 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
40965 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
40966 +6 6 6 6 6 6 4 3 3 5 5 5 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 5 5 5 5 5 5 5 5 5
40975 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
40976 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
40977 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
40978 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
40979 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
40980 +5 5 5 5 5 5 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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
40990 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
40991 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
40992 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
40993 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
40994 +4 3 3 5 5 5 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 5 5 5
41004 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41005 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
41006 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
41007 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41019 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41020 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
41021 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 5 5 5 4 3 3 5 5 5 6 6 6
41033 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41034 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41035 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 5 5 5 4 3 3 5 5 5
41047 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
41048 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
41049 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41058 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41059 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41060 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41061 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
41062 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41063 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41064 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41065 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41066 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41067 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41068 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41069 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41070 +4 4 4 4 4 4
41071 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41072 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41073 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41074 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41075 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
41076 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
41077 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41078 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41079 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41080 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41081 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41082 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41083 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41084 +4 4 4 4 4 4
41085 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41086 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41087 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41088 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41089 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
41090 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
41091 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41092 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41093 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41094 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41095 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41096 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41097 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41098 +4 4 4 4 4 4
41099 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41100 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41101 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41102 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41103 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
41104 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
41105 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41106 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41107 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41108 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41109 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41110 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41111 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41112 +4 4 4 4 4 4
41113 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41114 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41115 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41116 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41117 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41118 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
41119 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41120 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41121 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41122 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41123 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41124 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41125 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41126 +4 4 4 4 4 4
41127 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
41128 index a159b63..4ab532d 100644
41129 --- a/drivers/video/udlfb.c
41130 +++ b/drivers/video/udlfb.c
41131 @@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
41132 dlfb_urb_completion(urb);
41133
41134 error:
41135 - atomic_add(bytes_sent, &dev->bytes_sent);
41136 - atomic_add(bytes_identical, &dev->bytes_identical);
41137 - atomic_add(width*height*2, &dev->bytes_rendered);
41138 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41139 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41140 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
41141 end_cycles = get_cycles();
41142 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41143 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41144 >> 10)), /* Kcycles */
41145 &dev->cpu_kcycles_used);
41146
41147 @@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
41148 dlfb_urb_completion(urb);
41149
41150 error:
41151 - atomic_add(bytes_sent, &dev->bytes_sent);
41152 - atomic_add(bytes_identical, &dev->bytes_identical);
41153 - atomic_add(bytes_rendered, &dev->bytes_rendered);
41154 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41155 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41156 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
41157 end_cycles = get_cycles();
41158 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41159 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41160 >> 10)), /* Kcycles */
41161 &dev->cpu_kcycles_used);
41162 }
41163 @@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
41164 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41165 struct dlfb_data *dev = fb_info->par;
41166 return snprintf(buf, PAGE_SIZE, "%u\n",
41167 - atomic_read(&dev->bytes_rendered));
41168 + atomic_read_unchecked(&dev->bytes_rendered));
41169 }
41170
41171 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41172 @@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41173 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41174 struct dlfb_data *dev = fb_info->par;
41175 return snprintf(buf, PAGE_SIZE, "%u\n",
41176 - atomic_read(&dev->bytes_identical));
41177 + atomic_read_unchecked(&dev->bytes_identical));
41178 }
41179
41180 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41181 @@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41182 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41183 struct dlfb_data *dev = fb_info->par;
41184 return snprintf(buf, PAGE_SIZE, "%u\n",
41185 - atomic_read(&dev->bytes_sent));
41186 + atomic_read_unchecked(&dev->bytes_sent));
41187 }
41188
41189 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41190 @@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41191 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41192 struct dlfb_data *dev = fb_info->par;
41193 return snprintf(buf, PAGE_SIZE, "%u\n",
41194 - atomic_read(&dev->cpu_kcycles_used));
41195 + atomic_read_unchecked(&dev->cpu_kcycles_used));
41196 }
41197
41198 static ssize_t edid_show(
41199 @@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
41200 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41201 struct dlfb_data *dev = fb_info->par;
41202
41203 - atomic_set(&dev->bytes_rendered, 0);
41204 - atomic_set(&dev->bytes_identical, 0);
41205 - atomic_set(&dev->bytes_sent, 0);
41206 - atomic_set(&dev->cpu_kcycles_used, 0);
41207 + atomic_set_unchecked(&dev->bytes_rendered, 0);
41208 + atomic_set_unchecked(&dev->bytes_identical, 0);
41209 + atomic_set_unchecked(&dev->bytes_sent, 0);
41210 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
41211
41212 return count;
41213 }
41214 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
41215 index b0e2a42..e2df3ad 100644
41216 --- a/drivers/video/uvesafb.c
41217 +++ b/drivers/video/uvesafb.c
41218 @@ -19,6 +19,7 @@
41219 #include <linux/io.h>
41220 #include <linux/mutex.h>
41221 #include <linux/slab.h>
41222 +#include <linux/moduleloader.h>
41223 #include <video/edid.h>
41224 #include <video/uvesafb.h>
41225 #ifdef CONFIG_X86
41226 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
41227 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
41228 par->pmi_setpal = par->ypan = 0;
41229 } else {
41230 +
41231 +#ifdef CONFIG_PAX_KERNEXEC
41232 +#ifdef CONFIG_MODULES
41233 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
41234 +#endif
41235 + if (!par->pmi_code) {
41236 + par->pmi_setpal = par->ypan = 0;
41237 + return 0;
41238 + }
41239 +#endif
41240 +
41241 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
41242 + task->t.regs.edi);
41243 +
41244 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41245 + pax_open_kernel();
41246 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
41247 + pax_close_kernel();
41248 +
41249 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
41250 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
41251 +#else
41252 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
41253 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
41254 +#endif
41255 +
41256 printk(KERN_INFO "uvesafb: protected mode interface info at "
41257 "%04x:%04x\n",
41258 (u16)task->t.regs.es, (u16)task->t.regs.edi);
41259 @@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
41260 par->ypan = ypan;
41261
41262 if (par->pmi_setpal || par->ypan) {
41263 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
41264 if (__supported_pte_mask & _PAGE_NX) {
41265 par->pmi_setpal = par->ypan = 0;
41266 printk(KERN_WARNING "uvesafb: NX protection is actively."
41267 "We have better not to use the PMI.\n");
41268 - } else {
41269 + } else
41270 +#endif
41271 uvesafb_vbe_getpmi(task, par);
41272 - }
41273 }
41274 #else
41275 /* The protected mode interface is not available on non-x86. */
41276 @@ -1836,6 +1860,11 @@ out:
41277 if (par->vbe_modes)
41278 kfree(par->vbe_modes);
41279
41280 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41281 + if (par->pmi_code)
41282 + module_free_exec(NULL, par->pmi_code);
41283 +#endif
41284 +
41285 framebuffer_release(info);
41286 return err;
41287 }
41288 @@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
41289 kfree(par->vbe_state_orig);
41290 if (par->vbe_state_saved)
41291 kfree(par->vbe_state_saved);
41292 +
41293 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41294 + if (par->pmi_code)
41295 + module_free_exec(NULL, par->pmi_code);
41296 +#endif
41297 +
41298 }
41299
41300 framebuffer_release(info);
41301 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
41302 index 501b340..86bd4cf 100644
41303 --- a/drivers/video/vesafb.c
41304 +++ b/drivers/video/vesafb.c
41305 @@ -9,6 +9,7 @@
41306 */
41307
41308 #include <linux/module.h>
41309 +#include <linux/moduleloader.h>
41310 #include <linux/kernel.h>
41311 #include <linux/errno.h>
41312 #include <linux/string.h>
41313 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
41314 static int vram_total __initdata; /* Set total amount of memory */
41315 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
41316 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
41317 -static void (*pmi_start)(void) __read_mostly;
41318 -static void (*pmi_pal) (void) __read_mostly;
41319 +static void (*pmi_start)(void) __read_only;
41320 +static void (*pmi_pal) (void) __read_only;
41321 static int depth __read_mostly;
41322 static int vga_compat __read_mostly;
41323 /* --------------------------------------------------------------------- */
41324 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
41325 unsigned int size_vmode;
41326 unsigned int size_remap;
41327 unsigned int size_total;
41328 + void *pmi_code = NULL;
41329
41330 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
41331 return -ENODEV;
41332 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
41333 size_remap = size_total;
41334 vesafb_fix.smem_len = size_remap;
41335
41336 -#ifndef __i386__
41337 - screen_info.vesapm_seg = 0;
41338 -#endif
41339 -
41340 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
41341 printk(KERN_WARNING
41342 "vesafb: cannot reserve video memory at 0x%lx\n",
41343 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
41344 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
41345 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
41346
41347 +#ifdef __i386__
41348 +
41349 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41350 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
41351 + if (!pmi_code)
41352 +#elif !defined(CONFIG_PAX_KERNEXEC)
41353 + if (0)
41354 +#endif
41355 +
41356 +#endif
41357 + screen_info.vesapm_seg = 0;
41358 +
41359 if (screen_info.vesapm_seg) {
41360 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
41361 - screen_info.vesapm_seg,screen_info.vesapm_off);
41362 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
41363 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
41364 }
41365
41366 if (screen_info.vesapm_seg < 0xc000)
41367 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
41368
41369 if (ypan || pmi_setpal) {
41370 unsigned short *pmi_base;
41371 +
41372 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
41373 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
41374 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
41375 +
41376 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41377 + pax_open_kernel();
41378 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
41379 +#else
41380 + pmi_code = pmi_base;
41381 +#endif
41382 +
41383 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
41384 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
41385 +
41386 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41387 + pmi_start = ktva_ktla(pmi_start);
41388 + pmi_pal = ktva_ktla(pmi_pal);
41389 + pax_close_kernel();
41390 +#endif
41391 +
41392 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
41393 if (pmi_base[3]) {
41394 printk(KERN_INFO "vesafb: pmi: ports = ");
41395 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
41396 info->node, info->fix.id);
41397 return 0;
41398 err:
41399 +
41400 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41401 + module_free_exec(NULL, pmi_code);
41402 +#endif
41403 +
41404 if (info->screen_base)
41405 iounmap(info->screen_base);
41406 framebuffer_release(info);
41407 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
41408 index 88714ae..16c2e11 100644
41409 --- a/drivers/video/via/via_clock.h
41410 +++ b/drivers/video/via/via_clock.h
41411 @@ -56,7 +56,7 @@ struct via_clock {
41412
41413 void (*set_engine_pll_state)(u8 state);
41414 void (*set_engine_pll)(struct via_pll_config config);
41415 -};
41416 +} __no_const;
41417
41418
41419 static inline u32 get_pll_internal_frequency(u32 ref_freq,
41420 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
41421 index e56c934..fc22f4b 100644
41422 --- a/drivers/xen/xen-pciback/conf_space.h
41423 +++ b/drivers/xen/xen-pciback/conf_space.h
41424 @@ -44,15 +44,15 @@ struct config_field {
41425 struct {
41426 conf_dword_write write;
41427 conf_dword_read read;
41428 - } dw;
41429 + } __no_const dw;
41430 struct {
41431 conf_word_write write;
41432 conf_word_read read;
41433 - } w;
41434 + } __no_const w;
41435 struct {
41436 conf_byte_write write;
41437 conf_byte_read read;
41438 - } b;
41439 + } __no_const b;
41440 } u;
41441 struct list_head list;
41442 };
41443 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
41444 index 014c8dd..6f3dfe6 100644
41445 --- a/fs/9p/vfs_inode.c
41446 +++ b/fs/9p/vfs_inode.c
41447 @@ -1303,7 +1303,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
41448 void
41449 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
41450 {
41451 - char *s = nd_get_link(nd);
41452 + const char *s = nd_get_link(nd);
41453
41454 p9_debug(P9_DEBUG_VFS, " %s %s\n",
41455 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
41456 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
41457 index e95d1b6..3454244 100644
41458 --- a/fs/Kconfig.binfmt
41459 +++ b/fs/Kconfig.binfmt
41460 @@ -89,7 +89,7 @@ config HAVE_AOUT
41461
41462 config BINFMT_AOUT
41463 tristate "Kernel support for a.out and ECOFF binaries"
41464 - depends on HAVE_AOUT
41465 + depends on HAVE_AOUT && BROKEN
41466 ---help---
41467 A.out (Assembler.OUTput) is a set of formats for libraries and
41468 executables used in the earliest versions of UNIX. Linux used
41469 diff --git a/fs/aio.c b/fs/aio.c
41470 index e7f2fad..15ad8a4 100644
41471 --- a/fs/aio.c
41472 +++ b/fs/aio.c
41473 @@ -118,7 +118,7 @@ static int aio_setup_ring(struct kioctx *ctx)
41474 size += sizeof(struct io_event) * nr_events;
41475 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
41476
41477 - if (nr_pages < 0)
41478 + if (nr_pages <= 0)
41479 return -EINVAL;
41480
41481 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
41482 @@ -1440,18 +1440,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
41483 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
41484 {
41485 ssize_t ret;
41486 + struct iovec iovstack;
41487
41488 #ifdef CONFIG_COMPAT
41489 if (compat)
41490 ret = compat_rw_copy_check_uvector(type,
41491 (struct compat_iovec __user *)kiocb->ki_buf,
41492 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
41493 + kiocb->ki_nbytes, 1, &iovstack,
41494 &kiocb->ki_iovec, 1);
41495 else
41496 #endif
41497 ret = rw_copy_check_uvector(type,
41498 (struct iovec __user *)kiocb->ki_buf,
41499 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
41500 + kiocb->ki_nbytes, 1, &iovstack,
41501 &kiocb->ki_iovec, 1);
41502 if (ret < 0)
41503 goto out;
41504 @@ -1460,6 +1461,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
41505 if (ret < 0)
41506 goto out;
41507
41508 + if (kiocb->ki_iovec == &iovstack) {
41509 + kiocb->ki_inline_vec = iovstack;
41510 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
41511 + }
41512 kiocb->ki_nr_segs = kiocb->ki_nbytes;
41513 kiocb->ki_cur_seg = 0;
41514 /* ki_nbytes/left now reflect bytes instead of segs */
41515 diff --git a/fs/attr.c b/fs/attr.c
41516 index d94d1b6..f9bccd6 100644
41517 --- a/fs/attr.c
41518 +++ b/fs/attr.c
41519 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
41520 unsigned long limit;
41521
41522 limit = rlimit(RLIMIT_FSIZE);
41523 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
41524 if (limit != RLIM_INFINITY && offset > limit)
41525 goto out_sig;
41526 if (offset > inode->i_sb->s_maxbytes)
41527 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
41528 index da8876d..9f3e6d8 100644
41529 --- a/fs/autofs4/waitq.c
41530 +++ b/fs/autofs4/waitq.c
41531 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
41532 {
41533 unsigned long sigpipe, flags;
41534 mm_segment_t fs;
41535 - const char *data = (const char *)addr;
41536 + const char __user *data = (const char __force_user *)addr;
41537 ssize_t wr = 0;
41538
41539 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
41540 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
41541 index e18da23..affc30e 100644
41542 --- a/fs/befs/linuxvfs.c
41543 +++ b/fs/befs/linuxvfs.c
41544 @@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
41545 {
41546 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
41547 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
41548 - char *link = nd_get_link(nd);
41549 + const char *link = nd_get_link(nd);
41550 if (!IS_ERR(link))
41551 kfree(link);
41552 }
41553 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
41554 index d146e18..12d1bd1 100644
41555 --- a/fs/binfmt_aout.c
41556 +++ b/fs/binfmt_aout.c
41557 @@ -16,6 +16,7 @@
41558 #include <linux/string.h>
41559 #include <linux/fs.h>
41560 #include <linux/file.h>
41561 +#include <linux/security.h>
41562 #include <linux/stat.h>
41563 #include <linux/fcntl.h>
41564 #include <linux/ptrace.h>
41565 @@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
41566 #endif
41567 # define START_STACK(u) ((void __user *)u.start_stack)
41568
41569 + memset(&dump, 0, sizeof(dump));
41570 +
41571 fs = get_fs();
41572 set_fs(KERNEL_DS);
41573 has_dumped = 1;
41574 @@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
41575
41576 /* If the size of the dump file exceeds the rlimit, then see what would happen
41577 if we wrote the stack, but not the data area. */
41578 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
41579 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
41580 dump.u_dsize = 0;
41581
41582 /* Make sure we have enough room to write the stack and data areas. */
41583 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
41584 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
41585 dump.u_ssize = 0;
41586
41587 @@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41588 rlim = rlimit(RLIMIT_DATA);
41589 if (rlim >= RLIM_INFINITY)
41590 rlim = ~0;
41591 +
41592 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
41593 if (ex.a_data + ex.a_bss > rlim)
41594 return -ENOMEM;
41595
41596 @@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41597
41598 install_exec_creds(bprm);
41599
41600 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
41601 + current->mm->pax_flags = 0UL;
41602 +#endif
41603 +
41604 +#ifdef CONFIG_PAX_PAGEEXEC
41605 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
41606 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
41607 +
41608 +#ifdef CONFIG_PAX_EMUTRAMP
41609 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
41610 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
41611 +#endif
41612 +
41613 +#ifdef CONFIG_PAX_MPROTECT
41614 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
41615 + current->mm->pax_flags |= MF_PAX_MPROTECT;
41616 +#endif
41617 +
41618 + }
41619 +#endif
41620 +
41621 if (N_MAGIC(ex) == OMAGIC) {
41622 unsigned long text_addr, map_size;
41623 loff_t pos;
41624 @@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41625 }
41626
41627 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
41628 - PROT_READ | PROT_WRITE | PROT_EXEC,
41629 + PROT_READ | PROT_WRITE,
41630 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
41631 fd_offset + ex.a_text);
41632 if (error != N_DATADDR(ex)) {
41633 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
41634 index 16f7354..666524e 100644
41635 --- a/fs/binfmt_elf.c
41636 +++ b/fs/binfmt_elf.c
41637 @@ -32,6 +32,7 @@
41638 #include <linux/elf.h>
41639 #include <linux/utsname.h>
41640 #include <linux/coredump.h>
41641 +#include <linux/xattr.h>
41642 #include <asm/uaccess.h>
41643 #include <asm/param.h>
41644 #include <asm/page.h>
41645 @@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
41646 #define elf_core_dump NULL
41647 #endif
41648
41649 +#ifdef CONFIG_PAX_MPROTECT
41650 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
41651 +#endif
41652 +
41653 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
41654 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
41655 #else
41656 @@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
41657 .load_binary = load_elf_binary,
41658 .load_shlib = load_elf_library,
41659 .core_dump = elf_core_dump,
41660 +
41661 +#ifdef CONFIG_PAX_MPROTECT
41662 + .handle_mprotect= elf_handle_mprotect,
41663 +#endif
41664 +
41665 .min_coredump = ELF_EXEC_PAGESIZE,
41666 };
41667
41668 @@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
41669
41670 static int set_brk(unsigned long start, unsigned long end)
41671 {
41672 + unsigned long e = end;
41673 +
41674 start = ELF_PAGEALIGN(start);
41675 end = ELF_PAGEALIGN(end);
41676 if (end > start) {
41677 @@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
41678 if (BAD_ADDR(addr))
41679 return addr;
41680 }
41681 - current->mm->start_brk = current->mm->brk = end;
41682 + current->mm->start_brk = current->mm->brk = e;
41683 return 0;
41684 }
41685
41686 @@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
41687 elf_addr_t __user *u_rand_bytes;
41688 const char *k_platform = ELF_PLATFORM;
41689 const char *k_base_platform = ELF_BASE_PLATFORM;
41690 - unsigned char k_rand_bytes[16];
41691 + u32 k_rand_bytes[4];
41692 int items;
41693 elf_addr_t *elf_info;
41694 int ei_index = 0;
41695 const struct cred *cred = current_cred();
41696 struct vm_area_struct *vma;
41697 + unsigned long saved_auxv[AT_VECTOR_SIZE];
41698
41699 /*
41700 * In some cases (e.g. Hyper-Threading), we want to avoid L1
41701 @@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
41702 * Generate 16 random bytes for userspace PRNG seeding.
41703 */
41704 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
41705 - u_rand_bytes = (elf_addr_t __user *)
41706 - STACK_ALLOC(p, sizeof(k_rand_bytes));
41707 + srandom32(k_rand_bytes[0] ^ random32());
41708 + srandom32(k_rand_bytes[1] ^ random32());
41709 + srandom32(k_rand_bytes[2] ^ random32());
41710 + srandom32(k_rand_bytes[3] ^ random32());
41711 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
41712 + u_rand_bytes = (elf_addr_t __user *) p;
41713 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
41714 return -EFAULT;
41715
41716 @@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
41717 return -EFAULT;
41718 current->mm->env_end = p;
41719
41720 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
41721 +
41722 /* Put the elf_info on the stack in the right place. */
41723 sp = (elf_addr_t __user *)envp + 1;
41724 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
41725 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
41726 return -EFAULT;
41727 return 0;
41728 }
41729 @@ -380,10 +399,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
41730 {
41731 struct elf_phdr *elf_phdata;
41732 struct elf_phdr *eppnt;
41733 - unsigned long load_addr = 0;
41734 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
41735 int load_addr_set = 0;
41736 unsigned long last_bss = 0, elf_bss = 0;
41737 - unsigned long error = ~0UL;
41738 + unsigned long error = -EINVAL;
41739 unsigned long total_size;
41740 int retval, i, size;
41741
41742 @@ -429,6 +448,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
41743 goto out_close;
41744 }
41745
41746 +#ifdef CONFIG_PAX_SEGMEXEC
41747 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
41748 + pax_task_size = SEGMEXEC_TASK_SIZE;
41749 +#endif
41750 +
41751 eppnt = elf_phdata;
41752 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
41753 if (eppnt->p_type == PT_LOAD) {
41754 @@ -472,8 +496,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
41755 k = load_addr + eppnt->p_vaddr;
41756 if (BAD_ADDR(k) ||
41757 eppnt->p_filesz > eppnt->p_memsz ||
41758 - eppnt->p_memsz > TASK_SIZE ||
41759 - TASK_SIZE - eppnt->p_memsz < k) {
41760 + eppnt->p_memsz > pax_task_size ||
41761 + pax_task_size - eppnt->p_memsz < k) {
41762 error = -ENOMEM;
41763 goto out_close;
41764 }
41765 @@ -525,6 +549,349 @@ out:
41766 return error;
41767 }
41768
41769 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
41770 +#ifdef CONFIG_PAX_SOFTMODE
41771 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
41772 +{
41773 + unsigned long pax_flags = 0UL;
41774 +
41775 +#ifdef CONFIG_PAX_PAGEEXEC
41776 + if (elf_phdata->p_flags & PF_PAGEEXEC)
41777 + pax_flags |= MF_PAX_PAGEEXEC;
41778 +#endif
41779 +
41780 +#ifdef CONFIG_PAX_SEGMEXEC
41781 + if (elf_phdata->p_flags & PF_SEGMEXEC)
41782 + pax_flags |= MF_PAX_SEGMEXEC;
41783 +#endif
41784 +
41785 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41786 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41787 + if ((__supported_pte_mask & _PAGE_NX))
41788 + pax_flags &= ~MF_PAX_SEGMEXEC;
41789 + else
41790 + pax_flags &= ~MF_PAX_PAGEEXEC;
41791 + }
41792 +#endif
41793 +
41794 +#ifdef CONFIG_PAX_EMUTRAMP
41795 + if (elf_phdata->p_flags & PF_EMUTRAMP)
41796 + pax_flags |= MF_PAX_EMUTRAMP;
41797 +#endif
41798 +
41799 +#ifdef CONFIG_PAX_MPROTECT
41800 + if (elf_phdata->p_flags & PF_MPROTECT)
41801 + pax_flags |= MF_PAX_MPROTECT;
41802 +#endif
41803 +
41804 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41805 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
41806 + pax_flags |= MF_PAX_RANDMMAP;
41807 +#endif
41808 +
41809 + return pax_flags;
41810 +}
41811 +#endif
41812 +
41813 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
41814 +{
41815 + unsigned long pax_flags = 0UL;
41816 +
41817 +#ifdef CONFIG_PAX_PAGEEXEC
41818 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
41819 + pax_flags |= MF_PAX_PAGEEXEC;
41820 +#endif
41821 +
41822 +#ifdef CONFIG_PAX_SEGMEXEC
41823 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
41824 + pax_flags |= MF_PAX_SEGMEXEC;
41825 +#endif
41826 +
41827 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41828 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41829 + if ((__supported_pte_mask & _PAGE_NX))
41830 + pax_flags &= ~MF_PAX_SEGMEXEC;
41831 + else
41832 + pax_flags &= ~MF_PAX_PAGEEXEC;
41833 + }
41834 +#endif
41835 +
41836 +#ifdef CONFIG_PAX_EMUTRAMP
41837 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
41838 + pax_flags |= MF_PAX_EMUTRAMP;
41839 +#endif
41840 +
41841 +#ifdef CONFIG_PAX_MPROTECT
41842 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
41843 + pax_flags |= MF_PAX_MPROTECT;
41844 +#endif
41845 +
41846 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41847 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
41848 + pax_flags |= MF_PAX_RANDMMAP;
41849 +#endif
41850 +
41851 + return pax_flags;
41852 +}
41853 +#endif
41854 +
41855 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
41856 +#ifdef CONFIG_PAX_SOFTMODE
41857 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
41858 +{
41859 + unsigned long pax_flags = 0UL;
41860 +
41861 +#ifdef CONFIG_PAX_PAGEEXEC
41862 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
41863 + pax_flags |= MF_PAX_PAGEEXEC;
41864 +#endif
41865 +
41866 +#ifdef CONFIG_PAX_SEGMEXEC
41867 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
41868 + pax_flags |= MF_PAX_SEGMEXEC;
41869 +#endif
41870 +
41871 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41872 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41873 + if ((__supported_pte_mask & _PAGE_NX))
41874 + pax_flags &= ~MF_PAX_SEGMEXEC;
41875 + else
41876 + pax_flags &= ~MF_PAX_PAGEEXEC;
41877 + }
41878 +#endif
41879 +
41880 +#ifdef CONFIG_PAX_EMUTRAMP
41881 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
41882 + pax_flags |= MF_PAX_EMUTRAMP;
41883 +#endif
41884 +
41885 +#ifdef CONFIG_PAX_MPROTECT
41886 + if (pax_flags_softmode & MF_PAX_MPROTECT)
41887 + pax_flags |= MF_PAX_MPROTECT;
41888 +#endif
41889 +
41890 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41891 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
41892 + pax_flags |= MF_PAX_RANDMMAP;
41893 +#endif
41894 +
41895 + return pax_flags;
41896 +}
41897 +#endif
41898 +
41899 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
41900 +{
41901 + unsigned long pax_flags = 0UL;
41902 +
41903 +#ifdef CONFIG_PAX_PAGEEXEC
41904 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
41905 + pax_flags |= MF_PAX_PAGEEXEC;
41906 +#endif
41907 +
41908 +#ifdef CONFIG_PAX_SEGMEXEC
41909 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
41910 + pax_flags |= MF_PAX_SEGMEXEC;
41911 +#endif
41912 +
41913 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41914 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41915 + if ((__supported_pte_mask & _PAGE_NX))
41916 + pax_flags &= ~MF_PAX_SEGMEXEC;
41917 + else
41918 + pax_flags &= ~MF_PAX_PAGEEXEC;
41919 + }
41920 +#endif
41921 +
41922 +#ifdef CONFIG_PAX_EMUTRAMP
41923 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
41924 + pax_flags |= MF_PAX_EMUTRAMP;
41925 +#endif
41926 +
41927 +#ifdef CONFIG_PAX_MPROTECT
41928 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
41929 + pax_flags |= MF_PAX_MPROTECT;
41930 +#endif
41931 +
41932 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41933 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
41934 + pax_flags |= MF_PAX_RANDMMAP;
41935 +#endif
41936 +
41937 + return pax_flags;
41938 +}
41939 +#endif
41940 +
41941 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
41942 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
41943 +{
41944 + unsigned long pax_flags = 0UL;
41945 +
41946 +#ifdef CONFIG_PAX_EI_PAX
41947 +
41948 +#ifdef CONFIG_PAX_PAGEEXEC
41949 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
41950 + pax_flags |= MF_PAX_PAGEEXEC;
41951 +#endif
41952 +
41953 +#ifdef CONFIG_PAX_SEGMEXEC
41954 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
41955 + pax_flags |= MF_PAX_SEGMEXEC;
41956 +#endif
41957 +
41958 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41959 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41960 + if ((__supported_pte_mask & _PAGE_NX))
41961 + pax_flags &= ~MF_PAX_SEGMEXEC;
41962 + else
41963 + pax_flags &= ~MF_PAX_PAGEEXEC;
41964 + }
41965 +#endif
41966 +
41967 +#ifdef CONFIG_PAX_EMUTRAMP
41968 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
41969 + pax_flags |= MF_PAX_EMUTRAMP;
41970 +#endif
41971 +
41972 +#ifdef CONFIG_PAX_MPROTECT
41973 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
41974 + pax_flags |= MF_PAX_MPROTECT;
41975 +#endif
41976 +
41977 +#ifdef CONFIG_PAX_ASLR
41978 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
41979 + pax_flags |= MF_PAX_RANDMMAP;
41980 +#endif
41981 +
41982 +#else
41983 +
41984 +#ifdef CONFIG_PAX_PAGEEXEC
41985 + pax_flags |= MF_PAX_PAGEEXEC;
41986 +#endif
41987 +
41988 +#ifdef CONFIG_PAX_MPROTECT
41989 + pax_flags |= MF_PAX_MPROTECT;
41990 +#endif
41991 +
41992 +#ifdef CONFIG_PAX_RANDMMAP
41993 + pax_flags |= MF_PAX_RANDMMAP;
41994 +#endif
41995 +
41996 +#ifdef CONFIG_PAX_SEGMEXEC
41997 + if (!(pax_flags & MF_PAX_PAGEEXEC) || !(__supported_pte_mask & _PAGE_NX)) {
41998 + pax_flags &= ~MF_PAX_PAGEEXEC;
41999 + pax_flags |= MF_PAX_SEGMEXEC;
42000 + }
42001 +#endif
42002 +
42003 +#endif
42004 +
42005 + return pax_flags;
42006 +}
42007 +
42008 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
42009 +{
42010 +
42011 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42012 + unsigned long i;
42013 +
42014 + for (i = 0UL; i < elf_ex->e_phnum; i++)
42015 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
42016 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
42017 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
42018 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
42019 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
42020 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
42021 + return ~0UL;
42022 +
42023 +#ifdef CONFIG_PAX_SOFTMODE
42024 + if (pax_softmode)
42025 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
42026 + else
42027 +#endif
42028 +
42029 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
42030 + break;
42031 + }
42032 +#endif
42033 +
42034 + return ~0UL;
42035 +}
42036 +
42037 +static unsigned long pax_parse_xattr_pax(struct file * const file)
42038 +{
42039 +
42040 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42041 + ssize_t xattr_size, i;
42042 + unsigned char xattr_value[5];
42043 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
42044 +
42045 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
42046 + if (xattr_size <= 0)
42047 + return ~0UL;
42048 +
42049 + for (i = 0; i < xattr_size; i++)
42050 + switch (xattr_value[i]) {
42051 + default:
42052 + return ~0UL;
42053 +
42054 +#define parse_flag(option1, option2, flag) \
42055 + case option1: \
42056 + pax_flags_hardmode |= MF_PAX_##flag; \
42057 + break; \
42058 + case option2: \
42059 + pax_flags_softmode |= MF_PAX_##flag; \
42060 + break;
42061 +
42062 + parse_flag('p', 'P', PAGEEXEC);
42063 + parse_flag('e', 'E', EMUTRAMP);
42064 + parse_flag('m', 'M', MPROTECT);
42065 + parse_flag('r', 'R', RANDMMAP);
42066 + parse_flag('s', 'S', SEGMEXEC);
42067 +
42068 +#undef parse_flag
42069 + }
42070 +
42071 + if (pax_flags_hardmode & pax_flags_softmode)
42072 + return ~0UL;
42073 +
42074 +#ifdef CONFIG_PAX_SOFTMODE
42075 + if (pax_softmode)
42076 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
42077 + else
42078 +#endif
42079 +
42080 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
42081 +#else
42082 + return ~0UL;
42083 +#endif
42084 +
42085 +}
42086 +
42087 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
42088 +{
42089 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
42090 +
42091 + pax_flags = pax_parse_ei_pax(elf_ex);
42092 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
42093 + xattr_pax_flags = pax_parse_xattr_pax(file);
42094 +
42095 + if (pt_pax_flags == ~0UL)
42096 + pt_pax_flags = xattr_pax_flags;
42097 + else if (xattr_pax_flags == ~0UL)
42098 + xattr_pax_flags = pt_pax_flags;
42099 + if (pt_pax_flags != xattr_pax_flags)
42100 + return -EINVAL;
42101 + if (pt_pax_flags != ~0UL)
42102 + pax_flags = pt_pax_flags;
42103 +
42104 + if (0 > pax_check_flags(&pax_flags))
42105 + return -EINVAL;
42106 +
42107 + current->mm->pax_flags = pax_flags;
42108 + return 0;
42109 +}
42110 +#endif
42111 +
42112 /*
42113 * These are the functions used to load ELF style executables and shared
42114 * libraries. There is no binary dependent code anywhere else.
42115 @@ -541,6 +908,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
42116 {
42117 unsigned int random_variable = 0;
42118
42119 +#ifdef CONFIG_PAX_RANDUSTACK
42120 + if (randomize_va_space)
42121 + return stack_top - current->mm->delta_stack;
42122 +#endif
42123 +
42124 if ((current->flags & PF_RANDOMIZE) &&
42125 !(current->personality & ADDR_NO_RANDOMIZE)) {
42126 random_variable = get_random_int() & STACK_RND_MASK;
42127 @@ -559,7 +931,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42128 unsigned long load_addr = 0, load_bias = 0;
42129 int load_addr_set = 0;
42130 char * elf_interpreter = NULL;
42131 - unsigned long error;
42132 + unsigned long error = 0;
42133 struct elf_phdr *elf_ppnt, *elf_phdata;
42134 unsigned long elf_bss, elf_brk;
42135 int retval, i;
42136 @@ -569,11 +941,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42137 unsigned long start_code, end_code, start_data, end_data;
42138 unsigned long reloc_func_desc __maybe_unused = 0;
42139 int executable_stack = EXSTACK_DEFAULT;
42140 - unsigned long def_flags = 0;
42141 struct {
42142 struct elfhdr elf_ex;
42143 struct elfhdr interp_elf_ex;
42144 } *loc;
42145 + unsigned long pax_task_size = TASK_SIZE;
42146
42147 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
42148 if (!loc) {
42149 @@ -709,11 +1081,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42150 goto out_free_dentry;
42151
42152 /* OK, This is the point of no return */
42153 - current->mm->def_flags = def_flags;
42154 +
42155 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42156 + current->mm->pax_flags = 0UL;
42157 +#endif
42158 +
42159 +#ifdef CONFIG_PAX_DLRESOLVE
42160 + current->mm->call_dl_resolve = 0UL;
42161 +#endif
42162 +
42163 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
42164 + current->mm->call_syscall = 0UL;
42165 +#endif
42166 +
42167 +#ifdef CONFIG_PAX_ASLR
42168 + current->mm->delta_mmap = 0UL;
42169 + current->mm->delta_stack = 0UL;
42170 +#endif
42171 +
42172 + current->mm->def_flags = 0;
42173 +
42174 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
42175 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
42176 + send_sig(SIGKILL, current, 0);
42177 + goto out_free_dentry;
42178 + }
42179 +#endif
42180 +
42181 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
42182 + pax_set_initial_flags(bprm);
42183 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
42184 + if (pax_set_initial_flags_func)
42185 + (pax_set_initial_flags_func)(bprm);
42186 +#endif
42187 +
42188 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
42189 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
42190 + current->mm->context.user_cs_limit = PAGE_SIZE;
42191 + current->mm->def_flags |= VM_PAGEEXEC;
42192 + }
42193 +#endif
42194 +
42195 +#ifdef CONFIG_PAX_SEGMEXEC
42196 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
42197 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
42198 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
42199 + pax_task_size = SEGMEXEC_TASK_SIZE;
42200 + current->mm->def_flags |= VM_NOHUGEPAGE;
42201 + }
42202 +#endif
42203 +
42204 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
42205 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42206 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
42207 + put_cpu();
42208 + }
42209 +#endif
42210
42211 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
42212 may depend on the personality. */
42213 SET_PERSONALITY(loc->elf_ex);
42214 +
42215 +#ifdef CONFIG_PAX_ASLR
42216 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42217 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
42218 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
42219 + }
42220 +#endif
42221 +
42222 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
42223 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42224 + executable_stack = EXSTACK_DISABLE_X;
42225 + current->personality &= ~READ_IMPLIES_EXEC;
42226 + } else
42227 +#endif
42228 +
42229 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
42230 current->personality |= READ_IMPLIES_EXEC;
42231
42232 @@ -804,6 +1246,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42233 #else
42234 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
42235 #endif
42236 +
42237 +#ifdef CONFIG_PAX_RANDMMAP
42238 + /* PaX: randomize base address at the default exe base if requested */
42239 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
42240 +#ifdef CONFIG_SPARC64
42241 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
42242 +#else
42243 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
42244 +#endif
42245 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
42246 + elf_flags |= MAP_FIXED;
42247 + }
42248 +#endif
42249 +
42250 }
42251
42252 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
42253 @@ -836,9 +1292,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42254 * allowed task size. Note that p_filesz must always be
42255 * <= p_memsz so it is only necessary to check p_memsz.
42256 */
42257 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42258 - elf_ppnt->p_memsz > TASK_SIZE ||
42259 - TASK_SIZE - elf_ppnt->p_memsz < k) {
42260 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42261 + elf_ppnt->p_memsz > pax_task_size ||
42262 + pax_task_size - elf_ppnt->p_memsz < k) {
42263 /* set_brk can never work. Avoid overflows. */
42264 send_sig(SIGKILL, current, 0);
42265 retval = -EINVAL;
42266 @@ -877,11 +1333,40 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42267 goto out_free_dentry;
42268 }
42269 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
42270 - send_sig(SIGSEGV, current, 0);
42271 - retval = -EFAULT; /* Nobody gets to see this, but.. */
42272 - goto out_free_dentry;
42273 + /*
42274 + * This bss-zeroing can fail if the ELF
42275 + * file specifies odd protections. So
42276 + * we don't check the return value
42277 + */
42278 }
42279
42280 +#ifdef CONFIG_PAX_RANDMMAP
42281 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42282 + unsigned long start, size;
42283 +
42284 + start = ELF_PAGEALIGN(elf_brk);
42285 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
42286 + down_write(&current->mm->mmap_sem);
42287 + retval = -ENOMEM;
42288 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
42289 + unsigned long prot = PROT_NONE;
42290 +
42291 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
42292 +// if (current->personality & ADDR_NO_RANDOMIZE)
42293 +// prot = PROT_READ;
42294 + start = do_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
42295 + retval = IS_ERR_VALUE(start) ? start : 0;
42296 + }
42297 + up_write(&current->mm->mmap_sem);
42298 + if (retval == 0)
42299 + retval = set_brk(start + size, start + size + PAGE_SIZE);
42300 + if (retval < 0) {
42301 + send_sig(SIGKILL, current, 0);
42302 + goto out_free_dentry;
42303 + }
42304 + }
42305 +#endif
42306 +
42307 if (elf_interpreter) {
42308 unsigned long uninitialized_var(interp_map_addr);
42309
42310 @@ -1109,7 +1594,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
42311 * Decide what to dump of a segment, part, all or none.
42312 */
42313 static unsigned long vma_dump_size(struct vm_area_struct *vma,
42314 - unsigned long mm_flags)
42315 + unsigned long mm_flags, long signr)
42316 {
42317 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
42318
42319 @@ -1146,7 +1631,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
42320 if (vma->vm_file == NULL)
42321 return 0;
42322
42323 - if (FILTER(MAPPED_PRIVATE))
42324 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
42325 goto whole;
42326
42327 /*
42328 @@ -1368,9 +1853,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
42329 {
42330 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
42331 int i = 0;
42332 - do
42333 + do {
42334 i += 2;
42335 - while (auxv[i - 2] != AT_NULL);
42336 + } while (auxv[i - 2] != AT_NULL);
42337 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
42338 }
42339
42340 @@ -1892,14 +2377,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
42341 }
42342
42343 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
42344 - unsigned long mm_flags)
42345 + struct coredump_params *cprm)
42346 {
42347 struct vm_area_struct *vma;
42348 size_t size = 0;
42349
42350 for (vma = first_vma(current, gate_vma); vma != NULL;
42351 vma = next_vma(vma, gate_vma))
42352 - size += vma_dump_size(vma, mm_flags);
42353 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42354 return size;
42355 }
42356
42357 @@ -1993,7 +2478,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42358
42359 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
42360
42361 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
42362 + offset += elf_core_vma_data_size(gate_vma, cprm);
42363 offset += elf_core_extra_data_size();
42364 e_shoff = offset;
42365
42366 @@ -2007,10 +2492,12 @@ static int elf_core_dump(struct coredump_params *cprm)
42367 offset = dataoff;
42368
42369 size += sizeof(*elf);
42370 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42371 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
42372 goto end_coredump;
42373
42374 size += sizeof(*phdr4note);
42375 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42376 if (size > cprm->limit
42377 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
42378 goto end_coredump;
42379 @@ -2024,7 +2511,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42380 phdr.p_offset = offset;
42381 phdr.p_vaddr = vma->vm_start;
42382 phdr.p_paddr = 0;
42383 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
42384 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42385 phdr.p_memsz = vma->vm_end - vma->vm_start;
42386 offset += phdr.p_filesz;
42387 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
42388 @@ -2035,6 +2522,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42389 phdr.p_align = ELF_EXEC_PAGESIZE;
42390
42391 size += sizeof(phdr);
42392 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42393 if (size > cprm->limit
42394 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
42395 goto end_coredump;
42396 @@ -2059,7 +2547,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42397 unsigned long addr;
42398 unsigned long end;
42399
42400 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
42401 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42402
42403 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
42404 struct page *page;
42405 @@ -2068,6 +2556,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42406 page = get_dump_page(addr);
42407 if (page) {
42408 void *kaddr = kmap(page);
42409 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
42410 stop = ((size += PAGE_SIZE) > cprm->limit) ||
42411 !dump_write(cprm->file, kaddr,
42412 PAGE_SIZE);
42413 @@ -2085,6 +2574,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42414
42415 if (e_phnum == PN_XNUM) {
42416 size += sizeof(*shdr4extnum);
42417 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42418 if (size > cprm->limit
42419 || !dump_write(cprm->file, shdr4extnum,
42420 sizeof(*shdr4extnum)))
42421 @@ -2105,6 +2595,97 @@ out:
42422
42423 #endif /* CONFIG_ELF_CORE */
42424
42425 +#ifdef CONFIG_PAX_MPROTECT
42426 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
42427 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
42428 + * we'll remove VM_MAYWRITE for good on RELRO segments.
42429 + *
42430 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
42431 + * basis because we want to allow the common case and not the special ones.
42432 + */
42433 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
42434 +{
42435 + struct elfhdr elf_h;
42436 + struct elf_phdr elf_p;
42437 + unsigned long i;
42438 + unsigned long oldflags;
42439 + bool is_textrel_rw, is_textrel_rx, is_relro;
42440 +
42441 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
42442 + return;
42443 +
42444 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
42445 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
42446 +
42447 +#ifdef CONFIG_PAX_ELFRELOCS
42448 + /* possible TEXTREL */
42449 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
42450 + 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);
42451 +#else
42452 + is_textrel_rw = false;
42453 + is_textrel_rx = false;
42454 +#endif
42455 +
42456 + /* possible RELRO */
42457 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
42458 +
42459 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
42460 + return;
42461 +
42462 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
42463 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
42464 +
42465 +#ifdef CONFIG_PAX_ETEXECRELOCS
42466 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
42467 +#else
42468 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
42469 +#endif
42470 +
42471 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
42472 + !elf_check_arch(&elf_h) ||
42473 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
42474 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
42475 + return;
42476 +
42477 + for (i = 0UL; i < elf_h.e_phnum; i++) {
42478 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
42479 + return;
42480 + switch (elf_p.p_type) {
42481 + case PT_DYNAMIC:
42482 + if (!is_textrel_rw && !is_textrel_rx)
42483 + continue;
42484 + i = 0UL;
42485 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
42486 + elf_dyn dyn;
42487 +
42488 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
42489 + return;
42490 + if (dyn.d_tag == DT_NULL)
42491 + return;
42492 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
42493 + gr_log_textrel(vma);
42494 + if (is_textrel_rw)
42495 + vma->vm_flags |= VM_MAYWRITE;
42496 + else
42497 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
42498 + vma->vm_flags &= ~VM_MAYWRITE;
42499 + return;
42500 + }
42501 + i++;
42502 + }
42503 + return;
42504 +
42505 + case PT_GNU_RELRO:
42506 + if (!is_relro)
42507 + continue;
42508 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
42509 + vma->vm_flags &= ~VM_MAYWRITE;
42510 + return;
42511 + }
42512 + }
42513 +}
42514 +#endif
42515 +
42516 static int __init init_elf_binfmt(void)
42517 {
42518 register_binfmt(&elf_format);
42519 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
42520 index 6b2daf9..a70dccb 100644
42521 --- a/fs/binfmt_flat.c
42522 +++ b/fs/binfmt_flat.c
42523 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
42524 realdatastart = (unsigned long) -ENOMEM;
42525 printk("Unable to allocate RAM for process data, errno %d\n",
42526 (int)-realdatastart);
42527 + down_write(&current->mm->mmap_sem);
42528 do_munmap(current->mm, textpos, text_len);
42529 + up_write(&current->mm->mmap_sem);
42530 ret = realdatastart;
42531 goto err;
42532 }
42533 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
42534 }
42535 if (IS_ERR_VALUE(result)) {
42536 printk("Unable to read data+bss, errno %d\n", (int)-result);
42537 + down_write(&current->mm->mmap_sem);
42538 do_munmap(current->mm, textpos, text_len);
42539 do_munmap(current->mm, realdatastart, len);
42540 + up_write(&current->mm->mmap_sem);
42541 ret = result;
42542 goto err;
42543 }
42544 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
42545 }
42546 if (IS_ERR_VALUE(result)) {
42547 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
42548 + down_write(&current->mm->mmap_sem);
42549 do_munmap(current->mm, textpos, text_len + data_len + extra +
42550 MAX_SHARED_LIBS * sizeof(unsigned long));
42551 + up_write(&current->mm->mmap_sem);
42552 ret = result;
42553 goto err;
42554 }
42555 diff --git a/fs/bio.c b/fs/bio.c
42556 index 84da885..2149cd9 100644
42557 --- a/fs/bio.c
42558 +++ b/fs/bio.c
42559 @@ -838,7 +838,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
42560 /*
42561 * Overflow, abort
42562 */
42563 - if (end < start)
42564 + if (end < start || end - start > INT_MAX - nr_pages)
42565 return ERR_PTR(-EINVAL);
42566
42567 nr_pages += end - start;
42568 @@ -1234,7 +1234,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
42569 const int read = bio_data_dir(bio) == READ;
42570 struct bio_map_data *bmd = bio->bi_private;
42571 int i;
42572 - char *p = bmd->sgvecs[0].iov_base;
42573 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
42574
42575 __bio_for_each_segment(bvec, bio, i, 0) {
42576 char *addr = page_address(bvec->bv_page);
42577 diff --git a/fs/block_dev.c b/fs/block_dev.c
42578 index ba11c30..623d736 100644
42579 --- a/fs/block_dev.c
42580 +++ b/fs/block_dev.c
42581 @@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
42582 else if (bdev->bd_contains == bdev)
42583 return true; /* is a whole device which isn't held */
42584
42585 - else if (whole->bd_holder == bd_may_claim)
42586 + else if (whole->bd_holder == (void *)bd_may_claim)
42587 return true; /* is a partition of a device that is being partitioned */
42588 else if (whole->bd_holder != NULL)
42589 return false; /* is a partition of a held device */
42590 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
42591 index c053e90..e5f1afc 100644
42592 --- a/fs/btrfs/check-integrity.c
42593 +++ b/fs/btrfs/check-integrity.c
42594 @@ -156,7 +156,7 @@ struct btrfsic_block {
42595 union {
42596 bio_end_io_t *bio;
42597 bh_end_io_t *bh;
42598 - } orig_bio_bh_end_io;
42599 + } __no_const orig_bio_bh_end_io;
42600 int submit_bio_bh_rw;
42601 u64 flush_gen; /* only valid if !never_written */
42602 };
42603 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
42604 index 4106264..8157ede 100644
42605 --- a/fs/btrfs/ctree.c
42606 +++ b/fs/btrfs/ctree.c
42607 @@ -513,9 +513,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
42608 free_extent_buffer(buf);
42609 add_root_to_dirty_list(root);
42610 } else {
42611 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
42612 - parent_start = parent->start;
42613 - else
42614 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
42615 + if (parent)
42616 + parent_start = parent->start;
42617 + else
42618 + parent_start = 0;
42619 + } else
42620 parent_start = 0;
42621
42622 WARN_ON(trans->transid != btrfs_header_generation(parent));
42623 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
42624 index 0df0d1f..4bdcbfe 100644
42625 --- a/fs/btrfs/inode.c
42626 +++ b/fs/btrfs/inode.c
42627 @@ -7074,7 +7074,7 @@ fail:
42628 return -ENOMEM;
42629 }
42630
42631 -static int btrfs_getattr(struct vfsmount *mnt,
42632 +int btrfs_getattr(struct vfsmount *mnt,
42633 struct dentry *dentry, struct kstat *stat)
42634 {
42635 struct inode *inode = dentry->d_inode;
42636 @@ -7088,6 +7088,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
42637 return 0;
42638 }
42639
42640 +EXPORT_SYMBOL(btrfs_getattr);
42641 +
42642 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
42643 +{
42644 + return BTRFS_I(inode)->root->anon_dev;
42645 +}
42646 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
42647 +
42648 /*
42649 * If a file is moved, it will inherit the cow and compression flags of the new
42650 * directory.
42651 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
42652 index 14f8e1f..ab8d81f 100644
42653 --- a/fs/btrfs/ioctl.c
42654 +++ b/fs/btrfs/ioctl.c
42655 @@ -2882,9 +2882,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
42656 for (i = 0; i < num_types; i++) {
42657 struct btrfs_space_info *tmp;
42658
42659 + /* Don't copy in more than we allocated */
42660 if (!slot_count)
42661 break;
42662
42663 + slot_count--;
42664 +
42665 info = NULL;
42666 rcu_read_lock();
42667 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
42668 @@ -2906,15 +2909,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
42669 memcpy(dest, &space, sizeof(space));
42670 dest++;
42671 space_args.total_spaces++;
42672 - slot_count--;
42673 }
42674 - if (!slot_count)
42675 - break;
42676 }
42677 up_read(&info->groups_sem);
42678 }
42679
42680 - user_dest = (struct btrfs_ioctl_space_info *)
42681 + user_dest = (struct btrfs_ioctl_space_info __user *)
42682 (arg + sizeof(struct btrfs_ioctl_space_args));
42683
42684 if (copy_to_user(user_dest, dest_orig, alloc_size))
42685 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
42686 index 646ee21..f020f87 100644
42687 --- a/fs/btrfs/relocation.c
42688 +++ b/fs/btrfs/relocation.c
42689 @@ -1268,7 +1268,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
42690 }
42691 spin_unlock(&rc->reloc_root_tree.lock);
42692
42693 - BUG_ON((struct btrfs_root *)node->data != root);
42694 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
42695
42696 if (!del) {
42697 spin_lock(&rc->reloc_root_tree.lock);
42698 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
42699 index 622f469..e8d2d55 100644
42700 --- a/fs/cachefiles/bind.c
42701 +++ b/fs/cachefiles/bind.c
42702 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
42703 args);
42704
42705 /* start by checking things over */
42706 - ASSERT(cache->fstop_percent >= 0 &&
42707 - cache->fstop_percent < cache->fcull_percent &&
42708 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
42709 cache->fcull_percent < cache->frun_percent &&
42710 cache->frun_percent < 100);
42711
42712 - ASSERT(cache->bstop_percent >= 0 &&
42713 - cache->bstop_percent < cache->bcull_percent &&
42714 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
42715 cache->bcull_percent < cache->brun_percent &&
42716 cache->brun_percent < 100);
42717
42718 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
42719 index 0a1467b..6a53245 100644
42720 --- a/fs/cachefiles/daemon.c
42721 +++ b/fs/cachefiles/daemon.c
42722 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
42723 if (n > buflen)
42724 return -EMSGSIZE;
42725
42726 - if (copy_to_user(_buffer, buffer, n) != 0)
42727 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
42728 return -EFAULT;
42729
42730 return n;
42731 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
42732 if (test_bit(CACHEFILES_DEAD, &cache->flags))
42733 return -EIO;
42734
42735 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
42736 + if (datalen > PAGE_SIZE - 1)
42737 return -EOPNOTSUPP;
42738
42739 /* drag the command string into the kernel so we can parse it */
42740 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
42741 if (args[0] != '%' || args[1] != '\0')
42742 return -EINVAL;
42743
42744 - if (fstop < 0 || fstop >= cache->fcull_percent)
42745 + if (fstop >= cache->fcull_percent)
42746 return cachefiles_daemon_range_error(cache, args);
42747
42748 cache->fstop_percent = fstop;
42749 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
42750 if (args[0] != '%' || args[1] != '\0')
42751 return -EINVAL;
42752
42753 - if (bstop < 0 || bstop >= cache->bcull_percent)
42754 + if (bstop >= cache->bcull_percent)
42755 return cachefiles_daemon_range_error(cache, args);
42756
42757 cache->bstop_percent = bstop;
42758 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
42759 index bd6bc1b..b627b53 100644
42760 --- a/fs/cachefiles/internal.h
42761 +++ b/fs/cachefiles/internal.h
42762 @@ -57,7 +57,7 @@ struct cachefiles_cache {
42763 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
42764 struct rb_root active_nodes; /* active nodes (can't be culled) */
42765 rwlock_t active_lock; /* lock for active_nodes */
42766 - atomic_t gravecounter; /* graveyard uniquifier */
42767 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
42768 unsigned frun_percent; /* when to stop culling (% files) */
42769 unsigned fcull_percent; /* when to start culling (% files) */
42770 unsigned fstop_percent; /* when to stop allocating (% files) */
42771 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
42772 * proc.c
42773 */
42774 #ifdef CONFIG_CACHEFILES_HISTOGRAM
42775 -extern atomic_t cachefiles_lookup_histogram[HZ];
42776 -extern atomic_t cachefiles_mkdir_histogram[HZ];
42777 -extern atomic_t cachefiles_create_histogram[HZ];
42778 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
42779 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
42780 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
42781
42782 extern int __init cachefiles_proc_init(void);
42783 extern void cachefiles_proc_cleanup(void);
42784 static inline
42785 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
42786 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
42787 {
42788 unsigned long jif = jiffies - start_jif;
42789 if (jif >= HZ)
42790 jif = HZ - 1;
42791 - atomic_inc(&histogram[jif]);
42792 + atomic_inc_unchecked(&histogram[jif]);
42793 }
42794
42795 #else
42796 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
42797 index 7f0771d..87d4f36 100644
42798 --- a/fs/cachefiles/namei.c
42799 +++ b/fs/cachefiles/namei.c
42800 @@ -318,7 +318,7 @@ try_again:
42801 /* first step is to make up a grave dentry in the graveyard */
42802 sprintf(nbuffer, "%08x%08x",
42803 (uint32_t) get_seconds(),
42804 - (uint32_t) atomic_inc_return(&cache->gravecounter));
42805 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
42806
42807 /* do the multiway lock magic */
42808 trap = lock_rename(cache->graveyard, dir);
42809 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
42810 index eccd339..4c1d995 100644
42811 --- a/fs/cachefiles/proc.c
42812 +++ b/fs/cachefiles/proc.c
42813 @@ -14,9 +14,9 @@
42814 #include <linux/seq_file.h>
42815 #include "internal.h"
42816
42817 -atomic_t cachefiles_lookup_histogram[HZ];
42818 -atomic_t cachefiles_mkdir_histogram[HZ];
42819 -atomic_t cachefiles_create_histogram[HZ];
42820 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
42821 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
42822 +atomic_unchecked_t cachefiles_create_histogram[HZ];
42823
42824 /*
42825 * display the latency histogram
42826 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
42827 return 0;
42828 default:
42829 index = (unsigned long) v - 3;
42830 - x = atomic_read(&cachefiles_lookup_histogram[index]);
42831 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
42832 - z = atomic_read(&cachefiles_create_histogram[index]);
42833 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
42834 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
42835 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
42836 if (x == 0 && y == 0 && z == 0)
42837 return 0;
42838
42839 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
42840 index 0e3c092..818480e 100644
42841 --- a/fs/cachefiles/rdwr.c
42842 +++ b/fs/cachefiles/rdwr.c
42843 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
42844 old_fs = get_fs();
42845 set_fs(KERNEL_DS);
42846 ret = file->f_op->write(
42847 - file, (const void __user *) data, len, &pos);
42848 + file, (const void __force_user *) data, len, &pos);
42849 set_fs(old_fs);
42850 kunmap(page);
42851 if (ret != len)
42852 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
42853 index 3e8094b..cb3ff3d 100644
42854 --- a/fs/ceph/dir.c
42855 +++ b/fs/ceph/dir.c
42856 @@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
42857 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
42858 struct ceph_mds_client *mdsc = fsc->mdsc;
42859 unsigned frag = fpos_frag(filp->f_pos);
42860 - int off = fpos_off(filp->f_pos);
42861 + unsigned int off = fpos_off(filp->f_pos);
42862 int err;
42863 u32 ftype;
42864 struct ceph_mds_reply_info_parsed *rinfo;
42865 @@ -598,7 +598,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
42866 if (nd &&
42867 (nd->flags & LOOKUP_OPEN) &&
42868 !(nd->intent.open.flags & O_CREAT)) {
42869 - int mode = nd->intent.open.create_mode & ~current->fs->umask;
42870 + int mode = nd->intent.open.create_mode & ~current_umask();
42871 return ceph_lookup_open(dir, dentry, nd, mode, 1);
42872 }
42873
42874 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
42875 index 2704646..c581c91 100644
42876 --- a/fs/cifs/cifs_debug.c
42877 +++ b/fs/cifs/cifs_debug.c
42878 @@ -265,8 +265,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
42879
42880 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
42881 #ifdef CONFIG_CIFS_STATS2
42882 - atomic_set(&totBufAllocCount, 0);
42883 - atomic_set(&totSmBufAllocCount, 0);
42884 + atomic_set_unchecked(&totBufAllocCount, 0);
42885 + atomic_set_unchecked(&totSmBufAllocCount, 0);
42886 #endif /* CONFIG_CIFS_STATS2 */
42887 spin_lock(&cifs_tcp_ses_lock);
42888 list_for_each(tmp1, &cifs_tcp_ses_list) {
42889 @@ -279,25 +279,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
42890 tcon = list_entry(tmp3,
42891 struct cifs_tcon,
42892 tcon_list);
42893 - atomic_set(&tcon->num_smbs_sent, 0);
42894 - atomic_set(&tcon->num_writes, 0);
42895 - atomic_set(&tcon->num_reads, 0);
42896 - atomic_set(&tcon->num_oplock_brks, 0);
42897 - atomic_set(&tcon->num_opens, 0);
42898 - atomic_set(&tcon->num_posixopens, 0);
42899 - atomic_set(&tcon->num_posixmkdirs, 0);
42900 - atomic_set(&tcon->num_closes, 0);
42901 - atomic_set(&tcon->num_deletes, 0);
42902 - atomic_set(&tcon->num_mkdirs, 0);
42903 - atomic_set(&tcon->num_rmdirs, 0);
42904 - atomic_set(&tcon->num_renames, 0);
42905 - atomic_set(&tcon->num_t2renames, 0);
42906 - atomic_set(&tcon->num_ffirst, 0);
42907 - atomic_set(&tcon->num_fnext, 0);
42908 - atomic_set(&tcon->num_fclose, 0);
42909 - atomic_set(&tcon->num_hardlinks, 0);
42910 - atomic_set(&tcon->num_symlinks, 0);
42911 - atomic_set(&tcon->num_locks, 0);
42912 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
42913 + atomic_set_unchecked(&tcon->num_writes, 0);
42914 + atomic_set_unchecked(&tcon->num_reads, 0);
42915 + atomic_set_unchecked(&tcon->num_oplock_brks, 0);
42916 + atomic_set_unchecked(&tcon->num_opens, 0);
42917 + atomic_set_unchecked(&tcon->num_posixopens, 0);
42918 + atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
42919 + atomic_set_unchecked(&tcon->num_closes, 0);
42920 + atomic_set_unchecked(&tcon->num_deletes, 0);
42921 + atomic_set_unchecked(&tcon->num_mkdirs, 0);
42922 + atomic_set_unchecked(&tcon->num_rmdirs, 0);
42923 + atomic_set_unchecked(&tcon->num_renames, 0);
42924 + atomic_set_unchecked(&tcon->num_t2renames, 0);
42925 + atomic_set_unchecked(&tcon->num_ffirst, 0);
42926 + atomic_set_unchecked(&tcon->num_fnext, 0);
42927 + atomic_set_unchecked(&tcon->num_fclose, 0);
42928 + atomic_set_unchecked(&tcon->num_hardlinks, 0);
42929 + atomic_set_unchecked(&tcon->num_symlinks, 0);
42930 + atomic_set_unchecked(&tcon->num_locks, 0);
42931 }
42932 }
42933 }
42934 @@ -327,8 +327,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
42935 smBufAllocCount.counter, cifs_min_small);
42936 #ifdef CONFIG_CIFS_STATS2
42937 seq_printf(m, "Total Large %d Small %d Allocations\n",
42938 - atomic_read(&totBufAllocCount),
42939 - atomic_read(&totSmBufAllocCount));
42940 + atomic_read_unchecked(&totBufAllocCount),
42941 + atomic_read_unchecked(&totSmBufAllocCount));
42942 #endif /* CONFIG_CIFS_STATS2 */
42943
42944 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
42945 @@ -357,41 +357,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
42946 if (tcon->need_reconnect)
42947 seq_puts(m, "\tDISCONNECTED ");
42948 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
42949 - atomic_read(&tcon->num_smbs_sent),
42950 - atomic_read(&tcon->num_oplock_brks));
42951 + atomic_read_unchecked(&tcon->num_smbs_sent),
42952 + atomic_read_unchecked(&tcon->num_oplock_brks));
42953 seq_printf(m, "\nReads: %d Bytes: %lld",
42954 - atomic_read(&tcon->num_reads),
42955 + atomic_read_unchecked(&tcon->num_reads),
42956 (long long)(tcon->bytes_read));
42957 seq_printf(m, "\nWrites: %d Bytes: %lld",
42958 - atomic_read(&tcon->num_writes),
42959 + atomic_read_unchecked(&tcon->num_writes),
42960 (long long)(tcon->bytes_written));
42961 seq_printf(m, "\nFlushes: %d",
42962 - atomic_read(&tcon->num_flushes));
42963 + atomic_read_unchecked(&tcon->num_flushes));
42964 seq_printf(m, "\nLocks: %d HardLinks: %d "
42965 "Symlinks: %d",
42966 - atomic_read(&tcon->num_locks),
42967 - atomic_read(&tcon->num_hardlinks),
42968 - atomic_read(&tcon->num_symlinks));
42969 + atomic_read_unchecked(&tcon->num_locks),
42970 + atomic_read_unchecked(&tcon->num_hardlinks),
42971 + atomic_read_unchecked(&tcon->num_symlinks));
42972 seq_printf(m, "\nOpens: %d Closes: %d "
42973 "Deletes: %d",
42974 - atomic_read(&tcon->num_opens),
42975 - atomic_read(&tcon->num_closes),
42976 - atomic_read(&tcon->num_deletes));
42977 + atomic_read_unchecked(&tcon->num_opens),
42978 + atomic_read_unchecked(&tcon->num_closes),
42979 + atomic_read_unchecked(&tcon->num_deletes));
42980 seq_printf(m, "\nPosix Opens: %d "
42981 "Posix Mkdirs: %d",
42982 - atomic_read(&tcon->num_posixopens),
42983 - atomic_read(&tcon->num_posixmkdirs));
42984 + atomic_read_unchecked(&tcon->num_posixopens),
42985 + atomic_read_unchecked(&tcon->num_posixmkdirs));
42986 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
42987 - atomic_read(&tcon->num_mkdirs),
42988 - atomic_read(&tcon->num_rmdirs));
42989 + atomic_read_unchecked(&tcon->num_mkdirs),
42990 + atomic_read_unchecked(&tcon->num_rmdirs));
42991 seq_printf(m, "\nRenames: %d T2 Renames %d",
42992 - atomic_read(&tcon->num_renames),
42993 - atomic_read(&tcon->num_t2renames));
42994 + atomic_read_unchecked(&tcon->num_renames),
42995 + atomic_read_unchecked(&tcon->num_t2renames));
42996 seq_printf(m, "\nFindFirst: %d FNext %d "
42997 "FClose %d",
42998 - atomic_read(&tcon->num_ffirst),
42999 - atomic_read(&tcon->num_fnext),
43000 - atomic_read(&tcon->num_fclose));
43001 + atomic_read_unchecked(&tcon->num_ffirst),
43002 + atomic_read_unchecked(&tcon->num_fnext),
43003 + atomic_read_unchecked(&tcon->num_fclose));
43004 }
43005 }
43006 }
43007 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
43008 index 541ef81..a78deb8 100644
43009 --- a/fs/cifs/cifsfs.c
43010 +++ b/fs/cifs/cifsfs.c
43011 @@ -985,7 +985,7 @@ cifs_init_request_bufs(void)
43012 cifs_req_cachep = kmem_cache_create("cifs_request",
43013 CIFSMaxBufSize +
43014 MAX_CIFS_HDR_SIZE, 0,
43015 - SLAB_HWCACHE_ALIGN, NULL);
43016 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
43017 if (cifs_req_cachep == NULL)
43018 return -ENOMEM;
43019
43020 @@ -1012,7 +1012,7 @@ cifs_init_request_bufs(void)
43021 efficient to alloc 1 per page off the slab compared to 17K (5page)
43022 alloc of large cifs buffers even when page debugging is on */
43023 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
43024 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
43025 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
43026 NULL);
43027 if (cifs_sm_req_cachep == NULL) {
43028 mempool_destroy(cifs_req_poolp);
43029 @@ -1097,8 +1097,8 @@ init_cifs(void)
43030 atomic_set(&bufAllocCount, 0);
43031 atomic_set(&smBufAllocCount, 0);
43032 #ifdef CONFIG_CIFS_STATS2
43033 - atomic_set(&totBufAllocCount, 0);
43034 - atomic_set(&totSmBufAllocCount, 0);
43035 + atomic_set_unchecked(&totBufAllocCount, 0);
43036 + atomic_set_unchecked(&totSmBufAllocCount, 0);
43037 #endif /* CONFIG_CIFS_STATS2 */
43038
43039 atomic_set(&midCount, 0);
43040 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
43041 index 73fea28..b996b84 100644
43042 --- a/fs/cifs/cifsglob.h
43043 +++ b/fs/cifs/cifsglob.h
43044 @@ -439,28 +439,28 @@ struct cifs_tcon {
43045 __u16 Flags; /* optional support bits */
43046 enum statusEnum tidStatus;
43047 #ifdef CONFIG_CIFS_STATS
43048 - atomic_t num_smbs_sent;
43049 - atomic_t num_writes;
43050 - atomic_t num_reads;
43051 - atomic_t num_flushes;
43052 - atomic_t num_oplock_brks;
43053 - atomic_t num_opens;
43054 - atomic_t num_closes;
43055 - atomic_t num_deletes;
43056 - atomic_t num_mkdirs;
43057 - atomic_t num_posixopens;
43058 - atomic_t num_posixmkdirs;
43059 - atomic_t num_rmdirs;
43060 - atomic_t num_renames;
43061 - atomic_t num_t2renames;
43062 - atomic_t num_ffirst;
43063 - atomic_t num_fnext;
43064 - atomic_t num_fclose;
43065 - atomic_t num_hardlinks;
43066 - atomic_t num_symlinks;
43067 - atomic_t num_locks;
43068 - atomic_t num_acl_get;
43069 - atomic_t num_acl_set;
43070 + atomic_unchecked_t num_smbs_sent;
43071 + atomic_unchecked_t num_writes;
43072 + atomic_unchecked_t num_reads;
43073 + atomic_unchecked_t num_flushes;
43074 + atomic_unchecked_t num_oplock_brks;
43075 + atomic_unchecked_t num_opens;
43076 + atomic_unchecked_t num_closes;
43077 + atomic_unchecked_t num_deletes;
43078 + atomic_unchecked_t num_mkdirs;
43079 + atomic_unchecked_t num_posixopens;
43080 + atomic_unchecked_t num_posixmkdirs;
43081 + atomic_unchecked_t num_rmdirs;
43082 + atomic_unchecked_t num_renames;
43083 + atomic_unchecked_t num_t2renames;
43084 + atomic_unchecked_t num_ffirst;
43085 + atomic_unchecked_t num_fnext;
43086 + atomic_unchecked_t num_fclose;
43087 + atomic_unchecked_t num_hardlinks;
43088 + atomic_unchecked_t num_symlinks;
43089 + atomic_unchecked_t num_locks;
43090 + atomic_unchecked_t num_acl_get;
43091 + atomic_unchecked_t num_acl_set;
43092 #ifdef CONFIG_CIFS_STATS2
43093 unsigned long long time_writes;
43094 unsigned long long time_reads;
43095 @@ -677,7 +677,7 @@ convert_delimiter(char *path, char delim)
43096 }
43097
43098 #ifdef CONFIG_CIFS_STATS
43099 -#define cifs_stats_inc atomic_inc
43100 +#define cifs_stats_inc atomic_inc_unchecked
43101
43102 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
43103 unsigned int bytes)
43104 @@ -1036,8 +1036,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
43105 /* Various Debug counters */
43106 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
43107 #ifdef CONFIG_CIFS_STATS2
43108 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
43109 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
43110 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
43111 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
43112 #endif
43113 GLOBAL_EXTERN atomic_t smBufAllocCount;
43114 GLOBAL_EXTERN atomic_t midCount;
43115 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
43116 index 6b0e064..94e6c3c 100644
43117 --- a/fs/cifs/link.c
43118 +++ b/fs/cifs/link.c
43119 @@ -600,7 +600,7 @@ symlink_exit:
43120
43121 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
43122 {
43123 - char *p = nd_get_link(nd);
43124 + const char *p = nd_get_link(nd);
43125 if (!IS_ERR(p))
43126 kfree(p);
43127 }
43128 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
43129 index c29d1aa..58018da 100644
43130 --- a/fs/cifs/misc.c
43131 +++ b/fs/cifs/misc.c
43132 @@ -156,7 +156,7 @@ cifs_buf_get(void)
43133 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
43134 atomic_inc(&bufAllocCount);
43135 #ifdef CONFIG_CIFS_STATS2
43136 - atomic_inc(&totBufAllocCount);
43137 + atomic_inc_unchecked(&totBufAllocCount);
43138 #endif /* CONFIG_CIFS_STATS2 */
43139 }
43140
43141 @@ -191,7 +191,7 @@ cifs_small_buf_get(void)
43142 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
43143 atomic_inc(&smBufAllocCount);
43144 #ifdef CONFIG_CIFS_STATS2
43145 - atomic_inc(&totSmBufAllocCount);
43146 + atomic_inc_unchecked(&totSmBufAllocCount);
43147 #endif /* CONFIG_CIFS_STATS2 */
43148
43149 }
43150 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
43151 index 6901578..d402eb5 100644
43152 --- a/fs/coda/cache.c
43153 +++ b/fs/coda/cache.c
43154 @@ -24,7 +24,7 @@
43155 #include "coda_linux.h"
43156 #include "coda_cache.h"
43157
43158 -static atomic_t permission_epoch = ATOMIC_INIT(0);
43159 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
43160
43161 /* replace or extend an acl cache hit */
43162 void coda_cache_enter(struct inode *inode, int mask)
43163 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
43164 struct coda_inode_info *cii = ITOC(inode);
43165
43166 spin_lock(&cii->c_lock);
43167 - cii->c_cached_epoch = atomic_read(&permission_epoch);
43168 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
43169 if (cii->c_uid != current_fsuid()) {
43170 cii->c_uid = current_fsuid();
43171 cii->c_cached_perm = mask;
43172 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
43173 {
43174 struct coda_inode_info *cii = ITOC(inode);
43175 spin_lock(&cii->c_lock);
43176 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
43177 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
43178 spin_unlock(&cii->c_lock);
43179 }
43180
43181 /* remove all acl caches */
43182 void coda_cache_clear_all(struct super_block *sb)
43183 {
43184 - atomic_inc(&permission_epoch);
43185 + atomic_inc_unchecked(&permission_epoch);
43186 }
43187
43188
43189 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
43190 spin_lock(&cii->c_lock);
43191 hit = (mask & cii->c_cached_perm) == mask &&
43192 cii->c_uid == current_fsuid() &&
43193 - cii->c_cached_epoch == atomic_read(&permission_epoch);
43194 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
43195 spin_unlock(&cii->c_lock);
43196
43197 return hit;
43198 diff --git a/fs/compat.c b/fs/compat.c
43199 index f2944ac..62845d2 100644
43200 --- a/fs/compat.c
43201 +++ b/fs/compat.c
43202 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
43203
43204 set_fs(KERNEL_DS);
43205 /* The __user pointer cast is valid because of the set_fs() */
43206 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
43207 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
43208 set_fs(oldfs);
43209 /* truncating is ok because it's a user address */
43210 if (!ret)
43211 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
43212 goto out;
43213
43214 ret = -EINVAL;
43215 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
43216 + if (nr_segs > UIO_MAXIOV)
43217 goto out;
43218 if (nr_segs > fast_segs) {
43219 ret = -ENOMEM;
43220 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
43221
43222 struct compat_readdir_callback {
43223 struct compat_old_linux_dirent __user *dirent;
43224 + struct file * file;
43225 int result;
43226 };
43227
43228 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
43229 buf->result = -EOVERFLOW;
43230 return -EOVERFLOW;
43231 }
43232 +
43233 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43234 + return 0;
43235 +
43236 buf->result++;
43237 dirent = buf->dirent;
43238 if (!access_ok(VERIFY_WRITE, dirent,
43239 @@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
43240
43241 buf.result = 0;
43242 buf.dirent = dirent;
43243 + buf.file = file;
43244
43245 error = vfs_readdir(file, compat_fillonedir, &buf);
43246 if (buf.result)
43247 @@ -900,6 +906,7 @@ struct compat_linux_dirent {
43248 struct compat_getdents_callback {
43249 struct compat_linux_dirent __user *current_dir;
43250 struct compat_linux_dirent __user *previous;
43251 + struct file * file;
43252 int count;
43253 int error;
43254 };
43255 @@ -921,6 +928,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
43256 buf->error = -EOVERFLOW;
43257 return -EOVERFLOW;
43258 }
43259 +
43260 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43261 + return 0;
43262 +
43263 dirent = buf->previous;
43264 if (dirent) {
43265 if (__put_user(offset, &dirent->d_off))
43266 @@ -968,6 +979,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
43267 buf.previous = NULL;
43268 buf.count = count;
43269 buf.error = 0;
43270 + buf.file = file;
43271
43272 error = vfs_readdir(file, compat_filldir, &buf);
43273 if (error >= 0)
43274 @@ -989,6 +1001,7 @@ out:
43275 struct compat_getdents_callback64 {
43276 struct linux_dirent64 __user *current_dir;
43277 struct linux_dirent64 __user *previous;
43278 + struct file * file;
43279 int count;
43280 int error;
43281 };
43282 @@ -1005,6 +1018,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
43283 buf->error = -EINVAL; /* only used if we fail.. */
43284 if (reclen > buf->count)
43285 return -EINVAL;
43286 +
43287 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43288 + return 0;
43289 +
43290 dirent = buf->previous;
43291
43292 if (dirent) {
43293 @@ -1056,13 +1073,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
43294 buf.previous = NULL;
43295 buf.count = count;
43296 buf.error = 0;
43297 + buf.file = file;
43298
43299 error = vfs_readdir(file, compat_filldir64, &buf);
43300 if (error >= 0)
43301 error = buf.error;
43302 lastdirent = buf.previous;
43303 if (lastdirent) {
43304 - typeof(lastdirent->d_off) d_off = file->f_pos;
43305 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
43306 if (__put_user_unaligned(d_off, &lastdirent->d_off))
43307 error = -EFAULT;
43308 else
43309 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
43310 index 112e45a..b59845b 100644
43311 --- a/fs/compat_binfmt_elf.c
43312 +++ b/fs/compat_binfmt_elf.c
43313 @@ -30,11 +30,13 @@
43314 #undef elf_phdr
43315 #undef elf_shdr
43316 #undef elf_note
43317 +#undef elf_dyn
43318 #undef elf_addr_t
43319 #define elfhdr elf32_hdr
43320 #define elf_phdr elf32_phdr
43321 #define elf_shdr elf32_shdr
43322 #define elf_note elf32_note
43323 +#define elf_dyn Elf32_Dyn
43324 #define elf_addr_t Elf32_Addr
43325
43326 /*
43327 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
43328 index debdfe0..75d31d4 100644
43329 --- a/fs/compat_ioctl.c
43330 +++ b/fs/compat_ioctl.c
43331 @@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
43332
43333 err = get_user(palp, &up->palette);
43334 err |= get_user(length, &up->length);
43335 + if (err)
43336 + return -EFAULT;
43337
43338 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
43339 err = put_user(compat_ptr(palp), &up_native->palette);
43340 @@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
43341 return -EFAULT;
43342 if (__get_user(udata, &ss32->iomem_base))
43343 return -EFAULT;
43344 - ss.iomem_base = compat_ptr(udata);
43345 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
43346 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
43347 __get_user(ss.port_high, &ss32->port_high))
43348 return -EFAULT;
43349 @@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
43350 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
43351 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
43352 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
43353 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43354 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43355 return -EFAULT;
43356
43357 return ioctl_preallocate(file, p);
43358 @@ -1610,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
43359 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
43360 {
43361 unsigned int a, b;
43362 - a = *(unsigned int *)p;
43363 - b = *(unsigned int *)q;
43364 + a = *(const unsigned int *)p;
43365 + b = *(const unsigned int *)q;
43366 if (a > b)
43367 return 1;
43368 if (a < b)
43369 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
43370 index 7e6c52d..94bc756 100644
43371 --- a/fs/configfs/dir.c
43372 +++ b/fs/configfs/dir.c
43373 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43374 }
43375 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
43376 struct configfs_dirent *next;
43377 - const char * name;
43378 + const unsigned char * name;
43379 + char d_name[sizeof(next->s_dentry->d_iname)];
43380 int len;
43381 struct inode *inode = NULL;
43382
43383 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43384 continue;
43385
43386 name = configfs_get_name(next);
43387 - len = strlen(name);
43388 + if (next->s_dentry && name == next->s_dentry->d_iname) {
43389 + len = next->s_dentry->d_name.len;
43390 + memcpy(d_name, name, len);
43391 + name = d_name;
43392 + } else
43393 + len = strlen(name);
43394
43395 /*
43396 * We'll have a dentry and an inode for
43397 diff --git a/fs/dcache.c b/fs/dcache.c
43398 index b80531c..8ca7e2d 100644
43399 --- a/fs/dcache.c
43400 +++ b/fs/dcache.c
43401 @@ -3084,7 +3084,7 @@ void __init vfs_caches_init(unsigned long mempages)
43402 mempages -= reserve;
43403
43404 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
43405 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
43406 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
43407
43408 dcache_init();
43409 inode_init();
43410 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
43411 index b80bc84..0d46d1a 100644
43412 --- a/fs/debugfs/inode.c
43413 +++ b/fs/debugfs/inode.c
43414 @@ -408,7 +408,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
43415 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
43416 {
43417 return debugfs_create_file(name,
43418 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
43419 + S_IFDIR | S_IRWXU,
43420 +#else
43421 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
43422 +#endif
43423 parent, NULL, NULL);
43424 }
43425 EXPORT_SYMBOL_GPL(debugfs_create_dir);
43426 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
43427 index ab35b11..b30af66 100644
43428 --- a/fs/ecryptfs/inode.c
43429 +++ b/fs/ecryptfs/inode.c
43430 @@ -672,7 +672,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
43431 old_fs = get_fs();
43432 set_fs(get_ds());
43433 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
43434 - (char __user *)lower_buf,
43435 + (char __force_user *)lower_buf,
43436 lower_bufsiz);
43437 set_fs(old_fs);
43438 if (rc < 0)
43439 @@ -718,7 +718,7 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
43440 }
43441 old_fs = get_fs();
43442 set_fs(get_ds());
43443 - rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
43444 + rc = dentry->d_inode->i_op->readlink(dentry, (char __force_user *)buf, len);
43445 set_fs(old_fs);
43446 if (rc < 0) {
43447 kfree(buf);
43448 @@ -733,7 +733,7 @@ out:
43449 static void
43450 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
43451 {
43452 - char *buf = nd_get_link(nd);
43453 + const char *buf = nd_get_link(nd);
43454 if (!IS_ERR(buf)) {
43455 /* Free the char* */
43456 kfree(buf);
43457 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
43458 index 3a06f40..f7af544 100644
43459 --- a/fs/ecryptfs/miscdev.c
43460 +++ b/fs/ecryptfs/miscdev.c
43461 @@ -345,7 +345,7 @@ check_list:
43462 goto out_unlock_msg_ctx;
43463 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
43464 if (msg_ctx->msg) {
43465 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
43466 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
43467 goto out_unlock_msg_ctx;
43468 i += packet_length_size;
43469 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
43470 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
43471 index b2a34a1..162fa69 100644
43472 --- a/fs/ecryptfs/read_write.c
43473 +++ b/fs/ecryptfs/read_write.c
43474 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
43475 return -EIO;
43476 fs_save = get_fs();
43477 set_fs(get_ds());
43478 - rc = vfs_write(lower_file, data, size, &offset);
43479 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
43480 set_fs(fs_save);
43481 mark_inode_dirty_sync(ecryptfs_inode);
43482 return rc;
43483 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
43484 return -EIO;
43485 fs_save = get_fs();
43486 set_fs(get_ds());
43487 - rc = vfs_read(lower_file, data, size, &offset);
43488 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
43489 set_fs(fs_save);
43490 return rc;
43491 }
43492 diff --git a/fs/exec.c b/fs/exec.c
43493 index b1fd202..582240d 100644
43494 --- a/fs/exec.c
43495 +++ b/fs/exec.c
43496 @@ -55,6 +55,15 @@
43497 #include <linux/pipe_fs_i.h>
43498 #include <linux/oom.h>
43499 #include <linux/compat.h>
43500 +#include <linux/random.h>
43501 +#include <linux/seq_file.h>
43502 +
43503 +#ifdef CONFIG_PAX_REFCOUNT
43504 +#include <linux/kallsyms.h>
43505 +#include <linux/kdebug.h>
43506 +#endif
43507 +
43508 +#include <trace/events/fs.h>
43509
43510 #include <asm/uaccess.h>
43511 #include <asm/mmu_context.h>
43512 @@ -66,6 +75,18 @@
43513
43514 #include <trace/events/sched.h>
43515
43516 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43517 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
43518 +{
43519 + 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");
43520 +}
43521 +#endif
43522 +
43523 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
43524 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
43525 +EXPORT_SYMBOL(pax_set_initial_flags_func);
43526 +#endif
43527 +
43528 int core_uses_pid;
43529 char core_pattern[CORENAME_MAX_SIZE] = "core";
43530 unsigned int core_pipe_limit;
43531 @@ -75,7 +96,7 @@ struct core_name {
43532 char *corename;
43533 int used, size;
43534 };
43535 -static atomic_t call_count = ATOMIC_INIT(1);
43536 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
43537
43538 /* The maximal length of core_pattern is also specified in sysctl.c */
43539
43540 @@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
43541 int write)
43542 {
43543 struct page *page;
43544 - int ret;
43545
43546 -#ifdef CONFIG_STACK_GROWSUP
43547 - if (write) {
43548 - ret = expand_downwards(bprm->vma, pos);
43549 - if (ret < 0)
43550 - return NULL;
43551 - }
43552 -#endif
43553 - ret = get_user_pages(current, bprm->mm, pos,
43554 - 1, write, 1, &page, NULL);
43555 - if (ret <= 0)
43556 + if (0 > expand_downwards(bprm->vma, pos))
43557 + return NULL;
43558 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
43559 return NULL;
43560
43561 if (write) {
43562 @@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
43563 if (size <= ARG_MAX)
43564 return page;
43565
43566 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43567 + // only allow 512KB for argv+env on suid/sgid binaries
43568 + // to prevent easy ASLR exhaustion
43569 + if (((bprm->cred->euid != current_euid()) ||
43570 + (bprm->cred->egid != current_egid())) &&
43571 + (size > (512 * 1024))) {
43572 + put_page(page);
43573 + return NULL;
43574 + }
43575 +#endif
43576 +
43577 /*
43578 * Limit to 1/4-th the stack size for the argv+env strings.
43579 * This ensures that:
43580 @@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
43581 vma->vm_end = STACK_TOP_MAX;
43582 vma->vm_start = vma->vm_end - PAGE_SIZE;
43583 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
43584 +
43585 +#ifdef CONFIG_PAX_SEGMEXEC
43586 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
43587 +#endif
43588 +
43589 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
43590 INIT_LIST_HEAD(&vma->anon_vma_chain);
43591
43592 @@ -291,6 +320,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
43593 mm->stack_vm = mm->total_vm = 1;
43594 up_write(&mm->mmap_sem);
43595 bprm->p = vma->vm_end - sizeof(void *);
43596 +
43597 +#ifdef CONFIG_PAX_RANDUSTACK
43598 + if (randomize_va_space)
43599 + bprm->p ^= random32() & ~PAGE_MASK;
43600 +#endif
43601 +
43602 return 0;
43603 err:
43604 up_write(&mm->mmap_sem);
43605 @@ -399,19 +434,7 @@ err:
43606 return err;
43607 }
43608
43609 -struct user_arg_ptr {
43610 -#ifdef CONFIG_COMPAT
43611 - bool is_compat;
43612 -#endif
43613 - union {
43614 - const char __user *const __user *native;
43615 -#ifdef CONFIG_COMPAT
43616 - compat_uptr_t __user *compat;
43617 -#endif
43618 - } ptr;
43619 -};
43620 -
43621 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
43622 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
43623 {
43624 const char __user *native;
43625
43626 @@ -420,14 +443,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
43627 compat_uptr_t compat;
43628
43629 if (get_user(compat, argv.ptr.compat + nr))
43630 - return ERR_PTR(-EFAULT);
43631 + return (const char __force_user *)ERR_PTR(-EFAULT);
43632
43633 return compat_ptr(compat);
43634 }
43635 #endif
43636
43637 if (get_user(native, argv.ptr.native + nr))
43638 - return ERR_PTR(-EFAULT);
43639 + return (const char __force_user *)ERR_PTR(-EFAULT);
43640
43641 return native;
43642 }
43643 @@ -446,7 +469,7 @@ static int count(struct user_arg_ptr argv, int max)
43644 if (!p)
43645 break;
43646
43647 - if (IS_ERR(p))
43648 + if (IS_ERR((const char __force_kernel *)p))
43649 return -EFAULT;
43650
43651 if (i++ >= max)
43652 @@ -480,7 +503,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
43653
43654 ret = -EFAULT;
43655 str = get_user_arg_ptr(argv, argc);
43656 - if (IS_ERR(str))
43657 + if (IS_ERR((const char __force_kernel *)str))
43658 goto out;
43659
43660 len = strnlen_user(str, MAX_ARG_STRLEN);
43661 @@ -562,7 +585,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
43662 int r;
43663 mm_segment_t oldfs = get_fs();
43664 struct user_arg_ptr argv = {
43665 - .ptr.native = (const char __user *const __user *)__argv,
43666 + .ptr.native = (const char __force_user *const __force_user *)__argv,
43667 };
43668
43669 set_fs(KERNEL_DS);
43670 @@ -597,7 +620,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
43671 unsigned long new_end = old_end - shift;
43672 struct mmu_gather tlb;
43673
43674 - BUG_ON(new_start > new_end);
43675 + if (new_start >= new_end || new_start < mmap_min_addr)
43676 + return -ENOMEM;
43677
43678 /*
43679 * ensure there are no vmas between where we want to go
43680 @@ -606,6 +630,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
43681 if (vma != find_vma(mm, new_start))
43682 return -EFAULT;
43683
43684 +#ifdef CONFIG_PAX_SEGMEXEC
43685 + BUG_ON(pax_find_mirror_vma(vma));
43686 +#endif
43687 +
43688 /*
43689 * cover the whole range: [new_start, old_end)
43690 */
43691 @@ -686,10 +714,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
43692 stack_top = arch_align_stack(stack_top);
43693 stack_top = PAGE_ALIGN(stack_top);
43694
43695 - if (unlikely(stack_top < mmap_min_addr) ||
43696 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
43697 - return -ENOMEM;
43698 -
43699 stack_shift = vma->vm_end - stack_top;
43700
43701 bprm->p -= stack_shift;
43702 @@ -701,8 +725,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
43703 bprm->exec -= stack_shift;
43704
43705 down_write(&mm->mmap_sem);
43706 +
43707 + /* Move stack pages down in memory. */
43708 + if (stack_shift) {
43709 + ret = shift_arg_pages(vma, stack_shift);
43710 + if (ret)
43711 + goto out_unlock;
43712 + }
43713 +
43714 vm_flags = VM_STACK_FLAGS;
43715
43716 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43717 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43718 + vm_flags &= ~VM_EXEC;
43719 +
43720 +#ifdef CONFIG_PAX_MPROTECT
43721 + if (mm->pax_flags & MF_PAX_MPROTECT)
43722 + vm_flags &= ~VM_MAYEXEC;
43723 +#endif
43724 +
43725 + }
43726 +#endif
43727 +
43728 /*
43729 * Adjust stack execute permissions; explicitly enable for
43730 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
43731 @@ -721,13 +765,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
43732 goto out_unlock;
43733 BUG_ON(prev != vma);
43734
43735 - /* Move stack pages down in memory. */
43736 - if (stack_shift) {
43737 - ret = shift_arg_pages(vma, stack_shift);
43738 - if (ret)
43739 - goto out_unlock;
43740 - }
43741 -
43742 /* mprotect_fixup is overkill to remove the temporary stack flags */
43743 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
43744
43745 @@ -785,6 +822,8 @@ struct file *open_exec(const char *name)
43746
43747 fsnotify_open(file);
43748
43749 + trace_open_exec(name);
43750 +
43751 err = deny_write_access(file);
43752 if (err)
43753 goto exit;
43754 @@ -808,7 +847,7 @@ int kernel_read(struct file *file, loff_t offset,
43755 old_fs = get_fs();
43756 set_fs(get_ds());
43757 /* The cast to a user pointer is valid due to the set_fs() */
43758 - result = vfs_read(file, (void __user *)addr, count, &pos);
43759 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
43760 set_fs(old_fs);
43761 return result;
43762 }
43763 @@ -1254,7 +1293,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
43764 }
43765 rcu_read_unlock();
43766
43767 - if (p->fs->users > n_fs) {
43768 + if (atomic_read(&p->fs->users) > n_fs) {
43769 bprm->unsafe |= LSM_UNSAFE_SHARE;
43770 } else {
43771 res = -EAGAIN;
43772 @@ -1451,6 +1490,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
43773
43774 EXPORT_SYMBOL(search_binary_handler);
43775
43776 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43777 +static DEFINE_PER_CPU(u64, exec_counter);
43778 +static int __init init_exec_counters(void)
43779 +{
43780 + unsigned int cpu;
43781 +
43782 + for_each_possible_cpu(cpu) {
43783 + per_cpu(exec_counter, cpu) = (u64)cpu;
43784 + }
43785 +
43786 + return 0;
43787 +}
43788 +early_initcall(init_exec_counters);
43789 +static inline void increment_exec_counter(void)
43790 +{
43791 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
43792 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
43793 +}
43794 +#else
43795 +static inline void increment_exec_counter(void) {}
43796 +#endif
43797 +
43798 /*
43799 * sys_execve() executes a new program.
43800 */
43801 @@ -1459,6 +1520,11 @@ static int do_execve_common(const char *filename,
43802 struct user_arg_ptr envp,
43803 struct pt_regs *regs)
43804 {
43805 +#ifdef CONFIG_GRKERNSEC
43806 + struct file *old_exec_file;
43807 + struct acl_subject_label *old_acl;
43808 + struct rlimit old_rlim[RLIM_NLIMITS];
43809 +#endif
43810 struct linux_binprm *bprm;
43811 struct file *file;
43812 struct files_struct *displaced;
43813 @@ -1466,6 +1532,8 @@ static int do_execve_common(const char *filename,
43814 int retval;
43815 const struct cred *cred = current_cred();
43816
43817 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
43818 +
43819 /*
43820 * We move the actual failure in case of RLIMIT_NPROC excess from
43821 * set*uid() to execve() because too many poorly written programs
43822 @@ -1506,12 +1574,27 @@ static int do_execve_common(const char *filename,
43823 if (IS_ERR(file))
43824 goto out_unmark;
43825
43826 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
43827 + retval = -EPERM;
43828 + goto out_file;
43829 + }
43830 +
43831 sched_exec();
43832
43833 bprm->file = file;
43834 bprm->filename = filename;
43835 bprm->interp = filename;
43836
43837 + if (gr_process_user_ban()) {
43838 + retval = -EPERM;
43839 + goto out_file;
43840 + }
43841 +
43842 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
43843 + retval = -EACCES;
43844 + goto out_file;
43845 + }
43846 +
43847 retval = bprm_mm_init(bprm);
43848 if (retval)
43849 goto out_file;
43850 @@ -1528,24 +1611,65 @@ static int do_execve_common(const char *filename,
43851 if (retval < 0)
43852 goto out;
43853
43854 +#ifdef CONFIG_GRKERNSEC
43855 + old_acl = current->acl;
43856 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
43857 + old_exec_file = current->exec_file;
43858 + get_file(file);
43859 + current->exec_file = file;
43860 +#endif
43861 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43862 + /* limit suid stack to 8MB
43863 + we saved the old limits above and will restore them if this exec fails
43864 + */
43865 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
43866 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
43867 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
43868 +#endif
43869 +
43870 + if (!gr_tpe_allow(file)) {
43871 + retval = -EACCES;
43872 + goto out_fail;
43873 + }
43874 +
43875 + if (gr_check_crash_exec(file)) {
43876 + retval = -EACCES;
43877 + goto out_fail;
43878 + }
43879 +
43880 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
43881 + bprm->unsafe);
43882 + if (retval < 0)
43883 + goto out_fail;
43884 +
43885 retval = copy_strings_kernel(1, &bprm->filename, bprm);
43886 if (retval < 0)
43887 - goto out;
43888 + goto out_fail;
43889
43890 bprm->exec = bprm->p;
43891 retval = copy_strings(bprm->envc, envp, bprm);
43892 if (retval < 0)
43893 - goto out;
43894 + goto out_fail;
43895
43896 retval = copy_strings(bprm->argc, argv, bprm);
43897 if (retval < 0)
43898 - goto out;
43899 + goto out_fail;
43900 +
43901 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
43902 +
43903 + gr_handle_exec_args(bprm, argv);
43904
43905 retval = search_binary_handler(bprm,regs);
43906 if (retval < 0)
43907 - goto out;
43908 + goto out_fail;
43909 +#ifdef CONFIG_GRKERNSEC
43910 + if (old_exec_file)
43911 + fput(old_exec_file);
43912 +#endif
43913
43914 /* execve succeeded */
43915 +
43916 + increment_exec_counter();
43917 current->fs->in_exec = 0;
43918 current->in_execve = 0;
43919 acct_update_integrals(current);
43920 @@ -1554,6 +1678,14 @@ static int do_execve_common(const char *filename,
43921 put_files_struct(displaced);
43922 return retval;
43923
43924 +out_fail:
43925 +#ifdef CONFIG_GRKERNSEC
43926 + current->acl = old_acl;
43927 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
43928 + fput(current->exec_file);
43929 + current->exec_file = old_exec_file;
43930 +#endif
43931 +
43932 out:
43933 if (bprm->mm) {
43934 acct_arg_size(bprm, 0);
43935 @@ -1627,7 +1759,7 @@ static int expand_corename(struct core_name *cn)
43936 {
43937 char *old_corename = cn->corename;
43938
43939 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
43940 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
43941 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
43942
43943 if (!cn->corename) {
43944 @@ -1724,7 +1856,7 @@ static int format_corename(struct core_name *cn, long signr)
43945 int pid_in_pattern = 0;
43946 int err = 0;
43947
43948 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
43949 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
43950 cn->corename = kmalloc(cn->size, GFP_KERNEL);
43951 cn->used = 0;
43952
43953 @@ -1821,6 +1953,228 @@ out:
43954 return ispipe;
43955 }
43956
43957 +int pax_check_flags(unsigned long *flags)
43958 +{
43959 + int retval = 0;
43960 +
43961 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
43962 + if (*flags & MF_PAX_SEGMEXEC)
43963 + {
43964 + *flags &= ~MF_PAX_SEGMEXEC;
43965 + retval = -EINVAL;
43966 + }
43967 +#endif
43968 +
43969 + if ((*flags & MF_PAX_PAGEEXEC)
43970 +
43971 +#ifdef CONFIG_PAX_PAGEEXEC
43972 + && (*flags & MF_PAX_SEGMEXEC)
43973 +#endif
43974 +
43975 + )
43976 + {
43977 + *flags &= ~MF_PAX_PAGEEXEC;
43978 + retval = -EINVAL;
43979 + }
43980 +
43981 + if ((*flags & MF_PAX_MPROTECT)
43982 +
43983 +#ifdef CONFIG_PAX_MPROTECT
43984 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
43985 +#endif
43986 +
43987 + )
43988 + {
43989 + *flags &= ~MF_PAX_MPROTECT;
43990 + retval = -EINVAL;
43991 + }
43992 +
43993 + if ((*flags & MF_PAX_EMUTRAMP)
43994 +
43995 +#ifdef CONFIG_PAX_EMUTRAMP
43996 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
43997 +#endif
43998 +
43999 + )
44000 + {
44001 + *flags &= ~MF_PAX_EMUTRAMP;
44002 + retval = -EINVAL;
44003 + }
44004 +
44005 + return retval;
44006 +}
44007 +
44008 +EXPORT_SYMBOL(pax_check_flags);
44009 +
44010 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44011 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
44012 +{
44013 + struct task_struct *tsk = current;
44014 + struct mm_struct *mm = current->mm;
44015 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
44016 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
44017 + char *path_exec = NULL;
44018 + char *path_fault = NULL;
44019 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
44020 +
44021 + if (buffer_exec && buffer_fault) {
44022 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
44023 +
44024 + down_read(&mm->mmap_sem);
44025 + vma = mm->mmap;
44026 + while (vma && (!vma_exec || !vma_fault)) {
44027 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
44028 + vma_exec = vma;
44029 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
44030 + vma_fault = vma;
44031 + vma = vma->vm_next;
44032 + }
44033 + if (vma_exec) {
44034 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
44035 + if (IS_ERR(path_exec))
44036 + path_exec = "<path too long>";
44037 + else {
44038 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
44039 + if (path_exec) {
44040 + *path_exec = 0;
44041 + path_exec = buffer_exec;
44042 + } else
44043 + path_exec = "<path too long>";
44044 + }
44045 + }
44046 + if (vma_fault) {
44047 + start = vma_fault->vm_start;
44048 + end = vma_fault->vm_end;
44049 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
44050 + if (vma_fault->vm_file) {
44051 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
44052 + if (IS_ERR(path_fault))
44053 + path_fault = "<path too long>";
44054 + else {
44055 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
44056 + if (path_fault) {
44057 + *path_fault = 0;
44058 + path_fault = buffer_fault;
44059 + } else
44060 + path_fault = "<path too long>";
44061 + }
44062 + } else
44063 + path_fault = "<anonymous mapping>";
44064 + }
44065 + up_read(&mm->mmap_sem);
44066 + }
44067 + if (tsk->signal->curr_ip)
44068 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
44069 + else
44070 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
44071 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
44072 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
44073 + task_uid(tsk), task_euid(tsk), pc, sp);
44074 + free_page((unsigned long)buffer_exec);
44075 + free_page((unsigned long)buffer_fault);
44076 + pax_report_insns(regs, pc, sp);
44077 + do_coredump(SIGKILL, SIGKILL, regs);
44078 +}
44079 +#endif
44080 +
44081 +#ifdef CONFIG_PAX_REFCOUNT
44082 +void pax_report_refcount_overflow(struct pt_regs *regs)
44083 +{
44084 + if (current->signal->curr_ip)
44085 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44086 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
44087 + else
44088 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44089 + current->comm, task_pid_nr(current), current_uid(), current_euid());
44090 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
44091 + show_regs(regs);
44092 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
44093 +}
44094 +#endif
44095 +
44096 +#ifdef CONFIG_PAX_USERCOPY
44097 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
44098 +int object_is_on_stack(const void *obj, unsigned long len)
44099 +{
44100 + const void * const stack = task_stack_page(current);
44101 + const void * const stackend = stack + THREAD_SIZE;
44102 +
44103 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44104 + const void *frame = NULL;
44105 + const void *oldframe;
44106 +#endif
44107 +
44108 + if (obj + len < obj)
44109 + return -1;
44110 +
44111 + if (obj + len <= stack || stackend <= obj)
44112 + return 0;
44113 +
44114 + if (obj < stack || stackend < obj + len)
44115 + return -1;
44116 +
44117 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44118 + oldframe = __builtin_frame_address(1);
44119 + if (oldframe)
44120 + frame = __builtin_frame_address(2);
44121 + /*
44122 + low ----------------------------------------------> high
44123 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
44124 + ^----------------^
44125 + allow copies only within here
44126 + */
44127 + while (stack <= frame && frame < stackend) {
44128 + /* if obj + len extends past the last frame, this
44129 + check won't pass and the next frame will be 0,
44130 + causing us to bail out and correctly report
44131 + the copy as invalid
44132 + */
44133 + if (obj + len <= frame)
44134 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
44135 + oldframe = frame;
44136 + frame = *(const void * const *)frame;
44137 + }
44138 + return -1;
44139 +#else
44140 + return 1;
44141 +#endif
44142 +}
44143 +
44144 +__noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
44145 +{
44146 + if (current->signal->curr_ip)
44147 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44148 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44149 + else
44150 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44151 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44152 + dump_stack();
44153 + gr_handle_kernel_exploit();
44154 + do_group_exit(SIGKILL);
44155 +}
44156 +#endif
44157 +
44158 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
44159 +void pax_track_stack(void)
44160 +{
44161 + unsigned long sp = (unsigned long)&sp;
44162 + if (sp < current_thread_info()->lowest_stack &&
44163 + sp > (unsigned long)task_stack_page(current))
44164 + current_thread_info()->lowest_stack = sp;
44165 +}
44166 +EXPORT_SYMBOL(pax_track_stack);
44167 +#endif
44168 +
44169 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
44170 +void report_size_overflow(const char *file, unsigned int line, const char *func)
44171 +{
44172 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u\n", func, file, line);
44173 + dump_stack();
44174 + do_group_exit(SIGKILL);
44175 +}
44176 +EXPORT_SYMBOL(report_size_overflow);
44177 +#endif
44178 +
44179 static int zap_process(struct task_struct *start, int exit_code)
44180 {
44181 struct task_struct *t;
44182 @@ -2018,17 +2372,17 @@ static void wait_for_dump_helpers(struct file *file)
44183 pipe = file->f_path.dentry->d_inode->i_pipe;
44184
44185 pipe_lock(pipe);
44186 - pipe->readers++;
44187 - pipe->writers--;
44188 + atomic_inc(&pipe->readers);
44189 + atomic_dec(&pipe->writers);
44190
44191 - while ((pipe->readers > 1) && (!signal_pending(current))) {
44192 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
44193 wake_up_interruptible_sync(&pipe->wait);
44194 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
44195 pipe_wait(pipe);
44196 }
44197
44198 - pipe->readers--;
44199 - pipe->writers++;
44200 + atomic_dec(&pipe->readers);
44201 + atomic_inc(&pipe->writers);
44202 pipe_unlock(pipe);
44203
44204 }
44205 @@ -2089,7 +2443,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44206 int retval = 0;
44207 int flag = 0;
44208 int ispipe;
44209 - static atomic_t core_dump_count = ATOMIC_INIT(0);
44210 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
44211 struct coredump_params cprm = {
44212 .signr = signr,
44213 .regs = regs,
44214 @@ -2104,6 +2458,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44215
44216 audit_core_dumps(signr);
44217
44218 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
44219 + gr_handle_brute_attach(current, cprm.mm_flags);
44220 +
44221 binfmt = mm->binfmt;
44222 if (!binfmt || !binfmt->core_dump)
44223 goto fail;
44224 @@ -2171,7 +2528,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44225 }
44226 cprm.limit = RLIM_INFINITY;
44227
44228 - dump_count = atomic_inc_return(&core_dump_count);
44229 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
44230 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
44231 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
44232 task_tgid_vnr(current), current->comm);
44233 @@ -2198,6 +2555,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44234 } else {
44235 struct inode *inode;
44236
44237 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
44238 +
44239 if (cprm.limit < binfmt->min_coredump)
44240 goto fail_unlock;
44241
44242 @@ -2241,7 +2600,7 @@ close_fail:
44243 filp_close(cprm.file, NULL);
44244 fail_dropcount:
44245 if (ispipe)
44246 - atomic_dec(&core_dump_count);
44247 + atomic_dec_unchecked(&core_dump_count);
44248 fail_unlock:
44249 kfree(cn.corename);
44250 fail_corename:
44251 @@ -2260,7 +2619,7 @@ fail:
44252 */
44253 int dump_write(struct file *file, const void *addr, int nr)
44254 {
44255 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
44256 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
44257 }
44258 EXPORT_SYMBOL(dump_write);
44259
44260 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
44261 index a8cbe1b..fed04cb 100644
44262 --- a/fs/ext2/balloc.c
44263 +++ b/fs/ext2/balloc.c
44264 @@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
44265
44266 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44267 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44268 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44269 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
44270 sbi->s_resuid != current_fsuid() &&
44271 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
44272 return 0;
44273 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
44274 index baac1b1..1499b62 100644
44275 --- a/fs/ext3/balloc.c
44276 +++ b/fs/ext3/balloc.c
44277 @@ -1438,9 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
44278
44279 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44280 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44281 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44282 + if (free_blocks < root_blocks + 1 &&
44283 !use_reservation && sbi->s_resuid != current_fsuid() &&
44284 - (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
44285 + (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)) &&
44286 + !capable_nolog(CAP_SYS_RESOURCE)) {
44287 return 0;
44288 }
44289 return 1;
44290 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
44291 index 8da837b..ed3835b 100644
44292 --- a/fs/ext4/balloc.c
44293 +++ b/fs/ext4/balloc.c
44294 @@ -463,8 +463,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
44295 /* Hm, nope. Are (enough) root reserved clusters available? */
44296 if (sbi->s_resuid == current_fsuid() ||
44297 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
44298 - capable(CAP_SYS_RESOURCE) ||
44299 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
44300 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
44301 + capable_nolog(CAP_SYS_RESOURCE)) {
44302
44303 if (free_clusters >= (nclusters + dirty_clusters))
44304 return 1;
44305 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
44306 index 0e01e90..ae2bd5e 100644
44307 --- a/fs/ext4/ext4.h
44308 +++ b/fs/ext4/ext4.h
44309 @@ -1225,19 +1225,19 @@ struct ext4_sb_info {
44310 unsigned long s_mb_last_start;
44311
44312 /* stats for buddy allocator */
44313 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
44314 - atomic_t s_bal_success; /* we found long enough chunks */
44315 - atomic_t s_bal_allocated; /* in blocks */
44316 - atomic_t s_bal_ex_scanned; /* total extents scanned */
44317 - atomic_t s_bal_goals; /* goal hits */
44318 - atomic_t s_bal_breaks; /* too long searches */
44319 - atomic_t s_bal_2orders; /* 2^order hits */
44320 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
44321 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
44322 + atomic_unchecked_t s_bal_allocated; /* in blocks */
44323 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
44324 + atomic_unchecked_t s_bal_goals; /* goal hits */
44325 + atomic_unchecked_t s_bal_breaks; /* too long searches */
44326 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
44327 spinlock_t s_bal_lock;
44328 unsigned long s_mb_buddies_generated;
44329 unsigned long long s_mb_generation_time;
44330 - atomic_t s_mb_lost_chunks;
44331 - atomic_t s_mb_preallocated;
44332 - atomic_t s_mb_discarded;
44333 + atomic_unchecked_t s_mb_lost_chunks;
44334 + atomic_unchecked_t s_mb_preallocated;
44335 + atomic_unchecked_t s_mb_discarded;
44336 atomic_t s_lock_busy;
44337
44338 /* locality groups */
44339 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
44340 index 6b0a57e..1955a44 100644
44341 --- a/fs/ext4/mballoc.c
44342 +++ b/fs/ext4/mballoc.c
44343 @@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
44344 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
44345
44346 if (EXT4_SB(sb)->s_mb_stats)
44347 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
44348 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
44349
44350 break;
44351 }
44352 @@ -2041,7 +2041,7 @@ repeat:
44353 ac->ac_status = AC_STATUS_CONTINUE;
44354 ac->ac_flags |= EXT4_MB_HINT_FIRST;
44355 cr = 3;
44356 - atomic_inc(&sbi->s_mb_lost_chunks);
44357 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
44358 goto repeat;
44359 }
44360 }
44361 @@ -2545,25 +2545,25 @@ int ext4_mb_release(struct super_block *sb)
44362 if (sbi->s_mb_stats) {
44363 ext4_msg(sb, KERN_INFO,
44364 "mballoc: %u blocks %u reqs (%u success)",
44365 - atomic_read(&sbi->s_bal_allocated),
44366 - atomic_read(&sbi->s_bal_reqs),
44367 - atomic_read(&sbi->s_bal_success));
44368 + atomic_read_unchecked(&sbi->s_bal_allocated),
44369 + atomic_read_unchecked(&sbi->s_bal_reqs),
44370 + atomic_read_unchecked(&sbi->s_bal_success));
44371 ext4_msg(sb, KERN_INFO,
44372 "mballoc: %u extents scanned, %u goal hits, "
44373 "%u 2^N hits, %u breaks, %u lost",
44374 - atomic_read(&sbi->s_bal_ex_scanned),
44375 - atomic_read(&sbi->s_bal_goals),
44376 - atomic_read(&sbi->s_bal_2orders),
44377 - atomic_read(&sbi->s_bal_breaks),
44378 - atomic_read(&sbi->s_mb_lost_chunks));
44379 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
44380 + atomic_read_unchecked(&sbi->s_bal_goals),
44381 + atomic_read_unchecked(&sbi->s_bal_2orders),
44382 + atomic_read_unchecked(&sbi->s_bal_breaks),
44383 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
44384 ext4_msg(sb, KERN_INFO,
44385 "mballoc: %lu generated and it took %Lu",
44386 sbi->s_mb_buddies_generated,
44387 sbi->s_mb_generation_time);
44388 ext4_msg(sb, KERN_INFO,
44389 "mballoc: %u preallocated, %u discarded",
44390 - atomic_read(&sbi->s_mb_preallocated),
44391 - atomic_read(&sbi->s_mb_discarded));
44392 + atomic_read_unchecked(&sbi->s_mb_preallocated),
44393 + atomic_read_unchecked(&sbi->s_mb_discarded));
44394 }
44395
44396 free_percpu(sbi->s_locality_groups);
44397 @@ -3045,16 +3045,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
44398 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
44399
44400 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
44401 - atomic_inc(&sbi->s_bal_reqs);
44402 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
44403 + atomic_inc_unchecked(&sbi->s_bal_reqs);
44404 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
44405 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
44406 - atomic_inc(&sbi->s_bal_success);
44407 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
44408 + atomic_inc_unchecked(&sbi->s_bal_success);
44409 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
44410 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
44411 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
44412 - atomic_inc(&sbi->s_bal_goals);
44413 + atomic_inc_unchecked(&sbi->s_bal_goals);
44414 if (ac->ac_found > sbi->s_mb_max_to_scan)
44415 - atomic_inc(&sbi->s_bal_breaks);
44416 + atomic_inc_unchecked(&sbi->s_bal_breaks);
44417 }
44418
44419 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
44420 @@ -3458,7 +3458,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
44421 trace_ext4_mb_new_inode_pa(ac, pa);
44422
44423 ext4_mb_use_inode_pa(ac, pa);
44424 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
44425 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
44426
44427 ei = EXT4_I(ac->ac_inode);
44428 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
44429 @@ -3518,7 +3518,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
44430 trace_ext4_mb_new_group_pa(ac, pa);
44431
44432 ext4_mb_use_group_pa(ac, pa);
44433 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44434 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44435
44436 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
44437 lg = ac->ac_lg;
44438 @@ -3607,7 +3607,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
44439 * from the bitmap and continue.
44440 */
44441 }
44442 - atomic_add(free, &sbi->s_mb_discarded);
44443 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
44444
44445 return err;
44446 }
44447 @@ -3625,7 +3625,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
44448 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
44449 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
44450 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
44451 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
44452 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
44453 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
44454
44455 return 0;
44456 diff --git a/fs/fcntl.c b/fs/fcntl.c
44457 index 75e7c1f..1eb3e4d 100644
44458 --- a/fs/fcntl.c
44459 +++ b/fs/fcntl.c
44460 @@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
44461 if (err)
44462 return err;
44463
44464 + if (gr_handle_chroot_fowner(pid, type))
44465 + return -ENOENT;
44466 + if (gr_check_protected_task_fowner(pid, type))
44467 + return -EACCES;
44468 +
44469 f_modown(filp, pid, type, force);
44470 return 0;
44471 }
44472 @@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
44473
44474 static int f_setown_ex(struct file *filp, unsigned long arg)
44475 {
44476 - struct f_owner_ex * __user owner_p = (void * __user)arg;
44477 + struct f_owner_ex __user *owner_p = (void __user *)arg;
44478 struct f_owner_ex owner;
44479 struct pid *pid;
44480 int type;
44481 @@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
44482
44483 static int f_getown_ex(struct file *filp, unsigned long arg)
44484 {
44485 - struct f_owner_ex * __user owner_p = (void * __user)arg;
44486 + struct f_owner_ex __user *owner_p = (void __user *)arg;
44487 struct f_owner_ex owner;
44488 int ret = 0;
44489
44490 @@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
44491 switch (cmd) {
44492 case F_DUPFD:
44493 case F_DUPFD_CLOEXEC:
44494 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
44495 if (arg >= rlimit(RLIMIT_NOFILE))
44496 break;
44497 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
44498 diff --git a/fs/fifo.c b/fs/fifo.c
44499 index b1a524d..4ee270e 100644
44500 --- a/fs/fifo.c
44501 +++ b/fs/fifo.c
44502 @@ -58,10 +58,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
44503 */
44504 filp->f_op = &read_pipefifo_fops;
44505 pipe->r_counter++;
44506 - if (pipe->readers++ == 0)
44507 + if (atomic_inc_return(&pipe->readers) == 1)
44508 wake_up_partner(inode);
44509
44510 - if (!pipe->writers) {
44511 + if (!atomic_read(&pipe->writers)) {
44512 if ((filp->f_flags & O_NONBLOCK)) {
44513 /* suppress POLLHUP until we have
44514 * seen a writer */
44515 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
44516 * errno=ENXIO when there is no process reading the FIFO.
44517 */
44518 ret = -ENXIO;
44519 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
44520 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
44521 goto err;
44522
44523 filp->f_op = &write_pipefifo_fops;
44524 pipe->w_counter++;
44525 - if (!pipe->writers++)
44526 + if (atomic_inc_return(&pipe->writers) == 1)
44527 wake_up_partner(inode);
44528
44529 - if (!pipe->readers) {
44530 + if (!atomic_read(&pipe->readers)) {
44531 wait_for_partner(inode, &pipe->r_counter);
44532 if (signal_pending(current))
44533 goto err_wr;
44534 @@ -105,11 +105,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
44535 */
44536 filp->f_op = &rdwr_pipefifo_fops;
44537
44538 - pipe->readers++;
44539 - pipe->writers++;
44540 + atomic_inc(&pipe->readers);
44541 + atomic_inc(&pipe->writers);
44542 pipe->r_counter++;
44543 pipe->w_counter++;
44544 - if (pipe->readers == 1 || pipe->writers == 1)
44545 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
44546 wake_up_partner(inode);
44547 break;
44548
44549 @@ -123,19 +123,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
44550 return 0;
44551
44552 err_rd:
44553 - if (!--pipe->readers)
44554 + if (atomic_dec_and_test(&pipe->readers))
44555 wake_up_interruptible(&pipe->wait);
44556 ret = -ERESTARTSYS;
44557 goto err;
44558
44559 err_wr:
44560 - if (!--pipe->writers)
44561 + if (atomic_dec_and_test(&pipe->writers))
44562 wake_up_interruptible(&pipe->wait);
44563 ret = -ERESTARTSYS;
44564 goto err;
44565
44566 err:
44567 - if (!pipe->readers && !pipe->writers)
44568 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
44569 free_pipe_info(inode);
44570
44571 err_nocleanup:
44572 diff --git a/fs/file.c b/fs/file.c
44573 index ba3f605..fade102 100644
44574 --- a/fs/file.c
44575 +++ b/fs/file.c
44576 @@ -15,6 +15,7 @@
44577 #include <linux/slab.h>
44578 #include <linux/vmalloc.h>
44579 #include <linux/file.h>
44580 +#include <linux/security.h>
44581 #include <linux/fdtable.h>
44582 #include <linux/bitops.h>
44583 #include <linux/interrupt.h>
44584 @@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
44585 * N.B. For clone tasks sharing a files structure, this test
44586 * will limit the total number of files that can be opened.
44587 */
44588 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
44589 if (nr >= rlimit(RLIMIT_NOFILE))
44590 return -EMFILE;
44591
44592 diff --git a/fs/filesystems.c b/fs/filesystems.c
44593 index 96f2428..f5eeb8e 100644
44594 --- a/fs/filesystems.c
44595 +++ b/fs/filesystems.c
44596 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
44597 int len = dot ? dot - name : strlen(name);
44598
44599 fs = __get_fs_type(name, len);
44600 +
44601 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
44602 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
44603 +#else
44604 if (!fs && (request_module("%.*s", len, name) == 0))
44605 +#endif
44606 fs = __get_fs_type(name, len);
44607
44608 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
44609 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
44610 index e159e68..e7d2a6f 100644
44611 --- a/fs/fs_struct.c
44612 +++ b/fs/fs_struct.c
44613 @@ -4,6 +4,7 @@
44614 #include <linux/path.h>
44615 #include <linux/slab.h>
44616 #include <linux/fs_struct.h>
44617 +#include <linux/grsecurity.h>
44618 #include "internal.h"
44619
44620 static inline void path_get_longterm(struct path *path)
44621 @@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
44622 write_seqcount_begin(&fs->seq);
44623 old_root = fs->root;
44624 fs->root = *path;
44625 + gr_set_chroot_entries(current, path);
44626 write_seqcount_end(&fs->seq);
44627 spin_unlock(&fs->lock);
44628 if (old_root.dentry)
44629 @@ -65,6 +67,17 @@ static inline int replace_path(struct path *p, const struct path *old, const str
44630 return 1;
44631 }
44632
44633 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
44634 +{
44635 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
44636 + return 0;
44637 + *p = *new;
44638 +
44639 + gr_set_chroot_entries(task, new);
44640 +
44641 + return 1;
44642 +}
44643 +
44644 void chroot_fs_refs(struct path *old_root, struct path *new_root)
44645 {
44646 struct task_struct *g, *p;
44647 @@ -79,7 +92,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
44648 int hits = 0;
44649 spin_lock(&fs->lock);
44650 write_seqcount_begin(&fs->seq);
44651 - hits += replace_path(&fs->root, old_root, new_root);
44652 + hits += replace_root_path(p, &fs->root, old_root, new_root);
44653 hits += replace_path(&fs->pwd, old_root, new_root);
44654 write_seqcount_end(&fs->seq);
44655 while (hits--) {
44656 @@ -111,7 +124,8 @@ void exit_fs(struct task_struct *tsk)
44657 task_lock(tsk);
44658 spin_lock(&fs->lock);
44659 tsk->fs = NULL;
44660 - kill = !--fs->users;
44661 + gr_clear_chroot_entries(tsk);
44662 + kill = !atomic_dec_return(&fs->users);
44663 spin_unlock(&fs->lock);
44664 task_unlock(tsk);
44665 if (kill)
44666 @@ -124,7 +138,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
44667 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
44668 /* We don't need to lock fs - think why ;-) */
44669 if (fs) {
44670 - fs->users = 1;
44671 + atomic_set(&fs->users, 1);
44672 fs->in_exec = 0;
44673 spin_lock_init(&fs->lock);
44674 seqcount_init(&fs->seq);
44675 @@ -133,6 +147,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
44676 spin_lock(&old->lock);
44677 fs->root = old->root;
44678 path_get_longterm(&fs->root);
44679 + /* instead of calling gr_set_chroot_entries here,
44680 + we call it from every caller of this function
44681 + */
44682 fs->pwd = old->pwd;
44683 path_get_longterm(&fs->pwd);
44684 spin_unlock(&old->lock);
44685 @@ -151,8 +168,9 @@ int unshare_fs_struct(void)
44686
44687 task_lock(current);
44688 spin_lock(&fs->lock);
44689 - kill = !--fs->users;
44690 + kill = !atomic_dec_return(&fs->users);
44691 current->fs = new_fs;
44692 + gr_set_chroot_entries(current, &new_fs->root);
44693 spin_unlock(&fs->lock);
44694 task_unlock(current);
44695
44696 @@ -165,13 +183,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
44697
44698 int current_umask(void)
44699 {
44700 - return current->fs->umask;
44701 + return current->fs->umask | gr_acl_umask();
44702 }
44703 EXPORT_SYMBOL(current_umask);
44704
44705 /* to be mentioned only in INIT_TASK */
44706 struct fs_struct init_fs = {
44707 - .users = 1,
44708 + .users = ATOMIC_INIT(1),
44709 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
44710 .seq = SEQCNT_ZERO,
44711 .umask = 0022,
44712 @@ -187,12 +205,13 @@ void daemonize_fs_struct(void)
44713 task_lock(current);
44714
44715 spin_lock(&init_fs.lock);
44716 - init_fs.users++;
44717 + atomic_inc(&init_fs.users);
44718 spin_unlock(&init_fs.lock);
44719
44720 spin_lock(&fs->lock);
44721 current->fs = &init_fs;
44722 - kill = !--fs->users;
44723 + gr_set_chroot_entries(current, &current->fs->root);
44724 + kill = !atomic_dec_return(&fs->users);
44725 spin_unlock(&fs->lock);
44726
44727 task_unlock(current);
44728 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
44729 index 9905350..02eaec4 100644
44730 --- a/fs/fscache/cookie.c
44731 +++ b/fs/fscache/cookie.c
44732 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
44733 parent ? (char *) parent->def->name : "<no-parent>",
44734 def->name, netfs_data);
44735
44736 - fscache_stat(&fscache_n_acquires);
44737 + fscache_stat_unchecked(&fscache_n_acquires);
44738
44739 /* if there's no parent cookie, then we don't create one here either */
44740 if (!parent) {
44741 - fscache_stat(&fscache_n_acquires_null);
44742 + fscache_stat_unchecked(&fscache_n_acquires_null);
44743 _leave(" [no parent]");
44744 return NULL;
44745 }
44746 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
44747 /* allocate and initialise a cookie */
44748 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
44749 if (!cookie) {
44750 - fscache_stat(&fscache_n_acquires_oom);
44751 + fscache_stat_unchecked(&fscache_n_acquires_oom);
44752 _leave(" [ENOMEM]");
44753 return NULL;
44754 }
44755 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
44756
44757 switch (cookie->def->type) {
44758 case FSCACHE_COOKIE_TYPE_INDEX:
44759 - fscache_stat(&fscache_n_cookie_index);
44760 + fscache_stat_unchecked(&fscache_n_cookie_index);
44761 break;
44762 case FSCACHE_COOKIE_TYPE_DATAFILE:
44763 - fscache_stat(&fscache_n_cookie_data);
44764 + fscache_stat_unchecked(&fscache_n_cookie_data);
44765 break;
44766 default:
44767 - fscache_stat(&fscache_n_cookie_special);
44768 + fscache_stat_unchecked(&fscache_n_cookie_special);
44769 break;
44770 }
44771
44772 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
44773 if (fscache_acquire_non_index_cookie(cookie) < 0) {
44774 atomic_dec(&parent->n_children);
44775 __fscache_cookie_put(cookie);
44776 - fscache_stat(&fscache_n_acquires_nobufs);
44777 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
44778 _leave(" = NULL");
44779 return NULL;
44780 }
44781 }
44782
44783 - fscache_stat(&fscache_n_acquires_ok);
44784 + fscache_stat_unchecked(&fscache_n_acquires_ok);
44785 _leave(" = %p", cookie);
44786 return cookie;
44787 }
44788 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
44789 cache = fscache_select_cache_for_object(cookie->parent);
44790 if (!cache) {
44791 up_read(&fscache_addremove_sem);
44792 - fscache_stat(&fscache_n_acquires_no_cache);
44793 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
44794 _leave(" = -ENOMEDIUM [no cache]");
44795 return -ENOMEDIUM;
44796 }
44797 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
44798 object = cache->ops->alloc_object(cache, cookie);
44799 fscache_stat_d(&fscache_n_cop_alloc_object);
44800 if (IS_ERR(object)) {
44801 - fscache_stat(&fscache_n_object_no_alloc);
44802 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
44803 ret = PTR_ERR(object);
44804 goto error;
44805 }
44806
44807 - fscache_stat(&fscache_n_object_alloc);
44808 + fscache_stat_unchecked(&fscache_n_object_alloc);
44809
44810 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
44811
44812 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
44813 struct fscache_object *object;
44814 struct hlist_node *_p;
44815
44816 - fscache_stat(&fscache_n_updates);
44817 + fscache_stat_unchecked(&fscache_n_updates);
44818
44819 if (!cookie) {
44820 - fscache_stat(&fscache_n_updates_null);
44821 + fscache_stat_unchecked(&fscache_n_updates_null);
44822 _leave(" [no cookie]");
44823 return;
44824 }
44825 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
44826 struct fscache_object *object;
44827 unsigned long event;
44828
44829 - fscache_stat(&fscache_n_relinquishes);
44830 + fscache_stat_unchecked(&fscache_n_relinquishes);
44831 if (retire)
44832 - fscache_stat(&fscache_n_relinquishes_retire);
44833 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
44834
44835 if (!cookie) {
44836 - fscache_stat(&fscache_n_relinquishes_null);
44837 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
44838 _leave(" [no cookie]");
44839 return;
44840 }
44841 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
44842
44843 /* wait for the cookie to finish being instantiated (or to fail) */
44844 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
44845 - fscache_stat(&fscache_n_relinquishes_waitcrt);
44846 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
44847 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
44848 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
44849 }
44850 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
44851 index f6aad48..88dcf26 100644
44852 --- a/fs/fscache/internal.h
44853 +++ b/fs/fscache/internal.h
44854 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
44855 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
44856 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
44857
44858 -extern atomic_t fscache_n_op_pend;
44859 -extern atomic_t fscache_n_op_run;
44860 -extern atomic_t fscache_n_op_enqueue;
44861 -extern atomic_t fscache_n_op_deferred_release;
44862 -extern atomic_t fscache_n_op_release;
44863 -extern atomic_t fscache_n_op_gc;
44864 -extern atomic_t fscache_n_op_cancelled;
44865 -extern atomic_t fscache_n_op_rejected;
44866 +extern atomic_unchecked_t fscache_n_op_pend;
44867 +extern atomic_unchecked_t fscache_n_op_run;
44868 +extern atomic_unchecked_t fscache_n_op_enqueue;
44869 +extern atomic_unchecked_t fscache_n_op_deferred_release;
44870 +extern atomic_unchecked_t fscache_n_op_release;
44871 +extern atomic_unchecked_t fscache_n_op_gc;
44872 +extern atomic_unchecked_t fscache_n_op_cancelled;
44873 +extern atomic_unchecked_t fscache_n_op_rejected;
44874
44875 -extern atomic_t fscache_n_attr_changed;
44876 -extern atomic_t fscache_n_attr_changed_ok;
44877 -extern atomic_t fscache_n_attr_changed_nobufs;
44878 -extern atomic_t fscache_n_attr_changed_nomem;
44879 -extern atomic_t fscache_n_attr_changed_calls;
44880 +extern atomic_unchecked_t fscache_n_attr_changed;
44881 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
44882 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
44883 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
44884 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
44885
44886 -extern atomic_t fscache_n_allocs;
44887 -extern atomic_t fscache_n_allocs_ok;
44888 -extern atomic_t fscache_n_allocs_wait;
44889 -extern atomic_t fscache_n_allocs_nobufs;
44890 -extern atomic_t fscache_n_allocs_intr;
44891 -extern atomic_t fscache_n_allocs_object_dead;
44892 -extern atomic_t fscache_n_alloc_ops;
44893 -extern atomic_t fscache_n_alloc_op_waits;
44894 +extern atomic_unchecked_t fscache_n_allocs;
44895 +extern atomic_unchecked_t fscache_n_allocs_ok;
44896 +extern atomic_unchecked_t fscache_n_allocs_wait;
44897 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
44898 +extern atomic_unchecked_t fscache_n_allocs_intr;
44899 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
44900 +extern atomic_unchecked_t fscache_n_alloc_ops;
44901 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
44902
44903 -extern atomic_t fscache_n_retrievals;
44904 -extern atomic_t fscache_n_retrievals_ok;
44905 -extern atomic_t fscache_n_retrievals_wait;
44906 -extern atomic_t fscache_n_retrievals_nodata;
44907 -extern atomic_t fscache_n_retrievals_nobufs;
44908 -extern atomic_t fscache_n_retrievals_intr;
44909 -extern atomic_t fscache_n_retrievals_nomem;
44910 -extern atomic_t fscache_n_retrievals_object_dead;
44911 -extern atomic_t fscache_n_retrieval_ops;
44912 -extern atomic_t fscache_n_retrieval_op_waits;
44913 +extern atomic_unchecked_t fscache_n_retrievals;
44914 +extern atomic_unchecked_t fscache_n_retrievals_ok;
44915 +extern atomic_unchecked_t fscache_n_retrievals_wait;
44916 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
44917 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
44918 +extern atomic_unchecked_t fscache_n_retrievals_intr;
44919 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
44920 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
44921 +extern atomic_unchecked_t fscache_n_retrieval_ops;
44922 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
44923
44924 -extern atomic_t fscache_n_stores;
44925 -extern atomic_t fscache_n_stores_ok;
44926 -extern atomic_t fscache_n_stores_again;
44927 -extern atomic_t fscache_n_stores_nobufs;
44928 -extern atomic_t fscache_n_stores_oom;
44929 -extern atomic_t fscache_n_store_ops;
44930 -extern atomic_t fscache_n_store_calls;
44931 -extern atomic_t fscache_n_store_pages;
44932 -extern atomic_t fscache_n_store_radix_deletes;
44933 -extern atomic_t fscache_n_store_pages_over_limit;
44934 +extern atomic_unchecked_t fscache_n_stores;
44935 +extern atomic_unchecked_t fscache_n_stores_ok;
44936 +extern atomic_unchecked_t fscache_n_stores_again;
44937 +extern atomic_unchecked_t fscache_n_stores_nobufs;
44938 +extern atomic_unchecked_t fscache_n_stores_oom;
44939 +extern atomic_unchecked_t fscache_n_store_ops;
44940 +extern atomic_unchecked_t fscache_n_store_calls;
44941 +extern atomic_unchecked_t fscache_n_store_pages;
44942 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
44943 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
44944
44945 -extern atomic_t fscache_n_store_vmscan_not_storing;
44946 -extern atomic_t fscache_n_store_vmscan_gone;
44947 -extern atomic_t fscache_n_store_vmscan_busy;
44948 -extern atomic_t fscache_n_store_vmscan_cancelled;
44949 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
44950 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
44951 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
44952 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
44953
44954 -extern atomic_t fscache_n_marks;
44955 -extern atomic_t fscache_n_uncaches;
44956 +extern atomic_unchecked_t fscache_n_marks;
44957 +extern atomic_unchecked_t fscache_n_uncaches;
44958
44959 -extern atomic_t fscache_n_acquires;
44960 -extern atomic_t fscache_n_acquires_null;
44961 -extern atomic_t fscache_n_acquires_no_cache;
44962 -extern atomic_t fscache_n_acquires_ok;
44963 -extern atomic_t fscache_n_acquires_nobufs;
44964 -extern atomic_t fscache_n_acquires_oom;
44965 +extern atomic_unchecked_t fscache_n_acquires;
44966 +extern atomic_unchecked_t fscache_n_acquires_null;
44967 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
44968 +extern atomic_unchecked_t fscache_n_acquires_ok;
44969 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
44970 +extern atomic_unchecked_t fscache_n_acquires_oom;
44971
44972 -extern atomic_t fscache_n_updates;
44973 -extern atomic_t fscache_n_updates_null;
44974 -extern atomic_t fscache_n_updates_run;
44975 +extern atomic_unchecked_t fscache_n_updates;
44976 +extern atomic_unchecked_t fscache_n_updates_null;
44977 +extern atomic_unchecked_t fscache_n_updates_run;
44978
44979 -extern atomic_t fscache_n_relinquishes;
44980 -extern atomic_t fscache_n_relinquishes_null;
44981 -extern atomic_t fscache_n_relinquishes_waitcrt;
44982 -extern atomic_t fscache_n_relinquishes_retire;
44983 +extern atomic_unchecked_t fscache_n_relinquishes;
44984 +extern atomic_unchecked_t fscache_n_relinquishes_null;
44985 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
44986 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
44987
44988 -extern atomic_t fscache_n_cookie_index;
44989 -extern atomic_t fscache_n_cookie_data;
44990 -extern atomic_t fscache_n_cookie_special;
44991 +extern atomic_unchecked_t fscache_n_cookie_index;
44992 +extern atomic_unchecked_t fscache_n_cookie_data;
44993 +extern atomic_unchecked_t fscache_n_cookie_special;
44994
44995 -extern atomic_t fscache_n_object_alloc;
44996 -extern atomic_t fscache_n_object_no_alloc;
44997 -extern atomic_t fscache_n_object_lookups;
44998 -extern atomic_t fscache_n_object_lookups_negative;
44999 -extern atomic_t fscache_n_object_lookups_positive;
45000 -extern atomic_t fscache_n_object_lookups_timed_out;
45001 -extern atomic_t fscache_n_object_created;
45002 -extern atomic_t fscache_n_object_avail;
45003 -extern atomic_t fscache_n_object_dead;
45004 +extern atomic_unchecked_t fscache_n_object_alloc;
45005 +extern atomic_unchecked_t fscache_n_object_no_alloc;
45006 +extern atomic_unchecked_t fscache_n_object_lookups;
45007 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
45008 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
45009 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
45010 +extern atomic_unchecked_t fscache_n_object_created;
45011 +extern atomic_unchecked_t fscache_n_object_avail;
45012 +extern atomic_unchecked_t fscache_n_object_dead;
45013
45014 -extern atomic_t fscache_n_checkaux_none;
45015 -extern atomic_t fscache_n_checkaux_okay;
45016 -extern atomic_t fscache_n_checkaux_update;
45017 -extern atomic_t fscache_n_checkaux_obsolete;
45018 +extern atomic_unchecked_t fscache_n_checkaux_none;
45019 +extern atomic_unchecked_t fscache_n_checkaux_okay;
45020 +extern atomic_unchecked_t fscache_n_checkaux_update;
45021 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
45022
45023 extern atomic_t fscache_n_cop_alloc_object;
45024 extern atomic_t fscache_n_cop_lookup_object;
45025 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
45026 atomic_inc(stat);
45027 }
45028
45029 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
45030 +{
45031 + atomic_inc_unchecked(stat);
45032 +}
45033 +
45034 static inline void fscache_stat_d(atomic_t *stat)
45035 {
45036 atomic_dec(stat);
45037 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
45038
45039 #define __fscache_stat(stat) (NULL)
45040 #define fscache_stat(stat) do {} while (0)
45041 +#define fscache_stat_unchecked(stat) do {} while (0)
45042 #define fscache_stat_d(stat) do {} while (0)
45043 #endif
45044
45045 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
45046 index b6b897c..0ffff9c 100644
45047 --- a/fs/fscache/object.c
45048 +++ b/fs/fscache/object.c
45049 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45050 /* update the object metadata on disk */
45051 case FSCACHE_OBJECT_UPDATING:
45052 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
45053 - fscache_stat(&fscache_n_updates_run);
45054 + fscache_stat_unchecked(&fscache_n_updates_run);
45055 fscache_stat(&fscache_n_cop_update_object);
45056 object->cache->ops->update_object(object);
45057 fscache_stat_d(&fscache_n_cop_update_object);
45058 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45059 spin_lock(&object->lock);
45060 object->state = FSCACHE_OBJECT_DEAD;
45061 spin_unlock(&object->lock);
45062 - fscache_stat(&fscache_n_object_dead);
45063 + fscache_stat_unchecked(&fscache_n_object_dead);
45064 goto terminal_transit;
45065
45066 /* handle the parent cache of this object being withdrawn from
45067 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45068 spin_lock(&object->lock);
45069 object->state = FSCACHE_OBJECT_DEAD;
45070 spin_unlock(&object->lock);
45071 - fscache_stat(&fscache_n_object_dead);
45072 + fscache_stat_unchecked(&fscache_n_object_dead);
45073 goto terminal_transit;
45074
45075 /* complain about the object being woken up once it is
45076 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45077 parent->cookie->def->name, cookie->def->name,
45078 object->cache->tag->name);
45079
45080 - fscache_stat(&fscache_n_object_lookups);
45081 + fscache_stat_unchecked(&fscache_n_object_lookups);
45082 fscache_stat(&fscache_n_cop_lookup_object);
45083 ret = object->cache->ops->lookup_object(object);
45084 fscache_stat_d(&fscache_n_cop_lookup_object);
45085 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45086 if (ret == -ETIMEDOUT) {
45087 /* probably stuck behind another object, so move this one to
45088 * the back of the queue */
45089 - fscache_stat(&fscache_n_object_lookups_timed_out);
45090 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
45091 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45092 }
45093
45094 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
45095
45096 spin_lock(&object->lock);
45097 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45098 - fscache_stat(&fscache_n_object_lookups_negative);
45099 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
45100
45101 /* transit here to allow write requests to begin stacking up
45102 * and read requests to begin returning ENODATA */
45103 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
45104 * result, in which case there may be data available */
45105 spin_lock(&object->lock);
45106 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45107 - fscache_stat(&fscache_n_object_lookups_positive);
45108 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
45109
45110 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
45111
45112 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
45113 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45114 } else {
45115 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
45116 - fscache_stat(&fscache_n_object_created);
45117 + fscache_stat_unchecked(&fscache_n_object_created);
45118
45119 object->state = FSCACHE_OBJECT_AVAILABLE;
45120 spin_unlock(&object->lock);
45121 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
45122 fscache_enqueue_dependents(object);
45123
45124 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
45125 - fscache_stat(&fscache_n_object_avail);
45126 + fscache_stat_unchecked(&fscache_n_object_avail);
45127
45128 _leave("");
45129 }
45130 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45131 enum fscache_checkaux result;
45132
45133 if (!object->cookie->def->check_aux) {
45134 - fscache_stat(&fscache_n_checkaux_none);
45135 + fscache_stat_unchecked(&fscache_n_checkaux_none);
45136 return FSCACHE_CHECKAUX_OKAY;
45137 }
45138
45139 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45140 switch (result) {
45141 /* entry okay as is */
45142 case FSCACHE_CHECKAUX_OKAY:
45143 - fscache_stat(&fscache_n_checkaux_okay);
45144 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
45145 break;
45146
45147 /* entry requires update */
45148 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
45149 - fscache_stat(&fscache_n_checkaux_update);
45150 + fscache_stat_unchecked(&fscache_n_checkaux_update);
45151 break;
45152
45153 /* entry requires deletion */
45154 case FSCACHE_CHECKAUX_OBSOLETE:
45155 - fscache_stat(&fscache_n_checkaux_obsolete);
45156 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
45157 break;
45158
45159 default:
45160 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
45161 index 30afdfa..2256596 100644
45162 --- a/fs/fscache/operation.c
45163 +++ b/fs/fscache/operation.c
45164 @@ -17,7 +17,7 @@
45165 #include <linux/slab.h>
45166 #include "internal.h"
45167
45168 -atomic_t fscache_op_debug_id;
45169 +atomic_unchecked_t fscache_op_debug_id;
45170 EXPORT_SYMBOL(fscache_op_debug_id);
45171
45172 /**
45173 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
45174 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
45175 ASSERTCMP(atomic_read(&op->usage), >, 0);
45176
45177 - fscache_stat(&fscache_n_op_enqueue);
45178 + fscache_stat_unchecked(&fscache_n_op_enqueue);
45179 switch (op->flags & FSCACHE_OP_TYPE) {
45180 case FSCACHE_OP_ASYNC:
45181 _debug("queue async");
45182 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
45183 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
45184 if (op->processor)
45185 fscache_enqueue_operation(op);
45186 - fscache_stat(&fscache_n_op_run);
45187 + fscache_stat_unchecked(&fscache_n_op_run);
45188 }
45189
45190 /*
45191 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45192 if (object->n_ops > 1) {
45193 atomic_inc(&op->usage);
45194 list_add_tail(&op->pend_link, &object->pending_ops);
45195 - fscache_stat(&fscache_n_op_pend);
45196 + fscache_stat_unchecked(&fscache_n_op_pend);
45197 } else if (!list_empty(&object->pending_ops)) {
45198 atomic_inc(&op->usage);
45199 list_add_tail(&op->pend_link, &object->pending_ops);
45200 - fscache_stat(&fscache_n_op_pend);
45201 + fscache_stat_unchecked(&fscache_n_op_pend);
45202 fscache_start_operations(object);
45203 } else {
45204 ASSERTCMP(object->n_in_progress, ==, 0);
45205 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45206 object->n_exclusive++; /* reads and writes must wait */
45207 atomic_inc(&op->usage);
45208 list_add_tail(&op->pend_link, &object->pending_ops);
45209 - fscache_stat(&fscache_n_op_pend);
45210 + fscache_stat_unchecked(&fscache_n_op_pend);
45211 ret = 0;
45212 } else {
45213 /* not allowed to submit ops in any other state */
45214 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
45215 if (object->n_exclusive > 0) {
45216 atomic_inc(&op->usage);
45217 list_add_tail(&op->pend_link, &object->pending_ops);
45218 - fscache_stat(&fscache_n_op_pend);
45219 + fscache_stat_unchecked(&fscache_n_op_pend);
45220 } else if (!list_empty(&object->pending_ops)) {
45221 atomic_inc(&op->usage);
45222 list_add_tail(&op->pend_link, &object->pending_ops);
45223 - fscache_stat(&fscache_n_op_pend);
45224 + fscache_stat_unchecked(&fscache_n_op_pend);
45225 fscache_start_operations(object);
45226 } else {
45227 ASSERTCMP(object->n_exclusive, ==, 0);
45228 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
45229 object->n_ops++;
45230 atomic_inc(&op->usage);
45231 list_add_tail(&op->pend_link, &object->pending_ops);
45232 - fscache_stat(&fscache_n_op_pend);
45233 + fscache_stat_unchecked(&fscache_n_op_pend);
45234 ret = 0;
45235 } else if (object->state == FSCACHE_OBJECT_DYING ||
45236 object->state == FSCACHE_OBJECT_LC_DYING ||
45237 object->state == FSCACHE_OBJECT_WITHDRAWING) {
45238 - fscache_stat(&fscache_n_op_rejected);
45239 + fscache_stat_unchecked(&fscache_n_op_rejected);
45240 ret = -ENOBUFS;
45241 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
45242 fscache_report_unexpected_submission(object, op, ostate);
45243 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
45244
45245 ret = -EBUSY;
45246 if (!list_empty(&op->pend_link)) {
45247 - fscache_stat(&fscache_n_op_cancelled);
45248 + fscache_stat_unchecked(&fscache_n_op_cancelled);
45249 list_del_init(&op->pend_link);
45250 object->n_ops--;
45251 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
45252 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
45253 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
45254 BUG();
45255
45256 - fscache_stat(&fscache_n_op_release);
45257 + fscache_stat_unchecked(&fscache_n_op_release);
45258
45259 if (op->release) {
45260 op->release(op);
45261 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
45262 * lock, and defer it otherwise */
45263 if (!spin_trylock(&object->lock)) {
45264 _debug("defer put");
45265 - fscache_stat(&fscache_n_op_deferred_release);
45266 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
45267
45268 cache = object->cache;
45269 spin_lock(&cache->op_gc_list_lock);
45270 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
45271
45272 _debug("GC DEFERRED REL OBJ%x OP%x",
45273 object->debug_id, op->debug_id);
45274 - fscache_stat(&fscache_n_op_gc);
45275 + fscache_stat_unchecked(&fscache_n_op_gc);
45276
45277 ASSERTCMP(atomic_read(&op->usage), ==, 0);
45278
45279 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
45280 index 3f7a59b..cf196cc 100644
45281 --- a/fs/fscache/page.c
45282 +++ b/fs/fscache/page.c
45283 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45284 val = radix_tree_lookup(&cookie->stores, page->index);
45285 if (!val) {
45286 rcu_read_unlock();
45287 - fscache_stat(&fscache_n_store_vmscan_not_storing);
45288 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
45289 __fscache_uncache_page(cookie, page);
45290 return true;
45291 }
45292 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45293 spin_unlock(&cookie->stores_lock);
45294
45295 if (xpage) {
45296 - fscache_stat(&fscache_n_store_vmscan_cancelled);
45297 - fscache_stat(&fscache_n_store_radix_deletes);
45298 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
45299 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
45300 ASSERTCMP(xpage, ==, page);
45301 } else {
45302 - fscache_stat(&fscache_n_store_vmscan_gone);
45303 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
45304 }
45305
45306 wake_up_bit(&cookie->flags, 0);
45307 @@ -107,7 +107,7 @@ page_busy:
45308 /* we might want to wait here, but that could deadlock the allocator as
45309 * the work threads writing to the cache may all end up sleeping
45310 * on memory allocation */
45311 - fscache_stat(&fscache_n_store_vmscan_busy);
45312 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
45313 return false;
45314 }
45315 EXPORT_SYMBOL(__fscache_maybe_release_page);
45316 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
45317 FSCACHE_COOKIE_STORING_TAG);
45318 if (!radix_tree_tag_get(&cookie->stores, page->index,
45319 FSCACHE_COOKIE_PENDING_TAG)) {
45320 - fscache_stat(&fscache_n_store_radix_deletes);
45321 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
45322 xpage = radix_tree_delete(&cookie->stores, page->index);
45323 }
45324 spin_unlock(&cookie->stores_lock);
45325 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
45326
45327 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
45328
45329 - fscache_stat(&fscache_n_attr_changed_calls);
45330 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
45331
45332 if (fscache_object_is_active(object)) {
45333 fscache_stat(&fscache_n_cop_attr_changed);
45334 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45335
45336 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45337
45338 - fscache_stat(&fscache_n_attr_changed);
45339 + fscache_stat_unchecked(&fscache_n_attr_changed);
45340
45341 op = kzalloc(sizeof(*op), GFP_KERNEL);
45342 if (!op) {
45343 - fscache_stat(&fscache_n_attr_changed_nomem);
45344 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
45345 _leave(" = -ENOMEM");
45346 return -ENOMEM;
45347 }
45348 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45349 if (fscache_submit_exclusive_op(object, op) < 0)
45350 goto nobufs;
45351 spin_unlock(&cookie->lock);
45352 - fscache_stat(&fscache_n_attr_changed_ok);
45353 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
45354 fscache_put_operation(op);
45355 _leave(" = 0");
45356 return 0;
45357 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45358 nobufs:
45359 spin_unlock(&cookie->lock);
45360 kfree(op);
45361 - fscache_stat(&fscache_n_attr_changed_nobufs);
45362 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
45363 _leave(" = %d", -ENOBUFS);
45364 return -ENOBUFS;
45365 }
45366 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
45367 /* allocate a retrieval operation and attempt to submit it */
45368 op = kzalloc(sizeof(*op), GFP_NOIO);
45369 if (!op) {
45370 - fscache_stat(&fscache_n_retrievals_nomem);
45371 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45372 return NULL;
45373 }
45374
45375 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45376 return 0;
45377 }
45378
45379 - fscache_stat(&fscache_n_retrievals_wait);
45380 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
45381
45382 jif = jiffies;
45383 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
45384 fscache_wait_bit_interruptible,
45385 TASK_INTERRUPTIBLE) != 0) {
45386 - fscache_stat(&fscache_n_retrievals_intr);
45387 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45388 _leave(" = -ERESTARTSYS");
45389 return -ERESTARTSYS;
45390 }
45391 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45392 */
45393 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45394 struct fscache_retrieval *op,
45395 - atomic_t *stat_op_waits,
45396 - atomic_t *stat_object_dead)
45397 + atomic_unchecked_t *stat_op_waits,
45398 + atomic_unchecked_t *stat_object_dead)
45399 {
45400 int ret;
45401
45402 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45403 goto check_if_dead;
45404
45405 _debug(">>> WT");
45406 - fscache_stat(stat_op_waits);
45407 + fscache_stat_unchecked(stat_op_waits);
45408 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
45409 fscache_wait_bit_interruptible,
45410 TASK_INTERRUPTIBLE) < 0) {
45411 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45412
45413 check_if_dead:
45414 if (unlikely(fscache_object_is_dead(object))) {
45415 - fscache_stat(stat_object_dead);
45416 + fscache_stat_unchecked(stat_object_dead);
45417 return -ENOBUFS;
45418 }
45419 return 0;
45420 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45421
45422 _enter("%p,%p,,,", cookie, page);
45423
45424 - fscache_stat(&fscache_n_retrievals);
45425 + fscache_stat_unchecked(&fscache_n_retrievals);
45426
45427 if (hlist_empty(&cookie->backing_objects))
45428 goto nobufs;
45429 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45430 goto nobufs_unlock;
45431 spin_unlock(&cookie->lock);
45432
45433 - fscache_stat(&fscache_n_retrieval_ops);
45434 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
45435
45436 /* pin the netfs read context in case we need to do the actual netfs
45437 * read because we've encountered a cache read failure */
45438 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45439
45440 error:
45441 if (ret == -ENOMEM)
45442 - fscache_stat(&fscache_n_retrievals_nomem);
45443 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45444 else if (ret == -ERESTARTSYS)
45445 - fscache_stat(&fscache_n_retrievals_intr);
45446 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45447 else if (ret == -ENODATA)
45448 - fscache_stat(&fscache_n_retrievals_nodata);
45449 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
45450 else if (ret < 0)
45451 - fscache_stat(&fscache_n_retrievals_nobufs);
45452 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45453 else
45454 - fscache_stat(&fscache_n_retrievals_ok);
45455 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
45456
45457 fscache_put_retrieval(op);
45458 _leave(" = %d", ret);
45459 @@ -429,7 +429,7 @@ nobufs_unlock:
45460 spin_unlock(&cookie->lock);
45461 kfree(op);
45462 nobufs:
45463 - fscache_stat(&fscache_n_retrievals_nobufs);
45464 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45465 _leave(" = -ENOBUFS");
45466 return -ENOBUFS;
45467 }
45468 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45469
45470 _enter("%p,,%d,,,", cookie, *nr_pages);
45471
45472 - fscache_stat(&fscache_n_retrievals);
45473 + fscache_stat_unchecked(&fscache_n_retrievals);
45474
45475 if (hlist_empty(&cookie->backing_objects))
45476 goto nobufs;
45477 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45478 goto nobufs_unlock;
45479 spin_unlock(&cookie->lock);
45480
45481 - fscache_stat(&fscache_n_retrieval_ops);
45482 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
45483
45484 /* pin the netfs read context in case we need to do the actual netfs
45485 * read because we've encountered a cache read failure */
45486 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45487
45488 error:
45489 if (ret == -ENOMEM)
45490 - fscache_stat(&fscache_n_retrievals_nomem);
45491 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45492 else if (ret == -ERESTARTSYS)
45493 - fscache_stat(&fscache_n_retrievals_intr);
45494 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45495 else if (ret == -ENODATA)
45496 - fscache_stat(&fscache_n_retrievals_nodata);
45497 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
45498 else if (ret < 0)
45499 - fscache_stat(&fscache_n_retrievals_nobufs);
45500 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45501 else
45502 - fscache_stat(&fscache_n_retrievals_ok);
45503 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
45504
45505 fscache_put_retrieval(op);
45506 _leave(" = %d", ret);
45507 @@ -545,7 +545,7 @@ nobufs_unlock:
45508 spin_unlock(&cookie->lock);
45509 kfree(op);
45510 nobufs:
45511 - fscache_stat(&fscache_n_retrievals_nobufs);
45512 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45513 _leave(" = -ENOBUFS");
45514 return -ENOBUFS;
45515 }
45516 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45517
45518 _enter("%p,%p,,,", cookie, page);
45519
45520 - fscache_stat(&fscache_n_allocs);
45521 + fscache_stat_unchecked(&fscache_n_allocs);
45522
45523 if (hlist_empty(&cookie->backing_objects))
45524 goto nobufs;
45525 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45526 goto nobufs_unlock;
45527 spin_unlock(&cookie->lock);
45528
45529 - fscache_stat(&fscache_n_alloc_ops);
45530 + fscache_stat_unchecked(&fscache_n_alloc_ops);
45531
45532 ret = fscache_wait_for_retrieval_activation(
45533 object, op,
45534 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45535
45536 error:
45537 if (ret == -ERESTARTSYS)
45538 - fscache_stat(&fscache_n_allocs_intr);
45539 + fscache_stat_unchecked(&fscache_n_allocs_intr);
45540 else if (ret < 0)
45541 - fscache_stat(&fscache_n_allocs_nobufs);
45542 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
45543 else
45544 - fscache_stat(&fscache_n_allocs_ok);
45545 + fscache_stat_unchecked(&fscache_n_allocs_ok);
45546
45547 fscache_put_retrieval(op);
45548 _leave(" = %d", ret);
45549 @@ -625,7 +625,7 @@ nobufs_unlock:
45550 spin_unlock(&cookie->lock);
45551 kfree(op);
45552 nobufs:
45553 - fscache_stat(&fscache_n_allocs_nobufs);
45554 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
45555 _leave(" = -ENOBUFS");
45556 return -ENOBUFS;
45557 }
45558 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45559
45560 spin_lock(&cookie->stores_lock);
45561
45562 - fscache_stat(&fscache_n_store_calls);
45563 + fscache_stat_unchecked(&fscache_n_store_calls);
45564
45565 /* find a page to store */
45566 page = NULL;
45567 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45568 page = results[0];
45569 _debug("gang %d [%lx]", n, page->index);
45570 if (page->index > op->store_limit) {
45571 - fscache_stat(&fscache_n_store_pages_over_limit);
45572 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
45573 goto superseded;
45574 }
45575
45576 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45577 spin_unlock(&cookie->stores_lock);
45578 spin_unlock(&object->lock);
45579
45580 - fscache_stat(&fscache_n_store_pages);
45581 + fscache_stat_unchecked(&fscache_n_store_pages);
45582 fscache_stat(&fscache_n_cop_write_page);
45583 ret = object->cache->ops->write_page(op, page);
45584 fscache_stat_d(&fscache_n_cop_write_page);
45585 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45586 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45587 ASSERT(PageFsCache(page));
45588
45589 - fscache_stat(&fscache_n_stores);
45590 + fscache_stat_unchecked(&fscache_n_stores);
45591
45592 op = kzalloc(sizeof(*op), GFP_NOIO);
45593 if (!op)
45594 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45595 spin_unlock(&cookie->stores_lock);
45596 spin_unlock(&object->lock);
45597
45598 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
45599 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
45600 op->store_limit = object->store_limit;
45601
45602 if (fscache_submit_op(object, &op->op) < 0)
45603 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45604
45605 spin_unlock(&cookie->lock);
45606 radix_tree_preload_end();
45607 - fscache_stat(&fscache_n_store_ops);
45608 - fscache_stat(&fscache_n_stores_ok);
45609 + fscache_stat_unchecked(&fscache_n_store_ops);
45610 + fscache_stat_unchecked(&fscache_n_stores_ok);
45611
45612 /* the work queue now carries its own ref on the object */
45613 fscache_put_operation(&op->op);
45614 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45615 return 0;
45616
45617 already_queued:
45618 - fscache_stat(&fscache_n_stores_again);
45619 + fscache_stat_unchecked(&fscache_n_stores_again);
45620 already_pending:
45621 spin_unlock(&cookie->stores_lock);
45622 spin_unlock(&object->lock);
45623 spin_unlock(&cookie->lock);
45624 radix_tree_preload_end();
45625 kfree(op);
45626 - fscache_stat(&fscache_n_stores_ok);
45627 + fscache_stat_unchecked(&fscache_n_stores_ok);
45628 _leave(" = 0");
45629 return 0;
45630
45631 @@ -851,14 +851,14 @@ nobufs:
45632 spin_unlock(&cookie->lock);
45633 radix_tree_preload_end();
45634 kfree(op);
45635 - fscache_stat(&fscache_n_stores_nobufs);
45636 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
45637 _leave(" = -ENOBUFS");
45638 return -ENOBUFS;
45639
45640 nomem_free:
45641 kfree(op);
45642 nomem:
45643 - fscache_stat(&fscache_n_stores_oom);
45644 + fscache_stat_unchecked(&fscache_n_stores_oom);
45645 _leave(" = -ENOMEM");
45646 return -ENOMEM;
45647 }
45648 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
45649 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45650 ASSERTCMP(page, !=, NULL);
45651
45652 - fscache_stat(&fscache_n_uncaches);
45653 + fscache_stat_unchecked(&fscache_n_uncaches);
45654
45655 /* cache withdrawal may beat us to it */
45656 if (!PageFsCache(page))
45657 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
45658 unsigned long loop;
45659
45660 #ifdef CONFIG_FSCACHE_STATS
45661 - atomic_add(pagevec->nr, &fscache_n_marks);
45662 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
45663 #endif
45664
45665 for (loop = 0; loop < pagevec->nr; loop++) {
45666 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
45667 index 4765190..2a067f2 100644
45668 --- a/fs/fscache/stats.c
45669 +++ b/fs/fscache/stats.c
45670 @@ -18,95 +18,95 @@
45671 /*
45672 * operation counters
45673 */
45674 -atomic_t fscache_n_op_pend;
45675 -atomic_t fscache_n_op_run;
45676 -atomic_t fscache_n_op_enqueue;
45677 -atomic_t fscache_n_op_requeue;
45678 -atomic_t fscache_n_op_deferred_release;
45679 -atomic_t fscache_n_op_release;
45680 -atomic_t fscache_n_op_gc;
45681 -atomic_t fscache_n_op_cancelled;
45682 -atomic_t fscache_n_op_rejected;
45683 +atomic_unchecked_t fscache_n_op_pend;
45684 +atomic_unchecked_t fscache_n_op_run;
45685 +atomic_unchecked_t fscache_n_op_enqueue;
45686 +atomic_unchecked_t fscache_n_op_requeue;
45687 +atomic_unchecked_t fscache_n_op_deferred_release;
45688 +atomic_unchecked_t fscache_n_op_release;
45689 +atomic_unchecked_t fscache_n_op_gc;
45690 +atomic_unchecked_t fscache_n_op_cancelled;
45691 +atomic_unchecked_t fscache_n_op_rejected;
45692
45693 -atomic_t fscache_n_attr_changed;
45694 -atomic_t fscache_n_attr_changed_ok;
45695 -atomic_t fscache_n_attr_changed_nobufs;
45696 -atomic_t fscache_n_attr_changed_nomem;
45697 -atomic_t fscache_n_attr_changed_calls;
45698 +atomic_unchecked_t fscache_n_attr_changed;
45699 +atomic_unchecked_t fscache_n_attr_changed_ok;
45700 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
45701 +atomic_unchecked_t fscache_n_attr_changed_nomem;
45702 +atomic_unchecked_t fscache_n_attr_changed_calls;
45703
45704 -atomic_t fscache_n_allocs;
45705 -atomic_t fscache_n_allocs_ok;
45706 -atomic_t fscache_n_allocs_wait;
45707 -atomic_t fscache_n_allocs_nobufs;
45708 -atomic_t fscache_n_allocs_intr;
45709 -atomic_t fscache_n_allocs_object_dead;
45710 -atomic_t fscache_n_alloc_ops;
45711 -atomic_t fscache_n_alloc_op_waits;
45712 +atomic_unchecked_t fscache_n_allocs;
45713 +atomic_unchecked_t fscache_n_allocs_ok;
45714 +atomic_unchecked_t fscache_n_allocs_wait;
45715 +atomic_unchecked_t fscache_n_allocs_nobufs;
45716 +atomic_unchecked_t fscache_n_allocs_intr;
45717 +atomic_unchecked_t fscache_n_allocs_object_dead;
45718 +atomic_unchecked_t fscache_n_alloc_ops;
45719 +atomic_unchecked_t fscache_n_alloc_op_waits;
45720
45721 -atomic_t fscache_n_retrievals;
45722 -atomic_t fscache_n_retrievals_ok;
45723 -atomic_t fscache_n_retrievals_wait;
45724 -atomic_t fscache_n_retrievals_nodata;
45725 -atomic_t fscache_n_retrievals_nobufs;
45726 -atomic_t fscache_n_retrievals_intr;
45727 -atomic_t fscache_n_retrievals_nomem;
45728 -atomic_t fscache_n_retrievals_object_dead;
45729 -atomic_t fscache_n_retrieval_ops;
45730 -atomic_t fscache_n_retrieval_op_waits;
45731 +atomic_unchecked_t fscache_n_retrievals;
45732 +atomic_unchecked_t fscache_n_retrievals_ok;
45733 +atomic_unchecked_t fscache_n_retrievals_wait;
45734 +atomic_unchecked_t fscache_n_retrievals_nodata;
45735 +atomic_unchecked_t fscache_n_retrievals_nobufs;
45736 +atomic_unchecked_t fscache_n_retrievals_intr;
45737 +atomic_unchecked_t fscache_n_retrievals_nomem;
45738 +atomic_unchecked_t fscache_n_retrievals_object_dead;
45739 +atomic_unchecked_t fscache_n_retrieval_ops;
45740 +atomic_unchecked_t fscache_n_retrieval_op_waits;
45741
45742 -atomic_t fscache_n_stores;
45743 -atomic_t fscache_n_stores_ok;
45744 -atomic_t fscache_n_stores_again;
45745 -atomic_t fscache_n_stores_nobufs;
45746 -atomic_t fscache_n_stores_oom;
45747 -atomic_t fscache_n_store_ops;
45748 -atomic_t fscache_n_store_calls;
45749 -atomic_t fscache_n_store_pages;
45750 -atomic_t fscache_n_store_radix_deletes;
45751 -atomic_t fscache_n_store_pages_over_limit;
45752 +atomic_unchecked_t fscache_n_stores;
45753 +atomic_unchecked_t fscache_n_stores_ok;
45754 +atomic_unchecked_t fscache_n_stores_again;
45755 +atomic_unchecked_t fscache_n_stores_nobufs;
45756 +atomic_unchecked_t fscache_n_stores_oom;
45757 +atomic_unchecked_t fscache_n_store_ops;
45758 +atomic_unchecked_t fscache_n_store_calls;
45759 +atomic_unchecked_t fscache_n_store_pages;
45760 +atomic_unchecked_t fscache_n_store_radix_deletes;
45761 +atomic_unchecked_t fscache_n_store_pages_over_limit;
45762
45763 -atomic_t fscache_n_store_vmscan_not_storing;
45764 -atomic_t fscache_n_store_vmscan_gone;
45765 -atomic_t fscache_n_store_vmscan_busy;
45766 -atomic_t fscache_n_store_vmscan_cancelled;
45767 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45768 +atomic_unchecked_t fscache_n_store_vmscan_gone;
45769 +atomic_unchecked_t fscache_n_store_vmscan_busy;
45770 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45771
45772 -atomic_t fscache_n_marks;
45773 -atomic_t fscache_n_uncaches;
45774 +atomic_unchecked_t fscache_n_marks;
45775 +atomic_unchecked_t fscache_n_uncaches;
45776
45777 -atomic_t fscache_n_acquires;
45778 -atomic_t fscache_n_acquires_null;
45779 -atomic_t fscache_n_acquires_no_cache;
45780 -atomic_t fscache_n_acquires_ok;
45781 -atomic_t fscache_n_acquires_nobufs;
45782 -atomic_t fscache_n_acquires_oom;
45783 +atomic_unchecked_t fscache_n_acquires;
45784 +atomic_unchecked_t fscache_n_acquires_null;
45785 +atomic_unchecked_t fscache_n_acquires_no_cache;
45786 +atomic_unchecked_t fscache_n_acquires_ok;
45787 +atomic_unchecked_t fscache_n_acquires_nobufs;
45788 +atomic_unchecked_t fscache_n_acquires_oom;
45789
45790 -atomic_t fscache_n_updates;
45791 -atomic_t fscache_n_updates_null;
45792 -atomic_t fscache_n_updates_run;
45793 +atomic_unchecked_t fscache_n_updates;
45794 +atomic_unchecked_t fscache_n_updates_null;
45795 +atomic_unchecked_t fscache_n_updates_run;
45796
45797 -atomic_t fscache_n_relinquishes;
45798 -atomic_t fscache_n_relinquishes_null;
45799 -atomic_t fscache_n_relinquishes_waitcrt;
45800 -atomic_t fscache_n_relinquishes_retire;
45801 +atomic_unchecked_t fscache_n_relinquishes;
45802 +atomic_unchecked_t fscache_n_relinquishes_null;
45803 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45804 +atomic_unchecked_t fscache_n_relinquishes_retire;
45805
45806 -atomic_t fscache_n_cookie_index;
45807 -atomic_t fscache_n_cookie_data;
45808 -atomic_t fscache_n_cookie_special;
45809 +atomic_unchecked_t fscache_n_cookie_index;
45810 +atomic_unchecked_t fscache_n_cookie_data;
45811 +atomic_unchecked_t fscache_n_cookie_special;
45812
45813 -atomic_t fscache_n_object_alloc;
45814 -atomic_t fscache_n_object_no_alloc;
45815 -atomic_t fscache_n_object_lookups;
45816 -atomic_t fscache_n_object_lookups_negative;
45817 -atomic_t fscache_n_object_lookups_positive;
45818 -atomic_t fscache_n_object_lookups_timed_out;
45819 -atomic_t fscache_n_object_created;
45820 -atomic_t fscache_n_object_avail;
45821 -atomic_t fscache_n_object_dead;
45822 +atomic_unchecked_t fscache_n_object_alloc;
45823 +atomic_unchecked_t fscache_n_object_no_alloc;
45824 +atomic_unchecked_t fscache_n_object_lookups;
45825 +atomic_unchecked_t fscache_n_object_lookups_negative;
45826 +atomic_unchecked_t fscache_n_object_lookups_positive;
45827 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
45828 +atomic_unchecked_t fscache_n_object_created;
45829 +atomic_unchecked_t fscache_n_object_avail;
45830 +atomic_unchecked_t fscache_n_object_dead;
45831
45832 -atomic_t fscache_n_checkaux_none;
45833 -atomic_t fscache_n_checkaux_okay;
45834 -atomic_t fscache_n_checkaux_update;
45835 -atomic_t fscache_n_checkaux_obsolete;
45836 +atomic_unchecked_t fscache_n_checkaux_none;
45837 +atomic_unchecked_t fscache_n_checkaux_okay;
45838 +atomic_unchecked_t fscache_n_checkaux_update;
45839 +atomic_unchecked_t fscache_n_checkaux_obsolete;
45840
45841 atomic_t fscache_n_cop_alloc_object;
45842 atomic_t fscache_n_cop_lookup_object;
45843 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
45844 seq_puts(m, "FS-Cache statistics\n");
45845
45846 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
45847 - atomic_read(&fscache_n_cookie_index),
45848 - atomic_read(&fscache_n_cookie_data),
45849 - atomic_read(&fscache_n_cookie_special));
45850 + atomic_read_unchecked(&fscache_n_cookie_index),
45851 + atomic_read_unchecked(&fscache_n_cookie_data),
45852 + atomic_read_unchecked(&fscache_n_cookie_special));
45853
45854 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
45855 - atomic_read(&fscache_n_object_alloc),
45856 - atomic_read(&fscache_n_object_no_alloc),
45857 - atomic_read(&fscache_n_object_avail),
45858 - atomic_read(&fscache_n_object_dead));
45859 + atomic_read_unchecked(&fscache_n_object_alloc),
45860 + atomic_read_unchecked(&fscache_n_object_no_alloc),
45861 + atomic_read_unchecked(&fscache_n_object_avail),
45862 + atomic_read_unchecked(&fscache_n_object_dead));
45863 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
45864 - atomic_read(&fscache_n_checkaux_none),
45865 - atomic_read(&fscache_n_checkaux_okay),
45866 - atomic_read(&fscache_n_checkaux_update),
45867 - atomic_read(&fscache_n_checkaux_obsolete));
45868 + atomic_read_unchecked(&fscache_n_checkaux_none),
45869 + atomic_read_unchecked(&fscache_n_checkaux_okay),
45870 + atomic_read_unchecked(&fscache_n_checkaux_update),
45871 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
45872
45873 seq_printf(m, "Pages : mrk=%u unc=%u\n",
45874 - atomic_read(&fscache_n_marks),
45875 - atomic_read(&fscache_n_uncaches));
45876 + atomic_read_unchecked(&fscache_n_marks),
45877 + atomic_read_unchecked(&fscache_n_uncaches));
45878
45879 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
45880 " oom=%u\n",
45881 - atomic_read(&fscache_n_acquires),
45882 - atomic_read(&fscache_n_acquires_null),
45883 - atomic_read(&fscache_n_acquires_no_cache),
45884 - atomic_read(&fscache_n_acquires_ok),
45885 - atomic_read(&fscache_n_acquires_nobufs),
45886 - atomic_read(&fscache_n_acquires_oom));
45887 + atomic_read_unchecked(&fscache_n_acquires),
45888 + atomic_read_unchecked(&fscache_n_acquires_null),
45889 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
45890 + atomic_read_unchecked(&fscache_n_acquires_ok),
45891 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
45892 + atomic_read_unchecked(&fscache_n_acquires_oom));
45893
45894 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
45895 - atomic_read(&fscache_n_object_lookups),
45896 - atomic_read(&fscache_n_object_lookups_negative),
45897 - atomic_read(&fscache_n_object_lookups_positive),
45898 - atomic_read(&fscache_n_object_created),
45899 - atomic_read(&fscache_n_object_lookups_timed_out));
45900 + atomic_read_unchecked(&fscache_n_object_lookups),
45901 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
45902 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
45903 + atomic_read_unchecked(&fscache_n_object_created),
45904 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
45905
45906 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
45907 - atomic_read(&fscache_n_updates),
45908 - atomic_read(&fscache_n_updates_null),
45909 - atomic_read(&fscache_n_updates_run));
45910 + atomic_read_unchecked(&fscache_n_updates),
45911 + atomic_read_unchecked(&fscache_n_updates_null),
45912 + atomic_read_unchecked(&fscache_n_updates_run));
45913
45914 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
45915 - atomic_read(&fscache_n_relinquishes),
45916 - atomic_read(&fscache_n_relinquishes_null),
45917 - atomic_read(&fscache_n_relinquishes_waitcrt),
45918 - atomic_read(&fscache_n_relinquishes_retire));
45919 + atomic_read_unchecked(&fscache_n_relinquishes),
45920 + atomic_read_unchecked(&fscache_n_relinquishes_null),
45921 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
45922 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
45923
45924 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
45925 - atomic_read(&fscache_n_attr_changed),
45926 - atomic_read(&fscache_n_attr_changed_ok),
45927 - atomic_read(&fscache_n_attr_changed_nobufs),
45928 - atomic_read(&fscache_n_attr_changed_nomem),
45929 - atomic_read(&fscache_n_attr_changed_calls));
45930 + atomic_read_unchecked(&fscache_n_attr_changed),
45931 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
45932 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
45933 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
45934 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
45935
45936 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
45937 - atomic_read(&fscache_n_allocs),
45938 - atomic_read(&fscache_n_allocs_ok),
45939 - atomic_read(&fscache_n_allocs_wait),
45940 - atomic_read(&fscache_n_allocs_nobufs),
45941 - atomic_read(&fscache_n_allocs_intr));
45942 + atomic_read_unchecked(&fscache_n_allocs),
45943 + atomic_read_unchecked(&fscache_n_allocs_ok),
45944 + atomic_read_unchecked(&fscache_n_allocs_wait),
45945 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
45946 + atomic_read_unchecked(&fscache_n_allocs_intr));
45947 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
45948 - atomic_read(&fscache_n_alloc_ops),
45949 - atomic_read(&fscache_n_alloc_op_waits),
45950 - atomic_read(&fscache_n_allocs_object_dead));
45951 + atomic_read_unchecked(&fscache_n_alloc_ops),
45952 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
45953 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
45954
45955 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
45956 " int=%u oom=%u\n",
45957 - atomic_read(&fscache_n_retrievals),
45958 - atomic_read(&fscache_n_retrievals_ok),
45959 - atomic_read(&fscache_n_retrievals_wait),
45960 - atomic_read(&fscache_n_retrievals_nodata),
45961 - atomic_read(&fscache_n_retrievals_nobufs),
45962 - atomic_read(&fscache_n_retrievals_intr),
45963 - atomic_read(&fscache_n_retrievals_nomem));
45964 + atomic_read_unchecked(&fscache_n_retrievals),
45965 + atomic_read_unchecked(&fscache_n_retrievals_ok),
45966 + atomic_read_unchecked(&fscache_n_retrievals_wait),
45967 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
45968 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
45969 + atomic_read_unchecked(&fscache_n_retrievals_intr),
45970 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
45971 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
45972 - atomic_read(&fscache_n_retrieval_ops),
45973 - atomic_read(&fscache_n_retrieval_op_waits),
45974 - atomic_read(&fscache_n_retrievals_object_dead));
45975 + atomic_read_unchecked(&fscache_n_retrieval_ops),
45976 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
45977 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
45978
45979 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
45980 - atomic_read(&fscache_n_stores),
45981 - atomic_read(&fscache_n_stores_ok),
45982 - atomic_read(&fscache_n_stores_again),
45983 - atomic_read(&fscache_n_stores_nobufs),
45984 - atomic_read(&fscache_n_stores_oom));
45985 + atomic_read_unchecked(&fscache_n_stores),
45986 + atomic_read_unchecked(&fscache_n_stores_ok),
45987 + atomic_read_unchecked(&fscache_n_stores_again),
45988 + atomic_read_unchecked(&fscache_n_stores_nobufs),
45989 + atomic_read_unchecked(&fscache_n_stores_oom));
45990 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
45991 - atomic_read(&fscache_n_store_ops),
45992 - atomic_read(&fscache_n_store_calls),
45993 - atomic_read(&fscache_n_store_pages),
45994 - atomic_read(&fscache_n_store_radix_deletes),
45995 - atomic_read(&fscache_n_store_pages_over_limit));
45996 + atomic_read_unchecked(&fscache_n_store_ops),
45997 + atomic_read_unchecked(&fscache_n_store_calls),
45998 + atomic_read_unchecked(&fscache_n_store_pages),
45999 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
46000 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
46001
46002 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
46003 - atomic_read(&fscache_n_store_vmscan_not_storing),
46004 - atomic_read(&fscache_n_store_vmscan_gone),
46005 - atomic_read(&fscache_n_store_vmscan_busy),
46006 - atomic_read(&fscache_n_store_vmscan_cancelled));
46007 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
46008 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
46009 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
46010 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
46011
46012 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
46013 - atomic_read(&fscache_n_op_pend),
46014 - atomic_read(&fscache_n_op_run),
46015 - atomic_read(&fscache_n_op_enqueue),
46016 - atomic_read(&fscache_n_op_cancelled),
46017 - atomic_read(&fscache_n_op_rejected));
46018 + atomic_read_unchecked(&fscache_n_op_pend),
46019 + atomic_read_unchecked(&fscache_n_op_run),
46020 + atomic_read_unchecked(&fscache_n_op_enqueue),
46021 + atomic_read_unchecked(&fscache_n_op_cancelled),
46022 + atomic_read_unchecked(&fscache_n_op_rejected));
46023 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
46024 - atomic_read(&fscache_n_op_deferred_release),
46025 - atomic_read(&fscache_n_op_release),
46026 - atomic_read(&fscache_n_op_gc));
46027 + atomic_read_unchecked(&fscache_n_op_deferred_release),
46028 + atomic_read_unchecked(&fscache_n_op_release),
46029 + atomic_read_unchecked(&fscache_n_op_gc));
46030
46031 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
46032 atomic_read(&fscache_n_cop_alloc_object),
46033 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
46034 index 3426521..3b75162 100644
46035 --- a/fs/fuse/cuse.c
46036 +++ b/fs/fuse/cuse.c
46037 @@ -587,10 +587,12 @@ static int __init cuse_init(void)
46038 INIT_LIST_HEAD(&cuse_conntbl[i]);
46039
46040 /* inherit and extend fuse_dev_operations */
46041 - cuse_channel_fops = fuse_dev_operations;
46042 - cuse_channel_fops.owner = THIS_MODULE;
46043 - cuse_channel_fops.open = cuse_channel_open;
46044 - cuse_channel_fops.release = cuse_channel_release;
46045 + pax_open_kernel();
46046 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
46047 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
46048 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
46049 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
46050 + pax_close_kernel();
46051
46052 cuse_class = class_create(THIS_MODULE, "cuse");
46053 if (IS_ERR(cuse_class))
46054 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
46055 index 7df2b5e..5804aa7 100644
46056 --- a/fs/fuse/dev.c
46057 +++ b/fs/fuse/dev.c
46058 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
46059 ret = 0;
46060 pipe_lock(pipe);
46061
46062 - if (!pipe->readers) {
46063 + if (!atomic_read(&pipe->readers)) {
46064 send_sig(SIGPIPE, current, 0);
46065 if (!ret)
46066 ret = -EPIPE;
46067 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
46068 index bc43832..0cfe5a6 100644
46069 --- a/fs/fuse/dir.c
46070 +++ b/fs/fuse/dir.c
46071 @@ -1181,7 +1181,7 @@ static char *read_link(struct dentry *dentry)
46072 return link;
46073 }
46074
46075 -static void free_link(char *link)
46076 +static void free_link(const char *link)
46077 {
46078 if (!IS_ERR(link))
46079 free_page((unsigned long) link);
46080 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
46081 index a9ba244..d9df391 100644
46082 --- a/fs/gfs2/inode.c
46083 +++ b/fs/gfs2/inode.c
46084 @@ -1496,7 +1496,7 @@ out:
46085
46086 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46087 {
46088 - char *s = nd_get_link(nd);
46089 + const char *s = nd_get_link(nd);
46090 if (!IS_ERR(s))
46091 kfree(s);
46092 }
46093 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
46094 index 001ef01..f7d5f07 100644
46095 --- a/fs/hugetlbfs/inode.c
46096 +++ b/fs/hugetlbfs/inode.c
46097 @@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
46098 .kill_sb = kill_litter_super,
46099 };
46100
46101 -static struct vfsmount *hugetlbfs_vfsmount;
46102 +struct vfsmount *hugetlbfs_vfsmount;
46103
46104 static int can_do_hugetlb_shm(void)
46105 {
46106 diff --git a/fs/inode.c b/fs/inode.c
46107 index 9f4f5fe..6214688 100644
46108 --- a/fs/inode.c
46109 +++ b/fs/inode.c
46110 @@ -860,8 +860,8 @@ unsigned int get_next_ino(void)
46111
46112 #ifdef CONFIG_SMP
46113 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
46114 - static atomic_t shared_last_ino;
46115 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
46116 + static atomic_unchecked_t shared_last_ino;
46117 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
46118
46119 res = next - LAST_INO_BATCH;
46120 }
46121 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
46122 index 4a6cf28..d3a29d3 100644
46123 --- a/fs/jffs2/erase.c
46124 +++ b/fs/jffs2/erase.c
46125 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
46126 struct jffs2_unknown_node marker = {
46127 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
46128 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46129 - .totlen = cpu_to_je32(c->cleanmarker_size)
46130 + .totlen = cpu_to_je32(c->cleanmarker_size),
46131 + .hdr_crc = cpu_to_je32(0)
46132 };
46133
46134 jffs2_prealloc_raw_node_refs(c, jeb, 1);
46135 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
46136 index 74d9be1..d5dd140 100644
46137 --- a/fs/jffs2/wbuf.c
46138 +++ b/fs/jffs2/wbuf.c
46139 @@ -1022,7 +1022,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
46140 {
46141 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
46142 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46143 - .totlen = constant_cpu_to_je32(8)
46144 + .totlen = constant_cpu_to_je32(8),
46145 + .hdr_crc = constant_cpu_to_je32(0)
46146 };
46147
46148 /*
46149 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
46150 index 4a82950..bcaa0cb 100644
46151 --- a/fs/jfs/super.c
46152 +++ b/fs/jfs/super.c
46153 @@ -801,7 +801,7 @@ static int __init init_jfs_fs(void)
46154
46155 jfs_inode_cachep =
46156 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
46157 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
46158 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
46159 init_once);
46160 if (jfs_inode_cachep == NULL)
46161 return -ENOMEM;
46162 diff --git a/fs/libfs.c b/fs/libfs.c
46163 index 18d08f5..fe3dc64 100644
46164 --- a/fs/libfs.c
46165 +++ b/fs/libfs.c
46166 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46167
46168 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
46169 struct dentry *next;
46170 + char d_name[sizeof(next->d_iname)];
46171 + const unsigned char *name;
46172 +
46173 next = list_entry(p, struct dentry, d_u.d_child);
46174 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
46175 if (!simple_positive(next)) {
46176 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46177
46178 spin_unlock(&next->d_lock);
46179 spin_unlock(&dentry->d_lock);
46180 - if (filldir(dirent, next->d_name.name,
46181 + name = next->d_name.name;
46182 + if (name == next->d_iname) {
46183 + memcpy(d_name, name, next->d_name.len);
46184 + name = d_name;
46185 + }
46186 + if (filldir(dirent, name,
46187 next->d_name.len, filp->f_pos,
46188 next->d_inode->i_ino,
46189 dt_type(next->d_inode)) < 0)
46190 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
46191 index 8392cb8..80d6193 100644
46192 --- a/fs/lockd/clntproc.c
46193 +++ b/fs/lockd/clntproc.c
46194 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
46195 /*
46196 * Cookie counter for NLM requests
46197 */
46198 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
46199 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
46200
46201 void nlmclnt_next_cookie(struct nlm_cookie *c)
46202 {
46203 - u32 cookie = atomic_inc_return(&nlm_cookie);
46204 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
46205
46206 memcpy(c->data, &cookie, 4);
46207 c->len=4;
46208 diff --git a/fs/locks.c b/fs/locks.c
46209 index 0d68f1f..f216b79 100644
46210 --- a/fs/locks.c
46211 +++ b/fs/locks.c
46212 @@ -2075,16 +2075,16 @@ void locks_remove_flock(struct file *filp)
46213 return;
46214
46215 if (filp->f_op && filp->f_op->flock) {
46216 - struct file_lock fl = {
46217 + struct file_lock flock = {
46218 .fl_pid = current->tgid,
46219 .fl_file = filp,
46220 .fl_flags = FL_FLOCK,
46221 .fl_type = F_UNLCK,
46222 .fl_end = OFFSET_MAX,
46223 };
46224 - filp->f_op->flock(filp, F_SETLKW, &fl);
46225 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
46226 - fl.fl_ops->fl_release_private(&fl);
46227 + filp->f_op->flock(filp, F_SETLKW, &flock);
46228 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
46229 + flock.fl_ops->fl_release_private(&flock);
46230 }
46231
46232 lock_flocks();
46233 diff --git a/fs/namei.c b/fs/namei.c
46234 index c427919..232326c 100644
46235 --- a/fs/namei.c
46236 +++ b/fs/namei.c
46237 @@ -278,16 +278,32 @@ int generic_permission(struct inode *inode, int mask)
46238 if (ret != -EACCES)
46239 return ret;
46240
46241 +#ifdef CONFIG_GRKERNSEC
46242 + /* we'll block if we have to log due to a denied capability use */
46243 + if (mask & MAY_NOT_BLOCK)
46244 + return -ECHILD;
46245 +#endif
46246 +
46247 if (S_ISDIR(inode->i_mode)) {
46248 /* DACs are overridable for directories */
46249 - if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46250 - return 0;
46251 if (!(mask & MAY_WRITE))
46252 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46253 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
46254 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46255 return 0;
46256 + if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46257 + return 0;
46258 return -EACCES;
46259 }
46260 /*
46261 + * Searching includes executable on directories, else just read.
46262 + */
46263 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
46264 + if (mask == MAY_READ)
46265 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
46266 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46267 + return 0;
46268 +
46269 + /*
46270 * Read/write DACs are always overridable.
46271 * Executable DACs are overridable when there is
46272 * at least one exec bit set.
46273 @@ -296,14 +312,6 @@ int generic_permission(struct inode *inode, int mask)
46274 if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46275 return 0;
46276
46277 - /*
46278 - * Searching includes executable on directories, else just read.
46279 - */
46280 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
46281 - if (mask == MAY_READ)
46282 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46283 - return 0;
46284 -
46285 return -EACCES;
46286 }
46287
46288 @@ -652,11 +660,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
46289 return error;
46290 }
46291
46292 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
46293 + dentry->d_inode, dentry, nd->path.mnt)) {
46294 + error = -EACCES;
46295 + *p = ERR_PTR(error); /* no ->put_link(), please */
46296 + path_put(&nd->path);
46297 + return error;
46298 + }
46299 +
46300 nd->last_type = LAST_BIND;
46301 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
46302 error = PTR_ERR(*p);
46303 if (!IS_ERR(*p)) {
46304 - char *s = nd_get_link(nd);
46305 + const char *s = nd_get_link(nd);
46306 error = 0;
46307 if (s)
46308 error = __vfs_follow_link(nd, s);
46309 @@ -1355,6 +1371,9 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
46310 if (!res)
46311 res = walk_component(nd, path, &nd->last,
46312 nd->last_type, LOOKUP_FOLLOW);
46313 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode)) {
46314 + res = -EACCES;
46315 + }
46316 put_link(nd, &link, cookie);
46317 } while (res > 0);
46318
46319 @@ -1746,6 +1765,9 @@ static int path_lookupat(int dfd, const char *name,
46320 err = follow_link(&link, nd, &cookie);
46321 if (!err)
46322 err = lookup_last(nd, &path);
46323 + if (!err && gr_handle_symlink_owner(&link, nd->inode)) {
46324 + err = -EACCES;
46325 + }
46326 put_link(nd, &link, cookie);
46327 }
46328 }
46329 @@ -1753,6 +1775,21 @@ static int path_lookupat(int dfd, const char *name,
46330 if (!err)
46331 err = complete_walk(nd);
46332
46333 + if (!(nd->flags & LOOKUP_PARENT)) {
46334 +#ifdef CONFIG_GRKERNSEC
46335 + if (flags & LOOKUP_RCU) {
46336 + if (!err)
46337 + path_put(&nd->path);
46338 + err = -ECHILD;
46339 + } else
46340 +#endif
46341 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46342 + if (!err)
46343 + path_put(&nd->path);
46344 + err = -ENOENT;
46345 + }
46346 + }
46347 +
46348 if (!err && nd->flags & LOOKUP_DIRECTORY) {
46349 if (!nd->inode->i_op->lookup) {
46350 path_put(&nd->path);
46351 @@ -1780,6 +1817,15 @@ static int do_path_lookup(int dfd, const char *name,
46352 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
46353
46354 if (likely(!retval)) {
46355 + if (*name != '/' && nd->path.dentry && nd->inode) {
46356 +#ifdef CONFIG_GRKERNSEC
46357 + if (flags & LOOKUP_RCU)
46358 + return -ECHILD;
46359 +#endif
46360 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
46361 + return -ENOENT;
46362 + }
46363 +
46364 if (unlikely(!audit_dummy_context())) {
46365 if (nd->path.dentry && nd->inode)
46366 audit_inode(name, nd->path.dentry);
46367 @@ -2126,6 +2172,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
46368 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
46369 return -EPERM;
46370
46371 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
46372 + return -EPERM;
46373 + if (gr_handle_rawio(inode))
46374 + return -EPERM;
46375 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
46376 + return -EACCES;
46377 +
46378 return 0;
46379 }
46380
46381 @@ -2187,6 +2240,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46382 error = complete_walk(nd);
46383 if (error)
46384 return ERR_PTR(error);
46385 +#ifdef CONFIG_GRKERNSEC
46386 + if (nd->flags & LOOKUP_RCU) {
46387 + error = -ECHILD;
46388 + goto exit;
46389 + }
46390 +#endif
46391 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46392 + error = -ENOENT;
46393 + goto exit;
46394 + }
46395 audit_inode(pathname, nd->path.dentry);
46396 if (open_flag & O_CREAT) {
46397 error = -EISDIR;
46398 @@ -2197,6 +2260,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46399 error = complete_walk(nd);
46400 if (error)
46401 return ERR_PTR(error);
46402 +#ifdef CONFIG_GRKERNSEC
46403 + if (nd->flags & LOOKUP_RCU) {
46404 + error = -ECHILD;
46405 + goto exit;
46406 + }
46407 +#endif
46408 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
46409 + error = -ENOENT;
46410 + goto exit;
46411 + }
46412 audit_inode(pathname, dir);
46413 goto ok;
46414 }
46415 @@ -2218,6 +2291,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46416 error = complete_walk(nd);
46417 if (error)
46418 return ERR_PTR(error);
46419 +#ifdef CONFIG_GRKERNSEC
46420 + if (nd->flags & LOOKUP_RCU) {
46421 + error = -ECHILD;
46422 + goto exit;
46423 + }
46424 +#endif
46425 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46426 + error = -ENOENT;
46427 + goto exit;
46428 + }
46429
46430 error = -ENOTDIR;
46431 if (nd->flags & LOOKUP_DIRECTORY) {
46432 @@ -2258,6 +2341,12 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46433 /* Negative dentry, just create the file */
46434 if (!dentry->d_inode) {
46435 umode_t mode = op->mode;
46436 +
46437 + if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
46438 + error = -EACCES;
46439 + goto exit_mutex_unlock;
46440 + }
46441 +
46442 if (!IS_POSIXACL(dir->d_inode))
46443 mode &= ~current_umask();
46444 /*
46445 @@ -2281,6 +2370,8 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46446 error = vfs_create(dir->d_inode, dentry, mode, nd);
46447 if (error)
46448 goto exit_mutex_unlock;
46449 + else
46450 + gr_handle_create(path->dentry, path->mnt);
46451 mutex_unlock(&dir->d_inode->i_mutex);
46452 dput(nd->path.dentry);
46453 nd->path.dentry = dentry;
46454 @@ -2290,6 +2381,19 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46455 /*
46456 * It already exists.
46457 */
46458 +
46459 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
46460 + error = -ENOENT;
46461 + goto exit_mutex_unlock;
46462 + }
46463 +
46464 + /* only check if O_CREAT is specified, all other checks need to go
46465 + into may_open */
46466 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
46467 + error = -EACCES;
46468 + goto exit_mutex_unlock;
46469 + }
46470 +
46471 mutex_unlock(&dir->d_inode->i_mutex);
46472 audit_inode(pathname, path->dentry);
46473
46474 @@ -2407,8 +2511,14 @@ static struct file *path_openat(int dfd, const char *pathname,
46475 error = follow_link(&link, nd, &cookie);
46476 if (unlikely(error))
46477 filp = ERR_PTR(error);
46478 - else
46479 + else {
46480 filp = do_last(nd, &path, op, pathname);
46481 + if (!IS_ERR(filp) && gr_handle_symlink_owner(&link, nd->inode)) {
46482 + if (filp)
46483 + fput(filp);
46484 + filp = ERR_PTR(-EACCES);
46485 + }
46486 + }
46487 put_link(nd, &link, cookie);
46488 }
46489 out:
46490 @@ -2502,6 +2612,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
46491 *path = nd.path;
46492 return dentry;
46493 eexist:
46494 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
46495 + dput(dentry);
46496 + dentry = ERR_PTR(-ENOENT);
46497 + goto fail;
46498 + }
46499 dput(dentry);
46500 dentry = ERR_PTR(-EEXIST);
46501 fail:
46502 @@ -2524,6 +2639,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
46503 }
46504 EXPORT_SYMBOL(user_path_create);
46505
46506 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
46507 +{
46508 + char *tmp = getname(pathname);
46509 + struct dentry *res;
46510 + if (IS_ERR(tmp))
46511 + return ERR_CAST(tmp);
46512 + res = kern_path_create(dfd, tmp, path, is_dir);
46513 + if (IS_ERR(res))
46514 + putname(tmp);
46515 + else
46516 + *to = tmp;
46517 + return res;
46518 +}
46519 +
46520 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
46521 {
46522 int error = may_create(dir, dentry);
46523 @@ -2591,6 +2720,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
46524 error = mnt_want_write(path.mnt);
46525 if (error)
46526 goto out_dput;
46527 +
46528 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
46529 + error = -EPERM;
46530 + goto out_drop_write;
46531 + }
46532 +
46533 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
46534 + error = -EACCES;
46535 + goto out_drop_write;
46536 + }
46537 +
46538 error = security_path_mknod(&path, dentry, mode, dev);
46539 if (error)
46540 goto out_drop_write;
46541 @@ -2608,6 +2748,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
46542 }
46543 out_drop_write:
46544 mnt_drop_write(path.mnt);
46545 +
46546 + if (!error)
46547 + gr_handle_create(dentry, path.mnt);
46548 out_dput:
46549 dput(dentry);
46550 mutex_unlock(&path.dentry->d_inode->i_mutex);
46551 @@ -2661,12 +2804,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
46552 error = mnt_want_write(path.mnt);
46553 if (error)
46554 goto out_dput;
46555 +
46556 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
46557 + error = -EACCES;
46558 + goto out_drop_write;
46559 + }
46560 +
46561 error = security_path_mkdir(&path, dentry, mode);
46562 if (error)
46563 goto out_drop_write;
46564 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
46565 out_drop_write:
46566 mnt_drop_write(path.mnt);
46567 +
46568 + if (!error)
46569 + gr_handle_create(dentry, path.mnt);
46570 out_dput:
46571 dput(dentry);
46572 mutex_unlock(&path.dentry->d_inode->i_mutex);
46573 @@ -2746,6 +2898,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
46574 char * name;
46575 struct dentry *dentry;
46576 struct nameidata nd;
46577 + ino_t saved_ino = 0;
46578 + dev_t saved_dev = 0;
46579
46580 error = user_path_parent(dfd, pathname, &nd, &name);
46581 if (error)
46582 @@ -2774,6 +2928,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
46583 error = -ENOENT;
46584 goto exit3;
46585 }
46586 +
46587 + saved_ino = dentry->d_inode->i_ino;
46588 + saved_dev = gr_get_dev_from_dentry(dentry);
46589 +
46590 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
46591 + error = -EACCES;
46592 + goto exit3;
46593 + }
46594 +
46595 error = mnt_want_write(nd.path.mnt);
46596 if (error)
46597 goto exit3;
46598 @@ -2781,6 +2944,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
46599 if (error)
46600 goto exit4;
46601 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
46602 + if (!error && (saved_dev || saved_ino))
46603 + gr_handle_delete(saved_ino, saved_dev);
46604 exit4:
46605 mnt_drop_write(nd.path.mnt);
46606 exit3:
46607 @@ -2843,6 +3008,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46608 struct dentry *dentry;
46609 struct nameidata nd;
46610 struct inode *inode = NULL;
46611 + ino_t saved_ino = 0;
46612 + dev_t saved_dev = 0;
46613
46614 error = user_path_parent(dfd, pathname, &nd, &name);
46615 if (error)
46616 @@ -2865,6 +3032,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46617 if (!inode)
46618 goto slashes;
46619 ihold(inode);
46620 +
46621 + if (inode->i_nlink <= 1) {
46622 + saved_ino = inode->i_ino;
46623 + saved_dev = gr_get_dev_from_dentry(dentry);
46624 + }
46625 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
46626 + error = -EACCES;
46627 + goto exit2;
46628 + }
46629 +
46630 error = mnt_want_write(nd.path.mnt);
46631 if (error)
46632 goto exit2;
46633 @@ -2872,6 +3049,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46634 if (error)
46635 goto exit3;
46636 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
46637 + if (!error && (saved_ino || saved_dev))
46638 + gr_handle_delete(saved_ino, saved_dev);
46639 exit3:
46640 mnt_drop_write(nd.path.mnt);
46641 exit2:
46642 @@ -2947,10 +3126,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
46643 error = mnt_want_write(path.mnt);
46644 if (error)
46645 goto out_dput;
46646 +
46647 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
46648 + error = -EACCES;
46649 + goto out_drop_write;
46650 + }
46651 +
46652 error = security_path_symlink(&path, dentry, from);
46653 if (error)
46654 goto out_drop_write;
46655 error = vfs_symlink(path.dentry->d_inode, dentry, from);
46656 + if (!error)
46657 + gr_handle_create(dentry, path.mnt);
46658 out_drop_write:
46659 mnt_drop_write(path.mnt);
46660 out_dput:
46661 @@ -3025,6 +3212,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
46662 {
46663 struct dentry *new_dentry;
46664 struct path old_path, new_path;
46665 + char *to = NULL;
46666 int how = 0;
46667 int error;
46668
46669 @@ -3048,7 +3236,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
46670 if (error)
46671 return error;
46672
46673 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
46674 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
46675 error = PTR_ERR(new_dentry);
46676 if (IS_ERR(new_dentry))
46677 goto out;
46678 @@ -3059,13 +3247,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
46679 error = mnt_want_write(new_path.mnt);
46680 if (error)
46681 goto out_dput;
46682 +
46683 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
46684 + old_path.dentry->d_inode,
46685 + old_path.dentry->d_inode->i_mode, to)) {
46686 + error = -EACCES;
46687 + goto out_drop_write;
46688 + }
46689 +
46690 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
46691 + old_path.dentry, old_path.mnt, to)) {
46692 + error = -EACCES;
46693 + goto out_drop_write;
46694 + }
46695 +
46696 error = security_path_link(old_path.dentry, &new_path, new_dentry);
46697 if (error)
46698 goto out_drop_write;
46699 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
46700 + if (!error)
46701 + gr_handle_create(new_dentry, new_path.mnt);
46702 out_drop_write:
46703 mnt_drop_write(new_path.mnt);
46704 out_dput:
46705 + putname(to);
46706 dput(new_dentry);
46707 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
46708 path_put(&new_path);
46709 @@ -3299,6 +3504,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
46710 if (new_dentry == trap)
46711 goto exit5;
46712
46713 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
46714 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
46715 + to);
46716 + if (error)
46717 + goto exit5;
46718 +
46719 error = mnt_want_write(oldnd.path.mnt);
46720 if (error)
46721 goto exit5;
46722 @@ -3308,6 +3519,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
46723 goto exit6;
46724 error = vfs_rename(old_dir->d_inode, old_dentry,
46725 new_dir->d_inode, new_dentry);
46726 + if (!error)
46727 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
46728 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
46729 exit6:
46730 mnt_drop_write(oldnd.path.mnt);
46731 exit5:
46732 @@ -3333,6 +3547,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
46733
46734 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
46735 {
46736 + char tmpbuf[64];
46737 + const char *newlink;
46738 int len;
46739
46740 len = PTR_ERR(link);
46741 @@ -3342,7 +3558,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
46742 len = strlen(link);
46743 if (len > (unsigned) buflen)
46744 len = buflen;
46745 - if (copy_to_user(buffer, link, len))
46746 +
46747 + if (len < sizeof(tmpbuf)) {
46748 + memcpy(tmpbuf, link, len);
46749 + newlink = tmpbuf;
46750 + } else
46751 + newlink = link;
46752 +
46753 + if (copy_to_user(buffer, newlink, len))
46754 len = -EFAULT;
46755 out:
46756 return len;
46757 diff --git a/fs/namespace.c b/fs/namespace.c
46758 index 4e46539..b28253c 100644
46759 --- a/fs/namespace.c
46760 +++ b/fs/namespace.c
46761 @@ -1156,6 +1156,9 @@ static int do_umount(struct mount *mnt, int flags)
46762 if (!(sb->s_flags & MS_RDONLY))
46763 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
46764 up_write(&sb->s_umount);
46765 +
46766 + gr_log_remount(mnt->mnt_devname, retval);
46767 +
46768 return retval;
46769 }
46770
46771 @@ -1175,6 +1178,9 @@ static int do_umount(struct mount *mnt, int flags)
46772 br_write_unlock(vfsmount_lock);
46773 up_write(&namespace_sem);
46774 release_mounts(&umount_list);
46775 +
46776 + gr_log_unmount(mnt->mnt_devname, retval);
46777 +
46778 return retval;
46779 }
46780
46781 @@ -2176,6 +2182,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
46782 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
46783 MS_STRICTATIME);
46784
46785 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
46786 + retval = -EPERM;
46787 + goto dput_out;
46788 + }
46789 +
46790 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
46791 + retval = -EPERM;
46792 + goto dput_out;
46793 + }
46794 +
46795 if (flags & MS_REMOUNT)
46796 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
46797 data_page);
46798 @@ -2190,6 +2206,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
46799 dev_name, data_page);
46800 dput_out:
46801 path_put(&path);
46802 +
46803 + gr_log_mount(dev_name, dir_name, retval);
46804 +
46805 return retval;
46806 }
46807
46808 @@ -2471,6 +2490,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
46809 if (error)
46810 goto out2;
46811
46812 + if (gr_handle_chroot_pivot()) {
46813 + error = -EPERM;
46814 + goto out2;
46815 + }
46816 +
46817 get_fs_root(current->fs, &root);
46818 error = lock_mount(&old);
46819 if (error)
46820 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
46821 index e8bbfa5..864f936 100644
46822 --- a/fs/nfs/inode.c
46823 +++ b/fs/nfs/inode.c
46824 @@ -152,7 +152,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
46825 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
46826 nfsi->attrtimeo_timestamp = jiffies;
46827
46828 - memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
46829 + memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
46830 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
46831 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
46832 else
46833 @@ -1005,16 +1005,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
46834 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
46835 }
46836
46837 -static atomic_long_t nfs_attr_generation_counter;
46838 +static atomic_long_unchecked_t nfs_attr_generation_counter;
46839
46840 static unsigned long nfs_read_attr_generation_counter(void)
46841 {
46842 - return atomic_long_read(&nfs_attr_generation_counter);
46843 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
46844 }
46845
46846 unsigned long nfs_inc_attr_generation_counter(void)
46847 {
46848 - return atomic_long_inc_return(&nfs_attr_generation_counter);
46849 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
46850 }
46851
46852 void nfs_fattr_init(struct nfs_fattr *fattr)
46853 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
46854 index 5686661..80a9a3a 100644
46855 --- a/fs/nfsd/vfs.c
46856 +++ b/fs/nfsd/vfs.c
46857 @@ -933,7 +933,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
46858 } else {
46859 oldfs = get_fs();
46860 set_fs(KERNEL_DS);
46861 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
46862 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
46863 set_fs(oldfs);
46864 }
46865
46866 @@ -1037,7 +1037,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
46867
46868 /* Write the data. */
46869 oldfs = get_fs(); set_fs(KERNEL_DS);
46870 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
46871 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
46872 set_fs(oldfs);
46873 if (host_err < 0)
46874 goto out_nfserr;
46875 @@ -1573,7 +1573,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
46876 */
46877
46878 oldfs = get_fs(); set_fs(KERNEL_DS);
46879 - host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
46880 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
46881 set_fs(oldfs);
46882
46883 if (host_err < 0)
46884 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
46885 index 3568c8a..e0240d8 100644
46886 --- a/fs/notify/fanotify/fanotify_user.c
46887 +++ b/fs/notify/fanotify/fanotify_user.c
46888 @@ -278,7 +278,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
46889 goto out_close_fd;
46890
46891 ret = -EFAULT;
46892 - if (copy_to_user(buf, &fanotify_event_metadata,
46893 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
46894 + copy_to_user(buf, &fanotify_event_metadata,
46895 fanotify_event_metadata.event_len))
46896 goto out_kill_access_response;
46897
46898 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
46899 index c887b13..0fdf472 100644
46900 --- a/fs/notify/notification.c
46901 +++ b/fs/notify/notification.c
46902 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
46903 * get set to 0 so it will never get 'freed'
46904 */
46905 static struct fsnotify_event *q_overflow_event;
46906 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
46907 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
46908
46909 /**
46910 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
46911 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
46912 */
46913 u32 fsnotify_get_cookie(void)
46914 {
46915 - return atomic_inc_return(&fsnotify_sync_cookie);
46916 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
46917 }
46918 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
46919
46920 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
46921 index 99e3610..02c1068 100644
46922 --- a/fs/ntfs/dir.c
46923 +++ b/fs/ntfs/dir.c
46924 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
46925 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
46926 ~(s64)(ndir->itype.index.block_size - 1)));
46927 /* Bounds checks. */
46928 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
46929 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
46930 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
46931 "inode 0x%lx or driver bug.", vdir->i_ino);
46932 goto err_out;
46933 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
46934 index 8639169..76697aa 100644
46935 --- a/fs/ntfs/file.c
46936 +++ b/fs/ntfs/file.c
46937 @@ -2229,6 +2229,6 @@ const struct inode_operations ntfs_file_inode_ops = {
46938 #endif /* NTFS_RW */
46939 };
46940
46941 -const struct file_operations ntfs_empty_file_ops = {};
46942 +const struct file_operations ntfs_empty_file_ops __read_only;
46943
46944 -const struct inode_operations ntfs_empty_inode_ops = {};
46945 +const struct inode_operations ntfs_empty_inode_ops __read_only;
46946 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
46947 index 210c352..a174f83 100644
46948 --- a/fs/ocfs2/localalloc.c
46949 +++ b/fs/ocfs2/localalloc.c
46950 @@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
46951 goto bail;
46952 }
46953
46954 - atomic_inc(&osb->alloc_stats.moves);
46955 + atomic_inc_unchecked(&osb->alloc_stats.moves);
46956
46957 bail:
46958 if (handle)
46959 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
46960 index d355e6e..578d905 100644
46961 --- a/fs/ocfs2/ocfs2.h
46962 +++ b/fs/ocfs2/ocfs2.h
46963 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
46964
46965 struct ocfs2_alloc_stats
46966 {
46967 - atomic_t moves;
46968 - atomic_t local_data;
46969 - atomic_t bitmap_data;
46970 - atomic_t bg_allocs;
46971 - atomic_t bg_extends;
46972 + atomic_unchecked_t moves;
46973 + atomic_unchecked_t local_data;
46974 + atomic_unchecked_t bitmap_data;
46975 + atomic_unchecked_t bg_allocs;
46976 + atomic_unchecked_t bg_extends;
46977 };
46978
46979 enum ocfs2_local_alloc_state
46980 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
46981 index f169da4..9112253 100644
46982 --- a/fs/ocfs2/suballoc.c
46983 +++ b/fs/ocfs2/suballoc.c
46984 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
46985 mlog_errno(status);
46986 goto bail;
46987 }
46988 - atomic_inc(&osb->alloc_stats.bg_extends);
46989 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
46990
46991 /* You should never ask for this much metadata */
46992 BUG_ON(bits_wanted >
46993 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
46994 mlog_errno(status);
46995 goto bail;
46996 }
46997 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46998 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
46999
47000 *suballoc_loc = res.sr_bg_blkno;
47001 *suballoc_bit_start = res.sr_bit_offset;
47002 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
47003 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
47004 res->sr_bits);
47005
47006 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47007 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47008
47009 BUG_ON(res->sr_bits != 1);
47010
47011 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
47012 mlog_errno(status);
47013 goto bail;
47014 }
47015 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47016 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47017
47018 BUG_ON(res.sr_bits != 1);
47019
47020 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47021 cluster_start,
47022 num_clusters);
47023 if (!status)
47024 - atomic_inc(&osb->alloc_stats.local_data);
47025 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
47026 } else {
47027 if (min_clusters > (osb->bitmap_cpg - 1)) {
47028 /* The only paths asking for contiguousness
47029 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47030 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
47031 res.sr_bg_blkno,
47032 res.sr_bit_offset);
47033 - atomic_inc(&osb->alloc_stats.bitmap_data);
47034 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
47035 *num_clusters = res.sr_bits;
47036 }
47037 }
47038 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
47039 index 68f4541..89cfe6a 100644
47040 --- a/fs/ocfs2/super.c
47041 +++ b/fs/ocfs2/super.c
47042 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
47043 "%10s => GlobalAllocs: %d LocalAllocs: %d "
47044 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
47045 "Stats",
47046 - atomic_read(&osb->alloc_stats.bitmap_data),
47047 - atomic_read(&osb->alloc_stats.local_data),
47048 - atomic_read(&osb->alloc_stats.bg_allocs),
47049 - atomic_read(&osb->alloc_stats.moves),
47050 - atomic_read(&osb->alloc_stats.bg_extends));
47051 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
47052 + atomic_read_unchecked(&osb->alloc_stats.local_data),
47053 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
47054 + atomic_read_unchecked(&osb->alloc_stats.moves),
47055 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
47056
47057 out += snprintf(buf + out, len - out,
47058 "%10s => State: %u Descriptor: %llu Size: %u bits "
47059 @@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
47060 spin_lock_init(&osb->osb_xattr_lock);
47061 ocfs2_init_steal_slots(osb);
47062
47063 - atomic_set(&osb->alloc_stats.moves, 0);
47064 - atomic_set(&osb->alloc_stats.local_data, 0);
47065 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
47066 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
47067 - atomic_set(&osb->alloc_stats.bg_extends, 0);
47068 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
47069 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
47070 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
47071 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
47072 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
47073
47074 /* Copy the blockcheck stats from the superblock probe */
47075 osb->osb_ecc_stats = *stats;
47076 diff --git a/fs/ocfs2/symlink.c b/fs/ocfs2/symlink.c
47077 index 5d22872..523db20 100644
47078 --- a/fs/ocfs2/symlink.c
47079 +++ b/fs/ocfs2/symlink.c
47080 @@ -142,7 +142,7 @@ bail:
47081
47082 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
47083 {
47084 - char *link = nd_get_link(nd);
47085 + const char *link = nd_get_link(nd);
47086 if (!IS_ERR(link))
47087 kfree(link);
47088 }
47089 diff --git a/fs/open.c b/fs/open.c
47090 index 5720854..ccfe124 100644
47091 --- a/fs/open.c
47092 +++ b/fs/open.c
47093 @@ -31,6 +31,8 @@
47094 #include <linux/ima.h>
47095 #include <linux/dnotify.h>
47096
47097 +#define CREATE_TRACE_POINTS
47098 +#include <trace/events/fs.h>
47099 #include "internal.h"
47100
47101 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
47102 @@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
47103 error = locks_verify_truncate(inode, NULL, length);
47104 if (!error)
47105 error = security_path_truncate(&path);
47106 +
47107 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
47108 + error = -EACCES;
47109 +
47110 if (!error)
47111 error = do_truncate(path.dentry, length, 0, NULL);
47112
47113 @@ -358,6 +364,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
47114 if (__mnt_is_readonly(path.mnt))
47115 res = -EROFS;
47116
47117 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
47118 + res = -EACCES;
47119 +
47120 out_path_release:
47121 path_put(&path);
47122 out:
47123 @@ -384,6 +393,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
47124 if (error)
47125 goto dput_and_out;
47126
47127 + gr_log_chdir(path.dentry, path.mnt);
47128 +
47129 set_fs_pwd(current->fs, &path);
47130
47131 dput_and_out:
47132 @@ -410,6 +421,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
47133 goto out_putf;
47134
47135 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
47136 +
47137 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
47138 + error = -EPERM;
47139 +
47140 + if (!error)
47141 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
47142 +
47143 if (!error)
47144 set_fs_pwd(current->fs, &file->f_path);
47145 out_putf:
47146 @@ -438,7 +456,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
47147 if (error)
47148 goto dput_and_out;
47149
47150 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
47151 + goto dput_and_out;
47152 +
47153 set_fs_root(current->fs, &path);
47154 +
47155 + gr_handle_chroot_chdir(&path);
47156 +
47157 error = 0;
47158 dput_and_out:
47159 path_put(&path);
47160 @@ -456,6 +480,16 @@ static int chmod_common(struct path *path, umode_t mode)
47161 if (error)
47162 return error;
47163 mutex_lock(&inode->i_mutex);
47164 +
47165 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
47166 + error = -EACCES;
47167 + goto out_unlock;
47168 + }
47169 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
47170 + error = -EACCES;
47171 + goto out_unlock;
47172 + }
47173 +
47174 error = security_path_chmod(path, mode);
47175 if (error)
47176 goto out_unlock;
47177 @@ -506,6 +540,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
47178 int error;
47179 struct iattr newattrs;
47180
47181 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
47182 + return -EACCES;
47183 +
47184 newattrs.ia_valid = ATTR_CTIME;
47185 if (user != (uid_t) -1) {
47186 newattrs.ia_valid |= ATTR_UID;
47187 @@ -987,6 +1024,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
47188 } else {
47189 fsnotify_open(f);
47190 fd_install(fd, f);
47191 + trace_do_sys_open(tmp, flags, mode);
47192 }
47193 }
47194 putname(tmp);
47195 diff --git a/fs/pipe.c b/fs/pipe.c
47196 index fec5e4a..f4210f9 100644
47197 --- a/fs/pipe.c
47198 +++ b/fs/pipe.c
47199 @@ -438,9 +438,9 @@ redo:
47200 }
47201 if (bufs) /* More to do? */
47202 continue;
47203 - if (!pipe->writers)
47204 + if (!atomic_read(&pipe->writers))
47205 break;
47206 - if (!pipe->waiting_writers) {
47207 + if (!atomic_read(&pipe->waiting_writers)) {
47208 /* syscall merging: Usually we must not sleep
47209 * if O_NONBLOCK is set, or if we got some data.
47210 * But if a writer sleeps in kernel space, then
47211 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
47212 mutex_lock(&inode->i_mutex);
47213 pipe = inode->i_pipe;
47214
47215 - if (!pipe->readers) {
47216 + if (!atomic_read(&pipe->readers)) {
47217 send_sig(SIGPIPE, current, 0);
47218 ret = -EPIPE;
47219 goto out;
47220 @@ -553,7 +553,7 @@ redo1:
47221 for (;;) {
47222 int bufs;
47223
47224 - if (!pipe->readers) {
47225 + if (!atomic_read(&pipe->readers)) {
47226 send_sig(SIGPIPE, current, 0);
47227 if (!ret)
47228 ret = -EPIPE;
47229 @@ -644,9 +644,9 @@ redo2:
47230 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
47231 do_wakeup = 0;
47232 }
47233 - pipe->waiting_writers++;
47234 + atomic_inc(&pipe->waiting_writers);
47235 pipe_wait(pipe);
47236 - pipe->waiting_writers--;
47237 + atomic_dec(&pipe->waiting_writers);
47238 }
47239 out:
47240 mutex_unlock(&inode->i_mutex);
47241 @@ -713,7 +713,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47242 mask = 0;
47243 if (filp->f_mode & FMODE_READ) {
47244 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
47245 - if (!pipe->writers && filp->f_version != pipe->w_counter)
47246 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
47247 mask |= POLLHUP;
47248 }
47249
47250 @@ -723,7 +723,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47251 * Most Unices do not set POLLERR for FIFOs but on Linux they
47252 * behave exactly like pipes for poll().
47253 */
47254 - if (!pipe->readers)
47255 + if (!atomic_read(&pipe->readers))
47256 mask |= POLLERR;
47257 }
47258
47259 @@ -737,10 +737,10 @@ pipe_release(struct inode *inode, int decr, int decw)
47260
47261 mutex_lock(&inode->i_mutex);
47262 pipe = inode->i_pipe;
47263 - pipe->readers -= decr;
47264 - pipe->writers -= decw;
47265 + atomic_sub(decr, &pipe->readers);
47266 + atomic_sub(decw, &pipe->writers);
47267
47268 - if (!pipe->readers && !pipe->writers) {
47269 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
47270 free_pipe_info(inode);
47271 } else {
47272 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
47273 @@ -830,7 +830,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
47274
47275 if (inode->i_pipe) {
47276 ret = 0;
47277 - inode->i_pipe->readers++;
47278 + atomic_inc(&inode->i_pipe->readers);
47279 }
47280
47281 mutex_unlock(&inode->i_mutex);
47282 @@ -847,7 +847,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
47283
47284 if (inode->i_pipe) {
47285 ret = 0;
47286 - inode->i_pipe->writers++;
47287 + atomic_inc(&inode->i_pipe->writers);
47288 }
47289
47290 mutex_unlock(&inode->i_mutex);
47291 @@ -865,9 +865,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
47292 if (inode->i_pipe) {
47293 ret = 0;
47294 if (filp->f_mode & FMODE_READ)
47295 - inode->i_pipe->readers++;
47296 + atomic_inc(&inode->i_pipe->readers);
47297 if (filp->f_mode & FMODE_WRITE)
47298 - inode->i_pipe->writers++;
47299 + atomic_inc(&inode->i_pipe->writers);
47300 }
47301
47302 mutex_unlock(&inode->i_mutex);
47303 @@ -959,7 +959,7 @@ void free_pipe_info(struct inode *inode)
47304 inode->i_pipe = NULL;
47305 }
47306
47307 -static struct vfsmount *pipe_mnt __read_mostly;
47308 +struct vfsmount *pipe_mnt __read_mostly;
47309
47310 /*
47311 * pipefs_dname() is called from d_path().
47312 @@ -989,7 +989,8 @@ static struct inode * get_pipe_inode(void)
47313 goto fail_iput;
47314 inode->i_pipe = pipe;
47315
47316 - pipe->readers = pipe->writers = 1;
47317 + atomic_set(&pipe->readers, 1);
47318 + atomic_set(&pipe->writers, 1);
47319 inode->i_fop = &rdwr_pipefifo_fops;
47320
47321 /*
47322 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
47323 index 15af622..0e9f4467 100644
47324 --- a/fs/proc/Kconfig
47325 +++ b/fs/proc/Kconfig
47326 @@ -30,12 +30,12 @@ config PROC_FS
47327
47328 config PROC_KCORE
47329 bool "/proc/kcore support" if !ARM
47330 - depends on PROC_FS && MMU
47331 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
47332
47333 config PROC_VMCORE
47334 bool "/proc/vmcore support"
47335 - depends on PROC_FS && CRASH_DUMP
47336 - default y
47337 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
47338 + default n
47339 help
47340 Exports the dump image of crashed kernel in ELF format.
47341
47342 @@ -59,8 +59,8 @@ config PROC_SYSCTL
47343 limited in memory.
47344
47345 config PROC_PAGE_MONITOR
47346 - default y
47347 - depends on PROC_FS && MMU
47348 + default n
47349 + depends on PROC_FS && MMU && !GRKERNSEC
47350 bool "Enable /proc page monitoring" if EXPERT
47351 help
47352 Various /proc files exist to monitor process memory utilization:
47353 diff --git a/fs/proc/array.c b/fs/proc/array.c
47354 index f9bd395..acb7847 100644
47355 --- a/fs/proc/array.c
47356 +++ b/fs/proc/array.c
47357 @@ -60,6 +60,7 @@
47358 #include <linux/tty.h>
47359 #include <linux/string.h>
47360 #include <linux/mman.h>
47361 +#include <linux/grsecurity.h>
47362 #include <linux/proc_fs.h>
47363 #include <linux/ioport.h>
47364 #include <linux/uaccess.h>
47365 @@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
47366 seq_putc(m, '\n');
47367 }
47368
47369 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47370 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
47371 +{
47372 + if (p->mm)
47373 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
47374 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
47375 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
47376 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
47377 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
47378 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
47379 + else
47380 + seq_printf(m, "PaX:\t-----\n");
47381 +}
47382 +#endif
47383 +
47384 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47385 struct pid *pid, struct task_struct *task)
47386 {
47387 @@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47388 task_cpus_allowed(m, task);
47389 cpuset_task_status_allowed(m, task);
47390 task_context_switch_counts(m, task);
47391 +
47392 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47393 + task_pax(m, task);
47394 +#endif
47395 +
47396 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
47397 + task_grsec_rbac(m, task);
47398 +#endif
47399 +
47400 return 0;
47401 }
47402
47403 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47404 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
47405 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
47406 + _mm->pax_flags & MF_PAX_SEGMEXEC))
47407 +#endif
47408 +
47409 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47410 struct pid *pid, struct task_struct *task, int whole)
47411 {
47412 @@ -378,6 +409,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47413 char tcomm[sizeof(task->comm)];
47414 unsigned long flags;
47415
47416 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47417 + if (current->exec_id != m->exec_id) {
47418 + gr_log_badprocpid("stat");
47419 + return 0;
47420 + }
47421 +#endif
47422 +
47423 state = *get_task_state(task);
47424 vsize = eip = esp = 0;
47425 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
47426 @@ -449,6 +487,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47427 gtime = task->gtime;
47428 }
47429
47430 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47431 + if (PAX_RAND_FLAGS(mm)) {
47432 + eip = 0;
47433 + esp = 0;
47434 + wchan = 0;
47435 + }
47436 +#endif
47437 +#ifdef CONFIG_GRKERNSEC_HIDESYM
47438 + wchan = 0;
47439 + eip =0;
47440 + esp =0;
47441 +#endif
47442 +
47443 /* scale priority and nice values from timeslices to -20..20 */
47444 /* to make it look like a "normal" Unix priority/nice value */
47445 priority = task_prio(task);
47446 @@ -485,9 +536,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47447 seq_put_decimal_ull(m, ' ', vsize);
47448 seq_put_decimal_ll(m, ' ', mm ? get_mm_rss(mm) : 0);
47449 seq_put_decimal_ull(m, ' ', rsslim);
47450 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47451 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
47452 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
47453 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
47454 +#else
47455 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
47456 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
47457 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
47458 +#endif
47459 seq_put_decimal_ull(m, ' ', esp);
47460 seq_put_decimal_ull(m, ' ', eip);
47461 /* The signal information here is obsolete.
47462 @@ -508,9 +565,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47463 seq_put_decimal_ull(m, ' ', delayacct_blkio_ticks(task));
47464 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
47465 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
47466 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47467 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((mm && permitted) ? mm->start_data : 0));
47468 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((mm && permitted) ? mm->end_data : 0));
47469 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((mm && permitted) ? mm->start_brk : 0));
47470 +#else
47471 seq_put_decimal_ull(m, ' ', (mm && permitted) ? mm->start_data : 0);
47472 seq_put_decimal_ull(m, ' ', (mm && permitted) ? mm->end_data : 0);
47473 seq_put_decimal_ull(m, ' ', (mm && permitted) ? mm->start_brk : 0);
47474 +#endif
47475 seq_putc(m, '\n');
47476 if (mm)
47477 mmput(mm);
47478 @@ -533,8 +596,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47479 struct pid *pid, struct task_struct *task)
47480 {
47481 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
47482 - struct mm_struct *mm = get_task_mm(task);
47483 + struct mm_struct *mm;
47484
47485 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47486 + if (current->exec_id != m->exec_id) {
47487 + gr_log_badprocpid("statm");
47488 + return 0;
47489 + }
47490 +#endif
47491 + mm = get_task_mm(task);
47492 if (mm) {
47493 size = task_statm(mm, &shared, &text, &data, &resident);
47494 mmput(mm);
47495 @@ -556,3 +626,18 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47496
47497 return 0;
47498 }
47499 +
47500 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
47501 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
47502 +{
47503 + u32 curr_ip = 0;
47504 + unsigned long flags;
47505 +
47506 + if (lock_task_sighand(task, &flags)) {
47507 + curr_ip = task->signal->curr_ip;
47508 + unlock_task_sighand(task, &flags);
47509 + }
47510 +
47511 + return sprintf(buffer, "%pI4\n", &curr_ip);
47512 +}
47513 +#endif
47514 diff --git a/fs/proc/base.c b/fs/proc/base.c
47515 index 9fc77b4..04761b8 100644
47516 --- a/fs/proc/base.c
47517 +++ b/fs/proc/base.c
47518 @@ -109,6 +109,14 @@ struct pid_entry {
47519 union proc_op op;
47520 };
47521
47522 +struct getdents_callback {
47523 + struct linux_dirent __user * current_dir;
47524 + struct linux_dirent __user * previous;
47525 + struct file * file;
47526 + int count;
47527 + int error;
47528 +};
47529 +
47530 #define NOD(NAME, MODE, IOP, FOP, OP) { \
47531 .name = (NAME), \
47532 .len = sizeof(NAME) - 1, \
47533 @@ -213,6 +221,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
47534 if (!mm->arg_end)
47535 goto out_mm; /* Shh! No looking before we're done */
47536
47537 + if (gr_acl_handle_procpidmem(task))
47538 + goto out_mm;
47539 +
47540 len = mm->arg_end - mm->arg_start;
47541
47542 if (len > PAGE_SIZE)
47543 @@ -240,12 +251,28 @@ out:
47544 return res;
47545 }
47546
47547 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47548 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
47549 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
47550 + _mm->pax_flags & MF_PAX_SEGMEXEC))
47551 +#endif
47552 +
47553 static int proc_pid_auxv(struct task_struct *task, char *buffer)
47554 {
47555 struct mm_struct *mm = mm_for_maps(task);
47556 int res = PTR_ERR(mm);
47557 if (mm && !IS_ERR(mm)) {
47558 unsigned int nwords = 0;
47559 +
47560 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47561 + /* allow if we're currently ptracing this task */
47562 + if (PAX_RAND_FLAGS(mm) &&
47563 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
47564 + mmput(mm);
47565 + return 0;
47566 + }
47567 +#endif
47568 +
47569 do {
47570 nwords += 2;
47571 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
47572 @@ -259,7 +286,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
47573 }
47574
47575
47576 -#ifdef CONFIG_KALLSYMS
47577 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47578 /*
47579 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
47580 * Returns the resolved symbol. If that fails, simply return the address.
47581 @@ -298,7 +325,7 @@ static void unlock_trace(struct task_struct *task)
47582 mutex_unlock(&task->signal->cred_guard_mutex);
47583 }
47584
47585 -#ifdef CONFIG_STACKTRACE
47586 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47587
47588 #define MAX_STACK_TRACE_DEPTH 64
47589
47590 @@ -489,7 +516,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
47591 return count;
47592 }
47593
47594 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
47595 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
47596 static int proc_pid_syscall(struct task_struct *task, char *buffer)
47597 {
47598 long nr;
47599 @@ -518,7 +545,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
47600 /************************************************************************/
47601
47602 /* permission checks */
47603 -static int proc_fd_access_allowed(struct inode *inode)
47604 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
47605 {
47606 struct task_struct *task;
47607 int allowed = 0;
47608 @@ -528,7 +555,10 @@ static int proc_fd_access_allowed(struct inode *inode)
47609 */
47610 task = get_proc_task(inode);
47611 if (task) {
47612 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
47613 + if (log)
47614 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
47615 + else
47616 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
47617 put_task_struct(task);
47618 }
47619 return allowed;
47620 @@ -566,10 +596,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
47621 struct task_struct *task,
47622 int hide_pid_min)
47623 {
47624 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47625 + return false;
47626 +
47627 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47628 + rcu_read_lock();
47629 + {
47630 + const struct cred *tmpcred = current_cred();
47631 + const struct cred *cred = __task_cred(task);
47632 +
47633 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
47634 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47635 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
47636 +#endif
47637 + ) {
47638 + rcu_read_unlock();
47639 + return true;
47640 + }
47641 + }
47642 + rcu_read_unlock();
47643 +
47644 + if (!pid->hide_pid)
47645 + return false;
47646 +#endif
47647 +
47648 if (pid->hide_pid < hide_pid_min)
47649 return true;
47650 if (in_group_p(pid->pid_gid))
47651 return true;
47652 +
47653 return ptrace_may_access(task, PTRACE_MODE_READ);
47654 }
47655
47656 @@ -587,7 +642,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
47657 put_task_struct(task);
47658
47659 if (!has_perms) {
47660 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47661 + {
47662 +#else
47663 if (pid->hide_pid == 2) {
47664 +#endif
47665 /*
47666 * Let's make getdents(), stat(), and open()
47667 * consistent with each other. If a process
47668 @@ -702,6 +761,10 @@ static int mem_open(struct inode* inode, struct file* file)
47669 file->f_mode |= FMODE_UNSIGNED_OFFSET;
47670 file->private_data = mm;
47671
47672 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47673 + file->f_version = current->exec_id;
47674 +#endif
47675 +
47676 return 0;
47677 }
47678
47679 @@ -713,6 +776,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
47680 ssize_t copied;
47681 char *page;
47682
47683 +#ifdef CONFIG_GRKERNSEC
47684 + if (write)
47685 + return -EPERM;
47686 +#endif
47687 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47688 + if (file->f_version != current->exec_id) {
47689 + gr_log_badprocpid("mem");
47690 + return 0;
47691 + }
47692 +#endif
47693 +
47694 if (!mm)
47695 return 0;
47696
47697 @@ -813,6 +887,9 @@ static ssize_t environ_read(struct file *file, char __user *buf,
47698 if (!task)
47699 goto out_no_task;
47700
47701 + if (gr_acl_handle_procpidmem(task))
47702 + goto out;
47703 +
47704 ret = -ENOMEM;
47705 page = (char *)__get_free_page(GFP_TEMPORARY);
47706 if (!page)
47707 @@ -1433,7 +1510,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
47708 path_put(&nd->path);
47709
47710 /* Are we allowed to snoop on the tasks file descriptors? */
47711 - if (!proc_fd_access_allowed(inode))
47712 + if (!proc_fd_access_allowed(inode, 0))
47713 goto out;
47714
47715 error = PROC_I(inode)->op.proc_get_link(dentry, &nd->path);
47716 @@ -1472,8 +1549,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
47717 struct path path;
47718
47719 /* Are we allowed to snoop on the tasks file descriptors? */
47720 - if (!proc_fd_access_allowed(inode))
47721 - goto out;
47722 + /* logging this is needed for learning on chromium to work properly,
47723 + but we don't want to flood the logs from 'ps' which does a readlink
47724 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
47725 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
47726 + */
47727 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
47728 + if (!proc_fd_access_allowed(inode,0))
47729 + goto out;
47730 + } else {
47731 + if (!proc_fd_access_allowed(inode,1))
47732 + goto out;
47733 + }
47734
47735 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
47736 if (error)
47737 @@ -1538,7 +1625,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
47738 rcu_read_lock();
47739 cred = __task_cred(task);
47740 inode->i_uid = cred->euid;
47741 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47742 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
47743 +#else
47744 inode->i_gid = cred->egid;
47745 +#endif
47746 rcu_read_unlock();
47747 }
47748 security_task_to_inode(task, inode);
47749 @@ -1574,10 +1665,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
47750 return -ENOENT;
47751 }
47752 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
47753 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47754 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
47755 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47756 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
47757 +#endif
47758 task_dumpable(task)) {
47759 cred = __task_cred(task);
47760 stat->uid = cred->euid;
47761 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47762 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
47763 +#else
47764 stat->gid = cred->egid;
47765 +#endif
47766 }
47767 }
47768 rcu_read_unlock();
47769 @@ -1615,11 +1715,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
47770
47771 if (task) {
47772 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
47773 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47774 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
47775 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47776 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
47777 +#endif
47778 task_dumpable(task)) {
47779 rcu_read_lock();
47780 cred = __task_cred(task);
47781 inode->i_uid = cred->euid;
47782 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47783 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
47784 +#else
47785 inode->i_gid = cred->egid;
47786 +#endif
47787 rcu_read_unlock();
47788 } else {
47789 inode->i_uid = 0;
47790 @@ -1737,7 +1846,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
47791 int fd = proc_fd(inode);
47792
47793 if (task) {
47794 - files = get_files_struct(task);
47795 + if (!gr_acl_handle_procpidmem(task))
47796 + files = get_files_struct(task);
47797 put_task_struct(task);
47798 }
47799 if (files) {
47800 @@ -2338,11 +2448,21 @@ static const struct file_operations proc_map_files_operations = {
47801 */
47802 static int proc_fd_permission(struct inode *inode, int mask)
47803 {
47804 + struct task_struct *task;
47805 int rv = generic_permission(inode, mask);
47806 - if (rv == 0)
47807 - return 0;
47808 +
47809 if (task_pid(current) == proc_pid(inode))
47810 rv = 0;
47811 +
47812 + task = get_proc_task(inode);
47813 + if (task == NULL)
47814 + return rv;
47815 +
47816 + if (gr_acl_handle_procpidmem(task))
47817 + rv = -EACCES;
47818 +
47819 + put_task_struct(task);
47820 +
47821 return rv;
47822 }
47823
47824 @@ -2452,6 +2572,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
47825 if (!task)
47826 goto out_no_task;
47827
47828 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47829 + goto out;
47830 +
47831 /*
47832 * Yes, it does not scale. And it should not. Don't add
47833 * new entries into /proc/<tgid>/ without very good reasons.
47834 @@ -2496,6 +2619,9 @@ static int proc_pident_readdir(struct file *filp,
47835 if (!task)
47836 goto out_no_task;
47837
47838 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47839 + goto out;
47840 +
47841 ret = 0;
47842 i = filp->f_pos;
47843 switch (i) {
47844 @@ -2766,7 +2892,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
47845 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
47846 void *cookie)
47847 {
47848 - char *s = nd_get_link(nd);
47849 + const char *s = nd_get_link(nd);
47850 if (!IS_ERR(s))
47851 __putname(s);
47852 }
47853 @@ -2967,7 +3093,7 @@ static const struct pid_entry tgid_base_stuff[] = {
47854 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
47855 #endif
47856 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
47857 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
47858 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
47859 INF("syscall", S_IRUGO, proc_pid_syscall),
47860 #endif
47861 INF("cmdline", S_IRUGO, proc_pid_cmdline),
47862 @@ -2992,10 +3118,10 @@ static const struct pid_entry tgid_base_stuff[] = {
47863 #ifdef CONFIG_SECURITY
47864 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
47865 #endif
47866 -#ifdef CONFIG_KALLSYMS
47867 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47868 INF("wchan", S_IRUGO, proc_pid_wchan),
47869 #endif
47870 -#ifdef CONFIG_STACKTRACE
47871 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47872 ONE("stack", S_IRUGO, proc_pid_stack),
47873 #endif
47874 #ifdef CONFIG_SCHEDSTATS
47875 @@ -3029,6 +3155,9 @@ static const struct pid_entry tgid_base_stuff[] = {
47876 #ifdef CONFIG_HARDWALL
47877 INF("hardwall", S_IRUGO, proc_pid_hardwall),
47878 #endif
47879 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
47880 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
47881 +#endif
47882 };
47883
47884 static int proc_tgid_base_readdir(struct file * filp,
47885 @@ -3155,7 +3284,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
47886 if (!inode)
47887 goto out;
47888
47889 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47890 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
47891 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47892 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
47893 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
47894 +#else
47895 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
47896 +#endif
47897 inode->i_op = &proc_tgid_base_inode_operations;
47898 inode->i_fop = &proc_tgid_base_operations;
47899 inode->i_flags|=S_IMMUTABLE;
47900 @@ -3197,7 +3333,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
47901 if (!task)
47902 goto out;
47903
47904 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47905 + goto out_put_task;
47906 +
47907 result = proc_pid_instantiate(dir, dentry, task, NULL);
47908 +out_put_task:
47909 put_task_struct(task);
47910 out:
47911 return result;
47912 @@ -3260,6 +3400,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
47913 static int fake_filldir(void *buf, const char *name, int namelen,
47914 loff_t offset, u64 ino, unsigned d_type)
47915 {
47916 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
47917 + __buf->error = -EINVAL;
47918 return 0;
47919 }
47920
47921 @@ -3326,7 +3468,7 @@ static const struct pid_entry tid_base_stuff[] = {
47922 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
47923 #endif
47924 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
47925 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
47926 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
47927 INF("syscall", S_IRUGO, proc_pid_syscall),
47928 #endif
47929 INF("cmdline", S_IRUGO, proc_pid_cmdline),
47930 @@ -3350,10 +3492,10 @@ static const struct pid_entry tid_base_stuff[] = {
47931 #ifdef CONFIG_SECURITY
47932 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
47933 #endif
47934 -#ifdef CONFIG_KALLSYMS
47935 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47936 INF("wchan", S_IRUGO, proc_pid_wchan),
47937 #endif
47938 -#ifdef CONFIG_STACKTRACE
47939 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47940 ONE("stack", S_IRUGO, proc_pid_stack),
47941 #endif
47942 #ifdef CONFIG_SCHEDSTATS
47943 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
47944 index 82676e3..5f8518a 100644
47945 --- a/fs/proc/cmdline.c
47946 +++ b/fs/proc/cmdline.c
47947 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
47948
47949 static int __init proc_cmdline_init(void)
47950 {
47951 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
47952 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
47953 +#else
47954 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
47955 +#endif
47956 return 0;
47957 }
47958 module_init(proc_cmdline_init);
47959 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
47960 index b143471..bb105e5 100644
47961 --- a/fs/proc/devices.c
47962 +++ b/fs/proc/devices.c
47963 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
47964
47965 static int __init proc_devices_init(void)
47966 {
47967 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
47968 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
47969 +#else
47970 proc_create("devices", 0, NULL, &proc_devinfo_operations);
47971 +#endif
47972 return 0;
47973 }
47974 module_init(proc_devices_init);
47975 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
47976 index 205c922..2ee4c57 100644
47977 --- a/fs/proc/inode.c
47978 +++ b/fs/proc/inode.c
47979 @@ -21,11 +21,17 @@
47980 #include <linux/seq_file.h>
47981 #include <linux/slab.h>
47982 #include <linux/mount.h>
47983 +#include <linux/grsecurity.h>
47984
47985 #include <asm/uaccess.h>
47986
47987 #include "internal.h"
47988
47989 +#ifdef CONFIG_PROC_SYSCTL
47990 +extern const struct inode_operations proc_sys_inode_operations;
47991 +extern const struct inode_operations proc_sys_dir_operations;
47992 +#endif
47993 +
47994 static void proc_evict_inode(struct inode *inode)
47995 {
47996 struct proc_dir_entry *de;
47997 @@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
47998 ns_ops = PROC_I(inode)->ns_ops;
47999 if (ns_ops && ns_ops->put)
48000 ns_ops->put(PROC_I(inode)->ns);
48001 +
48002 +#ifdef CONFIG_PROC_SYSCTL
48003 + if (inode->i_op == &proc_sys_inode_operations ||
48004 + inode->i_op == &proc_sys_dir_operations)
48005 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
48006 +#endif
48007 +
48008 }
48009
48010 static struct kmem_cache * proc_inode_cachep;
48011 @@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
48012 if (de->mode) {
48013 inode->i_mode = de->mode;
48014 inode->i_uid = de->uid;
48015 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48016 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48017 +#else
48018 inode->i_gid = de->gid;
48019 +#endif
48020 }
48021 if (de->size)
48022 inode->i_size = de->size;
48023 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
48024 index 5f79bb8..eeccee4 100644
48025 --- a/fs/proc/internal.h
48026 +++ b/fs/proc/internal.h
48027 @@ -54,6 +54,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48028 struct pid *pid, struct task_struct *task);
48029 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48030 struct pid *pid, struct task_struct *task);
48031 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48032 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
48033 +#endif
48034 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
48035
48036 extern const struct file_operations proc_pid_maps_operations;
48037 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
48038 index 86c67ee..cdca321 100644
48039 --- a/fs/proc/kcore.c
48040 +++ b/fs/proc/kcore.c
48041 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48042 * the addresses in the elf_phdr on our list.
48043 */
48044 start = kc_offset_to_vaddr(*fpos - elf_buflen);
48045 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
48046 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
48047 + if (tsz > buflen)
48048 tsz = buflen;
48049 -
48050 +
48051 while (buflen) {
48052 struct kcore_list *m;
48053
48054 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48055 kfree(elf_buf);
48056 } else {
48057 if (kern_addr_valid(start)) {
48058 - unsigned long n;
48059 + char *elf_buf;
48060 + mm_segment_t oldfs;
48061
48062 - n = copy_to_user(buffer, (char *)start, tsz);
48063 - /*
48064 - * We cannot distinguish between fault on source
48065 - * and fault on destination. When this happens
48066 - * we clear too and hope it will trigger the
48067 - * EFAULT again.
48068 - */
48069 - if (n) {
48070 - if (clear_user(buffer + tsz - n,
48071 - n))
48072 + elf_buf = kmalloc(tsz, GFP_KERNEL);
48073 + if (!elf_buf)
48074 + return -ENOMEM;
48075 + oldfs = get_fs();
48076 + set_fs(KERNEL_DS);
48077 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
48078 + set_fs(oldfs);
48079 + if (copy_to_user(buffer, elf_buf, tsz)) {
48080 + kfree(elf_buf);
48081 return -EFAULT;
48082 + }
48083 }
48084 + set_fs(oldfs);
48085 + kfree(elf_buf);
48086 } else {
48087 if (clear_user(buffer, tsz))
48088 return -EFAULT;
48089 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48090
48091 static int open_kcore(struct inode *inode, struct file *filp)
48092 {
48093 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
48094 + return -EPERM;
48095 +#endif
48096 if (!capable(CAP_SYS_RAWIO))
48097 return -EPERM;
48098 if (kcore_need_update)
48099 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
48100 index 80e4645..53e5fcf 100644
48101 --- a/fs/proc/meminfo.c
48102 +++ b/fs/proc/meminfo.c
48103 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
48104 vmi.used >> 10,
48105 vmi.largest_chunk >> 10
48106 #ifdef CONFIG_MEMORY_FAILURE
48107 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
48108 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
48109 #endif
48110 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
48111 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
48112 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
48113 index b1822dd..df622cb 100644
48114 --- a/fs/proc/nommu.c
48115 +++ b/fs/proc/nommu.c
48116 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
48117 if (len < 1)
48118 len = 1;
48119 seq_printf(m, "%*c", len, ' ');
48120 - seq_path(m, &file->f_path, "");
48121 + seq_path(m, &file->f_path, "\n\\");
48122 }
48123
48124 seq_putc(m, '\n');
48125 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
48126 index 06e1cc1..177cd98 100644
48127 --- a/fs/proc/proc_net.c
48128 +++ b/fs/proc/proc_net.c
48129 @@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
48130 struct task_struct *task;
48131 struct nsproxy *ns;
48132 struct net *net = NULL;
48133 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48134 + const struct cred *cred = current_cred();
48135 +#endif
48136 +
48137 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48138 + if (cred->fsuid)
48139 + return net;
48140 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48141 + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
48142 + return net;
48143 +#endif
48144
48145 rcu_read_lock();
48146 task = pid_task(proc_pid(dir), PIDTYPE_PID);
48147 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
48148 index 21d836f..bebf3ee 100644
48149 --- a/fs/proc/proc_sysctl.c
48150 +++ b/fs/proc/proc_sysctl.c
48151 @@ -12,11 +12,15 @@
48152 #include <linux/module.h>
48153 #include "internal.h"
48154
48155 +extern int gr_handle_chroot_sysctl(const int op);
48156 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
48157 + const int op);
48158 +
48159 static const struct dentry_operations proc_sys_dentry_operations;
48160 static const struct file_operations proc_sys_file_operations;
48161 -static const struct inode_operations proc_sys_inode_operations;
48162 +const struct inode_operations proc_sys_inode_operations;
48163 static const struct file_operations proc_sys_dir_file_operations;
48164 -static const struct inode_operations proc_sys_dir_operations;
48165 +const struct inode_operations proc_sys_dir_operations;
48166
48167 void proc_sys_poll_notify(struct ctl_table_poll *poll)
48168 {
48169 @@ -470,8 +474,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
48170
48171 err = NULL;
48172 d_set_d_op(dentry, &proc_sys_dentry_operations);
48173 +
48174 + gr_handle_proc_create(dentry, inode);
48175 +
48176 d_add(dentry, inode);
48177
48178 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt))
48179 + err = ERR_PTR(-ENOENT);
48180 +
48181 out:
48182 sysctl_head_finish(head);
48183 return err;
48184 @@ -483,18 +493,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
48185 struct inode *inode = filp->f_path.dentry->d_inode;
48186 struct ctl_table_header *head = grab_header(inode);
48187 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
48188 + int op = write ? MAY_WRITE : MAY_READ;
48189 ssize_t error;
48190 size_t res;
48191
48192 if (IS_ERR(head))
48193 return PTR_ERR(head);
48194
48195 +
48196 /*
48197 * At this point we know that the sysctl was not unregistered
48198 * and won't be until we finish.
48199 */
48200 error = -EPERM;
48201 - if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
48202 + if (sysctl_perm(head->root, table, op))
48203 goto out;
48204
48205 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
48206 @@ -502,6 +514,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
48207 if (!table->proc_handler)
48208 goto out;
48209
48210 +#ifdef CONFIG_GRKERNSEC
48211 + error = -EPERM;
48212 + if (gr_handle_chroot_sysctl(op))
48213 + goto out;
48214 + dget(filp->f_path.dentry);
48215 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
48216 + dput(filp->f_path.dentry);
48217 + goto out;
48218 + }
48219 + dput(filp->f_path.dentry);
48220 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
48221 + goto out;
48222 + if (write && !capable(CAP_SYS_ADMIN))
48223 + goto out;
48224 +#endif
48225 +
48226 /* careful: calling conventions are nasty here */
48227 res = count;
48228 error = table->proc_handler(table, write, buf, &res, ppos);
48229 @@ -599,6 +627,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
48230 return -ENOMEM;
48231 } else {
48232 d_set_d_op(child, &proc_sys_dentry_operations);
48233 +
48234 + gr_handle_proc_create(child, inode);
48235 +
48236 d_add(child, inode);
48237 }
48238 } else {
48239 @@ -642,6 +673,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
48240 if ((*pos)++ < file->f_pos)
48241 return 0;
48242
48243 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
48244 + return 0;
48245 +
48246 if (unlikely(S_ISLNK(table->mode)))
48247 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
48248 else
48249 @@ -759,6 +793,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
48250 if (IS_ERR(head))
48251 return PTR_ERR(head);
48252
48253 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
48254 + return -ENOENT;
48255 +
48256 generic_fillattr(inode, stat);
48257 if (table)
48258 stat->mode = (stat->mode & S_IFMT) | table->mode;
48259 @@ -781,13 +818,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
48260 .llseek = generic_file_llseek,
48261 };
48262
48263 -static const struct inode_operations proc_sys_inode_operations = {
48264 +const struct inode_operations proc_sys_inode_operations = {
48265 .permission = proc_sys_permission,
48266 .setattr = proc_sys_setattr,
48267 .getattr = proc_sys_getattr,
48268 };
48269
48270 -static const struct inode_operations proc_sys_dir_operations = {
48271 +const struct inode_operations proc_sys_dir_operations = {
48272 .lookup = proc_sys_lookup,
48273 .permission = proc_sys_permission,
48274 .setattr = proc_sys_setattr,
48275 diff --git a/fs/proc/root.c b/fs/proc/root.c
48276 index eed44bf..abeb499 100644
48277 --- a/fs/proc/root.c
48278 +++ b/fs/proc/root.c
48279 @@ -188,7 +188,15 @@ void __init proc_root_init(void)
48280 #ifdef CONFIG_PROC_DEVICETREE
48281 proc_device_tree_init();
48282 #endif
48283 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48284 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48285 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
48286 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48287 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
48288 +#endif
48289 +#else
48290 proc_mkdir("bus", NULL);
48291 +#endif
48292 proc_sys_init();
48293 }
48294
48295 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
48296 index 7faaf2a..096c28b 100644
48297 --- a/fs/proc/task_mmu.c
48298 +++ b/fs/proc/task_mmu.c
48299 @@ -11,12 +11,19 @@
48300 #include <linux/rmap.h>
48301 #include <linux/swap.h>
48302 #include <linux/swapops.h>
48303 +#include <linux/grsecurity.h>
48304
48305 #include <asm/elf.h>
48306 #include <asm/uaccess.h>
48307 #include <asm/tlbflush.h>
48308 #include "internal.h"
48309
48310 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48311 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48312 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48313 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48314 +#endif
48315 +
48316 void task_mem(struct seq_file *m, struct mm_struct *mm)
48317 {
48318 unsigned long data, text, lib, swap;
48319 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48320 "VmExe:\t%8lu kB\n"
48321 "VmLib:\t%8lu kB\n"
48322 "VmPTE:\t%8lu kB\n"
48323 - "VmSwap:\t%8lu kB\n",
48324 - hiwater_vm << (PAGE_SHIFT-10),
48325 + "VmSwap:\t%8lu kB\n"
48326 +
48327 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48328 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
48329 +#endif
48330 +
48331 + ,hiwater_vm << (PAGE_SHIFT-10),
48332 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
48333 mm->locked_vm << (PAGE_SHIFT-10),
48334 mm->pinned_vm << (PAGE_SHIFT-10),
48335 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48336 data << (PAGE_SHIFT-10),
48337 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
48338 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
48339 - swap << (PAGE_SHIFT-10));
48340 + swap << (PAGE_SHIFT-10)
48341 +
48342 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48343 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48344 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
48345 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
48346 +#else
48347 + , mm->context.user_cs_base
48348 + , mm->context.user_cs_limit
48349 +#endif
48350 +#endif
48351 +
48352 + );
48353 }
48354
48355 unsigned long task_vsize(struct mm_struct *mm)
48356 @@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
48357 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
48358 }
48359
48360 - /* We don't show the stack guard page in /proc/maps */
48361 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48362 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
48363 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
48364 +#else
48365 start = vma->vm_start;
48366 - if (stack_guard_page_start(vma, start))
48367 - start += PAGE_SIZE;
48368 end = vma->vm_end;
48369 - if (stack_guard_page_end(vma, end))
48370 - end -= PAGE_SIZE;
48371 +#endif
48372
48373 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
48374 start,
48375 @@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
48376 flags & VM_WRITE ? 'w' : '-',
48377 flags & VM_EXEC ? 'x' : '-',
48378 flags & VM_MAYSHARE ? 's' : 'p',
48379 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48380 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
48381 +#else
48382 pgoff,
48383 +#endif
48384 MAJOR(dev), MINOR(dev), ino, &len);
48385
48386 /*
48387 @@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
48388 */
48389 if (file) {
48390 pad_len_spaces(m, len);
48391 - seq_path(m, &file->f_path, "\n");
48392 + seq_path(m, &file->f_path, "\n\\");
48393 goto done;
48394 }
48395
48396 @@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
48397 * Thread stack in /proc/PID/task/TID/maps or
48398 * the main process stack.
48399 */
48400 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
48401 - vma->vm_end >= mm->start_stack)) {
48402 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
48403 + (vma->vm_start <= mm->start_stack &&
48404 + vma->vm_end >= mm->start_stack)) {
48405 name = "[stack]";
48406 } else {
48407 /* Thread stack in /proc/PID/maps */
48408 @@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
48409 struct proc_maps_private *priv = m->private;
48410 struct task_struct *task = priv->task;
48411
48412 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48413 + if (current->exec_id != m->exec_id) {
48414 + gr_log_badprocpid("maps");
48415 + return 0;
48416 + }
48417 +#endif
48418 +
48419 show_map_vma(m, vma, is_pid);
48420
48421 if (m->count < m->size) /* vma is copied successfully */
48422 @@ -482,12 +518,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
48423 .private = &mss,
48424 };
48425
48426 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48427 + if (current->exec_id != m->exec_id) {
48428 + gr_log_badprocpid("smaps");
48429 + return 0;
48430 + }
48431 +#endif
48432 memset(&mss, 0, sizeof mss);
48433 - mss.vma = vma;
48434 - /* mmap_sem is held in m_start */
48435 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
48436 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
48437 -
48438 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48439 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
48440 +#endif
48441 + mss.vma = vma;
48442 + /* mmap_sem is held in m_start */
48443 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
48444 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
48445 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48446 + }
48447 +#endif
48448 show_map_vma(m, vma, is_pid);
48449
48450 seq_printf(m,
48451 @@ -505,7 +552,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
48452 "KernelPageSize: %8lu kB\n"
48453 "MMUPageSize: %8lu kB\n"
48454 "Locked: %8lu kB\n",
48455 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48456 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
48457 +#else
48458 (vma->vm_end - vma->vm_start) >> 10,
48459 +#endif
48460 mss.resident >> 10,
48461 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
48462 mss.shared_clean >> 10,
48463 @@ -1138,6 +1189,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
48464 int n;
48465 char buffer[50];
48466
48467 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48468 + if (current->exec_id != m->exec_id) {
48469 + gr_log_badprocpid("numa_maps");
48470 + return 0;
48471 + }
48472 +#endif
48473 +
48474 if (!mm)
48475 return 0;
48476
48477 @@ -1155,11 +1213,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
48478 mpol_to_str(buffer, sizeof(buffer), pol, 0);
48479 mpol_cond_put(pol);
48480
48481 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48482 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
48483 +#else
48484 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
48485 +#endif
48486
48487 if (file) {
48488 seq_printf(m, " file=");
48489 - seq_path(m, &file->f_path, "\n\t= ");
48490 + seq_path(m, &file->f_path, "\n\t\\= ");
48491 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
48492 seq_printf(m, " heap");
48493 } else {
48494 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
48495 index 74fe164..899e77b 100644
48496 --- a/fs/proc/task_nommu.c
48497 +++ b/fs/proc/task_nommu.c
48498 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48499 else
48500 bytes += kobjsize(mm);
48501
48502 - if (current->fs && current->fs->users > 1)
48503 + if (current->fs && atomic_read(&current->fs->users) > 1)
48504 sbytes += kobjsize(current->fs);
48505 else
48506 bytes += kobjsize(current->fs);
48507 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
48508
48509 if (file) {
48510 pad_len_spaces(m, len);
48511 - seq_path(m, &file->f_path, "");
48512 + seq_path(m, &file->f_path, "\n\\");
48513 } else if (mm) {
48514 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
48515
48516 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
48517 index d67908b..d13f6a6 100644
48518 --- a/fs/quota/netlink.c
48519 +++ b/fs/quota/netlink.c
48520 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
48521 void quota_send_warning(short type, unsigned int id, dev_t dev,
48522 const char warntype)
48523 {
48524 - static atomic_t seq;
48525 + static atomic_unchecked_t seq;
48526 struct sk_buff *skb;
48527 void *msg_head;
48528 int ret;
48529 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
48530 "VFS: Not enough memory to send quota warning.\n");
48531 return;
48532 }
48533 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
48534 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
48535 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
48536 if (!msg_head) {
48537 printk(KERN_ERR
48538 diff --git a/fs/readdir.c b/fs/readdir.c
48539 index cc0a822..43cb195 100644
48540 --- a/fs/readdir.c
48541 +++ b/fs/readdir.c
48542 @@ -17,6 +17,7 @@
48543 #include <linux/security.h>
48544 #include <linux/syscalls.h>
48545 #include <linux/unistd.h>
48546 +#include <linux/namei.h>
48547
48548 #include <asm/uaccess.h>
48549
48550 @@ -67,6 +68,7 @@ struct old_linux_dirent {
48551
48552 struct readdir_callback {
48553 struct old_linux_dirent __user * dirent;
48554 + struct file * file;
48555 int result;
48556 };
48557
48558 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
48559 buf->result = -EOVERFLOW;
48560 return -EOVERFLOW;
48561 }
48562 +
48563 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48564 + return 0;
48565 +
48566 buf->result++;
48567 dirent = buf->dirent;
48568 if (!access_ok(VERIFY_WRITE, dirent,
48569 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
48570
48571 buf.result = 0;
48572 buf.dirent = dirent;
48573 + buf.file = file;
48574
48575 error = vfs_readdir(file, fillonedir, &buf);
48576 if (buf.result)
48577 @@ -142,6 +149,7 @@ struct linux_dirent {
48578 struct getdents_callback {
48579 struct linux_dirent __user * current_dir;
48580 struct linux_dirent __user * previous;
48581 + struct file * file;
48582 int count;
48583 int error;
48584 };
48585 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
48586 buf->error = -EOVERFLOW;
48587 return -EOVERFLOW;
48588 }
48589 +
48590 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48591 + return 0;
48592 +
48593 dirent = buf->previous;
48594 if (dirent) {
48595 if (__put_user(offset, &dirent->d_off))
48596 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
48597 buf.previous = NULL;
48598 buf.count = count;
48599 buf.error = 0;
48600 + buf.file = file;
48601
48602 error = vfs_readdir(file, filldir, &buf);
48603 if (error >= 0)
48604 @@ -229,6 +242,7 @@ out:
48605 struct getdents_callback64 {
48606 struct linux_dirent64 __user * current_dir;
48607 struct linux_dirent64 __user * previous;
48608 + struct file *file;
48609 int count;
48610 int error;
48611 };
48612 @@ -244,6 +258,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
48613 buf->error = -EINVAL; /* only used if we fail.. */
48614 if (reclen > buf->count)
48615 return -EINVAL;
48616 +
48617 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48618 + return 0;
48619 +
48620 dirent = buf->previous;
48621 if (dirent) {
48622 if (__put_user(offset, &dirent->d_off))
48623 @@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
48624
48625 buf.current_dir = dirent;
48626 buf.previous = NULL;
48627 + buf.file = file;
48628 buf.count = count;
48629 buf.error = 0;
48630
48631 @@ -299,7 +318,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
48632 error = buf.error;
48633 lastdirent = buf.previous;
48634 if (lastdirent) {
48635 - typeof(lastdirent->d_off) d_off = file->f_pos;
48636 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
48637 if (__put_user(d_off, &lastdirent->d_off))
48638 error = -EFAULT;
48639 else
48640 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
48641 index 2b7882b..1c5ef48 100644
48642 --- a/fs/reiserfs/do_balan.c
48643 +++ b/fs/reiserfs/do_balan.c
48644 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
48645 return;
48646 }
48647
48648 - atomic_inc(&(fs_generation(tb->tb_sb)));
48649 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
48650 do_balance_starts(tb);
48651
48652 /* balance leaf returns 0 except if combining L R and S into
48653 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
48654 index 2c1ade6..8c59d8d 100644
48655 --- a/fs/reiserfs/procfs.c
48656 +++ b/fs/reiserfs/procfs.c
48657 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
48658 "SMALL_TAILS " : "NO_TAILS ",
48659 replay_only(sb) ? "REPLAY_ONLY " : "",
48660 convert_reiserfs(sb) ? "CONV " : "",
48661 - atomic_read(&r->s_generation_counter),
48662 + atomic_read_unchecked(&r->s_generation_counter),
48663 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
48664 SF(s_do_balance), SF(s_unneeded_left_neighbor),
48665 SF(s_good_search_by_key_reada), SF(s_bmaps),
48666 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
48667 index a59d271..e12d1cf 100644
48668 --- a/fs/reiserfs/reiserfs.h
48669 +++ b/fs/reiserfs/reiserfs.h
48670 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
48671 /* Comment? -Hans */
48672 wait_queue_head_t s_wait;
48673 /* To be obsoleted soon by per buffer seals.. -Hans */
48674 - atomic_t s_generation_counter; // increased by one every time the
48675 + atomic_unchecked_t s_generation_counter; // increased by one every time the
48676 // tree gets re-balanced
48677 unsigned long s_properties; /* File system properties. Currently holds
48678 on-disk FS format */
48679 @@ -1973,7 +1973,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
48680 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
48681
48682 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
48683 -#define get_generation(s) atomic_read (&fs_generation(s))
48684 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
48685 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
48686 #define __fs_changed(gen,s) (gen != get_generation (s))
48687 #define fs_changed(gen,s) \
48688 diff --git a/fs/select.c b/fs/select.c
48689 index 17d33d0..da0bf5c 100644
48690 --- a/fs/select.c
48691 +++ b/fs/select.c
48692 @@ -20,6 +20,7 @@
48693 #include <linux/export.h>
48694 #include <linux/slab.h>
48695 #include <linux/poll.h>
48696 +#include <linux/security.h>
48697 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
48698 #include <linux/file.h>
48699 #include <linux/fdtable.h>
48700 @@ -833,6 +834,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
48701 struct poll_list *walk = head;
48702 unsigned long todo = nfds;
48703
48704 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
48705 if (nfds > rlimit(RLIMIT_NOFILE))
48706 return -EINVAL;
48707
48708 diff --git a/fs/seq_file.c b/fs/seq_file.c
48709 index 0cbd049..cab1127 100644
48710 --- a/fs/seq_file.c
48711 +++ b/fs/seq_file.c
48712 @@ -9,6 +9,7 @@
48713 #include <linux/export.h>
48714 #include <linux/seq_file.h>
48715 #include <linux/slab.h>
48716 +#include <linux/sched.h>
48717
48718 #include <asm/uaccess.h>
48719 #include <asm/page.h>
48720 @@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
48721 memset(p, 0, sizeof(*p));
48722 mutex_init(&p->lock);
48723 p->op = op;
48724 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48725 + p->exec_id = current->exec_id;
48726 +#endif
48727
48728 /*
48729 * Wrappers around seq_open(e.g. swaps_open) need to be
48730 @@ -567,7 +571,7 @@ static void single_stop(struct seq_file *p, void *v)
48731 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
48732 void *data)
48733 {
48734 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
48735 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
48736 int res = -ENOMEM;
48737
48738 if (op) {
48739 diff --git a/fs/splice.c b/fs/splice.c
48740 index f847684..156619e 100644
48741 --- a/fs/splice.c
48742 +++ b/fs/splice.c
48743 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
48744 pipe_lock(pipe);
48745
48746 for (;;) {
48747 - if (!pipe->readers) {
48748 + if (!atomic_read(&pipe->readers)) {
48749 send_sig(SIGPIPE, current, 0);
48750 if (!ret)
48751 ret = -EPIPE;
48752 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
48753 do_wakeup = 0;
48754 }
48755
48756 - pipe->waiting_writers++;
48757 + atomic_inc(&pipe->waiting_writers);
48758 pipe_wait(pipe);
48759 - pipe->waiting_writers--;
48760 + atomic_dec(&pipe->waiting_writers);
48761 }
48762
48763 pipe_unlock(pipe);
48764 @@ -560,7 +560,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
48765 old_fs = get_fs();
48766 set_fs(get_ds());
48767 /* The cast to a user pointer is valid due to the set_fs() */
48768 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
48769 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
48770 set_fs(old_fs);
48771
48772 return res;
48773 @@ -575,7 +575,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
48774 old_fs = get_fs();
48775 set_fs(get_ds());
48776 /* The cast to a user pointer is valid due to the set_fs() */
48777 - res = vfs_write(file, (const char __user *)buf, count, &pos);
48778 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
48779 set_fs(old_fs);
48780
48781 return res;
48782 @@ -626,7 +626,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
48783 goto err;
48784
48785 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
48786 - vec[i].iov_base = (void __user *) page_address(page);
48787 + vec[i].iov_base = (void __force_user *) page_address(page);
48788 vec[i].iov_len = this_len;
48789 spd.pages[i] = page;
48790 spd.nr_pages++;
48791 @@ -845,10 +845,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
48792 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
48793 {
48794 while (!pipe->nrbufs) {
48795 - if (!pipe->writers)
48796 + if (!atomic_read(&pipe->writers))
48797 return 0;
48798
48799 - if (!pipe->waiting_writers && sd->num_spliced)
48800 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
48801 return 0;
48802
48803 if (sd->flags & SPLICE_F_NONBLOCK)
48804 @@ -1181,7 +1181,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
48805 * out of the pipe right after the splice_to_pipe(). So set
48806 * PIPE_READERS appropriately.
48807 */
48808 - pipe->readers = 1;
48809 + atomic_set(&pipe->readers, 1);
48810
48811 current->splice_pipe = pipe;
48812 }
48813 @@ -1733,9 +1733,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
48814 ret = -ERESTARTSYS;
48815 break;
48816 }
48817 - if (!pipe->writers)
48818 + if (!atomic_read(&pipe->writers))
48819 break;
48820 - if (!pipe->waiting_writers) {
48821 + if (!atomic_read(&pipe->waiting_writers)) {
48822 if (flags & SPLICE_F_NONBLOCK) {
48823 ret = -EAGAIN;
48824 break;
48825 @@ -1767,7 +1767,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
48826 pipe_lock(pipe);
48827
48828 while (pipe->nrbufs >= pipe->buffers) {
48829 - if (!pipe->readers) {
48830 + if (!atomic_read(&pipe->readers)) {
48831 send_sig(SIGPIPE, current, 0);
48832 ret = -EPIPE;
48833 break;
48834 @@ -1780,9 +1780,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
48835 ret = -ERESTARTSYS;
48836 break;
48837 }
48838 - pipe->waiting_writers++;
48839 + atomic_inc(&pipe->waiting_writers);
48840 pipe_wait(pipe);
48841 - pipe->waiting_writers--;
48842 + atomic_dec(&pipe->waiting_writers);
48843 }
48844
48845 pipe_unlock(pipe);
48846 @@ -1818,14 +1818,14 @@ retry:
48847 pipe_double_lock(ipipe, opipe);
48848
48849 do {
48850 - if (!opipe->readers) {
48851 + if (!atomic_read(&opipe->readers)) {
48852 send_sig(SIGPIPE, current, 0);
48853 if (!ret)
48854 ret = -EPIPE;
48855 break;
48856 }
48857
48858 - if (!ipipe->nrbufs && !ipipe->writers)
48859 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
48860 break;
48861
48862 /*
48863 @@ -1922,7 +1922,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
48864 pipe_double_lock(ipipe, opipe);
48865
48866 do {
48867 - if (!opipe->readers) {
48868 + if (!atomic_read(&opipe->readers)) {
48869 send_sig(SIGPIPE, current, 0);
48870 if (!ret)
48871 ret = -EPIPE;
48872 @@ -1967,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
48873 * return EAGAIN if we have the potential of some data in the
48874 * future, otherwise just return 0
48875 */
48876 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
48877 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
48878 ret = -EAGAIN;
48879
48880 pipe_unlock(ipipe);
48881 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
48882 index 35a36d3..23424b2 100644
48883 --- a/fs/sysfs/dir.c
48884 +++ b/fs/sysfs/dir.c
48885 @@ -657,6 +657,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
48886 struct sysfs_dirent *sd;
48887 int rc;
48888
48889 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
48890 + const char *parent_name = parent_sd->s_name;
48891 +
48892 + mode = S_IFDIR | S_IRWXU;
48893 +
48894 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
48895 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
48896 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
48897 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
48898 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
48899 +#endif
48900 +
48901 /* allocate */
48902 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
48903 if (!sd)
48904 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
48905 index 00012e3..8392349 100644
48906 --- a/fs/sysfs/file.c
48907 +++ b/fs/sysfs/file.c
48908 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
48909
48910 struct sysfs_open_dirent {
48911 atomic_t refcnt;
48912 - atomic_t event;
48913 + atomic_unchecked_t event;
48914 wait_queue_head_t poll;
48915 struct list_head buffers; /* goes through sysfs_buffer.list */
48916 };
48917 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
48918 if (!sysfs_get_active(attr_sd))
48919 return -ENODEV;
48920
48921 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
48922 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
48923 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
48924
48925 sysfs_put_active(attr_sd);
48926 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
48927 return -ENOMEM;
48928
48929 atomic_set(&new_od->refcnt, 0);
48930 - atomic_set(&new_od->event, 1);
48931 + atomic_set_unchecked(&new_od->event, 1);
48932 init_waitqueue_head(&new_od->poll);
48933 INIT_LIST_HEAD(&new_od->buffers);
48934 goto retry;
48935 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
48936
48937 sysfs_put_active(attr_sd);
48938
48939 - if (buffer->event != atomic_read(&od->event))
48940 + if (buffer->event != atomic_read_unchecked(&od->event))
48941 goto trigger;
48942
48943 return DEFAULT_POLLMASK;
48944 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
48945
48946 od = sd->s_attr.open;
48947 if (od) {
48948 - atomic_inc(&od->event);
48949 + atomic_inc_unchecked(&od->event);
48950 wake_up_interruptible(&od->poll);
48951 }
48952
48953 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
48954 index a7ac78f..02158e1 100644
48955 --- a/fs/sysfs/symlink.c
48956 +++ b/fs/sysfs/symlink.c
48957 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
48958
48959 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
48960 {
48961 - char *page = nd_get_link(nd);
48962 + const char *page = nd_get_link(nd);
48963 if (!IS_ERR(page))
48964 free_page((unsigned long)page);
48965 }
48966 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
48967 index c175b4d..8f36a16 100644
48968 --- a/fs/udf/misc.c
48969 +++ b/fs/udf/misc.c
48970 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
48971
48972 u8 udf_tag_checksum(const struct tag *t)
48973 {
48974 - u8 *data = (u8 *)t;
48975 + const u8 *data = (const u8 *)t;
48976 u8 checksum = 0;
48977 int i;
48978 for (i = 0; i < sizeof(struct tag); ++i)
48979 diff --git a/fs/utimes.c b/fs/utimes.c
48980 index ba653f3..06ea4b1 100644
48981 --- a/fs/utimes.c
48982 +++ b/fs/utimes.c
48983 @@ -1,6 +1,7 @@
48984 #include <linux/compiler.h>
48985 #include <linux/file.h>
48986 #include <linux/fs.h>
48987 +#include <linux/security.h>
48988 #include <linux/linkage.h>
48989 #include <linux/mount.h>
48990 #include <linux/namei.h>
48991 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
48992 goto mnt_drop_write_and_out;
48993 }
48994 }
48995 +
48996 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
48997 + error = -EACCES;
48998 + goto mnt_drop_write_and_out;
48999 + }
49000 +
49001 mutex_lock(&inode->i_mutex);
49002 error = notify_change(path->dentry, &newattrs);
49003 mutex_unlock(&inode->i_mutex);
49004 diff --git a/fs/xattr.c b/fs/xattr.c
49005 index 3c8c1cc..a83c398 100644
49006 --- a/fs/xattr.c
49007 +++ b/fs/xattr.c
49008 @@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
49009 * Extended attribute SET operations
49010 */
49011 static long
49012 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
49013 +setxattr(struct path *path, const char __user *name, const void __user *value,
49014 size_t size, int flags)
49015 {
49016 int error;
49017 @@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
49018 }
49019 }
49020
49021 - error = vfs_setxattr(d, kname, kvalue, size, flags);
49022 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
49023 + error = -EACCES;
49024 + goto out;
49025 + }
49026 +
49027 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
49028 out:
49029 if (vvalue)
49030 vfree(vvalue);
49031 @@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
49032 return error;
49033 error = mnt_want_write(path.mnt);
49034 if (!error) {
49035 - error = setxattr(path.dentry, name, value, size, flags);
49036 + error = setxattr(&path, name, value, size, flags);
49037 mnt_drop_write(path.mnt);
49038 }
49039 path_put(&path);
49040 @@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
49041 return error;
49042 error = mnt_want_write(path.mnt);
49043 if (!error) {
49044 - error = setxattr(path.dentry, name, value, size, flags);
49045 + error = setxattr(&path, name, value, size, flags);
49046 mnt_drop_write(path.mnt);
49047 }
49048 path_put(&path);
49049 @@ -400,17 +405,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
49050 const void __user *,value, size_t, size, int, flags)
49051 {
49052 struct file *f;
49053 - struct dentry *dentry;
49054 int error = -EBADF;
49055
49056 f = fget(fd);
49057 if (!f)
49058 return error;
49059 - dentry = f->f_path.dentry;
49060 - audit_inode(NULL, dentry);
49061 + audit_inode(NULL, f->f_path.dentry);
49062 error = mnt_want_write_file(f);
49063 if (!error) {
49064 - error = setxattr(dentry, name, value, size, flags);
49065 + error = setxattr(&f->f_path, name, value, size, flags);
49066 mnt_drop_write_file(f);
49067 }
49068 fput(f);
49069 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
49070 index 69d06b0..c0996e5 100644
49071 --- a/fs/xattr_acl.c
49072 +++ b/fs/xattr_acl.c
49073 @@ -17,8 +17,8 @@
49074 struct posix_acl *
49075 posix_acl_from_xattr(const void *value, size_t size)
49076 {
49077 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
49078 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
49079 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
49080 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
49081 int count;
49082 struct posix_acl *acl;
49083 struct posix_acl_entry *acl_e;
49084 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
49085 index 85e7e32..5344e52 100644
49086 --- a/fs/xfs/xfs_bmap.c
49087 +++ b/fs/xfs/xfs_bmap.c
49088 @@ -190,7 +190,7 @@ xfs_bmap_validate_ret(
49089 int nmap,
49090 int ret_nmap);
49091 #else
49092 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
49093 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
49094 #endif /* DEBUG */
49095
49096 STATIC int
49097 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
49098 index 79d05e8..e3e5861 100644
49099 --- a/fs/xfs/xfs_dir2_sf.c
49100 +++ b/fs/xfs/xfs_dir2_sf.c
49101 @@ -852,7 +852,15 @@ xfs_dir2_sf_getdents(
49102 }
49103
49104 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
49105 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49106 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
49107 + char name[sfep->namelen];
49108 + memcpy(name, sfep->name, sfep->namelen);
49109 + if (filldir(dirent, name, sfep->namelen,
49110 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
49111 + *offset = off & 0x7fffffff;
49112 + return 0;
49113 + }
49114 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49115 off & 0x7fffffff, ino, DT_UNKNOWN)) {
49116 *offset = off & 0x7fffffff;
49117 return 0;
49118 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
49119 index 91f8ff5..0ce68f9 100644
49120 --- a/fs/xfs/xfs_ioctl.c
49121 +++ b/fs/xfs/xfs_ioctl.c
49122 @@ -128,7 +128,7 @@ xfs_find_handle(
49123 }
49124
49125 error = -EFAULT;
49126 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
49127 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
49128 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
49129 goto out_put;
49130
49131 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
49132 index 3011b87..1ab03e9 100644
49133 --- a/fs/xfs/xfs_iops.c
49134 +++ b/fs/xfs/xfs_iops.c
49135 @@ -397,7 +397,7 @@ xfs_vn_put_link(
49136 struct nameidata *nd,
49137 void *p)
49138 {
49139 - char *s = nd_get_link(nd);
49140 + const char *s = nd_get_link(nd);
49141
49142 if (!IS_ERR(s))
49143 kfree(s);
49144 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
49145 new file mode 100644
49146 index 0000000..b9e7d6f
49147 --- /dev/null
49148 +++ b/grsecurity/Kconfig
49149 @@ -0,0 +1,940 @@
49150 +#
49151 +# grecurity configuration
49152 +#
49153 +menu "Memory Protections"
49154 +depends on GRKERNSEC
49155 +
49156 +config GRKERNSEC_KMEM
49157 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
49158 + default y if GRKERNSEC_CONFIG_AUTO
49159 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
49160 + help
49161 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
49162 + be written to or read from to modify or leak the contents of the running
49163 + kernel. /dev/port will also not be allowed to be opened. If you have module
49164 + support disabled, enabling this will close up four ways that are
49165 + currently used to insert malicious code into the running kernel.
49166 + Even with all these features enabled, we still highly recommend that
49167 + you use the RBAC system, as it is still possible for an attacker to
49168 + modify the running kernel through privileged I/O granted by ioperm/iopl.
49169 + If you are not using XFree86, you may be able to stop this additional
49170 + case by enabling the 'Disable privileged I/O' option. Though nothing
49171 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
49172 + but only to video memory, which is the only writing we allow in this
49173 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
49174 + not be allowed to mprotect it with PROT_WRITE later.
49175 + It is highly recommended that you say Y here if you meet all the
49176 + conditions above.
49177 +
49178 +config GRKERNSEC_VM86
49179 + bool "Restrict VM86 mode"
49180 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
49181 + depends on X86_32
49182 +
49183 + help
49184 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
49185 + make use of a special execution mode on 32bit x86 processors called
49186 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
49187 + video cards and will still work with this option enabled. The purpose
49188 + of the option is to prevent exploitation of emulation errors in
49189 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
49190 + Nearly all users should be able to enable this option.
49191 +
49192 +config GRKERNSEC_IO
49193 + bool "Disable privileged I/O"
49194 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
49195 + depends on X86
49196 + select RTC_CLASS
49197 + select RTC_INTF_DEV
49198 + select RTC_DRV_CMOS
49199 +
49200 + help
49201 + If you say Y here, all ioperm and iopl calls will return an error.
49202 + Ioperm and iopl can be used to modify the running kernel.
49203 + Unfortunately, some programs need this access to operate properly,
49204 + the most notable of which are XFree86 and hwclock. hwclock can be
49205 + remedied by having RTC support in the kernel, so real-time
49206 + clock support is enabled if this option is enabled, to ensure
49207 + that hwclock operates correctly. XFree86 still will not
49208 + operate correctly with this option enabled, so DO NOT CHOOSE Y
49209 + IF YOU USE XFree86. If you use XFree86 and you still want to
49210 + protect your kernel against modification, use the RBAC system.
49211 +
49212 +config GRKERNSEC_PROC_MEMMAP
49213 + bool "Harden ASLR against information leaks and entropy reduction"
49214 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
49215 + depends on PAX_NOEXEC || PAX_ASLR
49216 + help
49217 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
49218 + give no information about the addresses of its mappings if
49219 + PaX features that rely on random addresses are enabled on the task.
49220 + In addition to sanitizing this information and disabling other
49221 + dangerous sources of information, this option causes reads of sensitive
49222 + /proc/<pid> entries where the file descriptor was opened in a different
49223 + task than the one performing the read. Such attempts are logged.
49224 + This option also limits argv/env strings for suid/sgid binaries
49225 + to 512KB to prevent a complete exhaustion of the stack entropy provided
49226 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
49227 + binaries to prevent alternative mmap layouts from being abused.
49228 +
49229 + If you use PaX it is essential that you say Y here as it closes up
49230 + several holes that make full ASLR useless locally.
49231 +
49232 +config GRKERNSEC_BRUTE
49233 + bool "Deter exploit bruteforcing"
49234 + default y if GRKERNSEC_CONFIG_AUTO
49235 + help
49236 + If you say Y here, attempts to bruteforce exploits against forking
49237 + daemons such as apache or sshd, as well as against suid/sgid binaries
49238 + will be deterred. When a child of a forking daemon is killed by PaX
49239 + or crashes due to an illegal instruction or other suspicious signal,
49240 + the parent process will be delayed 30 seconds upon every subsequent
49241 + fork until the administrator is able to assess the situation and
49242 + restart the daemon.
49243 + In the suid/sgid case, the attempt is logged, the user has all their
49244 + processes terminated, and they are prevented from executing any further
49245 + processes for 15 minutes.
49246 + It is recommended that you also enable signal logging in the auditing
49247 + section so that logs are generated when a process triggers a suspicious
49248 + signal.
49249 + If the sysctl option is enabled, a sysctl option with name
49250 + "deter_bruteforce" is created.
49251 +
49252 +
49253 +config GRKERNSEC_MODHARDEN
49254 + bool "Harden module auto-loading"
49255 + default y if GRKERNSEC_CONFIG_AUTO
49256 + depends on MODULES
49257 + help
49258 + If you say Y here, module auto-loading in response to use of some
49259 + feature implemented by an unloaded module will be restricted to
49260 + root users. Enabling this option helps defend against attacks
49261 + by unprivileged users who abuse the auto-loading behavior to
49262 + cause a vulnerable module to load that is then exploited.
49263 +
49264 + If this option prevents a legitimate use of auto-loading for a
49265 + non-root user, the administrator can execute modprobe manually
49266 + with the exact name of the module mentioned in the alert log.
49267 + Alternatively, the administrator can add the module to the list
49268 + of modules loaded at boot by modifying init scripts.
49269 +
49270 + Modification of init scripts will most likely be needed on
49271 + Ubuntu servers with encrypted home directory support enabled,
49272 + as the first non-root user logging in will cause the ecb(aes),
49273 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
49274 +
49275 +config GRKERNSEC_HIDESYM
49276 + bool "Hide kernel symbols"
49277 + default y if GRKERNSEC_CONFIG_AUTO
49278 + help
49279 + If you say Y here, getting information on loaded modules, and
49280 + displaying all kernel symbols through a syscall will be restricted
49281 + to users with CAP_SYS_MODULE. For software compatibility reasons,
49282 + /proc/kallsyms will be restricted to the root user. The RBAC
49283 + system can hide that entry even from root.
49284 +
49285 + This option also prevents leaking of kernel addresses through
49286 + several /proc entries.
49287 +
49288 + Note that this option is only effective provided the following
49289 + conditions are met:
49290 + 1) The kernel using grsecurity is not precompiled by some distribution
49291 + 2) You have also enabled GRKERNSEC_DMESG
49292 + 3) You are using the RBAC system and hiding other files such as your
49293 + kernel image and System.map. Alternatively, enabling this option
49294 + causes the permissions on /boot, /lib/modules, and the kernel
49295 + source directory to change at compile time to prevent
49296 + reading by non-root users.
49297 + If the above conditions are met, this option will aid in providing a
49298 + useful protection against local kernel exploitation of overflows
49299 + and arbitrary read/write vulnerabilities.
49300 +
49301 +config GRKERNSEC_KERN_LOCKOUT
49302 + bool "Active kernel exploit response"
49303 + default y if GRKERNSEC_CONFIG_AUTO
49304 + depends on X86 || ARM || PPC || SPARC
49305 + help
49306 + If you say Y here, when a PaX alert is triggered due to suspicious
49307 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
49308 + or an OOPS occurs due to bad memory accesses, instead of just
49309 + terminating the offending process (and potentially allowing
49310 + a subsequent exploit from the same user), we will take one of two
49311 + actions:
49312 + If the user was root, we will panic the system
49313 + If the user was non-root, we will log the attempt, terminate
49314 + all processes owned by the user, then prevent them from creating
49315 + any new processes until the system is restarted
49316 + This deters repeated kernel exploitation/bruteforcing attempts
49317 + and is useful for later forensics.
49318 +
49319 +endmenu
49320 +menu "Role Based Access Control Options"
49321 +depends on GRKERNSEC
49322 +
49323 +config GRKERNSEC_RBAC_DEBUG
49324 + bool
49325 +
49326 +config GRKERNSEC_NO_RBAC
49327 + bool "Disable RBAC system"
49328 + help
49329 + If you say Y here, the /dev/grsec device will be removed from the kernel,
49330 + preventing the RBAC system from being enabled. You should only say Y
49331 + here if you have no intention of using the RBAC system, so as to prevent
49332 + an attacker with root access from misusing the RBAC system to hide files
49333 + and processes when loadable module support and /dev/[k]mem have been
49334 + locked down.
49335 +
49336 +config GRKERNSEC_ACL_HIDEKERN
49337 + bool "Hide kernel processes"
49338 + help
49339 + If you say Y here, all kernel threads will be hidden to all
49340 + processes but those whose subject has the "view hidden processes"
49341 + flag.
49342 +
49343 +config GRKERNSEC_ACL_MAXTRIES
49344 + int "Maximum tries before password lockout"
49345 + default 3
49346 + help
49347 + This option enforces the maximum number of times a user can attempt
49348 + to authorize themselves with the grsecurity RBAC system before being
49349 + denied the ability to attempt authorization again for a specified time.
49350 + The lower the number, the harder it will be to brute-force a password.
49351 +
49352 +config GRKERNSEC_ACL_TIMEOUT
49353 + int "Time to wait after max password tries, in seconds"
49354 + default 30
49355 + help
49356 + This option specifies the time the user must wait after attempting to
49357 + authorize to the RBAC system with the maximum number of invalid
49358 + passwords. The higher the number, the harder it will be to brute-force
49359 + a password.
49360 +
49361 +endmenu
49362 +menu "Filesystem Protections"
49363 +depends on GRKERNSEC
49364 +
49365 +config GRKERNSEC_PROC
49366 + bool "Proc restrictions"
49367 + default y if GRKERNSEC_CONFIG_AUTO
49368 + help
49369 + If you say Y here, the permissions of the /proc filesystem
49370 + will be altered to enhance system security and privacy. You MUST
49371 + choose either a user only restriction or a user and group restriction.
49372 + Depending upon the option you choose, you can either restrict users to
49373 + see only the processes they themselves run, or choose a group that can
49374 + view all processes and files normally restricted to root if you choose
49375 + the "restrict to user only" option. NOTE: If you're running identd or
49376 + ntpd as a non-root user, you will have to run it as the group you
49377 + specify here.
49378 +
49379 +config GRKERNSEC_PROC_USER
49380 + bool "Restrict /proc to user only"
49381 + depends on GRKERNSEC_PROC
49382 + help
49383 + If you say Y here, non-root users will only be able to view their own
49384 + processes, and restricts them from viewing network-related information,
49385 + and viewing kernel symbol and module information.
49386 +
49387 +config GRKERNSEC_PROC_USERGROUP
49388 + bool "Allow special group"
49389 + default y if GRKERNSEC_CONFIG_AUTO
49390 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
49391 + help
49392 + If you say Y here, you will be able to select a group that will be
49393 + able to view all processes and network-related information. If you've
49394 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
49395 + remain hidden. This option is useful if you want to run identd as
49396 + a non-root user.
49397 +
49398 +config GRKERNSEC_PROC_GID
49399 + int "GID for special group"
49400 + depends on GRKERNSEC_PROC_USERGROUP
49401 + default 1001
49402 +
49403 +config GRKERNSEC_PROC_ADD
49404 + bool "Additional restrictions"
49405 + default y if GRKERNSEC_CONFIG_AUTO
49406 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
49407 + help
49408 + If you say Y here, additional restrictions will be placed on
49409 + /proc that keep normal users from viewing device information and
49410 + slabinfo information that could be useful for exploits.
49411 +
49412 +config GRKERNSEC_LINK
49413 + bool "Linking restrictions"
49414 + default y if GRKERNSEC_CONFIG_AUTO
49415 + help
49416 + If you say Y here, /tmp race exploits will be prevented, since users
49417 + will no longer be able to follow symlinks owned by other users in
49418 + world-writable +t directories (e.g. /tmp), unless the owner of the
49419 + symlink is the owner of the directory. users will also not be
49420 + able to hardlink to files they do not own. If the sysctl option is
49421 + enabled, a sysctl option with name "linking_restrictions" is created.
49422 +
49423 +config GRKERNSEC_SYMLINKOWN
49424 + bool "Kernel-enforced SymlinksIfOwnerMatch"
49425 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
49426 + help
49427 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
49428 + that prevents it from being used as a security feature. As Apache
49429 + verifies the symlink by performing a stat() against the target of
49430 + the symlink before it is followed, an attacker can setup a symlink
49431 + to point to a same-owned file, then replace the symlink with one
49432 + that targets another user's file just after Apache "validates" the
49433 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
49434 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
49435 + will be in place for the group you specify. If the sysctl option
49436 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
49437 + created.
49438 +
49439 +config GRKERNSEC_SYMLINKOWN_GID
49440 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
49441 + depends on GRKERNSEC_SYMLINKOWN
49442 + default 1006
49443 + help
49444 + Setting this GID determines what group kernel-enforced
49445 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
49446 + is enabled, a sysctl option with name "symlinkown_gid" is created.
49447 +
49448 +config GRKERNSEC_FIFO
49449 + bool "FIFO restrictions"
49450 + default y if GRKERNSEC_CONFIG_AUTO
49451 + help
49452 + If you say Y here, users will not be able to write to FIFOs they don't
49453 + own in world-writable +t directories (e.g. /tmp), unless the owner of
49454 + the FIFO is the same owner of the directory it's held in. If the sysctl
49455 + option is enabled, a sysctl option with name "fifo_restrictions" is
49456 + created.
49457 +
49458 +config GRKERNSEC_SYSFS_RESTRICT
49459 + bool "Sysfs/debugfs restriction"
49460 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
49461 + depends on SYSFS
49462 + help
49463 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
49464 + any filesystem normally mounted under it (e.g. debugfs) will be
49465 + mostly accessible only by root. These filesystems generally provide access
49466 + to hardware and debug information that isn't appropriate for unprivileged
49467 + users of the system. Sysfs and debugfs have also become a large source
49468 + of new vulnerabilities, ranging from infoleaks to local compromise.
49469 + There has been very little oversight with an eye toward security involved
49470 + in adding new exporters of information to these filesystems, so their
49471 + use is discouraged.
49472 + For reasons of compatibility, a few directories have been whitelisted
49473 + for access by non-root users:
49474 + /sys/fs/selinux
49475 + /sys/fs/fuse
49476 + /sys/devices/system/cpu
49477 +
49478 +config GRKERNSEC_ROFS
49479 + bool "Runtime read-only mount protection"
49480 + help
49481 + If you say Y here, a sysctl option with name "romount_protect" will
49482 + be created. By setting this option to 1 at runtime, filesystems
49483 + will be protected in the following ways:
49484 + * No new writable mounts will be allowed
49485 + * Existing read-only mounts won't be able to be remounted read/write
49486 + * Write operations will be denied on all block devices
49487 + This option acts independently of grsec_lock: once it is set to 1,
49488 + it cannot be turned off. Therefore, please be mindful of the resulting
49489 + behavior if this option is enabled in an init script on a read-only
49490 + filesystem. This feature is mainly intended for secure embedded systems.
49491 +
49492 +config GRKERNSEC_CHROOT
49493 + bool "Chroot jail restrictions"
49494 + default y if GRKERNSEC_CONFIG_AUTO
49495 + help
49496 + If you say Y here, you will be able to choose several options that will
49497 + make breaking out of a chrooted jail much more difficult. If you
49498 + encounter no software incompatibilities with the following options, it
49499 + is recommended that you enable each one.
49500 +
49501 +config GRKERNSEC_CHROOT_MOUNT
49502 + bool "Deny mounts"
49503 + default y if GRKERNSEC_CONFIG_AUTO
49504 + depends on GRKERNSEC_CHROOT
49505 + help
49506 + If you say Y here, processes inside a chroot will not be able to
49507 + mount or remount filesystems. If the sysctl option is enabled, a
49508 + sysctl option with name "chroot_deny_mount" is created.
49509 +
49510 +config GRKERNSEC_CHROOT_DOUBLE
49511 + bool "Deny double-chroots"
49512 + default y if GRKERNSEC_CONFIG_AUTO
49513 + depends on GRKERNSEC_CHROOT
49514 + help
49515 + If you say Y here, processes inside a chroot will not be able to chroot
49516 + again outside the chroot. This is a widely used method of breaking
49517 + out of a chroot jail and should not be allowed. If the sysctl
49518 + option is enabled, a sysctl option with name
49519 + "chroot_deny_chroot" is created.
49520 +
49521 +config GRKERNSEC_CHROOT_PIVOT
49522 + bool "Deny pivot_root in chroot"
49523 + default y if GRKERNSEC_CONFIG_AUTO
49524 + depends on GRKERNSEC_CHROOT
49525 + help
49526 + If you say Y here, processes inside a chroot will not be able to use
49527 + a function called pivot_root() that was introduced in Linux 2.3.41. It
49528 + works similar to chroot in that it changes the root filesystem. This
49529 + function could be misused in a chrooted process to attempt to break out
49530 + of the chroot, and therefore should not be allowed. If the sysctl
49531 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
49532 + created.
49533 +
49534 +config GRKERNSEC_CHROOT_CHDIR
49535 + bool "Enforce chdir(\"/\") on all chroots"
49536 + default y if GRKERNSEC_CONFIG_AUTO
49537 + depends on GRKERNSEC_CHROOT
49538 + help
49539 + If you say Y here, the current working directory of all newly-chrooted
49540 + applications will be set to the the root directory of the chroot.
49541 + The man page on chroot(2) states:
49542 + Note that this call does not change the current working
49543 + directory, so that `.' can be outside the tree rooted at
49544 + `/'. In particular, the super-user can escape from a
49545 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
49546 +
49547 + It is recommended that you say Y here, since it's not known to break
49548 + any software. If the sysctl option is enabled, a sysctl option with
49549 + name "chroot_enforce_chdir" is created.
49550 +
49551 +config GRKERNSEC_CHROOT_CHMOD
49552 + bool "Deny (f)chmod +s"
49553 + default y if GRKERNSEC_CONFIG_AUTO
49554 + depends on GRKERNSEC_CHROOT
49555 + help
49556 + If you say Y here, processes inside a chroot will not be able to chmod
49557 + or fchmod files to make them have suid or sgid bits. This protects
49558 + against another published method of breaking a chroot. If the sysctl
49559 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
49560 + created.
49561 +
49562 +config GRKERNSEC_CHROOT_FCHDIR
49563 + bool "Deny fchdir out of chroot"
49564 + default y if GRKERNSEC_CONFIG_AUTO
49565 + depends on GRKERNSEC_CHROOT
49566 + help
49567 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
49568 + to a file descriptor of the chrooting process that points to a directory
49569 + outside the filesystem will be stopped. If the sysctl option
49570 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
49571 +
49572 +config GRKERNSEC_CHROOT_MKNOD
49573 + bool "Deny mknod"
49574 + default y if GRKERNSEC_CONFIG_AUTO
49575 + depends on GRKERNSEC_CHROOT
49576 + help
49577 + If you say Y here, processes inside a chroot will not be allowed to
49578 + mknod. The problem with using mknod inside a chroot is that it
49579 + would allow an attacker to create a device entry that is the same
49580 + as one on the physical root of your system, which could range from
49581 + anything from the console device to a device for your harddrive (which
49582 + they could then use to wipe the drive or steal data). It is recommended
49583 + that you say Y here, unless you run into software incompatibilities.
49584 + If the sysctl option is enabled, a sysctl option with name
49585 + "chroot_deny_mknod" is created.
49586 +
49587 +config GRKERNSEC_CHROOT_SHMAT
49588 + bool "Deny shmat() out of chroot"
49589 + default y if GRKERNSEC_CONFIG_AUTO
49590 + depends on GRKERNSEC_CHROOT
49591 + help
49592 + If you say Y here, processes inside a chroot will not be able to attach
49593 + to shared memory segments that were created outside of the chroot jail.
49594 + It is recommended that you say Y here. If the sysctl option is enabled,
49595 + a sysctl option with name "chroot_deny_shmat" is created.
49596 +
49597 +config GRKERNSEC_CHROOT_UNIX
49598 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
49599 + default y if GRKERNSEC_CONFIG_AUTO
49600 + depends on GRKERNSEC_CHROOT
49601 + help
49602 + If you say Y here, processes inside a chroot will not be able to
49603 + connect to abstract (meaning not belonging to a filesystem) Unix
49604 + domain sockets that were bound outside of a chroot. It is recommended
49605 + that you say Y here. If the sysctl option is enabled, a sysctl option
49606 + with name "chroot_deny_unix" is created.
49607 +
49608 +config GRKERNSEC_CHROOT_FINDTASK
49609 + bool "Protect outside processes"
49610 + default y if GRKERNSEC_CONFIG_AUTO
49611 + depends on GRKERNSEC_CHROOT
49612 + help
49613 + If you say Y here, processes inside a chroot will not be able to
49614 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
49615 + getsid, or view any process outside of the chroot. If the sysctl
49616 + option is enabled, a sysctl option with name "chroot_findtask" is
49617 + created.
49618 +
49619 +config GRKERNSEC_CHROOT_NICE
49620 + bool "Restrict priority changes"
49621 + default y if GRKERNSEC_CONFIG_AUTO
49622 + depends on GRKERNSEC_CHROOT
49623 + help
49624 + If you say Y here, processes inside a chroot will not be able to raise
49625 + the priority of processes in the chroot, or alter the priority of
49626 + processes outside the chroot. This provides more security than simply
49627 + removing CAP_SYS_NICE from the process' capability set. If the
49628 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
49629 + is created.
49630 +
49631 +config GRKERNSEC_CHROOT_SYSCTL
49632 + bool "Deny sysctl writes"
49633 + default y if GRKERNSEC_CONFIG_AUTO
49634 + depends on GRKERNSEC_CHROOT
49635 + help
49636 + If you say Y here, an attacker in a chroot will not be able to
49637 + write to sysctl entries, either by sysctl(2) or through a /proc
49638 + interface. It is strongly recommended that you say Y here. If the
49639 + sysctl option is enabled, a sysctl option with name
49640 + "chroot_deny_sysctl" is created.
49641 +
49642 +config GRKERNSEC_CHROOT_CAPS
49643 + bool "Capability restrictions"
49644 + default y if GRKERNSEC_CONFIG_AUTO
49645 + depends on GRKERNSEC_CHROOT
49646 + help
49647 + If you say Y here, the capabilities on all processes within a
49648 + chroot jail will be lowered to stop module insertion, raw i/o,
49649 + system and net admin tasks, rebooting the system, modifying immutable
49650 + files, modifying IPC owned by another, and changing the system time.
49651 + This is left an option because it can break some apps. Disable this
49652 + if your chrooted apps are having problems performing those kinds of
49653 + tasks. If the sysctl option is enabled, a sysctl option with
49654 + name "chroot_caps" is created.
49655 +
49656 +endmenu
49657 +menu "Kernel Auditing"
49658 +depends on GRKERNSEC
49659 +
49660 +config GRKERNSEC_AUDIT_GROUP
49661 + bool "Single group for auditing"
49662 + help
49663 + If you say Y here, the exec, chdir, and (un)mount logging features
49664 + will only operate on a group you specify. This option is recommended
49665 + if you only want to watch certain users instead of having a large
49666 + amount of logs from the entire system. If the sysctl option is enabled,
49667 + a sysctl option with name "audit_group" is created.
49668 +
49669 +config GRKERNSEC_AUDIT_GID
49670 + int "GID for auditing"
49671 + depends on GRKERNSEC_AUDIT_GROUP
49672 + default 1007
49673 +
49674 +config GRKERNSEC_EXECLOG
49675 + bool "Exec logging"
49676 + help
49677 + If you say Y here, all execve() calls will be logged (since the
49678 + other exec*() calls are frontends to execve(), all execution
49679 + will be logged). Useful for shell-servers that like to keep track
49680 + of their users. If the sysctl option is enabled, a sysctl option with
49681 + name "exec_logging" is created.
49682 + WARNING: This option when enabled will produce a LOT of logs, especially
49683 + on an active system.
49684 +
49685 +config GRKERNSEC_RESLOG
49686 + bool "Resource logging"
49687 + default y if GRKERNSEC_CONFIG_AUTO
49688 + help
49689 + If you say Y here, all attempts to overstep resource limits will
49690 + be logged with the resource name, the requested size, and the current
49691 + limit. It is highly recommended that you say Y here. If the sysctl
49692 + option is enabled, a sysctl option with name "resource_logging" is
49693 + created. If the RBAC system is enabled, the sysctl value is ignored.
49694 +
49695 +config GRKERNSEC_CHROOT_EXECLOG
49696 + bool "Log execs within chroot"
49697 + help
49698 + If you say Y here, all executions inside a chroot jail will be logged
49699 + to syslog. This can cause a large amount of logs if certain
49700 + applications (eg. djb's daemontools) are installed on the system, and
49701 + is therefore left as an option. If the sysctl option is enabled, a
49702 + sysctl option with name "chroot_execlog" is created.
49703 +
49704 +config GRKERNSEC_AUDIT_PTRACE
49705 + bool "Ptrace logging"
49706 + help
49707 + If you say Y here, all attempts to attach to a process via ptrace
49708 + will be logged. If the sysctl option is enabled, a sysctl option
49709 + with name "audit_ptrace" is created.
49710 +
49711 +config GRKERNSEC_AUDIT_CHDIR
49712 + bool "Chdir logging"
49713 + help
49714 + If you say Y here, all chdir() calls will be logged. If the sysctl
49715 + option is enabled, a sysctl option with name "audit_chdir" is created.
49716 +
49717 +config GRKERNSEC_AUDIT_MOUNT
49718 + bool "(Un)Mount logging"
49719 + help
49720 + If you say Y here, all mounts and unmounts will be logged. If the
49721 + sysctl option is enabled, a sysctl option with name "audit_mount" is
49722 + created.
49723 +
49724 +config GRKERNSEC_SIGNAL
49725 + bool "Signal logging"
49726 + default y if GRKERNSEC_CONFIG_AUTO
49727 + help
49728 + If you say Y here, certain important signals will be logged, such as
49729 + SIGSEGV, which will as a result inform you of when a error in a program
49730 + occurred, which in some cases could mean a possible exploit attempt.
49731 + If the sysctl option is enabled, a sysctl option with name
49732 + "signal_logging" is created.
49733 +
49734 +config GRKERNSEC_FORKFAIL
49735 + bool "Fork failure logging"
49736 + help
49737 + If you say Y here, all failed fork() attempts will be logged.
49738 + This could suggest a fork bomb, or someone attempting to overstep
49739 + their process limit. If the sysctl option is enabled, a sysctl option
49740 + with name "forkfail_logging" is created.
49741 +
49742 +config GRKERNSEC_TIME
49743 + bool "Time change logging"
49744 + default y if GRKERNSEC_CONFIG_AUTO
49745 + help
49746 + If you say Y here, any changes of the system clock will be logged.
49747 + If the sysctl option is enabled, a sysctl option with name
49748 + "timechange_logging" is created.
49749 +
49750 +config GRKERNSEC_PROC_IPADDR
49751 + bool "/proc/<pid>/ipaddr support"
49752 + default y if GRKERNSEC_CONFIG_AUTO
49753 + help
49754 + If you say Y here, a new entry will be added to each /proc/<pid>
49755 + directory that contains the IP address of the person using the task.
49756 + The IP is carried across local TCP and AF_UNIX stream sockets.
49757 + This information can be useful for IDS/IPSes to perform remote response
49758 + to a local attack. The entry is readable by only the owner of the
49759 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
49760 + the RBAC system), and thus does not create privacy concerns.
49761 +
49762 +config GRKERNSEC_RWXMAP_LOG
49763 + bool 'Denied RWX mmap/mprotect logging'
49764 + default y if GRKERNSEC_CONFIG_AUTO
49765 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
49766 + help
49767 + If you say Y here, calls to mmap() and mprotect() with explicit
49768 + usage of PROT_WRITE and PROT_EXEC together will be logged when
49769 + denied by the PAX_MPROTECT feature. If the sysctl option is
49770 + enabled, a sysctl option with name "rwxmap_logging" is created.
49771 +
49772 +config GRKERNSEC_AUDIT_TEXTREL
49773 + bool 'ELF text relocations logging (READ HELP)'
49774 + depends on PAX_MPROTECT
49775 + help
49776 + If you say Y here, text relocations will be logged with the filename
49777 + of the offending library or binary. The purpose of the feature is
49778 + to help Linux distribution developers get rid of libraries and
49779 + binaries that need text relocations which hinder the future progress
49780 + of PaX. Only Linux distribution developers should say Y here, and
49781 + never on a production machine, as this option creates an information
49782 + leak that could aid an attacker in defeating the randomization of
49783 + a single memory region. If the sysctl option is enabled, a sysctl
49784 + option with name "audit_textrel" is created.
49785 +
49786 +endmenu
49787 +
49788 +menu "Executable Protections"
49789 +depends on GRKERNSEC
49790 +
49791 +config GRKERNSEC_DMESG
49792 + bool "Dmesg(8) restriction"
49793 + default y if GRKERNSEC_CONFIG_AUTO
49794 + help
49795 + If you say Y here, non-root users will not be able to use dmesg(8)
49796 + to view up to the last 4kb of messages in the kernel's log buffer.
49797 + The kernel's log buffer often contains kernel addresses and other
49798 + identifying information useful to an attacker in fingerprinting a
49799 + system for a targeted exploit.
49800 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
49801 + created.
49802 +
49803 +config GRKERNSEC_HARDEN_PTRACE
49804 + bool "Deter ptrace-based process snooping"
49805 + default y if GRKERNSEC_CONFIG_AUTO
49806 + help
49807 + If you say Y here, TTY sniffers and other malicious monitoring
49808 + programs implemented through ptrace will be defeated. If you
49809 + have been using the RBAC system, this option has already been
49810 + enabled for several years for all users, with the ability to make
49811 + fine-grained exceptions.
49812 +
49813 + This option only affects the ability of non-root users to ptrace
49814 + processes that are not a descendent of the ptracing process.
49815 + This means that strace ./binary and gdb ./binary will still work,
49816 + but attaching to arbitrary processes will not. If the sysctl
49817 + option is enabled, a sysctl option with name "harden_ptrace" is
49818 + created.
49819 +
49820 +config GRKERNSEC_PTRACE_READEXEC
49821 + bool "Require read access to ptrace sensitive binaries"
49822 + default y if GRKERNSEC_CONFIG_AUTO
49823 + help
49824 + If you say Y here, unprivileged users will not be able to ptrace unreadable
49825 + binaries. This option is useful in environments that
49826 + remove the read bits (e.g. file mode 4711) from suid binaries to
49827 + prevent infoleaking of their contents. This option adds
49828 + consistency to the use of that file mode, as the binary could normally
49829 + be read out when run without privileges while ptracing.
49830 +
49831 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
49832 + is created.
49833 +
49834 +config GRKERNSEC_SETXID
49835 + bool "Enforce consistent multithreaded privileges"
49836 + default y if GRKERNSEC_CONFIG_AUTO
49837 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
49838 + help
49839 + If you say Y here, a change from a root uid to a non-root uid
49840 + in a multithreaded application will cause the resulting uids,
49841 + gids, supplementary groups, and capabilities in that thread
49842 + to be propagated to the other threads of the process. In most
49843 + cases this is unnecessary, as glibc will emulate this behavior
49844 + on behalf of the application. Other libcs do not act in the
49845 + same way, allowing the other threads of the process to continue
49846 + running with root privileges. If the sysctl option is enabled,
49847 + a sysctl option with name "consistent_setxid" is created.
49848 +
49849 +config GRKERNSEC_TPE
49850 + bool "Trusted Path Execution (TPE)"
49851 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
49852 + help
49853 + If you say Y here, you will be able to choose a gid to add to the
49854 + supplementary groups of users you want to mark as "untrusted."
49855 + These users will not be able to execute any files that are not in
49856 + root-owned directories writable only by root. If the sysctl option
49857 + is enabled, a sysctl option with name "tpe" is created.
49858 +
49859 +config GRKERNSEC_TPE_ALL
49860 + bool "Partially restrict all non-root users"
49861 + depends on GRKERNSEC_TPE
49862 + help
49863 + If you say Y here, all non-root users will be covered under
49864 + a weaker TPE restriction. This is separate from, and in addition to,
49865 + the main TPE options that you have selected elsewhere. Thus, if a
49866 + "trusted" GID is chosen, this restriction applies to even that GID.
49867 + Under this restriction, all non-root users will only be allowed to
49868 + execute files in directories they own that are not group or
49869 + world-writable, or in directories owned by root and writable only by
49870 + root. If the sysctl option is enabled, a sysctl option with name
49871 + "tpe_restrict_all" is created.
49872 +
49873 +config GRKERNSEC_TPE_INVERT
49874 + bool "Invert GID option"
49875 + depends on GRKERNSEC_TPE
49876 + help
49877 + If you say Y here, the group you specify in the TPE configuration will
49878 + decide what group TPE restrictions will be *disabled* for. This
49879 + option is useful if you want TPE restrictions to be applied to most
49880 + users on the system. If the sysctl option is enabled, a sysctl option
49881 + with name "tpe_invert" is created. Unlike other sysctl options, this
49882 + entry will default to on for backward-compatibility.
49883 +
49884 +config GRKERNSEC_TPE_GID
49885 + int "GID for untrusted users"
49886 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
49887 + default 1005
49888 + help
49889 + Setting this GID determines what group TPE restrictions will be
49890 + *enabled* for. If the sysctl option is enabled, a sysctl option
49891 + with name "tpe_gid" is created.
49892 +
49893 +config GRKERNSEC_TPE_GID
49894 + int "GID for trusted users"
49895 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
49896 + default 1005
49897 + help
49898 + Setting this GID determines what group TPE restrictions will be
49899 + *disabled* for. If the sysctl option is enabled, a sysctl option
49900 + with name "tpe_gid" is created.
49901 +
49902 +endmenu
49903 +menu "Network Protections"
49904 +depends on GRKERNSEC
49905 +
49906 +config GRKERNSEC_RANDNET
49907 + bool "Larger entropy pools"
49908 + default y if GRKERNSEC_CONFIG_AUTO
49909 + help
49910 + If you say Y here, the entropy pools used for many features of Linux
49911 + and grsecurity will be doubled in size. Since several grsecurity
49912 + features use additional randomness, it is recommended that you say Y
49913 + here. Saying Y here has a similar effect as modifying
49914 + /proc/sys/kernel/random/poolsize.
49915 +
49916 +config GRKERNSEC_BLACKHOLE
49917 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
49918 + default y if GRKERNSEC_CONFIG_AUTO
49919 + depends on NET
49920 + help
49921 + If you say Y here, neither TCP resets nor ICMP
49922 + destination-unreachable packets will be sent in response to packets
49923 + sent to ports for which no associated listening process exists.
49924 + This feature supports both IPV4 and IPV6 and exempts the
49925 + loopback interface from blackholing. Enabling this feature
49926 + makes a host more resilient to DoS attacks and reduces network
49927 + visibility against scanners.
49928 +
49929 + The blackhole feature as-implemented is equivalent to the FreeBSD
49930 + blackhole feature, as it prevents RST responses to all packets, not
49931 + just SYNs. Under most application behavior this causes no
49932 + problems, but applications (like haproxy) may not close certain
49933 + connections in a way that cleanly terminates them on the remote
49934 + end, leaving the remote host in LAST_ACK state. Because of this
49935 + side-effect and to prevent intentional LAST_ACK DoSes, this
49936 + feature also adds automatic mitigation against such attacks.
49937 + The mitigation drastically reduces the amount of time a socket
49938 + can spend in LAST_ACK state. If you're using haproxy and not
49939 + all servers it connects to have this option enabled, consider
49940 + disabling this feature on the haproxy host.
49941 +
49942 + If the sysctl option is enabled, two sysctl options with names
49943 + "ip_blackhole" and "lastack_retries" will be created.
49944 + While "ip_blackhole" takes the standard zero/non-zero on/off
49945 + toggle, "lastack_retries" uses the same kinds of values as
49946 + "tcp_retries1" and "tcp_retries2". The default value of 4
49947 + prevents a socket from lasting more than 45 seconds in LAST_ACK
49948 + state.
49949 +
49950 +config GRKERNSEC_SOCKET
49951 + bool "Socket restrictions"
49952 + depends on NET
49953 + help
49954 + If you say Y here, you will be able to choose from several options.
49955 + If you assign a GID on your system and add it to the supplementary
49956 + groups of users you want to restrict socket access to, this patch
49957 + will perform up to three things, based on the option(s) you choose.
49958 +
49959 +config GRKERNSEC_SOCKET_ALL
49960 + bool "Deny any sockets to group"
49961 + depends on GRKERNSEC_SOCKET
49962 + help
49963 + If you say Y here, you will be able to choose a GID of whose users will
49964 + be unable to connect to other hosts from your machine or run server
49965 + applications from your machine. If the sysctl option is enabled, a
49966 + sysctl option with name "socket_all" is created.
49967 +
49968 +config GRKERNSEC_SOCKET_ALL_GID
49969 + int "GID to deny all sockets for"
49970 + depends on GRKERNSEC_SOCKET_ALL
49971 + default 1004
49972 + help
49973 + Here you can choose the GID to disable socket access for. Remember to
49974 + add the users you want socket access disabled for to the GID
49975 + specified here. If the sysctl option is enabled, a sysctl option
49976 + with name "socket_all_gid" is created.
49977 +
49978 +config GRKERNSEC_SOCKET_CLIENT
49979 + bool "Deny client sockets to group"
49980 + depends on GRKERNSEC_SOCKET
49981 + help
49982 + If you say Y here, you will be able to choose a GID of whose users will
49983 + be unable to connect to other hosts from your machine, but will be
49984 + able to run servers. If this option is enabled, all users in the group
49985 + you specify will have to use passive mode when initiating ftp transfers
49986 + from the shell on your machine. If the sysctl option is enabled, a
49987 + sysctl option with name "socket_client" is created.
49988 +
49989 +config GRKERNSEC_SOCKET_CLIENT_GID
49990 + int "GID to deny client sockets for"
49991 + depends on GRKERNSEC_SOCKET_CLIENT
49992 + default 1003
49993 + help
49994 + Here you can choose the GID to disable client socket access for.
49995 + Remember to add the users you want client socket access disabled for to
49996 + the GID specified here. If the sysctl option is enabled, a sysctl
49997 + option with name "socket_client_gid" is created.
49998 +
49999 +config GRKERNSEC_SOCKET_SERVER
50000 + bool "Deny server sockets to group"
50001 + depends on GRKERNSEC_SOCKET
50002 + help
50003 + If you say Y here, you will be able to choose a GID of whose users will
50004 + be unable to run server applications from your machine. If the sysctl
50005 + option is enabled, a sysctl option with name "socket_server" is created.
50006 +
50007 +config GRKERNSEC_SOCKET_SERVER_GID
50008 + int "GID to deny server sockets for"
50009 + depends on GRKERNSEC_SOCKET_SERVER
50010 + default 1002
50011 + help
50012 + Here you can choose the GID to disable server socket access for.
50013 + Remember to add the users you want server socket access disabled for to
50014 + the GID specified here. If the sysctl option is enabled, a sysctl
50015 + option with name "socket_server_gid" is created.
50016 +
50017 +endmenu
50018 +menu "Sysctl Support"
50019 +depends on GRKERNSEC && SYSCTL
50020 +
50021 +config GRKERNSEC_SYSCTL
50022 + bool "Sysctl support"
50023 + default y if GRKERNSEC_CONFIG_AUTO
50024 + help
50025 + If you say Y here, you will be able to change the options that
50026 + grsecurity runs with at bootup, without having to recompile your
50027 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
50028 + to enable (1) or disable (0) various features. All the sysctl entries
50029 + are mutable until the "grsec_lock" entry is set to a non-zero value.
50030 + All features enabled in the kernel configuration are disabled at boot
50031 + if you do not say Y to the "Turn on features by default" option.
50032 + All options should be set at startup, and the grsec_lock entry should
50033 + be set to a non-zero value after all the options are set.
50034 + *THIS IS EXTREMELY IMPORTANT*
50035 +
50036 +config GRKERNSEC_SYSCTL_DISTRO
50037 + bool "Extra sysctl support for distro makers (READ HELP)"
50038 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
50039 + help
50040 + If you say Y here, additional sysctl options will be created
50041 + for features that affect processes running as root. Therefore,
50042 + it is critical when using this option that the grsec_lock entry be
50043 + enabled after boot. Only distros with prebuilt kernel packages
50044 + with this option enabled that can ensure grsec_lock is enabled
50045 + after boot should use this option.
50046 + *Failure to set grsec_lock after boot makes all grsec features
50047 + this option covers useless*
50048 +
50049 + Currently this option creates the following sysctl entries:
50050 + "Disable Privileged I/O": "disable_priv_io"
50051 +
50052 +config GRKERNSEC_SYSCTL_ON
50053 + bool "Turn on features by default"
50054 + default y if GRKERNSEC_CONFIG_AUTO
50055 + depends on GRKERNSEC_SYSCTL
50056 + help
50057 + If you say Y here, instead of having all features enabled in the
50058 + kernel configuration disabled at boot time, the features will be
50059 + enabled at boot time. It is recommended you say Y here unless
50060 + there is some reason you would want all sysctl-tunable features to
50061 + be disabled by default. As mentioned elsewhere, it is important
50062 + to enable the grsec_lock entry once you have finished modifying
50063 + the sysctl entries.
50064 +
50065 +endmenu
50066 +menu "Logging Options"
50067 +depends on GRKERNSEC
50068 +
50069 +config GRKERNSEC_FLOODTIME
50070 + int "Seconds in between log messages (minimum)"
50071 + default 10
50072 + help
50073 + This option allows you to enforce the number of seconds between
50074 + grsecurity log messages. The default should be suitable for most
50075 + people, however, if you choose to change it, choose a value small enough
50076 + to allow informative logs to be produced, but large enough to
50077 + prevent flooding.
50078 +
50079 +config GRKERNSEC_FLOODBURST
50080 + int "Number of messages in a burst (maximum)"
50081 + default 6
50082 + help
50083 + This option allows you to choose the maximum number of messages allowed
50084 + within the flood time interval you chose in a separate option. The
50085 + default should be suitable for most people, however if you find that
50086 + many of your logs are being interpreted as flooding, you may want to
50087 + raise this value.
50088 +
50089 +endmenu
50090 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
50091 new file mode 100644
50092 index 0000000..1b9afa9
50093 --- /dev/null
50094 +++ b/grsecurity/Makefile
50095 @@ -0,0 +1,38 @@
50096 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
50097 +# during 2001-2009 it has been completely redesigned by Brad Spengler
50098 +# into an RBAC system
50099 +#
50100 +# All code in this directory and various hooks inserted throughout the kernel
50101 +# are copyright Brad Spengler - Open Source Security, Inc., and released
50102 +# under the GPL v2 or higher
50103 +
50104 +KBUILD_CFLAGS += -Werror
50105 +
50106 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
50107 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
50108 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
50109 +
50110 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
50111 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
50112 + gracl_learn.o grsec_log.o
50113 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
50114 +
50115 +ifdef CONFIG_NET
50116 +obj-y += grsec_sock.o
50117 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
50118 +endif
50119 +
50120 +ifndef CONFIG_GRKERNSEC
50121 +obj-y += grsec_disabled.o
50122 +endif
50123 +
50124 +ifdef CONFIG_GRKERNSEC_HIDESYM
50125 +extra-y := grsec_hidesym.o
50126 +$(obj)/grsec_hidesym.o:
50127 + @-chmod -f 500 /boot
50128 + @-chmod -f 500 /lib/modules
50129 + @-chmod -f 500 /lib64/modules
50130 + @-chmod -f 500 /lib32/modules
50131 + @-chmod -f 700 .
50132 + @echo ' grsec: protected kernel image paths'
50133 +endif
50134 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
50135 new file mode 100644
50136 index 0000000..dc0417e
50137 --- /dev/null
50138 +++ b/grsecurity/gracl.c
50139 @@ -0,0 +1,4016 @@
50140 +#include <linux/kernel.h>
50141 +#include <linux/module.h>
50142 +#include <linux/sched.h>
50143 +#include <linux/mm.h>
50144 +#include <linux/file.h>
50145 +#include <linux/fs.h>
50146 +#include <linux/namei.h>
50147 +#include <linux/mount.h>
50148 +#include <linux/tty.h>
50149 +#include <linux/proc_fs.h>
50150 +#include <linux/lglock.h>
50151 +#include <linux/slab.h>
50152 +#include <linux/vmalloc.h>
50153 +#include <linux/types.h>
50154 +#include <linux/sysctl.h>
50155 +#include <linux/netdevice.h>
50156 +#include <linux/ptrace.h>
50157 +#include <linux/gracl.h>
50158 +#include <linux/gralloc.h>
50159 +#include <linux/security.h>
50160 +#include <linux/grinternal.h>
50161 +#include <linux/pid_namespace.h>
50162 +#include <linux/fdtable.h>
50163 +#include <linux/percpu.h>
50164 +#include "../fs/mount.h"
50165 +
50166 +#include <asm/uaccess.h>
50167 +#include <asm/errno.h>
50168 +#include <asm/mman.h>
50169 +
50170 +static struct acl_role_db acl_role_set;
50171 +static struct name_db name_set;
50172 +static struct inodev_db inodev_set;
50173 +
50174 +/* for keeping track of userspace pointers used for subjects, so we
50175 + can share references in the kernel as well
50176 +*/
50177 +
50178 +static struct path real_root;
50179 +
50180 +static struct acl_subj_map_db subj_map_set;
50181 +
50182 +static struct acl_role_label *default_role;
50183 +
50184 +static struct acl_role_label *role_list;
50185 +
50186 +static u16 acl_sp_role_value;
50187 +
50188 +extern char *gr_shared_page[4];
50189 +static DEFINE_MUTEX(gr_dev_mutex);
50190 +DEFINE_RWLOCK(gr_inode_lock);
50191 +
50192 +struct gr_arg *gr_usermode;
50193 +
50194 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
50195 +
50196 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
50197 +extern void gr_clear_learn_entries(void);
50198 +
50199 +#ifdef CONFIG_GRKERNSEC_RESLOG
50200 +extern void gr_log_resource(const struct task_struct *task,
50201 + const int res, const unsigned long wanted, const int gt);
50202 +#endif
50203 +
50204 +unsigned char *gr_system_salt;
50205 +unsigned char *gr_system_sum;
50206 +
50207 +static struct sprole_pw **acl_special_roles = NULL;
50208 +static __u16 num_sprole_pws = 0;
50209 +
50210 +static struct acl_role_label *kernel_role = NULL;
50211 +
50212 +static unsigned int gr_auth_attempts = 0;
50213 +static unsigned long gr_auth_expires = 0UL;
50214 +
50215 +#ifdef CONFIG_NET
50216 +extern struct vfsmount *sock_mnt;
50217 +#endif
50218 +
50219 +extern struct vfsmount *pipe_mnt;
50220 +extern struct vfsmount *shm_mnt;
50221 +#ifdef CONFIG_HUGETLBFS
50222 +extern struct vfsmount *hugetlbfs_vfsmount;
50223 +#endif
50224 +
50225 +static struct acl_object_label *fakefs_obj_rw;
50226 +static struct acl_object_label *fakefs_obj_rwx;
50227 +
50228 +extern int gr_init_uidset(void);
50229 +extern void gr_free_uidset(void);
50230 +extern void gr_remove_uid(uid_t uid);
50231 +extern int gr_find_uid(uid_t uid);
50232 +
50233 +DECLARE_BRLOCK(vfsmount_lock);
50234 +
50235 +__inline__ int
50236 +gr_acl_is_enabled(void)
50237 +{
50238 + return (gr_status & GR_READY);
50239 +}
50240 +
50241 +#ifdef CONFIG_BTRFS_FS
50242 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
50243 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
50244 +#endif
50245 +
50246 +static inline dev_t __get_dev(const struct dentry *dentry)
50247 +{
50248 +#ifdef CONFIG_BTRFS_FS
50249 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
50250 + return get_btrfs_dev_from_inode(dentry->d_inode);
50251 + else
50252 +#endif
50253 + return dentry->d_inode->i_sb->s_dev;
50254 +}
50255 +
50256 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
50257 +{
50258 + return __get_dev(dentry);
50259 +}
50260 +
50261 +static char gr_task_roletype_to_char(struct task_struct *task)
50262 +{
50263 + switch (task->role->roletype &
50264 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
50265 + GR_ROLE_SPECIAL)) {
50266 + case GR_ROLE_DEFAULT:
50267 + return 'D';
50268 + case GR_ROLE_USER:
50269 + return 'U';
50270 + case GR_ROLE_GROUP:
50271 + return 'G';
50272 + case GR_ROLE_SPECIAL:
50273 + return 'S';
50274 + }
50275 +
50276 + return 'X';
50277 +}
50278 +
50279 +char gr_roletype_to_char(void)
50280 +{
50281 + return gr_task_roletype_to_char(current);
50282 +}
50283 +
50284 +__inline__ int
50285 +gr_acl_tpe_check(void)
50286 +{
50287 + if (unlikely(!(gr_status & GR_READY)))
50288 + return 0;
50289 + if (current->role->roletype & GR_ROLE_TPE)
50290 + return 1;
50291 + else
50292 + return 0;
50293 +}
50294 +
50295 +int
50296 +gr_handle_rawio(const struct inode *inode)
50297 +{
50298 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
50299 + if (inode && S_ISBLK(inode->i_mode) &&
50300 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
50301 + !capable(CAP_SYS_RAWIO))
50302 + return 1;
50303 +#endif
50304 + return 0;
50305 +}
50306 +
50307 +static int
50308 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
50309 +{
50310 + if (likely(lena != lenb))
50311 + return 0;
50312 +
50313 + return !memcmp(a, b, lena);
50314 +}
50315 +
50316 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
50317 +{
50318 + *buflen -= namelen;
50319 + if (*buflen < 0)
50320 + return -ENAMETOOLONG;
50321 + *buffer -= namelen;
50322 + memcpy(*buffer, str, namelen);
50323 + return 0;
50324 +}
50325 +
50326 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
50327 +{
50328 + return prepend(buffer, buflen, name->name, name->len);
50329 +}
50330 +
50331 +static int prepend_path(const struct path *path, struct path *root,
50332 + char **buffer, int *buflen)
50333 +{
50334 + struct dentry *dentry = path->dentry;
50335 + struct vfsmount *vfsmnt = path->mnt;
50336 + struct mount *mnt = real_mount(vfsmnt);
50337 + bool slash = false;
50338 + int error = 0;
50339 +
50340 + while (dentry != root->dentry || vfsmnt != root->mnt) {
50341 + struct dentry * parent;
50342 +
50343 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
50344 + /* Global root? */
50345 + if (!mnt_has_parent(mnt)) {
50346 + goto out;
50347 + }
50348 + dentry = mnt->mnt_mountpoint;
50349 + mnt = mnt->mnt_parent;
50350 + vfsmnt = &mnt->mnt;
50351 + continue;
50352 + }
50353 + parent = dentry->d_parent;
50354 + prefetch(parent);
50355 + spin_lock(&dentry->d_lock);
50356 + error = prepend_name(buffer, buflen, &dentry->d_name);
50357 + spin_unlock(&dentry->d_lock);
50358 + if (!error)
50359 + error = prepend(buffer, buflen, "/", 1);
50360 + if (error)
50361 + break;
50362 +
50363 + slash = true;
50364 + dentry = parent;
50365 + }
50366 +
50367 +out:
50368 + if (!error && !slash)
50369 + error = prepend(buffer, buflen, "/", 1);
50370 +
50371 + return error;
50372 +}
50373 +
50374 +/* this must be called with vfsmount_lock and rename_lock held */
50375 +
50376 +static char *__our_d_path(const struct path *path, struct path *root,
50377 + char *buf, int buflen)
50378 +{
50379 + char *res = buf + buflen;
50380 + int error;
50381 +
50382 + prepend(&res, &buflen, "\0", 1);
50383 + error = prepend_path(path, root, &res, &buflen);
50384 + if (error)
50385 + return ERR_PTR(error);
50386 +
50387 + return res;
50388 +}
50389 +
50390 +static char *
50391 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
50392 +{
50393 + char *retval;
50394 +
50395 + retval = __our_d_path(path, root, buf, buflen);
50396 + if (unlikely(IS_ERR(retval)))
50397 + retval = strcpy(buf, "<path too long>");
50398 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
50399 + retval[1] = '\0';
50400 +
50401 + return retval;
50402 +}
50403 +
50404 +static char *
50405 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
50406 + char *buf, int buflen)
50407 +{
50408 + struct path path;
50409 + char *res;
50410 +
50411 + path.dentry = (struct dentry *)dentry;
50412 + path.mnt = (struct vfsmount *)vfsmnt;
50413 +
50414 + /* we can use real_root.dentry, real_root.mnt, because this is only called
50415 + by the RBAC system */
50416 + res = gen_full_path(&path, &real_root, buf, buflen);
50417 +
50418 + return res;
50419 +}
50420 +
50421 +static char *
50422 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
50423 + char *buf, int buflen)
50424 +{
50425 + char *res;
50426 + struct path path;
50427 + struct path root;
50428 + struct task_struct *reaper = init_pid_ns.child_reaper;
50429 +
50430 + path.dentry = (struct dentry *)dentry;
50431 + path.mnt = (struct vfsmount *)vfsmnt;
50432 +
50433 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
50434 + get_fs_root(reaper->fs, &root);
50435 +
50436 + write_seqlock(&rename_lock);
50437 + br_read_lock(vfsmount_lock);
50438 + res = gen_full_path(&path, &root, buf, buflen);
50439 + br_read_unlock(vfsmount_lock);
50440 + write_sequnlock(&rename_lock);
50441 +
50442 + path_put(&root);
50443 + return res;
50444 +}
50445 +
50446 +static char *
50447 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
50448 +{
50449 + char *ret;
50450 + write_seqlock(&rename_lock);
50451 + br_read_lock(vfsmount_lock);
50452 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
50453 + PAGE_SIZE);
50454 + br_read_unlock(vfsmount_lock);
50455 + write_sequnlock(&rename_lock);
50456 + return ret;
50457 +}
50458 +
50459 +static char *
50460 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
50461 +{
50462 + char *ret;
50463 + char *buf;
50464 + int buflen;
50465 +
50466 + write_seqlock(&rename_lock);
50467 + br_read_lock(vfsmount_lock);
50468 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
50469 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
50470 + buflen = (int)(ret - buf);
50471 + if (buflen >= 5)
50472 + prepend(&ret, &buflen, "/proc", 5);
50473 + else
50474 + ret = strcpy(buf, "<path too long>");
50475 + br_read_unlock(vfsmount_lock);
50476 + write_sequnlock(&rename_lock);
50477 + return ret;
50478 +}
50479 +
50480 +char *
50481 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
50482 +{
50483 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
50484 + PAGE_SIZE);
50485 +}
50486 +
50487 +char *
50488 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
50489 +{
50490 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
50491 + PAGE_SIZE);
50492 +}
50493 +
50494 +char *
50495 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
50496 +{
50497 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
50498 + PAGE_SIZE);
50499 +}
50500 +
50501 +char *
50502 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
50503 +{
50504 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
50505 + PAGE_SIZE);
50506 +}
50507 +
50508 +char *
50509 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
50510 +{
50511 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
50512 + PAGE_SIZE);
50513 +}
50514 +
50515 +__inline__ __u32
50516 +to_gr_audit(const __u32 reqmode)
50517 +{
50518 + /* masks off auditable permission flags, then shifts them to create
50519 + auditing flags, and adds the special case of append auditing if
50520 + we're requesting write */
50521 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
50522 +}
50523 +
50524 +struct acl_subject_label *
50525 +lookup_subject_map(const struct acl_subject_label *userp)
50526 +{
50527 + unsigned int index = shash(userp, subj_map_set.s_size);
50528 + struct subject_map *match;
50529 +
50530 + match = subj_map_set.s_hash[index];
50531 +
50532 + while (match && match->user != userp)
50533 + match = match->next;
50534 +
50535 + if (match != NULL)
50536 + return match->kernel;
50537 + else
50538 + return NULL;
50539 +}
50540 +
50541 +static void
50542 +insert_subj_map_entry(struct subject_map *subjmap)
50543 +{
50544 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
50545 + struct subject_map **curr;
50546 +
50547 + subjmap->prev = NULL;
50548 +
50549 + curr = &subj_map_set.s_hash[index];
50550 + if (*curr != NULL)
50551 + (*curr)->prev = subjmap;
50552 +
50553 + subjmap->next = *curr;
50554 + *curr = subjmap;
50555 +
50556 + return;
50557 +}
50558 +
50559 +static struct acl_role_label *
50560 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
50561 + const gid_t gid)
50562 +{
50563 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
50564 + struct acl_role_label *match;
50565 + struct role_allowed_ip *ipp;
50566 + unsigned int x;
50567 + u32 curr_ip = task->signal->curr_ip;
50568 +
50569 + task->signal->saved_ip = curr_ip;
50570 +
50571 + match = acl_role_set.r_hash[index];
50572 +
50573 + while (match) {
50574 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
50575 + for (x = 0; x < match->domain_child_num; x++) {
50576 + if (match->domain_children[x] == uid)
50577 + goto found;
50578 + }
50579 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
50580 + break;
50581 + match = match->next;
50582 + }
50583 +found:
50584 + if (match == NULL) {
50585 + try_group:
50586 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
50587 + match = acl_role_set.r_hash[index];
50588 +
50589 + while (match) {
50590 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
50591 + for (x = 0; x < match->domain_child_num; x++) {
50592 + if (match->domain_children[x] == gid)
50593 + goto found2;
50594 + }
50595 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
50596 + break;
50597 + match = match->next;
50598 + }
50599 +found2:
50600 + if (match == NULL)
50601 + match = default_role;
50602 + if (match->allowed_ips == NULL)
50603 + return match;
50604 + else {
50605 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
50606 + if (likely
50607 + ((ntohl(curr_ip) & ipp->netmask) ==
50608 + (ntohl(ipp->addr) & ipp->netmask)))
50609 + return match;
50610 + }
50611 + match = default_role;
50612 + }
50613 + } else if (match->allowed_ips == NULL) {
50614 + return match;
50615 + } else {
50616 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
50617 + if (likely
50618 + ((ntohl(curr_ip) & ipp->netmask) ==
50619 + (ntohl(ipp->addr) & ipp->netmask)))
50620 + return match;
50621 + }
50622 + goto try_group;
50623 + }
50624 +
50625 + return match;
50626 +}
50627 +
50628 +struct acl_subject_label *
50629 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
50630 + const struct acl_role_label *role)
50631 +{
50632 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
50633 + struct acl_subject_label *match;
50634 +
50635 + match = role->subj_hash[index];
50636 +
50637 + while (match && (match->inode != ino || match->device != dev ||
50638 + (match->mode & GR_DELETED))) {
50639 + match = match->next;
50640 + }
50641 +
50642 + if (match && !(match->mode & GR_DELETED))
50643 + return match;
50644 + else
50645 + return NULL;
50646 +}
50647 +
50648 +struct acl_subject_label *
50649 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
50650 + const struct acl_role_label *role)
50651 +{
50652 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
50653 + struct acl_subject_label *match;
50654 +
50655 + match = role->subj_hash[index];
50656 +
50657 + while (match && (match->inode != ino || match->device != dev ||
50658 + !(match->mode & GR_DELETED))) {
50659 + match = match->next;
50660 + }
50661 +
50662 + if (match && (match->mode & GR_DELETED))
50663 + return match;
50664 + else
50665 + return NULL;
50666 +}
50667 +
50668 +static struct acl_object_label *
50669 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
50670 + const struct acl_subject_label *subj)
50671 +{
50672 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
50673 + struct acl_object_label *match;
50674 +
50675 + match = subj->obj_hash[index];
50676 +
50677 + while (match && (match->inode != ino || match->device != dev ||
50678 + (match->mode & GR_DELETED))) {
50679 + match = match->next;
50680 + }
50681 +
50682 + if (match && !(match->mode & GR_DELETED))
50683 + return match;
50684 + else
50685 + return NULL;
50686 +}
50687 +
50688 +static struct acl_object_label *
50689 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
50690 + const struct acl_subject_label *subj)
50691 +{
50692 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
50693 + struct acl_object_label *match;
50694 +
50695 + match = subj->obj_hash[index];
50696 +
50697 + while (match && (match->inode != ino || match->device != dev ||
50698 + !(match->mode & GR_DELETED))) {
50699 + match = match->next;
50700 + }
50701 +
50702 + if (match && (match->mode & GR_DELETED))
50703 + return match;
50704 +
50705 + match = subj->obj_hash[index];
50706 +
50707 + while (match && (match->inode != ino || match->device != dev ||
50708 + (match->mode & GR_DELETED))) {
50709 + match = match->next;
50710 + }
50711 +
50712 + if (match && !(match->mode & GR_DELETED))
50713 + return match;
50714 + else
50715 + return NULL;
50716 +}
50717 +
50718 +static struct name_entry *
50719 +lookup_name_entry(const char *name)
50720 +{
50721 + unsigned int len = strlen(name);
50722 + unsigned int key = full_name_hash(name, len);
50723 + unsigned int index = key % name_set.n_size;
50724 + struct name_entry *match;
50725 +
50726 + match = name_set.n_hash[index];
50727 +
50728 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
50729 + match = match->next;
50730 +
50731 + return match;
50732 +}
50733 +
50734 +static struct name_entry *
50735 +lookup_name_entry_create(const char *name)
50736 +{
50737 + unsigned int len = strlen(name);
50738 + unsigned int key = full_name_hash(name, len);
50739 + unsigned int index = key % name_set.n_size;
50740 + struct name_entry *match;
50741 +
50742 + match = name_set.n_hash[index];
50743 +
50744 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
50745 + !match->deleted))
50746 + match = match->next;
50747 +
50748 + if (match && match->deleted)
50749 + return match;
50750 +
50751 + match = name_set.n_hash[index];
50752 +
50753 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
50754 + match->deleted))
50755 + match = match->next;
50756 +
50757 + if (match && !match->deleted)
50758 + return match;
50759 + else
50760 + return NULL;
50761 +}
50762 +
50763 +static struct inodev_entry *
50764 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
50765 +{
50766 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
50767 + struct inodev_entry *match;
50768 +
50769 + match = inodev_set.i_hash[index];
50770 +
50771 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
50772 + match = match->next;
50773 +
50774 + return match;
50775 +}
50776 +
50777 +static void
50778 +insert_inodev_entry(struct inodev_entry *entry)
50779 +{
50780 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
50781 + inodev_set.i_size);
50782 + struct inodev_entry **curr;
50783 +
50784 + entry->prev = NULL;
50785 +
50786 + curr = &inodev_set.i_hash[index];
50787 + if (*curr != NULL)
50788 + (*curr)->prev = entry;
50789 +
50790 + entry->next = *curr;
50791 + *curr = entry;
50792 +
50793 + return;
50794 +}
50795 +
50796 +static void
50797 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
50798 +{
50799 + unsigned int index =
50800 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
50801 + struct acl_role_label **curr;
50802 + struct acl_role_label *tmp, *tmp2;
50803 +
50804 + curr = &acl_role_set.r_hash[index];
50805 +
50806 + /* simple case, slot is empty, just set it to our role */
50807 + if (*curr == NULL) {
50808 + *curr = role;
50809 + } else {
50810 + /* example:
50811 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
50812 + 2 -> 3
50813 + */
50814 + /* first check to see if we can already be reached via this slot */
50815 + tmp = *curr;
50816 + while (tmp && tmp != role)
50817 + tmp = tmp->next;
50818 + if (tmp == role) {
50819 + /* we don't need to add ourselves to this slot's chain */
50820 + return;
50821 + }
50822 + /* we need to add ourselves to this chain, two cases */
50823 + if (role->next == NULL) {
50824 + /* simple case, append the current chain to our role */
50825 + role->next = *curr;
50826 + *curr = role;
50827 + } else {
50828 + /* 1 -> 2 -> 3 -> 4
50829 + 2 -> 3 -> 4
50830 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
50831 + */
50832 + /* trickier case: walk our role's chain until we find
50833 + the role for the start of the current slot's chain */
50834 + tmp = role;
50835 + tmp2 = *curr;
50836 + while (tmp->next && tmp->next != tmp2)
50837 + tmp = tmp->next;
50838 + if (tmp->next == tmp2) {
50839 + /* from example above, we found 3, so just
50840 + replace this slot's chain with ours */
50841 + *curr = role;
50842 + } else {
50843 + /* we didn't find a subset of our role's chain
50844 + in the current slot's chain, so append their
50845 + chain to ours, and set us as the first role in
50846 + the slot's chain
50847 +
50848 + we could fold this case with the case above,
50849 + but making it explicit for clarity
50850 + */
50851 + tmp->next = tmp2;
50852 + *curr = role;
50853 + }
50854 + }
50855 + }
50856 +
50857 + return;
50858 +}
50859 +
50860 +static void
50861 +insert_acl_role_label(struct acl_role_label *role)
50862 +{
50863 + int i;
50864 +
50865 + if (role_list == NULL) {
50866 + role_list = role;
50867 + role->prev = NULL;
50868 + } else {
50869 + role->prev = role_list;
50870 + role_list = role;
50871 + }
50872 +
50873 + /* used for hash chains */
50874 + role->next = NULL;
50875 +
50876 + if (role->roletype & GR_ROLE_DOMAIN) {
50877 + for (i = 0; i < role->domain_child_num; i++)
50878 + __insert_acl_role_label(role, role->domain_children[i]);
50879 + } else
50880 + __insert_acl_role_label(role, role->uidgid);
50881 +}
50882 +
50883 +static int
50884 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
50885 +{
50886 + struct name_entry **curr, *nentry;
50887 + struct inodev_entry *ientry;
50888 + unsigned int len = strlen(name);
50889 + unsigned int key = full_name_hash(name, len);
50890 + unsigned int index = key % name_set.n_size;
50891 +
50892 + curr = &name_set.n_hash[index];
50893 +
50894 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
50895 + curr = &((*curr)->next);
50896 +
50897 + if (*curr != NULL)
50898 + return 1;
50899 +
50900 + nentry = acl_alloc(sizeof (struct name_entry));
50901 + if (nentry == NULL)
50902 + return 0;
50903 + ientry = acl_alloc(sizeof (struct inodev_entry));
50904 + if (ientry == NULL)
50905 + return 0;
50906 + ientry->nentry = nentry;
50907 +
50908 + nentry->key = key;
50909 + nentry->name = name;
50910 + nentry->inode = inode;
50911 + nentry->device = device;
50912 + nentry->len = len;
50913 + nentry->deleted = deleted;
50914 +
50915 + nentry->prev = NULL;
50916 + curr = &name_set.n_hash[index];
50917 + if (*curr != NULL)
50918 + (*curr)->prev = nentry;
50919 + nentry->next = *curr;
50920 + *curr = nentry;
50921 +
50922 + /* insert us into the table searchable by inode/dev */
50923 + insert_inodev_entry(ientry);
50924 +
50925 + return 1;
50926 +}
50927 +
50928 +static void
50929 +insert_acl_obj_label(struct acl_object_label *obj,
50930 + struct acl_subject_label *subj)
50931 +{
50932 + unsigned int index =
50933 + fhash(obj->inode, obj->device, subj->obj_hash_size);
50934 + struct acl_object_label **curr;
50935 +
50936 +
50937 + obj->prev = NULL;
50938 +
50939 + curr = &subj->obj_hash[index];
50940 + if (*curr != NULL)
50941 + (*curr)->prev = obj;
50942 +
50943 + obj->next = *curr;
50944 + *curr = obj;
50945 +
50946 + return;
50947 +}
50948 +
50949 +static void
50950 +insert_acl_subj_label(struct acl_subject_label *obj,
50951 + struct acl_role_label *role)
50952 +{
50953 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
50954 + struct acl_subject_label **curr;
50955 +
50956 + obj->prev = NULL;
50957 +
50958 + curr = &role->subj_hash[index];
50959 + if (*curr != NULL)
50960 + (*curr)->prev = obj;
50961 +
50962 + obj->next = *curr;
50963 + *curr = obj;
50964 +
50965 + return;
50966 +}
50967 +
50968 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
50969 +
50970 +static void *
50971 +create_table(__u32 * len, int elementsize)
50972 +{
50973 + unsigned int table_sizes[] = {
50974 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
50975 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
50976 + 4194301, 8388593, 16777213, 33554393, 67108859
50977 + };
50978 + void *newtable = NULL;
50979 + unsigned int pwr = 0;
50980 +
50981 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
50982 + table_sizes[pwr] <= *len)
50983 + pwr++;
50984 +
50985 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
50986 + return newtable;
50987 +
50988 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
50989 + newtable =
50990 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
50991 + else
50992 + newtable = vmalloc(table_sizes[pwr] * elementsize);
50993 +
50994 + *len = table_sizes[pwr];
50995 +
50996 + return newtable;
50997 +}
50998 +
50999 +static int
51000 +init_variables(const struct gr_arg *arg)
51001 +{
51002 + struct task_struct *reaper = init_pid_ns.child_reaper;
51003 + unsigned int stacksize;
51004 +
51005 + subj_map_set.s_size = arg->role_db.num_subjects;
51006 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
51007 + name_set.n_size = arg->role_db.num_objects;
51008 + inodev_set.i_size = arg->role_db.num_objects;
51009 +
51010 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
51011 + !name_set.n_size || !inodev_set.i_size)
51012 + return 1;
51013 +
51014 + if (!gr_init_uidset())
51015 + return 1;
51016 +
51017 + /* set up the stack that holds allocation info */
51018 +
51019 + stacksize = arg->role_db.num_pointers + 5;
51020 +
51021 + if (!acl_alloc_stack_init(stacksize))
51022 + return 1;
51023 +
51024 + /* grab reference for the real root dentry and vfsmount */
51025 + get_fs_root(reaper->fs, &real_root);
51026 +
51027 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51028 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
51029 +#endif
51030 +
51031 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
51032 + if (fakefs_obj_rw == NULL)
51033 + return 1;
51034 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
51035 +
51036 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
51037 + if (fakefs_obj_rwx == NULL)
51038 + return 1;
51039 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
51040 +
51041 + subj_map_set.s_hash =
51042 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
51043 + acl_role_set.r_hash =
51044 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
51045 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
51046 + inodev_set.i_hash =
51047 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
51048 +
51049 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
51050 + !name_set.n_hash || !inodev_set.i_hash)
51051 + return 1;
51052 +
51053 + memset(subj_map_set.s_hash, 0,
51054 + sizeof(struct subject_map *) * subj_map_set.s_size);
51055 + memset(acl_role_set.r_hash, 0,
51056 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
51057 + memset(name_set.n_hash, 0,
51058 + sizeof (struct name_entry *) * name_set.n_size);
51059 + memset(inodev_set.i_hash, 0,
51060 + sizeof (struct inodev_entry *) * inodev_set.i_size);
51061 +
51062 + return 0;
51063 +}
51064 +
51065 +/* free information not needed after startup
51066 + currently contains user->kernel pointer mappings for subjects
51067 +*/
51068 +
51069 +static void
51070 +free_init_variables(void)
51071 +{
51072 + __u32 i;
51073 +
51074 + if (subj_map_set.s_hash) {
51075 + for (i = 0; i < subj_map_set.s_size; i++) {
51076 + if (subj_map_set.s_hash[i]) {
51077 + kfree(subj_map_set.s_hash[i]);
51078 + subj_map_set.s_hash[i] = NULL;
51079 + }
51080 + }
51081 +
51082 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
51083 + PAGE_SIZE)
51084 + kfree(subj_map_set.s_hash);
51085 + else
51086 + vfree(subj_map_set.s_hash);
51087 + }
51088 +
51089 + return;
51090 +}
51091 +
51092 +static void
51093 +free_variables(void)
51094 +{
51095 + struct acl_subject_label *s;
51096 + struct acl_role_label *r;
51097 + struct task_struct *task, *task2;
51098 + unsigned int x;
51099 +
51100 + gr_clear_learn_entries();
51101 +
51102 + read_lock(&tasklist_lock);
51103 + do_each_thread(task2, task) {
51104 + task->acl_sp_role = 0;
51105 + task->acl_role_id = 0;
51106 + task->acl = NULL;
51107 + task->role = NULL;
51108 + } while_each_thread(task2, task);
51109 + read_unlock(&tasklist_lock);
51110 +
51111 + /* release the reference to the real root dentry and vfsmount */
51112 + path_put(&real_root);
51113 + memset(&real_root, 0, sizeof(real_root));
51114 +
51115 + /* free all object hash tables */
51116 +
51117 + FOR_EACH_ROLE_START(r)
51118 + if (r->subj_hash == NULL)
51119 + goto next_role;
51120 + FOR_EACH_SUBJECT_START(r, s, x)
51121 + if (s->obj_hash == NULL)
51122 + break;
51123 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51124 + kfree(s->obj_hash);
51125 + else
51126 + vfree(s->obj_hash);
51127 + FOR_EACH_SUBJECT_END(s, x)
51128 + FOR_EACH_NESTED_SUBJECT_START(r, s)
51129 + if (s->obj_hash == NULL)
51130 + break;
51131 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51132 + kfree(s->obj_hash);
51133 + else
51134 + vfree(s->obj_hash);
51135 + FOR_EACH_NESTED_SUBJECT_END(s)
51136 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
51137 + kfree(r->subj_hash);
51138 + else
51139 + vfree(r->subj_hash);
51140 + r->subj_hash = NULL;
51141 +next_role:
51142 + FOR_EACH_ROLE_END(r)
51143 +
51144 + acl_free_all();
51145 +
51146 + if (acl_role_set.r_hash) {
51147 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
51148 + PAGE_SIZE)
51149 + kfree(acl_role_set.r_hash);
51150 + else
51151 + vfree(acl_role_set.r_hash);
51152 + }
51153 + if (name_set.n_hash) {
51154 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
51155 + PAGE_SIZE)
51156 + kfree(name_set.n_hash);
51157 + else
51158 + vfree(name_set.n_hash);
51159 + }
51160 +
51161 + if (inodev_set.i_hash) {
51162 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
51163 + PAGE_SIZE)
51164 + kfree(inodev_set.i_hash);
51165 + else
51166 + vfree(inodev_set.i_hash);
51167 + }
51168 +
51169 + gr_free_uidset();
51170 +
51171 + memset(&name_set, 0, sizeof (struct name_db));
51172 + memset(&inodev_set, 0, sizeof (struct inodev_db));
51173 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
51174 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
51175 +
51176 + default_role = NULL;
51177 + kernel_role = NULL;
51178 + role_list = NULL;
51179 +
51180 + return;
51181 +}
51182 +
51183 +static __u32
51184 +count_user_objs(struct acl_object_label *userp)
51185 +{
51186 + struct acl_object_label o_tmp;
51187 + __u32 num = 0;
51188 +
51189 + while (userp) {
51190 + if (copy_from_user(&o_tmp, userp,
51191 + sizeof (struct acl_object_label)))
51192 + break;
51193 +
51194 + userp = o_tmp.prev;
51195 + num++;
51196 + }
51197 +
51198 + return num;
51199 +}
51200 +
51201 +static struct acl_subject_label *
51202 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
51203 +
51204 +static int
51205 +copy_user_glob(struct acl_object_label *obj)
51206 +{
51207 + struct acl_object_label *g_tmp, **guser;
51208 + unsigned int len;
51209 + char *tmp;
51210 +
51211 + if (obj->globbed == NULL)
51212 + return 0;
51213 +
51214 + guser = &obj->globbed;
51215 + while (*guser) {
51216 + g_tmp = (struct acl_object_label *)
51217 + acl_alloc(sizeof (struct acl_object_label));
51218 + if (g_tmp == NULL)
51219 + return -ENOMEM;
51220 +
51221 + if (copy_from_user(g_tmp, *guser,
51222 + sizeof (struct acl_object_label)))
51223 + return -EFAULT;
51224 +
51225 + len = strnlen_user(g_tmp->filename, PATH_MAX);
51226 +
51227 + if (!len || len >= PATH_MAX)
51228 + return -EINVAL;
51229 +
51230 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51231 + return -ENOMEM;
51232 +
51233 + if (copy_from_user(tmp, g_tmp->filename, len))
51234 + return -EFAULT;
51235 + tmp[len-1] = '\0';
51236 + g_tmp->filename = tmp;
51237 +
51238 + *guser = g_tmp;
51239 + guser = &(g_tmp->next);
51240 + }
51241 +
51242 + return 0;
51243 +}
51244 +
51245 +static int
51246 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
51247 + struct acl_role_label *role)
51248 +{
51249 + struct acl_object_label *o_tmp;
51250 + unsigned int len;
51251 + int ret;
51252 + char *tmp;
51253 +
51254 + while (userp) {
51255 + if ((o_tmp = (struct acl_object_label *)
51256 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
51257 + return -ENOMEM;
51258 +
51259 + if (copy_from_user(o_tmp, userp,
51260 + sizeof (struct acl_object_label)))
51261 + return -EFAULT;
51262 +
51263 + userp = o_tmp->prev;
51264 +
51265 + len = strnlen_user(o_tmp->filename, PATH_MAX);
51266 +
51267 + if (!len || len >= PATH_MAX)
51268 + return -EINVAL;
51269 +
51270 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51271 + return -ENOMEM;
51272 +
51273 + if (copy_from_user(tmp, o_tmp->filename, len))
51274 + return -EFAULT;
51275 + tmp[len-1] = '\0';
51276 + o_tmp->filename = tmp;
51277 +
51278 + insert_acl_obj_label(o_tmp, subj);
51279 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
51280 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
51281 + return -ENOMEM;
51282 +
51283 + ret = copy_user_glob(o_tmp);
51284 + if (ret)
51285 + return ret;
51286 +
51287 + if (o_tmp->nested) {
51288 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
51289 + if (IS_ERR(o_tmp->nested))
51290 + return PTR_ERR(o_tmp->nested);
51291 +
51292 + /* insert into nested subject list */
51293 + o_tmp->nested->next = role->hash->first;
51294 + role->hash->first = o_tmp->nested;
51295 + }
51296 + }
51297 +
51298 + return 0;
51299 +}
51300 +
51301 +static __u32
51302 +count_user_subjs(struct acl_subject_label *userp)
51303 +{
51304 + struct acl_subject_label s_tmp;
51305 + __u32 num = 0;
51306 +
51307 + while (userp) {
51308 + if (copy_from_user(&s_tmp, userp,
51309 + sizeof (struct acl_subject_label)))
51310 + break;
51311 +
51312 + userp = s_tmp.prev;
51313 + /* do not count nested subjects against this count, since
51314 + they are not included in the hash table, but are
51315 + attached to objects. We have already counted
51316 + the subjects in userspace for the allocation
51317 + stack
51318 + */
51319 + if (!(s_tmp.mode & GR_NESTED))
51320 + num++;
51321 + }
51322 +
51323 + return num;
51324 +}
51325 +
51326 +static int
51327 +copy_user_allowedips(struct acl_role_label *rolep)
51328 +{
51329 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
51330 +
51331 + ruserip = rolep->allowed_ips;
51332 +
51333 + while (ruserip) {
51334 + rlast = rtmp;
51335 +
51336 + if ((rtmp = (struct role_allowed_ip *)
51337 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
51338 + return -ENOMEM;
51339 +
51340 + if (copy_from_user(rtmp, ruserip,
51341 + sizeof (struct role_allowed_ip)))
51342 + return -EFAULT;
51343 +
51344 + ruserip = rtmp->prev;
51345 +
51346 + if (!rlast) {
51347 + rtmp->prev = NULL;
51348 + rolep->allowed_ips = rtmp;
51349 + } else {
51350 + rlast->next = rtmp;
51351 + rtmp->prev = rlast;
51352 + }
51353 +
51354 + if (!ruserip)
51355 + rtmp->next = NULL;
51356 + }
51357 +
51358 + return 0;
51359 +}
51360 +
51361 +static int
51362 +copy_user_transitions(struct acl_role_label *rolep)
51363 +{
51364 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
51365 +
51366 + unsigned int len;
51367 + char *tmp;
51368 +
51369 + rusertp = rolep->transitions;
51370 +
51371 + while (rusertp) {
51372 + rlast = rtmp;
51373 +
51374 + if ((rtmp = (struct role_transition *)
51375 + acl_alloc(sizeof (struct role_transition))) == NULL)
51376 + return -ENOMEM;
51377 +
51378 + if (copy_from_user(rtmp, rusertp,
51379 + sizeof (struct role_transition)))
51380 + return -EFAULT;
51381 +
51382 + rusertp = rtmp->prev;
51383 +
51384 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
51385 +
51386 + if (!len || len >= GR_SPROLE_LEN)
51387 + return -EINVAL;
51388 +
51389 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51390 + return -ENOMEM;
51391 +
51392 + if (copy_from_user(tmp, rtmp->rolename, len))
51393 + return -EFAULT;
51394 + tmp[len-1] = '\0';
51395 + rtmp->rolename = tmp;
51396 +
51397 + if (!rlast) {
51398 + rtmp->prev = NULL;
51399 + rolep->transitions = rtmp;
51400 + } else {
51401 + rlast->next = rtmp;
51402 + rtmp->prev = rlast;
51403 + }
51404 +
51405 + if (!rusertp)
51406 + rtmp->next = NULL;
51407 + }
51408 +
51409 + return 0;
51410 +}
51411 +
51412 +static struct acl_subject_label *
51413 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
51414 +{
51415 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
51416 + unsigned int len;
51417 + char *tmp;
51418 + __u32 num_objs;
51419 + struct acl_ip_label **i_tmp, *i_utmp2;
51420 + struct gr_hash_struct ghash;
51421 + struct subject_map *subjmap;
51422 + unsigned int i_num;
51423 + int err;
51424 +
51425 + s_tmp = lookup_subject_map(userp);
51426 +
51427 + /* we've already copied this subject into the kernel, just return
51428 + the reference to it, and don't copy it over again
51429 + */
51430 + if (s_tmp)
51431 + return(s_tmp);
51432 +
51433 + if ((s_tmp = (struct acl_subject_label *)
51434 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
51435 + return ERR_PTR(-ENOMEM);
51436 +
51437 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
51438 + if (subjmap == NULL)
51439 + return ERR_PTR(-ENOMEM);
51440 +
51441 + subjmap->user = userp;
51442 + subjmap->kernel = s_tmp;
51443 + insert_subj_map_entry(subjmap);
51444 +
51445 + if (copy_from_user(s_tmp, userp,
51446 + sizeof (struct acl_subject_label)))
51447 + return ERR_PTR(-EFAULT);
51448 +
51449 + len = strnlen_user(s_tmp->filename, PATH_MAX);
51450 +
51451 + if (!len || len >= PATH_MAX)
51452 + return ERR_PTR(-EINVAL);
51453 +
51454 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51455 + return ERR_PTR(-ENOMEM);
51456 +
51457 + if (copy_from_user(tmp, s_tmp->filename, len))
51458 + return ERR_PTR(-EFAULT);
51459 + tmp[len-1] = '\0';
51460 + s_tmp->filename = tmp;
51461 +
51462 + if (!strcmp(s_tmp->filename, "/"))
51463 + role->root_label = s_tmp;
51464 +
51465 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
51466 + return ERR_PTR(-EFAULT);
51467 +
51468 + /* copy user and group transition tables */
51469 +
51470 + if (s_tmp->user_trans_num) {
51471 + uid_t *uidlist;
51472 +
51473 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
51474 + if (uidlist == NULL)
51475 + return ERR_PTR(-ENOMEM);
51476 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
51477 + return ERR_PTR(-EFAULT);
51478 +
51479 + s_tmp->user_transitions = uidlist;
51480 + }
51481 +
51482 + if (s_tmp->group_trans_num) {
51483 + gid_t *gidlist;
51484 +
51485 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
51486 + if (gidlist == NULL)
51487 + return ERR_PTR(-ENOMEM);
51488 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
51489 + return ERR_PTR(-EFAULT);
51490 +
51491 + s_tmp->group_transitions = gidlist;
51492 + }
51493 +
51494 + /* set up object hash table */
51495 + num_objs = count_user_objs(ghash.first);
51496 +
51497 + s_tmp->obj_hash_size = num_objs;
51498 + s_tmp->obj_hash =
51499 + (struct acl_object_label **)
51500 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
51501 +
51502 + if (!s_tmp->obj_hash)
51503 + return ERR_PTR(-ENOMEM);
51504 +
51505 + memset(s_tmp->obj_hash, 0,
51506 + s_tmp->obj_hash_size *
51507 + sizeof (struct acl_object_label *));
51508 +
51509 + /* add in objects */
51510 + err = copy_user_objs(ghash.first, s_tmp, role);
51511 +
51512 + if (err)
51513 + return ERR_PTR(err);
51514 +
51515 + /* set pointer for parent subject */
51516 + if (s_tmp->parent_subject) {
51517 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
51518 +
51519 + if (IS_ERR(s_tmp2))
51520 + return s_tmp2;
51521 +
51522 + s_tmp->parent_subject = s_tmp2;
51523 + }
51524 +
51525 + /* add in ip acls */
51526 +
51527 + if (!s_tmp->ip_num) {
51528 + s_tmp->ips = NULL;
51529 + goto insert;
51530 + }
51531 +
51532 + i_tmp =
51533 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
51534 + sizeof (struct acl_ip_label *));
51535 +
51536 + if (!i_tmp)
51537 + return ERR_PTR(-ENOMEM);
51538 +
51539 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
51540 + *(i_tmp + i_num) =
51541 + (struct acl_ip_label *)
51542 + acl_alloc(sizeof (struct acl_ip_label));
51543 + if (!*(i_tmp + i_num))
51544 + return ERR_PTR(-ENOMEM);
51545 +
51546 + if (copy_from_user
51547 + (&i_utmp2, s_tmp->ips + i_num,
51548 + sizeof (struct acl_ip_label *)))
51549 + return ERR_PTR(-EFAULT);
51550 +
51551 + if (copy_from_user
51552 + (*(i_tmp + i_num), i_utmp2,
51553 + sizeof (struct acl_ip_label)))
51554 + return ERR_PTR(-EFAULT);
51555 +
51556 + if ((*(i_tmp + i_num))->iface == NULL)
51557 + continue;
51558 +
51559 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
51560 + if (!len || len >= IFNAMSIZ)
51561 + return ERR_PTR(-EINVAL);
51562 + tmp = acl_alloc(len);
51563 + if (tmp == NULL)
51564 + return ERR_PTR(-ENOMEM);
51565 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
51566 + return ERR_PTR(-EFAULT);
51567 + (*(i_tmp + i_num))->iface = tmp;
51568 + }
51569 +
51570 + s_tmp->ips = i_tmp;
51571 +
51572 +insert:
51573 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
51574 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
51575 + return ERR_PTR(-ENOMEM);
51576 +
51577 + return s_tmp;
51578 +}
51579 +
51580 +static int
51581 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
51582 +{
51583 + struct acl_subject_label s_pre;
51584 + struct acl_subject_label * ret;
51585 + int err;
51586 +
51587 + while (userp) {
51588 + if (copy_from_user(&s_pre, userp,
51589 + sizeof (struct acl_subject_label)))
51590 + return -EFAULT;
51591 +
51592 + /* do not add nested subjects here, add
51593 + while parsing objects
51594 + */
51595 +
51596 + if (s_pre.mode & GR_NESTED) {
51597 + userp = s_pre.prev;
51598 + continue;
51599 + }
51600 +
51601 + ret = do_copy_user_subj(userp, role);
51602 +
51603 + err = PTR_ERR(ret);
51604 + if (IS_ERR(ret))
51605 + return err;
51606 +
51607 + insert_acl_subj_label(ret, role);
51608 +
51609 + userp = s_pre.prev;
51610 + }
51611 +
51612 + return 0;
51613 +}
51614 +
51615 +static int
51616 +copy_user_acl(struct gr_arg *arg)
51617 +{
51618 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
51619 + struct sprole_pw *sptmp;
51620 + struct gr_hash_struct *ghash;
51621 + uid_t *domainlist;
51622 + unsigned int r_num;
51623 + unsigned int len;
51624 + char *tmp;
51625 + int err = 0;
51626 + __u16 i;
51627 + __u32 num_subjs;
51628 +
51629 + /* we need a default and kernel role */
51630 + if (arg->role_db.num_roles < 2)
51631 + return -EINVAL;
51632 +
51633 + /* copy special role authentication info from userspace */
51634 +
51635 + num_sprole_pws = arg->num_sprole_pws;
51636 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
51637 +
51638 + if (!acl_special_roles && num_sprole_pws)
51639 + return -ENOMEM;
51640 +
51641 + for (i = 0; i < num_sprole_pws; i++) {
51642 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
51643 + if (!sptmp)
51644 + return -ENOMEM;
51645 + if (copy_from_user(sptmp, arg->sprole_pws + i,
51646 + sizeof (struct sprole_pw)))
51647 + return -EFAULT;
51648 +
51649 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
51650 +
51651 + if (!len || len >= GR_SPROLE_LEN)
51652 + return -EINVAL;
51653 +
51654 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51655 + return -ENOMEM;
51656 +
51657 + if (copy_from_user(tmp, sptmp->rolename, len))
51658 + return -EFAULT;
51659 +
51660 + tmp[len-1] = '\0';
51661 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51662 + printk(KERN_ALERT "Copying special role %s\n", tmp);
51663 +#endif
51664 + sptmp->rolename = tmp;
51665 + acl_special_roles[i] = sptmp;
51666 + }
51667 +
51668 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
51669 +
51670 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
51671 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
51672 +
51673 + if (!r_tmp)
51674 + return -ENOMEM;
51675 +
51676 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
51677 + sizeof (struct acl_role_label *)))
51678 + return -EFAULT;
51679 +
51680 + if (copy_from_user(r_tmp, r_utmp2,
51681 + sizeof (struct acl_role_label)))
51682 + return -EFAULT;
51683 +
51684 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
51685 +
51686 + if (!len || len >= PATH_MAX)
51687 + return -EINVAL;
51688 +
51689 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51690 + return -ENOMEM;
51691 +
51692 + if (copy_from_user(tmp, r_tmp->rolename, len))
51693 + return -EFAULT;
51694 +
51695 + tmp[len-1] = '\0';
51696 + r_tmp->rolename = tmp;
51697 +
51698 + if (!strcmp(r_tmp->rolename, "default")
51699 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
51700 + default_role = r_tmp;
51701 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
51702 + kernel_role = r_tmp;
51703 + }
51704 +
51705 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
51706 + return -ENOMEM;
51707 +
51708 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
51709 + return -EFAULT;
51710 +
51711 + r_tmp->hash = ghash;
51712 +
51713 + num_subjs = count_user_subjs(r_tmp->hash->first);
51714 +
51715 + r_tmp->subj_hash_size = num_subjs;
51716 + r_tmp->subj_hash =
51717 + (struct acl_subject_label **)
51718 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
51719 +
51720 + if (!r_tmp->subj_hash)
51721 + return -ENOMEM;
51722 +
51723 + err = copy_user_allowedips(r_tmp);
51724 + if (err)
51725 + return err;
51726 +
51727 + /* copy domain info */
51728 + if (r_tmp->domain_children != NULL) {
51729 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
51730 + if (domainlist == NULL)
51731 + return -ENOMEM;
51732 +
51733 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
51734 + return -EFAULT;
51735 +
51736 + r_tmp->domain_children = domainlist;
51737 + }
51738 +
51739 + err = copy_user_transitions(r_tmp);
51740 + if (err)
51741 + return err;
51742 +
51743 + memset(r_tmp->subj_hash, 0,
51744 + r_tmp->subj_hash_size *
51745 + sizeof (struct acl_subject_label *));
51746 +
51747 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
51748 +
51749 + if (err)
51750 + return err;
51751 +
51752 + /* set nested subject list to null */
51753 + r_tmp->hash->first = NULL;
51754 +
51755 + insert_acl_role_label(r_tmp);
51756 + }
51757 +
51758 + if (default_role == NULL || kernel_role == NULL)
51759 + return -EINVAL;
51760 +
51761 + return err;
51762 +}
51763 +
51764 +static int
51765 +gracl_init(struct gr_arg *args)
51766 +{
51767 + int error = 0;
51768 +
51769 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
51770 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
51771 +
51772 + if (init_variables(args)) {
51773 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
51774 + error = -ENOMEM;
51775 + free_variables();
51776 + goto out;
51777 + }
51778 +
51779 + error = copy_user_acl(args);
51780 + free_init_variables();
51781 + if (error) {
51782 + free_variables();
51783 + goto out;
51784 + }
51785 +
51786 + if ((error = gr_set_acls(0))) {
51787 + free_variables();
51788 + goto out;
51789 + }
51790 +
51791 + pax_open_kernel();
51792 + gr_status |= GR_READY;
51793 + pax_close_kernel();
51794 +
51795 + out:
51796 + return error;
51797 +}
51798 +
51799 +/* derived from glibc fnmatch() 0: match, 1: no match*/
51800 +
51801 +static int
51802 +glob_match(const char *p, const char *n)
51803 +{
51804 + char c;
51805 +
51806 + while ((c = *p++) != '\0') {
51807 + switch (c) {
51808 + case '?':
51809 + if (*n == '\0')
51810 + return 1;
51811 + else if (*n == '/')
51812 + return 1;
51813 + break;
51814 + case '\\':
51815 + if (*n != c)
51816 + return 1;
51817 + break;
51818 + case '*':
51819 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
51820 + if (*n == '/')
51821 + return 1;
51822 + else if (c == '?') {
51823 + if (*n == '\0')
51824 + return 1;
51825 + else
51826 + ++n;
51827 + }
51828 + }
51829 + if (c == '\0') {
51830 + return 0;
51831 + } else {
51832 + const char *endp;
51833 +
51834 + if ((endp = strchr(n, '/')) == NULL)
51835 + endp = n + strlen(n);
51836 +
51837 + if (c == '[') {
51838 + for (--p; n < endp; ++n)
51839 + if (!glob_match(p, n))
51840 + return 0;
51841 + } else if (c == '/') {
51842 + while (*n != '\0' && *n != '/')
51843 + ++n;
51844 + if (*n == '/' && !glob_match(p, n + 1))
51845 + return 0;
51846 + } else {
51847 + for (--p; n < endp; ++n)
51848 + if (*n == c && !glob_match(p, n))
51849 + return 0;
51850 + }
51851 +
51852 + return 1;
51853 + }
51854 + case '[':
51855 + {
51856 + int not;
51857 + char cold;
51858 +
51859 + if (*n == '\0' || *n == '/')
51860 + return 1;
51861 +
51862 + not = (*p == '!' || *p == '^');
51863 + if (not)
51864 + ++p;
51865 +
51866 + c = *p++;
51867 + for (;;) {
51868 + unsigned char fn = (unsigned char)*n;
51869 +
51870 + if (c == '\0')
51871 + return 1;
51872 + else {
51873 + if (c == fn)
51874 + goto matched;
51875 + cold = c;
51876 + c = *p++;
51877 +
51878 + if (c == '-' && *p != ']') {
51879 + unsigned char cend = *p++;
51880 +
51881 + if (cend == '\0')
51882 + return 1;
51883 +
51884 + if (cold <= fn && fn <= cend)
51885 + goto matched;
51886 +
51887 + c = *p++;
51888 + }
51889 + }
51890 +
51891 + if (c == ']')
51892 + break;
51893 + }
51894 + if (!not)
51895 + return 1;
51896 + break;
51897 + matched:
51898 + while (c != ']') {
51899 + if (c == '\0')
51900 + return 1;
51901 +
51902 + c = *p++;
51903 + }
51904 + if (not)
51905 + return 1;
51906 + }
51907 + break;
51908 + default:
51909 + if (c != *n)
51910 + return 1;
51911 + }
51912 +
51913 + ++n;
51914 + }
51915 +
51916 + if (*n == '\0')
51917 + return 0;
51918 +
51919 + if (*n == '/')
51920 + return 0;
51921 +
51922 + return 1;
51923 +}
51924 +
51925 +static struct acl_object_label *
51926 +chk_glob_label(struct acl_object_label *globbed,
51927 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
51928 +{
51929 + struct acl_object_label *tmp;
51930 +
51931 + if (*path == NULL)
51932 + *path = gr_to_filename_nolock(dentry, mnt);
51933 +
51934 + tmp = globbed;
51935 +
51936 + while (tmp) {
51937 + if (!glob_match(tmp->filename, *path))
51938 + return tmp;
51939 + tmp = tmp->next;
51940 + }
51941 +
51942 + return NULL;
51943 +}
51944 +
51945 +static struct acl_object_label *
51946 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
51947 + const ino_t curr_ino, const dev_t curr_dev,
51948 + const struct acl_subject_label *subj, char **path, const int checkglob)
51949 +{
51950 + struct acl_subject_label *tmpsubj;
51951 + struct acl_object_label *retval;
51952 + struct acl_object_label *retval2;
51953 +
51954 + tmpsubj = (struct acl_subject_label *) subj;
51955 + read_lock(&gr_inode_lock);
51956 + do {
51957 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
51958 + if (retval) {
51959 + if (checkglob && retval->globbed) {
51960 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
51961 + if (retval2)
51962 + retval = retval2;
51963 + }
51964 + break;
51965 + }
51966 + } while ((tmpsubj = tmpsubj->parent_subject));
51967 + read_unlock(&gr_inode_lock);
51968 +
51969 + return retval;
51970 +}
51971 +
51972 +static __inline__ struct acl_object_label *
51973 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
51974 + struct dentry *curr_dentry,
51975 + const struct acl_subject_label *subj, char **path, const int checkglob)
51976 +{
51977 + int newglob = checkglob;
51978 + ino_t inode;
51979 + dev_t device;
51980 +
51981 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
51982 + as we don't want a / * rule to match instead of the / object
51983 + don't do this for create lookups that call this function though, since they're looking up
51984 + on the parent and thus need globbing checks on all paths
51985 + */
51986 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
51987 + newglob = GR_NO_GLOB;
51988 +
51989 + spin_lock(&curr_dentry->d_lock);
51990 + inode = curr_dentry->d_inode->i_ino;
51991 + device = __get_dev(curr_dentry);
51992 + spin_unlock(&curr_dentry->d_lock);
51993 +
51994 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
51995 +}
51996 +
51997 +static struct acl_object_label *
51998 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
51999 + const struct acl_subject_label *subj, char *path, const int checkglob)
52000 +{
52001 + struct dentry *dentry = (struct dentry *) l_dentry;
52002 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52003 + struct mount *real_mnt = real_mount(mnt);
52004 + struct acl_object_label *retval;
52005 + struct dentry *parent;
52006 +
52007 + write_seqlock(&rename_lock);
52008 + br_read_lock(vfsmount_lock);
52009 +
52010 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
52011 +#ifdef CONFIG_NET
52012 + mnt == sock_mnt ||
52013 +#endif
52014 +#ifdef CONFIG_HUGETLBFS
52015 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
52016 +#endif
52017 + /* ignore Eric Biederman */
52018 + IS_PRIVATE(l_dentry->d_inode))) {
52019 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
52020 + goto out;
52021 + }
52022 +
52023 + for (;;) {
52024 + if (dentry == real_root.dentry && mnt == real_root.mnt)
52025 + break;
52026 +
52027 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52028 + if (!mnt_has_parent(real_mnt))
52029 + break;
52030 +
52031 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52032 + if (retval != NULL)
52033 + goto out;
52034 +
52035 + dentry = real_mnt->mnt_mountpoint;
52036 + real_mnt = real_mnt->mnt_parent;
52037 + mnt = &real_mnt->mnt;
52038 + continue;
52039 + }
52040 +
52041 + parent = dentry->d_parent;
52042 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52043 + if (retval != NULL)
52044 + goto out;
52045 +
52046 + dentry = parent;
52047 + }
52048 +
52049 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52050 +
52051 + /* real_root is pinned so we don't have to hold a reference */
52052 + if (retval == NULL)
52053 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
52054 +out:
52055 + br_read_unlock(vfsmount_lock);
52056 + write_sequnlock(&rename_lock);
52057 +
52058 + BUG_ON(retval == NULL);
52059 +
52060 + return retval;
52061 +}
52062 +
52063 +static __inline__ struct acl_object_label *
52064 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52065 + const struct acl_subject_label *subj)
52066 +{
52067 + char *path = NULL;
52068 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
52069 +}
52070 +
52071 +static __inline__ struct acl_object_label *
52072 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52073 + const struct acl_subject_label *subj)
52074 +{
52075 + char *path = NULL;
52076 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
52077 +}
52078 +
52079 +static __inline__ struct acl_object_label *
52080 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52081 + const struct acl_subject_label *subj, char *path)
52082 +{
52083 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
52084 +}
52085 +
52086 +static struct acl_subject_label *
52087 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52088 + const struct acl_role_label *role)
52089 +{
52090 + struct dentry *dentry = (struct dentry *) l_dentry;
52091 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52092 + struct mount *real_mnt = real_mount(mnt);
52093 + struct acl_subject_label *retval;
52094 + struct dentry *parent;
52095 +
52096 + write_seqlock(&rename_lock);
52097 + br_read_lock(vfsmount_lock);
52098 +
52099 + for (;;) {
52100 + if (dentry == real_root.dentry && mnt == real_root.mnt)
52101 + break;
52102 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52103 + if (!mnt_has_parent(real_mnt))
52104 + break;
52105 +
52106 + spin_lock(&dentry->d_lock);
52107 + read_lock(&gr_inode_lock);
52108 + retval =
52109 + lookup_acl_subj_label(dentry->d_inode->i_ino,
52110 + __get_dev(dentry), role);
52111 + read_unlock(&gr_inode_lock);
52112 + spin_unlock(&dentry->d_lock);
52113 + if (retval != NULL)
52114 + goto out;
52115 +
52116 + dentry = real_mnt->mnt_mountpoint;
52117 + real_mnt = real_mnt->mnt_parent;
52118 + mnt = &real_mnt->mnt;
52119 + continue;
52120 + }
52121 +
52122 + spin_lock(&dentry->d_lock);
52123 + read_lock(&gr_inode_lock);
52124 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52125 + __get_dev(dentry), role);
52126 + read_unlock(&gr_inode_lock);
52127 + parent = dentry->d_parent;
52128 + spin_unlock(&dentry->d_lock);
52129 +
52130 + if (retval != NULL)
52131 + goto out;
52132 +
52133 + dentry = parent;
52134 + }
52135 +
52136 + spin_lock(&dentry->d_lock);
52137 + read_lock(&gr_inode_lock);
52138 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52139 + __get_dev(dentry), role);
52140 + read_unlock(&gr_inode_lock);
52141 + spin_unlock(&dentry->d_lock);
52142 +
52143 + if (unlikely(retval == NULL)) {
52144 + /* real_root is pinned, we don't need to hold a reference */
52145 + read_lock(&gr_inode_lock);
52146 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
52147 + __get_dev(real_root.dentry), role);
52148 + read_unlock(&gr_inode_lock);
52149 + }
52150 +out:
52151 + br_read_unlock(vfsmount_lock);
52152 + write_sequnlock(&rename_lock);
52153 +
52154 + BUG_ON(retval == NULL);
52155 +
52156 + return retval;
52157 +}
52158 +
52159 +static void
52160 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
52161 +{
52162 + struct task_struct *task = current;
52163 + const struct cred *cred = current_cred();
52164 +
52165 + security_learn(GR_LEARN_AUDIT_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 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
52169 +
52170 + return;
52171 +}
52172 +
52173 +static void
52174 +gr_log_learn_id_change(const char type, const unsigned int real,
52175 + const unsigned int effective, const unsigned int fs)
52176 +{
52177 + struct task_struct *task = current;
52178 + const struct cred *cred = current_cred();
52179 +
52180 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
52181 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52182 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52183 + type, real, effective, fs, &task->signal->saved_ip);
52184 +
52185 + return;
52186 +}
52187 +
52188 +__u32
52189 +gr_search_file(const struct dentry * dentry, const __u32 mode,
52190 + const struct vfsmount * mnt)
52191 +{
52192 + __u32 retval = mode;
52193 + struct acl_subject_label *curracl;
52194 + struct acl_object_label *currobj;
52195 +
52196 + if (unlikely(!(gr_status & GR_READY)))
52197 + return (mode & ~GR_AUDITS);
52198 +
52199 + curracl = current->acl;
52200 +
52201 + currobj = chk_obj_label(dentry, mnt, curracl);
52202 + retval = currobj->mode & mode;
52203 +
52204 + /* if we're opening a specified transfer file for writing
52205 + (e.g. /dev/initctl), then transfer our role to init
52206 + */
52207 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
52208 + current->role->roletype & GR_ROLE_PERSIST)) {
52209 + struct task_struct *task = init_pid_ns.child_reaper;
52210 +
52211 + if (task->role != current->role) {
52212 + task->acl_sp_role = 0;
52213 + task->acl_role_id = current->acl_role_id;
52214 + task->role = current->role;
52215 + rcu_read_lock();
52216 + read_lock(&grsec_exec_file_lock);
52217 + gr_apply_subject_to_task(task);
52218 + read_unlock(&grsec_exec_file_lock);
52219 + rcu_read_unlock();
52220 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
52221 + }
52222 + }
52223 +
52224 + if (unlikely
52225 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
52226 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
52227 + __u32 new_mode = mode;
52228 +
52229 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
52230 +
52231 + retval = new_mode;
52232 +
52233 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
52234 + new_mode |= GR_INHERIT;
52235 +
52236 + if (!(mode & GR_NOLEARN))
52237 + gr_log_learn(dentry, mnt, new_mode);
52238 + }
52239 +
52240 + return retval;
52241 +}
52242 +
52243 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
52244 + const struct dentry *parent,
52245 + const struct vfsmount *mnt)
52246 +{
52247 + struct name_entry *match;
52248 + struct acl_object_label *matchpo;
52249 + struct acl_subject_label *curracl;
52250 + char *path;
52251 +
52252 + if (unlikely(!(gr_status & GR_READY)))
52253 + return NULL;
52254 +
52255 + preempt_disable();
52256 + path = gr_to_filename_rbac(new_dentry, mnt);
52257 + match = lookup_name_entry_create(path);
52258 +
52259 + curracl = current->acl;
52260 +
52261 + if (match) {
52262 + read_lock(&gr_inode_lock);
52263 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
52264 + read_unlock(&gr_inode_lock);
52265 +
52266 + if (matchpo) {
52267 + preempt_enable();
52268 + return matchpo;
52269 + }
52270 + }
52271 +
52272 + // lookup parent
52273 +
52274 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
52275 +
52276 + preempt_enable();
52277 + return matchpo;
52278 +}
52279 +
52280 +__u32
52281 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
52282 + const struct vfsmount * mnt, const __u32 mode)
52283 +{
52284 + struct acl_object_label *matchpo;
52285 + __u32 retval;
52286 +
52287 + if (unlikely(!(gr_status & GR_READY)))
52288 + return (mode & ~GR_AUDITS);
52289 +
52290 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
52291 +
52292 + retval = matchpo->mode & mode;
52293 +
52294 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
52295 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
52296 + __u32 new_mode = mode;
52297 +
52298 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
52299 +
52300 + gr_log_learn(new_dentry, mnt, new_mode);
52301 + return new_mode;
52302 + }
52303 +
52304 + return retval;
52305 +}
52306 +
52307 +__u32
52308 +gr_check_link(const struct dentry * new_dentry,
52309 + const struct dentry * parent_dentry,
52310 + const struct vfsmount * parent_mnt,
52311 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
52312 +{
52313 + struct acl_object_label *obj;
52314 + __u32 oldmode, newmode;
52315 + __u32 needmode;
52316 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
52317 + GR_DELETE | GR_INHERIT;
52318 +
52319 + if (unlikely(!(gr_status & GR_READY)))
52320 + return (GR_CREATE | GR_LINK);
52321 +
52322 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
52323 + oldmode = obj->mode;
52324 +
52325 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
52326 + newmode = obj->mode;
52327 +
52328 + needmode = newmode & checkmodes;
52329 +
52330 + // old name for hardlink must have at least the permissions of the new name
52331 + if ((oldmode & needmode) != needmode)
52332 + goto bad;
52333 +
52334 + // if old name had restrictions/auditing, make sure the new name does as well
52335 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
52336 +
52337 + // don't allow hardlinking of suid/sgid files without permission
52338 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
52339 + needmode |= GR_SETID;
52340 +
52341 + if ((newmode & needmode) != needmode)
52342 + goto bad;
52343 +
52344 + // enforce minimum permissions
52345 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
52346 + return newmode;
52347 +bad:
52348 + needmode = oldmode;
52349 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
52350 + needmode |= GR_SETID;
52351 +
52352 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
52353 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
52354 + return (GR_CREATE | GR_LINK);
52355 + } else if (newmode & GR_SUPPRESS)
52356 + return GR_SUPPRESS;
52357 + else
52358 + return 0;
52359 +}
52360 +
52361 +int
52362 +gr_check_hidden_task(const struct task_struct *task)
52363 +{
52364 + if (unlikely(!(gr_status & GR_READY)))
52365 + return 0;
52366 +
52367 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
52368 + return 1;
52369 +
52370 + return 0;
52371 +}
52372 +
52373 +int
52374 +gr_check_protected_task(const struct task_struct *task)
52375 +{
52376 + if (unlikely(!(gr_status & GR_READY) || !task))
52377 + return 0;
52378 +
52379 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
52380 + task->acl != current->acl)
52381 + return 1;
52382 +
52383 + return 0;
52384 +}
52385 +
52386 +int
52387 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
52388 +{
52389 + struct task_struct *p;
52390 + int ret = 0;
52391 +
52392 + if (unlikely(!(gr_status & GR_READY) || !pid))
52393 + return ret;
52394 +
52395 + read_lock(&tasklist_lock);
52396 + do_each_pid_task(pid, type, p) {
52397 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
52398 + p->acl != current->acl) {
52399 + ret = 1;
52400 + goto out;
52401 + }
52402 + } while_each_pid_task(pid, type, p);
52403 +out:
52404 + read_unlock(&tasklist_lock);
52405 +
52406 + return ret;
52407 +}
52408 +
52409 +void
52410 +gr_copy_label(struct task_struct *tsk)
52411 +{
52412 + /* plain copying of fields is already done by dup_task_struct */
52413 + tsk->signal->used_accept = 0;
52414 + tsk->acl_sp_role = 0;
52415 + //tsk->acl_role_id = current->acl_role_id;
52416 + //tsk->acl = current->acl;
52417 + //tsk->role = current->role;
52418 + tsk->signal->curr_ip = current->signal->curr_ip;
52419 + tsk->signal->saved_ip = current->signal->saved_ip;
52420 + if (current->exec_file)
52421 + get_file(current->exec_file);
52422 + //tsk->exec_file = current->exec_file;
52423 + //tsk->is_writable = current->is_writable;
52424 + if (unlikely(current->signal->used_accept)) {
52425 + current->signal->curr_ip = 0;
52426 + current->signal->saved_ip = 0;
52427 + }
52428 +
52429 + return;
52430 +}
52431 +
52432 +static void
52433 +gr_set_proc_res(struct task_struct *task)
52434 +{
52435 + struct acl_subject_label *proc;
52436 + unsigned short i;
52437 +
52438 + proc = task->acl;
52439 +
52440 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
52441 + return;
52442 +
52443 + for (i = 0; i < RLIM_NLIMITS; i++) {
52444 + if (!(proc->resmask & (1 << i)))
52445 + continue;
52446 +
52447 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
52448 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
52449 + }
52450 +
52451 + return;
52452 +}
52453 +
52454 +extern int __gr_process_user_ban(struct user_struct *user);
52455 +
52456 +int
52457 +gr_check_user_change(int real, int effective, int fs)
52458 +{
52459 + unsigned int i;
52460 + __u16 num;
52461 + uid_t *uidlist;
52462 + int curuid;
52463 + int realok = 0;
52464 + int effectiveok = 0;
52465 + int fsok = 0;
52466 +
52467 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
52468 + struct user_struct *user;
52469 +
52470 + if (real == -1)
52471 + goto skipit;
52472 +
52473 + user = find_user(real);
52474 + if (user == NULL)
52475 + goto skipit;
52476 +
52477 + if (__gr_process_user_ban(user)) {
52478 + /* for find_user */
52479 + free_uid(user);
52480 + return 1;
52481 + }
52482 +
52483 + /* for find_user */
52484 + free_uid(user);
52485 +
52486 +skipit:
52487 +#endif
52488 +
52489 + if (unlikely(!(gr_status & GR_READY)))
52490 + return 0;
52491 +
52492 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
52493 + gr_log_learn_id_change('u', real, effective, fs);
52494 +
52495 + num = current->acl->user_trans_num;
52496 + uidlist = current->acl->user_transitions;
52497 +
52498 + if (uidlist == NULL)
52499 + return 0;
52500 +
52501 + if (real == -1)
52502 + realok = 1;
52503 + if (effective == -1)
52504 + effectiveok = 1;
52505 + if (fs == -1)
52506 + fsok = 1;
52507 +
52508 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
52509 + for (i = 0; i < num; i++) {
52510 + curuid = (int)uidlist[i];
52511 + if (real == curuid)
52512 + realok = 1;
52513 + if (effective == curuid)
52514 + effectiveok = 1;
52515 + if (fs == curuid)
52516 + fsok = 1;
52517 + }
52518 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
52519 + for (i = 0; i < num; i++) {
52520 + curuid = (int)uidlist[i];
52521 + if (real == curuid)
52522 + break;
52523 + if (effective == curuid)
52524 + break;
52525 + if (fs == curuid)
52526 + break;
52527 + }
52528 + /* not in deny list */
52529 + if (i == num) {
52530 + realok = 1;
52531 + effectiveok = 1;
52532 + fsok = 1;
52533 + }
52534 + }
52535 +
52536 + if (realok && effectiveok && fsok)
52537 + return 0;
52538 + else {
52539 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
52540 + return 1;
52541 + }
52542 +}
52543 +
52544 +int
52545 +gr_check_group_change(int real, int effective, int fs)
52546 +{
52547 + unsigned int i;
52548 + __u16 num;
52549 + gid_t *gidlist;
52550 + int curgid;
52551 + int realok = 0;
52552 + int effectiveok = 0;
52553 + int fsok = 0;
52554 +
52555 + if (unlikely(!(gr_status & GR_READY)))
52556 + return 0;
52557 +
52558 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
52559 + gr_log_learn_id_change('g', real, effective, fs);
52560 +
52561 + num = current->acl->group_trans_num;
52562 + gidlist = current->acl->group_transitions;
52563 +
52564 + if (gidlist == NULL)
52565 + return 0;
52566 +
52567 + if (real == -1)
52568 + realok = 1;
52569 + if (effective == -1)
52570 + effectiveok = 1;
52571 + if (fs == -1)
52572 + fsok = 1;
52573 +
52574 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
52575 + for (i = 0; i < num; i++) {
52576 + curgid = (int)gidlist[i];
52577 + if (real == curgid)
52578 + realok = 1;
52579 + if (effective == curgid)
52580 + effectiveok = 1;
52581 + if (fs == curgid)
52582 + fsok = 1;
52583 + }
52584 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
52585 + for (i = 0; i < num; i++) {
52586 + curgid = (int)gidlist[i];
52587 + if (real == curgid)
52588 + break;
52589 + if (effective == curgid)
52590 + break;
52591 + if (fs == curgid)
52592 + break;
52593 + }
52594 + /* not in deny list */
52595 + if (i == num) {
52596 + realok = 1;
52597 + effectiveok = 1;
52598 + fsok = 1;
52599 + }
52600 + }
52601 +
52602 + if (realok && effectiveok && fsok)
52603 + return 0;
52604 + else {
52605 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
52606 + return 1;
52607 + }
52608 +}
52609 +
52610 +extern int gr_acl_is_capable(const int cap);
52611 +
52612 +void
52613 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
52614 +{
52615 + struct acl_role_label *role = task->role;
52616 + struct acl_subject_label *subj = NULL;
52617 + struct acl_object_label *obj;
52618 + struct file *filp;
52619 +
52620 + if (unlikely(!(gr_status & GR_READY)))
52621 + return;
52622 +
52623 + filp = task->exec_file;
52624 +
52625 + /* kernel process, we'll give them the kernel role */
52626 + if (unlikely(!filp)) {
52627 + task->role = kernel_role;
52628 + task->acl = kernel_role->root_label;
52629 + return;
52630 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
52631 + role = lookup_acl_role_label(task, uid, gid);
52632 +
52633 + /* don't change the role if we're not a privileged process */
52634 + if (role && task->role != role &&
52635 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
52636 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
52637 + return;
52638 +
52639 + /* perform subject lookup in possibly new role
52640 + we can use this result below in the case where role == task->role
52641 + */
52642 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
52643 +
52644 + /* if we changed uid/gid, but result in the same role
52645 + and are using inheritance, don't lose the inherited subject
52646 + if current subject is other than what normal lookup
52647 + would result in, we arrived via inheritance, don't
52648 + lose subject
52649 + */
52650 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
52651 + (subj == task->acl)))
52652 + task->acl = subj;
52653 +
52654 + task->role = role;
52655 +
52656 + task->is_writable = 0;
52657 +
52658 + /* ignore additional mmap checks for processes that are writable
52659 + by the default ACL */
52660 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
52661 + if (unlikely(obj->mode & GR_WRITE))
52662 + task->is_writable = 1;
52663 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
52664 + if (unlikely(obj->mode & GR_WRITE))
52665 + task->is_writable = 1;
52666 +
52667 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52668 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
52669 +#endif
52670 +
52671 + gr_set_proc_res(task);
52672 +
52673 + return;
52674 +}
52675 +
52676 +int
52677 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
52678 + const int unsafe_flags)
52679 +{
52680 + struct task_struct *task = current;
52681 + struct acl_subject_label *newacl;
52682 + struct acl_object_label *obj;
52683 + __u32 retmode;
52684 +
52685 + if (unlikely(!(gr_status & GR_READY)))
52686 + return 0;
52687 +
52688 + newacl = chk_subj_label(dentry, mnt, task->role);
52689 +
52690 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
52691 + did an exec
52692 + */
52693 + rcu_read_lock();
52694 + read_lock(&tasklist_lock);
52695 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
52696 + (task->parent->acl->mode & GR_POVERRIDE))) {
52697 + read_unlock(&tasklist_lock);
52698 + rcu_read_unlock();
52699 + goto skip_check;
52700 + }
52701 + read_unlock(&tasklist_lock);
52702 + rcu_read_unlock();
52703 +
52704 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
52705 + !(task->role->roletype & GR_ROLE_GOD) &&
52706 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
52707 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
52708 + if (unsafe_flags & LSM_UNSAFE_SHARE)
52709 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
52710 + else
52711 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
52712 + return -EACCES;
52713 + }
52714 +
52715 +skip_check:
52716 +
52717 + obj = chk_obj_label(dentry, mnt, task->acl);
52718 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
52719 +
52720 + if (!(task->acl->mode & GR_INHERITLEARN) &&
52721 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
52722 + if (obj->nested)
52723 + task->acl = obj->nested;
52724 + else
52725 + task->acl = newacl;
52726 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
52727 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
52728 +
52729 + task->is_writable = 0;
52730 +
52731 + /* ignore additional mmap checks for processes that are writable
52732 + by the default ACL */
52733 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
52734 + if (unlikely(obj->mode & GR_WRITE))
52735 + task->is_writable = 1;
52736 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
52737 + if (unlikely(obj->mode & GR_WRITE))
52738 + task->is_writable = 1;
52739 +
52740 + gr_set_proc_res(task);
52741 +
52742 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52743 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
52744 +#endif
52745 + return 0;
52746 +}
52747 +
52748 +/* always called with valid inodev ptr */
52749 +static void
52750 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
52751 +{
52752 + struct acl_object_label *matchpo;
52753 + struct acl_subject_label *matchps;
52754 + struct acl_subject_label *subj;
52755 + struct acl_role_label *role;
52756 + unsigned int x;
52757 +
52758 + FOR_EACH_ROLE_START(role)
52759 + FOR_EACH_SUBJECT_START(role, subj, x)
52760 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
52761 + matchpo->mode |= GR_DELETED;
52762 + FOR_EACH_SUBJECT_END(subj,x)
52763 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
52764 + if (subj->inode == ino && subj->device == dev)
52765 + subj->mode |= GR_DELETED;
52766 + FOR_EACH_NESTED_SUBJECT_END(subj)
52767 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
52768 + matchps->mode |= GR_DELETED;
52769 + FOR_EACH_ROLE_END(role)
52770 +
52771 + inodev->nentry->deleted = 1;
52772 +
52773 + return;
52774 +}
52775 +
52776 +void
52777 +gr_handle_delete(const ino_t ino, const dev_t dev)
52778 +{
52779 + struct inodev_entry *inodev;
52780 +
52781 + if (unlikely(!(gr_status & GR_READY)))
52782 + return;
52783 +
52784 + write_lock(&gr_inode_lock);
52785 + inodev = lookup_inodev_entry(ino, dev);
52786 + if (inodev != NULL)
52787 + do_handle_delete(inodev, ino, dev);
52788 + write_unlock(&gr_inode_lock);
52789 +
52790 + return;
52791 +}
52792 +
52793 +static void
52794 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
52795 + const ino_t newinode, const dev_t newdevice,
52796 + struct acl_subject_label *subj)
52797 +{
52798 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
52799 + struct acl_object_label *match;
52800 +
52801 + match = subj->obj_hash[index];
52802 +
52803 + while (match && (match->inode != oldinode ||
52804 + match->device != olddevice ||
52805 + !(match->mode & GR_DELETED)))
52806 + match = match->next;
52807 +
52808 + if (match && (match->inode == oldinode)
52809 + && (match->device == olddevice)
52810 + && (match->mode & GR_DELETED)) {
52811 + if (match->prev == NULL) {
52812 + subj->obj_hash[index] = match->next;
52813 + if (match->next != NULL)
52814 + match->next->prev = NULL;
52815 + } else {
52816 + match->prev->next = match->next;
52817 + if (match->next != NULL)
52818 + match->next->prev = match->prev;
52819 + }
52820 + match->prev = NULL;
52821 + match->next = NULL;
52822 + match->inode = newinode;
52823 + match->device = newdevice;
52824 + match->mode &= ~GR_DELETED;
52825 +
52826 + insert_acl_obj_label(match, subj);
52827 + }
52828 +
52829 + return;
52830 +}
52831 +
52832 +static void
52833 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
52834 + const ino_t newinode, const dev_t newdevice,
52835 + struct acl_role_label *role)
52836 +{
52837 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
52838 + struct acl_subject_label *match;
52839 +
52840 + match = role->subj_hash[index];
52841 +
52842 + while (match && (match->inode != oldinode ||
52843 + match->device != olddevice ||
52844 + !(match->mode & GR_DELETED)))
52845 + match = match->next;
52846 +
52847 + if (match && (match->inode == oldinode)
52848 + && (match->device == olddevice)
52849 + && (match->mode & GR_DELETED)) {
52850 + if (match->prev == NULL) {
52851 + role->subj_hash[index] = match->next;
52852 + if (match->next != NULL)
52853 + match->next->prev = NULL;
52854 + } else {
52855 + match->prev->next = match->next;
52856 + if (match->next != NULL)
52857 + match->next->prev = match->prev;
52858 + }
52859 + match->prev = NULL;
52860 + match->next = NULL;
52861 + match->inode = newinode;
52862 + match->device = newdevice;
52863 + match->mode &= ~GR_DELETED;
52864 +
52865 + insert_acl_subj_label(match, role);
52866 + }
52867 +
52868 + return;
52869 +}
52870 +
52871 +static void
52872 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
52873 + const ino_t newinode, const dev_t newdevice)
52874 +{
52875 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
52876 + struct inodev_entry *match;
52877 +
52878 + match = inodev_set.i_hash[index];
52879 +
52880 + while (match && (match->nentry->inode != oldinode ||
52881 + match->nentry->device != olddevice || !match->nentry->deleted))
52882 + match = match->next;
52883 +
52884 + if (match && (match->nentry->inode == oldinode)
52885 + && (match->nentry->device == olddevice) &&
52886 + match->nentry->deleted) {
52887 + if (match->prev == NULL) {
52888 + inodev_set.i_hash[index] = match->next;
52889 + if (match->next != NULL)
52890 + match->next->prev = NULL;
52891 + } else {
52892 + match->prev->next = match->next;
52893 + if (match->next != NULL)
52894 + match->next->prev = match->prev;
52895 + }
52896 + match->prev = NULL;
52897 + match->next = NULL;
52898 + match->nentry->inode = newinode;
52899 + match->nentry->device = newdevice;
52900 + match->nentry->deleted = 0;
52901 +
52902 + insert_inodev_entry(match);
52903 + }
52904 +
52905 + return;
52906 +}
52907 +
52908 +static void
52909 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
52910 +{
52911 + struct acl_subject_label *subj;
52912 + struct acl_role_label *role;
52913 + unsigned int x;
52914 +
52915 + FOR_EACH_ROLE_START(role)
52916 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
52917 +
52918 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
52919 + if ((subj->inode == ino) && (subj->device == dev)) {
52920 + subj->inode = ino;
52921 + subj->device = dev;
52922 + }
52923 + FOR_EACH_NESTED_SUBJECT_END(subj)
52924 + FOR_EACH_SUBJECT_START(role, subj, x)
52925 + update_acl_obj_label(matchn->inode, matchn->device,
52926 + ino, dev, subj);
52927 + FOR_EACH_SUBJECT_END(subj,x)
52928 + FOR_EACH_ROLE_END(role)
52929 +
52930 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
52931 +
52932 + return;
52933 +}
52934 +
52935 +static void
52936 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
52937 + const struct vfsmount *mnt)
52938 +{
52939 + ino_t ino = dentry->d_inode->i_ino;
52940 + dev_t dev = __get_dev(dentry);
52941 +
52942 + __do_handle_create(matchn, ino, dev);
52943 +
52944 + return;
52945 +}
52946 +
52947 +void
52948 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
52949 +{
52950 + struct name_entry *matchn;
52951 +
52952 + if (unlikely(!(gr_status & GR_READY)))
52953 + return;
52954 +
52955 + preempt_disable();
52956 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
52957 +
52958 + if (unlikely((unsigned long)matchn)) {
52959 + write_lock(&gr_inode_lock);
52960 + do_handle_create(matchn, dentry, mnt);
52961 + write_unlock(&gr_inode_lock);
52962 + }
52963 + preempt_enable();
52964 +
52965 + return;
52966 +}
52967 +
52968 +void
52969 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
52970 +{
52971 + struct name_entry *matchn;
52972 +
52973 + if (unlikely(!(gr_status & GR_READY)))
52974 + return;
52975 +
52976 + preempt_disable();
52977 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
52978 +
52979 + if (unlikely((unsigned long)matchn)) {
52980 + write_lock(&gr_inode_lock);
52981 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
52982 + write_unlock(&gr_inode_lock);
52983 + }
52984 + preempt_enable();
52985 +
52986 + return;
52987 +}
52988 +
52989 +void
52990 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
52991 + struct dentry *old_dentry,
52992 + struct dentry *new_dentry,
52993 + struct vfsmount *mnt, const __u8 replace)
52994 +{
52995 + struct name_entry *matchn;
52996 + struct inodev_entry *inodev;
52997 + struct inode *inode = new_dentry->d_inode;
52998 + ino_t old_ino = old_dentry->d_inode->i_ino;
52999 + dev_t old_dev = __get_dev(old_dentry);
53000 +
53001 + /* vfs_rename swaps the name and parent link for old_dentry and
53002 + new_dentry
53003 + at this point, old_dentry has the new name, parent link, and inode
53004 + for the renamed file
53005 + if a file is being replaced by a rename, new_dentry has the inode
53006 + and name for the replaced file
53007 + */
53008 +
53009 + if (unlikely(!(gr_status & GR_READY)))
53010 + return;
53011 +
53012 + preempt_disable();
53013 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
53014 +
53015 + /* we wouldn't have to check d_inode if it weren't for
53016 + NFS silly-renaming
53017 + */
53018 +
53019 + write_lock(&gr_inode_lock);
53020 + if (unlikely(replace && inode)) {
53021 + ino_t new_ino = inode->i_ino;
53022 + dev_t new_dev = __get_dev(new_dentry);
53023 +
53024 + inodev = lookup_inodev_entry(new_ino, new_dev);
53025 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
53026 + do_handle_delete(inodev, new_ino, new_dev);
53027 + }
53028 +
53029 + inodev = lookup_inodev_entry(old_ino, old_dev);
53030 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
53031 + do_handle_delete(inodev, old_ino, old_dev);
53032 +
53033 + if (unlikely((unsigned long)matchn))
53034 + do_handle_create(matchn, old_dentry, mnt);
53035 +
53036 + write_unlock(&gr_inode_lock);
53037 + preempt_enable();
53038 +
53039 + return;
53040 +}
53041 +
53042 +static int
53043 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
53044 + unsigned char **sum)
53045 +{
53046 + struct acl_role_label *r;
53047 + struct role_allowed_ip *ipp;
53048 + struct role_transition *trans;
53049 + unsigned int i;
53050 + int found = 0;
53051 + u32 curr_ip = current->signal->curr_ip;
53052 +
53053 + current->signal->saved_ip = curr_ip;
53054 +
53055 + /* check transition table */
53056 +
53057 + for (trans = current->role->transitions; trans; trans = trans->next) {
53058 + if (!strcmp(rolename, trans->rolename)) {
53059 + found = 1;
53060 + break;
53061 + }
53062 + }
53063 +
53064 + if (!found)
53065 + return 0;
53066 +
53067 + /* handle special roles that do not require authentication
53068 + and check ip */
53069 +
53070 + FOR_EACH_ROLE_START(r)
53071 + if (!strcmp(rolename, r->rolename) &&
53072 + (r->roletype & GR_ROLE_SPECIAL)) {
53073 + found = 0;
53074 + if (r->allowed_ips != NULL) {
53075 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
53076 + if ((ntohl(curr_ip) & ipp->netmask) ==
53077 + (ntohl(ipp->addr) & ipp->netmask))
53078 + found = 1;
53079 + }
53080 + } else
53081 + found = 2;
53082 + if (!found)
53083 + return 0;
53084 +
53085 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
53086 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
53087 + *salt = NULL;
53088 + *sum = NULL;
53089 + return 1;
53090 + }
53091 + }
53092 + FOR_EACH_ROLE_END(r)
53093 +
53094 + for (i = 0; i < num_sprole_pws; i++) {
53095 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
53096 + *salt = acl_special_roles[i]->salt;
53097 + *sum = acl_special_roles[i]->sum;
53098 + return 1;
53099 + }
53100 + }
53101 +
53102 + return 0;
53103 +}
53104 +
53105 +static void
53106 +assign_special_role(char *rolename)
53107 +{
53108 + struct acl_object_label *obj;
53109 + struct acl_role_label *r;
53110 + struct acl_role_label *assigned = NULL;
53111 + struct task_struct *tsk;
53112 + struct file *filp;
53113 +
53114 + FOR_EACH_ROLE_START(r)
53115 + if (!strcmp(rolename, r->rolename) &&
53116 + (r->roletype & GR_ROLE_SPECIAL)) {
53117 + assigned = r;
53118 + break;
53119 + }
53120 + FOR_EACH_ROLE_END(r)
53121 +
53122 + if (!assigned)
53123 + return;
53124 +
53125 + read_lock(&tasklist_lock);
53126 + read_lock(&grsec_exec_file_lock);
53127 +
53128 + tsk = current->real_parent;
53129 + if (tsk == NULL)
53130 + goto out_unlock;
53131 +
53132 + filp = tsk->exec_file;
53133 + if (filp == NULL)
53134 + goto out_unlock;
53135 +
53136 + tsk->is_writable = 0;
53137 +
53138 + tsk->acl_sp_role = 1;
53139 + tsk->acl_role_id = ++acl_sp_role_value;
53140 + tsk->role = assigned;
53141 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
53142 +
53143 + /* ignore additional mmap checks for processes that are writable
53144 + by the default ACL */
53145 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53146 + if (unlikely(obj->mode & GR_WRITE))
53147 + tsk->is_writable = 1;
53148 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
53149 + if (unlikely(obj->mode & GR_WRITE))
53150 + tsk->is_writable = 1;
53151 +
53152 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53153 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
53154 +#endif
53155 +
53156 +out_unlock:
53157 + read_unlock(&grsec_exec_file_lock);
53158 + read_unlock(&tasklist_lock);
53159 + return;
53160 +}
53161 +
53162 +int gr_check_secure_terminal(struct task_struct *task)
53163 +{
53164 + struct task_struct *p, *p2, *p3;
53165 + struct files_struct *files;
53166 + struct fdtable *fdt;
53167 + struct file *our_file = NULL, *file;
53168 + int i;
53169 +
53170 + if (task->signal->tty == NULL)
53171 + return 1;
53172 +
53173 + files = get_files_struct(task);
53174 + if (files != NULL) {
53175 + rcu_read_lock();
53176 + fdt = files_fdtable(files);
53177 + for (i=0; i < fdt->max_fds; i++) {
53178 + file = fcheck_files(files, i);
53179 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
53180 + get_file(file);
53181 + our_file = file;
53182 + }
53183 + }
53184 + rcu_read_unlock();
53185 + put_files_struct(files);
53186 + }
53187 +
53188 + if (our_file == NULL)
53189 + return 1;
53190 +
53191 + read_lock(&tasklist_lock);
53192 + do_each_thread(p2, p) {
53193 + files = get_files_struct(p);
53194 + if (files == NULL ||
53195 + (p->signal && p->signal->tty == task->signal->tty)) {
53196 + if (files != NULL)
53197 + put_files_struct(files);
53198 + continue;
53199 + }
53200 + rcu_read_lock();
53201 + fdt = files_fdtable(files);
53202 + for (i=0; i < fdt->max_fds; i++) {
53203 + file = fcheck_files(files, i);
53204 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
53205 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
53206 + p3 = task;
53207 + while (p3->pid > 0) {
53208 + if (p3 == p)
53209 + break;
53210 + p3 = p3->real_parent;
53211 + }
53212 + if (p3 == p)
53213 + break;
53214 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
53215 + gr_handle_alertkill(p);
53216 + rcu_read_unlock();
53217 + put_files_struct(files);
53218 + read_unlock(&tasklist_lock);
53219 + fput(our_file);
53220 + return 0;
53221 + }
53222 + }
53223 + rcu_read_unlock();
53224 + put_files_struct(files);
53225 + } while_each_thread(p2, p);
53226 + read_unlock(&tasklist_lock);
53227 +
53228 + fput(our_file);
53229 + return 1;
53230 +}
53231 +
53232 +ssize_t
53233 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
53234 +{
53235 + struct gr_arg_wrapper uwrap;
53236 + unsigned char *sprole_salt = NULL;
53237 + unsigned char *sprole_sum = NULL;
53238 + int error = sizeof (struct gr_arg_wrapper);
53239 + int error2 = 0;
53240 +
53241 + mutex_lock(&gr_dev_mutex);
53242 +
53243 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
53244 + error = -EPERM;
53245 + goto out;
53246 + }
53247 +
53248 + if (count != sizeof (struct gr_arg_wrapper)) {
53249 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
53250 + error = -EINVAL;
53251 + goto out;
53252 + }
53253 +
53254 +
53255 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
53256 + gr_auth_expires = 0;
53257 + gr_auth_attempts = 0;
53258 + }
53259 +
53260 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
53261 + error = -EFAULT;
53262 + goto out;
53263 + }
53264 +
53265 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
53266 + error = -EINVAL;
53267 + goto out;
53268 + }
53269 +
53270 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
53271 + error = -EFAULT;
53272 + goto out;
53273 + }
53274 +
53275 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
53276 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
53277 + time_after(gr_auth_expires, get_seconds())) {
53278 + error = -EBUSY;
53279 + goto out;
53280 + }
53281 +
53282 + /* if non-root trying to do anything other than use a special role,
53283 + do not attempt authentication, do not count towards authentication
53284 + locking
53285 + */
53286 +
53287 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
53288 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
53289 + current_uid()) {
53290 + error = -EPERM;
53291 + goto out;
53292 + }
53293 +
53294 + /* ensure pw and special role name are null terminated */
53295 +
53296 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
53297 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
53298 +
53299 + /* Okay.
53300 + * We have our enough of the argument structure..(we have yet
53301 + * to copy_from_user the tables themselves) . Copy the tables
53302 + * only if we need them, i.e. for loading operations. */
53303 +
53304 + switch (gr_usermode->mode) {
53305 + case GR_STATUS:
53306 + if (gr_status & GR_READY) {
53307 + error = 1;
53308 + if (!gr_check_secure_terminal(current))
53309 + error = 3;
53310 + } else
53311 + error = 2;
53312 + goto out;
53313 + case GR_SHUTDOWN:
53314 + if ((gr_status & GR_READY)
53315 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53316 + pax_open_kernel();
53317 + gr_status &= ~GR_READY;
53318 + pax_close_kernel();
53319 +
53320 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
53321 + free_variables();
53322 + memset(gr_usermode, 0, sizeof (struct gr_arg));
53323 + memset(gr_system_salt, 0, GR_SALT_LEN);
53324 + memset(gr_system_sum, 0, GR_SHA_LEN);
53325 + } else if (gr_status & GR_READY) {
53326 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
53327 + error = -EPERM;
53328 + } else {
53329 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
53330 + error = -EAGAIN;
53331 + }
53332 + break;
53333 + case GR_ENABLE:
53334 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
53335 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
53336 + else {
53337 + if (gr_status & GR_READY)
53338 + error = -EAGAIN;
53339 + else
53340 + error = error2;
53341 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
53342 + }
53343 + break;
53344 + case GR_RELOAD:
53345 + if (!(gr_status & GR_READY)) {
53346 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
53347 + error = -EAGAIN;
53348 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53349 + preempt_disable();
53350 +
53351 + pax_open_kernel();
53352 + gr_status &= ~GR_READY;
53353 + pax_close_kernel();
53354 +
53355 + free_variables();
53356 + if (!(error2 = gracl_init(gr_usermode))) {
53357 + preempt_enable();
53358 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
53359 + } else {
53360 + preempt_enable();
53361 + error = error2;
53362 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
53363 + }
53364 + } else {
53365 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
53366 + error = -EPERM;
53367 + }
53368 + break;
53369 + case GR_SEGVMOD:
53370 + if (unlikely(!(gr_status & GR_READY))) {
53371 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
53372 + error = -EAGAIN;
53373 + break;
53374 + }
53375 +
53376 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53377 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
53378 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
53379 + struct acl_subject_label *segvacl;
53380 + segvacl =
53381 + lookup_acl_subj_label(gr_usermode->segv_inode,
53382 + gr_usermode->segv_device,
53383 + current->role);
53384 + if (segvacl) {
53385 + segvacl->crashes = 0;
53386 + segvacl->expires = 0;
53387 + }
53388 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
53389 + gr_remove_uid(gr_usermode->segv_uid);
53390 + }
53391 + } else {
53392 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
53393 + error = -EPERM;
53394 + }
53395 + break;
53396 + case GR_SPROLE:
53397 + case GR_SPROLEPAM:
53398 + if (unlikely(!(gr_status & GR_READY))) {
53399 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
53400 + error = -EAGAIN;
53401 + break;
53402 + }
53403 +
53404 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
53405 + current->role->expires = 0;
53406 + current->role->auth_attempts = 0;
53407 + }
53408 +
53409 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
53410 + time_after(current->role->expires, get_seconds())) {
53411 + error = -EBUSY;
53412 + goto out;
53413 + }
53414 +
53415 + if (lookup_special_role_auth
53416 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
53417 + && ((!sprole_salt && !sprole_sum)
53418 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
53419 + char *p = "";
53420 + assign_special_role(gr_usermode->sp_role);
53421 + read_lock(&tasklist_lock);
53422 + if (current->real_parent)
53423 + p = current->real_parent->role->rolename;
53424 + read_unlock(&tasklist_lock);
53425 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
53426 + p, acl_sp_role_value);
53427 + } else {
53428 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
53429 + error = -EPERM;
53430 + if(!(current->role->auth_attempts++))
53431 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
53432 +
53433 + goto out;
53434 + }
53435 + break;
53436 + case GR_UNSPROLE:
53437 + if (unlikely(!(gr_status & GR_READY))) {
53438 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
53439 + error = -EAGAIN;
53440 + break;
53441 + }
53442 +
53443 + if (current->role->roletype & GR_ROLE_SPECIAL) {
53444 + char *p = "";
53445 + int i = 0;
53446 +
53447 + read_lock(&tasklist_lock);
53448 + if (current->real_parent) {
53449 + p = current->real_parent->role->rolename;
53450 + i = current->real_parent->acl_role_id;
53451 + }
53452 + read_unlock(&tasklist_lock);
53453 +
53454 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
53455 + gr_set_acls(1);
53456 + } else {
53457 + error = -EPERM;
53458 + goto out;
53459 + }
53460 + break;
53461 + default:
53462 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
53463 + error = -EINVAL;
53464 + break;
53465 + }
53466 +
53467 + if (error != -EPERM)
53468 + goto out;
53469 +
53470 + if(!(gr_auth_attempts++))
53471 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
53472 +
53473 + out:
53474 + mutex_unlock(&gr_dev_mutex);
53475 + return error;
53476 +}
53477 +
53478 +/* must be called with
53479 + rcu_read_lock();
53480 + read_lock(&tasklist_lock);
53481 + read_lock(&grsec_exec_file_lock);
53482 +*/
53483 +int gr_apply_subject_to_task(struct task_struct *task)
53484 +{
53485 + struct acl_object_label *obj;
53486 + char *tmpname;
53487 + struct acl_subject_label *tmpsubj;
53488 + struct file *filp;
53489 + struct name_entry *nmatch;
53490 +
53491 + filp = task->exec_file;
53492 + if (filp == NULL)
53493 + return 0;
53494 +
53495 + /* the following is to apply the correct subject
53496 + on binaries running when the RBAC system
53497 + is enabled, when the binaries have been
53498 + replaced or deleted since their execution
53499 + -----
53500 + when the RBAC system starts, the inode/dev
53501 + from exec_file will be one the RBAC system
53502 + is unaware of. It only knows the inode/dev
53503 + of the present file on disk, or the absence
53504 + of it.
53505 + */
53506 + preempt_disable();
53507 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
53508 +
53509 + nmatch = lookup_name_entry(tmpname);
53510 + preempt_enable();
53511 + tmpsubj = NULL;
53512 + if (nmatch) {
53513 + if (nmatch->deleted)
53514 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
53515 + else
53516 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
53517 + if (tmpsubj != NULL)
53518 + task->acl = tmpsubj;
53519 + }
53520 + if (tmpsubj == NULL)
53521 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
53522 + task->role);
53523 + if (task->acl) {
53524 + task->is_writable = 0;
53525 + /* ignore additional mmap checks for processes that are writable
53526 + by the default ACL */
53527 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53528 + if (unlikely(obj->mode & GR_WRITE))
53529 + task->is_writable = 1;
53530 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53531 + if (unlikely(obj->mode & GR_WRITE))
53532 + task->is_writable = 1;
53533 +
53534 + gr_set_proc_res(task);
53535 +
53536 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53537 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53538 +#endif
53539 + } else {
53540 + return 1;
53541 + }
53542 +
53543 + return 0;
53544 +}
53545 +
53546 +int
53547 +gr_set_acls(const int type)
53548 +{
53549 + struct task_struct *task, *task2;
53550 + struct acl_role_label *role = current->role;
53551 + __u16 acl_role_id = current->acl_role_id;
53552 + const struct cred *cred;
53553 + int ret;
53554 +
53555 + rcu_read_lock();
53556 + read_lock(&tasklist_lock);
53557 + read_lock(&grsec_exec_file_lock);
53558 + do_each_thread(task2, task) {
53559 + /* check to see if we're called from the exit handler,
53560 + if so, only replace ACLs that have inherited the admin
53561 + ACL */
53562 +
53563 + if (type && (task->role != role ||
53564 + task->acl_role_id != acl_role_id))
53565 + continue;
53566 +
53567 + task->acl_role_id = 0;
53568 + task->acl_sp_role = 0;
53569 +
53570 + if (task->exec_file) {
53571 + cred = __task_cred(task);
53572 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
53573 + ret = gr_apply_subject_to_task(task);
53574 + if (ret) {
53575 + read_unlock(&grsec_exec_file_lock);
53576 + read_unlock(&tasklist_lock);
53577 + rcu_read_unlock();
53578 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
53579 + return ret;
53580 + }
53581 + } else {
53582 + // it's a kernel process
53583 + task->role = kernel_role;
53584 + task->acl = kernel_role->root_label;
53585 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
53586 + task->acl->mode &= ~GR_PROCFIND;
53587 +#endif
53588 + }
53589 + } while_each_thread(task2, task);
53590 + read_unlock(&grsec_exec_file_lock);
53591 + read_unlock(&tasklist_lock);
53592 + rcu_read_unlock();
53593 +
53594 + return 0;
53595 +}
53596 +
53597 +void
53598 +gr_learn_resource(const struct task_struct *task,
53599 + const int res, const unsigned long wanted, const int gt)
53600 +{
53601 + struct acl_subject_label *acl;
53602 + const struct cred *cred;
53603 +
53604 + if (unlikely((gr_status & GR_READY) &&
53605 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
53606 + goto skip_reslog;
53607 +
53608 +#ifdef CONFIG_GRKERNSEC_RESLOG
53609 + gr_log_resource(task, res, wanted, gt);
53610 +#endif
53611 + skip_reslog:
53612 +
53613 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
53614 + return;
53615 +
53616 + acl = task->acl;
53617 +
53618 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
53619 + !(acl->resmask & (1 << (unsigned short) res))))
53620 + return;
53621 +
53622 + if (wanted >= acl->res[res].rlim_cur) {
53623 + unsigned long res_add;
53624 +
53625 + res_add = wanted;
53626 + switch (res) {
53627 + case RLIMIT_CPU:
53628 + res_add += GR_RLIM_CPU_BUMP;
53629 + break;
53630 + case RLIMIT_FSIZE:
53631 + res_add += GR_RLIM_FSIZE_BUMP;
53632 + break;
53633 + case RLIMIT_DATA:
53634 + res_add += GR_RLIM_DATA_BUMP;
53635 + break;
53636 + case RLIMIT_STACK:
53637 + res_add += GR_RLIM_STACK_BUMP;
53638 + break;
53639 + case RLIMIT_CORE:
53640 + res_add += GR_RLIM_CORE_BUMP;
53641 + break;
53642 + case RLIMIT_RSS:
53643 + res_add += GR_RLIM_RSS_BUMP;
53644 + break;
53645 + case RLIMIT_NPROC:
53646 + res_add += GR_RLIM_NPROC_BUMP;
53647 + break;
53648 + case RLIMIT_NOFILE:
53649 + res_add += GR_RLIM_NOFILE_BUMP;
53650 + break;
53651 + case RLIMIT_MEMLOCK:
53652 + res_add += GR_RLIM_MEMLOCK_BUMP;
53653 + break;
53654 + case RLIMIT_AS:
53655 + res_add += GR_RLIM_AS_BUMP;
53656 + break;
53657 + case RLIMIT_LOCKS:
53658 + res_add += GR_RLIM_LOCKS_BUMP;
53659 + break;
53660 + case RLIMIT_SIGPENDING:
53661 + res_add += GR_RLIM_SIGPENDING_BUMP;
53662 + break;
53663 + case RLIMIT_MSGQUEUE:
53664 + res_add += GR_RLIM_MSGQUEUE_BUMP;
53665 + break;
53666 + case RLIMIT_NICE:
53667 + res_add += GR_RLIM_NICE_BUMP;
53668 + break;
53669 + case RLIMIT_RTPRIO:
53670 + res_add += GR_RLIM_RTPRIO_BUMP;
53671 + break;
53672 + case RLIMIT_RTTIME:
53673 + res_add += GR_RLIM_RTTIME_BUMP;
53674 + break;
53675 + }
53676 +
53677 + acl->res[res].rlim_cur = res_add;
53678 +
53679 + if (wanted > acl->res[res].rlim_max)
53680 + acl->res[res].rlim_max = res_add;
53681 +
53682 + /* only log the subject filename, since resource logging is supported for
53683 + single-subject learning only */
53684 + rcu_read_lock();
53685 + cred = __task_cred(task);
53686 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
53687 + task->role->roletype, cred->uid, cred->gid, acl->filename,
53688 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
53689 + "", (unsigned long) res, &task->signal->saved_ip);
53690 + rcu_read_unlock();
53691 + }
53692 +
53693 + return;
53694 +}
53695 +
53696 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
53697 +void
53698 +pax_set_initial_flags(struct linux_binprm *bprm)
53699 +{
53700 + struct task_struct *task = current;
53701 + struct acl_subject_label *proc;
53702 + unsigned long flags;
53703 +
53704 + if (unlikely(!(gr_status & GR_READY)))
53705 + return;
53706 +
53707 + flags = pax_get_flags(task);
53708 +
53709 + proc = task->acl;
53710 +
53711 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
53712 + flags &= ~MF_PAX_PAGEEXEC;
53713 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
53714 + flags &= ~MF_PAX_SEGMEXEC;
53715 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
53716 + flags &= ~MF_PAX_RANDMMAP;
53717 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
53718 + flags &= ~MF_PAX_EMUTRAMP;
53719 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
53720 + flags &= ~MF_PAX_MPROTECT;
53721 +
53722 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
53723 + flags |= MF_PAX_PAGEEXEC;
53724 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
53725 + flags |= MF_PAX_SEGMEXEC;
53726 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
53727 + flags |= MF_PAX_RANDMMAP;
53728 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
53729 + flags |= MF_PAX_EMUTRAMP;
53730 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
53731 + flags |= MF_PAX_MPROTECT;
53732 +
53733 + pax_set_flags(task, flags);
53734 +
53735 + return;
53736 +}
53737 +#endif
53738 +
53739 +int
53740 +gr_handle_proc_ptrace(struct task_struct *task)
53741 +{
53742 + struct file *filp;
53743 + struct task_struct *tmp = task;
53744 + struct task_struct *curtemp = current;
53745 + __u32 retmode;
53746 +
53747 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
53748 + if (unlikely(!(gr_status & GR_READY)))
53749 + return 0;
53750 +#endif
53751 +
53752 + read_lock(&tasklist_lock);
53753 + read_lock(&grsec_exec_file_lock);
53754 + filp = task->exec_file;
53755 +
53756 + while (tmp->pid > 0) {
53757 + if (tmp == curtemp)
53758 + break;
53759 + tmp = tmp->real_parent;
53760 + }
53761 +
53762 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
53763 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
53764 + read_unlock(&grsec_exec_file_lock);
53765 + read_unlock(&tasklist_lock);
53766 + return 1;
53767 + }
53768 +
53769 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
53770 + if (!(gr_status & GR_READY)) {
53771 + read_unlock(&grsec_exec_file_lock);
53772 + read_unlock(&tasklist_lock);
53773 + return 0;
53774 + }
53775 +#endif
53776 +
53777 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
53778 + read_unlock(&grsec_exec_file_lock);
53779 + read_unlock(&tasklist_lock);
53780 +
53781 + if (retmode & GR_NOPTRACE)
53782 + return 1;
53783 +
53784 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
53785 + && (current->acl != task->acl || (current->acl != current->role->root_label
53786 + && current->pid != task->pid)))
53787 + return 1;
53788 +
53789 + return 0;
53790 +}
53791 +
53792 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
53793 +{
53794 + if (unlikely(!(gr_status & GR_READY)))
53795 + return;
53796 +
53797 + if (!(current->role->roletype & GR_ROLE_GOD))
53798 + return;
53799 +
53800 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
53801 + p->role->rolename, gr_task_roletype_to_char(p),
53802 + p->acl->filename);
53803 +}
53804 +
53805 +int
53806 +gr_handle_ptrace(struct task_struct *task, const long request)
53807 +{
53808 + struct task_struct *tmp = task;
53809 + struct task_struct *curtemp = current;
53810 + __u32 retmode;
53811 +
53812 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
53813 + if (unlikely(!(gr_status & GR_READY)))
53814 + return 0;
53815 +#endif
53816 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
53817 + read_lock(&tasklist_lock);
53818 + while (tmp->pid > 0) {
53819 + if (tmp == curtemp)
53820 + break;
53821 + tmp = tmp->real_parent;
53822 + }
53823 +
53824 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
53825 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
53826 + read_unlock(&tasklist_lock);
53827 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
53828 + return 1;
53829 + }
53830 + read_unlock(&tasklist_lock);
53831 + }
53832 +
53833 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
53834 + if (!(gr_status & GR_READY))
53835 + return 0;
53836 +#endif
53837 +
53838 + read_lock(&grsec_exec_file_lock);
53839 + if (unlikely(!task->exec_file)) {
53840 + read_unlock(&grsec_exec_file_lock);
53841 + return 0;
53842 + }
53843 +
53844 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
53845 + read_unlock(&grsec_exec_file_lock);
53846 +
53847 + if (retmode & GR_NOPTRACE) {
53848 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
53849 + return 1;
53850 + }
53851 +
53852 + if (retmode & GR_PTRACERD) {
53853 + switch (request) {
53854 + case PTRACE_SEIZE:
53855 + case PTRACE_POKETEXT:
53856 + case PTRACE_POKEDATA:
53857 + case PTRACE_POKEUSR:
53858 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
53859 + case PTRACE_SETREGS:
53860 + case PTRACE_SETFPREGS:
53861 +#endif
53862 +#ifdef CONFIG_X86
53863 + case PTRACE_SETFPXREGS:
53864 +#endif
53865 +#ifdef CONFIG_ALTIVEC
53866 + case PTRACE_SETVRREGS:
53867 +#endif
53868 + return 1;
53869 + default:
53870 + return 0;
53871 + }
53872 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
53873 + !(current->role->roletype & GR_ROLE_GOD) &&
53874 + (current->acl != task->acl)) {
53875 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
53876 + return 1;
53877 + }
53878 +
53879 + return 0;
53880 +}
53881 +
53882 +static int is_writable_mmap(const struct file *filp)
53883 +{
53884 + struct task_struct *task = current;
53885 + struct acl_object_label *obj, *obj2;
53886 +
53887 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
53888 + !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))) {
53889 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53890 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
53891 + task->role->root_label);
53892 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
53893 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
53894 + return 1;
53895 + }
53896 + }
53897 + return 0;
53898 +}
53899 +
53900 +int
53901 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
53902 +{
53903 + __u32 mode;
53904 +
53905 + if (unlikely(!file || !(prot & PROT_EXEC)))
53906 + return 1;
53907 +
53908 + if (is_writable_mmap(file))
53909 + return 0;
53910 +
53911 + mode =
53912 + gr_search_file(file->f_path.dentry,
53913 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
53914 + file->f_path.mnt);
53915 +
53916 + if (!gr_tpe_allow(file))
53917 + return 0;
53918 +
53919 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
53920 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
53921 + return 0;
53922 + } else if (unlikely(!(mode & GR_EXEC))) {
53923 + return 0;
53924 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
53925 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
53926 + return 1;
53927 + }
53928 +
53929 + return 1;
53930 +}
53931 +
53932 +int
53933 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
53934 +{
53935 + __u32 mode;
53936 +
53937 + if (unlikely(!file || !(prot & PROT_EXEC)))
53938 + return 1;
53939 +
53940 + if (is_writable_mmap(file))
53941 + return 0;
53942 +
53943 + mode =
53944 + gr_search_file(file->f_path.dentry,
53945 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
53946 + file->f_path.mnt);
53947 +
53948 + if (!gr_tpe_allow(file))
53949 + return 0;
53950 +
53951 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
53952 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
53953 + return 0;
53954 + } else if (unlikely(!(mode & GR_EXEC))) {
53955 + return 0;
53956 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
53957 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
53958 + return 1;
53959 + }
53960 +
53961 + return 1;
53962 +}
53963 +
53964 +void
53965 +gr_acl_handle_psacct(struct task_struct *task, const long code)
53966 +{
53967 + unsigned long runtime;
53968 + unsigned long cputime;
53969 + unsigned int wday, cday;
53970 + __u8 whr, chr;
53971 + __u8 wmin, cmin;
53972 + __u8 wsec, csec;
53973 + struct timespec timeval;
53974 +
53975 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
53976 + !(task->acl->mode & GR_PROCACCT)))
53977 + return;
53978 +
53979 + do_posix_clock_monotonic_gettime(&timeval);
53980 + runtime = timeval.tv_sec - task->start_time.tv_sec;
53981 + wday = runtime / (3600 * 24);
53982 + runtime -= wday * (3600 * 24);
53983 + whr = runtime / 3600;
53984 + runtime -= whr * 3600;
53985 + wmin = runtime / 60;
53986 + runtime -= wmin * 60;
53987 + wsec = runtime;
53988 +
53989 + cputime = (task->utime + task->stime) / HZ;
53990 + cday = cputime / (3600 * 24);
53991 + cputime -= cday * (3600 * 24);
53992 + chr = cputime / 3600;
53993 + cputime -= chr * 3600;
53994 + cmin = cputime / 60;
53995 + cputime -= cmin * 60;
53996 + csec = cputime;
53997 +
53998 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
53999 +
54000 + return;
54001 +}
54002 +
54003 +void gr_set_kernel_label(struct task_struct *task)
54004 +{
54005 + if (gr_status & GR_READY) {
54006 + task->role = kernel_role;
54007 + task->acl = kernel_role->root_label;
54008 + }
54009 + return;
54010 +}
54011 +
54012 +#ifdef CONFIG_TASKSTATS
54013 +int gr_is_taskstats_denied(int pid)
54014 +{
54015 + struct task_struct *task;
54016 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54017 + const struct cred *cred;
54018 +#endif
54019 + int ret = 0;
54020 +
54021 + /* restrict taskstats viewing to un-chrooted root users
54022 + who have the 'view' subject flag if the RBAC system is enabled
54023 + */
54024 +
54025 + rcu_read_lock();
54026 + read_lock(&tasklist_lock);
54027 + task = find_task_by_vpid(pid);
54028 + if (task) {
54029 +#ifdef CONFIG_GRKERNSEC_CHROOT
54030 + if (proc_is_chrooted(task))
54031 + ret = -EACCES;
54032 +#endif
54033 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54034 + cred = __task_cred(task);
54035 +#ifdef CONFIG_GRKERNSEC_PROC_USER
54036 + if (cred->uid != 0)
54037 + ret = -EACCES;
54038 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54039 + if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
54040 + ret = -EACCES;
54041 +#endif
54042 +#endif
54043 + if (gr_status & GR_READY) {
54044 + if (!(task->acl->mode & GR_VIEW))
54045 + ret = -EACCES;
54046 + }
54047 + } else
54048 + ret = -ENOENT;
54049 +
54050 + read_unlock(&tasklist_lock);
54051 + rcu_read_unlock();
54052 +
54053 + return ret;
54054 +}
54055 +#endif
54056 +
54057 +/* AUXV entries are filled via a descendant of search_binary_handler
54058 + after we've already applied the subject for the target
54059 +*/
54060 +int gr_acl_enable_at_secure(void)
54061 +{
54062 + if (unlikely(!(gr_status & GR_READY)))
54063 + return 0;
54064 +
54065 + if (current->acl->mode & GR_ATSECURE)
54066 + return 1;
54067 +
54068 + return 0;
54069 +}
54070 +
54071 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
54072 +{
54073 + struct task_struct *task = current;
54074 + struct dentry *dentry = file->f_path.dentry;
54075 + struct vfsmount *mnt = file->f_path.mnt;
54076 + struct acl_object_label *obj, *tmp;
54077 + struct acl_subject_label *subj;
54078 + unsigned int bufsize;
54079 + int is_not_root;
54080 + char *path;
54081 + dev_t dev = __get_dev(dentry);
54082 +
54083 + if (unlikely(!(gr_status & GR_READY)))
54084 + return 1;
54085 +
54086 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54087 + return 1;
54088 +
54089 + /* ignore Eric Biederman */
54090 + if (IS_PRIVATE(dentry->d_inode))
54091 + return 1;
54092 +
54093 + subj = task->acl;
54094 + read_lock(&gr_inode_lock);
54095 + do {
54096 + obj = lookup_acl_obj_label(ino, dev, subj);
54097 + if (obj != NULL) {
54098 + read_unlock(&gr_inode_lock);
54099 + return (obj->mode & GR_FIND) ? 1 : 0;
54100 + }
54101 + } while ((subj = subj->parent_subject));
54102 + read_unlock(&gr_inode_lock);
54103 +
54104 + /* this is purely an optimization since we're looking for an object
54105 + for the directory we're doing a readdir on
54106 + if it's possible for any globbed object to match the entry we're
54107 + filling into the directory, then the object we find here will be
54108 + an anchor point with attached globbed objects
54109 + */
54110 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
54111 + if (obj->globbed == NULL)
54112 + return (obj->mode & GR_FIND) ? 1 : 0;
54113 +
54114 + is_not_root = ((obj->filename[0] == '/') &&
54115 + (obj->filename[1] == '\0')) ? 0 : 1;
54116 + bufsize = PAGE_SIZE - namelen - is_not_root;
54117 +
54118 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
54119 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
54120 + return 1;
54121 +
54122 + preempt_disable();
54123 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
54124 + bufsize);
54125 +
54126 + bufsize = strlen(path);
54127 +
54128 + /* if base is "/", don't append an additional slash */
54129 + if (is_not_root)
54130 + *(path + bufsize) = '/';
54131 + memcpy(path + bufsize + is_not_root, name, namelen);
54132 + *(path + bufsize + namelen + is_not_root) = '\0';
54133 +
54134 + tmp = obj->globbed;
54135 + while (tmp) {
54136 + if (!glob_match(tmp->filename, path)) {
54137 + preempt_enable();
54138 + return (tmp->mode & GR_FIND) ? 1 : 0;
54139 + }
54140 + tmp = tmp->next;
54141 + }
54142 + preempt_enable();
54143 + return (obj->mode & GR_FIND) ? 1 : 0;
54144 +}
54145 +
54146 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
54147 +EXPORT_SYMBOL(gr_acl_is_enabled);
54148 +#endif
54149 +EXPORT_SYMBOL(gr_learn_resource);
54150 +EXPORT_SYMBOL(gr_set_kernel_label);
54151 +#ifdef CONFIG_SECURITY
54152 +EXPORT_SYMBOL(gr_check_user_change);
54153 +EXPORT_SYMBOL(gr_check_group_change);
54154 +#endif
54155 +
54156 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
54157 new file mode 100644
54158 index 0000000..34fefda
54159 --- /dev/null
54160 +++ b/grsecurity/gracl_alloc.c
54161 @@ -0,0 +1,105 @@
54162 +#include <linux/kernel.h>
54163 +#include <linux/mm.h>
54164 +#include <linux/slab.h>
54165 +#include <linux/vmalloc.h>
54166 +#include <linux/gracl.h>
54167 +#include <linux/grsecurity.h>
54168 +
54169 +static unsigned long alloc_stack_next = 1;
54170 +static unsigned long alloc_stack_size = 1;
54171 +static void **alloc_stack;
54172 +
54173 +static __inline__ int
54174 +alloc_pop(void)
54175 +{
54176 + if (alloc_stack_next == 1)
54177 + return 0;
54178 +
54179 + kfree(alloc_stack[alloc_stack_next - 2]);
54180 +
54181 + alloc_stack_next--;
54182 +
54183 + return 1;
54184 +}
54185 +
54186 +static __inline__ int
54187 +alloc_push(void *buf)
54188 +{
54189 + if (alloc_stack_next >= alloc_stack_size)
54190 + return 1;
54191 +
54192 + alloc_stack[alloc_stack_next - 1] = buf;
54193 +
54194 + alloc_stack_next++;
54195 +
54196 + return 0;
54197 +}
54198 +
54199 +void *
54200 +acl_alloc(unsigned long len)
54201 +{
54202 + void *ret = NULL;
54203 +
54204 + if (!len || len > PAGE_SIZE)
54205 + goto out;
54206 +
54207 + ret = kmalloc(len, GFP_KERNEL);
54208 +
54209 + if (ret) {
54210 + if (alloc_push(ret)) {
54211 + kfree(ret);
54212 + ret = NULL;
54213 + }
54214 + }
54215 +
54216 +out:
54217 + return ret;
54218 +}
54219 +
54220 +void *
54221 +acl_alloc_num(unsigned long num, unsigned long len)
54222 +{
54223 + if (!len || (num > (PAGE_SIZE / len)))
54224 + return NULL;
54225 +
54226 + return acl_alloc(num * len);
54227 +}
54228 +
54229 +void
54230 +acl_free_all(void)
54231 +{
54232 + if (gr_acl_is_enabled() || !alloc_stack)
54233 + return;
54234 +
54235 + while (alloc_pop()) ;
54236 +
54237 + if (alloc_stack) {
54238 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
54239 + kfree(alloc_stack);
54240 + else
54241 + vfree(alloc_stack);
54242 + }
54243 +
54244 + alloc_stack = NULL;
54245 + alloc_stack_size = 1;
54246 + alloc_stack_next = 1;
54247 +
54248 + return;
54249 +}
54250 +
54251 +int
54252 +acl_alloc_stack_init(unsigned long size)
54253 +{
54254 + if ((size * sizeof (void *)) <= PAGE_SIZE)
54255 + alloc_stack =
54256 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
54257 + else
54258 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
54259 +
54260 + alloc_stack_size = size;
54261 +
54262 + if (!alloc_stack)
54263 + return 0;
54264 + else
54265 + return 1;
54266 +}
54267 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
54268 new file mode 100644
54269 index 0000000..6d21049
54270 --- /dev/null
54271 +++ b/grsecurity/gracl_cap.c
54272 @@ -0,0 +1,110 @@
54273 +#include <linux/kernel.h>
54274 +#include <linux/module.h>
54275 +#include <linux/sched.h>
54276 +#include <linux/gracl.h>
54277 +#include <linux/grsecurity.h>
54278 +#include <linux/grinternal.h>
54279 +
54280 +extern const char *captab_log[];
54281 +extern int captab_log_entries;
54282 +
54283 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
54284 +{
54285 + struct acl_subject_label *curracl;
54286 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
54287 + kernel_cap_t cap_audit = __cap_empty_set;
54288 +
54289 + if (!gr_acl_is_enabled())
54290 + return 1;
54291 +
54292 + curracl = task->acl;
54293 +
54294 + cap_drop = curracl->cap_lower;
54295 + cap_mask = curracl->cap_mask;
54296 + cap_audit = curracl->cap_invert_audit;
54297 +
54298 + while ((curracl = curracl->parent_subject)) {
54299 + /* if the cap isn't specified in the current computed mask but is specified in the
54300 + current level subject, and is lowered in the current level subject, then add
54301 + it to the set of dropped capabilities
54302 + otherwise, add the current level subject's mask to the current computed mask
54303 + */
54304 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
54305 + cap_raise(cap_mask, cap);
54306 + if (cap_raised(curracl->cap_lower, cap))
54307 + cap_raise(cap_drop, cap);
54308 + if (cap_raised(curracl->cap_invert_audit, cap))
54309 + cap_raise(cap_audit, cap);
54310 + }
54311 + }
54312 +
54313 + if (!cap_raised(cap_drop, cap)) {
54314 + if (cap_raised(cap_audit, cap))
54315 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
54316 + return 1;
54317 + }
54318 +
54319 + curracl = task->acl;
54320 +
54321 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
54322 + && cap_raised(cred->cap_effective, cap)) {
54323 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54324 + task->role->roletype, cred->uid,
54325 + cred->gid, task->exec_file ?
54326 + gr_to_filename(task->exec_file->f_path.dentry,
54327 + task->exec_file->f_path.mnt) : curracl->filename,
54328 + curracl->filename, 0UL,
54329 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
54330 + return 1;
54331 + }
54332 +
54333 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
54334 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
54335 +
54336 + return 0;
54337 +}
54338 +
54339 +int
54340 +gr_acl_is_capable(const int cap)
54341 +{
54342 + return gr_task_acl_is_capable(current, current_cred(), cap);
54343 +}
54344 +
54345 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
54346 +{
54347 + struct acl_subject_label *curracl;
54348 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
54349 +
54350 + if (!gr_acl_is_enabled())
54351 + return 1;
54352 +
54353 + curracl = task->acl;
54354 +
54355 + cap_drop = curracl->cap_lower;
54356 + cap_mask = curracl->cap_mask;
54357 +
54358 + while ((curracl = curracl->parent_subject)) {
54359 + /* if the cap isn't specified in the current computed mask but is specified in the
54360 + current level subject, and is lowered in the current level subject, then add
54361 + it to the set of dropped capabilities
54362 + otherwise, add the current level subject's mask to the current computed mask
54363 + */
54364 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
54365 + cap_raise(cap_mask, cap);
54366 + if (cap_raised(curracl->cap_lower, cap))
54367 + cap_raise(cap_drop, cap);
54368 + }
54369 + }
54370 +
54371 + if (!cap_raised(cap_drop, cap))
54372 + return 1;
54373 +
54374 + return 0;
54375 +}
54376 +
54377 +int
54378 +gr_acl_is_capable_nolog(const int cap)
54379 +{
54380 + return gr_task_acl_is_capable_nolog(current, cap);
54381 +}
54382 +
54383 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
54384 new file mode 100644
54385 index 0000000..88d0e87
54386 --- /dev/null
54387 +++ b/grsecurity/gracl_fs.c
54388 @@ -0,0 +1,435 @@
54389 +#include <linux/kernel.h>
54390 +#include <linux/sched.h>
54391 +#include <linux/types.h>
54392 +#include <linux/fs.h>
54393 +#include <linux/file.h>
54394 +#include <linux/stat.h>
54395 +#include <linux/grsecurity.h>
54396 +#include <linux/grinternal.h>
54397 +#include <linux/gracl.h>
54398 +
54399 +umode_t
54400 +gr_acl_umask(void)
54401 +{
54402 + if (unlikely(!gr_acl_is_enabled()))
54403 + return 0;
54404 +
54405 + return current->role->umask;
54406 +}
54407 +
54408 +__u32
54409 +gr_acl_handle_hidden_file(const struct dentry * dentry,
54410 + const struct vfsmount * mnt)
54411 +{
54412 + __u32 mode;
54413 +
54414 + if (unlikely(!dentry->d_inode))
54415 + return GR_FIND;
54416 +
54417 + mode =
54418 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
54419 +
54420 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
54421 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
54422 + return mode;
54423 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
54424 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
54425 + return 0;
54426 + } else if (unlikely(!(mode & GR_FIND)))
54427 + return 0;
54428 +
54429 + return GR_FIND;
54430 +}
54431 +
54432 +__u32
54433 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
54434 + int acc_mode)
54435 +{
54436 + __u32 reqmode = GR_FIND;
54437 + __u32 mode;
54438 +
54439 + if (unlikely(!dentry->d_inode))
54440 + return reqmode;
54441 +
54442 + if (acc_mode & MAY_APPEND)
54443 + reqmode |= GR_APPEND;
54444 + else if (acc_mode & MAY_WRITE)
54445 + reqmode |= GR_WRITE;
54446 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
54447 + reqmode |= GR_READ;
54448 +
54449 + mode =
54450 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
54451 + mnt);
54452 +
54453 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
54454 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
54455 + reqmode & GR_READ ? " reading" : "",
54456 + reqmode & GR_WRITE ? " writing" : reqmode &
54457 + GR_APPEND ? " appending" : "");
54458 + return reqmode;
54459 + } else
54460 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
54461 + {
54462 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
54463 + reqmode & GR_READ ? " reading" : "",
54464 + reqmode & GR_WRITE ? " writing" : reqmode &
54465 + GR_APPEND ? " appending" : "");
54466 + return 0;
54467 + } else if (unlikely((mode & reqmode) != reqmode))
54468 + return 0;
54469 +
54470 + return reqmode;
54471 +}
54472 +
54473 +__u32
54474 +gr_acl_handle_creat(const struct dentry * dentry,
54475 + const struct dentry * p_dentry,
54476 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
54477 + const int imode)
54478 +{
54479 + __u32 reqmode = GR_WRITE | GR_CREATE;
54480 + __u32 mode;
54481 +
54482 + if (acc_mode & MAY_APPEND)
54483 + reqmode |= GR_APPEND;
54484 + // if a directory was required or the directory already exists, then
54485 + // don't count this open as a read
54486 + if ((acc_mode & MAY_READ) &&
54487 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
54488 + reqmode |= GR_READ;
54489 + if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
54490 + reqmode |= GR_SETID;
54491 +
54492 + mode =
54493 + gr_check_create(dentry, p_dentry, p_mnt,
54494 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
54495 +
54496 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
54497 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
54498 + reqmode & GR_READ ? " reading" : "",
54499 + reqmode & GR_WRITE ? " writing" : reqmode &
54500 + GR_APPEND ? " appending" : "");
54501 + return reqmode;
54502 + } else
54503 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
54504 + {
54505 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
54506 + reqmode & GR_READ ? " reading" : "",
54507 + reqmode & GR_WRITE ? " writing" : reqmode &
54508 + GR_APPEND ? " appending" : "");
54509 + return 0;
54510 + } else if (unlikely((mode & reqmode) != reqmode))
54511 + return 0;
54512 +
54513 + return reqmode;
54514 +}
54515 +
54516 +__u32
54517 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
54518 + const int fmode)
54519 +{
54520 + __u32 mode, reqmode = GR_FIND;
54521 +
54522 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
54523 + reqmode |= GR_EXEC;
54524 + if (fmode & S_IWOTH)
54525 + reqmode |= GR_WRITE;
54526 + if (fmode & S_IROTH)
54527 + reqmode |= GR_READ;
54528 +
54529 + mode =
54530 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
54531 + mnt);
54532 +
54533 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
54534 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
54535 + reqmode & GR_READ ? " reading" : "",
54536 + reqmode & GR_WRITE ? " writing" : "",
54537 + reqmode & GR_EXEC ? " executing" : "");
54538 + return reqmode;
54539 + } else
54540 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
54541 + {
54542 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
54543 + reqmode & GR_READ ? " reading" : "",
54544 + reqmode & GR_WRITE ? " writing" : "",
54545 + reqmode & GR_EXEC ? " executing" : "");
54546 + return 0;
54547 + } else if (unlikely((mode & reqmode) != reqmode))
54548 + return 0;
54549 +
54550 + return reqmode;
54551 +}
54552 +
54553 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
54554 +{
54555 + __u32 mode;
54556 +
54557 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
54558 +
54559 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
54560 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
54561 + return mode;
54562 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
54563 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
54564 + return 0;
54565 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
54566 + return 0;
54567 +
54568 + return (reqmode);
54569 +}
54570 +
54571 +__u32
54572 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
54573 +{
54574 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
54575 +}
54576 +
54577 +__u32
54578 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
54579 +{
54580 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
54581 +}
54582 +
54583 +__u32
54584 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
54585 +{
54586 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
54587 +}
54588 +
54589 +__u32
54590 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
54591 +{
54592 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
54593 +}
54594 +
54595 +__u32
54596 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
54597 + umode_t *modeptr)
54598 +{
54599 + umode_t mode;
54600 +
54601 + *modeptr &= ~gr_acl_umask();
54602 + mode = *modeptr;
54603 +
54604 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
54605 + return 1;
54606 +
54607 + if (unlikely(mode & (S_ISUID | S_ISGID))) {
54608 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
54609 + GR_CHMOD_ACL_MSG);
54610 + } else {
54611 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
54612 + }
54613 +}
54614 +
54615 +__u32
54616 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
54617 +{
54618 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
54619 +}
54620 +
54621 +__u32
54622 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
54623 +{
54624 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
54625 +}
54626 +
54627 +__u32
54628 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
54629 +{
54630 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
54631 +}
54632 +
54633 +__u32
54634 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
54635 +{
54636 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
54637 + GR_UNIXCONNECT_ACL_MSG);
54638 +}
54639 +
54640 +/* hardlinks require at minimum create and link permission,
54641 + any additional privilege required is based on the
54642 + privilege of the file being linked to
54643 +*/
54644 +__u32
54645 +gr_acl_handle_link(const struct dentry * new_dentry,
54646 + const struct dentry * parent_dentry,
54647 + const struct vfsmount * parent_mnt,
54648 + const struct dentry * old_dentry,
54649 + const struct vfsmount * old_mnt, const char *to)
54650 +{
54651 + __u32 mode;
54652 + __u32 needmode = GR_CREATE | GR_LINK;
54653 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
54654 +
54655 + mode =
54656 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
54657 + old_mnt);
54658 +
54659 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
54660 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
54661 + return mode;
54662 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
54663 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
54664 + return 0;
54665 + } else if (unlikely((mode & needmode) != needmode))
54666 + return 0;
54667 +
54668 + return 1;
54669 +}
54670 +
54671 +__u32
54672 +gr_acl_handle_symlink(const struct dentry * new_dentry,
54673 + const struct dentry * parent_dentry,
54674 + const struct vfsmount * parent_mnt, const char *from)
54675 +{
54676 + __u32 needmode = GR_WRITE | GR_CREATE;
54677 + __u32 mode;
54678 +
54679 + mode =
54680 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
54681 + GR_CREATE | GR_AUDIT_CREATE |
54682 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
54683 +
54684 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
54685 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
54686 + return mode;
54687 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
54688 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
54689 + return 0;
54690 + } else if (unlikely((mode & needmode) != needmode))
54691 + return 0;
54692 +
54693 + return (GR_WRITE | GR_CREATE);
54694 +}
54695 +
54696 +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)
54697 +{
54698 + __u32 mode;
54699 +
54700 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
54701 +
54702 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
54703 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
54704 + return mode;
54705 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
54706 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
54707 + return 0;
54708 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
54709 + return 0;
54710 +
54711 + return (reqmode);
54712 +}
54713 +
54714 +__u32
54715 +gr_acl_handle_mknod(const struct dentry * new_dentry,
54716 + const struct dentry * parent_dentry,
54717 + const struct vfsmount * parent_mnt,
54718 + const int mode)
54719 +{
54720 + __u32 reqmode = GR_WRITE | GR_CREATE;
54721 + if (unlikely(mode & (S_ISUID | S_ISGID)))
54722 + reqmode |= GR_SETID;
54723 +
54724 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
54725 + reqmode, GR_MKNOD_ACL_MSG);
54726 +}
54727 +
54728 +__u32
54729 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
54730 + const struct dentry *parent_dentry,
54731 + const struct vfsmount *parent_mnt)
54732 +{
54733 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
54734 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
54735 +}
54736 +
54737 +#define RENAME_CHECK_SUCCESS(old, new) \
54738 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
54739 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
54740 +
54741 +int
54742 +gr_acl_handle_rename(struct dentry *new_dentry,
54743 + struct dentry *parent_dentry,
54744 + const struct vfsmount *parent_mnt,
54745 + struct dentry *old_dentry,
54746 + struct inode *old_parent_inode,
54747 + struct vfsmount *old_mnt, const char *newname)
54748 +{
54749 + __u32 comp1, comp2;
54750 + int error = 0;
54751 +
54752 + if (unlikely(!gr_acl_is_enabled()))
54753 + return 0;
54754 +
54755 + if (!new_dentry->d_inode) {
54756 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
54757 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
54758 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
54759 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
54760 + GR_DELETE | GR_AUDIT_DELETE |
54761 + GR_AUDIT_READ | GR_AUDIT_WRITE |
54762 + GR_SUPPRESS, old_mnt);
54763 + } else {
54764 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
54765 + GR_CREATE | GR_DELETE |
54766 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
54767 + GR_AUDIT_READ | GR_AUDIT_WRITE |
54768 + GR_SUPPRESS, parent_mnt);
54769 + comp2 =
54770 + gr_search_file(old_dentry,
54771 + GR_READ | GR_WRITE | GR_AUDIT_READ |
54772 + GR_DELETE | GR_AUDIT_DELETE |
54773 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
54774 + }
54775 +
54776 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
54777 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
54778 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
54779 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
54780 + && !(comp2 & GR_SUPPRESS)) {
54781 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
54782 + error = -EACCES;
54783 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
54784 + error = -EACCES;
54785 +
54786 + return error;
54787 +}
54788 +
54789 +void
54790 +gr_acl_handle_exit(void)
54791 +{
54792 + u16 id;
54793 + char *rolename;
54794 + struct file *exec_file;
54795 +
54796 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
54797 + !(current->role->roletype & GR_ROLE_PERSIST))) {
54798 + id = current->acl_role_id;
54799 + rolename = current->role->rolename;
54800 + gr_set_acls(1);
54801 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
54802 + }
54803 +
54804 + write_lock(&grsec_exec_file_lock);
54805 + exec_file = current->exec_file;
54806 + current->exec_file = NULL;
54807 + write_unlock(&grsec_exec_file_lock);
54808 +
54809 + if (exec_file)
54810 + fput(exec_file);
54811 +}
54812 +
54813 +int
54814 +gr_acl_handle_procpidmem(const struct task_struct *task)
54815 +{
54816 + if (unlikely(!gr_acl_is_enabled()))
54817 + return 0;
54818 +
54819 + if (task != current && task->acl->mode & GR_PROTPROCFD)
54820 + return -EACCES;
54821 +
54822 + return 0;
54823 +}
54824 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
54825 new file mode 100644
54826 index 0000000..58800a7
54827 --- /dev/null
54828 +++ b/grsecurity/gracl_ip.c
54829 @@ -0,0 +1,384 @@
54830 +#include <linux/kernel.h>
54831 +#include <asm/uaccess.h>
54832 +#include <asm/errno.h>
54833 +#include <net/sock.h>
54834 +#include <linux/file.h>
54835 +#include <linux/fs.h>
54836 +#include <linux/net.h>
54837 +#include <linux/in.h>
54838 +#include <linux/skbuff.h>
54839 +#include <linux/ip.h>
54840 +#include <linux/udp.h>
54841 +#include <linux/types.h>
54842 +#include <linux/sched.h>
54843 +#include <linux/netdevice.h>
54844 +#include <linux/inetdevice.h>
54845 +#include <linux/gracl.h>
54846 +#include <linux/grsecurity.h>
54847 +#include <linux/grinternal.h>
54848 +
54849 +#define GR_BIND 0x01
54850 +#define GR_CONNECT 0x02
54851 +#define GR_INVERT 0x04
54852 +#define GR_BINDOVERRIDE 0x08
54853 +#define GR_CONNECTOVERRIDE 0x10
54854 +#define GR_SOCK_FAMILY 0x20
54855 +
54856 +static const char * gr_protocols[IPPROTO_MAX] = {
54857 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
54858 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
54859 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
54860 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
54861 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
54862 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
54863 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
54864 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
54865 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
54866 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
54867 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
54868 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
54869 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
54870 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
54871 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
54872 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
54873 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
54874 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
54875 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
54876 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
54877 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
54878 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
54879 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
54880 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
54881 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
54882 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
54883 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
54884 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
54885 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
54886 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
54887 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
54888 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
54889 + };
54890 +
54891 +static const char * gr_socktypes[SOCK_MAX] = {
54892 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
54893 + "unknown:7", "unknown:8", "unknown:9", "packet"
54894 + };
54895 +
54896 +static const char * gr_sockfamilies[AF_MAX+1] = {
54897 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
54898 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
54899 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
54900 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
54901 + };
54902 +
54903 +const char *
54904 +gr_proto_to_name(unsigned char proto)
54905 +{
54906 + return gr_protocols[proto];
54907 +}
54908 +
54909 +const char *
54910 +gr_socktype_to_name(unsigned char type)
54911 +{
54912 + return gr_socktypes[type];
54913 +}
54914 +
54915 +const char *
54916 +gr_sockfamily_to_name(unsigned char family)
54917 +{
54918 + return gr_sockfamilies[family];
54919 +}
54920 +
54921 +int
54922 +gr_search_socket(const int domain, const int type, const int protocol)
54923 +{
54924 + struct acl_subject_label *curr;
54925 + const struct cred *cred = current_cred();
54926 +
54927 + if (unlikely(!gr_acl_is_enabled()))
54928 + goto exit;
54929 +
54930 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
54931 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
54932 + goto exit; // let the kernel handle it
54933 +
54934 + curr = current->acl;
54935 +
54936 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
54937 + /* the family is allowed, if this is PF_INET allow it only if
54938 + the extra sock type/protocol checks pass */
54939 + if (domain == PF_INET)
54940 + goto inet_check;
54941 + goto exit;
54942 + } else {
54943 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
54944 + __u32 fakeip = 0;
54945 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
54946 + current->role->roletype, cred->uid,
54947 + cred->gid, current->exec_file ?
54948 + gr_to_filename(current->exec_file->f_path.dentry,
54949 + current->exec_file->f_path.mnt) :
54950 + curr->filename, curr->filename,
54951 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
54952 + &current->signal->saved_ip);
54953 + goto exit;
54954 + }
54955 + goto exit_fail;
54956 + }
54957 +
54958 +inet_check:
54959 + /* the rest of this checking is for IPv4 only */
54960 + if (!curr->ips)
54961 + goto exit;
54962 +
54963 + if ((curr->ip_type & (1 << type)) &&
54964 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
54965 + goto exit;
54966 +
54967 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
54968 + /* we don't place acls on raw sockets , and sometimes
54969 + dgram/ip sockets are opened for ioctl and not
54970 + bind/connect, so we'll fake a bind learn log */
54971 + if (type == SOCK_RAW || type == SOCK_PACKET) {
54972 + __u32 fakeip = 0;
54973 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
54974 + current->role->roletype, cred->uid,
54975 + cred->gid, current->exec_file ?
54976 + gr_to_filename(current->exec_file->f_path.dentry,
54977 + current->exec_file->f_path.mnt) :
54978 + curr->filename, curr->filename,
54979 + &fakeip, 0, type,
54980 + protocol, GR_CONNECT, &current->signal->saved_ip);
54981 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
54982 + __u32 fakeip = 0;
54983 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
54984 + current->role->roletype, cred->uid,
54985 + cred->gid, current->exec_file ?
54986 + gr_to_filename(current->exec_file->f_path.dentry,
54987 + current->exec_file->f_path.mnt) :
54988 + curr->filename, curr->filename,
54989 + &fakeip, 0, type,
54990 + protocol, GR_BIND, &current->signal->saved_ip);
54991 + }
54992 + /* we'll log when they use connect or bind */
54993 + goto exit;
54994 + }
54995 +
54996 +exit_fail:
54997 + if (domain == PF_INET)
54998 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
54999 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
55000 + else
55001 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
55002 + gr_socktype_to_name(type), protocol);
55003 +
55004 + return 0;
55005 +exit:
55006 + return 1;
55007 +}
55008 +
55009 +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)
55010 +{
55011 + if ((ip->mode & mode) &&
55012 + (ip_port >= ip->low) &&
55013 + (ip_port <= ip->high) &&
55014 + ((ntohl(ip_addr) & our_netmask) ==
55015 + (ntohl(our_addr) & our_netmask))
55016 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
55017 + && (ip->type & (1 << type))) {
55018 + if (ip->mode & GR_INVERT)
55019 + return 2; // specifically denied
55020 + else
55021 + return 1; // allowed
55022 + }
55023 +
55024 + return 0; // not specifically allowed, may continue parsing
55025 +}
55026 +
55027 +static int
55028 +gr_search_connectbind(const int full_mode, struct sock *sk,
55029 + struct sockaddr_in *addr, const int type)
55030 +{
55031 + char iface[IFNAMSIZ] = {0};
55032 + struct acl_subject_label *curr;
55033 + struct acl_ip_label *ip;
55034 + struct inet_sock *isk;
55035 + struct net_device *dev;
55036 + struct in_device *idev;
55037 + unsigned long i;
55038 + int ret;
55039 + int mode = full_mode & (GR_BIND | GR_CONNECT);
55040 + __u32 ip_addr = 0;
55041 + __u32 our_addr;
55042 + __u32 our_netmask;
55043 + char *p;
55044 + __u16 ip_port = 0;
55045 + const struct cred *cred = current_cred();
55046 +
55047 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
55048 + return 0;
55049 +
55050 + curr = current->acl;
55051 + isk = inet_sk(sk);
55052 +
55053 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
55054 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
55055 + addr->sin_addr.s_addr = curr->inaddr_any_override;
55056 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
55057 + struct sockaddr_in saddr;
55058 + int err;
55059 +
55060 + saddr.sin_family = AF_INET;
55061 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
55062 + saddr.sin_port = isk->inet_sport;
55063 +
55064 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55065 + if (err)
55066 + return err;
55067 +
55068 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55069 + if (err)
55070 + return err;
55071 + }
55072 +
55073 + if (!curr->ips)
55074 + return 0;
55075 +
55076 + ip_addr = addr->sin_addr.s_addr;
55077 + ip_port = ntohs(addr->sin_port);
55078 +
55079 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55080 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55081 + current->role->roletype, cred->uid,
55082 + cred->gid, current->exec_file ?
55083 + gr_to_filename(current->exec_file->f_path.dentry,
55084 + current->exec_file->f_path.mnt) :
55085 + curr->filename, curr->filename,
55086 + &ip_addr, ip_port, type,
55087 + sk->sk_protocol, mode, &current->signal->saved_ip);
55088 + return 0;
55089 + }
55090 +
55091 + for (i = 0; i < curr->ip_num; i++) {
55092 + ip = *(curr->ips + i);
55093 + if (ip->iface != NULL) {
55094 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
55095 + p = strchr(iface, ':');
55096 + if (p != NULL)
55097 + *p = '\0';
55098 + dev = dev_get_by_name(sock_net(sk), iface);
55099 + if (dev == NULL)
55100 + continue;
55101 + idev = in_dev_get(dev);
55102 + if (idev == NULL) {
55103 + dev_put(dev);
55104 + continue;
55105 + }
55106 + rcu_read_lock();
55107 + for_ifa(idev) {
55108 + if (!strcmp(ip->iface, ifa->ifa_label)) {
55109 + our_addr = ifa->ifa_address;
55110 + our_netmask = 0xffffffff;
55111 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55112 + if (ret == 1) {
55113 + rcu_read_unlock();
55114 + in_dev_put(idev);
55115 + dev_put(dev);
55116 + return 0;
55117 + } else if (ret == 2) {
55118 + rcu_read_unlock();
55119 + in_dev_put(idev);
55120 + dev_put(dev);
55121 + goto denied;
55122 + }
55123 + }
55124 + } endfor_ifa(idev);
55125 + rcu_read_unlock();
55126 + in_dev_put(idev);
55127 + dev_put(dev);
55128 + } else {
55129 + our_addr = ip->addr;
55130 + our_netmask = ip->netmask;
55131 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55132 + if (ret == 1)
55133 + return 0;
55134 + else if (ret == 2)
55135 + goto denied;
55136 + }
55137 + }
55138 +
55139 +denied:
55140 + if (mode == GR_BIND)
55141 + 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));
55142 + else if (mode == GR_CONNECT)
55143 + 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));
55144 +
55145 + return -EACCES;
55146 +}
55147 +
55148 +int
55149 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
55150 +{
55151 + /* always allow disconnection of dgram sockets with connect */
55152 + if (addr->sin_family == AF_UNSPEC)
55153 + return 0;
55154 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
55155 +}
55156 +
55157 +int
55158 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
55159 +{
55160 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
55161 +}
55162 +
55163 +int gr_search_listen(struct socket *sock)
55164 +{
55165 + struct sock *sk = sock->sk;
55166 + struct sockaddr_in addr;
55167 +
55168 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
55169 + addr.sin_port = inet_sk(sk)->inet_sport;
55170 +
55171 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
55172 +}
55173 +
55174 +int gr_search_accept(struct socket *sock)
55175 +{
55176 + struct sock *sk = sock->sk;
55177 + struct sockaddr_in addr;
55178 +
55179 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
55180 + addr.sin_port = inet_sk(sk)->inet_sport;
55181 +
55182 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
55183 +}
55184 +
55185 +int
55186 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
55187 +{
55188 + if (addr)
55189 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
55190 + else {
55191 + struct sockaddr_in sin;
55192 + const struct inet_sock *inet = inet_sk(sk);
55193 +
55194 + sin.sin_addr.s_addr = inet->inet_daddr;
55195 + sin.sin_port = inet->inet_dport;
55196 +
55197 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
55198 + }
55199 +}
55200 +
55201 +int
55202 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
55203 +{
55204 + struct sockaddr_in sin;
55205 +
55206 + if (unlikely(skb->len < sizeof (struct udphdr)))
55207 + return 0; // skip this packet
55208 +
55209 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
55210 + sin.sin_port = udp_hdr(skb)->source;
55211 +
55212 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
55213 +}
55214 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
55215 new file mode 100644
55216 index 0000000..25f54ef
55217 --- /dev/null
55218 +++ b/grsecurity/gracl_learn.c
55219 @@ -0,0 +1,207 @@
55220 +#include <linux/kernel.h>
55221 +#include <linux/mm.h>
55222 +#include <linux/sched.h>
55223 +#include <linux/poll.h>
55224 +#include <linux/string.h>
55225 +#include <linux/file.h>
55226 +#include <linux/types.h>
55227 +#include <linux/vmalloc.h>
55228 +#include <linux/grinternal.h>
55229 +
55230 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
55231 + size_t count, loff_t *ppos);
55232 +extern int gr_acl_is_enabled(void);
55233 +
55234 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
55235 +static int gr_learn_attached;
55236 +
55237 +/* use a 512k buffer */
55238 +#define LEARN_BUFFER_SIZE (512 * 1024)
55239 +
55240 +static DEFINE_SPINLOCK(gr_learn_lock);
55241 +static DEFINE_MUTEX(gr_learn_user_mutex);
55242 +
55243 +/* we need to maintain two buffers, so that the kernel context of grlearn
55244 + uses a semaphore around the userspace copying, and the other kernel contexts
55245 + use a spinlock when copying into the buffer, since they cannot sleep
55246 +*/
55247 +static char *learn_buffer;
55248 +static char *learn_buffer_user;
55249 +static int learn_buffer_len;
55250 +static int learn_buffer_user_len;
55251 +
55252 +static ssize_t
55253 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
55254 +{
55255 + DECLARE_WAITQUEUE(wait, current);
55256 + ssize_t retval = 0;
55257 +
55258 + add_wait_queue(&learn_wait, &wait);
55259 + set_current_state(TASK_INTERRUPTIBLE);
55260 + do {
55261 + mutex_lock(&gr_learn_user_mutex);
55262 + spin_lock(&gr_learn_lock);
55263 + if (learn_buffer_len)
55264 + break;
55265 + spin_unlock(&gr_learn_lock);
55266 + mutex_unlock(&gr_learn_user_mutex);
55267 + if (file->f_flags & O_NONBLOCK) {
55268 + retval = -EAGAIN;
55269 + goto out;
55270 + }
55271 + if (signal_pending(current)) {
55272 + retval = -ERESTARTSYS;
55273 + goto out;
55274 + }
55275 +
55276 + schedule();
55277 + } while (1);
55278 +
55279 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
55280 + learn_buffer_user_len = learn_buffer_len;
55281 + retval = learn_buffer_len;
55282 + learn_buffer_len = 0;
55283 +
55284 + spin_unlock(&gr_learn_lock);
55285 +
55286 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
55287 + retval = -EFAULT;
55288 +
55289 + mutex_unlock(&gr_learn_user_mutex);
55290 +out:
55291 + set_current_state(TASK_RUNNING);
55292 + remove_wait_queue(&learn_wait, &wait);
55293 + return retval;
55294 +}
55295 +
55296 +static unsigned int
55297 +poll_learn(struct file * file, poll_table * wait)
55298 +{
55299 + poll_wait(file, &learn_wait, wait);
55300 +
55301 + if (learn_buffer_len)
55302 + return (POLLIN | POLLRDNORM);
55303 +
55304 + return 0;
55305 +}
55306 +
55307 +void
55308 +gr_clear_learn_entries(void)
55309 +{
55310 + char *tmp;
55311 +
55312 + mutex_lock(&gr_learn_user_mutex);
55313 + spin_lock(&gr_learn_lock);
55314 + tmp = learn_buffer;
55315 + learn_buffer = NULL;
55316 + spin_unlock(&gr_learn_lock);
55317 + if (tmp)
55318 + vfree(tmp);
55319 + if (learn_buffer_user != NULL) {
55320 + vfree(learn_buffer_user);
55321 + learn_buffer_user = NULL;
55322 + }
55323 + learn_buffer_len = 0;
55324 + mutex_unlock(&gr_learn_user_mutex);
55325 +
55326 + return;
55327 +}
55328 +
55329 +void
55330 +gr_add_learn_entry(const char *fmt, ...)
55331 +{
55332 + va_list args;
55333 + unsigned int len;
55334 +
55335 + if (!gr_learn_attached)
55336 + return;
55337 +
55338 + spin_lock(&gr_learn_lock);
55339 +
55340 + /* leave a gap at the end so we know when it's "full" but don't have to
55341 + compute the exact length of the string we're trying to append
55342 + */
55343 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
55344 + spin_unlock(&gr_learn_lock);
55345 + wake_up_interruptible(&learn_wait);
55346 + return;
55347 + }
55348 + if (learn_buffer == NULL) {
55349 + spin_unlock(&gr_learn_lock);
55350 + return;
55351 + }
55352 +
55353 + va_start(args, fmt);
55354 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
55355 + va_end(args);
55356 +
55357 + learn_buffer_len += len + 1;
55358 +
55359 + spin_unlock(&gr_learn_lock);
55360 + wake_up_interruptible(&learn_wait);
55361 +
55362 + return;
55363 +}
55364 +
55365 +static int
55366 +open_learn(struct inode *inode, struct file *file)
55367 +{
55368 + if (file->f_mode & FMODE_READ && gr_learn_attached)
55369 + return -EBUSY;
55370 + if (file->f_mode & FMODE_READ) {
55371 + int retval = 0;
55372 + mutex_lock(&gr_learn_user_mutex);
55373 + if (learn_buffer == NULL)
55374 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
55375 + if (learn_buffer_user == NULL)
55376 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
55377 + if (learn_buffer == NULL) {
55378 + retval = -ENOMEM;
55379 + goto out_error;
55380 + }
55381 + if (learn_buffer_user == NULL) {
55382 + retval = -ENOMEM;
55383 + goto out_error;
55384 + }
55385 + learn_buffer_len = 0;
55386 + learn_buffer_user_len = 0;
55387 + gr_learn_attached = 1;
55388 +out_error:
55389 + mutex_unlock(&gr_learn_user_mutex);
55390 + return retval;
55391 + }
55392 + return 0;
55393 +}
55394 +
55395 +static int
55396 +close_learn(struct inode *inode, struct file *file)
55397 +{
55398 + if (file->f_mode & FMODE_READ) {
55399 + char *tmp = NULL;
55400 + mutex_lock(&gr_learn_user_mutex);
55401 + spin_lock(&gr_learn_lock);
55402 + tmp = learn_buffer;
55403 + learn_buffer = NULL;
55404 + spin_unlock(&gr_learn_lock);
55405 + if (tmp)
55406 + vfree(tmp);
55407 + if (learn_buffer_user != NULL) {
55408 + vfree(learn_buffer_user);
55409 + learn_buffer_user = NULL;
55410 + }
55411 + learn_buffer_len = 0;
55412 + learn_buffer_user_len = 0;
55413 + gr_learn_attached = 0;
55414 + mutex_unlock(&gr_learn_user_mutex);
55415 + }
55416 +
55417 + return 0;
55418 +}
55419 +
55420 +const struct file_operations grsec_fops = {
55421 + .read = read_learn,
55422 + .write = write_grsec_handler,
55423 + .open = open_learn,
55424 + .release = close_learn,
55425 + .poll = poll_learn,
55426 +};
55427 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
55428 new file mode 100644
55429 index 0000000..39645c9
55430 --- /dev/null
55431 +++ b/grsecurity/gracl_res.c
55432 @@ -0,0 +1,68 @@
55433 +#include <linux/kernel.h>
55434 +#include <linux/sched.h>
55435 +#include <linux/gracl.h>
55436 +#include <linux/grinternal.h>
55437 +
55438 +static const char *restab_log[] = {
55439 + [RLIMIT_CPU] = "RLIMIT_CPU",
55440 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
55441 + [RLIMIT_DATA] = "RLIMIT_DATA",
55442 + [RLIMIT_STACK] = "RLIMIT_STACK",
55443 + [RLIMIT_CORE] = "RLIMIT_CORE",
55444 + [RLIMIT_RSS] = "RLIMIT_RSS",
55445 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
55446 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
55447 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
55448 + [RLIMIT_AS] = "RLIMIT_AS",
55449 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
55450 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
55451 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
55452 + [RLIMIT_NICE] = "RLIMIT_NICE",
55453 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
55454 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
55455 + [GR_CRASH_RES] = "RLIMIT_CRASH"
55456 +};
55457 +
55458 +void
55459 +gr_log_resource(const struct task_struct *task,
55460 + const int res, const unsigned long wanted, const int gt)
55461 +{
55462 + const struct cred *cred;
55463 + unsigned long rlim;
55464 +
55465 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
55466 + return;
55467 +
55468 + // not yet supported resource
55469 + if (unlikely(!restab_log[res]))
55470 + return;
55471 +
55472 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
55473 + rlim = task_rlimit_max(task, res);
55474 + else
55475 + rlim = task_rlimit(task, res);
55476 +
55477 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
55478 + return;
55479 +
55480 + rcu_read_lock();
55481 + cred = __task_cred(task);
55482 +
55483 + if (res == RLIMIT_NPROC &&
55484 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
55485 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
55486 + goto out_rcu_unlock;
55487 + else if (res == RLIMIT_MEMLOCK &&
55488 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
55489 + goto out_rcu_unlock;
55490 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
55491 + goto out_rcu_unlock;
55492 + rcu_read_unlock();
55493 +
55494 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
55495 +
55496 + return;
55497 +out_rcu_unlock:
55498 + rcu_read_unlock();
55499 + return;
55500 +}
55501 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
55502 new file mode 100644
55503 index 0000000..5556be3
55504 --- /dev/null
55505 +++ b/grsecurity/gracl_segv.c
55506 @@ -0,0 +1,299 @@
55507 +#include <linux/kernel.h>
55508 +#include <linux/mm.h>
55509 +#include <asm/uaccess.h>
55510 +#include <asm/errno.h>
55511 +#include <asm/mman.h>
55512 +#include <net/sock.h>
55513 +#include <linux/file.h>
55514 +#include <linux/fs.h>
55515 +#include <linux/net.h>
55516 +#include <linux/in.h>
55517 +#include <linux/slab.h>
55518 +#include <linux/types.h>
55519 +#include <linux/sched.h>
55520 +#include <linux/timer.h>
55521 +#include <linux/gracl.h>
55522 +#include <linux/grsecurity.h>
55523 +#include <linux/grinternal.h>
55524 +
55525 +static struct crash_uid *uid_set;
55526 +static unsigned short uid_used;
55527 +static DEFINE_SPINLOCK(gr_uid_lock);
55528 +extern rwlock_t gr_inode_lock;
55529 +extern struct acl_subject_label *
55530 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
55531 + struct acl_role_label *role);
55532 +
55533 +#ifdef CONFIG_BTRFS_FS
55534 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
55535 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
55536 +#endif
55537 +
55538 +static inline dev_t __get_dev(const struct dentry *dentry)
55539 +{
55540 +#ifdef CONFIG_BTRFS_FS
55541 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
55542 + return get_btrfs_dev_from_inode(dentry->d_inode);
55543 + else
55544 +#endif
55545 + return dentry->d_inode->i_sb->s_dev;
55546 +}
55547 +
55548 +int
55549 +gr_init_uidset(void)
55550 +{
55551 + uid_set =
55552 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
55553 + uid_used = 0;
55554 +
55555 + return uid_set ? 1 : 0;
55556 +}
55557 +
55558 +void
55559 +gr_free_uidset(void)
55560 +{
55561 + if (uid_set)
55562 + kfree(uid_set);
55563 +
55564 + return;
55565 +}
55566 +
55567 +int
55568 +gr_find_uid(const uid_t uid)
55569 +{
55570 + struct crash_uid *tmp = uid_set;
55571 + uid_t buid;
55572 + int low = 0, high = uid_used - 1, mid;
55573 +
55574 + while (high >= low) {
55575 + mid = (low + high) >> 1;
55576 + buid = tmp[mid].uid;
55577 + if (buid == uid)
55578 + return mid;
55579 + if (buid > uid)
55580 + high = mid - 1;
55581 + if (buid < uid)
55582 + low = mid + 1;
55583 + }
55584 +
55585 + return -1;
55586 +}
55587 +
55588 +static __inline__ void
55589 +gr_insertsort(void)
55590 +{
55591 + unsigned short i, j;
55592 + struct crash_uid index;
55593 +
55594 + for (i = 1; i < uid_used; i++) {
55595 + index = uid_set[i];
55596 + j = i;
55597 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
55598 + uid_set[j] = uid_set[j - 1];
55599 + j--;
55600 + }
55601 + uid_set[j] = index;
55602 + }
55603 +
55604 + return;
55605 +}
55606 +
55607 +static __inline__ void
55608 +gr_insert_uid(const uid_t uid, const unsigned long expires)
55609 +{
55610 + int loc;
55611 +
55612 + if (uid_used == GR_UIDTABLE_MAX)
55613 + return;
55614 +
55615 + loc = gr_find_uid(uid);
55616 +
55617 + if (loc >= 0) {
55618 + uid_set[loc].expires = expires;
55619 + return;
55620 + }
55621 +
55622 + uid_set[uid_used].uid = uid;
55623 + uid_set[uid_used].expires = expires;
55624 + uid_used++;
55625 +
55626 + gr_insertsort();
55627 +
55628 + return;
55629 +}
55630 +
55631 +void
55632 +gr_remove_uid(const unsigned short loc)
55633 +{
55634 + unsigned short i;
55635 +
55636 + for (i = loc + 1; i < uid_used; i++)
55637 + uid_set[i - 1] = uid_set[i];
55638 +
55639 + uid_used--;
55640 +
55641 + return;
55642 +}
55643 +
55644 +int
55645 +gr_check_crash_uid(const uid_t uid)
55646 +{
55647 + int loc;
55648 + int ret = 0;
55649 +
55650 + if (unlikely(!gr_acl_is_enabled()))
55651 + return 0;
55652 +
55653 + spin_lock(&gr_uid_lock);
55654 + loc = gr_find_uid(uid);
55655 +
55656 + if (loc < 0)
55657 + goto out_unlock;
55658 +
55659 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
55660 + gr_remove_uid(loc);
55661 + else
55662 + ret = 1;
55663 +
55664 +out_unlock:
55665 + spin_unlock(&gr_uid_lock);
55666 + return ret;
55667 +}
55668 +
55669 +static __inline__ int
55670 +proc_is_setxid(const struct cred *cred)
55671 +{
55672 + if (cred->uid != cred->euid || cred->uid != cred->suid ||
55673 + cred->uid != cred->fsuid)
55674 + return 1;
55675 + if (cred->gid != cred->egid || cred->gid != cred->sgid ||
55676 + cred->gid != cred->fsgid)
55677 + return 1;
55678 +
55679 + return 0;
55680 +}
55681 +
55682 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
55683 +
55684 +void
55685 +gr_handle_crash(struct task_struct *task, const int sig)
55686 +{
55687 + struct acl_subject_label *curr;
55688 + struct task_struct *tsk, *tsk2;
55689 + const struct cred *cred;
55690 + const struct cred *cred2;
55691 +
55692 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
55693 + return;
55694 +
55695 + if (unlikely(!gr_acl_is_enabled()))
55696 + return;
55697 +
55698 + curr = task->acl;
55699 +
55700 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
55701 + return;
55702 +
55703 + if (time_before_eq(curr->expires, get_seconds())) {
55704 + curr->expires = 0;
55705 + curr->crashes = 0;
55706 + }
55707 +
55708 + curr->crashes++;
55709 +
55710 + if (!curr->expires)
55711 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
55712 +
55713 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
55714 + time_after(curr->expires, get_seconds())) {
55715 + rcu_read_lock();
55716 + cred = __task_cred(task);
55717 + if (cred->uid && proc_is_setxid(cred)) {
55718 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
55719 + spin_lock(&gr_uid_lock);
55720 + gr_insert_uid(cred->uid, curr->expires);
55721 + spin_unlock(&gr_uid_lock);
55722 + curr->expires = 0;
55723 + curr->crashes = 0;
55724 + read_lock(&tasklist_lock);
55725 + do_each_thread(tsk2, tsk) {
55726 + cred2 = __task_cred(tsk);
55727 + if (tsk != task && cred2->uid == cred->uid)
55728 + gr_fake_force_sig(SIGKILL, tsk);
55729 + } while_each_thread(tsk2, tsk);
55730 + read_unlock(&tasklist_lock);
55731 + } else {
55732 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
55733 + read_lock(&tasklist_lock);
55734 + read_lock(&grsec_exec_file_lock);
55735 + do_each_thread(tsk2, tsk) {
55736 + if (likely(tsk != task)) {
55737 + // if this thread has the same subject as the one that triggered
55738 + // RES_CRASH and it's the same binary, kill it
55739 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
55740 + gr_fake_force_sig(SIGKILL, tsk);
55741 + }
55742 + } while_each_thread(tsk2, tsk);
55743 + read_unlock(&grsec_exec_file_lock);
55744 + read_unlock(&tasklist_lock);
55745 + }
55746 + rcu_read_unlock();
55747 + }
55748 +
55749 + return;
55750 +}
55751 +
55752 +int
55753 +gr_check_crash_exec(const struct file *filp)
55754 +{
55755 + struct acl_subject_label *curr;
55756 +
55757 + if (unlikely(!gr_acl_is_enabled()))
55758 + return 0;
55759 +
55760 + read_lock(&gr_inode_lock);
55761 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
55762 + __get_dev(filp->f_path.dentry),
55763 + current->role);
55764 + read_unlock(&gr_inode_lock);
55765 +
55766 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
55767 + (!curr->crashes && !curr->expires))
55768 + return 0;
55769 +
55770 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
55771 + time_after(curr->expires, get_seconds()))
55772 + return 1;
55773 + else if (time_before_eq(curr->expires, get_seconds())) {
55774 + curr->crashes = 0;
55775 + curr->expires = 0;
55776 + }
55777 +
55778 + return 0;
55779 +}
55780 +
55781 +void
55782 +gr_handle_alertkill(struct task_struct *task)
55783 +{
55784 + struct acl_subject_label *curracl;
55785 + __u32 curr_ip;
55786 + struct task_struct *p, *p2;
55787 +
55788 + if (unlikely(!gr_acl_is_enabled()))
55789 + return;
55790 +
55791 + curracl = task->acl;
55792 + curr_ip = task->signal->curr_ip;
55793 +
55794 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
55795 + read_lock(&tasklist_lock);
55796 + do_each_thread(p2, p) {
55797 + if (p->signal->curr_ip == curr_ip)
55798 + gr_fake_force_sig(SIGKILL, p);
55799 + } while_each_thread(p2, p);
55800 + read_unlock(&tasklist_lock);
55801 + } else if (curracl->mode & GR_KILLPROC)
55802 + gr_fake_force_sig(SIGKILL, task);
55803 +
55804 + return;
55805 +}
55806 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
55807 new file mode 100644
55808 index 0000000..9d83a69
55809 --- /dev/null
55810 +++ b/grsecurity/gracl_shm.c
55811 @@ -0,0 +1,40 @@
55812 +#include <linux/kernel.h>
55813 +#include <linux/mm.h>
55814 +#include <linux/sched.h>
55815 +#include <linux/file.h>
55816 +#include <linux/ipc.h>
55817 +#include <linux/gracl.h>
55818 +#include <linux/grsecurity.h>
55819 +#include <linux/grinternal.h>
55820 +
55821 +int
55822 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
55823 + const time_t shm_createtime, const uid_t cuid, const int shmid)
55824 +{
55825 + struct task_struct *task;
55826 +
55827 + if (!gr_acl_is_enabled())
55828 + return 1;
55829 +
55830 + rcu_read_lock();
55831 + read_lock(&tasklist_lock);
55832 +
55833 + task = find_task_by_vpid(shm_cprid);
55834 +
55835 + if (unlikely(!task))
55836 + task = find_task_by_vpid(shm_lapid);
55837 +
55838 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
55839 + (task->pid == shm_lapid)) &&
55840 + (task->acl->mode & GR_PROTSHM) &&
55841 + (task->acl != current->acl))) {
55842 + read_unlock(&tasklist_lock);
55843 + rcu_read_unlock();
55844 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
55845 + return 0;
55846 + }
55847 + read_unlock(&tasklist_lock);
55848 + rcu_read_unlock();
55849 +
55850 + return 1;
55851 +}
55852 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
55853 new file mode 100644
55854 index 0000000..bc0be01
55855 --- /dev/null
55856 +++ b/grsecurity/grsec_chdir.c
55857 @@ -0,0 +1,19 @@
55858 +#include <linux/kernel.h>
55859 +#include <linux/sched.h>
55860 +#include <linux/fs.h>
55861 +#include <linux/file.h>
55862 +#include <linux/grsecurity.h>
55863 +#include <linux/grinternal.h>
55864 +
55865 +void
55866 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
55867 +{
55868 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
55869 + if ((grsec_enable_chdir && grsec_enable_group &&
55870 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
55871 + !grsec_enable_group)) {
55872 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
55873 + }
55874 +#endif
55875 + return;
55876 +}
55877 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
55878 new file mode 100644
55879 index 0000000..9807ee2
55880 --- /dev/null
55881 +++ b/grsecurity/grsec_chroot.c
55882 @@ -0,0 +1,368 @@
55883 +#include <linux/kernel.h>
55884 +#include <linux/module.h>
55885 +#include <linux/sched.h>
55886 +#include <linux/file.h>
55887 +#include <linux/fs.h>
55888 +#include <linux/mount.h>
55889 +#include <linux/types.h>
55890 +#include "../fs/mount.h"
55891 +#include <linux/grsecurity.h>
55892 +#include <linux/grinternal.h>
55893 +
55894 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
55895 +{
55896 +#ifdef CONFIG_GRKERNSEC
55897 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
55898 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
55899 + task->gr_is_chrooted = 1;
55900 + else
55901 + task->gr_is_chrooted = 0;
55902 +
55903 + task->gr_chroot_dentry = path->dentry;
55904 +#endif
55905 + return;
55906 +}
55907 +
55908 +void gr_clear_chroot_entries(struct task_struct *task)
55909 +{
55910 +#ifdef CONFIG_GRKERNSEC
55911 + task->gr_is_chrooted = 0;
55912 + task->gr_chroot_dentry = NULL;
55913 +#endif
55914 + return;
55915 +}
55916 +
55917 +int
55918 +gr_handle_chroot_unix(const pid_t pid)
55919 +{
55920 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
55921 + struct task_struct *p;
55922 +
55923 + if (unlikely(!grsec_enable_chroot_unix))
55924 + return 1;
55925 +
55926 + if (likely(!proc_is_chrooted(current)))
55927 + return 1;
55928 +
55929 + rcu_read_lock();
55930 + read_lock(&tasklist_lock);
55931 + p = find_task_by_vpid_unrestricted(pid);
55932 + if (unlikely(p && !have_same_root(current, p))) {
55933 + read_unlock(&tasklist_lock);
55934 + rcu_read_unlock();
55935 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
55936 + return 0;
55937 + }
55938 + read_unlock(&tasklist_lock);
55939 + rcu_read_unlock();
55940 +#endif
55941 + return 1;
55942 +}
55943 +
55944 +int
55945 +gr_handle_chroot_nice(void)
55946 +{
55947 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
55948 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
55949 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
55950 + return -EPERM;
55951 + }
55952 +#endif
55953 + return 0;
55954 +}
55955 +
55956 +int
55957 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
55958 +{
55959 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
55960 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
55961 + && proc_is_chrooted(current)) {
55962 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
55963 + return -EACCES;
55964 + }
55965 +#endif
55966 + return 0;
55967 +}
55968 +
55969 +int
55970 +gr_handle_chroot_rawio(const struct inode *inode)
55971 +{
55972 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
55973 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
55974 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
55975 + return 1;
55976 +#endif
55977 + return 0;
55978 +}
55979 +
55980 +int
55981 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
55982 +{
55983 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
55984 + struct task_struct *p;
55985 + int ret = 0;
55986 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
55987 + return ret;
55988 +
55989 + read_lock(&tasklist_lock);
55990 + do_each_pid_task(pid, type, p) {
55991 + if (!have_same_root(current, p)) {
55992 + ret = 1;
55993 + goto out;
55994 + }
55995 + } while_each_pid_task(pid, type, p);
55996 +out:
55997 + read_unlock(&tasklist_lock);
55998 + return ret;
55999 +#endif
56000 + return 0;
56001 +}
56002 +
56003 +int
56004 +gr_pid_is_chrooted(struct task_struct *p)
56005 +{
56006 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56007 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
56008 + return 0;
56009 +
56010 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
56011 + !have_same_root(current, p)) {
56012 + return 1;
56013 + }
56014 +#endif
56015 + return 0;
56016 +}
56017 +
56018 +EXPORT_SYMBOL(gr_pid_is_chrooted);
56019 +
56020 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
56021 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
56022 +{
56023 + struct path path, currentroot;
56024 + int ret = 0;
56025 +
56026 + path.dentry = (struct dentry *)u_dentry;
56027 + path.mnt = (struct vfsmount *)u_mnt;
56028 + get_fs_root(current->fs, &currentroot);
56029 + if (path_is_under(&path, &currentroot))
56030 + ret = 1;
56031 + path_put(&currentroot);
56032 +
56033 + return ret;
56034 +}
56035 +#endif
56036 +
56037 +int
56038 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
56039 +{
56040 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
56041 + if (!grsec_enable_chroot_fchdir)
56042 + return 1;
56043 +
56044 + if (!proc_is_chrooted(current))
56045 + return 1;
56046 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
56047 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
56048 + return 0;
56049 + }
56050 +#endif
56051 + return 1;
56052 +}
56053 +
56054 +int
56055 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56056 + const time_t shm_createtime)
56057 +{
56058 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
56059 + struct task_struct *p;
56060 + time_t starttime;
56061 +
56062 + if (unlikely(!grsec_enable_chroot_shmat))
56063 + return 1;
56064 +
56065 + if (likely(!proc_is_chrooted(current)))
56066 + return 1;
56067 +
56068 + rcu_read_lock();
56069 + read_lock(&tasklist_lock);
56070 +
56071 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
56072 + starttime = p->start_time.tv_sec;
56073 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
56074 + if (have_same_root(current, p)) {
56075 + goto allow;
56076 + } else {
56077 + read_unlock(&tasklist_lock);
56078 + rcu_read_unlock();
56079 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56080 + return 0;
56081 + }
56082 + }
56083 + /* creator exited, pid reuse, fall through to next check */
56084 + }
56085 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
56086 + if (unlikely(!have_same_root(current, p))) {
56087 + read_unlock(&tasklist_lock);
56088 + rcu_read_unlock();
56089 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56090 + return 0;
56091 + }
56092 + }
56093 +
56094 +allow:
56095 + read_unlock(&tasklist_lock);
56096 + rcu_read_unlock();
56097 +#endif
56098 + return 1;
56099 +}
56100 +
56101 +void
56102 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
56103 +{
56104 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
56105 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
56106 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
56107 +#endif
56108 + return;
56109 +}
56110 +
56111 +int
56112 +gr_handle_chroot_mknod(const struct dentry *dentry,
56113 + const struct vfsmount *mnt, const int mode)
56114 +{
56115 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
56116 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
56117 + proc_is_chrooted(current)) {
56118 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
56119 + return -EPERM;
56120 + }
56121 +#endif
56122 + return 0;
56123 +}
56124 +
56125 +int
56126 +gr_handle_chroot_mount(const struct dentry *dentry,
56127 + const struct vfsmount *mnt, const char *dev_name)
56128 +{
56129 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
56130 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
56131 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
56132 + return -EPERM;
56133 + }
56134 +#endif
56135 + return 0;
56136 +}
56137 +
56138 +int
56139 +gr_handle_chroot_pivot(void)
56140 +{
56141 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
56142 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
56143 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
56144 + return -EPERM;
56145 + }
56146 +#endif
56147 + return 0;
56148 +}
56149 +
56150 +int
56151 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
56152 +{
56153 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
56154 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
56155 + !gr_is_outside_chroot(dentry, mnt)) {
56156 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
56157 + return -EPERM;
56158 + }
56159 +#endif
56160 + return 0;
56161 +}
56162 +
56163 +extern const char *captab_log[];
56164 +extern int captab_log_entries;
56165 +
56166 +int
56167 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
56168 +{
56169 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56170 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
56171 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
56172 + if (cap_raised(chroot_caps, cap)) {
56173 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
56174 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
56175 + }
56176 + return 0;
56177 + }
56178 + }
56179 +#endif
56180 + return 1;
56181 +}
56182 +
56183 +int
56184 +gr_chroot_is_capable(const int cap)
56185 +{
56186 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56187 + return gr_task_chroot_is_capable(current, current_cred(), cap);
56188 +#endif
56189 + return 1;
56190 +}
56191 +
56192 +int
56193 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
56194 +{
56195 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56196 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
56197 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
56198 + if (cap_raised(chroot_caps, cap)) {
56199 + return 0;
56200 + }
56201 + }
56202 +#endif
56203 + return 1;
56204 +}
56205 +
56206 +int
56207 +gr_chroot_is_capable_nolog(const int cap)
56208 +{
56209 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56210 + return gr_task_chroot_is_capable_nolog(current, cap);
56211 +#endif
56212 + return 1;
56213 +}
56214 +
56215 +int
56216 +gr_handle_chroot_sysctl(const int op)
56217 +{
56218 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
56219 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
56220 + proc_is_chrooted(current))
56221 + return -EACCES;
56222 +#endif
56223 + return 0;
56224 +}
56225 +
56226 +void
56227 +gr_handle_chroot_chdir(struct path *path)
56228 +{
56229 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
56230 + if (grsec_enable_chroot_chdir)
56231 + set_fs_pwd(current->fs, path);
56232 +#endif
56233 + return;
56234 +}
56235 +
56236 +int
56237 +gr_handle_chroot_chmod(const struct dentry *dentry,
56238 + const struct vfsmount *mnt, const int mode)
56239 +{
56240 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
56241 + /* allow chmod +s on directories, but not files */
56242 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
56243 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
56244 + proc_is_chrooted(current)) {
56245 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
56246 + return -EPERM;
56247 + }
56248 +#endif
56249 + return 0;
56250 +}
56251 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
56252 new file mode 100644
56253 index 0000000..213ad8b
56254 --- /dev/null
56255 +++ b/grsecurity/grsec_disabled.c
56256 @@ -0,0 +1,437 @@
56257 +#include <linux/kernel.h>
56258 +#include <linux/module.h>
56259 +#include <linux/sched.h>
56260 +#include <linux/file.h>
56261 +#include <linux/fs.h>
56262 +#include <linux/kdev_t.h>
56263 +#include <linux/net.h>
56264 +#include <linux/in.h>
56265 +#include <linux/ip.h>
56266 +#include <linux/skbuff.h>
56267 +#include <linux/sysctl.h>
56268 +
56269 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56270 +void
56271 +pax_set_initial_flags(struct linux_binprm *bprm)
56272 +{
56273 + return;
56274 +}
56275 +#endif
56276 +
56277 +#ifdef CONFIG_SYSCTL
56278 +__u32
56279 +gr_handle_sysctl(const struct ctl_table * table, const int op)
56280 +{
56281 + return 0;
56282 +}
56283 +#endif
56284 +
56285 +#ifdef CONFIG_TASKSTATS
56286 +int gr_is_taskstats_denied(int pid)
56287 +{
56288 + return 0;
56289 +}
56290 +#endif
56291 +
56292 +int
56293 +gr_acl_is_enabled(void)
56294 +{
56295 + return 0;
56296 +}
56297 +
56298 +void
56299 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
56300 +{
56301 + return;
56302 +}
56303 +
56304 +int
56305 +gr_handle_rawio(const struct inode *inode)
56306 +{
56307 + return 0;
56308 +}
56309 +
56310 +void
56311 +gr_acl_handle_psacct(struct task_struct *task, const long code)
56312 +{
56313 + return;
56314 +}
56315 +
56316 +int
56317 +gr_handle_ptrace(struct task_struct *task, const long request)
56318 +{
56319 + return 0;
56320 +}
56321 +
56322 +int
56323 +gr_handle_proc_ptrace(struct task_struct *task)
56324 +{
56325 + return 0;
56326 +}
56327 +
56328 +void
56329 +gr_learn_resource(const struct task_struct *task,
56330 + const int res, const unsigned long wanted, const int gt)
56331 +{
56332 + return;
56333 +}
56334 +
56335 +int
56336 +gr_set_acls(const int type)
56337 +{
56338 + return 0;
56339 +}
56340 +
56341 +int
56342 +gr_check_hidden_task(const struct task_struct *tsk)
56343 +{
56344 + return 0;
56345 +}
56346 +
56347 +int
56348 +gr_check_protected_task(const struct task_struct *task)
56349 +{
56350 + return 0;
56351 +}
56352 +
56353 +int
56354 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
56355 +{
56356 + return 0;
56357 +}
56358 +
56359 +void
56360 +gr_copy_label(struct task_struct *tsk)
56361 +{
56362 + return;
56363 +}
56364 +
56365 +void
56366 +gr_set_pax_flags(struct task_struct *task)
56367 +{
56368 + return;
56369 +}
56370 +
56371 +int
56372 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
56373 + const int unsafe_share)
56374 +{
56375 + return 0;
56376 +}
56377 +
56378 +void
56379 +gr_handle_delete(const ino_t ino, const dev_t dev)
56380 +{
56381 + return;
56382 +}
56383 +
56384 +void
56385 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
56386 +{
56387 + return;
56388 +}
56389 +
56390 +void
56391 +gr_handle_crash(struct task_struct *task, const int sig)
56392 +{
56393 + return;
56394 +}
56395 +
56396 +int
56397 +gr_check_crash_exec(const struct file *filp)
56398 +{
56399 + return 0;
56400 +}
56401 +
56402 +int
56403 +gr_check_crash_uid(const uid_t uid)
56404 +{
56405 + return 0;
56406 +}
56407 +
56408 +void
56409 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
56410 + struct dentry *old_dentry,
56411 + struct dentry *new_dentry,
56412 + struct vfsmount *mnt, const __u8 replace)
56413 +{
56414 + return;
56415 +}
56416 +
56417 +int
56418 +gr_search_socket(const int family, const int type, const int protocol)
56419 +{
56420 + return 1;
56421 +}
56422 +
56423 +int
56424 +gr_search_connectbind(const int mode, const struct socket *sock,
56425 + const struct sockaddr_in *addr)
56426 +{
56427 + return 0;
56428 +}
56429 +
56430 +void
56431 +gr_handle_alertkill(struct task_struct *task)
56432 +{
56433 + return;
56434 +}
56435 +
56436 +__u32
56437 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
56438 +{
56439 + return 1;
56440 +}
56441 +
56442 +__u32
56443 +gr_acl_handle_hidden_file(const struct dentry * dentry,
56444 + const struct vfsmount * mnt)
56445 +{
56446 + return 1;
56447 +}
56448 +
56449 +__u32
56450 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
56451 + int acc_mode)
56452 +{
56453 + return 1;
56454 +}
56455 +
56456 +__u32
56457 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
56458 +{
56459 + return 1;
56460 +}
56461 +
56462 +__u32
56463 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
56464 +{
56465 + return 1;
56466 +}
56467 +
56468 +int
56469 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
56470 + unsigned int *vm_flags)
56471 +{
56472 + return 1;
56473 +}
56474 +
56475 +__u32
56476 +gr_acl_handle_truncate(const struct dentry * dentry,
56477 + const struct vfsmount * mnt)
56478 +{
56479 + return 1;
56480 +}
56481 +
56482 +__u32
56483 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
56484 +{
56485 + return 1;
56486 +}
56487 +
56488 +__u32
56489 +gr_acl_handle_access(const struct dentry * dentry,
56490 + const struct vfsmount * mnt, const int fmode)
56491 +{
56492 + return 1;
56493 +}
56494 +
56495 +__u32
56496 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
56497 + umode_t *mode)
56498 +{
56499 + return 1;
56500 +}
56501 +
56502 +__u32
56503 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
56504 +{
56505 + return 1;
56506 +}
56507 +
56508 +__u32
56509 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
56510 +{
56511 + return 1;
56512 +}
56513 +
56514 +void
56515 +grsecurity_init(void)
56516 +{
56517 + return;
56518 +}
56519 +
56520 +umode_t gr_acl_umask(void)
56521 +{
56522 + return 0;
56523 +}
56524 +
56525 +__u32
56526 +gr_acl_handle_mknod(const struct dentry * new_dentry,
56527 + const struct dentry * parent_dentry,
56528 + const struct vfsmount * parent_mnt,
56529 + const int mode)
56530 +{
56531 + return 1;
56532 +}
56533 +
56534 +__u32
56535 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
56536 + const struct dentry * parent_dentry,
56537 + const struct vfsmount * parent_mnt)
56538 +{
56539 + return 1;
56540 +}
56541 +
56542 +__u32
56543 +gr_acl_handle_symlink(const struct dentry * new_dentry,
56544 + const struct dentry * parent_dentry,
56545 + const struct vfsmount * parent_mnt, const char *from)
56546 +{
56547 + return 1;
56548 +}
56549 +
56550 +__u32
56551 +gr_acl_handle_link(const struct dentry * new_dentry,
56552 + const struct dentry * parent_dentry,
56553 + const struct vfsmount * parent_mnt,
56554 + const struct dentry * old_dentry,
56555 + const struct vfsmount * old_mnt, const char *to)
56556 +{
56557 + return 1;
56558 +}
56559 +
56560 +int
56561 +gr_acl_handle_rename(const struct dentry *new_dentry,
56562 + const struct dentry *parent_dentry,
56563 + const struct vfsmount *parent_mnt,
56564 + const struct dentry *old_dentry,
56565 + const struct inode *old_parent_inode,
56566 + const struct vfsmount *old_mnt, const char *newname)
56567 +{
56568 + return 0;
56569 +}
56570 +
56571 +int
56572 +gr_acl_handle_filldir(const struct file *file, const char *name,
56573 + const int namelen, const ino_t ino)
56574 +{
56575 + return 1;
56576 +}
56577 +
56578 +int
56579 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56580 + const time_t shm_createtime, const uid_t cuid, const int shmid)
56581 +{
56582 + return 1;
56583 +}
56584 +
56585 +int
56586 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
56587 +{
56588 + return 0;
56589 +}
56590 +
56591 +int
56592 +gr_search_accept(const struct socket *sock)
56593 +{
56594 + return 0;
56595 +}
56596 +
56597 +int
56598 +gr_search_listen(const struct socket *sock)
56599 +{
56600 + return 0;
56601 +}
56602 +
56603 +int
56604 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
56605 +{
56606 + return 0;
56607 +}
56608 +
56609 +__u32
56610 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
56611 +{
56612 + return 1;
56613 +}
56614 +
56615 +__u32
56616 +gr_acl_handle_creat(const struct dentry * dentry,
56617 + const struct dentry * p_dentry,
56618 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
56619 + const int imode)
56620 +{
56621 + return 1;
56622 +}
56623 +
56624 +void
56625 +gr_acl_handle_exit(void)
56626 +{
56627 + return;
56628 +}
56629 +
56630 +int
56631 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
56632 +{
56633 + return 1;
56634 +}
56635 +
56636 +void
56637 +gr_set_role_label(const uid_t uid, const gid_t gid)
56638 +{
56639 + return;
56640 +}
56641 +
56642 +int
56643 +gr_acl_handle_procpidmem(const struct task_struct *task)
56644 +{
56645 + return 0;
56646 +}
56647 +
56648 +int
56649 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
56650 +{
56651 + return 0;
56652 +}
56653 +
56654 +int
56655 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
56656 +{
56657 + return 0;
56658 +}
56659 +
56660 +void
56661 +gr_set_kernel_label(struct task_struct *task)
56662 +{
56663 + return;
56664 +}
56665 +
56666 +int
56667 +gr_check_user_change(int real, int effective, int fs)
56668 +{
56669 + return 0;
56670 +}
56671 +
56672 +int
56673 +gr_check_group_change(int real, int effective, int fs)
56674 +{
56675 + return 0;
56676 +}
56677 +
56678 +int gr_acl_enable_at_secure(void)
56679 +{
56680 + return 0;
56681 +}
56682 +
56683 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
56684 +{
56685 + return dentry->d_inode->i_sb->s_dev;
56686 +}
56687 +
56688 +EXPORT_SYMBOL(gr_learn_resource);
56689 +EXPORT_SYMBOL(gr_set_kernel_label);
56690 +#ifdef CONFIG_SECURITY
56691 +EXPORT_SYMBOL(gr_check_user_change);
56692 +EXPORT_SYMBOL(gr_check_group_change);
56693 +#endif
56694 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
56695 new file mode 100644
56696 index 0000000..abfa971
56697 --- /dev/null
56698 +++ b/grsecurity/grsec_exec.c
56699 @@ -0,0 +1,174 @@
56700 +#include <linux/kernel.h>
56701 +#include <linux/sched.h>
56702 +#include <linux/file.h>
56703 +#include <linux/binfmts.h>
56704 +#include <linux/fs.h>
56705 +#include <linux/types.h>
56706 +#include <linux/grdefs.h>
56707 +#include <linux/grsecurity.h>
56708 +#include <linux/grinternal.h>
56709 +#include <linux/capability.h>
56710 +#include <linux/module.h>
56711 +
56712 +#include <asm/uaccess.h>
56713 +
56714 +#ifdef CONFIG_GRKERNSEC_EXECLOG
56715 +static char gr_exec_arg_buf[132];
56716 +static DEFINE_MUTEX(gr_exec_arg_mutex);
56717 +#endif
56718 +
56719 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
56720 +
56721 +void
56722 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
56723 +{
56724 +#ifdef CONFIG_GRKERNSEC_EXECLOG
56725 + char *grarg = gr_exec_arg_buf;
56726 + unsigned int i, x, execlen = 0;
56727 + char c;
56728 +
56729 + if (!((grsec_enable_execlog && grsec_enable_group &&
56730 + in_group_p(grsec_audit_gid))
56731 + || (grsec_enable_execlog && !grsec_enable_group)))
56732 + return;
56733 +
56734 + mutex_lock(&gr_exec_arg_mutex);
56735 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
56736 +
56737 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
56738 + const char __user *p;
56739 + unsigned int len;
56740 +
56741 + p = get_user_arg_ptr(argv, i);
56742 + if (IS_ERR(p))
56743 + goto log;
56744 +
56745 + len = strnlen_user(p, 128 - execlen);
56746 + if (len > 128 - execlen)
56747 + len = 128 - execlen;
56748 + else if (len > 0)
56749 + len--;
56750 + if (copy_from_user(grarg + execlen, p, len))
56751 + goto log;
56752 +
56753 + /* rewrite unprintable characters */
56754 + for (x = 0; x < len; x++) {
56755 + c = *(grarg + execlen + x);
56756 + if (c < 32 || c > 126)
56757 + *(grarg + execlen + x) = ' ';
56758 + }
56759 +
56760 + execlen += len;
56761 + *(grarg + execlen) = ' ';
56762 + *(grarg + execlen + 1) = '\0';
56763 + execlen++;
56764 + }
56765 +
56766 + log:
56767 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
56768 + bprm->file->f_path.mnt, grarg);
56769 + mutex_unlock(&gr_exec_arg_mutex);
56770 +#endif
56771 + return;
56772 +}
56773 +
56774 +#ifdef CONFIG_GRKERNSEC
56775 +extern int gr_acl_is_capable(const int cap);
56776 +extern int gr_acl_is_capable_nolog(const int cap);
56777 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
56778 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
56779 +extern int gr_chroot_is_capable(const int cap);
56780 +extern int gr_chroot_is_capable_nolog(const int cap);
56781 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
56782 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
56783 +#endif
56784 +
56785 +const char *captab_log[] = {
56786 + "CAP_CHOWN",
56787 + "CAP_DAC_OVERRIDE",
56788 + "CAP_DAC_READ_SEARCH",
56789 + "CAP_FOWNER",
56790 + "CAP_FSETID",
56791 + "CAP_KILL",
56792 + "CAP_SETGID",
56793 + "CAP_SETUID",
56794 + "CAP_SETPCAP",
56795 + "CAP_LINUX_IMMUTABLE",
56796 + "CAP_NET_BIND_SERVICE",
56797 + "CAP_NET_BROADCAST",
56798 + "CAP_NET_ADMIN",
56799 + "CAP_NET_RAW",
56800 + "CAP_IPC_LOCK",
56801 + "CAP_IPC_OWNER",
56802 + "CAP_SYS_MODULE",
56803 + "CAP_SYS_RAWIO",
56804 + "CAP_SYS_CHROOT",
56805 + "CAP_SYS_PTRACE",
56806 + "CAP_SYS_PACCT",
56807 + "CAP_SYS_ADMIN",
56808 + "CAP_SYS_BOOT",
56809 + "CAP_SYS_NICE",
56810 + "CAP_SYS_RESOURCE",
56811 + "CAP_SYS_TIME",
56812 + "CAP_SYS_TTY_CONFIG",
56813 + "CAP_MKNOD",
56814 + "CAP_LEASE",
56815 + "CAP_AUDIT_WRITE",
56816 + "CAP_AUDIT_CONTROL",
56817 + "CAP_SETFCAP",
56818 + "CAP_MAC_OVERRIDE",
56819 + "CAP_MAC_ADMIN",
56820 + "CAP_SYSLOG",
56821 + "CAP_WAKE_ALARM"
56822 +};
56823 +
56824 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
56825 +
56826 +int gr_is_capable(const int cap)
56827 +{
56828 +#ifdef CONFIG_GRKERNSEC
56829 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
56830 + return 1;
56831 + return 0;
56832 +#else
56833 + return 1;
56834 +#endif
56835 +}
56836 +
56837 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
56838 +{
56839 +#ifdef CONFIG_GRKERNSEC
56840 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
56841 + return 1;
56842 + return 0;
56843 +#else
56844 + return 1;
56845 +#endif
56846 +}
56847 +
56848 +int gr_is_capable_nolog(const int cap)
56849 +{
56850 +#ifdef CONFIG_GRKERNSEC
56851 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
56852 + return 1;
56853 + return 0;
56854 +#else
56855 + return 1;
56856 +#endif
56857 +}
56858 +
56859 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
56860 +{
56861 +#ifdef CONFIG_GRKERNSEC
56862 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
56863 + return 1;
56864 + return 0;
56865 +#else
56866 + return 1;
56867 +#endif
56868 +}
56869 +
56870 +EXPORT_SYMBOL(gr_is_capable);
56871 +EXPORT_SYMBOL(gr_is_capable_nolog);
56872 +EXPORT_SYMBOL(gr_task_is_capable);
56873 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
56874 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
56875 new file mode 100644
56876 index 0000000..d3ee748
56877 --- /dev/null
56878 +++ b/grsecurity/grsec_fifo.c
56879 @@ -0,0 +1,24 @@
56880 +#include <linux/kernel.h>
56881 +#include <linux/sched.h>
56882 +#include <linux/fs.h>
56883 +#include <linux/file.h>
56884 +#include <linux/grinternal.h>
56885 +
56886 +int
56887 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
56888 + const struct dentry *dir, const int flag, const int acc_mode)
56889 +{
56890 +#ifdef CONFIG_GRKERNSEC_FIFO
56891 + const struct cred *cred = current_cred();
56892 +
56893 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
56894 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
56895 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
56896 + (cred->fsuid != dentry->d_inode->i_uid)) {
56897 + if (!inode_permission(dentry->d_inode, acc_mode))
56898 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
56899 + return -EACCES;
56900 + }
56901 +#endif
56902 + return 0;
56903 +}
56904 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
56905 new file mode 100644
56906 index 0000000..8ca18bf
56907 --- /dev/null
56908 +++ b/grsecurity/grsec_fork.c
56909 @@ -0,0 +1,23 @@
56910 +#include <linux/kernel.h>
56911 +#include <linux/sched.h>
56912 +#include <linux/grsecurity.h>
56913 +#include <linux/grinternal.h>
56914 +#include <linux/errno.h>
56915 +
56916 +void
56917 +gr_log_forkfail(const int retval)
56918 +{
56919 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
56920 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
56921 + switch (retval) {
56922 + case -EAGAIN:
56923 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
56924 + break;
56925 + case -ENOMEM:
56926 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
56927 + break;
56928 + }
56929 + }
56930 +#endif
56931 + return;
56932 +}
56933 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
56934 new file mode 100644
56935 index 0000000..05a6015
56936 --- /dev/null
56937 +++ b/grsecurity/grsec_init.c
56938 @@ -0,0 +1,283 @@
56939 +#include <linux/kernel.h>
56940 +#include <linux/sched.h>
56941 +#include <linux/mm.h>
56942 +#include <linux/gracl.h>
56943 +#include <linux/slab.h>
56944 +#include <linux/vmalloc.h>
56945 +#include <linux/percpu.h>
56946 +#include <linux/module.h>
56947 +
56948 +int grsec_enable_ptrace_readexec;
56949 +int grsec_enable_setxid;
56950 +int grsec_enable_symlinkown;
56951 +int grsec_symlinkown_gid;
56952 +int grsec_enable_brute;
56953 +int grsec_enable_link;
56954 +int grsec_enable_dmesg;
56955 +int grsec_enable_harden_ptrace;
56956 +int grsec_enable_fifo;
56957 +int grsec_enable_execlog;
56958 +int grsec_enable_signal;
56959 +int grsec_enable_forkfail;
56960 +int grsec_enable_audit_ptrace;
56961 +int grsec_enable_time;
56962 +int grsec_enable_audit_textrel;
56963 +int grsec_enable_group;
56964 +int grsec_audit_gid;
56965 +int grsec_enable_chdir;
56966 +int grsec_enable_mount;
56967 +int grsec_enable_rofs;
56968 +int grsec_enable_chroot_findtask;
56969 +int grsec_enable_chroot_mount;
56970 +int grsec_enable_chroot_shmat;
56971 +int grsec_enable_chroot_fchdir;
56972 +int grsec_enable_chroot_double;
56973 +int grsec_enable_chroot_pivot;
56974 +int grsec_enable_chroot_chdir;
56975 +int grsec_enable_chroot_chmod;
56976 +int grsec_enable_chroot_mknod;
56977 +int grsec_enable_chroot_nice;
56978 +int grsec_enable_chroot_execlog;
56979 +int grsec_enable_chroot_caps;
56980 +int grsec_enable_chroot_sysctl;
56981 +int grsec_enable_chroot_unix;
56982 +int grsec_enable_tpe;
56983 +int grsec_tpe_gid;
56984 +int grsec_enable_blackhole;
56985 +#ifdef CONFIG_IPV6_MODULE
56986 +EXPORT_SYMBOL(grsec_enable_blackhole);
56987 +#endif
56988 +int grsec_lastack_retries;
56989 +int grsec_enable_tpe_all;
56990 +int grsec_enable_tpe_invert;
56991 +int grsec_enable_socket_all;
56992 +int grsec_socket_all_gid;
56993 +int grsec_enable_socket_client;
56994 +int grsec_socket_client_gid;
56995 +int grsec_enable_socket_server;
56996 +int grsec_socket_server_gid;
56997 +int grsec_resource_logging;
56998 +int grsec_disable_privio;
56999 +int grsec_enable_log_rwxmaps;
57000 +int grsec_lock;
57001 +
57002 +DEFINE_SPINLOCK(grsec_alert_lock);
57003 +unsigned long grsec_alert_wtime = 0;
57004 +unsigned long grsec_alert_fyet = 0;
57005 +
57006 +DEFINE_SPINLOCK(grsec_audit_lock);
57007 +
57008 +DEFINE_RWLOCK(grsec_exec_file_lock);
57009 +
57010 +char *gr_shared_page[4];
57011 +
57012 +char *gr_alert_log_fmt;
57013 +char *gr_audit_log_fmt;
57014 +char *gr_alert_log_buf;
57015 +char *gr_audit_log_buf;
57016 +
57017 +extern struct gr_arg *gr_usermode;
57018 +extern unsigned char *gr_system_salt;
57019 +extern unsigned char *gr_system_sum;
57020 +
57021 +void __init
57022 +grsecurity_init(void)
57023 +{
57024 + int j;
57025 + /* create the per-cpu shared pages */
57026 +
57027 +#ifdef CONFIG_X86
57028 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
57029 +#endif
57030 +
57031 + for (j = 0; j < 4; j++) {
57032 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
57033 + if (gr_shared_page[j] == NULL) {
57034 + panic("Unable to allocate grsecurity shared page");
57035 + return;
57036 + }
57037 + }
57038 +
57039 + /* allocate log buffers */
57040 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
57041 + if (!gr_alert_log_fmt) {
57042 + panic("Unable to allocate grsecurity alert log format buffer");
57043 + return;
57044 + }
57045 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
57046 + if (!gr_audit_log_fmt) {
57047 + panic("Unable to allocate grsecurity audit log format buffer");
57048 + return;
57049 + }
57050 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57051 + if (!gr_alert_log_buf) {
57052 + panic("Unable to allocate grsecurity alert log buffer");
57053 + return;
57054 + }
57055 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57056 + if (!gr_audit_log_buf) {
57057 + panic("Unable to allocate grsecurity audit log buffer");
57058 + return;
57059 + }
57060 +
57061 + /* allocate memory for authentication structure */
57062 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
57063 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
57064 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
57065 +
57066 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
57067 + panic("Unable to allocate grsecurity authentication structure");
57068 + return;
57069 + }
57070 +
57071 +
57072 +#ifdef CONFIG_GRKERNSEC_IO
57073 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
57074 + grsec_disable_privio = 1;
57075 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57076 + grsec_disable_privio = 1;
57077 +#else
57078 + grsec_disable_privio = 0;
57079 +#endif
57080 +#endif
57081 +
57082 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
57083 + /* for backward compatibility, tpe_invert always defaults to on if
57084 + enabled in the kernel
57085 + */
57086 + grsec_enable_tpe_invert = 1;
57087 +#endif
57088 +
57089 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57090 +#ifndef CONFIG_GRKERNSEC_SYSCTL
57091 + grsec_lock = 1;
57092 +#endif
57093 +
57094 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
57095 + grsec_enable_audit_textrel = 1;
57096 +#endif
57097 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57098 + grsec_enable_log_rwxmaps = 1;
57099 +#endif
57100 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
57101 + grsec_enable_group = 1;
57102 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
57103 +#endif
57104 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
57105 + grsec_enable_ptrace_readexec = 1;
57106 +#endif
57107 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57108 + grsec_enable_chdir = 1;
57109 +#endif
57110 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57111 + grsec_enable_harden_ptrace = 1;
57112 +#endif
57113 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57114 + grsec_enable_mount = 1;
57115 +#endif
57116 +#ifdef CONFIG_GRKERNSEC_LINK
57117 + grsec_enable_link = 1;
57118 +#endif
57119 +#ifdef CONFIG_GRKERNSEC_BRUTE
57120 + grsec_enable_brute = 1;
57121 +#endif
57122 +#ifdef CONFIG_GRKERNSEC_DMESG
57123 + grsec_enable_dmesg = 1;
57124 +#endif
57125 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
57126 + grsec_enable_blackhole = 1;
57127 + grsec_lastack_retries = 4;
57128 +#endif
57129 +#ifdef CONFIG_GRKERNSEC_FIFO
57130 + grsec_enable_fifo = 1;
57131 +#endif
57132 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57133 + grsec_enable_execlog = 1;
57134 +#endif
57135 +#ifdef CONFIG_GRKERNSEC_SETXID
57136 + grsec_enable_setxid = 1;
57137 +#endif
57138 +#ifdef CONFIG_GRKERNSEC_SIGNAL
57139 + grsec_enable_signal = 1;
57140 +#endif
57141 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
57142 + grsec_enable_forkfail = 1;
57143 +#endif
57144 +#ifdef CONFIG_GRKERNSEC_TIME
57145 + grsec_enable_time = 1;
57146 +#endif
57147 +#ifdef CONFIG_GRKERNSEC_RESLOG
57148 + grsec_resource_logging = 1;
57149 +#endif
57150 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57151 + grsec_enable_chroot_findtask = 1;
57152 +#endif
57153 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57154 + grsec_enable_chroot_unix = 1;
57155 +#endif
57156 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57157 + grsec_enable_chroot_mount = 1;
57158 +#endif
57159 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57160 + grsec_enable_chroot_fchdir = 1;
57161 +#endif
57162 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57163 + grsec_enable_chroot_shmat = 1;
57164 +#endif
57165 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
57166 + grsec_enable_audit_ptrace = 1;
57167 +#endif
57168 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57169 + grsec_enable_chroot_double = 1;
57170 +#endif
57171 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57172 + grsec_enable_chroot_pivot = 1;
57173 +#endif
57174 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57175 + grsec_enable_chroot_chdir = 1;
57176 +#endif
57177 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57178 + grsec_enable_chroot_chmod = 1;
57179 +#endif
57180 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57181 + grsec_enable_chroot_mknod = 1;
57182 +#endif
57183 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57184 + grsec_enable_chroot_nice = 1;
57185 +#endif
57186 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57187 + grsec_enable_chroot_execlog = 1;
57188 +#endif
57189 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57190 + grsec_enable_chroot_caps = 1;
57191 +#endif
57192 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57193 + grsec_enable_chroot_sysctl = 1;
57194 +#endif
57195 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
57196 + grsec_enable_symlinkown = 1;
57197 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
57198 +#endif
57199 +#ifdef CONFIG_GRKERNSEC_TPE
57200 + grsec_enable_tpe = 1;
57201 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
57202 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
57203 + grsec_enable_tpe_all = 1;
57204 +#endif
57205 +#endif
57206 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
57207 + grsec_enable_socket_all = 1;
57208 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
57209 +#endif
57210 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
57211 + grsec_enable_socket_client = 1;
57212 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
57213 +#endif
57214 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
57215 + grsec_enable_socket_server = 1;
57216 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
57217 +#endif
57218 +#endif
57219 +
57220 + return;
57221 +}
57222 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
57223 new file mode 100644
57224 index 0000000..35a96d1
57225 --- /dev/null
57226 +++ b/grsecurity/grsec_link.c
57227 @@ -0,0 +1,59 @@
57228 +#include <linux/kernel.h>
57229 +#include <linux/sched.h>
57230 +#include <linux/fs.h>
57231 +#include <linux/file.h>
57232 +#include <linux/grinternal.h>
57233 +
57234 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
57235 +{
57236 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
57237 + const struct inode *link_inode = link->dentry->d_inode;
57238 +
57239 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
57240 + /* ignore root-owned links, e.g. /proc/self */
57241 + link_inode->i_uid &&
57242 + link_inode->i_uid != target->i_uid) {
57243 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
57244 + return 1;
57245 + }
57246 +#endif
57247 + return 0;
57248 +}
57249 +
57250 +int
57251 +gr_handle_follow_link(const struct inode *parent,
57252 + const struct inode *inode,
57253 + const struct dentry *dentry, const struct vfsmount *mnt)
57254 +{
57255 +#ifdef CONFIG_GRKERNSEC_LINK
57256 + const struct cred *cred = current_cred();
57257 +
57258 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
57259 + (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
57260 + (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
57261 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
57262 + return -EACCES;
57263 + }
57264 +#endif
57265 + return 0;
57266 +}
57267 +
57268 +int
57269 +gr_handle_hardlink(const struct dentry *dentry,
57270 + const struct vfsmount *mnt,
57271 + struct inode *inode, const int mode, const char *to)
57272 +{
57273 +#ifdef CONFIG_GRKERNSEC_LINK
57274 + const struct cred *cred = current_cred();
57275 +
57276 + if (grsec_enable_link && cred->fsuid != inode->i_uid &&
57277 + (!S_ISREG(mode) || (mode & S_ISUID) ||
57278 + ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
57279 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
57280 + !capable(CAP_FOWNER) && cred->uid) {
57281 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
57282 + return -EPERM;
57283 + }
57284 +#endif
57285 + return 0;
57286 +}
57287 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
57288 new file mode 100644
57289 index 0000000..a45d2e9
57290 --- /dev/null
57291 +++ b/grsecurity/grsec_log.c
57292 @@ -0,0 +1,322 @@
57293 +#include <linux/kernel.h>
57294 +#include <linux/sched.h>
57295 +#include <linux/file.h>
57296 +#include <linux/tty.h>
57297 +#include <linux/fs.h>
57298 +#include <linux/grinternal.h>
57299 +
57300 +#ifdef CONFIG_TREE_PREEMPT_RCU
57301 +#define DISABLE_PREEMPT() preempt_disable()
57302 +#define ENABLE_PREEMPT() preempt_enable()
57303 +#else
57304 +#define DISABLE_PREEMPT()
57305 +#define ENABLE_PREEMPT()
57306 +#endif
57307 +
57308 +#define BEGIN_LOCKS(x) \
57309 + DISABLE_PREEMPT(); \
57310 + rcu_read_lock(); \
57311 + read_lock(&tasklist_lock); \
57312 + read_lock(&grsec_exec_file_lock); \
57313 + if (x != GR_DO_AUDIT) \
57314 + spin_lock(&grsec_alert_lock); \
57315 + else \
57316 + spin_lock(&grsec_audit_lock)
57317 +
57318 +#define END_LOCKS(x) \
57319 + if (x != GR_DO_AUDIT) \
57320 + spin_unlock(&grsec_alert_lock); \
57321 + else \
57322 + spin_unlock(&grsec_audit_lock); \
57323 + read_unlock(&grsec_exec_file_lock); \
57324 + read_unlock(&tasklist_lock); \
57325 + rcu_read_unlock(); \
57326 + ENABLE_PREEMPT(); \
57327 + if (x == GR_DONT_AUDIT) \
57328 + gr_handle_alertkill(current)
57329 +
57330 +enum {
57331 + FLOODING,
57332 + NO_FLOODING
57333 +};
57334 +
57335 +extern char *gr_alert_log_fmt;
57336 +extern char *gr_audit_log_fmt;
57337 +extern char *gr_alert_log_buf;
57338 +extern char *gr_audit_log_buf;
57339 +
57340 +static int gr_log_start(int audit)
57341 +{
57342 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
57343 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
57344 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57345 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
57346 + unsigned long curr_secs = get_seconds();
57347 +
57348 + if (audit == GR_DO_AUDIT)
57349 + goto set_fmt;
57350 +
57351 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
57352 + grsec_alert_wtime = curr_secs;
57353 + grsec_alert_fyet = 0;
57354 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
57355 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
57356 + grsec_alert_fyet++;
57357 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
57358 + grsec_alert_wtime = curr_secs;
57359 + grsec_alert_fyet++;
57360 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
57361 + return FLOODING;
57362 + }
57363 + else return FLOODING;
57364 +
57365 +set_fmt:
57366 +#endif
57367 + memset(buf, 0, PAGE_SIZE);
57368 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
57369 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
57370 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
57371 + } else if (current->signal->curr_ip) {
57372 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
57373 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
57374 + } else if (gr_acl_is_enabled()) {
57375 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
57376 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
57377 + } else {
57378 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
57379 + strcpy(buf, fmt);
57380 + }
57381 +
57382 + return NO_FLOODING;
57383 +}
57384 +
57385 +static void gr_log_middle(int audit, const char *msg, va_list ap)
57386 + __attribute__ ((format (printf, 2, 0)));
57387 +
57388 +static void gr_log_middle(int audit, const char *msg, va_list ap)
57389 +{
57390 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57391 + unsigned int len = strlen(buf);
57392 +
57393 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
57394 +
57395 + return;
57396 +}
57397 +
57398 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
57399 + __attribute__ ((format (printf, 2, 3)));
57400 +
57401 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
57402 +{
57403 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57404 + unsigned int len = strlen(buf);
57405 + va_list ap;
57406 +
57407 + va_start(ap, msg);
57408 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
57409 + va_end(ap);
57410 +
57411 + return;
57412 +}
57413 +
57414 +static void gr_log_end(int audit, int append_default)
57415 +{
57416 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57417 +
57418 + if (append_default) {
57419 + unsigned int len = strlen(buf);
57420 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
57421 + }
57422 +
57423 + printk("%s\n", buf);
57424 +
57425 + return;
57426 +}
57427 +
57428 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
57429 +{
57430 + int logtype;
57431 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
57432 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
57433 + void *voidptr = NULL;
57434 + int num1 = 0, num2 = 0;
57435 + unsigned long ulong1 = 0, ulong2 = 0;
57436 + struct dentry *dentry = NULL;
57437 + struct vfsmount *mnt = NULL;
57438 + struct file *file = NULL;
57439 + struct task_struct *task = NULL;
57440 + const struct cred *cred, *pcred;
57441 + va_list ap;
57442 +
57443 + BEGIN_LOCKS(audit);
57444 + logtype = gr_log_start(audit);
57445 + if (logtype == FLOODING) {
57446 + END_LOCKS(audit);
57447 + return;
57448 + }
57449 + va_start(ap, argtypes);
57450 + switch (argtypes) {
57451 + case GR_TTYSNIFF:
57452 + task = va_arg(ap, struct task_struct *);
57453 + 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);
57454 + break;
57455 + case GR_SYSCTL_HIDDEN:
57456 + str1 = va_arg(ap, char *);
57457 + gr_log_middle_varargs(audit, msg, result, str1);
57458 + break;
57459 + case GR_RBAC:
57460 + dentry = va_arg(ap, struct dentry *);
57461 + mnt = va_arg(ap, struct vfsmount *);
57462 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
57463 + break;
57464 + case GR_RBAC_STR:
57465 + dentry = va_arg(ap, struct dentry *);
57466 + mnt = va_arg(ap, struct vfsmount *);
57467 + str1 = va_arg(ap, char *);
57468 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
57469 + break;
57470 + case GR_STR_RBAC:
57471 + str1 = va_arg(ap, char *);
57472 + dentry = va_arg(ap, struct dentry *);
57473 + mnt = va_arg(ap, struct vfsmount *);
57474 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
57475 + break;
57476 + case GR_RBAC_MODE2:
57477 + dentry = va_arg(ap, struct dentry *);
57478 + mnt = va_arg(ap, struct vfsmount *);
57479 + str1 = va_arg(ap, char *);
57480 + str2 = va_arg(ap, char *);
57481 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
57482 + break;
57483 + case GR_RBAC_MODE3:
57484 + dentry = va_arg(ap, struct dentry *);
57485 + mnt = va_arg(ap, struct vfsmount *);
57486 + str1 = va_arg(ap, char *);
57487 + str2 = va_arg(ap, char *);
57488 + str3 = va_arg(ap, char *);
57489 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
57490 + break;
57491 + case GR_FILENAME:
57492 + dentry = va_arg(ap, struct dentry *);
57493 + mnt = va_arg(ap, struct vfsmount *);
57494 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
57495 + break;
57496 + case GR_STR_FILENAME:
57497 + str1 = va_arg(ap, char *);
57498 + dentry = va_arg(ap, struct dentry *);
57499 + mnt = va_arg(ap, struct vfsmount *);
57500 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
57501 + break;
57502 + case GR_FILENAME_STR:
57503 + dentry = va_arg(ap, struct dentry *);
57504 + mnt = va_arg(ap, struct vfsmount *);
57505 + str1 = va_arg(ap, char *);
57506 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
57507 + break;
57508 + case GR_FILENAME_TWO_INT:
57509 + dentry = va_arg(ap, struct dentry *);
57510 + mnt = va_arg(ap, struct vfsmount *);
57511 + num1 = va_arg(ap, int);
57512 + num2 = va_arg(ap, int);
57513 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
57514 + break;
57515 + case GR_FILENAME_TWO_INT_STR:
57516 + dentry = va_arg(ap, struct dentry *);
57517 + mnt = va_arg(ap, struct vfsmount *);
57518 + num1 = va_arg(ap, int);
57519 + num2 = va_arg(ap, int);
57520 + str1 = va_arg(ap, char *);
57521 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
57522 + break;
57523 + case GR_TEXTREL:
57524 + file = va_arg(ap, struct file *);
57525 + ulong1 = va_arg(ap, unsigned long);
57526 + ulong2 = va_arg(ap, unsigned long);
57527 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
57528 + break;
57529 + case GR_PTRACE:
57530 + task = va_arg(ap, struct task_struct *);
57531 + 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);
57532 + break;
57533 + case GR_RESOURCE:
57534 + task = va_arg(ap, struct task_struct *);
57535 + cred = __task_cred(task);
57536 + pcred = __task_cred(task->real_parent);
57537 + ulong1 = va_arg(ap, unsigned long);
57538 + str1 = va_arg(ap, char *);
57539 + ulong2 = va_arg(ap, unsigned long);
57540 + 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);
57541 + break;
57542 + case GR_CAP:
57543 + task = va_arg(ap, struct task_struct *);
57544 + cred = __task_cred(task);
57545 + pcred = __task_cred(task->real_parent);
57546 + str1 = va_arg(ap, char *);
57547 + 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);
57548 + break;
57549 + case GR_SIG:
57550 + str1 = va_arg(ap, char *);
57551 + voidptr = va_arg(ap, void *);
57552 + gr_log_middle_varargs(audit, msg, str1, voidptr);
57553 + break;
57554 + case GR_SIG2:
57555 + task = va_arg(ap, struct task_struct *);
57556 + cred = __task_cred(task);
57557 + pcred = __task_cred(task->real_parent);
57558 + num1 = va_arg(ap, int);
57559 + 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);
57560 + break;
57561 + case GR_CRASH1:
57562 + task = va_arg(ap, struct task_struct *);
57563 + cred = __task_cred(task);
57564 + pcred = __task_cred(task->real_parent);
57565 + ulong1 = va_arg(ap, unsigned long);
57566 + 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);
57567 + break;
57568 + case GR_CRASH2:
57569 + task = va_arg(ap, struct task_struct *);
57570 + cred = __task_cred(task);
57571 + pcred = __task_cred(task->real_parent);
57572 + ulong1 = va_arg(ap, unsigned long);
57573 + 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);
57574 + break;
57575 + case GR_RWXMAP:
57576 + file = va_arg(ap, struct file *);
57577 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
57578 + break;
57579 + case GR_PSACCT:
57580 + {
57581 + unsigned int wday, cday;
57582 + __u8 whr, chr;
57583 + __u8 wmin, cmin;
57584 + __u8 wsec, csec;
57585 + char cur_tty[64] = { 0 };
57586 + char parent_tty[64] = { 0 };
57587 +
57588 + task = va_arg(ap, struct task_struct *);
57589 + wday = va_arg(ap, unsigned int);
57590 + cday = va_arg(ap, unsigned int);
57591 + whr = va_arg(ap, int);
57592 + chr = va_arg(ap, int);
57593 + wmin = va_arg(ap, int);
57594 + cmin = va_arg(ap, int);
57595 + wsec = va_arg(ap, int);
57596 + csec = va_arg(ap, int);
57597 + ulong1 = va_arg(ap, unsigned long);
57598 + cred = __task_cred(task);
57599 + pcred = __task_cred(task->real_parent);
57600 +
57601 + 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);
57602 + }
57603 + break;
57604 + default:
57605 + gr_log_middle(audit, msg, ap);
57606 + }
57607 + va_end(ap);
57608 + // these don't need DEFAULTSECARGS printed on the end
57609 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
57610 + gr_log_end(audit, 0);
57611 + else
57612 + gr_log_end(audit, 1);
57613 + END_LOCKS(audit);
57614 +}
57615 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
57616 new file mode 100644
57617 index 0000000..f536303
57618 --- /dev/null
57619 +++ b/grsecurity/grsec_mem.c
57620 @@ -0,0 +1,40 @@
57621 +#include <linux/kernel.h>
57622 +#include <linux/sched.h>
57623 +#include <linux/mm.h>
57624 +#include <linux/mman.h>
57625 +#include <linux/grinternal.h>
57626 +
57627 +void
57628 +gr_handle_ioperm(void)
57629 +{
57630 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
57631 + return;
57632 +}
57633 +
57634 +void
57635 +gr_handle_iopl(void)
57636 +{
57637 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
57638 + return;
57639 +}
57640 +
57641 +void
57642 +gr_handle_mem_readwrite(u64 from, u64 to)
57643 +{
57644 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
57645 + return;
57646 +}
57647 +
57648 +void
57649 +gr_handle_vm86(void)
57650 +{
57651 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
57652 + return;
57653 +}
57654 +
57655 +void
57656 +gr_log_badprocpid(const char *entry)
57657 +{
57658 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
57659 + return;
57660 +}
57661 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
57662 new file mode 100644
57663 index 0000000..2131422
57664 --- /dev/null
57665 +++ b/grsecurity/grsec_mount.c
57666 @@ -0,0 +1,62 @@
57667 +#include <linux/kernel.h>
57668 +#include <linux/sched.h>
57669 +#include <linux/mount.h>
57670 +#include <linux/grsecurity.h>
57671 +#include <linux/grinternal.h>
57672 +
57673 +void
57674 +gr_log_remount(const char *devname, const int retval)
57675 +{
57676 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57677 + if (grsec_enable_mount && (retval >= 0))
57678 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
57679 +#endif
57680 + return;
57681 +}
57682 +
57683 +void
57684 +gr_log_unmount(const char *devname, const int retval)
57685 +{
57686 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57687 + if (grsec_enable_mount && (retval >= 0))
57688 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
57689 +#endif
57690 + return;
57691 +}
57692 +
57693 +void
57694 +gr_log_mount(const char *from, const char *to, const int retval)
57695 +{
57696 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57697 + if (grsec_enable_mount && (retval >= 0))
57698 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
57699 +#endif
57700 + return;
57701 +}
57702 +
57703 +int
57704 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
57705 +{
57706 +#ifdef CONFIG_GRKERNSEC_ROFS
57707 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
57708 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
57709 + return -EPERM;
57710 + } else
57711 + return 0;
57712 +#endif
57713 + return 0;
57714 +}
57715 +
57716 +int
57717 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
57718 +{
57719 +#ifdef CONFIG_GRKERNSEC_ROFS
57720 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
57721 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
57722 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
57723 + return -EPERM;
57724 + } else
57725 + return 0;
57726 +#endif
57727 + return 0;
57728 +}
57729 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
57730 new file mode 100644
57731 index 0000000..a3b12a0
57732 --- /dev/null
57733 +++ b/grsecurity/grsec_pax.c
57734 @@ -0,0 +1,36 @@
57735 +#include <linux/kernel.h>
57736 +#include <linux/sched.h>
57737 +#include <linux/mm.h>
57738 +#include <linux/file.h>
57739 +#include <linux/grinternal.h>
57740 +#include <linux/grsecurity.h>
57741 +
57742 +void
57743 +gr_log_textrel(struct vm_area_struct * vma)
57744 +{
57745 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
57746 + if (grsec_enable_audit_textrel)
57747 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
57748 +#endif
57749 + return;
57750 +}
57751 +
57752 +void
57753 +gr_log_rwxmmap(struct file *file)
57754 +{
57755 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57756 + if (grsec_enable_log_rwxmaps)
57757 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
57758 +#endif
57759 + return;
57760 +}
57761 +
57762 +void
57763 +gr_log_rwxmprotect(struct file *file)
57764 +{
57765 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57766 + if (grsec_enable_log_rwxmaps)
57767 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
57768 +#endif
57769 + return;
57770 +}
57771 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
57772 new file mode 100644
57773 index 0000000..f7f29aa
57774 --- /dev/null
57775 +++ b/grsecurity/grsec_ptrace.c
57776 @@ -0,0 +1,30 @@
57777 +#include <linux/kernel.h>
57778 +#include <linux/sched.h>
57779 +#include <linux/grinternal.h>
57780 +#include <linux/security.h>
57781 +
57782 +void
57783 +gr_audit_ptrace(struct task_struct *task)
57784 +{
57785 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
57786 + if (grsec_enable_audit_ptrace)
57787 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
57788 +#endif
57789 + return;
57790 +}
57791 +
57792 +int
57793 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
57794 +{
57795 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
57796 + const struct dentry *dentry = file->f_path.dentry;
57797 + const struct vfsmount *mnt = file->f_path.mnt;
57798 +
57799 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
57800 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
57801 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
57802 + return -EACCES;
57803 + }
57804 +#endif
57805 + return 0;
57806 +}
57807 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
57808 new file mode 100644
57809 index 0000000..7a5b2de
57810 --- /dev/null
57811 +++ b/grsecurity/grsec_sig.c
57812 @@ -0,0 +1,207 @@
57813 +#include <linux/kernel.h>
57814 +#include <linux/sched.h>
57815 +#include <linux/delay.h>
57816 +#include <linux/grsecurity.h>
57817 +#include <linux/grinternal.h>
57818 +#include <linux/hardirq.h>
57819 +
57820 +char *signames[] = {
57821 + [SIGSEGV] = "Segmentation fault",
57822 + [SIGILL] = "Illegal instruction",
57823 + [SIGABRT] = "Abort",
57824 + [SIGBUS] = "Invalid alignment/Bus error"
57825 +};
57826 +
57827 +void
57828 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
57829 +{
57830 +#ifdef CONFIG_GRKERNSEC_SIGNAL
57831 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
57832 + (sig == SIGABRT) || (sig == SIGBUS))) {
57833 + if (t->pid == current->pid) {
57834 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
57835 + } else {
57836 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
57837 + }
57838 + }
57839 +#endif
57840 + return;
57841 +}
57842 +
57843 +int
57844 +gr_handle_signal(const struct task_struct *p, const int sig)
57845 +{
57846 +#ifdef CONFIG_GRKERNSEC
57847 + /* ignore the 0 signal for protected task checks */
57848 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
57849 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
57850 + return -EPERM;
57851 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
57852 + return -EPERM;
57853 + }
57854 +#endif
57855 + return 0;
57856 +}
57857 +
57858 +#ifdef CONFIG_GRKERNSEC
57859 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
57860 +
57861 +int gr_fake_force_sig(int sig, struct task_struct *t)
57862 +{
57863 + unsigned long int flags;
57864 + int ret, blocked, ignored;
57865 + struct k_sigaction *action;
57866 +
57867 + spin_lock_irqsave(&t->sighand->siglock, flags);
57868 + action = &t->sighand->action[sig-1];
57869 + ignored = action->sa.sa_handler == SIG_IGN;
57870 + blocked = sigismember(&t->blocked, sig);
57871 + if (blocked || ignored) {
57872 + action->sa.sa_handler = SIG_DFL;
57873 + if (blocked) {
57874 + sigdelset(&t->blocked, sig);
57875 + recalc_sigpending_and_wake(t);
57876 + }
57877 + }
57878 + if (action->sa.sa_handler == SIG_DFL)
57879 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
57880 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
57881 +
57882 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
57883 +
57884 + return ret;
57885 +}
57886 +#endif
57887 +
57888 +#ifdef CONFIG_GRKERNSEC_BRUTE
57889 +#define GR_USER_BAN_TIME (15 * 60)
57890 +
57891 +static int __get_dumpable(unsigned long mm_flags)
57892 +{
57893 + int ret;
57894 +
57895 + ret = mm_flags & MMF_DUMPABLE_MASK;
57896 + return (ret >= 2) ? 2 : ret;
57897 +}
57898 +#endif
57899 +
57900 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
57901 +{
57902 +#ifdef CONFIG_GRKERNSEC_BRUTE
57903 + uid_t uid = 0;
57904 +
57905 + if (!grsec_enable_brute)
57906 + return;
57907 +
57908 + rcu_read_lock();
57909 + read_lock(&tasklist_lock);
57910 + read_lock(&grsec_exec_file_lock);
57911 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
57912 + p->real_parent->brute = 1;
57913 + else {
57914 + const struct cred *cred = __task_cred(p), *cred2;
57915 + struct task_struct *tsk, *tsk2;
57916 +
57917 + if (!__get_dumpable(mm_flags) && cred->uid) {
57918 + struct user_struct *user;
57919 +
57920 + uid = cred->uid;
57921 +
57922 + /* this is put upon execution past expiration */
57923 + user = find_user(uid);
57924 + if (user == NULL)
57925 + goto unlock;
57926 + user->banned = 1;
57927 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
57928 + if (user->ban_expires == ~0UL)
57929 + user->ban_expires--;
57930 +
57931 + do_each_thread(tsk2, tsk) {
57932 + cred2 = __task_cred(tsk);
57933 + if (tsk != p && cred2->uid == uid)
57934 + gr_fake_force_sig(SIGKILL, tsk);
57935 + } while_each_thread(tsk2, tsk);
57936 + }
57937 + }
57938 +unlock:
57939 + read_unlock(&grsec_exec_file_lock);
57940 + read_unlock(&tasklist_lock);
57941 + rcu_read_unlock();
57942 +
57943 + if (uid)
57944 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
57945 +
57946 +#endif
57947 + return;
57948 +}
57949 +
57950 +void gr_handle_brute_check(void)
57951 +{
57952 +#ifdef CONFIG_GRKERNSEC_BRUTE
57953 + if (current->brute)
57954 + msleep(30 * 1000);
57955 +#endif
57956 + return;
57957 +}
57958 +
57959 +void gr_handle_kernel_exploit(void)
57960 +{
57961 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
57962 + const struct cred *cred;
57963 + struct task_struct *tsk, *tsk2;
57964 + struct user_struct *user;
57965 + uid_t uid;
57966 +
57967 + if (in_irq() || in_serving_softirq() || in_nmi())
57968 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
57969 +
57970 + uid = current_uid();
57971 +
57972 + if (uid == 0)
57973 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
57974 + else {
57975 + /* kill all the processes of this user, hold a reference
57976 + to their creds struct, and prevent them from creating
57977 + another process until system reset
57978 + */
57979 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
57980 + /* we intentionally leak this ref */
57981 + user = get_uid(current->cred->user);
57982 + if (user) {
57983 + user->banned = 1;
57984 + user->ban_expires = ~0UL;
57985 + }
57986 +
57987 + read_lock(&tasklist_lock);
57988 + do_each_thread(tsk2, tsk) {
57989 + cred = __task_cred(tsk);
57990 + if (cred->uid == uid)
57991 + gr_fake_force_sig(SIGKILL, tsk);
57992 + } while_each_thread(tsk2, tsk);
57993 + read_unlock(&tasklist_lock);
57994 + }
57995 +#endif
57996 +}
57997 +
57998 +int __gr_process_user_ban(struct user_struct *user)
57999 +{
58000 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58001 + if (unlikely(user->banned)) {
58002 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
58003 + user->banned = 0;
58004 + user->ban_expires = 0;
58005 + free_uid(user);
58006 + } else
58007 + return -EPERM;
58008 + }
58009 +#endif
58010 + return 0;
58011 +}
58012 +
58013 +int gr_process_user_ban(void)
58014 +{
58015 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58016 + return __gr_process_user_ban(current->cred->user);
58017 +#endif
58018 + return 0;
58019 +}
58020 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
58021 new file mode 100644
58022 index 0000000..4030d57
58023 --- /dev/null
58024 +++ b/grsecurity/grsec_sock.c
58025 @@ -0,0 +1,244 @@
58026 +#include <linux/kernel.h>
58027 +#include <linux/module.h>
58028 +#include <linux/sched.h>
58029 +#include <linux/file.h>
58030 +#include <linux/net.h>
58031 +#include <linux/in.h>
58032 +#include <linux/ip.h>
58033 +#include <net/sock.h>
58034 +#include <net/inet_sock.h>
58035 +#include <linux/grsecurity.h>
58036 +#include <linux/grinternal.h>
58037 +#include <linux/gracl.h>
58038 +
58039 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
58040 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
58041 +
58042 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
58043 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
58044 +
58045 +#ifdef CONFIG_UNIX_MODULE
58046 +EXPORT_SYMBOL(gr_acl_handle_unix);
58047 +EXPORT_SYMBOL(gr_acl_handle_mknod);
58048 +EXPORT_SYMBOL(gr_handle_chroot_unix);
58049 +EXPORT_SYMBOL(gr_handle_create);
58050 +#endif
58051 +
58052 +#ifdef CONFIG_GRKERNSEC
58053 +#define gr_conn_table_size 32749
58054 +struct conn_table_entry {
58055 + struct conn_table_entry *next;
58056 + struct signal_struct *sig;
58057 +};
58058 +
58059 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
58060 +DEFINE_SPINLOCK(gr_conn_table_lock);
58061 +
58062 +extern const char * gr_socktype_to_name(unsigned char type);
58063 +extern const char * gr_proto_to_name(unsigned char proto);
58064 +extern const char * gr_sockfamily_to_name(unsigned char family);
58065 +
58066 +static __inline__ int
58067 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
58068 +{
58069 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
58070 +}
58071 +
58072 +static __inline__ int
58073 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
58074 + __u16 sport, __u16 dport)
58075 +{
58076 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
58077 + sig->gr_sport == sport && sig->gr_dport == dport))
58078 + return 1;
58079 + else
58080 + return 0;
58081 +}
58082 +
58083 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
58084 +{
58085 + struct conn_table_entry **match;
58086 + unsigned int index;
58087 +
58088 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58089 + sig->gr_sport, sig->gr_dport,
58090 + gr_conn_table_size);
58091 +
58092 + newent->sig = sig;
58093 +
58094 + match = &gr_conn_table[index];
58095 + newent->next = *match;
58096 + *match = newent;
58097 +
58098 + return;
58099 +}
58100 +
58101 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
58102 +{
58103 + struct conn_table_entry *match, *last = NULL;
58104 + unsigned int index;
58105 +
58106 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58107 + sig->gr_sport, sig->gr_dport,
58108 + gr_conn_table_size);
58109 +
58110 + match = gr_conn_table[index];
58111 + while (match && !conn_match(match->sig,
58112 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
58113 + sig->gr_dport)) {
58114 + last = match;
58115 + match = match->next;
58116 + }
58117 +
58118 + if (match) {
58119 + if (last)
58120 + last->next = match->next;
58121 + else
58122 + gr_conn_table[index] = NULL;
58123 + kfree(match);
58124 + }
58125 +
58126 + return;
58127 +}
58128 +
58129 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
58130 + __u16 sport, __u16 dport)
58131 +{
58132 + struct conn_table_entry *match;
58133 + unsigned int index;
58134 +
58135 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
58136 +
58137 + match = gr_conn_table[index];
58138 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
58139 + match = match->next;
58140 +
58141 + if (match)
58142 + return match->sig;
58143 + else
58144 + return NULL;
58145 +}
58146 +
58147 +#endif
58148 +
58149 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
58150 +{
58151 +#ifdef CONFIG_GRKERNSEC
58152 + struct signal_struct *sig = task->signal;
58153 + struct conn_table_entry *newent;
58154 +
58155 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
58156 + if (newent == NULL)
58157 + return;
58158 + /* no bh lock needed since we are called with bh disabled */
58159 + spin_lock(&gr_conn_table_lock);
58160 + gr_del_task_from_ip_table_nolock(sig);
58161 + sig->gr_saddr = inet->inet_rcv_saddr;
58162 + sig->gr_daddr = inet->inet_daddr;
58163 + sig->gr_sport = inet->inet_sport;
58164 + sig->gr_dport = inet->inet_dport;
58165 + gr_add_to_task_ip_table_nolock(sig, newent);
58166 + spin_unlock(&gr_conn_table_lock);
58167 +#endif
58168 + return;
58169 +}
58170 +
58171 +void gr_del_task_from_ip_table(struct task_struct *task)
58172 +{
58173 +#ifdef CONFIG_GRKERNSEC
58174 + spin_lock_bh(&gr_conn_table_lock);
58175 + gr_del_task_from_ip_table_nolock(task->signal);
58176 + spin_unlock_bh(&gr_conn_table_lock);
58177 +#endif
58178 + return;
58179 +}
58180 +
58181 +void
58182 +gr_attach_curr_ip(const struct sock *sk)
58183 +{
58184 +#ifdef CONFIG_GRKERNSEC
58185 + struct signal_struct *p, *set;
58186 + const struct inet_sock *inet = inet_sk(sk);
58187 +
58188 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
58189 + return;
58190 +
58191 + set = current->signal;
58192 +
58193 + spin_lock_bh(&gr_conn_table_lock);
58194 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
58195 + inet->inet_dport, inet->inet_sport);
58196 + if (unlikely(p != NULL)) {
58197 + set->curr_ip = p->curr_ip;
58198 + set->used_accept = 1;
58199 + gr_del_task_from_ip_table_nolock(p);
58200 + spin_unlock_bh(&gr_conn_table_lock);
58201 + return;
58202 + }
58203 + spin_unlock_bh(&gr_conn_table_lock);
58204 +
58205 + set->curr_ip = inet->inet_daddr;
58206 + set->used_accept = 1;
58207 +#endif
58208 + return;
58209 +}
58210 +
58211 +int
58212 +gr_handle_sock_all(const int family, const int type, const int protocol)
58213 +{
58214 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58215 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
58216 + (family != AF_UNIX)) {
58217 + if (family == AF_INET)
58218 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
58219 + else
58220 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
58221 + return -EACCES;
58222 + }
58223 +#endif
58224 + return 0;
58225 +}
58226 +
58227 +int
58228 +gr_handle_sock_server(const struct sockaddr *sck)
58229 +{
58230 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58231 + if (grsec_enable_socket_server &&
58232 + in_group_p(grsec_socket_server_gid) &&
58233 + sck && (sck->sa_family != AF_UNIX) &&
58234 + (sck->sa_family != AF_LOCAL)) {
58235 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
58236 + return -EACCES;
58237 + }
58238 +#endif
58239 + return 0;
58240 +}
58241 +
58242 +int
58243 +gr_handle_sock_server_other(const struct sock *sck)
58244 +{
58245 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58246 + if (grsec_enable_socket_server &&
58247 + in_group_p(grsec_socket_server_gid) &&
58248 + sck && (sck->sk_family != AF_UNIX) &&
58249 + (sck->sk_family != AF_LOCAL)) {
58250 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
58251 + return -EACCES;
58252 + }
58253 +#endif
58254 + return 0;
58255 +}
58256 +
58257 +int
58258 +gr_handle_sock_client(const struct sockaddr *sck)
58259 +{
58260 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58261 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
58262 + sck && (sck->sa_family != AF_UNIX) &&
58263 + (sck->sa_family != AF_LOCAL)) {
58264 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
58265 + return -EACCES;
58266 + }
58267 +#endif
58268 + return 0;
58269 +}
58270 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
58271 new file mode 100644
58272 index 0000000..f55ef0f
58273 --- /dev/null
58274 +++ b/grsecurity/grsec_sysctl.c
58275 @@ -0,0 +1,469 @@
58276 +#include <linux/kernel.h>
58277 +#include <linux/sched.h>
58278 +#include <linux/sysctl.h>
58279 +#include <linux/grsecurity.h>
58280 +#include <linux/grinternal.h>
58281 +
58282 +int
58283 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
58284 +{
58285 +#ifdef CONFIG_GRKERNSEC_SYSCTL
58286 + if (dirname == NULL || name == NULL)
58287 + return 0;
58288 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
58289 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
58290 + return -EACCES;
58291 + }
58292 +#endif
58293 + return 0;
58294 +}
58295 +
58296 +#ifdef CONFIG_GRKERNSEC_ROFS
58297 +static int __maybe_unused one = 1;
58298 +#endif
58299 +
58300 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
58301 +struct ctl_table grsecurity_table[] = {
58302 +#ifdef CONFIG_GRKERNSEC_SYSCTL
58303 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
58304 +#ifdef CONFIG_GRKERNSEC_IO
58305 + {
58306 + .procname = "disable_priv_io",
58307 + .data = &grsec_disable_privio,
58308 + .maxlen = sizeof(int),
58309 + .mode = 0600,
58310 + .proc_handler = &proc_dointvec,
58311 + },
58312 +#endif
58313 +#endif
58314 +#ifdef CONFIG_GRKERNSEC_LINK
58315 + {
58316 + .procname = "linking_restrictions",
58317 + .data = &grsec_enable_link,
58318 + .maxlen = sizeof(int),
58319 + .mode = 0600,
58320 + .proc_handler = &proc_dointvec,
58321 + },
58322 +#endif
58323 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58324 + {
58325 + .procname = "enforce_symlinksifowner",
58326 + .data = &grsec_enable_symlinkown,
58327 + .maxlen = sizeof(int),
58328 + .mode = 0600,
58329 + .proc_handler = &proc_dointvec,
58330 + },
58331 + {
58332 + .procname = "symlinkown_gid",
58333 + .data = &grsec_symlinkown_gid,
58334 + .maxlen = sizeof(int),
58335 + .mode = 0600,
58336 + .proc_handler = &proc_dointvec,
58337 + },
58338 +#endif
58339 +#ifdef CONFIG_GRKERNSEC_BRUTE
58340 + {
58341 + .procname = "deter_bruteforce",
58342 + .data = &grsec_enable_brute,
58343 + .maxlen = sizeof(int),
58344 + .mode = 0600,
58345 + .proc_handler = &proc_dointvec,
58346 + },
58347 +#endif
58348 +#ifdef CONFIG_GRKERNSEC_FIFO
58349 + {
58350 + .procname = "fifo_restrictions",
58351 + .data = &grsec_enable_fifo,
58352 + .maxlen = sizeof(int),
58353 + .mode = 0600,
58354 + .proc_handler = &proc_dointvec,
58355 + },
58356 +#endif
58357 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58358 + {
58359 + .procname = "ptrace_readexec",
58360 + .data = &grsec_enable_ptrace_readexec,
58361 + .maxlen = sizeof(int),
58362 + .mode = 0600,
58363 + .proc_handler = &proc_dointvec,
58364 + },
58365 +#endif
58366 +#ifdef CONFIG_GRKERNSEC_SETXID
58367 + {
58368 + .procname = "consistent_setxid",
58369 + .data = &grsec_enable_setxid,
58370 + .maxlen = sizeof(int),
58371 + .mode = 0600,
58372 + .proc_handler = &proc_dointvec,
58373 + },
58374 +#endif
58375 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58376 + {
58377 + .procname = "ip_blackhole",
58378 + .data = &grsec_enable_blackhole,
58379 + .maxlen = sizeof(int),
58380 + .mode = 0600,
58381 + .proc_handler = &proc_dointvec,
58382 + },
58383 + {
58384 + .procname = "lastack_retries",
58385 + .data = &grsec_lastack_retries,
58386 + .maxlen = sizeof(int),
58387 + .mode = 0600,
58388 + .proc_handler = &proc_dointvec,
58389 + },
58390 +#endif
58391 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58392 + {
58393 + .procname = "exec_logging",
58394 + .data = &grsec_enable_execlog,
58395 + .maxlen = sizeof(int),
58396 + .mode = 0600,
58397 + .proc_handler = &proc_dointvec,
58398 + },
58399 +#endif
58400 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58401 + {
58402 + .procname = "rwxmap_logging",
58403 + .data = &grsec_enable_log_rwxmaps,
58404 + .maxlen = sizeof(int),
58405 + .mode = 0600,
58406 + .proc_handler = &proc_dointvec,
58407 + },
58408 +#endif
58409 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58410 + {
58411 + .procname = "signal_logging",
58412 + .data = &grsec_enable_signal,
58413 + .maxlen = sizeof(int),
58414 + .mode = 0600,
58415 + .proc_handler = &proc_dointvec,
58416 + },
58417 +#endif
58418 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58419 + {
58420 + .procname = "forkfail_logging",
58421 + .data = &grsec_enable_forkfail,
58422 + .maxlen = sizeof(int),
58423 + .mode = 0600,
58424 + .proc_handler = &proc_dointvec,
58425 + },
58426 +#endif
58427 +#ifdef CONFIG_GRKERNSEC_TIME
58428 + {
58429 + .procname = "timechange_logging",
58430 + .data = &grsec_enable_time,
58431 + .maxlen = sizeof(int),
58432 + .mode = 0600,
58433 + .proc_handler = &proc_dointvec,
58434 + },
58435 +#endif
58436 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58437 + {
58438 + .procname = "chroot_deny_shmat",
58439 + .data = &grsec_enable_chroot_shmat,
58440 + .maxlen = sizeof(int),
58441 + .mode = 0600,
58442 + .proc_handler = &proc_dointvec,
58443 + },
58444 +#endif
58445 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58446 + {
58447 + .procname = "chroot_deny_unix",
58448 + .data = &grsec_enable_chroot_unix,
58449 + .maxlen = sizeof(int),
58450 + .mode = 0600,
58451 + .proc_handler = &proc_dointvec,
58452 + },
58453 +#endif
58454 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58455 + {
58456 + .procname = "chroot_deny_mount",
58457 + .data = &grsec_enable_chroot_mount,
58458 + .maxlen = sizeof(int),
58459 + .mode = 0600,
58460 + .proc_handler = &proc_dointvec,
58461 + },
58462 +#endif
58463 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58464 + {
58465 + .procname = "chroot_deny_fchdir",
58466 + .data = &grsec_enable_chroot_fchdir,
58467 + .maxlen = sizeof(int),
58468 + .mode = 0600,
58469 + .proc_handler = &proc_dointvec,
58470 + },
58471 +#endif
58472 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58473 + {
58474 + .procname = "chroot_deny_chroot",
58475 + .data = &grsec_enable_chroot_double,
58476 + .maxlen = sizeof(int),
58477 + .mode = 0600,
58478 + .proc_handler = &proc_dointvec,
58479 + },
58480 +#endif
58481 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58482 + {
58483 + .procname = "chroot_deny_pivot",
58484 + .data = &grsec_enable_chroot_pivot,
58485 + .maxlen = sizeof(int),
58486 + .mode = 0600,
58487 + .proc_handler = &proc_dointvec,
58488 + },
58489 +#endif
58490 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58491 + {
58492 + .procname = "chroot_enforce_chdir",
58493 + .data = &grsec_enable_chroot_chdir,
58494 + .maxlen = sizeof(int),
58495 + .mode = 0600,
58496 + .proc_handler = &proc_dointvec,
58497 + },
58498 +#endif
58499 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58500 + {
58501 + .procname = "chroot_deny_chmod",
58502 + .data = &grsec_enable_chroot_chmod,
58503 + .maxlen = sizeof(int),
58504 + .mode = 0600,
58505 + .proc_handler = &proc_dointvec,
58506 + },
58507 +#endif
58508 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58509 + {
58510 + .procname = "chroot_deny_mknod",
58511 + .data = &grsec_enable_chroot_mknod,
58512 + .maxlen = sizeof(int),
58513 + .mode = 0600,
58514 + .proc_handler = &proc_dointvec,
58515 + },
58516 +#endif
58517 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58518 + {
58519 + .procname = "chroot_restrict_nice",
58520 + .data = &grsec_enable_chroot_nice,
58521 + .maxlen = sizeof(int),
58522 + .mode = 0600,
58523 + .proc_handler = &proc_dointvec,
58524 + },
58525 +#endif
58526 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58527 + {
58528 + .procname = "chroot_execlog",
58529 + .data = &grsec_enable_chroot_execlog,
58530 + .maxlen = sizeof(int),
58531 + .mode = 0600,
58532 + .proc_handler = &proc_dointvec,
58533 + },
58534 +#endif
58535 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58536 + {
58537 + .procname = "chroot_caps",
58538 + .data = &grsec_enable_chroot_caps,
58539 + .maxlen = sizeof(int),
58540 + .mode = 0600,
58541 + .proc_handler = &proc_dointvec,
58542 + },
58543 +#endif
58544 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58545 + {
58546 + .procname = "chroot_deny_sysctl",
58547 + .data = &grsec_enable_chroot_sysctl,
58548 + .maxlen = sizeof(int),
58549 + .mode = 0600,
58550 + .proc_handler = &proc_dointvec,
58551 + },
58552 +#endif
58553 +#ifdef CONFIG_GRKERNSEC_TPE
58554 + {
58555 + .procname = "tpe",
58556 + .data = &grsec_enable_tpe,
58557 + .maxlen = sizeof(int),
58558 + .mode = 0600,
58559 + .proc_handler = &proc_dointvec,
58560 + },
58561 + {
58562 + .procname = "tpe_gid",
58563 + .data = &grsec_tpe_gid,
58564 + .maxlen = sizeof(int),
58565 + .mode = 0600,
58566 + .proc_handler = &proc_dointvec,
58567 + },
58568 +#endif
58569 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58570 + {
58571 + .procname = "tpe_invert",
58572 + .data = &grsec_enable_tpe_invert,
58573 + .maxlen = sizeof(int),
58574 + .mode = 0600,
58575 + .proc_handler = &proc_dointvec,
58576 + },
58577 +#endif
58578 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58579 + {
58580 + .procname = "tpe_restrict_all",
58581 + .data = &grsec_enable_tpe_all,
58582 + .maxlen = sizeof(int),
58583 + .mode = 0600,
58584 + .proc_handler = &proc_dointvec,
58585 + },
58586 +#endif
58587 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58588 + {
58589 + .procname = "socket_all",
58590 + .data = &grsec_enable_socket_all,
58591 + .maxlen = sizeof(int),
58592 + .mode = 0600,
58593 + .proc_handler = &proc_dointvec,
58594 + },
58595 + {
58596 + .procname = "socket_all_gid",
58597 + .data = &grsec_socket_all_gid,
58598 + .maxlen = sizeof(int),
58599 + .mode = 0600,
58600 + .proc_handler = &proc_dointvec,
58601 + },
58602 +#endif
58603 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58604 + {
58605 + .procname = "socket_client",
58606 + .data = &grsec_enable_socket_client,
58607 + .maxlen = sizeof(int),
58608 + .mode = 0600,
58609 + .proc_handler = &proc_dointvec,
58610 + },
58611 + {
58612 + .procname = "socket_client_gid",
58613 + .data = &grsec_socket_client_gid,
58614 + .maxlen = sizeof(int),
58615 + .mode = 0600,
58616 + .proc_handler = &proc_dointvec,
58617 + },
58618 +#endif
58619 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58620 + {
58621 + .procname = "socket_server",
58622 + .data = &grsec_enable_socket_server,
58623 + .maxlen = sizeof(int),
58624 + .mode = 0600,
58625 + .proc_handler = &proc_dointvec,
58626 + },
58627 + {
58628 + .procname = "socket_server_gid",
58629 + .data = &grsec_socket_server_gid,
58630 + .maxlen = sizeof(int),
58631 + .mode = 0600,
58632 + .proc_handler = &proc_dointvec,
58633 + },
58634 +#endif
58635 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58636 + {
58637 + .procname = "audit_group",
58638 + .data = &grsec_enable_group,
58639 + .maxlen = sizeof(int),
58640 + .mode = 0600,
58641 + .proc_handler = &proc_dointvec,
58642 + },
58643 + {
58644 + .procname = "audit_gid",
58645 + .data = &grsec_audit_gid,
58646 + .maxlen = sizeof(int),
58647 + .mode = 0600,
58648 + .proc_handler = &proc_dointvec,
58649 + },
58650 +#endif
58651 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58652 + {
58653 + .procname = "audit_chdir",
58654 + .data = &grsec_enable_chdir,
58655 + .maxlen = sizeof(int),
58656 + .mode = 0600,
58657 + .proc_handler = &proc_dointvec,
58658 + },
58659 +#endif
58660 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58661 + {
58662 + .procname = "audit_mount",
58663 + .data = &grsec_enable_mount,
58664 + .maxlen = sizeof(int),
58665 + .mode = 0600,
58666 + .proc_handler = &proc_dointvec,
58667 + },
58668 +#endif
58669 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58670 + {
58671 + .procname = "audit_textrel",
58672 + .data = &grsec_enable_audit_textrel,
58673 + .maxlen = sizeof(int),
58674 + .mode = 0600,
58675 + .proc_handler = &proc_dointvec,
58676 + },
58677 +#endif
58678 +#ifdef CONFIG_GRKERNSEC_DMESG
58679 + {
58680 + .procname = "dmesg",
58681 + .data = &grsec_enable_dmesg,
58682 + .maxlen = sizeof(int),
58683 + .mode = 0600,
58684 + .proc_handler = &proc_dointvec,
58685 + },
58686 +#endif
58687 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58688 + {
58689 + .procname = "chroot_findtask",
58690 + .data = &grsec_enable_chroot_findtask,
58691 + .maxlen = sizeof(int),
58692 + .mode = 0600,
58693 + .proc_handler = &proc_dointvec,
58694 + },
58695 +#endif
58696 +#ifdef CONFIG_GRKERNSEC_RESLOG
58697 + {
58698 + .procname = "resource_logging",
58699 + .data = &grsec_resource_logging,
58700 + .maxlen = sizeof(int),
58701 + .mode = 0600,
58702 + .proc_handler = &proc_dointvec,
58703 + },
58704 +#endif
58705 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58706 + {
58707 + .procname = "audit_ptrace",
58708 + .data = &grsec_enable_audit_ptrace,
58709 + .maxlen = sizeof(int),
58710 + .mode = 0600,
58711 + .proc_handler = &proc_dointvec,
58712 + },
58713 +#endif
58714 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58715 + {
58716 + .procname = "harden_ptrace",
58717 + .data = &grsec_enable_harden_ptrace,
58718 + .maxlen = sizeof(int),
58719 + .mode = 0600,
58720 + .proc_handler = &proc_dointvec,
58721 + },
58722 +#endif
58723 + {
58724 + .procname = "grsec_lock",
58725 + .data = &grsec_lock,
58726 + .maxlen = sizeof(int),
58727 + .mode = 0600,
58728 + .proc_handler = &proc_dointvec,
58729 + },
58730 +#endif
58731 +#ifdef CONFIG_GRKERNSEC_ROFS
58732 + {
58733 + .procname = "romount_protect",
58734 + .data = &grsec_enable_rofs,
58735 + .maxlen = sizeof(int),
58736 + .mode = 0600,
58737 + .proc_handler = &proc_dointvec_minmax,
58738 + .extra1 = &one,
58739 + .extra2 = &one,
58740 + },
58741 +#endif
58742 + { }
58743 +};
58744 +#endif
58745 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
58746 new file mode 100644
58747 index 0000000..0dc13c3
58748 --- /dev/null
58749 +++ b/grsecurity/grsec_time.c
58750 @@ -0,0 +1,16 @@
58751 +#include <linux/kernel.h>
58752 +#include <linux/sched.h>
58753 +#include <linux/grinternal.h>
58754 +#include <linux/module.h>
58755 +
58756 +void
58757 +gr_log_timechange(void)
58758 +{
58759 +#ifdef CONFIG_GRKERNSEC_TIME
58760 + if (grsec_enable_time)
58761 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
58762 +#endif
58763 + return;
58764 +}
58765 +
58766 +EXPORT_SYMBOL(gr_log_timechange);
58767 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
58768 new file mode 100644
58769 index 0000000..07e0dc0
58770 --- /dev/null
58771 +++ b/grsecurity/grsec_tpe.c
58772 @@ -0,0 +1,73 @@
58773 +#include <linux/kernel.h>
58774 +#include <linux/sched.h>
58775 +#include <linux/file.h>
58776 +#include <linux/fs.h>
58777 +#include <linux/grinternal.h>
58778 +
58779 +extern int gr_acl_tpe_check(void);
58780 +
58781 +int
58782 +gr_tpe_allow(const struct file *file)
58783 +{
58784 +#ifdef CONFIG_GRKERNSEC
58785 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
58786 + const struct cred *cred = current_cred();
58787 + char *msg = NULL;
58788 + char *msg2 = NULL;
58789 +
58790 + // never restrict root
58791 + if (!cred->uid)
58792 + return 1;
58793 +
58794 + if (grsec_enable_tpe) {
58795 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58796 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
58797 + msg = "not being in trusted group";
58798 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
58799 + msg = "being in untrusted group";
58800 +#else
58801 + if (in_group_p(grsec_tpe_gid))
58802 + msg = "being in untrusted group";
58803 +#endif
58804 + }
58805 + if (!msg && gr_acl_tpe_check())
58806 + msg = "being in untrusted role";
58807 +
58808 + // not in any affected group/role
58809 + if (!msg)
58810 + goto next_check;
58811 +
58812 + if (inode->i_uid)
58813 + msg2 = "file in non-root-owned directory";
58814 + else if (inode->i_mode & S_IWOTH)
58815 + msg2 = "file in world-writable directory";
58816 + else if (inode->i_mode & S_IWGRP)
58817 + msg2 = "file in group-writable directory";
58818 +
58819 + if (msg && msg2) {
58820 + char fullmsg[70] = {0};
58821 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
58822 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
58823 + return 0;
58824 + }
58825 + msg = NULL;
58826 +next_check:
58827 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58828 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
58829 + return 1;
58830 +
58831 + if (inode->i_uid && (inode->i_uid != cred->uid))
58832 + msg = "directory not owned by user";
58833 + else if (inode->i_mode & S_IWOTH)
58834 + msg = "file in world-writable directory";
58835 + else if (inode->i_mode & S_IWGRP)
58836 + msg = "file in group-writable directory";
58837 +
58838 + if (msg) {
58839 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
58840 + return 0;
58841 + }
58842 +#endif
58843 +#endif
58844 + return 1;
58845 +}
58846 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
58847 new file mode 100644
58848 index 0000000..9f7b1ac
58849 --- /dev/null
58850 +++ b/grsecurity/grsum.c
58851 @@ -0,0 +1,61 @@
58852 +#include <linux/err.h>
58853 +#include <linux/kernel.h>
58854 +#include <linux/sched.h>
58855 +#include <linux/mm.h>
58856 +#include <linux/scatterlist.h>
58857 +#include <linux/crypto.h>
58858 +#include <linux/gracl.h>
58859 +
58860 +
58861 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
58862 +#error "crypto and sha256 must be built into the kernel"
58863 +#endif
58864 +
58865 +int
58866 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
58867 +{
58868 + char *p;
58869 + struct crypto_hash *tfm;
58870 + struct hash_desc desc;
58871 + struct scatterlist sg;
58872 + unsigned char temp_sum[GR_SHA_LEN];
58873 + volatile int retval = 0;
58874 + volatile int dummy = 0;
58875 + unsigned int i;
58876 +
58877 + sg_init_table(&sg, 1);
58878 +
58879 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
58880 + if (IS_ERR(tfm)) {
58881 + /* should never happen, since sha256 should be built in */
58882 + return 1;
58883 + }
58884 +
58885 + desc.tfm = tfm;
58886 + desc.flags = 0;
58887 +
58888 + crypto_hash_init(&desc);
58889 +
58890 + p = salt;
58891 + sg_set_buf(&sg, p, GR_SALT_LEN);
58892 + crypto_hash_update(&desc, &sg, sg.length);
58893 +
58894 + p = entry->pw;
58895 + sg_set_buf(&sg, p, strlen(p));
58896 +
58897 + crypto_hash_update(&desc, &sg, sg.length);
58898 +
58899 + crypto_hash_final(&desc, temp_sum);
58900 +
58901 + memset(entry->pw, 0, GR_PW_LEN);
58902 +
58903 + for (i = 0; i < GR_SHA_LEN; i++)
58904 + if (sum[i] != temp_sum[i])
58905 + retval = 1;
58906 + else
58907 + dummy = 1; // waste a cycle
58908 +
58909 + crypto_free_hash(tfm);
58910 +
58911 + return retval;
58912 +}
58913 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
58914 index f1c8ca6..b5c1cc7 100644
58915 --- a/include/acpi/acpi_bus.h
58916 +++ b/include/acpi/acpi_bus.h
58917 @@ -107,7 +107,7 @@ struct acpi_device_ops {
58918 acpi_op_bind bind;
58919 acpi_op_unbind unbind;
58920 acpi_op_notify notify;
58921 -};
58922 +} __no_const;
58923
58924 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
58925
58926 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
58927 index b7babf0..71e4e74 100644
58928 --- a/include/asm-generic/atomic-long.h
58929 +++ b/include/asm-generic/atomic-long.h
58930 @@ -22,6 +22,12 @@
58931
58932 typedef atomic64_t atomic_long_t;
58933
58934 +#ifdef CONFIG_PAX_REFCOUNT
58935 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
58936 +#else
58937 +typedef atomic64_t atomic_long_unchecked_t;
58938 +#endif
58939 +
58940 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
58941
58942 static inline long atomic_long_read(atomic_long_t *l)
58943 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
58944 return (long)atomic64_read(v);
58945 }
58946
58947 +#ifdef CONFIG_PAX_REFCOUNT
58948 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
58949 +{
58950 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58951 +
58952 + return (long)atomic64_read_unchecked(v);
58953 +}
58954 +#endif
58955 +
58956 static inline void atomic_long_set(atomic_long_t *l, long i)
58957 {
58958 atomic64_t *v = (atomic64_t *)l;
58959 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
58960 atomic64_set(v, i);
58961 }
58962
58963 +#ifdef CONFIG_PAX_REFCOUNT
58964 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
58965 +{
58966 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58967 +
58968 + atomic64_set_unchecked(v, i);
58969 +}
58970 +#endif
58971 +
58972 static inline void atomic_long_inc(atomic_long_t *l)
58973 {
58974 atomic64_t *v = (atomic64_t *)l;
58975 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
58976 atomic64_inc(v);
58977 }
58978
58979 +#ifdef CONFIG_PAX_REFCOUNT
58980 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
58981 +{
58982 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58983 +
58984 + atomic64_inc_unchecked(v);
58985 +}
58986 +#endif
58987 +
58988 static inline void atomic_long_dec(atomic_long_t *l)
58989 {
58990 atomic64_t *v = (atomic64_t *)l;
58991 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
58992 atomic64_dec(v);
58993 }
58994
58995 +#ifdef CONFIG_PAX_REFCOUNT
58996 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
58997 +{
58998 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
58999 +
59000 + atomic64_dec_unchecked(v);
59001 +}
59002 +#endif
59003 +
59004 static inline void atomic_long_add(long i, atomic_long_t *l)
59005 {
59006 atomic64_t *v = (atomic64_t *)l;
59007 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59008 atomic64_add(i, v);
59009 }
59010
59011 +#ifdef CONFIG_PAX_REFCOUNT
59012 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59013 +{
59014 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59015 +
59016 + atomic64_add_unchecked(i, v);
59017 +}
59018 +#endif
59019 +
59020 static inline void atomic_long_sub(long i, atomic_long_t *l)
59021 {
59022 atomic64_t *v = (atomic64_t *)l;
59023 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59024 atomic64_sub(i, v);
59025 }
59026
59027 +#ifdef CONFIG_PAX_REFCOUNT
59028 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59029 +{
59030 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59031 +
59032 + atomic64_sub_unchecked(i, v);
59033 +}
59034 +#endif
59035 +
59036 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59037 {
59038 atomic64_t *v = (atomic64_t *)l;
59039 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59040 return (long)atomic64_inc_return(v);
59041 }
59042
59043 +#ifdef CONFIG_PAX_REFCOUNT
59044 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59045 +{
59046 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59047 +
59048 + return (long)atomic64_inc_return_unchecked(v);
59049 +}
59050 +#endif
59051 +
59052 static inline long atomic_long_dec_return(atomic_long_t *l)
59053 {
59054 atomic64_t *v = (atomic64_t *)l;
59055 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59056
59057 typedef atomic_t atomic_long_t;
59058
59059 +#ifdef CONFIG_PAX_REFCOUNT
59060 +typedef atomic_unchecked_t atomic_long_unchecked_t;
59061 +#else
59062 +typedef atomic_t atomic_long_unchecked_t;
59063 +#endif
59064 +
59065 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
59066 static inline long atomic_long_read(atomic_long_t *l)
59067 {
59068 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59069 return (long)atomic_read(v);
59070 }
59071
59072 +#ifdef CONFIG_PAX_REFCOUNT
59073 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59074 +{
59075 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59076 +
59077 + return (long)atomic_read_unchecked(v);
59078 +}
59079 +#endif
59080 +
59081 static inline void atomic_long_set(atomic_long_t *l, long i)
59082 {
59083 atomic_t *v = (atomic_t *)l;
59084 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59085 atomic_set(v, i);
59086 }
59087
59088 +#ifdef CONFIG_PAX_REFCOUNT
59089 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59090 +{
59091 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59092 +
59093 + atomic_set_unchecked(v, i);
59094 +}
59095 +#endif
59096 +
59097 static inline void atomic_long_inc(atomic_long_t *l)
59098 {
59099 atomic_t *v = (atomic_t *)l;
59100 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59101 atomic_inc(v);
59102 }
59103
59104 +#ifdef CONFIG_PAX_REFCOUNT
59105 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59106 +{
59107 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59108 +
59109 + atomic_inc_unchecked(v);
59110 +}
59111 +#endif
59112 +
59113 static inline void atomic_long_dec(atomic_long_t *l)
59114 {
59115 atomic_t *v = (atomic_t *)l;
59116 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59117 atomic_dec(v);
59118 }
59119
59120 +#ifdef CONFIG_PAX_REFCOUNT
59121 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59122 +{
59123 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59124 +
59125 + atomic_dec_unchecked(v);
59126 +}
59127 +#endif
59128 +
59129 static inline void atomic_long_add(long i, atomic_long_t *l)
59130 {
59131 atomic_t *v = (atomic_t *)l;
59132 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59133 atomic_add(i, v);
59134 }
59135
59136 +#ifdef CONFIG_PAX_REFCOUNT
59137 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59138 +{
59139 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59140 +
59141 + atomic_add_unchecked(i, v);
59142 +}
59143 +#endif
59144 +
59145 static inline void atomic_long_sub(long i, atomic_long_t *l)
59146 {
59147 atomic_t *v = (atomic_t *)l;
59148 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59149 atomic_sub(i, v);
59150 }
59151
59152 +#ifdef CONFIG_PAX_REFCOUNT
59153 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59154 +{
59155 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59156 +
59157 + atomic_sub_unchecked(i, v);
59158 +}
59159 +#endif
59160 +
59161 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59162 {
59163 atomic_t *v = (atomic_t *)l;
59164 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59165 return (long)atomic_inc_return(v);
59166 }
59167
59168 +#ifdef CONFIG_PAX_REFCOUNT
59169 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59170 +{
59171 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59172 +
59173 + return (long)atomic_inc_return_unchecked(v);
59174 +}
59175 +#endif
59176 +
59177 static inline long atomic_long_dec_return(atomic_long_t *l)
59178 {
59179 atomic_t *v = (atomic_t *)l;
59180 @@ -255,4 +393,49 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59181
59182 #endif /* BITS_PER_LONG == 64 */
59183
59184 +#ifdef CONFIG_PAX_REFCOUNT
59185 +static inline void pax_refcount_needs_these_functions(void)
59186 +{
59187 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
59188 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
59189 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
59190 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
59191 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
59192 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
59193 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
59194 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
59195 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
59196 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
59197 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
59198 +
59199 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
59200 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
59201 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
59202 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
59203 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
59204 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
59205 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
59206 +}
59207 +#else
59208 +#define atomic_read_unchecked(v) atomic_read(v)
59209 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
59210 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
59211 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
59212 +#define atomic_inc_unchecked(v) atomic_inc(v)
59213 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
59214 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
59215 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
59216 +#define atomic_dec_unchecked(v) atomic_dec(v)
59217 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
59218 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
59219 +
59220 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
59221 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
59222 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
59223 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
59224 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
59225 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
59226 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
59227 +#endif
59228 +
59229 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
59230 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
59231 index b18ce4f..2ee2843 100644
59232 --- a/include/asm-generic/atomic64.h
59233 +++ b/include/asm-generic/atomic64.h
59234 @@ -16,6 +16,8 @@ typedef struct {
59235 long long counter;
59236 } atomic64_t;
59237
59238 +typedef atomic64_t atomic64_unchecked_t;
59239 +
59240 #define ATOMIC64_INIT(i) { (i) }
59241
59242 extern long long atomic64_read(const atomic64_t *v);
59243 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
59244 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
59245 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
59246
59247 +#define atomic64_read_unchecked(v) atomic64_read(v)
59248 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
59249 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
59250 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
59251 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
59252 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
59253 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
59254 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
59255 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
59256 +
59257 #endif /* _ASM_GENERIC_ATOMIC64_H */
59258 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
59259 index 1bfcfe5..e04c5c9 100644
59260 --- a/include/asm-generic/cache.h
59261 +++ b/include/asm-generic/cache.h
59262 @@ -6,7 +6,7 @@
59263 * cache lines need to provide their own cache.h.
59264 */
59265
59266 -#define L1_CACHE_SHIFT 5
59267 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
59268 +#define L1_CACHE_SHIFT 5UL
59269 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
59270
59271 #endif /* __ASM_GENERIC_CACHE_H */
59272 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
59273 index 0d68a1e..b74a761 100644
59274 --- a/include/asm-generic/emergency-restart.h
59275 +++ b/include/asm-generic/emergency-restart.h
59276 @@ -1,7 +1,7 @@
59277 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
59278 #define _ASM_GENERIC_EMERGENCY_RESTART_H
59279
59280 -static inline void machine_emergency_restart(void)
59281 +static inline __noreturn void machine_emergency_restart(void)
59282 {
59283 machine_restart(NULL);
59284 }
59285 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
59286 index 0232ccb..13d9165 100644
59287 --- a/include/asm-generic/kmap_types.h
59288 +++ b/include/asm-generic/kmap_types.h
59289 @@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
59290 KMAP_D(17) KM_NMI,
59291 KMAP_D(18) KM_NMI_PTE,
59292 KMAP_D(19) KM_KDB,
59293 +KMAP_D(20) KM_CLEARPAGE,
59294 /*
59295 * Remember to update debug_kmap_atomic() when adding new kmap types!
59296 */
59297 -KMAP_D(20) KM_TYPE_NR
59298 +KMAP_D(21) KM_TYPE_NR
59299 };
59300
59301 #undef KMAP_D
59302 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
59303 index 9ceb03b..2efbcbd 100644
59304 --- a/include/asm-generic/local.h
59305 +++ b/include/asm-generic/local.h
59306 @@ -39,6 +39,7 @@ typedef struct
59307 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
59308 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
59309 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
59310 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
59311
59312 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
59313 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
59314 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
59315 index 725612b..9cc513a 100644
59316 --- a/include/asm-generic/pgtable-nopmd.h
59317 +++ b/include/asm-generic/pgtable-nopmd.h
59318 @@ -1,14 +1,19 @@
59319 #ifndef _PGTABLE_NOPMD_H
59320 #define _PGTABLE_NOPMD_H
59321
59322 -#ifndef __ASSEMBLY__
59323 -
59324 #include <asm-generic/pgtable-nopud.h>
59325
59326 -struct mm_struct;
59327 -
59328 #define __PAGETABLE_PMD_FOLDED
59329
59330 +#define PMD_SHIFT PUD_SHIFT
59331 +#define PTRS_PER_PMD 1
59332 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
59333 +#define PMD_MASK (~(PMD_SIZE-1))
59334 +
59335 +#ifndef __ASSEMBLY__
59336 +
59337 +struct mm_struct;
59338 +
59339 /*
59340 * Having the pmd type consist of a pud gets the size right, and allows
59341 * us to conceptually access the pud entry that this pmd is folded into
59342 @@ -16,11 +21,6 @@ struct mm_struct;
59343 */
59344 typedef struct { pud_t pud; } pmd_t;
59345
59346 -#define PMD_SHIFT PUD_SHIFT
59347 -#define PTRS_PER_PMD 1
59348 -#define PMD_SIZE (1UL << PMD_SHIFT)
59349 -#define PMD_MASK (~(PMD_SIZE-1))
59350 -
59351 /*
59352 * The "pud_xxx()" functions here are trivial for a folded two-level
59353 * setup: the pmd is never bad, and a pmd always exists (as it's folded
59354 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
59355 index 810431d..0ec4804f 100644
59356 --- a/include/asm-generic/pgtable-nopud.h
59357 +++ b/include/asm-generic/pgtable-nopud.h
59358 @@ -1,10 +1,15 @@
59359 #ifndef _PGTABLE_NOPUD_H
59360 #define _PGTABLE_NOPUD_H
59361
59362 -#ifndef __ASSEMBLY__
59363 -
59364 #define __PAGETABLE_PUD_FOLDED
59365
59366 +#define PUD_SHIFT PGDIR_SHIFT
59367 +#define PTRS_PER_PUD 1
59368 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
59369 +#define PUD_MASK (~(PUD_SIZE-1))
59370 +
59371 +#ifndef __ASSEMBLY__
59372 +
59373 /*
59374 * Having the pud type consist of a pgd gets the size right, and allows
59375 * us to conceptually access the pgd entry that this pud is folded into
59376 @@ -12,11 +17,6 @@
59377 */
59378 typedef struct { pgd_t pgd; } pud_t;
59379
59380 -#define PUD_SHIFT PGDIR_SHIFT
59381 -#define PTRS_PER_PUD 1
59382 -#define PUD_SIZE (1UL << PUD_SHIFT)
59383 -#define PUD_MASK (~(PUD_SIZE-1))
59384 -
59385 /*
59386 * The "pgd_xxx()" functions here are trivial for a folded two-level
59387 * setup: the pud is never bad, and a pud always exists (as it's folded
59388 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
59389 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
59390
59391 #define pgd_populate(mm, pgd, pud) do { } while (0)
59392 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
59393 /*
59394 * (puds are folded into pgds so this doesn't get actually called,
59395 * but the define is needed for a generic inline function.)
59396 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
59397 index 125c54e..e95c18e 100644
59398 --- a/include/asm-generic/pgtable.h
59399 +++ b/include/asm-generic/pgtable.h
59400 @@ -446,6 +446,18 @@ static inline int pmd_write(pmd_t pmd)
59401 #endif /* __HAVE_ARCH_PMD_WRITE */
59402 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
59403
59404 +#ifndef __HAVE_ARCH_READ_PMD_ATOMIC
59405 +static inline pmd_t read_pmd_atomic(pmd_t *pmdp)
59406 +{
59407 + /*
59408 + * Depend on compiler for an atomic pmd read. NOTE: this is
59409 + * only going to work, if the pmdval_t isn't larger than
59410 + * an unsigned long.
59411 + */
59412 + return *pmdp;
59413 +}
59414 +#endif /* __HAVE_ARCH_READ_PMD_ATOMIC */
59415 +
59416 /*
59417 * This function is meant to be used by sites walking pagetables with
59418 * the mmap_sem hold in read mode to protect against MADV_DONTNEED and
59419 @@ -459,11 +471,17 @@ static inline int pmd_write(pmd_t pmd)
59420 * undefined so behaving like if the pmd was none is safe (because it
59421 * can return none anyway). The compiler level barrier() is critically
59422 * important to compute the two checks atomically on the same pmdval.
59423 + *
59424 + * For 32bit kernels with a 64bit large pmd_t this automatically takes
59425 + * care of reading the pmd atomically to avoid SMP race conditions
59426 + * against pmd_populate() when the mmap_sem is hold for reading by the
59427 + * caller (a special atomic read not done by "gcc" as in the generic
59428 + * version above, is also needed when THP is disabled because the page
59429 + * fault can populate the pmd from under us).
59430 */
59431 static inline int pmd_none_or_trans_huge_or_clear_bad(pmd_t *pmd)
59432 {
59433 - /* depend on compiler for an atomic pmd read */
59434 - pmd_t pmdval = *pmd;
59435 + pmd_t pmdval = read_pmd_atomic(pmd);
59436 /*
59437 * The barrier will stabilize the pmdval in a register or on
59438 * the stack so that it will stop changing under the code.
59439 @@ -503,6 +521,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
59440 #endif
59441 }
59442
59443 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
59444 +static inline unsigned long pax_open_kernel(void) { return 0; }
59445 +#endif
59446 +
59447 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
59448 +static inline unsigned long pax_close_kernel(void) { return 0; }
59449 +#endif
59450 +
59451 #endif /* CONFIG_MMU */
59452
59453 #endif /* !__ASSEMBLY__ */
59454 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
59455 index 8aeadf6..f1dc019 100644
59456 --- a/include/asm-generic/vmlinux.lds.h
59457 +++ b/include/asm-generic/vmlinux.lds.h
59458 @@ -218,6 +218,7 @@
59459 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
59460 VMLINUX_SYMBOL(__start_rodata) = .; \
59461 *(.rodata) *(.rodata.*) \
59462 + *(.data..read_only) \
59463 *(__vermagic) /* Kernel version magic */ \
59464 . = ALIGN(8); \
59465 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
59466 @@ -716,17 +717,18 @@
59467 * section in the linker script will go there too. @phdr should have
59468 * a leading colon.
59469 *
59470 - * Note that this macros defines __per_cpu_load as an absolute symbol.
59471 + * Note that this macros defines per_cpu_load as an absolute symbol.
59472 * If there is no need to put the percpu section at a predetermined
59473 * address, use PERCPU_SECTION.
59474 */
59475 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
59476 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
59477 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
59478 + per_cpu_load = .; \
59479 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
59480 - LOAD_OFFSET) { \
59481 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
59482 PERCPU_INPUT(cacheline) \
59483 } phdr \
59484 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
59485 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
59486
59487 /**
59488 * PERCPU_SECTION - define output section for percpu area, simple version
59489 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
59490 index dd73104..fde86bd 100644
59491 --- a/include/drm/drmP.h
59492 +++ b/include/drm/drmP.h
59493 @@ -72,6 +72,7 @@
59494 #include <linux/workqueue.h>
59495 #include <linux/poll.h>
59496 #include <asm/pgalloc.h>
59497 +#include <asm/local.h>
59498 #include "drm.h"
59499
59500 #include <linux/idr.h>
59501 @@ -1074,7 +1075,7 @@ struct drm_device {
59502
59503 /** \name Usage Counters */
59504 /*@{ */
59505 - int open_count; /**< Outstanding files open */
59506 + local_t open_count; /**< Outstanding files open */
59507 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
59508 atomic_t vma_count; /**< Outstanding vma areas open */
59509 int buf_use; /**< Buffers in use -- cannot alloc */
59510 @@ -1085,7 +1086,7 @@ struct drm_device {
59511 /*@{ */
59512 unsigned long counters;
59513 enum drm_stat_type types[15];
59514 - atomic_t counts[15];
59515 + atomic_unchecked_t counts[15];
59516 /*@} */
59517
59518 struct list_head filelist;
59519 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
59520 index 37515d1..34fa8b0 100644
59521 --- a/include/drm/drm_crtc_helper.h
59522 +++ b/include/drm/drm_crtc_helper.h
59523 @@ -74,7 +74,7 @@ struct drm_crtc_helper_funcs {
59524
59525 /* disable crtc when not in use - more explicit than dpms off */
59526 void (*disable)(struct drm_crtc *crtc);
59527 -};
59528 +} __no_const;
59529
59530 struct drm_encoder_helper_funcs {
59531 void (*dpms)(struct drm_encoder *encoder, int mode);
59532 @@ -95,7 +95,7 @@ struct drm_encoder_helper_funcs {
59533 struct drm_connector *connector);
59534 /* disable encoder when not in use - more explicit than dpms off */
59535 void (*disable)(struct drm_encoder *encoder);
59536 -};
59537 +} __no_const;
59538
59539 struct drm_connector_helper_funcs {
59540 int (*get_modes)(struct drm_connector *connector);
59541 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
59542 index d6d1da4..fdd1ac5 100644
59543 --- a/include/drm/ttm/ttm_memory.h
59544 +++ b/include/drm/ttm/ttm_memory.h
59545 @@ -48,7 +48,7 @@
59546
59547 struct ttm_mem_shrink {
59548 int (*do_shrink) (struct ttm_mem_shrink *);
59549 -};
59550 +} __no_const;
59551
59552 /**
59553 * struct ttm_mem_global - Global memory accounting structure.
59554 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
59555 index e86dfca..40cc55f 100644
59556 --- a/include/linux/a.out.h
59557 +++ b/include/linux/a.out.h
59558 @@ -39,6 +39,14 @@ enum machine_type {
59559 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
59560 };
59561
59562 +/* Constants for the N_FLAGS field */
59563 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
59564 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
59565 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
59566 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
59567 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
59568 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
59569 +
59570 #if !defined (N_MAGIC)
59571 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
59572 #endif
59573 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
59574 index 06fd4bb..1caec0d 100644
59575 --- a/include/linux/atmdev.h
59576 +++ b/include/linux/atmdev.h
59577 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
59578 #endif
59579
59580 struct k_atm_aal_stats {
59581 -#define __HANDLE_ITEM(i) atomic_t i
59582 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
59583 __AAL_STAT_ITEMS
59584 #undef __HANDLE_ITEM
59585 };
59586 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
59587 index 366422b..1fa7f84 100644
59588 --- a/include/linux/binfmts.h
59589 +++ b/include/linux/binfmts.h
59590 @@ -89,6 +89,7 @@ struct linux_binfmt {
59591 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
59592 int (*load_shlib)(struct file *);
59593 int (*core_dump)(struct coredump_params *cprm);
59594 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
59595 unsigned long min_coredump; /* minimal dump size */
59596 };
59597
59598 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
59599 index 4d4ac24..2c3ccce 100644
59600 --- a/include/linux/blkdev.h
59601 +++ b/include/linux/blkdev.h
59602 @@ -1376,7 +1376,7 @@ struct block_device_operations {
59603 /* this callback is with swap_lock and sometimes page table lock held */
59604 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
59605 struct module *owner;
59606 -};
59607 +} __do_const;
59608
59609 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
59610 unsigned long);
59611 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
59612 index 4d1a074..88f929a 100644
59613 --- a/include/linux/blktrace_api.h
59614 +++ b/include/linux/blktrace_api.h
59615 @@ -162,7 +162,7 @@ struct blk_trace {
59616 struct dentry *dir;
59617 struct dentry *dropped_file;
59618 struct dentry *msg_file;
59619 - atomic_t dropped;
59620 + atomic_unchecked_t dropped;
59621 };
59622
59623 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
59624 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
59625 index 83195fb..0b0f77d 100644
59626 --- a/include/linux/byteorder/little_endian.h
59627 +++ b/include/linux/byteorder/little_endian.h
59628 @@ -42,51 +42,51 @@
59629
59630 static inline __le64 __cpu_to_le64p(const __u64 *p)
59631 {
59632 - return (__force __le64)*p;
59633 + return (__force const __le64)*p;
59634 }
59635 static inline __u64 __le64_to_cpup(const __le64 *p)
59636 {
59637 - return (__force __u64)*p;
59638 + return (__force const __u64)*p;
59639 }
59640 static inline __le32 __cpu_to_le32p(const __u32 *p)
59641 {
59642 - return (__force __le32)*p;
59643 + return (__force const __le32)*p;
59644 }
59645 static inline __u32 __le32_to_cpup(const __le32 *p)
59646 {
59647 - return (__force __u32)*p;
59648 + return (__force const __u32)*p;
59649 }
59650 static inline __le16 __cpu_to_le16p(const __u16 *p)
59651 {
59652 - return (__force __le16)*p;
59653 + return (__force const __le16)*p;
59654 }
59655 static inline __u16 __le16_to_cpup(const __le16 *p)
59656 {
59657 - return (__force __u16)*p;
59658 + return (__force const __u16)*p;
59659 }
59660 static inline __be64 __cpu_to_be64p(const __u64 *p)
59661 {
59662 - return (__force __be64)__swab64p(p);
59663 + return (__force const __be64)__swab64p(p);
59664 }
59665 static inline __u64 __be64_to_cpup(const __be64 *p)
59666 {
59667 - return __swab64p((__u64 *)p);
59668 + return __swab64p((const __u64 *)p);
59669 }
59670 static inline __be32 __cpu_to_be32p(const __u32 *p)
59671 {
59672 - return (__force __be32)__swab32p(p);
59673 + return (__force const __be32)__swab32p(p);
59674 }
59675 static inline __u32 __be32_to_cpup(const __be32 *p)
59676 {
59677 - return __swab32p((__u32 *)p);
59678 + return __swab32p((const __u32 *)p);
59679 }
59680 static inline __be16 __cpu_to_be16p(const __u16 *p)
59681 {
59682 - return (__force __be16)__swab16p(p);
59683 + return (__force const __be16)__swab16p(p);
59684 }
59685 static inline __u16 __be16_to_cpup(const __be16 *p)
59686 {
59687 - return __swab16p((__u16 *)p);
59688 + return __swab16p((const __u16 *)p);
59689 }
59690 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
59691 #define __le64_to_cpus(x) do { (void)(x); } while (0)
59692 diff --git a/include/linux/cache.h b/include/linux/cache.h
59693 index 4c57065..4307975 100644
59694 --- a/include/linux/cache.h
59695 +++ b/include/linux/cache.h
59696 @@ -16,6 +16,10 @@
59697 #define __read_mostly
59698 #endif
59699
59700 +#ifndef __read_only
59701 +#define __read_only __read_mostly
59702 +#endif
59703 +
59704 #ifndef ____cacheline_aligned
59705 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
59706 #endif
59707 diff --git a/include/linux/capability.h b/include/linux/capability.h
59708 index 12d52de..b5f7fa7 100644
59709 --- a/include/linux/capability.h
59710 +++ b/include/linux/capability.h
59711 @@ -548,6 +548,8 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
59712 extern bool capable(int cap);
59713 extern bool ns_capable(struct user_namespace *ns, int cap);
59714 extern bool nsown_capable(int cap);
59715 +extern bool capable_nolog(int cap);
59716 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
59717
59718 /* audit system wants to get cap info from files as well */
59719 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
59720 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
59721 index 42e55de..1cd0e66 100644
59722 --- a/include/linux/cleancache.h
59723 +++ b/include/linux/cleancache.h
59724 @@ -31,7 +31,7 @@ struct cleancache_ops {
59725 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
59726 void (*invalidate_inode)(int, struct cleancache_filekey);
59727 void (*invalidate_fs)(int);
59728 -};
59729 +} __no_const;
59730
59731 extern struct cleancache_ops
59732 cleancache_register_ops(struct cleancache_ops *ops);
59733 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
59734 index 2f40791..a62d196 100644
59735 --- a/include/linux/compiler-gcc4.h
59736 +++ b/include/linux/compiler-gcc4.h
59737 @@ -32,6 +32,16 @@
59738 #define __linktime_error(message) __attribute__((__error__(message)))
59739
59740 #if __GNUC_MINOR__ >= 5
59741 +
59742 +#ifdef CONSTIFY_PLUGIN
59743 +#define __no_const __attribute__((no_const))
59744 +#define __do_const __attribute__((do_const))
59745 +#endif
59746 +
59747 +#ifdef SIZE_OVERFLOW_PLUGIN
59748 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
59749 +#endif
59750 +
59751 /*
59752 * Mark a position in code as unreachable. This can be used to
59753 * suppress control flow warnings after asm blocks that transfer
59754 @@ -47,6 +57,11 @@
59755 #define __noclone __attribute__((__noclone__))
59756
59757 #endif
59758 +
59759 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
59760 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
59761 +#define __bos0(ptr) __bos((ptr), 0)
59762 +#define __bos1(ptr) __bos((ptr), 1)
59763 #endif
59764
59765 #if __GNUC_MINOR__ > 0
59766 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
59767 index 923d093..726c17f 100644
59768 --- a/include/linux/compiler.h
59769 +++ b/include/linux/compiler.h
59770 @@ -5,31 +5,62 @@
59771
59772 #ifdef __CHECKER__
59773 # define __user __attribute__((noderef, address_space(1)))
59774 +# define __force_user __force __user
59775 # define __kernel __attribute__((address_space(0)))
59776 +# define __force_kernel __force __kernel
59777 # define __safe __attribute__((safe))
59778 # define __force __attribute__((force))
59779 # define __nocast __attribute__((nocast))
59780 # define __iomem __attribute__((noderef, address_space(2)))
59781 +# define __force_iomem __force __iomem
59782 # define __acquires(x) __attribute__((context(x,0,1)))
59783 # define __releases(x) __attribute__((context(x,1,0)))
59784 # define __acquire(x) __context__(x,1)
59785 # define __release(x) __context__(x,-1)
59786 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
59787 # define __percpu __attribute__((noderef, address_space(3)))
59788 +# define __force_percpu __force __percpu
59789 #ifdef CONFIG_SPARSE_RCU_POINTER
59790 # define __rcu __attribute__((noderef, address_space(4)))
59791 +# define __force_rcu __force __rcu
59792 #else
59793 # define __rcu
59794 +# define __force_rcu
59795 #endif
59796 extern void __chk_user_ptr(const volatile void __user *);
59797 extern void __chk_io_ptr(const volatile void __iomem *);
59798 +#elif defined(CHECKER_PLUGIN)
59799 +//# define __user
59800 +//# define __force_user
59801 +//# define __kernel
59802 +//# define __force_kernel
59803 +# define __safe
59804 +# define __force
59805 +# define __nocast
59806 +# define __iomem
59807 +# define __force_iomem
59808 +# define __chk_user_ptr(x) (void)0
59809 +# define __chk_io_ptr(x) (void)0
59810 +# define __builtin_warning(x, y...) (1)
59811 +# define __acquires(x)
59812 +# define __releases(x)
59813 +# define __acquire(x) (void)0
59814 +# define __release(x) (void)0
59815 +# define __cond_lock(x,c) (c)
59816 +# define __percpu
59817 +# define __force_percpu
59818 +# define __rcu
59819 +# define __force_rcu
59820 #else
59821 # define __user
59822 +# define __force_user
59823 # define __kernel
59824 +# define __force_kernel
59825 # define __safe
59826 # define __force
59827 # define __nocast
59828 # define __iomem
59829 +# define __force_iomem
59830 # define __chk_user_ptr(x) (void)0
59831 # define __chk_io_ptr(x) (void)0
59832 # define __builtin_warning(x, y...) (1)
59833 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
59834 # define __release(x) (void)0
59835 # define __cond_lock(x,c) (c)
59836 # define __percpu
59837 +# define __force_percpu
59838 # define __rcu
59839 +# define __force_rcu
59840 #endif
59841
59842 #ifdef __KERNEL__
59843 @@ -264,6 +297,18 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
59844 # define __attribute_const__ /* unimplemented */
59845 #endif
59846
59847 +#ifndef __no_const
59848 +# define __no_const
59849 +#endif
59850 +
59851 +#ifndef __do_const
59852 +# define __do_const
59853 +#endif
59854 +
59855 +#ifndef __size_overflow
59856 +# define __size_overflow(...)
59857 +#endif
59858 +
59859 /*
59860 * Tell gcc if a function is cold. The compiler will assume any path
59861 * directly leading to the call is unlikely.
59862 @@ -273,6 +318,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
59863 #define __cold
59864 #endif
59865
59866 +#ifndef __alloc_size
59867 +#define __alloc_size(...)
59868 +#endif
59869 +
59870 +#ifndef __bos
59871 +#define __bos(ptr, arg)
59872 +#endif
59873 +
59874 +#ifndef __bos0
59875 +#define __bos0(ptr)
59876 +#endif
59877 +
59878 +#ifndef __bos1
59879 +#define __bos1(ptr)
59880 +#endif
59881 +
59882 /* Simple shorthand for a section definition */
59883 #ifndef __section
59884 # define __section(S) __attribute__ ((__section__(#S)))
59885 @@ -308,6 +369,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
59886 * use is to mediate communication between process-level code and irq/NMI
59887 * handlers, all running on the same CPU.
59888 */
59889 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
59890 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
59891 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
59892
59893 #endif /* __LINUX_COMPILER_H */
59894 diff --git a/include/linux/cred.h b/include/linux/cred.h
59895 index adadf71..6af5560 100644
59896 --- a/include/linux/cred.h
59897 +++ b/include/linux/cred.h
59898 @@ -207,6 +207,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
59899 static inline void validate_process_creds(void)
59900 {
59901 }
59902 +static inline void validate_task_creds(struct task_struct *task)
59903 +{
59904 +}
59905 #endif
59906
59907 /**
59908 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
59909 index b92eadf..b4ecdc1 100644
59910 --- a/include/linux/crypto.h
59911 +++ b/include/linux/crypto.h
59912 @@ -373,7 +373,7 @@ struct cipher_tfm {
59913 const u8 *key, unsigned int keylen);
59914 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
59915 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
59916 -};
59917 +} __no_const;
59918
59919 struct hash_tfm {
59920 int (*init)(struct hash_desc *desc);
59921 @@ -394,13 +394,13 @@ struct compress_tfm {
59922 int (*cot_decompress)(struct crypto_tfm *tfm,
59923 const u8 *src, unsigned int slen,
59924 u8 *dst, unsigned int *dlen);
59925 -};
59926 +} __no_const;
59927
59928 struct rng_tfm {
59929 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
59930 unsigned int dlen);
59931 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
59932 -};
59933 +} __no_const;
59934
59935 #define crt_ablkcipher crt_u.ablkcipher
59936 #define crt_aead crt_u.aead
59937 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
59938 index 7925bf0..d5143d2 100644
59939 --- a/include/linux/decompress/mm.h
59940 +++ b/include/linux/decompress/mm.h
59941 @@ -77,7 +77,7 @@ static void free(void *where)
59942 * warnings when not needed (indeed large_malloc / large_free are not
59943 * needed by inflate */
59944
59945 -#define malloc(a) kmalloc(a, GFP_KERNEL)
59946 +#define malloc(a) kmalloc((a), GFP_KERNEL)
59947 #define free(a) kfree(a)
59948
59949 #define large_malloc(a) vmalloc(a)
59950 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
59951 index dfc099e..e583e66 100644
59952 --- a/include/linux/dma-mapping.h
59953 +++ b/include/linux/dma-mapping.h
59954 @@ -51,7 +51,7 @@ struct dma_map_ops {
59955 u64 (*get_required_mask)(struct device *dev);
59956 #endif
59957 int is_phys;
59958 -};
59959 +} __do_const;
59960
59961 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
59962
59963 diff --git a/include/linux/efi.h b/include/linux/efi.h
59964 index ec45ccd..9923c32 100644
59965 --- a/include/linux/efi.h
59966 +++ b/include/linux/efi.h
59967 @@ -635,7 +635,7 @@ struct efivar_operations {
59968 efi_get_variable_t *get_variable;
59969 efi_get_next_variable_t *get_next_variable;
59970 efi_set_variable_t *set_variable;
59971 -};
59972 +} __no_const;
59973
59974 struct efivars {
59975 /*
59976 diff --git a/include/linux/elf.h b/include/linux/elf.h
59977 index 999b4f5..57753b4 100644
59978 --- a/include/linux/elf.h
59979 +++ b/include/linux/elf.h
59980 @@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
59981 #define PT_GNU_EH_FRAME 0x6474e550
59982
59983 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
59984 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
59985 +
59986 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
59987 +
59988 +/* Constants for the e_flags field */
59989 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
59990 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
59991 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
59992 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
59993 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
59994 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
59995
59996 /*
59997 * Extended Numbering
59998 @@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
59999 #define DT_DEBUG 21
60000 #define DT_TEXTREL 22
60001 #define DT_JMPREL 23
60002 +#define DT_FLAGS 30
60003 + #define DF_TEXTREL 0x00000004
60004 #define DT_ENCODING 32
60005 #define OLD_DT_LOOS 0x60000000
60006 #define DT_LOOS 0x6000000d
60007 @@ -243,6 +256,19 @@ typedef struct elf64_hdr {
60008 #define PF_W 0x2
60009 #define PF_X 0x1
60010
60011 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
60012 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
60013 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
60014 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
60015 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
60016 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
60017 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
60018 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
60019 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
60020 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
60021 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
60022 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
60023 +
60024 typedef struct elf32_phdr{
60025 Elf32_Word p_type;
60026 Elf32_Off p_offset;
60027 @@ -335,6 +361,8 @@ typedef struct elf64_shdr {
60028 #define EI_OSABI 7
60029 #define EI_PAD 8
60030
60031 +#define EI_PAX 14
60032 +
60033 #define ELFMAG0 0x7f /* EI_MAG */
60034 #define ELFMAG1 'E'
60035 #define ELFMAG2 'L'
60036 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
60037 #define elf_note elf32_note
60038 #define elf_addr_t Elf32_Off
60039 #define Elf_Half Elf32_Half
60040 +#define elf_dyn Elf32_Dyn
60041
60042 #else
60043
60044 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
60045 #define elf_note elf64_note
60046 #define elf_addr_t Elf64_Off
60047 #define Elf_Half Elf64_Half
60048 +#define elf_dyn Elf64_Dyn
60049
60050 #endif
60051
60052 diff --git a/include/linux/filter.h b/include/linux/filter.h
60053 index 8eeb205..d59bfa2 100644
60054 --- a/include/linux/filter.h
60055 +++ b/include/linux/filter.h
60056 @@ -134,6 +134,7 @@ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
60057
60058 struct sk_buff;
60059 struct sock;
60060 +struct bpf_jit_work;
60061
60062 struct sk_filter
60063 {
60064 @@ -141,6 +142,9 @@ struct sk_filter
60065 unsigned int len; /* Number of filter blocks */
60066 unsigned int (*bpf_func)(const struct sk_buff *skb,
60067 const struct sock_filter *filter);
60068 +#ifdef CONFIG_BPF_JIT
60069 + struct bpf_jit_work *work;
60070 +#endif
60071 struct rcu_head rcu;
60072 struct sock_filter insns[0];
60073 };
60074 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
60075 index cdc9b71..ce69fb5 100644
60076 --- a/include/linux/firewire.h
60077 +++ b/include/linux/firewire.h
60078 @@ -413,7 +413,7 @@ struct fw_iso_context {
60079 union {
60080 fw_iso_callback_t sc;
60081 fw_iso_mc_callback_t mc;
60082 - } callback;
60083 + } __no_const callback;
60084 void *callback_data;
60085 };
60086
60087 diff --git a/include/linux/fs.h b/include/linux/fs.h
60088 index 25c40b9..1bfd4f4 100644
60089 --- a/include/linux/fs.h
60090 +++ b/include/linux/fs.h
60091 @@ -1634,7 +1634,8 @@ struct file_operations {
60092 int (*setlease)(struct file *, long, struct file_lock **);
60093 long (*fallocate)(struct file *file, int mode, loff_t offset,
60094 loff_t len);
60095 -};
60096 +} __do_const;
60097 +typedef struct file_operations __no_const file_operations_no_const;
60098
60099 struct inode_operations {
60100 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
60101 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
60102 index 003dc0f..3c4ea97 100644
60103 --- a/include/linux/fs_struct.h
60104 +++ b/include/linux/fs_struct.h
60105 @@ -6,7 +6,7 @@
60106 #include <linux/seqlock.h>
60107
60108 struct fs_struct {
60109 - int users;
60110 + atomic_t users;
60111 spinlock_t lock;
60112 seqcount_t seq;
60113 int umask;
60114 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
60115 index ce31408..b1ad003 100644
60116 --- a/include/linux/fscache-cache.h
60117 +++ b/include/linux/fscache-cache.h
60118 @@ -102,7 +102,7 @@ struct fscache_operation {
60119 fscache_operation_release_t release;
60120 };
60121
60122 -extern atomic_t fscache_op_debug_id;
60123 +extern atomic_unchecked_t fscache_op_debug_id;
60124 extern void fscache_op_work_func(struct work_struct *work);
60125
60126 extern void fscache_enqueue_operation(struct fscache_operation *);
60127 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
60128 {
60129 INIT_WORK(&op->work, fscache_op_work_func);
60130 atomic_set(&op->usage, 1);
60131 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
60132 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60133 op->processor = processor;
60134 op->release = release;
60135 INIT_LIST_HEAD(&op->pend_link);
60136 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
60137 index a6dfe69..569586df 100644
60138 --- a/include/linux/fsnotify.h
60139 +++ b/include/linux/fsnotify.h
60140 @@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
60141 */
60142 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
60143 {
60144 - return kstrdup(name, GFP_KERNEL);
60145 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
60146 }
60147
60148 /*
60149 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
60150 index 91d0e0a3..035666b 100644
60151 --- a/include/linux/fsnotify_backend.h
60152 +++ b/include/linux/fsnotify_backend.h
60153 @@ -105,6 +105,7 @@ struct fsnotify_ops {
60154 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
60155 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
60156 };
60157 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
60158
60159 /*
60160 * A group is a "thing" that wants to receive notification about filesystem
60161 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
60162 index 176a939..1462211 100644
60163 --- a/include/linux/ftrace_event.h
60164 +++ b/include/linux/ftrace_event.h
60165 @@ -97,7 +97,7 @@ struct trace_event_functions {
60166 trace_print_func raw;
60167 trace_print_func hex;
60168 trace_print_func binary;
60169 -};
60170 +} __no_const;
60171
60172 struct trace_event {
60173 struct hlist_node node;
60174 @@ -263,7 +263,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
60175 extern int trace_add_event_call(struct ftrace_event_call *call);
60176 extern void trace_remove_event_call(struct ftrace_event_call *call);
60177
60178 -#define is_signed_type(type) (((type)(-1)) < 0)
60179 +#define is_signed_type(type) (((type)(-1)) < (type)1)
60180
60181 int trace_set_clr_event(const char *system, const char *event, int set);
60182
60183 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
60184 index 017a7fb..33a8507 100644
60185 --- a/include/linux/genhd.h
60186 +++ b/include/linux/genhd.h
60187 @@ -185,7 +185,7 @@ struct gendisk {
60188 struct kobject *slave_dir;
60189
60190 struct timer_rand_state *random;
60191 - atomic_t sync_io; /* RAID */
60192 + atomic_unchecked_t sync_io; /* RAID */
60193 struct disk_events *ev;
60194 #ifdef CONFIG_BLK_DEV_INTEGRITY
60195 struct blk_integrity *integrity;
60196 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
60197 new file mode 100644
60198 index 0000000..c938b1f
60199 --- /dev/null
60200 +++ b/include/linux/gracl.h
60201 @@ -0,0 +1,319 @@
60202 +#ifndef GR_ACL_H
60203 +#define GR_ACL_H
60204 +
60205 +#include <linux/grdefs.h>
60206 +#include <linux/resource.h>
60207 +#include <linux/capability.h>
60208 +#include <linux/dcache.h>
60209 +#include <asm/resource.h>
60210 +
60211 +/* Major status information */
60212 +
60213 +#define GR_VERSION "grsecurity 2.9.1"
60214 +#define GRSECURITY_VERSION 0x2901
60215 +
60216 +enum {
60217 + GR_SHUTDOWN = 0,
60218 + GR_ENABLE = 1,
60219 + GR_SPROLE = 2,
60220 + GR_RELOAD = 3,
60221 + GR_SEGVMOD = 4,
60222 + GR_STATUS = 5,
60223 + GR_UNSPROLE = 6,
60224 + GR_PASSSET = 7,
60225 + GR_SPROLEPAM = 8,
60226 +};
60227 +
60228 +/* Password setup definitions
60229 + * kernel/grhash.c */
60230 +enum {
60231 + GR_PW_LEN = 128,
60232 + GR_SALT_LEN = 16,
60233 + GR_SHA_LEN = 32,
60234 +};
60235 +
60236 +enum {
60237 + GR_SPROLE_LEN = 64,
60238 +};
60239 +
60240 +enum {
60241 + GR_NO_GLOB = 0,
60242 + GR_REG_GLOB,
60243 + GR_CREATE_GLOB
60244 +};
60245 +
60246 +#define GR_NLIMITS 32
60247 +
60248 +/* Begin Data Structures */
60249 +
60250 +struct sprole_pw {
60251 + unsigned char *rolename;
60252 + unsigned char salt[GR_SALT_LEN];
60253 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
60254 +};
60255 +
60256 +struct name_entry {
60257 + __u32 key;
60258 + ino_t inode;
60259 + dev_t device;
60260 + char *name;
60261 + __u16 len;
60262 + __u8 deleted;
60263 + struct name_entry *prev;
60264 + struct name_entry *next;
60265 +};
60266 +
60267 +struct inodev_entry {
60268 + struct name_entry *nentry;
60269 + struct inodev_entry *prev;
60270 + struct inodev_entry *next;
60271 +};
60272 +
60273 +struct acl_role_db {
60274 + struct acl_role_label **r_hash;
60275 + __u32 r_size;
60276 +};
60277 +
60278 +struct inodev_db {
60279 + struct inodev_entry **i_hash;
60280 + __u32 i_size;
60281 +};
60282 +
60283 +struct name_db {
60284 + struct name_entry **n_hash;
60285 + __u32 n_size;
60286 +};
60287 +
60288 +struct crash_uid {
60289 + uid_t uid;
60290 + unsigned long expires;
60291 +};
60292 +
60293 +struct gr_hash_struct {
60294 + void **table;
60295 + void **nametable;
60296 + void *first;
60297 + __u32 table_size;
60298 + __u32 used_size;
60299 + int type;
60300 +};
60301 +
60302 +/* Userspace Grsecurity ACL data structures */
60303 +
60304 +struct acl_subject_label {
60305 + char *filename;
60306 + ino_t inode;
60307 + dev_t device;
60308 + __u32 mode;
60309 + kernel_cap_t cap_mask;
60310 + kernel_cap_t cap_lower;
60311 + kernel_cap_t cap_invert_audit;
60312 +
60313 + struct rlimit res[GR_NLIMITS];
60314 + __u32 resmask;
60315 +
60316 + __u8 user_trans_type;
60317 + __u8 group_trans_type;
60318 + uid_t *user_transitions;
60319 + gid_t *group_transitions;
60320 + __u16 user_trans_num;
60321 + __u16 group_trans_num;
60322 +
60323 + __u32 sock_families[2];
60324 + __u32 ip_proto[8];
60325 + __u32 ip_type;
60326 + struct acl_ip_label **ips;
60327 + __u32 ip_num;
60328 + __u32 inaddr_any_override;
60329 +
60330 + __u32 crashes;
60331 + unsigned long expires;
60332 +
60333 + struct acl_subject_label *parent_subject;
60334 + struct gr_hash_struct *hash;
60335 + struct acl_subject_label *prev;
60336 + struct acl_subject_label *next;
60337 +
60338 + struct acl_object_label **obj_hash;
60339 + __u32 obj_hash_size;
60340 + __u16 pax_flags;
60341 +};
60342 +
60343 +struct role_allowed_ip {
60344 + __u32 addr;
60345 + __u32 netmask;
60346 +
60347 + struct role_allowed_ip *prev;
60348 + struct role_allowed_ip *next;
60349 +};
60350 +
60351 +struct role_transition {
60352 + char *rolename;
60353 +
60354 + struct role_transition *prev;
60355 + struct role_transition *next;
60356 +};
60357 +
60358 +struct acl_role_label {
60359 + char *rolename;
60360 + uid_t uidgid;
60361 + __u16 roletype;
60362 +
60363 + __u16 auth_attempts;
60364 + unsigned long expires;
60365 +
60366 + struct acl_subject_label *root_label;
60367 + struct gr_hash_struct *hash;
60368 +
60369 + struct acl_role_label *prev;
60370 + struct acl_role_label *next;
60371 +
60372 + struct role_transition *transitions;
60373 + struct role_allowed_ip *allowed_ips;
60374 + uid_t *domain_children;
60375 + __u16 domain_child_num;
60376 +
60377 + umode_t umask;
60378 +
60379 + struct acl_subject_label **subj_hash;
60380 + __u32 subj_hash_size;
60381 +};
60382 +
60383 +struct user_acl_role_db {
60384 + struct acl_role_label **r_table;
60385 + __u32 num_pointers; /* Number of allocations to track */
60386 + __u32 num_roles; /* Number of roles */
60387 + __u32 num_domain_children; /* Number of domain children */
60388 + __u32 num_subjects; /* Number of subjects */
60389 + __u32 num_objects; /* Number of objects */
60390 +};
60391 +
60392 +struct acl_object_label {
60393 + char *filename;
60394 + ino_t inode;
60395 + dev_t device;
60396 + __u32 mode;
60397 +
60398 + struct acl_subject_label *nested;
60399 + struct acl_object_label *globbed;
60400 +
60401 + /* next two structures not used */
60402 +
60403 + struct acl_object_label *prev;
60404 + struct acl_object_label *next;
60405 +};
60406 +
60407 +struct acl_ip_label {
60408 + char *iface;
60409 + __u32 addr;
60410 + __u32 netmask;
60411 + __u16 low, high;
60412 + __u8 mode;
60413 + __u32 type;
60414 + __u32 proto[8];
60415 +
60416 + /* next two structures not used */
60417 +
60418 + struct acl_ip_label *prev;
60419 + struct acl_ip_label *next;
60420 +};
60421 +
60422 +struct gr_arg {
60423 + struct user_acl_role_db role_db;
60424 + unsigned char pw[GR_PW_LEN];
60425 + unsigned char salt[GR_SALT_LEN];
60426 + unsigned char sum[GR_SHA_LEN];
60427 + unsigned char sp_role[GR_SPROLE_LEN];
60428 + struct sprole_pw *sprole_pws;
60429 + dev_t segv_device;
60430 + ino_t segv_inode;
60431 + uid_t segv_uid;
60432 + __u16 num_sprole_pws;
60433 + __u16 mode;
60434 +};
60435 +
60436 +struct gr_arg_wrapper {
60437 + struct gr_arg *arg;
60438 + __u32 version;
60439 + __u32 size;
60440 +};
60441 +
60442 +struct subject_map {
60443 + struct acl_subject_label *user;
60444 + struct acl_subject_label *kernel;
60445 + struct subject_map *prev;
60446 + struct subject_map *next;
60447 +};
60448 +
60449 +struct acl_subj_map_db {
60450 + struct subject_map **s_hash;
60451 + __u32 s_size;
60452 +};
60453 +
60454 +/* End Data Structures Section */
60455 +
60456 +/* Hash functions generated by empirical testing by Brad Spengler
60457 + Makes good use of the low bits of the inode. Generally 0-1 times
60458 + in loop for successful match. 0-3 for unsuccessful match.
60459 + Shift/add algorithm with modulus of table size and an XOR*/
60460 +
60461 +static __inline__ unsigned int
60462 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
60463 +{
60464 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
60465 +}
60466 +
60467 + static __inline__ unsigned int
60468 +shash(const struct acl_subject_label *userp, const unsigned int sz)
60469 +{
60470 + return ((const unsigned long)userp % sz);
60471 +}
60472 +
60473 +static __inline__ unsigned int
60474 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
60475 +{
60476 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
60477 +}
60478 +
60479 +static __inline__ unsigned int
60480 +nhash(const char *name, const __u16 len, const unsigned int sz)
60481 +{
60482 + return full_name_hash((const unsigned char *)name, len) % sz;
60483 +}
60484 +
60485 +#define FOR_EACH_ROLE_START(role) \
60486 + role = role_list; \
60487 + while (role) {
60488 +
60489 +#define FOR_EACH_ROLE_END(role) \
60490 + role = role->prev; \
60491 + }
60492 +
60493 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
60494 + subj = NULL; \
60495 + iter = 0; \
60496 + while (iter < role->subj_hash_size) { \
60497 + if (subj == NULL) \
60498 + subj = role->subj_hash[iter]; \
60499 + if (subj == NULL) { \
60500 + iter++; \
60501 + continue; \
60502 + }
60503 +
60504 +#define FOR_EACH_SUBJECT_END(subj,iter) \
60505 + subj = subj->next; \
60506 + if (subj == NULL) \
60507 + iter++; \
60508 + }
60509 +
60510 +
60511 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
60512 + subj = role->hash->first; \
60513 + while (subj != NULL) {
60514 +
60515 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
60516 + subj = subj->next; \
60517 + }
60518 +
60519 +#endif
60520 +
60521 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
60522 new file mode 100644
60523 index 0000000..323ecf2
60524 --- /dev/null
60525 +++ b/include/linux/gralloc.h
60526 @@ -0,0 +1,9 @@
60527 +#ifndef __GRALLOC_H
60528 +#define __GRALLOC_H
60529 +
60530 +void acl_free_all(void);
60531 +int acl_alloc_stack_init(unsigned long size);
60532 +void *acl_alloc(unsigned long len);
60533 +void *acl_alloc_num(unsigned long num, unsigned long len);
60534 +
60535 +#endif
60536 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
60537 new file mode 100644
60538 index 0000000..b30e9bc
60539 --- /dev/null
60540 +++ b/include/linux/grdefs.h
60541 @@ -0,0 +1,140 @@
60542 +#ifndef GRDEFS_H
60543 +#define GRDEFS_H
60544 +
60545 +/* Begin grsecurity status declarations */
60546 +
60547 +enum {
60548 + GR_READY = 0x01,
60549 + GR_STATUS_INIT = 0x00 // disabled state
60550 +};
60551 +
60552 +/* Begin ACL declarations */
60553 +
60554 +/* Role flags */
60555 +
60556 +enum {
60557 + GR_ROLE_USER = 0x0001,
60558 + GR_ROLE_GROUP = 0x0002,
60559 + GR_ROLE_DEFAULT = 0x0004,
60560 + GR_ROLE_SPECIAL = 0x0008,
60561 + GR_ROLE_AUTH = 0x0010,
60562 + GR_ROLE_NOPW = 0x0020,
60563 + GR_ROLE_GOD = 0x0040,
60564 + GR_ROLE_LEARN = 0x0080,
60565 + GR_ROLE_TPE = 0x0100,
60566 + GR_ROLE_DOMAIN = 0x0200,
60567 + GR_ROLE_PAM = 0x0400,
60568 + GR_ROLE_PERSIST = 0x0800
60569 +};
60570 +
60571 +/* ACL Subject and Object mode flags */
60572 +enum {
60573 + GR_DELETED = 0x80000000
60574 +};
60575 +
60576 +/* ACL Object-only mode flags */
60577 +enum {
60578 + GR_READ = 0x00000001,
60579 + GR_APPEND = 0x00000002,
60580 + GR_WRITE = 0x00000004,
60581 + GR_EXEC = 0x00000008,
60582 + GR_FIND = 0x00000010,
60583 + GR_INHERIT = 0x00000020,
60584 + GR_SETID = 0x00000040,
60585 + GR_CREATE = 0x00000080,
60586 + GR_DELETE = 0x00000100,
60587 + GR_LINK = 0x00000200,
60588 + GR_AUDIT_READ = 0x00000400,
60589 + GR_AUDIT_APPEND = 0x00000800,
60590 + GR_AUDIT_WRITE = 0x00001000,
60591 + GR_AUDIT_EXEC = 0x00002000,
60592 + GR_AUDIT_FIND = 0x00004000,
60593 + GR_AUDIT_INHERIT= 0x00008000,
60594 + GR_AUDIT_SETID = 0x00010000,
60595 + GR_AUDIT_CREATE = 0x00020000,
60596 + GR_AUDIT_DELETE = 0x00040000,
60597 + GR_AUDIT_LINK = 0x00080000,
60598 + GR_PTRACERD = 0x00100000,
60599 + GR_NOPTRACE = 0x00200000,
60600 + GR_SUPPRESS = 0x00400000,
60601 + GR_NOLEARN = 0x00800000,
60602 + GR_INIT_TRANSFER= 0x01000000
60603 +};
60604 +
60605 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
60606 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
60607 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
60608 +
60609 +/* ACL subject-only mode flags */
60610 +enum {
60611 + GR_KILL = 0x00000001,
60612 + GR_VIEW = 0x00000002,
60613 + GR_PROTECTED = 0x00000004,
60614 + GR_LEARN = 0x00000008,
60615 + GR_OVERRIDE = 0x00000010,
60616 + /* just a placeholder, this mode is only used in userspace */
60617 + GR_DUMMY = 0x00000020,
60618 + GR_PROTSHM = 0x00000040,
60619 + GR_KILLPROC = 0x00000080,
60620 + GR_KILLIPPROC = 0x00000100,
60621 + /* just a placeholder, this mode is only used in userspace */
60622 + GR_NOTROJAN = 0x00000200,
60623 + GR_PROTPROCFD = 0x00000400,
60624 + GR_PROCACCT = 0x00000800,
60625 + GR_RELAXPTRACE = 0x00001000,
60626 + GR_NESTED = 0x00002000,
60627 + GR_INHERITLEARN = 0x00004000,
60628 + GR_PROCFIND = 0x00008000,
60629 + GR_POVERRIDE = 0x00010000,
60630 + GR_KERNELAUTH = 0x00020000,
60631 + GR_ATSECURE = 0x00040000,
60632 + GR_SHMEXEC = 0x00080000
60633 +};
60634 +
60635 +enum {
60636 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
60637 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
60638 + GR_PAX_ENABLE_MPROTECT = 0x0004,
60639 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
60640 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
60641 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
60642 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
60643 + GR_PAX_DISABLE_MPROTECT = 0x0400,
60644 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
60645 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
60646 +};
60647 +
60648 +enum {
60649 + GR_ID_USER = 0x01,
60650 + GR_ID_GROUP = 0x02,
60651 +};
60652 +
60653 +enum {
60654 + GR_ID_ALLOW = 0x01,
60655 + GR_ID_DENY = 0x02,
60656 +};
60657 +
60658 +#define GR_CRASH_RES 31
60659 +#define GR_UIDTABLE_MAX 500
60660 +
60661 +/* begin resource learning section */
60662 +enum {
60663 + GR_RLIM_CPU_BUMP = 60,
60664 + GR_RLIM_FSIZE_BUMP = 50000,
60665 + GR_RLIM_DATA_BUMP = 10000,
60666 + GR_RLIM_STACK_BUMP = 1000,
60667 + GR_RLIM_CORE_BUMP = 10000,
60668 + GR_RLIM_RSS_BUMP = 500000,
60669 + GR_RLIM_NPROC_BUMP = 1,
60670 + GR_RLIM_NOFILE_BUMP = 5,
60671 + GR_RLIM_MEMLOCK_BUMP = 50000,
60672 + GR_RLIM_AS_BUMP = 500000,
60673 + GR_RLIM_LOCKS_BUMP = 2,
60674 + GR_RLIM_SIGPENDING_BUMP = 5,
60675 + GR_RLIM_MSGQUEUE_BUMP = 10000,
60676 + GR_RLIM_NICE_BUMP = 1,
60677 + GR_RLIM_RTPRIO_BUMP = 1,
60678 + GR_RLIM_RTTIME_BUMP = 1000000
60679 +};
60680 +
60681 +#endif
60682 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
60683 new file mode 100644
60684 index 0000000..c9292f7
60685 --- /dev/null
60686 +++ b/include/linux/grinternal.h
60687 @@ -0,0 +1,223 @@
60688 +#ifndef __GRINTERNAL_H
60689 +#define __GRINTERNAL_H
60690 +
60691 +#ifdef CONFIG_GRKERNSEC
60692 +
60693 +#include <linux/fs.h>
60694 +#include <linux/mnt_namespace.h>
60695 +#include <linux/nsproxy.h>
60696 +#include <linux/gracl.h>
60697 +#include <linux/grdefs.h>
60698 +#include <linux/grmsg.h>
60699 +
60700 +void gr_add_learn_entry(const char *fmt, ...)
60701 + __attribute__ ((format (printf, 1, 2)));
60702 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
60703 + const struct vfsmount *mnt);
60704 +__u32 gr_check_create(const struct dentry *new_dentry,
60705 + const struct dentry *parent,
60706 + const struct vfsmount *mnt, const __u32 mode);
60707 +int gr_check_protected_task(const struct task_struct *task);
60708 +__u32 to_gr_audit(const __u32 reqmode);
60709 +int gr_set_acls(const int type);
60710 +int gr_apply_subject_to_task(struct task_struct *task);
60711 +int gr_acl_is_enabled(void);
60712 +char gr_roletype_to_char(void);
60713 +
60714 +void gr_handle_alertkill(struct task_struct *task);
60715 +char *gr_to_filename(const struct dentry *dentry,
60716 + const struct vfsmount *mnt);
60717 +char *gr_to_filename1(const struct dentry *dentry,
60718 + const struct vfsmount *mnt);
60719 +char *gr_to_filename2(const struct dentry *dentry,
60720 + const struct vfsmount *mnt);
60721 +char *gr_to_filename3(const struct dentry *dentry,
60722 + const struct vfsmount *mnt);
60723 +
60724 +extern int grsec_enable_ptrace_readexec;
60725 +extern int grsec_enable_harden_ptrace;
60726 +extern int grsec_enable_link;
60727 +extern int grsec_enable_fifo;
60728 +extern int grsec_enable_execve;
60729 +extern int grsec_enable_shm;
60730 +extern int grsec_enable_execlog;
60731 +extern int grsec_enable_signal;
60732 +extern int grsec_enable_audit_ptrace;
60733 +extern int grsec_enable_forkfail;
60734 +extern int grsec_enable_time;
60735 +extern int grsec_enable_rofs;
60736 +extern int grsec_enable_chroot_shmat;
60737 +extern int grsec_enable_chroot_mount;
60738 +extern int grsec_enable_chroot_double;
60739 +extern int grsec_enable_chroot_pivot;
60740 +extern int grsec_enable_chroot_chdir;
60741 +extern int grsec_enable_chroot_chmod;
60742 +extern int grsec_enable_chroot_mknod;
60743 +extern int grsec_enable_chroot_fchdir;
60744 +extern int grsec_enable_chroot_nice;
60745 +extern int grsec_enable_chroot_execlog;
60746 +extern int grsec_enable_chroot_caps;
60747 +extern int grsec_enable_chroot_sysctl;
60748 +extern int grsec_enable_chroot_unix;
60749 +extern int grsec_enable_symlinkown;
60750 +extern int grsec_symlinkown_gid;
60751 +extern int grsec_enable_tpe;
60752 +extern int grsec_tpe_gid;
60753 +extern int grsec_enable_tpe_all;
60754 +extern int grsec_enable_tpe_invert;
60755 +extern int grsec_enable_socket_all;
60756 +extern int grsec_socket_all_gid;
60757 +extern int grsec_enable_socket_client;
60758 +extern int grsec_socket_client_gid;
60759 +extern int grsec_enable_socket_server;
60760 +extern int grsec_socket_server_gid;
60761 +extern int grsec_audit_gid;
60762 +extern int grsec_enable_group;
60763 +extern int grsec_enable_audit_textrel;
60764 +extern int grsec_enable_log_rwxmaps;
60765 +extern int grsec_enable_mount;
60766 +extern int grsec_enable_chdir;
60767 +extern int grsec_resource_logging;
60768 +extern int grsec_enable_blackhole;
60769 +extern int grsec_lastack_retries;
60770 +extern int grsec_enable_brute;
60771 +extern int grsec_lock;
60772 +
60773 +extern spinlock_t grsec_alert_lock;
60774 +extern unsigned long grsec_alert_wtime;
60775 +extern unsigned long grsec_alert_fyet;
60776 +
60777 +extern spinlock_t grsec_audit_lock;
60778 +
60779 +extern rwlock_t grsec_exec_file_lock;
60780 +
60781 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
60782 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
60783 + (tsk)->exec_file->f_vfsmnt) : "/")
60784 +
60785 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
60786 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
60787 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
60788 +
60789 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
60790 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
60791 + (tsk)->exec_file->f_vfsmnt) : "/")
60792 +
60793 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
60794 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
60795 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
60796 +
60797 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
60798 +
60799 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
60800 +
60801 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
60802 + (task)->pid, (cred)->uid, \
60803 + (cred)->euid, (cred)->gid, (cred)->egid, \
60804 + gr_parent_task_fullpath(task), \
60805 + (task)->real_parent->comm, (task)->real_parent->pid, \
60806 + (pcred)->uid, (pcred)->euid, \
60807 + (pcred)->gid, (pcred)->egid
60808 +
60809 +#define GR_CHROOT_CAPS {{ \
60810 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
60811 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
60812 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
60813 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
60814 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
60815 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
60816 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
60817 +
60818 +#define security_learn(normal_msg,args...) \
60819 +({ \
60820 + read_lock(&grsec_exec_file_lock); \
60821 + gr_add_learn_entry(normal_msg "\n", ## args); \
60822 + read_unlock(&grsec_exec_file_lock); \
60823 +})
60824 +
60825 +enum {
60826 + GR_DO_AUDIT,
60827 + GR_DONT_AUDIT,
60828 + /* used for non-audit messages that we shouldn't kill the task on */
60829 + GR_DONT_AUDIT_GOOD
60830 +};
60831 +
60832 +enum {
60833 + GR_TTYSNIFF,
60834 + GR_RBAC,
60835 + GR_RBAC_STR,
60836 + GR_STR_RBAC,
60837 + GR_RBAC_MODE2,
60838 + GR_RBAC_MODE3,
60839 + GR_FILENAME,
60840 + GR_SYSCTL_HIDDEN,
60841 + GR_NOARGS,
60842 + GR_ONE_INT,
60843 + GR_ONE_INT_TWO_STR,
60844 + GR_ONE_STR,
60845 + GR_STR_INT,
60846 + GR_TWO_STR_INT,
60847 + GR_TWO_INT,
60848 + GR_TWO_U64,
60849 + GR_THREE_INT,
60850 + GR_FIVE_INT_TWO_STR,
60851 + GR_TWO_STR,
60852 + GR_THREE_STR,
60853 + GR_FOUR_STR,
60854 + GR_STR_FILENAME,
60855 + GR_FILENAME_STR,
60856 + GR_FILENAME_TWO_INT,
60857 + GR_FILENAME_TWO_INT_STR,
60858 + GR_TEXTREL,
60859 + GR_PTRACE,
60860 + GR_RESOURCE,
60861 + GR_CAP,
60862 + GR_SIG,
60863 + GR_SIG2,
60864 + GR_CRASH1,
60865 + GR_CRASH2,
60866 + GR_PSACCT,
60867 + GR_RWXMAP
60868 +};
60869 +
60870 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
60871 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
60872 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
60873 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
60874 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
60875 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
60876 +#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)
60877 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
60878 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
60879 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
60880 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
60881 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
60882 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
60883 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
60884 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
60885 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
60886 +#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)
60887 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
60888 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
60889 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
60890 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
60891 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
60892 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
60893 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
60894 +#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)
60895 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
60896 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
60897 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
60898 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
60899 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
60900 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
60901 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
60902 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
60903 +#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)
60904 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
60905 +
60906 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
60907 +
60908 +#endif
60909 +
60910 +#endif
60911 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
60912 new file mode 100644
60913 index 0000000..54f4e85
60914 --- /dev/null
60915 +++ b/include/linux/grmsg.h
60916 @@ -0,0 +1,110 @@
60917 +#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"
60918 +#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"
60919 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
60920 +#define GR_STOPMOD_MSG "denied modification of module state by "
60921 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
60922 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
60923 +#define GR_IOPERM_MSG "denied use of ioperm() by "
60924 +#define GR_IOPL_MSG "denied use of iopl() by "
60925 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
60926 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
60927 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
60928 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
60929 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
60930 +#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"
60931 +#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"
60932 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
60933 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
60934 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
60935 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
60936 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
60937 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
60938 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
60939 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
60940 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
60941 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
60942 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
60943 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
60944 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
60945 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
60946 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
60947 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
60948 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
60949 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
60950 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
60951 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
60952 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
60953 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
60954 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
60955 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
60956 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
60957 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
60958 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
60959 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
60960 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
60961 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
60962 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
60963 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
60964 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
60965 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
60966 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
60967 +#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"
60968 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
60969 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
60970 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
60971 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
60972 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
60973 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
60974 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
60975 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
60976 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
60977 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
60978 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
60979 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
60980 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
60981 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
60982 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
60983 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
60984 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
60985 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
60986 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
60987 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
60988 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
60989 +#define GR_NICE_CHROOT_MSG "denied priority change by "
60990 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
60991 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
60992 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
60993 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
60994 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
60995 +#define GR_TIME_MSG "time set by "
60996 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
60997 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
60998 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
60999 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
61000 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
61001 +#define GR_BIND_MSG "denied bind() by "
61002 +#define GR_CONNECT_MSG "denied connect() by "
61003 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
61004 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
61005 +#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"
61006 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
61007 +#define GR_CAP_ACL_MSG "use of %s denied for "
61008 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
61009 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
61010 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
61011 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
61012 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
61013 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
61014 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
61015 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
61016 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
61017 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
61018 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
61019 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
61020 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
61021 +#define GR_VM86_MSG "denied use of vm86 by "
61022 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
61023 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
61024 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
61025 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
61026 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
61027 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
61028 new file mode 100644
61029 index 0000000..38bfb04
61030 --- /dev/null
61031 +++ b/include/linux/grsecurity.h
61032 @@ -0,0 +1,233 @@
61033 +#ifndef GR_SECURITY_H
61034 +#define GR_SECURITY_H
61035 +#include <linux/fs.h>
61036 +#include <linux/fs_struct.h>
61037 +#include <linux/binfmts.h>
61038 +#include <linux/gracl.h>
61039 +
61040 +/* notify of brain-dead configs */
61041 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61042 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
61043 +#endif
61044 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
61045 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
61046 +#endif
61047 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
61048 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
61049 +#endif
61050 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
61051 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
61052 +#endif
61053 +
61054 +#include <linux/compat.h>
61055 +
61056 +struct user_arg_ptr {
61057 +#ifdef CONFIG_COMPAT
61058 + bool is_compat;
61059 +#endif
61060 + union {
61061 + const char __user *const __user *native;
61062 +#ifdef CONFIG_COMPAT
61063 + compat_uptr_t __user *compat;
61064 +#endif
61065 + } ptr;
61066 +};
61067 +
61068 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
61069 +void gr_handle_brute_check(void);
61070 +void gr_handle_kernel_exploit(void);
61071 +int gr_process_user_ban(void);
61072 +
61073 +char gr_roletype_to_char(void);
61074 +
61075 +int gr_acl_enable_at_secure(void);
61076 +
61077 +int gr_check_user_change(int real, int effective, int fs);
61078 +int gr_check_group_change(int real, int effective, int fs);
61079 +
61080 +void gr_del_task_from_ip_table(struct task_struct *p);
61081 +
61082 +int gr_pid_is_chrooted(struct task_struct *p);
61083 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
61084 +int gr_handle_chroot_nice(void);
61085 +int gr_handle_chroot_sysctl(const int op);
61086 +int gr_handle_chroot_setpriority(struct task_struct *p,
61087 + const int niceval);
61088 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
61089 +int gr_handle_chroot_chroot(const struct dentry *dentry,
61090 + const struct vfsmount *mnt);
61091 +void gr_handle_chroot_chdir(struct path *path);
61092 +int gr_handle_chroot_chmod(const struct dentry *dentry,
61093 + const struct vfsmount *mnt, const int mode);
61094 +int gr_handle_chroot_mknod(const struct dentry *dentry,
61095 + const struct vfsmount *mnt, const int mode);
61096 +int gr_handle_chroot_mount(const struct dentry *dentry,
61097 + const struct vfsmount *mnt,
61098 + const char *dev_name);
61099 +int gr_handle_chroot_pivot(void);
61100 +int gr_handle_chroot_unix(const pid_t pid);
61101 +
61102 +int gr_handle_rawio(const struct inode *inode);
61103 +
61104 +void gr_handle_ioperm(void);
61105 +void gr_handle_iopl(void);
61106 +
61107 +umode_t gr_acl_umask(void);
61108 +
61109 +int gr_tpe_allow(const struct file *file);
61110 +
61111 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
61112 +void gr_clear_chroot_entries(struct task_struct *task);
61113 +
61114 +void gr_log_forkfail(const int retval);
61115 +void gr_log_timechange(void);
61116 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
61117 +void gr_log_chdir(const struct dentry *dentry,
61118 + const struct vfsmount *mnt);
61119 +void gr_log_chroot_exec(const struct dentry *dentry,
61120 + const struct vfsmount *mnt);
61121 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
61122 +void gr_log_remount(const char *devname, const int retval);
61123 +void gr_log_unmount(const char *devname, const int retval);
61124 +void gr_log_mount(const char *from, const char *to, const int retval);
61125 +void gr_log_textrel(struct vm_area_struct *vma);
61126 +void gr_log_rwxmmap(struct file *file);
61127 +void gr_log_rwxmprotect(struct file *file);
61128 +
61129 +int gr_handle_follow_link(const struct inode *parent,
61130 + const struct inode *inode,
61131 + const struct dentry *dentry,
61132 + const struct vfsmount *mnt);
61133 +int gr_handle_fifo(const struct dentry *dentry,
61134 + const struct vfsmount *mnt,
61135 + const struct dentry *dir, const int flag,
61136 + const int acc_mode);
61137 +int gr_handle_hardlink(const struct dentry *dentry,
61138 + const struct vfsmount *mnt,
61139 + struct inode *inode,
61140 + const int mode, const char *to);
61141 +
61142 +int gr_is_capable(const int cap);
61143 +int gr_is_capable_nolog(const int cap);
61144 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
61145 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
61146 +
61147 +void gr_learn_resource(const struct task_struct *task, const int limit,
61148 + const unsigned long wanted, const int gt);
61149 +void gr_copy_label(struct task_struct *tsk);
61150 +void gr_handle_crash(struct task_struct *task, const int sig);
61151 +int gr_handle_signal(const struct task_struct *p, const int sig);
61152 +int gr_check_crash_uid(const uid_t uid);
61153 +int gr_check_protected_task(const struct task_struct *task);
61154 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
61155 +int gr_acl_handle_mmap(const struct file *file,
61156 + const unsigned long prot);
61157 +int gr_acl_handle_mprotect(const struct file *file,
61158 + const unsigned long prot);
61159 +int gr_check_hidden_task(const struct task_struct *tsk);
61160 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
61161 + const struct vfsmount *mnt);
61162 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
61163 + const struct vfsmount *mnt);
61164 +__u32 gr_acl_handle_access(const struct dentry *dentry,
61165 + const struct vfsmount *mnt, const int fmode);
61166 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
61167 + const struct vfsmount *mnt, umode_t *mode);
61168 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
61169 + const struct vfsmount *mnt);
61170 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
61171 + const struct vfsmount *mnt);
61172 +int gr_handle_ptrace(struct task_struct *task, const long request);
61173 +int gr_handle_proc_ptrace(struct task_struct *task);
61174 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
61175 + const struct vfsmount *mnt);
61176 +int gr_check_crash_exec(const struct file *filp);
61177 +int gr_acl_is_enabled(void);
61178 +void gr_set_kernel_label(struct task_struct *task);
61179 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
61180 + const gid_t gid);
61181 +int gr_set_proc_label(const struct dentry *dentry,
61182 + const struct vfsmount *mnt,
61183 + const int unsafe_flags);
61184 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
61185 + const struct vfsmount *mnt);
61186 +__u32 gr_acl_handle_open(const struct dentry *dentry,
61187 + const struct vfsmount *mnt, int acc_mode);
61188 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
61189 + const struct dentry *p_dentry,
61190 + const struct vfsmount *p_mnt,
61191 + int open_flags, int acc_mode, const int imode);
61192 +void gr_handle_create(const struct dentry *dentry,
61193 + const struct vfsmount *mnt);
61194 +void gr_handle_proc_create(const struct dentry *dentry,
61195 + const struct inode *inode);
61196 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
61197 + const struct dentry *parent_dentry,
61198 + const struct vfsmount *parent_mnt,
61199 + const int mode);
61200 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
61201 + const struct dentry *parent_dentry,
61202 + const struct vfsmount *parent_mnt);
61203 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
61204 + const struct vfsmount *mnt);
61205 +void gr_handle_delete(const ino_t ino, const dev_t dev);
61206 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
61207 + const struct vfsmount *mnt);
61208 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
61209 + const struct dentry *parent_dentry,
61210 + const struct vfsmount *parent_mnt,
61211 + const char *from);
61212 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
61213 + const struct dentry *parent_dentry,
61214 + const struct vfsmount *parent_mnt,
61215 + const struct dentry *old_dentry,
61216 + const struct vfsmount *old_mnt, const char *to);
61217 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
61218 +int gr_acl_handle_rename(struct dentry *new_dentry,
61219 + struct dentry *parent_dentry,
61220 + const struct vfsmount *parent_mnt,
61221 + struct dentry *old_dentry,
61222 + struct inode *old_parent_inode,
61223 + struct vfsmount *old_mnt, const char *newname);
61224 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
61225 + struct dentry *old_dentry,
61226 + struct dentry *new_dentry,
61227 + struct vfsmount *mnt, const __u8 replace);
61228 +__u32 gr_check_link(const struct dentry *new_dentry,
61229 + const struct dentry *parent_dentry,
61230 + const struct vfsmount *parent_mnt,
61231 + const struct dentry *old_dentry,
61232 + const struct vfsmount *old_mnt);
61233 +int gr_acl_handle_filldir(const struct file *file, const char *name,
61234 + const unsigned int namelen, const ino_t ino);
61235 +
61236 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
61237 + const struct vfsmount *mnt);
61238 +void gr_acl_handle_exit(void);
61239 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
61240 +int gr_acl_handle_procpidmem(const struct task_struct *task);
61241 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
61242 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
61243 +void gr_audit_ptrace(struct task_struct *task);
61244 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
61245 +
61246 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
61247 +
61248 +#ifdef CONFIG_GRKERNSEC
61249 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
61250 +void gr_handle_vm86(void);
61251 +void gr_handle_mem_readwrite(u64 from, u64 to);
61252 +
61253 +void gr_log_badprocpid(const char *entry);
61254 +
61255 +extern int grsec_enable_dmesg;
61256 +extern int grsec_disable_privio;
61257 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61258 +extern int grsec_enable_chroot_findtask;
61259 +#endif
61260 +#ifdef CONFIG_GRKERNSEC_SETXID
61261 +extern int grsec_enable_setxid;
61262 +#endif
61263 +#endif
61264 +
61265 +#endif
61266 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
61267 new file mode 100644
61268 index 0000000..e7ffaaf
61269 --- /dev/null
61270 +++ b/include/linux/grsock.h
61271 @@ -0,0 +1,19 @@
61272 +#ifndef __GRSOCK_H
61273 +#define __GRSOCK_H
61274 +
61275 +extern void gr_attach_curr_ip(const struct sock *sk);
61276 +extern int gr_handle_sock_all(const int family, const int type,
61277 + const int protocol);
61278 +extern int gr_handle_sock_server(const struct sockaddr *sck);
61279 +extern int gr_handle_sock_server_other(const struct sock *sck);
61280 +extern int gr_handle_sock_client(const struct sockaddr *sck);
61281 +extern int gr_search_connect(struct socket * sock,
61282 + struct sockaddr_in * addr);
61283 +extern int gr_search_bind(struct socket * sock,
61284 + struct sockaddr_in * addr);
61285 +extern int gr_search_listen(struct socket * sock);
61286 +extern int gr_search_accept(struct socket * sock);
61287 +extern int gr_search_socket(const int domain, const int type,
61288 + const int protocol);
61289 +
61290 +#endif
61291 diff --git a/include/linux/hid.h b/include/linux/hid.h
61292 index 3a95da6..51986f1 100644
61293 --- a/include/linux/hid.h
61294 +++ b/include/linux/hid.h
61295 @@ -696,7 +696,7 @@ struct hid_ll_driver {
61296 unsigned int code, int value);
61297
61298 int (*parse)(struct hid_device *hdev);
61299 -};
61300 +} __no_const;
61301
61302 #define PM_HINT_FULLON 1<<5
61303 #define PM_HINT_NORMAL 1<<1
61304 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
61305 index d3999b4..1304cb4 100644
61306 --- a/include/linux/highmem.h
61307 +++ b/include/linux/highmem.h
61308 @@ -221,6 +221,18 @@ static inline void clear_highpage(struct page *page)
61309 kunmap_atomic(kaddr);
61310 }
61311
61312 +static inline void sanitize_highpage(struct page *page)
61313 +{
61314 + void *kaddr;
61315 + unsigned long flags;
61316 +
61317 + local_irq_save(flags);
61318 + kaddr = kmap_atomic(page);
61319 + clear_page(kaddr);
61320 + kunmap_atomic(kaddr);
61321 + local_irq_restore(flags);
61322 +}
61323 +
61324 static inline void zero_user_segments(struct page *page,
61325 unsigned start1, unsigned end1,
61326 unsigned start2, unsigned end2)
61327 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
61328 index 195d8b3..e20cfab 100644
61329 --- a/include/linux/i2c.h
61330 +++ b/include/linux/i2c.h
61331 @@ -365,6 +365,7 @@ struct i2c_algorithm {
61332 /* To determine what the adapter supports */
61333 u32 (*functionality) (struct i2c_adapter *);
61334 };
61335 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
61336
61337 /*
61338 * i2c_adapter is the structure used to identify a physical i2c bus along
61339 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
61340 index d23c3c2..eb63c81 100644
61341 --- a/include/linux/i2o.h
61342 +++ b/include/linux/i2o.h
61343 @@ -565,7 +565,7 @@ struct i2o_controller {
61344 struct i2o_device *exec; /* Executive */
61345 #if BITS_PER_LONG == 64
61346 spinlock_t context_list_lock; /* lock for context_list */
61347 - atomic_t context_list_counter; /* needed for unique contexts */
61348 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
61349 struct list_head context_list; /* list of context id's
61350 and pointers */
61351 #endif
61352 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
61353 index 58404b0..439ed95 100644
61354 --- a/include/linux/if_team.h
61355 +++ b/include/linux/if_team.h
61356 @@ -64,6 +64,7 @@ struct team_mode_ops {
61357 void (*port_leave)(struct team *team, struct team_port *port);
61358 void (*port_change_mac)(struct team *team, struct team_port *port);
61359 };
61360 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
61361
61362 enum team_option_type {
61363 TEAM_OPTION_TYPE_U32,
61364 @@ -112,7 +113,7 @@ struct team {
61365 struct list_head option_list;
61366
61367 const struct team_mode *mode;
61368 - struct team_mode_ops ops;
61369 + team_mode_ops_no_const ops;
61370 long mode_priv[TEAM_MODE_PRIV_LONGS];
61371 };
61372
61373 diff --git a/include/linux/init.h b/include/linux/init.h
61374 index 6b95109..4aca62c 100644
61375 --- a/include/linux/init.h
61376 +++ b/include/linux/init.h
61377 @@ -294,13 +294,13 @@ void __init parse_early_options(char *cmdline);
61378
61379 /* Each module must use one module_init(). */
61380 #define module_init(initfn) \
61381 - static inline initcall_t __inittest(void) \
61382 + static inline __used initcall_t __inittest(void) \
61383 { return initfn; } \
61384 int init_module(void) __attribute__((alias(#initfn)));
61385
61386 /* This is only required if you want to be unloadable. */
61387 #define module_exit(exitfn) \
61388 - static inline exitcall_t __exittest(void) \
61389 + static inline __used exitcall_t __exittest(void) \
61390 { return exitfn; } \
61391 void cleanup_module(void) __attribute__((alias(#exitfn)));
61392
61393 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
61394 index e4baff5..83bb175 100644
61395 --- a/include/linux/init_task.h
61396 +++ b/include/linux/init_task.h
61397 @@ -134,6 +134,12 @@ extern struct cred init_cred;
61398
61399 #define INIT_TASK_COMM "swapper"
61400
61401 +#ifdef CONFIG_X86
61402 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
61403 +#else
61404 +#define INIT_TASK_THREAD_INFO
61405 +#endif
61406 +
61407 /*
61408 * INIT_TASK is used to set up the first task table, touch at
61409 * your own risk!. Base=0, limit=0x1fffff (=2MB)
61410 @@ -172,6 +178,7 @@ extern struct cred init_cred;
61411 RCU_INIT_POINTER(.cred, &init_cred), \
61412 .comm = INIT_TASK_COMM, \
61413 .thread = INIT_THREAD, \
61414 + INIT_TASK_THREAD_INFO \
61415 .fs = &init_fs, \
61416 .files = &init_files, \
61417 .signal = &init_signals, \
61418 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
61419 index e6ca56d..8583707 100644
61420 --- a/include/linux/intel-iommu.h
61421 +++ b/include/linux/intel-iommu.h
61422 @@ -296,7 +296,7 @@ struct iommu_flush {
61423 u8 fm, u64 type);
61424 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
61425 unsigned int size_order, u64 type);
61426 -};
61427 +} __no_const;
61428
61429 enum {
61430 SR_DMAR_FECTL_REG,
61431 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
61432 index 2aea5d2..0b82f0c 100644
61433 --- a/include/linux/interrupt.h
61434 +++ b/include/linux/interrupt.h
61435 @@ -439,7 +439,7 @@ enum
61436 /* map softirq index to softirq name. update 'softirq_to_name' in
61437 * kernel/softirq.c when adding a new softirq.
61438 */
61439 -extern char *softirq_to_name[NR_SOFTIRQS];
61440 +extern const char * const softirq_to_name[NR_SOFTIRQS];
61441
61442 /* softirq mask and active fields moved to irq_cpustat_t in
61443 * asm/hardirq.h to get better cache usage. KAO
61444 @@ -447,12 +447,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
61445
61446 struct softirq_action
61447 {
61448 - void (*action)(struct softirq_action *);
61449 + void (*action)(void);
61450 };
61451
61452 asmlinkage void do_softirq(void);
61453 asmlinkage void __do_softirq(void);
61454 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
61455 +extern void open_softirq(int nr, void (*action)(void));
61456 extern void softirq_init(void);
61457 extern void __raise_softirq_irqoff(unsigned int nr);
61458
61459 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
61460 index 3875719..4cd454c 100644
61461 --- a/include/linux/kallsyms.h
61462 +++ b/include/linux/kallsyms.h
61463 @@ -15,7 +15,8 @@
61464
61465 struct module;
61466
61467 -#ifdef CONFIG_KALLSYMS
61468 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
61469 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
61470 /* Lookup the address for a symbol. Returns 0 if not found. */
61471 unsigned long kallsyms_lookup_name(const char *name);
61472
61473 @@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
61474 /* Stupid that this does nothing, but I didn't create this mess. */
61475 #define __print_symbol(fmt, addr)
61476 #endif /*CONFIG_KALLSYMS*/
61477 +#else /* when included by kallsyms.c, vsnprintf.c, or
61478 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
61479 +extern void __print_symbol(const char *fmt, unsigned long address);
61480 +extern int sprint_backtrace(char *buffer, unsigned long address);
61481 +extern int sprint_symbol(char *buffer, unsigned long address);
61482 +const char *kallsyms_lookup(unsigned long addr,
61483 + unsigned long *symbolsize,
61484 + unsigned long *offset,
61485 + char **modname, char *namebuf);
61486 +#endif
61487
61488 /* This macro allows us to keep printk typechecking */
61489 static __printf(1, 2)
61490 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
61491 index c4d2fc1..5df9c19 100644
61492 --- a/include/linux/kgdb.h
61493 +++ b/include/linux/kgdb.h
61494 @@ -53,7 +53,7 @@ extern int kgdb_connected;
61495 extern int kgdb_io_module_registered;
61496
61497 extern atomic_t kgdb_setting_breakpoint;
61498 -extern atomic_t kgdb_cpu_doing_single_step;
61499 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
61500
61501 extern struct task_struct *kgdb_usethread;
61502 extern struct task_struct *kgdb_contthread;
61503 @@ -252,7 +252,7 @@ struct kgdb_arch {
61504 void (*disable_hw_break)(struct pt_regs *regs);
61505 void (*remove_all_hw_break)(void);
61506 void (*correct_hw_break)(void);
61507 -};
61508 +} __do_const;
61509
61510 /**
61511 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
61512 @@ -277,7 +277,7 @@ struct kgdb_io {
61513 void (*pre_exception) (void);
61514 void (*post_exception) (void);
61515 int is_console;
61516 -};
61517 +} __do_const;
61518
61519 extern struct kgdb_arch arch_kgdb_ops;
61520
61521 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
61522 index dd99c32..da06047 100644
61523 --- a/include/linux/kmod.h
61524 +++ b/include/linux/kmod.h
61525 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
61526 * usually useless though. */
61527 extern __printf(2, 3)
61528 int __request_module(bool wait, const char *name, ...);
61529 +extern __printf(3, 4)
61530 +int ___request_module(bool wait, char *param_name, const char *name, ...);
61531 #define request_module(mod...) __request_module(true, mod)
61532 #define request_module_nowait(mod...) __request_module(false, mod)
61533 #define try_then_request_module(x, mod...) \
61534 diff --git a/include/linux/kref.h b/include/linux/kref.h
61535 index 9c07dce..a92fa71 100644
61536 --- a/include/linux/kref.h
61537 +++ b/include/linux/kref.h
61538 @@ -63,7 +63,7 @@ static inline void kref_get(struct kref *kref)
61539 static inline int kref_sub(struct kref *kref, unsigned int count,
61540 void (*release)(struct kref *kref))
61541 {
61542 - WARN_ON(release == NULL);
61543 + BUG_ON(release == NULL);
61544
61545 if (atomic_sub_and_test((int) count, &kref->refcount)) {
61546 release(kref);
61547 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
61548 index 72cbf08..dd0201d 100644
61549 --- a/include/linux/kvm_host.h
61550 +++ b/include/linux/kvm_host.h
61551 @@ -322,7 +322,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
61552 void vcpu_load(struct kvm_vcpu *vcpu);
61553 void vcpu_put(struct kvm_vcpu *vcpu);
61554
61555 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
61556 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
61557 struct module *module);
61558 void kvm_exit(void);
61559
61560 @@ -486,7 +486,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
61561 struct kvm_guest_debug *dbg);
61562 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
61563
61564 -int kvm_arch_init(void *opaque);
61565 +int kvm_arch_init(const void *opaque);
61566 void kvm_arch_exit(void);
61567
61568 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
61569 diff --git a/include/linux/libata.h b/include/linux/libata.h
61570 index 6e887c7..4539601 100644
61571 --- a/include/linux/libata.h
61572 +++ b/include/linux/libata.h
61573 @@ -910,7 +910,7 @@ struct ata_port_operations {
61574 * fields must be pointers.
61575 */
61576 const struct ata_port_operations *inherits;
61577 -};
61578 +} __do_const;
61579
61580 struct ata_port_info {
61581 unsigned long flags;
61582 diff --git a/include/linux/mca.h b/include/linux/mca.h
61583 index 3797270..7765ede 100644
61584 --- a/include/linux/mca.h
61585 +++ b/include/linux/mca.h
61586 @@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
61587 int region);
61588 void * (*mca_transform_memory)(struct mca_device *,
61589 void *memory);
61590 -};
61591 +} __no_const;
61592
61593 struct mca_bus {
61594 u64 default_dma_mask;
61595 diff --git a/include/linux/memory.h b/include/linux/memory.h
61596 index 1ac7f6e..a5794d0 100644
61597 --- a/include/linux/memory.h
61598 +++ b/include/linux/memory.h
61599 @@ -143,7 +143,7 @@ struct memory_accessor {
61600 size_t count);
61601 ssize_t (*write)(struct memory_accessor *, const char *buf,
61602 off_t offset, size_t count);
61603 -};
61604 +} __no_const;
61605
61606 /*
61607 * Kernel text modification mutex, used for code patching. Users of this lock
61608 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
61609 index ee96cd5..7823c3a 100644
61610 --- a/include/linux/mfd/abx500.h
61611 +++ b/include/linux/mfd/abx500.h
61612 @@ -455,6 +455,7 @@ struct abx500_ops {
61613 int (*event_registers_startup_state_get) (struct device *, u8 *);
61614 int (*startup_irq_enabled) (struct device *, unsigned int);
61615 };
61616 +typedef struct abx500_ops __no_const abx500_ops_no_const;
61617
61618 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
61619 void abx500_remove_ops(struct device *dev);
61620 diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
61621 index 9b07725..3d55001 100644
61622 --- a/include/linux/mfd/abx500/ux500_chargalg.h
61623 +++ b/include/linux/mfd/abx500/ux500_chargalg.h
61624 @@ -19,7 +19,7 @@ struct ux500_charger_ops {
61625 int (*enable) (struct ux500_charger *, int, int, int);
61626 int (*kick_wd) (struct ux500_charger *);
61627 int (*update_curr) (struct ux500_charger *, int);
61628 -};
61629 +} __no_const;
61630
61631 /**
61632 * struct ux500_charger - power supply ux500 charger sub class
61633 diff --git a/include/linux/mm.h b/include/linux/mm.h
61634 index 74aa71b..4ae97ba 100644
61635 --- a/include/linux/mm.h
61636 +++ b/include/linux/mm.h
61637 @@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
61638
61639 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
61640 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
61641 +
61642 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
61643 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
61644 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
61645 +#else
61646 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
61647 +#endif
61648 +
61649 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
61650 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
61651
61652 @@ -1013,34 +1020,6 @@ int set_page_dirty(struct page *page);
61653 int set_page_dirty_lock(struct page *page);
61654 int clear_page_dirty_for_io(struct page *page);
61655
61656 -/* Is the vma a continuation of the stack vma above it? */
61657 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
61658 -{
61659 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
61660 -}
61661 -
61662 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
61663 - unsigned long addr)
61664 -{
61665 - return (vma->vm_flags & VM_GROWSDOWN) &&
61666 - (vma->vm_start == addr) &&
61667 - !vma_growsdown(vma->vm_prev, addr);
61668 -}
61669 -
61670 -/* Is the vma a continuation of the stack vma below it? */
61671 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
61672 -{
61673 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
61674 -}
61675 -
61676 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
61677 - unsigned long addr)
61678 -{
61679 - return (vma->vm_flags & VM_GROWSUP) &&
61680 - (vma->vm_end == addr) &&
61681 - !vma_growsup(vma->vm_next, addr);
61682 -}
61683 -
61684 extern pid_t
61685 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
61686
61687 @@ -1139,6 +1118,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
61688 }
61689 #endif
61690
61691 +#ifdef CONFIG_MMU
61692 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
61693 +#else
61694 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
61695 +{
61696 + return __pgprot(0);
61697 +}
61698 +#endif
61699 +
61700 int vma_wants_writenotify(struct vm_area_struct *vma);
61701
61702 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
61703 @@ -1157,8 +1145,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
61704 {
61705 return 0;
61706 }
61707 +
61708 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
61709 + unsigned long address)
61710 +{
61711 + return 0;
61712 +}
61713 #else
61714 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
61715 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
61716 #endif
61717
61718 #ifdef __PAGETABLE_PMD_FOLDED
61719 @@ -1167,8 +1162,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
61720 {
61721 return 0;
61722 }
61723 +
61724 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
61725 + unsigned long address)
61726 +{
61727 + return 0;
61728 +}
61729 #else
61730 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
61731 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
61732 #endif
61733
61734 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
61735 @@ -1186,11 +1188,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
61736 NULL: pud_offset(pgd, address);
61737 }
61738
61739 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
61740 +{
61741 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
61742 + NULL: pud_offset(pgd, address);
61743 +}
61744 +
61745 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
61746 {
61747 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
61748 NULL: pmd_offset(pud, address);
61749 }
61750 +
61751 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
61752 +{
61753 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
61754 + NULL: pmd_offset(pud, address);
61755 +}
61756 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
61757
61758 #if USE_SPLIT_PTLOCKS
61759 @@ -1400,6 +1414,7 @@ extern unsigned long do_mmap(struct file *, unsigned long,
61760 unsigned long, unsigned long,
61761 unsigned long, unsigned long);
61762 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
61763 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
61764
61765 /* These take the mm semaphore themselves */
61766 extern unsigned long vm_brk(unsigned long, unsigned long);
61767 @@ -1462,6 +1477,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
61768 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
61769 struct vm_area_struct **pprev);
61770
61771 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
61772 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
61773 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
61774 +
61775 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
61776 NULL if none. Assume start_addr < end_addr. */
61777 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
61778 @@ -1490,15 +1509,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
61779 return vma;
61780 }
61781
61782 -#ifdef CONFIG_MMU
61783 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
61784 -#else
61785 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
61786 -{
61787 - return __pgprot(0);
61788 -}
61789 -#endif
61790 -
61791 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
61792 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
61793 unsigned long pfn, unsigned long size, pgprot_t);
61794 @@ -1602,7 +1612,7 @@ extern int unpoison_memory(unsigned long pfn);
61795 extern int sysctl_memory_failure_early_kill;
61796 extern int sysctl_memory_failure_recovery;
61797 extern void shake_page(struct page *p, int access);
61798 -extern atomic_long_t mce_bad_pages;
61799 +extern atomic_long_unchecked_t mce_bad_pages;
61800 extern int soft_offline_page(struct page *page, int flags);
61801
61802 extern void dump_page(struct page *page);
61803 @@ -1633,5 +1643,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
61804 static inline bool page_is_guard(struct page *page) { return false; }
61805 #endif /* CONFIG_DEBUG_PAGEALLOC */
61806
61807 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
61808 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
61809 +#else
61810 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
61811 +#endif
61812 +
61813 #endif /* __KERNEL__ */
61814 #endif /* _LINUX_MM_H */
61815 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
61816 index 3cc3062..efeaeb7 100644
61817 --- a/include/linux/mm_types.h
61818 +++ b/include/linux/mm_types.h
61819 @@ -252,6 +252,8 @@ struct vm_area_struct {
61820 #ifdef CONFIG_NUMA
61821 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
61822 #endif
61823 +
61824 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
61825 };
61826
61827 struct core_thread {
61828 @@ -326,7 +328,7 @@ struct mm_struct {
61829 unsigned long def_flags;
61830 unsigned long nr_ptes; /* Page table pages */
61831 unsigned long start_code, end_code, start_data, end_data;
61832 - unsigned long start_brk, brk, start_stack;
61833 + unsigned long brk_gap, start_brk, brk, start_stack;
61834 unsigned long arg_start, arg_end, env_start, env_end;
61835
61836 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
61837 @@ -388,6 +390,24 @@ struct mm_struct {
61838 #ifdef CONFIG_CPUMASK_OFFSTACK
61839 struct cpumask cpumask_allocation;
61840 #endif
61841 +
61842 +#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)
61843 + unsigned long pax_flags;
61844 +#endif
61845 +
61846 +#ifdef CONFIG_PAX_DLRESOLVE
61847 + unsigned long call_dl_resolve;
61848 +#endif
61849 +
61850 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
61851 + unsigned long call_syscall;
61852 +#endif
61853 +
61854 +#ifdef CONFIG_PAX_ASLR
61855 + unsigned long delta_mmap; /* randomized offset */
61856 + unsigned long delta_stack; /* randomized offset */
61857 +#endif
61858 +
61859 };
61860
61861 static inline void mm_init_cpumask(struct mm_struct *mm)
61862 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
61863 index 1d1b1e1..2a13c78 100644
61864 --- a/include/linux/mmu_notifier.h
61865 +++ b/include/linux/mmu_notifier.h
61866 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
61867 */
61868 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
61869 ({ \
61870 - pte_t __pte; \
61871 + pte_t ___pte; \
61872 struct vm_area_struct *___vma = __vma; \
61873 unsigned long ___address = __address; \
61874 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
61875 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
61876 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
61877 - __pte; \
61878 + ___pte; \
61879 })
61880
61881 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
61882 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
61883 index dff7115..0e001c8 100644
61884 --- a/include/linux/mmzone.h
61885 +++ b/include/linux/mmzone.h
61886 @@ -380,7 +380,7 @@ struct zone {
61887 unsigned long flags; /* zone flags, see below */
61888
61889 /* Zone statistics */
61890 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
61891 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
61892
61893 /*
61894 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
61895 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
61896 index 501da4c..ba79bb4 100644
61897 --- a/include/linux/mod_devicetable.h
61898 +++ b/include/linux/mod_devicetable.h
61899 @@ -12,7 +12,7 @@
61900 typedef unsigned long kernel_ulong_t;
61901 #endif
61902
61903 -#define PCI_ANY_ID (~0)
61904 +#define PCI_ANY_ID ((__u16)~0)
61905
61906 struct pci_device_id {
61907 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
61908 @@ -131,7 +131,7 @@ struct usb_device_id {
61909 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
61910 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
61911
61912 -#define HID_ANY_ID (~0)
61913 +#define HID_ANY_ID (~0U)
61914
61915 struct hid_device_id {
61916 __u16 bus;
61917 diff --git a/include/linux/module.h b/include/linux/module.h
61918 index fbcafe2..e5d9587 100644
61919 --- a/include/linux/module.h
61920 +++ b/include/linux/module.h
61921 @@ -17,6 +17,7 @@
61922 #include <linux/moduleparam.h>
61923 #include <linux/tracepoint.h>
61924 #include <linux/export.h>
61925 +#include <linux/fs.h>
61926
61927 #include <linux/percpu.h>
61928 #include <asm/module.h>
61929 @@ -273,19 +274,16 @@ struct module
61930 int (*init)(void);
61931
61932 /* If this is non-NULL, vfree after init() returns */
61933 - void *module_init;
61934 + void *module_init_rx, *module_init_rw;
61935
61936 /* Here is the actual code + data, vfree'd on unload. */
61937 - void *module_core;
61938 + void *module_core_rx, *module_core_rw;
61939
61940 /* Here are the sizes of the init and core sections */
61941 - unsigned int init_size, core_size;
61942 + unsigned int init_size_rw, core_size_rw;
61943
61944 /* The size of the executable code in each section. */
61945 - unsigned int init_text_size, core_text_size;
61946 -
61947 - /* Size of RO sections of the module (text+rodata) */
61948 - unsigned int init_ro_size, core_ro_size;
61949 + unsigned int init_size_rx, core_size_rx;
61950
61951 /* Arch-specific module values */
61952 struct mod_arch_specific arch;
61953 @@ -341,6 +339,10 @@ struct module
61954 #ifdef CONFIG_EVENT_TRACING
61955 struct ftrace_event_call **trace_events;
61956 unsigned int num_trace_events;
61957 + struct file_operations trace_id;
61958 + struct file_operations trace_enable;
61959 + struct file_operations trace_format;
61960 + struct file_operations trace_filter;
61961 #endif
61962 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
61963 unsigned int num_ftrace_callsites;
61964 @@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
61965 bool is_module_percpu_address(unsigned long addr);
61966 bool is_module_text_address(unsigned long addr);
61967
61968 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
61969 +{
61970 +
61971 +#ifdef CONFIG_PAX_KERNEXEC
61972 + if (ktla_ktva(addr) >= (unsigned long)start &&
61973 + ktla_ktva(addr) < (unsigned long)start + size)
61974 + return 1;
61975 +#endif
61976 +
61977 + return ((void *)addr >= start && (void *)addr < start + size);
61978 +}
61979 +
61980 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
61981 +{
61982 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
61983 +}
61984 +
61985 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
61986 +{
61987 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
61988 +}
61989 +
61990 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
61991 +{
61992 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
61993 +}
61994 +
61995 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
61996 +{
61997 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
61998 +}
61999 +
62000 static inline int within_module_core(unsigned long addr, struct module *mod)
62001 {
62002 - return (unsigned long)mod->module_core <= addr &&
62003 - addr < (unsigned long)mod->module_core + mod->core_size;
62004 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
62005 }
62006
62007 static inline int within_module_init(unsigned long addr, struct module *mod)
62008 {
62009 - return (unsigned long)mod->module_init <= addr &&
62010 - addr < (unsigned long)mod->module_init + mod->init_size;
62011 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
62012 }
62013
62014 /* Search for module by name: must hold module_mutex. */
62015 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
62016 index b2be02e..72d2f78 100644
62017 --- a/include/linux/moduleloader.h
62018 +++ b/include/linux/moduleloader.h
62019 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
62020
62021 /* Allocator used for allocating struct module, core sections and init
62022 sections. Returns NULL on failure. */
62023 -void *module_alloc(unsigned long size);
62024 +void *module_alloc(unsigned long size) __size_overflow(1);
62025 +
62026 +#ifdef CONFIG_PAX_KERNEXEC
62027 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
62028 +#else
62029 +#define module_alloc_exec(x) module_alloc(x)
62030 +#endif
62031
62032 /* Free memory returned from module_alloc. */
62033 void module_free(struct module *mod, void *module_region);
62034
62035 +#ifdef CONFIG_PAX_KERNEXEC
62036 +void module_free_exec(struct module *mod, void *module_region);
62037 +#else
62038 +#define module_free_exec(x, y) module_free((x), (y))
62039 +#endif
62040 +
62041 /* Apply the given relocation to the (simplified) ELF. Return -error
62042 or 0. */
62043 int apply_relocate(Elf_Shdr *sechdrs,
62044 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
62045 index 944bc18..042d291 100644
62046 --- a/include/linux/moduleparam.h
62047 +++ b/include/linux/moduleparam.h
62048 @@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
62049 * @len is usually just sizeof(string).
62050 */
62051 #define module_param_string(name, string, len, perm) \
62052 - static const struct kparam_string __param_string_##name \
62053 + static const struct kparam_string __param_string_##name __used \
62054 = { len, string }; \
62055 __module_param_call(MODULE_PARAM_PREFIX, name, \
62056 &param_ops_string, \
62057 @@ -424,7 +424,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
62058 */
62059 #define module_param_array_named(name, array, type, nump, perm) \
62060 param_check_##type(name, &(array)[0]); \
62061 - static const struct kparam_array __param_arr_##name \
62062 + static const struct kparam_array __param_arr_##name __used \
62063 = { .max = ARRAY_SIZE(array), .num = nump, \
62064 .ops = &param_ops_##type, \
62065 .elemsize = sizeof(array[0]), .elem = array }; \
62066 diff --git a/include/linux/namei.h b/include/linux/namei.h
62067 index ffc0213..2c1f2cb 100644
62068 --- a/include/linux/namei.h
62069 +++ b/include/linux/namei.h
62070 @@ -24,7 +24,7 @@ struct nameidata {
62071 unsigned seq;
62072 int last_type;
62073 unsigned depth;
62074 - char *saved_names[MAX_NESTED_LINKS + 1];
62075 + const char *saved_names[MAX_NESTED_LINKS + 1];
62076
62077 /* Intent data */
62078 union {
62079 @@ -94,12 +94,12 @@ extern int follow_up(struct path *);
62080 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
62081 extern void unlock_rename(struct dentry *, struct dentry *);
62082
62083 -static inline void nd_set_link(struct nameidata *nd, char *path)
62084 +static inline void nd_set_link(struct nameidata *nd, const char *path)
62085 {
62086 nd->saved_names[nd->depth] = path;
62087 }
62088
62089 -static inline char *nd_get_link(struct nameidata *nd)
62090 +static inline const char *nd_get_link(const struct nameidata *nd)
62091 {
62092 return nd->saved_names[nd->depth];
62093 }
62094 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
62095 index 33900a5..2072000 100644
62096 --- a/include/linux/netdevice.h
62097 +++ b/include/linux/netdevice.h
62098 @@ -1003,6 +1003,7 @@ struct net_device_ops {
62099 int (*ndo_neigh_construct)(struct neighbour *n);
62100 void (*ndo_neigh_destroy)(struct neighbour *n);
62101 };
62102 +typedef struct net_device_ops __no_const net_device_ops_no_const;
62103
62104 /*
62105 * The DEVICE structure.
62106 @@ -1064,7 +1065,7 @@ struct net_device {
62107 int iflink;
62108
62109 struct net_device_stats stats;
62110 - atomic_long_t rx_dropped; /* dropped packets by core network
62111 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
62112 * Do not use this in drivers.
62113 */
62114
62115 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
62116 new file mode 100644
62117 index 0000000..33f4af8
62118 --- /dev/null
62119 +++ b/include/linux/netfilter/xt_gradm.h
62120 @@ -0,0 +1,9 @@
62121 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
62122 +#define _LINUX_NETFILTER_XT_GRADM_H 1
62123 +
62124 +struct xt_gradm_mtinfo {
62125 + __u16 flags;
62126 + __u16 invflags;
62127 +};
62128 +
62129 +#endif
62130 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
62131 index c65a18a..0c05f3a 100644
62132 --- a/include/linux/of_pdt.h
62133 +++ b/include/linux/of_pdt.h
62134 @@ -32,7 +32,7 @@ struct of_pdt_ops {
62135
62136 /* return 0 on success; fill in 'len' with number of bytes in path */
62137 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
62138 -};
62139 +} __no_const;
62140
62141 extern void *prom_early_alloc(unsigned long size);
62142
62143 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
62144 index a4c5624..79d6d88 100644
62145 --- a/include/linux/oprofile.h
62146 +++ b/include/linux/oprofile.h
62147 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
62148 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
62149 char const * name, ulong * val);
62150
62151 -/** Create a file for read-only access to an atomic_t. */
62152 +/** Create a file for read-only access to an atomic_unchecked_t. */
62153 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
62154 - char const * name, atomic_t * val);
62155 + char const * name, atomic_unchecked_t * val);
62156
62157 /** create a directory */
62158 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
62159 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
62160 index ddbb6a9..be1680e 100644
62161 --- a/include/linux/perf_event.h
62162 +++ b/include/linux/perf_event.h
62163 @@ -879,8 +879,8 @@ struct perf_event {
62164
62165 enum perf_event_active_state state;
62166 unsigned int attach_state;
62167 - local64_t count;
62168 - atomic64_t child_count;
62169 + local64_t count; /* PaX: fix it one day */
62170 + atomic64_unchecked_t child_count;
62171
62172 /*
62173 * These are the total time in nanoseconds that the event
62174 @@ -931,8 +931,8 @@ struct perf_event {
62175 * These accumulate total time (in nanoseconds) that children
62176 * events have been enabled and running, respectively.
62177 */
62178 - atomic64_t child_total_time_enabled;
62179 - atomic64_t child_total_time_running;
62180 + atomic64_unchecked_t child_total_time_enabled;
62181 + atomic64_unchecked_t child_total_time_running;
62182
62183 /*
62184 * Protect attach/detach and child_list:
62185 diff --git a/include/linux/personality.h b/include/linux/personality.h
62186 index 8fc7dd1a..c19d89e 100644
62187 --- a/include/linux/personality.h
62188 +++ b/include/linux/personality.h
62189 @@ -44,6 +44,7 @@ enum {
62190 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
62191 ADDR_NO_RANDOMIZE | \
62192 ADDR_COMPAT_LAYOUT | \
62193 + ADDR_LIMIT_3GB | \
62194 MMAP_PAGE_ZERO)
62195
62196 /*
62197 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
62198 index e1ac1ce..0675fed 100644
62199 --- a/include/linux/pipe_fs_i.h
62200 +++ b/include/linux/pipe_fs_i.h
62201 @@ -45,9 +45,9 @@ struct pipe_buffer {
62202 struct pipe_inode_info {
62203 wait_queue_head_t wait;
62204 unsigned int nrbufs, curbuf, buffers;
62205 - unsigned int readers;
62206 - unsigned int writers;
62207 - unsigned int waiting_writers;
62208 + atomic_t readers;
62209 + atomic_t writers;
62210 + atomic_t waiting_writers;
62211 unsigned int r_counter;
62212 unsigned int w_counter;
62213 struct page *tmp_page;
62214 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
62215 index 609daae..5392427 100644
62216 --- a/include/linux/pm_runtime.h
62217 +++ b/include/linux/pm_runtime.h
62218 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
62219
62220 static inline void pm_runtime_mark_last_busy(struct device *dev)
62221 {
62222 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
62223 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
62224 }
62225
62226 #else /* !CONFIG_PM_RUNTIME */
62227 diff --git a/include/linux/poison.h b/include/linux/poison.h
62228 index 2110a81..13a11bb 100644
62229 --- a/include/linux/poison.h
62230 +++ b/include/linux/poison.h
62231 @@ -19,8 +19,8 @@
62232 * under normal circumstances, used to verify that nobody uses
62233 * non-initialized list entries.
62234 */
62235 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
62236 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
62237 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
62238 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
62239
62240 /********** include/linux/timer.h **********/
62241 /*
62242 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
62243 index 5a710b9..0b0dab9 100644
62244 --- a/include/linux/preempt.h
62245 +++ b/include/linux/preempt.h
62246 @@ -126,7 +126,7 @@ struct preempt_ops {
62247 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
62248 void (*sched_out)(struct preempt_notifier *notifier,
62249 struct task_struct *next);
62250 -};
62251 +} __no_const;
62252
62253 /**
62254 * preempt_notifier - key for installing preemption notifiers
62255 diff --git a/include/linux/printk.h b/include/linux/printk.h
62256 index 0525927..a5388b6 100644
62257 --- a/include/linux/printk.h
62258 +++ b/include/linux/printk.h
62259 @@ -94,6 +94,8 @@ void early_printk(const char *fmt, ...);
62260 extern int printk_needs_cpu(int cpu);
62261 extern void printk_tick(void);
62262
62263 +extern int kptr_restrict;
62264 +
62265 #ifdef CONFIG_PRINTK
62266 asmlinkage __printf(1, 0)
62267 int vprintk(const char *fmt, va_list args);
62268 @@ -117,7 +119,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
62269
62270 extern int printk_delay_msec;
62271 extern int dmesg_restrict;
62272 -extern int kptr_restrict;
62273
62274 void log_buf_kexec_setup(void);
62275 void __init setup_log_buf(int early);
62276 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
62277 index 85c5073..51fac8b 100644
62278 --- a/include/linux/proc_fs.h
62279 +++ b/include/linux/proc_fs.h
62280 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
62281 return proc_create_data(name, mode, parent, proc_fops, NULL);
62282 }
62283
62284 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
62285 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
62286 +{
62287 +#ifdef CONFIG_GRKERNSEC_PROC_USER
62288 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
62289 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62290 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
62291 +#else
62292 + return proc_create_data(name, mode, parent, proc_fops, NULL);
62293 +#endif
62294 +}
62295 +
62296 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
62297 umode_t mode, struct proc_dir_entry *base,
62298 read_proc_t *read_proc, void * data)
62299 @@ -258,7 +270,7 @@ union proc_op {
62300 int (*proc_show)(struct seq_file *m,
62301 struct pid_namespace *ns, struct pid *pid,
62302 struct task_struct *task);
62303 -};
62304 +} __no_const;
62305
62306 struct ctl_table_header;
62307 struct ctl_table;
62308 diff --git a/include/linux/random.h b/include/linux/random.h
62309 index 8f74538..02a1012 100644
62310 --- a/include/linux/random.h
62311 +++ b/include/linux/random.h
62312 @@ -69,12 +69,17 @@ void srandom32(u32 seed);
62313
62314 u32 prandom32(struct rnd_state *);
62315
62316 +static inline unsigned long pax_get_random_long(void)
62317 +{
62318 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
62319 +}
62320 +
62321 /*
62322 * Handle minimum values for seeds
62323 */
62324 static inline u32 __seed(u32 x, u32 m)
62325 {
62326 - return (x < m) ? x + m : x;
62327 + return (x <= m) ? x + m + 1 : x;
62328 }
62329
62330 /**
62331 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
62332 index e0879a7..a12f962 100644
62333 --- a/include/linux/reboot.h
62334 +++ b/include/linux/reboot.h
62335 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
62336 * Architecture-specific implementations of sys_reboot commands.
62337 */
62338
62339 -extern void machine_restart(char *cmd);
62340 -extern void machine_halt(void);
62341 -extern void machine_power_off(void);
62342 +extern void machine_restart(char *cmd) __noreturn;
62343 +extern void machine_halt(void) __noreturn;
62344 +extern void machine_power_off(void) __noreturn;
62345
62346 extern void machine_shutdown(void);
62347 struct pt_regs;
62348 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
62349 */
62350
62351 extern void kernel_restart_prepare(char *cmd);
62352 -extern void kernel_restart(char *cmd);
62353 -extern void kernel_halt(void);
62354 -extern void kernel_power_off(void);
62355 +extern void kernel_restart(char *cmd) __noreturn;
62356 +extern void kernel_halt(void) __noreturn;
62357 +extern void kernel_power_off(void) __noreturn;
62358
62359 extern int C_A_D; /* for sysctl */
62360 void ctrl_alt_del(void);
62361 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
62362 * Emergency restart, callable from an interrupt handler.
62363 */
62364
62365 -extern void emergency_restart(void);
62366 +extern void emergency_restart(void) __noreturn;
62367 #include <asm/emergency-restart.h>
62368
62369 #endif
62370 diff --git a/include/linux/relay.h b/include/linux/relay.h
62371 index 91cacc3..b55ff74 100644
62372 --- a/include/linux/relay.h
62373 +++ b/include/linux/relay.h
62374 @@ -160,7 +160,7 @@ struct rchan_callbacks
62375 * The callback should return 0 if successful, negative if not.
62376 */
62377 int (*remove_buf_file)(struct dentry *dentry);
62378 -};
62379 +} __no_const;
62380
62381 /*
62382 * CONFIG_RELAY kernel API, kernel/relay.c
62383 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
62384 index 6fdf027..ff72610 100644
62385 --- a/include/linux/rfkill.h
62386 +++ b/include/linux/rfkill.h
62387 @@ -147,6 +147,7 @@ struct rfkill_ops {
62388 void (*query)(struct rfkill *rfkill, void *data);
62389 int (*set_block)(void *data, bool blocked);
62390 };
62391 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
62392
62393 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
62394 /**
62395 diff --git a/include/linux/rio.h b/include/linux/rio.h
62396 index 4d50611..c6858a2 100644
62397 --- a/include/linux/rio.h
62398 +++ b/include/linux/rio.h
62399 @@ -315,7 +315,7 @@ struct rio_ops {
62400 int mbox, void *buffer, size_t len);
62401 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
62402 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
62403 -};
62404 +} __no_const;
62405
62406 #define RIO_RESOURCE_MEM 0x00000100
62407 #define RIO_RESOURCE_DOORBELL 0x00000200
62408 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
62409 index fd07c45..4676b8e 100644
62410 --- a/include/linux/rmap.h
62411 +++ b/include/linux/rmap.h
62412 @@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
62413 void anon_vma_init(void); /* create anon_vma_cachep */
62414 int anon_vma_prepare(struct vm_area_struct *);
62415 void unlink_anon_vmas(struct vm_area_struct *);
62416 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
62417 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
62418 void anon_vma_moveto_tail(struct vm_area_struct *);
62419 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
62420 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
62421
62422 static inline void anon_vma_merge(struct vm_area_struct *vma,
62423 struct vm_area_struct *next)
62424 diff --git a/include/linux/sched.h b/include/linux/sched.h
62425 index 81a173c..85ccd8f 100644
62426 --- a/include/linux/sched.h
62427 +++ b/include/linux/sched.h
62428 @@ -100,6 +100,7 @@ struct bio_list;
62429 struct fs_struct;
62430 struct perf_event_context;
62431 struct blk_plug;
62432 +struct linux_binprm;
62433
62434 /*
62435 * List of flags we want to share for kernel threads,
62436 @@ -382,10 +383,13 @@ struct user_namespace;
62437 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
62438
62439 extern int sysctl_max_map_count;
62440 +extern unsigned long sysctl_heap_stack_gap;
62441
62442 #include <linux/aio.h>
62443
62444 #ifdef CONFIG_MMU
62445 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
62446 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
62447 extern void arch_pick_mmap_layout(struct mm_struct *mm);
62448 extern unsigned long
62449 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
62450 @@ -643,6 +647,17 @@ struct signal_struct {
62451 #ifdef CONFIG_TASKSTATS
62452 struct taskstats *stats;
62453 #endif
62454 +
62455 +#ifdef CONFIG_GRKERNSEC
62456 + u32 curr_ip;
62457 + u32 saved_ip;
62458 + u32 gr_saddr;
62459 + u32 gr_daddr;
62460 + u16 gr_sport;
62461 + u16 gr_dport;
62462 + u8 used_accept:1;
62463 +#endif
62464 +
62465 #ifdef CONFIG_AUDIT
62466 unsigned audit_tty;
62467 struct tty_audit_buf *tty_audit_buf;
62468 @@ -726,6 +741,11 @@ struct user_struct {
62469 struct key *session_keyring; /* UID's default session keyring */
62470 #endif
62471
62472 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
62473 + unsigned int banned;
62474 + unsigned long ban_expires;
62475 +#endif
62476 +
62477 /* Hash table maintenance information */
62478 struct hlist_node uidhash_node;
62479 uid_t uid;
62480 @@ -1386,8 +1406,8 @@ struct task_struct {
62481 struct list_head thread_group;
62482
62483 struct completion *vfork_done; /* for vfork() */
62484 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
62485 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
62486 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
62487 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
62488
62489 cputime_t utime, stime, utimescaled, stimescaled;
62490 cputime_t gtime;
62491 @@ -1403,13 +1423,6 @@ struct task_struct {
62492 struct task_cputime cputime_expires;
62493 struct list_head cpu_timers[3];
62494
62495 -/* process credentials */
62496 - const struct cred __rcu *real_cred; /* objective and real subjective task
62497 - * credentials (COW) */
62498 - const struct cred __rcu *cred; /* effective (overridable) subjective task
62499 - * credentials (COW) */
62500 - struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
62501 -
62502 char comm[TASK_COMM_LEN]; /* executable name excluding path
62503 - access with [gs]et_task_comm (which lock
62504 it with task_lock())
62505 @@ -1426,8 +1439,16 @@ struct task_struct {
62506 #endif
62507 /* CPU-specific state of this task */
62508 struct thread_struct thread;
62509 +/* thread_info moved to task_struct */
62510 +#ifdef CONFIG_X86
62511 + struct thread_info tinfo;
62512 +#endif
62513 /* filesystem information */
62514 struct fs_struct *fs;
62515 +
62516 + const struct cred __rcu *cred; /* effective (overridable) subjective task
62517 + * credentials (COW) */
62518 +
62519 /* open file information */
62520 struct files_struct *files;
62521 /* namespaces */
62522 @@ -1469,6 +1490,11 @@ struct task_struct {
62523 struct rt_mutex_waiter *pi_blocked_on;
62524 #endif
62525
62526 +/* process credentials */
62527 + const struct cred __rcu *real_cred; /* objective and real subjective task
62528 + * credentials (COW) */
62529 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
62530 +
62531 #ifdef CONFIG_DEBUG_MUTEXES
62532 /* mutex deadlock detection */
62533 struct mutex_waiter *blocked_on;
62534 @@ -1585,6 +1611,27 @@ struct task_struct {
62535 unsigned long default_timer_slack_ns;
62536
62537 struct list_head *scm_work_list;
62538 +
62539 +#ifdef CONFIG_GRKERNSEC
62540 + /* grsecurity */
62541 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62542 + u64 exec_id;
62543 +#endif
62544 +#ifdef CONFIG_GRKERNSEC_SETXID
62545 + const struct cred *delayed_cred;
62546 +#endif
62547 + struct dentry *gr_chroot_dentry;
62548 + struct acl_subject_label *acl;
62549 + struct acl_role_label *role;
62550 + struct file *exec_file;
62551 + u16 acl_role_id;
62552 + /* is this the task that authenticated to the special role */
62553 + u8 acl_sp_role;
62554 + u8 is_writable;
62555 + u8 brute;
62556 + u8 gr_is_chrooted;
62557 +#endif
62558 +
62559 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
62560 /* Index of current stored address in ret_stack */
62561 int curr_ret_stack;
62562 @@ -1619,6 +1666,51 @@ struct task_struct {
62563 #endif
62564 };
62565
62566 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
62567 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
62568 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
62569 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
62570 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
62571 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
62572 +
62573 +#ifdef CONFIG_PAX_SOFTMODE
62574 +extern int pax_softmode;
62575 +#endif
62576 +
62577 +extern int pax_check_flags(unsigned long *);
62578 +
62579 +/* if tsk != current then task_lock must be held on it */
62580 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62581 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
62582 +{
62583 + if (likely(tsk->mm))
62584 + return tsk->mm->pax_flags;
62585 + else
62586 + return 0UL;
62587 +}
62588 +
62589 +/* if tsk != current then task_lock must be held on it */
62590 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
62591 +{
62592 + if (likely(tsk->mm)) {
62593 + tsk->mm->pax_flags = flags;
62594 + return 0;
62595 + }
62596 + return -EINVAL;
62597 +}
62598 +#endif
62599 +
62600 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
62601 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
62602 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
62603 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
62604 +#endif
62605 +
62606 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
62607 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
62608 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
62609 +extern __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type);
62610 +
62611 /* Future-safe accessor for struct task_struct's cpus_allowed. */
62612 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
62613
62614 @@ -2138,7 +2230,9 @@ void yield(void);
62615 extern struct exec_domain default_exec_domain;
62616
62617 union thread_union {
62618 +#ifndef CONFIG_X86
62619 struct thread_info thread_info;
62620 +#endif
62621 unsigned long stack[THREAD_SIZE/sizeof(long)];
62622 };
62623
62624 @@ -2171,6 +2265,7 @@ extern struct pid_namespace init_pid_ns;
62625 */
62626
62627 extern struct task_struct *find_task_by_vpid(pid_t nr);
62628 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
62629 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
62630 struct pid_namespace *ns);
62631
62632 @@ -2314,7 +2409,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
62633 extern void exit_itimers(struct signal_struct *);
62634 extern void flush_itimer_signals(void);
62635
62636 -extern void do_group_exit(int);
62637 +extern __noreturn void do_group_exit(int);
62638
62639 extern void daemonize(const char *, ...);
62640 extern int allow_signal(int);
62641 @@ -2515,13 +2610,17 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
62642
62643 #endif
62644
62645 -static inline int object_is_on_stack(void *obj)
62646 +static inline int object_starts_on_stack(void *obj)
62647 {
62648 - void *stack = task_stack_page(current);
62649 + const void *stack = task_stack_page(current);
62650
62651 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
62652 }
62653
62654 +#ifdef CONFIG_PAX_USERCOPY
62655 +extern int object_is_on_stack(const void *obj, unsigned long len);
62656 +#endif
62657 +
62658 extern void thread_info_cache_init(void);
62659
62660 #ifdef CONFIG_DEBUG_STACK_USAGE
62661 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
62662 index 899fbb4..1cb4138 100644
62663 --- a/include/linux/screen_info.h
62664 +++ b/include/linux/screen_info.h
62665 @@ -43,7 +43,8 @@ struct screen_info {
62666 __u16 pages; /* 0x32 */
62667 __u16 vesa_attributes; /* 0x34 */
62668 __u32 capabilities; /* 0x36 */
62669 - __u8 _reserved[6]; /* 0x3a */
62670 + __u16 vesapm_size; /* 0x3a */
62671 + __u8 _reserved[4]; /* 0x3c */
62672 } __attribute__((packed));
62673
62674 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
62675 diff --git a/include/linux/security.h b/include/linux/security.h
62676 index 673afbb..2b7454b 100644
62677 --- a/include/linux/security.h
62678 +++ b/include/linux/security.h
62679 @@ -26,6 +26,7 @@
62680 #include <linux/capability.h>
62681 #include <linux/slab.h>
62682 #include <linux/err.h>
62683 +#include <linux/grsecurity.h>
62684
62685 struct linux_binprm;
62686 struct cred;
62687 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
62688 index fc61854..d7c490b 100644
62689 --- a/include/linux/seq_file.h
62690 +++ b/include/linux/seq_file.h
62691 @@ -25,6 +25,9 @@ struct seq_file {
62692 struct mutex lock;
62693 const struct seq_operations *op;
62694 int poll_event;
62695 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62696 + u64 exec_id;
62697 +#endif
62698 void *private;
62699 };
62700
62701 @@ -34,6 +37,7 @@ struct seq_operations {
62702 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
62703 int (*show) (struct seq_file *m, void *v);
62704 };
62705 +typedef struct seq_operations __no_const seq_operations_no_const;
62706
62707 #define SEQ_SKIP 1
62708
62709 diff --git a/include/linux/shm.h b/include/linux/shm.h
62710 index 92808b8..c28cac4 100644
62711 --- a/include/linux/shm.h
62712 +++ b/include/linux/shm.h
62713 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
62714
62715 /* The task created the shm object. NULL if the task is dead. */
62716 struct task_struct *shm_creator;
62717 +#ifdef CONFIG_GRKERNSEC
62718 + time_t shm_createtime;
62719 + pid_t shm_lapid;
62720 +#endif
62721 };
62722
62723 /* shm_mode upper byte flags */
62724 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
62725 index c168907..c7756db 100644
62726 --- a/include/linux/skbuff.h
62727 +++ b/include/linux/skbuff.h
62728 @@ -666,7 +666,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
62729 */
62730 static inline int skb_queue_empty(const struct sk_buff_head *list)
62731 {
62732 - return list->next == (struct sk_buff *)list;
62733 + return list->next == (const struct sk_buff *)list;
62734 }
62735
62736 /**
62737 @@ -679,7 +679,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
62738 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
62739 const struct sk_buff *skb)
62740 {
62741 - return skb->next == (struct sk_buff *)list;
62742 + return skb->next == (const struct sk_buff *)list;
62743 }
62744
62745 /**
62746 @@ -692,7 +692,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
62747 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
62748 const struct sk_buff *skb)
62749 {
62750 - return skb->prev == (struct sk_buff *)list;
62751 + return skb->prev == (const struct sk_buff *)list;
62752 }
62753
62754 /**
62755 @@ -1587,7 +1587,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
62756 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
62757 */
62758 #ifndef NET_SKB_PAD
62759 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
62760 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
62761 #endif
62762
62763 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
62764 diff --git a/include/linux/slab.h b/include/linux/slab.h
62765 index a595dce..c403597 100644
62766 --- a/include/linux/slab.h
62767 +++ b/include/linux/slab.h
62768 @@ -11,12 +11,20 @@
62769
62770 #include <linux/gfp.h>
62771 #include <linux/types.h>
62772 +#include <linux/err.h>
62773
62774 /*
62775 * Flags to pass to kmem_cache_create().
62776 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
62777 */
62778 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
62779 +
62780 +#ifdef CONFIG_PAX_USERCOPY
62781 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
62782 +#else
62783 +#define SLAB_USERCOPY 0x00000000UL
62784 +#endif
62785 +
62786 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
62787 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
62788 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
62789 @@ -87,10 +95,13 @@
62790 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
62791 * Both make kfree a no-op.
62792 */
62793 -#define ZERO_SIZE_PTR ((void *)16)
62794 +#define ZERO_SIZE_PTR \
62795 +({ \
62796 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
62797 + (void *)(-MAX_ERRNO-1L); \
62798 +})
62799
62800 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
62801 - (unsigned long)ZERO_SIZE_PTR)
62802 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
62803
62804 /*
62805 * struct kmem_cache related prototypes
62806 @@ -161,6 +172,7 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
62807 void kfree(const void *);
62808 void kzfree(const void *);
62809 size_t ksize(const void *);
62810 +void check_object_size(const void *ptr, unsigned long n, bool to);
62811
62812 /*
62813 * Allocator specific definitions. These are mainly used to establish optimized
62814 @@ -240,6 +252,7 @@ size_t ksize(const void *);
62815 * for general use, and so are not documented here. For a full list of
62816 * potential flags, always refer to linux/gfp.h.
62817 */
62818 +static void *kmalloc_array(size_t n, size_t size, gfp_t flags) __size_overflow(1, 2);
62819 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
62820 {
62821 if (size != 0 && n > ULONG_MAX / size)
62822 @@ -298,7 +311,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
62823 */
62824 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
62825 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
62826 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
62827 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
62828 #define kmalloc_track_caller(size, flags) \
62829 __kmalloc_track_caller(size, flags, _RET_IP_)
62830 #else
62831 @@ -317,7 +330,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
62832 */
62833 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
62834 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
62835 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
62836 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
62837 #define kmalloc_node_track_caller(size, flags, node) \
62838 __kmalloc_node_track_caller(size, flags, node, \
62839 _RET_IP_)
62840 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
62841 index fbd1117..d4d8ef8 100644
62842 --- a/include/linux/slab_def.h
62843 +++ b/include/linux/slab_def.h
62844 @@ -66,10 +66,10 @@ struct kmem_cache {
62845 unsigned long node_allocs;
62846 unsigned long node_frees;
62847 unsigned long node_overflow;
62848 - atomic_t allochit;
62849 - atomic_t allocmiss;
62850 - atomic_t freehit;
62851 - atomic_t freemiss;
62852 + atomic_unchecked_t allochit;
62853 + atomic_unchecked_t allocmiss;
62854 + atomic_unchecked_t freehit;
62855 + atomic_unchecked_t freemiss;
62856
62857 /*
62858 * If debugging is enabled, then the allocator can add additional
62859 @@ -107,7 +107,7 @@ struct cache_sizes {
62860 extern struct cache_sizes malloc_sizes[];
62861
62862 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
62863 -void *__kmalloc(size_t size, gfp_t flags);
62864 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
62865
62866 #ifdef CONFIG_TRACING
62867 extern void *kmem_cache_alloc_trace(size_t size,
62868 @@ -160,7 +160,7 @@ found:
62869 }
62870
62871 #ifdef CONFIG_NUMA
62872 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
62873 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
62874 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
62875
62876 #ifdef CONFIG_TRACING
62877 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
62878 index 0ec00b3..39cb7fc 100644
62879 --- a/include/linux/slob_def.h
62880 +++ b/include/linux/slob_def.h
62881 @@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
62882 return kmem_cache_alloc_node(cachep, flags, -1);
62883 }
62884
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
62888 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
62889 {
62890 @@ -29,6 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
62891 return __kmalloc_node(size, flags, -1);
62892 }
62893
62894 +static __always_inline void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
62895 static __always_inline void *__kmalloc(size_t size, gfp_t flags)
62896 {
62897 return kmalloc(size, flags);
62898 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
62899 index c2f8c8b..be9e036 100644
62900 --- a/include/linux/slub_def.h
62901 +++ b/include/linux/slub_def.h
62902 @@ -92,7 +92,7 @@ struct kmem_cache {
62903 struct kmem_cache_order_objects max;
62904 struct kmem_cache_order_objects min;
62905 gfp_t allocflags; /* gfp flags to use on each alloc */
62906 - int refcount; /* Refcount for slab cache destroy */
62907 + atomic_t refcount; /* Refcount for slab cache destroy */
62908 void (*ctor)(void *);
62909 int inuse; /* Offset to metadata */
62910 int align; /* Alignment */
62911 @@ -153,6 +153,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
62912 * Sorry that the following has to be that ugly but some versions of GCC
62913 * have trouble with constant propagation and loops.
62914 */
62915 +static __always_inline int kmalloc_index(size_t size) __size_overflow(1);
62916 static __always_inline int kmalloc_index(size_t size)
62917 {
62918 if (!size)
62919 @@ -218,7 +219,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
62920 }
62921
62922 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
62923 -void *__kmalloc(size_t size, gfp_t flags);
62924 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
62925
62926 static __always_inline void *
62927 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
62928 @@ -259,6 +260,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
62929 }
62930 #endif
62931
62932 +static __always_inline void *kmalloc_large(size_t size, gfp_t flags) __size_overflow(1);
62933 static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
62934 {
62935 unsigned int order = get_order(size);
62936 @@ -284,7 +286,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
62937 }
62938
62939 #ifdef CONFIG_NUMA
62940 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
62941 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
62942 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
62943
62944 #ifdef CONFIG_TRACING
62945 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
62946 index de8832d..0147b46 100644
62947 --- a/include/linux/sonet.h
62948 +++ b/include/linux/sonet.h
62949 @@ -61,7 +61,7 @@ struct sonet_stats {
62950 #include <linux/atomic.h>
62951
62952 struct k_sonet_stats {
62953 -#define __HANDLE_ITEM(i) atomic_t i
62954 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
62955 __SONET_ITEMS
62956 #undef __HANDLE_ITEM
62957 };
62958 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
62959 index 523547e..2cb7140 100644
62960 --- a/include/linux/sunrpc/clnt.h
62961 +++ b/include/linux/sunrpc/clnt.h
62962 @@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
62963 {
62964 switch (sap->sa_family) {
62965 case AF_INET:
62966 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
62967 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
62968 case AF_INET6:
62969 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
62970 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
62971 }
62972 return 0;
62973 }
62974 @@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
62975 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
62976 const struct sockaddr *src)
62977 {
62978 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
62979 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
62980 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
62981
62982 dsin->sin_family = ssin->sin_family;
62983 @@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
62984 if (sa->sa_family != AF_INET6)
62985 return 0;
62986
62987 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
62988 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
62989 }
62990
62991 #endif /* __KERNEL__ */
62992 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
62993 index dc0c3cc..8503fb6 100644
62994 --- a/include/linux/sunrpc/sched.h
62995 +++ b/include/linux/sunrpc/sched.h
62996 @@ -106,6 +106,7 @@ struct rpc_call_ops {
62997 void (*rpc_count_stats)(struct rpc_task *, void *);
62998 void (*rpc_release)(void *);
62999 };
63000 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
63001
63002 struct rpc_task_setup {
63003 struct rpc_task *task;
63004 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
63005 index 0b8e3e6..33e0a01 100644
63006 --- a/include/linux/sunrpc/svc_rdma.h
63007 +++ b/include/linux/sunrpc/svc_rdma.h
63008 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
63009 extern unsigned int svcrdma_max_requests;
63010 extern unsigned int svcrdma_max_req_size;
63011
63012 -extern atomic_t rdma_stat_recv;
63013 -extern atomic_t rdma_stat_read;
63014 -extern atomic_t rdma_stat_write;
63015 -extern atomic_t rdma_stat_sq_starve;
63016 -extern atomic_t rdma_stat_rq_starve;
63017 -extern atomic_t rdma_stat_rq_poll;
63018 -extern atomic_t rdma_stat_rq_prod;
63019 -extern atomic_t rdma_stat_sq_poll;
63020 -extern atomic_t rdma_stat_sq_prod;
63021 +extern atomic_unchecked_t rdma_stat_recv;
63022 +extern atomic_unchecked_t rdma_stat_read;
63023 +extern atomic_unchecked_t rdma_stat_write;
63024 +extern atomic_unchecked_t rdma_stat_sq_starve;
63025 +extern atomic_unchecked_t rdma_stat_rq_starve;
63026 +extern atomic_unchecked_t rdma_stat_rq_poll;
63027 +extern atomic_unchecked_t rdma_stat_rq_prod;
63028 +extern atomic_unchecked_t rdma_stat_sq_poll;
63029 +extern atomic_unchecked_t rdma_stat_sq_prod;
63030
63031 #define RPCRDMA_VERSION 1
63032
63033 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
63034 index c34b4c8..a65b67d 100644
63035 --- a/include/linux/sysctl.h
63036 +++ b/include/linux/sysctl.h
63037 @@ -155,7 +155,11 @@ enum
63038 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
63039 };
63040
63041 -
63042 +#ifdef CONFIG_PAX_SOFTMODE
63043 +enum {
63044 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
63045 +};
63046 +#endif
63047
63048 /* CTL_VM names: */
63049 enum
63050 @@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
63051
63052 extern int proc_dostring(struct ctl_table *, int,
63053 void __user *, size_t *, loff_t *);
63054 +extern int proc_dostring_modpriv(struct ctl_table *, int,
63055 + void __user *, size_t *, loff_t *);
63056 extern int proc_dointvec(struct ctl_table *, int,
63057 void __user *, size_t *, loff_t *);
63058 extern int proc_dointvec_minmax(struct ctl_table *, int,
63059 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
63060 index ff7dc08..893e1bd 100644
63061 --- a/include/linux/tty_ldisc.h
63062 +++ b/include/linux/tty_ldisc.h
63063 @@ -148,7 +148,7 @@ struct tty_ldisc_ops {
63064
63065 struct module *owner;
63066
63067 - int refcount;
63068 + atomic_t refcount;
63069 };
63070
63071 struct tty_ldisc {
63072 diff --git a/include/linux/types.h b/include/linux/types.h
63073 index 7f480db..175c256 100644
63074 --- a/include/linux/types.h
63075 +++ b/include/linux/types.h
63076 @@ -220,10 +220,26 @@ typedef struct {
63077 int counter;
63078 } atomic_t;
63079
63080 +#ifdef CONFIG_PAX_REFCOUNT
63081 +typedef struct {
63082 + int counter;
63083 +} atomic_unchecked_t;
63084 +#else
63085 +typedef atomic_t atomic_unchecked_t;
63086 +#endif
63087 +
63088 #ifdef CONFIG_64BIT
63089 typedef struct {
63090 long counter;
63091 } atomic64_t;
63092 +
63093 +#ifdef CONFIG_PAX_REFCOUNT
63094 +typedef struct {
63095 + long counter;
63096 +} atomic64_unchecked_t;
63097 +#else
63098 +typedef atomic64_t atomic64_unchecked_t;
63099 +#endif
63100 #endif
63101
63102 struct list_head {
63103 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
63104 index 5ca0951..ab496a5 100644
63105 --- a/include/linux/uaccess.h
63106 +++ b/include/linux/uaccess.h
63107 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
63108 long ret; \
63109 mm_segment_t old_fs = get_fs(); \
63110 \
63111 - set_fs(KERNEL_DS); \
63112 pagefault_disable(); \
63113 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
63114 - pagefault_enable(); \
63115 + set_fs(KERNEL_DS); \
63116 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
63117 set_fs(old_fs); \
63118 + pagefault_enable(); \
63119 ret; \
63120 })
63121
63122 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
63123 index 99c1b4d..bb94261 100644
63124 --- a/include/linux/unaligned/access_ok.h
63125 +++ b/include/linux/unaligned/access_ok.h
63126 @@ -6,32 +6,32 @@
63127
63128 static inline u16 get_unaligned_le16(const void *p)
63129 {
63130 - return le16_to_cpup((__le16 *)p);
63131 + return le16_to_cpup((const __le16 *)p);
63132 }
63133
63134 static inline u32 get_unaligned_le32(const void *p)
63135 {
63136 - return le32_to_cpup((__le32 *)p);
63137 + return le32_to_cpup((const __le32 *)p);
63138 }
63139
63140 static inline u64 get_unaligned_le64(const void *p)
63141 {
63142 - return le64_to_cpup((__le64 *)p);
63143 + return le64_to_cpup((const __le64 *)p);
63144 }
63145
63146 static inline u16 get_unaligned_be16(const void *p)
63147 {
63148 - return be16_to_cpup((__be16 *)p);
63149 + return be16_to_cpup((const __be16 *)p);
63150 }
63151
63152 static inline u32 get_unaligned_be32(const void *p)
63153 {
63154 - return be32_to_cpup((__be32 *)p);
63155 + return be32_to_cpup((const __be32 *)p);
63156 }
63157
63158 static inline u64 get_unaligned_be64(const void *p)
63159 {
63160 - return be64_to_cpup((__be64 *)p);
63161 + return be64_to_cpup((const __be64 *)p);
63162 }
63163
63164 static inline void put_unaligned_le16(u16 val, void *p)
63165 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
63166 index 547e59c..db6ad19 100644
63167 --- a/include/linux/usb/renesas_usbhs.h
63168 +++ b/include/linux/usb/renesas_usbhs.h
63169 @@ -39,7 +39,7 @@ enum {
63170 */
63171 struct renesas_usbhs_driver_callback {
63172 int (*notify_hotplug)(struct platform_device *pdev);
63173 -};
63174 +} __no_const;
63175
63176 /*
63177 * callback functions for platform
63178 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
63179 * VBUS control is needed for Host
63180 */
63181 int (*set_vbus)(struct platform_device *pdev, int enable);
63182 -};
63183 +} __no_const;
63184
63185 /*
63186 * parameters for renesas usbhs
63187 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
63188 index 6f8fbcf..8259001 100644
63189 --- a/include/linux/vermagic.h
63190 +++ b/include/linux/vermagic.h
63191 @@ -25,9 +25,35 @@
63192 #define MODULE_ARCH_VERMAGIC ""
63193 #endif
63194
63195 +#ifdef CONFIG_PAX_REFCOUNT
63196 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
63197 +#else
63198 +#define MODULE_PAX_REFCOUNT ""
63199 +#endif
63200 +
63201 +#ifdef CONSTIFY_PLUGIN
63202 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
63203 +#else
63204 +#define MODULE_CONSTIFY_PLUGIN ""
63205 +#endif
63206 +
63207 +#ifdef STACKLEAK_PLUGIN
63208 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
63209 +#else
63210 +#define MODULE_STACKLEAK_PLUGIN ""
63211 +#endif
63212 +
63213 +#ifdef CONFIG_GRKERNSEC
63214 +#define MODULE_GRSEC "GRSEC "
63215 +#else
63216 +#define MODULE_GRSEC ""
63217 +#endif
63218 +
63219 #define VERMAGIC_STRING \
63220 UTS_RELEASE " " \
63221 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
63222 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
63223 - MODULE_ARCH_VERMAGIC
63224 + MODULE_ARCH_VERMAGIC \
63225 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
63226 + MODULE_GRSEC
63227
63228 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
63229 index dcdfc2b..ec79ab5 100644
63230 --- a/include/linux/vmalloc.h
63231 +++ b/include/linux/vmalloc.h
63232 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
63233 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
63234 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
63235 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
63236 +
63237 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
63238 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
63239 +#endif
63240 +
63241 /* bits [20..32] reserved for arch specific ioremap internals */
63242
63243 /*
63244 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
63245 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
63246 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
63247 unsigned long start, unsigned long end, gfp_t gfp_mask,
63248 - pgprot_t prot, int node, void *caller);
63249 + pgprot_t prot, int node, void *caller) __size_overflow(1);
63250 extern void vfree(const void *addr);
63251
63252 extern void *vmap(struct page **pages, unsigned int count,
63253 @@ -123,8 +128,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
63254 extern void free_vm_area(struct vm_struct *area);
63255
63256 /* for /dev/kmem */
63257 -extern long vread(char *buf, char *addr, unsigned long count);
63258 -extern long vwrite(char *buf, char *addr, unsigned long count);
63259 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
63260 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
63261
63262 /*
63263 * Internals. Dont't use..
63264 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
63265 index 65efb92..137adbb 100644
63266 --- a/include/linux/vmstat.h
63267 +++ b/include/linux/vmstat.h
63268 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
63269 /*
63270 * Zone based page accounting with per cpu differentials.
63271 */
63272 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63273 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63274
63275 static inline void zone_page_state_add(long x, struct zone *zone,
63276 enum zone_stat_item item)
63277 {
63278 - atomic_long_add(x, &zone->vm_stat[item]);
63279 - atomic_long_add(x, &vm_stat[item]);
63280 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
63281 + atomic_long_add_unchecked(x, &vm_stat[item]);
63282 }
63283
63284 static inline unsigned long global_page_state(enum zone_stat_item item)
63285 {
63286 - long x = atomic_long_read(&vm_stat[item]);
63287 + long x = atomic_long_read_unchecked(&vm_stat[item]);
63288 #ifdef CONFIG_SMP
63289 if (x < 0)
63290 x = 0;
63291 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
63292 static inline unsigned long zone_page_state(struct zone *zone,
63293 enum zone_stat_item item)
63294 {
63295 - long x = atomic_long_read(&zone->vm_stat[item]);
63296 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
63297 #ifdef CONFIG_SMP
63298 if (x < 0)
63299 x = 0;
63300 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
63301 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
63302 enum zone_stat_item item)
63303 {
63304 - long x = atomic_long_read(&zone->vm_stat[item]);
63305 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
63306
63307 #ifdef CONFIG_SMP
63308 int cpu;
63309 @@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
63310
63311 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
63312 {
63313 - atomic_long_inc(&zone->vm_stat[item]);
63314 - atomic_long_inc(&vm_stat[item]);
63315 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
63316 + atomic_long_inc_unchecked(&vm_stat[item]);
63317 }
63318
63319 static inline void __inc_zone_page_state(struct page *page,
63320 @@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
63321
63322 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
63323 {
63324 - atomic_long_dec(&zone->vm_stat[item]);
63325 - atomic_long_dec(&vm_stat[item]);
63326 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
63327 + atomic_long_dec_unchecked(&vm_stat[item]);
63328 }
63329
63330 static inline void __dec_zone_page_state(struct page *page,
63331 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
63332 index e5d1220..ef6e406 100644
63333 --- a/include/linux/xattr.h
63334 +++ b/include/linux/xattr.h
63335 @@ -57,6 +57,11 @@
63336 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
63337 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
63338
63339 +/* User namespace */
63340 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
63341 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
63342 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
63343 +
63344 #ifdef __KERNEL__
63345
63346 #include <linux/types.h>
63347 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
63348 index 4aeff96..b378cdc 100644
63349 --- a/include/media/saa7146_vv.h
63350 +++ b/include/media/saa7146_vv.h
63351 @@ -163,7 +163,7 @@ struct saa7146_ext_vv
63352 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
63353
63354 /* the extension can override this */
63355 - struct v4l2_ioctl_ops ops;
63356 + v4l2_ioctl_ops_no_const ops;
63357 /* pointer to the saa7146 core ops */
63358 const struct v4l2_ioctl_ops *core_ops;
63359
63360 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
63361 index 96d2221..2292f89 100644
63362 --- a/include/media/v4l2-dev.h
63363 +++ b/include/media/v4l2-dev.h
63364 @@ -56,7 +56,7 @@ int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);
63365
63366
63367 struct v4l2_file_operations {
63368 - struct module *owner;
63369 + struct module * const owner;
63370 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
63371 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
63372 unsigned int (*poll) (struct file *, struct poll_table_struct *);
63373 @@ -71,6 +71,7 @@ struct v4l2_file_operations {
63374 int (*open) (struct file *);
63375 int (*release) (struct file *);
63376 };
63377 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
63378
63379 /*
63380 * Newer version of video_device, handled by videodev2.c
63381 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
63382 index 3cb939c..f23c6bb 100644
63383 --- a/include/media/v4l2-ioctl.h
63384 +++ b/include/media/v4l2-ioctl.h
63385 @@ -281,7 +281,7 @@ struct v4l2_ioctl_ops {
63386 long (*vidioc_default) (struct file *file, void *fh,
63387 bool valid_prio, int cmd, void *arg);
63388 };
63389 -
63390 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
63391
63392 /* v4l debugging and diagnostics */
63393
63394 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
63395 index 6db8ecf..8c23861 100644
63396 --- a/include/net/caif/caif_hsi.h
63397 +++ b/include/net/caif/caif_hsi.h
63398 @@ -98,7 +98,7 @@ struct cfhsi_drv {
63399 void (*rx_done_cb) (struct cfhsi_drv *drv);
63400 void (*wake_up_cb) (struct cfhsi_drv *drv);
63401 void (*wake_down_cb) (struct cfhsi_drv *drv);
63402 -};
63403 +} __no_const;
63404
63405 /* Structure implemented by HSI device. */
63406 struct cfhsi_dev {
63407 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
63408 index 9e5425b..8136ffc 100644
63409 --- a/include/net/caif/cfctrl.h
63410 +++ b/include/net/caif/cfctrl.h
63411 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
63412 void (*radioset_rsp)(void);
63413 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
63414 struct cflayer *client_layer);
63415 -};
63416 +} __no_const;
63417
63418 /* Link Setup Parameters for CAIF-Links. */
63419 struct cfctrl_link_param {
63420 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
63421 struct cfctrl {
63422 struct cfsrvl serv;
63423 struct cfctrl_rsp res;
63424 - atomic_t req_seq_no;
63425 - atomic_t rsp_seq_no;
63426 + atomic_unchecked_t req_seq_no;
63427 + atomic_unchecked_t rsp_seq_no;
63428 struct list_head list;
63429 /* Protects from simultaneous access to first_req list */
63430 spinlock_t info_list_lock;
63431 diff --git a/include/net/flow.h b/include/net/flow.h
63432 index 6c469db..7743b8e 100644
63433 --- a/include/net/flow.h
63434 +++ b/include/net/flow.h
63435 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
63436
63437 extern void flow_cache_flush(void);
63438 extern void flow_cache_flush_deferred(void);
63439 -extern atomic_t flow_cache_genid;
63440 +extern atomic_unchecked_t flow_cache_genid;
63441
63442 #endif
63443 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
63444 index b94765e..053f68b 100644
63445 --- a/include/net/inetpeer.h
63446 +++ b/include/net/inetpeer.h
63447 @@ -48,8 +48,8 @@ struct inet_peer {
63448 */
63449 union {
63450 struct {
63451 - atomic_t rid; /* Frag reception counter */
63452 - atomic_t ip_id_count; /* IP ID for the next packet */
63453 + atomic_unchecked_t rid; /* Frag reception counter */
63454 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
63455 __u32 tcp_ts;
63456 __u32 tcp_ts_stamp;
63457 };
63458 @@ -115,11 +115,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
63459 more++;
63460 inet_peer_refcheck(p);
63461 do {
63462 - old = atomic_read(&p->ip_id_count);
63463 + old = atomic_read_unchecked(&p->ip_id_count);
63464 new = old + more;
63465 if (!new)
63466 new = 1;
63467 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
63468 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
63469 return new;
63470 }
63471
63472 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
63473 index 10422ef..662570f 100644
63474 --- a/include/net/ip_fib.h
63475 +++ b/include/net/ip_fib.h
63476 @@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
63477
63478 #define FIB_RES_SADDR(net, res) \
63479 ((FIB_RES_NH(res).nh_saddr_genid == \
63480 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
63481 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
63482 FIB_RES_NH(res).nh_saddr : \
63483 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
63484 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
63485 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
63486 index 72522f0..6f03a2b 100644
63487 --- a/include/net/ip_vs.h
63488 +++ b/include/net/ip_vs.h
63489 @@ -510,7 +510,7 @@ struct ip_vs_conn {
63490 struct ip_vs_conn *control; /* Master control connection */
63491 atomic_t n_control; /* Number of controlled ones */
63492 struct ip_vs_dest *dest; /* real server */
63493 - atomic_t in_pkts; /* incoming packet counter */
63494 + atomic_unchecked_t in_pkts; /* incoming packet counter */
63495
63496 /* packet transmitter for different forwarding methods. If it
63497 mangles the packet, it must return NF_DROP or better NF_STOLEN,
63498 @@ -648,7 +648,7 @@ struct ip_vs_dest {
63499 __be16 port; /* port number of the server */
63500 union nf_inet_addr addr; /* IP address of the server */
63501 volatile unsigned flags; /* dest status flags */
63502 - atomic_t conn_flags; /* flags to copy to conn */
63503 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
63504 atomic_t weight; /* server weight */
63505
63506 atomic_t refcnt; /* reference counter */
63507 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
63508 index 69b610a..fe3962c 100644
63509 --- a/include/net/irda/ircomm_core.h
63510 +++ b/include/net/irda/ircomm_core.h
63511 @@ -51,7 +51,7 @@ typedef struct {
63512 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
63513 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
63514 struct ircomm_info *);
63515 -} call_t;
63516 +} __no_const call_t;
63517
63518 struct ircomm_cb {
63519 irda_queue_t queue;
63520 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
63521 index 59ba38bc..d515662 100644
63522 --- a/include/net/irda/ircomm_tty.h
63523 +++ b/include/net/irda/ircomm_tty.h
63524 @@ -35,6 +35,7 @@
63525 #include <linux/termios.h>
63526 #include <linux/timer.h>
63527 #include <linux/tty.h> /* struct tty_struct */
63528 +#include <asm/local.h>
63529
63530 #include <net/irda/irias_object.h>
63531 #include <net/irda/ircomm_core.h>
63532 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
63533 unsigned short close_delay;
63534 unsigned short closing_wait; /* time to wait before closing */
63535
63536 - int open_count;
63537 - int blocked_open; /* # of blocked opens */
63538 + local_t open_count;
63539 + local_t blocked_open; /* # of blocked opens */
63540
63541 /* Protect concurent access to :
63542 * o self->open_count
63543 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
63544 index cc7c197..9f2da2a 100644
63545 --- a/include/net/iucv/af_iucv.h
63546 +++ b/include/net/iucv/af_iucv.h
63547 @@ -141,7 +141,7 @@ struct iucv_sock {
63548 struct iucv_sock_list {
63549 struct hlist_head head;
63550 rwlock_t lock;
63551 - atomic_t autobind_name;
63552 + atomic_unchecked_t autobind_name;
63553 };
63554
63555 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
63556 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
63557 index 34c996f..bb3b4d4 100644
63558 --- a/include/net/neighbour.h
63559 +++ b/include/net/neighbour.h
63560 @@ -123,7 +123,7 @@ struct neigh_ops {
63561 void (*error_report)(struct neighbour *, struct sk_buff *);
63562 int (*output)(struct neighbour *, struct sk_buff *);
63563 int (*connected_output)(struct neighbour *, struct sk_buff *);
63564 -};
63565 +} __do_const;
63566
63567 struct pneigh_entry {
63568 struct pneigh_entry *next;
63569 diff --git a/include/net/netlink.h b/include/net/netlink.h
63570 index f394fe5..fd073f9 100644
63571 --- a/include/net/netlink.h
63572 +++ b/include/net/netlink.h
63573 @@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
63574 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
63575 {
63576 if (mark)
63577 - skb_trim(skb, (unsigned char *) mark - skb->data);
63578 + skb_trim(skb, (const unsigned char *) mark - skb->data);
63579 }
63580
63581 /**
63582 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
63583 index bbd023a..97c6d0d 100644
63584 --- a/include/net/netns/ipv4.h
63585 +++ b/include/net/netns/ipv4.h
63586 @@ -57,8 +57,8 @@ struct netns_ipv4 {
63587 unsigned int sysctl_ping_group_range[2];
63588 long sysctl_tcp_mem[3];
63589
63590 - atomic_t rt_genid;
63591 - atomic_t dev_addr_genid;
63592 + atomic_unchecked_t rt_genid;
63593 + atomic_unchecked_t dev_addr_genid;
63594
63595 #ifdef CONFIG_IP_MROUTE
63596 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
63597 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
63598 index a2ef814..31a8e3f 100644
63599 --- a/include/net/sctp/sctp.h
63600 +++ b/include/net/sctp/sctp.h
63601 @@ -318,9 +318,9 @@ do { \
63602
63603 #else /* SCTP_DEBUG */
63604
63605 -#define SCTP_DEBUG_PRINTK(whatever...)
63606 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
63607 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
63608 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
63609 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
63610 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
63611 #define SCTP_ENABLE_DEBUG
63612 #define SCTP_DISABLE_DEBUG
63613 #define SCTP_ASSERT(expr, str, func)
63614 diff --git a/include/net/sock.h b/include/net/sock.h
63615 index 5a0a58a..2e3d4d0 100644
63616 --- a/include/net/sock.h
63617 +++ b/include/net/sock.h
63618 @@ -302,7 +302,7 @@ struct sock {
63619 #ifdef CONFIG_RPS
63620 __u32 sk_rxhash;
63621 #endif
63622 - atomic_t sk_drops;
63623 + atomic_unchecked_t sk_drops;
63624 int sk_rcvbuf;
63625
63626 struct sk_filter __rcu *sk_filter;
63627 @@ -1691,7 +1691,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
63628 }
63629
63630 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
63631 - char __user *from, char *to,
63632 + char __user *from, unsigned char *to,
63633 int copy, int offset)
63634 {
63635 if (skb->ip_summed == CHECKSUM_NONE) {
63636 diff --git a/include/net/tcp.h b/include/net/tcp.h
63637 index f75a04d..702cf06 100644
63638 --- a/include/net/tcp.h
63639 +++ b/include/net/tcp.h
63640 @@ -1425,7 +1425,7 @@ struct tcp_seq_afinfo {
63641 char *name;
63642 sa_family_t family;
63643 const struct file_operations *seq_fops;
63644 - struct seq_operations seq_ops;
63645 + seq_operations_no_const seq_ops;
63646 };
63647
63648 struct tcp_iter_state {
63649 diff --git a/include/net/udp.h b/include/net/udp.h
63650 index 5d606d9..e879f7b 100644
63651 --- a/include/net/udp.h
63652 +++ b/include/net/udp.h
63653 @@ -244,7 +244,7 @@ struct udp_seq_afinfo {
63654 sa_family_t family;
63655 struct udp_table *udp_table;
63656 const struct file_operations *seq_fops;
63657 - struct seq_operations seq_ops;
63658 + seq_operations_no_const seq_ops;
63659 };
63660
63661 struct udp_iter_state {
63662 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
63663 index 96239e7..c85b032 100644
63664 --- a/include/net/xfrm.h
63665 +++ b/include/net/xfrm.h
63666 @@ -505,7 +505,7 @@ struct xfrm_policy {
63667 struct timer_list timer;
63668
63669 struct flow_cache_object flo;
63670 - atomic_t genid;
63671 + atomic_unchecked_t genid;
63672 u32 priority;
63673 u32 index;
63674 struct xfrm_mark mark;
63675 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
63676 index 1a046b1..ee0bef0 100644
63677 --- a/include/rdma/iw_cm.h
63678 +++ b/include/rdma/iw_cm.h
63679 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
63680 int backlog);
63681
63682 int (*destroy_listen)(struct iw_cm_id *cm_id);
63683 -};
63684 +} __no_const;
63685
63686 /**
63687 * iw_create_cm_id - Create an IW CM identifier.
63688 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
63689 index 8f9dfba..610ab6c 100644
63690 --- a/include/scsi/libfc.h
63691 +++ b/include/scsi/libfc.h
63692 @@ -756,6 +756,7 @@ struct libfc_function_template {
63693 */
63694 void (*disc_stop_final) (struct fc_lport *);
63695 };
63696 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
63697
63698 /**
63699 * struct fc_disc - Discovery context
63700 @@ -861,7 +862,7 @@ struct fc_lport {
63701 struct fc_vport *vport;
63702
63703 /* Operational Information */
63704 - struct libfc_function_template tt;
63705 + libfc_function_template_no_const tt;
63706 u8 link_up;
63707 u8 qfull;
63708 enum fc_lport_state state;
63709 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
63710 index 6efb2e1..cdad57f 100644
63711 --- a/include/scsi/scsi_device.h
63712 +++ b/include/scsi/scsi_device.h
63713 @@ -162,9 +162,9 @@ struct scsi_device {
63714 unsigned int max_device_blocked; /* what device_blocked counts down from */
63715 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
63716
63717 - atomic_t iorequest_cnt;
63718 - atomic_t iodone_cnt;
63719 - atomic_t ioerr_cnt;
63720 + atomic_unchecked_t iorequest_cnt;
63721 + atomic_unchecked_t iodone_cnt;
63722 + atomic_unchecked_t ioerr_cnt;
63723
63724 struct device sdev_gendev,
63725 sdev_dev;
63726 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
63727 index 719faf1..d1154d4 100644
63728 --- a/include/scsi/scsi_transport_fc.h
63729 +++ b/include/scsi/scsi_transport_fc.h
63730 @@ -739,7 +739,7 @@ struct fc_function_template {
63731 unsigned long show_host_system_hostname:1;
63732
63733 unsigned long disable_target_scan:1;
63734 -};
63735 +} __do_const;
63736
63737
63738 /**
63739 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
63740 index 030b87c..98a6954 100644
63741 --- a/include/sound/ak4xxx-adda.h
63742 +++ b/include/sound/ak4xxx-adda.h
63743 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
63744 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
63745 unsigned char val);
63746 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
63747 -};
63748 +} __no_const;
63749
63750 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
63751
63752 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
63753 index 8c05e47..2b5df97 100644
63754 --- a/include/sound/hwdep.h
63755 +++ b/include/sound/hwdep.h
63756 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
63757 struct snd_hwdep_dsp_status *status);
63758 int (*dsp_load)(struct snd_hwdep *hw,
63759 struct snd_hwdep_dsp_image *image);
63760 -};
63761 +} __no_const;
63762
63763 struct snd_hwdep {
63764 struct snd_card *card;
63765 diff --git a/include/sound/info.h b/include/sound/info.h
63766 index 9ca1a49..aba1728 100644
63767 --- a/include/sound/info.h
63768 +++ b/include/sound/info.h
63769 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
63770 struct snd_info_buffer *buffer);
63771 void (*write)(struct snd_info_entry *entry,
63772 struct snd_info_buffer *buffer);
63773 -};
63774 +} __no_const;
63775
63776 struct snd_info_entry_ops {
63777 int (*open)(struct snd_info_entry *entry,
63778 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
63779 index 0d11128..814178e 100644
63780 --- a/include/sound/pcm.h
63781 +++ b/include/sound/pcm.h
63782 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
63783 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
63784 int (*ack)(struct snd_pcm_substream *substream);
63785 };
63786 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
63787
63788 /*
63789 *
63790 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
63791 index af1b49e..a5d55a5 100644
63792 --- a/include/sound/sb16_csp.h
63793 +++ b/include/sound/sb16_csp.h
63794 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
63795 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
63796 int (*csp_stop) (struct snd_sb_csp * p);
63797 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
63798 -};
63799 +} __no_const;
63800
63801 /*
63802 * CSP private data
63803 diff --git a/include/sound/soc.h b/include/sound/soc.h
63804 index 2ebf787..0276839 100644
63805 --- a/include/sound/soc.h
63806 +++ b/include/sound/soc.h
63807 @@ -711,7 +711,7 @@ struct snd_soc_platform_driver {
63808 /* platform IO - used for platform DAPM */
63809 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
63810 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
63811 -};
63812 +} __do_const;
63813
63814 struct snd_soc_platform {
63815 const char *name;
63816 @@ -887,7 +887,7 @@ struct snd_soc_pcm_runtime {
63817 struct snd_soc_dai_link *dai_link;
63818 struct mutex pcm_mutex;
63819 enum snd_soc_pcm_subclass pcm_subclass;
63820 - struct snd_pcm_ops ops;
63821 + snd_pcm_ops_no_const ops;
63822
63823 unsigned int complete:1;
63824 unsigned int dev_registered:1;
63825 diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
63826 index 4119966..1a4671c 100644
63827 --- a/include/sound/ymfpci.h
63828 +++ b/include/sound/ymfpci.h
63829 @@ -358,7 +358,7 @@ struct snd_ymfpci {
63830 spinlock_t reg_lock;
63831 spinlock_t voice_lock;
63832 wait_queue_head_t interrupt_sleep;
63833 - atomic_t interrupt_sleep_count;
63834 + atomic_unchecked_t interrupt_sleep_count;
63835 struct snd_info_entry *proc_entry;
63836 const struct firmware *dsp_microcode;
63837 const struct firmware *controller_microcode;
63838 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
63839 index aaccc5f..092d568 100644
63840 --- a/include/target/target_core_base.h
63841 +++ b/include/target/target_core_base.h
63842 @@ -447,7 +447,7 @@ struct t10_reservation_ops {
63843 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
63844 int (*t10_pr_register)(struct se_cmd *);
63845 int (*t10_pr_clear)(struct se_cmd *);
63846 -};
63847 +} __no_const;
63848
63849 struct t10_reservation {
63850 /* Reservation effects all target ports */
63851 @@ -576,7 +576,7 @@ struct se_cmd {
63852 atomic_t t_se_count;
63853 atomic_t t_task_cdbs_left;
63854 atomic_t t_task_cdbs_ex_left;
63855 - atomic_t t_task_cdbs_sent;
63856 + atomic_unchecked_t t_task_cdbs_sent;
63857 unsigned int transport_state;
63858 #define CMD_T_ABORTED (1 << 0)
63859 #define CMD_T_ACTIVE (1 << 1)
63860 @@ -802,7 +802,7 @@ struct se_device {
63861 spinlock_t stats_lock;
63862 /* Active commands on this virtual SE device */
63863 atomic_t simple_cmds;
63864 - atomic_t dev_ordered_id;
63865 + atomic_unchecked_t dev_ordered_id;
63866 atomic_t execute_tasks;
63867 atomic_t dev_ordered_sync;
63868 atomic_t dev_qf_count;
63869 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
63870 new file mode 100644
63871 index 0000000..2efe49d
63872 --- /dev/null
63873 +++ b/include/trace/events/fs.h
63874 @@ -0,0 +1,53 @@
63875 +#undef TRACE_SYSTEM
63876 +#define TRACE_SYSTEM fs
63877 +
63878 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
63879 +#define _TRACE_FS_H
63880 +
63881 +#include <linux/fs.h>
63882 +#include <linux/tracepoint.h>
63883 +
63884 +TRACE_EVENT(do_sys_open,
63885 +
63886 + TP_PROTO(char *filename, int flags, int mode),
63887 +
63888 + TP_ARGS(filename, flags, mode),
63889 +
63890 + TP_STRUCT__entry(
63891 + __string( filename, filename )
63892 + __field( int, flags )
63893 + __field( int, mode )
63894 + ),
63895 +
63896 + TP_fast_assign(
63897 + __assign_str(filename, filename);
63898 + __entry->flags = flags;
63899 + __entry->mode = mode;
63900 + ),
63901 +
63902 + TP_printk("\"%s\" %x %o",
63903 + __get_str(filename), __entry->flags, __entry->mode)
63904 +);
63905 +
63906 +TRACE_EVENT(open_exec,
63907 +
63908 + TP_PROTO(const char *filename),
63909 +
63910 + TP_ARGS(filename),
63911 +
63912 + TP_STRUCT__entry(
63913 + __string( filename, filename )
63914 + ),
63915 +
63916 + TP_fast_assign(
63917 + __assign_str(filename, filename);
63918 + ),
63919 +
63920 + TP_printk("\"%s\"",
63921 + __get_str(filename))
63922 +);
63923 +
63924 +#endif /* _TRACE_FS_H */
63925 +
63926 +/* This part must be outside protection */
63927 +#include <trace/define_trace.h>
63928 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
63929 index 1c09820..7f5ec79 100644
63930 --- a/include/trace/events/irq.h
63931 +++ b/include/trace/events/irq.h
63932 @@ -36,7 +36,7 @@ struct softirq_action;
63933 */
63934 TRACE_EVENT(irq_handler_entry,
63935
63936 - TP_PROTO(int irq, struct irqaction *action),
63937 + TP_PROTO(int irq, const struct irqaction *action),
63938
63939 TP_ARGS(irq, action),
63940
63941 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
63942 */
63943 TRACE_EVENT(irq_handler_exit,
63944
63945 - TP_PROTO(int irq, struct irqaction *action, int ret),
63946 + TP_PROTO(int irq, const struct irqaction *action, int ret),
63947
63948 TP_ARGS(irq, action, ret),
63949
63950 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
63951 index f9466fa..f4e2b81 100644
63952 --- a/include/video/udlfb.h
63953 +++ b/include/video/udlfb.h
63954 @@ -53,10 +53,10 @@ struct dlfb_data {
63955 u32 pseudo_palette[256];
63956 int blank_mode; /*one of FB_BLANK_ */
63957 /* blit-only rendering path metrics, exposed through sysfs */
63958 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
63959 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
63960 - atomic_t bytes_sent; /* to usb, after compression including overhead */
63961 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
63962 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
63963 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
63964 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
63965 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
63966 };
63967
63968 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
63969 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
63970 index 0993a22..32ba2fe 100644
63971 --- a/include/video/uvesafb.h
63972 +++ b/include/video/uvesafb.h
63973 @@ -177,6 +177,7 @@ struct uvesafb_par {
63974 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
63975 u8 pmi_setpal; /* PMI for palette changes */
63976 u16 *pmi_base; /* protected mode interface location */
63977 + u8 *pmi_code; /* protected mode code location */
63978 void *pmi_start;
63979 void *pmi_pal;
63980 u8 *vbe_state_orig; /*
63981 diff --git a/init/Kconfig b/init/Kconfig
63982 index 6cfd71d..73cb68d 100644
63983 --- a/init/Kconfig
63984 +++ b/init/Kconfig
63985 @@ -790,6 +790,7 @@ endif # CGROUPS
63986
63987 config CHECKPOINT_RESTORE
63988 bool "Checkpoint/restore support" if EXPERT
63989 + depends on !GRKERNSEC
63990 default n
63991 help
63992 Enables additional kernel features in a sake of checkpoint/restore.
63993 @@ -1240,7 +1241,7 @@ config SLUB_DEBUG
63994
63995 config COMPAT_BRK
63996 bool "Disable heap randomization"
63997 - default y
63998 + default n
63999 help
64000 Randomizing heap placement makes heap exploits harder, but it
64001 also breaks ancient binaries (including anything libc5 based).
64002 diff --git a/init/do_mounts.c b/init/do_mounts.c
64003 index 42b0707..c06eef4 100644
64004 --- a/init/do_mounts.c
64005 +++ b/init/do_mounts.c
64006 @@ -326,11 +326,11 @@ static void __init get_fs_names(char *page)
64007 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
64008 {
64009 struct super_block *s;
64010 - int err = sys_mount(name, "/root", fs, flags, data);
64011 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
64012 if (err)
64013 return err;
64014
64015 - sys_chdir((const char __user __force *)"/root");
64016 + sys_chdir((const char __force_user *)"/root");
64017 s = current->fs->pwd.dentry->d_sb;
64018 ROOT_DEV = s->s_dev;
64019 printk(KERN_INFO
64020 @@ -450,18 +450,18 @@ void __init change_floppy(char *fmt, ...)
64021 va_start(args, fmt);
64022 vsprintf(buf, fmt, args);
64023 va_end(args);
64024 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
64025 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
64026 if (fd >= 0) {
64027 sys_ioctl(fd, FDEJECT, 0);
64028 sys_close(fd);
64029 }
64030 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
64031 - fd = sys_open("/dev/console", O_RDWR, 0);
64032 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
64033 if (fd >= 0) {
64034 sys_ioctl(fd, TCGETS, (long)&termios);
64035 termios.c_lflag &= ~ICANON;
64036 sys_ioctl(fd, TCSETSF, (long)&termios);
64037 - sys_read(fd, &c, 1);
64038 + sys_read(fd, (char __user *)&c, 1);
64039 termios.c_lflag |= ICANON;
64040 sys_ioctl(fd, TCSETSF, (long)&termios);
64041 sys_close(fd);
64042 @@ -555,6 +555,6 @@ void __init prepare_namespace(void)
64043 mount_root();
64044 out:
64045 devtmpfs_mount("dev");
64046 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
64047 - sys_chroot((const char __user __force *)".");
64048 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
64049 + sys_chroot((const char __force_user *)".");
64050 }
64051 diff --git a/init/do_mounts.h b/init/do_mounts.h
64052 index f5b978a..69dbfe8 100644
64053 --- a/init/do_mounts.h
64054 +++ b/init/do_mounts.h
64055 @@ -15,15 +15,15 @@ extern int root_mountflags;
64056
64057 static inline int create_dev(char *name, dev_t dev)
64058 {
64059 - sys_unlink(name);
64060 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
64061 + sys_unlink((char __force_user *)name);
64062 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
64063 }
64064
64065 #if BITS_PER_LONG == 32
64066 static inline u32 bstat(char *name)
64067 {
64068 struct stat64 stat;
64069 - if (sys_stat64(name, &stat) != 0)
64070 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
64071 return 0;
64072 if (!S_ISBLK(stat.st_mode))
64073 return 0;
64074 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
64075 static inline u32 bstat(char *name)
64076 {
64077 struct stat stat;
64078 - if (sys_newstat(name, &stat) != 0)
64079 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
64080 return 0;
64081 if (!S_ISBLK(stat.st_mode))
64082 return 0;
64083 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
64084 index 9047330..de0d1fb 100644
64085 --- a/init/do_mounts_initrd.c
64086 +++ b/init/do_mounts_initrd.c
64087 @@ -43,13 +43,13 @@ static void __init handle_initrd(void)
64088 create_dev("/dev/root.old", Root_RAM0);
64089 /* mount initrd on rootfs' /root */
64090 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
64091 - sys_mkdir("/old", 0700);
64092 - root_fd = sys_open("/", 0, 0);
64093 - old_fd = sys_open("/old", 0, 0);
64094 + sys_mkdir((const char __force_user *)"/old", 0700);
64095 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
64096 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
64097 /* move initrd over / and chdir/chroot in initrd root */
64098 - sys_chdir("/root");
64099 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
64100 - sys_chroot(".");
64101 + sys_chdir((const char __force_user *)"/root");
64102 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
64103 + sys_chroot((const char __force_user *)".");
64104
64105 /*
64106 * In case that a resume from disk is carried out by linuxrc or one of
64107 @@ -66,15 +66,15 @@ static void __init handle_initrd(void)
64108
64109 /* move initrd to rootfs' /old */
64110 sys_fchdir(old_fd);
64111 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
64112 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
64113 /* switch root and cwd back to / of rootfs */
64114 sys_fchdir(root_fd);
64115 - sys_chroot(".");
64116 + sys_chroot((const char __force_user *)".");
64117 sys_close(old_fd);
64118 sys_close(root_fd);
64119
64120 if (new_decode_dev(real_root_dev) == Root_RAM0) {
64121 - sys_chdir("/old");
64122 + sys_chdir((const char __force_user *)"/old");
64123 return;
64124 }
64125
64126 @@ -82,17 +82,17 @@ static void __init handle_initrd(void)
64127 mount_root();
64128
64129 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
64130 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
64131 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
64132 if (!error)
64133 printk("okay\n");
64134 else {
64135 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
64136 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
64137 if (error == -ENOENT)
64138 printk("/initrd does not exist. Ignored.\n");
64139 else
64140 printk("failed\n");
64141 printk(KERN_NOTICE "Unmounting old root\n");
64142 - sys_umount("/old", MNT_DETACH);
64143 + sys_umount((char __force_user *)"/old", MNT_DETACH);
64144 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
64145 if (fd < 0) {
64146 error = fd;
64147 @@ -115,11 +115,11 @@ int __init initrd_load(void)
64148 * mounted in the normal path.
64149 */
64150 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
64151 - sys_unlink("/initrd.image");
64152 + sys_unlink((const char __force_user *)"/initrd.image");
64153 handle_initrd();
64154 return 1;
64155 }
64156 }
64157 - sys_unlink("/initrd.image");
64158 + sys_unlink((const char __force_user *)"/initrd.image");
64159 return 0;
64160 }
64161 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
64162 index 32c4799..c27ee74 100644
64163 --- a/init/do_mounts_md.c
64164 +++ b/init/do_mounts_md.c
64165 @@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
64166 partitioned ? "_d" : "", minor,
64167 md_setup_args[ent].device_names);
64168
64169 - fd = sys_open(name, 0, 0);
64170 + fd = sys_open((char __force_user *)name, 0, 0);
64171 if (fd < 0) {
64172 printk(KERN_ERR "md: open failed - cannot start "
64173 "array %s\n", name);
64174 @@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
64175 * array without it
64176 */
64177 sys_close(fd);
64178 - fd = sys_open(name, 0, 0);
64179 + fd = sys_open((char __force_user *)name, 0, 0);
64180 sys_ioctl(fd, BLKRRPART, 0);
64181 }
64182 sys_close(fd);
64183 @@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
64184
64185 wait_for_device_probe();
64186
64187 - fd = sys_open((const char __user __force *) "/dev/md0", 0, 0);
64188 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
64189 if (fd >= 0) {
64190 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
64191 sys_close(fd);
64192 diff --git a/init/initramfs.c b/init/initramfs.c
64193 index 8216c30..25e8e32 100644
64194 --- a/init/initramfs.c
64195 +++ b/init/initramfs.c
64196 @@ -74,7 +74,7 @@ static void __init free_hash(void)
64197 }
64198 }
64199
64200 -static long __init do_utime(char __user *filename, time_t mtime)
64201 +static long __init do_utime(__force char __user *filename, time_t mtime)
64202 {
64203 struct timespec t[2];
64204
64205 @@ -109,7 +109,7 @@ static void __init dir_utime(void)
64206 struct dir_entry *de, *tmp;
64207 list_for_each_entry_safe(de, tmp, &dir_list, list) {
64208 list_del(&de->list);
64209 - do_utime(de->name, de->mtime);
64210 + do_utime((char __force_user *)de->name, de->mtime);
64211 kfree(de->name);
64212 kfree(de);
64213 }
64214 @@ -271,7 +271,7 @@ static int __init maybe_link(void)
64215 if (nlink >= 2) {
64216 char *old = find_link(major, minor, ino, mode, collected);
64217 if (old)
64218 - return (sys_link(old, collected) < 0) ? -1 : 1;
64219 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
64220 }
64221 return 0;
64222 }
64223 @@ -280,11 +280,11 @@ static void __init clean_path(char *path, umode_t mode)
64224 {
64225 struct stat st;
64226
64227 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
64228 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
64229 if (S_ISDIR(st.st_mode))
64230 - sys_rmdir(path);
64231 + sys_rmdir((char __force_user *)path);
64232 else
64233 - sys_unlink(path);
64234 + sys_unlink((char __force_user *)path);
64235 }
64236 }
64237
64238 @@ -305,7 +305,7 @@ static int __init do_name(void)
64239 int openflags = O_WRONLY|O_CREAT;
64240 if (ml != 1)
64241 openflags |= O_TRUNC;
64242 - wfd = sys_open(collected, openflags, mode);
64243 + wfd = sys_open((char __force_user *)collected, openflags, mode);
64244
64245 if (wfd >= 0) {
64246 sys_fchown(wfd, uid, gid);
64247 @@ -317,17 +317,17 @@ static int __init do_name(void)
64248 }
64249 }
64250 } else if (S_ISDIR(mode)) {
64251 - sys_mkdir(collected, mode);
64252 - sys_chown(collected, uid, gid);
64253 - sys_chmod(collected, mode);
64254 + sys_mkdir((char __force_user *)collected, mode);
64255 + sys_chown((char __force_user *)collected, uid, gid);
64256 + sys_chmod((char __force_user *)collected, mode);
64257 dir_add(collected, mtime);
64258 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
64259 S_ISFIFO(mode) || S_ISSOCK(mode)) {
64260 if (maybe_link() == 0) {
64261 - sys_mknod(collected, mode, rdev);
64262 - sys_chown(collected, uid, gid);
64263 - sys_chmod(collected, mode);
64264 - do_utime(collected, mtime);
64265 + sys_mknod((char __force_user *)collected, mode, rdev);
64266 + sys_chown((char __force_user *)collected, uid, gid);
64267 + sys_chmod((char __force_user *)collected, mode);
64268 + do_utime((char __force_user *)collected, mtime);
64269 }
64270 }
64271 return 0;
64272 @@ -336,15 +336,15 @@ static int __init do_name(void)
64273 static int __init do_copy(void)
64274 {
64275 if (count >= body_len) {
64276 - sys_write(wfd, victim, body_len);
64277 + sys_write(wfd, (char __force_user *)victim, body_len);
64278 sys_close(wfd);
64279 - do_utime(vcollected, mtime);
64280 + do_utime((char __force_user *)vcollected, mtime);
64281 kfree(vcollected);
64282 eat(body_len);
64283 state = SkipIt;
64284 return 0;
64285 } else {
64286 - sys_write(wfd, victim, count);
64287 + sys_write(wfd, (char __force_user *)victim, count);
64288 body_len -= count;
64289 eat(count);
64290 return 1;
64291 @@ -355,9 +355,9 @@ static int __init do_symlink(void)
64292 {
64293 collected[N_ALIGN(name_len) + body_len] = '\0';
64294 clean_path(collected, 0);
64295 - sys_symlink(collected + N_ALIGN(name_len), collected);
64296 - sys_lchown(collected, uid, gid);
64297 - do_utime(collected, mtime);
64298 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
64299 + sys_lchown((char __force_user *)collected, uid, gid);
64300 + do_utime((char __force_user *)collected, mtime);
64301 state = SkipIt;
64302 next_state = Reset;
64303 return 0;
64304 diff --git a/init/main.c b/init/main.c
64305 index b08c5f7..09f865e 100644
64306 --- a/init/main.c
64307 +++ b/init/main.c
64308 @@ -95,6 +95,8 @@ static inline void mark_rodata_ro(void) { }
64309 extern void tc_init(void);
64310 #endif
64311
64312 +extern void grsecurity_init(void);
64313 +
64314 /*
64315 * Debug helper: via this flag we know that we are in 'early bootup code'
64316 * where only the boot processor is running with IRQ disabled. This means
64317 @@ -148,6 +150,49 @@ static int __init set_reset_devices(char *str)
64318
64319 __setup("reset_devices", set_reset_devices);
64320
64321 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
64322 +extern char pax_enter_kernel_user[];
64323 +extern char pax_exit_kernel_user[];
64324 +extern pgdval_t clone_pgd_mask;
64325 +#endif
64326 +
64327 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
64328 +static int __init setup_pax_nouderef(char *str)
64329 +{
64330 +#ifdef CONFIG_X86_32
64331 + unsigned int cpu;
64332 + struct desc_struct *gdt;
64333 +
64334 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
64335 + gdt = get_cpu_gdt_table(cpu);
64336 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
64337 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
64338 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
64339 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
64340 + }
64341 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
64342 +#else
64343 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
64344 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
64345 + clone_pgd_mask = ~(pgdval_t)0UL;
64346 +#endif
64347 +
64348 + return 0;
64349 +}
64350 +early_param("pax_nouderef", setup_pax_nouderef);
64351 +#endif
64352 +
64353 +#ifdef CONFIG_PAX_SOFTMODE
64354 +int pax_softmode;
64355 +
64356 +static int __init setup_pax_softmode(char *str)
64357 +{
64358 + get_option(&str, &pax_softmode);
64359 + return 1;
64360 +}
64361 +__setup("pax_softmode=", setup_pax_softmode);
64362 +#endif
64363 +
64364 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
64365 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
64366 static const char *panic_later, *panic_param;
64367 @@ -674,6 +719,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
64368 {
64369 int count = preempt_count();
64370 int ret;
64371 + const char *msg1 = "", *msg2 = "";
64372
64373 if (initcall_debug)
64374 ret = do_one_initcall_debug(fn);
64375 @@ -686,15 +732,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
64376 sprintf(msgbuf, "error code %d ", ret);
64377
64378 if (preempt_count() != count) {
64379 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
64380 + msg1 = " preemption imbalance";
64381 preempt_count() = count;
64382 }
64383 if (irqs_disabled()) {
64384 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
64385 + msg2 = " disabled interrupts";
64386 local_irq_enable();
64387 }
64388 - if (msgbuf[0]) {
64389 - printk("initcall %pF returned with %s\n", fn, msgbuf);
64390 + if (msgbuf[0] || *msg1 || *msg2) {
64391 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
64392 }
64393
64394 return ret;
64395 @@ -865,7 +911,7 @@ static int __init kernel_init(void * unused)
64396 do_basic_setup();
64397
64398 /* Open the /dev/console on the rootfs, this should never fail */
64399 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
64400 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
64401 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
64402
64403 (void) sys_dup(0);
64404 @@ -878,11 +924,13 @@ static int __init kernel_init(void * unused)
64405 if (!ramdisk_execute_command)
64406 ramdisk_execute_command = "/init";
64407
64408 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
64409 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
64410 ramdisk_execute_command = NULL;
64411 prepare_namespace();
64412 }
64413
64414 + grsecurity_init();
64415 +
64416 /*
64417 * Ok, we have completed the initial bootup, and
64418 * we're essentially up and running. Get rid of the
64419 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
64420 index 28bd64d..c66b72a 100644
64421 --- a/ipc/mqueue.c
64422 +++ b/ipc/mqueue.c
64423 @@ -156,6 +156,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
64424 mq_bytes = (mq_msg_tblsz +
64425 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
64426
64427 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
64428 spin_lock(&mq_lock);
64429 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
64430 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
64431 diff --git a/ipc/msg.c b/ipc/msg.c
64432 index 7385de2..a8180e08 100644
64433 --- a/ipc/msg.c
64434 +++ b/ipc/msg.c
64435 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
64436 return security_msg_queue_associate(msq, msgflg);
64437 }
64438
64439 +static struct ipc_ops msg_ops = {
64440 + .getnew = newque,
64441 + .associate = msg_security,
64442 + .more_checks = NULL
64443 +};
64444 +
64445 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
64446 {
64447 struct ipc_namespace *ns;
64448 - struct ipc_ops msg_ops;
64449 struct ipc_params msg_params;
64450
64451 ns = current->nsproxy->ipc_ns;
64452
64453 - msg_ops.getnew = newque;
64454 - msg_ops.associate = msg_security;
64455 - msg_ops.more_checks = NULL;
64456 -
64457 msg_params.key = key;
64458 msg_params.flg = msgflg;
64459
64460 diff --git a/ipc/sem.c b/ipc/sem.c
64461 index 5215a81..cfc0cac 100644
64462 --- a/ipc/sem.c
64463 +++ b/ipc/sem.c
64464 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
64465 return 0;
64466 }
64467
64468 +static struct ipc_ops sem_ops = {
64469 + .getnew = newary,
64470 + .associate = sem_security,
64471 + .more_checks = sem_more_checks
64472 +};
64473 +
64474 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
64475 {
64476 struct ipc_namespace *ns;
64477 - struct ipc_ops sem_ops;
64478 struct ipc_params sem_params;
64479
64480 ns = current->nsproxy->ipc_ns;
64481 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
64482 if (nsems < 0 || nsems > ns->sc_semmsl)
64483 return -EINVAL;
64484
64485 - sem_ops.getnew = newary;
64486 - sem_ops.associate = sem_security;
64487 - sem_ops.more_checks = sem_more_checks;
64488 -
64489 sem_params.key = key;
64490 sem_params.flg = semflg;
64491 sem_params.u.nsems = nsems;
64492 diff --git a/ipc/shm.c b/ipc/shm.c
64493 index 406c5b2..bc66d67 100644
64494 --- a/ipc/shm.c
64495 +++ b/ipc/shm.c
64496 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
64497 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
64498 #endif
64499
64500 +#ifdef CONFIG_GRKERNSEC
64501 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64502 + const time_t shm_createtime, const uid_t cuid,
64503 + const int shmid);
64504 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64505 + const time_t shm_createtime);
64506 +#endif
64507 +
64508 void shm_init_ns(struct ipc_namespace *ns)
64509 {
64510 ns->shm_ctlmax = SHMMAX;
64511 @@ -508,6 +516,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
64512 shp->shm_lprid = 0;
64513 shp->shm_atim = shp->shm_dtim = 0;
64514 shp->shm_ctim = get_seconds();
64515 +#ifdef CONFIG_GRKERNSEC
64516 + {
64517 + struct timespec timeval;
64518 + do_posix_clock_monotonic_gettime(&timeval);
64519 +
64520 + shp->shm_createtime = timeval.tv_sec;
64521 + }
64522 +#endif
64523 shp->shm_segsz = size;
64524 shp->shm_nattch = 0;
64525 shp->shm_file = file;
64526 @@ -559,18 +575,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
64527 return 0;
64528 }
64529
64530 +static struct ipc_ops shm_ops = {
64531 + .getnew = newseg,
64532 + .associate = shm_security,
64533 + .more_checks = shm_more_checks
64534 +};
64535 +
64536 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
64537 {
64538 struct ipc_namespace *ns;
64539 - struct ipc_ops shm_ops;
64540 struct ipc_params shm_params;
64541
64542 ns = current->nsproxy->ipc_ns;
64543
64544 - shm_ops.getnew = newseg;
64545 - shm_ops.associate = shm_security;
64546 - shm_ops.more_checks = shm_more_checks;
64547 -
64548 shm_params.key = key;
64549 shm_params.flg = shmflg;
64550 shm_params.u.size = size;
64551 @@ -988,6 +1005,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
64552 f_mode = FMODE_READ | FMODE_WRITE;
64553 }
64554 if (shmflg & SHM_EXEC) {
64555 +
64556 +#ifdef CONFIG_PAX_MPROTECT
64557 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
64558 + goto out;
64559 +#endif
64560 +
64561 prot |= PROT_EXEC;
64562 acc_mode |= S_IXUGO;
64563 }
64564 @@ -1011,9 +1034,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
64565 if (err)
64566 goto out_unlock;
64567
64568 +#ifdef CONFIG_GRKERNSEC
64569 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
64570 + shp->shm_perm.cuid, shmid) ||
64571 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
64572 + err = -EACCES;
64573 + goto out_unlock;
64574 + }
64575 +#endif
64576 +
64577 path = shp->shm_file->f_path;
64578 path_get(&path);
64579 shp->shm_nattch++;
64580 +#ifdef CONFIG_GRKERNSEC
64581 + shp->shm_lapid = current->pid;
64582 +#endif
64583 size = i_size_read(path.dentry->d_inode);
64584 shm_unlock(shp);
64585
64586 diff --git a/kernel/acct.c b/kernel/acct.c
64587 index 02e6167..54824f7 100644
64588 --- a/kernel/acct.c
64589 +++ b/kernel/acct.c
64590 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
64591 */
64592 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
64593 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
64594 - file->f_op->write(file, (char *)&ac,
64595 + file->f_op->write(file, (char __force_user *)&ac,
64596 sizeof(acct_t), &file->f_pos);
64597 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
64598 set_fs(fs);
64599 diff --git a/kernel/audit.c b/kernel/audit.c
64600 index 1c7f2c6..9ba5359 100644
64601 --- a/kernel/audit.c
64602 +++ b/kernel/audit.c
64603 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
64604 3) suppressed due to audit_rate_limit
64605 4) suppressed due to audit_backlog_limit
64606 */
64607 -static atomic_t audit_lost = ATOMIC_INIT(0);
64608 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
64609
64610 /* The netlink socket. */
64611 static struct sock *audit_sock;
64612 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
64613 unsigned long now;
64614 int print;
64615
64616 - atomic_inc(&audit_lost);
64617 + atomic_inc_unchecked(&audit_lost);
64618
64619 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
64620
64621 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
64622 printk(KERN_WARNING
64623 "audit: audit_lost=%d audit_rate_limit=%d "
64624 "audit_backlog_limit=%d\n",
64625 - atomic_read(&audit_lost),
64626 + atomic_read_unchecked(&audit_lost),
64627 audit_rate_limit,
64628 audit_backlog_limit);
64629 audit_panic(message);
64630 @@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
64631 status_set.pid = audit_pid;
64632 status_set.rate_limit = audit_rate_limit;
64633 status_set.backlog_limit = audit_backlog_limit;
64634 - status_set.lost = atomic_read(&audit_lost);
64635 + status_set.lost = atomic_read_unchecked(&audit_lost);
64636 status_set.backlog = skb_queue_len(&audit_skb_queue);
64637 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
64638 &status_set, sizeof(status_set));
64639 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
64640 index af1de0f..06dfe57 100644
64641 --- a/kernel/auditsc.c
64642 +++ b/kernel/auditsc.c
64643 @@ -2288,7 +2288,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
64644 }
64645
64646 /* global counter which is incremented every time something logs in */
64647 -static atomic_t session_id = ATOMIC_INIT(0);
64648 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
64649
64650 /**
64651 * audit_set_loginuid - set current task's audit_context loginuid
64652 @@ -2312,7 +2312,7 @@ int audit_set_loginuid(uid_t loginuid)
64653 return -EPERM;
64654 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
64655
64656 - sessionid = atomic_inc_return(&session_id);
64657 + sessionid = atomic_inc_return_unchecked(&session_id);
64658 if (context && context->in_syscall) {
64659 struct audit_buffer *ab;
64660
64661 diff --git a/kernel/capability.c b/kernel/capability.c
64662 index 3f1adb6..c564db0 100644
64663 --- a/kernel/capability.c
64664 +++ b/kernel/capability.c
64665 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
64666 * before modification is attempted and the application
64667 * fails.
64668 */
64669 + if (tocopy > ARRAY_SIZE(kdata))
64670 + return -EFAULT;
64671 +
64672 if (copy_to_user(dataptr, kdata, tocopy
64673 * sizeof(struct __user_cap_data_struct))) {
64674 return -EFAULT;
64675 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
64676 int ret;
64677
64678 rcu_read_lock();
64679 - ret = security_capable(__task_cred(t), ns, cap);
64680 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
64681 + gr_task_is_capable(t, __task_cred(t), cap);
64682 rcu_read_unlock();
64683
64684 - return (ret == 0);
64685 + return ret;
64686 }
64687
64688 /**
64689 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
64690 int ret;
64691
64692 rcu_read_lock();
64693 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
64694 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
64695 rcu_read_unlock();
64696
64697 - return (ret == 0);
64698 + return ret;
64699 }
64700
64701 /**
64702 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
64703 BUG();
64704 }
64705
64706 - if (security_capable(current_cred(), ns, cap) == 0) {
64707 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
64708 current->flags |= PF_SUPERPRIV;
64709 return true;
64710 }
64711 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
64712 }
64713 EXPORT_SYMBOL(ns_capable);
64714
64715 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
64716 +{
64717 + if (unlikely(!cap_valid(cap))) {
64718 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
64719 + BUG();
64720 + }
64721 +
64722 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
64723 + current->flags |= PF_SUPERPRIV;
64724 + return true;
64725 + }
64726 + return false;
64727 +}
64728 +EXPORT_SYMBOL(ns_capable_nolog);
64729 +
64730 /**
64731 * capable - Determine if the current task has a superior capability in effect
64732 * @cap: The capability to be tested for
64733 @@ -408,6 +427,12 @@ bool capable(int cap)
64734 }
64735 EXPORT_SYMBOL(capable);
64736
64737 +bool capable_nolog(int cap)
64738 +{
64739 + return ns_capable_nolog(&init_user_ns, cap);
64740 +}
64741 +EXPORT_SYMBOL(capable_nolog);
64742 +
64743 /**
64744 * nsown_capable - Check superior capability to one's own user_ns
64745 * @cap: The capability in question
64746 diff --git a/kernel/compat.c b/kernel/compat.c
64747 index d2c67aa..a629b2e 100644
64748 --- a/kernel/compat.c
64749 +++ b/kernel/compat.c
64750 @@ -13,6 +13,7 @@
64751
64752 #include <linux/linkage.h>
64753 #include <linux/compat.h>
64754 +#include <linux/module.h>
64755 #include <linux/errno.h>
64756 #include <linux/time.h>
64757 #include <linux/signal.h>
64758 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
64759 mm_segment_t oldfs;
64760 long ret;
64761
64762 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
64763 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
64764 oldfs = get_fs();
64765 set_fs(KERNEL_DS);
64766 ret = hrtimer_nanosleep_restart(restart);
64767 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
64768 oldfs = get_fs();
64769 set_fs(KERNEL_DS);
64770 ret = hrtimer_nanosleep(&tu,
64771 - rmtp ? (struct timespec __user *)&rmt : NULL,
64772 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
64773 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
64774 set_fs(oldfs);
64775
64776 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
64777 mm_segment_t old_fs = get_fs();
64778
64779 set_fs(KERNEL_DS);
64780 - ret = sys_sigpending((old_sigset_t __user *) &s);
64781 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
64782 set_fs(old_fs);
64783 if (ret == 0)
64784 ret = put_user(s, set);
64785 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
64786 mm_segment_t old_fs = get_fs();
64787
64788 set_fs(KERNEL_DS);
64789 - ret = sys_old_getrlimit(resource, &r);
64790 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
64791 set_fs(old_fs);
64792
64793 if (!ret) {
64794 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
64795 mm_segment_t old_fs = get_fs();
64796
64797 set_fs(KERNEL_DS);
64798 - ret = sys_getrusage(who, (struct rusage __user *) &r);
64799 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
64800 set_fs(old_fs);
64801
64802 if (ret)
64803 @@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
64804 set_fs (KERNEL_DS);
64805 ret = sys_wait4(pid,
64806 (stat_addr ?
64807 - (unsigned int __user *) &status : NULL),
64808 - options, (struct rusage __user *) &r);
64809 + (unsigned int __force_user *) &status : NULL),
64810 + options, (struct rusage __force_user *) &r);
64811 set_fs (old_fs);
64812
64813 if (ret > 0) {
64814 @@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
64815 memset(&info, 0, sizeof(info));
64816
64817 set_fs(KERNEL_DS);
64818 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
64819 - uru ? (struct rusage __user *)&ru : NULL);
64820 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
64821 + uru ? (struct rusage __force_user *)&ru : NULL);
64822 set_fs(old_fs);
64823
64824 if ((ret < 0) || (info.si_signo == 0))
64825 @@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
64826 oldfs = get_fs();
64827 set_fs(KERNEL_DS);
64828 err = sys_timer_settime(timer_id, flags,
64829 - (struct itimerspec __user *) &newts,
64830 - (struct itimerspec __user *) &oldts);
64831 + (struct itimerspec __force_user *) &newts,
64832 + (struct itimerspec __force_user *) &oldts);
64833 set_fs(oldfs);
64834 if (!err && old && put_compat_itimerspec(old, &oldts))
64835 return -EFAULT;
64836 @@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
64837 oldfs = get_fs();
64838 set_fs(KERNEL_DS);
64839 err = sys_timer_gettime(timer_id,
64840 - (struct itimerspec __user *) &ts);
64841 + (struct itimerspec __force_user *) &ts);
64842 set_fs(oldfs);
64843 if (!err && put_compat_itimerspec(setting, &ts))
64844 return -EFAULT;
64845 @@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
64846 oldfs = get_fs();
64847 set_fs(KERNEL_DS);
64848 err = sys_clock_settime(which_clock,
64849 - (struct timespec __user *) &ts);
64850 + (struct timespec __force_user *) &ts);
64851 set_fs(oldfs);
64852 return err;
64853 }
64854 @@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
64855 oldfs = get_fs();
64856 set_fs(KERNEL_DS);
64857 err = sys_clock_gettime(which_clock,
64858 - (struct timespec __user *) &ts);
64859 + (struct timespec __force_user *) &ts);
64860 set_fs(oldfs);
64861 if (!err && put_compat_timespec(&ts, tp))
64862 return -EFAULT;
64863 @@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
64864
64865 oldfs = get_fs();
64866 set_fs(KERNEL_DS);
64867 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
64868 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
64869 set_fs(oldfs);
64870
64871 err = compat_put_timex(utp, &txc);
64872 @@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
64873 oldfs = get_fs();
64874 set_fs(KERNEL_DS);
64875 err = sys_clock_getres(which_clock,
64876 - (struct timespec __user *) &ts);
64877 + (struct timespec __force_user *) &ts);
64878 set_fs(oldfs);
64879 if (!err && tp && put_compat_timespec(&ts, tp))
64880 return -EFAULT;
64881 @@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
64882 long err;
64883 mm_segment_t oldfs;
64884 struct timespec tu;
64885 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
64886 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
64887
64888 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
64889 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
64890 oldfs = get_fs();
64891 set_fs(KERNEL_DS);
64892 err = clock_nanosleep_restart(restart);
64893 @@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
64894 oldfs = get_fs();
64895 set_fs(KERNEL_DS);
64896 err = sys_clock_nanosleep(which_clock, flags,
64897 - (struct timespec __user *) &in,
64898 - (struct timespec __user *) &out);
64899 + (struct timespec __force_user *) &in,
64900 + (struct timespec __force_user *) &out);
64901 set_fs(oldfs);
64902
64903 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
64904 diff --git a/kernel/configs.c b/kernel/configs.c
64905 index 42e8fa0..9e7406b 100644
64906 --- a/kernel/configs.c
64907 +++ b/kernel/configs.c
64908 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
64909 struct proc_dir_entry *entry;
64910
64911 /* create the current config file */
64912 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
64913 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
64914 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
64915 + &ikconfig_file_ops);
64916 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64917 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
64918 + &ikconfig_file_ops);
64919 +#endif
64920 +#else
64921 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
64922 &ikconfig_file_ops);
64923 +#endif
64924 +
64925 if (!entry)
64926 return -ENOMEM;
64927
64928 diff --git a/kernel/cred.c b/kernel/cred.c
64929 index e70683d..27761b6 100644
64930 --- a/kernel/cred.c
64931 +++ b/kernel/cred.c
64932 @@ -205,6 +205,15 @@ void exit_creds(struct task_struct *tsk)
64933 validate_creds(cred);
64934 put_cred(cred);
64935 }
64936 +
64937 +#ifdef CONFIG_GRKERNSEC_SETXID
64938 + cred = (struct cred *) tsk->delayed_cred;
64939 + if (cred) {
64940 + tsk->delayed_cred = NULL;
64941 + validate_creds(cred);
64942 + put_cred(cred);
64943 + }
64944 +#endif
64945 }
64946
64947 /**
64948 @@ -473,7 +482,7 @@ error_put:
64949 * Always returns 0 thus allowing this function to be tail-called at the end
64950 * of, say, sys_setgid().
64951 */
64952 -int commit_creds(struct cred *new)
64953 +static int __commit_creds(struct cred *new)
64954 {
64955 struct task_struct *task = current;
64956 const struct cred *old = task->real_cred;
64957 @@ -492,6 +501,8 @@ int commit_creds(struct cred *new)
64958
64959 get_cred(new); /* we will require a ref for the subj creds too */
64960
64961 + gr_set_role_label(task, new->uid, new->gid);
64962 +
64963 /* dumpability changes */
64964 if (old->euid != new->euid ||
64965 old->egid != new->egid ||
64966 @@ -541,6 +552,101 @@ int commit_creds(struct cred *new)
64967 put_cred(old);
64968 return 0;
64969 }
64970 +#ifdef CONFIG_GRKERNSEC_SETXID
64971 +extern int set_user(struct cred *new);
64972 +
64973 +void gr_delayed_cred_worker(void)
64974 +{
64975 + const struct cred *new = current->delayed_cred;
64976 + struct cred *ncred;
64977 +
64978 + current->delayed_cred = NULL;
64979 +
64980 + if (current_uid() && new != NULL) {
64981 + // from doing get_cred on it when queueing this
64982 + put_cred(new);
64983 + return;
64984 + } else if (new == NULL)
64985 + return;
64986 +
64987 + ncred = prepare_creds();
64988 + if (!ncred)
64989 + goto die;
64990 + // uids
64991 + ncred->uid = new->uid;
64992 + ncred->euid = new->euid;
64993 + ncred->suid = new->suid;
64994 + ncred->fsuid = new->fsuid;
64995 + // gids
64996 + ncred->gid = new->gid;
64997 + ncred->egid = new->egid;
64998 + ncred->sgid = new->sgid;
64999 + ncred->fsgid = new->fsgid;
65000 + // groups
65001 + if (set_groups(ncred, new->group_info) < 0) {
65002 + abort_creds(ncred);
65003 + goto die;
65004 + }
65005 + // caps
65006 + ncred->securebits = new->securebits;
65007 + ncred->cap_inheritable = new->cap_inheritable;
65008 + ncred->cap_permitted = new->cap_permitted;
65009 + ncred->cap_effective = new->cap_effective;
65010 + ncred->cap_bset = new->cap_bset;
65011 +
65012 + if (set_user(ncred)) {
65013 + abort_creds(ncred);
65014 + goto die;
65015 + }
65016 +
65017 + // from doing get_cred on it when queueing this
65018 + put_cred(new);
65019 +
65020 + __commit_creds(ncred);
65021 + return;
65022 +die:
65023 + // from doing get_cred on it when queueing this
65024 + put_cred(new);
65025 + do_group_exit(SIGKILL);
65026 +}
65027 +#endif
65028 +
65029 +int commit_creds(struct cred *new)
65030 +{
65031 +#ifdef CONFIG_GRKERNSEC_SETXID
65032 + int ret;
65033 + int schedule_it = 0;
65034 + struct task_struct *t;
65035 +
65036 + /* we won't get called with tasklist_lock held for writing
65037 + and interrupts disabled as the cred struct in that case is
65038 + init_cred
65039 + */
65040 + if (grsec_enable_setxid && !current_is_single_threaded() &&
65041 + !current_uid() && new->uid) {
65042 + schedule_it = 1;
65043 + }
65044 + ret = __commit_creds(new);
65045 + if (schedule_it) {
65046 + rcu_read_lock();
65047 + read_lock(&tasklist_lock);
65048 + for (t = next_thread(current); t != current;
65049 + t = next_thread(t)) {
65050 + if (t->delayed_cred == NULL) {
65051 + t->delayed_cred = get_cred(new);
65052 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
65053 + set_tsk_need_resched(t);
65054 + }
65055 + }
65056 + read_unlock(&tasklist_lock);
65057 + rcu_read_unlock();
65058 + }
65059 + return ret;
65060 +#else
65061 + return __commit_creds(new);
65062 +#endif
65063 +}
65064 +
65065 EXPORT_SYMBOL(commit_creds);
65066
65067 /**
65068 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
65069 index 0557f24..1a00d9a 100644
65070 --- a/kernel/debug/debug_core.c
65071 +++ b/kernel/debug/debug_core.c
65072 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
65073 */
65074 static atomic_t masters_in_kgdb;
65075 static atomic_t slaves_in_kgdb;
65076 -static atomic_t kgdb_break_tasklet_var;
65077 +static atomic_unchecked_t kgdb_break_tasklet_var;
65078 atomic_t kgdb_setting_breakpoint;
65079
65080 struct task_struct *kgdb_usethread;
65081 @@ -132,7 +132,7 @@ int kgdb_single_step;
65082 static pid_t kgdb_sstep_pid;
65083
65084 /* to keep track of the CPU which is doing the single stepping*/
65085 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
65086 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
65087
65088 /*
65089 * If you are debugging a problem where roundup (the collection of
65090 @@ -540,7 +540,7 @@ return_normal:
65091 * kernel will only try for the value of sstep_tries before
65092 * giving up and continuing on.
65093 */
65094 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
65095 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
65096 (kgdb_info[cpu].task &&
65097 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
65098 atomic_set(&kgdb_active, -1);
65099 @@ -634,8 +634,8 @@ cpu_master_loop:
65100 }
65101
65102 kgdb_restore:
65103 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
65104 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
65105 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
65106 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
65107 if (kgdb_info[sstep_cpu].task)
65108 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
65109 else
65110 @@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
65111 static void kgdb_tasklet_bpt(unsigned long ing)
65112 {
65113 kgdb_breakpoint();
65114 - atomic_set(&kgdb_break_tasklet_var, 0);
65115 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
65116 }
65117
65118 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
65119
65120 void kgdb_schedule_breakpoint(void)
65121 {
65122 - if (atomic_read(&kgdb_break_tasklet_var) ||
65123 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
65124 atomic_read(&kgdb_active) != -1 ||
65125 atomic_read(&kgdb_setting_breakpoint))
65126 return;
65127 - atomic_inc(&kgdb_break_tasklet_var);
65128 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
65129 tasklet_schedule(&kgdb_tasklet_breakpoint);
65130 }
65131 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
65132 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
65133 index 67b847d..93834dd 100644
65134 --- a/kernel/debug/kdb/kdb_main.c
65135 +++ b/kernel/debug/kdb/kdb_main.c
65136 @@ -1983,7 +1983,7 @@ static int kdb_lsmod(int argc, const char **argv)
65137 list_for_each_entry(mod, kdb_modules, list) {
65138
65139 kdb_printf("%-20s%8u 0x%p ", mod->name,
65140 - mod->core_size, (void *)mod);
65141 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
65142 #ifdef CONFIG_MODULE_UNLOAD
65143 kdb_printf("%4ld ", module_refcount(mod));
65144 #endif
65145 @@ -1993,7 +1993,7 @@ static int kdb_lsmod(int argc, const char **argv)
65146 kdb_printf(" (Loading)");
65147 else
65148 kdb_printf(" (Live)");
65149 - kdb_printf(" 0x%p", mod->module_core);
65150 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
65151
65152 #ifdef CONFIG_MODULE_UNLOAD
65153 {
65154 diff --git a/kernel/events/core.c b/kernel/events/core.c
65155 index fd126f8..70b755b 100644
65156 --- a/kernel/events/core.c
65157 +++ b/kernel/events/core.c
65158 @@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
65159 return 0;
65160 }
65161
65162 -static atomic64_t perf_event_id;
65163 +static atomic64_unchecked_t perf_event_id;
65164
65165 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
65166 enum event_type_t event_type);
65167 @@ -2659,7 +2659,7 @@ static void __perf_event_read(void *info)
65168
65169 static inline u64 perf_event_count(struct perf_event *event)
65170 {
65171 - return local64_read(&event->count) + atomic64_read(&event->child_count);
65172 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
65173 }
65174
65175 static u64 perf_event_read(struct perf_event *event)
65176 @@ -2983,9 +2983,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
65177 mutex_lock(&event->child_mutex);
65178 total += perf_event_read(event);
65179 *enabled += event->total_time_enabled +
65180 - atomic64_read(&event->child_total_time_enabled);
65181 + atomic64_read_unchecked(&event->child_total_time_enabled);
65182 *running += event->total_time_running +
65183 - atomic64_read(&event->child_total_time_running);
65184 + atomic64_read_unchecked(&event->child_total_time_running);
65185
65186 list_for_each_entry(child, &event->child_list, child_list) {
65187 total += perf_event_read(child);
65188 @@ -3393,10 +3393,10 @@ void perf_event_update_userpage(struct perf_event *event)
65189 userpg->offset -= local64_read(&event->hw.prev_count);
65190
65191 userpg->time_enabled = enabled +
65192 - atomic64_read(&event->child_total_time_enabled);
65193 + atomic64_read_unchecked(&event->child_total_time_enabled);
65194
65195 userpg->time_running = running +
65196 - atomic64_read(&event->child_total_time_running);
65197 + atomic64_read_unchecked(&event->child_total_time_running);
65198
65199 arch_perf_update_userpage(userpg, now);
65200
65201 @@ -3829,11 +3829,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
65202 values[n++] = perf_event_count(event);
65203 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
65204 values[n++] = enabled +
65205 - atomic64_read(&event->child_total_time_enabled);
65206 + atomic64_read_unchecked(&event->child_total_time_enabled);
65207 }
65208 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
65209 values[n++] = running +
65210 - atomic64_read(&event->child_total_time_running);
65211 + atomic64_read_unchecked(&event->child_total_time_running);
65212 }
65213 if (read_format & PERF_FORMAT_ID)
65214 values[n++] = primary_event_id(event);
65215 @@ -4511,12 +4511,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
65216 * need to add enough zero bytes after the string to handle
65217 * the 64bit alignment we do later.
65218 */
65219 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
65220 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
65221 if (!buf) {
65222 name = strncpy(tmp, "//enomem", sizeof(tmp));
65223 goto got_name;
65224 }
65225 - name = d_path(&file->f_path, buf, PATH_MAX);
65226 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
65227 if (IS_ERR(name)) {
65228 name = strncpy(tmp, "//toolong", sizeof(tmp));
65229 goto got_name;
65230 @@ -5929,7 +5929,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
65231 event->parent = parent_event;
65232
65233 event->ns = get_pid_ns(current->nsproxy->pid_ns);
65234 - event->id = atomic64_inc_return(&perf_event_id);
65235 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
65236
65237 event->state = PERF_EVENT_STATE_INACTIVE;
65238
65239 @@ -6491,10 +6491,10 @@ static void sync_child_event(struct perf_event *child_event,
65240 /*
65241 * Add back the child's count to the parent's count:
65242 */
65243 - atomic64_add(child_val, &parent_event->child_count);
65244 - atomic64_add(child_event->total_time_enabled,
65245 + atomic64_add_unchecked(child_val, &parent_event->child_count);
65246 + atomic64_add_unchecked(child_event->total_time_enabled,
65247 &parent_event->child_total_time_enabled);
65248 - atomic64_add(child_event->total_time_running,
65249 + atomic64_add_unchecked(child_event->total_time_running,
65250 &parent_event->child_total_time_running);
65251
65252 /*
65253 diff --git a/kernel/exit.c b/kernel/exit.c
65254 index d8bd3b42..26bd8dc 100644
65255 --- a/kernel/exit.c
65256 +++ b/kernel/exit.c
65257 @@ -59,6 +59,10 @@
65258 #include <asm/pgtable.h>
65259 #include <asm/mmu_context.h>
65260
65261 +#ifdef CONFIG_GRKERNSEC
65262 +extern rwlock_t grsec_exec_file_lock;
65263 +#endif
65264 +
65265 static void exit_mm(struct task_struct * tsk);
65266
65267 static void __unhash_process(struct task_struct *p, bool group_dead)
65268 @@ -170,6 +174,10 @@ void release_task(struct task_struct * p)
65269 struct task_struct *leader;
65270 int zap_leader;
65271 repeat:
65272 +#ifdef CONFIG_NET
65273 + gr_del_task_from_ip_table(p);
65274 +#endif
65275 +
65276 /* don't need to get the RCU readlock here - the process is dead and
65277 * can't be modifying its own credentials. But shut RCU-lockdep up */
65278 rcu_read_lock();
65279 @@ -382,7 +390,7 @@ int allow_signal(int sig)
65280 * know it'll be handled, so that they don't get converted to
65281 * SIGKILL or just silently dropped.
65282 */
65283 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
65284 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
65285 recalc_sigpending();
65286 spin_unlock_irq(&current->sighand->siglock);
65287 return 0;
65288 @@ -418,6 +426,17 @@ void daemonize(const char *name, ...)
65289 vsnprintf(current->comm, sizeof(current->comm), name, args);
65290 va_end(args);
65291
65292 +#ifdef CONFIG_GRKERNSEC
65293 + write_lock(&grsec_exec_file_lock);
65294 + if (current->exec_file) {
65295 + fput(current->exec_file);
65296 + current->exec_file = NULL;
65297 + }
65298 + write_unlock(&grsec_exec_file_lock);
65299 +#endif
65300 +
65301 + gr_set_kernel_label(current);
65302 +
65303 /*
65304 * If we were started as result of loading a module, close all of the
65305 * user space pages. We don't need them, and if we didn't close them
65306 @@ -900,6 +919,8 @@ void do_exit(long code)
65307 struct task_struct *tsk = current;
65308 int group_dead;
65309
65310 + set_fs(USER_DS);
65311 +
65312 profile_task_exit(tsk);
65313
65314 WARN_ON(blk_needs_flush_plug(tsk));
65315 @@ -916,7 +937,6 @@ void do_exit(long code)
65316 * mm_release()->clear_child_tid() from writing to a user-controlled
65317 * kernel address.
65318 */
65319 - set_fs(USER_DS);
65320
65321 ptrace_event(PTRACE_EVENT_EXIT, code);
65322
65323 @@ -977,6 +997,9 @@ void do_exit(long code)
65324 tsk->exit_code = code;
65325 taskstats_exit(tsk, group_dead);
65326
65327 + gr_acl_handle_psacct(tsk, code);
65328 + gr_acl_handle_exit();
65329 +
65330 exit_mm(tsk);
65331
65332 if (group_dead)
65333 @@ -1093,7 +1116,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
65334 * Take down every thread in the group. This is called by fatal signals
65335 * as well as by sys_exit_group (below).
65336 */
65337 -void
65338 +__noreturn void
65339 do_group_exit(int exit_code)
65340 {
65341 struct signal_struct *sig = current->signal;
65342 diff --git a/kernel/fork.c b/kernel/fork.c
65343 index 8163333..efb4692 100644
65344 --- a/kernel/fork.c
65345 +++ b/kernel/fork.c
65346 @@ -286,7 +286,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
65347 *stackend = STACK_END_MAGIC; /* for overflow detection */
65348
65349 #ifdef CONFIG_CC_STACKPROTECTOR
65350 - tsk->stack_canary = get_random_int();
65351 + tsk->stack_canary = pax_get_random_long();
65352 #endif
65353
65354 /*
65355 @@ -310,13 +310,78 @@ out:
65356 }
65357
65358 #ifdef CONFIG_MMU
65359 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
65360 +{
65361 + struct vm_area_struct *tmp;
65362 + unsigned long charge;
65363 + struct mempolicy *pol;
65364 + struct file *file;
65365 +
65366 + charge = 0;
65367 + if (mpnt->vm_flags & VM_ACCOUNT) {
65368 + unsigned long len;
65369 + len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
65370 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
65371 + goto fail_nomem;
65372 + charge = len;
65373 + }
65374 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
65375 + if (!tmp)
65376 + goto fail_nomem;
65377 + *tmp = *mpnt;
65378 + tmp->vm_mm = mm;
65379 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
65380 + pol = mpol_dup(vma_policy(mpnt));
65381 + if (IS_ERR(pol))
65382 + goto fail_nomem_policy;
65383 + vma_set_policy(tmp, pol);
65384 + if (anon_vma_fork(tmp, mpnt))
65385 + goto fail_nomem_anon_vma_fork;
65386 + tmp->vm_flags &= ~VM_LOCKED;
65387 + tmp->vm_next = tmp->vm_prev = NULL;
65388 + tmp->vm_mirror = NULL;
65389 + file = tmp->vm_file;
65390 + if (file) {
65391 + struct inode *inode = file->f_path.dentry->d_inode;
65392 + struct address_space *mapping = file->f_mapping;
65393 +
65394 + get_file(file);
65395 + if (tmp->vm_flags & VM_DENYWRITE)
65396 + atomic_dec(&inode->i_writecount);
65397 + mutex_lock(&mapping->i_mmap_mutex);
65398 + if (tmp->vm_flags & VM_SHARED)
65399 + mapping->i_mmap_writable++;
65400 + flush_dcache_mmap_lock(mapping);
65401 + /* insert tmp into the share list, just after mpnt */
65402 + vma_prio_tree_add(tmp, mpnt);
65403 + flush_dcache_mmap_unlock(mapping);
65404 + mutex_unlock(&mapping->i_mmap_mutex);
65405 + }
65406 +
65407 + /*
65408 + * Clear hugetlb-related page reserves for children. This only
65409 + * affects MAP_PRIVATE mappings. Faults generated by the child
65410 + * are not guaranteed to succeed, even if read-only
65411 + */
65412 + if (is_vm_hugetlb_page(tmp))
65413 + reset_vma_resv_huge_pages(tmp);
65414 +
65415 + return tmp;
65416 +
65417 +fail_nomem_anon_vma_fork:
65418 + mpol_put(pol);
65419 +fail_nomem_policy:
65420 + kmem_cache_free(vm_area_cachep, tmp);
65421 +fail_nomem:
65422 + vm_unacct_memory(charge);
65423 + return NULL;
65424 +}
65425 +
65426 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
65427 {
65428 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
65429 struct rb_node **rb_link, *rb_parent;
65430 int retval;
65431 - unsigned long charge;
65432 - struct mempolicy *pol;
65433
65434 down_write(&oldmm->mmap_sem);
65435 flush_cache_dup_mm(oldmm);
65436 @@ -328,8 +393,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
65437 mm->locked_vm = 0;
65438 mm->mmap = NULL;
65439 mm->mmap_cache = NULL;
65440 - mm->free_area_cache = oldmm->mmap_base;
65441 - mm->cached_hole_size = ~0UL;
65442 + mm->free_area_cache = oldmm->free_area_cache;
65443 + mm->cached_hole_size = oldmm->cached_hole_size;
65444 mm->map_count = 0;
65445 cpumask_clear(mm_cpumask(mm));
65446 mm->mm_rb = RB_ROOT;
65447 @@ -345,8 +410,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
65448
65449 prev = NULL;
65450 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
65451 - struct file *file;
65452 -
65453 if (mpnt->vm_flags & VM_DONTCOPY) {
65454 long pages = vma_pages(mpnt);
65455 mm->total_vm -= pages;
65456 @@ -354,54 +417,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
65457 -pages);
65458 continue;
65459 }
65460 - charge = 0;
65461 - if (mpnt->vm_flags & VM_ACCOUNT) {
65462 - unsigned long len;
65463 - len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
65464 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
65465 - goto fail_nomem;
65466 - charge = len;
65467 + tmp = dup_vma(mm, oldmm, mpnt);
65468 + if (!tmp) {
65469 + retval = -ENOMEM;
65470 + goto out;
65471 }
65472 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
65473 - if (!tmp)
65474 - goto fail_nomem;
65475 - *tmp = *mpnt;
65476 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
65477 - pol = mpol_dup(vma_policy(mpnt));
65478 - retval = PTR_ERR(pol);
65479 - if (IS_ERR(pol))
65480 - goto fail_nomem_policy;
65481 - vma_set_policy(tmp, pol);
65482 - tmp->vm_mm = mm;
65483 - if (anon_vma_fork(tmp, mpnt))
65484 - goto fail_nomem_anon_vma_fork;
65485 - tmp->vm_flags &= ~VM_LOCKED;
65486 - tmp->vm_next = tmp->vm_prev = NULL;
65487 - file = tmp->vm_file;
65488 - if (file) {
65489 - struct inode *inode = file->f_path.dentry->d_inode;
65490 - struct address_space *mapping = file->f_mapping;
65491 -
65492 - get_file(file);
65493 - if (tmp->vm_flags & VM_DENYWRITE)
65494 - atomic_dec(&inode->i_writecount);
65495 - mutex_lock(&mapping->i_mmap_mutex);
65496 - if (tmp->vm_flags & VM_SHARED)
65497 - mapping->i_mmap_writable++;
65498 - flush_dcache_mmap_lock(mapping);
65499 - /* insert tmp into the share list, just after mpnt */
65500 - vma_prio_tree_add(tmp, mpnt);
65501 - flush_dcache_mmap_unlock(mapping);
65502 - mutex_unlock(&mapping->i_mmap_mutex);
65503 - }
65504 -
65505 - /*
65506 - * Clear hugetlb-related page reserves for children. This only
65507 - * affects MAP_PRIVATE mappings. Faults generated by the child
65508 - * are not guaranteed to succeed, even if read-only
65509 - */
65510 - if (is_vm_hugetlb_page(tmp))
65511 - reset_vma_resv_huge_pages(tmp);
65512
65513 /*
65514 * Link in the new vma and copy the page table entries.
65515 @@ -424,6 +444,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
65516 if (retval)
65517 goto out;
65518 }
65519 +
65520 +#ifdef CONFIG_PAX_SEGMEXEC
65521 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
65522 + struct vm_area_struct *mpnt_m;
65523 +
65524 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
65525 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
65526 +
65527 + if (!mpnt->vm_mirror)
65528 + continue;
65529 +
65530 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
65531 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
65532 + mpnt->vm_mirror = mpnt_m;
65533 + } else {
65534 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
65535 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
65536 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
65537 + mpnt->vm_mirror->vm_mirror = mpnt;
65538 + }
65539 + }
65540 + BUG_ON(mpnt_m);
65541 + }
65542 +#endif
65543 +
65544 /* a new mm has just been created */
65545 arch_dup_mmap(oldmm, mm);
65546 retval = 0;
65547 @@ -432,14 +477,6 @@ out:
65548 flush_tlb_mm(oldmm);
65549 up_write(&oldmm->mmap_sem);
65550 return retval;
65551 -fail_nomem_anon_vma_fork:
65552 - mpol_put(pol);
65553 -fail_nomem_policy:
65554 - kmem_cache_free(vm_area_cachep, tmp);
65555 -fail_nomem:
65556 - retval = -ENOMEM;
65557 - vm_unacct_memory(charge);
65558 - goto out;
65559 }
65560
65561 static inline int mm_alloc_pgd(struct mm_struct *mm)
65562 @@ -676,8 +713,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
65563 return ERR_PTR(err);
65564
65565 mm = get_task_mm(task);
65566 - if (mm && mm != current->mm &&
65567 - !ptrace_may_access(task, mode)) {
65568 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
65569 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
65570 mmput(mm);
65571 mm = ERR_PTR(-EACCES);
65572 }
65573 @@ -899,13 +936,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
65574 spin_unlock(&fs->lock);
65575 return -EAGAIN;
65576 }
65577 - fs->users++;
65578 + atomic_inc(&fs->users);
65579 spin_unlock(&fs->lock);
65580 return 0;
65581 }
65582 tsk->fs = copy_fs_struct(fs);
65583 if (!tsk->fs)
65584 return -ENOMEM;
65585 + gr_set_chroot_entries(tsk, &tsk->fs->root);
65586 return 0;
65587 }
65588
65589 @@ -1172,6 +1210,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
65590 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
65591 #endif
65592 retval = -EAGAIN;
65593 +
65594 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
65595 +
65596 if (atomic_read(&p->real_cred->user->processes) >=
65597 task_rlimit(p, RLIMIT_NPROC)) {
65598 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
65599 @@ -1328,6 +1369,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
65600 if (clone_flags & CLONE_THREAD)
65601 p->tgid = current->tgid;
65602
65603 + gr_copy_label(p);
65604 +
65605 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
65606 /*
65607 * Clear TID on mm_release()?
65608 @@ -1502,6 +1545,8 @@ bad_fork_cleanup_count:
65609 bad_fork_free:
65610 free_task(p);
65611 fork_out:
65612 + gr_log_forkfail(retval);
65613 +
65614 return ERR_PTR(retval);
65615 }
65616
65617 @@ -1602,6 +1647,8 @@ long do_fork(unsigned long clone_flags,
65618 if (clone_flags & CLONE_PARENT_SETTID)
65619 put_user(nr, parent_tidptr);
65620
65621 + gr_handle_brute_check();
65622 +
65623 if (clone_flags & CLONE_VFORK) {
65624 p->vfork_done = &vfork;
65625 init_completion(&vfork);
65626 @@ -1700,7 +1747,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
65627 return 0;
65628
65629 /* don't need lock here; in the worst case we'll do useless copy */
65630 - if (fs->users == 1)
65631 + if (atomic_read(&fs->users) == 1)
65632 return 0;
65633
65634 *new_fsp = copy_fs_struct(fs);
65635 @@ -1789,7 +1836,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
65636 fs = current->fs;
65637 spin_lock(&fs->lock);
65638 current->fs = new_fs;
65639 - if (--fs->users)
65640 + gr_set_chroot_entries(current, &current->fs->root);
65641 + if (atomic_dec_return(&fs->users))
65642 new_fs = NULL;
65643 else
65644 new_fs = fs;
65645 diff --git a/kernel/futex.c b/kernel/futex.c
65646 index e2b0fb9..db818ac 100644
65647 --- a/kernel/futex.c
65648 +++ b/kernel/futex.c
65649 @@ -54,6 +54,7 @@
65650 #include <linux/mount.h>
65651 #include <linux/pagemap.h>
65652 #include <linux/syscalls.h>
65653 +#include <linux/ptrace.h>
65654 #include <linux/signal.h>
65655 #include <linux/export.h>
65656 #include <linux/magic.h>
65657 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
65658 struct page *page, *page_head;
65659 int err, ro = 0;
65660
65661 +#ifdef CONFIG_PAX_SEGMEXEC
65662 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
65663 + return -EFAULT;
65664 +#endif
65665 +
65666 /*
65667 * The futex address must be "naturally" aligned.
65668 */
65669 @@ -2711,6 +2717,7 @@ static int __init futex_init(void)
65670 {
65671 u32 curval;
65672 int i;
65673 + mm_segment_t oldfs;
65674
65675 /*
65676 * This will fail and we want it. Some arch implementations do
65677 @@ -2722,8 +2729,11 @@ static int __init futex_init(void)
65678 * implementation, the non-functional ones will return
65679 * -ENOSYS.
65680 */
65681 + oldfs = get_fs();
65682 + set_fs(USER_DS);
65683 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
65684 futex_cmpxchg_enabled = 1;
65685 + set_fs(oldfs);
65686
65687 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
65688 plist_head_init(&futex_queues[i].chain);
65689 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
65690 index 9b22d03..6295b62 100644
65691 --- a/kernel/gcov/base.c
65692 +++ b/kernel/gcov/base.c
65693 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
65694 }
65695
65696 #ifdef CONFIG_MODULES
65697 -static inline int within(void *addr, void *start, unsigned long size)
65698 -{
65699 - return ((addr >= start) && (addr < start + size));
65700 -}
65701 -
65702 /* Update list and generate events when modules are unloaded. */
65703 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
65704 void *data)
65705 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
65706 prev = NULL;
65707 /* Remove entries located in module from linked list. */
65708 for (info = gcov_info_head; info; info = info->next) {
65709 - if (within(info, mod->module_core, mod->core_size)) {
65710 + if (within_module_core_rw((unsigned long)info, mod)) {
65711 if (prev)
65712 prev->next = info->next;
65713 else
65714 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
65715 index ae34bf5..4e2f3d0 100644
65716 --- a/kernel/hrtimer.c
65717 +++ b/kernel/hrtimer.c
65718 @@ -1393,7 +1393,7 @@ void hrtimer_peek_ahead_timers(void)
65719 local_irq_restore(flags);
65720 }
65721
65722 -static void run_hrtimer_softirq(struct softirq_action *h)
65723 +static void run_hrtimer_softirq(void)
65724 {
65725 hrtimer_peek_ahead_timers();
65726 }
65727 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
65728 index 4304919..408c4c0 100644
65729 --- a/kernel/jump_label.c
65730 +++ b/kernel/jump_label.c
65731 @@ -13,6 +13,7 @@
65732 #include <linux/sort.h>
65733 #include <linux/err.h>
65734 #include <linux/static_key.h>
65735 +#include <linux/mm.h>
65736
65737 #ifdef HAVE_JUMP_LABEL
65738
65739 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
65740
65741 size = (((unsigned long)stop - (unsigned long)start)
65742 / sizeof(struct jump_entry));
65743 + pax_open_kernel();
65744 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
65745 + pax_close_kernel();
65746 }
65747
65748 static void jump_label_update(struct static_key *key, int enable);
65749 @@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
65750 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
65751 struct jump_entry *iter;
65752
65753 + pax_open_kernel();
65754 for (iter = iter_start; iter < iter_stop; iter++) {
65755 if (within_module_init(iter->code, mod))
65756 iter->code = 0;
65757 }
65758 + pax_close_kernel();
65759 }
65760
65761 static int
65762 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
65763 index 079f1d3..a407562 100644
65764 --- a/kernel/kallsyms.c
65765 +++ b/kernel/kallsyms.c
65766 @@ -11,6 +11,9 @@
65767 * Changed the compression method from stem compression to "table lookup"
65768 * compression (see scripts/kallsyms.c for a more complete description)
65769 */
65770 +#ifdef CONFIG_GRKERNSEC_HIDESYM
65771 +#define __INCLUDED_BY_HIDESYM 1
65772 +#endif
65773 #include <linux/kallsyms.h>
65774 #include <linux/module.h>
65775 #include <linux/init.h>
65776 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
65777
65778 static inline int is_kernel_inittext(unsigned long addr)
65779 {
65780 + if (system_state != SYSTEM_BOOTING)
65781 + return 0;
65782 +
65783 if (addr >= (unsigned long)_sinittext
65784 && addr <= (unsigned long)_einittext)
65785 return 1;
65786 return 0;
65787 }
65788
65789 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
65790 +#ifdef CONFIG_MODULES
65791 +static inline int is_module_text(unsigned long addr)
65792 +{
65793 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
65794 + return 1;
65795 +
65796 + addr = ktla_ktva(addr);
65797 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
65798 +}
65799 +#else
65800 +static inline int is_module_text(unsigned long addr)
65801 +{
65802 + return 0;
65803 +}
65804 +#endif
65805 +#endif
65806 +
65807 static inline int is_kernel_text(unsigned long addr)
65808 {
65809 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
65810 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
65811
65812 static inline int is_kernel(unsigned long addr)
65813 {
65814 +
65815 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
65816 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
65817 + return 1;
65818 +
65819 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
65820 +#else
65821 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
65822 +#endif
65823 +
65824 return 1;
65825 return in_gate_area_no_mm(addr);
65826 }
65827
65828 static int is_ksym_addr(unsigned long addr)
65829 {
65830 +
65831 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
65832 + if (is_module_text(addr))
65833 + return 0;
65834 +#endif
65835 +
65836 if (all_var)
65837 return is_kernel(addr);
65838
65839 @@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
65840
65841 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
65842 {
65843 - iter->name[0] = '\0';
65844 iter->nameoff = get_symbol_offset(new_pos);
65845 iter->pos = new_pos;
65846 }
65847 @@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, void *p)
65848 {
65849 struct kallsym_iter *iter = m->private;
65850
65851 +#ifdef CONFIG_GRKERNSEC_HIDESYM
65852 + if (current_uid())
65853 + return 0;
65854 +#endif
65855 +
65856 /* Some debugging symbols have no name. Ignore them. */
65857 if (!iter->name[0])
65858 return 0;
65859 @@ -540,7 +583,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
65860 struct kallsym_iter *iter;
65861 int ret;
65862
65863 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
65864 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
65865 if (!iter)
65866 return -ENOMEM;
65867 reset_iter(iter, 0);
65868 diff --git a/kernel/kexec.c b/kernel/kexec.c
65869 index 4e2e472..cd0c7ae 100644
65870 --- a/kernel/kexec.c
65871 +++ b/kernel/kexec.c
65872 @@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
65873 unsigned long flags)
65874 {
65875 struct compat_kexec_segment in;
65876 - struct kexec_segment out, __user *ksegments;
65877 + struct kexec_segment out;
65878 + struct kexec_segment __user *ksegments;
65879 unsigned long i, result;
65880
65881 /* Don't allow clients that don't understand the native
65882 diff --git a/kernel/kmod.c b/kernel/kmod.c
65883 index 05698a7..a4c1e3a 100644
65884 --- a/kernel/kmod.c
65885 +++ b/kernel/kmod.c
65886 @@ -66,7 +66,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
65887 kfree(info->argv);
65888 }
65889
65890 -static int call_modprobe(char *module_name, int wait)
65891 +static int call_modprobe(char *module_name, char *module_param, int wait)
65892 {
65893 static char *envp[] = {
65894 "HOME=/",
65895 @@ -75,7 +75,7 @@ static int call_modprobe(char *module_name, int wait)
65896 NULL
65897 };
65898
65899 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
65900 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
65901 if (!argv)
65902 goto out;
65903
65904 @@ -87,7 +87,8 @@ static int call_modprobe(char *module_name, int wait)
65905 argv[1] = "-q";
65906 argv[2] = "--";
65907 argv[3] = module_name; /* check free_modprobe_argv() */
65908 - argv[4] = NULL;
65909 + argv[4] = module_param;
65910 + argv[5] = NULL;
65911
65912 return call_usermodehelper_fns(modprobe_path, argv, envp,
65913 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
65914 @@ -112,9 +113,8 @@ out:
65915 * If module auto-loading support is disabled then this function
65916 * becomes a no-operation.
65917 */
65918 -int __request_module(bool wait, const char *fmt, ...)
65919 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
65920 {
65921 - va_list args;
65922 char module_name[MODULE_NAME_LEN];
65923 unsigned int max_modprobes;
65924 int ret;
65925 @@ -122,9 +122,7 @@ int __request_module(bool wait, const char *fmt, ...)
65926 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
65927 static int kmod_loop_msg;
65928
65929 - va_start(args, fmt);
65930 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
65931 - va_end(args);
65932 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
65933 if (ret >= MODULE_NAME_LEN)
65934 return -ENAMETOOLONG;
65935
65936 @@ -132,6 +130,20 @@ int __request_module(bool wait, const char *fmt, ...)
65937 if (ret)
65938 return ret;
65939
65940 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
65941 + if (!current_uid()) {
65942 + /* hack to workaround consolekit/udisks stupidity */
65943 + read_lock(&tasklist_lock);
65944 + if (!strcmp(current->comm, "mount") &&
65945 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
65946 + read_unlock(&tasklist_lock);
65947 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
65948 + return -EPERM;
65949 + }
65950 + read_unlock(&tasklist_lock);
65951 + }
65952 +#endif
65953 +
65954 /* If modprobe needs a service that is in a module, we get a recursive
65955 * loop. Limit the number of running kmod threads to max_threads/2 or
65956 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
65957 @@ -160,11 +172,52 @@ int __request_module(bool wait, const char *fmt, ...)
65958
65959 trace_module_request(module_name, wait, _RET_IP_);
65960
65961 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
65962 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
65963
65964 atomic_dec(&kmod_concurrent);
65965 return ret;
65966 }
65967 +
65968 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
65969 +{
65970 + va_list args;
65971 + int ret;
65972 +
65973 + va_start(args, fmt);
65974 + ret = ____request_module(wait, module_param, fmt, args);
65975 + va_end(args);
65976 +
65977 + return ret;
65978 +}
65979 +
65980 +int __request_module(bool wait, const char *fmt, ...)
65981 +{
65982 + va_list args;
65983 + int ret;
65984 +
65985 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
65986 + if (current_uid()) {
65987 + char module_param[MODULE_NAME_LEN];
65988 +
65989 + memset(module_param, 0, sizeof(module_param));
65990 +
65991 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
65992 +
65993 + va_start(args, fmt);
65994 + ret = ____request_module(wait, module_param, fmt, args);
65995 + va_end(args);
65996 +
65997 + return ret;
65998 + }
65999 +#endif
66000 +
66001 + va_start(args, fmt);
66002 + ret = ____request_module(wait, NULL, fmt, args);
66003 + va_end(args);
66004 +
66005 + return ret;
66006 +}
66007 +
66008 EXPORT_SYMBOL(__request_module);
66009 #endif /* CONFIG_MODULES */
66010
66011 @@ -267,7 +320,7 @@ static int wait_for_helper(void *data)
66012 *
66013 * Thus the __user pointer cast is valid here.
66014 */
66015 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
66016 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
66017
66018 /*
66019 * If ret is 0, either ____call_usermodehelper failed and the
66020 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
66021 index c62b854..cb67968 100644
66022 --- a/kernel/kprobes.c
66023 +++ b/kernel/kprobes.c
66024 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
66025 * kernel image and loaded module images reside. This is required
66026 * so x86_64 can correctly handle the %rip-relative fixups.
66027 */
66028 - kip->insns = module_alloc(PAGE_SIZE);
66029 + kip->insns = module_alloc_exec(PAGE_SIZE);
66030 if (!kip->insns) {
66031 kfree(kip);
66032 return NULL;
66033 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
66034 */
66035 if (!list_is_singular(&kip->list)) {
66036 list_del(&kip->list);
66037 - module_free(NULL, kip->insns);
66038 + module_free_exec(NULL, kip->insns);
66039 kfree(kip);
66040 }
66041 return 1;
66042 @@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
66043 {
66044 int i, err = 0;
66045 unsigned long offset = 0, size = 0;
66046 - char *modname, namebuf[128];
66047 + char *modname, namebuf[KSYM_NAME_LEN];
66048 const char *symbol_name;
66049 void *addr;
66050 struct kprobe_blackpoint *kb;
66051 @@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
66052 const char *sym = NULL;
66053 unsigned int i = *(loff_t *) v;
66054 unsigned long offset = 0;
66055 - char *modname, namebuf[128];
66056 + char *modname, namebuf[KSYM_NAME_LEN];
66057
66058 head = &kprobe_table[i];
66059 preempt_disable();
66060 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
66061 index 4e316e1..5501eef 100644
66062 --- a/kernel/ksysfs.c
66063 +++ b/kernel/ksysfs.c
66064 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
66065 {
66066 if (count+1 > UEVENT_HELPER_PATH_LEN)
66067 return -ENOENT;
66068 + if (!capable(CAP_SYS_ADMIN))
66069 + return -EPERM;
66070 memcpy(uevent_helper, buf, count);
66071 uevent_helper[count] = '\0';
66072 if (count && uevent_helper[count-1] == '\n')
66073 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
66074 index ea9ee45..67ebc8f 100644
66075 --- a/kernel/lockdep.c
66076 +++ b/kernel/lockdep.c
66077 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
66078 end = (unsigned long) &_end,
66079 addr = (unsigned long) obj;
66080
66081 +#ifdef CONFIG_PAX_KERNEXEC
66082 + start = ktla_ktva(start);
66083 +#endif
66084 +
66085 /*
66086 * static variable?
66087 */
66088 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
66089 if (!static_obj(lock->key)) {
66090 debug_locks_off();
66091 printk("INFO: trying to register non-static key.\n");
66092 + printk("lock:%pS key:%pS.\n", lock, lock->key);
66093 printk("the code is fine but needs lockdep annotation.\n");
66094 printk("turning off the locking correctness validator.\n");
66095 dump_stack();
66096 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
66097 if (!class)
66098 return 0;
66099 }
66100 - atomic_inc((atomic_t *)&class->ops);
66101 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
66102 if (very_verbose(class)) {
66103 printk("\nacquire class [%p] %s", class->key, class->name);
66104 if (class->name_version > 1)
66105 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
66106 index 91c32a0..b2c71c5 100644
66107 --- a/kernel/lockdep_proc.c
66108 +++ b/kernel/lockdep_proc.c
66109 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
66110
66111 static void print_name(struct seq_file *m, struct lock_class *class)
66112 {
66113 - char str[128];
66114 + char str[KSYM_NAME_LEN];
66115 const char *name = class->name;
66116
66117 if (!name) {
66118 diff --git a/kernel/module.c b/kernel/module.c
66119 index 78ac6ec..e87db0e 100644
66120 --- a/kernel/module.c
66121 +++ b/kernel/module.c
66122 @@ -58,6 +58,7 @@
66123 #include <linux/jump_label.h>
66124 #include <linux/pfn.h>
66125 #include <linux/bsearch.h>
66126 +#include <linux/grsecurity.h>
66127
66128 #define CREATE_TRACE_POINTS
66129 #include <trace/events/module.h>
66130 @@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
66131
66132 /* Bounds of module allocation, for speeding __module_address.
66133 * Protected by module_mutex. */
66134 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
66135 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
66136 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
66137
66138 int register_module_notifier(struct notifier_block * nb)
66139 {
66140 @@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
66141 return true;
66142
66143 list_for_each_entry_rcu(mod, &modules, list) {
66144 - struct symsearch arr[] = {
66145 + struct symsearch modarr[] = {
66146 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
66147 NOT_GPL_ONLY, false },
66148 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
66149 @@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
66150 #endif
66151 };
66152
66153 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
66154 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
66155 return true;
66156 }
66157 return false;
66158 @@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
66159 static int percpu_modalloc(struct module *mod,
66160 unsigned long size, unsigned long align)
66161 {
66162 - if (align > PAGE_SIZE) {
66163 + if (align-1 >= PAGE_SIZE) {
66164 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
66165 mod->name, align, PAGE_SIZE);
66166 align = PAGE_SIZE;
66167 @@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
66168 static ssize_t show_coresize(struct module_attribute *mattr,
66169 struct module_kobject *mk, char *buffer)
66170 {
66171 - return sprintf(buffer, "%u\n", mk->mod->core_size);
66172 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
66173 }
66174
66175 static struct module_attribute modinfo_coresize =
66176 @@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
66177 static ssize_t show_initsize(struct module_attribute *mattr,
66178 struct module_kobject *mk, char *buffer)
66179 {
66180 - return sprintf(buffer, "%u\n", mk->mod->init_size);
66181 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
66182 }
66183
66184 static struct module_attribute modinfo_initsize =
66185 @@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
66186 */
66187 #ifdef CONFIG_SYSFS
66188
66189 -#ifdef CONFIG_KALLSYMS
66190 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66191 static inline bool sect_empty(const Elf_Shdr *sect)
66192 {
66193 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
66194 @@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
66195
66196 static void unset_module_core_ro_nx(struct module *mod)
66197 {
66198 - set_page_attributes(mod->module_core + mod->core_text_size,
66199 - mod->module_core + mod->core_size,
66200 + set_page_attributes(mod->module_core_rw,
66201 + mod->module_core_rw + mod->core_size_rw,
66202 set_memory_x);
66203 - set_page_attributes(mod->module_core,
66204 - mod->module_core + mod->core_ro_size,
66205 + set_page_attributes(mod->module_core_rx,
66206 + mod->module_core_rx + mod->core_size_rx,
66207 set_memory_rw);
66208 }
66209
66210 static void unset_module_init_ro_nx(struct module *mod)
66211 {
66212 - set_page_attributes(mod->module_init + mod->init_text_size,
66213 - mod->module_init + mod->init_size,
66214 + set_page_attributes(mod->module_init_rw,
66215 + mod->module_init_rw + mod->init_size_rw,
66216 set_memory_x);
66217 - set_page_attributes(mod->module_init,
66218 - mod->module_init + mod->init_ro_size,
66219 + set_page_attributes(mod->module_init_rx,
66220 + mod->module_init_rx + mod->init_size_rx,
66221 set_memory_rw);
66222 }
66223
66224 @@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
66225
66226 mutex_lock(&module_mutex);
66227 list_for_each_entry_rcu(mod, &modules, list) {
66228 - if ((mod->module_core) && (mod->core_text_size)) {
66229 - set_page_attributes(mod->module_core,
66230 - mod->module_core + mod->core_text_size,
66231 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
66232 + set_page_attributes(mod->module_core_rx,
66233 + mod->module_core_rx + mod->core_size_rx,
66234 set_memory_rw);
66235 }
66236 - if ((mod->module_init) && (mod->init_text_size)) {
66237 - set_page_attributes(mod->module_init,
66238 - mod->module_init + mod->init_text_size,
66239 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
66240 + set_page_attributes(mod->module_init_rx,
66241 + mod->module_init_rx + mod->init_size_rx,
66242 set_memory_rw);
66243 }
66244 }
66245 @@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
66246
66247 mutex_lock(&module_mutex);
66248 list_for_each_entry_rcu(mod, &modules, list) {
66249 - if ((mod->module_core) && (mod->core_text_size)) {
66250 - set_page_attributes(mod->module_core,
66251 - mod->module_core + mod->core_text_size,
66252 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
66253 + set_page_attributes(mod->module_core_rx,
66254 + mod->module_core_rx + mod->core_size_rx,
66255 set_memory_ro);
66256 }
66257 - if ((mod->module_init) && (mod->init_text_size)) {
66258 - set_page_attributes(mod->module_init,
66259 - mod->module_init + mod->init_text_size,
66260 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
66261 + set_page_attributes(mod->module_init_rx,
66262 + mod->module_init_rx + mod->init_size_rx,
66263 set_memory_ro);
66264 }
66265 }
66266 @@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
66267
66268 /* This may be NULL, but that's OK */
66269 unset_module_init_ro_nx(mod);
66270 - module_free(mod, mod->module_init);
66271 + module_free(mod, mod->module_init_rw);
66272 + module_free_exec(mod, mod->module_init_rx);
66273 kfree(mod->args);
66274 percpu_modfree(mod);
66275
66276 /* Free lock-classes: */
66277 - lockdep_free_key_range(mod->module_core, mod->core_size);
66278 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
66279 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
66280
66281 /* Finally, free the core (containing the module structure) */
66282 unset_module_core_ro_nx(mod);
66283 - module_free(mod, mod->module_core);
66284 + module_free_exec(mod, mod->module_core_rx);
66285 + module_free(mod, mod->module_core_rw);
66286
66287 #ifdef CONFIG_MPU
66288 update_protections(current->mm);
66289 @@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66290 int ret = 0;
66291 const struct kernel_symbol *ksym;
66292
66293 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66294 + int is_fs_load = 0;
66295 + int register_filesystem_found = 0;
66296 + char *p;
66297 +
66298 + p = strstr(mod->args, "grsec_modharden_fs");
66299 + if (p) {
66300 + char *endptr = p + strlen("grsec_modharden_fs");
66301 + /* copy \0 as well */
66302 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
66303 + is_fs_load = 1;
66304 + }
66305 +#endif
66306 +
66307 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
66308 const char *name = info->strtab + sym[i].st_name;
66309
66310 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66311 + /* it's a real shame this will never get ripped and copied
66312 + upstream! ;(
66313 + */
66314 + if (is_fs_load && !strcmp(name, "register_filesystem"))
66315 + register_filesystem_found = 1;
66316 +#endif
66317 +
66318 switch (sym[i].st_shndx) {
66319 case SHN_COMMON:
66320 /* We compiled with -fno-common. These are not
66321 @@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66322 ksym = resolve_symbol_wait(mod, info, name);
66323 /* Ok if resolved. */
66324 if (ksym && !IS_ERR(ksym)) {
66325 + pax_open_kernel();
66326 sym[i].st_value = ksym->value;
66327 + pax_close_kernel();
66328 break;
66329 }
66330
66331 @@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66332 secbase = (unsigned long)mod_percpu(mod);
66333 else
66334 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
66335 + pax_open_kernel();
66336 sym[i].st_value += secbase;
66337 + pax_close_kernel();
66338 break;
66339 }
66340 }
66341
66342 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66343 + if (is_fs_load && !register_filesystem_found) {
66344 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
66345 + ret = -EPERM;
66346 + }
66347 +#endif
66348 +
66349 return ret;
66350 }
66351
66352 @@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
66353 || s->sh_entsize != ~0UL
66354 || strstarts(sname, ".init"))
66355 continue;
66356 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
66357 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
66358 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
66359 + else
66360 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
66361 pr_debug("\t%s\n", sname);
66362 }
66363 - switch (m) {
66364 - case 0: /* executable */
66365 - mod->core_size = debug_align(mod->core_size);
66366 - mod->core_text_size = mod->core_size;
66367 - break;
66368 - case 1: /* RO: text and ro-data */
66369 - mod->core_size = debug_align(mod->core_size);
66370 - mod->core_ro_size = mod->core_size;
66371 - break;
66372 - case 3: /* whole core */
66373 - mod->core_size = debug_align(mod->core_size);
66374 - break;
66375 - }
66376 }
66377
66378 pr_debug("Init section allocation order:\n");
66379 @@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
66380 || s->sh_entsize != ~0UL
66381 || !strstarts(sname, ".init"))
66382 continue;
66383 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
66384 - | INIT_OFFSET_MASK);
66385 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
66386 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
66387 + else
66388 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
66389 + s->sh_entsize |= INIT_OFFSET_MASK;
66390 pr_debug("\t%s\n", sname);
66391 }
66392 - switch (m) {
66393 - case 0: /* executable */
66394 - mod->init_size = debug_align(mod->init_size);
66395 - mod->init_text_size = mod->init_size;
66396 - break;
66397 - case 1: /* RO: text and ro-data */
66398 - mod->init_size = debug_align(mod->init_size);
66399 - mod->init_ro_size = mod->init_size;
66400 - break;
66401 - case 3: /* whole init */
66402 - mod->init_size = debug_align(mod->init_size);
66403 - break;
66404 - }
66405 }
66406 }
66407
66408 @@ -2266,7 +2284,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
66409
66410 /* Put symbol section at end of init part of module. */
66411 symsect->sh_flags |= SHF_ALLOC;
66412 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
66413 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
66414 info->index.sym) | INIT_OFFSET_MASK;
66415 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
66416
66417 @@ -2281,13 +2299,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
66418 }
66419
66420 /* Append room for core symbols at end of core part. */
66421 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
66422 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
66423 - mod->core_size += strtab_size;
66424 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
66425 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
66426 + mod->core_size_rx += strtab_size;
66427
66428 /* Put string table section at end of init part of module. */
66429 strsect->sh_flags |= SHF_ALLOC;
66430 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
66431 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
66432 info->index.str) | INIT_OFFSET_MASK;
66433 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
66434 }
66435 @@ -2305,12 +2323,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
66436 /* Make sure we get permanent strtab: don't use info->strtab. */
66437 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
66438
66439 + pax_open_kernel();
66440 +
66441 /* Set types up while we still have access to sections. */
66442 for (i = 0; i < mod->num_symtab; i++)
66443 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
66444
66445 - mod->core_symtab = dst = mod->module_core + info->symoffs;
66446 - mod->core_strtab = s = mod->module_core + info->stroffs;
66447 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
66448 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
66449 src = mod->symtab;
66450 *dst = *src;
66451 *s++ = 0;
66452 @@ -2323,6 +2343,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
66453 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
66454 }
66455 mod->core_num_syms = ndst;
66456 +
66457 + pax_close_kernel();
66458 }
66459 #else
66460 static inline void layout_symtab(struct module *mod, struct load_info *info)
66461 @@ -2356,17 +2378,33 @@ void * __weak module_alloc(unsigned long size)
66462 return size == 0 ? NULL : vmalloc_exec(size);
66463 }
66464
66465 -static void *module_alloc_update_bounds(unsigned long size)
66466 +static void *module_alloc_update_bounds_rw(unsigned long size)
66467 {
66468 void *ret = module_alloc(size);
66469
66470 if (ret) {
66471 mutex_lock(&module_mutex);
66472 /* Update module bounds. */
66473 - if ((unsigned long)ret < module_addr_min)
66474 - module_addr_min = (unsigned long)ret;
66475 - if ((unsigned long)ret + size > module_addr_max)
66476 - module_addr_max = (unsigned long)ret + size;
66477 + if ((unsigned long)ret < module_addr_min_rw)
66478 + module_addr_min_rw = (unsigned long)ret;
66479 + if ((unsigned long)ret + size > module_addr_max_rw)
66480 + module_addr_max_rw = (unsigned long)ret + size;
66481 + mutex_unlock(&module_mutex);
66482 + }
66483 + return ret;
66484 +}
66485 +
66486 +static void *module_alloc_update_bounds_rx(unsigned long size)
66487 +{
66488 + void *ret = module_alloc_exec(size);
66489 +
66490 + if (ret) {
66491 + mutex_lock(&module_mutex);
66492 + /* Update module bounds. */
66493 + if ((unsigned long)ret < module_addr_min_rx)
66494 + module_addr_min_rx = (unsigned long)ret;
66495 + if ((unsigned long)ret + size > module_addr_max_rx)
66496 + module_addr_max_rx = (unsigned long)ret + size;
66497 mutex_unlock(&module_mutex);
66498 }
66499 return ret;
66500 @@ -2543,8 +2581,14 @@ static struct module *setup_load_info(struct load_info *info)
66501 static int check_modinfo(struct module *mod, struct load_info *info)
66502 {
66503 const char *modmagic = get_modinfo(info, "vermagic");
66504 + const char *license = get_modinfo(info, "license");
66505 int err;
66506
66507 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
66508 + if (!license || !license_is_gpl_compatible(license))
66509 + return -ENOEXEC;
66510 +#endif
66511 +
66512 /* This is allowed: modprobe --force will invalidate it. */
66513 if (!modmagic) {
66514 err = try_to_force_load(mod, "bad vermagic");
66515 @@ -2567,7 +2611,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
66516 }
66517
66518 /* Set up license info based on the info section */
66519 - set_license(mod, get_modinfo(info, "license"));
66520 + set_license(mod, license);
66521
66522 return 0;
66523 }
66524 @@ -2661,7 +2705,7 @@ static int move_module(struct module *mod, struct load_info *info)
66525 void *ptr;
66526
66527 /* Do the allocs. */
66528 - ptr = module_alloc_update_bounds(mod->core_size);
66529 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
66530 /*
66531 * The pointer to this block is stored in the module structure
66532 * which is inside the block. Just mark it as not being a
66533 @@ -2671,23 +2715,50 @@ static int move_module(struct module *mod, struct load_info *info)
66534 if (!ptr)
66535 return -ENOMEM;
66536
66537 - memset(ptr, 0, mod->core_size);
66538 - mod->module_core = ptr;
66539 + memset(ptr, 0, mod->core_size_rw);
66540 + mod->module_core_rw = ptr;
66541
66542 - ptr = module_alloc_update_bounds(mod->init_size);
66543 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
66544 /*
66545 * The pointer to this block is stored in the module structure
66546 * which is inside the block. This block doesn't need to be
66547 * scanned as it contains data and code that will be freed
66548 * after the module is initialized.
66549 */
66550 - kmemleak_ignore(ptr);
66551 - if (!ptr && mod->init_size) {
66552 - module_free(mod, mod->module_core);
66553 + kmemleak_not_leak(ptr);
66554 + if (!ptr && mod->init_size_rw) {
66555 + module_free(mod, mod->module_core_rw);
66556 return -ENOMEM;
66557 }
66558 - memset(ptr, 0, mod->init_size);
66559 - mod->module_init = ptr;
66560 + memset(ptr, 0, mod->init_size_rw);
66561 + mod->module_init_rw = ptr;
66562 +
66563 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
66564 + kmemleak_not_leak(ptr);
66565 + if (!ptr) {
66566 + module_free(mod, mod->module_init_rw);
66567 + module_free(mod, mod->module_core_rw);
66568 + return -ENOMEM;
66569 + }
66570 +
66571 + pax_open_kernel();
66572 + memset(ptr, 0, mod->core_size_rx);
66573 + pax_close_kernel();
66574 + mod->module_core_rx = ptr;
66575 +
66576 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
66577 + kmemleak_not_leak(ptr);
66578 + if (!ptr && mod->init_size_rx) {
66579 + module_free_exec(mod, mod->module_core_rx);
66580 + module_free(mod, mod->module_init_rw);
66581 + module_free(mod, mod->module_core_rw);
66582 + return -ENOMEM;
66583 + }
66584 +
66585 + pax_open_kernel();
66586 + memset(ptr, 0, mod->init_size_rx);
66587 + pax_close_kernel();
66588 + mod->module_init_rx = ptr;
66589
66590 /* Transfer each section which specifies SHF_ALLOC */
66591 pr_debug("final section addresses:\n");
66592 @@ -2698,16 +2769,45 @@ static int move_module(struct module *mod, struct load_info *info)
66593 if (!(shdr->sh_flags & SHF_ALLOC))
66594 continue;
66595
66596 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
66597 - dest = mod->module_init
66598 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
66599 - else
66600 - dest = mod->module_core + shdr->sh_entsize;
66601 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
66602 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
66603 + dest = mod->module_init_rw
66604 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
66605 + else
66606 + dest = mod->module_init_rx
66607 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
66608 + } else {
66609 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
66610 + dest = mod->module_core_rw + shdr->sh_entsize;
66611 + else
66612 + dest = mod->module_core_rx + shdr->sh_entsize;
66613 + }
66614 +
66615 + if (shdr->sh_type != SHT_NOBITS) {
66616 +
66617 +#ifdef CONFIG_PAX_KERNEXEC
66618 +#ifdef CONFIG_X86_64
66619 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
66620 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
66621 +#endif
66622 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
66623 + pax_open_kernel();
66624 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
66625 + pax_close_kernel();
66626 + } else
66627 +#endif
66628
66629 - if (shdr->sh_type != SHT_NOBITS)
66630 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
66631 + }
66632 /* Update sh_addr to point to copy in image. */
66633 - shdr->sh_addr = (unsigned long)dest;
66634 +
66635 +#ifdef CONFIG_PAX_KERNEXEC
66636 + if (shdr->sh_flags & SHF_EXECINSTR)
66637 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
66638 + else
66639 +#endif
66640 +
66641 + shdr->sh_addr = (unsigned long)dest;
66642 pr_debug("\t0x%lx %s\n",
66643 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
66644 }
66645 @@ -2758,12 +2858,12 @@ static void flush_module_icache(const struct module *mod)
66646 * Do it before processing of module parameters, so the module
66647 * can provide parameter accessor functions of its own.
66648 */
66649 - if (mod->module_init)
66650 - flush_icache_range((unsigned long)mod->module_init,
66651 - (unsigned long)mod->module_init
66652 - + mod->init_size);
66653 - flush_icache_range((unsigned long)mod->module_core,
66654 - (unsigned long)mod->module_core + mod->core_size);
66655 + if (mod->module_init_rx)
66656 + flush_icache_range((unsigned long)mod->module_init_rx,
66657 + (unsigned long)mod->module_init_rx
66658 + + mod->init_size_rx);
66659 + flush_icache_range((unsigned long)mod->module_core_rx,
66660 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
66661
66662 set_fs(old_fs);
66663 }
66664 @@ -2833,8 +2933,10 @@ out:
66665 static void module_deallocate(struct module *mod, struct load_info *info)
66666 {
66667 percpu_modfree(mod);
66668 - module_free(mod, mod->module_init);
66669 - module_free(mod, mod->module_core);
66670 + module_free_exec(mod, mod->module_init_rx);
66671 + module_free_exec(mod, mod->module_core_rx);
66672 + module_free(mod, mod->module_init_rw);
66673 + module_free(mod, mod->module_core_rw);
66674 }
66675
66676 int __weak module_finalize(const Elf_Ehdr *hdr,
66677 @@ -2898,9 +3000,38 @@ static struct module *load_module(void __user *umod,
66678 if (err)
66679 goto free_unload;
66680
66681 + /* Now copy in args */
66682 + mod->args = strndup_user(uargs, ~0UL >> 1);
66683 + if (IS_ERR(mod->args)) {
66684 + err = PTR_ERR(mod->args);
66685 + goto free_unload;
66686 + }
66687 +
66688 /* Set up MODINFO_ATTR fields */
66689 setup_modinfo(mod, &info);
66690
66691 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66692 + {
66693 + char *p, *p2;
66694 +
66695 + if (strstr(mod->args, "grsec_modharden_netdev")) {
66696 + 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);
66697 + err = -EPERM;
66698 + goto free_modinfo;
66699 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
66700 + p += strlen("grsec_modharden_normal");
66701 + p2 = strstr(p, "_");
66702 + if (p2) {
66703 + *p2 = '\0';
66704 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
66705 + *p2 = '_';
66706 + }
66707 + err = -EPERM;
66708 + goto free_modinfo;
66709 + }
66710 + }
66711 +#endif
66712 +
66713 /* Fix up syms, so that st_value is a pointer to location. */
66714 err = simplify_symbols(mod, &info);
66715 if (err < 0)
66716 @@ -2916,13 +3047,6 @@ static struct module *load_module(void __user *umod,
66717
66718 flush_module_icache(mod);
66719
66720 - /* Now copy in args */
66721 - mod->args = strndup_user(uargs, ~0UL >> 1);
66722 - if (IS_ERR(mod->args)) {
66723 - err = PTR_ERR(mod->args);
66724 - goto free_arch_cleanup;
66725 - }
66726 -
66727 /* Mark state as coming so strong_try_module_get() ignores us. */
66728 mod->state = MODULE_STATE_COMING;
66729
66730 @@ -2980,11 +3104,10 @@ static struct module *load_module(void __user *umod,
66731 unlock:
66732 mutex_unlock(&module_mutex);
66733 synchronize_sched();
66734 - kfree(mod->args);
66735 - free_arch_cleanup:
66736 module_arch_cleanup(mod);
66737 free_modinfo:
66738 free_modinfo(mod);
66739 + kfree(mod->args);
66740 free_unload:
66741 module_unload_free(mod);
66742 free_module:
66743 @@ -3025,16 +3148,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
66744 MODULE_STATE_COMING, mod);
66745
66746 /* Set RO and NX regions for core */
66747 - set_section_ro_nx(mod->module_core,
66748 - mod->core_text_size,
66749 - mod->core_ro_size,
66750 - mod->core_size);
66751 + set_section_ro_nx(mod->module_core_rx,
66752 + mod->core_size_rx,
66753 + mod->core_size_rx,
66754 + mod->core_size_rx);
66755
66756 /* Set RO and NX regions for init */
66757 - set_section_ro_nx(mod->module_init,
66758 - mod->init_text_size,
66759 - mod->init_ro_size,
66760 - mod->init_size);
66761 + set_section_ro_nx(mod->module_init_rx,
66762 + mod->init_size_rx,
66763 + mod->init_size_rx,
66764 + mod->init_size_rx);
66765
66766 do_mod_ctors(mod);
66767 /* Start the module */
66768 @@ -3080,11 +3203,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
66769 mod->strtab = mod->core_strtab;
66770 #endif
66771 unset_module_init_ro_nx(mod);
66772 - module_free(mod, mod->module_init);
66773 - mod->module_init = NULL;
66774 - mod->init_size = 0;
66775 - mod->init_ro_size = 0;
66776 - mod->init_text_size = 0;
66777 + module_free(mod, mod->module_init_rw);
66778 + module_free_exec(mod, mod->module_init_rx);
66779 + mod->module_init_rw = NULL;
66780 + mod->module_init_rx = NULL;
66781 + mod->init_size_rw = 0;
66782 + mod->init_size_rx = 0;
66783 mutex_unlock(&module_mutex);
66784
66785 return 0;
66786 @@ -3115,10 +3239,16 @@ static const char *get_ksymbol(struct module *mod,
66787 unsigned long nextval;
66788
66789 /* At worse, next value is at end of module */
66790 - if (within_module_init(addr, mod))
66791 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
66792 + if (within_module_init_rx(addr, mod))
66793 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
66794 + else if (within_module_init_rw(addr, mod))
66795 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
66796 + else if (within_module_core_rx(addr, mod))
66797 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
66798 + else if (within_module_core_rw(addr, mod))
66799 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
66800 else
66801 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
66802 + return NULL;
66803
66804 /* Scan for closest preceding symbol, and next symbol. (ELF
66805 starts real symbols at 1). */
66806 @@ -3353,7 +3483,7 @@ static int m_show(struct seq_file *m, void *p)
66807 char buf[8];
66808
66809 seq_printf(m, "%s %u",
66810 - mod->name, mod->init_size + mod->core_size);
66811 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
66812 print_unload_info(m, mod);
66813
66814 /* Informative for users. */
66815 @@ -3362,7 +3492,7 @@ static int m_show(struct seq_file *m, void *p)
66816 mod->state == MODULE_STATE_COMING ? "Loading":
66817 "Live");
66818 /* Used by oprofile and other similar tools. */
66819 - seq_printf(m, " 0x%pK", mod->module_core);
66820 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
66821
66822 /* Taints info */
66823 if (mod->taints)
66824 @@ -3398,7 +3528,17 @@ static const struct file_operations proc_modules_operations = {
66825
66826 static int __init proc_modules_init(void)
66827 {
66828 +#ifndef CONFIG_GRKERNSEC_HIDESYM
66829 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66830 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
66831 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66832 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
66833 +#else
66834 proc_create("modules", 0, NULL, &proc_modules_operations);
66835 +#endif
66836 +#else
66837 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
66838 +#endif
66839 return 0;
66840 }
66841 module_init(proc_modules_init);
66842 @@ -3457,12 +3597,12 @@ struct module *__module_address(unsigned long addr)
66843 {
66844 struct module *mod;
66845
66846 - if (addr < module_addr_min || addr > module_addr_max)
66847 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
66848 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
66849 return NULL;
66850
66851 list_for_each_entry_rcu(mod, &modules, list)
66852 - if (within_module_core(addr, mod)
66853 - || within_module_init(addr, mod))
66854 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
66855 return mod;
66856 return NULL;
66857 }
66858 @@ -3496,11 +3636,20 @@ bool is_module_text_address(unsigned long addr)
66859 */
66860 struct module *__module_text_address(unsigned long addr)
66861 {
66862 - struct module *mod = __module_address(addr);
66863 + struct module *mod;
66864 +
66865 +#ifdef CONFIG_X86_32
66866 + addr = ktla_ktva(addr);
66867 +#endif
66868 +
66869 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
66870 + return NULL;
66871 +
66872 + mod = __module_address(addr);
66873 +
66874 if (mod) {
66875 /* Make sure it's within the text section. */
66876 - if (!within(addr, mod->module_init, mod->init_text_size)
66877 - && !within(addr, mod->module_core, mod->core_text_size))
66878 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
66879 mod = NULL;
66880 }
66881 return mod;
66882 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
66883 index 7e3443f..b2a1e6b 100644
66884 --- a/kernel/mutex-debug.c
66885 +++ b/kernel/mutex-debug.c
66886 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
66887 }
66888
66889 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
66890 - struct thread_info *ti)
66891 + struct task_struct *task)
66892 {
66893 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
66894
66895 /* Mark the current thread as blocked on the lock: */
66896 - ti->task->blocked_on = waiter;
66897 + task->blocked_on = waiter;
66898 }
66899
66900 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
66901 - struct thread_info *ti)
66902 + struct task_struct *task)
66903 {
66904 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
66905 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
66906 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
66907 - ti->task->blocked_on = NULL;
66908 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
66909 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
66910 + task->blocked_on = NULL;
66911
66912 list_del_init(&waiter->list);
66913 waiter->task = NULL;
66914 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
66915 index 0799fd3..d06ae3b 100644
66916 --- a/kernel/mutex-debug.h
66917 +++ b/kernel/mutex-debug.h
66918 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
66919 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
66920 extern void debug_mutex_add_waiter(struct mutex *lock,
66921 struct mutex_waiter *waiter,
66922 - struct thread_info *ti);
66923 + struct task_struct *task);
66924 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
66925 - struct thread_info *ti);
66926 + struct task_struct *task);
66927 extern void debug_mutex_unlock(struct mutex *lock);
66928 extern void debug_mutex_init(struct mutex *lock, const char *name,
66929 struct lock_class_key *key);
66930 diff --git a/kernel/mutex.c b/kernel/mutex.c
66931 index a307cc9..27fd2e9 100644
66932 --- a/kernel/mutex.c
66933 +++ b/kernel/mutex.c
66934 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
66935 spin_lock_mutex(&lock->wait_lock, flags);
66936
66937 debug_mutex_lock_common(lock, &waiter);
66938 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
66939 + debug_mutex_add_waiter(lock, &waiter, task);
66940
66941 /* add waiting tasks to the end of the waitqueue (FIFO): */
66942 list_add_tail(&waiter.list, &lock->wait_list);
66943 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
66944 * TASK_UNINTERRUPTIBLE case.)
66945 */
66946 if (unlikely(signal_pending_state(state, task))) {
66947 - mutex_remove_waiter(lock, &waiter,
66948 - task_thread_info(task));
66949 + mutex_remove_waiter(lock, &waiter, task);
66950 mutex_release(&lock->dep_map, 1, ip);
66951 spin_unlock_mutex(&lock->wait_lock, flags);
66952
66953 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
66954 done:
66955 lock_acquired(&lock->dep_map, ip);
66956 /* got the lock - rejoice! */
66957 - mutex_remove_waiter(lock, &waiter, current_thread_info());
66958 + mutex_remove_waiter(lock, &waiter, task);
66959 mutex_set_owner(lock);
66960
66961 /* set it to 0 if there are no waiters left: */
66962 diff --git a/kernel/panic.c b/kernel/panic.c
66963 index 9ed023b..e49543e 100644
66964 --- a/kernel/panic.c
66965 +++ b/kernel/panic.c
66966 @@ -402,7 +402,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
66967 const char *board;
66968
66969 printk(KERN_WARNING "------------[ cut here ]------------\n");
66970 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
66971 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
66972 board = dmi_get_system_info(DMI_PRODUCT_NAME);
66973 if (board)
66974 printk(KERN_WARNING "Hardware name: %s\n", board);
66975 @@ -457,7 +457,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
66976 */
66977 void __stack_chk_fail(void)
66978 {
66979 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
66980 + dump_stack();
66981 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
66982 __builtin_return_address(0));
66983 }
66984 EXPORT_SYMBOL(__stack_chk_fail);
66985 diff --git a/kernel/pid.c b/kernel/pid.c
66986 index 9f08dfa..6765c40 100644
66987 --- a/kernel/pid.c
66988 +++ b/kernel/pid.c
66989 @@ -33,6 +33,7 @@
66990 #include <linux/rculist.h>
66991 #include <linux/bootmem.h>
66992 #include <linux/hash.h>
66993 +#include <linux/security.h>
66994 #include <linux/pid_namespace.h>
66995 #include <linux/init_task.h>
66996 #include <linux/syscalls.h>
66997 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
66998
66999 int pid_max = PID_MAX_DEFAULT;
67000
67001 -#define RESERVED_PIDS 300
67002 +#define RESERVED_PIDS 500
67003
67004 int pid_max_min = RESERVED_PIDS + 1;
67005 int pid_max_max = PID_MAX_LIMIT;
67006 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
67007 */
67008 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
67009 {
67010 + struct task_struct *task;
67011 +
67012 rcu_lockdep_assert(rcu_read_lock_held(),
67013 "find_task_by_pid_ns() needs rcu_read_lock()"
67014 " protection");
67015 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
67016 +
67017 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
67018 +
67019 + if (gr_pid_is_chrooted(task))
67020 + return NULL;
67021 +
67022 + return task;
67023 }
67024
67025 struct task_struct *find_task_by_vpid(pid_t vnr)
67026 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
67027 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
67028 }
67029
67030 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
67031 +{
67032 + rcu_lockdep_assert(rcu_read_lock_held(),
67033 + "find_task_by_pid_ns() needs rcu_read_lock()"
67034 + " protection");
67035 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
67036 +}
67037 +
67038 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
67039 {
67040 struct pid *pid;
67041 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
67042 index 125cb67..a4d1c30 100644
67043 --- a/kernel/posix-cpu-timers.c
67044 +++ b/kernel/posix-cpu-timers.c
67045 @@ -6,6 +6,7 @@
67046 #include <linux/posix-timers.h>
67047 #include <linux/errno.h>
67048 #include <linux/math64.h>
67049 +#include <linux/security.h>
67050 #include <asm/uaccess.h>
67051 #include <linux/kernel_stat.h>
67052 #include <trace/events/timer.h>
67053 @@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
67054
67055 static __init int init_posix_cpu_timers(void)
67056 {
67057 - struct k_clock process = {
67058 + static struct k_clock process = {
67059 .clock_getres = process_cpu_clock_getres,
67060 .clock_get = process_cpu_clock_get,
67061 .timer_create = process_cpu_timer_create,
67062 .nsleep = process_cpu_nsleep,
67063 .nsleep_restart = process_cpu_nsleep_restart,
67064 };
67065 - struct k_clock thread = {
67066 + static struct k_clock thread = {
67067 .clock_getres = thread_cpu_clock_getres,
67068 .clock_get = thread_cpu_clock_get,
67069 .timer_create = thread_cpu_timer_create,
67070 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
67071 index 69185ae..cc2847a 100644
67072 --- a/kernel/posix-timers.c
67073 +++ b/kernel/posix-timers.c
67074 @@ -43,6 +43,7 @@
67075 #include <linux/idr.h>
67076 #include <linux/posix-clock.h>
67077 #include <linux/posix-timers.h>
67078 +#include <linux/grsecurity.h>
67079 #include <linux/syscalls.h>
67080 #include <linux/wait.h>
67081 #include <linux/workqueue.h>
67082 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
67083 * which we beg off on and pass to do_sys_settimeofday().
67084 */
67085
67086 -static struct k_clock posix_clocks[MAX_CLOCKS];
67087 +static struct k_clock *posix_clocks[MAX_CLOCKS];
67088
67089 /*
67090 * These ones are defined below.
67091 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
67092 */
67093 static __init int init_posix_timers(void)
67094 {
67095 - struct k_clock clock_realtime = {
67096 + static struct k_clock clock_realtime = {
67097 .clock_getres = hrtimer_get_res,
67098 .clock_get = posix_clock_realtime_get,
67099 .clock_set = posix_clock_realtime_set,
67100 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
67101 .timer_get = common_timer_get,
67102 .timer_del = common_timer_del,
67103 };
67104 - struct k_clock clock_monotonic = {
67105 + static struct k_clock clock_monotonic = {
67106 .clock_getres = hrtimer_get_res,
67107 .clock_get = posix_ktime_get_ts,
67108 .nsleep = common_nsleep,
67109 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
67110 .timer_get = common_timer_get,
67111 .timer_del = common_timer_del,
67112 };
67113 - struct k_clock clock_monotonic_raw = {
67114 + static struct k_clock clock_monotonic_raw = {
67115 .clock_getres = hrtimer_get_res,
67116 .clock_get = posix_get_monotonic_raw,
67117 };
67118 - struct k_clock clock_realtime_coarse = {
67119 + static struct k_clock clock_realtime_coarse = {
67120 .clock_getres = posix_get_coarse_res,
67121 .clock_get = posix_get_realtime_coarse,
67122 };
67123 - struct k_clock clock_monotonic_coarse = {
67124 + static struct k_clock clock_monotonic_coarse = {
67125 .clock_getres = posix_get_coarse_res,
67126 .clock_get = posix_get_monotonic_coarse,
67127 };
67128 - struct k_clock clock_boottime = {
67129 + static struct k_clock clock_boottime = {
67130 .clock_getres = hrtimer_get_res,
67131 .clock_get = posix_get_boottime,
67132 .nsleep = common_nsleep,
67133 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
67134 return;
67135 }
67136
67137 - posix_clocks[clock_id] = *new_clock;
67138 + posix_clocks[clock_id] = new_clock;
67139 }
67140 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
67141
67142 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
67143 return (id & CLOCKFD_MASK) == CLOCKFD ?
67144 &clock_posix_dynamic : &clock_posix_cpu;
67145
67146 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
67147 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
67148 return NULL;
67149 - return &posix_clocks[id];
67150 + return posix_clocks[id];
67151 }
67152
67153 static int common_timer_create(struct k_itimer *new_timer)
67154 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
67155 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
67156 return -EFAULT;
67157
67158 + /* only the CLOCK_REALTIME clock can be set, all other clocks
67159 + have their clock_set fptr set to a nosettime dummy function
67160 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
67161 + call common_clock_set, which calls do_sys_settimeofday, which
67162 + we hook
67163 + */
67164 +
67165 return kc->clock_set(which_clock, &new_tp);
67166 }
67167
67168 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
67169 index d523593..68197a4 100644
67170 --- a/kernel/power/poweroff.c
67171 +++ b/kernel/power/poweroff.c
67172 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
67173 .enable_mask = SYSRQ_ENABLE_BOOT,
67174 };
67175
67176 -static int pm_sysrq_init(void)
67177 +static int __init pm_sysrq_init(void)
67178 {
67179 register_sysrq_key('o', &sysrq_poweroff_op);
67180 return 0;
67181 diff --git a/kernel/power/process.c b/kernel/power/process.c
67182 index 19db29f..33b52b6 100644
67183 --- a/kernel/power/process.c
67184 +++ b/kernel/power/process.c
67185 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
67186 u64 elapsed_csecs64;
67187 unsigned int elapsed_csecs;
67188 bool wakeup = false;
67189 + bool timedout = false;
67190
67191 do_gettimeofday(&start);
67192
67193 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
67194
67195 while (true) {
67196 todo = 0;
67197 + if (time_after(jiffies, end_time))
67198 + timedout = true;
67199 read_lock(&tasklist_lock);
67200 do_each_thread(g, p) {
67201 if (p == current || !freeze_task(p))
67202 @@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
67203 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
67204 * transition can't race with task state testing here.
67205 */
67206 - if (!task_is_stopped_or_traced(p) &&
67207 - !freezer_should_skip(p))
67208 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
67209 todo++;
67210 + if (timedout) {
67211 + printk(KERN_ERR "Task refusing to freeze:\n");
67212 + sched_show_task(p);
67213 + }
67214 + }
67215 } while_each_thread(g, p);
67216 read_unlock(&tasklist_lock);
67217
67218 @@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
67219 todo += wq_busy;
67220 }
67221
67222 - if (!todo || time_after(jiffies, end_time))
67223 + if (!todo || timedout)
67224 break;
67225
67226 if (pm_wakeup_pending()) {
67227 diff --git a/kernel/printk.c b/kernel/printk.c
67228 index b663c2c..1d6ba7a 100644
67229 --- a/kernel/printk.c
67230 +++ b/kernel/printk.c
67231 @@ -316,6 +316,11 @@ static int check_syslog_permissions(int type, bool from_file)
67232 if (from_file && type != SYSLOG_ACTION_OPEN)
67233 return 0;
67234
67235 +#ifdef CONFIG_GRKERNSEC_DMESG
67236 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
67237 + return -EPERM;
67238 +#endif
67239 +
67240 if (syslog_action_restricted(type)) {
67241 if (capable(CAP_SYSLOG))
67242 return 0;
67243 diff --git a/kernel/profile.c b/kernel/profile.c
67244 index 76b8e77..a2930e8 100644
67245 --- a/kernel/profile.c
67246 +++ b/kernel/profile.c
67247 @@ -39,7 +39,7 @@ struct profile_hit {
67248 /* Oprofile timer tick hook */
67249 static int (*timer_hook)(struct pt_regs *) __read_mostly;
67250
67251 -static atomic_t *prof_buffer;
67252 +static atomic_unchecked_t *prof_buffer;
67253 static unsigned long prof_len, prof_shift;
67254
67255 int prof_on __read_mostly;
67256 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
67257 hits[i].pc = 0;
67258 continue;
67259 }
67260 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
67261 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
67262 hits[i].hits = hits[i].pc = 0;
67263 }
67264 }
67265 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
67266 * Add the current hit(s) and flush the write-queue out
67267 * to the global buffer:
67268 */
67269 - atomic_add(nr_hits, &prof_buffer[pc]);
67270 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
67271 for (i = 0; i < NR_PROFILE_HIT; ++i) {
67272 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
67273 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
67274 hits[i].pc = hits[i].hits = 0;
67275 }
67276 out:
67277 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
67278 {
67279 unsigned long pc;
67280 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
67281 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
67282 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
67283 }
67284 #endif /* !CONFIG_SMP */
67285
67286 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
67287 return -EFAULT;
67288 buf++; p++; count--; read++;
67289 }
67290 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
67291 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
67292 if (copy_to_user(buf, (void *)pnt, count))
67293 return -EFAULT;
67294 read += count;
67295 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
67296 }
67297 #endif
67298 profile_discard_flip_buffers();
67299 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
67300 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
67301 return count;
67302 }
67303
67304 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
67305 index ee8d49b..bd3d790 100644
67306 --- a/kernel/ptrace.c
67307 +++ b/kernel/ptrace.c
67308 @@ -280,7 +280,7 @@ static int ptrace_attach(struct task_struct *task, long request,
67309
67310 if (seize)
67311 flags |= PT_SEIZED;
67312 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
67313 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
67314 flags |= PT_PTRACE_CAP;
67315 task->ptrace = flags;
67316
67317 @@ -487,7 +487,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
67318 break;
67319 return -EIO;
67320 }
67321 - if (copy_to_user(dst, buf, retval))
67322 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
67323 return -EFAULT;
67324 copied += retval;
67325 src += retval;
67326 @@ -672,7 +672,7 @@ int ptrace_request(struct task_struct *child, long request,
67327 bool seized = child->ptrace & PT_SEIZED;
67328 int ret = -EIO;
67329 siginfo_t siginfo, *si;
67330 - void __user *datavp = (void __user *) data;
67331 + void __user *datavp = (__force void __user *) data;
67332 unsigned long __user *datalp = datavp;
67333 unsigned long flags;
67334
67335 @@ -874,14 +874,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
67336 goto out;
67337 }
67338
67339 + if (gr_handle_ptrace(child, request)) {
67340 + ret = -EPERM;
67341 + goto out_put_task_struct;
67342 + }
67343 +
67344 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
67345 ret = ptrace_attach(child, request, addr, data);
67346 /*
67347 * Some architectures need to do book-keeping after
67348 * a ptrace attach.
67349 */
67350 - if (!ret)
67351 + if (!ret) {
67352 arch_ptrace_attach(child);
67353 + gr_audit_ptrace(child);
67354 + }
67355 goto out_put_task_struct;
67356 }
67357
67358 @@ -907,7 +914,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
67359 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
67360 if (copied != sizeof(tmp))
67361 return -EIO;
67362 - return put_user(tmp, (unsigned long __user *)data);
67363 + return put_user(tmp, (__force unsigned long __user *)data);
67364 }
67365
67366 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
67367 @@ -1017,14 +1024,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
67368 goto out;
67369 }
67370
67371 + if (gr_handle_ptrace(child, request)) {
67372 + ret = -EPERM;
67373 + goto out_put_task_struct;
67374 + }
67375 +
67376 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
67377 ret = ptrace_attach(child, request, addr, data);
67378 /*
67379 * Some architectures need to do book-keeping after
67380 * a ptrace attach.
67381 */
67382 - if (!ret)
67383 + if (!ret) {
67384 arch_ptrace_attach(child);
67385 + gr_audit_ptrace(child);
67386 + }
67387 goto out_put_task_struct;
67388 }
67389
67390 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
67391 index 37a5444..eec170a 100644
67392 --- a/kernel/rcutiny.c
67393 +++ b/kernel/rcutiny.c
67394 @@ -46,7 +46,7 @@
67395 struct rcu_ctrlblk;
67396 static void invoke_rcu_callbacks(void);
67397 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
67398 -static void rcu_process_callbacks(struct softirq_action *unused);
67399 +static void rcu_process_callbacks(void);
67400 static void __call_rcu(struct rcu_head *head,
67401 void (*func)(struct rcu_head *rcu),
67402 struct rcu_ctrlblk *rcp);
67403 @@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
67404 rcu_is_callbacks_kthread()));
67405 }
67406
67407 -static void rcu_process_callbacks(struct softirq_action *unused)
67408 +static void rcu_process_callbacks(void)
67409 {
67410 __rcu_process_callbacks(&rcu_sched_ctrlblk);
67411 __rcu_process_callbacks(&rcu_bh_ctrlblk);
67412 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
67413 index 22ecea0..3789898 100644
67414 --- a/kernel/rcutiny_plugin.h
67415 +++ b/kernel/rcutiny_plugin.h
67416 @@ -955,7 +955,7 @@ static int rcu_kthread(void *arg)
67417 have_rcu_kthread_work = morework;
67418 local_irq_restore(flags);
67419 if (work)
67420 - rcu_process_callbacks(NULL);
67421 + rcu_process_callbacks();
67422 schedule_timeout_interruptible(1); /* Leave CPU for others. */
67423 }
67424
67425 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
67426 index a89b381..efdcad8 100644
67427 --- a/kernel/rcutorture.c
67428 +++ b/kernel/rcutorture.c
67429 @@ -158,12 +158,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
67430 { 0 };
67431 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
67432 { 0 };
67433 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
67434 -static atomic_t n_rcu_torture_alloc;
67435 -static atomic_t n_rcu_torture_alloc_fail;
67436 -static atomic_t n_rcu_torture_free;
67437 -static atomic_t n_rcu_torture_mberror;
67438 -static atomic_t n_rcu_torture_error;
67439 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
67440 +static atomic_unchecked_t n_rcu_torture_alloc;
67441 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
67442 +static atomic_unchecked_t n_rcu_torture_free;
67443 +static atomic_unchecked_t n_rcu_torture_mberror;
67444 +static atomic_unchecked_t n_rcu_torture_error;
67445 static long n_rcu_torture_boost_ktrerror;
67446 static long n_rcu_torture_boost_rterror;
67447 static long n_rcu_torture_boost_failure;
67448 @@ -253,11 +253,11 @@ rcu_torture_alloc(void)
67449
67450 spin_lock_bh(&rcu_torture_lock);
67451 if (list_empty(&rcu_torture_freelist)) {
67452 - atomic_inc(&n_rcu_torture_alloc_fail);
67453 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
67454 spin_unlock_bh(&rcu_torture_lock);
67455 return NULL;
67456 }
67457 - atomic_inc(&n_rcu_torture_alloc);
67458 + atomic_inc_unchecked(&n_rcu_torture_alloc);
67459 p = rcu_torture_freelist.next;
67460 list_del_init(p);
67461 spin_unlock_bh(&rcu_torture_lock);
67462 @@ -270,7 +270,7 @@ rcu_torture_alloc(void)
67463 static void
67464 rcu_torture_free(struct rcu_torture *p)
67465 {
67466 - atomic_inc(&n_rcu_torture_free);
67467 + atomic_inc_unchecked(&n_rcu_torture_free);
67468 spin_lock_bh(&rcu_torture_lock);
67469 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
67470 spin_unlock_bh(&rcu_torture_lock);
67471 @@ -390,7 +390,7 @@ rcu_torture_cb(struct rcu_head *p)
67472 i = rp->rtort_pipe_count;
67473 if (i > RCU_TORTURE_PIPE_LEN)
67474 i = RCU_TORTURE_PIPE_LEN;
67475 - atomic_inc(&rcu_torture_wcount[i]);
67476 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
67477 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
67478 rp->rtort_mbtest = 0;
67479 rcu_torture_free(rp);
67480 @@ -437,7 +437,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
67481 i = rp->rtort_pipe_count;
67482 if (i > RCU_TORTURE_PIPE_LEN)
67483 i = RCU_TORTURE_PIPE_LEN;
67484 - atomic_inc(&rcu_torture_wcount[i]);
67485 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
67486 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
67487 rp->rtort_mbtest = 0;
67488 list_del(&rp->rtort_free);
67489 @@ -926,7 +926,7 @@ rcu_torture_writer(void *arg)
67490 i = old_rp->rtort_pipe_count;
67491 if (i > RCU_TORTURE_PIPE_LEN)
67492 i = RCU_TORTURE_PIPE_LEN;
67493 - atomic_inc(&rcu_torture_wcount[i]);
67494 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
67495 old_rp->rtort_pipe_count++;
67496 cur_ops->deferred_free(old_rp);
67497 }
67498 @@ -1007,7 +1007,7 @@ static void rcu_torture_timer(unsigned long unused)
67499 }
67500 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
67501 if (p->rtort_mbtest == 0)
67502 - atomic_inc(&n_rcu_torture_mberror);
67503 + atomic_inc_unchecked(&n_rcu_torture_mberror);
67504 spin_lock(&rand_lock);
67505 cur_ops->read_delay(&rand);
67506 n_rcu_torture_timers++;
67507 @@ -1071,7 +1071,7 @@ rcu_torture_reader(void *arg)
67508 }
67509 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
67510 if (p->rtort_mbtest == 0)
67511 - atomic_inc(&n_rcu_torture_mberror);
67512 + atomic_inc_unchecked(&n_rcu_torture_mberror);
67513 cur_ops->read_delay(&rand);
67514 preempt_disable();
67515 pipe_count = p->rtort_pipe_count;
67516 @@ -1133,10 +1133,10 @@ rcu_torture_printk(char *page)
67517 rcu_torture_current,
67518 rcu_torture_current_version,
67519 list_empty(&rcu_torture_freelist),
67520 - atomic_read(&n_rcu_torture_alloc),
67521 - atomic_read(&n_rcu_torture_alloc_fail),
67522 - atomic_read(&n_rcu_torture_free),
67523 - atomic_read(&n_rcu_torture_mberror),
67524 + atomic_read_unchecked(&n_rcu_torture_alloc),
67525 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
67526 + atomic_read_unchecked(&n_rcu_torture_free),
67527 + atomic_read_unchecked(&n_rcu_torture_mberror),
67528 n_rcu_torture_boost_ktrerror,
67529 n_rcu_torture_boost_rterror,
67530 n_rcu_torture_boost_failure,
67531 @@ -1146,7 +1146,7 @@ rcu_torture_printk(char *page)
67532 n_online_attempts,
67533 n_offline_successes,
67534 n_offline_attempts);
67535 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
67536 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
67537 n_rcu_torture_boost_ktrerror != 0 ||
67538 n_rcu_torture_boost_rterror != 0 ||
67539 n_rcu_torture_boost_failure != 0)
67540 @@ -1154,7 +1154,7 @@ rcu_torture_printk(char *page)
67541 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
67542 if (i > 1) {
67543 cnt += sprintf(&page[cnt], "!!! ");
67544 - atomic_inc(&n_rcu_torture_error);
67545 + atomic_inc_unchecked(&n_rcu_torture_error);
67546 WARN_ON_ONCE(1);
67547 }
67548 cnt += sprintf(&page[cnt], "Reader Pipe: ");
67549 @@ -1168,7 +1168,7 @@ rcu_torture_printk(char *page)
67550 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
67551 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
67552 cnt += sprintf(&page[cnt], " %d",
67553 - atomic_read(&rcu_torture_wcount[i]));
67554 + atomic_read_unchecked(&rcu_torture_wcount[i]));
67555 }
67556 cnt += sprintf(&page[cnt], "\n");
67557 if (cur_ops->stats)
67558 @@ -1676,7 +1676,7 @@ rcu_torture_cleanup(void)
67559
67560 if (cur_ops->cleanup)
67561 cur_ops->cleanup();
67562 - if (atomic_read(&n_rcu_torture_error))
67563 + if (atomic_read_unchecked(&n_rcu_torture_error))
67564 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
67565 else if (n_online_successes != n_online_attempts ||
67566 n_offline_successes != n_offline_attempts)
67567 @@ -1744,17 +1744,17 @@ rcu_torture_init(void)
67568
67569 rcu_torture_current = NULL;
67570 rcu_torture_current_version = 0;
67571 - atomic_set(&n_rcu_torture_alloc, 0);
67572 - atomic_set(&n_rcu_torture_alloc_fail, 0);
67573 - atomic_set(&n_rcu_torture_free, 0);
67574 - atomic_set(&n_rcu_torture_mberror, 0);
67575 - atomic_set(&n_rcu_torture_error, 0);
67576 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
67577 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
67578 + atomic_set_unchecked(&n_rcu_torture_free, 0);
67579 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
67580 + atomic_set_unchecked(&n_rcu_torture_error, 0);
67581 n_rcu_torture_boost_ktrerror = 0;
67582 n_rcu_torture_boost_rterror = 0;
67583 n_rcu_torture_boost_failure = 0;
67584 n_rcu_torture_boosts = 0;
67585 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
67586 - atomic_set(&rcu_torture_wcount[i], 0);
67587 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
67588 for_each_possible_cpu(cpu) {
67589 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
67590 per_cpu(rcu_torture_count, cpu)[i] = 0;
67591 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
67592 index d0c5baf..109b2e7 100644
67593 --- a/kernel/rcutree.c
67594 +++ b/kernel/rcutree.c
67595 @@ -357,9 +357,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
67596 rcu_prepare_for_idle(smp_processor_id());
67597 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
67598 smp_mb__before_atomic_inc(); /* See above. */
67599 - atomic_inc(&rdtp->dynticks);
67600 + atomic_inc_unchecked(&rdtp->dynticks);
67601 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
67602 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
67603 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
67604
67605 /*
67606 * The idle task is not permitted to enter the idle loop while
67607 @@ -448,10 +448,10 @@ void rcu_irq_exit(void)
67608 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
67609 {
67610 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
67611 - atomic_inc(&rdtp->dynticks);
67612 + atomic_inc_unchecked(&rdtp->dynticks);
67613 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
67614 smp_mb__after_atomic_inc(); /* See above. */
67615 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
67616 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
67617 rcu_cleanup_after_idle(smp_processor_id());
67618 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
67619 if (!is_idle_task(current)) {
67620 @@ -545,14 +545,14 @@ void rcu_nmi_enter(void)
67621 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
67622
67623 if (rdtp->dynticks_nmi_nesting == 0 &&
67624 - (atomic_read(&rdtp->dynticks) & 0x1))
67625 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
67626 return;
67627 rdtp->dynticks_nmi_nesting++;
67628 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
67629 - atomic_inc(&rdtp->dynticks);
67630 + atomic_inc_unchecked(&rdtp->dynticks);
67631 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
67632 smp_mb__after_atomic_inc(); /* See above. */
67633 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
67634 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
67635 }
67636
67637 /**
67638 @@ -571,9 +571,9 @@ void rcu_nmi_exit(void)
67639 return;
67640 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
67641 smp_mb__before_atomic_inc(); /* See above. */
67642 - atomic_inc(&rdtp->dynticks);
67643 + atomic_inc_unchecked(&rdtp->dynticks);
67644 smp_mb__after_atomic_inc(); /* Force delay to next write. */
67645 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
67646 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
67647 }
67648
67649 #ifdef CONFIG_PROVE_RCU
67650 @@ -589,7 +589,7 @@ int rcu_is_cpu_idle(void)
67651 int ret;
67652
67653 preempt_disable();
67654 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
67655 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
67656 preempt_enable();
67657 return ret;
67658 }
67659 @@ -659,7 +659,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
67660 */
67661 static int dyntick_save_progress_counter(struct rcu_data *rdp)
67662 {
67663 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
67664 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
67665 return (rdp->dynticks_snap & 0x1) == 0;
67666 }
67667
67668 @@ -674,7 +674,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
67669 unsigned int curr;
67670 unsigned int snap;
67671
67672 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
67673 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
67674 snap = (unsigned int)rdp->dynticks_snap;
67675
67676 /*
67677 @@ -704,10 +704,10 @@ static int jiffies_till_stall_check(void)
67678 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
67679 */
67680 if (till_stall_check < 3) {
67681 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
67682 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
67683 till_stall_check = 3;
67684 } else if (till_stall_check > 300) {
67685 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
67686 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
67687 till_stall_check = 300;
67688 }
67689 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
67690 @@ -1766,7 +1766,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
67691 /*
67692 * Do RCU core processing for the current CPU.
67693 */
67694 -static void rcu_process_callbacks(struct softirq_action *unused)
67695 +static void rcu_process_callbacks(void)
67696 {
67697 trace_rcu_utilization("Start RCU core");
67698 __rcu_process_callbacks(&rcu_sched_state,
67699 @@ -1949,8 +1949,8 @@ void synchronize_rcu_bh(void)
67700 }
67701 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
67702
67703 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
67704 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
67705 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
67706 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
67707
67708 static int synchronize_sched_expedited_cpu_stop(void *data)
67709 {
67710 @@ -2011,7 +2011,7 @@ void synchronize_sched_expedited(void)
67711 int firstsnap, s, snap, trycount = 0;
67712
67713 /* Note that atomic_inc_return() implies full memory barrier. */
67714 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
67715 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
67716 get_online_cpus();
67717 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
67718
67719 @@ -2033,7 +2033,7 @@ void synchronize_sched_expedited(void)
67720 }
67721
67722 /* Check to see if someone else did our work for us. */
67723 - s = atomic_read(&sync_sched_expedited_done);
67724 + s = atomic_read_unchecked(&sync_sched_expedited_done);
67725 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
67726 smp_mb(); /* ensure test happens before caller kfree */
67727 return;
67728 @@ -2048,7 +2048,7 @@ void synchronize_sched_expedited(void)
67729 * grace period works for us.
67730 */
67731 get_online_cpus();
67732 - snap = atomic_read(&sync_sched_expedited_started);
67733 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
67734 smp_mb(); /* ensure read is before try_stop_cpus(). */
67735 }
67736
67737 @@ -2059,12 +2059,12 @@ void synchronize_sched_expedited(void)
67738 * than we did beat us to the punch.
67739 */
67740 do {
67741 - s = atomic_read(&sync_sched_expedited_done);
67742 + s = atomic_read_unchecked(&sync_sched_expedited_done);
67743 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
67744 smp_mb(); /* ensure test happens before caller kfree */
67745 break;
67746 }
67747 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
67748 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
67749
67750 put_online_cpus();
67751 }
67752 @@ -2262,7 +2262,7 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
67753 rdp->qlen = 0;
67754 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
67755 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
67756 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
67757 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
67758 rdp->cpu = cpu;
67759 rdp->rsp = rsp;
67760 raw_spin_unlock_irqrestore(&rnp->lock, flags);
67761 @@ -2290,8 +2290,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
67762 rdp->n_force_qs_snap = rsp->n_force_qs;
67763 rdp->blimit = blimit;
67764 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
67765 - atomic_set(&rdp->dynticks->dynticks,
67766 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
67767 + atomic_set_unchecked(&rdp->dynticks->dynticks,
67768 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
67769 rcu_prepare_for_idle_init(cpu);
67770 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
67771
67772 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
67773 index cdd1be0..5b2efb4 100644
67774 --- a/kernel/rcutree.h
67775 +++ b/kernel/rcutree.h
67776 @@ -87,7 +87,7 @@ struct rcu_dynticks {
67777 long long dynticks_nesting; /* Track irq/process nesting level. */
67778 /* Process level is worth LLONG_MAX/2. */
67779 int dynticks_nmi_nesting; /* Track NMI nesting level. */
67780 - atomic_t dynticks; /* Even value for idle, else odd. */
67781 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
67782 };
67783
67784 /* RCU's kthread states for tracing. */
67785 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
67786 index c023464..7f57225 100644
67787 --- a/kernel/rcutree_plugin.h
67788 +++ b/kernel/rcutree_plugin.h
67789 @@ -909,7 +909,7 @@ void synchronize_rcu_expedited(void)
67790
67791 /* Clean up and exit. */
67792 smp_mb(); /* ensure expedited GP seen before counter increment. */
67793 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
67794 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
67795 unlock_mb_ret:
67796 mutex_unlock(&sync_rcu_preempt_exp_mutex);
67797 mb_ret:
67798 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
67799 index ed459ed..a03c3fa 100644
67800 --- a/kernel/rcutree_trace.c
67801 +++ b/kernel/rcutree_trace.c
67802 @@ -68,7 +68,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
67803 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
67804 rdp->qs_pending);
67805 seq_printf(m, " dt=%d/%llx/%d df=%lu",
67806 - atomic_read(&rdp->dynticks->dynticks),
67807 + atomic_read_unchecked(&rdp->dynticks->dynticks),
67808 rdp->dynticks->dynticks_nesting,
67809 rdp->dynticks->dynticks_nmi_nesting,
67810 rdp->dynticks_fqs);
67811 @@ -140,7 +140,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
67812 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
67813 rdp->qs_pending);
67814 seq_printf(m, ",%d,%llx,%d,%lu",
67815 - atomic_read(&rdp->dynticks->dynticks),
67816 + atomic_read_unchecked(&rdp->dynticks->dynticks),
67817 rdp->dynticks->dynticks_nesting,
67818 rdp->dynticks->dynticks_nmi_nesting,
67819 rdp->dynticks_fqs);
67820 diff --git a/kernel/resource.c b/kernel/resource.c
67821 index 7e8ea66..1efd11f 100644
67822 --- a/kernel/resource.c
67823 +++ b/kernel/resource.c
67824 @@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
67825
67826 static int __init ioresources_init(void)
67827 {
67828 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67829 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67830 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
67831 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
67832 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67833 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
67834 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
67835 +#endif
67836 +#else
67837 proc_create("ioports", 0, NULL, &proc_ioports_operations);
67838 proc_create("iomem", 0, NULL, &proc_iomem_operations);
67839 +#endif
67840 return 0;
67841 }
67842 __initcall(ioresources_init);
67843 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
67844 index 98ec494..4241d6d 100644
67845 --- a/kernel/rtmutex-tester.c
67846 +++ b/kernel/rtmutex-tester.c
67847 @@ -20,7 +20,7 @@
67848 #define MAX_RT_TEST_MUTEXES 8
67849
67850 static spinlock_t rttest_lock;
67851 -static atomic_t rttest_event;
67852 +static atomic_unchecked_t rttest_event;
67853
67854 struct test_thread_data {
67855 int opcode;
67856 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67857
67858 case RTTEST_LOCKCONT:
67859 td->mutexes[td->opdata] = 1;
67860 - td->event = atomic_add_return(1, &rttest_event);
67861 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67862 return 0;
67863
67864 case RTTEST_RESET:
67865 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67866 return 0;
67867
67868 case RTTEST_RESETEVENT:
67869 - atomic_set(&rttest_event, 0);
67870 + atomic_set_unchecked(&rttest_event, 0);
67871 return 0;
67872
67873 default:
67874 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67875 return ret;
67876
67877 td->mutexes[id] = 1;
67878 - td->event = atomic_add_return(1, &rttest_event);
67879 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67880 rt_mutex_lock(&mutexes[id]);
67881 - td->event = atomic_add_return(1, &rttest_event);
67882 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67883 td->mutexes[id] = 4;
67884 return 0;
67885
67886 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67887 return ret;
67888
67889 td->mutexes[id] = 1;
67890 - td->event = atomic_add_return(1, &rttest_event);
67891 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67892 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
67893 - td->event = atomic_add_return(1, &rttest_event);
67894 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67895 td->mutexes[id] = ret ? 0 : 4;
67896 return ret ? -EINTR : 0;
67897
67898 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
67899 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
67900 return ret;
67901
67902 - td->event = atomic_add_return(1, &rttest_event);
67903 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67904 rt_mutex_unlock(&mutexes[id]);
67905 - td->event = atomic_add_return(1, &rttest_event);
67906 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67907 td->mutexes[id] = 0;
67908 return 0;
67909
67910 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
67911 break;
67912
67913 td->mutexes[dat] = 2;
67914 - td->event = atomic_add_return(1, &rttest_event);
67915 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67916 break;
67917
67918 default:
67919 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
67920 return;
67921
67922 td->mutexes[dat] = 3;
67923 - td->event = atomic_add_return(1, &rttest_event);
67924 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67925 break;
67926
67927 case RTTEST_LOCKNOWAIT:
67928 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
67929 return;
67930
67931 td->mutexes[dat] = 1;
67932 - td->event = atomic_add_return(1, &rttest_event);
67933 + td->event = atomic_add_return_unchecked(1, &rttest_event);
67934 return;
67935
67936 default:
67937 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
67938 index 0984a21..939f183 100644
67939 --- a/kernel/sched/auto_group.c
67940 +++ b/kernel/sched/auto_group.c
67941 @@ -11,7 +11,7 @@
67942
67943 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
67944 static struct autogroup autogroup_default;
67945 -static atomic_t autogroup_seq_nr;
67946 +static atomic_unchecked_t autogroup_seq_nr;
67947
67948 void __init autogroup_init(struct task_struct *init_task)
67949 {
67950 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
67951
67952 kref_init(&ag->kref);
67953 init_rwsem(&ag->lock);
67954 - ag->id = atomic_inc_return(&autogroup_seq_nr);
67955 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
67956 ag->tg = tg;
67957 #ifdef CONFIG_RT_GROUP_SCHED
67958 /*
67959 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
67960 index 2000e06..79cf3d8 100644
67961 --- a/kernel/sched/core.c
67962 +++ b/kernel/sched/core.c
67963 @@ -3907,6 +3907,8 @@ int can_nice(const struct task_struct *p, const int nice)
67964 /* convert nice value [19,-20] to rlimit style value [1,40] */
67965 int nice_rlim = 20 - nice;
67966
67967 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
67968 +
67969 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
67970 capable(CAP_SYS_NICE));
67971 }
67972 @@ -3940,7 +3942,8 @@ SYSCALL_DEFINE1(nice, int, increment)
67973 if (nice > 19)
67974 nice = 19;
67975
67976 - if (increment < 0 && !can_nice(current, nice))
67977 + if (increment < 0 && (!can_nice(current, nice) ||
67978 + gr_handle_chroot_nice()))
67979 return -EPERM;
67980
67981 retval = security_task_setnice(current, nice);
67982 @@ -4097,6 +4100,7 @@ recheck:
67983 unsigned long rlim_rtprio =
67984 task_rlimit(p, RLIMIT_RTPRIO);
67985
67986 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
67987 /* can't set/change the rt policy */
67988 if (policy != p->policy && !rlim_rtprio)
67989 return -EPERM;
67990 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
67991 index e955364..eacd2a4 100644
67992 --- a/kernel/sched/fair.c
67993 +++ b/kernel/sched/fair.c
67994 @@ -5107,7 +5107,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
67995 * run_rebalance_domains is triggered when needed from the scheduler tick.
67996 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
67997 */
67998 -static void run_rebalance_domains(struct softirq_action *h)
67999 +static void run_rebalance_domains(void)
68000 {
68001 int this_cpu = smp_processor_id();
68002 struct rq *this_rq = cpu_rq(this_cpu);
68003 diff --git a/kernel/signal.c b/kernel/signal.c
68004 index 17afcaf..4500b05 100644
68005 --- a/kernel/signal.c
68006 +++ b/kernel/signal.c
68007 @@ -47,12 +47,12 @@ static struct kmem_cache *sigqueue_cachep;
68008
68009 int print_fatal_signals __read_mostly;
68010
68011 -static void __user *sig_handler(struct task_struct *t, int sig)
68012 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
68013 {
68014 return t->sighand->action[sig - 1].sa.sa_handler;
68015 }
68016
68017 -static int sig_handler_ignored(void __user *handler, int sig)
68018 +static int sig_handler_ignored(__sighandler_t handler, int sig)
68019 {
68020 /* Is it explicitly or implicitly ignored? */
68021 return handler == SIG_IGN ||
68022 @@ -61,7 +61,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
68023
68024 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
68025 {
68026 - void __user *handler;
68027 + __sighandler_t handler;
68028
68029 handler = sig_handler(t, sig);
68030
68031 @@ -365,6 +365,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
68032 atomic_inc(&user->sigpending);
68033 rcu_read_unlock();
68034
68035 + if (!override_rlimit)
68036 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
68037 +
68038 if (override_rlimit ||
68039 atomic_read(&user->sigpending) <=
68040 task_rlimit(t, RLIMIT_SIGPENDING)) {
68041 @@ -489,7 +492,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
68042
68043 int unhandled_signal(struct task_struct *tsk, int sig)
68044 {
68045 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
68046 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
68047 if (is_global_init(tsk))
68048 return 1;
68049 if (handler != SIG_IGN && handler != SIG_DFL)
68050 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
68051 }
68052 }
68053
68054 + /* allow glibc communication via tgkill to other threads in our
68055 + thread group */
68056 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
68057 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
68058 + && gr_handle_signal(t, sig))
68059 + return -EPERM;
68060 +
68061 return security_task_kill(t, info, sig, 0);
68062 }
68063
68064 @@ -1204,7 +1214,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
68065 return send_signal(sig, info, p, 1);
68066 }
68067
68068 -static int
68069 +int
68070 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68071 {
68072 return send_signal(sig, info, t, 0);
68073 @@ -1241,6 +1251,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68074 unsigned long int flags;
68075 int ret, blocked, ignored;
68076 struct k_sigaction *action;
68077 + int is_unhandled = 0;
68078
68079 spin_lock_irqsave(&t->sighand->siglock, flags);
68080 action = &t->sighand->action[sig-1];
68081 @@ -1255,9 +1266,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68082 }
68083 if (action->sa.sa_handler == SIG_DFL)
68084 t->signal->flags &= ~SIGNAL_UNKILLABLE;
68085 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
68086 + is_unhandled = 1;
68087 ret = specific_send_sig_info(sig, info, t);
68088 spin_unlock_irqrestore(&t->sighand->siglock, flags);
68089
68090 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
68091 + normal operation */
68092 + if (is_unhandled) {
68093 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
68094 + gr_handle_crash(t, sig);
68095 + }
68096 +
68097 return ret;
68098 }
68099
68100 @@ -1324,8 +1344,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
68101 ret = check_kill_permission(sig, info, p);
68102 rcu_read_unlock();
68103
68104 - if (!ret && sig)
68105 + if (!ret && sig) {
68106 ret = do_send_sig_info(sig, info, p, true);
68107 + if (!ret)
68108 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
68109 + }
68110
68111 return ret;
68112 }
68113 @@ -2840,7 +2863,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
68114 int error = -ESRCH;
68115
68116 rcu_read_lock();
68117 - p = find_task_by_vpid(pid);
68118 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68119 + /* allow glibc communication via tgkill to other threads in our
68120 + thread group */
68121 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
68122 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
68123 + p = find_task_by_vpid_unrestricted(pid);
68124 + else
68125 +#endif
68126 + p = find_task_by_vpid(pid);
68127 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
68128 error = check_kill_permission(sig, info, p);
68129 /*
68130 diff --git a/kernel/smp.c b/kernel/smp.c
68131 index 2f8b10e..a41bc14 100644
68132 --- a/kernel/smp.c
68133 +++ b/kernel/smp.c
68134 @@ -580,22 +580,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
68135 }
68136 EXPORT_SYMBOL(smp_call_function);
68137
68138 -void ipi_call_lock(void)
68139 +void ipi_call_lock(void) __acquires(call_function.lock)
68140 {
68141 raw_spin_lock(&call_function.lock);
68142 }
68143
68144 -void ipi_call_unlock(void)
68145 +void ipi_call_unlock(void) __releases(call_function.lock)
68146 {
68147 raw_spin_unlock(&call_function.lock);
68148 }
68149
68150 -void ipi_call_lock_irq(void)
68151 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
68152 {
68153 raw_spin_lock_irq(&call_function.lock);
68154 }
68155
68156 -void ipi_call_unlock_irq(void)
68157 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
68158 {
68159 raw_spin_unlock_irq(&call_function.lock);
68160 }
68161 diff --git a/kernel/softirq.c b/kernel/softirq.c
68162 index 671f959..91c51cb 100644
68163 --- a/kernel/softirq.c
68164 +++ b/kernel/softirq.c
68165 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
68166
68167 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
68168
68169 -char *softirq_to_name[NR_SOFTIRQS] = {
68170 +const char * const softirq_to_name[NR_SOFTIRQS] = {
68171 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
68172 "TASKLET", "SCHED", "HRTIMER", "RCU"
68173 };
68174 @@ -235,7 +235,7 @@ restart:
68175 kstat_incr_softirqs_this_cpu(vec_nr);
68176
68177 trace_softirq_entry(vec_nr);
68178 - h->action(h);
68179 + h->action();
68180 trace_softirq_exit(vec_nr);
68181 if (unlikely(prev_count != preempt_count())) {
68182 printk(KERN_ERR "huh, entered softirq %u %s %p"
68183 @@ -381,9 +381,11 @@ void __raise_softirq_irqoff(unsigned int nr)
68184 or_softirq_pending(1UL << nr);
68185 }
68186
68187 -void open_softirq(int nr, void (*action)(struct softirq_action *))
68188 +void open_softirq(int nr, void (*action)(void))
68189 {
68190 - softirq_vec[nr].action = action;
68191 + pax_open_kernel();
68192 + *(void **)&softirq_vec[nr].action = action;
68193 + pax_close_kernel();
68194 }
68195
68196 /*
68197 @@ -437,7 +439,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
68198
68199 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
68200
68201 -static void tasklet_action(struct softirq_action *a)
68202 +static void tasklet_action(void)
68203 {
68204 struct tasklet_struct *list;
68205
68206 @@ -472,7 +474,7 @@ static void tasklet_action(struct softirq_action *a)
68207 }
68208 }
68209
68210 -static void tasklet_hi_action(struct softirq_action *a)
68211 +static void tasklet_hi_action(void)
68212 {
68213 struct tasklet_struct *list;
68214
68215 diff --git a/kernel/sys.c b/kernel/sys.c
68216 index e7006eb..8fb7c51 100644
68217 --- a/kernel/sys.c
68218 +++ b/kernel/sys.c
68219 @@ -158,6 +158,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
68220 error = -EACCES;
68221 goto out;
68222 }
68223 +
68224 + if (gr_handle_chroot_setpriority(p, niceval)) {
68225 + error = -EACCES;
68226 + goto out;
68227 + }
68228 +
68229 no_nice = security_task_setnice(p, niceval);
68230 if (no_nice) {
68231 error = no_nice;
68232 @@ -581,6 +587,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
68233 goto error;
68234 }
68235
68236 + if (gr_check_group_change(new->gid, new->egid, -1))
68237 + goto error;
68238 +
68239 if (rgid != (gid_t) -1 ||
68240 (egid != (gid_t) -1 && egid != old->gid))
68241 new->sgid = new->egid;
68242 @@ -610,6 +619,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
68243 old = current_cred();
68244
68245 retval = -EPERM;
68246 +
68247 + if (gr_check_group_change(gid, gid, gid))
68248 + goto error;
68249 +
68250 if (nsown_capable(CAP_SETGID))
68251 new->gid = new->egid = new->sgid = new->fsgid = gid;
68252 else if (gid == old->gid || gid == old->sgid)
68253 @@ -627,7 +640,7 @@ error:
68254 /*
68255 * change the user struct in a credentials set to match the new UID
68256 */
68257 -static int set_user(struct cred *new)
68258 +int set_user(struct cred *new)
68259 {
68260 struct user_struct *new_user;
68261
68262 @@ -697,6 +710,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
68263 goto error;
68264 }
68265
68266 + if (gr_check_user_change(new->uid, new->euid, -1))
68267 + goto error;
68268 +
68269 if (new->uid != old->uid) {
68270 retval = set_user(new);
68271 if (retval < 0)
68272 @@ -741,6 +757,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
68273 old = current_cred();
68274
68275 retval = -EPERM;
68276 +
68277 + if (gr_check_crash_uid(uid))
68278 + goto error;
68279 + if (gr_check_user_change(uid, uid, uid))
68280 + goto error;
68281 +
68282 if (nsown_capable(CAP_SETUID)) {
68283 new->suid = new->uid = uid;
68284 if (uid != old->uid) {
68285 @@ -795,6 +817,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
68286 goto error;
68287 }
68288
68289 + if (gr_check_user_change(ruid, euid, -1))
68290 + goto error;
68291 +
68292 if (ruid != (uid_t) -1) {
68293 new->uid = ruid;
68294 if (ruid != old->uid) {
68295 @@ -859,6 +884,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
68296 goto error;
68297 }
68298
68299 + if (gr_check_group_change(rgid, egid, -1))
68300 + goto error;
68301 +
68302 if (rgid != (gid_t) -1)
68303 new->gid = rgid;
68304 if (egid != (gid_t) -1)
68305 @@ -905,6 +933,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
68306 old = current_cred();
68307 old_fsuid = old->fsuid;
68308
68309 + if (gr_check_user_change(-1, -1, uid))
68310 + goto error;
68311 +
68312 if (uid == old->uid || uid == old->euid ||
68313 uid == old->suid || uid == old->fsuid ||
68314 nsown_capable(CAP_SETUID)) {
68315 @@ -915,6 +946,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
68316 }
68317 }
68318
68319 +error:
68320 abort_creds(new);
68321 return old_fsuid;
68322
68323 @@ -941,12 +973,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
68324 if (gid == old->gid || gid == old->egid ||
68325 gid == old->sgid || gid == old->fsgid ||
68326 nsown_capable(CAP_SETGID)) {
68327 + if (gr_check_group_change(-1, -1, gid))
68328 + goto error;
68329 +
68330 if (gid != old_fsgid) {
68331 new->fsgid = gid;
68332 goto change_okay;
68333 }
68334 }
68335
68336 +error:
68337 abort_creds(new);
68338 return old_fsgid;
68339
68340 @@ -1198,7 +1234,10 @@ static int override_release(char __user *release, int len)
68341 }
68342 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
68343 snprintf(buf, len, "2.6.%u%s", v, rest);
68344 - ret = copy_to_user(release, buf, len);
68345 + if (len > sizeof(buf))
68346 + ret = -EFAULT;
68347 + else
68348 + ret = copy_to_user(release, buf, len);
68349 }
68350 return ret;
68351 }
68352 @@ -1252,19 +1291,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
68353 return -EFAULT;
68354
68355 down_read(&uts_sem);
68356 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
68357 + error = __copy_to_user(name->sysname, &utsname()->sysname,
68358 __OLD_UTS_LEN);
68359 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
68360 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
68361 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
68362 __OLD_UTS_LEN);
68363 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
68364 - error |= __copy_to_user(&name->release, &utsname()->release,
68365 + error |= __copy_to_user(name->release, &utsname()->release,
68366 __OLD_UTS_LEN);
68367 error |= __put_user(0, name->release + __OLD_UTS_LEN);
68368 - error |= __copy_to_user(&name->version, &utsname()->version,
68369 + error |= __copy_to_user(name->version, &utsname()->version,
68370 __OLD_UTS_LEN);
68371 error |= __put_user(0, name->version + __OLD_UTS_LEN);
68372 - error |= __copy_to_user(&name->machine, &utsname()->machine,
68373 + error |= __copy_to_user(name->machine, &utsname()->machine,
68374 __OLD_UTS_LEN);
68375 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
68376 up_read(&uts_sem);
68377 @@ -1847,7 +1886,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
68378 error = get_dumpable(me->mm);
68379 break;
68380 case PR_SET_DUMPABLE:
68381 - if (arg2 < 0 || arg2 > 1) {
68382 + if (arg2 > 1) {
68383 error = -EINVAL;
68384 break;
68385 }
68386 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
68387 index 4ab1187..0b75ced 100644
68388 --- a/kernel/sysctl.c
68389 +++ b/kernel/sysctl.c
68390 @@ -91,7 +91,6 @@
68391
68392
68393 #if defined(CONFIG_SYSCTL)
68394 -
68395 /* External variables not in a header file. */
68396 extern int sysctl_overcommit_memory;
68397 extern int sysctl_overcommit_ratio;
68398 @@ -169,10 +168,8 @@ static int proc_taint(struct ctl_table *table, int write,
68399 void __user *buffer, size_t *lenp, loff_t *ppos);
68400 #endif
68401
68402 -#ifdef CONFIG_PRINTK
68403 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
68404 void __user *buffer, size_t *lenp, loff_t *ppos);
68405 -#endif
68406
68407 #ifdef CONFIG_MAGIC_SYSRQ
68408 /* Note: sysrq code uses it's own private copy */
68409 @@ -196,6 +193,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
68410
68411 #endif
68412
68413 +extern struct ctl_table grsecurity_table[];
68414 +
68415 static struct ctl_table kern_table[];
68416 static struct ctl_table vm_table[];
68417 static struct ctl_table fs_table[];
68418 @@ -210,6 +209,20 @@ extern struct ctl_table epoll_table[];
68419 int sysctl_legacy_va_layout;
68420 #endif
68421
68422 +#ifdef CONFIG_PAX_SOFTMODE
68423 +static ctl_table pax_table[] = {
68424 + {
68425 + .procname = "softmode",
68426 + .data = &pax_softmode,
68427 + .maxlen = sizeof(unsigned int),
68428 + .mode = 0600,
68429 + .proc_handler = &proc_dointvec,
68430 + },
68431 +
68432 + { }
68433 +};
68434 +#endif
68435 +
68436 /* The default sysctl tables: */
68437
68438 static struct ctl_table sysctl_base_table[] = {
68439 @@ -256,6 +269,22 @@ static int max_extfrag_threshold = 1000;
68440 #endif
68441
68442 static struct ctl_table kern_table[] = {
68443 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
68444 + {
68445 + .procname = "grsecurity",
68446 + .mode = 0500,
68447 + .child = grsecurity_table,
68448 + },
68449 +#endif
68450 +
68451 +#ifdef CONFIG_PAX_SOFTMODE
68452 + {
68453 + .procname = "pax",
68454 + .mode = 0500,
68455 + .child = pax_table,
68456 + },
68457 +#endif
68458 +
68459 {
68460 .procname = "sched_child_runs_first",
68461 .data = &sysctl_sched_child_runs_first,
68462 @@ -540,7 +569,7 @@ static struct ctl_table kern_table[] = {
68463 .data = &modprobe_path,
68464 .maxlen = KMOD_PATH_LEN,
68465 .mode = 0644,
68466 - .proc_handler = proc_dostring,
68467 + .proc_handler = proc_dostring_modpriv,
68468 },
68469 {
68470 .procname = "modules_disabled",
68471 @@ -707,16 +736,20 @@ static struct ctl_table kern_table[] = {
68472 .extra1 = &zero,
68473 .extra2 = &one,
68474 },
68475 +#endif
68476 {
68477 .procname = "kptr_restrict",
68478 .data = &kptr_restrict,
68479 .maxlen = sizeof(int),
68480 .mode = 0644,
68481 .proc_handler = proc_dointvec_minmax_sysadmin,
68482 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68483 + .extra1 = &two,
68484 +#else
68485 .extra1 = &zero,
68486 +#endif
68487 .extra2 = &two,
68488 },
68489 -#endif
68490 {
68491 .procname = "ngroups_max",
68492 .data = &ngroups_max,
68493 @@ -1215,6 +1248,13 @@ static struct ctl_table vm_table[] = {
68494 .proc_handler = proc_dointvec_minmax,
68495 .extra1 = &zero,
68496 },
68497 + {
68498 + .procname = "heap_stack_gap",
68499 + .data = &sysctl_heap_stack_gap,
68500 + .maxlen = sizeof(sysctl_heap_stack_gap),
68501 + .mode = 0644,
68502 + .proc_handler = proc_doulongvec_minmax,
68503 + },
68504 #else
68505 {
68506 .procname = "nr_trim_pages",
68507 @@ -1645,6 +1685,16 @@ int proc_dostring(struct ctl_table *table, int write,
68508 buffer, lenp, ppos);
68509 }
68510
68511 +int proc_dostring_modpriv(struct ctl_table *table, int write,
68512 + void __user *buffer, size_t *lenp, loff_t *ppos)
68513 +{
68514 + if (write && !capable(CAP_SYS_MODULE))
68515 + return -EPERM;
68516 +
68517 + return _proc_do_string(table->data, table->maxlen, write,
68518 + buffer, lenp, ppos);
68519 +}
68520 +
68521 static size_t proc_skip_spaces(char **buf)
68522 {
68523 size_t ret;
68524 @@ -1750,6 +1800,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
68525 len = strlen(tmp);
68526 if (len > *size)
68527 len = *size;
68528 + if (len > sizeof(tmp))
68529 + len = sizeof(tmp);
68530 if (copy_to_user(*buf, tmp, len))
68531 return -EFAULT;
68532 *size -= len;
68533 @@ -1942,7 +1994,6 @@ static int proc_taint(struct ctl_table *table, int write,
68534 return err;
68535 }
68536
68537 -#ifdef CONFIG_PRINTK
68538 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
68539 void __user *buffer, size_t *lenp, loff_t *ppos)
68540 {
68541 @@ -1951,7 +2002,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
68542
68543 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
68544 }
68545 -#endif
68546
68547 struct do_proc_dointvec_minmax_conv_param {
68548 int *min;
68549 @@ -2066,8 +2116,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
68550 *i = val;
68551 } else {
68552 val = convdiv * (*i) / convmul;
68553 - if (!first)
68554 + if (!first) {
68555 err = proc_put_char(&buffer, &left, '\t');
68556 + if (err)
68557 + break;
68558 + }
68559 err = proc_put_long(&buffer, &left, val, false);
68560 if (err)
68561 break;
68562 @@ -2459,6 +2512,12 @@ int proc_dostring(struct ctl_table *table, int write,
68563 return -ENOSYS;
68564 }
68565
68566 +int proc_dostring_modpriv(struct ctl_table *table, int write,
68567 + void __user *buffer, size_t *lenp, loff_t *ppos)
68568 +{
68569 + return -ENOSYS;
68570 +}
68571 +
68572 int proc_dointvec(struct ctl_table *table, int write,
68573 void __user *buffer, size_t *lenp, loff_t *ppos)
68574 {
68575 @@ -2515,5 +2574,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
68576 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
68577 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
68578 EXPORT_SYMBOL(proc_dostring);
68579 +EXPORT_SYMBOL(proc_dostring_modpriv);
68580 EXPORT_SYMBOL(proc_doulongvec_minmax);
68581 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
68582 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
68583 index a650694..aaeeb20 100644
68584 --- a/kernel/sysctl_binary.c
68585 +++ b/kernel/sysctl_binary.c
68586 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
68587 int i;
68588
68589 set_fs(KERNEL_DS);
68590 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
68591 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
68592 set_fs(old_fs);
68593 if (result < 0)
68594 goto out_kfree;
68595 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
68596 }
68597
68598 set_fs(KERNEL_DS);
68599 - result = vfs_write(file, buffer, str - buffer, &pos);
68600 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
68601 set_fs(old_fs);
68602 if (result < 0)
68603 goto out_kfree;
68604 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
68605 int i;
68606
68607 set_fs(KERNEL_DS);
68608 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
68609 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
68610 set_fs(old_fs);
68611 if (result < 0)
68612 goto out_kfree;
68613 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
68614 }
68615
68616 set_fs(KERNEL_DS);
68617 - result = vfs_write(file, buffer, str - buffer, &pos);
68618 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
68619 set_fs(old_fs);
68620 if (result < 0)
68621 goto out_kfree;
68622 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
68623 int i;
68624
68625 set_fs(KERNEL_DS);
68626 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
68627 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
68628 set_fs(old_fs);
68629 if (result < 0)
68630 goto out;
68631 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
68632 __le16 dnaddr;
68633
68634 set_fs(KERNEL_DS);
68635 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
68636 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
68637 set_fs(old_fs);
68638 if (result < 0)
68639 goto out;
68640 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
68641 le16_to_cpu(dnaddr) & 0x3ff);
68642
68643 set_fs(KERNEL_DS);
68644 - result = vfs_write(file, buf, len, &pos);
68645 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
68646 set_fs(old_fs);
68647 if (result < 0)
68648 goto out;
68649 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
68650 index e660464..c8b9e67 100644
68651 --- a/kernel/taskstats.c
68652 +++ b/kernel/taskstats.c
68653 @@ -27,9 +27,12 @@
68654 #include <linux/cgroup.h>
68655 #include <linux/fs.h>
68656 #include <linux/file.h>
68657 +#include <linux/grsecurity.h>
68658 #include <net/genetlink.h>
68659 #include <linux/atomic.h>
68660
68661 +extern int gr_is_taskstats_denied(int pid);
68662 +
68663 /*
68664 * Maximum length of a cpumask that can be specified in
68665 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
68666 @@ -556,6 +559,9 @@ err:
68667
68668 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
68669 {
68670 + if (gr_is_taskstats_denied(current->pid))
68671 + return -EACCES;
68672 +
68673 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
68674 return cmd_attr_register_cpumask(info);
68675 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
68676 diff --git a/kernel/time.c b/kernel/time.c
68677 index ba744cf..267b7c5 100644
68678 --- a/kernel/time.c
68679 +++ b/kernel/time.c
68680 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
68681 return error;
68682
68683 if (tz) {
68684 + /* we log in do_settimeofday called below, so don't log twice
68685 + */
68686 + if (!tv)
68687 + gr_log_timechange();
68688 +
68689 sys_tz = *tz;
68690 update_vsyscall_tz();
68691 if (firsttime) {
68692 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
68693 index 8a538c5..def79d4 100644
68694 --- a/kernel/time/alarmtimer.c
68695 +++ b/kernel/time/alarmtimer.c
68696 @@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
68697 struct platform_device *pdev;
68698 int error = 0;
68699 int i;
68700 - struct k_clock alarm_clock = {
68701 + static struct k_clock alarm_clock = {
68702 .clock_getres = alarm_clock_getres,
68703 .clock_get = alarm_clock_get,
68704 .timer_create = alarm_timer_create,
68705 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
68706 index f113755..ec24223 100644
68707 --- a/kernel/time/tick-broadcast.c
68708 +++ b/kernel/time/tick-broadcast.c
68709 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
68710 * then clear the broadcast bit.
68711 */
68712 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
68713 - int cpu = smp_processor_id();
68714 + cpu = smp_processor_id();
68715
68716 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
68717 tick_broadcast_clear_oneshot(cpu);
68718 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
68719 index d42574df..247414c 100644
68720 --- a/kernel/time/timekeeping.c
68721 +++ b/kernel/time/timekeeping.c
68722 @@ -14,6 +14,7 @@
68723 #include <linux/init.h>
68724 #include <linux/mm.h>
68725 #include <linux/sched.h>
68726 +#include <linux/grsecurity.h>
68727 #include <linux/syscore_ops.h>
68728 #include <linux/clocksource.h>
68729 #include <linux/jiffies.h>
68730 @@ -373,6 +374,8 @@ int do_settimeofday(const struct timespec *tv)
68731 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
68732 return -EINVAL;
68733
68734 + gr_log_timechange();
68735 +
68736 write_seqlock_irqsave(&timekeeper.lock, flags);
68737
68738 timekeeping_forward_now();
68739 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
68740 index 3258455..f35227d 100644
68741 --- a/kernel/time/timer_list.c
68742 +++ b/kernel/time/timer_list.c
68743 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
68744
68745 static void print_name_offset(struct seq_file *m, void *sym)
68746 {
68747 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68748 + SEQ_printf(m, "<%p>", NULL);
68749 +#else
68750 char symname[KSYM_NAME_LEN];
68751
68752 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
68753 SEQ_printf(m, "<%pK>", sym);
68754 else
68755 SEQ_printf(m, "%s", symname);
68756 +#endif
68757 }
68758
68759 static void
68760 @@ -112,7 +116,11 @@ next_one:
68761 static void
68762 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
68763 {
68764 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68765 + SEQ_printf(m, " .base: %p\n", NULL);
68766 +#else
68767 SEQ_printf(m, " .base: %pK\n", base);
68768 +#endif
68769 SEQ_printf(m, " .index: %d\n",
68770 base->index);
68771 SEQ_printf(m, " .resolution: %Lu nsecs\n",
68772 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
68773 {
68774 struct proc_dir_entry *pe;
68775
68776 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
68777 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
68778 +#else
68779 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
68780 +#endif
68781 if (!pe)
68782 return -ENOMEM;
68783 return 0;
68784 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
68785 index 0b537f2..9e71eca 100644
68786 --- a/kernel/time/timer_stats.c
68787 +++ b/kernel/time/timer_stats.c
68788 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
68789 static unsigned long nr_entries;
68790 static struct entry entries[MAX_ENTRIES];
68791
68792 -static atomic_t overflow_count;
68793 +static atomic_unchecked_t overflow_count;
68794
68795 /*
68796 * The entries are in a hash-table, for fast lookup:
68797 @@ -140,7 +140,7 @@ static void reset_entries(void)
68798 nr_entries = 0;
68799 memset(entries, 0, sizeof(entries));
68800 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
68801 - atomic_set(&overflow_count, 0);
68802 + atomic_set_unchecked(&overflow_count, 0);
68803 }
68804
68805 static struct entry *alloc_entry(void)
68806 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
68807 if (likely(entry))
68808 entry->count++;
68809 else
68810 - atomic_inc(&overflow_count);
68811 + atomic_inc_unchecked(&overflow_count);
68812
68813 out_unlock:
68814 raw_spin_unlock_irqrestore(lock, flags);
68815 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
68816
68817 static void print_name_offset(struct seq_file *m, unsigned long addr)
68818 {
68819 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68820 + seq_printf(m, "<%p>", NULL);
68821 +#else
68822 char symname[KSYM_NAME_LEN];
68823
68824 if (lookup_symbol_name(addr, symname) < 0)
68825 seq_printf(m, "<%p>", (void *)addr);
68826 else
68827 seq_printf(m, "%s", symname);
68828 +#endif
68829 }
68830
68831 static int tstats_show(struct seq_file *m, void *v)
68832 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
68833
68834 seq_puts(m, "Timer Stats Version: v0.2\n");
68835 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
68836 - if (atomic_read(&overflow_count))
68837 + if (atomic_read_unchecked(&overflow_count))
68838 seq_printf(m, "Overflow: %d entries\n",
68839 - atomic_read(&overflow_count));
68840 + atomic_read_unchecked(&overflow_count));
68841
68842 for (i = 0; i < nr_entries; i++) {
68843 entry = entries + i;
68844 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
68845 {
68846 struct proc_dir_entry *pe;
68847
68848 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
68849 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
68850 +#else
68851 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
68852 +#endif
68853 if (!pe)
68854 return -ENOMEM;
68855 return 0;
68856 diff --git a/kernel/timer.c b/kernel/timer.c
68857 index a297ffc..5e16b0b 100644
68858 --- a/kernel/timer.c
68859 +++ b/kernel/timer.c
68860 @@ -1354,7 +1354,7 @@ void update_process_times(int user_tick)
68861 /*
68862 * This function runs timers and the timer-tq in bottom half context.
68863 */
68864 -static void run_timer_softirq(struct softirq_action *h)
68865 +static void run_timer_softirq(void)
68866 {
68867 struct tvec_base *base = __this_cpu_read(tvec_bases);
68868
68869 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
68870 index c0bd030..62a1927 100644
68871 --- a/kernel/trace/blktrace.c
68872 +++ b/kernel/trace/blktrace.c
68873 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
68874 struct blk_trace *bt = filp->private_data;
68875 char buf[16];
68876
68877 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
68878 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
68879
68880 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
68881 }
68882 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
68883 return 1;
68884
68885 bt = buf->chan->private_data;
68886 - atomic_inc(&bt->dropped);
68887 + atomic_inc_unchecked(&bt->dropped);
68888 return 0;
68889 }
68890
68891 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
68892
68893 bt->dir = dir;
68894 bt->dev = dev;
68895 - atomic_set(&bt->dropped, 0);
68896 + atomic_set_unchecked(&bt->dropped, 0);
68897
68898 ret = -EIO;
68899 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
68900 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
68901 index 0fa92f6..89950b2 100644
68902 --- a/kernel/trace/ftrace.c
68903 +++ b/kernel/trace/ftrace.c
68904 @@ -1800,12 +1800,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
68905 if (unlikely(ftrace_disabled))
68906 return 0;
68907
68908 + ret = ftrace_arch_code_modify_prepare();
68909 + FTRACE_WARN_ON(ret);
68910 + if (ret)
68911 + return 0;
68912 +
68913 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
68914 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
68915 if (ret) {
68916 ftrace_bug(ret, ip);
68917 - return 0;
68918 }
68919 - return 1;
68920 + return ret ? 0 : 1;
68921 }
68922
68923 /*
68924 @@ -2917,7 +2922,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
68925
68926 int
68927 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
68928 - void *data)
68929 + void *data)
68930 {
68931 struct ftrace_func_probe *entry;
68932 struct ftrace_page *pg;
68933 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
68934 index 464a96f..bc0bd88 100644
68935 --- a/kernel/trace/trace.c
68936 +++ b/kernel/trace/trace.c
68937 @@ -4312,10 +4312,9 @@ static const struct file_operations tracing_dyn_info_fops = {
68938 };
68939 #endif
68940
68941 -static struct dentry *d_tracer;
68942 -
68943 struct dentry *tracing_init_dentry(void)
68944 {
68945 + static struct dentry *d_tracer;
68946 static int once;
68947
68948 if (d_tracer)
68949 @@ -4335,10 +4334,9 @@ struct dentry *tracing_init_dentry(void)
68950 return d_tracer;
68951 }
68952
68953 -static struct dentry *d_percpu;
68954 -
68955 struct dentry *tracing_dentry_percpu(void)
68956 {
68957 + static struct dentry *d_percpu;
68958 static int once;
68959 struct dentry *d_tracer;
68960
68961 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
68962 index 29111da..d190fe2 100644
68963 --- a/kernel/trace/trace_events.c
68964 +++ b/kernel/trace/trace_events.c
68965 @@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
68966 struct ftrace_module_file_ops {
68967 struct list_head list;
68968 struct module *mod;
68969 - struct file_operations id;
68970 - struct file_operations enable;
68971 - struct file_operations format;
68972 - struct file_operations filter;
68973 };
68974
68975 static struct ftrace_module_file_ops *
68976 @@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
68977
68978 file_ops->mod = mod;
68979
68980 - file_ops->id = ftrace_event_id_fops;
68981 - file_ops->id.owner = mod;
68982 -
68983 - file_ops->enable = ftrace_enable_fops;
68984 - file_ops->enable.owner = mod;
68985 -
68986 - file_ops->filter = ftrace_event_filter_fops;
68987 - file_ops->filter.owner = mod;
68988 -
68989 - file_ops->format = ftrace_event_format_fops;
68990 - file_ops->format.owner = mod;
68991 + pax_open_kernel();
68992 + *(void **)&mod->trace_id.owner = mod;
68993 + *(void **)&mod->trace_enable.owner = mod;
68994 + *(void **)&mod->trace_filter.owner = mod;
68995 + *(void **)&mod->trace_format.owner = mod;
68996 + pax_close_kernel();
68997
68998 list_add(&file_ops->list, &ftrace_module_file_list);
68999
69000 @@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
69001
69002 for_each_event(call, start, end) {
69003 __trace_add_event_call(*call, mod,
69004 - &file_ops->id, &file_ops->enable,
69005 - &file_ops->filter, &file_ops->format);
69006 + &mod->trace_id, &mod->trace_enable,
69007 + &mod->trace_filter, &mod->trace_format);
69008 }
69009 }
69010
69011 diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
69012 index 580a05e..9b31acb 100644
69013 --- a/kernel/trace/trace_kprobe.c
69014 +++ b/kernel/trace/trace_kprobe.c
69015 @@ -217,7 +217,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69016 long ret;
69017 int maxlen = get_rloc_len(*(u32 *)dest);
69018 u8 *dst = get_rloc_data(dest);
69019 - u8 *src = addr;
69020 + const u8 __user *src = (const u8 __force_user *)addr;
69021 mm_segment_t old_fs = get_fs();
69022 if (!maxlen)
69023 return;
69024 @@ -229,7 +229,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69025 pagefault_disable();
69026 do
69027 ret = __copy_from_user_inatomic(dst++, src++, 1);
69028 - while (dst[-1] && ret == 0 && src - (u8 *)addr < maxlen);
69029 + while (dst[-1] && ret == 0 && src - (const u8 __force_user *)addr < maxlen);
69030 dst[-1] = '\0';
69031 pagefault_enable();
69032 set_fs(old_fs);
69033 @@ -238,7 +238,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69034 ((u8 *)get_rloc_data(dest))[0] = '\0';
69035 *(u32 *)dest = make_data_rloc(0, get_rloc_offs(*(u32 *)dest));
69036 } else
69037 - *(u32 *)dest = make_data_rloc(src - (u8 *)addr,
69038 + *(u32 *)dest = make_data_rloc(src - (const u8 __force_user *)addr,
69039 get_rloc_offs(*(u32 *)dest));
69040 }
69041 /* Return the length of string -- including null terminal byte */
69042 @@ -252,7 +252,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string_size)(struct pt_regs *regs,
69043 set_fs(KERNEL_DS);
69044 pagefault_disable();
69045 do {
69046 - ret = __copy_from_user_inatomic(&c, (u8 *)addr + len, 1);
69047 + ret = __copy_from_user_inatomic(&c, (const u8 __force_user *)addr + len, 1);
69048 len++;
69049 } while (c && ret == 0 && len < MAX_STRING_SIZE);
69050 pagefault_enable();
69051 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
69052 index fd3c8aa..5f324a6 100644
69053 --- a/kernel/trace/trace_mmiotrace.c
69054 +++ b/kernel/trace/trace_mmiotrace.c
69055 @@ -24,7 +24,7 @@ struct header_iter {
69056 static struct trace_array *mmio_trace_array;
69057 static bool overrun_detected;
69058 static unsigned long prev_overruns;
69059 -static atomic_t dropped_count;
69060 +static atomic_unchecked_t dropped_count;
69061
69062 static void mmio_reset_data(struct trace_array *tr)
69063 {
69064 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
69065
69066 static unsigned long count_overruns(struct trace_iterator *iter)
69067 {
69068 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
69069 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
69070 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
69071
69072 if (over > prev_overruns)
69073 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
69074 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
69075 sizeof(*entry), 0, pc);
69076 if (!event) {
69077 - atomic_inc(&dropped_count);
69078 + atomic_inc_unchecked(&dropped_count);
69079 return;
69080 }
69081 entry = ring_buffer_event_data(event);
69082 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
69083 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
69084 sizeof(*entry), 0, pc);
69085 if (!event) {
69086 - atomic_inc(&dropped_count);
69087 + atomic_inc_unchecked(&dropped_count);
69088 return;
69089 }
69090 entry = ring_buffer_event_data(event);
69091 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
69092 index df611a0..10d8b32 100644
69093 --- a/kernel/trace/trace_output.c
69094 +++ b/kernel/trace/trace_output.c
69095 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
69096
69097 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
69098 if (!IS_ERR(p)) {
69099 - p = mangle_path(s->buffer + s->len, p, "\n");
69100 + p = mangle_path(s->buffer + s->len, p, "\n\\");
69101 if (p) {
69102 s->len = p - s->buffer;
69103 return 1;
69104 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
69105 index d4545f4..a9010a1 100644
69106 --- a/kernel/trace/trace_stack.c
69107 +++ b/kernel/trace/trace_stack.c
69108 @@ -53,7 +53,7 @@ static inline void check_stack(void)
69109 return;
69110
69111 /* we do not handle interrupt stacks yet */
69112 - if (!object_is_on_stack(&this_size))
69113 + if (!object_starts_on_stack(&this_size))
69114 return;
69115
69116 local_irq_save(flags);
69117 diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c
69118 index 209b379..7f76423 100644
69119 --- a/kernel/trace/trace_workqueue.c
69120 +++ b/kernel/trace/trace_workqueue.c
69121 @@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
69122 int cpu;
69123 pid_t pid;
69124 /* Can be inserted from interrupt or user context, need to be atomic */
69125 - atomic_t inserted;
69126 + atomic_unchecked_t inserted;
69127 /*
69128 * Don't need to be atomic, works are serialized in a single workqueue thread
69129 * on a single CPU.
69130 @@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
69131 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
69132 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
69133 if (node->pid == wq_thread->pid) {
69134 - atomic_inc(&node->inserted);
69135 + atomic_inc_unchecked(&node->inserted);
69136 goto found;
69137 }
69138 }
69139 @@ -210,7 +210,7 @@ static int workqueue_stat_show(struct seq_file *s, void *p)
69140 tsk = get_pid_task(pid, PIDTYPE_PID);
69141 if (tsk) {
69142 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
69143 - atomic_read(&cws->inserted), cws->executed,
69144 + atomic_read_unchecked(&cws->inserted), cws->executed,
69145 tsk->comm);
69146 put_task_struct(tsk);
69147 }
69148 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
69149 index 6777153..8519f60 100644
69150 --- a/lib/Kconfig.debug
69151 +++ b/lib/Kconfig.debug
69152 @@ -1132,6 +1132,7 @@ config LATENCYTOP
69153 depends on DEBUG_KERNEL
69154 depends on STACKTRACE_SUPPORT
69155 depends on PROC_FS
69156 + depends on !GRKERNSEC_HIDESYM
69157 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
69158 select KALLSYMS
69159 select KALLSYMS_ALL
69160 diff --git a/lib/bitmap.c b/lib/bitmap.c
69161 index b5a8b6a..a69623c 100644
69162 --- a/lib/bitmap.c
69163 +++ b/lib/bitmap.c
69164 @@ -421,7 +421,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
69165 {
69166 int c, old_c, totaldigits, ndigits, nchunks, nbits;
69167 u32 chunk;
69168 - const char __user __force *ubuf = (const char __user __force *)buf;
69169 + const char __user *ubuf = (const char __force_user *)buf;
69170
69171 bitmap_zero(maskp, nmaskbits);
69172
69173 @@ -506,7 +506,7 @@ int bitmap_parse_user(const char __user *ubuf,
69174 {
69175 if (!access_ok(VERIFY_READ, ubuf, ulen))
69176 return -EFAULT;
69177 - return __bitmap_parse((const char __force *)ubuf,
69178 + return __bitmap_parse((const char __force_kernel *)ubuf,
69179 ulen, 1, maskp, nmaskbits);
69180
69181 }
69182 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
69183 {
69184 unsigned a, b;
69185 int c, old_c, totaldigits;
69186 - const char __user __force *ubuf = (const char __user __force *)buf;
69187 + const char __user *ubuf = (const char __force_user *)buf;
69188 int exp_digit, in_range;
69189
69190 totaldigits = c = 0;
69191 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
69192 {
69193 if (!access_ok(VERIFY_READ, ubuf, ulen))
69194 return -EFAULT;
69195 - return __bitmap_parselist((const char __force *)ubuf,
69196 + return __bitmap_parselist((const char __force_kernel *)ubuf,
69197 ulen, 1, maskp, nmaskbits);
69198 }
69199 EXPORT_SYMBOL(bitmap_parselist_user);
69200 diff --git a/lib/bug.c b/lib/bug.c
69201 index a28c141..2bd3d95 100644
69202 --- a/lib/bug.c
69203 +++ b/lib/bug.c
69204 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
69205 return BUG_TRAP_TYPE_NONE;
69206
69207 bug = find_bug(bugaddr);
69208 + if (!bug)
69209 + return BUG_TRAP_TYPE_NONE;
69210
69211 file = NULL;
69212 line = 0;
69213 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
69214 index 0ab9ae8..f01ceca 100644
69215 --- a/lib/debugobjects.c
69216 +++ b/lib/debugobjects.c
69217 @@ -288,7 +288,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
69218 if (limit > 4)
69219 return;
69220
69221 - is_on_stack = object_is_on_stack(addr);
69222 + is_on_stack = object_starts_on_stack(addr);
69223 if (is_on_stack == onstack)
69224 return;
69225
69226 diff --git a/lib/devres.c b/lib/devres.c
69227 index 80b9c76..9e32279 100644
69228 --- a/lib/devres.c
69229 +++ b/lib/devres.c
69230 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
69231 void devm_iounmap(struct device *dev, void __iomem *addr)
69232 {
69233 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
69234 - (void *)addr));
69235 + (void __force *)addr));
69236 iounmap(addr);
69237 }
69238 EXPORT_SYMBOL(devm_iounmap);
69239 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
69240 {
69241 ioport_unmap(addr);
69242 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
69243 - devm_ioport_map_match, (void *)addr));
69244 + devm_ioport_map_match, (void __force *)addr));
69245 }
69246 EXPORT_SYMBOL(devm_ioport_unmap);
69247
69248 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
69249 index 13ef233..5241683 100644
69250 --- a/lib/dma-debug.c
69251 +++ b/lib/dma-debug.c
69252 @@ -924,7 +924,7 @@ out:
69253
69254 static void check_for_stack(struct device *dev, void *addr)
69255 {
69256 - if (object_is_on_stack(addr))
69257 + if (object_starts_on_stack(addr))
69258 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
69259 "stack [addr=%p]\n", addr);
69260 }
69261 diff --git a/lib/extable.c b/lib/extable.c
69262 index 4cac81e..63e9b8f 100644
69263 --- a/lib/extable.c
69264 +++ b/lib/extable.c
69265 @@ -13,6 +13,7 @@
69266 #include <linux/init.h>
69267 #include <linux/sort.h>
69268 #include <asm/uaccess.h>
69269 +#include <asm/pgtable.h>
69270
69271 #ifndef ARCH_HAS_SORT_EXTABLE
69272 /*
69273 @@ -36,8 +37,10 @@ static int cmp_ex(const void *a, const void *b)
69274 void sort_extable(struct exception_table_entry *start,
69275 struct exception_table_entry *finish)
69276 {
69277 + pax_open_kernel();
69278 sort(start, finish - start, sizeof(struct exception_table_entry),
69279 cmp_ex, NULL);
69280 + pax_close_kernel();
69281 }
69282
69283 #ifdef CONFIG_MODULES
69284 diff --git a/lib/inflate.c b/lib/inflate.c
69285 index 013a761..c28f3fc 100644
69286 --- a/lib/inflate.c
69287 +++ b/lib/inflate.c
69288 @@ -269,7 +269,7 @@ static void free(void *where)
69289 malloc_ptr = free_mem_ptr;
69290 }
69291 #else
69292 -#define malloc(a) kmalloc(a, GFP_KERNEL)
69293 +#define malloc(a) kmalloc((a), GFP_KERNEL)
69294 #define free(a) kfree(a)
69295 #endif
69296
69297 diff --git a/lib/ioremap.c b/lib/ioremap.c
69298 index 0c9216c..863bd89 100644
69299 --- a/lib/ioremap.c
69300 +++ b/lib/ioremap.c
69301 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
69302 unsigned long next;
69303
69304 phys_addr -= addr;
69305 - pmd = pmd_alloc(&init_mm, pud, addr);
69306 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
69307 if (!pmd)
69308 return -ENOMEM;
69309 do {
69310 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
69311 unsigned long next;
69312
69313 phys_addr -= addr;
69314 - pud = pud_alloc(&init_mm, pgd, addr);
69315 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
69316 if (!pud)
69317 return -ENOMEM;
69318 do {
69319 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
69320 index bd2bea9..6b3c95e 100644
69321 --- a/lib/is_single_threaded.c
69322 +++ b/lib/is_single_threaded.c
69323 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
69324 struct task_struct *p, *t;
69325 bool ret;
69326
69327 + if (!mm)
69328 + return true;
69329 +
69330 if (atomic_read(&task->signal->live) != 1)
69331 return false;
69332
69333 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
69334 index 3ac50dc..240bb7e 100644
69335 --- a/lib/radix-tree.c
69336 +++ b/lib/radix-tree.c
69337 @@ -79,7 +79,7 @@ struct radix_tree_preload {
69338 int nr;
69339 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
69340 };
69341 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
69342 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
69343
69344 static inline void *ptr_to_indirect(void *ptr)
69345 {
69346 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
69347 index abbabec..362988d 100644
69348 --- a/lib/vsprintf.c
69349 +++ b/lib/vsprintf.c
69350 @@ -16,6 +16,9 @@
69351 * - scnprintf and vscnprintf
69352 */
69353
69354 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69355 +#define __INCLUDED_BY_HIDESYM 1
69356 +#endif
69357 #include <stdarg.h>
69358 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
69359 #include <linux/types.h>
69360 @@ -433,7 +436,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
69361 char sym[KSYM_SYMBOL_LEN];
69362 if (ext == 'B')
69363 sprint_backtrace(sym, value);
69364 - else if (ext != 'f' && ext != 's')
69365 + else if (ext != 'f' && ext != 's' && ext != 'a')
69366 sprint_symbol(sym, value);
69367 else
69368 kallsyms_lookup(value, NULL, NULL, NULL, sym);
69369 @@ -809,7 +812,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
69370 return number(buf, end, *(const netdev_features_t *)addr, spec);
69371 }
69372
69373 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69374 +int kptr_restrict __read_mostly = 2;
69375 +#else
69376 int kptr_restrict __read_mostly;
69377 +#endif
69378
69379 /*
69380 * Show a '%p' thing. A kernel extension is that the '%p' is followed
69381 @@ -823,6 +830,8 @@ int kptr_restrict __read_mostly;
69382 * - 'S' For symbolic direct pointers with offset
69383 * - 's' For symbolic direct pointers without offset
69384 * - 'B' For backtraced symbolic direct pointers with offset
69385 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
69386 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
69387 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
69388 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
69389 * - 'M' For a 6-byte MAC address, it prints the address in the
69390 @@ -868,12 +877,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
69391 {
69392 if (!ptr && *fmt != 'K') {
69393 /*
69394 - * Print (null) with the same width as a pointer so it makes
69395 + * Print (nil) with the same width as a pointer so it makes
69396 * tabular output look nice.
69397 */
69398 if (spec.field_width == -1)
69399 spec.field_width = 2 * sizeof(void *);
69400 - return string(buf, end, "(null)", spec);
69401 + return string(buf, end, "(nil)", spec);
69402 }
69403
69404 switch (*fmt) {
69405 @@ -883,6 +892,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
69406 /* Fallthrough */
69407 case 'S':
69408 case 's':
69409 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69410 + break;
69411 +#else
69412 + return symbol_string(buf, end, ptr, spec, *fmt);
69413 +#endif
69414 + case 'A':
69415 + case 'a':
69416 case 'B':
69417 return symbol_string(buf, end, ptr, spec, *fmt);
69418 case 'R':
69419 @@ -1653,11 +1669,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
69420 typeof(type) value; \
69421 if (sizeof(type) == 8) { \
69422 args = PTR_ALIGN(args, sizeof(u32)); \
69423 - *(u32 *)&value = *(u32 *)args; \
69424 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
69425 + *(u32 *)&value = *(const u32 *)args; \
69426 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
69427 } else { \
69428 args = PTR_ALIGN(args, sizeof(type)); \
69429 - value = *(typeof(type) *)args; \
69430 + value = *(const typeof(type) *)args; \
69431 } \
69432 args += sizeof(type); \
69433 value; \
69434 @@ -1720,7 +1736,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
69435 case FORMAT_TYPE_STR: {
69436 const char *str_arg = args;
69437 args += strlen(str_arg) + 1;
69438 - str = string(str, end, (char *)str_arg, spec);
69439 + str = string(str, end, str_arg, spec);
69440 break;
69441 }
69442
69443 diff --git a/localversion-grsec b/localversion-grsec
69444 new file mode 100644
69445 index 0000000..7cd6065
69446 --- /dev/null
69447 +++ b/localversion-grsec
69448 @@ -0,0 +1 @@
69449 +-grsec
69450 diff --git a/mm/Kconfig b/mm/Kconfig
69451 index e338407..4210331 100644
69452 --- a/mm/Kconfig
69453 +++ b/mm/Kconfig
69454 @@ -247,10 +247,10 @@ config KSM
69455 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
69456
69457 config DEFAULT_MMAP_MIN_ADDR
69458 - int "Low address space to protect from user allocation"
69459 + int "Low address space to protect from user allocation"
69460 depends on MMU
69461 - default 4096
69462 - help
69463 + default 65536
69464 + help
69465 This is the portion of low virtual memory which should be protected
69466 from userspace allocation. Keeping a user from writing to low pages
69467 can help reduce the impact of kernel NULL pointer bugs.
69468 @@ -280,7 +280,7 @@ config MEMORY_FAILURE
69469
69470 config HWPOISON_INJECT
69471 tristate "HWPoison pages injector"
69472 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
69473 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
69474 select PROC_PAGE_MONITOR
69475
69476 config NOMMU_INITIAL_TRIM_EXCESS
69477 diff --git a/mm/filemap.c b/mm/filemap.c
69478 index 79c4b2b..596b417 100644
69479 --- a/mm/filemap.c
69480 +++ b/mm/filemap.c
69481 @@ -1762,7 +1762,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
69482 struct address_space *mapping = file->f_mapping;
69483
69484 if (!mapping->a_ops->readpage)
69485 - return -ENOEXEC;
69486 + return -ENODEV;
69487 file_accessed(file);
69488 vma->vm_ops = &generic_file_vm_ops;
69489 vma->vm_flags |= VM_CAN_NONLINEAR;
69490 @@ -2168,6 +2168,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
69491 *pos = i_size_read(inode);
69492
69493 if (limit != RLIM_INFINITY) {
69494 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
69495 if (*pos >= limit) {
69496 send_sig(SIGXFSZ, current, 0);
69497 return -EFBIG;
69498 diff --git a/mm/fremap.c b/mm/fremap.c
69499 index 9ed4fd4..c42648d 100644
69500 --- a/mm/fremap.c
69501 +++ b/mm/fremap.c
69502 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
69503 retry:
69504 vma = find_vma(mm, start);
69505
69506 +#ifdef CONFIG_PAX_SEGMEXEC
69507 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
69508 + goto out;
69509 +#endif
69510 +
69511 /*
69512 * Make sure the vma is shared, that it supports prefaulting,
69513 * and that the remapped range is valid and fully within
69514 diff --git a/mm/highmem.c b/mm/highmem.c
69515 index 57d82c6..e9e0552 100644
69516 --- a/mm/highmem.c
69517 +++ b/mm/highmem.c
69518 @@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
69519 * So no dangers, even with speculative execution.
69520 */
69521 page = pte_page(pkmap_page_table[i]);
69522 + pax_open_kernel();
69523 pte_clear(&init_mm, (unsigned long)page_address(page),
69524 &pkmap_page_table[i]);
69525 -
69526 + pax_close_kernel();
69527 set_page_address(page, NULL);
69528 need_flush = 1;
69529 }
69530 @@ -186,9 +187,11 @@ start:
69531 }
69532 }
69533 vaddr = PKMAP_ADDR(last_pkmap_nr);
69534 +
69535 + pax_open_kernel();
69536 set_pte_at(&init_mm, vaddr,
69537 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
69538 -
69539 + pax_close_kernel();
69540 pkmap_count[last_pkmap_nr] = 1;
69541 set_page_address(page, (void *)vaddr);
69542
69543 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
69544 index f0e5306..cb9398e 100644
69545 --- a/mm/huge_memory.c
69546 +++ b/mm/huge_memory.c
69547 @@ -733,7 +733,7 @@ out:
69548 * run pte_offset_map on the pmd, if an huge pmd could
69549 * materialize from under us from a different thread.
69550 */
69551 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
69552 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
69553 return VM_FAULT_OOM;
69554 /* if an huge pmd materialized from under us just retry later */
69555 if (unlikely(pmd_trans_huge(*pmd)))
69556 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
69557 index 263e177..3f36aec 100644
69558 --- a/mm/hugetlb.c
69559 +++ b/mm/hugetlb.c
69560 @@ -2446,6 +2446,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
69561 return 1;
69562 }
69563
69564 +#ifdef CONFIG_PAX_SEGMEXEC
69565 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
69566 +{
69567 + struct mm_struct *mm = vma->vm_mm;
69568 + struct vm_area_struct *vma_m;
69569 + unsigned long address_m;
69570 + pte_t *ptep_m;
69571 +
69572 + vma_m = pax_find_mirror_vma(vma);
69573 + if (!vma_m)
69574 + return;
69575 +
69576 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
69577 + address_m = address + SEGMEXEC_TASK_SIZE;
69578 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
69579 + get_page(page_m);
69580 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
69581 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
69582 +}
69583 +#endif
69584 +
69585 /*
69586 * Hugetlb_cow() should be called with page lock of the original hugepage held.
69587 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
69588 @@ -2558,6 +2579,11 @@ retry_avoidcopy:
69589 make_huge_pte(vma, new_page, 1));
69590 page_remove_rmap(old_page);
69591 hugepage_add_new_anon_rmap(new_page, vma, address);
69592 +
69593 +#ifdef CONFIG_PAX_SEGMEXEC
69594 + pax_mirror_huge_pte(vma, address, new_page);
69595 +#endif
69596 +
69597 /* Make the old page be freed below */
69598 new_page = old_page;
69599 mmu_notifier_invalidate_range_end(mm,
69600 @@ -2712,6 +2738,10 @@ retry:
69601 && (vma->vm_flags & VM_SHARED)));
69602 set_huge_pte_at(mm, address, ptep, new_pte);
69603
69604 +#ifdef CONFIG_PAX_SEGMEXEC
69605 + pax_mirror_huge_pte(vma, address, page);
69606 +#endif
69607 +
69608 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
69609 /* Optimization, do the COW without a second fault */
69610 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
69611 @@ -2741,6 +2771,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69612 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
69613 struct hstate *h = hstate_vma(vma);
69614
69615 +#ifdef CONFIG_PAX_SEGMEXEC
69616 + struct vm_area_struct *vma_m;
69617 +#endif
69618 +
69619 address &= huge_page_mask(h);
69620
69621 ptep = huge_pte_offset(mm, address);
69622 @@ -2754,6 +2788,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69623 VM_FAULT_SET_HINDEX(h - hstates);
69624 }
69625
69626 +#ifdef CONFIG_PAX_SEGMEXEC
69627 + vma_m = pax_find_mirror_vma(vma);
69628 + if (vma_m) {
69629 + unsigned long address_m;
69630 +
69631 + if (vma->vm_start > vma_m->vm_start) {
69632 + address_m = address;
69633 + address -= SEGMEXEC_TASK_SIZE;
69634 + vma = vma_m;
69635 + h = hstate_vma(vma);
69636 + } else
69637 + address_m = address + SEGMEXEC_TASK_SIZE;
69638 +
69639 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
69640 + return VM_FAULT_OOM;
69641 + address_m &= HPAGE_MASK;
69642 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
69643 + }
69644 +#endif
69645 +
69646 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
69647 if (!ptep)
69648 return VM_FAULT_OOM;
69649 diff --git a/mm/internal.h b/mm/internal.h
69650 index 2189af4..f2ca332 100644
69651 --- a/mm/internal.h
69652 +++ b/mm/internal.h
69653 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
69654 * in mm/page_alloc.c
69655 */
69656 extern void __free_pages_bootmem(struct page *page, unsigned int order);
69657 +extern void free_compound_page(struct page *page);
69658 extern void prep_compound_page(struct page *page, unsigned long order);
69659 #ifdef CONFIG_MEMORY_FAILURE
69660 extern bool is_free_buddy_page(struct page *page);
69661 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
69662 index 45eb621..6ccd8ea 100644
69663 --- a/mm/kmemleak.c
69664 +++ b/mm/kmemleak.c
69665 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
69666
69667 for (i = 0; i < object->trace_len; i++) {
69668 void *ptr = (void *)object->trace[i];
69669 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
69670 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
69671 }
69672 }
69673
69674 diff --git a/mm/maccess.c b/mm/maccess.c
69675 index d53adf9..03a24bf 100644
69676 --- a/mm/maccess.c
69677 +++ b/mm/maccess.c
69678 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
69679 set_fs(KERNEL_DS);
69680 pagefault_disable();
69681 ret = __copy_from_user_inatomic(dst,
69682 - (__force const void __user *)src, size);
69683 + (const void __force_user *)src, size);
69684 pagefault_enable();
69685 set_fs(old_fs);
69686
69687 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
69688
69689 set_fs(KERNEL_DS);
69690 pagefault_disable();
69691 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
69692 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
69693 pagefault_enable();
69694 set_fs(old_fs);
69695
69696 diff --git a/mm/madvise.c b/mm/madvise.c
69697 index 1ccbba5..819f7d5 100644
69698 --- a/mm/madvise.c
69699 +++ b/mm/madvise.c
69700 @@ -13,6 +13,8 @@
69701 #include <linux/hugetlb.h>
69702 #include <linux/sched.h>
69703 #include <linux/ksm.h>
69704 +#include <linux/fs.h>
69705 +#include <linux/file.h>
69706
69707 /*
69708 * Any behaviour which results in changes to the vma->vm_flags needs to
69709 @@ -45,6 +47,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
69710 pgoff_t pgoff;
69711 unsigned long new_flags = vma->vm_flags;
69712
69713 +#ifdef CONFIG_PAX_SEGMEXEC
69714 + struct vm_area_struct *vma_m;
69715 +#endif
69716 +
69717 switch (behavior) {
69718 case MADV_NORMAL:
69719 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
69720 @@ -116,6 +122,13 @@ success:
69721 /*
69722 * vm_flags is protected by the mmap_sem held in write mode.
69723 */
69724 +
69725 +#ifdef CONFIG_PAX_SEGMEXEC
69726 + vma_m = pax_find_mirror_vma(vma);
69727 + if (vma_m)
69728 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
69729 +#endif
69730 +
69731 vma->vm_flags = new_flags;
69732
69733 out:
69734 @@ -174,6 +187,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
69735 struct vm_area_struct ** prev,
69736 unsigned long start, unsigned long end)
69737 {
69738 +
69739 +#ifdef CONFIG_PAX_SEGMEXEC
69740 + struct vm_area_struct *vma_m;
69741 +#endif
69742 +
69743 *prev = vma;
69744 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
69745 return -EINVAL;
69746 @@ -186,6 +204,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
69747 zap_page_range(vma, start, end - start, &details);
69748 } else
69749 zap_page_range(vma, start, end - start, NULL);
69750 +
69751 +#ifdef CONFIG_PAX_SEGMEXEC
69752 + vma_m = pax_find_mirror_vma(vma);
69753 + if (vma_m) {
69754 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
69755 + struct zap_details details = {
69756 + .nonlinear_vma = vma_m,
69757 + .last_index = ULONG_MAX,
69758 + };
69759 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
69760 + } else
69761 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
69762 + }
69763 +#endif
69764 +
69765 return 0;
69766 }
69767
69768 @@ -203,16 +236,17 @@ static long madvise_remove(struct vm_area_struct *vma,
69769 struct address_space *mapping;
69770 loff_t offset, endoff;
69771 int error;
69772 + struct file *f;
69773
69774 *prev = NULL; /* tell sys_madvise we drop mmap_sem */
69775
69776 if (vma->vm_flags & (VM_LOCKED|VM_NONLINEAR|VM_HUGETLB))
69777 return -EINVAL;
69778
69779 - if (!vma->vm_file || !vma->vm_file->f_mapping
69780 - || !vma->vm_file->f_mapping->host) {
69781 - return -EINVAL;
69782 - }
69783 + f = vma->vm_file;
69784 +
69785 + if (!f || !f->f_mapping || !f->f_mapping->host)
69786 + return -EINVAL;
69787
69788 if ((vma->vm_flags & (VM_SHARED|VM_WRITE)) != (VM_SHARED|VM_WRITE))
69789 return -EACCES;
69790 @@ -224,10 +258,16 @@ static long madvise_remove(struct vm_area_struct *vma,
69791 endoff = (loff_t)(end - vma->vm_start - 1)
69792 + ((loff_t)vma->vm_pgoff << PAGE_SHIFT);
69793
69794 - /* vmtruncate_range needs to take i_mutex */
69795 + /* vmtruncate_range needs to take i_mutex. We need to
69796 + * explicitly grab a reference because the vma (and hence the
69797 + * vma's reference to the file) can go away as soon as we drop
69798 + * mmap_sem.
69799 + */
69800 + get_file(f);
69801 up_read(&current->mm->mmap_sem);
69802 error = vmtruncate_range(mapping->host, offset, endoff);
69803 down_read(&current->mm->mmap_sem);
69804 + fput(f);
69805 return error;
69806 }
69807
69808 @@ -384,6 +424,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
69809 if (end < start)
69810 goto out;
69811
69812 +#ifdef CONFIG_PAX_SEGMEXEC
69813 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
69814 + if (end > SEGMEXEC_TASK_SIZE)
69815 + goto out;
69816 + } else
69817 +#endif
69818 +
69819 + if (end > TASK_SIZE)
69820 + goto out;
69821 +
69822 error = 0;
69823 if (end == start)
69824 goto out;
69825 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
69826 index 97cc273..6ed703f 100644
69827 --- a/mm/memory-failure.c
69828 +++ b/mm/memory-failure.c
69829 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
69830
69831 int sysctl_memory_failure_recovery __read_mostly = 1;
69832
69833 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
69834 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
69835
69836 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
69837
69838 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
69839 pfn, t->comm, t->pid);
69840 si.si_signo = SIGBUS;
69841 si.si_errno = 0;
69842 - si.si_addr = (void *)addr;
69843 + si.si_addr = (void __user *)addr;
69844 #ifdef __ARCH_SI_TRAPNO
69845 si.si_trapno = trapno;
69846 #endif
69847 @@ -1036,7 +1036,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
69848 }
69849
69850 nr_pages = 1 << compound_trans_order(hpage);
69851 - atomic_long_add(nr_pages, &mce_bad_pages);
69852 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
69853
69854 /*
69855 * We need/can do nothing about count=0 pages.
69856 @@ -1066,7 +1066,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
69857 if (!PageHWPoison(hpage)
69858 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
69859 || (p != hpage && TestSetPageHWPoison(hpage))) {
69860 - atomic_long_sub(nr_pages, &mce_bad_pages);
69861 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69862 return 0;
69863 }
69864 set_page_hwpoison_huge_page(hpage);
69865 @@ -1124,7 +1124,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
69866 }
69867 if (hwpoison_filter(p)) {
69868 if (TestClearPageHWPoison(p))
69869 - atomic_long_sub(nr_pages, &mce_bad_pages);
69870 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69871 unlock_page(hpage);
69872 put_page(hpage);
69873 return 0;
69874 @@ -1319,7 +1319,7 @@ int unpoison_memory(unsigned long pfn)
69875 return 0;
69876 }
69877 if (TestClearPageHWPoison(p))
69878 - atomic_long_sub(nr_pages, &mce_bad_pages);
69879 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69880 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
69881 return 0;
69882 }
69883 @@ -1333,7 +1333,7 @@ int unpoison_memory(unsigned long pfn)
69884 */
69885 if (TestClearPageHWPoison(page)) {
69886 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
69887 - atomic_long_sub(nr_pages, &mce_bad_pages);
69888 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69889 freeit = 1;
69890 if (PageHuge(page))
69891 clear_page_hwpoison_huge_page(page);
69892 @@ -1446,7 +1446,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
69893 }
69894 done:
69895 if (!PageHWPoison(hpage))
69896 - atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
69897 + atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
69898 set_page_hwpoison_huge_page(hpage);
69899 dequeue_hwpoisoned_huge_page(hpage);
69900 /* keep elevated page count for bad page */
69901 @@ -1577,7 +1577,7 @@ int soft_offline_page(struct page *page, int flags)
69902 return ret;
69903
69904 done:
69905 - atomic_long_add(1, &mce_bad_pages);
69906 + atomic_long_add_unchecked(1, &mce_bad_pages);
69907 SetPageHWPoison(page);
69908 /* keep elevated page count for bad page */
69909 return ret;
69910 diff --git a/mm/memory.c b/mm/memory.c
69911 index 6105f47..3363489 100644
69912 --- a/mm/memory.c
69913 +++ b/mm/memory.c
69914 @@ -434,8 +434,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
69915 return;
69916
69917 pmd = pmd_offset(pud, start);
69918 +
69919 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
69920 pud_clear(pud);
69921 pmd_free_tlb(tlb, pmd, start);
69922 +#endif
69923 +
69924 }
69925
69926 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
69927 @@ -466,9 +470,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
69928 if (end - 1 > ceiling - 1)
69929 return;
69930
69931 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
69932 pud = pud_offset(pgd, start);
69933 pgd_clear(pgd);
69934 pud_free_tlb(tlb, pud, start);
69935 +#endif
69936 +
69937 }
69938
69939 /*
69940 @@ -1597,12 +1604,6 @@ no_page_table:
69941 return page;
69942 }
69943
69944 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
69945 -{
69946 - return stack_guard_page_start(vma, addr) ||
69947 - stack_guard_page_end(vma, addr+PAGE_SIZE);
69948 -}
69949 -
69950 /**
69951 * __get_user_pages() - pin user pages in memory
69952 * @tsk: task_struct of target task
69953 @@ -1675,10 +1676,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
69954 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
69955 i = 0;
69956
69957 - do {
69958 + while (nr_pages) {
69959 struct vm_area_struct *vma;
69960
69961 - vma = find_extend_vma(mm, start);
69962 + vma = find_vma(mm, start);
69963 if (!vma && in_gate_area(mm, start)) {
69964 unsigned long pg = start & PAGE_MASK;
69965 pgd_t *pgd;
69966 @@ -1726,7 +1727,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
69967 goto next_page;
69968 }
69969
69970 - if (!vma ||
69971 + if (!vma || start < vma->vm_start ||
69972 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
69973 !(vm_flags & vma->vm_flags))
69974 return i ? : -EFAULT;
69975 @@ -1753,11 +1754,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
69976 int ret;
69977 unsigned int fault_flags = 0;
69978
69979 - /* For mlock, just skip the stack guard page. */
69980 - if (foll_flags & FOLL_MLOCK) {
69981 - if (stack_guard_page(vma, start))
69982 - goto next_page;
69983 - }
69984 if (foll_flags & FOLL_WRITE)
69985 fault_flags |= FAULT_FLAG_WRITE;
69986 if (nonblocking)
69987 @@ -1831,7 +1827,7 @@ next_page:
69988 start += PAGE_SIZE;
69989 nr_pages--;
69990 } while (nr_pages && start < vma->vm_end);
69991 - } while (nr_pages);
69992 + }
69993 return i;
69994 }
69995 EXPORT_SYMBOL(__get_user_pages);
69996 @@ -2038,6 +2034,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
69997 page_add_file_rmap(page);
69998 set_pte_at(mm, addr, pte, mk_pte(page, prot));
69999
70000 +#ifdef CONFIG_PAX_SEGMEXEC
70001 + pax_mirror_file_pte(vma, addr, page, ptl);
70002 +#endif
70003 +
70004 retval = 0;
70005 pte_unmap_unlock(pte, ptl);
70006 return retval;
70007 @@ -2072,10 +2072,22 @@ out:
70008 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
70009 struct page *page)
70010 {
70011 +
70012 +#ifdef CONFIG_PAX_SEGMEXEC
70013 + struct vm_area_struct *vma_m;
70014 +#endif
70015 +
70016 if (addr < vma->vm_start || addr >= vma->vm_end)
70017 return -EFAULT;
70018 if (!page_count(page))
70019 return -EINVAL;
70020 +
70021 +#ifdef CONFIG_PAX_SEGMEXEC
70022 + vma_m = pax_find_mirror_vma(vma);
70023 + if (vma_m)
70024 + vma_m->vm_flags |= VM_INSERTPAGE;
70025 +#endif
70026 +
70027 vma->vm_flags |= VM_INSERTPAGE;
70028 return insert_page(vma, addr, page, vma->vm_page_prot);
70029 }
70030 @@ -2161,6 +2173,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
70031 unsigned long pfn)
70032 {
70033 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
70034 + BUG_ON(vma->vm_mirror);
70035
70036 if (addr < vma->vm_start || addr >= vma->vm_end)
70037 return -EFAULT;
70038 @@ -2368,7 +2381,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
70039
70040 BUG_ON(pud_huge(*pud));
70041
70042 - pmd = pmd_alloc(mm, pud, addr);
70043 + pmd = (mm == &init_mm) ?
70044 + pmd_alloc_kernel(mm, pud, addr) :
70045 + pmd_alloc(mm, pud, addr);
70046 if (!pmd)
70047 return -ENOMEM;
70048 do {
70049 @@ -2388,7 +2403,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
70050 unsigned long next;
70051 int err;
70052
70053 - pud = pud_alloc(mm, pgd, addr);
70054 + pud = (mm == &init_mm) ?
70055 + pud_alloc_kernel(mm, pgd, addr) :
70056 + pud_alloc(mm, pgd, addr);
70057 if (!pud)
70058 return -ENOMEM;
70059 do {
70060 @@ -2476,6 +2493,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
70061 copy_user_highpage(dst, src, va, vma);
70062 }
70063
70064 +#ifdef CONFIG_PAX_SEGMEXEC
70065 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
70066 +{
70067 + struct mm_struct *mm = vma->vm_mm;
70068 + spinlock_t *ptl;
70069 + pte_t *pte, entry;
70070 +
70071 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
70072 + entry = *pte;
70073 + if (!pte_present(entry)) {
70074 + if (!pte_none(entry)) {
70075 + BUG_ON(pte_file(entry));
70076 + free_swap_and_cache(pte_to_swp_entry(entry));
70077 + pte_clear_not_present_full(mm, address, pte, 0);
70078 + }
70079 + } else {
70080 + struct page *page;
70081 +
70082 + flush_cache_page(vma, address, pte_pfn(entry));
70083 + entry = ptep_clear_flush(vma, address, pte);
70084 + BUG_ON(pte_dirty(entry));
70085 + page = vm_normal_page(vma, address, entry);
70086 + if (page) {
70087 + update_hiwater_rss(mm);
70088 + if (PageAnon(page))
70089 + dec_mm_counter_fast(mm, MM_ANONPAGES);
70090 + else
70091 + dec_mm_counter_fast(mm, MM_FILEPAGES);
70092 + page_remove_rmap(page);
70093 + page_cache_release(page);
70094 + }
70095 + }
70096 + pte_unmap_unlock(pte, ptl);
70097 +}
70098 +
70099 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
70100 + *
70101 + * the ptl of the lower mapped page is held on entry and is not released on exit
70102 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
70103 + */
70104 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
70105 +{
70106 + struct mm_struct *mm = vma->vm_mm;
70107 + unsigned long address_m;
70108 + spinlock_t *ptl_m;
70109 + struct vm_area_struct *vma_m;
70110 + pmd_t *pmd_m;
70111 + pte_t *pte_m, entry_m;
70112 +
70113 + BUG_ON(!page_m || !PageAnon(page_m));
70114 +
70115 + vma_m = pax_find_mirror_vma(vma);
70116 + if (!vma_m)
70117 + return;
70118 +
70119 + BUG_ON(!PageLocked(page_m));
70120 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70121 + address_m = address + SEGMEXEC_TASK_SIZE;
70122 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70123 + pte_m = pte_offset_map(pmd_m, address_m);
70124 + ptl_m = pte_lockptr(mm, pmd_m);
70125 + if (ptl != ptl_m) {
70126 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70127 + if (!pte_none(*pte_m))
70128 + goto out;
70129 + }
70130 +
70131 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
70132 + page_cache_get(page_m);
70133 + page_add_anon_rmap(page_m, vma_m, address_m);
70134 + inc_mm_counter_fast(mm, MM_ANONPAGES);
70135 + set_pte_at(mm, address_m, pte_m, entry_m);
70136 + update_mmu_cache(vma_m, address_m, entry_m);
70137 +out:
70138 + if (ptl != ptl_m)
70139 + spin_unlock(ptl_m);
70140 + pte_unmap(pte_m);
70141 + unlock_page(page_m);
70142 +}
70143 +
70144 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
70145 +{
70146 + struct mm_struct *mm = vma->vm_mm;
70147 + unsigned long address_m;
70148 + spinlock_t *ptl_m;
70149 + struct vm_area_struct *vma_m;
70150 + pmd_t *pmd_m;
70151 + pte_t *pte_m, entry_m;
70152 +
70153 + BUG_ON(!page_m || PageAnon(page_m));
70154 +
70155 + vma_m = pax_find_mirror_vma(vma);
70156 + if (!vma_m)
70157 + return;
70158 +
70159 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70160 + address_m = address + SEGMEXEC_TASK_SIZE;
70161 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70162 + pte_m = pte_offset_map(pmd_m, address_m);
70163 + ptl_m = pte_lockptr(mm, pmd_m);
70164 + if (ptl != ptl_m) {
70165 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70166 + if (!pte_none(*pte_m))
70167 + goto out;
70168 + }
70169 +
70170 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
70171 + page_cache_get(page_m);
70172 + page_add_file_rmap(page_m);
70173 + inc_mm_counter_fast(mm, MM_FILEPAGES);
70174 + set_pte_at(mm, address_m, pte_m, entry_m);
70175 + update_mmu_cache(vma_m, address_m, entry_m);
70176 +out:
70177 + if (ptl != ptl_m)
70178 + spin_unlock(ptl_m);
70179 + pte_unmap(pte_m);
70180 +}
70181 +
70182 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
70183 +{
70184 + struct mm_struct *mm = vma->vm_mm;
70185 + unsigned long address_m;
70186 + spinlock_t *ptl_m;
70187 + struct vm_area_struct *vma_m;
70188 + pmd_t *pmd_m;
70189 + pte_t *pte_m, entry_m;
70190 +
70191 + vma_m = pax_find_mirror_vma(vma);
70192 + if (!vma_m)
70193 + return;
70194 +
70195 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70196 + address_m = address + SEGMEXEC_TASK_SIZE;
70197 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70198 + pte_m = pte_offset_map(pmd_m, address_m);
70199 + ptl_m = pte_lockptr(mm, pmd_m);
70200 + if (ptl != ptl_m) {
70201 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70202 + if (!pte_none(*pte_m))
70203 + goto out;
70204 + }
70205 +
70206 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
70207 + set_pte_at(mm, address_m, pte_m, entry_m);
70208 +out:
70209 + if (ptl != ptl_m)
70210 + spin_unlock(ptl_m);
70211 + pte_unmap(pte_m);
70212 +}
70213 +
70214 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
70215 +{
70216 + struct page *page_m;
70217 + pte_t entry;
70218 +
70219 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
70220 + goto out;
70221 +
70222 + entry = *pte;
70223 + page_m = vm_normal_page(vma, address, entry);
70224 + if (!page_m)
70225 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
70226 + else if (PageAnon(page_m)) {
70227 + if (pax_find_mirror_vma(vma)) {
70228 + pte_unmap_unlock(pte, ptl);
70229 + lock_page(page_m);
70230 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
70231 + if (pte_same(entry, *pte))
70232 + pax_mirror_anon_pte(vma, address, page_m, ptl);
70233 + else
70234 + unlock_page(page_m);
70235 + }
70236 + } else
70237 + pax_mirror_file_pte(vma, address, page_m, ptl);
70238 +
70239 +out:
70240 + pte_unmap_unlock(pte, ptl);
70241 +}
70242 +#endif
70243 +
70244 /*
70245 * This routine handles present pages, when users try to write
70246 * to a shared page. It is done by copying the page to a new address
70247 @@ -2687,6 +2884,12 @@ gotten:
70248 */
70249 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
70250 if (likely(pte_same(*page_table, orig_pte))) {
70251 +
70252 +#ifdef CONFIG_PAX_SEGMEXEC
70253 + if (pax_find_mirror_vma(vma))
70254 + BUG_ON(!trylock_page(new_page));
70255 +#endif
70256 +
70257 if (old_page) {
70258 if (!PageAnon(old_page)) {
70259 dec_mm_counter_fast(mm, MM_FILEPAGES);
70260 @@ -2738,6 +2941,10 @@ gotten:
70261 page_remove_rmap(old_page);
70262 }
70263
70264 +#ifdef CONFIG_PAX_SEGMEXEC
70265 + pax_mirror_anon_pte(vma, address, new_page, ptl);
70266 +#endif
70267 +
70268 /* Free the old page.. */
70269 new_page = old_page;
70270 ret |= VM_FAULT_WRITE;
70271 @@ -3017,6 +3224,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
70272 swap_free(entry);
70273 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
70274 try_to_free_swap(page);
70275 +
70276 +#ifdef CONFIG_PAX_SEGMEXEC
70277 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
70278 +#endif
70279 +
70280 unlock_page(page);
70281 if (swapcache) {
70282 /*
70283 @@ -3040,6 +3252,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
70284
70285 /* No need to invalidate - it was non-present before */
70286 update_mmu_cache(vma, address, page_table);
70287 +
70288 +#ifdef CONFIG_PAX_SEGMEXEC
70289 + pax_mirror_anon_pte(vma, address, page, ptl);
70290 +#endif
70291 +
70292 unlock:
70293 pte_unmap_unlock(page_table, ptl);
70294 out:
70295 @@ -3059,40 +3276,6 @@ out_release:
70296 }
70297
70298 /*
70299 - * This is like a special single-page "expand_{down|up}wards()",
70300 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
70301 - * doesn't hit another vma.
70302 - */
70303 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
70304 -{
70305 - address &= PAGE_MASK;
70306 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
70307 - struct vm_area_struct *prev = vma->vm_prev;
70308 -
70309 - /*
70310 - * Is there a mapping abutting this one below?
70311 - *
70312 - * That's only ok if it's the same stack mapping
70313 - * that has gotten split..
70314 - */
70315 - if (prev && prev->vm_end == address)
70316 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
70317 -
70318 - expand_downwards(vma, address - PAGE_SIZE);
70319 - }
70320 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
70321 - struct vm_area_struct *next = vma->vm_next;
70322 -
70323 - /* As VM_GROWSDOWN but s/below/above/ */
70324 - if (next && next->vm_start == address + PAGE_SIZE)
70325 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
70326 -
70327 - expand_upwards(vma, address + PAGE_SIZE);
70328 - }
70329 - return 0;
70330 -}
70331 -
70332 -/*
70333 * We enter with non-exclusive mmap_sem (to exclude vma changes,
70334 * but allow concurrent faults), and pte mapped but not yet locked.
70335 * We return with mmap_sem still held, but pte unmapped and unlocked.
70336 @@ -3101,27 +3284,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
70337 unsigned long address, pte_t *page_table, pmd_t *pmd,
70338 unsigned int flags)
70339 {
70340 - struct page *page;
70341 + struct page *page = NULL;
70342 spinlock_t *ptl;
70343 pte_t entry;
70344
70345 - pte_unmap(page_table);
70346 -
70347 - /* Check if we need to add a guard page to the stack */
70348 - if (check_stack_guard_page(vma, address) < 0)
70349 - return VM_FAULT_SIGBUS;
70350 -
70351 - /* Use the zero-page for reads */
70352 if (!(flags & FAULT_FLAG_WRITE)) {
70353 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
70354 vma->vm_page_prot));
70355 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
70356 + ptl = pte_lockptr(mm, pmd);
70357 + spin_lock(ptl);
70358 if (!pte_none(*page_table))
70359 goto unlock;
70360 goto setpte;
70361 }
70362
70363 /* Allocate our own private page. */
70364 + pte_unmap(page_table);
70365 +
70366 if (unlikely(anon_vma_prepare(vma)))
70367 goto oom;
70368 page = alloc_zeroed_user_highpage_movable(vma, address);
70369 @@ -3140,6 +3319,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
70370 if (!pte_none(*page_table))
70371 goto release;
70372
70373 +#ifdef CONFIG_PAX_SEGMEXEC
70374 + if (pax_find_mirror_vma(vma))
70375 + BUG_ON(!trylock_page(page));
70376 +#endif
70377 +
70378 inc_mm_counter_fast(mm, MM_ANONPAGES);
70379 page_add_new_anon_rmap(page, vma, address);
70380 setpte:
70381 @@ -3147,6 +3331,12 @@ setpte:
70382
70383 /* No need to invalidate - it was non-present before */
70384 update_mmu_cache(vma, address, page_table);
70385 +
70386 +#ifdef CONFIG_PAX_SEGMEXEC
70387 + if (page)
70388 + pax_mirror_anon_pte(vma, address, page, ptl);
70389 +#endif
70390 +
70391 unlock:
70392 pte_unmap_unlock(page_table, ptl);
70393 return 0;
70394 @@ -3290,6 +3480,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70395 */
70396 /* Only go through if we didn't race with anybody else... */
70397 if (likely(pte_same(*page_table, orig_pte))) {
70398 +
70399 +#ifdef CONFIG_PAX_SEGMEXEC
70400 + if (anon && pax_find_mirror_vma(vma))
70401 + BUG_ON(!trylock_page(page));
70402 +#endif
70403 +
70404 flush_icache_page(vma, page);
70405 entry = mk_pte(page, vma->vm_page_prot);
70406 if (flags & FAULT_FLAG_WRITE)
70407 @@ -3309,6 +3505,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70408
70409 /* no need to invalidate: a not-present page won't be cached */
70410 update_mmu_cache(vma, address, page_table);
70411 +
70412 +#ifdef CONFIG_PAX_SEGMEXEC
70413 + if (anon)
70414 + pax_mirror_anon_pte(vma, address, page, ptl);
70415 + else
70416 + pax_mirror_file_pte(vma, address, page, ptl);
70417 +#endif
70418 +
70419 } else {
70420 if (cow_page)
70421 mem_cgroup_uncharge_page(cow_page);
70422 @@ -3462,6 +3666,12 @@ int handle_pte_fault(struct mm_struct *mm,
70423 if (flags & FAULT_FLAG_WRITE)
70424 flush_tlb_fix_spurious_fault(vma, address);
70425 }
70426 +
70427 +#ifdef CONFIG_PAX_SEGMEXEC
70428 + pax_mirror_pte(vma, address, pte, pmd, ptl);
70429 + return 0;
70430 +#endif
70431 +
70432 unlock:
70433 pte_unmap_unlock(pte, ptl);
70434 return 0;
70435 @@ -3478,6 +3688,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70436 pmd_t *pmd;
70437 pte_t *pte;
70438
70439 +#ifdef CONFIG_PAX_SEGMEXEC
70440 + struct vm_area_struct *vma_m;
70441 +#endif
70442 +
70443 __set_current_state(TASK_RUNNING);
70444
70445 count_vm_event(PGFAULT);
70446 @@ -3489,6 +3703,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70447 if (unlikely(is_vm_hugetlb_page(vma)))
70448 return hugetlb_fault(mm, vma, address, flags);
70449
70450 +#ifdef CONFIG_PAX_SEGMEXEC
70451 + vma_m = pax_find_mirror_vma(vma);
70452 + if (vma_m) {
70453 + unsigned long address_m;
70454 + pgd_t *pgd_m;
70455 + pud_t *pud_m;
70456 + pmd_t *pmd_m;
70457 +
70458 + if (vma->vm_start > vma_m->vm_start) {
70459 + address_m = address;
70460 + address -= SEGMEXEC_TASK_SIZE;
70461 + vma = vma_m;
70462 + } else
70463 + address_m = address + SEGMEXEC_TASK_SIZE;
70464 +
70465 + pgd_m = pgd_offset(mm, address_m);
70466 + pud_m = pud_alloc(mm, pgd_m, address_m);
70467 + if (!pud_m)
70468 + return VM_FAULT_OOM;
70469 + pmd_m = pmd_alloc(mm, pud_m, address_m);
70470 + if (!pmd_m)
70471 + return VM_FAULT_OOM;
70472 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
70473 + return VM_FAULT_OOM;
70474 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
70475 + }
70476 +#endif
70477 +
70478 pgd = pgd_offset(mm, address);
70479 pud = pud_alloc(mm, pgd, address);
70480 if (!pud)
70481 @@ -3518,7 +3760,7 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70482 * run pte_offset_map on the pmd, if an huge pmd could
70483 * materialize from under us from a different thread.
70484 */
70485 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
70486 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
70487 return VM_FAULT_OOM;
70488 /* if an huge pmd materialized from under us just retry later */
70489 if (unlikely(pmd_trans_huge(*pmd)))
70490 @@ -3555,6 +3797,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
70491 spin_unlock(&mm->page_table_lock);
70492 return 0;
70493 }
70494 +
70495 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
70496 +{
70497 + pud_t *new = pud_alloc_one(mm, address);
70498 + if (!new)
70499 + return -ENOMEM;
70500 +
70501 + smp_wmb(); /* See comment in __pte_alloc */
70502 +
70503 + spin_lock(&mm->page_table_lock);
70504 + if (pgd_present(*pgd)) /* Another has populated it */
70505 + pud_free(mm, new);
70506 + else
70507 + pgd_populate_kernel(mm, pgd, new);
70508 + spin_unlock(&mm->page_table_lock);
70509 + return 0;
70510 +}
70511 #endif /* __PAGETABLE_PUD_FOLDED */
70512
70513 #ifndef __PAGETABLE_PMD_FOLDED
70514 @@ -3585,6 +3844,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
70515 spin_unlock(&mm->page_table_lock);
70516 return 0;
70517 }
70518 +
70519 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
70520 +{
70521 + pmd_t *new = pmd_alloc_one(mm, address);
70522 + if (!new)
70523 + return -ENOMEM;
70524 +
70525 + smp_wmb(); /* See comment in __pte_alloc */
70526 +
70527 + spin_lock(&mm->page_table_lock);
70528 +#ifndef __ARCH_HAS_4LEVEL_HACK
70529 + if (pud_present(*pud)) /* Another has populated it */
70530 + pmd_free(mm, new);
70531 + else
70532 + pud_populate_kernel(mm, pud, new);
70533 +#else
70534 + if (pgd_present(*pud)) /* Another has populated it */
70535 + pmd_free(mm, new);
70536 + else
70537 + pgd_populate_kernel(mm, pud, new);
70538 +#endif /* __ARCH_HAS_4LEVEL_HACK */
70539 + spin_unlock(&mm->page_table_lock);
70540 + return 0;
70541 +}
70542 #endif /* __PAGETABLE_PMD_FOLDED */
70543
70544 int make_pages_present(unsigned long addr, unsigned long end)
70545 @@ -3622,7 +3905,7 @@ static int __init gate_vma_init(void)
70546 gate_vma.vm_start = FIXADDR_USER_START;
70547 gate_vma.vm_end = FIXADDR_USER_END;
70548 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
70549 - gate_vma.vm_page_prot = __P101;
70550 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
70551
70552 return 0;
70553 }
70554 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
70555 index bf5b485..e44c2cb 100644
70556 --- a/mm/mempolicy.c
70557 +++ b/mm/mempolicy.c
70558 @@ -619,6 +619,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
70559 unsigned long vmstart;
70560 unsigned long vmend;
70561
70562 +#ifdef CONFIG_PAX_SEGMEXEC
70563 + struct vm_area_struct *vma_m;
70564 +#endif
70565 +
70566 vma = find_vma(mm, start);
70567 if (!vma || vma->vm_start > start)
70568 return -EFAULT;
70569 @@ -672,6 +676,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
70570 if (err)
70571 goto out;
70572 }
70573 +
70574 +#ifdef CONFIG_PAX_SEGMEXEC
70575 + vma_m = pax_find_mirror_vma(vma);
70576 + if (vma_m && vma_m->vm_ops && vma_m->vm_ops->set_policy) {
70577 + err = vma_m->vm_ops->set_policy(vma_m, new_pol);
70578 + if (err)
70579 + goto out;
70580 + }
70581 +#endif
70582 +
70583 }
70584
70585 out:
70586 @@ -1105,6 +1119,17 @@ static long do_mbind(unsigned long start, unsigned long len,
70587
70588 if (end < start)
70589 return -EINVAL;
70590 +
70591 +#ifdef CONFIG_PAX_SEGMEXEC
70592 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
70593 + if (end > SEGMEXEC_TASK_SIZE)
70594 + return -EINVAL;
70595 + } else
70596 +#endif
70597 +
70598 + if (end > TASK_SIZE)
70599 + return -EINVAL;
70600 +
70601 if (end == start)
70602 return 0;
70603
70604 @@ -1328,8 +1353,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
70605 */
70606 tcred = __task_cred(task);
70607 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
70608 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
70609 - !capable(CAP_SYS_NICE)) {
70610 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
70611 rcu_read_unlock();
70612 err = -EPERM;
70613 goto out_put;
70614 @@ -1360,6 +1384,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
70615 goto out;
70616 }
70617
70618 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
70619 + if (mm != current->mm &&
70620 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
70621 + mmput(mm);
70622 + err = -EPERM;
70623 + goto out;
70624 + }
70625 +#endif
70626 +
70627 err = do_migrate_pages(mm, old, new,
70628 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
70629
70630 diff --git a/mm/mlock.c b/mm/mlock.c
70631 index ef726e8..13e0901 100644
70632 --- a/mm/mlock.c
70633 +++ b/mm/mlock.c
70634 @@ -13,6 +13,7 @@
70635 #include <linux/pagemap.h>
70636 #include <linux/mempolicy.h>
70637 #include <linux/syscalls.h>
70638 +#include <linux/security.h>
70639 #include <linux/sched.h>
70640 #include <linux/export.h>
70641 #include <linux/rmap.h>
70642 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
70643 return -EINVAL;
70644 if (end == start)
70645 return 0;
70646 + if (end > TASK_SIZE)
70647 + return -EINVAL;
70648 +
70649 vma = find_vma(current->mm, start);
70650 if (!vma || vma->vm_start > start)
70651 return -ENOMEM;
70652 @@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
70653 for (nstart = start ; ; ) {
70654 vm_flags_t newflags;
70655
70656 +#ifdef CONFIG_PAX_SEGMEXEC
70657 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
70658 + break;
70659 +#endif
70660 +
70661 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
70662
70663 newflags = vma->vm_flags | VM_LOCKED;
70664 @@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
70665 lock_limit >>= PAGE_SHIFT;
70666
70667 /* check against resource limits */
70668 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
70669 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
70670 error = do_mlock(start, len, 1);
70671 up_write(&current->mm->mmap_sem);
70672 @@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
70673 static int do_mlockall(int flags)
70674 {
70675 struct vm_area_struct * vma, * prev = NULL;
70676 - unsigned int def_flags = 0;
70677
70678 if (flags & MCL_FUTURE)
70679 - def_flags = VM_LOCKED;
70680 - current->mm->def_flags = def_flags;
70681 + current->mm->def_flags |= VM_LOCKED;
70682 + else
70683 + current->mm->def_flags &= ~VM_LOCKED;
70684 if (flags == MCL_FUTURE)
70685 goto out;
70686
70687 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
70688 vm_flags_t newflags;
70689
70690 +#ifdef CONFIG_PAX_SEGMEXEC
70691 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
70692 + break;
70693 +#endif
70694 +
70695 + BUG_ON(vma->vm_end > TASK_SIZE);
70696 newflags = vma->vm_flags | VM_LOCKED;
70697 if (!(flags & MCL_CURRENT))
70698 newflags &= ~VM_LOCKED;
70699 @@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
70700 lock_limit >>= PAGE_SHIFT;
70701
70702 ret = -ENOMEM;
70703 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
70704 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
70705 capable(CAP_IPC_LOCK))
70706 ret = do_mlockall(flags);
70707 diff --git a/mm/mmap.c b/mm/mmap.c
70708 index 848ef52..d2b586c 100644
70709 --- a/mm/mmap.c
70710 +++ b/mm/mmap.c
70711 @@ -46,6 +46,16 @@
70712 #define arch_rebalance_pgtables(addr, len) (addr)
70713 #endif
70714
70715 +static inline void verify_mm_writelocked(struct mm_struct *mm)
70716 +{
70717 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
70718 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
70719 + up_read(&mm->mmap_sem);
70720 + BUG();
70721 + }
70722 +#endif
70723 +}
70724 +
70725 static void unmap_region(struct mm_struct *mm,
70726 struct vm_area_struct *vma, struct vm_area_struct *prev,
70727 unsigned long start, unsigned long end);
70728 @@ -71,22 +81,32 @@ static void unmap_region(struct mm_struct *mm,
70729 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
70730 *
70731 */
70732 -pgprot_t protection_map[16] = {
70733 +pgprot_t protection_map[16] __read_only = {
70734 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
70735 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
70736 };
70737
70738 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
70739 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
70740 {
70741 - return __pgprot(pgprot_val(protection_map[vm_flags &
70742 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
70743 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
70744 pgprot_val(arch_vm_get_page_prot(vm_flags)));
70745 +
70746 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
70747 + if (!(__supported_pte_mask & _PAGE_NX) &&
70748 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
70749 + (vm_flags & (VM_READ | VM_WRITE)))
70750 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
70751 +#endif
70752 +
70753 + return prot;
70754 }
70755 EXPORT_SYMBOL(vm_get_page_prot);
70756
70757 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
70758 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
70759 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
70760 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
70761 /*
70762 * Make sure vm_committed_as in one cacheline and not cacheline shared with
70763 * other variables. It can be updated by several CPUs frequently.
70764 @@ -228,6 +248,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
70765 struct vm_area_struct *next = vma->vm_next;
70766
70767 might_sleep();
70768 + BUG_ON(vma->vm_mirror);
70769 if (vma->vm_ops && vma->vm_ops->close)
70770 vma->vm_ops->close(vma);
70771 if (vma->vm_file) {
70772 @@ -274,6 +295,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
70773 * not page aligned -Ram Gupta
70774 */
70775 rlim = rlimit(RLIMIT_DATA);
70776 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
70777 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
70778 (mm->end_data - mm->start_data) > rlim)
70779 goto out;
70780 @@ -690,6 +712,12 @@ static int
70781 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
70782 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
70783 {
70784 +
70785 +#ifdef CONFIG_PAX_SEGMEXEC
70786 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
70787 + return 0;
70788 +#endif
70789 +
70790 if (is_mergeable_vma(vma, file, vm_flags) &&
70791 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
70792 if (vma->vm_pgoff == vm_pgoff)
70793 @@ -709,6 +737,12 @@ static int
70794 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
70795 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
70796 {
70797 +
70798 +#ifdef CONFIG_PAX_SEGMEXEC
70799 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
70800 + return 0;
70801 +#endif
70802 +
70803 if (is_mergeable_vma(vma, file, vm_flags) &&
70804 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
70805 pgoff_t vm_pglen;
70806 @@ -751,13 +785,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
70807 struct vm_area_struct *vma_merge(struct mm_struct *mm,
70808 struct vm_area_struct *prev, unsigned long addr,
70809 unsigned long end, unsigned long vm_flags,
70810 - struct anon_vma *anon_vma, struct file *file,
70811 + struct anon_vma *anon_vma, struct file *file,
70812 pgoff_t pgoff, struct mempolicy *policy)
70813 {
70814 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
70815 struct vm_area_struct *area, *next;
70816 int err;
70817
70818 +#ifdef CONFIG_PAX_SEGMEXEC
70819 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
70820 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
70821 +
70822 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
70823 +#endif
70824 +
70825 /*
70826 * We later require that vma->vm_flags == vm_flags,
70827 * so this tests vma->vm_flags & VM_SPECIAL, too.
70828 @@ -773,6 +814,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
70829 if (next && next->vm_end == end) /* cases 6, 7, 8 */
70830 next = next->vm_next;
70831
70832 +#ifdef CONFIG_PAX_SEGMEXEC
70833 + if (prev)
70834 + prev_m = pax_find_mirror_vma(prev);
70835 + if (area)
70836 + area_m = pax_find_mirror_vma(area);
70837 + if (next)
70838 + next_m = pax_find_mirror_vma(next);
70839 +#endif
70840 +
70841 /*
70842 * Can it merge with the predecessor?
70843 */
70844 @@ -792,9 +842,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
70845 /* cases 1, 6 */
70846 err = vma_adjust(prev, prev->vm_start,
70847 next->vm_end, prev->vm_pgoff, NULL);
70848 - } else /* cases 2, 5, 7 */
70849 +
70850 +#ifdef CONFIG_PAX_SEGMEXEC
70851 + if (!err && prev_m)
70852 + err = vma_adjust(prev_m, prev_m->vm_start,
70853 + next_m->vm_end, prev_m->vm_pgoff, NULL);
70854 +#endif
70855 +
70856 + } else { /* cases 2, 5, 7 */
70857 err = vma_adjust(prev, prev->vm_start,
70858 end, prev->vm_pgoff, NULL);
70859 +
70860 +#ifdef CONFIG_PAX_SEGMEXEC
70861 + if (!err && prev_m)
70862 + err = vma_adjust(prev_m, prev_m->vm_start,
70863 + end_m, prev_m->vm_pgoff, NULL);
70864 +#endif
70865 +
70866 + }
70867 if (err)
70868 return NULL;
70869 khugepaged_enter_vma_merge(prev);
70870 @@ -808,12 +873,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
70871 mpol_equal(policy, vma_policy(next)) &&
70872 can_vma_merge_before(next, vm_flags,
70873 anon_vma, file, pgoff+pglen)) {
70874 - if (prev && addr < prev->vm_end) /* case 4 */
70875 + if (prev && addr < prev->vm_end) { /* case 4 */
70876 err = vma_adjust(prev, prev->vm_start,
70877 addr, prev->vm_pgoff, NULL);
70878 - else /* cases 3, 8 */
70879 +
70880 +#ifdef CONFIG_PAX_SEGMEXEC
70881 + if (!err && prev_m)
70882 + err = vma_adjust(prev_m, prev_m->vm_start,
70883 + addr_m, prev_m->vm_pgoff, NULL);
70884 +#endif
70885 +
70886 + } else { /* cases 3, 8 */
70887 err = vma_adjust(area, addr, next->vm_end,
70888 next->vm_pgoff - pglen, NULL);
70889 +
70890 +#ifdef CONFIG_PAX_SEGMEXEC
70891 + if (!err && area_m)
70892 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
70893 + next_m->vm_pgoff - pglen, NULL);
70894 +#endif
70895 +
70896 + }
70897 if (err)
70898 return NULL;
70899 khugepaged_enter_vma_merge(area);
70900 @@ -922,14 +1002,11 @@ none:
70901 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
70902 struct file *file, long pages)
70903 {
70904 - const unsigned long stack_flags
70905 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
70906 -
70907 if (file) {
70908 mm->shared_vm += pages;
70909 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
70910 mm->exec_vm += pages;
70911 - } else if (flags & stack_flags)
70912 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
70913 mm->stack_vm += pages;
70914 if (flags & (VM_RESERVED|VM_IO))
70915 mm->reserved_vm += pages;
70916 @@ -969,7 +1046,7 @@ static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70917 * (the exception is when the underlying filesystem is noexec
70918 * mounted, in which case we dont add PROT_EXEC.)
70919 */
70920 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
70921 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
70922 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
70923 prot |= PROT_EXEC;
70924
70925 @@ -995,7 +1072,7 @@ static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70926 /* Obtain the address to map to. we verify (or select) it and ensure
70927 * that it represents a valid section of the address space.
70928 */
70929 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
70930 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
70931 if (addr & ~PAGE_MASK)
70932 return addr;
70933
70934 @@ -1006,6 +1083,36 @@ static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70935 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
70936 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
70937
70938 +#ifdef CONFIG_PAX_MPROTECT
70939 + if (mm->pax_flags & MF_PAX_MPROTECT) {
70940 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
70941 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
70942 + gr_log_rwxmmap(file);
70943 +
70944 +#ifdef CONFIG_PAX_EMUPLT
70945 + vm_flags &= ~VM_EXEC;
70946 +#else
70947 + return -EPERM;
70948 +#endif
70949 +
70950 + }
70951 +
70952 + if (!(vm_flags & VM_EXEC))
70953 + vm_flags &= ~VM_MAYEXEC;
70954 +#else
70955 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
70956 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
70957 +#endif
70958 + else
70959 + vm_flags &= ~VM_MAYWRITE;
70960 + }
70961 +#endif
70962 +
70963 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
70964 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
70965 + vm_flags &= ~VM_PAGEEXEC;
70966 +#endif
70967 +
70968 if (flags & MAP_LOCKED)
70969 if (!can_do_mlock())
70970 return -EPERM;
70971 @@ -1017,6 +1124,7 @@ static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70972 locked += mm->locked_vm;
70973 lock_limit = rlimit(RLIMIT_MEMLOCK);
70974 lock_limit >>= PAGE_SHIFT;
70975 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
70976 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
70977 return -EAGAIN;
70978 }
70979 @@ -1087,6 +1195,9 @@ static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70980 if (error)
70981 return error;
70982
70983 + if (!gr_acl_handle_mmap(file, prot))
70984 + return -EACCES;
70985 +
70986 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
70987 }
70988
70989 @@ -1192,7 +1303,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
70990 vm_flags_t vm_flags = vma->vm_flags;
70991
70992 /* If it was private or non-writable, the write bit is already clear */
70993 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
70994 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
70995 return 0;
70996
70997 /* The backer wishes to know when pages are first written to? */
70998 @@ -1241,14 +1352,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
70999 unsigned long charged = 0;
71000 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
71001
71002 +#ifdef CONFIG_PAX_SEGMEXEC
71003 + struct vm_area_struct *vma_m = NULL;
71004 +#endif
71005 +
71006 + /*
71007 + * mm->mmap_sem is required to protect against another thread
71008 + * changing the mappings in case we sleep.
71009 + */
71010 + verify_mm_writelocked(mm);
71011 +
71012 /* Clear old maps */
71013 error = -ENOMEM;
71014 -munmap_back:
71015 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71016 if (vma && vma->vm_start < addr + len) {
71017 if (do_munmap(mm, addr, len))
71018 return -ENOMEM;
71019 - goto munmap_back;
71020 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71021 + BUG_ON(vma && vma->vm_start < addr + len);
71022 }
71023
71024 /* Check against address space limit. */
71025 @@ -1297,6 +1418,16 @@ munmap_back:
71026 goto unacct_error;
71027 }
71028
71029 +#ifdef CONFIG_PAX_SEGMEXEC
71030 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
71031 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71032 + if (!vma_m) {
71033 + error = -ENOMEM;
71034 + goto free_vma;
71035 + }
71036 + }
71037 +#endif
71038 +
71039 vma->vm_mm = mm;
71040 vma->vm_start = addr;
71041 vma->vm_end = addr + len;
71042 @@ -1321,6 +1452,19 @@ munmap_back:
71043 error = file->f_op->mmap(file, vma);
71044 if (error)
71045 goto unmap_and_free_vma;
71046 +
71047 +#ifdef CONFIG_PAX_SEGMEXEC
71048 + if (vma_m && (vm_flags & VM_EXECUTABLE))
71049 + added_exe_file_vma(mm);
71050 +#endif
71051 +
71052 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71053 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
71054 + vma->vm_flags |= VM_PAGEEXEC;
71055 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
71056 + }
71057 +#endif
71058 +
71059 if (vm_flags & VM_EXECUTABLE)
71060 added_exe_file_vma(mm);
71061
71062 @@ -1358,6 +1502,11 @@ munmap_back:
71063 vma_link(mm, vma, prev, rb_link, rb_parent);
71064 file = vma->vm_file;
71065
71066 +#ifdef CONFIG_PAX_SEGMEXEC
71067 + if (vma_m)
71068 + BUG_ON(pax_mirror_vma(vma_m, vma));
71069 +#endif
71070 +
71071 /* Once vma denies write, undo our temporary denial count */
71072 if (correct_wcount)
71073 atomic_inc(&inode->i_writecount);
71074 @@ -1366,6 +1515,7 @@ out:
71075
71076 mm->total_vm += len >> PAGE_SHIFT;
71077 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
71078 + track_exec_limit(mm, addr, addr + len, vm_flags);
71079 if (vm_flags & VM_LOCKED) {
71080 if (!mlock_vma_pages_range(vma, addr, addr + len))
71081 mm->locked_vm += (len >> PAGE_SHIFT);
71082 @@ -1383,6 +1533,12 @@ unmap_and_free_vma:
71083 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
71084 charged = 0;
71085 free_vma:
71086 +
71087 +#ifdef CONFIG_PAX_SEGMEXEC
71088 + if (vma_m)
71089 + kmem_cache_free(vm_area_cachep, vma_m);
71090 +#endif
71091 +
71092 kmem_cache_free(vm_area_cachep, vma);
71093 unacct_error:
71094 if (charged)
71095 @@ -1390,6 +1546,44 @@ unacct_error:
71096 return error;
71097 }
71098
71099 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
71100 +{
71101 + if (!vma) {
71102 +#ifdef CONFIG_STACK_GROWSUP
71103 + if (addr > sysctl_heap_stack_gap)
71104 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
71105 + else
71106 + vma = find_vma(current->mm, 0);
71107 + if (vma && (vma->vm_flags & VM_GROWSUP))
71108 + return false;
71109 +#endif
71110 + return true;
71111 + }
71112 +
71113 + if (addr + len > vma->vm_start)
71114 + return false;
71115 +
71116 + if (vma->vm_flags & VM_GROWSDOWN)
71117 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
71118 +#ifdef CONFIG_STACK_GROWSUP
71119 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
71120 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
71121 +#endif
71122 +
71123 + return true;
71124 +}
71125 +
71126 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
71127 +{
71128 + if (vma->vm_start < len)
71129 + return -ENOMEM;
71130 + if (!(vma->vm_flags & VM_GROWSDOWN))
71131 + return vma->vm_start - len;
71132 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
71133 + return vma->vm_start - len - sysctl_heap_stack_gap;
71134 + return -ENOMEM;
71135 +}
71136 +
71137 /* Get an address range which is currently unmapped.
71138 * For shmat() with addr=0.
71139 *
71140 @@ -1416,18 +1610,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
71141 if (flags & MAP_FIXED)
71142 return addr;
71143
71144 +#ifdef CONFIG_PAX_RANDMMAP
71145 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
71146 +#endif
71147 +
71148 if (addr) {
71149 addr = PAGE_ALIGN(addr);
71150 - vma = find_vma(mm, addr);
71151 - if (TASK_SIZE - len >= addr &&
71152 - (!vma || addr + len <= vma->vm_start))
71153 - return addr;
71154 + if (TASK_SIZE - len >= addr) {
71155 + vma = find_vma(mm, addr);
71156 + if (check_heap_stack_gap(vma, addr, len))
71157 + return addr;
71158 + }
71159 }
71160 if (len > mm->cached_hole_size) {
71161 - start_addr = addr = mm->free_area_cache;
71162 + start_addr = addr = mm->free_area_cache;
71163 } else {
71164 - start_addr = addr = TASK_UNMAPPED_BASE;
71165 - mm->cached_hole_size = 0;
71166 + start_addr = addr = mm->mmap_base;
71167 + mm->cached_hole_size = 0;
71168 }
71169
71170 full_search:
71171 @@ -1438,34 +1637,40 @@ full_search:
71172 * Start a new search - just in case we missed
71173 * some holes.
71174 */
71175 - if (start_addr != TASK_UNMAPPED_BASE) {
71176 - addr = TASK_UNMAPPED_BASE;
71177 - start_addr = addr;
71178 + if (start_addr != mm->mmap_base) {
71179 + start_addr = addr = mm->mmap_base;
71180 mm->cached_hole_size = 0;
71181 goto full_search;
71182 }
71183 return -ENOMEM;
71184 }
71185 - if (!vma || addr + len <= vma->vm_start) {
71186 - /*
71187 - * Remember the place where we stopped the search:
71188 - */
71189 - mm->free_area_cache = addr + len;
71190 - return addr;
71191 - }
71192 + if (check_heap_stack_gap(vma, addr, len))
71193 + break;
71194 if (addr + mm->cached_hole_size < vma->vm_start)
71195 mm->cached_hole_size = vma->vm_start - addr;
71196 addr = vma->vm_end;
71197 }
71198 +
71199 + /*
71200 + * Remember the place where we stopped the search:
71201 + */
71202 + mm->free_area_cache = addr + len;
71203 + return addr;
71204 }
71205 #endif
71206
71207 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
71208 {
71209 +
71210 +#ifdef CONFIG_PAX_SEGMEXEC
71211 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
71212 + return;
71213 +#endif
71214 +
71215 /*
71216 * Is this a new hole at the lowest possible address?
71217 */
71218 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
71219 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
71220 mm->free_area_cache = addr;
71221 }
71222
71223 @@ -1481,7 +1686,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71224 {
71225 struct vm_area_struct *vma;
71226 struct mm_struct *mm = current->mm;
71227 - unsigned long addr = addr0, start_addr;
71228 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
71229
71230 /* requested length too big for entire address space */
71231 if (len > TASK_SIZE)
71232 @@ -1490,13 +1695,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71233 if (flags & MAP_FIXED)
71234 return addr;
71235
71236 +#ifdef CONFIG_PAX_RANDMMAP
71237 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
71238 +#endif
71239 +
71240 /* requesting a specific address */
71241 if (addr) {
71242 addr = PAGE_ALIGN(addr);
71243 - vma = find_vma(mm, addr);
71244 - if (TASK_SIZE - len >= addr &&
71245 - (!vma || addr + len <= vma->vm_start))
71246 - return addr;
71247 + if (TASK_SIZE - len >= addr) {
71248 + vma = find_vma(mm, addr);
71249 + if (check_heap_stack_gap(vma, addr, len))
71250 + return addr;
71251 + }
71252 }
71253
71254 /* check if free_area_cache is useful for us */
71255 @@ -1520,7 +1730,7 @@ try_again:
71256 * return with success:
71257 */
71258 vma = find_vma(mm, addr);
71259 - if (!vma || addr+len <= vma->vm_start)
71260 + if (check_heap_stack_gap(vma, addr, len))
71261 /* remember the address as a hint for next time */
71262 return (mm->free_area_cache = addr);
71263
71264 @@ -1529,8 +1739,8 @@ try_again:
71265 mm->cached_hole_size = vma->vm_start - addr;
71266
71267 /* try just below the current vma->vm_start */
71268 - addr = vma->vm_start-len;
71269 - } while (len < vma->vm_start);
71270 + addr = skip_heap_stack_gap(vma, len);
71271 + } while (!IS_ERR_VALUE(addr));
71272
71273 fail:
71274 /*
71275 @@ -1553,13 +1763,21 @@ fail:
71276 * can happen with large stack limits and large mmap()
71277 * allocations.
71278 */
71279 + mm->mmap_base = TASK_UNMAPPED_BASE;
71280 +
71281 +#ifdef CONFIG_PAX_RANDMMAP
71282 + if (mm->pax_flags & MF_PAX_RANDMMAP)
71283 + mm->mmap_base += mm->delta_mmap;
71284 +#endif
71285 +
71286 + mm->free_area_cache = mm->mmap_base;
71287 mm->cached_hole_size = ~0UL;
71288 - mm->free_area_cache = TASK_UNMAPPED_BASE;
71289 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
71290 /*
71291 * Restore the topdown base:
71292 */
71293 - mm->free_area_cache = mm->mmap_base;
71294 + mm->mmap_base = base;
71295 + mm->free_area_cache = base;
71296 mm->cached_hole_size = ~0UL;
71297
71298 return addr;
71299 @@ -1568,6 +1786,12 @@ fail:
71300
71301 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
71302 {
71303 +
71304 +#ifdef CONFIG_PAX_SEGMEXEC
71305 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
71306 + return;
71307 +#endif
71308 +
71309 /*
71310 * Is this a new hole at the highest possible address?
71311 */
71312 @@ -1575,8 +1799,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
71313 mm->free_area_cache = addr;
71314
71315 /* dont allow allocations above current base */
71316 - if (mm->free_area_cache > mm->mmap_base)
71317 + if (mm->free_area_cache > mm->mmap_base) {
71318 mm->free_area_cache = mm->mmap_base;
71319 + mm->cached_hole_size = ~0UL;
71320 + }
71321 }
71322
71323 unsigned long
71324 @@ -1672,6 +1898,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
71325 return vma;
71326 }
71327
71328 +#ifdef CONFIG_PAX_SEGMEXEC
71329 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
71330 +{
71331 + struct vm_area_struct *vma_m;
71332 +
71333 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
71334 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
71335 + BUG_ON(vma->vm_mirror);
71336 + return NULL;
71337 + }
71338 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
71339 + vma_m = vma->vm_mirror;
71340 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
71341 + BUG_ON(vma->vm_file != vma_m->vm_file);
71342 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
71343 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
71344 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
71345 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
71346 + return vma_m;
71347 +}
71348 +#endif
71349 +
71350 /*
71351 * Verify that the stack growth is acceptable and
71352 * update accounting. This is shared with both the
71353 @@ -1688,6 +1936,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
71354 return -ENOMEM;
71355
71356 /* Stack limit test */
71357 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
71358 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
71359 return -ENOMEM;
71360
71361 @@ -1698,6 +1947,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
71362 locked = mm->locked_vm + grow;
71363 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
71364 limit >>= PAGE_SHIFT;
71365 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
71366 if (locked > limit && !capable(CAP_IPC_LOCK))
71367 return -ENOMEM;
71368 }
71369 @@ -1728,37 +1978,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
71370 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
71371 * vma is the last one with address > vma->vm_end. Have to extend vma.
71372 */
71373 +#ifndef CONFIG_IA64
71374 +static
71375 +#endif
71376 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
71377 {
71378 int error;
71379 + bool locknext;
71380
71381 if (!(vma->vm_flags & VM_GROWSUP))
71382 return -EFAULT;
71383
71384 + /* Also guard against wrapping around to address 0. */
71385 + if (address < PAGE_ALIGN(address+1))
71386 + address = PAGE_ALIGN(address+1);
71387 + else
71388 + return -ENOMEM;
71389 +
71390 /*
71391 * We must make sure the anon_vma is allocated
71392 * so that the anon_vma locking is not a noop.
71393 */
71394 if (unlikely(anon_vma_prepare(vma)))
71395 return -ENOMEM;
71396 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
71397 + if (locknext && anon_vma_prepare(vma->vm_next))
71398 + return -ENOMEM;
71399 vma_lock_anon_vma(vma);
71400 + if (locknext)
71401 + vma_lock_anon_vma(vma->vm_next);
71402
71403 /*
71404 * vma->vm_start/vm_end cannot change under us because the caller
71405 * is required to hold the mmap_sem in read mode. We need the
71406 - * anon_vma lock to serialize against concurrent expand_stacks.
71407 - * Also guard against wrapping around to address 0.
71408 + * anon_vma locks to serialize against concurrent expand_stacks
71409 + * and expand_upwards.
71410 */
71411 - if (address < PAGE_ALIGN(address+4))
71412 - address = PAGE_ALIGN(address+4);
71413 - else {
71414 - vma_unlock_anon_vma(vma);
71415 - return -ENOMEM;
71416 - }
71417 error = 0;
71418
71419 /* Somebody else might have raced and expanded it already */
71420 - if (address > vma->vm_end) {
71421 + 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)
71422 + error = -ENOMEM;
71423 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
71424 unsigned long size, grow;
71425
71426 size = address - vma->vm_start;
71427 @@ -1773,6 +2034,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
71428 }
71429 }
71430 }
71431 + if (locknext)
71432 + vma_unlock_anon_vma(vma->vm_next);
71433 vma_unlock_anon_vma(vma);
71434 khugepaged_enter_vma_merge(vma);
71435 return error;
71436 @@ -1786,6 +2049,8 @@ int expand_downwards(struct vm_area_struct *vma,
71437 unsigned long address)
71438 {
71439 int error;
71440 + bool lockprev = false;
71441 + struct vm_area_struct *prev;
71442
71443 /*
71444 * We must make sure the anon_vma is allocated
71445 @@ -1799,6 +2064,15 @@ int expand_downwards(struct vm_area_struct *vma,
71446 if (error)
71447 return error;
71448
71449 + prev = vma->vm_prev;
71450 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
71451 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
71452 +#endif
71453 + if (lockprev && anon_vma_prepare(prev))
71454 + return -ENOMEM;
71455 + if (lockprev)
71456 + vma_lock_anon_vma(prev);
71457 +
71458 vma_lock_anon_vma(vma);
71459
71460 /*
71461 @@ -1808,9 +2082,17 @@ int expand_downwards(struct vm_area_struct *vma,
71462 */
71463
71464 /* Somebody else might have raced and expanded it already */
71465 - if (address < vma->vm_start) {
71466 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
71467 + error = -ENOMEM;
71468 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
71469 unsigned long size, grow;
71470
71471 +#ifdef CONFIG_PAX_SEGMEXEC
71472 + struct vm_area_struct *vma_m;
71473 +
71474 + vma_m = pax_find_mirror_vma(vma);
71475 +#endif
71476 +
71477 size = vma->vm_end - address;
71478 grow = (vma->vm_start - address) >> PAGE_SHIFT;
71479
71480 @@ -1820,11 +2102,22 @@ int expand_downwards(struct vm_area_struct *vma,
71481 if (!error) {
71482 vma->vm_start = address;
71483 vma->vm_pgoff -= grow;
71484 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
71485 +
71486 +#ifdef CONFIG_PAX_SEGMEXEC
71487 + if (vma_m) {
71488 + vma_m->vm_start -= grow << PAGE_SHIFT;
71489 + vma_m->vm_pgoff -= grow;
71490 + }
71491 +#endif
71492 +
71493 perf_event_mmap(vma);
71494 }
71495 }
71496 }
71497 vma_unlock_anon_vma(vma);
71498 + if (lockprev)
71499 + vma_unlock_anon_vma(prev);
71500 khugepaged_enter_vma_merge(vma);
71501 return error;
71502 }
71503 @@ -1894,6 +2187,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
71504 do {
71505 long nrpages = vma_pages(vma);
71506
71507 +#ifdef CONFIG_PAX_SEGMEXEC
71508 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
71509 + vma = remove_vma(vma);
71510 + continue;
71511 + }
71512 +#endif
71513 +
71514 mm->total_vm -= nrpages;
71515 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
71516 vma = remove_vma(vma);
71517 @@ -1939,6 +2239,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
71518 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
71519 vma->vm_prev = NULL;
71520 do {
71521 +
71522 +#ifdef CONFIG_PAX_SEGMEXEC
71523 + if (vma->vm_mirror) {
71524 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
71525 + vma->vm_mirror->vm_mirror = NULL;
71526 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
71527 + vma->vm_mirror = NULL;
71528 + }
71529 +#endif
71530 +
71531 rb_erase(&vma->vm_rb, &mm->mm_rb);
71532 mm->map_count--;
71533 tail_vma = vma;
71534 @@ -1967,14 +2277,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71535 struct vm_area_struct *new;
71536 int err = -ENOMEM;
71537
71538 +#ifdef CONFIG_PAX_SEGMEXEC
71539 + struct vm_area_struct *vma_m, *new_m = NULL;
71540 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
71541 +#endif
71542 +
71543 if (is_vm_hugetlb_page(vma) && (addr &
71544 ~(huge_page_mask(hstate_vma(vma)))))
71545 return -EINVAL;
71546
71547 +#ifdef CONFIG_PAX_SEGMEXEC
71548 + vma_m = pax_find_mirror_vma(vma);
71549 +#endif
71550 +
71551 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
71552 if (!new)
71553 goto out_err;
71554
71555 +#ifdef CONFIG_PAX_SEGMEXEC
71556 + if (vma_m) {
71557 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
71558 + if (!new_m) {
71559 + kmem_cache_free(vm_area_cachep, new);
71560 + goto out_err;
71561 + }
71562 + }
71563 +#endif
71564 +
71565 /* most fields are the same, copy all, and then fixup */
71566 *new = *vma;
71567
71568 @@ -1987,6 +2316,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71569 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
71570 }
71571
71572 +#ifdef CONFIG_PAX_SEGMEXEC
71573 + if (vma_m) {
71574 + *new_m = *vma_m;
71575 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
71576 + new_m->vm_mirror = new;
71577 + new->vm_mirror = new_m;
71578 +
71579 + if (new_below)
71580 + new_m->vm_end = addr_m;
71581 + else {
71582 + new_m->vm_start = addr_m;
71583 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
71584 + }
71585 + }
71586 +#endif
71587 +
71588 pol = mpol_dup(vma_policy(vma));
71589 if (IS_ERR(pol)) {
71590 err = PTR_ERR(pol);
71591 @@ -2012,6 +2357,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71592 else
71593 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
71594
71595 +#ifdef CONFIG_PAX_SEGMEXEC
71596 + if (!err && vma_m) {
71597 + if (anon_vma_clone(new_m, vma_m))
71598 + goto out_free_mpol;
71599 +
71600 + mpol_get(pol);
71601 + vma_set_policy(new_m, pol);
71602 +
71603 + if (new_m->vm_file) {
71604 + get_file(new_m->vm_file);
71605 + if (vma_m->vm_flags & VM_EXECUTABLE)
71606 + added_exe_file_vma(mm);
71607 + }
71608 +
71609 + if (new_m->vm_ops && new_m->vm_ops->open)
71610 + new_m->vm_ops->open(new_m);
71611 +
71612 + if (new_below)
71613 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
71614 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
71615 + else
71616 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
71617 +
71618 + if (err) {
71619 + if (new_m->vm_ops && new_m->vm_ops->close)
71620 + new_m->vm_ops->close(new_m);
71621 + if (new_m->vm_file) {
71622 + if (vma_m->vm_flags & VM_EXECUTABLE)
71623 + removed_exe_file_vma(mm);
71624 + fput(new_m->vm_file);
71625 + }
71626 + mpol_put(pol);
71627 + }
71628 + }
71629 +#endif
71630 +
71631 /* Success. */
71632 if (!err)
71633 return 0;
71634 @@ -2024,10 +2405,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71635 removed_exe_file_vma(mm);
71636 fput(new->vm_file);
71637 }
71638 - unlink_anon_vmas(new);
71639 out_free_mpol:
71640 mpol_put(pol);
71641 out_free_vma:
71642 +
71643 +#ifdef CONFIG_PAX_SEGMEXEC
71644 + if (new_m) {
71645 + unlink_anon_vmas(new_m);
71646 + kmem_cache_free(vm_area_cachep, new_m);
71647 + }
71648 +#endif
71649 +
71650 + unlink_anon_vmas(new);
71651 kmem_cache_free(vm_area_cachep, new);
71652 out_err:
71653 return err;
71654 @@ -2040,6 +2429,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71655 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
71656 unsigned long addr, int new_below)
71657 {
71658 +
71659 +#ifdef CONFIG_PAX_SEGMEXEC
71660 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
71661 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
71662 + if (mm->map_count >= sysctl_max_map_count-1)
71663 + return -ENOMEM;
71664 + } else
71665 +#endif
71666 +
71667 if (mm->map_count >= sysctl_max_map_count)
71668 return -ENOMEM;
71669
71670 @@ -2051,11 +2449,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
71671 * work. This now handles partial unmappings.
71672 * Jeremy Fitzhardinge <jeremy@goop.org>
71673 */
71674 +#ifdef CONFIG_PAX_SEGMEXEC
71675 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71676 {
71677 + int ret = __do_munmap(mm, start, len);
71678 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
71679 + return ret;
71680 +
71681 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
71682 +}
71683 +
71684 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71685 +#else
71686 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71687 +#endif
71688 +{
71689 unsigned long end;
71690 struct vm_area_struct *vma, *prev, *last;
71691
71692 + /*
71693 + * mm->mmap_sem is required to protect against another thread
71694 + * changing the mappings in case we sleep.
71695 + */
71696 + verify_mm_writelocked(mm);
71697 +
71698 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
71699 return -EINVAL;
71700
71701 @@ -2130,6 +2547,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71702 /* Fix up all other VM information */
71703 remove_vma_list(mm, vma);
71704
71705 + track_exec_limit(mm, start, end, 0UL);
71706 +
71707 return 0;
71708 }
71709 EXPORT_SYMBOL(do_munmap);
71710 @@ -2139,6 +2558,13 @@ int vm_munmap(unsigned long start, size_t len)
71711 int ret;
71712 struct mm_struct *mm = current->mm;
71713
71714 +
71715 +#ifdef CONFIG_PAX_SEGMEXEC
71716 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
71717 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
71718 + return -EINVAL;
71719 +#endif
71720 +
71721 down_write(&mm->mmap_sem);
71722 ret = do_munmap(mm, start, len);
71723 up_write(&mm->mmap_sem);
71724 @@ -2152,16 +2578,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
71725 return vm_munmap(addr, len);
71726 }
71727
71728 -static inline void verify_mm_writelocked(struct mm_struct *mm)
71729 -{
71730 -#ifdef CONFIG_DEBUG_VM
71731 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
71732 - WARN_ON(1);
71733 - up_read(&mm->mmap_sem);
71734 - }
71735 -#endif
71736 -}
71737 -
71738 /*
71739 * this is really a simplified "do_mmap". it only handles
71740 * anonymous maps. eventually we may be able to do some
71741 @@ -2175,6 +2591,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
71742 struct rb_node ** rb_link, * rb_parent;
71743 pgoff_t pgoff = addr >> PAGE_SHIFT;
71744 int error;
71745 + unsigned long charged;
71746
71747 len = PAGE_ALIGN(len);
71748 if (!len)
71749 @@ -2186,16 +2603,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
71750
71751 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
71752
71753 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
71754 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
71755 + flags &= ~VM_EXEC;
71756 +
71757 +#ifdef CONFIG_PAX_MPROTECT
71758 + if (mm->pax_flags & MF_PAX_MPROTECT)
71759 + flags &= ~VM_MAYEXEC;
71760 +#endif
71761 +
71762 + }
71763 +#endif
71764 +
71765 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
71766 if (error & ~PAGE_MASK)
71767 return error;
71768
71769 + charged = len >> PAGE_SHIFT;
71770 +
71771 /*
71772 * mlock MCL_FUTURE?
71773 */
71774 if (mm->def_flags & VM_LOCKED) {
71775 unsigned long locked, lock_limit;
71776 - locked = len >> PAGE_SHIFT;
71777 + locked = charged;
71778 locked += mm->locked_vm;
71779 lock_limit = rlimit(RLIMIT_MEMLOCK);
71780 lock_limit >>= PAGE_SHIFT;
71781 @@ -2212,22 +2643,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
71782 /*
71783 * Clear old maps. this also does some error checking for us
71784 */
71785 - munmap_back:
71786 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71787 if (vma && vma->vm_start < addr + len) {
71788 if (do_munmap(mm, addr, len))
71789 return -ENOMEM;
71790 - goto munmap_back;
71791 - }
71792 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71793 + BUG_ON(vma && vma->vm_start < addr + len);
71794 + }
71795
71796 /* Check against address space limits *after* clearing old maps... */
71797 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
71798 + if (!may_expand_vm(mm, charged))
71799 return -ENOMEM;
71800
71801 if (mm->map_count > sysctl_max_map_count)
71802 return -ENOMEM;
71803
71804 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
71805 + if (security_vm_enough_memory_mm(mm, charged))
71806 return -ENOMEM;
71807
71808 /* Can we just expand an old private anonymous mapping? */
71809 @@ -2241,7 +2672,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
71810 */
71811 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71812 if (!vma) {
71813 - vm_unacct_memory(len >> PAGE_SHIFT);
71814 + vm_unacct_memory(charged);
71815 return -ENOMEM;
71816 }
71817
71818 @@ -2255,11 +2686,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
71819 vma_link(mm, vma, prev, rb_link, rb_parent);
71820 out:
71821 perf_event_mmap(vma);
71822 - mm->total_vm += len >> PAGE_SHIFT;
71823 + mm->total_vm += charged;
71824 if (flags & VM_LOCKED) {
71825 if (!mlock_vma_pages_range(vma, addr, addr + len))
71826 - mm->locked_vm += (len >> PAGE_SHIFT);
71827 + mm->locked_vm += charged;
71828 }
71829 + track_exec_limit(mm, addr, addr + len, flags);
71830 return addr;
71831 }
71832
71833 @@ -2315,8 +2747,10 @@ void exit_mmap(struct mm_struct *mm)
71834 * Walk the list again, actually closing and freeing it,
71835 * with preemption enabled, without holding any MM locks.
71836 */
71837 - while (vma)
71838 + while (vma) {
71839 + vma->vm_mirror = NULL;
71840 vma = remove_vma(vma);
71841 + }
71842
71843 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
71844 }
71845 @@ -2330,6 +2764,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
71846 struct vm_area_struct * __vma, * prev;
71847 struct rb_node ** rb_link, * rb_parent;
71848
71849 +#ifdef CONFIG_PAX_SEGMEXEC
71850 + struct vm_area_struct *vma_m = NULL;
71851 +#endif
71852 +
71853 + if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
71854 + return -EPERM;
71855 +
71856 /*
71857 * The vm_pgoff of a purely anonymous vma should be irrelevant
71858 * until its first write fault, when page's anon_vma and index
71859 @@ -2352,7 +2793,22 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
71860 if ((vma->vm_flags & VM_ACCOUNT) &&
71861 security_vm_enough_memory_mm(mm, vma_pages(vma)))
71862 return -ENOMEM;
71863 +
71864 +#ifdef CONFIG_PAX_SEGMEXEC
71865 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
71866 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71867 + if (!vma_m)
71868 + return -ENOMEM;
71869 + }
71870 +#endif
71871 +
71872 vma_link(mm, vma, prev, rb_link, rb_parent);
71873 +
71874 +#ifdef CONFIG_PAX_SEGMEXEC
71875 + if (vma_m)
71876 + BUG_ON(pax_mirror_vma(vma_m, vma));
71877 +#endif
71878 +
71879 return 0;
71880 }
71881
71882 @@ -2371,6 +2827,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
71883 struct mempolicy *pol;
71884 bool faulted_in_anon_vma = true;
71885
71886 + BUG_ON(vma->vm_mirror);
71887 +
71888 /*
71889 * If anonymous vma has not yet been faulted, update new pgoff
71890 * to match new location, to increase its chance of merging.
71891 @@ -2438,6 +2896,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
71892 return NULL;
71893 }
71894
71895 +#ifdef CONFIG_PAX_SEGMEXEC
71896 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
71897 +{
71898 + struct vm_area_struct *prev_m;
71899 + struct rb_node **rb_link_m, *rb_parent_m;
71900 + struct mempolicy *pol_m;
71901 +
71902 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
71903 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
71904 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
71905 + *vma_m = *vma;
71906 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
71907 + if (anon_vma_clone(vma_m, vma))
71908 + return -ENOMEM;
71909 + pol_m = vma_policy(vma_m);
71910 + mpol_get(pol_m);
71911 + vma_set_policy(vma_m, pol_m);
71912 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
71913 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
71914 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
71915 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
71916 + if (vma_m->vm_file)
71917 + get_file(vma_m->vm_file);
71918 + if (vma_m->vm_ops && vma_m->vm_ops->open)
71919 + vma_m->vm_ops->open(vma_m);
71920 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
71921 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
71922 + vma_m->vm_mirror = vma;
71923 + vma->vm_mirror = vma_m;
71924 + return 0;
71925 +}
71926 +#endif
71927 +
71928 /*
71929 * Return true if the calling process may expand its vm space by the passed
71930 * number of pages
71931 @@ -2449,6 +2940,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
71932
71933 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
71934
71935 +#ifdef CONFIG_PAX_RANDMMAP
71936 + if (mm->pax_flags & MF_PAX_RANDMMAP)
71937 + cur -= mm->brk_gap;
71938 +#endif
71939 +
71940 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
71941 if (cur + npages > lim)
71942 return 0;
71943 return 1;
71944 @@ -2519,6 +3016,22 @@ int install_special_mapping(struct mm_struct *mm,
71945 vma->vm_start = addr;
71946 vma->vm_end = addr + len;
71947
71948 +#ifdef CONFIG_PAX_MPROTECT
71949 + if (mm->pax_flags & MF_PAX_MPROTECT) {
71950 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
71951 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
71952 + return -EPERM;
71953 + if (!(vm_flags & VM_EXEC))
71954 + vm_flags &= ~VM_MAYEXEC;
71955 +#else
71956 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
71957 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
71958 +#endif
71959 + else
71960 + vm_flags &= ~VM_MAYWRITE;
71961 + }
71962 +#endif
71963 +
71964 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
71965 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
71966
71967 diff --git a/mm/mprotect.c b/mm/mprotect.c
71968 index a409926..8b32e6d 100644
71969 --- a/mm/mprotect.c
71970 +++ b/mm/mprotect.c
71971 @@ -23,10 +23,17 @@
71972 #include <linux/mmu_notifier.h>
71973 #include <linux/migrate.h>
71974 #include <linux/perf_event.h>
71975 +
71976 +#ifdef CONFIG_PAX_MPROTECT
71977 +#include <linux/elf.h>
71978 +#include <linux/binfmts.h>
71979 +#endif
71980 +
71981 #include <asm/uaccess.h>
71982 #include <asm/pgtable.h>
71983 #include <asm/cacheflush.h>
71984 #include <asm/tlbflush.h>
71985 +#include <asm/mmu_context.h>
71986
71987 #ifndef pgprot_modify
71988 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
71989 @@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
71990 flush_tlb_range(vma, start, end);
71991 }
71992
71993 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
71994 +/* called while holding the mmap semaphor for writing except stack expansion */
71995 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
71996 +{
71997 + unsigned long oldlimit, newlimit = 0UL;
71998 +
71999 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
72000 + return;
72001 +
72002 + spin_lock(&mm->page_table_lock);
72003 + oldlimit = mm->context.user_cs_limit;
72004 + if ((prot & VM_EXEC) && oldlimit < end)
72005 + /* USER_CS limit moved up */
72006 + newlimit = end;
72007 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
72008 + /* USER_CS limit moved down */
72009 + newlimit = start;
72010 +
72011 + if (newlimit) {
72012 + mm->context.user_cs_limit = newlimit;
72013 +
72014 +#ifdef CONFIG_SMP
72015 + wmb();
72016 + cpus_clear(mm->context.cpu_user_cs_mask);
72017 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
72018 +#endif
72019 +
72020 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
72021 + }
72022 + spin_unlock(&mm->page_table_lock);
72023 + if (newlimit == end) {
72024 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
72025 +
72026 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
72027 + if (is_vm_hugetlb_page(vma))
72028 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
72029 + else
72030 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
72031 + }
72032 +}
72033 +#endif
72034 +
72035 int
72036 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72037 unsigned long start, unsigned long end, unsigned long newflags)
72038 @@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72039 int error;
72040 int dirty_accountable = 0;
72041
72042 +#ifdef CONFIG_PAX_SEGMEXEC
72043 + struct vm_area_struct *vma_m = NULL;
72044 + unsigned long start_m, end_m;
72045 +
72046 + start_m = start + SEGMEXEC_TASK_SIZE;
72047 + end_m = end + SEGMEXEC_TASK_SIZE;
72048 +#endif
72049 +
72050 if (newflags == oldflags) {
72051 *pprev = vma;
72052 return 0;
72053 }
72054
72055 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
72056 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
72057 +
72058 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
72059 + return -ENOMEM;
72060 +
72061 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
72062 + return -ENOMEM;
72063 + }
72064 +
72065 /*
72066 * If we make a private mapping writable we increase our commit;
72067 * but (without finer accounting) cannot reduce our commit if we
72068 @@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72069 }
72070 }
72071
72072 +#ifdef CONFIG_PAX_SEGMEXEC
72073 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
72074 + if (start != vma->vm_start) {
72075 + error = split_vma(mm, vma, start, 1);
72076 + if (error)
72077 + goto fail;
72078 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
72079 + *pprev = (*pprev)->vm_next;
72080 + }
72081 +
72082 + if (end != vma->vm_end) {
72083 + error = split_vma(mm, vma, end, 0);
72084 + if (error)
72085 + goto fail;
72086 + }
72087 +
72088 + if (pax_find_mirror_vma(vma)) {
72089 + error = __do_munmap(mm, start_m, end_m - start_m);
72090 + if (error)
72091 + goto fail;
72092 + } else {
72093 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72094 + if (!vma_m) {
72095 + error = -ENOMEM;
72096 + goto fail;
72097 + }
72098 + vma->vm_flags = newflags;
72099 + error = pax_mirror_vma(vma_m, vma);
72100 + if (error) {
72101 + vma->vm_flags = oldflags;
72102 + goto fail;
72103 + }
72104 + }
72105 + }
72106 +#endif
72107 +
72108 /*
72109 * First try to merge with previous and/or next vma.
72110 */
72111 @@ -204,9 +307,21 @@ success:
72112 * vm_flags and vm_page_prot are protected by the mmap_sem
72113 * held in write mode.
72114 */
72115 +
72116 +#ifdef CONFIG_PAX_SEGMEXEC
72117 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
72118 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
72119 +#endif
72120 +
72121 vma->vm_flags = newflags;
72122 +
72123 +#ifdef CONFIG_PAX_MPROTECT
72124 + if (mm->binfmt && mm->binfmt->handle_mprotect)
72125 + mm->binfmt->handle_mprotect(vma, newflags);
72126 +#endif
72127 +
72128 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
72129 - vm_get_page_prot(newflags));
72130 + vm_get_page_prot(vma->vm_flags));
72131
72132 if (vma_wants_writenotify(vma)) {
72133 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
72134 @@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72135 end = start + len;
72136 if (end <= start)
72137 return -ENOMEM;
72138 +
72139 +#ifdef CONFIG_PAX_SEGMEXEC
72140 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
72141 + if (end > SEGMEXEC_TASK_SIZE)
72142 + return -EINVAL;
72143 + } else
72144 +#endif
72145 +
72146 + if (end > TASK_SIZE)
72147 + return -EINVAL;
72148 +
72149 if (!arch_validate_prot(prot))
72150 return -EINVAL;
72151
72152 @@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72153 /*
72154 * Does the application expect PROT_READ to imply PROT_EXEC:
72155 */
72156 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72157 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72158 prot |= PROT_EXEC;
72159
72160 vm_flags = calc_vm_prot_bits(prot);
72161 @@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72162 if (start > vma->vm_start)
72163 prev = vma;
72164
72165 +#ifdef CONFIG_PAX_MPROTECT
72166 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
72167 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
72168 +#endif
72169 +
72170 for (nstart = start ; ; ) {
72171 unsigned long newflags;
72172
72173 @@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72174
72175 /* newflags >> 4 shift VM_MAY% in place of VM_% */
72176 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
72177 + if (prot & (PROT_WRITE | PROT_EXEC))
72178 + gr_log_rwxmprotect(vma->vm_file);
72179 +
72180 + error = -EACCES;
72181 + goto out;
72182 + }
72183 +
72184 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
72185 error = -EACCES;
72186 goto out;
72187 }
72188 @@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72189 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
72190 if (error)
72191 goto out;
72192 +
72193 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
72194 +
72195 nstart = tmp;
72196
72197 if (nstart < prev->vm_end)
72198 diff --git a/mm/mremap.c b/mm/mremap.c
72199 index db8d983..76506cb 100644
72200 --- a/mm/mremap.c
72201 +++ b/mm/mremap.c
72202 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
72203 continue;
72204 pte = ptep_get_and_clear(mm, old_addr, old_pte);
72205 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
72206 +
72207 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
72208 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
72209 + pte = pte_exprotect(pte);
72210 +#endif
72211 +
72212 set_pte_at(mm, new_addr, new_pte, pte);
72213 }
72214
72215 @@ -299,6 +305,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
72216 if (is_vm_hugetlb_page(vma))
72217 goto Einval;
72218
72219 +#ifdef CONFIG_PAX_SEGMEXEC
72220 + if (pax_find_mirror_vma(vma))
72221 + goto Einval;
72222 +#endif
72223 +
72224 /* We can't remap across vm area boundaries */
72225 if (old_len > vma->vm_end - addr)
72226 goto Efault;
72227 @@ -355,20 +366,25 @@ static unsigned long mremap_to(unsigned long addr,
72228 unsigned long ret = -EINVAL;
72229 unsigned long charged = 0;
72230 unsigned long map_flags;
72231 + unsigned long pax_task_size = TASK_SIZE;
72232
72233 if (new_addr & ~PAGE_MASK)
72234 goto out;
72235
72236 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
72237 +#ifdef CONFIG_PAX_SEGMEXEC
72238 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
72239 + pax_task_size = SEGMEXEC_TASK_SIZE;
72240 +#endif
72241 +
72242 + pax_task_size -= PAGE_SIZE;
72243 +
72244 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
72245 goto out;
72246
72247 /* Check if the location we're moving into overlaps the
72248 * old location at all, and fail if it does.
72249 */
72250 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
72251 - goto out;
72252 -
72253 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
72254 + if (addr + old_len > new_addr && new_addr + new_len > addr)
72255 goto out;
72256
72257 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
72258 @@ -440,6 +456,7 @@ unsigned long do_mremap(unsigned long addr,
72259 struct vm_area_struct *vma;
72260 unsigned long ret = -EINVAL;
72261 unsigned long charged = 0;
72262 + unsigned long pax_task_size = TASK_SIZE;
72263
72264 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
72265 goto out;
72266 @@ -458,6 +475,17 @@ unsigned long do_mremap(unsigned long addr,
72267 if (!new_len)
72268 goto out;
72269
72270 +#ifdef CONFIG_PAX_SEGMEXEC
72271 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
72272 + pax_task_size = SEGMEXEC_TASK_SIZE;
72273 +#endif
72274 +
72275 + pax_task_size -= PAGE_SIZE;
72276 +
72277 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
72278 + old_len > pax_task_size || addr > pax_task_size-old_len)
72279 + goto out;
72280 +
72281 if (flags & MREMAP_FIXED) {
72282 if (flags & MREMAP_MAYMOVE)
72283 ret = mremap_to(addr, old_len, new_addr, new_len);
72284 @@ -507,6 +535,7 @@ unsigned long do_mremap(unsigned long addr,
72285 addr + new_len);
72286 }
72287 ret = addr;
72288 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
72289 goto out;
72290 }
72291 }
72292 @@ -533,7 +562,13 @@ unsigned long do_mremap(unsigned long addr,
72293 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
72294 if (ret)
72295 goto out;
72296 +
72297 + map_flags = vma->vm_flags;
72298 ret = move_vma(vma, addr, old_len, new_len, new_addr);
72299 + if (!(ret & ~PAGE_MASK)) {
72300 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
72301 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
72302 + }
72303 }
72304 out:
72305 if (ret & ~PAGE_MASK)
72306 diff --git a/mm/nommu.c b/mm/nommu.c
72307 index bb8f4f0..40d3e02 100644
72308 --- a/mm/nommu.c
72309 +++ b/mm/nommu.c
72310 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
72311 int sysctl_overcommit_ratio = 50; /* default is 50% */
72312 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
72313 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
72314 -int heap_stack_gap = 0;
72315
72316 atomic_long_t mmap_pages_allocated;
72317
72318 @@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
72319 EXPORT_SYMBOL(find_vma);
72320
72321 /*
72322 - * find a VMA
72323 - * - we don't extend stack VMAs under NOMMU conditions
72324 - */
72325 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
72326 -{
72327 - return find_vma(mm, addr);
72328 -}
72329 -
72330 -/*
72331 * expand a stack to a given address
72332 * - not supported under NOMMU conditions
72333 */
72334 @@ -1580,6 +1570,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72335
72336 /* most fields are the same, copy all, and then fixup */
72337 *new = *vma;
72338 + INIT_LIST_HEAD(&new->anon_vma_chain);
72339 *region = *vma->vm_region;
72340 new->vm_region = region;
72341
72342 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
72343 index 918330f..ae99ae1 100644
72344 --- a/mm/page_alloc.c
72345 +++ b/mm/page_alloc.c
72346 @@ -335,7 +335,7 @@ out:
72347 * This usage means that zero-order pages may not be compound.
72348 */
72349
72350 -static void free_compound_page(struct page *page)
72351 +void free_compound_page(struct page *page)
72352 {
72353 __free_pages_ok(page, compound_order(page));
72354 }
72355 @@ -692,6 +692,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
72356 int i;
72357 int bad = 0;
72358
72359 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
72360 + unsigned long index = 1UL << order;
72361 +#endif
72362 +
72363 trace_mm_page_free(page, order);
72364 kmemcheck_free_shadow(page, order);
72365
72366 @@ -707,6 +711,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
72367 debug_check_no_obj_freed(page_address(page),
72368 PAGE_SIZE << order);
72369 }
72370 +
72371 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
72372 + for (; index; --index)
72373 + sanitize_highpage(page + index - 1);
72374 +#endif
72375 +
72376 arch_free_page(page, order);
72377 kernel_map_pages(page, 1 << order, 0);
72378
72379 @@ -830,8 +840,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
72380 arch_alloc_page(page, order);
72381 kernel_map_pages(page, 1 << order, 1);
72382
72383 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
72384 if (gfp_flags & __GFP_ZERO)
72385 prep_zero_page(page, order, gfp_flags);
72386 +#endif
72387
72388 if (order && (gfp_flags & __GFP_COMP))
72389 prep_compound_page(page, order);
72390 @@ -3523,7 +3535,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
72391 unsigned long pfn;
72392
72393 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
72394 +#ifdef CONFIG_X86_32
72395 + /* boot failures in VMware 8 on 32bit vanilla since
72396 + this change */
72397 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
72398 +#else
72399 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
72400 +#endif
72401 return 1;
72402 }
72403 return 0;
72404 diff --git a/mm/percpu.c b/mm/percpu.c
72405 index bb4be74..a43ea85 100644
72406 --- a/mm/percpu.c
72407 +++ b/mm/percpu.c
72408 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
72409 static unsigned int pcpu_high_unit_cpu __read_mostly;
72410
72411 /* the address of the first chunk which starts with the kernel static area */
72412 -void *pcpu_base_addr __read_mostly;
72413 +void *pcpu_base_addr __read_only;
72414 EXPORT_SYMBOL_GPL(pcpu_base_addr);
72415
72416 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
72417 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
72418 index c20ff48..137702a 100644
72419 --- a/mm/process_vm_access.c
72420 +++ b/mm/process_vm_access.c
72421 @@ -13,6 +13,7 @@
72422 #include <linux/uio.h>
72423 #include <linux/sched.h>
72424 #include <linux/highmem.h>
72425 +#include <linux/security.h>
72426 #include <linux/ptrace.h>
72427 #include <linux/slab.h>
72428 #include <linux/syscalls.h>
72429 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
72430 size_t iov_l_curr_offset = 0;
72431 ssize_t iov_len;
72432
72433 + return -ENOSYS; // PaX: until properly audited
72434 +
72435 /*
72436 * Work out how many pages of struct pages we're going to need
72437 * when eventually calling get_user_pages
72438 */
72439 for (i = 0; i < riovcnt; i++) {
72440 iov_len = rvec[i].iov_len;
72441 - if (iov_len > 0) {
72442 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
72443 - + iov_len)
72444 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
72445 - / PAGE_SIZE + 1;
72446 - nr_pages = max(nr_pages, nr_pages_iov);
72447 - }
72448 + if (iov_len <= 0)
72449 + continue;
72450 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
72451 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
72452 + nr_pages = max(nr_pages, nr_pages_iov);
72453 }
72454
72455 if (nr_pages == 0)
72456 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
72457 goto free_proc_pages;
72458 }
72459
72460 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
72461 + rc = -EPERM;
72462 + goto put_task_struct;
72463 + }
72464 +
72465 mm = mm_access(task, PTRACE_MODE_ATTACH);
72466 if (!mm || IS_ERR(mm)) {
72467 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
72468 diff --git a/mm/rmap.c b/mm/rmap.c
72469 index 5b5ad58..0f77903 100644
72470 --- a/mm/rmap.c
72471 +++ b/mm/rmap.c
72472 @@ -167,6 +167,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
72473 struct anon_vma *anon_vma = vma->anon_vma;
72474 struct anon_vma_chain *avc;
72475
72476 +#ifdef CONFIG_PAX_SEGMEXEC
72477 + struct anon_vma_chain *avc_m = NULL;
72478 +#endif
72479 +
72480 might_sleep();
72481 if (unlikely(!anon_vma)) {
72482 struct mm_struct *mm = vma->vm_mm;
72483 @@ -176,6 +180,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
72484 if (!avc)
72485 goto out_enomem;
72486
72487 +#ifdef CONFIG_PAX_SEGMEXEC
72488 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
72489 + if (!avc_m)
72490 + goto out_enomem_free_avc;
72491 +#endif
72492 +
72493 anon_vma = find_mergeable_anon_vma(vma);
72494 allocated = NULL;
72495 if (!anon_vma) {
72496 @@ -189,6 +199,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
72497 /* page_table_lock to protect against threads */
72498 spin_lock(&mm->page_table_lock);
72499 if (likely(!vma->anon_vma)) {
72500 +
72501 +#ifdef CONFIG_PAX_SEGMEXEC
72502 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
72503 +
72504 + if (vma_m) {
72505 + BUG_ON(vma_m->anon_vma);
72506 + vma_m->anon_vma = anon_vma;
72507 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
72508 + avc_m = NULL;
72509 + }
72510 +#endif
72511 +
72512 vma->anon_vma = anon_vma;
72513 anon_vma_chain_link(vma, avc, anon_vma);
72514 allocated = NULL;
72515 @@ -199,12 +221,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
72516
72517 if (unlikely(allocated))
72518 put_anon_vma(allocated);
72519 +
72520 +#ifdef CONFIG_PAX_SEGMEXEC
72521 + if (unlikely(avc_m))
72522 + anon_vma_chain_free(avc_m);
72523 +#endif
72524 +
72525 if (unlikely(avc))
72526 anon_vma_chain_free(avc);
72527 }
72528 return 0;
72529
72530 out_enomem_free_avc:
72531 +
72532 +#ifdef CONFIG_PAX_SEGMEXEC
72533 + if (avc_m)
72534 + anon_vma_chain_free(avc_m);
72535 +#endif
72536 +
72537 anon_vma_chain_free(avc);
72538 out_enomem:
72539 return -ENOMEM;
72540 @@ -240,7 +274,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
72541 * Attach the anon_vmas from src to dst.
72542 * Returns 0 on success, -ENOMEM on failure.
72543 */
72544 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
72545 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
72546 {
72547 struct anon_vma_chain *avc, *pavc;
72548 struct anon_vma *root = NULL;
72549 @@ -318,7 +352,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
72550 * the corresponding VMA in the parent process is attached to.
72551 * Returns 0 on success, non-zero on failure.
72552 */
72553 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
72554 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
72555 {
72556 struct anon_vma_chain *avc;
72557 struct anon_vma *anon_vma;
72558 diff --git a/mm/shmem.c b/mm/shmem.c
72559 index f99ff3e..faea8b6 100644
72560 --- a/mm/shmem.c
72561 +++ b/mm/shmem.c
72562 @@ -31,7 +31,7 @@
72563 #include <linux/export.h>
72564 #include <linux/swap.h>
72565
72566 -static struct vfsmount *shm_mnt;
72567 +struct vfsmount *shm_mnt;
72568
72569 #ifdef CONFIG_SHMEM
72570 /*
72571 @@ -74,7 +74,7 @@ static struct vfsmount *shm_mnt;
72572 #define BOGO_DIRENT_SIZE 20
72573
72574 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
72575 -#define SHORT_SYMLINK_LEN 128
72576 +#define SHORT_SYMLINK_LEN 64
72577
72578 struct shmem_xattr {
72579 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
72580 @@ -2235,8 +2235,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
72581 int err = -ENOMEM;
72582
72583 /* Round up to L1_CACHE_BYTES to resist false sharing */
72584 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
72585 - L1_CACHE_BYTES), GFP_KERNEL);
72586 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
72587 if (!sbinfo)
72588 return -ENOMEM;
72589
72590 diff --git a/mm/slab.c b/mm/slab.c
72591 index e901a36..ee8fe97 100644
72592 --- a/mm/slab.c
72593 +++ b/mm/slab.c
72594 @@ -153,7 +153,7 @@
72595
72596 /* Legal flag mask for kmem_cache_create(). */
72597 #if DEBUG
72598 -# define CREATE_MASK (SLAB_RED_ZONE | \
72599 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
72600 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
72601 SLAB_CACHE_DMA | \
72602 SLAB_STORE_USER | \
72603 @@ -161,7 +161,7 @@
72604 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
72605 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
72606 #else
72607 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
72608 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
72609 SLAB_CACHE_DMA | \
72610 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
72611 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
72612 @@ -290,7 +290,7 @@ struct kmem_list3 {
72613 * Need this for bootstrapping a per node allocator.
72614 */
72615 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
72616 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
72617 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
72618 #define CACHE_CACHE 0
72619 #define SIZE_AC MAX_NUMNODES
72620 #define SIZE_L3 (2 * MAX_NUMNODES)
72621 @@ -391,10 +391,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
72622 if ((x)->max_freeable < i) \
72623 (x)->max_freeable = i; \
72624 } while (0)
72625 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
72626 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
72627 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
72628 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
72629 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
72630 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
72631 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
72632 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
72633 #else
72634 #define STATS_INC_ACTIVE(x) do { } while (0)
72635 #define STATS_DEC_ACTIVE(x) do { } while (0)
72636 @@ -542,7 +542,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
72637 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
72638 */
72639 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
72640 - const struct slab *slab, void *obj)
72641 + const struct slab *slab, const void *obj)
72642 {
72643 u32 offset = (obj - slab->s_mem);
72644 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
72645 @@ -568,7 +568,7 @@ struct cache_names {
72646 static struct cache_names __initdata cache_names[] = {
72647 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
72648 #include <linux/kmalloc_sizes.h>
72649 - {NULL,}
72650 + {NULL}
72651 #undef CACHE
72652 };
72653
72654 @@ -1588,7 +1588,7 @@ void __init kmem_cache_init(void)
72655 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
72656 sizes[INDEX_AC].cs_size,
72657 ARCH_KMALLOC_MINALIGN,
72658 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
72659 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
72660 NULL);
72661
72662 if (INDEX_AC != INDEX_L3) {
72663 @@ -1596,7 +1596,7 @@ void __init kmem_cache_init(void)
72664 kmem_cache_create(names[INDEX_L3].name,
72665 sizes[INDEX_L3].cs_size,
72666 ARCH_KMALLOC_MINALIGN,
72667 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
72668 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
72669 NULL);
72670 }
72671
72672 @@ -1614,7 +1614,7 @@ void __init kmem_cache_init(void)
72673 sizes->cs_cachep = kmem_cache_create(names->name,
72674 sizes->cs_size,
72675 ARCH_KMALLOC_MINALIGN,
72676 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
72677 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
72678 NULL);
72679 }
72680 #ifdef CONFIG_ZONE_DMA
72681 @@ -4390,10 +4390,10 @@ static int s_show(struct seq_file *m, void *p)
72682 }
72683 /* cpu stats */
72684 {
72685 - unsigned long allochit = atomic_read(&cachep->allochit);
72686 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
72687 - unsigned long freehit = atomic_read(&cachep->freehit);
72688 - unsigned long freemiss = atomic_read(&cachep->freemiss);
72689 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
72690 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
72691 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
72692 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
72693
72694 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
72695 allochit, allocmiss, freehit, freemiss);
72696 @@ -4652,13 +4652,62 @@ static int __init slab_proc_init(void)
72697 {
72698 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
72699 #ifdef CONFIG_DEBUG_SLAB_LEAK
72700 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
72701 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
72702 #endif
72703 return 0;
72704 }
72705 module_init(slab_proc_init);
72706 #endif
72707
72708 +void check_object_size(const void *ptr, unsigned long n, bool to)
72709 +{
72710 +
72711 +#ifdef CONFIG_PAX_USERCOPY
72712 + struct page *page;
72713 + struct kmem_cache *cachep = NULL;
72714 + struct slab *slabp;
72715 + unsigned int objnr;
72716 + unsigned long offset;
72717 + const char *type;
72718 +
72719 + if (!n)
72720 + return;
72721 +
72722 + type = "<null>";
72723 + if (ZERO_OR_NULL_PTR(ptr))
72724 + goto report;
72725 +
72726 + if (!virt_addr_valid(ptr))
72727 + return;
72728 +
72729 + page = virt_to_head_page(ptr);
72730 +
72731 + type = "<process stack>";
72732 + if (!PageSlab(page)) {
72733 + if (object_is_on_stack(ptr, n) == -1)
72734 + goto report;
72735 + return;
72736 + }
72737 +
72738 + cachep = page_get_cache(page);
72739 + type = cachep->name;
72740 + if (!(cachep->flags & SLAB_USERCOPY))
72741 + goto report;
72742 +
72743 + slabp = page_get_slab(page);
72744 + objnr = obj_to_index(cachep, slabp, ptr);
72745 + BUG_ON(objnr >= cachep->num);
72746 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
72747 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
72748 + return;
72749 +
72750 +report:
72751 + pax_report_usercopy(ptr, n, to, type);
72752 +#endif
72753 +
72754 +}
72755 +EXPORT_SYMBOL(check_object_size);
72756 +
72757 /**
72758 * ksize - get the actual amount of memory allocated for a given object
72759 * @objp: Pointer to the object
72760 diff --git a/mm/slob.c b/mm/slob.c
72761 index 8105be4..e045f96 100644
72762 --- a/mm/slob.c
72763 +++ b/mm/slob.c
72764 @@ -29,7 +29,7 @@
72765 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
72766 * alloc_pages() directly, allocating compound pages so the page order
72767 * does not have to be separately tracked, and also stores the exact
72768 - * allocation size in page->private so that it can be used to accurately
72769 + * allocation size in slob_page->size so that it can be used to accurately
72770 * provide ksize(). These objects are detected in kfree() because slob_page()
72771 * is false for them.
72772 *
72773 @@ -58,6 +58,7 @@
72774 */
72775
72776 #include <linux/kernel.h>
72777 +#include <linux/sched.h>
72778 #include <linux/slab.h>
72779 #include <linux/mm.h>
72780 #include <linux/swap.h> /* struct reclaim_state */
72781 @@ -102,7 +103,8 @@ struct slob_page {
72782 unsigned long flags; /* mandatory */
72783 atomic_t _count; /* mandatory */
72784 slobidx_t units; /* free units left in page */
72785 - unsigned long pad[2];
72786 + unsigned long pad[1];
72787 + unsigned long size; /* size when >=PAGE_SIZE */
72788 slob_t *free; /* first free slob_t in page */
72789 struct list_head list; /* linked list of free pages */
72790 };
72791 @@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
72792 */
72793 static inline int is_slob_page(struct slob_page *sp)
72794 {
72795 - return PageSlab((struct page *)sp);
72796 + return PageSlab((struct page *)sp) && !sp->size;
72797 }
72798
72799 static inline void set_slob_page(struct slob_page *sp)
72800 @@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
72801
72802 static inline struct slob_page *slob_page(const void *addr)
72803 {
72804 - return (struct slob_page *)virt_to_page(addr);
72805 + return (struct slob_page *)virt_to_head_page(addr);
72806 }
72807
72808 /*
72809 @@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
72810 /*
72811 * Return the size of a slob block.
72812 */
72813 -static slobidx_t slob_units(slob_t *s)
72814 +static slobidx_t slob_units(const slob_t *s)
72815 {
72816 if (s->units > 0)
72817 return s->units;
72818 @@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
72819 /*
72820 * Return the next free slob block pointer after this one.
72821 */
72822 -static slob_t *slob_next(slob_t *s)
72823 +static slob_t *slob_next(const slob_t *s)
72824 {
72825 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
72826 slobidx_t next;
72827 @@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
72828 /*
72829 * Returns true if s is the last free block in its page.
72830 */
72831 -static int slob_last(slob_t *s)
72832 +static int slob_last(const slob_t *s)
72833 {
72834 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
72835 }
72836 @@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
72837 if (!page)
72838 return NULL;
72839
72840 + set_slob_page(page);
72841 return page_address(page);
72842 }
72843
72844 @@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
72845 if (!b)
72846 return NULL;
72847 sp = slob_page(b);
72848 - set_slob_page(sp);
72849
72850 spin_lock_irqsave(&slob_lock, flags);
72851 sp->units = SLOB_UNITS(PAGE_SIZE);
72852 sp->free = b;
72853 + sp->size = 0;
72854 INIT_LIST_HEAD(&sp->list);
72855 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
72856 set_slob_page_free(sp, slob_list);
72857 @@ -476,10 +479,9 @@ out:
72858 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
72859 */
72860
72861 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72862 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
72863 {
72864 - unsigned int *m;
72865 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
72866 + slob_t *m;
72867 void *ret;
72868
72869 gfp &= gfp_allowed_mask;
72870 @@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72871
72872 if (!m)
72873 return NULL;
72874 - *m = size;
72875 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
72876 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
72877 + m[0].units = size;
72878 + m[1].units = align;
72879 ret = (void *)m + align;
72880
72881 trace_kmalloc_node(_RET_IP_, ret,
72882 @@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72883 gfp |= __GFP_COMP;
72884 ret = slob_new_pages(gfp, order, node);
72885 if (ret) {
72886 - struct page *page;
72887 - page = virt_to_page(ret);
72888 - page->private = size;
72889 + struct slob_page *sp;
72890 + sp = slob_page(ret);
72891 + sp->size = size;
72892 }
72893
72894 trace_kmalloc_node(_RET_IP_, ret,
72895 size, PAGE_SIZE << order, gfp, node);
72896 }
72897
72898 - kmemleak_alloc(ret, size, 1, gfp);
72899 + return ret;
72900 +}
72901 +
72902 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72903 +{
72904 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
72905 + void *ret = __kmalloc_node_align(size, gfp, node, align);
72906 +
72907 + if (!ZERO_OR_NULL_PTR(ret))
72908 + kmemleak_alloc(ret, size, 1, gfp);
72909 return ret;
72910 }
72911 EXPORT_SYMBOL(__kmalloc_node);
72912 @@ -533,13 +547,92 @@ void kfree(const void *block)
72913 sp = slob_page(block);
72914 if (is_slob_page(sp)) {
72915 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
72916 - unsigned int *m = (unsigned int *)(block - align);
72917 - slob_free(m, *m + align);
72918 - } else
72919 + slob_t *m = (slob_t *)(block - align);
72920 + slob_free(m, m[0].units + align);
72921 + } else {
72922 + clear_slob_page(sp);
72923 + free_slob_page(sp);
72924 + sp->size = 0;
72925 put_page(&sp->page);
72926 + }
72927 }
72928 EXPORT_SYMBOL(kfree);
72929
72930 +void check_object_size(const void *ptr, unsigned long n, bool to)
72931 +{
72932 +
72933 +#ifdef CONFIG_PAX_USERCOPY
72934 + struct slob_page *sp;
72935 + const slob_t *free;
72936 + const void *base;
72937 + unsigned long flags;
72938 + const char *type;
72939 +
72940 + if (!n)
72941 + return;
72942 +
72943 + type = "<null>";
72944 + if (ZERO_OR_NULL_PTR(ptr))
72945 + goto report;
72946 +
72947 + if (!virt_addr_valid(ptr))
72948 + return;
72949 +
72950 + type = "<process stack>";
72951 + sp = slob_page(ptr);
72952 + if (!PageSlab((struct page *)sp)) {
72953 + if (object_is_on_stack(ptr, n) == -1)
72954 + goto report;
72955 + return;
72956 + }
72957 +
72958 + type = "<slob>";
72959 + if (sp->size) {
72960 + base = page_address(&sp->page);
72961 + if (base <= ptr && n <= sp->size - (ptr - base))
72962 + return;
72963 + goto report;
72964 + }
72965 +
72966 + /* some tricky double walking to find the chunk */
72967 + spin_lock_irqsave(&slob_lock, flags);
72968 + base = (void *)((unsigned long)ptr & PAGE_MASK);
72969 + free = sp->free;
72970 +
72971 + while (!slob_last(free) && (void *)free <= ptr) {
72972 + base = free + slob_units(free);
72973 + free = slob_next(free);
72974 + }
72975 +
72976 + while (base < (void *)free) {
72977 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
72978 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
72979 + int offset;
72980 +
72981 + if (ptr < base + align)
72982 + break;
72983 +
72984 + offset = ptr - base - align;
72985 + if (offset >= m) {
72986 + base += size;
72987 + continue;
72988 + }
72989 +
72990 + if (n > m - offset)
72991 + break;
72992 +
72993 + spin_unlock_irqrestore(&slob_lock, flags);
72994 + return;
72995 + }
72996 +
72997 + spin_unlock_irqrestore(&slob_lock, flags);
72998 +report:
72999 + pax_report_usercopy(ptr, n, to, type);
73000 +#endif
73001 +
73002 +}
73003 +EXPORT_SYMBOL(check_object_size);
73004 +
73005 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
73006 size_t ksize(const void *block)
73007 {
73008 @@ -552,10 +645,10 @@ size_t ksize(const void *block)
73009 sp = slob_page(block);
73010 if (is_slob_page(sp)) {
73011 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73012 - unsigned int *m = (unsigned int *)(block - align);
73013 - return SLOB_UNITS(*m) * SLOB_UNIT;
73014 + slob_t *m = (slob_t *)(block - align);
73015 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
73016 } else
73017 - return sp->page.private;
73018 + return sp->size;
73019 }
73020 EXPORT_SYMBOL(ksize);
73021
73022 @@ -571,8 +664,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73023 {
73024 struct kmem_cache *c;
73025
73026 +#ifdef CONFIG_PAX_USERCOPY
73027 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
73028 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
73029 +#else
73030 c = slob_alloc(sizeof(struct kmem_cache),
73031 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
73032 +#endif
73033
73034 if (c) {
73035 c->name = name;
73036 @@ -614,17 +712,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
73037
73038 lockdep_trace_alloc(flags);
73039
73040 +#ifdef CONFIG_PAX_USERCOPY
73041 + b = __kmalloc_node_align(c->size, flags, node, c->align);
73042 +#else
73043 if (c->size < PAGE_SIZE) {
73044 b = slob_alloc(c->size, flags, c->align, node);
73045 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
73046 SLOB_UNITS(c->size) * SLOB_UNIT,
73047 flags, node);
73048 } else {
73049 + struct slob_page *sp;
73050 +
73051 b = slob_new_pages(flags, get_order(c->size), node);
73052 + sp = slob_page(b);
73053 + sp->size = c->size;
73054 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
73055 PAGE_SIZE << get_order(c->size),
73056 flags, node);
73057 }
73058 +#endif
73059
73060 if (c->ctor)
73061 c->ctor(b);
73062 @@ -636,10 +742,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
73063
73064 static void __kmem_cache_free(void *b, int size)
73065 {
73066 - if (size < PAGE_SIZE)
73067 + struct slob_page *sp = slob_page(b);
73068 +
73069 + if (is_slob_page(sp))
73070 slob_free(b, size);
73071 - else
73072 + else {
73073 + clear_slob_page(sp);
73074 + free_slob_page(sp);
73075 + sp->size = 0;
73076 slob_free_pages(b, get_order(size));
73077 + }
73078 }
73079
73080 static void kmem_rcu_free(struct rcu_head *head)
73081 @@ -652,17 +764,31 @@ static void kmem_rcu_free(struct rcu_head *head)
73082
73083 void kmem_cache_free(struct kmem_cache *c, void *b)
73084 {
73085 + int size = c->size;
73086 +
73087 +#ifdef CONFIG_PAX_USERCOPY
73088 + if (size + c->align < PAGE_SIZE) {
73089 + size += c->align;
73090 + b -= c->align;
73091 + }
73092 +#endif
73093 +
73094 kmemleak_free_recursive(b, c->flags);
73095 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
73096 struct slob_rcu *slob_rcu;
73097 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
73098 - slob_rcu->size = c->size;
73099 + slob_rcu = b + (size - sizeof(struct slob_rcu));
73100 + slob_rcu->size = size;
73101 call_rcu(&slob_rcu->head, kmem_rcu_free);
73102 } else {
73103 - __kmem_cache_free(b, c->size);
73104 + __kmem_cache_free(b, size);
73105 }
73106
73107 +#ifdef CONFIG_PAX_USERCOPY
73108 + trace_kfree(_RET_IP_, b);
73109 +#else
73110 trace_kmem_cache_free(_RET_IP_, b);
73111 +#endif
73112 +
73113 }
73114 EXPORT_SYMBOL(kmem_cache_free);
73115
73116 diff --git a/mm/slub.c b/mm/slub.c
73117 index 71de9b5..dd263c5 100644
73118 --- a/mm/slub.c
73119 +++ b/mm/slub.c
73120 @@ -209,7 +209,7 @@ struct track {
73121
73122 enum track_item { TRACK_ALLOC, TRACK_FREE };
73123
73124 -#ifdef CONFIG_SYSFS
73125 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73126 static int sysfs_slab_add(struct kmem_cache *);
73127 static int sysfs_slab_alias(struct kmem_cache *, const char *);
73128 static void sysfs_slab_remove(struct kmem_cache *);
73129 @@ -538,7 +538,7 @@ static void print_track(const char *s, struct track *t)
73130 if (!t->addr)
73131 return;
73132
73133 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
73134 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
73135 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
73136 #ifdef CONFIG_STACKTRACE
73137 {
73138 @@ -2603,6 +2603,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
73139
73140 page = virt_to_head_page(x);
73141
73142 + BUG_ON(!PageSlab(page));
73143 +
73144 slab_free(s, page, x, _RET_IP_);
73145
73146 trace_kmem_cache_free(_RET_IP_, x);
73147 @@ -2636,7 +2638,7 @@ static int slub_min_objects;
73148 * Merge control. If this is set then no merging of slab caches will occur.
73149 * (Could be removed. This was introduced to pacify the merge skeptics.)
73150 */
73151 -static int slub_nomerge;
73152 +static int slub_nomerge = 1;
73153
73154 /*
73155 * Calculate the order of allocation given an slab object size.
73156 @@ -3089,7 +3091,7 @@ static int kmem_cache_open(struct kmem_cache *s,
73157 else
73158 s->cpu_partial = 30;
73159
73160 - s->refcount = 1;
73161 + atomic_set(&s->refcount, 1);
73162 #ifdef CONFIG_NUMA
73163 s->remote_node_defrag_ratio = 1000;
73164 #endif
73165 @@ -3193,8 +3195,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
73166 void kmem_cache_destroy(struct kmem_cache *s)
73167 {
73168 down_write(&slub_lock);
73169 - s->refcount--;
73170 - if (!s->refcount) {
73171 + if (atomic_dec_and_test(&s->refcount)) {
73172 list_del(&s->list);
73173 up_write(&slub_lock);
73174 if (kmem_cache_close(s)) {
73175 @@ -3405,6 +3406,50 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
73176 EXPORT_SYMBOL(__kmalloc_node);
73177 #endif
73178
73179 +void check_object_size(const void *ptr, unsigned long n, bool to)
73180 +{
73181 +
73182 +#ifdef CONFIG_PAX_USERCOPY
73183 + struct page *page;
73184 + struct kmem_cache *s = NULL;
73185 + unsigned long offset;
73186 + const char *type;
73187 +
73188 + if (!n)
73189 + return;
73190 +
73191 + type = "<null>";
73192 + if (ZERO_OR_NULL_PTR(ptr))
73193 + goto report;
73194 +
73195 + if (!virt_addr_valid(ptr))
73196 + return;
73197 +
73198 + page = virt_to_head_page(ptr);
73199 +
73200 + type = "<process stack>";
73201 + if (!PageSlab(page)) {
73202 + if (object_is_on_stack(ptr, n) == -1)
73203 + goto report;
73204 + return;
73205 + }
73206 +
73207 + s = page->slab;
73208 + type = s->name;
73209 + if (!(s->flags & SLAB_USERCOPY))
73210 + goto report;
73211 +
73212 + offset = (ptr - page_address(page)) % s->size;
73213 + if (offset <= s->objsize && n <= s->objsize - offset)
73214 + return;
73215 +
73216 +report:
73217 + pax_report_usercopy(ptr, n, to, type);
73218 +#endif
73219 +
73220 +}
73221 +EXPORT_SYMBOL(check_object_size);
73222 +
73223 size_t ksize(const void *object)
73224 {
73225 struct page *page;
73226 @@ -3679,7 +3724,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
73227 int node;
73228
73229 list_add(&s->list, &slab_caches);
73230 - s->refcount = -1;
73231 + atomic_set(&s->refcount, -1);
73232
73233 for_each_node_state(node, N_NORMAL_MEMORY) {
73234 struct kmem_cache_node *n = get_node(s, node);
73235 @@ -3799,17 +3844,17 @@ void __init kmem_cache_init(void)
73236
73237 /* Caches that are not of the two-to-the-power-of size */
73238 if (KMALLOC_MIN_SIZE <= 32) {
73239 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
73240 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
73241 caches++;
73242 }
73243
73244 if (KMALLOC_MIN_SIZE <= 64) {
73245 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
73246 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
73247 caches++;
73248 }
73249
73250 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
73251 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
73252 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
73253 caches++;
73254 }
73255
73256 @@ -3877,7 +3922,7 @@ static int slab_unmergeable(struct kmem_cache *s)
73257 /*
73258 * We may have set a slab to be unmergeable during bootstrap.
73259 */
73260 - if (s->refcount < 0)
73261 + if (atomic_read(&s->refcount) < 0)
73262 return 1;
73263
73264 return 0;
73265 @@ -3936,7 +3981,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73266 down_write(&slub_lock);
73267 s = find_mergeable(size, align, flags, name, ctor);
73268 if (s) {
73269 - s->refcount++;
73270 + atomic_inc(&s->refcount);
73271 /*
73272 * Adjust the object sizes so that we clear
73273 * the complete object on kzalloc.
73274 @@ -3945,7 +3990,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73275 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
73276
73277 if (sysfs_slab_alias(s, name)) {
73278 - s->refcount--;
73279 + atomic_dec(&s->refcount);
73280 goto err;
73281 }
73282 up_write(&slub_lock);
73283 @@ -4074,7 +4119,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
73284 }
73285 #endif
73286
73287 -#ifdef CONFIG_SYSFS
73288 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73289 static int count_inuse(struct page *page)
73290 {
73291 return page->inuse;
73292 @@ -4461,12 +4506,12 @@ static void resiliency_test(void)
73293 validate_slab_cache(kmalloc_caches[9]);
73294 }
73295 #else
73296 -#ifdef CONFIG_SYSFS
73297 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73298 static void resiliency_test(void) {};
73299 #endif
73300 #endif
73301
73302 -#ifdef CONFIG_SYSFS
73303 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73304 enum slab_stat_type {
73305 SL_ALL, /* All slabs */
73306 SL_PARTIAL, /* Only partially allocated slabs */
73307 @@ -4709,7 +4754,7 @@ SLAB_ATTR_RO(ctor);
73308
73309 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
73310 {
73311 - return sprintf(buf, "%d\n", s->refcount - 1);
73312 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
73313 }
73314 SLAB_ATTR_RO(aliases);
73315
73316 @@ -5280,6 +5325,7 @@ static char *create_unique_id(struct kmem_cache *s)
73317 return name;
73318 }
73319
73320 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73321 static int sysfs_slab_add(struct kmem_cache *s)
73322 {
73323 int err;
73324 @@ -5342,6 +5388,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
73325 kobject_del(&s->kobj);
73326 kobject_put(&s->kobj);
73327 }
73328 +#endif
73329
73330 /*
73331 * Need to buffer aliases during bootup until sysfs becomes
73332 @@ -5355,6 +5402,7 @@ struct saved_alias {
73333
73334 static struct saved_alias *alias_list;
73335
73336 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73337 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
73338 {
73339 struct saved_alias *al;
73340 @@ -5377,6 +5425,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
73341 alias_list = al;
73342 return 0;
73343 }
73344 +#endif
73345
73346 static int __init slab_sysfs_init(void)
73347 {
73348 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
73349 index 1b7e22a..3fcd4f3 100644
73350 --- a/mm/sparse-vmemmap.c
73351 +++ b/mm/sparse-vmemmap.c
73352 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
73353 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
73354 if (!p)
73355 return NULL;
73356 - pud_populate(&init_mm, pud, p);
73357 + pud_populate_kernel(&init_mm, pud, p);
73358 }
73359 return pud;
73360 }
73361 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
73362 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
73363 if (!p)
73364 return NULL;
73365 - pgd_populate(&init_mm, pgd, p);
73366 + pgd_populate_kernel(&init_mm, pgd, p);
73367 }
73368 return pgd;
73369 }
73370 diff --git a/mm/swap.c b/mm/swap.c
73371 index 5c13f13..f1cfc13 100644
73372 --- a/mm/swap.c
73373 +++ b/mm/swap.c
73374 @@ -30,6 +30,7 @@
73375 #include <linux/backing-dev.h>
73376 #include <linux/memcontrol.h>
73377 #include <linux/gfp.h>
73378 +#include <linux/hugetlb.h>
73379
73380 #include "internal.h"
73381
73382 @@ -70,6 +71,8 @@ static void __put_compound_page(struct page *page)
73383
73384 __page_cache_release(page);
73385 dtor = get_compound_page_dtor(page);
73386 + if (!PageHuge(page))
73387 + BUG_ON(dtor != free_compound_page);
73388 (*dtor)(page);
73389 }
73390
73391 diff --git a/mm/swapfile.c b/mm/swapfile.c
73392 index 38186d9..bfba6d3 100644
73393 --- a/mm/swapfile.c
73394 +++ b/mm/swapfile.c
73395 @@ -61,7 +61,7 @@ static DEFINE_MUTEX(swapon_mutex);
73396
73397 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
73398 /* Activity counter to indicate that a swapon or swapoff has occurred */
73399 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
73400 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
73401
73402 static inline unsigned char swap_count(unsigned char ent)
73403 {
73404 @@ -1671,7 +1671,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
73405 }
73406 filp_close(swap_file, NULL);
73407 err = 0;
73408 - atomic_inc(&proc_poll_event);
73409 + atomic_inc_unchecked(&proc_poll_event);
73410 wake_up_interruptible(&proc_poll_wait);
73411
73412 out_dput:
73413 @@ -1687,8 +1687,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
73414
73415 poll_wait(file, &proc_poll_wait, wait);
73416
73417 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
73418 - seq->poll_event = atomic_read(&proc_poll_event);
73419 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
73420 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
73421 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
73422 }
73423
73424 @@ -1786,7 +1786,7 @@ static int swaps_open(struct inode *inode, struct file *file)
73425 return ret;
73426
73427 seq = file->private_data;
73428 - seq->poll_event = atomic_read(&proc_poll_event);
73429 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
73430 return 0;
73431 }
73432
73433 @@ -2123,7 +2123,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
73434 (p->flags & SWP_DISCARDABLE) ? "D" : "");
73435
73436 mutex_unlock(&swapon_mutex);
73437 - atomic_inc(&proc_poll_event);
73438 + atomic_inc_unchecked(&proc_poll_event);
73439 wake_up_interruptible(&proc_poll_wait);
73440
73441 if (S_ISREG(inode->i_mode))
73442 diff --git a/mm/util.c b/mm/util.c
73443 index ae962b3..0bba886 100644
73444 --- a/mm/util.c
73445 +++ b/mm/util.c
73446 @@ -284,6 +284,12 @@ done:
73447 void arch_pick_mmap_layout(struct mm_struct *mm)
73448 {
73449 mm->mmap_base = TASK_UNMAPPED_BASE;
73450 +
73451 +#ifdef CONFIG_PAX_RANDMMAP
73452 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73453 + mm->mmap_base += mm->delta_mmap;
73454 +#endif
73455 +
73456 mm->get_unmapped_area = arch_get_unmapped_area;
73457 mm->unmap_area = arch_unmap_area;
73458 }
73459 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
73460 index 1196c77..2e608e8 100644
73461 --- a/mm/vmalloc.c
73462 +++ b/mm/vmalloc.c
73463 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
73464
73465 pte = pte_offset_kernel(pmd, addr);
73466 do {
73467 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
73468 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
73469 +
73470 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
73471 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
73472 + BUG_ON(!pte_exec(*pte));
73473 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
73474 + continue;
73475 + }
73476 +#endif
73477 +
73478 + {
73479 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
73480 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
73481 + }
73482 } while (pte++, addr += PAGE_SIZE, addr != end);
73483 }
73484
73485 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
73486 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
73487 {
73488 pte_t *pte;
73489 + int ret = -ENOMEM;
73490
73491 /*
73492 * nr is a running index into the array which helps higher level
73493 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
73494 pte = pte_alloc_kernel(pmd, addr);
73495 if (!pte)
73496 return -ENOMEM;
73497 +
73498 + pax_open_kernel();
73499 do {
73500 struct page *page = pages[*nr];
73501
73502 - if (WARN_ON(!pte_none(*pte)))
73503 - return -EBUSY;
73504 - if (WARN_ON(!page))
73505 - return -ENOMEM;
73506 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
73507 + if (pgprot_val(prot) & _PAGE_NX)
73508 +#endif
73509 +
73510 + if (WARN_ON(!pte_none(*pte))) {
73511 + ret = -EBUSY;
73512 + goto out;
73513 + }
73514 + if (WARN_ON(!page)) {
73515 + ret = -ENOMEM;
73516 + goto out;
73517 + }
73518 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
73519 (*nr)++;
73520 } while (pte++, addr += PAGE_SIZE, addr != end);
73521 - return 0;
73522 + ret = 0;
73523 +out:
73524 + pax_close_kernel();
73525 + return ret;
73526 }
73527
73528 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
73529 @@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
73530 pmd_t *pmd;
73531 unsigned long next;
73532
73533 - pmd = pmd_alloc(&init_mm, pud, addr);
73534 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
73535 if (!pmd)
73536 return -ENOMEM;
73537 do {
73538 @@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
73539 pud_t *pud;
73540 unsigned long next;
73541
73542 - pud = pud_alloc(&init_mm, pgd, addr);
73543 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
73544 if (!pud)
73545 return -ENOMEM;
73546 do {
73547 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
73548 * and fall back on vmalloc() if that fails. Others
73549 * just put it in the vmalloc space.
73550 */
73551 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
73552 +#ifdef CONFIG_MODULES
73553 +#ifdef MODULES_VADDR
73554 unsigned long addr = (unsigned long)x;
73555 if (addr >= MODULES_VADDR && addr < MODULES_END)
73556 return 1;
73557 #endif
73558 +
73559 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
73560 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
73561 + return 1;
73562 +#endif
73563 +
73564 +#endif
73565 +
73566 return is_vmalloc_addr(x);
73567 }
73568
73569 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
73570
73571 if (!pgd_none(*pgd)) {
73572 pud_t *pud = pud_offset(pgd, addr);
73573 +#ifdef CONFIG_X86
73574 + if (!pud_large(*pud))
73575 +#endif
73576 if (!pud_none(*pud)) {
73577 pmd_t *pmd = pmd_offset(pud, addr);
73578 +#ifdef CONFIG_X86
73579 + if (!pmd_large(*pmd))
73580 +#endif
73581 if (!pmd_none(*pmd)) {
73582 pte_t *ptep, pte;
73583
73584 @@ -332,6 +372,10 @@ static void purge_vmap_area_lazy(void);
73585 static struct vmap_area *alloc_vmap_area(unsigned long size,
73586 unsigned long align,
73587 unsigned long vstart, unsigned long vend,
73588 + int node, gfp_t gfp_mask) __size_overflow(1);
73589 +static struct vmap_area *alloc_vmap_area(unsigned long size,
73590 + unsigned long align,
73591 + unsigned long vstart, unsigned long vend,
73592 int node, gfp_t gfp_mask)
73593 {
73594 struct vmap_area *va;
73595 @@ -1320,6 +1364,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
73596 struct vm_struct *area;
73597
73598 BUG_ON(in_interrupt());
73599 +
73600 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
73601 + if (flags & VM_KERNEXEC) {
73602 + if (start != VMALLOC_START || end != VMALLOC_END)
73603 + return NULL;
73604 + start = (unsigned long)MODULES_EXEC_VADDR;
73605 + end = (unsigned long)MODULES_EXEC_END;
73606 + }
73607 +#endif
73608 +
73609 if (flags & VM_IOREMAP) {
73610 int bit = fls(size);
73611
73612 @@ -1552,6 +1606,11 @@ void *vmap(struct page **pages, unsigned int count,
73613 if (count > totalram_pages)
73614 return NULL;
73615
73616 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
73617 + if (!(pgprot_val(prot) & _PAGE_NX))
73618 + flags |= VM_KERNEXEC;
73619 +#endif
73620 +
73621 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
73622 __builtin_return_address(0));
73623 if (!area)
73624 @@ -1653,6 +1712,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
73625 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
73626 goto fail;
73627
73628 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
73629 + if (!(pgprot_val(prot) & _PAGE_NX))
73630 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
73631 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
73632 + else
73633 +#endif
73634 +
73635 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
73636 start, end, node, gfp_mask, caller);
73637 if (!area)
73638 @@ -1826,10 +1892,9 @@ EXPORT_SYMBOL(vzalloc_node);
73639 * For tight control over page level allocator and protection flags
73640 * use __vmalloc() instead.
73641 */
73642 -
73643 void *vmalloc_exec(unsigned long size)
73644 {
73645 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
73646 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
73647 -1, __builtin_return_address(0));
73648 }
73649
73650 @@ -2124,6 +2189,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
73651 unsigned long uaddr = vma->vm_start;
73652 unsigned long usize = vma->vm_end - vma->vm_start;
73653
73654 + BUG_ON(vma->vm_mirror);
73655 +
73656 if ((PAGE_SIZE-1) & (unsigned long)addr)
73657 return -EINVAL;
73658
73659 @@ -2376,8 +2443,8 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
73660 return NULL;
73661 }
73662
73663 - vms = kzalloc(sizeof(vms[0]) * nr_vms, GFP_KERNEL);
73664 - vas = kzalloc(sizeof(vas[0]) * nr_vms, GFP_KERNEL);
73665 + vms = kcalloc(nr_vms, sizeof(vms[0]), GFP_KERNEL);
73666 + vas = kcalloc(nr_vms, sizeof(vas[0]), GFP_KERNEL);
73667 if (!vas || !vms)
73668 goto err_free2;
73669
73670 diff --git a/mm/vmstat.c b/mm/vmstat.c
73671 index 7db1b9b..e9f6b07 100644
73672 --- a/mm/vmstat.c
73673 +++ b/mm/vmstat.c
73674 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
73675 *
73676 * vm_stat contains the global counters
73677 */
73678 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
73679 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
73680 EXPORT_SYMBOL(vm_stat);
73681
73682 #ifdef CONFIG_SMP
73683 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
73684 v = p->vm_stat_diff[i];
73685 p->vm_stat_diff[i] = 0;
73686 local_irq_restore(flags);
73687 - atomic_long_add(v, &zone->vm_stat[i]);
73688 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
73689 global_diff[i] += v;
73690 #ifdef CONFIG_NUMA
73691 /* 3 seconds idle till flush */
73692 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
73693
73694 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
73695 if (global_diff[i])
73696 - atomic_long_add(global_diff[i], &vm_stat[i]);
73697 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
73698 }
73699
73700 #endif
73701 @@ -1208,10 +1208,20 @@ static int __init setup_vmstat(void)
73702 start_cpu_timer(cpu);
73703 #endif
73704 #ifdef CONFIG_PROC_FS
73705 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
73706 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
73707 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
73708 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
73709 + {
73710 + mode_t gr_mode = S_IRUGO;
73711 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
73712 + gr_mode = S_IRUSR;
73713 +#endif
73714 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
73715 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
73716 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
73717 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
73718 +#else
73719 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
73720 +#endif
73721 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
73722 + }
73723 #endif
73724 return 0;
73725 }
73726 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
73727 index efea35b..9c8dd0b 100644
73728 --- a/net/8021q/vlan.c
73729 +++ b/net/8021q/vlan.c
73730 @@ -554,8 +554,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
73731 err = -EPERM;
73732 if (!capable(CAP_NET_ADMIN))
73733 break;
73734 - if ((args.u.name_type >= 0) &&
73735 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
73736 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
73737 struct vlan_net *vn;
73738
73739 vn = net_generic(net, vlan_net_id);
73740 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
73741 index fccae26..e7ece2f 100644
73742 --- a/net/9p/trans_fd.c
73743 +++ b/net/9p/trans_fd.c
73744 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
73745 oldfs = get_fs();
73746 set_fs(get_ds());
73747 /* The cast to a user pointer is valid due to the set_fs() */
73748 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
73749 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
73750 set_fs(oldfs);
73751
73752 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
73753 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
73754 index 876fbe8..8bbea9f 100644
73755 --- a/net/atm/atm_misc.c
73756 +++ b/net/atm/atm_misc.c
73757 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
73758 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
73759 return 1;
73760 atm_return(vcc, truesize);
73761 - atomic_inc(&vcc->stats->rx_drop);
73762 + atomic_inc_unchecked(&vcc->stats->rx_drop);
73763 return 0;
73764 }
73765 EXPORT_SYMBOL(atm_charge);
73766 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
73767 }
73768 }
73769 atm_return(vcc, guess);
73770 - atomic_inc(&vcc->stats->rx_drop);
73771 + atomic_inc_unchecked(&vcc->stats->rx_drop);
73772 return NULL;
73773 }
73774 EXPORT_SYMBOL(atm_alloc_charge);
73775 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
73776
73777 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
73778 {
73779 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
73780 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
73781 __SONET_ITEMS
73782 #undef __HANDLE_ITEM
73783 }
73784 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
73785
73786 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
73787 {
73788 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
73789 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
73790 __SONET_ITEMS
73791 #undef __HANDLE_ITEM
73792 }
73793 diff --git a/net/atm/lec.h b/net/atm/lec.h
73794 index dfc0719..47c5322 100644
73795 --- a/net/atm/lec.h
73796 +++ b/net/atm/lec.h
73797 @@ -48,7 +48,7 @@ struct lane2_ops {
73798 const u8 *tlvs, u32 sizeoftlvs);
73799 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
73800 const u8 *tlvs, u32 sizeoftlvs);
73801 -};
73802 +} __no_const;
73803
73804 /*
73805 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
73806 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
73807 index 0919a88..a23d54e 100644
73808 --- a/net/atm/mpc.h
73809 +++ b/net/atm/mpc.h
73810 @@ -33,7 +33,7 @@ struct mpoa_client {
73811 struct mpc_parameters parameters; /* parameters for this client */
73812
73813 const struct net_device_ops *old_ops;
73814 - struct net_device_ops new_ops;
73815 + net_device_ops_no_const new_ops;
73816 };
73817
73818
73819 diff --git a/net/atm/proc.c b/net/atm/proc.c
73820 index 0d020de..011c7bb 100644
73821 --- a/net/atm/proc.c
73822 +++ b/net/atm/proc.c
73823 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
73824 const struct k_atm_aal_stats *stats)
73825 {
73826 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
73827 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
73828 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
73829 - atomic_read(&stats->rx_drop));
73830 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
73831 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
73832 + atomic_read_unchecked(&stats->rx_drop));
73833 }
73834
73835 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
73836 diff --git a/net/atm/resources.c b/net/atm/resources.c
73837 index 23f45ce..c748f1a 100644
73838 --- a/net/atm/resources.c
73839 +++ b/net/atm/resources.c
73840 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
73841 static void copy_aal_stats(struct k_atm_aal_stats *from,
73842 struct atm_aal_stats *to)
73843 {
73844 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
73845 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
73846 __AAL_STAT_ITEMS
73847 #undef __HANDLE_ITEM
73848 }
73849 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
73850 static void subtract_aal_stats(struct k_atm_aal_stats *from,
73851 struct atm_aal_stats *to)
73852 {
73853 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
73854 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
73855 __AAL_STAT_ITEMS
73856 #undef __HANDLE_ITEM
73857 }
73858 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
73859 index a6d5d63..1cc6c2b 100644
73860 --- a/net/batman-adv/bat_iv_ogm.c
73861 +++ b/net/batman-adv/bat_iv_ogm.c
73862 @@ -539,7 +539,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
73863
73864 /* change sequence number to network order */
73865 batman_ogm_packet->seqno =
73866 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
73867 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
73868
73869 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
73870 batman_ogm_packet->tt_crc = htons((uint16_t)
73871 @@ -559,7 +559,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
73872 else
73873 batman_ogm_packet->gw_flags = NO_FLAGS;
73874
73875 - atomic_inc(&hard_iface->seqno);
73876 + atomic_inc_unchecked(&hard_iface->seqno);
73877
73878 slide_own_bcast_window(hard_iface);
73879 bat_iv_ogm_queue_add(bat_priv, hard_iface->packet_buff,
73880 @@ -917,7 +917,7 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
73881 return;
73882
73883 /* could be changed by schedule_own_packet() */
73884 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
73885 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
73886
73887 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
73888
73889 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
73890 index 3778977..f6a9450 100644
73891 --- a/net/batman-adv/hard-interface.c
73892 +++ b/net/batman-adv/hard-interface.c
73893 @@ -328,8 +328,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
73894 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
73895 dev_add_pack(&hard_iface->batman_adv_ptype);
73896
73897 - atomic_set(&hard_iface->seqno, 1);
73898 - atomic_set(&hard_iface->frag_seqno, 1);
73899 + atomic_set_unchecked(&hard_iface->seqno, 1);
73900 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
73901 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
73902 hard_iface->net_dev->name);
73903
73904 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
73905 index a5590f4..8d31969 100644
73906 --- a/net/batman-adv/soft-interface.c
73907 +++ b/net/batman-adv/soft-interface.c
73908 @@ -645,7 +645,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
73909
73910 /* set broadcast sequence number */
73911 bcast_packet->seqno =
73912 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
73913 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
73914
73915 add_bcast_packet_to_list(bat_priv, skb, 1);
73916
73917 @@ -841,7 +841,7 @@ struct net_device *softif_create(const char *name)
73918 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
73919
73920 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
73921 - atomic_set(&bat_priv->bcast_seqno, 1);
73922 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
73923 atomic_set(&bat_priv->ttvn, 0);
73924 atomic_set(&bat_priv->tt_local_changes, 0);
73925 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
73926 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
73927 index 302efb5..1590365 100644
73928 --- a/net/batman-adv/types.h
73929 +++ b/net/batman-adv/types.h
73930 @@ -38,8 +38,8 @@ struct hard_iface {
73931 int16_t if_num;
73932 char if_status;
73933 struct net_device *net_dev;
73934 - atomic_t seqno;
73935 - atomic_t frag_seqno;
73936 + atomic_unchecked_t seqno;
73937 + atomic_unchecked_t frag_seqno;
73938 unsigned char *packet_buff;
73939 int packet_len;
73940 struct kobject *hardif_obj;
73941 @@ -155,7 +155,7 @@ struct bat_priv {
73942 atomic_t orig_interval; /* uint */
73943 atomic_t hop_penalty; /* uint */
73944 atomic_t log_level; /* uint */
73945 - atomic_t bcast_seqno;
73946 + atomic_unchecked_t bcast_seqno;
73947 atomic_t bcast_queue_left;
73948 atomic_t batman_queue_left;
73949 atomic_t ttvn; /* translation table version number */
73950 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
73951 index 676f6a6..3b4e668 100644
73952 --- a/net/batman-adv/unicast.c
73953 +++ b/net/batman-adv/unicast.c
73954 @@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
73955 frag1->flags = UNI_FRAG_HEAD | large_tail;
73956 frag2->flags = large_tail;
73957
73958 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
73959 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
73960 frag1->seqno = htons(seqno - 1);
73961 frag2->seqno = htons(seqno);
73962
73963 diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
73964 index 5238b6b..c9798ce 100644
73965 --- a/net/bluetooth/hci_conn.c
73966 +++ b/net/bluetooth/hci_conn.c
73967 @@ -233,7 +233,7 @@ void hci_le_ltk_reply(struct hci_conn *conn, u8 ltk[16])
73968 memset(&cp, 0, sizeof(cp));
73969
73970 cp.handle = cpu_to_le16(conn->handle);
73971 - memcpy(cp.ltk, ltk, sizeof(ltk));
73972 + memcpy(cp.ltk, ltk, sizeof(cp.ltk));
73973
73974 hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
73975 }
73976 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
73977 index 6f9c25b..d19fd66 100644
73978 --- a/net/bluetooth/l2cap_core.c
73979 +++ b/net/bluetooth/l2cap_core.c
73980 @@ -2466,8 +2466,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
73981 break;
73982
73983 case L2CAP_CONF_RFC:
73984 - if (olen == sizeof(rfc))
73985 - memcpy(&rfc, (void *)val, olen);
73986 + if (olen != sizeof(rfc))
73987 + break;
73988 +
73989 + memcpy(&rfc, (void *)val, olen);
73990
73991 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
73992 rfc.mode != chan->mode)
73993 @@ -2585,8 +2587,10 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
73994
73995 switch (type) {
73996 case L2CAP_CONF_RFC:
73997 - if (olen == sizeof(rfc))
73998 - memcpy(&rfc, (void *)val, olen);
73999 + if (olen != sizeof(rfc))
74000 + break;
74001 +
74002 + memcpy(&rfc, (void *)val, olen);
74003 goto done;
74004 }
74005 }
74006 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
74007 index 5fe2ff3..10968b5 100644
74008 --- a/net/bridge/netfilter/ebtables.c
74009 +++ b/net/bridge/netfilter/ebtables.c
74010 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
74011 tmp.valid_hooks = t->table->valid_hooks;
74012 }
74013 mutex_unlock(&ebt_mutex);
74014 - if (copy_to_user(user, &tmp, *len) != 0){
74015 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
74016 BUGPRINT("c2u Didn't work\n");
74017 ret = -EFAULT;
74018 break;
74019 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
74020 index 5cf5222..6f704ad 100644
74021 --- a/net/caif/cfctrl.c
74022 +++ b/net/caif/cfctrl.c
74023 @@ -9,6 +9,7 @@
74024 #include <linux/stddef.h>
74025 #include <linux/spinlock.h>
74026 #include <linux/slab.h>
74027 +#include <linux/sched.h>
74028 #include <net/caif/caif_layer.h>
74029 #include <net/caif/cfpkt.h>
74030 #include <net/caif/cfctrl.h>
74031 @@ -42,8 +43,8 @@ struct cflayer *cfctrl_create(void)
74032 memset(&dev_info, 0, sizeof(dev_info));
74033 dev_info.id = 0xff;
74034 cfsrvl_init(&this->serv, 0, &dev_info, false);
74035 - atomic_set(&this->req_seq_no, 1);
74036 - atomic_set(&this->rsp_seq_no, 1);
74037 + atomic_set_unchecked(&this->req_seq_no, 1);
74038 + atomic_set_unchecked(&this->rsp_seq_no, 1);
74039 this->serv.layer.receive = cfctrl_recv;
74040 sprintf(this->serv.layer.name, "ctrl");
74041 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
74042 @@ -129,8 +130,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
74043 struct cfctrl_request_info *req)
74044 {
74045 spin_lock_bh(&ctrl->info_list_lock);
74046 - atomic_inc(&ctrl->req_seq_no);
74047 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
74048 + atomic_inc_unchecked(&ctrl->req_seq_no);
74049 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
74050 list_add_tail(&req->list, &ctrl->list);
74051 spin_unlock_bh(&ctrl->info_list_lock);
74052 }
74053 @@ -148,7 +149,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
74054 if (p != first)
74055 pr_warn("Requests are not received in order\n");
74056
74057 - atomic_set(&ctrl->rsp_seq_no,
74058 + atomic_set_unchecked(&ctrl->rsp_seq_no,
74059 p->sequence_no);
74060 list_del(&p->list);
74061 goto out;
74062 diff --git a/net/can/gw.c b/net/can/gw.c
74063 index 3d79b12..8de85fa 100644
74064 --- a/net/can/gw.c
74065 +++ b/net/can/gw.c
74066 @@ -96,7 +96,7 @@ struct cf_mod {
74067 struct {
74068 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
74069 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
74070 - } csumfunc;
74071 + } __no_const csumfunc;
74072 };
74073
74074
74075 diff --git a/net/compat.c b/net/compat.c
74076 index e055708..3f80795 100644
74077 --- a/net/compat.c
74078 +++ b/net/compat.c
74079 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
74080 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
74081 __get_user(kmsg->msg_flags, &umsg->msg_flags))
74082 return -EFAULT;
74083 - kmsg->msg_name = compat_ptr(tmp1);
74084 - kmsg->msg_iov = compat_ptr(tmp2);
74085 - kmsg->msg_control = compat_ptr(tmp3);
74086 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
74087 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
74088 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
74089 return 0;
74090 }
74091
74092 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74093
74094 if (kern_msg->msg_namelen) {
74095 if (mode == VERIFY_READ) {
74096 - int err = move_addr_to_kernel(kern_msg->msg_name,
74097 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
74098 kern_msg->msg_namelen,
74099 kern_address);
74100 if (err < 0)
74101 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74102 kern_msg->msg_name = NULL;
74103
74104 tot_len = iov_from_user_compat_to_kern(kern_iov,
74105 - (struct compat_iovec __user *)kern_msg->msg_iov,
74106 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
74107 kern_msg->msg_iovlen);
74108 if (tot_len >= 0)
74109 kern_msg->msg_iov = kern_iov;
74110 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74111
74112 #define CMSG_COMPAT_FIRSTHDR(msg) \
74113 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
74114 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
74115 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
74116 (struct compat_cmsghdr __user *)NULL)
74117
74118 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
74119 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
74120 (ucmlen) <= (unsigned long) \
74121 ((mhdr)->msg_controllen - \
74122 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
74123 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
74124
74125 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
74126 struct compat_cmsghdr __user *cmsg, int cmsg_len)
74127 {
74128 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
74129 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
74130 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
74131 msg->msg_controllen)
74132 return NULL;
74133 return (struct compat_cmsghdr __user *)ptr;
74134 @@ -219,7 +219,7 @@ Efault:
74135
74136 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
74137 {
74138 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
74139 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
74140 struct compat_cmsghdr cmhdr;
74141 int cmlen;
74142
74143 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
74144
74145 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
74146 {
74147 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
74148 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
74149 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
74150 int fdnum = scm->fp->count;
74151 struct file **fp = scm->fp->fp;
74152 @@ -372,7 +372,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
74153 return -EFAULT;
74154 old_fs = get_fs();
74155 set_fs(KERNEL_DS);
74156 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
74157 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
74158 set_fs(old_fs);
74159
74160 return err;
74161 @@ -433,7 +433,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
74162 len = sizeof(ktime);
74163 old_fs = get_fs();
74164 set_fs(KERNEL_DS);
74165 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
74166 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
74167 set_fs(old_fs);
74168
74169 if (!err) {
74170 @@ -576,7 +576,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
74171 case MCAST_JOIN_GROUP:
74172 case MCAST_LEAVE_GROUP:
74173 {
74174 - struct compat_group_req __user *gr32 = (void *)optval;
74175 + struct compat_group_req __user *gr32 = (void __user *)optval;
74176 struct group_req __user *kgr =
74177 compat_alloc_user_space(sizeof(struct group_req));
74178 u32 interface;
74179 @@ -597,7 +597,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
74180 case MCAST_BLOCK_SOURCE:
74181 case MCAST_UNBLOCK_SOURCE:
74182 {
74183 - struct compat_group_source_req __user *gsr32 = (void *)optval;
74184 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
74185 struct group_source_req __user *kgsr = compat_alloc_user_space(
74186 sizeof(struct group_source_req));
74187 u32 interface;
74188 @@ -618,7 +618,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
74189 }
74190 case MCAST_MSFILTER:
74191 {
74192 - struct compat_group_filter __user *gf32 = (void *)optval;
74193 + struct compat_group_filter __user *gf32 = (void __user *)optval;
74194 struct group_filter __user *kgf;
74195 u32 interface, fmode, numsrc;
74196
74197 @@ -656,7 +656,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
74198 char __user *optval, int __user *optlen,
74199 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
74200 {
74201 - struct compat_group_filter __user *gf32 = (void *)optval;
74202 + struct compat_group_filter __user *gf32 = (void __user *)optval;
74203 struct group_filter __user *kgf;
74204 int __user *koptlen;
74205 u32 interface, fmode, numsrc;
74206 diff --git a/net/core/datagram.c b/net/core/datagram.c
74207 index e4fbfd6..6a6ac94 100644
74208 --- a/net/core/datagram.c
74209 +++ b/net/core/datagram.c
74210 @@ -290,7 +290,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
74211 }
74212
74213 kfree_skb(skb);
74214 - atomic_inc(&sk->sk_drops);
74215 + atomic_inc_unchecked(&sk->sk_drops);
74216 sk_mem_reclaim_partial(sk);
74217
74218 return err;
74219 diff --git a/net/core/dev.c b/net/core/dev.c
74220 index 99e1d75..adf968a 100644
74221 --- a/net/core/dev.c
74222 +++ b/net/core/dev.c
74223 @@ -1136,9 +1136,13 @@ void dev_load(struct net *net, const char *name)
74224 if (no_module && capable(CAP_NET_ADMIN))
74225 no_module = request_module("netdev-%s", name);
74226 if (no_module && capable(CAP_SYS_MODULE)) {
74227 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
74228 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
74229 +#else
74230 if (!request_module("%s", name))
74231 pr_err("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
74232 name);
74233 +#endif
74234 }
74235 }
74236 EXPORT_SYMBOL(dev_load);
74237 @@ -1602,7 +1606,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
74238 {
74239 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
74240 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
74241 - atomic_long_inc(&dev->rx_dropped);
74242 + atomic_long_inc_unchecked(&dev->rx_dropped);
74243 kfree_skb(skb);
74244 return NET_RX_DROP;
74245 }
74246 @@ -1612,7 +1616,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
74247 nf_reset(skb);
74248
74249 if (unlikely(!is_skb_forwardable(dev, skb))) {
74250 - atomic_long_inc(&dev->rx_dropped);
74251 + atomic_long_inc_unchecked(&dev->rx_dropped);
74252 kfree_skb(skb);
74253 return NET_RX_DROP;
74254 }
74255 @@ -2042,7 +2046,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
74256
74257 struct dev_gso_cb {
74258 void (*destructor)(struct sk_buff *skb);
74259 -};
74260 +} __no_const;
74261
74262 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
74263
74264 @@ -2898,7 +2902,7 @@ enqueue:
74265
74266 local_irq_restore(flags);
74267
74268 - atomic_long_inc(&skb->dev->rx_dropped);
74269 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
74270 kfree_skb(skb);
74271 return NET_RX_DROP;
74272 }
74273 @@ -2970,7 +2974,7 @@ int netif_rx_ni(struct sk_buff *skb)
74274 }
74275 EXPORT_SYMBOL(netif_rx_ni);
74276
74277 -static void net_tx_action(struct softirq_action *h)
74278 +static void net_tx_action(void)
74279 {
74280 struct softnet_data *sd = &__get_cpu_var(softnet_data);
74281
74282 @@ -3258,7 +3262,7 @@ ncls:
74283 if (pt_prev) {
74284 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
74285 } else {
74286 - atomic_long_inc(&skb->dev->rx_dropped);
74287 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
74288 kfree_skb(skb);
74289 /* Jamal, now you will not able to escape explaining
74290 * me how you were going to use this. :-)
74291 @@ -3818,7 +3822,7 @@ void netif_napi_del(struct napi_struct *napi)
74292 }
74293 EXPORT_SYMBOL(netif_napi_del);
74294
74295 -static void net_rx_action(struct softirq_action *h)
74296 +static void net_rx_action(void)
74297 {
74298 struct softnet_data *sd = &__get_cpu_var(softnet_data);
74299 unsigned long time_limit = jiffies + 2;
74300 @@ -4288,8 +4292,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
74301 else
74302 seq_printf(seq, "%04x", ntohs(pt->type));
74303
74304 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74305 + seq_printf(seq, " %-8s %p\n",
74306 + pt->dev ? pt->dev->name : "", NULL);
74307 +#else
74308 seq_printf(seq, " %-8s %pF\n",
74309 pt->dev ? pt->dev->name : "", pt->func);
74310 +#endif
74311 }
74312
74313 return 0;
74314 @@ -5839,7 +5848,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
74315 } else {
74316 netdev_stats_to_stats64(storage, &dev->stats);
74317 }
74318 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
74319 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
74320 return storage;
74321 }
74322 EXPORT_SYMBOL(dev_get_stats);
74323 diff --git a/net/core/flow.c b/net/core/flow.c
74324 index e318c7e..168b1d0 100644
74325 --- a/net/core/flow.c
74326 +++ b/net/core/flow.c
74327 @@ -61,7 +61,7 @@ struct flow_cache {
74328 struct timer_list rnd_timer;
74329 };
74330
74331 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
74332 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
74333 EXPORT_SYMBOL(flow_cache_genid);
74334 static struct flow_cache flow_cache_global;
74335 static struct kmem_cache *flow_cachep __read_mostly;
74336 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
74337
74338 static int flow_entry_valid(struct flow_cache_entry *fle)
74339 {
74340 - if (atomic_read(&flow_cache_genid) != fle->genid)
74341 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
74342 return 0;
74343 if (fle->object && !fle->object->ops->check(fle->object))
74344 return 0;
74345 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
74346 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
74347 fcp->hash_count++;
74348 }
74349 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
74350 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
74351 flo = fle->object;
74352 if (!flo)
74353 goto ret_object;
74354 @@ -280,7 +280,7 @@ nocache:
74355 }
74356 flo = resolver(net, key, family, dir, flo, ctx);
74357 if (fle) {
74358 - fle->genid = atomic_read(&flow_cache_genid);
74359 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
74360 if (!IS_ERR(flo))
74361 fle->object = flo;
74362 else
74363 diff --git a/net/core/iovec.c b/net/core/iovec.c
74364 index 7e7aeb0..2a998cb 100644
74365 --- a/net/core/iovec.c
74366 +++ b/net/core/iovec.c
74367 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
74368 if (m->msg_namelen) {
74369 if (mode == VERIFY_READ) {
74370 void __user *namep;
74371 - namep = (void __user __force *) m->msg_name;
74372 + namep = (void __force_user *) m->msg_name;
74373 err = move_addr_to_kernel(namep, m->msg_namelen,
74374 address);
74375 if (err < 0)
74376 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
74377 }
74378
74379 size = m->msg_iovlen * sizeof(struct iovec);
74380 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
74381 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
74382 return -EFAULT;
74383
74384 m->msg_iov = iov;
74385 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
74386 index 90430b7..0032ec0 100644
74387 --- a/net/core/rtnetlink.c
74388 +++ b/net/core/rtnetlink.c
74389 @@ -56,7 +56,7 @@ struct rtnl_link {
74390 rtnl_doit_func doit;
74391 rtnl_dumpit_func dumpit;
74392 rtnl_calcit_func calcit;
74393 -};
74394 +} __no_const;
74395
74396 static DEFINE_MUTEX(rtnl_mutex);
74397
74398 diff --git a/net/core/scm.c b/net/core/scm.c
74399 index 611c5ef..88f6d6d 100644
74400 --- a/net/core/scm.c
74401 +++ b/net/core/scm.c
74402 @@ -219,7 +219,7 @@ EXPORT_SYMBOL(__scm_send);
74403 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
74404 {
74405 struct cmsghdr __user *cm
74406 - = (__force struct cmsghdr __user *)msg->msg_control;
74407 + = (struct cmsghdr __force_user *)msg->msg_control;
74408 struct cmsghdr cmhdr;
74409 int cmlen = CMSG_LEN(len);
74410 int err;
74411 @@ -242,7 +242,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
74412 err = -EFAULT;
74413 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
74414 goto out;
74415 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
74416 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
74417 goto out;
74418 cmlen = CMSG_SPACE(len);
74419 if (msg->msg_controllen < cmlen)
74420 @@ -258,7 +258,7 @@ EXPORT_SYMBOL(put_cmsg);
74421 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
74422 {
74423 struct cmsghdr __user *cm
74424 - = (__force struct cmsghdr __user*)msg->msg_control;
74425 + = (struct cmsghdr __force_user *)msg->msg_control;
74426
74427 int fdmax = 0;
74428 int fdnum = scm->fp->count;
74429 @@ -278,7 +278,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
74430 if (fdnum < fdmax)
74431 fdmax = fdnum;
74432
74433 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
74434 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
74435 i++, cmfptr++)
74436 {
74437 int new_fd;
74438 diff --git a/net/core/sock.c b/net/core/sock.c
74439 index b2e14c0..6651b32 100644
74440 --- a/net/core/sock.c
74441 +++ b/net/core/sock.c
74442 @@ -340,7 +340,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74443 struct sk_buff_head *list = &sk->sk_receive_queue;
74444
74445 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
74446 - atomic_inc(&sk->sk_drops);
74447 + atomic_inc_unchecked(&sk->sk_drops);
74448 trace_sock_rcvqueue_full(sk, skb);
74449 return -ENOMEM;
74450 }
74451 @@ -350,7 +350,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74452 return err;
74453
74454 if (!sk_rmem_schedule(sk, skb->truesize)) {
74455 - atomic_inc(&sk->sk_drops);
74456 + atomic_inc_unchecked(&sk->sk_drops);
74457 return -ENOBUFS;
74458 }
74459
74460 @@ -370,7 +370,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74461 skb_dst_force(skb);
74462
74463 spin_lock_irqsave(&list->lock, flags);
74464 - skb->dropcount = atomic_read(&sk->sk_drops);
74465 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
74466 __skb_queue_tail(list, skb);
74467 spin_unlock_irqrestore(&list->lock, flags);
74468
74469 @@ -390,7 +390,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
74470 skb->dev = NULL;
74471
74472 if (sk_rcvqueues_full(sk, skb)) {
74473 - atomic_inc(&sk->sk_drops);
74474 + atomic_inc_unchecked(&sk->sk_drops);
74475 goto discard_and_relse;
74476 }
74477 if (nested)
74478 @@ -408,7 +408,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
74479 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
74480 } else if (sk_add_backlog(sk, skb)) {
74481 bh_unlock_sock(sk);
74482 - atomic_inc(&sk->sk_drops);
74483 + atomic_inc_unchecked(&sk->sk_drops);
74484 goto discard_and_relse;
74485 }
74486
74487 @@ -984,7 +984,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
74488 if (len > sizeof(peercred))
74489 len = sizeof(peercred);
74490 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
74491 - if (copy_to_user(optval, &peercred, len))
74492 + if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
74493 return -EFAULT;
74494 goto lenout;
74495 }
74496 @@ -997,7 +997,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
74497 return -ENOTCONN;
74498 if (lv < len)
74499 return -EINVAL;
74500 - if (copy_to_user(optval, address, len))
74501 + if (len > sizeof(address) || copy_to_user(optval, address, len))
74502 return -EFAULT;
74503 goto lenout;
74504 }
74505 @@ -1043,7 +1043,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
74506
74507 if (len > lv)
74508 len = lv;
74509 - if (copy_to_user(optval, &v, len))
74510 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
74511 return -EFAULT;
74512 lenout:
74513 if (put_user(len, optlen))
74514 @@ -2128,7 +2128,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
74515 */
74516 smp_wmb();
74517 atomic_set(&sk->sk_refcnt, 1);
74518 - atomic_set(&sk->sk_drops, 0);
74519 + atomic_set_unchecked(&sk->sk_drops, 0);
74520 }
74521 EXPORT_SYMBOL(sock_init_data);
74522
74523 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
74524 index b9868e1..849f809 100644
74525 --- a/net/core/sock_diag.c
74526 +++ b/net/core/sock_diag.c
74527 @@ -16,20 +16,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
74528
74529 int sock_diag_check_cookie(void *sk, __u32 *cookie)
74530 {
74531 +#ifndef CONFIG_GRKERNSEC_HIDESYM
74532 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
74533 cookie[1] != INET_DIAG_NOCOOKIE) &&
74534 ((u32)(unsigned long)sk != cookie[0] ||
74535 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
74536 return -ESTALE;
74537 else
74538 +#endif
74539 return 0;
74540 }
74541 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
74542
74543 void sock_diag_save_cookie(void *sk, __u32 *cookie)
74544 {
74545 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74546 + cookie[0] = 0;
74547 + cookie[1] = 0;
74548 +#else
74549 cookie[0] = (u32)(unsigned long)sk;
74550 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
74551 +#endif
74552 }
74553 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
74554
74555 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
74556 index 02e75d1..9a57a7c 100644
74557 --- a/net/decnet/sysctl_net_decnet.c
74558 +++ b/net/decnet/sysctl_net_decnet.c
74559 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
74560
74561 if (len > *lenp) len = *lenp;
74562
74563 - if (copy_to_user(buffer, addr, len))
74564 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
74565 return -EFAULT;
74566
74567 *lenp = len;
74568 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
74569
74570 if (len > *lenp) len = *lenp;
74571
74572 - if (copy_to_user(buffer, devname, len))
74573 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
74574 return -EFAULT;
74575
74576 *lenp = len;
74577 diff --git a/net/econet/Kconfig b/net/econet/Kconfig
74578 index 39a2d29..f39c0fe 100644
74579 --- a/net/econet/Kconfig
74580 +++ b/net/econet/Kconfig
74581 @@ -4,7 +4,7 @@
74582
74583 config ECONET
74584 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
74585 - depends on EXPERIMENTAL && INET
74586 + depends on EXPERIMENTAL && INET && BROKEN
74587 ---help---
74588 Econet is a fairly old and slow networking protocol mainly used by
74589 Acorn computers to access file and print servers. It uses native
74590 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
74591 index cbe3a68..a879b75 100644
74592 --- a/net/ipv4/fib_frontend.c
74593 +++ b/net/ipv4/fib_frontend.c
74594 @@ -969,12 +969,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
74595 #ifdef CONFIG_IP_ROUTE_MULTIPATH
74596 fib_sync_up(dev);
74597 #endif
74598 - atomic_inc(&net->ipv4.dev_addr_genid);
74599 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
74600 rt_cache_flush(dev_net(dev), -1);
74601 break;
74602 case NETDEV_DOWN:
74603 fib_del_ifaddr(ifa, NULL);
74604 - atomic_inc(&net->ipv4.dev_addr_genid);
74605 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
74606 if (ifa->ifa_dev->ifa_list == NULL) {
74607 /* Last address was deleted from this interface.
74608 * Disable IP.
74609 @@ -1010,7 +1010,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
74610 #ifdef CONFIG_IP_ROUTE_MULTIPATH
74611 fib_sync_up(dev);
74612 #endif
74613 - atomic_inc(&net->ipv4.dev_addr_genid);
74614 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
74615 rt_cache_flush(dev_net(dev), -1);
74616 break;
74617 case NETDEV_DOWN:
74618 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
74619 index 8861f91..ab1e3c1 100644
74620 --- a/net/ipv4/fib_semantics.c
74621 +++ b/net/ipv4/fib_semantics.c
74622 @@ -698,7 +698,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
74623 nh->nh_saddr = inet_select_addr(nh->nh_dev,
74624 nh->nh_gw,
74625 nh->nh_parent->fib_scope);
74626 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
74627 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
74628
74629 return nh->nh_saddr;
74630 }
74631 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
74632 index 984ec65..97ac518 100644
74633 --- a/net/ipv4/inet_hashtables.c
74634 +++ b/net/ipv4/inet_hashtables.c
74635 @@ -18,12 +18,15 @@
74636 #include <linux/sched.h>
74637 #include <linux/slab.h>
74638 #include <linux/wait.h>
74639 +#include <linux/security.h>
74640
74641 #include <net/inet_connection_sock.h>
74642 #include <net/inet_hashtables.h>
74643 #include <net/secure_seq.h>
74644 #include <net/ip.h>
74645
74646 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
74647 +
74648 /*
74649 * Allocate and initialize a new local port bind bucket.
74650 * The bindhash mutex for snum's hash chain must be held here.
74651 @@ -530,6 +533,8 @@ ok:
74652 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
74653 spin_unlock(&head->lock);
74654
74655 + gr_update_task_in_ip_table(current, inet_sk(sk));
74656 +
74657 if (tw) {
74658 inet_twsk_deschedule(tw, death_row);
74659 while (twrefcnt) {
74660 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
74661 index d4d61b6..b81aec8 100644
74662 --- a/net/ipv4/inetpeer.c
74663 +++ b/net/ipv4/inetpeer.c
74664 @@ -487,8 +487,8 @@ relookup:
74665 if (p) {
74666 p->daddr = *daddr;
74667 atomic_set(&p->refcnt, 1);
74668 - atomic_set(&p->rid, 0);
74669 - atomic_set(&p->ip_id_count,
74670 + atomic_set_unchecked(&p->rid, 0);
74671 + atomic_set_unchecked(&p->ip_id_count,
74672 (daddr->family == AF_INET) ?
74673 secure_ip_id(daddr->addr.a4) :
74674 secure_ipv6_id(daddr->addr.a6));
74675 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
74676 index 3727e23..517f5df 100644
74677 --- a/net/ipv4/ip_fragment.c
74678 +++ b/net/ipv4/ip_fragment.c
74679 @@ -318,7 +318,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
74680 return 0;
74681
74682 start = qp->rid;
74683 - end = atomic_inc_return(&peer->rid);
74684 + end = atomic_inc_return_unchecked(&peer->rid);
74685 qp->rid = end;
74686
74687 rc = qp->q.fragments && (end - start) > max;
74688 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
74689 index 2fd0fba..83fac99 100644
74690 --- a/net/ipv4/ip_sockglue.c
74691 +++ b/net/ipv4/ip_sockglue.c
74692 @@ -1137,7 +1137,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
74693 len = min_t(unsigned int, len, opt->optlen);
74694 if (put_user(len, optlen))
74695 return -EFAULT;
74696 - if (copy_to_user(optval, opt->__data, len))
74697 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
74698 + copy_to_user(optval, opt->__data, len))
74699 return -EFAULT;
74700 return 0;
74701 }
74702 @@ -1268,7 +1269,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
74703 if (sk->sk_type != SOCK_STREAM)
74704 return -ENOPROTOOPT;
74705
74706 - msg.msg_control = optval;
74707 + msg.msg_control = (void __force_kernel *)optval;
74708 msg.msg_controllen = len;
74709 msg.msg_flags = flags;
74710
74711 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
74712 index 92ac7e7..13f93d9 100644
74713 --- a/net/ipv4/ipconfig.c
74714 +++ b/net/ipv4/ipconfig.c
74715 @@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
74716
74717 mm_segment_t oldfs = get_fs();
74718 set_fs(get_ds());
74719 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
74720 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
74721 set_fs(oldfs);
74722 return res;
74723 }
74724 @@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
74725
74726 mm_segment_t oldfs = get_fs();
74727 set_fs(get_ds());
74728 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
74729 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
74730 set_fs(oldfs);
74731 return res;
74732 }
74733 @@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
74734
74735 mm_segment_t oldfs = get_fs();
74736 set_fs(get_ds());
74737 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
74738 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
74739 set_fs(oldfs);
74740 return res;
74741 }
74742 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
74743 index 50009c7..5996a9f 100644
74744 --- a/net/ipv4/ping.c
74745 +++ b/net/ipv4/ping.c
74746 @@ -838,7 +838,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
74747 sk_rmem_alloc_get(sp),
74748 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
74749 atomic_read(&sp->sk_refcnt), sp,
74750 - atomic_read(&sp->sk_drops), len);
74751 + atomic_read_unchecked(&sp->sk_drops), len);
74752 }
74753
74754 static int ping_seq_show(struct seq_file *seq, void *v)
74755 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
74756 index bbd604c..4d5469c 100644
74757 --- a/net/ipv4/raw.c
74758 +++ b/net/ipv4/raw.c
74759 @@ -304,7 +304,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
74760 int raw_rcv(struct sock *sk, struct sk_buff *skb)
74761 {
74762 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
74763 - atomic_inc(&sk->sk_drops);
74764 + atomic_inc_unchecked(&sk->sk_drops);
74765 kfree_skb(skb);
74766 return NET_RX_DROP;
74767 }
74768 @@ -740,16 +740,20 @@ static int raw_init(struct sock *sk)
74769
74770 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
74771 {
74772 + struct icmp_filter filter;
74773 +
74774 if (optlen > sizeof(struct icmp_filter))
74775 optlen = sizeof(struct icmp_filter);
74776 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
74777 + if (copy_from_user(&filter, optval, optlen))
74778 return -EFAULT;
74779 + raw_sk(sk)->filter = filter;
74780 return 0;
74781 }
74782
74783 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
74784 {
74785 int len, ret = -EFAULT;
74786 + struct icmp_filter filter;
74787
74788 if (get_user(len, optlen))
74789 goto out;
74790 @@ -759,8 +763,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
74791 if (len > sizeof(struct icmp_filter))
74792 len = sizeof(struct icmp_filter);
74793 ret = -EFAULT;
74794 - if (put_user(len, optlen) ||
74795 - copy_to_user(optval, &raw_sk(sk)->filter, len))
74796 + filter = raw_sk(sk)->filter;
74797 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
74798 goto out;
74799 ret = 0;
74800 out: return ret;
74801 @@ -988,7 +992,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
74802 sk_wmem_alloc_get(sp),
74803 sk_rmem_alloc_get(sp),
74804 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
74805 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
74806 + atomic_read(&sp->sk_refcnt),
74807 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74808 + NULL,
74809 +#else
74810 + sp,
74811 +#endif
74812 + atomic_read_unchecked(&sp->sk_drops));
74813 }
74814
74815 static int raw_seq_show(struct seq_file *seq, void *v)
74816 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
74817 index 167ea10..4b15883 100644
74818 --- a/net/ipv4/route.c
74819 +++ b/net/ipv4/route.c
74820 @@ -312,7 +312,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
74821
74822 static inline int rt_genid(struct net *net)
74823 {
74824 - return atomic_read(&net->ipv4.rt_genid);
74825 + return atomic_read_unchecked(&net->ipv4.rt_genid);
74826 }
74827
74828 #ifdef CONFIG_PROC_FS
74829 @@ -936,7 +936,7 @@ static void rt_cache_invalidate(struct net *net)
74830 unsigned char shuffle;
74831
74832 get_random_bytes(&shuffle, sizeof(shuffle));
74833 - atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
74834 + atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
74835 inetpeer_invalidate_tree(AF_INET);
74836 }
74837
74838 @@ -3009,7 +3009,7 @@ static int rt_fill_info(struct net *net,
74839 error = rt->dst.error;
74840 if (peer) {
74841 inet_peer_refcheck(rt->peer);
74842 - id = atomic_read(&peer->ip_id_count) & 0xffff;
74843 + id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
74844 if (peer->tcp_ts_stamp) {
74845 ts = peer->tcp_ts;
74846 tsage = get_seconds() - peer->tcp_ts_stamp;
74847 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
74848 index 0cb86ce..8e7fda8 100644
74849 --- a/net/ipv4/tcp_ipv4.c
74850 +++ b/net/ipv4/tcp_ipv4.c
74851 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
74852 EXPORT_SYMBOL(sysctl_tcp_low_latency);
74853
74854
74855 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74856 +extern int grsec_enable_blackhole;
74857 +#endif
74858 +
74859 #ifdef CONFIG_TCP_MD5SIG
74860 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
74861 __be32 daddr, __be32 saddr, const struct tcphdr *th);
74862 @@ -1641,6 +1645,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
74863 return 0;
74864
74865 reset:
74866 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74867 + if (!grsec_enable_blackhole)
74868 +#endif
74869 tcp_v4_send_reset(rsk, skb);
74870 discard:
74871 kfree_skb(skb);
74872 @@ -1703,12 +1710,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
74873 TCP_SKB_CB(skb)->sacked = 0;
74874
74875 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
74876 - if (!sk)
74877 + if (!sk) {
74878 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74879 + ret = 1;
74880 +#endif
74881 goto no_tcp_socket;
74882 -
74883 + }
74884 process:
74885 - if (sk->sk_state == TCP_TIME_WAIT)
74886 + if (sk->sk_state == TCP_TIME_WAIT) {
74887 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74888 + ret = 2;
74889 +#endif
74890 goto do_time_wait;
74891 + }
74892
74893 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
74894 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
74895 @@ -1758,6 +1772,10 @@ no_tcp_socket:
74896 bad_packet:
74897 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
74898 } else {
74899 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74900 + if (!grsec_enable_blackhole || (ret == 1 &&
74901 + (skb->dev->flags & IFF_LOOPBACK)))
74902 +#endif
74903 tcp_v4_send_reset(NULL, skb);
74904 }
74905
74906 @@ -2419,7 +2437,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
74907 0, /* non standard timer */
74908 0, /* open_requests have no inode */
74909 atomic_read(&sk->sk_refcnt),
74910 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74911 + NULL,
74912 +#else
74913 req,
74914 +#endif
74915 len);
74916 }
74917
74918 @@ -2469,7 +2491,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
74919 sock_i_uid(sk),
74920 icsk->icsk_probes_out,
74921 sock_i_ino(sk),
74922 - atomic_read(&sk->sk_refcnt), sk,
74923 + atomic_read(&sk->sk_refcnt),
74924 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74925 + NULL,
74926 +#else
74927 + sk,
74928 +#endif
74929 jiffies_to_clock_t(icsk->icsk_rto),
74930 jiffies_to_clock_t(icsk->icsk_ack.ato),
74931 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
74932 @@ -2497,7 +2524,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
74933 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
74934 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
74935 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
74936 - atomic_read(&tw->tw_refcnt), tw, len);
74937 + atomic_read(&tw->tw_refcnt),
74938 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74939 + NULL,
74940 +#else
74941 + tw,
74942 +#endif
74943 + len);
74944 }
74945
74946 #define TMPSZ 150
74947 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
74948 index 3cabafb..640525b 100644
74949 --- a/net/ipv4/tcp_minisocks.c
74950 +++ b/net/ipv4/tcp_minisocks.c
74951 @@ -27,6 +27,10 @@
74952 #include <net/inet_common.h>
74953 #include <net/xfrm.h>
74954
74955 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74956 +extern int grsec_enable_blackhole;
74957 +#endif
74958 +
74959 int sysctl_tcp_syncookies __read_mostly = 1;
74960 EXPORT_SYMBOL(sysctl_tcp_syncookies);
74961
74962 @@ -753,6 +757,10 @@ listen_overflow:
74963
74964 embryonic_reset:
74965 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
74966 +
74967 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74968 + if (!grsec_enable_blackhole)
74969 +#endif
74970 if (!(flg & TCP_FLAG_RST))
74971 req->rsk_ops->send_reset(sk, skb);
74972
74973 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
74974 index a981cdc..48f4c3a 100644
74975 --- a/net/ipv4/tcp_probe.c
74976 +++ b/net/ipv4/tcp_probe.c
74977 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
74978 if (cnt + width >= len)
74979 break;
74980
74981 - if (copy_to_user(buf + cnt, tbuf, width))
74982 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
74983 return -EFAULT;
74984 cnt += width;
74985 }
74986 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
74987 index 34d4a02..3b57f86 100644
74988 --- a/net/ipv4/tcp_timer.c
74989 +++ b/net/ipv4/tcp_timer.c
74990 @@ -22,6 +22,10 @@
74991 #include <linux/gfp.h>
74992 #include <net/tcp.h>
74993
74994 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74995 +extern int grsec_lastack_retries;
74996 +#endif
74997 +
74998 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
74999 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
75000 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
75001 @@ -196,6 +200,13 @@ static int tcp_write_timeout(struct sock *sk)
75002 }
75003 }
75004
75005 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75006 + if ((sk->sk_state == TCP_LAST_ACK) &&
75007 + (grsec_lastack_retries > 0) &&
75008 + (grsec_lastack_retries < retry_until))
75009 + retry_until = grsec_lastack_retries;
75010 +#endif
75011 +
75012 if (retransmits_timed_out(sk, retry_until,
75013 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
75014 /* Has it gone just too far? */
75015 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
75016 index fe14105..0618260 100644
75017 --- a/net/ipv4/udp.c
75018 +++ b/net/ipv4/udp.c
75019 @@ -87,6 +87,7 @@
75020 #include <linux/types.h>
75021 #include <linux/fcntl.h>
75022 #include <linux/module.h>
75023 +#include <linux/security.h>
75024 #include <linux/socket.h>
75025 #include <linux/sockios.h>
75026 #include <linux/igmp.h>
75027 @@ -109,6 +110,10 @@
75028 #include <trace/events/udp.h>
75029 #include "udp_impl.h"
75030
75031 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75032 +extern int grsec_enable_blackhole;
75033 +#endif
75034 +
75035 struct udp_table udp_table __read_mostly;
75036 EXPORT_SYMBOL(udp_table);
75037
75038 @@ -567,6 +572,9 @@ found:
75039 return s;
75040 }
75041
75042 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
75043 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
75044 +
75045 /*
75046 * This routine is called by the ICMP module when it gets some
75047 * sort of error condition. If err < 0 then the socket should
75048 @@ -858,9 +866,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
75049 dport = usin->sin_port;
75050 if (dport == 0)
75051 return -EINVAL;
75052 +
75053 + err = gr_search_udp_sendmsg(sk, usin);
75054 + if (err)
75055 + return err;
75056 } else {
75057 if (sk->sk_state != TCP_ESTABLISHED)
75058 return -EDESTADDRREQ;
75059 +
75060 + err = gr_search_udp_sendmsg(sk, NULL);
75061 + if (err)
75062 + return err;
75063 +
75064 daddr = inet->inet_daddr;
75065 dport = inet->inet_dport;
75066 /* Open fast path for connected socket.
75067 @@ -1102,7 +1119,7 @@ static unsigned int first_packet_length(struct sock *sk)
75068 udp_lib_checksum_complete(skb)) {
75069 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
75070 IS_UDPLITE(sk));
75071 - atomic_inc(&sk->sk_drops);
75072 + atomic_inc_unchecked(&sk->sk_drops);
75073 __skb_unlink(skb, rcvq);
75074 __skb_queue_tail(&list_kill, skb);
75075 }
75076 @@ -1188,6 +1205,10 @@ try_again:
75077 if (!skb)
75078 goto out;
75079
75080 + err = gr_search_udp_recvmsg(sk, skb);
75081 + if (err)
75082 + goto out_free;
75083 +
75084 ulen = skb->len - sizeof(struct udphdr);
75085 copied = len;
75086 if (copied > ulen)
75087 @@ -1489,7 +1510,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75088
75089 drop:
75090 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
75091 - atomic_inc(&sk->sk_drops);
75092 + atomic_inc_unchecked(&sk->sk_drops);
75093 kfree_skb(skb);
75094 return -1;
75095 }
75096 @@ -1508,7 +1529,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
75097 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
75098
75099 if (!skb1) {
75100 - atomic_inc(&sk->sk_drops);
75101 + atomic_inc_unchecked(&sk->sk_drops);
75102 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
75103 IS_UDPLITE(sk));
75104 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
75105 @@ -1677,6 +1698,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
75106 goto csum_error;
75107
75108 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
75109 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75110 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
75111 +#endif
75112 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
75113
75114 /*
75115 @@ -2094,8 +2118,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
75116 sk_wmem_alloc_get(sp),
75117 sk_rmem_alloc_get(sp),
75118 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75119 - atomic_read(&sp->sk_refcnt), sp,
75120 - atomic_read(&sp->sk_drops), len);
75121 + atomic_read(&sp->sk_refcnt),
75122 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75123 + NULL,
75124 +#else
75125 + sp,
75126 +#endif
75127 + atomic_read_unchecked(&sp->sk_drops), len);
75128 }
75129
75130 int udp4_seq_show(struct seq_file *seq, void *v)
75131 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
75132 index 7d5cb97..c56564f 100644
75133 --- a/net/ipv6/addrconf.c
75134 +++ b/net/ipv6/addrconf.c
75135 @@ -2142,7 +2142,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
75136 p.iph.ihl = 5;
75137 p.iph.protocol = IPPROTO_IPV6;
75138 p.iph.ttl = 64;
75139 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
75140 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
75141
75142 if (ops->ndo_do_ioctl) {
75143 mm_segment_t oldfs = get_fs();
75144 diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
75145 index 02dd203..e03fcc9 100644
75146 --- a/net/ipv6/inet6_connection_sock.c
75147 +++ b/net/ipv6/inet6_connection_sock.c
75148 @@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
75149 #ifdef CONFIG_XFRM
75150 {
75151 struct rt6_info *rt = (struct rt6_info *)dst;
75152 - rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
75153 + rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
75154 }
75155 #endif
75156 }
75157 @@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
75158 #ifdef CONFIG_XFRM
75159 if (dst) {
75160 struct rt6_info *rt = (struct rt6_info *)dst;
75161 - if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
75162 + if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
75163 __sk_dst_reset(sk);
75164 dst = NULL;
75165 }
75166 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
75167 index 63dd1f8..e7f53ca 100644
75168 --- a/net/ipv6/ipv6_sockglue.c
75169 +++ b/net/ipv6/ipv6_sockglue.c
75170 @@ -990,7 +990,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
75171 if (sk->sk_type != SOCK_STREAM)
75172 return -ENOPROTOOPT;
75173
75174 - msg.msg_control = optval;
75175 + msg.msg_control = (void __force_kernel *)optval;
75176 msg.msg_controllen = len;
75177 msg.msg_flags = flags;
75178
75179 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
75180 index 5bddea7..82d9d67 100644
75181 --- a/net/ipv6/raw.c
75182 +++ b/net/ipv6/raw.c
75183 @@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
75184 {
75185 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
75186 skb_checksum_complete(skb)) {
75187 - atomic_inc(&sk->sk_drops);
75188 + atomic_inc_unchecked(&sk->sk_drops);
75189 kfree_skb(skb);
75190 return NET_RX_DROP;
75191 }
75192 @@ -405,7 +405,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
75193 struct raw6_sock *rp = raw6_sk(sk);
75194
75195 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
75196 - atomic_inc(&sk->sk_drops);
75197 + atomic_inc_unchecked(&sk->sk_drops);
75198 kfree_skb(skb);
75199 return NET_RX_DROP;
75200 }
75201 @@ -429,7 +429,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
75202
75203 if (inet->hdrincl) {
75204 if (skb_checksum_complete(skb)) {
75205 - atomic_inc(&sk->sk_drops);
75206 + atomic_inc_unchecked(&sk->sk_drops);
75207 kfree_skb(skb);
75208 return NET_RX_DROP;
75209 }
75210 @@ -602,7 +602,7 @@ out:
75211 return err;
75212 }
75213
75214 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
75215 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
75216 struct flowi6 *fl6, struct dst_entry **dstp,
75217 unsigned int flags)
75218 {
75219 @@ -914,12 +914,15 @@ do_confirm:
75220 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
75221 char __user *optval, int optlen)
75222 {
75223 + struct icmp6_filter filter;
75224 +
75225 switch (optname) {
75226 case ICMPV6_FILTER:
75227 if (optlen > sizeof(struct icmp6_filter))
75228 optlen = sizeof(struct icmp6_filter);
75229 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
75230 + if (copy_from_user(&filter, optval, optlen))
75231 return -EFAULT;
75232 + raw6_sk(sk)->filter = filter;
75233 return 0;
75234 default:
75235 return -ENOPROTOOPT;
75236 @@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
75237 char __user *optval, int __user *optlen)
75238 {
75239 int len;
75240 + struct icmp6_filter filter;
75241
75242 switch (optname) {
75243 case ICMPV6_FILTER:
75244 @@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
75245 len = sizeof(struct icmp6_filter);
75246 if (put_user(len, optlen))
75247 return -EFAULT;
75248 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
75249 + filter = raw6_sk(sk)->filter;
75250 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
75251 return -EFAULT;
75252 return 0;
75253 default:
75254 @@ -1250,7 +1255,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
75255 0, 0L, 0,
75256 sock_i_uid(sp), 0,
75257 sock_i_ino(sp),
75258 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
75259 + atomic_read(&sp->sk_refcnt),
75260 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75261 + NULL,
75262 +#else
75263 + sp,
75264 +#endif
75265 + atomic_read_unchecked(&sp->sk_drops));
75266 }
75267
75268 static int raw6_seq_show(struct seq_file *seq, void *v)
75269 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
75270 index 98256cf..7f16dbd 100644
75271 --- a/net/ipv6/tcp_ipv6.c
75272 +++ b/net/ipv6/tcp_ipv6.c
75273 @@ -94,6 +94,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
75274 }
75275 #endif
75276
75277 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75278 +extern int grsec_enable_blackhole;
75279 +#endif
75280 +
75281 static void tcp_v6_hash(struct sock *sk)
75282 {
75283 if (sk->sk_state != TCP_CLOSE) {
75284 @@ -1542,6 +1546,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
75285 return 0;
75286
75287 reset:
75288 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75289 + if (!grsec_enable_blackhole)
75290 +#endif
75291 tcp_v6_send_reset(sk, skb);
75292 discard:
75293 if (opt_skb)
75294 @@ -1623,12 +1630,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
75295 TCP_SKB_CB(skb)->sacked = 0;
75296
75297 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
75298 - if (!sk)
75299 + if (!sk) {
75300 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75301 + ret = 1;
75302 +#endif
75303 goto no_tcp_socket;
75304 + }
75305
75306 process:
75307 - if (sk->sk_state == TCP_TIME_WAIT)
75308 + if (sk->sk_state == TCP_TIME_WAIT) {
75309 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75310 + ret = 2;
75311 +#endif
75312 goto do_time_wait;
75313 + }
75314
75315 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
75316 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
75317 @@ -1676,6 +1691,10 @@ no_tcp_socket:
75318 bad_packet:
75319 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
75320 } else {
75321 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75322 + if (!grsec_enable_blackhole || (ret == 1 &&
75323 + (skb->dev->flags & IFF_LOOPBACK)))
75324 +#endif
75325 tcp_v6_send_reset(NULL, skb);
75326 }
75327
75328 @@ -1930,7 +1949,13 @@ static void get_openreq6(struct seq_file *seq,
75329 uid,
75330 0, /* non standard timer */
75331 0, /* open_requests have no inode */
75332 - 0, req);
75333 + 0,
75334 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75335 + NULL
75336 +#else
75337 + req
75338 +#endif
75339 + );
75340 }
75341
75342 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
75343 @@ -1980,7 +2005,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
75344 sock_i_uid(sp),
75345 icsk->icsk_probes_out,
75346 sock_i_ino(sp),
75347 - atomic_read(&sp->sk_refcnt), sp,
75348 + atomic_read(&sp->sk_refcnt),
75349 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75350 + NULL,
75351 +#else
75352 + sp,
75353 +#endif
75354 jiffies_to_clock_t(icsk->icsk_rto),
75355 jiffies_to_clock_t(icsk->icsk_ack.ato),
75356 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
75357 @@ -2015,7 +2045,13 @@ static void get_timewait6_sock(struct seq_file *seq,
75358 dest->s6_addr32[2], dest->s6_addr32[3], destp,
75359 tw->tw_substate, 0, 0,
75360 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
75361 - atomic_read(&tw->tw_refcnt), tw);
75362 + atomic_read(&tw->tw_refcnt),
75363 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75364 + NULL
75365 +#else
75366 + tw
75367 +#endif
75368 + );
75369 }
75370
75371 static int tcp6_seq_show(struct seq_file *seq, void *v)
75372 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
75373 index 37b0699..d323408 100644
75374 --- a/net/ipv6/udp.c
75375 +++ b/net/ipv6/udp.c
75376 @@ -50,6 +50,10 @@
75377 #include <linux/seq_file.h>
75378 #include "udp_impl.h"
75379
75380 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75381 +extern int grsec_enable_blackhole;
75382 +#endif
75383 +
75384 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
75385 {
75386 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
75387 @@ -551,7 +555,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
75388
75389 return 0;
75390 drop:
75391 - atomic_inc(&sk->sk_drops);
75392 + atomic_inc_unchecked(&sk->sk_drops);
75393 drop_no_sk_drops_inc:
75394 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
75395 kfree_skb(skb);
75396 @@ -627,7 +631,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
75397 continue;
75398 }
75399 drop:
75400 - atomic_inc(&sk->sk_drops);
75401 + atomic_inc_unchecked(&sk->sk_drops);
75402 UDP6_INC_STATS_BH(sock_net(sk),
75403 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
75404 UDP6_INC_STATS_BH(sock_net(sk),
75405 @@ -782,6 +786,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
75406 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
75407 proto == IPPROTO_UDPLITE);
75408
75409 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75410 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
75411 +#endif
75412 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
75413
75414 kfree_skb(skb);
75415 @@ -798,7 +805,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
75416 if (!sock_owned_by_user(sk))
75417 udpv6_queue_rcv_skb(sk, skb);
75418 else if (sk_add_backlog(sk, skb)) {
75419 - atomic_inc(&sk->sk_drops);
75420 + atomic_inc_unchecked(&sk->sk_drops);
75421 bh_unlock_sock(sk);
75422 sock_put(sk);
75423 goto discard;
75424 @@ -1411,8 +1418,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
75425 0, 0L, 0,
75426 sock_i_uid(sp), 0,
75427 sock_i_ino(sp),
75428 - atomic_read(&sp->sk_refcnt), sp,
75429 - atomic_read(&sp->sk_drops));
75430 + atomic_read(&sp->sk_refcnt),
75431 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75432 + NULL,
75433 +#else
75434 + sp,
75435 +#endif
75436 + atomic_read_unchecked(&sp->sk_drops));
75437 }
75438
75439 int udp6_seq_show(struct seq_file *seq, void *v)
75440 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
75441 index 6b9d5a0..4dffaf1 100644
75442 --- a/net/irda/ircomm/ircomm_tty.c
75443 +++ b/net/irda/ircomm/ircomm_tty.c
75444 @@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
75445 add_wait_queue(&self->open_wait, &wait);
75446
75447 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
75448 - __FILE__,__LINE__, tty->driver->name, self->open_count );
75449 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
75450
75451 /* As far as I can see, we protect open_count - Jean II */
75452 spin_lock_irqsave(&self->spinlock, flags);
75453 if (!tty_hung_up_p(filp)) {
75454 extra_count = 1;
75455 - self->open_count--;
75456 + local_dec(&self->open_count);
75457 }
75458 spin_unlock_irqrestore(&self->spinlock, flags);
75459 - self->blocked_open++;
75460 + local_inc(&self->blocked_open);
75461
75462 while (1) {
75463 if (tty->termios->c_cflag & CBAUD) {
75464 @@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
75465 }
75466
75467 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
75468 - __FILE__,__LINE__, tty->driver->name, self->open_count );
75469 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
75470
75471 schedule();
75472 }
75473 @@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
75474 if (extra_count) {
75475 /* ++ is not atomic, so this should be protected - Jean II */
75476 spin_lock_irqsave(&self->spinlock, flags);
75477 - self->open_count++;
75478 + local_inc(&self->open_count);
75479 spin_unlock_irqrestore(&self->spinlock, flags);
75480 }
75481 - self->blocked_open--;
75482 + local_dec(&self->blocked_open);
75483
75484 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
75485 - __FILE__,__LINE__, tty->driver->name, self->open_count);
75486 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
75487
75488 if (!retval)
75489 self->flags |= ASYNC_NORMAL_ACTIVE;
75490 @@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
75491 }
75492 /* ++ is not atomic, so this should be protected - Jean II */
75493 spin_lock_irqsave(&self->spinlock, flags);
75494 - self->open_count++;
75495 + local_inc(&self->open_count);
75496
75497 tty->driver_data = self;
75498 self->tty = tty;
75499 spin_unlock_irqrestore(&self->spinlock, flags);
75500
75501 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
75502 - self->line, self->open_count);
75503 + self->line, local_read(&self->open_count));
75504
75505 /* Not really used by us, but lets do it anyway */
75506 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
75507 @@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
75508 return;
75509 }
75510
75511 - if ((tty->count == 1) && (self->open_count != 1)) {
75512 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
75513 /*
75514 * Uh, oh. tty->count is 1, which means that the tty
75515 * structure will be freed. state->count should always
75516 @@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
75517 */
75518 IRDA_DEBUG(0, "%s(), bad serial port count; "
75519 "tty->count is 1, state->count is %d\n", __func__ ,
75520 - self->open_count);
75521 - self->open_count = 1;
75522 + local_read(&self->open_count));
75523 + local_set(&self->open_count, 1);
75524 }
75525
75526 - if (--self->open_count < 0) {
75527 + if (local_dec_return(&self->open_count) < 0) {
75528 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
75529 - __func__, self->line, self->open_count);
75530 - self->open_count = 0;
75531 + __func__, self->line, local_read(&self->open_count));
75532 + local_set(&self->open_count, 0);
75533 }
75534 - if (self->open_count) {
75535 + if (local_read(&self->open_count)) {
75536 spin_unlock_irqrestore(&self->spinlock, flags);
75537
75538 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
75539 @@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
75540 tty->closing = 0;
75541 self->tty = NULL;
75542
75543 - if (self->blocked_open) {
75544 + if (local_read(&self->blocked_open)) {
75545 if (self->close_delay)
75546 schedule_timeout_interruptible(self->close_delay);
75547 wake_up_interruptible(&self->open_wait);
75548 @@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
75549 spin_lock_irqsave(&self->spinlock, flags);
75550 self->flags &= ~ASYNC_NORMAL_ACTIVE;
75551 self->tty = NULL;
75552 - self->open_count = 0;
75553 + local_set(&self->open_count, 0);
75554 spin_unlock_irqrestore(&self->spinlock, flags);
75555
75556 wake_up_interruptible(&self->open_wait);
75557 @@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
75558 seq_putc(m, '\n');
75559
75560 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
75561 - seq_printf(m, "Open count: %d\n", self->open_count);
75562 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
75563 seq_printf(m, "Max data size: %d\n", self->max_data_size);
75564 seq_printf(m, "Max header size: %d\n", self->max_header_size);
75565
75566 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
75567 index 07d7d55..541de95 100644
75568 --- a/net/iucv/af_iucv.c
75569 +++ b/net/iucv/af_iucv.c
75570 @@ -783,10 +783,10 @@ static int iucv_sock_autobind(struct sock *sk)
75571
75572 write_lock_bh(&iucv_sk_list.lock);
75573
75574 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
75575 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
75576 while (__iucv_get_sock_by_name(name)) {
75577 sprintf(name, "%08x",
75578 - atomic_inc_return(&iucv_sk_list.autobind_name));
75579 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
75580 }
75581
75582 write_unlock_bh(&iucv_sk_list.lock);
75583 diff --git a/net/key/af_key.c b/net/key/af_key.c
75584 index 7e5d927..cdbb54e 100644
75585 --- a/net/key/af_key.c
75586 +++ b/net/key/af_key.c
75587 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
75588 static u32 get_acqseq(void)
75589 {
75590 u32 res;
75591 - static atomic_t acqseq;
75592 + static atomic_unchecked_t acqseq;
75593
75594 do {
75595 - res = atomic_inc_return(&acqseq);
75596 + res = atomic_inc_return_unchecked(&acqseq);
75597 } while (!res);
75598 return res;
75599 }
75600 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
75601 index db8fae5..ff070cd 100644
75602 --- a/net/mac80211/ieee80211_i.h
75603 +++ b/net/mac80211/ieee80211_i.h
75604 @@ -28,6 +28,7 @@
75605 #include <net/ieee80211_radiotap.h>
75606 #include <net/cfg80211.h>
75607 #include <net/mac80211.h>
75608 +#include <asm/local.h>
75609 #include "key.h"
75610 #include "sta_info.h"
75611
75612 @@ -842,7 +843,7 @@ struct ieee80211_local {
75613 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
75614 spinlock_t queue_stop_reason_lock;
75615
75616 - int open_count;
75617 + local_t open_count;
75618 int monitors, cooked_mntrs;
75619 /* number of interfaces with corresponding FIF_ flags */
75620 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
75621 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
75622 index 48f937e..4ccd7b8 100644
75623 --- a/net/mac80211/iface.c
75624 +++ b/net/mac80211/iface.c
75625 @@ -222,7 +222,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75626 break;
75627 }
75628
75629 - if (local->open_count == 0) {
75630 + if (local_read(&local->open_count) == 0) {
75631 res = drv_start(local);
75632 if (res)
75633 goto err_del_bss;
75634 @@ -246,7 +246,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75635 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
75636
75637 if (!is_valid_ether_addr(dev->dev_addr)) {
75638 - if (!local->open_count)
75639 + if (!local_read(&local->open_count))
75640 drv_stop(local);
75641 return -EADDRNOTAVAIL;
75642 }
75643 @@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75644 mutex_unlock(&local->mtx);
75645
75646 if (coming_up)
75647 - local->open_count++;
75648 + local_inc(&local->open_count);
75649
75650 if (hw_reconf_flags)
75651 ieee80211_hw_config(local, hw_reconf_flags);
75652 @@ -360,7 +360,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75653 err_del_interface:
75654 drv_remove_interface(local, sdata);
75655 err_stop:
75656 - if (!local->open_count)
75657 + if (!local_read(&local->open_count))
75658 drv_stop(local);
75659 err_del_bss:
75660 sdata->bss = NULL;
75661 @@ -491,7 +491,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
75662 }
75663
75664 if (going_down)
75665 - local->open_count--;
75666 + local_dec(&local->open_count);
75667
75668 switch (sdata->vif.type) {
75669 case NL80211_IFTYPE_AP_VLAN:
75670 @@ -562,7 +562,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
75671
75672 ieee80211_recalc_ps(local, -1);
75673
75674 - if (local->open_count == 0) {
75675 + if (local_read(&local->open_count) == 0) {
75676 if (local->ops->napi_poll)
75677 napi_disable(&local->napi);
75678 ieee80211_clear_tx_pending(local);
75679 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
75680 index 1633648..d45ebfa 100644
75681 --- a/net/mac80211/main.c
75682 +++ b/net/mac80211/main.c
75683 @@ -164,7 +164,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
75684 local->hw.conf.power_level = power;
75685 }
75686
75687 - if (changed && local->open_count) {
75688 + if (changed && local_read(&local->open_count)) {
75689 ret = drv_config(local, changed);
75690 /*
75691 * Goal:
75692 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
75693 index ef8eba1..5c63952 100644
75694 --- a/net/mac80211/pm.c
75695 +++ b/net/mac80211/pm.c
75696 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
75697 struct ieee80211_sub_if_data *sdata;
75698 struct sta_info *sta;
75699
75700 - if (!local->open_count)
75701 + if (!local_read(&local->open_count))
75702 goto suspend;
75703
75704 ieee80211_scan_cancel(local);
75705 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
75706 cancel_work_sync(&local->dynamic_ps_enable_work);
75707 del_timer_sync(&local->dynamic_ps_timer);
75708
75709 - local->wowlan = wowlan && local->open_count;
75710 + local->wowlan = wowlan && local_read(&local->open_count);
75711 if (local->wowlan) {
75712 int err = drv_suspend(local, wowlan);
75713 if (err < 0) {
75714 @@ -128,7 +128,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
75715 }
75716
75717 /* stop hardware - this must stop RX */
75718 - if (local->open_count)
75719 + if (local_read(&local->open_count))
75720 ieee80211_stop_device(local);
75721
75722 suspend:
75723 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
75724 index 3313c11..bec9f17 100644
75725 --- a/net/mac80211/rate.c
75726 +++ b/net/mac80211/rate.c
75727 @@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
75728
75729 ASSERT_RTNL();
75730
75731 - if (local->open_count)
75732 + if (local_read(&local->open_count))
75733 return -EBUSY;
75734
75735 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
75736 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
75737 index c97a065..ff61928 100644
75738 --- a/net/mac80211/rc80211_pid_debugfs.c
75739 +++ b/net/mac80211/rc80211_pid_debugfs.c
75740 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
75741
75742 spin_unlock_irqrestore(&events->lock, status);
75743
75744 - if (copy_to_user(buf, pb, p))
75745 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
75746 return -EFAULT;
75747
75748 return p;
75749 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
75750 index eb9d7c0..d34b832 100644
75751 --- a/net/mac80211/util.c
75752 +++ b/net/mac80211/util.c
75753 @@ -1179,7 +1179,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
75754 }
75755 #endif
75756 /* everything else happens only if HW was up & running */
75757 - if (!local->open_count)
75758 + if (!local_read(&local->open_count))
75759 goto wake_up;
75760
75761 /*
75762 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
75763 index 0c6f67e..d02cdfc 100644
75764 --- a/net/netfilter/Kconfig
75765 +++ b/net/netfilter/Kconfig
75766 @@ -836,6 +836,16 @@ config NETFILTER_XT_MATCH_ESP
75767
75768 To compile it as a module, choose M here. If unsure, say N.
75769
75770 +config NETFILTER_XT_MATCH_GRADM
75771 + tristate '"gradm" match support'
75772 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
75773 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
75774 + ---help---
75775 + The gradm match allows to match on grsecurity RBAC being enabled.
75776 + It is useful when iptables rules are applied early on bootup to
75777 + prevent connections to the machine (except from a trusted host)
75778 + while the RBAC system is disabled.
75779 +
75780 config NETFILTER_XT_MATCH_HASHLIMIT
75781 tristate '"hashlimit" match support'
75782 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
75783 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
75784 index ca36765..0882e7c 100644
75785 --- a/net/netfilter/Makefile
75786 +++ b/net/netfilter/Makefile
75787 @@ -86,6 +86,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
75788 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
75789 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
75790 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
75791 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
75792 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
75793 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
75794 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
75795 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
75796 index 29fa5ba..8debc79 100644
75797 --- a/net/netfilter/ipvs/ip_vs_conn.c
75798 +++ b/net/netfilter/ipvs/ip_vs_conn.c
75799 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
75800 /* Increase the refcnt counter of the dest */
75801 atomic_inc(&dest->refcnt);
75802
75803 - conn_flags = atomic_read(&dest->conn_flags);
75804 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
75805 if (cp->protocol != IPPROTO_UDP)
75806 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
75807 /* Bind with the destination and its corresponding transmitter */
75808 @@ -869,7 +869,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
75809 atomic_set(&cp->refcnt, 1);
75810
75811 atomic_set(&cp->n_control, 0);
75812 - atomic_set(&cp->in_pkts, 0);
75813 + atomic_set_unchecked(&cp->in_pkts, 0);
75814
75815 atomic_inc(&ipvs->conn_count);
75816 if (flags & IP_VS_CONN_F_NO_CPORT)
75817 @@ -1149,7 +1149,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
75818
75819 /* Don't drop the entry if its number of incoming packets is not
75820 located in [0, 8] */
75821 - i = atomic_read(&cp->in_pkts);
75822 + i = atomic_read_unchecked(&cp->in_pkts);
75823 if (i > 8 || i < 0) return 0;
75824
75825 if (!todrop_rate[i]) return 0;
75826 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
75827 index 00bdb1d..6725a48 100644
75828 --- a/net/netfilter/ipvs/ip_vs_core.c
75829 +++ b/net/netfilter/ipvs/ip_vs_core.c
75830 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
75831 ret = cp->packet_xmit(skb, cp, pd->pp);
75832 /* do not touch skb anymore */
75833
75834 - atomic_inc(&cp->in_pkts);
75835 + atomic_inc_unchecked(&cp->in_pkts);
75836 ip_vs_conn_put(cp);
75837 return ret;
75838 }
75839 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
75840 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
75841 pkts = sysctl_sync_threshold(ipvs);
75842 else
75843 - pkts = atomic_add_return(1, &cp->in_pkts);
75844 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
75845
75846 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
75847 cp->protocol == IPPROTO_SCTP) {
75848 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
75849 index f558998..9cdff60 100644
75850 --- a/net/netfilter/ipvs/ip_vs_ctl.c
75851 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
75852 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
75853 ip_vs_rs_hash(ipvs, dest);
75854 write_unlock_bh(&ipvs->rs_lock);
75855 }
75856 - atomic_set(&dest->conn_flags, conn_flags);
75857 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
75858
75859 /* bind the service */
75860 if (!dest->svc) {
75861 @@ -2028,7 +2028,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
75862 " %-7s %-6d %-10d %-10d\n",
75863 &dest->addr.in6,
75864 ntohs(dest->port),
75865 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
75866 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
75867 atomic_read(&dest->weight),
75868 atomic_read(&dest->activeconns),
75869 atomic_read(&dest->inactconns));
75870 @@ -2039,7 +2039,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
75871 "%-7s %-6d %-10d %-10d\n",
75872 ntohl(dest->addr.ip),
75873 ntohs(dest->port),
75874 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
75875 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
75876 atomic_read(&dest->weight),
75877 atomic_read(&dest->activeconns),
75878 atomic_read(&dest->inactconns));
75879 @@ -2509,7 +2509,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
75880
75881 entry.addr = dest->addr.ip;
75882 entry.port = dest->port;
75883 - entry.conn_flags = atomic_read(&dest->conn_flags);
75884 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
75885 entry.weight = atomic_read(&dest->weight);
75886 entry.u_threshold = dest->u_threshold;
75887 entry.l_threshold = dest->l_threshold;
75888 @@ -3042,7 +3042,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
75889 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
75890
75891 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
75892 - atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
75893 + atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
75894 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
75895 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
75896 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
75897 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
75898 index 8a0d6d6..90ec197 100644
75899 --- a/net/netfilter/ipvs/ip_vs_sync.c
75900 +++ b/net/netfilter/ipvs/ip_vs_sync.c
75901 @@ -649,7 +649,7 @@ control:
75902 * i.e only increment in_pkts for Templates.
75903 */
75904 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
75905 - int pkts = atomic_add_return(1, &cp->in_pkts);
75906 + int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
75907
75908 if (pkts % sysctl_sync_period(ipvs) != 1)
75909 return;
75910 @@ -795,7 +795,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
75911
75912 if (opt)
75913 memcpy(&cp->in_seq, opt, sizeof(*opt));
75914 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
75915 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
75916 cp->state = state;
75917 cp->old_state = cp->state;
75918 /*
75919 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
75920 index 7fd66de..e6fb361 100644
75921 --- a/net/netfilter/ipvs/ip_vs_xmit.c
75922 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
75923 @@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
75924 else
75925 rc = NF_ACCEPT;
75926 /* do not touch skb anymore */
75927 - atomic_inc(&cp->in_pkts);
75928 + atomic_inc_unchecked(&cp->in_pkts);
75929 goto out;
75930 }
75931
75932 @@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
75933 else
75934 rc = NF_ACCEPT;
75935 /* do not touch skb anymore */
75936 - atomic_inc(&cp->in_pkts);
75937 + atomic_inc_unchecked(&cp->in_pkts);
75938 goto out;
75939 }
75940
75941 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
75942 index 66b2c54..c7884e3 100644
75943 --- a/net/netfilter/nfnetlink_log.c
75944 +++ b/net/netfilter/nfnetlink_log.c
75945 @@ -70,7 +70,7 @@ struct nfulnl_instance {
75946 };
75947
75948 static DEFINE_SPINLOCK(instances_lock);
75949 -static atomic_t global_seq;
75950 +static atomic_unchecked_t global_seq;
75951
75952 #define INSTANCE_BUCKETS 16
75953 static struct hlist_head instance_table[INSTANCE_BUCKETS];
75954 @@ -502,7 +502,7 @@ __build_packet_message(struct nfulnl_instance *inst,
75955 /* global sequence number */
75956 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
75957 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
75958 - htonl(atomic_inc_return(&global_seq)));
75959 + htonl(atomic_inc_return_unchecked(&global_seq)));
75960
75961 if (data_len) {
75962 struct nlattr *nla;
75963 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
75964 new file mode 100644
75965 index 0000000..6905327
75966 --- /dev/null
75967 +++ b/net/netfilter/xt_gradm.c
75968 @@ -0,0 +1,51 @@
75969 +/*
75970 + * gradm match for netfilter
75971 + * Copyright © Zbigniew Krzystolik, 2010
75972 + *
75973 + * This program is free software; you can redistribute it and/or modify
75974 + * it under the terms of the GNU General Public License; either version
75975 + * 2 or 3 as published by the Free Software Foundation.
75976 + */
75977 +#include <linux/module.h>
75978 +#include <linux/moduleparam.h>
75979 +#include <linux/skbuff.h>
75980 +#include <linux/netfilter/x_tables.h>
75981 +#include <linux/grsecurity.h>
75982 +#include <linux/netfilter/xt_gradm.h>
75983 +
75984 +static bool
75985 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
75986 +{
75987 + const struct xt_gradm_mtinfo *info = par->matchinfo;
75988 + bool retval = false;
75989 + if (gr_acl_is_enabled())
75990 + retval = true;
75991 + return retval ^ info->invflags;
75992 +}
75993 +
75994 +static struct xt_match gradm_mt_reg __read_mostly = {
75995 + .name = "gradm",
75996 + .revision = 0,
75997 + .family = NFPROTO_UNSPEC,
75998 + .match = gradm_mt,
75999 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
76000 + .me = THIS_MODULE,
76001 +};
76002 +
76003 +static int __init gradm_mt_init(void)
76004 +{
76005 + return xt_register_match(&gradm_mt_reg);
76006 +}
76007 +
76008 +static void __exit gradm_mt_exit(void)
76009 +{
76010 + xt_unregister_match(&gradm_mt_reg);
76011 +}
76012 +
76013 +module_init(gradm_mt_init);
76014 +module_exit(gradm_mt_exit);
76015 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
76016 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
76017 +MODULE_LICENSE("GPL");
76018 +MODULE_ALIAS("ipt_gradm");
76019 +MODULE_ALIAS("ip6t_gradm");
76020 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
76021 index 4fe4fb4..87a89e5 100644
76022 --- a/net/netfilter/xt_statistic.c
76023 +++ b/net/netfilter/xt_statistic.c
76024 @@ -19,7 +19,7 @@
76025 #include <linux/module.h>
76026
76027 struct xt_statistic_priv {
76028 - atomic_t count;
76029 + atomic_unchecked_t count;
76030 } ____cacheline_aligned_in_smp;
76031
76032 MODULE_LICENSE("GPL");
76033 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
76034 break;
76035 case XT_STATISTIC_MODE_NTH:
76036 do {
76037 - oval = atomic_read(&info->master->count);
76038 + oval = atomic_read_unchecked(&info->master->count);
76039 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
76040 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
76041 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
76042 if (nval == 0)
76043 ret = !ret;
76044 break;
76045 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
76046 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
76047 if (info->master == NULL)
76048 return -ENOMEM;
76049 - atomic_set(&info->master->count, info->u.nth.count);
76050 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
76051
76052 return 0;
76053 }
76054 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
76055 index faa48f7..65f7f54 100644
76056 --- a/net/netlink/af_netlink.c
76057 +++ b/net/netlink/af_netlink.c
76058 @@ -741,7 +741,7 @@ static void netlink_overrun(struct sock *sk)
76059 sk->sk_error_report(sk);
76060 }
76061 }
76062 - atomic_inc(&sk->sk_drops);
76063 + atomic_inc_unchecked(&sk->sk_drops);
76064 }
76065
76066 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
76067 @@ -2013,7 +2013,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
76068 sk_wmem_alloc_get(s),
76069 nlk->cb,
76070 atomic_read(&s->sk_refcnt),
76071 - atomic_read(&s->sk_drops),
76072 + atomic_read_unchecked(&s->sk_drops),
76073 sock_i_ino(s)
76074 );
76075
76076 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
76077 index 06592d8..64860f6 100644
76078 --- a/net/netrom/af_netrom.c
76079 +++ b/net/netrom/af_netrom.c
76080 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
76081 struct sock *sk = sock->sk;
76082 struct nr_sock *nr = nr_sk(sk);
76083
76084 + memset(sax, 0, sizeof(*sax));
76085 lock_sock(sk);
76086 if (peer != 0) {
76087 if (sk->sk_state != TCP_ESTABLISHED) {
76088 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
76089 *uaddr_len = sizeof(struct full_sockaddr_ax25);
76090 } else {
76091 sax->fsa_ax25.sax25_family = AF_NETROM;
76092 - sax->fsa_ax25.sax25_ndigis = 0;
76093 sax->fsa_ax25.sax25_call = nr->source_addr;
76094 *uaddr_len = sizeof(struct sockaddr_ax25);
76095 }
76096 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
76097 index 4f2c0df..f0ff342 100644
76098 --- a/net/packet/af_packet.c
76099 +++ b/net/packet/af_packet.c
76100 @@ -1687,7 +1687,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
76101
76102 spin_lock(&sk->sk_receive_queue.lock);
76103 po->stats.tp_packets++;
76104 - skb->dropcount = atomic_read(&sk->sk_drops);
76105 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
76106 __skb_queue_tail(&sk->sk_receive_queue, skb);
76107 spin_unlock(&sk->sk_receive_queue.lock);
76108 sk->sk_data_ready(sk, skb->len);
76109 @@ -1696,7 +1696,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
76110 drop_n_acct:
76111 spin_lock(&sk->sk_receive_queue.lock);
76112 po->stats.tp_drops++;
76113 - atomic_inc(&sk->sk_drops);
76114 + atomic_inc_unchecked(&sk->sk_drops);
76115 spin_unlock(&sk->sk_receive_queue.lock);
76116
76117 drop_n_restore:
76118 @@ -3294,7 +3294,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
76119 case PACKET_HDRLEN:
76120 if (len > sizeof(int))
76121 len = sizeof(int);
76122 - if (copy_from_user(&val, optval, len))
76123 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
76124 return -EFAULT;
76125 switch (val) {
76126 case TPACKET_V1:
76127 @@ -3344,7 +3344,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
76128
76129 if (put_user(len, optlen))
76130 return -EFAULT;
76131 - if (copy_to_user(optval, data, len))
76132 + if (len > sizeof(st) || copy_to_user(optval, data, len))
76133 return -EFAULT;
76134 return 0;
76135 }
76136 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
76137 index d65f699..05aa6ce 100644
76138 --- a/net/phonet/af_phonet.c
76139 +++ b/net/phonet/af_phonet.c
76140 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
76141 {
76142 struct phonet_protocol *pp;
76143
76144 - if (protocol >= PHONET_NPROTO)
76145 + if (protocol < 0 || protocol >= PHONET_NPROTO)
76146 return NULL;
76147
76148 rcu_read_lock();
76149 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
76150 {
76151 int err = 0;
76152
76153 - if (protocol >= PHONET_NPROTO)
76154 + if (protocol < 0 || protocol >= PHONET_NPROTO)
76155 return -EINVAL;
76156
76157 err = proto_register(pp->prot, 1);
76158 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
76159 index 9726fe6..fc4e3a4 100644
76160 --- a/net/phonet/pep.c
76161 +++ b/net/phonet/pep.c
76162 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
76163
76164 case PNS_PEP_CTRL_REQ:
76165 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
76166 - atomic_inc(&sk->sk_drops);
76167 + atomic_inc_unchecked(&sk->sk_drops);
76168 break;
76169 }
76170 __skb_pull(skb, 4);
76171 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
76172 }
76173
76174 if (pn->rx_credits == 0) {
76175 - atomic_inc(&sk->sk_drops);
76176 + atomic_inc_unchecked(&sk->sk_drops);
76177 err = -ENOBUFS;
76178 break;
76179 }
76180 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
76181 }
76182
76183 if (pn->rx_credits == 0) {
76184 - atomic_inc(&sk->sk_drops);
76185 + atomic_inc_unchecked(&sk->sk_drops);
76186 err = NET_RX_DROP;
76187 break;
76188 }
76189 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
76190 index 4c7eff3..59c727f 100644
76191 --- a/net/phonet/socket.c
76192 +++ b/net/phonet/socket.c
76193 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
76194 pn->resource, sk->sk_state,
76195 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
76196 sock_i_uid(sk), sock_i_ino(sk),
76197 - atomic_read(&sk->sk_refcnt), sk,
76198 - atomic_read(&sk->sk_drops), &len);
76199 + atomic_read(&sk->sk_refcnt),
76200 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76201 + NULL,
76202 +#else
76203 + sk,
76204 +#endif
76205 + atomic_read_unchecked(&sk->sk_drops), &len);
76206 }
76207 seq_printf(seq, "%*s\n", 127 - len, "");
76208 return 0;
76209 diff --git a/net/rds/cong.c b/net/rds/cong.c
76210 index e5b65ac..f3b6fb7 100644
76211 --- a/net/rds/cong.c
76212 +++ b/net/rds/cong.c
76213 @@ -78,7 +78,7 @@
76214 * finds that the saved generation number is smaller than the global generation
76215 * number, it wakes up the process.
76216 */
76217 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
76218 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
76219
76220 /*
76221 * Congestion monitoring
76222 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
76223 rdsdebug("waking map %p for %pI4\n",
76224 map, &map->m_addr);
76225 rds_stats_inc(s_cong_update_received);
76226 - atomic_inc(&rds_cong_generation);
76227 + atomic_inc_unchecked(&rds_cong_generation);
76228 if (waitqueue_active(&map->m_waitq))
76229 wake_up(&map->m_waitq);
76230 if (waitqueue_active(&rds_poll_waitq))
76231 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
76232
76233 int rds_cong_updated_since(unsigned long *recent)
76234 {
76235 - unsigned long gen = atomic_read(&rds_cong_generation);
76236 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
76237
76238 if (likely(*recent == gen))
76239 return 0;
76240 diff --git a/net/rds/ib.h b/net/rds/ib.h
76241 index edfaaaf..8c89879 100644
76242 --- a/net/rds/ib.h
76243 +++ b/net/rds/ib.h
76244 @@ -128,7 +128,7 @@ struct rds_ib_connection {
76245 /* sending acks */
76246 unsigned long i_ack_flags;
76247 #ifdef KERNEL_HAS_ATOMIC64
76248 - atomic64_t i_ack_next; /* next ACK to send */
76249 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
76250 #else
76251 spinlock_t i_ack_lock; /* protect i_ack_next */
76252 u64 i_ack_next; /* next ACK to send */
76253 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
76254 index a1e1162..265e129 100644
76255 --- a/net/rds/ib_cm.c
76256 +++ b/net/rds/ib_cm.c
76257 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
76258 /* Clear the ACK state */
76259 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
76260 #ifdef KERNEL_HAS_ATOMIC64
76261 - atomic64_set(&ic->i_ack_next, 0);
76262 + atomic64_set_unchecked(&ic->i_ack_next, 0);
76263 #else
76264 ic->i_ack_next = 0;
76265 #endif
76266 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
76267 index 8d19491..05a3e65 100644
76268 --- a/net/rds/ib_recv.c
76269 +++ b/net/rds/ib_recv.c
76270 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
76271 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
76272 int ack_required)
76273 {
76274 - atomic64_set(&ic->i_ack_next, seq);
76275 + atomic64_set_unchecked(&ic->i_ack_next, seq);
76276 if (ack_required) {
76277 smp_mb__before_clear_bit();
76278 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
76279 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
76280 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
76281 smp_mb__after_clear_bit();
76282
76283 - return atomic64_read(&ic->i_ack_next);
76284 + return atomic64_read_unchecked(&ic->i_ack_next);
76285 }
76286 #endif
76287
76288 diff --git a/net/rds/iw.h b/net/rds/iw.h
76289 index 04ce3b1..48119a6 100644
76290 --- a/net/rds/iw.h
76291 +++ b/net/rds/iw.h
76292 @@ -134,7 +134,7 @@ struct rds_iw_connection {
76293 /* sending acks */
76294 unsigned long i_ack_flags;
76295 #ifdef KERNEL_HAS_ATOMIC64
76296 - atomic64_t i_ack_next; /* next ACK to send */
76297 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
76298 #else
76299 spinlock_t i_ack_lock; /* protect i_ack_next */
76300 u64 i_ack_next; /* next ACK to send */
76301 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
76302 index a91e1db..cf3053f 100644
76303 --- a/net/rds/iw_cm.c
76304 +++ b/net/rds/iw_cm.c
76305 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
76306 /* Clear the ACK state */
76307 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
76308 #ifdef KERNEL_HAS_ATOMIC64
76309 - atomic64_set(&ic->i_ack_next, 0);
76310 + atomic64_set_unchecked(&ic->i_ack_next, 0);
76311 #else
76312 ic->i_ack_next = 0;
76313 #endif
76314 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
76315 index 4503335..db566b4 100644
76316 --- a/net/rds/iw_recv.c
76317 +++ b/net/rds/iw_recv.c
76318 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
76319 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
76320 int ack_required)
76321 {
76322 - atomic64_set(&ic->i_ack_next, seq);
76323 + atomic64_set_unchecked(&ic->i_ack_next, seq);
76324 if (ack_required) {
76325 smp_mb__before_clear_bit();
76326 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
76327 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
76328 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
76329 smp_mb__after_clear_bit();
76330
76331 - return atomic64_read(&ic->i_ack_next);
76332 + return atomic64_read_unchecked(&ic->i_ack_next);
76333 }
76334 #endif
76335
76336 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
76337 index edac9ef..16bcb98 100644
76338 --- a/net/rds/tcp.c
76339 +++ b/net/rds/tcp.c
76340 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
76341 int val = 1;
76342
76343 set_fs(KERNEL_DS);
76344 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
76345 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
76346 sizeof(val));
76347 set_fs(oldfs);
76348 }
76349 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
76350 index 1b4fd68..2234175 100644
76351 --- a/net/rds/tcp_send.c
76352 +++ b/net/rds/tcp_send.c
76353 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
76354
76355 oldfs = get_fs();
76356 set_fs(KERNEL_DS);
76357 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
76358 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
76359 sizeof(val));
76360 set_fs(oldfs);
76361 }
76362 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
76363 index 74c064c..fdec26f 100644
76364 --- a/net/rxrpc/af_rxrpc.c
76365 +++ b/net/rxrpc/af_rxrpc.c
76366 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
76367 __be32 rxrpc_epoch;
76368
76369 /* current debugging ID */
76370 -atomic_t rxrpc_debug_id;
76371 +atomic_unchecked_t rxrpc_debug_id;
76372
76373 /* count of skbs currently in use */
76374 atomic_t rxrpc_n_skbs;
76375 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
76376 index c3126e8..21facc7 100644
76377 --- a/net/rxrpc/ar-ack.c
76378 +++ b/net/rxrpc/ar-ack.c
76379 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
76380
76381 _enter("{%d,%d,%d,%d},",
76382 call->acks_hard, call->acks_unacked,
76383 - atomic_read(&call->sequence),
76384 + atomic_read_unchecked(&call->sequence),
76385 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
76386
76387 stop = 0;
76388 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
76389
76390 /* each Tx packet has a new serial number */
76391 sp->hdr.serial =
76392 - htonl(atomic_inc_return(&call->conn->serial));
76393 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
76394
76395 hdr = (struct rxrpc_header *) txb->head;
76396 hdr->serial = sp->hdr.serial;
76397 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
76398 */
76399 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
76400 {
76401 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
76402 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
76403 }
76404
76405 /*
76406 @@ -629,7 +629,7 @@ process_further:
76407
76408 latest = ntohl(sp->hdr.serial);
76409 hard = ntohl(ack.firstPacket);
76410 - tx = atomic_read(&call->sequence);
76411 + tx = atomic_read_unchecked(&call->sequence);
76412
76413 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
76414 latest,
76415 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
76416 goto maybe_reschedule;
76417
76418 send_ACK_with_skew:
76419 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
76420 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
76421 ntohl(ack.serial));
76422 send_ACK:
76423 mtu = call->conn->trans->peer->if_mtu;
76424 @@ -1173,7 +1173,7 @@ send_ACK:
76425 ackinfo.rxMTU = htonl(5692);
76426 ackinfo.jumbo_max = htonl(4);
76427
76428 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
76429 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
76430 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
76431 ntohl(hdr.serial),
76432 ntohs(ack.maxSkew),
76433 @@ -1191,7 +1191,7 @@ send_ACK:
76434 send_message:
76435 _debug("send message");
76436
76437 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
76438 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
76439 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
76440 send_message_2:
76441
76442 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
76443 index bf656c2..48f9d27 100644
76444 --- a/net/rxrpc/ar-call.c
76445 +++ b/net/rxrpc/ar-call.c
76446 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
76447 spin_lock_init(&call->lock);
76448 rwlock_init(&call->state_lock);
76449 atomic_set(&call->usage, 1);
76450 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
76451 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
76452 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
76453
76454 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
76455 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
76456 index 4106ca9..a338d7a 100644
76457 --- a/net/rxrpc/ar-connection.c
76458 +++ b/net/rxrpc/ar-connection.c
76459 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
76460 rwlock_init(&conn->lock);
76461 spin_lock_init(&conn->state_lock);
76462 atomic_set(&conn->usage, 1);
76463 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
76464 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
76465 conn->avail_calls = RXRPC_MAXCALLS;
76466 conn->size_align = 4;
76467 conn->header_size = sizeof(struct rxrpc_header);
76468 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
76469 index e7ed43a..6afa140 100644
76470 --- a/net/rxrpc/ar-connevent.c
76471 +++ b/net/rxrpc/ar-connevent.c
76472 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
76473
76474 len = iov[0].iov_len + iov[1].iov_len;
76475
76476 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
76477 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
76478 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
76479
76480 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
76481 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
76482 index 1a2b0633..e8d1382 100644
76483 --- a/net/rxrpc/ar-input.c
76484 +++ b/net/rxrpc/ar-input.c
76485 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
76486 /* track the latest serial number on this connection for ACK packet
76487 * information */
76488 serial = ntohl(sp->hdr.serial);
76489 - hi_serial = atomic_read(&call->conn->hi_serial);
76490 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
76491 while (serial > hi_serial)
76492 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
76493 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
76494 serial);
76495
76496 /* request ACK generation for any ACK or DATA packet that requests
76497 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
76498 index 8e22bd3..f66d1c0 100644
76499 --- a/net/rxrpc/ar-internal.h
76500 +++ b/net/rxrpc/ar-internal.h
76501 @@ -272,8 +272,8 @@ struct rxrpc_connection {
76502 int error; /* error code for local abort */
76503 int debug_id; /* debug ID for printks */
76504 unsigned call_counter; /* call ID counter */
76505 - atomic_t serial; /* packet serial number counter */
76506 - atomic_t hi_serial; /* highest serial number received */
76507 + atomic_unchecked_t serial; /* packet serial number counter */
76508 + atomic_unchecked_t hi_serial; /* highest serial number received */
76509 u8 avail_calls; /* number of calls available */
76510 u8 size_align; /* data size alignment (for security) */
76511 u8 header_size; /* rxrpc + security header size */
76512 @@ -346,7 +346,7 @@ struct rxrpc_call {
76513 spinlock_t lock;
76514 rwlock_t state_lock; /* lock for state transition */
76515 atomic_t usage;
76516 - atomic_t sequence; /* Tx data packet sequence counter */
76517 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
76518 u32 abort_code; /* local/remote abort code */
76519 enum { /* current state of call */
76520 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
76521 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
76522 */
76523 extern atomic_t rxrpc_n_skbs;
76524 extern __be32 rxrpc_epoch;
76525 -extern atomic_t rxrpc_debug_id;
76526 +extern atomic_unchecked_t rxrpc_debug_id;
76527 extern struct workqueue_struct *rxrpc_workqueue;
76528
76529 /*
76530 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
76531 index 87f7135..74d3703 100644
76532 --- a/net/rxrpc/ar-local.c
76533 +++ b/net/rxrpc/ar-local.c
76534 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
76535 spin_lock_init(&local->lock);
76536 rwlock_init(&local->services_lock);
76537 atomic_set(&local->usage, 1);
76538 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
76539 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
76540 memcpy(&local->srx, srx, sizeof(*srx));
76541 }
76542
76543 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
76544 index 16ae887..d24f12b 100644
76545 --- a/net/rxrpc/ar-output.c
76546 +++ b/net/rxrpc/ar-output.c
76547 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
76548 sp->hdr.cid = call->cid;
76549 sp->hdr.callNumber = call->call_id;
76550 sp->hdr.seq =
76551 - htonl(atomic_inc_return(&call->sequence));
76552 + htonl(atomic_inc_return_unchecked(&call->sequence));
76553 sp->hdr.serial =
76554 - htonl(atomic_inc_return(&conn->serial));
76555 + htonl(atomic_inc_return_unchecked(&conn->serial));
76556 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
76557 sp->hdr.userStatus = 0;
76558 sp->hdr.securityIndex = conn->security_ix;
76559 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
76560 index 2754f09..b20e38f 100644
76561 --- a/net/rxrpc/ar-peer.c
76562 +++ b/net/rxrpc/ar-peer.c
76563 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
76564 INIT_LIST_HEAD(&peer->error_targets);
76565 spin_lock_init(&peer->lock);
76566 atomic_set(&peer->usage, 1);
76567 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
76568 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
76569 memcpy(&peer->srx, srx, sizeof(*srx));
76570
76571 rxrpc_assess_MTU_size(peer);
76572 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
76573 index 38047f7..9f48511 100644
76574 --- a/net/rxrpc/ar-proc.c
76575 +++ b/net/rxrpc/ar-proc.c
76576 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
76577 atomic_read(&conn->usage),
76578 rxrpc_conn_states[conn->state],
76579 key_serial(conn->key),
76580 - atomic_read(&conn->serial),
76581 - atomic_read(&conn->hi_serial));
76582 + atomic_read_unchecked(&conn->serial),
76583 + atomic_read_unchecked(&conn->hi_serial));
76584
76585 return 0;
76586 }
76587 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
76588 index 92df566..87ec1bf 100644
76589 --- a/net/rxrpc/ar-transport.c
76590 +++ b/net/rxrpc/ar-transport.c
76591 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
76592 spin_lock_init(&trans->client_lock);
76593 rwlock_init(&trans->conn_lock);
76594 atomic_set(&trans->usage, 1);
76595 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
76596 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
76597
76598 if (peer->srx.transport.family == AF_INET) {
76599 switch (peer->srx.transport_type) {
76600 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
76601 index 7635107..4670276 100644
76602 --- a/net/rxrpc/rxkad.c
76603 +++ b/net/rxrpc/rxkad.c
76604 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
76605
76606 len = iov[0].iov_len + iov[1].iov_len;
76607
76608 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
76609 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
76610 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
76611
76612 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
76613 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
76614
76615 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
76616
76617 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
76618 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
76619 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
76620
76621 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
76622 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
76623 index 1e2eee8..ce3967e 100644
76624 --- a/net/sctp/proc.c
76625 +++ b/net/sctp/proc.c
76626 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
76627 seq_printf(seq,
76628 "%8pK %8pK %-3d %-3d %-2d %-4d "
76629 "%4d %8d %8d %7d %5lu %-5d %5d ",
76630 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
76631 + assoc, sk,
76632 + sctp_sk(sk)->type, sk->sk_state,
76633 assoc->state, hash,
76634 assoc->assoc_id,
76635 assoc->sndbuf_used,
76636 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
76637 index 92ba71d..9a97902 100644
76638 --- a/net/sctp/socket.c
76639 +++ b/net/sctp/socket.c
76640 @@ -4569,7 +4569,7 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
76641 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
76642 if (space_left < addrlen)
76643 return -ENOMEM;
76644 - if (copy_to_user(to, &temp, addrlen))
76645 + if (addrlen > sizeof(temp) || copy_to_user(to, &temp, addrlen))
76646 return -EFAULT;
76647 to += addrlen;
76648 cnt++;
76649 diff --git a/net/socket.c b/net/socket.c
76650 index 851edcd..b786851 100644
76651 --- a/net/socket.c
76652 +++ b/net/socket.c
76653 @@ -88,6 +88,7 @@
76654 #include <linux/nsproxy.h>
76655 #include <linux/magic.h>
76656 #include <linux/slab.h>
76657 +#include <linux/in.h>
76658
76659 #include <asm/uaccess.h>
76660 #include <asm/unistd.h>
76661 @@ -105,6 +106,8 @@
76662 #include <linux/sockios.h>
76663 #include <linux/atalk.h>
76664
76665 +#include <linux/grsock.h>
76666 +
76667 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
76668 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
76669 unsigned long nr_segs, loff_t pos);
76670 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
76671 &sockfs_dentry_operations, SOCKFS_MAGIC);
76672 }
76673
76674 -static struct vfsmount *sock_mnt __read_mostly;
76675 +struct vfsmount *sock_mnt __read_mostly;
76676
76677 static struct file_system_type sock_fs_type = {
76678 .name = "sockfs",
76679 @@ -1207,6 +1210,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
76680 return -EAFNOSUPPORT;
76681 if (type < 0 || type >= SOCK_MAX)
76682 return -EINVAL;
76683 + if (protocol < 0)
76684 + return -EINVAL;
76685
76686 /* Compatibility.
76687
76688 @@ -1339,6 +1344,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
76689 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
76690 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
76691
76692 + if(!gr_search_socket(family, type, protocol)) {
76693 + retval = -EACCES;
76694 + goto out;
76695 + }
76696 +
76697 + if (gr_handle_sock_all(family, type, protocol)) {
76698 + retval = -EACCES;
76699 + goto out;
76700 + }
76701 +
76702 retval = sock_create(family, type, protocol, &sock);
76703 if (retval < 0)
76704 goto out;
76705 @@ -1451,6 +1466,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
76706 if (sock) {
76707 err = move_addr_to_kernel(umyaddr, addrlen, &address);
76708 if (err >= 0) {
76709 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
76710 + err = -EACCES;
76711 + goto error;
76712 + }
76713 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
76714 + if (err)
76715 + goto error;
76716 +
76717 err = security_socket_bind(sock,
76718 (struct sockaddr *)&address,
76719 addrlen);
76720 @@ -1459,6 +1482,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
76721 (struct sockaddr *)
76722 &address, addrlen);
76723 }
76724 +error:
76725 fput_light(sock->file, fput_needed);
76726 }
76727 return err;
76728 @@ -1482,10 +1506,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
76729 if ((unsigned)backlog > somaxconn)
76730 backlog = somaxconn;
76731
76732 + if (gr_handle_sock_server_other(sock->sk)) {
76733 + err = -EPERM;
76734 + goto error;
76735 + }
76736 +
76737 + err = gr_search_listen(sock);
76738 + if (err)
76739 + goto error;
76740 +
76741 err = security_socket_listen(sock, backlog);
76742 if (!err)
76743 err = sock->ops->listen(sock, backlog);
76744
76745 +error:
76746 fput_light(sock->file, fput_needed);
76747 }
76748 return err;
76749 @@ -1529,6 +1563,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
76750 newsock->type = sock->type;
76751 newsock->ops = sock->ops;
76752
76753 + if (gr_handle_sock_server_other(sock->sk)) {
76754 + err = -EPERM;
76755 + sock_release(newsock);
76756 + goto out_put;
76757 + }
76758 +
76759 + err = gr_search_accept(sock);
76760 + if (err) {
76761 + sock_release(newsock);
76762 + goto out_put;
76763 + }
76764 +
76765 /*
76766 * We don't need try_module_get here, as the listening socket (sock)
76767 * has the protocol module (sock->ops->owner) held.
76768 @@ -1567,6 +1613,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
76769 fd_install(newfd, newfile);
76770 err = newfd;
76771
76772 + gr_attach_curr_ip(newsock->sk);
76773 +
76774 out_put:
76775 fput_light(sock->file, fput_needed);
76776 out:
76777 @@ -1599,6 +1647,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
76778 int, addrlen)
76779 {
76780 struct socket *sock;
76781 + struct sockaddr *sck;
76782 struct sockaddr_storage address;
76783 int err, fput_needed;
76784
76785 @@ -1609,6 +1658,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
76786 if (err < 0)
76787 goto out_put;
76788
76789 + sck = (struct sockaddr *)&address;
76790 +
76791 + if (gr_handle_sock_client(sck)) {
76792 + err = -EACCES;
76793 + goto out_put;
76794 + }
76795 +
76796 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
76797 + if (err)
76798 + goto out_put;
76799 +
76800 err =
76801 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
76802 if (err)
76803 @@ -1966,7 +2026,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
76804 * checking falls down on this.
76805 */
76806 if (copy_from_user(ctl_buf,
76807 - (void __user __force *)msg_sys->msg_control,
76808 + (void __force_user *)msg_sys->msg_control,
76809 ctl_len))
76810 goto out_freectl;
76811 msg_sys->msg_control = ctl_buf;
76812 @@ -2136,7 +2196,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
76813 * kernel msghdr to use the kernel address space)
76814 */
76815
76816 - uaddr = (__force void __user *)msg_sys->msg_name;
76817 + uaddr = (void __force_user *)msg_sys->msg_name;
76818 uaddr_len = COMPAT_NAMELEN(msg);
76819 if (MSG_CMSG_COMPAT & flags) {
76820 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
76821 @@ -2758,7 +2818,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
76822 }
76823
76824 ifr = compat_alloc_user_space(buf_size);
76825 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
76826 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
76827
76828 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
76829 return -EFAULT;
76830 @@ -2782,12 +2842,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
76831 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
76832
76833 if (copy_in_user(rxnfc, compat_rxnfc,
76834 - (void *)(&rxnfc->fs.m_ext + 1) -
76835 - (void *)rxnfc) ||
76836 + (void __user *)(&rxnfc->fs.m_ext + 1) -
76837 + (void __user *)rxnfc) ||
76838 copy_in_user(&rxnfc->fs.ring_cookie,
76839 &compat_rxnfc->fs.ring_cookie,
76840 - (void *)(&rxnfc->fs.location + 1) -
76841 - (void *)&rxnfc->fs.ring_cookie) ||
76842 + (void __user *)(&rxnfc->fs.location + 1) -
76843 + (void __user *)&rxnfc->fs.ring_cookie) ||
76844 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
76845 sizeof(rxnfc->rule_cnt)))
76846 return -EFAULT;
76847 @@ -2799,12 +2859,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
76848
76849 if (convert_out) {
76850 if (copy_in_user(compat_rxnfc, rxnfc,
76851 - (const void *)(&rxnfc->fs.m_ext + 1) -
76852 - (const void *)rxnfc) ||
76853 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
76854 + (const void __user *)rxnfc) ||
76855 copy_in_user(&compat_rxnfc->fs.ring_cookie,
76856 &rxnfc->fs.ring_cookie,
76857 - (const void *)(&rxnfc->fs.location + 1) -
76858 - (const void *)&rxnfc->fs.ring_cookie) ||
76859 + (const void __user *)(&rxnfc->fs.location + 1) -
76860 + (const void __user *)&rxnfc->fs.ring_cookie) ||
76861 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
76862 sizeof(rxnfc->rule_cnt)))
76863 return -EFAULT;
76864 @@ -2874,7 +2934,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
76865 old_fs = get_fs();
76866 set_fs(KERNEL_DS);
76867 err = dev_ioctl(net, cmd,
76868 - (struct ifreq __user __force *) &kifr);
76869 + (struct ifreq __force_user *) &kifr);
76870 set_fs(old_fs);
76871
76872 return err;
76873 @@ -2983,7 +3043,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
76874
76875 old_fs = get_fs();
76876 set_fs(KERNEL_DS);
76877 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
76878 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
76879 set_fs(old_fs);
76880
76881 if (cmd == SIOCGIFMAP && !err) {
76882 @@ -3088,7 +3148,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
76883 ret |= __get_user(rtdev, &(ur4->rt_dev));
76884 if (rtdev) {
76885 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
76886 - r4.rt_dev = (char __user __force *)devname;
76887 + r4.rt_dev = (char __force_user *)devname;
76888 devname[15] = 0;
76889 } else
76890 r4.rt_dev = NULL;
76891 @@ -3314,8 +3374,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
76892 int __user *uoptlen;
76893 int err;
76894
76895 - uoptval = (char __user __force *) optval;
76896 - uoptlen = (int __user __force *) optlen;
76897 + uoptval = (char __force_user *) optval;
76898 + uoptlen = (int __force_user *) optlen;
76899
76900 set_fs(KERNEL_DS);
76901 if (level == SOL_SOCKET)
76902 @@ -3335,7 +3395,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
76903 char __user *uoptval;
76904 int err;
76905
76906 - uoptval = (char __user __force *) optval;
76907 + uoptval = (char __force_user *) optval;
76908
76909 set_fs(KERNEL_DS);
76910 if (level == SOL_SOCKET)
76911 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
76912 index 994cfea..5343b6b 100644
76913 --- a/net/sunrpc/sched.c
76914 +++ b/net/sunrpc/sched.c
76915 @@ -240,9 +240,9 @@ static int rpc_wait_bit_killable(void *word)
76916 #ifdef RPC_DEBUG
76917 static void rpc_task_set_debuginfo(struct rpc_task *task)
76918 {
76919 - static atomic_t rpc_pid;
76920 + static atomic_unchecked_t rpc_pid;
76921
76922 - task->tk_pid = atomic_inc_return(&rpc_pid);
76923 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
76924 }
76925 #else
76926 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
76927 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
76928 index 8343737..677025e 100644
76929 --- a/net/sunrpc/xprtrdma/svc_rdma.c
76930 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
76931 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
76932 static unsigned int min_max_inline = 4096;
76933 static unsigned int max_max_inline = 65536;
76934
76935 -atomic_t rdma_stat_recv;
76936 -atomic_t rdma_stat_read;
76937 -atomic_t rdma_stat_write;
76938 -atomic_t rdma_stat_sq_starve;
76939 -atomic_t rdma_stat_rq_starve;
76940 -atomic_t rdma_stat_rq_poll;
76941 -atomic_t rdma_stat_rq_prod;
76942 -atomic_t rdma_stat_sq_poll;
76943 -atomic_t rdma_stat_sq_prod;
76944 +atomic_unchecked_t rdma_stat_recv;
76945 +atomic_unchecked_t rdma_stat_read;
76946 +atomic_unchecked_t rdma_stat_write;
76947 +atomic_unchecked_t rdma_stat_sq_starve;
76948 +atomic_unchecked_t rdma_stat_rq_starve;
76949 +atomic_unchecked_t rdma_stat_rq_poll;
76950 +atomic_unchecked_t rdma_stat_rq_prod;
76951 +atomic_unchecked_t rdma_stat_sq_poll;
76952 +atomic_unchecked_t rdma_stat_sq_prod;
76953
76954 /* Temporary NFS request map and context caches */
76955 struct kmem_cache *svc_rdma_map_cachep;
76956 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
76957 len -= *ppos;
76958 if (len > *lenp)
76959 len = *lenp;
76960 - if (len && copy_to_user(buffer, str_buf, len))
76961 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
76962 return -EFAULT;
76963 *lenp = len;
76964 *ppos += len;
76965 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
76966 {
76967 .procname = "rdma_stat_read",
76968 .data = &rdma_stat_read,
76969 - .maxlen = sizeof(atomic_t),
76970 + .maxlen = sizeof(atomic_unchecked_t),
76971 .mode = 0644,
76972 .proc_handler = read_reset_stat,
76973 },
76974 {
76975 .procname = "rdma_stat_recv",
76976 .data = &rdma_stat_recv,
76977 - .maxlen = sizeof(atomic_t),
76978 + .maxlen = sizeof(atomic_unchecked_t),
76979 .mode = 0644,
76980 .proc_handler = read_reset_stat,
76981 },
76982 {
76983 .procname = "rdma_stat_write",
76984 .data = &rdma_stat_write,
76985 - .maxlen = sizeof(atomic_t),
76986 + .maxlen = sizeof(atomic_unchecked_t),
76987 .mode = 0644,
76988 .proc_handler = read_reset_stat,
76989 },
76990 {
76991 .procname = "rdma_stat_sq_starve",
76992 .data = &rdma_stat_sq_starve,
76993 - .maxlen = sizeof(atomic_t),
76994 + .maxlen = sizeof(atomic_unchecked_t),
76995 .mode = 0644,
76996 .proc_handler = read_reset_stat,
76997 },
76998 {
76999 .procname = "rdma_stat_rq_starve",
77000 .data = &rdma_stat_rq_starve,
77001 - .maxlen = sizeof(atomic_t),
77002 + .maxlen = sizeof(atomic_unchecked_t),
77003 .mode = 0644,
77004 .proc_handler = read_reset_stat,
77005 },
77006 {
77007 .procname = "rdma_stat_rq_poll",
77008 .data = &rdma_stat_rq_poll,
77009 - .maxlen = sizeof(atomic_t),
77010 + .maxlen = sizeof(atomic_unchecked_t),
77011 .mode = 0644,
77012 .proc_handler = read_reset_stat,
77013 },
77014 {
77015 .procname = "rdma_stat_rq_prod",
77016 .data = &rdma_stat_rq_prod,
77017 - .maxlen = sizeof(atomic_t),
77018 + .maxlen = sizeof(atomic_unchecked_t),
77019 .mode = 0644,
77020 .proc_handler = read_reset_stat,
77021 },
77022 {
77023 .procname = "rdma_stat_sq_poll",
77024 .data = &rdma_stat_sq_poll,
77025 - .maxlen = sizeof(atomic_t),
77026 + .maxlen = sizeof(atomic_unchecked_t),
77027 .mode = 0644,
77028 .proc_handler = read_reset_stat,
77029 },
77030 {
77031 .procname = "rdma_stat_sq_prod",
77032 .data = &rdma_stat_sq_prod,
77033 - .maxlen = sizeof(atomic_t),
77034 + .maxlen = sizeof(atomic_unchecked_t),
77035 .mode = 0644,
77036 .proc_handler = read_reset_stat,
77037 },
77038 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
77039 index 41cb63b..c4a1489 100644
77040 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
77041 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
77042 @@ -501,7 +501,7 @@ next_sge:
77043 svc_rdma_put_context(ctxt, 0);
77044 goto out;
77045 }
77046 - atomic_inc(&rdma_stat_read);
77047 + atomic_inc_unchecked(&rdma_stat_read);
77048
77049 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
77050 chl_map->ch[ch_no].count -= read_wr.num_sge;
77051 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
77052 dto_q);
77053 list_del_init(&ctxt->dto_q);
77054 } else {
77055 - atomic_inc(&rdma_stat_rq_starve);
77056 + atomic_inc_unchecked(&rdma_stat_rq_starve);
77057 clear_bit(XPT_DATA, &xprt->xpt_flags);
77058 ctxt = NULL;
77059 }
77060 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
77061 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
77062 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
77063 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
77064 - atomic_inc(&rdma_stat_recv);
77065 + atomic_inc_unchecked(&rdma_stat_recv);
77066
77067 /* Build up the XDR from the receive buffers. */
77068 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
77069 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
77070 index 42eb7ba..c887c45 100644
77071 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
77072 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
77073 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
77074 write_wr.wr.rdma.remote_addr = to;
77075
77076 /* Post It */
77077 - atomic_inc(&rdma_stat_write);
77078 + atomic_inc_unchecked(&rdma_stat_write);
77079 if (svc_rdma_send(xprt, &write_wr))
77080 goto err;
77081 return 0;
77082 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
77083 index 73b428b..5f3f8f3 100644
77084 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
77085 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
77086 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
77087 return;
77088
77089 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
77090 - atomic_inc(&rdma_stat_rq_poll);
77091 + atomic_inc_unchecked(&rdma_stat_rq_poll);
77092
77093 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
77094 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
77095 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
77096 }
77097
77098 if (ctxt)
77099 - atomic_inc(&rdma_stat_rq_prod);
77100 + atomic_inc_unchecked(&rdma_stat_rq_prod);
77101
77102 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
77103 /*
77104 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
77105 return;
77106
77107 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
77108 - atomic_inc(&rdma_stat_sq_poll);
77109 + atomic_inc_unchecked(&rdma_stat_sq_poll);
77110 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
77111 if (wc.status != IB_WC_SUCCESS)
77112 /* Close the transport */
77113 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
77114 }
77115
77116 if (ctxt)
77117 - atomic_inc(&rdma_stat_sq_prod);
77118 + atomic_inc_unchecked(&rdma_stat_sq_prod);
77119 }
77120
77121 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
77122 @@ -1266,7 +1266,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
77123 spin_lock_bh(&xprt->sc_lock);
77124 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
77125 spin_unlock_bh(&xprt->sc_lock);
77126 - atomic_inc(&rdma_stat_sq_starve);
77127 + atomic_inc_unchecked(&rdma_stat_sq_starve);
77128
77129 /* See if we can opportunistically reap SQ WR to make room */
77130 sq_cq_reap(xprt);
77131 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
77132 index c3e65ae..f512a2b 100644
77133 --- a/net/sysctl_net.c
77134 +++ b/net/sysctl_net.c
77135 @@ -47,7 +47,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
77136 struct ctl_table *table)
77137 {
77138 /* Allow network administrator to have same access as root. */
77139 - if (capable(CAP_NET_ADMIN)) {
77140 + if (capable_nolog(CAP_NET_ADMIN)) {
77141 int mode = (table->mode >> 6) & 7;
77142 return (mode << 6) | (mode << 3) | mode;
77143 }
77144 diff --git a/net/tipc/link.c b/net/tipc/link.c
77145 index b4b9b30..5b62131 100644
77146 --- a/net/tipc/link.c
77147 +++ b/net/tipc/link.c
77148 @@ -1203,7 +1203,7 @@ static int link_send_sections_long(struct tipc_port *sender,
77149 struct tipc_msg fragm_hdr;
77150 struct sk_buff *buf, *buf_chain, *prev;
77151 u32 fragm_crs, fragm_rest, hsz, sect_rest;
77152 - const unchar *sect_crs;
77153 + const unchar __user *sect_crs;
77154 int curr_sect;
77155 u32 fragm_no;
77156
77157 @@ -1247,7 +1247,7 @@ again:
77158
77159 if (!sect_rest) {
77160 sect_rest = msg_sect[++curr_sect].iov_len;
77161 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
77162 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
77163 }
77164
77165 if (sect_rest < fragm_rest)
77166 @@ -1266,7 +1266,7 @@ error:
77167 }
77168 } else
77169 skb_copy_to_linear_data_offset(buf, fragm_crs,
77170 - sect_crs, sz);
77171 + (const void __force_kernel *)sect_crs, sz);
77172 sect_crs += sz;
77173 sect_rest -= sz;
77174 fragm_crs += sz;
77175 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
77176 index e3afe16..333ea83 100644
77177 --- a/net/tipc/msg.c
77178 +++ b/net/tipc/msg.c
77179 @@ -99,7 +99,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
77180 msg_sect[cnt].iov_len);
77181 else
77182 skb_copy_to_linear_data_offset(*buf, pos,
77183 - msg_sect[cnt].iov_base,
77184 + (const void __force_kernel *)msg_sect[cnt].iov_base,
77185 msg_sect[cnt].iov_len);
77186 pos += msg_sect[cnt].iov_len;
77187 }
77188 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
77189 index b2964e9..fdf2e27 100644
77190 --- a/net/tipc/subscr.c
77191 +++ b/net/tipc/subscr.c
77192 @@ -101,7 +101,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
77193 {
77194 struct iovec msg_sect;
77195
77196 - msg_sect.iov_base = (void *)&sub->evt;
77197 + msg_sect.iov_base = (void __force_user *)&sub->evt;
77198 msg_sect.iov_len = sizeof(struct tipc_event);
77199
77200 sub->evt.event = htohl(event, sub->swap);
77201 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
77202 index d510353..26c8a32 100644
77203 --- a/net/unix/af_unix.c
77204 +++ b/net/unix/af_unix.c
77205 @@ -779,6 +779,12 @@ static struct sock *unix_find_other(struct net *net,
77206 err = -ECONNREFUSED;
77207 if (!S_ISSOCK(inode->i_mode))
77208 goto put_fail;
77209 +
77210 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
77211 + err = -EACCES;
77212 + goto put_fail;
77213 + }
77214 +
77215 u = unix_find_socket_byinode(inode);
77216 if (!u)
77217 goto put_fail;
77218 @@ -799,6 +805,13 @@ static struct sock *unix_find_other(struct net *net,
77219 if (u) {
77220 struct dentry *dentry;
77221 dentry = unix_sk(u)->path.dentry;
77222 +
77223 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
77224 + err = -EPERM;
77225 + sock_put(u);
77226 + goto fail;
77227 + }
77228 +
77229 if (dentry)
77230 touch_atime(&unix_sk(u)->path);
77231 } else
77232 @@ -881,11 +894,18 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
77233 err = security_path_mknod(&path, dentry, mode, 0);
77234 if (err)
77235 goto out_mknod_drop_write;
77236 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
77237 + err = -EACCES;
77238 + goto out_mknod_drop_write;
77239 + }
77240 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
77241 out_mknod_drop_write:
77242 mnt_drop_write(path.mnt);
77243 if (err)
77244 goto out_mknod_dput;
77245 +
77246 + gr_handle_create(dentry, path.mnt);
77247 +
77248 mutex_unlock(&path.dentry->d_inode->i_mutex);
77249 dput(path.dentry);
77250 path.dentry = dentry;
77251 diff --git a/net/wireless/core.h b/net/wireless/core.h
77252 index 3ac2dd0..fbe533e 100644
77253 --- a/net/wireless/core.h
77254 +++ b/net/wireless/core.h
77255 @@ -27,7 +27,7 @@ struct cfg80211_registered_device {
77256 struct mutex mtx;
77257
77258 /* rfkill support */
77259 - struct rfkill_ops rfkill_ops;
77260 + rfkill_ops_no_const rfkill_ops;
77261 struct rfkill *rfkill;
77262 struct work_struct rfkill_sync;
77263
77264 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
77265 index af648e0..6185d3a 100644
77266 --- a/net/wireless/wext-core.c
77267 +++ b/net/wireless/wext-core.c
77268 @@ -747,8 +747,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
77269 */
77270
77271 /* Support for very large requests */
77272 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
77273 - (user_length > descr->max_tokens)) {
77274 + if (user_length > descr->max_tokens) {
77275 /* Allow userspace to GET more than max so
77276 * we can support any size GET requests.
77277 * There is still a limit : -ENOMEM.
77278 @@ -787,22 +786,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
77279 }
77280 }
77281
77282 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
77283 - /*
77284 - * If this is a GET, but not NOMAX, it means that the extra
77285 - * data is not bounded by userspace, but by max_tokens. Thus
77286 - * set the length to max_tokens. This matches the extra data
77287 - * allocation.
77288 - * The driver should fill it with the number of tokens it
77289 - * provided, and it may check iwp->length rather than having
77290 - * knowledge of max_tokens. If the driver doesn't change the
77291 - * iwp->length, this ioctl just copies back max_token tokens
77292 - * filled with zeroes. Hopefully the driver isn't claiming
77293 - * them to be valid data.
77294 - */
77295 - iwp->length = descr->max_tokens;
77296 - }
77297 -
77298 err = handler(dev, info, (union iwreq_data *) iwp, extra);
77299
77300 iwp->length += essid_compat;
77301 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
77302 index a15d2a0..12142af 100644
77303 --- a/net/xfrm/xfrm_policy.c
77304 +++ b/net/xfrm/xfrm_policy.c
77305 @@ -299,7 +299,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
77306 {
77307 policy->walk.dead = 1;
77308
77309 - atomic_inc(&policy->genid);
77310 + atomic_inc_unchecked(&policy->genid);
77311
77312 if (del_timer(&policy->timer))
77313 xfrm_pol_put(policy);
77314 @@ -583,7 +583,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
77315 hlist_add_head(&policy->bydst, chain);
77316 xfrm_pol_hold(policy);
77317 net->xfrm.policy_count[dir]++;
77318 - atomic_inc(&flow_cache_genid);
77319 + atomic_inc_unchecked(&flow_cache_genid);
77320 if (delpol)
77321 __xfrm_policy_unlink(delpol, dir);
77322 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
77323 @@ -1530,7 +1530,7 @@ free_dst:
77324 goto out;
77325 }
77326
77327 -static int inline
77328 +static inline int
77329 xfrm_dst_alloc_copy(void **target, const void *src, int size)
77330 {
77331 if (!*target) {
77332 @@ -1542,7 +1542,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
77333 return 0;
77334 }
77335
77336 -static int inline
77337 +static inline int
77338 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
77339 {
77340 #ifdef CONFIG_XFRM_SUB_POLICY
77341 @@ -1554,7 +1554,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
77342 #endif
77343 }
77344
77345 -static int inline
77346 +static inline int
77347 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
77348 {
77349 #ifdef CONFIG_XFRM_SUB_POLICY
77350 @@ -1648,7 +1648,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
77351
77352 xdst->num_pols = num_pols;
77353 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
77354 - xdst->policy_genid = atomic_read(&pols[0]->genid);
77355 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
77356
77357 return xdst;
77358 }
77359 @@ -2348,7 +2348,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
77360 if (xdst->xfrm_genid != dst->xfrm->genid)
77361 return 0;
77362 if (xdst->num_pols > 0 &&
77363 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
77364 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
77365 return 0;
77366
77367 mtu = dst_mtu(dst->child);
77368 @@ -2885,7 +2885,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
77369 sizeof(pol->xfrm_vec[i].saddr));
77370 pol->xfrm_vec[i].encap_family = mp->new_family;
77371 /* flush bundles */
77372 - atomic_inc(&pol->genid);
77373 + atomic_inc_unchecked(&pol->genid);
77374 }
77375 }
77376
77377 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
77378 index ff1720d..ed8475e 100644
77379 --- a/scripts/Makefile.build
77380 +++ b/scripts/Makefile.build
77381 @@ -111,7 +111,7 @@ endif
77382 endif
77383
77384 # Do not include host rules unless needed
77385 -ifneq ($(hostprogs-y)$(hostprogs-m),)
77386 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
77387 include scripts/Makefile.host
77388 endif
77389
77390 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
77391 index 686cb0d..9d653bf 100644
77392 --- a/scripts/Makefile.clean
77393 +++ b/scripts/Makefile.clean
77394 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
77395 __clean-files := $(extra-y) $(always) \
77396 $(targets) $(clean-files) \
77397 $(host-progs) \
77398 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
77399 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
77400 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
77401
77402 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
77403
77404 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
77405 index 1ac414f..38575f7 100644
77406 --- a/scripts/Makefile.host
77407 +++ b/scripts/Makefile.host
77408 @@ -31,6 +31,8 @@
77409 # Note: Shared libraries consisting of C++ files are not supported
77410
77411 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
77412 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
77413 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
77414
77415 # C code
77416 # Executables compiled from a single .c file
77417 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
77418 # Shared libaries (only .c supported)
77419 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
77420 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
77421 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
77422 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
77423 # Remove .so files from "xxx-objs"
77424 host-cobjs := $(filter-out %.so,$(host-cobjs))
77425 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
77426
77427 -#Object (.o) files used by the shared libaries
77428 +# Object (.o) files used by the shared libaries
77429 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
77430 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
77431
77432 # output directory for programs/.o files
77433 # hostprogs-y := tools/build may have been specified. Retrieve directory
77434 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
77435 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
77436 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
77437 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
77438 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
77439 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
77440 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
77441 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
77442
77443 obj-dirs += $(host-objdirs)
77444 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
77445 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
77446 $(call if_changed_dep,host-cshobjs)
77447
77448 +# Compile .c file, create position independent .o file
77449 +# host-cxxshobjs -> .o
77450 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
77451 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
77452 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
77453 + $(call if_changed_dep,host-cxxshobjs)
77454 +
77455 # Link a shared library, based on position independent .o files
77456 # *.o -> .so shared library (host-cshlib)
77457 quiet_cmd_host-cshlib = HOSTLLD -shared $@
77458 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
77459 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
77460 $(call if_changed,host-cshlib)
77461
77462 +# Link a shared library, based on position independent .o files
77463 +# *.o -> .so shared library (host-cxxshlib)
77464 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
77465 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
77466 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
77467 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
77468 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
77469 + $(call if_changed,host-cxxshlib)
77470 +
77471 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
77472 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
77473 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
77474
77475 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
77476 index cb1f50c..cef2a7c 100644
77477 --- a/scripts/basic/fixdep.c
77478 +++ b/scripts/basic/fixdep.c
77479 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
77480 /*
77481 * Lookup a value in the configuration string.
77482 */
77483 -static int is_defined_config(const char *name, int len, unsigned int hash)
77484 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
77485 {
77486 struct item *aux;
77487
77488 @@ -211,10 +211,10 @@ static void clear_config(void)
77489 /*
77490 * Record the use of a CONFIG_* word.
77491 */
77492 -static void use_config(const char *m, int slen)
77493 +static void use_config(const char *m, unsigned int slen)
77494 {
77495 unsigned int hash = strhash(m, slen);
77496 - int c, i;
77497 + unsigned int c, i;
77498
77499 if (is_defined_config(m, slen, hash))
77500 return;
77501 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
77502
77503 static void parse_config_file(const char *map, size_t len)
77504 {
77505 - const int *end = (const int *) (map + len);
77506 + const unsigned int *end = (const unsigned int *) (map + len);
77507 /* start at +1, so that p can never be < map */
77508 - const int *m = (const int *) map + 1;
77509 + const unsigned int *m = (const unsigned int *) map + 1;
77510 const char *p, *q;
77511
77512 for (; m < end; m++) {
77513 @@ -406,7 +406,7 @@ static void print_deps(void)
77514 static void traps(void)
77515 {
77516 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
77517 - int *p = (int *)test;
77518 + unsigned int *p = (unsigned int *)test;
77519
77520 if (*p != INT_CONF) {
77521 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
77522 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
77523 new file mode 100644
77524 index 0000000..008ac1a
77525 --- /dev/null
77526 +++ b/scripts/gcc-plugin.sh
77527 @@ -0,0 +1,17 @@
77528 +#!/bin/bash
77529 +plugincc=`$1 -x c -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
77530 +#include "gcc-plugin.h"
77531 +#include "tree.h"
77532 +#include "tm.h"
77533 +#include "rtl.h"
77534 +#ifdef ENABLE_BUILD_WITH_CXX
77535 +#warning $2
77536 +#else
77537 +#warning $1
77538 +#endif
77539 +EOF`
77540 +if [ $? -eq 0 ]
77541 +then
77542 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
77543 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
77544 +fi
77545 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
77546 index 44ddaa5..a3119bd 100644
77547 --- a/scripts/mod/file2alias.c
77548 +++ b/scripts/mod/file2alias.c
77549 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
77550 unsigned long size, unsigned long id_size,
77551 void *symval)
77552 {
77553 - int i;
77554 + unsigned int i;
77555
77556 if (size % id_size || size < id_size) {
77557 if (cross_build != 0)
77558 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
77559 /* USB is special because the bcdDevice can be matched against a numeric range */
77560 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
77561 static void do_usb_entry(struct usb_device_id *id,
77562 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
77563 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
77564 unsigned char range_lo, unsigned char range_hi,
77565 unsigned char max, struct module *mod)
77566 {
77567 @@ -259,7 +259,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
77568 {
77569 unsigned int devlo, devhi;
77570 unsigned char chi, clo, max;
77571 - int ndigits;
77572 + unsigned int ndigits;
77573
77574 id->match_flags = TO_NATIVE(id->match_flags);
77575 id->idVendor = TO_NATIVE(id->idVendor);
77576 @@ -501,7 +501,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
77577 for (i = 0; i < count; i++) {
77578 const char *id = (char *)devs[i].id;
77579 char acpi_id[sizeof(devs[0].id)];
77580 - int j;
77581 + unsigned int j;
77582
77583 buf_printf(&mod->dev_table_buf,
77584 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
77585 @@ -531,7 +531,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
77586
77587 for (j = 0; j < PNP_MAX_DEVICES; j++) {
77588 const char *id = (char *)card->devs[j].id;
77589 - int i2, j2;
77590 + unsigned int i2, j2;
77591 int dup = 0;
77592
77593 if (!id[0])
77594 @@ -557,7 +557,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
77595 /* add an individual alias for every device entry */
77596 if (!dup) {
77597 char acpi_id[sizeof(card->devs[0].id)];
77598 - int k;
77599 + unsigned int k;
77600
77601 buf_printf(&mod->dev_table_buf,
77602 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
77603 @@ -882,7 +882,7 @@ static void dmi_ascii_filter(char *d, const char *s)
77604 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
77605 char *alias)
77606 {
77607 - int i, j;
77608 + unsigned int i, j;
77609
77610 sprintf(alias, "dmi*");
77611
77612 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
77613 index c4e7d15..4241aef 100644
77614 --- a/scripts/mod/modpost.c
77615 +++ b/scripts/mod/modpost.c
77616 @@ -922,6 +922,7 @@ enum mismatch {
77617 ANY_INIT_TO_ANY_EXIT,
77618 ANY_EXIT_TO_ANY_INIT,
77619 EXPORT_TO_INIT_EXIT,
77620 + DATA_TO_TEXT
77621 };
77622
77623 struct sectioncheck {
77624 @@ -1030,6 +1031,12 @@ const struct sectioncheck sectioncheck[] = {
77625 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
77626 .mismatch = EXPORT_TO_INIT_EXIT,
77627 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
77628 +},
77629 +/* Do not reference code from writable data */
77630 +{
77631 + .fromsec = { DATA_SECTIONS, NULL },
77632 + .tosec = { TEXT_SECTIONS, NULL },
77633 + .mismatch = DATA_TO_TEXT
77634 }
77635 };
77636
77637 @@ -1152,10 +1159,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
77638 continue;
77639 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
77640 continue;
77641 - if (sym->st_value == addr)
77642 - return sym;
77643 /* Find a symbol nearby - addr are maybe negative */
77644 d = sym->st_value - addr;
77645 + if (d == 0)
77646 + return sym;
77647 if (d < 0)
77648 d = addr - sym->st_value;
77649 if (d < distance) {
77650 @@ -1434,6 +1441,14 @@ static void report_sec_mismatch(const char *modname,
77651 tosym, prl_to, prl_to, tosym);
77652 free(prl_to);
77653 break;
77654 + case DATA_TO_TEXT:
77655 +/*
77656 + fprintf(stderr,
77657 + "The variable %s references\n"
77658 + "the %s %s%s%s\n",
77659 + fromsym, to, sec2annotation(tosec), tosym, to_p);
77660 +*/
77661 + break;
77662 }
77663 fprintf(stderr, "\n");
77664 }
77665 @@ -1668,7 +1683,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
77666 static void check_sec_ref(struct module *mod, const char *modname,
77667 struct elf_info *elf)
77668 {
77669 - int i;
77670 + unsigned int i;
77671 Elf_Shdr *sechdrs = elf->sechdrs;
77672
77673 /* Walk through all sections */
77674 @@ -1766,7 +1781,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
77675 va_end(ap);
77676 }
77677
77678 -void buf_write(struct buffer *buf, const char *s, int len)
77679 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
77680 {
77681 if (buf->size - buf->pos < len) {
77682 buf->size += len + SZ;
77683 @@ -1984,7 +1999,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
77684 if (fstat(fileno(file), &st) < 0)
77685 goto close_write;
77686
77687 - if (st.st_size != b->pos)
77688 + if (st.st_size != (off_t)b->pos)
77689 goto close_write;
77690
77691 tmp = NOFAIL(malloc(b->pos));
77692 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
77693 index 51207e4..f7d603d 100644
77694 --- a/scripts/mod/modpost.h
77695 +++ b/scripts/mod/modpost.h
77696 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
77697
77698 struct buffer {
77699 char *p;
77700 - int pos;
77701 - int size;
77702 + unsigned int pos;
77703 + unsigned int size;
77704 };
77705
77706 void __attribute__((format(printf, 2, 3)))
77707 buf_printf(struct buffer *buf, const char *fmt, ...);
77708
77709 void
77710 -buf_write(struct buffer *buf, const char *s, int len);
77711 +buf_write(struct buffer *buf, const char *s, unsigned int len);
77712
77713 struct module {
77714 struct module *next;
77715 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
77716 index 9dfcd6d..099068e 100644
77717 --- a/scripts/mod/sumversion.c
77718 +++ b/scripts/mod/sumversion.c
77719 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
77720 goto out;
77721 }
77722
77723 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
77724 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
77725 warn("writing sum in %s failed: %s\n",
77726 filename, strerror(errno));
77727 goto out;
77728 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
77729 index 5c11312..72742b5 100644
77730 --- a/scripts/pnmtologo.c
77731 +++ b/scripts/pnmtologo.c
77732 @@ -237,14 +237,14 @@ static void write_header(void)
77733 fprintf(out, " * Linux logo %s\n", logoname);
77734 fputs(" */\n\n", out);
77735 fputs("#include <linux/linux_logo.h>\n\n", out);
77736 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
77737 + fprintf(out, "static unsigned char %s_data[] = {\n",
77738 logoname);
77739 }
77740
77741 static void write_footer(void)
77742 {
77743 fputs("\n};\n\n", out);
77744 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
77745 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
77746 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
77747 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
77748 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
77749 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
77750 fputs("\n};\n\n", out);
77751
77752 /* write logo clut */
77753 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
77754 + fprintf(out, "static unsigned char %s_clut[] = {\n",
77755 logoname);
77756 write_hex_cnt = 0;
77757 for (i = 0; i < logo_clutsize; i++) {
77758 diff --git a/security/Kconfig b/security/Kconfig
77759 index ccc61f8..bac65f2 100644
77760 --- a/security/Kconfig
77761 +++ b/security/Kconfig
77762 @@ -4,6 +4,860 @@
77763
77764 menu "Security options"
77765
77766 +menu "Grsecurity"
77767 +
77768 + config ARCH_TRACK_EXEC_LIMIT
77769 + bool
77770 +
77771 + config PAX_KERNEXEC_PLUGIN
77772 + bool
77773 +
77774 + config PAX_PER_CPU_PGD
77775 + bool
77776 +
77777 + config TASK_SIZE_MAX_SHIFT
77778 + int
77779 + depends on X86_64
77780 + default 47 if !PAX_PER_CPU_PGD
77781 + default 42 if PAX_PER_CPU_PGD
77782 +
77783 + config PAX_ENABLE_PAE
77784 + bool
77785 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
77786 +
77787 +config GRKERNSEC
77788 + bool "Grsecurity"
77789 + select CRYPTO
77790 + select CRYPTO_SHA256
77791 + help
77792 + If you say Y here, you will be able to configure many features
77793 + that will enhance the security of your system. It is highly
77794 + recommended that you say Y here and read through the help
77795 + for each option so that you fully understand the features and
77796 + can evaluate their usefulness for your machine.
77797 +
77798 +choice
77799 + prompt "Configuration Method"
77800 + depends on GRKERNSEC
77801 + default GRKERNSEC_CONFIG_CUSTOM
77802 + help
77803 +
77804 +config GRKERNSEC_CONFIG_AUTO
77805 + bool "Automatic"
77806 + help
77807 + If you choose this configuration method, you'll be able to answer a small
77808 + number of simple questions about how you plan to use this kernel.
77809 + The settings of grsecurity and PaX will be automatically configured for
77810 + the highest commonly-used settings within the provided constraints.
77811 +
77812 + If you require additional configuration, custom changes can still be made
77813 + from the "custom configuration" menu.
77814 +
77815 +config GRKERNSEC_CONFIG_CUSTOM
77816 + bool "Custom"
77817 + help
77818 + If you choose this configuration method, you'll be able to configure all
77819 + grsecurity and PaX settings manually. Via this method, no options are
77820 + automatically enabled.
77821 +
77822 +endchoice
77823 +
77824 +choice
77825 + prompt "Usage Type"
77826 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
77827 + default GRKERNSEC_CONFIG_SERVER
77828 + help
77829 +
77830 +config GRKERNSEC_CONFIG_SERVER
77831 + bool "Server"
77832 + help
77833 + Choose this option if you plan to use this kernel on a server.
77834 +
77835 +config GRKERNSEC_CONFIG_DESKTOP
77836 + bool "Desktop"
77837 + help
77838 + Choose this option if you plan to use this kernel on a desktop.
77839 +
77840 +endchoice
77841 +
77842 +choice
77843 + prompt "Virtualization Type"
77844 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
77845 + default GRKERNSEC_CONFIG_VIRT_NONE
77846 + help
77847 +
77848 +config GRKERNSEC_CONFIG_VIRT_NONE
77849 + bool "None"
77850 + help
77851 + Choose this option if this kernel will be run on bare metal.
77852 +
77853 +config GRKERNSEC_CONFIG_VIRT_GUEST
77854 + bool "Guest"
77855 + help
77856 + Choose this option if this kernel will be run as a VM guest.
77857 +
77858 +config GRKERNSEC_CONFIG_VIRT_HOST
77859 + bool "Host"
77860 + help
77861 + Choose this option if this kernel will be run as a VM host.
77862 +
77863 +endchoice
77864 +
77865 +choice
77866 + prompt "Virtualization Hardware"
77867 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
77868 + help
77869 +
77870 +config GRKERNSEC_CONFIG_VIRT_EPT
77871 + bool "EPT/RVI Processor Support"
77872 + depends on X86
77873 + help
77874 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
77875 + hardware virtualization. This allows for additional kernel hardening protections
77876 + to operate without additional performance impact.
77877 +
77878 + To see if your Intel processor supports EPT, see:
77879 + http://ark.intel.com/Products/VirtualizationTechnology
77880 + (Most Core i3/5/7 support EPT)
77881 +
77882 + To see if your AMD processor supports RVI, see:
77883 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
77884 +
77885 +config GRKERNSEC_CONFIG_VIRT_SOFT
77886 + bool "First-gen/No Hardware Virtualization"
77887 + help
77888 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
77889 + support hardware virtualization or doesn't support the EPT/RVI extensions.
77890 +
77891 +endchoice
77892 +
77893 +choice
77894 + prompt "Virtualization Software"
77895 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
77896 + help
77897 +
77898 +config GRKERNSEC_CONFIG_VIRT_XEN
77899 + bool "Xen"
77900 + help
77901 + Choose this option if this kernel is running as a Xen guest or host.
77902 +
77903 +config GRKERNSEC_CONFIG_VIRT_VMWARE
77904 + bool "VMWare"
77905 + help
77906 + Choose this option if this kernel is running as a VMWare guest or host.
77907 +
77908 +config GRKERNSEC_CONFIG_VIRT_KVM
77909 + bool "KVM"
77910 + help
77911 + Choose this option if this kernel is running as a KVM guest or host.
77912 +
77913 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
77914 + bool "VirtualBox"
77915 + help
77916 + Choose this option if this kernel is running as a VirtualBox guest or host.
77917 +
77918 +endchoice
77919 +
77920 +choice
77921 + prompt "Required Priorities"
77922 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
77923 + default GRKERNSEC_CONFIG_PRIORITY_PERF
77924 + help
77925 +
77926 +config GRKERNSEC_CONFIG_PRIORITY_PERF
77927 + bool "Performance"
77928 + help
77929 + Choose this option if performance is of highest priority for this deployment
77930 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
77931 + and freed memory sanitizing will be disabled.
77932 +
77933 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
77934 + bool "Security"
77935 + help
77936 + Choose this option if security is of highest priority for this deployment of
77937 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
77938 + be enabled for this kernel. In a worst-case scenario, these features can
77939 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
77940 +
77941 +endchoice
77942 +
77943 +menu "Default Special Groups"
77944 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
77945 +
77946 +config GRKERNSEC_PROC_GID
77947 + int "GID exempted from /proc restrictions"
77948 + default 1001
77949 + help
77950 + Setting this GID determines which group will be exempted from
77951 + grsecurity's /proc restrictions, allowing users of the specified
77952 + group to view network statistics and the existence of other users'
77953 + processes on the system.
77954 +
77955 +config GRKERNSEC_TPE_GID
77956 + int "GID for untrusted users"
77957 + depends on GRKERNSEC_CONFIG_SERVER
77958 + default 1005
77959 + help
77960 + Setting this GID determines which group untrusted users should
77961 + be added to. These users will be placed under grsecurity's Trusted Path
77962 + Execution mechanism, preventing them from executing their own binaries.
77963 + The users will only be able to execute binaries in directories owned and
77964 + writable only by the root user.
77965 +
77966 +config GRKERNSEC_SYMLINKOWN_GID
77967 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
77968 + depends on GRKERNSEC_CONFIG_SERVER
77969 + default 1006
77970 + help
77971 + Setting this GID determines what group kernel-enforced
77972 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
77973 + is enabled, a sysctl option with name "symlinkown_gid" is created.
77974 +
77975 +
77976 +endmenu
77977 +
77978 +menu "Customize Configuration"
77979 +depends on GRKERNSEC
77980 +
77981 +menu "PaX"
77982 +
77983 +config PAX
77984 + bool "Enable various PaX features"
77985 + default y if GRKERNSEC_CONFIG_AUTO
77986 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
77987 + help
77988 + This allows you to enable various PaX features. PaX adds
77989 + intrusion prevention mechanisms to the kernel that reduce
77990 + the risks posed by exploitable memory corruption bugs.
77991 +
77992 +menu "PaX Control"
77993 + depends on PAX
77994 +
77995 +config PAX_SOFTMODE
77996 + bool 'Support soft mode'
77997 + help
77998 + Enabling this option will allow you to run PaX in soft mode, that
77999 + is, PaX features will not be enforced by default, only on executables
78000 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
78001 + support as they are the only way to mark executables for soft mode use.
78002 +
78003 + Soft mode can be activated by using the "pax_softmode=1" kernel command
78004 + line option on boot. Furthermore you can control various PaX features
78005 + at runtime via the entries in /proc/sys/kernel/pax.
78006 +
78007 +config PAX_EI_PAX
78008 + bool 'Use legacy ELF header marking'
78009 + default y if GRKERNSEC_CONFIG_AUTO
78010 + help
78011 + Enabling this option will allow you to control PaX features on
78012 + a per executable basis via the 'chpax' utility available at
78013 + http://pax.grsecurity.net/. The control flags will be read from
78014 + an otherwise reserved part of the ELF header. This marking has
78015 + numerous drawbacks (no support for soft-mode, toolchain does not
78016 + know about the non-standard use of the ELF header) therefore it
78017 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
78018 + support.
78019 +
78020 + If you have applications not marked by the PT_PAX_FLAGS ELF program
78021 + header and you cannot use XATTR_PAX_FLAGS then you MUST enable this
78022 + option otherwise they will not get any protection.
78023 +
78024 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
78025 + support as well, they will override the legacy EI_PAX marks.
78026 +
78027 +config PAX_PT_PAX_FLAGS
78028 + bool 'Use ELF program header marking'
78029 + default y if GRKERNSEC_CONFIG_AUTO
78030 + help
78031 + Enabling this option will allow you to control PaX features on
78032 + a per executable basis via the 'paxctl' utility available at
78033 + http://pax.grsecurity.net/. The control flags will be read from
78034 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
78035 + has the benefits of supporting both soft mode and being fully
78036 + integrated into the toolchain (the binutils patch is available
78037 + from http://pax.grsecurity.net).
78038 +
78039 + If you have applications not marked by the PT_PAX_FLAGS ELF program
78040 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
78041 + support otherwise they will not get any protection.
78042 +
78043 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
78044 + must make sure that the marks are the same if a binary has both marks.
78045 +
78046 + Note that if you enable the legacy EI_PAX marking support as well,
78047 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
78048 +
78049 +config PAX_XATTR_PAX_FLAGS
78050 + bool 'Use filesystem extended attributes marking'
78051 + default y if GRKERNSEC_CONFIG_AUTO
78052 + select CIFS_XATTR if CIFS
78053 + select EXT2_FS_XATTR if EXT2_FS
78054 + select EXT3_FS_XATTR if EXT3_FS
78055 + select EXT4_FS_XATTR if EXT4_FS
78056 + select JFFS2_FS_XATTR if JFFS2_FS
78057 + select REISERFS_FS_XATTR if REISERFS_FS
78058 + select SQUASHFS_XATTR if SQUASHFS
78059 + select TMPFS_XATTR if TMPFS
78060 + select UBIFS_FS_XATTR if UBIFS_FS
78061 + help
78062 + Enabling this option will allow you to control PaX features on
78063 + a per executable basis via the 'setfattr' utility. The control
78064 + flags will be read from the user.pax.flags extended attribute of
78065 + the file. This marking has the benefit of supporting binary-only
78066 + applications that self-check themselves (e.g., skype) and would
78067 + not tolerate chpax/paxctl changes. The main drawback is that
78068 + extended attributes are not supported by some filesystems (e.g.,
78069 + isofs, udf, vfat) so copying files through such filesystems will
78070 + lose the extended attributes and these PaX markings.
78071 +
78072 + If you have applications not marked by the PT_PAX_FLAGS ELF program
78073 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
78074 + support otherwise they will not get any protection.
78075 +
78076 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
78077 + must make sure that the marks are the same if a binary has both marks.
78078 +
78079 + Note that if you enable the legacy EI_PAX marking support as well,
78080 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
78081 +
78082 +choice
78083 + prompt 'MAC system integration'
78084 + default PAX_HAVE_ACL_FLAGS
78085 + help
78086 + Mandatory Access Control systems have the option of controlling
78087 + PaX flags on a per executable basis, choose the method supported
78088 + by your particular system.
78089 +
78090 + - "none": if your MAC system does not interact with PaX,
78091 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
78092 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
78093 +
78094 + NOTE: this option is for developers/integrators only.
78095 +
78096 + config PAX_NO_ACL_FLAGS
78097 + bool 'none'
78098 +
78099 + config PAX_HAVE_ACL_FLAGS
78100 + bool 'direct'
78101 +
78102 + config PAX_HOOK_ACL_FLAGS
78103 + bool 'hook'
78104 +endchoice
78105 +
78106 +endmenu
78107 +
78108 +menu "Non-executable pages"
78109 + depends on PAX
78110 +
78111 +config PAX_NOEXEC
78112 + bool "Enforce non-executable pages"
78113 + default y if GRKERNSEC_CONFIG_AUTO
78114 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
78115 + help
78116 + By design some architectures do not allow for protecting memory
78117 + pages against execution or even if they do, Linux does not make
78118 + use of this feature. In practice this means that if a page is
78119 + readable (such as the stack or heap) it is also executable.
78120 +
78121 + There is a well known exploit technique that makes use of this
78122 + fact and a common programming mistake where an attacker can
78123 + introduce code of his choice somewhere in the attacked program's
78124 + memory (typically the stack or the heap) and then execute it.
78125 +
78126 + If the attacked program was running with different (typically
78127 + higher) privileges than that of the attacker, then he can elevate
78128 + his own privilege level (e.g. get a root shell, write to files for
78129 + which he does not have write access to, etc).
78130 +
78131 + Enabling this option will let you choose from various features
78132 + that prevent the injection and execution of 'foreign' code in
78133 + a program.
78134 +
78135 + This will also break programs that rely on the old behaviour and
78136 + expect that dynamically allocated memory via the malloc() family
78137 + of functions is executable (which it is not). Notable examples
78138 + are the XFree86 4.x server, the java runtime and wine.
78139 +
78140 +config PAX_PAGEEXEC
78141 + bool "Paging based non-executable pages"
78142 + default y if GRKERNSEC_CONFIG_AUTO
78143 + 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)
78144 + select S390_SWITCH_AMODE if S390
78145 + select S390_EXEC_PROTECT if S390
78146 + select ARCH_TRACK_EXEC_LIMIT if X86_32
78147 + help
78148 + This implementation is based on the paging feature of the CPU.
78149 + On i386 without hardware non-executable bit support there is a
78150 + variable but usually low performance impact, however on Intel's
78151 + P4 core based CPUs it is very high so you should not enable this
78152 + for kernels meant to be used on such CPUs.
78153 +
78154 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
78155 + with hardware non-executable bit support there is no performance
78156 + impact, on ppc the impact is negligible.
78157 +
78158 + Note that several architectures require various emulations due to
78159 + badly designed userland ABIs, this will cause a performance impact
78160 + but will disappear as soon as userland is fixed. For example, ppc
78161 + userland MUST have been built with secure-plt by a recent toolchain.
78162 +
78163 +config PAX_SEGMEXEC
78164 + bool "Segmentation based non-executable pages"
78165 + default y if GRKERNSEC_CONFIG_AUTO
78166 + depends on PAX_NOEXEC && X86_32
78167 + help
78168 + This implementation is based on the segmentation feature of the
78169 + CPU and has a very small performance impact, however applications
78170 + will be limited to a 1.5 GB address space instead of the normal
78171 + 3 GB.
78172 +
78173 +config PAX_EMUTRAMP
78174 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
78175 + default y if PARISC
78176 + help
78177 + There are some programs and libraries that for one reason or
78178 + another attempt to execute special small code snippets from
78179 + non-executable memory pages. Most notable examples are the
78180 + signal handler return code generated by the kernel itself and
78181 + the GCC trampolines.
78182 +
78183 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
78184 + such programs will no longer work under your kernel.
78185 +
78186 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
78187 + utilities to enable trampoline emulation for the affected programs
78188 + yet still have the protection provided by the non-executable pages.
78189 +
78190 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
78191 + your system will not even boot.
78192 +
78193 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
78194 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
78195 + for the affected files.
78196 +
78197 + NOTE: enabling this feature *may* open up a loophole in the
78198 + protection provided by non-executable pages that an attacker
78199 + could abuse. Therefore the best solution is to not have any
78200 + files on your system that would require this option. This can
78201 + be achieved by not using libc5 (which relies on the kernel
78202 + signal handler return code) and not using or rewriting programs
78203 + that make use of the nested function implementation of GCC.
78204 + Skilled users can just fix GCC itself so that it implements
78205 + nested function calls in a way that does not interfere with PaX.
78206 +
78207 +config PAX_EMUSIGRT
78208 + bool "Automatically emulate sigreturn trampolines"
78209 + depends on PAX_EMUTRAMP && PARISC
78210 + default y
78211 + help
78212 + Enabling this option will have the kernel automatically detect
78213 + and emulate signal return trampolines executing on the stack
78214 + that would otherwise lead to task termination.
78215 +
78216 + This solution is intended as a temporary one for users with
78217 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
78218 + Modula-3 runtime, etc) or executables linked to such, basically
78219 + everything that does not specify its own SA_RESTORER function in
78220 + normal executable memory like glibc 2.1+ does.
78221 +
78222 + On parisc you MUST enable this option, otherwise your system will
78223 + not even boot.
78224 +
78225 + NOTE: this feature cannot be disabled on a per executable basis
78226 + and since it *does* open up a loophole in the protection provided
78227 + by non-executable pages, the best solution is to not have any
78228 + files on your system that would require this option.
78229 +
78230 +config PAX_MPROTECT
78231 + bool "Restrict mprotect()"
78232 + default y if GRKERNSEC_CONFIG_AUTO
78233 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
78234 + help
78235 + Enabling this option will prevent programs from
78236 + - changing the executable status of memory pages that were
78237 + not originally created as executable,
78238 + - making read-only executable pages writable again,
78239 + - creating executable pages from anonymous memory,
78240 + - making read-only-after-relocations (RELRO) data pages writable again.
78241 +
78242 + You should say Y here to complete the protection provided by
78243 + the enforcement of non-executable pages.
78244 +
78245 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
78246 + this feature on a per file basis.
78247 +
78248 +config PAX_MPROTECT_COMPAT
78249 + bool "Use legacy/compat protection demoting (read help)"
78250 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
78251 + depends on PAX_MPROTECT
78252 + help
78253 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
78254 + by sending the proper error code to the application. For some broken
78255 + userland, this can cause problems with Python or other applications. The
78256 + current implementation however allows for applications like clamav to
78257 + detect if JIT compilation/execution is allowed and to fall back gracefully
78258 + to an interpreter-based mode if it does not. While we encourage everyone
78259 + to use the current implementation as-is and push upstream to fix broken
78260 + userland (note that the RWX logging option can assist with this), in some
78261 + environments this may not be possible. Having to disable MPROTECT
78262 + completely on certain binaries reduces the security benefit of PaX,
78263 + so this option is provided for those environments to revert to the old
78264 + behavior.
78265 +
78266 +config PAX_ELFRELOCS
78267 + bool "Allow ELF text relocations (read help)"
78268 + depends on PAX_MPROTECT
78269 + default n
78270 + help
78271 + Non-executable pages and mprotect() restrictions are effective
78272 + in preventing the introduction of new executable code into an
78273 + attacked task's address space. There remain only two venues
78274 + for this kind of attack: if the attacker can execute already
78275 + existing code in the attacked task then he can either have it
78276 + create and mmap() a file containing his code or have it mmap()
78277 + an already existing ELF library that does not have position
78278 + independent code in it and use mprotect() on it to make it
78279 + writable and copy his code there. While protecting against
78280 + the former approach is beyond PaX, the latter can be prevented
78281 + by having only PIC ELF libraries on one's system (which do not
78282 + need to relocate their code). If you are sure this is your case,
78283 + as is the case with all modern Linux distributions, then leave
78284 + this option disabled. You should say 'n' here.
78285 +
78286 +config PAX_ETEXECRELOCS
78287 + bool "Allow ELF ET_EXEC text relocations"
78288 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
78289 + select PAX_ELFRELOCS
78290 + default y
78291 + help
78292 + On some architectures there are incorrectly created applications
78293 + that require text relocations and would not work without enabling
78294 + this option. If you are an alpha, ia64 or parisc user, you should
78295 + enable this option and disable it once you have made sure that
78296 + none of your applications need it.
78297 +
78298 +config PAX_EMUPLT
78299 + bool "Automatically emulate ELF PLT"
78300 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
78301 + default y
78302 + help
78303 + Enabling this option will have the kernel automatically detect
78304 + and emulate the Procedure Linkage Table entries in ELF files.
78305 + On some architectures such entries are in writable memory, and
78306 + become non-executable leading to task termination. Therefore
78307 + it is mandatory that you enable this option on alpha, parisc,
78308 + sparc and sparc64, otherwise your system would not even boot.
78309 +
78310 + NOTE: this feature *does* open up a loophole in the protection
78311 + provided by the non-executable pages, therefore the proper
78312 + solution is to modify the toolchain to produce a PLT that does
78313 + not need to be writable.
78314 +
78315 +config PAX_DLRESOLVE
78316 + bool 'Emulate old glibc resolver stub'
78317 + depends on PAX_EMUPLT && SPARC
78318 + default n
78319 + help
78320 + This option is needed if userland has an old glibc (before 2.4)
78321 + that puts a 'save' instruction into the runtime generated resolver
78322 + stub that needs special emulation.
78323 +
78324 +config PAX_KERNEXEC
78325 + bool "Enforce non-executable kernel pages"
78326 + 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))
78327 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
78328 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
78329 + select PAX_KERNEXEC_PLUGIN if X86_64
78330 + help
78331 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
78332 + that is, enabling this option will make it harder to inject
78333 + and execute 'foreign' code in kernel memory itself.
78334 +
78335 + Note that on x86_64 kernels there is a known regression when
78336 + this feature and KVM/VMX are both enabled in the host kernel.
78337 +
78338 +choice
78339 + prompt "Return Address Instrumentation Method"
78340 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
78341 + depends on PAX_KERNEXEC_PLUGIN
78342 + help
78343 + Select the method used to instrument function pointer dereferences.
78344 + Note that binary modules cannot be instrumented by this approach.
78345 +
78346 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
78347 + bool "bts"
78348 + help
78349 + This method is compatible with binary only modules but has
78350 + a higher runtime overhead.
78351 +
78352 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
78353 + bool "or"
78354 + depends on !PARAVIRT
78355 + help
78356 + This method is incompatible with binary only modules but has
78357 + a lower runtime overhead.
78358 +endchoice
78359 +
78360 +config PAX_KERNEXEC_PLUGIN_METHOD
78361 + string
78362 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
78363 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
78364 + default ""
78365 +
78366 +config PAX_KERNEXEC_MODULE_TEXT
78367 + int "Minimum amount of memory reserved for module code"
78368 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
78369 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
78370 + depends on PAX_KERNEXEC && X86_32 && MODULES
78371 + help
78372 + Due to implementation details the kernel must reserve a fixed
78373 + amount of memory for module code at compile time that cannot be
78374 + changed at runtime. Here you can specify the minimum amount
78375 + in MB that will be reserved. Due to the same implementation
78376 + details this size will always be rounded up to the next 2/4 MB
78377 + boundary (depends on PAE) so the actually available memory for
78378 + module code will usually be more than this minimum.
78379 +
78380 + The default 4 MB should be enough for most users but if you have
78381 + an excessive number of modules (e.g., most distribution configs
78382 + compile many drivers as modules) or use huge modules such as
78383 + nvidia's kernel driver, you will need to adjust this amount.
78384 + A good rule of thumb is to look at your currently loaded kernel
78385 + modules and add up their sizes.
78386 +
78387 +endmenu
78388 +
78389 +menu "Address Space Layout Randomization"
78390 + depends on PAX
78391 +
78392 +config PAX_ASLR
78393 + bool "Address Space Layout Randomization"
78394 + default y if GRKERNSEC_CONFIG_AUTO
78395 + help
78396 + Many if not most exploit techniques rely on the knowledge of
78397 + certain addresses in the attacked program. The following options
78398 + will allow the kernel to apply a certain amount of randomization
78399 + to specific parts of the program thereby forcing an attacker to
78400 + guess them in most cases. Any failed guess will most likely crash
78401 + the attacked program which allows the kernel to detect such attempts
78402 + and react on them. PaX itself provides no reaction mechanisms,
78403 + instead it is strongly encouraged that you make use of Nergal's
78404 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
78405 + (http://www.grsecurity.net/) built-in crash detection features or
78406 + develop one yourself.
78407 +
78408 + By saying Y here you can choose to randomize the following areas:
78409 + - top of the task's kernel stack
78410 + - top of the task's userland stack
78411 + - base address for mmap() requests that do not specify one
78412 + (this includes all libraries)
78413 + - base address of the main executable
78414 +
78415 + It is strongly recommended to say Y here as address space layout
78416 + randomization has negligible impact on performance yet it provides
78417 + a very effective protection.
78418 +
78419 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
78420 + this feature on a per file basis.
78421 +
78422 +config PAX_RANDKSTACK
78423 + bool "Randomize kernel stack base"
78424 + default y if GRKERNSEC_CONFIG_AUTO
78425 + depends on X86_TSC && X86
78426 + help
78427 + By saying Y here the kernel will randomize every task's kernel
78428 + stack on every system call. This will not only force an attacker
78429 + to guess it but also prevent him from making use of possible
78430 + leaked information about it.
78431 +
78432 + Since the kernel stack is a rather scarce resource, randomization
78433 + may cause unexpected stack overflows, therefore you should very
78434 + carefully test your system. Note that once enabled in the kernel
78435 + configuration, this feature cannot be disabled on a per file basis.
78436 +
78437 +config PAX_RANDUSTACK
78438 + bool "Randomize user stack base"
78439 + default y if GRKERNSEC_CONFIG_AUTO
78440 + depends on PAX_ASLR
78441 + help
78442 + By saying Y here the kernel will randomize every task's userland
78443 + stack. The randomization is done in two steps where the second
78444 + one may apply a big amount of shift to the top of the stack and
78445 + cause problems for programs that want to use lots of memory (more
78446 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
78447 + For this reason the second step can be controlled by 'chpax' or
78448 + 'paxctl' on a per file basis.
78449 +
78450 +config PAX_RANDMMAP
78451 + bool "Randomize mmap() base"
78452 + default y if GRKERNSEC_CONFIG_AUTO
78453 + depends on PAX_ASLR
78454 + help
78455 + By saying Y here the kernel will use a randomized base address for
78456 + mmap() requests that do not specify one themselves. As a result
78457 + all dynamically loaded libraries will appear at random addresses
78458 + and therefore be harder to exploit by a technique where an attacker
78459 + attempts to execute library code for his purposes (e.g. spawn a
78460 + shell from an exploited program that is running at an elevated
78461 + privilege level).
78462 +
78463 + Furthermore, if a program is relinked as a dynamic ELF file, its
78464 + base address will be randomized as well, completing the full
78465 + randomization of the address space layout. Attacking such programs
78466 + becomes a guess game. You can find an example of doing this at
78467 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
78468 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
78469 +
78470 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
78471 + feature on a per file basis.
78472 +
78473 +endmenu
78474 +
78475 +menu "Miscellaneous hardening features"
78476 +
78477 +config PAX_MEMORY_SANITIZE
78478 + bool "Sanitize all freed memory"
78479 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
78480 + depends on !HIBERNATION
78481 + help
78482 + By saying Y here the kernel will erase memory pages as soon as they
78483 + are freed. This in turn reduces the lifetime of data stored in the
78484 + pages, making it less likely that sensitive information such as
78485 + passwords, cryptographic secrets, etc stay in memory for too long.
78486 +
78487 + This is especially useful for programs whose runtime is short, long
78488 + lived processes and the kernel itself benefit from this as long as
78489 + they operate on whole memory pages and ensure timely freeing of pages
78490 + that may hold sensitive information.
78491 +
78492 + The tradeoff is performance impact, on a single CPU system kernel
78493 + compilation sees a 3% slowdown, other systems and workloads may vary
78494 + and you are advised to test this feature on your expected workload
78495 + before deploying it.
78496 +
78497 + Note that this feature does not protect data stored in live pages,
78498 + e.g., process memory swapped to disk may stay there for a long time.
78499 +
78500 +config PAX_MEMORY_STACKLEAK
78501 + bool "Sanitize kernel stack"
78502 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
78503 + depends on X86
78504 + help
78505 + By saying Y here the kernel will erase the kernel stack before it
78506 + returns from a system call. This in turn reduces the information
78507 + that a kernel stack leak bug can reveal.
78508 +
78509 + Note that such a bug can still leak information that was put on
78510 + the stack by the current system call (the one eventually triggering
78511 + the bug) but traces of earlier system calls on the kernel stack
78512 + cannot leak anymore.
78513 +
78514 + The tradeoff is performance impact: on a single CPU system kernel
78515 + compilation sees a 1% slowdown, other systems and workloads may vary
78516 + and you are advised to test this feature on your expected workload
78517 + before deploying it.
78518 +
78519 + Note: full support for this feature requires gcc with plugin support
78520 + so make sure your compiler is at least gcc 4.5.0. Using older gcc
78521 + versions means that functions with large enough stack frames may
78522 + leave uninitialized memory behind that may be exposed to a later
78523 + syscall leaking the stack.
78524 +
78525 +config PAX_MEMORY_UDEREF
78526 + bool "Prevent invalid userland pointer dereference"
78527 + default y if GRKERNSEC_CONFIG_AUTO && (X86_32 || (X86_64 && GRKERNSEC_CONFIG_PRIORITY_SECURITY)) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
78528 + depends on X86 && !UML_X86 && !XEN
78529 + select PAX_PER_CPU_PGD if X86_64
78530 + help
78531 + By saying Y here the kernel will be prevented from dereferencing
78532 + userland pointers in contexts where the kernel expects only kernel
78533 + pointers. This is both a useful runtime debugging feature and a
78534 + security measure that prevents exploiting a class of kernel bugs.
78535 +
78536 + The tradeoff is that some virtualization solutions may experience
78537 + a huge slowdown and therefore you should not enable this feature
78538 + for kernels meant to run in such environments. Whether a given VM
78539 + solution is affected or not is best determined by simply trying it
78540 + out, the performance impact will be obvious right on boot as this
78541 + mechanism engages from very early on. A good rule of thumb is that
78542 + VMs running on CPUs without hardware virtualization support (i.e.,
78543 + the majority of IA-32 CPUs) will likely experience the slowdown.
78544 +
78545 +config PAX_REFCOUNT
78546 + bool "Prevent various kernel object reference counter overflows"
78547 + default y if GRKERNSEC_CONFIG_AUTO
78548 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
78549 + help
78550 + By saying Y here the kernel will detect and prevent overflowing
78551 + various (but not all) kinds of object reference counters. Such
78552 + overflows can normally occur due to bugs only and are often, if
78553 + not always, exploitable.
78554 +
78555 + The tradeoff is that data structures protected by an overflowed
78556 + refcount will never be freed and therefore will leak memory. Note
78557 + that this leak also happens even without this protection but in
78558 + that case the overflow can eventually trigger the freeing of the
78559 + data structure while it is still being used elsewhere, resulting
78560 + in the exploitable situation that this feature prevents.
78561 +
78562 + Since this has a negligible performance impact, you should enable
78563 + this feature.
78564 +
78565 +config PAX_USERCOPY
78566 + bool "Harden heap object copies between kernel and userland"
78567 + default y if GRKERNSEC_CONFIG_AUTO
78568 + depends on X86 || PPC || SPARC || ARM
78569 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
78570 + help
78571 + By saying Y here the kernel will enforce the size of heap objects
78572 + when they are copied in either direction between the kernel and
78573 + userland, even if only a part of the heap object is copied.
78574 +
78575 + Specifically, this checking prevents information leaking from the
78576 + kernel heap during kernel to userland copies (if the kernel heap
78577 + object is otherwise fully initialized) and prevents kernel heap
78578 + overflows during userland to kernel copies.
78579 +
78580 + Note that the current implementation provides the strictest bounds
78581 + checks for the SLUB allocator.
78582 +
78583 + Enabling this option also enables per-slab cache protection against
78584 + data in a given cache being copied into/out of via userland
78585 + accessors. Though the whitelist of regions will be reduced over
78586 + time, it notably protects important data structures like task structs.
78587 +
78588 + If frame pointers are enabled on x86, this option will also restrict
78589 + copies into and out of the kernel stack to local variables within a
78590 + single frame.
78591 +
78592 + Since this has a negligible performance impact, you should enable
78593 + this feature.
78594 +
78595 +config PAX_SIZE_OVERFLOW
78596 + bool "Prevent various integer overflows in function size parameters"
78597 + default y if GRKERNSEC_CONFIG_AUTO
78598 + depends on X86
78599 + help
78600 + By saying Y here the kernel recomputes expressions of function
78601 + arguments marked by a size_overflow attribute with double integer
78602 + precision (DImode/TImode for 32/64 bit integer types).
78603 +
78604 + The recomputed argument is checked against INT_MAX and an event
78605 + is logged on overflow and the triggering process is killed.
78606 +
78607 + Homepage:
78608 + http://www.grsecurity.net/~ephox/overflow_plugin/
78609 +
78610 +endmenu
78611 +
78612 +endmenu
78613 +
78614 +source grsecurity/Kconfig
78615 +
78616 +endmenu
78617 +
78618 +endmenu
78619 +
78620 config KEYS
78621 bool "Enable access key retention support"
78622 help
78623 @@ -169,7 +1023,7 @@ config INTEL_TXT
78624 config LSM_MMAP_MIN_ADDR
78625 int "Low address space for LSM to protect from user allocation"
78626 depends on SECURITY && SECURITY_SELINUX
78627 - default 32768 if ARM
78628 + default 32768 if ALPHA || ARM || PARISC || SPARC32
78629 default 65536
78630 help
78631 This is the portion of low virtual memory which should be protected
78632 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
78633 index ad05d39..afffccb 100644
78634 --- a/security/apparmor/lsm.c
78635 +++ b/security/apparmor/lsm.c
78636 @@ -622,7 +622,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
78637 return error;
78638 }
78639
78640 -static struct security_operations apparmor_ops = {
78641 +static struct security_operations apparmor_ops __read_only = {
78642 .name = "apparmor",
78643
78644 .ptrace_access_check = apparmor_ptrace_access_check,
78645 diff --git a/security/commoncap.c b/security/commoncap.c
78646 index 71a166a..851bb3e 100644
78647 --- a/security/commoncap.c
78648 +++ b/security/commoncap.c
78649 @@ -576,6 +576,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
78650 {
78651 const struct cred *cred = current_cred();
78652
78653 + if (gr_acl_enable_at_secure())
78654 + return 1;
78655 +
78656 if (cred->uid != 0) {
78657 if (bprm->cap_effective)
78658 return 1;
78659 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
78660 index 3ccf7ac..d73ad64 100644
78661 --- a/security/integrity/ima/ima.h
78662 +++ b/security/integrity/ima/ima.h
78663 @@ -86,8 +86,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
78664 extern spinlock_t ima_queue_lock;
78665
78666 struct ima_h_table {
78667 - atomic_long_t len; /* number of stored measurements in the list */
78668 - atomic_long_t violations;
78669 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
78670 + atomic_long_unchecked_t violations;
78671 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
78672 };
78673 extern struct ima_h_table ima_htable;
78674 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
78675 index 88a2788..581ab92 100644
78676 --- a/security/integrity/ima/ima_api.c
78677 +++ b/security/integrity/ima/ima_api.c
78678 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
78679 int result;
78680
78681 /* can overflow, only indicator */
78682 - atomic_long_inc(&ima_htable.violations);
78683 + atomic_long_inc_unchecked(&ima_htable.violations);
78684
78685 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
78686 if (!entry) {
78687 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
78688 index e1aa2b4..52027bf 100644
78689 --- a/security/integrity/ima/ima_fs.c
78690 +++ b/security/integrity/ima/ima_fs.c
78691 @@ -28,12 +28,12 @@
78692 static int valid_policy = 1;
78693 #define TMPBUFLEN 12
78694 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
78695 - loff_t *ppos, atomic_long_t *val)
78696 + loff_t *ppos, atomic_long_unchecked_t *val)
78697 {
78698 char tmpbuf[TMPBUFLEN];
78699 ssize_t len;
78700
78701 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
78702 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
78703 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
78704 }
78705
78706 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
78707 index 55a6271..ad829c3 100644
78708 --- a/security/integrity/ima/ima_queue.c
78709 +++ b/security/integrity/ima/ima_queue.c
78710 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
78711 INIT_LIST_HEAD(&qe->later);
78712 list_add_tail_rcu(&qe->later, &ima_measurements);
78713
78714 - atomic_long_inc(&ima_htable.len);
78715 + atomic_long_inc_unchecked(&ima_htable.len);
78716 key = ima_hash_key(entry->digest);
78717 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
78718 return 0;
78719 diff --git a/security/keys/compat.c b/security/keys/compat.c
78720 index 4c48e13..7abdac9 100644
78721 --- a/security/keys/compat.c
78722 +++ b/security/keys/compat.c
78723 @@ -44,7 +44,7 @@ long compat_keyctl_instantiate_key_iov(
78724 if (ret == 0)
78725 goto no_payload_free;
78726
78727 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
78728 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
78729
78730 if (iov != iovstack)
78731 kfree(iov);
78732 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
78733 index fb767c6..b9c49c0 100644
78734 --- a/security/keys/keyctl.c
78735 +++ b/security/keys/keyctl.c
78736 @@ -935,7 +935,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
78737 /*
78738 * Copy the iovec data from userspace
78739 */
78740 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
78741 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
78742 unsigned ioc)
78743 {
78744 for (; ioc > 0; ioc--) {
78745 @@ -957,7 +957,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
78746 * If successful, 0 will be returned.
78747 */
78748 long keyctl_instantiate_key_common(key_serial_t id,
78749 - const struct iovec *payload_iov,
78750 + const struct iovec __user *payload_iov,
78751 unsigned ioc,
78752 size_t plen,
78753 key_serial_t ringid)
78754 @@ -1052,7 +1052,7 @@ long keyctl_instantiate_key(key_serial_t id,
78755 [0].iov_len = plen
78756 };
78757
78758 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
78759 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
78760 }
78761
78762 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
78763 @@ -1085,7 +1085,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
78764 if (ret == 0)
78765 goto no_payload_free;
78766
78767 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
78768 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
78769
78770 if (iov != iovstack)
78771 kfree(iov);
78772 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
78773 index d605f75..2bc6be9 100644
78774 --- a/security/keys/keyring.c
78775 +++ b/security/keys/keyring.c
78776 @@ -214,15 +214,15 @@ static long keyring_read(const struct key *keyring,
78777 ret = -EFAULT;
78778
78779 for (loop = 0; loop < klist->nkeys; loop++) {
78780 + key_serial_t serial;
78781 key = klist->keys[loop];
78782 + serial = key->serial;
78783
78784 tmp = sizeof(key_serial_t);
78785 if (tmp > buflen)
78786 tmp = buflen;
78787
78788 - if (copy_to_user(buffer,
78789 - &key->serial,
78790 - tmp) != 0)
78791 + if (copy_to_user(buffer, &serial, tmp))
78792 goto error;
78793
78794 buflen -= tmp;
78795 diff --git a/security/min_addr.c b/security/min_addr.c
78796 index f728728..6457a0c 100644
78797 --- a/security/min_addr.c
78798 +++ b/security/min_addr.c
78799 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
78800 */
78801 static void update_mmap_min_addr(void)
78802 {
78803 +#ifndef SPARC
78804 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
78805 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
78806 mmap_min_addr = dac_mmap_min_addr;
78807 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
78808 #else
78809 mmap_min_addr = dac_mmap_min_addr;
78810 #endif
78811 +#endif
78812 }
78813
78814 /*
78815 diff --git a/security/security.c b/security/security.c
78816 index bf619ff..8179030 100644
78817 --- a/security/security.c
78818 +++ b/security/security.c
78819 @@ -20,6 +20,7 @@
78820 #include <linux/ima.h>
78821 #include <linux/evm.h>
78822 #include <linux/fsnotify.h>
78823 +#include <linux/mm.h>
78824 #include <net/flow.h>
78825
78826 #define MAX_LSM_EVM_XATTR 2
78827 @@ -28,8 +29,8 @@
78828 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
78829 CONFIG_DEFAULT_SECURITY;
78830
78831 -static struct security_operations *security_ops;
78832 -static struct security_operations default_security_ops = {
78833 +static struct security_operations *security_ops __read_only;
78834 +static struct security_operations default_security_ops __read_only = {
78835 .name = "default",
78836 };
78837
78838 @@ -70,7 +71,9 @@ int __init security_init(void)
78839
78840 void reset_security_ops(void)
78841 {
78842 + pax_open_kernel();
78843 security_ops = &default_security_ops;
78844 + pax_close_kernel();
78845 }
78846
78847 /* Save user chosen LSM */
78848 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
78849 index d85b793..a164832 100644
78850 --- a/security/selinux/hooks.c
78851 +++ b/security/selinux/hooks.c
78852 @@ -95,8 +95,6 @@
78853
78854 #define NUM_SEL_MNT_OPTS 5
78855
78856 -extern struct security_operations *security_ops;
78857 -
78858 /* SECMARK reference count */
78859 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
78860
78861 @@ -5520,7 +5518,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
78862
78863 #endif
78864
78865 -static struct security_operations selinux_ops = {
78866 +static struct security_operations selinux_ops __read_only = {
78867 .name = "selinux",
78868
78869 .ptrace_access_check = selinux_ptrace_access_check,
78870 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
78871 index c220f31..89fab3f 100644
78872 --- a/security/selinux/include/xfrm.h
78873 +++ b/security/selinux/include/xfrm.h
78874 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
78875
78876 static inline void selinux_xfrm_notify_policyload(void)
78877 {
78878 - atomic_inc(&flow_cache_genid);
78879 + atomic_inc_unchecked(&flow_cache_genid);
78880 }
78881 #else
78882 static inline int selinux_xfrm_enabled(void)
78883 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
78884 index 45c32f0..0038be2 100644
78885 --- a/security/smack/smack_lsm.c
78886 +++ b/security/smack/smack_lsm.c
78887 @@ -3500,7 +3500,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
78888 return 0;
78889 }
78890
78891 -struct security_operations smack_ops = {
78892 +struct security_operations smack_ops __read_only = {
78893 .name = "smack",
78894
78895 .ptrace_access_check = smack_ptrace_access_check,
78896 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
78897 index 620d37c..e2ad89b 100644
78898 --- a/security/tomoyo/tomoyo.c
78899 +++ b/security/tomoyo/tomoyo.c
78900 @@ -501,7 +501,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
78901 * tomoyo_security_ops is a "struct security_operations" which is used for
78902 * registering TOMOYO.
78903 */
78904 -static struct security_operations tomoyo_security_ops = {
78905 +static struct security_operations tomoyo_security_ops __read_only = {
78906 .name = "tomoyo",
78907 .cred_alloc_blank = tomoyo_cred_alloc_blank,
78908 .cred_prepare = tomoyo_cred_prepare,
78909 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
78910 index 51d6709..1f3dbe2 100644
78911 --- a/security/yama/Kconfig
78912 +++ b/security/yama/Kconfig
78913 @@ -1,6 +1,6 @@
78914 config SECURITY_YAMA
78915 bool "Yama support"
78916 - depends on SECURITY
78917 + depends on SECURITY && !GRKERNSEC
78918 select SECURITYFS
78919 select SECURITY_PATH
78920 default n
78921 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
78922 index 270790d..c67dfcb 100644
78923 --- a/sound/aoa/codecs/onyx.c
78924 +++ b/sound/aoa/codecs/onyx.c
78925 @@ -54,7 +54,7 @@ struct onyx {
78926 spdif_locked:1,
78927 analog_locked:1,
78928 original_mute:2;
78929 - int open_count;
78930 + local_t open_count;
78931 struct codec_info *codec_info;
78932
78933 /* mutex serializes concurrent access to the device
78934 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
78935 struct onyx *onyx = cii->codec_data;
78936
78937 mutex_lock(&onyx->mutex);
78938 - onyx->open_count++;
78939 + local_inc(&onyx->open_count);
78940 mutex_unlock(&onyx->mutex);
78941
78942 return 0;
78943 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
78944 struct onyx *onyx = cii->codec_data;
78945
78946 mutex_lock(&onyx->mutex);
78947 - onyx->open_count--;
78948 - if (!onyx->open_count)
78949 + if (local_dec_and_test(&onyx->open_count))
78950 onyx->spdif_locked = onyx->analog_locked = 0;
78951 mutex_unlock(&onyx->mutex);
78952
78953 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
78954 index ffd2025..df062c9 100644
78955 --- a/sound/aoa/codecs/onyx.h
78956 +++ b/sound/aoa/codecs/onyx.h
78957 @@ -11,6 +11,7 @@
78958 #include <linux/i2c.h>
78959 #include <asm/pmac_low_i2c.h>
78960 #include <asm/prom.h>
78961 +#include <asm/local.h>
78962
78963 /* PCM3052 register definitions */
78964
78965 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
78966 index 08fde00..0bf641a 100644
78967 --- a/sound/core/oss/pcm_oss.c
78968 +++ b/sound/core/oss/pcm_oss.c
78969 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
78970 if (in_kernel) {
78971 mm_segment_t fs;
78972 fs = snd_enter_user();
78973 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
78974 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
78975 snd_leave_user(fs);
78976 } else {
78977 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
78978 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
78979 }
78980 if (ret != -EPIPE && ret != -ESTRPIPE)
78981 break;
78982 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
78983 if (in_kernel) {
78984 mm_segment_t fs;
78985 fs = snd_enter_user();
78986 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
78987 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
78988 snd_leave_user(fs);
78989 } else {
78990 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
78991 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
78992 }
78993 if (ret == -EPIPE) {
78994 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
78995 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
78996 struct snd_pcm_plugin_channel *channels;
78997 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
78998 if (!in_kernel) {
78999 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
79000 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
79001 return -EFAULT;
79002 buf = runtime->oss.buffer;
79003 }
79004 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
79005 }
79006 } else {
79007 tmp = snd_pcm_oss_write2(substream,
79008 - (const char __force *)buf,
79009 + (const char __force_kernel *)buf,
79010 runtime->oss.period_bytes, 0);
79011 if (tmp <= 0)
79012 goto err;
79013 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
79014 struct snd_pcm_runtime *runtime = substream->runtime;
79015 snd_pcm_sframes_t frames, frames1;
79016 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
79017 - char __user *final_dst = (char __force __user *)buf;
79018 + char __user *final_dst = (char __force_user *)buf;
79019 if (runtime->oss.plugin_first) {
79020 struct snd_pcm_plugin_channel *channels;
79021 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
79022 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
79023 xfer += tmp;
79024 runtime->oss.buffer_used -= tmp;
79025 } else {
79026 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
79027 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
79028 runtime->oss.period_bytes, 0);
79029 if (tmp <= 0)
79030 goto err;
79031 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
79032 size1);
79033 size1 /= runtime->channels; /* frames */
79034 fs = snd_enter_user();
79035 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
79036 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
79037 snd_leave_user(fs);
79038 }
79039 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
79040 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
79041 index 91cdf94..4085161 100644
79042 --- a/sound/core/pcm_compat.c
79043 +++ b/sound/core/pcm_compat.c
79044 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
79045 int err;
79046
79047 fs = snd_enter_user();
79048 - err = snd_pcm_delay(substream, &delay);
79049 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
79050 snd_leave_user(fs);
79051 if (err < 0)
79052 return err;
79053 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
79054 index 3fe99e6..26952e4 100644
79055 --- a/sound/core/pcm_native.c
79056 +++ b/sound/core/pcm_native.c
79057 @@ -2770,11 +2770,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
79058 switch (substream->stream) {
79059 case SNDRV_PCM_STREAM_PLAYBACK:
79060 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
79061 - (void __user *)arg);
79062 + (void __force_user *)arg);
79063 break;
79064 case SNDRV_PCM_STREAM_CAPTURE:
79065 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
79066 - (void __user *)arg);
79067 + (void __force_user *)arg);
79068 break;
79069 default:
79070 result = -EINVAL;
79071 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
79072 index 5cf8d65..912a79c 100644
79073 --- a/sound/core/seq/seq_device.c
79074 +++ b/sound/core/seq/seq_device.c
79075 @@ -64,7 +64,7 @@ struct ops_list {
79076 int argsize; /* argument size */
79077
79078 /* operators */
79079 - struct snd_seq_dev_ops ops;
79080 + struct snd_seq_dev_ops *ops;
79081
79082 /* registred devices */
79083 struct list_head dev_list; /* list of devices */
79084 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
79085
79086 mutex_lock(&ops->reg_mutex);
79087 /* copy driver operators */
79088 - ops->ops = *entry;
79089 + ops->ops = entry;
79090 ops->driver |= DRIVER_LOADED;
79091 ops->argsize = argsize;
79092
79093 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
79094 dev->name, ops->id, ops->argsize, dev->argsize);
79095 return -EINVAL;
79096 }
79097 - if (ops->ops.init_device(dev) >= 0) {
79098 + if (ops->ops->init_device(dev) >= 0) {
79099 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
79100 ops->num_init_devices++;
79101 } else {
79102 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
79103 dev->name, ops->id, ops->argsize, dev->argsize);
79104 return -EINVAL;
79105 }
79106 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
79107 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
79108 dev->status = SNDRV_SEQ_DEVICE_FREE;
79109 dev->driver_data = NULL;
79110 ops->num_init_devices--;
79111 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
79112 index 621e60e..f4543f5 100644
79113 --- a/sound/drivers/mts64.c
79114 +++ b/sound/drivers/mts64.c
79115 @@ -29,6 +29,7 @@
79116 #include <sound/initval.h>
79117 #include <sound/rawmidi.h>
79118 #include <sound/control.h>
79119 +#include <asm/local.h>
79120
79121 #define CARD_NAME "Miditerminal 4140"
79122 #define DRIVER_NAME "MTS64"
79123 @@ -67,7 +68,7 @@ struct mts64 {
79124 struct pardevice *pardev;
79125 int pardev_claimed;
79126
79127 - int open_count;
79128 + local_t open_count;
79129 int current_midi_output_port;
79130 int current_midi_input_port;
79131 u8 mode[MTS64_NUM_INPUT_PORTS];
79132 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
79133 {
79134 struct mts64 *mts = substream->rmidi->private_data;
79135
79136 - if (mts->open_count == 0) {
79137 + if (local_read(&mts->open_count) == 0) {
79138 /* We don't need a spinlock here, because this is just called
79139 if the device has not been opened before.
79140 So there aren't any IRQs from the device */
79141 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
79142
79143 msleep(50);
79144 }
79145 - ++(mts->open_count);
79146 + local_inc(&mts->open_count);
79147
79148 return 0;
79149 }
79150 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
79151 struct mts64 *mts = substream->rmidi->private_data;
79152 unsigned long flags;
79153
79154 - --(mts->open_count);
79155 - if (mts->open_count == 0) {
79156 + if (local_dec_return(&mts->open_count) == 0) {
79157 /* We need the spinlock_irqsave here because we can still
79158 have IRQs at this point */
79159 spin_lock_irqsave(&mts->lock, flags);
79160 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
79161
79162 msleep(500);
79163
79164 - } else if (mts->open_count < 0)
79165 - mts->open_count = 0;
79166 + } else if (local_read(&mts->open_count) < 0)
79167 + local_set(&mts->open_count, 0);
79168
79169 return 0;
79170 }
79171 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
79172 index b953fb4..1999c01 100644
79173 --- a/sound/drivers/opl4/opl4_lib.c
79174 +++ b/sound/drivers/opl4/opl4_lib.c
79175 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
79176 MODULE_DESCRIPTION("OPL4 driver");
79177 MODULE_LICENSE("GPL");
79178
79179 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
79180 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
79181 {
79182 int timeout = 10;
79183 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
79184 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
79185 index 3e32bd3..46fc152 100644
79186 --- a/sound/drivers/portman2x4.c
79187 +++ b/sound/drivers/portman2x4.c
79188 @@ -48,6 +48,7 @@
79189 #include <sound/initval.h>
79190 #include <sound/rawmidi.h>
79191 #include <sound/control.h>
79192 +#include <asm/local.h>
79193
79194 #define CARD_NAME "Portman 2x4"
79195 #define DRIVER_NAME "portman"
79196 @@ -85,7 +86,7 @@ struct portman {
79197 struct pardevice *pardev;
79198 int pardev_claimed;
79199
79200 - int open_count;
79201 + local_t open_count;
79202 int mode[PORTMAN_NUM_INPUT_PORTS];
79203 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
79204 };
79205 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
79206 index 87657dd..a8268d4 100644
79207 --- a/sound/firewire/amdtp.c
79208 +++ b/sound/firewire/amdtp.c
79209 @@ -371,7 +371,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
79210 ptr = s->pcm_buffer_pointer + data_blocks;
79211 if (ptr >= pcm->runtime->buffer_size)
79212 ptr -= pcm->runtime->buffer_size;
79213 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
79214 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
79215
79216 s->pcm_period_pointer += data_blocks;
79217 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
79218 @@ -511,7 +511,7 @@ EXPORT_SYMBOL(amdtp_out_stream_start);
79219 */
79220 void amdtp_out_stream_update(struct amdtp_out_stream *s)
79221 {
79222 - ACCESS_ONCE(s->source_node_id_field) =
79223 + ACCESS_ONCE_RW(s->source_node_id_field) =
79224 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
79225 }
79226 EXPORT_SYMBOL(amdtp_out_stream_update);
79227 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
79228 index 537a9cb..8e8c8e9 100644
79229 --- a/sound/firewire/amdtp.h
79230 +++ b/sound/firewire/amdtp.h
79231 @@ -146,7 +146,7 @@ static inline void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s)
79232 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
79233 struct snd_pcm_substream *pcm)
79234 {
79235 - ACCESS_ONCE(s->pcm) = pcm;
79236 + ACCESS_ONCE_RW(s->pcm) = pcm;
79237 }
79238
79239 /**
79240 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
79241 index d428ffe..751ef78 100644
79242 --- a/sound/firewire/isight.c
79243 +++ b/sound/firewire/isight.c
79244 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
79245 ptr += count;
79246 if (ptr >= runtime->buffer_size)
79247 ptr -= runtime->buffer_size;
79248 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
79249 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
79250
79251 isight->period_counter += count;
79252 if (isight->period_counter >= runtime->period_size) {
79253 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
79254 if (err < 0)
79255 return err;
79256
79257 - ACCESS_ONCE(isight->pcm_active) = true;
79258 + ACCESS_ONCE_RW(isight->pcm_active) = true;
79259
79260 return 0;
79261 }
79262 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
79263 {
79264 struct isight *isight = substream->private_data;
79265
79266 - ACCESS_ONCE(isight->pcm_active) = false;
79267 + ACCESS_ONCE_RW(isight->pcm_active) = false;
79268
79269 mutex_lock(&isight->mutex);
79270 isight_stop_streaming(isight);
79271 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
79272
79273 switch (cmd) {
79274 case SNDRV_PCM_TRIGGER_START:
79275 - ACCESS_ONCE(isight->pcm_running) = true;
79276 + ACCESS_ONCE_RW(isight->pcm_running) = true;
79277 break;
79278 case SNDRV_PCM_TRIGGER_STOP:
79279 - ACCESS_ONCE(isight->pcm_running) = false;
79280 + ACCESS_ONCE_RW(isight->pcm_running) = false;
79281 break;
79282 default:
79283 return -EINVAL;
79284 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
79285 index 7bd5e33..1fcab12 100644
79286 --- a/sound/isa/cmi8330.c
79287 +++ b/sound/isa/cmi8330.c
79288 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
79289
79290 struct snd_pcm *pcm;
79291 struct snd_cmi8330_stream {
79292 - struct snd_pcm_ops ops;
79293 + snd_pcm_ops_no_const ops;
79294 snd_pcm_open_callback_t open;
79295 void *private_data; /* sb or wss */
79296 } streams[2];
79297 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
79298 index 733b014..56ce96f 100644
79299 --- a/sound/oss/sb_audio.c
79300 +++ b/sound/oss/sb_audio.c
79301 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
79302 buf16 = (signed short *)(localbuf + localoffs);
79303 while (c)
79304 {
79305 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
79306 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
79307 if (copy_from_user(lbuf8,
79308 userbuf+useroffs + p,
79309 locallen))
79310 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
79311 index 09d4648..cf234c7 100644
79312 --- a/sound/oss/swarm_cs4297a.c
79313 +++ b/sound/oss/swarm_cs4297a.c
79314 @@ -2606,7 +2606,6 @@ static int __init cs4297a_init(void)
79315 {
79316 struct cs4297a_state *s;
79317 u32 pwr, id;
79318 - mm_segment_t fs;
79319 int rval;
79320 #ifndef CONFIG_BCM_CS4297A_CSWARM
79321 u64 cfg;
79322 @@ -2696,22 +2695,23 @@ static int __init cs4297a_init(void)
79323 if (!rval) {
79324 char *sb1250_duart_present;
79325
79326 +#if 0
79327 + mm_segment_t fs;
79328 fs = get_fs();
79329 set_fs(KERNEL_DS);
79330 -#if 0
79331 val = SOUND_MASK_LINE;
79332 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
79333 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
79334 val = initvol[i].vol;
79335 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
79336 }
79337 + set_fs(fs);
79338 // cs4297a_write_ac97(s, 0x18, 0x0808);
79339 #else
79340 // cs4297a_write_ac97(s, 0x5e, 0x180);
79341 cs4297a_write_ac97(s, 0x02, 0x0808);
79342 cs4297a_write_ac97(s, 0x18, 0x0808);
79343 #endif
79344 - set_fs(fs);
79345
79346 list_add(&s->list, &cs4297a_devs);
79347
79348 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
79349 index 56b4f74..7cfd41a 100644
79350 --- a/sound/pci/hda/hda_codec.h
79351 +++ b/sound/pci/hda/hda_codec.h
79352 @@ -611,7 +611,7 @@ struct hda_bus_ops {
79353 /* notify power-up/down from codec to controller */
79354 void (*pm_notify)(struct hda_bus *bus);
79355 #endif
79356 -};
79357 +} __no_const;
79358
79359 /* template to pass to the bus constructor */
79360 struct hda_bus_template {
79361 @@ -713,6 +713,7 @@ struct hda_codec_ops {
79362 #endif
79363 void (*reboot_notify)(struct hda_codec *codec);
79364 };
79365 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
79366
79367 /* record for amp information cache */
79368 struct hda_cache_head {
79369 @@ -743,7 +744,7 @@ struct hda_pcm_ops {
79370 struct snd_pcm_substream *substream);
79371 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
79372 struct snd_pcm_substream *substream);
79373 -};
79374 +} __no_const;
79375
79376 /* PCM information for each substream */
79377 struct hda_pcm_stream {
79378 @@ -801,7 +802,7 @@ struct hda_codec {
79379 const char *modelname; /* model name for preset */
79380
79381 /* set by patch */
79382 - struct hda_codec_ops patch_ops;
79383 + hda_codec_ops_no_const patch_ops;
79384
79385 /* PCM to create, set by patch_ops.build_pcms callback */
79386 unsigned int num_pcms;
79387 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
79388 index 0da778a..bc38b84 100644
79389 --- a/sound/pci/ice1712/ice1712.h
79390 +++ b/sound/pci/ice1712/ice1712.h
79391 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
79392 unsigned int mask_flags; /* total mask bits */
79393 struct snd_akm4xxx_ops {
79394 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
79395 - } ops;
79396 + } __no_const ops;
79397 };
79398
79399 struct snd_ice1712_spdif {
79400 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
79401 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
79402 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
79403 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
79404 - } ops;
79405 + } __no_const ops;
79406 };
79407
79408
79409 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
79410 index a8159b81..5f006a5 100644
79411 --- a/sound/pci/ymfpci/ymfpci_main.c
79412 +++ b/sound/pci/ymfpci/ymfpci_main.c
79413 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
79414 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
79415 break;
79416 }
79417 - if (atomic_read(&chip->interrupt_sleep_count)) {
79418 - atomic_set(&chip->interrupt_sleep_count, 0);
79419 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
79420 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
79421 wake_up(&chip->interrupt_sleep);
79422 }
79423 __end:
79424 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
79425 continue;
79426 init_waitqueue_entry(&wait, current);
79427 add_wait_queue(&chip->interrupt_sleep, &wait);
79428 - atomic_inc(&chip->interrupt_sleep_count);
79429 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
79430 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
79431 remove_wait_queue(&chip->interrupt_sleep, &wait);
79432 }
79433 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
79434 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
79435 spin_unlock(&chip->reg_lock);
79436
79437 - if (atomic_read(&chip->interrupt_sleep_count)) {
79438 - atomic_set(&chip->interrupt_sleep_count, 0);
79439 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
79440 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
79441 wake_up(&chip->interrupt_sleep);
79442 }
79443 }
79444 @@ -2398,7 +2398,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
79445 spin_lock_init(&chip->reg_lock);
79446 spin_lock_init(&chip->voice_lock);
79447 init_waitqueue_head(&chip->interrupt_sleep);
79448 - atomic_set(&chip->interrupt_sleep_count, 0);
79449 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
79450 chip->card = card;
79451 chip->pci = pci;
79452 chip->irq = -1;
79453 diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
79454 index 0ad8dca..7186339 100644
79455 --- a/sound/soc/soc-pcm.c
79456 +++ b/sound/soc/soc-pcm.c
79457 @@ -641,7 +641,7 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
79458 struct snd_soc_platform *platform = rtd->platform;
79459 struct snd_soc_dai *codec_dai = rtd->codec_dai;
79460 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
79461 - struct snd_pcm_ops *soc_pcm_ops = &rtd->ops;
79462 + snd_pcm_ops_no_const *soc_pcm_ops = &rtd->ops;
79463 struct snd_pcm *pcm;
79464 char new_name[64];
79465 int ret = 0, playback = 0, capture = 0;
79466 diff --git a/sound/usb/card.h b/sound/usb/card.h
79467 index da5fa1a..113cd02 100644
79468 --- a/sound/usb/card.h
79469 +++ b/sound/usb/card.h
79470 @@ -45,6 +45,7 @@ struct snd_urb_ops {
79471 int (*prepare_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
79472 int (*retire_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
79473 };
79474 +typedef struct snd_urb_ops __no_const snd_urb_ops_no_const;
79475
79476 struct snd_usb_substream {
79477 struct snd_usb_stream *stream;
79478 @@ -94,7 +95,7 @@ struct snd_usb_substream {
79479 struct snd_pcm_hw_constraint_list rate_list; /* limited rates */
79480 spinlock_t lock;
79481
79482 - struct snd_urb_ops ops; /* callbacks (must be filled at init) */
79483 + snd_urb_ops_no_const ops; /* callbacks (must be filled at init) */
79484 int last_frame_number; /* stored frame number */
79485 int last_delay; /* stored delay */
79486 };
79487 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
79488 new file mode 100644
79489 index 0000000..f4f9986
79490 --- /dev/null
79491 +++ b/tools/gcc/Makefile
79492 @@ -0,0 +1,41 @@
79493 +#CC := gcc
79494 +#PLUGIN_SOURCE_FILES := pax_plugin.c
79495 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
79496 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
79497 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
79498 +
79499 +ifeq ($(PLUGINCC),$(HOSTCC))
79500 +HOSTLIBS := hostlibs
79501 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
79502 +else
79503 +HOSTLIBS := hostcxxlibs
79504 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
79505 +endif
79506 +
79507 +$(HOSTLIBS)-y := constify_plugin.so
79508 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
79509 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
79510 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
79511 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
79512 +$(HOSTLIBS)-y += colorize_plugin.so
79513 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
79514 +
79515 +always := $($(HOSTLIBS)-y)
79516 +
79517 +constify_plugin-objs := constify_plugin.o
79518 +stackleak_plugin-objs := stackleak_plugin.o
79519 +kallocstat_plugin-objs := kallocstat_plugin.o
79520 +kernexec_plugin-objs := kernexec_plugin.o
79521 +checker_plugin-objs := checker_plugin.o
79522 +colorize_plugin-objs := colorize_plugin.o
79523 +size_overflow_plugin-objs := size_overflow_plugin.o
79524 +
79525 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
79526 +
79527 +quiet_cmd_build_size_overflow_hash = GENHASH $@
79528 + cmd_build_size_overflow_hash = \
79529 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
79530 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
79531 + $(call if_changed,build_size_overflow_hash)
79532 +
79533 +targets += size_overflow_hash.h
79534 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
79535 new file mode 100644
79536 index 0000000..d41b5af
79537 --- /dev/null
79538 +++ b/tools/gcc/checker_plugin.c
79539 @@ -0,0 +1,171 @@
79540 +/*
79541 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
79542 + * Licensed under the GPL v2
79543 + *
79544 + * Note: the choice of the license means that the compilation process is
79545 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
79546 + * but for the kernel it doesn't matter since it doesn't link against
79547 + * any of the gcc libraries
79548 + *
79549 + * gcc plugin to implement various sparse (source code checker) features
79550 + *
79551 + * TODO:
79552 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
79553 + *
79554 + * BUGS:
79555 + * - none known
79556 + */
79557 +#include "gcc-plugin.h"
79558 +#include "config.h"
79559 +#include "system.h"
79560 +#include "coretypes.h"
79561 +#include "tree.h"
79562 +#include "tree-pass.h"
79563 +#include "flags.h"
79564 +#include "intl.h"
79565 +#include "toplev.h"
79566 +#include "plugin.h"
79567 +//#include "expr.h" where are you...
79568 +#include "diagnostic.h"
79569 +#include "plugin-version.h"
79570 +#include "tm.h"
79571 +#include "function.h"
79572 +#include "basic-block.h"
79573 +#include "gimple.h"
79574 +#include "rtl.h"
79575 +#include "emit-rtl.h"
79576 +#include "tree-flow.h"
79577 +#include "target.h"
79578 +
79579 +extern void c_register_addr_space (const char *str, addr_space_t as);
79580 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
79581 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
79582 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
79583 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
79584 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
79585 +
79586 +extern void print_gimple_stmt(FILE *, gimple, int, int);
79587 +extern rtx emit_move_insn(rtx x, rtx y);
79588 +
79589 +int plugin_is_GPL_compatible;
79590 +
79591 +static struct plugin_info checker_plugin_info = {
79592 + .version = "201111150100",
79593 +};
79594 +
79595 +#define ADDR_SPACE_KERNEL 0
79596 +#define ADDR_SPACE_FORCE_KERNEL 1
79597 +#define ADDR_SPACE_USER 2
79598 +#define ADDR_SPACE_FORCE_USER 3
79599 +#define ADDR_SPACE_IOMEM 0
79600 +#define ADDR_SPACE_FORCE_IOMEM 0
79601 +#define ADDR_SPACE_PERCPU 0
79602 +#define ADDR_SPACE_FORCE_PERCPU 0
79603 +#define ADDR_SPACE_RCU 0
79604 +#define ADDR_SPACE_FORCE_RCU 0
79605 +
79606 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
79607 +{
79608 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
79609 +}
79610 +
79611 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
79612 +{
79613 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
79614 +}
79615 +
79616 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
79617 +{
79618 + return default_addr_space_valid_pointer_mode(mode, as);
79619 +}
79620 +
79621 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
79622 +{
79623 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
79624 +}
79625 +
79626 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
79627 +{
79628 + return default_addr_space_legitimize_address(x, oldx, mode, as);
79629 +}
79630 +
79631 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
79632 +{
79633 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
79634 + return true;
79635 +
79636 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
79637 + return true;
79638 +
79639 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
79640 + return true;
79641 +
79642 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
79643 + return true;
79644 +
79645 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
79646 + return true;
79647 +
79648 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
79649 + return true;
79650 +
79651 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
79652 + return true;
79653 +
79654 + return subset == superset;
79655 +}
79656 +
79657 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
79658 +{
79659 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
79660 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
79661 +
79662 + return op;
79663 +}
79664 +
79665 +static void register_checker_address_spaces(void *event_data, void *data)
79666 +{
79667 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
79668 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
79669 + c_register_addr_space("__user", ADDR_SPACE_USER);
79670 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
79671 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
79672 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
79673 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
79674 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
79675 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
79676 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
79677 +
79678 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
79679 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
79680 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
79681 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
79682 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
79683 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
79684 + targetm.addr_space.convert = checker_addr_space_convert;
79685 +}
79686 +
79687 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
79688 +{
79689 + const char * const plugin_name = plugin_info->base_name;
79690 + const int argc = plugin_info->argc;
79691 + const struct plugin_argument * const argv = plugin_info->argv;
79692 + int i;
79693 +
79694 + if (!plugin_default_version_check(version, &gcc_version)) {
79695 + error(G_("incompatible gcc/plugin versions"));
79696 + return 1;
79697 + }
79698 +
79699 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
79700 +
79701 + for (i = 0; i < argc; ++i)
79702 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
79703 +
79704 + if (TARGET_64BIT == 0)
79705 + return 0;
79706 +
79707 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
79708 +
79709 + return 0;
79710 +}
79711 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
79712 new file mode 100644
79713 index 0000000..7a5e311
79714 --- /dev/null
79715 +++ b/tools/gcc/colorize_plugin.c
79716 @@ -0,0 +1,148 @@
79717 +/*
79718 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
79719 + * Licensed under the GPL v2
79720 + *
79721 + * Note: the choice of the license means that the compilation process is
79722 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
79723 + * but for the kernel it doesn't matter since it doesn't link against
79724 + * any of the gcc libraries
79725 + *
79726 + * gcc plugin to colorize diagnostic output
79727 + *
79728 + */
79729 +
79730 +#include "gcc-plugin.h"
79731 +#include "config.h"
79732 +#include "system.h"
79733 +#include "coretypes.h"
79734 +#include "tree.h"
79735 +#include "tree-pass.h"
79736 +#include "flags.h"
79737 +#include "intl.h"
79738 +#include "toplev.h"
79739 +#include "plugin.h"
79740 +#include "diagnostic.h"
79741 +#include "plugin-version.h"
79742 +#include "tm.h"
79743 +
79744 +int plugin_is_GPL_compatible;
79745 +
79746 +static struct plugin_info colorize_plugin_info = {
79747 + .version = "201203092200",
79748 + .help = NULL,
79749 +};
79750 +
79751 +#define GREEN "\033[32m\033[2m"
79752 +#define LIGHTGREEN "\033[32m\033[1m"
79753 +#define YELLOW "\033[33m\033[2m"
79754 +#define LIGHTYELLOW "\033[33m\033[1m"
79755 +#define RED "\033[31m\033[2m"
79756 +#define LIGHTRED "\033[31m\033[1m"
79757 +#define BLUE "\033[34m\033[2m"
79758 +#define LIGHTBLUE "\033[34m\033[1m"
79759 +#define BRIGHT "\033[m\033[1m"
79760 +#define NORMAL "\033[m"
79761 +
79762 +static diagnostic_starter_fn old_starter;
79763 +static diagnostic_finalizer_fn old_finalizer;
79764 +
79765 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
79766 +{
79767 + const char *color;
79768 + char *newprefix;
79769 +
79770 + switch (diagnostic->kind) {
79771 + case DK_NOTE:
79772 + color = LIGHTBLUE;
79773 + break;
79774 +
79775 + case DK_PEDWARN:
79776 + case DK_WARNING:
79777 + color = LIGHTYELLOW;
79778 + break;
79779 +
79780 + case DK_ERROR:
79781 + case DK_FATAL:
79782 + case DK_ICE:
79783 + case DK_PERMERROR:
79784 + case DK_SORRY:
79785 + color = LIGHTRED;
79786 + break;
79787 +
79788 + default:
79789 + color = NORMAL;
79790 + }
79791 +
79792 + old_starter(context, diagnostic);
79793 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
79794 + return;
79795 + pp_destroy_prefix(context->printer);
79796 + pp_set_prefix(context->printer, newprefix);
79797 +}
79798 +
79799 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
79800 +{
79801 + old_finalizer(context, diagnostic);
79802 +}
79803 +
79804 +static void colorize_arm(void)
79805 +{
79806 + old_starter = diagnostic_starter(global_dc);
79807 + old_finalizer = diagnostic_finalizer(global_dc);
79808 +
79809 + diagnostic_starter(global_dc) = start_colorize;
79810 + diagnostic_finalizer(global_dc) = finalize_colorize;
79811 +}
79812 +
79813 +static unsigned int execute_colorize_rearm(void)
79814 +{
79815 + if (diagnostic_starter(global_dc) == start_colorize)
79816 + return 0;
79817 +
79818 + colorize_arm();
79819 + return 0;
79820 +}
79821 +
79822 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
79823 + .pass = {
79824 + .type = SIMPLE_IPA_PASS,
79825 + .name = "colorize_rearm",
79826 + .gate = NULL,
79827 + .execute = execute_colorize_rearm,
79828 + .sub = NULL,
79829 + .next = NULL,
79830 + .static_pass_number = 0,
79831 + .tv_id = TV_NONE,
79832 + .properties_required = 0,
79833 + .properties_provided = 0,
79834 + .properties_destroyed = 0,
79835 + .todo_flags_start = 0,
79836 + .todo_flags_finish = 0
79837 + }
79838 +};
79839 +
79840 +static void colorize_start_unit(void *gcc_data, void *user_data)
79841 +{
79842 + colorize_arm();
79843 +}
79844 +
79845 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
79846 +{
79847 + const char * const plugin_name = plugin_info->base_name;
79848 + struct register_pass_info colorize_rearm_pass_info = {
79849 + .pass = &pass_ipa_colorize_rearm.pass,
79850 + .reference_pass_name = "*free_lang_data",
79851 + .ref_pass_instance_number = 0,
79852 + .pos_op = PASS_POS_INSERT_AFTER
79853 + };
79854 +
79855 + if (!plugin_default_version_check(version, &gcc_version)) {
79856 + error(G_("incompatible gcc/plugin versions"));
79857 + return 1;
79858 + }
79859 +
79860 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
79861 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
79862 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
79863 + return 0;
79864 +}
79865 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
79866 new file mode 100644
79867 index 0000000..89b7f56
79868 --- /dev/null
79869 +++ b/tools/gcc/constify_plugin.c
79870 @@ -0,0 +1,328 @@
79871 +/*
79872 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
79873 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
79874 + * Licensed under the GPL v2, or (at your option) v3
79875 + *
79876 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
79877 + *
79878 + * Homepage:
79879 + * http://www.grsecurity.net/~ephox/const_plugin/
79880 + *
79881 + * Usage:
79882 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
79883 + * $ gcc -fplugin=constify_plugin.so test.c -O2
79884 + */
79885 +
79886 +#include "gcc-plugin.h"
79887 +#include "config.h"
79888 +#include "system.h"
79889 +#include "coretypes.h"
79890 +#include "tree.h"
79891 +#include "tree-pass.h"
79892 +#include "flags.h"
79893 +#include "intl.h"
79894 +#include "toplev.h"
79895 +#include "plugin.h"
79896 +#include "diagnostic.h"
79897 +#include "plugin-version.h"
79898 +#include "tm.h"
79899 +#include "function.h"
79900 +#include "basic-block.h"
79901 +#include "gimple.h"
79902 +#include "rtl.h"
79903 +#include "emit-rtl.h"
79904 +#include "tree-flow.h"
79905 +
79906 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
79907 +
79908 +int plugin_is_GPL_compatible;
79909 +
79910 +static struct plugin_info const_plugin_info = {
79911 + .version = "201205300030",
79912 + .help = "no-constify\tturn off constification\n",
79913 +};
79914 +
79915 +static void deconstify_tree(tree node);
79916 +
79917 +static void deconstify_type(tree type)
79918 +{
79919 + tree field;
79920 +
79921 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
79922 + tree type = TREE_TYPE(field);
79923 +
79924 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
79925 + continue;
79926 + if (!TYPE_READONLY(type))
79927 + continue;
79928 +
79929 + deconstify_tree(field);
79930 + }
79931 + TYPE_READONLY(type) = 0;
79932 + C_TYPE_FIELDS_READONLY(type) = 0;
79933 +}
79934 +
79935 +static void deconstify_tree(tree node)
79936 +{
79937 + tree old_type, new_type, field;
79938 +
79939 + old_type = TREE_TYPE(node);
79940 +
79941 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
79942 +
79943 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
79944 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
79945 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
79946 + DECL_FIELD_CONTEXT(field) = new_type;
79947 +
79948 + deconstify_type(new_type);
79949 +
79950 + TREE_READONLY(node) = 0;
79951 + TREE_TYPE(node) = new_type;
79952 +}
79953 +
79954 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
79955 +{
79956 + tree type;
79957 +
79958 + *no_add_attrs = true;
79959 + if (TREE_CODE(*node) == FUNCTION_DECL) {
79960 + error("%qE attribute does not apply to functions", name);
79961 + return NULL_TREE;
79962 + }
79963 +
79964 + if (TREE_CODE(*node) == VAR_DECL) {
79965 + error("%qE attribute does not apply to variables", name);
79966 + return NULL_TREE;
79967 + }
79968 +
79969 + if (TYPE_P(*node)) {
79970 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
79971 + *no_add_attrs = false;
79972 + else
79973 + error("%qE attribute applies to struct and union types only", name);
79974 + return NULL_TREE;
79975 + }
79976 +
79977 + type = TREE_TYPE(*node);
79978 +
79979 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
79980 + error("%qE attribute applies to struct and union types only", name);
79981 + return NULL_TREE;
79982 + }
79983 +
79984 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
79985 + error("%qE attribute is already applied to the type", name);
79986 + return NULL_TREE;
79987 + }
79988 +
79989 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
79990 + error("%qE attribute used on type that is not constified", name);
79991 + return NULL_TREE;
79992 + }
79993 +
79994 + if (TREE_CODE(*node) == TYPE_DECL) {
79995 + deconstify_tree(*node);
79996 + return NULL_TREE;
79997 + }
79998 +
79999 + return NULL_TREE;
80000 +}
80001 +
80002 +static void constify_type(tree type)
80003 +{
80004 + TYPE_READONLY(type) = 1;
80005 + C_TYPE_FIELDS_READONLY(type) = 1;
80006 +}
80007 +
80008 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
80009 +{
80010 + *no_add_attrs = true;
80011 + if (!TYPE_P(*node)) {
80012 + error("%qE attribute applies to types only", name);
80013 + return NULL_TREE;
80014 + }
80015 +
80016 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
80017 + error("%qE attribute applies to struct and union types only", name);
80018 + return NULL_TREE;
80019 + }
80020 +
80021 + *no_add_attrs = false;
80022 + constify_type(*node);
80023 + return NULL_TREE;
80024 +}
80025 +
80026 +static struct attribute_spec no_const_attr = {
80027 + .name = "no_const",
80028 + .min_length = 0,
80029 + .max_length = 0,
80030 + .decl_required = false,
80031 + .type_required = false,
80032 + .function_type_required = false,
80033 + .handler = handle_no_const_attribute,
80034 +#if BUILDING_GCC_VERSION >= 4007
80035 + .affects_type_identity = true
80036 +#endif
80037 +};
80038 +
80039 +static struct attribute_spec do_const_attr = {
80040 + .name = "do_const",
80041 + .min_length = 0,
80042 + .max_length = 0,
80043 + .decl_required = false,
80044 + .type_required = false,
80045 + .function_type_required = false,
80046 + .handler = handle_do_const_attribute,
80047 +#if BUILDING_GCC_VERSION >= 4007
80048 + .affects_type_identity = true
80049 +#endif
80050 +};
80051 +
80052 +static void register_attributes(void *event_data, void *data)
80053 +{
80054 + register_attribute(&no_const_attr);
80055 + register_attribute(&do_const_attr);
80056 +}
80057 +
80058 +static bool is_fptr(tree field)
80059 +{
80060 + tree ptr = TREE_TYPE(field);
80061 +
80062 + if (TREE_CODE(ptr) != POINTER_TYPE)
80063 + return false;
80064 +
80065 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
80066 +}
80067 +
80068 +static bool walk_struct(tree node)
80069 +{
80070 + tree field;
80071 +
80072 + if (TYPE_FIELDS(node) == NULL_TREE)
80073 + return false;
80074 +
80075 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
80076 + gcc_assert(!TYPE_READONLY(node));
80077 + deconstify_type(node);
80078 + return false;
80079 + }
80080 +
80081 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
80082 + tree type = TREE_TYPE(field);
80083 + enum tree_code code = TREE_CODE(type);
80084 + if (code == RECORD_TYPE || code == UNION_TYPE) {
80085 + if (!(walk_struct(type)))
80086 + return false;
80087 + } else if (!is_fptr(field) && !TREE_READONLY(field))
80088 + return false;
80089 + }
80090 + return true;
80091 +}
80092 +
80093 +static void finish_type(void *event_data, void *data)
80094 +{
80095 + tree type = (tree)event_data;
80096 +
80097 + if (type == NULL_TREE)
80098 + return;
80099 +
80100 + if (TYPE_READONLY(type))
80101 + return;
80102 +
80103 + if (walk_struct(type))
80104 + constify_type(type);
80105 +}
80106 +
80107 +static unsigned int check_local_variables(void);
80108 +
80109 +struct gimple_opt_pass pass_local_variable = {
80110 + {
80111 + .type = GIMPLE_PASS,
80112 + .name = "check_local_variables",
80113 + .gate = NULL,
80114 + .execute = check_local_variables,
80115 + .sub = NULL,
80116 + .next = NULL,
80117 + .static_pass_number = 0,
80118 + .tv_id = TV_NONE,
80119 + .properties_required = 0,
80120 + .properties_provided = 0,
80121 + .properties_destroyed = 0,
80122 + .todo_flags_start = 0,
80123 + .todo_flags_finish = 0
80124 + }
80125 +};
80126 +
80127 +static unsigned int check_local_variables(void)
80128 +{
80129 + tree var;
80130 + referenced_var_iterator rvi;
80131 +
80132 +#if BUILDING_GCC_VERSION == 4005
80133 + FOR_EACH_REFERENCED_VAR(var, rvi) {
80134 +#else
80135 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
80136 +#endif
80137 + tree type = TREE_TYPE(var);
80138 +
80139 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
80140 + continue;
80141 +
80142 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
80143 + continue;
80144 +
80145 + if (!TYPE_READONLY(type))
80146 + continue;
80147 +
80148 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
80149 +// continue;
80150 +
80151 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
80152 +// continue;
80153 +
80154 + if (walk_struct(type)) {
80155 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
80156 + return 1;
80157 + }
80158 + }
80159 + return 0;
80160 +}
80161 +
80162 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80163 +{
80164 + const char * const plugin_name = plugin_info->base_name;
80165 + const int argc = plugin_info->argc;
80166 + const struct plugin_argument * const argv = plugin_info->argv;
80167 + int i;
80168 + bool constify = true;
80169 +
80170 + struct register_pass_info local_variable_pass_info = {
80171 + .pass = &pass_local_variable.pass,
80172 + .reference_pass_name = "*referenced_vars",
80173 + .ref_pass_instance_number = 0,
80174 + .pos_op = PASS_POS_INSERT_AFTER
80175 + };
80176 +
80177 + if (!plugin_default_version_check(version, &gcc_version)) {
80178 + error(G_("incompatible gcc/plugin versions"));
80179 + return 1;
80180 + }
80181 +
80182 + for (i = 0; i < argc; ++i) {
80183 + if (!(strcmp(argv[i].key, "no-constify"))) {
80184 + constify = false;
80185 + continue;
80186 + }
80187 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80188 + }
80189 +
80190 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
80191 + if (constify) {
80192 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
80193 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
80194 + }
80195 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
80196 +
80197 + return 0;
80198 +}
80199 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
80200 new file mode 100644
80201 index 0000000..a0fe8b2
80202 --- /dev/null
80203 +++ b/tools/gcc/generate_size_overflow_hash.sh
80204 @@ -0,0 +1,94 @@
80205 +#!/bin/bash
80206 +
80207 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
80208 +
80209 +header1="size_overflow_hash.h"
80210 +database="size_overflow_hash.data"
80211 +n=65536
80212 +
80213 +usage() {
80214 +cat <<EOF
80215 +usage: $0 options
80216 +OPTIONS:
80217 + -h|--help help
80218 + -o header file
80219 + -d database file
80220 + -n hash array size
80221 +EOF
80222 + return 0
80223 +}
80224 +
80225 +while true
80226 +do
80227 + case "$1" in
80228 + -h|--help) usage && exit 0;;
80229 + -n) n=$2; shift 2;;
80230 + -o) header1="$2"; shift 2;;
80231 + -d) database="$2"; shift 2;;
80232 + --) shift 1; break ;;
80233 + *) break ;;
80234 + esac
80235 +done
80236 +
80237 +create_defines() {
80238 + for i in `seq 1 10`
80239 + do
80240 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
80241 + done
80242 + echo >> "$header1"
80243 +}
80244 +
80245 +create_structs () {
80246 + rm -f "$header1"
80247 +
80248 + create_defines
80249 +
80250 + cat "$database" | while read data
80251 + do
80252 + data_array=($data)
80253 + struct_hash_name="${data_array[0]}"
80254 + funcn="${data_array[1]}"
80255 + params="${data_array[2]}"
80256 + next="${data_array[5]}"
80257 +
80258 + echo "struct size_overflow_hash $struct_hash_name = {" >> "$header1"
80259 +
80260 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
80261 + echo -en "\t.param\t= " >> "$header1"
80262 + line=
80263 + for param_num in ${params//-/ };
80264 + do
80265 + line="${line}PARAM"$param_num"|"
80266 + done
80267 +
80268 + echo -e "${line%?},\n};\n" >> "$header1"
80269 + done
80270 +}
80271 +
80272 +create_headers () {
80273 + echo "struct size_overflow_hash *size_overflow_hash[$n] = {" >> "$header1"
80274 +}
80275 +
80276 +create_array_elements () {
80277 + index=0
80278 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
80279 + do
80280 + data_array=($data)
80281 + i="${data_array[3]}"
80282 + hash="${data_array[4]}"
80283 + while [[ $index -lt $i ]]
80284 + do
80285 + echo -e "\t["$index"]\t= NULL," >> "$header1"
80286 + index=$(($index + 1))
80287 + done
80288 + index=$(($index + 1))
80289 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
80290 + done
80291 + echo '};' >> $header1
80292 +}
80293 +
80294 +create_structs
80295 +create_headers
80296 +create_array_elements
80297 +
80298 +exit 0
80299 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
80300 new file mode 100644
80301 index 0000000..a5eabce
80302 --- /dev/null
80303 +++ b/tools/gcc/kallocstat_plugin.c
80304 @@ -0,0 +1,167 @@
80305 +/*
80306 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
80307 + * Licensed under the GPL v2
80308 + *
80309 + * Note: the choice of the license means that the compilation process is
80310 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80311 + * but for the kernel it doesn't matter since it doesn't link against
80312 + * any of the gcc libraries
80313 + *
80314 + * gcc plugin to find the distribution of k*alloc sizes
80315 + *
80316 + * TODO:
80317 + *
80318 + * BUGS:
80319 + * - none known
80320 + */
80321 +#include "gcc-plugin.h"
80322 +#include "config.h"
80323 +#include "system.h"
80324 +#include "coretypes.h"
80325 +#include "tree.h"
80326 +#include "tree-pass.h"
80327 +#include "flags.h"
80328 +#include "intl.h"
80329 +#include "toplev.h"
80330 +#include "plugin.h"
80331 +//#include "expr.h" where are you...
80332 +#include "diagnostic.h"
80333 +#include "plugin-version.h"
80334 +#include "tm.h"
80335 +#include "function.h"
80336 +#include "basic-block.h"
80337 +#include "gimple.h"
80338 +#include "rtl.h"
80339 +#include "emit-rtl.h"
80340 +
80341 +extern void print_gimple_stmt(FILE *, gimple, int, int);
80342 +
80343 +int plugin_is_GPL_compatible;
80344 +
80345 +static const char * const kalloc_functions[] = {
80346 + "__kmalloc",
80347 + "kmalloc",
80348 + "kmalloc_large",
80349 + "kmalloc_node",
80350 + "kmalloc_order",
80351 + "kmalloc_order_trace",
80352 + "kmalloc_slab",
80353 + "kzalloc",
80354 + "kzalloc_node",
80355 +};
80356 +
80357 +static struct plugin_info kallocstat_plugin_info = {
80358 + .version = "201111150100",
80359 +};
80360 +
80361 +static unsigned int execute_kallocstat(void);
80362 +
80363 +static struct gimple_opt_pass kallocstat_pass = {
80364 + .pass = {
80365 + .type = GIMPLE_PASS,
80366 + .name = "kallocstat",
80367 + .gate = NULL,
80368 + .execute = execute_kallocstat,
80369 + .sub = NULL,
80370 + .next = NULL,
80371 + .static_pass_number = 0,
80372 + .tv_id = TV_NONE,
80373 + .properties_required = 0,
80374 + .properties_provided = 0,
80375 + .properties_destroyed = 0,
80376 + .todo_flags_start = 0,
80377 + .todo_flags_finish = 0
80378 + }
80379 +};
80380 +
80381 +static bool is_kalloc(const char *fnname)
80382 +{
80383 + size_t i;
80384 +
80385 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
80386 + if (!strcmp(fnname, kalloc_functions[i]))
80387 + return true;
80388 + return false;
80389 +}
80390 +
80391 +static unsigned int execute_kallocstat(void)
80392 +{
80393 + basic_block bb;
80394 +
80395 + // 1. loop through BBs and GIMPLE statements
80396 + FOR_EACH_BB(bb) {
80397 + gimple_stmt_iterator gsi;
80398 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
80399 + // gimple match:
80400 + tree fndecl, size;
80401 + gimple call_stmt;
80402 + const char *fnname;
80403 +
80404 + // is it a call
80405 + call_stmt = gsi_stmt(gsi);
80406 + if (!is_gimple_call(call_stmt))
80407 + continue;
80408 + fndecl = gimple_call_fndecl(call_stmt);
80409 + if (fndecl == NULL_TREE)
80410 + continue;
80411 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
80412 + continue;
80413 +
80414 + // is it a call to k*alloc
80415 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
80416 + if (!is_kalloc(fnname))
80417 + continue;
80418 +
80419 + // is the size arg the result of a simple const assignment
80420 + size = gimple_call_arg(call_stmt, 0);
80421 + while (true) {
80422 + gimple def_stmt;
80423 + expanded_location xloc;
80424 + size_t size_val;
80425 +
80426 + if (TREE_CODE(size) != SSA_NAME)
80427 + break;
80428 + def_stmt = SSA_NAME_DEF_STMT(size);
80429 + if (!def_stmt || !is_gimple_assign(def_stmt))
80430 + break;
80431 + if (gimple_num_ops(def_stmt) != 2)
80432 + break;
80433 + size = gimple_assign_rhs1(def_stmt);
80434 + if (!TREE_CONSTANT(size))
80435 + continue;
80436 + xloc = expand_location(gimple_location(def_stmt));
80437 + if (!xloc.file)
80438 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
80439 + size_val = TREE_INT_CST_LOW(size);
80440 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
80441 + break;
80442 + }
80443 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
80444 +//debug_tree(gimple_call_fn(call_stmt));
80445 +//print_node(stderr, "pax", fndecl, 4);
80446 + }
80447 + }
80448 +
80449 + return 0;
80450 +}
80451 +
80452 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80453 +{
80454 + const char * const plugin_name = plugin_info->base_name;
80455 + struct register_pass_info kallocstat_pass_info = {
80456 + .pass = &kallocstat_pass.pass,
80457 + .reference_pass_name = "ssa",
80458 + .ref_pass_instance_number = 0,
80459 + .pos_op = PASS_POS_INSERT_AFTER
80460 + };
80461 +
80462 + if (!plugin_default_version_check(version, &gcc_version)) {
80463 + error(G_("incompatible gcc/plugin versions"));
80464 + return 1;
80465 + }
80466 +
80467 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
80468 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
80469 +
80470 + return 0;
80471 +}
80472 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
80473 new file mode 100644
80474 index 0000000..d8a8da2
80475 --- /dev/null
80476 +++ b/tools/gcc/kernexec_plugin.c
80477 @@ -0,0 +1,427 @@
80478 +/*
80479 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
80480 + * Licensed under the GPL v2
80481 + *
80482 + * Note: the choice of the license means that the compilation process is
80483 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80484 + * but for the kernel it doesn't matter since it doesn't link against
80485 + * any of the gcc libraries
80486 + *
80487 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
80488 + *
80489 + * TODO:
80490 + *
80491 + * BUGS:
80492 + * - none known
80493 + */
80494 +#include "gcc-plugin.h"
80495 +#include "config.h"
80496 +#include "system.h"
80497 +#include "coretypes.h"
80498 +#include "tree.h"
80499 +#include "tree-pass.h"
80500 +#include "flags.h"
80501 +#include "intl.h"
80502 +#include "toplev.h"
80503 +#include "plugin.h"
80504 +//#include "expr.h" where are you...
80505 +#include "diagnostic.h"
80506 +#include "plugin-version.h"
80507 +#include "tm.h"
80508 +#include "function.h"
80509 +#include "basic-block.h"
80510 +#include "gimple.h"
80511 +#include "rtl.h"
80512 +#include "emit-rtl.h"
80513 +#include "tree-flow.h"
80514 +
80515 +extern void print_gimple_stmt(FILE *, gimple, int, int);
80516 +extern rtx emit_move_insn(rtx x, rtx y);
80517 +
80518 +int plugin_is_GPL_compatible;
80519 +
80520 +static struct plugin_info kernexec_plugin_info = {
80521 + .version = "201111291120",
80522 + .help = "method=[bts|or]\tinstrumentation method\n"
80523 +};
80524 +
80525 +static unsigned int execute_kernexec_reload(void);
80526 +static unsigned int execute_kernexec_fptr(void);
80527 +static unsigned int execute_kernexec_retaddr(void);
80528 +static bool kernexec_cmodel_check(void);
80529 +
80530 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
80531 +static void (*kernexec_instrument_retaddr)(rtx);
80532 +
80533 +static struct gimple_opt_pass kernexec_reload_pass = {
80534 + .pass = {
80535 + .type = GIMPLE_PASS,
80536 + .name = "kernexec_reload",
80537 + .gate = kernexec_cmodel_check,
80538 + .execute = execute_kernexec_reload,
80539 + .sub = NULL,
80540 + .next = NULL,
80541 + .static_pass_number = 0,
80542 + .tv_id = TV_NONE,
80543 + .properties_required = 0,
80544 + .properties_provided = 0,
80545 + .properties_destroyed = 0,
80546 + .todo_flags_start = 0,
80547 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
80548 + }
80549 +};
80550 +
80551 +static struct gimple_opt_pass kernexec_fptr_pass = {
80552 + .pass = {
80553 + .type = GIMPLE_PASS,
80554 + .name = "kernexec_fptr",
80555 + .gate = kernexec_cmodel_check,
80556 + .execute = execute_kernexec_fptr,
80557 + .sub = NULL,
80558 + .next = NULL,
80559 + .static_pass_number = 0,
80560 + .tv_id = TV_NONE,
80561 + .properties_required = 0,
80562 + .properties_provided = 0,
80563 + .properties_destroyed = 0,
80564 + .todo_flags_start = 0,
80565 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
80566 + }
80567 +};
80568 +
80569 +static struct rtl_opt_pass kernexec_retaddr_pass = {
80570 + .pass = {
80571 + .type = RTL_PASS,
80572 + .name = "kernexec_retaddr",
80573 + .gate = kernexec_cmodel_check,
80574 + .execute = execute_kernexec_retaddr,
80575 + .sub = NULL,
80576 + .next = NULL,
80577 + .static_pass_number = 0,
80578 + .tv_id = TV_NONE,
80579 + .properties_required = 0,
80580 + .properties_provided = 0,
80581 + .properties_destroyed = 0,
80582 + .todo_flags_start = 0,
80583 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
80584 + }
80585 +};
80586 +
80587 +static bool kernexec_cmodel_check(void)
80588 +{
80589 + tree section;
80590 +
80591 + if (ix86_cmodel != CM_KERNEL)
80592 + return false;
80593 +
80594 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
80595 + if (!section || !TREE_VALUE(section))
80596 + return true;
80597 +
80598 + section = TREE_VALUE(TREE_VALUE(section));
80599 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
80600 + return true;
80601 +
80602 + return false;
80603 +}
80604 +
80605 +/*
80606 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
80607 + */
80608 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
80609 +{
80610 + gimple asm_movabs_stmt;
80611 +
80612 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
80613 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
80614 + gimple_asm_set_volatile(asm_movabs_stmt, true);
80615 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
80616 + update_stmt(asm_movabs_stmt);
80617 +}
80618 +
80619 +/*
80620 + * find all asm() stmts that clobber r10 and add a reload of r10
80621 + */
80622 +static unsigned int execute_kernexec_reload(void)
80623 +{
80624 + basic_block bb;
80625 +
80626 + // 1. loop through BBs and GIMPLE statements
80627 + FOR_EACH_BB(bb) {
80628 + gimple_stmt_iterator gsi;
80629 +
80630 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
80631 + // gimple match: __asm__ ("" : : : "r10");
80632 + gimple asm_stmt;
80633 + size_t nclobbers;
80634 +
80635 + // is it an asm ...
80636 + asm_stmt = gsi_stmt(gsi);
80637 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
80638 + continue;
80639 +
80640 + // ... clobbering r10
80641 + nclobbers = gimple_asm_nclobbers(asm_stmt);
80642 + while (nclobbers--) {
80643 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
80644 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
80645 + continue;
80646 + kernexec_reload_fptr_mask(&gsi);
80647 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
80648 + break;
80649 + }
80650 + }
80651 + }
80652 +
80653 + return 0;
80654 +}
80655 +
80656 +/*
80657 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
80658 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
80659 + */
80660 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
80661 +{
80662 + gimple assign_intptr, assign_new_fptr, call_stmt;
80663 + tree intptr, old_fptr, new_fptr, kernexec_mask;
80664 +
80665 + call_stmt = gsi_stmt(*gsi);
80666 + old_fptr = gimple_call_fn(call_stmt);
80667 +
80668 + // create temporary unsigned long variable used for bitops and cast fptr to it
80669 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
80670 + add_referenced_var(intptr);
80671 + mark_sym_for_renaming(intptr);
80672 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
80673 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
80674 + update_stmt(assign_intptr);
80675 +
80676 + // apply logical or to temporary unsigned long and bitmask
80677 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
80678 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
80679 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
80680 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
80681 + update_stmt(assign_intptr);
80682 +
80683 + // cast temporary unsigned long back to a temporary fptr variable
80684 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
80685 + add_referenced_var(new_fptr);
80686 + mark_sym_for_renaming(new_fptr);
80687 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
80688 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
80689 + update_stmt(assign_new_fptr);
80690 +
80691 + // replace call stmt fn with the new fptr
80692 + gimple_call_set_fn(call_stmt, new_fptr);
80693 + update_stmt(call_stmt);
80694 +}
80695 +
80696 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
80697 +{
80698 + gimple asm_or_stmt, call_stmt;
80699 + tree old_fptr, new_fptr, input, output;
80700 + VEC(tree, gc) *inputs = NULL;
80701 + VEC(tree, gc) *outputs = NULL;
80702 +
80703 + call_stmt = gsi_stmt(*gsi);
80704 + old_fptr = gimple_call_fn(call_stmt);
80705 +
80706 + // create temporary fptr variable
80707 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
80708 + add_referenced_var(new_fptr);
80709 + mark_sym_for_renaming(new_fptr);
80710 +
80711 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
80712 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
80713 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
80714 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
80715 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
80716 + VEC_safe_push(tree, gc, inputs, input);
80717 + VEC_safe_push(tree, gc, outputs, output);
80718 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
80719 + gimple_asm_set_volatile(asm_or_stmt, true);
80720 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
80721 + update_stmt(asm_or_stmt);
80722 +
80723 + // replace call stmt fn with the new fptr
80724 + gimple_call_set_fn(call_stmt, new_fptr);
80725 + update_stmt(call_stmt);
80726 +}
80727 +
80728 +/*
80729 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
80730 + */
80731 +static unsigned int execute_kernexec_fptr(void)
80732 +{
80733 + basic_block bb;
80734 +
80735 + // 1. loop through BBs and GIMPLE statements
80736 + FOR_EACH_BB(bb) {
80737 + gimple_stmt_iterator gsi;
80738 +
80739 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
80740 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
80741 + tree fn;
80742 + gimple call_stmt;
80743 +
80744 + // is it a call ...
80745 + call_stmt = gsi_stmt(gsi);
80746 + if (!is_gimple_call(call_stmt))
80747 + continue;
80748 + fn = gimple_call_fn(call_stmt);
80749 + if (TREE_CODE(fn) == ADDR_EXPR)
80750 + continue;
80751 + if (TREE_CODE(fn) != SSA_NAME)
80752 + gcc_unreachable();
80753 +
80754 + // ... through a function pointer
80755 + fn = SSA_NAME_VAR(fn);
80756 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
80757 + continue;
80758 + fn = TREE_TYPE(fn);
80759 + if (TREE_CODE(fn) != POINTER_TYPE)
80760 + continue;
80761 + fn = TREE_TYPE(fn);
80762 + if (TREE_CODE(fn) != FUNCTION_TYPE)
80763 + continue;
80764 +
80765 + kernexec_instrument_fptr(&gsi);
80766 +
80767 +//debug_tree(gimple_call_fn(call_stmt));
80768 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
80769 + }
80770 + }
80771 +
80772 + return 0;
80773 +}
80774 +
80775 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
80776 +static void kernexec_instrument_retaddr_bts(rtx insn)
80777 +{
80778 + rtx btsq;
80779 + rtvec argvec, constraintvec, labelvec;
80780 + int line;
80781 +
80782 + // create asm volatile("btsq $63,(%%rsp)":::)
80783 + argvec = rtvec_alloc(0);
80784 + constraintvec = rtvec_alloc(0);
80785 + labelvec = rtvec_alloc(0);
80786 + line = expand_location(RTL_LOCATION(insn)).line;
80787 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
80788 + MEM_VOLATILE_P(btsq) = 1;
80789 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
80790 + emit_insn_before(btsq, insn);
80791 +}
80792 +
80793 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
80794 +static void kernexec_instrument_retaddr_or(rtx insn)
80795 +{
80796 + rtx orq;
80797 + rtvec argvec, constraintvec, labelvec;
80798 + int line;
80799 +
80800 + // create asm volatile("orq %%r10,(%%rsp)":::)
80801 + argvec = rtvec_alloc(0);
80802 + constraintvec = rtvec_alloc(0);
80803 + labelvec = rtvec_alloc(0);
80804 + line = expand_location(RTL_LOCATION(insn)).line;
80805 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
80806 + MEM_VOLATILE_P(orq) = 1;
80807 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
80808 + emit_insn_before(orq, insn);
80809 +}
80810 +
80811 +/*
80812 + * find all asm level function returns and forcibly set the highest bit of the return address
80813 + */
80814 +static unsigned int execute_kernexec_retaddr(void)
80815 +{
80816 + rtx insn;
80817 +
80818 + // 1. find function returns
80819 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
80820 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
80821 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
80822 + rtx body;
80823 +
80824 + // is it a retn
80825 + if (!JUMP_P(insn))
80826 + continue;
80827 + body = PATTERN(insn);
80828 + if (GET_CODE(body) == PARALLEL)
80829 + body = XVECEXP(body, 0, 0);
80830 + if (GET_CODE(body) != RETURN)
80831 + continue;
80832 + kernexec_instrument_retaddr(insn);
80833 + }
80834 +
80835 +// print_simple_rtl(stderr, get_insns());
80836 +// print_rtl(stderr, get_insns());
80837 +
80838 + return 0;
80839 +}
80840 +
80841 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80842 +{
80843 + const char * const plugin_name = plugin_info->base_name;
80844 + const int argc = plugin_info->argc;
80845 + const struct plugin_argument * const argv = plugin_info->argv;
80846 + int i;
80847 + struct register_pass_info kernexec_reload_pass_info = {
80848 + .pass = &kernexec_reload_pass.pass,
80849 + .reference_pass_name = "ssa",
80850 + .ref_pass_instance_number = 0,
80851 + .pos_op = PASS_POS_INSERT_AFTER
80852 + };
80853 + struct register_pass_info kernexec_fptr_pass_info = {
80854 + .pass = &kernexec_fptr_pass.pass,
80855 + .reference_pass_name = "ssa",
80856 + .ref_pass_instance_number = 0,
80857 + .pos_op = PASS_POS_INSERT_AFTER
80858 + };
80859 + struct register_pass_info kernexec_retaddr_pass_info = {
80860 + .pass = &kernexec_retaddr_pass.pass,
80861 + .reference_pass_name = "pro_and_epilogue",
80862 + .ref_pass_instance_number = 0,
80863 + .pos_op = PASS_POS_INSERT_AFTER
80864 + };
80865 +
80866 + if (!plugin_default_version_check(version, &gcc_version)) {
80867 + error(G_("incompatible gcc/plugin versions"));
80868 + return 1;
80869 + }
80870 +
80871 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
80872 +
80873 + if (TARGET_64BIT == 0)
80874 + return 0;
80875 +
80876 + for (i = 0; i < argc; ++i) {
80877 + if (!strcmp(argv[i].key, "method")) {
80878 + if (!argv[i].value) {
80879 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80880 + continue;
80881 + }
80882 + if (!strcmp(argv[i].value, "bts")) {
80883 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
80884 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
80885 + } else if (!strcmp(argv[i].value, "or")) {
80886 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
80887 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
80888 + fix_register("r10", 1, 1);
80889 + } else
80890 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
80891 + continue;
80892 + }
80893 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80894 + }
80895 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
80896 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
80897 +
80898 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
80899 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
80900 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
80901 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
80902 +
80903 + return 0;
80904 +}
80905 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
80906 new file mode 100644
80907 index 0000000..daaa86c
80908 --- /dev/null
80909 +++ b/tools/gcc/size_overflow_hash.data
80910 @@ -0,0 +1,2486 @@
80911 +_000001_hash alloc_dr 2 65495 _000001_hash NULL
80912 +_000002_hash __copy_from_user 3 10918 _000002_hash NULL
80913 +_000003_hash copy_from_user 3 17559 _000003_hash NULL
80914 +_000004_hash __copy_from_user_inatomic 3 4365 _000004_hash NULL
80915 +_000005_hash __copy_from_user_nocache 3 39351 _000005_hash NULL
80916 +_000006_hash __copy_to_user_inatomic 3 19214 _000006_hash NULL
80917 +_000007_hash do_xip_mapping_read 5 60297 _000007_hash NULL
80918 +_000008_hash hugetlbfs_read 3 11268 _000008_hash NULL
80919 +_000009_hash kmalloc 1 60432 _002597_hash NULL nohasharray
80920 +_000010_hash kmalloc_array 1-2 9444 _000010_hash NULL
80921 +_000012_hash kmalloc_slab 1 11917 _000012_hash NULL
80922 +_000013_hash kmemdup 2 64015 _000013_hash NULL
80923 +_000014_hash __krealloc 2 14857 _000331_hash NULL nohasharray
80924 +_000015_hash memdup_user 2 59590 _000015_hash NULL
80925 +_000016_hash module_alloc 1 63630 _000016_hash NULL
80926 +_000017_hash read_default_ldt 2 14302 _000017_hash NULL
80927 +_000018_hash read_kcore 3 63488 _000018_hash NULL
80928 +_000019_hash read_ldt 2 47570 _000019_hash NULL
80929 +_000020_hash read_zero 3 19366 _000020_hash NULL
80930 +_000021_hash __vmalloc_node 1 39308 _000021_hash NULL
80931 +_000022_hash vm_map_ram 2 23078 _001054_hash NULL nohasharray
80932 +_000023_hash aa_simple_write_to_buffer 4-3 49683 _000023_hash NULL
80933 +_000024_hash ablkcipher_copy_iv 3 64140 _000024_hash NULL
80934 +_000025_hash ablkcipher_next_slow 4 47274 _000025_hash NULL
80935 +_000026_hash acpi_battery_write_alarm 3 1240 _000026_hash NULL
80936 +_000027_hash acpi_os_allocate 1 14892 _000027_hash NULL
80937 +_000028_hash acpi_system_write_wakeup_device 3 34853 _000028_hash NULL
80938 +_000029_hash adu_write 3 30487 _000029_hash NULL
80939 +_000030_hash aer_inject_write 3 52399 _000030_hash NULL
80940 +_000031_hash afs_alloc_flat_call 2-3 36399 _000031_hash NULL
80941 +_000033_hash afs_proc_cells_write 3 61139 _000033_hash NULL
80942 +_000034_hash afs_proc_rootcell_write 3 15822 _000034_hash NULL
80943 +_000035_hash agp_3_5_isochronous_node_enable 3 49465 _000035_hash NULL
80944 +_000036_hash agp_alloc_page_array 1 22554 _000036_hash NULL
80945 +_000037_hash ah_alloc_tmp 2 54378 _000037_hash NULL
80946 +_000038_hash ahash_setkey_unaligned 3 33521 _000038_hash NULL
80947 +_000039_hash alg_setkey 3 31485 _000039_hash NULL
80948 +_000040_hash aligned_kmalloc 1 3628 _000040_hash NULL
80949 +_000041_hash alloc_context 1 3194 _000041_hash NULL
80950 +_000042_hash alloc_ep_req 2 54860 _000042_hash NULL
80951 +_000043_hash alloc_fdmem 1 27083 _000043_hash NULL
80952 +_000044_hash alloc_flex_gd 1 57259 _000044_hash NULL
80953 +_000045_hash alloc_sglist 1-3-2 22960 _000045_hash NULL
80954 +_000046_hash aoedev_flush 2 44398 _000046_hash NULL
80955 +_000047_hash append_to_buffer 3 63550 _000047_hash NULL
80956 +_000048_hash asix_read_cmd 5 13245 _000048_hash NULL
80957 +_000049_hash asix_write_cmd 5 58192 _000049_hash NULL
80958 +_000050_hash asn1_octets_decode 2 9991 _000050_hash NULL
80959 +_000051_hash asn1_oid_decode 2 4999 _000051_hash NULL
80960 +_000052_hash at76_set_card_command 4 4471 _000052_hash NULL
80961 +_000053_hash ath6kl_add_bss_if_needed 6 24317 _000053_hash NULL
80962 +_000054_hash ath6kl_debug_roam_tbl_event 3 5224 _000054_hash NULL
80963 +_000055_hash ath6kl_mgmt_powersave_ap 6 13791 _000055_hash NULL
80964 +_000056_hash ath6kl_send_go_probe_resp 3 21113 _000056_hash NULL
80965 +_000057_hash ath6kl_set_ap_probe_resp_ies 3 50539 _000057_hash NULL
80966 +_000058_hash ath6kl_set_assoc_req_ies 3 43185 _000058_hash NULL
80967 +_000059_hash ath6kl_wmi_bssinfo_event_rx 3 2275 _000059_hash NULL
80968 +_000060_hash ath6kl_wmi_send_action_cmd 7 58860 _000060_hash NULL
80969 +_000061_hash __ath6kl_wmi_send_mgmt_cmd 7 38971 _000061_hash NULL
80970 +_000062_hash attach_hdlc_protocol 3 19986 _000062_hash NULL
80971 +_000063_hash audio_write 4 54261 _001597_hash NULL nohasharray
80972 +_000064_hash audit_unpack_string 3 13748 _000064_hash NULL
80973 +_000065_hash av7110_vbi_write 3 34384 _000065_hash NULL
80974 +_000066_hash ax25_setsockopt 5 42740 _000066_hash NULL
80975 +_000067_hash b43_debugfs_write 3 34838 _000067_hash NULL
80976 +_000068_hash b43legacy_debugfs_write 3 28556 _000068_hash NULL
80977 +_000069_hash bch_alloc 1 4593 _000069_hash NULL
80978 +_000070_hash befs_nls2utf 3 17163 _000070_hash NULL
80979 +_000071_hash befs_utf2nls 3 25628 _000071_hash NULL
80980 +_000072_hash bfad_debugfs_write_regrd 3 15218 _000072_hash NULL
80981 +_000073_hash bfad_debugfs_write_regwr 3 61841 _000073_hash NULL
80982 +_000074_hash bio_alloc_map_data 1-2 50782 _000074_hash NULL
80983 +_000076_hash bio_kmalloc 2 54672 _000076_hash NULL
80984 +_000077_hash blkcipher_copy_iv 3 24075 _000077_hash NULL
80985 +_000078_hash blkcipher_next_slow 4 52733 _000078_hash NULL
80986 +_000079_hash bl_pipe_downcall 3 34264 _000079_hash NULL
80987 +_000080_hash bnad_debugfs_write_regrd 3 6706 _000080_hash NULL
80988 +_000081_hash bnad_debugfs_write_regwr 3 57500 _000081_hash NULL
80989 +_000082_hash bnx2fc_cmd_mgr_alloc 2-3 24873 _000082_hash NULL
80990 +_000084_hash bnx2_nvram_write 4 7790 _000084_hash NULL
80991 +_000085_hash brcmf_sdbrcm_downloadvars 3 42064 _000085_hash NULL
80992 +_000086_hash btmrvl_gpiogap_write 3 35053 _000086_hash NULL
80993 +_000087_hash btmrvl_hscfgcmd_write 3 27143 _000087_hash NULL
80994 +_000088_hash btmrvl_hscmd_write 3 27089 _000088_hash NULL
80995 +_000089_hash btmrvl_hsmode_write 3 42252 _000089_hash NULL
80996 +_000090_hash btmrvl_pscmd_write 3 29504 _000090_hash NULL
80997 +_000091_hash btmrvl_psmode_write 3 3703 _000091_hash NULL
80998 +_000092_hash btrfs_alloc_delayed_item 1 11678 _000092_hash NULL
80999 +_000093_hash cache_do_downcall 3 6926 _000093_hash NULL
81000 +_000094_hash cachefiles_cook_key 2 33274 _000094_hash NULL
81001 +_000095_hash cachefiles_daemon_write 3 43535 _000095_hash NULL
81002 +_000096_hash capi_write 3 35104 _000096_hash NULL
81003 +_000097_hash carl9170_debugfs_write 3 50857 _000097_hash NULL
81004 +_000098_hash cciss_allocate_sg_chain_blocks 2-3 5368 _000098_hash NULL
81005 +_000100_hash cciss_proc_write 3 10259 _000100_hash NULL
81006 +_000101_hash cdrom_read_cdda_old 4 27664 _000101_hash NULL
81007 +_000102_hash ceph_alloc_page_vector 1 18710 _000102_hash NULL
81008 +_000103_hash ceph_buffer_new 1 35974 _000103_hash NULL
81009 +_000104_hash ceph_copy_user_to_page_vector 4 656 _000104_hash NULL
81010 +_000105_hash ceph_get_direct_page_vector 2 41917 _000105_hash NULL
81011 +_000106_hash ceph_msg_new 2 5846 _000106_hash NULL
81012 +_000107_hash ceph_setxattr 4 18913 _000107_hash NULL
81013 +_000108_hash cfi_read_pri 3 24366 _000108_hash NULL
81014 +_000109_hash cgroup_write_string 5 10900 _000109_hash NULL
81015 +_000110_hash cgroup_write_X64 5 54514 _000110_hash NULL
81016 +_000111_hash change_xattr 5 61390 _000111_hash NULL
81017 +_000112_hash check_load_and_stores 2 2143 _000112_hash NULL
81018 +_000113_hash cifs_idmap_key_instantiate 3 54503 _000113_hash NULL
81019 +_000114_hash cifs_security_flags_proc_write 3 5484 _000114_hash NULL
81020 +_000115_hash cifs_setxattr 4 23957 _000115_hash NULL
81021 +_000116_hash cifs_spnego_key_instantiate 3 23588 _000116_hash NULL
81022 +_000117_hash ci_ll_write 4 3740 _000117_hash NULL
81023 +_000118_hash cld_pipe_downcall 3 15058 _000118_hash NULL
81024 +_000119_hash clear_refs_write 3 61904 _000119_hash NULL
81025 +_000120_hash clusterip_proc_write 3 44729 _000120_hash NULL
81026 +_000121_hash cm4040_write 3 58079 _000121_hash NULL
81027 +_000122_hash cm_copy_private_data 2 3649 _000122_hash NULL
81028 +_000123_hash cmm_write 3 2896 _000123_hash NULL
81029 +_000124_hash cm_write 3 36858 _000124_hash NULL
81030 +_000125_hash coda_psdev_write 3 1711 _000125_hash NULL
81031 +_000126_hash codec_reg_read_file 3 36280 _000126_hash NULL
81032 +_000127_hash command_file_write 3 31318 _000127_hash NULL
81033 +_000128_hash command_write 3 58841 _000128_hash NULL
81034 +_000129_hash comm_write 3 44537 _001532_hash NULL nohasharray
81035 +_000130_hash concat_writev 3 21451 _000130_hash NULL
81036 +_000131_hash copy_and_check 3 19089 _000131_hash NULL
81037 +_000132_hash copy_from_user_toio 3 31966 _000132_hash NULL
81038 +_000133_hash copy_items 6 50140 _000133_hash NULL
81039 +_000134_hash copy_macs 4 45534 _000134_hash NULL
81040 +_000135_hash __copy_to_user 3 17551 _000135_hash NULL
81041 +_000136_hash copy_vm86_regs_from_user 3 45340 _000136_hash NULL
81042 +_000137_hash cosa_write 3 1774 _000137_hash NULL
81043 +_000138_hash create_entry 2 33479 _000138_hash NULL
81044 +_000139_hash create_queues 2-3 9088 _000139_hash NULL
81045 +_000141_hash create_xattr 5 54106 _000141_hash NULL
81046 +_000142_hash create_xattr_datum 5 33356 _000142_hash NULL
81047 +_000143_hash csum_partial_copy_fromiovecend 3-4 9957 _000143_hash NULL
81048 +_000145_hash ctrl_out 3-5 8712 _000145_hash NULL
81049 +_000147_hash cx24116_writeregN 4 41975 _000147_hash NULL
81050 +_000148_hash cxacru_cm_get_array 4 4412 _000148_hash NULL
81051 +_000149_hash cxgbi_alloc_big_mem 1 4707 _000149_hash NULL
81052 +_000150_hash dac960_user_command_proc_write 3 3071 _000150_hash NULL
81053 +_000151_hash datablob_format 2 39571 _002156_hash NULL nohasharray
81054 +_000152_hash dccp_feat_clone_sp_val 3 11942 _000152_hash NULL
81055 +_000153_hash dccp_setsockopt_ccid 4 30701 _000153_hash NULL
81056 +_000154_hash dccp_setsockopt_cscov 2 37766 _000154_hash NULL
81057 +_000155_hash dccp_setsockopt_service 4 65336 _000155_hash NULL
81058 +_000156_hash ddb_output_write 3 31902 _000156_hash NULL
81059 +_000157_hash ddebug_proc_write 3 18055 _000157_hash NULL
81060 +_000158_hash dev_config 3 8506 _000158_hash NULL
81061 +_000159_hash device_write 3 45156 _000159_hash NULL
81062 +_000160_hash devm_kzalloc 2 4966 _000160_hash NULL
81063 +_000161_hash devres_alloc 2 551 _000161_hash NULL
81064 +_000162_hash dfs_file_write 3 41196 _000162_hash NULL
81065 +_000163_hash direct_entry 3 38836 _000163_hash NULL
81066 +_000164_hash dispatch_proc_write 3 44320 _000164_hash NULL
81067 +_000165_hash diva_os_copy_from_user 4 7792 _000165_hash NULL
81068 +_000166_hash dlm_alloc_pagevec 1 54296 _000166_hash NULL
81069 +_000167_hash dlmfs_file_read 3 28385 _000167_hash NULL
81070 +_000168_hash dlmfs_file_write 3 6892 _000168_hash NULL
81071 +_000169_hash dm_read 3 15674 _000169_hash NULL
81072 +_000170_hash dm_write 3 2513 _000170_hash NULL
81073 +_000171_hash __dn_setsockopt 5 13060 _000171_hash NULL
81074 +_000172_hash dns_query 3 9676 _000172_hash NULL
81075 +_000173_hash dns_resolver_instantiate 3 63314 _000173_hash NULL
81076 +_000174_hash do_add_counters 3 3992 _000174_hash NULL
81077 +_000175_hash __do_config_autodelink 3 58763 _000175_hash NULL
81078 +_000176_hash do_ip_setsockopt 5 41852 _000176_hash NULL
81079 +_000177_hash do_ipv6_setsockopt 5 18215 _000177_hash NULL
81080 +_000178_hash do_ip_vs_set_ctl 4 48641 _000178_hash NULL
81081 +_000179_hash do_kimage_alloc 3 64827 _000179_hash NULL
81082 +_000180_hash do_register_entry 4 29478 _000180_hash NULL
81083 +_000181_hash do_tty_write 5 44896 _000181_hash NULL
81084 +_000182_hash do_update_counters 4 2259 _000182_hash NULL
81085 +_000183_hash dsp_write 2 46218 _000183_hash NULL
81086 +_000184_hash dup_to_netobj 3 26363 _000184_hash NULL
81087 +_000185_hash dvb_aplay 3 56296 _000185_hash NULL
81088 +_000186_hash dvb_ca_en50221_io_write 3 43533 _000186_hash NULL
81089 +_000187_hash dvbdmx_write 3 19423 _000187_hash NULL
81090 +_000188_hash dvb_play 3 50814 _000188_hash NULL
81091 +_000189_hash dw210x_op_rw 6 39915 _000189_hash NULL
81092 +_000190_hash dwc3_link_state_write 3 12641 _000190_hash NULL
81093 +_000191_hash dwc3_mode_write 3 51997 _000191_hash NULL
81094 +_000192_hash dwc3_testmode_write 3 30516 _000192_hash NULL
81095 +_000193_hash ecryptfs_copy_filename 4 11868 _000193_hash NULL
81096 +_000194_hash ecryptfs_miscdev_write 3 26847 _000194_hash NULL
81097 +_000195_hash ecryptfs_send_miscdev 2 64816 _000195_hash NULL
81098 +_000196_hash efx_tsoh_heap_alloc 2 58545 _000196_hash NULL
81099 +_000197_hash emi26_writememory 4 57908 _000197_hash NULL
81100 +_000198_hash emi62_writememory 4 29731 _000198_hash NULL
81101 +_000199_hash encrypted_instantiate 3 3168 _000199_hash NULL
81102 +_000200_hash encrypted_update 3 13414 _000200_hash NULL
81103 +_000201_hash ep0_write 3 14536 _001328_hash NULL nohasharray
81104 +_000202_hash ep_read 3 58813 _000202_hash NULL
81105 +_000203_hash ep_write 3 59008 _000203_hash NULL
81106 +_000204_hash erst_dbg_write 3 46715 _000204_hash NULL
81107 +_000205_hash esp_alloc_tmp 2 40558 _000205_hash NULL
81108 +_000206_hash exofs_read_lookup_dev_table 3 17733 _000206_hash NULL
81109 +_000207_hash ext4_kvmalloc 1 14796 _000207_hash NULL
81110 +_000208_hash ezusb_writememory 4 45976 _000208_hash NULL
81111 +_000209_hash fanotify_write 3 64623 _000209_hash NULL
81112 +_000210_hash fd_copyin 3 56247 _000210_hash NULL
81113 +_000211_hash ffs_epfile_io 3 64886 _000211_hash NULL
81114 +_000212_hash ffs_prepare_buffer 2 59892 _000212_hash NULL
81115 +_000213_hash f_hidg_write 3 7932 _000213_hash NULL
81116 +_000214_hash file_read_actor 4 1401 _000214_hash NULL
81117 +_000215_hash fill_write_buffer 3 3142 _000215_hash NULL
81118 +_000216_hash fl_create 5 56435 _000216_hash NULL
81119 +_000217_hash ftdi_elan_write 3 57309 _000217_hash NULL
81120 +_000218_hash fuse_conn_limit_write 3 30777 _000218_hash NULL
81121 +_000219_hash fw_iso_buffer_init 3 54582 _000219_hash NULL
81122 +_000220_hash garmin_write_bulk 3 58191 _000220_hash NULL
81123 +_000221_hash garp_attr_create 3 3883 _000221_hash NULL
81124 +_000222_hash get_arg 3 5694 _000222_hash NULL
81125 +_000223_hash getdqbuf 1 62908 _000223_hash NULL
81126 +_000224_hash get_fdb_entries 3 41916 _000224_hash NULL
81127 +_000225_hash get_indirect_ea 4 51869 _000225_hash NULL
81128 +_000226_hash get_registers 3 26187 _000226_hash NULL
81129 +_000227_hash get_scq 2 10897 _000227_hash NULL
81130 +_000228_hash get_server_iovec 2 16804 _000228_hash NULL
81131 +_000229_hash get_ucode_user 3 38202 _000229_hash NULL
81132 +_000230_hash get_user_cpu_mask 2 14861 _000230_hash NULL
81133 +_000231_hash gfs2_alloc_sort_buffer 1 18275 _000231_hash NULL
81134 +_000232_hash gfs2_glock_nq_m 1 20347 _000232_hash NULL
81135 +_000233_hash gigaset_initcs 2 43753 _000233_hash NULL
81136 +_000234_hash gigaset_initdriver 2 1060 _000234_hash NULL
81137 +_000235_hash gs_alloc_req 2 58883 _000235_hash NULL
81138 +_000236_hash gs_buf_alloc 2 25067 _000236_hash NULL
81139 +_000237_hash gsm_data_alloc 3 42437 _000237_hash NULL
81140 +_000238_hash gss_pipe_downcall 3 23182 _000238_hash NULL
81141 +_000239_hash handle_request 9 10024 _000239_hash NULL
81142 +_000240_hash hash_new 1 62224 _000240_hash NULL
81143 +_000241_hash hashtab_create 3 33769 _000241_hash NULL
81144 +_000242_hash hcd_buffer_alloc 2 27495 _000242_hash NULL
81145 +_000243_hash hci_sock_setsockopt 5 28993 _000243_hash NULL
81146 +_000244_hash heap_init 2 49617 _000244_hash NULL
81147 +_000245_hash hest_ghes_dev_register 1 46766 _000245_hash NULL
81148 +_000246_hash hidraw_get_report 3 45609 _000246_hash NULL
81149 +_000247_hash hidraw_report_event 3 49578 _000509_hash NULL nohasharray
81150 +_000248_hash hidraw_send_report 3 23449 _000248_hash NULL
81151 +_000249_hash hpfs_translate_name 3 41497 _000249_hash NULL
81152 +_000250_hash hysdn_conf_write 3 52145 _000250_hash NULL
81153 +_000251_hash hysdn_log_write 3 48694 _000251_hash NULL
81154 +_000252_hash __i2400mu_send_barker 3 23652 _000252_hash NULL
81155 +_000253_hash i2cdev_read 3 1206 _000253_hash NULL
81156 +_000254_hash i2cdev_write 3 23310 _000254_hash NULL
81157 +_000255_hash i2o_parm_field_get 5 34477 _000255_hash NULL
81158 +_000256_hash i2o_parm_table_get 6 61635 _000256_hash NULL
81159 +_000257_hash ib_copy_from_udata 3 59502 _000257_hash NULL
81160 +_000258_hash ib_ucm_alloc_data 3 36885 _000258_hash NULL
81161 +_000259_hash ib_umad_write 3 47993 _000259_hash NULL
81162 +_000260_hash ib_uverbs_unmarshall_recv 5 12251 _000260_hash NULL
81163 +_000261_hash icn_writecmd 2 38629 _000261_hash NULL
81164 +_000262_hash ide_driver_proc_write 3 32493 _000262_hash NULL
81165 +_000263_hash ide_settings_proc_write 3 35110 _000263_hash NULL
81166 +_000264_hash idetape_chrdev_write 3 53976 _000264_hash NULL
81167 +_000265_hash idmap_pipe_downcall 3 14591 _000265_hash NULL
81168 +_000266_hash ieee80211_build_probe_req 7 27660 _000266_hash NULL
81169 +_000267_hash ieee80211_if_write 3 34894 _000267_hash NULL
81170 +_000268_hash if_write 3 51756 _000268_hash NULL
81171 +_000269_hash ilo_write 3 64378 _000269_hash NULL
81172 +_000270_hash ima_write_policy 3 40548 _000270_hash NULL
81173 +_000271_hash init_data_container 1 60709 _000271_hash NULL
81174 +_000272_hash init_send_hfcd 1 34586 _000272_hash NULL
81175 +_000273_hash insert_dent 7 65034 _000273_hash NULL
81176 +_000274_hash interpret_user_input 2 19393 _000274_hash NULL
81177 +_000275_hash int_proc_write 3 39542 _000275_hash NULL
81178 +_000276_hash ioctl_private_iw_point 7 1273 _000276_hash NULL
81179 +_000277_hash iov_iter_copy_from_user 4 31942 _000277_hash NULL
81180 +_000278_hash iov_iter_copy_from_user_atomic 4 56368 _000278_hash NULL
81181 +_000279_hash iowarrior_write 3 18604 _000279_hash NULL
81182 +_000280_hash ipc_alloc 1 1192 _000280_hash NULL
81183 +_000281_hash ipc_rcu_alloc 1 21208 _000281_hash NULL
81184 +_000282_hash ip_options_get_from_user 4 64958 _000282_hash NULL
81185 +_000283_hash ipv6_renew_option 3 38813 _000283_hash NULL
81186 +_000284_hash ip_vs_conn_fill_param_sync 6 29771 _002404_hash NULL nohasharray
81187 +_000285_hash ip_vs_create_timeout_table 2 64478 _000285_hash NULL
81188 +_000286_hash ipw_queue_tx_init 3 49161 _000286_hash NULL
81189 +_000287_hash irda_setsockopt 5 19824 _000287_hash NULL
81190 +_000288_hash irias_new_octseq_value 2 13596 _000288_hash NULL
81191 +_000289_hash ir_lirc_transmit_ir 3 64403 _000289_hash NULL
81192 +_000290_hash irnet_ctrl_write 3 24139 _000290_hash NULL
81193 +_000291_hash isdn_add_channels 3 40905 _000291_hash NULL
81194 +_000292_hash isdn_ppp_fill_rq 2 41428 _000292_hash NULL
81195 +_000293_hash isdn_ppp_write 4 29109 _000293_hash NULL
81196 +_000294_hash isdn_read 3 50021 _000294_hash NULL
81197 +_000295_hash isdn_v110_open 3 2418 _000295_hash NULL
81198 +_000296_hash isdn_writebuf_stub 4 52383 _000296_hash NULL
81199 +_000297_hash islpci_mgt_transmit 5 34133 _000297_hash NULL
81200 +_000298_hash iso_callback 3 43208 _000298_hash NULL
81201 +_000299_hash iso_packets_buffer_init 3 29061 _000299_hash NULL
81202 +_000300_hash it821x_firmware_command 3 8628 _000300_hash NULL
81203 +_000301_hash ivtv_buf_copy_from_user 4 25502 _000301_hash NULL
81204 +_000302_hash iwch_alloc_fastreg_pbl 2 40153 _000302_hash NULL
81205 +_000303_hash iwl_calib_set 3 34400 _002188_hash NULL nohasharray
81206 +_000304_hash jbd2_journal_init_revoke_table 1 36336 _000304_hash NULL
81207 +_000305_hash jffs2_alloc_full_dirent 1 60179 _001111_hash NULL nohasharray
81208 +_000306_hash journal_init_revoke_table 1 56331 _000306_hash NULL
81209 +_000307_hash kcalloc 1-2 27770 _000307_hash NULL
81210 +_000309_hash keyctl_instantiate_key_common 4 47889 _000309_hash NULL
81211 +_000310_hash keyctl_update_key 3 26061 _000310_hash NULL
81212 +_000311_hash __kfifo_alloc 2-3 22173 _000311_hash NULL
81213 +_000313_hash kfifo_copy_from_user 3 5091 _000313_hash NULL
81214 +_000314_hash kmalloc_node 1 50163 _000314_hash NULL
81215 +_000315_hash kmalloc_parameter 1 65279 _000315_hash NULL
81216 +_000316_hash kmem_alloc 1 31920 _000316_hash NULL
81217 +_000317_hash kobj_map 2-3 9566 _000317_hash NULL
81218 +_000319_hash kone_receive 4 4690 _000319_hash NULL
81219 +_000320_hash kone_send 4 63435 _000320_hash NULL
81220 +_000321_hash krealloc 2 14908 _000321_hash NULL
81221 +_000322_hash kvmalloc 1 32646 _000322_hash NULL
81222 +_000323_hash kvm_read_guest_atomic 4 10765 _000323_hash NULL
81223 +_000324_hash kvm_read_guest_cached 4 39666 _000324_hash NULL
81224 +_000325_hash kvm_read_guest_page 5 18074 _000325_hash NULL
81225 +_000326_hash kzalloc 1 54740 _000326_hash NULL
81226 +_000327_hash l2cap_sock_setsockopt 5 50207 _000327_hash NULL
81227 +_000328_hash l2cap_sock_setsockopt_old 4 29346 _000328_hash NULL
81228 +_000329_hash lane2_associate_req 4 45398 _000329_hash NULL
81229 +_000330_hash lbs_debugfs_write 3 48413 _000330_hash NULL
81230 +_000331_hash lcd_write 3 14857 _000331_hash &_000014_hash
81231 +_000332_hash ldm_frag_add 2 5611 _000332_hash NULL
81232 +_000333_hash __lgread 4 31668 _000333_hash NULL
81233 +_000334_hash libipw_alloc_txb 1 27579 _000334_hash NULL
81234 +_000335_hash link_send_sections_long 4 46556 _000335_hash NULL
81235 +_000336_hash listxattr 3 12769 _000336_hash NULL
81236 +_000337_hash LoadBitmap 2 19658 _000337_hash NULL
81237 +_000338_hash load_msg 2 95 _000338_hash NULL
81238 +_000339_hash lpfc_debugfs_dif_err_write 3 17424 _000339_hash NULL
81239 +_000340_hash lp_write 3 9511 _000340_hash NULL
81240 +_000341_hash mb_cache_create 2 17307 _000341_hash NULL
81241 +_000342_hash mce_write 3 26201 _000342_hash NULL
81242 +_000343_hash mcs7830_get_reg 3 33308 _000343_hash NULL
81243 +_000344_hash mcs7830_set_reg 3 31413 _000344_hash NULL
81244 +_000345_hash memcpy_fromiovec 3 55247 _000345_hash NULL
81245 +_000346_hash memcpy_fromiovecend 3-4 2707 _000346_hash NULL
81246 +_000348_hash mempool_kmalloc 2 53831 _000348_hash NULL
81247 +_000349_hash mempool_resize 2 47983 _001821_hash NULL nohasharray
81248 +_000350_hash mem_rw 3 22085 _000350_hash NULL
81249 +_000351_hash mgmt_control 3 7349 _000351_hash NULL
81250 +_000352_hash mgmt_pending_add 5 46976 _000352_hash NULL
81251 +_000353_hash mlx4_ib_alloc_fast_reg_page_list 2 46119 _000353_hash NULL
81252 +_000354_hash mmc_alloc_sg 1 21504 _000354_hash NULL
81253 +_000355_hash mmc_send_bus_test 4 18285 _000355_hash NULL
81254 +_000356_hash mmc_send_cxd_data 5 38655 _000356_hash NULL
81255 +_000357_hash module_alloc_update_bounds 1 47205 _000357_hash NULL
81256 +_000358_hash move_addr_to_kernel 2 32673 _000358_hash NULL
81257 +_000359_hash mpi_alloc_limb_space 1 23190 _000359_hash NULL
81258 +_000360_hash mpi_resize 2 44674 _000360_hash NULL
81259 +_000361_hash mptctl_getiocinfo 2 28545 _000361_hash NULL
81260 +_000362_hash mtdchar_readoob 4 31200 _000362_hash NULL
81261 +_000363_hash mtdchar_write 3 56831 _000363_hash NULL
81262 +_000364_hash mtdchar_writeoob 4 3393 _000364_hash NULL
81263 +_000365_hash mtd_device_parse_register 5 5024 _000365_hash NULL
81264 +_000366_hash mtf_test_write 3 18844 _000366_hash NULL
81265 +_000367_hash mtrr_write 3 59622 _000367_hash NULL
81266 +_000368_hash musb_test_mode_write 3 33518 _000368_hash NULL
81267 +_000369_hash mwifiex_get_common_rates 3 17131 _000369_hash NULL
81268 +_000370_hash mwifiex_update_curr_bss_params 5 16908 _000370_hash NULL
81269 +_000371_hash nand_bch_init 2-3 16280 _001341_hash NULL nohasharray
81270 +_000373_hash ncp_file_write 3 3813 _000373_hash NULL
81271 +_000374_hash ncp__vol2io 5 4804 _000374_hash NULL
81272 +_000375_hash nes_alloc_fast_reg_page_list 2 33523 _000375_hash NULL
81273 +_000376_hash nfc_targets_found 3 29886 _000376_hash NULL
81274 +_000377_hash nfs4_acl_new 1 49806 _000377_hash NULL
81275 +_000378_hash nfs4_write_cached_acl 4 15070 _000378_hash NULL
81276 +_000379_hash nfsd_cache_update 3 59574 _000379_hash NULL
81277 +_000380_hash nfsd_symlink 6 63442 _000380_hash NULL
81278 +_000381_hash nfs_idmap_get_desc 2-4 42990 _000381_hash NULL
81279 +_000383_hash nfs_readdir_make_qstr 3 12509 _000383_hash NULL
81280 +_000384_hash note_last_dentry 3 12285 _000384_hash NULL
81281 +_000385_hash ntfs_copy_from_user 3-5 15072 _000385_hash NULL
81282 +_000387_hash __ntfs_copy_from_user_iovec_inatomic 3-4 38153 _000387_hash NULL
81283 +_000389_hash ntfs_ucstonls 3 23097 _000389_hash NULL
81284 +_000390_hash nvme_alloc_iod 1 56027 _000390_hash NULL
81285 +_000391_hash nvram_write 3 3894 _000391_hash NULL
81286 +_000392_hash o2hb_debug_create 4 18744 _000392_hash NULL
81287 +_000393_hash o2net_send_message_vec 4 879 _001792_hash NULL nohasharray
81288 +_000394_hash ocfs2_control_cfu 2 37750 _000394_hash NULL
81289 +_000395_hash oom_adjust_write 3 41116 _000395_hash NULL
81290 +_000396_hash oom_score_adj_write 3 42594 _000396_hash NULL
81291 +_000397_hash opera1_xilinx_rw 5 31453 _000397_hash NULL
81292 +_000398_hash oprofilefs_ulong_from_user 3 57251 _000398_hash NULL
81293 +_000399_hash opticon_write 4 60775 _000399_hash NULL
81294 +_000400_hash orig_node_add_if 2 32833 _000400_hash NULL
81295 +_000401_hash orig_node_del_if 2 28371 _000401_hash NULL
81296 +_000402_hash p9_check_zc_errors 4 15534 _000402_hash NULL
81297 +_000403_hash packet_buffer_init 2 1607 _000403_hash NULL
81298 +_000404_hash packet_setsockopt 5 17662 _000404_hash NULL
81299 +_000405_hash parse_command 2 37079 _000405_hash NULL
81300 +_000406_hash pcbit_writecmd 2 12332 _000406_hash NULL
81301 +_000407_hash pcmcia_replace_cis 3 57066 _000407_hash NULL
81302 +_000408_hash pgctrl_write 3 50453 _000408_hash NULL
81303 +_000409_hash pg_write 3 40766 _000409_hash NULL
81304 +_000410_hash pidlist_allocate 1 64404 _000410_hash NULL
81305 +_000411_hash pipe_iov_copy_from_user 3 23102 _000411_hash NULL
81306 +_000412_hash pipe_iov_copy_to_user 3 3447 _000412_hash NULL
81307 +_000413_hash pkt_add 3 39897 _000413_hash NULL
81308 +_000414_hash pktgen_if_write 3 55628 _000414_hash NULL
81309 +_000415_hash platform_device_add_data 3 310 _000415_hash NULL
81310 +_000416_hash platform_device_add_resources 3 13289 _000416_hash NULL
81311 +_000417_hash pm_qos_power_write 3 52513 _000417_hash NULL
81312 +_000418_hash pnpbios_proc_write 3 19758 _000418_hash NULL
81313 +_000419_hash pool_allocate 3 42012 _000419_hash NULL
81314 +_000420_hash posix_acl_alloc 1 48063 _000420_hash NULL
81315 +_000421_hash ppp_cp_parse_cr 4 5214 _000421_hash NULL
81316 +_000422_hash ppp_write 3 34034 _000422_hash NULL
81317 +_000423_hash pp_read 3 33210 _000423_hash NULL
81318 +_000424_hash pp_write 3 39554 _000424_hash NULL
81319 +_000425_hash printer_req_alloc 2 62687 _001807_hash NULL nohasharray
81320 +_000426_hash printer_write 3 60276 _000426_hash NULL
81321 +_000427_hash prism2_set_genericelement 3 29277 _000427_hash NULL
81322 +_000428_hash __probe_kernel_read 3 61119 _000428_hash NULL
81323 +_000429_hash __probe_kernel_write 3 29842 _000429_hash NULL
81324 +_000430_hash proc_coredump_filter_write 3 25625 _000430_hash NULL
81325 +_000431_hash _proc_do_string 2 6376 _000431_hash NULL
81326 +_000432_hash process_vm_rw_pages 5-6 15954 _000432_hash NULL
81327 +_000434_hash proc_loginuid_write 3 63648 _000434_hash NULL
81328 +_000435_hash proc_pid_attr_write 3 63845 _000435_hash NULL
81329 +_000436_hash proc_scsi_devinfo_write 3 32064 _000436_hash NULL
81330 +_000437_hash proc_scsi_write 3 29142 _000437_hash NULL
81331 +_000438_hash proc_scsi_write_proc 3 267 _000438_hash NULL
81332 +_000439_hash pstore_mkfile 5 50830 _000439_hash NULL
81333 +_000440_hash pti_char_write 3 60960 _000440_hash NULL
81334 +_000441_hash ptrace_writedata 4 45021 _000441_hash NULL
81335 +_000442_hash pt_write 3 40159 _000442_hash NULL
81336 +_000443_hash pvr2_ioread_set_sync_key 3 59882 _000443_hash NULL
81337 +_000444_hash pvr2_stream_buffer_count 2 33719 _000444_hash NULL
81338 +_000445_hash qdisc_class_hash_alloc 1 18262 _000445_hash NULL
81339 +_000446_hash r3964_write 4 57662 _000446_hash NULL
81340 +_000447_hash raw_seticmpfilter 3 6888 _000447_hash NULL
81341 +_000448_hash raw_setsockopt 5 45800 _000448_hash NULL
81342 +_000449_hash rawv6_seticmpfilter 5 12137 _000449_hash NULL
81343 +_000450_hash ray_cs_essid_proc_write 3 17875 _000450_hash NULL
81344 +_000451_hash rbd_add 3 16366 _000451_hash NULL
81345 +_000452_hash rbd_snap_add 4 19678 _000452_hash NULL
81346 +_000453_hash rdma_set_ib_paths 3 45592 _000453_hash NULL
81347 +_000454_hash rds_page_copy_user 4 35691 _000454_hash NULL
81348 +_000455_hash read 3 9397 _000455_hash NULL
81349 +_000456_hash read_buf 2 20469 _000456_hash NULL
81350 +_000457_hash read_cis_cache 4 29735 _000457_hash NULL
81351 +_000458_hash realloc_buffer 2 25816 _000458_hash NULL
81352 +_000459_hash realloc_packet_buffer 2 25569 _000459_hash NULL
81353 +_000460_hash receive_DataRequest 3 9904 _000460_hash NULL
81354 +_000461_hash recent_mt_proc_write 3 8206 _000461_hash NULL
81355 +_000462_hash regmap_access_read_file 3 37223 _000462_hash NULL
81356 +_000463_hash regmap_bulk_write 4 59049 _000463_hash NULL
81357 +_000464_hash regmap_map_read_file 3 37685 _000464_hash NULL
81358 +_000465_hash regset_tls_set 4 18459 _000465_hash NULL
81359 +_000466_hash reg_w_buf 3 27724 _000466_hash NULL
81360 +_000467_hash reg_w_ixbuf 4 34736 _000467_hash NULL
81361 +_000468_hash remote_settings_file_write 3 22987 _000468_hash NULL
81362 +_000469_hash request_key_auth_new 3 38092 _000469_hash NULL
81363 +_000470_hash restore_i387_fxsave 2 17528 _000470_hash NULL
81364 +_000471_hash revalidate 2 19043 _000471_hash NULL
81365 +_000472_hash rfcomm_sock_setsockopt 5 18254 _000472_hash NULL
81366 +_000473_hash rndis_add_response 2 58544 _000473_hash NULL
81367 +_000474_hash rndis_set_oid 4 6547 _000474_hash NULL
81368 +_000475_hash rngapi_reset 3 34366 _000475_hash NULL
81369 +_000476_hash roccat_common_receive 4 53407 _000476_hash NULL
81370 +_000477_hash roccat_common_send 4 12284 _000477_hash NULL
81371 +_000478_hash rpc_malloc 2 43573 _000478_hash NULL
81372 +_000479_hash rt2x00debug_write_bbp 3 8212 _000479_hash NULL
81373 +_000480_hash rt2x00debug_write_csr 3 64753 _000480_hash NULL
81374 +_000481_hash rt2x00debug_write_eeprom 3 23091 _000481_hash NULL
81375 +_000482_hash rt2x00debug_write_rf 3 38195 _000482_hash NULL
81376 +_000483_hash rts51x_read_mem 4 26577 _000483_hash NULL
81377 +_000484_hash rts51x_read_status 4 11830 _000484_hash NULL
81378 +_000485_hash rts51x_write_mem 4 17598 _000485_hash NULL
81379 +_000486_hash rw_copy_check_uvector 3 34271 _000486_hash NULL
81380 +_000487_hash rxrpc_request_key 3 27235 _000487_hash NULL
81381 +_000488_hash rxrpc_server_keyring 3 16431 _000488_hash NULL
81382 +_000489_hash savemem 3 58129 _000489_hash NULL
81383 +_000490_hash sb16_copy_from_user 10-7-6 55836 _000490_hash NULL
81384 +_000493_hash sched_autogroup_write 3 10984 _000493_hash NULL
81385 +_000494_hash scsi_mode_select 6 37330 _000494_hash NULL
81386 +_000495_hash scsi_tgt_copy_sense 3 26933 _000495_hash NULL
81387 +_000496_hash sctp_auth_create_key 1 51641 _000496_hash NULL
81388 +_000497_hash sctp_getsockopt_delayed_ack 2 9232 _000497_hash NULL
81389 +_000498_hash sctp_getsockopt_local_addrs 2 25178 _000498_hash NULL
81390 +_000499_hash sctp_make_abort_user 3 29654 _000499_hash NULL
81391 +_000500_hash sctp_setsockopt_active_key 3 43755 _000500_hash NULL
81392 +_000501_hash sctp_setsockopt_adaptation_layer 3 26935 _001925_hash NULL nohasharray
81393 +_000502_hash sctp_setsockopt_associnfo 3 51684 _000502_hash NULL
81394 +_000503_hash sctp_setsockopt_auth_chunk 3 30843 _000503_hash NULL
81395 +_000504_hash sctp_setsockopt_auth_key 3 3793 _000504_hash NULL
81396 +_000505_hash sctp_setsockopt_autoclose 3 5775 _000505_hash NULL
81397 +_000506_hash sctp_setsockopt_bindx 3 49870 _000506_hash NULL
81398 +_000507_hash __sctp_setsockopt_connectx 3 46949 _000507_hash NULL
81399 +_000508_hash sctp_setsockopt_context 3 31091 _000508_hash NULL
81400 +_000509_hash sctp_setsockopt_default_send_param 3 49578 _000509_hash &_000247_hash
81401 +_000510_hash sctp_setsockopt_delayed_ack 3 40129 _000510_hash NULL
81402 +_000511_hash sctp_setsockopt_del_key 3 42304 _002281_hash NULL nohasharray
81403 +_000512_hash sctp_setsockopt_events 3 18862 _000512_hash NULL
81404 +_000513_hash sctp_setsockopt_hmac_ident 3 11687 _000513_hash NULL
81405 +_000514_hash sctp_setsockopt_initmsg 3 1383 _000514_hash NULL
81406 +_000515_hash sctp_setsockopt_maxburst 3 28041 _000515_hash NULL
81407 +_000516_hash sctp_setsockopt_maxseg 3 11829 _000516_hash NULL
81408 +_000517_hash sctp_setsockopt_peer_addr_params 3 734 _000517_hash NULL
81409 +_000518_hash sctp_setsockopt_peer_primary_addr 3 13440 _000518_hash NULL
81410 +_000519_hash sctp_setsockopt_rtoinfo 3 30941 _000519_hash NULL
81411 +_000520_hash security_context_to_sid_core 2 29248 _000520_hash NULL
81412 +_000521_hash sel_commit_bools_write 3 46077 _000521_hash NULL
81413 +_000522_hash sel_write_avc_cache_threshold 3 2256 _000522_hash NULL
81414 +_000523_hash sel_write_bool 3 46996 _000523_hash NULL
81415 +_000524_hash sel_write_checkreqprot 3 60774 _000524_hash NULL
81416 +_000525_hash sel_write_disable 3 10511 _000525_hash NULL
81417 +_000526_hash sel_write_enforce 3 48998 _000526_hash NULL
81418 +_000527_hash sel_write_load 3 63830 _000527_hash NULL
81419 +_000528_hash send_bulk_static_data 3 61932 _000528_hash NULL
81420 +_000529_hash send_control_msg 6 48498 _000529_hash NULL
81421 +_000530_hash set_aoe_iflist 2 42737 _000530_hash NULL
81422 +_000531_hash setkey_unaligned 3 39474 _000531_hash NULL
81423 +_000532_hash set_registers 3 53582 _000532_hash NULL
81424 +_000533_hash setsockopt 5 54539 _000533_hash NULL
81425 +_000534_hash setup_req 3 5848 _000534_hash NULL
81426 +_000535_hash setup_window 7 59178 _000535_hash NULL
81427 +_000536_hash setxattr 4 37006 _000536_hash NULL
81428 +_000537_hash sfq_alloc 1 2861 _000537_hash NULL
81429 +_000538_hash sg_kmalloc 1 50240 _000538_hash NULL
81430 +_000539_hash sgl_map_user_pages 2 30610 _000539_hash NULL
81431 +_000540_hash shash_setkey_unaligned 3 8620 _000540_hash NULL
81432 +_000541_hash shmem_xattr_alloc 2 61190 _000541_hash NULL
81433 +_000542_hash sierra_setup_urb 5 46029 _000542_hash NULL
81434 +_000543_hash simple_transaction_get 3 50633 _000543_hash NULL
81435 +_000544_hash simple_write_to_buffer 2-5 3122 _000544_hash NULL
81436 +_000546_hash sisusb_send_bulk_msg 3 17864 _000546_hash NULL
81437 +_000547_hash skb_add_data 3 48363 _000547_hash NULL
81438 +_000548_hash skb_do_copy_data_nocache 5 12465 _000548_hash NULL
81439 +_000549_hash sl_alloc_bufs 2 50380 _000549_hash NULL
81440 +_000550_hash sl_realloc_bufs 2 64086 _000550_hash NULL
81441 +_000551_hash smk_write_ambient 3 45691 _000551_hash NULL
81442 +_000552_hash smk_write_cipso 3 17989 _000552_hash NULL
81443 +_000553_hash smk_write_direct 3 46363 _000553_hash NULL
81444 +_000554_hash smk_write_doi 3 49621 _000554_hash NULL
81445 +_000555_hash smk_write_load_list 3 52280 _000555_hash NULL
81446 +_000556_hash smk_write_logging 3 2618 _000556_hash NULL
81447 +_000557_hash smk_write_netlbladdr 3 42525 _000557_hash NULL
81448 +_000558_hash smk_write_onlycap 3 14400 _000558_hash NULL
81449 +_000559_hash snd_ctl_elem_user_tlv 3 11695 _000559_hash NULL
81450 +_000560_hash snd_emu10k1_fx8010_read 5 9605 _000560_hash NULL
81451 +_000561_hash snd_emu10k1_synth_copy_from_user 3-5 9061 _000561_hash NULL
81452 +_000563_hash snd_gus_dram_poke 4 18525 _000563_hash NULL
81453 +_000564_hash snd_hdsp_playback_copy 5 20676 _000564_hash NULL
81454 +_000565_hash snd_info_entry_write 3 63474 _000565_hash NULL
81455 +_000566_hash snd_korg1212_copy_from 6 36169 _000566_hash NULL
81456 +_000567_hash snd_mem_proc_write 3 9786 _000567_hash NULL
81457 +_000568_hash snd_midi_channel_init_set 1 30092 _000568_hash NULL
81458 +_000569_hash snd_midi_event_new 1 9893 _000750_hash NULL nohasharray
81459 +_000570_hash snd_opl4_mem_proc_write 5 9670 _000570_hash NULL
81460 +_000571_hash snd_pcm_aio_read 3 13900 _000571_hash NULL
81461 +_000572_hash snd_pcm_aio_write 3 28738 _000572_hash NULL
81462 +_000573_hash snd_pcm_oss_write1 3 10872 _000573_hash NULL
81463 +_000574_hash snd_pcm_oss_write2 3 27332 _000574_hash NULL
81464 +_000575_hash snd_rawmidi_kernel_write1 4 56847 _000575_hash NULL
81465 +_000576_hash snd_rme9652_playback_copy 5 20970 _000576_hash NULL
81466 +_000577_hash snd_sb_csp_load_user 3 45190 _000577_hash NULL
81467 +_000578_hash snd_usb_ctl_msg 8 8436 _000578_hash NULL
81468 +_000579_hash sock_bindtodevice 3 50942 _000579_hash NULL
81469 +_000580_hash sock_kmalloc 2 62205 _000580_hash NULL
81470 +_000581_hash spidev_write 3 44510 _000581_hash NULL
81471 +_000582_hash squashfs_read_table 3 16945 _000582_hash NULL
81472 +_000583_hash srpt_alloc_ioctx 2-3 51042 _000583_hash NULL
81473 +_000585_hash srpt_alloc_ioctx_ring 2 49330 _000585_hash NULL
81474 +_000586_hash st5481_setup_isocpipes 6-4 61340 _000586_hash NULL
81475 +_000587_hash sta_agg_status_write 3 45164 _000587_hash NULL
81476 +_000588_hash svc_setsockopt 5 36876 _000588_hash NULL
81477 +_000589_hash sys_add_key 4 61288 _000589_hash NULL
81478 +_000590_hash sys_modify_ldt 3 18824 _000590_hash NULL
81479 +_000591_hash sys_semtimedop 3 4486 _000591_hash NULL
81480 +_000592_hash sys_setdomainname 2 4373 _000592_hash NULL
81481 +_000593_hash sys_sethostname 2 42962 _000593_hash NULL
81482 +_000594_hash tda10048_writeregbulk 4 11050 _000594_hash NULL
81483 +_000595_hash tipc_log_resize 1 34803 _000595_hash NULL
81484 +_000596_hash tomoyo_write_self 3 45161 _000596_hash NULL
81485 +_000597_hash tower_write 3 8580 _000597_hash NULL
81486 +_000598_hash tpm_write 3 50798 _000598_hash NULL
81487 +_000599_hash trusted_instantiate 3 4710 _000599_hash NULL
81488 +_000600_hash trusted_update 3 12664 _000600_hash NULL
81489 +_000601_hash tt_changes_fill_buffer 3 62649 _000601_hash NULL
81490 +_000602_hash tty_buffer_alloc 2 45437 _000602_hash NULL
81491 +_000603_hash __tun_chr_ioctl 4 22300 _000603_hash NULL
81492 +_000604_hash ubi_more_leb_change_data 4 63534 _000604_hash NULL
81493 +_000605_hash ubi_more_update_data 4 39189 _000605_hash NULL
81494 +_000606_hash ubi_resize_volume 2 50172 _000606_hash NULL
81495 +_000607_hash udf_alloc_i_data 2 35786 _000607_hash NULL
81496 +_000608_hash uea_idma_write 3 64139 _000608_hash NULL
81497 +_000609_hash uea_request 4 47613 _000609_hash NULL
81498 +_000610_hash uea_send_modem_cmd 3 3888 _000610_hash NULL
81499 +_000611_hash uio_write 3 43202 _000611_hash NULL
81500 +_000612_hash um_idi_write 3 18293 _000612_hash NULL
81501 +_000613_hash us122l_ctl_msg 8 13330 _000613_hash NULL
81502 +_000614_hash usb_alloc_urb 1 43436 _000614_hash NULL
81503 +_000615_hash usblp_new_writeurb 2 22894 _000615_hash NULL
81504 +_000616_hash usblp_write 3 23178 _000616_hash NULL
81505 +_000617_hash usbtest_alloc_urb 3-5 34446 _000617_hash NULL
81506 +_000619_hash usbtmc_write 3 64340 _000619_hash NULL
81507 +_000620_hash user_instantiate 3 26131 _000620_hash NULL
81508 +_000621_hash user_update 3 41332 _000621_hash NULL
81509 +_000622_hash uvc_simplify_fraction 3 31303 _000622_hash NULL
81510 +_000623_hash uwb_rc_cmd_done 4 35892 _000623_hash NULL
81511 +_000624_hash uwb_rc_neh_grok_event 3 55799 _000624_hash NULL
81512 +_000625_hash v9fs_alloc_rdir_buf 2 42150 _000625_hash NULL
81513 +_000626_hash __vb2_perform_fileio 3 63033 _000626_hash NULL
81514 +_000627_hash vc_do_resize 3-4 48842 _000627_hash NULL
81515 +_000629_hash vcs_write 3 3910 _000629_hash NULL
81516 +_000630_hash vfd_write 3 14717 _000630_hash NULL
81517 +_000631_hash vga_arb_write 3 36112 _000631_hash NULL
81518 +_000632_hash vga_switcheroo_debugfs_write 3 33984 _000632_hash NULL
81519 +_000633_hash vhci_get_user 3 45039 _000633_hash NULL
81520 +_000634_hash video_proc_write 3 6724 _000634_hash NULL
81521 +_000635_hash vlsi_alloc_ring 3-4 57003 _000635_hash NULL
81522 +_000637_hash __vmalloc 1 61168 _000637_hash NULL
81523 +_000638_hash vmalloc_32 1 1135 _000638_hash NULL
81524 +_000639_hash vmalloc_32_user 1 37519 _000639_hash NULL
81525 +_000640_hash vmalloc_exec 1 36132 _000640_hash NULL
81526 +_000641_hash vmalloc_node 1 58700 _000641_hash NULL
81527 +_000642_hash __vmalloc_node_flags 1 30352 _000642_hash NULL
81528 +_000643_hash vmalloc_user 1 32308 _000643_hash NULL
81529 +_000644_hash vol_cdev_direct_write 3 20751 _000644_hash NULL
81530 +_000645_hash vp_request_msix_vectors 2 28849 _000645_hash NULL
81531 +_000646_hash vring_add_indirect 3-4 20737 _000646_hash NULL
81532 +_000648_hash vring_new_virtqueue 1 9671 _000648_hash NULL
81533 +_000649_hash vxge_os_dma_malloc 2 46184 _000649_hash NULL
81534 +_000650_hash vxge_os_dma_malloc_async 3 56348 _000650_hash NULL
81535 +_000651_hash wdm_write 3 53735 _000651_hash NULL
81536 +_000652_hash wiimote_hid_send 3 48528 _000652_hash NULL
81537 +_000653_hash wl1273_fm_fops_write 3 60621 _000653_hash NULL
81538 +_000654_hash wlc_phy_loadsampletable_nphy 3 64367 _000654_hash NULL
81539 +_000655_hash write 3 62671 _000655_hash NULL
81540 +_000656_hash write_flush 3 50803 _000656_hash NULL
81541 +_000657_hash write_rio 3 54837 _000657_hash NULL
81542 +_000658_hash x25_asy_change_mtu 2 26928 _000658_hash NULL
81543 +_000659_hash xdi_copy_from_user 4 8395 _000659_hash NULL
81544 +_000660_hash xfrm_dst_alloc_copy 3 3034 _000660_hash NULL
81545 +_000661_hash xfrm_user_policy 4 62573 _000661_hash NULL
81546 +_000662_hash xfs_attrmulti_attr_set 4 59346 _000662_hash NULL
81547 +_000663_hash xfs_handle_to_dentry 3 12135 _000663_hash NULL
81548 +_000664_hash __xip_file_write 3 2733 _000664_hash NULL
81549 +_000665_hash xprt_rdma_allocate 2 31372 _000665_hash NULL
81550 +_000666_hash zd_usb_iowrite16v_async 3 23984 _000666_hash NULL
81551 +_000667_hash zd_usb_read_fw 4 22049 _000667_hash NULL
81552 +_000668_hash zerocopy_sg_from_iovec 3 11828 _000668_hash NULL
81553 +_000669_hash zoran_write 3 22404 _000669_hash NULL
81554 +_000671_hash acpi_ex_allocate_name_string 2 7685 _000671_hash NULL
81555 +_000672_hash acpi_os_allocate_zeroed 1 37422 _000672_hash NULL
81556 +_000673_hash acpi_ut_initialize_buffer 2 47143 _002314_hash NULL nohasharray
81557 +_000674_hash ad7879_spi_xfer 3 36311 _000674_hash NULL
81558 +_000675_hash add_new_gdb 3 27643 _000675_hash NULL
81559 +_000676_hash add_numbered_child 5 14273 _000676_hash NULL
81560 +_000677_hash add_res_range 4 21310 _000677_hash NULL
81561 +_000678_hash addtgt 3 54703 _000678_hash NULL
81562 +_000679_hash add_uuid 4 49831 _000679_hash NULL
81563 +_000680_hash afs_cell_alloc 2 24052 _000680_hash NULL
81564 +_000681_hash aggr_recv_addba_req_evt 4 38037 _000681_hash NULL
81565 +_000682_hash agp_create_memory 1 1075 _000682_hash NULL
81566 +_000683_hash agp_create_user_memory 1 62955 _000683_hash NULL
81567 +_000684_hash alg_setsockopt 5 20985 _000684_hash NULL
81568 +_000685_hash alloc_async 1 14208 _000685_hash NULL
81569 +_000686_hash ___alloc_bootmem_nopanic 1 53626 _000686_hash NULL
81570 +_000687_hash alloc_buf 1 34532 _000687_hash NULL
81571 +_000688_hash alloc_chunk 1 49575 _000688_hash NULL
81572 +_000689_hash alloc_context 1 41283 _000689_hash NULL
81573 +_000690_hash alloc_ctrl_packet 1 44667 _000690_hash NULL
81574 +_000691_hash alloc_data_packet 1 46698 _000691_hash NULL
81575 +_000692_hash alloc_dca_provider 2 59670 _000692_hash NULL
81576 +_000693_hash __alloc_dev_table 2 54343 _000693_hash NULL
81577 +_000694_hash alloc_ep 1 17269 _000694_hash NULL
81578 +_000695_hash __alloc_extent_buffer 3 15093 _000695_hash NULL
81579 +_000696_hash alloc_group_attrs 2 9194 _000719_hash NULL nohasharray
81580 +_000697_hash alloc_large_system_hash 2 64490 _000697_hash NULL
81581 +_000698_hash alloc_netdev_mqs 1 30030 _000698_hash NULL
81582 +_000699_hash __alloc_objio_seg 1 7203 _000699_hash NULL
81583 +_000700_hash alloc_ring 2-4 15345 _000700_hash NULL
81584 +_000701_hash alloc_ring 2-4 39151 _000701_hash NULL
81585 +_000704_hash alloc_session 1-2 64171 _000704_hash NULL
81586 +_000708_hash alloc_smp_req 1 51337 _000708_hash NULL
81587 +_000709_hash alloc_smp_resp 1 3566 _000709_hash NULL
81588 +_000710_hash alloc_ts_config 1 45775 _000710_hash NULL
81589 +_000711_hash alloc_upcall 2 62186 _000711_hash NULL
81590 +_000712_hash altera_drscan 2 48698 _000712_hash NULL
81591 +_000713_hash altera_irscan 2 62396 _000713_hash NULL
81592 +_000714_hash altera_set_dr_post 2 54291 _000714_hash NULL
81593 +_000715_hash altera_set_dr_pre 2 64862 _000715_hash NULL
81594 +_000716_hash altera_set_ir_post 2 20948 _000716_hash NULL
81595 +_000717_hash altera_set_ir_pre 2 54103 _000717_hash NULL
81596 +_000718_hash altera_swap_dr 2 50090 _000718_hash NULL
81597 +_000719_hash altera_swap_ir 2 9194 _000719_hash &_000696_hash
81598 +_000720_hash amd_create_gatt_pages 1 20537 _000720_hash NULL
81599 +_000721_hash aoechr_write 3 62883 _001352_hash NULL nohasharray
81600 +_000722_hash applesmc_create_nodes 2 49392 _000722_hash NULL
81601 +_000723_hash array_zalloc 1-2 7519 _000723_hash NULL
81602 +_000725_hash arvo_sysfs_read 6 31617 _000725_hash NULL
81603 +_000726_hash arvo_sysfs_write 6 3311 _000726_hash NULL
81604 +_000727_hash asd_store_update_bios 4 10165 _000727_hash NULL
81605 +_000728_hash ata_host_alloc 2 46094 _000728_hash NULL
81606 +_000729_hash atalk_sendmsg 4 21677 _000729_hash NULL
81607 +_000730_hash ath6kl_cfg80211_connect_event 7-9-8 13443 _000730_hash NULL
81608 +_000731_hash ath6kl_mgmt_tx 9 21153 _000731_hash NULL
81609 +_000732_hash ath6kl_wmi_roam_tbl_event_rx 3 43440 _000732_hash NULL
81610 +_000733_hash ath6kl_wmi_send_mgmt_cmd 7 17347 _000733_hash NULL
81611 +_000734_hash ath_descdma_setup 5 12257 _000734_hash NULL
81612 +_000735_hash ath_rx_edma_init 2 65483 _000735_hash NULL
81613 +_000736_hash ati_create_gatt_pages 1 4722 _000736_hash NULL
81614 +_000737_hash au0828_init_isoc 2-3 61917 _000737_hash NULL
81615 +_000739_hash audit_init_entry 1 38644 _000739_hash NULL
81616 +_000740_hash ax25_sendmsg 4 62770 _000740_hash NULL
81617 +_000741_hash b1_alloc_card 1 36155 _000741_hash NULL
81618 +_000742_hash b43_nphy_load_samples 3 36481 _000742_hash NULL
81619 +_000743_hash bio_copy_user_iov 4 37660 _000743_hash NULL
81620 +_000744_hash __bio_map_kern 2-3 47379 _000744_hash NULL
81621 +_000746_hash blk_register_region 1-2 51424 _000746_hash NULL
81622 +_000748_hash bm_entry_write 3 28338 _000748_hash NULL
81623 +_000749_hash bm_realloc_pages 2 9431 _000749_hash NULL
81624 +_000750_hash bm_register_write 3 9893 _000750_hash &_000569_hash
81625 +_000751_hash bm_status_write 3 12964 _000751_hash NULL
81626 +_000752_hash br_mdb_rehash 2 42643 _000752_hash NULL
81627 +_000753_hash btrfs_copy_from_user 3 43806 _000753_hash NULL
81628 +_000754_hash btrfs_insert_delayed_dir_index 4 63720 _000754_hash NULL
81629 +_000755_hash __btrfs_map_block 3 49839 _000755_hash NULL
81630 +_000756_hash __c4iw_init_resource_fifo 3 8334 _000756_hash NULL
81631 +_000757_hash cache_downcall 3 13666 _000757_hash NULL
81632 +_000758_hash cache_slow_downcall 2 8570 _000758_hash NULL
81633 +_000759_hash ca_extend 2 64541 _000759_hash NULL
81634 +_000760_hash caif_seqpkt_sendmsg 4 22961 _000760_hash NULL
81635 +_000761_hash caif_stream_sendmsg 4 9110 _000761_hash NULL
81636 +_000762_hash carl9170_cmd_buf 3 950 _000762_hash NULL
81637 +_000763_hash cdev_add 2-3 38176 _000763_hash NULL
81638 +_000765_hash cdrom_read_cdda 4 50478 _000765_hash NULL
81639 +_000766_hash ceph_dns_resolve_name 1 62488 _000766_hash NULL
81640 +_000767_hash ceph_msgpool_get 2 54258 _000767_hash NULL
81641 +_000768_hash cfg80211_connect_result 4-6 56515 _000768_hash NULL
81642 +_000770_hash cfg80211_disconnected 4 57 _000770_hash NULL
81643 +_000771_hash cfg80211_inform_bss 8 19332 _000771_hash NULL
81644 +_000772_hash cfg80211_inform_bss_frame 4 41078 _000772_hash NULL
81645 +_000773_hash cfg80211_mlme_register_mgmt 5 19852 _000773_hash NULL
81646 +_000774_hash cfg80211_roamed_bss 4-6 50198 _000774_hash NULL
81647 +_000776_hash cifs_readdata_alloc 1 50318 _000776_hash NULL
81648 +_000777_hash cifs_readv_from_socket 3 19109 _000777_hash NULL
81649 +_000778_hash cifs_writedata_alloc 1 32880 _000778_hash NULL
81650 +_000779_hash cnic_alloc_dma 3 34641 _000779_hash NULL
81651 +_000780_hash configfs_write_file 3 61621 _000780_hash NULL
81652 +_000781_hash construct_key 3 11329 _000781_hash NULL
81653 +_000782_hash context_alloc 3 24645 _000782_hash NULL
81654 +_000783_hash copy_to_user 3 57835 _000783_hash NULL
81655 +_000784_hash create_attr_set 1 22861 _000784_hash NULL
81656 +_000785_hash create_bounce_buffer 3 39155 _000785_hash NULL
81657 +_000786_hash create_gpadl_header 2 19064 _000786_hash NULL
81658 +_000787_hash _create_sg_bios 4 31244 _000787_hash NULL
81659 +_000788_hash cryptd_alloc_instance 2-3 18048 _000788_hash NULL
81660 +_000790_hash crypto_ahash_setkey 3 55134 _000790_hash NULL
81661 +_000791_hash crypto_alloc_instance2 3 25277 _000791_hash NULL
81662 +_000792_hash crypto_shash_setkey 3 60483 _000792_hash NULL
81663 +_000793_hash cx231xx_init_bulk 3-2 47024 _000793_hash NULL
81664 +_000794_hash cx231xx_init_isoc 2-3 56453 _000794_hash NULL
81665 +_000796_hash cx231xx_init_vbi_isoc 2-3 28053 _000796_hash NULL
81666 +_000798_hash cxgb_alloc_mem 1 24007 _000798_hash NULL
81667 +_000799_hash cxgbi_device_portmap_create 3 25747 _000799_hash NULL
81668 +_000800_hash cxgbi_device_register 1-2 36746 _000800_hash NULL
81669 +_000802_hash __cxio_init_resource_fifo 3 23447 _000802_hash NULL
81670 +_000803_hash dccp_sendmsg 4 56058 _000803_hash NULL
81671 +_000804_hash ddp_make_gl 1 12179 _000804_hash NULL
81672 +_000805_hash depth_write 3 3021 _000805_hash NULL
81673 +_000806_hash dev_irnet_write 3 11398 _000806_hash NULL
81674 +_000807_hash dev_set_alias 3 50084 _000807_hash NULL
81675 +_000808_hash dev_write 3 7708 _000808_hash NULL
81676 +_000809_hash dfs_global_file_write 3 6112 _000809_hash NULL
81677 +_000810_hash dgram_sendmsg 4 45679 _000810_hash NULL
81678 +_000811_hash disconnect 4 32521 _000811_hash NULL
81679 +_000812_hash dma_attach 6-7 50831 _000812_hash NULL
81680 +_000814_hash dn_sendmsg 4 38390 _000814_hash NULL
81681 +_000815_hash do_dccp_setsockopt 5 54377 _000815_hash NULL
81682 +_000816_hash do_jffs2_setxattr 5 25910 _000816_hash NULL
81683 +_000817_hash do_msgsnd 4 1387 _000817_hash NULL
81684 +_000818_hash do_raw_setsockopt 5 55215 _000818_hash NULL
81685 +_000819_hash do_readv_writev 4 51849 _000819_hash NULL
81686 +_000820_hash do_sync 1 9604 _000820_hash NULL
81687 +_000821_hash dup_array 3 33551 _000821_hash NULL
81688 +_000822_hash dvb_audio_write 3 51275 _000822_hash NULL
81689 +_000823_hash dvb_ca_en50221_init 4 45718 _000823_hash NULL
81690 +_000824_hash dvb_video_write 3 754 _000824_hash NULL
81691 +_000825_hash econet_sendmsg 4 51430 _000825_hash NULL
81692 +_000826_hash ecryptfs_decode_and_decrypt_filename 5 10379 _000826_hash NULL
81693 +_000827_hash ecryptfs_encrypt_and_encode_filename 6 2109 _000827_hash NULL
81694 +_000828_hash ecryptfs_send_message_locked 2 31801 _000828_hash NULL
81695 +_000829_hash edac_device_alloc_ctl_info 1 5941 _000829_hash NULL
81696 +_000830_hash edac_mc_alloc 1 54846 _000830_hash NULL
81697 +_000831_hash edac_pci_alloc_ctl_info 1 63388 _000831_hash NULL
81698 +_000832_hash efivar_create_sysfs_entry 2 19485 _000832_hash NULL
81699 +_000833_hash em28xx_alloc_isoc 4 46892 _000833_hash NULL
81700 +_000834_hash enable_write 3 30456 _000834_hash NULL
81701 +_000835_hash enclosure_register 3 57412 _000835_hash NULL
81702 +_000836_hash ext4_kvzalloc 1 47605 _000836_hash NULL
81703 +_000837_hash extend_netdev_table 2 31680 _000837_hash NULL
81704 +_000838_hash __feat_register_sp 6 64712 _000838_hash NULL
81705 +_000839_hash __ffs_ep0_read_events 3 48868 _000839_hash NULL
81706 +_000840_hash ffs_ep0_write 3 9438 _000840_hash NULL
81707 +_000841_hash ffs_epfile_read 3 18775 _000841_hash NULL
81708 +_000842_hash ffs_epfile_write 3 48014 _000842_hash NULL
81709 +_000843_hash fib_info_hash_alloc 1 9075 _000843_hash NULL
81710 +_000844_hash fillonedir 3 41746 _000844_hash NULL
81711 +_000845_hash flexcop_device_kmalloc 1 54793 _000845_hash NULL
81712 +_000846_hash frame_alloc 4 15981 _000846_hash NULL
81713 +_000847_hash fw_node_create 2 9559 _000847_hash NULL
81714 +_000848_hash garmin_read_process 3 27509 _000848_hash NULL
81715 +_000849_hash garp_request_join 4 7471 _000849_hash NULL
81716 +_000850_hash get_derived_key 4 61100 _000850_hash NULL
81717 +_000851_hash get_entry 4 16003 _000851_hash NULL
81718 +_000852_hash get_free_de 2 33714 _000852_hash NULL
81719 +_000853_hash get_new_cssid 2 51665 _000853_hash NULL
81720 +_000854_hash getxattr 4 24398 _000854_hash NULL
81721 +_000855_hash gspca_dev_probe2 4 59833 _000855_hash NULL
81722 +_000856_hash hcd_alloc_coherent 5 55862 _000856_hash NULL
81723 +_000857_hash hci_sock_sendmsg 4 37420 _000857_hash NULL
81724 +_000858_hash hid_register_field 2-3 4874 _000858_hash NULL
81725 +_000860_hash hid_report_raw_event 4 7024 _000860_hash NULL
81726 +_000861_hash hpi_alloc_control_cache 1 35351 _000861_hash NULL
81727 +_000862_hash hugetlbfs_read_actor 2-5-4 34547 _000862_hash NULL
81728 +_000865_hash hvc_alloc 4 12579 _000865_hash NULL
81729 +_000866_hash __hwahc_dev_set_key 5 46328 _000866_hash NULL
81730 +_000867_hash i2400m_zrealloc_2x 3 54166 _001430_hash NULL nohasharray
81731 +_000868_hash ib_alloc_device 1 26483 _000868_hash NULL
81732 +_000869_hash ib_create_send_mad 5 1196 _000869_hash NULL
81733 +_000870_hash ibmasm_new_command 2 25714 _000870_hash NULL
81734 +_000871_hash ib_send_cm_drep 3 50186 _000871_hash NULL
81735 +_000872_hash ib_send_cm_mra 4 60202 _000872_hash NULL
81736 +_000873_hash ib_send_cm_rtu 3 63138 _000873_hash NULL
81737 +_000874_hash ieee80211_key_alloc 3 19065 _000874_hash NULL
81738 +_000875_hash ieee80211_mgmt_tx 9 46860 _000875_hash NULL
81739 +_000876_hash ieee80211_send_probe_req 6 6924 _000876_hash NULL
81740 +_000877_hash if_writecmd 2 815 _000877_hash NULL
81741 +_000878_hash init_bch 1-2 64130 _000878_hash NULL
81742 +_000880_hash init_ipath 1 48187 _000880_hash NULL
81743 +_000881_hash init_list_set 2-3 39188 _000881_hash NULL
81744 +_000883_hash init_q 4 132 _000883_hash NULL
81745 +_000884_hash init_state 2 60165 _000884_hash NULL
81746 +_000885_hash init_tag_map 3 57515 _000885_hash NULL
81747 +_000886_hash input_ff_create 2 21240 _000886_hash NULL
81748 +_000887_hash input_mt_init_slots 2 31183 _000887_hash NULL
81749 +_000888_hash interfaces 2 38859 _000888_hash NULL
81750 +_000889_hash ioat2_alloc_ring 2 11172 _000889_hash NULL
81751 +_000890_hash ip_generic_getfrag 3-4 12187 _000890_hash NULL
81752 +_000892_hash ipr_alloc_ucode_buffer 1 40199 _000892_hash NULL
81753 +_000893_hash ip_set_alloc 1 57953 _000893_hash NULL
81754 +_000894_hash ipv6_flowlabel_opt 3 58135 _001125_hash NULL nohasharray
81755 +_000895_hash ipv6_renew_options 5 28867 _000895_hash NULL
81756 +_000896_hash ipxrtr_route_packet 4 54036 _000896_hash NULL
81757 +_000897_hash irda_sendmsg 4 4388 _000897_hash NULL
81758 +_000898_hash irda_sendmsg_dgram 4 38563 _000898_hash NULL
81759 +_000899_hash irda_sendmsg_ultra 4 42047 _000899_hash NULL
81760 +_000900_hash irias_add_octseq_attrib 4 29983 _000900_hash NULL
81761 +_000901_hash irq_alloc_generic_chip 2 26650 _000901_hash NULL
81762 +_000902_hash irq_domain_add_linear 2 29236 _000902_hash NULL
81763 +_000903_hash iscsi_alloc_session 3 49390 _000903_hash NULL
81764 +_000904_hash iscsi_create_conn 2 50425 _000904_hash NULL
81765 +_000905_hash iscsi_create_endpoint 1 15193 _000905_hash NULL
81766 +_000906_hash iscsi_create_iface 5 38510 _000906_hash NULL
81767 +_000907_hash iscsi_decode_text_input 4 58292 _000907_hash NULL
81768 +_000908_hash iscsi_pool_init 2-4 54913 _000908_hash NULL
81769 +_000910_hash iscsit_dump_data_payload 2 38683 _000910_hash NULL
81770 +_000911_hash isdn_write 3 45863 _000911_hash NULL
81771 +_000912_hash isku_receive 4 54130 _000912_hash NULL
81772 +_000913_hash isku_send 4 41542 _000913_hash NULL
81773 +_000914_hash islpci_mgt_transaction 5 23610 _000914_hash NULL
81774 +_000915_hash iso_sched_alloc 1 13377 _002079_hash NULL nohasharray
81775 +_000916_hash ivtv_v4l2_write 3 39226 _000916_hash NULL
81776 +_000917_hash iwl_trans_txq_alloc 3 36147 _000917_hash NULL
81777 +_000918_hash iwmct_fw_parser_init 4 37876 _000918_hash NULL
81778 +_000919_hash iwm_notif_send 6 12295 _000919_hash NULL
81779 +_000920_hash iwm_ntf_calib_res 3 11686 _000920_hash NULL
81780 +_000921_hash iwm_umac_set_config_var 4 17320 _000921_hash NULL
81781 +_000922_hash ixgbe_alloc_q_vector 3-5 45428 _000922_hash NULL
81782 +_000924_hash jbd2_journal_init_revoke 2 51088 _000924_hash NULL
81783 +_000925_hash jffs2_write_dirent 5 37311 _000925_hash NULL
81784 +_000926_hash journal_init_revoke 2 56933 _000926_hash NULL
81785 +_000927_hash keyctl_instantiate_key 3 41855 _000927_hash NULL
81786 +_000928_hash keyctl_instantiate_key_iov 3 16969 _000928_hash NULL
81787 +_000929_hash __kfifo_from_user 3 20399 _000929_hash NULL
81788 +_000930_hash kimage_crash_alloc 3 3233 _000930_hash NULL
81789 +_000931_hash kimage_normal_alloc 3 31140 _000931_hash NULL
81790 +_000932_hash kmem_realloc 2 37489 _000932_hash NULL
81791 +_000933_hash kmem_zalloc 1 11510 _000933_hash NULL
81792 +_000934_hash koneplus_send 4 18226 _000934_hash NULL
81793 +_000935_hash koneplus_sysfs_read 6 42792 _000935_hash NULL
81794 +_000936_hash kovaplus_send 4 10009 _000936_hash NULL
81795 +_000937_hash kvm_read_guest_page_mmu 6 37611 _000937_hash NULL
81796 +_000938_hash kvm_set_irq_routing 3 48704 _000938_hash NULL
81797 +_000939_hash kvm_write_guest_cached 4 11106 _000939_hash NULL
81798 +_000940_hash kvm_write_guest_page 5 63555 _000940_hash NULL
81799 +_000941_hash l2cap_skbuff_fromiovec 3-4 35003 _000941_hash NULL
81800 +_000943_hash l2tp_ip_sendmsg 4 50411 _000943_hash NULL
81801 +_000944_hash l2tp_session_create 1 25286 _000944_hash NULL
81802 +_000945_hash lc_create 3 48662 _000945_hash NULL
81803 +_000946_hash leaf_dealloc 3 29566 _000946_hash NULL
81804 +_000947_hash linear_conf 2 23485 _000947_hash NULL
81805 +_000948_hash lirc_buffer_init 2-3 53282 _000948_hash NULL
81806 +_000950_hash llc_ui_sendmsg 4 24987 _000950_hash NULL
81807 +_000951_hash lpfc_sli4_queue_alloc 3 62646 _000951_hash NULL
81808 +_000952_hash mce_request_packet 3 1073 _000952_hash NULL
81809 +_000953_hash mdiobus_alloc_size 1 52259 _000953_hash NULL
81810 +_000954_hash media_entity_init 2-4 15870 _001556_hash NULL nohasharray
81811 +_000956_hash memstick_alloc_host 1 142 _000956_hash NULL
81812 +_000957_hash mesh_table_alloc 1 22305 _000957_hash NULL
81813 +_000958_hash mfd_add_devices 4 56753 _000958_hash NULL
81814 +_000959_hash mISDN_sock_sendmsg 4 41035 _000959_hash NULL
81815 +_000960_hash mmc_alloc_host 1 48097 _000960_hash NULL
81816 +_000961_hash mmc_test_alloc_mem 3 28102 _000961_hash NULL
81817 +_000962_hash mpi_alloc 1 18094 _000962_hash NULL
81818 +_000963_hash mpihelp_mul_karatsuba_case 5-3 23918 _000963_hash NULL
81819 +_000964_hash mpihelp_mul_n 4 16405 _000964_hash NULL
81820 +_000965_hash mpi_set_bit 2 15104 _000965_hash NULL
81821 +_000966_hash mpi_set_highbit 2 37327 _001420_hash NULL nohasharray
81822 +_000967_hash mtd_concat_create 2 14416 _000967_hash NULL
81823 +_000968_hash mvumi_alloc_mem_resource 3 47750 _000968_hash NULL
81824 +_000969_hash mwifiex_11n_create_rx_reorder_tbl 4 63806 _000969_hash NULL
81825 +_000970_hash mwifiex_alloc_sdio_mpa_buffers 2-3 60961 _000970_hash NULL
81826 +_000972_hash mwl8k_cmd_set_beacon 4 23110 _000972_hash NULL
81827 +_000973_hash neigh_hash_alloc 1 17595 _000973_hash NULL
81828 +_000974_hash netlink_sendmsg 4 33708 _001172_hash NULL nohasharray
81829 +_000975_hash netxen_alloc_sds_rings 2 13417 _000975_hash NULL
81830 +_000976_hash new_bind_ctl 2 35324 _000976_hash NULL
81831 +_000977_hash new_dir 3 31919 _000977_hash NULL
81832 +_000978_hash new_tape_buffer 2 32866 _000978_hash NULL
81833 +_000979_hash nfc_llcp_build_tlv 3 19536 _000979_hash NULL
81834 +_000980_hash nfc_llcp_send_i_frame 3 59130 _000980_hash NULL
81835 +_000981_hash nfs4_alloc_slots 1 2454 _000981_hash NULL
81836 +_000982_hash nfsctl_transaction_write 3 64800 _000982_hash NULL
81837 +_000983_hash nfs_idmap_request_key 3 30208 _000983_hash NULL
81838 +_000984_hash nfs_readdata_alloc 1 9990 _000984_hash NULL
81839 +_000985_hash nfs_writedata_alloc 1 62868 _000985_hash NULL
81840 +_000986_hash nl_pid_hash_zalloc 1 23314 _000986_hash NULL
81841 +_000987_hash nr_sendmsg 4 53656 _000987_hash NULL
81842 +_000988_hash nsm_create_handle 4 38060 _000988_hash NULL
81843 +_000989_hash ntfs_copy_from_user_iovec 3-6 49829 _000989_hash NULL
81844 +_000991_hash ntfs_file_buffered_write 4-6 41442 _000991_hash NULL
81845 +_000993_hash __ntfs_malloc 1 34022 _000993_hash NULL
81846 +_000994_hash nvme_alloc_queue 3 46865 _000994_hash NULL
81847 +_000995_hash ocfs2_acl_from_xattr 2 21604 _000995_hash NULL
81848 +_000996_hash ocfs2_control_message 3 19564 _000996_hash NULL
81849 +_000997_hash opera1_usb_i2c_msgxfer 4 64521 _000997_hash NULL
81850 +_000998_hash _ore_get_io_state 3 2166 _000998_hash NULL
81851 +_000999_hash orig_hash_add_if 2 53676 _000999_hash NULL
81852 +_001000_hash orig_hash_del_if 2 45080 _001000_hash NULL
81853 +_001001_hash orinoco_set_key 5-7 17878 _001001_hash NULL
81854 +_001003_hash osdmap_set_max_osd 2 57630 _001003_hash NULL
81855 +_001004_hash _osd_realloc_seg 3 54352 _001004_hash NULL
81856 +_001005_hash OSDSetBlock 2-4 38986 _001005_hash NULL
81857 +_001007_hash osst_execute 7-6 17607 _001007_hash NULL
81858 +_001008_hash osst_write 3 31581 _001008_hash NULL
81859 +_001009_hash otp_read 2-5-4 10594 _001009_hash NULL
81860 +_001012_hash ovs_vport_alloc 1 33475 _001012_hash NULL
81861 +_001013_hash packet_sendmsg_spkt 4 28885 _001013_hash NULL
81862 +_001014_hash pair_device 4 61175 _001708_hash NULL nohasharray
81863 +_001015_hash pccard_store_cis 6 18176 _001015_hash NULL
81864 +_001016_hash pci_add_cap_save_buffer 3 3426 _001016_hash NULL
81865 +_001017_hash pcnet32_realloc_rx_ring 3 36598 _001017_hash NULL
81866 +_001018_hash pcnet32_realloc_tx_ring 3 38428 _001018_hash NULL
81867 +_001019_hash pcpu_mem_zalloc 1 22948 _001019_hash NULL
81868 +_001020_hash pep_sendmsg 4 62524 _001020_hash NULL
81869 +_001021_hash pfkey_sendmsg 4 47394 _001021_hash NULL
81870 +_001022_hash pidlist_resize 2 496 _001022_hash NULL
81871 +_001023_hash pin_code_reply 4 46510 _001023_hash NULL
81872 +_001024_hash ping_getfrag 3-4 8360 _001024_hash NULL
81873 +_001026_hash pipe_set_size 2 5204 _001026_hash NULL
81874 +_001027_hash pkt_bio_alloc 1 48284 _001027_hash NULL
81875 +_001028_hash platform_create_bundle 4-6 12785 _001028_hash NULL
81876 +_001030_hash play_iframe 3 8219 _001030_hash NULL
81877 +_001031_hash pm8001_store_update_fw 4 55716 _001031_hash NULL
81878 +_001032_hash pmcraid_alloc_sglist 1 9864 _001032_hash NULL
81879 +_001033_hash pn533_dep_link_up 5 7659 _001033_hash NULL
81880 +_001034_hash pnp_alloc 1 24869 _001419_hash NULL nohasharray
81881 +_001035_hash pn_sendmsg 4 12640 _001035_hash NULL
81882 +_001036_hash pppoe_sendmsg 4 48039 _001036_hash NULL
81883 +_001037_hash pppol2tp_sendmsg 4 56420 _001037_hash NULL
81884 +_001038_hash process_vm_rw 3-5 47533 _001038_hash NULL
81885 +_001040_hash process_vm_rw_single_vec 1-2 26213 _001040_hash NULL
81886 +_001042_hash proc_write 3 51003 _001042_hash NULL
81887 +_001043_hash profile_load 3 58267 _001043_hash NULL
81888 +_001044_hash profile_remove 3 8556 _001044_hash NULL
81889 +_001045_hash profile_replace 3 14652 _001045_hash NULL
81890 +_001046_hash pscsi_get_bio 1 56103 _001046_hash NULL
81891 +_001047_hash pyra_send 4 12061 _001047_hash NULL
81892 +_001048_hash qc_capture 3 19298 _001048_hash NULL
81893 +_001049_hash qla4xxx_alloc_work 2 44813 _001049_hash NULL
81894 +_001050_hash qlcnic_alloc_msix_entries 2 46160 _001050_hash NULL
81895 +_001051_hash qlcnic_alloc_sds_rings 2 26795 _001051_hash NULL
81896 +_001052_hash queue_received_packet 5 9657 _001052_hash NULL
81897 +_001053_hash raw_send_hdrinc 4 58803 _001053_hash NULL
81898 +_001054_hash raw_sendmsg 4 23078 _001054_hash &_000022_hash
81899 +_001055_hash rawsock_sendmsg 4 60010 _001055_hash NULL
81900 +_001056_hash rawv6_send_hdrinc 3 35425 _001056_hash NULL
81901 +_001057_hash rb_alloc 1 3102 _001057_hash NULL
81902 +_001058_hash rbd_alloc_coll 1 33678 _001058_hash NULL
81903 +_001059_hash rbd_create_rw_ops 2 4605 _001059_hash NULL
81904 +_001060_hash rds_ib_inc_copy_to_user 3 55007 _001060_hash NULL
81905 +_001061_hash rds_iw_inc_copy_to_user 3 29214 _001061_hash NULL
81906 +_001062_hash rds_message_alloc 1 10517 _001062_hash NULL
81907 +_001063_hash rds_message_copy_from_user 3 45510 _001063_hash NULL
81908 +_001064_hash rds_message_inc_copy_to_user 3 26540 _001064_hash NULL
81909 +_001065_hash redrat3_transmit_ir 3 64244 _001065_hash NULL
81910 +_001066_hash regcache_rbtree_insert_to_block 5 58009 _001066_hash NULL
81911 +_001067_hash _regmap_raw_write 4 42652 _001067_hash NULL
81912 +_001068_hash regmap_register_patch 3 21681 _001068_hash NULL
81913 +_001069_hash relay_alloc_page_array 1 52735 _001069_hash NULL
81914 +_001070_hash remove_uuid 4 64505 _001070_hash NULL
81915 +_001071_hash reshape_ring 2 29147 _001071_hash NULL
81916 +_001072_hash RESIZE_IF_NEEDED 2 56286 _001072_hash NULL
81917 +_001073_hash resize_stripes 2 61650 _001073_hash NULL
81918 +_001074_hash rfcomm_sock_sendmsg 4 37661 _001074_hash NULL
81919 +_001075_hash rose_sendmsg 4 20249 _001075_hash NULL
81920 +_001076_hash rxrpc_send_data 5 21553 _001076_hash NULL
81921 +_001077_hash rxrpc_setsockopt 5 50286 _001077_hash NULL
81922 +_001078_hash saa7146_vmalloc_build_pgtable 2 19780 _001078_hash NULL
81923 +_001079_hash saa7164_buffer_alloc_user 2 9627 _001079_hash NULL
81924 +_001081_hash sco_send_frame 3 41815 _001081_hash NULL
81925 +_001082_hash scsi_host_alloc 2 63041 _001082_hash NULL
81926 +_001083_hash scsi_tgt_kspace_exec 8 9522 _001083_hash NULL
81927 +_001084_hash sctp_sendmsg 4 61919 _001084_hash NULL
81928 +_001085_hash sctp_setsockopt 5 44788 _001085_hash NULL
81929 +_001086_hash sctp_setsockopt_connectx 3 6073 _001086_hash NULL
81930 +_001087_hash sctp_setsockopt_connectx_old 3 22631 _001087_hash NULL
81931 +_001088_hash sctp_tsnmap_init 2 36446 _001088_hash NULL
81932 +_001089_hash sctp_user_addto_chunk 2-3 62047 _001089_hash NULL
81933 +_001091_hash security_context_to_sid 2 19839 _001091_hash NULL
81934 +_001092_hash security_context_to_sid_default 2 3492 _001092_hash NULL
81935 +_001093_hash security_context_to_sid_force 2 20724 _001093_hash NULL
81936 +_001094_hash selinux_transaction_write 3 59038 _001094_hash NULL
81937 +_001095_hash sel_write_access 3 51704 _001095_hash NULL
81938 +_001096_hash sel_write_create 3 11353 _001096_hash NULL
81939 +_001097_hash sel_write_member 3 28800 _001097_hash NULL
81940 +_001098_hash sel_write_relabel 3 55195 _001098_hash NULL
81941 +_001099_hash sel_write_user 3 45060 _001099_hash NULL
81942 +_001100_hash __seq_open_private 3 40715 _001100_hash NULL
81943 +_001101_hash serverworks_create_gatt_pages 1 46582 _001101_hash NULL
81944 +_001102_hash set_connectable 4 56458 _001102_hash NULL
81945 +_001103_hash set_dev_class 4 39645 _001697_hash NULL nohasharray
81946 +_001104_hash set_discoverable 4 48141 _001104_hash NULL
81947 +_001105_hash setkey 3 14987 _001105_hash NULL
81948 +_001106_hash set_le 4 30581 _001106_hash NULL
81949 +_001107_hash set_link_security 4 4502 _001107_hash NULL
81950 +_001108_hash set_local_name 4 55757 _001108_hash NULL
81951 +_001109_hash set_powered 4 12129 _001109_hash NULL
81952 +_001110_hash set_ssp 4 62411 _001110_hash NULL
81953 +_001111_hash sg_build_sgat 3 60179 _001111_hash &_000305_hash
81954 +_001112_hash sg_read_oxfer 3 51724 _001112_hash NULL
81955 +_001113_hash shmem_xattr_set 4 11843 _001113_hash NULL
81956 +_001114_hash simple_alloc_urb 3 60420 _001114_hash NULL
81957 +_001115_hash sisusb_send_bridge_packet 2 11649 _001115_hash NULL
81958 +_001116_hash sisusb_send_packet 2 20891 _001116_hash NULL
81959 +_001117_hash skb_add_data_nocache 4 4682 _001117_hash NULL
81960 +_001118_hash skb_copy_datagram_from_iovec 2-5-4 52014 _001118_hash NULL
81961 +_001121_hash skb_copy_to_page_nocache 6 58624 _001121_hash NULL
81962 +_001122_hash sk_chk_filter 2 42095 _001122_hash NULL
81963 +_001123_hash skcipher_sendmsg 4 30290 _001123_hash NULL
81964 +_001124_hash sl_change_mtu 2 7396 _001124_hash NULL
81965 +_001125_hash slhc_init 1-2 58135 _001125_hash &_000894_hash
81966 +_001127_hash sm501_create_subdev 3-4 48668 _001127_hash NULL
81967 +_001129_hash smk_write_access 3 49561 _001129_hash NULL
81968 +_001130_hash snapshot_write 3 28351 _001130_hash NULL
81969 +_001131_hash snd_ac97_pcm_assign 2 30218 _001131_hash NULL
81970 +_001132_hash snd_card_create 4 64418 _001411_hash NULL nohasharray
81971 +_001133_hash snd_emux_create_port 3 42533 _001133_hash NULL
81972 +_001134_hash snd_gus_dram_write 4 38784 _001134_hash NULL
81973 +_001135_hash snd_midi_channel_alloc_set 1 28153 _001135_hash NULL
81974 +_001136_hash _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 _001136_hash NULL
81975 +_001137_hash snd_pcm_oss_sync1 2 45298 _001137_hash NULL
81976 +_001138_hash snd_pcm_oss_write 3 38108 _001138_hash NULL
81977 +_001139_hash snd_pcm_plugin_build 5 25505 _001139_hash NULL
81978 +_001140_hash snd_rawmidi_kernel_write 3 25106 _001140_hash NULL
81979 +_001141_hash snd_rawmidi_write 3 28008 _001141_hash NULL
81980 +_001142_hash snd_rme32_playback_copy 5 43732 _001142_hash NULL
81981 +_001143_hash snd_rme96_playback_copy 5 13111 _001143_hash NULL
81982 +_001144_hash snd_seq_device_new 4 31753 _001144_hash NULL
81983 +_001145_hash snd_seq_oss_readq_new 2 14283 _001145_hash NULL
81984 +_001146_hash snd_vx_create 4 40948 _001146_hash NULL
81985 +_001147_hash sock_setsockopt 5 50088 _001147_hash NULL
81986 +_001148_hash sound_write 3 5102 _001148_hash NULL
81987 +_001149_hash _sp2d_alloc 1 16944 _001149_hash NULL
81988 +_001150_hash spi_alloc_master 2 45223 _001150_hash NULL
81989 +_001151_hash spidev_message 3 5518 _001151_hash NULL
81990 +_001152_hash spi_register_board_info 2 35651 _001152_hash NULL
81991 +_001153_hash squashfs_cache_init 2 41656 _001153_hash NULL
81992 +_001154_hash squashfs_read_data 6 59440 _001154_hash NULL
81993 +_001155_hash srp_alloc_iu 2 44227 _001155_hash NULL
81994 +_001156_hash srp_iu_pool_alloc 2 17920 _001156_hash NULL
81995 +_001157_hash srp_ring_alloc 2 26760 _001157_hash NULL
81996 +_001159_hash start_isoc_chain 2 565 _001159_hash NULL
81997 +_001160_hash stk_prepare_sio_buffers 2 57168 _001160_hash NULL
81998 +_001161_hash store_iwmct_log_level 4 60209 _001161_hash NULL
81999 +_001162_hash store_iwmct_log_level_fw 4 1974 _001162_hash NULL
82000 +_001163_hash st_write 3 16874 _001163_hash NULL
82001 +_001164_hash svc_pool_map_alloc_arrays 2 47181 _001164_hash NULL
82002 +_001165_hash symtab_init 2 61050 _001165_hash NULL
82003 +_001166_hash sys_bind 3 10799 _001166_hash NULL
82004 +_001167_hash sys_connect 3 15291 _001167_hash NULL
82005 +_001168_hash sys_flistxattr 3 41407 _001168_hash NULL
82006 +_001169_hash sys_fsetxattr 4 49736 _001169_hash NULL
82007 +_001170_hash sysfs_write_file 3 57116 _001170_hash NULL
82008 +_001171_hash sys_ipc 3 4889 _001171_hash NULL
82009 +_001172_hash sys_keyctl 4 33708 _001172_hash &_000974_hash
82010 +_001173_hash sys_listxattr 3 27833 _001173_hash NULL
82011 +_001174_hash sys_llistxattr 3 4532 _001174_hash NULL
82012 +_001175_hash sys_lsetxattr 4 61177 _001175_hash NULL
82013 +_001176_hash sys_mq_timedsend 3 57661 _001176_hash NULL
82014 +_001177_hash sys_sched_setaffinity 2 32046 _001177_hash NULL
82015 +_001178_hash sys_semop 3 39457 _001178_hash NULL
82016 +_001179_hash sys_sendto 6 20809 _001179_hash NULL
82017 +_001180_hash sys_setxattr 4 37880 _001180_hash NULL
82018 +_001181_hash t4_alloc_mem 1 32342 _001181_hash NULL
82019 +_001182_hash tcf_hash_create 4 54360 _001182_hash NULL
82020 +_001183_hash __team_options_register 3 63941 _001183_hash NULL
82021 +_001184_hash test_unaligned_bulk 3 52333 _001184_hash NULL
82022 +_001185_hash tifm_alloc_adapter 1 10903 _001185_hash NULL
82023 +_001186_hash timeout_write 3 50991 _001186_hash NULL
82024 +_001187_hash tipc_link_send_sections_fast 4 37920 _001187_hash NULL
82025 +_001188_hash tipc_subseq_alloc 1 5957 _001188_hash NULL
82026 +_001189_hash tm6000_read_write_usb 7 50774 _001189_hash NULL
82027 +_001190_hash tnode_alloc 1 49407 _001190_hash NULL
82028 +_001191_hash tomoyo_commit_ok 2 20167 _001191_hash NULL
82029 +_001192_hash tomoyo_scan_bprm 2-4 15642 _001192_hash NULL
82030 +_001194_hash tps65910_i2c_write 3 39531 _001194_hash NULL
82031 +_001195_hash ts_write 3 64336 _001195_hash NULL
82032 +_001196_hash ttusb2_msg 4 3100 _001196_hash NULL
82033 +_001197_hash tty_write 3 5494 _001197_hash NULL
82034 +_001198_hash ubi_dbg_check_all_ff 4 59810 _001198_hash NULL
82035 +_001199_hash ubi_dbg_check_write 5 48525 _001199_hash NULL
82036 +_001200_hash ubifs_setxattr 4 59650 _001370_hash NULL nohasharray
82037 +_001201_hash udf_sb_alloc_partition_maps 2 62313 _001201_hash NULL
82038 +_001202_hash udplite_getfrag 3-4 14479 _001202_hash NULL
82039 +_001204_hash ulong_write_file 3 26485 _001204_hash NULL
82040 +_001205_hash unix_dgram_sendmsg 4 45699 _001205_hash NULL
82041 +_001206_hash unix_stream_sendmsg 4 61455 _001206_hash NULL
82042 +_001207_hash unlink_queued 3-4 645 _001207_hash NULL
82043 +_001208_hash update_pmkid 4 2481 _001208_hash NULL
82044 +_001209_hash usb_alloc_coherent 2 65444 _001209_hash NULL
82045 +_001210_hash uvc_alloc_buffers 2 9656 _001210_hash NULL
82046 +_001211_hash uvc_alloc_entity 3 20836 _001211_hash NULL
82047 +_001212_hash v4l2_ctrl_new 7 38725 _001212_hash NULL
82048 +_001213_hash v4l2_event_subscribe 3 19510 _001213_hash NULL
82049 +_001214_hash vb2_read 3 42703 _001214_hash NULL
82050 +_001215_hash vb2_write 3 31948 _001215_hash NULL
82051 +_001216_hash vc_resize 2-3 3585 _001216_hash NULL
82052 +_001218_hash __vhost_add_used_n 3 26554 _001218_hash NULL
82053 +_001219_hash __videobuf_alloc_vb 1 27062 _001219_hash NULL
82054 +_001220_hash videobuf_dma_init_kernel 3 6963 _001220_hash NULL
82055 +_001221_hash virtqueue_add_buf 3-4 59470 _001221_hash NULL
82056 +_001223_hash vmalloc 1 15464 _001223_hash NULL
82057 +_001224_hash vmalloc_to_sg 2 58354 _001224_hash NULL
82058 +_001225_hash vol_cdev_write 3 40915 _001225_hash NULL
82059 +_001226_hash vxge_device_register 4 7752 _001226_hash NULL
82060 +_001227_hash __vxge_hw_channel_allocate 3 55462 _001227_hash NULL
82061 +_001228_hash vzalloc 1 47421 _001228_hash NULL
82062 +_001229_hash vzalloc_node 1 23424 _001229_hash NULL
82063 +_001230_hash wa_nep_queue 2 8858 _001230_hash NULL
82064 +_001231_hash __wa_xfer_setup_segs 2 56725 _001231_hash NULL
82065 +_001232_hash wiphy_new 2 2482 _001232_hash NULL
82066 +_001233_hash wpan_phy_alloc 1 48056 _001233_hash NULL
82067 +_001234_hash wusb_ccm_mac 7 32199 _001234_hash NULL
82068 +_001235_hash x25_sendmsg 4 12487 _001235_hash NULL
82069 +_001236_hash xfrm_hash_alloc 1 10997 _001236_hash NULL
82070 +_001237_hash _xfs_buf_get_pages 2 46811 _001237_hash NULL
82071 +_001238_hash xfs_da_buf_make 1 55845 _001238_hash NULL
82072 +_001239_hash xfs_da_grow_inode_int 3 21785 _001239_hash NULL
82073 +_001240_hash xfs_dir_cilookup_result 3 64288 _001240_hash NULL
82074 +_001241_hash xfs_iext_add_indirect_multi 3 32400 _001241_hash NULL
82075 +_001242_hash xfs_iext_inline_to_direct 2 12384 _001242_hash NULL
82076 +_001243_hash xfs_iroot_realloc 2 46826 _001243_hash NULL
82077 +_001244_hash xhci_alloc_stream_info 3 63902 _001244_hash NULL
82078 +_001245_hash xlog_recover_add_to_trans 4 62839 _001245_hash NULL
82079 +_001246_hash xprt_alloc 2 1475 _001246_hash NULL
82080 +_001247_hash xt_alloc_table_info 1 57903 _001247_hash NULL
82081 +_001248_hash _zd_iowrite32v_async_locked 3 39034 _001248_hash NULL
82082 +_001249_hash zd_usb_iowrite16v 3 49744 _001249_hash NULL
82083 +_001250_hash acpi_ds_build_internal_package_obj 3 58271 _001250_hash NULL
82084 +_001251_hash acpi_system_read_event 3 55362 _001251_hash NULL
82085 +_001252_hash acpi_ut_create_buffer_object 1 42030 _001252_hash NULL
82086 +_001253_hash acpi_ut_create_package_object 1 17594 _001253_hash NULL
82087 +_001254_hash acpi_ut_create_string_object 1 15360 _001254_hash NULL
82088 +_001255_hash ad7879_spi_multi_read 3 8218 _001255_hash NULL
82089 +_001256_hash add_child 4 45201 _001256_hash NULL
82090 +_001257_hash add_port 2 54941 _001257_hash NULL
82091 +_001258_hash adu_read 3 24177 _001258_hash NULL
82092 +_001259_hash afs_cell_create 2 27346 _001259_hash NULL
82093 +_001260_hash agp_generic_alloc_user 1 9470 _001260_hash NULL
82094 +_001261_hash alloc_agpphysmem_i8xx 1 39427 _001261_hash NULL
82095 +_001262_hash allocate_cnodes 1 5329 _001262_hash NULL
82096 +_001263_hash ___alloc_bootmem 1 11410 _001263_hash NULL
82097 +_001264_hash __alloc_bootmem_nopanic 1 65397 _001264_hash NULL
82098 +_001265_hash alloc_bulk_urbs_generic 5 12127 _001265_hash NULL
82099 +_001266_hash alloc_candev 1-2 7776 _001266_hash NULL
82100 +_001268_hash ____alloc_ei_netdev 1 51475 _001268_hash NULL
82101 +_001269_hash alloc_etherdev_mqs 1 36450 _001269_hash NULL
82102 +_001270_hash alloc_extent_buffer 3 52824 _001270_hash NULL
82103 +_001271_hash alloc_fcdev 1 18780 _001271_hash NULL
82104 +_001272_hash alloc_fddidev 1 15382 _001272_hash NULL
82105 +_001273_hash alloc_hippi_dev 1 51320 _001273_hash NULL
82106 +_001274_hash alloc_irdadev 1 19140 _001274_hash NULL
82107 +_001275_hash alloc_ltalkdev 1 38071 _001275_hash NULL
82108 +_001276_hash alloc_one_pg_vec_page 1 10747 _001276_hash NULL
82109 +_001277_hash alloc_orinocodev 1 21371 _001277_hash NULL
82110 +_001279_hash alloc_trdev 1 16399 _001279_hash NULL
82111 +_001280_hash async_setkey 3 35521 _001280_hash NULL
82112 +_001281_hash ata_host_alloc_pinfo 3 17325 _001281_hash NULL
82113 +_001284_hash ath6kl_connect_event 7-9-8 14267 _001284_hash NULL
82114 +_001285_hash ath6kl_fwlog_block_read 3 49836 _001285_hash NULL
82115 +_001286_hash ath6kl_fwlog_read 3 32101 _001286_hash NULL
82116 +_001287_hash ath_rx_init 2 43564 _001287_hash NULL
82117 +_001288_hash ath_tx_init 2 60515 _001288_hash NULL
82118 +_001289_hash atm_get_addr 3 31221 _001289_hash NULL
82119 +_001290_hash av7110_ipack_init 2 46655 _001290_hash NULL
82120 +_001291_hash bdx_rxdb_create 1 46525 _001291_hash NULL
82121 +_001292_hash bdx_tx_db_init 2 41719 _001292_hash NULL
82122 +_001293_hash bio_map_kern 3 64751 _001293_hash NULL
82123 +_001294_hash bits_to_user 3 47733 _001294_hash NULL
82124 +_001295_hash __blk_queue_init_tags 2 9778 _001295_hash NULL
82125 +_001296_hash blk_queue_resize_tags 2 28670 _001296_hash NULL
82126 +_001297_hash blk_rq_map_user_iov 5 16772 _001297_hash NULL
82127 +_001298_hash bm_init 2 13529 _001298_hash NULL
82128 +_001299_hash brcmf_alloc_wdev 1 60347 _001299_hash NULL
82129 +_001300_hash btrfs_insert_dir_item 4 59304 _001300_hash NULL
82130 +_001301_hash btrfs_map_block 3 64379 _001301_hash NULL
82131 +_001302_hash c4_add_card 3 54968 _001302_hash NULL
82132 +_001303_hash cache_read 3 24790 _001303_hash NULL
82133 +_001304_hash cache_write 3 13589 _001304_hash NULL
82134 +_001305_hash calc_hmac 3 32010 _001305_hash NULL
82135 +_001306_hash ccid_getsockopt_builtin_ccids 2 53634 _001306_hash NULL
82136 +_001307_hash ceph_copy_page_vector_to_user 4 31270 _001307_hash NULL
82137 +_001308_hash ceph_read_dir 3 17005 _001308_hash NULL
82138 +_001309_hash cfg80211_roamed 5-7 32632 _001309_hash NULL
82139 +_001311_hash ci_ll_init 3 12930 _001311_hash NULL
82140 +_001312_hash coda_psdev_read 3 35029 _001312_hash NULL
82141 +_001313_hash construct_key_and_link 4 8321 _001313_hash NULL
82142 +_001314_hash copy_counters_to_user 5 17027 _001824_hash NULL nohasharray
82143 +_001315_hash copy_entries_to_user 1 52367 _001315_hash NULL
82144 +_001316_hash copy_from_buf 4 27308 _001316_hash NULL
82145 +_001317_hash copy_oldmem_page 3 26164 _001317_hash NULL
82146 +_001318_hash copy_to_user_fromio 3 57432 _001318_hash NULL
82147 +_001319_hash cryptd_hash_setkey 3 42781 _001319_hash NULL
82148 +_001320_hash crypto_authenc_esn_setkey 3 6985 _001320_hash NULL
82149 +_001321_hash crypto_authenc_setkey 3 80 _001321_hash NULL
82150 +_001322_hash cx18_copy_buf_to_user 4 22735 _001322_hash NULL
82151 +_001324_hash cxgbi_ddp_reserve 4 30091 _001324_hash NULL
82152 +_001325_hash datablob_hmac_append 3 40038 _001325_hash NULL
82153 +_001326_hash datablob_hmac_verify 4 24786 _001326_hash NULL
82154 +_001327_hash dataflash_read_fact_otp 3-2 33204 _001327_hash NULL
82155 +_001328_hash dataflash_read_user_otp 3-2 14536 _001328_hash &_000201_hash
82156 +_001329_hash dccp_feat_register_sp 5 17914 _001329_hash NULL
82157 +_001330_hash ddb_input_read 3 9743 _001330_hash NULL
82158 +_001331_hash dev_read 3 56369 _001331_hash NULL
82159 +_001332_hash diva_os_copy_to_user 4 48508 _001332_hash NULL
82160 +_001333_hash diva_os_malloc 2 16406 _001333_hash NULL
82161 +_001334_hash dlm_dir_lookup 4 56662 _001334_hash NULL
82162 +_001335_hash dm_vcalloc 1-2 16814 _001335_hash NULL
82163 +_001337_hash do_proc_readlink 3 14096 _001337_hash NULL
82164 +_001338_hash do_readlink 2 43518 _001338_hash NULL
82165 +_001339_hash __do_replace 5 37227 _001339_hash NULL
82166 +_001340_hash do_sigpending 2 9766 _001340_hash NULL
82167 +_001341_hash drbd_setsockopt 5 16280 _001341_hash &_000371_hash
82168 +_001342_hash dsp_buffer_alloc 2 11684 _001342_hash NULL
82169 +_001343_hash dump_midi 3 51040 _001343_hash NULL
82170 +_001344_hash dvb_dmxdev_set_buffer_size 2 55643 _001344_hash NULL
82171 +_001345_hash dvb_dvr_set_buffer_size 2 9840 _001345_hash NULL
82172 +_001346_hash dvb_ringbuffer_pkt_read_user 3-5 4303 _001346_hash NULL
82173 +_001348_hash dvb_ringbuffer_read_user 3 56702 _001348_hash NULL
82174 +_001349_hash ecryptfs_filldir 3 6622 _001349_hash NULL
82175 +_001350_hash ecryptfs_readlink 3 40775 _001350_hash NULL
82176 +_001351_hash ecryptfs_send_message 2 18322 _001351_hash NULL
82177 +_001352_hash em28xx_init_isoc 4 62883 _001352_hash &_000721_hash
82178 +_001353_hash et61x251_read 3 25420 _001353_hash NULL
82179 +_001354_hash ext4_add_new_descs 3 19509 _001354_hash NULL
82180 +_001355_hash fat_ioctl_filldir 3 36621 _001355_hash NULL
82181 +_001356_hash fd_copyout 3 59323 _001356_hash NULL
82182 +_001357_hash f_hidg_read 3 6238 _001357_hash NULL
82183 +_001358_hash filldir 3 55137 _001358_hash NULL
82184 +_001359_hash filldir64 3 46469 _001359_hash NULL
82185 +_001360_hash fops_read 3 40672 _001360_hash NULL
82186 +_001361_hash from_buffer 3 18625 _001361_hash NULL
82187 +_001362_hash fsm_init 2 16134 _001362_hash NULL
82188 +_001363_hash get_subdir 3 62581 _001363_hash NULL
82189 +_001364_hash gspca_dev_probe 4 2570 _001364_hash NULL
82190 +_001365_hash handle_received_packet 3 22457 _001365_hash NULL
82191 +_001366_hash hash_setkey 3 48310 _001366_hash NULL
82192 +_001367_hash hdlcdrv_register 2 6792 _001367_hash NULL
82193 +_001368_hash hdpvr_read 3 9273 _001368_hash NULL
82194 +_001369_hash hid_input_report 4 32458 _001369_hash NULL
82195 +_001370_hash hidraw_read 3 59650 _001370_hash &_001200_hash
82196 +_001371_hash HiSax_readstatus 2 15752 _001371_hash NULL
82197 +_001373_hash __hwahc_op_set_gtk 4 42038 _001373_hash NULL
82198 +_001374_hash __hwahc_op_set_ptk 5 36510 _001374_hash NULL
82199 +_001375_hash ib_copy_to_udata 3 27525 _001375_hash NULL
82200 +_001376_hash idetape_chrdev_read 3 2097 _001376_hash NULL
82201 +_001377_hash ieee80211_alloc_hw 1 43829 _001377_hash NULL
82202 +_001378_hash ieee80211_bss_info_update 4 13991 _001378_hash NULL
82203 +_001379_hash ilo_read 3 32531 _001379_hash NULL
82204 +_001380_hash init_map_ipmac 3-4 63896 _001380_hash NULL
82205 +_001382_hash init_tid_tabs 2-4-3 13252 _001382_hash NULL
82206 +_001385_hash iowarrior_read 3 53483 _001385_hash NULL
82207 +_001386_hash ipv6_getsockopt_sticky 5 56711 _001386_hash NULL
82208 +_001387_hash ipwireless_send_packet 4 8328 _001387_hash NULL
82209 +_001388_hash ipx_sendmsg 4 1362 _001388_hash NULL
82210 +_001389_hash iscsi_conn_setup 2 35159 _001389_hash NULL
82211 +_001390_hash iscsi_create_session 3 51647 _001390_hash NULL
82212 +_001391_hash iscsi_host_alloc 2 36671 _001391_hash NULL
82213 +_001392_hash iscsi_session_setup 4-5 196 _001392_hash NULL
82214 +_001394_hash iscsit_find_cmd_from_itt_or_dump 3 17194 _001701_hash NULL nohasharray
82215 +_001395_hash isdn_ppp_read 4 50356 _001395_hash NULL
82216 +_001396_hash isku_sysfs_read 6 58806 _001396_hash NULL
82217 +_001397_hash isku_sysfs_write 6 49767 _001397_hash NULL
82218 +_001398_hash iso_alloc_urb 4-5 45206 _001398_hash NULL
82219 +_001400_hash ivtv_copy_buf_to_user 4 6159 _001400_hash NULL
82220 +_001401_hash iwm_rx_handle 3 24899 _001401_hash NULL
82221 +_001402_hash iwm_wdev_alloc 1 38415 _001402_hash NULL
82222 +_001403_hash jbd2_alloc 1 41359 _001403_hash NULL
82223 +_001404_hash jffs2_do_link 6 42048 _001404_hash NULL
82224 +_001405_hash jffs2_do_unlink 4 62020 _001405_hash NULL
82225 +_001406_hash jffs2_security_setxattr 4 62107 _001406_hash NULL
82226 +_001407_hash jffs2_trusted_setxattr 4 17048 _001407_hash NULL
82227 +_001408_hash jffs2_user_setxattr 4 10182 _001408_hash NULL
82228 +_001409_hash kernel_setsockopt 5 35913 _001409_hash NULL
82229 +_001410_hash keyctl_describe_key 3 36853 _001410_hash NULL
82230 +_001411_hash keyctl_get_security 3 64418 _001411_hash &_001132_hash
82231 +_001412_hash keyring_read 3 13438 _001412_hash NULL
82232 +_001413_hash kfifo_copy_to_user 3 20646 _001413_hash NULL
82233 +_001414_hash kmem_zalloc_large 1 56128 _001414_hash NULL
82234 +_001415_hash kmp_init 2 41373 _001415_hash NULL
82235 +_001416_hash koneplus_sysfs_write 6 35993 _001416_hash NULL
82236 +_001417_hash kvm_clear_guest_page 4 2308 _001417_hash NULL
82237 +_001418_hash kvm_read_nested_guest_page 5 13337 _001418_hash NULL
82238 +_001419_hash l2cap_create_basic_pdu 3 24869 _001419_hash &_001034_hash
82239 +_001420_hash l2cap_create_connless_pdu 3 37327 _001420_hash &_000966_hash
82240 +_001421_hash l2cap_create_iframe_pdu 3 51801 _001421_hash NULL
82241 +_001422_hash __lgwrite 4 57669 _001422_hash NULL
82242 +_001423_hash libfc_host_alloc 2 7917 _001423_hash NULL
82243 +_001424_hash llcp_sock_sendmsg 4 1092 _001424_hash NULL
82244 +_001425_hash macvtap_get_user 4 28185 _001425_hash NULL
82245 +_001426_hash mcam_v4l_read 3 36513 _001426_hash NULL
82246 +_001427_hash mce_async_out 3 58056 _001427_hash NULL
82247 +_001428_hash mce_flush_rx_buffer 2 14976 _001428_hash NULL
82248 +_001429_hash mdc800_device_read 3 22896 _001429_hash NULL
82249 +_001430_hash memcpy_toiovec 3 54166 _001430_hash &_000867_hash
82250 +_001431_hash memcpy_toiovecend 3-4 19736 _001431_hash NULL
82251 +_001433_hash mgt_set_varlen 4 60916 _001433_hash NULL
82252 +_001434_hash mlx4_en_create_rx_ring 3 62498 _001434_hash NULL
82253 +_001435_hash mlx4_en_create_tx_ring 4 48501 _001435_hash NULL
82254 +_001436_hash mon_bin_get_event 4 52863 _001436_hash NULL
82255 +_001437_hash mousedev_read 3 47123 _001437_hash NULL
82256 +_001438_hash move_addr_to_user 2 2868 _001438_hash NULL
82257 +_001439_hash mpihelp_mul 5-3 27805 _001439_hash NULL
82258 +_001441_hash mpi_lshift_limbs 2 9337 _001441_hash NULL
82259 +_001442_hash msnd_fifo_alloc 2 23179 _001442_hash NULL
82260 +_001443_hash mtdswap_init 2 55719 _001443_hash NULL
82261 +_001444_hash neigh_hash_grow 2 17283 _001444_hash NULL
82262 +_001445_hash nfs4_realloc_slot_table 2 22859 _001445_hash NULL
82263 +_001446_hash nfs_idmap_get_key 2 39616 _001446_hash NULL
82264 +_001447_hash nsm_get_handle 4 52089 _001447_hash NULL
82265 +_001448_hash ntfs_malloc_nofs 1 49572 _001448_hash NULL
82266 +_001449_hash ntfs_malloc_nofs_nofail 1 63631 _001449_hash NULL
82267 +_001450_hash nvme_create_queue 3 170 _001450_hash NULL
82268 +_001451_hash ocfs2_control_write 3 54737 _001451_hash NULL
82269 +_001452_hash orinoco_add_extscan_result 3 18207 _001452_hash NULL
82270 +_001454_hash override_release 2 52032 _001454_hash NULL
82271 +_001455_hash packet_snd 3 13634 _001455_hash NULL
82272 +_001456_hash pcbit_stat 2 27364 _001456_hash NULL
82273 +_001457_hash pcpu_extend_area_map 2 12589 _001457_hash NULL
82274 +_001458_hash pg_read 3 17276 _001458_hash NULL
82275 +_001459_hash picolcd_debug_eeprom_read 3 14549 _001459_hash NULL
82276 +_001460_hash pkt_alloc_packet_data 1 37928 _001460_hash NULL
82277 +_001461_hash pmcraid_build_passthrough_ioadls 2 62034 _001461_hash NULL
82278 +_001462_hash pms_capture 4 27142 _001462_hash NULL
82279 +_001463_hash posix_clock_register 2 5662 _001463_hash NULL
82280 +_001464_hash printer_read 3 54851 _001464_hash NULL
82281 +_001465_hash __proc_file_read 3 54978 _001465_hash NULL
82282 +_001466_hash pt_read 3 49136 _001466_hash NULL
82283 +_001467_hash put_cmsg 4 36589 _001467_hash NULL
82284 +_001468_hash pvr2_ioread_read 3 10720 _001505_hash NULL nohasharray
82285 +_001469_hash pwc_video_read 3 51735 _001469_hash NULL
82286 +_001470_hash px_raw_event 4 49371 _001470_hash NULL
82287 +_001471_hash qcam_read 3 13977 _001471_hash NULL
82288 +_001472_hash rawv6_sendmsg 4 20080 _001472_hash NULL
82289 +_001473_hash rds_sendmsg 4 40976 _001473_hash NULL
82290 +_001474_hash read_flush 3 43851 _001474_hash NULL
82291 +_001475_hash read_profile 3 27859 _001475_hash NULL
82292 +_001476_hash read_vmcore 3 26501 _001476_hash NULL
82293 +_001477_hash redirected_tty_write 3 65297 _001477_hash NULL
82294 +_001478_hash __register_chrdev 2-3 54223 _001478_hash NULL
82295 +_001480_hash regmap_raw_write 4 53803 _001480_hash NULL
82296 +_001481_hash reiserfs_allocate_list_bitmaps 3 21732 _001481_hash NULL
82297 +_001482_hash reiserfs_resize 2 34377 _001482_hash NULL
82298 +_001483_hash request_key_auth_read 3 24109 _001483_hash NULL
82299 +_001484_hash rfkill_fop_read 3 54711 _001484_hash NULL
82300 +_001485_hash rng_dev_read 3 41581 _001485_hash NULL
82301 +_001486_hash roccat_read 3 41093 _001486_hash NULL
82302 +_001487_hash sco_sock_sendmsg 4 62542 _001487_hash NULL
82303 +_001488_hash scsi_register 2 49094 _001488_hash NULL
82304 +_001489_hash sctp_getsockopt_events 2 3607 _001489_hash NULL
82305 +_001490_hash sctp_getsockopt_maxburst 2 42941 _001490_hash NULL
82306 +_001491_hash sctp_getsockopt_maxseg 2 10737 _001491_hash NULL
82307 +_001492_hash sctpprobe_read 3 17741 _001492_hash NULL
82308 +_001493_hash sdhci_alloc_host 2 7509 _001493_hash NULL
82309 +_001494_hash selinux_inode_post_setxattr 4 26037 _001494_hash NULL
82310 +_001495_hash selinux_inode_setsecurity 4 18148 _001495_hash NULL
82311 +_001496_hash selinux_inode_setxattr 4 10708 _001496_hash NULL
82312 +_001497_hash selinux_secctx_to_secid 2 63744 _001497_hash NULL
82313 +_001498_hash selinux_setprocattr 4 55611 _001498_hash NULL
82314 +_001499_hash sel_write_context 3 25726 _002397_hash NULL nohasharray
82315 +_001500_hash seq_copy_in_user 3 18543 _001500_hash NULL
82316 +_001501_hash seq_open_net 4 8968 _001594_hash NULL nohasharray
82317 +_001502_hash seq_open_private 3 61589 _001502_hash NULL
82318 +_001503_hash set_arg 3 42824 _001503_hash NULL
82319 +_001504_hash sg_read 3 25799 _001504_hash NULL
82320 +_001505_hash shash_async_setkey 3 10720 _001505_hash &_001468_hash
82321 +_001506_hash shash_compat_setkey 3 12267 _001506_hash NULL
82322 +_001507_hash shmem_setxattr 4 55867 _001507_hash NULL
82323 +_001508_hash simple_read_from_buffer 2-5 55957 _001508_hash NULL
82324 +_001511_hash sm_checker_extend 2 23615 _001511_hash NULL
82325 +_001512_hash sn9c102_read 3 29305 _001512_hash NULL
82326 +_001513_hash snd_es1938_capture_copy 5 25930 _001513_hash NULL
82327 +_001514_hash snd_gus_dram_peek 4 9062 _001514_hash NULL
82328 +_001515_hash snd_hdsp_capture_copy 5 4011 _001515_hash NULL
82329 +_001516_hash snd_korg1212_copy_to 6 92 _001516_hash NULL
82330 +_001517_hash snd_opl4_mem_proc_read 5 63774 _001517_hash NULL
82331 +_001518_hash snd_pcm_alloc_vmalloc_buffer 2 44595 _001518_hash NULL
82332 +_001519_hash snd_pcm_oss_read1 3 63771 _001519_hash NULL
82333 +_001520_hash snd_rawmidi_kernel_read1 4 36740 _001520_hash NULL
82334 +_001521_hash snd_rme9652_capture_copy 5 10287 _001521_hash NULL
82335 +_001522_hash srp_target_alloc 3 37288 _001522_hash NULL
82336 +_001523_hash stk_allocate_buffers 2 16291 _001523_hash NULL
82337 +_001524_hash store_ifalias 4 35088 _001524_hash NULL
82338 +_001525_hash store_msg 3 56417 _001525_hash NULL
82339 +_001526_hash str_to_user 2 11411 _001526_hash NULL
82340 +_001527_hash subbuf_read_actor 3 2071 _001527_hash NULL
82341 +_001528_hash sys_fgetxattr 4 25166 _001528_hash NULL
82342 +_001529_hash sys_gethostname 2 49698 _001529_hash NULL
82343 +_001530_hash sys_getxattr 4 37418 _001530_hash NULL
82344 +_001531_hash sys_kexec_load 2 14222 _001531_hash NULL
82345 +_001532_hash sys_msgsnd 3 44537 _001532_hash &_000129_hash
82346 +_001533_hash sys_process_vm_readv 3-5 19090 _001533_hash NULL
82347 +_001535_hash sys_process_vm_writev 3-5 4928 _001535_hash NULL
82348 +_001537_hash sys_sched_getaffinity 2 60033 _001537_hash NULL
82349 +_001538_hash sys_setsockopt 5 35320 _001538_hash NULL
82350 +_001539_hash t3_init_l2t 1 8261 _001539_hash NULL
82351 +_001540_hash team_options_register 3 20091 _001540_hash NULL
82352 +_001541_hash tipc_send2name 6 16809 _001541_hash NULL
82353 +_001542_hash tipc_send2port 5 63935 _001542_hash NULL
82354 +_001543_hash tipc_send 4 51238 _001543_hash NULL
82355 +_001544_hash tm6000_i2c_recv_regs16 5 2949 _001544_hash NULL
82356 +_001545_hash tm6000_i2c_recv_regs 5 46215 _001545_hash NULL
82357 +_001546_hash tm6000_i2c_send_regs 5 20250 _001546_hash NULL
82358 +_001547_hash tnode_new 3 44757 _001547_hash NULL
82359 +_001548_hash tomoyo_read_self 3 33539 _001548_hash NULL
82360 +_001549_hash tomoyo_update_domain 2 5498 _001549_hash NULL
82361 +_001550_hash tomoyo_update_policy 2 40458 _001550_hash NULL
82362 +_001551_hash tpm_read 3 50344 _001551_hash NULL
82363 +_001552_hash TSS_rawhmac 3 17486 _001552_hash NULL
82364 +_001553_hash tt3650_ci_msg 4 57219 _001553_hash NULL
82365 +_001554_hash tun_get_user 3 33178 _001554_hash NULL
82366 +_001555_hash ubi_dbg_dump_flash 4 3870 _001555_hash NULL
82367 +_001556_hash ubi_io_write 4-5 15870 _001556_hash &_000954_hash
82368 +_001558_hash uio_read 3 49300 _001558_hash NULL
82369 +_001559_hash unix_seqpacket_sendmsg 4 27893 _001559_hash NULL
82370 +_001560_hash unlink1 3 63059 _001560_hash NULL
82371 +_001562_hash usb_allocate_stream_buffers 3 8964 _001562_hash NULL
82372 +_001563_hash usbdev_read 3 45114 _001563_hash NULL
82373 +_001564_hash usblp_read 3 57342 _001564_hash NULL
82374 +_001565_hash usbtmc_read 3 32377 _001565_hash NULL
82375 +_001566_hash usbvision_v4l2_read 3 34386 _001566_hash NULL
82376 +_001567_hash _usb_writeN_sync 4 31682 _001567_hash NULL
82377 +_001568_hash user_read 3 51881 _001568_hash NULL
82378 +_001569_hash v4l_stk_read 3 39672 _001569_hash NULL
82379 +_001570_hash vcs_read 3 8017 _001570_hash NULL
82380 +_001571_hash vdma_mem_alloc 1 6171 _001571_hash NULL
82381 +_001572_hash venus_create 4 20555 _001572_hash NULL
82382 +_001573_hash venus_link 5 32165 _001573_hash NULL
82383 +_001574_hash venus_lookup 4 8121 _001574_hash NULL
82384 +_001575_hash venus_mkdir 4 8967 _001575_hash NULL
82385 +_001576_hash venus_remove 4 59781 _001576_hash NULL
82386 +_001577_hash venus_rename 4-5 17707 _001577_hash NULL
82387 +_001579_hash venus_rmdir 4 45564 _001579_hash NULL
82388 +_001580_hash venus_symlink 4-6 23570 _001580_hash NULL
82389 +_001582_hash vfs_readlink 3 54368 _001582_hash NULL
82390 +_001583_hash vfs_readv 3 38011 _001583_hash NULL
82391 +_001584_hash vfs_writev 3 25278 _001584_hash NULL
82392 +_001585_hash vga_arb_read 3 4886 _001585_hash NULL
82393 +_001586_hash vhci_put_user 4 12604 _001586_hash NULL
82394 +_001587_hash vhost_add_used_n 3 10760 _001587_hash NULL
82395 +_001588_hash __videobuf_copy_to_user 4 15423 _001588_hash NULL
82396 +_001589_hash videobuf_pages_to_sg 2 3708 _001589_hash NULL
82397 +_001590_hash videobuf_vmalloc_to_sg 2 4548 _001590_hash NULL
82398 +_001591_hash virtnet_send_command 5-6 61993 _001591_hash NULL
82399 +_001593_hash vmbus_establish_gpadl 3 4495 _001593_hash NULL
82400 +_001594_hash vol_cdev_read 3 8968 _001594_hash &_001501_hash
82401 +_001595_hash w9966_v4l_read 3 31148 _001595_hash NULL
82402 +_001596_hash wdm_read 3 6549 _001596_hash NULL
82403 +_001597_hash wusb_prf 7 54261 _001597_hash &_000063_hash
82404 +_001598_hash xdi_copy_to_user 4 48900 _001598_hash NULL
82405 +_001599_hash xfs_buf_get_uncached 2 51477 _001599_hash NULL
82406 +_001600_hash xfs_efd_init 3 5463 _001600_hash NULL
82407 +_001601_hash xfs_efi_init 2 5476 _001601_hash NULL
82408 +_001602_hash xfs_iext_realloc_direct 2 20521 _001602_hash NULL
82409 +_001603_hash xfs_iext_realloc_indirect 2 59211 _001603_hash NULL
82410 +_001604_hash xfs_inumbers_fmt 3 12817 _001604_hash NULL
82411 +_001605_hash xlog_recover_add_to_cont_trans 4 44102 _001605_hash NULL
82412 +_001606_hash xz_dec_lzma2_create 2 36353 _001606_hash NULL
82413 +_001607_hash _zd_iowrite32v_locked 3 44725 _001607_hash NULL
82414 +_001608_hash aat2870_reg_read_file 3 12221 _001608_hash NULL
82415 +_001609_hash add_sctp_bind_addr 3 12269 _001609_hash NULL
82416 +_001610_hash aes_decrypt_fail_read 3 54815 _001610_hash NULL
82417 +_001611_hash aes_decrypt_interrupt_read 3 19910 _001611_hash NULL
82418 +_001612_hash aes_decrypt_packets_read 3 10155 _001612_hash NULL
82419 +_001613_hash aes_encrypt_fail_read 3 32562 _001613_hash NULL
82420 +_001614_hash aes_encrypt_interrupt_read 3 39919 _001614_hash NULL
82421 +_001615_hash aes_encrypt_packets_read 3 48666 _001615_hash NULL
82422 +_001616_hash afs_cell_lookup 2 8482 _001616_hash NULL
82423 +_001617_hash agp_allocate_memory 2 58761 _001617_hash NULL
82424 +_001618_hash __alloc_bootmem 1 31498 _001618_hash NULL
82425 +_001619_hash __alloc_bootmem_low 1 43423 _001619_hash NULL
82426 +_001620_hash __alloc_bootmem_node_nopanic 2 6432 _001620_hash NULL
82427 +_001621_hash alloc_cc770dev 1 48186 _001621_hash NULL
82428 +_001622_hash __alloc_ei_netdev 1 29338 _001622_hash NULL
82429 +_001623_hash __alloc_eip_netdev 1 51549 _001623_hash NULL
82430 +_001624_hash alloc_libipw 1 22708 _001624_hash NULL
82431 +_001625_hash alloc_pg_vec 2 8533 _001625_hash NULL
82432 +_001626_hash alloc_sja1000dev 1 17868 _001626_hash NULL
82433 +_001627_hash alloc_targets 2 8074 _001627_hash NULL
82434 +_001630_hash ath6kl_disconnect_timeout_read 3 3650 _001630_hash NULL
82435 +_001631_hash ath6kl_endpoint_stats_read 3 41554 _001631_hash NULL
82436 +_001632_hash ath6kl_fwlog_mask_read 3 2050 _001632_hash NULL
82437 +_001633_hash ath6kl_keepalive_read 3 44303 _001633_hash NULL
82438 +_001634_hash ath6kl_listen_int_read 3 10355 _001634_hash NULL
82439 +_001635_hash ath6kl_lrssi_roam_read 3 61022 _001635_hash NULL
82440 +_001636_hash ath6kl_regdump_read 3 14393 _001636_hash NULL
82441 +_001637_hash ath6kl_regread_read 3 25884 _001637_hash NULL
82442 +_001638_hash ath6kl_regwrite_read 3 48747 _001638_hash NULL
82443 +_001639_hash ath6kl_roam_table_read 3 26166 _001639_hash NULL
82444 +_001640_hash ath9k_debugfs_read_buf 3 25316 _001640_hash NULL
82445 +_001641_hash atk_debugfs_ggrp_read 3 29522 _001641_hash NULL
82446 +_001642_hash b43_debugfs_read 3 24425 _001642_hash NULL
82447 +_001643_hash b43legacy_debugfs_read 3 2473 _001643_hash NULL
82448 +_001644_hash bcm_recvmsg 4 43992 _001644_hash NULL
82449 +_001645_hash bfad_debugfs_read 3 13119 _001645_hash NULL
82450 +_001646_hash bfad_debugfs_read_regrd 3 57830 _001646_hash NULL
82451 +_001647_hash blk_init_tags 1 30592 _001647_hash NULL
82452 +_001648_hash blk_queue_init_tags 2 44355 _001648_hash NULL
82453 +_001649_hash blk_rq_map_kern 4 47004 _001649_hash NULL
82454 +_001650_hash bm_entry_read 3 10976 _001650_hash NULL
82455 +_001651_hash bm_status_read 3 19583 _001651_hash NULL
82456 +_001652_hash bnad_debugfs_read 3 50665 _001652_hash NULL
82457 +_001653_hash bnad_debugfs_read_regrd 3 51308 _001653_hash NULL
82458 +_001654_hash btmrvl_curpsmode_read 3 46939 _001654_hash NULL
82459 +_001655_hash btmrvl_gpiogap_read 3 4718 _001655_hash NULL
82460 +_001656_hash btmrvl_hscfgcmd_read 3 56303 _001656_hash NULL
82461 +_001657_hash btmrvl_hscmd_read 3 1614 _001657_hash NULL
82462 +_001658_hash btmrvl_hsmode_read 3 1647 _001658_hash NULL
82463 +_001659_hash btmrvl_hsstate_read 3 920 _001659_hash NULL
82464 +_001660_hash btmrvl_pscmd_read 3 24308 _001660_hash NULL
82465 +_001661_hash btmrvl_psmode_read 3 22395 _001661_hash NULL
82466 +_001662_hash btmrvl_psstate_read 3 50683 _001662_hash NULL
82467 +_001663_hash btmrvl_txdnldready_read 3 413 _001663_hash NULL
82468 +_001664_hash btrfs_add_link 5 9973 _001664_hash NULL
82469 +_001665_hash btrfs_discard_extent 2 38547 _001665_hash NULL
82470 +_001666_hash btrfs_find_create_tree_block 3 55812 _001666_hash NULL
82471 +_001667_hash btrfsic_map_block 2 56751 _001667_hash NULL
82472 +_001668_hash caif_stream_recvmsg 4 13173 _001668_hash NULL
82473 +_001669_hash carl9170_alloc 1 27 _001669_hash NULL
82474 +_001670_hash carl9170_debugfs_read 3 47738 _001670_hash NULL
82475 +_001671_hash cgroup_read_s64 5 19570 _001671_hash NULL
82476 +_001672_hash cgroup_read_u64 5 45532 _001672_hash NULL
82477 +_001673_hash channel_type_read 3 47308 _001673_hash NULL
82478 +_001674_hash codec_list_read_file 3 24910 _001674_hash NULL
82479 +_001675_hash configfs_read_file 3 1683 _001675_hash NULL
82480 +_001676_hash cpuset_common_file_read 5 8800 _001676_hash NULL
82481 +_001677_hash create_subvol 4 2347 _001677_hash NULL
82482 +_001678_hash cx18_copy_mdl_to_user 4 45549 _001678_hash NULL
82483 +_001679_hash dai_list_read_file 3 25421 _001679_hash NULL
82484 +_001680_hash dapm_bias_read_file 3 64715 _001680_hash NULL
82485 +_001681_hash dapm_widget_power_read_file 3 59950 _001754_hash NULL nohasharray
82486 +_001684_hash dbgfs_frame 3 45917 _001684_hash NULL
82487 +_001685_hash dbgfs_state 3 38894 _001685_hash NULL
82488 +_001686_hash debugfs_read 3 62535 _001686_hash NULL
82489 +_001687_hash debug_output 3 18575 _001687_hash NULL
82490 +_001688_hash debug_read 3 19322 _001688_hash NULL
82491 +_001689_hash dfs_file_read 3 18116 _001689_hash NULL
82492 +_001690_hash dma_memcpy_pg_to_iovec 6 1725 _001690_hash NULL
82493 +_001691_hash dma_memcpy_to_iovec 5 12173 _001691_hash NULL
82494 +_001692_hash dma_rx_errors_read 3 52045 _001692_hash NULL
82495 +_001693_hash dma_rx_requested_read 3 65354 _001693_hash NULL
82496 +_001694_hash dma_show_regs 3 35266 _001694_hash NULL
82497 +_001695_hash dma_tx_errors_read 3 46060 _001695_hash NULL
82498 +_001696_hash dma_tx_requested_read 3 16110 _001775_hash NULL nohasharray
82499 +_001697_hash dm_exception_table_init 2 39645 _001697_hash &_001103_hash
82500 +_001698_hash dn_recvmsg 4 17213 _001698_hash NULL
82501 +_001699_hash dns_resolver_read 3 54658 _001699_hash NULL
82502 +_001700_hash do_msgrcv 4 5590 _001700_hash NULL
82503 +_001701_hash driver_state_read 3 17194 _001701_hash &_001394_hash
82504 +_001702_hash dvb_demux_do_ioctl 3 34871 _001702_hash NULL
82505 +_001703_hash dvb_dmxdev_buffer_read 4 20682 _001703_hash NULL
82506 +_001704_hash dvb_dvr_do_ioctl 3 43355 _001704_hash NULL
82507 +_001705_hash econet_recvmsg 4 40978 _001705_hash NULL
82508 +_001706_hash event_calibration_read 3 21083 _001706_hash NULL
82509 +_001707_hash event_heart_beat_read 3 48961 _001707_hash NULL
82510 +_001708_hash event_oom_late_read 3 61175 _001708_hash &_001014_hash
82511 +_001709_hash event_phy_transmit_error_read 3 10471 _001709_hash NULL
82512 +_001710_hash event_rx_mem_empty_read 3 40363 _001710_hash NULL
82513 +_001711_hash event_rx_mismatch_read 3 38518 _001711_hash NULL
82514 +_001712_hash event_rx_pool_read 3 25792 _001712_hash NULL
82515 +_001713_hash event_tx_stuck_read 3 19305 _001713_hash NULL
82516 +_001714_hash excessive_retries_read 3 60425 _001714_hash NULL
82517 +_001715_hash fallback_on_nodma_alloc 2 35332 _001715_hash NULL
82518 +_001716_hash filter_read 3 61692 _001716_hash NULL
82519 +_001717_hash format_devstat_counter 3 32550 _001717_hash NULL
82520 +_001718_hash fragmentation_threshold_read 3 61718 _001718_hash NULL
82521 +_001719_hash fuse_conn_limit_read 3 20084 _001719_hash NULL
82522 +_001720_hash fuse_conn_waiting_read 3 49762 _001720_hash NULL
82523 +_001721_hash generic_readlink 3 32654 _001721_hash NULL
82524 +_001722_hash gpio_power_read 3 36059 _001722_hash NULL
82525 +_001723_hash hash_recvmsg 4 50924 _001723_hash NULL
82526 +_001724_hash ht40allow_map_read 3 55209 _001724_hash NULL
82527 +_001725_hash hwflags_read 3 52318 _001725_hash NULL
82528 +_001726_hash hysdn_conf_read 3 42324 _001726_hash NULL
82529 +_001727_hash i2400m_rx_stats_read 3 57706 _001727_hash NULL
82530 +_001728_hash i2400m_tx_stats_read 3 28527 _001728_hash NULL
82531 +_001729_hash idmouse_read 3 63374 _001729_hash NULL
82532 +_001730_hash ieee80211_if_read 3 6785 _001730_hash NULL
82533 +_001731_hash ieee80211_rx_bss_info 3 61630 _001731_hash NULL
82534 +_001732_hash ikconfig_read_current 3 1658 _001732_hash NULL
82535 +_001733_hash il3945_sta_dbgfs_stats_table_read 3 48802 _001733_hash NULL
82536 +_001734_hash il3945_ucode_general_stats_read 3 46111 _001734_hash NULL
82537 +_001735_hash il3945_ucode_rx_stats_read 3 3048 _001735_hash NULL
82538 +_001736_hash il3945_ucode_tx_stats_read 3 36016 _001736_hash NULL
82539 +_001737_hash il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 _001737_hash NULL
82540 +_001738_hash il4965_rs_sta_dbgfs_scale_table_read 3 38564 _001738_hash NULL
82541 +_001739_hash il4965_rs_sta_dbgfs_stats_table_read 3 49206 _001739_hash NULL
82542 +_001740_hash il4965_ucode_general_stats_read 3 56277 _001740_hash NULL
82543 +_001741_hash il4965_ucode_rx_stats_read 3 61948 _001741_hash NULL
82544 +_001742_hash il4965_ucode_tx_stats_read 3 12064 _001742_hash NULL
82545 +_001743_hash il_dbgfs_chain_noise_read 3 38044 _001743_hash NULL
82546 +_001744_hash il_dbgfs_channels_read 3 25005 _001744_hash NULL
82547 +_001745_hash il_dbgfs_disable_ht40_read 3 42386 _001745_hash NULL
82548 +_001746_hash il_dbgfs_fh_reg_read 3 40993 _001746_hash NULL
82549 +_001747_hash il_dbgfs_force_reset_read 3 57517 _001747_hash NULL
82550 +_001748_hash il_dbgfs_interrupt_read 3 3351 _001748_hash NULL
82551 +_001749_hash il_dbgfs_missed_beacon_read 3 59956 _001749_hash NULL
82552 +_001750_hash il_dbgfs_nvm_read 3 12288 _001750_hash NULL
82553 +_001751_hash il_dbgfs_power_save_status_read 3 43165 _001751_hash NULL
82554 +_001752_hash il_dbgfs_qos_read 3 33615 _001752_hash NULL
82555 +_001753_hash il_dbgfs_rxon_filter_flags_read 3 19281 _001753_hash NULL
82556 +_001754_hash il_dbgfs_rxon_flags_read 3 59950 _001754_hash &_001681_hash
82557 +_001755_hash il_dbgfs_rx_queue_read 3 11221 _001755_hash NULL
82558 +_001756_hash il_dbgfs_rx_stats_read 3 15243 _001756_hash NULL
82559 +_001757_hash il_dbgfs_sensitivity_read 3 2370 _001757_hash NULL
82560 +_001758_hash il_dbgfs_sram_read 3 62296 _001758_hash NULL
82561 +_001759_hash il_dbgfs_stations_read 3 21532 _001759_hash NULL
82562 +_001760_hash il_dbgfs_status_read 3 58388 _001760_hash NULL
82563 +_001761_hash il_dbgfs_tx_queue_read 3 55668 _001761_hash NULL
82564 +_001762_hash il_dbgfs_tx_stats_read 3 32913 _001762_hash NULL
82565 +_001763_hash ima_show_htable_value 2 57136 _001763_hash NULL
82566 +_001765_hash ipw_write 3 59807 _001765_hash NULL
82567 +_001766_hash irda_recvmsg_stream 4 35280 _001766_hash NULL
82568 +_001767_hash iscsi_tcp_conn_setup 2 16376 _001767_hash NULL
82569 +_001768_hash isr_cmd_cmplt_read 3 53439 _001768_hash NULL
82570 +_001769_hash isr_commands_read 3 41398 _001769_hash NULL
82571 +_001770_hash isr_decrypt_done_read 3 49490 _001770_hash NULL
82572 +_001771_hash isr_dma0_done_read 3 8574 _001771_hash NULL
82573 +_001772_hash isr_dma1_done_read 3 48159 _001772_hash NULL
82574 +_001773_hash isr_fiqs_read 3 34687 _001773_hash NULL
82575 +_001774_hash isr_host_acknowledges_read 3 54136 _001774_hash NULL
82576 +_001775_hash isr_hw_pm_mode_changes_read 3 16110 _001775_hash &_001696_hash
82577 +_001776_hash isr_irqs_read 3 9181 _001776_hash NULL
82578 +_001777_hash isr_low_rssi_read 3 64789 _001777_hash NULL
82579 +_001778_hash isr_pci_pm_read 3 30271 _001778_hash NULL
82580 +_001779_hash isr_rx_headers_read 3 38325 _001779_hash NULL
82581 +_001780_hash isr_rx_mem_overflow_read 3 43025 _001780_hash NULL
82582 +_001781_hash isr_rx_procs_read 3 31804 _001781_hash NULL
82583 +_001782_hash isr_rx_rdys_read 3 35283 _001782_hash NULL
82584 +_001783_hash isr_tx_exch_complete_read 3 16103 _001783_hash NULL
82585 +_001784_hash isr_tx_procs_read 3 23084 _001784_hash NULL
82586 +_001785_hash isr_wakeups_read 3 49607 _001785_hash NULL
82587 +_001786_hash ivtv_read 3 57796 _001786_hash NULL
82588 +_001787_hash iwl_dbgfs_bt_traffic_read 3 35534 _001787_hash NULL
82589 +_001788_hash iwl_dbgfs_chain_noise_read 3 46355 _001788_hash NULL
82590 +_001789_hash iwl_dbgfs_channels_read 3 6784 _001789_hash NULL
82591 +_001790_hash iwl_dbgfs_current_sleep_command_read 3 2081 _001790_hash NULL
82592 +_001791_hash iwl_dbgfs_disable_ht40_read 3 35761 _001791_hash NULL
82593 +_001792_hash iwl_dbgfs_fh_reg_read 3 879 _001792_hash &_000393_hash
82594 +_001793_hash iwl_dbgfs_force_reset_read 3 62628 _001793_hash NULL
82595 +_001794_hash iwl_dbgfs_interrupt_read 3 23574 _001794_hash NULL
82596 +_001795_hash iwl_dbgfs_log_event_read 3 2107 _001795_hash NULL
82597 +_001796_hash iwl_dbgfs_missed_beacon_read 3 50584 _001796_hash NULL
82598 +_001797_hash iwl_dbgfs_nvm_read 3 23845 _001797_hash NULL
82599 +_001798_hash iwl_dbgfs_plcp_delta_read 3 55407 _001798_hash NULL
82600 +_001799_hash iwl_dbgfs_power_save_status_read 3 54392 _001799_hash NULL
82601 +_001800_hash iwl_dbgfs_protection_mode_read 3 13943 _001800_hash NULL
82602 +_001801_hash iwl_dbgfs_qos_read 3 11753 _001801_hash NULL
82603 +_001802_hash iwl_dbgfs_reply_tx_error_read 3 19205 _001802_hash NULL
82604 +_001803_hash iwl_dbgfs_rx_handlers_read 3 18708 _001803_hash NULL
82605 +_001804_hash iwl_dbgfs_rxon_filter_flags_read 3 28832 _001804_hash NULL
82606 +_001805_hash iwl_dbgfs_rxon_flags_read 3 20795 _001805_hash NULL
82607 +_001806_hash iwl_dbgfs_rx_queue_read 3 19943 _001806_hash NULL
82608 +_001807_hash iwl_dbgfs_rx_statistics_read 3 62687 _001807_hash &_000425_hash
82609 +_001808_hash iwl_dbgfs_sensitivity_read 3 63116 _001808_hash NULL
82610 +_001809_hash iwl_dbgfs_sleep_level_override_read 3 3038 _001809_hash NULL
82611 +_001810_hash iwl_dbgfs_sram_read 3 44505 _001810_hash NULL
82612 +_001811_hash iwl_dbgfs_stations_read 3 9309 _001811_hash NULL
82613 +_001812_hash iwl_dbgfs_status_read 3 5171 _001812_hash NULL
82614 +_001813_hash iwl_dbgfs_temperature_read 3 29224 _001813_hash NULL
82615 +_001814_hash iwl_dbgfs_thermal_throttling_read 3 38779 _001814_hash NULL
82616 +_001815_hash iwl_dbgfs_traffic_log_read 3 58870 _001815_hash NULL
82617 +_001816_hash iwl_dbgfs_tx_queue_read 3 4635 _001816_hash NULL
82618 +_001817_hash iwl_dbgfs_tx_statistics_read 3 314 _001817_hash NULL
82619 +_001818_hash iwl_dbgfs_ucode_bt_stats_read 3 42820 _001818_hash NULL
82620 +_001819_hash iwl_dbgfs_ucode_general_stats_read 3 49199 _001819_hash NULL
82621 +_001820_hash iwl_dbgfs_ucode_rx_stats_read 3 58023 _001820_hash NULL
82622 +_001821_hash iwl_dbgfs_ucode_tracing_read 3 47983 _001821_hash &_000349_hash
82623 +_001822_hash iwl_dbgfs_ucode_tx_stats_read 3 31611 _001822_hash NULL
82624 +_001823_hash iwl_dbgfs_wowlan_sram_read 3 540 _001823_hash NULL
82625 +_001824_hash iwm_if_alloc 1 17027 _001824_hash &_001314_hash
82626 +_001825_hash kernel_readv 3 35617 _001825_hash NULL
82627 +_001826_hash key_algorithm_read 3 57946 _001826_hash NULL
82628 +_001827_hash key_icverrors_read 3 20895 _001827_hash NULL
82629 +_001828_hash key_key_read 3 3241 _001828_hash NULL
82630 +_001829_hash key_replays_read 3 62746 _001829_hash NULL
82631 +_001830_hash key_rx_spec_read 3 12736 _001830_hash NULL
82632 +_001831_hash key_tx_spec_read 3 4862 _001831_hash NULL
82633 +_001832_hash __kfifo_to_user 3 36555 _002199_hash NULL nohasharray
82634 +_001833_hash __kfifo_to_user_r 3 39123 _001833_hash NULL
82635 +_001834_hash kmem_zalloc_greedy 2-3 65268 _001834_hash NULL
82636 +_001836_hash l2cap_chan_send 3 49995 _001836_hash NULL
82637 +_001837_hash l2cap_sar_segment_sdu 3 27701 _001837_hash NULL
82638 +_001838_hash lbs_debugfs_read 3 30721 _001838_hash NULL
82639 +_001839_hash lbs_dev_info 3 51023 _001839_hash NULL
82640 +_001840_hash lbs_host_sleep_read 3 31013 _001840_hash NULL
82641 +_001841_hash lbs_rdbbp_read 3 45805 _001841_hash NULL
82642 +_001842_hash lbs_rdmac_read 3 418 _001842_hash NULL
82643 +_001843_hash lbs_rdrf_read 3 41431 _001843_hash NULL
82644 +_001844_hash lbs_sleepparams_read 3 10840 _001844_hash NULL
82645 +_001845_hash lbs_threshold_read 5 21046 _001845_hash NULL
82646 +_001846_hash libfc_vport_create 2 4415 _001846_hash NULL
82647 +_001847_hash lkdtm_debugfs_read 3 45752 _001847_hash NULL
82648 +_001848_hash llcp_sock_recvmsg 4 13556 _001848_hash NULL
82649 +_001849_hash long_retry_limit_read 3 59766 _001849_hash NULL
82650 +_001850_hash lpfc_debugfs_dif_err_read 3 36303 _001850_hash NULL
82651 +_001851_hash lpfc_debugfs_read 3 16566 _001851_hash NULL
82652 +_001852_hash lpfc_idiag_baracc_read 3 58466 _002447_hash NULL nohasharray
82653 +_001853_hash lpfc_idiag_ctlacc_read 3 33943 _001853_hash NULL
82654 +_001854_hash lpfc_idiag_drbacc_read 3 15948 _001854_hash NULL
82655 +_001855_hash lpfc_idiag_extacc_read 3 48301 _001855_hash NULL
82656 +_001856_hash lpfc_idiag_mbxacc_read 3 28061 _001856_hash NULL
82657 +_001857_hash lpfc_idiag_pcicfg_read 3 50334 _001857_hash NULL
82658 +_001858_hash lpfc_idiag_queacc_read 3 13950 _001858_hash NULL
82659 +_001859_hash lpfc_idiag_queinfo_read 3 55662 _001859_hash NULL
82660 +_001860_hash mac80211_format_buffer 2 41010 _001860_hash NULL
82661 +_001861_hash macvtap_put_user 4 55609 _001861_hash NULL
82662 +_001862_hash macvtap_sendmsg 4 30629 _001862_hash NULL
82663 +_001863_hash mic_calc_failure_read 3 59700 _001863_hash NULL
82664 +_001864_hash mic_rx_pkts_read 3 27972 _001864_hash NULL
82665 +_001865_hash minstrel_stats_read 3 17290 _001865_hash NULL
82666 +_001866_hash mmc_ext_csd_read 3 13205 _001866_hash NULL
82667 +_001867_hash mon_bin_read 3 6841 _001867_hash NULL
82668 +_001868_hash mon_stat_read 3 25238 _001868_hash NULL
82669 +_001870_hash mqueue_read_file 3 6228 _001870_hash NULL
82670 +_001871_hash mwifiex_debug_read 3 53074 _001871_hash NULL
82671 +_001872_hash mwifiex_getlog_read 3 54269 _001872_hash NULL
82672 +_001873_hash mwifiex_info_read 3 53447 _001873_hash NULL
82673 +_001874_hash mwifiex_rdeeprom_read 3 51429 _001874_hash NULL
82674 +_001875_hash mwifiex_regrdwr_read 3 34472 _001875_hash NULL
82675 +_001876_hash nfsd_vfs_read 6 62605 _001876_hash NULL
82676 +_001877_hash nfsd_vfs_write 6 54577 _001877_hash NULL
82677 +_001878_hash nfs_idmap_lookup_id 2 10660 _001878_hash NULL
82678 +_001879_hash o2hb_debug_read 3 37851 _001879_hash NULL
82679 +_001880_hash o2net_debug_read 3 52105 _001880_hash NULL
82680 +_001881_hash ocfs2_control_read 3 56405 _001881_hash NULL
82681 +_001882_hash ocfs2_debug_read 3 14507 _001882_hash NULL
82682 +_001883_hash ocfs2_readlink 3 50656 _001883_hash NULL
82683 +_001884_hash oom_adjust_read 3 25127 _001884_hash NULL
82684 +_001885_hash oom_score_adj_read 3 39921 _002116_hash NULL nohasharray
82685 +_001886_hash oprofilefs_str_to_user 3 42182 _001886_hash NULL
82686 +_001887_hash oprofilefs_ulong_to_user 3 11582 _001887_hash NULL
82687 +_001888_hash _osd_req_list_objects 6 4204 _001888_hash NULL
82688 +_001889_hash osd_req_read_kern 5 59990 _001889_hash NULL
82689 +_001890_hash osd_req_write_kern 5 53486 _001890_hash NULL
82690 +_001891_hash p54_init_common 1 23850 _001891_hash NULL
82691 +_001892_hash packet_sendmsg 4 24954 _001892_hash NULL
82692 +_001893_hash page_readlink 3 23346 _001893_hash NULL
82693 +_001894_hash pcf50633_write_block 3 2124 _001894_hash NULL
82694 +_001895_hash platform_list_read_file 3 34734 _001895_hash NULL
82695 +_001896_hash pm860x_bulk_write 3 43875 _001896_hash NULL
82696 +_001897_hash pm_qos_power_read 3 55891 _001897_hash NULL
82697 +_001898_hash pms_read 3 53873 _001898_hash NULL
82698 +_001899_hash port_show_regs 3 5904 _001899_hash NULL
82699 +_001900_hash proc_coredump_filter_read 3 39153 _001900_hash NULL
82700 +_001901_hash proc_fdinfo_read 3 62043 _001901_hash NULL
82701 +_001902_hash proc_info_read 3 63344 _001902_hash NULL
82702 +_001903_hash proc_loginuid_read 3 15631 _001903_hash NULL
82703 +_001904_hash proc_pid_attr_read 3 10173 _001904_hash NULL
82704 +_001905_hash proc_pid_readlink 3 52186 _001905_hash NULL
82705 +_001906_hash proc_read 3 43614 _001906_hash NULL
82706 +_001907_hash proc_self_readlink 3 38094 _001907_hash NULL
82707 +_001908_hash proc_sessionid_read 3 6911 _002038_hash NULL nohasharray
82708 +_001909_hash provide_user_output 3 41105 _001909_hash NULL
82709 +_001910_hash ps_pspoll_max_apturn_read 3 6699 _001910_hash NULL
82710 +_001911_hash ps_pspoll_timeouts_read 3 11776 _001911_hash NULL
82711 +_001912_hash ps_pspoll_utilization_read 3 5361 _001912_hash NULL
82712 +_001913_hash pstore_file_read 3 57288 _001913_hash NULL
82713 +_001914_hash ps_upsd_max_apturn_read 3 19918 _001914_hash NULL
82714 +_001915_hash ps_upsd_max_sptime_read 3 63362 _001915_hash NULL
82715 +_001916_hash ps_upsd_timeouts_read 3 28924 _001916_hash NULL
82716 +_001917_hash ps_upsd_utilization_read 3 51669 _001917_hash NULL
82717 +_001918_hash pvr2_v4l2_read 3 18006 _001918_hash NULL
82718 +_001919_hash pwr_disable_ps_read 3 13176 _001919_hash NULL
82719 +_001920_hash pwr_elp_enter_read 3 5324 _001920_hash NULL
82720 +_001921_hash pwr_enable_ps_read 3 17686 _001921_hash NULL
82721 +_001922_hash pwr_fix_tsf_ps_read 3 26627 _001922_hash NULL
82722 +_001923_hash pwr_missing_bcns_read 3 25824 _001923_hash NULL
82723 +_001924_hash pwr_power_save_off_read 3 18355 _001924_hash NULL
82724 +_001925_hash pwr_ps_enter_read 3 26935 _001925_hash &_000501_hash
82725 +_001926_hash pwr_rcvd_awake_beacons_read 3 50505 _001926_hash NULL
82726 +_001927_hash pwr_rcvd_beacons_read 3 52836 _001927_hash NULL
82727 +_001928_hash pwr_tx_without_ps_read 3 48423 _001928_hash NULL
82728 +_001929_hash pwr_tx_with_ps_read 3 60851 _001929_hash NULL
82729 +_001930_hash pwr_wake_on_host_read 3 26321 _001930_hash NULL
82730 +_001931_hash pwr_wake_on_timer_exp_read 3 22640 _001931_hash NULL
82731 +_001932_hash queues_read 3 24877 _001932_hash NULL
82732 +_001933_hash raw_recvmsg 4 17277 _001933_hash NULL
82733 +_001934_hash rcname_read 3 25919 _001934_hash NULL
82734 +_001935_hash read_4k_modal_eeprom 3 30212 _001935_hash NULL
82735 +_001936_hash read_9287_modal_eeprom 3 59327 _001936_hash NULL
82736 +_001937_hash reada_find_extent 2 63486 _001937_hash NULL
82737 +_001938_hash read_def_modal_eeprom 3 14041 _001938_hash NULL
82738 +_001939_hash read_enabled_file_bool 3 37744 _001939_hash NULL
82739 +_001940_hash read_file_ani 3 23161 _001940_hash NULL
82740 +_001941_hash read_file_antenna 3 13574 _001941_hash NULL
82741 +_001942_hash read_file_base_eeprom 3 42168 _001942_hash NULL
82742 +_001943_hash read_file_beacon 3 32595 _001943_hash NULL
82743 +_001944_hash read_file_blob 3 57406 _001944_hash NULL
82744 +_001945_hash read_file_bool 3 4180 _001945_hash NULL
82745 +_001946_hash read_file_credit_dist_stats 3 54367 _001946_hash NULL
82746 +_001947_hash read_file_debug 3 58256 _001947_hash NULL
82747 +_001948_hash read_file_disable_ani 3 6536 _001948_hash NULL
82748 +_001949_hash read_file_dma 3 9530 _001949_hash NULL
82749 +_001950_hash read_file_dump_nfcal 3 18766 _001950_hash NULL
82750 +_001951_hash read_file_frameerrors 3 64001 _001951_hash NULL
82751 +_001952_hash read_file_interrupt 3 61742 _001959_hash NULL nohasharray
82752 +_001953_hash read_file_misc 3 9948 _001953_hash NULL
82753 +_001954_hash read_file_modal_eeprom 3 39909 _001954_hash NULL
82754 +_001955_hash read_file_queue 3 40895 _001955_hash NULL
82755 +_001956_hash read_file_rcstat 3 22854 _001956_hash NULL
82756 +_001957_hash read_file_recv 3 48232 _001957_hash NULL
82757 +_001958_hash read_file_regidx 3 33370 _001958_hash NULL
82758 +_001959_hash read_file_regval 3 61742 _001959_hash &_001952_hash
82759 +_001960_hash read_file_reset 3 52310 _001960_hash NULL
82760 +_001961_hash read_file_rx_chainmask 3 41605 _001961_hash NULL
82761 +_001962_hash read_file_slot 3 50111 _001962_hash NULL
82762 +_001963_hash read_file_stations 3 35795 _001963_hash NULL
82763 +_001964_hash read_file_tgt_int_stats 3 20697 _001964_hash NULL
82764 +_001965_hash read_file_tgt_rx_stats 3 33944 _001965_hash NULL
82765 +_001966_hash read_file_tgt_stats 3 8959 _001966_hash NULL
82766 +_001967_hash read_file_tgt_tx_stats 3 51847 _001967_hash NULL
82767 +_001968_hash read_file_tx_chainmask 3 3829 _001968_hash NULL
82768 +_001969_hash read_file_war_stats 3 292 _001969_hash NULL
82769 +_001970_hash read_file_xmit 3 21487 _001970_hash NULL
82770 +_001971_hash read_from_oldmem 2 3337 _001971_hash NULL
82771 +_001972_hash read_oldmem 3 55658 _001972_hash NULL
82772 +_001973_hash regmap_name_read_file 3 39379 _001973_hash NULL
82773 +_001974_hash repair_io_failure 4 4815 _001974_hash NULL
82774 +_001975_hash request_key_and_link 4 42693 _001975_hash NULL
82775 +_001976_hash res_counter_read 4 33499 _001976_hash NULL
82776 +_001977_hash retry_count_read 3 52129 _001977_hash NULL
82777 +_001978_hash rs_sta_dbgfs_rate_scale_data_read 3 47165 _001978_hash NULL
82778 +_001979_hash rs_sta_dbgfs_scale_table_read 3 40262 _001979_hash NULL
82779 +_001980_hash rs_sta_dbgfs_stats_table_read 3 56573 _001980_hash NULL
82780 +_001981_hash rts_threshold_read 3 44384 _001981_hash NULL
82781 +_001982_hash rx_dropped_read 3 44799 _001982_hash NULL
82782 +_001983_hash rx_fcs_err_read 3 62844 _001983_hash NULL
82783 +_001984_hash rx_hdr_overflow_read 3 64407 _001984_hash NULL
82784 +_001985_hash rx_hw_stuck_read 3 57179 _001985_hash NULL
82785 +_001986_hash rx_out_of_mem_read 3 10157 _001986_hash NULL
82786 +_001987_hash rx_path_reset_read 3 23801 _001987_hash NULL
82787 +_001988_hash rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 _001988_hash NULL
82788 +_001989_hash rxpipe_descr_host_int_trig_rx_data_read 3 22001 _001989_hash NULL
82789 +_001990_hash rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 _001990_hash NULL
82790 +_001991_hash rxpipe_rx_prep_beacon_drop_read 3 2403 _001991_hash NULL
82791 +_001992_hash rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 _001992_hash NULL
82792 +_001993_hash rx_reset_counter_read 3 58001 _001993_hash NULL
82793 +_001994_hash rx_xfr_hint_trig_read 3 40283 _001994_hash NULL
82794 +_001995_hash s5m_bulk_write 3 4833 _001995_hash NULL
82795 +_001996_hash scrub_setup_recheck_block 3-4 56245 _001996_hash NULL
82796 +_001998_hash scsi_adjust_queue_depth 3 12802 _001998_hash NULL
82797 +_001999_hash selinux_inode_notifysecctx 3 36896 _001999_hash NULL
82798 +_002000_hash sel_read_avc_cache_threshold 3 33942 _002000_hash NULL
82799 +_002001_hash sel_read_avc_hash_stats 3 1984 _002001_hash NULL
82800 +_002002_hash sel_read_bool 3 24236 _002002_hash NULL
82801 +_002003_hash sel_read_checkreqprot 3 33068 _002003_hash NULL
82802 +_002004_hash sel_read_class 3 12669 _002541_hash NULL nohasharray
82803 +_002005_hash sel_read_enforce 3 2828 _002005_hash NULL
82804 +_002006_hash sel_read_handle_status 3 56139 _002006_hash NULL
82805 +_002007_hash sel_read_handle_unknown 3 57933 _002007_hash NULL
82806 +_002008_hash sel_read_initcon 3 32362 _002008_hash NULL
82807 +_002009_hash sel_read_mls 3 25369 _002009_hash NULL
82808 +_002010_hash sel_read_perm 3 42302 _002010_hash NULL
82809 +_002011_hash sel_read_policy 3 55947 _002011_hash NULL
82810 +_002012_hash sel_read_policycap 3 28544 _002012_hash NULL
82811 +_002013_hash sel_read_policyvers 3 55 _002013_hash NULL
82812 +_002014_hash send_msg 4 37323 _002014_hash NULL
82813 +_002015_hash send_packet 4 52960 _002015_hash NULL
82814 +_002016_hash short_retry_limit_read 3 4687 _002016_hash NULL
82815 +_002017_hash simple_attr_read 3 24738 _002017_hash NULL
82816 +_002018_hash simple_transaction_read 3 17076 _002018_hash NULL
82817 +_002019_hash skb_copy_datagram_const_iovec 2-5-4 48102 _002019_hash NULL
82818 +_002022_hash skb_copy_datagram_iovec 2-4 5806 _002022_hash NULL
82819 +_002024_hash smk_read_ambient 3 61220 _002024_hash NULL
82820 +_002025_hash smk_read_direct 3 15803 _002025_hash NULL
82821 +_002026_hash smk_read_doi 3 30813 _002026_hash NULL
82822 +_002027_hash smk_read_logging 3 37804 _002027_hash NULL
82823 +_002028_hash smk_read_onlycap 3 3855 _002028_hash NULL
82824 +_002029_hash snapshot_read 3 22601 _002029_hash NULL
82825 +_002030_hash snd_cs4281_BA0_read 5 6847 _002030_hash NULL
82826 +_002031_hash snd_cs4281_BA1_read 5 20323 _002031_hash NULL
82827 +_002032_hash snd_cs46xx_io_read 5 45734 _002032_hash NULL
82828 +_002033_hash snd_gus_dram_read 4 56686 _002033_hash NULL
82829 +_002034_hash snd_pcm_oss_read 3 28317 _002034_hash NULL
82830 +_002035_hash snd_rme32_capture_copy 5 39653 _002035_hash NULL
82831 +_002036_hash snd_rme96_capture_copy 5 58484 _002036_hash NULL
82832 +_002037_hash snd_soc_hw_bulk_write_raw 4 14245 _002037_hash NULL
82833 +_002038_hash spi_show_regs 3 6911 _002038_hash &_001908_hash
82834 +_002039_hash sta_agg_status_read 3 14058 _002039_hash NULL
82835 +_002040_hash sta_connected_time_read 3 17435 _002040_hash NULL
82836 +_002041_hash sta_flags_read 3 56710 _002041_hash NULL
82837 +_002042_hash sta_ht_capa_read 3 10366 _002042_hash NULL
82838 +_002043_hash sta_last_seq_ctrl_read 3 19106 _002043_hash NULL
82839 +_002044_hash sta_num_ps_buf_frames_read 3 1488 _002044_hash NULL
82840 +_002045_hash st_read 3 51251 _002045_hash NULL
82841 +_002046_hash supply_map_read_file 3 10608 _002046_hash NULL
82842 +_002047_hash sysfs_read_file 3 42113 _002047_hash NULL
82843 +_002048_hash sys_lgetxattr 4 45531 _002048_hash NULL
82844 +_002049_hash sys_preadv 3 17100 _002049_hash NULL
82845 +_002050_hash sys_pwritev 3 41722 _002050_hash NULL
82846 +_002051_hash sys_readv 3 50664 _002051_hash NULL
82847 +_002052_hash sys_rt_sigpending 2 24961 _002052_hash NULL
82848 +_002053_hash sys_writev 3 28384 _002053_hash NULL
82849 +_002054_hash test_iso_queue 5 62534 _002054_hash NULL
82850 +_002055_hash ts_read 3 44687 _002055_hash NULL
82851 +_002056_hash TSS_authhmac 3 12839 _002056_hash NULL
82852 +_002057_hash TSS_checkhmac1 5 31429 _002057_hash NULL
82853 +_002058_hash TSS_checkhmac2 5-7 40520 _002058_hash NULL
82854 +_002060_hash tt3650_ci_msg_locked 4 8013 _002060_hash NULL
82855 +_002061_hash tun_sendmsg 4 10337 _002061_hash NULL
82856 +_002062_hash tx_internal_desc_overflow_read 3 47300 _002062_hash NULL
82857 +_002063_hash tx_queue_len_read 3 1463 _002063_hash NULL
82858 +_002064_hash tx_queue_status_read 3 44978 _002064_hash NULL
82859 +_002065_hash ubi_io_write_data 4-5 40305 _002065_hash NULL
82860 +_002067_hash uhci_debug_read 3 5911 _002067_hash NULL
82861 +_002068_hash unix_stream_recvmsg 4 35210 _002068_hash NULL
82862 +_002069_hash uvc_debugfs_stats_read 3 56651 _002069_hash NULL
82863 +_002070_hash vhost_add_used_and_signal_n 4 8038 _002070_hash NULL
82864 +_002071_hash vifs_state_read 3 33762 _002071_hash NULL
82865 +_002072_hash vmbus_open 2-3 12154 _002072_hash NULL
82866 +_002074_hash waiters_read 3 40902 _002074_hash NULL
82867 +_002075_hash wep_addr_key_count_read 3 20174 _002075_hash NULL
82868 +_002076_hash wep_decrypt_fail_read 3 58567 _002076_hash NULL
82869 +_002077_hash wep_default_key_count_read 3 43035 _002077_hash NULL
82870 +_002078_hash wep_interrupt_read 3 41492 _002078_hash NULL
82871 +_002079_hash wep_key_not_found_read 3 13377 _002079_hash &_000915_hash
82872 +_002080_hash wep_packets_read 3 18751 _002080_hash NULL
82873 +_002081_hash wl1271_format_buffer 2 20834 _002081_hash NULL
82874 +_002082_hash wm8994_bulk_write 3 13615 _002082_hash NULL
82875 +_002083_hash wusb_prf_256 7 29203 _002083_hash NULL
82876 +_002084_hash wusb_prf_64 7 51065 _002084_hash NULL
82877 +_002085_hash xfs_buf_read_uncached 4 27519 _002085_hash NULL
82878 +_002086_hash xfs_iext_add 3 41422 _002086_hash NULL
82879 +_002087_hash xfs_iext_remove_direct 3 40744 _002087_hash NULL
82880 +_002088_hash xfs_trans_get_efd 3 51148 _002088_hash NULL
82881 +_002089_hash xfs_trans_get_efi 2 7898 _002089_hash NULL
82882 +_002090_hash xlog_get_bp 2 23229 _002090_hash NULL
82883 +_002091_hash xz_dec_init 2 29029 _002091_hash NULL
82884 +_002092_hash aac_change_queue_depth 2 825 _002092_hash NULL
82885 +_002093_hash agp_allocate_memory_wrap 1 16576 _002093_hash NULL
82886 +_002094_hash arcmsr_adjust_disk_queue_depth 2 16756 _002094_hash NULL
82887 +_002095_hash atalk_recvmsg 4 22053 _002095_hash NULL
82888 +_002097_hash atomic_read_file 3 16227 _002097_hash NULL
82889 +_002098_hash ax25_recvmsg 4 64441 _002098_hash NULL
82890 +_002099_hash beacon_interval_read 3 7091 _002099_hash NULL
82891 +_002100_hash btrfs_init_new_buffer 4 55761 _002100_hash NULL
82892 +_002101_hash btrfs_mksubvol 3 39479 _002101_hash NULL
82893 +_002102_hash bt_sock_recvmsg 4 12316 _002102_hash NULL
82894 +_002103_hash bt_sock_stream_recvmsg 4 52518 _002103_hash NULL
82895 +_002104_hash caif_seqpkt_recvmsg 4 32241 _002104_hash NULL
82896 +_002105_hash cpu_type_read 3 36540 _002105_hash NULL
82897 +_002106_hash cx18_read 3 23699 _002106_hash NULL
82898 +_002107_hash dccp_recvmsg 4 16056 _002107_hash NULL
82899 +_002108_hash depth_read 3 31112 _002108_hash NULL
82900 +_002109_hash dfs_global_file_read 3 7787 _002109_hash NULL
82901 +_002110_hash dgram_recvmsg 4 23104 _002110_hash NULL
82902 +_002111_hash dma_skb_copy_datagram_iovec 3-5 21516 _002111_hash NULL
82903 +_002113_hash dtim_interval_read 3 654 _002113_hash NULL
82904 +_002114_hash dynamic_ps_timeout_read 3 10110 _002114_hash NULL
82905 +_002115_hash enable_read 3 2117 _002115_hash NULL
82906 +_002116_hash exofs_read_kern 6 39921 _002116_hash &_001885_hash
82907 +_002117_hash fc_change_queue_depth 2 36841 _002117_hash NULL
82908 +_002118_hash forced_ps_read 3 31685 _002118_hash NULL
82909 +_002119_hash frequency_read 3 64031 _002119_hash NULL
82910 +_002120_hash get_alua_req 3 4166 _002120_hash NULL
82911 +_002121_hash get_rdac_req 3 45882 _002121_hash NULL
82912 +_002122_hash hci_sock_recvmsg 4 7072 _002122_hash NULL
82913 +_002123_hash hpsa_change_queue_depth 2 15449 _002123_hash NULL
82914 +_002124_hash hptiop_adjust_disk_queue_depth 2 20122 _002124_hash NULL
82915 +_002125_hash ide_queue_pc_tail 5 11673 _002125_hash NULL
82916 +_002126_hash ide_raw_taskfile 4 42355 _002126_hash NULL
82917 +_002127_hash idetape_queue_rw_tail 3 29562 _002127_hash NULL
82918 +_002128_hash ieee80211_if_read_aid 3 9705 _002128_hash NULL
82919 +_002129_hash ieee80211_if_read_auto_open_plinks 3 38268 _002129_hash NULL
82920 +_002130_hash ieee80211_if_read_ave_beacon 3 64924 _002130_hash NULL
82921 +_002131_hash ieee80211_if_read_bssid 3 35161 _002131_hash NULL
82922 +_002132_hash ieee80211_if_read_channel_type 3 23884 _002132_hash NULL
82923 +_002133_hash ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 _002133_hash NULL
82924 +_002134_hash ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 _002134_hash NULL
82925 +_002135_hash ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 _002135_hash NULL
82926 +_002136_hash ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 _002136_hash NULL
82927 +_002137_hash ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 _002137_hash NULL
82928 +_002138_hash ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 _002138_hash NULL
82929 +_002139_hash ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 _002139_hash NULL
82930 +_002140_hash ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 _002140_hash NULL
82931 +_002141_hash ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 _002141_hash NULL
82932 +_002142_hash ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 _002142_hash NULL
82933 +_002143_hash ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 _002143_hash NULL
82934 +_002144_hash ieee80211_if_read_dot11MeshMaxRetries 3 12756 _002144_hash NULL
82935 +_002145_hash ieee80211_if_read_dot11MeshRetryTimeout 3 52168 _002145_hash NULL
82936 +_002146_hash ieee80211_if_read_dot11MeshTTL 3 58307 _002146_hash NULL
82937 +_002147_hash ieee80211_if_read_dropped_frames_congestion 3 32603 _002147_hash NULL
82938 +_002148_hash ieee80211_if_read_dropped_frames_no_route 3 33383 _002148_hash NULL
82939 +_002149_hash ieee80211_if_read_dropped_frames_ttl 3 44500 _002149_hash NULL
82940 +_002150_hash ieee80211_if_read_drop_unencrypted 3 37053 _002150_hash NULL
82941 +_002151_hash ieee80211_if_read_dtim_count 3 38419 _002151_hash NULL
82942 +_002152_hash ieee80211_if_read_element_ttl 3 18869 _002152_hash NULL
82943 +_002153_hash ieee80211_if_read_estab_plinks 3 32533 _002153_hash NULL
82944 +_002154_hash ieee80211_if_read_flags 3 57470 _002389_hash NULL nohasharray
82945 +_002155_hash ieee80211_if_read_fwded_frames 3 36520 _002155_hash NULL
82946 +_002156_hash ieee80211_if_read_fwded_mcast 3 39571 _002156_hash &_000151_hash
82947 +_002157_hash ieee80211_if_read_fwded_unicast 3 59740 _002157_hash NULL
82948 +_002158_hash ieee80211_if_read_last_beacon 3 31257 _002158_hash NULL
82949 +_002159_hash ieee80211_if_read_min_discovery_timeout 3 13946 _002159_hash NULL
82950 +_002160_hash ieee80211_if_read_num_buffered_multicast 3 12716 _002160_hash NULL
82951 +_002161_hash ieee80211_if_read_num_sta_authorized 3 56177 _002161_hash NULL
82952 +_002162_hash ieee80211_if_read_num_sta_ps 3 34722 _002162_hash NULL
82953 +_002163_hash ieee80211_if_read_path_refresh_time 3 25545 _002163_hash NULL
82954 +_002164_hash ieee80211_if_read_peer 3 45233 _002164_hash NULL
82955 +_002165_hash ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 _002165_hash NULL
82956 +_002166_hash ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 _002166_hash NULL
82957 +_002167_hash ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 _002167_hash NULL
82958 +_002168_hash ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 _002168_hash NULL
82959 +_002169_hash ieee80211_if_read_rssi_threshold 3 49260 _002169_hash NULL
82960 +_002170_hash ieee80211_if_read_smps 3 27416 _002170_hash NULL
82961 +_002171_hash ieee80211_if_read_state 3 9813 _002280_hash NULL nohasharray
82962 +_002172_hash ieee80211_if_read_tkip_mic_test 3 19565 _002172_hash NULL
82963 +_002173_hash ieee80211_if_read_tsf 3 16420 _002173_hash NULL
82964 +_002174_hash ieee80211_if_read_uapsd_max_sp_len 3 15067 _002174_hash NULL
82965 +_002175_hash ieee80211_if_read_uapsd_queues 3 55150 _002175_hash NULL
82966 +_002176_hash ieee80211_rx_mgmt_beacon 3 24430 _002176_hash NULL
82967 +_002177_hash ieee80211_rx_mgmt_probe_resp 3 6918 _002177_hash NULL
82968 +_002178_hash ima_show_htable_violations 3 10619 _002178_hash NULL
82969 +_002179_hash ima_show_measurements_count 3 23536 _002179_hash NULL
82970 +_002180_hash insert_one_name 7 61668 _002180_hash NULL
82971 +_002181_hash ipr_change_queue_depth 2 6431 _002181_hash NULL
82972 +_002182_hash ip_recv_error 3 23109 _002182_hash NULL
82973 +_002183_hash ipv6_recv_error 3 56347 _002183_hash NULL
82974 +_002184_hash ipv6_recv_rxpmtu 3 7142 _002184_hash NULL
82975 +_002185_hash ipx_recvmsg 4 44366 _002185_hash NULL
82976 +_002186_hash irda_recvmsg_dgram 4 32631 _002186_hash NULL
82977 +_002187_hash iscsi_change_queue_depth 2 23416 _002187_hash NULL
82978 +_002188_hash ivtv_read_pos 3 34400 _002188_hash &_000303_hash
82979 +_002189_hash key_conf_hw_key_idx_read 3 25003 _002189_hash NULL
82980 +_002190_hash key_conf_keyidx_read 3 42443 _002190_hash NULL
82981 +_002191_hash key_conf_keylen_read 3 49758 _002191_hash NULL
82982 +_002192_hash key_flags_read 3 25931 _002192_hash NULL
82983 +_002193_hash key_ifindex_read 3 31411 _002193_hash NULL
82984 +_002194_hash key_tx_rx_count_read 3 44742 _002194_hash NULL
82985 +_002195_hash l2cap_sock_sendmsg 4 63427 _002195_hash NULL
82986 +_002196_hash l2tp_ip_recvmsg 4 22681 _002196_hash NULL
82987 +_002197_hash llc_ui_recvmsg 4 3826 _002197_hash NULL
82988 +_002198_hash lpfc_change_queue_depth 2 25905 _002198_hash NULL
82989 +_002199_hash macvtap_do_read 4 36555 _002199_hash &_001832_hash
82990 +_002200_hash megaraid_change_queue_depth 2 64815 _002200_hash NULL
82991 +_002201_hash megasas_change_queue_depth 2 32747 _002201_hash NULL
82992 +_002202_hash mptscsih_change_queue_depth 2 26036 _002202_hash NULL
82993 +_002203_hash NCR_700_change_queue_depth 2 31742 _002203_hash NULL
82994 +_002204_hash netlink_recvmsg 4 61600 _002204_hash NULL
82995 +_002205_hash nfsctl_transaction_read 3 48250 _002205_hash NULL
82996 +_002206_hash nfs_map_group_to_gid 3 15892 _002206_hash NULL
82997 +_002207_hash nfs_map_name_to_uid 3 51132 _002207_hash NULL
82998 +_002208_hash nr_recvmsg 4 12649 _002208_hash NULL
82999 +_002209_hash osd_req_list_collection_objects 5 36664 _002209_hash NULL
83000 +_002210_hash osd_req_list_partition_objects 5 56464 _002210_hash NULL
83001 +_002212_hash packet_recv_error 3 16669 _002212_hash NULL
83002 +_002213_hash packet_recvmsg 4 47700 _002213_hash NULL
83003 +_002214_hash pep_recvmsg 4 19402 _002214_hash NULL
83004 +_002215_hash pfkey_recvmsg 4 53604 _002215_hash NULL
83005 +_002216_hash ping_recvmsg 4 25597 _002216_hash NULL
83006 +_002217_hash pmcraid_change_queue_depth 2 9116 _002217_hash NULL
83007 +_002218_hash pn_recvmsg 4 30887 _002218_hash NULL
83008 +_002219_hash pointer_size_read 3 51863 _002219_hash NULL
83009 +_002220_hash power_read 3 15939 _002220_hash NULL
83010 +_002221_hash pppoe_recvmsg 4 15073 _002221_hash NULL
83011 +_002222_hash pppol2tp_recvmsg 4 57742 _002222_hash NULL
83012 +_002223_hash qla2x00_adjust_sdev_qdepth_up 2 20097 _002223_hash NULL
83013 +_002224_hash qla2x00_change_queue_depth 2 24742 _002224_hash NULL
83014 +_002225_hash raw_recvmsg 4 52529 _002225_hash NULL
83015 +_002226_hash rawsock_recvmsg 4 12144 _002226_hash NULL
83016 +_002227_hash rawv6_recvmsg 4 30265 _002227_hash NULL
83017 +_002228_hash reada_add_block 2 54247 _002228_hash NULL
83018 +_002229_hash readahead_tree_block 3 36285 _002229_hash NULL
83019 +_002230_hash reada_tree_block_flagged 3 18402 _002230_hash NULL
83020 +_002231_hash read_tree_block 3 841 _002231_hash NULL
83021 +_002232_hash recover_peb 6-7 29238 _002232_hash NULL
83022 +_002234_hash recv_msg 4 48709 _002234_hash NULL
83023 +_002235_hash recv_stream 4 30138 _002235_hash NULL
83024 +_002236_hash _req_append_segment 2 41031 _002236_hash NULL
83025 +_002237_hash request_key_async 4 6990 _002237_hash NULL
83026 +_002238_hash request_key_async_with_auxdata 4 46624 _002238_hash NULL
83027 +_002239_hash request_key_with_auxdata 4 24515 _002239_hash NULL
83028 +_002240_hash rose_recvmsg 4 2368 _002240_hash NULL
83029 +_002241_hash rxrpc_recvmsg 4 26233 _002241_hash NULL
83030 +_002242_hash rx_streaming_always_read 3 49401 _002242_hash NULL
83031 +_002243_hash rx_streaming_interval_read 3 55291 _002243_hash NULL
83032 +_002244_hash sas_change_queue_depth 2 18555 _002244_hash NULL
83033 +_002245_hash scsi_activate_tcq 2 42640 _002245_hash NULL
83034 +_002246_hash scsi_deactivate_tcq 2 47086 _002246_hash NULL
83035 +_002247_hash scsi_execute 5 33596 _002247_hash NULL
83036 +_002248_hash _scsih_adjust_queue_depth 2 1083 _002248_hash NULL
83037 +_002249_hash scsi_init_shared_tag_map 2 59812 _002249_hash NULL
83038 +_002250_hash scsi_track_queue_full 2 44239 _002250_hash NULL
83039 +_002251_hash sctp_recvmsg 4 23265 _002251_hash NULL
83040 +_002252_hash send_stream 4 3397 _002252_hash NULL
83041 +_002253_hash skb_copy_and_csum_datagram_iovec 2 24466 _002253_hash NULL
83042 +_002255_hash snd_gf1_mem_proc_dump 5 16926 _002255_hash NULL
83043 +_002256_hash split_scan_timeout_read 3 20029 _002256_hash NULL
83044 +_002257_hash sta_dev_read 3 14782 _002257_hash NULL
83045 +_002258_hash sta_inactive_ms_read 3 25690 _002258_hash NULL
83046 +_002259_hash sta_last_signal_read 3 31818 _002259_hash NULL
83047 +_002260_hash stats_dot11ACKFailureCount_read 3 45558 _002260_hash NULL
83048 +_002261_hash stats_dot11FCSErrorCount_read 3 28154 _002261_hash NULL
83049 +_002262_hash stats_dot11RTSFailureCount_read 3 43948 _002262_hash NULL
83050 +_002263_hash stats_dot11RTSSuccessCount_read 3 33065 _002263_hash NULL
83051 +_002264_hash storvsc_connect_to_vsp 2 22 _002264_hash NULL
83052 +_002265_hash suspend_dtim_interval_read 3 64971 _002265_hash NULL
83053 +_002266_hash sys_msgrcv 3 959 _002266_hash NULL
83054 +_002267_hash tcm_loop_change_queue_depth 2 42454 _002267_hash NULL
83055 +_002268_hash tcp_copy_to_iovec 3 28344 _002268_hash NULL
83056 +_002269_hash tcp_recvmsg 4 31238 _002269_hash NULL
83057 +_002270_hash timeout_read 3 47915 _002270_hash NULL
83058 +_002271_hash total_ps_buffered_read 3 16365 _002271_hash NULL
83059 +_002272_hash tun_put_user 4 59849 _002272_hash NULL
83060 +_002273_hash twa_change_queue_depth 2 48808 _002273_hash NULL
83061 +_002274_hash tw_change_queue_depth 2 11116 _002274_hash NULL
83062 +_002275_hash twl_change_queue_depth 2 41342 _002275_hash NULL
83063 +_002276_hash ubi_eba_write_leb 5-6 19826 _002276_hash NULL
83064 +_002278_hash ubi_eba_write_leb_st 5 27896 _002278_hash NULL
83065 +_002279_hash udp_recvmsg 4 42558 _002279_hash NULL
83066 +_002280_hash udpv6_recvmsg 4 9813 _002280_hash &_002171_hash
83067 +_002281_hash ulong_read_file 3 42304 _002281_hash &_000511_hash
83068 +_002282_hash unix_dgram_recvmsg 4 14952 _002282_hash NULL
83069 +_002283_hash user_power_read 3 39414 _002283_hash NULL
83070 +_002284_hash vcc_recvmsg 4 37198 _002284_hash NULL
83071 +_002285_hash wep_iv_read 3 54744 _002285_hash NULL
83072 +_002286_hash x25_recvmsg 4 42777 _002286_hash NULL
83073 +_002287_hash xfs_iext_insert 3 18667 _002287_hash NULL
83074 +_002288_hash xfs_iext_remove 3 50909 _002288_hash NULL
83075 +_002289_hash xlog_find_verify_log_record 2 18870 _002289_hash NULL
83076 +_002290_hash btrfs_alloc_free_block 3 29982 _002290_hash NULL
83077 +_002291_hash cx18_read_pos 3 4683 _002291_hash NULL
83078 +_002292_hash l2cap_sock_recvmsg 4 59886 _002292_hash NULL
83079 +_002293_hash osd_req_list_dev_partitions 4 60027 _002293_hash NULL
83080 +_002294_hash osd_req_list_partition_collections 5 38223 _002294_hash NULL
83081 +_002295_hash osst_do_scsi 4 44410 _002295_hash NULL
83082 +_002296_hash qla2x00_handle_queue_full 2 24365 _002296_hash NULL
83083 +_002297_hash rfcomm_sock_recvmsg 4 22227 _002297_hash NULL
83084 +_002298_hash scsi_execute_req 5 42088 _002298_hash NULL
83085 +_002299_hash _scsih_change_queue_depth 2 26230 _002299_hash NULL
83086 +_002300_hash spi_execute 5 28736 _002300_hash NULL
83087 +_002301_hash submit_inquiry 3 42108 _002301_hash NULL
83088 +_002302_hash tcp_dma_try_early_copy 3 37651 _002302_hash NULL
83089 +_002303_hash tun_do_read 4 50800 _002303_hash NULL
83090 +_002304_hash ubi_eba_atomic_leb_change 5 13041 _002304_hash NULL
83091 +_002305_hash ubi_leb_write 4-5 41691 _002305_hash NULL
83092 +_002307_hash unix_seqpacket_recvmsg 4 23062 _002307_hash NULL
83093 +_002308_hash write_leb 5 36957 _002308_hash NULL
83094 +_002309_hash ch_do_scsi 4 31171 _002309_hash NULL
83095 +_002310_hash dbg_leb_write 4-5 20478 _002310_hash NULL
83096 +_002312_hash scsi_mode_sense 5 16835 _002312_hash NULL
83097 +_002313_hash scsi_vpd_inquiry 4 30040 _002313_hash NULL
83098 +_002314_hash ses_recv_diag 4 47143 _002314_hash &_000673_hash
83099 +_002315_hash ses_send_diag 4 64527 _002315_hash NULL
83100 +_002316_hash spi_dv_device_echo_buffer 2-3 39846 _002316_hash NULL
83101 +_002318_hash ubifs_leb_write 4-5 61226 _002318_hash NULL
83102 +_002320_hash ubi_leb_change 4 14899 _002320_hash NULL
83103 +_002321_hash ubi_write 4-5 30809 _002321_hash NULL
83104 +_002322_hash dbg_leb_change 4 19969 _002322_hash NULL
83105 +_002323_hash gluebi_write 3 27905 _002323_hash NULL
83106 +_002324_hash scsi_get_vpd_page 4 51951 _002324_hash NULL
83107 +_002325_hash sd_do_mode_sense 5 11507 _002325_hash NULL
83108 +_002326_hash ubifs_leb_change 4 22399 _002436_hash NULL nohasharray
83109 +_002327_hash ubifs_write_node 5 15088 _002327_hash NULL
83110 +_002328_hash fixup_leb 3 43256 _002328_hash NULL
83111 +_002329_hash recover_head 3 17904 _002329_hash NULL
83112 +_002330_hash alloc_cpu_rmap 1 65363 _002330_hash NULL
83113 +_002331_hash alloc_ebda_hpc 1-2 50046 _002331_hash NULL
83114 +_002333_hash alloc_sched_domains 1 28972 _002333_hash NULL
83115 +_002334_hash amthi_read 4 45831 _002334_hash NULL
83116 +_002335_hash bcm_char_read 3 31750 _002335_hash NULL
83117 +_002336_hash BcmCopySection 5 2035 _002336_hash NULL
83118 +_002337_hash buffer_from_user 3 51826 _002337_hash NULL
83119 +_002338_hash buffer_to_user 3 35439 _002338_hash NULL
83120 +_002339_hash c4iw_init_resource_fifo 3 48090 _002339_hash NULL
83121 +_002340_hash c4iw_init_resource_fifo_random 3 25547 _002340_hash NULL
83122 +_002341_hash card_send_command 3 40757 _002341_hash NULL
83123 +_002342_hash chd_dec_fetch_cdata 3 50926 _002342_hash NULL
83124 +_002343_hash crystalhd_create_dio_pool 2 3427 _002343_hash NULL
83125 +_002344_hash crystalhd_user_data 3 18407 _002344_hash NULL
83126 +_002345_hash cxio_init_resource_fifo 3 28764 _002345_hash NULL
83127 +_002346_hash cxio_init_resource_fifo_random 3 47151 _002346_hash NULL
83128 +_002347_hash do_pages_stat 2 4437 _002347_hash NULL
83129 +_002348_hash do_read_log_to_user 4 3236 _002348_hash NULL
83130 +_002349_hash do_write_log_from_user 3 39362 _002349_hash NULL
83131 +_002350_hash dt3155_read 3 59226 _002350_hash NULL
83132 +_002351_hash easycap_alsa_vmalloc 2 14426 _002351_hash NULL
83133 +_002352_hash evm_read_key 3 54674 _002352_hash NULL
83134 +_002353_hash evm_write_key 3 27715 _002353_hash NULL
83135 +_002354_hash fir16_create 3 5574 _002354_hash NULL
83136 +_002355_hash iio_allocate_device 1 18821 _002355_hash NULL
83137 +_002356_hash __iio_allocate_kfifo 2-3 55738 _002356_hash NULL
83138 +_002358_hash __iio_allocate_sw_ring_buffer 3 4843 _002358_hash NULL
83139 +_002359_hash iio_debugfs_read_reg 3 60908 _002359_hash NULL
83140 +_002360_hash iio_debugfs_write_reg 3 22742 _002360_hash NULL
83141 +_002361_hash iio_event_chrdev_read 3 54757 _002361_hash NULL
83142 +_002362_hash iio_read_first_n_kfifo 2 57910 _002362_hash NULL
83143 +_002363_hash iio_read_first_n_sw_rb 2 51911 _002363_hash NULL
83144 +_002364_hash ioapic_setup_resources 1 35255 _002364_hash NULL
83145 +_002365_hash keymap_store 4 45406 _002365_hash NULL
83146 +_002366_hash kzalloc_node 1 24352 _002366_hash NULL
83147 +_002367_hash line6_alloc_sysex_buffer 4 28225 _002367_hash NULL
83148 +_002368_hash line6_dumpreq_initbuf 3 53123 _002368_hash NULL
83149 +_002369_hash line6_midibuf_init 2 52425 _002369_hash NULL
83150 +_002370_hash lirc_write 3 20604 _002370_hash NULL
83151 +_002371_hash _malloc 1 54077 _002371_hash NULL
83152 +_002372_hash mei_read 3 6507 _002372_hash NULL
83153 +_002373_hash mei_write 3 4005 _002373_hash NULL
83154 +_002374_hash mempool_create_node 1 44715 _002374_hash NULL
83155 +_002375_hash msg_set 3 51725 _002375_hash NULL
83156 +_002376_hash newpart 6 47485 _002376_hash NULL
83157 +_002377_hash OS_kmalloc 1 36909 _002377_hash NULL
83158 +_002378_hash pcpu_alloc_bootmem 2 62074 _002378_hash NULL
83159 +_002379_hash pcpu_get_vm_areas 3 50085 _002379_hash NULL
83160 +_002380_hash resource_from_user 3 30341 _002380_hash NULL
83161 +_002381_hash sca3000_read_data 4 57064 _002381_hash NULL
83162 +_002382_hash sca3000_read_first_n_hw_rb 2 11479 _002382_hash NULL
83163 +_002383_hash send_midi_async 3 57463 _002383_hash NULL
83164 +_002384_hash sep_create_dcb_dmatables_context 6 37551 _002384_hash NULL
83165 +_002385_hash sep_create_dcb_dmatables_context_kernel 6 49728 _002385_hash NULL
83166 +_002386_hash sep_create_msgarea_context 4 33829 _002386_hash NULL
83167 +_002387_hash sep_lli_table_secure_dma 2-3 64042 _002387_hash NULL
83168 +_002389_hash sep_lock_user_pages 2-3 57470 _002389_hash &_002154_hash
83169 +_002391_hash sep_prepare_input_output_dma_table_in_dcb 4-5 63087 _002391_hash NULL
83170 +_002393_hash sep_read 3 17161 _002393_hash NULL
83171 +_002394_hash TransmitTcb 4 12989 _002394_hash NULL
83172 +_002395_hash ValidateDSDParamsChecksum 3 63654 _002395_hash NULL
83173 +_002396_hash Wb35Reg_BurstWrite 4 62327 _002396_hash NULL
83174 +_002397_hash __alloc_bootmem_low_node 2 25726 _002397_hash &_001499_hash
83175 +_002398_hash __alloc_bootmem_node 2 1992 _002398_hash NULL
83176 +_002399_hash alloc_irq_cpu_rmap 1 28459 _002399_hash NULL
83177 +_002400_hash alloc_ring 2-4 18278 _002400_hash NULL
83178 +_002402_hash c4iw_init_resource 2-3 30393 _002402_hash NULL
83179 +_002404_hash cxio_hal_init_resource 2-7-6 29771 _002404_hash &_000284_hash
83180 +_002407_hash cxio_hal_init_rhdl_resource 1 25104 _002407_hash NULL
83181 +_002408_hash disk_expand_part_tbl 2 30561 _002408_hash NULL
83182 +_002409_hash InterfaceTransmitPacket 3 42058 _002409_hash NULL
83183 +_002410_hash line6_dumpreq_init 3 34473 _002410_hash NULL
83184 +_002411_hash mempool_create 1 29437 _002411_hash NULL
83185 +_002412_hash pcpu_fc_alloc 2 11818 _002412_hash NULL
83186 +_002413_hash pod_alloc_sysex_buffer 3 31651 _002413_hash NULL
83187 +_002414_hash r8712_usbctrl_vendorreq 6 48489 _002414_hash NULL
83188 +_002415_hash r871x_set_wpa_ie 3 7000 _002415_hash NULL
83189 +_002416_hash sys_move_pages 2 42626 _002416_hash NULL
83190 +_002417_hash variax_alloc_sysex_buffer 3 15237 _002417_hash NULL
83191 +_002418_hash vme_user_write 3 15587 _002418_hash NULL
83192 +_002419_hash add_partition 2 55588 _002419_hash NULL
83193 +_002420_hash __alloc_bootmem_node_high 2 65076 _002420_hash NULL
83194 +_002421_hash ceph_msgpool_init 3 33312 _002421_hash NULL
83195 +_002423_hash mempool_create_kmalloc_pool 1 41650 _002423_hash NULL
83196 +_002424_hash mempool_create_page_pool 1 30189 _002424_hash NULL
83197 +_002425_hash mempool_create_slab_pool 1 62907 _002425_hash NULL
83198 +_002426_hash variax_set_raw2 4 32374 _002426_hash NULL
83199 +_002427_hash bioset_create 1 5580 _002427_hash NULL
83200 +_002428_hash bioset_integrity_create 2 62708 _002428_hash NULL
83201 +_002429_hash biovec_create_pools 2 9575 _002429_hash NULL
83202 +_002430_hash i2o_pool_alloc 4 55485 _002430_hash NULL
83203 +_002431_hash prison_create 1 43623 _002431_hash NULL
83204 +_002432_hash unlink_simple 3 47506 _002432_hash NULL
83205 +_002433_hash alloc_ieee80211 1 20063 _002433_hash NULL
83206 +_002434_hash alloc_ieee80211_rsl 1 34564 _002434_hash NULL
83207 +_002435_hash alloc_page_cgroup 1 2919 _002435_hash NULL
83208 +_002436_hash alloc_private 2 22399 _002436_hash &_002326_hash
83209 +_002437_hash alloc_rtllib 1 51136 _002437_hash NULL
83210 +_002438_hash alloc_rx_desc_ring 2 18016 _002438_hash NULL
83211 +_002439_hash alloc_subdevices 2 43300 _002439_hash NULL
83212 +_002440_hash atomic_counters_read 3 48827 _002440_hash NULL
83213 +_002441_hash atomic_stats_read 3 36228 _002441_hash NULL
83214 +_002442_hash capabilities_read 3 58457 _002442_hash NULL
83215 +_002443_hash comedi_read 3 13199 _002443_hash NULL
83216 +_002444_hash comedi_write 3 47926 _002444_hash NULL
83217 +_002445_hash compat_do_arpt_set_ctl 4 12184 _002445_hash NULL
83218 +_002446_hash compat_do_ip6t_set_ctl 4 3184 _002446_hash NULL
83219 +_002447_hash compat_do_ipt_set_ctl 4 58466 _002447_hash &_001852_hash
83220 +_002448_hash compat_filldir 3 32999 _002448_hash NULL
83221 +_002449_hash compat_filldir64 3 35354 _002449_hash NULL
83222 +_002450_hash compat_fillonedir 3 15620 _002450_hash NULL
83223 +_002451_hash compat_rw_copy_check_uvector 3 25242 _002451_hash NULL
83224 +_002452_hash compat_sock_setsockopt 5 23 _002452_hash NULL
83225 +_002453_hash compat_sys_kexec_load 2 35674 _002453_hash NULL
83226 +_002454_hash compat_sys_keyctl 4 9639 _002454_hash NULL
83227 +_002455_hash compat_sys_move_pages 2 5861 _002455_hash NULL
83228 +_002456_hash compat_sys_mq_timedsend 3 31060 _002456_hash NULL
83229 +_002457_hash compat_sys_msgrcv 2 7482 _002457_hash NULL
83230 +_002458_hash compat_sys_msgsnd 2 10738 _002458_hash NULL
83231 +_002459_hash compat_sys_semtimedop 3 3606 _002459_hash NULL
83232 +_002460_hash __copy_in_user 3 34790 _002460_hash NULL
83233 +_002461_hash copy_in_user 3 57502 _002461_hash NULL
83234 +_002462_hash dev_counters_read 3 19216 _002462_hash NULL
83235 +_002463_hash dev_names_read 3 38509 _002463_hash NULL
83236 +_002464_hash do_arpt_set_ctl 4 51053 _002464_hash NULL
83237 +_002465_hash do_ip6t_set_ctl 4 60040 _002465_hash NULL
83238 +_002466_hash do_ipt_set_ctl 4 56238 _002466_hash NULL
83239 +_002467_hash drbd_bm_resize 2 20522 _002467_hash NULL
83240 +_002468_hash driver_names_read 3 60399 _002468_hash NULL
83241 +_002469_hash driver_stats_read 3 8944 _002469_hash NULL
83242 +_002470_hash __earlyonly_bootmem_alloc 2 23824 _002470_hash NULL
83243 +_002471_hash evtchn_read 3 3569 _002471_hash NULL
83244 +_002472_hash ext_sd_execute_read_data 9 48589 _002472_hash NULL
83245 +_002473_hash ext_sd_execute_write_data 9 8175 _002473_hash NULL
83246 +_002474_hash fat_compat_ioctl_filldir 3 36328 _002474_hash NULL
83247 +_002475_hash firmwareUpload 3 32794 _002475_hash NULL
83248 +_002476_hash flash_read 3 57843 _002476_hash NULL
83249 +_002477_hash flash_write 3 62354 _002477_hash NULL
83250 +_002478_hash gather_array 3 56641 _002478_hash NULL
83251 +_002479_hash ghash_async_setkey 3 60001 _002479_hash NULL
83252 +_002480_hash gntdev_alloc_map 2 35145 _002480_hash NULL
83253 +_002481_hash gnttab_map 2 56439 _002481_hash NULL
83254 +_002482_hash gru_alloc_gts 2-3 60056 _002482_hash NULL
83255 +_002484_hash handle_eviocgbit 3 44193 _002484_hash NULL
83256 +_002485_hash hid_parse_report 3 51737 _002485_hash NULL
83257 +_002486_hash ieee80211_alloc_txb 1 52477 _002486_hash NULL
83258 +_002487_hash ieee80211_wx_set_gen_ie 3 51399 _002487_hash NULL
83259 +_002488_hash ieee80211_wx_set_gen_ie_rsl 3 3521 _002488_hash NULL
83260 +_002489_hash init_cdev 1 8274 _002489_hash NULL
83261 +_002490_hash init_per_cpu 1 17880 _002490_hash NULL
83262 +_002491_hash ipath_create_cq 2 45586 _002491_hash NULL
83263 +_002492_hash ipath_get_base_info 3 7043 _002492_hash NULL
83264 +_002493_hash ipath_init_qp_table 2 25167 _002493_hash NULL
83265 +_002494_hash ipath_resize_cq 2 712 _002494_hash NULL
83266 +_002495_hash ni_gpct_device_construct 5 610 _002495_hash NULL
83267 +_002496_hash options_write 3 47243 _002496_hash NULL
83268 +_002497_hash portcntrs_1_read 3 47253 _002497_hash NULL
83269 +_002498_hash portcntrs_2_read 3 56586 _002498_hash NULL
83270 +_002499_hash portnames_read 3 41958 _002499_hash NULL
83271 +_002500_hash ptc_proc_write 3 12076 _002500_hash NULL
83272 +_002501_hash put_cmsg_compat 4 35937 _002501_hash NULL
83273 +_002502_hash qib_alloc_devdata 2 51819 _002502_hash NULL
83274 +_002503_hash qib_alloc_fast_reg_page_list 2 10507 _002503_hash NULL
83275 +_002504_hash qib_cdev_init 1 34778 _002504_hash NULL
83276 +_002505_hash qib_create_cq 2 27497 _002505_hash NULL
83277 +_002506_hash qib_diag_write 3 62133 _002506_hash NULL
83278 +_002507_hash qib_get_base_info 3 11369 _002507_hash NULL
83279 +_002508_hash qib_resize_cq 2 53090 _002508_hash NULL
83280 +_002509_hash qsfp_1_read 3 21915 _002509_hash NULL
83281 +_002510_hash qsfp_2_read 3 31491 _002510_hash NULL
83282 +_002511_hash queue_reply 3 22416 _002511_hash NULL
83283 +_002512_hash Realloc 2 34961 _002512_hash NULL
83284 +_002513_hash rfc4106_set_key 3 54519 _002513_hash NULL
83285 +_002514_hash rtllib_alloc_txb 1 21687 _002514_hash NULL
83286 +_002515_hash rtllib_wx_set_gen_ie 3 59808 _002515_hash NULL
83287 +_002516_hash rts51x_transfer_data_partial 6 5735 _002516_hash NULL
83288 +_002517_hash sparse_early_usemaps_alloc_node 4 9269 _002517_hash NULL
83289 +_002518_hash split 2 11691 _002518_hash NULL
83290 +_002519_hash stats_read_ul 3 32751 _002519_hash NULL
83291 +_002520_hash store_debug_level 3 35652 _002520_hash NULL
83292 +_002521_hash sys32_ipc 3 7238 _002521_hash NULL
83293 +_002522_hash sys32_rt_sigpending 2 25814 _002522_hash NULL
83294 +_002523_hash tunables_read 3 36385 _002523_hash NULL
83295 +_002524_hash tunables_write 3 59563 _002524_hash NULL
83296 +_002525_hash u32_array_read 3 2219 _002525_hash NULL
83297 +_002526_hash usb_buffer_alloc 2 36276 _002526_hash NULL
83298 +_002527_hash xenbus_file_write 3 6282 _002527_hash NULL
83299 +_002528_hash xpc_kmalloc_cacheline_aligned 1 42895 _002528_hash NULL
83300 +_002529_hash xpc_kzalloc_cacheline_aligned 1 65433 _002529_hash NULL
83301 +_002530_hash xsd_read 3 15653 _002530_hash NULL
83302 +_002531_hash compat_do_readv_writev 4 49102 _002531_hash NULL
83303 +_002532_hash compat_keyctl_instantiate_key_iov 3 57431 _002532_hash NULL
83304 +_002533_hash compat_process_vm_rw 3-5 22254 _002533_hash NULL
83305 +_002535_hash compat_sys_setsockopt 5 3326 _002535_hash NULL
83306 +_002536_hash ipath_cdev_init 1 37752 _002536_hash NULL
83307 +_002537_hash ms_read_multiple_pages 4-5 8052 _002537_hash NULL
83308 +_002539_hash ms_write_multiple_pages 5-6 10362 _002539_hash NULL
83309 +_002541_hash sparse_mem_maps_populate_node 4 12669 _002541_hash &_002004_hash
83310 +_002542_hash vmemmap_alloc_block 1 43245 _002542_hash NULL
83311 +_002543_hash xd_read_multiple_pages 4-5 11422 _002543_hash NULL
83312 +_002545_hash xd_write_multiple_pages 5-6 53633 _002545_hash NULL
83313 +_002546_hash compat_readv 3 30273 _002546_hash NULL
83314 +_002547_hash compat_sys_process_vm_readv 3-5 15374 _002547_hash NULL
83315 +_002549_hash compat_sys_process_vm_writev 3-5 41194 _002549_hash NULL
83316 +_002551_hash compat_writev 3 60063 _002551_hash NULL
83317 +_002552_hash ms_rw_multi_sector 4 7459 _002552_hash NULL
83318 +_002553_hash sparse_early_mem_maps_alloc_node 4 36971 _002553_hash NULL
83319 +_002554_hash vmemmap_alloc_block_buf 1 61126 _002554_hash NULL
83320 +_002555_hash xd_rw 4 49020 _002555_hash NULL
83321 +_002556_hash compat_sys_preadv64 3 24283 _002556_hash NULL
83322 +_002557_hash compat_sys_pwritev64 3 51151 _002557_hash NULL
83323 +_002558_hash compat_sys_readv 3 20911 _002558_hash NULL
83324 +_002559_hash compat_sys_writev 3 5784 _002559_hash NULL
83325 +_002560_hash ms_rw 4 17220 _002560_hash NULL
83326 +_002561_hash compat_sys_preadv 3 583 _002561_hash NULL
83327 +_002562_hash compat_sys_pwritev 3 17886 _002562_hash NULL
83328 +_002563_hash alloc_apertures 1 56561 _002563_hash NULL
83329 +_002564_hash bin_uuid 3 28999 _002564_hash NULL
83330 +_002565_hash __copy_from_user_inatomic_nocache 3 49921 _002565_hash NULL
83331 +_002566_hash do_dmabuf_dirty_sou 7 3017 _002566_hash NULL
83332 +_002567_hash do_surface_dirty_sou 7 39678 _002567_hash NULL
83333 +_002568_hash drm_agp_bind_pages 3 56748 _002568_hash NULL
83334 +_002569_hash drm_calloc_large 1-2 65421 _002569_hash NULL
83335 +_002571_hash drm_fb_helper_init 3-4 19044 _002571_hash NULL
83336 +_002573_hash drm_ht_create 2 18853 _002573_hash NULL
83337 +_002574_hash drm_malloc_ab 1-2 16831 _002574_hash NULL
83338 +_002576_hash drm_mode_crtc_set_gamma_size 2 31881 _002576_hash NULL
83339 +_002577_hash drm_plane_init 6 28731 _002577_hash NULL
83340 +_002578_hash drm_property_create 4 51239 _002578_hash NULL
83341 +_002579_hash drm_property_create_blob 2 7414 _002579_hash NULL
83342 +_002580_hash drm_vblank_init 2 11362 _002580_hash NULL
83343 +_002581_hash drm_vmalloc_dma 1 14550 _002581_hash NULL
83344 +_002582_hash fb_alloc_cmap_gfp 2 20792 _002582_hash NULL
83345 +_002583_hash fbcon_prepare_logo 5 6246 _002583_hash NULL
83346 +_002584_hash fb_read 3 33506 _002584_hash NULL
83347 +_002585_hash fb_write 3 46924 _002585_hash NULL
83348 +_002586_hash framebuffer_alloc 1 59145 _002586_hash NULL
83349 +_002587_hash i915_cache_sharing_read 3 24775 _002587_hash NULL
83350 +_002588_hash i915_cache_sharing_write 3 57961 _002588_hash NULL
83351 +_002589_hash i915_max_freq_read 3 20581 _002589_hash NULL
83352 +_002590_hash i915_max_freq_write 3 11350 _002590_hash NULL
83353 +_002591_hash i915_wedged_read 3 35474 _002591_hash NULL
83354 +_002592_hash i915_wedged_write 3 47771 _002592_hash NULL
83355 +_002593_hash p9_client_read 5 19750 _002593_hash NULL
83356 +_002594_hash probe_kernel_write 3 17481 _002594_hash NULL
83357 +_002595_hash sched_feat_write 3 55202 _002595_hash NULL
83358 +_002596_hash sd_alloc_ctl_entry 1 29708 _002596_hash NULL
83359 +_002597_hash tstats_write 3 60432 _002597_hash &_000009_hash
83360 +_002598_hash ttm_bo_fbdev_io 4 9805 _002598_hash NULL
83361 +_002599_hash ttm_bo_io 5 47000 _002599_hash NULL
83362 +_002600_hash ttm_dma_page_pool_free 2 34135 _002600_hash NULL
83363 +_002601_hash ttm_page_pool_free 2 61661 _002601_hash NULL
83364 +_002602_hash vmw_execbuf_process 5 22885 _002602_hash NULL
83365 +_002603_hash vmw_fifo_reserve 2 12141 _002603_hash NULL
83366 +_002604_hash vmw_kms_present 9 38130 _002604_hash NULL
83367 +_002605_hash vmw_kms_readback 6 5727 _002605_hash NULL
83368 +_002606_hash do_dmabuf_dirty_ldu 6 52241 _002606_hash NULL
83369 +_002607_hash drm_mode_create_tv_properties 2 23122 _002607_hash NULL
83370 +_002608_hash drm_property_create_enum 5 29201 _002608_hash NULL
83371 +_002609_hash fast_user_write 5 20494 _002609_hash NULL
83372 +_002610_hash fb_alloc_cmap 2 6554 _002610_hash NULL
83373 +_002611_hash i915_gem_execbuffer_relocate_slow 7 25355 _002611_hash NULL
83374 +_002612_hash kgdb_hex2mem 3 24755 _002612_hash NULL
83375 +_002613_hash ttm_object_device_init 2 10321 _002613_hash NULL
83376 +_002614_hash ttm_object_file_init 2 27804 _002614_hash NULL
83377 +_002615_hash vmw_cursor_update_image 3-4 16332 _002615_hash NULL
83378 +_002617_hash vmw_gmr2_bind 3 21305 _002617_hash NULL
83379 +_002618_hash vmw_cursor_update_dmabuf 3-4 32045 _002618_hash NULL
83380 +_002620_hash vmw_gmr_bind 3 44130 _002620_hash NULL
83381 +_002621_hash vmw_du_crtc_cursor_set 4-5 28479 _002621_hash NULL
83382 +_002622_hash __module_alloc 1 50004 _002622_hash NULL
83383 +_002623_hash module_alloc_update_bounds_rw 1 63233 _002623_hash NULL
83384 +_002624_hash module_alloc_update_bounds_rx 1 58634 _002624_hash NULL
83385 +_002625_hash acpi_system_write_alarm 3 40205 _002625_hash NULL
83386 +_002626_hash create_table 2 16213 _002626_hash NULL
83387 +_002627_hash mem_read 3 57631 _002627_hash NULL
83388 +_002628_hash mem_write 3 22232 _002628_hash NULL
83389 +_002629_hash proc_fault_inject_read 3 36802 _002629_hash NULL
83390 +_002630_hash proc_fault_inject_write 3 21058 _002630_hash NULL
83391 +_002631_hash v9fs_fid_readn 4 60544 _002631_hash NULL
83392 +_002632_hash v9fs_file_read 3 40858 _002632_hash NULL
83393 +_002633_hash __devres_alloc 2 25598 _002633_hash NULL
83394 +_002634_hash acl_alloc 1 35979 _002634_hash NULL
83395 +_002635_hash acl_alloc_stack_init 1 60630 _002635_hash NULL
83396 +_002636_hash acl_alloc_num 1-2 60778 _002636_hash NULL
83397 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
83398 new file mode 100644
83399 index 0000000..cc96254
83400 --- /dev/null
83401 +++ b/tools/gcc/size_overflow_plugin.c
83402 @@ -0,0 +1,1204 @@
83403 +/*
83404 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
83405 + * Licensed under the GPL v2, or (at your option) v3
83406 + *
83407 + * Homepage:
83408 + * http://www.grsecurity.net/~ephox/overflow_plugin/
83409 + *
83410 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
83411 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
83412 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
83413 + *
83414 + * Usage:
83415 + * $ 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
83416 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
83417 + */
83418 +
83419 +#include "gcc-plugin.h"
83420 +#include "config.h"
83421 +#include "system.h"
83422 +#include "coretypes.h"
83423 +#include "tree.h"
83424 +#include "tree-pass.h"
83425 +#include "intl.h"
83426 +#include "plugin-version.h"
83427 +#include "tm.h"
83428 +#include "toplev.h"
83429 +#include "function.h"
83430 +#include "tree-flow.h"
83431 +#include "plugin.h"
83432 +#include "gimple.h"
83433 +#include "c-common.h"
83434 +#include "diagnostic.h"
83435 +#include "cfgloop.h"
83436 +
83437 +struct size_overflow_hash {
83438 + struct size_overflow_hash *next;
83439 + const char *name;
83440 + unsigned int param;
83441 +};
83442 +
83443 +#include "size_overflow_hash.h"
83444 +
83445 +#define __unused __attribute__((__unused__))
83446 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
83447 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
83448 +#define BEFORE_STMT true
83449 +#define AFTER_STMT false
83450 +#define CREATE_NEW_VAR NULL_TREE
83451 +#define CODES_LIMIT 32
83452 +#define MAX_PARAM 10
83453 +
83454 +#if BUILDING_GCC_VERSION == 4005
83455 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
83456 +#endif
83457 +
83458 +int plugin_is_GPL_compatible;
83459 +void debug_gimple_stmt(gimple gs);
83460 +
83461 +static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var);
83462 +static tree signed_size_overflow_type;
83463 +static tree unsigned_size_overflow_type;
83464 +static tree report_size_overflow_decl;
83465 +static tree const_char_ptr_type_node;
83466 +static unsigned int handle_function(void);
83467 +
83468 +static struct plugin_info size_overflow_plugin_info = {
83469 + .version = "20120618beta",
83470 + .help = "no-size-overflow\tturn off size overflow checking\n",
83471 +};
83472 +
83473 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
83474 +{
83475 + unsigned int arg_count = type_num_arguments(*node);
83476 +
83477 + for (; args; args = TREE_CHAIN(args)) {
83478 + tree position = TREE_VALUE(args);
83479 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
83480 + error("handle_size_overflow_attribute: overflow parameter outside range.");
83481 + *no_add_attrs = true;
83482 + }
83483 + }
83484 + return NULL_TREE;
83485 +}
83486 +
83487 +static struct attribute_spec no_size_overflow_attr = {
83488 + .name = "size_overflow",
83489 + .min_length = 1,
83490 + .max_length = -1,
83491 + .decl_required = false,
83492 + .type_required = true,
83493 + .function_type_required = true,
83494 + .handler = handle_size_overflow_attribute,
83495 +#if BUILDING_GCC_VERSION >= 4007
83496 + .affects_type_identity = false
83497 +#endif
83498 +};
83499 +
83500 +static void register_attributes(void __unused *event_data, void __unused *data)
83501 +{
83502 + register_attribute(&no_size_overflow_attr);
83503 +}
83504 +
83505 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
83506 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
83507 +{
83508 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
83509 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
83510 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
83511 +
83512 + const unsigned int m = 0x57559429;
83513 + const unsigned int n = 0x5052acdb;
83514 + const unsigned int *key4 = (const unsigned int *)key;
83515 + unsigned int h = len;
83516 + unsigned int k = len + seed + n;
83517 + unsigned long long p;
83518 +
83519 + while (len >= 8) {
83520 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
83521 + len -= 8;
83522 + }
83523 + if (len >= 4) {
83524 + cwmixb(key4[0]) key4 += 1;
83525 + len -= 4;
83526 + }
83527 + if (len)
83528 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
83529 + cwmixb(h ^ (k + n));
83530 + return k ^ h;
83531 +
83532 +#undef cwfold
83533 +#undef cwmixa
83534 +#undef cwmixb
83535 +}
83536 +
83537 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
83538 +{
83539 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
83540 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
83541 + return fn ^ codes;
83542 +}
83543 +
83544 +static inline tree get_original_function_decl(tree fndecl)
83545 +{
83546 + if (DECL_ABSTRACT_ORIGIN(fndecl))
83547 + return DECL_ABSTRACT_ORIGIN(fndecl);
83548 + return fndecl;
83549 +}
83550 +
83551 +static inline gimple get_def_stmt(tree node)
83552 +{
83553 + gcc_assert(TREE_CODE(node) == SSA_NAME);
83554 + return SSA_NAME_DEF_STMT(node);
83555 +}
83556 +
83557 +static unsigned char get_tree_code(tree type)
83558 +{
83559 + switch (TREE_CODE(type)) {
83560 + case ARRAY_TYPE:
83561 + return 0;
83562 + case BOOLEAN_TYPE:
83563 + return 1;
83564 + case ENUMERAL_TYPE:
83565 + return 2;
83566 + case FUNCTION_TYPE:
83567 + return 3;
83568 + case INTEGER_TYPE:
83569 + return 4;
83570 + case POINTER_TYPE:
83571 + return 5;
83572 + case RECORD_TYPE:
83573 + return 6;
83574 + case UNION_TYPE:
83575 + return 7;
83576 + case VOID_TYPE:
83577 + return 8;
83578 + case REAL_TYPE:
83579 + return 9;
83580 + case VECTOR_TYPE:
83581 + return 10;
83582 + case REFERENCE_TYPE:
83583 + return 11;
83584 + default:
83585 + debug_tree(type);
83586 + gcc_unreachable();
83587 + }
83588 +}
83589 +
83590 +static size_t add_type_codes(tree type, unsigned char *tree_codes, size_t len)
83591 +{
83592 + gcc_assert(type != NULL_TREE);
83593 +
83594 + while (type && len < CODES_LIMIT) {
83595 + tree_codes[len] = get_tree_code(type);
83596 + len++;
83597 + type = TREE_TYPE(type);
83598 + }
83599 + return len;
83600 +}
83601 +
83602 +static unsigned int get_function_decl(tree fndecl, unsigned char *tree_codes)
83603 +{
83604 + tree arg, result, type = TREE_TYPE(fndecl);
83605 + enum tree_code code = TREE_CODE(type);
83606 + size_t len = 0;
83607 +
83608 + gcc_assert(code == FUNCTION_TYPE);
83609 +
83610 + arg = TYPE_ARG_TYPES(type);
83611 + // skip builtins __builtin_constant_p
83612 + if (!arg && DECL_BUILT_IN(fndecl))
83613 + return 0;
83614 + gcc_assert(arg != NULL_TREE);
83615 +
83616 + if (TREE_CODE_CLASS(code) == tcc_type)
83617 + result = type;
83618 + else
83619 + result = DECL_RESULT(fndecl);
83620 +
83621 + gcc_assert(result != NULL_TREE);
83622 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
83623 +
83624 + while (arg && len < CODES_LIMIT) {
83625 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
83626 + arg = TREE_CHAIN(arg);
83627 + }
83628 +
83629 + gcc_assert(len != 0);
83630 + return len;
83631 +}
83632 +
83633 +static struct size_overflow_hash *get_function_hash(tree fndecl)
83634 +{
83635 + unsigned int hash;
83636 + struct size_overflow_hash *entry;
83637 + unsigned char tree_codes[CODES_LIMIT];
83638 + size_t len;
83639 + const char *func_name = NAME(fndecl);
83640 +
83641 + len = get_function_decl(fndecl, tree_codes);
83642 + if (len == 0)
83643 + return NULL;
83644 +
83645 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
83646 +
83647 + entry = size_overflow_hash[hash];
83648 + while (entry) {
83649 + if (!strcmp(entry->name, func_name))
83650 + return entry;
83651 + entry = entry->next;
83652 + }
83653 +
83654 + return NULL;
83655 +}
83656 +
83657 +static void check_arg_type(tree var)
83658 +{
83659 + tree type = TREE_TYPE(var);
83660 + enum tree_code code = TREE_CODE(type);
83661 +
83662 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
83663 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
83664 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
83665 +}
83666 +
83667 +static int find_arg_number(tree arg, tree func)
83668 +{
83669 + tree var;
83670 + bool match = false;
83671 + unsigned int argnum = 1;
83672 +
83673 + if (TREE_CODE(arg) == SSA_NAME)
83674 + arg = SSA_NAME_VAR(arg);
83675 +
83676 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
83677 + if (strcmp(NAME(arg), NAME(var))) {
83678 + argnum++;
83679 + continue;
83680 + }
83681 + check_arg_type(var);
83682 +
83683 + match = true;
83684 + break;
83685 + }
83686 + if (!match) {
83687 + warning(0, "find_arg_number: cannot find the %s argument in %s", NAME(arg), NAME(func));
83688 + return 0;
83689 + }
83690 + return argnum;
83691 +}
83692 +
83693 +static void print_missing_msg(tree func, unsigned int argnum)
83694 +{
83695 + unsigned int new_hash;
83696 + size_t len;
83697 + unsigned char tree_codes[CODES_LIMIT];
83698 + location_t loc = DECL_SOURCE_LOCATION(func);
83699 + const char *curfunc = NAME(func);
83700 +
83701 + len = get_function_decl(func, tree_codes);
83702 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
83703 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%d+%u+", curfunc, curfunc, argnum, new_hash);
83704 +}
83705 +
83706 +static void check_missing_attribute(tree arg)
83707 +{
83708 + tree type, func = get_original_function_decl(current_function_decl);
83709 + unsigned int argnum;
83710 + struct size_overflow_hash *hash;
83711 +
83712 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
83713 +
83714 + type = TREE_TYPE(arg);
83715 + // skip function pointers
83716 + if (TREE_CODE(type) == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == FUNCTION_TYPE)
83717 + return;
83718 +
83719 + if (lookup_attribute("size_overflow", TYPE_ATTRIBUTES(TREE_TYPE(func))))
83720 + return;
83721 +
83722 + argnum = find_arg_number(arg, func);
83723 + if (argnum == 0)
83724 + return;
83725 +
83726 + hash = get_function_hash(func);
83727 + if (!hash || !(hash->param & (1U << argnum)))
83728 + print_missing_msg(func, argnum);
83729 +}
83730 +
83731 +static tree create_new_var(tree type)
83732 +{
83733 + tree new_var = create_tmp_var(type, "cicus");
83734 +
83735 + add_referenced_var(new_var);
83736 + mark_sym_for_renaming(new_var);
83737 + return new_var;
83738 +}
83739 +
83740 +static bool is_bool(tree node)
83741 +{
83742 + tree type;
83743 +
83744 + if (node == NULL_TREE)
83745 + return false;
83746 +
83747 + type = TREE_TYPE(node);
83748 + if (!INTEGRAL_TYPE_P(type))
83749 + return false;
83750 + if (TREE_CODE(type) == BOOLEAN_TYPE)
83751 + return true;
83752 + if (TYPE_PRECISION(type) == 1)
83753 + return true;
83754 + return false;
83755 +}
83756 +
83757 +static tree cast_a_tree(tree type, tree var)
83758 +{
83759 + gcc_assert(type != NULL_TREE && var != NULL_TREE);
83760 + gcc_assert(fold_convertible_p(type, var));
83761 +
83762 + return fold_convert(type, var);
83763 +}
83764 +
83765 +static tree signed_cast(tree var)
83766 +{
83767 + return cast_a_tree(signed_size_overflow_type, var);
83768 +}
83769 +
83770 +static gimple build_cast_stmt(tree type, tree var, tree new_var, location_t loc)
83771 +{
83772 + gimple assign;
83773 +
83774 + if (new_var == CREATE_NEW_VAR)
83775 + new_var = create_new_var(type);
83776 +
83777 + assign = gimple_build_assign(new_var, cast_a_tree(type, var));
83778 + gimple_set_location(assign, loc);
83779 + gimple_set_lhs(assign, make_ssa_name(new_var, assign));
83780 +
83781 + return assign;
83782 +}
83783 +
83784 +static tree create_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree rhs1, bool before)
83785 +{
83786 + tree oldstmt_rhs1;
83787 + enum tree_code code;
83788 + gimple stmt;
83789 + gimple_stmt_iterator gsi;
83790 +
83791 + if (!*potentionally_overflowed)
83792 + return NULL_TREE;
83793 +
83794 + if (rhs1 == NULL_TREE) {
83795 + debug_gimple_stmt(oldstmt);
83796 + error("create_assign: rhs1 is NULL_TREE");
83797 + gcc_unreachable();
83798 + }
83799 +
83800 + oldstmt_rhs1 = gimple_assign_rhs1(oldstmt);
83801 + code = TREE_CODE(oldstmt_rhs1);
83802 + if (code == PARM_DECL || (code == SSA_NAME && gimple_code(get_def_stmt(oldstmt_rhs1)) == GIMPLE_NOP))
83803 + check_missing_attribute(oldstmt_rhs1);
83804 +
83805 + stmt = build_cast_stmt(signed_size_overflow_type, rhs1, CREATE_NEW_VAR, gimple_location(oldstmt));
83806 + gsi = gsi_for_stmt(oldstmt);
83807 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
83808 + basic_block next_bb, cur_bb;
83809 + edge e;
83810 +
83811 + gcc_assert(before == false);
83812 + gcc_assert(stmt_can_throw_internal(oldstmt));
83813 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
83814 + gcc_assert(!gsi_end_p(gsi));
83815 +
83816 + cur_bb = gimple_bb(oldstmt);
83817 + next_bb = cur_bb->next_bb;
83818 + e = find_edge(cur_bb, next_bb);
83819 + gcc_assert(e != NULL);
83820 + gcc_assert(e->flags & EDGE_FALLTHRU);
83821 +
83822 + gsi = gsi_after_labels(next_bb);
83823 + gcc_assert(!gsi_end_p(gsi));
83824 + before = true;
83825 + }
83826 + if (before)
83827 + gsi_insert_before(&gsi, stmt, GSI_NEW_STMT);
83828 + else
83829 + gsi_insert_after(&gsi, stmt, GSI_NEW_STMT);
83830 + update_stmt(stmt);
83831 + pointer_set_insert(visited, oldstmt);
83832 + return gimple_get_lhs(stmt);
83833 +}
83834 +
83835 +static tree dup_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree rhs1, tree rhs2, tree __unused rhs3)
83836 +{
83837 + tree new_var, lhs = gimple_get_lhs(oldstmt);
83838 + gimple stmt;
83839 + gimple_stmt_iterator gsi;
83840 +
83841 + if (!*potentionally_overflowed)
83842 + return NULL_TREE;
83843 +
83844 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
83845 + rhs1 = gimple_assign_rhs1(oldstmt);
83846 + rhs1 = create_assign(visited, potentionally_overflowed, oldstmt, rhs1, BEFORE_STMT);
83847 + }
83848 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
83849 + rhs2 = gimple_assign_rhs2(oldstmt);
83850 + rhs2 = create_assign(visited, potentionally_overflowed, oldstmt, rhs2, BEFORE_STMT);
83851 + }
83852 +
83853 + stmt = gimple_copy(oldstmt);
83854 + gimple_set_location(stmt, gimple_location(oldstmt));
83855 +
83856 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
83857 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
83858 +
83859 + if (is_bool(lhs))
83860 + new_var = SSA_NAME_VAR(lhs);
83861 + else
83862 + new_var = create_new_var(signed_size_overflow_type);
83863 + new_var = make_ssa_name(new_var, stmt);
83864 + gimple_set_lhs(stmt, new_var);
83865 +
83866 + if (rhs1 != NULL_TREE) {
83867 + if (!gimple_assign_cast_p(oldstmt))
83868 + rhs1 = signed_cast(rhs1);
83869 + gimple_assign_set_rhs1(stmt, rhs1);
83870 + }
83871 +
83872 + if (rhs2 != NULL_TREE)
83873 + gimple_assign_set_rhs2(stmt, rhs2);
83874 +#if BUILDING_GCC_VERSION >= 4007
83875 + if (rhs3 != NULL_TREE)
83876 + gimple_assign_set_rhs3(stmt, rhs3);
83877 +#endif
83878 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
83879 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
83880 +
83881 + gsi = gsi_for_stmt(oldstmt);
83882 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
83883 + update_stmt(stmt);
83884 + pointer_set_insert(visited, oldstmt);
83885 + return gimple_get_lhs(stmt);
83886 +}
83887 +
83888 +static gimple overflow_create_phi_node(gimple oldstmt, tree var)
83889 +{
83890 + basic_block bb;
83891 + gimple phi;
83892 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
83893 +
83894 + bb = gsi_bb(gsi);
83895 +
83896 + phi = create_phi_node(var, bb);
83897 + gsi = gsi_last(phi_nodes(bb));
83898 + gsi_remove(&gsi, false);
83899 +
83900 + gsi = gsi_for_stmt(oldstmt);
83901 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
83902 + gimple_set_bb(phi, bb);
83903 + return phi;
83904 +}
83905 +
83906 +static basic_block create_a_first_bb(void)
83907 +{
83908 + basic_block first_bb;
83909 +
83910 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
83911 + if (dom_info_available_p(CDI_DOMINATORS))
83912 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
83913 + return first_bb;
83914 +}
83915 +
83916 +static gimple cast_old_phi_arg(gimple oldstmt, tree arg, tree new_var, unsigned int i)
83917 +{
83918 + basic_block bb;
83919 + gimple newstmt, def_stmt;
83920 + gimple_stmt_iterator gsi;
83921 +
83922 + newstmt = build_cast_stmt(signed_size_overflow_type, arg, new_var, gimple_location(oldstmt));
83923 + if (TREE_CODE(arg) == SSA_NAME) {
83924 + def_stmt = get_def_stmt(arg);
83925 + if (gimple_code(def_stmt) != GIMPLE_NOP) {
83926 + gsi = gsi_for_stmt(def_stmt);
83927 + gsi_insert_after(&gsi, newstmt, GSI_NEW_STMT);
83928 + return newstmt;
83929 + }
83930 + }
83931 +
83932 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
83933 + if (bb->index == 0)
83934 + bb = create_a_first_bb();
83935 + gsi = gsi_after_labels(bb);
83936 + gsi_insert_before(&gsi, newstmt, GSI_NEW_STMT);
83937 + return newstmt;
83938 +}
83939 +
83940 +static gimple handle_new_phi_arg(tree arg, tree new_var, tree new_rhs)
83941 +{
83942 + gimple newstmt;
83943 + gimple_stmt_iterator gsi;
83944 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
83945 + gimple def_newstmt = get_def_stmt(new_rhs);
83946 +
83947 + gsi_insert = gsi_insert_after;
83948 + gsi = gsi_for_stmt(def_newstmt);
83949 +
83950 + switch (gimple_code(get_def_stmt(arg))) {
83951 + case GIMPLE_PHI:
83952 + newstmt = gimple_build_assign(new_var, new_rhs);
83953 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
83954 + gsi_insert = gsi_insert_before;
83955 + break;
83956 + case GIMPLE_ASM:
83957 + case GIMPLE_CALL:
83958 + newstmt = gimple_build_assign(new_var, new_rhs);
83959 + break;
83960 + case GIMPLE_ASSIGN:
83961 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
83962 + break;
83963 + default:
83964 + /* unknown gimple_code (handle_build_new_phi_arg) */
83965 + gcc_unreachable();
83966 + }
83967 +
83968 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
83969 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
83970 + update_stmt(newstmt);
83971 + return newstmt;
83972 +}
83973 +
83974 +static tree build_new_phi_arg(struct pointer_set_t *visited, bool *potentionally_overflowed, tree arg, tree new_var)
83975 +{
83976 + gimple newstmt;
83977 + tree new_rhs;
83978 +
83979 + new_rhs = expand(visited, potentionally_overflowed, arg);
83980 +
83981 + if (new_rhs == NULL_TREE)
83982 + return NULL_TREE;
83983 +
83984 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
83985 + return gimple_get_lhs(newstmt);
83986 +}
83987 +
83988 +static tree build_new_phi(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt)
83989 +{
83990 + gimple phi;
83991 + tree new_var = create_new_var(signed_size_overflow_type);
83992 + unsigned int i, n = gimple_phi_num_args(oldstmt);
83993 +
83994 + pointer_set_insert(visited, oldstmt);
83995 + phi = overflow_create_phi_node(oldstmt, new_var);
83996 + for (i = 0; i < n; i++) {
83997 + tree arg, lhs;
83998 +
83999 + arg = gimple_phi_arg_def(oldstmt, i);
84000 + if (is_gimple_constant(arg))
84001 + arg = signed_cast(arg);
84002 + lhs = build_new_phi_arg(visited, potentionally_overflowed, arg, new_var);
84003 + if (lhs == NULL_TREE)
84004 + lhs = gimple_get_lhs(cast_old_phi_arg(oldstmt, arg, new_var, i));
84005 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
84006 + }
84007 +
84008 + update_stmt(phi);
84009 + return gimple_phi_result(phi);
84010 +}
84011 +
84012 +static tree handle_unary_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
84013 +{
84014 + gimple def_stmt = get_def_stmt(var);
84015 + tree new_rhs1, rhs1 = gimple_assign_rhs1(def_stmt);
84016 +
84017 + *potentionally_overflowed = true;
84018 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
84019 + if (new_rhs1 == NULL_TREE) {
84020 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
84021 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
84022 + else
84023 + return create_assign(visited, potentionally_overflowed, def_stmt, rhs1, AFTER_STMT);
84024 + }
84025 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, NULL_TREE, NULL_TREE);
84026 +}
84027 +
84028 +static tree handle_unary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
84029 +{
84030 + gimple def_stmt = get_def_stmt(var);
84031 + tree rhs1 = gimple_assign_rhs1(def_stmt);
84032 +
84033 + if (is_gimple_constant(rhs1))
84034 + return dup_assign(visited, potentionally_overflowed, def_stmt, signed_cast(rhs1), NULL_TREE, NULL_TREE);
84035 +
84036 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
84037 + switch (TREE_CODE(rhs1)) {
84038 + case SSA_NAME:
84039 + return handle_unary_rhs(visited, potentionally_overflowed, var);
84040 +
84041 + case ARRAY_REF:
84042 + case BIT_FIELD_REF:
84043 + case ADDR_EXPR:
84044 + case COMPONENT_REF:
84045 + case INDIRECT_REF:
84046 +#if BUILDING_GCC_VERSION >= 4006
84047 + case MEM_REF:
84048 +#endif
84049 + case PARM_DECL:
84050 + case TARGET_MEM_REF:
84051 + case VAR_DECL:
84052 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
84053 +
84054 + default:
84055 + debug_gimple_stmt(def_stmt);
84056 + debug_tree(rhs1);
84057 + gcc_unreachable();
84058 + }
84059 +}
84060 +
84061 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
84062 +{
84063 + gimple cond_stmt;
84064 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
84065 +
84066 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
84067 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
84068 + update_stmt(cond_stmt);
84069 +}
84070 +
84071 +static tree create_string_param(tree string)
84072 +{
84073 + tree i_type, a_type;
84074 + int length = TREE_STRING_LENGTH(string);
84075 +
84076 + gcc_assert(length > 0);
84077 +
84078 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
84079 + a_type = build_array_type(char_type_node, i_type);
84080 +
84081 + TREE_TYPE(string) = a_type;
84082 + TREE_CONSTANT(string) = 1;
84083 + TREE_READONLY(string) = 1;
84084 +
84085 + return build1(ADDR_EXPR, ptr_type_node, string);
84086 +}
84087 +
84088 +static void insert_cond_result(basic_block bb_true, gimple stmt, tree arg)
84089 +{
84090 + gimple func_stmt, def_stmt;
84091 + tree current_func, loc_file, loc_line;
84092 + expanded_location xloc;
84093 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
84094 +
84095 + def_stmt = get_def_stmt(arg);
84096 + xloc = expand_location(gimple_location(def_stmt));
84097 +
84098 + if (!gimple_has_location(def_stmt)) {
84099 + xloc = expand_location(gimple_location(stmt));
84100 + if (!gimple_has_location(stmt))
84101 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
84102 + }
84103 +
84104 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
84105 +
84106 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
84107 + loc_file = create_string_param(loc_file);
84108 +
84109 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
84110 + current_func = create_string_param(current_func);
84111 +
84112 + // void report_size_overflow(const char *file, unsigned int line, const char *func)
84113 + func_stmt = gimple_build_call(report_size_overflow_decl, 3, loc_file, loc_line, current_func);
84114 +
84115 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
84116 +}
84117 +
84118 +static void __unused print_the_code_insertions(gimple stmt)
84119 +{
84120 + location_t loc = gimple_location(stmt);
84121 +
84122 + inform(loc, "Integer size_overflow check applied here.");
84123 +}
84124 +
84125 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value)
84126 +{
84127 + basic_block cond_bb, join_bb, bb_true;
84128 + edge e;
84129 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
84130 +
84131 + cond_bb = gimple_bb(stmt);
84132 + gsi_prev(&gsi);
84133 + if (gsi_end_p(gsi))
84134 + e = split_block_after_labels(cond_bb);
84135 + else
84136 + e = split_block(cond_bb, gsi_stmt(gsi));
84137 + cond_bb = e->src;
84138 + join_bb = e->dest;
84139 + e->flags = EDGE_FALSE_VALUE;
84140 + e->probability = REG_BR_PROB_BASE;
84141 +
84142 + bb_true = create_empty_bb(cond_bb);
84143 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
84144 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
84145 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
84146 +
84147 + if (dom_info_available_p(CDI_DOMINATORS)) {
84148 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
84149 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
84150 + }
84151 +
84152 + if (current_loops != NULL) {
84153 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
84154 + add_bb_to_loop(bb_true, cond_bb->loop_father);
84155 + }
84156 +
84157 + insert_cond(cond_bb, arg, cond_code, type_value);
84158 + insert_cond_result(bb_true, stmt, arg);
84159 +
84160 +// print_the_code_insertions(stmt);
84161 +}
84162 +
84163 +static gimple cast_to_unsigned_size_overflow_type(gimple stmt, tree cast_rhs)
84164 +{
84165 + gimple ucast_stmt;
84166 + gimple_stmt_iterator gsi;
84167 + location_t loc = gimple_location(stmt);
84168 +
84169 + ucast_stmt = build_cast_stmt(unsigned_size_overflow_type, cast_rhs, CREATE_NEW_VAR, loc);
84170 + gsi = gsi_for_stmt(stmt);
84171 + gsi_insert_before(&gsi, ucast_stmt, GSI_SAME_STMT);
84172 + return ucast_stmt;
84173 +}
84174 +
84175 +static void check_size_overflow(gimple stmt, tree cast_rhs, tree rhs, bool *potentionally_overflowed)
84176 +{
84177 + tree type_max, type_min, rhs_type = TREE_TYPE(rhs);
84178 + gimple ucast_stmt;
84179 +
84180 + if (!*potentionally_overflowed)
84181 + return;
84182 +
84183 + if (TYPE_UNSIGNED(rhs_type)) {
84184 + ucast_stmt = cast_to_unsigned_size_overflow_type(stmt, cast_rhs);
84185 + type_max = cast_a_tree(unsigned_size_overflow_type, TYPE_MAX_VALUE(rhs_type));
84186 + insert_check_size_overflow(stmt, GT_EXPR, gimple_get_lhs(ucast_stmt), type_max);
84187 + } else {
84188 + type_max = signed_cast(TYPE_MAX_VALUE(rhs_type));
84189 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max);
84190 +
84191 + type_min = signed_cast(TYPE_MIN_VALUE(rhs_type));
84192 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min);
84193 + }
84194 +}
84195 +
84196 +static tree change_assign_rhs(gimple stmt, tree orig_rhs, tree new_rhs)
84197 +{
84198 + gimple assign;
84199 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
84200 + tree origtype = TREE_TYPE(orig_rhs);
84201 +
84202 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
84203 +
84204 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, gimple_location(stmt));
84205 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
84206 + update_stmt(assign);
84207 + return gimple_get_lhs(assign);
84208 +}
84209 +
84210 +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))
84211 +{
84212 + tree new_rhs;
84213 +
84214 + if (gimple_assign_rhs_code(def_stmt) == MIN_EXPR)
84215 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, NULL_TREE);
84216 +
84217 + if (var_rhs == NULL_TREE)
84218 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
84219 +
84220 + new_rhs = change_assign_rhs(def_stmt, orig_rhs, var_rhs);
84221 + gimple_assign_set_rhs(def_stmt, new_rhs);
84222 + update_stmt(def_stmt);
84223 +
84224 + check_size_overflow(def_stmt, var_rhs, orig_rhs, potentionally_overflowed);
84225 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
84226 +}
84227 +
84228 +static tree handle_binary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
84229 +{
84230 + tree rhs1, rhs2;
84231 + gimple def_stmt = get_def_stmt(var);
84232 + tree new_rhs1 = NULL_TREE;
84233 + tree new_rhs2 = NULL_TREE;
84234 +
84235 + rhs1 = gimple_assign_rhs1(def_stmt);
84236 + rhs2 = gimple_assign_rhs2(def_stmt);
84237 +
84238 + /* no DImode/TImode division in the 32/64 bit kernel */
84239 + switch (gimple_assign_rhs_code(def_stmt)) {
84240 + case RDIV_EXPR:
84241 + case TRUNC_DIV_EXPR:
84242 + case CEIL_DIV_EXPR:
84243 + case FLOOR_DIV_EXPR:
84244 + case ROUND_DIV_EXPR:
84245 + case TRUNC_MOD_EXPR:
84246 + case CEIL_MOD_EXPR:
84247 + case FLOOR_MOD_EXPR:
84248 + case ROUND_MOD_EXPR:
84249 + case EXACT_DIV_EXPR:
84250 + case POINTER_PLUS_EXPR:
84251 + case BIT_AND_EXPR:
84252 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
84253 + default:
84254 + break;
84255 + }
84256 +
84257 + *potentionally_overflowed = true;
84258 +
84259 + if (TREE_CODE(rhs1) == SSA_NAME)
84260 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
84261 + if (TREE_CODE(rhs2) == SSA_NAME)
84262 + new_rhs2 = expand(visited, potentionally_overflowed, rhs2);
84263 +
84264 + if (is_gimple_constant(rhs2))
84265 + return handle_const_assign(visited, potentionally_overflowed, def_stmt, var, rhs1, new_rhs1, new_rhs1, signed_cast(rhs2), &gimple_assign_set_rhs1);
84266 +
84267 + if (is_gimple_constant(rhs1))
84268 + return handle_const_assign(visited, potentionally_overflowed, def_stmt, var, rhs2, new_rhs2, signed_cast(rhs1), new_rhs2, &gimple_assign_set_rhs2);
84269 +
84270 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, NULL_TREE);
84271 +}
84272 +
84273 +#if BUILDING_GCC_VERSION >= 4007
84274 +static tree get_new_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, tree rhs)
84275 +{
84276 + if (is_gimple_constant(rhs))
84277 + return signed_cast(rhs);
84278 + if (TREE_CODE(rhs) != SSA_NAME)
84279 + return NULL_TREE;
84280 + return expand(visited, potentionally_overflowed, rhs);
84281 +}
84282 +
84283 +static tree handle_ternary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
84284 +{
84285 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3;
84286 + gimple def_stmt = get_def_stmt(var);
84287 +
84288 + *potentionally_overflowed = true;
84289 +
84290 + rhs1 = gimple_assign_rhs1(def_stmt);
84291 + rhs2 = gimple_assign_rhs2(def_stmt);
84292 + rhs3 = gimple_assign_rhs3(def_stmt);
84293 + new_rhs1 = get_new_rhs(visited, potentionally_overflowed, rhs1);
84294 + new_rhs2 = get_new_rhs(visited, potentionally_overflowed, rhs2);
84295 + new_rhs3 = get_new_rhs(visited, potentionally_overflowed, rhs3);
84296 +
84297 + if (new_rhs1 == NULL_TREE && new_rhs2 != NULL_TREE && new_rhs3 != NULL_TREE)
84298 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, new_rhs3);
84299 + error("handle_ternary_ops: unknown rhs");
84300 + gcc_unreachable();
84301 +}
84302 +#endif
84303 +
84304 +static void set_size_overflow_type(tree node)
84305 +{
84306 + switch (TYPE_MODE(TREE_TYPE(node))) {
84307 + case SImode:
84308 + signed_size_overflow_type = intDI_type_node;
84309 + unsigned_size_overflow_type = unsigned_intDI_type_node;
84310 + break;
84311 + case DImode:
84312 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode)) {
84313 + signed_size_overflow_type = intDI_type_node;
84314 + unsigned_size_overflow_type = unsigned_intDI_type_node;
84315 + } else {
84316 + signed_size_overflow_type = intTI_type_node;
84317 + unsigned_size_overflow_type = unsigned_intTI_type_node;
84318 + }
84319 + break;
84320 + default:
84321 + error("set_size_overflow_type: unsupported gcc configuration.");
84322 + gcc_unreachable();
84323 + }
84324 +}
84325 +
84326 +static tree expand_visited(gimple def_stmt)
84327 +{
84328 + gimple tmp;
84329 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
84330 +
84331 + gsi_next(&gsi);
84332 + tmp = gsi_stmt(gsi);
84333 + switch (gimple_code(tmp)) {
84334 + case GIMPLE_ASSIGN:
84335 + return gimple_get_lhs(tmp);
84336 + case GIMPLE_PHI:
84337 + return gimple_phi_result(tmp);
84338 + case GIMPLE_CALL:
84339 + return gimple_call_lhs(tmp);
84340 + default:
84341 + return NULL_TREE;
84342 + }
84343 +}
84344 +
84345 +static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
84346 +{
84347 + gimple def_stmt;
84348 + enum tree_code code = TREE_CODE(TREE_TYPE(var));
84349 +
84350 + if (is_gimple_constant(var))
84351 + return NULL_TREE;
84352 +
84353 + if (TREE_CODE(var) == ADDR_EXPR)
84354 + return NULL_TREE;
84355 +
84356 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
84357 + if (code != INTEGER_TYPE)
84358 + return NULL_TREE;
84359 +
84360 + if (SSA_NAME_IS_DEFAULT_DEF(var)) {
84361 + check_missing_attribute(var);
84362 + return NULL_TREE;
84363 + }
84364 +
84365 + def_stmt = get_def_stmt(var);
84366 +
84367 + if (!def_stmt)
84368 + return NULL_TREE;
84369 +
84370 + if (pointer_set_contains(visited, def_stmt))
84371 + return expand_visited(def_stmt);
84372 +
84373 + switch (gimple_code(def_stmt)) {
84374 + case GIMPLE_NOP:
84375 + check_missing_attribute(var);
84376 + return NULL_TREE;
84377 + case GIMPLE_PHI:
84378 + return build_new_phi(visited, potentionally_overflowed, def_stmt);
84379 + case GIMPLE_CALL:
84380 + case GIMPLE_ASM:
84381 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
84382 + case GIMPLE_ASSIGN:
84383 + switch (gimple_num_ops(def_stmt)) {
84384 + case 2:
84385 + return handle_unary_ops(visited, potentionally_overflowed, var);
84386 + case 3:
84387 + return handle_binary_ops(visited, potentionally_overflowed, var);
84388 +#if BUILDING_GCC_VERSION >= 4007
84389 + case 4:
84390 + return handle_ternary_ops(visited, potentionally_overflowed, var);
84391 +#endif
84392 + }
84393 + default:
84394 + debug_gimple_stmt(def_stmt);
84395 + error("expand: unknown gimple code");
84396 + gcc_unreachable();
84397 + }
84398 +}
84399 +
84400 +static void change_function_arg(gimple stmt, tree origarg, unsigned int argnum, tree newarg)
84401 +{
84402 + gimple assign;
84403 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
84404 + tree origtype = TREE_TYPE(origarg);
84405 +
84406 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
84407 +
84408 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, gimple_location(stmt));
84409 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
84410 + update_stmt(assign);
84411 +
84412 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
84413 + update_stmt(stmt);
84414 +}
84415 +
84416 +static tree get_function_arg(unsigned int argnum, gimple stmt, tree fndecl)
84417 +{
84418 + const char *origid;
84419 + tree arg, origarg;
84420 +
84421 + if (!DECL_ABSTRACT_ORIGIN(fndecl)) {
84422 + gcc_assert(gimple_call_num_args(stmt) > argnum);
84423 + return gimple_call_arg(stmt, argnum);
84424 + }
84425 +
84426 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
84427 + while (origarg && argnum) {
84428 + argnum--;
84429 + origarg = TREE_CHAIN(origarg);
84430 + }
84431 +
84432 + gcc_assert(argnum == 0);
84433 +
84434 + gcc_assert(origarg != NULL_TREE);
84435 + origid = NAME(origarg);
84436 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
84437 + if (!strcmp(origid, NAME(arg)))
84438 + return arg;
84439 + }
84440 + return NULL_TREE;
84441 +}
84442 +
84443 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
84444 +{
84445 + struct pointer_set_t *visited;
84446 + tree arg, newarg;
84447 + bool potentionally_overflowed;
84448 +
84449 + arg = get_function_arg(argnum, stmt, fndecl);
84450 + if (arg == NULL_TREE)
84451 + return;
84452 +
84453 + if (is_gimple_constant(arg))
84454 + return;
84455 + if (TREE_CODE(arg) != SSA_NAME)
84456 + return;
84457 +
84458 + check_arg_type(arg);
84459 +
84460 + set_size_overflow_type(arg);
84461 +
84462 + visited = pointer_set_create();
84463 + potentionally_overflowed = false;
84464 + newarg = expand(visited, &potentionally_overflowed, arg);
84465 + pointer_set_destroy(visited);
84466 +
84467 + if (newarg == NULL_TREE || !potentionally_overflowed)
84468 + return;
84469 +
84470 + change_function_arg(stmt, arg, argnum, newarg);
84471 +
84472 + check_size_overflow(stmt, newarg, arg, &potentionally_overflowed);
84473 +}
84474 +
84475 +static void handle_function_by_attribute(gimple stmt, tree attr, tree fndecl)
84476 +{
84477 + tree p = TREE_VALUE(attr);
84478 + do {
84479 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
84480 + p = TREE_CHAIN(p);
84481 + } while (p);
84482 +}
84483 +
84484 +static void handle_function_by_hash(gimple stmt, tree fndecl)
84485 +{
84486 + tree orig_fndecl;
84487 + unsigned int num;
84488 + struct size_overflow_hash *hash;
84489 +
84490 + orig_fndecl = get_original_function_decl(fndecl);
84491 + hash = get_function_hash(orig_fndecl);
84492 + if (!hash)
84493 + return;
84494 +
84495 + for (num = 1; num <= MAX_PARAM; num++)
84496 + if (hash->param & (1U << num))
84497 + handle_function_arg(stmt, fndecl, num - 1);
84498 +}
84499 +
84500 +static unsigned int handle_function(void)
84501 +{
84502 + basic_block bb = ENTRY_BLOCK_PTR->next_bb;
84503 + int saved_last_basic_block = last_basic_block;
84504 +
84505 + do {
84506 + gimple_stmt_iterator gsi;
84507 + basic_block next = bb->next_bb;
84508 +
84509 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
84510 + tree fndecl, attr;
84511 + gimple stmt = gsi_stmt(gsi);
84512 +
84513 + if (!(is_gimple_call(stmt)))
84514 + continue;
84515 + fndecl = gimple_call_fndecl(stmt);
84516 + if (fndecl == NULL_TREE)
84517 + continue;
84518 + if (gimple_call_num_args(stmt) == 0)
84519 + continue;
84520 + attr = lookup_attribute("size_overflow", TYPE_ATTRIBUTES(TREE_TYPE(fndecl)));
84521 + if (!attr || !TREE_VALUE(attr))
84522 + handle_function_by_hash(stmt, fndecl);
84523 + else
84524 + handle_function_by_attribute(stmt, attr, fndecl);
84525 + gsi = gsi_for_stmt(stmt);
84526 + }
84527 + bb = next;
84528 + } while (bb && bb->index <= saved_last_basic_block);
84529 + return 0;
84530 +}
84531 +
84532 +static struct gimple_opt_pass size_overflow_pass = {
84533 + .pass = {
84534 + .type = GIMPLE_PASS,
84535 + .name = "size_overflow",
84536 + .gate = NULL,
84537 + .execute = handle_function,
84538 + .sub = NULL,
84539 + .next = NULL,
84540 + .static_pass_number = 0,
84541 + .tv_id = TV_NONE,
84542 + .properties_required = PROP_cfg | PROP_referenced_vars,
84543 + .properties_provided = 0,
84544 + .properties_destroyed = 0,
84545 + .todo_flags_start = 0,
84546 + .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
84547 + }
84548 +};
84549 +
84550 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
84551 +{
84552 + tree fntype;
84553 +
84554 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
84555 +
84556 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func)
84557 + fntype = build_function_type_list(void_type_node,
84558 + const_char_ptr_type_node,
84559 + unsigned_type_node,
84560 + const_char_ptr_type_node,
84561 + NULL_TREE);
84562 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
84563 +
84564 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
84565 + TREE_PUBLIC(report_size_overflow_decl) = 1;
84566 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
84567 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
84568 +}
84569 +
84570 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84571 +{
84572 + int i;
84573 + const char * const plugin_name = plugin_info->base_name;
84574 + const int argc = plugin_info->argc;
84575 + const struct plugin_argument * const argv = plugin_info->argv;
84576 + bool enable = true;
84577 +
84578 + struct register_pass_info size_overflow_pass_info = {
84579 + .pass = &size_overflow_pass.pass,
84580 + .reference_pass_name = "ssa",
84581 + .ref_pass_instance_number = 1,
84582 + .pos_op = PASS_POS_INSERT_AFTER
84583 + };
84584 +
84585 + if (!plugin_default_version_check(version, &gcc_version)) {
84586 + error(G_("incompatible gcc/plugin versions"));
84587 + return 1;
84588 + }
84589 +
84590 + for (i = 0; i < argc; ++i) {
84591 + if (!strcmp(argv[i].key, "no-size-overflow")) {
84592 + enable = false;
84593 + continue;
84594 + }
84595 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
84596 + }
84597 +
84598 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
84599 + if (enable) {
84600 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
84601 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
84602 + }
84603 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
84604 +
84605 + return 0;
84606 +}
84607 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
84608 new file mode 100644
84609 index 0000000..b87ec9d
84610 --- /dev/null
84611 +++ b/tools/gcc/stackleak_plugin.c
84612 @@ -0,0 +1,313 @@
84613 +/*
84614 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
84615 + * Licensed under the GPL v2
84616 + *
84617 + * Note: the choice of the license means that the compilation process is
84618 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
84619 + * but for the kernel it doesn't matter since it doesn't link against
84620 + * any of the gcc libraries
84621 + *
84622 + * gcc plugin to help implement various PaX features
84623 + *
84624 + * - track lowest stack pointer
84625 + *
84626 + * TODO:
84627 + * - initialize all local variables
84628 + *
84629 + * BUGS:
84630 + * - none known
84631 + */
84632 +#include "gcc-plugin.h"
84633 +#include "config.h"
84634 +#include "system.h"
84635 +#include "coretypes.h"
84636 +#include "tree.h"
84637 +#include "tree-pass.h"
84638 +#include "flags.h"
84639 +#include "intl.h"
84640 +#include "toplev.h"
84641 +#include "plugin.h"
84642 +//#include "expr.h" where are you...
84643 +#include "diagnostic.h"
84644 +#include "plugin-version.h"
84645 +#include "tm.h"
84646 +#include "function.h"
84647 +#include "basic-block.h"
84648 +#include "gimple.h"
84649 +#include "rtl.h"
84650 +#include "emit-rtl.h"
84651 +
84652 +extern void print_gimple_stmt(FILE *, gimple, int, int);
84653 +
84654 +int plugin_is_GPL_compatible;
84655 +
84656 +static int track_frame_size = -1;
84657 +static const char track_function[] = "pax_track_stack";
84658 +static const char check_function[] = "pax_check_alloca";
84659 +static bool init_locals;
84660 +
84661 +static struct plugin_info stackleak_plugin_info = {
84662 + .version = "201203140940",
84663 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
84664 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
84665 +};
84666 +
84667 +static bool gate_stackleak_track_stack(void);
84668 +static unsigned int execute_stackleak_tree_instrument(void);
84669 +static unsigned int execute_stackleak_final(void);
84670 +
84671 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
84672 + .pass = {
84673 + .type = GIMPLE_PASS,
84674 + .name = "stackleak_tree_instrument",
84675 + .gate = gate_stackleak_track_stack,
84676 + .execute = execute_stackleak_tree_instrument,
84677 + .sub = NULL,
84678 + .next = NULL,
84679 + .static_pass_number = 0,
84680 + .tv_id = TV_NONE,
84681 + .properties_required = PROP_gimple_leh | PROP_cfg,
84682 + .properties_provided = 0,
84683 + .properties_destroyed = 0,
84684 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
84685 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
84686 + }
84687 +};
84688 +
84689 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
84690 + .pass = {
84691 + .type = RTL_PASS,
84692 + .name = "stackleak_final",
84693 + .gate = gate_stackleak_track_stack,
84694 + .execute = execute_stackleak_final,
84695 + .sub = NULL,
84696 + .next = NULL,
84697 + .static_pass_number = 0,
84698 + .tv_id = TV_NONE,
84699 + .properties_required = 0,
84700 + .properties_provided = 0,
84701 + .properties_destroyed = 0,
84702 + .todo_flags_start = 0,
84703 + .todo_flags_finish = TODO_dump_func
84704 + }
84705 +};
84706 +
84707 +static bool gate_stackleak_track_stack(void)
84708 +{
84709 + return track_frame_size >= 0;
84710 +}
84711 +
84712 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
84713 +{
84714 + gimple check_alloca;
84715 + tree fntype, fndecl, alloca_size;
84716 +
84717 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
84718 + fndecl = build_fn_decl(check_function, fntype);
84719 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
84720 +
84721 + // insert call to void pax_check_alloca(unsigned long size)
84722 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
84723 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
84724 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
84725 +}
84726 +
84727 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
84728 +{
84729 + gimple track_stack;
84730 + tree fntype, fndecl;
84731 +
84732 + fntype = build_function_type_list(void_type_node, NULL_TREE);
84733 + fndecl = build_fn_decl(track_function, fntype);
84734 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
84735 +
84736 + // insert call to void pax_track_stack(void)
84737 + track_stack = gimple_build_call(fndecl, 0);
84738 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
84739 +}
84740 +
84741 +#if BUILDING_GCC_VERSION == 4005
84742 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
84743 +{
84744 + tree fndecl;
84745 +
84746 + if (!is_gimple_call(stmt))
84747 + return false;
84748 + fndecl = gimple_call_fndecl(stmt);
84749 + if (!fndecl)
84750 + return false;
84751 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
84752 + return false;
84753 +// print_node(stderr, "pax", fndecl, 4);
84754 + return DECL_FUNCTION_CODE(fndecl) == code;
84755 +}
84756 +#endif
84757 +
84758 +static bool is_alloca(gimple stmt)
84759 +{
84760 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
84761 + return true;
84762 +
84763 +#if BUILDING_GCC_VERSION >= 4007
84764 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
84765 + return true;
84766 +#endif
84767 +
84768 + return false;
84769 +}
84770 +
84771 +static unsigned int execute_stackleak_tree_instrument(void)
84772 +{
84773 + basic_block bb, entry_bb;
84774 + bool prologue_instrumented = false, is_leaf = true;
84775 +
84776 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
84777 +
84778 + // 1. loop through BBs and GIMPLE statements
84779 + FOR_EACH_BB(bb) {
84780 + gimple_stmt_iterator gsi;
84781 +
84782 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
84783 + gimple stmt;
84784 +
84785 + stmt = gsi_stmt(gsi);
84786 +
84787 + if (is_gimple_call(stmt))
84788 + is_leaf = false;
84789 +
84790 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
84791 + if (!is_alloca(stmt))
84792 + continue;
84793 +
84794 + // 2. insert stack overflow check before each __builtin_alloca call
84795 + stackleak_check_alloca(&gsi);
84796 +
84797 + // 3. insert track call after each __builtin_alloca call
84798 + stackleak_add_instrumentation(&gsi);
84799 + if (bb == entry_bb)
84800 + prologue_instrumented = true;
84801 + }
84802 + }
84803 +
84804 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
84805 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
84806 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
84807 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
84808 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
84809 + return 0;
84810 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
84811 + return 0;
84812 +
84813 + // 4. insert track call at the beginning
84814 + if (!prologue_instrumented) {
84815 + gimple_stmt_iterator gsi;
84816 +
84817 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
84818 + if (dom_info_available_p(CDI_DOMINATORS))
84819 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
84820 + gsi = gsi_start_bb(bb);
84821 + stackleak_add_instrumentation(&gsi);
84822 + }
84823 +
84824 + return 0;
84825 +}
84826 +
84827 +static unsigned int execute_stackleak_final(void)
84828 +{
84829 + rtx insn;
84830 +
84831 + if (cfun->calls_alloca)
84832 + return 0;
84833 +
84834 + // keep calls only if function frame is big enough
84835 + if (get_frame_size() >= track_frame_size)
84836 + return 0;
84837 +
84838 + // 1. find pax_track_stack calls
84839 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
84840 + // 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))
84841 + rtx body;
84842 +
84843 + if (!CALL_P(insn))
84844 + continue;
84845 + body = PATTERN(insn);
84846 + if (GET_CODE(body) != CALL)
84847 + continue;
84848 + body = XEXP(body, 0);
84849 + if (GET_CODE(body) != MEM)
84850 + continue;
84851 + body = XEXP(body, 0);
84852 + if (GET_CODE(body) != SYMBOL_REF)
84853 + continue;
84854 + if (strcmp(XSTR(body, 0), track_function))
84855 + continue;
84856 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
84857 + // 2. delete call
84858 + insn = delete_insn_and_edges(insn);
84859 +#if BUILDING_GCC_VERSION >= 4007
84860 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
84861 + insn = delete_insn_and_edges(insn);
84862 +#endif
84863 + }
84864 +
84865 +// print_simple_rtl(stderr, get_insns());
84866 +// print_rtl(stderr, get_insns());
84867 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
84868 +
84869 + return 0;
84870 +}
84871 +
84872 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84873 +{
84874 + const char * const plugin_name = plugin_info->base_name;
84875 + const int argc = plugin_info->argc;
84876 + const struct plugin_argument * const argv = plugin_info->argv;
84877 + int i;
84878 + struct register_pass_info stackleak_tree_instrument_pass_info = {
84879 + .pass = &stackleak_tree_instrument_pass.pass,
84880 +// .reference_pass_name = "tree_profile",
84881 + .reference_pass_name = "optimized",
84882 + .ref_pass_instance_number = 0,
84883 + .pos_op = PASS_POS_INSERT_BEFORE
84884 + };
84885 + struct register_pass_info stackleak_final_pass_info = {
84886 + .pass = &stackleak_final_rtl_opt_pass.pass,
84887 + .reference_pass_name = "final",
84888 + .ref_pass_instance_number = 0,
84889 + .pos_op = PASS_POS_INSERT_BEFORE
84890 + };
84891 +
84892 + if (!plugin_default_version_check(version, &gcc_version)) {
84893 + error(G_("incompatible gcc/plugin versions"));
84894 + return 1;
84895 + }
84896 +
84897 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
84898 +
84899 + for (i = 0; i < argc; ++i) {
84900 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
84901 + if (!argv[i].value) {
84902 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
84903 + continue;
84904 + }
84905 + track_frame_size = atoi(argv[i].value);
84906 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
84907 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
84908 + continue;
84909 + }
84910 + if (!strcmp(argv[i].key, "initialize-locals")) {
84911 + if (argv[i].value) {
84912 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
84913 + continue;
84914 + }
84915 + init_locals = true;
84916 + continue;
84917 + }
84918 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
84919 + }
84920 +
84921 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
84922 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
84923 +
84924 + return 0;
84925 +}
84926 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
84927 index 6789d78..4afd019 100644
84928 --- a/tools/perf/util/include/asm/alternative-asm.h
84929 +++ b/tools/perf/util/include/asm/alternative-asm.h
84930 @@ -5,4 +5,7 @@
84931
84932 #define altinstruction_entry #
84933
84934 + .macro pax_force_retaddr rip=0, reload=0
84935 + .endm
84936 +
84937 #endif
84938 diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
84939 index af0f22f..9a7d479 100644
84940 --- a/usr/gen_init_cpio.c
84941 +++ b/usr/gen_init_cpio.c
84942 @@ -303,7 +303,7 @@ static int cpio_mkfile(const char *name, const char *location,
84943 int retval;
84944 int rc = -1;
84945 int namesize;
84946 - int i;
84947 + unsigned int i;
84948
84949 mode |= S_IFREG;
84950
84951 @@ -392,9 +392,10 @@ static char *cpio_replace_env(char *new_location)
84952 *env_var = *expanded = '\0';
84953 strncat(env_var, start + 2, end - start - 2);
84954 strncat(expanded, new_location, start - new_location);
84955 - strncat(expanded, getenv(env_var), PATH_MAX);
84956 - strncat(expanded, end + 1, PATH_MAX);
84957 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
84958 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
84959 strncpy(new_location, expanded, PATH_MAX);
84960 + new_location[PATH_MAX] = 0;
84961 } else
84962 break;
84963 }
84964 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
84965 index 9739b53..6d457e3 100644
84966 --- a/virt/kvm/kvm_main.c
84967 +++ b/virt/kvm/kvm_main.c
84968 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
84969
84970 static cpumask_var_t cpus_hardware_enabled;
84971 static int kvm_usage_count = 0;
84972 -static atomic_t hardware_enable_failed;
84973 +static atomic_unchecked_t hardware_enable_failed;
84974
84975 struct kmem_cache *kvm_vcpu_cache;
84976 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
84977 @@ -2247,7 +2247,7 @@ static void hardware_enable_nolock(void *junk)
84978
84979 if (r) {
84980 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
84981 - atomic_inc(&hardware_enable_failed);
84982 + atomic_inc_unchecked(&hardware_enable_failed);
84983 printk(KERN_INFO "kvm: enabling virtualization on "
84984 "CPU%d failed\n", cpu);
84985 }
84986 @@ -2301,10 +2301,10 @@ static int hardware_enable_all(void)
84987
84988 kvm_usage_count++;
84989 if (kvm_usage_count == 1) {
84990 - atomic_set(&hardware_enable_failed, 0);
84991 + atomic_set_unchecked(&hardware_enable_failed, 0);
84992 on_each_cpu(hardware_enable_nolock, NULL, 1);
84993
84994 - if (atomic_read(&hardware_enable_failed)) {
84995 + if (atomic_read_unchecked(&hardware_enable_failed)) {
84996 hardware_disable_all_nolock();
84997 r = -EBUSY;
84998 }
84999 @@ -2667,7 +2667,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
85000 kvm_arch_vcpu_put(vcpu);
85001 }
85002
85003 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
85004 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
85005 struct module *module)
85006 {
85007 int r;
85008 @@ -2730,7 +2730,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
85009 if (!vcpu_align)
85010 vcpu_align = __alignof__(struct kvm_vcpu);
85011 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
85012 - 0, NULL);
85013 + SLAB_USERCOPY, NULL);
85014 if (!kvm_vcpu_cache) {
85015 r = -ENOMEM;
85016 goto out_free_3;
85017 @@ -2740,9 +2740,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
85018 if (r)
85019 goto out_free;
85020
85021 - kvm_chardev_ops.owner = module;
85022 - kvm_vm_fops.owner = module;
85023 - kvm_vcpu_fops.owner = module;
85024 + pax_open_kernel();
85025 + *(void **)&kvm_chardev_ops.owner = module;
85026 + *(void **)&kvm_vm_fops.owner = module;
85027 + *(void **)&kvm_vcpu_fops.owner = module;
85028 + pax_close_kernel();
85029
85030 r = misc_register(&kvm_dev);
85031 if (r) {