]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.4.6-201207201441.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.4.6-201207201441.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 5d0edcb..dcc0ce1 100644
233 --- a/Makefile
234 +++ b/Makefile
235 @@ -245,8 +245,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
236
237 HOSTCC = gcc
238 HOSTCXX = g++
239 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
240 -HOSTCXXFLAGS = -O2
241 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
242 +HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
243 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
244
245 # Decide whether to build built-in, modular, or both.
246 # Normally, just do built-in.
247 @@ -407,8 +408,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exc
248 # Rules shared between *config targets and build targets
249
250 # Basic helpers built in scripts/
251 -PHONY += scripts_basic
252 -scripts_basic:
253 +PHONY += scripts_basic gcc-plugins
254 +scripts_basic: gcc-plugins
255 $(Q)$(MAKE) $(build)=scripts/basic
256 $(Q)rm -f .tmp_quiet_recordmcount
257
258 @@ -564,6 +565,56 @@ else
259 KBUILD_CFLAGS += -O2
260 endif
261
262 +ifndef DISABLE_PAX_PLUGINS
263 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
264 +ifneq ($(PLUGINCC),)
265 +ifndef DISABLE_PAX_CONSTIFY_PLUGIN
266 +ifndef CONFIG_UML
267 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
268 +endif
269 +endif
270 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
271 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
272 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
273 +endif
274 +ifdef CONFIG_KALLOCSTAT_PLUGIN
275 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
276 +endif
277 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
278 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
279 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
280 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
281 +endif
282 +ifdef CONFIG_CHECKER_PLUGIN
283 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
284 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
285 +endif
286 +endif
287 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
288 +ifdef CONFIG_PAX_SIZE_OVERFLOW
289 +SIZE_OVERFLOW_PLUGIN := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
290 +endif
291 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
292 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS) $(SIZE_OVERFLOW_PLUGIN)
293 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
294 +export PLUGINCC CONSTIFY_PLUGIN STACKLEAK_PLUGIN KERNEXEC_PLUGIN CHECKER_PLUGIN SIZE_OVERFLOW_PLUGIN
295 +ifeq ($(KBUILD_EXTMOD),)
296 +gcc-plugins:
297 + $(Q)$(MAKE) $(build)=tools/gcc
298 +else
299 +gcc-plugins: ;
300 +endif
301 +else
302 +gcc-plugins:
303 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
304 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
305 +else
306 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
307 +endif
308 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
309 +endif
310 +endif
311 +
312 include $(srctree)/arch/$(SRCARCH)/Makefile
313
314 ifneq ($(CONFIG_FRAME_WARN),0)
315 @@ -708,7 +759,7 @@ export mod_strip_cmd
316
317
318 ifeq ($(KBUILD_EXTMOD),)
319 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
320 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
321
322 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
323 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
324 @@ -932,6 +983,8 @@ vmlinux.o: $(modpost-init) $(vmlinux-main) FORCE
325
326 # The actual objects are generated when descending,
327 # make sure no implicit rule kicks in
328 +$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
329 +$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
330 $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
331
332 # Handle descending into subdirectories listed in $(vmlinux-dirs)
333 @@ -941,7 +994,7 @@ $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
334 # Error messages still appears in the original language
335
336 PHONY += $(vmlinux-dirs)
337 -$(vmlinux-dirs): prepare scripts
338 +$(vmlinux-dirs): gcc-plugins prepare scripts
339 $(Q)$(MAKE) $(build)=$@
340
341 # Store (new) KERNELRELASE string in include/config/kernel.release
342 @@ -985,6 +1038,7 @@ prepare0: archprepare FORCE
343 $(Q)$(MAKE) $(build)=.
344
345 # All the preparing..
346 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
347 prepare: prepare0
348
349 # Generate some files
350 @@ -1092,6 +1146,8 @@ all: modules
351 # using awk while concatenating to the final file.
352
353 PHONY += modules
354 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
355 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
356 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
357 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
358 @$(kecho) ' Building modules, stage 2.';
359 @@ -1107,7 +1163,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
360
361 # Target to prepare building external modules
362 PHONY += modules_prepare
363 -modules_prepare: prepare scripts
364 +modules_prepare: gcc-plugins prepare scripts
365
366 # Target to install modules
367 PHONY += modules_install
368 @@ -1166,7 +1222,7 @@ CLEAN_FILES += vmlinux System.map \
369 MRPROPER_DIRS += include/config usr/include include/generated \
370 arch/*/include/generated
371 MRPROPER_FILES += .config .config.old .version .old_version \
372 - include/linux/version.h \
373 + include/linux/version.h tools/gcc/size_overflow_hash.h\
374 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
375
376 # clean - Delete most, but leave enough to build external modules
377 @@ -1204,6 +1260,7 @@ distclean: mrproper
378 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
379 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
380 -o -name '.*.rej' \
381 + -o -name '.*.rej' -o -name '*.so' \
382 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
383 -type f -print | xargs rm -f
384
385 @@ -1364,6 +1421,8 @@ PHONY += $(module-dirs) modules
386 $(module-dirs): crmodverdir $(objtree)/Module.symvers
387 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
388
389 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
390 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
391 modules: $(module-dirs)
392 @$(kecho) ' Building modules, stage 2.';
393 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
394 @@ -1490,17 +1549,21 @@ else
395 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
396 endif
397
398 -%.s: %.c prepare scripts FORCE
399 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
400 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
401 +%.s: %.c gcc-plugins prepare scripts FORCE
402 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
403 %.i: %.c prepare scripts FORCE
404 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
405 -%.o: %.c prepare scripts FORCE
406 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
407 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
408 +%.o: %.c gcc-plugins prepare scripts FORCE
409 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
410 %.lst: %.c prepare scripts FORCE
411 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
412 -%.s: %.S prepare scripts FORCE
413 +%.s: %.S gcc-plugins prepare scripts FORCE
414 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
415 -%.o: %.S prepare scripts FORCE
416 +%.o: %.S gcc-plugins prepare scripts FORCE
417 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
418 %.symtypes: %.c prepare scripts FORCE
419 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
420 @@ -1510,11 +1573,15 @@ endif
421 $(cmd_crmodverdir)
422 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
423 $(build)=$(build-dir)
424 -%/: prepare scripts FORCE
425 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
426 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
427 +%/: gcc-plugins prepare scripts FORCE
428 $(cmd_crmodverdir)
429 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
430 $(build)=$(build-dir)
431 -%.ko: prepare scripts FORCE
432 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
433 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
434 +%.ko: gcc-plugins prepare scripts FORCE
435 $(cmd_crmodverdir)
436 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
437 $(build)=$(build-dir) $(@:.ko=.o)
438 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
439 index 3bb7ffe..347a54c 100644
440 --- a/arch/alpha/include/asm/atomic.h
441 +++ b/arch/alpha/include/asm/atomic.h
442 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
443 #define atomic_dec(v) atomic_sub(1,(v))
444 #define atomic64_dec(v) atomic64_sub(1,(v))
445
446 +#define atomic64_read_unchecked(v) atomic64_read(v)
447 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
448 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
449 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
450 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
451 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
452 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
453 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
454 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
455 +
456 #define smp_mb__before_atomic_dec() smp_mb()
457 #define smp_mb__after_atomic_dec() smp_mb()
458 #define smp_mb__before_atomic_inc() smp_mb()
459 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
460 index ad368a9..fbe0f25 100644
461 --- a/arch/alpha/include/asm/cache.h
462 +++ b/arch/alpha/include/asm/cache.h
463 @@ -4,19 +4,19 @@
464 #ifndef __ARCH_ALPHA_CACHE_H
465 #define __ARCH_ALPHA_CACHE_H
466
467 +#include <linux/const.h>
468
469 /* Bytes per L1 (data) cache line. */
470 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
471 -# define L1_CACHE_BYTES 64
472 # define L1_CACHE_SHIFT 6
473 #else
474 /* Both EV4 and EV5 are write-through, read-allocate,
475 direct-mapped, physical.
476 */
477 -# define L1_CACHE_BYTES 32
478 # define L1_CACHE_SHIFT 5
479 #endif
480
481 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
482 #define SMP_CACHE_BYTES L1_CACHE_BYTES
483
484 #endif
485 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
486 index 968d999..d36b2df 100644
487 --- a/arch/alpha/include/asm/elf.h
488 +++ b/arch/alpha/include/asm/elf.h
489 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
490
491 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
492
493 +#ifdef CONFIG_PAX_ASLR
494 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
495 +
496 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
497 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
498 +#endif
499 +
500 /* $0 is set by ld.so to a pointer to a function which might be
501 registered using atexit. This provides a mean for the dynamic
502 linker to call DT_FINI functions for shared libraries that have
503 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
504 index bc2a0da..8ad11ee 100644
505 --- a/arch/alpha/include/asm/pgalloc.h
506 +++ b/arch/alpha/include/asm/pgalloc.h
507 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
508 pgd_set(pgd, pmd);
509 }
510
511 +static inline void
512 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
513 +{
514 + pgd_populate(mm, pgd, pmd);
515 +}
516 +
517 extern pgd_t *pgd_alloc(struct mm_struct *mm);
518
519 static inline void
520 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
521 index 81a4342..348b927 100644
522 --- a/arch/alpha/include/asm/pgtable.h
523 +++ b/arch/alpha/include/asm/pgtable.h
524 @@ -102,6 +102,17 @@ struct vm_area_struct;
525 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
526 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
527 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
528 +
529 +#ifdef CONFIG_PAX_PAGEEXEC
530 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
531 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
532 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
533 +#else
534 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
535 +# define PAGE_COPY_NOEXEC PAGE_COPY
536 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
537 +#endif
538 +
539 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
540
541 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
542 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
543 index 2fd00b7..cfd5069 100644
544 --- a/arch/alpha/kernel/module.c
545 +++ b/arch/alpha/kernel/module.c
546 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
547
548 /* The small sections were sorted to the end of the segment.
549 The following should definitely cover them. */
550 - gp = (u64)me->module_core + me->core_size - 0x8000;
551 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
552 got = sechdrs[me->arch.gotsecindex].sh_addr;
553
554 for (i = 0; i < n; i++) {
555 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
556 index 49ee319..9ee7d14 100644
557 --- a/arch/alpha/kernel/osf_sys.c
558 +++ b/arch/alpha/kernel/osf_sys.c
559 @@ -1146,7 +1146,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
560 /* At this point: (!vma || addr < vma->vm_end). */
561 if (limit - len < addr)
562 return -ENOMEM;
563 - if (!vma || addr + len <= vma->vm_start)
564 + if (check_heap_stack_gap(vma, addr, len))
565 return addr;
566 addr = vma->vm_end;
567 vma = vma->vm_next;
568 @@ -1182,6 +1182,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
569 merely specific addresses, but regions of memory -- perhaps
570 this feature should be incorporated into all ports? */
571
572 +#ifdef CONFIG_PAX_RANDMMAP
573 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
574 +#endif
575 +
576 if (addr) {
577 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
578 if (addr != (unsigned long) -ENOMEM)
579 @@ -1189,8 +1193,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
580 }
581
582 /* Next, try allocating at TASK_UNMAPPED_BASE. */
583 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
584 - len, limit);
585 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
586 +
587 if (addr != (unsigned long) -ENOMEM)
588 return addr;
589
590 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
591 index 5eecab1..609abc0 100644
592 --- a/arch/alpha/mm/fault.c
593 +++ b/arch/alpha/mm/fault.c
594 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
595 __reload_thread(pcb);
596 }
597
598 +#ifdef CONFIG_PAX_PAGEEXEC
599 +/*
600 + * PaX: decide what to do with offenders (regs->pc = fault address)
601 + *
602 + * returns 1 when task should be killed
603 + * 2 when patched PLT trampoline was detected
604 + * 3 when unpatched PLT trampoline was detected
605 + */
606 +static int pax_handle_fetch_fault(struct pt_regs *regs)
607 +{
608 +
609 +#ifdef CONFIG_PAX_EMUPLT
610 + int err;
611 +
612 + do { /* PaX: patched PLT emulation #1 */
613 + unsigned int ldah, ldq, jmp;
614 +
615 + err = get_user(ldah, (unsigned int *)regs->pc);
616 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
617 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
618 +
619 + if (err)
620 + break;
621 +
622 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
623 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
624 + jmp == 0x6BFB0000U)
625 + {
626 + unsigned long r27, addr;
627 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
628 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
629 +
630 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
631 + err = get_user(r27, (unsigned long *)addr);
632 + if (err)
633 + break;
634 +
635 + regs->r27 = r27;
636 + regs->pc = r27;
637 + return 2;
638 + }
639 + } while (0);
640 +
641 + do { /* PaX: patched PLT emulation #2 */
642 + unsigned int ldah, lda, br;
643 +
644 + err = get_user(ldah, (unsigned int *)regs->pc);
645 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
646 + err |= get_user(br, (unsigned int *)(regs->pc+8));
647 +
648 + if (err)
649 + break;
650 +
651 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
652 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
653 + (br & 0xFFE00000U) == 0xC3E00000U)
654 + {
655 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
656 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
657 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
658 +
659 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
660 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
661 + return 2;
662 + }
663 + } while (0);
664 +
665 + do { /* PaX: unpatched PLT emulation */
666 + unsigned int br;
667 +
668 + err = get_user(br, (unsigned int *)regs->pc);
669 +
670 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
671 + unsigned int br2, ldq, nop, jmp;
672 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
673 +
674 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
675 + err = get_user(br2, (unsigned int *)addr);
676 + err |= get_user(ldq, (unsigned int *)(addr+4));
677 + err |= get_user(nop, (unsigned int *)(addr+8));
678 + err |= get_user(jmp, (unsigned int *)(addr+12));
679 + err |= get_user(resolver, (unsigned long *)(addr+16));
680 +
681 + if (err)
682 + break;
683 +
684 + if (br2 == 0xC3600000U &&
685 + ldq == 0xA77B000CU &&
686 + nop == 0x47FF041FU &&
687 + jmp == 0x6B7B0000U)
688 + {
689 + regs->r28 = regs->pc+4;
690 + regs->r27 = addr+16;
691 + regs->pc = resolver;
692 + return 3;
693 + }
694 + }
695 + } while (0);
696 +#endif
697 +
698 + return 1;
699 +}
700 +
701 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
702 +{
703 + unsigned long i;
704 +
705 + printk(KERN_ERR "PAX: bytes at PC: ");
706 + for (i = 0; i < 5; i++) {
707 + unsigned int c;
708 + if (get_user(c, (unsigned int *)pc+i))
709 + printk(KERN_CONT "???????? ");
710 + else
711 + printk(KERN_CONT "%08x ", c);
712 + }
713 + printk("\n");
714 +}
715 +#endif
716
717 /*
718 * This routine handles page faults. It determines the address,
719 @@ -130,8 +248,29 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
720 good_area:
721 si_code = SEGV_ACCERR;
722 if (cause < 0) {
723 - if (!(vma->vm_flags & VM_EXEC))
724 + if (!(vma->vm_flags & VM_EXEC)) {
725 +
726 +#ifdef CONFIG_PAX_PAGEEXEC
727 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
728 + goto bad_area;
729 +
730 + up_read(&mm->mmap_sem);
731 + switch (pax_handle_fetch_fault(regs)) {
732 +
733 +#ifdef CONFIG_PAX_EMUPLT
734 + case 2:
735 + case 3:
736 + return;
737 +#endif
738 +
739 + }
740 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
741 + do_group_exit(SIGKILL);
742 +#else
743 goto bad_area;
744 +#endif
745 +
746 + }
747 } else if (!cause) {
748 /* Allow reads even for write-only mappings */
749 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
750 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
751 index 68374ba..cff7196 100644
752 --- a/arch/arm/include/asm/atomic.h
753 +++ b/arch/arm/include/asm/atomic.h
754 @@ -17,17 +17,35 @@
755 #include <asm/barrier.h>
756 #include <asm/cmpxchg.h>
757
758 +#ifdef CONFIG_GENERIC_ATOMIC64
759 +#include <asm-generic/atomic64.h>
760 +#endif
761 +
762 #define ATOMIC_INIT(i) { (i) }
763
764 #ifdef __KERNEL__
765
766 +#define _ASM_EXTABLE(from, to) \
767 +" .pushsection __ex_table,\"a\"\n"\
768 +" .align 3\n" \
769 +" .long " #from ", " #to"\n" \
770 +" .popsection"
771 +
772 /*
773 * On ARM, ordinary assignment (str instruction) doesn't clear the local
774 * strex/ldrex monitor on some implementations. The reason we can use it for
775 * atomic_set() is the clrex or dummy strex done on every exception return.
776 */
777 #define atomic_read(v) (*(volatile int *)&(v)->counter)
778 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
779 +{
780 + return v->counter;
781 +}
782 #define atomic_set(v,i) (((v)->counter) = (i))
783 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
784 +{
785 + v->counter = i;
786 +}
787
788 #if __LINUX_ARM_ARCH__ >= 6
789
790 @@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
791 int result;
792
793 __asm__ __volatile__("@ atomic_add\n"
794 +"1: ldrex %1, [%3]\n"
795 +" adds %0, %1, %4\n"
796 +
797 +#ifdef CONFIG_PAX_REFCOUNT
798 +" bvc 3f\n"
799 +"2: bkpt 0xf103\n"
800 +"3:\n"
801 +#endif
802 +
803 +" strex %1, %0, [%3]\n"
804 +" teq %1, #0\n"
805 +" bne 1b"
806 +
807 +#ifdef CONFIG_PAX_REFCOUNT
808 +"\n4:\n"
809 + _ASM_EXTABLE(2b, 4b)
810 +#endif
811 +
812 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
813 + : "r" (&v->counter), "Ir" (i)
814 + : "cc");
815 +}
816 +
817 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
818 +{
819 + unsigned long tmp;
820 + int result;
821 +
822 + __asm__ __volatile__("@ atomic_add_unchecked\n"
823 "1: ldrex %0, [%3]\n"
824 " add %0, %0, %4\n"
825 " strex %1, %0, [%3]\n"
826 @@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
827 smp_mb();
828
829 __asm__ __volatile__("@ atomic_add_return\n"
830 +"1: ldrex %1, [%3]\n"
831 +" adds %0, %1, %4\n"
832 +
833 +#ifdef CONFIG_PAX_REFCOUNT
834 +" bvc 3f\n"
835 +" mov %0, %1\n"
836 +"2: bkpt 0xf103\n"
837 +"3:\n"
838 +#endif
839 +
840 +" strex %1, %0, [%3]\n"
841 +" teq %1, #0\n"
842 +" bne 1b"
843 +
844 +#ifdef CONFIG_PAX_REFCOUNT
845 +"\n4:\n"
846 + _ASM_EXTABLE(2b, 4b)
847 +#endif
848 +
849 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
850 + : "r" (&v->counter), "Ir" (i)
851 + : "cc");
852 +
853 + smp_mb();
854 +
855 + return result;
856 +}
857 +
858 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
859 +{
860 + unsigned long tmp;
861 + int result;
862 +
863 + smp_mb();
864 +
865 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
866 "1: ldrex %0, [%3]\n"
867 " add %0, %0, %4\n"
868 " strex %1, %0, [%3]\n"
869 @@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
870 int result;
871
872 __asm__ __volatile__("@ atomic_sub\n"
873 +"1: ldrex %1, [%3]\n"
874 +" subs %0, %1, %4\n"
875 +
876 +#ifdef CONFIG_PAX_REFCOUNT
877 +" bvc 3f\n"
878 +"2: bkpt 0xf103\n"
879 +"3:\n"
880 +#endif
881 +
882 +" strex %1, %0, [%3]\n"
883 +" teq %1, #0\n"
884 +" bne 1b"
885 +
886 +#ifdef CONFIG_PAX_REFCOUNT
887 +"\n4:\n"
888 + _ASM_EXTABLE(2b, 4b)
889 +#endif
890 +
891 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
892 + : "r" (&v->counter), "Ir" (i)
893 + : "cc");
894 +}
895 +
896 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
897 +{
898 + unsigned long tmp;
899 + int result;
900 +
901 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
902 "1: ldrex %0, [%3]\n"
903 " sub %0, %0, %4\n"
904 " strex %1, %0, [%3]\n"
905 @@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
906 smp_mb();
907
908 __asm__ __volatile__("@ atomic_sub_return\n"
909 -"1: ldrex %0, [%3]\n"
910 -" sub %0, %0, %4\n"
911 +"1: ldrex %1, [%3]\n"
912 +" sub %0, %1, %4\n"
913 +
914 +#ifdef CONFIG_PAX_REFCOUNT
915 +" bvc 3f\n"
916 +" mov %0, %1\n"
917 +"2: bkpt 0xf103\n"
918 +"3:\n"
919 +#endif
920 +
921 " strex %1, %0, [%3]\n"
922 " teq %1, #0\n"
923 " bne 1b"
924 +
925 +#ifdef CONFIG_PAX_REFCOUNT
926 +"\n4:\n"
927 + _ASM_EXTABLE(2b, 4b)
928 +#endif
929 +
930 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
931 : "r" (&v->counter), "Ir" (i)
932 : "cc");
933 @@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
934 return oldval;
935 }
936
937 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
938 +{
939 + unsigned long oldval, res;
940 +
941 + smp_mb();
942 +
943 + do {
944 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
945 + "ldrex %1, [%3]\n"
946 + "mov %0, #0\n"
947 + "teq %1, %4\n"
948 + "strexeq %0, %5, [%3]\n"
949 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
950 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
951 + : "cc");
952 + } while (res);
953 +
954 + smp_mb();
955 +
956 + return oldval;
957 +}
958 +
959 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
960 {
961 unsigned long tmp, tmp2;
962 @@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
963
964 return val;
965 }
966 +
967 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
968 +{
969 + return atomic_add_return(i, v);
970 +}
971 +
972 #define atomic_add(i, v) (void) atomic_add_return(i, v)
973 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
974 +{
975 + (void) atomic_add_return(i, v);
976 +}
977
978 static inline int atomic_sub_return(int i, atomic_t *v)
979 {
980 @@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
981 return val;
982 }
983 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
984 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
985 +{
986 + (void) atomic_sub_return(i, v);
987 +}
988
989 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
990 {
991 @@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
992 return ret;
993 }
994
995 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
996 +{
997 + return atomic_cmpxchg(v, old, new);
998 +}
999 +
1000 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1001 {
1002 unsigned long flags;
1003 @@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1004 #endif /* __LINUX_ARM_ARCH__ */
1005
1006 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1007 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1008 +{
1009 + return xchg(&v->counter, new);
1010 +}
1011
1012 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1013 {
1014 @@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1015 }
1016
1017 #define atomic_inc(v) atomic_add(1, v)
1018 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1019 +{
1020 + atomic_add_unchecked(1, v);
1021 +}
1022 #define atomic_dec(v) atomic_sub(1, v)
1023 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1024 +{
1025 + atomic_sub_unchecked(1, v);
1026 +}
1027
1028 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1029 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1030 +{
1031 + return atomic_add_return_unchecked(1, v) == 0;
1032 +}
1033 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1034 #define atomic_inc_return(v) (atomic_add_return(1, v))
1035 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1036 +{
1037 + return atomic_add_return_unchecked(1, v);
1038 +}
1039 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1040 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1041
1042 @@ -241,6 +428,14 @@ typedef struct {
1043 u64 __aligned(8) counter;
1044 } atomic64_t;
1045
1046 +#ifdef CONFIG_PAX_REFCOUNT
1047 +typedef struct {
1048 + u64 __aligned(8) counter;
1049 +} atomic64_unchecked_t;
1050 +#else
1051 +typedef atomic64_t atomic64_unchecked_t;
1052 +#endif
1053 +
1054 #define ATOMIC64_INIT(i) { (i) }
1055
1056 static inline u64 atomic64_read(atomic64_t *v)
1057 @@ -256,6 +451,19 @@ static inline u64 atomic64_read(atomic64_t *v)
1058 return result;
1059 }
1060
1061 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1062 +{
1063 + u64 result;
1064 +
1065 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1066 +" ldrexd %0, %H0, [%1]"
1067 + : "=&r" (result)
1068 + : "r" (&v->counter), "Qo" (v->counter)
1069 + );
1070 +
1071 + return result;
1072 +}
1073 +
1074 static inline void atomic64_set(atomic64_t *v, u64 i)
1075 {
1076 u64 tmp;
1077 @@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1078 : "cc");
1079 }
1080
1081 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1082 +{
1083 + u64 tmp;
1084 +
1085 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1086 +"1: ldrexd %0, %H0, [%2]\n"
1087 +" strexd %0, %3, %H3, [%2]\n"
1088 +" teq %0, #0\n"
1089 +" bne 1b"
1090 + : "=&r" (tmp), "=Qo" (v->counter)
1091 + : "r" (&v->counter), "r" (i)
1092 + : "cc");
1093 +}
1094 +
1095 static inline void atomic64_add(u64 i, atomic64_t *v)
1096 {
1097 u64 result;
1098 @@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1099 __asm__ __volatile__("@ atomic64_add\n"
1100 "1: ldrexd %0, %H0, [%3]\n"
1101 " adds %0, %0, %4\n"
1102 +" adcs %H0, %H0, %H4\n"
1103 +
1104 +#ifdef CONFIG_PAX_REFCOUNT
1105 +" bvc 3f\n"
1106 +"2: bkpt 0xf103\n"
1107 +"3:\n"
1108 +#endif
1109 +
1110 +" strexd %1, %0, %H0, [%3]\n"
1111 +" teq %1, #0\n"
1112 +" bne 1b"
1113 +
1114 +#ifdef CONFIG_PAX_REFCOUNT
1115 +"\n4:\n"
1116 + _ASM_EXTABLE(2b, 4b)
1117 +#endif
1118 +
1119 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1120 + : "r" (&v->counter), "r" (i)
1121 + : "cc");
1122 +}
1123 +
1124 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1125 +{
1126 + u64 result;
1127 + unsigned long tmp;
1128 +
1129 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1130 +"1: ldrexd %0, %H0, [%3]\n"
1131 +" adds %0, %0, %4\n"
1132 " adc %H0, %H0, %H4\n"
1133 " strexd %1, %0, %H0, [%3]\n"
1134 " teq %1, #0\n"
1135 @@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1136
1137 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1138 {
1139 - u64 result;
1140 - unsigned long tmp;
1141 + u64 result, tmp;
1142
1143 smp_mb();
1144
1145 __asm__ __volatile__("@ atomic64_add_return\n"
1146 +"1: ldrexd %1, %H1, [%3]\n"
1147 +" adds %0, %1, %4\n"
1148 +" adcs %H0, %H1, %H4\n"
1149 +
1150 +#ifdef CONFIG_PAX_REFCOUNT
1151 +" bvc 3f\n"
1152 +" mov %0, %1\n"
1153 +" mov %H0, %H1\n"
1154 +"2: bkpt 0xf103\n"
1155 +"3:\n"
1156 +#endif
1157 +
1158 +" strexd %1, %0, %H0, [%3]\n"
1159 +" teq %1, #0\n"
1160 +" bne 1b"
1161 +
1162 +#ifdef CONFIG_PAX_REFCOUNT
1163 +"\n4:\n"
1164 + _ASM_EXTABLE(2b, 4b)
1165 +#endif
1166 +
1167 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1168 + : "r" (&v->counter), "r" (i)
1169 + : "cc");
1170 +
1171 + smp_mb();
1172 +
1173 + return result;
1174 +}
1175 +
1176 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1177 +{
1178 + u64 result;
1179 + unsigned long tmp;
1180 +
1181 + smp_mb();
1182 +
1183 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1184 "1: ldrexd %0, %H0, [%3]\n"
1185 " adds %0, %0, %4\n"
1186 " adc %H0, %H0, %H4\n"
1187 @@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1188 __asm__ __volatile__("@ atomic64_sub\n"
1189 "1: ldrexd %0, %H0, [%3]\n"
1190 " subs %0, %0, %4\n"
1191 +" sbcs %H0, %H0, %H4\n"
1192 +
1193 +#ifdef CONFIG_PAX_REFCOUNT
1194 +" bvc 3f\n"
1195 +"2: bkpt 0xf103\n"
1196 +"3:\n"
1197 +#endif
1198 +
1199 +" strexd %1, %0, %H0, [%3]\n"
1200 +" teq %1, #0\n"
1201 +" bne 1b"
1202 +
1203 +#ifdef CONFIG_PAX_REFCOUNT
1204 +"\n4:\n"
1205 + _ASM_EXTABLE(2b, 4b)
1206 +#endif
1207 +
1208 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1209 + : "r" (&v->counter), "r" (i)
1210 + : "cc");
1211 +}
1212 +
1213 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1214 +{
1215 + u64 result;
1216 + unsigned long tmp;
1217 +
1218 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1219 +"1: ldrexd %0, %H0, [%3]\n"
1220 +" subs %0, %0, %4\n"
1221 " sbc %H0, %H0, %H4\n"
1222 " strexd %1, %0, %H0, [%3]\n"
1223 " teq %1, #0\n"
1224 @@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1225
1226 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1227 {
1228 - u64 result;
1229 - unsigned long tmp;
1230 + u64 result, tmp;
1231
1232 smp_mb();
1233
1234 __asm__ __volatile__("@ atomic64_sub_return\n"
1235 -"1: ldrexd %0, %H0, [%3]\n"
1236 -" subs %0, %0, %4\n"
1237 -" sbc %H0, %H0, %H4\n"
1238 +"1: ldrexd %1, %H1, [%3]\n"
1239 +" subs %0, %1, %4\n"
1240 +" sbc %H0, %H1, %H4\n"
1241 +
1242 +#ifdef CONFIG_PAX_REFCOUNT
1243 +" bvc 3f\n"
1244 +" mov %0, %1\n"
1245 +" mov %H0, %H1\n"
1246 +"2: bkpt 0xf103\n"
1247 +"3:\n"
1248 +#endif
1249 +
1250 " strexd %1, %0, %H0, [%3]\n"
1251 " teq %1, #0\n"
1252 " bne 1b"
1253 +
1254 +#ifdef CONFIG_PAX_REFCOUNT
1255 +"\n4:\n"
1256 + _ASM_EXTABLE(2b, 4b)
1257 +#endif
1258 +
1259 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1260 : "r" (&v->counter), "r" (i)
1261 : "cc");
1262 @@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1263 return oldval;
1264 }
1265
1266 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1267 +{
1268 + u64 oldval;
1269 + unsigned long res;
1270 +
1271 + smp_mb();
1272 +
1273 + do {
1274 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1275 + "ldrexd %1, %H1, [%3]\n"
1276 + "mov %0, #0\n"
1277 + "teq %1, %4\n"
1278 + "teqeq %H1, %H4\n"
1279 + "strexdeq %0, %5, %H5, [%3]"
1280 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1281 + : "r" (&ptr->counter), "r" (old), "r" (new)
1282 + : "cc");
1283 + } while (res);
1284 +
1285 + smp_mb();
1286 +
1287 + return oldval;
1288 +}
1289 +
1290 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1291 {
1292 u64 result;
1293 @@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1294
1295 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1296 {
1297 - u64 result;
1298 - unsigned long tmp;
1299 + u64 result, tmp;
1300
1301 smp_mb();
1302
1303 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1304 -"1: ldrexd %0, %H0, [%3]\n"
1305 -" subs %0, %0, #1\n"
1306 -" sbc %H0, %H0, #0\n"
1307 +"1: ldrexd %1, %H1, [%3]\n"
1308 +" subs %0, %1, #1\n"
1309 +" sbc %H0, %H1, #0\n"
1310 +
1311 +#ifdef CONFIG_PAX_REFCOUNT
1312 +" bvc 3f\n"
1313 +" mov %0, %1\n"
1314 +" mov %H0, %H1\n"
1315 +"2: bkpt 0xf103\n"
1316 +"3:\n"
1317 +#endif
1318 +
1319 " teq %H0, #0\n"
1320 -" bmi 2f\n"
1321 +" bmi 4f\n"
1322 " strexd %1, %0, %H0, [%3]\n"
1323 " teq %1, #0\n"
1324 " bne 1b\n"
1325 -"2:"
1326 +"4:\n"
1327 +
1328 +#ifdef CONFIG_PAX_REFCOUNT
1329 + _ASM_EXTABLE(2b, 4b)
1330 +#endif
1331 +
1332 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1333 : "r" (&v->counter)
1334 : "cc");
1335 @@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1336 " teq %0, %5\n"
1337 " teqeq %H0, %H5\n"
1338 " moveq %1, #0\n"
1339 -" beq 2f\n"
1340 +" beq 4f\n"
1341 " adds %0, %0, %6\n"
1342 " adc %H0, %H0, %H6\n"
1343 +
1344 +#ifdef CONFIG_PAX_REFCOUNT
1345 +" bvc 3f\n"
1346 +"2: bkpt 0xf103\n"
1347 +"3:\n"
1348 +#endif
1349 +
1350 " strexd %2, %0, %H0, [%4]\n"
1351 " teq %2, #0\n"
1352 " bne 1b\n"
1353 -"2:"
1354 +"4:\n"
1355 +
1356 +#ifdef CONFIG_PAX_REFCOUNT
1357 + _ASM_EXTABLE(2b, 4b)
1358 +#endif
1359 +
1360 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1361 : "r" (&v->counter), "r" (u), "r" (a)
1362 : "cc");
1363 @@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1364
1365 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1366 #define atomic64_inc(v) atomic64_add(1LL, (v))
1367 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1368 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1369 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1370 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1371 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1372 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1373 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1374 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1375 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1376 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1377 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1378 index 75fe66b..2255c86 100644
1379 --- a/arch/arm/include/asm/cache.h
1380 +++ b/arch/arm/include/asm/cache.h
1381 @@ -4,8 +4,10 @@
1382 #ifndef __ASMARM_CACHE_H
1383 #define __ASMARM_CACHE_H
1384
1385 +#include <linux/const.h>
1386 +
1387 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1388 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1389 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1390
1391 /*
1392 * Memory returned by kmalloc() may be used for DMA, so we must make
1393 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1394 index 1252a26..9dc17b5 100644
1395 --- a/arch/arm/include/asm/cacheflush.h
1396 +++ b/arch/arm/include/asm/cacheflush.h
1397 @@ -108,7 +108,7 @@ struct cpu_cache_fns {
1398 void (*dma_unmap_area)(const void *, size_t, int);
1399
1400 void (*dma_flush_range)(const void *, const void *);
1401 -};
1402 +} __no_const;
1403
1404 /*
1405 * Select the calling method
1406 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1407 index d41d7cb..9bea5e0 100644
1408 --- a/arch/arm/include/asm/cmpxchg.h
1409 +++ b/arch/arm/include/asm/cmpxchg.h
1410 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1411
1412 #define xchg(ptr,x) \
1413 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1414 +#define xchg_unchecked(ptr,x) \
1415 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1416
1417 #include <asm-generic/cmpxchg-local.h>
1418
1419 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1420 index 38050b1..9d90e8b 100644
1421 --- a/arch/arm/include/asm/elf.h
1422 +++ b/arch/arm/include/asm/elf.h
1423 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1424 the loader. We need to make sure that it is out of the way of the program
1425 that it will "exec", and that there is sufficient room for the brk. */
1426
1427 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1428 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1429 +
1430 +#ifdef CONFIG_PAX_ASLR
1431 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1432 +
1433 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1434 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1435 +#endif
1436
1437 /* When the program starts, a1 contains a pointer to a function to be
1438 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1439 @@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1440 extern void elf_set_personality(const struct elf32_hdr *);
1441 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1442
1443 -struct mm_struct;
1444 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1445 -#define arch_randomize_brk arch_randomize_brk
1446 -
1447 #endif
1448 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1449 index e51b1e8..32a3113 100644
1450 --- a/arch/arm/include/asm/kmap_types.h
1451 +++ b/arch/arm/include/asm/kmap_types.h
1452 @@ -21,6 +21,7 @@ enum km_type {
1453 KM_L1_CACHE,
1454 KM_L2_CACHE,
1455 KM_KDB,
1456 + KM_CLEARPAGE,
1457 KM_TYPE_NR
1458 };
1459
1460 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1461 index 53426c6..c7baff3 100644
1462 --- a/arch/arm/include/asm/outercache.h
1463 +++ b/arch/arm/include/asm/outercache.h
1464 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1465 #endif
1466 void (*set_debug)(unsigned long);
1467 void (*resume)(void);
1468 -};
1469 +} __no_const;
1470
1471 #ifdef CONFIG_OUTER_CACHE
1472
1473 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1474 index 5838361..da6e813 100644
1475 --- a/arch/arm/include/asm/page.h
1476 +++ b/arch/arm/include/asm/page.h
1477 @@ -123,7 +123,7 @@ struct cpu_user_fns {
1478 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1479 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1480 unsigned long vaddr, struct vm_area_struct *vma);
1481 -};
1482 +} __no_const;
1483
1484 #ifdef MULTI_USER
1485 extern struct cpu_user_fns cpu_user;
1486 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1487 index 943504f..bf8d667 100644
1488 --- a/arch/arm/include/asm/pgalloc.h
1489 +++ b/arch/arm/include/asm/pgalloc.h
1490 @@ -43,6 +43,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1491 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1492 }
1493
1494 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1495 +{
1496 + pud_populate(mm, pud, pmd);
1497 +}
1498 +
1499 #else /* !CONFIG_ARM_LPAE */
1500
1501 /*
1502 @@ -51,6 +56,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1503 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1504 #define pmd_free(mm, pmd) do { } while (0)
1505 #define pud_populate(mm,pmd,pte) BUG()
1506 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1507
1508 #endif /* CONFIG_ARM_LPAE */
1509
1510 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1511 index 0f04d84..2be5648 100644
1512 --- a/arch/arm/include/asm/thread_info.h
1513 +++ b/arch/arm/include/asm/thread_info.h
1514 @@ -148,6 +148,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1515 #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
1516 #define TIF_SYSCALL_TRACE 8
1517 #define TIF_SYSCALL_AUDIT 9
1518 +
1519 +/* within 8 bits of TIF_SYSCALL_TRACE
1520 + to meet flexible second operand requirements
1521 +*/
1522 +#define TIF_GRSEC_SETXID 10
1523 +
1524 #define TIF_POLLING_NRFLAG 16
1525 #define TIF_USING_IWMMXT 17
1526 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1527 @@ -163,9 +169,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1528 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1529 #define _TIF_RESTORE_SIGMASK (1 << TIF_RESTORE_SIGMASK)
1530 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1531 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1532
1533 /* Checks for any syscall work in entry-common.S */
1534 -#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
1535 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
1536 + _TIF_GRSEC_SETXID)
1537
1538 /*
1539 * Change these and you break ASM code in entry-common.S
1540 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1541 index 71f6536..602f279 100644
1542 --- a/arch/arm/include/asm/uaccess.h
1543 +++ b/arch/arm/include/asm/uaccess.h
1544 @@ -22,6 +22,8 @@
1545 #define VERIFY_READ 0
1546 #define VERIFY_WRITE 1
1547
1548 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
1549 +
1550 /*
1551 * The exception table consists of pairs of addresses: the first is the
1552 * address of an instruction that is allowed to fault, and the second is
1553 @@ -387,8 +389,23 @@ do { \
1554
1555
1556 #ifdef CONFIG_MMU
1557 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1558 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1559 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1560 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1561 +
1562 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1563 +{
1564 + if (!__builtin_constant_p(n))
1565 + check_object_size(to, n, false);
1566 + return ___copy_from_user(to, from, n);
1567 +}
1568 +
1569 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1570 +{
1571 + if (!__builtin_constant_p(n))
1572 + check_object_size(from, n, true);
1573 + return ___copy_to_user(to, from, n);
1574 +}
1575 +
1576 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1577 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1578 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1579 @@ -403,6 +420,9 @@ extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
1580
1581 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1582 {
1583 + if ((long)n < 0)
1584 + return n;
1585 +
1586 if (access_ok(VERIFY_READ, from, n))
1587 n = __copy_from_user(to, from, n);
1588 else /* security hole - plug it */
1589 @@ -412,6 +432,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1590
1591 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1592 {
1593 + if ((long)n < 0)
1594 + return n;
1595 +
1596 if (access_ok(VERIFY_WRITE, to, n))
1597 n = __copy_to_user(to, from, n);
1598 return n;
1599 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1600 index b57c75e..ed2d6b2 100644
1601 --- a/arch/arm/kernel/armksyms.c
1602 +++ b/arch/arm/kernel/armksyms.c
1603 @@ -94,8 +94,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
1604 #ifdef CONFIG_MMU
1605 EXPORT_SYMBOL(copy_page);
1606
1607 -EXPORT_SYMBOL(__copy_from_user);
1608 -EXPORT_SYMBOL(__copy_to_user);
1609 +EXPORT_SYMBOL(___copy_from_user);
1610 +EXPORT_SYMBOL(___copy_to_user);
1611 EXPORT_SYMBOL(__clear_user);
1612
1613 EXPORT_SYMBOL(__get_user_1);
1614 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1615 index 2b7b017..c380fa2 100644
1616 --- a/arch/arm/kernel/process.c
1617 +++ b/arch/arm/kernel/process.c
1618 @@ -28,7 +28,6 @@
1619 #include <linux/tick.h>
1620 #include <linux/utsname.h>
1621 #include <linux/uaccess.h>
1622 -#include <linux/random.h>
1623 #include <linux/hw_breakpoint.h>
1624 #include <linux/cpuidle.h>
1625
1626 @@ -275,9 +274,10 @@ void machine_power_off(void)
1627 machine_shutdown();
1628 if (pm_power_off)
1629 pm_power_off();
1630 + BUG();
1631 }
1632
1633 -void machine_restart(char *cmd)
1634 +__noreturn void machine_restart(char *cmd)
1635 {
1636 machine_shutdown();
1637
1638 @@ -519,12 +519,6 @@ unsigned long get_wchan(struct task_struct *p)
1639 return 0;
1640 }
1641
1642 -unsigned long arch_randomize_brk(struct mm_struct *mm)
1643 -{
1644 - unsigned long range_end = mm->brk + 0x02000000;
1645 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1646 -}
1647 -
1648 #ifdef CONFIG_MMU
1649 /*
1650 * The vectors page is always readable from user space for the
1651 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
1652 index 9650c14..ae30cdd 100644
1653 --- a/arch/arm/kernel/ptrace.c
1654 +++ b/arch/arm/kernel/ptrace.c
1655 @@ -906,10 +906,19 @@ long arch_ptrace(struct task_struct *child, long request,
1656 return ret;
1657 }
1658
1659 +#ifdef CONFIG_GRKERNSEC_SETXID
1660 +extern void gr_delayed_cred_worker(void);
1661 +#endif
1662 +
1663 asmlinkage int syscall_trace(int why, struct pt_regs *regs, int scno)
1664 {
1665 unsigned long ip;
1666
1667 +#ifdef CONFIG_GRKERNSEC_SETXID
1668 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
1669 + gr_delayed_cred_worker();
1670 +#endif
1671 +
1672 if (why)
1673 audit_syscall_exit(regs);
1674 else
1675 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1676 index ebfac78..cbea9c0 100644
1677 --- a/arch/arm/kernel/setup.c
1678 +++ b/arch/arm/kernel/setup.c
1679 @@ -111,13 +111,13 @@ struct processor processor __read_mostly;
1680 struct cpu_tlb_fns cpu_tlb __read_mostly;
1681 #endif
1682 #ifdef MULTI_USER
1683 -struct cpu_user_fns cpu_user __read_mostly;
1684 +struct cpu_user_fns cpu_user __read_only;
1685 #endif
1686 #ifdef MULTI_CACHE
1687 -struct cpu_cache_fns cpu_cache __read_mostly;
1688 +struct cpu_cache_fns cpu_cache __read_only;
1689 #endif
1690 #ifdef CONFIG_OUTER_CACHE
1691 -struct outer_cache_fns outer_cache __read_mostly;
1692 +struct outer_cache_fns outer_cache __read_only;
1693 EXPORT_SYMBOL(outer_cache);
1694 #endif
1695
1696 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1697 index 63d402f..db1d714 100644
1698 --- a/arch/arm/kernel/traps.c
1699 +++ b/arch/arm/kernel/traps.c
1700 @@ -264,6 +264,8 @@ static int __die(const char *str, int err, struct thread_info *thread, struct pt
1701
1702 static DEFINE_RAW_SPINLOCK(die_lock);
1703
1704 +extern void gr_handle_kernel_exploit(void);
1705 +
1706 /*
1707 * This function is protected against re-entrancy.
1708 */
1709 @@ -296,6 +298,9 @@ void die(const char *str, struct pt_regs *regs, int err)
1710 panic("Fatal exception in interrupt");
1711 if (panic_on_oops)
1712 panic("Fatal exception");
1713 +
1714 + gr_handle_kernel_exploit();
1715 +
1716 if (ret != NOTIFY_STOP)
1717 do_exit(SIGSEGV);
1718 }
1719 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1720 index 66a477a..bee61d3 100644
1721 --- a/arch/arm/lib/copy_from_user.S
1722 +++ b/arch/arm/lib/copy_from_user.S
1723 @@ -16,7 +16,7 @@
1724 /*
1725 * Prototype:
1726 *
1727 - * size_t __copy_from_user(void *to, const void *from, size_t n)
1728 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
1729 *
1730 * Purpose:
1731 *
1732 @@ -84,11 +84,11 @@
1733
1734 .text
1735
1736 -ENTRY(__copy_from_user)
1737 +ENTRY(___copy_from_user)
1738
1739 #include "copy_template.S"
1740
1741 -ENDPROC(__copy_from_user)
1742 +ENDPROC(___copy_from_user)
1743
1744 .pushsection .fixup,"ax"
1745 .align 0
1746 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1747 index 6ee2f67..d1cce76 100644
1748 --- a/arch/arm/lib/copy_page.S
1749 +++ b/arch/arm/lib/copy_page.S
1750 @@ -10,6 +10,7 @@
1751 * ASM optimised string functions
1752 */
1753 #include <linux/linkage.h>
1754 +#include <linux/const.h>
1755 #include <asm/assembler.h>
1756 #include <asm/asm-offsets.h>
1757 #include <asm/cache.h>
1758 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1759 index d066df6..df28194 100644
1760 --- a/arch/arm/lib/copy_to_user.S
1761 +++ b/arch/arm/lib/copy_to_user.S
1762 @@ -16,7 +16,7 @@
1763 /*
1764 * Prototype:
1765 *
1766 - * size_t __copy_to_user(void *to, const void *from, size_t n)
1767 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
1768 *
1769 * Purpose:
1770 *
1771 @@ -88,11 +88,11 @@
1772 .text
1773
1774 ENTRY(__copy_to_user_std)
1775 -WEAK(__copy_to_user)
1776 +WEAK(___copy_to_user)
1777
1778 #include "copy_template.S"
1779
1780 -ENDPROC(__copy_to_user)
1781 +ENDPROC(___copy_to_user)
1782 ENDPROC(__copy_to_user_std)
1783
1784 .pushsection .fixup,"ax"
1785 diff --git a/arch/arm/lib/uaccess.S b/arch/arm/lib/uaccess.S
1786 index 5c908b1..e712687 100644
1787 --- a/arch/arm/lib/uaccess.S
1788 +++ b/arch/arm/lib/uaccess.S
1789 @@ -20,7 +20,7 @@
1790
1791 #define PAGE_SHIFT 12
1792
1793 -/* Prototype: int __copy_to_user(void *to, const char *from, size_t n)
1794 +/* Prototype: int ___copy_to_user(void *to, const char *from, size_t n)
1795 * Purpose : copy a block to user memory from kernel memory
1796 * Params : to - user memory
1797 * : from - kernel memory
1798 @@ -40,7 +40,7 @@ USER( TUSER( strgtb) r3, [r0], #1) @ May fault
1799 sub r2, r2, ip
1800 b .Lc2u_dest_aligned
1801
1802 -ENTRY(__copy_to_user)
1803 +ENTRY(___copy_to_user)
1804 stmfd sp!, {r2, r4 - r7, lr}
1805 cmp r2, #4
1806 blt .Lc2u_not_enough
1807 @@ -278,14 +278,14 @@ USER( TUSER( strgeb) r3, [r0], #1) @ May fault
1808 ldrgtb r3, [r1], #0
1809 USER( TUSER( strgtb) r3, [r0], #1) @ May fault
1810 b .Lc2u_finished
1811 -ENDPROC(__copy_to_user)
1812 +ENDPROC(___copy_to_user)
1813
1814 .pushsection .fixup,"ax"
1815 .align 0
1816 9001: ldmfd sp!, {r0, r4 - r7, pc}
1817 .popsection
1818
1819 -/* Prototype: unsigned long __copy_from_user(void *to,const void *from,unsigned long n);
1820 +/* Prototype: unsigned long ___copy_from_user(void *to,const void *from,unsigned long n);
1821 * Purpose : copy a block from user memory to kernel memory
1822 * Params : to - kernel memory
1823 * : from - user memory
1824 @@ -304,7 +304,7 @@ USER( TUSER( ldrgtb) r3, [r1], #1) @ May fault
1825 sub r2, r2, ip
1826 b .Lcfu_dest_aligned
1827
1828 -ENTRY(__copy_from_user)
1829 +ENTRY(___copy_from_user)
1830 stmfd sp!, {r0, r2, r4 - r7, lr}
1831 cmp r2, #4
1832 blt .Lcfu_not_enough
1833 @@ -544,7 +544,7 @@ USER( TUSER( ldrgeb) r3, [r1], #1) @ May fault
1834 USER( TUSER( ldrgtb) r3, [r1], #1) @ May fault
1835 strgtb r3, [r0], #1
1836 b .Lcfu_finished
1837 -ENDPROC(__copy_from_user)
1838 +ENDPROC(___copy_from_user)
1839
1840 .pushsection .fixup,"ax"
1841 .align 0
1842 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1843 index 025f742..8432b08 100644
1844 --- a/arch/arm/lib/uaccess_with_memcpy.c
1845 +++ b/arch/arm/lib/uaccess_with_memcpy.c
1846 @@ -104,7 +104,7 @@ out:
1847 }
1848
1849 unsigned long
1850 -__copy_to_user(void __user *to, const void *from, unsigned long n)
1851 +___copy_to_user(void __user *to, const void *from, unsigned long n)
1852 {
1853 /*
1854 * This test is stubbed out of the main function above to keep
1855 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1856 index 518091c..eae9a76 100644
1857 --- a/arch/arm/mach-omap2/board-n8x0.c
1858 +++ b/arch/arm/mach-omap2/board-n8x0.c
1859 @@ -596,7 +596,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1860 }
1861 #endif
1862
1863 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1864 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1865 .late_init = n8x0_menelaus_late_init,
1866 };
1867
1868 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1869 index 5bb4835..4760f68 100644
1870 --- a/arch/arm/mm/fault.c
1871 +++ b/arch/arm/mm/fault.c
1872 @@ -174,6 +174,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1873 }
1874 #endif
1875
1876 +#ifdef CONFIG_PAX_PAGEEXEC
1877 + if (fsr & FSR_LNX_PF) {
1878 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1879 + do_group_exit(SIGKILL);
1880 + }
1881 +#endif
1882 +
1883 tsk->thread.address = addr;
1884 tsk->thread.error_code = fsr;
1885 tsk->thread.trap_no = 14;
1886 @@ -397,6 +404,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1887 }
1888 #endif /* CONFIG_MMU */
1889
1890 +#ifdef CONFIG_PAX_PAGEEXEC
1891 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1892 +{
1893 + long i;
1894 +
1895 + printk(KERN_ERR "PAX: bytes at PC: ");
1896 + for (i = 0; i < 20; i++) {
1897 + unsigned char c;
1898 + if (get_user(c, (__force unsigned char __user *)pc+i))
1899 + printk(KERN_CONT "?? ");
1900 + else
1901 + printk(KERN_CONT "%02x ", c);
1902 + }
1903 + printk("\n");
1904 +
1905 + printk(KERN_ERR "PAX: bytes at SP-4: ");
1906 + for (i = -1; i < 20; i++) {
1907 + unsigned long c;
1908 + if (get_user(c, (__force unsigned long __user *)sp+i))
1909 + printk(KERN_CONT "???????? ");
1910 + else
1911 + printk(KERN_CONT "%08lx ", c);
1912 + }
1913 + printk("\n");
1914 +}
1915 +#endif
1916 +
1917 /*
1918 * First Level Translation Fault Handler
1919 *
1920 @@ -577,6 +611,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1921 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1922 struct siginfo info;
1923
1924 +#ifdef CONFIG_PAX_REFCOUNT
1925 + if (fsr_fs(ifsr) == 2) {
1926 + unsigned int bkpt;
1927 +
1928 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1929 + current->thread.error_code = ifsr;
1930 + current->thread.trap_no = 0;
1931 + pax_report_refcount_overflow(regs);
1932 + fixup_exception(regs);
1933 + return;
1934 + }
1935 + }
1936 +#endif
1937 +
1938 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1939 return;
1940
1941 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1942 index ce8cb19..3ec539d 100644
1943 --- a/arch/arm/mm/mmap.c
1944 +++ b/arch/arm/mm/mmap.c
1945 @@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1946 if (len > TASK_SIZE)
1947 return -ENOMEM;
1948
1949 +#ifdef CONFIG_PAX_RANDMMAP
1950 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1951 +#endif
1952 +
1953 if (addr) {
1954 if (do_align)
1955 addr = COLOUR_ALIGN(addr, pgoff);
1956 @@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1957 addr = PAGE_ALIGN(addr);
1958
1959 vma = find_vma(mm, addr);
1960 - if (TASK_SIZE - len >= addr &&
1961 - (!vma || addr + len <= vma->vm_start))
1962 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1963 return addr;
1964 }
1965 if (len > mm->cached_hole_size) {
1966 - start_addr = addr = mm->free_area_cache;
1967 + start_addr = addr = mm->free_area_cache;
1968 } else {
1969 - start_addr = addr = mm->mmap_base;
1970 - mm->cached_hole_size = 0;
1971 + start_addr = addr = mm->mmap_base;
1972 + mm->cached_hole_size = 0;
1973 }
1974
1975 full_search:
1976 @@ -124,14 +127,14 @@ full_search:
1977 * Start a new search - just in case we missed
1978 * some holes.
1979 */
1980 - if (start_addr != TASK_UNMAPPED_BASE) {
1981 - start_addr = addr = TASK_UNMAPPED_BASE;
1982 + if (start_addr != mm->mmap_base) {
1983 + start_addr = addr = mm->mmap_base;
1984 mm->cached_hole_size = 0;
1985 goto full_search;
1986 }
1987 return -ENOMEM;
1988 }
1989 - if (!vma || addr + len <= vma->vm_start) {
1990 + if (check_heap_stack_gap(vma, addr, len)) {
1991 /*
1992 * Remember the place where we stopped the search:
1993 */
1994 @@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
1995
1996 if (mmap_is_legacy()) {
1997 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
1998 +
1999 +#ifdef CONFIG_PAX_RANDMMAP
2000 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2001 + mm->mmap_base += mm->delta_mmap;
2002 +#endif
2003 +
2004 mm->get_unmapped_area = arch_get_unmapped_area;
2005 mm->unmap_area = arch_unmap_area;
2006 } else {
2007 mm->mmap_base = mmap_base(random_factor);
2008 +
2009 +#ifdef CONFIG_PAX_RANDMMAP
2010 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2011 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2012 +#endif
2013 +
2014 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2015 mm->unmap_area = arch_unmap_area_topdown;
2016 }
2017 diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2018 index fd556f7..af2e7d2 100644
2019 --- a/arch/arm/plat-orion/include/plat/addr-map.h
2020 +++ b/arch/arm/plat-orion/include/plat/addr-map.h
2021 @@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2022 value in bridge_virt_base */
2023 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2024 const int win);
2025 -};
2026 +} __no_const;
2027
2028 /*
2029 * Information needed to setup one address mapping.
2030 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2031 index 71a6827..e7fbc23 100644
2032 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2033 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2034 @@ -43,7 +43,7 @@ struct samsung_dma_ops {
2035 int (*started)(unsigned ch);
2036 int (*flush)(unsigned ch);
2037 int (*stop)(unsigned ch);
2038 -};
2039 +} __no_const;
2040
2041 extern void *samsung_dmadev_get_ops(void);
2042 extern void *s3c_dma_get_ops(void);
2043 diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
2044 index 5f28cae..3d23723 100644
2045 --- a/arch/arm/plat-samsung/include/plat/ehci.h
2046 +++ b/arch/arm/plat-samsung/include/plat/ehci.h
2047 @@ -14,7 +14,7 @@
2048 struct s5p_ehci_platdata {
2049 int (*phy_init)(struct platform_device *pdev, int type);
2050 int (*phy_exit)(struct platform_device *pdev, int type);
2051 -};
2052 +} __no_const;
2053
2054 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
2055
2056 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2057 index c3a58a1..78fbf54 100644
2058 --- a/arch/avr32/include/asm/cache.h
2059 +++ b/arch/avr32/include/asm/cache.h
2060 @@ -1,8 +1,10 @@
2061 #ifndef __ASM_AVR32_CACHE_H
2062 #define __ASM_AVR32_CACHE_H
2063
2064 +#include <linux/const.h>
2065 +
2066 #define L1_CACHE_SHIFT 5
2067 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2068 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2069
2070 /*
2071 * Memory returned by kmalloc() may be used for DMA, so we must make
2072 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2073 index 3b3159b..425ea94 100644
2074 --- a/arch/avr32/include/asm/elf.h
2075 +++ b/arch/avr32/include/asm/elf.h
2076 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2077 the loader. We need to make sure that it is out of the way of the program
2078 that it will "exec", and that there is sufficient room for the brk. */
2079
2080 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2081 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2082
2083 +#ifdef CONFIG_PAX_ASLR
2084 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2085 +
2086 +#define PAX_DELTA_MMAP_LEN 15
2087 +#define PAX_DELTA_STACK_LEN 15
2088 +#endif
2089
2090 /* This yields a mask that user programs can use to figure out what
2091 instruction set this CPU supports. This could be done in user space,
2092 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2093 index b7f5c68..556135c 100644
2094 --- a/arch/avr32/include/asm/kmap_types.h
2095 +++ b/arch/avr32/include/asm/kmap_types.h
2096 @@ -22,7 +22,8 @@ D(10) KM_IRQ0,
2097 D(11) KM_IRQ1,
2098 D(12) KM_SOFTIRQ0,
2099 D(13) KM_SOFTIRQ1,
2100 -D(14) KM_TYPE_NR
2101 +D(14) KM_CLEARPAGE,
2102 +D(15) KM_TYPE_NR
2103 };
2104
2105 #undef D
2106 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2107 index f7040a1..db9f300 100644
2108 --- a/arch/avr32/mm/fault.c
2109 +++ b/arch/avr32/mm/fault.c
2110 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2111
2112 int exception_trace = 1;
2113
2114 +#ifdef CONFIG_PAX_PAGEEXEC
2115 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2116 +{
2117 + unsigned long i;
2118 +
2119 + printk(KERN_ERR "PAX: bytes at PC: ");
2120 + for (i = 0; i < 20; i++) {
2121 + unsigned char c;
2122 + if (get_user(c, (unsigned char *)pc+i))
2123 + printk(KERN_CONT "???????? ");
2124 + else
2125 + printk(KERN_CONT "%02x ", c);
2126 + }
2127 + printk("\n");
2128 +}
2129 +#endif
2130 +
2131 /*
2132 * This routine handles page faults. It determines the address and the
2133 * problem, and then passes it off to one of the appropriate routines.
2134 @@ -156,6 +173,16 @@ bad_area:
2135 up_read(&mm->mmap_sem);
2136
2137 if (user_mode(regs)) {
2138 +
2139 +#ifdef CONFIG_PAX_PAGEEXEC
2140 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2141 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2142 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2143 + do_group_exit(SIGKILL);
2144 + }
2145 + }
2146 +#endif
2147 +
2148 if (exception_trace && printk_ratelimit())
2149 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2150 "sp %08lx ecr %lu\n",
2151 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2152 index 568885a..f8008df 100644
2153 --- a/arch/blackfin/include/asm/cache.h
2154 +++ b/arch/blackfin/include/asm/cache.h
2155 @@ -7,6 +7,7 @@
2156 #ifndef __ARCH_BLACKFIN_CACHE_H
2157 #define __ARCH_BLACKFIN_CACHE_H
2158
2159 +#include <linux/const.h>
2160 #include <linux/linkage.h> /* for asmlinkage */
2161
2162 /*
2163 @@ -14,7 +15,7 @@
2164 * Blackfin loads 32 bytes for cache
2165 */
2166 #define L1_CACHE_SHIFT 5
2167 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2168 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2169 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2170
2171 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2172 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2173 index aea2718..3639a60 100644
2174 --- a/arch/cris/include/arch-v10/arch/cache.h
2175 +++ b/arch/cris/include/arch-v10/arch/cache.h
2176 @@ -1,8 +1,9 @@
2177 #ifndef _ASM_ARCH_CACHE_H
2178 #define _ASM_ARCH_CACHE_H
2179
2180 +#include <linux/const.h>
2181 /* Etrax 100LX have 32-byte cache-lines. */
2182 -#define L1_CACHE_BYTES 32
2183 #define L1_CACHE_SHIFT 5
2184 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2185
2186 #endif /* _ASM_ARCH_CACHE_H */
2187 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2188 index 1de779f..336fad3 100644
2189 --- a/arch/cris/include/arch-v32/arch/cache.h
2190 +++ b/arch/cris/include/arch-v32/arch/cache.h
2191 @@ -1,11 +1,12 @@
2192 #ifndef _ASM_CRIS_ARCH_CACHE_H
2193 #define _ASM_CRIS_ARCH_CACHE_H
2194
2195 +#include <linux/const.h>
2196 #include <arch/hwregs/dma.h>
2197
2198 /* A cache-line is 32 bytes. */
2199 -#define L1_CACHE_BYTES 32
2200 #define L1_CACHE_SHIFT 5
2201 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2202
2203 #define __read_mostly __attribute__((__section__(".data.read_mostly")))
2204
2205 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2206 index b86329d..6709906 100644
2207 --- a/arch/frv/include/asm/atomic.h
2208 +++ b/arch/frv/include/asm/atomic.h
2209 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
2210 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2211 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2212
2213 +#define atomic64_read_unchecked(v) atomic64_read(v)
2214 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2215 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2216 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2217 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2218 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2219 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2220 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2221 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2222 +
2223 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2224 {
2225 int c, old;
2226 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2227 index 2797163..c2a401d 100644
2228 --- a/arch/frv/include/asm/cache.h
2229 +++ b/arch/frv/include/asm/cache.h
2230 @@ -12,10 +12,11 @@
2231 #ifndef __ASM_CACHE_H
2232 #define __ASM_CACHE_H
2233
2234 +#include <linux/const.h>
2235
2236 /* bytes per L1 cache line */
2237 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2238 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2239 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2240
2241 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2242 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2243 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2244 index f8e16b2..c73ff79 100644
2245 --- a/arch/frv/include/asm/kmap_types.h
2246 +++ b/arch/frv/include/asm/kmap_types.h
2247 @@ -23,6 +23,7 @@ enum km_type {
2248 KM_IRQ1,
2249 KM_SOFTIRQ0,
2250 KM_SOFTIRQ1,
2251 + KM_CLEARPAGE,
2252 KM_TYPE_NR
2253 };
2254
2255 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2256 index 385fd30..6c3d97e 100644
2257 --- a/arch/frv/mm/elf-fdpic.c
2258 +++ b/arch/frv/mm/elf-fdpic.c
2259 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2260 if (addr) {
2261 addr = PAGE_ALIGN(addr);
2262 vma = find_vma(current->mm, addr);
2263 - if (TASK_SIZE - len >= addr &&
2264 - (!vma || addr + len <= vma->vm_start))
2265 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2266 goto success;
2267 }
2268
2269 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2270 for (; vma; vma = vma->vm_next) {
2271 if (addr > limit)
2272 break;
2273 - if (addr + len <= vma->vm_start)
2274 + if (check_heap_stack_gap(vma, addr, len))
2275 goto success;
2276 addr = vma->vm_end;
2277 }
2278 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2279 for (; vma; vma = vma->vm_next) {
2280 if (addr > limit)
2281 break;
2282 - if (addr + len <= vma->vm_start)
2283 + if (check_heap_stack_gap(vma, addr, len))
2284 goto success;
2285 addr = vma->vm_end;
2286 }
2287 diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2288 index c635028..6d9445a 100644
2289 --- a/arch/h8300/include/asm/cache.h
2290 +++ b/arch/h8300/include/asm/cache.h
2291 @@ -1,8 +1,10 @@
2292 #ifndef __ARCH_H8300_CACHE_H
2293 #define __ARCH_H8300_CACHE_H
2294
2295 +#include <linux/const.h>
2296 +
2297 /* bytes per L1 cache line */
2298 -#define L1_CACHE_BYTES 4
2299 +#define L1_CACHE_BYTES _AC(4,UL)
2300
2301 /* m68k-elf-gcc 2.95.2 doesn't like these */
2302
2303 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2304 index 0f01de2..d37d309 100644
2305 --- a/arch/hexagon/include/asm/cache.h
2306 +++ b/arch/hexagon/include/asm/cache.h
2307 @@ -21,9 +21,11 @@
2308 #ifndef __ASM_CACHE_H
2309 #define __ASM_CACHE_H
2310
2311 +#include <linux/const.h>
2312 +
2313 /* Bytes per L1 cache line */
2314 -#define L1_CACHE_SHIFT (5)
2315 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2316 +#define L1_CACHE_SHIFT 5
2317 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2318
2319 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2320 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2321 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2322 index 7d91166..88ab87e 100644
2323 --- a/arch/ia64/include/asm/atomic.h
2324 +++ b/arch/ia64/include/asm/atomic.h
2325 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2326 #define atomic64_inc(v) atomic64_add(1, (v))
2327 #define atomic64_dec(v) atomic64_sub(1, (v))
2328
2329 +#define atomic64_read_unchecked(v) atomic64_read(v)
2330 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2331 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2332 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2333 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2334 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2335 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2336 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2337 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2338 +
2339 /* Atomic operations are already serializing */
2340 #define smp_mb__before_atomic_dec() barrier()
2341 #define smp_mb__after_atomic_dec() barrier()
2342 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2343 index 988254a..e1ee885 100644
2344 --- a/arch/ia64/include/asm/cache.h
2345 +++ b/arch/ia64/include/asm/cache.h
2346 @@ -1,6 +1,7 @@
2347 #ifndef _ASM_IA64_CACHE_H
2348 #define _ASM_IA64_CACHE_H
2349
2350 +#include <linux/const.h>
2351
2352 /*
2353 * Copyright (C) 1998-2000 Hewlett-Packard Co
2354 @@ -9,7 +10,7 @@
2355
2356 /* Bytes per L1 (data) cache line. */
2357 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2358 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2359 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2360
2361 #ifdef CONFIG_SMP
2362 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2363 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2364 index b5298eb..67c6e62 100644
2365 --- a/arch/ia64/include/asm/elf.h
2366 +++ b/arch/ia64/include/asm/elf.h
2367 @@ -42,6 +42,13 @@
2368 */
2369 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2370
2371 +#ifdef CONFIG_PAX_ASLR
2372 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2373 +
2374 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2375 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2376 +#endif
2377 +
2378 #define PT_IA_64_UNWIND 0x70000001
2379
2380 /* IA-64 relocations: */
2381 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
2382 index 96a8d92..617a1cf 100644
2383 --- a/arch/ia64/include/asm/pgalloc.h
2384 +++ b/arch/ia64/include/asm/pgalloc.h
2385 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2386 pgd_val(*pgd_entry) = __pa(pud);
2387 }
2388
2389 +static inline void
2390 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2391 +{
2392 + pgd_populate(mm, pgd_entry, pud);
2393 +}
2394 +
2395 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
2396 {
2397 return quicklist_alloc(0, GFP_KERNEL, NULL);
2398 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2399 pud_val(*pud_entry) = __pa(pmd);
2400 }
2401
2402 +static inline void
2403 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2404 +{
2405 + pud_populate(mm, pud_entry, pmd);
2406 +}
2407 +
2408 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
2409 {
2410 return quicklist_alloc(0, GFP_KERNEL, NULL);
2411 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2412 index 815810c..d60bd4c 100644
2413 --- a/arch/ia64/include/asm/pgtable.h
2414 +++ b/arch/ia64/include/asm/pgtable.h
2415 @@ -12,7 +12,7 @@
2416 * David Mosberger-Tang <davidm@hpl.hp.com>
2417 */
2418
2419 -
2420 +#include <linux/const.h>
2421 #include <asm/mman.h>
2422 #include <asm/page.h>
2423 #include <asm/processor.h>
2424 @@ -142,6 +142,17 @@
2425 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2426 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2427 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2428 +
2429 +#ifdef CONFIG_PAX_PAGEEXEC
2430 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2431 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2432 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2433 +#else
2434 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2435 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2436 +# define PAGE_COPY_NOEXEC PAGE_COPY
2437 +#endif
2438 +
2439 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2440 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2441 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2442 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2443 index 54ff557..70c88b7 100644
2444 --- a/arch/ia64/include/asm/spinlock.h
2445 +++ b/arch/ia64/include/asm/spinlock.h
2446 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2447 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2448
2449 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2450 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2451 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2452 }
2453
2454 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2455 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2456 index 449c8c0..432a3d2 100644
2457 --- a/arch/ia64/include/asm/uaccess.h
2458 +++ b/arch/ia64/include/asm/uaccess.h
2459 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2460 const void *__cu_from = (from); \
2461 long __cu_len = (n); \
2462 \
2463 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
2464 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2465 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2466 __cu_len; \
2467 })
2468 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2469 long __cu_len = (n); \
2470 \
2471 __chk_user_ptr(__cu_from); \
2472 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
2473 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2474 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2475 __cu_len; \
2476 })
2477 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2478 index 24603be..948052d 100644
2479 --- a/arch/ia64/kernel/module.c
2480 +++ b/arch/ia64/kernel/module.c
2481 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2482 void
2483 module_free (struct module *mod, void *module_region)
2484 {
2485 - if (mod && mod->arch.init_unw_table &&
2486 - module_region == mod->module_init) {
2487 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2488 unw_remove_unwind_table(mod->arch.init_unw_table);
2489 mod->arch.init_unw_table = NULL;
2490 }
2491 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2492 }
2493
2494 static inline int
2495 +in_init_rx (const struct module *mod, uint64_t addr)
2496 +{
2497 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2498 +}
2499 +
2500 +static inline int
2501 +in_init_rw (const struct module *mod, uint64_t addr)
2502 +{
2503 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2504 +}
2505 +
2506 +static inline int
2507 in_init (const struct module *mod, uint64_t addr)
2508 {
2509 - return addr - (uint64_t) mod->module_init < mod->init_size;
2510 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2511 +}
2512 +
2513 +static inline int
2514 +in_core_rx (const struct module *mod, uint64_t addr)
2515 +{
2516 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2517 +}
2518 +
2519 +static inline int
2520 +in_core_rw (const struct module *mod, uint64_t addr)
2521 +{
2522 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2523 }
2524
2525 static inline int
2526 in_core (const struct module *mod, uint64_t addr)
2527 {
2528 - return addr - (uint64_t) mod->module_core < mod->core_size;
2529 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2530 }
2531
2532 static inline int
2533 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2534 break;
2535
2536 case RV_BDREL:
2537 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2538 + if (in_init_rx(mod, val))
2539 + val -= (uint64_t) mod->module_init_rx;
2540 + else if (in_init_rw(mod, val))
2541 + val -= (uint64_t) mod->module_init_rw;
2542 + else if (in_core_rx(mod, val))
2543 + val -= (uint64_t) mod->module_core_rx;
2544 + else if (in_core_rw(mod, val))
2545 + val -= (uint64_t) mod->module_core_rw;
2546 break;
2547
2548 case RV_LTV:
2549 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2550 * addresses have been selected...
2551 */
2552 uint64_t gp;
2553 - if (mod->core_size > MAX_LTOFF)
2554 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2555 /*
2556 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2557 * at the end of the module.
2558 */
2559 - gp = mod->core_size - MAX_LTOFF / 2;
2560 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2561 else
2562 - gp = mod->core_size / 2;
2563 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2564 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2565 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2566 mod->arch.gp = gp;
2567 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2568 }
2569 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2570 index 609d500..7dde2a8 100644
2571 --- a/arch/ia64/kernel/sys_ia64.c
2572 +++ b/arch/ia64/kernel/sys_ia64.c
2573 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2574 if (REGION_NUMBER(addr) == RGN_HPAGE)
2575 addr = 0;
2576 #endif
2577 +
2578 +#ifdef CONFIG_PAX_RANDMMAP
2579 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2580 + addr = mm->free_area_cache;
2581 + else
2582 +#endif
2583 +
2584 if (!addr)
2585 addr = mm->free_area_cache;
2586
2587 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2588 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2589 /* At this point: (!vma || addr < vma->vm_end). */
2590 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2591 - if (start_addr != TASK_UNMAPPED_BASE) {
2592 + if (start_addr != mm->mmap_base) {
2593 /* Start a new search --- just in case we missed some holes. */
2594 - addr = TASK_UNMAPPED_BASE;
2595 + addr = mm->mmap_base;
2596 goto full_search;
2597 }
2598 return -ENOMEM;
2599 }
2600 - if (!vma || addr + len <= vma->vm_start) {
2601 + if (check_heap_stack_gap(vma, addr, len)) {
2602 /* Remember the address where we stopped this search: */
2603 mm->free_area_cache = addr + len;
2604 return addr;
2605 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2606 index 0ccb28f..8992469 100644
2607 --- a/arch/ia64/kernel/vmlinux.lds.S
2608 +++ b/arch/ia64/kernel/vmlinux.lds.S
2609 @@ -198,7 +198,7 @@ SECTIONS {
2610 /* Per-cpu data: */
2611 . = ALIGN(PERCPU_PAGE_SIZE);
2612 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2613 - __phys_per_cpu_start = __per_cpu_load;
2614 + __phys_per_cpu_start = per_cpu_load;
2615 /*
2616 * ensure percpu data fits
2617 * into percpu page size
2618 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2619 index 02d29c2..ea893df 100644
2620 --- a/arch/ia64/mm/fault.c
2621 +++ b/arch/ia64/mm/fault.c
2622 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
2623 return pte_present(pte);
2624 }
2625
2626 +#ifdef CONFIG_PAX_PAGEEXEC
2627 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2628 +{
2629 + unsigned long i;
2630 +
2631 + printk(KERN_ERR "PAX: bytes at PC: ");
2632 + for (i = 0; i < 8; i++) {
2633 + unsigned int c;
2634 + if (get_user(c, (unsigned int *)pc+i))
2635 + printk(KERN_CONT "???????? ");
2636 + else
2637 + printk(KERN_CONT "%08x ", c);
2638 + }
2639 + printk("\n");
2640 +}
2641 +#endif
2642 +
2643 void __kprobes
2644 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
2645 {
2646 @@ -145,9 +162,23 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
2647 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
2648 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
2649
2650 - if ((vma->vm_flags & mask) != mask)
2651 + if ((vma->vm_flags & mask) != mask) {
2652 +
2653 +#ifdef CONFIG_PAX_PAGEEXEC
2654 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2655 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2656 + goto bad_area;
2657 +
2658 + up_read(&mm->mmap_sem);
2659 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2660 + do_group_exit(SIGKILL);
2661 + }
2662 +#endif
2663 +
2664 goto bad_area;
2665
2666 + }
2667 +
2668 /*
2669 * If for any reason at all we couldn't handle the fault, make
2670 * sure we exit gracefully rather than endlessly redo the
2671 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2672 index 5ca674b..e0e1b70 100644
2673 --- a/arch/ia64/mm/hugetlbpage.c
2674 +++ b/arch/ia64/mm/hugetlbpage.c
2675 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2676 /* At this point: (!vmm || addr < vmm->vm_end). */
2677 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2678 return -ENOMEM;
2679 - if (!vmm || (addr + len) <= vmm->vm_start)
2680 + if (check_heap_stack_gap(vmm, addr, len))
2681 return addr;
2682 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2683 }
2684 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2685 index 0eab454..bd794f2 100644
2686 --- a/arch/ia64/mm/init.c
2687 +++ b/arch/ia64/mm/init.c
2688 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
2689 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2690 vma->vm_end = vma->vm_start + PAGE_SIZE;
2691 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2692 +
2693 +#ifdef CONFIG_PAX_PAGEEXEC
2694 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2695 + vma->vm_flags &= ~VM_EXEC;
2696 +
2697 +#ifdef CONFIG_PAX_MPROTECT
2698 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
2699 + vma->vm_flags &= ~VM_MAYEXEC;
2700 +#endif
2701 +
2702 + }
2703 +#endif
2704 +
2705 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2706 down_write(&current->mm->mmap_sem);
2707 if (insert_vm_struct(current->mm, vma)) {
2708 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2709 index 40b3ee9..8c2c112 100644
2710 --- a/arch/m32r/include/asm/cache.h
2711 +++ b/arch/m32r/include/asm/cache.h
2712 @@ -1,8 +1,10 @@
2713 #ifndef _ASM_M32R_CACHE_H
2714 #define _ASM_M32R_CACHE_H
2715
2716 +#include <linux/const.h>
2717 +
2718 /* L1 cache line size */
2719 #define L1_CACHE_SHIFT 4
2720 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2721 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2722
2723 #endif /* _ASM_M32R_CACHE_H */
2724 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2725 index 82abd15..d95ae5d 100644
2726 --- a/arch/m32r/lib/usercopy.c
2727 +++ b/arch/m32r/lib/usercopy.c
2728 @@ -14,6 +14,9 @@
2729 unsigned long
2730 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2731 {
2732 + if ((long)n < 0)
2733 + return n;
2734 +
2735 prefetch(from);
2736 if (access_ok(VERIFY_WRITE, to, n))
2737 __copy_user(to,from,n);
2738 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2739 unsigned long
2740 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2741 {
2742 + if ((long)n < 0)
2743 + return n;
2744 +
2745 prefetchw(to);
2746 if (access_ok(VERIFY_READ, from, n))
2747 __copy_user_zeroing(to,from,n);
2748 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2749 index 0395c51..5f26031 100644
2750 --- a/arch/m68k/include/asm/cache.h
2751 +++ b/arch/m68k/include/asm/cache.h
2752 @@ -4,9 +4,11 @@
2753 #ifndef __ARCH_M68K_CACHE_H
2754 #define __ARCH_M68K_CACHE_H
2755
2756 +#include <linux/const.h>
2757 +
2758 /* bytes per L1 cache line */
2759 #define L1_CACHE_SHIFT 4
2760 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2761 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2762
2763 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2764
2765 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2766 index 4efe96a..60e8699 100644
2767 --- a/arch/microblaze/include/asm/cache.h
2768 +++ b/arch/microblaze/include/asm/cache.h
2769 @@ -13,11 +13,12 @@
2770 #ifndef _ASM_MICROBLAZE_CACHE_H
2771 #define _ASM_MICROBLAZE_CACHE_H
2772
2773 +#include <linux/const.h>
2774 #include <asm/registers.h>
2775
2776 #define L1_CACHE_SHIFT 5
2777 /* word-granular cache in microblaze */
2778 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2779 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2780
2781 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2782
2783 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2784 index 3f4c5cb..3439c6e 100644
2785 --- a/arch/mips/include/asm/atomic.h
2786 +++ b/arch/mips/include/asm/atomic.h
2787 @@ -21,6 +21,10 @@
2788 #include <asm/cmpxchg.h>
2789 #include <asm/war.h>
2790
2791 +#ifdef CONFIG_GENERIC_ATOMIC64
2792 +#include <asm-generic/atomic64.h>
2793 +#endif
2794 +
2795 #define ATOMIC_INIT(i) { (i) }
2796
2797 /*
2798 @@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2799 */
2800 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2801
2802 +#define atomic64_read_unchecked(v) atomic64_read(v)
2803 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2804 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2805 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2806 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2807 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2808 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2809 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2810 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2811 +
2812 #endif /* CONFIG_64BIT */
2813
2814 /*
2815 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2816 index b4db69f..8f3b093 100644
2817 --- a/arch/mips/include/asm/cache.h
2818 +++ b/arch/mips/include/asm/cache.h
2819 @@ -9,10 +9,11 @@
2820 #ifndef _ASM_CACHE_H
2821 #define _ASM_CACHE_H
2822
2823 +#include <linux/const.h>
2824 #include <kmalloc.h>
2825
2826 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2827 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2828 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2829
2830 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2831 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2832 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2833 index 455c0ac..ad65fbe 100644
2834 --- a/arch/mips/include/asm/elf.h
2835 +++ b/arch/mips/include/asm/elf.h
2836 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
2837 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2838 #endif
2839
2840 +#ifdef CONFIG_PAX_ASLR
2841 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2842 +
2843 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2844 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2845 +#endif
2846 +
2847 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2848 struct linux_binprm;
2849 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2850 int uses_interp);
2851
2852 -struct mm_struct;
2853 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2854 -#define arch_randomize_brk arch_randomize_brk
2855 -
2856 #endif /* _ASM_ELF_H */
2857 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
2858 index c1f6afa..38cc6e9 100644
2859 --- a/arch/mips/include/asm/exec.h
2860 +++ b/arch/mips/include/asm/exec.h
2861 @@ -12,6 +12,6 @@
2862 #ifndef _ASM_EXEC_H
2863 #define _ASM_EXEC_H
2864
2865 -extern unsigned long arch_align_stack(unsigned long sp);
2866 +#define arch_align_stack(x) ((x) & ~0xfUL)
2867
2868 #endif /* _ASM_EXEC_H */
2869 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2870 index da9bd7d..91aa7ab 100644
2871 --- a/arch/mips/include/asm/page.h
2872 +++ b/arch/mips/include/asm/page.h
2873 @@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2874 #ifdef CONFIG_CPU_MIPS32
2875 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2876 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2877 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2878 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2879 #else
2880 typedef struct { unsigned long long pte; } pte_t;
2881 #define pte_val(x) ((x).pte)
2882 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
2883 index 881d18b..cea38bc 100644
2884 --- a/arch/mips/include/asm/pgalloc.h
2885 +++ b/arch/mips/include/asm/pgalloc.h
2886 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2887 {
2888 set_pud(pud, __pud((unsigned long)pmd));
2889 }
2890 +
2891 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2892 +{
2893 + pud_populate(mm, pud, pmd);
2894 +}
2895 #endif
2896
2897 /*
2898 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
2899 index 0d85d8e..ec71487 100644
2900 --- a/arch/mips/include/asm/thread_info.h
2901 +++ b/arch/mips/include/asm/thread_info.h
2902 @@ -123,6 +123,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
2903 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
2904 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
2905 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
2906 +/* li takes a 32bit immediate */
2907 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
2908 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
2909
2910 #ifdef CONFIG_MIPS32_O32
2911 @@ -146,15 +148,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
2912 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
2913 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
2914 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
2915 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
2916 +
2917 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2918
2919 /* work to do in syscall_trace_leave() */
2920 -#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
2921 +#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2922
2923 /* work to do on interrupt/exception return */
2924 #define _TIF_WORK_MASK (0x0000ffef & \
2925 ~(_TIF_SECCOMP | _TIF_SYSCALL_AUDIT))
2926 /* work to do on any return to u-space */
2927 -#define _TIF_ALLWORK_MASK (0x8000ffff & ~_TIF_SECCOMP)
2928 +#define _TIF_ALLWORK_MASK ((0x8000ffff & ~_TIF_SECCOMP) | _TIF_GRSEC_SETXID)
2929
2930 #endif /* __KERNEL__ */
2931
2932 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2933 index 9fdd8bc..4bd7f1a 100644
2934 --- a/arch/mips/kernel/binfmt_elfn32.c
2935 +++ b/arch/mips/kernel/binfmt_elfn32.c
2936 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2937 #undef ELF_ET_DYN_BASE
2938 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2939
2940 +#ifdef CONFIG_PAX_ASLR
2941 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2942 +
2943 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2944 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2945 +#endif
2946 +
2947 #include <asm/processor.h>
2948 #include <linux/module.h>
2949 #include <linux/elfcore.h>
2950 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2951 index ff44823..97f8906 100644
2952 --- a/arch/mips/kernel/binfmt_elfo32.c
2953 +++ b/arch/mips/kernel/binfmt_elfo32.c
2954 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2955 #undef ELF_ET_DYN_BASE
2956 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2957
2958 +#ifdef CONFIG_PAX_ASLR
2959 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2960 +
2961 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2962 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2963 +#endif
2964 +
2965 #include <asm/processor.h>
2966
2967 /*
2968 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2969 index e9a5fd7..378809a 100644
2970 --- a/arch/mips/kernel/process.c
2971 +++ b/arch/mips/kernel/process.c
2972 @@ -480,15 +480,3 @@ unsigned long get_wchan(struct task_struct *task)
2973 out:
2974 return pc;
2975 }
2976 -
2977 -/*
2978 - * Don't forget that the stack pointer must be aligned on a 8 bytes
2979 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2980 - */
2981 -unsigned long arch_align_stack(unsigned long sp)
2982 -{
2983 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2984 - sp -= get_random_int() & ~PAGE_MASK;
2985 -
2986 - return sp & ALMASK;
2987 -}
2988 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
2989 index 7c24c29..e2f1981 100644
2990 --- a/arch/mips/kernel/ptrace.c
2991 +++ b/arch/mips/kernel/ptrace.c
2992 @@ -528,6 +528,10 @@ static inline int audit_arch(void)
2993 return arch;
2994 }
2995
2996 +#ifdef CONFIG_GRKERNSEC_SETXID
2997 +extern void gr_delayed_cred_worker(void);
2998 +#endif
2999 +
3000 /*
3001 * Notification of system call entry/exit
3002 * - triggered by current->work.syscall_trace
3003 @@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
3004 /* do the secure computing check first */
3005 secure_computing(regs->regs[2]);
3006
3007 +#ifdef CONFIG_GRKERNSEC_SETXID
3008 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3009 + gr_delayed_cred_worker();
3010 +#endif
3011 +
3012 if (!(current->ptrace & PT_PTRACED))
3013 goto out;
3014
3015 diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3016 index a632bc1..0b77c7c 100644
3017 --- a/arch/mips/kernel/scall32-o32.S
3018 +++ b/arch/mips/kernel/scall32-o32.S
3019 @@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3020
3021 stack_done:
3022 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3023 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3024 + li t1, _TIF_SYSCALL_WORK
3025 and t0, t1
3026 bnez t0, syscall_trace_entry # -> yes
3027
3028 diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3029 index 3b5a5e9..e1ee86d 100644
3030 --- a/arch/mips/kernel/scall64-64.S
3031 +++ b/arch/mips/kernel/scall64-64.S
3032 @@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
3033
3034 sd a3, PT_R26(sp) # save a3 for syscall restarting
3035
3036 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3037 + li t1, _TIF_SYSCALL_WORK
3038 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3039 and t0, t1, t0
3040 bnez t0, syscall_trace_entry
3041 diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
3042 index 6be6f70..1859577 100644
3043 --- a/arch/mips/kernel/scall64-n32.S
3044 +++ b/arch/mips/kernel/scall64-n32.S
3045 @@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
3046
3047 sd a3, PT_R26(sp) # save a3 for syscall restarting
3048
3049 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3050 + li t1, _TIF_SYSCALL_WORK
3051 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3052 and t0, t1, t0
3053 bnez t0, n32_syscall_trace_entry
3054 diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3055 index 5422855..74e63a3 100644
3056 --- a/arch/mips/kernel/scall64-o32.S
3057 +++ b/arch/mips/kernel/scall64-o32.S
3058 @@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3059 PTR 4b, bad_stack
3060 .previous
3061
3062 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3063 + li t1, _TIF_SYSCALL_WORK
3064 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3065 and t0, t1, t0
3066 bnez t0, trace_a_syscall
3067 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3068 index c14f6df..537e729 100644
3069 --- a/arch/mips/mm/fault.c
3070 +++ b/arch/mips/mm/fault.c
3071 @@ -27,6 +27,23 @@
3072 #include <asm/highmem.h> /* For VMALLOC_END */
3073 #include <linux/kdebug.h>
3074
3075 +#ifdef CONFIG_PAX_PAGEEXEC
3076 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3077 +{
3078 + unsigned long i;
3079 +
3080 + printk(KERN_ERR "PAX: bytes at PC: ");
3081 + for (i = 0; i < 5; i++) {
3082 + unsigned int c;
3083 + if (get_user(c, (unsigned int *)pc+i))
3084 + printk(KERN_CONT "???????? ");
3085 + else
3086 + printk(KERN_CONT "%08x ", c);
3087 + }
3088 + printk("\n");
3089 +}
3090 +#endif
3091 +
3092 /*
3093 * This routine handles page faults. It determines the address,
3094 * and the problem, and then passes it off to one of the appropriate
3095 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3096 index 302d779..7d35bf8 100644
3097 --- a/arch/mips/mm/mmap.c
3098 +++ b/arch/mips/mm/mmap.c
3099 @@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3100 do_color_align = 1;
3101
3102 /* requesting a specific address */
3103 +
3104 +#ifdef CONFIG_PAX_RANDMMAP
3105 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
3106 +#endif
3107 +
3108 if (addr) {
3109 if (do_color_align)
3110 addr = COLOUR_ALIGN(addr, pgoff);
3111 @@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3112 addr = PAGE_ALIGN(addr);
3113
3114 vma = find_vma(mm, addr);
3115 - if (TASK_SIZE - len >= addr &&
3116 - (!vma || addr + len <= vma->vm_start))
3117 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
3118 return addr;
3119 }
3120
3121 @@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3122 /* At this point: (!vma || addr < vma->vm_end). */
3123 if (TASK_SIZE - len < addr)
3124 return -ENOMEM;
3125 - if (!vma || addr + len <= vma->vm_start)
3126 + if (check_heap_stack_gap(vmm, addr, len))
3127 return addr;
3128 addr = vma->vm_end;
3129 if (do_color_align)
3130 @@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3131 /* make sure it can fit in the remaining address space */
3132 if (likely(addr > len)) {
3133 vma = find_vma(mm, addr - len);
3134 - if (!vma || addr <= vma->vm_start) {
3135 + if (check_heap_stack_gap(vmm, addr - len, len))
3136 /* cache the address as a hint for next time */
3137 return mm->free_area_cache = addr - len;
3138 }
3139 @@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3140 * return with success:
3141 */
3142 vma = find_vma(mm, addr);
3143 - if (likely(!vma || addr + len <= vma->vm_start)) {
3144 + if (check_heap_stack_gap(vmm, addr, len)) {
3145 /* cache the address as a hint for next time */
3146 return mm->free_area_cache = addr;
3147 }
3148 @@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3149 mm->unmap_area = arch_unmap_area_topdown;
3150 }
3151 }
3152 -
3153 -static inline unsigned long brk_rnd(void)
3154 -{
3155 - unsigned long rnd = get_random_int();
3156 -
3157 - rnd = rnd << PAGE_SHIFT;
3158 - /* 8MB for 32bit, 256MB for 64bit */
3159 - if (TASK_IS_32BIT_ADDR)
3160 - rnd = rnd & 0x7ffffful;
3161 - else
3162 - rnd = rnd & 0xffffffful;
3163 -
3164 - return rnd;
3165 -}
3166 -
3167 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3168 -{
3169 - unsigned long base = mm->brk;
3170 - unsigned long ret;
3171 -
3172 - ret = PAGE_ALIGN(base + brk_rnd());
3173 -
3174 - if (ret < mm->brk)
3175 - return mm->brk;
3176 -
3177 - return ret;
3178 -}
3179 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3180 index 967d144..db12197 100644
3181 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
3182 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3183 @@ -11,12 +11,14 @@
3184 #ifndef _ASM_PROC_CACHE_H
3185 #define _ASM_PROC_CACHE_H
3186
3187 +#include <linux/const.h>
3188 +
3189 /* L1 cache */
3190
3191 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3192 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
3193 -#define L1_CACHE_BYTES 16 /* bytes per entry */
3194 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
3195 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3196 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
3197
3198 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3199 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3200 index bcb5df2..84fabd2 100644
3201 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3202 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3203 @@ -16,13 +16,15 @@
3204 #ifndef _ASM_PROC_CACHE_H
3205 #define _ASM_PROC_CACHE_H
3206
3207 +#include <linux/const.h>
3208 +
3209 /*
3210 * L1 cache
3211 */
3212 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3213 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
3214 -#define L1_CACHE_BYTES 32 /* bytes per entry */
3215 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
3216 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3217 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
3218
3219 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3220 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
3221 index 4ce7a01..449202a 100644
3222 --- a/arch/openrisc/include/asm/cache.h
3223 +++ b/arch/openrisc/include/asm/cache.h
3224 @@ -19,11 +19,13 @@
3225 #ifndef __ASM_OPENRISC_CACHE_H
3226 #define __ASM_OPENRISC_CACHE_H
3227
3228 +#include <linux/const.h>
3229 +
3230 /* FIXME: How can we replace these with values from the CPU...
3231 * they shouldn't be hard-coded!
3232 */
3233
3234 -#define L1_CACHE_BYTES 16
3235 #define L1_CACHE_SHIFT 4
3236 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3237
3238 #endif /* __ASM_OPENRISC_CACHE_H */
3239 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
3240 index 6c6defc..d30653d 100644
3241 --- a/arch/parisc/include/asm/atomic.h
3242 +++ b/arch/parisc/include/asm/atomic.h
3243 @@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3244
3245 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3246
3247 +#define atomic64_read_unchecked(v) atomic64_read(v)
3248 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3249 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3250 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3251 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3252 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3253 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3254 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3255 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3256 +
3257 #endif /* !CONFIG_64BIT */
3258
3259
3260 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
3261 index 47f11c7..3420df2 100644
3262 --- a/arch/parisc/include/asm/cache.h
3263 +++ b/arch/parisc/include/asm/cache.h
3264 @@ -5,6 +5,7 @@
3265 #ifndef __ARCH_PARISC_CACHE_H
3266 #define __ARCH_PARISC_CACHE_H
3267
3268 +#include <linux/const.h>
3269
3270 /*
3271 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
3272 @@ -15,13 +16,13 @@
3273 * just ruin performance.
3274 */
3275 #ifdef CONFIG_PA20
3276 -#define L1_CACHE_BYTES 64
3277 #define L1_CACHE_SHIFT 6
3278 #else
3279 -#define L1_CACHE_BYTES 32
3280 #define L1_CACHE_SHIFT 5
3281 #endif
3282
3283 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3284 +
3285 #ifndef __ASSEMBLY__
3286
3287 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3288 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
3289 index 19f6cb1..6c78cf2 100644
3290 --- a/arch/parisc/include/asm/elf.h
3291 +++ b/arch/parisc/include/asm/elf.h
3292 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
3293
3294 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
3295
3296 +#ifdef CONFIG_PAX_ASLR
3297 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
3298 +
3299 +#define PAX_DELTA_MMAP_LEN 16
3300 +#define PAX_DELTA_STACK_LEN 16
3301 +#endif
3302 +
3303 /* This yields a mask that user programs can use to figure out what
3304 instruction set this CPU supports. This could be done in user space,
3305 but it's not easy, and we've already done it here. */
3306 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
3307 index fc987a1..6e068ef 100644
3308 --- a/arch/parisc/include/asm/pgalloc.h
3309 +++ b/arch/parisc/include/asm/pgalloc.h
3310 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3311 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
3312 }
3313
3314 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3315 +{
3316 + pgd_populate(mm, pgd, pmd);
3317 +}
3318 +
3319 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
3320 {
3321 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
3322 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
3323 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
3324 #define pmd_free(mm, x) do { } while (0)
3325 #define pgd_populate(mm, pmd, pte) BUG()
3326 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
3327
3328 #endif
3329
3330 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
3331 index ee99f23..802b0a1 100644
3332 --- a/arch/parisc/include/asm/pgtable.h
3333 +++ b/arch/parisc/include/asm/pgtable.h
3334 @@ -212,6 +212,17 @@ struct vm_area_struct;
3335 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3336 #define PAGE_COPY PAGE_EXECREAD
3337 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3338 +
3339 +#ifdef CONFIG_PAX_PAGEEXEC
3340 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3341 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3342 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3343 +#else
3344 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3345 +# define PAGE_COPY_NOEXEC PAGE_COPY
3346 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3347 +#endif
3348 +
3349 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3350 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3351 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3352 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
3353 index 9ac0660..6ed15c4 100644
3354 --- a/arch/parisc/include/asm/uaccess.h
3355 +++ b/arch/parisc/include/asm/uaccess.h
3356 @@ -252,10 +252,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
3357 const void __user *from,
3358 unsigned long n)
3359 {
3360 - int sz = __compiletime_object_size(to);
3361 + size_t sz = __compiletime_object_size(to);
3362 int ret = -EFAULT;
3363
3364 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
3365 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
3366 ret = __copy_from_user(to, from, n);
3367 else
3368 copy_from_user_overflow();
3369 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3370 index 5e34ccf..672bc9c 100644
3371 --- a/arch/parisc/kernel/module.c
3372 +++ b/arch/parisc/kernel/module.c
3373 @@ -98,16 +98,38 @@
3374
3375 /* three functions to determine where in the module core
3376 * or init pieces the location is */
3377 +static inline int in_init_rx(struct module *me, void *loc)
3378 +{
3379 + return (loc >= me->module_init_rx &&
3380 + loc < (me->module_init_rx + me->init_size_rx));
3381 +}
3382 +
3383 +static inline int in_init_rw(struct module *me, void *loc)
3384 +{
3385 + return (loc >= me->module_init_rw &&
3386 + loc < (me->module_init_rw + me->init_size_rw));
3387 +}
3388 +
3389 static inline int in_init(struct module *me, void *loc)
3390 {
3391 - return (loc >= me->module_init &&
3392 - loc <= (me->module_init + me->init_size));
3393 + return in_init_rx(me, loc) || in_init_rw(me, loc);
3394 +}
3395 +
3396 +static inline int in_core_rx(struct module *me, void *loc)
3397 +{
3398 + return (loc >= me->module_core_rx &&
3399 + loc < (me->module_core_rx + me->core_size_rx));
3400 +}
3401 +
3402 +static inline int in_core_rw(struct module *me, void *loc)
3403 +{
3404 + return (loc >= me->module_core_rw &&
3405 + loc < (me->module_core_rw + me->core_size_rw));
3406 }
3407
3408 static inline int in_core(struct module *me, void *loc)
3409 {
3410 - return (loc >= me->module_core &&
3411 - loc <= (me->module_core + me->core_size));
3412 + return in_core_rx(me, loc) || in_core_rw(me, loc);
3413 }
3414
3415 static inline int in_local(struct module *me, void *loc)
3416 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3417 }
3418
3419 /* align things a bit */
3420 - me->core_size = ALIGN(me->core_size, 16);
3421 - me->arch.got_offset = me->core_size;
3422 - me->core_size += gots * sizeof(struct got_entry);
3423 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3424 + me->arch.got_offset = me->core_size_rw;
3425 + me->core_size_rw += gots * sizeof(struct got_entry);
3426
3427 - me->core_size = ALIGN(me->core_size, 16);
3428 - me->arch.fdesc_offset = me->core_size;
3429 - me->core_size += fdescs * sizeof(Elf_Fdesc);
3430 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3431 + me->arch.fdesc_offset = me->core_size_rw;
3432 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3433
3434 me->arch.got_max = gots;
3435 me->arch.fdesc_max = fdescs;
3436 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3437
3438 BUG_ON(value == 0);
3439
3440 - got = me->module_core + me->arch.got_offset;
3441 + got = me->module_core_rw + me->arch.got_offset;
3442 for (i = 0; got[i].addr; i++)
3443 if (got[i].addr == value)
3444 goto out;
3445 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3446 #ifdef CONFIG_64BIT
3447 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3448 {
3449 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3450 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3451
3452 if (!value) {
3453 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3454 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3455
3456 /* Create new one */
3457 fdesc->addr = value;
3458 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3459 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3460 return (Elf_Addr)fdesc;
3461 }
3462 #endif /* CONFIG_64BIT */
3463 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3464
3465 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3466 end = table + sechdrs[me->arch.unwind_section].sh_size;
3467 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3468 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3469
3470 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3471 me->arch.unwind_section, table, end, gp);
3472 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3473 index c9b9322..02d8940 100644
3474 --- a/arch/parisc/kernel/sys_parisc.c
3475 +++ b/arch/parisc/kernel/sys_parisc.c
3476 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3477 /* At this point: (!vma || addr < vma->vm_end). */
3478 if (TASK_SIZE - len < addr)
3479 return -ENOMEM;
3480 - if (!vma || addr + len <= vma->vm_start)
3481 + if (check_heap_stack_gap(vma, addr, len))
3482 return addr;
3483 addr = vma->vm_end;
3484 }
3485 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3486 /* At this point: (!vma || addr < vma->vm_end). */
3487 if (TASK_SIZE - len < addr)
3488 return -ENOMEM;
3489 - if (!vma || addr + len <= vma->vm_start)
3490 + if (check_heap_stack_gap(vma, addr, len))
3491 return addr;
3492 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3493 if (addr < vma->vm_end) /* handle wraparound */
3494 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3495 if (flags & MAP_FIXED)
3496 return addr;
3497 if (!addr)
3498 - addr = TASK_UNMAPPED_BASE;
3499 + addr = current->mm->mmap_base;
3500
3501 if (filp) {
3502 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3503 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3504 index 45ba99f..8e22c33 100644
3505 --- a/arch/parisc/kernel/traps.c
3506 +++ b/arch/parisc/kernel/traps.c
3507 @@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3508
3509 down_read(&current->mm->mmap_sem);
3510 vma = find_vma(current->mm,regs->iaoq[0]);
3511 - if (vma && (regs->iaoq[0] >= vma->vm_start)
3512 - && (vma->vm_flags & VM_EXEC)) {
3513 -
3514 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3515 fault_address = regs->iaoq[0];
3516 fault_space = regs->iasq[0];
3517
3518 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3519 index 18162ce..94de376 100644
3520 --- a/arch/parisc/mm/fault.c
3521 +++ b/arch/parisc/mm/fault.c
3522 @@ -15,6 +15,7 @@
3523 #include <linux/sched.h>
3524 #include <linux/interrupt.h>
3525 #include <linux/module.h>
3526 +#include <linux/unistd.h>
3527
3528 #include <asm/uaccess.h>
3529 #include <asm/traps.h>
3530 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3531 static unsigned long
3532 parisc_acctyp(unsigned long code, unsigned int inst)
3533 {
3534 - if (code == 6 || code == 16)
3535 + if (code == 6 || code == 7 || code == 16)
3536 return VM_EXEC;
3537
3538 switch (inst & 0xf0000000) {
3539 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3540 }
3541 #endif
3542
3543 +#ifdef CONFIG_PAX_PAGEEXEC
3544 +/*
3545 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3546 + *
3547 + * returns 1 when task should be killed
3548 + * 2 when rt_sigreturn trampoline was detected
3549 + * 3 when unpatched PLT trampoline was detected
3550 + */
3551 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3552 +{
3553 +
3554 +#ifdef CONFIG_PAX_EMUPLT
3555 + int err;
3556 +
3557 + do { /* PaX: unpatched PLT emulation */
3558 + unsigned int bl, depwi;
3559 +
3560 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3561 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3562 +
3563 + if (err)
3564 + break;
3565 +
3566 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3567 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3568 +
3569 + err = get_user(ldw, (unsigned int *)addr);
3570 + err |= get_user(bv, (unsigned int *)(addr+4));
3571 + err |= get_user(ldw2, (unsigned int *)(addr+8));
3572 +
3573 + if (err)
3574 + break;
3575 +
3576 + if (ldw == 0x0E801096U &&
3577 + bv == 0xEAC0C000U &&
3578 + ldw2 == 0x0E881095U)
3579 + {
3580 + unsigned int resolver, map;
3581 +
3582 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3583 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3584 + if (err)
3585 + break;
3586 +
3587 + regs->gr[20] = instruction_pointer(regs)+8;
3588 + regs->gr[21] = map;
3589 + regs->gr[22] = resolver;
3590 + regs->iaoq[0] = resolver | 3UL;
3591 + regs->iaoq[1] = regs->iaoq[0] + 4;
3592 + return 3;
3593 + }
3594 + }
3595 + } while (0);
3596 +#endif
3597 +
3598 +#ifdef CONFIG_PAX_EMUTRAMP
3599 +
3600 +#ifndef CONFIG_PAX_EMUSIGRT
3601 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3602 + return 1;
3603 +#endif
3604 +
3605 + do { /* PaX: rt_sigreturn emulation */
3606 + unsigned int ldi1, ldi2, bel, nop;
3607 +
3608 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3609 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3610 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3611 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3612 +
3613 + if (err)
3614 + break;
3615 +
3616 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3617 + ldi2 == 0x3414015AU &&
3618 + bel == 0xE4008200U &&
3619 + nop == 0x08000240U)
3620 + {
3621 + regs->gr[25] = (ldi1 & 2) >> 1;
3622 + regs->gr[20] = __NR_rt_sigreturn;
3623 + regs->gr[31] = regs->iaoq[1] + 16;
3624 + regs->sr[0] = regs->iasq[1];
3625 + regs->iaoq[0] = 0x100UL;
3626 + regs->iaoq[1] = regs->iaoq[0] + 4;
3627 + regs->iasq[0] = regs->sr[2];
3628 + regs->iasq[1] = regs->sr[2];
3629 + return 2;
3630 + }
3631 + } while (0);
3632 +#endif
3633 +
3634 + return 1;
3635 +}
3636 +
3637 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3638 +{
3639 + unsigned long i;
3640 +
3641 + printk(KERN_ERR "PAX: bytes at PC: ");
3642 + for (i = 0; i < 5; i++) {
3643 + unsigned int c;
3644 + if (get_user(c, (unsigned int *)pc+i))
3645 + printk(KERN_CONT "???????? ");
3646 + else
3647 + printk(KERN_CONT "%08x ", c);
3648 + }
3649 + printk("\n");
3650 +}
3651 +#endif
3652 +
3653 int fixup_exception(struct pt_regs *regs)
3654 {
3655 const struct exception_table_entry *fix;
3656 @@ -192,8 +303,33 @@ good_area:
3657
3658 acc_type = parisc_acctyp(code,regs->iir);
3659
3660 - if ((vma->vm_flags & acc_type) != acc_type)
3661 + if ((vma->vm_flags & acc_type) != acc_type) {
3662 +
3663 +#ifdef CONFIG_PAX_PAGEEXEC
3664 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3665 + (address & ~3UL) == instruction_pointer(regs))
3666 + {
3667 + up_read(&mm->mmap_sem);
3668 + switch (pax_handle_fetch_fault(regs)) {
3669 +
3670 +#ifdef CONFIG_PAX_EMUPLT
3671 + case 3:
3672 + return;
3673 +#endif
3674 +
3675 +#ifdef CONFIG_PAX_EMUTRAMP
3676 + case 2:
3677 + return;
3678 +#endif
3679 +
3680 + }
3681 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3682 + do_group_exit(SIGKILL);
3683 + }
3684 +#endif
3685 +
3686 goto bad_area;
3687 + }
3688
3689 /*
3690 * If for any reason at all we couldn't handle the fault, make
3691 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3692 index da29032..f76c24c 100644
3693 --- a/arch/powerpc/include/asm/atomic.h
3694 +++ b/arch/powerpc/include/asm/atomic.h
3695 @@ -522,6 +522,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
3696 return t1;
3697 }
3698
3699 +#define atomic64_read_unchecked(v) atomic64_read(v)
3700 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3701 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3702 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3703 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3704 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3705 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3706 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3707 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3708 +
3709 #endif /* __powerpc64__ */
3710
3711 #endif /* __KERNEL__ */
3712 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3713 index 9e495c9..b6878e5 100644
3714 --- a/arch/powerpc/include/asm/cache.h
3715 +++ b/arch/powerpc/include/asm/cache.h
3716 @@ -3,6 +3,7 @@
3717
3718 #ifdef __KERNEL__
3719
3720 +#include <linux/const.h>
3721
3722 /* bytes per L1 cache line */
3723 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3724 @@ -22,7 +23,7 @@
3725 #define L1_CACHE_SHIFT 7
3726 #endif
3727
3728 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3729 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3730
3731 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3732
3733 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3734 index 3bf9cca..e7457d0 100644
3735 --- a/arch/powerpc/include/asm/elf.h
3736 +++ b/arch/powerpc/include/asm/elf.h
3737 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3738 the loader. We need to make sure that it is out of the way of the program
3739 that it will "exec", and that there is sufficient room for the brk. */
3740
3741 -extern unsigned long randomize_et_dyn(unsigned long base);
3742 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3743 +#define ELF_ET_DYN_BASE (0x20000000)
3744 +
3745 +#ifdef CONFIG_PAX_ASLR
3746 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3747 +
3748 +#ifdef __powerpc64__
3749 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3750 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3751 +#else
3752 +#define PAX_DELTA_MMAP_LEN 15
3753 +#define PAX_DELTA_STACK_LEN 15
3754 +#endif
3755 +#endif
3756
3757 /*
3758 * Our registers are always unsigned longs, whether we're a 32 bit
3759 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3760 (0x7ff >> (PAGE_SHIFT - 12)) : \
3761 (0x3ffff >> (PAGE_SHIFT - 12)))
3762
3763 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3764 -#define arch_randomize_brk arch_randomize_brk
3765 -
3766 #endif /* __KERNEL__ */
3767
3768 /*
3769 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
3770 index 8196e9c..d83a9f3 100644
3771 --- a/arch/powerpc/include/asm/exec.h
3772 +++ b/arch/powerpc/include/asm/exec.h
3773 @@ -4,6 +4,6 @@
3774 #ifndef _ASM_POWERPC_EXEC_H
3775 #define _ASM_POWERPC_EXEC_H
3776
3777 -extern unsigned long arch_align_stack(unsigned long sp);
3778 +#define arch_align_stack(x) ((x) & ~0xfUL)
3779
3780 #endif /* _ASM_POWERPC_EXEC_H */
3781 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3782 index bca8fdc..61e9580 100644
3783 --- a/arch/powerpc/include/asm/kmap_types.h
3784 +++ b/arch/powerpc/include/asm/kmap_types.h
3785 @@ -27,6 +27,7 @@ enum km_type {
3786 KM_PPC_SYNC_PAGE,
3787 KM_PPC_SYNC_ICACHE,
3788 KM_KDB,
3789 + KM_CLEARPAGE,
3790 KM_TYPE_NR
3791 };
3792
3793 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3794 index d4a7f64..451de1c 100644
3795 --- a/arch/powerpc/include/asm/mman.h
3796 +++ b/arch/powerpc/include/asm/mman.h
3797 @@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3798 }
3799 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3800
3801 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3802 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3803 {
3804 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3805 }
3806 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3807 index f072e97..b436dee 100644
3808 --- a/arch/powerpc/include/asm/page.h
3809 +++ b/arch/powerpc/include/asm/page.h
3810 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3811 * and needs to be executable. This means the whole heap ends
3812 * up being executable.
3813 */
3814 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3815 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3816 +#define VM_DATA_DEFAULT_FLAGS32 \
3817 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3818 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3819
3820 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3821 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3822 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3823 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3824 #endif
3825
3826 +#define ktla_ktva(addr) (addr)
3827 +#define ktva_ktla(addr) (addr)
3828 +
3829 /*
3830 * Use the top bit of the higher-level page table entries to indicate whether
3831 * the entries we point to contain hugepages. This works because we know that
3832 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3833 index fed85e6..da5c71b 100644
3834 --- a/arch/powerpc/include/asm/page_64.h
3835 +++ b/arch/powerpc/include/asm/page_64.h
3836 @@ -146,15 +146,18 @@ do { \
3837 * stack by default, so in the absence of a PT_GNU_STACK program header
3838 * we turn execute permission off.
3839 */
3840 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3841 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3842 +#define VM_STACK_DEFAULT_FLAGS32 \
3843 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3844 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3845
3846 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3847 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3848
3849 +#ifndef CONFIG_PAX_PAGEEXEC
3850 #define VM_STACK_DEFAULT_FLAGS \
3851 (is_32bit_task() ? \
3852 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3853 +#endif
3854
3855 #include <asm-generic/getorder.h>
3856
3857 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
3858 index 292725c..f87ae14 100644
3859 --- a/arch/powerpc/include/asm/pgalloc-64.h
3860 +++ b/arch/powerpc/include/asm/pgalloc-64.h
3861 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3862 #ifndef CONFIG_PPC_64K_PAGES
3863
3864 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
3865 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
3866
3867 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3868 {
3869 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3870 pud_set(pud, (unsigned long)pmd);
3871 }
3872
3873 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3874 +{
3875 + pud_populate(mm, pud, pmd);
3876 +}
3877 +
3878 #define pmd_populate(mm, pmd, pte_page) \
3879 pmd_populate_kernel(mm, pmd, page_address(pte_page))
3880 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
3881 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3882 #else /* CONFIG_PPC_64K_PAGES */
3883
3884 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
3885 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
3886
3887 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
3888 pte_t *pte)
3889 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3890 index 2e0e411..7899c68 100644
3891 --- a/arch/powerpc/include/asm/pgtable.h
3892 +++ b/arch/powerpc/include/asm/pgtable.h
3893 @@ -2,6 +2,7 @@
3894 #define _ASM_POWERPC_PGTABLE_H
3895 #ifdef __KERNEL__
3896
3897 +#include <linux/const.h>
3898 #ifndef __ASSEMBLY__
3899 #include <asm/processor.h> /* For TASK_SIZE */
3900 #include <asm/mmu.h>
3901 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3902 index 4aad413..85d86bf 100644
3903 --- a/arch/powerpc/include/asm/pte-hash32.h
3904 +++ b/arch/powerpc/include/asm/pte-hash32.h
3905 @@ -21,6 +21,7 @@
3906 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3907 #define _PAGE_USER 0x004 /* usermode access allowed */
3908 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3909 +#define _PAGE_EXEC _PAGE_GUARDED
3910 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3911 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3912 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3913 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3914 index 9d7f0fb..a28fe69 100644
3915 --- a/arch/powerpc/include/asm/reg.h
3916 +++ b/arch/powerpc/include/asm/reg.h
3917 @@ -212,6 +212,7 @@
3918 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3919 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3920 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3921 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3922 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3923 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3924 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3925 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
3926 index 4a741c7..c8162227b 100644
3927 --- a/arch/powerpc/include/asm/thread_info.h
3928 +++ b/arch/powerpc/include/asm/thread_info.h
3929 @@ -104,12 +104,14 @@ static inline struct thread_info *current_thread_info(void)
3930 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
3931 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
3932 #define TIF_SINGLESTEP 8 /* singlestepping active */
3933 -#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
3934 #define TIF_SECCOMP 10 /* secure computing */
3935 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
3936 #define TIF_NOERROR 12 /* Force successful syscall return */
3937 #define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
3938 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
3939 +#define TIF_MEMDIE 16 /* is terminating due to OOM killer */
3940 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
3941 +#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
3942
3943 /* as above, but as bit values */
3944 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3945 @@ -127,8 +129,11 @@ static inline struct thread_info *current_thread_info(void)
3946 #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
3947 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
3948 #define _TIF_RUNLATCH (1<<TIF_RUNLATCH)
3949 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3950 +
3951 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
3952 - _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
3953 + _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT \
3954 + _TIF_GRSEC_SETXID)
3955
3956 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
3957 _TIF_NOTIFY_RESUME)
3958 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3959 index bd0fb84..a42a14b 100644
3960 --- a/arch/powerpc/include/asm/uaccess.h
3961 +++ b/arch/powerpc/include/asm/uaccess.h
3962 @@ -13,6 +13,8 @@
3963 #define VERIFY_READ 0
3964 #define VERIFY_WRITE 1
3965
3966 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3967 +
3968 /*
3969 * The fs value determines whether argument validity checking should be
3970 * performed or not. If get_fs() == USER_DS, checking is performed, with
3971 @@ -327,52 +329,6 @@ do { \
3972 extern unsigned long __copy_tofrom_user(void __user *to,
3973 const void __user *from, unsigned long size);
3974
3975 -#ifndef __powerpc64__
3976 -
3977 -static inline unsigned long copy_from_user(void *to,
3978 - const void __user *from, unsigned long n)
3979 -{
3980 - unsigned long over;
3981 -
3982 - if (access_ok(VERIFY_READ, from, n))
3983 - return __copy_tofrom_user((__force void __user *)to, from, n);
3984 - if ((unsigned long)from < TASK_SIZE) {
3985 - over = (unsigned long)from + n - TASK_SIZE;
3986 - return __copy_tofrom_user((__force void __user *)to, from,
3987 - n - over) + over;
3988 - }
3989 - return n;
3990 -}
3991 -
3992 -static inline unsigned long copy_to_user(void __user *to,
3993 - const void *from, unsigned long n)
3994 -{
3995 - unsigned long over;
3996 -
3997 - if (access_ok(VERIFY_WRITE, to, n))
3998 - return __copy_tofrom_user(to, (__force void __user *)from, n);
3999 - if ((unsigned long)to < TASK_SIZE) {
4000 - over = (unsigned long)to + n - TASK_SIZE;
4001 - return __copy_tofrom_user(to, (__force void __user *)from,
4002 - n - over) + over;
4003 - }
4004 - return n;
4005 -}
4006 -
4007 -#else /* __powerpc64__ */
4008 -
4009 -#define __copy_in_user(to, from, size) \
4010 - __copy_tofrom_user((to), (from), (size))
4011 -
4012 -extern unsigned long copy_from_user(void *to, const void __user *from,
4013 - unsigned long n);
4014 -extern unsigned long copy_to_user(void __user *to, const void *from,
4015 - unsigned long n);
4016 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
4017 - unsigned long n);
4018 -
4019 -#endif /* __powerpc64__ */
4020 -
4021 static inline unsigned long __copy_from_user_inatomic(void *to,
4022 const void __user *from, unsigned long n)
4023 {
4024 @@ -396,6 +352,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
4025 if (ret == 0)
4026 return 0;
4027 }
4028 +
4029 + if (!__builtin_constant_p(n))
4030 + check_object_size(to, n, false);
4031 +
4032 return __copy_tofrom_user((__force void __user *)to, from, n);
4033 }
4034
4035 @@ -422,6 +382,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
4036 if (ret == 0)
4037 return 0;
4038 }
4039 +
4040 + if (!__builtin_constant_p(n))
4041 + check_object_size(from, n, true);
4042 +
4043 return __copy_tofrom_user(to, (__force const void __user *)from, n);
4044 }
4045
4046 @@ -439,6 +403,92 @@ static inline unsigned long __copy_to_user(void __user *to,
4047 return __copy_to_user_inatomic(to, from, size);
4048 }
4049
4050 +#ifndef __powerpc64__
4051 +
4052 +static inline unsigned long __must_check copy_from_user(void *to,
4053 + const void __user *from, unsigned long n)
4054 +{
4055 + unsigned long over;
4056 +
4057 + if ((long)n < 0)
4058 + return n;
4059 +
4060 + if (access_ok(VERIFY_READ, from, n)) {
4061 + if (!__builtin_constant_p(n))
4062 + check_object_size(to, n, false);
4063 + return __copy_tofrom_user((__force void __user *)to, from, n);
4064 + }
4065 + if ((unsigned long)from < TASK_SIZE) {
4066 + over = (unsigned long)from + n - TASK_SIZE;
4067 + if (!__builtin_constant_p(n - over))
4068 + check_object_size(to, n - over, false);
4069 + return __copy_tofrom_user((__force void __user *)to, from,
4070 + n - over) + over;
4071 + }
4072 + return n;
4073 +}
4074 +
4075 +static inline unsigned long __must_check copy_to_user(void __user *to,
4076 + const void *from, unsigned long n)
4077 +{
4078 + unsigned long over;
4079 +
4080 + if ((long)n < 0)
4081 + return n;
4082 +
4083 + if (access_ok(VERIFY_WRITE, to, n)) {
4084 + if (!__builtin_constant_p(n))
4085 + check_object_size(from, n, true);
4086 + return __copy_tofrom_user(to, (__force void __user *)from, n);
4087 + }
4088 + if ((unsigned long)to < TASK_SIZE) {
4089 + over = (unsigned long)to + n - TASK_SIZE;
4090 + if (!__builtin_constant_p(n))
4091 + check_object_size(from, n - over, true);
4092 + return __copy_tofrom_user(to, (__force void __user *)from,
4093 + n - over) + over;
4094 + }
4095 + return n;
4096 +}
4097 +
4098 +#else /* __powerpc64__ */
4099 +
4100 +#define __copy_in_user(to, from, size) \
4101 + __copy_tofrom_user((to), (from), (size))
4102 +
4103 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4104 +{
4105 + if ((long)n < 0 || n > INT_MAX)
4106 + return n;
4107 +
4108 + if (!__builtin_constant_p(n))
4109 + check_object_size(to, n, false);
4110 +
4111 + if (likely(access_ok(VERIFY_READ, from, n)))
4112 + n = __copy_from_user(to, from, n);
4113 + else
4114 + memset(to, 0, n);
4115 + return n;
4116 +}
4117 +
4118 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4119 +{
4120 + if ((long)n < 0 || n > INT_MAX)
4121 + return n;
4122 +
4123 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
4124 + if (!__builtin_constant_p(n))
4125 + check_object_size(from, n, true);
4126 + n = __copy_to_user(to, from, n);
4127 + }
4128 + return n;
4129 +}
4130 +
4131 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
4132 + unsigned long n);
4133 +
4134 +#endif /* __powerpc64__ */
4135 +
4136 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4137
4138 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4139 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4140 index 7215cc2..a9730c1 100644
4141 --- a/arch/powerpc/kernel/exceptions-64e.S
4142 +++ b/arch/powerpc/kernel/exceptions-64e.S
4143 @@ -661,6 +661,7 @@ storage_fault_common:
4144 std r14,_DAR(r1)
4145 std r15,_DSISR(r1)
4146 addi r3,r1,STACK_FRAME_OVERHEAD
4147 + bl .save_nvgprs
4148 mr r4,r14
4149 mr r5,r15
4150 ld r14,PACA_EXGEN+EX_R14(r13)
4151 @@ -669,8 +670,7 @@ storage_fault_common:
4152 cmpdi r3,0
4153 bne- 1f
4154 b .ret_from_except_lite
4155 -1: bl .save_nvgprs
4156 - mr r5,r3
4157 +1: mr r5,r3
4158 addi r3,r1,STACK_FRAME_OVERHEAD
4159 ld r4,_DAR(r1)
4160 bl .bad_page_fault
4161 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4162 index 8f880bc..c5bd2f3 100644
4163 --- a/arch/powerpc/kernel/exceptions-64s.S
4164 +++ b/arch/powerpc/kernel/exceptions-64s.S
4165 @@ -890,10 +890,10 @@ handle_page_fault:
4166 11: ld r4,_DAR(r1)
4167 ld r5,_DSISR(r1)
4168 addi r3,r1,STACK_FRAME_OVERHEAD
4169 + bl .save_nvgprs
4170 bl .do_page_fault
4171 cmpdi r3,0
4172 beq+ 12f
4173 - bl .save_nvgprs
4174 mr r5,r3
4175 addi r3,r1,STACK_FRAME_OVERHEAD
4176 lwz r4,_DAR(r1)
4177 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4178 index 2e3200c..72095ce 100644
4179 --- a/arch/powerpc/kernel/module_32.c
4180 +++ b/arch/powerpc/kernel/module_32.c
4181 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4182 me->arch.core_plt_section = i;
4183 }
4184 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4185 - printk("Module doesn't contain .plt or .init.plt sections.\n");
4186 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4187 return -ENOEXEC;
4188 }
4189
4190 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4191
4192 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4193 /* Init, or core PLT? */
4194 - if (location >= mod->module_core
4195 - && location < mod->module_core + mod->core_size)
4196 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
4197 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
4198 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
4199 - else
4200 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
4201 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
4202 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
4203 + else {
4204 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
4205 + return ~0UL;
4206 + }
4207
4208 /* Find this entry, or if that fails, the next avail. entry */
4209 while (entry->jump[0]) {
4210 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
4211 index 4937c96..70714b7 100644
4212 --- a/arch/powerpc/kernel/process.c
4213 +++ b/arch/powerpc/kernel/process.c
4214 @@ -681,8 +681,8 @@ void show_regs(struct pt_regs * regs)
4215 * Lookup NIP late so we have the best change of getting the
4216 * above info out without failing
4217 */
4218 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
4219 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
4220 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
4221 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
4222 #endif
4223 show_stack(current, (unsigned long *) regs->gpr[1]);
4224 if (!user_mode(regs))
4225 @@ -1186,10 +1186,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4226 newsp = stack[0];
4227 ip = stack[STACK_FRAME_LR_SAVE];
4228 if (!firstframe || ip != lr) {
4229 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
4230 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
4231 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4232 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
4233 - printk(" (%pS)",
4234 + printk(" (%pA)",
4235 (void *)current->ret_stack[curr_frame].ret);
4236 curr_frame--;
4237 }
4238 @@ -1209,7 +1209,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4239 struct pt_regs *regs = (struct pt_regs *)
4240 (sp + STACK_FRAME_OVERHEAD);
4241 lr = regs->link;
4242 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
4243 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
4244 regs->trap, (void *)regs->nip, (void *)lr);
4245 firstframe = 1;
4246 }
4247 @@ -1282,58 +1282,3 @@ void thread_info_cache_init(void)
4248 }
4249
4250 #endif /* THREAD_SHIFT < PAGE_SHIFT */
4251 -
4252 -unsigned long arch_align_stack(unsigned long sp)
4253 -{
4254 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4255 - sp -= get_random_int() & ~PAGE_MASK;
4256 - return sp & ~0xf;
4257 -}
4258 -
4259 -static inline unsigned long brk_rnd(void)
4260 -{
4261 - unsigned long rnd = 0;
4262 -
4263 - /* 8MB for 32bit, 1GB for 64bit */
4264 - if (is_32bit_task())
4265 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4266 - else
4267 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4268 -
4269 - return rnd << PAGE_SHIFT;
4270 -}
4271 -
4272 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4273 -{
4274 - unsigned long base = mm->brk;
4275 - unsigned long ret;
4276 -
4277 -#ifdef CONFIG_PPC_STD_MMU_64
4278 - /*
4279 - * If we are using 1TB segments and we are allowed to randomise
4280 - * the heap, we can put it above 1TB so it is backed by a 1TB
4281 - * segment. Otherwise the heap will be in the bottom 1TB
4282 - * which always uses 256MB segments and this may result in a
4283 - * performance penalty.
4284 - */
4285 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
4286 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
4287 -#endif
4288 -
4289 - ret = PAGE_ALIGN(base + brk_rnd());
4290 -
4291 - if (ret < mm->brk)
4292 - return mm->brk;
4293 -
4294 - return ret;
4295 -}
4296 -
4297 -unsigned long randomize_et_dyn(unsigned long base)
4298 -{
4299 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4300 -
4301 - if (ret < base)
4302 - return base;
4303 -
4304 - return ret;
4305 -}
4306 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
4307 index 8d8e028..c2aeb50 100644
4308 --- a/arch/powerpc/kernel/ptrace.c
4309 +++ b/arch/powerpc/kernel/ptrace.c
4310 @@ -1702,6 +1702,10 @@ long arch_ptrace(struct task_struct *child, long request,
4311 return ret;
4312 }
4313
4314 +#ifdef CONFIG_GRKERNSEC_SETXID
4315 +extern void gr_delayed_cred_worker(void);
4316 +#endif
4317 +
4318 /*
4319 * We must return the syscall number to actually look up in the table.
4320 * This can be -1L to skip running any syscall at all.
4321 @@ -1712,6 +1716,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
4322
4323 secure_computing(regs->gpr[0]);
4324
4325 +#ifdef CONFIG_GRKERNSEC_SETXID
4326 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4327 + gr_delayed_cred_worker();
4328 +#endif
4329 +
4330 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
4331 tracehook_report_syscall_entry(regs))
4332 /*
4333 @@ -1746,6 +1755,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
4334 {
4335 int step;
4336
4337 +#ifdef CONFIG_GRKERNSEC_SETXID
4338 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4339 + gr_delayed_cred_worker();
4340 +#endif
4341 +
4342 audit_syscall_exit(regs);
4343
4344 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
4345 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
4346 index 45eb998..0cb36bc 100644
4347 --- a/arch/powerpc/kernel/signal_32.c
4348 +++ b/arch/powerpc/kernel/signal_32.c
4349 @@ -861,7 +861,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
4350 /* Save user registers on the stack */
4351 frame = &rt_sf->uc.uc_mcontext;
4352 addr = frame;
4353 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4354 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4355 if (save_user_regs(regs, frame, 0, 1))
4356 goto badframe;
4357 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4358 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
4359 index 2692efd..6673d2e 100644
4360 --- a/arch/powerpc/kernel/signal_64.c
4361 +++ b/arch/powerpc/kernel/signal_64.c
4362 @@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
4363 current->thread.fpscr.val = 0;
4364
4365 /* Set up to return from userspace. */
4366 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4367 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4368 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4369 } else {
4370 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4371 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4372 index 1589723..cefe690 100644
4373 --- a/arch/powerpc/kernel/traps.c
4374 +++ b/arch/powerpc/kernel/traps.c
4375 @@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4376 return flags;
4377 }
4378
4379 +extern void gr_handle_kernel_exploit(void);
4380 +
4381 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4382 int signr)
4383 {
4384 @@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4385 panic("Fatal exception in interrupt");
4386 if (panic_on_oops)
4387 panic("Fatal exception");
4388 +
4389 + gr_handle_kernel_exploit();
4390 +
4391 do_exit(signr);
4392 }
4393
4394 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4395 index 9eb5b9b..e45498a 100644
4396 --- a/arch/powerpc/kernel/vdso.c
4397 +++ b/arch/powerpc/kernel/vdso.c
4398 @@ -34,6 +34,7 @@
4399 #include <asm/firmware.h>
4400 #include <asm/vdso.h>
4401 #include <asm/vdso_datapage.h>
4402 +#include <asm/mman.h>
4403
4404 #include "setup.h"
4405
4406 @@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4407 vdso_base = VDSO32_MBASE;
4408 #endif
4409
4410 - current->mm->context.vdso_base = 0;
4411 + current->mm->context.vdso_base = ~0UL;
4412
4413 /* vDSO has a problem and was disabled, just don't "enable" it for the
4414 * process
4415 @@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4416 vdso_base = get_unmapped_area(NULL, vdso_base,
4417 (vdso_pages << PAGE_SHIFT) +
4418 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4419 - 0, 0);
4420 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
4421 if (IS_ERR_VALUE(vdso_base)) {
4422 rc = vdso_base;
4423 goto fail_mmapsem;
4424 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4425 index 5eea6f3..5d10396 100644
4426 --- a/arch/powerpc/lib/usercopy_64.c
4427 +++ b/arch/powerpc/lib/usercopy_64.c
4428 @@ -9,22 +9,6 @@
4429 #include <linux/module.h>
4430 #include <asm/uaccess.h>
4431
4432 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4433 -{
4434 - if (likely(access_ok(VERIFY_READ, from, n)))
4435 - n = __copy_from_user(to, from, n);
4436 - else
4437 - memset(to, 0, n);
4438 - return n;
4439 -}
4440 -
4441 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4442 -{
4443 - if (likely(access_ok(VERIFY_WRITE, to, n)))
4444 - n = __copy_to_user(to, from, n);
4445 - return n;
4446 -}
4447 -
4448 unsigned long copy_in_user(void __user *to, const void __user *from,
4449 unsigned long n)
4450 {
4451 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4452 return n;
4453 }
4454
4455 -EXPORT_SYMBOL(copy_from_user);
4456 -EXPORT_SYMBOL(copy_to_user);
4457 EXPORT_SYMBOL(copy_in_user);
4458
4459 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4460 index 08ffcf5..a0ab912 100644
4461 --- a/arch/powerpc/mm/fault.c
4462 +++ b/arch/powerpc/mm/fault.c
4463 @@ -32,6 +32,10 @@
4464 #include <linux/perf_event.h>
4465 #include <linux/magic.h>
4466 #include <linux/ratelimit.h>
4467 +#include <linux/slab.h>
4468 +#include <linux/pagemap.h>
4469 +#include <linux/compiler.h>
4470 +#include <linux/unistd.h>
4471
4472 #include <asm/firmware.h>
4473 #include <asm/page.h>
4474 @@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4475 }
4476 #endif
4477
4478 +#ifdef CONFIG_PAX_PAGEEXEC
4479 +/*
4480 + * PaX: decide what to do with offenders (regs->nip = fault address)
4481 + *
4482 + * returns 1 when task should be killed
4483 + */
4484 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4485 +{
4486 + return 1;
4487 +}
4488 +
4489 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4490 +{
4491 + unsigned long i;
4492 +
4493 + printk(KERN_ERR "PAX: bytes at PC: ");
4494 + for (i = 0; i < 5; i++) {
4495 + unsigned int c;
4496 + if (get_user(c, (unsigned int __user *)pc+i))
4497 + printk(KERN_CONT "???????? ");
4498 + else
4499 + printk(KERN_CONT "%08x ", c);
4500 + }
4501 + printk("\n");
4502 +}
4503 +#endif
4504 +
4505 /*
4506 * Check whether the instruction at regs->nip is a store using
4507 * an update addressing form which will update r1.
4508 @@ -215,7 +246,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4509 * indicate errors in DSISR but can validly be set in SRR1.
4510 */
4511 if (trap == 0x400)
4512 - error_code &= 0x48200000;
4513 + error_code &= 0x58200000;
4514 else
4515 is_write = error_code & DSISR_ISSTORE;
4516 #else
4517 @@ -366,7 +397,7 @@ good_area:
4518 * "undefined". Of those that can be set, this is the only
4519 * one which seems bad.
4520 */
4521 - if (error_code & 0x10000000)
4522 + if (error_code & DSISR_GUARDED)
4523 /* Guarded storage error. */
4524 goto bad_area;
4525 #endif /* CONFIG_8xx */
4526 @@ -381,7 +412,7 @@ good_area:
4527 * processors use the same I/D cache coherency mechanism
4528 * as embedded.
4529 */
4530 - if (error_code & DSISR_PROTFAULT)
4531 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4532 goto bad_area;
4533 #endif /* CONFIG_PPC_STD_MMU */
4534
4535 @@ -463,6 +494,23 @@ bad_area:
4536 bad_area_nosemaphore:
4537 /* User mode accesses cause a SIGSEGV */
4538 if (user_mode(regs)) {
4539 +
4540 +#ifdef CONFIG_PAX_PAGEEXEC
4541 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4542 +#ifdef CONFIG_PPC_STD_MMU
4543 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4544 +#else
4545 + if (is_exec && regs->nip == address) {
4546 +#endif
4547 + switch (pax_handle_fetch_fault(regs)) {
4548 + }
4549 +
4550 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4551 + do_group_exit(SIGKILL);
4552 + }
4553 + }
4554 +#endif
4555 +
4556 _exception(SIGSEGV, regs, code, address);
4557 return 0;
4558 }
4559 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4560 index 67a42ed..1c7210c 100644
4561 --- a/arch/powerpc/mm/mmap_64.c
4562 +++ b/arch/powerpc/mm/mmap_64.c
4563 @@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4564 */
4565 if (mmap_is_legacy()) {
4566 mm->mmap_base = TASK_UNMAPPED_BASE;
4567 +
4568 +#ifdef CONFIG_PAX_RANDMMAP
4569 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4570 + mm->mmap_base += mm->delta_mmap;
4571 +#endif
4572 +
4573 mm->get_unmapped_area = arch_get_unmapped_area;
4574 mm->unmap_area = arch_unmap_area;
4575 } else {
4576 mm->mmap_base = mmap_base();
4577 +
4578 +#ifdef CONFIG_PAX_RANDMMAP
4579 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4580 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4581 +#endif
4582 +
4583 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4584 mm->unmap_area = arch_unmap_area_topdown;
4585 }
4586 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4587 index 73709f7..6b90313 100644
4588 --- a/arch/powerpc/mm/slice.c
4589 +++ b/arch/powerpc/mm/slice.c
4590 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4591 if ((mm->task_size - len) < addr)
4592 return 0;
4593 vma = find_vma(mm, addr);
4594 - return (!vma || (addr + len) <= vma->vm_start);
4595 + return check_heap_stack_gap(vma, addr, len);
4596 }
4597
4598 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4599 @@ -256,7 +256,7 @@ full_search:
4600 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4601 continue;
4602 }
4603 - if (!vma || addr + len <= vma->vm_start) {
4604 + if (check_heap_stack_gap(vma, addr, len)) {
4605 /*
4606 * Remember the place where we stopped the search:
4607 */
4608 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4609 }
4610 }
4611
4612 - addr = mm->mmap_base;
4613 - while (addr > len) {
4614 + if (mm->mmap_base < len)
4615 + addr = -ENOMEM;
4616 + else
4617 + addr = mm->mmap_base - len;
4618 +
4619 + while (!IS_ERR_VALUE(addr)) {
4620 /* Go down by chunk size */
4621 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4622 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
4623
4624 /* Check for hit with different page size */
4625 mask = slice_range_to_mask(addr, len);
4626 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4627 * return with success:
4628 */
4629 vma = find_vma(mm, addr);
4630 - if (!vma || (addr + len) <= vma->vm_start) {
4631 + if (check_heap_stack_gap(vma, addr, len)) {
4632 /* remember the address as a hint for next time */
4633 if (use_cache)
4634 mm->free_area_cache = addr;
4635 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4636 mm->cached_hole_size = vma->vm_start - addr;
4637
4638 /* try just below the current vma->vm_start */
4639 - addr = vma->vm_start;
4640 + addr = skip_heap_stack_gap(vma, len);
4641 }
4642
4643 /*
4644 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4645 if (fixed && addr > (mm->task_size - len))
4646 return -EINVAL;
4647
4648 +#ifdef CONFIG_PAX_RANDMMAP
4649 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4650 + addr = 0;
4651 +#endif
4652 +
4653 /* If hint, make sure it matches our alignment restrictions */
4654 if (!fixed && addr) {
4655 addr = _ALIGN_UP(addr, 1ul << pshift);
4656 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4657 index 748347b..81bc6c7 100644
4658 --- a/arch/s390/include/asm/atomic.h
4659 +++ b/arch/s390/include/asm/atomic.h
4660 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4661 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4662 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4663
4664 +#define atomic64_read_unchecked(v) atomic64_read(v)
4665 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4666 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4667 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4668 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4669 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4670 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4671 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4672 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4673 +
4674 #define smp_mb__before_atomic_dec() smp_mb()
4675 #define smp_mb__after_atomic_dec() smp_mb()
4676 #define smp_mb__before_atomic_inc() smp_mb()
4677 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4678 index 2a30d5a..5e5586f 100644
4679 --- a/arch/s390/include/asm/cache.h
4680 +++ b/arch/s390/include/asm/cache.h
4681 @@ -11,8 +11,10 @@
4682 #ifndef __ARCH_S390_CACHE_H
4683 #define __ARCH_S390_CACHE_H
4684
4685 -#define L1_CACHE_BYTES 256
4686 +#include <linux/const.h>
4687 +
4688 #define L1_CACHE_SHIFT 8
4689 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4690 #define NET_SKB_PAD 32
4691
4692 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4693 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4694 index c4ee39f..352881b 100644
4695 --- a/arch/s390/include/asm/elf.h
4696 +++ b/arch/s390/include/asm/elf.h
4697 @@ -161,8 +161,14 @@ extern unsigned int vdso_enabled;
4698 the loader. We need to make sure that it is out of the way of the program
4699 that it will "exec", and that there is sufficient room for the brk. */
4700
4701 -extern unsigned long randomize_et_dyn(unsigned long base);
4702 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4703 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4704 +
4705 +#ifdef CONFIG_PAX_ASLR
4706 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4707 +
4708 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4709 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4710 +#endif
4711
4712 /* This yields a mask that user programs can use to figure out what
4713 instruction set this CPU supports. */
4714 @@ -210,7 +216,4 @@ struct linux_binprm;
4715 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4716 int arch_setup_additional_pages(struct linux_binprm *, int);
4717
4718 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4719 -#define arch_randomize_brk arch_randomize_brk
4720 -
4721 #endif
4722 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
4723 index c4a93d6..4d2a9b4 100644
4724 --- a/arch/s390/include/asm/exec.h
4725 +++ b/arch/s390/include/asm/exec.h
4726 @@ -7,6 +7,6 @@
4727 #ifndef __ASM_EXEC_H
4728 #define __ASM_EXEC_H
4729
4730 -extern unsigned long arch_align_stack(unsigned long sp);
4731 +#define arch_align_stack(x) ((x) & ~0xfUL)
4732
4733 #endif /* __ASM_EXEC_H */
4734 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4735 index 8f2cada..43072c1 100644
4736 --- a/arch/s390/include/asm/uaccess.h
4737 +++ b/arch/s390/include/asm/uaccess.h
4738 @@ -236,6 +236,10 @@ static inline unsigned long __must_check
4739 copy_to_user(void __user *to, const void *from, unsigned long n)
4740 {
4741 might_fault();
4742 +
4743 + if ((long)n < 0)
4744 + return n;
4745 +
4746 if (access_ok(VERIFY_WRITE, to, n))
4747 n = __copy_to_user(to, from, n);
4748 return n;
4749 @@ -261,6 +265,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4750 static inline unsigned long __must_check
4751 __copy_from_user(void *to, const void __user *from, unsigned long n)
4752 {
4753 + if ((long)n < 0)
4754 + return n;
4755 +
4756 if (__builtin_constant_p(n) && (n <= 256))
4757 return uaccess.copy_from_user_small(n, from, to);
4758 else
4759 @@ -292,10 +299,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
4760 static inline unsigned long __must_check
4761 copy_from_user(void *to, const void __user *from, unsigned long n)
4762 {
4763 - unsigned int sz = __compiletime_object_size(to);
4764 + size_t sz = __compiletime_object_size(to);
4765
4766 might_fault();
4767 - if (unlikely(sz != -1 && sz < n)) {
4768 +
4769 + if ((long)n < 0)
4770 + return n;
4771 +
4772 + if (unlikely(sz != (size_t)-1 && sz < n)) {
4773 copy_from_user_overflow();
4774 return n;
4775 }
4776 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4777 index dfcb343..eda788a 100644
4778 --- a/arch/s390/kernel/module.c
4779 +++ b/arch/s390/kernel/module.c
4780 @@ -161,11 +161,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4781
4782 /* Increase core size by size of got & plt and set start
4783 offsets for got and plt. */
4784 - me->core_size = ALIGN(me->core_size, 4);
4785 - me->arch.got_offset = me->core_size;
4786 - me->core_size += me->arch.got_size;
4787 - me->arch.plt_offset = me->core_size;
4788 - me->core_size += me->arch.plt_size;
4789 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
4790 + me->arch.got_offset = me->core_size_rw;
4791 + me->core_size_rw += me->arch.got_size;
4792 + me->arch.plt_offset = me->core_size_rx;
4793 + me->core_size_rx += me->arch.plt_size;
4794 return 0;
4795 }
4796
4797 @@ -242,7 +242,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4798 if (info->got_initialized == 0) {
4799 Elf_Addr *gotent;
4800
4801 - gotent = me->module_core + me->arch.got_offset +
4802 + gotent = me->module_core_rw + me->arch.got_offset +
4803 info->got_offset;
4804 *gotent = val;
4805 info->got_initialized = 1;
4806 @@ -266,7 +266,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4807 else if (r_type == R_390_GOTENT ||
4808 r_type == R_390_GOTPLTENT)
4809 *(unsigned int *) loc =
4810 - (val + (Elf_Addr) me->module_core - loc) >> 1;
4811 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4812 else if (r_type == R_390_GOT64 ||
4813 r_type == R_390_GOTPLT64)
4814 *(unsigned long *) loc = val;
4815 @@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4816 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4817 if (info->plt_initialized == 0) {
4818 unsigned int *ip;
4819 - ip = me->module_core + me->arch.plt_offset +
4820 + ip = me->module_core_rx + me->arch.plt_offset +
4821 info->plt_offset;
4822 #ifndef CONFIG_64BIT
4823 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4824 @@ -305,7 +305,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4825 val - loc + 0xffffUL < 0x1ffffeUL) ||
4826 (r_type == R_390_PLT32DBL &&
4827 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4828 - val = (Elf_Addr) me->module_core +
4829 + val = (Elf_Addr) me->module_core_rx +
4830 me->arch.plt_offset +
4831 info->plt_offset;
4832 val += rela->r_addend - loc;
4833 @@ -327,7 +327,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4834 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4835 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4836 val = val + rela->r_addend -
4837 - ((Elf_Addr) me->module_core + me->arch.got_offset);
4838 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4839 if (r_type == R_390_GOTOFF16)
4840 *(unsigned short *) loc = val;
4841 else if (r_type == R_390_GOTOFF32)
4842 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4843 break;
4844 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4845 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4846 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
4847 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4848 rela->r_addend - loc;
4849 if (r_type == R_390_GOTPC)
4850 *(unsigned int *) loc = val;
4851 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4852 index 60055ce..ee4b252 100644
4853 --- a/arch/s390/kernel/process.c
4854 +++ b/arch/s390/kernel/process.c
4855 @@ -316,39 +316,3 @@ unsigned long get_wchan(struct task_struct *p)
4856 }
4857 return 0;
4858 }
4859 -
4860 -unsigned long arch_align_stack(unsigned long sp)
4861 -{
4862 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4863 - sp -= get_random_int() & ~PAGE_MASK;
4864 - return sp & ~0xf;
4865 -}
4866 -
4867 -static inline unsigned long brk_rnd(void)
4868 -{
4869 - /* 8MB for 32bit, 1GB for 64bit */
4870 - if (is_32bit_task())
4871 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4872 - else
4873 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4874 -}
4875 -
4876 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4877 -{
4878 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4879 -
4880 - if (ret < mm->brk)
4881 - return mm->brk;
4882 - return ret;
4883 -}
4884 -
4885 -unsigned long randomize_et_dyn(unsigned long base)
4886 -{
4887 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4888 -
4889 - if (!(current->flags & PF_RANDOMIZE))
4890 - return base;
4891 - if (ret < base)
4892 - return base;
4893 - return ret;
4894 -}
4895 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4896 index 2857c48..d047481 100644
4897 --- a/arch/s390/mm/mmap.c
4898 +++ b/arch/s390/mm/mmap.c
4899 @@ -92,10 +92,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4900 */
4901 if (mmap_is_legacy()) {
4902 mm->mmap_base = TASK_UNMAPPED_BASE;
4903 +
4904 +#ifdef CONFIG_PAX_RANDMMAP
4905 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4906 + mm->mmap_base += mm->delta_mmap;
4907 +#endif
4908 +
4909 mm->get_unmapped_area = arch_get_unmapped_area;
4910 mm->unmap_area = arch_unmap_area;
4911 } else {
4912 mm->mmap_base = mmap_base();
4913 +
4914 +#ifdef CONFIG_PAX_RANDMMAP
4915 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4916 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4917 +#endif
4918 +
4919 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4920 mm->unmap_area = arch_unmap_area_topdown;
4921 }
4922 @@ -166,10 +178,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4923 */
4924 if (mmap_is_legacy()) {
4925 mm->mmap_base = TASK_UNMAPPED_BASE;
4926 +
4927 +#ifdef CONFIG_PAX_RANDMMAP
4928 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4929 + mm->mmap_base += mm->delta_mmap;
4930 +#endif
4931 +
4932 mm->get_unmapped_area = s390_get_unmapped_area;
4933 mm->unmap_area = arch_unmap_area;
4934 } else {
4935 mm->mmap_base = mmap_base();
4936 +
4937 +#ifdef CONFIG_PAX_RANDMMAP
4938 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4939 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4940 +#endif
4941 +
4942 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4943 mm->unmap_area = arch_unmap_area_topdown;
4944 }
4945 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4946 index ae3d59f..f65f075 100644
4947 --- a/arch/score/include/asm/cache.h
4948 +++ b/arch/score/include/asm/cache.h
4949 @@ -1,7 +1,9 @@
4950 #ifndef _ASM_SCORE_CACHE_H
4951 #define _ASM_SCORE_CACHE_H
4952
4953 +#include <linux/const.h>
4954 +
4955 #define L1_CACHE_SHIFT 4
4956 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4957 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4958
4959 #endif /* _ASM_SCORE_CACHE_H */
4960 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
4961 index f9f3cd5..58ff438 100644
4962 --- a/arch/score/include/asm/exec.h
4963 +++ b/arch/score/include/asm/exec.h
4964 @@ -1,6 +1,6 @@
4965 #ifndef _ASM_SCORE_EXEC_H
4966 #define _ASM_SCORE_EXEC_H
4967
4968 -extern unsigned long arch_align_stack(unsigned long sp);
4969 +#define arch_align_stack(x) (x)
4970
4971 #endif /* _ASM_SCORE_EXEC_H */
4972 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4973 index 2707023..1c2a3b7 100644
4974 --- a/arch/score/kernel/process.c
4975 +++ b/arch/score/kernel/process.c
4976 @@ -159,8 +159,3 @@ unsigned long get_wchan(struct task_struct *task)
4977
4978 return task_pt_regs(task)->cp0_epc;
4979 }
4980 -
4981 -unsigned long arch_align_stack(unsigned long sp)
4982 -{
4983 - return sp;
4984 -}
4985 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
4986 index ef9e555..331bd29 100644
4987 --- a/arch/sh/include/asm/cache.h
4988 +++ b/arch/sh/include/asm/cache.h
4989 @@ -9,10 +9,11 @@
4990 #define __ASM_SH_CACHE_H
4991 #ifdef __KERNEL__
4992
4993 +#include <linux/const.h>
4994 #include <linux/init.h>
4995 #include <cpu/cache.h>
4996
4997 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4998 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4999
5000 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5001
5002 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
5003 index afeb710..d1d1289 100644
5004 --- a/arch/sh/mm/mmap.c
5005 +++ b/arch/sh/mm/mmap.c
5006 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5007 addr = PAGE_ALIGN(addr);
5008
5009 vma = find_vma(mm, addr);
5010 - if (TASK_SIZE - len >= addr &&
5011 - (!vma || addr + len <= vma->vm_start))
5012 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5013 return addr;
5014 }
5015
5016 @@ -106,7 +105,7 @@ full_search:
5017 }
5018 return -ENOMEM;
5019 }
5020 - if (likely(!vma || addr + len <= vma->vm_start)) {
5021 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5022 /*
5023 * Remember the place where we stopped the search:
5024 */
5025 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5026 addr = PAGE_ALIGN(addr);
5027
5028 vma = find_vma(mm, addr);
5029 - if (TASK_SIZE - len >= addr &&
5030 - (!vma || addr + len <= vma->vm_start))
5031 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5032 return addr;
5033 }
5034
5035 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5036 /* make sure it can fit in the remaining address space */
5037 if (likely(addr > len)) {
5038 vma = find_vma(mm, addr-len);
5039 - if (!vma || addr <= vma->vm_start) {
5040 + if (check_heap_stack_gap(vma, addr - len, len)) {
5041 /* remember the address as a hint for next time */
5042 return (mm->free_area_cache = addr-len);
5043 }
5044 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5045 if (unlikely(mm->mmap_base < len))
5046 goto bottomup;
5047
5048 - addr = mm->mmap_base-len;
5049 - if (do_colour_align)
5050 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5051 + addr = mm->mmap_base - len;
5052
5053 do {
5054 + if (do_colour_align)
5055 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5056 /*
5057 * Lookup failure means no vma is above this address,
5058 * else if new region fits below vma->vm_start,
5059 * return with success:
5060 */
5061 vma = find_vma(mm, addr);
5062 - if (likely(!vma || addr+len <= vma->vm_start)) {
5063 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5064 /* remember the address as a hint for next time */
5065 return (mm->free_area_cache = addr);
5066 }
5067 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5068 mm->cached_hole_size = vma->vm_start - addr;
5069
5070 /* try just below the current vma->vm_start */
5071 - addr = vma->vm_start-len;
5072 - if (do_colour_align)
5073 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5074 - } while (likely(len < vma->vm_start));
5075 + addr = skip_heap_stack_gap(vma, len);
5076 + } while (!IS_ERR_VALUE(addr));
5077
5078 bottomup:
5079 /*
5080 diff --git a/arch/sparc/Makefile b/arch/sparc/Makefile
5081 index eddcfb3..b117d90 100644
5082 --- a/arch/sparc/Makefile
5083 +++ b/arch/sparc/Makefile
5084 @@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc/oprofile/
5085 # Export what is needed by arch/sparc/boot/Makefile
5086 export VMLINUX_INIT VMLINUX_MAIN
5087 VMLINUX_INIT := $(head-y) $(init-y)
5088 -VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
5089 +VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
5090 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
5091 VMLINUX_MAIN += $(drivers-y) $(net-y)
5092
5093 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5094 index ce35a1c..2e7b8f9 100644
5095 --- a/arch/sparc/include/asm/atomic_64.h
5096 +++ b/arch/sparc/include/asm/atomic_64.h
5097 @@ -14,18 +14,40 @@
5098 #define ATOMIC64_INIT(i) { (i) }
5099
5100 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5101 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5102 +{
5103 + return v->counter;
5104 +}
5105 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5106 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5107 +{
5108 + return v->counter;
5109 +}
5110
5111 #define atomic_set(v, i) (((v)->counter) = i)
5112 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5113 +{
5114 + v->counter = i;
5115 +}
5116 #define atomic64_set(v, i) (((v)->counter) = i)
5117 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5118 +{
5119 + v->counter = i;
5120 +}
5121
5122 extern void atomic_add(int, atomic_t *);
5123 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5124 extern void atomic64_add(long, atomic64_t *);
5125 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5126 extern void atomic_sub(int, atomic_t *);
5127 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5128 extern void atomic64_sub(long, atomic64_t *);
5129 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5130
5131 extern int atomic_add_ret(int, atomic_t *);
5132 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5133 extern long atomic64_add_ret(long, atomic64_t *);
5134 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5135 extern int atomic_sub_ret(int, atomic_t *);
5136 extern long atomic64_sub_ret(long, atomic64_t *);
5137
5138 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5139 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5140
5141 #define atomic_inc_return(v) atomic_add_ret(1, v)
5142 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5143 +{
5144 + return atomic_add_ret_unchecked(1, v);
5145 +}
5146 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5147 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5148 +{
5149 + return atomic64_add_ret_unchecked(1, v);
5150 +}
5151
5152 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5153 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5154
5155 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5156 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5157 +{
5158 + return atomic_add_ret_unchecked(i, v);
5159 +}
5160 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5161 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5162 +{
5163 + return atomic64_add_ret_unchecked(i, v);
5164 +}
5165
5166 /*
5167 * atomic_inc_and_test - increment and test
5168 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5169 * other cases.
5170 */
5171 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5172 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5173 +{
5174 + return atomic_inc_return_unchecked(v) == 0;
5175 +}
5176 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5177
5178 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5179 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5180 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5181
5182 #define atomic_inc(v) atomic_add(1, v)
5183 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5184 +{
5185 + atomic_add_unchecked(1, v);
5186 +}
5187 #define atomic64_inc(v) atomic64_add(1, v)
5188 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5189 +{
5190 + atomic64_add_unchecked(1, v);
5191 +}
5192
5193 #define atomic_dec(v) atomic_sub(1, v)
5194 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5195 +{
5196 + atomic_sub_unchecked(1, v);
5197 +}
5198 #define atomic64_dec(v) atomic64_sub(1, v)
5199 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5200 +{
5201 + atomic64_sub_unchecked(1, v);
5202 +}
5203
5204 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5205 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5206
5207 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5208 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5209 +{
5210 + return cmpxchg(&v->counter, old, new);
5211 +}
5212 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5213 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5214 +{
5215 + return xchg(&v->counter, new);
5216 +}
5217
5218 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5219 {
5220 - int c, old;
5221 + int c, old, new;
5222 c = atomic_read(v);
5223 for (;;) {
5224 - if (unlikely(c == (u)))
5225 + if (unlikely(c == u))
5226 break;
5227 - old = atomic_cmpxchg((v), c, c + (a));
5228 +
5229 + asm volatile("addcc %2, %0, %0\n"
5230 +
5231 +#ifdef CONFIG_PAX_REFCOUNT
5232 + "tvs %%icc, 6\n"
5233 +#endif
5234 +
5235 + : "=r" (new)
5236 + : "0" (c), "ir" (a)
5237 + : "cc");
5238 +
5239 + old = atomic_cmpxchg(v, c, new);
5240 if (likely(old == c))
5241 break;
5242 c = old;
5243 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5244 #define atomic64_cmpxchg(v, o, n) \
5245 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
5246 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
5247 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
5248 +{
5249 + return xchg(&v->counter, new);
5250 +}
5251
5252 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5253 {
5254 - long c, old;
5255 + long c, old, new;
5256 c = atomic64_read(v);
5257 for (;;) {
5258 - if (unlikely(c == (u)))
5259 + if (unlikely(c == u))
5260 break;
5261 - old = atomic64_cmpxchg((v), c, c + (a));
5262 +
5263 + asm volatile("addcc %2, %0, %0\n"
5264 +
5265 +#ifdef CONFIG_PAX_REFCOUNT
5266 + "tvs %%xcc, 6\n"
5267 +#endif
5268 +
5269 + : "=r" (new)
5270 + : "0" (c), "ir" (a)
5271 + : "cc");
5272 +
5273 + old = atomic64_cmpxchg(v, c, new);
5274 if (likely(old == c))
5275 break;
5276 c = old;
5277 }
5278 - return c != (u);
5279 + return c != u;
5280 }
5281
5282 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5283 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5284 index 69358b5..9d0d492 100644
5285 --- a/arch/sparc/include/asm/cache.h
5286 +++ b/arch/sparc/include/asm/cache.h
5287 @@ -7,10 +7,12 @@
5288 #ifndef _SPARC_CACHE_H
5289 #define _SPARC_CACHE_H
5290
5291 +#include <linux/const.h>
5292 +
5293 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5294
5295 #define L1_CACHE_SHIFT 5
5296 -#define L1_CACHE_BYTES 32
5297 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5298
5299 #ifdef CONFIG_SPARC32
5300 #define SMP_CACHE_BYTES_SHIFT 5
5301 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5302 index 4269ca6..e3da77f 100644
5303 --- a/arch/sparc/include/asm/elf_32.h
5304 +++ b/arch/sparc/include/asm/elf_32.h
5305 @@ -114,6 +114,13 @@ typedef struct {
5306
5307 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5308
5309 +#ifdef CONFIG_PAX_ASLR
5310 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
5311 +
5312 +#define PAX_DELTA_MMAP_LEN 16
5313 +#define PAX_DELTA_STACK_LEN 16
5314 +#endif
5315 +
5316 /* This yields a mask that user programs can use to figure out what
5317 instruction set this cpu supports. This can NOT be done in userspace
5318 on Sparc. */
5319 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5320 index 7df8b7f..4946269 100644
5321 --- a/arch/sparc/include/asm/elf_64.h
5322 +++ b/arch/sparc/include/asm/elf_64.h
5323 @@ -180,6 +180,13 @@ typedef struct {
5324 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5325 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5326
5327 +#ifdef CONFIG_PAX_ASLR
5328 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5329 +
5330 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5331 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5332 +#endif
5333 +
5334 extern unsigned long sparc64_elf_hwcap;
5335 #define ELF_HWCAP sparc64_elf_hwcap
5336
5337 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5338 index ca2b344..c6084f89 100644
5339 --- a/arch/sparc/include/asm/pgalloc_32.h
5340 +++ b/arch/sparc/include/asm/pgalloc_32.h
5341 @@ -37,6 +37,7 @@ BTFIXUPDEF_CALL(void, free_pgd_fast, pgd_t *)
5342 BTFIXUPDEF_CALL(void, pgd_set, pgd_t *, pmd_t *)
5343 #define pgd_set(pgdp,pmdp) BTFIXUP_CALL(pgd_set)(pgdp,pmdp)
5344 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5345 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5346
5347 BTFIXUPDEF_CALL(pmd_t *, pmd_alloc_one, struct mm_struct *, unsigned long)
5348 #define pmd_alloc_one(mm, address) BTFIXUP_CALL(pmd_alloc_one)(mm, address)
5349 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5350 index 40b2d7a..22a665b 100644
5351 --- a/arch/sparc/include/asm/pgalloc_64.h
5352 +++ b/arch/sparc/include/asm/pgalloc_64.h
5353 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5354 }
5355
5356 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5357 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5358
5359 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5360 {
5361 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5362 index 3d71018..48a11c5 100644
5363 --- a/arch/sparc/include/asm/pgtable_32.h
5364 +++ b/arch/sparc/include/asm/pgtable_32.h
5365 @@ -45,6 +45,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
5366 BTFIXUPDEF_INT(page_none)
5367 BTFIXUPDEF_INT(page_copy)
5368 BTFIXUPDEF_INT(page_readonly)
5369 +
5370 +#ifdef CONFIG_PAX_PAGEEXEC
5371 +BTFIXUPDEF_INT(page_shared_noexec)
5372 +BTFIXUPDEF_INT(page_copy_noexec)
5373 +BTFIXUPDEF_INT(page_readonly_noexec)
5374 +#endif
5375 +
5376 BTFIXUPDEF_INT(page_kernel)
5377
5378 #define PMD_SHIFT SUN4C_PMD_SHIFT
5379 @@ -66,6 +73,16 @@ extern pgprot_t PAGE_SHARED;
5380 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
5381 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
5382
5383 +#ifdef CONFIG_PAX_PAGEEXEC
5384 +extern pgprot_t PAGE_SHARED_NOEXEC;
5385 +# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
5386 +# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
5387 +#else
5388 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5389 +# define PAGE_COPY_NOEXEC PAGE_COPY
5390 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5391 +#endif
5392 +
5393 extern unsigned long page_kernel;
5394
5395 #ifdef MODULE
5396 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5397 index f6ae2b2..b03ffc7 100644
5398 --- a/arch/sparc/include/asm/pgtsrmmu.h
5399 +++ b/arch/sparc/include/asm/pgtsrmmu.h
5400 @@ -115,6 +115,13 @@
5401 SRMMU_EXEC | SRMMU_REF)
5402 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5403 SRMMU_EXEC | SRMMU_REF)
5404 +
5405 +#ifdef CONFIG_PAX_PAGEEXEC
5406 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5407 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5408 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5409 +#endif
5410 +
5411 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5412 SRMMU_DIRTY | SRMMU_REF)
5413
5414 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5415 index 9689176..63c18ea 100644
5416 --- a/arch/sparc/include/asm/spinlock_64.h
5417 +++ b/arch/sparc/include/asm/spinlock_64.h
5418 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5419
5420 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5421
5422 -static void inline arch_read_lock(arch_rwlock_t *lock)
5423 +static inline void arch_read_lock(arch_rwlock_t *lock)
5424 {
5425 unsigned long tmp1, tmp2;
5426
5427 __asm__ __volatile__ (
5428 "1: ldsw [%2], %0\n"
5429 " brlz,pn %0, 2f\n"
5430 -"4: add %0, 1, %1\n"
5431 +"4: addcc %0, 1, %1\n"
5432 +
5433 +#ifdef CONFIG_PAX_REFCOUNT
5434 +" tvs %%icc, 6\n"
5435 +#endif
5436 +
5437 " cas [%2], %0, %1\n"
5438 " cmp %0, %1\n"
5439 " bne,pn %%icc, 1b\n"
5440 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5441 " .previous"
5442 : "=&r" (tmp1), "=&r" (tmp2)
5443 : "r" (lock)
5444 - : "memory");
5445 + : "memory", "cc");
5446 }
5447
5448 -static int inline arch_read_trylock(arch_rwlock_t *lock)
5449 +static inline int arch_read_trylock(arch_rwlock_t *lock)
5450 {
5451 int tmp1, tmp2;
5452
5453 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5454 "1: ldsw [%2], %0\n"
5455 " brlz,a,pn %0, 2f\n"
5456 " mov 0, %0\n"
5457 -" add %0, 1, %1\n"
5458 +" addcc %0, 1, %1\n"
5459 +
5460 +#ifdef CONFIG_PAX_REFCOUNT
5461 +" tvs %%icc, 6\n"
5462 +#endif
5463 +
5464 " cas [%2], %0, %1\n"
5465 " cmp %0, %1\n"
5466 " bne,pn %%icc, 1b\n"
5467 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5468 return tmp1;
5469 }
5470
5471 -static void inline arch_read_unlock(arch_rwlock_t *lock)
5472 +static inline void arch_read_unlock(arch_rwlock_t *lock)
5473 {
5474 unsigned long tmp1, tmp2;
5475
5476 __asm__ __volatile__(
5477 "1: lduw [%2], %0\n"
5478 -" sub %0, 1, %1\n"
5479 +" subcc %0, 1, %1\n"
5480 +
5481 +#ifdef CONFIG_PAX_REFCOUNT
5482 +" tvs %%icc, 6\n"
5483 +#endif
5484 +
5485 " cas [%2], %0, %1\n"
5486 " cmp %0, %1\n"
5487 " bne,pn %%xcc, 1b\n"
5488 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5489 : "memory");
5490 }
5491
5492 -static void inline arch_write_lock(arch_rwlock_t *lock)
5493 +static inline void arch_write_lock(arch_rwlock_t *lock)
5494 {
5495 unsigned long mask, tmp1, tmp2;
5496
5497 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5498 : "memory");
5499 }
5500
5501 -static void inline arch_write_unlock(arch_rwlock_t *lock)
5502 +static inline void arch_write_unlock(arch_rwlock_t *lock)
5503 {
5504 __asm__ __volatile__(
5505 " stw %%g0, [%0]"
5506 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5507 : "memory");
5508 }
5509
5510 -static int inline arch_write_trylock(arch_rwlock_t *lock)
5511 +static inline int arch_write_trylock(arch_rwlock_t *lock)
5512 {
5513 unsigned long mask, tmp1, tmp2, result;
5514
5515 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5516 index c2a1080..21ed218 100644
5517 --- a/arch/sparc/include/asm/thread_info_32.h
5518 +++ b/arch/sparc/include/asm/thread_info_32.h
5519 @@ -50,6 +50,8 @@ struct thread_info {
5520 unsigned long w_saved;
5521
5522 struct restart_block restart_block;
5523 +
5524 + unsigned long lowest_stack;
5525 };
5526
5527 /*
5528 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5529 index 01d057f..13a7d2f 100644
5530 --- a/arch/sparc/include/asm/thread_info_64.h
5531 +++ b/arch/sparc/include/asm/thread_info_64.h
5532 @@ -63,6 +63,8 @@ struct thread_info {
5533 struct pt_regs *kern_una_regs;
5534 unsigned int kern_una_insn;
5535
5536 + unsigned long lowest_stack;
5537 +
5538 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5539 };
5540
5541 @@ -214,10 +216,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
5542 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
5543 /* flag bit 6 is available */
5544 #define TIF_32BIT 7 /* 32-bit binary */
5545 -/* flag bit 8 is available */
5546 +#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
5547 #define TIF_SECCOMP 9 /* secure computing */
5548 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
5549 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
5550 +
5551 /* NOTE: Thread flags >= 12 should be ones we have no interest
5552 * in using in assembly, else we can't use the mask as
5553 * an immediate value in instructions such as andcc.
5554 @@ -236,12 +239,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
5555 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
5556 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5557 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
5558 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5559
5560 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
5561 _TIF_DO_NOTIFY_RESUME_MASK | \
5562 _TIF_NEED_RESCHED)
5563 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
5564
5565 +#define _TIF_WORK_SYSCALL \
5566 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
5567 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
5568 +
5569 +
5570 /*
5571 * Thread-synchronous status.
5572 *
5573 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5574 index e88fbe5..96b0ce5 100644
5575 --- a/arch/sparc/include/asm/uaccess.h
5576 +++ b/arch/sparc/include/asm/uaccess.h
5577 @@ -1,5 +1,13 @@
5578 #ifndef ___ASM_SPARC_UACCESS_H
5579 #define ___ASM_SPARC_UACCESS_H
5580 +
5581 +#ifdef __KERNEL__
5582 +#ifndef __ASSEMBLY__
5583 +#include <linux/types.h>
5584 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5585 +#endif
5586 +#endif
5587 +
5588 #if defined(__sparc__) && defined(__arch64__)
5589 #include <asm/uaccess_64.h>
5590 #else
5591 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5592 index 8303ac4..07f333d 100644
5593 --- a/arch/sparc/include/asm/uaccess_32.h
5594 +++ b/arch/sparc/include/asm/uaccess_32.h
5595 @@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5596
5597 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5598 {
5599 - if (n && __access_ok((unsigned long) to, n))
5600 + if ((long)n < 0)
5601 + return n;
5602 +
5603 + if (n && __access_ok((unsigned long) to, n)) {
5604 + if (!__builtin_constant_p(n))
5605 + check_object_size(from, n, true);
5606 return __copy_user(to, (__force void __user *) from, n);
5607 - else
5608 + } else
5609 return n;
5610 }
5611
5612 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5613 {
5614 + if ((long)n < 0)
5615 + return n;
5616 +
5617 + if (!__builtin_constant_p(n))
5618 + check_object_size(from, n, true);
5619 +
5620 return __copy_user(to, (__force void __user *) from, n);
5621 }
5622
5623 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5624 {
5625 - if (n && __access_ok((unsigned long) from, n))
5626 + if ((long)n < 0)
5627 + return n;
5628 +
5629 + if (n && __access_ok((unsigned long) from, n)) {
5630 + if (!__builtin_constant_p(n))
5631 + check_object_size(to, n, false);
5632 return __copy_user((__force void __user *) to, from, n);
5633 - else
5634 + } else
5635 return n;
5636 }
5637
5638 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5639 {
5640 + if ((long)n < 0)
5641 + return n;
5642 +
5643 return __copy_user((__force void __user *) to, from, n);
5644 }
5645
5646 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5647 index a1091afb..380228e 100644
5648 --- a/arch/sparc/include/asm/uaccess_64.h
5649 +++ b/arch/sparc/include/asm/uaccess_64.h
5650 @@ -10,6 +10,7 @@
5651 #include <linux/compiler.h>
5652 #include <linux/string.h>
5653 #include <linux/thread_info.h>
5654 +#include <linux/kernel.h>
5655 #include <asm/asi.h>
5656 #include <asm/spitfire.h>
5657 #include <asm-generic/uaccess-unaligned.h>
5658 @@ -212,8 +213,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5659 static inline unsigned long __must_check
5660 copy_from_user(void *to, const void __user *from, unsigned long size)
5661 {
5662 - unsigned long ret = ___copy_from_user(to, from, size);
5663 + unsigned long ret;
5664
5665 + if ((long)size < 0 || size > INT_MAX)
5666 + return size;
5667 +
5668 + if (!__builtin_constant_p(size))
5669 + check_object_size(to, size, false);
5670 +
5671 + ret = ___copy_from_user(to, from, size);
5672 if (unlikely(ret))
5673 ret = copy_from_user_fixup(to, from, size);
5674
5675 @@ -229,8 +237,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5676 static inline unsigned long __must_check
5677 copy_to_user(void __user *to, const void *from, unsigned long size)
5678 {
5679 - unsigned long ret = ___copy_to_user(to, from, size);
5680 + unsigned long ret;
5681
5682 + if ((long)size < 0 || size > INT_MAX)
5683 + return size;
5684 +
5685 + if (!__builtin_constant_p(size))
5686 + check_object_size(from, size, true);
5687 +
5688 + ret = ___copy_to_user(to, from, size);
5689 if (unlikely(ret))
5690 ret = copy_to_user_fixup(to, from, size);
5691 return ret;
5692 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5693 index cb85458..e063f17 100644
5694 --- a/arch/sparc/kernel/Makefile
5695 +++ b/arch/sparc/kernel/Makefile
5696 @@ -3,7 +3,7 @@
5697 #
5698
5699 asflags-y := -ansi
5700 -ccflags-y := -Werror
5701 +#ccflags-y := -Werror
5702
5703 extra-y := head_$(BITS).o
5704 extra-y += init_task.o
5705 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5706 index efa0754..74b03fe 100644
5707 --- a/arch/sparc/kernel/process_32.c
5708 +++ b/arch/sparc/kernel/process_32.c
5709 @@ -200,7 +200,7 @@ void __show_backtrace(unsigned long fp)
5710 rw->ins[4], rw->ins[5],
5711 rw->ins[6],
5712 rw->ins[7]);
5713 - printk("%pS\n", (void *) rw->ins[7]);
5714 + printk("%pA\n", (void *) rw->ins[7]);
5715 rw = (struct reg_window32 *) rw->ins[6];
5716 }
5717 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
5718 @@ -267,14 +267,14 @@ void show_regs(struct pt_regs *r)
5719
5720 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5721 r->psr, r->pc, r->npc, r->y, print_tainted());
5722 - printk("PC: <%pS>\n", (void *) r->pc);
5723 + printk("PC: <%pA>\n", (void *) r->pc);
5724 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5725 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5726 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5727 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5728 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5729 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5730 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5731 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5732
5733 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5734 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5735 @@ -309,7 +309,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5736 rw = (struct reg_window32 *) fp;
5737 pc = rw->ins[7];
5738 printk("[%08lx : ", pc);
5739 - printk("%pS ] ", (void *) pc);
5740 + printk("%pA ] ", (void *) pc);
5741 fp = rw->ins[6];
5742 } while (++count < 16);
5743 printk("\n");
5744 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5745 index aff0c72..9067b39 100644
5746 --- a/arch/sparc/kernel/process_64.c
5747 +++ b/arch/sparc/kernel/process_64.c
5748 @@ -179,14 +179,14 @@ static void show_regwindow(struct pt_regs *regs)
5749 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5750 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5751 if (regs->tstate & TSTATE_PRIV)
5752 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5753 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5754 }
5755
5756 void show_regs(struct pt_regs *regs)
5757 {
5758 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5759 regs->tpc, regs->tnpc, regs->y, print_tainted());
5760 - printk("TPC: <%pS>\n", (void *) regs->tpc);
5761 + printk("TPC: <%pA>\n", (void *) regs->tpc);
5762 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5763 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5764 regs->u_regs[3]);
5765 @@ -199,7 +199,7 @@ void show_regs(struct pt_regs *regs)
5766 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5767 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5768 regs->u_regs[15]);
5769 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5770 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5771 show_regwindow(regs);
5772 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5773 }
5774 @@ -284,7 +284,7 @@ void arch_trigger_all_cpu_backtrace(void)
5775 ((tp && tp->task) ? tp->task->pid : -1));
5776
5777 if (gp->tstate & TSTATE_PRIV) {
5778 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5779 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5780 (void *) gp->tpc,
5781 (void *) gp->o7,
5782 (void *) gp->i7,
5783 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
5784 index 6f97c07..b1300ec 100644
5785 --- a/arch/sparc/kernel/ptrace_64.c
5786 +++ b/arch/sparc/kernel/ptrace_64.c
5787 @@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
5788 return ret;
5789 }
5790
5791 +#ifdef CONFIG_GRKERNSEC_SETXID
5792 +extern void gr_delayed_cred_worker(void);
5793 +#endif
5794 +
5795 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5796 {
5797 int ret = 0;
5798 @@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5799 /* do the secure computing check first */
5800 secure_computing(regs->u_regs[UREG_G1]);
5801
5802 +#ifdef CONFIG_GRKERNSEC_SETXID
5803 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5804 + gr_delayed_cred_worker();
5805 +#endif
5806 +
5807 if (test_thread_flag(TIF_SYSCALL_TRACE))
5808 ret = tracehook_report_syscall_entry(regs);
5809
5810 @@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5811
5812 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
5813 {
5814 +#ifdef CONFIG_GRKERNSEC_SETXID
5815 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5816 + gr_delayed_cred_worker();
5817 +#endif
5818 +
5819 audit_syscall_exit(regs);
5820
5821 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5822 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5823 index 42b282f..28ce9f2 100644
5824 --- a/arch/sparc/kernel/sys_sparc_32.c
5825 +++ b/arch/sparc/kernel/sys_sparc_32.c
5826 @@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5827 if (ARCH_SUN4C && len > 0x20000000)
5828 return -ENOMEM;
5829 if (!addr)
5830 - addr = TASK_UNMAPPED_BASE;
5831 + addr = current->mm->mmap_base;
5832
5833 if (flags & MAP_SHARED)
5834 addr = COLOUR_ALIGN(addr);
5835 @@ -71,7 +71,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5836 }
5837 if (TASK_SIZE - PAGE_SIZE - len < addr)
5838 return -ENOMEM;
5839 - if (!vmm || addr + len <= vmm->vm_start)
5840 + if (check_heap_stack_gap(vmm, addr, len))
5841 return addr;
5842 addr = vmm->vm_end;
5843 if (flags & MAP_SHARED)
5844 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5845 index 3ee51f1..2ba4913 100644
5846 --- a/arch/sparc/kernel/sys_sparc_64.c
5847 +++ b/arch/sparc/kernel/sys_sparc_64.c
5848 @@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5849 /* We do not accept a shared mapping if it would violate
5850 * cache aliasing constraints.
5851 */
5852 - if ((flags & MAP_SHARED) &&
5853 + if ((filp || (flags & MAP_SHARED)) &&
5854 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5855 return -EINVAL;
5856 return addr;
5857 @@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5858 if (filp || (flags & MAP_SHARED))
5859 do_color_align = 1;
5860
5861 +#ifdef CONFIG_PAX_RANDMMAP
5862 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5863 +#endif
5864 +
5865 if (addr) {
5866 if (do_color_align)
5867 addr = COLOUR_ALIGN(addr, pgoff);
5868 @@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5869 addr = PAGE_ALIGN(addr);
5870
5871 vma = find_vma(mm, addr);
5872 - if (task_size - len >= addr &&
5873 - (!vma || addr + len <= vma->vm_start))
5874 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5875 return addr;
5876 }
5877
5878 if (len > mm->cached_hole_size) {
5879 - start_addr = addr = mm->free_area_cache;
5880 + start_addr = addr = mm->free_area_cache;
5881 } else {
5882 - start_addr = addr = TASK_UNMAPPED_BASE;
5883 + start_addr = addr = mm->mmap_base;
5884 mm->cached_hole_size = 0;
5885 }
5886
5887 @@ -174,14 +177,14 @@ full_search:
5888 vma = find_vma(mm, VA_EXCLUDE_END);
5889 }
5890 if (unlikely(task_size < addr)) {
5891 - if (start_addr != TASK_UNMAPPED_BASE) {
5892 - start_addr = addr = TASK_UNMAPPED_BASE;
5893 + if (start_addr != mm->mmap_base) {
5894 + start_addr = addr = mm->mmap_base;
5895 mm->cached_hole_size = 0;
5896 goto full_search;
5897 }
5898 return -ENOMEM;
5899 }
5900 - if (likely(!vma || addr + len <= vma->vm_start)) {
5901 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5902 /*
5903 * Remember the place where we stopped the search:
5904 */
5905 @@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5906 /* We do not accept a shared mapping if it would violate
5907 * cache aliasing constraints.
5908 */
5909 - if ((flags & MAP_SHARED) &&
5910 + if ((filp || (flags & MAP_SHARED)) &&
5911 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5912 return -EINVAL;
5913 return addr;
5914 @@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5915 addr = PAGE_ALIGN(addr);
5916
5917 vma = find_vma(mm, addr);
5918 - if (task_size - len >= addr &&
5919 - (!vma || addr + len <= vma->vm_start))
5920 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5921 return addr;
5922 }
5923
5924 @@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5925 /* make sure it can fit in the remaining address space */
5926 if (likely(addr > len)) {
5927 vma = find_vma(mm, addr-len);
5928 - if (!vma || addr <= vma->vm_start) {
5929 + if (check_heap_stack_gap(vma, addr - len, len)) {
5930 /* remember the address as a hint for next time */
5931 return (mm->free_area_cache = addr-len);
5932 }
5933 @@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5934 if (unlikely(mm->mmap_base < len))
5935 goto bottomup;
5936
5937 - addr = mm->mmap_base-len;
5938 - if (do_color_align)
5939 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5940 + addr = mm->mmap_base - len;
5941
5942 do {
5943 + if (do_color_align)
5944 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5945 /*
5946 * Lookup failure means no vma is above this address,
5947 * else if new region fits below vma->vm_start,
5948 * return with success:
5949 */
5950 vma = find_vma(mm, addr);
5951 - if (likely(!vma || addr+len <= vma->vm_start)) {
5952 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5953 /* remember the address as a hint for next time */
5954 return (mm->free_area_cache = addr);
5955 }
5956 @@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5957 mm->cached_hole_size = vma->vm_start - addr;
5958
5959 /* try just below the current vma->vm_start */
5960 - addr = vma->vm_start-len;
5961 - if (do_color_align)
5962 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5963 - } while (likely(len < vma->vm_start));
5964 + addr = skip_heap_stack_gap(vma, len);
5965 + } while (!IS_ERR_VALUE(addr));
5966
5967 bottomup:
5968 /*
5969 @@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5970 gap == RLIM_INFINITY ||
5971 sysctl_legacy_va_layout) {
5972 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5973 +
5974 +#ifdef CONFIG_PAX_RANDMMAP
5975 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5976 + mm->mmap_base += mm->delta_mmap;
5977 +#endif
5978 +
5979 mm->get_unmapped_area = arch_get_unmapped_area;
5980 mm->unmap_area = arch_unmap_area;
5981 } else {
5982 @@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5983 gap = (task_size / 6 * 5);
5984
5985 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5986 +
5987 +#ifdef CONFIG_PAX_RANDMMAP
5988 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5989 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5990 +#endif
5991 +
5992 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5993 mm->unmap_area = arch_unmap_area_topdown;
5994 }
5995 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
5996 index 1d7e274..b39c527 100644
5997 --- a/arch/sparc/kernel/syscalls.S
5998 +++ b/arch/sparc/kernel/syscalls.S
5999 @@ -62,7 +62,7 @@ sys32_rt_sigreturn:
6000 #endif
6001 .align 32
6002 1: ldx [%g6 + TI_FLAGS], %l5
6003 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6004 + andcc %l5, _TIF_WORK_SYSCALL, %g0
6005 be,pt %icc, rtrap
6006 nop
6007 call syscall_trace_leave
6008 @@ -179,7 +179,7 @@ linux_sparc_syscall32:
6009
6010 srl %i5, 0, %o5 ! IEU1
6011 srl %i2, 0, %o2 ! IEU0 Group
6012 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6013 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6014 bne,pn %icc, linux_syscall_trace32 ! CTI
6015 mov %i0, %l5 ! IEU1
6016 call %l7 ! CTI Group brk forced
6017 @@ -202,7 +202,7 @@ linux_sparc_syscall:
6018
6019 mov %i3, %o3 ! IEU1
6020 mov %i4, %o4 ! IEU0 Group
6021 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6022 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6023 bne,pn %icc, linux_syscall_trace ! CTI Group
6024 mov %i0, %l5 ! IEU0
6025 2: call %l7 ! CTI Group brk forced
6026 @@ -226,7 +226,7 @@ ret_sys_call:
6027
6028 cmp %o0, -ERESTART_RESTARTBLOCK
6029 bgeu,pn %xcc, 1f
6030 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6031 + andcc %l0, _TIF_WORK_SYSCALL, %l6
6032 80:
6033 /* System call success, clear Carry condition code. */
6034 andn %g3, %g2, %g3
6035 @@ -241,7 +241,7 @@ ret_sys_call:
6036 /* System call failure, set Carry condition code.
6037 * Also, get abs(errno) to return to the process.
6038 */
6039 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6040 + andcc %l0, _TIF_WORK_SYSCALL, %l6
6041 sub %g0, %o0, %o0
6042 or %g3, %g2, %g3
6043 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
6044 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6045 index d2de213..6b22bc3 100644
6046 --- a/arch/sparc/kernel/traps_32.c
6047 +++ b/arch/sparc/kernel/traps_32.c
6048 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
6049 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6050 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6051
6052 +extern void gr_handle_kernel_exploit(void);
6053 +
6054 void die_if_kernel(char *str, struct pt_regs *regs)
6055 {
6056 static int die_counter;
6057 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6058 count++ < 30 &&
6059 (((unsigned long) rw) >= PAGE_OFFSET) &&
6060 !(((unsigned long) rw) & 0x7)) {
6061 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
6062 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
6063 (void *) rw->ins[7]);
6064 rw = (struct reg_window32 *)rw->ins[6];
6065 }
6066 }
6067 printk("Instruction DUMP:");
6068 instruction_dump ((unsigned long *) regs->pc);
6069 - if(regs->psr & PSR_PS)
6070 + if(regs->psr & PSR_PS) {
6071 + gr_handle_kernel_exploit();
6072 do_exit(SIGKILL);
6073 + }
6074 do_exit(SIGSEGV);
6075 }
6076
6077 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6078 index c72fdf5..743a344 100644
6079 --- a/arch/sparc/kernel/traps_64.c
6080 +++ b/arch/sparc/kernel/traps_64.c
6081 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6082 i + 1,
6083 p->trapstack[i].tstate, p->trapstack[i].tpc,
6084 p->trapstack[i].tnpc, p->trapstack[i].tt);
6085 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6086 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6087 }
6088 }
6089
6090 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6091
6092 lvl -= 0x100;
6093 if (regs->tstate & TSTATE_PRIV) {
6094 +
6095 +#ifdef CONFIG_PAX_REFCOUNT
6096 + if (lvl == 6)
6097 + pax_report_refcount_overflow(regs);
6098 +#endif
6099 +
6100 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6101 die_if_kernel(buffer, regs);
6102 }
6103 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6104 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6105 {
6106 char buffer[32];
6107 -
6108 +
6109 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6110 0, lvl, SIGTRAP) == NOTIFY_STOP)
6111 return;
6112
6113 +#ifdef CONFIG_PAX_REFCOUNT
6114 + if (lvl == 6)
6115 + pax_report_refcount_overflow(regs);
6116 +#endif
6117 +
6118 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6119
6120 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6121 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6122 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6123 printk("%s" "ERROR(%d): ",
6124 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6125 - printk("TPC<%pS>\n", (void *) regs->tpc);
6126 + printk("TPC<%pA>\n", (void *) regs->tpc);
6127 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6128 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6129 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6130 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6131 smp_processor_id(),
6132 (type & 0x1) ? 'I' : 'D',
6133 regs->tpc);
6134 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6135 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6136 panic("Irrecoverable Cheetah+ parity error.");
6137 }
6138
6139 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6140 smp_processor_id(),
6141 (type & 0x1) ? 'I' : 'D',
6142 regs->tpc);
6143 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6144 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6145 }
6146
6147 struct sun4v_error_entry {
6148 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6149
6150 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6151 regs->tpc, tl);
6152 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6153 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6154 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6155 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6156 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6157 (void *) regs->u_regs[UREG_I7]);
6158 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6159 "pte[%lx] error[%lx]\n",
6160 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6161
6162 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6163 regs->tpc, tl);
6164 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6165 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6166 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6167 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6168 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6169 (void *) regs->u_regs[UREG_I7]);
6170 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6171 "pte[%lx] error[%lx]\n",
6172 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6173 fp = (unsigned long)sf->fp + STACK_BIAS;
6174 }
6175
6176 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6177 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6178 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6179 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6180 int index = tsk->curr_ret_stack;
6181 if (tsk->ret_stack && index >= graph) {
6182 pc = tsk->ret_stack[index - graph].ret;
6183 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6184 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6185 graph++;
6186 }
6187 }
6188 @@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6189 return (struct reg_window *) (fp + STACK_BIAS);
6190 }
6191
6192 +extern void gr_handle_kernel_exploit(void);
6193 +
6194 void die_if_kernel(char *str, struct pt_regs *regs)
6195 {
6196 static int die_counter;
6197 @@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6198 while (rw &&
6199 count++ < 30 &&
6200 kstack_valid(tp, (unsigned long) rw)) {
6201 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
6202 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
6203 (void *) rw->ins[7]);
6204
6205 rw = kernel_stack_up(rw);
6206 @@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6207 }
6208 user_instruction_dump ((unsigned int __user *) regs->tpc);
6209 }
6210 - if (regs->tstate & TSTATE_PRIV)
6211 + if (regs->tstate & TSTATE_PRIV) {
6212 + gr_handle_kernel_exploit();
6213 do_exit(SIGKILL);
6214 + }
6215 do_exit(SIGSEGV);
6216 }
6217 EXPORT_SYMBOL(die_if_kernel);
6218 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6219 index dae85bc..af1e19d 100644
6220 --- a/arch/sparc/kernel/unaligned_64.c
6221 +++ b/arch/sparc/kernel/unaligned_64.c
6222 @@ -279,7 +279,7 @@ static void log_unaligned(struct pt_regs *regs)
6223 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6224
6225 if (__ratelimit(&ratelimit)) {
6226 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
6227 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
6228 regs->tpc, (void *) regs->tpc);
6229 }
6230 }
6231 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6232 index a3fc437..fea9957 100644
6233 --- a/arch/sparc/lib/Makefile
6234 +++ b/arch/sparc/lib/Makefile
6235 @@ -2,7 +2,7 @@
6236 #
6237
6238 asflags-y := -ansi -DST_DIV0=0x02
6239 -ccflags-y := -Werror
6240 +#ccflags-y := -Werror
6241
6242 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
6243 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6244 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6245 index 59186e0..f747d7a 100644
6246 --- a/arch/sparc/lib/atomic_64.S
6247 +++ b/arch/sparc/lib/atomic_64.S
6248 @@ -18,7 +18,12 @@
6249 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
6250 BACKOFF_SETUP(%o2)
6251 1: lduw [%o1], %g1
6252 - add %g1, %o0, %g7
6253 + addcc %g1, %o0, %g7
6254 +
6255 +#ifdef CONFIG_PAX_REFCOUNT
6256 + tvs %icc, 6
6257 +#endif
6258 +
6259 cas [%o1], %g1, %g7
6260 cmp %g1, %g7
6261 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6262 @@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
6263 2: BACKOFF_SPIN(%o2, %o3, 1b)
6264 .size atomic_add, .-atomic_add
6265
6266 + .globl atomic_add_unchecked
6267 + .type atomic_add_unchecked,#function
6268 +atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6269 + BACKOFF_SETUP(%o2)
6270 +1: lduw [%o1], %g1
6271 + add %g1, %o0, %g7
6272 + cas [%o1], %g1, %g7
6273 + cmp %g1, %g7
6274 + bne,pn %icc, 2f
6275 + nop
6276 + retl
6277 + nop
6278 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6279 + .size atomic_add_unchecked, .-atomic_add_unchecked
6280 +
6281 .globl atomic_sub
6282 .type atomic_sub,#function
6283 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6284 BACKOFF_SETUP(%o2)
6285 1: lduw [%o1], %g1
6286 - sub %g1, %o0, %g7
6287 + subcc %g1, %o0, %g7
6288 +
6289 +#ifdef CONFIG_PAX_REFCOUNT
6290 + tvs %icc, 6
6291 +#endif
6292 +
6293 cas [%o1], %g1, %g7
6294 cmp %g1, %g7
6295 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6296 @@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6297 2: BACKOFF_SPIN(%o2, %o3, 1b)
6298 .size atomic_sub, .-atomic_sub
6299
6300 + .globl atomic_sub_unchecked
6301 + .type atomic_sub_unchecked,#function
6302 +atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
6303 + BACKOFF_SETUP(%o2)
6304 +1: lduw [%o1], %g1
6305 + sub %g1, %o0, %g7
6306 + cas [%o1], %g1, %g7
6307 + cmp %g1, %g7
6308 + bne,pn %icc, 2f
6309 + nop
6310 + retl
6311 + nop
6312 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6313 + .size atomic_sub_unchecked, .-atomic_sub_unchecked
6314 +
6315 .globl atomic_add_ret
6316 .type atomic_add_ret,#function
6317 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6318 BACKOFF_SETUP(%o2)
6319 1: lduw [%o1], %g1
6320 - add %g1, %o0, %g7
6321 + addcc %g1, %o0, %g7
6322 +
6323 +#ifdef CONFIG_PAX_REFCOUNT
6324 + tvs %icc, 6
6325 +#endif
6326 +
6327 cas [%o1], %g1, %g7
6328 cmp %g1, %g7
6329 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6330 @@ -58,12 +103,33 @@ atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6331 2: BACKOFF_SPIN(%o2, %o3, 1b)
6332 .size atomic_add_ret, .-atomic_add_ret
6333
6334 + .globl atomic_add_ret_unchecked
6335 + .type atomic_add_ret_unchecked,#function
6336 +atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6337 + BACKOFF_SETUP(%o2)
6338 +1: lduw [%o1], %g1
6339 + addcc %g1, %o0, %g7
6340 + cas [%o1], %g1, %g7
6341 + cmp %g1, %g7
6342 + bne,pn %icc, 2f
6343 + add %g7, %o0, %g7
6344 + sra %g7, 0, %o0
6345 + retl
6346 + nop
6347 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6348 + .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
6349 +
6350 .globl atomic_sub_ret
6351 .type atomic_sub_ret,#function
6352 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6353 BACKOFF_SETUP(%o2)
6354 1: lduw [%o1], %g1
6355 - sub %g1, %o0, %g7
6356 + subcc %g1, %o0, %g7
6357 +
6358 +#ifdef CONFIG_PAX_REFCOUNT
6359 + tvs %icc, 6
6360 +#endif
6361 +
6362 cas [%o1], %g1, %g7
6363 cmp %g1, %g7
6364 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6365 @@ -78,7 +144,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6366 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
6367 BACKOFF_SETUP(%o2)
6368 1: ldx [%o1], %g1
6369 - add %g1, %o0, %g7
6370 + addcc %g1, %o0, %g7
6371 +
6372 +#ifdef CONFIG_PAX_REFCOUNT
6373 + tvs %xcc, 6
6374 +#endif
6375 +
6376 casx [%o1], %g1, %g7
6377 cmp %g1, %g7
6378 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6379 @@ -88,12 +159,32 @@ atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
6380 2: BACKOFF_SPIN(%o2, %o3, 1b)
6381 .size atomic64_add, .-atomic64_add
6382
6383 + .globl atomic64_add_unchecked
6384 + .type atomic64_add_unchecked,#function
6385 +atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6386 + BACKOFF_SETUP(%o2)
6387 +1: ldx [%o1], %g1
6388 + addcc %g1, %o0, %g7
6389 + casx [%o1], %g1, %g7
6390 + cmp %g1, %g7
6391 + bne,pn %xcc, 2f
6392 + nop
6393 + retl
6394 + nop
6395 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6396 + .size atomic64_add_unchecked, .-atomic64_add_unchecked
6397 +
6398 .globl atomic64_sub
6399 .type atomic64_sub,#function
6400 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6401 BACKOFF_SETUP(%o2)
6402 1: ldx [%o1], %g1
6403 - sub %g1, %o0, %g7
6404 + subcc %g1, %o0, %g7
6405 +
6406 +#ifdef CONFIG_PAX_REFCOUNT
6407 + tvs %xcc, 6
6408 +#endif
6409 +
6410 casx [%o1], %g1, %g7
6411 cmp %g1, %g7
6412 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6413 @@ -103,12 +194,32 @@ atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6414 2: BACKOFF_SPIN(%o2, %o3, 1b)
6415 .size atomic64_sub, .-atomic64_sub
6416
6417 + .globl atomic64_sub_unchecked
6418 + .type atomic64_sub_unchecked,#function
6419 +atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
6420 + BACKOFF_SETUP(%o2)
6421 +1: ldx [%o1], %g1
6422 + subcc %g1, %o0, %g7
6423 + casx [%o1], %g1, %g7
6424 + cmp %g1, %g7
6425 + bne,pn %xcc, 2f
6426 + nop
6427 + retl
6428 + nop
6429 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6430 + .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
6431 +
6432 .globl atomic64_add_ret
6433 .type atomic64_add_ret,#function
6434 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6435 BACKOFF_SETUP(%o2)
6436 1: ldx [%o1], %g1
6437 - add %g1, %o0, %g7
6438 + addcc %g1, %o0, %g7
6439 +
6440 +#ifdef CONFIG_PAX_REFCOUNT
6441 + tvs %xcc, 6
6442 +#endif
6443 +
6444 casx [%o1], %g1, %g7
6445 cmp %g1, %g7
6446 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6447 @@ -118,12 +229,33 @@ atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6448 2: BACKOFF_SPIN(%o2, %o3, 1b)
6449 .size atomic64_add_ret, .-atomic64_add_ret
6450
6451 + .globl atomic64_add_ret_unchecked
6452 + .type atomic64_add_ret_unchecked,#function
6453 +atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6454 + BACKOFF_SETUP(%o2)
6455 +1: ldx [%o1], %g1
6456 + addcc %g1, %o0, %g7
6457 + casx [%o1], %g1, %g7
6458 + cmp %g1, %g7
6459 + bne,pn %xcc, 2f
6460 + add %g7, %o0, %g7
6461 + mov %g7, %o0
6462 + retl
6463 + nop
6464 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6465 + .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
6466 +
6467 .globl atomic64_sub_ret
6468 .type atomic64_sub_ret,#function
6469 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6470 BACKOFF_SETUP(%o2)
6471 1: ldx [%o1], %g1
6472 - sub %g1, %o0, %g7
6473 + subcc %g1, %o0, %g7
6474 +
6475 +#ifdef CONFIG_PAX_REFCOUNT
6476 + tvs %xcc, 6
6477 +#endif
6478 +
6479 casx [%o1], %g1, %g7
6480 cmp %g1, %g7
6481 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6482 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6483 index f73c224..662af10 100644
6484 --- a/arch/sparc/lib/ksyms.c
6485 +++ b/arch/sparc/lib/ksyms.c
6486 @@ -136,12 +136,18 @@ EXPORT_SYMBOL(__downgrade_write);
6487
6488 /* Atomic counter implementation. */
6489 EXPORT_SYMBOL(atomic_add);
6490 +EXPORT_SYMBOL(atomic_add_unchecked);
6491 EXPORT_SYMBOL(atomic_add_ret);
6492 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
6493 EXPORT_SYMBOL(atomic_sub);
6494 +EXPORT_SYMBOL(atomic_sub_unchecked);
6495 EXPORT_SYMBOL(atomic_sub_ret);
6496 EXPORT_SYMBOL(atomic64_add);
6497 +EXPORT_SYMBOL(atomic64_add_unchecked);
6498 EXPORT_SYMBOL(atomic64_add_ret);
6499 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6500 EXPORT_SYMBOL(atomic64_sub);
6501 +EXPORT_SYMBOL(atomic64_sub_unchecked);
6502 EXPORT_SYMBOL(atomic64_sub_ret);
6503
6504 /* Atomic bit operations. */
6505 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6506 index 301421c..e2535d1 100644
6507 --- a/arch/sparc/mm/Makefile
6508 +++ b/arch/sparc/mm/Makefile
6509 @@ -2,7 +2,7 @@
6510 #
6511
6512 asflags-y := -ansi
6513 -ccflags-y := -Werror
6514 +#ccflags-y := -Werror
6515
6516 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6517 obj-y += fault_$(BITS).o
6518 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6519 index df3155a..eb708b8 100644
6520 --- a/arch/sparc/mm/fault_32.c
6521 +++ b/arch/sparc/mm/fault_32.c
6522 @@ -21,6 +21,9 @@
6523 #include <linux/perf_event.h>
6524 #include <linux/interrupt.h>
6525 #include <linux/kdebug.h>
6526 +#include <linux/slab.h>
6527 +#include <linux/pagemap.h>
6528 +#include <linux/compiler.h>
6529
6530 #include <asm/page.h>
6531 #include <asm/pgtable.h>
6532 @@ -207,6 +210,268 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6533 return safe_compute_effective_address(regs, insn);
6534 }
6535
6536 +#ifdef CONFIG_PAX_PAGEEXEC
6537 +#ifdef CONFIG_PAX_DLRESOLVE
6538 +static void pax_emuplt_close(struct vm_area_struct *vma)
6539 +{
6540 + vma->vm_mm->call_dl_resolve = 0UL;
6541 +}
6542 +
6543 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6544 +{
6545 + unsigned int *kaddr;
6546 +
6547 + vmf->page = alloc_page(GFP_HIGHUSER);
6548 + if (!vmf->page)
6549 + return VM_FAULT_OOM;
6550 +
6551 + kaddr = kmap(vmf->page);
6552 + memset(kaddr, 0, PAGE_SIZE);
6553 + kaddr[0] = 0x9DE3BFA8U; /* save */
6554 + flush_dcache_page(vmf->page);
6555 + kunmap(vmf->page);
6556 + return VM_FAULT_MAJOR;
6557 +}
6558 +
6559 +static const struct vm_operations_struct pax_vm_ops = {
6560 + .close = pax_emuplt_close,
6561 + .fault = pax_emuplt_fault
6562 +};
6563 +
6564 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6565 +{
6566 + int ret;
6567 +
6568 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6569 + vma->vm_mm = current->mm;
6570 + vma->vm_start = addr;
6571 + vma->vm_end = addr + PAGE_SIZE;
6572 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6573 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6574 + vma->vm_ops = &pax_vm_ops;
6575 +
6576 + ret = insert_vm_struct(current->mm, vma);
6577 + if (ret)
6578 + return ret;
6579 +
6580 + ++current->mm->total_vm;
6581 + return 0;
6582 +}
6583 +#endif
6584 +
6585 +/*
6586 + * PaX: decide what to do with offenders (regs->pc = fault address)
6587 + *
6588 + * returns 1 when task should be killed
6589 + * 2 when patched PLT trampoline was detected
6590 + * 3 when unpatched PLT trampoline was detected
6591 + */
6592 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6593 +{
6594 +
6595 +#ifdef CONFIG_PAX_EMUPLT
6596 + int err;
6597 +
6598 + do { /* PaX: patched PLT emulation #1 */
6599 + unsigned int sethi1, sethi2, jmpl;
6600 +
6601 + err = get_user(sethi1, (unsigned int *)regs->pc);
6602 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6603 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6604 +
6605 + if (err)
6606 + break;
6607 +
6608 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6609 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6610 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6611 + {
6612 + unsigned int addr;
6613 +
6614 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6615 + addr = regs->u_regs[UREG_G1];
6616 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6617 + regs->pc = addr;
6618 + regs->npc = addr+4;
6619 + return 2;
6620 + }
6621 + } while (0);
6622 +
6623 + { /* PaX: patched PLT emulation #2 */
6624 + unsigned int ba;
6625 +
6626 + err = get_user(ba, (unsigned int *)regs->pc);
6627 +
6628 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6629 + unsigned int addr;
6630 +
6631 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6632 + regs->pc = addr;
6633 + regs->npc = addr+4;
6634 + return 2;
6635 + }
6636 + }
6637 +
6638 + do { /* PaX: patched PLT emulation #3 */
6639 + unsigned int sethi, jmpl, nop;
6640 +
6641 + err = get_user(sethi, (unsigned int *)regs->pc);
6642 + err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
6643 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6644 +
6645 + if (err)
6646 + break;
6647 +
6648 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6649 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6650 + nop == 0x01000000U)
6651 + {
6652 + unsigned int addr;
6653 +
6654 + addr = (sethi & 0x003FFFFFU) << 10;
6655 + regs->u_regs[UREG_G1] = addr;
6656 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6657 + regs->pc = addr;
6658 + regs->npc = addr+4;
6659 + return 2;
6660 + }
6661 + } while (0);
6662 +
6663 + do { /* PaX: unpatched PLT emulation step 1 */
6664 + unsigned int sethi, ba, nop;
6665 +
6666 + err = get_user(sethi, (unsigned int *)regs->pc);
6667 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
6668 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6669 +
6670 + if (err)
6671 + break;
6672 +
6673 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6674 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6675 + nop == 0x01000000U)
6676 + {
6677 + unsigned int addr, save, call;
6678 +
6679 + if ((ba & 0xFFC00000U) == 0x30800000U)
6680 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6681 + else
6682 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6683 +
6684 + err = get_user(save, (unsigned int *)addr);
6685 + err |= get_user(call, (unsigned int *)(addr+4));
6686 + err |= get_user(nop, (unsigned int *)(addr+8));
6687 + if (err)
6688 + break;
6689 +
6690 +#ifdef CONFIG_PAX_DLRESOLVE
6691 + if (save == 0x9DE3BFA8U &&
6692 + (call & 0xC0000000U) == 0x40000000U &&
6693 + nop == 0x01000000U)
6694 + {
6695 + struct vm_area_struct *vma;
6696 + unsigned long call_dl_resolve;
6697 +
6698 + down_read(&current->mm->mmap_sem);
6699 + call_dl_resolve = current->mm->call_dl_resolve;
6700 + up_read(&current->mm->mmap_sem);
6701 + if (likely(call_dl_resolve))
6702 + goto emulate;
6703 +
6704 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6705 +
6706 + down_write(&current->mm->mmap_sem);
6707 + if (current->mm->call_dl_resolve) {
6708 + call_dl_resolve = current->mm->call_dl_resolve;
6709 + up_write(&current->mm->mmap_sem);
6710 + if (vma)
6711 + kmem_cache_free(vm_area_cachep, vma);
6712 + goto emulate;
6713 + }
6714 +
6715 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6716 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6717 + up_write(&current->mm->mmap_sem);
6718 + if (vma)
6719 + kmem_cache_free(vm_area_cachep, vma);
6720 + return 1;
6721 + }
6722 +
6723 + if (pax_insert_vma(vma, call_dl_resolve)) {
6724 + up_write(&current->mm->mmap_sem);
6725 + kmem_cache_free(vm_area_cachep, vma);
6726 + return 1;
6727 + }
6728 +
6729 + current->mm->call_dl_resolve = call_dl_resolve;
6730 + up_write(&current->mm->mmap_sem);
6731 +
6732 +emulate:
6733 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6734 + regs->pc = call_dl_resolve;
6735 + regs->npc = addr+4;
6736 + return 3;
6737 + }
6738 +#endif
6739 +
6740 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6741 + if ((save & 0xFFC00000U) == 0x05000000U &&
6742 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6743 + nop == 0x01000000U)
6744 + {
6745 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6746 + regs->u_regs[UREG_G2] = addr + 4;
6747 + addr = (save & 0x003FFFFFU) << 10;
6748 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6749 + regs->pc = addr;
6750 + regs->npc = addr+4;
6751 + return 3;
6752 + }
6753 + }
6754 + } while (0);
6755 +
6756 + do { /* PaX: unpatched PLT emulation step 2 */
6757 + unsigned int save, call, nop;
6758 +
6759 + err = get_user(save, (unsigned int *)(regs->pc-4));
6760 + err |= get_user(call, (unsigned int *)regs->pc);
6761 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
6762 + if (err)
6763 + break;
6764 +
6765 + if (save == 0x9DE3BFA8U &&
6766 + (call & 0xC0000000U) == 0x40000000U &&
6767 + nop == 0x01000000U)
6768 + {
6769 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6770 +
6771 + regs->u_regs[UREG_RETPC] = regs->pc;
6772 + regs->pc = dl_resolve;
6773 + regs->npc = dl_resolve+4;
6774 + return 3;
6775 + }
6776 + } while (0);
6777 +#endif
6778 +
6779 + return 1;
6780 +}
6781 +
6782 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6783 +{
6784 + unsigned long i;
6785 +
6786 + printk(KERN_ERR "PAX: bytes at PC: ");
6787 + for (i = 0; i < 8; i++) {
6788 + unsigned int c;
6789 + if (get_user(c, (unsigned int *)pc+i))
6790 + printk(KERN_CONT "???????? ");
6791 + else
6792 + printk(KERN_CONT "%08x ", c);
6793 + }
6794 + printk("\n");
6795 +}
6796 +#endif
6797 +
6798 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6799 int text_fault)
6800 {
6801 @@ -282,6 +547,24 @@ good_area:
6802 if(!(vma->vm_flags & VM_WRITE))
6803 goto bad_area;
6804 } else {
6805 +
6806 +#ifdef CONFIG_PAX_PAGEEXEC
6807 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6808 + up_read(&mm->mmap_sem);
6809 + switch (pax_handle_fetch_fault(regs)) {
6810 +
6811 +#ifdef CONFIG_PAX_EMUPLT
6812 + case 2:
6813 + case 3:
6814 + return;
6815 +#endif
6816 +
6817 + }
6818 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6819 + do_group_exit(SIGKILL);
6820 + }
6821 +#endif
6822 +
6823 /* Allow reads even for write-only mappings */
6824 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
6825 goto bad_area;
6826 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6827 index 1fe0429..aee2e87 100644
6828 --- a/arch/sparc/mm/fault_64.c
6829 +++ b/arch/sparc/mm/fault_64.c
6830 @@ -21,6 +21,9 @@
6831 #include <linux/kprobes.h>
6832 #include <linux/kdebug.h>
6833 #include <linux/percpu.h>
6834 +#include <linux/slab.h>
6835 +#include <linux/pagemap.h>
6836 +#include <linux/compiler.h>
6837
6838 #include <asm/page.h>
6839 #include <asm/pgtable.h>
6840 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6841 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6842 regs->tpc);
6843 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6844 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6845 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6846 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6847 dump_stack();
6848 unhandled_fault(regs->tpc, current, regs);
6849 @@ -272,6 +275,457 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6850 show_regs(regs);
6851 }
6852
6853 +#ifdef CONFIG_PAX_PAGEEXEC
6854 +#ifdef CONFIG_PAX_DLRESOLVE
6855 +static void pax_emuplt_close(struct vm_area_struct *vma)
6856 +{
6857 + vma->vm_mm->call_dl_resolve = 0UL;
6858 +}
6859 +
6860 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6861 +{
6862 + unsigned int *kaddr;
6863 +
6864 + vmf->page = alloc_page(GFP_HIGHUSER);
6865 + if (!vmf->page)
6866 + return VM_FAULT_OOM;
6867 +
6868 + kaddr = kmap(vmf->page);
6869 + memset(kaddr, 0, PAGE_SIZE);
6870 + kaddr[0] = 0x9DE3BFA8U; /* save */
6871 + flush_dcache_page(vmf->page);
6872 + kunmap(vmf->page);
6873 + return VM_FAULT_MAJOR;
6874 +}
6875 +
6876 +static const struct vm_operations_struct pax_vm_ops = {
6877 + .close = pax_emuplt_close,
6878 + .fault = pax_emuplt_fault
6879 +};
6880 +
6881 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6882 +{
6883 + int ret;
6884 +
6885 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6886 + vma->vm_mm = current->mm;
6887 + vma->vm_start = addr;
6888 + vma->vm_end = addr + PAGE_SIZE;
6889 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6890 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6891 + vma->vm_ops = &pax_vm_ops;
6892 +
6893 + ret = insert_vm_struct(current->mm, vma);
6894 + if (ret)
6895 + return ret;
6896 +
6897 + ++current->mm->total_vm;
6898 + return 0;
6899 +}
6900 +#endif
6901 +
6902 +/*
6903 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6904 + *
6905 + * returns 1 when task should be killed
6906 + * 2 when patched PLT trampoline was detected
6907 + * 3 when unpatched PLT trampoline was detected
6908 + */
6909 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6910 +{
6911 +
6912 +#ifdef CONFIG_PAX_EMUPLT
6913 + int err;
6914 +
6915 + do { /* PaX: patched PLT emulation #1 */
6916 + unsigned int sethi1, sethi2, jmpl;
6917 +
6918 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6919 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6920 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6921 +
6922 + if (err)
6923 + break;
6924 +
6925 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6926 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6927 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6928 + {
6929 + unsigned long addr;
6930 +
6931 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6932 + addr = regs->u_regs[UREG_G1];
6933 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6934 +
6935 + if (test_thread_flag(TIF_32BIT))
6936 + addr &= 0xFFFFFFFFUL;
6937 +
6938 + regs->tpc = addr;
6939 + regs->tnpc = addr+4;
6940 + return 2;
6941 + }
6942 + } while (0);
6943 +
6944 + { /* PaX: patched PLT emulation #2 */
6945 + unsigned int ba;
6946 +
6947 + err = get_user(ba, (unsigned int *)regs->tpc);
6948 +
6949 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6950 + unsigned long addr;
6951 +
6952 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6953 +
6954 + if (test_thread_flag(TIF_32BIT))
6955 + addr &= 0xFFFFFFFFUL;
6956 +
6957 + regs->tpc = addr;
6958 + regs->tnpc = addr+4;
6959 + return 2;
6960 + }
6961 + }
6962 +
6963 + do { /* PaX: patched PLT emulation #3 */
6964 + unsigned int sethi, jmpl, nop;
6965 +
6966 + err = get_user(sethi, (unsigned int *)regs->tpc);
6967 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
6968 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6969 +
6970 + if (err)
6971 + break;
6972 +
6973 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6974 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6975 + nop == 0x01000000U)
6976 + {
6977 + unsigned long addr;
6978 +
6979 + addr = (sethi & 0x003FFFFFU) << 10;
6980 + regs->u_regs[UREG_G1] = addr;
6981 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6982 +
6983 + if (test_thread_flag(TIF_32BIT))
6984 + addr &= 0xFFFFFFFFUL;
6985 +
6986 + regs->tpc = addr;
6987 + regs->tnpc = addr+4;
6988 + return 2;
6989 + }
6990 + } while (0);
6991 +
6992 + do { /* PaX: patched PLT emulation #4 */
6993 + unsigned int sethi, mov1, call, mov2;
6994 +
6995 + err = get_user(sethi, (unsigned int *)regs->tpc);
6996 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6997 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
6998 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6999 +
7000 + if (err)
7001 + break;
7002 +
7003 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7004 + mov1 == 0x8210000FU &&
7005 + (call & 0xC0000000U) == 0x40000000U &&
7006 + mov2 == 0x9E100001U)
7007 + {
7008 + unsigned long addr;
7009 +
7010 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
7011 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7012 +
7013 + if (test_thread_flag(TIF_32BIT))
7014 + addr &= 0xFFFFFFFFUL;
7015 +
7016 + regs->tpc = addr;
7017 + regs->tnpc = addr+4;
7018 + return 2;
7019 + }
7020 + } while (0);
7021 +
7022 + do { /* PaX: patched PLT emulation #5 */
7023 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
7024 +
7025 + err = get_user(sethi, (unsigned int *)regs->tpc);
7026 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7027 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7028 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
7029 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
7030 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
7031 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
7032 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
7033 +
7034 + if (err)
7035 + break;
7036 +
7037 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7038 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7039 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7040 + (or1 & 0xFFFFE000U) == 0x82106000U &&
7041 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7042 + sllx == 0x83287020U &&
7043 + jmpl == 0x81C04005U &&
7044 + nop == 0x01000000U)
7045 + {
7046 + unsigned long addr;
7047 +
7048 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7049 + regs->u_regs[UREG_G1] <<= 32;
7050 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7051 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7052 + regs->tpc = addr;
7053 + regs->tnpc = addr+4;
7054 + return 2;
7055 + }
7056 + } while (0);
7057 +
7058 + do { /* PaX: patched PLT emulation #6 */
7059 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7060 +
7061 + err = get_user(sethi, (unsigned int *)regs->tpc);
7062 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7063 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7064 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7065 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
7066 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7067 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7068 +
7069 + if (err)
7070 + break;
7071 +
7072 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7073 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7074 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7075 + sllx == 0x83287020U &&
7076 + (or & 0xFFFFE000U) == 0x8A116000U &&
7077 + jmpl == 0x81C04005U &&
7078 + nop == 0x01000000U)
7079 + {
7080 + unsigned long addr;
7081 +
7082 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7083 + regs->u_regs[UREG_G1] <<= 32;
7084 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7085 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7086 + regs->tpc = addr;
7087 + regs->tnpc = addr+4;
7088 + return 2;
7089 + }
7090 + } while (0);
7091 +
7092 + do { /* PaX: unpatched PLT emulation step 1 */
7093 + unsigned int sethi, ba, nop;
7094 +
7095 + err = get_user(sethi, (unsigned int *)regs->tpc);
7096 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7097 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7098 +
7099 + if (err)
7100 + break;
7101 +
7102 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7103 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7104 + nop == 0x01000000U)
7105 + {
7106 + unsigned long addr;
7107 + unsigned int save, call;
7108 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7109 +
7110 + if ((ba & 0xFFC00000U) == 0x30800000U)
7111 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7112 + else
7113 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7114 +
7115 + if (test_thread_flag(TIF_32BIT))
7116 + addr &= 0xFFFFFFFFUL;
7117 +
7118 + err = get_user(save, (unsigned int *)addr);
7119 + err |= get_user(call, (unsigned int *)(addr+4));
7120 + err |= get_user(nop, (unsigned int *)(addr+8));
7121 + if (err)
7122 + break;
7123 +
7124 +#ifdef CONFIG_PAX_DLRESOLVE
7125 + if (save == 0x9DE3BFA8U &&
7126 + (call & 0xC0000000U) == 0x40000000U &&
7127 + nop == 0x01000000U)
7128 + {
7129 + struct vm_area_struct *vma;
7130 + unsigned long call_dl_resolve;
7131 +
7132 + down_read(&current->mm->mmap_sem);
7133 + call_dl_resolve = current->mm->call_dl_resolve;
7134 + up_read(&current->mm->mmap_sem);
7135 + if (likely(call_dl_resolve))
7136 + goto emulate;
7137 +
7138 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7139 +
7140 + down_write(&current->mm->mmap_sem);
7141 + if (current->mm->call_dl_resolve) {
7142 + call_dl_resolve = current->mm->call_dl_resolve;
7143 + up_write(&current->mm->mmap_sem);
7144 + if (vma)
7145 + kmem_cache_free(vm_area_cachep, vma);
7146 + goto emulate;
7147 + }
7148 +
7149 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7150 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7151 + up_write(&current->mm->mmap_sem);
7152 + if (vma)
7153 + kmem_cache_free(vm_area_cachep, vma);
7154 + return 1;
7155 + }
7156 +
7157 + if (pax_insert_vma(vma, call_dl_resolve)) {
7158 + up_write(&current->mm->mmap_sem);
7159 + kmem_cache_free(vm_area_cachep, vma);
7160 + return 1;
7161 + }
7162 +
7163 + current->mm->call_dl_resolve = call_dl_resolve;
7164 + up_write(&current->mm->mmap_sem);
7165 +
7166 +emulate:
7167 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7168 + regs->tpc = call_dl_resolve;
7169 + regs->tnpc = addr+4;
7170 + return 3;
7171 + }
7172 +#endif
7173 +
7174 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7175 + if ((save & 0xFFC00000U) == 0x05000000U &&
7176 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7177 + nop == 0x01000000U)
7178 + {
7179 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7180 + regs->u_regs[UREG_G2] = addr + 4;
7181 + addr = (save & 0x003FFFFFU) << 10;
7182 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7183 +
7184 + if (test_thread_flag(TIF_32BIT))
7185 + addr &= 0xFFFFFFFFUL;
7186 +
7187 + regs->tpc = addr;
7188 + regs->tnpc = addr+4;
7189 + return 3;
7190 + }
7191 +
7192 + /* PaX: 64-bit PLT stub */
7193 + err = get_user(sethi1, (unsigned int *)addr);
7194 + err |= get_user(sethi2, (unsigned int *)(addr+4));
7195 + err |= get_user(or1, (unsigned int *)(addr+8));
7196 + err |= get_user(or2, (unsigned int *)(addr+12));
7197 + err |= get_user(sllx, (unsigned int *)(addr+16));
7198 + err |= get_user(add, (unsigned int *)(addr+20));
7199 + err |= get_user(jmpl, (unsigned int *)(addr+24));
7200 + err |= get_user(nop, (unsigned int *)(addr+28));
7201 + if (err)
7202 + break;
7203 +
7204 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7205 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7206 + (or1 & 0xFFFFE000U) == 0x88112000U &&
7207 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7208 + sllx == 0x89293020U &&
7209 + add == 0x8A010005U &&
7210 + jmpl == 0x89C14000U &&
7211 + nop == 0x01000000U)
7212 + {
7213 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7214 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7215 + regs->u_regs[UREG_G4] <<= 32;
7216 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7217 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7218 + regs->u_regs[UREG_G4] = addr + 24;
7219 + addr = regs->u_regs[UREG_G5];
7220 + regs->tpc = addr;
7221 + regs->tnpc = addr+4;
7222 + return 3;
7223 + }
7224 + }
7225 + } while (0);
7226 +
7227 +#ifdef CONFIG_PAX_DLRESOLVE
7228 + do { /* PaX: unpatched PLT emulation step 2 */
7229 + unsigned int save, call, nop;
7230 +
7231 + err = get_user(save, (unsigned int *)(regs->tpc-4));
7232 + err |= get_user(call, (unsigned int *)regs->tpc);
7233 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7234 + if (err)
7235 + break;
7236 +
7237 + if (save == 0x9DE3BFA8U &&
7238 + (call & 0xC0000000U) == 0x40000000U &&
7239 + nop == 0x01000000U)
7240 + {
7241 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7242 +
7243 + if (test_thread_flag(TIF_32BIT))
7244 + dl_resolve &= 0xFFFFFFFFUL;
7245 +
7246 + regs->u_regs[UREG_RETPC] = regs->tpc;
7247 + regs->tpc = dl_resolve;
7248 + regs->tnpc = dl_resolve+4;
7249 + return 3;
7250 + }
7251 + } while (0);
7252 +#endif
7253 +
7254 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7255 + unsigned int sethi, ba, nop;
7256 +
7257 + err = get_user(sethi, (unsigned int *)regs->tpc);
7258 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7259 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7260 +
7261 + if (err)
7262 + break;
7263 +
7264 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7265 + (ba & 0xFFF00000U) == 0x30600000U &&
7266 + nop == 0x01000000U)
7267 + {
7268 + unsigned long addr;
7269 +
7270 + addr = (sethi & 0x003FFFFFU) << 10;
7271 + regs->u_regs[UREG_G1] = addr;
7272 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7273 +
7274 + if (test_thread_flag(TIF_32BIT))
7275 + addr &= 0xFFFFFFFFUL;
7276 +
7277 + regs->tpc = addr;
7278 + regs->tnpc = addr+4;
7279 + return 2;
7280 + }
7281 + } while (0);
7282 +
7283 +#endif
7284 +
7285 + return 1;
7286 +}
7287 +
7288 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7289 +{
7290 + unsigned long i;
7291 +
7292 + printk(KERN_ERR "PAX: bytes at PC: ");
7293 + for (i = 0; i < 8; i++) {
7294 + unsigned int c;
7295 + if (get_user(c, (unsigned int *)pc+i))
7296 + printk(KERN_CONT "???????? ");
7297 + else
7298 + printk(KERN_CONT "%08x ", c);
7299 + }
7300 + printk("\n");
7301 +}
7302 +#endif
7303 +
7304 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7305 {
7306 struct mm_struct *mm = current->mm;
7307 @@ -343,6 +797,29 @@ retry:
7308 if (!vma)
7309 goto bad_area;
7310
7311 +#ifdef CONFIG_PAX_PAGEEXEC
7312 + /* PaX: detect ITLB misses on non-exec pages */
7313 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7314 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7315 + {
7316 + if (address != regs->tpc)
7317 + goto good_area;
7318 +
7319 + up_read(&mm->mmap_sem);
7320 + switch (pax_handle_fetch_fault(regs)) {
7321 +
7322 +#ifdef CONFIG_PAX_EMUPLT
7323 + case 2:
7324 + case 3:
7325 + return;
7326 +#endif
7327 +
7328 + }
7329 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7330 + do_group_exit(SIGKILL);
7331 + }
7332 +#endif
7333 +
7334 /* Pure DTLB misses do not tell us whether the fault causing
7335 * load/store/atomic was a write or not, it only says that there
7336 * was no match. So in such a case we (carefully) read the
7337 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7338 index 07e1453..0a7d9e9 100644
7339 --- a/arch/sparc/mm/hugetlbpage.c
7340 +++ b/arch/sparc/mm/hugetlbpage.c
7341 @@ -67,7 +67,7 @@ full_search:
7342 }
7343 return -ENOMEM;
7344 }
7345 - if (likely(!vma || addr + len <= vma->vm_start)) {
7346 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7347 /*
7348 * Remember the place where we stopped the search:
7349 */
7350 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7351 /* make sure it can fit in the remaining address space */
7352 if (likely(addr > len)) {
7353 vma = find_vma(mm, addr-len);
7354 - if (!vma || addr <= vma->vm_start) {
7355 + if (check_heap_stack_gap(vma, addr - len, len)) {
7356 /* remember the address as a hint for next time */
7357 return (mm->free_area_cache = addr-len);
7358 }
7359 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7360 if (unlikely(mm->mmap_base < len))
7361 goto bottomup;
7362
7363 - addr = (mm->mmap_base-len) & HPAGE_MASK;
7364 + addr = mm->mmap_base - len;
7365
7366 do {
7367 + addr &= HPAGE_MASK;
7368 /*
7369 * Lookup failure means no vma is above this address,
7370 * else if new region fits below vma->vm_start,
7371 * return with success:
7372 */
7373 vma = find_vma(mm, addr);
7374 - if (likely(!vma || addr+len <= vma->vm_start)) {
7375 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7376 /* remember the address as a hint for next time */
7377 return (mm->free_area_cache = addr);
7378 }
7379 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7380 mm->cached_hole_size = vma->vm_start - addr;
7381
7382 /* try just below the current vma->vm_start */
7383 - addr = (vma->vm_start-len) & HPAGE_MASK;
7384 - } while (likely(len < vma->vm_start));
7385 + addr = skip_heap_stack_gap(vma, len);
7386 + } while (!IS_ERR_VALUE(addr));
7387
7388 bottomup:
7389 /*
7390 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7391 if (addr) {
7392 addr = ALIGN(addr, HPAGE_SIZE);
7393 vma = find_vma(mm, addr);
7394 - if (task_size - len >= addr &&
7395 - (!vma || addr + len <= vma->vm_start))
7396 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7397 return addr;
7398 }
7399 if (mm->get_unmapped_area == arch_get_unmapped_area)
7400 diff --git a/arch/sparc/mm/init_32.c b/arch/sparc/mm/init_32.c
7401 index c5f9021..7591bae 100644
7402 --- a/arch/sparc/mm/init_32.c
7403 +++ b/arch/sparc/mm/init_32.c
7404 @@ -315,6 +315,9 @@ extern void device_scan(void);
7405 pgprot_t PAGE_SHARED __read_mostly;
7406 EXPORT_SYMBOL(PAGE_SHARED);
7407
7408 +pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
7409 +EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
7410 +
7411 void __init paging_init(void)
7412 {
7413 switch(sparc_cpu_model) {
7414 @@ -343,17 +346,17 @@ void __init paging_init(void)
7415
7416 /* Initialize the protection map with non-constant, MMU dependent values. */
7417 protection_map[0] = PAGE_NONE;
7418 - protection_map[1] = PAGE_READONLY;
7419 - protection_map[2] = PAGE_COPY;
7420 - protection_map[3] = PAGE_COPY;
7421 + protection_map[1] = PAGE_READONLY_NOEXEC;
7422 + protection_map[2] = PAGE_COPY_NOEXEC;
7423 + protection_map[3] = PAGE_COPY_NOEXEC;
7424 protection_map[4] = PAGE_READONLY;
7425 protection_map[5] = PAGE_READONLY;
7426 protection_map[6] = PAGE_COPY;
7427 protection_map[7] = PAGE_COPY;
7428 protection_map[8] = PAGE_NONE;
7429 - protection_map[9] = PAGE_READONLY;
7430 - protection_map[10] = PAGE_SHARED;
7431 - protection_map[11] = PAGE_SHARED;
7432 + protection_map[9] = PAGE_READONLY_NOEXEC;
7433 + protection_map[10] = PAGE_SHARED_NOEXEC;
7434 + protection_map[11] = PAGE_SHARED_NOEXEC;
7435 protection_map[12] = PAGE_READONLY;
7436 protection_map[13] = PAGE_READONLY;
7437 protection_map[14] = PAGE_SHARED;
7438 diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
7439 index cbef74e..c38fead 100644
7440 --- a/arch/sparc/mm/srmmu.c
7441 +++ b/arch/sparc/mm/srmmu.c
7442 @@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
7443 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
7444 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
7445 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
7446 +
7447 +#ifdef CONFIG_PAX_PAGEEXEC
7448 + PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
7449 + BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
7450 + BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
7451 +#endif
7452 +
7453 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
7454 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
7455
7456 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7457 index f4500c6..889656c 100644
7458 --- a/arch/tile/include/asm/atomic_64.h
7459 +++ b/arch/tile/include/asm/atomic_64.h
7460 @@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7461
7462 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7463
7464 +#define atomic64_read_unchecked(v) atomic64_read(v)
7465 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7466 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7467 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7468 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7469 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7470 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7471 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7472 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7473 +
7474 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7475 #define smp_mb__before_atomic_dec() smp_mb()
7476 #define smp_mb__after_atomic_dec() smp_mb()
7477 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7478 index 392e533..536b092 100644
7479 --- a/arch/tile/include/asm/cache.h
7480 +++ b/arch/tile/include/asm/cache.h
7481 @@ -15,11 +15,12 @@
7482 #ifndef _ASM_TILE_CACHE_H
7483 #define _ASM_TILE_CACHE_H
7484
7485 +#include <linux/const.h>
7486 #include <arch/chip.h>
7487
7488 /* bytes per L1 data cache line */
7489 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7490 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7491 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7492
7493 /* bytes per L2 cache line */
7494 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7495 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
7496 index ef34d2c..d6ce60c 100644
7497 --- a/arch/tile/include/asm/uaccess.h
7498 +++ b/arch/tile/include/asm/uaccess.h
7499 @@ -361,9 +361,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
7500 const void __user *from,
7501 unsigned long n)
7502 {
7503 - int sz = __compiletime_object_size(to);
7504 + size_t sz = __compiletime_object_size(to);
7505
7506 - if (likely(sz == -1 || sz >= n))
7507 + if (likely(sz == (size_t)-1 || sz >= n))
7508 n = _copy_from_user(to, from, n);
7509 else
7510 copy_from_user_overflow();
7511 diff --git a/arch/um/Makefile b/arch/um/Makefile
7512 index 55c0661..86ad413 100644
7513 --- a/arch/um/Makefile
7514 +++ b/arch/um/Makefile
7515 @@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7516 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7517 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7518
7519 +ifdef CONSTIFY_PLUGIN
7520 +USER_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7521 +endif
7522 +
7523 #This will adjust *FLAGS accordingly to the platform.
7524 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7525
7526 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7527 index 19e1bdd..3665b77 100644
7528 --- a/arch/um/include/asm/cache.h
7529 +++ b/arch/um/include/asm/cache.h
7530 @@ -1,6 +1,7 @@
7531 #ifndef __UM_CACHE_H
7532 #define __UM_CACHE_H
7533
7534 +#include <linux/const.h>
7535
7536 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7537 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7538 @@ -12,6 +13,6 @@
7539 # define L1_CACHE_SHIFT 5
7540 #endif
7541
7542 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7543 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7544
7545 #endif
7546 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7547 index 6c03acd..a5e0215 100644
7548 --- a/arch/um/include/asm/kmap_types.h
7549 +++ b/arch/um/include/asm/kmap_types.h
7550 @@ -23,6 +23,7 @@ enum km_type {
7551 KM_IRQ1,
7552 KM_SOFTIRQ0,
7553 KM_SOFTIRQ1,
7554 + KM_CLEARPAGE,
7555 KM_TYPE_NR
7556 };
7557
7558 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7559 index 7cfc3ce..cbd1a58 100644
7560 --- a/arch/um/include/asm/page.h
7561 +++ b/arch/um/include/asm/page.h
7562 @@ -14,6 +14,9 @@
7563 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7564 #define PAGE_MASK (~(PAGE_SIZE-1))
7565
7566 +#define ktla_ktva(addr) (addr)
7567 +#define ktva_ktla(addr) (addr)
7568 +
7569 #ifndef __ASSEMBLY__
7570
7571 struct page;
7572 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7573 index 0032f92..cd151e0 100644
7574 --- a/arch/um/include/asm/pgtable-3level.h
7575 +++ b/arch/um/include/asm/pgtable-3level.h
7576 @@ -58,6 +58,7 @@
7577 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7578 #define pud_populate(mm, pud, pmd) \
7579 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7580 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7581
7582 #ifdef CONFIG_64BIT
7583 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7584 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7585 index 2b73ded..804f540 100644
7586 --- a/arch/um/kernel/process.c
7587 +++ b/arch/um/kernel/process.c
7588 @@ -404,22 +404,6 @@ int singlestepping(void * t)
7589 return 2;
7590 }
7591
7592 -/*
7593 - * Only x86 and x86_64 have an arch_align_stack().
7594 - * All other arches have "#define arch_align_stack(x) (x)"
7595 - * in their asm/system.h
7596 - * As this is included in UML from asm-um/system-generic.h,
7597 - * we can use it to behave as the subarch does.
7598 - */
7599 -#ifndef arch_align_stack
7600 -unsigned long arch_align_stack(unsigned long sp)
7601 -{
7602 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7603 - sp -= get_random_int() % 8192;
7604 - return sp & ~0xf;
7605 -}
7606 -#endif
7607 -
7608 unsigned long get_wchan(struct task_struct *p)
7609 {
7610 unsigned long stack_page, sp, ip;
7611 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7612 index ad8f795..2c7eec6 100644
7613 --- a/arch/unicore32/include/asm/cache.h
7614 +++ b/arch/unicore32/include/asm/cache.h
7615 @@ -12,8 +12,10 @@
7616 #ifndef __UNICORE_CACHE_H__
7617 #define __UNICORE_CACHE_H__
7618
7619 -#define L1_CACHE_SHIFT (5)
7620 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7621 +#include <linux/const.h>
7622 +
7623 +#define L1_CACHE_SHIFT 5
7624 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7625
7626 /*
7627 * Memory returned by kmalloc() may be used for DMA, so we must make
7628 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7629 index c9866b0..fe53aef 100644
7630 --- a/arch/x86/Kconfig
7631 +++ b/arch/x86/Kconfig
7632 @@ -229,7 +229,7 @@ config X86_HT
7633
7634 config X86_32_LAZY_GS
7635 def_bool y
7636 - depends on X86_32 && !CC_STACKPROTECTOR
7637 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7638
7639 config ARCH_HWEIGHT_CFLAGS
7640 string
7641 @@ -1042,7 +1042,7 @@ choice
7642
7643 config NOHIGHMEM
7644 bool "off"
7645 - depends on !X86_NUMAQ
7646 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7647 ---help---
7648 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7649 However, the address space of 32-bit x86 processors is only 4
7650 @@ -1079,7 +1079,7 @@ config NOHIGHMEM
7651
7652 config HIGHMEM4G
7653 bool "4GB"
7654 - depends on !X86_NUMAQ
7655 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7656 ---help---
7657 Select this if you have a 32-bit processor and between 1 and 4
7658 gigabytes of physical RAM.
7659 @@ -1133,7 +1133,7 @@ config PAGE_OFFSET
7660 hex
7661 default 0xB0000000 if VMSPLIT_3G_OPT
7662 default 0x80000000 if VMSPLIT_2G
7663 - default 0x78000000 if VMSPLIT_2G_OPT
7664 + default 0x70000000 if VMSPLIT_2G_OPT
7665 default 0x40000000 if VMSPLIT_1G
7666 default 0xC0000000
7667 depends on X86_32
7668 @@ -1523,6 +1523,7 @@ config SECCOMP
7669
7670 config CC_STACKPROTECTOR
7671 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
7672 + depends on X86_64 || !PAX_MEMORY_UDEREF
7673 ---help---
7674 This option turns on the -fstack-protector GCC feature. This
7675 feature puts, at the beginning of functions, a canary value on
7676 @@ -1580,6 +1581,7 @@ config KEXEC_JUMP
7677 config PHYSICAL_START
7678 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7679 default "0x1000000"
7680 + range 0x400000 0x40000000
7681 ---help---
7682 This gives the physical address where the kernel is loaded.
7683
7684 @@ -1643,6 +1645,7 @@ config X86_NEED_RELOCS
7685 config PHYSICAL_ALIGN
7686 hex "Alignment value to which kernel should be aligned" if X86_32
7687 default "0x1000000"
7688 + range 0x400000 0x1000000 if PAX_KERNEXEC
7689 range 0x2000 0x1000000
7690 ---help---
7691 This value puts the alignment restrictions on physical address
7692 @@ -1674,9 +1677,10 @@ config HOTPLUG_CPU
7693 Say N if you want to disable CPU hotplug.
7694
7695 config COMPAT_VDSO
7696 - def_bool y
7697 + def_bool n
7698 prompt "Compat VDSO support"
7699 depends on X86_32 || IA32_EMULATION
7700 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7701 ---help---
7702 Map the 32-bit VDSO to the predictable old-style address too.
7703
7704 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7705 index 706e12e..62e4feb 100644
7706 --- a/arch/x86/Kconfig.cpu
7707 +++ b/arch/x86/Kconfig.cpu
7708 @@ -334,7 +334,7 @@ config X86_PPRO_FENCE
7709
7710 config X86_F00F_BUG
7711 def_bool y
7712 - depends on M586MMX || M586TSC || M586 || M486 || M386
7713 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7714
7715 config X86_INVD_BUG
7716 def_bool y
7717 @@ -358,7 +358,7 @@ config X86_POPAD_OK
7718
7719 config X86_ALIGNMENT_16
7720 def_bool y
7721 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7722 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7723
7724 config X86_INTEL_USERCOPY
7725 def_bool y
7726 @@ -404,7 +404,7 @@ config X86_CMPXCHG64
7727 # generates cmov.
7728 config X86_CMOV
7729 def_bool y
7730 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7731 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7732
7733 config X86_MINIMUM_CPU_FAMILY
7734 int
7735 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7736 index e46c214..ab62fd1 100644
7737 --- a/arch/x86/Kconfig.debug
7738 +++ b/arch/x86/Kconfig.debug
7739 @@ -84,7 +84,7 @@ config X86_PTDUMP
7740 config DEBUG_RODATA
7741 bool "Write protect kernel read-only data structures"
7742 default y
7743 - depends on DEBUG_KERNEL
7744 + depends on DEBUG_KERNEL && BROKEN
7745 ---help---
7746 Mark the kernel read-only data as write-protected in the pagetables,
7747 in order to catch accidental (and incorrect) writes to such const
7748 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7749
7750 config DEBUG_SET_MODULE_RONX
7751 bool "Set loadable kernel module data as NX and text as RO"
7752 - depends on MODULES
7753 + depends on MODULES && BROKEN
7754 ---help---
7755 This option helps catch unintended modifications to loadable
7756 kernel module's text and read-only data. It also prevents execution
7757 @@ -275,7 +275,7 @@ config OPTIMIZE_INLINING
7758
7759 config DEBUG_STRICT_USER_COPY_CHECKS
7760 bool "Strict copy size checks"
7761 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
7762 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
7763 ---help---
7764 Enabling this option turns a certain set of sanity checks for user
7765 copy operations into compile time failures.
7766 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7767 index b1c611e..2c1a823 100644
7768 --- a/arch/x86/Makefile
7769 +++ b/arch/x86/Makefile
7770 @@ -46,6 +46,7 @@ else
7771 UTS_MACHINE := x86_64
7772 CHECKFLAGS += -D__x86_64__ -m64
7773
7774 + biarch := $(call cc-option,-m64)
7775 KBUILD_AFLAGS += -m64
7776 KBUILD_CFLAGS += -m64
7777
7778 @@ -222,3 +223,12 @@ define archhelp
7779 echo ' FDARGS="..." arguments for the booted kernel'
7780 echo ' FDINITRD=file initrd for the booted kernel'
7781 endef
7782 +
7783 +define OLD_LD
7784 +
7785 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7786 +*** Please upgrade your binutils to 2.18 or newer
7787 +endef
7788 +
7789 +archprepare:
7790 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7791 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7792 index 5a747dd..ff7b12c 100644
7793 --- a/arch/x86/boot/Makefile
7794 +++ b/arch/x86/boot/Makefile
7795 @@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7796 $(call cc-option, -fno-stack-protector) \
7797 $(call cc-option, -mpreferred-stack-boundary=2)
7798 KBUILD_CFLAGS += $(call cc-option, -m32)
7799 +ifdef CONSTIFY_PLUGIN
7800 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7801 +endif
7802 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7803 GCOV_PROFILE := n
7804
7805 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7806 index 878e4b9..20537ab 100644
7807 --- a/arch/x86/boot/bitops.h
7808 +++ b/arch/x86/boot/bitops.h
7809 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7810 u8 v;
7811 const u32 *p = (const u32 *)addr;
7812
7813 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7814 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7815 return v;
7816 }
7817
7818 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7819
7820 static inline void set_bit(int nr, void *addr)
7821 {
7822 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7823 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7824 }
7825
7826 #endif /* BOOT_BITOPS_H */
7827 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7828 index 18997e5..83d9c67 100644
7829 --- a/arch/x86/boot/boot.h
7830 +++ b/arch/x86/boot/boot.h
7831 @@ -85,7 +85,7 @@ static inline void io_delay(void)
7832 static inline u16 ds(void)
7833 {
7834 u16 seg;
7835 - asm("movw %%ds,%0" : "=rm" (seg));
7836 + asm volatile("movw %%ds,%0" : "=rm" (seg));
7837 return seg;
7838 }
7839
7840 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7841 static inline int memcmp(const void *s1, const void *s2, size_t len)
7842 {
7843 u8 diff;
7844 - asm("repe; cmpsb; setnz %0"
7845 + asm volatile("repe; cmpsb; setnz %0"
7846 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7847 return diff;
7848 }
7849 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7850 index e398bb5..3a382ca 100644
7851 --- a/arch/x86/boot/compressed/Makefile
7852 +++ b/arch/x86/boot/compressed/Makefile
7853 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7854 KBUILD_CFLAGS += $(cflags-y)
7855 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7856 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7857 +ifdef CONSTIFY_PLUGIN
7858 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7859 +endif
7860
7861 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7862 GCOV_PROFILE := n
7863 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7864 index 0cdfc0d..6e79437 100644
7865 --- a/arch/x86/boot/compressed/eboot.c
7866 +++ b/arch/x86/boot/compressed/eboot.c
7867 @@ -122,7 +122,6 @@ again:
7868 *addr = max_addr;
7869 }
7870
7871 -free_pool:
7872 efi_call_phys1(sys_table->boottime->free_pool, map);
7873
7874 fail:
7875 @@ -186,7 +185,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7876 if (i == map_size / desc_size)
7877 status = EFI_NOT_FOUND;
7878
7879 -free_pool:
7880 efi_call_phys1(sys_table->boottime->free_pool, map);
7881 fail:
7882 return status;
7883 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7884 index c85e3ac..6f5aa80 100644
7885 --- a/arch/x86/boot/compressed/head_32.S
7886 +++ b/arch/x86/boot/compressed/head_32.S
7887 @@ -106,7 +106,7 @@ preferred_addr:
7888 notl %eax
7889 andl %eax, %ebx
7890 #else
7891 - movl $LOAD_PHYSICAL_ADDR, %ebx
7892 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7893 #endif
7894
7895 /* Target address to relocate to for decompression */
7896 @@ -192,7 +192,7 @@ relocated:
7897 * and where it was actually loaded.
7898 */
7899 movl %ebp, %ebx
7900 - subl $LOAD_PHYSICAL_ADDR, %ebx
7901 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7902 jz 2f /* Nothing to be done if loaded at compiled addr. */
7903 /*
7904 * Process relocations.
7905 @@ -200,8 +200,7 @@ relocated:
7906
7907 1: subl $4, %edi
7908 movl (%edi), %ecx
7909 - testl %ecx, %ecx
7910 - jz 2f
7911 + jecxz 2f
7912 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7913 jmp 1b
7914 2:
7915 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7916 index 87e03a1..0d94c76 100644
7917 --- a/arch/x86/boot/compressed/head_64.S
7918 +++ b/arch/x86/boot/compressed/head_64.S
7919 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7920 notl %eax
7921 andl %eax, %ebx
7922 #else
7923 - movl $LOAD_PHYSICAL_ADDR, %ebx
7924 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7925 #endif
7926
7927 /* Target address to relocate to for decompression */
7928 @@ -263,7 +263,7 @@ preferred_addr:
7929 notq %rax
7930 andq %rax, %rbp
7931 #else
7932 - movq $LOAD_PHYSICAL_ADDR, %rbp
7933 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7934 #endif
7935
7936 /* Target address to relocate to for decompression */
7937 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7938 index 7116dcb..d9ae1d7 100644
7939 --- a/arch/x86/boot/compressed/misc.c
7940 +++ b/arch/x86/boot/compressed/misc.c
7941 @@ -310,7 +310,7 @@ static void parse_elf(void *output)
7942 case PT_LOAD:
7943 #ifdef CONFIG_RELOCATABLE
7944 dest = output;
7945 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7946 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7947 #else
7948 dest = (void *)(phdr->p_paddr);
7949 #endif
7950 @@ -365,7 +365,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7951 error("Destination address too large");
7952 #endif
7953 #ifndef CONFIG_RELOCATABLE
7954 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7955 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7956 error("Wrong destination address");
7957 #endif
7958
7959 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7960 index 4d3ff03..e4972ff 100644
7961 --- a/arch/x86/boot/cpucheck.c
7962 +++ b/arch/x86/boot/cpucheck.c
7963 @@ -74,7 +74,7 @@ static int has_fpu(void)
7964 u16 fcw = -1, fsw = -1;
7965 u32 cr0;
7966
7967 - asm("movl %%cr0,%0" : "=r" (cr0));
7968 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7969 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7970 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7971 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7972 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7973 {
7974 u32 f0, f1;
7975
7976 - asm("pushfl ; "
7977 + asm volatile("pushfl ; "
7978 "pushfl ; "
7979 "popl %0 ; "
7980 "movl %0,%1 ; "
7981 @@ -115,7 +115,7 @@ static void get_flags(void)
7982 set_bit(X86_FEATURE_FPU, cpu.flags);
7983
7984 if (has_eflag(X86_EFLAGS_ID)) {
7985 - asm("cpuid"
7986 + asm volatile("cpuid"
7987 : "=a" (max_intel_level),
7988 "=b" (cpu_vendor[0]),
7989 "=d" (cpu_vendor[1]),
7990 @@ -124,7 +124,7 @@ static void get_flags(void)
7991
7992 if (max_intel_level >= 0x00000001 &&
7993 max_intel_level <= 0x0000ffff) {
7994 - asm("cpuid"
7995 + asm volatile("cpuid"
7996 : "=a" (tfms),
7997 "=c" (cpu.flags[4]),
7998 "=d" (cpu.flags[0])
7999 @@ -136,7 +136,7 @@ static void get_flags(void)
8000 cpu.model += ((tfms >> 16) & 0xf) << 4;
8001 }
8002
8003 - asm("cpuid"
8004 + asm volatile("cpuid"
8005 : "=a" (max_amd_level)
8006 : "a" (0x80000000)
8007 : "ebx", "ecx", "edx");
8008 @@ -144,7 +144,7 @@ static void get_flags(void)
8009 if (max_amd_level >= 0x80000001 &&
8010 max_amd_level <= 0x8000ffff) {
8011 u32 eax = 0x80000001;
8012 - asm("cpuid"
8013 + asm volatile("cpuid"
8014 : "+a" (eax),
8015 "=c" (cpu.flags[6]),
8016 "=d" (cpu.flags[1])
8017 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8018 u32 ecx = MSR_K7_HWCR;
8019 u32 eax, edx;
8020
8021 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8022 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8023 eax &= ~(1 << 15);
8024 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8025 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8026
8027 get_flags(); /* Make sure it really did something */
8028 err = check_flags();
8029 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8030 u32 ecx = MSR_VIA_FCR;
8031 u32 eax, edx;
8032
8033 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8034 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8035 eax |= (1<<1)|(1<<7);
8036 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8037 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8038
8039 set_bit(X86_FEATURE_CX8, cpu.flags);
8040 err = check_flags();
8041 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8042 u32 eax, edx;
8043 u32 level = 1;
8044
8045 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8046 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8047 - asm("cpuid"
8048 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8049 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8050 + asm volatile("cpuid"
8051 : "+a" (level), "=d" (cpu.flags[0])
8052 : : "ecx", "ebx");
8053 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8054 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8055
8056 err = check_flags();
8057 }
8058 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
8059 index f1bbeeb..aff09cb 100644
8060 --- a/arch/x86/boot/header.S
8061 +++ b/arch/x86/boot/header.S
8062 @@ -372,7 +372,7 @@ setup_data: .quad 0 # 64-bit physical pointer to
8063 # single linked list of
8064 # struct setup_data
8065
8066 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
8067 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
8068
8069 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
8070 #define VO_INIT_SIZE (VO__end - VO__text)
8071 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
8072 index db75d07..8e6d0af 100644
8073 --- a/arch/x86/boot/memory.c
8074 +++ b/arch/x86/boot/memory.c
8075 @@ -19,7 +19,7 @@
8076
8077 static int detect_memory_e820(void)
8078 {
8079 - int count = 0;
8080 + unsigned int count = 0;
8081 struct biosregs ireg, oreg;
8082 struct e820entry *desc = boot_params.e820_map;
8083 static struct e820entry buf; /* static so it is zeroed */
8084 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
8085 index 11e8c6e..fdbb1ed 100644
8086 --- a/arch/x86/boot/video-vesa.c
8087 +++ b/arch/x86/boot/video-vesa.c
8088 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
8089
8090 boot_params.screen_info.vesapm_seg = oreg.es;
8091 boot_params.screen_info.vesapm_off = oreg.di;
8092 + boot_params.screen_info.vesapm_size = oreg.cx;
8093 }
8094
8095 /*
8096 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8097 index 43eda28..5ab5fdb 100644
8098 --- a/arch/x86/boot/video.c
8099 +++ b/arch/x86/boot/video.c
8100 @@ -96,7 +96,7 @@ static void store_mode_params(void)
8101 static unsigned int get_entry(void)
8102 {
8103 char entry_buf[4];
8104 - int i, len = 0;
8105 + unsigned int i, len = 0;
8106 int key;
8107 unsigned int v;
8108
8109 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8110 index 5b577d5..3c1fed4 100644
8111 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
8112 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8113 @@ -8,6 +8,8 @@
8114 * including this sentence is retained in full.
8115 */
8116
8117 +#include <asm/alternative-asm.h>
8118 +
8119 .extern crypto_ft_tab
8120 .extern crypto_it_tab
8121 .extern crypto_fl_tab
8122 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8123 je B192; \
8124 leaq 32(r9),r9;
8125
8126 +#define ret pax_force_retaddr 0, 1; ret
8127 +
8128 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8129 movq r1,r2; \
8130 movq r3,r4; \
8131 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8132 index 3470624..201259d 100644
8133 --- a/arch/x86/crypto/aesni-intel_asm.S
8134 +++ b/arch/x86/crypto/aesni-intel_asm.S
8135 @@ -31,6 +31,7 @@
8136
8137 #include <linux/linkage.h>
8138 #include <asm/inst.h>
8139 +#include <asm/alternative-asm.h>
8140
8141 #ifdef __x86_64__
8142 .data
8143 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8144 pop %r14
8145 pop %r13
8146 pop %r12
8147 + pax_force_retaddr 0, 1
8148 ret
8149 +ENDPROC(aesni_gcm_dec)
8150
8151
8152 /*****************************************************************************
8153 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8154 pop %r14
8155 pop %r13
8156 pop %r12
8157 + pax_force_retaddr 0, 1
8158 ret
8159 +ENDPROC(aesni_gcm_enc)
8160
8161 #endif
8162
8163 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
8164 pxor %xmm1, %xmm0
8165 movaps %xmm0, (TKEYP)
8166 add $0x10, TKEYP
8167 + pax_force_retaddr_bts
8168 ret
8169
8170 .align 4
8171 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
8172 shufps $0b01001110, %xmm2, %xmm1
8173 movaps %xmm1, 0x10(TKEYP)
8174 add $0x20, TKEYP
8175 + pax_force_retaddr_bts
8176 ret
8177
8178 .align 4
8179 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
8180
8181 movaps %xmm0, (TKEYP)
8182 add $0x10, TKEYP
8183 + pax_force_retaddr_bts
8184 ret
8185
8186 .align 4
8187 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
8188 pxor %xmm1, %xmm2
8189 movaps %xmm2, (TKEYP)
8190 add $0x10, TKEYP
8191 + pax_force_retaddr_bts
8192 ret
8193
8194 /*
8195 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8196 #ifndef __x86_64__
8197 popl KEYP
8198 #endif
8199 + pax_force_retaddr 0, 1
8200 ret
8201 +ENDPROC(aesni_set_key)
8202
8203 /*
8204 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8205 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8206 popl KLEN
8207 popl KEYP
8208 #endif
8209 + pax_force_retaddr 0, 1
8210 ret
8211 +ENDPROC(aesni_enc)
8212
8213 /*
8214 * _aesni_enc1: internal ABI
8215 @@ -1959,6 +1972,7 @@ _aesni_enc1:
8216 AESENC KEY STATE
8217 movaps 0x70(TKEYP), KEY
8218 AESENCLAST KEY STATE
8219 + pax_force_retaddr_bts
8220 ret
8221
8222 /*
8223 @@ -2067,6 +2081,7 @@ _aesni_enc4:
8224 AESENCLAST KEY STATE2
8225 AESENCLAST KEY STATE3
8226 AESENCLAST KEY STATE4
8227 + pax_force_retaddr_bts
8228 ret
8229
8230 /*
8231 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8232 popl KLEN
8233 popl KEYP
8234 #endif
8235 + pax_force_retaddr 0, 1
8236 ret
8237 +ENDPROC(aesni_dec)
8238
8239 /*
8240 * _aesni_dec1: internal ABI
8241 @@ -2146,6 +2163,7 @@ _aesni_dec1:
8242 AESDEC KEY STATE
8243 movaps 0x70(TKEYP), KEY
8244 AESDECLAST KEY STATE
8245 + pax_force_retaddr_bts
8246 ret
8247
8248 /*
8249 @@ -2254,6 +2272,7 @@ _aesni_dec4:
8250 AESDECLAST KEY STATE2
8251 AESDECLAST KEY STATE3
8252 AESDECLAST KEY STATE4
8253 + pax_force_retaddr_bts
8254 ret
8255
8256 /*
8257 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8258 popl KEYP
8259 popl LEN
8260 #endif
8261 + pax_force_retaddr 0, 1
8262 ret
8263 +ENDPROC(aesni_ecb_enc)
8264
8265 /*
8266 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8267 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8268 popl KEYP
8269 popl LEN
8270 #endif
8271 + pax_force_retaddr 0, 1
8272 ret
8273 +ENDPROC(aesni_ecb_dec)
8274
8275 /*
8276 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8277 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8278 popl LEN
8279 popl IVP
8280 #endif
8281 + pax_force_retaddr 0, 1
8282 ret
8283 +ENDPROC(aesni_cbc_enc)
8284
8285 /*
8286 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8287 @@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
8288 popl LEN
8289 popl IVP
8290 #endif
8291 + pax_force_retaddr 0, 1
8292 ret
8293 +ENDPROC(aesni_cbc_dec)
8294
8295 #ifdef __x86_64__
8296 .align 16
8297 @@ -2526,6 +2553,7 @@ _aesni_inc_init:
8298 mov $1, TCTR_LOW
8299 MOVQ_R64_XMM TCTR_LOW INC
8300 MOVQ_R64_XMM CTR TCTR_LOW
8301 + pax_force_retaddr_bts
8302 ret
8303
8304 /*
8305 @@ -2554,6 +2582,7 @@ _aesni_inc:
8306 .Linc_low:
8307 movaps CTR, IV
8308 PSHUFB_XMM BSWAP_MASK IV
8309 + pax_force_retaddr_bts
8310 ret
8311
8312 /*
8313 @@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
8314 .Lctr_enc_ret:
8315 movups IV, (IVP)
8316 .Lctr_enc_just_ret:
8317 + pax_force_retaddr 0, 1
8318 ret
8319 +ENDPROC(aesni_ctr_enc)
8320 #endif
8321 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8322 index 391d245..67f35c2 100644
8323 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8324 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8325 @@ -20,6 +20,8 @@
8326 *
8327 */
8328
8329 +#include <asm/alternative-asm.h>
8330 +
8331 .file "blowfish-x86_64-asm.S"
8332 .text
8333
8334 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
8335 jnz __enc_xor;
8336
8337 write_block();
8338 + pax_force_retaddr 0, 1
8339 ret;
8340 __enc_xor:
8341 xor_block();
8342 + pax_force_retaddr 0, 1
8343 ret;
8344
8345 .align 8
8346 @@ -188,6 +192,7 @@ blowfish_dec_blk:
8347
8348 movq %r11, %rbp;
8349
8350 + pax_force_retaddr 0, 1
8351 ret;
8352
8353 /**********************************************************************
8354 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8355
8356 popq %rbx;
8357 popq %rbp;
8358 + pax_force_retaddr 0, 1
8359 ret;
8360
8361 __enc_xor4:
8362 @@ -349,6 +355,7 @@ __enc_xor4:
8363
8364 popq %rbx;
8365 popq %rbp;
8366 + pax_force_retaddr 0, 1
8367 ret;
8368
8369 .align 8
8370 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8371 popq %rbx;
8372 popq %rbp;
8373
8374 + pax_force_retaddr 0, 1
8375 ret;
8376
8377 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
8378 index 0b33743..7a56206 100644
8379 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
8380 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
8381 @@ -20,6 +20,8 @@
8382 *
8383 */
8384
8385 +#include <asm/alternative-asm.h>
8386 +
8387 .file "camellia-x86_64-asm_64.S"
8388 .text
8389
8390 @@ -229,12 +231,14 @@ __enc_done:
8391 enc_outunpack(mov, RT1);
8392
8393 movq RRBP, %rbp;
8394 + pax_force_retaddr 0, 1
8395 ret;
8396
8397 __enc_xor:
8398 enc_outunpack(xor, RT1);
8399
8400 movq RRBP, %rbp;
8401 + pax_force_retaddr 0, 1
8402 ret;
8403
8404 .global camellia_dec_blk;
8405 @@ -275,6 +279,7 @@ __dec_rounds16:
8406 dec_outunpack();
8407
8408 movq RRBP, %rbp;
8409 + pax_force_retaddr 0, 1
8410 ret;
8411
8412 /**********************************************************************
8413 @@ -468,6 +473,7 @@ __enc2_done:
8414
8415 movq RRBP, %rbp;
8416 popq %rbx;
8417 + pax_force_retaddr 0, 1
8418 ret;
8419
8420 __enc2_xor:
8421 @@ -475,6 +481,7 @@ __enc2_xor:
8422
8423 movq RRBP, %rbp;
8424 popq %rbx;
8425 + pax_force_retaddr 0, 1
8426 ret;
8427
8428 .global camellia_dec_blk_2way;
8429 @@ -517,4 +524,5 @@ __dec2_rounds16:
8430
8431 movq RRBP, %rbp;
8432 movq RXOR, %rbx;
8433 + pax_force_retaddr 0, 1
8434 ret;
8435 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8436 index 6214a9b..1f4fc9a 100644
8437 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8438 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8439 @@ -1,3 +1,5 @@
8440 +#include <asm/alternative-asm.h>
8441 +
8442 # enter ECRYPT_encrypt_bytes
8443 .text
8444 .p2align 5
8445 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8446 add %r11,%rsp
8447 mov %rdi,%rax
8448 mov %rsi,%rdx
8449 + pax_force_retaddr 0, 1
8450 ret
8451 # bytesatleast65:
8452 ._bytesatleast65:
8453 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
8454 add %r11,%rsp
8455 mov %rdi,%rax
8456 mov %rsi,%rdx
8457 + pax_force_retaddr
8458 ret
8459 # enter ECRYPT_ivsetup
8460 .text
8461 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8462 add %r11,%rsp
8463 mov %rdi,%rax
8464 mov %rsi,%rdx
8465 + pax_force_retaddr
8466 ret
8467 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8468 index 3ee1ff0..cbc568b 100644
8469 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8470 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8471 @@ -24,6 +24,8 @@
8472 *
8473 */
8474
8475 +#include <asm/alternative-asm.h>
8476 +
8477 .file "serpent-sse2-x86_64-asm_64.S"
8478 .text
8479
8480 @@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
8481 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8482 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8483
8484 + pax_force_retaddr
8485 ret;
8486
8487 __enc_xor8:
8488 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8489 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8490
8491 + pax_force_retaddr
8492 ret;
8493
8494 .align 8
8495 @@ -755,4 +759,5 @@ serpent_dec_blk_8way:
8496 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8497 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8498
8499 + pax_force_retaddr
8500 ret;
8501 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8502 index b2c2f57..8470cab 100644
8503 --- a/arch/x86/crypto/sha1_ssse3_asm.S
8504 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
8505 @@ -28,6 +28,8 @@
8506 * (at your option) any later version.
8507 */
8508
8509 +#include <asm/alternative-asm.h>
8510 +
8511 #define CTX %rdi // arg1
8512 #define BUF %rsi // arg2
8513 #define CNT %rdx // arg3
8514 @@ -104,6 +106,7 @@
8515 pop %r12
8516 pop %rbp
8517 pop %rbx
8518 + pax_force_retaddr 0, 1
8519 ret
8520
8521 .size \name, .-\name
8522 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8523 index 5b012a2..36d5364 100644
8524 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8525 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8526 @@ -20,6 +20,8 @@
8527 *
8528 */
8529
8530 +#include <asm/alternative-asm.h>
8531 +
8532 .file "twofish-x86_64-asm-3way.S"
8533 .text
8534
8535 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8536 popq %r13;
8537 popq %r14;
8538 popq %r15;
8539 + pax_force_retaddr 0, 1
8540 ret;
8541
8542 __enc_xor3:
8543 @@ -271,6 +274,7 @@ __enc_xor3:
8544 popq %r13;
8545 popq %r14;
8546 popq %r15;
8547 + pax_force_retaddr 0, 1
8548 ret;
8549
8550 .global twofish_dec_blk_3way
8551 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8552 popq %r13;
8553 popq %r14;
8554 popq %r15;
8555 + pax_force_retaddr 0, 1
8556 ret;
8557
8558 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8559 index 7bcf3fc..f53832f 100644
8560 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8561 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8562 @@ -21,6 +21,7 @@
8563 .text
8564
8565 #include <asm/asm-offsets.h>
8566 +#include <asm/alternative-asm.h>
8567
8568 #define a_offset 0
8569 #define b_offset 4
8570 @@ -268,6 +269,7 @@ twofish_enc_blk:
8571
8572 popq R1
8573 movq $1,%rax
8574 + pax_force_retaddr 0, 1
8575 ret
8576
8577 twofish_dec_blk:
8578 @@ -319,4 +321,5 @@ twofish_dec_blk:
8579
8580 popq R1
8581 movq $1,%rax
8582 + pax_force_retaddr 0, 1
8583 ret
8584 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8585 index 07b3a68..bd2a388 100644
8586 --- a/arch/x86/ia32/ia32_aout.c
8587 +++ b/arch/x86/ia32/ia32_aout.c
8588 @@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8589 unsigned long dump_start, dump_size;
8590 struct user32 dump;
8591
8592 + memset(&dump, 0, sizeof(dump));
8593 +
8594 fs = get_fs();
8595 set_fs(KERNEL_DS);
8596 has_dumped = 1;
8597 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8598 index 4f5bfac..e1ef0d3 100644
8599 --- a/arch/x86/ia32/ia32_signal.c
8600 +++ b/arch/x86/ia32/ia32_signal.c
8601 @@ -168,7 +168,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8602 }
8603 seg = get_fs();
8604 set_fs(KERNEL_DS);
8605 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8606 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8607 set_fs(seg);
8608 if (ret >= 0 && uoss_ptr) {
8609 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8610 @@ -369,7 +369,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8611 */
8612 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8613 size_t frame_size,
8614 - void **fpstate)
8615 + void __user **fpstate)
8616 {
8617 unsigned long sp;
8618
8619 @@ -390,7 +390,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8620
8621 if (used_math()) {
8622 sp = sp - sig_xstate_ia32_size;
8623 - *fpstate = (struct _fpstate_ia32 *) sp;
8624 + *fpstate = (struct _fpstate_ia32 __user *) sp;
8625 if (save_i387_xstate_ia32(*fpstate) < 0)
8626 return (void __user *) -1L;
8627 }
8628 @@ -398,7 +398,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8629 sp -= frame_size;
8630 /* Align the stack pointer according to the i386 ABI,
8631 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8632 - sp = ((sp + 4) & -16ul) - 4;
8633 + sp = ((sp - 12) & -16ul) - 4;
8634 return (void __user *) sp;
8635 }
8636
8637 @@ -456,7 +456,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8638 * These are actually not used anymore, but left because some
8639 * gdb versions depend on them as a marker.
8640 */
8641 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8642 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8643 } put_user_catch(err);
8644
8645 if (err)
8646 @@ -498,7 +498,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8647 0xb8,
8648 __NR_ia32_rt_sigreturn,
8649 0x80cd,
8650 - 0,
8651 + 0
8652 };
8653
8654 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8655 @@ -528,16 +528,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8656
8657 if (ka->sa.sa_flags & SA_RESTORER)
8658 restorer = ka->sa.sa_restorer;
8659 + else if (current->mm->context.vdso)
8660 + /* Return stub is in 32bit vsyscall page */
8661 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8662 else
8663 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8664 - rt_sigreturn);
8665 + restorer = &frame->retcode;
8666 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8667
8668 /*
8669 * Not actually used anymore, but left because some gdb
8670 * versions need it.
8671 */
8672 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8673 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8674 } put_user_catch(err);
8675
8676 if (err)
8677 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8678 index e3e7340..05ed805 100644
8679 --- a/arch/x86/ia32/ia32entry.S
8680 +++ b/arch/x86/ia32/ia32entry.S
8681 @@ -13,8 +13,10 @@
8682 #include <asm/thread_info.h>
8683 #include <asm/segment.h>
8684 #include <asm/irqflags.h>
8685 +#include <asm/pgtable.h>
8686 #include <linux/linkage.h>
8687 #include <linux/err.h>
8688 +#include <asm/alternative-asm.h>
8689
8690 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8691 #include <linux/elf-em.h>
8692 @@ -94,6 +96,32 @@ ENTRY(native_irq_enable_sysexit)
8693 ENDPROC(native_irq_enable_sysexit)
8694 #endif
8695
8696 + .macro pax_enter_kernel_user
8697 + pax_set_fptr_mask
8698 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8699 + call pax_enter_kernel_user
8700 +#endif
8701 + .endm
8702 +
8703 + .macro pax_exit_kernel_user
8704 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8705 + call pax_exit_kernel_user
8706 +#endif
8707 +#ifdef CONFIG_PAX_RANDKSTACK
8708 + pushq %rax
8709 + pushq %r11
8710 + call pax_randomize_kstack
8711 + popq %r11
8712 + popq %rax
8713 +#endif
8714 + .endm
8715 +
8716 +.macro pax_erase_kstack
8717 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8718 + call pax_erase_kstack
8719 +#endif
8720 +.endm
8721 +
8722 /*
8723 * 32bit SYSENTER instruction entry.
8724 *
8725 @@ -120,12 +148,6 @@ ENTRY(ia32_sysenter_target)
8726 CFI_REGISTER rsp,rbp
8727 SWAPGS_UNSAFE_STACK
8728 movq PER_CPU_VAR(kernel_stack), %rsp
8729 - addq $(KERNEL_STACK_OFFSET),%rsp
8730 - /*
8731 - * No need to follow this irqs on/off section: the syscall
8732 - * disabled irqs, here we enable it straight after entry:
8733 - */
8734 - ENABLE_INTERRUPTS(CLBR_NONE)
8735 movl %ebp,%ebp /* zero extension */
8736 pushq_cfi $__USER32_DS
8737 /*CFI_REL_OFFSET ss,0*/
8738 @@ -133,24 +155,39 @@ ENTRY(ia32_sysenter_target)
8739 CFI_REL_OFFSET rsp,0
8740 pushfq_cfi
8741 /*CFI_REL_OFFSET rflags,0*/
8742 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8743 - CFI_REGISTER rip,r10
8744 + orl $X86_EFLAGS_IF,(%rsp)
8745 + GET_THREAD_INFO(%r11)
8746 + movl TI_sysenter_return(%r11), %r11d
8747 + CFI_REGISTER rip,r11
8748 pushq_cfi $__USER32_CS
8749 /*CFI_REL_OFFSET cs,0*/
8750 movl %eax, %eax
8751 - pushq_cfi %r10
8752 + pushq_cfi %r11
8753 CFI_REL_OFFSET rip,0
8754 pushq_cfi %rax
8755 cld
8756 SAVE_ARGS 0,1,0
8757 + pax_enter_kernel_user
8758 + /*
8759 + * No need to follow this irqs on/off section: the syscall
8760 + * disabled irqs, here we enable it straight after entry:
8761 + */
8762 + ENABLE_INTERRUPTS(CLBR_NONE)
8763 /* no need to do an access_ok check here because rbp has been
8764 32bit zero extended */
8765 +
8766 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8767 + mov $PAX_USER_SHADOW_BASE,%r11
8768 + add %r11,%rbp
8769 +#endif
8770 +
8771 1: movl (%rbp),%ebp
8772 .section __ex_table,"a"
8773 .quad 1b,ia32_badarg
8774 .previous
8775 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8776 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8777 + GET_THREAD_INFO(%r11)
8778 + orl $TS_COMPAT,TI_status(%r11)
8779 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8780 CFI_REMEMBER_STATE
8781 jnz sysenter_tracesys
8782 cmpq $(IA32_NR_syscalls-1),%rax
8783 @@ -160,12 +197,15 @@ sysenter_do_call:
8784 sysenter_dispatch:
8785 call *ia32_sys_call_table(,%rax,8)
8786 movq %rax,RAX-ARGOFFSET(%rsp)
8787 + GET_THREAD_INFO(%r11)
8788 DISABLE_INTERRUPTS(CLBR_NONE)
8789 TRACE_IRQS_OFF
8790 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8791 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8792 jnz sysexit_audit
8793 sysexit_from_sys_call:
8794 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8795 + pax_exit_kernel_user
8796 + pax_erase_kstack
8797 + andl $~TS_COMPAT,TI_status(%r11)
8798 /* clear IF, that popfq doesn't enable interrupts early */
8799 andl $~0x200,EFLAGS-R11(%rsp)
8800 movl RIP-R11(%rsp),%edx /* User %eip */
8801 @@ -191,6 +231,9 @@ sysexit_from_sys_call:
8802 movl %eax,%esi /* 2nd arg: syscall number */
8803 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8804 call __audit_syscall_entry
8805 +
8806 + pax_erase_kstack
8807 +
8808 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8809 cmpq $(IA32_NR_syscalls-1),%rax
8810 ja ia32_badsys
8811 @@ -202,7 +245,7 @@ sysexit_from_sys_call:
8812 .endm
8813
8814 .macro auditsys_exit exit
8815 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8816 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8817 jnz ia32_ret_from_sys_call
8818 TRACE_IRQS_ON
8819 sti
8820 @@ -213,11 +256,12 @@ sysexit_from_sys_call:
8821 1: setbe %al /* 1 if error, 0 if not */
8822 movzbl %al,%edi /* zero-extend that into %edi */
8823 call __audit_syscall_exit
8824 + GET_THREAD_INFO(%r11)
8825 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8826 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8827 cli
8828 TRACE_IRQS_OFF
8829 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8830 + testl %edi,TI_flags(%r11)
8831 jz \exit
8832 CLEAR_RREGS -ARGOFFSET
8833 jmp int_with_check
8834 @@ -235,7 +279,7 @@ sysexit_audit:
8835
8836 sysenter_tracesys:
8837 #ifdef CONFIG_AUDITSYSCALL
8838 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8839 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8840 jz sysenter_auditsys
8841 #endif
8842 SAVE_REST
8843 @@ -243,6 +287,9 @@ sysenter_tracesys:
8844 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
8845 movq %rsp,%rdi /* &pt_regs -> arg1 */
8846 call syscall_trace_enter
8847 +
8848 + pax_erase_kstack
8849 +
8850 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8851 RESTORE_REST
8852 cmpq $(IA32_NR_syscalls-1),%rax
8853 @@ -274,19 +321,20 @@ ENDPROC(ia32_sysenter_target)
8854 ENTRY(ia32_cstar_target)
8855 CFI_STARTPROC32 simple
8856 CFI_SIGNAL_FRAME
8857 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8858 + CFI_DEF_CFA rsp,0
8859 CFI_REGISTER rip,rcx
8860 /*CFI_REGISTER rflags,r11*/
8861 SWAPGS_UNSAFE_STACK
8862 movl %esp,%r8d
8863 CFI_REGISTER rsp,r8
8864 movq PER_CPU_VAR(kernel_stack),%rsp
8865 + SAVE_ARGS 8*6,0,0
8866 + pax_enter_kernel_user
8867 /*
8868 * No need to follow this irqs on/off section: the syscall
8869 * disabled irqs and here we enable it straight after entry:
8870 */
8871 ENABLE_INTERRUPTS(CLBR_NONE)
8872 - SAVE_ARGS 8,0,0
8873 movl %eax,%eax /* zero extension */
8874 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8875 movq %rcx,RIP-ARGOFFSET(%rsp)
8876 @@ -302,12 +350,19 @@ ENTRY(ia32_cstar_target)
8877 /* no need to do an access_ok check here because r8 has been
8878 32bit zero extended */
8879 /* hardware stack frame is complete now */
8880 +
8881 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8882 + mov $PAX_USER_SHADOW_BASE,%r11
8883 + add %r11,%r8
8884 +#endif
8885 +
8886 1: movl (%r8),%r9d
8887 .section __ex_table,"a"
8888 .quad 1b,ia32_badarg
8889 .previous
8890 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8891 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8892 + GET_THREAD_INFO(%r11)
8893 + orl $TS_COMPAT,TI_status(%r11)
8894 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8895 CFI_REMEMBER_STATE
8896 jnz cstar_tracesys
8897 cmpq $IA32_NR_syscalls-1,%rax
8898 @@ -317,12 +372,15 @@ cstar_do_call:
8899 cstar_dispatch:
8900 call *ia32_sys_call_table(,%rax,8)
8901 movq %rax,RAX-ARGOFFSET(%rsp)
8902 + GET_THREAD_INFO(%r11)
8903 DISABLE_INTERRUPTS(CLBR_NONE)
8904 TRACE_IRQS_OFF
8905 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8906 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8907 jnz sysretl_audit
8908 sysretl_from_sys_call:
8909 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8910 + pax_exit_kernel_user
8911 + pax_erase_kstack
8912 + andl $~TS_COMPAT,TI_status(%r11)
8913 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8914 movl RIP-ARGOFFSET(%rsp),%ecx
8915 CFI_REGISTER rip,rcx
8916 @@ -350,7 +408,7 @@ sysretl_audit:
8917
8918 cstar_tracesys:
8919 #ifdef CONFIG_AUDITSYSCALL
8920 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8921 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8922 jz cstar_auditsys
8923 #endif
8924 xchgl %r9d,%ebp
8925 @@ -359,6 +417,9 @@ cstar_tracesys:
8926 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8927 movq %rsp,%rdi /* &pt_regs -> arg1 */
8928 call syscall_trace_enter
8929 +
8930 + pax_erase_kstack
8931 +
8932 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
8933 RESTORE_REST
8934 xchgl %ebp,%r9d
8935 @@ -404,19 +465,21 @@ ENTRY(ia32_syscall)
8936 CFI_REL_OFFSET rip,RIP-RIP
8937 PARAVIRT_ADJUST_EXCEPTION_FRAME
8938 SWAPGS
8939 - /*
8940 - * No need to follow this irqs on/off section: the syscall
8941 - * disabled irqs and here we enable it straight after entry:
8942 - */
8943 - ENABLE_INTERRUPTS(CLBR_NONE)
8944 movl %eax,%eax
8945 pushq_cfi %rax
8946 cld
8947 /* note the registers are not zero extended to the sf.
8948 this could be a problem. */
8949 SAVE_ARGS 0,1,0
8950 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8951 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8952 + pax_enter_kernel_user
8953 + /*
8954 + * No need to follow this irqs on/off section: the syscall
8955 + * disabled irqs and here we enable it straight after entry:
8956 + */
8957 + ENABLE_INTERRUPTS(CLBR_NONE)
8958 + GET_THREAD_INFO(%r11)
8959 + orl $TS_COMPAT,TI_status(%r11)
8960 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8961 jnz ia32_tracesys
8962 cmpq $(IA32_NR_syscalls-1),%rax
8963 ja ia32_badsys
8964 @@ -435,6 +498,9 @@ ia32_tracesys:
8965 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8966 movq %rsp,%rdi /* &pt_regs -> arg1 */
8967 call syscall_trace_enter
8968 +
8969 + pax_erase_kstack
8970 +
8971 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8972 RESTORE_REST
8973 cmpq $(IA32_NR_syscalls-1),%rax
8974 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8975 index aec2202..f76174e 100644
8976 --- a/arch/x86/ia32/sys_ia32.c
8977 +++ b/arch/x86/ia32/sys_ia32.c
8978 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8979 */
8980 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8981 {
8982 - typeof(ubuf->st_uid) uid = 0;
8983 - typeof(ubuf->st_gid) gid = 0;
8984 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
8985 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
8986 SET_UID(uid, stat->uid);
8987 SET_GID(gid, stat->gid);
8988 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8989 @@ -292,7 +292,7 @@ asmlinkage long sys32_alarm(unsigned int seconds)
8990 return alarm_setitimer(seconds);
8991 }
8992
8993 -asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
8994 +asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
8995 int options)
8996 {
8997 return compat_sys_wait4(pid, stat_addr, options, NULL);
8998 @@ -313,7 +313,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8999 mm_segment_t old_fs = get_fs();
9000
9001 set_fs(KERNEL_DS);
9002 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
9003 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
9004 set_fs(old_fs);
9005 if (put_compat_timespec(&t, interval))
9006 return -EFAULT;
9007 @@ -329,7 +329,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
9008 mm_segment_t old_fs = get_fs();
9009
9010 set_fs(KERNEL_DS);
9011 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
9012 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
9013 set_fs(old_fs);
9014 if (!ret) {
9015 switch (_NSIG_WORDS) {
9016 @@ -354,7 +354,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
9017 if (copy_siginfo_from_user32(&info, uinfo))
9018 return -EFAULT;
9019 set_fs(KERNEL_DS);
9020 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
9021 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
9022 set_fs(old_fs);
9023 return ret;
9024 }
9025 @@ -399,7 +399,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
9026 return -EFAULT;
9027
9028 set_fs(KERNEL_DS);
9029 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
9030 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
9031 count);
9032 set_fs(old_fs);
9033
9034 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
9035 index 952bd01..7692c6f 100644
9036 --- a/arch/x86/include/asm/alternative-asm.h
9037 +++ b/arch/x86/include/asm/alternative-asm.h
9038 @@ -15,6 +15,45 @@
9039 .endm
9040 #endif
9041
9042 +#ifdef KERNEXEC_PLUGIN
9043 + .macro pax_force_retaddr_bts rip=0
9044 + btsq $63,\rip(%rsp)
9045 + .endm
9046 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9047 + .macro pax_force_retaddr rip=0, reload=0
9048 + btsq $63,\rip(%rsp)
9049 + .endm
9050 + .macro pax_force_fptr ptr
9051 + btsq $63,\ptr
9052 + .endm
9053 + .macro pax_set_fptr_mask
9054 + .endm
9055 +#endif
9056 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
9057 + .macro pax_force_retaddr rip=0, reload=0
9058 + .if \reload
9059 + pax_set_fptr_mask
9060 + .endif
9061 + orq %r10,\rip(%rsp)
9062 + .endm
9063 + .macro pax_force_fptr ptr
9064 + orq %r10,\ptr
9065 + .endm
9066 + .macro pax_set_fptr_mask
9067 + movabs $0x8000000000000000,%r10
9068 + .endm
9069 +#endif
9070 +#else
9071 + .macro pax_force_retaddr rip=0, reload=0
9072 + .endm
9073 + .macro pax_force_fptr ptr
9074 + .endm
9075 + .macro pax_force_retaddr_bts rip=0
9076 + .endm
9077 + .macro pax_set_fptr_mask
9078 + .endm
9079 +#endif
9080 +
9081 .macro altinstruction_entry orig alt feature orig_len alt_len
9082 .long \orig - .
9083 .long \alt - .
9084 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9085 index 49331be..9706065 100644
9086 --- a/arch/x86/include/asm/alternative.h
9087 +++ b/arch/x86/include/asm/alternative.h
9088 @@ -89,7 +89,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9089 ".section .discard,\"aw\",@progbits\n" \
9090 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
9091 ".previous\n" \
9092 - ".section .altinstr_replacement, \"ax\"\n" \
9093 + ".section .altinstr_replacement, \"a\"\n" \
9094 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
9095 ".previous"
9096
9097 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9098 index d854101..f6ea947 100644
9099 --- a/arch/x86/include/asm/apic.h
9100 +++ b/arch/x86/include/asm/apic.h
9101 @@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9102
9103 #ifdef CONFIG_X86_LOCAL_APIC
9104
9105 -extern unsigned int apic_verbosity;
9106 +extern int apic_verbosity;
9107 extern int local_apic_timer_c2_ok;
9108
9109 extern int disable_apic;
9110 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9111 index 20370c6..a2eb9b0 100644
9112 --- a/arch/x86/include/asm/apm.h
9113 +++ b/arch/x86/include/asm/apm.h
9114 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9115 __asm__ __volatile__(APM_DO_ZERO_SEGS
9116 "pushl %%edi\n\t"
9117 "pushl %%ebp\n\t"
9118 - "lcall *%%cs:apm_bios_entry\n\t"
9119 + "lcall *%%ss:apm_bios_entry\n\t"
9120 "setc %%al\n\t"
9121 "popl %%ebp\n\t"
9122 "popl %%edi\n\t"
9123 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9124 __asm__ __volatile__(APM_DO_ZERO_SEGS
9125 "pushl %%edi\n\t"
9126 "pushl %%ebp\n\t"
9127 - "lcall *%%cs:apm_bios_entry\n\t"
9128 + "lcall *%%ss:apm_bios_entry\n\t"
9129 "setc %%bl\n\t"
9130 "popl %%ebp\n\t"
9131 "popl %%edi\n\t"
9132 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9133 index 58cb6d4..ca9010d 100644
9134 --- a/arch/x86/include/asm/atomic.h
9135 +++ b/arch/x86/include/asm/atomic.h
9136 @@ -22,7 +22,18 @@
9137 */
9138 static inline int atomic_read(const atomic_t *v)
9139 {
9140 - return (*(volatile int *)&(v)->counter);
9141 + return (*(volatile const int *)&(v)->counter);
9142 +}
9143 +
9144 +/**
9145 + * atomic_read_unchecked - read atomic variable
9146 + * @v: pointer of type atomic_unchecked_t
9147 + *
9148 + * Atomically reads the value of @v.
9149 + */
9150 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9151 +{
9152 + return (*(volatile const int *)&(v)->counter);
9153 }
9154
9155 /**
9156 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9157 }
9158
9159 /**
9160 + * atomic_set_unchecked - set atomic variable
9161 + * @v: pointer of type atomic_unchecked_t
9162 + * @i: required value
9163 + *
9164 + * Atomically sets the value of @v to @i.
9165 + */
9166 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9167 +{
9168 + v->counter = i;
9169 +}
9170 +
9171 +/**
9172 * atomic_add - add integer to atomic variable
9173 * @i: integer value to add
9174 * @v: pointer of type atomic_t
9175 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9176 */
9177 static inline void atomic_add(int i, atomic_t *v)
9178 {
9179 - asm volatile(LOCK_PREFIX "addl %1,%0"
9180 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9181 +
9182 +#ifdef CONFIG_PAX_REFCOUNT
9183 + "jno 0f\n"
9184 + LOCK_PREFIX "subl %1,%0\n"
9185 + "int $4\n0:\n"
9186 + _ASM_EXTABLE(0b, 0b)
9187 +#endif
9188 +
9189 + : "+m" (v->counter)
9190 + : "ir" (i));
9191 +}
9192 +
9193 +/**
9194 + * atomic_add_unchecked - add integer to atomic variable
9195 + * @i: integer value to add
9196 + * @v: pointer of type atomic_unchecked_t
9197 + *
9198 + * Atomically adds @i to @v.
9199 + */
9200 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9201 +{
9202 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9203 : "+m" (v->counter)
9204 : "ir" (i));
9205 }
9206 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9207 */
9208 static inline void atomic_sub(int i, atomic_t *v)
9209 {
9210 - asm volatile(LOCK_PREFIX "subl %1,%0"
9211 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9212 +
9213 +#ifdef CONFIG_PAX_REFCOUNT
9214 + "jno 0f\n"
9215 + LOCK_PREFIX "addl %1,%0\n"
9216 + "int $4\n0:\n"
9217 + _ASM_EXTABLE(0b, 0b)
9218 +#endif
9219 +
9220 + : "+m" (v->counter)
9221 + : "ir" (i));
9222 +}
9223 +
9224 +/**
9225 + * atomic_sub_unchecked - subtract integer from atomic variable
9226 + * @i: integer value to subtract
9227 + * @v: pointer of type atomic_unchecked_t
9228 + *
9229 + * Atomically subtracts @i from @v.
9230 + */
9231 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9232 +{
9233 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9234 : "+m" (v->counter)
9235 : "ir" (i));
9236 }
9237 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9238 {
9239 unsigned char c;
9240
9241 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9242 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
9243 +
9244 +#ifdef CONFIG_PAX_REFCOUNT
9245 + "jno 0f\n"
9246 + LOCK_PREFIX "addl %2,%0\n"
9247 + "int $4\n0:\n"
9248 + _ASM_EXTABLE(0b, 0b)
9249 +#endif
9250 +
9251 + "sete %1\n"
9252 : "+m" (v->counter), "=qm" (c)
9253 : "ir" (i) : "memory");
9254 return c;
9255 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9256 */
9257 static inline void atomic_inc(atomic_t *v)
9258 {
9259 - asm volatile(LOCK_PREFIX "incl %0"
9260 + asm volatile(LOCK_PREFIX "incl %0\n"
9261 +
9262 +#ifdef CONFIG_PAX_REFCOUNT
9263 + "jno 0f\n"
9264 + LOCK_PREFIX "decl %0\n"
9265 + "int $4\n0:\n"
9266 + _ASM_EXTABLE(0b, 0b)
9267 +#endif
9268 +
9269 + : "+m" (v->counter));
9270 +}
9271 +
9272 +/**
9273 + * atomic_inc_unchecked - increment atomic variable
9274 + * @v: pointer of type atomic_unchecked_t
9275 + *
9276 + * Atomically increments @v by 1.
9277 + */
9278 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9279 +{
9280 + asm volatile(LOCK_PREFIX "incl %0\n"
9281 : "+m" (v->counter));
9282 }
9283
9284 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9285 */
9286 static inline void atomic_dec(atomic_t *v)
9287 {
9288 - asm volatile(LOCK_PREFIX "decl %0"
9289 + asm volatile(LOCK_PREFIX "decl %0\n"
9290 +
9291 +#ifdef CONFIG_PAX_REFCOUNT
9292 + "jno 0f\n"
9293 + LOCK_PREFIX "incl %0\n"
9294 + "int $4\n0:\n"
9295 + _ASM_EXTABLE(0b, 0b)
9296 +#endif
9297 +
9298 + : "+m" (v->counter));
9299 +}
9300 +
9301 +/**
9302 + * atomic_dec_unchecked - decrement atomic variable
9303 + * @v: pointer of type atomic_unchecked_t
9304 + *
9305 + * Atomically decrements @v by 1.
9306 + */
9307 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9308 +{
9309 + asm volatile(LOCK_PREFIX "decl %0\n"
9310 : "+m" (v->counter));
9311 }
9312
9313 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9314 {
9315 unsigned char c;
9316
9317 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
9318 + asm volatile(LOCK_PREFIX "decl %0\n"
9319 +
9320 +#ifdef CONFIG_PAX_REFCOUNT
9321 + "jno 0f\n"
9322 + LOCK_PREFIX "incl %0\n"
9323 + "int $4\n0:\n"
9324 + _ASM_EXTABLE(0b, 0b)
9325 +#endif
9326 +
9327 + "sete %1\n"
9328 : "+m" (v->counter), "=qm" (c)
9329 : : "memory");
9330 return c != 0;
9331 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9332 {
9333 unsigned char c;
9334
9335 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
9336 + asm volatile(LOCK_PREFIX "incl %0\n"
9337 +
9338 +#ifdef CONFIG_PAX_REFCOUNT
9339 + "jno 0f\n"
9340 + LOCK_PREFIX "decl %0\n"
9341 + "int $4\n0:\n"
9342 + _ASM_EXTABLE(0b, 0b)
9343 +#endif
9344 +
9345 + "sete %1\n"
9346 + : "+m" (v->counter), "=qm" (c)
9347 + : : "memory");
9348 + return c != 0;
9349 +}
9350 +
9351 +/**
9352 + * atomic_inc_and_test_unchecked - increment and test
9353 + * @v: pointer of type atomic_unchecked_t
9354 + *
9355 + * Atomically increments @v by 1
9356 + * and returns true if the result is zero, or false for all
9357 + * other cases.
9358 + */
9359 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9360 +{
9361 + unsigned char c;
9362 +
9363 + asm volatile(LOCK_PREFIX "incl %0\n"
9364 + "sete %1\n"
9365 : "+m" (v->counter), "=qm" (c)
9366 : : "memory");
9367 return c != 0;
9368 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9369 {
9370 unsigned char c;
9371
9372 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9373 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
9374 +
9375 +#ifdef CONFIG_PAX_REFCOUNT
9376 + "jno 0f\n"
9377 + LOCK_PREFIX "subl %2,%0\n"
9378 + "int $4\n0:\n"
9379 + _ASM_EXTABLE(0b, 0b)
9380 +#endif
9381 +
9382 + "sets %1\n"
9383 : "+m" (v->counter), "=qm" (c)
9384 : "ir" (i) : "memory");
9385 return c;
9386 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9387 goto no_xadd;
9388 #endif
9389 /* Modern 486+ processor */
9390 - return i + xadd(&v->counter, i);
9391 + return i + xadd_check_overflow(&v->counter, i);
9392
9393 #ifdef CONFIG_M386
9394 no_xadd: /* Legacy 386 processor */
9395 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9396 }
9397
9398 /**
9399 + * atomic_add_return_unchecked - add integer and return
9400 + * @i: integer value to add
9401 + * @v: pointer of type atomic_unchecked_t
9402 + *
9403 + * Atomically adds @i to @v and returns @i + @v
9404 + */
9405 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9406 +{
9407 +#ifdef CONFIG_M386
9408 + int __i;
9409 + unsigned long flags;
9410 + if (unlikely(boot_cpu_data.x86 <= 3))
9411 + goto no_xadd;
9412 +#endif
9413 + /* Modern 486+ processor */
9414 + return i + xadd(&v->counter, i);
9415 +
9416 +#ifdef CONFIG_M386
9417 +no_xadd: /* Legacy 386 processor */
9418 + raw_local_irq_save(flags);
9419 + __i = atomic_read_unchecked(v);
9420 + atomic_set_unchecked(v, i + __i);
9421 + raw_local_irq_restore(flags);
9422 + return i + __i;
9423 +#endif
9424 +}
9425 +
9426 +/**
9427 * atomic_sub_return - subtract integer and return
9428 * @v: pointer of type atomic_t
9429 * @i: integer value to subtract
9430 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9431 }
9432
9433 #define atomic_inc_return(v) (atomic_add_return(1, v))
9434 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9435 +{
9436 + return atomic_add_return_unchecked(1, v);
9437 +}
9438 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9439
9440 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9441 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9442 return cmpxchg(&v->counter, old, new);
9443 }
9444
9445 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9446 +{
9447 + return cmpxchg(&v->counter, old, new);
9448 +}
9449 +
9450 static inline int atomic_xchg(atomic_t *v, int new)
9451 {
9452 return xchg(&v->counter, new);
9453 }
9454
9455 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9456 +{
9457 + return xchg(&v->counter, new);
9458 +}
9459 +
9460 /**
9461 * __atomic_add_unless - add unless the number is already a given value
9462 * @v: pointer of type atomic_t
9463 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9464 */
9465 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9466 {
9467 - int c, old;
9468 + int c, old, new;
9469 c = atomic_read(v);
9470 for (;;) {
9471 - if (unlikely(c == (u)))
9472 + if (unlikely(c == u))
9473 break;
9474 - old = atomic_cmpxchg((v), c, c + (a));
9475 +
9476 + asm volatile("addl %2,%0\n"
9477 +
9478 +#ifdef CONFIG_PAX_REFCOUNT
9479 + "jno 0f\n"
9480 + "subl %2,%0\n"
9481 + "int $4\n0:\n"
9482 + _ASM_EXTABLE(0b, 0b)
9483 +#endif
9484 +
9485 + : "=r" (new)
9486 + : "0" (c), "ir" (a));
9487 +
9488 + old = atomic_cmpxchg(v, c, new);
9489 if (likely(old == c))
9490 break;
9491 c = old;
9492 @@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9493 return c;
9494 }
9495
9496 +/**
9497 + * atomic_inc_not_zero_hint - increment if not null
9498 + * @v: pointer of type atomic_t
9499 + * @hint: probable value of the atomic before the increment
9500 + *
9501 + * This version of atomic_inc_not_zero() gives a hint of probable
9502 + * value of the atomic. This helps processor to not read the memory
9503 + * before doing the atomic read/modify/write cycle, lowering
9504 + * number of bus transactions on some arches.
9505 + *
9506 + * Returns: 0 if increment was not done, 1 otherwise.
9507 + */
9508 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9509 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9510 +{
9511 + int val, c = hint, new;
9512 +
9513 + /* sanity test, should be removed by compiler if hint is a constant */
9514 + if (!hint)
9515 + return __atomic_add_unless(v, 1, 0);
9516 +
9517 + do {
9518 + asm volatile("incl %0\n"
9519 +
9520 +#ifdef CONFIG_PAX_REFCOUNT
9521 + "jno 0f\n"
9522 + "decl %0\n"
9523 + "int $4\n0:\n"
9524 + _ASM_EXTABLE(0b, 0b)
9525 +#endif
9526 +
9527 + : "=r" (new)
9528 + : "0" (c));
9529 +
9530 + val = atomic_cmpxchg(v, c, new);
9531 + if (val == c)
9532 + return 1;
9533 + c = val;
9534 + } while (c);
9535 +
9536 + return 0;
9537 +}
9538
9539 /*
9540 * atomic_dec_if_positive - decrement by 1 if old value positive
9541 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9542 index 1981199..36b9dfb 100644
9543 --- a/arch/x86/include/asm/atomic64_32.h
9544 +++ b/arch/x86/include/asm/atomic64_32.h
9545 @@ -12,6 +12,14 @@ typedef struct {
9546 u64 __aligned(8) counter;
9547 } atomic64_t;
9548
9549 +#ifdef CONFIG_PAX_REFCOUNT
9550 +typedef struct {
9551 + u64 __aligned(8) counter;
9552 +} atomic64_unchecked_t;
9553 +#else
9554 +typedef atomic64_t atomic64_unchecked_t;
9555 +#endif
9556 +
9557 #define ATOMIC64_INIT(val) { (val) }
9558
9559 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
9560 @@ -37,21 +45,31 @@ typedef struct {
9561 ATOMIC64_DECL_ONE(sym##_386)
9562
9563 ATOMIC64_DECL_ONE(add_386);
9564 +ATOMIC64_DECL_ONE(add_unchecked_386);
9565 ATOMIC64_DECL_ONE(sub_386);
9566 +ATOMIC64_DECL_ONE(sub_unchecked_386);
9567 ATOMIC64_DECL_ONE(inc_386);
9568 +ATOMIC64_DECL_ONE(inc_unchecked_386);
9569 ATOMIC64_DECL_ONE(dec_386);
9570 +ATOMIC64_DECL_ONE(dec_unchecked_386);
9571 #endif
9572
9573 #define alternative_atomic64(f, out, in...) \
9574 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
9575
9576 ATOMIC64_DECL(read);
9577 +ATOMIC64_DECL(read_unchecked);
9578 ATOMIC64_DECL(set);
9579 +ATOMIC64_DECL(set_unchecked);
9580 ATOMIC64_DECL(xchg);
9581 ATOMIC64_DECL(add_return);
9582 +ATOMIC64_DECL(add_return_unchecked);
9583 ATOMIC64_DECL(sub_return);
9584 +ATOMIC64_DECL(sub_return_unchecked);
9585 ATOMIC64_DECL(inc_return);
9586 +ATOMIC64_DECL(inc_return_unchecked);
9587 ATOMIC64_DECL(dec_return);
9588 +ATOMIC64_DECL(dec_return_unchecked);
9589 ATOMIC64_DECL(dec_if_positive);
9590 ATOMIC64_DECL(inc_not_zero);
9591 ATOMIC64_DECL(add_unless);
9592 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9593 }
9594
9595 /**
9596 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9597 + * @p: pointer to type atomic64_unchecked_t
9598 + * @o: expected value
9599 + * @n: new value
9600 + *
9601 + * Atomically sets @v to @n if it was equal to @o and returns
9602 + * the old value.
9603 + */
9604 +
9605 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9606 +{
9607 + return cmpxchg64(&v->counter, o, n);
9608 +}
9609 +
9610 +/**
9611 * atomic64_xchg - xchg atomic64 variable
9612 * @v: pointer to type atomic64_t
9613 * @n: value to assign
9614 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9615 }
9616
9617 /**
9618 + * atomic64_set_unchecked - set atomic64 variable
9619 + * @v: pointer to type atomic64_unchecked_t
9620 + * @n: value to assign
9621 + *
9622 + * Atomically sets the value of @v to @n.
9623 + */
9624 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9625 +{
9626 + unsigned high = (unsigned)(i >> 32);
9627 + unsigned low = (unsigned)i;
9628 + alternative_atomic64(set, /* no output */,
9629 + "S" (v), "b" (low), "c" (high)
9630 + : "eax", "edx", "memory");
9631 +}
9632 +
9633 +/**
9634 * atomic64_read - read atomic64 variable
9635 * @v: pointer to type atomic64_t
9636 *
9637 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
9638 }
9639
9640 /**
9641 + * atomic64_read_unchecked - read atomic64 variable
9642 + * @v: pointer to type atomic64_unchecked_t
9643 + *
9644 + * Atomically reads the value of @v and returns it.
9645 + */
9646 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9647 +{
9648 + long long r;
9649 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
9650 + return r;
9651 + }
9652 +
9653 +/**
9654 * atomic64_add_return - add and return
9655 * @i: integer value to add
9656 * @v: pointer to type atomic64_t
9657 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9658 return i;
9659 }
9660
9661 +/**
9662 + * atomic64_add_return_unchecked - add and return
9663 + * @i: integer value to add
9664 + * @v: pointer to type atomic64_unchecked_t
9665 + *
9666 + * Atomically adds @i to @v and returns @i + *@v
9667 + */
9668 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9669 +{
9670 + alternative_atomic64(add_return_unchecked,
9671 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9672 + ASM_NO_INPUT_CLOBBER("memory"));
9673 + return i;
9674 +}
9675 +
9676 /*
9677 * Other variants with different arithmetic operators:
9678 */
9679 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9680 return a;
9681 }
9682
9683 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9684 +{
9685 + long long a;
9686 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
9687 + "S" (v) : "memory", "ecx");
9688 + return a;
9689 +}
9690 +
9691 static inline long long atomic64_dec_return(atomic64_t *v)
9692 {
9693 long long a;
9694 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9695 }
9696
9697 /**
9698 + * atomic64_add_unchecked - add integer to atomic64 variable
9699 + * @i: integer value to add
9700 + * @v: pointer to type atomic64_unchecked_t
9701 + *
9702 + * Atomically adds @i to @v.
9703 + */
9704 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9705 +{
9706 + __alternative_atomic64(add_unchecked, add_return_unchecked,
9707 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9708 + ASM_NO_INPUT_CLOBBER("memory"));
9709 + return i;
9710 +}
9711 +
9712 +/**
9713 * atomic64_sub - subtract the atomic64 variable
9714 * @i: integer value to subtract
9715 * @v: pointer to type atomic64_t
9716 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9717 index 0e1cbfc..5623683 100644
9718 --- a/arch/x86/include/asm/atomic64_64.h
9719 +++ b/arch/x86/include/asm/atomic64_64.h
9720 @@ -18,7 +18,19 @@
9721 */
9722 static inline long atomic64_read(const atomic64_t *v)
9723 {
9724 - return (*(volatile long *)&(v)->counter);
9725 + return (*(volatile const long *)&(v)->counter);
9726 +}
9727 +
9728 +/**
9729 + * atomic64_read_unchecked - read atomic64 variable
9730 + * @v: pointer of type atomic64_unchecked_t
9731 + *
9732 + * Atomically reads the value of @v.
9733 + * Doesn't imply a read memory barrier.
9734 + */
9735 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9736 +{
9737 + return (*(volatile const long *)&(v)->counter);
9738 }
9739
9740 /**
9741 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9742 }
9743
9744 /**
9745 + * atomic64_set_unchecked - set atomic64 variable
9746 + * @v: pointer to type atomic64_unchecked_t
9747 + * @i: required value
9748 + *
9749 + * Atomically sets the value of @v to @i.
9750 + */
9751 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9752 +{
9753 + v->counter = i;
9754 +}
9755 +
9756 +/**
9757 * atomic64_add - add integer to atomic64 variable
9758 * @i: integer value to add
9759 * @v: pointer to type atomic64_t
9760 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9761 */
9762 static inline void atomic64_add(long i, atomic64_t *v)
9763 {
9764 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
9765 +
9766 +#ifdef CONFIG_PAX_REFCOUNT
9767 + "jno 0f\n"
9768 + LOCK_PREFIX "subq %1,%0\n"
9769 + "int $4\n0:\n"
9770 + _ASM_EXTABLE(0b, 0b)
9771 +#endif
9772 +
9773 + : "=m" (v->counter)
9774 + : "er" (i), "m" (v->counter));
9775 +}
9776 +
9777 +/**
9778 + * atomic64_add_unchecked - add integer to atomic64 variable
9779 + * @i: integer value to add
9780 + * @v: pointer to type atomic64_unchecked_t
9781 + *
9782 + * Atomically adds @i to @v.
9783 + */
9784 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9785 +{
9786 asm volatile(LOCK_PREFIX "addq %1,%0"
9787 : "=m" (v->counter)
9788 : "er" (i), "m" (v->counter));
9789 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9790 */
9791 static inline void atomic64_sub(long i, atomic64_t *v)
9792 {
9793 - asm volatile(LOCK_PREFIX "subq %1,%0"
9794 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9795 +
9796 +#ifdef CONFIG_PAX_REFCOUNT
9797 + "jno 0f\n"
9798 + LOCK_PREFIX "addq %1,%0\n"
9799 + "int $4\n0:\n"
9800 + _ASM_EXTABLE(0b, 0b)
9801 +#endif
9802 +
9803 + : "=m" (v->counter)
9804 + : "er" (i), "m" (v->counter));
9805 +}
9806 +
9807 +/**
9808 + * atomic64_sub_unchecked - subtract the atomic64 variable
9809 + * @i: integer value to subtract
9810 + * @v: pointer to type atomic64_unchecked_t
9811 + *
9812 + * Atomically subtracts @i from @v.
9813 + */
9814 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9815 +{
9816 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9817 : "=m" (v->counter)
9818 : "er" (i), "m" (v->counter));
9819 }
9820 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9821 {
9822 unsigned char c;
9823
9824 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9825 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
9826 +
9827 +#ifdef CONFIG_PAX_REFCOUNT
9828 + "jno 0f\n"
9829 + LOCK_PREFIX "addq %2,%0\n"
9830 + "int $4\n0:\n"
9831 + _ASM_EXTABLE(0b, 0b)
9832 +#endif
9833 +
9834 + "sete %1\n"
9835 : "=m" (v->counter), "=qm" (c)
9836 : "er" (i), "m" (v->counter) : "memory");
9837 return c;
9838 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9839 */
9840 static inline void atomic64_inc(atomic64_t *v)
9841 {
9842 + asm volatile(LOCK_PREFIX "incq %0\n"
9843 +
9844 +#ifdef CONFIG_PAX_REFCOUNT
9845 + "jno 0f\n"
9846 + LOCK_PREFIX "decq %0\n"
9847 + "int $4\n0:\n"
9848 + _ASM_EXTABLE(0b, 0b)
9849 +#endif
9850 +
9851 + : "=m" (v->counter)
9852 + : "m" (v->counter));
9853 +}
9854 +
9855 +/**
9856 + * atomic64_inc_unchecked - increment atomic64 variable
9857 + * @v: pointer to type atomic64_unchecked_t
9858 + *
9859 + * Atomically increments @v by 1.
9860 + */
9861 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9862 +{
9863 asm volatile(LOCK_PREFIX "incq %0"
9864 : "=m" (v->counter)
9865 : "m" (v->counter));
9866 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9867 */
9868 static inline void atomic64_dec(atomic64_t *v)
9869 {
9870 - asm volatile(LOCK_PREFIX "decq %0"
9871 + asm volatile(LOCK_PREFIX "decq %0\n"
9872 +
9873 +#ifdef CONFIG_PAX_REFCOUNT
9874 + "jno 0f\n"
9875 + LOCK_PREFIX "incq %0\n"
9876 + "int $4\n0:\n"
9877 + _ASM_EXTABLE(0b, 0b)
9878 +#endif
9879 +
9880 + : "=m" (v->counter)
9881 + : "m" (v->counter));
9882 +}
9883 +
9884 +/**
9885 + * atomic64_dec_unchecked - decrement atomic64 variable
9886 + * @v: pointer to type atomic64_t
9887 + *
9888 + * Atomically decrements @v by 1.
9889 + */
9890 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9891 +{
9892 + asm volatile(LOCK_PREFIX "decq %0\n"
9893 : "=m" (v->counter)
9894 : "m" (v->counter));
9895 }
9896 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9897 {
9898 unsigned char c;
9899
9900 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
9901 + asm volatile(LOCK_PREFIX "decq %0\n"
9902 +
9903 +#ifdef CONFIG_PAX_REFCOUNT
9904 + "jno 0f\n"
9905 + LOCK_PREFIX "incq %0\n"
9906 + "int $4\n0:\n"
9907 + _ASM_EXTABLE(0b, 0b)
9908 +#endif
9909 +
9910 + "sete %1\n"
9911 : "=m" (v->counter), "=qm" (c)
9912 : "m" (v->counter) : "memory");
9913 return c != 0;
9914 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9915 {
9916 unsigned char c;
9917
9918 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
9919 + asm volatile(LOCK_PREFIX "incq %0\n"
9920 +
9921 +#ifdef CONFIG_PAX_REFCOUNT
9922 + "jno 0f\n"
9923 + LOCK_PREFIX "decq %0\n"
9924 + "int $4\n0:\n"
9925 + _ASM_EXTABLE(0b, 0b)
9926 +#endif
9927 +
9928 + "sete %1\n"
9929 : "=m" (v->counter), "=qm" (c)
9930 : "m" (v->counter) : "memory");
9931 return c != 0;
9932 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9933 {
9934 unsigned char c;
9935
9936 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9937 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
9938 +
9939 +#ifdef CONFIG_PAX_REFCOUNT
9940 + "jno 0f\n"
9941 + LOCK_PREFIX "subq %2,%0\n"
9942 + "int $4\n0:\n"
9943 + _ASM_EXTABLE(0b, 0b)
9944 +#endif
9945 +
9946 + "sets %1\n"
9947 : "=m" (v->counter), "=qm" (c)
9948 : "er" (i), "m" (v->counter) : "memory");
9949 return c;
9950 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9951 */
9952 static inline long atomic64_add_return(long i, atomic64_t *v)
9953 {
9954 + return i + xadd_check_overflow(&v->counter, i);
9955 +}
9956 +
9957 +/**
9958 + * atomic64_add_return_unchecked - add and return
9959 + * @i: integer value to add
9960 + * @v: pointer to type atomic64_unchecked_t
9961 + *
9962 + * Atomically adds @i to @v and returns @i + @v
9963 + */
9964 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9965 +{
9966 return i + xadd(&v->counter, i);
9967 }
9968
9969 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
9970 }
9971
9972 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
9973 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9974 +{
9975 + return atomic64_add_return_unchecked(1, v);
9976 +}
9977 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
9978
9979 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9980 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9981 return cmpxchg(&v->counter, old, new);
9982 }
9983
9984 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
9985 +{
9986 + return cmpxchg(&v->counter, old, new);
9987 +}
9988 +
9989 static inline long atomic64_xchg(atomic64_t *v, long new)
9990 {
9991 return xchg(&v->counter, new);
9992 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
9993 */
9994 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
9995 {
9996 - long c, old;
9997 + long c, old, new;
9998 c = atomic64_read(v);
9999 for (;;) {
10000 - if (unlikely(c == (u)))
10001 + if (unlikely(c == u))
10002 break;
10003 - old = atomic64_cmpxchg((v), c, c + (a));
10004 +
10005 + asm volatile("add %2,%0\n"
10006 +
10007 +#ifdef CONFIG_PAX_REFCOUNT
10008 + "jno 0f\n"
10009 + "sub %2,%0\n"
10010 + "int $4\n0:\n"
10011 + _ASM_EXTABLE(0b, 0b)
10012 +#endif
10013 +
10014 + : "=r" (new)
10015 + : "0" (c), "ir" (a));
10016 +
10017 + old = atomic64_cmpxchg(v, c, new);
10018 if (likely(old == c))
10019 break;
10020 c = old;
10021 }
10022 - return c != (u);
10023 + return c != u;
10024 }
10025
10026 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10027 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10028 index b97596e..9bd48b06 100644
10029 --- a/arch/x86/include/asm/bitops.h
10030 +++ b/arch/x86/include/asm/bitops.h
10031 @@ -38,7 +38,7 @@
10032 * a mask operation on a byte.
10033 */
10034 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10035 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10036 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10037 #define CONST_MASK(nr) (1 << ((nr) & 7))
10038
10039 /**
10040 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10041 index 5e1a2ee..c9f9533 100644
10042 --- a/arch/x86/include/asm/boot.h
10043 +++ b/arch/x86/include/asm/boot.h
10044 @@ -11,10 +11,15 @@
10045 #include <asm/pgtable_types.h>
10046
10047 /* Physical address where kernel should be loaded. */
10048 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10049 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10050 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10051 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10052
10053 +#ifndef __ASSEMBLY__
10054 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
10055 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10056 +#endif
10057 +
10058 /* Minimum kernel alignment, as a power of two */
10059 #ifdef CONFIG_X86_64
10060 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10061 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10062 index 48f99f1..d78ebf9 100644
10063 --- a/arch/x86/include/asm/cache.h
10064 +++ b/arch/x86/include/asm/cache.h
10065 @@ -5,12 +5,13 @@
10066
10067 /* L1 cache line size */
10068 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10069 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10070 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10071
10072 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10073 +#define __read_only __attribute__((__section__(".data..read_only")))
10074
10075 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10076 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10077 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10078
10079 #ifdef CONFIG_X86_VSMP
10080 #ifdef CONFIG_SMP
10081 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10082 index 9863ee3..4a1f8e1 100644
10083 --- a/arch/x86/include/asm/cacheflush.h
10084 +++ b/arch/x86/include/asm/cacheflush.h
10085 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10086 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10087
10088 if (pg_flags == _PGMT_DEFAULT)
10089 - return -1;
10090 + return ~0UL;
10091 else if (pg_flags == _PGMT_WC)
10092 return _PAGE_CACHE_WC;
10093 else if (pg_flags == _PGMT_UC_MINUS)
10094 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10095 index 46fc474..b02b0f9 100644
10096 --- a/arch/x86/include/asm/checksum_32.h
10097 +++ b/arch/x86/include/asm/checksum_32.h
10098 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10099 int len, __wsum sum,
10100 int *src_err_ptr, int *dst_err_ptr);
10101
10102 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10103 + int len, __wsum sum,
10104 + int *src_err_ptr, int *dst_err_ptr);
10105 +
10106 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10107 + int len, __wsum sum,
10108 + int *src_err_ptr, int *dst_err_ptr);
10109 +
10110 /*
10111 * Note: when you get a NULL pointer exception here this means someone
10112 * passed in an incorrect kernel address to one of these functions.
10113 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10114 int *err_ptr)
10115 {
10116 might_sleep();
10117 - return csum_partial_copy_generic((__force void *)src, dst,
10118 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
10119 len, sum, err_ptr, NULL);
10120 }
10121
10122 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10123 {
10124 might_sleep();
10125 if (access_ok(VERIFY_WRITE, dst, len))
10126 - return csum_partial_copy_generic(src, (__force void *)dst,
10127 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10128 len, sum, NULL, err_ptr);
10129
10130 if (len)
10131 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10132 index 99480e5..d81165b 100644
10133 --- a/arch/x86/include/asm/cmpxchg.h
10134 +++ b/arch/x86/include/asm/cmpxchg.h
10135 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10136 __compiletime_error("Bad argument size for cmpxchg");
10137 extern void __xadd_wrong_size(void)
10138 __compiletime_error("Bad argument size for xadd");
10139 +extern void __xadd_check_overflow_wrong_size(void)
10140 + __compiletime_error("Bad argument size for xadd_check_overflow");
10141 extern void __add_wrong_size(void)
10142 __compiletime_error("Bad argument size for add");
10143 +extern void __add_check_overflow_wrong_size(void)
10144 + __compiletime_error("Bad argument size for add_check_overflow");
10145
10146 /*
10147 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10148 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10149 __ret; \
10150 })
10151
10152 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10153 + ({ \
10154 + __typeof__ (*(ptr)) __ret = (arg); \
10155 + switch (sizeof(*(ptr))) { \
10156 + case __X86_CASE_L: \
10157 + asm volatile (lock #op "l %0, %1\n" \
10158 + "jno 0f\n" \
10159 + "mov %0,%1\n" \
10160 + "int $4\n0:\n" \
10161 + _ASM_EXTABLE(0b, 0b) \
10162 + : "+r" (__ret), "+m" (*(ptr)) \
10163 + : : "memory", "cc"); \
10164 + break; \
10165 + case __X86_CASE_Q: \
10166 + asm volatile (lock #op "q %q0, %1\n" \
10167 + "jno 0f\n" \
10168 + "mov %0,%1\n" \
10169 + "int $4\n0:\n" \
10170 + _ASM_EXTABLE(0b, 0b) \
10171 + : "+r" (__ret), "+m" (*(ptr)) \
10172 + : : "memory", "cc"); \
10173 + break; \
10174 + default: \
10175 + __ ## op ## _check_overflow_wrong_size(); \
10176 + } \
10177 + __ret; \
10178 + })
10179 +
10180 /*
10181 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10182 * Since this is generally used to protect other memory information, we
10183 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10184 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10185 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10186
10187 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10188 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10189 +
10190 #define __add(ptr, inc, lock) \
10191 ({ \
10192 __typeof__ (*(ptr)) __ret = (inc); \
10193 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10194 index f91e80f..7f9bd27 100644
10195 --- a/arch/x86/include/asm/cpufeature.h
10196 +++ b/arch/x86/include/asm/cpufeature.h
10197 @@ -371,7 +371,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10198 ".section .discard,\"aw\",@progbits\n"
10199 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10200 ".previous\n"
10201 - ".section .altinstr_replacement,\"ax\"\n"
10202 + ".section .altinstr_replacement,\"a\"\n"
10203 "3: movb $1,%0\n"
10204 "4:\n"
10205 ".previous\n"
10206 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10207 index e95822d..a90010e 100644
10208 --- a/arch/x86/include/asm/desc.h
10209 +++ b/arch/x86/include/asm/desc.h
10210 @@ -4,6 +4,7 @@
10211 #include <asm/desc_defs.h>
10212 #include <asm/ldt.h>
10213 #include <asm/mmu.h>
10214 +#include <asm/pgtable.h>
10215
10216 #include <linux/smp.h>
10217
10218 @@ -16,6 +17,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10219
10220 desc->type = (info->read_exec_only ^ 1) << 1;
10221 desc->type |= info->contents << 2;
10222 + desc->type |= info->seg_not_present ^ 1;
10223
10224 desc->s = 1;
10225 desc->dpl = 0x3;
10226 @@ -34,19 +36,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10227 }
10228
10229 extern struct desc_ptr idt_descr;
10230 -extern gate_desc idt_table[];
10231 extern struct desc_ptr nmi_idt_descr;
10232 -extern gate_desc nmi_idt_table[];
10233 -
10234 -struct gdt_page {
10235 - struct desc_struct gdt[GDT_ENTRIES];
10236 -} __attribute__((aligned(PAGE_SIZE)));
10237 -
10238 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10239 +extern gate_desc idt_table[256];
10240 +extern gate_desc nmi_idt_table[256];
10241
10242 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10243 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10244 {
10245 - return per_cpu(gdt_page, cpu).gdt;
10246 + return cpu_gdt_table[cpu];
10247 }
10248
10249 #ifdef CONFIG_X86_64
10250 @@ -71,8 +68,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10251 unsigned long base, unsigned dpl, unsigned flags,
10252 unsigned short seg)
10253 {
10254 - gate->a = (seg << 16) | (base & 0xffff);
10255 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10256 + gate->gate.offset_low = base;
10257 + gate->gate.seg = seg;
10258 + gate->gate.reserved = 0;
10259 + gate->gate.type = type;
10260 + gate->gate.s = 0;
10261 + gate->gate.dpl = dpl;
10262 + gate->gate.p = 1;
10263 + gate->gate.offset_high = base >> 16;
10264 }
10265
10266 #endif
10267 @@ -117,12 +120,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10268
10269 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10270 {
10271 + pax_open_kernel();
10272 memcpy(&idt[entry], gate, sizeof(*gate));
10273 + pax_close_kernel();
10274 }
10275
10276 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10277 {
10278 + pax_open_kernel();
10279 memcpy(&ldt[entry], desc, 8);
10280 + pax_close_kernel();
10281 }
10282
10283 static inline void
10284 @@ -136,7 +143,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10285 default: size = sizeof(*gdt); break;
10286 }
10287
10288 + pax_open_kernel();
10289 memcpy(&gdt[entry], desc, size);
10290 + pax_close_kernel();
10291 }
10292
10293 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10294 @@ -209,7 +218,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10295
10296 static inline void native_load_tr_desc(void)
10297 {
10298 + pax_open_kernel();
10299 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10300 + pax_close_kernel();
10301 }
10302
10303 static inline void native_load_gdt(const struct desc_ptr *dtr)
10304 @@ -246,8 +257,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10305 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10306 unsigned int i;
10307
10308 + pax_open_kernel();
10309 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10310 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10311 + pax_close_kernel();
10312 }
10313
10314 #define _LDT_empty(info) \
10315 @@ -310,7 +323,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10316 }
10317
10318 #ifdef CONFIG_X86_64
10319 -static inline void set_nmi_gate(int gate, void *addr)
10320 +static inline void set_nmi_gate(int gate, const void *addr)
10321 {
10322 gate_desc s;
10323
10324 @@ -319,7 +332,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10325 }
10326 #endif
10327
10328 -static inline void _set_gate(int gate, unsigned type, void *addr,
10329 +static inline void _set_gate(int gate, unsigned type, const void *addr,
10330 unsigned dpl, unsigned ist, unsigned seg)
10331 {
10332 gate_desc s;
10333 @@ -338,7 +351,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10334 * Pentium F0 0F bugfix can have resulted in the mapped
10335 * IDT being write-protected.
10336 */
10337 -static inline void set_intr_gate(unsigned int n, void *addr)
10338 +static inline void set_intr_gate(unsigned int n, const void *addr)
10339 {
10340 BUG_ON((unsigned)n > 0xFF);
10341 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10342 @@ -368,19 +381,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10343 /*
10344 * This routine sets up an interrupt gate at directory privilege level 3.
10345 */
10346 -static inline void set_system_intr_gate(unsigned int n, void *addr)
10347 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
10348 {
10349 BUG_ON((unsigned)n > 0xFF);
10350 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10351 }
10352
10353 -static inline void set_system_trap_gate(unsigned int n, void *addr)
10354 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
10355 {
10356 BUG_ON((unsigned)n > 0xFF);
10357 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10358 }
10359
10360 -static inline void set_trap_gate(unsigned int n, void *addr)
10361 +static inline void set_trap_gate(unsigned int n, const void *addr)
10362 {
10363 BUG_ON((unsigned)n > 0xFF);
10364 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10365 @@ -389,19 +402,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10366 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10367 {
10368 BUG_ON((unsigned)n > 0xFF);
10369 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10370 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10371 }
10372
10373 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10374 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10375 {
10376 BUG_ON((unsigned)n > 0xFF);
10377 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10378 }
10379
10380 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10381 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10382 {
10383 BUG_ON((unsigned)n > 0xFF);
10384 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10385 }
10386
10387 +#ifdef CONFIG_X86_32
10388 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10389 +{
10390 + struct desc_struct d;
10391 +
10392 + if (likely(limit))
10393 + limit = (limit - 1UL) >> PAGE_SHIFT;
10394 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
10395 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10396 +}
10397 +#endif
10398 +
10399 #endif /* _ASM_X86_DESC_H */
10400 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10401 index 278441f..b95a174 100644
10402 --- a/arch/x86/include/asm/desc_defs.h
10403 +++ b/arch/x86/include/asm/desc_defs.h
10404 @@ -31,6 +31,12 @@ struct desc_struct {
10405 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10406 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10407 };
10408 + struct {
10409 + u16 offset_low;
10410 + u16 seg;
10411 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10412 + unsigned offset_high: 16;
10413 + } gate;
10414 };
10415 } __attribute__((packed));
10416
10417 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10418 index 3778256..c5d4fce 100644
10419 --- a/arch/x86/include/asm/e820.h
10420 +++ b/arch/x86/include/asm/e820.h
10421 @@ -69,7 +69,7 @@ struct e820map {
10422 #define ISA_START_ADDRESS 0xa0000
10423 #define ISA_END_ADDRESS 0x100000
10424
10425 -#define BIOS_BEGIN 0x000a0000
10426 +#define BIOS_BEGIN 0x000c0000
10427 #define BIOS_END 0x00100000
10428
10429 #define BIOS_ROM_BASE 0xffe00000
10430 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10431 index 5939f44..f8845f6 100644
10432 --- a/arch/x86/include/asm/elf.h
10433 +++ b/arch/x86/include/asm/elf.h
10434 @@ -243,7 +243,25 @@ extern int force_personality32;
10435 the loader. We need to make sure that it is out of the way of the program
10436 that it will "exec", and that there is sufficient room for the brk. */
10437
10438 +#ifdef CONFIG_PAX_SEGMEXEC
10439 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10440 +#else
10441 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10442 +#endif
10443 +
10444 +#ifdef CONFIG_PAX_ASLR
10445 +#ifdef CONFIG_X86_32
10446 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10447 +
10448 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10449 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10450 +#else
10451 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
10452 +
10453 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10454 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10455 +#endif
10456 +#endif
10457
10458 /* This yields a mask that user programs can use to figure out what
10459 instruction set this CPU supports. This could be done in user space,
10460 @@ -296,16 +314,12 @@ do { \
10461
10462 #define ARCH_DLINFO \
10463 do { \
10464 - if (vdso_enabled) \
10465 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10466 - (unsigned long)current->mm->context.vdso); \
10467 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10468 } while (0)
10469
10470 #define ARCH_DLINFO_X32 \
10471 do { \
10472 - if (vdso_enabled) \
10473 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10474 - (unsigned long)current->mm->context.vdso); \
10475 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10476 } while (0)
10477
10478 #define AT_SYSINFO 32
10479 @@ -320,7 +334,7 @@ else \
10480
10481 #endif /* !CONFIG_X86_32 */
10482
10483 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10484 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10485
10486 #define VDSO_ENTRY \
10487 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10488 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
10489 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10490 #define compat_arch_setup_additional_pages syscall32_setup_pages
10491
10492 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10493 -#define arch_randomize_brk arch_randomize_brk
10494 -
10495 /*
10496 * True on X86_32 or when emulating IA32 on X86_64
10497 */
10498 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10499 index cc70c1c..d96d011 100644
10500 --- a/arch/x86/include/asm/emergency-restart.h
10501 +++ b/arch/x86/include/asm/emergency-restart.h
10502 @@ -15,6 +15,6 @@ enum reboot_type {
10503
10504 extern enum reboot_type reboot_type;
10505
10506 -extern void machine_emergency_restart(void);
10507 +extern void machine_emergency_restart(void) __noreturn;
10508
10509 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10510 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
10511 index 4fa8815..71b121a 100644
10512 --- a/arch/x86/include/asm/fpu-internal.h
10513 +++ b/arch/x86/include/asm/fpu-internal.h
10514 @@ -86,6 +86,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10515 {
10516 int err;
10517
10518 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10519 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10520 + fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10521 +#endif
10522 +
10523 /* See comment in fxsave() below. */
10524 #ifdef CONFIG_AS_FXSAVEQ
10525 asm volatile("1: fxrstorq %[fx]\n\t"
10526 @@ -115,6 +120,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10527 {
10528 int err;
10529
10530 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10531 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10532 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10533 +#endif
10534 +
10535 /*
10536 * Clear the bytes not touched by the fxsave and reserved
10537 * for the SW usage.
10538 @@ -271,7 +281,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10539 "emms\n\t" /* clear stack tags */
10540 "fildl %P[addr]", /* set F?P to defined value */
10541 X86_FEATURE_FXSAVE_LEAK,
10542 - [addr] "m" (tsk->thread.fpu.has_fpu));
10543 + [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10544
10545 return fpu_restore_checking(&tsk->thread.fpu);
10546 }
10547 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10548 index 71ecbcb..bac10b7 100644
10549 --- a/arch/x86/include/asm/futex.h
10550 +++ b/arch/x86/include/asm/futex.h
10551 @@ -11,16 +11,18 @@
10552 #include <asm/processor.h>
10553
10554 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10555 + typecheck(u32 __user *, uaddr); \
10556 asm volatile("1:\t" insn "\n" \
10557 "2:\t.section .fixup,\"ax\"\n" \
10558 "3:\tmov\t%3, %1\n" \
10559 "\tjmp\t2b\n" \
10560 "\t.previous\n" \
10561 _ASM_EXTABLE(1b, 3b) \
10562 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10563 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10564 : "i" (-EFAULT), "0" (oparg), "1" (0))
10565
10566 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10567 + typecheck(u32 __user *, uaddr); \
10568 asm volatile("1:\tmovl %2, %0\n" \
10569 "\tmovl\t%0, %3\n" \
10570 "\t" insn "\n" \
10571 @@ -33,7 +35,7 @@
10572 _ASM_EXTABLE(1b, 4b) \
10573 _ASM_EXTABLE(2b, 4b) \
10574 : "=&a" (oldval), "=&r" (ret), \
10575 - "+m" (*uaddr), "=&r" (tem) \
10576 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10577 : "r" (oparg), "i" (-EFAULT), "1" (0))
10578
10579 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10580 @@ -60,10 +62,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10581
10582 switch (op) {
10583 case FUTEX_OP_SET:
10584 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10585 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10586 break;
10587 case FUTEX_OP_ADD:
10588 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10589 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10590 uaddr, oparg);
10591 break;
10592 case FUTEX_OP_OR:
10593 @@ -122,13 +124,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10594 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10595 return -EFAULT;
10596
10597 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10598 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10599 "2:\t.section .fixup, \"ax\"\n"
10600 "3:\tmov %3, %0\n"
10601 "\tjmp 2b\n"
10602 "\t.previous\n"
10603 _ASM_EXTABLE(1b, 3b)
10604 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10605 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10606 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10607 : "memory"
10608 );
10609 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10610 index eb92a6e..b98b2f4 100644
10611 --- a/arch/x86/include/asm/hw_irq.h
10612 +++ b/arch/x86/include/asm/hw_irq.h
10613 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10614 extern void enable_IO_APIC(void);
10615
10616 /* Statistics */
10617 -extern atomic_t irq_err_count;
10618 -extern atomic_t irq_mis_count;
10619 +extern atomic_unchecked_t irq_err_count;
10620 +extern atomic_unchecked_t irq_mis_count;
10621
10622 /* EISA */
10623 extern void eisa_set_level_irq(unsigned int irq);
10624 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10625 index d8e8eef..99f81ae 100644
10626 --- a/arch/x86/include/asm/io.h
10627 +++ b/arch/x86/include/asm/io.h
10628 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10629
10630 #include <linux/vmalloc.h>
10631
10632 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10633 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10634 +{
10635 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10636 +}
10637 +
10638 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10639 +{
10640 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10641 +}
10642 +
10643 /*
10644 * Convert a virtual cached pointer to an uncached pointer
10645 */
10646 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10647 index bba3cf8..06bc8da 100644
10648 --- a/arch/x86/include/asm/irqflags.h
10649 +++ b/arch/x86/include/asm/irqflags.h
10650 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10651 sti; \
10652 sysexit
10653
10654 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
10655 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10656 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
10657 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10658 +
10659 #else
10660 #define INTERRUPT_RETURN iret
10661 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10662 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10663 index 5478825..839e88c 100644
10664 --- a/arch/x86/include/asm/kprobes.h
10665 +++ b/arch/x86/include/asm/kprobes.h
10666 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10667 #define RELATIVEJUMP_SIZE 5
10668 #define RELATIVECALL_OPCODE 0xe8
10669 #define RELATIVE_ADDR_SIZE 4
10670 -#define MAX_STACK_SIZE 64
10671 -#define MIN_STACK_SIZE(ADDR) \
10672 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10673 - THREAD_SIZE - (unsigned long)(ADDR))) \
10674 - ? (MAX_STACK_SIZE) \
10675 - : (((unsigned long)current_thread_info()) + \
10676 - THREAD_SIZE - (unsigned long)(ADDR)))
10677 +#define MAX_STACK_SIZE 64UL
10678 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10679
10680 #define flush_insn_slot(p) do { } while (0)
10681
10682 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10683 index e216ba0..453f6ec 100644
10684 --- a/arch/x86/include/asm/kvm_host.h
10685 +++ b/arch/x86/include/asm/kvm_host.h
10686 @@ -679,7 +679,7 @@ struct kvm_x86_ops {
10687 int (*check_intercept)(struct kvm_vcpu *vcpu,
10688 struct x86_instruction_info *info,
10689 enum x86_intercept_stage stage);
10690 -};
10691 +} __do_const;
10692
10693 struct kvm_arch_async_pf {
10694 u32 token;
10695 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10696 index c8bed0d..e5721fa 100644
10697 --- a/arch/x86/include/asm/local.h
10698 +++ b/arch/x86/include/asm/local.h
10699 @@ -17,26 +17,58 @@ typedef struct {
10700
10701 static inline void local_inc(local_t *l)
10702 {
10703 - asm volatile(_ASM_INC "%0"
10704 + asm volatile(_ASM_INC "%0\n"
10705 +
10706 +#ifdef CONFIG_PAX_REFCOUNT
10707 + "jno 0f\n"
10708 + _ASM_DEC "%0\n"
10709 + "int $4\n0:\n"
10710 + _ASM_EXTABLE(0b, 0b)
10711 +#endif
10712 +
10713 : "+m" (l->a.counter));
10714 }
10715
10716 static inline void local_dec(local_t *l)
10717 {
10718 - asm volatile(_ASM_DEC "%0"
10719 + asm volatile(_ASM_DEC "%0\n"
10720 +
10721 +#ifdef CONFIG_PAX_REFCOUNT
10722 + "jno 0f\n"
10723 + _ASM_INC "%0\n"
10724 + "int $4\n0:\n"
10725 + _ASM_EXTABLE(0b, 0b)
10726 +#endif
10727 +
10728 : "+m" (l->a.counter));
10729 }
10730
10731 static inline void local_add(long i, local_t *l)
10732 {
10733 - asm volatile(_ASM_ADD "%1,%0"
10734 + asm volatile(_ASM_ADD "%1,%0\n"
10735 +
10736 +#ifdef CONFIG_PAX_REFCOUNT
10737 + "jno 0f\n"
10738 + _ASM_SUB "%1,%0\n"
10739 + "int $4\n0:\n"
10740 + _ASM_EXTABLE(0b, 0b)
10741 +#endif
10742 +
10743 : "+m" (l->a.counter)
10744 : "ir" (i));
10745 }
10746
10747 static inline void local_sub(long i, local_t *l)
10748 {
10749 - asm volatile(_ASM_SUB "%1,%0"
10750 + asm volatile(_ASM_SUB "%1,%0\n"
10751 +
10752 +#ifdef CONFIG_PAX_REFCOUNT
10753 + "jno 0f\n"
10754 + _ASM_ADD "%1,%0\n"
10755 + "int $4\n0:\n"
10756 + _ASM_EXTABLE(0b, 0b)
10757 +#endif
10758 +
10759 : "+m" (l->a.counter)
10760 : "ir" (i));
10761 }
10762 @@ -54,7 +86,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10763 {
10764 unsigned char c;
10765
10766 - asm volatile(_ASM_SUB "%2,%0; sete %1"
10767 + asm volatile(_ASM_SUB "%2,%0\n"
10768 +
10769 +#ifdef CONFIG_PAX_REFCOUNT
10770 + "jno 0f\n"
10771 + _ASM_ADD "%2,%0\n"
10772 + "int $4\n0:\n"
10773 + _ASM_EXTABLE(0b, 0b)
10774 +#endif
10775 +
10776 + "sete %1\n"
10777 : "+m" (l->a.counter), "=qm" (c)
10778 : "ir" (i) : "memory");
10779 return c;
10780 @@ -72,7 +113,16 @@ static inline int local_dec_and_test(local_t *l)
10781 {
10782 unsigned char c;
10783
10784 - asm volatile(_ASM_DEC "%0; sete %1"
10785 + asm volatile(_ASM_DEC "%0\n"
10786 +
10787 +#ifdef CONFIG_PAX_REFCOUNT
10788 + "jno 0f\n"
10789 + _ASM_INC "%0\n"
10790 + "int $4\n0:\n"
10791 + _ASM_EXTABLE(0b, 0b)
10792 +#endif
10793 +
10794 + "sete %1\n"
10795 : "+m" (l->a.counter), "=qm" (c)
10796 : : "memory");
10797 return c != 0;
10798 @@ -90,7 +140,16 @@ static inline int local_inc_and_test(local_t *l)
10799 {
10800 unsigned char c;
10801
10802 - asm volatile(_ASM_INC "%0; sete %1"
10803 + asm volatile(_ASM_INC "%0\n"
10804 +
10805 +#ifdef CONFIG_PAX_REFCOUNT
10806 + "jno 0f\n"
10807 + _ASM_DEC "%0\n"
10808 + "int $4\n0:\n"
10809 + _ASM_EXTABLE(0b, 0b)
10810 +#endif
10811 +
10812 + "sete %1\n"
10813 : "+m" (l->a.counter), "=qm" (c)
10814 : : "memory");
10815 return c != 0;
10816 @@ -109,7 +168,16 @@ static inline int local_add_negative(long i, local_t *l)
10817 {
10818 unsigned char c;
10819
10820 - asm volatile(_ASM_ADD "%2,%0; sets %1"
10821 + asm volatile(_ASM_ADD "%2,%0\n"
10822 +
10823 +#ifdef CONFIG_PAX_REFCOUNT
10824 + "jno 0f\n"
10825 + _ASM_SUB "%2,%0\n"
10826 + "int $4\n0:\n"
10827 + _ASM_EXTABLE(0b, 0b)
10828 +#endif
10829 +
10830 + "sets %1\n"
10831 : "+m" (l->a.counter), "=qm" (c)
10832 : "ir" (i) : "memory");
10833 return c;
10834 @@ -132,7 +200,15 @@ static inline long local_add_return(long i, local_t *l)
10835 #endif
10836 /* Modern 486+ processor */
10837 __i = i;
10838 - asm volatile(_ASM_XADD "%0, %1;"
10839 + asm volatile(_ASM_XADD "%0, %1\n"
10840 +
10841 +#ifdef CONFIG_PAX_REFCOUNT
10842 + "jno 0f\n"
10843 + _ASM_MOV "%0,%1\n"
10844 + "int $4\n0:\n"
10845 + _ASM_EXTABLE(0b, 0b)
10846 +#endif
10847 +
10848 : "+r" (i), "+m" (l->a.counter)
10849 : : "memory");
10850 return i + __i;
10851 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10852 index 593e51d..fa69c9a 100644
10853 --- a/arch/x86/include/asm/mman.h
10854 +++ b/arch/x86/include/asm/mman.h
10855 @@ -5,4 +5,14 @@
10856
10857 #include <asm-generic/mman.h>
10858
10859 +#ifdef __KERNEL__
10860 +#ifndef __ASSEMBLY__
10861 +#ifdef CONFIG_X86_32
10862 +#define arch_mmap_check i386_mmap_check
10863 +int i386_mmap_check(unsigned long addr, unsigned long len,
10864 + unsigned long flags);
10865 +#endif
10866 +#endif
10867 +#endif
10868 +
10869 #endif /* _ASM_X86_MMAN_H */
10870 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10871 index 5f55e69..e20bfb1 100644
10872 --- a/arch/x86/include/asm/mmu.h
10873 +++ b/arch/x86/include/asm/mmu.h
10874 @@ -9,7 +9,7 @@
10875 * we put the segment information here.
10876 */
10877 typedef struct {
10878 - void *ldt;
10879 + struct desc_struct *ldt;
10880 int size;
10881
10882 #ifdef CONFIG_X86_64
10883 @@ -18,7 +18,19 @@ typedef struct {
10884 #endif
10885
10886 struct mutex lock;
10887 - void *vdso;
10888 + unsigned long vdso;
10889 +
10890 +#ifdef CONFIG_X86_32
10891 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10892 + unsigned long user_cs_base;
10893 + unsigned long user_cs_limit;
10894 +
10895 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10896 + cpumask_t cpu_user_cs_mask;
10897 +#endif
10898 +
10899 +#endif
10900 +#endif
10901 } mm_context_t;
10902
10903 #ifdef CONFIG_SMP
10904 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10905 index 6902152..da4283a 100644
10906 --- a/arch/x86/include/asm/mmu_context.h
10907 +++ b/arch/x86/include/asm/mmu_context.h
10908 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10909
10910 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10911 {
10912 +
10913 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10914 + unsigned int i;
10915 + pgd_t *pgd;
10916 +
10917 + pax_open_kernel();
10918 + pgd = get_cpu_pgd(smp_processor_id());
10919 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10920 + set_pgd_batched(pgd+i, native_make_pgd(0));
10921 + pax_close_kernel();
10922 +#endif
10923 +
10924 #ifdef CONFIG_SMP
10925 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10926 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10927 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10928 struct task_struct *tsk)
10929 {
10930 unsigned cpu = smp_processor_id();
10931 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10932 + int tlbstate = TLBSTATE_OK;
10933 +#endif
10934
10935 if (likely(prev != next)) {
10936 #ifdef CONFIG_SMP
10937 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10938 + tlbstate = percpu_read(cpu_tlbstate.state);
10939 +#endif
10940 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10941 percpu_write(cpu_tlbstate.active_mm, next);
10942 #endif
10943 cpumask_set_cpu(cpu, mm_cpumask(next));
10944
10945 /* Re-load page tables */
10946 +#ifdef CONFIG_PAX_PER_CPU_PGD
10947 + pax_open_kernel();
10948 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
10949 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
10950 + pax_close_kernel();
10951 + load_cr3(get_cpu_pgd(cpu));
10952 +#else
10953 load_cr3(next->pgd);
10954 +#endif
10955
10956 /* stop flush ipis for the previous mm */
10957 cpumask_clear_cpu(cpu, mm_cpumask(prev));
10958 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10959 */
10960 if (unlikely(prev->context.ldt != next->context.ldt))
10961 load_LDT_nolock(&next->context);
10962 - }
10963 +
10964 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10965 + if (!(__supported_pte_mask & _PAGE_NX)) {
10966 + smp_mb__before_clear_bit();
10967 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
10968 + smp_mb__after_clear_bit();
10969 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10970 + }
10971 +#endif
10972 +
10973 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10974 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
10975 + prev->context.user_cs_limit != next->context.user_cs_limit))
10976 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10977 #ifdef CONFIG_SMP
10978 + else if (unlikely(tlbstate != TLBSTATE_OK))
10979 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10980 +#endif
10981 +#endif
10982 +
10983 + }
10984 else {
10985 +
10986 +#ifdef CONFIG_PAX_PER_CPU_PGD
10987 + pax_open_kernel();
10988 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
10989 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
10990 + pax_close_kernel();
10991 + load_cr3(get_cpu_pgd(cpu));
10992 +#endif
10993 +
10994 +#ifdef CONFIG_SMP
10995 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10996 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
10997
10998 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10999 * tlb flush IPI delivery. We must reload CR3
11000 * to make sure to use no freed page tables.
11001 */
11002 +
11003 +#ifndef CONFIG_PAX_PER_CPU_PGD
11004 load_cr3(next->pgd);
11005 +#endif
11006 +
11007 load_LDT_nolock(&next->context);
11008 +
11009 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
11010 + if (!(__supported_pte_mask & _PAGE_NX))
11011 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11012 +#endif
11013 +
11014 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11015 +#ifdef CONFIG_PAX_PAGEEXEC
11016 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
11017 +#endif
11018 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11019 +#endif
11020 +
11021 }
11022 +#endif
11023 }
11024 -#endif
11025 }
11026
11027 #define activate_mm(prev, next) \
11028 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11029 index 9eae775..c914fea 100644
11030 --- a/arch/x86/include/asm/module.h
11031 +++ b/arch/x86/include/asm/module.h
11032 @@ -5,6 +5,7 @@
11033
11034 #ifdef CONFIG_X86_64
11035 /* X86_64 does not define MODULE_PROC_FAMILY */
11036 +#define MODULE_PROC_FAMILY ""
11037 #elif defined CONFIG_M386
11038 #define MODULE_PROC_FAMILY "386 "
11039 #elif defined CONFIG_M486
11040 @@ -59,8 +60,20 @@
11041 #error unknown processor family
11042 #endif
11043
11044 -#ifdef CONFIG_X86_32
11045 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11046 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11047 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11048 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11049 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11050 +#else
11051 +#define MODULE_PAX_KERNEXEC ""
11052 #endif
11053
11054 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11055 +#define MODULE_PAX_UDEREF "UDEREF "
11056 +#else
11057 +#define MODULE_PAX_UDEREF ""
11058 +#endif
11059 +
11060 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11061 +
11062 #endif /* _ASM_X86_MODULE_H */
11063 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11064 index 7639dbf..e08a58c 100644
11065 --- a/arch/x86/include/asm/page_64_types.h
11066 +++ b/arch/x86/include/asm/page_64_types.h
11067 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11068
11069 /* duplicated to the one in bootmem.h */
11070 extern unsigned long max_pfn;
11071 -extern unsigned long phys_base;
11072 +extern const unsigned long phys_base;
11073
11074 extern unsigned long __phys_addr(unsigned long);
11075 #define __phys_reloc_hide(x) (x)
11076 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11077 index aa0f913..0c5bc6a 100644
11078 --- a/arch/x86/include/asm/paravirt.h
11079 +++ b/arch/x86/include/asm/paravirt.h
11080 @@ -668,6 +668,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11081 val);
11082 }
11083
11084 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11085 +{
11086 + pgdval_t val = native_pgd_val(pgd);
11087 +
11088 + if (sizeof(pgdval_t) > sizeof(long))
11089 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11090 + val, (u64)val >> 32);
11091 + else
11092 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11093 + val);
11094 +}
11095 +
11096 static inline void pgd_clear(pgd_t *pgdp)
11097 {
11098 set_pgd(pgdp, __pgd(0));
11099 @@ -749,6 +761,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11100 pv_mmu_ops.set_fixmap(idx, phys, flags);
11101 }
11102
11103 +#ifdef CONFIG_PAX_KERNEXEC
11104 +static inline unsigned long pax_open_kernel(void)
11105 +{
11106 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11107 +}
11108 +
11109 +static inline unsigned long pax_close_kernel(void)
11110 +{
11111 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11112 +}
11113 +#else
11114 +static inline unsigned long pax_open_kernel(void) { return 0; }
11115 +static inline unsigned long pax_close_kernel(void) { return 0; }
11116 +#endif
11117 +
11118 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11119
11120 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11121 @@ -965,7 +992,7 @@ extern void default_banner(void);
11122
11123 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11124 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11125 -#define PARA_INDIRECT(addr) *%cs:addr
11126 +#define PARA_INDIRECT(addr) *%ss:addr
11127 #endif
11128
11129 #define INTERRUPT_RETURN \
11130 @@ -1042,6 +1069,21 @@ extern void default_banner(void);
11131 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11132 CLBR_NONE, \
11133 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11134 +
11135 +#define GET_CR0_INTO_RDI \
11136 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11137 + mov %rax,%rdi
11138 +
11139 +#define SET_RDI_INTO_CR0 \
11140 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11141 +
11142 +#define GET_CR3_INTO_RDI \
11143 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11144 + mov %rax,%rdi
11145 +
11146 +#define SET_RDI_INTO_CR3 \
11147 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11148 +
11149 #endif /* CONFIG_X86_32 */
11150
11151 #endif /* __ASSEMBLY__ */
11152 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11153 index 8e8b9a4..f07d725 100644
11154 --- a/arch/x86/include/asm/paravirt_types.h
11155 +++ b/arch/x86/include/asm/paravirt_types.h
11156 @@ -84,20 +84,20 @@ struct pv_init_ops {
11157 */
11158 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11159 unsigned long addr, unsigned len);
11160 -};
11161 +} __no_const;
11162
11163
11164 struct pv_lazy_ops {
11165 /* Set deferred update mode, used for batching operations. */
11166 void (*enter)(void);
11167 void (*leave)(void);
11168 -};
11169 +} __no_const;
11170
11171 struct pv_time_ops {
11172 unsigned long long (*sched_clock)(void);
11173 unsigned long long (*steal_clock)(int cpu);
11174 unsigned long (*get_tsc_khz)(void);
11175 -};
11176 +} __no_const;
11177
11178 struct pv_cpu_ops {
11179 /* hooks for various privileged instructions */
11180 @@ -193,7 +193,7 @@ struct pv_cpu_ops {
11181
11182 void (*start_context_switch)(struct task_struct *prev);
11183 void (*end_context_switch)(struct task_struct *next);
11184 -};
11185 +} __no_const;
11186
11187 struct pv_irq_ops {
11188 /*
11189 @@ -224,7 +224,7 @@ struct pv_apic_ops {
11190 unsigned long start_eip,
11191 unsigned long start_esp);
11192 #endif
11193 -};
11194 +} __no_const;
11195
11196 struct pv_mmu_ops {
11197 unsigned long (*read_cr2)(void);
11198 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
11199 struct paravirt_callee_save make_pud;
11200
11201 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11202 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11203 #endif /* PAGETABLE_LEVELS == 4 */
11204 #endif /* PAGETABLE_LEVELS >= 3 */
11205
11206 @@ -324,6 +325,12 @@ struct pv_mmu_ops {
11207 an mfn. We can tell which is which from the index. */
11208 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11209 phys_addr_t phys, pgprot_t flags);
11210 +
11211 +#ifdef CONFIG_PAX_KERNEXEC
11212 + unsigned long (*pax_open_kernel)(void);
11213 + unsigned long (*pax_close_kernel)(void);
11214 +#endif
11215 +
11216 };
11217
11218 struct arch_spinlock;
11219 @@ -334,7 +341,7 @@ struct pv_lock_ops {
11220 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11221 int (*spin_trylock)(struct arch_spinlock *lock);
11222 void (*spin_unlock)(struct arch_spinlock *lock);
11223 -};
11224 +} __no_const;
11225
11226 /* This contains all the paravirt structures: we get a convenient
11227 * number for each function using the offset which we use to indicate
11228 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11229 index b4389a4..7024269 100644
11230 --- a/arch/x86/include/asm/pgalloc.h
11231 +++ b/arch/x86/include/asm/pgalloc.h
11232 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11233 pmd_t *pmd, pte_t *pte)
11234 {
11235 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11236 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11237 +}
11238 +
11239 +static inline void pmd_populate_user(struct mm_struct *mm,
11240 + pmd_t *pmd, pte_t *pte)
11241 +{
11242 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11243 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11244 }
11245
11246 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11247
11248 #ifdef CONFIG_X86_PAE
11249 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11250 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11251 +{
11252 + pud_populate(mm, pudp, pmd);
11253 +}
11254 #else /* !CONFIG_X86_PAE */
11255 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11256 {
11257 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11258 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11259 }
11260 +
11261 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11262 +{
11263 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11264 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11265 +}
11266 #endif /* CONFIG_X86_PAE */
11267
11268 #if PAGETABLE_LEVELS > 3
11269 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11270 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11271 }
11272
11273 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11274 +{
11275 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11276 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11277 +}
11278 +
11279 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11280 {
11281 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11282 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11283 index 98391db..8f6984e 100644
11284 --- a/arch/x86/include/asm/pgtable-2level.h
11285 +++ b/arch/x86/include/asm/pgtable-2level.h
11286 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11287
11288 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11289 {
11290 + pax_open_kernel();
11291 *pmdp = pmd;
11292 + pax_close_kernel();
11293 }
11294
11295 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11296 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11297 index cb00ccc..17e9054 100644
11298 --- a/arch/x86/include/asm/pgtable-3level.h
11299 +++ b/arch/x86/include/asm/pgtable-3level.h
11300 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11301
11302 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11303 {
11304 + pax_open_kernel();
11305 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11306 + pax_close_kernel();
11307 }
11308
11309 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11310 {
11311 + pax_open_kernel();
11312 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11313 + pax_close_kernel();
11314 }
11315
11316 /*
11317 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11318 index 49afb3f..91a8c63 100644
11319 --- a/arch/x86/include/asm/pgtable.h
11320 +++ b/arch/x86/include/asm/pgtable.h
11321 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11322
11323 #ifndef __PAGETABLE_PUD_FOLDED
11324 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11325 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11326 #define pgd_clear(pgd) native_pgd_clear(pgd)
11327 #endif
11328
11329 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11330
11331 #define arch_end_context_switch(prev) do {} while(0)
11332
11333 +#define pax_open_kernel() native_pax_open_kernel()
11334 +#define pax_close_kernel() native_pax_close_kernel()
11335 #endif /* CONFIG_PARAVIRT */
11336
11337 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
11338 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11339 +
11340 +#ifdef CONFIG_PAX_KERNEXEC
11341 +static inline unsigned long native_pax_open_kernel(void)
11342 +{
11343 + unsigned long cr0;
11344 +
11345 + preempt_disable();
11346 + barrier();
11347 + cr0 = read_cr0() ^ X86_CR0_WP;
11348 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
11349 + write_cr0(cr0);
11350 + return cr0 ^ X86_CR0_WP;
11351 +}
11352 +
11353 +static inline unsigned long native_pax_close_kernel(void)
11354 +{
11355 + unsigned long cr0;
11356 +
11357 + cr0 = read_cr0() ^ X86_CR0_WP;
11358 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11359 + write_cr0(cr0);
11360 + barrier();
11361 + preempt_enable_no_resched();
11362 + return cr0 ^ X86_CR0_WP;
11363 +}
11364 +#else
11365 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
11366 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
11367 +#endif
11368 +
11369 /*
11370 * The following only work if pte_present() is true.
11371 * Undefined behaviour if not..
11372 */
11373 +static inline int pte_user(pte_t pte)
11374 +{
11375 + return pte_val(pte) & _PAGE_USER;
11376 +}
11377 +
11378 static inline int pte_dirty(pte_t pte)
11379 {
11380 return pte_flags(pte) & _PAGE_DIRTY;
11381 @@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11382 return pte_clear_flags(pte, _PAGE_RW);
11383 }
11384
11385 +static inline pte_t pte_mkread(pte_t pte)
11386 +{
11387 + return __pte(pte_val(pte) | _PAGE_USER);
11388 +}
11389 +
11390 static inline pte_t pte_mkexec(pte_t pte)
11391 {
11392 - return pte_clear_flags(pte, _PAGE_NX);
11393 +#ifdef CONFIG_X86_PAE
11394 + if (__supported_pte_mask & _PAGE_NX)
11395 + return pte_clear_flags(pte, _PAGE_NX);
11396 + else
11397 +#endif
11398 + return pte_set_flags(pte, _PAGE_USER);
11399 +}
11400 +
11401 +static inline pte_t pte_exprotect(pte_t pte)
11402 +{
11403 +#ifdef CONFIG_X86_PAE
11404 + if (__supported_pte_mask & _PAGE_NX)
11405 + return pte_set_flags(pte, _PAGE_NX);
11406 + else
11407 +#endif
11408 + return pte_clear_flags(pte, _PAGE_USER);
11409 }
11410
11411 static inline pte_t pte_mkdirty(pte_t pte)
11412 @@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11413 #endif
11414
11415 #ifndef __ASSEMBLY__
11416 +
11417 +#ifdef CONFIG_PAX_PER_CPU_PGD
11418 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11419 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11420 +{
11421 + return cpu_pgd[cpu];
11422 +}
11423 +#endif
11424 +
11425 #include <linux/mm_types.h>
11426
11427 static inline int pte_none(pte_t pte)
11428 @@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11429
11430 static inline int pgd_bad(pgd_t pgd)
11431 {
11432 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11433 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11434 }
11435
11436 static inline int pgd_none(pgd_t pgd)
11437 @@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
11438 * pgd_offset() returns a (pgd_t *)
11439 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11440 */
11441 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11442 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11443 +
11444 +#ifdef CONFIG_PAX_PER_CPU_PGD
11445 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11446 +#endif
11447 +
11448 /*
11449 * a shortcut which implies the use of the kernel's pgd, instead
11450 * of a process's
11451 @@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
11452 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11453 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11454
11455 +#ifdef CONFIG_X86_32
11456 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11457 +#else
11458 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11459 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11460 +
11461 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11462 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11463 +#else
11464 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11465 +#endif
11466 +
11467 +#endif
11468 +
11469 #ifndef __ASSEMBLY__
11470
11471 extern int direct_gbpages;
11472 @@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11473 * dst and src can be on the same page, but the range must not overlap,
11474 * and must not cross a page boundary.
11475 */
11476 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11477 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11478 {
11479 - memcpy(dst, src, count * sizeof(pgd_t));
11480 + pax_open_kernel();
11481 + while (count--)
11482 + *dst++ = *src++;
11483 + pax_close_kernel();
11484 }
11485
11486 +#ifdef CONFIG_PAX_PER_CPU_PGD
11487 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11488 +#endif
11489 +
11490 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11491 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11492 +#else
11493 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11494 +#endif
11495
11496 #include <asm-generic/pgtable.h>
11497 #endif /* __ASSEMBLY__ */
11498 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11499 index 0c92113..34a77c6 100644
11500 --- a/arch/x86/include/asm/pgtable_32.h
11501 +++ b/arch/x86/include/asm/pgtable_32.h
11502 @@ -25,9 +25,6 @@
11503 struct mm_struct;
11504 struct vm_area_struct;
11505
11506 -extern pgd_t swapper_pg_dir[1024];
11507 -extern pgd_t initial_page_table[1024];
11508 -
11509 static inline void pgtable_cache_init(void) { }
11510 static inline void check_pgt_cache(void) { }
11511 void paging_init(void);
11512 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11513 # include <asm/pgtable-2level.h>
11514 #endif
11515
11516 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11517 +extern pgd_t initial_page_table[PTRS_PER_PGD];
11518 +#ifdef CONFIG_X86_PAE
11519 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11520 +#endif
11521 +
11522 #if defined(CONFIG_HIGHPTE)
11523 #define pte_offset_map(dir, address) \
11524 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11525 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11526 /* Clear a kernel PTE and flush it from the TLB */
11527 #define kpte_clear_flush(ptep, vaddr) \
11528 do { \
11529 + pax_open_kernel(); \
11530 pte_clear(&init_mm, (vaddr), (ptep)); \
11531 + pax_close_kernel(); \
11532 __flush_tlb_one((vaddr)); \
11533 } while (0)
11534
11535 @@ -74,6 +79,9 @@ do { \
11536
11537 #endif /* !__ASSEMBLY__ */
11538
11539 +#define HAVE_ARCH_UNMAPPED_AREA
11540 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11541 +
11542 /*
11543 * kern_addr_valid() is (1) for FLATMEM and (0) for
11544 * SPARSEMEM and DISCONTIGMEM
11545 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11546 index ed5903b..c7fe163 100644
11547 --- a/arch/x86/include/asm/pgtable_32_types.h
11548 +++ b/arch/x86/include/asm/pgtable_32_types.h
11549 @@ -8,7 +8,7 @@
11550 */
11551 #ifdef CONFIG_X86_PAE
11552 # include <asm/pgtable-3level_types.h>
11553 -# define PMD_SIZE (1UL << PMD_SHIFT)
11554 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11555 # define PMD_MASK (~(PMD_SIZE - 1))
11556 #else
11557 # include <asm/pgtable-2level_types.h>
11558 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11559 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11560 #endif
11561
11562 +#ifdef CONFIG_PAX_KERNEXEC
11563 +#ifndef __ASSEMBLY__
11564 +extern unsigned char MODULES_EXEC_VADDR[];
11565 +extern unsigned char MODULES_EXEC_END[];
11566 +#endif
11567 +#include <asm/boot.h>
11568 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11569 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11570 +#else
11571 +#define ktla_ktva(addr) (addr)
11572 +#define ktva_ktla(addr) (addr)
11573 +#endif
11574 +
11575 #define MODULES_VADDR VMALLOC_START
11576 #define MODULES_END VMALLOC_END
11577 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11578 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11579 index 975f709..9f779c9 100644
11580 --- a/arch/x86/include/asm/pgtable_64.h
11581 +++ b/arch/x86/include/asm/pgtable_64.h
11582 @@ -16,10 +16,14 @@
11583
11584 extern pud_t level3_kernel_pgt[512];
11585 extern pud_t level3_ident_pgt[512];
11586 +extern pud_t level3_vmalloc_start_pgt[512];
11587 +extern pud_t level3_vmalloc_end_pgt[512];
11588 +extern pud_t level3_vmemmap_pgt[512];
11589 +extern pud_t level2_vmemmap_pgt[512];
11590 extern pmd_t level2_kernel_pgt[512];
11591 extern pmd_t level2_fixmap_pgt[512];
11592 -extern pmd_t level2_ident_pgt[512];
11593 -extern pgd_t init_level4_pgt[];
11594 +extern pmd_t level2_ident_pgt[512*2];
11595 +extern pgd_t init_level4_pgt[512];
11596
11597 #define swapper_pg_dir init_level4_pgt
11598
11599 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11600
11601 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11602 {
11603 + pax_open_kernel();
11604 *pmdp = pmd;
11605 + pax_close_kernel();
11606 }
11607
11608 static inline void native_pmd_clear(pmd_t *pmd)
11609 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11610
11611 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11612 {
11613 + pax_open_kernel();
11614 *pudp = pud;
11615 + pax_close_kernel();
11616 }
11617
11618 static inline void native_pud_clear(pud_t *pud)
11619 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11620
11621 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11622 {
11623 + pax_open_kernel();
11624 + *pgdp = pgd;
11625 + pax_close_kernel();
11626 +}
11627 +
11628 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11629 +{
11630 *pgdp = pgd;
11631 }
11632
11633 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11634 index 766ea16..5b96cb3 100644
11635 --- a/arch/x86/include/asm/pgtable_64_types.h
11636 +++ b/arch/x86/include/asm/pgtable_64_types.h
11637 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11638 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11639 #define MODULES_END _AC(0xffffffffff000000, UL)
11640 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11641 +#define MODULES_EXEC_VADDR MODULES_VADDR
11642 +#define MODULES_EXEC_END MODULES_END
11643 +
11644 +#define ktla_ktva(addr) (addr)
11645 +#define ktva_ktla(addr) (addr)
11646
11647 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11648 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11649 index 013286a..8b42f4f 100644
11650 --- a/arch/x86/include/asm/pgtable_types.h
11651 +++ b/arch/x86/include/asm/pgtable_types.h
11652 @@ -16,13 +16,12 @@
11653 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11654 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11655 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11656 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11657 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11658 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11659 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11660 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11661 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11662 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11663 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11664 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11665 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11666 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11667
11668 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11669 @@ -40,7 +39,6 @@
11670 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11671 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11672 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11673 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11674 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11675 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11676 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11677 @@ -57,8 +55,10 @@
11678
11679 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11680 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11681 -#else
11682 +#elif defined(CONFIG_KMEMCHECK)
11683 #define _PAGE_NX (_AT(pteval_t, 0))
11684 +#else
11685 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11686 #endif
11687
11688 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11689 @@ -96,6 +96,9 @@
11690 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11691 _PAGE_ACCESSED)
11692
11693 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
11694 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
11695 +
11696 #define __PAGE_KERNEL_EXEC \
11697 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11698 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11699 @@ -106,7 +109,7 @@
11700 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11701 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11702 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11703 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11704 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11705 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11706 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11707 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11708 @@ -168,8 +171,8 @@
11709 * bits are combined, this will alow user to access the high address mapped
11710 * VDSO in the presence of CONFIG_COMPAT_VDSO
11711 */
11712 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11713 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11714 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11715 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11716 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11717 #endif
11718
11719 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11720 {
11721 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11722 }
11723 +#endif
11724
11725 +#if PAGETABLE_LEVELS == 3
11726 +#include <asm-generic/pgtable-nopud.h>
11727 +#endif
11728 +
11729 +#if PAGETABLE_LEVELS == 2
11730 +#include <asm-generic/pgtable-nopmd.h>
11731 +#endif
11732 +
11733 +#ifndef __ASSEMBLY__
11734 #if PAGETABLE_LEVELS > 3
11735 typedef struct { pudval_t pud; } pud_t;
11736
11737 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11738 return pud.pud;
11739 }
11740 #else
11741 -#include <asm-generic/pgtable-nopud.h>
11742 -
11743 static inline pudval_t native_pud_val(pud_t pud)
11744 {
11745 return native_pgd_val(pud.pgd);
11746 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11747 return pmd.pmd;
11748 }
11749 #else
11750 -#include <asm-generic/pgtable-nopmd.h>
11751 -
11752 static inline pmdval_t native_pmd_val(pmd_t pmd)
11753 {
11754 return native_pgd_val(pmd.pud.pgd);
11755 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11756
11757 extern pteval_t __supported_pte_mask;
11758 extern void set_nx(void);
11759 -extern int nx_enabled;
11760
11761 #define pgprot_writecombine pgprot_writecombine
11762 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11763 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11764 index 4fa7dcc..764e33a 100644
11765 --- a/arch/x86/include/asm/processor.h
11766 +++ b/arch/x86/include/asm/processor.h
11767 @@ -276,7 +276,7 @@ struct tss_struct {
11768
11769 } ____cacheline_aligned;
11770
11771 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11772 +extern struct tss_struct init_tss[NR_CPUS];
11773
11774 /*
11775 * Save the original ist values for checking stack pointers during debugging
11776 @@ -807,11 +807,18 @@ static inline void spin_lock_prefetch(const void *x)
11777 */
11778 #define TASK_SIZE PAGE_OFFSET
11779 #define TASK_SIZE_MAX TASK_SIZE
11780 +
11781 +#ifdef CONFIG_PAX_SEGMEXEC
11782 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11783 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11784 +#else
11785 #define STACK_TOP TASK_SIZE
11786 -#define STACK_TOP_MAX STACK_TOP
11787 +#endif
11788 +
11789 +#define STACK_TOP_MAX TASK_SIZE
11790
11791 #define INIT_THREAD { \
11792 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11793 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11794 .vm86_info = NULL, \
11795 .sysenter_cs = __KERNEL_CS, \
11796 .io_bitmap_ptr = NULL, \
11797 @@ -825,7 +832,7 @@ static inline void spin_lock_prefetch(const void *x)
11798 */
11799 #define INIT_TSS { \
11800 .x86_tss = { \
11801 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11802 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11803 .ss0 = __KERNEL_DS, \
11804 .ss1 = __KERNEL_CS, \
11805 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11806 @@ -836,11 +843,7 @@ static inline void spin_lock_prefetch(const void *x)
11807 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11808
11809 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11810 -#define KSTK_TOP(info) \
11811 -({ \
11812 - unsigned long *__ptr = (unsigned long *)(info); \
11813 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11814 -})
11815 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11816
11817 /*
11818 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11819 @@ -855,7 +858,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11820 #define task_pt_regs(task) \
11821 ({ \
11822 struct pt_regs *__regs__; \
11823 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11824 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11825 __regs__ - 1; \
11826 })
11827
11828 @@ -865,13 +868,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11829 /*
11830 * User space process size. 47bits minus one guard page.
11831 */
11832 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11833 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11834
11835 /* This decides where the kernel will search for a free chunk of vm
11836 * space during mmap's.
11837 */
11838 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11839 - 0xc0000000 : 0xFFFFe000)
11840 + 0xc0000000 : 0xFFFFf000)
11841
11842 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
11843 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11844 @@ -882,11 +885,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11845 #define STACK_TOP_MAX TASK_SIZE_MAX
11846
11847 #define INIT_THREAD { \
11848 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11849 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11850 }
11851
11852 #define INIT_TSS { \
11853 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11854 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11855 }
11856
11857 /*
11858 @@ -914,6 +917,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11859 */
11860 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11861
11862 +#ifdef CONFIG_PAX_SEGMEXEC
11863 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11864 +#endif
11865 +
11866 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11867
11868 /* Get/set a process' ability to use the timestamp counter instruction */
11869 @@ -976,12 +983,12 @@ extern bool cpu_has_amd_erratum(const int *);
11870
11871 void cpu_idle_wait(void);
11872
11873 -extern unsigned long arch_align_stack(unsigned long sp);
11874 +#define arch_align_stack(x) ((x) & ~0xfUL)
11875 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11876
11877 void default_idle(void);
11878 bool set_pm_idle_to_default(void);
11879
11880 -void stop_this_cpu(void *dummy);
11881 +void stop_this_cpu(void *dummy) __noreturn;
11882
11883 #endif /* _ASM_X86_PROCESSOR_H */
11884 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11885 index dcfde52..dbfea06 100644
11886 --- a/arch/x86/include/asm/ptrace.h
11887 +++ b/arch/x86/include/asm/ptrace.h
11888 @@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11889 }
11890
11891 /*
11892 - * user_mode_vm(regs) determines whether a register set came from user mode.
11893 + * user_mode(regs) determines whether a register set came from user mode.
11894 * This is true if V8086 mode was enabled OR if the register set was from
11895 * protected mode with RPL-3 CS value. This tricky test checks that with
11896 * one comparison. Many places in the kernel can bypass this full check
11897 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11898 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11899 + * be used.
11900 */
11901 -static inline int user_mode(struct pt_regs *regs)
11902 +static inline int user_mode_novm(struct pt_regs *regs)
11903 {
11904 #ifdef CONFIG_X86_32
11905 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11906 #else
11907 - return !!(regs->cs & 3);
11908 + return !!(regs->cs & SEGMENT_RPL_MASK);
11909 #endif
11910 }
11911
11912 -static inline int user_mode_vm(struct pt_regs *regs)
11913 +static inline int user_mode(struct pt_regs *regs)
11914 {
11915 #ifdef CONFIG_X86_32
11916 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11917 USER_RPL;
11918 #else
11919 - return user_mode(regs);
11920 + return user_mode_novm(regs);
11921 #endif
11922 }
11923
11924 @@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
11925 #ifdef CONFIG_X86_64
11926 static inline bool user_64bit_mode(struct pt_regs *regs)
11927 {
11928 + unsigned long cs = regs->cs & 0xffff;
11929 #ifndef CONFIG_PARAVIRT
11930 /*
11931 * On non-paravirt systems, this is the only long mode CPL 3
11932 * selector. We do not allow long mode selectors in the LDT.
11933 */
11934 - return regs->cs == __USER_CS;
11935 + return cs == __USER_CS;
11936 #else
11937 /* Headers are too twisted for this to go in paravirt.h. */
11938 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
11939 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
11940 #endif
11941 }
11942 #endif
11943 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
11944 index 92f29706..a79cbbb 100644
11945 --- a/arch/x86/include/asm/reboot.h
11946 +++ b/arch/x86/include/asm/reboot.h
11947 @@ -6,19 +6,19 @@
11948 struct pt_regs;
11949
11950 struct machine_ops {
11951 - void (*restart)(char *cmd);
11952 - void (*halt)(void);
11953 - void (*power_off)(void);
11954 + void (* __noreturn restart)(char *cmd);
11955 + void (* __noreturn halt)(void);
11956 + void (* __noreturn power_off)(void);
11957 void (*shutdown)(void);
11958 void (*crash_shutdown)(struct pt_regs *);
11959 - void (*emergency_restart)(void);
11960 -};
11961 + void (* __noreturn emergency_restart)(void);
11962 +} __no_const;
11963
11964 extern struct machine_ops machine_ops;
11965
11966 void native_machine_crash_shutdown(struct pt_regs *regs);
11967 void native_machine_shutdown(void);
11968 -void machine_real_restart(unsigned int type);
11969 +void machine_real_restart(unsigned int type) __noreturn;
11970 /* These must match dispatch_table in reboot_32.S */
11971 #define MRR_BIOS 0
11972 #define MRR_APM 1
11973 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
11974 index 2dbe4a7..ce1db00 100644
11975 --- a/arch/x86/include/asm/rwsem.h
11976 +++ b/arch/x86/include/asm/rwsem.h
11977 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
11978 {
11979 asm volatile("# beginning down_read\n\t"
11980 LOCK_PREFIX _ASM_INC "(%1)\n\t"
11981 +
11982 +#ifdef CONFIG_PAX_REFCOUNT
11983 + "jno 0f\n"
11984 + LOCK_PREFIX _ASM_DEC "(%1)\n"
11985 + "int $4\n0:\n"
11986 + _ASM_EXTABLE(0b, 0b)
11987 +#endif
11988 +
11989 /* adds 0x00000001 */
11990 " jns 1f\n"
11991 " call call_rwsem_down_read_failed\n"
11992 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
11993 "1:\n\t"
11994 " mov %1,%2\n\t"
11995 " add %3,%2\n\t"
11996 +
11997 +#ifdef CONFIG_PAX_REFCOUNT
11998 + "jno 0f\n"
11999 + "sub %3,%2\n"
12000 + "int $4\n0:\n"
12001 + _ASM_EXTABLE(0b, 0b)
12002 +#endif
12003 +
12004 " jle 2f\n\t"
12005 LOCK_PREFIX " cmpxchg %2,%0\n\t"
12006 " jnz 1b\n\t"
12007 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
12008 long tmp;
12009 asm volatile("# beginning down_write\n\t"
12010 LOCK_PREFIX " xadd %1,(%2)\n\t"
12011 +
12012 +#ifdef CONFIG_PAX_REFCOUNT
12013 + "jno 0f\n"
12014 + "mov %1,(%2)\n"
12015 + "int $4\n0:\n"
12016 + _ASM_EXTABLE(0b, 0b)
12017 +#endif
12018 +
12019 /* adds 0xffff0001, returns the old value */
12020 " test %1,%1\n\t"
12021 /* was the count 0 before? */
12022 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12023 long tmp;
12024 asm volatile("# beginning __up_read\n\t"
12025 LOCK_PREFIX " xadd %1,(%2)\n\t"
12026 +
12027 +#ifdef CONFIG_PAX_REFCOUNT
12028 + "jno 0f\n"
12029 + "mov %1,(%2)\n"
12030 + "int $4\n0:\n"
12031 + _ASM_EXTABLE(0b, 0b)
12032 +#endif
12033 +
12034 /* subtracts 1, returns the old value */
12035 " jns 1f\n\t"
12036 " call call_rwsem_wake\n" /* expects old value in %edx */
12037 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12038 long tmp;
12039 asm volatile("# beginning __up_write\n\t"
12040 LOCK_PREFIX " xadd %1,(%2)\n\t"
12041 +
12042 +#ifdef CONFIG_PAX_REFCOUNT
12043 + "jno 0f\n"
12044 + "mov %1,(%2)\n"
12045 + "int $4\n0:\n"
12046 + _ASM_EXTABLE(0b, 0b)
12047 +#endif
12048 +
12049 /* subtracts 0xffff0001, returns the old value */
12050 " jns 1f\n\t"
12051 " call call_rwsem_wake\n" /* expects old value in %edx */
12052 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12053 {
12054 asm volatile("# beginning __downgrade_write\n\t"
12055 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12056 +
12057 +#ifdef CONFIG_PAX_REFCOUNT
12058 + "jno 0f\n"
12059 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12060 + "int $4\n0:\n"
12061 + _ASM_EXTABLE(0b, 0b)
12062 +#endif
12063 +
12064 /*
12065 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12066 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12067 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12068 */
12069 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12070 {
12071 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12072 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12073 +
12074 +#ifdef CONFIG_PAX_REFCOUNT
12075 + "jno 0f\n"
12076 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
12077 + "int $4\n0:\n"
12078 + _ASM_EXTABLE(0b, 0b)
12079 +#endif
12080 +
12081 : "+m" (sem->count)
12082 : "er" (delta));
12083 }
12084 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12085 */
12086 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12087 {
12088 - return delta + xadd(&sem->count, delta);
12089 + return delta + xadd_check_overflow(&sem->count, delta);
12090 }
12091
12092 #endif /* __KERNEL__ */
12093 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12094 index 1654662..5af4157 100644
12095 --- a/arch/x86/include/asm/segment.h
12096 +++ b/arch/x86/include/asm/segment.h
12097 @@ -64,10 +64,15 @@
12098 * 26 - ESPFIX small SS
12099 * 27 - per-cpu [ offset to per-cpu data area ]
12100 * 28 - stack_canary-20 [ for stack protector ]
12101 - * 29 - unused
12102 - * 30 - unused
12103 + * 29 - PCI BIOS CS
12104 + * 30 - PCI BIOS DS
12105 * 31 - TSS for double fault handler
12106 */
12107 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12108 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12109 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12110 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12111 +
12112 #define GDT_ENTRY_TLS_MIN 6
12113 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12114
12115 @@ -79,6 +84,8 @@
12116
12117 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12118
12119 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12120 +
12121 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12122
12123 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12124 @@ -104,6 +111,12 @@
12125 #define __KERNEL_STACK_CANARY 0
12126 #endif
12127
12128 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12129 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12130 +
12131 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12132 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12133 +
12134 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12135
12136 /*
12137 @@ -141,7 +154,7 @@
12138 */
12139
12140 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12141 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12142 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12143
12144
12145 #else
12146 @@ -165,6 +178,8 @@
12147 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12148 #define __USER32_DS __USER_DS
12149
12150 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12151 +
12152 #define GDT_ENTRY_TSS 8 /* needs two entries */
12153 #define GDT_ENTRY_LDT 10 /* needs two entries */
12154 #define GDT_ENTRY_TLS_MIN 12
12155 @@ -185,6 +200,7 @@
12156 #endif
12157
12158 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12159 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12160 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12161 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12162 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12163 @@ -263,7 +279,7 @@ static inline unsigned long get_limit(unsigned long segment)
12164 {
12165 unsigned long __limit;
12166 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12167 - return __limit + 1;
12168 + return __limit;
12169 }
12170
12171 #endif /* !__ASSEMBLY__ */
12172 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12173 index 0434c40..1714bf0 100644
12174 --- a/arch/x86/include/asm/smp.h
12175 +++ b/arch/x86/include/asm/smp.h
12176 @@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
12177 /* cpus sharing the last level cache: */
12178 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
12179 DECLARE_PER_CPU(u16, cpu_llc_id);
12180 -DECLARE_PER_CPU(int, cpu_number);
12181 +DECLARE_PER_CPU(unsigned int, cpu_number);
12182
12183 static inline struct cpumask *cpu_sibling_mask(int cpu)
12184 {
12185 @@ -77,7 +77,7 @@ struct smp_ops {
12186
12187 void (*send_call_func_ipi)(const struct cpumask *mask);
12188 void (*send_call_func_single_ipi)(int cpu);
12189 -};
12190 +} __no_const;
12191
12192 /* Globals due to paravirt */
12193 extern void set_cpu_sibling_map(int cpu);
12194 @@ -192,14 +192,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12195 extern int safe_smp_processor_id(void);
12196
12197 #elif defined(CONFIG_X86_64_SMP)
12198 -#define raw_smp_processor_id() (percpu_read(cpu_number))
12199 -
12200 -#define stack_smp_processor_id() \
12201 -({ \
12202 - struct thread_info *ti; \
12203 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12204 - ti->cpu; \
12205 -})
12206 +#define raw_smp_processor_id() (percpu_read(cpu_number))
12207 +#define stack_smp_processor_id() raw_smp_processor_id()
12208 #define safe_smp_processor_id() smp_processor_id()
12209
12210 #endif
12211 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12212 index 76bfa2c..12d3fe7 100644
12213 --- a/arch/x86/include/asm/spinlock.h
12214 +++ b/arch/x86/include/asm/spinlock.h
12215 @@ -175,6 +175,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12216 static inline void arch_read_lock(arch_rwlock_t *rw)
12217 {
12218 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12219 +
12220 +#ifdef CONFIG_PAX_REFCOUNT
12221 + "jno 0f\n"
12222 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12223 + "int $4\n0:\n"
12224 + _ASM_EXTABLE(0b, 0b)
12225 +#endif
12226 +
12227 "jns 1f\n"
12228 "call __read_lock_failed\n\t"
12229 "1:\n"
12230 @@ -184,6 +192,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12231 static inline void arch_write_lock(arch_rwlock_t *rw)
12232 {
12233 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12234 +
12235 +#ifdef CONFIG_PAX_REFCOUNT
12236 + "jno 0f\n"
12237 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12238 + "int $4\n0:\n"
12239 + _ASM_EXTABLE(0b, 0b)
12240 +#endif
12241 +
12242 "jz 1f\n"
12243 "call __write_lock_failed\n\t"
12244 "1:\n"
12245 @@ -213,13 +229,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12246
12247 static inline void arch_read_unlock(arch_rwlock_t *rw)
12248 {
12249 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12250 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12251 +
12252 +#ifdef CONFIG_PAX_REFCOUNT
12253 + "jno 0f\n"
12254 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12255 + "int $4\n0:\n"
12256 + _ASM_EXTABLE(0b, 0b)
12257 +#endif
12258 +
12259 :"+m" (rw->lock) : : "memory");
12260 }
12261
12262 static inline void arch_write_unlock(arch_rwlock_t *rw)
12263 {
12264 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12265 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12266 +
12267 +#ifdef CONFIG_PAX_REFCOUNT
12268 + "jno 0f\n"
12269 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12270 + "int $4\n0:\n"
12271 + _ASM_EXTABLE(0b, 0b)
12272 +#endif
12273 +
12274 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12275 }
12276
12277 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12278 index b5d9533..41655fa 100644
12279 --- a/arch/x86/include/asm/stackprotector.h
12280 +++ b/arch/x86/include/asm/stackprotector.h
12281 @@ -47,7 +47,7 @@
12282 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12283 */
12284 #define GDT_STACK_CANARY_INIT \
12285 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12286 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12287
12288 /*
12289 * Initialize the stackprotector canary value.
12290 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12291
12292 static inline void load_stack_canary_segment(void)
12293 {
12294 -#ifdef CONFIG_X86_32
12295 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12296 asm volatile ("mov %0, %%gs" : : "r" (0));
12297 #endif
12298 }
12299 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12300 index 70bbe39..4ae2bd4 100644
12301 --- a/arch/x86/include/asm/stacktrace.h
12302 +++ b/arch/x86/include/asm/stacktrace.h
12303 @@ -11,28 +11,20 @@
12304
12305 extern int kstack_depth_to_print;
12306
12307 -struct thread_info;
12308 +struct task_struct;
12309 struct stacktrace_ops;
12310
12311 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12312 - unsigned long *stack,
12313 - unsigned long bp,
12314 - const struct stacktrace_ops *ops,
12315 - void *data,
12316 - unsigned long *end,
12317 - int *graph);
12318 +typedef unsigned long walk_stack_t(struct task_struct *task,
12319 + void *stack_start,
12320 + unsigned long *stack,
12321 + unsigned long bp,
12322 + const struct stacktrace_ops *ops,
12323 + void *data,
12324 + unsigned long *end,
12325 + int *graph);
12326
12327 -extern unsigned long
12328 -print_context_stack(struct thread_info *tinfo,
12329 - unsigned long *stack, unsigned long bp,
12330 - const struct stacktrace_ops *ops, void *data,
12331 - unsigned long *end, int *graph);
12332 -
12333 -extern unsigned long
12334 -print_context_stack_bp(struct thread_info *tinfo,
12335 - unsigned long *stack, unsigned long bp,
12336 - const struct stacktrace_ops *ops, void *data,
12337 - unsigned long *end, int *graph);
12338 +extern walk_stack_t print_context_stack;
12339 +extern walk_stack_t print_context_stack_bp;
12340
12341 /* Generic stack tracer with callbacks */
12342
12343 @@ -40,7 +32,7 @@ struct stacktrace_ops {
12344 void (*address)(void *data, unsigned long address, int reliable);
12345 /* On negative return stop dumping */
12346 int (*stack)(void *data, char *name);
12347 - walk_stack_t walk_stack;
12348 + walk_stack_t *walk_stack;
12349 };
12350
12351 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12352 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12353 index 4ec45b3..a4f0a8a 100644
12354 --- a/arch/x86/include/asm/switch_to.h
12355 +++ b/arch/x86/include/asm/switch_to.h
12356 @@ -108,7 +108,7 @@ do { \
12357 "call __switch_to\n\t" \
12358 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12359 __switch_canary \
12360 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
12361 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12362 "movq %%rax,%%rdi\n\t" \
12363 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12364 "jnz ret_from_fork\n\t" \
12365 @@ -119,7 +119,7 @@ do { \
12366 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12367 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12368 [_tif_fork] "i" (_TIF_FORK), \
12369 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
12370 + [thread_info] "m" (current_tinfo), \
12371 [current_task] "m" (current_task) \
12372 __switch_canary_iparam \
12373 : "memory", "cc" __EXTRA_CLOBBER)
12374 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12375 index 3fda9db4..4ca1c61 100644
12376 --- a/arch/x86/include/asm/sys_ia32.h
12377 +++ b/arch/x86/include/asm/sys_ia32.h
12378 @@ -40,7 +40,7 @@ asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *,
12379 struct old_sigaction32 __user *);
12380 asmlinkage long sys32_alarm(unsigned int);
12381
12382 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12383 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12384 asmlinkage long sys32_sysfs(int, u32, u32);
12385
12386 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12387 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12388 index ad6df8c..5e0cf6e 100644
12389 --- a/arch/x86/include/asm/thread_info.h
12390 +++ b/arch/x86/include/asm/thread_info.h
12391 @@ -10,6 +10,7 @@
12392 #include <linux/compiler.h>
12393 #include <asm/page.h>
12394 #include <asm/types.h>
12395 +#include <asm/percpu.h>
12396
12397 /*
12398 * low level task data that entry.S needs immediate access to
12399 @@ -24,7 +25,6 @@ struct exec_domain;
12400 #include <linux/atomic.h>
12401
12402 struct thread_info {
12403 - struct task_struct *task; /* main task structure */
12404 struct exec_domain *exec_domain; /* execution domain */
12405 __u32 flags; /* low level flags */
12406 __u32 status; /* thread synchronous flags */
12407 @@ -34,19 +34,13 @@ struct thread_info {
12408 mm_segment_t addr_limit;
12409 struct restart_block restart_block;
12410 void __user *sysenter_return;
12411 -#ifdef CONFIG_X86_32
12412 - unsigned long previous_esp; /* ESP of the previous stack in
12413 - case of nested (IRQ) stacks
12414 - */
12415 - __u8 supervisor_stack[0];
12416 -#endif
12417 + unsigned long lowest_stack;
12418 unsigned int sig_on_uaccess_error:1;
12419 unsigned int uaccess_err:1; /* uaccess failed */
12420 };
12421
12422 -#define INIT_THREAD_INFO(tsk) \
12423 +#define INIT_THREAD_INFO \
12424 { \
12425 - .task = &tsk, \
12426 .exec_domain = &default_exec_domain, \
12427 .flags = 0, \
12428 .cpu = 0, \
12429 @@ -57,7 +51,7 @@ struct thread_info {
12430 }, \
12431 }
12432
12433 -#define init_thread_info (init_thread_union.thread_info)
12434 +#define init_thread_info (init_thread_union.stack)
12435 #define init_stack (init_thread_union.stack)
12436
12437 #else /* !__ASSEMBLY__ */
12438 @@ -97,6 +91,7 @@ struct thread_info {
12439 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12440 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12441 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12442 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12443
12444 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12445 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12446 @@ -120,16 +115,18 @@ struct thread_info {
12447 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12448 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12449 #define _TIF_X32 (1 << TIF_X32)
12450 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12451
12452 /* work to do in syscall_trace_enter() */
12453 #define _TIF_WORK_SYSCALL_ENTRY \
12454 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12455 - _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12456 + _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12457 + _TIF_GRSEC_SETXID)
12458
12459 /* work to do in syscall_trace_leave() */
12460 #define _TIF_WORK_SYSCALL_EXIT \
12461 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12462 - _TIF_SYSCALL_TRACEPOINT)
12463 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12464
12465 /* work to do on interrupt/exception return */
12466 #define _TIF_WORK_MASK \
12467 @@ -139,7 +136,8 @@ struct thread_info {
12468
12469 /* work to do on any return to user space */
12470 #define _TIF_ALLWORK_MASK \
12471 - ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12472 + ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12473 + _TIF_GRSEC_SETXID)
12474
12475 /* Only used for 64 bit */
12476 #define _TIF_DO_NOTIFY_MASK \
12477 @@ -173,45 +171,40 @@ struct thread_info {
12478 ret; \
12479 })
12480
12481 -#ifdef CONFIG_X86_32
12482 -
12483 -#define STACK_WARN (THREAD_SIZE/8)
12484 -/*
12485 - * macros/functions for gaining access to the thread information structure
12486 - *
12487 - * preempt_count needs to be 1 initially, until the scheduler is functional.
12488 - */
12489 -#ifndef __ASSEMBLY__
12490 -
12491 -
12492 -/* how to get the current stack pointer from C */
12493 -register unsigned long current_stack_pointer asm("esp") __used;
12494 -
12495 -/* how to get the thread information struct from C */
12496 -static inline struct thread_info *current_thread_info(void)
12497 -{
12498 - return (struct thread_info *)
12499 - (current_stack_pointer & ~(THREAD_SIZE - 1));
12500 -}
12501 -
12502 -#else /* !__ASSEMBLY__ */
12503 -
12504 +#ifdef __ASSEMBLY__
12505 /* how to get the thread information struct from ASM */
12506 #define GET_THREAD_INFO(reg) \
12507 - movl $-THREAD_SIZE, reg; \
12508 - andl %esp, reg
12509 + mov PER_CPU_VAR(current_tinfo), reg
12510
12511 /* use this one if reg already contains %esp */
12512 -#define GET_THREAD_INFO_WITH_ESP(reg) \
12513 - andl $-THREAD_SIZE, reg
12514 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12515 +#else
12516 +/* how to get the thread information struct from C */
12517 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12518 +
12519 +static __always_inline struct thread_info *current_thread_info(void)
12520 +{
12521 + return percpu_read_stable(current_tinfo);
12522 +}
12523 +#endif
12524 +
12525 +#ifdef CONFIG_X86_32
12526 +
12527 +#define STACK_WARN (THREAD_SIZE/8)
12528 +/*
12529 + * macros/functions for gaining access to the thread information structure
12530 + *
12531 + * preempt_count needs to be 1 initially, until the scheduler is functional.
12532 + */
12533 +#ifndef __ASSEMBLY__
12534 +
12535 +/* how to get the current stack pointer from C */
12536 +register unsigned long current_stack_pointer asm("esp") __used;
12537
12538 #endif
12539
12540 #else /* X86_32 */
12541
12542 -#include <asm/percpu.h>
12543 -#define KERNEL_STACK_OFFSET (5*8)
12544 -
12545 /*
12546 * macros/functions for gaining access to the thread information structure
12547 * preempt_count needs to be 1 initially, until the scheduler is functional.
12548 @@ -219,27 +212,8 @@ static inline struct thread_info *current_thread_info(void)
12549 #ifndef __ASSEMBLY__
12550 DECLARE_PER_CPU(unsigned long, kernel_stack);
12551
12552 -static inline struct thread_info *current_thread_info(void)
12553 -{
12554 - struct thread_info *ti;
12555 - ti = (void *)(percpu_read_stable(kernel_stack) +
12556 - KERNEL_STACK_OFFSET - THREAD_SIZE);
12557 - return ti;
12558 -}
12559 -
12560 -#else /* !__ASSEMBLY__ */
12561 -
12562 -/* how to get the thread information struct from ASM */
12563 -#define GET_THREAD_INFO(reg) \
12564 - movq PER_CPU_VAR(kernel_stack),reg ; \
12565 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12566 -
12567 -/*
12568 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12569 - * a certain register (to be used in assembler memory operands).
12570 - */
12571 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12572 -
12573 +/* how to get the current stack pointer from C */
12574 +register unsigned long current_stack_pointer asm("rsp") __used;
12575 #endif
12576
12577 #endif /* !X86_32 */
12578 @@ -285,5 +259,16 @@ extern void arch_task_cache_init(void);
12579 extern void free_thread_info(struct thread_info *ti);
12580 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12581 #define arch_task_cache_init arch_task_cache_init
12582 +
12583 +#define __HAVE_THREAD_FUNCTIONS
12584 +#define task_thread_info(task) (&(task)->tinfo)
12585 +#define task_stack_page(task) ((task)->stack)
12586 +#define setup_thread_stack(p, org) do {} while (0)
12587 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12588 +
12589 +#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
12590 +extern struct task_struct *alloc_task_struct_node(int node);
12591 +extern void free_task_struct(struct task_struct *);
12592 +
12593 #endif
12594 #endif /* _ASM_X86_THREAD_INFO_H */
12595 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12596 index e054459..14bc8a7 100644
12597 --- a/arch/x86/include/asm/uaccess.h
12598 +++ b/arch/x86/include/asm/uaccess.h
12599 @@ -7,12 +7,15 @@
12600 #include <linux/compiler.h>
12601 #include <linux/thread_info.h>
12602 #include <linux/string.h>
12603 +#include <linux/sched.h>
12604 #include <asm/asm.h>
12605 #include <asm/page.h>
12606
12607 #define VERIFY_READ 0
12608 #define VERIFY_WRITE 1
12609
12610 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12611 +
12612 /*
12613 * The fs value determines whether argument validity checking should be
12614 * performed or not. If get_fs() == USER_DS, checking is performed, with
12615 @@ -28,7 +31,12 @@
12616
12617 #define get_ds() (KERNEL_DS)
12618 #define get_fs() (current_thread_info()->addr_limit)
12619 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12620 +void __set_fs(mm_segment_t x);
12621 +void set_fs(mm_segment_t x);
12622 +#else
12623 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12624 +#endif
12625
12626 #define segment_eq(a, b) ((a).seg == (b).seg)
12627
12628 @@ -76,7 +84,33 @@
12629 * checks that the pointer is in the user space range - after calling
12630 * this function, memory access functions may still return -EFAULT.
12631 */
12632 -#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12633 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12634 +#define access_ok(type, addr, size) \
12635 +({ \
12636 + long __size = size; \
12637 + unsigned long __addr = (unsigned long)addr; \
12638 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12639 + unsigned long __end_ao = __addr + __size - 1; \
12640 + bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
12641 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12642 + while(__addr_ao <= __end_ao) { \
12643 + char __c_ao; \
12644 + __addr_ao += PAGE_SIZE; \
12645 + if (__size > PAGE_SIZE) \
12646 + cond_resched(); \
12647 + if (__get_user(__c_ao, (char __user *)__addr)) \
12648 + break; \
12649 + if (type != VERIFY_WRITE) { \
12650 + __addr = __addr_ao; \
12651 + continue; \
12652 + } \
12653 + if (__put_user(__c_ao, (char __user *)__addr)) \
12654 + break; \
12655 + __addr = __addr_ao; \
12656 + } \
12657 + } \
12658 + __ret_ao; \
12659 +})
12660
12661 /*
12662 * The exception table consists of pairs of addresses: the first is the
12663 @@ -182,12 +216,20 @@ extern int __get_user_bad(void);
12664 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12665 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12666
12667 -
12668 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12669 +#define __copyuser_seg "gs;"
12670 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12671 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12672 +#else
12673 +#define __copyuser_seg
12674 +#define __COPYUSER_SET_ES
12675 +#define __COPYUSER_RESTORE_ES
12676 +#endif
12677
12678 #ifdef CONFIG_X86_32
12679 #define __put_user_asm_u64(x, addr, err, errret) \
12680 - asm volatile("1: movl %%eax,0(%2)\n" \
12681 - "2: movl %%edx,4(%2)\n" \
12682 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12683 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12684 "3:\n" \
12685 ".section .fixup,\"ax\"\n" \
12686 "4: movl %3,%0\n" \
12687 @@ -199,8 +241,8 @@ extern int __get_user_bad(void);
12688 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12689
12690 #define __put_user_asm_ex_u64(x, addr) \
12691 - asm volatile("1: movl %%eax,0(%1)\n" \
12692 - "2: movl %%edx,4(%1)\n" \
12693 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12694 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12695 "3:\n" \
12696 _ASM_EXTABLE(1b, 2b - 1b) \
12697 _ASM_EXTABLE(2b, 3b - 2b) \
12698 @@ -252,7 +294,7 @@ extern void __put_user_8(void);
12699 __typeof__(*(ptr)) __pu_val; \
12700 __chk_user_ptr(ptr); \
12701 might_fault(); \
12702 - __pu_val = x; \
12703 + __pu_val = (x); \
12704 switch (sizeof(*(ptr))) { \
12705 case 1: \
12706 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12707 @@ -373,7 +415,7 @@ do { \
12708 } while (0)
12709
12710 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12711 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12712 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12713 "2:\n" \
12714 ".section .fixup,\"ax\"\n" \
12715 "3: mov %3,%0\n" \
12716 @@ -381,7 +423,7 @@ do { \
12717 " jmp 2b\n" \
12718 ".previous\n" \
12719 _ASM_EXTABLE(1b, 3b) \
12720 - : "=r" (err), ltype(x) \
12721 + : "=r" (err), ltype (x) \
12722 : "m" (__m(addr)), "i" (errret), "0" (err))
12723
12724 #define __get_user_size_ex(x, ptr, size) \
12725 @@ -406,7 +448,7 @@ do { \
12726 } while (0)
12727
12728 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12729 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12730 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12731 "2:\n" \
12732 _ASM_EXTABLE(1b, 2b - 1b) \
12733 : ltype(x) : "m" (__m(addr)))
12734 @@ -423,13 +465,24 @@ do { \
12735 int __gu_err; \
12736 unsigned long __gu_val; \
12737 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12738 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12739 + (x) = (__typeof__(*(ptr)))__gu_val; \
12740 __gu_err; \
12741 })
12742
12743 /* FIXME: this hack is definitely wrong -AK */
12744 struct __large_struct { unsigned long buf[100]; };
12745 -#define __m(x) (*(struct __large_struct __user *)(x))
12746 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12747 +#define ____m(x) \
12748 +({ \
12749 + unsigned long ____x = (unsigned long)(x); \
12750 + if (____x < PAX_USER_SHADOW_BASE) \
12751 + ____x += PAX_USER_SHADOW_BASE; \
12752 + (void __user *)____x; \
12753 +})
12754 +#else
12755 +#define ____m(x) (x)
12756 +#endif
12757 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12758
12759 /*
12760 * Tell gcc we read from memory instead of writing: this is because
12761 @@ -437,7 +490,7 @@ struct __large_struct { unsigned long buf[100]; };
12762 * aliasing issues.
12763 */
12764 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12765 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12766 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12767 "2:\n" \
12768 ".section .fixup,\"ax\"\n" \
12769 "3: mov %3,%0\n" \
12770 @@ -445,10 +498,10 @@ struct __large_struct { unsigned long buf[100]; };
12771 ".previous\n" \
12772 _ASM_EXTABLE(1b, 3b) \
12773 : "=r"(err) \
12774 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12775 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12776
12777 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12778 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12779 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12780 "2:\n" \
12781 _ASM_EXTABLE(1b, 2b - 1b) \
12782 : : ltype(x), "m" (__m(addr)))
12783 @@ -487,8 +540,12 @@ struct __large_struct { unsigned long buf[100]; };
12784 * On error, the variable @x is set to zero.
12785 */
12786
12787 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12788 +#define __get_user(x, ptr) get_user((x), (ptr))
12789 +#else
12790 #define __get_user(x, ptr) \
12791 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12792 +#endif
12793
12794 /**
12795 * __put_user: - Write a simple value into user space, with less checking.
12796 @@ -510,8 +567,12 @@ struct __large_struct { unsigned long buf[100]; };
12797 * Returns zero on success, or -EFAULT on error.
12798 */
12799
12800 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12801 +#define __put_user(x, ptr) put_user((x), (ptr))
12802 +#else
12803 #define __put_user(x, ptr) \
12804 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12805 +#endif
12806
12807 #define __get_user_unaligned __get_user
12808 #define __put_user_unaligned __put_user
12809 @@ -529,7 +590,7 @@ struct __large_struct { unsigned long buf[100]; };
12810 #define get_user_ex(x, ptr) do { \
12811 unsigned long __gue_val; \
12812 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12813 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12814 + (x) = (__typeof__(*(ptr)))__gue_val; \
12815 } while (0)
12816
12817 #ifdef CONFIG_X86_WP_WORKS_OK
12818 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12819 index 8084bc7..3d6ec37 100644
12820 --- a/arch/x86/include/asm/uaccess_32.h
12821 +++ b/arch/x86/include/asm/uaccess_32.h
12822 @@ -11,15 +11,15 @@
12823 #include <asm/page.h>
12824
12825 unsigned long __must_check __copy_to_user_ll
12826 - (void __user *to, const void *from, unsigned long n);
12827 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12828 unsigned long __must_check __copy_from_user_ll
12829 - (void *to, const void __user *from, unsigned long n);
12830 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12831 unsigned long __must_check __copy_from_user_ll_nozero
12832 - (void *to, const void __user *from, unsigned long n);
12833 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12834 unsigned long __must_check __copy_from_user_ll_nocache
12835 - (void *to, const void __user *from, unsigned long n);
12836 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12837 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12838 - (void *to, const void __user *from, unsigned long n);
12839 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12840
12841 /**
12842 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12843 @@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12844 static __always_inline unsigned long __must_check
12845 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12846 {
12847 + if ((long)n < 0)
12848 + return n;
12849 +
12850 if (__builtin_constant_p(n)) {
12851 unsigned long ret;
12852
12853 @@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12854 return ret;
12855 }
12856 }
12857 + if (!__builtin_constant_p(n))
12858 + check_object_size(from, n, true);
12859 return __copy_to_user_ll(to, from, n);
12860 }
12861
12862 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12863 __copy_to_user(void __user *to, const void *from, unsigned long n)
12864 {
12865 might_fault();
12866 +
12867 return __copy_to_user_inatomic(to, from, n);
12868 }
12869
12870 static __always_inline unsigned long
12871 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12872 {
12873 + if ((long)n < 0)
12874 + return n;
12875 +
12876 /* Avoid zeroing the tail if the copy fails..
12877 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12878 * but as the zeroing behaviour is only significant when n is not
12879 @@ -137,6 +146,10 @@ static __always_inline unsigned long
12880 __copy_from_user(void *to, const void __user *from, unsigned long n)
12881 {
12882 might_fault();
12883 +
12884 + if ((long)n < 0)
12885 + return n;
12886 +
12887 if (__builtin_constant_p(n)) {
12888 unsigned long ret;
12889
12890 @@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12891 return ret;
12892 }
12893 }
12894 + if (!__builtin_constant_p(n))
12895 + check_object_size(to, n, false);
12896 return __copy_from_user_ll(to, from, n);
12897 }
12898
12899 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12900 const void __user *from, unsigned long n)
12901 {
12902 might_fault();
12903 +
12904 + if ((long)n < 0)
12905 + return n;
12906 +
12907 if (__builtin_constant_p(n)) {
12908 unsigned long ret;
12909
12910 @@ -181,15 +200,19 @@ static __always_inline unsigned long
12911 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12912 unsigned long n)
12913 {
12914 - return __copy_from_user_ll_nocache_nozero(to, from, n);
12915 + if ((long)n < 0)
12916 + return n;
12917 +
12918 + return __copy_from_user_ll_nocache_nozero(to, from, n);
12919 }
12920
12921 -unsigned long __must_check copy_to_user(void __user *to,
12922 - const void *from, unsigned long n);
12923 -unsigned long __must_check _copy_from_user(void *to,
12924 - const void __user *from,
12925 - unsigned long n);
12926 -
12927 +extern void copy_to_user_overflow(void)
12928 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12929 + __compiletime_error("copy_to_user() buffer size is not provably correct")
12930 +#else
12931 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
12932 +#endif
12933 +;
12934
12935 extern void copy_from_user_overflow(void)
12936 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12937 @@ -199,17 +222,61 @@ extern void copy_from_user_overflow(void)
12938 #endif
12939 ;
12940
12941 -static inline unsigned long __must_check copy_from_user(void *to,
12942 - const void __user *from,
12943 - unsigned long n)
12944 +/**
12945 + * copy_to_user: - Copy a block of data into user space.
12946 + * @to: Destination address, in user space.
12947 + * @from: Source address, in kernel space.
12948 + * @n: Number of bytes to copy.
12949 + *
12950 + * Context: User context only. This function may sleep.
12951 + *
12952 + * Copy data from kernel space to user space.
12953 + *
12954 + * Returns number of bytes that could not be copied.
12955 + * On success, this will be zero.
12956 + */
12957 +static inline unsigned long __must_check
12958 +copy_to_user(void __user *to, const void *from, unsigned long n)
12959 {
12960 - int sz = __compiletime_object_size(to);
12961 + size_t sz = __compiletime_object_size(from);
12962
12963 - if (likely(sz == -1 || sz >= n))
12964 - n = _copy_from_user(to, from, n);
12965 - else
12966 + if (unlikely(sz != (size_t)-1 && sz < n))
12967 + copy_to_user_overflow();
12968 + else if (access_ok(VERIFY_WRITE, to, n))
12969 + n = __copy_to_user(to, from, n);
12970 + return n;
12971 +}
12972 +
12973 +/**
12974 + * copy_from_user: - Copy a block of data from user space.
12975 + * @to: Destination address, in kernel space.
12976 + * @from: Source address, in user space.
12977 + * @n: Number of bytes to copy.
12978 + *
12979 + * Context: User context only. This function may sleep.
12980 + *
12981 + * Copy data from user space to kernel space.
12982 + *
12983 + * Returns number of bytes that could not be copied.
12984 + * On success, this will be zero.
12985 + *
12986 + * If some data could not be copied, this function will pad the copied
12987 + * data to the requested size using zero bytes.
12988 + */
12989 +static inline unsigned long __must_check
12990 +copy_from_user(void *to, const void __user *from, unsigned long n)
12991 +{
12992 + size_t sz = __compiletime_object_size(to);
12993 +
12994 + if (unlikely(sz != (size_t)-1 && sz < n))
12995 copy_from_user_overflow();
12996 -
12997 + else if (access_ok(VERIFY_READ, from, n))
12998 + n = __copy_from_user(to, from, n);
12999 + else if ((long)n > 0) {
13000 + if (!__builtin_constant_p(n))
13001 + check_object_size(to, n, false);
13002 + memset(to, 0, n);
13003 + }
13004 return n;
13005 }
13006
13007 @@ -230,7 +297,7 @@ static inline unsigned long __must_check copy_from_user(void *to,
13008 #define strlen_user(str) strnlen_user(str, LONG_MAX)
13009
13010 long strnlen_user(const char __user *str, long n);
13011 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13012 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13013 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13014 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13015
13016 #endif /* _ASM_X86_UACCESS_32_H */
13017 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
13018 index fcd4b6f..ef04f8f 100644
13019 --- a/arch/x86/include/asm/uaccess_64.h
13020 +++ b/arch/x86/include/asm/uaccess_64.h
13021 @@ -10,6 +10,9 @@
13022 #include <asm/alternative.h>
13023 #include <asm/cpufeature.h>
13024 #include <asm/page.h>
13025 +#include <asm/pgtable.h>
13026 +
13027 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
13028
13029 /*
13030 * Copy To/From Userspace
13031 @@ -17,12 +20,14 @@
13032
13033 /* Handles exceptions in both to and from, but doesn't do access_ok */
13034 __must_check unsigned long
13035 -copy_user_generic_string(void *to, const void *from, unsigned len);
13036 +copy_user_generic_string(void *to, const void *from, unsigned long len) __size_overflow(3);
13037 __must_check unsigned long
13038 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13039 +copy_user_generic_unrolled(void *to, const void *from, unsigned long len) __size_overflow(3);
13040
13041 static __always_inline __must_check unsigned long
13042 -copy_user_generic(void *to, const void *from, unsigned len)
13043 +copy_user_generic(void *to, const void *from, unsigned long len) __size_overflow(3);
13044 +static __always_inline __must_check unsigned long
13045 +copy_user_generic(void *to, const void *from, unsigned long len)
13046 {
13047 unsigned ret;
13048
13049 @@ -32,142 +37,238 @@ copy_user_generic(void *to, const void *from, unsigned len)
13050 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13051 "=d" (len)),
13052 "1" (to), "2" (from), "3" (len)
13053 - : "memory", "rcx", "r8", "r9", "r10", "r11");
13054 + : "memory", "rcx", "r8", "r9", "r11");
13055 return ret;
13056 }
13057
13058 +static __always_inline __must_check unsigned long
13059 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13060 +static __always_inline __must_check unsigned long
13061 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13062 __must_check unsigned long
13063 -_copy_to_user(void __user *to, const void *from, unsigned len);
13064 -__must_check unsigned long
13065 -_copy_from_user(void *to, const void __user *from, unsigned len);
13066 -__must_check unsigned long
13067 -copy_in_user(void __user *to, const void __user *from, unsigned len);
13068 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13069 +
13070 +extern void copy_to_user_overflow(void)
13071 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13072 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13073 +#else
13074 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13075 +#endif
13076 +;
13077 +
13078 +extern void copy_from_user_overflow(void)
13079 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13080 + __compiletime_error("copy_from_user() buffer size is not provably correct")
13081 +#else
13082 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
13083 +#endif
13084 +;
13085
13086 static inline unsigned long __must_check copy_from_user(void *to,
13087 const void __user *from,
13088 unsigned long n)
13089 {
13090 - int sz = __compiletime_object_size(to);
13091 -
13092 might_fault();
13093 - if (likely(sz == -1 || sz >= n))
13094 - n = _copy_from_user(to, from, n);
13095 -#ifdef CONFIG_DEBUG_VM
13096 - else
13097 - WARN(1, "Buffer overflow detected!\n");
13098 -#endif
13099 +
13100 + if (access_ok(VERIFY_READ, from, n))
13101 + n = __copy_from_user(to, from, n);
13102 + else if (n < INT_MAX) {
13103 + if (!__builtin_constant_p(n))
13104 + check_object_size(to, n, false);
13105 + memset(to, 0, n);
13106 + }
13107 return n;
13108 }
13109
13110 static __always_inline __must_check
13111 -int copy_to_user(void __user *dst, const void *src, unsigned size)
13112 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
13113 {
13114 might_fault();
13115
13116 - return _copy_to_user(dst, src, size);
13117 + if (access_ok(VERIFY_WRITE, dst, size))
13118 + size = __copy_to_user(dst, src, size);
13119 + return size;
13120 }
13121
13122 static __always_inline __must_check
13123 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
13124 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13125 {
13126 - int ret = 0;
13127 + size_t sz = __compiletime_object_size(dst);
13128 + unsigned ret = 0;
13129
13130 might_fault();
13131 - if (!__builtin_constant_p(size))
13132 - return copy_user_generic(dst, (__force void *)src, size);
13133 +
13134 + if (size > INT_MAX)
13135 + return size;
13136 +
13137 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13138 + if (!__access_ok(VERIFY_READ, src, size))
13139 + return size;
13140 +#endif
13141 +
13142 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13143 + copy_from_user_overflow();
13144 + return size;
13145 + }
13146 +
13147 + if (!__builtin_constant_p(size)) {
13148 + check_object_size(dst, size, false);
13149 +
13150 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13151 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13152 + src += PAX_USER_SHADOW_BASE;
13153 +#endif
13154 +
13155 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13156 + }
13157 switch (size) {
13158 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13159 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13160 ret, "b", "b", "=q", 1);
13161 return ret;
13162 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13163 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13164 ret, "w", "w", "=r", 2);
13165 return ret;
13166 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13167 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13168 ret, "l", "k", "=r", 4);
13169 return ret;
13170 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13171 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13172 ret, "q", "", "=r", 8);
13173 return ret;
13174 case 10:
13175 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13176 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13177 ret, "q", "", "=r", 10);
13178 if (unlikely(ret))
13179 return ret;
13180 __get_user_asm(*(u16 *)(8 + (char *)dst),
13181 - (u16 __user *)(8 + (char __user *)src),
13182 + (const u16 __user *)(8 + (const char __user *)src),
13183 ret, "w", "w", "=r", 2);
13184 return ret;
13185 case 16:
13186 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13187 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13188 ret, "q", "", "=r", 16);
13189 if (unlikely(ret))
13190 return ret;
13191 __get_user_asm(*(u64 *)(8 + (char *)dst),
13192 - (u64 __user *)(8 + (char __user *)src),
13193 + (const u64 __user *)(8 + (const char __user *)src),
13194 ret, "q", "", "=r", 8);
13195 return ret;
13196 default:
13197 - return copy_user_generic(dst, (__force void *)src, size);
13198 +
13199 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13200 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13201 + src += PAX_USER_SHADOW_BASE;
13202 +#endif
13203 +
13204 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13205 }
13206 }
13207
13208 static __always_inline __must_check
13209 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
13210 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13211 {
13212 - int ret = 0;
13213 + size_t sz = __compiletime_object_size(src);
13214 + unsigned ret = 0;
13215
13216 might_fault();
13217 - if (!__builtin_constant_p(size))
13218 - return copy_user_generic((__force void *)dst, src, size);
13219 +
13220 + if (size > INT_MAX)
13221 + return size;
13222 +
13223 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13224 + if (!__access_ok(VERIFY_WRITE, dst, size))
13225 + return size;
13226 +#endif
13227 +
13228 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13229 + copy_to_user_overflow();
13230 + return size;
13231 + }
13232 +
13233 + if (!__builtin_constant_p(size)) {
13234 + check_object_size(src, size, true);
13235 +
13236 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13237 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13238 + dst += PAX_USER_SHADOW_BASE;
13239 +#endif
13240 +
13241 + return copy_user_generic((__force_kernel void *)dst, src, size);
13242 + }
13243 switch (size) {
13244 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13245 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13246 ret, "b", "b", "iq", 1);
13247 return ret;
13248 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13249 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13250 ret, "w", "w", "ir", 2);
13251 return ret;
13252 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13253 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13254 ret, "l", "k", "ir", 4);
13255 return ret;
13256 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13257 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13258 ret, "q", "", "er", 8);
13259 return ret;
13260 case 10:
13261 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13262 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13263 ret, "q", "", "er", 10);
13264 if (unlikely(ret))
13265 return ret;
13266 asm("":::"memory");
13267 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13268 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13269 ret, "w", "w", "ir", 2);
13270 return ret;
13271 case 16:
13272 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13273 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13274 ret, "q", "", "er", 16);
13275 if (unlikely(ret))
13276 return ret;
13277 asm("":::"memory");
13278 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13279 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13280 ret, "q", "", "er", 8);
13281 return ret;
13282 default:
13283 - return copy_user_generic((__force void *)dst, src, size);
13284 +
13285 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13286 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13287 + dst += PAX_USER_SHADOW_BASE;
13288 +#endif
13289 +
13290 + return copy_user_generic((__force_kernel void *)dst, src, size);
13291 }
13292 }
13293
13294 static __always_inline __must_check
13295 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13296 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13297 {
13298 - int ret = 0;
13299 + unsigned ret = 0;
13300
13301 might_fault();
13302 - if (!__builtin_constant_p(size))
13303 - return copy_user_generic((__force void *)dst,
13304 - (__force void *)src, size);
13305 +
13306 + if (size > INT_MAX)
13307 + return size;
13308 +
13309 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13310 + if (!__access_ok(VERIFY_READ, src, size))
13311 + return size;
13312 + if (!__access_ok(VERIFY_WRITE, dst, size))
13313 + return size;
13314 +#endif
13315 +
13316 + if (!__builtin_constant_p(size)) {
13317 +
13318 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13319 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13320 + src += PAX_USER_SHADOW_BASE;
13321 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13322 + dst += PAX_USER_SHADOW_BASE;
13323 +#endif
13324 +
13325 + return copy_user_generic((__force_kernel void *)dst,
13326 + (__force_kernel const void *)src, size);
13327 + }
13328 switch (size) {
13329 case 1: {
13330 u8 tmp;
13331 - __get_user_asm(tmp, (u8 __user *)src,
13332 + __get_user_asm(tmp, (const u8 __user *)src,
13333 ret, "b", "b", "=q", 1);
13334 if (likely(!ret))
13335 __put_user_asm(tmp, (u8 __user *)dst,
13336 @@ -176,7 +277,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13337 }
13338 case 2: {
13339 u16 tmp;
13340 - __get_user_asm(tmp, (u16 __user *)src,
13341 + __get_user_asm(tmp, (const u16 __user *)src,
13342 ret, "w", "w", "=r", 2);
13343 if (likely(!ret))
13344 __put_user_asm(tmp, (u16 __user *)dst,
13345 @@ -186,7 +287,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13346
13347 case 4: {
13348 u32 tmp;
13349 - __get_user_asm(tmp, (u32 __user *)src,
13350 + __get_user_asm(tmp, (const u32 __user *)src,
13351 ret, "l", "k", "=r", 4);
13352 if (likely(!ret))
13353 __put_user_asm(tmp, (u32 __user *)dst,
13354 @@ -195,7 +296,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13355 }
13356 case 8: {
13357 u64 tmp;
13358 - __get_user_asm(tmp, (u64 __user *)src,
13359 + __get_user_asm(tmp, (const u64 __user *)src,
13360 ret, "q", "", "=r", 8);
13361 if (likely(!ret))
13362 __put_user_asm(tmp, (u64 __user *)dst,
13363 @@ -203,47 +304,92 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13364 return ret;
13365 }
13366 default:
13367 - return copy_user_generic((__force void *)dst,
13368 - (__force void *)src, size);
13369 +
13370 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13371 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13372 + src += PAX_USER_SHADOW_BASE;
13373 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13374 + dst += PAX_USER_SHADOW_BASE;
13375 +#endif
13376 +
13377 + return copy_user_generic((__force_kernel void *)dst,
13378 + (__force_kernel const void *)src, size);
13379 }
13380 }
13381
13382 __must_check long strnlen_user(const char __user *str, long n);
13383 __must_check long __strnlen_user(const char __user *str, long n);
13384 __must_check long strlen_user(const char __user *str);
13385 -__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13386 -__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13387 +__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13388 +__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13389
13390 static __must_check __always_inline int
13391 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13392 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13393 {
13394 - return copy_user_generic(dst, (__force const void *)src, size);
13395 + if (size > INT_MAX)
13396 + return size;
13397 +
13398 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13399 + if (!__access_ok(VERIFY_READ, src, size))
13400 + return size;
13401 +
13402 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13403 + src += PAX_USER_SHADOW_BASE;
13404 +#endif
13405 +
13406 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13407 }
13408
13409 -static __must_check __always_inline int
13410 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13411 +static __must_check __always_inline unsigned long
13412 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13413 {
13414 - return copy_user_generic((__force void *)dst, src, size);
13415 + if (size > INT_MAX)
13416 + return size;
13417 +
13418 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13419 + if (!__access_ok(VERIFY_WRITE, dst, size))
13420 + return size;
13421 +
13422 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13423 + dst += PAX_USER_SHADOW_BASE;
13424 +#endif
13425 +
13426 + return copy_user_generic((__force_kernel void *)dst, src, size);
13427 }
13428
13429 -extern long __copy_user_nocache(void *dst, const void __user *src,
13430 - unsigned size, int zerorest);
13431 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13432 + unsigned long size, int zerorest) __size_overflow(3);
13433
13434 -static inline int
13435 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13436 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13437 {
13438 might_sleep();
13439 +
13440 + if (size > INT_MAX)
13441 + return size;
13442 +
13443 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13444 + if (!__access_ok(VERIFY_READ, src, size))
13445 + return size;
13446 +#endif
13447 +
13448 return __copy_user_nocache(dst, src, size, 1);
13449 }
13450
13451 -static inline int
13452 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13453 - unsigned size)
13454 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13455 + unsigned long size)
13456 {
13457 + if (size > INT_MAX)
13458 + return size;
13459 +
13460 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13461 + if (!__access_ok(VERIFY_READ, src, size))
13462 + return size;
13463 +#endif
13464 +
13465 return __copy_user_nocache(dst, src, size, 0);
13466 }
13467
13468 -unsigned long
13469 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13470 +extern unsigned long
13471 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13472
13473 #endif /* _ASM_X86_UACCESS_64_H */
13474 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13475 index bb05228..d763d5b 100644
13476 --- a/arch/x86/include/asm/vdso.h
13477 +++ b/arch/x86/include/asm/vdso.h
13478 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13479 #define VDSO32_SYMBOL(base, name) \
13480 ({ \
13481 extern const char VDSO32_##name[]; \
13482 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13483 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13484 })
13485 #endif
13486
13487 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13488 index 764b66a..ad3cfc8 100644
13489 --- a/arch/x86/include/asm/x86_init.h
13490 +++ b/arch/x86/include/asm/x86_init.h
13491 @@ -29,7 +29,7 @@ struct x86_init_mpparse {
13492 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13493 void (*find_smp_config)(void);
13494 void (*get_smp_config)(unsigned int early);
13495 -};
13496 +} __no_const;
13497
13498 /**
13499 * struct x86_init_resources - platform specific resource related ops
13500 @@ -43,7 +43,7 @@ struct x86_init_resources {
13501 void (*probe_roms)(void);
13502 void (*reserve_resources)(void);
13503 char *(*memory_setup)(void);
13504 -};
13505 +} __no_const;
13506
13507 /**
13508 * struct x86_init_irqs - platform specific interrupt setup
13509 @@ -56,7 +56,7 @@ struct x86_init_irqs {
13510 void (*pre_vector_init)(void);
13511 void (*intr_init)(void);
13512 void (*trap_init)(void);
13513 -};
13514 +} __no_const;
13515
13516 /**
13517 * struct x86_init_oem - oem platform specific customizing functions
13518 @@ -66,7 +66,7 @@ struct x86_init_irqs {
13519 struct x86_init_oem {
13520 void (*arch_setup)(void);
13521 void (*banner)(void);
13522 -};
13523 +} __no_const;
13524
13525 /**
13526 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13527 @@ -77,7 +77,7 @@ struct x86_init_oem {
13528 */
13529 struct x86_init_mapping {
13530 void (*pagetable_reserve)(u64 start, u64 end);
13531 -};
13532 +} __no_const;
13533
13534 /**
13535 * struct x86_init_paging - platform specific paging functions
13536 @@ -87,7 +87,7 @@ struct x86_init_mapping {
13537 struct x86_init_paging {
13538 void (*pagetable_setup_start)(pgd_t *base);
13539 void (*pagetable_setup_done)(pgd_t *base);
13540 -};
13541 +} __no_const;
13542
13543 /**
13544 * struct x86_init_timers - platform specific timer setup
13545 @@ -102,7 +102,7 @@ struct x86_init_timers {
13546 void (*tsc_pre_init)(void);
13547 void (*timer_init)(void);
13548 void (*wallclock_init)(void);
13549 -};
13550 +} __no_const;
13551
13552 /**
13553 * struct x86_init_iommu - platform specific iommu setup
13554 @@ -110,7 +110,7 @@ struct x86_init_timers {
13555 */
13556 struct x86_init_iommu {
13557 int (*iommu_init)(void);
13558 -};
13559 +} __no_const;
13560
13561 /**
13562 * struct x86_init_pci - platform specific pci init functions
13563 @@ -124,7 +124,7 @@ struct x86_init_pci {
13564 int (*init)(void);
13565 void (*init_irq)(void);
13566 void (*fixup_irqs)(void);
13567 -};
13568 +} __no_const;
13569
13570 /**
13571 * struct x86_init_ops - functions for platform specific setup
13572 @@ -140,7 +140,7 @@ struct x86_init_ops {
13573 struct x86_init_timers timers;
13574 struct x86_init_iommu iommu;
13575 struct x86_init_pci pci;
13576 -};
13577 +} __no_const;
13578
13579 /**
13580 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13581 @@ -151,7 +151,7 @@ struct x86_cpuinit_ops {
13582 void (*setup_percpu_clockev)(void);
13583 void (*early_percpu_clock_init)(void);
13584 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13585 -};
13586 +} __no_const;
13587
13588 /**
13589 * struct x86_platform_ops - platform specific runtime functions
13590 @@ -177,7 +177,7 @@ struct x86_platform_ops {
13591 int (*i8042_detect)(void);
13592 void (*save_sched_clock_state)(void);
13593 void (*restore_sched_clock_state)(void);
13594 -};
13595 +} __no_const;
13596
13597 struct pci_dev;
13598
13599 @@ -186,7 +186,7 @@ struct x86_msi_ops {
13600 void (*teardown_msi_irq)(unsigned int irq);
13601 void (*teardown_msi_irqs)(struct pci_dev *dev);
13602 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13603 -};
13604 +} __no_const;
13605
13606 extern struct x86_init_ops x86_init;
13607 extern struct x86_cpuinit_ops x86_cpuinit;
13608 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13609 index c6ce245..ffbdab7 100644
13610 --- a/arch/x86/include/asm/xsave.h
13611 +++ b/arch/x86/include/asm/xsave.h
13612 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13613 {
13614 int err;
13615
13616 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13617 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13618 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13619 +#endif
13620 +
13621 /*
13622 * Clear the xsave header first, so that reserved fields are
13623 * initialized to zero.
13624 @@ -96,10 +101,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13625 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13626 {
13627 int err;
13628 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13629 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13630 u32 lmask = mask;
13631 u32 hmask = mask >> 32;
13632
13633 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13634 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13635 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13636 +#endif
13637 +
13638 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13639 "2:\n"
13640 ".section .fixup,\"ax\"\n"
13641 diff --git a/arch/x86/kernel/acpi/realmode/Makefile b/arch/x86/kernel/acpi/realmode/Makefile
13642 index 6a564ac..9b1340c 100644
13643 --- a/arch/x86/kernel/acpi/realmode/Makefile
13644 +++ b/arch/x86/kernel/acpi/realmode/Makefile
13645 @@ -41,6 +41,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D_WAKEUP -D__KERNEL__ \
13646 $(call cc-option, -fno-stack-protector) \
13647 $(call cc-option, -mpreferred-stack-boundary=2)
13648 KBUILD_CFLAGS += $(call cc-option, -m32)
13649 +ifdef CONSTIFY_PLUGIN
13650 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
13651 +endif
13652 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13653 GCOV_PROFILE := n
13654
13655 diff --git a/arch/x86/kernel/acpi/realmode/wakeup.S b/arch/x86/kernel/acpi/realmode/wakeup.S
13656 index b4fd836..4358fe3 100644
13657 --- a/arch/x86/kernel/acpi/realmode/wakeup.S
13658 +++ b/arch/x86/kernel/acpi/realmode/wakeup.S
13659 @@ -108,6 +108,9 @@ wakeup_code:
13660 /* Do any other stuff... */
13661
13662 #ifndef CONFIG_64BIT
13663 + /* Recheck NX bit overrides (64bit path does this in trampoline */
13664 + call verify_cpu
13665 +
13666 /* This could also be done in C code... */
13667 movl pmode_cr3, %eax
13668 movl %eax, %cr3
13669 @@ -131,6 +134,7 @@ wakeup_code:
13670 movl pmode_cr0, %eax
13671 movl %eax, %cr0
13672 jmp pmode_return
13673 +# include "../../verify_cpu.S"
13674 #else
13675 pushw $0
13676 pushw trampoline_segment
13677 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13678 index 146a49c..1b5338b 100644
13679 --- a/arch/x86/kernel/acpi/sleep.c
13680 +++ b/arch/x86/kernel/acpi/sleep.c
13681 @@ -98,8 +98,12 @@ int acpi_suspend_lowlevel(void)
13682 header->trampoline_segment = trampoline_address() >> 4;
13683 #ifdef CONFIG_SMP
13684 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13685 +
13686 + pax_open_kernel();
13687 early_gdt_descr.address =
13688 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13689 + pax_close_kernel();
13690 +
13691 initial_gs = per_cpu_offset(smp_processor_id());
13692 #endif
13693 initial_code = (unsigned long)wakeup_long64;
13694 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13695 index 7261083..5c12053 100644
13696 --- a/arch/x86/kernel/acpi/wakeup_32.S
13697 +++ b/arch/x86/kernel/acpi/wakeup_32.S
13698 @@ -30,13 +30,11 @@ wakeup_pmode_return:
13699 # and restore the stack ... but you need gdt for this to work
13700 movl saved_context_esp, %esp
13701
13702 - movl %cs:saved_magic, %eax
13703 - cmpl $0x12345678, %eax
13704 + cmpl $0x12345678, saved_magic
13705 jne bogus_magic
13706
13707 # jump to place where we left off
13708 - movl saved_eip, %eax
13709 - jmp *%eax
13710 + jmp *(saved_eip)
13711
13712 bogus_magic:
13713 jmp bogus_magic
13714 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13715 index 1f84794..e23f862 100644
13716 --- a/arch/x86/kernel/alternative.c
13717 +++ b/arch/x86/kernel/alternative.c
13718 @@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13719 */
13720 for (a = start; a < end; a++) {
13721 instr = (u8 *)&a->instr_offset + a->instr_offset;
13722 +
13723 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13724 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13725 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13726 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13727 +#endif
13728 +
13729 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13730 BUG_ON(a->replacementlen > a->instrlen);
13731 BUG_ON(a->instrlen > sizeof(insnbuf));
13732 @@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13733 for (poff = start; poff < end; poff++) {
13734 u8 *ptr = (u8 *)poff + *poff;
13735
13736 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13737 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13738 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13739 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13740 +#endif
13741 +
13742 if (!*poff || ptr < text || ptr >= text_end)
13743 continue;
13744 /* turn DS segment override prefix into lock prefix */
13745 - if (*ptr == 0x3e)
13746 + if (*ktla_ktva(ptr) == 0x3e)
13747 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13748 };
13749 mutex_unlock(&text_mutex);
13750 @@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13751 for (poff = start; poff < end; poff++) {
13752 u8 *ptr = (u8 *)poff + *poff;
13753
13754 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13755 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13756 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13757 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13758 +#endif
13759 +
13760 if (!*poff || ptr < text || ptr >= text_end)
13761 continue;
13762 /* turn lock prefix into DS segment override prefix */
13763 - if (*ptr == 0xf0)
13764 + if (*ktla_ktva(ptr) == 0xf0)
13765 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13766 };
13767 mutex_unlock(&text_mutex);
13768 @@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13769
13770 BUG_ON(p->len > MAX_PATCH_LEN);
13771 /* prep the buffer with the original instructions */
13772 - memcpy(insnbuf, p->instr, p->len);
13773 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13774 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13775 (unsigned long)p->instr, p->len);
13776
13777 @@ -568,7 +587,7 @@ void __init alternative_instructions(void)
13778 if (smp_alt_once)
13779 free_init_pages("SMP alternatives",
13780 (unsigned long)__smp_locks,
13781 - (unsigned long)__smp_locks_end);
13782 + PAGE_ALIGN((unsigned long)__smp_locks_end));
13783
13784 restart_nmi();
13785 }
13786 @@ -585,13 +604,17 @@ void __init alternative_instructions(void)
13787 * instructions. And on the local CPU you need to be protected again NMI or MCE
13788 * handlers seeing an inconsistent instruction while you patch.
13789 */
13790 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
13791 +void *__kprobes text_poke_early(void *addr, const void *opcode,
13792 size_t len)
13793 {
13794 unsigned long flags;
13795 local_irq_save(flags);
13796 - memcpy(addr, opcode, len);
13797 +
13798 + pax_open_kernel();
13799 + memcpy(ktla_ktva(addr), opcode, len);
13800 sync_core();
13801 + pax_close_kernel();
13802 +
13803 local_irq_restore(flags);
13804 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13805 that causes hangs on some VIA CPUs. */
13806 @@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13807 */
13808 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13809 {
13810 - unsigned long flags;
13811 - char *vaddr;
13812 + unsigned char *vaddr = ktla_ktva(addr);
13813 struct page *pages[2];
13814 - int i;
13815 + size_t i;
13816
13817 if (!core_kernel_text((unsigned long)addr)) {
13818 - pages[0] = vmalloc_to_page(addr);
13819 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13820 + pages[0] = vmalloc_to_page(vaddr);
13821 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13822 } else {
13823 - pages[0] = virt_to_page(addr);
13824 + pages[0] = virt_to_page(vaddr);
13825 WARN_ON(!PageReserved(pages[0]));
13826 - pages[1] = virt_to_page(addr + PAGE_SIZE);
13827 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13828 }
13829 BUG_ON(!pages[0]);
13830 - local_irq_save(flags);
13831 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13832 - if (pages[1])
13833 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13834 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13835 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13836 - clear_fixmap(FIX_TEXT_POKE0);
13837 - if (pages[1])
13838 - clear_fixmap(FIX_TEXT_POKE1);
13839 - local_flush_tlb();
13840 - sync_core();
13841 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
13842 - that causes hangs on some VIA CPUs. */
13843 + text_poke_early(addr, opcode, len);
13844 for (i = 0; i < len; i++)
13845 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13846 - local_irq_restore(flags);
13847 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13848 return addr;
13849 }
13850
13851 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13852 index edc2448..553e7c5 100644
13853 --- a/arch/x86/kernel/apic/apic.c
13854 +++ b/arch/x86/kernel/apic/apic.c
13855 @@ -184,7 +184,7 @@ int first_system_vector = 0xfe;
13856 /*
13857 * Debug level, exported for io_apic.c
13858 */
13859 -unsigned int apic_verbosity;
13860 +int apic_verbosity;
13861
13862 int pic_mode;
13863
13864 @@ -1917,7 +1917,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13865 apic_write(APIC_ESR, 0);
13866 v1 = apic_read(APIC_ESR);
13867 ack_APIC_irq();
13868 - atomic_inc(&irq_err_count);
13869 + atomic_inc_unchecked(&irq_err_count);
13870
13871 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13872 smp_processor_id(), v0 , v1);
13873 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13874 index e88300d..cd5a87a 100644
13875 --- a/arch/x86/kernel/apic/io_apic.c
13876 +++ b/arch/x86/kernel/apic/io_apic.c
13877 @@ -83,7 +83,9 @@ static struct io_apic_ops io_apic_ops = {
13878
13879 void __init set_io_apic_ops(const struct io_apic_ops *ops)
13880 {
13881 - io_apic_ops = *ops;
13882 + pax_open_kernel();
13883 + memcpy((void*)&io_apic_ops, ops, sizeof io_apic_ops);
13884 + pax_close_kernel();
13885 }
13886
13887 /*
13888 @@ -1135,7 +1137,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13889 }
13890 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13891
13892 -void lock_vector_lock(void)
13893 +void lock_vector_lock(void) __acquires(vector_lock)
13894 {
13895 /* Used to the online set of cpus does not change
13896 * during assign_irq_vector.
13897 @@ -1143,7 +1145,7 @@ void lock_vector_lock(void)
13898 raw_spin_lock(&vector_lock);
13899 }
13900
13901 -void unlock_vector_lock(void)
13902 +void unlock_vector_lock(void) __releases(vector_lock)
13903 {
13904 raw_spin_unlock(&vector_lock);
13905 }
13906 @@ -2549,7 +2551,7 @@ static void ack_apic_edge(struct irq_data *data)
13907 ack_APIC_irq();
13908 }
13909
13910 -atomic_t irq_mis_count;
13911 +atomic_unchecked_t irq_mis_count;
13912
13913 #ifdef CONFIG_GENERIC_PENDING_IRQ
13914 static inline bool ioapic_irqd_mask(struct irq_data *data, struct irq_cfg *cfg)
13915 @@ -2667,7 +2669,7 @@ static void ack_apic_level(struct irq_data *data)
13916 * at the cpu.
13917 */
13918 if (!(v & (1 << (i & 0x1f)))) {
13919 - atomic_inc(&irq_mis_count);
13920 + atomic_inc_unchecked(&irq_mis_count);
13921
13922 eoi_ioapic_irq(irq, cfg);
13923 }
13924 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13925 index 459e78c..f037006 100644
13926 --- a/arch/x86/kernel/apm_32.c
13927 +++ b/arch/x86/kernel/apm_32.c
13928 @@ -410,7 +410,7 @@ static DEFINE_MUTEX(apm_mutex);
13929 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13930 * even though they are called in protected mode.
13931 */
13932 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13933 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13934 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13935
13936 static const char driver_version[] = "1.16ac"; /* no spaces */
13937 @@ -588,7 +588,10 @@ static long __apm_bios_call(void *_call)
13938 BUG_ON(cpu != 0);
13939 gdt = get_cpu_gdt_table(cpu);
13940 save_desc_40 = gdt[0x40 / 8];
13941 +
13942 + pax_open_kernel();
13943 gdt[0x40 / 8] = bad_bios_desc;
13944 + pax_close_kernel();
13945
13946 apm_irq_save(flags);
13947 APM_DO_SAVE_SEGS;
13948 @@ -597,7 +600,11 @@ static long __apm_bios_call(void *_call)
13949 &call->esi);
13950 APM_DO_RESTORE_SEGS;
13951 apm_irq_restore(flags);
13952 +
13953 + pax_open_kernel();
13954 gdt[0x40 / 8] = save_desc_40;
13955 + pax_close_kernel();
13956 +
13957 put_cpu();
13958
13959 return call->eax & 0xff;
13960 @@ -664,7 +671,10 @@ static long __apm_bios_call_simple(void *_call)
13961 BUG_ON(cpu != 0);
13962 gdt = get_cpu_gdt_table(cpu);
13963 save_desc_40 = gdt[0x40 / 8];
13964 +
13965 + pax_open_kernel();
13966 gdt[0x40 / 8] = bad_bios_desc;
13967 + pax_close_kernel();
13968
13969 apm_irq_save(flags);
13970 APM_DO_SAVE_SEGS;
13971 @@ -672,7 +682,11 @@ static long __apm_bios_call_simple(void *_call)
13972 &call->eax);
13973 APM_DO_RESTORE_SEGS;
13974 apm_irq_restore(flags);
13975 +
13976 + pax_open_kernel();
13977 gdt[0x40 / 8] = save_desc_40;
13978 + pax_close_kernel();
13979 +
13980 put_cpu();
13981 return error;
13982 }
13983 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
13984 * code to that CPU.
13985 */
13986 gdt = get_cpu_gdt_table(0);
13987 +
13988 + pax_open_kernel();
13989 set_desc_base(&gdt[APM_CS >> 3],
13990 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
13991 set_desc_base(&gdt[APM_CS_16 >> 3],
13992 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
13993 set_desc_base(&gdt[APM_DS >> 3],
13994 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
13995 + pax_close_kernel();
13996
13997 proc_create("apm", 0, NULL, &apm_file_ops);
13998
13999 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
14000 index 68de2dc..1f3c720 100644
14001 --- a/arch/x86/kernel/asm-offsets.c
14002 +++ b/arch/x86/kernel/asm-offsets.c
14003 @@ -33,6 +33,8 @@ void common(void) {
14004 OFFSET(TI_status, thread_info, status);
14005 OFFSET(TI_addr_limit, thread_info, addr_limit);
14006 OFFSET(TI_preempt_count, thread_info, preempt_count);
14007 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
14008 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
14009
14010 BLANK();
14011 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
14012 @@ -53,8 +55,26 @@ void common(void) {
14013 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
14014 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
14015 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
14016 +
14017 +#ifdef CONFIG_PAX_KERNEXEC
14018 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
14019 #endif
14020
14021 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14022 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
14023 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
14024 +#ifdef CONFIG_X86_64
14025 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
14026 +#endif
14027 +#endif
14028 +
14029 +#endif
14030 +
14031 + BLANK();
14032 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
14033 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
14034 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
14035 +
14036 #ifdef CONFIG_XEN
14037 BLANK();
14038 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14039 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14040 index 1b4754f..fbb4227 100644
14041 --- a/arch/x86/kernel/asm-offsets_64.c
14042 +++ b/arch/x86/kernel/asm-offsets_64.c
14043 @@ -76,6 +76,7 @@ int main(void)
14044 BLANK();
14045 #undef ENTRY
14046
14047 + DEFINE(TSS_size, sizeof(struct tss_struct));
14048 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14049 BLANK();
14050
14051 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14052 index 6ab6aa2..8f71507 100644
14053 --- a/arch/x86/kernel/cpu/Makefile
14054 +++ b/arch/x86/kernel/cpu/Makefile
14055 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14056 CFLAGS_REMOVE_perf_event.o = -pg
14057 endif
14058
14059 -# Make sure load_percpu_segment has no stackprotector
14060 -nostackp := $(call cc-option, -fno-stack-protector)
14061 -CFLAGS_common.o := $(nostackp)
14062 -
14063 obj-y := intel_cacheinfo.o scattered.o topology.o
14064 obj-y += proc.o capflags.o powerflags.o common.o
14065 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
14066 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14067 index 146bb62..ac9c74a 100644
14068 --- a/arch/x86/kernel/cpu/amd.c
14069 +++ b/arch/x86/kernel/cpu/amd.c
14070 @@ -691,7 +691,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14071 unsigned int size)
14072 {
14073 /* AMD errata T13 (order #21922) */
14074 - if ((c->x86 == 6)) {
14075 + if (c->x86 == 6) {
14076 /* Duron Rev A0 */
14077 if (c->x86_model == 3 && c->x86_mask == 0)
14078 size = 64;
14079 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14080 index cf79302..b1b28ae 100644
14081 --- a/arch/x86/kernel/cpu/common.c
14082 +++ b/arch/x86/kernel/cpu/common.c
14083 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14084
14085 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14086
14087 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14088 -#ifdef CONFIG_X86_64
14089 - /*
14090 - * We need valid kernel segments for data and code in long mode too
14091 - * IRET will check the segment types kkeil 2000/10/28
14092 - * Also sysret mandates a special GDT layout
14093 - *
14094 - * TLS descriptors are currently at a different place compared to i386.
14095 - * Hopefully nobody expects them at a fixed place (Wine?)
14096 - */
14097 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14098 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14099 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14100 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14101 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14102 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14103 -#else
14104 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14105 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14106 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14107 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14108 - /*
14109 - * Segments used for calling PnP BIOS have byte granularity.
14110 - * They code segments and data segments have fixed 64k limits,
14111 - * the transfer segment sizes are set at run time.
14112 - */
14113 - /* 32-bit code */
14114 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14115 - /* 16-bit code */
14116 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14117 - /* 16-bit data */
14118 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14119 - /* 16-bit data */
14120 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14121 - /* 16-bit data */
14122 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14123 - /*
14124 - * The APM segments have byte granularity and their bases
14125 - * are set at run time. All have 64k limits.
14126 - */
14127 - /* 32-bit code */
14128 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14129 - /* 16-bit code */
14130 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14131 - /* data */
14132 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14133 -
14134 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14135 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14136 - GDT_STACK_CANARY_INIT
14137 -#endif
14138 -} };
14139 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14140 -
14141 static int __init x86_xsave_setup(char *s)
14142 {
14143 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14144 @@ -374,7 +320,7 @@ void switch_to_new_gdt(int cpu)
14145 {
14146 struct desc_ptr gdt_descr;
14147
14148 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14149 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14150 gdt_descr.size = GDT_SIZE - 1;
14151 load_gdt(&gdt_descr);
14152 /* Reload the per-cpu base */
14153 @@ -841,6 +787,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14154 /* Filter out anything that depends on CPUID levels we don't have */
14155 filter_cpuid_features(c, true);
14156
14157 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14158 + setup_clear_cpu_cap(X86_FEATURE_SEP);
14159 +#endif
14160 +
14161 /* If the model name is still unset, do table lookup. */
14162 if (!c->x86_model_id[0]) {
14163 const char *p;
14164 @@ -1021,10 +971,12 @@ static __init int setup_disablecpuid(char *arg)
14165 }
14166 __setup("clearcpuid=", setup_disablecpuid);
14167
14168 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14169 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
14170 +
14171 #ifdef CONFIG_X86_64
14172 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14173 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14174 - (unsigned long) nmi_idt_table };
14175 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14176
14177 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14178 irq_stack_union) __aligned(PAGE_SIZE);
14179 @@ -1038,7 +990,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14180 EXPORT_PER_CPU_SYMBOL(current_task);
14181
14182 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14183 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14184 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14185 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14186
14187 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14188 @@ -1126,7 +1078,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14189 {
14190 memset(regs, 0, sizeof(struct pt_regs));
14191 regs->fs = __KERNEL_PERCPU;
14192 - regs->gs = __KERNEL_STACK_CANARY;
14193 + savesegment(gs, regs->gs);
14194
14195 return regs;
14196 }
14197 @@ -1181,7 +1133,7 @@ void __cpuinit cpu_init(void)
14198 int i;
14199
14200 cpu = stack_smp_processor_id();
14201 - t = &per_cpu(init_tss, cpu);
14202 + t = init_tss + cpu;
14203 oist = &per_cpu(orig_ist, cpu);
14204
14205 #ifdef CONFIG_NUMA
14206 @@ -1207,7 +1159,7 @@ void __cpuinit cpu_init(void)
14207 switch_to_new_gdt(cpu);
14208 loadsegment(fs, 0);
14209
14210 - load_idt((const struct desc_ptr *)&idt_descr);
14211 + load_idt(&idt_descr);
14212
14213 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14214 syscall_init();
14215 @@ -1216,7 +1168,6 @@ void __cpuinit cpu_init(void)
14216 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14217 barrier();
14218
14219 - x86_configure_nx();
14220 if (cpu != 0)
14221 enable_x2apic();
14222
14223 @@ -1272,7 +1223,7 @@ void __cpuinit cpu_init(void)
14224 {
14225 int cpu = smp_processor_id();
14226 struct task_struct *curr = current;
14227 - struct tss_struct *t = &per_cpu(init_tss, cpu);
14228 + struct tss_struct *t = init_tss + cpu;
14229 struct thread_struct *thread = &curr->thread;
14230
14231 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14232 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14233 index 3e6ff6c..54b4992 100644
14234 --- a/arch/x86/kernel/cpu/intel.c
14235 +++ b/arch/x86/kernel/cpu/intel.c
14236 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14237 * Update the IDT descriptor and reload the IDT so that
14238 * it uses the read-only mapped virtual address.
14239 */
14240 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14241 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14242 load_idt(&idt_descr);
14243 }
14244 #endif
14245 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14246 index 61604ae..98250a5 100644
14247 --- a/arch/x86/kernel/cpu/mcheck/mce.c
14248 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
14249 @@ -42,6 +42,7 @@
14250 #include <asm/processor.h>
14251 #include <asm/mce.h>
14252 #include <asm/msr.h>
14253 +#include <asm/local.h>
14254
14255 #include "mce-internal.h"
14256
14257 @@ -250,7 +251,7 @@ static void print_mce(struct mce *m)
14258 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14259 m->cs, m->ip);
14260
14261 - if (m->cs == __KERNEL_CS)
14262 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14263 print_symbol("{%s}", m->ip);
14264 pr_cont("\n");
14265 }
14266 @@ -283,10 +284,10 @@ static void print_mce(struct mce *m)
14267
14268 #define PANIC_TIMEOUT 5 /* 5 seconds */
14269
14270 -static atomic_t mce_paniced;
14271 +static atomic_unchecked_t mce_paniced;
14272
14273 static int fake_panic;
14274 -static atomic_t mce_fake_paniced;
14275 +static atomic_unchecked_t mce_fake_paniced;
14276
14277 /* Panic in progress. Enable interrupts and wait for final IPI */
14278 static void wait_for_panic(void)
14279 @@ -310,7 +311,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14280 /*
14281 * Make sure only one CPU runs in machine check panic
14282 */
14283 - if (atomic_inc_return(&mce_paniced) > 1)
14284 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14285 wait_for_panic();
14286 barrier();
14287
14288 @@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14289 console_verbose();
14290 } else {
14291 /* Don't log too much for fake panic */
14292 - if (atomic_inc_return(&mce_fake_paniced) > 1)
14293 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14294 return;
14295 }
14296 /* First print corrected ones that are still unlogged */
14297 @@ -684,7 +685,7 @@ static int mce_timed_out(u64 *t)
14298 * might have been modified by someone else.
14299 */
14300 rmb();
14301 - if (atomic_read(&mce_paniced))
14302 + if (atomic_read_unchecked(&mce_paniced))
14303 wait_for_panic();
14304 if (!monarch_timeout)
14305 goto out;
14306 @@ -1535,7 +1536,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14307 }
14308
14309 /* Call the installed machine check handler for this CPU setup. */
14310 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
14311 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14312 unexpected_machine_check;
14313
14314 /*
14315 @@ -1558,7 +1559,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14316 return;
14317 }
14318
14319 + pax_open_kernel();
14320 machine_check_vector = do_machine_check;
14321 + pax_close_kernel();
14322
14323 __mcheck_cpu_init_generic();
14324 __mcheck_cpu_init_vendor(c);
14325 @@ -1572,7 +1575,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14326 */
14327
14328 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14329 -static int mce_chrdev_open_count; /* #times opened */
14330 +static local_t mce_chrdev_open_count; /* #times opened */
14331 static int mce_chrdev_open_exclu; /* already open exclusive? */
14332
14333 static int mce_chrdev_open(struct inode *inode, struct file *file)
14334 @@ -1580,7 +1583,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14335 spin_lock(&mce_chrdev_state_lock);
14336
14337 if (mce_chrdev_open_exclu ||
14338 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14339 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14340 spin_unlock(&mce_chrdev_state_lock);
14341
14342 return -EBUSY;
14343 @@ -1588,7 +1591,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14344
14345 if (file->f_flags & O_EXCL)
14346 mce_chrdev_open_exclu = 1;
14347 - mce_chrdev_open_count++;
14348 + local_inc(&mce_chrdev_open_count);
14349
14350 spin_unlock(&mce_chrdev_state_lock);
14351
14352 @@ -1599,7 +1602,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14353 {
14354 spin_lock(&mce_chrdev_state_lock);
14355
14356 - mce_chrdev_open_count--;
14357 + local_dec(&mce_chrdev_open_count);
14358 mce_chrdev_open_exclu = 0;
14359
14360 spin_unlock(&mce_chrdev_state_lock);
14361 @@ -2324,7 +2327,7 @@ struct dentry *mce_get_debugfs_dir(void)
14362 static void mce_reset(void)
14363 {
14364 cpu_missing = 0;
14365 - atomic_set(&mce_fake_paniced, 0);
14366 + atomic_set_unchecked(&mce_fake_paniced, 0);
14367 atomic_set(&mce_executing, 0);
14368 atomic_set(&mce_callin, 0);
14369 atomic_set(&global_nwo, 0);
14370 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14371 index 2d5454c..51987eb 100644
14372 --- a/arch/x86/kernel/cpu/mcheck/p5.c
14373 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
14374 @@ -11,6 +11,7 @@
14375 #include <asm/processor.h>
14376 #include <asm/mce.h>
14377 #include <asm/msr.h>
14378 +#include <asm/pgtable.h>
14379
14380 /* By default disabled */
14381 int mce_p5_enabled __read_mostly;
14382 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14383 if (!cpu_has(c, X86_FEATURE_MCE))
14384 return;
14385
14386 + pax_open_kernel();
14387 machine_check_vector = pentium_machine_check;
14388 + pax_close_kernel();
14389 /* Make sure the vector pointer is visible before we enable MCEs: */
14390 wmb();
14391
14392 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14393 index 2d7998f..17c9de1 100644
14394 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
14395 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14396 @@ -10,6 +10,7 @@
14397 #include <asm/processor.h>
14398 #include <asm/mce.h>
14399 #include <asm/msr.h>
14400 +#include <asm/pgtable.h>
14401
14402 /* Machine check handler for WinChip C6: */
14403 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14404 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14405 {
14406 u32 lo, hi;
14407
14408 + pax_open_kernel();
14409 machine_check_vector = winchip_machine_check;
14410 + pax_close_kernel();
14411 /* Make sure the vector pointer is visible before we enable MCEs: */
14412 wmb();
14413
14414 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14415 index 6b96110..0da73eb 100644
14416 --- a/arch/x86/kernel/cpu/mtrr/main.c
14417 +++ b/arch/x86/kernel/cpu/mtrr/main.c
14418 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14419 u64 size_or_mask, size_and_mask;
14420 static bool mtrr_aps_delayed_init;
14421
14422 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14423 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14424
14425 const struct mtrr_ops *mtrr_if;
14426
14427 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14428 index df5e41f..816c719 100644
14429 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14430 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14431 @@ -25,7 +25,7 @@ struct mtrr_ops {
14432 int (*validate_add_page)(unsigned long base, unsigned long size,
14433 unsigned int type);
14434 int (*have_wrcomb)(void);
14435 -};
14436 +} __do_const;
14437
14438 extern int generic_get_free_region(unsigned long base, unsigned long size,
14439 int replace_reg);
14440 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14441 index bb8e034..fb9020b 100644
14442 --- a/arch/x86/kernel/cpu/perf_event.c
14443 +++ b/arch/x86/kernel/cpu/perf_event.c
14444 @@ -1835,7 +1835,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14445 break;
14446
14447 perf_callchain_store(entry, frame.return_address);
14448 - fp = frame.next_frame;
14449 + fp = (const void __force_user *)frame.next_frame;
14450 }
14451 }
14452
14453 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14454 index 13ad899..f642b9a 100644
14455 --- a/arch/x86/kernel/crash.c
14456 +++ b/arch/x86/kernel/crash.c
14457 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14458 {
14459 #ifdef CONFIG_X86_32
14460 struct pt_regs fixed_regs;
14461 -#endif
14462
14463 -#ifdef CONFIG_X86_32
14464 - if (!user_mode_vm(regs)) {
14465 + if (!user_mode(regs)) {
14466 crash_fixup_ss_esp(&fixed_regs, regs);
14467 regs = &fixed_regs;
14468 }
14469 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14470 index 37250fe..bf2ec74 100644
14471 --- a/arch/x86/kernel/doublefault_32.c
14472 +++ b/arch/x86/kernel/doublefault_32.c
14473 @@ -11,7 +11,7 @@
14474
14475 #define DOUBLEFAULT_STACKSIZE (1024)
14476 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14477 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14478 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14479
14480 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14481
14482 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
14483 unsigned long gdt, tss;
14484
14485 store_gdt(&gdt_desc);
14486 - gdt = gdt_desc.address;
14487 + gdt = (unsigned long)gdt_desc.address;
14488
14489 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14490
14491 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14492 /* 0x2 bit is always set */
14493 .flags = X86_EFLAGS_SF | 0x2,
14494 .sp = STACK_START,
14495 - .es = __USER_DS,
14496 + .es = __KERNEL_DS,
14497 .cs = __KERNEL_CS,
14498 .ss = __KERNEL_DS,
14499 - .ds = __USER_DS,
14500 + .ds = __KERNEL_DS,
14501 .fs = __KERNEL_PERCPU,
14502
14503 .__cr3 = __pa_nodebug(swapper_pg_dir),
14504 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14505 index 1b81839..0b4e7b0 100644
14506 --- a/arch/x86/kernel/dumpstack.c
14507 +++ b/arch/x86/kernel/dumpstack.c
14508 @@ -2,6 +2,9 @@
14509 * Copyright (C) 1991, 1992 Linus Torvalds
14510 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14511 */
14512 +#ifdef CONFIG_GRKERNSEC_HIDESYM
14513 +#define __INCLUDED_BY_HIDESYM 1
14514 +#endif
14515 #include <linux/kallsyms.h>
14516 #include <linux/kprobes.h>
14517 #include <linux/uaccess.h>
14518 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14519 static void
14520 print_ftrace_graph_addr(unsigned long addr, void *data,
14521 const struct stacktrace_ops *ops,
14522 - struct thread_info *tinfo, int *graph)
14523 + struct task_struct *task, int *graph)
14524 {
14525 - struct task_struct *task;
14526 unsigned long ret_addr;
14527 int index;
14528
14529 if (addr != (unsigned long)return_to_handler)
14530 return;
14531
14532 - task = tinfo->task;
14533 index = task->curr_ret_stack;
14534
14535 if (!task->ret_stack || index < *graph)
14536 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14537 static inline void
14538 print_ftrace_graph_addr(unsigned long addr, void *data,
14539 const struct stacktrace_ops *ops,
14540 - struct thread_info *tinfo, int *graph)
14541 + struct task_struct *task, int *graph)
14542 { }
14543 #endif
14544
14545 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14546 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14547 */
14548
14549 -static inline int valid_stack_ptr(struct thread_info *tinfo,
14550 - void *p, unsigned int size, void *end)
14551 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14552 {
14553 - void *t = tinfo;
14554 if (end) {
14555 if (p < end && p >= (end-THREAD_SIZE))
14556 return 1;
14557 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14558 }
14559
14560 unsigned long
14561 -print_context_stack(struct thread_info *tinfo,
14562 +print_context_stack(struct task_struct *task, void *stack_start,
14563 unsigned long *stack, unsigned long bp,
14564 const struct stacktrace_ops *ops, void *data,
14565 unsigned long *end, int *graph)
14566 {
14567 struct stack_frame *frame = (struct stack_frame *)bp;
14568
14569 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14570 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14571 unsigned long addr;
14572
14573 addr = *stack;
14574 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14575 } else {
14576 ops->address(data, addr, 0);
14577 }
14578 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14579 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14580 }
14581 stack++;
14582 }
14583 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14584 EXPORT_SYMBOL_GPL(print_context_stack);
14585
14586 unsigned long
14587 -print_context_stack_bp(struct thread_info *tinfo,
14588 +print_context_stack_bp(struct task_struct *task, void *stack_start,
14589 unsigned long *stack, unsigned long bp,
14590 const struct stacktrace_ops *ops, void *data,
14591 unsigned long *end, int *graph)
14592 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14593 struct stack_frame *frame = (struct stack_frame *)bp;
14594 unsigned long *ret_addr = &frame->return_address;
14595
14596 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14597 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14598 unsigned long addr = *ret_addr;
14599
14600 if (!__kernel_text_address(addr))
14601 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14602 ops->address(data, addr, 1);
14603 frame = frame->next_frame;
14604 ret_addr = &frame->return_address;
14605 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14606 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14607 }
14608
14609 return (unsigned long)frame;
14610 @@ -189,7 +188,7 @@ void dump_stack(void)
14611
14612 bp = stack_frame(current, NULL);
14613 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14614 - current->pid, current->comm, print_tainted(),
14615 + task_pid_nr(current), current->comm, print_tainted(),
14616 init_utsname()->release,
14617 (int)strcspn(init_utsname()->version, " "),
14618 init_utsname()->version);
14619 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14620 }
14621 EXPORT_SYMBOL_GPL(oops_begin);
14622
14623 +extern void gr_handle_kernel_exploit(void);
14624 +
14625 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14626 {
14627 if (regs && kexec_should_crash(current))
14628 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14629 panic("Fatal exception in interrupt");
14630 if (panic_on_oops)
14631 panic("Fatal exception");
14632 - do_exit(signr);
14633 +
14634 + gr_handle_kernel_exploit();
14635 +
14636 + do_group_exit(signr);
14637 }
14638
14639 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14640 @@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14641
14642 show_registers(regs);
14643 #ifdef CONFIG_X86_32
14644 - if (user_mode_vm(regs)) {
14645 + if (user_mode(regs)) {
14646 sp = regs->sp;
14647 ss = regs->ss & 0xffff;
14648 } else {
14649 @@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14650 unsigned long flags = oops_begin();
14651 int sig = SIGSEGV;
14652
14653 - if (!user_mode_vm(regs))
14654 + if (!user_mode(regs))
14655 report_bug(regs->ip, regs);
14656
14657 if (__die(str, regs, err))
14658 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14659 index 88ec912..e95e935 100644
14660 --- a/arch/x86/kernel/dumpstack_32.c
14661 +++ b/arch/x86/kernel/dumpstack_32.c
14662 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14663 bp = stack_frame(task, regs);
14664
14665 for (;;) {
14666 - struct thread_info *context;
14667 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14668
14669 - context = (struct thread_info *)
14670 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14671 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14672 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14673
14674 - stack = (unsigned long *)context->previous_esp;
14675 - if (!stack)
14676 + if (stack_start == task_stack_page(task))
14677 break;
14678 + stack = *(unsigned long **)stack_start;
14679 if (ops->stack(data, "IRQ") < 0)
14680 break;
14681 touch_nmi_watchdog();
14682 @@ -87,7 +85,7 @@ void show_registers(struct pt_regs *regs)
14683 int i;
14684
14685 print_modules();
14686 - __show_regs(regs, !user_mode_vm(regs));
14687 + __show_regs(regs, !user_mode(regs));
14688
14689 printk(KERN_EMERG "Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14690 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14691 @@ -96,21 +94,22 @@ void show_registers(struct pt_regs *regs)
14692 * When in-kernel, we also print out the stack and code at the
14693 * time of the fault..
14694 */
14695 - if (!user_mode_vm(regs)) {
14696 + if (!user_mode(regs)) {
14697 unsigned int code_prologue = code_bytes * 43 / 64;
14698 unsigned int code_len = code_bytes;
14699 unsigned char c;
14700 u8 *ip;
14701 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14702
14703 printk(KERN_EMERG "Stack:\n");
14704 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14705
14706 printk(KERN_EMERG "Code: ");
14707
14708 - ip = (u8 *)regs->ip - code_prologue;
14709 + ip = (u8 *)regs->ip - code_prologue + cs_base;
14710 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14711 /* try starting at IP */
14712 - ip = (u8 *)regs->ip;
14713 + ip = (u8 *)regs->ip + cs_base;
14714 code_len = code_len - code_prologue + 1;
14715 }
14716 for (i = 0; i < code_len; i++, ip++) {
14717 @@ -119,7 +118,7 @@ void show_registers(struct pt_regs *regs)
14718 printk(KERN_CONT " Bad EIP value.");
14719 break;
14720 }
14721 - if (ip == (u8 *)regs->ip)
14722 + if (ip == (u8 *)regs->ip + cs_base)
14723 printk(KERN_CONT "<%02x> ", c);
14724 else
14725 printk(KERN_CONT "%02x ", c);
14726 @@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
14727 {
14728 unsigned short ud2;
14729
14730 + ip = ktla_ktva(ip);
14731 if (ip < PAGE_OFFSET)
14732 return 0;
14733 if (probe_kernel_address((unsigned short *)ip, ud2))
14734 @@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
14735
14736 return ud2 == 0x0b0f;
14737 }
14738 +
14739 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14740 +void pax_check_alloca(unsigned long size)
14741 +{
14742 + unsigned long sp = (unsigned long)&sp, stack_left;
14743 +
14744 + /* all kernel stacks are of the same size */
14745 + stack_left = sp & (THREAD_SIZE - 1);
14746 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14747 +}
14748 +EXPORT_SYMBOL(pax_check_alloca);
14749 +#endif
14750 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14751 index 17107bd..9623722 100644
14752 --- a/arch/x86/kernel/dumpstack_64.c
14753 +++ b/arch/x86/kernel/dumpstack_64.c
14754 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14755 unsigned long *irq_stack_end =
14756 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14757 unsigned used = 0;
14758 - struct thread_info *tinfo;
14759 int graph = 0;
14760 unsigned long dummy;
14761 + void *stack_start;
14762
14763 if (!task)
14764 task = current;
14765 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14766 * current stack address. If the stacks consist of nested
14767 * exceptions
14768 */
14769 - tinfo = task_thread_info(task);
14770 for (;;) {
14771 char *id;
14772 unsigned long *estack_end;
14773 +
14774 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14775 &used, &id);
14776
14777 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14778 if (ops->stack(data, id) < 0)
14779 break;
14780
14781 - bp = ops->walk_stack(tinfo, stack, bp, ops,
14782 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14783 data, estack_end, &graph);
14784 ops->stack(data, "<EOE>");
14785 /*
14786 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14787 * second-to-last pointer (index -2 to end) in the
14788 * exception stack:
14789 */
14790 + if ((u16)estack_end[-1] != __KERNEL_DS)
14791 + goto out;
14792 stack = (unsigned long *) estack_end[-2];
14793 continue;
14794 }
14795 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14796 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14797 if (ops->stack(data, "IRQ") < 0)
14798 break;
14799 - bp = ops->walk_stack(tinfo, stack, bp,
14800 + bp = ops->walk_stack(task, irq_stack, stack, bp,
14801 ops, data, irq_stack_end, &graph);
14802 /*
14803 * We link to the next stack (which would be
14804 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14805 /*
14806 * This handles the process stack:
14807 */
14808 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14809 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14810 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14811 +out:
14812 put_cpu();
14813 }
14814 EXPORT_SYMBOL(dump_trace);
14815 @@ -305,3 +309,50 @@ int is_valid_bugaddr(unsigned long ip)
14816
14817 return ud2 == 0x0b0f;
14818 }
14819 +
14820 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14821 +void pax_check_alloca(unsigned long size)
14822 +{
14823 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14824 + unsigned cpu, used;
14825 + char *id;
14826 +
14827 + /* check the process stack first */
14828 + stack_start = (unsigned long)task_stack_page(current);
14829 + stack_end = stack_start + THREAD_SIZE;
14830 + if (likely(stack_start <= sp && sp < stack_end)) {
14831 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
14832 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14833 + return;
14834 + }
14835 +
14836 + cpu = get_cpu();
14837 +
14838 + /* check the irq stacks */
14839 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14840 + stack_start = stack_end - IRQ_STACK_SIZE;
14841 + if (stack_start <= sp && sp < stack_end) {
14842 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14843 + put_cpu();
14844 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14845 + return;
14846 + }
14847 +
14848 + /* check the exception stacks */
14849 + used = 0;
14850 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14851 + stack_start = stack_end - EXCEPTION_STKSZ;
14852 + if (stack_end && stack_start <= sp && sp < stack_end) {
14853 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14854 + put_cpu();
14855 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14856 + return;
14857 + }
14858 +
14859 + put_cpu();
14860 +
14861 + /* unknown stack */
14862 + BUG();
14863 +}
14864 +EXPORT_SYMBOL(pax_check_alloca);
14865 +#endif
14866 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14867 index 9b9f18b..9fcaa04 100644
14868 --- a/arch/x86/kernel/early_printk.c
14869 +++ b/arch/x86/kernel/early_printk.c
14870 @@ -7,6 +7,7 @@
14871 #include <linux/pci_regs.h>
14872 #include <linux/pci_ids.h>
14873 #include <linux/errno.h>
14874 +#include <linux/sched.h>
14875 #include <asm/io.h>
14876 #include <asm/processor.h>
14877 #include <asm/fcntl.h>
14878 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14879 index 7b784f4..db6b628 100644
14880 --- a/arch/x86/kernel/entry_32.S
14881 +++ b/arch/x86/kernel/entry_32.S
14882 @@ -179,13 +179,146 @@
14883 /*CFI_REL_OFFSET gs, PT_GS*/
14884 .endm
14885 .macro SET_KERNEL_GS reg
14886 +
14887 +#ifdef CONFIG_CC_STACKPROTECTOR
14888 movl $(__KERNEL_STACK_CANARY), \reg
14889 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14890 + movl $(__USER_DS), \reg
14891 +#else
14892 + xorl \reg, \reg
14893 +#endif
14894 +
14895 movl \reg, %gs
14896 .endm
14897
14898 #endif /* CONFIG_X86_32_LAZY_GS */
14899
14900 -.macro SAVE_ALL
14901 +.macro pax_enter_kernel
14902 +#ifdef CONFIG_PAX_KERNEXEC
14903 + call pax_enter_kernel
14904 +#endif
14905 +.endm
14906 +
14907 +.macro pax_exit_kernel
14908 +#ifdef CONFIG_PAX_KERNEXEC
14909 + call pax_exit_kernel
14910 +#endif
14911 +.endm
14912 +
14913 +#ifdef CONFIG_PAX_KERNEXEC
14914 +ENTRY(pax_enter_kernel)
14915 +#ifdef CONFIG_PARAVIRT
14916 + pushl %eax
14917 + pushl %ecx
14918 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
14919 + mov %eax, %esi
14920 +#else
14921 + mov %cr0, %esi
14922 +#endif
14923 + bts $16, %esi
14924 + jnc 1f
14925 + mov %cs, %esi
14926 + cmp $__KERNEL_CS, %esi
14927 + jz 3f
14928 + ljmp $__KERNEL_CS, $3f
14929 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
14930 +2:
14931 +#ifdef CONFIG_PARAVIRT
14932 + mov %esi, %eax
14933 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14934 +#else
14935 + mov %esi, %cr0
14936 +#endif
14937 +3:
14938 +#ifdef CONFIG_PARAVIRT
14939 + popl %ecx
14940 + popl %eax
14941 +#endif
14942 + ret
14943 +ENDPROC(pax_enter_kernel)
14944 +
14945 +ENTRY(pax_exit_kernel)
14946 +#ifdef CONFIG_PARAVIRT
14947 + pushl %eax
14948 + pushl %ecx
14949 +#endif
14950 + mov %cs, %esi
14951 + cmp $__KERNEXEC_KERNEL_CS, %esi
14952 + jnz 2f
14953 +#ifdef CONFIG_PARAVIRT
14954 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
14955 + mov %eax, %esi
14956 +#else
14957 + mov %cr0, %esi
14958 +#endif
14959 + btr $16, %esi
14960 + ljmp $__KERNEL_CS, $1f
14961 +1:
14962 +#ifdef CONFIG_PARAVIRT
14963 + mov %esi, %eax
14964 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
14965 +#else
14966 + mov %esi, %cr0
14967 +#endif
14968 +2:
14969 +#ifdef CONFIG_PARAVIRT
14970 + popl %ecx
14971 + popl %eax
14972 +#endif
14973 + ret
14974 +ENDPROC(pax_exit_kernel)
14975 +#endif
14976 +
14977 +.macro pax_erase_kstack
14978 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14979 + call pax_erase_kstack
14980 +#endif
14981 +.endm
14982 +
14983 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14984 +/*
14985 + * ebp: thread_info
14986 + * ecx, edx: can be clobbered
14987 + */
14988 +ENTRY(pax_erase_kstack)
14989 + pushl %edi
14990 + pushl %eax
14991 +
14992 + mov TI_lowest_stack(%ebp), %edi
14993 + mov $-0xBEEF, %eax
14994 + std
14995 +
14996 +1: mov %edi, %ecx
14997 + and $THREAD_SIZE_asm - 1, %ecx
14998 + shr $2, %ecx
14999 + repne scasl
15000 + jecxz 2f
15001 +
15002 + cmp $2*16, %ecx
15003 + jc 2f
15004 +
15005 + mov $2*16, %ecx
15006 + repe scasl
15007 + jecxz 2f
15008 + jne 1b
15009 +
15010 +2: cld
15011 + mov %esp, %ecx
15012 + sub %edi, %ecx
15013 + shr $2, %ecx
15014 + rep stosl
15015 +
15016 + mov TI_task_thread_sp0(%ebp), %edi
15017 + sub $128, %edi
15018 + mov %edi, TI_lowest_stack(%ebp)
15019 +
15020 + popl %eax
15021 + popl %edi
15022 + ret
15023 +ENDPROC(pax_erase_kstack)
15024 +#endif
15025 +
15026 +.macro __SAVE_ALL _DS
15027 cld
15028 PUSH_GS
15029 pushl_cfi %fs
15030 @@ -208,7 +341,7 @@
15031 CFI_REL_OFFSET ecx, 0
15032 pushl_cfi %ebx
15033 CFI_REL_OFFSET ebx, 0
15034 - movl $(__USER_DS), %edx
15035 + movl $\_DS, %edx
15036 movl %edx, %ds
15037 movl %edx, %es
15038 movl $(__KERNEL_PERCPU), %edx
15039 @@ -216,6 +349,15 @@
15040 SET_KERNEL_GS %edx
15041 .endm
15042
15043 +.macro SAVE_ALL
15044 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15045 + __SAVE_ALL __KERNEL_DS
15046 + pax_enter_kernel
15047 +#else
15048 + __SAVE_ALL __USER_DS
15049 +#endif
15050 +.endm
15051 +
15052 .macro RESTORE_INT_REGS
15053 popl_cfi %ebx
15054 CFI_RESTORE ebx
15055 @@ -301,7 +443,7 @@ ENTRY(ret_from_fork)
15056 popfl_cfi
15057 jmp syscall_exit
15058 CFI_ENDPROC
15059 -END(ret_from_fork)
15060 +ENDPROC(ret_from_fork)
15061
15062 /*
15063 * Interrupt exit functions should be protected against kprobes
15064 @@ -335,7 +477,15 @@ resume_userspace_sig:
15065 andl $SEGMENT_RPL_MASK, %eax
15066 #endif
15067 cmpl $USER_RPL, %eax
15068 +
15069 +#ifdef CONFIG_PAX_KERNEXEC
15070 + jae resume_userspace
15071 +
15072 + pax_exit_kernel
15073 + jmp resume_kernel
15074 +#else
15075 jb resume_kernel # not returning to v8086 or userspace
15076 +#endif
15077
15078 ENTRY(resume_userspace)
15079 LOCKDEP_SYS_EXIT
15080 @@ -347,8 +497,8 @@ ENTRY(resume_userspace)
15081 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15082 # int/exception return?
15083 jne work_pending
15084 - jmp restore_all
15085 -END(ret_from_exception)
15086 + jmp restore_all_pax
15087 +ENDPROC(ret_from_exception)
15088
15089 #ifdef CONFIG_PREEMPT
15090 ENTRY(resume_kernel)
15091 @@ -363,7 +513,7 @@ need_resched:
15092 jz restore_all
15093 call preempt_schedule_irq
15094 jmp need_resched
15095 -END(resume_kernel)
15096 +ENDPROC(resume_kernel)
15097 #endif
15098 CFI_ENDPROC
15099 /*
15100 @@ -397,23 +547,34 @@ sysenter_past_esp:
15101 /*CFI_REL_OFFSET cs, 0*/
15102 /*
15103 * Push current_thread_info()->sysenter_return to the stack.
15104 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15105 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
15106 */
15107 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15108 + pushl_cfi $0
15109 CFI_REL_OFFSET eip, 0
15110
15111 pushl_cfi %eax
15112 SAVE_ALL
15113 + GET_THREAD_INFO(%ebp)
15114 + movl TI_sysenter_return(%ebp),%ebp
15115 + movl %ebp,PT_EIP(%esp)
15116 ENABLE_INTERRUPTS(CLBR_NONE)
15117
15118 /*
15119 * Load the potential sixth argument from user stack.
15120 * Careful about security.
15121 */
15122 + movl PT_OLDESP(%esp),%ebp
15123 +
15124 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15125 + mov PT_OLDSS(%esp),%ds
15126 +1: movl %ds:(%ebp),%ebp
15127 + push %ss
15128 + pop %ds
15129 +#else
15130 cmpl $__PAGE_OFFSET-3,%ebp
15131 jae syscall_fault
15132 1: movl (%ebp),%ebp
15133 +#endif
15134 +
15135 movl %ebp,PT_EBP(%esp)
15136 .section __ex_table,"a"
15137 .align 4
15138 @@ -436,12 +597,24 @@ sysenter_do_call:
15139 testl $_TIF_ALLWORK_MASK, %ecx
15140 jne sysexit_audit
15141 sysenter_exit:
15142 +
15143 +#ifdef CONFIG_PAX_RANDKSTACK
15144 + pushl_cfi %eax
15145 + movl %esp, %eax
15146 + call pax_randomize_kstack
15147 + popl_cfi %eax
15148 +#endif
15149 +
15150 + pax_erase_kstack
15151 +
15152 /* if something modifies registers it must also disable sysexit */
15153 movl PT_EIP(%esp), %edx
15154 movl PT_OLDESP(%esp), %ecx
15155 xorl %ebp,%ebp
15156 TRACE_IRQS_ON
15157 1: mov PT_FS(%esp), %fs
15158 +2: mov PT_DS(%esp), %ds
15159 +3: mov PT_ES(%esp), %es
15160 PTGS_TO_GS
15161 ENABLE_INTERRUPTS_SYSEXIT
15162
15163 @@ -458,6 +631,9 @@ sysenter_audit:
15164 movl %eax,%edx /* 2nd arg: syscall number */
15165 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15166 call __audit_syscall_entry
15167 +
15168 + pax_erase_kstack
15169 +
15170 pushl_cfi %ebx
15171 movl PT_EAX(%esp),%eax /* reload syscall number */
15172 jmp sysenter_do_call
15173 @@ -483,11 +659,17 @@ sysexit_audit:
15174
15175 CFI_ENDPROC
15176 .pushsection .fixup,"ax"
15177 -2: movl $0,PT_FS(%esp)
15178 +4: movl $0,PT_FS(%esp)
15179 + jmp 1b
15180 +5: movl $0,PT_DS(%esp)
15181 + jmp 1b
15182 +6: movl $0,PT_ES(%esp)
15183 jmp 1b
15184 .section __ex_table,"a"
15185 .align 4
15186 - .long 1b,2b
15187 + .long 1b,4b
15188 + .long 2b,5b
15189 + .long 3b,6b
15190 .popsection
15191 PTGS_TO_GS_EX
15192 ENDPROC(ia32_sysenter_target)
15193 @@ -520,6 +702,15 @@ syscall_exit:
15194 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15195 jne syscall_exit_work
15196
15197 +restore_all_pax:
15198 +
15199 +#ifdef CONFIG_PAX_RANDKSTACK
15200 + movl %esp, %eax
15201 + call pax_randomize_kstack
15202 +#endif
15203 +
15204 + pax_erase_kstack
15205 +
15206 restore_all:
15207 TRACE_IRQS_IRET
15208 restore_all_notrace:
15209 @@ -579,14 +770,34 @@ ldt_ss:
15210 * compensating for the offset by changing to the ESPFIX segment with
15211 * a base address that matches for the difference.
15212 */
15213 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15214 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15215 mov %esp, %edx /* load kernel esp */
15216 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15217 mov %dx, %ax /* eax: new kernel esp */
15218 sub %eax, %edx /* offset (low word is 0) */
15219 +#ifdef CONFIG_SMP
15220 + movl PER_CPU_VAR(cpu_number), %ebx
15221 + shll $PAGE_SHIFT_asm, %ebx
15222 + addl $cpu_gdt_table, %ebx
15223 +#else
15224 + movl $cpu_gdt_table, %ebx
15225 +#endif
15226 shr $16, %edx
15227 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15228 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15229 +
15230 +#ifdef CONFIG_PAX_KERNEXEC
15231 + mov %cr0, %esi
15232 + btr $16, %esi
15233 + mov %esi, %cr0
15234 +#endif
15235 +
15236 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15237 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15238 +
15239 +#ifdef CONFIG_PAX_KERNEXEC
15240 + bts $16, %esi
15241 + mov %esi, %cr0
15242 +#endif
15243 +
15244 pushl_cfi $__ESPFIX_SS
15245 pushl_cfi %eax /* new kernel esp */
15246 /* Disable interrupts, but do not irqtrace this section: we
15247 @@ -615,38 +826,30 @@ work_resched:
15248 movl TI_flags(%ebp), %ecx
15249 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15250 # than syscall tracing?
15251 - jz restore_all
15252 + jz restore_all_pax
15253 testb $_TIF_NEED_RESCHED, %cl
15254 jnz work_resched
15255
15256 work_notifysig: # deal with pending signals and
15257 # notify-resume requests
15258 + movl %esp, %eax
15259 #ifdef CONFIG_VM86
15260 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15261 - movl %esp, %eax
15262 - jne work_notifysig_v86 # returning to kernel-space or
15263 + jz 1f # returning to kernel-space or
15264 # vm86-space
15265 - TRACE_IRQS_ON
15266 - ENABLE_INTERRUPTS(CLBR_NONE)
15267 - xorl %edx, %edx
15268 - call do_notify_resume
15269 - jmp resume_userspace_sig
15270
15271 - ALIGN
15272 -work_notifysig_v86:
15273 pushl_cfi %ecx # save ti_flags for do_notify_resume
15274 call save_v86_state # %eax contains pt_regs pointer
15275 popl_cfi %ecx
15276 movl %eax, %esp
15277 -#else
15278 - movl %esp, %eax
15279 +1:
15280 #endif
15281 TRACE_IRQS_ON
15282 ENABLE_INTERRUPTS(CLBR_NONE)
15283 xorl %edx, %edx
15284 call do_notify_resume
15285 jmp resume_userspace_sig
15286 -END(work_pending)
15287 +ENDPROC(work_pending)
15288
15289 # perform syscall exit tracing
15290 ALIGN
15291 @@ -654,11 +857,14 @@ syscall_trace_entry:
15292 movl $-ENOSYS,PT_EAX(%esp)
15293 movl %esp, %eax
15294 call syscall_trace_enter
15295 +
15296 + pax_erase_kstack
15297 +
15298 /* What it returned is what we'll actually use. */
15299 cmpl $(NR_syscalls), %eax
15300 jnae syscall_call
15301 jmp syscall_exit
15302 -END(syscall_trace_entry)
15303 +ENDPROC(syscall_trace_entry)
15304
15305 # perform syscall exit tracing
15306 ALIGN
15307 @@ -671,20 +877,24 @@ syscall_exit_work:
15308 movl %esp, %eax
15309 call syscall_trace_leave
15310 jmp resume_userspace
15311 -END(syscall_exit_work)
15312 +ENDPROC(syscall_exit_work)
15313 CFI_ENDPROC
15314
15315 RING0_INT_FRAME # can't unwind into user space anyway
15316 syscall_fault:
15317 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15318 + push %ss
15319 + pop %ds
15320 +#endif
15321 GET_THREAD_INFO(%ebp)
15322 movl $-EFAULT,PT_EAX(%esp)
15323 jmp resume_userspace
15324 -END(syscall_fault)
15325 +ENDPROC(syscall_fault)
15326
15327 syscall_badsys:
15328 movl $-ENOSYS,PT_EAX(%esp)
15329 jmp resume_userspace
15330 -END(syscall_badsys)
15331 +ENDPROC(syscall_badsys)
15332 CFI_ENDPROC
15333 /*
15334 * End of kprobes section
15335 @@ -756,6 +966,36 @@ ENTRY(ptregs_clone)
15336 CFI_ENDPROC
15337 ENDPROC(ptregs_clone)
15338
15339 + ALIGN;
15340 +ENTRY(kernel_execve)
15341 + CFI_STARTPROC
15342 + pushl_cfi %ebp
15343 + sub $PT_OLDSS+4,%esp
15344 + pushl_cfi %edi
15345 + pushl_cfi %ecx
15346 + pushl_cfi %eax
15347 + lea 3*4(%esp),%edi
15348 + mov $PT_OLDSS/4+1,%ecx
15349 + xorl %eax,%eax
15350 + rep stosl
15351 + popl_cfi %eax
15352 + popl_cfi %ecx
15353 + popl_cfi %edi
15354 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15355 + pushl_cfi %esp
15356 + call sys_execve
15357 + add $4,%esp
15358 + CFI_ADJUST_CFA_OFFSET -4
15359 + GET_THREAD_INFO(%ebp)
15360 + test %eax,%eax
15361 + jz syscall_exit
15362 + add $PT_OLDSS+4,%esp
15363 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15364 + popl_cfi %ebp
15365 + ret
15366 + CFI_ENDPROC
15367 +ENDPROC(kernel_execve)
15368 +
15369 .macro FIXUP_ESPFIX_STACK
15370 /*
15371 * Switch back for ESPFIX stack to the normal zerobased stack
15372 @@ -765,8 +1005,15 @@ ENDPROC(ptregs_clone)
15373 * normal stack and adjusts ESP with the matching offset.
15374 */
15375 /* fixup the stack */
15376 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15377 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15378 +#ifdef CONFIG_SMP
15379 + movl PER_CPU_VAR(cpu_number), %ebx
15380 + shll $PAGE_SHIFT_asm, %ebx
15381 + addl $cpu_gdt_table, %ebx
15382 +#else
15383 + movl $cpu_gdt_table, %ebx
15384 +#endif
15385 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15386 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15387 shl $16, %eax
15388 addl %esp, %eax /* the adjusted stack pointer */
15389 pushl_cfi $__KERNEL_DS
15390 @@ -819,7 +1066,7 @@ vector=vector+1
15391 .endr
15392 2: jmp common_interrupt
15393 .endr
15394 -END(irq_entries_start)
15395 +ENDPROC(irq_entries_start)
15396
15397 .previous
15398 END(interrupt)
15399 @@ -867,7 +1114,7 @@ ENTRY(coprocessor_error)
15400 pushl_cfi $do_coprocessor_error
15401 jmp error_code
15402 CFI_ENDPROC
15403 -END(coprocessor_error)
15404 +ENDPROC(coprocessor_error)
15405
15406 ENTRY(simd_coprocessor_error)
15407 RING0_INT_FRAME
15408 @@ -888,7 +1135,7 @@ ENTRY(simd_coprocessor_error)
15409 #endif
15410 jmp error_code
15411 CFI_ENDPROC
15412 -END(simd_coprocessor_error)
15413 +ENDPROC(simd_coprocessor_error)
15414
15415 ENTRY(device_not_available)
15416 RING0_INT_FRAME
15417 @@ -896,7 +1143,7 @@ ENTRY(device_not_available)
15418 pushl_cfi $do_device_not_available
15419 jmp error_code
15420 CFI_ENDPROC
15421 -END(device_not_available)
15422 +ENDPROC(device_not_available)
15423
15424 #ifdef CONFIG_PARAVIRT
15425 ENTRY(native_iret)
15426 @@ -905,12 +1152,12 @@ ENTRY(native_iret)
15427 .align 4
15428 .long native_iret, iret_exc
15429 .previous
15430 -END(native_iret)
15431 +ENDPROC(native_iret)
15432
15433 ENTRY(native_irq_enable_sysexit)
15434 sti
15435 sysexit
15436 -END(native_irq_enable_sysexit)
15437 +ENDPROC(native_irq_enable_sysexit)
15438 #endif
15439
15440 ENTRY(overflow)
15441 @@ -919,7 +1166,7 @@ ENTRY(overflow)
15442 pushl_cfi $do_overflow
15443 jmp error_code
15444 CFI_ENDPROC
15445 -END(overflow)
15446 +ENDPROC(overflow)
15447
15448 ENTRY(bounds)
15449 RING0_INT_FRAME
15450 @@ -927,7 +1174,7 @@ ENTRY(bounds)
15451 pushl_cfi $do_bounds
15452 jmp error_code
15453 CFI_ENDPROC
15454 -END(bounds)
15455 +ENDPROC(bounds)
15456
15457 ENTRY(invalid_op)
15458 RING0_INT_FRAME
15459 @@ -935,7 +1182,7 @@ ENTRY(invalid_op)
15460 pushl_cfi $do_invalid_op
15461 jmp error_code
15462 CFI_ENDPROC
15463 -END(invalid_op)
15464 +ENDPROC(invalid_op)
15465
15466 ENTRY(coprocessor_segment_overrun)
15467 RING0_INT_FRAME
15468 @@ -943,35 +1190,35 @@ ENTRY(coprocessor_segment_overrun)
15469 pushl_cfi $do_coprocessor_segment_overrun
15470 jmp error_code
15471 CFI_ENDPROC
15472 -END(coprocessor_segment_overrun)
15473 +ENDPROC(coprocessor_segment_overrun)
15474
15475 ENTRY(invalid_TSS)
15476 RING0_EC_FRAME
15477 pushl_cfi $do_invalid_TSS
15478 jmp error_code
15479 CFI_ENDPROC
15480 -END(invalid_TSS)
15481 +ENDPROC(invalid_TSS)
15482
15483 ENTRY(segment_not_present)
15484 RING0_EC_FRAME
15485 pushl_cfi $do_segment_not_present
15486 jmp error_code
15487 CFI_ENDPROC
15488 -END(segment_not_present)
15489 +ENDPROC(segment_not_present)
15490
15491 ENTRY(stack_segment)
15492 RING0_EC_FRAME
15493 pushl_cfi $do_stack_segment
15494 jmp error_code
15495 CFI_ENDPROC
15496 -END(stack_segment)
15497 +ENDPROC(stack_segment)
15498
15499 ENTRY(alignment_check)
15500 RING0_EC_FRAME
15501 pushl_cfi $do_alignment_check
15502 jmp error_code
15503 CFI_ENDPROC
15504 -END(alignment_check)
15505 +ENDPROC(alignment_check)
15506
15507 ENTRY(divide_error)
15508 RING0_INT_FRAME
15509 @@ -979,7 +1226,7 @@ ENTRY(divide_error)
15510 pushl_cfi $do_divide_error
15511 jmp error_code
15512 CFI_ENDPROC
15513 -END(divide_error)
15514 +ENDPROC(divide_error)
15515
15516 #ifdef CONFIG_X86_MCE
15517 ENTRY(machine_check)
15518 @@ -988,7 +1235,7 @@ ENTRY(machine_check)
15519 pushl_cfi machine_check_vector
15520 jmp error_code
15521 CFI_ENDPROC
15522 -END(machine_check)
15523 +ENDPROC(machine_check)
15524 #endif
15525
15526 ENTRY(spurious_interrupt_bug)
15527 @@ -997,7 +1244,7 @@ ENTRY(spurious_interrupt_bug)
15528 pushl_cfi $do_spurious_interrupt_bug
15529 jmp error_code
15530 CFI_ENDPROC
15531 -END(spurious_interrupt_bug)
15532 +ENDPROC(spurious_interrupt_bug)
15533 /*
15534 * End of kprobes section
15535 */
15536 @@ -1112,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15537
15538 ENTRY(mcount)
15539 ret
15540 -END(mcount)
15541 +ENDPROC(mcount)
15542
15543 ENTRY(ftrace_caller)
15544 cmpl $0, function_trace_stop
15545 @@ -1141,7 +1388,7 @@ ftrace_graph_call:
15546 .globl ftrace_stub
15547 ftrace_stub:
15548 ret
15549 -END(ftrace_caller)
15550 +ENDPROC(ftrace_caller)
15551
15552 #else /* ! CONFIG_DYNAMIC_FTRACE */
15553
15554 @@ -1177,7 +1424,7 @@ trace:
15555 popl %ecx
15556 popl %eax
15557 jmp ftrace_stub
15558 -END(mcount)
15559 +ENDPROC(mcount)
15560 #endif /* CONFIG_DYNAMIC_FTRACE */
15561 #endif /* CONFIG_FUNCTION_TRACER */
15562
15563 @@ -1198,7 +1445,7 @@ ENTRY(ftrace_graph_caller)
15564 popl %ecx
15565 popl %eax
15566 ret
15567 -END(ftrace_graph_caller)
15568 +ENDPROC(ftrace_graph_caller)
15569
15570 .globl return_to_handler
15571 return_to_handler:
15572 @@ -1253,15 +1500,18 @@ error_code:
15573 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15574 REG_TO_PTGS %ecx
15575 SET_KERNEL_GS %ecx
15576 - movl $(__USER_DS), %ecx
15577 + movl $(__KERNEL_DS), %ecx
15578 movl %ecx, %ds
15579 movl %ecx, %es
15580 +
15581 + pax_enter_kernel
15582 +
15583 TRACE_IRQS_OFF
15584 movl %esp,%eax # pt_regs pointer
15585 call *%edi
15586 jmp ret_from_exception
15587 CFI_ENDPROC
15588 -END(page_fault)
15589 +ENDPROC(page_fault)
15590
15591 /*
15592 * Debug traps and NMI can happen at the one SYSENTER instruction
15593 @@ -1303,7 +1553,7 @@ debug_stack_correct:
15594 call do_debug
15595 jmp ret_from_exception
15596 CFI_ENDPROC
15597 -END(debug)
15598 +ENDPROC(debug)
15599
15600 /*
15601 * NMI is doubly nasty. It can happen _while_ we're handling
15602 @@ -1340,6 +1590,9 @@ nmi_stack_correct:
15603 xorl %edx,%edx # zero error code
15604 movl %esp,%eax # pt_regs pointer
15605 call do_nmi
15606 +
15607 + pax_exit_kernel
15608 +
15609 jmp restore_all_notrace
15610 CFI_ENDPROC
15611
15612 @@ -1376,12 +1629,15 @@ nmi_espfix_stack:
15613 FIXUP_ESPFIX_STACK # %eax == %esp
15614 xorl %edx,%edx # zero error code
15615 call do_nmi
15616 +
15617 + pax_exit_kernel
15618 +
15619 RESTORE_REGS
15620 lss 12+4(%esp), %esp # back to espfix stack
15621 CFI_ADJUST_CFA_OFFSET -24
15622 jmp irq_return
15623 CFI_ENDPROC
15624 -END(nmi)
15625 +ENDPROC(nmi)
15626
15627 ENTRY(int3)
15628 RING0_INT_FRAME
15629 @@ -1393,14 +1649,14 @@ ENTRY(int3)
15630 call do_int3
15631 jmp ret_from_exception
15632 CFI_ENDPROC
15633 -END(int3)
15634 +ENDPROC(int3)
15635
15636 ENTRY(general_protection)
15637 RING0_EC_FRAME
15638 pushl_cfi $do_general_protection
15639 jmp error_code
15640 CFI_ENDPROC
15641 -END(general_protection)
15642 +ENDPROC(general_protection)
15643
15644 #ifdef CONFIG_KVM_GUEST
15645 ENTRY(async_page_fault)
15646 @@ -1408,7 +1664,7 @@ ENTRY(async_page_fault)
15647 pushl_cfi $do_async_page_fault
15648 jmp error_code
15649 CFI_ENDPROC
15650 -END(async_page_fault)
15651 +ENDPROC(async_page_fault)
15652 #endif
15653
15654 /*
15655 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15656 index cdc79b5..4710a75 100644
15657 --- a/arch/x86/kernel/entry_64.S
15658 +++ b/arch/x86/kernel/entry_64.S
15659 @@ -56,6 +56,8 @@
15660 #include <asm/ftrace.h>
15661 #include <asm/percpu.h>
15662 #include <linux/err.h>
15663 +#include <asm/pgtable.h>
15664 +#include <asm/alternative-asm.h>
15665
15666 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15667 #include <linux/elf-em.h>
15668 @@ -69,8 +71,9 @@
15669 #ifdef CONFIG_FUNCTION_TRACER
15670 #ifdef CONFIG_DYNAMIC_FTRACE
15671 ENTRY(mcount)
15672 + pax_force_retaddr
15673 retq
15674 -END(mcount)
15675 +ENDPROC(mcount)
15676
15677 ENTRY(ftrace_caller)
15678 cmpl $0, function_trace_stop
15679 @@ -93,8 +96,9 @@ GLOBAL(ftrace_graph_call)
15680 #endif
15681
15682 GLOBAL(ftrace_stub)
15683 + pax_force_retaddr
15684 retq
15685 -END(ftrace_caller)
15686 +ENDPROC(ftrace_caller)
15687
15688 #else /* ! CONFIG_DYNAMIC_FTRACE */
15689 ENTRY(mcount)
15690 @@ -113,6 +117,7 @@ ENTRY(mcount)
15691 #endif
15692
15693 GLOBAL(ftrace_stub)
15694 + pax_force_retaddr
15695 retq
15696
15697 trace:
15698 @@ -122,12 +127,13 @@ trace:
15699 movq 8(%rbp), %rsi
15700 subq $MCOUNT_INSN_SIZE, %rdi
15701
15702 + pax_force_fptr ftrace_trace_function
15703 call *ftrace_trace_function
15704
15705 MCOUNT_RESTORE_FRAME
15706
15707 jmp ftrace_stub
15708 -END(mcount)
15709 +ENDPROC(mcount)
15710 #endif /* CONFIG_DYNAMIC_FTRACE */
15711 #endif /* CONFIG_FUNCTION_TRACER */
15712
15713 @@ -147,8 +153,9 @@ ENTRY(ftrace_graph_caller)
15714
15715 MCOUNT_RESTORE_FRAME
15716
15717 + pax_force_retaddr
15718 retq
15719 -END(ftrace_graph_caller)
15720 +ENDPROC(ftrace_graph_caller)
15721
15722 GLOBAL(return_to_handler)
15723 subq $24, %rsp
15724 @@ -164,6 +171,7 @@ GLOBAL(return_to_handler)
15725 movq 8(%rsp), %rdx
15726 movq (%rsp), %rax
15727 addq $24, %rsp
15728 + pax_force_fptr %rdi
15729 jmp *%rdi
15730 #endif
15731
15732 @@ -179,6 +187,282 @@ ENTRY(native_usergs_sysret64)
15733 ENDPROC(native_usergs_sysret64)
15734 #endif /* CONFIG_PARAVIRT */
15735
15736 + .macro ljmpq sel, off
15737 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15738 + .byte 0x48; ljmp *1234f(%rip)
15739 + .pushsection .rodata
15740 + .align 16
15741 + 1234: .quad \off; .word \sel
15742 + .popsection
15743 +#else
15744 + pushq $\sel
15745 + pushq $\off
15746 + lretq
15747 +#endif
15748 + .endm
15749 +
15750 + .macro pax_enter_kernel
15751 + pax_set_fptr_mask
15752 +#ifdef CONFIG_PAX_KERNEXEC
15753 + call pax_enter_kernel
15754 +#endif
15755 + .endm
15756 +
15757 + .macro pax_exit_kernel
15758 +#ifdef CONFIG_PAX_KERNEXEC
15759 + call pax_exit_kernel
15760 +#endif
15761 + .endm
15762 +
15763 +#ifdef CONFIG_PAX_KERNEXEC
15764 +ENTRY(pax_enter_kernel)
15765 + pushq %rdi
15766 +
15767 +#ifdef CONFIG_PARAVIRT
15768 + PV_SAVE_REGS(CLBR_RDI)
15769 +#endif
15770 +
15771 + GET_CR0_INTO_RDI
15772 + bts $16,%rdi
15773 + jnc 3f
15774 + mov %cs,%edi
15775 + cmp $__KERNEL_CS,%edi
15776 + jnz 2f
15777 +1:
15778 +
15779 +#ifdef CONFIG_PARAVIRT
15780 + PV_RESTORE_REGS(CLBR_RDI)
15781 +#endif
15782 +
15783 + popq %rdi
15784 + pax_force_retaddr
15785 + retq
15786 +
15787 +2: ljmpq __KERNEL_CS,1f
15788 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
15789 +4: SET_RDI_INTO_CR0
15790 + jmp 1b
15791 +ENDPROC(pax_enter_kernel)
15792 +
15793 +ENTRY(pax_exit_kernel)
15794 + pushq %rdi
15795 +
15796 +#ifdef CONFIG_PARAVIRT
15797 + PV_SAVE_REGS(CLBR_RDI)
15798 +#endif
15799 +
15800 + mov %cs,%rdi
15801 + cmp $__KERNEXEC_KERNEL_CS,%edi
15802 + jz 2f
15803 +1:
15804 +
15805 +#ifdef CONFIG_PARAVIRT
15806 + PV_RESTORE_REGS(CLBR_RDI);
15807 +#endif
15808 +
15809 + popq %rdi
15810 + pax_force_retaddr
15811 + retq
15812 +
15813 +2: GET_CR0_INTO_RDI
15814 + btr $16,%rdi
15815 + ljmpq __KERNEL_CS,3f
15816 +3: SET_RDI_INTO_CR0
15817 + jmp 1b
15818 +#ifdef CONFIG_PARAVIRT
15819 + PV_RESTORE_REGS(CLBR_RDI);
15820 +#endif
15821 +
15822 + popq %rdi
15823 + pax_force_retaddr
15824 + retq
15825 +ENDPROC(pax_exit_kernel)
15826 +#endif
15827 +
15828 + .macro pax_enter_kernel_user
15829 + pax_set_fptr_mask
15830 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15831 + call pax_enter_kernel_user
15832 +#endif
15833 + .endm
15834 +
15835 + .macro pax_exit_kernel_user
15836 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15837 + call pax_exit_kernel_user
15838 +#endif
15839 +#ifdef CONFIG_PAX_RANDKSTACK
15840 + pushq %rax
15841 + call pax_randomize_kstack
15842 + popq %rax
15843 +#endif
15844 + .endm
15845 +
15846 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15847 +ENTRY(pax_enter_kernel_user)
15848 + pushq %rdi
15849 + pushq %rbx
15850 +
15851 +#ifdef CONFIG_PARAVIRT
15852 + PV_SAVE_REGS(CLBR_RDI)
15853 +#endif
15854 +
15855 + GET_CR3_INTO_RDI
15856 + mov %rdi,%rbx
15857 + add $__START_KERNEL_map,%rbx
15858 + sub phys_base(%rip),%rbx
15859 +
15860 +#ifdef CONFIG_PARAVIRT
15861 + pushq %rdi
15862 + cmpl $0, pv_info+PARAVIRT_enabled
15863 + jz 1f
15864 + i = 0
15865 + .rept USER_PGD_PTRS
15866 + mov i*8(%rbx),%rsi
15867 + mov $0,%sil
15868 + lea i*8(%rbx),%rdi
15869 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15870 + i = i + 1
15871 + .endr
15872 + jmp 2f
15873 +1:
15874 +#endif
15875 +
15876 + i = 0
15877 + .rept USER_PGD_PTRS
15878 + movb $0,i*8(%rbx)
15879 + i = i + 1
15880 + .endr
15881 +
15882 +#ifdef CONFIG_PARAVIRT
15883 +2: popq %rdi
15884 +#endif
15885 + SET_RDI_INTO_CR3
15886 +
15887 +#ifdef CONFIG_PAX_KERNEXEC
15888 + GET_CR0_INTO_RDI
15889 + bts $16,%rdi
15890 + SET_RDI_INTO_CR0
15891 +#endif
15892 +
15893 +#ifdef CONFIG_PARAVIRT
15894 + PV_RESTORE_REGS(CLBR_RDI)
15895 +#endif
15896 +
15897 + popq %rbx
15898 + popq %rdi
15899 + pax_force_retaddr
15900 + retq
15901 +ENDPROC(pax_enter_kernel_user)
15902 +
15903 +ENTRY(pax_exit_kernel_user)
15904 + push %rdi
15905 +
15906 +#ifdef CONFIG_PARAVIRT
15907 + pushq %rbx
15908 + PV_SAVE_REGS(CLBR_RDI)
15909 +#endif
15910 +
15911 +#ifdef CONFIG_PAX_KERNEXEC
15912 + GET_CR0_INTO_RDI
15913 + btr $16,%rdi
15914 + SET_RDI_INTO_CR0
15915 +#endif
15916 +
15917 + GET_CR3_INTO_RDI
15918 + add $__START_KERNEL_map,%rdi
15919 + sub phys_base(%rip),%rdi
15920 +
15921 +#ifdef CONFIG_PARAVIRT
15922 + cmpl $0, pv_info+PARAVIRT_enabled
15923 + jz 1f
15924 + mov %rdi,%rbx
15925 + i = 0
15926 + .rept USER_PGD_PTRS
15927 + mov i*8(%rbx),%rsi
15928 + mov $0x67,%sil
15929 + lea i*8(%rbx),%rdi
15930 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15931 + i = i + 1
15932 + .endr
15933 + jmp 2f
15934 +1:
15935 +#endif
15936 +
15937 + i = 0
15938 + .rept USER_PGD_PTRS
15939 + movb $0x67,i*8(%rdi)
15940 + i = i + 1
15941 + .endr
15942 +
15943 +#ifdef CONFIG_PARAVIRT
15944 +2: PV_RESTORE_REGS(CLBR_RDI)
15945 + popq %rbx
15946 +#endif
15947 +
15948 + popq %rdi
15949 + pax_force_retaddr
15950 + retq
15951 +ENDPROC(pax_exit_kernel_user)
15952 +#endif
15953 +
15954 +.macro pax_erase_kstack
15955 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15956 + call pax_erase_kstack
15957 +#endif
15958 +.endm
15959 +
15960 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15961 +/*
15962 + * r11: thread_info
15963 + * rcx, rdx: can be clobbered
15964 + */
15965 +ENTRY(pax_erase_kstack)
15966 + pushq %rdi
15967 + pushq %rax
15968 + pushq %r11
15969 +
15970 + GET_THREAD_INFO(%r11)
15971 + mov TI_lowest_stack(%r11), %rdi
15972 + mov $-0xBEEF, %rax
15973 + std
15974 +
15975 +1: mov %edi, %ecx
15976 + and $THREAD_SIZE_asm - 1, %ecx
15977 + shr $3, %ecx
15978 + repne scasq
15979 + jecxz 2f
15980 +
15981 + cmp $2*8, %ecx
15982 + jc 2f
15983 +
15984 + mov $2*8, %ecx
15985 + repe scasq
15986 + jecxz 2f
15987 + jne 1b
15988 +
15989 +2: cld
15990 + mov %esp, %ecx
15991 + sub %edi, %ecx
15992 +
15993 + cmp $THREAD_SIZE_asm, %rcx
15994 + jb 3f
15995 + ud2
15996 +3:
15997 +
15998 + shr $3, %ecx
15999 + rep stosq
16000 +
16001 + mov TI_task_thread_sp0(%r11), %rdi
16002 + sub $256, %rdi
16003 + mov %rdi, TI_lowest_stack(%r11)
16004 +
16005 + popq %r11
16006 + popq %rax
16007 + popq %rdi
16008 + pax_force_retaddr
16009 + ret
16010 +ENDPROC(pax_erase_kstack)
16011 +#endif
16012
16013 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
16014 #ifdef CONFIG_TRACE_IRQFLAGS
16015 @@ -232,8 +516,8 @@ ENDPROC(native_usergs_sysret64)
16016 .endm
16017
16018 .macro UNFAKE_STACK_FRAME
16019 - addq $8*6, %rsp
16020 - CFI_ADJUST_CFA_OFFSET -(6*8)
16021 + addq $8*6 + ARG_SKIP, %rsp
16022 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
16023 .endm
16024
16025 /*
16026 @@ -320,7 +604,7 @@ ENDPROC(native_usergs_sysret64)
16027 movq %rsp, %rsi
16028
16029 leaq -RBP(%rsp),%rdi /* arg1 for handler */
16030 - testl $3, CS-RBP(%rsi)
16031 + testb $3, CS-RBP(%rsi)
16032 je 1f
16033 SWAPGS
16034 /*
16035 @@ -355,9 +639,10 @@ ENTRY(save_rest)
16036 movq_cfi r15, R15+16
16037 movq %r11, 8(%rsp) /* return address */
16038 FIXUP_TOP_OF_STACK %r11, 16
16039 + pax_force_retaddr
16040 ret
16041 CFI_ENDPROC
16042 -END(save_rest)
16043 +ENDPROC(save_rest)
16044
16045 /* save complete stack frame */
16046 .pushsection .kprobes.text, "ax"
16047 @@ -386,9 +671,10 @@ ENTRY(save_paranoid)
16048 js 1f /* negative -> in kernel */
16049 SWAPGS
16050 xorl %ebx,%ebx
16051 -1: ret
16052 +1: pax_force_retaddr_bts
16053 + ret
16054 CFI_ENDPROC
16055 -END(save_paranoid)
16056 +ENDPROC(save_paranoid)
16057 .popsection
16058
16059 /*
16060 @@ -410,7 +696,7 @@ ENTRY(ret_from_fork)
16061
16062 RESTORE_REST
16063
16064 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16065 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16066 jz retint_restore_args
16067
16068 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16069 @@ -420,7 +706,7 @@ ENTRY(ret_from_fork)
16070 jmp ret_from_sys_call # go to the SYSRET fastpath
16071
16072 CFI_ENDPROC
16073 -END(ret_from_fork)
16074 +ENDPROC(ret_from_fork)
16075
16076 /*
16077 * System call entry. Up to 6 arguments in registers are supported.
16078 @@ -456,7 +742,7 @@ END(ret_from_fork)
16079 ENTRY(system_call)
16080 CFI_STARTPROC simple
16081 CFI_SIGNAL_FRAME
16082 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16083 + CFI_DEF_CFA rsp,0
16084 CFI_REGISTER rip,rcx
16085 /*CFI_REGISTER rflags,r11*/
16086 SWAPGS_UNSAFE_STACK
16087 @@ -469,16 +755,18 @@ GLOBAL(system_call_after_swapgs)
16088
16089 movq %rsp,PER_CPU_VAR(old_rsp)
16090 movq PER_CPU_VAR(kernel_stack),%rsp
16091 + SAVE_ARGS 8*6,0
16092 + pax_enter_kernel_user
16093 /*
16094 * No need to follow this irqs off/on section - it's straight
16095 * and short:
16096 */
16097 ENABLE_INTERRUPTS(CLBR_NONE)
16098 - SAVE_ARGS 8,0
16099 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16100 movq %rcx,RIP-ARGOFFSET(%rsp)
16101 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16102 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16103 + GET_THREAD_INFO(%rcx)
16104 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16105 jnz tracesys
16106 system_call_fastpath:
16107 #if __SYSCALL_MASK == ~0
16108 @@ -488,7 +776,7 @@ system_call_fastpath:
16109 cmpl $__NR_syscall_max,%eax
16110 #endif
16111 ja badsys
16112 - movq %r10,%rcx
16113 + movq R10-ARGOFFSET(%rsp),%rcx
16114 call *sys_call_table(,%rax,8) # XXX: rip relative
16115 movq %rax,RAX-ARGOFFSET(%rsp)
16116 /*
16117 @@ -502,10 +790,13 @@ sysret_check:
16118 LOCKDEP_SYS_EXIT
16119 DISABLE_INTERRUPTS(CLBR_NONE)
16120 TRACE_IRQS_OFF
16121 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16122 + GET_THREAD_INFO(%rcx)
16123 + movl TI_flags(%rcx),%edx
16124 andl %edi,%edx
16125 jnz sysret_careful
16126 CFI_REMEMBER_STATE
16127 + pax_exit_kernel_user
16128 + pax_erase_kstack
16129 /*
16130 * sysretq will re-enable interrupts:
16131 */
16132 @@ -557,14 +848,18 @@ badsys:
16133 * jump back to the normal fast path.
16134 */
16135 auditsys:
16136 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
16137 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16138 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16139 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16140 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16141 movq %rax,%rsi /* 2nd arg: syscall number */
16142 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16143 call __audit_syscall_entry
16144 +
16145 + pax_erase_kstack
16146 +
16147 LOAD_ARGS 0 /* reload call-clobbered registers */
16148 + pax_set_fptr_mask
16149 jmp system_call_fastpath
16150
16151 /*
16152 @@ -585,7 +880,7 @@ sysret_audit:
16153 /* Do syscall tracing */
16154 tracesys:
16155 #ifdef CONFIG_AUDITSYSCALL
16156 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16157 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16158 jz auditsys
16159 #endif
16160 SAVE_REST
16161 @@ -593,12 +888,16 @@ tracesys:
16162 FIXUP_TOP_OF_STACK %rdi
16163 movq %rsp,%rdi
16164 call syscall_trace_enter
16165 +
16166 + pax_erase_kstack
16167 +
16168 /*
16169 * Reload arg registers from stack in case ptrace changed them.
16170 * We don't reload %rax because syscall_trace_enter() returned
16171 * the value it wants us to use in the table lookup.
16172 */
16173 LOAD_ARGS ARGOFFSET, 1
16174 + pax_set_fptr_mask
16175 RESTORE_REST
16176 #if __SYSCALL_MASK == ~0
16177 cmpq $__NR_syscall_max,%rax
16178 @@ -607,7 +906,7 @@ tracesys:
16179 cmpl $__NR_syscall_max,%eax
16180 #endif
16181 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16182 - movq %r10,%rcx /* fixup for C */
16183 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16184 call *sys_call_table(,%rax,8)
16185 movq %rax,RAX-ARGOFFSET(%rsp)
16186 /* Use IRET because user could have changed frame */
16187 @@ -628,6 +927,7 @@ GLOBAL(int_with_check)
16188 andl %edi,%edx
16189 jnz int_careful
16190 andl $~TS_COMPAT,TI_status(%rcx)
16191 + pax_erase_kstack
16192 jmp retint_swapgs
16193
16194 /* Either reschedule or signal or syscall exit tracking needed. */
16195 @@ -674,7 +974,7 @@ int_restore_rest:
16196 TRACE_IRQS_OFF
16197 jmp int_with_check
16198 CFI_ENDPROC
16199 -END(system_call)
16200 +ENDPROC(system_call)
16201
16202 /*
16203 * Certain special system calls that need to save a complete full stack frame.
16204 @@ -690,7 +990,7 @@ ENTRY(\label)
16205 call \func
16206 jmp ptregscall_common
16207 CFI_ENDPROC
16208 -END(\label)
16209 +ENDPROC(\label)
16210 .endm
16211
16212 PTREGSCALL stub_clone, sys_clone, %r8
16213 @@ -708,9 +1008,10 @@ ENTRY(ptregscall_common)
16214 movq_cfi_restore R12+8, r12
16215 movq_cfi_restore RBP+8, rbp
16216 movq_cfi_restore RBX+8, rbx
16217 + pax_force_retaddr
16218 ret $REST_SKIP /* pop extended registers */
16219 CFI_ENDPROC
16220 -END(ptregscall_common)
16221 +ENDPROC(ptregscall_common)
16222
16223 ENTRY(stub_execve)
16224 CFI_STARTPROC
16225 @@ -725,7 +1026,7 @@ ENTRY(stub_execve)
16226 RESTORE_REST
16227 jmp int_ret_from_sys_call
16228 CFI_ENDPROC
16229 -END(stub_execve)
16230 +ENDPROC(stub_execve)
16231
16232 /*
16233 * sigreturn is special because it needs to restore all registers on return.
16234 @@ -743,7 +1044,7 @@ ENTRY(stub_rt_sigreturn)
16235 RESTORE_REST
16236 jmp int_ret_from_sys_call
16237 CFI_ENDPROC
16238 -END(stub_rt_sigreturn)
16239 +ENDPROC(stub_rt_sigreturn)
16240
16241 #ifdef CONFIG_X86_X32_ABI
16242 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16243 @@ -812,7 +1113,7 @@ vector=vector+1
16244 2: jmp common_interrupt
16245 .endr
16246 CFI_ENDPROC
16247 -END(irq_entries_start)
16248 +ENDPROC(irq_entries_start)
16249
16250 .previous
16251 END(interrupt)
16252 @@ -832,6 +1133,16 @@ END(interrupt)
16253 subq $ORIG_RAX-RBP, %rsp
16254 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16255 SAVE_ARGS_IRQ
16256 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16257 + testb $3, CS(%rdi)
16258 + jnz 1f
16259 + pax_enter_kernel
16260 + jmp 2f
16261 +1: pax_enter_kernel_user
16262 +2:
16263 +#else
16264 + pax_enter_kernel
16265 +#endif
16266 call \func
16267 .endm
16268
16269 @@ -863,7 +1174,7 @@ ret_from_intr:
16270
16271 exit_intr:
16272 GET_THREAD_INFO(%rcx)
16273 - testl $3,CS-ARGOFFSET(%rsp)
16274 + testb $3,CS-ARGOFFSET(%rsp)
16275 je retint_kernel
16276
16277 /* Interrupt came from user space */
16278 @@ -885,12 +1196,15 @@ retint_swapgs: /* return to user-space */
16279 * The iretq could re-enable interrupts:
16280 */
16281 DISABLE_INTERRUPTS(CLBR_ANY)
16282 + pax_exit_kernel_user
16283 TRACE_IRQS_IRETQ
16284 SWAPGS
16285 jmp restore_args
16286
16287 retint_restore_args: /* return to kernel space */
16288 DISABLE_INTERRUPTS(CLBR_ANY)
16289 + pax_exit_kernel
16290 + pax_force_retaddr RIP-ARGOFFSET
16291 /*
16292 * The iretq could re-enable interrupts:
16293 */
16294 @@ -979,7 +1293,7 @@ ENTRY(retint_kernel)
16295 #endif
16296
16297 CFI_ENDPROC
16298 -END(common_interrupt)
16299 +ENDPROC(common_interrupt)
16300 /*
16301 * End of kprobes section
16302 */
16303 @@ -996,7 +1310,7 @@ ENTRY(\sym)
16304 interrupt \do_sym
16305 jmp ret_from_intr
16306 CFI_ENDPROC
16307 -END(\sym)
16308 +ENDPROC(\sym)
16309 .endm
16310
16311 #ifdef CONFIG_SMP
16312 @@ -1069,12 +1383,22 @@ ENTRY(\sym)
16313 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16314 call error_entry
16315 DEFAULT_FRAME 0
16316 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16317 + testb $3, CS(%rsp)
16318 + jnz 1f
16319 + pax_enter_kernel
16320 + jmp 2f
16321 +1: pax_enter_kernel_user
16322 +2:
16323 +#else
16324 + pax_enter_kernel
16325 +#endif
16326 movq %rsp,%rdi /* pt_regs pointer */
16327 xorl %esi,%esi /* no error code */
16328 call \do_sym
16329 jmp error_exit /* %ebx: no swapgs flag */
16330 CFI_ENDPROC
16331 -END(\sym)
16332 +ENDPROC(\sym)
16333 .endm
16334
16335 .macro paranoidzeroentry sym do_sym
16336 @@ -1086,15 +1410,25 @@ ENTRY(\sym)
16337 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16338 call save_paranoid
16339 TRACE_IRQS_OFF
16340 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16341 + testb $3, CS(%rsp)
16342 + jnz 1f
16343 + pax_enter_kernel
16344 + jmp 2f
16345 +1: pax_enter_kernel_user
16346 +2:
16347 +#else
16348 + pax_enter_kernel
16349 +#endif
16350 movq %rsp,%rdi /* pt_regs pointer */
16351 xorl %esi,%esi /* no error code */
16352 call \do_sym
16353 jmp paranoid_exit /* %ebx: no swapgs flag */
16354 CFI_ENDPROC
16355 -END(\sym)
16356 +ENDPROC(\sym)
16357 .endm
16358
16359 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16360 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16361 .macro paranoidzeroentry_ist sym do_sym ist
16362 ENTRY(\sym)
16363 INTR_FRAME
16364 @@ -1104,14 +1438,30 @@ ENTRY(\sym)
16365 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16366 call save_paranoid
16367 TRACE_IRQS_OFF
16368 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16369 + testb $3, CS(%rsp)
16370 + jnz 1f
16371 + pax_enter_kernel
16372 + jmp 2f
16373 +1: pax_enter_kernel_user
16374 +2:
16375 +#else
16376 + pax_enter_kernel
16377 +#endif
16378 movq %rsp,%rdi /* pt_regs pointer */
16379 xorl %esi,%esi /* no error code */
16380 +#ifdef CONFIG_SMP
16381 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16382 + lea init_tss(%r12), %r12
16383 +#else
16384 + lea init_tss(%rip), %r12
16385 +#endif
16386 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16387 call \do_sym
16388 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16389 jmp paranoid_exit /* %ebx: no swapgs flag */
16390 CFI_ENDPROC
16391 -END(\sym)
16392 +ENDPROC(\sym)
16393 .endm
16394
16395 .macro errorentry sym do_sym
16396 @@ -1122,13 +1472,23 @@ ENTRY(\sym)
16397 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16398 call error_entry
16399 DEFAULT_FRAME 0
16400 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16401 + testb $3, CS(%rsp)
16402 + jnz 1f
16403 + pax_enter_kernel
16404 + jmp 2f
16405 +1: pax_enter_kernel_user
16406 +2:
16407 +#else
16408 + pax_enter_kernel
16409 +#endif
16410 movq %rsp,%rdi /* pt_regs pointer */
16411 movq ORIG_RAX(%rsp),%rsi /* get error code */
16412 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16413 call \do_sym
16414 jmp error_exit /* %ebx: no swapgs flag */
16415 CFI_ENDPROC
16416 -END(\sym)
16417 +ENDPROC(\sym)
16418 .endm
16419
16420 /* error code is on the stack already */
16421 @@ -1141,13 +1501,23 @@ ENTRY(\sym)
16422 call save_paranoid
16423 DEFAULT_FRAME 0
16424 TRACE_IRQS_OFF
16425 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16426 + testb $3, CS(%rsp)
16427 + jnz 1f
16428 + pax_enter_kernel
16429 + jmp 2f
16430 +1: pax_enter_kernel_user
16431 +2:
16432 +#else
16433 + pax_enter_kernel
16434 +#endif
16435 movq %rsp,%rdi /* pt_regs pointer */
16436 movq ORIG_RAX(%rsp),%rsi /* get error code */
16437 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16438 call \do_sym
16439 jmp paranoid_exit /* %ebx: no swapgs flag */
16440 CFI_ENDPROC
16441 -END(\sym)
16442 +ENDPROC(\sym)
16443 .endm
16444
16445 zeroentry divide_error do_divide_error
16446 @@ -1177,9 +1547,10 @@ gs_change:
16447 2: mfence /* workaround */
16448 SWAPGS
16449 popfq_cfi
16450 + pax_force_retaddr
16451 ret
16452 CFI_ENDPROC
16453 -END(native_load_gs_index)
16454 +ENDPROC(native_load_gs_index)
16455
16456 .section __ex_table,"a"
16457 .align 8
16458 @@ -1201,13 +1572,14 @@ ENTRY(kernel_thread_helper)
16459 * Here we are in the child and the registers are set as they were
16460 * at kernel_thread() invocation in the parent.
16461 */
16462 + pax_force_fptr %rsi
16463 call *%rsi
16464 # exit
16465 mov %eax, %edi
16466 call do_exit
16467 ud2 # padding for call trace
16468 CFI_ENDPROC
16469 -END(kernel_thread_helper)
16470 +ENDPROC(kernel_thread_helper)
16471
16472 /*
16473 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16474 @@ -1234,11 +1606,11 @@ ENTRY(kernel_execve)
16475 RESTORE_REST
16476 testq %rax,%rax
16477 je int_ret_from_sys_call
16478 - RESTORE_ARGS
16479 UNFAKE_STACK_FRAME
16480 + pax_force_retaddr
16481 ret
16482 CFI_ENDPROC
16483 -END(kernel_execve)
16484 +ENDPROC(kernel_execve)
16485
16486 /* Call softirq on interrupt stack. Interrupts are off. */
16487 ENTRY(call_softirq)
16488 @@ -1256,9 +1628,10 @@ ENTRY(call_softirq)
16489 CFI_DEF_CFA_REGISTER rsp
16490 CFI_ADJUST_CFA_OFFSET -8
16491 decl PER_CPU_VAR(irq_count)
16492 + pax_force_retaddr
16493 ret
16494 CFI_ENDPROC
16495 -END(call_softirq)
16496 +ENDPROC(call_softirq)
16497
16498 #ifdef CONFIG_XEN
16499 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16500 @@ -1296,7 +1669,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16501 decl PER_CPU_VAR(irq_count)
16502 jmp error_exit
16503 CFI_ENDPROC
16504 -END(xen_do_hypervisor_callback)
16505 +ENDPROC(xen_do_hypervisor_callback)
16506
16507 /*
16508 * Hypervisor uses this for application faults while it executes.
16509 @@ -1355,7 +1728,7 @@ ENTRY(xen_failsafe_callback)
16510 SAVE_ALL
16511 jmp error_exit
16512 CFI_ENDPROC
16513 -END(xen_failsafe_callback)
16514 +ENDPROC(xen_failsafe_callback)
16515
16516 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16517 xen_hvm_callback_vector xen_evtchn_do_upcall
16518 @@ -1404,16 +1777,31 @@ ENTRY(paranoid_exit)
16519 TRACE_IRQS_OFF
16520 testl %ebx,%ebx /* swapgs needed? */
16521 jnz paranoid_restore
16522 - testl $3,CS(%rsp)
16523 + testb $3,CS(%rsp)
16524 jnz paranoid_userspace
16525 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16526 + pax_exit_kernel
16527 + TRACE_IRQS_IRETQ 0
16528 + SWAPGS_UNSAFE_STACK
16529 + RESTORE_ALL 8
16530 + pax_force_retaddr_bts
16531 + jmp irq_return
16532 +#endif
16533 paranoid_swapgs:
16534 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16535 + pax_exit_kernel_user
16536 +#else
16537 + pax_exit_kernel
16538 +#endif
16539 TRACE_IRQS_IRETQ 0
16540 SWAPGS_UNSAFE_STACK
16541 RESTORE_ALL 8
16542 jmp irq_return
16543 paranoid_restore:
16544 + pax_exit_kernel
16545 TRACE_IRQS_IRETQ 0
16546 RESTORE_ALL 8
16547 + pax_force_retaddr_bts
16548 jmp irq_return
16549 paranoid_userspace:
16550 GET_THREAD_INFO(%rcx)
16551 @@ -1442,7 +1830,7 @@ paranoid_schedule:
16552 TRACE_IRQS_OFF
16553 jmp paranoid_userspace
16554 CFI_ENDPROC
16555 -END(paranoid_exit)
16556 +ENDPROC(paranoid_exit)
16557
16558 /*
16559 * Exception entry point. This expects an error code/orig_rax on the stack.
16560 @@ -1469,12 +1857,13 @@ ENTRY(error_entry)
16561 movq_cfi r14, R14+8
16562 movq_cfi r15, R15+8
16563 xorl %ebx,%ebx
16564 - testl $3,CS+8(%rsp)
16565 + testb $3,CS+8(%rsp)
16566 je error_kernelspace
16567 error_swapgs:
16568 SWAPGS
16569 error_sti:
16570 TRACE_IRQS_OFF
16571 + pax_force_retaddr_bts
16572 ret
16573
16574 /*
16575 @@ -1501,7 +1890,7 @@ bstep_iret:
16576 movq %rcx,RIP+8(%rsp)
16577 jmp error_swapgs
16578 CFI_ENDPROC
16579 -END(error_entry)
16580 +ENDPROC(error_entry)
16581
16582
16583 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16584 @@ -1521,7 +1910,7 @@ ENTRY(error_exit)
16585 jnz retint_careful
16586 jmp retint_swapgs
16587 CFI_ENDPROC
16588 -END(error_exit)
16589 +ENDPROC(error_exit)
16590
16591 /*
16592 * Test if a given stack is an NMI stack or not.
16593 @@ -1579,9 +1968,11 @@ ENTRY(nmi)
16594 * If %cs was not the kernel segment, then the NMI triggered in user
16595 * space, which means it is definitely not nested.
16596 */
16597 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16598 + je 1f
16599 cmpl $__KERNEL_CS, 16(%rsp)
16600 jne first_nmi
16601 -
16602 +1:
16603 /*
16604 * Check the special variable on the stack to see if NMIs are
16605 * executing.
16606 @@ -1728,6 +2119,16 @@ end_repeat_nmi:
16607 */
16608 call save_paranoid
16609 DEFAULT_FRAME 0
16610 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16611 + testb $3, CS(%rsp)
16612 + jnz 1f
16613 + pax_enter_kernel
16614 + jmp 2f
16615 +1: pax_enter_kernel_user
16616 +2:
16617 +#else
16618 + pax_enter_kernel
16619 +#endif
16620 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16621 movq %rsp,%rdi
16622 movq $-1,%rsi
16623 @@ -1735,21 +2136,32 @@ end_repeat_nmi:
16624 testl %ebx,%ebx /* swapgs needed? */
16625 jnz nmi_restore
16626 nmi_swapgs:
16627 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16628 + pax_exit_kernel_user
16629 +#else
16630 + pax_exit_kernel
16631 +#endif
16632 SWAPGS_UNSAFE_STACK
16633 + RESTORE_ALL 8
16634 + /* Clear the NMI executing stack variable */
16635 + movq $0, 10*8(%rsp)
16636 + jmp irq_return
16637 nmi_restore:
16638 + pax_exit_kernel
16639 RESTORE_ALL 8
16640 + pax_force_retaddr_bts
16641 /* Clear the NMI executing stack variable */
16642 movq $0, 10*8(%rsp)
16643 jmp irq_return
16644 CFI_ENDPROC
16645 -END(nmi)
16646 +ENDPROC(nmi)
16647
16648 ENTRY(ignore_sysret)
16649 CFI_STARTPROC
16650 mov $-ENOSYS,%eax
16651 sysret
16652 CFI_ENDPROC
16653 -END(ignore_sysret)
16654 +ENDPROC(ignore_sysret)
16655
16656 /*
16657 * End of kprobes section
16658 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16659 index c9a281f..ce2f317 100644
16660 --- a/arch/x86/kernel/ftrace.c
16661 +++ b/arch/x86/kernel/ftrace.c
16662 @@ -126,7 +126,7 @@ static void *mod_code_ip; /* holds the IP to write to */
16663 static const void *mod_code_newcode; /* holds the text to write to the IP */
16664
16665 static unsigned nmi_wait_count;
16666 -static atomic_t nmi_update_count = ATOMIC_INIT(0);
16667 +static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
16668
16669 int ftrace_arch_read_dyn_info(char *buf, int size)
16670 {
16671 @@ -134,7 +134,7 @@ int ftrace_arch_read_dyn_info(char *buf, int size)
16672
16673 r = snprintf(buf, size, "%u %u",
16674 nmi_wait_count,
16675 - atomic_read(&nmi_update_count));
16676 + atomic_read_unchecked(&nmi_update_count));
16677 return r;
16678 }
16679
16680 @@ -177,8 +177,10 @@ void ftrace_nmi_enter(void)
16681
16682 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
16683 smp_rmb();
16684 + pax_open_kernel();
16685 ftrace_mod_code();
16686 - atomic_inc(&nmi_update_count);
16687 + pax_close_kernel();
16688 + atomic_inc_unchecked(&nmi_update_count);
16689 }
16690 /* Must have previous changes seen before executions */
16691 smp_mb();
16692 @@ -271,6 +273,8 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
16693 {
16694 unsigned char replaced[MCOUNT_INSN_SIZE];
16695
16696 + ip = ktla_ktva(ip);
16697 +
16698 /*
16699 * Note: Due to modules and __init, code can
16700 * disappear and change, we need to protect against faulting
16701 @@ -327,7 +331,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16702 unsigned char old[MCOUNT_INSN_SIZE], *new;
16703 int ret;
16704
16705 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16706 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16707 new = ftrace_call_replace(ip, (unsigned long)func);
16708 ret = ftrace_modify_code(ip, old, new);
16709
16710 @@ -353,6 +357,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16711 {
16712 unsigned char code[MCOUNT_INSN_SIZE];
16713
16714 + ip = ktla_ktva(ip);
16715 +
16716 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16717 return -EFAULT;
16718
16719 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16720 index 51ff186..9e77418 100644
16721 --- a/arch/x86/kernel/head32.c
16722 +++ b/arch/x86/kernel/head32.c
16723 @@ -19,6 +19,7 @@
16724 #include <asm/io_apic.h>
16725 #include <asm/bios_ebda.h>
16726 #include <asm/tlbflush.h>
16727 +#include <asm/boot.h>
16728
16729 static void __init i386_default_early_setup(void)
16730 {
16731 @@ -31,8 +32,7 @@ static void __init i386_default_early_setup(void)
16732
16733 void __init i386_start_kernel(void)
16734 {
16735 - memblock_reserve(__pa_symbol(&_text),
16736 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16737 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16738
16739 #ifdef CONFIG_BLK_DEV_INITRD
16740 /* Reserve INITRD */
16741 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16742 index ce0be7c..c41476e 100644
16743 --- a/arch/x86/kernel/head_32.S
16744 +++ b/arch/x86/kernel/head_32.S
16745 @@ -25,6 +25,12 @@
16746 /* Physical address */
16747 #define pa(X) ((X) - __PAGE_OFFSET)
16748
16749 +#ifdef CONFIG_PAX_KERNEXEC
16750 +#define ta(X) (X)
16751 +#else
16752 +#define ta(X) ((X) - __PAGE_OFFSET)
16753 +#endif
16754 +
16755 /*
16756 * References to members of the new_cpu_data structure.
16757 */
16758 @@ -54,11 +60,7 @@
16759 * and small than max_low_pfn, otherwise will waste some page table entries
16760 */
16761
16762 -#if PTRS_PER_PMD > 1
16763 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16764 -#else
16765 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16766 -#endif
16767 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16768
16769 /* Number of possible pages in the lowmem region */
16770 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16771 @@ -77,6 +79,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16772 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16773
16774 /*
16775 + * Real beginning of normal "text" segment
16776 + */
16777 +ENTRY(stext)
16778 +ENTRY(_stext)
16779 +
16780 +/*
16781 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16782 * %esi points to the real-mode code as a 32-bit pointer.
16783 * CS and DS must be 4 GB flat segments, but we don't depend on
16784 @@ -84,6 +92,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16785 * can.
16786 */
16787 __HEAD
16788 +
16789 +#ifdef CONFIG_PAX_KERNEXEC
16790 + jmp startup_32
16791 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16792 +.fill PAGE_SIZE-5,1,0xcc
16793 +#endif
16794 +
16795 ENTRY(startup_32)
16796 movl pa(stack_start),%ecx
16797
16798 @@ -105,6 +120,57 @@ ENTRY(startup_32)
16799 2:
16800 leal -__PAGE_OFFSET(%ecx),%esp
16801
16802 +#ifdef CONFIG_SMP
16803 + movl $pa(cpu_gdt_table),%edi
16804 + movl $__per_cpu_load,%eax
16805 + movw %ax,__KERNEL_PERCPU + 2(%edi)
16806 + rorl $16,%eax
16807 + movb %al,__KERNEL_PERCPU + 4(%edi)
16808 + movb %ah,__KERNEL_PERCPU + 7(%edi)
16809 + movl $__per_cpu_end - 1,%eax
16810 + subl $__per_cpu_start,%eax
16811 + movw %ax,__KERNEL_PERCPU + 0(%edi)
16812 +#endif
16813 +
16814 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16815 + movl $NR_CPUS,%ecx
16816 + movl $pa(cpu_gdt_table),%edi
16817 +1:
16818 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16819 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16820 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16821 + addl $PAGE_SIZE_asm,%edi
16822 + loop 1b
16823 +#endif
16824 +
16825 +#ifdef CONFIG_PAX_KERNEXEC
16826 + movl $pa(boot_gdt),%edi
16827 + movl $__LOAD_PHYSICAL_ADDR,%eax
16828 + movw %ax,__BOOT_CS + 2(%edi)
16829 + rorl $16,%eax
16830 + movb %al,__BOOT_CS + 4(%edi)
16831 + movb %ah,__BOOT_CS + 7(%edi)
16832 + rorl $16,%eax
16833 +
16834 + ljmp $(__BOOT_CS),$1f
16835 +1:
16836 +
16837 + movl $NR_CPUS,%ecx
16838 + movl $pa(cpu_gdt_table),%edi
16839 + addl $__PAGE_OFFSET,%eax
16840 +1:
16841 + movw %ax,__KERNEL_CS + 2(%edi)
16842 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16843 + rorl $16,%eax
16844 + movb %al,__KERNEL_CS + 4(%edi)
16845 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16846 + movb %ah,__KERNEL_CS + 7(%edi)
16847 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16848 + rorl $16,%eax
16849 + addl $PAGE_SIZE_asm,%edi
16850 + loop 1b
16851 +#endif
16852 +
16853 /*
16854 * Clear BSS first so that there are no surprises...
16855 */
16856 @@ -195,8 +261,11 @@ ENTRY(startup_32)
16857 movl %eax, pa(max_pfn_mapped)
16858
16859 /* Do early initialization of the fixmap area */
16860 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16861 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16862 +#ifdef CONFIG_COMPAT_VDSO
16863 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16864 +#else
16865 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16866 +#endif
16867 #else /* Not PAE */
16868
16869 page_pde_offset = (__PAGE_OFFSET >> 20);
16870 @@ -226,8 +295,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16871 movl %eax, pa(max_pfn_mapped)
16872
16873 /* Do early initialization of the fixmap area */
16874 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16875 - movl %eax,pa(initial_page_table+0xffc)
16876 +#ifdef CONFIG_COMPAT_VDSO
16877 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16878 +#else
16879 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16880 +#endif
16881 #endif
16882
16883 #ifdef CONFIG_PARAVIRT
16884 @@ -241,9 +313,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16885 cmpl $num_subarch_entries, %eax
16886 jae bad_subarch
16887
16888 - movl pa(subarch_entries)(,%eax,4), %eax
16889 - subl $__PAGE_OFFSET, %eax
16890 - jmp *%eax
16891 + jmp *pa(subarch_entries)(,%eax,4)
16892
16893 bad_subarch:
16894 WEAK(lguest_entry)
16895 @@ -255,10 +325,10 @@ WEAK(xen_entry)
16896 __INITDATA
16897
16898 subarch_entries:
16899 - .long default_entry /* normal x86/PC */
16900 - .long lguest_entry /* lguest hypervisor */
16901 - .long xen_entry /* Xen hypervisor */
16902 - .long default_entry /* Moorestown MID */
16903 + .long ta(default_entry) /* normal x86/PC */
16904 + .long ta(lguest_entry) /* lguest hypervisor */
16905 + .long ta(xen_entry) /* Xen hypervisor */
16906 + .long ta(default_entry) /* Moorestown MID */
16907 num_subarch_entries = (. - subarch_entries) / 4
16908 .previous
16909 #else
16910 @@ -312,6 +382,7 @@ default_entry:
16911 orl %edx,%eax
16912 movl %eax,%cr4
16913
16914 +#ifdef CONFIG_X86_PAE
16915 testb $X86_CR4_PAE, %al # check if PAE is enabled
16916 jz 6f
16917
16918 @@ -340,6 +411,9 @@ default_entry:
16919 /* Make changes effective */
16920 wrmsr
16921
16922 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
16923 +#endif
16924 +
16925 6:
16926
16927 /*
16928 @@ -443,7 +517,7 @@ is386: movl $2,%ecx # set MP
16929 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
16930 movl %eax,%ss # after changing gdt.
16931
16932 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
16933 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
16934 movl %eax,%ds
16935 movl %eax,%es
16936
16937 @@ -457,15 +531,22 @@ is386: movl $2,%ecx # set MP
16938 */
16939 cmpb $0,ready
16940 jne 1f
16941 - movl $gdt_page,%eax
16942 + movl $cpu_gdt_table,%eax
16943 movl $stack_canary,%ecx
16944 +#ifdef CONFIG_SMP
16945 + addl $__per_cpu_load,%ecx
16946 +#endif
16947 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
16948 shrl $16, %ecx
16949 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
16950 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
16951 1:
16952 -#endif
16953 movl $(__KERNEL_STACK_CANARY),%eax
16954 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16955 + movl $(__USER_DS),%eax
16956 +#else
16957 + xorl %eax,%eax
16958 +#endif
16959 movl %eax,%gs
16960
16961 xorl %eax,%eax # Clear LDT
16962 @@ -558,22 +639,22 @@ early_page_fault:
16963 jmp early_fault
16964
16965 early_fault:
16966 - cld
16967 #ifdef CONFIG_PRINTK
16968 + cmpl $1,%ss:early_recursion_flag
16969 + je hlt_loop
16970 + incl %ss:early_recursion_flag
16971 + cld
16972 pusha
16973 movl $(__KERNEL_DS),%eax
16974 movl %eax,%ds
16975 movl %eax,%es
16976 - cmpl $2,early_recursion_flag
16977 - je hlt_loop
16978 - incl early_recursion_flag
16979 movl %cr2,%eax
16980 pushl %eax
16981 pushl %edx /* trapno */
16982 pushl $fault_msg
16983 call printk
16984 +; call dump_stack
16985 #endif
16986 - call dump_stack
16987 hlt_loop:
16988 hlt
16989 jmp hlt_loop
16990 @@ -581,8 +662,11 @@ hlt_loop:
16991 /* This is the default interrupt "handler" :-) */
16992 ALIGN
16993 ignore_int:
16994 - cld
16995 #ifdef CONFIG_PRINTK
16996 + cmpl $2,%ss:early_recursion_flag
16997 + je hlt_loop
16998 + incl %ss:early_recursion_flag
16999 + cld
17000 pushl %eax
17001 pushl %ecx
17002 pushl %edx
17003 @@ -591,9 +675,6 @@ ignore_int:
17004 movl $(__KERNEL_DS),%eax
17005 movl %eax,%ds
17006 movl %eax,%es
17007 - cmpl $2,early_recursion_flag
17008 - je hlt_loop
17009 - incl early_recursion_flag
17010 pushl 16(%esp)
17011 pushl 24(%esp)
17012 pushl 32(%esp)
17013 @@ -622,29 +703,43 @@ ENTRY(initial_code)
17014 /*
17015 * BSS section
17016 */
17017 -__PAGE_ALIGNED_BSS
17018 - .align PAGE_SIZE
17019 #ifdef CONFIG_X86_PAE
17020 +.section .initial_pg_pmd,"a",@progbits
17021 initial_pg_pmd:
17022 .fill 1024*KPMDS,4,0
17023 #else
17024 +.section .initial_page_table,"a",@progbits
17025 ENTRY(initial_page_table)
17026 .fill 1024,4,0
17027 #endif
17028 +.section .initial_pg_fixmap,"a",@progbits
17029 initial_pg_fixmap:
17030 .fill 1024,4,0
17031 +.section .empty_zero_page,"a",@progbits
17032 ENTRY(empty_zero_page)
17033 .fill 4096,1,0
17034 +.section .swapper_pg_dir,"a",@progbits
17035 ENTRY(swapper_pg_dir)
17036 +#ifdef CONFIG_X86_PAE
17037 + .fill 4,8,0
17038 +#else
17039 .fill 1024,4,0
17040 +#endif
17041 +
17042 +/*
17043 + * The IDT has to be page-aligned to simplify the Pentium
17044 + * F0 0F bug workaround.. We have a special link segment
17045 + * for this.
17046 + */
17047 +.section .idt,"a",@progbits
17048 +ENTRY(idt_table)
17049 + .fill 256,8,0
17050
17051 /*
17052 * This starts the data section.
17053 */
17054 #ifdef CONFIG_X86_PAE
17055 -__PAGE_ALIGNED_DATA
17056 - /* Page-aligned for the benefit of paravirt? */
17057 - .align PAGE_SIZE
17058 +.section .initial_page_table,"a",@progbits
17059 ENTRY(initial_page_table)
17060 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17061 # if KPMDS == 3
17062 @@ -663,18 +758,27 @@ ENTRY(initial_page_table)
17063 # error "Kernel PMDs should be 1, 2 or 3"
17064 # endif
17065 .align PAGE_SIZE /* needs to be page-sized too */
17066 +
17067 +#ifdef CONFIG_PAX_PER_CPU_PGD
17068 +ENTRY(cpu_pgd)
17069 + .rept NR_CPUS
17070 + .fill 4,8,0
17071 + .endr
17072 +#endif
17073 +
17074 #endif
17075
17076 .data
17077 .balign 4
17078 ENTRY(stack_start)
17079 - .long init_thread_union+THREAD_SIZE
17080 + .long init_thread_union+THREAD_SIZE-8
17081
17082 +ready: .byte 0
17083 +
17084 +.section .rodata,"a",@progbits
17085 early_recursion_flag:
17086 .long 0
17087
17088 -ready: .byte 0
17089 -
17090 int_msg:
17091 .asciz "Unknown interrupt or fault at: %p %p %p\n"
17092
17093 @@ -707,7 +811,7 @@ fault_msg:
17094 .word 0 # 32 bit align gdt_desc.address
17095 boot_gdt_descr:
17096 .word __BOOT_DS+7
17097 - .long boot_gdt - __PAGE_OFFSET
17098 + .long pa(boot_gdt)
17099
17100 .word 0 # 32-bit align idt_desc.address
17101 idt_descr:
17102 @@ -718,7 +822,7 @@ idt_descr:
17103 .word 0 # 32 bit align gdt_desc.address
17104 ENTRY(early_gdt_descr)
17105 .word GDT_ENTRIES*8-1
17106 - .long gdt_page /* Overwritten for secondary CPUs */
17107 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
17108
17109 /*
17110 * The boot_gdt must mirror the equivalent in setup.S and is
17111 @@ -727,5 +831,65 @@ ENTRY(early_gdt_descr)
17112 .align L1_CACHE_BYTES
17113 ENTRY(boot_gdt)
17114 .fill GDT_ENTRY_BOOT_CS,8,0
17115 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17116 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17117 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17118 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17119 +
17120 + .align PAGE_SIZE_asm
17121 +ENTRY(cpu_gdt_table)
17122 + .rept NR_CPUS
17123 + .quad 0x0000000000000000 /* NULL descriptor */
17124 + .quad 0x0000000000000000 /* 0x0b reserved */
17125 + .quad 0x0000000000000000 /* 0x13 reserved */
17126 + .quad 0x0000000000000000 /* 0x1b reserved */
17127 +
17128 +#ifdef CONFIG_PAX_KERNEXEC
17129 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17130 +#else
17131 + .quad 0x0000000000000000 /* 0x20 unused */
17132 +#endif
17133 +
17134 + .quad 0x0000000000000000 /* 0x28 unused */
17135 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17136 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17137 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17138 + .quad 0x0000000000000000 /* 0x4b reserved */
17139 + .quad 0x0000000000000000 /* 0x53 reserved */
17140 + .quad 0x0000000000000000 /* 0x5b reserved */
17141 +
17142 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17143 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17144 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17145 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17146 +
17147 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17148 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17149 +
17150 + /*
17151 + * Segments used for calling PnP BIOS have byte granularity.
17152 + * The code segments and data segments have fixed 64k limits,
17153 + * the transfer segment sizes are set at run time.
17154 + */
17155 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
17156 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
17157 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
17158 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
17159 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
17160 +
17161 + /*
17162 + * The APM segments have byte granularity and their bases
17163 + * are set at run time. All have 64k limits.
17164 + */
17165 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17166 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17167 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
17168 +
17169 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17170 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17171 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17172 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17173 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17174 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17175 +
17176 + /* Be sure this is zeroed to avoid false validations in Xen */
17177 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17178 + .endr
17179 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17180 index 40f4eb3..6d24d9d 100644
17181 --- a/arch/x86/kernel/head_64.S
17182 +++ b/arch/x86/kernel/head_64.S
17183 @@ -19,6 +19,8 @@
17184 #include <asm/cache.h>
17185 #include <asm/processor-flags.h>
17186 #include <asm/percpu.h>
17187 +#include <asm/cpufeature.h>
17188 +#include <asm/alternative-asm.h>
17189
17190 #ifdef CONFIG_PARAVIRT
17191 #include <asm/asm-offsets.h>
17192 @@ -38,6 +40,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17193 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17194 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17195 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17196 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
17197 +L3_VMALLOC_START = pud_index(VMALLOC_START)
17198 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
17199 +L3_VMALLOC_END = pud_index(VMALLOC_END)
17200 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17201 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17202
17203 .text
17204 __HEAD
17205 @@ -85,35 +93,23 @@ startup_64:
17206 */
17207 addq %rbp, init_level4_pgt + 0(%rip)
17208 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17209 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17210 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17211 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17212 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17213
17214 addq %rbp, level3_ident_pgt + 0(%rip)
17215 +#ifndef CONFIG_XEN
17216 + addq %rbp, level3_ident_pgt + 8(%rip)
17217 +#endif
17218
17219 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17220 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17221 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17222 +
17223 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17224 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17225
17226 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17227 -
17228 - /* Add an Identity mapping if I am above 1G */
17229 - leaq _text(%rip), %rdi
17230 - andq $PMD_PAGE_MASK, %rdi
17231 -
17232 - movq %rdi, %rax
17233 - shrq $PUD_SHIFT, %rax
17234 - andq $(PTRS_PER_PUD - 1), %rax
17235 - jz ident_complete
17236 -
17237 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17238 - leaq level3_ident_pgt(%rip), %rbx
17239 - movq %rdx, 0(%rbx, %rax, 8)
17240 -
17241 - movq %rdi, %rax
17242 - shrq $PMD_SHIFT, %rax
17243 - andq $(PTRS_PER_PMD - 1), %rax
17244 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17245 - leaq level2_spare_pgt(%rip), %rbx
17246 - movq %rdx, 0(%rbx, %rax, 8)
17247 -ident_complete:
17248 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17249
17250 /*
17251 * Fixup the kernel text+data virtual addresses. Note that
17252 @@ -160,8 +156,8 @@ ENTRY(secondary_startup_64)
17253 * after the boot processor executes this code.
17254 */
17255
17256 - /* Enable PAE mode and PGE */
17257 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17258 + /* Enable PAE mode and PSE/PGE */
17259 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17260 movq %rax, %cr4
17261
17262 /* Setup early boot stage 4 level pagetables. */
17263 @@ -183,9 +179,17 @@ ENTRY(secondary_startup_64)
17264 movl $MSR_EFER, %ecx
17265 rdmsr
17266 btsl $_EFER_SCE, %eax /* Enable System Call */
17267 - btl $20,%edi /* No Execute supported? */
17268 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17269 jnc 1f
17270 btsl $_EFER_NX, %eax
17271 + leaq init_level4_pgt(%rip), %rdi
17272 +#ifndef CONFIG_EFI
17273 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17274 +#endif
17275 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17276 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17277 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17278 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17279 1: wrmsr /* Make changes effective */
17280
17281 /* Setup cr0 */
17282 @@ -247,6 +251,7 @@ ENTRY(secondary_startup_64)
17283 * jump. In addition we need to ensure %cs is set so we make this
17284 * a far return.
17285 */
17286 + pax_set_fptr_mask
17287 movq initial_code(%rip),%rax
17288 pushq $0 # fake return address to stop unwinder
17289 pushq $__KERNEL_CS # set correct cs
17290 @@ -269,7 +274,7 @@ ENTRY(secondary_startup_64)
17291 bad_address:
17292 jmp bad_address
17293
17294 - .section ".init.text","ax"
17295 + __INIT
17296 #ifdef CONFIG_EARLY_PRINTK
17297 .globl early_idt_handlers
17298 early_idt_handlers:
17299 @@ -314,18 +319,23 @@ ENTRY(early_idt_handler)
17300 #endif /* EARLY_PRINTK */
17301 1: hlt
17302 jmp 1b
17303 + .previous
17304
17305 #ifdef CONFIG_EARLY_PRINTK
17306 + __INITDATA
17307 early_recursion_flag:
17308 .long 0
17309 + .previous
17310
17311 + .section .rodata,"a",@progbits
17312 early_idt_msg:
17313 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17314 early_idt_ripmsg:
17315 .asciz "RIP %s\n"
17316 + .previous
17317 #endif /* CONFIG_EARLY_PRINTK */
17318 - .previous
17319
17320 + .section .rodata,"a",@progbits
17321 #define NEXT_PAGE(name) \
17322 .balign PAGE_SIZE; \
17323 ENTRY(name)
17324 @@ -338,7 +348,6 @@ ENTRY(name)
17325 i = i + 1 ; \
17326 .endr
17327
17328 - .data
17329 /*
17330 * This default setting generates an ident mapping at address 0x100000
17331 * and a mapping for the kernel that precisely maps virtual address
17332 @@ -349,13 +358,41 @@ NEXT_PAGE(init_level4_pgt)
17333 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17334 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17335 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17336 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
17337 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17338 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
17339 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17340 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17341 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17342 .org init_level4_pgt + L4_START_KERNEL*8, 0
17343 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17344 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17345
17346 +#ifdef CONFIG_PAX_PER_CPU_PGD
17347 +NEXT_PAGE(cpu_pgd)
17348 + .rept NR_CPUS
17349 + .fill 512,8,0
17350 + .endr
17351 +#endif
17352 +
17353 NEXT_PAGE(level3_ident_pgt)
17354 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17355 +#ifdef CONFIG_XEN
17356 .fill 511,8,0
17357 +#else
17358 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17359 + .fill 510,8,0
17360 +#endif
17361 +
17362 +NEXT_PAGE(level3_vmalloc_start_pgt)
17363 + .fill 512,8,0
17364 +
17365 +NEXT_PAGE(level3_vmalloc_end_pgt)
17366 + .fill 512,8,0
17367 +
17368 +NEXT_PAGE(level3_vmemmap_pgt)
17369 + .fill L3_VMEMMAP_START,8,0
17370 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17371
17372 NEXT_PAGE(level3_kernel_pgt)
17373 .fill L3_START_KERNEL,8,0
17374 @@ -363,20 +400,23 @@ NEXT_PAGE(level3_kernel_pgt)
17375 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17376 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17377
17378 +NEXT_PAGE(level2_vmemmap_pgt)
17379 + .fill 512,8,0
17380 +
17381 NEXT_PAGE(level2_fixmap_pgt)
17382 - .fill 506,8,0
17383 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17384 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17385 - .fill 5,8,0
17386 + .fill 507,8,0
17387 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17388 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17389 + .fill 4,8,0
17390
17391 -NEXT_PAGE(level1_fixmap_pgt)
17392 +NEXT_PAGE(level1_vsyscall_pgt)
17393 .fill 512,8,0
17394
17395 -NEXT_PAGE(level2_ident_pgt)
17396 - /* Since I easily can, map the first 1G.
17397 + /* Since I easily can, map the first 2G.
17398 * Don't set NX because code runs from these pages.
17399 */
17400 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17401 +NEXT_PAGE(level2_ident_pgt)
17402 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17403
17404 NEXT_PAGE(level2_kernel_pgt)
17405 /*
17406 @@ -389,37 +429,59 @@ NEXT_PAGE(level2_kernel_pgt)
17407 * If you want to increase this then increase MODULES_VADDR
17408 * too.)
17409 */
17410 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17411 - KERNEL_IMAGE_SIZE/PMD_SIZE)
17412 -
17413 -NEXT_PAGE(level2_spare_pgt)
17414 - .fill 512, 8, 0
17415 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17416
17417 #undef PMDS
17418 #undef NEXT_PAGE
17419
17420 - .data
17421 + .align PAGE_SIZE
17422 +ENTRY(cpu_gdt_table)
17423 + .rept NR_CPUS
17424 + .quad 0x0000000000000000 /* NULL descriptor */
17425 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17426 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
17427 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
17428 + .quad 0x00cffb000000ffff /* __USER32_CS */
17429 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17430 + .quad 0x00affb000000ffff /* __USER_CS */
17431 +
17432 +#ifdef CONFIG_PAX_KERNEXEC
17433 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17434 +#else
17435 + .quad 0x0 /* unused */
17436 +#endif
17437 +
17438 + .quad 0,0 /* TSS */
17439 + .quad 0,0 /* LDT */
17440 + .quad 0,0,0 /* three TLS descriptors */
17441 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
17442 + /* asm/segment.h:GDT_ENTRIES must match this */
17443 +
17444 + /* zero the remaining page */
17445 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17446 + .endr
17447 +
17448 .align 16
17449 .globl early_gdt_descr
17450 early_gdt_descr:
17451 .word GDT_ENTRIES*8-1
17452 early_gdt_descr_base:
17453 - .quad INIT_PER_CPU_VAR(gdt_page)
17454 + .quad cpu_gdt_table
17455
17456 ENTRY(phys_base)
17457 /* This must match the first entry in level2_kernel_pgt */
17458 .quad 0x0000000000000000
17459
17460 #include "../../x86/xen/xen-head.S"
17461 -
17462 - .section .bss, "aw", @nobits
17463 +
17464 + .section .rodata,"a",@progbits
17465 .align L1_CACHE_BYTES
17466 ENTRY(idt_table)
17467 - .skip IDT_ENTRIES * 16
17468 + .fill 512,8,0
17469
17470 .align L1_CACHE_BYTES
17471 ENTRY(nmi_idt_table)
17472 - .skip IDT_ENTRIES * 16
17473 + .fill 512,8,0
17474
17475 __PAGE_ALIGNED_BSS
17476 .align PAGE_SIZE
17477 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17478 index 9c3bd4a..e1d9b35 100644
17479 --- a/arch/x86/kernel/i386_ksyms_32.c
17480 +++ b/arch/x86/kernel/i386_ksyms_32.c
17481 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17482 EXPORT_SYMBOL(cmpxchg8b_emu);
17483 #endif
17484
17485 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
17486 +
17487 /* Networking helper routines. */
17488 EXPORT_SYMBOL(csum_partial_copy_generic);
17489 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17490 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17491
17492 EXPORT_SYMBOL(__get_user_1);
17493 EXPORT_SYMBOL(__get_user_2);
17494 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17495
17496 EXPORT_SYMBOL(csum_partial);
17497 EXPORT_SYMBOL(empty_zero_page);
17498 +
17499 +#ifdef CONFIG_PAX_KERNEXEC
17500 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17501 +#endif
17502 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17503 index 2d6e649..df6e1af 100644
17504 --- a/arch/x86/kernel/i387.c
17505 +++ b/arch/x86/kernel/i387.c
17506 @@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17507 static inline bool interrupted_user_mode(void)
17508 {
17509 struct pt_regs *regs = get_irq_regs();
17510 - return regs && user_mode_vm(regs);
17511 + return regs && user_mode(regs);
17512 }
17513
17514 /*
17515 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17516 index 36d1853..bf25736 100644
17517 --- a/arch/x86/kernel/i8259.c
17518 +++ b/arch/x86/kernel/i8259.c
17519 @@ -209,7 +209,7 @@ spurious_8259A_irq:
17520 "spurious 8259A interrupt: IRQ%d.\n", irq);
17521 spurious_irq_mask |= irqmask;
17522 }
17523 - atomic_inc(&irq_err_count);
17524 + atomic_inc_unchecked(&irq_err_count);
17525 /*
17526 * Theoretically we do not have to handle this IRQ,
17527 * but in Linux this does not cause problems and is
17528 diff --git a/arch/x86/kernel/init_task.c b/arch/x86/kernel/init_task.c
17529 index 43e9ccf..44ccf6f 100644
17530 --- a/arch/x86/kernel/init_task.c
17531 +++ b/arch/x86/kernel/init_task.c
17532 @@ -20,8 +20,7 @@ static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
17533 * way process stacks are handled. This is done by having a special
17534 * "init_task" linker map entry..
17535 */
17536 -union thread_union init_thread_union __init_task_data =
17537 - { INIT_THREAD_INFO(init_task) };
17538 +union thread_union init_thread_union __init_task_data;
17539
17540 /*
17541 * Initial task structure.
17542 @@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
17543 * section. Since TSS's are completely CPU-local, we want them
17544 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
17545 */
17546 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
17547 -
17548 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
17549 +EXPORT_SYMBOL(init_tss);
17550 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17551 index 8c96897..be66bfa 100644
17552 --- a/arch/x86/kernel/ioport.c
17553 +++ b/arch/x86/kernel/ioport.c
17554 @@ -6,6 +6,7 @@
17555 #include <linux/sched.h>
17556 #include <linux/kernel.h>
17557 #include <linux/capability.h>
17558 +#include <linux/security.h>
17559 #include <linux/errno.h>
17560 #include <linux/types.h>
17561 #include <linux/ioport.h>
17562 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17563
17564 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17565 return -EINVAL;
17566 +#ifdef CONFIG_GRKERNSEC_IO
17567 + if (turn_on && grsec_disable_privio) {
17568 + gr_handle_ioperm();
17569 + return -EPERM;
17570 + }
17571 +#endif
17572 if (turn_on && !capable(CAP_SYS_RAWIO))
17573 return -EPERM;
17574
17575 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17576 * because the ->io_bitmap_max value must match the bitmap
17577 * contents:
17578 */
17579 - tss = &per_cpu(init_tss, get_cpu());
17580 + tss = init_tss + get_cpu();
17581
17582 if (turn_on)
17583 bitmap_clear(t->io_bitmap_ptr, from, num);
17584 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17585 return -EINVAL;
17586 /* Trying to gain more privileges? */
17587 if (level > old) {
17588 +#ifdef CONFIG_GRKERNSEC_IO
17589 + if (grsec_disable_privio) {
17590 + gr_handle_iopl();
17591 + return -EPERM;
17592 + }
17593 +#endif
17594 if (!capable(CAP_SYS_RAWIO))
17595 return -EPERM;
17596 }
17597 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17598 index 3dafc60..aa8e9c4 100644
17599 --- a/arch/x86/kernel/irq.c
17600 +++ b/arch/x86/kernel/irq.c
17601 @@ -18,7 +18,7 @@
17602 #include <asm/mce.h>
17603 #include <asm/hw_irq.h>
17604
17605 -atomic_t irq_err_count;
17606 +atomic_unchecked_t irq_err_count;
17607
17608 /* Function pointer for generic interrupt vector handling */
17609 void (*x86_platform_ipi_callback)(void) = NULL;
17610 @@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17611 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17612 seq_printf(p, " Machine check polls\n");
17613 #endif
17614 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17615 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17616 #if defined(CONFIG_X86_IO_APIC)
17617 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17618 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17619 #endif
17620 return 0;
17621 }
17622 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17623
17624 u64 arch_irq_stat(void)
17625 {
17626 - u64 sum = atomic_read(&irq_err_count);
17627 + u64 sum = atomic_read_unchecked(&irq_err_count);
17628
17629 #ifdef CONFIG_X86_IO_APIC
17630 - sum += atomic_read(&irq_mis_count);
17631 + sum += atomic_read_unchecked(&irq_mis_count);
17632 #endif
17633 return sum;
17634 }
17635 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17636 index 58b7f27..e112d08 100644
17637 --- a/arch/x86/kernel/irq_32.c
17638 +++ b/arch/x86/kernel/irq_32.c
17639 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17640 __asm__ __volatile__("andl %%esp,%0" :
17641 "=r" (sp) : "0" (THREAD_SIZE - 1));
17642
17643 - return sp < (sizeof(struct thread_info) + STACK_WARN);
17644 + return sp < STACK_WARN;
17645 }
17646
17647 static void print_stack_overflow(void)
17648 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17649 * per-CPU IRQ handling contexts (thread information and stack)
17650 */
17651 union irq_ctx {
17652 - struct thread_info tinfo;
17653 - u32 stack[THREAD_SIZE/sizeof(u32)];
17654 + unsigned long previous_esp;
17655 + u32 stack[THREAD_SIZE/sizeof(u32)];
17656 } __attribute__((aligned(THREAD_SIZE)));
17657
17658 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17659 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17660 static inline int
17661 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17662 {
17663 - union irq_ctx *curctx, *irqctx;
17664 + union irq_ctx *irqctx;
17665 u32 *isp, arg1, arg2;
17666
17667 - curctx = (union irq_ctx *) current_thread_info();
17668 irqctx = __this_cpu_read(hardirq_ctx);
17669
17670 /*
17671 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17672 * handler) we can't do that and just have to keep using the
17673 * current stack (which is the irq stack already after all)
17674 */
17675 - if (unlikely(curctx == irqctx))
17676 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17677 return 0;
17678
17679 /* build the stack frame on the IRQ stack */
17680 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17681 - irqctx->tinfo.task = curctx->tinfo.task;
17682 - irqctx->tinfo.previous_esp = current_stack_pointer;
17683 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17684 + irqctx->previous_esp = current_stack_pointer;
17685
17686 - /* Copy the preempt_count so that the [soft]irq checks work. */
17687 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17688 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17689 + __set_fs(MAKE_MM_SEG(0));
17690 +#endif
17691
17692 if (unlikely(overflow))
17693 call_on_stack(print_stack_overflow, isp);
17694 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17695 : "0" (irq), "1" (desc), "2" (isp),
17696 "D" (desc->handle_irq)
17697 : "memory", "cc", "ecx");
17698 +
17699 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17700 + __set_fs(current_thread_info()->addr_limit);
17701 +#endif
17702 +
17703 return 1;
17704 }
17705
17706 @@ -121,29 +125,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17707 */
17708 void __cpuinit irq_ctx_init(int cpu)
17709 {
17710 - union irq_ctx *irqctx;
17711 -
17712 if (per_cpu(hardirq_ctx, cpu))
17713 return;
17714
17715 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17716 - THREAD_FLAGS,
17717 - THREAD_ORDER));
17718 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17719 - irqctx->tinfo.cpu = cpu;
17720 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17721 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17722 -
17723 - per_cpu(hardirq_ctx, cpu) = irqctx;
17724 -
17725 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17726 - THREAD_FLAGS,
17727 - THREAD_ORDER));
17728 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17729 - irqctx->tinfo.cpu = cpu;
17730 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17731 -
17732 - per_cpu(softirq_ctx, cpu) = irqctx;
17733 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17734 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17735
17736 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17737 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17738 @@ -152,7 +138,6 @@ void __cpuinit irq_ctx_init(int cpu)
17739 asmlinkage void do_softirq(void)
17740 {
17741 unsigned long flags;
17742 - struct thread_info *curctx;
17743 union irq_ctx *irqctx;
17744 u32 *isp;
17745
17746 @@ -162,15 +147,22 @@ asmlinkage void do_softirq(void)
17747 local_irq_save(flags);
17748
17749 if (local_softirq_pending()) {
17750 - curctx = current_thread_info();
17751 irqctx = __this_cpu_read(softirq_ctx);
17752 - irqctx->tinfo.task = curctx->task;
17753 - irqctx->tinfo.previous_esp = current_stack_pointer;
17754 + irqctx->previous_esp = current_stack_pointer;
17755
17756 /* build the stack frame on the softirq stack */
17757 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17758 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17759 +
17760 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17761 + __set_fs(MAKE_MM_SEG(0));
17762 +#endif
17763
17764 call_on_stack(__do_softirq, isp);
17765 +
17766 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17767 + __set_fs(current_thread_info()->addr_limit);
17768 +#endif
17769 +
17770 /*
17771 * Shouldn't happen, we returned above if in_interrupt():
17772 */
17773 @@ -191,7 +183,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17774 if (unlikely(!desc))
17775 return false;
17776
17777 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17778 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17779 if (unlikely(overflow))
17780 print_stack_overflow();
17781 desc->handle_irq(irq, desc);
17782 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17783 index d04d3ec..ea4b374 100644
17784 --- a/arch/x86/kernel/irq_64.c
17785 +++ b/arch/x86/kernel/irq_64.c
17786 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17787 u64 estack_top, estack_bottom;
17788 u64 curbase = (u64)task_stack_page(current);
17789
17790 - if (user_mode_vm(regs))
17791 + if (user_mode(regs))
17792 return;
17793
17794 if (regs->sp >= curbase + sizeof(struct thread_info) +
17795 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17796 index 1d5d31e..ab846ed 100644
17797 --- a/arch/x86/kernel/kdebugfs.c
17798 +++ b/arch/x86/kernel/kdebugfs.c
17799 @@ -28,6 +28,8 @@ struct setup_data_node {
17800 };
17801
17802 static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17803 + size_t count, loff_t *ppos) __size_overflow(3);
17804 +static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17805 size_t count, loff_t *ppos)
17806 {
17807 struct setup_data_node *node = file->private_data;
17808 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17809 index 8bfb614..2b3b35f 100644
17810 --- a/arch/x86/kernel/kgdb.c
17811 +++ b/arch/x86/kernel/kgdb.c
17812 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17813 #ifdef CONFIG_X86_32
17814 switch (regno) {
17815 case GDB_SS:
17816 - if (!user_mode_vm(regs))
17817 + if (!user_mode(regs))
17818 *(unsigned long *)mem = __KERNEL_DS;
17819 break;
17820 case GDB_SP:
17821 - if (!user_mode_vm(regs))
17822 + if (!user_mode(regs))
17823 *(unsigned long *)mem = kernel_stack_pointer(regs);
17824 break;
17825 case GDB_GS:
17826 @@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17827 case 'k':
17828 /* clear the trace bit */
17829 linux_regs->flags &= ~X86_EFLAGS_TF;
17830 - atomic_set(&kgdb_cpu_doing_single_step, -1);
17831 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17832
17833 /* set the trace bit if we're stepping */
17834 if (remcomInBuffer[0] == 's') {
17835 linux_regs->flags |= X86_EFLAGS_TF;
17836 - atomic_set(&kgdb_cpu_doing_single_step,
17837 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17838 raw_smp_processor_id());
17839 }
17840
17841 @@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17842
17843 switch (cmd) {
17844 case DIE_DEBUG:
17845 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17846 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17847 if (user_mode(regs))
17848 return single_step_cont(regs, args);
17849 break;
17850 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17851 index c5e410e..da6aaf9 100644
17852 --- a/arch/x86/kernel/kprobes-opt.c
17853 +++ b/arch/x86/kernel/kprobes-opt.c
17854 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17855 * Verify if the address gap is in 2GB range, because this uses
17856 * a relative jump.
17857 */
17858 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17859 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17860 if (abs(rel) > 0x7fffffff)
17861 return -ERANGE;
17862
17863 @@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17864 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17865
17866 /* Set probe function call */
17867 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17868 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17869
17870 /* Set returning jmp instruction at the tail of out-of-line buffer */
17871 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17872 - (u8 *)op->kp.addr + op->optinsn.size);
17873 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17874
17875 flush_icache_range((unsigned long) buf,
17876 (unsigned long) buf + TMPL_END_IDX +
17877 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17878 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17879
17880 /* Backup instructions which will be replaced by jump address */
17881 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17882 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17883 RELATIVE_ADDR_SIZE);
17884
17885 insn_buf[0] = RELATIVEJUMP_OPCODE;
17886 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17887 index e213fc8..d783ba4 100644
17888 --- a/arch/x86/kernel/kprobes.c
17889 +++ b/arch/x86/kernel/kprobes.c
17890 @@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17891 } __attribute__((packed)) *insn;
17892
17893 insn = (struct __arch_relative_insn *)from;
17894 +
17895 + pax_open_kernel();
17896 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17897 insn->op = op;
17898 + pax_close_kernel();
17899 }
17900
17901 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17902 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
17903 kprobe_opcode_t opcode;
17904 kprobe_opcode_t *orig_opcodes = opcodes;
17905
17906 - if (search_exception_tables((unsigned long)opcodes))
17907 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17908 return 0; /* Page fault may occur on this address. */
17909
17910 retry:
17911 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17912 /* Another subsystem puts a breakpoint, failed to recover */
17913 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
17914 return 0;
17915 + pax_open_kernel();
17916 memcpy(dest, insn.kaddr, insn.length);
17917 + pax_close_kernel();
17918
17919 #ifdef CONFIG_X86_64
17920 if (insn_rip_relative(&insn)) {
17921 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17922 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
17923 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
17924 disp = (u8 *) dest + insn_offset_displacement(&insn);
17925 + pax_open_kernel();
17926 *(s32 *) disp = (s32) newdisp;
17927 + pax_close_kernel();
17928 }
17929 #endif
17930 return insn.length;
17931 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17932 * nor set current_kprobe, because it doesn't use single
17933 * stepping.
17934 */
17935 - regs->ip = (unsigned long)p->ainsn.insn;
17936 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17937 preempt_enable_no_resched();
17938 return;
17939 }
17940 @@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17941 if (p->opcode == BREAKPOINT_INSTRUCTION)
17942 regs->ip = (unsigned long)p->addr;
17943 else
17944 - regs->ip = (unsigned long)p->ainsn.insn;
17945 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17946 }
17947
17948 /*
17949 @@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
17950 setup_singlestep(p, regs, kcb, 0);
17951 return 1;
17952 }
17953 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
17954 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
17955 /*
17956 * The breakpoint instruction was removed right
17957 * after we hit it. Another cpu has removed
17958 @@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
17959 " movq %rax, 152(%rsp)\n"
17960 RESTORE_REGS_STRING
17961 " popfq\n"
17962 +#ifdef KERNEXEC_PLUGIN
17963 + " btsq $63,(%rsp)\n"
17964 +#endif
17965 #else
17966 " pushf\n"
17967 SAVE_REGS_STRING
17968 @@ -765,7 +775,7 @@ static void __kprobes
17969 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
17970 {
17971 unsigned long *tos = stack_addr(regs);
17972 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
17973 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
17974 unsigned long orig_ip = (unsigned long)p->addr;
17975 kprobe_opcode_t *insn = p->ainsn.insn;
17976
17977 @@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
17978 struct die_args *args = data;
17979 int ret = NOTIFY_DONE;
17980
17981 - if (args->regs && user_mode_vm(args->regs))
17982 + if (args->regs && user_mode(args->regs))
17983 return ret;
17984
17985 switch (val) {
17986 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
17987 index ebc9873..1b9724b 100644
17988 --- a/arch/x86/kernel/ldt.c
17989 +++ b/arch/x86/kernel/ldt.c
17990 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
17991 if (reload) {
17992 #ifdef CONFIG_SMP
17993 preempt_disable();
17994 - load_LDT(pc);
17995 + load_LDT_nolock(pc);
17996 if (!cpumask_equal(mm_cpumask(current->mm),
17997 cpumask_of(smp_processor_id())))
17998 smp_call_function(flush_ldt, current->mm, 1);
17999 preempt_enable();
18000 #else
18001 - load_LDT(pc);
18002 + load_LDT_nolock(pc);
18003 #endif
18004 }
18005 if (oldsize) {
18006 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
18007 return err;
18008
18009 for (i = 0; i < old->size; i++)
18010 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
18011 + write_ldt_entry(new->ldt, i, old->ldt + i);
18012 return 0;
18013 }
18014
18015 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
18016 retval = copy_ldt(&mm->context, &old_mm->context);
18017 mutex_unlock(&old_mm->context.lock);
18018 }
18019 +
18020 + if (tsk == current) {
18021 + mm->context.vdso = 0;
18022 +
18023 +#ifdef CONFIG_X86_32
18024 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18025 + mm->context.user_cs_base = 0UL;
18026 + mm->context.user_cs_limit = ~0UL;
18027 +
18028 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18029 + cpus_clear(mm->context.cpu_user_cs_mask);
18030 +#endif
18031 +
18032 +#endif
18033 +#endif
18034 +
18035 + }
18036 +
18037 return retval;
18038 }
18039
18040 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18041 }
18042 }
18043
18044 +#ifdef CONFIG_PAX_SEGMEXEC
18045 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18046 + error = -EINVAL;
18047 + goto out_unlock;
18048 + }
18049 +#endif
18050 +
18051 fill_ldt(&ldt, &ldt_info);
18052 if (oldmode)
18053 ldt.avl = 0;
18054 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18055 index 5b19e4d..6476a76 100644
18056 --- a/arch/x86/kernel/machine_kexec_32.c
18057 +++ b/arch/x86/kernel/machine_kexec_32.c
18058 @@ -26,7 +26,7 @@
18059 #include <asm/cacheflush.h>
18060 #include <asm/debugreg.h>
18061
18062 -static void set_idt(void *newidt, __u16 limit)
18063 +static void set_idt(struct desc_struct *newidt, __u16 limit)
18064 {
18065 struct desc_ptr curidt;
18066
18067 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
18068 }
18069
18070
18071 -static void set_gdt(void *newgdt, __u16 limit)
18072 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18073 {
18074 struct desc_ptr curgdt;
18075
18076 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
18077 }
18078
18079 control_page = page_address(image->control_code_page);
18080 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18081 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18082
18083 relocate_kernel_ptr = control_page;
18084 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18085 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18086 index 0327e2b..e43737b 100644
18087 --- a/arch/x86/kernel/microcode_intel.c
18088 +++ b/arch/x86/kernel/microcode_intel.c
18089 @@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18090
18091 static int get_ucode_user(void *to, const void *from, size_t n)
18092 {
18093 - return copy_from_user(to, from, n);
18094 + return copy_from_user(to, (const void __force_user *)from, n);
18095 }
18096
18097 static enum ucode_state
18098 request_microcode_user(int cpu, const void __user *buf, size_t size)
18099 {
18100 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18101 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18102 }
18103
18104 static void microcode_fini_cpu(int cpu)
18105 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18106 index f21fd94..61565cd 100644
18107 --- a/arch/x86/kernel/module.c
18108 +++ b/arch/x86/kernel/module.c
18109 @@ -35,15 +35,60 @@
18110 #define DEBUGP(fmt...)
18111 #endif
18112
18113 -void *module_alloc(unsigned long size)
18114 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18115 {
18116 - if (PAGE_ALIGN(size) > MODULES_LEN)
18117 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18118 return NULL;
18119 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18120 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18121 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18122 -1, __builtin_return_address(0));
18123 }
18124
18125 +void *module_alloc(unsigned long size)
18126 +{
18127 +
18128 +#ifdef CONFIG_PAX_KERNEXEC
18129 + return __module_alloc(size, PAGE_KERNEL);
18130 +#else
18131 + return __module_alloc(size, PAGE_KERNEL_EXEC);
18132 +#endif
18133 +
18134 +}
18135 +
18136 +#ifdef CONFIG_PAX_KERNEXEC
18137 +#ifdef CONFIG_X86_32
18138 +void *module_alloc_exec(unsigned long size)
18139 +{
18140 + struct vm_struct *area;
18141 +
18142 + if (size == 0)
18143 + return NULL;
18144 +
18145 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18146 + return area ? area->addr : NULL;
18147 +}
18148 +EXPORT_SYMBOL(module_alloc_exec);
18149 +
18150 +void module_free_exec(struct module *mod, void *module_region)
18151 +{
18152 + vunmap(module_region);
18153 +}
18154 +EXPORT_SYMBOL(module_free_exec);
18155 +#else
18156 +void module_free_exec(struct module *mod, void *module_region)
18157 +{
18158 + module_free(mod, module_region);
18159 +}
18160 +EXPORT_SYMBOL(module_free_exec);
18161 +
18162 +void *module_alloc_exec(unsigned long size)
18163 +{
18164 + return __module_alloc(size, PAGE_KERNEL_RX);
18165 +}
18166 +EXPORT_SYMBOL(module_alloc_exec);
18167 +#endif
18168 +#endif
18169 +
18170 #ifdef CONFIG_X86_32
18171 int apply_relocate(Elf32_Shdr *sechdrs,
18172 const char *strtab,
18173 @@ -54,14 +99,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18174 unsigned int i;
18175 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18176 Elf32_Sym *sym;
18177 - uint32_t *location;
18178 + uint32_t *plocation, location;
18179
18180 DEBUGP("Applying relocate section %u to %u\n", relsec,
18181 sechdrs[relsec].sh_info);
18182 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18183 /* This is where to make the change */
18184 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18185 - + rel[i].r_offset;
18186 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18187 + location = (uint32_t)plocation;
18188 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18189 + plocation = ktla_ktva((void *)plocation);
18190 /* This is the symbol it is referring to. Note that all
18191 undefined symbols have been resolved. */
18192 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18193 @@ -70,11 +117,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18194 switch (ELF32_R_TYPE(rel[i].r_info)) {
18195 case R_386_32:
18196 /* We add the value into the location given */
18197 - *location += sym->st_value;
18198 + pax_open_kernel();
18199 + *plocation += sym->st_value;
18200 + pax_close_kernel();
18201 break;
18202 case R_386_PC32:
18203 /* Add the value, subtract its postition */
18204 - *location += sym->st_value - (uint32_t)location;
18205 + pax_open_kernel();
18206 + *plocation += sym->st_value - location;
18207 + pax_close_kernel();
18208 break;
18209 default:
18210 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
18211 @@ -119,21 +170,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18212 case R_X86_64_NONE:
18213 break;
18214 case R_X86_64_64:
18215 + pax_open_kernel();
18216 *(u64 *)loc = val;
18217 + pax_close_kernel();
18218 break;
18219 case R_X86_64_32:
18220 + pax_open_kernel();
18221 *(u32 *)loc = val;
18222 + pax_close_kernel();
18223 if (val != *(u32 *)loc)
18224 goto overflow;
18225 break;
18226 case R_X86_64_32S:
18227 + pax_open_kernel();
18228 *(s32 *)loc = val;
18229 + pax_close_kernel();
18230 if ((s64)val != *(s32 *)loc)
18231 goto overflow;
18232 break;
18233 case R_X86_64_PC32:
18234 val -= (u64)loc;
18235 + pax_open_kernel();
18236 *(u32 *)loc = val;
18237 + pax_close_kernel();
18238 +
18239 #if 0
18240 if ((s64)val != *(s32 *)loc)
18241 goto overflow;
18242 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18243 index 32856fa..ce95eaa 100644
18244 --- a/arch/x86/kernel/nmi.c
18245 +++ b/arch/x86/kernel/nmi.c
18246 @@ -507,6 +507,17 @@ static inline void nmi_nesting_postprocess(void)
18247 dotraplinkage notrace __kprobes void
18248 do_nmi(struct pt_regs *regs, long error_code)
18249 {
18250 +
18251 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18252 + if (!user_mode(regs)) {
18253 + unsigned long cs = regs->cs & 0xFFFF;
18254 + unsigned long ip = ktva_ktla(regs->ip);
18255 +
18256 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18257 + regs->ip = ip;
18258 + }
18259 +#endif
18260 +
18261 nmi_nesting_preprocess(regs);
18262
18263 nmi_enter();
18264 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18265 index 676b8c7..870ba04 100644
18266 --- a/arch/x86/kernel/paravirt-spinlocks.c
18267 +++ b/arch/x86/kernel/paravirt-spinlocks.c
18268 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18269 arch_spin_lock(lock);
18270 }
18271
18272 -struct pv_lock_ops pv_lock_ops = {
18273 +struct pv_lock_ops pv_lock_ops __read_only = {
18274 #ifdef CONFIG_SMP
18275 .spin_is_locked = __ticket_spin_is_locked,
18276 .spin_is_contended = __ticket_spin_is_contended,
18277 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18278 index ab13760..01218e0 100644
18279 --- a/arch/x86/kernel/paravirt.c
18280 +++ b/arch/x86/kernel/paravirt.c
18281 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18282 {
18283 return x;
18284 }
18285 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18286 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18287 +#endif
18288
18289 void __init default_banner(void)
18290 {
18291 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18292 if (opfunc == NULL)
18293 /* If there's no function, patch it with a ud2a (BUG) */
18294 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18295 - else if (opfunc == _paravirt_nop)
18296 + else if (opfunc == (void *)_paravirt_nop)
18297 /* If the operation is a nop, then nop the callsite */
18298 ret = paravirt_patch_nop();
18299
18300 /* identity functions just return their single argument */
18301 - else if (opfunc == _paravirt_ident_32)
18302 + else if (opfunc == (void *)_paravirt_ident_32)
18303 ret = paravirt_patch_ident_32(insnbuf, len);
18304 - else if (opfunc == _paravirt_ident_64)
18305 + else if (opfunc == (void *)_paravirt_ident_64)
18306 ret = paravirt_patch_ident_64(insnbuf, len);
18307 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18308 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18309 + ret = paravirt_patch_ident_64(insnbuf, len);
18310 +#endif
18311
18312 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18313 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18314 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18315 if (insn_len > len || start == NULL)
18316 insn_len = len;
18317 else
18318 - memcpy(insnbuf, start, insn_len);
18319 + memcpy(insnbuf, ktla_ktva(start), insn_len);
18320
18321 return insn_len;
18322 }
18323 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18324 preempt_enable();
18325 }
18326
18327 -struct pv_info pv_info = {
18328 +struct pv_info pv_info __read_only = {
18329 .name = "bare hardware",
18330 .paravirt_enabled = 0,
18331 .kernel_rpl = 0,
18332 @@ -315,16 +322,16 @@ struct pv_info pv_info = {
18333 #endif
18334 };
18335
18336 -struct pv_init_ops pv_init_ops = {
18337 +struct pv_init_ops pv_init_ops __read_only = {
18338 .patch = native_patch,
18339 };
18340
18341 -struct pv_time_ops pv_time_ops = {
18342 +struct pv_time_ops pv_time_ops __read_only = {
18343 .sched_clock = native_sched_clock,
18344 .steal_clock = native_steal_clock,
18345 };
18346
18347 -struct pv_irq_ops pv_irq_ops = {
18348 +struct pv_irq_ops pv_irq_ops __read_only = {
18349 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18350 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18351 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18352 @@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18353 #endif
18354 };
18355
18356 -struct pv_cpu_ops pv_cpu_ops = {
18357 +struct pv_cpu_ops pv_cpu_ops __read_only = {
18358 .cpuid = native_cpuid,
18359 .get_debugreg = native_get_debugreg,
18360 .set_debugreg = native_set_debugreg,
18361 @@ -397,21 +404,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18362 .end_context_switch = paravirt_nop,
18363 };
18364
18365 -struct pv_apic_ops pv_apic_ops = {
18366 +struct pv_apic_ops pv_apic_ops __read_only = {
18367 #ifdef CONFIG_X86_LOCAL_APIC
18368 .startup_ipi_hook = paravirt_nop,
18369 #endif
18370 };
18371
18372 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18373 +#ifdef CONFIG_X86_32
18374 +#ifdef CONFIG_X86_PAE
18375 +/* 64-bit pagetable entries */
18376 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18377 +#else
18378 /* 32-bit pagetable entries */
18379 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18380 +#endif
18381 #else
18382 /* 64-bit pagetable entries */
18383 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18384 #endif
18385
18386 -struct pv_mmu_ops pv_mmu_ops = {
18387 +struct pv_mmu_ops pv_mmu_ops __read_only = {
18388
18389 .read_cr2 = native_read_cr2,
18390 .write_cr2 = native_write_cr2,
18391 @@ -461,6 +473,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18392 .make_pud = PTE_IDENT,
18393
18394 .set_pgd = native_set_pgd,
18395 + .set_pgd_batched = native_set_pgd_batched,
18396 #endif
18397 #endif /* PAGETABLE_LEVELS >= 3 */
18398
18399 @@ -480,6 +493,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18400 },
18401
18402 .set_fixmap = native_set_fixmap,
18403 +
18404 +#ifdef CONFIG_PAX_KERNEXEC
18405 + .pax_open_kernel = native_pax_open_kernel,
18406 + .pax_close_kernel = native_pax_close_kernel,
18407 +#endif
18408 +
18409 };
18410
18411 EXPORT_SYMBOL_GPL(pv_time_ops);
18412 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18413 index 35ccf75..7a15747 100644
18414 --- a/arch/x86/kernel/pci-iommu_table.c
18415 +++ b/arch/x86/kernel/pci-iommu_table.c
18416 @@ -2,7 +2,7 @@
18417 #include <asm/iommu_table.h>
18418 #include <linux/string.h>
18419 #include <linux/kallsyms.h>
18420 -
18421 +#include <linux/sched.h>
18422
18423 #define DEBUG 1
18424
18425 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18426 index 1d92a5a..7bc8c29 100644
18427 --- a/arch/x86/kernel/process.c
18428 +++ b/arch/x86/kernel/process.c
18429 @@ -69,16 +69,33 @@ void free_thread_xstate(struct task_struct *tsk)
18430
18431 void free_thread_info(struct thread_info *ti)
18432 {
18433 - free_thread_xstate(ti->task);
18434 free_pages((unsigned long)ti, THREAD_ORDER);
18435 }
18436
18437 +static struct kmem_cache *task_struct_cachep;
18438 +
18439 void arch_task_cache_init(void)
18440 {
18441 - task_xstate_cachep =
18442 - kmem_cache_create("task_xstate", xstate_size,
18443 + /* create a slab on which task_structs can be allocated */
18444 + task_struct_cachep =
18445 + kmem_cache_create("task_struct", sizeof(struct task_struct),
18446 + ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
18447 +
18448 + task_xstate_cachep =
18449 + kmem_cache_create("task_xstate", xstate_size,
18450 __alignof__(union thread_xstate),
18451 - SLAB_PANIC | SLAB_NOTRACK, NULL);
18452 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18453 +}
18454 +
18455 +struct task_struct *alloc_task_struct_node(int node)
18456 +{
18457 + return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
18458 +}
18459 +
18460 +void free_task_struct(struct task_struct *task)
18461 +{
18462 + free_thread_xstate(task);
18463 + kmem_cache_free(task_struct_cachep, task);
18464 }
18465
18466 /*
18467 @@ -91,7 +108,7 @@ void exit_thread(void)
18468 unsigned long *bp = t->io_bitmap_ptr;
18469
18470 if (bp) {
18471 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18472 + struct tss_struct *tss = init_tss + get_cpu();
18473
18474 t->io_bitmap_ptr = NULL;
18475 clear_thread_flag(TIF_IO_BITMAP);
18476 @@ -127,7 +144,7 @@ void show_regs_common(void)
18477
18478 printk(KERN_CONT "\n");
18479 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
18480 - current->pid, current->comm, print_tainted(),
18481 + task_pid_nr(current), current->comm, print_tainted(),
18482 init_utsname()->release,
18483 (int)strcspn(init_utsname()->version, " "),
18484 init_utsname()->version);
18485 @@ -141,6 +158,9 @@ void flush_thread(void)
18486 {
18487 struct task_struct *tsk = current;
18488
18489 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18490 + loadsegment(gs, 0);
18491 +#endif
18492 flush_ptrace_hw_breakpoint(tsk);
18493 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18494 /*
18495 @@ -303,10 +323,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18496 regs.di = (unsigned long) arg;
18497
18498 #ifdef CONFIG_X86_32
18499 - regs.ds = __USER_DS;
18500 - regs.es = __USER_DS;
18501 + regs.ds = __KERNEL_DS;
18502 + regs.es = __KERNEL_DS;
18503 regs.fs = __KERNEL_PERCPU;
18504 - regs.gs = __KERNEL_STACK_CANARY;
18505 + savesegment(gs, regs.gs);
18506 #else
18507 regs.ss = __KERNEL_DS;
18508 #endif
18509 @@ -392,7 +412,7 @@ static void __exit_idle(void)
18510 void exit_idle(void)
18511 {
18512 /* idle loop has pid 0 */
18513 - if (current->pid)
18514 + if (task_pid_nr(current))
18515 return;
18516 __exit_idle();
18517 }
18518 @@ -501,7 +521,7 @@ bool set_pm_idle_to_default(void)
18519
18520 return ret;
18521 }
18522 -void stop_this_cpu(void *dummy)
18523 +__noreturn void stop_this_cpu(void *dummy)
18524 {
18525 local_irq_disable();
18526 /*
18527 @@ -743,16 +763,37 @@ static int __init idle_setup(char *str)
18528 }
18529 early_param("idle", idle_setup);
18530
18531 -unsigned long arch_align_stack(unsigned long sp)
18532 +#ifdef CONFIG_PAX_RANDKSTACK
18533 +void pax_randomize_kstack(struct pt_regs *regs)
18534 {
18535 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18536 - sp -= get_random_int() % 8192;
18537 - return sp & ~0xf;
18538 -}
18539 + struct thread_struct *thread = &current->thread;
18540 + unsigned long time;
18541
18542 -unsigned long arch_randomize_brk(struct mm_struct *mm)
18543 -{
18544 - unsigned long range_end = mm->brk + 0x02000000;
18545 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18546 -}
18547 + if (!randomize_va_space)
18548 + return;
18549 +
18550 + if (v8086_mode(regs))
18551 + return;
18552
18553 + rdtscl(time);
18554 +
18555 + /* P4 seems to return a 0 LSB, ignore it */
18556 +#ifdef CONFIG_MPENTIUM4
18557 + time &= 0x3EUL;
18558 + time <<= 2;
18559 +#elif defined(CONFIG_X86_64)
18560 + time &= 0xFUL;
18561 + time <<= 4;
18562 +#else
18563 + time &= 0x1FUL;
18564 + time <<= 3;
18565 +#endif
18566 +
18567 + thread->sp0 ^= time;
18568 + load_sp0(init_tss + smp_processor_id(), thread);
18569 +
18570 +#ifdef CONFIG_X86_64
18571 + percpu_write(kernel_stack, thread->sp0);
18572 +#endif
18573 +}
18574 +#endif
18575 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18576 index ae68473..7b0bb71 100644
18577 --- a/arch/x86/kernel/process_32.c
18578 +++ b/arch/x86/kernel/process_32.c
18579 @@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18580 unsigned long thread_saved_pc(struct task_struct *tsk)
18581 {
18582 return ((unsigned long *)tsk->thread.sp)[3];
18583 +//XXX return tsk->thread.eip;
18584 }
18585
18586 void __show_regs(struct pt_regs *regs, int all)
18587 @@ -73,15 +74,14 @@ void __show_regs(struct pt_regs *regs, int all)
18588 unsigned long sp;
18589 unsigned short ss, gs;
18590
18591 - if (user_mode_vm(regs)) {
18592 + if (user_mode(regs)) {
18593 sp = regs->sp;
18594 ss = regs->ss & 0xffff;
18595 - gs = get_user_gs(regs);
18596 } else {
18597 sp = kernel_stack_pointer(regs);
18598 savesegment(ss, ss);
18599 - savesegment(gs, gs);
18600 }
18601 + gs = get_user_gs(regs);
18602
18603 show_regs_common();
18604
18605 @@ -143,13 +143,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18606 struct task_struct *tsk;
18607 int err;
18608
18609 - childregs = task_pt_regs(p);
18610 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18611 *childregs = *regs;
18612 childregs->ax = 0;
18613 childregs->sp = sp;
18614
18615 p->thread.sp = (unsigned long) childregs;
18616 p->thread.sp0 = (unsigned long) (childregs+1);
18617 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18618
18619 p->thread.ip = (unsigned long) ret_from_fork;
18620
18621 @@ -240,7 +241,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18622 struct thread_struct *prev = &prev_p->thread,
18623 *next = &next_p->thread;
18624 int cpu = smp_processor_id();
18625 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18626 + struct tss_struct *tss = init_tss + cpu;
18627 fpu_switch_t fpu;
18628
18629 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18630 @@ -264,6 +265,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18631 */
18632 lazy_save_gs(prev->gs);
18633
18634 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18635 + __set_fs(task_thread_info(next_p)->addr_limit);
18636 +#endif
18637 +
18638 /*
18639 * Load the per-thread Thread-Local Storage descriptor.
18640 */
18641 @@ -294,6 +299,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18642 */
18643 arch_end_context_switch(next_p);
18644
18645 + percpu_write(current_task, next_p);
18646 + percpu_write(current_tinfo, &next_p->tinfo);
18647 +
18648 /*
18649 * Restore %gs if needed (which is common)
18650 */
18651 @@ -302,8 +310,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18652
18653 switch_fpu_finish(next_p, fpu);
18654
18655 - percpu_write(current_task, next_p);
18656 -
18657 return prev_p;
18658 }
18659
18660 @@ -333,4 +339,3 @@ unsigned long get_wchan(struct task_struct *p)
18661 } while (count++ < 16);
18662 return 0;
18663 }
18664 -
18665 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18666 index 43d8b48..c45d566 100644
18667 --- a/arch/x86/kernel/process_64.c
18668 +++ b/arch/x86/kernel/process_64.c
18669 @@ -162,8 +162,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18670 struct pt_regs *childregs;
18671 struct task_struct *me = current;
18672
18673 - childregs = ((struct pt_regs *)
18674 - (THREAD_SIZE + task_stack_page(p))) - 1;
18675 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18676 *childregs = *regs;
18677
18678 childregs->ax = 0;
18679 @@ -175,6 +174,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18680 p->thread.sp = (unsigned long) childregs;
18681 p->thread.sp0 = (unsigned long) (childregs+1);
18682 p->thread.usersp = me->thread.usersp;
18683 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18684
18685 set_tsk_thread_flag(p, TIF_FORK);
18686
18687 @@ -280,7 +280,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18688 struct thread_struct *prev = &prev_p->thread;
18689 struct thread_struct *next = &next_p->thread;
18690 int cpu = smp_processor_id();
18691 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18692 + struct tss_struct *tss = init_tss + cpu;
18693 unsigned fsindex, gsindex;
18694 fpu_switch_t fpu;
18695
18696 @@ -362,10 +362,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18697 prev->usersp = percpu_read(old_rsp);
18698 percpu_write(old_rsp, next->usersp);
18699 percpu_write(current_task, next_p);
18700 + percpu_write(current_tinfo, &next_p->tinfo);
18701
18702 - percpu_write(kernel_stack,
18703 - (unsigned long)task_stack_page(next_p) +
18704 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18705 + percpu_write(kernel_stack, next->sp0);
18706
18707 /*
18708 * Now maybe reload the debug registers and handle I/O bitmaps
18709 @@ -434,12 +433,11 @@ unsigned long get_wchan(struct task_struct *p)
18710 if (!p || p == current || p->state == TASK_RUNNING)
18711 return 0;
18712 stack = (unsigned long)task_stack_page(p);
18713 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18714 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18715 return 0;
18716 fp = *(u64 *)(p->thread.sp);
18717 do {
18718 - if (fp < (unsigned long)stack ||
18719 - fp >= (unsigned long)stack+THREAD_SIZE)
18720 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18721 return 0;
18722 ip = *(u64 *)(fp+8);
18723 if (!in_sched_functions(ip))
18724 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18725 index cf11783..e7ce551 100644
18726 --- a/arch/x86/kernel/ptrace.c
18727 +++ b/arch/x86/kernel/ptrace.c
18728 @@ -824,7 +824,7 @@ long arch_ptrace(struct task_struct *child, long request,
18729 unsigned long addr, unsigned long data)
18730 {
18731 int ret;
18732 - unsigned long __user *datap = (unsigned long __user *)data;
18733 + unsigned long __user *datap = (__force unsigned long __user *)data;
18734
18735 switch (request) {
18736 /* read the word at location addr in the USER area. */
18737 @@ -909,14 +909,14 @@ long arch_ptrace(struct task_struct *child, long request,
18738 if ((int) addr < 0)
18739 return -EIO;
18740 ret = do_get_thread_area(child, addr,
18741 - (struct user_desc __user *)data);
18742 + (__force struct user_desc __user *) data);
18743 break;
18744
18745 case PTRACE_SET_THREAD_AREA:
18746 if ((int) addr < 0)
18747 return -EIO;
18748 ret = do_set_thread_area(child, addr,
18749 - (struct user_desc __user *)data, 0);
18750 + (__force struct user_desc __user *) data, 0);
18751 break;
18752 #endif
18753
18754 @@ -1426,7 +1426,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18755 memset(info, 0, sizeof(*info));
18756 info->si_signo = SIGTRAP;
18757 info->si_code = si_code;
18758 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18759 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18760 }
18761
18762 void user_single_step_siginfo(struct task_struct *tsk,
18763 @@ -1455,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18764 # define IS_IA32 0
18765 #endif
18766
18767 +#ifdef CONFIG_GRKERNSEC_SETXID
18768 +extern void gr_delayed_cred_worker(void);
18769 +#endif
18770 +
18771 /*
18772 * We must return the syscall number to actually look up in the table.
18773 * This can be -1L to skip running any syscall at all.
18774 @@ -1463,6 +1467,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18775 {
18776 long ret = 0;
18777
18778 +#ifdef CONFIG_GRKERNSEC_SETXID
18779 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18780 + gr_delayed_cred_worker();
18781 +#endif
18782 +
18783 /*
18784 * If we stepped into a sysenter/syscall insn, it trapped in
18785 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18786 @@ -1506,6 +1515,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18787 {
18788 bool step;
18789
18790 +#ifdef CONFIG_GRKERNSEC_SETXID
18791 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18792 + gr_delayed_cred_worker();
18793 +#endif
18794 +
18795 audit_syscall_exit(regs);
18796
18797 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18798 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18799 index 42eb330..139955c 100644
18800 --- a/arch/x86/kernel/pvclock.c
18801 +++ b/arch/x86/kernel/pvclock.c
18802 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18803 return pv_tsc_khz;
18804 }
18805
18806 -static atomic64_t last_value = ATOMIC64_INIT(0);
18807 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18808
18809 void pvclock_resume(void)
18810 {
18811 - atomic64_set(&last_value, 0);
18812 + atomic64_set_unchecked(&last_value, 0);
18813 }
18814
18815 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18816 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18817 * updating at the same time, and one of them could be slightly behind,
18818 * making the assumption that last_value always go forward fail to hold.
18819 */
18820 - last = atomic64_read(&last_value);
18821 + last = atomic64_read_unchecked(&last_value);
18822 do {
18823 if (ret < last)
18824 return last;
18825 - last = atomic64_cmpxchg(&last_value, last, ret);
18826 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18827 } while (unlikely(last != ret));
18828
18829 return ret;
18830 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18831 index 3034ee5..7cfbfa6 100644
18832 --- a/arch/x86/kernel/reboot.c
18833 +++ b/arch/x86/kernel/reboot.c
18834 @@ -35,7 +35,7 @@ void (*pm_power_off)(void);
18835 EXPORT_SYMBOL(pm_power_off);
18836
18837 static const struct desc_ptr no_idt = {};
18838 -static int reboot_mode;
18839 +static unsigned short reboot_mode;
18840 enum reboot_type reboot_type = BOOT_ACPI;
18841 int reboot_force;
18842
18843 @@ -335,13 +335,17 @@ core_initcall(reboot_init);
18844 extern const unsigned char machine_real_restart_asm[];
18845 extern const u64 machine_real_restart_gdt[3];
18846
18847 -void machine_real_restart(unsigned int type)
18848 +__noreturn void machine_real_restart(unsigned int type)
18849 {
18850 void *restart_va;
18851 unsigned long restart_pa;
18852 - void (*restart_lowmem)(unsigned int);
18853 + void (* __noreturn restart_lowmem)(unsigned int);
18854 u64 *lowmem_gdt;
18855
18856 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18857 + struct desc_struct *gdt;
18858 +#endif
18859 +
18860 local_irq_disable();
18861
18862 /* Write zero to CMOS register number 0x0f, which the BIOS POST
18863 @@ -367,14 +371,14 @@ void machine_real_restart(unsigned int type)
18864 boot)". This seems like a fairly standard thing that gets set by
18865 REBOOT.COM programs, and the previous reset routine did this
18866 too. */
18867 - *((unsigned short *)0x472) = reboot_mode;
18868 + *(unsigned short *)(__va(0x472)) = reboot_mode;
18869
18870 /* Patch the GDT in the low memory trampoline */
18871 lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt);
18872
18873 restart_va = TRAMPOLINE_SYM(machine_real_restart_asm);
18874 restart_pa = virt_to_phys(restart_va);
18875 - restart_lowmem = (void (*)(unsigned int))restart_pa;
18876 + restart_lowmem = (void *)restart_pa;
18877
18878 /* GDT[0]: GDT self-pointer */
18879 lowmem_gdt[0] =
18880 @@ -385,7 +389,33 @@ void machine_real_restart(unsigned int type)
18881 GDT_ENTRY(0x009b, restart_pa, 0xffff);
18882
18883 /* Jump to the identity-mapped low memory code */
18884 +
18885 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18886 + gdt = get_cpu_gdt_table(smp_processor_id());
18887 + pax_open_kernel();
18888 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18889 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18890 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18891 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
18892 +#endif
18893 +#ifdef CONFIG_PAX_KERNEXEC
18894 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18895 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18896 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18897 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18898 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18899 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18900 +#endif
18901 + pax_close_kernel();
18902 +#endif
18903 +
18904 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18905 + asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
18906 + unreachable();
18907 +#else
18908 restart_lowmem(type);
18909 +#endif
18910 +
18911 }
18912 #ifdef CONFIG_APM_MODULE
18913 EXPORT_SYMBOL(machine_real_restart);
18914 @@ -564,7 +594,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18915 * try to force a triple fault and then cycle between hitting the keyboard
18916 * controller and doing that
18917 */
18918 -static void native_machine_emergency_restart(void)
18919 +__noreturn static void native_machine_emergency_restart(void)
18920 {
18921 int i;
18922 int attempt = 0;
18923 @@ -688,13 +718,13 @@ void native_machine_shutdown(void)
18924 #endif
18925 }
18926
18927 -static void __machine_emergency_restart(int emergency)
18928 +static __noreturn void __machine_emergency_restart(int emergency)
18929 {
18930 reboot_emergency = emergency;
18931 machine_ops.emergency_restart();
18932 }
18933
18934 -static void native_machine_restart(char *__unused)
18935 +static __noreturn void native_machine_restart(char *__unused)
18936 {
18937 printk("machine restart\n");
18938
18939 @@ -703,7 +733,7 @@ static void native_machine_restart(char *__unused)
18940 __machine_emergency_restart(0);
18941 }
18942
18943 -static void native_machine_halt(void)
18944 +static __noreturn void native_machine_halt(void)
18945 {
18946 /* stop other cpus and apics */
18947 machine_shutdown();
18948 @@ -714,7 +744,7 @@ static void native_machine_halt(void)
18949 stop_this_cpu(NULL);
18950 }
18951
18952 -static void native_machine_power_off(void)
18953 +__noreturn static void native_machine_power_off(void)
18954 {
18955 if (pm_power_off) {
18956 if (!reboot_force)
18957 @@ -723,6 +753,7 @@ static void native_machine_power_off(void)
18958 }
18959 /* a fallback in case there is no PM info available */
18960 tboot_shutdown(TB_SHUTDOWN_HALT);
18961 + unreachable();
18962 }
18963
18964 struct machine_ops machine_ops = {
18965 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
18966 index 7a6f3b3..bed145d7 100644
18967 --- a/arch/x86/kernel/relocate_kernel_64.S
18968 +++ b/arch/x86/kernel/relocate_kernel_64.S
18969 @@ -11,6 +11,7 @@
18970 #include <asm/kexec.h>
18971 #include <asm/processor-flags.h>
18972 #include <asm/pgtable_types.h>
18973 +#include <asm/alternative-asm.h>
18974
18975 /*
18976 * Must be relocatable PIC code callable as a C function
18977 @@ -160,13 +161,14 @@ identity_mapped:
18978 xorq %rbp, %rbp
18979 xorq %r8, %r8
18980 xorq %r9, %r9
18981 - xorq %r10, %r9
18982 + xorq %r10, %r10
18983 xorq %r11, %r11
18984 xorq %r12, %r12
18985 xorq %r13, %r13
18986 xorq %r14, %r14
18987 xorq %r15, %r15
18988
18989 + pax_force_retaddr 0, 1
18990 ret
18991
18992 1:
18993 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
18994 index 1a29015..712f324 100644
18995 --- a/arch/x86/kernel/setup.c
18996 +++ b/arch/x86/kernel/setup.c
18997 @@ -447,7 +447,7 @@ static void __init parse_setup_data(void)
18998
18999 switch (data->type) {
19000 case SETUP_E820_EXT:
19001 - parse_e820_ext(data);
19002 + parse_e820_ext((struct setup_data __force_kernel *)data);
19003 break;
19004 case SETUP_DTB:
19005 add_dtb(pa_data);
19006 @@ -639,7 +639,7 @@ static void __init trim_bios_range(void)
19007 * area (640->1Mb) as ram even though it is not.
19008 * take them out.
19009 */
19010 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
19011 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
19012 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
19013 }
19014
19015 @@ -763,14 +763,14 @@ void __init setup_arch(char **cmdline_p)
19016
19017 if (!boot_params.hdr.root_flags)
19018 root_mountflags &= ~MS_RDONLY;
19019 - init_mm.start_code = (unsigned long) _text;
19020 - init_mm.end_code = (unsigned long) _etext;
19021 + init_mm.start_code = ktla_ktva((unsigned long) _text);
19022 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
19023 init_mm.end_data = (unsigned long) _edata;
19024 init_mm.brk = _brk_end;
19025
19026 - code_resource.start = virt_to_phys(_text);
19027 - code_resource.end = virt_to_phys(_etext)-1;
19028 - data_resource.start = virt_to_phys(_etext);
19029 + code_resource.start = virt_to_phys(ktla_ktva(_text));
19030 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
19031 + data_resource.start = virt_to_phys(_sdata);
19032 data_resource.end = virt_to_phys(_edata)-1;
19033 bss_resource.start = virt_to_phys(&__bss_start);
19034 bss_resource.end = virt_to_phys(&__bss_stop)-1;
19035 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
19036 index 5a98aa2..2f9288d 100644
19037 --- a/arch/x86/kernel/setup_percpu.c
19038 +++ b/arch/x86/kernel/setup_percpu.c
19039 @@ -21,19 +21,17 @@
19040 #include <asm/cpu.h>
19041 #include <asm/stackprotector.h>
19042
19043 -DEFINE_PER_CPU(int, cpu_number);
19044 +#ifdef CONFIG_SMP
19045 +DEFINE_PER_CPU(unsigned int, cpu_number);
19046 EXPORT_PER_CPU_SYMBOL(cpu_number);
19047 +#endif
19048
19049 -#ifdef CONFIG_X86_64
19050 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
19051 -#else
19052 -#define BOOT_PERCPU_OFFSET 0
19053 -#endif
19054
19055 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
19056 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
19057
19058 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
19059 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
19060 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19061 };
19062 EXPORT_SYMBOL(__per_cpu_offset);
19063 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
19064 {
19065 #ifdef CONFIG_X86_32
19066 struct desc_struct gdt;
19067 + unsigned long base = per_cpu_offset(cpu);
19068
19069 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19070 - 0x2 | DESCTYPE_S, 0x8);
19071 - gdt.s = 1;
19072 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19073 + 0x83 | DESCTYPE_S, 0xC);
19074 write_gdt_entry(get_cpu_gdt_table(cpu),
19075 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19076 #endif
19077 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
19078 /* alrighty, percpu areas up and running */
19079 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19080 for_each_possible_cpu(cpu) {
19081 +#ifdef CONFIG_CC_STACKPROTECTOR
19082 +#ifdef CONFIG_X86_32
19083 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
19084 +#endif
19085 +#endif
19086 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19087 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19088 per_cpu(cpu_number, cpu) = cpu;
19089 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
19090 */
19091 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
19092 #endif
19093 +#ifdef CONFIG_CC_STACKPROTECTOR
19094 +#ifdef CONFIG_X86_32
19095 + if (!cpu)
19096 + per_cpu(stack_canary.canary, cpu) = canary;
19097 +#endif
19098 +#endif
19099 /*
19100 * Up to this point, the boot CPU has been using .init.data
19101 * area. Reload any changed state for the boot CPU.
19102 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19103 index 115eac4..c0591d5 100644
19104 --- a/arch/x86/kernel/signal.c
19105 +++ b/arch/x86/kernel/signal.c
19106 @@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
19107 * Align the stack pointer according to the i386 ABI,
19108 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19109 */
19110 - sp = ((sp + 4) & -16ul) - 4;
19111 + sp = ((sp - 12) & -16ul) - 4;
19112 #else /* !CONFIG_X86_32 */
19113 sp = round_down(sp, 16) - 8;
19114 #endif
19115 @@ -241,11 +241,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19116 * Return an always-bogus address instead so we will die with SIGSEGV.
19117 */
19118 if (onsigstack && !likely(on_sig_stack(sp)))
19119 - return (void __user *)-1L;
19120 + return (__force void __user *)-1L;
19121
19122 /* save i387 state */
19123 if (used_math() && save_i387_xstate(*fpstate) < 0)
19124 - return (void __user *)-1L;
19125 + return (__force void __user *)-1L;
19126
19127 return (void __user *)sp;
19128 }
19129 @@ -300,9 +300,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19130 }
19131
19132 if (current->mm->context.vdso)
19133 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19134 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19135 else
19136 - restorer = &frame->retcode;
19137 + restorer = (void __user *)&frame->retcode;
19138 if (ka->sa.sa_flags & SA_RESTORER)
19139 restorer = ka->sa.sa_restorer;
19140
19141 @@ -316,7 +316,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19142 * reasons and because gdb uses it as a signature to notice
19143 * signal handler stack frames.
19144 */
19145 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19146 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19147
19148 if (err)
19149 return -EFAULT;
19150 @@ -370,7 +370,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19151 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19152
19153 /* Set up to return from userspace. */
19154 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19155 + if (current->mm->context.vdso)
19156 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19157 + else
19158 + restorer = (void __user *)&frame->retcode;
19159 if (ka->sa.sa_flags & SA_RESTORER)
19160 restorer = ka->sa.sa_restorer;
19161 put_user_ex(restorer, &frame->pretcode);
19162 @@ -382,7 +385,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19163 * reasons and because gdb uses it as a signature to notice
19164 * signal handler stack frames.
19165 */
19166 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19167 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19168 } put_user_catch(err);
19169
19170 if (err)
19171 @@ -773,7 +776,7 @@ static void do_signal(struct pt_regs *regs)
19172 * X86_32: vm86 regs switched out by assembly code before reaching
19173 * here, so testing against kernel CS suffices.
19174 */
19175 - if (!user_mode(regs))
19176 + if (!user_mode_novm(regs))
19177 return;
19178
19179 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
19180 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19181 index 6e1e406..edfb7cb 100644
19182 --- a/arch/x86/kernel/smpboot.c
19183 +++ b/arch/x86/kernel/smpboot.c
19184 @@ -699,17 +699,20 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)
19185 set_idle_for_cpu(cpu, c_idle.idle);
19186 do_rest:
19187 per_cpu(current_task, cpu) = c_idle.idle;
19188 + per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
19189 #ifdef CONFIG_X86_32
19190 /* Stack for startup_32 can be just as for start_secondary onwards */
19191 irq_ctx_init(cpu);
19192 #else
19193 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
19194 initial_gs = per_cpu_offset(cpu);
19195 - per_cpu(kernel_stack, cpu) =
19196 - (unsigned long)task_stack_page(c_idle.idle) -
19197 - KERNEL_STACK_OFFSET + THREAD_SIZE;
19198 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
19199 #endif
19200 +
19201 + pax_open_kernel();
19202 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19203 + pax_close_kernel();
19204 +
19205 initial_code = (unsigned long)start_secondary;
19206 stack_start = c_idle.idle->thread.sp;
19207
19208 @@ -851,6 +854,12 @@ int __cpuinit native_cpu_up(unsigned int cpu)
19209
19210 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19211
19212 +#ifdef CONFIG_PAX_PER_CPU_PGD
19213 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19214 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19215 + KERNEL_PGD_PTRS);
19216 +#endif
19217 +
19218 err = do_boot_cpu(apicid, cpu);
19219 if (err) {
19220 pr_debug("do_boot_cpu failed %d\n", err);
19221 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19222 index c346d11..d43b163 100644
19223 --- a/arch/x86/kernel/step.c
19224 +++ b/arch/x86/kernel/step.c
19225 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19226 struct desc_struct *desc;
19227 unsigned long base;
19228
19229 - seg &= ~7UL;
19230 + seg >>= 3;
19231
19232 mutex_lock(&child->mm->context.lock);
19233 - if (unlikely((seg >> 3) >= child->mm->context.size))
19234 + if (unlikely(seg >= child->mm->context.size))
19235 addr = -1L; /* bogus selector, access would fault */
19236 else {
19237 desc = child->mm->context.ldt + seg;
19238 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19239 addr += base;
19240 }
19241 mutex_unlock(&child->mm->context.lock);
19242 - }
19243 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19244 + addr = ktla_ktva(addr);
19245
19246 return addr;
19247 }
19248 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19249 unsigned char opcode[15];
19250 unsigned long addr = convert_ip_to_linear(child, regs);
19251
19252 + if (addr == -EINVAL)
19253 + return 0;
19254 +
19255 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19256 for (i = 0; i < copied; i++) {
19257 switch (opcode[i]) {
19258 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19259 index 0b0cb5f..db6b9ed 100644
19260 --- a/arch/x86/kernel/sys_i386_32.c
19261 +++ b/arch/x86/kernel/sys_i386_32.c
19262 @@ -24,17 +24,224 @@
19263
19264 #include <asm/syscalls.h>
19265
19266 -/*
19267 - * Do a system call from kernel instead of calling sys_execve so we
19268 - * end up with proper pt_regs.
19269 - */
19270 -int kernel_execve(const char *filename,
19271 - const char *const argv[],
19272 - const char *const envp[])
19273 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19274 {
19275 - long __res;
19276 - asm volatile ("int $0x80"
19277 - : "=a" (__res)
19278 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19279 - return __res;
19280 + unsigned long pax_task_size = TASK_SIZE;
19281 +
19282 +#ifdef CONFIG_PAX_SEGMEXEC
19283 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19284 + pax_task_size = SEGMEXEC_TASK_SIZE;
19285 +#endif
19286 +
19287 + if (len > pax_task_size || addr > pax_task_size - len)
19288 + return -EINVAL;
19289 +
19290 + return 0;
19291 +}
19292 +
19293 +unsigned long
19294 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
19295 + unsigned long len, unsigned long pgoff, unsigned long flags)
19296 +{
19297 + struct mm_struct *mm = current->mm;
19298 + struct vm_area_struct *vma;
19299 + unsigned long start_addr, pax_task_size = TASK_SIZE;
19300 +
19301 +#ifdef CONFIG_PAX_SEGMEXEC
19302 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19303 + pax_task_size = SEGMEXEC_TASK_SIZE;
19304 +#endif
19305 +
19306 + pax_task_size -= PAGE_SIZE;
19307 +
19308 + if (len > pax_task_size)
19309 + return -ENOMEM;
19310 +
19311 + if (flags & MAP_FIXED)
19312 + return addr;
19313 +
19314 +#ifdef CONFIG_PAX_RANDMMAP
19315 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19316 +#endif
19317 +
19318 + if (addr) {
19319 + addr = PAGE_ALIGN(addr);
19320 + if (pax_task_size - len >= addr) {
19321 + vma = find_vma(mm, addr);
19322 + if (check_heap_stack_gap(vma, addr, len))
19323 + return addr;
19324 + }
19325 + }
19326 + if (len > mm->cached_hole_size) {
19327 + start_addr = addr = mm->free_area_cache;
19328 + } else {
19329 + start_addr = addr = mm->mmap_base;
19330 + mm->cached_hole_size = 0;
19331 + }
19332 +
19333 +#ifdef CONFIG_PAX_PAGEEXEC
19334 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19335 + start_addr = 0x00110000UL;
19336 +
19337 +#ifdef CONFIG_PAX_RANDMMAP
19338 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19339 + start_addr += mm->delta_mmap & 0x03FFF000UL;
19340 +#endif
19341 +
19342 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19343 + start_addr = addr = mm->mmap_base;
19344 + else
19345 + addr = start_addr;
19346 + }
19347 +#endif
19348 +
19349 +full_search:
19350 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19351 + /* At this point: (!vma || addr < vma->vm_end). */
19352 + if (pax_task_size - len < addr) {
19353 + /*
19354 + * Start a new search - just in case we missed
19355 + * some holes.
19356 + */
19357 + if (start_addr != mm->mmap_base) {
19358 + start_addr = addr = mm->mmap_base;
19359 + mm->cached_hole_size = 0;
19360 + goto full_search;
19361 + }
19362 + return -ENOMEM;
19363 + }
19364 + if (check_heap_stack_gap(vma, addr, len))
19365 + break;
19366 + if (addr + mm->cached_hole_size < vma->vm_start)
19367 + mm->cached_hole_size = vma->vm_start - addr;
19368 + addr = vma->vm_end;
19369 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
19370 + start_addr = addr = mm->mmap_base;
19371 + mm->cached_hole_size = 0;
19372 + goto full_search;
19373 + }
19374 + }
19375 +
19376 + /*
19377 + * Remember the place where we stopped the search:
19378 + */
19379 + mm->free_area_cache = addr + len;
19380 + return addr;
19381 +}
19382 +
19383 +unsigned long
19384 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19385 + const unsigned long len, const unsigned long pgoff,
19386 + const unsigned long flags)
19387 +{
19388 + struct vm_area_struct *vma;
19389 + struct mm_struct *mm = current->mm;
19390 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19391 +
19392 +#ifdef CONFIG_PAX_SEGMEXEC
19393 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19394 + pax_task_size = SEGMEXEC_TASK_SIZE;
19395 +#endif
19396 +
19397 + pax_task_size -= PAGE_SIZE;
19398 +
19399 + /* requested length too big for entire address space */
19400 + if (len > pax_task_size)
19401 + return -ENOMEM;
19402 +
19403 + if (flags & MAP_FIXED)
19404 + return addr;
19405 +
19406 +#ifdef CONFIG_PAX_PAGEEXEC
19407 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19408 + goto bottomup;
19409 +#endif
19410 +
19411 +#ifdef CONFIG_PAX_RANDMMAP
19412 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19413 +#endif
19414 +
19415 + /* requesting a specific address */
19416 + if (addr) {
19417 + addr = PAGE_ALIGN(addr);
19418 + if (pax_task_size - len >= addr) {
19419 + vma = find_vma(mm, addr);
19420 + if (check_heap_stack_gap(vma, addr, len))
19421 + return addr;
19422 + }
19423 + }
19424 +
19425 + /* check if free_area_cache is useful for us */
19426 + if (len <= mm->cached_hole_size) {
19427 + mm->cached_hole_size = 0;
19428 + mm->free_area_cache = mm->mmap_base;
19429 + }
19430 +
19431 + /* either no address requested or can't fit in requested address hole */
19432 + addr = mm->free_area_cache;
19433 +
19434 + /* make sure it can fit in the remaining address space */
19435 + if (addr > len) {
19436 + vma = find_vma(mm, addr-len);
19437 + if (check_heap_stack_gap(vma, addr - len, len))
19438 + /* remember the address as a hint for next time */
19439 + return (mm->free_area_cache = addr-len);
19440 + }
19441 +
19442 + if (mm->mmap_base < len)
19443 + goto bottomup;
19444 +
19445 + addr = mm->mmap_base-len;
19446 +
19447 + do {
19448 + /*
19449 + * Lookup failure means no vma is above this address,
19450 + * else if new region fits below vma->vm_start,
19451 + * return with success:
19452 + */
19453 + vma = find_vma(mm, addr);
19454 + if (check_heap_stack_gap(vma, addr, len))
19455 + /* remember the address as a hint for next time */
19456 + return (mm->free_area_cache = addr);
19457 +
19458 + /* remember the largest hole we saw so far */
19459 + if (addr + mm->cached_hole_size < vma->vm_start)
19460 + mm->cached_hole_size = vma->vm_start - addr;
19461 +
19462 + /* try just below the current vma->vm_start */
19463 + addr = skip_heap_stack_gap(vma, len);
19464 + } while (!IS_ERR_VALUE(addr));
19465 +
19466 +bottomup:
19467 + /*
19468 + * A failed mmap() very likely causes application failure,
19469 + * so fall back to the bottom-up function here. This scenario
19470 + * can happen with large stack limits and large mmap()
19471 + * allocations.
19472 + */
19473 +
19474 +#ifdef CONFIG_PAX_SEGMEXEC
19475 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19476 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19477 + else
19478 +#endif
19479 +
19480 + mm->mmap_base = TASK_UNMAPPED_BASE;
19481 +
19482 +#ifdef CONFIG_PAX_RANDMMAP
19483 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19484 + mm->mmap_base += mm->delta_mmap;
19485 +#endif
19486 +
19487 + mm->free_area_cache = mm->mmap_base;
19488 + mm->cached_hole_size = ~0UL;
19489 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19490 + /*
19491 + * Restore the topdown base:
19492 + */
19493 + mm->mmap_base = base;
19494 + mm->free_area_cache = base;
19495 + mm->cached_hole_size = ~0UL;
19496 +
19497 + return addr;
19498 }
19499 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19500 index b4d3c39..82bb73b 100644
19501 --- a/arch/x86/kernel/sys_x86_64.c
19502 +++ b/arch/x86/kernel/sys_x86_64.c
19503 @@ -95,8 +95,8 @@ out:
19504 return error;
19505 }
19506
19507 -static void find_start_end(unsigned long flags, unsigned long *begin,
19508 - unsigned long *end)
19509 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
19510 + unsigned long *begin, unsigned long *end)
19511 {
19512 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19513 unsigned long new_begin;
19514 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19515 *begin = new_begin;
19516 }
19517 } else {
19518 - *begin = TASK_UNMAPPED_BASE;
19519 + *begin = mm->mmap_base;
19520 *end = TASK_SIZE;
19521 }
19522 }
19523 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19524 if (flags & MAP_FIXED)
19525 return addr;
19526
19527 - find_start_end(flags, &begin, &end);
19528 + find_start_end(mm, flags, &begin, &end);
19529
19530 if (len > end)
19531 return -ENOMEM;
19532
19533 +#ifdef CONFIG_PAX_RANDMMAP
19534 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19535 +#endif
19536 +
19537 if (addr) {
19538 addr = PAGE_ALIGN(addr);
19539 vma = find_vma(mm, addr);
19540 - if (end - len >= addr &&
19541 - (!vma || addr + len <= vma->vm_start))
19542 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19543 return addr;
19544 }
19545 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19546 @@ -172,7 +175,7 @@ full_search:
19547 }
19548 return -ENOMEM;
19549 }
19550 - if (!vma || addr + len <= vma->vm_start) {
19551 + if (check_heap_stack_gap(vma, addr, len)) {
19552 /*
19553 * Remember the place where we stopped the search:
19554 */
19555 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19556 {
19557 struct vm_area_struct *vma;
19558 struct mm_struct *mm = current->mm;
19559 - unsigned long addr = addr0, start_addr;
19560 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19561
19562 /* requested length too big for entire address space */
19563 if (len > TASK_SIZE)
19564 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19565 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19566 goto bottomup;
19567
19568 +#ifdef CONFIG_PAX_RANDMMAP
19569 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19570 +#endif
19571 +
19572 /* requesting a specific address */
19573 if (addr) {
19574 addr = PAGE_ALIGN(addr);
19575 - vma = find_vma(mm, addr);
19576 - if (TASK_SIZE - len >= addr &&
19577 - (!vma || addr + len <= vma->vm_start))
19578 - return addr;
19579 + if (TASK_SIZE - len >= addr) {
19580 + vma = find_vma(mm, addr);
19581 + if (check_heap_stack_gap(vma, addr, len))
19582 + return addr;
19583 + }
19584 }
19585
19586 /* check if free_area_cache is useful for us */
19587 @@ -240,7 +248,7 @@ try_again:
19588 * return with success:
19589 */
19590 vma = find_vma(mm, addr);
19591 - if (!vma || addr+len <= vma->vm_start)
19592 + if (check_heap_stack_gap(vma, addr, len))
19593 /* remember the address as a hint for next time */
19594 return mm->free_area_cache = addr;
19595
19596 @@ -249,8 +257,8 @@ try_again:
19597 mm->cached_hole_size = vma->vm_start - addr;
19598
19599 /* try just below the current vma->vm_start */
19600 - addr = vma->vm_start-len;
19601 - } while (len < vma->vm_start);
19602 + addr = skip_heap_stack_gap(vma, len);
19603 + } while (!IS_ERR_VALUE(addr));
19604
19605 fail:
19606 /*
19607 @@ -270,13 +278,21 @@ bottomup:
19608 * can happen with large stack limits and large mmap()
19609 * allocations.
19610 */
19611 + mm->mmap_base = TASK_UNMAPPED_BASE;
19612 +
19613 +#ifdef CONFIG_PAX_RANDMMAP
19614 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19615 + mm->mmap_base += mm->delta_mmap;
19616 +#endif
19617 +
19618 + mm->free_area_cache = mm->mmap_base;
19619 mm->cached_hole_size = ~0UL;
19620 - mm->free_area_cache = TASK_UNMAPPED_BASE;
19621 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19622 /*
19623 * Restore the topdown base:
19624 */
19625 - mm->free_area_cache = mm->mmap_base;
19626 + mm->mmap_base = base;
19627 + mm->free_area_cache = base;
19628 mm->cached_hole_size = ~0UL;
19629
19630 return addr;
19631 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19632 index 6410744..79758f0 100644
19633 --- a/arch/x86/kernel/tboot.c
19634 +++ b/arch/x86/kernel/tboot.c
19635 @@ -219,7 +219,7 @@ static int tboot_setup_sleep(void)
19636
19637 void tboot_shutdown(u32 shutdown_type)
19638 {
19639 - void (*shutdown)(void);
19640 + void (* __noreturn shutdown)(void);
19641
19642 if (!tboot_enabled())
19643 return;
19644 @@ -241,7 +241,7 @@ void tboot_shutdown(u32 shutdown_type)
19645
19646 switch_to_tboot_pt();
19647
19648 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19649 + shutdown = (void *)tboot->shutdown_entry;
19650 shutdown();
19651
19652 /* should not reach here */
19653 @@ -299,7 +299,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19654 return 0;
19655 }
19656
19657 -static atomic_t ap_wfs_count;
19658 +static atomic_unchecked_t ap_wfs_count;
19659
19660 static int tboot_wait_for_aps(int num_aps)
19661 {
19662 @@ -323,9 +323,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19663 {
19664 switch (action) {
19665 case CPU_DYING:
19666 - atomic_inc(&ap_wfs_count);
19667 + atomic_inc_unchecked(&ap_wfs_count);
19668 if (num_online_cpus() == 1)
19669 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19670 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19671 return NOTIFY_BAD;
19672 break;
19673 }
19674 @@ -344,7 +344,7 @@ static __init int tboot_late_init(void)
19675
19676 tboot_create_trampoline();
19677
19678 - atomic_set(&ap_wfs_count, 0);
19679 + atomic_set_unchecked(&ap_wfs_count, 0);
19680 register_hotcpu_notifier(&tboot_cpu_notifier);
19681
19682 acpi_os_set_prepare_sleep(&tboot_sleep);
19683 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19684 index c6eba2b..3303326 100644
19685 --- a/arch/x86/kernel/time.c
19686 +++ b/arch/x86/kernel/time.c
19687 @@ -31,9 +31,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19688 {
19689 unsigned long pc = instruction_pointer(regs);
19690
19691 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19692 + if (!user_mode(regs) && in_lock_functions(pc)) {
19693 #ifdef CONFIG_FRAME_POINTER
19694 - return *(unsigned long *)(regs->bp + sizeof(long));
19695 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19696 #else
19697 unsigned long *sp =
19698 (unsigned long *)kernel_stack_pointer(regs);
19699 @@ -42,11 +42,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19700 * or above a saved flags. Eflags has bits 22-31 zero,
19701 * kernel addresses don't.
19702 */
19703 +
19704 +#ifdef CONFIG_PAX_KERNEXEC
19705 + return ktla_ktva(sp[0]);
19706 +#else
19707 if (sp[0] >> 22)
19708 return sp[0];
19709 if (sp[1] >> 22)
19710 return sp[1];
19711 #endif
19712 +
19713 +#endif
19714 }
19715 return pc;
19716 }
19717 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19718 index 9d9d2f9..ed344e4 100644
19719 --- a/arch/x86/kernel/tls.c
19720 +++ b/arch/x86/kernel/tls.c
19721 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19722 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19723 return -EINVAL;
19724
19725 +#ifdef CONFIG_PAX_SEGMEXEC
19726 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19727 + return -EINVAL;
19728 +#endif
19729 +
19730 set_tls_desc(p, idx, &info, 1);
19731
19732 return 0;
19733 diff --git a/arch/x86/kernel/trampoline_32.S b/arch/x86/kernel/trampoline_32.S
19734 index 451c0a7..e57f551 100644
19735 --- a/arch/x86/kernel/trampoline_32.S
19736 +++ b/arch/x86/kernel/trampoline_32.S
19737 @@ -32,6 +32,12 @@
19738 #include <asm/segment.h>
19739 #include <asm/page_types.h>
19740
19741 +#ifdef CONFIG_PAX_KERNEXEC
19742 +#define ta(X) (X)
19743 +#else
19744 +#define ta(X) ((X) - __PAGE_OFFSET)
19745 +#endif
19746 +
19747 #ifdef CONFIG_SMP
19748
19749 .section ".x86_trampoline","a"
19750 @@ -62,7 +68,7 @@ r_base = .
19751 inc %ax # protected mode (PE) bit
19752 lmsw %ax # into protected mode
19753 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
19754 - ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
19755 + ljmpl $__BOOT_CS, $ta(startup_32_smp)
19756
19757 # These need to be in the same 64K segment as the above;
19758 # hence we don't use the boot_gdt_descr defined in head.S
19759 diff --git a/arch/x86/kernel/trampoline_64.S b/arch/x86/kernel/trampoline_64.S
19760 index 09ff517..df19fbff 100644
19761 --- a/arch/x86/kernel/trampoline_64.S
19762 +++ b/arch/x86/kernel/trampoline_64.S
19763 @@ -90,7 +90,7 @@ startup_32:
19764 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
19765 movl %eax, %ds
19766
19767 - movl $X86_CR4_PAE, %eax
19768 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
19769 movl %eax, %cr4 # Enable PAE mode
19770
19771 # Setup trampoline 4 level pagetables
19772 @@ -138,7 +138,7 @@ tidt:
19773 # so the kernel can live anywhere
19774 .balign 4
19775 tgdt:
19776 - .short tgdt_end - tgdt # gdt limit
19777 + .short tgdt_end - tgdt - 1 # gdt limit
19778 .long tgdt - r_base
19779 .short 0
19780 .quad 0x00cf9b000000ffff # __KERNEL32_CS
19781 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19782 index ff9281f1..30cb4ac 100644
19783 --- a/arch/x86/kernel/traps.c
19784 +++ b/arch/x86/kernel/traps.c
19785 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19786
19787 /* Do we ignore FPU interrupts ? */
19788 char ignore_fpu_irq;
19789 -
19790 -/*
19791 - * The IDT has to be page-aligned to simplify the Pentium
19792 - * F0 0F bug workaround.
19793 - */
19794 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19795 #endif
19796
19797 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19798 @@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19799 }
19800
19801 static void __kprobes
19802 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19803 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19804 long error_code, siginfo_t *info)
19805 {
19806 struct task_struct *tsk = current;
19807
19808 #ifdef CONFIG_X86_32
19809 - if (regs->flags & X86_VM_MASK) {
19810 + if (v8086_mode(regs)) {
19811 /*
19812 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19813 * On nmi (interrupt 2), do_trap should not be called.
19814 @@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19815 }
19816 #endif
19817
19818 - if (!user_mode(regs))
19819 + if (!user_mode_novm(regs))
19820 goto kernel_trap;
19821
19822 #ifdef CONFIG_X86_32
19823 @@ -148,7 +142,7 @@ trap_signal:
19824 printk_ratelimit()) {
19825 printk(KERN_INFO
19826 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19827 - tsk->comm, tsk->pid, str,
19828 + tsk->comm, task_pid_nr(tsk), str,
19829 regs->ip, regs->sp, error_code);
19830 print_vma_addr(" in ", regs->ip);
19831 printk("\n");
19832 @@ -165,8 +159,20 @@ kernel_trap:
19833 if (!fixup_exception(regs)) {
19834 tsk->thread.error_code = error_code;
19835 tsk->thread.trap_nr = trapnr;
19836 +
19837 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19838 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19839 + str = "PAX: suspicious stack segment fault";
19840 +#endif
19841 +
19842 die(str, regs, error_code);
19843 }
19844 +
19845 +#ifdef CONFIG_PAX_REFCOUNT
19846 + if (trapnr == 4)
19847 + pax_report_refcount_overflow(regs);
19848 +#endif
19849 +
19850 return;
19851
19852 #ifdef CONFIG_X86_32
19853 @@ -259,14 +265,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19854 conditional_sti(regs);
19855
19856 #ifdef CONFIG_X86_32
19857 - if (regs->flags & X86_VM_MASK)
19858 + if (v8086_mode(regs))
19859 goto gp_in_vm86;
19860 #endif
19861
19862 tsk = current;
19863 - if (!user_mode(regs))
19864 + if (!user_mode_novm(regs))
19865 goto gp_in_kernel;
19866
19867 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19868 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19869 + struct mm_struct *mm = tsk->mm;
19870 + unsigned long limit;
19871 +
19872 + down_write(&mm->mmap_sem);
19873 + limit = mm->context.user_cs_limit;
19874 + if (limit < TASK_SIZE) {
19875 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19876 + up_write(&mm->mmap_sem);
19877 + return;
19878 + }
19879 + up_write(&mm->mmap_sem);
19880 + }
19881 +#endif
19882 +
19883 tsk->thread.error_code = error_code;
19884 tsk->thread.trap_nr = X86_TRAP_GP;
19885
19886 @@ -299,6 +321,13 @@ gp_in_kernel:
19887 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19888 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19889 return;
19890 +
19891 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19892 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19893 + die("PAX: suspicious general protection fault", regs, error_code);
19894 + else
19895 +#endif
19896 +
19897 die("general protection fault", regs, error_code);
19898 }
19899
19900 @@ -425,7 +454,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19901 /* It's safe to allow irq's after DR6 has been saved */
19902 preempt_conditional_sti(regs);
19903
19904 - if (regs->flags & X86_VM_MASK) {
19905 + if (v8086_mode(regs)) {
19906 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
19907 X86_TRAP_DB);
19908 preempt_conditional_cli(regs);
19909 @@ -440,7 +469,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19910 * We already checked v86 mode above, so we can check for kernel mode
19911 * by just checking the CPL of CS.
19912 */
19913 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
19914 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19915 tsk->thread.debugreg6 &= ~DR_STEP;
19916 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19917 regs->flags &= ~X86_EFLAGS_TF;
19918 @@ -471,7 +500,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19919 return;
19920 conditional_sti(regs);
19921
19922 - if (!user_mode_vm(regs))
19923 + if (!user_mode(regs))
19924 {
19925 if (!fixup_exception(regs)) {
19926 task->thread.error_code = error_code;
19927 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19928 index b9242ba..50c5edd 100644
19929 --- a/arch/x86/kernel/verify_cpu.S
19930 +++ b/arch/x86/kernel/verify_cpu.S
19931 @@ -20,6 +20,7 @@
19932 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19933 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19934 * arch/x86/kernel/head_32.S: processor startup
19935 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19936 *
19937 * verify_cpu, returns the status of longmode and SSE in register %eax.
19938 * 0: Success 1: Failure
19939 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19940 index 255f58a..5e91150 100644
19941 --- a/arch/x86/kernel/vm86_32.c
19942 +++ b/arch/x86/kernel/vm86_32.c
19943 @@ -41,6 +41,7 @@
19944 #include <linux/ptrace.h>
19945 #include <linux/audit.h>
19946 #include <linux/stddef.h>
19947 +#include <linux/grsecurity.h>
19948
19949 #include <asm/uaccess.h>
19950 #include <asm/io.h>
19951 @@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19952 do_exit(SIGSEGV);
19953 }
19954
19955 - tss = &per_cpu(init_tss, get_cpu());
19956 + tss = init_tss + get_cpu();
19957 current->thread.sp0 = current->thread.saved_sp0;
19958 current->thread.sysenter_cs = __KERNEL_CS;
19959 load_sp0(tss, &current->thread);
19960 @@ -210,6 +211,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19961 struct task_struct *tsk;
19962 int tmp, ret = -EPERM;
19963
19964 +#ifdef CONFIG_GRKERNSEC_VM86
19965 + if (!capable(CAP_SYS_RAWIO)) {
19966 + gr_handle_vm86();
19967 + goto out;
19968 + }
19969 +#endif
19970 +
19971 tsk = current;
19972 if (tsk->thread.saved_sp0)
19973 goto out;
19974 @@ -240,6 +248,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19975 int tmp, ret;
19976 struct vm86plus_struct __user *v86;
19977
19978 +#ifdef CONFIG_GRKERNSEC_VM86
19979 + if (!capable(CAP_SYS_RAWIO)) {
19980 + gr_handle_vm86();
19981 + ret = -EPERM;
19982 + goto out;
19983 + }
19984 +#endif
19985 +
19986 tsk = current;
19987 switch (cmd) {
19988 case VM86_REQUEST_IRQ:
19989 @@ -326,7 +342,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19990 tsk->thread.saved_fs = info->regs32->fs;
19991 tsk->thread.saved_gs = get_user_gs(info->regs32);
19992
19993 - tss = &per_cpu(init_tss, get_cpu());
19994 + tss = init_tss + get_cpu();
19995 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
19996 if (cpu_has_sep)
19997 tsk->thread.sysenter_cs = 0;
19998 @@ -533,7 +549,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
19999 goto cannot_handle;
20000 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
20001 goto cannot_handle;
20002 - intr_ptr = (unsigned long __user *) (i << 2);
20003 + intr_ptr = (__force unsigned long __user *) (i << 2);
20004 if (get_user(segoffs, intr_ptr))
20005 goto cannot_handle;
20006 if ((segoffs >> 16) == BIOSSEG)
20007 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
20008 index 0f703f1..9e15f64 100644
20009 --- a/arch/x86/kernel/vmlinux.lds.S
20010 +++ b/arch/x86/kernel/vmlinux.lds.S
20011 @@ -26,6 +26,13 @@
20012 #include <asm/page_types.h>
20013 #include <asm/cache.h>
20014 #include <asm/boot.h>
20015 +#include <asm/segment.h>
20016 +
20017 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20018 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
20019 +#else
20020 +#define __KERNEL_TEXT_OFFSET 0
20021 +#endif
20022
20023 #undef i386 /* in case the preprocessor is a 32bit one */
20024
20025 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
20026
20027 PHDRS {
20028 text PT_LOAD FLAGS(5); /* R_E */
20029 +#ifdef CONFIG_X86_32
20030 + module PT_LOAD FLAGS(5); /* R_E */
20031 +#endif
20032 +#ifdef CONFIG_XEN
20033 + rodata PT_LOAD FLAGS(5); /* R_E */
20034 +#else
20035 + rodata PT_LOAD FLAGS(4); /* R__ */
20036 +#endif
20037 data PT_LOAD FLAGS(6); /* RW_ */
20038 -#ifdef CONFIG_X86_64
20039 + init.begin PT_LOAD FLAGS(6); /* RW_ */
20040 #ifdef CONFIG_SMP
20041 percpu PT_LOAD FLAGS(6); /* RW_ */
20042 #endif
20043 + text.init PT_LOAD FLAGS(5); /* R_E */
20044 + text.exit PT_LOAD FLAGS(5); /* R_E */
20045 init PT_LOAD FLAGS(7); /* RWE */
20046 -#endif
20047 note PT_NOTE FLAGS(0); /* ___ */
20048 }
20049
20050 SECTIONS
20051 {
20052 #ifdef CONFIG_X86_32
20053 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
20054 - phys_startup_32 = startup_32 - LOAD_OFFSET;
20055 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
20056 #else
20057 - . = __START_KERNEL;
20058 - phys_startup_64 = startup_64 - LOAD_OFFSET;
20059 + . = __START_KERNEL;
20060 #endif
20061
20062 /* Text and read-only data */
20063 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
20064 - _text = .;
20065 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20066 /* bootstrapping code */
20067 +#ifdef CONFIG_X86_32
20068 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20069 +#else
20070 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20071 +#endif
20072 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20073 + _text = .;
20074 HEAD_TEXT
20075 #ifdef CONFIG_X86_32
20076 . = ALIGN(PAGE_SIZE);
20077 @@ -108,13 +128,47 @@ SECTIONS
20078 IRQENTRY_TEXT
20079 *(.fixup)
20080 *(.gnu.warning)
20081 - /* End of text section */
20082 - _etext = .;
20083 } :text = 0x9090
20084
20085 - NOTES :text :note
20086 + . += __KERNEL_TEXT_OFFSET;
20087
20088 - EXCEPTION_TABLE(16) :text = 0x9090
20089 +#ifdef CONFIG_X86_32
20090 + . = ALIGN(PAGE_SIZE);
20091 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
20092 +
20093 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
20094 + MODULES_EXEC_VADDR = .;
20095 + BYTE(0)
20096 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
20097 + . = ALIGN(HPAGE_SIZE);
20098 + MODULES_EXEC_END = . - 1;
20099 +#endif
20100 +
20101 + } :module
20102 +#endif
20103 +
20104 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20105 + /* End of text section */
20106 + _etext = . - __KERNEL_TEXT_OFFSET;
20107 + }
20108 +
20109 +#ifdef CONFIG_X86_32
20110 + . = ALIGN(PAGE_SIZE);
20111 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20112 + *(.idt)
20113 + . = ALIGN(PAGE_SIZE);
20114 + *(.empty_zero_page)
20115 + *(.initial_pg_fixmap)
20116 + *(.initial_pg_pmd)
20117 + *(.initial_page_table)
20118 + *(.swapper_pg_dir)
20119 + } :rodata
20120 +#endif
20121 +
20122 + . = ALIGN(PAGE_SIZE);
20123 + NOTES :rodata :note
20124 +
20125 + EXCEPTION_TABLE(16) :rodata
20126
20127 #if defined(CONFIG_DEBUG_RODATA)
20128 /* .text should occupy whole number of pages */
20129 @@ -126,16 +180,20 @@ SECTIONS
20130
20131 /* Data */
20132 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20133 +
20134 +#ifdef CONFIG_PAX_KERNEXEC
20135 + . = ALIGN(HPAGE_SIZE);
20136 +#else
20137 + . = ALIGN(PAGE_SIZE);
20138 +#endif
20139 +
20140 /* Start of data section */
20141 _sdata = .;
20142
20143 /* init_task */
20144 INIT_TASK_DATA(THREAD_SIZE)
20145
20146 -#ifdef CONFIG_X86_32
20147 - /* 32 bit has nosave before _edata */
20148 NOSAVE_DATA
20149 -#endif
20150
20151 PAGE_ALIGNED_DATA(PAGE_SIZE)
20152
20153 @@ -176,12 +234,19 @@ SECTIONS
20154 #endif /* CONFIG_X86_64 */
20155
20156 /* Init code and data - will be freed after init */
20157 - . = ALIGN(PAGE_SIZE);
20158 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20159 + BYTE(0)
20160 +
20161 +#ifdef CONFIG_PAX_KERNEXEC
20162 + . = ALIGN(HPAGE_SIZE);
20163 +#else
20164 + . = ALIGN(PAGE_SIZE);
20165 +#endif
20166 +
20167 __init_begin = .; /* paired with __init_end */
20168 - }
20169 + } :init.begin
20170
20171 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20172 +#ifdef CONFIG_SMP
20173 /*
20174 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20175 * output PHDR, so the next output section - .init.text - should
20176 @@ -190,12 +255,27 @@ SECTIONS
20177 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20178 #endif
20179
20180 - INIT_TEXT_SECTION(PAGE_SIZE)
20181 -#ifdef CONFIG_X86_64
20182 - :init
20183 -#endif
20184 + . = ALIGN(PAGE_SIZE);
20185 + init_begin = .;
20186 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20187 + VMLINUX_SYMBOL(_sinittext) = .;
20188 + INIT_TEXT
20189 + VMLINUX_SYMBOL(_einittext) = .;
20190 + . = ALIGN(PAGE_SIZE);
20191 + } :text.init
20192
20193 - INIT_DATA_SECTION(16)
20194 + /*
20195 + * .exit.text is discard at runtime, not link time, to deal with
20196 + * references from .altinstructions and .eh_frame
20197 + */
20198 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20199 + EXIT_TEXT
20200 + . = ALIGN(16);
20201 + } :text.exit
20202 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20203 +
20204 + . = ALIGN(PAGE_SIZE);
20205 + INIT_DATA_SECTION(16) :init
20206
20207 /*
20208 * Code and data for a variety of lowlevel trampolines, to be
20209 @@ -269,19 +349,12 @@ SECTIONS
20210 }
20211
20212 . = ALIGN(8);
20213 - /*
20214 - * .exit.text is discard at runtime, not link time, to deal with
20215 - * references from .altinstructions and .eh_frame
20216 - */
20217 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20218 - EXIT_TEXT
20219 - }
20220
20221 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20222 EXIT_DATA
20223 }
20224
20225 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20226 +#ifndef CONFIG_SMP
20227 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20228 #endif
20229
20230 @@ -300,16 +373,10 @@ SECTIONS
20231 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20232 __smp_locks = .;
20233 *(.smp_locks)
20234 - . = ALIGN(PAGE_SIZE);
20235 __smp_locks_end = .;
20236 + . = ALIGN(PAGE_SIZE);
20237 }
20238
20239 -#ifdef CONFIG_X86_64
20240 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20241 - NOSAVE_DATA
20242 - }
20243 -#endif
20244 -
20245 /* BSS */
20246 . = ALIGN(PAGE_SIZE);
20247 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20248 @@ -325,6 +392,7 @@ SECTIONS
20249 __brk_base = .;
20250 . += 64 * 1024; /* 64k alignment slop space */
20251 *(.brk_reservation) /* areas brk users have reserved */
20252 + . = ALIGN(HPAGE_SIZE);
20253 __brk_limit = .;
20254 }
20255
20256 @@ -351,13 +419,12 @@ SECTIONS
20257 * for the boot processor.
20258 */
20259 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20260 -INIT_PER_CPU(gdt_page);
20261 INIT_PER_CPU(irq_stack_union);
20262
20263 /*
20264 * Build-time check on the image size:
20265 */
20266 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20267 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20268 "kernel image bigger than KERNEL_IMAGE_SIZE");
20269
20270 #ifdef CONFIG_SMP
20271 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20272 index 7515cf0..331a1a0 100644
20273 --- a/arch/x86/kernel/vsyscall_64.c
20274 +++ b/arch/x86/kernel/vsyscall_64.c
20275 @@ -54,15 +54,13 @@
20276 DEFINE_VVAR(int, vgetcpu_mode);
20277 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20278
20279 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20280 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20281
20282 static int __init vsyscall_setup(char *str)
20283 {
20284 if (str) {
20285 if (!strcmp("emulate", str))
20286 vsyscall_mode = EMULATE;
20287 - else if (!strcmp("native", str))
20288 - vsyscall_mode = NATIVE;
20289 else if (!strcmp("none", str))
20290 vsyscall_mode = NONE;
20291 else
20292 @@ -206,7 +204,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
20293
20294 tsk = current;
20295 if (seccomp_mode(&tsk->seccomp))
20296 - do_exit(SIGKILL);
20297 + do_group_exit(SIGKILL);
20298
20299 /*
20300 * With a real vsyscall, page faults cause SIGSEGV. We want to
20301 @@ -278,8 +276,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
20302 return true;
20303
20304 sigsegv:
20305 - force_sig(SIGSEGV, current);
20306 - return true;
20307 + do_group_exit(SIGKILL);
20308 }
20309
20310 /*
20311 @@ -332,10 +329,7 @@ void __init map_vsyscall(void)
20312 extern char __vvar_page;
20313 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20314
20315 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20316 - vsyscall_mode == NATIVE
20317 - ? PAGE_KERNEL_VSYSCALL
20318 - : PAGE_KERNEL_VVAR);
20319 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20320 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20321 (unsigned long)VSYSCALL_START);
20322
20323 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20324 index 9796c2f..f686fbf 100644
20325 --- a/arch/x86/kernel/x8664_ksyms_64.c
20326 +++ b/arch/x86/kernel/x8664_ksyms_64.c
20327 @@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
20328 EXPORT_SYMBOL(copy_user_generic_string);
20329 EXPORT_SYMBOL(copy_user_generic_unrolled);
20330 EXPORT_SYMBOL(__copy_user_nocache);
20331 -EXPORT_SYMBOL(_copy_from_user);
20332 -EXPORT_SYMBOL(_copy_to_user);
20333
20334 EXPORT_SYMBOL(copy_page);
20335 EXPORT_SYMBOL(clear_page);
20336 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20337 index e62728e..5fc3a07 100644
20338 --- a/arch/x86/kernel/xsave.c
20339 +++ b/arch/x86/kernel/xsave.c
20340 @@ -131,7 +131,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20341 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20342 return -EINVAL;
20343
20344 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20345 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20346 fx_sw_user->extended_size -
20347 FP_XSTATE_MAGIC2_SIZE));
20348 if (err)
20349 @@ -267,7 +267,7 @@ fx_only:
20350 * the other extended state.
20351 */
20352 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20353 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20354 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20355 }
20356
20357 /*
20358 @@ -296,7 +296,7 @@ int restore_i387_xstate(void __user *buf)
20359 if (use_xsave())
20360 err = restore_user_xstate(buf);
20361 else
20362 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
20363 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20364 buf);
20365 if (unlikely(err)) {
20366 /*
20367 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20368 index 9fed5be..18fd595 100644
20369 --- a/arch/x86/kvm/cpuid.c
20370 +++ b/arch/x86/kvm/cpuid.c
20371 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20372 struct kvm_cpuid2 *cpuid,
20373 struct kvm_cpuid_entry2 __user *entries)
20374 {
20375 - int r;
20376 + int r, i;
20377
20378 r = -E2BIG;
20379 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20380 goto out;
20381 r = -EFAULT;
20382 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20383 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20384 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20385 goto out;
20386 + for (i = 0; i < cpuid->nent; ++i) {
20387 + struct kvm_cpuid_entry2 cpuid_entry;
20388 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20389 + goto out;
20390 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
20391 + }
20392 vcpu->arch.cpuid_nent = cpuid->nent;
20393 kvm_apic_set_version(vcpu);
20394 kvm_x86_ops->cpuid_update(vcpu);
20395 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20396 struct kvm_cpuid2 *cpuid,
20397 struct kvm_cpuid_entry2 __user *entries)
20398 {
20399 - int r;
20400 + int r, i;
20401
20402 r = -E2BIG;
20403 if (cpuid->nent < vcpu->arch.cpuid_nent)
20404 goto out;
20405 r = -EFAULT;
20406 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20407 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20408 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20409 goto out;
20410 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20411 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20412 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20413 + goto out;
20414 + }
20415 return 0;
20416
20417 out:
20418 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20419 index 8375622..b7bca1a 100644
20420 --- a/arch/x86/kvm/emulate.c
20421 +++ b/arch/x86/kvm/emulate.c
20422 @@ -252,6 +252,7 @@ struct gprefix {
20423
20424 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20425 do { \
20426 + unsigned long _tmp; \
20427 __asm__ __volatile__ ( \
20428 _PRE_EFLAGS("0", "4", "2") \
20429 _op _suffix " %"_x"3,%1; " \
20430 @@ -266,8 +267,6 @@ struct gprefix {
20431 /* Raw emulation: instruction has two explicit operands. */
20432 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20433 do { \
20434 - unsigned long _tmp; \
20435 - \
20436 switch ((ctxt)->dst.bytes) { \
20437 case 2: \
20438 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20439 @@ -283,7 +282,6 @@ struct gprefix {
20440
20441 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20442 do { \
20443 - unsigned long _tmp; \
20444 switch ((ctxt)->dst.bytes) { \
20445 case 1: \
20446 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20447 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20448 index 8584322..17d5955 100644
20449 --- a/arch/x86/kvm/lapic.c
20450 +++ b/arch/x86/kvm/lapic.c
20451 @@ -54,7 +54,7 @@
20452 #define APIC_BUS_CYCLE_NS 1
20453
20454 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20455 -#define apic_debug(fmt, arg...)
20456 +#define apic_debug(fmt, arg...) do {} while (0)
20457
20458 #define APIC_LVT_NUM 6
20459 /* 14 is the version for Xeon and Pentium 8.4.8*/
20460 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20461 index df5a703..63748a7 100644
20462 --- a/arch/x86/kvm/paging_tmpl.h
20463 +++ b/arch/x86/kvm/paging_tmpl.h
20464 @@ -197,7 +197,7 @@ retry_walk:
20465 if (unlikely(kvm_is_error_hva(host_addr)))
20466 goto error;
20467
20468 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20469 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20470 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20471 goto error;
20472
20473 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20474 index e334389..6839087 100644
20475 --- a/arch/x86/kvm/svm.c
20476 +++ b/arch/x86/kvm/svm.c
20477 @@ -3509,7 +3509,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20478 int cpu = raw_smp_processor_id();
20479
20480 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20481 +
20482 + pax_open_kernel();
20483 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20484 + pax_close_kernel();
20485 +
20486 load_TR_desc();
20487 }
20488
20489 @@ -3887,6 +3891,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20490 #endif
20491 #endif
20492
20493 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20494 + __set_fs(current_thread_info()->addr_limit);
20495 +#endif
20496 +
20497 reload_tss(vcpu);
20498
20499 local_irq_disable();
20500 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20501 index 4ff0ab9..2ff68d3 100644
20502 --- a/arch/x86/kvm/vmx.c
20503 +++ b/arch/x86/kvm/vmx.c
20504 @@ -1303,7 +1303,11 @@ static void reload_tss(void)
20505 struct desc_struct *descs;
20506
20507 descs = (void *)gdt->address;
20508 +
20509 + pax_open_kernel();
20510 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20511 + pax_close_kernel();
20512 +
20513 load_TR_desc();
20514 }
20515
20516 @@ -2625,8 +2629,11 @@ static __init int hardware_setup(void)
20517 if (!cpu_has_vmx_flexpriority())
20518 flexpriority_enabled = 0;
20519
20520 - if (!cpu_has_vmx_tpr_shadow())
20521 - kvm_x86_ops->update_cr8_intercept = NULL;
20522 + if (!cpu_has_vmx_tpr_shadow()) {
20523 + pax_open_kernel();
20524 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20525 + pax_close_kernel();
20526 + }
20527
20528 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20529 kvm_disable_largepages();
20530 @@ -3642,7 +3649,7 @@ static void vmx_set_constant_host_state(void)
20531 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20532
20533 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20534 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20535 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20536
20537 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20538 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20539 @@ -6180,6 +6187,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20540 "jmp .Lkvm_vmx_return \n\t"
20541 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20542 ".Lkvm_vmx_return: "
20543 +
20544 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20545 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20546 + ".Lkvm_vmx_return2: "
20547 +#endif
20548 +
20549 /* Save guest registers, load host registers, keep flags */
20550 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20551 "pop %0 \n\t"
20552 @@ -6228,6 +6241,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20553 #endif
20554 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20555 [wordsize]"i"(sizeof(ulong))
20556 +
20557 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20558 + ,[cs]"i"(__KERNEL_CS)
20559 +#endif
20560 +
20561 : "cc", "memory"
20562 , R"ax", R"bx", R"di", R"si"
20563 #ifdef CONFIG_X86_64
20564 @@ -6256,7 +6274,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20565 }
20566 }
20567
20568 - asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
20569 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
20570 +
20571 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20572 + loadsegment(fs, __KERNEL_PERCPU);
20573 +#endif
20574 +
20575 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20576 + __set_fs(current_thread_info()->addr_limit);
20577 +#endif
20578 +
20579 vmx->loaded_vmcs->launched = 1;
20580
20581 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
20582 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20583 index 185a2b8..866d2a6 100644
20584 --- a/arch/x86/kvm/x86.c
20585 +++ b/arch/x86/kvm/x86.c
20586 @@ -1357,8 +1357,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20587 {
20588 struct kvm *kvm = vcpu->kvm;
20589 int lm = is_long_mode(vcpu);
20590 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20591 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20592 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20593 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20594 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20595 : kvm->arch.xen_hvm_config.blob_size_32;
20596 u32 page_num = data & ~PAGE_MASK;
20597 @@ -2213,6 +2213,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20598 if (n < msr_list.nmsrs)
20599 goto out;
20600 r = -EFAULT;
20601 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20602 + goto out;
20603 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20604 num_msrs_to_save * sizeof(u32)))
20605 goto out;
20606 @@ -2338,7 +2340,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20607 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20608 struct kvm_interrupt *irq)
20609 {
20610 - if (irq->irq < 0 || irq->irq >= 256)
20611 + if (irq->irq >= 256)
20612 return -EINVAL;
20613 if (irqchip_in_kernel(vcpu->kvm))
20614 return -ENXIO;
20615 @@ -4860,7 +4862,7 @@ static void kvm_set_mmio_spte_mask(void)
20616 kvm_mmu_set_mmio_spte_mask(mask);
20617 }
20618
20619 -int kvm_arch_init(void *opaque)
20620 +int kvm_arch_init(const void *opaque)
20621 {
20622 int r;
20623 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20624 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20625 index 642d880..44e0f3f 100644
20626 --- a/arch/x86/lguest/boot.c
20627 +++ b/arch/x86/lguest/boot.c
20628 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20629 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20630 * Launcher to reboot us.
20631 */
20632 -static void lguest_restart(char *reason)
20633 +static __noreturn void lguest_restart(char *reason)
20634 {
20635 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20636 + BUG();
20637 }
20638
20639 /*G:050
20640 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20641 index 00933d5..3a64af9 100644
20642 --- a/arch/x86/lib/atomic64_386_32.S
20643 +++ b/arch/x86/lib/atomic64_386_32.S
20644 @@ -48,6 +48,10 @@ BEGIN(read)
20645 movl (v), %eax
20646 movl 4(v), %edx
20647 RET_ENDP
20648 +BEGIN(read_unchecked)
20649 + movl (v), %eax
20650 + movl 4(v), %edx
20651 +RET_ENDP
20652 #undef v
20653
20654 #define v %esi
20655 @@ -55,6 +59,10 @@ BEGIN(set)
20656 movl %ebx, (v)
20657 movl %ecx, 4(v)
20658 RET_ENDP
20659 +BEGIN(set_unchecked)
20660 + movl %ebx, (v)
20661 + movl %ecx, 4(v)
20662 +RET_ENDP
20663 #undef v
20664
20665 #define v %esi
20666 @@ -70,6 +78,20 @@ RET_ENDP
20667 BEGIN(add)
20668 addl %eax, (v)
20669 adcl %edx, 4(v)
20670 +
20671 +#ifdef CONFIG_PAX_REFCOUNT
20672 + jno 0f
20673 + subl %eax, (v)
20674 + sbbl %edx, 4(v)
20675 + int $4
20676 +0:
20677 + _ASM_EXTABLE(0b, 0b)
20678 +#endif
20679 +
20680 +RET_ENDP
20681 +BEGIN(add_unchecked)
20682 + addl %eax, (v)
20683 + adcl %edx, 4(v)
20684 RET_ENDP
20685 #undef v
20686
20687 @@ -77,6 +99,24 @@ RET_ENDP
20688 BEGIN(add_return)
20689 addl (v), %eax
20690 adcl 4(v), %edx
20691 +
20692 +#ifdef CONFIG_PAX_REFCOUNT
20693 + into
20694 +1234:
20695 + _ASM_EXTABLE(1234b, 2f)
20696 +#endif
20697 +
20698 + movl %eax, (v)
20699 + movl %edx, 4(v)
20700 +
20701 +#ifdef CONFIG_PAX_REFCOUNT
20702 +2:
20703 +#endif
20704 +
20705 +RET_ENDP
20706 +BEGIN(add_return_unchecked)
20707 + addl (v), %eax
20708 + adcl 4(v), %edx
20709 movl %eax, (v)
20710 movl %edx, 4(v)
20711 RET_ENDP
20712 @@ -86,6 +126,20 @@ RET_ENDP
20713 BEGIN(sub)
20714 subl %eax, (v)
20715 sbbl %edx, 4(v)
20716 +
20717 +#ifdef CONFIG_PAX_REFCOUNT
20718 + jno 0f
20719 + addl %eax, (v)
20720 + adcl %edx, 4(v)
20721 + int $4
20722 +0:
20723 + _ASM_EXTABLE(0b, 0b)
20724 +#endif
20725 +
20726 +RET_ENDP
20727 +BEGIN(sub_unchecked)
20728 + subl %eax, (v)
20729 + sbbl %edx, 4(v)
20730 RET_ENDP
20731 #undef v
20732
20733 @@ -96,6 +150,27 @@ BEGIN(sub_return)
20734 sbbl $0, %edx
20735 addl (v), %eax
20736 adcl 4(v), %edx
20737 +
20738 +#ifdef CONFIG_PAX_REFCOUNT
20739 + into
20740 +1234:
20741 + _ASM_EXTABLE(1234b, 2f)
20742 +#endif
20743 +
20744 + movl %eax, (v)
20745 + movl %edx, 4(v)
20746 +
20747 +#ifdef CONFIG_PAX_REFCOUNT
20748 +2:
20749 +#endif
20750 +
20751 +RET_ENDP
20752 +BEGIN(sub_return_unchecked)
20753 + negl %edx
20754 + negl %eax
20755 + sbbl $0, %edx
20756 + addl (v), %eax
20757 + adcl 4(v), %edx
20758 movl %eax, (v)
20759 movl %edx, 4(v)
20760 RET_ENDP
20761 @@ -105,6 +180,20 @@ RET_ENDP
20762 BEGIN(inc)
20763 addl $1, (v)
20764 adcl $0, 4(v)
20765 +
20766 +#ifdef CONFIG_PAX_REFCOUNT
20767 + jno 0f
20768 + subl $1, (v)
20769 + sbbl $0, 4(v)
20770 + int $4
20771 +0:
20772 + _ASM_EXTABLE(0b, 0b)
20773 +#endif
20774 +
20775 +RET_ENDP
20776 +BEGIN(inc_unchecked)
20777 + addl $1, (v)
20778 + adcl $0, 4(v)
20779 RET_ENDP
20780 #undef v
20781
20782 @@ -114,6 +203,26 @@ BEGIN(inc_return)
20783 movl 4(v), %edx
20784 addl $1, %eax
20785 adcl $0, %edx
20786 +
20787 +#ifdef CONFIG_PAX_REFCOUNT
20788 + into
20789 +1234:
20790 + _ASM_EXTABLE(1234b, 2f)
20791 +#endif
20792 +
20793 + movl %eax, (v)
20794 + movl %edx, 4(v)
20795 +
20796 +#ifdef CONFIG_PAX_REFCOUNT
20797 +2:
20798 +#endif
20799 +
20800 +RET_ENDP
20801 +BEGIN(inc_return_unchecked)
20802 + movl (v), %eax
20803 + movl 4(v), %edx
20804 + addl $1, %eax
20805 + adcl $0, %edx
20806 movl %eax, (v)
20807 movl %edx, 4(v)
20808 RET_ENDP
20809 @@ -123,6 +232,20 @@ RET_ENDP
20810 BEGIN(dec)
20811 subl $1, (v)
20812 sbbl $0, 4(v)
20813 +
20814 +#ifdef CONFIG_PAX_REFCOUNT
20815 + jno 0f
20816 + addl $1, (v)
20817 + adcl $0, 4(v)
20818 + int $4
20819 +0:
20820 + _ASM_EXTABLE(0b, 0b)
20821 +#endif
20822 +
20823 +RET_ENDP
20824 +BEGIN(dec_unchecked)
20825 + subl $1, (v)
20826 + sbbl $0, 4(v)
20827 RET_ENDP
20828 #undef v
20829
20830 @@ -132,6 +255,26 @@ BEGIN(dec_return)
20831 movl 4(v), %edx
20832 subl $1, %eax
20833 sbbl $0, %edx
20834 +
20835 +#ifdef CONFIG_PAX_REFCOUNT
20836 + into
20837 +1234:
20838 + _ASM_EXTABLE(1234b, 2f)
20839 +#endif
20840 +
20841 + movl %eax, (v)
20842 + movl %edx, 4(v)
20843 +
20844 +#ifdef CONFIG_PAX_REFCOUNT
20845 +2:
20846 +#endif
20847 +
20848 +RET_ENDP
20849 +BEGIN(dec_return_unchecked)
20850 + movl (v), %eax
20851 + movl 4(v), %edx
20852 + subl $1, %eax
20853 + sbbl $0, %edx
20854 movl %eax, (v)
20855 movl %edx, 4(v)
20856 RET_ENDP
20857 @@ -143,6 +286,13 @@ BEGIN(add_unless)
20858 adcl %edx, %edi
20859 addl (v), %eax
20860 adcl 4(v), %edx
20861 +
20862 +#ifdef CONFIG_PAX_REFCOUNT
20863 + into
20864 +1234:
20865 + _ASM_EXTABLE(1234b, 2f)
20866 +#endif
20867 +
20868 cmpl %eax, %ecx
20869 je 3f
20870 1:
20871 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20872 1:
20873 addl $1, %eax
20874 adcl $0, %edx
20875 +
20876 +#ifdef CONFIG_PAX_REFCOUNT
20877 + into
20878 +1234:
20879 + _ASM_EXTABLE(1234b, 2f)
20880 +#endif
20881 +
20882 movl %eax, (v)
20883 movl %edx, 4(v)
20884 movl $1, %eax
20885 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20886 movl 4(v), %edx
20887 subl $1, %eax
20888 sbbl $0, %edx
20889 +
20890 +#ifdef CONFIG_PAX_REFCOUNT
20891 + into
20892 +1234:
20893 + _ASM_EXTABLE(1234b, 1f)
20894 +#endif
20895 +
20896 js 1f
20897 movl %eax, (v)
20898 movl %edx, 4(v)
20899 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20900 index f5cc9eb..51fa319 100644
20901 --- a/arch/x86/lib/atomic64_cx8_32.S
20902 +++ b/arch/x86/lib/atomic64_cx8_32.S
20903 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20904 CFI_STARTPROC
20905
20906 read64 %ecx
20907 + pax_force_retaddr
20908 ret
20909 CFI_ENDPROC
20910 ENDPROC(atomic64_read_cx8)
20911
20912 +ENTRY(atomic64_read_unchecked_cx8)
20913 + CFI_STARTPROC
20914 +
20915 + read64 %ecx
20916 + pax_force_retaddr
20917 + ret
20918 + CFI_ENDPROC
20919 +ENDPROC(atomic64_read_unchecked_cx8)
20920 +
20921 ENTRY(atomic64_set_cx8)
20922 CFI_STARTPROC
20923
20924 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20925 cmpxchg8b (%esi)
20926 jne 1b
20927
20928 + pax_force_retaddr
20929 ret
20930 CFI_ENDPROC
20931 ENDPROC(atomic64_set_cx8)
20932
20933 +ENTRY(atomic64_set_unchecked_cx8)
20934 + CFI_STARTPROC
20935 +
20936 +1:
20937 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
20938 + * are atomic on 586 and newer */
20939 + cmpxchg8b (%esi)
20940 + jne 1b
20941 +
20942 + pax_force_retaddr
20943 + ret
20944 + CFI_ENDPROC
20945 +ENDPROC(atomic64_set_unchecked_cx8)
20946 +
20947 ENTRY(atomic64_xchg_cx8)
20948 CFI_STARTPROC
20949
20950 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
20951 cmpxchg8b (%esi)
20952 jne 1b
20953
20954 + pax_force_retaddr
20955 ret
20956 CFI_ENDPROC
20957 ENDPROC(atomic64_xchg_cx8)
20958
20959 -.macro addsub_return func ins insc
20960 -ENTRY(atomic64_\func\()_return_cx8)
20961 +.macro addsub_return func ins insc unchecked=""
20962 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20963 CFI_STARTPROC
20964 SAVE ebp
20965 SAVE ebx
20966 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
20967 movl %edx, %ecx
20968 \ins\()l %esi, %ebx
20969 \insc\()l %edi, %ecx
20970 +
20971 +.ifb \unchecked
20972 +#ifdef CONFIG_PAX_REFCOUNT
20973 + into
20974 +2:
20975 + _ASM_EXTABLE(2b, 3f)
20976 +#endif
20977 +.endif
20978 +
20979 LOCK_PREFIX
20980 cmpxchg8b (%ebp)
20981 jne 1b
20982 -
20983 -10:
20984 movl %ebx, %eax
20985 movl %ecx, %edx
20986 +
20987 +.ifb \unchecked
20988 +#ifdef CONFIG_PAX_REFCOUNT
20989 +3:
20990 +#endif
20991 +.endif
20992 +
20993 RESTORE edi
20994 RESTORE esi
20995 RESTORE ebx
20996 RESTORE ebp
20997 + pax_force_retaddr
20998 ret
20999 CFI_ENDPROC
21000 -ENDPROC(atomic64_\func\()_return_cx8)
21001 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21002 .endm
21003
21004 addsub_return add add adc
21005 addsub_return sub sub sbb
21006 +addsub_return add add adc _unchecked
21007 +addsub_return sub sub sbb _unchecked
21008
21009 -.macro incdec_return func ins insc
21010 -ENTRY(atomic64_\func\()_return_cx8)
21011 +.macro incdec_return func ins insc unchecked=""
21012 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21013 CFI_STARTPROC
21014 SAVE ebx
21015
21016 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
21017 movl %edx, %ecx
21018 \ins\()l $1, %ebx
21019 \insc\()l $0, %ecx
21020 +
21021 +.ifb \unchecked
21022 +#ifdef CONFIG_PAX_REFCOUNT
21023 + into
21024 +2:
21025 + _ASM_EXTABLE(2b, 3f)
21026 +#endif
21027 +.endif
21028 +
21029 LOCK_PREFIX
21030 cmpxchg8b (%esi)
21031 jne 1b
21032
21033 -10:
21034 movl %ebx, %eax
21035 movl %ecx, %edx
21036 +
21037 +.ifb \unchecked
21038 +#ifdef CONFIG_PAX_REFCOUNT
21039 +3:
21040 +#endif
21041 +.endif
21042 +
21043 RESTORE ebx
21044 + pax_force_retaddr
21045 ret
21046 CFI_ENDPROC
21047 -ENDPROC(atomic64_\func\()_return_cx8)
21048 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21049 .endm
21050
21051 incdec_return inc add adc
21052 incdec_return dec sub sbb
21053 +incdec_return inc add adc _unchecked
21054 +incdec_return dec sub sbb _unchecked
21055
21056 ENTRY(atomic64_dec_if_positive_cx8)
21057 CFI_STARTPROC
21058 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
21059 movl %edx, %ecx
21060 subl $1, %ebx
21061 sbb $0, %ecx
21062 +
21063 +#ifdef CONFIG_PAX_REFCOUNT
21064 + into
21065 +1234:
21066 + _ASM_EXTABLE(1234b, 2f)
21067 +#endif
21068 +
21069 js 2f
21070 LOCK_PREFIX
21071 cmpxchg8b (%esi)
21072 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
21073 movl %ebx, %eax
21074 movl %ecx, %edx
21075 RESTORE ebx
21076 + pax_force_retaddr
21077 ret
21078 CFI_ENDPROC
21079 ENDPROC(atomic64_dec_if_positive_cx8)
21080 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
21081 movl %edx, %ecx
21082 addl %ebp, %ebx
21083 adcl %edi, %ecx
21084 +
21085 +#ifdef CONFIG_PAX_REFCOUNT
21086 + into
21087 +1234:
21088 + _ASM_EXTABLE(1234b, 3f)
21089 +#endif
21090 +
21091 LOCK_PREFIX
21092 cmpxchg8b (%esi)
21093 jne 1b
21094 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
21095 CFI_ADJUST_CFA_OFFSET -8
21096 RESTORE ebx
21097 RESTORE ebp
21098 + pax_force_retaddr
21099 ret
21100 4:
21101 cmpl %edx, 4(%esp)
21102 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21103 xorl %ecx, %ecx
21104 addl $1, %ebx
21105 adcl %edx, %ecx
21106 +
21107 +#ifdef CONFIG_PAX_REFCOUNT
21108 + into
21109 +1234:
21110 + _ASM_EXTABLE(1234b, 3f)
21111 +#endif
21112 +
21113 LOCK_PREFIX
21114 cmpxchg8b (%esi)
21115 jne 1b
21116 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21117 movl $1, %eax
21118 3:
21119 RESTORE ebx
21120 + pax_force_retaddr
21121 ret
21122 CFI_ENDPROC
21123 ENDPROC(atomic64_inc_not_zero_cx8)
21124 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21125 index 78d16a5..fbcf666 100644
21126 --- a/arch/x86/lib/checksum_32.S
21127 +++ b/arch/x86/lib/checksum_32.S
21128 @@ -28,7 +28,8 @@
21129 #include <linux/linkage.h>
21130 #include <asm/dwarf2.h>
21131 #include <asm/errno.h>
21132 -
21133 +#include <asm/segment.h>
21134 +
21135 /*
21136 * computes a partial checksum, e.g. for TCP/UDP fragments
21137 */
21138 @@ -296,9 +297,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21139
21140 #define ARGBASE 16
21141 #define FP 12
21142 -
21143 -ENTRY(csum_partial_copy_generic)
21144 +
21145 +ENTRY(csum_partial_copy_generic_to_user)
21146 CFI_STARTPROC
21147 +
21148 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21149 + pushl_cfi %gs
21150 + popl_cfi %es
21151 + jmp csum_partial_copy_generic
21152 +#endif
21153 +
21154 +ENTRY(csum_partial_copy_generic_from_user)
21155 +
21156 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21157 + pushl_cfi %gs
21158 + popl_cfi %ds
21159 +#endif
21160 +
21161 +ENTRY(csum_partial_copy_generic)
21162 subl $4,%esp
21163 CFI_ADJUST_CFA_OFFSET 4
21164 pushl_cfi %edi
21165 @@ -320,7 +336,7 @@ ENTRY(csum_partial_copy_generic)
21166 jmp 4f
21167 SRC(1: movw (%esi), %bx )
21168 addl $2, %esi
21169 -DST( movw %bx, (%edi) )
21170 +DST( movw %bx, %es:(%edi) )
21171 addl $2, %edi
21172 addw %bx, %ax
21173 adcl $0, %eax
21174 @@ -332,30 +348,30 @@ DST( movw %bx, (%edi) )
21175 SRC(1: movl (%esi), %ebx )
21176 SRC( movl 4(%esi), %edx )
21177 adcl %ebx, %eax
21178 -DST( movl %ebx, (%edi) )
21179 +DST( movl %ebx, %es:(%edi) )
21180 adcl %edx, %eax
21181 -DST( movl %edx, 4(%edi) )
21182 +DST( movl %edx, %es:4(%edi) )
21183
21184 SRC( movl 8(%esi), %ebx )
21185 SRC( movl 12(%esi), %edx )
21186 adcl %ebx, %eax
21187 -DST( movl %ebx, 8(%edi) )
21188 +DST( movl %ebx, %es:8(%edi) )
21189 adcl %edx, %eax
21190 -DST( movl %edx, 12(%edi) )
21191 +DST( movl %edx, %es:12(%edi) )
21192
21193 SRC( movl 16(%esi), %ebx )
21194 SRC( movl 20(%esi), %edx )
21195 adcl %ebx, %eax
21196 -DST( movl %ebx, 16(%edi) )
21197 +DST( movl %ebx, %es:16(%edi) )
21198 adcl %edx, %eax
21199 -DST( movl %edx, 20(%edi) )
21200 +DST( movl %edx, %es:20(%edi) )
21201
21202 SRC( movl 24(%esi), %ebx )
21203 SRC( movl 28(%esi), %edx )
21204 adcl %ebx, %eax
21205 -DST( movl %ebx, 24(%edi) )
21206 +DST( movl %ebx, %es:24(%edi) )
21207 adcl %edx, %eax
21208 -DST( movl %edx, 28(%edi) )
21209 +DST( movl %edx, %es:28(%edi) )
21210
21211 lea 32(%esi), %esi
21212 lea 32(%edi), %edi
21213 @@ -369,7 +385,7 @@ DST( movl %edx, 28(%edi) )
21214 shrl $2, %edx # This clears CF
21215 SRC(3: movl (%esi), %ebx )
21216 adcl %ebx, %eax
21217 -DST( movl %ebx, (%edi) )
21218 +DST( movl %ebx, %es:(%edi) )
21219 lea 4(%esi), %esi
21220 lea 4(%edi), %edi
21221 dec %edx
21222 @@ -381,12 +397,12 @@ DST( movl %ebx, (%edi) )
21223 jb 5f
21224 SRC( movw (%esi), %cx )
21225 leal 2(%esi), %esi
21226 -DST( movw %cx, (%edi) )
21227 +DST( movw %cx, %es:(%edi) )
21228 leal 2(%edi), %edi
21229 je 6f
21230 shll $16,%ecx
21231 SRC(5: movb (%esi), %cl )
21232 -DST( movb %cl, (%edi) )
21233 +DST( movb %cl, %es:(%edi) )
21234 6: addl %ecx, %eax
21235 adcl $0, %eax
21236 7:
21237 @@ -397,7 +413,7 @@ DST( movb %cl, (%edi) )
21238
21239 6001:
21240 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21241 - movl $-EFAULT, (%ebx)
21242 + movl $-EFAULT, %ss:(%ebx)
21243
21244 # zero the complete destination - computing the rest
21245 # is too much work
21246 @@ -410,11 +426,15 @@ DST( movb %cl, (%edi) )
21247
21248 6002:
21249 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21250 - movl $-EFAULT,(%ebx)
21251 + movl $-EFAULT,%ss:(%ebx)
21252 jmp 5000b
21253
21254 .previous
21255
21256 + pushl_cfi %ss
21257 + popl_cfi %ds
21258 + pushl_cfi %ss
21259 + popl_cfi %es
21260 popl_cfi %ebx
21261 CFI_RESTORE ebx
21262 popl_cfi %esi
21263 @@ -424,26 +444,43 @@ DST( movb %cl, (%edi) )
21264 popl_cfi %ecx # equivalent to addl $4,%esp
21265 ret
21266 CFI_ENDPROC
21267 -ENDPROC(csum_partial_copy_generic)
21268 +ENDPROC(csum_partial_copy_generic_to_user)
21269
21270 #else
21271
21272 /* Version for PentiumII/PPro */
21273
21274 #define ROUND1(x) \
21275 + nop; nop; nop; \
21276 SRC(movl x(%esi), %ebx ) ; \
21277 addl %ebx, %eax ; \
21278 - DST(movl %ebx, x(%edi) ) ;
21279 + DST(movl %ebx, %es:x(%edi)) ;
21280
21281 #define ROUND(x) \
21282 + nop; nop; nop; \
21283 SRC(movl x(%esi), %ebx ) ; \
21284 adcl %ebx, %eax ; \
21285 - DST(movl %ebx, x(%edi) ) ;
21286 + DST(movl %ebx, %es:x(%edi)) ;
21287
21288 #define ARGBASE 12
21289 -
21290 -ENTRY(csum_partial_copy_generic)
21291 +
21292 +ENTRY(csum_partial_copy_generic_to_user)
21293 CFI_STARTPROC
21294 +
21295 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21296 + pushl_cfi %gs
21297 + popl_cfi %es
21298 + jmp csum_partial_copy_generic
21299 +#endif
21300 +
21301 +ENTRY(csum_partial_copy_generic_from_user)
21302 +
21303 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21304 + pushl_cfi %gs
21305 + popl_cfi %ds
21306 +#endif
21307 +
21308 +ENTRY(csum_partial_copy_generic)
21309 pushl_cfi %ebx
21310 CFI_REL_OFFSET ebx, 0
21311 pushl_cfi %edi
21312 @@ -464,7 +501,7 @@ ENTRY(csum_partial_copy_generic)
21313 subl %ebx, %edi
21314 lea -1(%esi),%edx
21315 andl $-32,%edx
21316 - lea 3f(%ebx,%ebx), %ebx
21317 + lea 3f(%ebx,%ebx,2), %ebx
21318 testl %esi, %esi
21319 jmp *%ebx
21320 1: addl $64,%esi
21321 @@ -485,19 +522,19 @@ ENTRY(csum_partial_copy_generic)
21322 jb 5f
21323 SRC( movw (%esi), %dx )
21324 leal 2(%esi), %esi
21325 -DST( movw %dx, (%edi) )
21326 +DST( movw %dx, %es:(%edi) )
21327 leal 2(%edi), %edi
21328 je 6f
21329 shll $16,%edx
21330 5:
21331 SRC( movb (%esi), %dl )
21332 -DST( movb %dl, (%edi) )
21333 +DST( movb %dl, %es:(%edi) )
21334 6: addl %edx, %eax
21335 adcl $0, %eax
21336 7:
21337 .section .fixup, "ax"
21338 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21339 - movl $-EFAULT, (%ebx)
21340 + movl $-EFAULT, %ss:(%ebx)
21341 # zero the complete destination (computing the rest is too much work)
21342 movl ARGBASE+8(%esp),%edi # dst
21343 movl ARGBASE+12(%esp),%ecx # len
21344 @@ -505,10 +542,17 @@ DST( movb %dl, (%edi) )
21345 rep; stosb
21346 jmp 7b
21347 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21348 - movl $-EFAULT, (%ebx)
21349 + movl $-EFAULT, %ss:(%ebx)
21350 jmp 7b
21351 .previous
21352
21353 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21354 + pushl_cfi %ss
21355 + popl_cfi %ds
21356 + pushl_cfi %ss
21357 + popl_cfi %es
21358 +#endif
21359 +
21360 popl_cfi %esi
21361 CFI_RESTORE esi
21362 popl_cfi %edi
21363 @@ -517,7 +561,7 @@ DST( movb %dl, (%edi) )
21364 CFI_RESTORE ebx
21365 ret
21366 CFI_ENDPROC
21367 -ENDPROC(csum_partial_copy_generic)
21368 +ENDPROC(csum_partial_copy_generic_to_user)
21369
21370 #undef ROUND
21371 #undef ROUND1
21372 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21373 index f2145cf..cea889d 100644
21374 --- a/arch/x86/lib/clear_page_64.S
21375 +++ b/arch/x86/lib/clear_page_64.S
21376 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21377 movl $4096/8,%ecx
21378 xorl %eax,%eax
21379 rep stosq
21380 + pax_force_retaddr
21381 ret
21382 CFI_ENDPROC
21383 ENDPROC(clear_page_c)
21384 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21385 movl $4096,%ecx
21386 xorl %eax,%eax
21387 rep stosb
21388 + pax_force_retaddr
21389 ret
21390 CFI_ENDPROC
21391 ENDPROC(clear_page_c_e)
21392 @@ -43,6 +45,7 @@ ENTRY(clear_page)
21393 leaq 64(%rdi),%rdi
21394 jnz .Lloop
21395 nop
21396 + pax_force_retaddr
21397 ret
21398 CFI_ENDPROC
21399 .Lclear_page_end:
21400 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
21401
21402 #include <asm/cpufeature.h>
21403
21404 - .section .altinstr_replacement,"ax"
21405 + .section .altinstr_replacement,"a"
21406 1: .byte 0xeb /* jmp <disp8> */
21407 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21408 2: .byte 0xeb /* jmp <disp8> */
21409 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21410 index 1e572c5..2a162cd 100644
21411 --- a/arch/x86/lib/cmpxchg16b_emu.S
21412 +++ b/arch/x86/lib/cmpxchg16b_emu.S
21413 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21414
21415 popf
21416 mov $1, %al
21417 + pax_force_retaddr
21418 ret
21419
21420 not_same:
21421 popf
21422 xor %al,%al
21423 + pax_force_retaddr
21424 ret
21425
21426 CFI_ENDPROC
21427 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21428 index 6b34d04..dccb07f 100644
21429 --- a/arch/x86/lib/copy_page_64.S
21430 +++ b/arch/x86/lib/copy_page_64.S
21431 @@ -9,6 +9,7 @@ copy_page_c:
21432 CFI_STARTPROC
21433 movl $4096/8,%ecx
21434 rep movsq
21435 + pax_force_retaddr
21436 ret
21437 CFI_ENDPROC
21438 ENDPROC(copy_page_c)
21439 @@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21440
21441 ENTRY(copy_page)
21442 CFI_STARTPROC
21443 - subq $2*8,%rsp
21444 - CFI_ADJUST_CFA_OFFSET 2*8
21445 + subq $3*8,%rsp
21446 + CFI_ADJUST_CFA_OFFSET 3*8
21447 movq %rbx,(%rsp)
21448 CFI_REL_OFFSET rbx, 0
21449 movq %r12,1*8(%rsp)
21450 CFI_REL_OFFSET r12, 1*8
21451 + movq %r13,2*8(%rsp)
21452 + CFI_REL_OFFSET r13, 2*8
21453
21454 movl $(4096/64)-5,%ecx
21455 .p2align 4
21456 @@ -37,7 +40,7 @@ ENTRY(copy_page)
21457 movq 16 (%rsi), %rdx
21458 movq 24 (%rsi), %r8
21459 movq 32 (%rsi), %r9
21460 - movq 40 (%rsi), %r10
21461 + movq 40 (%rsi), %r13
21462 movq 48 (%rsi), %r11
21463 movq 56 (%rsi), %r12
21464
21465 @@ -48,7 +51,7 @@ ENTRY(copy_page)
21466 movq %rdx, 16 (%rdi)
21467 movq %r8, 24 (%rdi)
21468 movq %r9, 32 (%rdi)
21469 - movq %r10, 40 (%rdi)
21470 + movq %r13, 40 (%rdi)
21471 movq %r11, 48 (%rdi)
21472 movq %r12, 56 (%rdi)
21473
21474 @@ -67,7 +70,7 @@ ENTRY(copy_page)
21475 movq 16 (%rsi), %rdx
21476 movq 24 (%rsi), %r8
21477 movq 32 (%rsi), %r9
21478 - movq 40 (%rsi), %r10
21479 + movq 40 (%rsi), %r13
21480 movq 48 (%rsi), %r11
21481 movq 56 (%rsi), %r12
21482
21483 @@ -76,7 +79,7 @@ ENTRY(copy_page)
21484 movq %rdx, 16 (%rdi)
21485 movq %r8, 24 (%rdi)
21486 movq %r9, 32 (%rdi)
21487 - movq %r10, 40 (%rdi)
21488 + movq %r13, 40 (%rdi)
21489 movq %r11, 48 (%rdi)
21490 movq %r12, 56 (%rdi)
21491
21492 @@ -89,8 +92,11 @@ ENTRY(copy_page)
21493 CFI_RESTORE rbx
21494 movq 1*8(%rsp),%r12
21495 CFI_RESTORE r12
21496 - addq $2*8,%rsp
21497 - CFI_ADJUST_CFA_OFFSET -2*8
21498 + movq 2*8(%rsp),%r13
21499 + CFI_RESTORE r13
21500 + addq $3*8,%rsp
21501 + CFI_ADJUST_CFA_OFFSET -3*8
21502 + pax_force_retaddr
21503 ret
21504 .Lcopy_page_end:
21505 CFI_ENDPROC
21506 @@ -101,7 +107,7 @@ ENDPROC(copy_page)
21507
21508 #include <asm/cpufeature.h>
21509
21510 - .section .altinstr_replacement,"ax"
21511 + .section .altinstr_replacement,"a"
21512 1: .byte 0xeb /* jmp <disp8> */
21513 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21514 2:
21515 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21516 index 0248402..821c786 100644
21517 --- a/arch/x86/lib/copy_user_64.S
21518 +++ b/arch/x86/lib/copy_user_64.S
21519 @@ -16,6 +16,7 @@
21520 #include <asm/thread_info.h>
21521 #include <asm/cpufeature.h>
21522 #include <asm/alternative-asm.h>
21523 +#include <asm/pgtable.h>
21524
21525 /*
21526 * By placing feature2 after feature1 in altinstructions section, we logically
21527 @@ -29,7 +30,7 @@
21528 .byte 0xe9 /* 32bit jump */
21529 .long \orig-1f /* by default jump to orig */
21530 1:
21531 - .section .altinstr_replacement,"ax"
21532 + .section .altinstr_replacement,"a"
21533 2: .byte 0xe9 /* near jump with 32bit immediate */
21534 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21535 3: .byte 0xe9 /* near jump with 32bit immediate */
21536 @@ -71,47 +72,20 @@
21537 #endif
21538 .endm
21539
21540 -/* Standard copy_to_user with segment limit checking */
21541 -ENTRY(_copy_to_user)
21542 - CFI_STARTPROC
21543 - GET_THREAD_INFO(%rax)
21544 - movq %rdi,%rcx
21545 - addq %rdx,%rcx
21546 - jc bad_to_user
21547 - cmpq TI_addr_limit(%rax),%rcx
21548 - ja bad_to_user
21549 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21550 - copy_user_generic_unrolled,copy_user_generic_string, \
21551 - copy_user_enhanced_fast_string
21552 - CFI_ENDPROC
21553 -ENDPROC(_copy_to_user)
21554 -
21555 -/* Standard copy_from_user with segment limit checking */
21556 -ENTRY(_copy_from_user)
21557 - CFI_STARTPROC
21558 - GET_THREAD_INFO(%rax)
21559 - movq %rsi,%rcx
21560 - addq %rdx,%rcx
21561 - jc bad_from_user
21562 - cmpq TI_addr_limit(%rax),%rcx
21563 - ja bad_from_user
21564 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21565 - copy_user_generic_unrolled,copy_user_generic_string, \
21566 - copy_user_enhanced_fast_string
21567 - CFI_ENDPROC
21568 -ENDPROC(_copy_from_user)
21569 -
21570 .section .fixup,"ax"
21571 /* must zero dest */
21572 ENTRY(bad_from_user)
21573 bad_from_user:
21574 CFI_STARTPROC
21575 + testl %edx,%edx
21576 + js bad_to_user
21577 movl %edx,%ecx
21578 xorl %eax,%eax
21579 rep
21580 stosb
21581 bad_to_user:
21582 movl %edx,%eax
21583 + pax_force_retaddr
21584 ret
21585 CFI_ENDPROC
21586 ENDPROC(bad_from_user)
21587 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
21588 jz 17f
21589 1: movq (%rsi),%r8
21590 2: movq 1*8(%rsi),%r9
21591 -3: movq 2*8(%rsi),%r10
21592 +3: movq 2*8(%rsi),%rax
21593 4: movq 3*8(%rsi),%r11
21594 5: movq %r8,(%rdi)
21595 6: movq %r9,1*8(%rdi)
21596 -7: movq %r10,2*8(%rdi)
21597 +7: movq %rax,2*8(%rdi)
21598 8: movq %r11,3*8(%rdi)
21599 9: movq 4*8(%rsi),%r8
21600 10: movq 5*8(%rsi),%r9
21601 -11: movq 6*8(%rsi),%r10
21602 +11: movq 6*8(%rsi),%rax
21603 12: movq 7*8(%rsi),%r11
21604 13: movq %r8,4*8(%rdi)
21605 14: movq %r9,5*8(%rdi)
21606 -15: movq %r10,6*8(%rdi)
21607 +15: movq %rax,6*8(%rdi)
21608 16: movq %r11,7*8(%rdi)
21609 leaq 64(%rsi),%rsi
21610 leaq 64(%rdi),%rdi
21611 @@ -179,6 +153,7 @@ ENTRY(copy_user_generic_unrolled)
21612 decl %ecx
21613 jnz 21b
21614 23: xor %eax,%eax
21615 + pax_force_retaddr
21616 ret
21617
21618 .section .fixup,"ax"
21619 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
21620 3: rep
21621 movsb
21622 4: xorl %eax,%eax
21623 + pax_force_retaddr
21624 ret
21625
21626 .section .fixup,"ax"
21627 @@ -287,6 +263,7 @@ ENTRY(copy_user_enhanced_fast_string)
21628 1: rep
21629 movsb
21630 2: xorl %eax,%eax
21631 + pax_force_retaddr
21632 ret
21633
21634 .section .fixup,"ax"
21635 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21636 index cb0c112..e3a6895 100644
21637 --- a/arch/x86/lib/copy_user_nocache_64.S
21638 +++ b/arch/x86/lib/copy_user_nocache_64.S
21639 @@ -8,12 +8,14 @@
21640
21641 #include <linux/linkage.h>
21642 #include <asm/dwarf2.h>
21643 +#include <asm/alternative-asm.h>
21644
21645 #define FIX_ALIGNMENT 1
21646
21647 #include <asm/current.h>
21648 #include <asm/asm-offsets.h>
21649 #include <asm/thread_info.h>
21650 +#include <asm/pgtable.h>
21651
21652 .macro ALIGN_DESTINATION
21653 #ifdef FIX_ALIGNMENT
21654 @@ -50,6 +52,15 @@
21655 */
21656 ENTRY(__copy_user_nocache)
21657 CFI_STARTPROC
21658 +
21659 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21660 + mov $PAX_USER_SHADOW_BASE,%rcx
21661 + cmp %rcx,%rsi
21662 + jae 1f
21663 + add %rcx,%rsi
21664 +1:
21665 +#endif
21666 +
21667 cmpl $8,%edx
21668 jb 20f /* less then 8 bytes, go to byte copy loop */
21669 ALIGN_DESTINATION
21670 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
21671 jz 17f
21672 1: movq (%rsi),%r8
21673 2: movq 1*8(%rsi),%r9
21674 -3: movq 2*8(%rsi),%r10
21675 +3: movq 2*8(%rsi),%rax
21676 4: movq 3*8(%rsi),%r11
21677 5: movnti %r8,(%rdi)
21678 6: movnti %r9,1*8(%rdi)
21679 -7: movnti %r10,2*8(%rdi)
21680 +7: movnti %rax,2*8(%rdi)
21681 8: movnti %r11,3*8(%rdi)
21682 9: movq 4*8(%rsi),%r8
21683 10: movq 5*8(%rsi),%r9
21684 -11: movq 6*8(%rsi),%r10
21685 +11: movq 6*8(%rsi),%rax
21686 12: movq 7*8(%rsi),%r11
21687 13: movnti %r8,4*8(%rdi)
21688 14: movnti %r9,5*8(%rdi)
21689 -15: movnti %r10,6*8(%rdi)
21690 +15: movnti %rax,6*8(%rdi)
21691 16: movnti %r11,7*8(%rdi)
21692 leaq 64(%rsi),%rsi
21693 leaq 64(%rdi),%rdi
21694 @@ -98,6 +109,7 @@ ENTRY(__copy_user_nocache)
21695 jnz 21b
21696 23: xorl %eax,%eax
21697 sfence
21698 + pax_force_retaddr
21699 ret
21700
21701 .section .fixup,"ax"
21702 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21703 index fb903b7..c92b7f7 100644
21704 --- a/arch/x86/lib/csum-copy_64.S
21705 +++ b/arch/x86/lib/csum-copy_64.S
21706 @@ -8,6 +8,7 @@
21707 #include <linux/linkage.h>
21708 #include <asm/dwarf2.h>
21709 #include <asm/errno.h>
21710 +#include <asm/alternative-asm.h>
21711
21712 /*
21713 * Checksum copy with exception handling.
21714 @@ -228,6 +229,7 @@ ENTRY(csum_partial_copy_generic)
21715 CFI_RESTORE rbp
21716 addq $7*8, %rsp
21717 CFI_ADJUST_CFA_OFFSET -7*8
21718 + pax_force_retaddr 0, 1
21719 ret
21720 CFI_RESTORE_STATE
21721
21722 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21723 index 459b58a..9570bc7 100644
21724 --- a/arch/x86/lib/csum-wrappers_64.c
21725 +++ b/arch/x86/lib/csum-wrappers_64.c
21726 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21727 len -= 2;
21728 }
21729 }
21730 - isum = csum_partial_copy_generic((__force const void *)src,
21731 +
21732 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21733 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21734 + src += PAX_USER_SHADOW_BASE;
21735 +#endif
21736 +
21737 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
21738 dst, len, isum, errp, NULL);
21739 if (unlikely(*errp))
21740 goto out_err;
21741 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21742 }
21743
21744 *errp = 0;
21745 - return csum_partial_copy_generic(src, (void __force *)dst,
21746 +
21747 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21748 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21749 + dst += PAX_USER_SHADOW_BASE;
21750 +#endif
21751 +
21752 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21753 len, isum, NULL, errp);
21754 }
21755 EXPORT_SYMBOL(csum_partial_copy_to_user);
21756 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21757 index 51f1504..ddac4c1 100644
21758 --- a/arch/x86/lib/getuser.S
21759 +++ b/arch/x86/lib/getuser.S
21760 @@ -33,15 +33,38 @@
21761 #include <asm/asm-offsets.h>
21762 #include <asm/thread_info.h>
21763 #include <asm/asm.h>
21764 +#include <asm/segment.h>
21765 +#include <asm/pgtable.h>
21766 +#include <asm/alternative-asm.h>
21767 +
21768 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21769 +#define __copyuser_seg gs;
21770 +#else
21771 +#define __copyuser_seg
21772 +#endif
21773
21774 .text
21775 ENTRY(__get_user_1)
21776 CFI_STARTPROC
21777 +
21778 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21779 GET_THREAD_INFO(%_ASM_DX)
21780 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21781 jae bad_get_user
21782 -1: movzb (%_ASM_AX),%edx
21783 +
21784 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21785 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21786 + cmp %_ASM_DX,%_ASM_AX
21787 + jae 1234f
21788 + add %_ASM_DX,%_ASM_AX
21789 +1234:
21790 +#endif
21791 +
21792 +#endif
21793 +
21794 +1: __copyuser_seg movzb (%_ASM_AX),%edx
21795 xor %eax,%eax
21796 + pax_force_retaddr
21797 ret
21798 CFI_ENDPROC
21799 ENDPROC(__get_user_1)
21800 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21801 ENTRY(__get_user_2)
21802 CFI_STARTPROC
21803 add $1,%_ASM_AX
21804 +
21805 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21806 jc bad_get_user
21807 GET_THREAD_INFO(%_ASM_DX)
21808 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21809 jae bad_get_user
21810 -2: movzwl -1(%_ASM_AX),%edx
21811 +
21812 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21813 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21814 + cmp %_ASM_DX,%_ASM_AX
21815 + jae 1234f
21816 + add %_ASM_DX,%_ASM_AX
21817 +1234:
21818 +#endif
21819 +
21820 +#endif
21821 +
21822 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21823 xor %eax,%eax
21824 + pax_force_retaddr
21825 ret
21826 CFI_ENDPROC
21827 ENDPROC(__get_user_2)
21828 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21829 ENTRY(__get_user_4)
21830 CFI_STARTPROC
21831 add $3,%_ASM_AX
21832 +
21833 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21834 jc bad_get_user
21835 GET_THREAD_INFO(%_ASM_DX)
21836 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21837 jae bad_get_user
21838 -3: mov -3(%_ASM_AX),%edx
21839 +
21840 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21841 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21842 + cmp %_ASM_DX,%_ASM_AX
21843 + jae 1234f
21844 + add %_ASM_DX,%_ASM_AX
21845 +1234:
21846 +#endif
21847 +
21848 +#endif
21849 +
21850 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
21851 xor %eax,%eax
21852 + pax_force_retaddr
21853 ret
21854 CFI_ENDPROC
21855 ENDPROC(__get_user_4)
21856 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21857 GET_THREAD_INFO(%_ASM_DX)
21858 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21859 jae bad_get_user
21860 +
21861 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21862 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21863 + cmp %_ASM_DX,%_ASM_AX
21864 + jae 1234f
21865 + add %_ASM_DX,%_ASM_AX
21866 +1234:
21867 +#endif
21868 +
21869 4: movq -7(%_ASM_AX),%_ASM_DX
21870 xor %eax,%eax
21871 + pax_force_retaddr
21872 ret
21873 CFI_ENDPROC
21874 ENDPROC(__get_user_8)
21875 @@ -91,6 +152,7 @@ bad_get_user:
21876 CFI_STARTPROC
21877 xor %edx,%edx
21878 mov $(-EFAULT),%_ASM_AX
21879 + pax_force_retaddr
21880 ret
21881 CFI_ENDPROC
21882 END(bad_get_user)
21883 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21884 index b1e6c4b..21ae8fc 100644
21885 --- a/arch/x86/lib/insn.c
21886 +++ b/arch/x86/lib/insn.c
21887 @@ -21,6 +21,11 @@
21888 #include <linux/string.h>
21889 #include <asm/inat.h>
21890 #include <asm/insn.h>
21891 +#ifdef __KERNEL__
21892 +#include <asm/pgtable_types.h>
21893 +#else
21894 +#define ktla_ktva(addr) addr
21895 +#endif
21896
21897 /* Verify next sizeof(t) bytes can be on the same instruction */
21898 #define validate_next(t, insn, n) \
21899 @@ -49,8 +54,8 @@
21900 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21901 {
21902 memset(insn, 0, sizeof(*insn));
21903 - insn->kaddr = kaddr;
21904 - insn->next_byte = kaddr;
21905 + insn->kaddr = ktla_ktva(kaddr);
21906 + insn->next_byte = ktla_ktva(kaddr);
21907 insn->x86_64 = x86_64 ? 1 : 0;
21908 insn->opnd_bytes = 4;
21909 if (x86_64)
21910 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21911 index 05a95e7..326f2fa 100644
21912 --- a/arch/x86/lib/iomap_copy_64.S
21913 +++ b/arch/x86/lib/iomap_copy_64.S
21914 @@ -17,6 +17,7 @@
21915
21916 #include <linux/linkage.h>
21917 #include <asm/dwarf2.h>
21918 +#include <asm/alternative-asm.h>
21919
21920 /*
21921 * override generic version in lib/iomap_copy.c
21922 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21923 CFI_STARTPROC
21924 movl %edx,%ecx
21925 rep movsd
21926 + pax_force_retaddr
21927 ret
21928 CFI_ENDPROC
21929 ENDPROC(__iowrite32_copy)
21930 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21931 index 1c273be..da9cc0e 100644
21932 --- a/arch/x86/lib/memcpy_64.S
21933 +++ b/arch/x86/lib/memcpy_64.S
21934 @@ -33,6 +33,7 @@
21935 rep movsq
21936 movl %edx, %ecx
21937 rep movsb
21938 + pax_force_retaddr
21939 ret
21940 .Lmemcpy_e:
21941 .previous
21942 @@ -49,6 +50,7 @@
21943 movq %rdi, %rax
21944 movq %rdx, %rcx
21945 rep movsb
21946 + pax_force_retaddr
21947 ret
21948 .Lmemcpy_e_e:
21949 .previous
21950 @@ -76,13 +78,13 @@ ENTRY(memcpy)
21951 */
21952 movq 0*8(%rsi), %r8
21953 movq 1*8(%rsi), %r9
21954 - movq 2*8(%rsi), %r10
21955 + movq 2*8(%rsi), %rcx
21956 movq 3*8(%rsi), %r11
21957 leaq 4*8(%rsi), %rsi
21958
21959 movq %r8, 0*8(%rdi)
21960 movq %r9, 1*8(%rdi)
21961 - movq %r10, 2*8(%rdi)
21962 + movq %rcx, 2*8(%rdi)
21963 movq %r11, 3*8(%rdi)
21964 leaq 4*8(%rdi), %rdi
21965 jae .Lcopy_forward_loop
21966 @@ -105,12 +107,12 @@ ENTRY(memcpy)
21967 subq $0x20, %rdx
21968 movq -1*8(%rsi), %r8
21969 movq -2*8(%rsi), %r9
21970 - movq -3*8(%rsi), %r10
21971 + movq -3*8(%rsi), %rcx
21972 movq -4*8(%rsi), %r11
21973 leaq -4*8(%rsi), %rsi
21974 movq %r8, -1*8(%rdi)
21975 movq %r9, -2*8(%rdi)
21976 - movq %r10, -3*8(%rdi)
21977 + movq %rcx, -3*8(%rdi)
21978 movq %r11, -4*8(%rdi)
21979 leaq -4*8(%rdi), %rdi
21980 jae .Lcopy_backward_loop
21981 @@ -130,12 +132,13 @@ ENTRY(memcpy)
21982 */
21983 movq 0*8(%rsi), %r8
21984 movq 1*8(%rsi), %r9
21985 - movq -2*8(%rsi, %rdx), %r10
21986 + movq -2*8(%rsi, %rdx), %rcx
21987 movq -1*8(%rsi, %rdx), %r11
21988 movq %r8, 0*8(%rdi)
21989 movq %r9, 1*8(%rdi)
21990 - movq %r10, -2*8(%rdi, %rdx)
21991 + movq %rcx, -2*8(%rdi, %rdx)
21992 movq %r11, -1*8(%rdi, %rdx)
21993 + pax_force_retaddr
21994 retq
21995 .p2align 4
21996 .Lless_16bytes:
21997 @@ -148,6 +151,7 @@ ENTRY(memcpy)
21998 movq -1*8(%rsi, %rdx), %r9
21999 movq %r8, 0*8(%rdi)
22000 movq %r9, -1*8(%rdi, %rdx)
22001 + pax_force_retaddr
22002 retq
22003 .p2align 4
22004 .Lless_8bytes:
22005 @@ -161,6 +165,7 @@ ENTRY(memcpy)
22006 movl -4(%rsi, %rdx), %r8d
22007 movl %ecx, (%rdi)
22008 movl %r8d, -4(%rdi, %rdx)
22009 + pax_force_retaddr
22010 retq
22011 .p2align 4
22012 .Lless_3bytes:
22013 @@ -179,6 +184,7 @@ ENTRY(memcpy)
22014 movb %cl, (%rdi)
22015
22016 .Lend:
22017 + pax_force_retaddr
22018 retq
22019 CFI_ENDPROC
22020 ENDPROC(memcpy)
22021 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
22022 index ee16461..c39c199 100644
22023 --- a/arch/x86/lib/memmove_64.S
22024 +++ b/arch/x86/lib/memmove_64.S
22025 @@ -61,13 +61,13 @@ ENTRY(memmove)
22026 5:
22027 sub $0x20, %rdx
22028 movq 0*8(%rsi), %r11
22029 - movq 1*8(%rsi), %r10
22030 + movq 1*8(%rsi), %rcx
22031 movq 2*8(%rsi), %r9
22032 movq 3*8(%rsi), %r8
22033 leaq 4*8(%rsi), %rsi
22034
22035 movq %r11, 0*8(%rdi)
22036 - movq %r10, 1*8(%rdi)
22037 + movq %rcx, 1*8(%rdi)
22038 movq %r9, 2*8(%rdi)
22039 movq %r8, 3*8(%rdi)
22040 leaq 4*8(%rdi), %rdi
22041 @@ -81,10 +81,10 @@ ENTRY(memmove)
22042 4:
22043 movq %rdx, %rcx
22044 movq -8(%rsi, %rdx), %r11
22045 - lea -8(%rdi, %rdx), %r10
22046 + lea -8(%rdi, %rdx), %r9
22047 shrq $3, %rcx
22048 rep movsq
22049 - movq %r11, (%r10)
22050 + movq %r11, (%r9)
22051 jmp 13f
22052 .Lmemmove_end_forward:
22053
22054 @@ -95,14 +95,14 @@ ENTRY(memmove)
22055 7:
22056 movq %rdx, %rcx
22057 movq (%rsi), %r11
22058 - movq %rdi, %r10
22059 + movq %rdi, %r9
22060 leaq -8(%rsi, %rdx), %rsi
22061 leaq -8(%rdi, %rdx), %rdi
22062 shrq $3, %rcx
22063 std
22064 rep movsq
22065 cld
22066 - movq %r11, (%r10)
22067 + movq %r11, (%r9)
22068 jmp 13f
22069
22070 /*
22071 @@ -127,13 +127,13 @@ ENTRY(memmove)
22072 8:
22073 subq $0x20, %rdx
22074 movq -1*8(%rsi), %r11
22075 - movq -2*8(%rsi), %r10
22076 + movq -2*8(%rsi), %rcx
22077 movq -3*8(%rsi), %r9
22078 movq -4*8(%rsi), %r8
22079 leaq -4*8(%rsi), %rsi
22080
22081 movq %r11, -1*8(%rdi)
22082 - movq %r10, -2*8(%rdi)
22083 + movq %rcx, -2*8(%rdi)
22084 movq %r9, -3*8(%rdi)
22085 movq %r8, -4*8(%rdi)
22086 leaq -4*8(%rdi), %rdi
22087 @@ -151,11 +151,11 @@ ENTRY(memmove)
22088 * Move data from 16 bytes to 31 bytes.
22089 */
22090 movq 0*8(%rsi), %r11
22091 - movq 1*8(%rsi), %r10
22092 + movq 1*8(%rsi), %rcx
22093 movq -2*8(%rsi, %rdx), %r9
22094 movq -1*8(%rsi, %rdx), %r8
22095 movq %r11, 0*8(%rdi)
22096 - movq %r10, 1*8(%rdi)
22097 + movq %rcx, 1*8(%rdi)
22098 movq %r9, -2*8(%rdi, %rdx)
22099 movq %r8, -1*8(%rdi, %rdx)
22100 jmp 13f
22101 @@ -167,9 +167,9 @@ ENTRY(memmove)
22102 * Move data from 8 bytes to 15 bytes.
22103 */
22104 movq 0*8(%rsi), %r11
22105 - movq -1*8(%rsi, %rdx), %r10
22106 + movq -1*8(%rsi, %rdx), %r9
22107 movq %r11, 0*8(%rdi)
22108 - movq %r10, -1*8(%rdi, %rdx)
22109 + movq %r9, -1*8(%rdi, %rdx)
22110 jmp 13f
22111 10:
22112 cmpq $4, %rdx
22113 @@ -178,9 +178,9 @@ ENTRY(memmove)
22114 * Move data from 4 bytes to 7 bytes.
22115 */
22116 movl (%rsi), %r11d
22117 - movl -4(%rsi, %rdx), %r10d
22118 + movl -4(%rsi, %rdx), %r9d
22119 movl %r11d, (%rdi)
22120 - movl %r10d, -4(%rdi, %rdx)
22121 + movl %r9d, -4(%rdi, %rdx)
22122 jmp 13f
22123 11:
22124 cmp $2, %rdx
22125 @@ -189,9 +189,9 @@ ENTRY(memmove)
22126 * Move data from 2 bytes to 3 bytes.
22127 */
22128 movw (%rsi), %r11w
22129 - movw -2(%rsi, %rdx), %r10w
22130 + movw -2(%rsi, %rdx), %r9w
22131 movw %r11w, (%rdi)
22132 - movw %r10w, -2(%rdi, %rdx)
22133 + movw %r9w, -2(%rdi, %rdx)
22134 jmp 13f
22135 12:
22136 cmp $1, %rdx
22137 @@ -202,6 +202,7 @@ ENTRY(memmove)
22138 movb (%rsi), %r11b
22139 movb %r11b, (%rdi)
22140 13:
22141 + pax_force_retaddr
22142 retq
22143 CFI_ENDPROC
22144
22145 @@ -210,6 +211,7 @@ ENTRY(memmove)
22146 /* Forward moving data. */
22147 movq %rdx, %rcx
22148 rep movsb
22149 + pax_force_retaddr
22150 retq
22151 .Lmemmove_end_forward_efs:
22152 .previous
22153 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22154 index 2dcb380..963660a 100644
22155 --- a/arch/x86/lib/memset_64.S
22156 +++ b/arch/x86/lib/memset_64.S
22157 @@ -30,6 +30,7 @@
22158 movl %edx,%ecx
22159 rep stosb
22160 movq %r9,%rax
22161 + pax_force_retaddr
22162 ret
22163 .Lmemset_e:
22164 .previous
22165 @@ -52,6 +53,7 @@
22166 movq %rdx,%rcx
22167 rep stosb
22168 movq %r9,%rax
22169 + pax_force_retaddr
22170 ret
22171 .Lmemset_e_e:
22172 .previous
22173 @@ -59,7 +61,7 @@
22174 ENTRY(memset)
22175 ENTRY(__memset)
22176 CFI_STARTPROC
22177 - movq %rdi,%r10
22178 + movq %rdi,%r11
22179
22180 /* expand byte value */
22181 movzbl %sil,%ecx
22182 @@ -117,7 +119,8 @@ ENTRY(__memset)
22183 jnz .Lloop_1
22184
22185 .Lende:
22186 - movq %r10,%rax
22187 + movq %r11,%rax
22188 + pax_force_retaddr
22189 ret
22190
22191 CFI_RESTORE_STATE
22192 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22193 index c9f2d9b..e7fd2c0 100644
22194 --- a/arch/x86/lib/mmx_32.c
22195 +++ b/arch/x86/lib/mmx_32.c
22196 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22197 {
22198 void *p;
22199 int i;
22200 + unsigned long cr0;
22201
22202 if (unlikely(in_interrupt()))
22203 return __memcpy(to, from, len);
22204 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22205 kernel_fpu_begin();
22206
22207 __asm__ __volatile__ (
22208 - "1: prefetch (%0)\n" /* This set is 28 bytes */
22209 - " prefetch 64(%0)\n"
22210 - " prefetch 128(%0)\n"
22211 - " prefetch 192(%0)\n"
22212 - " prefetch 256(%0)\n"
22213 + "1: prefetch (%1)\n" /* This set is 28 bytes */
22214 + " prefetch 64(%1)\n"
22215 + " prefetch 128(%1)\n"
22216 + " prefetch 192(%1)\n"
22217 + " prefetch 256(%1)\n"
22218 "2: \n"
22219 ".section .fixup, \"ax\"\n"
22220 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22221 + "3: \n"
22222 +
22223 +#ifdef CONFIG_PAX_KERNEXEC
22224 + " movl %%cr0, %0\n"
22225 + " movl %0, %%eax\n"
22226 + " andl $0xFFFEFFFF, %%eax\n"
22227 + " movl %%eax, %%cr0\n"
22228 +#endif
22229 +
22230 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22231 +
22232 +#ifdef CONFIG_PAX_KERNEXEC
22233 + " movl %0, %%cr0\n"
22234 +#endif
22235 +
22236 " jmp 2b\n"
22237 ".previous\n"
22238 _ASM_EXTABLE(1b, 3b)
22239 - : : "r" (from));
22240 + : "=&r" (cr0) : "r" (from) : "ax");
22241
22242 for ( ; i > 5; i--) {
22243 __asm__ __volatile__ (
22244 - "1: prefetch 320(%0)\n"
22245 - "2: movq (%0), %%mm0\n"
22246 - " movq 8(%0), %%mm1\n"
22247 - " movq 16(%0), %%mm2\n"
22248 - " movq 24(%0), %%mm3\n"
22249 - " movq %%mm0, (%1)\n"
22250 - " movq %%mm1, 8(%1)\n"
22251 - " movq %%mm2, 16(%1)\n"
22252 - " movq %%mm3, 24(%1)\n"
22253 - " movq 32(%0), %%mm0\n"
22254 - " movq 40(%0), %%mm1\n"
22255 - " movq 48(%0), %%mm2\n"
22256 - " movq 56(%0), %%mm3\n"
22257 - " movq %%mm0, 32(%1)\n"
22258 - " movq %%mm1, 40(%1)\n"
22259 - " movq %%mm2, 48(%1)\n"
22260 - " movq %%mm3, 56(%1)\n"
22261 + "1: prefetch 320(%1)\n"
22262 + "2: movq (%1), %%mm0\n"
22263 + " movq 8(%1), %%mm1\n"
22264 + " movq 16(%1), %%mm2\n"
22265 + " movq 24(%1), %%mm3\n"
22266 + " movq %%mm0, (%2)\n"
22267 + " movq %%mm1, 8(%2)\n"
22268 + " movq %%mm2, 16(%2)\n"
22269 + " movq %%mm3, 24(%2)\n"
22270 + " movq 32(%1), %%mm0\n"
22271 + " movq 40(%1), %%mm1\n"
22272 + " movq 48(%1), %%mm2\n"
22273 + " movq 56(%1), %%mm3\n"
22274 + " movq %%mm0, 32(%2)\n"
22275 + " movq %%mm1, 40(%2)\n"
22276 + " movq %%mm2, 48(%2)\n"
22277 + " movq %%mm3, 56(%2)\n"
22278 ".section .fixup, \"ax\"\n"
22279 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22280 + "3:\n"
22281 +
22282 +#ifdef CONFIG_PAX_KERNEXEC
22283 + " movl %%cr0, %0\n"
22284 + " movl %0, %%eax\n"
22285 + " andl $0xFFFEFFFF, %%eax\n"
22286 + " movl %%eax, %%cr0\n"
22287 +#endif
22288 +
22289 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22290 +
22291 +#ifdef CONFIG_PAX_KERNEXEC
22292 + " movl %0, %%cr0\n"
22293 +#endif
22294 +
22295 " jmp 2b\n"
22296 ".previous\n"
22297 _ASM_EXTABLE(1b, 3b)
22298 - : : "r" (from), "r" (to) : "memory");
22299 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22300
22301 from += 64;
22302 to += 64;
22303 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22304 static void fast_copy_page(void *to, void *from)
22305 {
22306 int i;
22307 + unsigned long cr0;
22308
22309 kernel_fpu_begin();
22310
22311 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22312 * but that is for later. -AV
22313 */
22314 __asm__ __volatile__(
22315 - "1: prefetch (%0)\n"
22316 - " prefetch 64(%0)\n"
22317 - " prefetch 128(%0)\n"
22318 - " prefetch 192(%0)\n"
22319 - " prefetch 256(%0)\n"
22320 + "1: prefetch (%1)\n"
22321 + " prefetch 64(%1)\n"
22322 + " prefetch 128(%1)\n"
22323 + " prefetch 192(%1)\n"
22324 + " prefetch 256(%1)\n"
22325 "2: \n"
22326 ".section .fixup, \"ax\"\n"
22327 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22328 + "3: \n"
22329 +
22330 +#ifdef CONFIG_PAX_KERNEXEC
22331 + " movl %%cr0, %0\n"
22332 + " movl %0, %%eax\n"
22333 + " andl $0xFFFEFFFF, %%eax\n"
22334 + " movl %%eax, %%cr0\n"
22335 +#endif
22336 +
22337 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22338 +
22339 +#ifdef CONFIG_PAX_KERNEXEC
22340 + " movl %0, %%cr0\n"
22341 +#endif
22342 +
22343 " jmp 2b\n"
22344 ".previous\n"
22345 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22346 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22347
22348 for (i = 0; i < (4096-320)/64; i++) {
22349 __asm__ __volatile__ (
22350 - "1: prefetch 320(%0)\n"
22351 - "2: movq (%0), %%mm0\n"
22352 - " movntq %%mm0, (%1)\n"
22353 - " movq 8(%0), %%mm1\n"
22354 - " movntq %%mm1, 8(%1)\n"
22355 - " movq 16(%0), %%mm2\n"
22356 - " movntq %%mm2, 16(%1)\n"
22357 - " movq 24(%0), %%mm3\n"
22358 - " movntq %%mm3, 24(%1)\n"
22359 - " movq 32(%0), %%mm4\n"
22360 - " movntq %%mm4, 32(%1)\n"
22361 - " movq 40(%0), %%mm5\n"
22362 - " movntq %%mm5, 40(%1)\n"
22363 - " movq 48(%0), %%mm6\n"
22364 - " movntq %%mm6, 48(%1)\n"
22365 - " movq 56(%0), %%mm7\n"
22366 - " movntq %%mm7, 56(%1)\n"
22367 + "1: prefetch 320(%1)\n"
22368 + "2: movq (%1), %%mm0\n"
22369 + " movntq %%mm0, (%2)\n"
22370 + " movq 8(%1), %%mm1\n"
22371 + " movntq %%mm1, 8(%2)\n"
22372 + " movq 16(%1), %%mm2\n"
22373 + " movntq %%mm2, 16(%2)\n"
22374 + " movq 24(%1), %%mm3\n"
22375 + " movntq %%mm3, 24(%2)\n"
22376 + " movq 32(%1), %%mm4\n"
22377 + " movntq %%mm4, 32(%2)\n"
22378 + " movq 40(%1), %%mm5\n"
22379 + " movntq %%mm5, 40(%2)\n"
22380 + " movq 48(%1), %%mm6\n"
22381 + " movntq %%mm6, 48(%2)\n"
22382 + " movq 56(%1), %%mm7\n"
22383 + " movntq %%mm7, 56(%2)\n"
22384 ".section .fixup, \"ax\"\n"
22385 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22386 + "3:\n"
22387 +
22388 +#ifdef CONFIG_PAX_KERNEXEC
22389 + " movl %%cr0, %0\n"
22390 + " movl %0, %%eax\n"
22391 + " andl $0xFFFEFFFF, %%eax\n"
22392 + " movl %%eax, %%cr0\n"
22393 +#endif
22394 +
22395 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22396 +
22397 +#ifdef CONFIG_PAX_KERNEXEC
22398 + " movl %0, %%cr0\n"
22399 +#endif
22400 +
22401 " jmp 2b\n"
22402 ".previous\n"
22403 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22404 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22405
22406 from += 64;
22407 to += 64;
22408 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22409 static void fast_copy_page(void *to, void *from)
22410 {
22411 int i;
22412 + unsigned long cr0;
22413
22414 kernel_fpu_begin();
22415
22416 __asm__ __volatile__ (
22417 - "1: prefetch (%0)\n"
22418 - " prefetch 64(%0)\n"
22419 - " prefetch 128(%0)\n"
22420 - " prefetch 192(%0)\n"
22421 - " prefetch 256(%0)\n"
22422 + "1: prefetch (%1)\n"
22423 + " prefetch 64(%1)\n"
22424 + " prefetch 128(%1)\n"
22425 + " prefetch 192(%1)\n"
22426 + " prefetch 256(%1)\n"
22427 "2: \n"
22428 ".section .fixup, \"ax\"\n"
22429 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22430 + "3: \n"
22431 +
22432 +#ifdef CONFIG_PAX_KERNEXEC
22433 + " movl %%cr0, %0\n"
22434 + " movl %0, %%eax\n"
22435 + " andl $0xFFFEFFFF, %%eax\n"
22436 + " movl %%eax, %%cr0\n"
22437 +#endif
22438 +
22439 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22440 +
22441 +#ifdef CONFIG_PAX_KERNEXEC
22442 + " movl %0, %%cr0\n"
22443 +#endif
22444 +
22445 " jmp 2b\n"
22446 ".previous\n"
22447 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22448 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22449
22450 for (i = 0; i < 4096/64; i++) {
22451 __asm__ __volatile__ (
22452 - "1: prefetch 320(%0)\n"
22453 - "2: movq (%0), %%mm0\n"
22454 - " movq 8(%0), %%mm1\n"
22455 - " movq 16(%0), %%mm2\n"
22456 - " movq 24(%0), %%mm3\n"
22457 - " movq %%mm0, (%1)\n"
22458 - " movq %%mm1, 8(%1)\n"
22459 - " movq %%mm2, 16(%1)\n"
22460 - " movq %%mm3, 24(%1)\n"
22461 - " movq 32(%0), %%mm0\n"
22462 - " movq 40(%0), %%mm1\n"
22463 - " movq 48(%0), %%mm2\n"
22464 - " movq 56(%0), %%mm3\n"
22465 - " movq %%mm0, 32(%1)\n"
22466 - " movq %%mm1, 40(%1)\n"
22467 - " movq %%mm2, 48(%1)\n"
22468 - " movq %%mm3, 56(%1)\n"
22469 + "1: prefetch 320(%1)\n"
22470 + "2: movq (%1), %%mm0\n"
22471 + " movq 8(%1), %%mm1\n"
22472 + " movq 16(%1), %%mm2\n"
22473 + " movq 24(%1), %%mm3\n"
22474 + " movq %%mm0, (%2)\n"
22475 + " movq %%mm1, 8(%2)\n"
22476 + " movq %%mm2, 16(%2)\n"
22477 + " movq %%mm3, 24(%2)\n"
22478 + " movq 32(%1), %%mm0\n"
22479 + " movq 40(%1), %%mm1\n"
22480 + " movq 48(%1), %%mm2\n"
22481 + " movq 56(%1), %%mm3\n"
22482 + " movq %%mm0, 32(%2)\n"
22483 + " movq %%mm1, 40(%2)\n"
22484 + " movq %%mm2, 48(%2)\n"
22485 + " movq %%mm3, 56(%2)\n"
22486 ".section .fixup, \"ax\"\n"
22487 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22488 + "3:\n"
22489 +
22490 +#ifdef CONFIG_PAX_KERNEXEC
22491 + " movl %%cr0, %0\n"
22492 + " movl %0, %%eax\n"
22493 + " andl $0xFFFEFFFF, %%eax\n"
22494 + " movl %%eax, %%cr0\n"
22495 +#endif
22496 +
22497 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22498 +
22499 +#ifdef CONFIG_PAX_KERNEXEC
22500 + " movl %0, %%cr0\n"
22501 +#endif
22502 +
22503 " jmp 2b\n"
22504 ".previous\n"
22505 _ASM_EXTABLE(1b, 3b)
22506 - : : "r" (from), "r" (to) : "memory");
22507 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22508
22509 from += 64;
22510 to += 64;
22511 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22512 index 69fa106..adda88b 100644
22513 --- a/arch/x86/lib/msr-reg.S
22514 +++ b/arch/x86/lib/msr-reg.S
22515 @@ -3,6 +3,7 @@
22516 #include <asm/dwarf2.h>
22517 #include <asm/asm.h>
22518 #include <asm/msr.h>
22519 +#include <asm/alternative-asm.h>
22520
22521 #ifdef CONFIG_X86_64
22522 /*
22523 @@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
22524 CFI_STARTPROC
22525 pushq_cfi %rbx
22526 pushq_cfi %rbp
22527 - movq %rdi, %r10 /* Save pointer */
22528 + movq %rdi, %r9 /* Save pointer */
22529 xorl %r11d, %r11d /* Return value */
22530 movl (%rdi), %eax
22531 movl 4(%rdi), %ecx
22532 @@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
22533 movl 28(%rdi), %edi
22534 CFI_REMEMBER_STATE
22535 1: \op
22536 -2: movl %eax, (%r10)
22537 +2: movl %eax, (%r9)
22538 movl %r11d, %eax /* Return value */
22539 - movl %ecx, 4(%r10)
22540 - movl %edx, 8(%r10)
22541 - movl %ebx, 12(%r10)
22542 - movl %ebp, 20(%r10)
22543 - movl %esi, 24(%r10)
22544 - movl %edi, 28(%r10)
22545 + movl %ecx, 4(%r9)
22546 + movl %edx, 8(%r9)
22547 + movl %ebx, 12(%r9)
22548 + movl %ebp, 20(%r9)
22549 + movl %esi, 24(%r9)
22550 + movl %edi, 28(%r9)
22551 popq_cfi %rbp
22552 popq_cfi %rbx
22553 + pax_force_retaddr
22554 ret
22555 3:
22556 CFI_RESTORE_STATE
22557 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22558 index 36b0d15..d381858 100644
22559 --- a/arch/x86/lib/putuser.S
22560 +++ b/arch/x86/lib/putuser.S
22561 @@ -15,7 +15,9 @@
22562 #include <asm/thread_info.h>
22563 #include <asm/errno.h>
22564 #include <asm/asm.h>
22565 -
22566 +#include <asm/segment.h>
22567 +#include <asm/pgtable.h>
22568 +#include <asm/alternative-asm.h>
22569
22570 /*
22571 * __put_user_X
22572 @@ -29,52 +31,119 @@
22573 * as they get called from within inline assembly.
22574 */
22575
22576 -#define ENTER CFI_STARTPROC ; \
22577 - GET_THREAD_INFO(%_ASM_BX)
22578 -#define EXIT ret ; \
22579 +#define ENTER CFI_STARTPROC
22580 +#define EXIT pax_force_retaddr; ret ; \
22581 CFI_ENDPROC
22582
22583 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22584 +#define _DEST %_ASM_CX,%_ASM_BX
22585 +#else
22586 +#define _DEST %_ASM_CX
22587 +#endif
22588 +
22589 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22590 +#define __copyuser_seg gs;
22591 +#else
22592 +#define __copyuser_seg
22593 +#endif
22594 +
22595 .text
22596 ENTRY(__put_user_1)
22597 ENTER
22598 +
22599 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22600 + GET_THREAD_INFO(%_ASM_BX)
22601 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22602 jae bad_put_user
22603 -1: movb %al,(%_ASM_CX)
22604 +
22605 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22606 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22607 + cmp %_ASM_BX,%_ASM_CX
22608 + jb 1234f
22609 + xor %ebx,%ebx
22610 +1234:
22611 +#endif
22612 +
22613 +#endif
22614 +
22615 +1: __copyuser_seg movb %al,(_DEST)
22616 xor %eax,%eax
22617 EXIT
22618 ENDPROC(__put_user_1)
22619
22620 ENTRY(__put_user_2)
22621 ENTER
22622 +
22623 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22624 + GET_THREAD_INFO(%_ASM_BX)
22625 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22626 sub $1,%_ASM_BX
22627 cmp %_ASM_BX,%_ASM_CX
22628 jae bad_put_user
22629 -2: movw %ax,(%_ASM_CX)
22630 +
22631 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22632 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22633 + cmp %_ASM_BX,%_ASM_CX
22634 + jb 1234f
22635 + xor %ebx,%ebx
22636 +1234:
22637 +#endif
22638 +
22639 +#endif
22640 +
22641 +2: __copyuser_seg movw %ax,(_DEST)
22642 xor %eax,%eax
22643 EXIT
22644 ENDPROC(__put_user_2)
22645
22646 ENTRY(__put_user_4)
22647 ENTER
22648 +
22649 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22650 + GET_THREAD_INFO(%_ASM_BX)
22651 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22652 sub $3,%_ASM_BX
22653 cmp %_ASM_BX,%_ASM_CX
22654 jae bad_put_user
22655 -3: movl %eax,(%_ASM_CX)
22656 +
22657 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22658 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22659 + cmp %_ASM_BX,%_ASM_CX
22660 + jb 1234f
22661 + xor %ebx,%ebx
22662 +1234:
22663 +#endif
22664 +
22665 +#endif
22666 +
22667 +3: __copyuser_seg movl %eax,(_DEST)
22668 xor %eax,%eax
22669 EXIT
22670 ENDPROC(__put_user_4)
22671
22672 ENTRY(__put_user_8)
22673 ENTER
22674 +
22675 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22676 + GET_THREAD_INFO(%_ASM_BX)
22677 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22678 sub $7,%_ASM_BX
22679 cmp %_ASM_BX,%_ASM_CX
22680 jae bad_put_user
22681 -4: mov %_ASM_AX,(%_ASM_CX)
22682 +
22683 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22684 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22685 + cmp %_ASM_BX,%_ASM_CX
22686 + jb 1234f
22687 + xor %ebx,%ebx
22688 +1234:
22689 +#endif
22690 +
22691 +#endif
22692 +
22693 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
22694 #ifdef CONFIG_X86_32
22695 -5: movl %edx,4(%_ASM_CX)
22696 +5: __copyuser_seg movl %edx,4(_DEST)
22697 #endif
22698 xor %eax,%eax
22699 EXIT
22700 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22701 index 1cad221..de671ee 100644
22702 --- a/arch/x86/lib/rwlock.S
22703 +++ b/arch/x86/lib/rwlock.S
22704 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22705 FRAME
22706 0: LOCK_PREFIX
22707 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22708 +
22709 +#ifdef CONFIG_PAX_REFCOUNT
22710 + jno 1234f
22711 + LOCK_PREFIX
22712 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22713 + int $4
22714 +1234:
22715 + _ASM_EXTABLE(1234b, 1234b)
22716 +#endif
22717 +
22718 1: rep; nop
22719 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22720 jne 1b
22721 LOCK_PREFIX
22722 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22723 +
22724 +#ifdef CONFIG_PAX_REFCOUNT
22725 + jno 1234f
22726 + LOCK_PREFIX
22727 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22728 + int $4
22729 +1234:
22730 + _ASM_EXTABLE(1234b, 1234b)
22731 +#endif
22732 +
22733 jnz 0b
22734 ENDFRAME
22735 + pax_force_retaddr
22736 ret
22737 CFI_ENDPROC
22738 END(__write_lock_failed)
22739 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22740 FRAME
22741 0: LOCK_PREFIX
22742 READ_LOCK_SIZE(inc) (%__lock_ptr)
22743 +
22744 +#ifdef CONFIG_PAX_REFCOUNT
22745 + jno 1234f
22746 + LOCK_PREFIX
22747 + READ_LOCK_SIZE(dec) (%__lock_ptr)
22748 + int $4
22749 +1234:
22750 + _ASM_EXTABLE(1234b, 1234b)
22751 +#endif
22752 +
22753 1: rep; nop
22754 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22755 js 1b
22756 LOCK_PREFIX
22757 READ_LOCK_SIZE(dec) (%__lock_ptr)
22758 +
22759 +#ifdef CONFIG_PAX_REFCOUNT
22760 + jno 1234f
22761 + LOCK_PREFIX
22762 + READ_LOCK_SIZE(inc) (%__lock_ptr)
22763 + int $4
22764 +1234:
22765 + _ASM_EXTABLE(1234b, 1234b)
22766 +#endif
22767 +
22768 js 0b
22769 ENDFRAME
22770 + pax_force_retaddr
22771 ret
22772 CFI_ENDPROC
22773 END(__read_lock_failed)
22774 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22775 index 5dff5f0..cadebf4 100644
22776 --- a/arch/x86/lib/rwsem.S
22777 +++ b/arch/x86/lib/rwsem.S
22778 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22779 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22780 CFI_RESTORE __ASM_REG(dx)
22781 restore_common_regs
22782 + pax_force_retaddr
22783 ret
22784 CFI_ENDPROC
22785 ENDPROC(call_rwsem_down_read_failed)
22786 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22787 movq %rax,%rdi
22788 call rwsem_down_write_failed
22789 restore_common_regs
22790 + pax_force_retaddr
22791 ret
22792 CFI_ENDPROC
22793 ENDPROC(call_rwsem_down_write_failed)
22794 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22795 movq %rax,%rdi
22796 call rwsem_wake
22797 restore_common_regs
22798 -1: ret
22799 +1: pax_force_retaddr
22800 + ret
22801 CFI_ENDPROC
22802 ENDPROC(call_rwsem_wake)
22803
22804 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22805 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22806 CFI_RESTORE __ASM_REG(dx)
22807 restore_common_regs
22808 + pax_force_retaddr
22809 ret
22810 CFI_ENDPROC
22811 ENDPROC(call_rwsem_downgrade_wake)
22812 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22813 index a63efd6..ccecad8 100644
22814 --- a/arch/x86/lib/thunk_64.S
22815 +++ b/arch/x86/lib/thunk_64.S
22816 @@ -8,6 +8,7 @@
22817 #include <linux/linkage.h>
22818 #include <asm/dwarf2.h>
22819 #include <asm/calling.h>
22820 +#include <asm/alternative-asm.h>
22821
22822 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22823 .macro THUNK name, func, put_ret_addr_in_rdi=0
22824 @@ -41,5 +42,6 @@
22825 SAVE_ARGS
22826 restore:
22827 RESTORE_ARGS
22828 + pax_force_retaddr
22829 ret
22830 CFI_ENDPROC
22831 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22832 index ef2a6a5..3b28862 100644
22833 --- a/arch/x86/lib/usercopy_32.c
22834 +++ b/arch/x86/lib/usercopy_32.c
22835 @@ -41,10 +41,12 @@ do { \
22836 int __d0; \
22837 might_fault(); \
22838 __asm__ __volatile__( \
22839 + __COPYUSER_SET_ES \
22840 "0: rep; stosl\n" \
22841 " movl %2,%0\n" \
22842 "1: rep; stosb\n" \
22843 "2:\n" \
22844 + __COPYUSER_RESTORE_ES \
22845 ".section .fixup,\"ax\"\n" \
22846 "3: lea 0(%2,%0,4),%0\n" \
22847 " jmp 2b\n" \
22848 @@ -113,6 +115,7 @@ long strnlen_user(const char __user *s, long n)
22849 might_fault();
22850
22851 __asm__ __volatile__(
22852 + __COPYUSER_SET_ES
22853 " testl %0, %0\n"
22854 " jz 3f\n"
22855 " andl %0,%%ecx\n"
22856 @@ -121,6 +124,7 @@ long strnlen_user(const char __user *s, long n)
22857 " subl %%ecx,%0\n"
22858 " addl %0,%%eax\n"
22859 "1:\n"
22860 + __COPYUSER_RESTORE_ES
22861 ".section .fixup,\"ax\"\n"
22862 "2: xorl %%eax,%%eax\n"
22863 " jmp 1b\n"
22864 @@ -140,7 +144,7 @@ EXPORT_SYMBOL(strnlen_user);
22865
22866 #ifdef CONFIG_X86_INTEL_USERCOPY
22867 static unsigned long
22868 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
22869 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22870 {
22871 int d0, d1;
22872 __asm__ __volatile__(
22873 @@ -152,36 +156,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22874 " .align 2,0x90\n"
22875 "3: movl 0(%4), %%eax\n"
22876 "4: movl 4(%4), %%edx\n"
22877 - "5: movl %%eax, 0(%3)\n"
22878 - "6: movl %%edx, 4(%3)\n"
22879 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22880 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22881 "7: movl 8(%4), %%eax\n"
22882 "8: movl 12(%4),%%edx\n"
22883 - "9: movl %%eax, 8(%3)\n"
22884 - "10: movl %%edx, 12(%3)\n"
22885 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22886 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22887 "11: movl 16(%4), %%eax\n"
22888 "12: movl 20(%4), %%edx\n"
22889 - "13: movl %%eax, 16(%3)\n"
22890 - "14: movl %%edx, 20(%3)\n"
22891 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22892 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22893 "15: movl 24(%4), %%eax\n"
22894 "16: movl 28(%4), %%edx\n"
22895 - "17: movl %%eax, 24(%3)\n"
22896 - "18: movl %%edx, 28(%3)\n"
22897 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22898 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22899 "19: movl 32(%4), %%eax\n"
22900 "20: movl 36(%4), %%edx\n"
22901 - "21: movl %%eax, 32(%3)\n"
22902 - "22: movl %%edx, 36(%3)\n"
22903 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22904 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22905 "23: movl 40(%4), %%eax\n"
22906 "24: movl 44(%4), %%edx\n"
22907 - "25: movl %%eax, 40(%3)\n"
22908 - "26: movl %%edx, 44(%3)\n"
22909 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22910 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22911 "27: movl 48(%4), %%eax\n"
22912 "28: movl 52(%4), %%edx\n"
22913 - "29: movl %%eax, 48(%3)\n"
22914 - "30: movl %%edx, 52(%3)\n"
22915 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22916 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22917 "31: movl 56(%4), %%eax\n"
22918 "32: movl 60(%4), %%edx\n"
22919 - "33: movl %%eax, 56(%3)\n"
22920 - "34: movl %%edx, 60(%3)\n"
22921 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22922 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22923 " addl $-64, %0\n"
22924 " addl $64, %4\n"
22925 " addl $64, %3\n"
22926 @@ -191,10 +195,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22927 " shrl $2, %0\n"
22928 " andl $3, %%eax\n"
22929 " cld\n"
22930 + __COPYUSER_SET_ES
22931 "99: rep; movsl\n"
22932 "36: movl %%eax, %0\n"
22933 "37: rep; movsb\n"
22934 "100:\n"
22935 + __COPYUSER_RESTORE_ES
22936 ".section .fixup,\"ax\"\n"
22937 "101: lea 0(%%eax,%0,4),%0\n"
22938 " jmp 100b\n"
22939 @@ -247,46 +253,155 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22940 }
22941
22942 static unsigned long
22943 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22944 +{
22945 + int d0, d1;
22946 + __asm__ __volatile__(
22947 + " .align 2,0x90\n"
22948 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22949 + " cmpl $67, %0\n"
22950 + " jbe 3f\n"
22951 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
22952 + " .align 2,0x90\n"
22953 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
22954 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
22955 + "5: movl %%eax, 0(%3)\n"
22956 + "6: movl %%edx, 4(%3)\n"
22957 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
22958 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
22959 + "9: movl %%eax, 8(%3)\n"
22960 + "10: movl %%edx, 12(%3)\n"
22961 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
22962 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
22963 + "13: movl %%eax, 16(%3)\n"
22964 + "14: movl %%edx, 20(%3)\n"
22965 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
22966 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
22967 + "17: movl %%eax, 24(%3)\n"
22968 + "18: movl %%edx, 28(%3)\n"
22969 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
22970 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
22971 + "21: movl %%eax, 32(%3)\n"
22972 + "22: movl %%edx, 36(%3)\n"
22973 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
22974 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
22975 + "25: movl %%eax, 40(%3)\n"
22976 + "26: movl %%edx, 44(%3)\n"
22977 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
22978 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
22979 + "29: movl %%eax, 48(%3)\n"
22980 + "30: movl %%edx, 52(%3)\n"
22981 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
22982 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
22983 + "33: movl %%eax, 56(%3)\n"
22984 + "34: movl %%edx, 60(%3)\n"
22985 + " addl $-64, %0\n"
22986 + " addl $64, %4\n"
22987 + " addl $64, %3\n"
22988 + " cmpl $63, %0\n"
22989 + " ja 1b\n"
22990 + "35: movl %0, %%eax\n"
22991 + " shrl $2, %0\n"
22992 + " andl $3, %%eax\n"
22993 + " cld\n"
22994 + "99: rep; "__copyuser_seg" movsl\n"
22995 + "36: movl %%eax, %0\n"
22996 + "37: rep; "__copyuser_seg" movsb\n"
22997 + "100:\n"
22998 + ".section .fixup,\"ax\"\n"
22999 + "101: lea 0(%%eax,%0,4),%0\n"
23000 + " jmp 100b\n"
23001 + ".previous\n"
23002 + ".section __ex_table,\"a\"\n"
23003 + " .align 4\n"
23004 + " .long 1b,100b\n"
23005 + " .long 2b,100b\n"
23006 + " .long 3b,100b\n"
23007 + " .long 4b,100b\n"
23008 + " .long 5b,100b\n"
23009 + " .long 6b,100b\n"
23010 + " .long 7b,100b\n"
23011 + " .long 8b,100b\n"
23012 + " .long 9b,100b\n"
23013 + " .long 10b,100b\n"
23014 + " .long 11b,100b\n"
23015 + " .long 12b,100b\n"
23016 + " .long 13b,100b\n"
23017 + " .long 14b,100b\n"
23018 + " .long 15b,100b\n"
23019 + " .long 16b,100b\n"
23020 + " .long 17b,100b\n"
23021 + " .long 18b,100b\n"
23022 + " .long 19b,100b\n"
23023 + " .long 20b,100b\n"
23024 + " .long 21b,100b\n"
23025 + " .long 22b,100b\n"
23026 + " .long 23b,100b\n"
23027 + " .long 24b,100b\n"
23028 + " .long 25b,100b\n"
23029 + " .long 26b,100b\n"
23030 + " .long 27b,100b\n"
23031 + " .long 28b,100b\n"
23032 + " .long 29b,100b\n"
23033 + " .long 30b,100b\n"
23034 + " .long 31b,100b\n"
23035 + " .long 32b,100b\n"
23036 + " .long 33b,100b\n"
23037 + " .long 34b,100b\n"
23038 + " .long 35b,100b\n"
23039 + " .long 36b,100b\n"
23040 + " .long 37b,100b\n"
23041 + " .long 99b,101b\n"
23042 + ".previous"
23043 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
23044 + : "1"(to), "2"(from), "0"(size)
23045 + : "eax", "edx", "memory");
23046 + return size;
23047 +}
23048 +
23049 +static unsigned long
23050 +__copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size) __size_overflow(3);
23051 +static unsigned long
23052 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23053 {
23054 int d0, d1;
23055 __asm__ __volatile__(
23056 " .align 2,0x90\n"
23057 - "0: movl 32(%4), %%eax\n"
23058 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23059 " cmpl $67, %0\n"
23060 " jbe 2f\n"
23061 - "1: movl 64(%4), %%eax\n"
23062 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23063 " .align 2,0x90\n"
23064 - "2: movl 0(%4), %%eax\n"
23065 - "21: movl 4(%4), %%edx\n"
23066 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23067 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23068 " movl %%eax, 0(%3)\n"
23069 " movl %%edx, 4(%3)\n"
23070 - "3: movl 8(%4), %%eax\n"
23071 - "31: movl 12(%4),%%edx\n"
23072 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23073 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23074 " movl %%eax, 8(%3)\n"
23075 " movl %%edx, 12(%3)\n"
23076 - "4: movl 16(%4), %%eax\n"
23077 - "41: movl 20(%4), %%edx\n"
23078 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23079 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23080 " movl %%eax, 16(%3)\n"
23081 " movl %%edx, 20(%3)\n"
23082 - "10: movl 24(%4), %%eax\n"
23083 - "51: movl 28(%4), %%edx\n"
23084 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23085 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23086 " movl %%eax, 24(%3)\n"
23087 " movl %%edx, 28(%3)\n"
23088 - "11: movl 32(%4), %%eax\n"
23089 - "61: movl 36(%4), %%edx\n"
23090 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23091 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23092 " movl %%eax, 32(%3)\n"
23093 " movl %%edx, 36(%3)\n"
23094 - "12: movl 40(%4), %%eax\n"
23095 - "71: movl 44(%4), %%edx\n"
23096 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23097 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23098 " movl %%eax, 40(%3)\n"
23099 " movl %%edx, 44(%3)\n"
23100 - "13: movl 48(%4), %%eax\n"
23101 - "81: movl 52(%4), %%edx\n"
23102 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23103 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23104 " movl %%eax, 48(%3)\n"
23105 " movl %%edx, 52(%3)\n"
23106 - "14: movl 56(%4), %%eax\n"
23107 - "91: movl 60(%4), %%edx\n"
23108 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23109 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23110 " movl %%eax, 56(%3)\n"
23111 " movl %%edx, 60(%3)\n"
23112 " addl $-64, %0\n"
23113 @@ -298,9 +413,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23114 " shrl $2, %0\n"
23115 " andl $3, %%eax\n"
23116 " cld\n"
23117 - "6: rep; movsl\n"
23118 + "6: rep; "__copyuser_seg" movsl\n"
23119 " movl %%eax,%0\n"
23120 - "7: rep; movsb\n"
23121 + "7: rep; "__copyuser_seg" movsb\n"
23122 "8:\n"
23123 ".section .fixup,\"ax\"\n"
23124 "9: lea 0(%%eax,%0,4),%0\n"
23125 @@ -347,47 +462,49 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23126 */
23127
23128 static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23129 + const void __user *from, unsigned long size) __size_overflow(3);
23130 +static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23131 const void __user *from, unsigned long size)
23132 {
23133 int d0, d1;
23134
23135 __asm__ __volatile__(
23136 " .align 2,0x90\n"
23137 - "0: movl 32(%4), %%eax\n"
23138 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23139 " cmpl $67, %0\n"
23140 " jbe 2f\n"
23141 - "1: movl 64(%4), %%eax\n"
23142 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23143 " .align 2,0x90\n"
23144 - "2: movl 0(%4), %%eax\n"
23145 - "21: movl 4(%4), %%edx\n"
23146 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23147 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23148 " movnti %%eax, 0(%3)\n"
23149 " movnti %%edx, 4(%3)\n"
23150 - "3: movl 8(%4), %%eax\n"
23151 - "31: movl 12(%4),%%edx\n"
23152 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23153 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23154 " movnti %%eax, 8(%3)\n"
23155 " movnti %%edx, 12(%3)\n"
23156 - "4: movl 16(%4), %%eax\n"
23157 - "41: movl 20(%4), %%edx\n"
23158 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23159 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23160 " movnti %%eax, 16(%3)\n"
23161 " movnti %%edx, 20(%3)\n"
23162 - "10: movl 24(%4), %%eax\n"
23163 - "51: movl 28(%4), %%edx\n"
23164 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23165 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23166 " movnti %%eax, 24(%3)\n"
23167 " movnti %%edx, 28(%3)\n"
23168 - "11: movl 32(%4), %%eax\n"
23169 - "61: movl 36(%4), %%edx\n"
23170 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23171 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23172 " movnti %%eax, 32(%3)\n"
23173 " movnti %%edx, 36(%3)\n"
23174 - "12: movl 40(%4), %%eax\n"
23175 - "71: movl 44(%4), %%edx\n"
23176 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23177 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23178 " movnti %%eax, 40(%3)\n"
23179 " movnti %%edx, 44(%3)\n"
23180 - "13: movl 48(%4), %%eax\n"
23181 - "81: movl 52(%4), %%edx\n"
23182 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23183 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23184 " movnti %%eax, 48(%3)\n"
23185 " movnti %%edx, 52(%3)\n"
23186 - "14: movl 56(%4), %%eax\n"
23187 - "91: movl 60(%4), %%edx\n"
23188 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23189 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23190 " movnti %%eax, 56(%3)\n"
23191 " movnti %%edx, 60(%3)\n"
23192 " addl $-64, %0\n"
23193 @@ -400,9 +517,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23194 " shrl $2, %0\n"
23195 " andl $3, %%eax\n"
23196 " cld\n"
23197 - "6: rep; movsl\n"
23198 + "6: rep; "__copyuser_seg" movsl\n"
23199 " movl %%eax,%0\n"
23200 - "7: rep; movsb\n"
23201 + "7: rep; "__copyuser_seg" movsb\n"
23202 "8:\n"
23203 ".section .fixup,\"ax\"\n"
23204 "9: lea 0(%%eax,%0,4),%0\n"
23205 @@ -444,47 +561,49 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23206 }
23207
23208 static unsigned long __copy_user_intel_nocache(void *to,
23209 + const void __user *from, unsigned long size) __size_overflow(3);
23210 +static unsigned long __copy_user_intel_nocache(void *to,
23211 const void __user *from, unsigned long size)
23212 {
23213 int d0, d1;
23214
23215 __asm__ __volatile__(
23216 " .align 2,0x90\n"
23217 - "0: movl 32(%4), %%eax\n"
23218 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23219 " cmpl $67, %0\n"
23220 " jbe 2f\n"
23221 - "1: movl 64(%4), %%eax\n"
23222 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23223 " .align 2,0x90\n"
23224 - "2: movl 0(%4), %%eax\n"
23225 - "21: movl 4(%4), %%edx\n"
23226 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23227 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23228 " movnti %%eax, 0(%3)\n"
23229 " movnti %%edx, 4(%3)\n"
23230 - "3: movl 8(%4), %%eax\n"
23231 - "31: movl 12(%4),%%edx\n"
23232 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23233 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23234 " movnti %%eax, 8(%3)\n"
23235 " movnti %%edx, 12(%3)\n"
23236 - "4: movl 16(%4), %%eax\n"
23237 - "41: movl 20(%4), %%edx\n"
23238 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23239 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23240 " movnti %%eax, 16(%3)\n"
23241 " movnti %%edx, 20(%3)\n"
23242 - "10: movl 24(%4), %%eax\n"
23243 - "51: movl 28(%4), %%edx\n"
23244 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23245 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23246 " movnti %%eax, 24(%3)\n"
23247 " movnti %%edx, 28(%3)\n"
23248 - "11: movl 32(%4), %%eax\n"
23249 - "61: movl 36(%4), %%edx\n"
23250 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23251 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23252 " movnti %%eax, 32(%3)\n"
23253 " movnti %%edx, 36(%3)\n"
23254 - "12: movl 40(%4), %%eax\n"
23255 - "71: movl 44(%4), %%edx\n"
23256 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23257 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23258 " movnti %%eax, 40(%3)\n"
23259 " movnti %%edx, 44(%3)\n"
23260 - "13: movl 48(%4), %%eax\n"
23261 - "81: movl 52(%4), %%edx\n"
23262 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23263 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23264 " movnti %%eax, 48(%3)\n"
23265 " movnti %%edx, 52(%3)\n"
23266 - "14: movl 56(%4), %%eax\n"
23267 - "91: movl 60(%4), %%edx\n"
23268 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23269 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23270 " movnti %%eax, 56(%3)\n"
23271 " movnti %%edx, 60(%3)\n"
23272 " addl $-64, %0\n"
23273 @@ -497,9 +616,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23274 " shrl $2, %0\n"
23275 " andl $3, %%eax\n"
23276 " cld\n"
23277 - "6: rep; movsl\n"
23278 + "6: rep; "__copyuser_seg" movsl\n"
23279 " movl %%eax,%0\n"
23280 - "7: rep; movsb\n"
23281 + "7: rep; "__copyuser_seg" movsb\n"
23282 "8:\n"
23283 ".section .fixup,\"ax\"\n"
23284 "9: lea 0(%%eax,%0,4),%0\n"
23285 @@ -542,32 +661,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23286 */
23287 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23288 unsigned long size);
23289 -unsigned long __copy_user_intel(void __user *to, const void *from,
23290 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23291 + unsigned long size);
23292 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23293 unsigned long size);
23294 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23295 const void __user *from, unsigned long size);
23296 #endif /* CONFIG_X86_INTEL_USERCOPY */
23297
23298 /* Generic arbitrary sized copy. */
23299 -#define __copy_user(to, from, size) \
23300 +#define __copy_user(to, from, size, prefix, set, restore) \
23301 do { \
23302 int __d0, __d1, __d2; \
23303 __asm__ __volatile__( \
23304 + set \
23305 " cmp $7,%0\n" \
23306 " jbe 1f\n" \
23307 " movl %1,%0\n" \
23308 " negl %0\n" \
23309 " andl $7,%0\n" \
23310 " subl %0,%3\n" \
23311 - "4: rep; movsb\n" \
23312 + "4: rep; "prefix"movsb\n" \
23313 " movl %3,%0\n" \
23314 " shrl $2,%0\n" \
23315 " andl $3,%3\n" \
23316 " .align 2,0x90\n" \
23317 - "0: rep; movsl\n" \
23318 + "0: rep; "prefix"movsl\n" \
23319 " movl %3,%0\n" \
23320 - "1: rep; movsb\n" \
23321 + "1: rep; "prefix"movsb\n" \
23322 "2:\n" \
23323 + restore \
23324 ".section .fixup,\"ax\"\n" \
23325 "5: addl %3,%0\n" \
23326 " jmp 2b\n" \
23327 @@ -595,14 +718,14 @@ do { \
23328 " negl %0\n" \
23329 " andl $7,%0\n" \
23330 " subl %0,%3\n" \
23331 - "4: rep; movsb\n" \
23332 + "4: rep; "__copyuser_seg"movsb\n" \
23333 " movl %3,%0\n" \
23334 " shrl $2,%0\n" \
23335 " andl $3,%3\n" \
23336 " .align 2,0x90\n" \
23337 - "0: rep; movsl\n" \
23338 + "0: rep; "__copyuser_seg"movsl\n" \
23339 " movl %3,%0\n" \
23340 - "1: rep; movsb\n" \
23341 + "1: rep; "__copyuser_seg"movsb\n" \
23342 "2:\n" \
23343 ".section .fixup,\"ax\"\n" \
23344 "5: addl %3,%0\n" \
23345 @@ -688,9 +811,9 @@ survive:
23346 }
23347 #endif
23348 if (movsl_is_ok(to, from, n))
23349 - __copy_user(to, from, n);
23350 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23351 else
23352 - n = __copy_user_intel(to, from, n);
23353 + n = __generic_copy_to_user_intel(to, from, n);
23354 return n;
23355 }
23356 EXPORT_SYMBOL(__copy_to_user_ll);
23357 @@ -710,10 +833,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23358 unsigned long n)
23359 {
23360 if (movsl_is_ok(to, from, n))
23361 - __copy_user(to, from, n);
23362 + __copy_user(to, from, n, __copyuser_seg, "", "");
23363 else
23364 - n = __copy_user_intel((void __user *)to,
23365 - (const void *)from, n);
23366 + n = __generic_copy_from_user_intel(to, from, n);
23367 return n;
23368 }
23369 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23370 @@ -740,65 +862,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23371 if (n > 64 && cpu_has_xmm2)
23372 n = __copy_user_intel_nocache(to, from, n);
23373 else
23374 - __copy_user(to, from, n);
23375 + __copy_user(to, from, n, __copyuser_seg, "", "");
23376 #else
23377 - __copy_user(to, from, n);
23378 + __copy_user(to, from, n, __copyuser_seg, "", "");
23379 #endif
23380 return n;
23381 }
23382 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23383
23384 -/**
23385 - * copy_to_user: - Copy a block of data into user space.
23386 - * @to: Destination address, in user space.
23387 - * @from: Source address, in kernel space.
23388 - * @n: Number of bytes to copy.
23389 - *
23390 - * Context: User context only. This function may sleep.
23391 - *
23392 - * Copy data from kernel space to user space.
23393 - *
23394 - * Returns number of bytes that could not be copied.
23395 - * On success, this will be zero.
23396 - */
23397 -unsigned long
23398 -copy_to_user(void __user *to, const void *from, unsigned long n)
23399 -{
23400 - if (access_ok(VERIFY_WRITE, to, n))
23401 - n = __copy_to_user(to, from, n);
23402 - return n;
23403 -}
23404 -EXPORT_SYMBOL(copy_to_user);
23405 -
23406 -/**
23407 - * copy_from_user: - Copy a block of data from user space.
23408 - * @to: Destination address, in kernel space.
23409 - * @from: Source address, in user space.
23410 - * @n: Number of bytes to copy.
23411 - *
23412 - * Context: User context only. This function may sleep.
23413 - *
23414 - * Copy data from user space to kernel space.
23415 - *
23416 - * Returns number of bytes that could not be copied.
23417 - * On success, this will be zero.
23418 - *
23419 - * If some data could not be copied, this function will pad the copied
23420 - * data to the requested size using zero bytes.
23421 - */
23422 -unsigned long
23423 -_copy_from_user(void *to, const void __user *from, unsigned long n)
23424 -{
23425 - if (access_ok(VERIFY_READ, from, n))
23426 - n = __copy_from_user(to, from, n);
23427 - else
23428 - memset(to, 0, n);
23429 - return n;
23430 -}
23431 -EXPORT_SYMBOL(_copy_from_user);
23432 -
23433 void copy_from_user_overflow(void)
23434 {
23435 WARN(1, "Buffer overflow detected!\n");
23436 }
23437 EXPORT_SYMBOL(copy_from_user_overflow);
23438 +
23439 +void copy_to_user_overflow(void)
23440 +{
23441 + WARN(1, "Buffer overflow detected!\n");
23442 +}
23443 +EXPORT_SYMBOL(copy_to_user_overflow);
23444 +
23445 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23446 +void __set_fs(mm_segment_t x)
23447 +{
23448 + switch (x.seg) {
23449 + case 0:
23450 + loadsegment(gs, 0);
23451 + break;
23452 + case TASK_SIZE_MAX:
23453 + loadsegment(gs, __USER_DS);
23454 + break;
23455 + case -1UL:
23456 + loadsegment(gs, __KERNEL_DS);
23457 + break;
23458 + default:
23459 + BUG();
23460 + }
23461 + return;
23462 +}
23463 +EXPORT_SYMBOL(__set_fs);
23464 +
23465 +void set_fs(mm_segment_t x)
23466 +{
23467 + current_thread_info()->addr_limit = x;
23468 + __set_fs(x);
23469 +}
23470 +EXPORT_SYMBOL(set_fs);
23471 +#endif
23472 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23473 index 0d0326f..6a6155b 100644
23474 --- a/arch/x86/lib/usercopy_64.c
23475 +++ b/arch/x86/lib/usercopy_64.c
23476 @@ -16,6 +16,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23477 {
23478 long __d0;
23479 might_fault();
23480 +
23481 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23482 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23483 + addr += PAX_USER_SHADOW_BASE;
23484 +#endif
23485 +
23486 /* no memory constraint because it doesn't change any memory gcc knows
23487 about */
23488 asm volatile(
23489 @@ -100,12 +106,20 @@ long strlen_user(const char __user *s)
23490 }
23491 EXPORT_SYMBOL(strlen_user);
23492
23493 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23494 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23495 {
23496 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23497 - return copy_user_generic((__force void *)to, (__force void *)from, len);
23498 - }
23499 - return len;
23500 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23501 +
23502 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23503 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23504 + to += PAX_USER_SHADOW_BASE;
23505 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23506 + from += PAX_USER_SHADOW_BASE;
23507 +#endif
23508 +
23509 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23510 + }
23511 + return len;
23512 }
23513 EXPORT_SYMBOL(copy_in_user);
23514
23515 @@ -115,7 +129,7 @@ EXPORT_SYMBOL(copy_in_user);
23516 * it is not necessary to optimize tail handling.
23517 */
23518 unsigned long
23519 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23520 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23521 {
23522 char c;
23523 unsigned zero_len;
23524 @@ -132,3 +146,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23525 break;
23526 return len;
23527 }
23528 +
23529 +void copy_from_user_overflow(void)
23530 +{
23531 + WARN(1, "Buffer overflow detected!\n");
23532 +}
23533 +EXPORT_SYMBOL(copy_from_user_overflow);
23534 +
23535 +void copy_to_user_overflow(void)
23536 +{
23537 + WARN(1, "Buffer overflow detected!\n");
23538 +}
23539 +EXPORT_SYMBOL(copy_to_user_overflow);
23540 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23541 index 1fb85db..8b3540b 100644
23542 --- a/arch/x86/mm/extable.c
23543 +++ b/arch/x86/mm/extable.c
23544 @@ -8,7 +8,7 @@ int fixup_exception(struct pt_regs *regs)
23545 const struct exception_table_entry *fixup;
23546
23547 #ifdef CONFIG_PNPBIOS
23548 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23549 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23550 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23551 extern u32 pnp_bios_is_utter_crap;
23552 pnp_bios_is_utter_crap = 1;
23553 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23554 index 3ecfd1a..304d554 100644
23555 --- a/arch/x86/mm/fault.c
23556 +++ b/arch/x86/mm/fault.c
23557 @@ -13,11 +13,18 @@
23558 #include <linux/perf_event.h> /* perf_sw_event */
23559 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23560 #include <linux/prefetch.h> /* prefetchw */
23561 +#include <linux/unistd.h>
23562 +#include <linux/compiler.h>
23563
23564 #include <asm/traps.h> /* dotraplinkage, ... */
23565 #include <asm/pgalloc.h> /* pgd_*(), ... */
23566 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23567 #include <asm/fixmap.h> /* VSYSCALL_START */
23568 +#include <asm/tlbflush.h>
23569 +
23570 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23571 +#include <asm/stacktrace.h>
23572 +#endif
23573
23574 /*
23575 * Page fault error code bits:
23576 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23577 int ret = 0;
23578
23579 /* kprobe_running() needs smp_processor_id() */
23580 - if (kprobes_built_in() && !user_mode_vm(regs)) {
23581 + if (kprobes_built_in() && !user_mode(regs)) {
23582 preempt_disable();
23583 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23584 ret = 1;
23585 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23586 return !instr_lo || (instr_lo>>1) == 1;
23587 case 0x00:
23588 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23589 - if (probe_kernel_address(instr, opcode))
23590 + if (user_mode(regs)) {
23591 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23592 + return 0;
23593 + } else if (probe_kernel_address(instr, opcode))
23594 return 0;
23595
23596 *prefetch = (instr_lo == 0xF) &&
23597 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23598 while (instr < max_instr) {
23599 unsigned char opcode;
23600
23601 - if (probe_kernel_address(instr, opcode))
23602 + if (user_mode(regs)) {
23603 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23604 + break;
23605 + } else if (probe_kernel_address(instr, opcode))
23606 break;
23607
23608 instr++;
23609 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23610 force_sig_info(si_signo, &info, tsk);
23611 }
23612
23613 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23614 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23615 +#endif
23616 +
23617 +#ifdef CONFIG_PAX_EMUTRAMP
23618 +static int pax_handle_fetch_fault(struct pt_regs *regs);
23619 +#endif
23620 +
23621 +#ifdef CONFIG_PAX_PAGEEXEC
23622 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23623 +{
23624 + pgd_t *pgd;
23625 + pud_t *pud;
23626 + pmd_t *pmd;
23627 +
23628 + pgd = pgd_offset(mm, address);
23629 + if (!pgd_present(*pgd))
23630 + return NULL;
23631 + pud = pud_offset(pgd, address);
23632 + if (!pud_present(*pud))
23633 + return NULL;
23634 + pmd = pmd_offset(pud, address);
23635 + if (!pmd_present(*pmd))
23636 + return NULL;
23637 + return pmd;
23638 +}
23639 +#endif
23640 +
23641 DEFINE_SPINLOCK(pgd_lock);
23642 LIST_HEAD(pgd_list);
23643
23644 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23645 for (address = VMALLOC_START & PMD_MASK;
23646 address >= TASK_SIZE && address < FIXADDR_TOP;
23647 address += PMD_SIZE) {
23648 +
23649 +#ifdef CONFIG_PAX_PER_CPU_PGD
23650 + unsigned long cpu;
23651 +#else
23652 struct page *page;
23653 +#endif
23654
23655 spin_lock(&pgd_lock);
23656 +
23657 +#ifdef CONFIG_PAX_PER_CPU_PGD
23658 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23659 + pgd_t *pgd = get_cpu_pgd(cpu);
23660 + pmd_t *ret;
23661 +#else
23662 list_for_each_entry(page, &pgd_list, lru) {
23663 + pgd_t *pgd = page_address(page);
23664 spinlock_t *pgt_lock;
23665 pmd_t *ret;
23666
23667 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23668 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23669
23670 spin_lock(pgt_lock);
23671 - ret = vmalloc_sync_one(page_address(page), address);
23672 +#endif
23673 +
23674 + ret = vmalloc_sync_one(pgd, address);
23675 +
23676 +#ifndef CONFIG_PAX_PER_CPU_PGD
23677 spin_unlock(pgt_lock);
23678 +#endif
23679
23680 if (!ret)
23681 break;
23682 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23683 * an interrupt in the middle of a task switch..
23684 */
23685 pgd_paddr = read_cr3();
23686 +
23687 +#ifdef CONFIG_PAX_PER_CPU_PGD
23688 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23689 +#endif
23690 +
23691 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23692 if (!pmd_k)
23693 return -1;
23694 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23695 * happen within a race in page table update. In the later
23696 * case just flush:
23697 */
23698 +
23699 +#ifdef CONFIG_PAX_PER_CPU_PGD
23700 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23701 + pgd = pgd_offset_cpu(smp_processor_id(), address);
23702 +#else
23703 pgd = pgd_offset(current->active_mm, address);
23704 +#endif
23705 +
23706 pgd_ref = pgd_offset_k(address);
23707 if (pgd_none(*pgd_ref))
23708 return -1;
23709 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23710 static int is_errata100(struct pt_regs *regs, unsigned long address)
23711 {
23712 #ifdef CONFIG_X86_64
23713 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23714 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23715 return 1;
23716 #endif
23717 return 0;
23718 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23719 }
23720
23721 static const char nx_warning[] = KERN_CRIT
23722 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23723 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23724
23725 static void
23726 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23727 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23728 if (!oops_may_print())
23729 return;
23730
23731 - if (error_code & PF_INSTR) {
23732 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23733 unsigned int level;
23734
23735 pte_t *pte = lookup_address(address, &level);
23736
23737 if (pte && pte_present(*pte) && !pte_exec(*pte))
23738 - printk(nx_warning, current_uid());
23739 + printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
23740 }
23741
23742 +#ifdef CONFIG_PAX_KERNEXEC
23743 + if (init_mm.start_code <= address && address < init_mm.end_code) {
23744 + if (current->signal->curr_ip)
23745 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23746 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23747 + else
23748 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23749 + current->comm, task_pid_nr(current), current_uid(), current_euid());
23750 + }
23751 +#endif
23752 +
23753 printk(KERN_ALERT "BUG: unable to handle kernel ");
23754 if (address < PAGE_SIZE)
23755 printk(KERN_CONT "NULL pointer dereference");
23756 @@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23757 }
23758 #endif
23759
23760 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23761 + if (pax_is_fetch_fault(regs, error_code, address)) {
23762 +
23763 +#ifdef CONFIG_PAX_EMUTRAMP
23764 + switch (pax_handle_fetch_fault(regs)) {
23765 + case 2:
23766 + return;
23767 + }
23768 +#endif
23769 +
23770 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23771 + do_group_exit(SIGKILL);
23772 + }
23773 +#endif
23774 +
23775 if (unlikely(show_unhandled_signals))
23776 show_signal_msg(regs, error_code, address, tsk);
23777
23778 @@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23779 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23780 printk(KERN_ERR
23781 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23782 - tsk->comm, tsk->pid, address);
23783 + tsk->comm, task_pid_nr(tsk), address);
23784 code = BUS_MCEERR_AR;
23785 }
23786 #endif
23787 @@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23788 return 1;
23789 }
23790
23791 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23792 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23793 +{
23794 + pte_t *pte;
23795 + pmd_t *pmd;
23796 + spinlock_t *ptl;
23797 + unsigned char pte_mask;
23798 +
23799 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23800 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
23801 + return 0;
23802 +
23803 + /* PaX: it's our fault, let's handle it if we can */
23804 +
23805 + /* PaX: take a look at read faults before acquiring any locks */
23806 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23807 + /* instruction fetch attempt from a protected page in user mode */
23808 + up_read(&mm->mmap_sem);
23809 +
23810 +#ifdef CONFIG_PAX_EMUTRAMP
23811 + switch (pax_handle_fetch_fault(regs)) {
23812 + case 2:
23813 + return 1;
23814 + }
23815 +#endif
23816 +
23817 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23818 + do_group_exit(SIGKILL);
23819 + }
23820 +
23821 + pmd = pax_get_pmd(mm, address);
23822 + if (unlikely(!pmd))
23823 + return 0;
23824 +
23825 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23826 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23827 + pte_unmap_unlock(pte, ptl);
23828 + return 0;
23829 + }
23830 +
23831 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23832 + /* write attempt to a protected page in user mode */
23833 + pte_unmap_unlock(pte, ptl);
23834 + return 0;
23835 + }
23836 +
23837 +#ifdef CONFIG_SMP
23838 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23839 +#else
23840 + if (likely(address > get_limit(regs->cs)))
23841 +#endif
23842 + {
23843 + set_pte(pte, pte_mkread(*pte));
23844 + __flush_tlb_one(address);
23845 + pte_unmap_unlock(pte, ptl);
23846 + up_read(&mm->mmap_sem);
23847 + return 1;
23848 + }
23849 +
23850 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23851 +
23852 + /*
23853 + * PaX: fill DTLB with user rights and retry
23854 + */
23855 + __asm__ __volatile__ (
23856 + "orb %2,(%1)\n"
23857 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23858 +/*
23859 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23860 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23861 + * page fault when examined during a TLB load attempt. this is true not only
23862 + * for PTEs holding a non-present entry but also present entries that will
23863 + * raise a page fault (such as those set up by PaX, or the copy-on-write
23864 + * mechanism). in effect it means that we do *not* need to flush the TLBs
23865 + * for our target pages since their PTEs are simply not in the TLBs at all.
23866 +
23867 + * the best thing in omitting it is that we gain around 15-20% speed in the
23868 + * fast path of the page fault handler and can get rid of tracing since we
23869 + * can no longer flush unintended entries.
23870 + */
23871 + "invlpg (%0)\n"
23872 +#endif
23873 + __copyuser_seg"testb $0,(%0)\n"
23874 + "xorb %3,(%1)\n"
23875 + :
23876 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23877 + : "memory", "cc");
23878 + pte_unmap_unlock(pte, ptl);
23879 + up_read(&mm->mmap_sem);
23880 + return 1;
23881 +}
23882 +#endif
23883 +
23884 /*
23885 * Handle a spurious fault caused by a stale TLB entry.
23886 *
23887 @@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23888 static inline int
23889 access_error(unsigned long error_code, struct vm_area_struct *vma)
23890 {
23891 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23892 + return 1;
23893 +
23894 if (error_code & PF_WRITE) {
23895 /* write, present and write, not present: */
23896 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23897 @@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23898 {
23899 struct vm_area_struct *vma;
23900 struct task_struct *tsk;
23901 - unsigned long address;
23902 struct mm_struct *mm;
23903 int fault;
23904 int write = error_code & PF_WRITE;
23905 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23906 (write ? FAULT_FLAG_WRITE : 0);
23907
23908 - tsk = current;
23909 - mm = tsk->mm;
23910 -
23911 /* Get the faulting address: */
23912 - address = read_cr2();
23913 + unsigned long address = read_cr2();
23914 +
23915 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23916 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23917 + if (!search_exception_tables(regs->ip)) {
23918 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23919 + bad_area_nosemaphore(regs, error_code, address);
23920 + return;
23921 + }
23922 + if (address < PAX_USER_SHADOW_BASE) {
23923 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23924 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
23925 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
23926 + } else
23927 + address -= PAX_USER_SHADOW_BASE;
23928 + }
23929 +#endif
23930 +
23931 + tsk = current;
23932 + mm = tsk->mm;
23933
23934 /*
23935 * Detect and handle instructions that would cause a page fault for
23936 @@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23937 * User-mode registers count as a user access even for any
23938 * potential system fault or CPU buglet:
23939 */
23940 - if (user_mode_vm(regs)) {
23941 + if (user_mode(regs)) {
23942 local_irq_enable();
23943 error_code |= PF_USER;
23944 } else {
23945 @@ -1132,6 +1339,11 @@ retry:
23946 might_sleep();
23947 }
23948
23949 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23950 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
23951 + return;
23952 +#endif
23953 +
23954 vma = find_vma(mm, address);
23955 if (unlikely(!vma)) {
23956 bad_area(regs, error_code, address);
23957 @@ -1143,18 +1355,24 @@ retry:
23958 bad_area(regs, error_code, address);
23959 return;
23960 }
23961 - if (error_code & PF_USER) {
23962 - /*
23963 - * Accessing the stack below %sp is always a bug.
23964 - * The large cushion allows instructions like enter
23965 - * and pusha to work. ("enter $65535, $31" pushes
23966 - * 32 pointers and then decrements %sp by 65535.)
23967 - */
23968 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
23969 - bad_area(regs, error_code, address);
23970 - return;
23971 - }
23972 + /*
23973 + * Accessing the stack below %sp is always a bug.
23974 + * The large cushion allows instructions like enter
23975 + * and pusha to work. ("enter $65535, $31" pushes
23976 + * 32 pointers and then decrements %sp by 65535.)
23977 + */
23978 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
23979 + bad_area(regs, error_code, address);
23980 + return;
23981 }
23982 +
23983 +#ifdef CONFIG_PAX_SEGMEXEC
23984 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
23985 + bad_area(regs, error_code, address);
23986 + return;
23987 + }
23988 +#endif
23989 +
23990 if (unlikely(expand_stack(vma, address))) {
23991 bad_area(regs, error_code, address);
23992 return;
23993 @@ -1209,3 +1427,292 @@ good_area:
23994
23995 up_read(&mm->mmap_sem);
23996 }
23997 +
23998 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23999 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
24000 +{
24001 + struct mm_struct *mm = current->mm;
24002 + unsigned long ip = regs->ip;
24003 +
24004 + if (v8086_mode(regs))
24005 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24006 +
24007 +#ifdef CONFIG_PAX_PAGEEXEC
24008 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24009 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24010 + return true;
24011 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24012 + return true;
24013 + return false;
24014 + }
24015 +#endif
24016 +
24017 +#ifdef CONFIG_PAX_SEGMEXEC
24018 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24019 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24020 + return true;
24021 + return false;
24022 + }
24023 +#endif
24024 +
24025 + return false;
24026 +}
24027 +#endif
24028 +
24029 +#ifdef CONFIG_PAX_EMUTRAMP
24030 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24031 +{
24032 + int err;
24033 +
24034 + do { /* PaX: libffi trampoline emulation */
24035 + unsigned char mov, jmp;
24036 + unsigned int addr1, addr2;
24037 +
24038 +#ifdef CONFIG_X86_64
24039 + if ((regs->ip + 9) >> 32)
24040 + break;
24041 +#endif
24042 +
24043 + err = get_user(mov, (unsigned char __user *)regs->ip);
24044 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24045 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24046 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24047 +
24048 + if (err)
24049 + break;
24050 +
24051 + if (mov == 0xB8 && jmp == 0xE9) {
24052 + regs->ax = addr1;
24053 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24054 + return 2;
24055 + }
24056 + } while (0);
24057 +
24058 + do { /* PaX: gcc trampoline emulation #1 */
24059 + unsigned char mov1, mov2;
24060 + unsigned short jmp;
24061 + unsigned int addr1, addr2;
24062 +
24063 +#ifdef CONFIG_X86_64
24064 + if ((regs->ip + 11) >> 32)
24065 + break;
24066 +#endif
24067 +
24068 + err = get_user(mov1, (unsigned char __user *)regs->ip);
24069 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24070 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24071 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24072 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24073 +
24074 + if (err)
24075 + break;
24076 +
24077 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24078 + regs->cx = addr1;
24079 + regs->ax = addr2;
24080 + regs->ip = addr2;
24081 + return 2;
24082 + }
24083 + } while (0);
24084 +
24085 + do { /* PaX: gcc trampoline emulation #2 */
24086 + unsigned char mov, jmp;
24087 + unsigned int addr1, addr2;
24088 +
24089 +#ifdef CONFIG_X86_64
24090 + if ((regs->ip + 9) >> 32)
24091 + break;
24092 +#endif
24093 +
24094 + err = get_user(mov, (unsigned char __user *)regs->ip);
24095 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24096 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24097 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24098 +
24099 + if (err)
24100 + break;
24101 +
24102 + if (mov == 0xB9 && jmp == 0xE9) {
24103 + regs->cx = addr1;
24104 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24105 + return 2;
24106 + }
24107 + } while (0);
24108 +
24109 + return 1; /* PaX in action */
24110 +}
24111 +
24112 +#ifdef CONFIG_X86_64
24113 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24114 +{
24115 + int err;
24116 +
24117 + do { /* PaX: libffi trampoline emulation */
24118 + unsigned short mov1, mov2, jmp1;
24119 + unsigned char stcclc, jmp2;
24120 + unsigned long addr1, addr2;
24121 +
24122 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24123 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24124 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24125 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24126 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24127 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24128 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24129 +
24130 + if (err)
24131 + break;
24132 +
24133 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24134 + regs->r11 = addr1;
24135 + regs->r10 = addr2;
24136 + if (stcclc == 0xF8)
24137 + regs->flags &= ~X86_EFLAGS_CF;
24138 + else
24139 + regs->flags |= X86_EFLAGS_CF;
24140 + regs->ip = addr1;
24141 + return 2;
24142 + }
24143 + } while (0);
24144 +
24145 + do { /* PaX: gcc trampoline emulation #1 */
24146 + unsigned short mov1, mov2, jmp1;
24147 + unsigned char jmp2;
24148 + unsigned int addr1;
24149 + unsigned long addr2;
24150 +
24151 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24152 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24153 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24154 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24155 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24156 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24157 +
24158 + if (err)
24159 + break;
24160 +
24161 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24162 + regs->r11 = addr1;
24163 + regs->r10 = addr2;
24164 + regs->ip = addr1;
24165 + return 2;
24166 + }
24167 + } while (0);
24168 +
24169 + do { /* PaX: gcc trampoline emulation #2 */
24170 + unsigned short mov1, mov2, jmp1;
24171 + unsigned char jmp2;
24172 + unsigned long addr1, addr2;
24173 +
24174 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24175 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24176 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24177 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24178 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24179 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24180 +
24181 + if (err)
24182 + break;
24183 +
24184 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24185 + regs->r11 = addr1;
24186 + regs->r10 = addr2;
24187 + regs->ip = addr1;
24188 + return 2;
24189 + }
24190 + } while (0);
24191 +
24192 + return 1; /* PaX in action */
24193 +}
24194 +#endif
24195 +
24196 +/*
24197 + * PaX: decide what to do with offenders (regs->ip = fault address)
24198 + *
24199 + * returns 1 when task should be killed
24200 + * 2 when gcc trampoline was detected
24201 + */
24202 +static int pax_handle_fetch_fault(struct pt_regs *regs)
24203 +{
24204 + if (v8086_mode(regs))
24205 + return 1;
24206 +
24207 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24208 + return 1;
24209 +
24210 +#ifdef CONFIG_X86_32
24211 + return pax_handle_fetch_fault_32(regs);
24212 +#else
24213 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24214 + return pax_handle_fetch_fault_32(regs);
24215 + else
24216 + return pax_handle_fetch_fault_64(regs);
24217 +#endif
24218 +}
24219 +#endif
24220 +
24221 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24222 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24223 +{
24224 + long i;
24225 +
24226 + printk(KERN_ERR "PAX: bytes at PC: ");
24227 + for (i = 0; i < 20; i++) {
24228 + unsigned char c;
24229 + if (get_user(c, (unsigned char __force_user *)pc+i))
24230 + printk(KERN_CONT "?? ");
24231 + else
24232 + printk(KERN_CONT "%02x ", c);
24233 + }
24234 + printk("\n");
24235 +
24236 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24237 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
24238 + unsigned long c;
24239 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
24240 +#ifdef CONFIG_X86_32
24241 + printk(KERN_CONT "???????? ");
24242 +#else
24243 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24244 + printk(KERN_CONT "???????? ???????? ");
24245 + else
24246 + printk(KERN_CONT "???????????????? ");
24247 +#endif
24248 + } else {
24249 +#ifdef CONFIG_X86_64
24250 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24251 + printk(KERN_CONT "%08x ", (unsigned int)c);
24252 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24253 + } else
24254 +#endif
24255 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24256 + }
24257 + }
24258 + printk("\n");
24259 +}
24260 +#endif
24261 +
24262 +/**
24263 + * probe_kernel_write(): safely attempt to write to a location
24264 + * @dst: address to write to
24265 + * @src: pointer to the data that shall be written
24266 + * @size: size of the data chunk
24267 + *
24268 + * Safely write to address @dst from the buffer at @src. If a kernel fault
24269 + * happens, handle that and return -EFAULT.
24270 + */
24271 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24272 +{
24273 + long ret;
24274 + mm_segment_t old_fs = get_fs();
24275 +
24276 + set_fs(KERNEL_DS);
24277 + pagefault_disable();
24278 + pax_open_kernel();
24279 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24280 + pax_close_kernel();
24281 + pagefault_enable();
24282 + set_fs(old_fs);
24283 +
24284 + return ret ? -EFAULT : 0;
24285 +}
24286 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24287 index dd74e46..7d26398 100644
24288 --- a/arch/x86/mm/gup.c
24289 +++ b/arch/x86/mm/gup.c
24290 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24291 addr = start;
24292 len = (unsigned long) nr_pages << PAGE_SHIFT;
24293 end = start + len;
24294 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24295 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24296 (void __user *)start, len)))
24297 return 0;
24298
24299 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24300 index 6f31ee5..8ee4164 100644
24301 --- a/arch/x86/mm/highmem_32.c
24302 +++ b/arch/x86/mm/highmem_32.c
24303 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24304 idx = type + KM_TYPE_NR*smp_processor_id();
24305 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24306 BUG_ON(!pte_none(*(kmap_pte-idx)));
24307 +
24308 + pax_open_kernel();
24309 set_pte(kmap_pte-idx, mk_pte(page, prot));
24310 + pax_close_kernel();
24311 +
24312 arch_flush_lazy_mmu_mode();
24313
24314 return (void *)vaddr;
24315 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24316 index f6679a7..8f795a3 100644
24317 --- a/arch/x86/mm/hugetlbpage.c
24318 +++ b/arch/x86/mm/hugetlbpage.c
24319 @@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24320 struct hstate *h = hstate_file(file);
24321 struct mm_struct *mm = current->mm;
24322 struct vm_area_struct *vma;
24323 - unsigned long start_addr;
24324 + unsigned long start_addr, pax_task_size = TASK_SIZE;
24325 +
24326 +#ifdef CONFIG_PAX_SEGMEXEC
24327 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24328 + pax_task_size = SEGMEXEC_TASK_SIZE;
24329 +#endif
24330 +
24331 + pax_task_size -= PAGE_SIZE;
24332
24333 if (len > mm->cached_hole_size) {
24334 - start_addr = mm->free_area_cache;
24335 + start_addr = mm->free_area_cache;
24336 } else {
24337 - start_addr = TASK_UNMAPPED_BASE;
24338 - mm->cached_hole_size = 0;
24339 + start_addr = mm->mmap_base;
24340 + mm->cached_hole_size = 0;
24341 }
24342
24343 full_search:
24344 @@ -280,26 +287,27 @@ full_search:
24345
24346 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24347 /* At this point: (!vma || addr < vma->vm_end). */
24348 - if (TASK_SIZE - len < addr) {
24349 + if (pax_task_size - len < addr) {
24350 /*
24351 * Start a new search - just in case we missed
24352 * some holes.
24353 */
24354 - if (start_addr != TASK_UNMAPPED_BASE) {
24355 - start_addr = TASK_UNMAPPED_BASE;
24356 + if (start_addr != mm->mmap_base) {
24357 + start_addr = mm->mmap_base;
24358 mm->cached_hole_size = 0;
24359 goto full_search;
24360 }
24361 return -ENOMEM;
24362 }
24363 - if (!vma || addr + len <= vma->vm_start) {
24364 - mm->free_area_cache = addr + len;
24365 - return addr;
24366 - }
24367 + if (check_heap_stack_gap(vma, addr, len))
24368 + break;
24369 if (addr + mm->cached_hole_size < vma->vm_start)
24370 mm->cached_hole_size = vma->vm_start - addr;
24371 addr = ALIGN(vma->vm_end, huge_page_size(h));
24372 }
24373 +
24374 + mm->free_area_cache = addr + len;
24375 + return addr;
24376 }
24377
24378 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24379 @@ -310,9 +318,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24380 struct mm_struct *mm = current->mm;
24381 struct vm_area_struct *vma;
24382 unsigned long base = mm->mmap_base;
24383 - unsigned long addr = addr0;
24384 + unsigned long addr;
24385 unsigned long largest_hole = mm->cached_hole_size;
24386 - unsigned long start_addr;
24387
24388 /* don't allow allocations above current base */
24389 if (mm->free_area_cache > base)
24390 @@ -322,16 +329,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24391 largest_hole = 0;
24392 mm->free_area_cache = base;
24393 }
24394 -try_again:
24395 - start_addr = mm->free_area_cache;
24396
24397 /* make sure it can fit in the remaining address space */
24398 if (mm->free_area_cache < len)
24399 goto fail;
24400
24401 /* either no address requested or can't fit in requested address hole */
24402 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
24403 + addr = mm->free_area_cache - len;
24404 do {
24405 + addr &= huge_page_mask(h);
24406 /*
24407 * Lookup failure means no vma is above this address,
24408 * i.e. return with success:
24409 @@ -340,10 +346,10 @@ try_again:
24410 if (!vma)
24411 return addr;
24412
24413 - if (addr + len <= vma->vm_start) {
24414 + if (check_heap_stack_gap(vma, addr, len)) {
24415 /* remember the address as a hint for next time */
24416 - mm->cached_hole_size = largest_hole;
24417 - return (mm->free_area_cache = addr);
24418 + mm->cached_hole_size = largest_hole;
24419 + return (mm->free_area_cache = addr);
24420 } else if (mm->free_area_cache == vma->vm_end) {
24421 /* pull free_area_cache down to the first hole */
24422 mm->free_area_cache = vma->vm_start;
24423 @@ -352,29 +358,34 @@ try_again:
24424
24425 /* remember the largest hole we saw so far */
24426 if (addr + largest_hole < vma->vm_start)
24427 - largest_hole = vma->vm_start - addr;
24428 + largest_hole = vma->vm_start - addr;
24429
24430 /* try just below the current vma->vm_start */
24431 - addr = (vma->vm_start - len) & huge_page_mask(h);
24432 - } while (len <= vma->vm_start);
24433 + addr = skip_heap_stack_gap(vma, len);
24434 + } while (!IS_ERR_VALUE(addr));
24435
24436 fail:
24437 /*
24438 - * if hint left us with no space for the requested
24439 - * mapping then try again:
24440 - */
24441 - if (start_addr != base) {
24442 - mm->free_area_cache = base;
24443 - largest_hole = 0;
24444 - goto try_again;
24445 - }
24446 - /*
24447 * A failed mmap() very likely causes application failure,
24448 * so fall back to the bottom-up function here. This scenario
24449 * can happen with large stack limits and large mmap()
24450 * allocations.
24451 */
24452 - mm->free_area_cache = TASK_UNMAPPED_BASE;
24453 +
24454 +#ifdef CONFIG_PAX_SEGMEXEC
24455 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24456 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24457 + else
24458 +#endif
24459 +
24460 + mm->mmap_base = TASK_UNMAPPED_BASE;
24461 +
24462 +#ifdef CONFIG_PAX_RANDMMAP
24463 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24464 + mm->mmap_base += mm->delta_mmap;
24465 +#endif
24466 +
24467 + mm->free_area_cache = mm->mmap_base;
24468 mm->cached_hole_size = ~0UL;
24469 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24470 len, pgoff, flags);
24471 @@ -382,6 +393,7 @@ fail:
24472 /*
24473 * Restore the topdown base:
24474 */
24475 + mm->mmap_base = base;
24476 mm->free_area_cache = base;
24477 mm->cached_hole_size = ~0UL;
24478
24479 @@ -395,10 +407,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24480 struct hstate *h = hstate_file(file);
24481 struct mm_struct *mm = current->mm;
24482 struct vm_area_struct *vma;
24483 + unsigned long pax_task_size = TASK_SIZE;
24484
24485 if (len & ~huge_page_mask(h))
24486 return -EINVAL;
24487 - if (len > TASK_SIZE)
24488 +
24489 +#ifdef CONFIG_PAX_SEGMEXEC
24490 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24491 + pax_task_size = SEGMEXEC_TASK_SIZE;
24492 +#endif
24493 +
24494 + pax_task_size -= PAGE_SIZE;
24495 +
24496 + if (len > pax_task_size)
24497 return -ENOMEM;
24498
24499 if (flags & MAP_FIXED) {
24500 @@ -410,8 +431,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24501 if (addr) {
24502 addr = ALIGN(addr, huge_page_size(h));
24503 vma = find_vma(mm, addr);
24504 - if (TASK_SIZE - len >= addr &&
24505 - (!vma || addr + len <= vma->vm_start))
24506 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24507 return addr;
24508 }
24509 if (mm->get_unmapped_area == arch_get_unmapped_area)
24510 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24511 index 4f0cec7..00976ce 100644
24512 --- a/arch/x86/mm/init.c
24513 +++ b/arch/x86/mm/init.c
24514 @@ -16,6 +16,8 @@
24515 #include <asm/tlb.h>
24516 #include <asm/proto.h>
24517 #include <asm/dma.h> /* for MAX_DMA_PFN */
24518 +#include <asm/desc.h>
24519 +#include <asm/bios_ebda.h>
24520
24521 unsigned long __initdata pgt_buf_start;
24522 unsigned long __meminitdata pgt_buf_end;
24523 @@ -32,7 +34,7 @@ int direct_gbpages
24524 static void __init find_early_table_space(unsigned long end, int use_pse,
24525 int use_gbpages)
24526 {
24527 - unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
24528 + unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
24529 phys_addr_t base;
24530
24531 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
24532 @@ -311,10 +313,37 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24533 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24534 * mmio resources as well as potential bios/acpi data regions.
24535 */
24536 +
24537 +#ifdef CONFIG_GRKERNSEC_KMEM
24538 +static unsigned int ebda_start __read_only;
24539 +static unsigned int ebda_end __read_only;
24540 +#endif
24541 +
24542 int devmem_is_allowed(unsigned long pagenr)
24543 {
24544 +#ifdef CONFIG_GRKERNSEC_KMEM
24545 + /* allow BDA */
24546 + if (!pagenr)
24547 + return 1;
24548 + /* allow EBDA */
24549 + if (pagenr >= ebda_start && pagenr < ebda_end)
24550 + return 1;
24551 +#else
24552 + if (!pagenr)
24553 + return 1;
24554 +#ifdef CONFIG_VM86
24555 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24556 + return 1;
24557 +#endif
24558 +#endif
24559 +
24560 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24561 + return 1;
24562 +#ifdef CONFIG_GRKERNSEC_KMEM
24563 + /* throw out everything else below 1MB */
24564 if (pagenr <= 256)
24565 - return 1;
24566 + return 0;
24567 +#endif
24568 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24569 return 0;
24570 if (!page_is_ram(pagenr))
24571 @@ -371,8 +400,116 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24572 #endif
24573 }
24574
24575 +#ifdef CONFIG_GRKERNSEC_KMEM
24576 +static inline void gr_init_ebda(void)
24577 +{
24578 + unsigned int ebda_addr;
24579 + unsigned int ebda_size = 0;
24580 +
24581 + ebda_addr = get_bios_ebda();
24582 + if (ebda_addr) {
24583 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24584 + ebda_size <<= 10;
24585 + }
24586 + if (ebda_addr && ebda_size) {
24587 + ebda_start = ebda_addr >> PAGE_SHIFT;
24588 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24589 + } else {
24590 + ebda_start = 0x9f000 >> PAGE_SHIFT;
24591 + ebda_end = 0xa0000 >> PAGE_SHIFT;
24592 + }
24593 +}
24594 +#else
24595 +static inline void gr_init_ebda(void) { }
24596 +#endif
24597 +
24598 void free_initmem(void)
24599 {
24600 +#ifdef CONFIG_PAX_KERNEXEC
24601 +#ifdef CONFIG_X86_32
24602 + /* PaX: limit KERNEL_CS to actual size */
24603 + unsigned long addr, limit;
24604 + struct desc_struct d;
24605 + int cpu;
24606 +#else
24607 + pgd_t *pgd;
24608 + pud_t *pud;
24609 + pmd_t *pmd;
24610 + unsigned long addr, end;
24611 +#endif
24612 +#endif
24613 +
24614 + gr_init_ebda();
24615 +
24616 +#ifdef CONFIG_PAX_KERNEXEC
24617 +#ifdef CONFIG_X86_32
24618 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24619 + limit = (limit - 1UL) >> PAGE_SHIFT;
24620 +
24621 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24622 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24623 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24624 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24625 + }
24626 +
24627 + /* PaX: make KERNEL_CS read-only */
24628 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24629 + if (!paravirt_enabled())
24630 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24631 +/*
24632 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24633 + pgd = pgd_offset_k(addr);
24634 + pud = pud_offset(pgd, addr);
24635 + pmd = pmd_offset(pud, addr);
24636 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24637 + }
24638 +*/
24639 +#ifdef CONFIG_X86_PAE
24640 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24641 +/*
24642 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24643 + pgd = pgd_offset_k(addr);
24644 + pud = pud_offset(pgd, addr);
24645 + pmd = pmd_offset(pud, addr);
24646 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24647 + }
24648 +*/
24649 +#endif
24650 +
24651 +#ifdef CONFIG_MODULES
24652 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24653 +#endif
24654 +
24655 +#else
24656 + /* PaX: make kernel code/rodata read-only, rest non-executable */
24657 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24658 + pgd = pgd_offset_k(addr);
24659 + pud = pud_offset(pgd, addr);
24660 + pmd = pmd_offset(pud, addr);
24661 + if (!pmd_present(*pmd))
24662 + continue;
24663 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24664 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24665 + else
24666 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24667 + }
24668 +
24669 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24670 + end = addr + KERNEL_IMAGE_SIZE;
24671 + for (; addr < end; addr += PMD_SIZE) {
24672 + pgd = pgd_offset_k(addr);
24673 + pud = pud_offset(pgd, addr);
24674 + pmd = pmd_offset(pud, addr);
24675 + if (!pmd_present(*pmd))
24676 + continue;
24677 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24678 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24679 + }
24680 +#endif
24681 +
24682 + flush_tlb_all();
24683 +#endif
24684 +
24685 free_init_pages("unused kernel memory",
24686 (unsigned long)(&__init_begin),
24687 (unsigned long)(&__init_end));
24688 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24689 index 575d86f..4987469 100644
24690 --- a/arch/x86/mm/init_32.c
24691 +++ b/arch/x86/mm/init_32.c
24692 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24693 }
24694
24695 /*
24696 - * Creates a middle page table and puts a pointer to it in the
24697 - * given global directory entry. This only returns the gd entry
24698 - * in non-PAE compilation mode, since the middle layer is folded.
24699 - */
24700 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24701 -{
24702 - pud_t *pud;
24703 - pmd_t *pmd_table;
24704 -
24705 -#ifdef CONFIG_X86_PAE
24706 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24707 - if (after_bootmem)
24708 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24709 - else
24710 - pmd_table = (pmd_t *)alloc_low_page();
24711 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24712 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24713 - pud = pud_offset(pgd, 0);
24714 - BUG_ON(pmd_table != pmd_offset(pud, 0));
24715 -
24716 - return pmd_table;
24717 - }
24718 -#endif
24719 - pud = pud_offset(pgd, 0);
24720 - pmd_table = pmd_offset(pud, 0);
24721 -
24722 - return pmd_table;
24723 -}
24724 -
24725 -/*
24726 * Create a page table and place a pointer to it in a middle page
24727 * directory entry:
24728 */
24729 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24730 page_table = (pte_t *)alloc_low_page();
24731
24732 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24733 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24734 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24735 +#else
24736 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24737 +#endif
24738 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24739 }
24740
24741 return pte_offset_kernel(pmd, 0);
24742 }
24743
24744 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
24745 +{
24746 + pud_t *pud;
24747 + pmd_t *pmd_table;
24748 +
24749 + pud = pud_offset(pgd, 0);
24750 + pmd_table = pmd_offset(pud, 0);
24751 +
24752 + return pmd_table;
24753 +}
24754 +
24755 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24756 {
24757 int pgd_idx = pgd_index(vaddr);
24758 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24759 int pgd_idx, pmd_idx;
24760 unsigned long vaddr;
24761 pgd_t *pgd;
24762 + pud_t *pud;
24763 pmd_t *pmd;
24764 pte_t *pte = NULL;
24765
24766 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24767 pgd = pgd_base + pgd_idx;
24768
24769 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24770 - pmd = one_md_table_init(pgd);
24771 - pmd = pmd + pmd_index(vaddr);
24772 + pud = pud_offset(pgd, vaddr);
24773 + pmd = pmd_offset(pud, vaddr);
24774 +
24775 +#ifdef CONFIG_X86_PAE
24776 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24777 +#endif
24778 +
24779 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24780 pmd++, pmd_idx++) {
24781 pte = page_table_kmap_check(one_page_table_init(pmd),
24782 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24783 }
24784 }
24785
24786 -static inline int is_kernel_text(unsigned long addr)
24787 +static inline int is_kernel_text(unsigned long start, unsigned long end)
24788 {
24789 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24790 - return 1;
24791 - return 0;
24792 + if ((start > ktla_ktva((unsigned long)_etext) ||
24793 + end <= ktla_ktva((unsigned long)_stext)) &&
24794 + (start > ktla_ktva((unsigned long)_einittext) ||
24795 + end <= ktla_ktva((unsigned long)_sinittext)) &&
24796 +
24797 +#ifdef CONFIG_ACPI_SLEEP
24798 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24799 +#endif
24800 +
24801 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24802 + return 0;
24803 + return 1;
24804 }
24805
24806 /*
24807 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24808 unsigned long last_map_addr = end;
24809 unsigned long start_pfn, end_pfn;
24810 pgd_t *pgd_base = swapper_pg_dir;
24811 - int pgd_idx, pmd_idx, pte_ofs;
24812 + unsigned int pgd_idx, pmd_idx, pte_ofs;
24813 unsigned long pfn;
24814 pgd_t *pgd;
24815 + pud_t *pud;
24816 pmd_t *pmd;
24817 pte_t *pte;
24818 unsigned pages_2m, pages_4k;
24819 @@ -280,8 +281,13 @@ repeat:
24820 pfn = start_pfn;
24821 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24822 pgd = pgd_base + pgd_idx;
24823 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24824 - pmd = one_md_table_init(pgd);
24825 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24826 + pud = pud_offset(pgd, 0);
24827 + pmd = pmd_offset(pud, 0);
24828 +
24829 +#ifdef CONFIG_X86_PAE
24830 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24831 +#endif
24832
24833 if (pfn >= end_pfn)
24834 continue;
24835 @@ -293,14 +299,13 @@ repeat:
24836 #endif
24837 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24838 pmd++, pmd_idx++) {
24839 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24840 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24841
24842 /*
24843 * Map with big pages if possible, otherwise
24844 * create normal page tables:
24845 */
24846 if (use_pse) {
24847 - unsigned int addr2;
24848 pgprot_t prot = PAGE_KERNEL_LARGE;
24849 /*
24850 * first pass will use the same initial
24851 @@ -310,11 +315,7 @@ repeat:
24852 __pgprot(PTE_IDENT_ATTR |
24853 _PAGE_PSE);
24854
24855 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24856 - PAGE_OFFSET + PAGE_SIZE-1;
24857 -
24858 - if (is_kernel_text(addr) ||
24859 - is_kernel_text(addr2))
24860 + if (is_kernel_text(address, address + PMD_SIZE))
24861 prot = PAGE_KERNEL_LARGE_EXEC;
24862
24863 pages_2m++;
24864 @@ -331,7 +332,7 @@ repeat:
24865 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24866 pte += pte_ofs;
24867 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24868 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24869 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24870 pgprot_t prot = PAGE_KERNEL;
24871 /*
24872 * first pass will use the same initial
24873 @@ -339,7 +340,7 @@ repeat:
24874 */
24875 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24876
24877 - if (is_kernel_text(addr))
24878 + if (is_kernel_text(address, address + PAGE_SIZE))
24879 prot = PAGE_KERNEL_EXEC;
24880
24881 pages_4k++;
24882 @@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24883
24884 pud = pud_offset(pgd, va);
24885 pmd = pmd_offset(pud, va);
24886 - if (!pmd_present(*pmd))
24887 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
24888 break;
24889
24890 pte = pte_offset_kernel(pmd, va);
24891 @@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
24892
24893 static void __init pagetable_init(void)
24894 {
24895 - pgd_t *pgd_base = swapper_pg_dir;
24896 -
24897 - permanent_kmaps_init(pgd_base);
24898 + permanent_kmaps_init(swapper_pg_dir);
24899 }
24900
24901 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24902 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24903 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24904
24905 /* user-defined highmem size */
24906 @@ -734,6 +733,12 @@ void __init mem_init(void)
24907
24908 pci_iommu_alloc();
24909
24910 +#ifdef CONFIG_PAX_PER_CPU_PGD
24911 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24912 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24913 + KERNEL_PGD_PTRS);
24914 +#endif
24915 +
24916 #ifdef CONFIG_FLATMEM
24917 BUG_ON(!mem_map);
24918 #endif
24919 @@ -760,7 +765,7 @@ void __init mem_init(void)
24920 reservedpages++;
24921
24922 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24923 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
24924 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
24925 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
24926
24927 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
24928 @@ -801,10 +806,10 @@ void __init mem_init(void)
24929 ((unsigned long)&__init_end -
24930 (unsigned long)&__init_begin) >> 10,
24931
24932 - (unsigned long)&_etext, (unsigned long)&_edata,
24933 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
24934 + (unsigned long)&_sdata, (unsigned long)&_edata,
24935 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
24936
24937 - (unsigned long)&_text, (unsigned long)&_etext,
24938 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
24939 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
24940
24941 /*
24942 @@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
24943 if (!kernel_set_to_readonly)
24944 return;
24945
24946 + start = ktla_ktva(start);
24947 pr_debug("Set kernel text: %lx - %lx for read write\n",
24948 start, start+size);
24949
24950 @@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
24951 if (!kernel_set_to_readonly)
24952 return;
24953
24954 + start = ktla_ktva(start);
24955 pr_debug("Set kernel text: %lx - %lx for read only\n",
24956 start, start+size);
24957
24958 @@ -924,6 +931,7 @@ void mark_rodata_ro(void)
24959 unsigned long start = PFN_ALIGN(_text);
24960 unsigned long size = PFN_ALIGN(_etext) - start;
24961
24962 + start = ktla_ktva(start);
24963 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
24964 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
24965 size >> 10);
24966 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
24967 index fc18be0..e539653 100644
24968 --- a/arch/x86/mm/init_64.c
24969 +++ b/arch/x86/mm/init_64.c
24970 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
24971 * around without checking the pgd every time.
24972 */
24973
24974 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
24975 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
24976 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24977
24978 int force_personality32;
24979 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24980
24981 for (address = start; address <= end; address += PGDIR_SIZE) {
24982 const pgd_t *pgd_ref = pgd_offset_k(address);
24983 +
24984 +#ifdef CONFIG_PAX_PER_CPU_PGD
24985 + unsigned long cpu;
24986 +#else
24987 struct page *page;
24988 +#endif
24989
24990 if (pgd_none(*pgd_ref))
24991 continue;
24992
24993 spin_lock(&pgd_lock);
24994 +
24995 +#ifdef CONFIG_PAX_PER_CPU_PGD
24996 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
24997 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
24998 +#else
24999 list_for_each_entry(page, &pgd_list, lru) {
25000 pgd_t *pgd;
25001 spinlock_t *pgt_lock;
25002 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25003 /* the pgt_lock only for Xen */
25004 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25005 spin_lock(pgt_lock);
25006 +#endif
25007
25008 if (pgd_none(*pgd))
25009 set_pgd(pgd, *pgd_ref);
25010 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25011 BUG_ON(pgd_page_vaddr(*pgd)
25012 != pgd_page_vaddr(*pgd_ref));
25013
25014 +#ifndef CONFIG_PAX_PER_CPU_PGD
25015 spin_unlock(pgt_lock);
25016 +#endif
25017 +
25018 }
25019 spin_unlock(&pgd_lock);
25020 }
25021 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
25022 {
25023 if (pgd_none(*pgd)) {
25024 pud_t *pud = (pud_t *)spp_getpage();
25025 - pgd_populate(&init_mm, pgd, pud);
25026 + pgd_populate_kernel(&init_mm, pgd, pud);
25027 if (pud != pud_offset(pgd, 0))
25028 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
25029 pud, pud_offset(pgd, 0));
25030 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
25031 {
25032 if (pud_none(*pud)) {
25033 pmd_t *pmd = (pmd_t *) spp_getpage();
25034 - pud_populate(&init_mm, pud, pmd);
25035 + pud_populate_kernel(&init_mm, pud, pmd);
25036 if (pmd != pmd_offset(pud, 0))
25037 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
25038 pmd, pmd_offset(pud, 0));
25039 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25040 pmd = fill_pmd(pud, vaddr);
25041 pte = fill_pte(pmd, vaddr);
25042
25043 + pax_open_kernel();
25044 set_pte(pte, new_pte);
25045 + pax_close_kernel();
25046
25047 /*
25048 * It's enough to flush this one mapping.
25049 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25050 pgd = pgd_offset_k((unsigned long)__va(phys));
25051 if (pgd_none(*pgd)) {
25052 pud = (pud_t *) spp_getpage();
25053 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25054 - _PAGE_USER));
25055 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25056 }
25057 pud = pud_offset(pgd, (unsigned long)__va(phys));
25058 if (pud_none(*pud)) {
25059 pmd = (pmd_t *) spp_getpage();
25060 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25061 - _PAGE_USER));
25062 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25063 }
25064 pmd = pmd_offset(pud, phys);
25065 BUG_ON(!pmd_none(*pmd));
25066 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
25067 if (pfn >= pgt_buf_top)
25068 panic("alloc_low_page: ran out of memory");
25069
25070 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25071 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25072 clear_page(adr);
25073 *phys = pfn * PAGE_SIZE;
25074 return adr;
25075 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
25076
25077 phys = __pa(virt);
25078 left = phys & (PAGE_SIZE - 1);
25079 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25080 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25081 adr = (void *)(((unsigned long)adr) | left);
25082
25083 return adr;
25084 @@ -545,7 +559,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25085 unmap_low_page(pmd);
25086
25087 spin_lock(&init_mm.page_table_lock);
25088 - pud_populate(&init_mm, pud, __va(pmd_phys));
25089 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25090 spin_unlock(&init_mm.page_table_lock);
25091 }
25092 __flush_tlb_all();
25093 @@ -591,7 +605,7 @@ kernel_physical_mapping_init(unsigned long start,
25094 unmap_low_page(pud);
25095
25096 spin_lock(&init_mm.page_table_lock);
25097 - pgd_populate(&init_mm, pgd, __va(pud_phys));
25098 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25099 spin_unlock(&init_mm.page_table_lock);
25100 pgd_changed = true;
25101 }
25102 @@ -683,6 +697,12 @@ void __init mem_init(void)
25103
25104 pci_iommu_alloc();
25105
25106 +#ifdef CONFIG_PAX_PER_CPU_PGD
25107 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25108 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25109 + KERNEL_PGD_PTRS);
25110 +#endif
25111 +
25112 /* clear_bss() already clear the empty_zero_page */
25113
25114 reservedpages = 0;
25115 @@ -843,8 +863,8 @@ int kern_addr_valid(unsigned long addr)
25116 static struct vm_area_struct gate_vma = {
25117 .vm_start = VSYSCALL_START,
25118 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25119 - .vm_page_prot = PAGE_READONLY_EXEC,
25120 - .vm_flags = VM_READ | VM_EXEC
25121 + .vm_page_prot = PAGE_READONLY,
25122 + .vm_flags = VM_READ
25123 };
25124
25125 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25126 @@ -878,7 +898,7 @@ int in_gate_area_no_mm(unsigned long addr)
25127
25128 const char *arch_vma_name(struct vm_area_struct *vma)
25129 {
25130 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25131 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25132 return "[vdso]";
25133 if (vma == &gate_vma)
25134 return "[vsyscall]";
25135 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25136 index 7b179b4..6bd1777 100644
25137 --- a/arch/x86/mm/iomap_32.c
25138 +++ b/arch/x86/mm/iomap_32.c
25139 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25140 type = kmap_atomic_idx_push();
25141 idx = type + KM_TYPE_NR * smp_processor_id();
25142 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25143 +
25144 + pax_open_kernel();
25145 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25146 + pax_close_kernel();
25147 +
25148 arch_flush_lazy_mmu_mode();
25149
25150 return (void *)vaddr;
25151 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25152 index be1ef57..55f0160 100644
25153 --- a/arch/x86/mm/ioremap.c
25154 +++ b/arch/x86/mm/ioremap.c
25155 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25156 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25157 int is_ram = page_is_ram(pfn);
25158
25159 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25160 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25161 return NULL;
25162 WARN_ON_ONCE(is_ram);
25163 }
25164 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25165
25166 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25167 if (page_is_ram(start >> PAGE_SHIFT))
25168 +#ifdef CONFIG_HIGHMEM
25169 + if ((start >> PAGE_SHIFT) < max_low_pfn)
25170 +#endif
25171 return __va(phys);
25172
25173 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25174 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25175 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25176
25177 static __initdata int after_paging_init;
25178 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25179 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25180
25181 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25182 {
25183 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25184 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25185
25186 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25187 - memset(bm_pte, 0, sizeof(bm_pte));
25188 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
25189 + pmd_populate_user(&init_mm, pmd, bm_pte);
25190
25191 /*
25192 * The boot-ioremap range spans multiple pmds, for which
25193 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25194 index d87dd6d..bf3fa66 100644
25195 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
25196 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25197 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25198 * memory (e.g. tracked pages)? For now, we need this to avoid
25199 * invoking kmemcheck for PnP BIOS calls.
25200 */
25201 - if (regs->flags & X86_VM_MASK)
25202 + if (v8086_mode(regs))
25203 return false;
25204 - if (regs->cs != __KERNEL_CS)
25205 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25206 return false;
25207
25208 pte = kmemcheck_pte_lookup(address);
25209 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25210 index 845df68..1d8d29f 100644
25211 --- a/arch/x86/mm/mmap.c
25212 +++ b/arch/x86/mm/mmap.c
25213 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25214 * Leave an at least ~128 MB hole with possible stack randomization.
25215 */
25216 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25217 -#define MAX_GAP (TASK_SIZE/6*5)
25218 +#define MAX_GAP (pax_task_size/6*5)
25219
25220 static int mmap_is_legacy(void)
25221 {
25222 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25223 return rnd << PAGE_SHIFT;
25224 }
25225
25226 -static unsigned long mmap_base(void)
25227 +static unsigned long mmap_base(struct mm_struct *mm)
25228 {
25229 unsigned long gap = rlimit(RLIMIT_STACK);
25230 + unsigned long pax_task_size = TASK_SIZE;
25231 +
25232 +#ifdef CONFIG_PAX_SEGMEXEC
25233 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25234 + pax_task_size = SEGMEXEC_TASK_SIZE;
25235 +#endif
25236
25237 if (gap < MIN_GAP)
25238 gap = MIN_GAP;
25239 else if (gap > MAX_GAP)
25240 gap = MAX_GAP;
25241
25242 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25243 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25244 }
25245
25246 /*
25247 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25248 * does, but not when emulating X86_32
25249 */
25250 -static unsigned long mmap_legacy_base(void)
25251 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
25252 {
25253 - if (mmap_is_ia32())
25254 + if (mmap_is_ia32()) {
25255 +
25256 +#ifdef CONFIG_PAX_SEGMEXEC
25257 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25258 + return SEGMEXEC_TASK_UNMAPPED_BASE;
25259 + else
25260 +#endif
25261 +
25262 return TASK_UNMAPPED_BASE;
25263 - else
25264 + } else
25265 return TASK_UNMAPPED_BASE + mmap_rnd();
25266 }
25267
25268 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25269 void arch_pick_mmap_layout(struct mm_struct *mm)
25270 {
25271 if (mmap_is_legacy()) {
25272 - mm->mmap_base = mmap_legacy_base();
25273 + mm->mmap_base = mmap_legacy_base(mm);
25274 +
25275 +#ifdef CONFIG_PAX_RANDMMAP
25276 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25277 + mm->mmap_base += mm->delta_mmap;
25278 +#endif
25279 +
25280 mm->get_unmapped_area = arch_get_unmapped_area;
25281 mm->unmap_area = arch_unmap_area;
25282 } else {
25283 - mm->mmap_base = mmap_base();
25284 + mm->mmap_base = mmap_base(mm);
25285 +
25286 +#ifdef CONFIG_PAX_RANDMMAP
25287 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25288 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25289 +#endif
25290 +
25291 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25292 mm->unmap_area = arch_unmap_area_topdown;
25293 }
25294 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25295 index dc0b727..dc9d71a 100644
25296 --- a/arch/x86/mm/mmio-mod.c
25297 +++ b/arch/x86/mm/mmio-mod.c
25298 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25299 break;
25300 default:
25301 {
25302 - unsigned char *ip = (unsigned char *)instptr;
25303 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25304 my_trace->opcode = MMIO_UNKNOWN_OP;
25305 my_trace->width = 0;
25306 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25307 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25308 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25309 void __iomem *addr)
25310 {
25311 - static atomic_t next_id;
25312 + static atomic_unchecked_t next_id;
25313 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25314 /* These are page-unaligned. */
25315 struct mmiotrace_map map = {
25316 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25317 .private = trace
25318 },
25319 .phys = offset,
25320 - .id = atomic_inc_return(&next_id)
25321 + .id = atomic_inc_return_unchecked(&next_id)
25322 };
25323 map.map_id = trace->id;
25324
25325 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25326 index b008656..773eac2 100644
25327 --- a/arch/x86/mm/pageattr-test.c
25328 +++ b/arch/x86/mm/pageattr-test.c
25329 @@ -36,7 +36,7 @@ enum {
25330
25331 static int pte_testbit(pte_t pte)
25332 {
25333 - return pte_flags(pte) & _PAGE_UNUSED1;
25334 + return pte_flags(pte) & _PAGE_CPA_TEST;
25335 }
25336
25337 struct split_state {
25338 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25339 index e1ebde3..b1e1db38 100644
25340 --- a/arch/x86/mm/pageattr.c
25341 +++ b/arch/x86/mm/pageattr.c
25342 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25343 */
25344 #ifdef CONFIG_PCI_BIOS
25345 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25346 - pgprot_val(forbidden) |= _PAGE_NX;
25347 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25348 #endif
25349
25350 /*
25351 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25352 * Does not cover __inittext since that is gone later on. On
25353 * 64bit we do not enforce !NX on the low mapping
25354 */
25355 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
25356 - pgprot_val(forbidden) |= _PAGE_NX;
25357 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25358 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25359
25360 +#ifdef CONFIG_DEBUG_RODATA
25361 /*
25362 * The .rodata section needs to be read-only. Using the pfn
25363 * catches all aliases.
25364 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25365 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25366 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25367 pgprot_val(forbidden) |= _PAGE_RW;
25368 +#endif
25369
25370 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25371 /*
25372 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25373 }
25374 #endif
25375
25376 +#ifdef CONFIG_PAX_KERNEXEC
25377 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25378 + pgprot_val(forbidden) |= _PAGE_RW;
25379 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25380 + }
25381 +#endif
25382 +
25383 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25384
25385 return prot;
25386 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25387 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25388 {
25389 /* change init_mm */
25390 + pax_open_kernel();
25391 set_pte_atomic(kpte, pte);
25392 +
25393 #ifdef CONFIG_X86_32
25394 if (!SHARED_KERNEL_PMD) {
25395 +
25396 +#ifdef CONFIG_PAX_PER_CPU_PGD
25397 + unsigned long cpu;
25398 +#else
25399 struct page *page;
25400 +#endif
25401
25402 +#ifdef CONFIG_PAX_PER_CPU_PGD
25403 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25404 + pgd_t *pgd = get_cpu_pgd(cpu);
25405 +#else
25406 list_for_each_entry(page, &pgd_list, lru) {
25407 - pgd_t *pgd;
25408 + pgd_t *pgd = (pgd_t *)page_address(page);
25409 +#endif
25410 +
25411 pud_t *pud;
25412 pmd_t *pmd;
25413
25414 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
25415 + pgd += pgd_index(address);
25416 pud = pud_offset(pgd, address);
25417 pmd = pmd_offset(pud, address);
25418 set_pte_atomic((pte_t *)pmd, pte);
25419 }
25420 }
25421 #endif
25422 + pax_close_kernel();
25423 }
25424
25425 static int
25426 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25427 index f6ff57b..481690f 100644
25428 --- a/arch/x86/mm/pat.c
25429 +++ b/arch/x86/mm/pat.c
25430 @@ -361,7 +361,7 @@ int free_memtype(u64 start, u64 end)
25431
25432 if (!entry) {
25433 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
25434 - current->comm, current->pid, start, end);
25435 + current->comm, task_pid_nr(current), start, end);
25436 return -EINVAL;
25437 }
25438
25439 @@ -492,8 +492,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25440 while (cursor < to) {
25441 if (!devmem_is_allowed(pfn)) {
25442 printk(KERN_INFO
25443 - "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
25444 - current->comm, from, to);
25445 + "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
25446 + current->comm, from, to, cursor);
25447 return 0;
25448 }
25449 cursor += PAGE_SIZE;
25450 @@ -557,7 +557,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25451 printk(KERN_INFO
25452 "%s:%d ioremap_change_attr failed %s "
25453 "for %Lx-%Lx\n",
25454 - current->comm, current->pid,
25455 + current->comm, task_pid_nr(current),
25456 cattr_name(flags),
25457 base, (unsigned long long)(base + size));
25458 return -EINVAL;
25459 @@ -593,7 +593,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25460 if (want_flags != flags) {
25461 printk(KERN_WARNING
25462 "%s:%d map pfn RAM range req %s for %Lx-%Lx, got %s\n",
25463 - current->comm, current->pid,
25464 + current->comm, task_pid_nr(current),
25465 cattr_name(want_flags),
25466 (unsigned long long)paddr,
25467 (unsigned long long)(paddr + size),
25468 @@ -615,7 +615,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25469 free_memtype(paddr, paddr + size);
25470 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25471 " for %Lx-%Lx, got %s\n",
25472 - current->comm, current->pid,
25473 + current->comm, task_pid_nr(current),
25474 cattr_name(want_flags),
25475 (unsigned long long)paddr,
25476 (unsigned long long)(paddr + size),
25477 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25478 index 9f0614d..92ae64a 100644
25479 --- a/arch/x86/mm/pf_in.c
25480 +++ b/arch/x86/mm/pf_in.c
25481 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25482 int i;
25483 enum reason_type rv = OTHERS;
25484
25485 - p = (unsigned char *)ins_addr;
25486 + p = (unsigned char *)ktla_ktva(ins_addr);
25487 p += skip_prefix(p, &prf);
25488 p += get_opcode(p, &opcode);
25489
25490 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25491 struct prefix_bits prf;
25492 int i;
25493
25494 - p = (unsigned char *)ins_addr;
25495 + p = (unsigned char *)ktla_ktva(ins_addr);
25496 p += skip_prefix(p, &prf);
25497 p += get_opcode(p, &opcode);
25498
25499 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25500 struct prefix_bits prf;
25501 int i;
25502
25503 - p = (unsigned char *)ins_addr;
25504 + p = (unsigned char *)ktla_ktva(ins_addr);
25505 p += skip_prefix(p, &prf);
25506 p += get_opcode(p, &opcode);
25507
25508 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25509 struct prefix_bits prf;
25510 int i;
25511
25512 - p = (unsigned char *)ins_addr;
25513 + p = (unsigned char *)ktla_ktva(ins_addr);
25514 p += skip_prefix(p, &prf);
25515 p += get_opcode(p, &opcode);
25516 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25517 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25518 struct prefix_bits prf;
25519 int i;
25520
25521 - p = (unsigned char *)ins_addr;
25522 + p = (unsigned char *)ktla_ktva(ins_addr);
25523 p += skip_prefix(p, &prf);
25524 p += get_opcode(p, &opcode);
25525 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25526 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25527 index 8573b83..4f3ed7e 100644
25528 --- a/arch/x86/mm/pgtable.c
25529 +++ b/arch/x86/mm/pgtable.c
25530 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25531 list_del(&page->lru);
25532 }
25533
25534 -#define UNSHARED_PTRS_PER_PGD \
25535 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25536 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25537 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25538
25539 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25540 +{
25541 + unsigned int count = USER_PGD_PTRS;
25542
25543 + while (count--)
25544 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25545 +}
25546 +#endif
25547 +
25548 +#ifdef CONFIG_PAX_PER_CPU_PGD
25549 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25550 +{
25551 + unsigned int count = USER_PGD_PTRS;
25552 +
25553 + while (count--) {
25554 + pgd_t pgd;
25555 +
25556 +#ifdef CONFIG_X86_64
25557 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25558 +#else
25559 + pgd = *src++;
25560 +#endif
25561 +
25562 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25563 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25564 +#endif
25565 +
25566 + *dst++ = pgd;
25567 + }
25568 +
25569 +}
25570 +#endif
25571 +
25572 +#ifdef CONFIG_X86_64
25573 +#define pxd_t pud_t
25574 +#define pyd_t pgd_t
25575 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25576 +#define pxd_free(mm, pud) pud_free((mm), (pud))
25577 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25578 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
25579 +#define PYD_SIZE PGDIR_SIZE
25580 +#else
25581 +#define pxd_t pmd_t
25582 +#define pyd_t pud_t
25583 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25584 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
25585 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25586 +#define pyd_offset(mm, address) pud_offset((mm), (address))
25587 +#define PYD_SIZE PUD_SIZE
25588 +#endif
25589 +
25590 +#ifdef CONFIG_PAX_PER_CPU_PGD
25591 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25592 +static inline void pgd_dtor(pgd_t *pgd) {}
25593 +#else
25594 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25595 {
25596 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25597 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25598 pgd_list_del(pgd);
25599 spin_unlock(&pgd_lock);
25600 }
25601 +#endif
25602
25603 /*
25604 * List of all pgd's needed for non-PAE so it can invalidate entries
25605 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25606 * -- wli
25607 */
25608
25609 -#ifdef CONFIG_X86_PAE
25610 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25611 /*
25612 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25613 * updating the top-level pagetable entries to guarantee the
25614 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25615 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25616 * and initialize the kernel pmds here.
25617 */
25618 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25619 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25620
25621 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25622 {
25623 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25624 */
25625 flush_tlb_mm(mm);
25626 }
25627 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25628 +#define PREALLOCATED_PXDS USER_PGD_PTRS
25629 #else /* !CONFIG_X86_PAE */
25630
25631 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25632 -#define PREALLOCATED_PMDS 0
25633 +#define PREALLOCATED_PXDS 0
25634
25635 #endif /* CONFIG_X86_PAE */
25636
25637 -static void free_pmds(pmd_t *pmds[])
25638 +static void free_pxds(pxd_t *pxds[])
25639 {
25640 int i;
25641
25642 - for(i = 0; i < PREALLOCATED_PMDS; i++)
25643 - if (pmds[i])
25644 - free_page((unsigned long)pmds[i]);
25645 + for(i = 0; i < PREALLOCATED_PXDS; i++)
25646 + if (pxds[i])
25647 + free_page((unsigned long)pxds[i]);
25648 }
25649
25650 -static int preallocate_pmds(pmd_t *pmds[])
25651 +static int preallocate_pxds(pxd_t *pxds[])
25652 {
25653 int i;
25654 bool failed = false;
25655
25656 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25657 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25658 - if (pmd == NULL)
25659 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25660 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25661 + if (pxd == NULL)
25662 failed = true;
25663 - pmds[i] = pmd;
25664 + pxds[i] = pxd;
25665 }
25666
25667 if (failed) {
25668 - free_pmds(pmds);
25669 + free_pxds(pxds);
25670 return -ENOMEM;
25671 }
25672
25673 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25674 * preallocate which never got a corresponding vma will need to be
25675 * freed manually.
25676 */
25677 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25678 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25679 {
25680 int i;
25681
25682 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25683 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25684 pgd_t pgd = pgdp[i];
25685
25686 if (pgd_val(pgd) != 0) {
25687 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25688 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25689
25690 - pgdp[i] = native_make_pgd(0);
25691 + set_pgd(pgdp + i, native_make_pgd(0));
25692
25693 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25694 - pmd_free(mm, pmd);
25695 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25696 + pxd_free(mm, pxd);
25697 }
25698 }
25699 }
25700
25701 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25702 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25703 {
25704 - pud_t *pud;
25705 + pyd_t *pyd;
25706 unsigned long addr;
25707 int i;
25708
25709 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25710 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25711 return;
25712
25713 - pud = pud_offset(pgd, 0);
25714 +#ifdef CONFIG_X86_64
25715 + pyd = pyd_offset(mm, 0L);
25716 +#else
25717 + pyd = pyd_offset(pgd, 0L);
25718 +#endif
25719
25720 - for (addr = i = 0; i < PREALLOCATED_PMDS;
25721 - i++, pud++, addr += PUD_SIZE) {
25722 - pmd_t *pmd = pmds[i];
25723 + for (addr = i = 0; i < PREALLOCATED_PXDS;
25724 + i++, pyd++, addr += PYD_SIZE) {
25725 + pxd_t *pxd = pxds[i];
25726
25727 if (i >= KERNEL_PGD_BOUNDARY)
25728 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25729 - sizeof(pmd_t) * PTRS_PER_PMD);
25730 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25731 + sizeof(pxd_t) * PTRS_PER_PMD);
25732
25733 - pud_populate(mm, pud, pmd);
25734 + pyd_populate(mm, pyd, pxd);
25735 }
25736 }
25737
25738 pgd_t *pgd_alloc(struct mm_struct *mm)
25739 {
25740 pgd_t *pgd;
25741 - pmd_t *pmds[PREALLOCATED_PMDS];
25742 + pxd_t *pxds[PREALLOCATED_PXDS];
25743
25744 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25745
25746 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25747
25748 mm->pgd = pgd;
25749
25750 - if (preallocate_pmds(pmds) != 0)
25751 + if (preallocate_pxds(pxds) != 0)
25752 goto out_free_pgd;
25753
25754 if (paravirt_pgd_alloc(mm) != 0)
25755 - goto out_free_pmds;
25756 + goto out_free_pxds;
25757
25758 /*
25759 * Make sure that pre-populating the pmds is atomic with
25760 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25761 spin_lock(&pgd_lock);
25762
25763 pgd_ctor(mm, pgd);
25764 - pgd_prepopulate_pmd(mm, pgd, pmds);
25765 + pgd_prepopulate_pxd(mm, pgd, pxds);
25766
25767 spin_unlock(&pgd_lock);
25768
25769 return pgd;
25770
25771 -out_free_pmds:
25772 - free_pmds(pmds);
25773 +out_free_pxds:
25774 + free_pxds(pxds);
25775 out_free_pgd:
25776 free_page((unsigned long)pgd);
25777 out:
25778 @@ -295,7 +356,7 @@ out:
25779
25780 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25781 {
25782 - pgd_mop_up_pmds(mm, pgd);
25783 + pgd_mop_up_pxds(mm, pgd);
25784 pgd_dtor(pgd);
25785 paravirt_pgd_free(mm, pgd);
25786 free_page((unsigned long)pgd);
25787 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25788 index a69bcb8..19068ab 100644
25789 --- a/arch/x86/mm/pgtable_32.c
25790 +++ b/arch/x86/mm/pgtable_32.c
25791 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25792 return;
25793 }
25794 pte = pte_offset_kernel(pmd, vaddr);
25795 +
25796 + pax_open_kernel();
25797 if (pte_val(pteval))
25798 set_pte_at(&init_mm, vaddr, pte, pteval);
25799 else
25800 pte_clear(&init_mm, vaddr, pte);
25801 + pax_close_kernel();
25802
25803 /*
25804 * It's enough to flush this one mapping.
25805 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25806 index 410531d..0f16030 100644
25807 --- a/arch/x86/mm/setup_nx.c
25808 +++ b/arch/x86/mm/setup_nx.c
25809 @@ -5,8 +5,10 @@
25810 #include <asm/pgtable.h>
25811 #include <asm/proto.h>
25812
25813 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25814 static int disable_nx __cpuinitdata;
25815
25816 +#ifndef CONFIG_PAX_PAGEEXEC
25817 /*
25818 * noexec = on|off
25819 *
25820 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25821 return 0;
25822 }
25823 early_param("noexec", noexec_setup);
25824 +#endif
25825 +
25826 +#endif
25827
25828 void __cpuinit x86_configure_nx(void)
25829 {
25830 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25831 if (cpu_has_nx && !disable_nx)
25832 __supported_pte_mask |= _PAGE_NX;
25833 else
25834 +#endif
25835 __supported_pte_mask &= ~_PAGE_NX;
25836 }
25837
25838 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25839 index d6c0418..06a0ad5 100644
25840 --- a/arch/x86/mm/tlb.c
25841 +++ b/arch/x86/mm/tlb.c
25842 @@ -65,7 +65,11 @@ void leave_mm(int cpu)
25843 BUG();
25844 cpumask_clear_cpu(cpu,
25845 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
25846 +
25847 +#ifndef CONFIG_PAX_PER_CPU_PGD
25848 load_cr3(swapper_pg_dir);
25849 +#endif
25850 +
25851 }
25852 EXPORT_SYMBOL_GPL(leave_mm);
25853
25854 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25855 index 877b9a1..a8ecf42 100644
25856 --- a/arch/x86/net/bpf_jit.S
25857 +++ b/arch/x86/net/bpf_jit.S
25858 @@ -9,6 +9,7 @@
25859 */
25860 #include <linux/linkage.h>
25861 #include <asm/dwarf2.h>
25862 +#include <asm/alternative-asm.h>
25863
25864 /*
25865 * Calling convention :
25866 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
25867 jle bpf_slow_path_word
25868 mov (SKBDATA,%rsi),%eax
25869 bswap %eax /* ntohl() */
25870 + pax_force_retaddr
25871 ret
25872
25873 sk_load_half:
25874 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
25875 jle bpf_slow_path_half
25876 movzwl (SKBDATA,%rsi),%eax
25877 rol $8,%ax # ntohs()
25878 + pax_force_retaddr
25879 ret
25880
25881 sk_load_byte:
25882 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
25883 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25884 jle bpf_slow_path_byte
25885 movzbl (SKBDATA,%rsi),%eax
25886 + pax_force_retaddr
25887 ret
25888
25889 /**
25890 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
25891 movzbl (SKBDATA,%rsi),%ebx
25892 and $15,%bl
25893 shl $2,%bl
25894 + pax_force_retaddr
25895 ret
25896
25897 /* rsi contains offset and can be scratched */
25898 @@ -109,6 +114,7 @@ bpf_slow_path_word:
25899 js bpf_error
25900 mov -12(%rbp),%eax
25901 bswap %eax
25902 + pax_force_retaddr
25903 ret
25904
25905 bpf_slow_path_half:
25906 @@ -117,12 +123,14 @@ bpf_slow_path_half:
25907 mov -12(%rbp),%ax
25908 rol $8,%ax
25909 movzwl %ax,%eax
25910 + pax_force_retaddr
25911 ret
25912
25913 bpf_slow_path_byte:
25914 bpf_slow_path_common(1)
25915 js bpf_error
25916 movzbl -12(%rbp),%eax
25917 + pax_force_retaddr
25918 ret
25919
25920 bpf_slow_path_byte_msh:
25921 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
25922 and $15,%al
25923 shl $2,%al
25924 xchg %eax,%ebx
25925 + pax_force_retaddr
25926 ret
25927
25928 #define sk_negative_common(SIZE) \
25929 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
25930 sk_negative_common(4)
25931 mov (%rax), %eax
25932 bswap %eax
25933 + pax_force_retaddr
25934 ret
25935
25936 bpf_slow_path_half_neg:
25937 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
25938 mov (%rax),%ax
25939 rol $8,%ax
25940 movzwl %ax,%eax
25941 + pax_force_retaddr
25942 ret
25943
25944 bpf_slow_path_byte_neg:
25945 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
25946 .globl sk_load_byte_negative_offset
25947 sk_negative_common(1)
25948 movzbl (%rax), %eax
25949 + pax_force_retaddr
25950 ret
25951
25952 bpf_slow_path_byte_msh_neg:
25953 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
25954 and $15,%al
25955 shl $2,%al
25956 xchg %eax,%ebx
25957 + pax_force_retaddr
25958 ret
25959
25960 bpf_error:
25961 @@ -197,4 +210,5 @@ bpf_error:
25962 xor %eax,%eax
25963 mov -8(%rbp),%rbx
25964 leaveq
25965 + pax_force_retaddr
25966 ret
25967 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
25968 index 0597f95..a12c36e 100644
25969 --- a/arch/x86/net/bpf_jit_comp.c
25970 +++ b/arch/x86/net/bpf_jit_comp.c
25971 @@ -120,6 +120,11 @@ static inline void bpf_flush_icache(void *start, void *end)
25972 set_fs(old_fs);
25973 }
25974
25975 +struct bpf_jit_work {
25976 + struct work_struct work;
25977 + void *image;
25978 +};
25979 +
25980 #define CHOOSE_LOAD_FUNC(K, func) \
25981 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
25982
25983 @@ -146,6 +151,10 @@ void bpf_jit_compile(struct sk_filter *fp)
25984 if (addrs == NULL)
25985 return;
25986
25987 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
25988 + if (!fp->work)
25989 + goto out;
25990 +
25991 /* Before first pass, make a rough estimation of addrs[]
25992 * each bpf instruction is translated to less than 64 bytes
25993 */
25994 @@ -589,17 +598,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25995 break;
25996 default:
25997 /* hmm, too complex filter, give up with jit compiler */
25998 - goto out;
25999 + goto error;
26000 }
26001 ilen = prog - temp;
26002 if (image) {
26003 if (unlikely(proglen + ilen > oldproglen)) {
26004 pr_err("bpb_jit_compile fatal error\n");
26005 - kfree(addrs);
26006 - module_free(NULL, image);
26007 - return;
26008 + module_free_exec(NULL, image);
26009 + goto error;
26010 }
26011 + pax_open_kernel();
26012 memcpy(image + proglen, temp, ilen);
26013 + pax_close_kernel();
26014 }
26015 proglen += ilen;
26016 addrs[i] = proglen;
26017 @@ -620,11 +630,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26018 break;
26019 }
26020 if (proglen == oldproglen) {
26021 - image = module_alloc(max_t(unsigned int,
26022 - proglen,
26023 - sizeof(struct work_struct)));
26024 + image = module_alloc_exec(proglen);
26025 if (!image)
26026 - goto out;
26027 + goto error;
26028 }
26029 oldproglen = proglen;
26030 }
26031 @@ -640,7 +648,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26032 bpf_flush_icache(image, image + proglen);
26033
26034 fp->bpf_func = (void *)image;
26035 - }
26036 + } else
26037 +error:
26038 + kfree(fp->work);
26039 +
26040 out:
26041 kfree(addrs);
26042 return;
26043 @@ -648,18 +659,20 @@ out:
26044
26045 static void jit_free_defer(struct work_struct *arg)
26046 {
26047 - module_free(NULL, arg);
26048 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
26049 + kfree(arg);
26050 }
26051
26052 /* run from softirq, we must use a work_struct to call
26053 - * module_free() from process context
26054 + * module_free_exec() from process context
26055 */
26056 void bpf_jit_free(struct sk_filter *fp)
26057 {
26058 if (fp->bpf_func != sk_run_filter) {
26059 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
26060 + struct work_struct *work = &fp->work->work;
26061
26062 INIT_WORK(work, jit_free_defer);
26063 + fp->work->image = fp->bpf_func;
26064 schedule_work(work);
26065 }
26066 }
26067 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26068 index d6aa6e8..266395a 100644
26069 --- a/arch/x86/oprofile/backtrace.c
26070 +++ b/arch/x86/oprofile/backtrace.c
26071 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
26072 struct stack_frame_ia32 *fp;
26073 unsigned long bytes;
26074
26075 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26076 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26077 if (bytes != sizeof(bufhead))
26078 return NULL;
26079
26080 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26081 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26082
26083 oprofile_add_trace(bufhead[0].return_address);
26084
26085 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26086 struct stack_frame bufhead[2];
26087 unsigned long bytes;
26088
26089 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26090 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26091 if (bytes != sizeof(bufhead))
26092 return NULL;
26093
26094 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26095 {
26096 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26097
26098 - if (!user_mode_vm(regs)) {
26099 + if (!user_mode(regs)) {
26100 unsigned long stack = kernel_stack_pointer(regs);
26101 if (depth)
26102 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26103 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26104 index 140942f..8a5cc55 100644
26105 --- a/arch/x86/pci/mrst.c
26106 +++ b/arch/x86/pci/mrst.c
26107 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
26108 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
26109 pci_mmcfg_late_init();
26110 pcibios_enable_irq = mrst_pci_irq_enable;
26111 - pci_root_ops = pci_mrst_ops;
26112 + pax_open_kernel();
26113 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26114 + pax_close_kernel();
26115 pci_soc_mode = 1;
26116 /* Continue with standard init */
26117 return 1;
26118 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26119 index da8fe05..7ee6704 100644
26120 --- a/arch/x86/pci/pcbios.c
26121 +++ b/arch/x86/pci/pcbios.c
26122 @@ -79,50 +79,93 @@ union bios32 {
26123 static struct {
26124 unsigned long address;
26125 unsigned short segment;
26126 -} bios32_indirect = { 0, __KERNEL_CS };
26127 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26128
26129 /*
26130 * Returns the entry point for the given service, NULL on error
26131 */
26132
26133 -static unsigned long bios32_service(unsigned long service)
26134 +static unsigned long __devinit bios32_service(unsigned long service)
26135 {
26136 unsigned char return_code; /* %al */
26137 unsigned long address; /* %ebx */
26138 unsigned long length; /* %ecx */
26139 unsigned long entry; /* %edx */
26140 unsigned long flags;
26141 + struct desc_struct d, *gdt;
26142
26143 local_irq_save(flags);
26144 - __asm__("lcall *(%%edi); cld"
26145 +
26146 + gdt = get_cpu_gdt_table(smp_processor_id());
26147 +
26148 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26149 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26150 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26151 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26152 +
26153 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26154 : "=a" (return_code),
26155 "=b" (address),
26156 "=c" (length),
26157 "=d" (entry)
26158 : "0" (service),
26159 "1" (0),
26160 - "D" (&bios32_indirect));
26161 + "D" (&bios32_indirect),
26162 + "r"(__PCIBIOS_DS)
26163 + : "memory");
26164 +
26165 + pax_open_kernel();
26166 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26167 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26168 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26169 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26170 + pax_close_kernel();
26171 +
26172 local_irq_restore(flags);
26173
26174 switch (return_code) {
26175 - case 0:
26176 - return address + entry;
26177 - case 0x80: /* Not present */
26178 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26179 - return 0;
26180 - default: /* Shouldn't happen */
26181 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26182 - service, return_code);
26183 + case 0: {
26184 + int cpu;
26185 + unsigned char flags;
26186 +
26187 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26188 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26189 + printk(KERN_WARNING "bios32_service: not valid\n");
26190 return 0;
26191 + }
26192 + address = address + PAGE_OFFSET;
26193 + length += 16UL; /* some BIOSs underreport this... */
26194 + flags = 4;
26195 + if (length >= 64*1024*1024) {
26196 + length >>= PAGE_SHIFT;
26197 + flags |= 8;
26198 + }
26199 +
26200 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26201 + gdt = get_cpu_gdt_table(cpu);
26202 + pack_descriptor(&d, address, length, 0x9b, flags);
26203 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26204 + pack_descriptor(&d, address, length, 0x93, flags);
26205 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26206 + }
26207 + return entry;
26208 + }
26209 + case 0x80: /* Not present */
26210 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26211 + return 0;
26212 + default: /* Shouldn't happen */
26213 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26214 + service, return_code);
26215 + return 0;
26216 }
26217 }
26218
26219 static struct {
26220 unsigned long address;
26221 unsigned short segment;
26222 -} pci_indirect = { 0, __KERNEL_CS };
26223 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26224
26225 -static int pci_bios_present;
26226 +static int pci_bios_present __read_only;
26227
26228 static int __devinit check_pcibios(void)
26229 {
26230 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26231 unsigned long flags, pcibios_entry;
26232
26233 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26234 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26235 + pci_indirect.address = pcibios_entry;
26236
26237 local_irq_save(flags);
26238 - __asm__(
26239 - "lcall *(%%edi); cld\n\t"
26240 + __asm__("movw %w6, %%ds\n\t"
26241 + "lcall *%%ss:(%%edi); cld\n\t"
26242 + "push %%ss\n\t"
26243 + "pop %%ds\n\t"
26244 "jc 1f\n\t"
26245 "xor %%ah, %%ah\n"
26246 "1:"
26247 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26248 "=b" (ebx),
26249 "=c" (ecx)
26250 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26251 - "D" (&pci_indirect)
26252 + "D" (&pci_indirect),
26253 + "r" (__PCIBIOS_DS)
26254 : "memory");
26255 local_irq_restore(flags);
26256
26257 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26258
26259 switch (len) {
26260 case 1:
26261 - __asm__("lcall *(%%esi); cld\n\t"
26262 + __asm__("movw %w6, %%ds\n\t"
26263 + "lcall *%%ss:(%%esi); cld\n\t"
26264 + "push %%ss\n\t"
26265 + "pop %%ds\n\t"
26266 "jc 1f\n\t"
26267 "xor %%ah, %%ah\n"
26268 "1:"
26269 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26270 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26271 "b" (bx),
26272 "D" ((long)reg),
26273 - "S" (&pci_indirect));
26274 + "S" (&pci_indirect),
26275 + "r" (__PCIBIOS_DS));
26276 /*
26277 * Zero-extend the result beyond 8 bits, do not trust the
26278 * BIOS having done it:
26279 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26280 *value &= 0xff;
26281 break;
26282 case 2:
26283 - __asm__("lcall *(%%esi); cld\n\t"
26284 + __asm__("movw %w6, %%ds\n\t"
26285 + "lcall *%%ss:(%%esi); cld\n\t"
26286 + "push %%ss\n\t"
26287 + "pop %%ds\n\t"
26288 "jc 1f\n\t"
26289 "xor %%ah, %%ah\n"
26290 "1:"
26291 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26292 : "1" (PCIBIOS_READ_CONFIG_WORD),
26293 "b" (bx),
26294 "D" ((long)reg),
26295 - "S" (&pci_indirect));
26296 + "S" (&pci_indirect),
26297 + "r" (__PCIBIOS_DS));
26298 /*
26299 * Zero-extend the result beyond 16 bits, do not trust the
26300 * BIOS having done it:
26301 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26302 *value &= 0xffff;
26303 break;
26304 case 4:
26305 - __asm__("lcall *(%%esi); cld\n\t"
26306 + __asm__("movw %w6, %%ds\n\t"
26307 + "lcall *%%ss:(%%esi); cld\n\t"
26308 + "push %%ss\n\t"
26309 + "pop %%ds\n\t"
26310 "jc 1f\n\t"
26311 "xor %%ah, %%ah\n"
26312 "1:"
26313 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26314 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26315 "b" (bx),
26316 "D" ((long)reg),
26317 - "S" (&pci_indirect));
26318 + "S" (&pci_indirect),
26319 + "r" (__PCIBIOS_DS));
26320 break;
26321 }
26322
26323 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26324
26325 switch (len) {
26326 case 1:
26327 - __asm__("lcall *(%%esi); cld\n\t"
26328 + __asm__("movw %w6, %%ds\n\t"
26329 + "lcall *%%ss:(%%esi); cld\n\t"
26330 + "push %%ss\n\t"
26331 + "pop %%ds\n\t"
26332 "jc 1f\n\t"
26333 "xor %%ah, %%ah\n"
26334 "1:"
26335 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26336 "c" (value),
26337 "b" (bx),
26338 "D" ((long)reg),
26339 - "S" (&pci_indirect));
26340 + "S" (&pci_indirect),
26341 + "r" (__PCIBIOS_DS));
26342 break;
26343 case 2:
26344 - __asm__("lcall *(%%esi); cld\n\t"
26345 + __asm__("movw %w6, %%ds\n\t"
26346 + "lcall *%%ss:(%%esi); cld\n\t"
26347 + "push %%ss\n\t"
26348 + "pop %%ds\n\t"
26349 "jc 1f\n\t"
26350 "xor %%ah, %%ah\n"
26351 "1:"
26352 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26353 "c" (value),
26354 "b" (bx),
26355 "D" ((long)reg),
26356 - "S" (&pci_indirect));
26357 + "S" (&pci_indirect),
26358 + "r" (__PCIBIOS_DS));
26359 break;
26360 case 4:
26361 - __asm__("lcall *(%%esi); cld\n\t"
26362 + __asm__("movw %w6, %%ds\n\t"
26363 + "lcall *%%ss:(%%esi); cld\n\t"
26364 + "push %%ss\n\t"
26365 + "pop %%ds\n\t"
26366 "jc 1f\n\t"
26367 "xor %%ah, %%ah\n"
26368 "1:"
26369 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26370 "c" (value),
26371 "b" (bx),
26372 "D" ((long)reg),
26373 - "S" (&pci_indirect));
26374 + "S" (&pci_indirect),
26375 + "r" (__PCIBIOS_DS));
26376 break;
26377 }
26378
26379 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26380
26381 DBG("PCI: Fetching IRQ routing table... ");
26382 __asm__("push %%es\n\t"
26383 + "movw %w8, %%ds\n\t"
26384 "push %%ds\n\t"
26385 "pop %%es\n\t"
26386 - "lcall *(%%esi); cld\n\t"
26387 + "lcall *%%ss:(%%esi); cld\n\t"
26388 "pop %%es\n\t"
26389 + "push %%ss\n\t"
26390 + "pop %%ds\n"
26391 "jc 1f\n\t"
26392 "xor %%ah, %%ah\n"
26393 "1:"
26394 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26395 "1" (0),
26396 "D" ((long) &opt),
26397 "S" (&pci_indirect),
26398 - "m" (opt)
26399 + "m" (opt),
26400 + "r" (__PCIBIOS_DS)
26401 : "memory");
26402 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26403 if (ret & 0xff00)
26404 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26405 {
26406 int ret;
26407
26408 - __asm__("lcall *(%%esi); cld\n\t"
26409 + __asm__("movw %w5, %%ds\n\t"
26410 + "lcall *%%ss:(%%esi); cld\n\t"
26411 + "push %%ss\n\t"
26412 + "pop %%ds\n"
26413 "jc 1f\n\t"
26414 "xor %%ah, %%ah\n"
26415 "1:"
26416 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26417 : "0" (PCIBIOS_SET_PCI_HW_INT),
26418 "b" ((dev->bus->number << 8) | dev->devfn),
26419 "c" ((irq << 8) | (pin + 10)),
26420 - "S" (&pci_indirect));
26421 + "S" (&pci_indirect),
26422 + "r" (__PCIBIOS_DS));
26423 return !(ret & 0xff00);
26424 }
26425 EXPORT_SYMBOL(pcibios_set_irq_routing);
26426 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26427 index 40e4469..1ab536e 100644
26428 --- a/arch/x86/platform/efi/efi_32.c
26429 +++ b/arch/x86/platform/efi/efi_32.c
26430 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26431 {
26432 struct desc_ptr gdt_descr;
26433
26434 +#ifdef CONFIG_PAX_KERNEXEC
26435 + struct desc_struct d;
26436 +#endif
26437 +
26438 local_irq_save(efi_rt_eflags);
26439
26440 load_cr3(initial_page_table);
26441 __flush_tlb_all();
26442
26443 +#ifdef CONFIG_PAX_KERNEXEC
26444 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26445 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26446 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26447 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26448 +#endif
26449 +
26450 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26451 gdt_descr.size = GDT_SIZE - 1;
26452 load_gdt(&gdt_descr);
26453 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26454 {
26455 struct desc_ptr gdt_descr;
26456
26457 +#ifdef CONFIG_PAX_KERNEXEC
26458 + struct desc_struct d;
26459 +
26460 + memset(&d, 0, sizeof d);
26461 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26462 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26463 +#endif
26464 +
26465 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26466 gdt_descr.size = GDT_SIZE - 1;
26467 load_gdt(&gdt_descr);
26468 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26469 index fbe66e6..c5c0dd2 100644
26470 --- a/arch/x86/platform/efi/efi_stub_32.S
26471 +++ b/arch/x86/platform/efi/efi_stub_32.S
26472 @@ -6,7 +6,9 @@
26473 */
26474
26475 #include <linux/linkage.h>
26476 +#include <linux/init.h>
26477 #include <asm/page_types.h>
26478 +#include <asm/segment.h>
26479
26480 /*
26481 * efi_call_phys(void *, ...) is a function with variable parameters.
26482 @@ -20,7 +22,7 @@
26483 * service functions will comply with gcc calling convention, too.
26484 */
26485
26486 -.text
26487 +__INIT
26488 ENTRY(efi_call_phys)
26489 /*
26490 * 0. The function can only be called in Linux kernel. So CS has been
26491 @@ -36,9 +38,11 @@ ENTRY(efi_call_phys)
26492 * The mapping of lower virtual memory has been created in prelog and
26493 * epilog.
26494 */
26495 - movl $1f, %edx
26496 - subl $__PAGE_OFFSET, %edx
26497 - jmp *%edx
26498 + movl $(__KERNEXEC_EFI_DS), %edx
26499 + mov %edx, %ds
26500 + mov %edx, %es
26501 + mov %edx, %ss
26502 + ljmp $(__KERNEXEC_EFI_CS),$1f-__PAGE_OFFSET
26503 1:
26504
26505 /*
26506 @@ -47,14 +51,8 @@ ENTRY(efi_call_phys)
26507 * parameter 2, ..., param n. To make things easy, we save the return
26508 * address of efi_call_phys in a global variable.
26509 */
26510 - popl %edx
26511 - movl %edx, saved_return_addr
26512 - /* get the function pointer into ECX*/
26513 - popl %ecx
26514 - movl %ecx, efi_rt_function_ptr
26515 - movl $2f, %edx
26516 - subl $__PAGE_OFFSET, %edx
26517 - pushl %edx
26518 + popl (saved_return_addr)
26519 + popl (efi_rt_function_ptr)
26520
26521 /*
26522 * 3. Clear PG bit in %CR0.
26523 @@ -73,9 +71,8 @@ ENTRY(efi_call_phys)
26524 /*
26525 * 5. Call the physical function.
26526 */
26527 - jmp *%ecx
26528 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
26529
26530 -2:
26531 /*
26532 * 6. After EFI runtime service returns, control will return to
26533 * following instruction. We'd better readjust stack pointer first.
26534 @@ -88,35 +85,32 @@ ENTRY(efi_call_phys)
26535 movl %cr0, %edx
26536 orl $0x80000000, %edx
26537 movl %edx, %cr0
26538 - jmp 1f
26539 -1:
26540 +
26541 /*
26542 * 8. Now restore the virtual mode from flat mode by
26543 * adding EIP with PAGE_OFFSET.
26544 */
26545 - movl $1f, %edx
26546 - jmp *%edx
26547 + ljmp $(__KERNEL_CS),$1f+__PAGE_OFFSET
26548 1:
26549 + movl $(__KERNEL_DS), %edx
26550 + mov %edx, %ds
26551 + mov %edx, %es
26552 + mov %edx, %ss
26553
26554 /*
26555 * 9. Balance the stack. And because EAX contain the return value,
26556 * we'd better not clobber it.
26557 */
26558 - leal efi_rt_function_ptr, %edx
26559 - movl (%edx), %ecx
26560 - pushl %ecx
26561 + pushl (efi_rt_function_ptr)
26562
26563 /*
26564 - * 10. Push the saved return address onto the stack and return.
26565 + * 10. Return to the saved return address.
26566 */
26567 - leal saved_return_addr, %edx
26568 - movl (%edx), %ecx
26569 - pushl %ecx
26570 - ret
26571 + jmpl *(saved_return_addr)
26572 ENDPROC(efi_call_phys)
26573 .previous
26574
26575 -.data
26576 +__INITDATA
26577 saved_return_addr:
26578 .long 0
26579 efi_rt_function_ptr:
26580 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26581 index 4c07cca..2c8427d 100644
26582 --- a/arch/x86/platform/efi/efi_stub_64.S
26583 +++ b/arch/x86/platform/efi/efi_stub_64.S
26584 @@ -7,6 +7,7 @@
26585 */
26586
26587 #include <linux/linkage.h>
26588 +#include <asm/alternative-asm.h>
26589
26590 #define SAVE_XMM \
26591 mov %rsp, %rax; \
26592 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
26593 call *%rdi
26594 addq $32, %rsp
26595 RESTORE_XMM
26596 + pax_force_retaddr 0, 1
26597 ret
26598 ENDPROC(efi_call0)
26599
26600 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
26601 call *%rdi
26602 addq $32, %rsp
26603 RESTORE_XMM
26604 + pax_force_retaddr 0, 1
26605 ret
26606 ENDPROC(efi_call1)
26607
26608 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
26609 call *%rdi
26610 addq $32, %rsp
26611 RESTORE_XMM
26612 + pax_force_retaddr 0, 1
26613 ret
26614 ENDPROC(efi_call2)
26615
26616 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
26617 call *%rdi
26618 addq $32, %rsp
26619 RESTORE_XMM
26620 + pax_force_retaddr 0, 1
26621 ret
26622 ENDPROC(efi_call3)
26623
26624 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
26625 call *%rdi
26626 addq $32, %rsp
26627 RESTORE_XMM
26628 + pax_force_retaddr 0, 1
26629 ret
26630 ENDPROC(efi_call4)
26631
26632 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
26633 call *%rdi
26634 addq $48, %rsp
26635 RESTORE_XMM
26636 + pax_force_retaddr 0, 1
26637 ret
26638 ENDPROC(efi_call5)
26639
26640 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
26641 call *%rdi
26642 addq $48, %rsp
26643 RESTORE_XMM
26644 + pax_force_retaddr 0, 1
26645 ret
26646 ENDPROC(efi_call6)
26647 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26648 index e31bcd8..f12dc46 100644
26649 --- a/arch/x86/platform/mrst/mrst.c
26650 +++ b/arch/x86/platform/mrst/mrst.c
26651 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26652 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26653 int sfi_mrtc_num;
26654
26655 -static void mrst_power_off(void)
26656 +static __noreturn void mrst_power_off(void)
26657 {
26658 + BUG();
26659 }
26660
26661 -static void mrst_reboot(void)
26662 +static __noreturn void mrst_reboot(void)
26663 {
26664 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26665 + BUG();
26666 }
26667
26668 /* parse all the mtimer info to a static mtimer array */
26669 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26670 index 218cdb1..fd55c08 100644
26671 --- a/arch/x86/power/cpu.c
26672 +++ b/arch/x86/power/cpu.c
26673 @@ -132,7 +132,7 @@ static void do_fpu_end(void)
26674 static void fix_processor_context(void)
26675 {
26676 int cpu = smp_processor_id();
26677 - struct tss_struct *t = &per_cpu(init_tss, cpu);
26678 + struct tss_struct *t = init_tss + cpu;
26679
26680 set_tss_desc(cpu, t); /*
26681 * This just modifies memory; should not be
26682 @@ -142,7 +142,9 @@ static void fix_processor_context(void)
26683 */
26684
26685 #ifdef CONFIG_X86_64
26686 + pax_open_kernel();
26687 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26688 + pax_close_kernel();
26689
26690 syscall_init(); /* This sets MSR_*STAR and related */
26691 #endif
26692 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
26693 index b685296..e00eb65 100644
26694 --- a/arch/x86/tools/relocs.c
26695 +++ b/arch/x86/tools/relocs.c
26696 @@ -12,10 +12,13 @@
26697 #include <regex.h>
26698 #include <tools/le_byteshift.h>
26699
26700 +#include "../../../include/generated/autoconf.h"
26701 +
26702 static void die(char *fmt, ...);
26703
26704 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
26705 static Elf32_Ehdr ehdr;
26706 +static Elf32_Phdr *phdr;
26707 static unsigned long reloc_count, reloc_idx;
26708 static unsigned long *relocs;
26709 static unsigned long reloc16_count, reloc16_idx;
26710 @@ -323,9 +326,39 @@ static void read_ehdr(FILE *fp)
26711 }
26712 }
26713
26714 +static void read_phdrs(FILE *fp)
26715 +{
26716 + unsigned int i;
26717 +
26718 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
26719 + if (!phdr) {
26720 + die("Unable to allocate %d program headers\n",
26721 + ehdr.e_phnum);
26722 + }
26723 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
26724 + die("Seek to %d failed: %s\n",
26725 + ehdr.e_phoff, strerror(errno));
26726 + }
26727 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
26728 + die("Cannot read ELF program headers: %s\n",
26729 + strerror(errno));
26730 + }
26731 + for(i = 0; i < ehdr.e_phnum; i++) {
26732 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
26733 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
26734 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
26735 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
26736 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
26737 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
26738 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
26739 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
26740 + }
26741 +
26742 +}
26743 +
26744 static void read_shdrs(FILE *fp)
26745 {
26746 - int i;
26747 + unsigned int i;
26748 Elf32_Shdr shdr;
26749
26750 secs = calloc(ehdr.e_shnum, sizeof(struct section));
26751 @@ -360,7 +393,7 @@ static void read_shdrs(FILE *fp)
26752
26753 static void read_strtabs(FILE *fp)
26754 {
26755 - int i;
26756 + unsigned int i;
26757 for (i = 0; i < ehdr.e_shnum; i++) {
26758 struct section *sec = &secs[i];
26759 if (sec->shdr.sh_type != SHT_STRTAB) {
26760 @@ -385,7 +418,7 @@ static void read_strtabs(FILE *fp)
26761
26762 static void read_symtabs(FILE *fp)
26763 {
26764 - int i,j;
26765 + unsigned int i,j;
26766 for (i = 0; i < ehdr.e_shnum; i++) {
26767 struct section *sec = &secs[i];
26768 if (sec->shdr.sh_type != SHT_SYMTAB) {
26769 @@ -418,7 +451,9 @@ static void read_symtabs(FILE *fp)
26770
26771 static void read_relocs(FILE *fp)
26772 {
26773 - int i,j;
26774 + unsigned int i,j;
26775 + uint32_t base;
26776 +
26777 for (i = 0; i < ehdr.e_shnum; i++) {
26778 struct section *sec = &secs[i];
26779 if (sec->shdr.sh_type != SHT_REL) {
26780 @@ -438,9 +473,22 @@ static void read_relocs(FILE *fp)
26781 die("Cannot read symbol table: %s\n",
26782 strerror(errno));
26783 }
26784 + base = 0;
26785 +
26786 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
26787 + for (j = 0; j < ehdr.e_phnum; j++) {
26788 + if (phdr[j].p_type != PT_LOAD )
26789 + continue;
26790 + if (secs[sec->shdr.sh_info].shdr.sh_offset < phdr[j].p_offset || secs[sec->shdr.sh_info].shdr.sh_offset >= phdr[j].p_offset + phdr[j].p_filesz)
26791 + continue;
26792 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
26793 + break;
26794 + }
26795 +#endif
26796 +
26797 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
26798 Elf32_Rel *rel = &sec->reltab[j];
26799 - rel->r_offset = elf32_to_cpu(rel->r_offset);
26800 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
26801 rel->r_info = elf32_to_cpu(rel->r_info);
26802 }
26803 }
26804 @@ -449,13 +497,13 @@ static void read_relocs(FILE *fp)
26805
26806 static void print_absolute_symbols(void)
26807 {
26808 - int i;
26809 + unsigned int i;
26810 printf("Absolute symbols\n");
26811 printf(" Num: Value Size Type Bind Visibility Name\n");
26812 for (i = 0; i < ehdr.e_shnum; i++) {
26813 struct section *sec = &secs[i];
26814 char *sym_strtab;
26815 - int j;
26816 + unsigned int j;
26817
26818 if (sec->shdr.sh_type != SHT_SYMTAB) {
26819 continue;
26820 @@ -482,14 +530,14 @@ static void print_absolute_symbols(void)
26821
26822 static void print_absolute_relocs(void)
26823 {
26824 - int i, printed = 0;
26825 + unsigned int i, printed = 0;
26826
26827 for (i = 0; i < ehdr.e_shnum; i++) {
26828 struct section *sec = &secs[i];
26829 struct section *sec_applies, *sec_symtab;
26830 char *sym_strtab;
26831 Elf32_Sym *sh_symtab;
26832 - int j;
26833 + unsigned int j;
26834 if (sec->shdr.sh_type != SHT_REL) {
26835 continue;
26836 }
26837 @@ -551,13 +599,13 @@ static void print_absolute_relocs(void)
26838 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26839 int use_real_mode)
26840 {
26841 - int i;
26842 + unsigned int i;
26843 /* Walk through the relocations */
26844 for (i = 0; i < ehdr.e_shnum; i++) {
26845 char *sym_strtab;
26846 Elf32_Sym *sh_symtab;
26847 struct section *sec_applies, *sec_symtab;
26848 - int j;
26849 + unsigned int j;
26850 struct section *sec = &secs[i];
26851
26852 if (sec->shdr.sh_type != SHT_REL) {
26853 @@ -581,6 +629,22 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26854 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
26855 r_type = ELF32_R_TYPE(rel->r_info);
26856
26857 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
26858 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
26859 + continue;
26860 +
26861 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
26862 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
26863 + if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
26864 + continue;
26865 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
26866 + continue;
26867 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
26868 + continue;
26869 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
26870 + continue;
26871 +#endif
26872 +
26873 shn_abs = sym->st_shndx == SHN_ABS;
26874
26875 switch (r_type) {
26876 @@ -674,7 +738,7 @@ static int write32(unsigned int v, FILE *f)
26877
26878 static void emit_relocs(int as_text, int use_real_mode)
26879 {
26880 - int i;
26881 + unsigned int i;
26882 /* Count how many relocations I have and allocate space for them. */
26883 reloc_count = 0;
26884 walk_relocs(count_reloc, use_real_mode);
26885 @@ -801,6 +865,7 @@ int main(int argc, char **argv)
26886 fname, strerror(errno));
26887 }
26888 read_ehdr(fp);
26889 + read_phdrs(fp);
26890 read_shdrs(fp);
26891 read_strtabs(fp);
26892 read_symtabs(fp);
26893 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
26894 index fd14be1..e3c79c0 100644
26895 --- a/arch/x86/vdso/Makefile
26896 +++ b/arch/x86/vdso/Makefile
26897 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
26898 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
26899 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
26900
26901 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26902 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26903 GCOV_PROFILE := n
26904
26905 #
26906 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
26907 index 66e6d93..587f435 100644
26908 --- a/arch/x86/vdso/vdso32-setup.c
26909 +++ b/arch/x86/vdso/vdso32-setup.c
26910 @@ -25,6 +25,7 @@
26911 #include <asm/tlbflush.h>
26912 #include <asm/vdso.h>
26913 #include <asm/proto.h>
26914 +#include <asm/mman.h>
26915
26916 enum {
26917 VDSO_DISABLED = 0,
26918 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
26919 void enable_sep_cpu(void)
26920 {
26921 int cpu = get_cpu();
26922 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26923 + struct tss_struct *tss = init_tss + cpu;
26924
26925 if (!boot_cpu_has(X86_FEATURE_SEP)) {
26926 put_cpu();
26927 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
26928 gate_vma.vm_start = FIXADDR_USER_START;
26929 gate_vma.vm_end = FIXADDR_USER_END;
26930 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
26931 - gate_vma.vm_page_prot = __P101;
26932 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
26933
26934 return 0;
26935 }
26936 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26937 if (compat)
26938 addr = VDSO_HIGH_BASE;
26939 else {
26940 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
26941 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
26942 if (IS_ERR_VALUE(addr)) {
26943 ret = addr;
26944 goto up_fail;
26945 }
26946 }
26947
26948 - current->mm->context.vdso = (void *)addr;
26949 + current->mm->context.vdso = addr;
26950
26951 if (compat_uses_vma || !compat) {
26952 /*
26953 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26954 }
26955
26956 current_thread_info()->sysenter_return =
26957 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26958 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26959
26960 up_fail:
26961 if (ret)
26962 - current->mm->context.vdso = NULL;
26963 + current->mm->context.vdso = 0;
26964
26965 up_write(&mm->mmap_sem);
26966
26967 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
26968
26969 const char *arch_vma_name(struct vm_area_struct *vma)
26970 {
26971 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26972 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26973 return "[vdso]";
26974 +
26975 +#ifdef CONFIG_PAX_SEGMEXEC
26976 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
26977 + return "[vdso]";
26978 +#endif
26979 +
26980 return NULL;
26981 }
26982
26983 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
26984 * Check to see if the corresponding task was created in compat vdso
26985 * mode.
26986 */
26987 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
26988 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
26989 return &gate_vma;
26990 return NULL;
26991 }
26992 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
26993 index 00aaf04..4a26505 100644
26994 --- a/arch/x86/vdso/vma.c
26995 +++ b/arch/x86/vdso/vma.c
26996 @@ -16,8 +16,6 @@
26997 #include <asm/vdso.h>
26998 #include <asm/page.h>
26999
27000 -unsigned int __read_mostly vdso_enabled = 1;
27001 -
27002 extern char vdso_start[], vdso_end[];
27003 extern unsigned short vdso_sync_cpuid;
27004
27005 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27006 * unaligned here as a result of stack start randomization.
27007 */
27008 addr = PAGE_ALIGN(addr);
27009 - addr = align_addr(addr, NULL, ALIGN_VDSO);
27010
27011 return addr;
27012 }
27013 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
27014 unsigned size)
27015 {
27016 struct mm_struct *mm = current->mm;
27017 - unsigned long addr;
27018 + unsigned long addr = 0;
27019 int ret;
27020
27021 - if (!vdso_enabled)
27022 - return 0;
27023 -
27024 down_write(&mm->mmap_sem);
27025 +
27026 +#ifdef CONFIG_PAX_RANDMMAP
27027 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27028 +#endif
27029 +
27030 addr = vdso_addr(mm->start_stack, size);
27031 + addr = align_addr(addr, NULL, ALIGN_VDSO);
27032 addr = get_unmapped_area(NULL, addr, size, 0, 0);
27033 if (IS_ERR_VALUE(addr)) {
27034 ret = addr;
27035 goto up_fail;
27036 }
27037
27038 - current->mm->context.vdso = (void *)addr;
27039 + mm->context.vdso = addr;
27040
27041 ret = install_special_mapping(mm, addr, size,
27042 VM_READ|VM_EXEC|
27043 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
27044 pages);
27045 - if (ret) {
27046 - current->mm->context.vdso = NULL;
27047 - goto up_fail;
27048 - }
27049 + if (ret)
27050 + mm->context.vdso = 0;
27051
27052 up_fail:
27053 up_write(&mm->mmap_sem);
27054 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27055 vdsox32_size);
27056 }
27057 #endif
27058 -
27059 -static __init int vdso_setup(char *s)
27060 -{
27061 - vdso_enabled = simple_strtoul(s, NULL, 0);
27062 - return 0;
27063 -}
27064 -__setup("vdso=", vdso_setup);
27065 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27066 index 40edfc3..b4d80ac 100644
27067 --- a/arch/x86/xen/enlighten.c
27068 +++ b/arch/x86/xen/enlighten.c
27069 @@ -95,8 +95,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27070
27071 struct shared_info xen_dummy_shared_info;
27072
27073 -void *xen_initial_gdt;
27074 -
27075 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27076 __read_mostly int xen_have_vector_callback;
27077 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27078 @@ -1165,30 +1163,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27079 #endif
27080 };
27081
27082 -static void xen_reboot(int reason)
27083 +static __noreturn void xen_reboot(int reason)
27084 {
27085 struct sched_shutdown r = { .reason = reason };
27086
27087 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27088 - BUG();
27089 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27090 + BUG();
27091 }
27092
27093 -static void xen_restart(char *msg)
27094 +static __noreturn void xen_restart(char *msg)
27095 {
27096 xen_reboot(SHUTDOWN_reboot);
27097 }
27098
27099 -static void xen_emergency_restart(void)
27100 +static __noreturn void xen_emergency_restart(void)
27101 {
27102 xen_reboot(SHUTDOWN_reboot);
27103 }
27104
27105 -static void xen_machine_halt(void)
27106 +static __noreturn void xen_machine_halt(void)
27107 {
27108 xen_reboot(SHUTDOWN_poweroff);
27109 }
27110
27111 -static void xen_machine_power_off(void)
27112 +static __noreturn void xen_machine_power_off(void)
27113 {
27114 if (pm_power_off)
27115 pm_power_off();
27116 @@ -1291,7 +1289,17 @@ asmlinkage void __init xen_start_kernel(void)
27117 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27118
27119 /* Work out if we support NX */
27120 - x86_configure_nx();
27121 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27122 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27123 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27124 + unsigned l, h;
27125 +
27126 + __supported_pte_mask |= _PAGE_NX;
27127 + rdmsr(MSR_EFER, l, h);
27128 + l |= EFER_NX;
27129 + wrmsr(MSR_EFER, l, h);
27130 + }
27131 +#endif
27132
27133 xen_setup_features();
27134
27135 @@ -1322,13 +1330,6 @@ asmlinkage void __init xen_start_kernel(void)
27136
27137 machine_ops = xen_machine_ops;
27138
27139 - /*
27140 - * The only reliable way to retain the initial address of the
27141 - * percpu gdt_page is to remember it here, so we can go and
27142 - * mark it RW later, when the initial percpu area is freed.
27143 - */
27144 - xen_initial_gdt = &per_cpu(gdt_page, 0);
27145 -
27146 xen_smp_init();
27147
27148 #ifdef CONFIG_ACPI_NUMA
27149 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27150 index 69f5857..0699dc5 100644
27151 --- a/arch/x86/xen/mmu.c
27152 +++ b/arch/x86/xen/mmu.c
27153 @@ -1738,6 +1738,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27154 convert_pfn_mfn(init_level4_pgt);
27155 convert_pfn_mfn(level3_ident_pgt);
27156 convert_pfn_mfn(level3_kernel_pgt);
27157 + convert_pfn_mfn(level3_vmalloc_start_pgt);
27158 + convert_pfn_mfn(level3_vmalloc_end_pgt);
27159 + convert_pfn_mfn(level3_vmemmap_pgt);
27160
27161 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27162 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27163 @@ -1756,7 +1759,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27164 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27165 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27166 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27167 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27168 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27169 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27170 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27171 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27172 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27173 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27174
27175 @@ -1964,6 +1971,7 @@ static void __init xen_post_allocator_init(void)
27176 pv_mmu_ops.set_pud = xen_set_pud;
27177 #if PAGETABLE_LEVELS == 4
27178 pv_mmu_ops.set_pgd = xen_set_pgd;
27179 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27180 #endif
27181
27182 /* This will work as long as patching hasn't happened yet
27183 @@ -2045,6 +2053,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27184 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27185 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27186 .set_pgd = xen_set_pgd_hyper,
27187 + .set_pgd_batched = xen_set_pgd_hyper,
27188
27189 .alloc_pud = xen_alloc_pmd_init,
27190 .release_pud = xen_release_pmd_init,
27191 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27192 index 0503c0c..ceb2d16 100644
27193 --- a/arch/x86/xen/smp.c
27194 +++ b/arch/x86/xen/smp.c
27195 @@ -215,11 +215,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27196 {
27197 BUG_ON(smp_processor_id() != 0);
27198 native_smp_prepare_boot_cpu();
27199 -
27200 - /* We've switched to the "real" per-cpu gdt, so make sure the
27201 - old memory can be recycled */
27202 - make_lowmem_page_readwrite(xen_initial_gdt);
27203 -
27204 xen_filter_cpu_maps();
27205 xen_setup_vcpu_info_placement();
27206 }
27207 @@ -296,12 +291,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27208 gdt = get_cpu_gdt_table(cpu);
27209
27210 ctxt->flags = VGCF_IN_KERNEL;
27211 - ctxt->user_regs.ds = __USER_DS;
27212 - ctxt->user_regs.es = __USER_DS;
27213 + ctxt->user_regs.ds = __KERNEL_DS;
27214 + ctxt->user_regs.es = __KERNEL_DS;
27215 ctxt->user_regs.ss = __KERNEL_DS;
27216 #ifdef CONFIG_X86_32
27217 ctxt->user_regs.fs = __KERNEL_PERCPU;
27218 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27219 + savesegment(gs, ctxt->user_regs.gs);
27220 #else
27221 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27222 #endif
27223 @@ -352,13 +347,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu)
27224 int rc;
27225
27226 per_cpu(current_task, cpu) = idle;
27227 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27228 #ifdef CONFIG_X86_32
27229 irq_ctx_init(cpu);
27230 #else
27231 clear_tsk_thread_flag(idle, TIF_FORK);
27232 - per_cpu(kernel_stack, cpu) =
27233 - (unsigned long)task_stack_page(idle) -
27234 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27235 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27236 #endif
27237 xen_setup_runstate_info(cpu);
27238 xen_setup_timer(cpu);
27239 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27240 index b040b0e..8cc4fe0 100644
27241 --- a/arch/x86/xen/xen-asm_32.S
27242 +++ b/arch/x86/xen/xen-asm_32.S
27243 @@ -83,14 +83,14 @@ ENTRY(xen_iret)
27244 ESP_OFFSET=4 # bytes pushed onto stack
27245
27246 /*
27247 - * Store vcpu_info pointer for easy access. Do it this way to
27248 - * avoid having to reload %fs
27249 + * Store vcpu_info pointer for easy access.
27250 */
27251 #ifdef CONFIG_SMP
27252 - GET_THREAD_INFO(%eax)
27253 - movl TI_cpu(%eax), %eax
27254 - movl __per_cpu_offset(,%eax,4), %eax
27255 - mov xen_vcpu(%eax), %eax
27256 + push %fs
27257 + mov $(__KERNEL_PERCPU), %eax
27258 + mov %eax, %fs
27259 + mov PER_CPU_VAR(xen_vcpu), %eax
27260 + pop %fs
27261 #else
27262 movl xen_vcpu, %eax
27263 #endif
27264 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27265 index aaa7291..3f77960 100644
27266 --- a/arch/x86/xen/xen-head.S
27267 +++ b/arch/x86/xen/xen-head.S
27268 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
27269 #ifdef CONFIG_X86_32
27270 mov %esi,xen_start_info
27271 mov $init_thread_union+THREAD_SIZE,%esp
27272 +#ifdef CONFIG_SMP
27273 + movl $cpu_gdt_table,%edi
27274 + movl $__per_cpu_load,%eax
27275 + movw %ax,__KERNEL_PERCPU + 2(%edi)
27276 + rorl $16,%eax
27277 + movb %al,__KERNEL_PERCPU + 4(%edi)
27278 + movb %ah,__KERNEL_PERCPU + 7(%edi)
27279 + movl $__per_cpu_end - 1,%eax
27280 + subl $__per_cpu_start,%eax
27281 + movw %ax,__KERNEL_PERCPU + 0(%edi)
27282 +#endif
27283 #else
27284 mov %rsi,xen_start_info
27285 mov $init_thread_union+THREAD_SIZE,%rsp
27286 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27287 index b095739..8c17bcd 100644
27288 --- a/arch/x86/xen/xen-ops.h
27289 +++ b/arch/x86/xen/xen-ops.h
27290 @@ -10,8 +10,6 @@
27291 extern const char xen_hypervisor_callback[];
27292 extern const char xen_failsafe_callback[];
27293
27294 -extern void *xen_initial_gdt;
27295 -
27296 struct trap_info;
27297 void xen_copy_trap_info(struct trap_info *traps);
27298
27299 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27300 index 525bd3d..ef888b1 100644
27301 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
27302 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27303 @@ -119,9 +119,9 @@
27304 ----------------------------------------------------------------------*/
27305
27306 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27307 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27308 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27309 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27310 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27311
27312 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27313 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27314 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27315 index 2f33760..835e50a 100644
27316 --- a/arch/xtensa/variants/fsf/include/variant/core.h
27317 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
27318 @@ -11,6 +11,7 @@
27319 #ifndef _XTENSA_CORE_H
27320 #define _XTENSA_CORE_H
27321
27322 +#include <linux/const.h>
27323
27324 /****************************************************************************
27325 Parameters Useful for Any Code, USER or PRIVILEGED
27326 @@ -112,9 +113,9 @@
27327 ----------------------------------------------------------------------*/
27328
27329 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27330 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27331 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27332 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27333 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27334
27335 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27336 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27337 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27338 index af00795..2bb8105 100644
27339 --- a/arch/xtensa/variants/s6000/include/variant/core.h
27340 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
27341 @@ -11,6 +11,7 @@
27342 #ifndef _XTENSA_CORE_CONFIGURATION_H
27343 #define _XTENSA_CORE_CONFIGURATION_H
27344
27345 +#include <linux/const.h>
27346
27347 /****************************************************************************
27348 Parameters Useful for Any Code, USER or PRIVILEGED
27349 @@ -118,9 +119,9 @@
27350 ----------------------------------------------------------------------*/
27351
27352 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27353 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27354 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27355 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27356 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27357
27358 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27359 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27360 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27361 index 58916af..9cb880b 100644
27362 --- a/block/blk-iopoll.c
27363 +++ b/block/blk-iopoll.c
27364 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27365 }
27366 EXPORT_SYMBOL(blk_iopoll_complete);
27367
27368 -static void blk_iopoll_softirq(struct softirq_action *h)
27369 +static void blk_iopoll_softirq(void)
27370 {
27371 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27372 int rearm = 0, budget = blk_iopoll_budget;
27373 diff --git a/block/blk-map.c b/block/blk-map.c
27374 index 623e1cd..ca1e109 100644
27375 --- a/block/blk-map.c
27376 +++ b/block/blk-map.c
27377 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27378 if (!len || !kbuf)
27379 return -EINVAL;
27380
27381 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27382 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27383 if (do_copy)
27384 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27385 else
27386 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27387 index 467c8de..4bddc6d 100644
27388 --- a/block/blk-softirq.c
27389 +++ b/block/blk-softirq.c
27390 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27391 * Softirq action handler - move entries to local list and loop over them
27392 * while passing them to the queue registered handler.
27393 */
27394 -static void blk_done_softirq(struct softirq_action *h)
27395 +static void blk_done_softirq(void)
27396 {
27397 struct list_head *cpu_list, local_list;
27398
27399 diff --git a/block/bsg.c b/block/bsg.c
27400 index ff64ae3..593560c 100644
27401 --- a/block/bsg.c
27402 +++ b/block/bsg.c
27403 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27404 struct sg_io_v4 *hdr, struct bsg_device *bd,
27405 fmode_t has_write_perm)
27406 {
27407 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27408 + unsigned char *cmdptr;
27409 +
27410 if (hdr->request_len > BLK_MAX_CDB) {
27411 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27412 if (!rq->cmd)
27413 return -ENOMEM;
27414 - }
27415 + cmdptr = rq->cmd;
27416 + } else
27417 + cmdptr = tmpcmd;
27418
27419 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27420 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27421 hdr->request_len))
27422 return -EFAULT;
27423
27424 + if (cmdptr != rq->cmd)
27425 + memcpy(rq->cmd, cmdptr, hdr->request_len);
27426 +
27427 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27428 if (blk_verify_command(rq->cmd, has_write_perm))
27429 return -EPERM;
27430 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27431 index 7c668c8..db3521c 100644
27432 --- a/block/compat_ioctl.c
27433 +++ b/block/compat_ioctl.c
27434 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27435 err |= __get_user(f->spec1, &uf->spec1);
27436 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27437 err |= __get_user(name, &uf->name);
27438 - f->name = compat_ptr(name);
27439 + f->name = (void __force_kernel *)compat_ptr(name);
27440 if (err) {
27441 err = -EFAULT;
27442 goto out;
27443 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27444 index 6296b40..417c00f 100644
27445 --- a/block/partitions/efi.c
27446 +++ b/block/partitions/efi.c
27447 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27448 if (!gpt)
27449 return NULL;
27450
27451 + if (!le32_to_cpu(gpt->num_partition_entries))
27452 + return NULL;
27453 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27454 + if (!pte)
27455 + return NULL;
27456 +
27457 count = le32_to_cpu(gpt->num_partition_entries) *
27458 le32_to_cpu(gpt->sizeof_partition_entry);
27459 - if (!count)
27460 - return NULL;
27461 - pte = kzalloc(count, GFP_KERNEL);
27462 - if (!pte)
27463 - return NULL;
27464 -
27465 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27466 (u8 *) pte,
27467 count) < count) {
27468 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27469 index 260fa80..e8f3caf 100644
27470 --- a/block/scsi_ioctl.c
27471 +++ b/block/scsi_ioctl.c
27472 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27473 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27474 struct sg_io_hdr *hdr, fmode_t mode)
27475 {
27476 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27477 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27478 + unsigned char *cmdptr;
27479 +
27480 + if (rq->cmd != rq->__cmd)
27481 + cmdptr = rq->cmd;
27482 + else
27483 + cmdptr = tmpcmd;
27484 +
27485 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27486 return -EFAULT;
27487 +
27488 + if (cmdptr != rq->cmd)
27489 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27490 +
27491 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27492 return -EPERM;
27493
27494 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27495 int err;
27496 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27497 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27498 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27499 + unsigned char *cmdptr;
27500
27501 if (!sic)
27502 return -EINVAL;
27503 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27504 */
27505 err = -EFAULT;
27506 rq->cmd_len = cmdlen;
27507 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
27508 +
27509 + if (rq->cmd != rq->__cmd)
27510 + cmdptr = rq->cmd;
27511 + else
27512 + cmdptr = tmpcmd;
27513 +
27514 + if (copy_from_user(cmdptr, sic->data, cmdlen))
27515 goto error;
27516
27517 + if (rq->cmd != cmdptr)
27518 + memcpy(rq->cmd, cmdptr, cmdlen);
27519 +
27520 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27521 goto error;
27522
27523 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27524 index 671d4d6..5f24030 100644
27525 --- a/crypto/cryptd.c
27526 +++ b/crypto/cryptd.c
27527 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27528
27529 struct cryptd_blkcipher_request_ctx {
27530 crypto_completion_t complete;
27531 -};
27532 +} __no_const;
27533
27534 struct cryptd_hash_ctx {
27535 struct crypto_shash *child;
27536 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27537
27538 struct cryptd_aead_request_ctx {
27539 crypto_completion_t complete;
27540 -};
27541 +} __no_const;
27542
27543 static void cryptd_queue_worker(struct work_struct *work);
27544
27545 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27546 index e6defd8..c26a225 100644
27547 --- a/drivers/acpi/apei/cper.c
27548 +++ b/drivers/acpi/apei/cper.c
27549 @@ -38,12 +38,12 @@
27550 */
27551 u64 cper_next_record_id(void)
27552 {
27553 - static atomic64_t seq;
27554 + static atomic64_unchecked_t seq;
27555
27556 - if (!atomic64_read(&seq))
27557 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
27558 + if (!atomic64_read_unchecked(&seq))
27559 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27560
27561 - return atomic64_inc_return(&seq);
27562 + return atomic64_inc_return_unchecked(&seq);
27563 }
27564 EXPORT_SYMBOL_GPL(cper_next_record_id);
27565
27566 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27567 index 7586544..636a2f0 100644
27568 --- a/drivers/acpi/ec_sys.c
27569 +++ b/drivers/acpi/ec_sys.c
27570 @@ -12,6 +12,7 @@
27571 #include <linux/acpi.h>
27572 #include <linux/debugfs.h>
27573 #include <linux/module.h>
27574 +#include <linux/uaccess.h>
27575 #include "internal.h"
27576
27577 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27578 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27579 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27580 */
27581 unsigned int size = EC_SPACE_SIZE;
27582 - u8 *data = (u8 *) buf;
27583 + u8 data;
27584 loff_t init_off = *off;
27585 int err = 0;
27586
27587 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27588 size = count;
27589
27590 while (size) {
27591 - err = ec_read(*off, &data[*off - init_off]);
27592 + err = ec_read(*off, &data);
27593 if (err)
27594 return err;
27595 + if (put_user(data, &buf[*off - init_off]))
27596 + return -EFAULT;
27597 *off += 1;
27598 size--;
27599 }
27600 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27601
27602 unsigned int size = count;
27603 loff_t init_off = *off;
27604 - u8 *data = (u8 *) buf;
27605 int err = 0;
27606
27607 if (*off >= EC_SPACE_SIZE)
27608 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27609 }
27610
27611 while (size) {
27612 - u8 byte_write = data[*off - init_off];
27613 + u8 byte_write;
27614 + if (get_user(byte_write, &buf[*off - init_off]))
27615 + return -EFAULT;
27616 err = ec_write(*off, byte_write);
27617 if (err)
27618 return err;
27619 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27620 index 251c7b62..000462d 100644
27621 --- a/drivers/acpi/proc.c
27622 +++ b/drivers/acpi/proc.c
27623 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27624 size_t count, loff_t * ppos)
27625 {
27626 struct list_head *node, *next;
27627 - char strbuf[5];
27628 - char str[5] = "";
27629 - unsigned int len = count;
27630 + char strbuf[5] = {0};
27631
27632 - if (len > 4)
27633 - len = 4;
27634 - if (len < 0)
27635 + if (count > 4)
27636 + count = 4;
27637 + if (copy_from_user(strbuf, buffer, count))
27638 return -EFAULT;
27639 -
27640 - if (copy_from_user(strbuf, buffer, len))
27641 - return -EFAULT;
27642 - strbuf[len] = '\0';
27643 - sscanf(strbuf, "%s", str);
27644 + strbuf[count] = '\0';
27645
27646 mutex_lock(&acpi_device_lock);
27647 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27648 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27649 if (!dev->wakeup.flags.valid)
27650 continue;
27651
27652 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
27653 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27654 if (device_can_wakeup(&dev->dev)) {
27655 bool enable = !device_may_wakeup(&dev->dev);
27656 device_set_wakeup_enable(&dev->dev, enable);
27657 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27658 index 0734086..3ad3e4c 100644
27659 --- a/drivers/acpi/processor_driver.c
27660 +++ b/drivers/acpi/processor_driver.c
27661 @@ -556,7 +556,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27662 return 0;
27663 #endif
27664
27665 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27666 + BUG_ON(pr->id >= nr_cpu_ids);
27667
27668 /*
27669 * Buggy BIOS check
27670 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27671 index d31ee55..8363a8b 100644
27672 --- a/drivers/ata/libata-core.c
27673 +++ b/drivers/ata/libata-core.c
27674 @@ -4742,7 +4742,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27675 struct ata_port *ap;
27676 unsigned int tag;
27677
27678 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27679 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27680 ap = qc->ap;
27681
27682 qc->flags = 0;
27683 @@ -4758,7 +4758,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27684 struct ata_port *ap;
27685 struct ata_link *link;
27686
27687 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27688 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27689 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27690 ap = qc->ap;
27691 link = qc->dev->link;
27692 @@ -5822,6 +5822,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27693 return;
27694
27695 spin_lock(&lock);
27696 + pax_open_kernel();
27697
27698 for (cur = ops->inherits; cur; cur = cur->inherits) {
27699 void **inherit = (void **)cur;
27700 @@ -5835,8 +5836,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27701 if (IS_ERR(*pp))
27702 *pp = NULL;
27703
27704 - ops->inherits = NULL;
27705 + *(struct ata_port_operations **)&ops->inherits = NULL;
27706
27707 + pax_close_kernel();
27708 spin_unlock(&lock);
27709 }
27710
27711 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27712 index 3239517..343b5f6 100644
27713 --- a/drivers/ata/pata_arasan_cf.c
27714 +++ b/drivers/ata/pata_arasan_cf.c
27715 @@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27716 /* Handle platform specific quirks */
27717 if (pdata->quirk) {
27718 if (pdata->quirk & CF_BROKEN_PIO) {
27719 - ap->ops->set_piomode = NULL;
27720 + pax_open_kernel();
27721 + *(void **)&ap->ops->set_piomode = NULL;
27722 + pax_close_kernel();
27723 ap->pio_mask = 0;
27724 }
27725 if (pdata->quirk & CF_BROKEN_MWDMA)
27726 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27727 index f9b983a..887b9d8 100644
27728 --- a/drivers/atm/adummy.c
27729 +++ b/drivers/atm/adummy.c
27730 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27731 vcc->pop(vcc, skb);
27732 else
27733 dev_kfree_skb_any(skb);
27734 - atomic_inc(&vcc->stats->tx);
27735 + atomic_inc_unchecked(&vcc->stats->tx);
27736
27737 return 0;
27738 }
27739 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27740 index f8f41e0..1f987dd 100644
27741 --- a/drivers/atm/ambassador.c
27742 +++ b/drivers/atm/ambassador.c
27743 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27744 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27745
27746 // VC layer stats
27747 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27748 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27749
27750 // free the descriptor
27751 kfree (tx_descr);
27752 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27753 dump_skb ("<<<", vc, skb);
27754
27755 // VC layer stats
27756 - atomic_inc(&atm_vcc->stats->rx);
27757 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27758 __net_timestamp(skb);
27759 // end of our responsibility
27760 atm_vcc->push (atm_vcc, skb);
27761 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27762 } else {
27763 PRINTK (KERN_INFO, "dropped over-size frame");
27764 // should we count this?
27765 - atomic_inc(&atm_vcc->stats->rx_drop);
27766 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27767 }
27768
27769 } else {
27770 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
27771 }
27772
27773 if (check_area (skb->data, skb->len)) {
27774 - atomic_inc(&atm_vcc->stats->tx_err);
27775 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
27776 return -ENOMEM; // ?
27777 }
27778
27779 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
27780 index b22d71c..d6e1049 100644
27781 --- a/drivers/atm/atmtcp.c
27782 +++ b/drivers/atm/atmtcp.c
27783 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27784 if (vcc->pop) vcc->pop(vcc,skb);
27785 else dev_kfree_skb(skb);
27786 if (dev_data) return 0;
27787 - atomic_inc(&vcc->stats->tx_err);
27788 + atomic_inc_unchecked(&vcc->stats->tx_err);
27789 return -ENOLINK;
27790 }
27791 size = skb->len+sizeof(struct atmtcp_hdr);
27792 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27793 if (!new_skb) {
27794 if (vcc->pop) vcc->pop(vcc,skb);
27795 else dev_kfree_skb(skb);
27796 - atomic_inc(&vcc->stats->tx_err);
27797 + atomic_inc_unchecked(&vcc->stats->tx_err);
27798 return -ENOBUFS;
27799 }
27800 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
27801 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27802 if (vcc->pop) vcc->pop(vcc,skb);
27803 else dev_kfree_skb(skb);
27804 out_vcc->push(out_vcc,new_skb);
27805 - atomic_inc(&vcc->stats->tx);
27806 - atomic_inc(&out_vcc->stats->rx);
27807 + atomic_inc_unchecked(&vcc->stats->tx);
27808 + atomic_inc_unchecked(&out_vcc->stats->rx);
27809 return 0;
27810 }
27811
27812 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27813 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
27814 read_unlock(&vcc_sklist_lock);
27815 if (!out_vcc) {
27816 - atomic_inc(&vcc->stats->tx_err);
27817 + atomic_inc_unchecked(&vcc->stats->tx_err);
27818 goto done;
27819 }
27820 skb_pull(skb,sizeof(struct atmtcp_hdr));
27821 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27822 __net_timestamp(new_skb);
27823 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
27824 out_vcc->push(out_vcc,new_skb);
27825 - atomic_inc(&vcc->stats->tx);
27826 - atomic_inc(&out_vcc->stats->rx);
27827 + atomic_inc_unchecked(&vcc->stats->tx);
27828 + atomic_inc_unchecked(&out_vcc->stats->rx);
27829 done:
27830 if (vcc->pop) vcc->pop(vcc,skb);
27831 else dev_kfree_skb(skb);
27832 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
27833 index 2059ee4..faf51c7 100644
27834 --- a/drivers/atm/eni.c
27835 +++ b/drivers/atm/eni.c
27836 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
27837 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
27838 vcc->dev->number);
27839 length = 0;
27840 - atomic_inc(&vcc->stats->rx_err);
27841 + atomic_inc_unchecked(&vcc->stats->rx_err);
27842 }
27843 else {
27844 length = ATM_CELL_SIZE-1; /* no HEC */
27845 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27846 size);
27847 }
27848 eff = length = 0;
27849 - atomic_inc(&vcc->stats->rx_err);
27850 + atomic_inc_unchecked(&vcc->stats->rx_err);
27851 }
27852 else {
27853 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
27854 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27855 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
27856 vcc->dev->number,vcc->vci,length,size << 2,descr);
27857 length = eff = 0;
27858 - atomic_inc(&vcc->stats->rx_err);
27859 + atomic_inc_unchecked(&vcc->stats->rx_err);
27860 }
27861 }
27862 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
27863 @@ -767,7 +767,7 @@ rx_dequeued++;
27864 vcc->push(vcc,skb);
27865 pushed++;
27866 }
27867 - atomic_inc(&vcc->stats->rx);
27868 + atomic_inc_unchecked(&vcc->stats->rx);
27869 }
27870 wake_up(&eni_dev->rx_wait);
27871 }
27872 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
27873 PCI_DMA_TODEVICE);
27874 if (vcc->pop) vcc->pop(vcc,skb);
27875 else dev_kfree_skb_irq(skb);
27876 - atomic_inc(&vcc->stats->tx);
27877 + atomic_inc_unchecked(&vcc->stats->tx);
27878 wake_up(&eni_dev->tx_wait);
27879 dma_complete++;
27880 }
27881 @@ -1567,7 +1567,7 @@ tx_complete++;
27882 /*--------------------------------- entries ---------------------------------*/
27883
27884
27885 -static const char *media_name[] __devinitdata = {
27886 +static const char *media_name[] __devinitconst = {
27887 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
27888 "UTP", "05?", "06?", "07?", /* 4- 7 */
27889 "TAXI","09?", "10?", "11?", /* 8-11 */
27890 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
27891 index 86fed1b..6dc4721 100644
27892 --- a/drivers/atm/firestream.c
27893 +++ b/drivers/atm/firestream.c
27894 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
27895 }
27896 }
27897
27898 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27899 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27900
27901 fs_dprintk (FS_DEBUG_TXMEM, "i");
27902 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
27903 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27904 #endif
27905 skb_put (skb, qe->p1 & 0xffff);
27906 ATM_SKB(skb)->vcc = atm_vcc;
27907 - atomic_inc(&atm_vcc->stats->rx);
27908 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27909 __net_timestamp(skb);
27910 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
27911 atm_vcc->push (atm_vcc, skb);
27912 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27913 kfree (pe);
27914 }
27915 if (atm_vcc)
27916 - atomic_inc(&atm_vcc->stats->rx_drop);
27917 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27918 break;
27919 case 0x1f: /* Reassembly abort: no buffers. */
27920 /* Silently increment error counter. */
27921 if (atm_vcc)
27922 - atomic_inc(&atm_vcc->stats->rx_drop);
27923 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27924 break;
27925 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
27926 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
27927 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
27928 index 361f5ae..7fc552d 100644
27929 --- a/drivers/atm/fore200e.c
27930 +++ b/drivers/atm/fore200e.c
27931 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
27932 #endif
27933 /* check error condition */
27934 if (*entry->status & STATUS_ERROR)
27935 - atomic_inc(&vcc->stats->tx_err);
27936 + atomic_inc_unchecked(&vcc->stats->tx_err);
27937 else
27938 - atomic_inc(&vcc->stats->tx);
27939 + atomic_inc_unchecked(&vcc->stats->tx);
27940 }
27941 }
27942
27943 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27944 if (skb == NULL) {
27945 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
27946
27947 - atomic_inc(&vcc->stats->rx_drop);
27948 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27949 return -ENOMEM;
27950 }
27951
27952 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27953
27954 dev_kfree_skb_any(skb);
27955
27956 - atomic_inc(&vcc->stats->rx_drop);
27957 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27958 return -ENOMEM;
27959 }
27960
27961 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27962
27963 vcc->push(vcc, skb);
27964 - atomic_inc(&vcc->stats->rx);
27965 + atomic_inc_unchecked(&vcc->stats->rx);
27966
27967 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27968
27969 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
27970 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
27971 fore200e->atm_dev->number,
27972 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
27973 - atomic_inc(&vcc->stats->rx_err);
27974 + atomic_inc_unchecked(&vcc->stats->rx_err);
27975 }
27976 }
27977
27978 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
27979 goto retry_here;
27980 }
27981
27982 - atomic_inc(&vcc->stats->tx_err);
27983 + atomic_inc_unchecked(&vcc->stats->tx_err);
27984
27985 fore200e->tx_sat++;
27986 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
27987 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
27988 index b182c2f..1c6fa8a 100644
27989 --- a/drivers/atm/he.c
27990 +++ b/drivers/atm/he.c
27991 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27992
27993 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
27994 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
27995 - atomic_inc(&vcc->stats->rx_drop);
27996 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27997 goto return_host_buffers;
27998 }
27999
28000 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28001 RBRQ_LEN_ERR(he_dev->rbrq_head)
28002 ? "LEN_ERR" : "",
28003 vcc->vpi, vcc->vci);
28004 - atomic_inc(&vcc->stats->rx_err);
28005 + atomic_inc_unchecked(&vcc->stats->rx_err);
28006 goto return_host_buffers;
28007 }
28008
28009 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28010 vcc->push(vcc, skb);
28011 spin_lock(&he_dev->global_lock);
28012
28013 - atomic_inc(&vcc->stats->rx);
28014 + atomic_inc_unchecked(&vcc->stats->rx);
28015
28016 return_host_buffers:
28017 ++pdus_assembled;
28018 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28019 tpd->vcc->pop(tpd->vcc, tpd->skb);
28020 else
28021 dev_kfree_skb_any(tpd->skb);
28022 - atomic_inc(&tpd->vcc->stats->tx_err);
28023 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28024 }
28025 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28026 return;
28027 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28028 vcc->pop(vcc, skb);
28029 else
28030 dev_kfree_skb_any(skb);
28031 - atomic_inc(&vcc->stats->tx_err);
28032 + atomic_inc_unchecked(&vcc->stats->tx_err);
28033 return -EINVAL;
28034 }
28035
28036 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28037 vcc->pop(vcc, skb);
28038 else
28039 dev_kfree_skb_any(skb);
28040 - atomic_inc(&vcc->stats->tx_err);
28041 + atomic_inc_unchecked(&vcc->stats->tx_err);
28042 return -EINVAL;
28043 }
28044 #endif
28045 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28046 vcc->pop(vcc, skb);
28047 else
28048 dev_kfree_skb_any(skb);
28049 - atomic_inc(&vcc->stats->tx_err);
28050 + atomic_inc_unchecked(&vcc->stats->tx_err);
28051 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28052 return -ENOMEM;
28053 }
28054 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28055 vcc->pop(vcc, skb);
28056 else
28057 dev_kfree_skb_any(skb);
28058 - atomic_inc(&vcc->stats->tx_err);
28059 + atomic_inc_unchecked(&vcc->stats->tx_err);
28060 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28061 return -ENOMEM;
28062 }
28063 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28064 __enqueue_tpd(he_dev, tpd, cid);
28065 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28066
28067 - atomic_inc(&vcc->stats->tx);
28068 + atomic_inc_unchecked(&vcc->stats->tx);
28069
28070 return 0;
28071 }
28072 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28073 index 75fd691..2d20b14 100644
28074 --- a/drivers/atm/horizon.c
28075 +++ b/drivers/atm/horizon.c
28076 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28077 {
28078 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28079 // VC layer stats
28080 - atomic_inc(&vcc->stats->rx);
28081 + atomic_inc_unchecked(&vcc->stats->rx);
28082 __net_timestamp(skb);
28083 // end of our responsibility
28084 vcc->push (vcc, skb);
28085 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28086 dev->tx_iovec = NULL;
28087
28088 // VC layer stats
28089 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28090 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28091
28092 // free the skb
28093 hrz_kfree_skb (skb);
28094 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28095 index 1c05212..c28e200 100644
28096 --- a/drivers/atm/idt77252.c
28097 +++ b/drivers/atm/idt77252.c
28098 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28099 else
28100 dev_kfree_skb(skb);
28101
28102 - atomic_inc(&vcc->stats->tx);
28103 + atomic_inc_unchecked(&vcc->stats->tx);
28104 }
28105
28106 atomic_dec(&scq->used);
28107 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28108 if ((sb = dev_alloc_skb(64)) == NULL) {
28109 printk("%s: Can't allocate buffers for aal0.\n",
28110 card->name);
28111 - atomic_add(i, &vcc->stats->rx_drop);
28112 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28113 break;
28114 }
28115 if (!atm_charge(vcc, sb->truesize)) {
28116 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28117 card->name);
28118 - atomic_add(i - 1, &vcc->stats->rx_drop);
28119 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28120 dev_kfree_skb(sb);
28121 break;
28122 }
28123 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28124 ATM_SKB(sb)->vcc = vcc;
28125 __net_timestamp(sb);
28126 vcc->push(vcc, sb);
28127 - atomic_inc(&vcc->stats->rx);
28128 + atomic_inc_unchecked(&vcc->stats->rx);
28129
28130 cell += ATM_CELL_PAYLOAD;
28131 }
28132 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28133 "(CDC: %08x)\n",
28134 card->name, len, rpp->len, readl(SAR_REG_CDC));
28135 recycle_rx_pool_skb(card, rpp);
28136 - atomic_inc(&vcc->stats->rx_err);
28137 + atomic_inc_unchecked(&vcc->stats->rx_err);
28138 return;
28139 }
28140 if (stat & SAR_RSQE_CRC) {
28141 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28142 recycle_rx_pool_skb(card, rpp);
28143 - atomic_inc(&vcc->stats->rx_err);
28144 + atomic_inc_unchecked(&vcc->stats->rx_err);
28145 return;
28146 }
28147 if (skb_queue_len(&rpp->queue) > 1) {
28148 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28149 RXPRINTK("%s: Can't alloc RX skb.\n",
28150 card->name);
28151 recycle_rx_pool_skb(card, rpp);
28152 - atomic_inc(&vcc->stats->rx_err);
28153 + atomic_inc_unchecked(&vcc->stats->rx_err);
28154 return;
28155 }
28156 if (!atm_charge(vcc, skb->truesize)) {
28157 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28158 __net_timestamp(skb);
28159
28160 vcc->push(vcc, skb);
28161 - atomic_inc(&vcc->stats->rx);
28162 + atomic_inc_unchecked(&vcc->stats->rx);
28163
28164 return;
28165 }
28166 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28167 __net_timestamp(skb);
28168
28169 vcc->push(vcc, skb);
28170 - atomic_inc(&vcc->stats->rx);
28171 + atomic_inc_unchecked(&vcc->stats->rx);
28172
28173 if (skb->truesize > SAR_FB_SIZE_3)
28174 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28175 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28176 if (vcc->qos.aal != ATM_AAL0) {
28177 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28178 card->name, vpi, vci);
28179 - atomic_inc(&vcc->stats->rx_drop);
28180 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28181 goto drop;
28182 }
28183
28184 if ((sb = dev_alloc_skb(64)) == NULL) {
28185 printk("%s: Can't allocate buffers for AAL0.\n",
28186 card->name);
28187 - atomic_inc(&vcc->stats->rx_err);
28188 + atomic_inc_unchecked(&vcc->stats->rx_err);
28189 goto drop;
28190 }
28191
28192 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28193 ATM_SKB(sb)->vcc = vcc;
28194 __net_timestamp(sb);
28195 vcc->push(vcc, sb);
28196 - atomic_inc(&vcc->stats->rx);
28197 + atomic_inc_unchecked(&vcc->stats->rx);
28198
28199 drop:
28200 skb_pull(queue, 64);
28201 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28202
28203 if (vc == NULL) {
28204 printk("%s: NULL connection in send().\n", card->name);
28205 - atomic_inc(&vcc->stats->tx_err);
28206 + atomic_inc_unchecked(&vcc->stats->tx_err);
28207 dev_kfree_skb(skb);
28208 return -EINVAL;
28209 }
28210 if (!test_bit(VCF_TX, &vc->flags)) {
28211 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28212 - atomic_inc(&vcc->stats->tx_err);
28213 + atomic_inc_unchecked(&vcc->stats->tx_err);
28214 dev_kfree_skb(skb);
28215 return -EINVAL;
28216 }
28217 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28218 break;
28219 default:
28220 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28221 - atomic_inc(&vcc->stats->tx_err);
28222 + atomic_inc_unchecked(&vcc->stats->tx_err);
28223 dev_kfree_skb(skb);
28224 return -EINVAL;
28225 }
28226
28227 if (skb_shinfo(skb)->nr_frags != 0) {
28228 printk("%s: No scatter-gather yet.\n", card->name);
28229 - atomic_inc(&vcc->stats->tx_err);
28230 + atomic_inc_unchecked(&vcc->stats->tx_err);
28231 dev_kfree_skb(skb);
28232 return -EINVAL;
28233 }
28234 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28235
28236 err = queue_skb(card, vc, skb, oam);
28237 if (err) {
28238 - atomic_inc(&vcc->stats->tx_err);
28239 + atomic_inc_unchecked(&vcc->stats->tx_err);
28240 dev_kfree_skb(skb);
28241 return err;
28242 }
28243 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28244 skb = dev_alloc_skb(64);
28245 if (!skb) {
28246 printk("%s: Out of memory in send_oam().\n", card->name);
28247 - atomic_inc(&vcc->stats->tx_err);
28248 + atomic_inc_unchecked(&vcc->stats->tx_err);
28249 return -ENOMEM;
28250 }
28251 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28252 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28253 index d438601..8b98495 100644
28254 --- a/drivers/atm/iphase.c
28255 +++ b/drivers/atm/iphase.c
28256 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28257 status = (u_short) (buf_desc_ptr->desc_mode);
28258 if (status & (RX_CER | RX_PTE | RX_OFL))
28259 {
28260 - atomic_inc(&vcc->stats->rx_err);
28261 + atomic_inc_unchecked(&vcc->stats->rx_err);
28262 IF_ERR(printk("IA: bad packet, dropping it");)
28263 if (status & RX_CER) {
28264 IF_ERR(printk(" cause: packet CRC error\n");)
28265 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28266 len = dma_addr - buf_addr;
28267 if (len > iadev->rx_buf_sz) {
28268 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28269 - atomic_inc(&vcc->stats->rx_err);
28270 + atomic_inc_unchecked(&vcc->stats->rx_err);
28271 goto out_free_desc;
28272 }
28273
28274 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28275 ia_vcc = INPH_IA_VCC(vcc);
28276 if (ia_vcc == NULL)
28277 {
28278 - atomic_inc(&vcc->stats->rx_err);
28279 + atomic_inc_unchecked(&vcc->stats->rx_err);
28280 atm_return(vcc, skb->truesize);
28281 dev_kfree_skb_any(skb);
28282 goto INCR_DLE;
28283 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28284 if ((length > iadev->rx_buf_sz) || (length >
28285 (skb->len - sizeof(struct cpcs_trailer))))
28286 {
28287 - atomic_inc(&vcc->stats->rx_err);
28288 + atomic_inc_unchecked(&vcc->stats->rx_err);
28289 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28290 length, skb->len);)
28291 atm_return(vcc, skb->truesize);
28292 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28293
28294 IF_RX(printk("rx_dle_intr: skb push");)
28295 vcc->push(vcc,skb);
28296 - atomic_inc(&vcc->stats->rx);
28297 + atomic_inc_unchecked(&vcc->stats->rx);
28298 iadev->rx_pkt_cnt++;
28299 }
28300 INCR_DLE:
28301 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28302 {
28303 struct k_sonet_stats *stats;
28304 stats = &PRIV(_ia_dev[board])->sonet_stats;
28305 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28306 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28307 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28308 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28309 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28310 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28311 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28312 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28313 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28314 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28315 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28316 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28317 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28318 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28319 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28320 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28321 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28322 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28323 }
28324 ia_cmds.status = 0;
28325 break;
28326 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28327 if ((desc == 0) || (desc > iadev->num_tx_desc))
28328 {
28329 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28330 - atomic_inc(&vcc->stats->tx);
28331 + atomic_inc_unchecked(&vcc->stats->tx);
28332 if (vcc->pop)
28333 vcc->pop(vcc, skb);
28334 else
28335 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28336 ATM_DESC(skb) = vcc->vci;
28337 skb_queue_tail(&iadev->tx_dma_q, skb);
28338
28339 - atomic_inc(&vcc->stats->tx);
28340 + atomic_inc_unchecked(&vcc->stats->tx);
28341 iadev->tx_pkt_cnt++;
28342 /* Increment transaction counter */
28343 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28344
28345 #if 0
28346 /* add flow control logic */
28347 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28348 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28349 if (iavcc->vc_desc_cnt > 10) {
28350 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28351 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28352 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28353 index 68c7588..7036683 100644
28354 --- a/drivers/atm/lanai.c
28355 +++ b/drivers/atm/lanai.c
28356 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28357 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28358 lanai_endtx(lanai, lvcc);
28359 lanai_free_skb(lvcc->tx.atmvcc, skb);
28360 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28361 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28362 }
28363
28364 /* Try to fill the buffer - don't call unless there is backlog */
28365 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28366 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28367 __net_timestamp(skb);
28368 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28369 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28370 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28371 out:
28372 lvcc->rx.buf.ptr = end;
28373 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28374 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28375 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28376 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28377 lanai->stats.service_rxnotaal5++;
28378 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28379 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28380 return 0;
28381 }
28382 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28383 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28384 int bytes;
28385 read_unlock(&vcc_sklist_lock);
28386 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28387 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28388 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28389 lvcc->stats.x.aal5.service_trash++;
28390 bytes = (SERVICE_GET_END(s) * 16) -
28391 (((unsigned long) lvcc->rx.buf.ptr) -
28392 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28393 }
28394 if (s & SERVICE_STREAM) {
28395 read_unlock(&vcc_sklist_lock);
28396 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28397 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28398 lvcc->stats.x.aal5.service_stream++;
28399 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28400 "PDU on VCI %d!\n", lanai->number, vci);
28401 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28402 return 0;
28403 }
28404 DPRINTK("got rx crc error on vci %d\n", vci);
28405 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28406 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28407 lvcc->stats.x.aal5.service_rxcrc++;
28408 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28409 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28410 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28411 index 1c70c45..300718d 100644
28412 --- a/drivers/atm/nicstar.c
28413 +++ b/drivers/atm/nicstar.c
28414 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28415 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28416 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28417 card->index);
28418 - atomic_inc(&vcc->stats->tx_err);
28419 + atomic_inc_unchecked(&vcc->stats->tx_err);
28420 dev_kfree_skb_any(skb);
28421 return -EINVAL;
28422 }
28423 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28424 if (!vc->tx) {
28425 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28426 card->index);
28427 - atomic_inc(&vcc->stats->tx_err);
28428 + atomic_inc_unchecked(&vcc->stats->tx_err);
28429 dev_kfree_skb_any(skb);
28430 return -EINVAL;
28431 }
28432 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28433 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28434 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28435 card->index);
28436 - atomic_inc(&vcc->stats->tx_err);
28437 + atomic_inc_unchecked(&vcc->stats->tx_err);
28438 dev_kfree_skb_any(skb);
28439 return -EINVAL;
28440 }
28441
28442 if (skb_shinfo(skb)->nr_frags != 0) {
28443 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28444 - atomic_inc(&vcc->stats->tx_err);
28445 + atomic_inc_unchecked(&vcc->stats->tx_err);
28446 dev_kfree_skb_any(skb);
28447 return -EINVAL;
28448 }
28449 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28450 }
28451
28452 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28453 - atomic_inc(&vcc->stats->tx_err);
28454 + atomic_inc_unchecked(&vcc->stats->tx_err);
28455 dev_kfree_skb_any(skb);
28456 return -EIO;
28457 }
28458 - atomic_inc(&vcc->stats->tx);
28459 + atomic_inc_unchecked(&vcc->stats->tx);
28460
28461 return 0;
28462 }
28463 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28464 printk
28465 ("nicstar%d: Can't allocate buffers for aal0.\n",
28466 card->index);
28467 - atomic_add(i, &vcc->stats->rx_drop);
28468 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28469 break;
28470 }
28471 if (!atm_charge(vcc, sb->truesize)) {
28472 RXPRINTK
28473 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28474 card->index);
28475 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28476 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28477 dev_kfree_skb_any(sb);
28478 break;
28479 }
28480 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28481 ATM_SKB(sb)->vcc = vcc;
28482 __net_timestamp(sb);
28483 vcc->push(vcc, sb);
28484 - atomic_inc(&vcc->stats->rx);
28485 + atomic_inc_unchecked(&vcc->stats->rx);
28486 cell += ATM_CELL_PAYLOAD;
28487 }
28488
28489 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28490 if (iovb == NULL) {
28491 printk("nicstar%d: Out of iovec buffers.\n",
28492 card->index);
28493 - atomic_inc(&vcc->stats->rx_drop);
28494 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28495 recycle_rx_buf(card, skb);
28496 return;
28497 }
28498 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28499 small or large buffer itself. */
28500 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28501 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28502 - atomic_inc(&vcc->stats->rx_err);
28503 + atomic_inc_unchecked(&vcc->stats->rx_err);
28504 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28505 NS_MAX_IOVECS);
28506 NS_PRV_IOVCNT(iovb) = 0;
28507 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28508 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28509 card->index);
28510 which_list(card, skb);
28511 - atomic_inc(&vcc->stats->rx_err);
28512 + atomic_inc_unchecked(&vcc->stats->rx_err);
28513 recycle_rx_buf(card, skb);
28514 vc->rx_iov = NULL;
28515 recycle_iov_buf(card, iovb);
28516 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28517 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28518 card->index);
28519 which_list(card, skb);
28520 - atomic_inc(&vcc->stats->rx_err);
28521 + atomic_inc_unchecked(&vcc->stats->rx_err);
28522 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28523 NS_PRV_IOVCNT(iovb));
28524 vc->rx_iov = NULL;
28525 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28526 printk(" - PDU size mismatch.\n");
28527 else
28528 printk(".\n");
28529 - atomic_inc(&vcc->stats->rx_err);
28530 + atomic_inc_unchecked(&vcc->stats->rx_err);
28531 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28532 NS_PRV_IOVCNT(iovb));
28533 vc->rx_iov = NULL;
28534 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28535 /* skb points to a small buffer */
28536 if (!atm_charge(vcc, skb->truesize)) {
28537 push_rxbufs(card, skb);
28538 - atomic_inc(&vcc->stats->rx_drop);
28539 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28540 } else {
28541 skb_put(skb, len);
28542 dequeue_sm_buf(card, skb);
28543 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28544 ATM_SKB(skb)->vcc = vcc;
28545 __net_timestamp(skb);
28546 vcc->push(vcc, skb);
28547 - atomic_inc(&vcc->stats->rx);
28548 + atomic_inc_unchecked(&vcc->stats->rx);
28549 }
28550 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28551 struct sk_buff *sb;
28552 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28553 if (len <= NS_SMBUFSIZE) {
28554 if (!atm_charge(vcc, sb->truesize)) {
28555 push_rxbufs(card, sb);
28556 - atomic_inc(&vcc->stats->rx_drop);
28557 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28558 } else {
28559 skb_put(sb, len);
28560 dequeue_sm_buf(card, sb);
28561 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28562 ATM_SKB(sb)->vcc = vcc;
28563 __net_timestamp(sb);
28564 vcc->push(vcc, sb);
28565 - atomic_inc(&vcc->stats->rx);
28566 + atomic_inc_unchecked(&vcc->stats->rx);
28567 }
28568
28569 push_rxbufs(card, skb);
28570 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28571
28572 if (!atm_charge(vcc, skb->truesize)) {
28573 push_rxbufs(card, skb);
28574 - atomic_inc(&vcc->stats->rx_drop);
28575 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28576 } else {
28577 dequeue_lg_buf(card, skb);
28578 #ifdef NS_USE_DESTRUCTORS
28579 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28580 ATM_SKB(skb)->vcc = vcc;
28581 __net_timestamp(skb);
28582 vcc->push(vcc, skb);
28583 - atomic_inc(&vcc->stats->rx);
28584 + atomic_inc_unchecked(&vcc->stats->rx);
28585 }
28586
28587 push_rxbufs(card, sb);
28588 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28589 printk
28590 ("nicstar%d: Out of huge buffers.\n",
28591 card->index);
28592 - atomic_inc(&vcc->stats->rx_drop);
28593 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28594 recycle_iovec_rx_bufs(card,
28595 (struct iovec *)
28596 iovb->data,
28597 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28598 card->hbpool.count++;
28599 } else
28600 dev_kfree_skb_any(hb);
28601 - atomic_inc(&vcc->stats->rx_drop);
28602 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28603 } else {
28604 /* Copy the small buffer to the huge buffer */
28605 sb = (struct sk_buff *)iov->iov_base;
28606 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28607 #endif /* NS_USE_DESTRUCTORS */
28608 __net_timestamp(hb);
28609 vcc->push(vcc, hb);
28610 - atomic_inc(&vcc->stats->rx);
28611 + atomic_inc_unchecked(&vcc->stats->rx);
28612 }
28613 }
28614
28615 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28616 index 9851093..adb2b1e 100644
28617 --- a/drivers/atm/solos-pci.c
28618 +++ b/drivers/atm/solos-pci.c
28619 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28620 }
28621 atm_charge(vcc, skb->truesize);
28622 vcc->push(vcc, skb);
28623 - atomic_inc(&vcc->stats->rx);
28624 + atomic_inc_unchecked(&vcc->stats->rx);
28625 break;
28626
28627 case PKT_STATUS:
28628 @@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28629 vcc = SKB_CB(oldskb)->vcc;
28630
28631 if (vcc) {
28632 - atomic_inc(&vcc->stats->tx);
28633 + atomic_inc_unchecked(&vcc->stats->tx);
28634 solos_pop(vcc, oldskb);
28635 } else
28636 dev_kfree_skb_irq(oldskb);
28637 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28638 index 0215934..ce9f5b1 100644
28639 --- a/drivers/atm/suni.c
28640 +++ b/drivers/atm/suni.c
28641 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28642
28643
28644 #define ADD_LIMITED(s,v) \
28645 - atomic_add((v),&stats->s); \
28646 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28647 + atomic_add_unchecked((v),&stats->s); \
28648 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28649
28650
28651 static void suni_hz(unsigned long from_timer)
28652 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28653 index 5120a96..e2572bd 100644
28654 --- a/drivers/atm/uPD98402.c
28655 +++ b/drivers/atm/uPD98402.c
28656 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28657 struct sonet_stats tmp;
28658 int error = 0;
28659
28660 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28661 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28662 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28663 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28664 if (zero && !error) {
28665 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28666
28667
28668 #define ADD_LIMITED(s,v) \
28669 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28670 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28671 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28672 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28673 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28674 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28675
28676
28677 static void stat_event(struct atm_dev *dev)
28678 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28679 if (reason & uPD98402_INT_PFM) stat_event(dev);
28680 if (reason & uPD98402_INT_PCO) {
28681 (void) GET(PCOCR); /* clear interrupt cause */
28682 - atomic_add(GET(HECCT),
28683 + atomic_add_unchecked(GET(HECCT),
28684 &PRIV(dev)->sonet_stats.uncorr_hcs);
28685 }
28686 if ((reason & uPD98402_INT_RFO) &&
28687 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28688 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28689 uPD98402_INT_LOS),PIMR); /* enable them */
28690 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28691 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28692 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28693 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28694 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28695 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28696 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28697 return 0;
28698 }
28699
28700 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28701 index abe4e20..83c4727 100644
28702 --- a/drivers/atm/zatm.c
28703 +++ b/drivers/atm/zatm.c
28704 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28705 }
28706 if (!size) {
28707 dev_kfree_skb_irq(skb);
28708 - if (vcc) atomic_inc(&vcc->stats->rx_err);
28709 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28710 continue;
28711 }
28712 if (!atm_charge(vcc,skb->truesize)) {
28713 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28714 skb->len = size;
28715 ATM_SKB(skb)->vcc = vcc;
28716 vcc->push(vcc,skb);
28717 - atomic_inc(&vcc->stats->rx);
28718 + atomic_inc_unchecked(&vcc->stats->rx);
28719 }
28720 zout(pos & 0xffff,MTA(mbx));
28721 #if 0 /* probably a stupid idea */
28722 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28723 skb_queue_head(&zatm_vcc->backlog,skb);
28724 break;
28725 }
28726 - atomic_inc(&vcc->stats->tx);
28727 + atomic_inc_unchecked(&vcc->stats->tx);
28728 wake_up(&zatm_vcc->tx_wait);
28729 }
28730
28731 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28732 index 8493536..31adee0 100644
28733 --- a/drivers/base/devtmpfs.c
28734 +++ b/drivers/base/devtmpfs.c
28735 @@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
28736 if (!thread)
28737 return 0;
28738
28739 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28740 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28741 if (err)
28742 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28743 else
28744 diff --git a/drivers/base/node.c b/drivers/base/node.c
28745 index 90aa2a1..af1a177 100644
28746 --- a/drivers/base/node.c
28747 +++ b/drivers/base/node.c
28748 @@ -592,11 +592,9 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
28749 {
28750 int n;
28751
28752 - n = nodelist_scnprintf(buf, PAGE_SIZE, node_states[state]);
28753 - if (n > 0 && PAGE_SIZE > n + 1) {
28754 - *(buf + n++) = '\n';
28755 - *(buf + n++) = '\0';
28756 - }
28757 + n = nodelist_scnprintf(buf, PAGE_SIZE-2, node_states[state]);
28758 + buf[n++] = '\n';
28759 + buf[n] = '\0';
28760 return n;
28761 }
28762
28763 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28764 index 2a3e581..3d6a73f 100644
28765 --- a/drivers/base/power/wakeup.c
28766 +++ b/drivers/base/power/wakeup.c
28767 @@ -30,14 +30,14 @@ bool events_check_enabled;
28768 * They need to be modified together atomically, so it's better to use one
28769 * atomic variable to hold them both.
28770 */
28771 -static atomic_t combined_event_count = ATOMIC_INIT(0);
28772 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28773
28774 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28775 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28776
28777 static void split_counters(unsigned int *cnt, unsigned int *inpr)
28778 {
28779 - unsigned int comb = atomic_read(&combined_event_count);
28780 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
28781
28782 *cnt = (comb >> IN_PROGRESS_BITS);
28783 *inpr = comb & MAX_IN_PROGRESS;
28784 @@ -379,7 +379,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
28785 ws->last_time = ktime_get();
28786
28787 /* Increment the counter of events in progress. */
28788 - atomic_inc(&combined_event_count);
28789 + atomic_inc_unchecked(&combined_event_count);
28790 }
28791
28792 /**
28793 @@ -475,7 +475,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
28794 * Increment the counter of registered wakeup events and decrement the
28795 * couter of wakeup events in progress simultaneously.
28796 */
28797 - atomic_add(MAX_IN_PROGRESS, &combined_event_count);
28798 + atomic_add_unchecked(MAX_IN_PROGRESS, &combined_event_count);
28799 }
28800
28801 /**
28802 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
28803 index b0f553b..77b928b 100644
28804 --- a/drivers/block/cciss.c
28805 +++ b/drivers/block/cciss.c
28806 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
28807 int err;
28808 u32 cp;
28809
28810 + memset(&arg64, 0, sizeof(arg64));
28811 +
28812 err = 0;
28813 err |=
28814 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
28815 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
28816 while (!list_empty(&h->reqQ)) {
28817 c = list_entry(h->reqQ.next, CommandList_struct, list);
28818 /* can't do anything if fifo is full */
28819 - if ((h->access.fifo_full(h))) {
28820 + if ((h->access->fifo_full(h))) {
28821 dev_warn(&h->pdev->dev, "fifo full\n");
28822 break;
28823 }
28824 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
28825 h->Qdepth--;
28826
28827 /* Tell the controller execute command */
28828 - h->access.submit_command(h, c);
28829 + h->access->submit_command(h, c);
28830
28831 /* Put job onto the completed Q */
28832 addQ(&h->cmpQ, c);
28833 @@ -3443,17 +3445,17 @@ startio:
28834
28835 static inline unsigned long get_next_completion(ctlr_info_t *h)
28836 {
28837 - return h->access.command_completed(h);
28838 + return h->access->command_completed(h);
28839 }
28840
28841 static inline int interrupt_pending(ctlr_info_t *h)
28842 {
28843 - return h->access.intr_pending(h);
28844 + return h->access->intr_pending(h);
28845 }
28846
28847 static inline long interrupt_not_for_us(ctlr_info_t *h)
28848 {
28849 - return ((h->access.intr_pending(h) == 0) ||
28850 + return ((h->access->intr_pending(h) == 0) ||
28851 (h->interrupts_enabled == 0));
28852 }
28853
28854 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
28855 u32 a;
28856
28857 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
28858 - return h->access.command_completed(h);
28859 + return h->access->command_completed(h);
28860
28861 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
28862 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
28863 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
28864 trans_support & CFGTBL_Trans_use_short_tags);
28865
28866 /* Change the access methods to the performant access methods */
28867 - h->access = SA5_performant_access;
28868 + h->access = &SA5_performant_access;
28869 h->transMethod = CFGTBL_Trans_Performant;
28870
28871 return;
28872 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
28873 if (prod_index < 0)
28874 return -ENODEV;
28875 h->product_name = products[prod_index].product_name;
28876 - h->access = *(products[prod_index].access);
28877 + h->access = products[prod_index].access;
28878
28879 if (cciss_board_disabled(h)) {
28880 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
28881 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
28882 }
28883
28884 /* make sure the board interrupts are off */
28885 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28886 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28887 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
28888 if (rc)
28889 goto clean2;
28890 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
28891 * fake ones to scoop up any residual completions.
28892 */
28893 spin_lock_irqsave(&h->lock, flags);
28894 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28895 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28896 spin_unlock_irqrestore(&h->lock, flags);
28897 free_irq(h->intr[h->intr_mode], h);
28898 rc = cciss_request_irq(h, cciss_msix_discard_completions,
28899 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
28900 dev_info(&h->pdev->dev, "Board READY.\n");
28901 dev_info(&h->pdev->dev,
28902 "Waiting for stale completions to drain.\n");
28903 - h->access.set_intr_mask(h, CCISS_INTR_ON);
28904 + h->access->set_intr_mask(h, CCISS_INTR_ON);
28905 msleep(10000);
28906 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28907 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28908
28909 rc = controller_reset_failed(h->cfgtable);
28910 if (rc)
28911 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
28912 cciss_scsi_setup(h);
28913
28914 /* Turn the interrupts on so we can service requests */
28915 - h->access.set_intr_mask(h, CCISS_INTR_ON);
28916 + h->access->set_intr_mask(h, CCISS_INTR_ON);
28917
28918 /* Get the firmware version */
28919 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
28920 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
28921 kfree(flush_buf);
28922 if (return_code != IO_OK)
28923 dev_warn(&h->pdev->dev, "Error flushing cache\n");
28924 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28925 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28926 free_irq(h->intr[h->intr_mode], h);
28927 }
28928
28929 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
28930 index 7fda30e..eb5dfe0 100644
28931 --- a/drivers/block/cciss.h
28932 +++ b/drivers/block/cciss.h
28933 @@ -101,7 +101,7 @@ struct ctlr_info
28934 /* information about each logical volume */
28935 drive_info_struct *drv[CISS_MAX_LUN];
28936
28937 - struct access_method access;
28938 + struct access_method *access;
28939
28940 /* queue and queue Info */
28941 struct list_head reqQ;
28942 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
28943 index 9125bbe..eede5c8 100644
28944 --- a/drivers/block/cpqarray.c
28945 +++ b/drivers/block/cpqarray.c
28946 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28947 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
28948 goto Enomem4;
28949 }
28950 - hba[i]->access.set_intr_mask(hba[i], 0);
28951 + hba[i]->access->set_intr_mask(hba[i], 0);
28952 if (request_irq(hba[i]->intr, do_ida_intr,
28953 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
28954 {
28955 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28956 add_timer(&hba[i]->timer);
28957
28958 /* Enable IRQ now that spinlock and rate limit timer are set up */
28959 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28960 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28961
28962 for(j=0; j<NWD; j++) {
28963 struct gendisk *disk = ida_gendisk[i][j];
28964 @@ -694,7 +694,7 @@ DBGINFO(
28965 for(i=0; i<NR_PRODUCTS; i++) {
28966 if (board_id == products[i].board_id) {
28967 c->product_name = products[i].product_name;
28968 - c->access = *(products[i].access);
28969 + c->access = products[i].access;
28970 break;
28971 }
28972 }
28973 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
28974 hba[ctlr]->intr = intr;
28975 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
28976 hba[ctlr]->product_name = products[j].product_name;
28977 - hba[ctlr]->access = *(products[j].access);
28978 + hba[ctlr]->access = products[j].access;
28979 hba[ctlr]->ctlr = ctlr;
28980 hba[ctlr]->board_id = board_id;
28981 hba[ctlr]->pci_dev = NULL; /* not PCI */
28982 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
28983
28984 while((c = h->reqQ) != NULL) {
28985 /* Can't do anything if we're busy */
28986 - if (h->access.fifo_full(h) == 0)
28987 + if (h->access->fifo_full(h) == 0)
28988 return;
28989
28990 /* Get the first entry from the request Q */
28991 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
28992 h->Qdepth--;
28993
28994 /* Tell the controller to do our bidding */
28995 - h->access.submit_command(h, c);
28996 + h->access->submit_command(h, c);
28997
28998 /* Get onto the completion Q */
28999 addQ(&h->cmpQ, c);
29000 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29001 unsigned long flags;
29002 __u32 a,a1;
29003
29004 - istat = h->access.intr_pending(h);
29005 + istat = h->access->intr_pending(h);
29006 /* Is this interrupt for us? */
29007 if (istat == 0)
29008 return IRQ_NONE;
29009 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29010 */
29011 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
29012 if (istat & FIFO_NOT_EMPTY) {
29013 - while((a = h->access.command_completed(h))) {
29014 + while((a = h->access->command_completed(h))) {
29015 a1 = a; a &= ~3;
29016 if ((c = h->cmpQ) == NULL)
29017 {
29018 @@ -1449,11 +1449,11 @@ static int sendcmd(
29019 /*
29020 * Disable interrupt
29021 */
29022 - info_p->access.set_intr_mask(info_p, 0);
29023 + info_p->access->set_intr_mask(info_p, 0);
29024 /* Make sure there is room in the command FIFO */
29025 /* Actually it should be completely empty at this time. */
29026 for (i = 200000; i > 0; i--) {
29027 - temp = info_p->access.fifo_full(info_p);
29028 + temp = info_p->access->fifo_full(info_p);
29029 if (temp != 0) {
29030 break;
29031 }
29032 @@ -1466,7 +1466,7 @@ DBG(
29033 /*
29034 * Send the cmd
29035 */
29036 - info_p->access.submit_command(info_p, c);
29037 + info_p->access->submit_command(info_p, c);
29038 complete = pollcomplete(ctlr);
29039
29040 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29041 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29042 * we check the new geometry. Then turn interrupts back on when
29043 * we're done.
29044 */
29045 - host->access.set_intr_mask(host, 0);
29046 + host->access->set_intr_mask(host, 0);
29047 getgeometry(ctlr);
29048 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29049 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29050
29051 for(i=0; i<NWD; i++) {
29052 struct gendisk *disk = ida_gendisk[ctlr][i];
29053 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29054 /* Wait (up to 2 seconds) for a command to complete */
29055
29056 for (i = 200000; i > 0; i--) {
29057 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
29058 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
29059 if (done == 0) {
29060 udelay(10); /* a short fixed delay */
29061 } else
29062 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29063 index be73e9d..7fbf140 100644
29064 --- a/drivers/block/cpqarray.h
29065 +++ b/drivers/block/cpqarray.h
29066 @@ -99,7 +99,7 @@ struct ctlr_info {
29067 drv_info_t drv[NWD];
29068 struct proc_dir_entry *proc;
29069
29070 - struct access_method access;
29071 + struct access_method *access;
29072
29073 cmdlist_t *reqQ;
29074 cmdlist_t *cmpQ;
29075 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29076 index 8d68056..e67050f 100644
29077 --- a/drivers/block/drbd/drbd_int.h
29078 +++ b/drivers/block/drbd/drbd_int.h
29079 @@ -736,7 +736,7 @@ struct drbd_request;
29080 struct drbd_epoch {
29081 struct list_head list;
29082 unsigned int barrier_nr;
29083 - atomic_t epoch_size; /* increased on every request added. */
29084 + atomic_unchecked_t epoch_size; /* increased on every request added. */
29085 atomic_t active; /* increased on every req. added, and dec on every finished. */
29086 unsigned long flags;
29087 };
29088 @@ -1108,7 +1108,7 @@ struct drbd_conf {
29089 void *int_dig_in;
29090 void *int_dig_vv;
29091 wait_queue_head_t seq_wait;
29092 - atomic_t packet_seq;
29093 + atomic_unchecked_t packet_seq;
29094 unsigned int peer_seq;
29095 spinlock_t peer_seq_lock;
29096 unsigned int minor;
29097 @@ -1617,30 +1617,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29098
29099 static inline void drbd_tcp_cork(struct socket *sock)
29100 {
29101 - int __user val = 1;
29102 + int val = 1;
29103 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29104 - (char __user *)&val, sizeof(val));
29105 + (char __force_user *)&val, sizeof(val));
29106 }
29107
29108 static inline void drbd_tcp_uncork(struct socket *sock)
29109 {
29110 - int __user val = 0;
29111 + int val = 0;
29112 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29113 - (char __user *)&val, sizeof(val));
29114 + (char __force_user *)&val, sizeof(val));
29115 }
29116
29117 static inline void drbd_tcp_nodelay(struct socket *sock)
29118 {
29119 - int __user val = 1;
29120 + int val = 1;
29121 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29122 - (char __user *)&val, sizeof(val));
29123 + (char __force_user *)&val, sizeof(val));
29124 }
29125
29126 static inline void drbd_tcp_quickack(struct socket *sock)
29127 {
29128 - int __user val = 2;
29129 + int val = 2;
29130 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29131 - (char __user *)&val, sizeof(val));
29132 + (char __force_user *)&val, sizeof(val));
29133 }
29134
29135 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29136 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29137 index 211fc44..c5116f1 100644
29138 --- a/drivers/block/drbd/drbd_main.c
29139 +++ b/drivers/block/drbd/drbd_main.c
29140 @@ -2397,7 +2397,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29141 p.sector = sector;
29142 p.block_id = block_id;
29143 p.blksize = blksize;
29144 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29145 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29146
29147 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29148 return false;
29149 @@ -2696,7 +2696,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29150 p.sector = cpu_to_be64(req->sector);
29151 p.block_id = (unsigned long)req;
29152 p.seq_num = cpu_to_be32(req->seq_num =
29153 - atomic_add_return(1, &mdev->packet_seq));
29154 + atomic_add_return_unchecked(1, &mdev->packet_seq));
29155
29156 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29157
29158 @@ -2981,7 +2981,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29159 atomic_set(&mdev->unacked_cnt, 0);
29160 atomic_set(&mdev->local_cnt, 0);
29161 atomic_set(&mdev->net_cnt, 0);
29162 - atomic_set(&mdev->packet_seq, 0);
29163 + atomic_set_unchecked(&mdev->packet_seq, 0);
29164 atomic_set(&mdev->pp_in_use, 0);
29165 atomic_set(&mdev->pp_in_use_by_net, 0);
29166 atomic_set(&mdev->rs_sect_in, 0);
29167 @@ -3063,8 +3063,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29168 mdev->receiver.t_state);
29169
29170 /* no need to lock it, I'm the only thread alive */
29171 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29172 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29173 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29174 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29175 mdev->al_writ_cnt =
29176 mdev->bm_writ_cnt =
29177 mdev->read_cnt =
29178 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29179 index 946166e..356b39a 100644
29180 --- a/drivers/block/drbd/drbd_nl.c
29181 +++ b/drivers/block/drbd/drbd_nl.c
29182 @@ -2359,7 +2359,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29183 module_put(THIS_MODULE);
29184 }
29185
29186 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29187 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29188
29189 static unsigned short *
29190 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29191 @@ -2430,7 +2430,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29192 cn_reply->id.idx = CN_IDX_DRBD;
29193 cn_reply->id.val = CN_VAL_DRBD;
29194
29195 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29196 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29197 cn_reply->ack = 0; /* not used here. */
29198 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29199 (int)((char *)tl - (char *)reply->tag_list);
29200 @@ -2462,7 +2462,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29201 cn_reply->id.idx = CN_IDX_DRBD;
29202 cn_reply->id.val = CN_VAL_DRBD;
29203
29204 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29205 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29206 cn_reply->ack = 0; /* not used here. */
29207 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29208 (int)((char *)tl - (char *)reply->tag_list);
29209 @@ -2540,7 +2540,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29210 cn_reply->id.idx = CN_IDX_DRBD;
29211 cn_reply->id.val = CN_VAL_DRBD;
29212
29213 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29214 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29215 cn_reply->ack = 0; // not used here.
29216 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29217 (int)((char*)tl - (char*)reply->tag_list);
29218 @@ -2579,7 +2579,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29219 cn_reply->id.idx = CN_IDX_DRBD;
29220 cn_reply->id.val = CN_VAL_DRBD;
29221
29222 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29223 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29224 cn_reply->ack = 0; /* not used here. */
29225 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29226 (int)((char *)tl - (char *)reply->tag_list);
29227 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29228 index 43beaca..4a5b1dd 100644
29229 --- a/drivers/block/drbd/drbd_receiver.c
29230 +++ b/drivers/block/drbd/drbd_receiver.c
29231 @@ -894,7 +894,7 @@ retry:
29232 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29233 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29234
29235 - atomic_set(&mdev->packet_seq, 0);
29236 + atomic_set_unchecked(&mdev->packet_seq, 0);
29237 mdev->peer_seq = 0;
29238
29239 drbd_thread_start(&mdev->asender);
29240 @@ -985,7 +985,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29241 do {
29242 next_epoch = NULL;
29243
29244 - epoch_size = atomic_read(&epoch->epoch_size);
29245 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29246
29247 switch (ev & ~EV_CLEANUP) {
29248 case EV_PUT:
29249 @@ -1020,7 +1020,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29250 rv = FE_DESTROYED;
29251 } else {
29252 epoch->flags = 0;
29253 - atomic_set(&epoch->epoch_size, 0);
29254 + atomic_set_unchecked(&epoch->epoch_size, 0);
29255 /* atomic_set(&epoch->active, 0); is already zero */
29256 if (rv == FE_STILL_LIVE)
29257 rv = FE_RECYCLED;
29258 @@ -1191,14 +1191,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29259 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29260 drbd_flush(mdev);
29261
29262 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29263 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29264 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29265 if (epoch)
29266 break;
29267 }
29268
29269 epoch = mdev->current_epoch;
29270 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29271 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29272
29273 D_ASSERT(atomic_read(&epoch->active) == 0);
29274 D_ASSERT(epoch->flags == 0);
29275 @@ -1210,11 +1210,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29276 }
29277
29278 epoch->flags = 0;
29279 - atomic_set(&epoch->epoch_size, 0);
29280 + atomic_set_unchecked(&epoch->epoch_size, 0);
29281 atomic_set(&epoch->active, 0);
29282
29283 spin_lock(&mdev->epoch_lock);
29284 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29285 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29286 list_add(&epoch->list, &mdev->current_epoch->list);
29287 mdev->current_epoch = epoch;
29288 mdev->epochs++;
29289 @@ -1663,7 +1663,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29290 spin_unlock(&mdev->peer_seq_lock);
29291
29292 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29293 - atomic_inc(&mdev->current_epoch->epoch_size);
29294 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29295 return drbd_drain_block(mdev, data_size);
29296 }
29297
29298 @@ -1689,7 +1689,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29299
29300 spin_lock(&mdev->epoch_lock);
29301 e->epoch = mdev->current_epoch;
29302 - atomic_inc(&e->epoch->epoch_size);
29303 + atomic_inc_unchecked(&e->epoch->epoch_size);
29304 atomic_inc(&e->epoch->active);
29305 spin_unlock(&mdev->epoch_lock);
29306
29307 @@ -3885,7 +3885,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29308 D_ASSERT(list_empty(&mdev->done_ee));
29309
29310 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29311 - atomic_set(&mdev->current_epoch->epoch_size, 0);
29312 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29313 D_ASSERT(list_empty(&mdev->current_epoch->list));
29314 }
29315
29316 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29317 index bbca966..65e37dd 100644
29318 --- a/drivers/block/loop.c
29319 +++ b/drivers/block/loop.c
29320 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29321 mm_segment_t old_fs = get_fs();
29322
29323 set_fs(get_ds());
29324 - bw = file->f_op->write(file, buf, len, &pos);
29325 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29326 set_fs(old_fs);
29327 if (likely(bw == len))
29328 return 0;
29329 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29330 index ee94686..3e09ad3 100644
29331 --- a/drivers/char/Kconfig
29332 +++ b/drivers/char/Kconfig
29333 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29334
29335 config DEVKMEM
29336 bool "/dev/kmem virtual device support"
29337 - default y
29338 + default n
29339 + depends on !GRKERNSEC_KMEM
29340 help
29341 Say Y here if you want to support the /dev/kmem device. The
29342 /dev/kmem device is rarely used, but can be used for certain
29343 @@ -581,6 +582,7 @@ config DEVPORT
29344 bool
29345 depends on !M68K
29346 depends on ISA || PCI
29347 + depends on !GRKERNSEC_KMEM
29348 default y
29349
29350 source "drivers/s390/char/Kconfig"
29351 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29352 index 2e04433..22afc64 100644
29353 --- a/drivers/char/agp/frontend.c
29354 +++ b/drivers/char/agp/frontend.c
29355 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29356 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29357 return -EFAULT;
29358
29359 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29360 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29361 return -EFAULT;
29362
29363 client = agp_find_client_by_pid(reserve.pid);
29364 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29365 index 21cb980..f15107c 100644
29366 --- a/drivers/char/genrtc.c
29367 +++ b/drivers/char/genrtc.c
29368 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29369 switch (cmd) {
29370
29371 case RTC_PLL_GET:
29372 + memset(&pll, 0, sizeof(pll));
29373 if (get_rtc_pll(&pll))
29374 return -EINVAL;
29375 else
29376 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29377 index dfd7876..c0b0885 100644
29378 --- a/drivers/char/hpet.c
29379 +++ b/drivers/char/hpet.c
29380 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29381 }
29382
29383 static int
29384 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29385 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29386 struct hpet_info *info)
29387 {
29388 struct hpet_timer __iomem *timer;
29389 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29390 index 2c29942..604c5ba 100644
29391 --- a/drivers/char/ipmi/ipmi_msghandler.c
29392 +++ b/drivers/char/ipmi/ipmi_msghandler.c
29393 @@ -420,7 +420,7 @@ struct ipmi_smi {
29394 struct proc_dir_entry *proc_dir;
29395 char proc_dir_name[10];
29396
29397 - atomic_t stats[IPMI_NUM_STATS];
29398 + atomic_unchecked_t stats[IPMI_NUM_STATS];
29399
29400 /*
29401 * run_to_completion duplicate of smb_info, smi_info
29402 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29403
29404
29405 #define ipmi_inc_stat(intf, stat) \
29406 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29407 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29408 #define ipmi_get_stat(intf, stat) \
29409 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29410 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29411
29412 static int is_lan_addr(struct ipmi_addr *addr)
29413 {
29414 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29415 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29416 init_waitqueue_head(&intf->waitq);
29417 for (i = 0; i < IPMI_NUM_STATS; i++)
29418 - atomic_set(&intf->stats[i], 0);
29419 + atomic_set_unchecked(&intf->stats[i], 0);
29420
29421 intf->proc_dir = NULL;
29422
29423 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29424 index 1e638ff..a869ef5 100644
29425 --- a/drivers/char/ipmi/ipmi_si_intf.c
29426 +++ b/drivers/char/ipmi/ipmi_si_intf.c
29427 @@ -275,7 +275,7 @@ struct smi_info {
29428 unsigned char slave_addr;
29429
29430 /* Counters and things for the proc filesystem. */
29431 - atomic_t stats[SI_NUM_STATS];
29432 + atomic_unchecked_t stats[SI_NUM_STATS];
29433
29434 struct task_struct *thread;
29435
29436 @@ -284,9 +284,9 @@ struct smi_info {
29437 };
29438
29439 #define smi_inc_stat(smi, stat) \
29440 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29441 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29442 #define smi_get_stat(smi, stat) \
29443 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29444 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29445
29446 #define SI_MAX_PARMS 4
29447
29448 @@ -3209,7 +3209,7 @@ static int try_smi_init(struct smi_info *new_smi)
29449 atomic_set(&new_smi->req_events, 0);
29450 new_smi->run_to_completion = 0;
29451 for (i = 0; i < SI_NUM_STATS; i++)
29452 - atomic_set(&new_smi->stats[i], 0);
29453 + atomic_set_unchecked(&new_smi->stats[i], 0);
29454
29455 new_smi->interrupt_disabled = 1;
29456 atomic_set(&new_smi->stop_operation, 0);
29457 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29458 index 47ff7e4..0c7d340 100644
29459 --- a/drivers/char/mbcs.c
29460 +++ b/drivers/char/mbcs.c
29461 @@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29462 return 0;
29463 }
29464
29465 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29466 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29467 {
29468 .part_num = MBCS_PART_NUM,
29469 .mfg_num = MBCS_MFG_NUM,
29470 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29471 index d6e9d08..4493e89 100644
29472 --- a/drivers/char/mem.c
29473 +++ b/drivers/char/mem.c
29474 @@ -18,6 +18,7 @@
29475 #include <linux/raw.h>
29476 #include <linux/tty.h>
29477 #include <linux/capability.h>
29478 +#include <linux/security.h>
29479 #include <linux/ptrace.h>
29480 #include <linux/device.h>
29481 #include <linux/highmem.h>
29482 @@ -35,6 +36,10 @@
29483 # include <linux/efi.h>
29484 #endif
29485
29486 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29487 +extern const struct file_operations grsec_fops;
29488 +#endif
29489 +
29490 static inline unsigned long size_inside_page(unsigned long start,
29491 unsigned long size)
29492 {
29493 @@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29494
29495 while (cursor < to) {
29496 if (!devmem_is_allowed(pfn)) {
29497 +#ifdef CONFIG_GRKERNSEC_KMEM
29498 + gr_handle_mem_readwrite(from, to);
29499 +#else
29500 printk(KERN_INFO
29501 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29502 current->comm, from, to);
29503 +#endif
29504 return 0;
29505 }
29506 cursor += PAGE_SIZE;
29507 @@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29508 }
29509 return 1;
29510 }
29511 +#elif defined(CONFIG_GRKERNSEC_KMEM)
29512 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29513 +{
29514 + return 0;
29515 +}
29516 #else
29517 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29518 {
29519 @@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29520
29521 while (count > 0) {
29522 unsigned long remaining;
29523 + char *temp;
29524
29525 sz = size_inside_page(p, count);
29526
29527 @@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29528 if (!ptr)
29529 return -EFAULT;
29530
29531 - remaining = copy_to_user(buf, ptr, sz);
29532 +#ifdef CONFIG_PAX_USERCOPY
29533 + temp = kmalloc(sz, GFP_KERNEL);
29534 + if (!temp) {
29535 + unxlate_dev_mem_ptr(p, ptr);
29536 + return -ENOMEM;
29537 + }
29538 + memcpy(temp, ptr, sz);
29539 +#else
29540 + temp = ptr;
29541 +#endif
29542 +
29543 + remaining = copy_to_user(buf, temp, sz);
29544 +
29545 +#ifdef CONFIG_PAX_USERCOPY
29546 + kfree(temp);
29547 +#endif
29548 +
29549 unxlate_dev_mem_ptr(p, ptr);
29550 if (remaining)
29551 return -EFAULT;
29552 @@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29553 size_t count, loff_t *ppos)
29554 {
29555 unsigned long p = *ppos;
29556 - ssize_t low_count, read, sz;
29557 + ssize_t low_count, read, sz, err = 0;
29558 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29559 - int err = 0;
29560
29561 read = 0;
29562 if (p < (unsigned long) high_memory) {
29563 @@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29564 }
29565 #endif
29566 while (low_count > 0) {
29567 + char *temp;
29568 +
29569 sz = size_inside_page(p, low_count);
29570
29571 /*
29572 @@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29573 */
29574 kbuf = xlate_dev_kmem_ptr((char *)p);
29575
29576 - if (copy_to_user(buf, kbuf, sz))
29577 +#ifdef CONFIG_PAX_USERCOPY
29578 + temp = kmalloc(sz, GFP_KERNEL);
29579 + if (!temp)
29580 + return -ENOMEM;
29581 + memcpy(temp, kbuf, sz);
29582 +#else
29583 + temp = kbuf;
29584 +#endif
29585 +
29586 + err = copy_to_user(buf, temp, sz);
29587 +
29588 +#ifdef CONFIG_PAX_USERCOPY
29589 + kfree(temp);
29590 +#endif
29591 +
29592 + if (err)
29593 return -EFAULT;
29594 buf += sz;
29595 p += sz;
29596 @@ -867,6 +914,9 @@ static const struct memdev {
29597 #ifdef CONFIG_CRASH_DUMP
29598 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29599 #endif
29600 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29601 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29602 +#endif
29603 };
29604
29605 static int memory_open(struct inode *inode, struct file *filp)
29606 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29607 index 9df78e2..01ba9ae 100644
29608 --- a/drivers/char/nvram.c
29609 +++ b/drivers/char/nvram.c
29610 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29611
29612 spin_unlock_irq(&rtc_lock);
29613
29614 - if (copy_to_user(buf, contents, tmp - contents))
29615 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29616 return -EFAULT;
29617
29618 *ppos = i;
29619 diff --git a/drivers/char/random.c b/drivers/char/random.c
29620 index 4ec04a7..4a092ed 100644
29621 --- a/drivers/char/random.c
29622 +++ b/drivers/char/random.c
29623 @@ -261,8 +261,13 @@
29624 /*
29625 * Configuration information
29626 */
29627 +#ifdef CONFIG_GRKERNSEC_RANDNET
29628 +#define INPUT_POOL_WORDS 512
29629 +#define OUTPUT_POOL_WORDS 128
29630 +#else
29631 #define INPUT_POOL_WORDS 128
29632 #define OUTPUT_POOL_WORDS 32
29633 +#endif
29634 #define SEC_XFER_SIZE 512
29635 #define EXTRACT_SIZE 10
29636
29637 @@ -300,10 +305,17 @@ static struct poolinfo {
29638 int poolwords;
29639 int tap1, tap2, tap3, tap4, tap5;
29640 } poolinfo_table[] = {
29641 +#ifdef CONFIG_GRKERNSEC_RANDNET
29642 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29643 + { 512, 411, 308, 208, 104, 1 },
29644 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29645 + { 128, 103, 76, 51, 25, 1 },
29646 +#else
29647 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29648 { 128, 103, 76, 51, 25, 1 },
29649 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29650 { 32, 26, 20, 14, 7, 1 },
29651 +#endif
29652 #if 0
29653 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29654 { 2048, 1638, 1231, 819, 411, 1 },
29655 @@ -913,7 +925,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29656
29657 extract_buf(r, tmp);
29658 i = min_t(int, nbytes, EXTRACT_SIZE);
29659 - if (copy_to_user(buf, tmp, i)) {
29660 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29661 ret = -EFAULT;
29662 break;
29663 }
29664 @@ -1238,7 +1250,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29665 #include <linux/sysctl.h>
29666
29667 static int min_read_thresh = 8, min_write_thresh;
29668 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
29669 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29670 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29671 static char sysctl_bootid[16];
29672
29673 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
29674 index 45713f0..8286d21 100644
29675 --- a/drivers/char/sonypi.c
29676 +++ b/drivers/char/sonypi.c
29677 @@ -54,6 +54,7 @@
29678
29679 #include <asm/uaccess.h>
29680 #include <asm/io.h>
29681 +#include <asm/local.h>
29682
29683 #include <linux/sonypi.h>
29684
29685 @@ -490,7 +491,7 @@ static struct sonypi_device {
29686 spinlock_t fifo_lock;
29687 wait_queue_head_t fifo_proc_list;
29688 struct fasync_struct *fifo_async;
29689 - int open_count;
29690 + local_t open_count;
29691 int model;
29692 struct input_dev *input_jog_dev;
29693 struct input_dev *input_key_dev;
29694 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
29695 static int sonypi_misc_release(struct inode *inode, struct file *file)
29696 {
29697 mutex_lock(&sonypi_device.lock);
29698 - sonypi_device.open_count--;
29699 + local_dec(&sonypi_device.open_count);
29700 mutex_unlock(&sonypi_device.lock);
29701 return 0;
29702 }
29703 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
29704 {
29705 mutex_lock(&sonypi_device.lock);
29706 /* Flush input queue on first open */
29707 - if (!sonypi_device.open_count)
29708 + if (!local_read(&sonypi_device.open_count))
29709 kfifo_reset(&sonypi_device.fifo);
29710 - sonypi_device.open_count++;
29711 + local_inc(&sonypi_device.open_count);
29712 mutex_unlock(&sonypi_device.lock);
29713
29714 return 0;
29715 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
29716 index ad7c732..5aa8054 100644
29717 --- a/drivers/char/tpm/tpm.c
29718 +++ b/drivers/char/tpm/tpm.c
29719 @@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
29720 chip->vendor.req_complete_val)
29721 goto out_recv;
29722
29723 - if ((status == chip->vendor.req_canceled)) {
29724 + if (status == chip->vendor.req_canceled) {
29725 dev_err(chip->dev, "Operation Canceled\n");
29726 rc = -ECANCELED;
29727 goto out;
29728 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
29729 index 0636520..169c1d0 100644
29730 --- a/drivers/char/tpm/tpm_bios.c
29731 +++ b/drivers/char/tpm/tpm_bios.c
29732 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
29733 event = addr;
29734
29735 if ((event->event_type == 0 && event->event_size == 0) ||
29736 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
29737 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
29738 return NULL;
29739
29740 return addr;
29741 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
29742 return NULL;
29743
29744 if ((event->event_type == 0 && event->event_size == 0) ||
29745 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
29746 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
29747 return NULL;
29748
29749 (*pos)++;
29750 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
29751 int i;
29752
29753 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
29754 - seq_putc(m, data[i]);
29755 + if (!seq_putc(m, data[i]))
29756 + return -EFAULT;
29757
29758 return 0;
29759 }
29760 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
29761 log->bios_event_log_end = log->bios_event_log + len;
29762
29763 virt = acpi_os_map_memory(start, len);
29764 + if (!virt) {
29765 + kfree(log->bios_event_log);
29766 + log->bios_event_log = NULL;
29767 + return -EFAULT;
29768 + }
29769
29770 - memcpy(log->bios_event_log, virt, len);
29771 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
29772
29773 acpi_os_unmap_memory(virt, len);
29774 return 0;
29775 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
29776 index cdf2f54..e55c197 100644
29777 --- a/drivers/char/virtio_console.c
29778 +++ b/drivers/char/virtio_console.c
29779 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
29780 if (to_user) {
29781 ssize_t ret;
29782
29783 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
29784 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
29785 if (ret)
29786 return -EFAULT;
29787 } else {
29788 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
29789 if (!port_has_data(port) && !port->host_connected)
29790 return 0;
29791
29792 - return fill_readbuf(port, ubuf, count, true);
29793 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
29794 }
29795
29796 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
29797 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
29798 index 97f5064..202b6e6 100644
29799 --- a/drivers/edac/edac_pci_sysfs.c
29800 +++ b/drivers/edac/edac_pci_sysfs.c
29801 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
29802 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
29803 static int edac_pci_poll_msec = 1000; /* one second workq period */
29804
29805 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
29806 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
29807 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
29808 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
29809
29810 static struct kobject *edac_pci_top_main_kobj;
29811 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
29812 @@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29813 edac_printk(KERN_CRIT, EDAC_PCI,
29814 "Signaled System Error on %s\n",
29815 pci_name(dev));
29816 - atomic_inc(&pci_nonparity_count);
29817 + atomic_inc_unchecked(&pci_nonparity_count);
29818 }
29819
29820 if (status & (PCI_STATUS_PARITY)) {
29821 @@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29822 "Master Data Parity Error on %s\n",
29823 pci_name(dev));
29824
29825 - atomic_inc(&pci_parity_count);
29826 + atomic_inc_unchecked(&pci_parity_count);
29827 }
29828
29829 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29830 @@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29831 "Detected Parity Error on %s\n",
29832 pci_name(dev));
29833
29834 - atomic_inc(&pci_parity_count);
29835 + atomic_inc_unchecked(&pci_parity_count);
29836 }
29837 }
29838
29839 @@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29840 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
29841 "Signaled System Error on %s\n",
29842 pci_name(dev));
29843 - atomic_inc(&pci_nonparity_count);
29844 + atomic_inc_unchecked(&pci_nonparity_count);
29845 }
29846
29847 if (status & (PCI_STATUS_PARITY)) {
29848 @@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29849 "Master Data Parity Error on "
29850 "%s\n", pci_name(dev));
29851
29852 - atomic_inc(&pci_parity_count);
29853 + atomic_inc_unchecked(&pci_parity_count);
29854 }
29855
29856 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29857 @@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29858 "Detected Parity Error on %s\n",
29859 pci_name(dev));
29860
29861 - atomic_inc(&pci_parity_count);
29862 + atomic_inc_unchecked(&pci_parity_count);
29863 }
29864 }
29865 }
29866 @@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
29867 if (!check_pci_errors)
29868 return;
29869
29870 - before_count = atomic_read(&pci_parity_count);
29871 + before_count = atomic_read_unchecked(&pci_parity_count);
29872
29873 /* scan all PCI devices looking for a Parity Error on devices and
29874 * bridges.
29875 @@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
29876 /* Only if operator has selected panic on PCI Error */
29877 if (edac_pci_get_panic_on_pe()) {
29878 /* If the count is different 'after' from 'before' */
29879 - if (before_count != atomic_read(&pci_parity_count))
29880 + if (before_count != atomic_read_unchecked(&pci_parity_count))
29881 panic("EDAC: PCI Parity Error");
29882 }
29883 }
29884 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
29885 index c6074c5..88a9e2e 100644
29886 --- a/drivers/edac/mce_amd.h
29887 +++ b/drivers/edac/mce_amd.h
29888 @@ -82,7 +82,7 @@ extern const char * const ii_msgs[];
29889 struct amd_decoder_ops {
29890 bool (*dc_mce)(u16, u8);
29891 bool (*ic_mce)(u16, u8);
29892 -};
29893 +} __no_const;
29894
29895 void amd_report_gart_errors(bool);
29896 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
29897 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
29898 index cc595eb..4ec702a 100644
29899 --- a/drivers/firewire/core-card.c
29900 +++ b/drivers/firewire/core-card.c
29901 @@ -679,7 +679,7 @@ void fw_card_release(struct kref *kref)
29902
29903 void fw_core_remove_card(struct fw_card *card)
29904 {
29905 - struct fw_card_driver dummy_driver = dummy_driver_template;
29906 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
29907
29908 card->driver->update_phy_reg(card, 4,
29909 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
29910 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
29911 index 2e6b245..c3857d9 100644
29912 --- a/drivers/firewire/core-cdev.c
29913 +++ b/drivers/firewire/core-cdev.c
29914 @@ -1341,8 +1341,7 @@ static int init_iso_resource(struct client *client,
29915 int ret;
29916
29917 if ((request->channels == 0 && request->bandwidth == 0) ||
29918 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
29919 - request->bandwidth < 0)
29920 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
29921 return -EINVAL;
29922
29923 r = kmalloc(sizeof(*r), GFP_KERNEL);
29924 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
29925 index dea2dcc..a4fb978 100644
29926 --- a/drivers/firewire/core-transaction.c
29927 +++ b/drivers/firewire/core-transaction.c
29928 @@ -37,6 +37,7 @@
29929 #include <linux/timer.h>
29930 #include <linux/types.h>
29931 #include <linux/workqueue.h>
29932 +#include <linux/sched.h>
29933
29934 #include <asm/byteorder.h>
29935
29936 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
29937 index 9047f55..e47c7ff 100644
29938 --- a/drivers/firewire/core.h
29939 +++ b/drivers/firewire/core.h
29940 @@ -110,6 +110,7 @@ struct fw_card_driver {
29941
29942 int (*stop_iso)(struct fw_iso_context *ctx);
29943 };
29944 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
29945
29946 void fw_card_initialize(struct fw_card *card,
29947 const struct fw_card_driver *driver, struct device *device);
29948 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
29949 index 153980b..4b4d046 100644
29950 --- a/drivers/firmware/dmi_scan.c
29951 +++ b/drivers/firmware/dmi_scan.c
29952 @@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
29953 }
29954 }
29955 else {
29956 - /*
29957 - * no iounmap() for that ioremap(); it would be a no-op, but
29958 - * it's so early in setup that sucker gets confused into doing
29959 - * what it shouldn't if we actually call it.
29960 - */
29961 p = dmi_ioremap(0xF0000, 0x10000);
29962 if (p == NULL)
29963 goto error;
29964 @@ -723,7 +718,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
29965 if (buf == NULL)
29966 return -1;
29967
29968 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
29969 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
29970
29971 iounmap(buf);
29972 return 0;
29973 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
29974 index 82d5c20..44a7177 100644
29975 --- a/drivers/gpio/gpio-vr41xx.c
29976 +++ b/drivers/gpio/gpio-vr41xx.c
29977 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
29978 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
29979 maskl, pendl, maskh, pendh);
29980
29981 - atomic_inc(&irq_err_count);
29982 + atomic_inc_unchecked(&irq_err_count);
29983
29984 return -EINVAL;
29985 }
29986 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
29987 index 8111889..367b253 100644
29988 --- a/drivers/gpu/drm/drm_crtc_helper.c
29989 +++ b/drivers/gpu/drm/drm_crtc_helper.c
29990 @@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
29991 struct drm_crtc *tmp;
29992 int crtc_mask = 1;
29993
29994 - WARN(!crtc, "checking null crtc?\n");
29995 + BUG_ON(!crtc);
29996
29997 dev = crtc->dev;
29998
29999 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30000 index 6116e3b..c29dd16 100644
30001 --- a/drivers/gpu/drm/drm_drv.c
30002 +++ b/drivers/gpu/drm/drm_drv.c
30003 @@ -316,7 +316,7 @@ module_exit(drm_core_exit);
30004 /**
30005 * Copy and IOCTL return string to user space
30006 */
30007 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30008 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30009 {
30010 int len;
30011
30012 @@ -399,7 +399,7 @@ long drm_ioctl(struct file *filp,
30013 return -ENODEV;
30014
30015 atomic_inc(&dev->ioctl_count);
30016 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30017 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30018 ++file_priv->ioctl_count;
30019
30020 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30021 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30022 index 123de28..43a0897 100644
30023 --- a/drivers/gpu/drm/drm_fops.c
30024 +++ b/drivers/gpu/drm/drm_fops.c
30025 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30026 }
30027
30028 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30029 - atomic_set(&dev->counts[i], 0);
30030 + atomic_set_unchecked(&dev->counts[i], 0);
30031
30032 dev->sigdata.lock = NULL;
30033
30034 @@ -138,8 +138,8 @@ int drm_open(struct inode *inode, struct file *filp)
30035
30036 retcode = drm_open_helper(inode, filp, dev);
30037 if (!retcode) {
30038 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30039 - if (!dev->open_count++)
30040 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30041 + if (local_inc_return(&dev->open_count) == 1)
30042 retcode = drm_setup(dev);
30043 }
30044 if (!retcode) {
30045 @@ -482,7 +482,7 @@ int drm_release(struct inode *inode, struct file *filp)
30046
30047 mutex_lock(&drm_global_mutex);
30048
30049 - DRM_DEBUG("open_count = %d\n", dev->open_count);
30050 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30051
30052 if (dev->driver->preclose)
30053 dev->driver->preclose(dev, file_priv);
30054 @@ -491,10 +491,10 @@ int drm_release(struct inode *inode, struct file *filp)
30055 * Begin inline drm_release
30056 */
30057
30058 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30059 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30060 task_pid_nr(current),
30061 (long)old_encode_dev(file_priv->minor->device),
30062 - dev->open_count);
30063 + local_read(&dev->open_count));
30064
30065 /* Release any auth tokens that might point to this file_priv,
30066 (do that under the drm_global_mutex) */
30067 @@ -584,8 +584,8 @@ int drm_release(struct inode *inode, struct file *filp)
30068 * End inline drm_release
30069 */
30070
30071 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30072 - if (!--dev->open_count) {
30073 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30074 + if (local_dec_and_test(&dev->open_count)) {
30075 if (atomic_read(&dev->ioctl_count)) {
30076 DRM_ERROR("Device busy: %d\n",
30077 atomic_read(&dev->ioctl_count));
30078 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30079 index c87dc96..326055d 100644
30080 --- a/drivers/gpu/drm/drm_global.c
30081 +++ b/drivers/gpu/drm/drm_global.c
30082 @@ -36,7 +36,7 @@
30083 struct drm_global_item {
30084 struct mutex mutex;
30085 void *object;
30086 - int refcount;
30087 + atomic_t refcount;
30088 };
30089
30090 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30091 @@ -49,7 +49,7 @@ void drm_global_init(void)
30092 struct drm_global_item *item = &glob[i];
30093 mutex_init(&item->mutex);
30094 item->object = NULL;
30095 - item->refcount = 0;
30096 + atomic_set(&item->refcount, 0);
30097 }
30098 }
30099
30100 @@ -59,7 +59,7 @@ void drm_global_release(void)
30101 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30102 struct drm_global_item *item = &glob[i];
30103 BUG_ON(item->object != NULL);
30104 - BUG_ON(item->refcount != 0);
30105 + BUG_ON(atomic_read(&item->refcount) != 0);
30106 }
30107 }
30108
30109 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30110 void *object;
30111
30112 mutex_lock(&item->mutex);
30113 - if (item->refcount == 0) {
30114 + if (atomic_read(&item->refcount) == 0) {
30115 item->object = kzalloc(ref->size, GFP_KERNEL);
30116 if (unlikely(item->object == NULL)) {
30117 ret = -ENOMEM;
30118 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30119 goto out_err;
30120
30121 }
30122 - ++item->refcount;
30123 + atomic_inc(&item->refcount);
30124 ref->object = item->object;
30125 object = item->object;
30126 mutex_unlock(&item->mutex);
30127 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30128 struct drm_global_item *item = &glob[ref->global_type];
30129
30130 mutex_lock(&item->mutex);
30131 - BUG_ON(item->refcount == 0);
30132 + BUG_ON(atomic_read(&item->refcount) == 0);
30133 BUG_ON(ref->object != item->object);
30134 - if (--item->refcount == 0) {
30135 + if (atomic_dec_and_test(&item->refcount)) {
30136 ref->release(ref);
30137 item->object = NULL;
30138 }
30139 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30140 index ab1162d..42587b2 100644
30141 --- a/drivers/gpu/drm/drm_info.c
30142 +++ b/drivers/gpu/drm/drm_info.c
30143 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30144 struct drm_local_map *map;
30145 struct drm_map_list *r_list;
30146
30147 - /* Hardcoded from _DRM_FRAME_BUFFER,
30148 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30149 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30150 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30151 + static const char * const types[] = {
30152 + [_DRM_FRAME_BUFFER] = "FB",
30153 + [_DRM_REGISTERS] = "REG",
30154 + [_DRM_SHM] = "SHM",
30155 + [_DRM_AGP] = "AGP",
30156 + [_DRM_SCATTER_GATHER] = "SG",
30157 + [_DRM_CONSISTENT] = "PCI",
30158 + [_DRM_GEM] = "GEM" };
30159 const char *type;
30160 int i;
30161
30162 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30163 map = r_list->map;
30164 if (!map)
30165 continue;
30166 - if (map->type < 0 || map->type > 5)
30167 + if (map->type >= ARRAY_SIZE(types))
30168 type = "??";
30169 else
30170 type = types[map->type];
30171 @@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30172 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30173 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30174 vma->vm_flags & VM_IO ? 'i' : '-',
30175 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30176 + 0);
30177 +#else
30178 vma->vm_pgoff);
30179 +#endif
30180
30181 #if defined(__i386__)
30182 pgprot = pgprot_val(vma->vm_page_prot);
30183 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30184 index 637fcc3..e890b33 100644
30185 --- a/drivers/gpu/drm/drm_ioc32.c
30186 +++ b/drivers/gpu/drm/drm_ioc32.c
30187 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30188 request = compat_alloc_user_space(nbytes);
30189 if (!access_ok(VERIFY_WRITE, request, nbytes))
30190 return -EFAULT;
30191 - list = (struct drm_buf_desc *) (request + 1);
30192 + list = (struct drm_buf_desc __user *) (request + 1);
30193
30194 if (__put_user(count, &request->count)
30195 || __put_user(list, &request->list))
30196 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30197 request = compat_alloc_user_space(nbytes);
30198 if (!access_ok(VERIFY_WRITE, request, nbytes))
30199 return -EFAULT;
30200 - list = (struct drm_buf_pub *) (request + 1);
30201 + list = (struct drm_buf_pub __user *) (request + 1);
30202
30203 if (__put_user(count, &request->count)
30204 || __put_user(list, &request->list))
30205 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30206 index cf85155..f2665cb 100644
30207 --- a/drivers/gpu/drm/drm_ioctl.c
30208 +++ b/drivers/gpu/drm/drm_ioctl.c
30209 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30210 stats->data[i].value =
30211 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30212 else
30213 - stats->data[i].value = atomic_read(&dev->counts[i]);
30214 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30215 stats->data[i].type = dev->types[i];
30216 }
30217
30218 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30219 index c79c713..2048588 100644
30220 --- a/drivers/gpu/drm/drm_lock.c
30221 +++ b/drivers/gpu/drm/drm_lock.c
30222 @@ -90,7 +90,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30223 if (drm_lock_take(&master->lock, lock->context)) {
30224 master->lock.file_priv = file_priv;
30225 master->lock.lock_time = jiffies;
30226 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30227 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30228 break; /* Got lock */
30229 }
30230
30231 @@ -161,7 +161,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30232 return -EINVAL;
30233 }
30234
30235 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30236 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30237
30238 if (drm_lock_free(&master->lock, lock->context)) {
30239 /* FIXME: Should really bail out here. */
30240 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30241 index aa454f8..6d38580 100644
30242 --- a/drivers/gpu/drm/drm_stub.c
30243 +++ b/drivers/gpu/drm/drm_stub.c
30244 @@ -512,7 +512,7 @@ void drm_unplug_dev(struct drm_device *dev)
30245
30246 drm_device_set_unplugged(dev);
30247
30248 - if (dev->open_count == 0) {
30249 + if (local_read(&dev->open_count) == 0) {
30250 drm_put_dev(dev);
30251 }
30252 mutex_unlock(&drm_global_mutex);
30253 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30254 index f920fb5..001c52d 100644
30255 --- a/drivers/gpu/drm/i810/i810_dma.c
30256 +++ b/drivers/gpu/drm/i810/i810_dma.c
30257 @@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30258 dma->buflist[vertex->idx],
30259 vertex->discard, vertex->used);
30260
30261 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30262 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30263 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30264 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30265 sarea_priv->last_enqueue = dev_priv->counter - 1;
30266 sarea_priv->last_dispatch = (int)hw_status[5];
30267
30268 @@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30269 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30270 mc->last_render);
30271
30272 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30273 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30274 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30275 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30276 sarea_priv->last_enqueue = dev_priv->counter - 1;
30277 sarea_priv->last_dispatch = (int)hw_status[5];
30278
30279 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30280 index c9339f4..f5e1b9d 100644
30281 --- a/drivers/gpu/drm/i810/i810_drv.h
30282 +++ b/drivers/gpu/drm/i810/i810_drv.h
30283 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30284 int page_flipping;
30285
30286 wait_queue_head_t irq_queue;
30287 - atomic_t irq_received;
30288 - atomic_t irq_emitted;
30289 + atomic_unchecked_t irq_received;
30290 + atomic_unchecked_t irq_emitted;
30291
30292 int front_offset;
30293 } drm_i810_private_t;
30294 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30295 index e6162a1..b2ff486 100644
30296 --- a/drivers/gpu/drm/i915/i915_debugfs.c
30297 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
30298 @@ -500,7 +500,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30299 I915_READ(GTIMR));
30300 }
30301 seq_printf(m, "Interrupts received: %d\n",
30302 - atomic_read(&dev_priv->irq_received));
30303 + atomic_read_unchecked(&dev_priv->irq_received));
30304 for (i = 0; i < I915_NUM_RINGS; i++) {
30305 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30306 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30307 @@ -1313,7 +1313,7 @@ static int i915_opregion(struct seq_file *m, void *unused)
30308 return ret;
30309
30310 if (opregion->header)
30311 - seq_write(m, opregion->header, OPREGION_SIZE);
30312 + seq_write(m, (const void __force_kernel *)opregion->header, OPREGION_SIZE);
30313
30314 mutex_unlock(&dev->struct_mutex);
30315
30316 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30317 index ba60f3c..e2dff7f 100644
30318 --- a/drivers/gpu/drm/i915/i915_dma.c
30319 +++ b/drivers/gpu/drm/i915/i915_dma.c
30320 @@ -1178,7 +1178,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30321 bool can_switch;
30322
30323 spin_lock(&dev->count_lock);
30324 - can_switch = (dev->open_count == 0);
30325 + can_switch = (local_read(&dev->open_count) == 0);
30326 spin_unlock(&dev->count_lock);
30327 return can_switch;
30328 }
30329 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30330 index 5fabc6c..0b08aa1 100644
30331 --- a/drivers/gpu/drm/i915/i915_drv.h
30332 +++ b/drivers/gpu/drm/i915/i915_drv.h
30333 @@ -240,7 +240,7 @@ struct drm_i915_display_funcs {
30334 /* render clock increase/decrease */
30335 /* display clock increase/decrease */
30336 /* pll clock increase/decrease */
30337 -};
30338 +} __no_const;
30339
30340 struct intel_device_info {
30341 u8 gen;
30342 @@ -350,7 +350,7 @@ typedef struct drm_i915_private {
30343 int current_page;
30344 int page_flipping;
30345
30346 - atomic_t irq_received;
30347 + atomic_unchecked_t irq_received;
30348
30349 /* protects the irq masks */
30350 spinlock_t irq_lock;
30351 @@ -937,7 +937,7 @@ struct drm_i915_gem_object {
30352 * will be page flipped away on the next vblank. When it
30353 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30354 */
30355 - atomic_t pending_flip;
30356 + atomic_unchecked_t pending_flip;
30357 };
30358
30359 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30360 @@ -1359,7 +1359,7 @@ extern int intel_setup_gmbus(struct drm_device *dev);
30361 extern void intel_teardown_gmbus(struct drm_device *dev);
30362 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30363 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30364 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30365 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30366 {
30367 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30368 }
30369 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30370 index de43194..a14c4cc 100644
30371 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30372 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30373 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30374 i915_gem_clflush_object(obj);
30375
30376 if (obj->base.pending_write_domain)
30377 - cd->flips |= atomic_read(&obj->pending_flip);
30378 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30379
30380 /* The actual obj->write_domain will be updated with
30381 * pending_write_domain after we emit the accumulated flush for all
30382 @@ -933,9 +933,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30383
30384 static int
30385 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30386 - int count)
30387 + unsigned int count)
30388 {
30389 - int i;
30390 + unsigned int i;
30391
30392 for (i = 0; i < count; i++) {
30393 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30394 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30395 index 26c67a7..8d4cbcb 100644
30396 --- a/drivers/gpu/drm/i915/i915_irq.c
30397 +++ b/drivers/gpu/drm/i915/i915_irq.c
30398 @@ -496,7 +496,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30399 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30400 struct drm_i915_master_private *master_priv;
30401
30402 - atomic_inc(&dev_priv->irq_received);
30403 + atomic_inc_unchecked(&dev_priv->irq_received);
30404
30405 /* disable master interrupt before clearing iir */
30406 de_ier = I915_READ(DEIER);
30407 @@ -579,7 +579,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30408 struct drm_i915_master_private *master_priv;
30409 u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT;
30410
30411 - atomic_inc(&dev_priv->irq_received);
30412 + atomic_inc_unchecked(&dev_priv->irq_received);
30413
30414 if (IS_GEN6(dev))
30415 bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT;
30416 @@ -1291,7 +1291,7 @@ static irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
30417 int ret = IRQ_NONE, pipe;
30418 bool blc_event = false;
30419
30420 - atomic_inc(&dev_priv->irq_received);
30421 + atomic_inc_unchecked(&dev_priv->irq_received);
30422
30423 iir = I915_READ(IIR);
30424
30425 @@ -1802,7 +1802,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30426 {
30427 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30428
30429 - atomic_set(&dev_priv->irq_received, 0);
30430 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30431
30432 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
30433 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
30434 @@ -1979,7 +1979,7 @@ static void i915_driver_irq_preinstall(struct drm_device * dev)
30435 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30436 int pipe;
30437
30438 - atomic_set(&dev_priv->irq_received, 0);
30439 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30440
30441 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
30442 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
30443 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30444 index d4d162f..e80037c 100644
30445 --- a/drivers/gpu/drm/i915/intel_display.c
30446 +++ b/drivers/gpu/drm/i915/intel_display.c
30447 @@ -2254,7 +2254,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
30448
30449 wait_event(dev_priv->pending_flip_queue,
30450 atomic_read(&dev_priv->mm.wedged) ||
30451 - atomic_read(&obj->pending_flip) == 0);
30452 + atomic_read_unchecked(&obj->pending_flip) == 0);
30453
30454 /* Big Hammer, we also need to ensure that any pending
30455 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30456 @@ -2919,7 +2919,7 @@ static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
30457 obj = to_intel_framebuffer(crtc->fb)->obj;
30458 dev_priv = crtc->dev->dev_private;
30459 wait_event(dev_priv->pending_flip_queue,
30460 - atomic_read(&obj->pending_flip) == 0);
30461 + atomic_read_unchecked(&obj->pending_flip) == 0);
30462 }
30463
30464 static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
30465 @@ -7286,7 +7286,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30466
30467 atomic_clear_mask(1 << intel_crtc->plane,
30468 &obj->pending_flip.counter);
30469 - if (atomic_read(&obj->pending_flip) == 0)
30470 + if (atomic_read_unchecked(&obj->pending_flip) == 0)
30471 wake_up(&dev_priv->pending_flip_queue);
30472
30473 schedule_work(&work->work);
30474 @@ -7582,7 +7582,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30475 /* Block clients from rendering to the new back buffer until
30476 * the flip occurs and the object is no longer visible.
30477 */
30478 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30479 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30480
30481 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30482 if (ret)
30483 @@ -7596,7 +7596,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30484 return 0;
30485
30486 cleanup_pending:
30487 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30488 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30489 drm_gem_object_unreference(&work->old_fb_obj->base);
30490 drm_gem_object_unreference(&obj->base);
30491 mutex_unlock(&dev->struct_mutex);
30492 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30493 index 54558a0..2d97005 100644
30494 --- a/drivers/gpu/drm/mga/mga_drv.h
30495 +++ b/drivers/gpu/drm/mga/mga_drv.h
30496 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30497 u32 clear_cmd;
30498 u32 maccess;
30499
30500 - atomic_t vbl_received; /**< Number of vblanks received. */
30501 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30502 wait_queue_head_t fence_queue;
30503 - atomic_t last_fence_retired;
30504 + atomic_unchecked_t last_fence_retired;
30505 u32 next_fence_to_post;
30506
30507 unsigned int fb_cpp;
30508 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30509 index 2581202..f230a8d9 100644
30510 --- a/drivers/gpu/drm/mga/mga_irq.c
30511 +++ b/drivers/gpu/drm/mga/mga_irq.c
30512 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30513 if (crtc != 0)
30514 return 0;
30515
30516 - return atomic_read(&dev_priv->vbl_received);
30517 + return atomic_read_unchecked(&dev_priv->vbl_received);
30518 }
30519
30520
30521 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30522 /* VBLANK interrupt */
30523 if (status & MGA_VLINEPEN) {
30524 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30525 - atomic_inc(&dev_priv->vbl_received);
30526 + atomic_inc_unchecked(&dev_priv->vbl_received);
30527 drm_handle_vblank(dev, 0);
30528 handled = 1;
30529 }
30530 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30531 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30532 MGA_WRITE(MGA_PRIMEND, prim_end);
30533
30534 - atomic_inc(&dev_priv->last_fence_retired);
30535 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
30536 DRM_WAKEUP(&dev_priv->fence_queue);
30537 handled = 1;
30538 }
30539 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30540 * using fences.
30541 */
30542 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30543 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30544 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30545 - *sequence) <= (1 << 23)));
30546
30547 *sequence = cur_fence;
30548 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30549 index 0be4a81..7464804 100644
30550 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30551 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30552 @@ -5329,7 +5329,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30553 struct bit_table {
30554 const char id;
30555 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30556 -};
30557 +} __no_const;
30558
30559 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30560
30561 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30562 index 3aef353..0ad1322 100644
30563 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30564 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30565 @@ -240,7 +240,7 @@ struct nouveau_channel {
30566 struct list_head pending;
30567 uint32_t sequence;
30568 uint32_t sequence_ack;
30569 - atomic_t last_sequence_irq;
30570 + atomic_unchecked_t last_sequence_irq;
30571 struct nouveau_vma vma;
30572 } fence;
30573
30574 @@ -321,7 +321,7 @@ struct nouveau_exec_engine {
30575 u32 handle, u16 class);
30576 void (*set_tile_region)(struct drm_device *dev, int i);
30577 void (*tlb_flush)(struct drm_device *, int engine);
30578 -};
30579 +} __no_const;
30580
30581 struct nouveau_instmem_engine {
30582 void *priv;
30583 @@ -343,13 +343,13 @@ struct nouveau_instmem_engine {
30584 struct nouveau_mc_engine {
30585 int (*init)(struct drm_device *dev);
30586 void (*takedown)(struct drm_device *dev);
30587 -};
30588 +} __no_const;
30589
30590 struct nouveau_timer_engine {
30591 int (*init)(struct drm_device *dev);
30592 void (*takedown)(struct drm_device *dev);
30593 uint64_t (*read)(struct drm_device *dev);
30594 -};
30595 +} __no_const;
30596
30597 struct nouveau_fb_engine {
30598 int num_tiles;
30599 @@ -590,7 +590,7 @@ struct nouveau_vram_engine {
30600 void (*put)(struct drm_device *, struct nouveau_mem **);
30601
30602 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30603 -};
30604 +} __no_const;
30605
30606 struct nouveau_engine {
30607 struct nouveau_instmem_engine instmem;
30608 @@ -739,7 +739,7 @@ struct drm_nouveau_private {
30609 struct drm_global_reference mem_global_ref;
30610 struct ttm_bo_global_ref bo_global_ref;
30611 struct ttm_bo_device bdev;
30612 - atomic_t validate_sequence;
30613 + atomic_unchecked_t validate_sequence;
30614 } ttm;
30615
30616 struct {
30617 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
30618 index c1dc20f..4df673c 100644
30619 --- a/drivers/gpu/drm/nouveau/nouveau_fence.c
30620 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
30621 @@ -85,7 +85,7 @@ nouveau_fence_update(struct nouveau_channel *chan)
30622 if (USE_REFCNT(dev))
30623 sequence = nvchan_rd32(chan, 0x48);
30624 else
30625 - sequence = atomic_read(&chan->fence.last_sequence_irq);
30626 + sequence = atomic_read_unchecked(&chan->fence.last_sequence_irq);
30627
30628 if (chan->fence.sequence_ack == sequence)
30629 goto out;
30630 @@ -538,7 +538,7 @@ nouveau_fence_channel_init(struct nouveau_channel *chan)
30631 return ret;
30632 }
30633
30634 - atomic_set(&chan->fence.last_sequence_irq, 0);
30635 + atomic_set_unchecked(&chan->fence.last_sequence_irq, 0);
30636 return 0;
30637 }
30638
30639 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30640 index ed52a6f..484acdc 100644
30641 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30642 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30643 @@ -314,7 +314,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30644 int trycnt = 0;
30645 int ret, i;
30646
30647 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30648 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30649 retry:
30650 if (++trycnt > 100000) {
30651 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30652 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30653 index c2a8511..4b996f9 100644
30654 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
30655 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30656 @@ -588,7 +588,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30657 bool can_switch;
30658
30659 spin_lock(&dev->count_lock);
30660 - can_switch = (dev->open_count == 0);
30661 + can_switch = (local_read(&dev->open_count) == 0);
30662 spin_unlock(&dev->count_lock);
30663 return can_switch;
30664 }
30665 diff --git a/drivers/gpu/drm/nouveau/nv04_graph.c b/drivers/gpu/drm/nouveau/nv04_graph.c
30666 index dbdea8e..cd6eeeb 100644
30667 --- a/drivers/gpu/drm/nouveau/nv04_graph.c
30668 +++ b/drivers/gpu/drm/nouveau/nv04_graph.c
30669 @@ -554,7 +554,7 @@ static int
30670 nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
30671 u32 class, u32 mthd, u32 data)
30672 {
30673 - atomic_set(&chan->fence.last_sequence_irq, data);
30674 + atomic_set_unchecked(&chan->fence.last_sequence_irq, data);
30675 return 0;
30676 }
30677
30678 diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
30679 index 2746402..c8dc4a4 100644
30680 --- a/drivers/gpu/drm/nouveau/nv50_sor.c
30681 +++ b/drivers/gpu/drm/nouveau/nv50_sor.c
30682 @@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
30683 }
30684
30685 if (nv_encoder->dcb->type == OUTPUT_DP) {
30686 - struct dp_train_func func = {
30687 + static struct dp_train_func func = {
30688 .link_set = nv50_sor_dp_link_set,
30689 .train_set = nv50_sor_dp_train_set,
30690 .train_adj = nv50_sor_dp_train_adj
30691 diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
30692 index 0247250..d2f6aaf 100644
30693 --- a/drivers/gpu/drm/nouveau/nvd0_display.c
30694 +++ b/drivers/gpu/drm/nouveau/nvd0_display.c
30695 @@ -1366,7 +1366,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
30696 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
30697
30698 if (nv_encoder->dcb->type == OUTPUT_DP) {
30699 - struct dp_train_func func = {
30700 + static struct dp_train_func func = {
30701 .link_set = nvd0_sor_dp_link_set,
30702 .train_set = nvd0_sor_dp_train_set,
30703 .train_adj = nvd0_sor_dp_train_adj
30704 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
30705 index bcac90b..53bfc76 100644
30706 --- a/drivers/gpu/drm/r128/r128_cce.c
30707 +++ b/drivers/gpu/drm/r128/r128_cce.c
30708 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
30709
30710 /* GH: Simple idle check.
30711 */
30712 - atomic_set(&dev_priv->idle_count, 0);
30713 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30714
30715 /* We don't support anything other than bus-mastering ring mode,
30716 * but the ring can be in either AGP or PCI space for the ring
30717 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
30718 index 930c71b..499aded 100644
30719 --- a/drivers/gpu/drm/r128/r128_drv.h
30720 +++ b/drivers/gpu/drm/r128/r128_drv.h
30721 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
30722 int is_pci;
30723 unsigned long cce_buffers_offset;
30724
30725 - atomic_t idle_count;
30726 + atomic_unchecked_t idle_count;
30727
30728 int page_flipping;
30729 int current_page;
30730 u32 crtc_offset;
30731 u32 crtc_offset_cntl;
30732
30733 - atomic_t vbl_received;
30734 + atomic_unchecked_t vbl_received;
30735
30736 u32 color_fmt;
30737 unsigned int front_offset;
30738 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
30739 index 429d5a0..7e899ed 100644
30740 --- a/drivers/gpu/drm/r128/r128_irq.c
30741 +++ b/drivers/gpu/drm/r128/r128_irq.c
30742 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
30743 if (crtc != 0)
30744 return 0;
30745
30746 - return atomic_read(&dev_priv->vbl_received);
30747 + return atomic_read_unchecked(&dev_priv->vbl_received);
30748 }
30749
30750 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30751 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30752 /* VBLANK interrupt */
30753 if (status & R128_CRTC_VBLANK_INT) {
30754 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
30755 - atomic_inc(&dev_priv->vbl_received);
30756 + atomic_inc_unchecked(&dev_priv->vbl_received);
30757 drm_handle_vblank(dev, 0);
30758 return IRQ_HANDLED;
30759 }
30760 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
30761 index a9e33ce..09edd4b 100644
30762 --- a/drivers/gpu/drm/r128/r128_state.c
30763 +++ b/drivers/gpu/drm/r128/r128_state.c
30764 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
30765
30766 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
30767 {
30768 - if (atomic_read(&dev_priv->idle_count) == 0)
30769 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
30770 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
30771 else
30772 - atomic_set(&dev_priv->idle_count, 0);
30773 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30774 }
30775
30776 #endif
30777 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
30778 index 5a82b6b..9e69c73 100644
30779 --- a/drivers/gpu/drm/radeon/mkregtable.c
30780 +++ b/drivers/gpu/drm/radeon/mkregtable.c
30781 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
30782 regex_t mask_rex;
30783 regmatch_t match[4];
30784 char buf[1024];
30785 - size_t end;
30786 + long end;
30787 int len;
30788 int done = 0;
30789 int r;
30790 unsigned o;
30791 struct offset *offset;
30792 char last_reg_s[10];
30793 - int last_reg;
30794 + unsigned long last_reg;
30795
30796 if (regcomp
30797 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
30798 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
30799 index 138b952..d74f9cb 100644
30800 --- a/drivers/gpu/drm/radeon/radeon.h
30801 +++ b/drivers/gpu/drm/radeon/radeon.h
30802 @@ -253,7 +253,7 @@ struct radeon_fence_driver {
30803 uint32_t scratch_reg;
30804 uint64_t gpu_addr;
30805 volatile uint32_t *cpu_addr;
30806 - atomic_t seq;
30807 + atomic_unchecked_t seq;
30808 uint32_t last_seq;
30809 unsigned long last_jiffies;
30810 unsigned long last_timeout;
30811 @@ -753,7 +753,7 @@ struct r600_blit_cp_primitives {
30812 int x2, int y2);
30813 void (*draw_auto)(struct radeon_device *rdev);
30814 void (*set_default_state)(struct radeon_device *rdev);
30815 -};
30816 +} __no_const;
30817
30818 struct r600_blit {
30819 struct mutex mutex;
30820 @@ -1246,7 +1246,7 @@ struct radeon_asic {
30821 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
30822 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
30823 } pflip;
30824 -};
30825 +} __no_const;
30826
30827 /*
30828 * Asic structures
30829 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
30830 index 5992502..c19c633 100644
30831 --- a/drivers/gpu/drm/radeon/radeon_device.c
30832 +++ b/drivers/gpu/drm/radeon/radeon_device.c
30833 @@ -691,7 +691,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
30834 bool can_switch;
30835
30836 spin_lock(&dev->count_lock);
30837 - can_switch = (dev->open_count == 0);
30838 + can_switch = (local_read(&dev->open_count) == 0);
30839 spin_unlock(&dev->count_lock);
30840 return can_switch;
30841 }
30842 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
30843 index a1b59ca..86f2d44 100644
30844 --- a/drivers/gpu/drm/radeon/radeon_drv.h
30845 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
30846 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
30847
30848 /* SW interrupt */
30849 wait_queue_head_t swi_queue;
30850 - atomic_t swi_emitted;
30851 + atomic_unchecked_t swi_emitted;
30852 int vblank_crtc;
30853 uint32_t irq_enable_reg;
30854 uint32_t r500_disp_irq_reg;
30855 diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
30856 index 4bd36a3..e66fe9c 100644
30857 --- a/drivers/gpu/drm/radeon/radeon_fence.c
30858 +++ b/drivers/gpu/drm/radeon/radeon_fence.c
30859 @@ -70,7 +70,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
30860 write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
30861 return 0;
30862 }
30863 - fence->seq = atomic_add_return(1, &rdev->fence_drv[fence->ring].seq);
30864 + fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv[fence->ring].seq);
30865 if (!rdev->ring[fence->ring].ready)
30866 /* FIXME: cp is not running assume everythings is done right
30867 * away
30868 @@ -405,7 +405,7 @@ int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring)
30869 }
30870 rdev->fence_drv[ring].cpu_addr = &rdev->wb.wb[index/4];
30871 rdev->fence_drv[ring].gpu_addr = rdev->wb.gpu_addr + index;
30872 - radeon_fence_write(rdev, atomic_read(&rdev->fence_drv[ring].seq), ring);
30873 + radeon_fence_write(rdev, atomic_read_unchecked(&rdev->fence_drv[ring].seq), ring);
30874 rdev->fence_drv[ring].initialized = true;
30875 DRM_INFO("fence driver on ring %d use gpu addr 0x%08Lx and cpu addr 0x%p\n",
30876 ring, rdev->fence_drv[ring].gpu_addr, rdev->fence_drv[ring].cpu_addr);
30877 @@ -418,7 +418,7 @@ static void radeon_fence_driver_init_ring(struct radeon_device *rdev, int ring)
30878 rdev->fence_drv[ring].scratch_reg = -1;
30879 rdev->fence_drv[ring].cpu_addr = NULL;
30880 rdev->fence_drv[ring].gpu_addr = 0;
30881 - atomic_set(&rdev->fence_drv[ring].seq, 0);
30882 + atomic_set_unchecked(&rdev->fence_drv[ring].seq, 0);
30883 INIT_LIST_HEAD(&rdev->fence_drv[ring].created);
30884 INIT_LIST_HEAD(&rdev->fence_drv[ring].emitted);
30885 INIT_LIST_HEAD(&rdev->fence_drv[ring].signaled);
30886 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
30887 index 48b7cea..342236f 100644
30888 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
30889 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
30890 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
30891 request = compat_alloc_user_space(sizeof(*request));
30892 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
30893 || __put_user(req32.param, &request->param)
30894 - || __put_user((void __user *)(unsigned long)req32.value,
30895 + || __put_user((unsigned long)req32.value,
30896 &request->value))
30897 return -EFAULT;
30898
30899 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
30900 index 00da384..32f972d 100644
30901 --- a/drivers/gpu/drm/radeon/radeon_irq.c
30902 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
30903 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
30904 unsigned int ret;
30905 RING_LOCALS;
30906
30907 - atomic_inc(&dev_priv->swi_emitted);
30908 - ret = atomic_read(&dev_priv->swi_emitted);
30909 + atomic_inc_unchecked(&dev_priv->swi_emitted);
30910 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
30911
30912 BEGIN_RING(4);
30913 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
30914 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
30915 drm_radeon_private_t *dev_priv =
30916 (drm_radeon_private_t *) dev->dev_private;
30917
30918 - atomic_set(&dev_priv->swi_emitted, 0);
30919 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
30920 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
30921
30922 dev->max_vblank_count = 0x001fffff;
30923 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
30924 index e8422ae..d22d4a8 100644
30925 --- a/drivers/gpu/drm/radeon/radeon_state.c
30926 +++ b/drivers/gpu/drm/radeon/radeon_state.c
30927 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
30928 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
30929 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
30930
30931 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30932 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30933 sarea_priv->nbox * sizeof(depth_boxes[0])))
30934 return -EFAULT;
30935
30936 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
30937 {
30938 drm_radeon_private_t *dev_priv = dev->dev_private;
30939 drm_radeon_getparam_t *param = data;
30940 - int value;
30941 + int value = 0;
30942
30943 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
30944
30945 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
30946 index f493c64..524ab6b 100644
30947 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
30948 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
30949 @@ -843,8 +843,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
30950 }
30951 if (unlikely(ttm_vm_ops == NULL)) {
30952 ttm_vm_ops = vma->vm_ops;
30953 - radeon_ttm_vm_ops = *ttm_vm_ops;
30954 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30955 + pax_open_kernel();
30956 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
30957 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30958 + pax_close_kernel();
30959 }
30960 vma->vm_ops = &radeon_ttm_vm_ops;
30961 return 0;
30962 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
30963 index f2c3b9d..d5a376b 100644
30964 --- a/drivers/gpu/drm/radeon/rs690.c
30965 +++ b/drivers/gpu/drm/radeon/rs690.c
30966 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
30967 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
30968 rdev->pm.sideport_bandwidth.full)
30969 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
30970 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
30971 + read_delay_latency.full = dfixed_const(800 * 1000);
30972 read_delay_latency.full = dfixed_div(read_delay_latency,
30973 rdev->pm.igp_sideport_mclk);
30974 + a.full = dfixed_const(370);
30975 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
30976 } else {
30977 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
30978 rdev->pm.k8_bandwidth.full)
30979 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30980 index ebc6fac..a8313ed 100644
30981 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
30982 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30983 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
30984 static int ttm_pool_mm_shrink(struct shrinker *shrink,
30985 struct shrink_control *sc)
30986 {
30987 - static atomic_t start_pool = ATOMIC_INIT(0);
30988 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
30989 unsigned i;
30990 - unsigned pool_offset = atomic_add_return(1, &start_pool);
30991 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
30992 struct ttm_page_pool *pool;
30993 int shrink_pages = sc->nr_to_scan;
30994
30995 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
30996 index 88edacc..1e5412b 100644
30997 --- a/drivers/gpu/drm/via/via_drv.h
30998 +++ b/drivers/gpu/drm/via/via_drv.h
30999 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31000 typedef uint32_t maskarray_t[5];
31001
31002 typedef struct drm_via_irq {
31003 - atomic_t irq_received;
31004 + atomic_unchecked_t irq_received;
31005 uint32_t pending_mask;
31006 uint32_t enable_mask;
31007 wait_queue_head_t irq_queue;
31008 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
31009 struct timeval last_vblank;
31010 int last_vblank_valid;
31011 unsigned usec_per_vblank;
31012 - atomic_t vbl_received;
31013 + atomic_unchecked_t vbl_received;
31014 drm_via_state_t hc_state;
31015 char pci_buf[VIA_PCI_BUF_SIZE];
31016 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31017 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31018 index d391f48..10c8ca3 100644
31019 --- a/drivers/gpu/drm/via/via_irq.c
31020 +++ b/drivers/gpu/drm/via/via_irq.c
31021 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31022 if (crtc != 0)
31023 return 0;
31024
31025 - return atomic_read(&dev_priv->vbl_received);
31026 + return atomic_read_unchecked(&dev_priv->vbl_received);
31027 }
31028
31029 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31030 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31031
31032 status = VIA_READ(VIA_REG_INTERRUPT);
31033 if (status & VIA_IRQ_VBLANK_PENDING) {
31034 - atomic_inc(&dev_priv->vbl_received);
31035 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31036 + atomic_inc_unchecked(&dev_priv->vbl_received);
31037 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31038 do_gettimeofday(&cur_vblank);
31039 if (dev_priv->last_vblank_valid) {
31040 dev_priv->usec_per_vblank =
31041 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31042 dev_priv->last_vblank = cur_vblank;
31043 dev_priv->last_vblank_valid = 1;
31044 }
31045 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31046 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31047 DRM_DEBUG("US per vblank is: %u\n",
31048 dev_priv->usec_per_vblank);
31049 }
31050 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31051
31052 for (i = 0; i < dev_priv->num_irqs; ++i) {
31053 if (status & cur_irq->pending_mask) {
31054 - atomic_inc(&cur_irq->irq_received);
31055 + atomic_inc_unchecked(&cur_irq->irq_received);
31056 DRM_WAKEUP(&cur_irq->irq_queue);
31057 handled = 1;
31058 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31059 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31060 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31061 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31062 masks[irq][4]));
31063 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31064 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31065 } else {
31066 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31067 (((cur_irq_sequence =
31068 - atomic_read(&cur_irq->irq_received)) -
31069 + atomic_read_unchecked(&cur_irq->irq_received)) -
31070 *sequence) <= (1 << 23)));
31071 }
31072 *sequence = cur_irq_sequence;
31073 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31074 }
31075
31076 for (i = 0; i < dev_priv->num_irqs; ++i) {
31077 - atomic_set(&cur_irq->irq_received, 0);
31078 + atomic_set_unchecked(&cur_irq->irq_received, 0);
31079 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31080 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31081 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31082 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31083 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31084 case VIA_IRQ_RELATIVE:
31085 irqwait->request.sequence +=
31086 - atomic_read(&cur_irq->irq_received);
31087 + atomic_read_unchecked(&cur_irq->irq_received);
31088 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31089 case VIA_IRQ_ABSOLUTE:
31090 break;
31091 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31092 index d0f2c07..9ebd9c3 100644
31093 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31094 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31095 @@ -263,7 +263,7 @@ struct vmw_private {
31096 * Fencing and IRQs.
31097 */
31098
31099 - atomic_t marker_seq;
31100 + atomic_unchecked_t marker_seq;
31101 wait_queue_head_t fence_queue;
31102 wait_queue_head_t fifo_queue;
31103 int fence_queue_waiters; /* Protected by hw_mutex */
31104 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31105 index a0c2f12..68ae6cb 100644
31106 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31107 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31108 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31109 (unsigned int) min,
31110 (unsigned int) fifo->capabilities);
31111
31112 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31113 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31114 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31115 vmw_marker_queue_init(&fifo->marker_queue);
31116 return vmw_fifo_send_fence(dev_priv, &dummy);
31117 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31118 if (reserveable)
31119 iowrite32(bytes, fifo_mem +
31120 SVGA_FIFO_RESERVED);
31121 - return fifo_mem + (next_cmd >> 2);
31122 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31123 } else {
31124 need_bounce = true;
31125 }
31126 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31127
31128 fm = vmw_fifo_reserve(dev_priv, bytes);
31129 if (unlikely(fm == NULL)) {
31130 - *seqno = atomic_read(&dev_priv->marker_seq);
31131 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31132 ret = -ENOMEM;
31133 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31134 false, 3*HZ);
31135 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31136 }
31137
31138 do {
31139 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31140 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31141 } while (*seqno == 0);
31142
31143 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31144 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31145 index cabc95f..14b3d77 100644
31146 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31147 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31148 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31149 * emitted. Then the fence is stale and signaled.
31150 */
31151
31152 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31153 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31154 > VMW_FENCE_WRAP);
31155
31156 return ret;
31157 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31158
31159 if (fifo_idle)
31160 down_read(&fifo_state->rwsem);
31161 - signal_seq = atomic_read(&dev_priv->marker_seq);
31162 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31163 ret = 0;
31164
31165 for (;;) {
31166 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31167 index 8a8725c..afed796 100644
31168 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31169 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31170 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31171 while (!vmw_lag_lt(queue, us)) {
31172 spin_lock(&queue->lock);
31173 if (list_empty(&queue->head))
31174 - seqno = atomic_read(&dev_priv->marker_seq);
31175 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31176 else {
31177 marker = list_first_entry(&queue->head,
31178 struct vmw_marker, head);
31179 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31180 index 054677b..741672a 100644
31181 --- a/drivers/hid/hid-core.c
31182 +++ b/drivers/hid/hid-core.c
31183 @@ -2070,7 +2070,7 @@ static bool hid_ignore(struct hid_device *hdev)
31184
31185 int hid_add_device(struct hid_device *hdev)
31186 {
31187 - static atomic_t id = ATOMIC_INIT(0);
31188 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31189 int ret;
31190
31191 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31192 @@ -2085,7 +2085,7 @@ int hid_add_device(struct hid_device *hdev)
31193 /* XXX hack, any other cleaner solution after the driver core
31194 * is converted to allow more than 20 bytes as the device name? */
31195 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31196 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31197 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31198
31199 hid_debug_register(hdev, dev_name(&hdev->dev));
31200 ret = device_add(&hdev->dev);
31201 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31202 index eec3291..8ed706b 100644
31203 --- a/drivers/hid/hid-wiimote-debug.c
31204 +++ b/drivers/hid/hid-wiimote-debug.c
31205 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31206 else if (size == 0)
31207 return -EIO;
31208
31209 - if (copy_to_user(u, buf, size))
31210 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
31211 return -EFAULT;
31212
31213 *off += size;
31214 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31215 index b1ec0e2..c295a61 100644
31216 --- a/drivers/hid/usbhid/hiddev.c
31217 +++ b/drivers/hid/usbhid/hiddev.c
31218 @@ -624,7 +624,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31219 break;
31220
31221 case HIDIOCAPPLICATION:
31222 - if (arg < 0 || arg >= hid->maxapplication)
31223 + if (arg >= hid->maxapplication)
31224 break;
31225
31226 for (i = 0; i < hid->maxcollection; i++)
31227 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31228 index 4065374..10ed7dc 100644
31229 --- a/drivers/hv/channel.c
31230 +++ b/drivers/hv/channel.c
31231 @@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31232 int ret = 0;
31233 int t;
31234
31235 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31236 - atomic_inc(&vmbus_connection.next_gpadl_handle);
31237 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31238 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31239
31240 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31241 if (ret)
31242 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31243 index 15956bd..ea34398 100644
31244 --- a/drivers/hv/hv.c
31245 +++ b/drivers/hv/hv.c
31246 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31247 u64 output_address = (output) ? virt_to_phys(output) : 0;
31248 u32 output_address_hi = output_address >> 32;
31249 u32 output_address_lo = output_address & 0xFFFFFFFF;
31250 - void *hypercall_page = hv_context.hypercall_page;
31251 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31252
31253 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31254 "=a"(hv_status_lo) : "d" (control_hi),
31255 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31256 index 699f0d8..f4f19250 100644
31257 --- a/drivers/hv/hyperv_vmbus.h
31258 +++ b/drivers/hv/hyperv_vmbus.h
31259 @@ -555,7 +555,7 @@ enum vmbus_connect_state {
31260 struct vmbus_connection {
31261 enum vmbus_connect_state conn_state;
31262
31263 - atomic_t next_gpadl_handle;
31264 + atomic_unchecked_t next_gpadl_handle;
31265
31266 /*
31267 * Represents channel interrupts. Each bit position represents a
31268 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31269 index a220e57..428f54d 100644
31270 --- a/drivers/hv/vmbus_drv.c
31271 +++ b/drivers/hv/vmbus_drv.c
31272 @@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31273 {
31274 int ret = 0;
31275
31276 - static atomic_t device_num = ATOMIC_INIT(0);
31277 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31278
31279 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31280 - atomic_inc_return(&device_num));
31281 + atomic_inc_return_unchecked(&device_num));
31282
31283 child_device_obj->device.bus = &hv_bus;
31284 child_device_obj->device.parent = &hv_acpi_dev->dev;
31285 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
31286 index 9140236..ceaef4e 100644
31287 --- a/drivers/hwmon/acpi_power_meter.c
31288 +++ b/drivers/hwmon/acpi_power_meter.c
31289 @@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
31290 return res;
31291
31292 temp /= 1000;
31293 - if (temp < 0)
31294 - return -EINVAL;
31295
31296 mutex_lock(&resource->lock);
31297 resource->trip[attr->index - 7] = temp;
31298 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31299 index 8b011d0..3de24a1 100644
31300 --- a/drivers/hwmon/sht15.c
31301 +++ b/drivers/hwmon/sht15.c
31302 @@ -166,7 +166,7 @@ struct sht15_data {
31303 int supply_uV;
31304 bool supply_uV_valid;
31305 struct work_struct update_supply_work;
31306 - atomic_t interrupt_handled;
31307 + atomic_unchecked_t interrupt_handled;
31308 };
31309
31310 /**
31311 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31312 return ret;
31313
31314 gpio_direction_input(data->pdata->gpio_data);
31315 - atomic_set(&data->interrupt_handled, 0);
31316 + atomic_set_unchecked(&data->interrupt_handled, 0);
31317
31318 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31319 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31320 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31321 /* Only relevant if the interrupt hasn't occurred. */
31322 - if (!atomic_read(&data->interrupt_handled))
31323 + if (!atomic_read_unchecked(&data->interrupt_handled))
31324 schedule_work(&data->read_work);
31325 }
31326 ret = wait_event_timeout(data->wait_queue,
31327 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31328
31329 /* First disable the interrupt */
31330 disable_irq_nosync(irq);
31331 - atomic_inc(&data->interrupt_handled);
31332 + atomic_inc_unchecked(&data->interrupt_handled);
31333 /* Then schedule a reading work struct */
31334 if (data->state != SHT15_READING_NOTHING)
31335 schedule_work(&data->read_work);
31336 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31337 * If not, then start the interrupt again - care here as could
31338 * have gone low in meantime so verify it hasn't!
31339 */
31340 - atomic_set(&data->interrupt_handled, 0);
31341 + atomic_set_unchecked(&data->interrupt_handled, 0);
31342 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31343 /* If still not occurred or another handler was scheduled */
31344 if (gpio_get_value(data->pdata->gpio_data)
31345 - || atomic_read(&data->interrupt_handled))
31346 + || atomic_read_unchecked(&data->interrupt_handled))
31347 return;
31348 }
31349
31350 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31351 index 378fcb5..5e91fa8 100644
31352 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
31353 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31354 @@ -43,7 +43,7 @@
31355 extern struct i2c_adapter amd756_smbus;
31356
31357 static struct i2c_adapter *s4882_adapter;
31358 -static struct i2c_algorithm *s4882_algo;
31359 +static i2c_algorithm_no_const *s4882_algo;
31360
31361 /* Wrapper access functions for multiplexed SMBus */
31362 static DEFINE_MUTEX(amd756_lock);
31363 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31364 index 29015eb..af2d8e9 100644
31365 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31366 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31367 @@ -41,7 +41,7 @@
31368 extern struct i2c_adapter *nforce2_smbus;
31369
31370 static struct i2c_adapter *s4985_adapter;
31371 -static struct i2c_algorithm *s4985_algo;
31372 +static i2c_algorithm_no_const *s4985_algo;
31373
31374 /* Wrapper access functions for multiplexed SMBus */
31375 static DEFINE_MUTEX(nforce2_lock);
31376 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31377 index d7a4833..7fae376 100644
31378 --- a/drivers/i2c/i2c-mux.c
31379 +++ b/drivers/i2c/i2c-mux.c
31380 @@ -28,7 +28,7 @@
31381 /* multiplexer per channel data */
31382 struct i2c_mux_priv {
31383 struct i2c_adapter adap;
31384 - struct i2c_algorithm algo;
31385 + i2c_algorithm_no_const algo;
31386
31387 struct i2c_adapter *parent;
31388 void *mux_dev; /* the mux chip/device */
31389 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31390 index 57d00ca..0145194 100644
31391 --- a/drivers/ide/aec62xx.c
31392 +++ b/drivers/ide/aec62xx.c
31393 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31394 .cable_detect = atp86x_cable_detect,
31395 };
31396
31397 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31398 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31399 { /* 0: AEC6210 */
31400 .name = DRV_NAME,
31401 .init_chipset = init_chipset_aec62xx,
31402 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31403 index 2c8016a..911a27c 100644
31404 --- a/drivers/ide/alim15x3.c
31405 +++ b/drivers/ide/alim15x3.c
31406 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31407 .dma_sff_read_status = ide_dma_sff_read_status,
31408 };
31409
31410 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
31411 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
31412 .name = DRV_NAME,
31413 .init_chipset = init_chipset_ali15x3,
31414 .init_hwif = init_hwif_ali15x3,
31415 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31416 index 3747b25..56fc995 100644
31417 --- a/drivers/ide/amd74xx.c
31418 +++ b/drivers/ide/amd74xx.c
31419 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31420 .udma_mask = udma, \
31421 }
31422
31423 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31424 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31425 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31426 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31427 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31428 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31429 index 15f0ead..cb43480 100644
31430 --- a/drivers/ide/atiixp.c
31431 +++ b/drivers/ide/atiixp.c
31432 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31433 .cable_detect = atiixp_cable_detect,
31434 };
31435
31436 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31437 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31438 { /* 0: IXP200/300/400/700 */
31439 .name = DRV_NAME,
31440 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31441 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31442 index 5f80312..d1fc438 100644
31443 --- a/drivers/ide/cmd64x.c
31444 +++ b/drivers/ide/cmd64x.c
31445 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31446 .dma_sff_read_status = ide_dma_sff_read_status,
31447 };
31448
31449 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31450 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31451 { /* 0: CMD643 */
31452 .name = DRV_NAME,
31453 .init_chipset = init_chipset_cmd64x,
31454 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31455 index 2c1e5f7..1444762 100644
31456 --- a/drivers/ide/cs5520.c
31457 +++ b/drivers/ide/cs5520.c
31458 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31459 .set_dma_mode = cs5520_set_dma_mode,
31460 };
31461
31462 -static const struct ide_port_info cyrix_chipset __devinitdata = {
31463 +static const struct ide_port_info cyrix_chipset __devinitconst = {
31464 .name = DRV_NAME,
31465 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31466 .port_ops = &cs5520_port_ops,
31467 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31468 index 4dc4eb9..49b40ad 100644
31469 --- a/drivers/ide/cs5530.c
31470 +++ b/drivers/ide/cs5530.c
31471 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31472 .udma_filter = cs5530_udma_filter,
31473 };
31474
31475 -static const struct ide_port_info cs5530_chipset __devinitdata = {
31476 +static const struct ide_port_info cs5530_chipset __devinitconst = {
31477 .name = DRV_NAME,
31478 .init_chipset = init_chipset_cs5530,
31479 .init_hwif = init_hwif_cs5530,
31480 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31481 index 5059faf..18d4c85 100644
31482 --- a/drivers/ide/cs5535.c
31483 +++ b/drivers/ide/cs5535.c
31484 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31485 .cable_detect = cs5535_cable_detect,
31486 };
31487
31488 -static const struct ide_port_info cs5535_chipset __devinitdata = {
31489 +static const struct ide_port_info cs5535_chipset __devinitconst = {
31490 .name = DRV_NAME,
31491 .port_ops = &cs5535_port_ops,
31492 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31493 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31494 index 847553f..3ffb49d 100644
31495 --- a/drivers/ide/cy82c693.c
31496 +++ b/drivers/ide/cy82c693.c
31497 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31498 .set_dma_mode = cy82c693_set_dma_mode,
31499 };
31500
31501 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
31502 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
31503 .name = DRV_NAME,
31504 .init_iops = init_iops_cy82c693,
31505 .port_ops = &cy82c693_port_ops,
31506 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31507 index 58c51cd..4aec3b8 100644
31508 --- a/drivers/ide/hpt366.c
31509 +++ b/drivers/ide/hpt366.c
31510 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31511 }
31512 };
31513
31514 -static const struct hpt_info hpt36x __devinitdata = {
31515 +static const struct hpt_info hpt36x __devinitconst = {
31516 .chip_name = "HPT36x",
31517 .chip_type = HPT36x,
31518 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31519 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31520 .timings = &hpt36x_timings
31521 };
31522
31523 -static const struct hpt_info hpt370 __devinitdata = {
31524 +static const struct hpt_info hpt370 __devinitconst = {
31525 .chip_name = "HPT370",
31526 .chip_type = HPT370,
31527 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31528 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31529 .timings = &hpt37x_timings
31530 };
31531
31532 -static const struct hpt_info hpt370a __devinitdata = {
31533 +static const struct hpt_info hpt370a __devinitconst = {
31534 .chip_name = "HPT370A",
31535 .chip_type = HPT370A,
31536 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31537 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31538 .timings = &hpt37x_timings
31539 };
31540
31541 -static const struct hpt_info hpt374 __devinitdata = {
31542 +static const struct hpt_info hpt374 __devinitconst = {
31543 .chip_name = "HPT374",
31544 .chip_type = HPT374,
31545 .udma_mask = ATA_UDMA5,
31546 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31547 .timings = &hpt37x_timings
31548 };
31549
31550 -static const struct hpt_info hpt372 __devinitdata = {
31551 +static const struct hpt_info hpt372 __devinitconst = {
31552 .chip_name = "HPT372",
31553 .chip_type = HPT372,
31554 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31555 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31556 .timings = &hpt37x_timings
31557 };
31558
31559 -static const struct hpt_info hpt372a __devinitdata = {
31560 +static const struct hpt_info hpt372a __devinitconst = {
31561 .chip_name = "HPT372A",
31562 .chip_type = HPT372A,
31563 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31564 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31565 .timings = &hpt37x_timings
31566 };
31567
31568 -static const struct hpt_info hpt302 __devinitdata = {
31569 +static const struct hpt_info hpt302 __devinitconst = {
31570 .chip_name = "HPT302",
31571 .chip_type = HPT302,
31572 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31573 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31574 .timings = &hpt37x_timings
31575 };
31576
31577 -static const struct hpt_info hpt371 __devinitdata = {
31578 +static const struct hpt_info hpt371 __devinitconst = {
31579 .chip_name = "HPT371",
31580 .chip_type = HPT371,
31581 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31582 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31583 .timings = &hpt37x_timings
31584 };
31585
31586 -static const struct hpt_info hpt372n __devinitdata = {
31587 +static const struct hpt_info hpt372n __devinitconst = {
31588 .chip_name = "HPT372N",
31589 .chip_type = HPT372N,
31590 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31591 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31592 .timings = &hpt37x_timings
31593 };
31594
31595 -static const struct hpt_info hpt302n __devinitdata = {
31596 +static const struct hpt_info hpt302n __devinitconst = {
31597 .chip_name = "HPT302N",
31598 .chip_type = HPT302N,
31599 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31600 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31601 .timings = &hpt37x_timings
31602 };
31603
31604 -static const struct hpt_info hpt371n __devinitdata = {
31605 +static const struct hpt_info hpt371n __devinitconst = {
31606 .chip_name = "HPT371N",
31607 .chip_type = HPT371N,
31608 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31609 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31610 .dma_sff_read_status = ide_dma_sff_read_status,
31611 };
31612
31613 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31614 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31615 { /* 0: HPT36x */
31616 .name = DRV_NAME,
31617 .init_chipset = init_chipset_hpt366,
31618 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31619 index 8126824..55a2798 100644
31620 --- a/drivers/ide/ide-cd.c
31621 +++ b/drivers/ide/ide-cd.c
31622 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31623 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31624 if ((unsigned long)buf & alignment
31625 || blk_rq_bytes(rq) & q->dma_pad_mask
31626 - || object_is_on_stack(buf))
31627 + || object_starts_on_stack(buf))
31628 drive->dma = 0;
31629 }
31630 }
31631 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31632 index 7f56b73..dab5b67 100644
31633 --- a/drivers/ide/ide-pci-generic.c
31634 +++ b/drivers/ide/ide-pci-generic.c
31635 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31636 .udma_mask = ATA_UDMA6, \
31637 }
31638
31639 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
31640 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
31641 /* 0: Unknown */
31642 DECLARE_GENERIC_PCI_DEV(0),
31643
31644 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31645 index 560e66d..d5dd180 100644
31646 --- a/drivers/ide/it8172.c
31647 +++ b/drivers/ide/it8172.c
31648 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31649 .set_dma_mode = it8172_set_dma_mode,
31650 };
31651
31652 -static const struct ide_port_info it8172_port_info __devinitdata = {
31653 +static const struct ide_port_info it8172_port_info __devinitconst = {
31654 .name = DRV_NAME,
31655 .port_ops = &it8172_port_ops,
31656 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31657 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31658 index 46816ba..1847aeb 100644
31659 --- a/drivers/ide/it8213.c
31660 +++ b/drivers/ide/it8213.c
31661 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31662 .cable_detect = it8213_cable_detect,
31663 };
31664
31665 -static const struct ide_port_info it8213_chipset __devinitdata = {
31666 +static const struct ide_port_info it8213_chipset __devinitconst = {
31667 .name = DRV_NAME,
31668 .enablebits = { {0x41, 0x80, 0x80} },
31669 .port_ops = &it8213_port_ops,
31670 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31671 index 2e3169f..c5611db 100644
31672 --- a/drivers/ide/it821x.c
31673 +++ b/drivers/ide/it821x.c
31674 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31675 .cable_detect = it821x_cable_detect,
31676 };
31677
31678 -static const struct ide_port_info it821x_chipset __devinitdata = {
31679 +static const struct ide_port_info it821x_chipset __devinitconst = {
31680 .name = DRV_NAME,
31681 .init_chipset = init_chipset_it821x,
31682 .init_hwif = init_hwif_it821x,
31683 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31684 index 74c2c4a..efddd7d 100644
31685 --- a/drivers/ide/jmicron.c
31686 +++ b/drivers/ide/jmicron.c
31687 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31688 .cable_detect = jmicron_cable_detect,
31689 };
31690
31691 -static const struct ide_port_info jmicron_chipset __devinitdata = {
31692 +static const struct ide_port_info jmicron_chipset __devinitconst = {
31693 .name = DRV_NAME,
31694 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31695 .port_ops = &jmicron_port_ops,
31696 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31697 index 95327a2..73f78d8 100644
31698 --- a/drivers/ide/ns87415.c
31699 +++ b/drivers/ide/ns87415.c
31700 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31701 .dma_sff_read_status = superio_dma_sff_read_status,
31702 };
31703
31704 -static const struct ide_port_info ns87415_chipset __devinitdata = {
31705 +static const struct ide_port_info ns87415_chipset __devinitconst = {
31706 .name = DRV_NAME,
31707 .init_hwif = init_hwif_ns87415,
31708 .tp_ops = &ns87415_tp_ops,
31709 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31710 index 1a53a4c..39edc66 100644
31711 --- a/drivers/ide/opti621.c
31712 +++ b/drivers/ide/opti621.c
31713 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31714 .set_pio_mode = opti621_set_pio_mode,
31715 };
31716
31717 -static const struct ide_port_info opti621_chipset __devinitdata = {
31718 +static const struct ide_port_info opti621_chipset __devinitconst = {
31719 .name = DRV_NAME,
31720 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31721 .port_ops = &opti621_port_ops,
31722 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31723 index 9546fe2..2e5ceb6 100644
31724 --- a/drivers/ide/pdc202xx_new.c
31725 +++ b/drivers/ide/pdc202xx_new.c
31726 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31727 .udma_mask = udma, \
31728 }
31729
31730 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
31731 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
31732 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
31733 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
31734 };
31735 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
31736 index 3a35ec6..5634510 100644
31737 --- a/drivers/ide/pdc202xx_old.c
31738 +++ b/drivers/ide/pdc202xx_old.c
31739 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
31740 .max_sectors = sectors, \
31741 }
31742
31743 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
31744 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
31745 { /* 0: PDC20246 */
31746 .name = DRV_NAME,
31747 .init_chipset = init_chipset_pdc202xx,
31748 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
31749 index 1892e81..fe0fd60 100644
31750 --- a/drivers/ide/piix.c
31751 +++ b/drivers/ide/piix.c
31752 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
31753 .udma_mask = udma, \
31754 }
31755
31756 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
31757 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
31758 /* 0: MPIIX */
31759 { /*
31760 * MPIIX actually has only a single IDE channel mapped to
31761 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
31762 index a6414a8..c04173e 100644
31763 --- a/drivers/ide/rz1000.c
31764 +++ b/drivers/ide/rz1000.c
31765 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
31766 }
31767 }
31768
31769 -static const struct ide_port_info rz1000_chipset __devinitdata = {
31770 +static const struct ide_port_info rz1000_chipset __devinitconst = {
31771 .name = DRV_NAME,
31772 .host_flags = IDE_HFLAG_NO_DMA,
31773 };
31774 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
31775 index 356b9b5..d4758eb 100644
31776 --- a/drivers/ide/sc1200.c
31777 +++ b/drivers/ide/sc1200.c
31778 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
31779 .dma_sff_read_status = ide_dma_sff_read_status,
31780 };
31781
31782 -static const struct ide_port_info sc1200_chipset __devinitdata = {
31783 +static const struct ide_port_info sc1200_chipset __devinitconst = {
31784 .name = DRV_NAME,
31785 .port_ops = &sc1200_port_ops,
31786 .dma_ops = &sc1200_dma_ops,
31787 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
31788 index b7f5b0c..9701038 100644
31789 --- a/drivers/ide/scc_pata.c
31790 +++ b/drivers/ide/scc_pata.c
31791 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
31792 .dma_sff_read_status = scc_dma_sff_read_status,
31793 };
31794
31795 -static const struct ide_port_info scc_chipset __devinitdata = {
31796 +static const struct ide_port_info scc_chipset __devinitconst = {
31797 .name = "sccIDE",
31798 .init_iops = init_iops_scc,
31799 .init_dma = scc_init_dma,
31800 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
31801 index 35fb8da..24d72ef 100644
31802 --- a/drivers/ide/serverworks.c
31803 +++ b/drivers/ide/serverworks.c
31804 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
31805 .cable_detect = svwks_cable_detect,
31806 };
31807
31808 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
31809 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
31810 { /* 0: OSB4 */
31811 .name = DRV_NAME,
31812 .init_chipset = init_chipset_svwks,
31813 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
31814 index ddeda44..46f7e30 100644
31815 --- a/drivers/ide/siimage.c
31816 +++ b/drivers/ide/siimage.c
31817 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
31818 .udma_mask = ATA_UDMA6, \
31819 }
31820
31821 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
31822 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
31823 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
31824 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
31825 };
31826 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
31827 index 4a00225..09e61b4 100644
31828 --- a/drivers/ide/sis5513.c
31829 +++ b/drivers/ide/sis5513.c
31830 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
31831 .cable_detect = sis_cable_detect,
31832 };
31833
31834 -static const struct ide_port_info sis5513_chipset __devinitdata = {
31835 +static const struct ide_port_info sis5513_chipset __devinitconst = {
31836 .name = DRV_NAME,
31837 .init_chipset = init_chipset_sis5513,
31838 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
31839 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
31840 index f21dc2a..d051cd2 100644
31841 --- a/drivers/ide/sl82c105.c
31842 +++ b/drivers/ide/sl82c105.c
31843 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
31844 .dma_sff_read_status = ide_dma_sff_read_status,
31845 };
31846
31847 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
31848 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
31849 .name = DRV_NAME,
31850 .init_chipset = init_chipset_sl82c105,
31851 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
31852 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
31853 index 864ffe0..863a5e9 100644
31854 --- a/drivers/ide/slc90e66.c
31855 +++ b/drivers/ide/slc90e66.c
31856 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
31857 .cable_detect = slc90e66_cable_detect,
31858 };
31859
31860 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
31861 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
31862 .name = DRV_NAME,
31863 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
31864 .port_ops = &slc90e66_port_ops,
31865 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
31866 index 4799d5c..1794678 100644
31867 --- a/drivers/ide/tc86c001.c
31868 +++ b/drivers/ide/tc86c001.c
31869 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
31870 .dma_sff_read_status = ide_dma_sff_read_status,
31871 };
31872
31873 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
31874 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
31875 .name = DRV_NAME,
31876 .init_hwif = init_hwif_tc86c001,
31877 .port_ops = &tc86c001_port_ops,
31878 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
31879 index 281c914..55ce1b8 100644
31880 --- a/drivers/ide/triflex.c
31881 +++ b/drivers/ide/triflex.c
31882 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
31883 .set_dma_mode = triflex_set_mode,
31884 };
31885
31886 -static const struct ide_port_info triflex_device __devinitdata = {
31887 +static const struct ide_port_info triflex_device __devinitconst = {
31888 .name = DRV_NAME,
31889 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
31890 .port_ops = &triflex_port_ops,
31891 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
31892 index 4b42ca0..e494a98 100644
31893 --- a/drivers/ide/trm290.c
31894 +++ b/drivers/ide/trm290.c
31895 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
31896 .dma_check = trm290_dma_check,
31897 };
31898
31899 -static const struct ide_port_info trm290_chipset __devinitdata = {
31900 +static const struct ide_port_info trm290_chipset __devinitconst = {
31901 .name = DRV_NAME,
31902 .init_hwif = init_hwif_trm290,
31903 .tp_ops = &trm290_tp_ops,
31904 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
31905 index f46f49c..eb77678 100644
31906 --- a/drivers/ide/via82cxxx.c
31907 +++ b/drivers/ide/via82cxxx.c
31908 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
31909 .cable_detect = via82cxxx_cable_detect,
31910 };
31911
31912 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
31913 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
31914 .name = DRV_NAME,
31915 .init_chipset = init_chipset_via82cxxx,
31916 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
31917 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
31918 index 73d4531..c90cd2d 100644
31919 --- a/drivers/ieee802154/fakehard.c
31920 +++ b/drivers/ieee802154/fakehard.c
31921 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
31922 phy->transmit_power = 0xbf;
31923
31924 dev->netdev_ops = &fake_ops;
31925 - dev->ml_priv = &fake_mlme;
31926 + dev->ml_priv = (void *)&fake_mlme;
31927
31928 priv = netdev_priv(dev);
31929 priv->phy = phy;
31930 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
31931 index c889aae..6cf5aa7 100644
31932 --- a/drivers/infiniband/core/cm.c
31933 +++ b/drivers/infiniband/core/cm.c
31934 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
31935
31936 struct cm_counter_group {
31937 struct kobject obj;
31938 - atomic_long_t counter[CM_ATTR_COUNT];
31939 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
31940 };
31941
31942 struct cm_counter_attribute {
31943 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
31944 struct ib_mad_send_buf *msg = NULL;
31945 int ret;
31946
31947 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31948 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31949 counter[CM_REQ_COUNTER]);
31950
31951 /* Quick state check to discard duplicate REQs. */
31952 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
31953 if (!cm_id_priv)
31954 return;
31955
31956 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31957 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31958 counter[CM_REP_COUNTER]);
31959 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
31960 if (ret)
31961 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
31962 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
31963 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
31964 spin_unlock_irq(&cm_id_priv->lock);
31965 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31966 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31967 counter[CM_RTU_COUNTER]);
31968 goto out;
31969 }
31970 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
31971 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
31972 dreq_msg->local_comm_id);
31973 if (!cm_id_priv) {
31974 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31975 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31976 counter[CM_DREQ_COUNTER]);
31977 cm_issue_drep(work->port, work->mad_recv_wc);
31978 return -EINVAL;
31979 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
31980 case IB_CM_MRA_REP_RCVD:
31981 break;
31982 case IB_CM_TIMEWAIT:
31983 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31984 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31985 counter[CM_DREQ_COUNTER]);
31986 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
31987 goto unlock;
31988 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
31989 cm_free_msg(msg);
31990 goto deref;
31991 case IB_CM_DREQ_RCVD:
31992 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31993 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31994 counter[CM_DREQ_COUNTER]);
31995 goto unlock;
31996 default:
31997 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
31998 ib_modify_mad(cm_id_priv->av.port->mad_agent,
31999 cm_id_priv->msg, timeout)) {
32000 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32001 - atomic_long_inc(&work->port->
32002 + atomic_long_inc_unchecked(&work->port->
32003 counter_group[CM_RECV_DUPLICATES].
32004 counter[CM_MRA_COUNTER]);
32005 goto out;
32006 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32007 break;
32008 case IB_CM_MRA_REQ_RCVD:
32009 case IB_CM_MRA_REP_RCVD:
32010 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32011 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32012 counter[CM_MRA_COUNTER]);
32013 /* fall through */
32014 default:
32015 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32016 case IB_CM_LAP_IDLE:
32017 break;
32018 case IB_CM_MRA_LAP_SENT:
32019 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32020 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32021 counter[CM_LAP_COUNTER]);
32022 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32023 goto unlock;
32024 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32025 cm_free_msg(msg);
32026 goto deref;
32027 case IB_CM_LAP_RCVD:
32028 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32029 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32030 counter[CM_LAP_COUNTER]);
32031 goto unlock;
32032 default:
32033 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32034 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32035 if (cur_cm_id_priv) {
32036 spin_unlock_irq(&cm.lock);
32037 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32038 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32039 counter[CM_SIDR_REQ_COUNTER]);
32040 goto out; /* Duplicate message. */
32041 }
32042 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32043 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32044 msg->retries = 1;
32045
32046 - atomic_long_add(1 + msg->retries,
32047 + atomic_long_add_unchecked(1 + msg->retries,
32048 &port->counter_group[CM_XMIT].counter[attr_index]);
32049 if (msg->retries)
32050 - atomic_long_add(msg->retries,
32051 + atomic_long_add_unchecked(msg->retries,
32052 &port->counter_group[CM_XMIT_RETRIES].
32053 counter[attr_index]);
32054
32055 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32056 }
32057
32058 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32059 - atomic_long_inc(&port->counter_group[CM_RECV].
32060 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32061 counter[attr_id - CM_ATTR_ID_OFFSET]);
32062
32063 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32064 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32065 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32066
32067 return sprintf(buf, "%ld\n",
32068 - atomic_long_read(&group->counter[cm_attr->index]));
32069 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32070 }
32071
32072 static const struct sysfs_ops cm_counter_ops = {
32073 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32074 index 176c8f9..2627b62 100644
32075 --- a/drivers/infiniband/core/fmr_pool.c
32076 +++ b/drivers/infiniband/core/fmr_pool.c
32077 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
32078
32079 struct task_struct *thread;
32080
32081 - atomic_t req_ser;
32082 - atomic_t flush_ser;
32083 + atomic_unchecked_t req_ser;
32084 + atomic_unchecked_t flush_ser;
32085
32086 wait_queue_head_t force_wait;
32087 };
32088 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32089 struct ib_fmr_pool *pool = pool_ptr;
32090
32091 do {
32092 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32093 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32094 ib_fmr_batch_release(pool);
32095
32096 - atomic_inc(&pool->flush_ser);
32097 + atomic_inc_unchecked(&pool->flush_ser);
32098 wake_up_interruptible(&pool->force_wait);
32099
32100 if (pool->flush_function)
32101 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32102 }
32103
32104 set_current_state(TASK_INTERRUPTIBLE);
32105 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32106 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32107 !kthread_should_stop())
32108 schedule();
32109 __set_current_state(TASK_RUNNING);
32110 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32111 pool->dirty_watermark = params->dirty_watermark;
32112 pool->dirty_len = 0;
32113 spin_lock_init(&pool->pool_lock);
32114 - atomic_set(&pool->req_ser, 0);
32115 - atomic_set(&pool->flush_ser, 0);
32116 + atomic_set_unchecked(&pool->req_ser, 0);
32117 + atomic_set_unchecked(&pool->flush_ser, 0);
32118 init_waitqueue_head(&pool->force_wait);
32119
32120 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32121 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32122 }
32123 spin_unlock_irq(&pool->pool_lock);
32124
32125 - serial = atomic_inc_return(&pool->req_ser);
32126 + serial = atomic_inc_return_unchecked(&pool->req_ser);
32127 wake_up_process(pool->thread);
32128
32129 if (wait_event_interruptible(pool->force_wait,
32130 - atomic_read(&pool->flush_ser) - serial >= 0))
32131 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32132 return -EINTR;
32133
32134 return 0;
32135 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32136 } else {
32137 list_add_tail(&fmr->list, &pool->dirty_list);
32138 if (++pool->dirty_len >= pool->dirty_watermark) {
32139 - atomic_inc(&pool->req_ser);
32140 + atomic_inc_unchecked(&pool->req_ser);
32141 wake_up_process(pool->thread);
32142 }
32143 }
32144 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32145 index 40c8353..946b0e4 100644
32146 --- a/drivers/infiniband/hw/cxgb4/mem.c
32147 +++ b/drivers/infiniband/hw/cxgb4/mem.c
32148 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32149 int err;
32150 struct fw_ri_tpte tpt;
32151 u32 stag_idx;
32152 - static atomic_t key;
32153 + static atomic_unchecked_t key;
32154
32155 if (c4iw_fatal_error(rdev))
32156 return -EIO;
32157 @@ -135,7 +135,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32158 &rdev->resource.tpt_fifo_lock);
32159 if (!stag_idx)
32160 return -ENOMEM;
32161 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32162 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32163 }
32164 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32165 __func__, stag_state, type, pdid, stag_idx);
32166 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32167 index 79b3dbc..96e5fcc 100644
32168 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
32169 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32170 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32171 struct ib_atomic_eth *ateth;
32172 struct ipath_ack_entry *e;
32173 u64 vaddr;
32174 - atomic64_t *maddr;
32175 + atomic64_unchecked_t *maddr;
32176 u64 sdata;
32177 u32 rkey;
32178 u8 next;
32179 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32180 IB_ACCESS_REMOTE_ATOMIC)))
32181 goto nack_acc_unlck;
32182 /* Perform atomic OP and save result. */
32183 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32184 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32185 sdata = be64_to_cpu(ateth->swap_data);
32186 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32187 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32188 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32189 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32190 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32191 be64_to_cpu(ateth->compare_data),
32192 sdata);
32193 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32194 index 1f95bba..9530f87 100644
32195 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32196 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32197 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32198 unsigned long flags;
32199 struct ib_wc wc;
32200 u64 sdata;
32201 - atomic64_t *maddr;
32202 + atomic64_unchecked_t *maddr;
32203 enum ib_wc_status send_status;
32204
32205 /*
32206 @@ -382,11 +382,11 @@ again:
32207 IB_ACCESS_REMOTE_ATOMIC)))
32208 goto acc_err;
32209 /* Perform atomic OP and save result. */
32210 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32211 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32212 sdata = wqe->wr.wr.atomic.compare_add;
32213 *(u64 *) sqp->s_sge.sge.vaddr =
32214 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32215 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32216 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32217 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32218 sdata, wqe->wr.wr.atomic.swap);
32219 goto send_comp;
32220 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32221 index 7140199..da60063 100644
32222 --- a/drivers/infiniband/hw/nes/nes.c
32223 +++ b/drivers/infiniband/hw/nes/nes.c
32224 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32225 LIST_HEAD(nes_adapter_list);
32226 static LIST_HEAD(nes_dev_list);
32227
32228 -atomic_t qps_destroyed;
32229 +atomic_unchecked_t qps_destroyed;
32230
32231 static unsigned int ee_flsh_adapter;
32232 static unsigned int sysfs_nonidx_addr;
32233 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32234 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32235 struct nes_adapter *nesadapter = nesdev->nesadapter;
32236
32237 - atomic_inc(&qps_destroyed);
32238 + atomic_inc_unchecked(&qps_destroyed);
32239
32240 /* Free the control structures */
32241
32242 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32243 index c438e46..ca30356 100644
32244 --- a/drivers/infiniband/hw/nes/nes.h
32245 +++ b/drivers/infiniband/hw/nes/nes.h
32246 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32247 extern unsigned int wqm_quanta;
32248 extern struct list_head nes_adapter_list;
32249
32250 -extern atomic_t cm_connects;
32251 -extern atomic_t cm_accepts;
32252 -extern atomic_t cm_disconnects;
32253 -extern atomic_t cm_closes;
32254 -extern atomic_t cm_connecteds;
32255 -extern atomic_t cm_connect_reqs;
32256 -extern atomic_t cm_rejects;
32257 -extern atomic_t mod_qp_timouts;
32258 -extern atomic_t qps_created;
32259 -extern atomic_t qps_destroyed;
32260 -extern atomic_t sw_qps_destroyed;
32261 +extern atomic_unchecked_t cm_connects;
32262 +extern atomic_unchecked_t cm_accepts;
32263 +extern atomic_unchecked_t cm_disconnects;
32264 +extern atomic_unchecked_t cm_closes;
32265 +extern atomic_unchecked_t cm_connecteds;
32266 +extern atomic_unchecked_t cm_connect_reqs;
32267 +extern atomic_unchecked_t cm_rejects;
32268 +extern atomic_unchecked_t mod_qp_timouts;
32269 +extern atomic_unchecked_t qps_created;
32270 +extern atomic_unchecked_t qps_destroyed;
32271 +extern atomic_unchecked_t sw_qps_destroyed;
32272 extern u32 mh_detected;
32273 extern u32 mh_pauses_sent;
32274 extern u32 cm_packets_sent;
32275 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32276 extern u32 cm_packets_received;
32277 extern u32 cm_packets_dropped;
32278 extern u32 cm_packets_retrans;
32279 -extern atomic_t cm_listens_created;
32280 -extern atomic_t cm_listens_destroyed;
32281 +extern atomic_unchecked_t cm_listens_created;
32282 +extern atomic_unchecked_t cm_listens_destroyed;
32283 extern u32 cm_backlog_drops;
32284 -extern atomic_t cm_loopbacks;
32285 -extern atomic_t cm_nodes_created;
32286 -extern atomic_t cm_nodes_destroyed;
32287 -extern atomic_t cm_accel_dropped_pkts;
32288 -extern atomic_t cm_resets_recvd;
32289 -extern atomic_t pau_qps_created;
32290 -extern atomic_t pau_qps_destroyed;
32291 +extern atomic_unchecked_t cm_loopbacks;
32292 +extern atomic_unchecked_t cm_nodes_created;
32293 +extern atomic_unchecked_t cm_nodes_destroyed;
32294 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32295 +extern atomic_unchecked_t cm_resets_recvd;
32296 +extern atomic_unchecked_t pau_qps_created;
32297 +extern atomic_unchecked_t pau_qps_destroyed;
32298
32299 extern u32 int_mod_timer_init;
32300 extern u32 int_mod_cq_depth_256;
32301 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32302 index 71edfbb..15b62ae 100644
32303 --- a/drivers/infiniband/hw/nes/nes_cm.c
32304 +++ b/drivers/infiniband/hw/nes/nes_cm.c
32305 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32306 u32 cm_packets_retrans;
32307 u32 cm_packets_created;
32308 u32 cm_packets_received;
32309 -atomic_t cm_listens_created;
32310 -atomic_t cm_listens_destroyed;
32311 +atomic_unchecked_t cm_listens_created;
32312 +atomic_unchecked_t cm_listens_destroyed;
32313 u32 cm_backlog_drops;
32314 -atomic_t cm_loopbacks;
32315 -atomic_t cm_nodes_created;
32316 -atomic_t cm_nodes_destroyed;
32317 -atomic_t cm_accel_dropped_pkts;
32318 -atomic_t cm_resets_recvd;
32319 +atomic_unchecked_t cm_loopbacks;
32320 +atomic_unchecked_t cm_nodes_created;
32321 +atomic_unchecked_t cm_nodes_destroyed;
32322 +atomic_unchecked_t cm_accel_dropped_pkts;
32323 +atomic_unchecked_t cm_resets_recvd;
32324
32325 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32326 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32327 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32328
32329 static struct nes_cm_core *g_cm_core;
32330
32331 -atomic_t cm_connects;
32332 -atomic_t cm_accepts;
32333 -atomic_t cm_disconnects;
32334 -atomic_t cm_closes;
32335 -atomic_t cm_connecteds;
32336 -atomic_t cm_connect_reqs;
32337 -atomic_t cm_rejects;
32338 +atomic_unchecked_t cm_connects;
32339 +atomic_unchecked_t cm_accepts;
32340 +atomic_unchecked_t cm_disconnects;
32341 +atomic_unchecked_t cm_closes;
32342 +atomic_unchecked_t cm_connecteds;
32343 +atomic_unchecked_t cm_connect_reqs;
32344 +atomic_unchecked_t cm_rejects;
32345
32346 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32347 {
32348 @@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32349 kfree(listener);
32350 listener = NULL;
32351 ret = 0;
32352 - atomic_inc(&cm_listens_destroyed);
32353 + atomic_inc_unchecked(&cm_listens_destroyed);
32354 } else {
32355 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32356 }
32357 @@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32358 cm_node->rem_mac);
32359
32360 add_hte_node(cm_core, cm_node);
32361 - atomic_inc(&cm_nodes_created);
32362 + atomic_inc_unchecked(&cm_nodes_created);
32363
32364 return cm_node;
32365 }
32366 @@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32367 }
32368
32369 atomic_dec(&cm_core->node_cnt);
32370 - atomic_inc(&cm_nodes_destroyed);
32371 + atomic_inc_unchecked(&cm_nodes_destroyed);
32372 nesqp = cm_node->nesqp;
32373 if (nesqp) {
32374 nesqp->cm_node = NULL;
32375 @@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32376
32377 static void drop_packet(struct sk_buff *skb)
32378 {
32379 - atomic_inc(&cm_accel_dropped_pkts);
32380 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32381 dev_kfree_skb_any(skb);
32382 }
32383
32384 @@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32385 {
32386
32387 int reset = 0; /* whether to send reset in case of err.. */
32388 - atomic_inc(&cm_resets_recvd);
32389 + atomic_inc_unchecked(&cm_resets_recvd);
32390 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32391 " refcnt=%d\n", cm_node, cm_node->state,
32392 atomic_read(&cm_node->ref_count));
32393 @@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32394 rem_ref_cm_node(cm_node->cm_core, cm_node);
32395 return NULL;
32396 }
32397 - atomic_inc(&cm_loopbacks);
32398 + atomic_inc_unchecked(&cm_loopbacks);
32399 loopbackremotenode->loopbackpartner = cm_node;
32400 loopbackremotenode->tcp_cntxt.rcv_wscale =
32401 NES_CM_DEFAULT_RCV_WND_SCALE;
32402 @@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32403 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32404 else {
32405 rem_ref_cm_node(cm_core, cm_node);
32406 - atomic_inc(&cm_accel_dropped_pkts);
32407 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32408 dev_kfree_skb_any(skb);
32409 }
32410 break;
32411 @@ -2890,7 +2890,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32412
32413 if ((cm_id) && (cm_id->event_handler)) {
32414 if (issue_disconn) {
32415 - atomic_inc(&cm_disconnects);
32416 + atomic_inc_unchecked(&cm_disconnects);
32417 cm_event.event = IW_CM_EVENT_DISCONNECT;
32418 cm_event.status = disconn_status;
32419 cm_event.local_addr = cm_id->local_addr;
32420 @@ -2912,7 +2912,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32421 }
32422
32423 if (issue_close) {
32424 - atomic_inc(&cm_closes);
32425 + atomic_inc_unchecked(&cm_closes);
32426 nes_disconnect(nesqp, 1);
32427
32428 cm_id->provider_data = nesqp;
32429 @@ -3048,7 +3048,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32430
32431 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32432 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32433 - atomic_inc(&cm_accepts);
32434 + atomic_inc_unchecked(&cm_accepts);
32435
32436 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32437 netdev_refcnt_read(nesvnic->netdev));
32438 @@ -3250,7 +3250,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32439 struct nes_cm_core *cm_core;
32440 u8 *start_buff;
32441
32442 - atomic_inc(&cm_rejects);
32443 + atomic_inc_unchecked(&cm_rejects);
32444 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32445 loopback = cm_node->loopbackpartner;
32446 cm_core = cm_node->cm_core;
32447 @@ -3310,7 +3310,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32448 ntohl(cm_id->local_addr.sin_addr.s_addr),
32449 ntohs(cm_id->local_addr.sin_port));
32450
32451 - atomic_inc(&cm_connects);
32452 + atomic_inc_unchecked(&cm_connects);
32453 nesqp->active_conn = 1;
32454
32455 /* cache the cm_id in the qp */
32456 @@ -3416,7 +3416,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32457 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32458 return err;
32459 }
32460 - atomic_inc(&cm_listens_created);
32461 + atomic_inc_unchecked(&cm_listens_created);
32462 }
32463
32464 cm_id->add_ref(cm_id);
32465 @@ -3517,7 +3517,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32466
32467 if (nesqp->destroyed)
32468 return;
32469 - atomic_inc(&cm_connecteds);
32470 + atomic_inc_unchecked(&cm_connecteds);
32471 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32472 " local port 0x%04X. jiffies = %lu.\n",
32473 nesqp->hwqp.qp_id,
32474 @@ -3704,7 +3704,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32475
32476 cm_id->add_ref(cm_id);
32477 ret = cm_id->event_handler(cm_id, &cm_event);
32478 - atomic_inc(&cm_closes);
32479 + atomic_inc_unchecked(&cm_closes);
32480 cm_event.event = IW_CM_EVENT_CLOSE;
32481 cm_event.status = 0;
32482 cm_event.provider_data = cm_id->provider_data;
32483 @@ -3740,7 +3740,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32484 return;
32485 cm_id = cm_node->cm_id;
32486
32487 - atomic_inc(&cm_connect_reqs);
32488 + atomic_inc_unchecked(&cm_connect_reqs);
32489 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32490 cm_node, cm_id, jiffies);
32491
32492 @@ -3780,7 +3780,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32493 return;
32494 cm_id = cm_node->cm_id;
32495
32496 - atomic_inc(&cm_connect_reqs);
32497 + atomic_inc_unchecked(&cm_connect_reqs);
32498 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32499 cm_node, cm_id, jiffies);
32500
32501 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32502 index 3ba7be3..c81f6ff 100644
32503 --- a/drivers/infiniband/hw/nes/nes_mgt.c
32504 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
32505 @@ -40,8 +40,8 @@
32506 #include "nes.h"
32507 #include "nes_mgt.h"
32508
32509 -atomic_t pau_qps_created;
32510 -atomic_t pau_qps_destroyed;
32511 +atomic_unchecked_t pau_qps_created;
32512 +atomic_unchecked_t pau_qps_destroyed;
32513
32514 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32515 {
32516 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32517 {
32518 struct sk_buff *skb;
32519 unsigned long flags;
32520 - atomic_inc(&pau_qps_destroyed);
32521 + atomic_inc_unchecked(&pau_qps_destroyed);
32522
32523 /* Free packets that have not yet been forwarded */
32524 /* Lock is acquired by skb_dequeue when removing the skb */
32525 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32526 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32527 skb_queue_head_init(&nesqp->pau_list);
32528 spin_lock_init(&nesqp->pau_lock);
32529 - atomic_inc(&pau_qps_created);
32530 + atomic_inc_unchecked(&pau_qps_created);
32531 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32532 }
32533
32534 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32535 index f3a3ecf..57d311d 100644
32536 --- a/drivers/infiniband/hw/nes/nes_nic.c
32537 +++ b/drivers/infiniband/hw/nes/nes_nic.c
32538 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32539 target_stat_values[++index] = mh_detected;
32540 target_stat_values[++index] = mh_pauses_sent;
32541 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32542 - target_stat_values[++index] = atomic_read(&cm_connects);
32543 - target_stat_values[++index] = atomic_read(&cm_accepts);
32544 - target_stat_values[++index] = atomic_read(&cm_disconnects);
32545 - target_stat_values[++index] = atomic_read(&cm_connecteds);
32546 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32547 - target_stat_values[++index] = atomic_read(&cm_rejects);
32548 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32549 - target_stat_values[++index] = atomic_read(&qps_created);
32550 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32551 - target_stat_values[++index] = atomic_read(&qps_destroyed);
32552 - target_stat_values[++index] = atomic_read(&cm_closes);
32553 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32554 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32555 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32556 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32557 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32558 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32559 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32560 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32561 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32562 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32563 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32564 target_stat_values[++index] = cm_packets_sent;
32565 target_stat_values[++index] = cm_packets_bounced;
32566 target_stat_values[++index] = cm_packets_created;
32567 target_stat_values[++index] = cm_packets_received;
32568 target_stat_values[++index] = cm_packets_dropped;
32569 target_stat_values[++index] = cm_packets_retrans;
32570 - target_stat_values[++index] = atomic_read(&cm_listens_created);
32571 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32572 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32573 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32574 target_stat_values[++index] = cm_backlog_drops;
32575 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
32576 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
32577 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32578 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32579 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32580 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32581 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32582 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32583 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32584 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32585 target_stat_values[++index] = nesadapter->free_4kpbl;
32586 target_stat_values[++index] = nesadapter->free_256pbl;
32587 target_stat_values[++index] = int_mod_timer_init;
32588 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32589 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32590 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32591 - target_stat_values[++index] = atomic_read(&pau_qps_created);
32592 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32593 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32594 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32595 }
32596
32597 /**
32598 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32599 index 8b8812d..a5e1133 100644
32600 --- a/drivers/infiniband/hw/nes/nes_verbs.c
32601 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
32602 @@ -46,9 +46,9 @@
32603
32604 #include <rdma/ib_umem.h>
32605
32606 -atomic_t mod_qp_timouts;
32607 -atomic_t qps_created;
32608 -atomic_t sw_qps_destroyed;
32609 +atomic_unchecked_t mod_qp_timouts;
32610 +atomic_unchecked_t qps_created;
32611 +atomic_unchecked_t sw_qps_destroyed;
32612
32613 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32614
32615 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32616 if (init_attr->create_flags)
32617 return ERR_PTR(-EINVAL);
32618
32619 - atomic_inc(&qps_created);
32620 + atomic_inc_unchecked(&qps_created);
32621 switch (init_attr->qp_type) {
32622 case IB_QPT_RC:
32623 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32624 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32625 struct iw_cm_event cm_event;
32626 int ret = 0;
32627
32628 - atomic_inc(&sw_qps_destroyed);
32629 + atomic_inc_unchecked(&sw_qps_destroyed);
32630 nesqp->destroyed = 1;
32631
32632 /* Blow away the connection if it exists. */
32633 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32634 index 6b811e3..f8acf88 100644
32635 --- a/drivers/infiniband/hw/qib/qib.h
32636 +++ b/drivers/infiniband/hw/qib/qib.h
32637 @@ -51,6 +51,7 @@
32638 #include <linux/completion.h>
32639 #include <linux/kref.h>
32640 #include <linux/sched.h>
32641 +#include <linux/slab.h>
32642
32643 #include "qib_common.h"
32644 #include "qib_verbs.h"
32645 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32646 index da739d9..da1c7f4 100644
32647 --- a/drivers/input/gameport/gameport.c
32648 +++ b/drivers/input/gameport/gameport.c
32649 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32650 */
32651 static void gameport_init_port(struct gameport *gameport)
32652 {
32653 - static atomic_t gameport_no = ATOMIC_INIT(0);
32654 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32655
32656 __module_get(THIS_MODULE);
32657
32658 mutex_init(&gameport->drv_mutex);
32659 device_initialize(&gameport->dev);
32660 dev_set_name(&gameport->dev, "gameport%lu",
32661 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
32662 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32663 gameport->dev.bus = &gameport_bus;
32664 gameport->dev.release = gameport_release_port;
32665 if (gameport->parent)
32666 diff --git a/drivers/input/input.c b/drivers/input/input.c
32667 index 8921c61..f5cd63d 100644
32668 --- a/drivers/input/input.c
32669 +++ b/drivers/input/input.c
32670 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32671 */
32672 int input_register_device(struct input_dev *dev)
32673 {
32674 - static atomic_t input_no = ATOMIC_INIT(0);
32675 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32676 struct input_handler *handler;
32677 const char *path;
32678 int error;
32679 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32680 dev->setkeycode = input_default_setkeycode;
32681
32682 dev_set_name(&dev->dev, "input%ld",
32683 - (unsigned long) atomic_inc_return(&input_no) - 1);
32684 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32685
32686 error = device_add(&dev->dev);
32687 if (error)
32688 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32689 index b8d8611..7a4a04b 100644
32690 --- a/drivers/input/joystick/sidewinder.c
32691 +++ b/drivers/input/joystick/sidewinder.c
32692 @@ -30,6 +30,7 @@
32693 #include <linux/kernel.h>
32694 #include <linux/module.h>
32695 #include <linux/slab.h>
32696 +#include <linux/sched.h>
32697 #include <linux/init.h>
32698 #include <linux/input.h>
32699 #include <linux/gameport.h>
32700 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32701 index 42f7b25..09fcf46 100644
32702 --- a/drivers/input/joystick/xpad.c
32703 +++ b/drivers/input/joystick/xpad.c
32704 @@ -714,7 +714,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32705
32706 static int xpad_led_probe(struct usb_xpad *xpad)
32707 {
32708 - static atomic_t led_seq = ATOMIC_INIT(0);
32709 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32710 long led_no;
32711 struct xpad_led *led;
32712 struct led_classdev *led_cdev;
32713 @@ -727,7 +727,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32714 if (!led)
32715 return -ENOMEM;
32716
32717 - led_no = (long)atomic_inc_return(&led_seq) - 1;
32718 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32719
32720 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32721 led->xpad = xpad;
32722 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32723 index 0110b5a..d3ad144 100644
32724 --- a/drivers/input/mousedev.c
32725 +++ b/drivers/input/mousedev.c
32726 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32727
32728 spin_unlock_irq(&client->packet_lock);
32729
32730 - if (copy_to_user(buffer, data, count))
32731 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
32732 return -EFAULT;
32733
32734 return count;
32735 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
32736 index d0f7533..fb8215b 100644
32737 --- a/drivers/input/serio/serio.c
32738 +++ b/drivers/input/serio/serio.c
32739 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
32740 */
32741 static void serio_init_port(struct serio *serio)
32742 {
32743 - static atomic_t serio_no = ATOMIC_INIT(0);
32744 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
32745
32746 __module_get(THIS_MODULE);
32747
32748 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
32749 mutex_init(&serio->drv_mutex);
32750 device_initialize(&serio->dev);
32751 dev_set_name(&serio->dev, "serio%ld",
32752 - (long)atomic_inc_return(&serio_no) - 1);
32753 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
32754 serio->dev.bus = &serio_bus;
32755 serio->dev.release = serio_release_port;
32756 serio->dev.groups = serio_device_attr_groups;
32757 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
32758 index b902794..fc7b85b 100644
32759 --- a/drivers/isdn/capi/capi.c
32760 +++ b/drivers/isdn/capi/capi.c
32761 @@ -83,8 +83,8 @@ struct capiminor {
32762
32763 struct capi20_appl *ap;
32764 u32 ncci;
32765 - atomic_t datahandle;
32766 - atomic_t msgid;
32767 + atomic_unchecked_t datahandle;
32768 + atomic_unchecked_t msgid;
32769
32770 struct tty_port port;
32771 int ttyinstop;
32772 @@ -397,7 +397,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
32773 capimsg_setu16(s, 2, mp->ap->applid);
32774 capimsg_setu8 (s, 4, CAPI_DATA_B3);
32775 capimsg_setu8 (s, 5, CAPI_RESP);
32776 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
32777 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
32778 capimsg_setu32(s, 8, mp->ncci);
32779 capimsg_setu16(s, 12, datahandle);
32780 }
32781 @@ -518,14 +518,14 @@ static void handle_minor_send(struct capiminor *mp)
32782 mp->outbytes -= len;
32783 spin_unlock_bh(&mp->outlock);
32784
32785 - datahandle = atomic_inc_return(&mp->datahandle);
32786 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
32787 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
32788 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32789 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32790 capimsg_setu16(skb->data, 2, mp->ap->applid);
32791 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
32792 capimsg_setu8 (skb->data, 5, CAPI_REQ);
32793 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
32794 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
32795 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
32796 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
32797 capimsg_setu16(skb->data, 16, len); /* Data length */
32798 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
32799 index 821f7ac..28d4030 100644
32800 --- a/drivers/isdn/hardware/avm/b1.c
32801 +++ b/drivers/isdn/hardware/avm/b1.c
32802 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
32803 }
32804 if (left) {
32805 if (t4file->user) {
32806 - if (copy_from_user(buf, dp, left))
32807 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32808 return -EFAULT;
32809 } else {
32810 memcpy(buf, dp, left);
32811 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
32812 }
32813 if (left) {
32814 if (config->user) {
32815 - if (copy_from_user(buf, dp, left))
32816 + if (left > sizeof buf || copy_from_user(buf, dp, left))
32817 return -EFAULT;
32818 } else {
32819 memcpy(buf, dp, left);
32820 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
32821 index dd6b53a..19d9ee6 100644
32822 --- a/drivers/isdn/hardware/eicon/divasync.h
32823 +++ b/drivers/isdn/hardware/eicon/divasync.h
32824 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
32825 } diva_didd_add_adapter_t;
32826 typedef struct _diva_didd_remove_adapter {
32827 IDI_CALL p_request;
32828 -} diva_didd_remove_adapter_t;
32829 +} __no_const diva_didd_remove_adapter_t;
32830 typedef struct _diva_didd_read_adapter_array {
32831 void *buffer;
32832 dword length;
32833 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
32834 index d303e65..28bcb7b 100644
32835 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
32836 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
32837 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
32838 typedef struct _diva_os_idi_adapter_interface {
32839 diva_init_card_proc_t cleanup_adapter_proc;
32840 diva_cmd_card_proc_t cmd_proc;
32841 -} diva_os_idi_adapter_interface_t;
32842 +} __no_const diva_os_idi_adapter_interface_t;
32843
32844 typedef struct _diva_os_xdi_adapter {
32845 struct list_head link;
32846 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
32847 index e74df7c..03a03ba 100644
32848 --- a/drivers/isdn/icn/icn.c
32849 +++ b/drivers/isdn/icn/icn.c
32850 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
32851 if (count > len)
32852 count = len;
32853 if (user) {
32854 - if (copy_from_user(msg, buf, count))
32855 + if (count > sizeof msg || copy_from_user(msg, buf, count))
32856 return -EFAULT;
32857 } else
32858 memcpy(msg, buf, count);
32859 diff --git a/drivers/leds/leds-mc13783.c b/drivers/leds/leds-mc13783.c
32860 index 8bc4915..4cc6a2e 100644
32861 --- a/drivers/leds/leds-mc13783.c
32862 +++ b/drivers/leds/leds-mc13783.c
32863 @@ -280,7 +280,7 @@ static int __devinit mc13783_led_probe(struct platform_device *pdev)
32864 return -EINVAL;
32865 }
32866
32867 - led = kzalloc(sizeof(*led) * pdata->num_leds, GFP_KERNEL);
32868 + led = kcalloc(pdata->num_leds, sizeof(*led), GFP_KERNEL);
32869 if (led == NULL) {
32870 dev_err(&pdev->dev, "failed to alloc memory\n");
32871 return -ENOMEM;
32872 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
32873 index b5fdcb7..5b6c59f 100644
32874 --- a/drivers/lguest/core.c
32875 +++ b/drivers/lguest/core.c
32876 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
32877 * it's worked so far. The end address needs +1 because __get_vm_area
32878 * allocates an extra guard page, so we need space for that.
32879 */
32880 +
32881 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32882 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32883 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
32884 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32885 +#else
32886 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32887 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
32888 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32889 +#endif
32890 +
32891 if (!switcher_vma) {
32892 err = -ENOMEM;
32893 printk("lguest: could not map switcher pages high\n");
32894 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
32895 * Now the Switcher is mapped at the right address, we can't fail!
32896 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
32897 */
32898 - memcpy(switcher_vma->addr, start_switcher_text,
32899 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
32900 end_switcher_text - start_switcher_text);
32901
32902 printk(KERN_INFO "lguest: mapped switcher at %p\n",
32903 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
32904 index 39809035..ce25c5e 100644
32905 --- a/drivers/lguest/x86/core.c
32906 +++ b/drivers/lguest/x86/core.c
32907 @@ -59,7 +59,7 @@ static struct {
32908 /* Offset from where switcher.S was compiled to where we've copied it */
32909 static unsigned long switcher_offset(void)
32910 {
32911 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
32912 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
32913 }
32914
32915 /* This cpu's struct lguest_pages. */
32916 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
32917 * These copies are pretty cheap, so we do them unconditionally: */
32918 /* Save the current Host top-level page directory.
32919 */
32920 +
32921 +#ifdef CONFIG_PAX_PER_CPU_PGD
32922 + pages->state.host_cr3 = read_cr3();
32923 +#else
32924 pages->state.host_cr3 = __pa(current->mm->pgd);
32925 +#endif
32926 +
32927 /*
32928 * Set up the Guest's page tables to see this CPU's pages (and no
32929 * other CPU's pages).
32930 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
32931 * compiled-in switcher code and the high-mapped copy we just made.
32932 */
32933 for (i = 0; i < IDT_ENTRIES; i++)
32934 - default_idt_entries[i] += switcher_offset();
32935 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
32936
32937 /*
32938 * Set up the Switcher's per-cpu areas.
32939 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
32940 * it will be undisturbed when we switch. To change %cs and jump we
32941 * need this structure to feed to Intel's "lcall" instruction.
32942 */
32943 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
32944 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
32945 lguest_entry.segment = LGUEST_CS;
32946
32947 /*
32948 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
32949 index 40634b0..4f5855e 100644
32950 --- a/drivers/lguest/x86/switcher_32.S
32951 +++ b/drivers/lguest/x86/switcher_32.S
32952 @@ -87,6 +87,7 @@
32953 #include <asm/page.h>
32954 #include <asm/segment.h>
32955 #include <asm/lguest.h>
32956 +#include <asm/processor-flags.h>
32957
32958 // We mark the start of the code to copy
32959 // It's placed in .text tho it's never run here
32960 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
32961 // Changes type when we load it: damn Intel!
32962 // For after we switch over our page tables
32963 // That entry will be read-only: we'd crash.
32964 +
32965 +#ifdef CONFIG_PAX_KERNEXEC
32966 + mov %cr0, %edx
32967 + xor $X86_CR0_WP, %edx
32968 + mov %edx, %cr0
32969 +#endif
32970 +
32971 movl $(GDT_ENTRY_TSS*8), %edx
32972 ltr %dx
32973
32974 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
32975 // Let's clear it again for our return.
32976 // The GDT descriptor of the Host
32977 // Points to the table after two "size" bytes
32978 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
32979 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
32980 // Clear "used" from type field (byte 5, bit 2)
32981 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
32982 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
32983 +
32984 +#ifdef CONFIG_PAX_KERNEXEC
32985 + mov %cr0, %eax
32986 + xor $X86_CR0_WP, %eax
32987 + mov %eax, %cr0
32988 +#endif
32989
32990 // Once our page table's switched, the Guest is live!
32991 // The Host fades as we run this final step.
32992 @@ -295,13 +309,12 @@ deliver_to_host:
32993 // I consulted gcc, and it gave
32994 // These instructions, which I gladly credit:
32995 leal (%edx,%ebx,8), %eax
32996 - movzwl (%eax),%edx
32997 - movl 4(%eax), %eax
32998 - xorw %ax, %ax
32999 - orl %eax, %edx
33000 + movl 4(%eax), %edx
33001 + movw (%eax), %dx
33002 // Now the address of the handler's in %edx
33003 // We call it now: its "iret" drops us home.
33004 - jmp *%edx
33005 + ljmp $__KERNEL_CS, $1f
33006 +1: jmp *%edx
33007
33008 // Every interrupt can come to us here
33009 // But we must truly tell each apart.
33010 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33011 index 20e5c2c..9e849a9 100644
33012 --- a/drivers/macintosh/macio_asic.c
33013 +++ b/drivers/macintosh/macio_asic.c
33014 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33015 * MacIO is matched against any Apple ID, it's probe() function
33016 * will then decide wether it applies or not
33017 */
33018 -static const struct pci_device_id __devinitdata pci_ids [] = { {
33019 +static const struct pci_device_id __devinitconst pci_ids [] = { {
33020 .vendor = PCI_VENDOR_ID_APPLE,
33021 .device = PCI_ANY_ID,
33022 .subvendor = PCI_ANY_ID,
33023 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33024 index 17e2b47..bcbeec4 100644
33025 --- a/drivers/md/bitmap.c
33026 +++ b/drivers/md/bitmap.c
33027 @@ -1823,7 +1823,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33028 chunk_kb ? "KB" : "B");
33029 if (bitmap->file) {
33030 seq_printf(seq, ", file: ");
33031 - seq_path(seq, &bitmap->file->f_path, " \t\n");
33032 + seq_path(seq, &bitmap->file->f_path, " \t\n\\");
33033 }
33034
33035 seq_printf(seq, "\n");
33036 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33037 index a1a3e6d..1918bfc 100644
33038 --- a/drivers/md/dm-ioctl.c
33039 +++ b/drivers/md/dm-ioctl.c
33040 @@ -1590,7 +1590,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33041 cmd == DM_LIST_VERSIONS_CMD)
33042 return 0;
33043
33044 - if ((cmd == DM_DEV_CREATE_CMD)) {
33045 + if (cmd == DM_DEV_CREATE_CMD) {
33046 if (!*param->name) {
33047 DMWARN("name not supplied when creating device");
33048 return -EINVAL;
33049 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33050 index d039de8..0cf5b87 100644
33051 --- a/drivers/md/dm-raid1.c
33052 +++ b/drivers/md/dm-raid1.c
33053 @@ -40,7 +40,7 @@ enum dm_raid1_error {
33054
33055 struct mirror {
33056 struct mirror_set *ms;
33057 - atomic_t error_count;
33058 + atomic_unchecked_t error_count;
33059 unsigned long error_type;
33060 struct dm_dev *dev;
33061 sector_t offset;
33062 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33063 struct mirror *m;
33064
33065 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33066 - if (!atomic_read(&m->error_count))
33067 + if (!atomic_read_unchecked(&m->error_count))
33068 return m;
33069
33070 return NULL;
33071 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33072 * simple way to tell if a device has encountered
33073 * errors.
33074 */
33075 - atomic_inc(&m->error_count);
33076 + atomic_inc_unchecked(&m->error_count);
33077
33078 if (test_and_set_bit(error_type, &m->error_type))
33079 return;
33080 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33081 struct mirror *m = get_default_mirror(ms);
33082
33083 do {
33084 - if (likely(!atomic_read(&m->error_count)))
33085 + if (likely(!atomic_read_unchecked(&m->error_count)))
33086 return m;
33087
33088 if (m-- == ms->mirror)
33089 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33090 {
33091 struct mirror *default_mirror = get_default_mirror(m->ms);
33092
33093 - return !atomic_read(&default_mirror->error_count);
33094 + return !atomic_read_unchecked(&default_mirror->error_count);
33095 }
33096
33097 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33098 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33099 */
33100 if (likely(region_in_sync(ms, region, 1)))
33101 m = choose_mirror(ms, bio->bi_sector);
33102 - else if (m && atomic_read(&m->error_count))
33103 + else if (m && atomic_read_unchecked(&m->error_count))
33104 m = NULL;
33105
33106 if (likely(m))
33107 @@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33108 }
33109
33110 ms->mirror[mirror].ms = ms;
33111 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33112 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33113 ms->mirror[mirror].error_type = 0;
33114 ms->mirror[mirror].offset = offset;
33115
33116 @@ -1351,7 +1351,7 @@ static void mirror_resume(struct dm_target *ti)
33117 */
33118 static char device_status_char(struct mirror *m)
33119 {
33120 - if (!atomic_read(&(m->error_count)))
33121 + if (!atomic_read_unchecked(&(m->error_count)))
33122 return 'A';
33123
33124 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33125 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33126 index 35c94ff..20d4c17 100644
33127 --- a/drivers/md/dm-stripe.c
33128 +++ b/drivers/md/dm-stripe.c
33129 @@ -20,7 +20,7 @@ struct stripe {
33130 struct dm_dev *dev;
33131 sector_t physical_start;
33132
33133 - atomic_t error_count;
33134 + atomic_unchecked_t error_count;
33135 };
33136
33137 struct stripe_c {
33138 @@ -193,7 +193,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33139 kfree(sc);
33140 return r;
33141 }
33142 - atomic_set(&(sc->stripe[i].error_count), 0);
33143 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33144 }
33145
33146 ti->private = sc;
33147 @@ -315,7 +315,7 @@ static int stripe_status(struct dm_target *ti,
33148 DMEMIT("%d ", sc->stripes);
33149 for (i = 0; i < sc->stripes; i++) {
33150 DMEMIT("%s ", sc->stripe[i].dev->name);
33151 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33152 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33153 'D' : 'A';
33154 }
33155 buffer[i] = '\0';
33156 @@ -362,8 +362,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33157 */
33158 for (i = 0; i < sc->stripes; i++)
33159 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33160 - atomic_inc(&(sc->stripe[i].error_count));
33161 - if (atomic_read(&(sc->stripe[i].error_count)) <
33162 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
33163 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33164 DM_IO_ERROR_THRESHOLD)
33165 schedule_work(&sc->trigger_event);
33166 }
33167 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33168 index 2e227fb..44ead1f 100644
33169 --- a/drivers/md/dm-table.c
33170 +++ b/drivers/md/dm-table.c
33171 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33172 if (!dev_size)
33173 return 0;
33174
33175 - if ((start >= dev_size) || (start + len > dev_size)) {
33176 + if ((start >= dev_size) || (len > dev_size - start)) {
33177 DMWARN("%s: %s too small for target: "
33178 "start=%llu, len=%llu, dev_size=%llu",
33179 dm_device_name(ti->table->md), bdevname(bdev, b),
33180 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33181 index 737d388..811ad5a 100644
33182 --- a/drivers/md/dm-thin-metadata.c
33183 +++ b/drivers/md/dm-thin-metadata.c
33184 @@ -432,7 +432,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33185
33186 pmd->info.tm = tm;
33187 pmd->info.levels = 2;
33188 - pmd->info.value_type.context = pmd->data_sm;
33189 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33190 pmd->info.value_type.size = sizeof(__le64);
33191 pmd->info.value_type.inc = data_block_inc;
33192 pmd->info.value_type.dec = data_block_dec;
33193 @@ -451,7 +451,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33194
33195 pmd->bl_info.tm = tm;
33196 pmd->bl_info.levels = 1;
33197 - pmd->bl_info.value_type.context = pmd->data_sm;
33198 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33199 pmd->bl_info.value_type.size = sizeof(__le64);
33200 pmd->bl_info.value_type.inc = data_block_inc;
33201 pmd->bl_info.value_type.dec = data_block_dec;
33202 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33203 index e24143c..ce2f21a1 100644
33204 --- a/drivers/md/dm.c
33205 +++ b/drivers/md/dm.c
33206 @@ -176,9 +176,9 @@ struct mapped_device {
33207 /*
33208 * Event handling.
33209 */
33210 - atomic_t event_nr;
33211 + atomic_unchecked_t event_nr;
33212 wait_queue_head_t eventq;
33213 - atomic_t uevent_seq;
33214 + atomic_unchecked_t uevent_seq;
33215 struct list_head uevent_list;
33216 spinlock_t uevent_lock; /* Protect access to uevent_list */
33217
33218 @@ -1845,8 +1845,8 @@ static struct mapped_device *alloc_dev(int minor)
33219 rwlock_init(&md->map_lock);
33220 atomic_set(&md->holders, 1);
33221 atomic_set(&md->open_count, 0);
33222 - atomic_set(&md->event_nr, 0);
33223 - atomic_set(&md->uevent_seq, 0);
33224 + atomic_set_unchecked(&md->event_nr, 0);
33225 + atomic_set_unchecked(&md->uevent_seq, 0);
33226 INIT_LIST_HEAD(&md->uevent_list);
33227 spin_lock_init(&md->uevent_lock);
33228
33229 @@ -1980,7 +1980,7 @@ static void event_callback(void *context)
33230
33231 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33232
33233 - atomic_inc(&md->event_nr);
33234 + atomic_inc_unchecked(&md->event_nr);
33235 wake_up(&md->eventq);
33236 }
33237
33238 @@ -2622,18 +2622,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33239
33240 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33241 {
33242 - return atomic_add_return(1, &md->uevent_seq);
33243 + return atomic_add_return_unchecked(1, &md->uevent_seq);
33244 }
33245
33246 uint32_t dm_get_event_nr(struct mapped_device *md)
33247 {
33248 - return atomic_read(&md->event_nr);
33249 + return atomic_read_unchecked(&md->event_nr);
33250 }
33251
33252 int dm_wait_event(struct mapped_device *md, int event_nr)
33253 {
33254 return wait_event_interruptible(md->eventq,
33255 - (event_nr != atomic_read(&md->event_nr)));
33256 + (event_nr != atomic_read_unchecked(&md->event_nr)));
33257 }
33258
33259 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33260 diff --git a/drivers/md/md.c b/drivers/md/md.c
33261 index 2b30ffd..362b519 100644
33262 --- a/drivers/md/md.c
33263 +++ b/drivers/md/md.c
33264 @@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33265 * start build, activate spare
33266 */
33267 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33268 -static atomic_t md_event_count;
33269 +static atomic_unchecked_t md_event_count;
33270 void md_new_event(struct mddev *mddev)
33271 {
33272 - atomic_inc(&md_event_count);
33273 + atomic_inc_unchecked(&md_event_count);
33274 wake_up(&md_event_waiters);
33275 }
33276 EXPORT_SYMBOL_GPL(md_new_event);
33277 @@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33278 */
33279 static void md_new_event_inintr(struct mddev *mddev)
33280 {
33281 - atomic_inc(&md_event_count);
33282 + atomic_inc_unchecked(&md_event_count);
33283 wake_up(&md_event_waiters);
33284 }
33285
33286 @@ -1526,7 +1526,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33287
33288 rdev->preferred_minor = 0xffff;
33289 rdev->data_offset = le64_to_cpu(sb->data_offset);
33290 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33291 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33292
33293 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33294 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33295 @@ -1745,7 +1745,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33296 else
33297 sb->resync_offset = cpu_to_le64(0);
33298
33299 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33300 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33301
33302 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33303 sb->size = cpu_to_le64(mddev->dev_sectors);
33304 @@ -2691,7 +2691,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33305 static ssize_t
33306 errors_show(struct md_rdev *rdev, char *page)
33307 {
33308 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33309 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33310 }
33311
33312 static ssize_t
33313 @@ -2700,7 +2700,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33314 char *e;
33315 unsigned long n = simple_strtoul(buf, &e, 10);
33316 if (*buf && (*e == 0 || *e == '\n')) {
33317 - atomic_set(&rdev->corrected_errors, n);
33318 + atomic_set_unchecked(&rdev->corrected_errors, n);
33319 return len;
33320 }
33321 return -EINVAL;
33322 @@ -3086,8 +3086,8 @@ int md_rdev_init(struct md_rdev *rdev)
33323 rdev->sb_loaded = 0;
33324 rdev->bb_page = NULL;
33325 atomic_set(&rdev->nr_pending, 0);
33326 - atomic_set(&rdev->read_errors, 0);
33327 - atomic_set(&rdev->corrected_errors, 0);
33328 + atomic_set_unchecked(&rdev->read_errors, 0);
33329 + atomic_set_unchecked(&rdev->corrected_errors, 0);
33330
33331 INIT_LIST_HEAD(&rdev->same_set);
33332 init_waitqueue_head(&rdev->blocked_wait);
33333 @@ -3744,8 +3744,8 @@ array_state_show(struct mddev *mddev, char *page)
33334 return sprintf(page, "%s\n", array_states[st]);
33335 }
33336
33337 -static int do_md_stop(struct mddev * mddev, int ro, int is_open);
33338 -static int md_set_readonly(struct mddev * mddev, int is_open);
33339 +static int do_md_stop(struct mddev * mddev, int ro, struct block_device *bdev);
33340 +static int md_set_readonly(struct mddev * mddev, struct block_device *bdev);
33341 static int do_md_run(struct mddev * mddev);
33342 static int restart_array(struct mddev *mddev);
33343
33344 @@ -3761,14 +3761,14 @@ array_state_store(struct mddev *mddev, const char *buf, size_t len)
33345 /* stopping an active array */
33346 if (atomic_read(&mddev->openers) > 0)
33347 return -EBUSY;
33348 - err = do_md_stop(mddev, 0, 0);
33349 + err = do_md_stop(mddev, 0, NULL);
33350 break;
33351 case inactive:
33352 /* stopping an active array */
33353 if (mddev->pers) {
33354 if (atomic_read(&mddev->openers) > 0)
33355 return -EBUSY;
33356 - err = do_md_stop(mddev, 2, 0);
33357 + err = do_md_stop(mddev, 2, NULL);
33358 } else
33359 err = 0; /* already inactive */
33360 break;
33361 @@ -3776,7 +3776,7 @@ array_state_store(struct mddev *mddev, const char *buf, size_t len)
33362 break; /* not supported yet */
33363 case readonly:
33364 if (mddev->pers)
33365 - err = md_set_readonly(mddev, 0);
33366 + err = md_set_readonly(mddev, NULL);
33367 else {
33368 mddev->ro = 1;
33369 set_disk_ro(mddev->gendisk, 1);
33370 @@ -3786,7 +3786,7 @@ array_state_store(struct mddev *mddev, const char *buf, size_t len)
33371 case read_auto:
33372 if (mddev->pers) {
33373 if (mddev->ro == 0)
33374 - err = md_set_readonly(mddev, 0);
33375 + err = md_set_readonly(mddev, NULL);
33376 else if (mddev->ro == 1)
33377 err = restart_array(mddev);
33378 if (err == 0) {
33379 @@ -5124,15 +5124,17 @@ void md_stop(struct mddev *mddev)
33380 }
33381 EXPORT_SYMBOL_GPL(md_stop);
33382
33383 -static int md_set_readonly(struct mddev *mddev, int is_open)
33384 +static int md_set_readonly(struct mddev *mddev, struct block_device *bdev)
33385 {
33386 int err = 0;
33387 mutex_lock(&mddev->open_mutex);
33388 - if (atomic_read(&mddev->openers) > is_open) {
33389 + if (atomic_read(&mddev->openers) > !!bdev) {
33390 printk("md: %s still in use.\n",mdname(mddev));
33391 err = -EBUSY;
33392 goto out;
33393 }
33394 + if (bdev)
33395 + sync_blockdev(bdev);
33396 if (mddev->pers) {
33397 __md_stop_writes(mddev);
33398
33399 @@ -5154,18 +5156,26 @@ out:
33400 * 0 - completely stop and dis-assemble array
33401 * 2 - stop but do not disassemble array
33402 */
33403 -static int do_md_stop(struct mddev * mddev, int mode, int is_open)
33404 +static int do_md_stop(struct mddev * mddev, int mode,
33405 + struct block_device *bdev)
33406 {
33407 struct gendisk *disk = mddev->gendisk;
33408 struct md_rdev *rdev;
33409
33410 mutex_lock(&mddev->open_mutex);
33411 - if (atomic_read(&mddev->openers) > is_open ||
33412 + if (atomic_read(&mddev->openers) > !!bdev ||
33413 mddev->sysfs_active) {
33414 printk("md: %s still in use.\n",mdname(mddev));
33415 mutex_unlock(&mddev->open_mutex);
33416 return -EBUSY;
33417 }
33418 + if (bdev)
33419 + /* It is possible IO was issued on some other
33420 + * open file which was closed before we took ->open_mutex.
33421 + * As that was not the last close __blkdev_put will not
33422 + * have called sync_blockdev, so we must.
33423 + */
33424 + sync_blockdev(bdev);
33425
33426 if (mddev->pers) {
33427 if (mddev->ro)
33428 @@ -5239,7 +5249,7 @@ static void autorun_array(struct mddev *mddev)
33429 err = do_md_run(mddev);
33430 if (err) {
33431 printk(KERN_WARNING "md: do_md_run() returned %d\n", err);
33432 - do_md_stop(mddev, 0, 0);
33433 + do_md_stop(mddev, 0, NULL);
33434 }
33435 }
33436
33437 @@ -6237,11 +6247,11 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
33438 goto done_unlock;
33439
33440 case STOP_ARRAY:
33441 - err = do_md_stop(mddev, 0, 1);
33442 + err = do_md_stop(mddev, 0, bdev);
33443 goto done_unlock;
33444
33445 case STOP_ARRAY_RO:
33446 - err = md_set_readonly(mddev, 1);
33447 + err = md_set_readonly(mddev, bdev);
33448 goto done_unlock;
33449
33450 case BLKROSET:
33451 @@ -6738,7 +6748,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33452
33453 spin_unlock(&pers_lock);
33454 seq_printf(seq, "\n");
33455 - seq->poll_event = atomic_read(&md_event_count);
33456 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33457 return 0;
33458 }
33459 if (v == (void*)2) {
33460 @@ -6841,7 +6851,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33461 return error;
33462
33463 seq = file->private_data;
33464 - seq->poll_event = atomic_read(&md_event_count);
33465 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33466 return error;
33467 }
33468
33469 @@ -6855,7 +6865,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33470 /* always allow read */
33471 mask = POLLIN | POLLRDNORM;
33472
33473 - if (seq->poll_event != atomic_read(&md_event_count))
33474 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33475 mask |= POLLERR | POLLPRI;
33476 return mask;
33477 }
33478 @@ -6899,7 +6909,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33479 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33480 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33481 (int)part_stat_read(&disk->part0, sectors[1]) -
33482 - atomic_read(&disk->sync_io);
33483 + atomic_read_unchecked(&disk->sync_io);
33484 /* sync IO will cause sync_io to increase before the disk_stats
33485 * as sync_io is counted when a request starts, and
33486 * disk_stats is counted when it completes.
33487 diff --git a/drivers/md/md.h b/drivers/md/md.h
33488 index 1c2063c..9639970 100644
33489 --- a/drivers/md/md.h
33490 +++ b/drivers/md/md.h
33491 @@ -93,13 +93,13 @@ struct md_rdev {
33492 * only maintained for arrays that
33493 * support hot removal
33494 */
33495 - atomic_t read_errors; /* number of consecutive read errors that
33496 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
33497 * we have tried to ignore.
33498 */
33499 struct timespec last_read_error; /* monotonic time since our
33500 * last read error
33501 */
33502 - atomic_t corrected_errors; /* number of corrected read errors,
33503 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33504 * for reporting to userspace and storing
33505 * in superblock.
33506 */
33507 @@ -429,7 +429,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33508
33509 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33510 {
33511 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33512 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33513 }
33514
33515 struct md_personality
33516 diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
33517 index fc90c11..c8cd9a9 100644
33518 --- a/drivers/md/persistent-data/dm-space-map-checker.c
33519 +++ b/drivers/md/persistent-data/dm-space-map-checker.c
33520 @@ -167,7 +167,7 @@ static int ca_commit(struct count_array *old, struct count_array *new)
33521 /*----------------------------------------------------------------*/
33522
33523 struct sm_checker {
33524 - struct dm_space_map sm;
33525 + dm_space_map_no_const sm;
33526
33527 struct count_array old_counts;
33528 struct count_array counts;
33529 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33530 index 3d0ed53..35dc592 100644
33531 --- a/drivers/md/persistent-data/dm-space-map-disk.c
33532 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
33533 @@ -23,7 +23,7 @@
33534 * Space map interface.
33535 */
33536 struct sm_disk {
33537 - struct dm_space_map sm;
33538 + dm_space_map_no_const sm;
33539
33540 struct ll_disk ll;
33541 struct ll_disk old_ll;
33542 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33543 index e89ae5e..062e4c2 100644
33544 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
33545 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33546 @@ -43,7 +43,7 @@ struct block_op {
33547 };
33548
33549 struct sm_metadata {
33550 - struct dm_space_map sm;
33551 + dm_space_map_no_const sm;
33552
33553 struct ll_disk ll;
33554 struct ll_disk old_ll;
33555 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33556 index 1cbfc6b..56e1dbb 100644
33557 --- a/drivers/md/persistent-data/dm-space-map.h
33558 +++ b/drivers/md/persistent-data/dm-space-map.h
33559 @@ -60,6 +60,7 @@ struct dm_space_map {
33560 int (*root_size)(struct dm_space_map *sm, size_t *result);
33561 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33562 };
33563 +typedef struct dm_space_map __no_const dm_space_map_no_const;
33564
33565 /*----------------------------------------------------------------*/
33566
33567 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33568 index d1f74ab..d1b24fd 100644
33569 --- a/drivers/md/raid1.c
33570 +++ b/drivers/md/raid1.c
33571 @@ -1688,7 +1688,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33572 if (r1_sync_page_io(rdev, sect, s,
33573 bio->bi_io_vec[idx].bv_page,
33574 READ) != 0)
33575 - atomic_add(s, &rdev->corrected_errors);
33576 + atomic_add_unchecked(s, &rdev->corrected_errors);
33577 }
33578 sectors -= s;
33579 sect += s;
33580 @@ -1902,7 +1902,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33581 test_bit(In_sync, &rdev->flags)) {
33582 if (r1_sync_page_io(rdev, sect, s,
33583 conf->tmppage, READ)) {
33584 - atomic_add(s, &rdev->corrected_errors);
33585 + atomic_add_unchecked(s, &rdev->corrected_errors);
33586 printk(KERN_INFO
33587 "md/raid1:%s: read error corrected "
33588 "(%d sectors at %llu on %s)\n",
33589 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33590 index a954c95..6e7a21c 100644
33591 --- a/drivers/md/raid10.c
33592 +++ b/drivers/md/raid10.c
33593 @@ -1684,7 +1684,7 @@ static void end_sync_read(struct bio *bio, int error)
33594 /* The write handler will notice the lack of
33595 * R10BIO_Uptodate and record any errors etc
33596 */
33597 - atomic_add(r10_bio->sectors,
33598 + atomic_add_unchecked(r10_bio->sectors,
33599 &conf->mirrors[d].rdev->corrected_errors);
33600
33601 /* for reconstruct, we always reschedule after a read.
33602 @@ -2033,7 +2033,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33603 {
33604 struct timespec cur_time_mon;
33605 unsigned long hours_since_last;
33606 - unsigned int read_errors = atomic_read(&rdev->read_errors);
33607 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33608
33609 ktime_get_ts(&cur_time_mon);
33610
33611 @@ -2055,9 +2055,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33612 * overflowing the shift of read_errors by hours_since_last.
33613 */
33614 if (hours_since_last >= 8 * sizeof(read_errors))
33615 - atomic_set(&rdev->read_errors, 0);
33616 + atomic_set_unchecked(&rdev->read_errors, 0);
33617 else
33618 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33619 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33620 }
33621
33622 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33623 @@ -2111,8 +2111,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33624 return;
33625
33626 check_decay_read_errors(mddev, rdev);
33627 - atomic_inc(&rdev->read_errors);
33628 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
33629 + atomic_inc_unchecked(&rdev->read_errors);
33630 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33631 char b[BDEVNAME_SIZE];
33632 bdevname(rdev->bdev, b);
33633
33634 @@ -2120,7 +2120,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33635 "md/raid10:%s: %s: Raid device exceeded "
33636 "read_error threshold [cur %d:max %d]\n",
33637 mdname(mddev), b,
33638 - atomic_read(&rdev->read_errors), max_read_errors);
33639 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33640 printk(KERN_NOTICE
33641 "md/raid10:%s: %s: Failing raid device\n",
33642 mdname(mddev), b);
33643 @@ -2271,7 +2271,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33644 (unsigned long long)(
33645 sect + rdev->data_offset),
33646 bdevname(rdev->bdev, b));
33647 - atomic_add(s, &rdev->corrected_errors);
33648 + atomic_add_unchecked(s, &rdev->corrected_errors);
33649 }
33650
33651 rdev_dec_pending(rdev, mddev);
33652 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33653 index 73a5800..2b0e3b1 100644
33654 --- a/drivers/md/raid5.c
33655 +++ b/drivers/md/raid5.c
33656 @@ -1694,18 +1694,18 @@ static void raid5_end_read_request(struct bio * bi, int error)
33657 (unsigned long long)(sh->sector
33658 + rdev->data_offset),
33659 bdevname(rdev->bdev, b));
33660 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33661 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33662 clear_bit(R5_ReadError, &sh->dev[i].flags);
33663 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33664 }
33665 - if (atomic_read(&rdev->read_errors))
33666 - atomic_set(&rdev->read_errors, 0);
33667 + if (atomic_read_unchecked(&rdev->read_errors))
33668 + atomic_set_unchecked(&rdev->read_errors, 0);
33669 } else {
33670 const char *bdn = bdevname(rdev->bdev, b);
33671 int retry = 0;
33672
33673 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33674 - atomic_inc(&rdev->read_errors);
33675 + atomic_inc_unchecked(&rdev->read_errors);
33676 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33677 printk_ratelimited(
33678 KERN_WARNING
33679 @@ -1734,7 +1734,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33680 (unsigned long long)(sh->sector
33681 + rdev->data_offset),
33682 bdn);
33683 - else if (atomic_read(&rdev->read_errors)
33684 + else if (atomic_read_unchecked(&rdev->read_errors)
33685 > conf->max_nr_stripes)
33686 printk(KERN_WARNING
33687 "md/raid:%s: Too many read errors, failing device %s.\n",
33688 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33689 index d88c4aa..17c80b1 100644
33690 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33691 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33692 @@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
33693 .subvendor = _subvend, .subdevice = _subdev, \
33694 .driver_data = (unsigned long)&_driverdata }
33695
33696 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33697 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33698 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33699 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33700 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33701 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33702 index a7d876f..8c21b61 100644
33703 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
33704 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33705 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
33706 union {
33707 dmx_ts_cb ts;
33708 dmx_section_cb sec;
33709 - } cb;
33710 + } __no_const cb;
33711
33712 struct dvb_demux *demux;
33713 void *priv;
33714 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33715 index 39eab73..60033e7 100644
33716 --- a/drivers/media/dvb/dvb-core/dvbdev.c
33717 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
33718 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33719 const struct dvb_device *template, void *priv, int type)
33720 {
33721 struct dvb_device *dvbdev;
33722 - struct file_operations *dvbdevfops;
33723 + file_operations_no_const *dvbdevfops;
33724 struct device *clsdev;
33725 int minor;
33726 int id;
33727 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33728 index 3940bb0..fb3952a 100644
33729 --- a/drivers/media/dvb/dvb-usb/cxusb.c
33730 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
33731 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33732
33733 struct dib0700_adapter_state {
33734 int (*set_param_save) (struct dvb_frontend *);
33735 -};
33736 +} __no_const;
33737
33738 static int dib7070_set_param_override(struct dvb_frontend *fe)
33739 {
33740 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33741 index 451c5a7..649f711 100644
33742 --- a/drivers/media/dvb/dvb-usb/dw2102.c
33743 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
33744 @@ -95,7 +95,7 @@ struct su3000_state {
33745
33746 struct s6x0_state {
33747 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33748 -};
33749 +} __no_const;
33750
33751 /* debug */
33752 static int dvb_usb_dw2102_debug;
33753 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33754 index 404f63a..4796533 100644
33755 --- a/drivers/media/dvb/frontends/dib3000.h
33756 +++ b/drivers/media/dvb/frontends/dib3000.h
33757 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33758 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33759 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33760 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33761 -};
33762 +} __no_const;
33763
33764 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33765 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33766 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33767 index 7539a5d..06531a6 100644
33768 --- a/drivers/media/dvb/ngene/ngene-cards.c
33769 +++ b/drivers/media/dvb/ngene/ngene-cards.c
33770 @@ -478,7 +478,7 @@ static struct ngene_info ngene_info_m780 = {
33771
33772 /****************************************************************************/
33773
33774 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33775 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33776 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33777 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33778 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33779 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33780 index 16a089f..1661b11 100644
33781 --- a/drivers/media/radio/radio-cadet.c
33782 +++ b/drivers/media/radio/radio-cadet.c
33783 @@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33784 unsigned char readbuf[RDS_BUFFER];
33785 int i = 0;
33786
33787 + if (count > RDS_BUFFER)
33788 + return -EFAULT;
33789 mutex_lock(&dev->lock);
33790 if (dev->rdsstat == 0) {
33791 dev->rdsstat = 1;
33792 @@ -347,7 +349,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33793 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
33794 mutex_unlock(&dev->lock);
33795
33796 - if (copy_to_user(data, readbuf, i))
33797 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
33798 return -EFAULT;
33799 return i;
33800 }
33801 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
33802 index 9cde353..8c6a1c3 100644
33803 --- a/drivers/media/video/au0828/au0828.h
33804 +++ b/drivers/media/video/au0828/au0828.h
33805 @@ -191,7 +191,7 @@ struct au0828_dev {
33806
33807 /* I2C */
33808 struct i2c_adapter i2c_adap;
33809 - struct i2c_algorithm i2c_algo;
33810 + i2c_algorithm_no_const i2c_algo;
33811 struct i2c_client i2c_client;
33812 u32 i2c_rc;
33813
33814 diff --git a/drivers/media/video/cx25821/cx25821-core.c b/drivers/media/video/cx25821/cx25821-core.c
33815 index 7930ca5..235bf7d 100644
33816 --- a/drivers/media/video/cx25821/cx25821-core.c
33817 +++ b/drivers/media/video/cx25821/cx25821-core.c
33818 @@ -912,9 +912,6 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
33819 list_add_tail(&dev->devlist, &cx25821_devlist);
33820 mutex_unlock(&cx25821_devlist_mutex);
33821
33822 - strcpy(cx25821_boards[UNKNOWN_BOARD].name, "unknown");
33823 - strcpy(cx25821_boards[CX25821_BOARD].name, "cx25821");
33824 -
33825 if (dev->pci->device != 0x8210) {
33826 pr_info("%s(): Exiting. Incorrect Hardware device = 0x%02x\n",
33827 __func__, dev->pci->device);
33828 diff --git a/drivers/media/video/cx25821/cx25821.h b/drivers/media/video/cx25821/cx25821.h
33829 index b9aa801..029f293 100644
33830 --- a/drivers/media/video/cx25821/cx25821.h
33831 +++ b/drivers/media/video/cx25821/cx25821.h
33832 @@ -187,7 +187,7 @@ enum port {
33833 };
33834
33835 struct cx25821_board {
33836 - char *name;
33837 + const char *name;
33838 enum port porta;
33839 enum port portb;
33840 enum port portc;
33841 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
33842 index 04bf662..e0ac026 100644
33843 --- a/drivers/media/video/cx88/cx88-alsa.c
33844 +++ b/drivers/media/video/cx88/cx88-alsa.c
33845 @@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
33846 * Only boards with eeprom and byte 1 at eeprom=1 have it
33847 */
33848
33849 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
33850 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
33851 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33852 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33853 {0, }
33854 diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
33855 index 88cf9d9..bbc4b2c 100644
33856 --- a/drivers/media/video/omap/omap_vout.c
33857 +++ b/drivers/media/video/omap/omap_vout.c
33858 @@ -64,7 +64,6 @@ enum omap_vout_channels {
33859 OMAP_VIDEO2,
33860 };
33861
33862 -static struct videobuf_queue_ops video_vbq_ops;
33863 /* Variables configurable through module params*/
33864 static u32 video1_numbuffers = 3;
33865 static u32 video2_numbuffers = 3;
33866 @@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
33867 {
33868 struct videobuf_queue *q;
33869 struct omap_vout_device *vout = NULL;
33870 + static struct videobuf_queue_ops video_vbq_ops = {
33871 + .buf_setup = omap_vout_buffer_setup,
33872 + .buf_prepare = omap_vout_buffer_prepare,
33873 + .buf_release = omap_vout_buffer_release,
33874 + .buf_queue = omap_vout_buffer_queue,
33875 + };
33876
33877 vout = video_drvdata(file);
33878 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
33879 @@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
33880 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
33881
33882 q = &vout->vbq;
33883 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
33884 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
33885 - video_vbq_ops.buf_release = omap_vout_buffer_release;
33886 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
33887 spin_lock_init(&vout->vbq_lock);
33888
33889 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
33890 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33891 index 305e6aa..0143317 100644
33892 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33893 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33894 @@ -196,7 +196,7 @@ struct pvr2_hdw {
33895
33896 /* I2C stuff */
33897 struct i2c_adapter i2c_adap;
33898 - struct i2c_algorithm i2c_algo;
33899 + i2c_algorithm_no_const i2c_algo;
33900 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
33901 int i2c_cx25840_hack_state;
33902 int i2c_linked;
33903 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
33904 index 02194c0..091733b 100644
33905 --- a/drivers/media/video/timblogiw.c
33906 +++ b/drivers/media/video/timblogiw.c
33907 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
33908
33909 /* Platform device functions */
33910
33911 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33912 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
33913 .vidioc_querycap = timblogiw_querycap,
33914 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
33915 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
33916 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33917 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
33918 };
33919
33920 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
33921 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
33922 .owner = THIS_MODULE,
33923 .open = timblogiw_open,
33924 .release = timblogiw_close,
33925 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
33926 index a5c591f..db692a3 100644
33927 --- a/drivers/message/fusion/mptbase.c
33928 +++ b/drivers/message/fusion/mptbase.c
33929 @@ -6754,8 +6754,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
33930 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
33931 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33932
33933 +#ifdef CONFIG_GRKERNSEC_HIDESYM
33934 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
33935 +#else
33936 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33937 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33938 +#endif
33939 +
33940 /*
33941 * Rounding UP to nearest 4-kB boundary here...
33942 */
33943 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
33944 index 551262e..7551198 100644
33945 --- a/drivers/message/fusion/mptsas.c
33946 +++ b/drivers/message/fusion/mptsas.c
33947 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
33948 return 0;
33949 }
33950
33951 +static inline void
33952 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33953 +{
33954 + if (phy_info->port_details) {
33955 + phy_info->port_details->rphy = rphy;
33956 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33957 + ioc->name, rphy));
33958 + }
33959 +
33960 + if (rphy) {
33961 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33962 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33963 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33964 + ioc->name, rphy, rphy->dev.release));
33965 + }
33966 +}
33967 +
33968 /* no mutex */
33969 static void
33970 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
33971 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
33972 return NULL;
33973 }
33974
33975 -static inline void
33976 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33977 -{
33978 - if (phy_info->port_details) {
33979 - phy_info->port_details->rphy = rphy;
33980 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33981 - ioc->name, rphy));
33982 - }
33983 -
33984 - if (rphy) {
33985 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33986 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33987 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33988 - ioc->name, rphy, rphy->dev.release));
33989 - }
33990 -}
33991 -
33992 static inline struct sas_port *
33993 mptsas_get_port(struct mptsas_phyinfo *phy_info)
33994 {
33995 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
33996 index 0c3ced7..1fe34ec 100644
33997 --- a/drivers/message/fusion/mptscsih.c
33998 +++ b/drivers/message/fusion/mptscsih.c
33999 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34000
34001 h = shost_priv(SChost);
34002
34003 - if (h) {
34004 - if (h->info_kbuf == NULL)
34005 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34006 - return h->info_kbuf;
34007 - h->info_kbuf[0] = '\0';
34008 + if (!h)
34009 + return NULL;
34010
34011 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34012 - h->info_kbuf[size-1] = '\0';
34013 - }
34014 + if (h->info_kbuf == NULL)
34015 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34016 + return h->info_kbuf;
34017 + h->info_kbuf[0] = '\0';
34018 +
34019 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34020 + h->info_kbuf[size-1] = '\0';
34021
34022 return h->info_kbuf;
34023 }
34024 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34025 index 6d115c7..58ff7fd 100644
34026 --- a/drivers/message/i2o/i2o_proc.c
34027 +++ b/drivers/message/i2o/i2o_proc.c
34028 @@ -255,13 +255,6 @@ static char *scsi_devices[] = {
34029 "Array Controller Device"
34030 };
34031
34032 -static char *chtostr(u8 * chars, int n)
34033 -{
34034 - char tmp[256];
34035 - tmp[0] = 0;
34036 - return strncat(tmp, (char *)chars, n);
34037 -}
34038 -
34039 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34040 char *group)
34041 {
34042 @@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34043
34044 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34045 seq_printf(seq, "%-#8x", ddm_table.module_id);
34046 - seq_printf(seq, "%-29s",
34047 - chtostr(ddm_table.module_name_version, 28));
34048 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34049 seq_printf(seq, "%9d ", ddm_table.data_size);
34050 seq_printf(seq, "%8d", ddm_table.code_size);
34051
34052 @@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34053
34054 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34055 seq_printf(seq, "%-#8x", dst->module_id);
34056 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
34057 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
34058 + seq_printf(seq, "%-.28s", dst->module_name_version);
34059 + seq_printf(seq, "%-.8s", dst->date);
34060 seq_printf(seq, "%8d ", dst->module_size);
34061 seq_printf(seq, "%8d ", dst->mpb_size);
34062 seq_printf(seq, "0x%04x", dst->module_flags);
34063 @@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34064 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34065 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34066 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34067 - seq_printf(seq, "Vendor info : %s\n",
34068 - chtostr((u8 *) (work32 + 2), 16));
34069 - seq_printf(seq, "Product info : %s\n",
34070 - chtostr((u8 *) (work32 + 6), 16));
34071 - seq_printf(seq, "Description : %s\n",
34072 - chtostr((u8 *) (work32 + 10), 16));
34073 - seq_printf(seq, "Product rev. : %s\n",
34074 - chtostr((u8 *) (work32 + 14), 8));
34075 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34076 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34077 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34078 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34079
34080 seq_printf(seq, "Serial number : ");
34081 print_serial_number(seq, (u8 *) (work32 + 16),
34082 @@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34083 }
34084
34085 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34086 - seq_printf(seq, "Module name : %s\n",
34087 - chtostr(result.module_name, 24));
34088 - seq_printf(seq, "Module revision : %s\n",
34089 - chtostr(result.module_rev, 8));
34090 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
34091 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34092
34093 seq_printf(seq, "Serial number : ");
34094 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34095 @@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34096 return 0;
34097 }
34098
34099 - seq_printf(seq, "Device name : %s\n",
34100 - chtostr(result.device_name, 64));
34101 - seq_printf(seq, "Service name : %s\n",
34102 - chtostr(result.service_name, 64));
34103 - seq_printf(seq, "Physical name : %s\n",
34104 - chtostr(result.physical_location, 64));
34105 - seq_printf(seq, "Instance number : %s\n",
34106 - chtostr(result.instance_number, 4));
34107 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
34108 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
34109 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34110 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34111
34112 return 0;
34113 }
34114 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34115 index a8c08f3..155fe3d 100644
34116 --- a/drivers/message/i2o/iop.c
34117 +++ b/drivers/message/i2o/iop.c
34118 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34119
34120 spin_lock_irqsave(&c->context_list_lock, flags);
34121
34122 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34123 - atomic_inc(&c->context_list_counter);
34124 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34125 + atomic_inc_unchecked(&c->context_list_counter);
34126
34127 - entry->context = atomic_read(&c->context_list_counter);
34128 + entry->context = atomic_read_unchecked(&c->context_list_counter);
34129
34130 list_add(&entry->list, &c->context_list);
34131
34132 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34133
34134 #if BITS_PER_LONG == 64
34135 spin_lock_init(&c->context_list_lock);
34136 - atomic_set(&c->context_list_counter, 0);
34137 + atomic_set_unchecked(&c->context_list_counter, 0);
34138 INIT_LIST_HEAD(&c->context_list);
34139 #endif
34140
34141 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34142 index 7ce65f4..e66e9bc 100644
34143 --- a/drivers/mfd/abx500-core.c
34144 +++ b/drivers/mfd/abx500-core.c
34145 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34146
34147 struct abx500_device_entry {
34148 struct list_head list;
34149 - struct abx500_ops ops;
34150 + abx500_ops_no_const ops;
34151 struct device *dev;
34152 };
34153
34154 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34155 index a9223ed..4127b13 100644
34156 --- a/drivers/mfd/janz-cmodio.c
34157 +++ b/drivers/mfd/janz-cmodio.c
34158 @@ -13,6 +13,7 @@
34159
34160 #include <linux/kernel.h>
34161 #include <linux/module.h>
34162 +#include <linux/slab.h>
34163 #include <linux/init.h>
34164 #include <linux/pci.h>
34165 #include <linux/interrupt.h>
34166 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34167 index a981e2a..5ca0c8b 100644
34168 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
34169 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34170 @@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34171 * the lid is closed. This leads to interrupts as soon as a little move
34172 * is done.
34173 */
34174 - atomic_inc(&lis3->count);
34175 + atomic_inc_unchecked(&lis3->count);
34176
34177 wake_up_interruptible(&lis3->misc_wait);
34178 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34179 @@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34180 if (lis3->pm_dev)
34181 pm_runtime_get_sync(lis3->pm_dev);
34182
34183 - atomic_set(&lis3->count, 0);
34184 + atomic_set_unchecked(&lis3->count, 0);
34185 return 0;
34186 }
34187
34188 @@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34189 add_wait_queue(&lis3->misc_wait, &wait);
34190 while (true) {
34191 set_current_state(TASK_INTERRUPTIBLE);
34192 - data = atomic_xchg(&lis3->count, 0);
34193 + data = atomic_xchg_unchecked(&lis3->count, 0);
34194 if (data)
34195 break;
34196
34197 @@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34198 struct lis3lv02d, miscdev);
34199
34200 poll_wait(file, &lis3->misc_wait, wait);
34201 - if (atomic_read(&lis3->count))
34202 + if (atomic_read_unchecked(&lis3->count))
34203 return POLLIN | POLLRDNORM;
34204 return 0;
34205 }
34206 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34207 index 2b1482a..5d33616 100644
34208 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
34209 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34210 @@ -266,7 +266,7 @@ struct lis3lv02d {
34211 struct input_polled_dev *idev; /* input device */
34212 struct platform_device *pdev; /* platform device */
34213 struct regulator_bulk_data regulators[2];
34214 - atomic_t count; /* interrupt count after last read */
34215 + atomic_unchecked_t count; /* interrupt count after last read */
34216 union axis_conversion ac; /* hw -> logical axis */
34217 int mapped_btns[3];
34218
34219 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34220 index 2f30bad..c4c13d0 100644
34221 --- a/drivers/misc/sgi-gru/gruhandles.c
34222 +++ b/drivers/misc/sgi-gru/gruhandles.c
34223 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34224 unsigned long nsec;
34225
34226 nsec = CLKS2NSEC(clks);
34227 - atomic_long_inc(&mcs_op_statistics[op].count);
34228 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
34229 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34230 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34231 if (mcs_op_statistics[op].max < nsec)
34232 mcs_op_statistics[op].max = nsec;
34233 }
34234 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34235 index 950dbe9..eeef0f8 100644
34236 --- a/drivers/misc/sgi-gru/gruprocfs.c
34237 +++ b/drivers/misc/sgi-gru/gruprocfs.c
34238 @@ -32,9 +32,9 @@
34239
34240 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34241
34242 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34243 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34244 {
34245 - unsigned long val = atomic_long_read(v);
34246 + unsigned long val = atomic_long_read_unchecked(v);
34247
34248 seq_printf(s, "%16lu %s\n", val, id);
34249 }
34250 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34251
34252 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34253 for (op = 0; op < mcsop_last; op++) {
34254 - count = atomic_long_read(&mcs_op_statistics[op].count);
34255 - total = atomic_long_read(&mcs_op_statistics[op].total);
34256 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34257 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34258 max = mcs_op_statistics[op].max;
34259 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34260 count ? total / count : 0, max);
34261 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34262 index 5c3ce24..4915ccb 100644
34263 --- a/drivers/misc/sgi-gru/grutables.h
34264 +++ b/drivers/misc/sgi-gru/grutables.h
34265 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34266 * GRU statistics.
34267 */
34268 struct gru_stats_s {
34269 - atomic_long_t vdata_alloc;
34270 - atomic_long_t vdata_free;
34271 - atomic_long_t gts_alloc;
34272 - atomic_long_t gts_free;
34273 - atomic_long_t gms_alloc;
34274 - atomic_long_t gms_free;
34275 - atomic_long_t gts_double_allocate;
34276 - atomic_long_t assign_context;
34277 - atomic_long_t assign_context_failed;
34278 - atomic_long_t free_context;
34279 - atomic_long_t load_user_context;
34280 - atomic_long_t load_kernel_context;
34281 - atomic_long_t lock_kernel_context;
34282 - atomic_long_t unlock_kernel_context;
34283 - atomic_long_t steal_user_context;
34284 - atomic_long_t steal_kernel_context;
34285 - atomic_long_t steal_context_failed;
34286 - atomic_long_t nopfn;
34287 - atomic_long_t asid_new;
34288 - atomic_long_t asid_next;
34289 - atomic_long_t asid_wrap;
34290 - atomic_long_t asid_reuse;
34291 - atomic_long_t intr;
34292 - atomic_long_t intr_cbr;
34293 - atomic_long_t intr_tfh;
34294 - atomic_long_t intr_spurious;
34295 - atomic_long_t intr_mm_lock_failed;
34296 - atomic_long_t call_os;
34297 - atomic_long_t call_os_wait_queue;
34298 - atomic_long_t user_flush_tlb;
34299 - atomic_long_t user_unload_context;
34300 - atomic_long_t user_exception;
34301 - atomic_long_t set_context_option;
34302 - atomic_long_t check_context_retarget_intr;
34303 - atomic_long_t check_context_unload;
34304 - atomic_long_t tlb_dropin;
34305 - atomic_long_t tlb_preload_page;
34306 - atomic_long_t tlb_dropin_fail_no_asid;
34307 - atomic_long_t tlb_dropin_fail_upm;
34308 - atomic_long_t tlb_dropin_fail_invalid;
34309 - atomic_long_t tlb_dropin_fail_range_active;
34310 - atomic_long_t tlb_dropin_fail_idle;
34311 - atomic_long_t tlb_dropin_fail_fmm;
34312 - atomic_long_t tlb_dropin_fail_no_exception;
34313 - atomic_long_t tfh_stale_on_fault;
34314 - atomic_long_t mmu_invalidate_range;
34315 - atomic_long_t mmu_invalidate_page;
34316 - atomic_long_t flush_tlb;
34317 - atomic_long_t flush_tlb_gru;
34318 - atomic_long_t flush_tlb_gru_tgh;
34319 - atomic_long_t flush_tlb_gru_zero_asid;
34320 + atomic_long_unchecked_t vdata_alloc;
34321 + atomic_long_unchecked_t vdata_free;
34322 + atomic_long_unchecked_t gts_alloc;
34323 + atomic_long_unchecked_t gts_free;
34324 + atomic_long_unchecked_t gms_alloc;
34325 + atomic_long_unchecked_t gms_free;
34326 + atomic_long_unchecked_t gts_double_allocate;
34327 + atomic_long_unchecked_t assign_context;
34328 + atomic_long_unchecked_t assign_context_failed;
34329 + atomic_long_unchecked_t free_context;
34330 + atomic_long_unchecked_t load_user_context;
34331 + atomic_long_unchecked_t load_kernel_context;
34332 + atomic_long_unchecked_t lock_kernel_context;
34333 + atomic_long_unchecked_t unlock_kernel_context;
34334 + atomic_long_unchecked_t steal_user_context;
34335 + atomic_long_unchecked_t steal_kernel_context;
34336 + atomic_long_unchecked_t steal_context_failed;
34337 + atomic_long_unchecked_t nopfn;
34338 + atomic_long_unchecked_t asid_new;
34339 + atomic_long_unchecked_t asid_next;
34340 + atomic_long_unchecked_t asid_wrap;
34341 + atomic_long_unchecked_t asid_reuse;
34342 + atomic_long_unchecked_t intr;
34343 + atomic_long_unchecked_t intr_cbr;
34344 + atomic_long_unchecked_t intr_tfh;
34345 + atomic_long_unchecked_t intr_spurious;
34346 + atomic_long_unchecked_t intr_mm_lock_failed;
34347 + atomic_long_unchecked_t call_os;
34348 + atomic_long_unchecked_t call_os_wait_queue;
34349 + atomic_long_unchecked_t user_flush_tlb;
34350 + atomic_long_unchecked_t user_unload_context;
34351 + atomic_long_unchecked_t user_exception;
34352 + atomic_long_unchecked_t set_context_option;
34353 + atomic_long_unchecked_t check_context_retarget_intr;
34354 + atomic_long_unchecked_t check_context_unload;
34355 + atomic_long_unchecked_t tlb_dropin;
34356 + atomic_long_unchecked_t tlb_preload_page;
34357 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34358 + atomic_long_unchecked_t tlb_dropin_fail_upm;
34359 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
34360 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
34361 + atomic_long_unchecked_t tlb_dropin_fail_idle;
34362 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
34363 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34364 + atomic_long_unchecked_t tfh_stale_on_fault;
34365 + atomic_long_unchecked_t mmu_invalidate_range;
34366 + atomic_long_unchecked_t mmu_invalidate_page;
34367 + atomic_long_unchecked_t flush_tlb;
34368 + atomic_long_unchecked_t flush_tlb_gru;
34369 + atomic_long_unchecked_t flush_tlb_gru_tgh;
34370 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34371
34372 - atomic_long_t copy_gpa;
34373 - atomic_long_t read_gpa;
34374 + atomic_long_unchecked_t copy_gpa;
34375 + atomic_long_unchecked_t read_gpa;
34376
34377 - atomic_long_t mesq_receive;
34378 - atomic_long_t mesq_receive_none;
34379 - atomic_long_t mesq_send;
34380 - atomic_long_t mesq_send_failed;
34381 - atomic_long_t mesq_noop;
34382 - atomic_long_t mesq_send_unexpected_error;
34383 - atomic_long_t mesq_send_lb_overflow;
34384 - atomic_long_t mesq_send_qlimit_reached;
34385 - atomic_long_t mesq_send_amo_nacked;
34386 - atomic_long_t mesq_send_put_nacked;
34387 - atomic_long_t mesq_page_overflow;
34388 - atomic_long_t mesq_qf_locked;
34389 - atomic_long_t mesq_qf_noop_not_full;
34390 - atomic_long_t mesq_qf_switch_head_failed;
34391 - atomic_long_t mesq_qf_unexpected_error;
34392 - atomic_long_t mesq_noop_unexpected_error;
34393 - atomic_long_t mesq_noop_lb_overflow;
34394 - atomic_long_t mesq_noop_qlimit_reached;
34395 - atomic_long_t mesq_noop_amo_nacked;
34396 - atomic_long_t mesq_noop_put_nacked;
34397 - atomic_long_t mesq_noop_page_overflow;
34398 + atomic_long_unchecked_t mesq_receive;
34399 + atomic_long_unchecked_t mesq_receive_none;
34400 + atomic_long_unchecked_t mesq_send;
34401 + atomic_long_unchecked_t mesq_send_failed;
34402 + atomic_long_unchecked_t mesq_noop;
34403 + atomic_long_unchecked_t mesq_send_unexpected_error;
34404 + atomic_long_unchecked_t mesq_send_lb_overflow;
34405 + atomic_long_unchecked_t mesq_send_qlimit_reached;
34406 + atomic_long_unchecked_t mesq_send_amo_nacked;
34407 + atomic_long_unchecked_t mesq_send_put_nacked;
34408 + atomic_long_unchecked_t mesq_page_overflow;
34409 + atomic_long_unchecked_t mesq_qf_locked;
34410 + atomic_long_unchecked_t mesq_qf_noop_not_full;
34411 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
34412 + atomic_long_unchecked_t mesq_qf_unexpected_error;
34413 + atomic_long_unchecked_t mesq_noop_unexpected_error;
34414 + atomic_long_unchecked_t mesq_noop_lb_overflow;
34415 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
34416 + atomic_long_unchecked_t mesq_noop_amo_nacked;
34417 + atomic_long_unchecked_t mesq_noop_put_nacked;
34418 + atomic_long_unchecked_t mesq_noop_page_overflow;
34419
34420 };
34421
34422 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34423 tghop_invalidate, mcsop_last};
34424
34425 struct mcs_op_statistic {
34426 - atomic_long_t count;
34427 - atomic_long_t total;
34428 + atomic_long_unchecked_t count;
34429 + atomic_long_unchecked_t total;
34430 unsigned long max;
34431 };
34432
34433 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34434
34435 #define STAT(id) do { \
34436 if (gru_options & OPT_STATS) \
34437 - atomic_long_inc(&gru_stats.id); \
34438 + atomic_long_inc_unchecked(&gru_stats.id); \
34439 } while (0)
34440
34441 #ifdef CONFIG_SGI_GRU_DEBUG
34442 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34443 index c862cd4..0d176fe 100644
34444 --- a/drivers/misc/sgi-xp/xp.h
34445 +++ b/drivers/misc/sgi-xp/xp.h
34446 @@ -288,7 +288,7 @@ struct xpc_interface {
34447 xpc_notify_func, void *);
34448 void (*received) (short, int, void *);
34449 enum xp_retval (*partid_to_nasids) (short, void *);
34450 -};
34451 +} __no_const;
34452
34453 extern struct xpc_interface xpc_interface;
34454
34455 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34456 index b94d5f7..7f494c5 100644
34457 --- a/drivers/misc/sgi-xp/xpc.h
34458 +++ b/drivers/misc/sgi-xp/xpc.h
34459 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
34460 void (*received_payload) (struct xpc_channel *, void *);
34461 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34462 };
34463 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34464
34465 /* struct xpc_partition act_state values (for XPC HB) */
34466
34467 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34468 /* found in xpc_main.c */
34469 extern struct device *xpc_part;
34470 extern struct device *xpc_chan;
34471 -extern struct xpc_arch_operations xpc_arch_ops;
34472 +extern xpc_arch_operations_no_const xpc_arch_ops;
34473 extern int xpc_disengage_timelimit;
34474 extern int xpc_disengage_timedout;
34475 extern int xpc_activate_IRQ_rcvd;
34476 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34477 index 8d082b4..aa749ae 100644
34478 --- a/drivers/misc/sgi-xp/xpc_main.c
34479 +++ b/drivers/misc/sgi-xp/xpc_main.c
34480 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34481 .notifier_call = xpc_system_die,
34482 };
34483
34484 -struct xpc_arch_operations xpc_arch_ops;
34485 +xpc_arch_operations_no_const xpc_arch_ops;
34486
34487 /*
34488 * Timer function to enforce the timelimit on the partition disengage.
34489 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34490 index 69ef0be..f3ef91e 100644
34491 --- a/drivers/mmc/host/sdhci-pci.c
34492 +++ b/drivers/mmc/host/sdhci-pci.c
34493 @@ -652,7 +652,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34494 .probe = via_probe,
34495 };
34496
34497 -static const struct pci_device_id pci_ids[] __devinitdata = {
34498 +static const struct pci_device_id pci_ids[] __devinitconst = {
34499 {
34500 .vendor = PCI_VENDOR_ID_RICOH,
34501 .device = PCI_DEVICE_ID_RICOH_R5C822,
34502 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34503 index a4eb8b5..8c0628f 100644
34504 --- a/drivers/mtd/devices/doc2000.c
34505 +++ b/drivers/mtd/devices/doc2000.c
34506 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34507
34508 /* The ECC will not be calculated correctly if less than 512 is written */
34509 /* DBB-
34510 - if (len != 0x200 && eccbuf)
34511 + if (len != 0x200)
34512 printk(KERN_WARNING
34513 "ECC needs a full sector write (adr: %lx size %lx)\n",
34514 (long) to, (long) len);
34515 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34516 index a9e57d6..c6d8731 100644
34517 --- a/drivers/mtd/nand/denali.c
34518 +++ b/drivers/mtd/nand/denali.c
34519 @@ -26,6 +26,7 @@
34520 #include <linux/pci.h>
34521 #include <linux/mtd/mtd.h>
34522 #include <linux/module.h>
34523 +#include <linux/slab.h>
34524
34525 #include "denali.h"
34526
34527 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34528 index 51b9d6a..52af9a7 100644
34529 --- a/drivers/mtd/nftlmount.c
34530 +++ b/drivers/mtd/nftlmount.c
34531 @@ -24,6 +24,7 @@
34532 #include <asm/errno.h>
34533 #include <linux/delay.h>
34534 #include <linux/slab.h>
34535 +#include <linux/sched.h>
34536 #include <linux/mtd/mtd.h>
34537 #include <linux/mtd/nand.h>
34538 #include <linux/mtd/nftl.h>
34539 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34540 index 6762dc4..9956862 100644
34541 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
34542 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34543 @@ -2859,7 +2859,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34544 */
34545
34546 #define ATL2_PARAM(X, desc) \
34547 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34548 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34549 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34550 MODULE_PARM_DESC(X, desc);
34551 #else
34552 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34553 index 61a7670..7da6e34 100644
34554 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34555 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34556 @@ -483,7 +483,7 @@ struct bnx2x_rx_mode_obj {
34557
34558 int (*wait_comp)(struct bnx2x *bp,
34559 struct bnx2x_rx_mode_ramrod_params *p);
34560 -};
34561 +} __no_const;
34562
34563 /********************** Set multicast group ***********************************/
34564
34565 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34566 index 93865f8..5448741 100644
34567 --- a/drivers/net/ethernet/broadcom/tg3.h
34568 +++ b/drivers/net/ethernet/broadcom/tg3.h
34569 @@ -140,6 +140,7 @@
34570 #define CHIPREV_ID_5750_A0 0x4000
34571 #define CHIPREV_ID_5750_A1 0x4001
34572 #define CHIPREV_ID_5750_A3 0x4003
34573 +#define CHIPREV_ID_5750_C1 0x4201
34574 #define CHIPREV_ID_5750_C2 0x4202
34575 #define CHIPREV_ID_5752_A0_HW 0x5000
34576 #define CHIPREV_ID_5752_A0 0x6000
34577 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34578 index c4e8643..0979484 100644
34579 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34580 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34581 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34582 */
34583 struct l2t_skb_cb {
34584 arp_failure_handler_func arp_failure_handler;
34585 -};
34586 +} __no_const;
34587
34588 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34589
34590 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34591 index 18b106c..2b38d36 100644
34592 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
34593 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34594 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34595 for (i=0; i<ETH_ALEN; i++) {
34596 tmp.addr[i] = dev->dev_addr[i];
34597 }
34598 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34599 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34600 break;
34601
34602 case DE4X5_SET_HWADDR: /* Set the hardware address */
34603 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34604 spin_lock_irqsave(&lp->lock, flags);
34605 memcpy(&statbuf, &lp->pktStats, ioc->len);
34606 spin_unlock_irqrestore(&lp->lock, flags);
34607 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
34608 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34609 return -EFAULT;
34610 break;
34611 }
34612 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34613 index ed7d1dc..d426748 100644
34614 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
34615 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34616 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34617 {NULL}};
34618
34619
34620 -static const char *block_name[] __devinitdata = {
34621 +static const char *block_name[] __devinitconst = {
34622 "21140 non-MII",
34623 "21140 MII PHY",
34624 "21142 Serial PHY",
34625 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34626 index 2ac6fff..2d127d0 100644
34627 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34628 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34629 @@ -236,7 +236,7 @@ struct pci_id_info {
34630 int drv_flags; /* Driver use, intended as capability flags. */
34631 };
34632
34633 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34634 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34635 { /* Sometime a Level-One switch card. */
34636 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34637 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34638 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34639 index d783f4f..97fa1b0 100644
34640 --- a/drivers/net/ethernet/dlink/sundance.c
34641 +++ b/drivers/net/ethernet/dlink/sundance.c
34642 @@ -218,7 +218,7 @@ enum {
34643 struct pci_id_info {
34644 const char *name;
34645 };
34646 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34647 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34648 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34649 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34650 {"D-Link DFE-580TX 4 port Server Adapter"},
34651 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34652 index 1bbf6b3..430dcd0 100644
34653 --- a/drivers/net/ethernet/emulex/benet/be_main.c
34654 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
34655 @@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34656
34657 if (wrapped)
34658 newacc += 65536;
34659 - ACCESS_ONCE(*acc) = newacc;
34660 + ACCESS_ONCE_RW(*acc) = newacc;
34661 }
34662
34663 void be_parse_stats(struct be_adapter *adapter)
34664 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34665 index 16b0704..d2c07d7 100644
34666 --- a/drivers/net/ethernet/faraday/ftgmac100.c
34667 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
34668 @@ -31,6 +31,8 @@
34669 #include <linux/netdevice.h>
34670 #include <linux/phy.h>
34671 #include <linux/platform_device.h>
34672 +#include <linux/interrupt.h>
34673 +#include <linux/irqreturn.h>
34674 #include <net/ip.h>
34675
34676 #include "ftgmac100.h"
34677 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34678 index 829b109..4ae5f6a 100644
34679 --- a/drivers/net/ethernet/faraday/ftmac100.c
34680 +++ b/drivers/net/ethernet/faraday/ftmac100.c
34681 @@ -31,6 +31,8 @@
34682 #include <linux/module.h>
34683 #include <linux/netdevice.h>
34684 #include <linux/platform_device.h>
34685 +#include <linux/interrupt.h>
34686 +#include <linux/irqreturn.h>
34687
34688 #include "ftmac100.h"
34689
34690 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34691 index 1637b98..c42f87b 100644
34692 --- a/drivers/net/ethernet/fealnx.c
34693 +++ b/drivers/net/ethernet/fealnx.c
34694 @@ -150,7 +150,7 @@ struct chip_info {
34695 int flags;
34696 };
34697
34698 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
34699 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
34700 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34701 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
34702 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34703 diff --git a/drivers/net/ethernet/intel/e1000e/e1000.h b/drivers/net/ethernet/intel/e1000e/e1000.h
34704 index b83897f..b2d970f 100644
34705 --- a/drivers/net/ethernet/intel/e1000e/e1000.h
34706 +++ b/drivers/net/ethernet/intel/e1000e/e1000.h
34707 @@ -181,7 +181,7 @@ struct e1000_info;
34708 #define E1000_TXDCTL_DMA_BURST_ENABLE \
34709 (E1000_TXDCTL_GRAN | /* set descriptor granularity */ \
34710 E1000_TXDCTL_COUNT_DESC | \
34711 - (5 << 16) | /* wthresh must be +1 more than desired */\
34712 + (1 << 16) | /* wthresh must be +1 more than desired */\
34713 (1 << 8) | /* hthresh */ \
34714 0x1f) /* pthresh */
34715
34716 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34717 index f82ecf5..7d59ecb 100644
34718 --- a/drivers/net/ethernet/intel/e1000e/hw.h
34719 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
34720 @@ -784,6 +784,7 @@ struct e1000_mac_operations {
34721 void (*config_collision_dist)(struct e1000_hw *);
34722 s32 (*read_mac_addr)(struct e1000_hw *);
34723 };
34724 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34725
34726 /*
34727 * When to use various PHY register access functions:
34728 @@ -824,6 +825,7 @@ struct e1000_phy_operations {
34729 void (*power_up)(struct e1000_hw *);
34730 void (*power_down)(struct e1000_hw *);
34731 };
34732 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34733
34734 /* Function pointers for the NVM. */
34735 struct e1000_nvm_operations {
34736 @@ -836,9 +838,10 @@ struct e1000_nvm_operations {
34737 s32 (*validate)(struct e1000_hw *);
34738 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34739 };
34740 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34741
34742 struct e1000_mac_info {
34743 - struct e1000_mac_operations ops;
34744 + e1000_mac_operations_no_const ops;
34745 u8 addr[ETH_ALEN];
34746 u8 perm_addr[ETH_ALEN];
34747
34748 @@ -879,7 +882,7 @@ struct e1000_mac_info {
34749 };
34750
34751 struct e1000_phy_info {
34752 - struct e1000_phy_operations ops;
34753 + e1000_phy_operations_no_const ops;
34754
34755 enum e1000_phy_type type;
34756
34757 @@ -913,7 +916,7 @@ struct e1000_phy_info {
34758 };
34759
34760 struct e1000_nvm_info {
34761 - struct e1000_nvm_operations ops;
34762 + e1000_nvm_operations_no_const ops;
34763
34764 enum e1000_nvm_type type;
34765 enum e1000_nvm_override override;
34766 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
34767 index f67cbd3..cef9e3d 100644
34768 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
34769 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
34770 @@ -314,6 +314,7 @@ struct e1000_mac_operations {
34771 s32 (*read_mac_addr)(struct e1000_hw *);
34772 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
34773 };
34774 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34775
34776 struct e1000_phy_operations {
34777 s32 (*acquire)(struct e1000_hw *);
34778 @@ -330,6 +331,7 @@ struct e1000_phy_operations {
34779 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
34780 s32 (*write_reg)(struct e1000_hw *, u32, u16);
34781 };
34782 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34783
34784 struct e1000_nvm_operations {
34785 s32 (*acquire)(struct e1000_hw *);
34786 @@ -339,6 +341,7 @@ struct e1000_nvm_operations {
34787 s32 (*update)(struct e1000_hw *);
34788 s32 (*validate)(struct e1000_hw *);
34789 };
34790 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34791
34792 struct e1000_info {
34793 s32 (*get_invariants)(struct e1000_hw *);
34794 @@ -350,7 +353,7 @@ struct e1000_info {
34795 extern const struct e1000_info e1000_82575_info;
34796
34797 struct e1000_mac_info {
34798 - struct e1000_mac_operations ops;
34799 + e1000_mac_operations_no_const ops;
34800
34801 u8 addr[6];
34802 u8 perm_addr[6];
34803 @@ -388,7 +391,7 @@ struct e1000_mac_info {
34804 };
34805
34806 struct e1000_phy_info {
34807 - struct e1000_phy_operations ops;
34808 + e1000_phy_operations_no_const ops;
34809
34810 enum e1000_phy_type type;
34811
34812 @@ -423,7 +426,7 @@ struct e1000_phy_info {
34813 };
34814
34815 struct e1000_nvm_info {
34816 - struct e1000_nvm_operations ops;
34817 + e1000_nvm_operations_no_const ops;
34818 enum e1000_nvm_type type;
34819 enum e1000_nvm_override override;
34820
34821 @@ -468,6 +471,7 @@ struct e1000_mbx_operations {
34822 s32 (*check_for_ack)(struct e1000_hw *, u16);
34823 s32 (*check_for_rst)(struct e1000_hw *, u16);
34824 };
34825 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34826
34827 struct e1000_mbx_stats {
34828 u32 msgs_tx;
34829 @@ -479,7 +483,7 @@ struct e1000_mbx_stats {
34830 };
34831
34832 struct e1000_mbx_info {
34833 - struct e1000_mbx_operations ops;
34834 + e1000_mbx_operations_no_const ops;
34835 struct e1000_mbx_stats stats;
34836 u32 timeout;
34837 u32 usec_delay;
34838 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
34839 index 57db3c6..aa825fc 100644
34840 --- a/drivers/net/ethernet/intel/igbvf/vf.h
34841 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
34842 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
34843 s32 (*read_mac_addr)(struct e1000_hw *);
34844 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
34845 };
34846 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34847
34848 struct e1000_mac_info {
34849 - struct e1000_mac_operations ops;
34850 + e1000_mac_operations_no_const ops;
34851 u8 addr[6];
34852 u8 perm_addr[6];
34853
34854 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
34855 s32 (*check_for_ack)(struct e1000_hw *);
34856 s32 (*check_for_rst)(struct e1000_hw *);
34857 };
34858 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34859
34860 struct e1000_mbx_stats {
34861 u32 msgs_tx;
34862 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
34863 };
34864
34865 struct e1000_mbx_info {
34866 - struct e1000_mbx_operations ops;
34867 + e1000_mbx_operations_no_const ops;
34868 struct e1000_mbx_stats stats;
34869 u32 timeout;
34870 u32 usec_delay;
34871 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34872 index 8636e83..ab9bbc3 100644
34873 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34874 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34875 @@ -2710,6 +2710,7 @@ struct ixgbe_eeprom_operations {
34876 s32 (*update_checksum)(struct ixgbe_hw *);
34877 u16 (*calc_checksum)(struct ixgbe_hw *);
34878 };
34879 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
34880
34881 struct ixgbe_mac_operations {
34882 s32 (*init_hw)(struct ixgbe_hw *);
34883 @@ -2773,6 +2774,7 @@ struct ixgbe_mac_operations {
34884 /* Manageability interface */
34885 s32 (*set_fw_drv_ver)(struct ixgbe_hw *, u8, u8, u8, u8);
34886 };
34887 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34888
34889 struct ixgbe_phy_operations {
34890 s32 (*identify)(struct ixgbe_hw *);
34891 @@ -2792,9 +2794,10 @@ struct ixgbe_phy_operations {
34892 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
34893 s32 (*check_overtemp)(struct ixgbe_hw *);
34894 };
34895 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
34896
34897 struct ixgbe_eeprom_info {
34898 - struct ixgbe_eeprom_operations ops;
34899 + ixgbe_eeprom_operations_no_const ops;
34900 enum ixgbe_eeprom_type type;
34901 u32 semaphore_delay;
34902 u16 word_size;
34903 @@ -2804,7 +2807,7 @@ struct ixgbe_eeprom_info {
34904
34905 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
34906 struct ixgbe_mac_info {
34907 - struct ixgbe_mac_operations ops;
34908 + ixgbe_mac_operations_no_const ops;
34909 enum ixgbe_mac_type type;
34910 u8 addr[ETH_ALEN];
34911 u8 perm_addr[ETH_ALEN];
34912 @@ -2832,7 +2835,7 @@ struct ixgbe_mac_info {
34913 };
34914
34915 struct ixgbe_phy_info {
34916 - struct ixgbe_phy_operations ops;
34917 + ixgbe_phy_operations_no_const ops;
34918 struct mdio_if_info mdio;
34919 enum ixgbe_phy_type type;
34920 u32 id;
34921 @@ -2860,6 +2863,7 @@ struct ixgbe_mbx_operations {
34922 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
34923 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
34924 };
34925 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34926
34927 struct ixgbe_mbx_stats {
34928 u32 msgs_tx;
34929 @@ -2871,7 +2875,7 @@ struct ixgbe_mbx_stats {
34930 };
34931
34932 struct ixgbe_mbx_info {
34933 - struct ixgbe_mbx_operations ops;
34934 + ixgbe_mbx_operations_no_const ops;
34935 struct ixgbe_mbx_stats stats;
34936 u32 timeout;
34937 u32 usec_delay;
34938 diff --git a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
34939 index 307611a..d8e4562 100644
34940 --- a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
34941 +++ b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
34942 @@ -969,8 +969,6 @@ static irqreturn_t ixgbevf_msix_clean_tx(int irq, void *data)
34943 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
34944 for (i = 0; i < q_vector->txr_count; i++) {
34945 tx_ring = &(adapter->tx_ring[r_idx]);
34946 - tx_ring->total_bytes = 0;
34947 - tx_ring->total_packets = 0;
34948 ixgbevf_clean_tx_irq(adapter, tx_ring);
34949 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
34950 r_idx + 1);
34951 @@ -994,16 +992,6 @@ static irqreturn_t ixgbevf_msix_clean_rx(int irq, void *data)
34952 struct ixgbe_hw *hw = &adapter->hw;
34953 struct ixgbevf_ring *rx_ring;
34954 int r_idx;
34955 - int i;
34956 -
34957 - r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
34958 - for (i = 0; i < q_vector->rxr_count; i++) {
34959 - rx_ring = &(adapter->rx_ring[r_idx]);
34960 - rx_ring->total_bytes = 0;
34961 - rx_ring->total_packets = 0;
34962 - r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
34963 - r_idx + 1);
34964 - }
34965
34966 if (!q_vector->rxr_count)
34967 return IRQ_HANDLED;
34968 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
34969 index 25c951d..cc7cf33 100644
34970 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
34971 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
34972 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
34973 s32 (*clear_vfta)(struct ixgbe_hw *);
34974 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
34975 };
34976 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34977
34978 enum ixgbe_mac_type {
34979 ixgbe_mac_unknown = 0,
34980 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
34981 };
34982
34983 struct ixgbe_mac_info {
34984 - struct ixgbe_mac_operations ops;
34985 + ixgbe_mac_operations_no_const ops;
34986 u8 addr[6];
34987 u8 perm_addr[6];
34988
34989 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
34990 s32 (*check_for_ack)(struct ixgbe_hw *);
34991 s32 (*check_for_rst)(struct ixgbe_hw *);
34992 };
34993 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34994
34995 struct ixgbe_mbx_stats {
34996 u32 msgs_tx;
34997 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
34998 };
34999
35000 struct ixgbe_mbx_info {
35001 - struct ixgbe_mbx_operations ops;
35002 + ixgbe_mbx_operations_no_const ops;
35003 struct ixgbe_mbx_stats stats;
35004 u32 timeout;
35005 u32 udelay;
35006 diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
35007 index 8bb05b4..074796f 100644
35008 --- a/drivers/net/ethernet/mellanox/mlx4/main.c
35009 +++ b/drivers/net/ethernet/mellanox/mlx4/main.c
35010 @@ -41,6 +41,7 @@
35011 #include <linux/slab.h>
35012 #include <linux/io-mapping.h>
35013 #include <linux/delay.h>
35014 +#include <linux/sched.h>
35015
35016 #include <linux/mlx4/device.h>
35017 #include <linux/mlx4/doorbell.h>
35018 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35019 index 5046a64..71ca936 100644
35020 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35021 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35022 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35023 void (*link_down)(struct __vxge_hw_device *devh);
35024 void (*crit_err)(struct __vxge_hw_device *devh,
35025 enum vxge_hw_event type, u64 ext_data);
35026 -};
35027 +} __no_const;
35028
35029 /*
35030 * struct __vxge_hw_blockpool_entry - Block private data structure
35031 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35032 index 4a518a3..936b334 100644
35033 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35034 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35035 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35036 struct vxge_hw_mempool_dma *dma_object,
35037 u32 index,
35038 u32 is_last);
35039 -};
35040 +} __no_const;
35041
35042 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35043 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35044 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35045 index 161e045..0bb5b86 100644
35046 --- a/drivers/net/ethernet/realtek/r8169.c
35047 +++ b/drivers/net/ethernet/realtek/r8169.c
35048 @@ -708,17 +708,17 @@ struct rtl8169_private {
35049 struct mdio_ops {
35050 void (*write)(void __iomem *, int, int);
35051 int (*read)(void __iomem *, int);
35052 - } mdio_ops;
35053 + } __no_const mdio_ops;
35054
35055 struct pll_power_ops {
35056 void (*down)(struct rtl8169_private *);
35057 void (*up)(struct rtl8169_private *);
35058 - } pll_power_ops;
35059 + } __no_const pll_power_ops;
35060
35061 struct jumbo_ops {
35062 void (*enable)(struct rtl8169_private *);
35063 void (*disable)(struct rtl8169_private *);
35064 - } jumbo_ops;
35065 + } __no_const jumbo_ops;
35066
35067 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35068 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35069 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35070 index a9deda8..5507c31 100644
35071 --- a/drivers/net/ethernet/sis/sis190.c
35072 +++ b/drivers/net/ethernet/sis/sis190.c
35073 @@ -1620,7 +1620,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35074 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35075 struct net_device *dev)
35076 {
35077 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35078 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35079 struct sis190_private *tp = netdev_priv(dev);
35080 struct pci_dev *isa_bridge;
35081 u8 reg, tmp8;
35082 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35083 index c07cfe9..81cbf7e 100644
35084 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35085 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35086 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35087
35088 writel(value, ioaddr + MMC_CNTRL);
35089
35090 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35091 - MMC_CNTRL, value);
35092 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35093 +// MMC_CNTRL, value);
35094 }
35095
35096 /* To mask all all interrupts.*/
35097 diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
35098 index 9bdfaba..3d8f8d4 100644
35099 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
35100 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
35101 @@ -1587,7 +1587,7 @@ static const struct file_operations stmmac_rings_status_fops = {
35102 .open = stmmac_sysfs_ring_open,
35103 .read = seq_read,
35104 .llseek = seq_lseek,
35105 - .release = seq_release,
35106 + .release = single_release,
35107 };
35108
35109 static int stmmac_sysfs_dma_cap_read(struct seq_file *seq, void *v)
35110 @@ -1659,7 +1659,7 @@ static const struct file_operations stmmac_dma_cap_fops = {
35111 .open = stmmac_sysfs_dma_cap_open,
35112 .read = seq_read,
35113 .llseek = seq_lseek,
35114 - .release = seq_release,
35115 + .release = single_release,
35116 };
35117
35118 static int stmmac_init_fs(struct net_device *dev)
35119 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35120 index c358245..8c1de63 100644
35121 --- a/drivers/net/hyperv/hyperv_net.h
35122 +++ b/drivers/net/hyperv/hyperv_net.h
35123 @@ -98,7 +98,7 @@ struct rndis_device {
35124
35125 enum rndis_device_state state;
35126 bool link_state;
35127 - atomic_t new_req_id;
35128 + atomic_unchecked_t new_req_id;
35129
35130 spinlock_t request_lock;
35131 struct list_head req_list;
35132 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35133 index d6be64b..5d97e3b 100644
35134 --- a/drivers/net/hyperv/rndis_filter.c
35135 +++ b/drivers/net/hyperv/rndis_filter.c
35136 @@ -97,7 +97,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35137 * template
35138 */
35139 set = &rndis_msg->msg.set_req;
35140 - set->req_id = atomic_inc_return(&dev->new_req_id);
35141 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35142
35143 /* Add to the request list */
35144 spin_lock_irqsave(&dev->request_lock, flags);
35145 @@ -648,7 +648,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35146
35147 /* Setup the rndis set */
35148 halt = &request->request_msg.msg.halt_req;
35149 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35150 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35151
35152 /* Ignore return since this msg is optional. */
35153 rndis_filter_send_request(dev, request);
35154 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35155 index 21d7151..8034208 100644
35156 --- a/drivers/net/ppp/ppp_generic.c
35157 +++ b/drivers/net/ppp/ppp_generic.c
35158 @@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35159 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35160 struct ppp_stats stats;
35161 struct ppp_comp_stats cstats;
35162 - char *vers;
35163
35164 switch (cmd) {
35165 case SIOCGPPPSTATS:
35166 @@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35167 break;
35168
35169 case SIOCGPPPVER:
35170 - vers = PPP_VERSION;
35171 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35172 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35173 break;
35174 err = 0;
35175 break;
35176 diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
35177 index b715e6b..6d2490f 100644
35178 --- a/drivers/net/tokenring/abyss.c
35179 +++ b/drivers/net/tokenring/abyss.c
35180 @@ -450,10 +450,12 @@ static struct pci_driver abyss_driver = {
35181
35182 static int __init abyss_init (void)
35183 {
35184 - abyss_netdev_ops = tms380tr_netdev_ops;
35185 + pax_open_kernel();
35186 + memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35187
35188 - abyss_netdev_ops.ndo_open = abyss_open;
35189 - abyss_netdev_ops.ndo_stop = abyss_close;
35190 + *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
35191 + *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
35192 + pax_close_kernel();
35193
35194 return pci_register_driver(&abyss_driver);
35195 }
35196 diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
35197 index 28adcdf..ae82f35 100644
35198 --- a/drivers/net/tokenring/madgemc.c
35199 +++ b/drivers/net/tokenring/madgemc.c
35200 @@ -742,9 +742,11 @@ static struct mca_driver madgemc_driver = {
35201
35202 static int __init madgemc_init (void)
35203 {
35204 - madgemc_netdev_ops = tms380tr_netdev_ops;
35205 - madgemc_netdev_ops.ndo_open = madgemc_open;
35206 - madgemc_netdev_ops.ndo_stop = madgemc_close;
35207 + pax_open_kernel();
35208 + memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35209 + *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
35210 + *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
35211 + pax_close_kernel();
35212
35213 return mca_register_driver (&madgemc_driver);
35214 }
35215 diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
35216 index 62d90e4..9d84237 100644
35217 --- a/drivers/net/tokenring/proteon.c
35218 +++ b/drivers/net/tokenring/proteon.c
35219 @@ -352,9 +352,11 @@ static int __init proteon_init(void)
35220 struct platform_device *pdev;
35221 int i, num = 0, err = 0;
35222
35223 - proteon_netdev_ops = tms380tr_netdev_ops;
35224 - proteon_netdev_ops.ndo_open = proteon_open;
35225 - proteon_netdev_ops.ndo_stop = tms380tr_close;
35226 + pax_open_kernel();
35227 + memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35228 + *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
35229 + *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
35230 + pax_close_kernel();
35231
35232 err = platform_driver_register(&proteon_driver);
35233 if (err)
35234 diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
35235 index ee11e93..c8f19c7 100644
35236 --- a/drivers/net/tokenring/skisa.c
35237 +++ b/drivers/net/tokenring/skisa.c
35238 @@ -362,9 +362,11 @@ static int __init sk_isa_init(void)
35239 struct platform_device *pdev;
35240 int i, num = 0, err = 0;
35241
35242 - sk_isa_netdev_ops = tms380tr_netdev_ops;
35243 - sk_isa_netdev_ops.ndo_open = sk_isa_open;
35244 - sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35245 + pax_open_kernel();
35246 + memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35247 + *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
35248 + *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35249 + pax_close_kernel();
35250
35251 err = platform_driver_register(&sk_isa_driver);
35252 if (err)
35253 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35254 index 2d2a688..35f2372 100644
35255 --- a/drivers/net/usb/hso.c
35256 +++ b/drivers/net/usb/hso.c
35257 @@ -71,7 +71,7 @@
35258 #include <asm/byteorder.h>
35259 #include <linux/serial_core.h>
35260 #include <linux/serial.h>
35261 -
35262 +#include <asm/local.h>
35263
35264 #define MOD_AUTHOR "Option Wireless"
35265 #define MOD_DESCRIPTION "USB High Speed Option driver"
35266 @@ -257,7 +257,7 @@ struct hso_serial {
35267
35268 /* from usb_serial_port */
35269 struct tty_struct *tty;
35270 - int open_count;
35271 + local_t open_count;
35272 spinlock_t serial_lock;
35273
35274 int (*write_data) (struct hso_serial *serial);
35275 @@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35276 struct urb *urb;
35277
35278 urb = serial->rx_urb[0];
35279 - if (serial->open_count > 0) {
35280 + if (local_read(&serial->open_count) > 0) {
35281 count = put_rxbuf_data(urb, serial);
35282 if (count == -1)
35283 return;
35284 @@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35285 DUMP1(urb->transfer_buffer, urb->actual_length);
35286
35287 /* Anyone listening? */
35288 - if (serial->open_count == 0)
35289 + if (local_read(&serial->open_count) == 0)
35290 return;
35291
35292 if (status == 0) {
35293 @@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35294 spin_unlock_irq(&serial->serial_lock);
35295
35296 /* check for port already opened, if not set the termios */
35297 - serial->open_count++;
35298 - if (serial->open_count == 1) {
35299 + if (local_inc_return(&serial->open_count) == 1) {
35300 serial->rx_state = RX_IDLE;
35301 /* Force default termio settings */
35302 _hso_serial_set_termios(tty, NULL);
35303 @@ -1324,7 +1323,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35304 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35305 if (result) {
35306 hso_stop_serial_device(serial->parent);
35307 - serial->open_count--;
35308 + local_dec(&serial->open_count);
35309 kref_put(&serial->parent->ref, hso_serial_ref_free);
35310 }
35311 } else {
35312 @@ -1361,10 +1360,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35313
35314 /* reset the rts and dtr */
35315 /* do the actual close */
35316 - serial->open_count--;
35317 + local_dec(&serial->open_count);
35318
35319 - if (serial->open_count <= 0) {
35320 - serial->open_count = 0;
35321 + if (local_read(&serial->open_count) <= 0) {
35322 + local_set(&serial->open_count, 0);
35323 spin_lock_irq(&serial->serial_lock);
35324 if (serial->tty == tty) {
35325 serial->tty->driver_data = NULL;
35326 @@ -1446,7 +1445,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35327
35328 /* the actual setup */
35329 spin_lock_irqsave(&serial->serial_lock, flags);
35330 - if (serial->open_count)
35331 + if (local_read(&serial->open_count))
35332 _hso_serial_set_termios(tty, old);
35333 else
35334 tty->termios = old;
35335 @@ -1905,7 +1904,7 @@ static void intr_callback(struct urb *urb)
35336 D1("Pending read interrupt on port %d\n", i);
35337 spin_lock(&serial->serial_lock);
35338 if (serial->rx_state == RX_IDLE &&
35339 - serial->open_count > 0) {
35340 + local_read(&serial->open_count) > 0) {
35341 /* Setup and send a ctrl req read on
35342 * port i */
35343 if (!serial->rx_urb_filled[0]) {
35344 @@ -3098,7 +3097,7 @@ static int hso_resume(struct usb_interface *iface)
35345 /* Start all serial ports */
35346 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35347 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35348 - if (dev2ser(serial_table[i])->open_count) {
35349 + if (local_read(&dev2ser(serial_table[i])->open_count)) {
35350 result =
35351 hso_start_serial_device(serial_table[i], GFP_NOIO);
35352 hso_kick_transmit(dev2ser(serial_table[i]));
35353 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35354 index 420d69b..74f90a2 100644
35355 --- a/drivers/net/wireless/ath/ath.h
35356 +++ b/drivers/net/wireless/ath/ath.h
35357 @@ -119,6 +119,7 @@ struct ath_ops {
35358 void (*write_flush) (void *);
35359 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35360 };
35361 +typedef struct ath_ops __no_const ath_ops_no_const;
35362
35363 struct ath_common;
35364 struct ath_bus_ops;
35365 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35366 index aa2abaf..5f5152d 100644
35367 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35368 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35369 @@ -183,8 +183,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35370 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35371 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35372
35373 - ACCESS_ONCE(ads->ds_link) = i->link;
35374 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35375 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
35376 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35377
35378 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35379 ctl6 = SM(i->keytype, AR_EncrType);
35380 @@ -198,26 +198,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35381
35382 if ((i->is_first || i->is_last) &&
35383 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35384 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35385 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35386 | set11nTries(i->rates, 1)
35387 | set11nTries(i->rates, 2)
35388 | set11nTries(i->rates, 3)
35389 | (i->dur_update ? AR_DurUpdateEna : 0)
35390 | SM(0, AR_BurstDur);
35391
35392 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35393 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35394 | set11nRate(i->rates, 1)
35395 | set11nRate(i->rates, 2)
35396 | set11nRate(i->rates, 3);
35397 } else {
35398 - ACCESS_ONCE(ads->ds_ctl2) = 0;
35399 - ACCESS_ONCE(ads->ds_ctl3) = 0;
35400 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35401 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35402 }
35403
35404 if (!i->is_first) {
35405 - ACCESS_ONCE(ads->ds_ctl0) = 0;
35406 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35407 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35408 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35409 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35410 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35411 return;
35412 }
35413
35414 @@ -242,7 +242,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35415 break;
35416 }
35417
35418 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35419 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35420 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35421 | SM(i->txpower, AR_XmitPower)
35422 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35423 @@ -252,19 +252,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35424 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35425 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35426
35427 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35428 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35429 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35430 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35431
35432 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35433 return;
35434
35435 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35436 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35437 | set11nPktDurRTSCTS(i->rates, 1);
35438
35439 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35440 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35441 | set11nPktDurRTSCTS(i->rates, 3);
35442
35443 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35444 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35445 | set11nRateFlags(i->rates, 1)
35446 | set11nRateFlags(i->rates, 2)
35447 | set11nRateFlags(i->rates, 3)
35448 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35449 index a66a13b..0ef399e 100644
35450 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35451 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35452 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35453 (i->qcu << AR_TxQcuNum_S) | desc_len;
35454
35455 checksum += val;
35456 - ACCESS_ONCE(ads->info) = val;
35457 + ACCESS_ONCE_RW(ads->info) = val;
35458
35459 checksum += i->link;
35460 - ACCESS_ONCE(ads->link) = i->link;
35461 + ACCESS_ONCE_RW(ads->link) = i->link;
35462
35463 checksum += i->buf_addr[0];
35464 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35465 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35466 checksum += i->buf_addr[1];
35467 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35468 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35469 checksum += i->buf_addr[2];
35470 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35471 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35472 checksum += i->buf_addr[3];
35473 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35474 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35475
35476 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35477 - ACCESS_ONCE(ads->ctl3) = val;
35478 + ACCESS_ONCE_RW(ads->ctl3) = val;
35479 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35480 - ACCESS_ONCE(ads->ctl5) = val;
35481 + ACCESS_ONCE_RW(ads->ctl5) = val;
35482 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35483 - ACCESS_ONCE(ads->ctl7) = val;
35484 + ACCESS_ONCE_RW(ads->ctl7) = val;
35485 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35486 - ACCESS_ONCE(ads->ctl9) = val;
35487 + ACCESS_ONCE_RW(ads->ctl9) = val;
35488
35489 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35490 - ACCESS_ONCE(ads->ctl10) = checksum;
35491 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
35492
35493 if (i->is_first || i->is_last) {
35494 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35495 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35496 | set11nTries(i->rates, 1)
35497 | set11nTries(i->rates, 2)
35498 | set11nTries(i->rates, 3)
35499 | (i->dur_update ? AR_DurUpdateEna : 0)
35500 | SM(0, AR_BurstDur);
35501
35502 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35503 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35504 | set11nRate(i->rates, 1)
35505 | set11nRate(i->rates, 2)
35506 | set11nRate(i->rates, 3);
35507 } else {
35508 - ACCESS_ONCE(ads->ctl13) = 0;
35509 - ACCESS_ONCE(ads->ctl14) = 0;
35510 + ACCESS_ONCE_RW(ads->ctl13) = 0;
35511 + ACCESS_ONCE_RW(ads->ctl14) = 0;
35512 }
35513
35514 ads->ctl20 = 0;
35515 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35516
35517 ctl17 = SM(i->keytype, AR_EncrType);
35518 if (!i->is_first) {
35519 - ACCESS_ONCE(ads->ctl11) = 0;
35520 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35521 - ACCESS_ONCE(ads->ctl15) = 0;
35522 - ACCESS_ONCE(ads->ctl16) = 0;
35523 - ACCESS_ONCE(ads->ctl17) = ctl17;
35524 - ACCESS_ONCE(ads->ctl18) = 0;
35525 - ACCESS_ONCE(ads->ctl19) = 0;
35526 + ACCESS_ONCE_RW(ads->ctl11) = 0;
35527 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35528 + ACCESS_ONCE_RW(ads->ctl15) = 0;
35529 + ACCESS_ONCE_RW(ads->ctl16) = 0;
35530 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35531 + ACCESS_ONCE_RW(ads->ctl18) = 0;
35532 + ACCESS_ONCE_RW(ads->ctl19) = 0;
35533 return;
35534 }
35535
35536 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35537 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35538 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35539 | SM(i->txpower, AR_XmitPower)
35540 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35541 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35542 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35543 ctl12 |= SM(val, AR_PAPRDChainMask);
35544
35545 - ACCESS_ONCE(ads->ctl12) = ctl12;
35546 - ACCESS_ONCE(ads->ctl17) = ctl17;
35547 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35548 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35549
35550 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35551 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35552 | set11nPktDurRTSCTS(i->rates, 1);
35553
35554 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35555 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35556 | set11nPktDurRTSCTS(i->rates, 3);
35557
35558 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35559 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35560 | set11nRateFlags(i->rates, 1)
35561 | set11nRateFlags(i->rates, 2)
35562 | set11nRateFlags(i->rates, 3)
35563 | SM(i->rtscts_rate, AR_RTSCTSRate);
35564
35565 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35566 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35567 }
35568
35569 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35570 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35571 index e88f182..4e57f5d 100644
35572 --- a/drivers/net/wireless/ath/ath9k/hw.h
35573 +++ b/drivers/net/wireless/ath/ath9k/hw.h
35574 @@ -614,7 +614,7 @@ struct ath_hw_private_ops {
35575
35576 /* ANI */
35577 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35578 -};
35579 +} __no_const;
35580
35581 /**
35582 * struct ath_hw_ops - callbacks used by hardware code and driver code
35583 @@ -644,7 +644,7 @@ struct ath_hw_ops {
35584 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35585 struct ath_hw_antcomb_conf *antconf);
35586
35587 -};
35588 +} __no_const;
35589
35590 struct ath_nf_limits {
35591 s16 max;
35592 @@ -664,7 +664,7 @@ enum ath_cal_list {
35593 #define AH_FASTCC 0x4
35594
35595 struct ath_hw {
35596 - struct ath_ops reg_ops;
35597 + ath_ops_no_const reg_ops;
35598
35599 struct ieee80211_hw *hw;
35600 struct ath_common common;
35601 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35602 index af00e2c..ab04d34 100644
35603 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35604 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35605 @@ -545,7 +545,7 @@ struct phy_func_ptr {
35606 void (*carrsuppr)(struct brcms_phy *);
35607 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35608 void (*detach)(struct brcms_phy *);
35609 -};
35610 +} __no_const;
35611
35612 struct brcms_phy {
35613 struct brcms_phy_pub pubpi_ro;
35614 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35615 index faec404..a5277f1 100644
35616 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
35617 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35618 @@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35619 */
35620 if (il3945_mod_params.disable_hw_scan) {
35621 D_INFO("Disabling hw_scan\n");
35622 - il3945_mac_ops.hw_scan = NULL;
35623 + pax_open_kernel();
35624 + *(void **)&il3945_mac_ops.hw_scan = NULL;
35625 + pax_close_kernel();
35626 }
35627
35628 D_INFO("*** LOAD DRIVER ***\n");
35629 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35630 index b7ce6a6..5649756 100644
35631 --- a/drivers/net/wireless/mac80211_hwsim.c
35632 +++ b/drivers/net/wireless/mac80211_hwsim.c
35633 @@ -1721,9 +1721,11 @@ static int __init init_mac80211_hwsim(void)
35634 return -EINVAL;
35635
35636 if (fake_hw_scan) {
35637 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35638 - mac80211_hwsim_ops.sw_scan_start = NULL;
35639 - mac80211_hwsim_ops.sw_scan_complete = NULL;
35640 + pax_open_kernel();
35641 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35642 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35643 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35644 + pax_close_kernel();
35645 }
35646
35647 spin_lock_init(&hwsim_radio_lock);
35648 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35649 index 35225e9..95e6bf9 100644
35650 --- a/drivers/net/wireless/mwifiex/main.h
35651 +++ b/drivers/net/wireless/mwifiex/main.h
35652 @@ -537,7 +537,7 @@ struct mwifiex_if_ops {
35653 void (*cleanup_mpa_buf) (struct mwifiex_adapter *);
35654 int (*cmdrsp_complete) (struct mwifiex_adapter *, struct sk_buff *);
35655 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35656 -};
35657 +} __no_const;
35658
35659 struct mwifiex_adapter {
35660 u8 iface_type;
35661 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35662 index d66e298..55b0a89 100644
35663 --- a/drivers/net/wireless/rndis_wlan.c
35664 +++ b/drivers/net/wireless/rndis_wlan.c
35665 @@ -1278,7 +1278,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35666
35667 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35668
35669 - if (rts_threshold < 0 || rts_threshold > 2347)
35670 + if (rts_threshold > 2347)
35671 rts_threshold = 2347;
35672
35673 tmp = cpu_to_le32(rts_threshold);
35674 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
35675 index c264dfa..08ee30e 100644
35676 --- a/drivers/net/wireless/rt2x00/rt2x00.h
35677 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
35678 @@ -396,7 +396,7 @@ struct rt2x00_intf {
35679 * for hardware which doesn't support hardware
35680 * sequence counting.
35681 */
35682 - atomic_t seqno;
35683 + atomic_unchecked_t seqno;
35684 };
35685
35686 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
35687 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
35688 index 50f92d5..f3afc41 100644
35689 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
35690 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
35691 @@ -229,9 +229,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
35692 * sequence counter given by mac80211.
35693 */
35694 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
35695 - seqno = atomic_add_return(0x10, &intf->seqno);
35696 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
35697 else
35698 - seqno = atomic_read(&intf->seqno);
35699 + seqno = atomic_read_unchecked(&intf->seqno);
35700
35701 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
35702 hdr->seq_ctrl |= cpu_to_le16(seqno);
35703 diff --git a/drivers/net/wireless/wl1251/wl1251.h b/drivers/net/wireless/wl1251/wl1251.h
35704 index 9d8f581..0f6589e 100644
35705 --- a/drivers/net/wireless/wl1251/wl1251.h
35706 +++ b/drivers/net/wireless/wl1251/wl1251.h
35707 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
35708 void (*reset)(struct wl1251 *wl);
35709 void (*enable_irq)(struct wl1251 *wl);
35710 void (*disable_irq)(struct wl1251 *wl);
35711 -};
35712 +} __no_const;
35713
35714 struct wl1251 {
35715 struct ieee80211_hw *hw;
35716 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
35717 index f34b5b2..b5abb9f 100644
35718 --- a/drivers/oprofile/buffer_sync.c
35719 +++ b/drivers/oprofile/buffer_sync.c
35720 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
35721 if (cookie == NO_COOKIE)
35722 offset = pc;
35723 if (cookie == INVALID_COOKIE) {
35724 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35725 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35726 offset = pc;
35727 }
35728 if (cookie != last_cookie) {
35729 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
35730 /* add userspace sample */
35731
35732 if (!mm) {
35733 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
35734 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
35735 return 0;
35736 }
35737
35738 cookie = lookup_dcookie(mm, s->eip, &offset);
35739
35740 if (cookie == INVALID_COOKIE) {
35741 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35742 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35743 return 0;
35744 }
35745
35746 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
35747 /* ignore backtraces if failed to add a sample */
35748 if (state == sb_bt_start) {
35749 state = sb_bt_ignore;
35750 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
35751 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
35752 }
35753 }
35754 release_mm(mm);
35755 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
35756 index c0cc4e7..44d4e54 100644
35757 --- a/drivers/oprofile/event_buffer.c
35758 +++ b/drivers/oprofile/event_buffer.c
35759 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
35760 }
35761
35762 if (buffer_pos == buffer_size) {
35763 - atomic_inc(&oprofile_stats.event_lost_overflow);
35764 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
35765 return;
35766 }
35767
35768 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
35769 index ed2c3ec..deda85a 100644
35770 --- a/drivers/oprofile/oprof.c
35771 +++ b/drivers/oprofile/oprof.c
35772 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
35773 if (oprofile_ops.switch_events())
35774 return;
35775
35776 - atomic_inc(&oprofile_stats.multiplex_counter);
35777 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
35778 start_switch_worker();
35779 }
35780
35781 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
35782 index 917d28e..d62d981 100644
35783 --- a/drivers/oprofile/oprofile_stats.c
35784 +++ b/drivers/oprofile/oprofile_stats.c
35785 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
35786 cpu_buf->sample_invalid_eip = 0;
35787 }
35788
35789 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
35790 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
35791 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
35792 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
35793 - atomic_set(&oprofile_stats.multiplex_counter, 0);
35794 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
35795 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
35796 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
35797 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
35798 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
35799 }
35800
35801
35802 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
35803 index 38b6fc0..b5cbfce 100644
35804 --- a/drivers/oprofile/oprofile_stats.h
35805 +++ b/drivers/oprofile/oprofile_stats.h
35806 @@ -13,11 +13,11 @@
35807 #include <linux/atomic.h>
35808
35809 struct oprofile_stat_struct {
35810 - atomic_t sample_lost_no_mm;
35811 - atomic_t sample_lost_no_mapping;
35812 - atomic_t bt_lost_no_mapping;
35813 - atomic_t event_lost_overflow;
35814 - atomic_t multiplex_counter;
35815 + atomic_unchecked_t sample_lost_no_mm;
35816 + atomic_unchecked_t sample_lost_no_mapping;
35817 + atomic_unchecked_t bt_lost_no_mapping;
35818 + atomic_unchecked_t event_lost_overflow;
35819 + atomic_unchecked_t multiplex_counter;
35820 };
35821
35822 extern struct oprofile_stat_struct oprofile_stats;
35823 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
35824 index 849357c..b83c1e0 100644
35825 --- a/drivers/oprofile/oprofilefs.c
35826 +++ b/drivers/oprofile/oprofilefs.c
35827 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
35828
35829
35830 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
35831 - char const *name, atomic_t *val)
35832 + char const *name, atomic_unchecked_t *val)
35833 {
35834 return __oprofilefs_create_file(sb, root, name,
35835 &atomic_ro_fops, 0444, val);
35836 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
35837 index 3f56bc0..707d642 100644
35838 --- a/drivers/parport/procfs.c
35839 +++ b/drivers/parport/procfs.c
35840 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
35841
35842 *ppos += len;
35843
35844 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
35845 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
35846 }
35847
35848 #ifdef CONFIG_PARPORT_1284
35849 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
35850
35851 *ppos += len;
35852
35853 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
35854 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
35855 }
35856 #endif /* IEEE1284.3 support. */
35857
35858 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
35859 index 9fff878..ad0ad53 100644
35860 --- a/drivers/pci/hotplug/cpci_hotplug.h
35861 +++ b/drivers/pci/hotplug/cpci_hotplug.h
35862 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
35863 int (*hardware_test) (struct slot* slot, u32 value);
35864 u8 (*get_power) (struct slot* slot);
35865 int (*set_power) (struct slot* slot, int value);
35866 -};
35867 +} __no_const;
35868
35869 struct cpci_hp_controller {
35870 unsigned int irq;
35871 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
35872 index 76ba8a1..20ca857 100644
35873 --- a/drivers/pci/hotplug/cpqphp_nvram.c
35874 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
35875 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
35876
35877 void compaq_nvram_init (void __iomem *rom_start)
35878 {
35879 +
35880 +#ifndef CONFIG_PAX_KERNEXEC
35881 if (rom_start) {
35882 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
35883 }
35884 +#endif
35885 +
35886 dbg("int15 entry = %p\n", compaq_int15_entry_point);
35887
35888 /* initialize our int15 lock */
35889 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
35890 index b500840..d7159d3 100644
35891 --- a/drivers/pci/pcie/aspm.c
35892 +++ b/drivers/pci/pcie/aspm.c
35893 @@ -27,9 +27,9 @@
35894 #define MODULE_PARAM_PREFIX "pcie_aspm."
35895
35896 /* Note: those are not register definitions */
35897 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
35898 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
35899 -#define ASPM_STATE_L1 (4) /* L1 state */
35900 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
35901 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
35902 +#define ASPM_STATE_L1 (4U) /* L1 state */
35903 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
35904 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
35905
35906 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
35907 index 5e1ca3c..08082fe 100644
35908 --- a/drivers/pci/probe.c
35909 +++ b/drivers/pci/probe.c
35910 @@ -215,7 +215,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
35911 u16 orig_cmd;
35912 struct pci_bus_region region;
35913
35914 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
35915 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
35916
35917 if (!dev->mmio_always_on) {
35918 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
35919 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
35920 index 27911b5..5b6db88 100644
35921 --- a/drivers/pci/proc.c
35922 +++ b/drivers/pci/proc.c
35923 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
35924 static int __init pci_proc_init(void)
35925 {
35926 struct pci_dev *dev = NULL;
35927 +
35928 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
35929 +#ifdef CONFIG_GRKERNSEC_PROC_USER
35930 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
35931 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
35932 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
35933 +#endif
35934 +#else
35935 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
35936 +#endif
35937 proc_create("devices", 0, proc_bus_pci_dir,
35938 &proc_bus_pci_dev_operations);
35939 proc_initialized = 1;
35940 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
35941 index d68c000..f6094ca 100644
35942 --- a/drivers/platform/x86/thinkpad_acpi.c
35943 +++ b/drivers/platform/x86/thinkpad_acpi.c
35944 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
35945 return 0;
35946 }
35947
35948 -void static hotkey_mask_warn_incomplete_mask(void)
35949 +static void hotkey_mask_warn_incomplete_mask(void)
35950 {
35951 /* log only what the user can fix... */
35952 const u32 wantedmask = hotkey_driver_mask &
35953 @@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
35954 }
35955 }
35956
35957 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35958 - struct tp_nvram_state *newn,
35959 - const u32 event_mask)
35960 -{
35961 -
35962 #define TPACPI_COMPARE_KEY(__scancode, __member) \
35963 do { \
35964 if ((event_mask & (1 << __scancode)) && \
35965 @@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35966 tpacpi_hotkey_send_key(__scancode); \
35967 } while (0)
35968
35969 - void issue_volchange(const unsigned int oldvol,
35970 - const unsigned int newvol)
35971 - {
35972 - unsigned int i = oldvol;
35973 +static void issue_volchange(const unsigned int oldvol,
35974 + const unsigned int newvol,
35975 + const u32 event_mask)
35976 +{
35977 + unsigned int i = oldvol;
35978
35979 - while (i > newvol) {
35980 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35981 - i--;
35982 - }
35983 - while (i < newvol) {
35984 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35985 - i++;
35986 - }
35987 + while (i > newvol) {
35988 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35989 + i--;
35990 }
35991 + while (i < newvol) {
35992 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35993 + i++;
35994 + }
35995 +}
35996
35997 - void issue_brightnesschange(const unsigned int oldbrt,
35998 - const unsigned int newbrt)
35999 - {
36000 - unsigned int i = oldbrt;
36001 +static void issue_brightnesschange(const unsigned int oldbrt,
36002 + const unsigned int newbrt,
36003 + const u32 event_mask)
36004 +{
36005 + unsigned int i = oldbrt;
36006
36007 - while (i > newbrt) {
36008 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36009 - i--;
36010 - }
36011 - while (i < newbrt) {
36012 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36013 - i++;
36014 - }
36015 + while (i > newbrt) {
36016 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36017 + i--;
36018 + }
36019 + while (i < newbrt) {
36020 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36021 + i++;
36022 }
36023 +}
36024
36025 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36026 + struct tp_nvram_state *newn,
36027 + const u32 event_mask)
36028 +{
36029 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36030 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36031 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36032 @@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36033 oldn->volume_level != newn->volume_level) {
36034 /* recently muted, or repeated mute keypress, or
36035 * multiple presses ending in mute */
36036 - issue_volchange(oldn->volume_level, newn->volume_level);
36037 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36038 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36039 }
36040 } else {
36041 @@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36042 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36043 }
36044 if (oldn->volume_level != newn->volume_level) {
36045 - issue_volchange(oldn->volume_level, newn->volume_level);
36046 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36047 } else if (oldn->volume_toggle != newn->volume_toggle) {
36048 /* repeated vol up/down keypress at end of scale ? */
36049 if (newn->volume_level == 0)
36050 @@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36051 /* handle brightness */
36052 if (oldn->brightness_level != newn->brightness_level) {
36053 issue_brightnesschange(oldn->brightness_level,
36054 - newn->brightness_level);
36055 + newn->brightness_level,
36056 + event_mask);
36057 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36058 /* repeated key presses that didn't change state */
36059 if (newn->brightness_level == 0)
36060 @@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36061 && !tp_features.bright_unkfw)
36062 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36063 }
36064 +}
36065
36066 #undef TPACPI_COMPARE_KEY
36067 #undef TPACPI_MAY_SEND_KEY
36068 -}
36069
36070 /*
36071 * Polling driver
36072 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36073 index 769d265..a3a05ca 100644
36074 --- a/drivers/pnp/pnpbios/bioscalls.c
36075 +++ b/drivers/pnp/pnpbios/bioscalls.c
36076 @@ -58,7 +58,7 @@ do { \
36077 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36078 } while(0)
36079
36080 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36081 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36082 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36083
36084 /*
36085 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36086
36087 cpu = get_cpu();
36088 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36089 +
36090 + pax_open_kernel();
36091 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36092 + pax_close_kernel();
36093
36094 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36095 spin_lock_irqsave(&pnp_bios_lock, flags);
36096 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36097 :"memory");
36098 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36099
36100 + pax_open_kernel();
36101 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36102 + pax_close_kernel();
36103 +
36104 put_cpu();
36105
36106 /* If we get here and this is set then the PnP BIOS faulted on us. */
36107 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36108 return status;
36109 }
36110
36111 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
36112 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36113 {
36114 int i;
36115
36116 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36117 pnp_bios_callpoint.offset = header->fields.pm16offset;
36118 pnp_bios_callpoint.segment = PNP_CS16;
36119
36120 + pax_open_kernel();
36121 +
36122 for_each_possible_cpu(i) {
36123 struct desc_struct *gdt = get_cpu_gdt_table(i);
36124 if (!gdt)
36125 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36126 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36127 (unsigned long)__va(header->fields.pm16dseg));
36128 }
36129 +
36130 + pax_close_kernel();
36131 }
36132 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36133 index b0ecacb..7c9da2e 100644
36134 --- a/drivers/pnp/resource.c
36135 +++ b/drivers/pnp/resource.c
36136 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36137 return 1;
36138
36139 /* check if the resource is valid */
36140 - if (*irq < 0 || *irq > 15)
36141 + if (*irq > 15)
36142 return 0;
36143
36144 /* check if the resource is reserved */
36145 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36146 return 1;
36147
36148 /* check if the resource is valid */
36149 - if (*dma < 0 || *dma == 4 || *dma > 7)
36150 + if (*dma == 4 || *dma > 7)
36151 return 0;
36152
36153 /* check if the resource is reserved */
36154 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36155 index 222ccd8..6275fa5 100644
36156 --- a/drivers/power/bq27x00_battery.c
36157 +++ b/drivers/power/bq27x00_battery.c
36158 @@ -72,7 +72,7 @@
36159 struct bq27x00_device_info;
36160 struct bq27x00_access_methods {
36161 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36162 -};
36163 +} __no_const;
36164
36165 enum bq27x00_chip { BQ27000, BQ27500 };
36166
36167 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36168 index 4c5b053..104263e 100644
36169 --- a/drivers/regulator/max8660.c
36170 +++ b/drivers/regulator/max8660.c
36171 @@ -385,8 +385,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36172 max8660->shadow_regs[MAX8660_OVER1] = 5;
36173 } else {
36174 /* Otherwise devices can be toggled via software */
36175 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
36176 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
36177 + pax_open_kernel();
36178 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36179 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36180 + pax_close_kernel();
36181 }
36182
36183 /*
36184 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36185 index 845aa22..99ec402 100644
36186 --- a/drivers/regulator/mc13892-regulator.c
36187 +++ b/drivers/regulator/mc13892-regulator.c
36188 @@ -574,10 +574,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36189 }
36190 mc13xxx_unlock(mc13892);
36191
36192 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36193 + pax_open_kernel();
36194 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36195 = mc13892_vcam_set_mode;
36196 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36197 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36198 = mc13892_vcam_get_mode;
36199 + pax_close_kernel();
36200
36201 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36202 ARRAY_SIZE(mc13892_regulators));
36203 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36204 index cace6d3..f623fda 100644
36205 --- a/drivers/rtc/rtc-dev.c
36206 +++ b/drivers/rtc/rtc-dev.c
36207 @@ -14,6 +14,7 @@
36208 #include <linux/module.h>
36209 #include <linux/rtc.h>
36210 #include <linux/sched.h>
36211 +#include <linux/grsecurity.h>
36212 #include "rtc-core.h"
36213
36214 static dev_t rtc_devt;
36215 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36216 if (copy_from_user(&tm, uarg, sizeof(tm)))
36217 return -EFAULT;
36218
36219 + gr_log_timechange();
36220 +
36221 return rtc_set_time(rtc, &tm);
36222
36223 case RTC_PIE_ON:
36224 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36225 index 3fcf627..f334910 100644
36226 --- a/drivers/scsi/aacraid/aacraid.h
36227 +++ b/drivers/scsi/aacraid/aacraid.h
36228 @@ -492,7 +492,7 @@ struct adapter_ops
36229 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36230 /* Administrative operations */
36231 int (*adapter_comm)(struct aac_dev * dev, int comm);
36232 -};
36233 +} __no_const;
36234
36235 /*
36236 * Define which interrupt handler needs to be installed
36237 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36238 index 0d279c44..3d25a97 100644
36239 --- a/drivers/scsi/aacraid/linit.c
36240 +++ b/drivers/scsi/aacraid/linit.c
36241 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36242 #elif defined(__devinitconst)
36243 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36244 #else
36245 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36246 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36247 #endif
36248 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36249 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36250 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36251 index ff80552..1c4120c 100644
36252 --- a/drivers/scsi/aic94xx/aic94xx_init.c
36253 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
36254 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36255 .lldd_ata_set_dmamode = asd_set_dmamode,
36256 };
36257
36258 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36259 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36260 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36261 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36262 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36263 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36264 index 4ad7e36..d004679 100644
36265 --- a/drivers/scsi/bfa/bfa.h
36266 +++ b/drivers/scsi/bfa/bfa.h
36267 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
36268 u32 *end);
36269 int cpe_vec_q0;
36270 int rme_vec_q0;
36271 -};
36272 +} __no_const;
36273 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36274
36275 struct bfa_faa_cbfn_s {
36276 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36277 index f0f80e2..8ec946b 100644
36278 --- a/drivers/scsi/bfa/bfa_fcpim.c
36279 +++ b/drivers/scsi/bfa/bfa_fcpim.c
36280 @@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36281
36282 bfa_iotag_attach(fcp);
36283
36284 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36285 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36286 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36287 (fcp->num_itns * sizeof(struct bfa_itn_s));
36288 memset(fcp->itn_arr, 0,
36289 @@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36290 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36291 {
36292 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36293 - struct bfa_itn_s *itn;
36294 + bfa_itn_s_no_const *itn;
36295
36296 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36297 itn->isr = isr;
36298 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36299 index 36f26da..38a34a8 100644
36300 --- a/drivers/scsi/bfa/bfa_fcpim.h
36301 +++ b/drivers/scsi/bfa/bfa_fcpim.h
36302 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
36303 struct bfa_itn_s {
36304 bfa_isr_func_t isr;
36305 };
36306 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36307
36308 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36309 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36310 @@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36311 struct list_head iotag_tio_free_q; /* free IO resources */
36312 struct list_head iotag_unused_q; /* unused IO resources*/
36313 struct bfa_iotag_s *iotag_arr;
36314 - struct bfa_itn_s *itn_arr;
36315 + bfa_itn_s_no_const *itn_arr;
36316 int num_ioim_reqs;
36317 int num_fwtio_reqs;
36318 int num_itns;
36319 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36320 index 1a99d4b..e85d64b 100644
36321 --- a/drivers/scsi/bfa/bfa_ioc.h
36322 +++ b/drivers/scsi/bfa/bfa_ioc.h
36323 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36324 bfa_ioc_disable_cbfn_t disable_cbfn;
36325 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36326 bfa_ioc_reset_cbfn_t reset_cbfn;
36327 -};
36328 +} __no_const;
36329
36330 /*
36331 * IOC event notification mechanism.
36332 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36333 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36334 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36335 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36336 -};
36337 +} __no_const;
36338
36339 /*
36340 * Queue element to wait for room in request queue. FIFO order is
36341 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36342 index a3a056a..b9bbc2f 100644
36343 --- a/drivers/scsi/hosts.c
36344 +++ b/drivers/scsi/hosts.c
36345 @@ -42,7 +42,7 @@
36346 #include "scsi_logging.h"
36347
36348
36349 -static atomic_t scsi_host_next_hn; /* host_no for next new host */
36350 +static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
36351
36352
36353 static void scsi_host_cls_release(struct device *dev)
36354 @@ -360,7 +360,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36355 * subtract one because we increment first then return, but we need to
36356 * know what the next host number was before increment
36357 */
36358 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36359 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36360 shost->dma_channel = 0xff;
36361
36362 /* These three are default values which can be overridden */
36363 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36364 index 500e20d..ebd3059 100644
36365 --- a/drivers/scsi/hpsa.c
36366 +++ b/drivers/scsi/hpsa.c
36367 @@ -521,7 +521,7 @@ static inline u32 next_command(struct ctlr_info *h)
36368 u32 a;
36369
36370 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36371 - return h->access.command_completed(h);
36372 + return h->access->command_completed(h);
36373
36374 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36375 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36376 @@ -3002,7 +3002,7 @@ static void start_io(struct ctlr_info *h)
36377 while (!list_empty(&h->reqQ)) {
36378 c = list_entry(h->reqQ.next, struct CommandList, list);
36379 /* can't do anything if fifo is full */
36380 - if ((h->access.fifo_full(h))) {
36381 + if ((h->access->fifo_full(h))) {
36382 dev_warn(&h->pdev->dev, "fifo full\n");
36383 break;
36384 }
36385 @@ -3012,7 +3012,7 @@ static void start_io(struct ctlr_info *h)
36386 h->Qdepth--;
36387
36388 /* Tell the controller execute command */
36389 - h->access.submit_command(h, c);
36390 + h->access->submit_command(h, c);
36391
36392 /* Put job onto the completed Q */
36393 addQ(&h->cmpQ, c);
36394 @@ -3021,17 +3021,17 @@ static void start_io(struct ctlr_info *h)
36395
36396 static inline unsigned long get_next_completion(struct ctlr_info *h)
36397 {
36398 - return h->access.command_completed(h);
36399 + return h->access->command_completed(h);
36400 }
36401
36402 static inline bool interrupt_pending(struct ctlr_info *h)
36403 {
36404 - return h->access.intr_pending(h);
36405 + return h->access->intr_pending(h);
36406 }
36407
36408 static inline long interrupt_not_for_us(struct ctlr_info *h)
36409 {
36410 - return (h->access.intr_pending(h) == 0) ||
36411 + return (h->access->intr_pending(h) == 0) ||
36412 (h->interrupts_enabled == 0);
36413 }
36414
36415 @@ -3930,7 +3930,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36416 if (prod_index < 0)
36417 return -ENODEV;
36418 h->product_name = products[prod_index].product_name;
36419 - h->access = *(products[prod_index].access);
36420 + h->access = products[prod_index].access;
36421
36422 if (hpsa_board_disabled(h->pdev)) {
36423 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36424 @@ -4175,7 +4175,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36425
36426 assert_spin_locked(&lockup_detector_lock);
36427 remove_ctlr_from_lockup_detector_list(h);
36428 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36429 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36430 spin_lock_irqsave(&h->lock, flags);
36431 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36432 spin_unlock_irqrestore(&h->lock, flags);
36433 @@ -4355,7 +4355,7 @@ reinit_after_soft_reset:
36434 }
36435
36436 /* make sure the board interrupts are off */
36437 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36438 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36439
36440 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36441 goto clean2;
36442 @@ -4389,7 +4389,7 @@ reinit_after_soft_reset:
36443 * fake ones to scoop up any residual completions.
36444 */
36445 spin_lock_irqsave(&h->lock, flags);
36446 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36447 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36448 spin_unlock_irqrestore(&h->lock, flags);
36449 free_irq(h->intr[h->intr_mode], h);
36450 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36451 @@ -4408,9 +4408,9 @@ reinit_after_soft_reset:
36452 dev_info(&h->pdev->dev, "Board READY.\n");
36453 dev_info(&h->pdev->dev,
36454 "Waiting for stale completions to drain.\n");
36455 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36456 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36457 msleep(10000);
36458 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36459 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36460
36461 rc = controller_reset_failed(h->cfgtable);
36462 if (rc)
36463 @@ -4431,7 +4431,7 @@ reinit_after_soft_reset:
36464 }
36465
36466 /* Turn the interrupts on so we can service requests */
36467 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36468 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36469
36470 hpsa_hba_inquiry(h);
36471 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36472 @@ -4483,7 +4483,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36473 * To write all data in the battery backed cache to disks
36474 */
36475 hpsa_flush_cache(h);
36476 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36477 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36478 free_irq(h->intr[h->intr_mode], h);
36479 #ifdef CONFIG_PCI_MSI
36480 if (h->msix_vector)
36481 @@ -4657,7 +4657,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36482 return;
36483 }
36484 /* Change the access methods to the performant access methods */
36485 - h->access = SA5_performant_access;
36486 + h->access = &SA5_performant_access;
36487 h->transMethod = CFGTBL_Trans_Performant;
36488 }
36489
36490 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36491 index 7b28d54..952f23a 100644
36492 --- a/drivers/scsi/hpsa.h
36493 +++ b/drivers/scsi/hpsa.h
36494 @@ -72,7 +72,7 @@ struct ctlr_info {
36495 unsigned int msix_vector;
36496 unsigned int msi_vector;
36497 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36498 - struct access_method access;
36499 + struct access_method *access;
36500
36501 /* queue and queue Info */
36502 struct list_head reqQ;
36503 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36504 index f2df059..a3a9930 100644
36505 --- a/drivers/scsi/ips.h
36506 +++ b/drivers/scsi/ips.h
36507 @@ -1027,7 +1027,7 @@ typedef struct {
36508 int (*intr)(struct ips_ha *);
36509 void (*enableint)(struct ips_ha *);
36510 uint32_t (*statupd)(struct ips_ha *);
36511 -} ips_hw_func_t;
36512 +} __no_const ips_hw_func_t;
36513
36514 typedef struct ips_ha {
36515 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36516 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36517 index aceffad..c35c08d 100644
36518 --- a/drivers/scsi/libfc/fc_exch.c
36519 +++ b/drivers/scsi/libfc/fc_exch.c
36520 @@ -105,12 +105,12 @@ struct fc_exch_mgr {
36521 * all together if not used XXX
36522 */
36523 struct {
36524 - atomic_t no_free_exch;
36525 - atomic_t no_free_exch_xid;
36526 - atomic_t xid_not_found;
36527 - atomic_t xid_busy;
36528 - atomic_t seq_not_found;
36529 - atomic_t non_bls_resp;
36530 + atomic_unchecked_t no_free_exch;
36531 + atomic_unchecked_t no_free_exch_xid;
36532 + atomic_unchecked_t xid_not_found;
36533 + atomic_unchecked_t xid_busy;
36534 + atomic_unchecked_t seq_not_found;
36535 + atomic_unchecked_t non_bls_resp;
36536 } stats;
36537 };
36538
36539 @@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36540 /* allocate memory for exchange */
36541 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36542 if (!ep) {
36543 - atomic_inc(&mp->stats.no_free_exch);
36544 + atomic_inc_unchecked(&mp->stats.no_free_exch);
36545 goto out;
36546 }
36547 memset(ep, 0, sizeof(*ep));
36548 @@ -780,7 +780,7 @@ out:
36549 return ep;
36550 err:
36551 spin_unlock_bh(&pool->lock);
36552 - atomic_inc(&mp->stats.no_free_exch_xid);
36553 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36554 mempool_free(ep, mp->ep_pool);
36555 return NULL;
36556 }
36557 @@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36558 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36559 ep = fc_exch_find(mp, xid);
36560 if (!ep) {
36561 - atomic_inc(&mp->stats.xid_not_found);
36562 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36563 reject = FC_RJT_OX_ID;
36564 goto out;
36565 }
36566 @@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36567 ep = fc_exch_find(mp, xid);
36568 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36569 if (ep) {
36570 - atomic_inc(&mp->stats.xid_busy);
36571 + atomic_inc_unchecked(&mp->stats.xid_busy);
36572 reject = FC_RJT_RX_ID;
36573 goto rel;
36574 }
36575 @@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36576 }
36577 xid = ep->xid; /* get our XID */
36578 } else if (!ep) {
36579 - atomic_inc(&mp->stats.xid_not_found);
36580 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36581 reject = FC_RJT_RX_ID; /* XID not found */
36582 goto out;
36583 }
36584 @@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36585 } else {
36586 sp = &ep->seq;
36587 if (sp->id != fh->fh_seq_id) {
36588 - atomic_inc(&mp->stats.seq_not_found);
36589 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36590 if (f_ctl & FC_FC_END_SEQ) {
36591 /*
36592 * Update sequence_id based on incoming last
36593 @@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36594
36595 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36596 if (!ep) {
36597 - atomic_inc(&mp->stats.xid_not_found);
36598 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36599 goto out;
36600 }
36601 if (ep->esb_stat & ESB_ST_COMPLETE) {
36602 - atomic_inc(&mp->stats.xid_not_found);
36603 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36604 goto rel;
36605 }
36606 if (ep->rxid == FC_XID_UNKNOWN)
36607 ep->rxid = ntohs(fh->fh_rx_id);
36608 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36609 - atomic_inc(&mp->stats.xid_not_found);
36610 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36611 goto rel;
36612 }
36613 if (ep->did != ntoh24(fh->fh_s_id) &&
36614 ep->did != FC_FID_FLOGI) {
36615 - atomic_inc(&mp->stats.xid_not_found);
36616 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36617 goto rel;
36618 }
36619 sof = fr_sof(fp);
36620 @@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36621 sp->ssb_stat |= SSB_ST_RESP;
36622 sp->id = fh->fh_seq_id;
36623 } else if (sp->id != fh->fh_seq_id) {
36624 - atomic_inc(&mp->stats.seq_not_found);
36625 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36626 goto rel;
36627 }
36628
36629 @@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36630 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36631
36632 if (!sp)
36633 - atomic_inc(&mp->stats.xid_not_found);
36634 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36635 else
36636 - atomic_inc(&mp->stats.non_bls_resp);
36637 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
36638
36639 fc_frame_free(fp);
36640 }
36641 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36642 index d109cc3..09f4e7d 100644
36643 --- a/drivers/scsi/libsas/sas_ata.c
36644 +++ b/drivers/scsi/libsas/sas_ata.c
36645 @@ -529,7 +529,7 @@ static struct ata_port_operations sas_sata_ops = {
36646 .postreset = ata_std_postreset,
36647 .error_handler = ata_std_error_handler,
36648 .post_internal_cmd = sas_ata_post_internal,
36649 - .qc_defer = ata_std_qc_defer,
36650 + .qc_defer = ata_std_qc_defer,
36651 .qc_prep = ata_noop_qc_prep,
36652 .qc_issue = sas_ata_qc_issue,
36653 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36654 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36655 index 3a1ffdd..8eb7c71 100644
36656 --- a/drivers/scsi/lpfc/lpfc.h
36657 +++ b/drivers/scsi/lpfc/lpfc.h
36658 @@ -413,7 +413,7 @@ struct lpfc_vport {
36659 struct dentry *debug_nodelist;
36660 struct dentry *vport_debugfs_root;
36661 struct lpfc_debugfs_trc *disc_trc;
36662 - atomic_t disc_trc_cnt;
36663 + atomic_unchecked_t disc_trc_cnt;
36664 #endif
36665 uint8_t stat_data_enabled;
36666 uint8_t stat_data_blocked;
36667 @@ -826,8 +826,8 @@ struct lpfc_hba {
36668 struct timer_list fabric_block_timer;
36669 unsigned long bit_flags;
36670 #define FABRIC_COMANDS_BLOCKED 0
36671 - atomic_t num_rsrc_err;
36672 - atomic_t num_cmd_success;
36673 + atomic_unchecked_t num_rsrc_err;
36674 + atomic_unchecked_t num_cmd_success;
36675 unsigned long last_rsrc_error_time;
36676 unsigned long last_ramp_down_time;
36677 unsigned long last_ramp_up_time;
36678 @@ -863,7 +863,7 @@ struct lpfc_hba {
36679
36680 struct dentry *debug_slow_ring_trc;
36681 struct lpfc_debugfs_trc *slow_ring_trc;
36682 - atomic_t slow_ring_trc_cnt;
36683 + atomic_unchecked_t slow_ring_trc_cnt;
36684 /* iDiag debugfs sub-directory */
36685 struct dentry *idiag_root;
36686 struct dentry *idiag_pci_cfg;
36687 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
36688 index af04b0d..8f1a97e 100644
36689 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
36690 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
36691 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
36692
36693 #include <linux/debugfs.h>
36694
36695 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36696 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36697 static unsigned long lpfc_debugfs_start_time = 0L;
36698
36699 /* iDiag */
36700 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
36701 lpfc_debugfs_enable = 0;
36702
36703 len = 0;
36704 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
36705 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
36706 (lpfc_debugfs_max_disc_trc - 1);
36707 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
36708 dtp = vport->disc_trc + i;
36709 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
36710 lpfc_debugfs_enable = 0;
36711
36712 len = 0;
36713 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
36714 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
36715 (lpfc_debugfs_max_slow_ring_trc - 1);
36716 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
36717 dtp = phba->slow_ring_trc + i;
36718 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
36719 !vport || !vport->disc_trc)
36720 return;
36721
36722 - index = atomic_inc_return(&vport->disc_trc_cnt) &
36723 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
36724 (lpfc_debugfs_max_disc_trc - 1);
36725 dtp = vport->disc_trc + index;
36726 dtp->fmt = fmt;
36727 dtp->data1 = data1;
36728 dtp->data2 = data2;
36729 dtp->data3 = data3;
36730 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36731 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36732 dtp->jif = jiffies;
36733 #endif
36734 return;
36735 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
36736 !phba || !phba->slow_ring_trc)
36737 return;
36738
36739 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
36740 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
36741 (lpfc_debugfs_max_slow_ring_trc - 1);
36742 dtp = phba->slow_ring_trc + index;
36743 dtp->fmt = fmt;
36744 dtp->data1 = data1;
36745 dtp->data2 = data2;
36746 dtp->data3 = data3;
36747 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36748 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36749 dtp->jif = jiffies;
36750 #endif
36751 return;
36752 @@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36753 "slow_ring buffer\n");
36754 goto debug_failed;
36755 }
36756 - atomic_set(&phba->slow_ring_trc_cnt, 0);
36757 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
36758 memset(phba->slow_ring_trc, 0,
36759 (sizeof(struct lpfc_debugfs_trc) *
36760 lpfc_debugfs_max_slow_ring_trc));
36761 @@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36762 "buffer\n");
36763 goto debug_failed;
36764 }
36765 - atomic_set(&vport->disc_trc_cnt, 0);
36766 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
36767
36768 snprintf(name, sizeof(name), "discovery_trace");
36769 vport->debug_disc_trc =
36770 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
36771 index 9598fdc..7e9f3d9 100644
36772 --- a/drivers/scsi/lpfc/lpfc_init.c
36773 +++ b/drivers/scsi/lpfc/lpfc_init.c
36774 @@ -10266,8 +10266,10 @@ lpfc_init(void)
36775 "misc_register returned with status %d", error);
36776
36777 if (lpfc_enable_npiv) {
36778 - lpfc_transport_functions.vport_create = lpfc_vport_create;
36779 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36780 + pax_open_kernel();
36781 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
36782 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36783 + pax_close_kernel();
36784 }
36785 lpfc_transport_template =
36786 fc_attach_transport(&lpfc_transport_functions);
36787 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
36788 index 88f3a83..686d3fa 100644
36789 --- a/drivers/scsi/lpfc/lpfc_scsi.c
36790 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
36791 @@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
36792 uint32_t evt_posted;
36793
36794 spin_lock_irqsave(&phba->hbalock, flags);
36795 - atomic_inc(&phba->num_rsrc_err);
36796 + atomic_inc_unchecked(&phba->num_rsrc_err);
36797 phba->last_rsrc_error_time = jiffies;
36798
36799 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
36800 @@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
36801 unsigned long flags;
36802 struct lpfc_hba *phba = vport->phba;
36803 uint32_t evt_posted;
36804 - atomic_inc(&phba->num_cmd_success);
36805 + atomic_inc_unchecked(&phba->num_cmd_success);
36806
36807 if (vport->cfg_lun_queue_depth <= queue_depth)
36808 return;
36809 @@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36810 unsigned long num_rsrc_err, num_cmd_success;
36811 int i;
36812
36813 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
36814 - num_cmd_success = atomic_read(&phba->num_cmd_success);
36815 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
36816 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
36817
36818 vports = lpfc_create_vport_work_array(phba);
36819 if (vports != NULL)
36820 @@ -417,8 +417,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36821 }
36822 }
36823 lpfc_destroy_vport_work_array(phba, vports);
36824 - atomic_set(&phba->num_rsrc_err, 0);
36825 - atomic_set(&phba->num_cmd_success, 0);
36826 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
36827 + atomic_set_unchecked(&phba->num_cmd_success, 0);
36828 }
36829
36830 /**
36831 @@ -452,8 +452,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
36832 }
36833 }
36834 lpfc_destroy_vport_work_array(phba, vports);
36835 - atomic_set(&phba->num_rsrc_err, 0);
36836 - atomic_set(&phba->num_cmd_success, 0);
36837 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
36838 + atomic_set_unchecked(&phba->num_cmd_success, 0);
36839 }
36840
36841 /**
36842 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
36843 index ea8a0b4..812a124 100644
36844 --- a/drivers/scsi/pmcraid.c
36845 +++ b/drivers/scsi/pmcraid.c
36846 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
36847 res->scsi_dev = scsi_dev;
36848 scsi_dev->hostdata = res;
36849 res->change_detected = 0;
36850 - atomic_set(&res->read_failures, 0);
36851 - atomic_set(&res->write_failures, 0);
36852 + atomic_set_unchecked(&res->read_failures, 0);
36853 + atomic_set_unchecked(&res->write_failures, 0);
36854 rc = 0;
36855 }
36856 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
36857 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
36858
36859 /* If this was a SCSI read/write command keep count of errors */
36860 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
36861 - atomic_inc(&res->read_failures);
36862 + atomic_inc_unchecked(&res->read_failures);
36863 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
36864 - atomic_inc(&res->write_failures);
36865 + atomic_inc_unchecked(&res->write_failures);
36866
36867 if (!RES_IS_GSCSI(res->cfg_entry) &&
36868 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
36869 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
36870 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36871 * hrrq_id assigned here in queuecommand
36872 */
36873 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36874 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36875 pinstance->num_hrrq;
36876 cmd->cmd_done = pmcraid_io_done;
36877
36878 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
36879 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36880 * hrrq_id assigned here in queuecommand
36881 */
36882 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36883 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36884 pinstance->num_hrrq;
36885
36886 if (request_size) {
36887 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
36888
36889 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
36890 /* add resources only after host is added into system */
36891 - if (!atomic_read(&pinstance->expose_resources))
36892 + if (!atomic_read_unchecked(&pinstance->expose_resources))
36893 return;
36894
36895 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
36896 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
36897 init_waitqueue_head(&pinstance->reset_wait_q);
36898
36899 atomic_set(&pinstance->outstanding_cmds, 0);
36900 - atomic_set(&pinstance->last_message_id, 0);
36901 - atomic_set(&pinstance->expose_resources, 0);
36902 + atomic_set_unchecked(&pinstance->last_message_id, 0);
36903 + atomic_set_unchecked(&pinstance->expose_resources, 0);
36904
36905 INIT_LIST_HEAD(&pinstance->free_res_q);
36906 INIT_LIST_HEAD(&pinstance->used_res_q);
36907 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
36908 /* Schedule worker thread to handle CCN and take care of adding and
36909 * removing devices to OS
36910 */
36911 - atomic_set(&pinstance->expose_resources, 1);
36912 + atomic_set_unchecked(&pinstance->expose_resources, 1);
36913 schedule_work(&pinstance->worker_q);
36914 return rc;
36915
36916 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
36917 index e1d150f..6c6df44 100644
36918 --- a/drivers/scsi/pmcraid.h
36919 +++ b/drivers/scsi/pmcraid.h
36920 @@ -748,7 +748,7 @@ struct pmcraid_instance {
36921 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
36922
36923 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
36924 - atomic_t last_message_id;
36925 + atomic_unchecked_t last_message_id;
36926
36927 /* configuration table */
36928 struct pmcraid_config_table *cfg_table;
36929 @@ -777,7 +777,7 @@ struct pmcraid_instance {
36930 atomic_t outstanding_cmds;
36931
36932 /* should add/delete resources to mid-layer now ?*/
36933 - atomic_t expose_resources;
36934 + atomic_unchecked_t expose_resources;
36935
36936
36937
36938 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
36939 struct pmcraid_config_table_entry_ext cfg_entry_ext;
36940 };
36941 struct scsi_device *scsi_dev; /* Link scsi_device structure */
36942 - atomic_t read_failures; /* count of failed READ commands */
36943 - atomic_t write_failures; /* count of failed WRITE commands */
36944 + atomic_unchecked_t read_failures; /* count of failed READ commands */
36945 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
36946
36947 /* To indicate add/delete/modify during CCN */
36948 u8 change_detected;
36949 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
36950 index a244303..6015eb7 100644
36951 --- a/drivers/scsi/qla2xxx/qla_def.h
36952 +++ b/drivers/scsi/qla2xxx/qla_def.h
36953 @@ -2264,7 +2264,7 @@ struct isp_operations {
36954 int (*start_scsi) (srb_t *);
36955 int (*abort_isp) (struct scsi_qla_host *);
36956 int (*iospace_config)(struct qla_hw_data*);
36957 -};
36958 +} __no_const;
36959
36960 /* MSI-X Support *************************************************************/
36961
36962 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
36963 index 7f2492e..5113877 100644
36964 --- a/drivers/scsi/qla4xxx/ql4_def.h
36965 +++ b/drivers/scsi/qla4xxx/ql4_def.h
36966 @@ -268,7 +268,7 @@ struct ddb_entry {
36967 * (4000 only) */
36968 atomic_t relogin_timer; /* Max Time to wait for
36969 * relogin to complete */
36970 - atomic_t relogin_retry_count; /* Num of times relogin has been
36971 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
36972 * retried */
36973 uint32_t default_time2wait; /* Default Min time between
36974 * relogins (+aens) */
36975 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
36976 index ee47820..a83b1f4 100644
36977 --- a/drivers/scsi/qla4xxx/ql4_os.c
36978 +++ b/drivers/scsi/qla4xxx/ql4_os.c
36979 @@ -2551,12 +2551,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
36980 */
36981 if (!iscsi_is_session_online(cls_sess)) {
36982 /* Reset retry relogin timer */
36983 - atomic_inc(&ddb_entry->relogin_retry_count);
36984 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
36985 DEBUG2(ql4_printk(KERN_INFO, ha,
36986 "%s: index[%d] relogin timed out-retrying"
36987 " relogin (%d), retry (%d)\n", __func__,
36988 ddb_entry->fw_ddb_index,
36989 - atomic_read(&ddb_entry->relogin_retry_count),
36990 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
36991 ddb_entry->default_time2wait + 4));
36992 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
36993 atomic_set(&ddb_entry->retry_relogin_timer,
36994 @@ -4453,7 +4453,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
36995
36996 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
36997 atomic_set(&ddb_entry->relogin_timer, 0);
36998 - atomic_set(&ddb_entry->relogin_retry_count, 0);
36999 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37000 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37001 ddb_entry->default_relogin_timeout =
37002 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37003 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37004 index 07322ec..91ccc23 100644
37005 --- a/drivers/scsi/scsi.c
37006 +++ b/drivers/scsi/scsi.c
37007 @@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37008 unsigned long timeout;
37009 int rtn = 0;
37010
37011 - atomic_inc(&cmd->device->iorequest_cnt);
37012 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37013
37014 /* check if the device is still usable */
37015 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37016 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37017 index 4037fd5..a19fcc7 100644
37018 --- a/drivers/scsi/scsi_lib.c
37019 +++ b/drivers/scsi/scsi_lib.c
37020 @@ -1415,7 +1415,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37021 shost = sdev->host;
37022 scsi_init_cmd_errh(cmd);
37023 cmd->result = DID_NO_CONNECT << 16;
37024 - atomic_inc(&cmd->device->iorequest_cnt);
37025 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37026
37027 /*
37028 * SCSI request completion path will do scsi_device_unbusy(),
37029 @@ -1441,9 +1441,9 @@ static void scsi_softirq_done(struct request *rq)
37030
37031 INIT_LIST_HEAD(&cmd->eh_entry);
37032
37033 - atomic_inc(&cmd->device->iodone_cnt);
37034 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
37035 if (cmd->result)
37036 - atomic_inc(&cmd->device->ioerr_cnt);
37037 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37038
37039 disposition = scsi_decide_disposition(cmd);
37040 if (disposition != SUCCESS &&
37041 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37042 index 04c2a27..9d8bd66 100644
37043 --- a/drivers/scsi/scsi_sysfs.c
37044 +++ b/drivers/scsi/scsi_sysfs.c
37045 @@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37046 char *buf) \
37047 { \
37048 struct scsi_device *sdev = to_scsi_device(dev); \
37049 - unsigned long long count = atomic_read(&sdev->field); \
37050 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
37051 return snprintf(buf, 20, "0x%llx\n", count); \
37052 } \
37053 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37054 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37055 index 84a1fdf..693b0d6 100644
37056 --- a/drivers/scsi/scsi_tgt_lib.c
37057 +++ b/drivers/scsi/scsi_tgt_lib.c
37058 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37059 int err;
37060
37061 dprintk("%lx %u\n", uaddr, len);
37062 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37063 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37064 if (err) {
37065 /*
37066 * TODO: need to fixup sg_tablesize, max_segment_size,
37067 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37068 index 80fbe2a..efa223b 100644
37069 --- a/drivers/scsi/scsi_transport_fc.c
37070 +++ b/drivers/scsi/scsi_transport_fc.c
37071 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37072 * Netlink Infrastructure
37073 */
37074
37075 -static atomic_t fc_event_seq;
37076 +static atomic_unchecked_t fc_event_seq;
37077
37078 /**
37079 * fc_get_event_number - Obtain the next sequential FC event number
37080 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
37081 u32
37082 fc_get_event_number(void)
37083 {
37084 - return atomic_add_return(1, &fc_event_seq);
37085 + return atomic_add_return_unchecked(1, &fc_event_seq);
37086 }
37087 EXPORT_SYMBOL(fc_get_event_number);
37088
37089 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
37090 {
37091 int error;
37092
37093 - atomic_set(&fc_event_seq, 0);
37094 + atomic_set_unchecked(&fc_event_seq, 0);
37095
37096 error = transport_class_register(&fc_host_class);
37097 if (error)
37098 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37099 char *cp;
37100
37101 *val = simple_strtoul(buf, &cp, 0);
37102 - if ((*cp && (*cp != '\n')) || (*val < 0))
37103 + if (*cp && (*cp != '\n'))
37104 return -EINVAL;
37105 /*
37106 * Check for overflow; dev_loss_tmo is u32
37107 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37108 index 1cf640e..78e9014 100644
37109 --- a/drivers/scsi/scsi_transport_iscsi.c
37110 +++ b/drivers/scsi/scsi_transport_iscsi.c
37111 @@ -79,7 +79,7 @@ struct iscsi_internal {
37112 struct transport_container session_cont;
37113 };
37114
37115 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37116 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37117 static struct workqueue_struct *iscsi_eh_timer_workq;
37118
37119 static DEFINE_IDA(iscsi_sess_ida);
37120 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37121 int err;
37122
37123 ihost = shost->shost_data;
37124 - session->sid = atomic_add_return(1, &iscsi_session_nr);
37125 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37126
37127 if (target_id == ISCSI_MAX_TARGET) {
37128 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37129 @@ -2940,7 +2940,7 @@ static __init int iscsi_transport_init(void)
37130 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37131 ISCSI_TRANSPORT_VERSION);
37132
37133 - atomic_set(&iscsi_session_nr, 0);
37134 + atomic_set_unchecked(&iscsi_session_nr, 0);
37135
37136 err = class_register(&iscsi_transport_class);
37137 if (err)
37138 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37139 index 21a045e..ec89e03 100644
37140 --- a/drivers/scsi/scsi_transport_srp.c
37141 +++ b/drivers/scsi/scsi_transport_srp.c
37142 @@ -33,7 +33,7 @@
37143 #include "scsi_transport_srp_internal.h"
37144
37145 struct srp_host_attrs {
37146 - atomic_t next_port_id;
37147 + atomic_unchecked_t next_port_id;
37148 };
37149 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37150
37151 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37152 struct Scsi_Host *shost = dev_to_shost(dev);
37153 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37154
37155 - atomic_set(&srp_host->next_port_id, 0);
37156 + atomic_set_unchecked(&srp_host->next_port_id, 0);
37157 return 0;
37158 }
37159
37160 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37161 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37162 rport->roles = ids->roles;
37163
37164 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37165 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37166 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37167
37168 transport_setup_device(&rport->dev);
37169 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37170 index eacd46b..e3f4d62 100644
37171 --- a/drivers/scsi/sg.c
37172 +++ b/drivers/scsi/sg.c
37173 @@ -1077,7 +1077,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37174 sdp->disk->disk_name,
37175 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37176 NULL,
37177 - (char *)arg);
37178 + (char __user *)arg);
37179 case BLKTRACESTART:
37180 return blk_trace_startstop(sdp->device->request_queue, 1);
37181 case BLKTRACESTOP:
37182 @@ -2312,7 +2312,7 @@ struct sg_proc_leaf {
37183 const struct file_operations * fops;
37184 };
37185
37186 -static struct sg_proc_leaf sg_proc_leaf_arr[] = {
37187 +static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
37188 {"allow_dio", &adio_fops},
37189 {"debug", &debug_fops},
37190 {"def_reserved_size", &dressz_fops},
37191 @@ -2332,7 +2332,7 @@ sg_proc_init(void)
37192 if (!sg_proc_sgp)
37193 return 1;
37194 for (k = 0; k < num_leaves; ++k) {
37195 - struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
37196 + const struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
37197 umode_t mask = leaf->fops->write ? S_IRUGO | S_IWUSR : S_IRUGO;
37198 proc_create(leaf->name, mask, sg_proc_sgp, leaf->fops);
37199 }
37200 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37201 index 3d8f662..070f1a5 100644
37202 --- a/drivers/spi/spi.c
37203 +++ b/drivers/spi/spi.c
37204 @@ -1361,7 +1361,7 @@ int spi_bus_unlock(struct spi_master *master)
37205 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37206
37207 /* portable code must never pass more than 32 bytes */
37208 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37209 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37210
37211 static u8 *buf;
37212
37213 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37214 index d91751f..a3a9e36 100644
37215 --- a/drivers/staging/octeon/ethernet-rx.c
37216 +++ b/drivers/staging/octeon/ethernet-rx.c
37217 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37218 /* Increment RX stats for virtual ports */
37219 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37220 #ifdef CONFIG_64BIT
37221 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37222 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37223 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37224 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37225 #else
37226 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37227 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37228 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37229 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37230 #endif
37231 }
37232 netif_receive_skb(skb);
37233 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37234 dev->name);
37235 */
37236 #ifdef CONFIG_64BIT
37237 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37238 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37239 #else
37240 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37241 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37242 #endif
37243 dev_kfree_skb_irq(skb);
37244 }
37245 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37246 index 60cba81..71eb239 100644
37247 --- a/drivers/staging/octeon/ethernet.c
37248 +++ b/drivers/staging/octeon/ethernet.c
37249 @@ -259,11 +259,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37250 * since the RX tasklet also increments it.
37251 */
37252 #ifdef CONFIG_64BIT
37253 - atomic64_add(rx_status.dropped_packets,
37254 - (atomic64_t *)&priv->stats.rx_dropped);
37255 + atomic64_add_unchecked(rx_status.dropped_packets,
37256 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37257 #else
37258 - atomic_add(rx_status.dropped_packets,
37259 - (atomic_t *)&priv->stats.rx_dropped);
37260 + atomic_add_unchecked(rx_status.dropped_packets,
37261 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37262 #endif
37263 }
37264
37265 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37266 index d3d8727..f9327bb8 100644
37267 --- a/drivers/staging/rtl8712/rtl871x_io.h
37268 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37269 @@ -108,7 +108,7 @@ struct _io_ops {
37270 u8 *pmem);
37271 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37272 u8 *pmem);
37273 -};
37274 +} __no_const;
37275
37276 struct io_req {
37277 struct list_head list;
37278 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37279 index c7b5e8b..783d6cb 100644
37280 --- a/drivers/staging/sbe-2t3e3/netdev.c
37281 +++ b/drivers/staging/sbe-2t3e3/netdev.c
37282 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37283 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37284
37285 if (rlen)
37286 - if (copy_to_user(data, &resp, rlen))
37287 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37288 return -EFAULT;
37289
37290 return 0;
37291 diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c
37292 index 42cdafe..2769103 100644
37293 --- a/drivers/staging/speakup/speakup_soft.c
37294 +++ b/drivers/staging/speakup/speakup_soft.c
37295 @@ -241,11 +241,11 @@ static ssize_t softsynth_read(struct file *fp, char *buf, size_t count,
37296 break;
37297 } else if (!initialized) {
37298 if (*init) {
37299 - ch = *init;
37300 init++;
37301 } else {
37302 initialized = 1;
37303 }
37304 + ch = *init;
37305 } else {
37306 ch = synth_buffer_getc();
37307 }
37308 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37309 index c7b888c..c94be93 100644
37310 --- a/drivers/staging/usbip/usbip_common.h
37311 +++ b/drivers/staging/usbip/usbip_common.h
37312 @@ -289,7 +289,7 @@ struct usbip_device {
37313 void (*shutdown)(struct usbip_device *);
37314 void (*reset)(struct usbip_device *);
37315 void (*unusable)(struct usbip_device *);
37316 - } eh_ops;
37317 + } __no_const eh_ops;
37318 };
37319
37320 /* usbip_common.c */
37321 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37322 index 88b3298..3783eee 100644
37323 --- a/drivers/staging/usbip/vhci.h
37324 +++ b/drivers/staging/usbip/vhci.h
37325 @@ -88,7 +88,7 @@ struct vhci_hcd {
37326 unsigned resuming:1;
37327 unsigned long re_timeout;
37328
37329 - atomic_t seqnum;
37330 + atomic_unchecked_t seqnum;
37331
37332 /*
37333 * NOTE:
37334 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37335 index dca9bf1..80735c9 100644
37336 --- a/drivers/staging/usbip/vhci_hcd.c
37337 +++ b/drivers/staging/usbip/vhci_hcd.c
37338 @@ -488,7 +488,7 @@ static void vhci_tx_urb(struct urb *urb)
37339 return;
37340 }
37341
37342 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37343 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37344 if (priv->seqnum == 0xffff)
37345 dev_info(&urb->dev->dev, "seqnum max\n");
37346
37347 @@ -740,7 +740,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37348 return -ENOMEM;
37349 }
37350
37351 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37352 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37353 if (unlink->seqnum == 0xffff)
37354 pr_info("seqnum max\n");
37355
37356 @@ -928,7 +928,7 @@ static int vhci_start(struct usb_hcd *hcd)
37357 vdev->rhport = rhport;
37358 }
37359
37360 - atomic_set(&vhci->seqnum, 0);
37361 + atomic_set_unchecked(&vhci->seqnum, 0);
37362 spin_lock_init(&vhci->lock);
37363
37364 hcd->power_budget = 0; /* no limit */
37365 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37366 index f5fba732..210a16c 100644
37367 --- a/drivers/staging/usbip/vhci_rx.c
37368 +++ b/drivers/staging/usbip/vhci_rx.c
37369 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37370 if (!urb) {
37371 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37372 pr_info("max seqnum %d\n",
37373 - atomic_read(&the_controller->seqnum));
37374 + atomic_read_unchecked(&the_controller->seqnum));
37375 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37376 return;
37377 }
37378 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37379 index 7735027..30eed13 100644
37380 --- a/drivers/staging/vt6655/hostap.c
37381 +++ b/drivers/staging/vt6655/hostap.c
37382 @@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
37383 *
37384 */
37385
37386 +static net_device_ops_no_const apdev_netdev_ops;
37387 +
37388 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37389 {
37390 PSDevice apdev_priv;
37391 struct net_device *dev = pDevice->dev;
37392 int ret;
37393 - const struct net_device_ops apdev_netdev_ops = {
37394 - .ndo_start_xmit = pDevice->tx_80211,
37395 - };
37396
37397 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37398
37399 @@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37400 *apdev_priv = *pDevice;
37401 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37402
37403 + /* only half broken now */
37404 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37405 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37406
37407 pDevice->apdev->type = ARPHRD_IEEE80211;
37408 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37409 index 51b5adf..098e320 100644
37410 --- a/drivers/staging/vt6656/hostap.c
37411 +++ b/drivers/staging/vt6656/hostap.c
37412 @@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
37413 *
37414 */
37415
37416 +static net_device_ops_no_const apdev_netdev_ops;
37417 +
37418 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37419 {
37420 PSDevice apdev_priv;
37421 struct net_device *dev = pDevice->dev;
37422 int ret;
37423 - const struct net_device_ops apdev_netdev_ops = {
37424 - .ndo_start_xmit = pDevice->tx_80211,
37425 - };
37426
37427 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37428
37429 @@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37430 *apdev_priv = *pDevice;
37431 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37432
37433 + /* only half broken now */
37434 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37435 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37436
37437 pDevice->apdev->type = ARPHRD_IEEE80211;
37438 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37439 index 7843dfd..3db105f 100644
37440 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
37441 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37442 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37443
37444 struct usbctlx_completor {
37445 int (*complete) (struct usbctlx_completor *);
37446 -};
37447 +} __no_const;
37448
37449 static int
37450 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37451 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37452 index 1ca66ea..76f1343 100644
37453 --- a/drivers/staging/zcache/tmem.c
37454 +++ b/drivers/staging/zcache/tmem.c
37455 @@ -39,7 +39,7 @@
37456 * A tmem host implementation must use this function to register callbacks
37457 * for memory allocation.
37458 */
37459 -static struct tmem_hostops tmem_hostops;
37460 +static tmem_hostops_no_const tmem_hostops;
37461
37462 static void tmem_objnode_tree_init(void);
37463
37464 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37465 * A tmem host implementation must use this function to register
37466 * callbacks for a page-accessible memory (PAM) implementation
37467 */
37468 -static struct tmem_pamops tmem_pamops;
37469 +static tmem_pamops_no_const tmem_pamops;
37470
37471 void tmem_register_pamops(struct tmem_pamops *m)
37472 {
37473 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37474 index 0d4aa82..f7832d4 100644
37475 --- a/drivers/staging/zcache/tmem.h
37476 +++ b/drivers/staging/zcache/tmem.h
37477 @@ -180,6 +180,7 @@ struct tmem_pamops {
37478 void (*new_obj)(struct tmem_obj *);
37479 int (*replace_in_obj)(void *, struct tmem_obj *);
37480 };
37481 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37482 extern void tmem_register_pamops(struct tmem_pamops *m);
37483
37484 /* memory allocation methods provided by the host implementation */
37485 @@ -189,6 +190,7 @@ struct tmem_hostops {
37486 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37487 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37488 };
37489 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37490 extern void tmem_register_hostops(struct tmem_hostops *m);
37491
37492 /* core tmem accessor functions */
37493 diff --git a/drivers/target/target_core_cdb.c b/drivers/target/target_core_cdb.c
37494 index 30a6770..fa323f8 100644
37495 --- a/drivers/target/target_core_cdb.c
37496 +++ b/drivers/target/target_core_cdb.c
37497 @@ -1107,7 +1107,7 @@ int target_emulate_write_same(struct se_task *task)
37498 if (num_blocks != 0)
37499 range = num_blocks;
37500 else
37501 - range = (dev->transport->get_blocks(dev) - lba);
37502 + range = (dev->transport->get_blocks(dev) - lba) + 1;
37503
37504 pr_debug("WRITE_SAME UNMAP: LBA: %llu Range: %llu\n",
37505 (unsigned long long)lba, (unsigned long long)range);
37506 diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c
37507 index c3148b1..89d10e6 100644
37508 --- a/drivers/target/target_core_pr.c
37509 +++ b/drivers/target/target_core_pr.c
37510 @@ -2038,7 +2038,7 @@ static int __core_scsi3_write_aptpl_to_file(
37511 if (IS_ERR(file) || !file || !file->f_dentry) {
37512 pr_err("filp_open(%s) for APTPL metadata"
37513 " failed\n", path);
37514 - return (PTR_ERR(file) < 0 ? PTR_ERR(file) : -ENOENT);
37515 + return IS_ERR(file) ? PTR_ERR(file) : -ENOENT;
37516 }
37517
37518 iov[0].iov_base = &buf[0];
37519 @@ -3826,7 +3826,7 @@ int target_scsi3_emulate_pr_out(struct se_task *task)
37520 " SPC-2 reservation is held, returning"
37521 " RESERVATION_CONFLICT\n");
37522 cmd->scsi_sense_reason = TCM_RESERVATION_CONFLICT;
37523 - ret = EINVAL;
37524 + ret = -EINVAL;
37525 goto out;
37526 }
37527
37528 @@ -3836,7 +3836,8 @@ int target_scsi3_emulate_pr_out(struct se_task *task)
37529 */
37530 if (!cmd->se_sess) {
37531 cmd->scsi_sense_reason = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
37532 - return -EINVAL;
37533 + ret = -EINVAL;
37534 + goto out;
37535 }
37536
37537 if (cmd->data_length < 24) {
37538 diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
37539 index f015839..b15dfc4 100644
37540 --- a/drivers/target/target_core_tmr.c
37541 +++ b/drivers/target/target_core_tmr.c
37542 @@ -327,7 +327,7 @@ static void core_tmr_drain_task_list(
37543 cmd->se_tfo->get_task_tag(cmd), cmd->pr_res_key,
37544 cmd->t_task_list_num,
37545 atomic_read(&cmd->t_task_cdbs_left),
37546 - atomic_read(&cmd->t_task_cdbs_sent),
37547 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37548 (cmd->transport_state & CMD_T_ACTIVE) != 0,
37549 (cmd->transport_state & CMD_T_STOP) != 0,
37550 (cmd->transport_state & CMD_T_SENT) != 0);
37551 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37552 index 443704f..92d3517 100644
37553 --- a/drivers/target/target_core_transport.c
37554 +++ b/drivers/target/target_core_transport.c
37555 @@ -1355,7 +1355,7 @@ struct se_device *transport_add_device_to_core_hba(
37556 spin_lock_init(&dev->se_port_lock);
37557 spin_lock_init(&dev->se_tmr_lock);
37558 spin_lock_init(&dev->qf_cmd_lock);
37559 - atomic_set(&dev->dev_ordered_id, 0);
37560 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
37561
37562 se_dev_set_default_attribs(dev, dev_limits);
37563
37564 @@ -1542,7 +1542,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37565 * Used to determine when ORDERED commands should go from
37566 * Dormant to Active status.
37567 */
37568 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37569 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37570 smp_mb__after_atomic_inc();
37571 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37572 cmd->se_ordered_id, cmd->sam_task_attr,
37573 @@ -1956,7 +1956,7 @@ void transport_generic_request_failure(struct se_cmd *cmd)
37574 " CMD_T_ACTIVE: %d CMD_T_STOP: %d CMD_T_SENT: %d\n",
37575 cmd->t_task_list_num,
37576 atomic_read(&cmd->t_task_cdbs_left),
37577 - atomic_read(&cmd->t_task_cdbs_sent),
37578 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37579 atomic_read(&cmd->t_task_cdbs_ex_left),
37580 (cmd->transport_state & CMD_T_ACTIVE) != 0,
37581 (cmd->transport_state & CMD_T_STOP) != 0,
37582 @@ -2216,9 +2216,9 @@ check_depth:
37583 cmd = task->task_se_cmd;
37584 spin_lock_irqsave(&cmd->t_state_lock, flags);
37585 task->task_flags |= (TF_ACTIVE | TF_SENT);
37586 - atomic_inc(&cmd->t_task_cdbs_sent);
37587 + atomic_inc_unchecked(&cmd->t_task_cdbs_sent);
37588
37589 - if (atomic_read(&cmd->t_task_cdbs_sent) ==
37590 + if (atomic_read_unchecked(&cmd->t_task_cdbs_sent) ==
37591 cmd->t_task_list_num)
37592 cmd->transport_state |= CMD_T_SENT;
37593
37594 diff --git a/drivers/target/tcm_fc/tfc_cmd.c b/drivers/target/tcm_fc/tfc_cmd.c
37595 index a375f25..da90f64 100644
37596 --- a/drivers/target/tcm_fc/tfc_cmd.c
37597 +++ b/drivers/target/tcm_fc/tfc_cmd.c
37598 @@ -240,6 +240,8 @@ u32 ft_get_task_tag(struct se_cmd *se_cmd)
37599 {
37600 struct ft_cmd *cmd = container_of(se_cmd, struct ft_cmd, se_cmd);
37601
37602 + if (cmd->aborted)
37603 + return ~0;
37604 return fc_seq_exch(cmd->seq)->rxid;
37605 }
37606
37607 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37608 index 3436436..772237b 100644
37609 --- a/drivers/tty/hvc/hvcs.c
37610 +++ b/drivers/tty/hvc/hvcs.c
37611 @@ -83,6 +83,7 @@
37612 #include <asm/hvcserver.h>
37613 #include <asm/uaccess.h>
37614 #include <asm/vio.h>
37615 +#include <asm/local.h>
37616
37617 /*
37618 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37619 @@ -270,7 +271,7 @@ struct hvcs_struct {
37620 unsigned int index;
37621
37622 struct tty_struct *tty;
37623 - int open_count;
37624 + local_t open_count;
37625
37626 /*
37627 * Used to tell the driver kernel_thread what operations need to take
37628 @@ -422,7 +423,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37629
37630 spin_lock_irqsave(&hvcsd->lock, flags);
37631
37632 - if (hvcsd->open_count > 0) {
37633 + if (local_read(&hvcsd->open_count) > 0) {
37634 spin_unlock_irqrestore(&hvcsd->lock, flags);
37635 printk(KERN_INFO "HVCS: vterm state unchanged. "
37636 "The hvcs device node is still in use.\n");
37637 @@ -1138,7 +1139,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37638 if ((retval = hvcs_partner_connect(hvcsd)))
37639 goto error_release;
37640
37641 - hvcsd->open_count = 1;
37642 + local_set(&hvcsd->open_count, 1);
37643 hvcsd->tty = tty;
37644 tty->driver_data = hvcsd;
37645
37646 @@ -1172,7 +1173,7 @@ fast_open:
37647
37648 spin_lock_irqsave(&hvcsd->lock, flags);
37649 kref_get(&hvcsd->kref);
37650 - hvcsd->open_count++;
37651 + local_inc(&hvcsd->open_count);
37652 hvcsd->todo_mask |= HVCS_SCHED_READ;
37653 spin_unlock_irqrestore(&hvcsd->lock, flags);
37654
37655 @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37656 hvcsd = tty->driver_data;
37657
37658 spin_lock_irqsave(&hvcsd->lock, flags);
37659 - if (--hvcsd->open_count == 0) {
37660 + if (local_dec_and_test(&hvcsd->open_count)) {
37661
37662 vio_disable_interrupts(hvcsd->vdev);
37663
37664 @@ -1242,10 +1243,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37665 free_irq(irq, hvcsd);
37666 kref_put(&hvcsd->kref, destroy_hvcs_struct);
37667 return;
37668 - } else if (hvcsd->open_count < 0) {
37669 + } else if (local_read(&hvcsd->open_count) < 0) {
37670 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37671 " is missmanaged.\n",
37672 - hvcsd->vdev->unit_address, hvcsd->open_count);
37673 + hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
37674 }
37675
37676 spin_unlock_irqrestore(&hvcsd->lock, flags);
37677 @@ -1261,7 +1262,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37678
37679 spin_lock_irqsave(&hvcsd->lock, flags);
37680 /* Preserve this so that we know how many kref refs to put */
37681 - temp_open_count = hvcsd->open_count;
37682 + temp_open_count = local_read(&hvcsd->open_count);
37683
37684 /*
37685 * Don't kref put inside the spinlock because the destruction
37686 @@ -1276,7 +1277,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37687 hvcsd->tty->driver_data = NULL;
37688 hvcsd->tty = NULL;
37689
37690 - hvcsd->open_count = 0;
37691 + local_set(&hvcsd->open_count, 0);
37692
37693 /* This will drop any buffered data on the floor which is OK in a hangup
37694 * scenario. */
37695 @@ -1347,7 +1348,7 @@ static int hvcs_write(struct tty_struct *tty,
37696 * the middle of a write operation? This is a crummy place to do this
37697 * but we want to keep it all in the spinlock.
37698 */
37699 - if (hvcsd->open_count <= 0) {
37700 + if (local_read(&hvcsd->open_count) <= 0) {
37701 spin_unlock_irqrestore(&hvcsd->lock, flags);
37702 return -ENODEV;
37703 }
37704 @@ -1421,7 +1422,7 @@ static int hvcs_write_room(struct tty_struct *tty)
37705 {
37706 struct hvcs_struct *hvcsd = tty->driver_data;
37707
37708 - if (!hvcsd || hvcsd->open_count <= 0)
37709 + if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
37710 return 0;
37711
37712 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
37713 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
37714 index 4daf962..b4a2281 100644
37715 --- a/drivers/tty/ipwireless/tty.c
37716 +++ b/drivers/tty/ipwireless/tty.c
37717 @@ -29,6 +29,7 @@
37718 #include <linux/tty_driver.h>
37719 #include <linux/tty_flip.h>
37720 #include <linux/uaccess.h>
37721 +#include <asm/local.h>
37722
37723 #include "tty.h"
37724 #include "network.h"
37725 @@ -51,7 +52,7 @@ struct ipw_tty {
37726 int tty_type;
37727 struct ipw_network *network;
37728 struct tty_struct *linux_tty;
37729 - int open_count;
37730 + local_t open_count;
37731 unsigned int control_lines;
37732 struct mutex ipw_tty_mutex;
37733 int tx_bytes_queued;
37734 @@ -117,10 +118,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37735 mutex_unlock(&tty->ipw_tty_mutex);
37736 return -ENODEV;
37737 }
37738 - if (tty->open_count == 0)
37739 + if (local_read(&tty->open_count) == 0)
37740 tty->tx_bytes_queued = 0;
37741
37742 - tty->open_count++;
37743 + local_inc(&tty->open_count);
37744
37745 tty->linux_tty = linux_tty;
37746 linux_tty->driver_data = tty;
37747 @@ -136,9 +137,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37748
37749 static void do_ipw_close(struct ipw_tty *tty)
37750 {
37751 - tty->open_count--;
37752 -
37753 - if (tty->open_count == 0) {
37754 + if (local_dec_return(&tty->open_count) == 0) {
37755 struct tty_struct *linux_tty = tty->linux_tty;
37756
37757 if (linux_tty != NULL) {
37758 @@ -159,7 +158,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
37759 return;
37760
37761 mutex_lock(&tty->ipw_tty_mutex);
37762 - if (tty->open_count == 0) {
37763 + if (local_read(&tty->open_count) == 0) {
37764 mutex_unlock(&tty->ipw_tty_mutex);
37765 return;
37766 }
37767 @@ -188,7 +187,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
37768 return;
37769 }
37770
37771 - if (!tty->open_count) {
37772 + if (!local_read(&tty->open_count)) {
37773 mutex_unlock(&tty->ipw_tty_mutex);
37774 return;
37775 }
37776 @@ -230,7 +229,7 @@ static int ipw_write(struct tty_struct *linux_tty,
37777 return -ENODEV;
37778
37779 mutex_lock(&tty->ipw_tty_mutex);
37780 - if (!tty->open_count) {
37781 + if (!local_read(&tty->open_count)) {
37782 mutex_unlock(&tty->ipw_tty_mutex);
37783 return -EINVAL;
37784 }
37785 @@ -270,7 +269,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
37786 if (!tty)
37787 return -ENODEV;
37788
37789 - if (!tty->open_count)
37790 + if (!local_read(&tty->open_count))
37791 return -EINVAL;
37792
37793 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
37794 @@ -312,7 +311,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
37795 if (!tty)
37796 return 0;
37797
37798 - if (!tty->open_count)
37799 + if (!local_read(&tty->open_count))
37800 return 0;
37801
37802 return tty->tx_bytes_queued;
37803 @@ -393,7 +392,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
37804 if (!tty)
37805 return -ENODEV;
37806
37807 - if (!tty->open_count)
37808 + if (!local_read(&tty->open_count))
37809 return -EINVAL;
37810
37811 return get_control_lines(tty);
37812 @@ -409,7 +408,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
37813 if (!tty)
37814 return -ENODEV;
37815
37816 - if (!tty->open_count)
37817 + if (!local_read(&tty->open_count))
37818 return -EINVAL;
37819
37820 return set_control_lines(tty, set, clear);
37821 @@ -423,7 +422,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
37822 if (!tty)
37823 return -ENODEV;
37824
37825 - if (!tty->open_count)
37826 + if (!local_read(&tty->open_count))
37827 return -EINVAL;
37828
37829 /* FIXME: Exactly how is the tty object locked here .. */
37830 @@ -572,7 +571,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
37831 against a parallel ioctl etc */
37832 mutex_lock(&ttyj->ipw_tty_mutex);
37833 }
37834 - while (ttyj->open_count)
37835 + while (local_read(&ttyj->open_count))
37836 do_ipw_close(ttyj);
37837 ipwireless_disassociate_network_ttys(network,
37838 ttyj->channel_idx);
37839 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
37840 index c43b683..0a88f1c 100644
37841 --- a/drivers/tty/n_gsm.c
37842 +++ b/drivers/tty/n_gsm.c
37843 @@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
37844 kref_init(&dlci->ref);
37845 mutex_init(&dlci->mutex);
37846 dlci->fifo = &dlci->_fifo;
37847 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
37848 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
37849 kfree(dlci);
37850 return NULL;
37851 }
37852 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
37853 index 94b6eda..15f7cec 100644
37854 --- a/drivers/tty/n_tty.c
37855 +++ b/drivers/tty/n_tty.c
37856 @@ -2122,6 +2122,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
37857 {
37858 *ops = tty_ldisc_N_TTY;
37859 ops->owner = NULL;
37860 - ops->refcount = ops->flags = 0;
37861 + atomic_set(&ops->refcount, 0);
37862 + ops->flags = 0;
37863 }
37864 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
37865 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
37866 index eeae7fa..177a743 100644
37867 --- a/drivers/tty/pty.c
37868 +++ b/drivers/tty/pty.c
37869 @@ -707,8 +707,10 @@ static void __init unix98_pty_init(void)
37870 panic("Couldn't register Unix98 pts driver");
37871
37872 /* Now create the /dev/ptmx special device */
37873 + pax_open_kernel();
37874 tty_default_fops(&ptmx_fops);
37875 - ptmx_fops.open = ptmx_open;
37876 + *(void **)&ptmx_fops.open = ptmx_open;
37877 + pax_close_kernel();
37878
37879 cdev_init(&ptmx_cdev, &ptmx_fops);
37880 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
37881 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
37882 index 2b42a01..32a2ed3 100644
37883 --- a/drivers/tty/serial/kgdboc.c
37884 +++ b/drivers/tty/serial/kgdboc.c
37885 @@ -24,8 +24,9 @@
37886 #define MAX_CONFIG_LEN 40
37887
37888 static struct kgdb_io kgdboc_io_ops;
37889 +static struct kgdb_io kgdboc_io_ops_console;
37890
37891 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
37892 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
37893 static int configured = -1;
37894
37895 static char config[MAX_CONFIG_LEN];
37896 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
37897 kgdboc_unregister_kbd();
37898 if (configured == 1)
37899 kgdb_unregister_io_module(&kgdboc_io_ops);
37900 + else if (configured == 2)
37901 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
37902 }
37903
37904 static int configure_kgdboc(void)
37905 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
37906 int err;
37907 char *cptr = config;
37908 struct console *cons;
37909 + int is_console = 0;
37910
37911 err = kgdboc_option_setup(config);
37912 if (err || !strlen(config) || isspace(config[0]))
37913 goto noconfig;
37914
37915 err = -ENODEV;
37916 - kgdboc_io_ops.is_console = 0;
37917 kgdb_tty_driver = NULL;
37918
37919 kgdboc_use_kms = 0;
37920 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
37921 int idx;
37922 if (cons->device && cons->device(cons, &idx) == p &&
37923 idx == tty_line) {
37924 - kgdboc_io_ops.is_console = 1;
37925 + is_console = 1;
37926 break;
37927 }
37928 cons = cons->next;
37929 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
37930 kgdb_tty_line = tty_line;
37931
37932 do_register:
37933 - err = kgdb_register_io_module(&kgdboc_io_ops);
37934 + if (is_console) {
37935 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
37936 + configured = 2;
37937 + } else {
37938 + err = kgdb_register_io_module(&kgdboc_io_ops);
37939 + configured = 1;
37940 + }
37941 if (err)
37942 goto noconfig;
37943
37944 - configured = 1;
37945 -
37946 return 0;
37947
37948 noconfig:
37949 @@ -213,7 +220,7 @@ noconfig:
37950 static int __init init_kgdboc(void)
37951 {
37952 /* Already configured? */
37953 - if (configured == 1)
37954 + if (configured >= 1)
37955 return 0;
37956
37957 return configure_kgdboc();
37958 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
37959 if (config[len - 1] == '\n')
37960 config[len - 1] = '\0';
37961
37962 - if (configured == 1)
37963 + if (configured >= 1)
37964 cleanup_kgdboc();
37965
37966 /* Go and configure with the new params. */
37967 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
37968 .post_exception = kgdboc_post_exp_handler,
37969 };
37970
37971 +static struct kgdb_io kgdboc_io_ops_console = {
37972 + .name = "kgdboc",
37973 + .read_char = kgdboc_get_char,
37974 + .write_char = kgdboc_put_char,
37975 + .pre_exception = kgdboc_pre_exp_handler,
37976 + .post_exception = kgdboc_post_exp_handler,
37977 + .is_console = 1
37978 +};
37979 +
37980 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
37981 /* This is only available if kgdboc is a built in for early debugging */
37982 static int __init kgdboc_early_init(char *opt)
37983 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
37984 index 05728894..b9d44c6 100644
37985 --- a/drivers/tty/sysrq.c
37986 +++ b/drivers/tty/sysrq.c
37987 @@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
37988 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
37989 size_t count, loff_t *ppos)
37990 {
37991 - if (count) {
37992 + if (count && capable(CAP_SYS_ADMIN)) {
37993 char c;
37994
37995 if (get_user(c, buf))
37996 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
37997 index d939bd7..33d92cd 100644
37998 --- a/drivers/tty/tty_io.c
37999 +++ b/drivers/tty/tty_io.c
38000 @@ -3278,7 +3278,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38001
38002 void tty_default_fops(struct file_operations *fops)
38003 {
38004 - *fops = tty_fops;
38005 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38006 }
38007
38008 /*
38009 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38010 index 24b95db..9c078d0 100644
38011 --- a/drivers/tty/tty_ldisc.c
38012 +++ b/drivers/tty/tty_ldisc.c
38013 @@ -57,7 +57,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38014 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38015 struct tty_ldisc_ops *ldo = ld->ops;
38016
38017 - ldo->refcount--;
38018 + atomic_dec(&ldo->refcount);
38019 module_put(ldo->owner);
38020 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38021
38022 @@ -92,7 +92,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38023 spin_lock_irqsave(&tty_ldisc_lock, flags);
38024 tty_ldiscs[disc] = new_ldisc;
38025 new_ldisc->num = disc;
38026 - new_ldisc->refcount = 0;
38027 + atomic_set(&new_ldisc->refcount, 0);
38028 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38029
38030 return ret;
38031 @@ -120,7 +120,7 @@ int tty_unregister_ldisc(int disc)
38032 return -EINVAL;
38033
38034 spin_lock_irqsave(&tty_ldisc_lock, flags);
38035 - if (tty_ldiscs[disc]->refcount)
38036 + if (atomic_read(&tty_ldiscs[disc]->refcount))
38037 ret = -EBUSY;
38038 else
38039 tty_ldiscs[disc] = NULL;
38040 @@ -141,7 +141,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38041 if (ldops) {
38042 ret = ERR_PTR(-EAGAIN);
38043 if (try_module_get(ldops->owner)) {
38044 - ldops->refcount++;
38045 + atomic_inc(&ldops->refcount);
38046 ret = ldops;
38047 }
38048 }
38049 @@ -154,7 +154,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38050 unsigned long flags;
38051
38052 spin_lock_irqsave(&tty_ldisc_lock, flags);
38053 - ldops->refcount--;
38054 + atomic_dec(&ldops->refcount);
38055 module_put(ldops->owner);
38056 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38057 }
38058 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
38059 index 3b0c4e3..f98a992 100644
38060 --- a/drivers/tty/vt/keyboard.c
38061 +++ b/drivers/tty/vt/keyboard.c
38062 @@ -663,6 +663,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
38063 kbd->kbdmode == VC_OFF) &&
38064 value != KVAL(K_SAK))
38065 return; /* SAK is allowed even in raw mode */
38066 +
38067 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
38068 + {
38069 + void *func = fn_handler[value];
38070 + if (func == fn_show_state || func == fn_show_ptregs ||
38071 + func == fn_show_mem)
38072 + return;
38073 + }
38074 +#endif
38075 +
38076 fn_handler[value](vc);
38077 }
38078
38079 @@ -1812,9 +1822,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38080 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
38081 return -EFAULT;
38082
38083 - if (!capable(CAP_SYS_TTY_CONFIG))
38084 - perm = 0;
38085 -
38086 switch (cmd) {
38087 case KDGKBENT:
38088 /* Ensure another thread doesn't free it under us */
38089 @@ -1829,6 +1836,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38090 spin_unlock_irqrestore(&kbd_event_lock, flags);
38091 return put_user(val, &user_kbe->kb_value);
38092 case KDSKBENT:
38093 + if (!capable(CAP_SYS_TTY_CONFIG))
38094 + perm = 0;
38095 +
38096 if (!perm)
38097 return -EPERM;
38098 if (!i && v == K_NOSUCHMAP) {
38099 @@ -1919,9 +1929,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38100 int i, j, k;
38101 int ret;
38102
38103 - if (!capable(CAP_SYS_TTY_CONFIG))
38104 - perm = 0;
38105 -
38106 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
38107 if (!kbs) {
38108 ret = -ENOMEM;
38109 @@ -1955,6 +1962,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38110 kfree(kbs);
38111 return ((p && *p) ? -EOVERFLOW : 0);
38112 case KDSKBSENT:
38113 + if (!capable(CAP_SYS_TTY_CONFIG))
38114 + perm = 0;
38115 +
38116 if (!perm) {
38117 ret = -EPERM;
38118 goto reterr;
38119 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
38120 index a783d53..cb30d94 100644
38121 --- a/drivers/uio/uio.c
38122 +++ b/drivers/uio/uio.c
38123 @@ -25,6 +25,7 @@
38124 #include <linux/kobject.h>
38125 #include <linux/cdev.h>
38126 #include <linux/uio_driver.h>
38127 +#include <asm/local.h>
38128
38129 #define UIO_MAX_DEVICES (1U << MINORBITS)
38130
38131 @@ -32,10 +33,10 @@ struct uio_device {
38132 struct module *owner;
38133 struct device *dev;
38134 int minor;
38135 - atomic_t event;
38136 + atomic_unchecked_t event;
38137 struct fasync_struct *async_queue;
38138 wait_queue_head_t wait;
38139 - int vma_count;
38140 + local_t vma_count;
38141 struct uio_info *info;
38142 struct kobject *map_dir;
38143 struct kobject *portio_dir;
38144 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
38145 struct device_attribute *attr, char *buf)
38146 {
38147 struct uio_device *idev = dev_get_drvdata(dev);
38148 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
38149 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
38150 }
38151
38152 static struct device_attribute uio_class_attributes[] = {
38153 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
38154 {
38155 struct uio_device *idev = info->uio_dev;
38156
38157 - atomic_inc(&idev->event);
38158 + atomic_inc_unchecked(&idev->event);
38159 wake_up_interruptible(&idev->wait);
38160 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
38161 }
38162 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
38163 }
38164
38165 listener->dev = idev;
38166 - listener->event_count = atomic_read(&idev->event);
38167 + listener->event_count = atomic_read_unchecked(&idev->event);
38168 filep->private_data = listener;
38169
38170 if (idev->info->open) {
38171 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
38172 return -EIO;
38173
38174 poll_wait(filep, &idev->wait, wait);
38175 - if (listener->event_count != atomic_read(&idev->event))
38176 + if (listener->event_count != atomic_read_unchecked(&idev->event))
38177 return POLLIN | POLLRDNORM;
38178 return 0;
38179 }
38180 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
38181 do {
38182 set_current_state(TASK_INTERRUPTIBLE);
38183
38184 - event_count = atomic_read(&idev->event);
38185 + event_count = atomic_read_unchecked(&idev->event);
38186 if (event_count != listener->event_count) {
38187 if (copy_to_user(buf, &event_count, count))
38188 retval = -EFAULT;
38189 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
38190 static void uio_vma_open(struct vm_area_struct *vma)
38191 {
38192 struct uio_device *idev = vma->vm_private_data;
38193 - idev->vma_count++;
38194 + local_inc(&idev->vma_count);
38195 }
38196
38197 static void uio_vma_close(struct vm_area_struct *vma)
38198 {
38199 struct uio_device *idev = vma->vm_private_data;
38200 - idev->vma_count--;
38201 + local_dec(&idev->vma_count);
38202 }
38203
38204 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38205 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
38206 idev->owner = owner;
38207 idev->info = info;
38208 init_waitqueue_head(&idev->wait);
38209 - atomic_set(&idev->event, 0);
38210 + atomic_set_unchecked(&idev->event, 0);
38211
38212 ret = uio_get_minor(idev);
38213 if (ret)
38214 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
38215 index 98b89fe..aff824e 100644
38216 --- a/drivers/usb/atm/cxacru.c
38217 +++ b/drivers/usb/atm/cxacru.c
38218 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
38219 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
38220 if (ret < 2)
38221 return -EINVAL;
38222 - if (index < 0 || index > 0x7f)
38223 + if (index > 0x7f)
38224 return -EINVAL;
38225 pos += tmp;
38226
38227 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
38228 index d3448ca..d2864ca 100644
38229 --- a/drivers/usb/atm/usbatm.c
38230 +++ b/drivers/usb/atm/usbatm.c
38231 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38232 if (printk_ratelimit())
38233 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
38234 __func__, vpi, vci);
38235 - atomic_inc(&vcc->stats->rx_err);
38236 + atomic_inc_unchecked(&vcc->stats->rx_err);
38237 return;
38238 }
38239
38240 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38241 if (length > ATM_MAX_AAL5_PDU) {
38242 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
38243 __func__, length, vcc);
38244 - atomic_inc(&vcc->stats->rx_err);
38245 + atomic_inc_unchecked(&vcc->stats->rx_err);
38246 goto out;
38247 }
38248
38249 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38250 if (sarb->len < pdu_length) {
38251 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
38252 __func__, pdu_length, sarb->len, vcc);
38253 - atomic_inc(&vcc->stats->rx_err);
38254 + atomic_inc_unchecked(&vcc->stats->rx_err);
38255 goto out;
38256 }
38257
38258 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
38259 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
38260 __func__, vcc);
38261 - atomic_inc(&vcc->stats->rx_err);
38262 + atomic_inc_unchecked(&vcc->stats->rx_err);
38263 goto out;
38264 }
38265
38266 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38267 if (printk_ratelimit())
38268 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
38269 __func__, length);
38270 - atomic_inc(&vcc->stats->rx_drop);
38271 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38272 goto out;
38273 }
38274
38275 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38276
38277 vcc->push(vcc, skb);
38278
38279 - atomic_inc(&vcc->stats->rx);
38280 + atomic_inc_unchecked(&vcc->stats->rx);
38281 out:
38282 skb_trim(sarb, 0);
38283 }
38284 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
38285 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
38286
38287 usbatm_pop(vcc, skb);
38288 - atomic_inc(&vcc->stats->tx);
38289 + atomic_inc_unchecked(&vcc->stats->tx);
38290
38291 skb = skb_dequeue(&instance->sndqueue);
38292 }
38293 @@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
38294 if (!left--)
38295 return sprintf(page,
38296 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
38297 - atomic_read(&atm_dev->stats.aal5.tx),
38298 - atomic_read(&atm_dev->stats.aal5.tx_err),
38299 - atomic_read(&atm_dev->stats.aal5.rx),
38300 - atomic_read(&atm_dev->stats.aal5.rx_err),
38301 - atomic_read(&atm_dev->stats.aal5.rx_drop));
38302 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
38303 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
38304 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
38305 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
38306 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
38307
38308 if (!left--) {
38309 if (instance->disconnected)
38310 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
38311 index d956965..4179a77 100644
38312 --- a/drivers/usb/core/devices.c
38313 +++ b/drivers/usb/core/devices.c
38314 @@ -126,7 +126,7 @@ static const char format_endpt[] =
38315 * time it gets called.
38316 */
38317 static struct device_connect_event {
38318 - atomic_t count;
38319 + atomic_unchecked_t count;
38320 wait_queue_head_t wait;
38321 } device_event = {
38322 .count = ATOMIC_INIT(1),
38323 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
38324
38325 void usbfs_conn_disc_event(void)
38326 {
38327 - atomic_add(2, &device_event.count);
38328 + atomic_add_unchecked(2, &device_event.count);
38329 wake_up(&device_event.wait);
38330 }
38331
38332 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
38333
38334 poll_wait(file, &device_event.wait, wait);
38335
38336 - event_count = atomic_read(&device_event.count);
38337 + event_count = atomic_read_unchecked(&device_event.count);
38338 if (file->f_version != event_count) {
38339 file->f_version = event_count;
38340 return POLLIN | POLLRDNORM;
38341 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
38342 index 1fc8f12..20647c1 100644
38343 --- a/drivers/usb/early/ehci-dbgp.c
38344 +++ b/drivers/usb/early/ehci-dbgp.c
38345 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
38346
38347 #ifdef CONFIG_KGDB
38348 static struct kgdb_io kgdbdbgp_io_ops;
38349 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
38350 +static struct kgdb_io kgdbdbgp_io_ops_console;
38351 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
38352 #else
38353 #define dbgp_kgdb_mode (0)
38354 #endif
38355 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
38356 .write_char = kgdbdbgp_write_char,
38357 };
38358
38359 +static struct kgdb_io kgdbdbgp_io_ops_console = {
38360 + .name = "kgdbdbgp",
38361 + .read_char = kgdbdbgp_read_char,
38362 + .write_char = kgdbdbgp_write_char,
38363 + .is_console = 1
38364 +};
38365 +
38366 static int kgdbdbgp_wait_time;
38367
38368 static int __init kgdbdbgp_parse_config(char *str)
38369 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
38370 ptr++;
38371 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
38372 }
38373 - kgdb_register_io_module(&kgdbdbgp_io_ops);
38374 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
38375 + if (early_dbgp_console.index != -1)
38376 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
38377 + else
38378 + kgdb_register_io_module(&kgdbdbgp_io_ops);
38379
38380 return 0;
38381 }
38382 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
38383 index d6bea3e..60b250e 100644
38384 --- a/drivers/usb/wusbcore/wa-hc.h
38385 +++ b/drivers/usb/wusbcore/wa-hc.h
38386 @@ -192,7 +192,7 @@ struct wahc {
38387 struct list_head xfer_delayed_list;
38388 spinlock_t xfer_list_lock;
38389 struct work_struct xfer_work;
38390 - atomic_t xfer_id_count;
38391 + atomic_unchecked_t xfer_id_count;
38392 };
38393
38394
38395 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
38396 INIT_LIST_HEAD(&wa->xfer_delayed_list);
38397 spin_lock_init(&wa->xfer_list_lock);
38398 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
38399 - atomic_set(&wa->xfer_id_count, 1);
38400 + atomic_set_unchecked(&wa->xfer_id_count, 1);
38401 }
38402
38403 /**
38404 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
38405 index 57c01ab..8a05959 100644
38406 --- a/drivers/usb/wusbcore/wa-xfer.c
38407 +++ b/drivers/usb/wusbcore/wa-xfer.c
38408 @@ -296,7 +296,7 @@ out:
38409 */
38410 static void wa_xfer_id_init(struct wa_xfer *xfer)
38411 {
38412 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
38413 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
38414 }
38415
38416 /*
38417 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
38418 index 51e4c1e..9d87e2a 100644
38419 --- a/drivers/vhost/vhost.c
38420 +++ b/drivers/vhost/vhost.c
38421 @@ -632,7 +632,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
38422 return 0;
38423 }
38424
38425 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
38426 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
38427 {
38428 struct file *eventfp, *filep = NULL,
38429 *pollstart = NULL, *pollstop = NULL;
38430 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
38431 index b0b2ac3..89a4399 100644
38432 --- a/drivers/video/aty/aty128fb.c
38433 +++ b/drivers/video/aty/aty128fb.c
38434 @@ -148,7 +148,7 @@ enum {
38435 };
38436
38437 /* Must match above enum */
38438 -static const char *r128_family[] __devinitdata = {
38439 +static const char *r128_family[] __devinitconst = {
38440 "AGP",
38441 "PCI",
38442 "PRO AGP",
38443 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
38444 index 5c3960d..15cf8fc 100644
38445 --- a/drivers/video/fbcmap.c
38446 +++ b/drivers/video/fbcmap.c
38447 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
38448 rc = -ENODEV;
38449 goto out;
38450 }
38451 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
38452 - !info->fbops->fb_setcmap)) {
38453 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
38454 rc = -EINVAL;
38455 goto out1;
38456 }
38457 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
38458 index c6ce416..3b9b642 100644
38459 --- a/drivers/video/fbmem.c
38460 +++ b/drivers/video/fbmem.c
38461 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38462 image->dx += image->width + 8;
38463 }
38464 } else if (rotate == FB_ROTATE_UD) {
38465 - for (x = 0; x < num && image->dx >= 0; x++) {
38466 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
38467 info->fbops->fb_imageblit(info, image);
38468 image->dx -= image->width + 8;
38469 }
38470 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38471 image->dy += image->height + 8;
38472 }
38473 } else if (rotate == FB_ROTATE_CCW) {
38474 - for (x = 0; x < num && image->dy >= 0; x++) {
38475 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
38476 info->fbops->fb_imageblit(info, image);
38477 image->dy -= image->height + 8;
38478 }
38479 @@ -1157,7 +1157,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
38480 return -EFAULT;
38481 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
38482 return -EINVAL;
38483 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
38484 + if (con2fb.framebuffer >= FB_MAX)
38485 return -EINVAL;
38486 if (!registered_fb[con2fb.framebuffer])
38487 request_module("fb%d", con2fb.framebuffer);
38488 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
38489 index 5a5d092..265c5ed 100644
38490 --- a/drivers/video/geode/gx1fb_core.c
38491 +++ b/drivers/video/geode/gx1fb_core.c
38492 @@ -29,7 +29,7 @@ static int crt_option = 1;
38493 static char panel_option[32] = "";
38494
38495 /* Modes relevant to the GX1 (taken from modedb.c) */
38496 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
38497 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
38498 /* 640x480-60 VESA */
38499 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
38500 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
38501 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
38502 index 0fad23f..0e9afa4 100644
38503 --- a/drivers/video/gxt4500.c
38504 +++ b/drivers/video/gxt4500.c
38505 @@ -156,7 +156,7 @@ struct gxt4500_par {
38506 static char *mode_option;
38507
38508 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
38509 -static const struct fb_videomode defaultmode __devinitdata = {
38510 +static const struct fb_videomode defaultmode __devinitconst = {
38511 .refresh = 60,
38512 .xres = 1280,
38513 .yres = 1024,
38514 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
38515 return 0;
38516 }
38517
38518 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
38519 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
38520 .id = "IBM GXT4500P",
38521 .type = FB_TYPE_PACKED_PIXELS,
38522 .visual = FB_VISUAL_PSEUDOCOLOR,
38523 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
38524 index 7672d2e..b56437f 100644
38525 --- a/drivers/video/i810/i810_accel.c
38526 +++ b/drivers/video/i810/i810_accel.c
38527 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
38528 }
38529 }
38530 printk("ringbuffer lockup!!!\n");
38531 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
38532 i810_report_error(mmio);
38533 par->dev_flags |= LOCKUP;
38534 info->pixmap.scan_align = 1;
38535 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
38536 index b83f361..2b05a91 100644
38537 --- a/drivers/video/i810/i810_main.c
38538 +++ b/drivers/video/i810/i810_main.c
38539 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
38540 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
38541
38542 /* PCI */
38543 -static const char *i810_pci_list[] __devinitdata = {
38544 +static const char *i810_pci_list[] __devinitconst = {
38545 "Intel(R) 810 Framebuffer Device" ,
38546 "Intel(R) 810-DC100 Framebuffer Device" ,
38547 "Intel(R) 810E Framebuffer Device" ,
38548 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
38549 index de36693..3c63fc2 100644
38550 --- a/drivers/video/jz4740_fb.c
38551 +++ b/drivers/video/jz4740_fb.c
38552 @@ -136,7 +136,7 @@ struct jzfb {
38553 uint32_t pseudo_palette[16];
38554 };
38555
38556 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
38557 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
38558 .id = "JZ4740 FB",
38559 .type = FB_TYPE_PACKED_PIXELS,
38560 .visual = FB_VISUAL_TRUECOLOR,
38561 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
38562 index 3c14e43..eafa544 100644
38563 --- a/drivers/video/logo/logo_linux_clut224.ppm
38564 +++ b/drivers/video/logo/logo_linux_clut224.ppm
38565 @@ -1,1604 +1,1123 @@
38566 P3
38567 -# Standard 224-color Linux logo
38568 80 80
38569 255
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 - 0 0 0 0 0 0 0 0 0 0 0 0
38575 - 0 0 0 0 0 0 0 0 0 0 0 0
38576 - 0 0 0 0 0 0 0 0 0 0 0 0
38577 - 0 0 0 0 0 0 0 0 0 0 0 0
38578 - 0 0 0 0 0 0 0 0 0 0 0 0
38579 - 6 6 6 6 6 6 10 10 10 10 10 10
38580 - 10 10 10 6 6 6 6 6 6 6 6 6
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 0 0 0
38594 - 0 0 0 0 0 0 0 0 0 0 0 0
38595 - 0 0 0 0 0 0 0 0 0 0 0 0
38596 - 0 0 0 0 0 0 0 0 0 0 0 0
38597 - 0 0 0 0 0 0 0 0 0 0 0 0
38598 - 0 0 0 6 6 6 10 10 10 14 14 14
38599 - 22 22 22 26 26 26 30 30 30 34 34 34
38600 - 30 30 30 30 30 30 26 26 26 18 18 18
38601 - 14 14 14 10 10 10 6 6 6 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 0 0 0 0 0 0 0
38609 - 0 0 0 0 0 0 0 0 0 0 0 0
38610 - 0 0 0 0 0 0 0 0 0 0 0 0
38611 - 0 0 0 0 0 1 0 0 1 0 0 0
38612 - 0 0 0 0 0 0 0 0 0 0 0 0
38613 - 0 0 0 0 0 0 0 0 0 0 0 0
38614 - 0 0 0 0 0 0 0 0 0 0 0 0
38615 - 0 0 0 0 0 0 0 0 0 0 0 0
38616 - 0 0 0 0 0 0 0 0 0 0 0 0
38617 - 0 0 0 0 0 0 0 0 0 0 0 0
38618 - 6 6 6 14 14 14 26 26 26 42 42 42
38619 - 54 54 54 66 66 66 78 78 78 78 78 78
38620 - 78 78 78 74 74 74 66 66 66 54 54 54
38621 - 42 42 42 26 26 26 18 18 18 10 10 10
38622 - 6 6 6 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 0 0 0 0 0 0 0 0 0 0
38629 - 0 0 0 0 0 0 0 0 0 0 0 0
38630 - 0 0 0 0 0 0 0 0 0 0 0 0
38631 - 0 0 1 0 0 0 0 0 0 0 0 0
38632 - 0 0 0 0 0 0 0 0 0 0 0 0
38633 - 0 0 0 0 0 0 0 0 0 0 0 0
38634 - 0 0 0 0 0 0 0 0 0 0 0 0
38635 - 0 0 0 0 0 0 0 0 0 0 0 0
38636 - 0 0 0 0 0 0 0 0 0 0 0 0
38637 - 0 0 0 0 0 0 0 0 0 10 10 10
38638 - 22 22 22 42 42 42 66 66 66 86 86 86
38639 - 66 66 66 38 38 38 38 38 38 22 22 22
38640 - 26 26 26 34 34 34 54 54 54 66 66 66
38641 - 86 86 86 70 70 70 46 46 46 26 26 26
38642 - 14 14 14 6 6 6 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 0 0 0 0 0 0 0
38649 - 0 0 0 0 0 0 0 0 0 0 0 0
38650 - 0 0 0 0 0 0 0 0 0 0 0 0
38651 - 0 0 1 0 0 1 0 0 1 0 0 0
38652 - 0 0 0 0 0 0 0 0 0 0 0 0
38653 - 0 0 0 0 0 0 0 0 0 0 0 0
38654 - 0 0 0 0 0 0 0 0 0 0 0 0
38655 - 0 0 0 0 0 0 0 0 0 0 0 0
38656 - 0 0 0 0 0 0 0 0 0 0 0 0
38657 - 0 0 0 0 0 0 10 10 10 26 26 26
38658 - 50 50 50 82 82 82 58 58 58 6 6 6
38659 - 2 2 6 2 2 6 2 2 6 2 2 6
38660 - 2 2 6 2 2 6 2 2 6 2 2 6
38661 - 6 6 6 54 54 54 86 86 86 66 66 66
38662 - 38 38 38 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0 0
38669 - 0 0 0 0 0 0 0 0 0 0 0 0
38670 - 0 0 0 0 0 0 0 0 0 0 0 0
38671 - 0 0 0 0 0 0 0 0 0 0 0 0
38672 - 0 0 0 0 0 0 0 0 0 0 0 0
38673 - 0 0 0 0 0 0 0 0 0 0 0 0
38674 - 0 0 0 0 0 0 0 0 0 0 0 0
38675 - 0 0 0 0 0 0 0 0 0 0 0 0
38676 - 0 0 0 0 0 0 0 0 0 0 0 0
38677 - 0 0 0 6 6 6 22 22 22 50 50 50
38678 - 78 78 78 34 34 34 2 2 6 2 2 6
38679 - 2 2 6 2 2 6 2 2 6 2 2 6
38680 - 2 2 6 2 2 6 2 2 6 2 2 6
38681 - 2 2 6 2 2 6 6 6 6 70 70 70
38682 - 78 78 78 46 46 46 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0 0
38689 - 0 0 0 0 0 0 0 0 0 0 0 0
38690 - 0 0 0 0 0 0 0 0 0 0 0 0
38691 - 0 0 1 0 0 1 0 0 1 0 0 0
38692 - 0 0 0 0 0 0 0 0 0 0 0 0
38693 - 0 0 0 0 0 0 0 0 0 0 0 0
38694 - 0 0 0 0 0 0 0 0 0 0 0 0
38695 - 0 0 0 0 0 0 0 0 0 0 0 0
38696 - 0 0 0 0 0 0 0 0 0 0 0 0
38697 - 6 6 6 18 18 18 42 42 42 82 82 82
38698 - 26 26 26 2 2 6 2 2 6 2 2 6
38699 - 2 2 6 2 2 6 2 2 6 2 2 6
38700 - 2 2 6 2 2 6 2 2 6 14 14 14
38701 - 46 46 46 34 34 34 6 6 6 2 2 6
38702 - 42 42 42 78 78 78 42 42 42 18 18 18
38703 - 6 6 6 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 1 0 0 0 0 0 1 0 0 0
38712 - 0 0 0 0 0 0 0 0 0 0 0 0
38713 - 0 0 0 0 0 0 0 0 0 0 0 0
38714 - 0 0 0 0 0 0 0 0 0 0 0 0
38715 - 0 0 0 0 0 0 0 0 0 0 0 0
38716 - 0 0 0 0 0 0 0 0 0 0 0 0
38717 - 10 10 10 30 30 30 66 66 66 58 58 58
38718 - 2 2 6 2 2 6 2 2 6 2 2 6
38719 - 2 2 6 2 2 6 2 2 6 2 2 6
38720 - 2 2 6 2 2 6 2 2 6 26 26 26
38721 - 86 86 86 101 101 101 46 46 46 10 10 10
38722 - 2 2 6 58 58 58 70 70 70 34 34 34
38723 - 10 10 10 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 0 0 0 0
38728 - 0 0 0 0 0 0 0 0 0 0 0 0
38729 - 0 0 0 0 0 0 0 0 0 0 0 0
38730 - 0 0 0 0 0 0 0 0 0 0 0 0
38731 - 0 0 1 0 0 1 0 0 1 0 0 0
38732 - 0 0 0 0 0 0 0 0 0 0 0 0
38733 - 0 0 0 0 0 0 0 0 0 0 0 0
38734 - 0 0 0 0 0 0 0 0 0 0 0 0
38735 - 0 0 0 0 0 0 0 0 0 0 0 0
38736 - 0 0 0 0 0 0 0 0 0 0 0 0
38737 - 14 14 14 42 42 42 86 86 86 10 10 10
38738 - 2 2 6 2 2 6 2 2 6 2 2 6
38739 - 2 2 6 2 2 6 2 2 6 2 2 6
38740 - 2 2 6 2 2 6 2 2 6 30 30 30
38741 - 94 94 94 94 94 94 58 58 58 26 26 26
38742 - 2 2 6 6 6 6 78 78 78 54 54 54
38743 - 22 22 22 6 6 6 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 0 0 0
38754 - 0 0 0 0 0 0 0 0 0 0 0 0
38755 - 0 0 0 0 0 0 0 0 0 0 0 0
38756 - 0 0 0 0 0 0 0 0 0 6 6 6
38757 - 22 22 22 62 62 62 62 62 62 2 2 6
38758 - 2 2 6 2 2 6 2 2 6 2 2 6
38759 - 2 2 6 2 2 6 2 2 6 2 2 6
38760 - 2 2 6 2 2 6 2 2 6 26 26 26
38761 - 54 54 54 38 38 38 18 18 18 10 10 10
38762 - 2 2 6 2 2 6 34 34 34 82 82 82
38763 - 38 38 38 14 14 14 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 0 0 0 0
38768 - 0 0 0 0 0 0 0 0 0 0 0 0
38769 - 0 0 0 0 0 0 0 0 0 0 0 0
38770 - 0 0 0 0 0 0 0 0 0 0 0 0
38771 - 0 0 0 0 0 1 0 0 1 0 0 0
38772 - 0 0 0 0 0 0 0 0 0 0 0 0
38773 - 0 0 0 0 0 0 0 0 0 0 0 0
38774 - 0 0 0 0 0 0 0 0 0 0 0 0
38775 - 0 0 0 0 0 0 0 0 0 0 0 0
38776 - 0 0 0 0 0 0 0 0 0 6 6 6
38777 - 30 30 30 78 78 78 30 30 30 2 2 6
38778 - 2 2 6 2 2 6 2 2 6 2 2 6
38779 - 2 2 6 2 2 6 2 2 6 2 2 6
38780 - 2 2 6 2 2 6 2 2 6 10 10 10
38781 - 10 10 10 2 2 6 2 2 6 2 2 6
38782 - 2 2 6 2 2 6 2 2 6 78 78 78
38783 - 50 50 50 18 18 18 6 6 6 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 0 0 0 0
38788 - 0 0 0 0 0 0 0 0 0 0 0 0
38789 - 0 0 0 0 0 0 0 0 0 0 0 0
38790 - 0 0 0 0 0 0 0 0 0 0 0 0
38791 - 0 0 1 0 0 0 0 0 0 0 0 0
38792 - 0 0 0 0 0 0 0 0 0 0 0 0
38793 - 0 0 0 0 0 0 0 0 0 0 0 0
38794 - 0 0 0 0 0 0 0 0 0 0 0 0
38795 - 0 0 0 0 0 0 0 0 0 0 0 0
38796 - 0 0 0 0 0 0 0 0 0 10 10 10
38797 - 38 38 38 86 86 86 14 14 14 2 2 6
38798 - 2 2 6 2 2 6 2 2 6 2 2 6
38799 - 2 2 6 2 2 6 2 2 6 2 2 6
38800 - 2 2 6 2 2 6 2 2 6 2 2 6
38801 - 2 2 6 2 2 6 2 2 6 2 2 6
38802 - 2 2 6 2 2 6 2 2 6 54 54 54
38803 - 66 66 66 26 26 26 6 6 6 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 0 0 0 0
38808 - 0 0 0 0 0 0 0 0 0 0 0 0
38809 - 0 0 0 0 0 0 0 0 0 0 0 0
38810 - 0 0 0 0 0 0 0 0 0 0 0 0
38811 - 0 0 0 0 0 1 0 0 1 0 0 0
38812 - 0 0 0 0 0 0 0 0 0 0 0 0
38813 - 0 0 0 0 0 0 0 0 0 0 0 0
38814 - 0 0 0 0 0 0 0 0 0 0 0 0
38815 - 0 0 0 0 0 0 0 0 0 0 0 0
38816 - 0 0 0 0 0 0 0 0 0 14 14 14
38817 - 42 42 42 82 82 82 2 2 6 2 2 6
38818 - 2 2 6 6 6 6 10 10 10 2 2 6
38819 - 2 2 6 2 2 6 2 2 6 2 2 6
38820 - 2 2 6 2 2 6 2 2 6 6 6 6
38821 - 14 14 14 10 10 10 2 2 6 2 2 6
38822 - 2 2 6 2 2 6 2 2 6 18 18 18
38823 - 82 82 82 34 34 34 10 10 10 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 1 0 0 0 0 0 0 0 0 0
38832 - 0 0 0 0 0 0 0 0 0 0 0 0
38833 - 0 0 0 0 0 0 0 0 0 0 0 0
38834 - 0 0 0 0 0 0 0 0 0 0 0 0
38835 - 0 0 0 0 0 0 0 0 0 0 0 0
38836 - 0 0 0 0 0 0 0 0 0 14 14 14
38837 - 46 46 46 86 86 86 2 2 6 2 2 6
38838 - 6 6 6 6 6 6 22 22 22 34 34 34
38839 - 6 6 6 2 2 6 2 2 6 2 2 6
38840 - 2 2 6 2 2 6 18 18 18 34 34 34
38841 - 10 10 10 50 50 50 22 22 22 2 2 6
38842 - 2 2 6 2 2 6 2 2 6 10 10 10
38843 - 86 86 86 42 42 42 14 14 14 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 1 0 0 1 0 0 1 0 0 0
38852 - 0 0 0 0 0 0 0 0 0 0 0 0
38853 - 0 0 0 0 0 0 0 0 0 0 0 0
38854 - 0 0 0 0 0 0 0 0 0 0 0 0
38855 - 0 0 0 0 0 0 0 0 0 0 0 0
38856 - 0 0 0 0 0 0 0 0 0 14 14 14
38857 - 46 46 46 86 86 86 2 2 6 2 2 6
38858 - 38 38 38 116 116 116 94 94 94 22 22 22
38859 - 22 22 22 2 2 6 2 2 6 2 2 6
38860 - 14 14 14 86 86 86 138 138 138 162 162 162
38861 -154 154 154 38 38 38 26 26 26 6 6 6
38862 - 2 2 6 2 2 6 2 2 6 2 2 6
38863 - 86 86 86 46 46 46 14 14 14 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 0 0 0
38874 - 0 0 0 0 0 0 0 0 0 0 0 0
38875 - 0 0 0 0 0 0 0 0 0 0 0 0
38876 - 0 0 0 0 0 0 0 0 0 14 14 14
38877 - 46 46 46 86 86 86 2 2 6 14 14 14
38878 -134 134 134 198 198 198 195 195 195 116 116 116
38879 - 10 10 10 2 2 6 2 2 6 6 6 6
38880 -101 98 89 187 187 187 210 210 210 218 218 218
38881 -214 214 214 134 134 134 14 14 14 6 6 6
38882 - 2 2 6 2 2 6 2 2 6 2 2 6
38883 - 86 86 86 50 50 50 18 18 18 6 6 6
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 1 0 0 0
38891 - 0 0 1 0 0 1 0 0 1 0 0 0
38892 - 0 0 0 0 0 0 0 0 0 0 0 0
38893 - 0 0 0 0 0 0 0 0 0 0 0 0
38894 - 0 0 0 0 0 0 0 0 0 0 0 0
38895 - 0 0 0 0 0 0 0 0 0 0 0 0
38896 - 0 0 0 0 0 0 0 0 0 14 14 14
38897 - 46 46 46 86 86 86 2 2 6 54 54 54
38898 -218 218 218 195 195 195 226 226 226 246 246 246
38899 - 58 58 58 2 2 6 2 2 6 30 30 30
38900 -210 210 210 253 253 253 174 174 174 123 123 123
38901 -221 221 221 234 234 234 74 74 74 2 2 6
38902 - 2 2 6 2 2 6 2 2 6 2 2 6
38903 - 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0
38914 - 0 0 0 0 0 0 0 0 0 0 0 0
38915 - 0 0 0 0 0 0 0 0 0 0 0 0
38916 - 0 0 0 0 0 0 0 0 0 14 14 14
38917 - 46 46 46 82 82 82 2 2 6 106 106 106
38918 -170 170 170 26 26 26 86 86 86 226 226 226
38919 -123 123 123 10 10 10 14 14 14 46 46 46
38920 -231 231 231 190 190 190 6 6 6 70 70 70
38921 - 90 90 90 238 238 238 158 158 158 2 2 6
38922 - 2 2 6 2 2 6 2 2 6 2 2 6
38923 - 70 70 70 58 58 58 22 22 22 6 6 6
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 1 0 0 0
38931 - 0 0 1 0 0 1 0 0 1 0 0 0
38932 - 0 0 0 0 0 0 0 0 0 0 0 0
38933 - 0 0 0 0 0 0 0 0 0 0 0 0
38934 - 0 0 0 0 0 0 0 0 0 0 0 0
38935 - 0 0 0 0 0 0 0 0 0 0 0 0
38936 - 0 0 0 0 0 0 0 0 0 14 14 14
38937 - 42 42 42 86 86 86 6 6 6 116 116 116
38938 -106 106 106 6 6 6 70 70 70 149 149 149
38939 -128 128 128 18 18 18 38 38 38 54 54 54
38940 -221 221 221 106 106 106 2 2 6 14 14 14
38941 - 46 46 46 190 190 190 198 198 198 2 2 6
38942 - 2 2 6 2 2 6 2 2 6 2 2 6
38943 - 74 74 74 62 62 62 22 22 22 6 6 6
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 1 0 0 0
38951 - 0 0 1 0 0 0 0 0 1 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 0 0 0
38954 - 0 0 0 0 0 0 0 0 0 0 0 0
38955 - 0 0 0 0 0 0 0 0 0 0 0 0
38956 - 0 0 0 0 0 0 0 0 0 14 14 14
38957 - 42 42 42 94 94 94 14 14 14 101 101 101
38958 -128 128 128 2 2 6 18 18 18 116 116 116
38959 -118 98 46 121 92 8 121 92 8 98 78 10
38960 -162 162 162 106 106 106 2 2 6 2 2 6
38961 - 2 2 6 195 195 195 195 195 195 6 6 6
38962 - 2 2 6 2 2 6 2 2 6 2 2 6
38963 - 74 74 74 62 62 62 22 22 22 6 6 6
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 1 0 0 1
38971 - 0 0 1 0 0 0 0 0 1 0 0 0
38972 - 0 0 0 0 0 0 0 0 0 0 0 0
38973 - 0 0 0 0 0 0 0 0 0 0 0 0
38974 - 0 0 0 0 0 0 0 0 0 0 0 0
38975 - 0 0 0 0 0 0 0 0 0 0 0 0
38976 - 0 0 0 0 0 0 0 0 0 10 10 10
38977 - 38 38 38 90 90 90 14 14 14 58 58 58
38978 -210 210 210 26 26 26 54 38 6 154 114 10
38979 -226 170 11 236 186 11 225 175 15 184 144 12
38980 -215 174 15 175 146 61 37 26 9 2 2 6
38981 - 70 70 70 246 246 246 138 138 138 2 2 6
38982 - 2 2 6 2 2 6 2 2 6 2 2 6
38983 - 70 70 70 66 66 66 26 26 26 6 6 6
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 0 0 0 0 0 0
38994 - 0 0 0 0 0 0 0 0 0 0 0 0
38995 - 0 0 0 0 0 0 0 0 0 0 0 0
38996 - 0 0 0 0 0 0 0 0 0 10 10 10
38997 - 38 38 38 86 86 86 14 14 14 10 10 10
38998 -195 195 195 188 164 115 192 133 9 225 175 15
38999 -239 182 13 234 190 10 232 195 16 232 200 30
39000 -245 207 45 241 208 19 232 195 16 184 144 12
39001 -218 194 134 211 206 186 42 42 42 2 2 6
39002 - 2 2 6 2 2 6 2 2 6 2 2 6
39003 - 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0 0 0 0 0 0 0
39014 - 0 0 0 0 0 0 0 0 0 0 0 0
39015 - 0 0 0 0 0 0 0 0 0 0 0 0
39016 - 0 0 0 0 0 0 0 0 0 10 10 10
39017 - 34 34 34 86 86 86 14 14 14 2 2 6
39018 -121 87 25 192 133 9 219 162 10 239 182 13
39019 -236 186 11 232 195 16 241 208 19 244 214 54
39020 -246 218 60 246 218 38 246 215 20 241 208 19
39021 -241 208 19 226 184 13 121 87 25 2 2 6
39022 - 2 2 6 2 2 6 2 2 6 2 2 6
39023 - 50 50 50 82 82 82 34 34 34 10 10 10
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 - 0 0 0 0 0 0 0 0 0 0 0 0
39034 - 0 0 0 0 0 0 0 0 0 0 0 0
39035 - 0 0 0 0 0 0 0 0 0 0 0 0
39036 - 0 0 0 0 0 0 0 0 0 10 10 10
39037 - 34 34 34 82 82 82 30 30 30 61 42 6
39038 -180 123 7 206 145 10 230 174 11 239 182 13
39039 -234 190 10 238 202 15 241 208 19 246 218 74
39040 -246 218 38 246 215 20 246 215 20 246 215 20
39041 -226 184 13 215 174 15 184 144 12 6 6 6
39042 - 2 2 6 2 2 6 2 2 6 2 2 6
39043 - 26 26 26 94 94 94 42 42 42 14 14 14
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 0 0 0
39053 - 0 0 0 0 0 0 0 0 0 0 0 0
39054 - 0 0 0 0 0 0 0 0 0 0 0 0
39055 - 0 0 0 0 0 0 0 0 0 0 0 0
39056 - 0 0 0 0 0 0 0 0 0 10 10 10
39057 - 30 30 30 78 78 78 50 50 50 104 69 6
39058 -192 133 9 216 158 10 236 178 12 236 186 11
39059 -232 195 16 241 208 19 244 214 54 245 215 43
39060 -246 215 20 246 215 20 241 208 19 198 155 10
39061 -200 144 11 216 158 10 156 118 10 2 2 6
39062 - 2 2 6 2 2 6 2 2 6 2 2 6
39063 - 6 6 6 90 90 90 54 54 54 18 18 18
39064 - 6 6 6 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 0 0 0
39073 - 0 0 0 0 0 0 0 0 0 0 0 0
39074 - 0 0 0 0 0 0 0 0 0 0 0 0
39075 - 0 0 0 0 0 0 0 0 0 0 0 0
39076 - 0 0 0 0 0 0 0 0 0 10 10 10
39077 - 30 30 30 78 78 78 46 46 46 22 22 22
39078 -137 92 6 210 162 10 239 182 13 238 190 10
39079 -238 202 15 241 208 19 246 215 20 246 215 20
39080 -241 208 19 203 166 17 185 133 11 210 150 10
39081 -216 158 10 210 150 10 102 78 10 2 2 6
39082 - 6 6 6 54 54 54 14 14 14 2 2 6
39083 - 2 2 6 62 62 62 74 74 74 30 30 30
39084 - 10 10 10 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 0 0 0 0 0 0
39093 - 0 0 0 0 0 0 0 0 0 0 0 0
39094 - 0 0 0 0 0 0 0 0 0 0 0 0
39095 - 0 0 0 0 0 0 0 0 0 0 0 0
39096 - 0 0 0 0 0 0 0 0 0 10 10 10
39097 - 34 34 34 78 78 78 50 50 50 6 6 6
39098 - 94 70 30 139 102 15 190 146 13 226 184 13
39099 -232 200 30 232 195 16 215 174 15 190 146 13
39100 -168 122 10 192 133 9 210 150 10 213 154 11
39101 -202 150 34 182 157 106 101 98 89 2 2 6
39102 - 2 2 6 78 78 78 116 116 116 58 58 58
39103 - 2 2 6 22 22 22 90 90 90 46 46 46
39104 - 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0
39113 - 0 0 0 0 0 0 0 0 0 0 0 0
39114 - 0 0 0 0 0 0 0 0 0 0 0 0
39115 - 0 0 0 0 0 0 0 0 0 0 0 0
39116 - 0 0 0 0 0 0 0 0 0 10 10 10
39117 - 38 38 38 86 86 86 50 50 50 6 6 6
39118 -128 128 128 174 154 114 156 107 11 168 122 10
39119 -198 155 10 184 144 12 197 138 11 200 144 11
39120 -206 145 10 206 145 10 197 138 11 188 164 115
39121 -195 195 195 198 198 198 174 174 174 14 14 14
39122 - 2 2 6 22 22 22 116 116 116 116 116 116
39123 - 22 22 22 2 2 6 74 74 74 70 70 70
39124 - 30 30 30 10 10 10 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 - 0 0 0 0 0 0 0 0 0 0 0 0
39133 - 0 0 0 0 0 0 0 0 0 0 0 0
39134 - 0 0 0 0 0 0 0 0 0 0 0 0
39135 - 0 0 0 0 0 0 0 0 0 0 0 0
39136 - 0 0 0 0 0 0 6 6 6 18 18 18
39137 - 50 50 50 101 101 101 26 26 26 10 10 10
39138 -138 138 138 190 190 190 174 154 114 156 107 11
39139 -197 138 11 200 144 11 197 138 11 192 133 9
39140 -180 123 7 190 142 34 190 178 144 187 187 187
39141 -202 202 202 221 221 221 214 214 214 66 66 66
39142 - 2 2 6 2 2 6 50 50 50 62 62 62
39143 - 6 6 6 2 2 6 10 10 10 90 90 90
39144 - 50 50 50 18 18 18 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
39153 - 0 0 0 0 0 0 0 0 0 0 0 0
39154 - 0 0 0 0 0 0 0 0 0 0 0 0
39155 - 0 0 0 0 0 0 0 0 0 0 0 0
39156 - 0 0 0 0 0 0 10 10 10 34 34 34
39157 - 74 74 74 74 74 74 2 2 6 6 6 6
39158 -144 144 144 198 198 198 190 190 190 178 166 146
39159 -154 121 60 156 107 11 156 107 11 168 124 44
39160 -174 154 114 187 187 187 190 190 190 210 210 210
39161 -246 246 246 253 253 253 253 253 253 182 182 182
39162 - 6 6 6 2 2 6 2 2 6 2 2 6
39163 - 2 2 6 2 2 6 2 2 6 62 62 62
39164 - 74 74 74 34 34 34 14 14 14 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 - 0 0 0 0 0 0 0 0 0 0 0 0
39173 - 0 0 0 0 0 0 0 0 0 0 0 0
39174 - 0 0 0 0 0 0 0 0 0 0 0 0
39175 - 0 0 0 0 0 0 0 0 0 0 0 0
39176 - 0 0 0 10 10 10 22 22 22 54 54 54
39177 - 94 94 94 18 18 18 2 2 6 46 46 46
39178 -234 234 234 221 221 221 190 190 190 190 190 190
39179 -190 190 190 187 187 187 187 187 187 190 190 190
39180 -190 190 190 195 195 195 214 214 214 242 242 242
39181 -253 253 253 253 253 253 253 253 253 253 253 253
39182 - 82 82 82 2 2 6 2 2 6 2 2 6
39183 - 2 2 6 2 2 6 2 2 6 14 14 14
39184 - 86 86 86 54 54 54 22 22 22 6 6 6
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 0 0 0
39192 - 0 0 0 0 0 0 0 0 0 0 0 0
39193 - 0 0 0 0 0 0 0 0 0 0 0 0
39194 - 0 0 0 0 0 0 0 0 0 0 0 0
39195 - 0 0 0 0 0 0 0 0 0 0 0 0
39196 - 6 6 6 18 18 18 46 46 46 90 90 90
39197 - 46 46 46 18 18 18 6 6 6 182 182 182
39198 -253 253 253 246 246 246 206 206 206 190 190 190
39199 -190 190 190 190 190 190 190 190 190 190 190 190
39200 -206 206 206 231 231 231 250 250 250 253 253 253
39201 -253 253 253 253 253 253 253 253 253 253 253 253
39202 -202 202 202 14 14 14 2 2 6 2 2 6
39203 - 2 2 6 2 2 6 2 2 6 2 2 6
39204 - 42 42 42 86 86 86 42 42 42 18 18 18
39205 - 6 6 6 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 0 0 0
39212 - 0 0 0 0 0 0 0 0 0 0 0 0
39213 - 0 0 0 0 0 0 0 0 0 0 0 0
39214 - 0 0 0 0 0 0 0 0 0 0 0 0
39215 - 0 0 0 0 0 0 0 0 0 6 6 6
39216 - 14 14 14 38 38 38 74 74 74 66 66 66
39217 - 2 2 6 6 6 6 90 90 90 250 250 250
39218 -253 253 253 253 253 253 238 238 238 198 198 198
39219 -190 190 190 190 190 190 195 195 195 221 221 221
39220 -246 246 246 253 253 253 253 253 253 253 253 253
39221 -253 253 253 253 253 253 253 253 253 253 253 253
39222 -253 253 253 82 82 82 2 2 6 2 2 6
39223 - 2 2 6 2 2 6 2 2 6 2 2 6
39224 - 2 2 6 78 78 78 70 70 70 34 34 34
39225 - 14 14 14 6 6 6 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 0 0 0
39232 - 0 0 0 0 0 0 0 0 0 0 0 0
39233 - 0 0 0 0 0 0 0 0 0 0 0 0
39234 - 0 0 0 0 0 0 0 0 0 0 0 0
39235 - 0 0 0 0 0 0 0 0 0 14 14 14
39236 - 34 34 34 66 66 66 78 78 78 6 6 6
39237 - 2 2 6 18 18 18 218 218 218 253 253 253
39238 -253 253 253 253 253 253 253 253 253 246 246 246
39239 -226 226 226 231 231 231 246 246 246 253 253 253
39240 -253 253 253 253 253 253 253 253 253 253 253 253
39241 -253 253 253 253 253 253 253 253 253 253 253 253
39242 -253 253 253 178 178 178 2 2 6 2 2 6
39243 - 2 2 6 2 2 6 2 2 6 2 2 6
39244 - 2 2 6 18 18 18 90 90 90 62 62 62
39245 - 30 30 30 10 10 10 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 0 0 0 0 0 0
39252 - 0 0 0 0 0 0 0 0 0 0 0 0
39253 - 0 0 0 0 0 0 0 0 0 0 0 0
39254 - 0 0 0 0 0 0 0 0 0 0 0 0
39255 - 0 0 0 0 0 0 10 10 10 26 26 26
39256 - 58 58 58 90 90 90 18 18 18 2 2 6
39257 - 2 2 6 110 110 110 253 253 253 253 253 253
39258 -253 253 253 253 253 253 253 253 253 253 253 253
39259 -250 250 250 253 253 253 253 253 253 253 253 253
39260 -253 253 253 253 253 253 253 253 253 253 253 253
39261 -253 253 253 253 253 253 253 253 253 253 253 253
39262 -253 253 253 231 231 231 18 18 18 2 2 6
39263 - 2 2 6 2 2 6 2 2 6 2 2 6
39264 - 2 2 6 2 2 6 18 18 18 94 94 94
39265 - 54 54 54 26 26 26 10 10 10 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 0 0 0 0 0 0
39272 - 0 0 0 0 0 0 0 0 0 0 0 0
39273 - 0 0 0 0 0 0 0 0 0 0 0 0
39274 - 0 0 0 0 0 0 0 0 0 0 0 0
39275 - 0 0 0 6 6 6 22 22 22 50 50 50
39276 - 90 90 90 26 26 26 2 2 6 2 2 6
39277 - 14 14 14 195 195 195 250 250 250 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 253 253 253 253 253 253 253 253 253
39281 -253 253 253 253 253 253 253 253 253 253 253 253
39282 -250 250 250 242 242 242 54 54 54 2 2 6
39283 - 2 2 6 2 2 6 2 2 6 2 2 6
39284 - 2 2 6 2 2 6 2 2 6 38 38 38
39285 - 86 86 86 50 50 50 22 22 22 6 6 6
39286 - 0 0 0 0 0 0 0 0 0 0 0 0
39287 - 0 0 0 0 0 0 0 0 0 0 0 0
39288 - 0 0 0 0 0 0 0 0 0 0 0 0
39289 - 0 0 0 0 0 0 0 0 0 0 0 0
39290 - 0 0 0 0 0 0 0 0 0 0 0 0
39291 - 0 0 0 0 0 0 0 0 0 0 0 0
39292 - 0 0 0 0 0 0 0 0 0 0 0 0
39293 - 0 0 0 0 0 0 0 0 0 0 0 0
39294 - 0 0 0 0 0 0 0 0 0 0 0 0
39295 - 6 6 6 14 14 14 38 38 38 82 82 82
39296 - 34 34 34 2 2 6 2 2 6 2 2 6
39297 - 42 42 42 195 195 195 246 246 246 253 253 253
39298 -253 253 253 253 253 253 253 253 253 250 250 250
39299 -242 242 242 242 242 242 250 250 250 253 253 253
39300 -253 253 253 253 253 253 253 253 253 253 253 253
39301 -253 253 253 250 250 250 246 246 246 238 238 238
39302 -226 226 226 231 231 231 101 101 101 6 6 6
39303 - 2 2 6 2 2 6 2 2 6 2 2 6
39304 - 2 2 6 2 2 6 2 2 6 2 2 6
39305 - 38 38 38 82 82 82 42 42 42 14 14 14
39306 - 6 6 6 0 0 0 0 0 0 0 0 0
39307 - 0 0 0 0 0 0 0 0 0 0 0 0
39308 - 0 0 0 0 0 0 0 0 0 0 0 0
39309 - 0 0 0 0 0 0 0 0 0 0 0 0
39310 - 0 0 0 0 0 0 0 0 0 0 0 0
39311 - 0 0 0 0 0 0 0 0 0 0 0 0
39312 - 0 0 0 0 0 0 0 0 0 0 0 0
39313 - 0 0 0 0 0 0 0 0 0 0 0 0
39314 - 0 0 0 0 0 0 0 0 0 0 0 0
39315 - 10 10 10 26 26 26 62 62 62 66 66 66
39316 - 2 2 6 2 2 6 2 2 6 6 6 6
39317 - 70 70 70 170 170 170 206 206 206 234 234 234
39318 -246 246 246 250 250 250 250 250 250 238 238 238
39319 -226 226 226 231 231 231 238 238 238 250 250 250
39320 -250 250 250 250 250 250 246 246 246 231 231 231
39321 -214 214 214 206 206 206 202 202 202 202 202 202
39322 -198 198 198 202 202 202 182 182 182 18 18 18
39323 - 2 2 6 2 2 6 2 2 6 2 2 6
39324 - 2 2 6 2 2 6 2 2 6 2 2 6
39325 - 2 2 6 62 62 62 66 66 66 30 30 30
39326 - 10 10 10 0 0 0 0 0 0 0 0 0
39327 - 0 0 0 0 0 0 0 0 0 0 0 0
39328 - 0 0 0 0 0 0 0 0 0 0 0 0
39329 - 0 0 0 0 0 0 0 0 0 0 0 0
39330 - 0 0 0 0 0 0 0 0 0 0 0 0
39331 - 0 0 0 0 0 0 0 0 0 0 0 0
39332 - 0 0 0 0 0 0 0 0 0 0 0 0
39333 - 0 0 0 0 0 0 0 0 0 0 0 0
39334 - 0 0 0 0 0 0 0 0 0 0 0 0
39335 - 14 14 14 42 42 42 82 82 82 18 18 18
39336 - 2 2 6 2 2 6 2 2 6 10 10 10
39337 - 94 94 94 182 182 182 218 218 218 242 242 242
39338 -250 250 250 253 253 253 253 253 253 250 250 250
39339 -234 234 234 253 253 253 253 253 253 253 253 253
39340 -253 253 253 253 253 253 253 253 253 246 246 246
39341 -238 238 238 226 226 226 210 210 210 202 202 202
39342 -195 195 195 195 195 195 210 210 210 158 158 158
39343 - 6 6 6 14 14 14 50 50 50 14 14 14
39344 - 2 2 6 2 2 6 2 2 6 2 2 6
39345 - 2 2 6 6 6 6 86 86 86 46 46 46
39346 - 18 18 18 6 6 6 0 0 0 0 0 0
39347 - 0 0 0 0 0 0 0 0 0 0 0 0
39348 - 0 0 0 0 0 0 0 0 0 0 0 0
39349 - 0 0 0 0 0 0 0 0 0 0 0 0
39350 - 0 0 0 0 0 0 0 0 0 0 0 0
39351 - 0 0 0 0 0 0 0 0 0 0 0 0
39352 - 0 0 0 0 0 0 0 0 0 0 0 0
39353 - 0 0 0 0 0 0 0 0 0 0 0 0
39354 - 0 0 0 0 0 0 0 0 0 6 6 6
39355 - 22 22 22 54 54 54 70 70 70 2 2 6
39356 - 2 2 6 10 10 10 2 2 6 22 22 22
39357 -166 166 166 231 231 231 250 250 250 253 253 253
39358 -253 253 253 253 253 253 253 253 253 250 250 250
39359 -242 242 242 253 253 253 253 253 253 253 253 253
39360 -253 253 253 253 253 253 253 253 253 253 253 253
39361 -253 253 253 253 253 253 253 253 253 246 246 246
39362 -231 231 231 206 206 206 198 198 198 226 226 226
39363 - 94 94 94 2 2 6 6 6 6 38 38 38
39364 - 30 30 30 2 2 6 2 2 6 2 2 6
39365 - 2 2 6 2 2 6 62 62 62 66 66 66
39366 - 26 26 26 10 10 10 0 0 0 0 0 0
39367 - 0 0 0 0 0 0 0 0 0 0 0 0
39368 - 0 0 0 0 0 0 0 0 0 0 0 0
39369 - 0 0 0 0 0 0 0 0 0 0 0 0
39370 - 0 0 0 0 0 0 0 0 0 0 0 0
39371 - 0 0 0 0 0 0 0 0 0 0 0 0
39372 - 0 0 0 0 0 0 0 0 0 0 0 0
39373 - 0 0 0 0 0 0 0 0 0 0 0 0
39374 - 0 0 0 0 0 0 0 0 0 10 10 10
39375 - 30 30 30 74 74 74 50 50 50 2 2 6
39376 - 26 26 26 26 26 26 2 2 6 106 106 106
39377 -238 238 238 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 253 253 253 253 253 253
39381 -253 253 253 253 253 253 253 253 253 253 253 253
39382 -253 253 253 246 246 246 218 218 218 202 202 202
39383 -210 210 210 14 14 14 2 2 6 2 2 6
39384 - 30 30 30 22 22 22 2 2 6 2 2 6
39385 - 2 2 6 2 2 6 18 18 18 86 86 86
39386 - 42 42 42 14 14 14 0 0 0 0 0 0
39387 - 0 0 0 0 0 0 0 0 0 0 0 0
39388 - 0 0 0 0 0 0 0 0 0 0 0 0
39389 - 0 0 0 0 0 0 0 0 0 0 0 0
39390 - 0 0 0 0 0 0 0 0 0 0 0 0
39391 - 0 0 0 0 0 0 0 0 0 0 0 0
39392 - 0 0 0 0 0 0 0 0 0 0 0 0
39393 - 0 0 0 0 0 0 0 0 0 0 0 0
39394 - 0 0 0 0 0 0 0 0 0 14 14 14
39395 - 42 42 42 90 90 90 22 22 22 2 2 6
39396 - 42 42 42 2 2 6 18 18 18 218 218 218
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 253 253 253 253 253 253
39401 -253 253 253 253 253 253 253 253 253 253 253 253
39402 -253 253 253 253 253 253 250 250 250 221 221 221
39403 -218 218 218 101 101 101 2 2 6 14 14 14
39404 - 18 18 18 38 38 38 10 10 10 2 2 6
39405 - 2 2 6 2 2 6 2 2 6 78 78 78
39406 - 58 58 58 22 22 22 6 6 6 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 0 0 0
39411 - 0 0 0 0 0 0 0 0 0 0 0 0
39412 - 0 0 0 0 0 0 0 0 0 0 0 0
39413 - 0 0 0 0 0 0 0 0 0 0 0 0
39414 - 0 0 0 0 0 0 6 6 6 18 18 18
39415 - 54 54 54 82 82 82 2 2 6 26 26 26
39416 - 22 22 22 2 2 6 123 123 123 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 253 253 253 253 253 253
39421 -253 253 253 253 253 253 253 253 253 253 253 253
39422 -253 253 253 253 253 253 253 253 253 250 250 250
39423 -238 238 238 198 198 198 6 6 6 38 38 38
39424 - 58 58 58 26 26 26 38 38 38 2 2 6
39425 - 2 2 6 2 2 6 2 2 6 46 46 46
39426 - 78 78 78 30 30 30 10 10 10 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 0 0 0 0 0 0
39431 - 0 0 0 0 0 0 0 0 0 0 0 0
39432 - 0 0 0 0 0 0 0 0 0 0 0 0
39433 - 0 0 0 0 0 0 0 0 0 0 0 0
39434 - 0 0 0 0 0 0 10 10 10 30 30 30
39435 - 74 74 74 58 58 58 2 2 6 42 42 42
39436 - 2 2 6 22 22 22 231 231 231 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 250 250 250
39439 -253 253 253 253 253 253 253 253 253 253 253 253
39440 -253 253 253 253 253 253 253 253 253 253 253 253
39441 -253 253 253 253 253 253 253 253 253 253 253 253
39442 -253 253 253 253 253 253 253 253 253 253 253 253
39443 -253 253 253 246 246 246 46 46 46 38 38 38
39444 - 42 42 42 14 14 14 38 38 38 14 14 14
39445 - 2 2 6 2 2 6 2 2 6 6 6 6
39446 - 86 86 86 46 46 46 14 14 14 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 0 0 0 0 0 0
39451 - 0 0 0 0 0 0 0 0 0 0 0 0
39452 - 0 0 0 0 0 0 0 0 0 0 0 0
39453 - 0 0 0 0 0 0 0 0 0 0 0 0
39454 - 0 0 0 6 6 6 14 14 14 42 42 42
39455 - 90 90 90 18 18 18 18 18 18 26 26 26
39456 - 2 2 6 116 116 116 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 250 250 250 238 238 238
39459 -253 253 253 253 253 253 253 253 253 253 253 253
39460 -253 253 253 253 253 253 253 253 253 253 253 253
39461 -253 253 253 253 253 253 253 253 253 253 253 253
39462 -253 253 253 253 253 253 253 253 253 253 253 253
39463 -253 253 253 253 253 253 94 94 94 6 6 6
39464 - 2 2 6 2 2 6 10 10 10 34 34 34
39465 - 2 2 6 2 2 6 2 2 6 2 2 6
39466 - 74 74 74 58 58 58 22 22 22 6 6 6
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 0 0 0 0 0 0
39471 - 0 0 0 0 0 0 0 0 0 0 0 0
39472 - 0 0 0 0 0 0 0 0 0 0 0 0
39473 - 0 0 0 0 0 0 0 0 0 0 0 0
39474 - 0 0 0 10 10 10 26 26 26 66 66 66
39475 - 82 82 82 2 2 6 38 38 38 6 6 6
39476 - 14 14 14 210 210 210 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 246 246 246 242 242 242
39479 -253 253 253 253 253 253 253 253 253 253 253 253
39480 -253 253 253 253 253 253 253 253 253 253 253 253
39481 -253 253 253 253 253 253 253 253 253 253 253 253
39482 -253 253 253 253 253 253 253 253 253 253 253 253
39483 -253 253 253 253 253 253 144 144 144 2 2 6
39484 - 2 2 6 2 2 6 2 2 6 46 46 46
39485 - 2 2 6 2 2 6 2 2 6 2 2 6
39486 - 42 42 42 74 74 74 30 30 30 10 10 10
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 0 0 0 0 0 0
39491 - 0 0 0 0 0 0 0 0 0 0 0 0
39492 - 0 0 0 0 0 0 0 0 0 0 0 0
39493 - 0 0 0 0 0 0 0 0 0 0 0 0
39494 - 6 6 6 14 14 14 42 42 42 90 90 90
39495 - 26 26 26 6 6 6 42 42 42 2 2 6
39496 - 74 74 74 250 250 250 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 242 242 242 242 242 242
39499 -253 253 253 253 253 253 253 253 253 253 253 253
39500 -253 253 253 253 253 253 253 253 253 253 253 253
39501 -253 253 253 253 253 253 253 253 253 253 253 253
39502 -253 253 253 253 253 253 253 253 253 253 253 253
39503 -253 253 253 253 253 253 182 182 182 2 2 6
39504 - 2 2 6 2 2 6 2 2 6 46 46 46
39505 - 2 2 6 2 2 6 2 2 6 2 2 6
39506 - 10 10 10 86 86 86 38 38 38 10 10 10
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 0 0 0
39510 - 0 0 0 0 0 0 0 0 0 0 0 0
39511 - 0 0 0 0 0 0 0 0 0 0 0 0
39512 - 0 0 0 0 0 0 0 0 0 0 0 0
39513 - 0 0 0 0 0 0 0 0 0 0 0 0
39514 - 10 10 10 26 26 26 66 66 66 82 82 82
39515 - 2 2 6 22 22 22 18 18 18 2 2 6
39516 -149 149 149 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 234 234 234 242 242 242
39519 -253 253 253 253 253 253 253 253 253 253 253 253
39520 -253 253 253 253 253 253 253 253 253 253 253 253
39521 -253 253 253 253 253 253 253 253 253 253 253 253
39522 -253 253 253 253 253 253 253 253 253 253 253 253
39523 -253 253 253 253 253 253 206 206 206 2 2 6
39524 - 2 2 6 2 2 6 2 2 6 38 38 38
39525 - 2 2 6 2 2 6 2 2 6 2 2 6
39526 - 6 6 6 86 86 86 46 46 46 14 14 14
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 0 0 0 0 0 0 0 0 0
39530 - 0 0 0 0 0 0 0 0 0 0 0 0
39531 - 0 0 0 0 0 0 0 0 0 0 0 0
39532 - 0 0 0 0 0 0 0 0 0 0 0 0
39533 - 0 0 0 0 0 0 0 0 0 6 6 6
39534 - 18 18 18 46 46 46 86 86 86 18 18 18
39535 - 2 2 6 34 34 34 10 10 10 6 6 6
39536 -210 210 210 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 234 234 234 242 242 242
39539 -253 253 253 253 253 253 253 253 253 253 253 253
39540 -253 253 253 253 253 253 253 253 253 253 253 253
39541 -253 253 253 253 253 253 253 253 253 253 253 253
39542 -253 253 253 253 253 253 253 253 253 253 253 253
39543 -253 253 253 253 253 253 221 221 221 6 6 6
39544 - 2 2 6 2 2 6 6 6 6 30 30 30
39545 - 2 2 6 2 2 6 2 2 6 2 2 6
39546 - 2 2 6 82 82 82 54 54 54 18 18 18
39547 - 6 6 6 0 0 0 0 0 0 0 0 0
39548 - 0 0 0 0 0 0 0 0 0 0 0 0
39549 - 0 0 0 0 0 0 0 0 0 0 0 0
39550 - 0 0 0 0 0 0 0 0 0 0 0 0
39551 - 0 0 0 0 0 0 0 0 0 0 0 0
39552 - 0 0 0 0 0 0 0 0 0 0 0 0
39553 - 0 0 0 0 0 0 0 0 0 10 10 10
39554 - 26 26 26 66 66 66 62 62 62 2 2 6
39555 - 2 2 6 38 38 38 10 10 10 26 26 26
39556 -238 238 238 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 231 231 231 238 238 238
39559 -253 253 253 253 253 253 253 253 253 253 253 253
39560 -253 253 253 253 253 253 253 253 253 253 253 253
39561 -253 253 253 253 253 253 253 253 253 253 253 253
39562 -253 253 253 253 253 253 253 253 253 253 253 253
39563 -253 253 253 253 253 253 231 231 231 6 6 6
39564 - 2 2 6 2 2 6 10 10 10 30 30 30
39565 - 2 2 6 2 2 6 2 2 6 2 2 6
39566 - 2 2 6 66 66 66 58 58 58 22 22 22
39567 - 6 6 6 0 0 0 0 0 0 0 0 0
39568 - 0 0 0 0 0 0 0 0 0 0 0 0
39569 - 0 0 0 0 0 0 0 0 0 0 0 0
39570 - 0 0 0 0 0 0 0 0 0 0 0 0
39571 - 0 0 0 0 0 0 0 0 0 0 0 0
39572 - 0 0 0 0 0 0 0 0 0 0 0 0
39573 - 0 0 0 0 0 0 0 0 0 10 10 10
39574 - 38 38 38 78 78 78 6 6 6 2 2 6
39575 - 2 2 6 46 46 46 14 14 14 42 42 42
39576 -246 246 246 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 231 231 231 242 242 242
39579 -253 253 253 253 253 253 253 253 253 253 253 253
39580 -253 253 253 253 253 253 253 253 253 253 253 253
39581 -253 253 253 253 253 253 253 253 253 253 253 253
39582 -253 253 253 253 253 253 253 253 253 253 253 253
39583 -253 253 253 253 253 253 234 234 234 10 10 10
39584 - 2 2 6 2 2 6 22 22 22 14 14 14
39585 - 2 2 6 2 2 6 2 2 6 2 2 6
39586 - 2 2 6 66 66 66 62 62 62 22 22 22
39587 - 6 6 6 0 0 0 0 0 0 0 0 0
39588 - 0 0 0 0 0 0 0 0 0 0 0 0
39589 - 0 0 0 0 0 0 0 0 0 0 0 0
39590 - 0 0 0 0 0 0 0 0 0 0 0 0
39591 - 0 0 0 0 0 0 0 0 0 0 0 0
39592 - 0 0 0 0 0 0 0 0 0 0 0 0
39593 - 0 0 0 0 0 0 6 6 6 18 18 18
39594 - 50 50 50 74 74 74 2 2 6 2 2 6
39595 - 14 14 14 70 70 70 34 34 34 62 62 62
39596 -250 250 250 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 231 231 231 246 246 246
39599 -253 253 253 253 253 253 253 253 253 253 253 253
39600 -253 253 253 253 253 253 253 253 253 253 253 253
39601 -253 253 253 253 253 253 253 253 253 253 253 253
39602 -253 253 253 253 253 253 253 253 253 253 253 253
39603 -253 253 253 253 253 253 234 234 234 14 14 14
39604 - 2 2 6 2 2 6 30 30 30 2 2 6
39605 - 2 2 6 2 2 6 2 2 6 2 2 6
39606 - 2 2 6 66 66 66 62 62 62 22 22 22
39607 - 6 6 6 0 0 0 0 0 0 0 0 0
39608 - 0 0 0 0 0 0 0 0 0 0 0 0
39609 - 0 0 0 0 0 0 0 0 0 0 0 0
39610 - 0 0 0 0 0 0 0 0 0 0 0 0
39611 - 0 0 0 0 0 0 0 0 0 0 0 0
39612 - 0 0 0 0 0 0 0 0 0 0 0 0
39613 - 0 0 0 0 0 0 6 6 6 18 18 18
39614 - 54 54 54 62 62 62 2 2 6 2 2 6
39615 - 2 2 6 30 30 30 46 46 46 70 70 70
39616 -250 250 250 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 231 231 231 246 246 246
39619 -253 253 253 253 253 253 253 253 253 253 253 253
39620 -253 253 253 253 253 253 253 253 253 253 253 253
39621 -253 253 253 253 253 253 253 253 253 253 253 253
39622 -253 253 253 253 253 253 253 253 253 253 253 253
39623 -253 253 253 253 253 253 226 226 226 10 10 10
39624 - 2 2 6 6 6 6 30 30 30 2 2 6
39625 - 2 2 6 2 2 6 2 2 6 2 2 6
39626 - 2 2 6 66 66 66 58 58 58 22 22 22
39627 - 6 6 6 0 0 0 0 0 0 0 0 0
39628 - 0 0 0 0 0 0 0 0 0 0 0 0
39629 - 0 0 0 0 0 0 0 0 0 0 0 0
39630 - 0 0 0 0 0 0 0 0 0 0 0 0
39631 - 0 0 0 0 0 0 0 0 0 0 0 0
39632 - 0 0 0 0 0 0 0 0 0 0 0 0
39633 - 0 0 0 0 0 0 6 6 6 22 22 22
39634 - 58 58 58 62 62 62 2 2 6 2 2 6
39635 - 2 2 6 2 2 6 30 30 30 78 78 78
39636 -250 250 250 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 231 231 231 246 246 246
39639 -253 253 253 253 253 253 253 253 253 253 253 253
39640 -253 253 253 253 253 253 253 253 253 253 253 253
39641 -253 253 253 253 253 253 253 253 253 253 253 253
39642 -253 253 253 253 253 253 253 253 253 253 253 253
39643 -253 253 253 253 253 253 206 206 206 2 2 6
39644 - 22 22 22 34 34 34 18 14 6 22 22 22
39645 - 26 26 26 18 18 18 6 6 6 2 2 6
39646 - 2 2 6 82 82 82 54 54 54 18 18 18
39647 - 6 6 6 0 0 0 0 0 0 0 0 0
39648 - 0 0 0 0 0 0 0 0 0 0 0 0
39649 - 0 0 0 0 0 0 0 0 0 0 0 0
39650 - 0 0 0 0 0 0 0 0 0 0 0 0
39651 - 0 0 0 0 0 0 0 0 0 0 0 0
39652 - 0 0 0 0 0 0 0 0 0 0 0 0
39653 - 0 0 0 0 0 0 6 6 6 26 26 26
39654 - 62 62 62 106 106 106 74 54 14 185 133 11
39655 -210 162 10 121 92 8 6 6 6 62 62 62
39656 -238 238 238 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 231 231 231 246 246 246
39659 -253 253 253 253 253 253 253 253 253 253 253 253
39660 -253 253 253 253 253 253 253 253 253 253 253 253
39661 -253 253 253 253 253 253 253 253 253 253 253 253
39662 -253 253 253 253 253 253 253 253 253 253 253 253
39663 -253 253 253 253 253 253 158 158 158 18 18 18
39664 - 14 14 14 2 2 6 2 2 6 2 2 6
39665 - 6 6 6 18 18 18 66 66 66 38 38 38
39666 - 6 6 6 94 94 94 50 50 50 18 18 18
39667 - 6 6 6 0 0 0 0 0 0 0 0 0
39668 - 0 0 0 0 0 0 0 0 0 0 0 0
39669 - 0 0 0 0 0 0 0 0 0 0 0 0
39670 - 0 0 0 0 0 0 0 0 0 0 0 0
39671 - 0 0 0 0 0 0 0 0 0 0 0 0
39672 - 0 0 0 0 0 0 0 0 0 6 6 6
39673 - 10 10 10 10 10 10 18 18 18 38 38 38
39674 - 78 78 78 142 134 106 216 158 10 242 186 14
39675 -246 190 14 246 190 14 156 118 10 10 10 10
39676 - 90 90 90 238 238 238 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 231 231 231 250 250 250
39679 -253 253 253 253 253 253 253 253 253 253 253 253
39680 -253 253 253 253 253 253 253 253 253 253 253 253
39681 -253 253 253 253 253 253 253 253 253 253 253 253
39682 -253 253 253 253 253 253 253 253 253 246 230 190
39683 -238 204 91 238 204 91 181 142 44 37 26 9
39684 - 2 2 6 2 2 6 2 2 6 2 2 6
39685 - 2 2 6 2 2 6 38 38 38 46 46 46
39686 - 26 26 26 106 106 106 54 54 54 18 18 18
39687 - 6 6 6 0 0 0 0 0 0 0 0 0
39688 - 0 0 0 0 0 0 0 0 0 0 0 0
39689 - 0 0 0 0 0 0 0 0 0 0 0 0
39690 - 0 0 0 0 0 0 0 0 0 0 0 0
39691 - 0 0 0 0 0 0 0 0 0 0 0 0
39692 - 0 0 0 6 6 6 14 14 14 22 22 22
39693 - 30 30 30 38 38 38 50 50 50 70 70 70
39694 -106 106 106 190 142 34 226 170 11 242 186 14
39695 -246 190 14 246 190 14 246 190 14 154 114 10
39696 - 6 6 6 74 74 74 226 226 226 253 253 253
39697 -253 253 253 253 253 253 253 253 253 253 253 253
39698 -253 253 253 253 253 253 231 231 231 250 250 250
39699 -253 253 253 253 253 253 253 253 253 253 253 253
39700 -253 253 253 253 253 253 253 253 253 253 253 253
39701 -253 253 253 253 253 253 253 253 253 253 253 253
39702 -253 253 253 253 253 253 253 253 253 228 184 62
39703 -241 196 14 241 208 19 232 195 16 38 30 10
39704 - 2 2 6 2 2 6 2 2 6 2 2 6
39705 - 2 2 6 6 6 6 30 30 30 26 26 26
39706 -203 166 17 154 142 90 66 66 66 26 26 26
39707 - 6 6 6 0 0 0 0 0 0 0 0 0
39708 - 0 0 0 0 0 0 0 0 0 0 0 0
39709 - 0 0 0 0 0 0 0 0 0 0 0 0
39710 - 0 0 0 0 0 0 0 0 0 0 0 0
39711 - 0 0 0 0 0 0 0 0 0 0 0 0
39712 - 6 6 6 18 18 18 38 38 38 58 58 58
39713 - 78 78 78 86 86 86 101 101 101 123 123 123
39714 -175 146 61 210 150 10 234 174 13 246 186 14
39715 -246 190 14 246 190 14 246 190 14 238 190 10
39716 -102 78 10 2 2 6 46 46 46 198 198 198
39717 -253 253 253 253 253 253 253 253 253 253 253 253
39718 -253 253 253 253 253 253 234 234 234 242 242 242
39719 -253 253 253 253 253 253 253 253 253 253 253 253
39720 -253 253 253 253 253 253 253 253 253 253 253 253
39721 -253 253 253 253 253 253 253 253 253 253 253 253
39722 -253 253 253 253 253 253 253 253 253 224 178 62
39723 -242 186 14 241 196 14 210 166 10 22 18 6
39724 - 2 2 6 2 2 6 2 2 6 2 2 6
39725 - 2 2 6 2 2 6 6 6 6 121 92 8
39726 -238 202 15 232 195 16 82 82 82 34 34 34
39727 - 10 10 10 0 0 0 0 0 0 0 0 0
39728 - 0 0 0 0 0 0 0 0 0 0 0 0
39729 - 0 0 0 0 0 0 0 0 0 0 0 0
39730 - 0 0 0 0 0 0 0 0 0 0 0 0
39731 - 0 0 0 0 0 0 0 0 0 0 0 0
39732 - 14 14 14 38 38 38 70 70 70 154 122 46
39733 -190 142 34 200 144 11 197 138 11 197 138 11
39734 -213 154 11 226 170 11 242 186 14 246 190 14
39735 -246 190 14 246 190 14 246 190 14 246 190 14
39736 -225 175 15 46 32 6 2 2 6 22 22 22
39737 -158 158 158 250 250 250 253 253 253 253 253 253
39738 -253 253 253 253 253 253 253 253 253 253 253 253
39739 -253 253 253 253 253 253 253 253 253 253 253 253
39740 -253 253 253 253 253 253 253 253 253 253 253 253
39741 -253 253 253 253 253 253 253 253 253 253 253 253
39742 -253 253 253 250 250 250 242 242 242 224 178 62
39743 -239 182 13 236 186 11 213 154 11 46 32 6
39744 - 2 2 6 2 2 6 2 2 6 2 2 6
39745 - 2 2 6 2 2 6 61 42 6 225 175 15
39746 -238 190 10 236 186 11 112 100 78 42 42 42
39747 - 14 14 14 0 0 0 0 0 0 0 0 0
39748 - 0 0 0 0 0 0 0 0 0 0 0 0
39749 - 0 0 0 0 0 0 0 0 0 0 0 0
39750 - 0 0 0 0 0 0 0 0 0 0 0 0
39751 - 0 0 0 0 0 0 0 0 0 6 6 6
39752 - 22 22 22 54 54 54 154 122 46 213 154 11
39753 -226 170 11 230 174 11 226 170 11 226 170 11
39754 -236 178 12 242 186 14 246 190 14 246 190 14
39755 -246 190 14 246 190 14 246 190 14 246 190 14
39756 -241 196 14 184 144 12 10 10 10 2 2 6
39757 - 6 6 6 116 116 116 242 242 242 253 253 253
39758 -253 253 253 253 253 253 253 253 253 253 253 253
39759 -253 253 253 253 253 253 253 253 253 253 253 253
39760 -253 253 253 253 253 253 253 253 253 253 253 253
39761 -253 253 253 253 253 253 253 253 253 253 253 253
39762 -253 253 253 231 231 231 198 198 198 214 170 54
39763 -236 178 12 236 178 12 210 150 10 137 92 6
39764 - 18 14 6 2 2 6 2 2 6 2 2 6
39765 - 6 6 6 70 47 6 200 144 11 236 178 12
39766 -239 182 13 239 182 13 124 112 88 58 58 58
39767 - 22 22 22 6 6 6 0 0 0 0 0 0
39768 - 0 0 0 0 0 0 0 0 0 0 0 0
39769 - 0 0 0 0 0 0 0 0 0 0 0 0
39770 - 0 0 0 0 0 0 0 0 0 0 0 0
39771 - 0 0 0 0 0 0 0 0 0 10 10 10
39772 - 30 30 30 70 70 70 180 133 36 226 170 11
39773 -239 182 13 242 186 14 242 186 14 246 186 14
39774 -246 190 14 246 190 14 246 190 14 246 190 14
39775 -246 190 14 246 190 14 246 190 14 246 190 14
39776 -246 190 14 232 195 16 98 70 6 2 2 6
39777 - 2 2 6 2 2 6 66 66 66 221 221 221
39778 -253 253 253 253 253 253 253 253 253 253 253 253
39779 -253 253 253 253 253 253 253 253 253 253 253 253
39780 -253 253 253 253 253 253 253 253 253 253 253 253
39781 -253 253 253 253 253 253 253 253 253 253 253 253
39782 -253 253 253 206 206 206 198 198 198 214 166 58
39783 -230 174 11 230 174 11 216 158 10 192 133 9
39784 -163 110 8 116 81 8 102 78 10 116 81 8
39785 -167 114 7 197 138 11 226 170 11 239 182 13
39786 -242 186 14 242 186 14 162 146 94 78 78 78
39787 - 34 34 34 14 14 14 6 6 6 0 0 0
39788 - 0 0 0 0 0 0 0 0 0 0 0 0
39789 - 0 0 0 0 0 0 0 0 0 0 0 0
39790 - 0 0 0 0 0 0 0 0 0 0 0 0
39791 - 0 0 0 0 0 0 0 0 0 6 6 6
39792 - 30 30 30 78 78 78 190 142 34 226 170 11
39793 -239 182 13 246 190 14 246 190 14 246 190 14
39794 -246 190 14 246 190 14 246 190 14 246 190 14
39795 -246 190 14 246 190 14 246 190 14 246 190 14
39796 -246 190 14 241 196 14 203 166 17 22 18 6
39797 - 2 2 6 2 2 6 2 2 6 38 38 38
39798 -218 218 218 253 253 253 253 253 253 253 253 253
39799 -253 253 253 253 253 253 253 253 253 253 253 253
39800 -253 253 253 253 253 253 253 253 253 253 253 253
39801 -253 253 253 253 253 253 253 253 253 253 253 253
39802 -250 250 250 206 206 206 198 198 198 202 162 69
39803 -226 170 11 236 178 12 224 166 10 210 150 10
39804 -200 144 11 197 138 11 192 133 9 197 138 11
39805 -210 150 10 226 170 11 242 186 14 246 190 14
39806 -246 190 14 246 186 14 225 175 15 124 112 88
39807 - 62 62 62 30 30 30 14 14 14 6 6 6
39808 - 0 0 0 0 0 0 0 0 0 0 0 0
39809 - 0 0 0 0 0 0 0 0 0 0 0 0
39810 - 0 0 0 0 0 0 0 0 0 0 0 0
39811 - 0 0 0 0 0 0 0 0 0 10 10 10
39812 - 30 30 30 78 78 78 174 135 50 224 166 10
39813 -239 182 13 246 190 14 246 190 14 246 190 14
39814 -246 190 14 246 190 14 246 190 14 246 190 14
39815 -246 190 14 246 190 14 246 190 14 246 190 14
39816 -246 190 14 246 190 14 241 196 14 139 102 15
39817 - 2 2 6 2 2 6 2 2 6 2 2 6
39818 - 78 78 78 250 250 250 253 253 253 253 253 253
39819 -253 253 253 253 253 253 253 253 253 253 253 253
39820 -253 253 253 253 253 253 253 253 253 253 253 253
39821 -253 253 253 253 253 253 253 253 253 253 253 253
39822 -250 250 250 214 214 214 198 198 198 190 150 46
39823 -219 162 10 236 178 12 234 174 13 224 166 10
39824 -216 158 10 213 154 11 213 154 11 216 158 10
39825 -226 170 11 239 182 13 246 190 14 246 190 14
39826 -246 190 14 246 190 14 242 186 14 206 162 42
39827 -101 101 101 58 58 58 30 30 30 14 14 14
39828 - 6 6 6 0 0 0 0 0 0 0 0 0
39829 - 0 0 0 0 0 0 0 0 0 0 0 0
39830 - 0 0 0 0 0 0 0 0 0 0 0 0
39831 - 0 0 0 0 0 0 0 0 0 10 10 10
39832 - 30 30 30 74 74 74 174 135 50 216 158 10
39833 -236 178 12 246 190 14 246 190 14 246 190 14
39834 -246 190 14 246 190 14 246 190 14 246 190 14
39835 -246 190 14 246 190 14 246 190 14 246 190 14
39836 -246 190 14 246 190 14 241 196 14 226 184 13
39837 - 61 42 6 2 2 6 2 2 6 2 2 6
39838 - 22 22 22 238 238 238 253 253 253 253 253 253
39839 -253 253 253 253 253 253 253 253 253 253 253 253
39840 -253 253 253 253 253 253 253 253 253 253 253 253
39841 -253 253 253 253 253 253 253 253 253 253 253 253
39842 -253 253 253 226 226 226 187 187 187 180 133 36
39843 -216 158 10 236 178 12 239 182 13 236 178 12
39844 -230 174 11 226 170 11 226 170 11 230 174 11
39845 -236 178 12 242 186 14 246 190 14 246 190 14
39846 -246 190 14 246 190 14 246 186 14 239 182 13
39847 -206 162 42 106 106 106 66 66 66 34 34 34
39848 - 14 14 14 6 6 6 0 0 0 0 0 0
39849 - 0 0 0 0 0 0 0 0 0 0 0 0
39850 - 0 0 0 0 0 0 0 0 0 0 0 0
39851 - 0 0 0 0 0 0 0 0 0 6 6 6
39852 - 26 26 26 70 70 70 163 133 67 213 154 11
39853 -236 178 12 246 190 14 246 190 14 246 190 14
39854 -246 190 14 246 190 14 246 190 14 246 190 14
39855 -246 190 14 246 190 14 246 190 14 246 190 14
39856 -246 190 14 246 190 14 246 190 14 241 196 14
39857 -190 146 13 18 14 6 2 2 6 2 2 6
39858 - 46 46 46 246 246 246 253 253 253 253 253 253
39859 -253 253 253 253 253 253 253 253 253 253 253 253
39860 -253 253 253 253 253 253 253 253 253 253 253 253
39861 -253 253 253 253 253 253 253 253 253 253 253 253
39862 -253 253 253 221 221 221 86 86 86 156 107 11
39863 -216 158 10 236 178 12 242 186 14 246 186 14
39864 -242 186 14 239 182 13 239 182 13 242 186 14
39865 -242 186 14 246 186 14 246 190 14 246 190 14
39866 -246 190 14 246 190 14 246 190 14 246 190 14
39867 -242 186 14 225 175 15 142 122 72 66 66 66
39868 - 30 30 30 10 10 10 0 0 0 0 0 0
39869 - 0 0 0 0 0 0 0 0 0 0 0 0
39870 - 0 0 0 0 0 0 0 0 0 0 0 0
39871 - 0 0 0 0 0 0 0 0 0 6 6 6
39872 - 26 26 26 70 70 70 163 133 67 210 150 10
39873 -236 178 12 246 190 14 246 190 14 246 190 14
39874 -246 190 14 246 190 14 246 190 14 246 190 14
39875 -246 190 14 246 190 14 246 190 14 246 190 14
39876 -246 190 14 246 190 14 246 190 14 246 190 14
39877 -232 195 16 121 92 8 34 34 34 106 106 106
39878 -221 221 221 253 253 253 253 253 253 253 253 253
39879 -253 253 253 253 253 253 253 253 253 253 253 253
39880 -253 253 253 253 253 253 253 253 253 253 253 253
39881 -253 253 253 253 253 253 253 253 253 253 253 253
39882 -242 242 242 82 82 82 18 14 6 163 110 8
39883 -216 158 10 236 178 12 242 186 14 246 190 14
39884 -246 190 14 246 190 14 246 190 14 246 190 14
39885 -246 190 14 246 190 14 246 190 14 246 190 14
39886 -246 190 14 246 190 14 246 190 14 246 190 14
39887 -246 190 14 246 190 14 242 186 14 163 133 67
39888 - 46 46 46 18 18 18 6 6 6 0 0 0
39889 - 0 0 0 0 0 0 0 0 0 0 0 0
39890 - 0 0 0 0 0 0 0 0 0 0 0 0
39891 - 0 0 0 0 0 0 0 0 0 10 10 10
39892 - 30 30 30 78 78 78 163 133 67 210 150 10
39893 -236 178 12 246 186 14 246 190 14 246 190 14
39894 -246 190 14 246 190 14 246 190 14 246 190 14
39895 -246 190 14 246 190 14 246 190 14 246 190 14
39896 -246 190 14 246 190 14 246 190 14 246 190 14
39897 -241 196 14 215 174 15 190 178 144 253 253 253
39898 -253 253 253 253 253 253 253 253 253 253 253 253
39899 -253 253 253 253 253 253 253 253 253 253 253 253
39900 -253 253 253 253 253 253 253 253 253 253 253 253
39901 -253 253 253 253 253 253 253 253 253 218 218 218
39902 - 58 58 58 2 2 6 22 18 6 167 114 7
39903 -216 158 10 236 178 12 246 186 14 246 190 14
39904 -246 190 14 246 190 14 246 190 14 246 190 14
39905 -246 190 14 246 190 14 246 190 14 246 190 14
39906 -246 190 14 246 190 14 246 190 14 246 190 14
39907 -246 190 14 246 186 14 242 186 14 190 150 46
39908 - 54 54 54 22 22 22 6 6 6 0 0 0
39909 - 0 0 0 0 0 0 0 0 0 0 0 0
39910 - 0 0 0 0 0 0 0 0 0 0 0 0
39911 - 0 0 0 0 0 0 0 0 0 14 14 14
39912 - 38 38 38 86 86 86 180 133 36 213 154 11
39913 -236 178 12 246 186 14 246 190 14 246 190 14
39914 -246 190 14 246 190 14 246 190 14 246 190 14
39915 -246 190 14 246 190 14 246 190 14 246 190 14
39916 -246 190 14 246 190 14 246 190 14 246 190 14
39917 -246 190 14 232 195 16 190 146 13 214 214 214
39918 -253 253 253 253 253 253 253 253 253 253 253 253
39919 -253 253 253 253 253 253 253 253 253 253 253 253
39920 -253 253 253 253 253 253 253 253 253 253 253 253
39921 -253 253 253 250 250 250 170 170 170 26 26 26
39922 - 2 2 6 2 2 6 37 26 9 163 110 8
39923 -219 162 10 239 182 13 246 186 14 246 190 14
39924 -246 190 14 246 190 14 246 190 14 246 190 14
39925 -246 190 14 246 190 14 246 190 14 246 190 14
39926 -246 190 14 246 190 14 246 190 14 246 190 14
39927 -246 186 14 236 178 12 224 166 10 142 122 72
39928 - 46 46 46 18 18 18 6 6 6 0 0 0
39929 - 0 0 0 0 0 0 0 0 0 0 0 0
39930 - 0 0 0 0 0 0 0 0 0 0 0 0
39931 - 0 0 0 0 0 0 6 6 6 18 18 18
39932 - 50 50 50 109 106 95 192 133 9 224 166 10
39933 -242 186 14 246 190 14 246 190 14 246 190 14
39934 -246 190 14 246 190 14 246 190 14 246 190 14
39935 -246 190 14 246 190 14 246 190 14 246 190 14
39936 -246 190 14 246 190 14 246 190 14 246 190 14
39937 -242 186 14 226 184 13 210 162 10 142 110 46
39938 -226 226 226 253 253 253 253 253 253 253 253 253
39939 -253 253 253 253 253 253 253 253 253 253 253 253
39940 -253 253 253 253 253 253 253 253 253 253 253 253
39941 -198 198 198 66 66 66 2 2 6 2 2 6
39942 - 2 2 6 2 2 6 50 34 6 156 107 11
39943 -219 162 10 239 182 13 246 186 14 246 190 14
39944 -246 190 14 246 190 14 246 190 14 246 190 14
39945 -246 190 14 246 190 14 246 190 14 246 190 14
39946 -246 190 14 246 190 14 246 190 14 242 186 14
39947 -234 174 13 213 154 11 154 122 46 66 66 66
39948 - 30 30 30 10 10 10 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 0 0 0 6 6 6 22 22 22
39952 - 58 58 58 154 121 60 206 145 10 234 174 13
39953 -242 186 14 246 186 14 246 190 14 246 190 14
39954 -246 190 14 246 190 14 246 190 14 246 190 14
39955 -246 190 14 246 190 14 246 190 14 246 190 14
39956 -246 190 14 246 190 14 246 190 14 246 190 14
39957 -246 186 14 236 178 12 210 162 10 163 110 8
39958 - 61 42 6 138 138 138 218 218 218 250 250 250
39959 -253 253 253 253 253 253 253 253 253 250 250 250
39960 -242 242 242 210 210 210 144 144 144 66 66 66
39961 - 6 6 6 2 2 6 2 2 6 2 2 6
39962 - 2 2 6 2 2 6 61 42 6 163 110 8
39963 -216 158 10 236 178 12 246 190 14 246 190 14
39964 -246 190 14 246 190 14 246 190 14 246 190 14
39965 -246 190 14 246 190 14 246 190 14 246 190 14
39966 -246 190 14 239 182 13 230 174 11 216 158 10
39967 -190 142 34 124 112 88 70 70 70 38 38 38
39968 - 18 18 18 6 6 6 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 6 6 6 22 22 22
39972 - 62 62 62 168 124 44 206 145 10 224 166 10
39973 -236 178 12 239 182 13 242 186 14 242 186 14
39974 -246 186 14 246 190 14 246 190 14 246 190 14
39975 -246 190 14 246 190 14 246 190 14 246 190 14
39976 -246 190 14 246 190 14 246 190 14 246 190 14
39977 -246 190 14 236 178 12 216 158 10 175 118 6
39978 - 80 54 7 2 2 6 6 6 6 30 30 30
39979 - 54 54 54 62 62 62 50 50 50 38 38 38
39980 - 14 14 14 2 2 6 2 2 6 2 2 6
39981 - 2 2 6 2 2 6 2 2 6 2 2 6
39982 - 2 2 6 6 6 6 80 54 7 167 114 7
39983 -213 154 11 236 178 12 246 190 14 246 190 14
39984 -246 190 14 246 190 14 246 190 14 246 190 14
39985 -246 190 14 242 186 14 239 182 13 239 182 13
39986 -230 174 11 210 150 10 174 135 50 124 112 88
39987 - 82 82 82 54 54 54 34 34 34 18 18 18
39988 - 6 6 6 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 6 6 6 18 18 18
39992 - 50 50 50 158 118 36 192 133 9 200 144 11
39993 -216 158 10 219 162 10 224 166 10 226 170 11
39994 -230 174 11 236 178 12 239 182 13 239 182 13
39995 -242 186 14 246 186 14 246 190 14 246 190 14
39996 -246 190 14 246 190 14 246 190 14 246 190 14
39997 -246 186 14 230 174 11 210 150 10 163 110 8
39998 -104 69 6 10 10 10 2 2 6 2 2 6
39999 - 2 2 6 2 2 6 2 2 6 2 2 6
40000 - 2 2 6 2 2 6 2 2 6 2 2 6
40001 - 2 2 6 2 2 6 2 2 6 2 2 6
40002 - 2 2 6 6 6 6 91 60 6 167 114 7
40003 -206 145 10 230 174 11 242 186 14 246 190 14
40004 -246 190 14 246 190 14 246 186 14 242 186 14
40005 -239 182 13 230 174 11 224 166 10 213 154 11
40006 -180 133 36 124 112 88 86 86 86 58 58 58
40007 - 38 38 38 22 22 22 10 10 10 6 6 6
40008 - 0 0 0 0 0 0 0 0 0 0 0 0
40009 - 0 0 0 0 0 0 0 0 0 0 0 0
40010 - 0 0 0 0 0 0 0 0 0 0 0 0
40011 - 0 0 0 0 0 0 0 0 0 14 14 14
40012 - 34 34 34 70 70 70 138 110 50 158 118 36
40013 -167 114 7 180 123 7 192 133 9 197 138 11
40014 -200 144 11 206 145 10 213 154 11 219 162 10
40015 -224 166 10 230 174 11 239 182 13 242 186 14
40016 -246 186 14 246 186 14 246 186 14 246 186 14
40017 -239 182 13 216 158 10 185 133 11 152 99 6
40018 -104 69 6 18 14 6 2 2 6 2 2 6
40019 - 2 2 6 2 2 6 2 2 6 2 2 6
40020 - 2 2 6 2 2 6 2 2 6 2 2 6
40021 - 2 2 6 2 2 6 2 2 6 2 2 6
40022 - 2 2 6 6 6 6 80 54 7 152 99 6
40023 -192 133 9 219 162 10 236 178 12 239 182 13
40024 -246 186 14 242 186 14 239 182 13 236 178 12
40025 -224 166 10 206 145 10 192 133 9 154 121 60
40026 - 94 94 94 62 62 62 42 42 42 22 22 22
40027 - 14 14 14 6 6 6 0 0 0 0 0 0
40028 - 0 0 0 0 0 0 0 0 0 0 0 0
40029 - 0 0 0 0 0 0 0 0 0 0 0 0
40030 - 0 0 0 0 0 0 0 0 0 0 0 0
40031 - 0 0 0 0 0 0 0 0 0 6 6 6
40032 - 18 18 18 34 34 34 58 58 58 78 78 78
40033 -101 98 89 124 112 88 142 110 46 156 107 11
40034 -163 110 8 167 114 7 175 118 6 180 123 7
40035 -185 133 11 197 138 11 210 150 10 219 162 10
40036 -226 170 11 236 178 12 236 178 12 234 174 13
40037 -219 162 10 197 138 11 163 110 8 130 83 6
40038 - 91 60 6 10 10 10 2 2 6 2 2 6
40039 - 18 18 18 38 38 38 38 38 38 38 38 38
40040 - 38 38 38 38 38 38 38 38 38 38 38 38
40041 - 38 38 38 38 38 38 26 26 26 2 2 6
40042 - 2 2 6 6 6 6 70 47 6 137 92 6
40043 -175 118 6 200 144 11 219 162 10 230 174 11
40044 -234 174 13 230 174 11 219 162 10 210 150 10
40045 -192 133 9 163 110 8 124 112 88 82 82 82
40046 - 50 50 50 30 30 30 14 14 14 6 6 6
40047 - 0 0 0 0 0 0 0 0 0 0 0 0
40048 - 0 0 0 0 0 0 0 0 0 0 0 0
40049 - 0 0 0 0 0 0 0 0 0 0 0 0
40050 - 0 0 0 0 0 0 0 0 0 0 0 0
40051 - 0 0 0 0 0 0 0 0 0 0 0 0
40052 - 6 6 6 14 14 14 22 22 22 34 34 34
40053 - 42 42 42 58 58 58 74 74 74 86 86 86
40054 -101 98 89 122 102 70 130 98 46 121 87 25
40055 -137 92 6 152 99 6 163 110 8 180 123 7
40056 -185 133 11 197 138 11 206 145 10 200 144 11
40057 -180 123 7 156 107 11 130 83 6 104 69 6
40058 - 50 34 6 54 54 54 110 110 110 101 98 89
40059 - 86 86 86 82 82 82 78 78 78 78 78 78
40060 - 78 78 78 78 78 78 78 78 78 78 78 78
40061 - 78 78 78 82 82 82 86 86 86 94 94 94
40062 -106 106 106 101 101 101 86 66 34 124 80 6
40063 -156 107 11 180 123 7 192 133 9 200 144 11
40064 -206 145 10 200 144 11 192 133 9 175 118 6
40065 -139 102 15 109 106 95 70 70 70 42 42 42
40066 - 22 22 22 10 10 10 0 0 0 0 0 0
40067 - 0 0 0 0 0 0 0 0 0 0 0 0
40068 - 0 0 0 0 0 0 0 0 0 0 0 0
40069 - 0 0 0 0 0 0 0 0 0 0 0 0
40070 - 0 0 0 0 0 0 0 0 0 0 0 0
40071 - 0 0 0 0 0 0 0 0 0 0 0 0
40072 - 0 0 0 0 0 0 6 6 6 10 10 10
40073 - 14 14 14 22 22 22 30 30 30 38 38 38
40074 - 50 50 50 62 62 62 74 74 74 90 90 90
40075 -101 98 89 112 100 78 121 87 25 124 80 6
40076 -137 92 6 152 99 6 152 99 6 152 99 6
40077 -138 86 6 124 80 6 98 70 6 86 66 30
40078 -101 98 89 82 82 82 58 58 58 46 46 46
40079 - 38 38 38 34 34 34 34 34 34 34 34 34
40080 - 34 34 34 34 34 34 34 34 34 34 34 34
40081 - 34 34 34 34 34 34 38 38 38 42 42 42
40082 - 54 54 54 82 82 82 94 86 76 91 60 6
40083 -134 86 6 156 107 11 167 114 7 175 118 6
40084 -175 118 6 167 114 7 152 99 6 121 87 25
40085 -101 98 89 62 62 62 34 34 34 18 18 18
40086 - 6 6 6 0 0 0 0 0 0 0 0 0
40087 - 0 0 0 0 0 0 0 0 0 0 0 0
40088 - 0 0 0 0 0 0 0 0 0 0 0 0
40089 - 0 0 0 0 0 0 0 0 0 0 0 0
40090 - 0 0 0 0 0 0 0 0 0 0 0 0
40091 - 0 0 0 0 0 0 0 0 0 0 0 0
40092 - 0 0 0 0 0 0 0 0 0 0 0 0
40093 - 0 0 0 6 6 6 6 6 6 10 10 10
40094 - 18 18 18 22 22 22 30 30 30 42 42 42
40095 - 50 50 50 66 66 66 86 86 86 101 98 89
40096 -106 86 58 98 70 6 104 69 6 104 69 6
40097 -104 69 6 91 60 6 82 62 34 90 90 90
40098 - 62 62 62 38 38 38 22 22 22 14 14 14
40099 - 10 10 10 10 10 10 10 10 10 10 10 10
40100 - 10 10 10 10 10 10 6 6 6 10 10 10
40101 - 10 10 10 10 10 10 10 10 10 14 14 14
40102 - 22 22 22 42 42 42 70 70 70 89 81 66
40103 - 80 54 7 104 69 6 124 80 6 137 92 6
40104 -134 86 6 116 81 8 100 82 52 86 86 86
40105 - 58 58 58 30 30 30 14 14 14 6 6 6
40106 - 0 0 0 0 0 0 0 0 0 0 0 0
40107 - 0 0 0 0 0 0 0 0 0 0 0 0
40108 - 0 0 0 0 0 0 0 0 0 0 0 0
40109 - 0 0 0 0 0 0 0 0 0 0 0 0
40110 - 0 0 0 0 0 0 0 0 0 0 0 0
40111 - 0 0 0 0 0 0 0 0 0 0 0 0
40112 - 0 0 0 0 0 0 0 0 0 0 0 0
40113 - 0 0 0 0 0 0 0 0 0 0 0 0
40114 - 0 0 0 6 6 6 10 10 10 14 14 14
40115 - 18 18 18 26 26 26 38 38 38 54 54 54
40116 - 70 70 70 86 86 86 94 86 76 89 81 66
40117 - 89 81 66 86 86 86 74 74 74 50 50 50
40118 - 30 30 30 14 14 14 6 6 6 0 0 0
40119 - 0 0 0 0 0 0 0 0 0 0 0 0
40120 - 0 0 0 0 0 0 0 0 0 0 0 0
40121 - 0 0 0 0 0 0 0 0 0 0 0 0
40122 - 6 6 6 18 18 18 34 34 34 58 58 58
40123 - 82 82 82 89 81 66 89 81 66 89 81 66
40124 - 94 86 66 94 86 76 74 74 74 50 50 50
40125 - 26 26 26 14 14 14 6 6 6 0 0 0
40126 - 0 0 0 0 0 0 0 0 0 0 0 0
40127 - 0 0 0 0 0 0 0 0 0 0 0 0
40128 - 0 0 0 0 0 0 0 0 0 0 0 0
40129 - 0 0 0 0 0 0 0 0 0 0 0 0
40130 - 0 0 0 0 0 0 0 0 0 0 0 0
40131 - 0 0 0 0 0 0 0 0 0 0 0 0
40132 - 0 0 0 0 0 0 0 0 0 0 0 0
40133 - 0 0 0 0 0 0 0 0 0 0 0 0
40134 - 0 0 0 0 0 0 0 0 0 0 0 0
40135 - 6 6 6 6 6 6 14 14 14 18 18 18
40136 - 30 30 30 38 38 38 46 46 46 54 54 54
40137 - 50 50 50 42 42 42 30 30 30 18 18 18
40138 - 10 10 10 0 0 0 0 0 0 0 0 0
40139 - 0 0 0 0 0 0 0 0 0 0 0 0
40140 - 0 0 0 0 0 0 0 0 0 0 0 0
40141 - 0 0 0 0 0 0 0 0 0 0 0 0
40142 - 0 0 0 6 6 6 14 14 14 26 26 26
40143 - 38 38 38 50 50 50 58 58 58 58 58 58
40144 - 54 54 54 42 42 42 30 30 30 18 18 18
40145 - 10 10 10 0 0 0 0 0 0 0 0 0
40146 - 0 0 0 0 0 0 0 0 0 0 0 0
40147 - 0 0 0 0 0 0 0 0 0 0 0 0
40148 - 0 0 0 0 0 0 0 0 0 0 0 0
40149 - 0 0 0 0 0 0 0 0 0 0 0 0
40150 - 0 0 0 0 0 0 0 0 0 0 0 0
40151 - 0 0 0 0 0 0 0 0 0 0 0 0
40152 - 0 0 0 0 0 0 0 0 0 0 0 0
40153 - 0 0 0 0 0 0 0 0 0 0 0 0
40154 - 0 0 0 0 0 0 0 0 0 0 0 0
40155 - 0 0 0 0 0 0 0 0 0 6 6 6
40156 - 6 6 6 10 10 10 14 14 14 18 18 18
40157 - 18 18 18 14 14 14 10 10 10 6 6 6
40158 - 0 0 0 0 0 0 0 0 0 0 0 0
40159 - 0 0 0 0 0 0 0 0 0 0 0 0
40160 - 0 0 0 0 0 0 0 0 0 0 0 0
40161 - 0 0 0 0 0 0 0 0 0 0 0 0
40162 - 0 0 0 0 0 0 0 0 0 6 6 6
40163 - 14 14 14 18 18 18 22 22 22 22 22 22
40164 - 18 18 18 14 14 14 10 10 10 6 6 6
40165 - 0 0 0 0 0 0 0 0 0 0 0 0
40166 - 0 0 0 0 0 0 0 0 0 0 0 0
40167 - 0 0 0 0 0 0 0 0 0 0 0 0
40168 - 0 0 0 0 0 0 0 0 0 0 0 0
40169 - 0 0 0 0 0 0 0 0 0 0 0 0
40170 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40172 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40173 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40174 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
40178 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40179 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40180 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40183 +4 4 4 4 4 4
40184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40187 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40188 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
40192 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40193 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40194 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40197 +4 4 4 4 4 4
40198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40201 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40202 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40206 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40207 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40208 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40211 +4 4 4 4 4 4
40212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40215 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40216 +4 4 4 4 4 4 4 4 4 4 4 4 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 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40220 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40221 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40222 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40224 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40225 +4 4 4 4 4 4
40226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40229 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40230 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
40233 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40234 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40235 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40237 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40238 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40239 +4 4 4 4 4 4
40240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40248 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40249 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40250 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40251 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40252 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40253 +4 4 4 4 4 4
40254 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40257 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40258 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
40259 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
40260 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40261 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40262 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40263 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
40264 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40265 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
40266 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40267 +4 4 4 4 4 4
40268 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40269 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40270 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40271 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40272 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
40273 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
40274 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40275 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40276 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40277 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
40278 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
40279 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
40280 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40281 +4 4 4 4 4 4
40282 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40284 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40285 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40286 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
40287 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
40288 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40289 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40290 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40291 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
40292 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
40293 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
40294 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
40295 +4 4 4 4 4 4
40296 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40297 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40298 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40299 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
40300 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
40301 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
40302 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
40303 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40304 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40305 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
40306 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
40307 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
40308 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
40309 +4 4 4 4 4 4
40310 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40311 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40312 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40313 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
40314 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
40315 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
40316 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
40317 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40318 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
40319 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
40320 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
40321 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
40322 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
40323 +4 4 4 4 4 4
40324 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40325 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40326 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40327 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
40328 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
40329 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
40330 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
40331 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
40332 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
40333 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
40334 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
40335 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
40336 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
40337 +4 4 4 4 4 4
40338 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40339 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40340 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
40341 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
40342 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
40343 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
40344 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
40345 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
40346 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
40347 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
40348 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
40349 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
40350 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
40351 +4 4 4 4 4 4
40352 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40353 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40354 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
40355 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
40356 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
40357 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
40358 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
40359 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
40360 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
40361 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
40362 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
40363 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
40364 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
40365 +4 4 4 4 4 4
40366 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40367 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40368 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
40369 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
40370 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
40371 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
40372 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
40373 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
40374 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
40375 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
40376 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
40377 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
40378 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40379 +4 4 4 4 4 4
40380 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40381 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40382 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
40383 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
40384 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
40385 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
40386 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
40387 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
40388 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
40389 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
40390 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
40391 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
40392 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
40393 +4 4 4 4 4 4
40394 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40395 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
40396 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
40397 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
40398 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
40399 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
40400 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
40401 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
40402 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
40403 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
40404 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
40405 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
40406 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
40407 +4 4 4 4 4 4
40408 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40409 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
40410 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
40411 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
40412 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
40413 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
40414 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
40415 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
40416 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
40417 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
40418 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
40419 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
40420 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
40421 +0 0 0 4 4 4
40422 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40423 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
40424 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
40425 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
40426 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
40427 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
40428 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
40429 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
40430 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
40431 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
40432 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
40433 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
40434 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
40435 +2 0 0 0 0 0
40436 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
40437 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
40438 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
40439 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
40440 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
40441 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
40442 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
40443 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
40444 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
40445 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
40446 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
40447 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
40448 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
40449 +37 38 37 0 0 0
40450 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40451 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
40452 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
40453 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
40454 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
40455 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
40456 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
40457 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
40458 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
40459 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
40460 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
40461 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
40462 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
40463 +85 115 134 4 0 0
40464 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
40465 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
40466 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
40467 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
40468 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
40469 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
40470 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
40471 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
40472 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
40473 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
40474 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
40475 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
40476 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
40477 +60 73 81 4 0 0
40478 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
40479 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
40480 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
40481 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
40482 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
40483 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
40484 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
40485 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
40486 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
40487 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
40488 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
40489 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
40490 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
40491 +16 19 21 4 0 0
40492 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
40493 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
40494 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
40495 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
40496 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
40497 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
40498 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
40499 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
40500 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
40501 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
40502 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
40503 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
40504 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
40505 +4 0 0 4 3 3
40506 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
40507 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
40508 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
40509 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
40510 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
40511 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
40512 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
40513 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
40514 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
40515 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
40516 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
40517 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
40518 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
40519 +3 2 2 4 4 4
40520 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
40521 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
40522 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
40523 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40524 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
40525 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
40526 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
40527 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
40528 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
40529 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
40530 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
40531 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
40532 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
40533 +4 4 4 4 4 4
40534 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
40535 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
40536 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
40537 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
40538 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
40539 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
40540 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
40541 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
40542 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
40543 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
40544 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
40545 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
40546 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
40547 +4 4 4 4 4 4
40548 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
40549 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
40550 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
40551 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
40552 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
40553 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
40554 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
40555 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
40556 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
40557 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
40558 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
40559 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
40560 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
40561 +5 5 5 5 5 5
40562 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
40563 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
40564 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
40565 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
40566 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
40567 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40568 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
40569 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
40570 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
40571 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
40572 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
40573 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
40574 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
40575 +5 5 5 4 4 4
40576 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
40577 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
40578 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
40579 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
40580 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40581 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
40582 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
40583 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
40584 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
40585 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
40586 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
40587 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
40588 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40589 +4 4 4 4 4 4
40590 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
40591 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
40592 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
40593 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
40594 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
40595 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40596 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40597 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
40598 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
40599 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
40600 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
40601 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
40602 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40603 +4 4 4 4 4 4
40604 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
40605 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
40606 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
40607 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
40608 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40609 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
40610 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
40611 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
40612 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
40613 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
40614 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
40615 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40616 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40617 +4 4 4 4 4 4
40618 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
40619 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
40620 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
40621 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
40622 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40623 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40624 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40625 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
40626 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
40627 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
40628 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
40629 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40630 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40631 +4 4 4 4 4 4
40632 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
40633 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
40634 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
40635 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
40636 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40637 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
40638 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
40639 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
40640 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
40641 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
40642 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40643 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40644 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40645 +4 4 4 4 4 4
40646 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
40647 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
40648 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
40649 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
40650 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40651 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
40652 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
40653 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
40654 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
40655 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
40656 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
40657 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40658 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40659 +4 4 4 4 4 4
40660 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
40661 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
40662 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
40663 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
40664 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40665 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
40666 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
40667 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
40668 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
40669 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
40670 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
40671 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40672 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40673 +4 4 4 4 4 4
40674 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
40675 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
40676 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
40677 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
40678 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
40679 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
40680 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
40681 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
40682 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
40683 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
40684 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40685 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40686 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40687 +4 4 4 4 4 4
40688 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
40689 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
40690 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
40691 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
40692 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40693 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
40694 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
40695 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
40696 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
40697 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
40698 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40699 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40700 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40701 +4 4 4 4 4 4
40702 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
40703 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
40704 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
40705 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
40706 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40707 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
40708 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
40709 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
40710 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
40711 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
40712 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40713 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40714 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40715 +4 4 4 4 4 4
40716 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
40717 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
40718 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
40719 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
40720 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40721 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
40722 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
40723 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
40724 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
40725 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40726 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40727 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40728 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40729 +4 4 4 4 4 4
40730 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
40731 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
40732 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
40733 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
40734 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
40735 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
40736 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
40737 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
40738 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40739 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40740 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40741 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40742 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40743 +4 4 4 4 4 4
40744 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
40745 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
40746 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
40747 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
40748 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40749 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
40750 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
40751 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
40752 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
40753 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40754 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40755 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40756 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40757 +4 4 4 4 4 4
40758 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
40759 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
40760 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
40761 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
40762 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
40763 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
40764 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
40765 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
40766 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40767 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40768 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40769 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40770 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40771 +4 4 4 4 4 4
40772 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
40773 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
40774 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
40775 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
40776 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
40777 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
40778 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
40779 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
40780 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
40781 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40782 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40783 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40784 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40785 +4 4 4 4 4 4
40786 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
40787 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
40788 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
40789 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
40790 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
40791 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
40792 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
40793 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
40794 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40795 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40796 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40797 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40798 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40799 +4 4 4 4 4 4
40800 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
40801 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
40802 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
40803 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
40804 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
40805 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
40806 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
40807 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
40808 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
40809 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40810 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40811 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40812 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40813 +4 4 4 4 4 4
40814 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
40815 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
40816 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
40817 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
40818 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
40819 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
40820 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
40821 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
40822 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40823 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40824 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40825 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40826 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40827 +4 4 4 4 4 4
40828 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40829 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
40830 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
40831 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
40832 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
40833 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
40834 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
40835 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
40836 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
40837 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40838 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40839 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40840 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40841 +4 4 4 4 4 4
40842 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
40843 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
40844 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
40845 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
40846 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
40847 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
40848 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40849 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
40850 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
40851 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40852 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40853 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40854 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40855 +4 4 4 4 4 4
40856 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40857 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
40858 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
40859 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
40860 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
40861 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
40862 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40863 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
40864 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
40865 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40866 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40867 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40868 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40869 +4 4 4 4 4 4
40870 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
40871 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
40872 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
40873 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
40874 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
40875 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
40876 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
40877 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
40878 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
40879 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40880 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40881 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40882 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40883 +4 4 4 4 4 4
40884 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40885 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
40886 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
40887 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
40888 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
40889 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
40890 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
40891 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
40892 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
40893 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40894 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40895 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40896 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40897 +4 4 4 4 4 4
40898 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
40899 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
40900 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
40901 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
40902 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
40903 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
40904 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
40905 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
40906 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
40907 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40908 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40909 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40910 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40911 +4 4 4 4 4 4
40912 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
40913 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
40914 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
40915 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
40916 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
40917 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
40918 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
40919 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
40920 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
40921 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40922 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40923 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40924 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40925 +4 4 4 4 4 4
40926 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
40927 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
40928 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
40929 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
40930 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
40931 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
40932 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
40933 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
40934 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
40935 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
40936 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40937 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40938 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40939 +4 4 4 4 4 4
40940 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
40941 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
40942 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
40943 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
40944 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
40945 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
40946 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
40947 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
40948 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
40949 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
40950 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40951 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40952 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40953 +4 4 4 4 4 4
40954 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
40955 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
40956 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
40957 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
40958 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
40959 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
40960 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40961 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
40962 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
40963 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
40964 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40965 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40966 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40967 +4 4 4 4 4 4
40968 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
40969 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
40970 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
40971 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
40972 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
40973 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
40974 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
40975 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
40976 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
40977 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
40978 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40979 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40980 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40981 +4 4 4 4 4 4
40982 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
40983 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
40984 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
40985 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
40986 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
40987 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
40988 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
40989 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
40990 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
40991 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
40992 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40993 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40994 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40995 +4 4 4 4 4 4
40996 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
40997 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
40998 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
40999 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
41000 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
41001 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
41002 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
41003 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
41004 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
41005 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41006 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41007 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41008 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41009 +4 4 4 4 4 4
41010 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
41011 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
41012 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
41013 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
41014 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
41015 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
41016 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
41017 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
41018 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
41019 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41020 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41021 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41022 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41023 +4 4 4 4 4 4
41024 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
41025 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
41026 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
41027 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
41028 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
41029 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
41030 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
41031 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
41032 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41033 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41034 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41035 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41036 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41037 +4 4 4 4 4 4
41038 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
41039 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41040 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
41041 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41042 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
41043 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
41044 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
41045 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
41046 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
41047 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41048 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41049 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41050 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41051 +4 4 4 4 4 4
41052 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
41053 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
41054 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
41055 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
41056 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
41057 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
41058 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
41059 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
41060 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
41061 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41062 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41063 +4 4 4 4 4 4 4 4 4 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
41066 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41067 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
41068 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
41069 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
41070 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
41071 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
41072 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
41073 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
41074 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41075 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41076 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41077 +4 4 4 4 4 4 4 4 4 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
41080 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
41081 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
41082 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41083 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
41084 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
41085 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
41086 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
41087 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
41088 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41089 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41090 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41091 +4 4 4 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
41094 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41095 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
41096 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
41097 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
41098 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
41099 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
41100 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
41101 +6 6 6 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4
41104 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
41108 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41109 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
41110 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41111 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
41112 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
41113 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
41114 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
41115 +4 0 0 4 3 3 6 6 6 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 4 4 4 4 4 4
41118 +4 4 4 4 4 4 4 4 4 4 4 4 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
41122 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41123 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
41124 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
41125 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
41126 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
41127 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
41128 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
41129 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
41130 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41131 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41132 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41133 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41134 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41135 +4 4 4 4 4 4
41136 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41137 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41138 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
41139 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41140 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
41141 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
41142 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
41143 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41144 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41145 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41146 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41148 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41149 +4 4 4 4 4 4
41150 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41151 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41152 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41153 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
41154 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
41155 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
41156 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
41157 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41158 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41159 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41160 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41161 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41162 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41163 +4 4 4 4 4 4
41164 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41165 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41166 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41167 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41168 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
41169 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
41170 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
41171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41172 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41173 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41174 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41177 +4 4 4 4 4 4
41178 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41179 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41180 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41181 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41182 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41183 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
41184 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
41185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41187 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41188 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41191 +4 4 4 4 4 4
41192 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41193 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41194 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41195 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41196 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41197 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41198 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
41199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41201 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41202 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41205 +4 4 4 4 4 4
41206 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41207 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41208 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41209 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
41210 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
41211 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
41212 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
41213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41215 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41216 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41219 +4 4 4 4 4 4
41220 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41221 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41222 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41224 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
41225 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41226 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41229 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41230 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41232 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41233 +4 4 4 4 4 4
41234 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41235 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41237 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41238 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
41239 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
41240 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41247 +4 4 4 4 4 4
41248 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41249 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41250 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41251 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41252 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
41253 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
41254 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41257 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41258 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41260 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41261 +4 4 4 4 4 4
41262 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41263 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41264 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41266 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
41267 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
41268 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41269 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41270 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41271 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41272 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41274 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41275 +4 4 4 4 4 4
41276 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41277 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41278 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41279 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41280 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41281 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
41282 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41284 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41285 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41286 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41288 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41289 +4 4 4 4 4 4
41290 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
41291 index a159b63..4ab532d 100644
41292 --- a/drivers/video/udlfb.c
41293 +++ b/drivers/video/udlfb.c
41294 @@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
41295 dlfb_urb_completion(urb);
41296
41297 error:
41298 - atomic_add(bytes_sent, &dev->bytes_sent);
41299 - atomic_add(bytes_identical, &dev->bytes_identical);
41300 - atomic_add(width*height*2, &dev->bytes_rendered);
41301 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41302 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41303 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
41304 end_cycles = get_cycles();
41305 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41306 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41307 >> 10)), /* Kcycles */
41308 &dev->cpu_kcycles_used);
41309
41310 @@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
41311 dlfb_urb_completion(urb);
41312
41313 error:
41314 - atomic_add(bytes_sent, &dev->bytes_sent);
41315 - atomic_add(bytes_identical, &dev->bytes_identical);
41316 - atomic_add(bytes_rendered, &dev->bytes_rendered);
41317 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41318 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41319 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
41320 end_cycles = get_cycles();
41321 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41322 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41323 >> 10)), /* Kcycles */
41324 &dev->cpu_kcycles_used);
41325 }
41326 @@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
41327 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41328 struct dlfb_data *dev = fb_info->par;
41329 return snprintf(buf, PAGE_SIZE, "%u\n",
41330 - atomic_read(&dev->bytes_rendered));
41331 + atomic_read_unchecked(&dev->bytes_rendered));
41332 }
41333
41334 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41335 @@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41336 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41337 struct dlfb_data *dev = fb_info->par;
41338 return snprintf(buf, PAGE_SIZE, "%u\n",
41339 - atomic_read(&dev->bytes_identical));
41340 + atomic_read_unchecked(&dev->bytes_identical));
41341 }
41342
41343 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41344 @@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41345 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41346 struct dlfb_data *dev = fb_info->par;
41347 return snprintf(buf, PAGE_SIZE, "%u\n",
41348 - atomic_read(&dev->bytes_sent));
41349 + atomic_read_unchecked(&dev->bytes_sent));
41350 }
41351
41352 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41353 @@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41354 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41355 struct dlfb_data *dev = fb_info->par;
41356 return snprintf(buf, PAGE_SIZE, "%u\n",
41357 - atomic_read(&dev->cpu_kcycles_used));
41358 + atomic_read_unchecked(&dev->cpu_kcycles_used));
41359 }
41360
41361 static ssize_t edid_show(
41362 @@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
41363 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41364 struct dlfb_data *dev = fb_info->par;
41365
41366 - atomic_set(&dev->bytes_rendered, 0);
41367 - atomic_set(&dev->bytes_identical, 0);
41368 - atomic_set(&dev->bytes_sent, 0);
41369 - atomic_set(&dev->cpu_kcycles_used, 0);
41370 + atomic_set_unchecked(&dev->bytes_rendered, 0);
41371 + atomic_set_unchecked(&dev->bytes_identical, 0);
41372 + atomic_set_unchecked(&dev->bytes_sent, 0);
41373 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
41374
41375 return count;
41376 }
41377 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
41378 index b0e2a42..e2df3ad 100644
41379 --- a/drivers/video/uvesafb.c
41380 +++ b/drivers/video/uvesafb.c
41381 @@ -19,6 +19,7 @@
41382 #include <linux/io.h>
41383 #include <linux/mutex.h>
41384 #include <linux/slab.h>
41385 +#include <linux/moduleloader.h>
41386 #include <video/edid.h>
41387 #include <video/uvesafb.h>
41388 #ifdef CONFIG_X86
41389 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
41390 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
41391 par->pmi_setpal = par->ypan = 0;
41392 } else {
41393 +
41394 +#ifdef CONFIG_PAX_KERNEXEC
41395 +#ifdef CONFIG_MODULES
41396 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
41397 +#endif
41398 + if (!par->pmi_code) {
41399 + par->pmi_setpal = par->ypan = 0;
41400 + return 0;
41401 + }
41402 +#endif
41403 +
41404 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
41405 + task->t.regs.edi);
41406 +
41407 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41408 + pax_open_kernel();
41409 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
41410 + pax_close_kernel();
41411 +
41412 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
41413 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
41414 +#else
41415 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
41416 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
41417 +#endif
41418 +
41419 printk(KERN_INFO "uvesafb: protected mode interface info at "
41420 "%04x:%04x\n",
41421 (u16)task->t.regs.es, (u16)task->t.regs.edi);
41422 @@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
41423 par->ypan = ypan;
41424
41425 if (par->pmi_setpal || par->ypan) {
41426 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
41427 if (__supported_pte_mask & _PAGE_NX) {
41428 par->pmi_setpal = par->ypan = 0;
41429 printk(KERN_WARNING "uvesafb: NX protection is actively."
41430 "We have better not to use the PMI.\n");
41431 - } else {
41432 + } else
41433 +#endif
41434 uvesafb_vbe_getpmi(task, par);
41435 - }
41436 }
41437 #else
41438 /* The protected mode interface is not available on non-x86. */
41439 @@ -1836,6 +1860,11 @@ out:
41440 if (par->vbe_modes)
41441 kfree(par->vbe_modes);
41442
41443 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41444 + if (par->pmi_code)
41445 + module_free_exec(NULL, par->pmi_code);
41446 +#endif
41447 +
41448 framebuffer_release(info);
41449 return err;
41450 }
41451 @@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
41452 kfree(par->vbe_state_orig);
41453 if (par->vbe_state_saved)
41454 kfree(par->vbe_state_saved);
41455 +
41456 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41457 + if (par->pmi_code)
41458 + module_free_exec(NULL, par->pmi_code);
41459 +#endif
41460 +
41461 }
41462
41463 framebuffer_release(info);
41464 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
41465 index 501b340..86bd4cf 100644
41466 --- a/drivers/video/vesafb.c
41467 +++ b/drivers/video/vesafb.c
41468 @@ -9,6 +9,7 @@
41469 */
41470
41471 #include <linux/module.h>
41472 +#include <linux/moduleloader.h>
41473 #include <linux/kernel.h>
41474 #include <linux/errno.h>
41475 #include <linux/string.h>
41476 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
41477 static int vram_total __initdata; /* Set total amount of memory */
41478 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
41479 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
41480 -static void (*pmi_start)(void) __read_mostly;
41481 -static void (*pmi_pal) (void) __read_mostly;
41482 +static void (*pmi_start)(void) __read_only;
41483 +static void (*pmi_pal) (void) __read_only;
41484 static int depth __read_mostly;
41485 static int vga_compat __read_mostly;
41486 /* --------------------------------------------------------------------- */
41487 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
41488 unsigned int size_vmode;
41489 unsigned int size_remap;
41490 unsigned int size_total;
41491 + void *pmi_code = NULL;
41492
41493 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
41494 return -ENODEV;
41495 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
41496 size_remap = size_total;
41497 vesafb_fix.smem_len = size_remap;
41498
41499 -#ifndef __i386__
41500 - screen_info.vesapm_seg = 0;
41501 -#endif
41502 -
41503 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
41504 printk(KERN_WARNING
41505 "vesafb: cannot reserve video memory at 0x%lx\n",
41506 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
41507 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
41508 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
41509
41510 +#ifdef __i386__
41511 +
41512 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41513 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
41514 + if (!pmi_code)
41515 +#elif !defined(CONFIG_PAX_KERNEXEC)
41516 + if (0)
41517 +#endif
41518 +
41519 +#endif
41520 + screen_info.vesapm_seg = 0;
41521 +
41522 if (screen_info.vesapm_seg) {
41523 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
41524 - screen_info.vesapm_seg,screen_info.vesapm_off);
41525 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
41526 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
41527 }
41528
41529 if (screen_info.vesapm_seg < 0xc000)
41530 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
41531
41532 if (ypan || pmi_setpal) {
41533 unsigned short *pmi_base;
41534 +
41535 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
41536 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
41537 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
41538 +
41539 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41540 + pax_open_kernel();
41541 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
41542 +#else
41543 + pmi_code = pmi_base;
41544 +#endif
41545 +
41546 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
41547 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
41548 +
41549 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41550 + pmi_start = ktva_ktla(pmi_start);
41551 + pmi_pal = ktva_ktla(pmi_pal);
41552 + pax_close_kernel();
41553 +#endif
41554 +
41555 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
41556 if (pmi_base[3]) {
41557 printk(KERN_INFO "vesafb: pmi: ports = ");
41558 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
41559 info->node, info->fix.id);
41560 return 0;
41561 err:
41562 +
41563 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41564 + module_free_exec(NULL, pmi_code);
41565 +#endif
41566 +
41567 if (info->screen_base)
41568 iounmap(info->screen_base);
41569 framebuffer_release(info);
41570 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
41571 index 88714ae..16c2e11 100644
41572 --- a/drivers/video/via/via_clock.h
41573 +++ b/drivers/video/via/via_clock.h
41574 @@ -56,7 +56,7 @@ struct via_clock {
41575
41576 void (*set_engine_pll_state)(u8 state);
41577 void (*set_engine_pll)(struct via_pll_config config);
41578 -};
41579 +} __no_const;
41580
41581
41582 static inline u32 get_pll_internal_frequency(u32 ref_freq,
41583 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
41584 index e56c934..fc22f4b 100644
41585 --- a/drivers/xen/xen-pciback/conf_space.h
41586 +++ b/drivers/xen/xen-pciback/conf_space.h
41587 @@ -44,15 +44,15 @@ struct config_field {
41588 struct {
41589 conf_dword_write write;
41590 conf_dword_read read;
41591 - } dw;
41592 + } __no_const dw;
41593 struct {
41594 conf_word_write write;
41595 conf_word_read read;
41596 - } w;
41597 + } __no_const w;
41598 struct {
41599 conf_byte_write write;
41600 conf_byte_read read;
41601 - } b;
41602 + } __no_const b;
41603 } u;
41604 struct list_head list;
41605 };
41606 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
41607 index 014c8dd..6f3dfe6 100644
41608 --- a/fs/9p/vfs_inode.c
41609 +++ b/fs/9p/vfs_inode.c
41610 @@ -1303,7 +1303,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
41611 void
41612 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
41613 {
41614 - char *s = nd_get_link(nd);
41615 + const char *s = nd_get_link(nd);
41616
41617 p9_debug(P9_DEBUG_VFS, " %s %s\n",
41618 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
41619 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
41620 index e95d1b6..3454244 100644
41621 --- a/fs/Kconfig.binfmt
41622 +++ b/fs/Kconfig.binfmt
41623 @@ -89,7 +89,7 @@ config HAVE_AOUT
41624
41625 config BINFMT_AOUT
41626 tristate "Kernel support for a.out and ECOFF binaries"
41627 - depends on HAVE_AOUT
41628 + depends on HAVE_AOUT && BROKEN
41629 ---help---
41630 A.out (Assembler.OUTput) is a set of formats for libraries and
41631 executables used in the earliest versions of UNIX. Linux used
41632 diff --git a/fs/aio.c b/fs/aio.c
41633 index e7f2fad..15ad8a4 100644
41634 --- a/fs/aio.c
41635 +++ b/fs/aio.c
41636 @@ -118,7 +118,7 @@ static int aio_setup_ring(struct kioctx *ctx)
41637 size += sizeof(struct io_event) * nr_events;
41638 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
41639
41640 - if (nr_pages < 0)
41641 + if (nr_pages <= 0)
41642 return -EINVAL;
41643
41644 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
41645 @@ -1440,18 +1440,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
41646 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
41647 {
41648 ssize_t ret;
41649 + struct iovec iovstack;
41650
41651 #ifdef CONFIG_COMPAT
41652 if (compat)
41653 ret = compat_rw_copy_check_uvector(type,
41654 (struct compat_iovec __user *)kiocb->ki_buf,
41655 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
41656 + kiocb->ki_nbytes, 1, &iovstack,
41657 &kiocb->ki_iovec, 1);
41658 else
41659 #endif
41660 ret = rw_copy_check_uvector(type,
41661 (struct iovec __user *)kiocb->ki_buf,
41662 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
41663 + kiocb->ki_nbytes, 1, &iovstack,
41664 &kiocb->ki_iovec, 1);
41665 if (ret < 0)
41666 goto out;
41667 @@ -1460,6 +1461,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
41668 if (ret < 0)
41669 goto out;
41670
41671 + if (kiocb->ki_iovec == &iovstack) {
41672 + kiocb->ki_inline_vec = iovstack;
41673 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
41674 + }
41675 kiocb->ki_nr_segs = kiocb->ki_nbytes;
41676 kiocb->ki_cur_seg = 0;
41677 /* ki_nbytes/left now reflect bytes instead of segs */
41678 diff --git a/fs/attr.c b/fs/attr.c
41679 index d94d1b6..f9bccd6 100644
41680 --- a/fs/attr.c
41681 +++ b/fs/attr.c
41682 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
41683 unsigned long limit;
41684
41685 limit = rlimit(RLIMIT_FSIZE);
41686 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
41687 if (limit != RLIM_INFINITY && offset > limit)
41688 goto out_sig;
41689 if (offset > inode->i_sb->s_maxbytes)
41690 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
41691 index da8876d..9f3e6d8 100644
41692 --- a/fs/autofs4/waitq.c
41693 +++ b/fs/autofs4/waitq.c
41694 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
41695 {
41696 unsigned long sigpipe, flags;
41697 mm_segment_t fs;
41698 - const char *data = (const char *)addr;
41699 + const char __user *data = (const char __force_user *)addr;
41700 ssize_t wr = 0;
41701
41702 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
41703 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
41704 index e18da23..affc30e 100644
41705 --- a/fs/befs/linuxvfs.c
41706 +++ b/fs/befs/linuxvfs.c
41707 @@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
41708 {
41709 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
41710 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
41711 - char *link = nd_get_link(nd);
41712 + const char *link = nd_get_link(nd);
41713 if (!IS_ERR(link))
41714 kfree(link);
41715 }
41716 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
41717 index d146e18..12d1bd1 100644
41718 --- a/fs/binfmt_aout.c
41719 +++ b/fs/binfmt_aout.c
41720 @@ -16,6 +16,7 @@
41721 #include <linux/string.h>
41722 #include <linux/fs.h>
41723 #include <linux/file.h>
41724 +#include <linux/security.h>
41725 #include <linux/stat.h>
41726 #include <linux/fcntl.h>
41727 #include <linux/ptrace.h>
41728 @@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
41729 #endif
41730 # define START_STACK(u) ((void __user *)u.start_stack)
41731
41732 + memset(&dump, 0, sizeof(dump));
41733 +
41734 fs = get_fs();
41735 set_fs(KERNEL_DS);
41736 has_dumped = 1;
41737 @@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
41738
41739 /* If the size of the dump file exceeds the rlimit, then see what would happen
41740 if we wrote the stack, but not the data area. */
41741 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
41742 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
41743 dump.u_dsize = 0;
41744
41745 /* Make sure we have enough room to write the stack and data areas. */
41746 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
41747 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
41748 dump.u_ssize = 0;
41749
41750 @@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41751 rlim = rlimit(RLIMIT_DATA);
41752 if (rlim >= RLIM_INFINITY)
41753 rlim = ~0;
41754 +
41755 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
41756 if (ex.a_data + ex.a_bss > rlim)
41757 return -ENOMEM;
41758
41759 @@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41760
41761 install_exec_creds(bprm);
41762
41763 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
41764 + current->mm->pax_flags = 0UL;
41765 +#endif
41766 +
41767 +#ifdef CONFIG_PAX_PAGEEXEC
41768 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
41769 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
41770 +
41771 +#ifdef CONFIG_PAX_EMUTRAMP
41772 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
41773 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
41774 +#endif
41775 +
41776 +#ifdef CONFIG_PAX_MPROTECT
41777 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
41778 + current->mm->pax_flags |= MF_PAX_MPROTECT;
41779 +#endif
41780 +
41781 + }
41782 +#endif
41783 +
41784 if (N_MAGIC(ex) == OMAGIC) {
41785 unsigned long text_addr, map_size;
41786 loff_t pos;
41787 @@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
41788 }
41789
41790 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
41791 - PROT_READ | PROT_WRITE | PROT_EXEC,
41792 + PROT_READ | PROT_WRITE,
41793 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
41794 fd_offset + ex.a_text);
41795 if (error != N_DATADDR(ex)) {
41796 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
41797 index 16f7354..666524e 100644
41798 --- a/fs/binfmt_elf.c
41799 +++ b/fs/binfmt_elf.c
41800 @@ -32,6 +32,7 @@
41801 #include <linux/elf.h>
41802 #include <linux/utsname.h>
41803 #include <linux/coredump.h>
41804 +#include <linux/xattr.h>
41805 #include <asm/uaccess.h>
41806 #include <asm/param.h>
41807 #include <asm/page.h>
41808 @@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
41809 #define elf_core_dump NULL
41810 #endif
41811
41812 +#ifdef CONFIG_PAX_MPROTECT
41813 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
41814 +#endif
41815 +
41816 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
41817 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
41818 #else
41819 @@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
41820 .load_binary = load_elf_binary,
41821 .load_shlib = load_elf_library,
41822 .core_dump = elf_core_dump,
41823 +
41824 +#ifdef CONFIG_PAX_MPROTECT
41825 + .handle_mprotect= elf_handle_mprotect,
41826 +#endif
41827 +
41828 .min_coredump = ELF_EXEC_PAGESIZE,
41829 };
41830
41831 @@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
41832
41833 static int set_brk(unsigned long start, unsigned long end)
41834 {
41835 + unsigned long e = end;
41836 +
41837 start = ELF_PAGEALIGN(start);
41838 end = ELF_PAGEALIGN(end);
41839 if (end > start) {
41840 @@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
41841 if (BAD_ADDR(addr))
41842 return addr;
41843 }
41844 - current->mm->start_brk = current->mm->brk = end;
41845 + current->mm->start_brk = current->mm->brk = e;
41846 return 0;
41847 }
41848
41849 @@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
41850 elf_addr_t __user *u_rand_bytes;
41851 const char *k_platform = ELF_PLATFORM;
41852 const char *k_base_platform = ELF_BASE_PLATFORM;
41853 - unsigned char k_rand_bytes[16];
41854 + u32 k_rand_bytes[4];
41855 int items;
41856 elf_addr_t *elf_info;
41857 int ei_index = 0;
41858 const struct cred *cred = current_cred();
41859 struct vm_area_struct *vma;
41860 + unsigned long saved_auxv[AT_VECTOR_SIZE];
41861
41862 /*
41863 * In some cases (e.g. Hyper-Threading), we want to avoid L1
41864 @@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
41865 * Generate 16 random bytes for userspace PRNG seeding.
41866 */
41867 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
41868 - u_rand_bytes = (elf_addr_t __user *)
41869 - STACK_ALLOC(p, sizeof(k_rand_bytes));
41870 + srandom32(k_rand_bytes[0] ^ random32());
41871 + srandom32(k_rand_bytes[1] ^ random32());
41872 + srandom32(k_rand_bytes[2] ^ random32());
41873 + srandom32(k_rand_bytes[3] ^ random32());
41874 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
41875 + u_rand_bytes = (elf_addr_t __user *) p;
41876 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
41877 return -EFAULT;
41878
41879 @@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
41880 return -EFAULT;
41881 current->mm->env_end = p;
41882
41883 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
41884 +
41885 /* Put the elf_info on the stack in the right place. */
41886 sp = (elf_addr_t __user *)envp + 1;
41887 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
41888 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
41889 return -EFAULT;
41890 return 0;
41891 }
41892 @@ -380,10 +399,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
41893 {
41894 struct elf_phdr *elf_phdata;
41895 struct elf_phdr *eppnt;
41896 - unsigned long load_addr = 0;
41897 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
41898 int load_addr_set = 0;
41899 unsigned long last_bss = 0, elf_bss = 0;
41900 - unsigned long error = ~0UL;
41901 + unsigned long error = -EINVAL;
41902 unsigned long total_size;
41903 int retval, i, size;
41904
41905 @@ -429,6 +448,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
41906 goto out_close;
41907 }
41908
41909 +#ifdef CONFIG_PAX_SEGMEXEC
41910 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
41911 + pax_task_size = SEGMEXEC_TASK_SIZE;
41912 +#endif
41913 +
41914 eppnt = elf_phdata;
41915 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
41916 if (eppnt->p_type == PT_LOAD) {
41917 @@ -472,8 +496,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
41918 k = load_addr + eppnt->p_vaddr;
41919 if (BAD_ADDR(k) ||
41920 eppnt->p_filesz > eppnt->p_memsz ||
41921 - eppnt->p_memsz > TASK_SIZE ||
41922 - TASK_SIZE - eppnt->p_memsz < k) {
41923 + eppnt->p_memsz > pax_task_size ||
41924 + pax_task_size - eppnt->p_memsz < k) {
41925 error = -ENOMEM;
41926 goto out_close;
41927 }
41928 @@ -525,6 +549,349 @@ out:
41929 return error;
41930 }
41931
41932 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
41933 +#ifdef CONFIG_PAX_SOFTMODE
41934 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
41935 +{
41936 + unsigned long pax_flags = 0UL;
41937 +
41938 +#ifdef CONFIG_PAX_PAGEEXEC
41939 + if (elf_phdata->p_flags & PF_PAGEEXEC)
41940 + pax_flags |= MF_PAX_PAGEEXEC;
41941 +#endif
41942 +
41943 +#ifdef CONFIG_PAX_SEGMEXEC
41944 + if (elf_phdata->p_flags & PF_SEGMEXEC)
41945 + pax_flags |= MF_PAX_SEGMEXEC;
41946 +#endif
41947 +
41948 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41949 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41950 + if ((__supported_pte_mask & _PAGE_NX))
41951 + pax_flags &= ~MF_PAX_SEGMEXEC;
41952 + else
41953 + pax_flags &= ~MF_PAX_PAGEEXEC;
41954 + }
41955 +#endif
41956 +
41957 +#ifdef CONFIG_PAX_EMUTRAMP
41958 + if (elf_phdata->p_flags & PF_EMUTRAMP)
41959 + pax_flags |= MF_PAX_EMUTRAMP;
41960 +#endif
41961 +
41962 +#ifdef CONFIG_PAX_MPROTECT
41963 + if (elf_phdata->p_flags & PF_MPROTECT)
41964 + pax_flags |= MF_PAX_MPROTECT;
41965 +#endif
41966 +
41967 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
41968 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
41969 + pax_flags |= MF_PAX_RANDMMAP;
41970 +#endif
41971 +
41972 + return pax_flags;
41973 +}
41974 +#endif
41975 +
41976 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
41977 +{
41978 + unsigned long pax_flags = 0UL;
41979 +
41980 +#ifdef CONFIG_PAX_PAGEEXEC
41981 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
41982 + pax_flags |= MF_PAX_PAGEEXEC;
41983 +#endif
41984 +
41985 +#ifdef CONFIG_PAX_SEGMEXEC
41986 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
41987 + pax_flags |= MF_PAX_SEGMEXEC;
41988 +#endif
41989 +
41990 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
41991 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41992 + if ((__supported_pte_mask & _PAGE_NX))
41993 + pax_flags &= ~MF_PAX_SEGMEXEC;
41994 + else
41995 + pax_flags &= ~MF_PAX_PAGEEXEC;
41996 + }
41997 +#endif
41998 +
41999 +#ifdef CONFIG_PAX_EMUTRAMP
42000 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
42001 + pax_flags |= MF_PAX_EMUTRAMP;
42002 +#endif
42003 +
42004 +#ifdef CONFIG_PAX_MPROTECT
42005 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
42006 + pax_flags |= MF_PAX_MPROTECT;
42007 +#endif
42008 +
42009 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42010 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
42011 + pax_flags |= MF_PAX_RANDMMAP;
42012 +#endif
42013 +
42014 + return pax_flags;
42015 +}
42016 +#endif
42017 +
42018 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42019 +#ifdef CONFIG_PAX_SOFTMODE
42020 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
42021 +{
42022 + unsigned long pax_flags = 0UL;
42023 +
42024 +#ifdef CONFIG_PAX_PAGEEXEC
42025 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
42026 + pax_flags |= MF_PAX_PAGEEXEC;
42027 +#endif
42028 +
42029 +#ifdef CONFIG_PAX_SEGMEXEC
42030 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
42031 + pax_flags |= MF_PAX_SEGMEXEC;
42032 +#endif
42033 +
42034 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42035 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42036 + if ((__supported_pte_mask & _PAGE_NX))
42037 + pax_flags &= ~MF_PAX_SEGMEXEC;
42038 + else
42039 + pax_flags &= ~MF_PAX_PAGEEXEC;
42040 + }
42041 +#endif
42042 +
42043 +#ifdef CONFIG_PAX_EMUTRAMP
42044 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
42045 + pax_flags |= MF_PAX_EMUTRAMP;
42046 +#endif
42047 +
42048 +#ifdef CONFIG_PAX_MPROTECT
42049 + if (pax_flags_softmode & MF_PAX_MPROTECT)
42050 + pax_flags |= MF_PAX_MPROTECT;
42051 +#endif
42052 +
42053 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42054 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
42055 + pax_flags |= MF_PAX_RANDMMAP;
42056 +#endif
42057 +
42058 + return pax_flags;
42059 +}
42060 +#endif
42061 +
42062 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
42063 +{
42064 + unsigned long pax_flags = 0UL;
42065 +
42066 +#ifdef CONFIG_PAX_PAGEEXEC
42067 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
42068 + pax_flags |= MF_PAX_PAGEEXEC;
42069 +#endif
42070 +
42071 +#ifdef CONFIG_PAX_SEGMEXEC
42072 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
42073 + pax_flags |= MF_PAX_SEGMEXEC;
42074 +#endif
42075 +
42076 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42077 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42078 + if ((__supported_pte_mask & _PAGE_NX))
42079 + pax_flags &= ~MF_PAX_SEGMEXEC;
42080 + else
42081 + pax_flags &= ~MF_PAX_PAGEEXEC;
42082 + }
42083 +#endif
42084 +
42085 +#ifdef CONFIG_PAX_EMUTRAMP
42086 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
42087 + pax_flags |= MF_PAX_EMUTRAMP;
42088 +#endif
42089 +
42090 +#ifdef CONFIG_PAX_MPROTECT
42091 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
42092 + pax_flags |= MF_PAX_MPROTECT;
42093 +#endif
42094 +
42095 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42096 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
42097 + pax_flags |= MF_PAX_RANDMMAP;
42098 +#endif
42099 +
42100 + return pax_flags;
42101 +}
42102 +#endif
42103 +
42104 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
42105 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
42106 +{
42107 + unsigned long pax_flags = 0UL;
42108 +
42109 +#ifdef CONFIG_PAX_EI_PAX
42110 +
42111 +#ifdef CONFIG_PAX_PAGEEXEC
42112 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
42113 + pax_flags |= MF_PAX_PAGEEXEC;
42114 +#endif
42115 +
42116 +#ifdef CONFIG_PAX_SEGMEXEC
42117 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
42118 + pax_flags |= MF_PAX_SEGMEXEC;
42119 +#endif
42120 +
42121 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42122 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42123 + if ((__supported_pte_mask & _PAGE_NX))
42124 + pax_flags &= ~MF_PAX_SEGMEXEC;
42125 + else
42126 + pax_flags &= ~MF_PAX_PAGEEXEC;
42127 + }
42128 +#endif
42129 +
42130 +#ifdef CONFIG_PAX_EMUTRAMP
42131 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
42132 + pax_flags |= MF_PAX_EMUTRAMP;
42133 +#endif
42134 +
42135 +#ifdef CONFIG_PAX_MPROTECT
42136 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
42137 + pax_flags |= MF_PAX_MPROTECT;
42138 +#endif
42139 +
42140 +#ifdef CONFIG_PAX_ASLR
42141 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
42142 + pax_flags |= MF_PAX_RANDMMAP;
42143 +#endif
42144 +
42145 +#else
42146 +
42147 +#ifdef CONFIG_PAX_PAGEEXEC
42148 + pax_flags |= MF_PAX_PAGEEXEC;
42149 +#endif
42150 +
42151 +#ifdef CONFIG_PAX_MPROTECT
42152 + pax_flags |= MF_PAX_MPROTECT;
42153 +#endif
42154 +
42155 +#ifdef CONFIG_PAX_RANDMMAP
42156 + pax_flags |= MF_PAX_RANDMMAP;
42157 +#endif
42158 +
42159 +#ifdef CONFIG_PAX_SEGMEXEC
42160 + if (!(pax_flags & MF_PAX_PAGEEXEC) || !(__supported_pte_mask & _PAGE_NX)) {
42161 + pax_flags &= ~MF_PAX_PAGEEXEC;
42162 + pax_flags |= MF_PAX_SEGMEXEC;
42163 + }
42164 +#endif
42165 +
42166 +#endif
42167 +
42168 + return pax_flags;
42169 +}
42170 +
42171 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
42172 +{
42173 +
42174 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42175 + unsigned long i;
42176 +
42177 + for (i = 0UL; i < elf_ex->e_phnum; i++)
42178 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
42179 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
42180 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
42181 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
42182 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
42183 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
42184 + return ~0UL;
42185 +
42186 +#ifdef CONFIG_PAX_SOFTMODE
42187 + if (pax_softmode)
42188 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
42189 + else
42190 +#endif
42191 +
42192 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
42193 + break;
42194 + }
42195 +#endif
42196 +
42197 + return ~0UL;
42198 +}
42199 +
42200 +static unsigned long pax_parse_xattr_pax(struct file * const file)
42201 +{
42202 +
42203 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42204 + ssize_t xattr_size, i;
42205 + unsigned char xattr_value[5];
42206 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
42207 +
42208 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
42209 + if (xattr_size <= 0)
42210 + return ~0UL;
42211 +
42212 + for (i = 0; i < xattr_size; i++)
42213 + switch (xattr_value[i]) {
42214 + default:
42215 + return ~0UL;
42216 +
42217 +#define parse_flag(option1, option2, flag) \
42218 + case option1: \
42219 + pax_flags_hardmode |= MF_PAX_##flag; \
42220 + break; \
42221 + case option2: \
42222 + pax_flags_softmode |= MF_PAX_##flag; \
42223 + break;
42224 +
42225 + parse_flag('p', 'P', PAGEEXEC);
42226 + parse_flag('e', 'E', EMUTRAMP);
42227 + parse_flag('m', 'M', MPROTECT);
42228 + parse_flag('r', 'R', RANDMMAP);
42229 + parse_flag('s', 'S', SEGMEXEC);
42230 +
42231 +#undef parse_flag
42232 + }
42233 +
42234 + if (pax_flags_hardmode & pax_flags_softmode)
42235 + return ~0UL;
42236 +
42237 +#ifdef CONFIG_PAX_SOFTMODE
42238 + if (pax_softmode)
42239 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
42240 + else
42241 +#endif
42242 +
42243 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
42244 +#else
42245 + return ~0UL;
42246 +#endif
42247 +
42248 +}
42249 +
42250 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
42251 +{
42252 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
42253 +
42254 + pax_flags = pax_parse_ei_pax(elf_ex);
42255 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
42256 + xattr_pax_flags = pax_parse_xattr_pax(file);
42257 +
42258 + if (pt_pax_flags == ~0UL)
42259 + pt_pax_flags = xattr_pax_flags;
42260 + else if (xattr_pax_flags == ~0UL)
42261 + xattr_pax_flags = pt_pax_flags;
42262 + if (pt_pax_flags != xattr_pax_flags)
42263 + return -EINVAL;
42264 + if (pt_pax_flags != ~0UL)
42265 + pax_flags = pt_pax_flags;
42266 +
42267 + if (0 > pax_check_flags(&pax_flags))
42268 + return -EINVAL;
42269 +
42270 + current->mm->pax_flags = pax_flags;
42271 + return 0;
42272 +}
42273 +#endif
42274 +
42275 /*
42276 * These are the functions used to load ELF style executables and shared
42277 * libraries. There is no binary dependent code anywhere else.
42278 @@ -541,6 +908,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
42279 {
42280 unsigned int random_variable = 0;
42281
42282 +#ifdef CONFIG_PAX_RANDUSTACK
42283 + if (randomize_va_space)
42284 + return stack_top - current->mm->delta_stack;
42285 +#endif
42286 +
42287 if ((current->flags & PF_RANDOMIZE) &&
42288 !(current->personality & ADDR_NO_RANDOMIZE)) {
42289 random_variable = get_random_int() & STACK_RND_MASK;
42290 @@ -559,7 +931,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42291 unsigned long load_addr = 0, load_bias = 0;
42292 int load_addr_set = 0;
42293 char * elf_interpreter = NULL;
42294 - unsigned long error;
42295 + unsigned long error = 0;
42296 struct elf_phdr *elf_ppnt, *elf_phdata;
42297 unsigned long elf_bss, elf_brk;
42298 int retval, i;
42299 @@ -569,11 +941,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42300 unsigned long start_code, end_code, start_data, end_data;
42301 unsigned long reloc_func_desc __maybe_unused = 0;
42302 int executable_stack = EXSTACK_DEFAULT;
42303 - unsigned long def_flags = 0;
42304 struct {
42305 struct elfhdr elf_ex;
42306 struct elfhdr interp_elf_ex;
42307 } *loc;
42308 + unsigned long pax_task_size = TASK_SIZE;
42309
42310 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
42311 if (!loc) {
42312 @@ -709,11 +1081,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42313 goto out_free_dentry;
42314
42315 /* OK, This is the point of no return */
42316 - current->mm->def_flags = def_flags;
42317 +
42318 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42319 + current->mm->pax_flags = 0UL;
42320 +#endif
42321 +
42322 +#ifdef CONFIG_PAX_DLRESOLVE
42323 + current->mm->call_dl_resolve = 0UL;
42324 +#endif
42325 +
42326 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
42327 + current->mm->call_syscall = 0UL;
42328 +#endif
42329 +
42330 +#ifdef CONFIG_PAX_ASLR
42331 + current->mm->delta_mmap = 0UL;
42332 + current->mm->delta_stack = 0UL;
42333 +#endif
42334 +
42335 + current->mm->def_flags = 0;
42336 +
42337 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
42338 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
42339 + send_sig(SIGKILL, current, 0);
42340 + goto out_free_dentry;
42341 + }
42342 +#endif
42343 +
42344 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
42345 + pax_set_initial_flags(bprm);
42346 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
42347 + if (pax_set_initial_flags_func)
42348 + (pax_set_initial_flags_func)(bprm);
42349 +#endif
42350 +
42351 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
42352 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
42353 + current->mm->context.user_cs_limit = PAGE_SIZE;
42354 + current->mm->def_flags |= VM_PAGEEXEC;
42355 + }
42356 +#endif
42357 +
42358 +#ifdef CONFIG_PAX_SEGMEXEC
42359 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
42360 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
42361 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
42362 + pax_task_size = SEGMEXEC_TASK_SIZE;
42363 + current->mm->def_flags |= VM_NOHUGEPAGE;
42364 + }
42365 +#endif
42366 +
42367 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
42368 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42369 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
42370 + put_cpu();
42371 + }
42372 +#endif
42373
42374 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
42375 may depend on the personality. */
42376 SET_PERSONALITY(loc->elf_ex);
42377 +
42378 +#ifdef CONFIG_PAX_ASLR
42379 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42380 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
42381 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
42382 + }
42383 +#endif
42384 +
42385 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
42386 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42387 + executable_stack = EXSTACK_DISABLE_X;
42388 + current->personality &= ~READ_IMPLIES_EXEC;
42389 + } else
42390 +#endif
42391 +
42392 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
42393 current->personality |= READ_IMPLIES_EXEC;
42394
42395 @@ -804,6 +1246,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42396 #else
42397 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
42398 #endif
42399 +
42400 +#ifdef CONFIG_PAX_RANDMMAP
42401 + /* PaX: randomize base address at the default exe base if requested */
42402 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
42403 +#ifdef CONFIG_SPARC64
42404 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
42405 +#else
42406 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
42407 +#endif
42408 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
42409 + elf_flags |= MAP_FIXED;
42410 + }
42411 +#endif
42412 +
42413 }
42414
42415 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
42416 @@ -836,9 +1292,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42417 * allowed task size. Note that p_filesz must always be
42418 * <= p_memsz so it is only necessary to check p_memsz.
42419 */
42420 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42421 - elf_ppnt->p_memsz > TASK_SIZE ||
42422 - TASK_SIZE - elf_ppnt->p_memsz < k) {
42423 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42424 + elf_ppnt->p_memsz > pax_task_size ||
42425 + pax_task_size - elf_ppnt->p_memsz < k) {
42426 /* set_brk can never work. Avoid overflows. */
42427 send_sig(SIGKILL, current, 0);
42428 retval = -EINVAL;
42429 @@ -877,11 +1333,40 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42430 goto out_free_dentry;
42431 }
42432 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
42433 - send_sig(SIGSEGV, current, 0);
42434 - retval = -EFAULT; /* Nobody gets to see this, but.. */
42435 - goto out_free_dentry;
42436 + /*
42437 + * This bss-zeroing can fail if the ELF
42438 + * file specifies odd protections. So
42439 + * we don't check the return value
42440 + */
42441 }
42442
42443 +#ifdef CONFIG_PAX_RANDMMAP
42444 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42445 + unsigned long start, size;
42446 +
42447 + start = ELF_PAGEALIGN(elf_brk);
42448 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
42449 + down_write(&current->mm->mmap_sem);
42450 + retval = -ENOMEM;
42451 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
42452 + unsigned long prot = PROT_NONE;
42453 +
42454 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
42455 +// if (current->personality & ADDR_NO_RANDOMIZE)
42456 +// prot = PROT_READ;
42457 + start = do_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
42458 + retval = IS_ERR_VALUE(start) ? start : 0;
42459 + }
42460 + up_write(&current->mm->mmap_sem);
42461 + if (retval == 0)
42462 + retval = set_brk(start + size, start + size + PAGE_SIZE);
42463 + if (retval < 0) {
42464 + send_sig(SIGKILL, current, 0);
42465 + goto out_free_dentry;
42466 + }
42467 + }
42468 +#endif
42469 +
42470 if (elf_interpreter) {
42471 unsigned long uninitialized_var(interp_map_addr);
42472
42473 @@ -1109,7 +1594,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
42474 * Decide what to dump of a segment, part, all or none.
42475 */
42476 static unsigned long vma_dump_size(struct vm_area_struct *vma,
42477 - unsigned long mm_flags)
42478 + unsigned long mm_flags, long signr)
42479 {
42480 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
42481
42482 @@ -1146,7 +1631,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
42483 if (vma->vm_file == NULL)
42484 return 0;
42485
42486 - if (FILTER(MAPPED_PRIVATE))
42487 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
42488 goto whole;
42489
42490 /*
42491 @@ -1368,9 +1853,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
42492 {
42493 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
42494 int i = 0;
42495 - do
42496 + do {
42497 i += 2;
42498 - while (auxv[i - 2] != AT_NULL);
42499 + } while (auxv[i - 2] != AT_NULL);
42500 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
42501 }
42502
42503 @@ -1892,14 +2377,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
42504 }
42505
42506 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
42507 - unsigned long mm_flags)
42508 + struct coredump_params *cprm)
42509 {
42510 struct vm_area_struct *vma;
42511 size_t size = 0;
42512
42513 for (vma = first_vma(current, gate_vma); vma != NULL;
42514 vma = next_vma(vma, gate_vma))
42515 - size += vma_dump_size(vma, mm_flags);
42516 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42517 return size;
42518 }
42519
42520 @@ -1993,7 +2478,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42521
42522 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
42523
42524 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
42525 + offset += elf_core_vma_data_size(gate_vma, cprm);
42526 offset += elf_core_extra_data_size();
42527 e_shoff = offset;
42528
42529 @@ -2007,10 +2492,12 @@ static int elf_core_dump(struct coredump_params *cprm)
42530 offset = dataoff;
42531
42532 size += sizeof(*elf);
42533 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42534 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
42535 goto end_coredump;
42536
42537 size += sizeof(*phdr4note);
42538 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42539 if (size > cprm->limit
42540 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
42541 goto end_coredump;
42542 @@ -2024,7 +2511,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42543 phdr.p_offset = offset;
42544 phdr.p_vaddr = vma->vm_start;
42545 phdr.p_paddr = 0;
42546 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
42547 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42548 phdr.p_memsz = vma->vm_end - vma->vm_start;
42549 offset += phdr.p_filesz;
42550 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
42551 @@ -2035,6 +2522,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42552 phdr.p_align = ELF_EXEC_PAGESIZE;
42553
42554 size += sizeof(phdr);
42555 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42556 if (size > cprm->limit
42557 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
42558 goto end_coredump;
42559 @@ -2059,7 +2547,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42560 unsigned long addr;
42561 unsigned long end;
42562
42563 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
42564 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42565
42566 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
42567 struct page *page;
42568 @@ -2068,6 +2556,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42569 page = get_dump_page(addr);
42570 if (page) {
42571 void *kaddr = kmap(page);
42572 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
42573 stop = ((size += PAGE_SIZE) > cprm->limit) ||
42574 !dump_write(cprm->file, kaddr,
42575 PAGE_SIZE);
42576 @@ -2085,6 +2574,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42577
42578 if (e_phnum == PN_XNUM) {
42579 size += sizeof(*shdr4extnum);
42580 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42581 if (size > cprm->limit
42582 || !dump_write(cprm->file, shdr4extnum,
42583 sizeof(*shdr4extnum)))
42584 @@ -2105,6 +2595,97 @@ out:
42585
42586 #endif /* CONFIG_ELF_CORE */
42587
42588 +#ifdef CONFIG_PAX_MPROTECT
42589 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
42590 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
42591 + * we'll remove VM_MAYWRITE for good on RELRO segments.
42592 + *
42593 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
42594 + * basis because we want to allow the common case and not the special ones.
42595 + */
42596 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
42597 +{
42598 + struct elfhdr elf_h;
42599 + struct elf_phdr elf_p;
42600 + unsigned long i;
42601 + unsigned long oldflags;
42602 + bool is_textrel_rw, is_textrel_rx, is_relro;
42603 +
42604 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
42605 + return;
42606 +
42607 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
42608 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
42609 +
42610 +#ifdef CONFIG_PAX_ELFRELOCS
42611 + /* possible TEXTREL */
42612 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
42613 + 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);
42614 +#else
42615 + is_textrel_rw = false;
42616 + is_textrel_rx = false;
42617 +#endif
42618 +
42619 + /* possible RELRO */
42620 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
42621 +
42622 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
42623 + return;
42624 +
42625 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
42626 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
42627 +
42628 +#ifdef CONFIG_PAX_ETEXECRELOCS
42629 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
42630 +#else
42631 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
42632 +#endif
42633 +
42634 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
42635 + !elf_check_arch(&elf_h) ||
42636 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
42637 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
42638 + return;
42639 +
42640 + for (i = 0UL; i < elf_h.e_phnum; i++) {
42641 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
42642 + return;
42643 + switch (elf_p.p_type) {
42644 + case PT_DYNAMIC:
42645 + if (!is_textrel_rw && !is_textrel_rx)
42646 + continue;
42647 + i = 0UL;
42648 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
42649 + elf_dyn dyn;
42650 +
42651 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
42652 + return;
42653 + if (dyn.d_tag == DT_NULL)
42654 + return;
42655 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
42656 + gr_log_textrel(vma);
42657 + if (is_textrel_rw)
42658 + vma->vm_flags |= VM_MAYWRITE;
42659 + else
42660 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
42661 + vma->vm_flags &= ~VM_MAYWRITE;
42662 + return;
42663 + }
42664 + i++;
42665 + }
42666 + return;
42667 +
42668 + case PT_GNU_RELRO:
42669 + if (!is_relro)
42670 + continue;
42671 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
42672 + vma->vm_flags &= ~VM_MAYWRITE;
42673 + return;
42674 + }
42675 + }
42676 +}
42677 +#endif
42678 +
42679 static int __init init_elf_binfmt(void)
42680 {
42681 register_binfmt(&elf_format);
42682 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
42683 index 6b2daf9..a70dccb 100644
42684 --- a/fs/binfmt_flat.c
42685 +++ b/fs/binfmt_flat.c
42686 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
42687 realdatastart = (unsigned long) -ENOMEM;
42688 printk("Unable to allocate RAM for process data, errno %d\n",
42689 (int)-realdatastart);
42690 + down_write(&current->mm->mmap_sem);
42691 do_munmap(current->mm, textpos, text_len);
42692 + up_write(&current->mm->mmap_sem);
42693 ret = realdatastart;
42694 goto err;
42695 }
42696 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
42697 }
42698 if (IS_ERR_VALUE(result)) {
42699 printk("Unable to read data+bss, errno %d\n", (int)-result);
42700 + down_write(&current->mm->mmap_sem);
42701 do_munmap(current->mm, textpos, text_len);
42702 do_munmap(current->mm, realdatastart, len);
42703 + up_write(&current->mm->mmap_sem);
42704 ret = result;
42705 goto err;
42706 }
42707 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
42708 }
42709 if (IS_ERR_VALUE(result)) {
42710 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
42711 + down_write(&current->mm->mmap_sem);
42712 do_munmap(current->mm, textpos, text_len + data_len + extra +
42713 MAX_SHARED_LIBS * sizeof(unsigned long));
42714 + up_write(&current->mm->mmap_sem);
42715 ret = result;
42716 goto err;
42717 }
42718 diff --git a/fs/bio.c b/fs/bio.c
42719 index 84da885..2149cd9 100644
42720 --- a/fs/bio.c
42721 +++ b/fs/bio.c
42722 @@ -838,7 +838,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
42723 /*
42724 * Overflow, abort
42725 */
42726 - if (end < start)
42727 + if (end < start || end - start > INT_MAX - nr_pages)
42728 return ERR_PTR(-EINVAL);
42729
42730 nr_pages += end - start;
42731 @@ -1234,7 +1234,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
42732 const int read = bio_data_dir(bio) == READ;
42733 struct bio_map_data *bmd = bio->bi_private;
42734 int i;
42735 - char *p = bmd->sgvecs[0].iov_base;
42736 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
42737
42738 __bio_for_each_segment(bvec, bio, i, 0) {
42739 char *addr = page_address(bvec->bv_page);
42740 diff --git a/fs/block_dev.c b/fs/block_dev.c
42741 index ba11c30..623d736 100644
42742 --- a/fs/block_dev.c
42743 +++ b/fs/block_dev.c
42744 @@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
42745 else if (bdev->bd_contains == bdev)
42746 return true; /* is a whole device which isn't held */
42747
42748 - else if (whole->bd_holder == bd_may_claim)
42749 + else if (whole->bd_holder == (void *)bd_may_claim)
42750 return true; /* is a partition of a device that is being partitioned */
42751 else if (whole->bd_holder != NULL)
42752 return false; /* is a partition of a held device */
42753 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
42754 index c053e90..e5f1afc 100644
42755 --- a/fs/btrfs/check-integrity.c
42756 +++ b/fs/btrfs/check-integrity.c
42757 @@ -156,7 +156,7 @@ struct btrfsic_block {
42758 union {
42759 bio_end_io_t *bio;
42760 bh_end_io_t *bh;
42761 - } orig_bio_bh_end_io;
42762 + } __no_const orig_bio_bh_end_io;
42763 int submit_bio_bh_rw;
42764 u64 flush_gen; /* only valid if !never_written */
42765 };
42766 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
42767 index 4106264..8157ede 100644
42768 --- a/fs/btrfs/ctree.c
42769 +++ b/fs/btrfs/ctree.c
42770 @@ -513,9 +513,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
42771 free_extent_buffer(buf);
42772 add_root_to_dirty_list(root);
42773 } else {
42774 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
42775 - parent_start = parent->start;
42776 - else
42777 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
42778 + if (parent)
42779 + parent_start = parent->start;
42780 + else
42781 + parent_start = 0;
42782 + } else
42783 parent_start = 0;
42784
42785 WARN_ON(trans->transid != btrfs_header_generation(parent));
42786 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
42787 index 0df0d1f..4bdcbfe 100644
42788 --- a/fs/btrfs/inode.c
42789 +++ b/fs/btrfs/inode.c
42790 @@ -7074,7 +7074,7 @@ fail:
42791 return -ENOMEM;
42792 }
42793
42794 -static int btrfs_getattr(struct vfsmount *mnt,
42795 +int btrfs_getattr(struct vfsmount *mnt,
42796 struct dentry *dentry, struct kstat *stat)
42797 {
42798 struct inode *inode = dentry->d_inode;
42799 @@ -7088,6 +7088,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
42800 return 0;
42801 }
42802
42803 +EXPORT_SYMBOL(btrfs_getattr);
42804 +
42805 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
42806 +{
42807 + return BTRFS_I(inode)->root->anon_dev;
42808 +}
42809 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
42810 +
42811 /*
42812 * If a file is moved, it will inherit the cow and compression flags of the new
42813 * directory.
42814 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
42815 index 14f8e1f..ab8d81f 100644
42816 --- a/fs/btrfs/ioctl.c
42817 +++ b/fs/btrfs/ioctl.c
42818 @@ -2882,9 +2882,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
42819 for (i = 0; i < num_types; i++) {
42820 struct btrfs_space_info *tmp;
42821
42822 + /* Don't copy in more than we allocated */
42823 if (!slot_count)
42824 break;
42825
42826 + slot_count--;
42827 +
42828 info = NULL;
42829 rcu_read_lock();
42830 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
42831 @@ -2906,15 +2909,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
42832 memcpy(dest, &space, sizeof(space));
42833 dest++;
42834 space_args.total_spaces++;
42835 - slot_count--;
42836 }
42837 - if (!slot_count)
42838 - break;
42839 }
42840 up_read(&info->groups_sem);
42841 }
42842
42843 - user_dest = (struct btrfs_ioctl_space_info *)
42844 + user_dest = (struct btrfs_ioctl_space_info __user *)
42845 (arg + sizeof(struct btrfs_ioctl_space_args));
42846
42847 if (copy_to_user(user_dest, dest_orig, alloc_size))
42848 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
42849 index 646ee21..f020f87 100644
42850 --- a/fs/btrfs/relocation.c
42851 +++ b/fs/btrfs/relocation.c
42852 @@ -1268,7 +1268,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
42853 }
42854 spin_unlock(&rc->reloc_root_tree.lock);
42855
42856 - BUG_ON((struct btrfs_root *)node->data != root);
42857 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
42858
42859 if (!del) {
42860 spin_lock(&rc->reloc_root_tree.lock);
42861 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
42862 index 622f469..e8d2d55 100644
42863 --- a/fs/cachefiles/bind.c
42864 +++ b/fs/cachefiles/bind.c
42865 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
42866 args);
42867
42868 /* start by checking things over */
42869 - ASSERT(cache->fstop_percent >= 0 &&
42870 - cache->fstop_percent < cache->fcull_percent &&
42871 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
42872 cache->fcull_percent < cache->frun_percent &&
42873 cache->frun_percent < 100);
42874
42875 - ASSERT(cache->bstop_percent >= 0 &&
42876 - cache->bstop_percent < cache->bcull_percent &&
42877 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
42878 cache->bcull_percent < cache->brun_percent &&
42879 cache->brun_percent < 100);
42880
42881 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
42882 index 0a1467b..6a53245 100644
42883 --- a/fs/cachefiles/daemon.c
42884 +++ b/fs/cachefiles/daemon.c
42885 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
42886 if (n > buflen)
42887 return -EMSGSIZE;
42888
42889 - if (copy_to_user(_buffer, buffer, n) != 0)
42890 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
42891 return -EFAULT;
42892
42893 return n;
42894 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
42895 if (test_bit(CACHEFILES_DEAD, &cache->flags))
42896 return -EIO;
42897
42898 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
42899 + if (datalen > PAGE_SIZE - 1)
42900 return -EOPNOTSUPP;
42901
42902 /* drag the command string into the kernel so we can parse it */
42903 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
42904 if (args[0] != '%' || args[1] != '\0')
42905 return -EINVAL;
42906
42907 - if (fstop < 0 || fstop >= cache->fcull_percent)
42908 + if (fstop >= cache->fcull_percent)
42909 return cachefiles_daemon_range_error(cache, args);
42910
42911 cache->fstop_percent = fstop;
42912 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
42913 if (args[0] != '%' || args[1] != '\0')
42914 return -EINVAL;
42915
42916 - if (bstop < 0 || bstop >= cache->bcull_percent)
42917 + if (bstop >= cache->bcull_percent)
42918 return cachefiles_daemon_range_error(cache, args);
42919
42920 cache->bstop_percent = bstop;
42921 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
42922 index bd6bc1b..b627b53 100644
42923 --- a/fs/cachefiles/internal.h
42924 +++ b/fs/cachefiles/internal.h
42925 @@ -57,7 +57,7 @@ struct cachefiles_cache {
42926 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
42927 struct rb_root active_nodes; /* active nodes (can't be culled) */
42928 rwlock_t active_lock; /* lock for active_nodes */
42929 - atomic_t gravecounter; /* graveyard uniquifier */
42930 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
42931 unsigned frun_percent; /* when to stop culling (% files) */
42932 unsigned fcull_percent; /* when to start culling (% files) */
42933 unsigned fstop_percent; /* when to stop allocating (% files) */
42934 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
42935 * proc.c
42936 */
42937 #ifdef CONFIG_CACHEFILES_HISTOGRAM
42938 -extern atomic_t cachefiles_lookup_histogram[HZ];
42939 -extern atomic_t cachefiles_mkdir_histogram[HZ];
42940 -extern atomic_t cachefiles_create_histogram[HZ];
42941 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
42942 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
42943 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
42944
42945 extern int __init cachefiles_proc_init(void);
42946 extern void cachefiles_proc_cleanup(void);
42947 static inline
42948 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
42949 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
42950 {
42951 unsigned long jif = jiffies - start_jif;
42952 if (jif >= HZ)
42953 jif = HZ - 1;
42954 - atomic_inc(&histogram[jif]);
42955 + atomic_inc_unchecked(&histogram[jif]);
42956 }
42957
42958 #else
42959 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
42960 index 7f0771d..87d4f36 100644
42961 --- a/fs/cachefiles/namei.c
42962 +++ b/fs/cachefiles/namei.c
42963 @@ -318,7 +318,7 @@ try_again:
42964 /* first step is to make up a grave dentry in the graveyard */
42965 sprintf(nbuffer, "%08x%08x",
42966 (uint32_t) get_seconds(),
42967 - (uint32_t) atomic_inc_return(&cache->gravecounter));
42968 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
42969
42970 /* do the multiway lock magic */
42971 trap = lock_rename(cache->graveyard, dir);
42972 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
42973 index eccd339..4c1d995 100644
42974 --- a/fs/cachefiles/proc.c
42975 +++ b/fs/cachefiles/proc.c
42976 @@ -14,9 +14,9 @@
42977 #include <linux/seq_file.h>
42978 #include "internal.h"
42979
42980 -atomic_t cachefiles_lookup_histogram[HZ];
42981 -atomic_t cachefiles_mkdir_histogram[HZ];
42982 -atomic_t cachefiles_create_histogram[HZ];
42983 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
42984 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
42985 +atomic_unchecked_t cachefiles_create_histogram[HZ];
42986
42987 /*
42988 * display the latency histogram
42989 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
42990 return 0;
42991 default:
42992 index = (unsigned long) v - 3;
42993 - x = atomic_read(&cachefiles_lookup_histogram[index]);
42994 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
42995 - z = atomic_read(&cachefiles_create_histogram[index]);
42996 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
42997 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
42998 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
42999 if (x == 0 && y == 0 && z == 0)
43000 return 0;
43001
43002 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
43003 index 0e3c092..818480e 100644
43004 --- a/fs/cachefiles/rdwr.c
43005 +++ b/fs/cachefiles/rdwr.c
43006 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
43007 old_fs = get_fs();
43008 set_fs(KERNEL_DS);
43009 ret = file->f_op->write(
43010 - file, (const void __user *) data, len, &pos);
43011 + file, (const void __force_user *) data, len, &pos);
43012 set_fs(old_fs);
43013 kunmap(page);
43014 if (ret != len)
43015 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
43016 index 3e8094b..cb3ff3d 100644
43017 --- a/fs/ceph/dir.c
43018 +++ b/fs/ceph/dir.c
43019 @@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
43020 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
43021 struct ceph_mds_client *mdsc = fsc->mdsc;
43022 unsigned frag = fpos_frag(filp->f_pos);
43023 - int off = fpos_off(filp->f_pos);
43024 + unsigned int off = fpos_off(filp->f_pos);
43025 int err;
43026 u32 ftype;
43027 struct ceph_mds_reply_info_parsed *rinfo;
43028 @@ -598,7 +598,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
43029 if (nd &&
43030 (nd->flags & LOOKUP_OPEN) &&
43031 !(nd->intent.open.flags & O_CREAT)) {
43032 - int mode = nd->intent.open.create_mode & ~current->fs->umask;
43033 + int mode = nd->intent.open.create_mode & ~current_umask();
43034 return ceph_lookup_open(dir, dentry, nd, mode, 1);
43035 }
43036
43037 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
43038 index 2704646..c581c91 100644
43039 --- a/fs/cifs/cifs_debug.c
43040 +++ b/fs/cifs/cifs_debug.c
43041 @@ -265,8 +265,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43042
43043 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
43044 #ifdef CONFIG_CIFS_STATS2
43045 - atomic_set(&totBufAllocCount, 0);
43046 - atomic_set(&totSmBufAllocCount, 0);
43047 + atomic_set_unchecked(&totBufAllocCount, 0);
43048 + atomic_set_unchecked(&totSmBufAllocCount, 0);
43049 #endif /* CONFIG_CIFS_STATS2 */
43050 spin_lock(&cifs_tcp_ses_lock);
43051 list_for_each(tmp1, &cifs_tcp_ses_list) {
43052 @@ -279,25 +279,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43053 tcon = list_entry(tmp3,
43054 struct cifs_tcon,
43055 tcon_list);
43056 - atomic_set(&tcon->num_smbs_sent, 0);
43057 - atomic_set(&tcon->num_writes, 0);
43058 - atomic_set(&tcon->num_reads, 0);
43059 - atomic_set(&tcon->num_oplock_brks, 0);
43060 - atomic_set(&tcon->num_opens, 0);
43061 - atomic_set(&tcon->num_posixopens, 0);
43062 - atomic_set(&tcon->num_posixmkdirs, 0);
43063 - atomic_set(&tcon->num_closes, 0);
43064 - atomic_set(&tcon->num_deletes, 0);
43065 - atomic_set(&tcon->num_mkdirs, 0);
43066 - atomic_set(&tcon->num_rmdirs, 0);
43067 - atomic_set(&tcon->num_renames, 0);
43068 - atomic_set(&tcon->num_t2renames, 0);
43069 - atomic_set(&tcon->num_ffirst, 0);
43070 - atomic_set(&tcon->num_fnext, 0);
43071 - atomic_set(&tcon->num_fclose, 0);
43072 - atomic_set(&tcon->num_hardlinks, 0);
43073 - atomic_set(&tcon->num_symlinks, 0);
43074 - atomic_set(&tcon->num_locks, 0);
43075 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
43076 + atomic_set_unchecked(&tcon->num_writes, 0);
43077 + atomic_set_unchecked(&tcon->num_reads, 0);
43078 + atomic_set_unchecked(&tcon->num_oplock_brks, 0);
43079 + atomic_set_unchecked(&tcon->num_opens, 0);
43080 + atomic_set_unchecked(&tcon->num_posixopens, 0);
43081 + atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
43082 + atomic_set_unchecked(&tcon->num_closes, 0);
43083 + atomic_set_unchecked(&tcon->num_deletes, 0);
43084 + atomic_set_unchecked(&tcon->num_mkdirs, 0);
43085 + atomic_set_unchecked(&tcon->num_rmdirs, 0);
43086 + atomic_set_unchecked(&tcon->num_renames, 0);
43087 + atomic_set_unchecked(&tcon->num_t2renames, 0);
43088 + atomic_set_unchecked(&tcon->num_ffirst, 0);
43089 + atomic_set_unchecked(&tcon->num_fnext, 0);
43090 + atomic_set_unchecked(&tcon->num_fclose, 0);
43091 + atomic_set_unchecked(&tcon->num_hardlinks, 0);
43092 + atomic_set_unchecked(&tcon->num_symlinks, 0);
43093 + atomic_set_unchecked(&tcon->num_locks, 0);
43094 }
43095 }
43096 }
43097 @@ -327,8 +327,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43098 smBufAllocCount.counter, cifs_min_small);
43099 #ifdef CONFIG_CIFS_STATS2
43100 seq_printf(m, "Total Large %d Small %d Allocations\n",
43101 - atomic_read(&totBufAllocCount),
43102 - atomic_read(&totSmBufAllocCount));
43103 + atomic_read_unchecked(&totBufAllocCount),
43104 + atomic_read_unchecked(&totSmBufAllocCount));
43105 #endif /* CONFIG_CIFS_STATS2 */
43106
43107 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
43108 @@ -357,41 +357,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43109 if (tcon->need_reconnect)
43110 seq_puts(m, "\tDISCONNECTED ");
43111 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
43112 - atomic_read(&tcon->num_smbs_sent),
43113 - atomic_read(&tcon->num_oplock_brks));
43114 + atomic_read_unchecked(&tcon->num_smbs_sent),
43115 + atomic_read_unchecked(&tcon->num_oplock_brks));
43116 seq_printf(m, "\nReads: %d Bytes: %lld",
43117 - atomic_read(&tcon->num_reads),
43118 + atomic_read_unchecked(&tcon->num_reads),
43119 (long long)(tcon->bytes_read));
43120 seq_printf(m, "\nWrites: %d Bytes: %lld",
43121 - atomic_read(&tcon->num_writes),
43122 + atomic_read_unchecked(&tcon->num_writes),
43123 (long long)(tcon->bytes_written));
43124 seq_printf(m, "\nFlushes: %d",
43125 - atomic_read(&tcon->num_flushes));
43126 + atomic_read_unchecked(&tcon->num_flushes));
43127 seq_printf(m, "\nLocks: %d HardLinks: %d "
43128 "Symlinks: %d",
43129 - atomic_read(&tcon->num_locks),
43130 - atomic_read(&tcon->num_hardlinks),
43131 - atomic_read(&tcon->num_symlinks));
43132 + atomic_read_unchecked(&tcon->num_locks),
43133 + atomic_read_unchecked(&tcon->num_hardlinks),
43134 + atomic_read_unchecked(&tcon->num_symlinks));
43135 seq_printf(m, "\nOpens: %d Closes: %d "
43136 "Deletes: %d",
43137 - atomic_read(&tcon->num_opens),
43138 - atomic_read(&tcon->num_closes),
43139 - atomic_read(&tcon->num_deletes));
43140 + atomic_read_unchecked(&tcon->num_opens),
43141 + atomic_read_unchecked(&tcon->num_closes),
43142 + atomic_read_unchecked(&tcon->num_deletes));
43143 seq_printf(m, "\nPosix Opens: %d "
43144 "Posix Mkdirs: %d",
43145 - atomic_read(&tcon->num_posixopens),
43146 - atomic_read(&tcon->num_posixmkdirs));
43147 + atomic_read_unchecked(&tcon->num_posixopens),
43148 + atomic_read_unchecked(&tcon->num_posixmkdirs));
43149 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
43150 - atomic_read(&tcon->num_mkdirs),
43151 - atomic_read(&tcon->num_rmdirs));
43152 + atomic_read_unchecked(&tcon->num_mkdirs),
43153 + atomic_read_unchecked(&tcon->num_rmdirs));
43154 seq_printf(m, "\nRenames: %d T2 Renames %d",
43155 - atomic_read(&tcon->num_renames),
43156 - atomic_read(&tcon->num_t2renames));
43157 + atomic_read_unchecked(&tcon->num_renames),
43158 + atomic_read_unchecked(&tcon->num_t2renames));
43159 seq_printf(m, "\nFindFirst: %d FNext %d "
43160 "FClose %d",
43161 - atomic_read(&tcon->num_ffirst),
43162 - atomic_read(&tcon->num_fnext),
43163 - atomic_read(&tcon->num_fclose));
43164 + atomic_read_unchecked(&tcon->num_ffirst),
43165 + atomic_read_unchecked(&tcon->num_fnext),
43166 + atomic_read_unchecked(&tcon->num_fclose));
43167 }
43168 }
43169 }
43170 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
43171 index 541ef81..a78deb8 100644
43172 --- a/fs/cifs/cifsfs.c
43173 +++ b/fs/cifs/cifsfs.c
43174 @@ -985,7 +985,7 @@ cifs_init_request_bufs(void)
43175 cifs_req_cachep = kmem_cache_create("cifs_request",
43176 CIFSMaxBufSize +
43177 MAX_CIFS_HDR_SIZE, 0,
43178 - SLAB_HWCACHE_ALIGN, NULL);
43179 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
43180 if (cifs_req_cachep == NULL)
43181 return -ENOMEM;
43182
43183 @@ -1012,7 +1012,7 @@ cifs_init_request_bufs(void)
43184 efficient to alloc 1 per page off the slab compared to 17K (5page)
43185 alloc of large cifs buffers even when page debugging is on */
43186 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
43187 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
43188 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
43189 NULL);
43190 if (cifs_sm_req_cachep == NULL) {
43191 mempool_destroy(cifs_req_poolp);
43192 @@ -1097,8 +1097,8 @@ init_cifs(void)
43193 atomic_set(&bufAllocCount, 0);
43194 atomic_set(&smBufAllocCount, 0);
43195 #ifdef CONFIG_CIFS_STATS2
43196 - atomic_set(&totBufAllocCount, 0);
43197 - atomic_set(&totSmBufAllocCount, 0);
43198 + atomic_set_unchecked(&totBufAllocCount, 0);
43199 + atomic_set_unchecked(&totSmBufAllocCount, 0);
43200 #endif /* CONFIG_CIFS_STATS2 */
43201
43202 atomic_set(&midCount, 0);
43203 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
43204 index 73fea28..b996b84 100644
43205 --- a/fs/cifs/cifsglob.h
43206 +++ b/fs/cifs/cifsglob.h
43207 @@ -439,28 +439,28 @@ struct cifs_tcon {
43208 __u16 Flags; /* optional support bits */
43209 enum statusEnum tidStatus;
43210 #ifdef CONFIG_CIFS_STATS
43211 - atomic_t num_smbs_sent;
43212 - atomic_t num_writes;
43213 - atomic_t num_reads;
43214 - atomic_t num_flushes;
43215 - atomic_t num_oplock_brks;
43216 - atomic_t num_opens;
43217 - atomic_t num_closes;
43218 - atomic_t num_deletes;
43219 - atomic_t num_mkdirs;
43220 - atomic_t num_posixopens;
43221 - atomic_t num_posixmkdirs;
43222 - atomic_t num_rmdirs;
43223 - atomic_t num_renames;
43224 - atomic_t num_t2renames;
43225 - atomic_t num_ffirst;
43226 - atomic_t num_fnext;
43227 - atomic_t num_fclose;
43228 - atomic_t num_hardlinks;
43229 - atomic_t num_symlinks;
43230 - atomic_t num_locks;
43231 - atomic_t num_acl_get;
43232 - atomic_t num_acl_set;
43233 + atomic_unchecked_t num_smbs_sent;
43234 + atomic_unchecked_t num_writes;
43235 + atomic_unchecked_t num_reads;
43236 + atomic_unchecked_t num_flushes;
43237 + atomic_unchecked_t num_oplock_brks;
43238 + atomic_unchecked_t num_opens;
43239 + atomic_unchecked_t num_closes;
43240 + atomic_unchecked_t num_deletes;
43241 + atomic_unchecked_t num_mkdirs;
43242 + atomic_unchecked_t num_posixopens;
43243 + atomic_unchecked_t num_posixmkdirs;
43244 + atomic_unchecked_t num_rmdirs;
43245 + atomic_unchecked_t num_renames;
43246 + atomic_unchecked_t num_t2renames;
43247 + atomic_unchecked_t num_ffirst;
43248 + atomic_unchecked_t num_fnext;
43249 + atomic_unchecked_t num_fclose;
43250 + atomic_unchecked_t num_hardlinks;
43251 + atomic_unchecked_t num_symlinks;
43252 + atomic_unchecked_t num_locks;
43253 + atomic_unchecked_t num_acl_get;
43254 + atomic_unchecked_t num_acl_set;
43255 #ifdef CONFIG_CIFS_STATS2
43256 unsigned long long time_writes;
43257 unsigned long long time_reads;
43258 @@ -677,7 +677,7 @@ convert_delimiter(char *path, char delim)
43259 }
43260
43261 #ifdef CONFIG_CIFS_STATS
43262 -#define cifs_stats_inc atomic_inc
43263 +#define cifs_stats_inc atomic_inc_unchecked
43264
43265 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
43266 unsigned int bytes)
43267 @@ -1036,8 +1036,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
43268 /* Various Debug counters */
43269 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
43270 #ifdef CONFIG_CIFS_STATS2
43271 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
43272 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
43273 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
43274 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
43275 #endif
43276 GLOBAL_EXTERN atomic_t smBufAllocCount;
43277 GLOBAL_EXTERN atomic_t midCount;
43278 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
43279 index 6b0e064..94e6c3c 100644
43280 --- a/fs/cifs/link.c
43281 +++ b/fs/cifs/link.c
43282 @@ -600,7 +600,7 @@ symlink_exit:
43283
43284 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
43285 {
43286 - char *p = nd_get_link(nd);
43287 + const char *p = nd_get_link(nd);
43288 if (!IS_ERR(p))
43289 kfree(p);
43290 }
43291 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
43292 index c29d1aa..58018da 100644
43293 --- a/fs/cifs/misc.c
43294 +++ b/fs/cifs/misc.c
43295 @@ -156,7 +156,7 @@ cifs_buf_get(void)
43296 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
43297 atomic_inc(&bufAllocCount);
43298 #ifdef CONFIG_CIFS_STATS2
43299 - atomic_inc(&totBufAllocCount);
43300 + atomic_inc_unchecked(&totBufAllocCount);
43301 #endif /* CONFIG_CIFS_STATS2 */
43302 }
43303
43304 @@ -191,7 +191,7 @@ cifs_small_buf_get(void)
43305 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
43306 atomic_inc(&smBufAllocCount);
43307 #ifdef CONFIG_CIFS_STATS2
43308 - atomic_inc(&totSmBufAllocCount);
43309 + atomic_inc_unchecked(&totSmBufAllocCount);
43310 #endif /* CONFIG_CIFS_STATS2 */
43311
43312 }
43313 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
43314 index 6901578..d402eb5 100644
43315 --- a/fs/coda/cache.c
43316 +++ b/fs/coda/cache.c
43317 @@ -24,7 +24,7 @@
43318 #include "coda_linux.h"
43319 #include "coda_cache.h"
43320
43321 -static atomic_t permission_epoch = ATOMIC_INIT(0);
43322 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
43323
43324 /* replace or extend an acl cache hit */
43325 void coda_cache_enter(struct inode *inode, int mask)
43326 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
43327 struct coda_inode_info *cii = ITOC(inode);
43328
43329 spin_lock(&cii->c_lock);
43330 - cii->c_cached_epoch = atomic_read(&permission_epoch);
43331 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
43332 if (cii->c_uid != current_fsuid()) {
43333 cii->c_uid = current_fsuid();
43334 cii->c_cached_perm = mask;
43335 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
43336 {
43337 struct coda_inode_info *cii = ITOC(inode);
43338 spin_lock(&cii->c_lock);
43339 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
43340 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
43341 spin_unlock(&cii->c_lock);
43342 }
43343
43344 /* remove all acl caches */
43345 void coda_cache_clear_all(struct super_block *sb)
43346 {
43347 - atomic_inc(&permission_epoch);
43348 + atomic_inc_unchecked(&permission_epoch);
43349 }
43350
43351
43352 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
43353 spin_lock(&cii->c_lock);
43354 hit = (mask & cii->c_cached_perm) == mask &&
43355 cii->c_uid == current_fsuid() &&
43356 - cii->c_cached_epoch == atomic_read(&permission_epoch);
43357 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
43358 spin_unlock(&cii->c_lock);
43359
43360 return hit;
43361 diff --git a/fs/compat.c b/fs/compat.c
43362 index f2944ac..62845d2 100644
43363 --- a/fs/compat.c
43364 +++ b/fs/compat.c
43365 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
43366
43367 set_fs(KERNEL_DS);
43368 /* The __user pointer cast is valid because of the set_fs() */
43369 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
43370 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
43371 set_fs(oldfs);
43372 /* truncating is ok because it's a user address */
43373 if (!ret)
43374 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
43375 goto out;
43376
43377 ret = -EINVAL;
43378 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
43379 + if (nr_segs > UIO_MAXIOV)
43380 goto out;
43381 if (nr_segs > fast_segs) {
43382 ret = -ENOMEM;
43383 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
43384
43385 struct compat_readdir_callback {
43386 struct compat_old_linux_dirent __user *dirent;
43387 + struct file * file;
43388 int result;
43389 };
43390
43391 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
43392 buf->result = -EOVERFLOW;
43393 return -EOVERFLOW;
43394 }
43395 +
43396 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43397 + return 0;
43398 +
43399 buf->result++;
43400 dirent = buf->dirent;
43401 if (!access_ok(VERIFY_WRITE, dirent,
43402 @@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
43403
43404 buf.result = 0;
43405 buf.dirent = dirent;
43406 + buf.file = file;
43407
43408 error = vfs_readdir(file, compat_fillonedir, &buf);
43409 if (buf.result)
43410 @@ -900,6 +906,7 @@ struct compat_linux_dirent {
43411 struct compat_getdents_callback {
43412 struct compat_linux_dirent __user *current_dir;
43413 struct compat_linux_dirent __user *previous;
43414 + struct file * file;
43415 int count;
43416 int error;
43417 };
43418 @@ -921,6 +928,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
43419 buf->error = -EOVERFLOW;
43420 return -EOVERFLOW;
43421 }
43422 +
43423 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43424 + return 0;
43425 +
43426 dirent = buf->previous;
43427 if (dirent) {
43428 if (__put_user(offset, &dirent->d_off))
43429 @@ -968,6 +979,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
43430 buf.previous = NULL;
43431 buf.count = count;
43432 buf.error = 0;
43433 + buf.file = file;
43434
43435 error = vfs_readdir(file, compat_filldir, &buf);
43436 if (error >= 0)
43437 @@ -989,6 +1001,7 @@ out:
43438 struct compat_getdents_callback64 {
43439 struct linux_dirent64 __user *current_dir;
43440 struct linux_dirent64 __user *previous;
43441 + struct file * file;
43442 int count;
43443 int error;
43444 };
43445 @@ -1005,6 +1018,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
43446 buf->error = -EINVAL; /* only used if we fail.. */
43447 if (reclen > buf->count)
43448 return -EINVAL;
43449 +
43450 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43451 + return 0;
43452 +
43453 dirent = buf->previous;
43454
43455 if (dirent) {
43456 @@ -1056,13 +1073,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
43457 buf.previous = NULL;
43458 buf.count = count;
43459 buf.error = 0;
43460 + buf.file = file;
43461
43462 error = vfs_readdir(file, compat_filldir64, &buf);
43463 if (error >= 0)
43464 error = buf.error;
43465 lastdirent = buf.previous;
43466 if (lastdirent) {
43467 - typeof(lastdirent->d_off) d_off = file->f_pos;
43468 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
43469 if (__put_user_unaligned(d_off, &lastdirent->d_off))
43470 error = -EFAULT;
43471 else
43472 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
43473 index 112e45a..b59845b 100644
43474 --- a/fs/compat_binfmt_elf.c
43475 +++ b/fs/compat_binfmt_elf.c
43476 @@ -30,11 +30,13 @@
43477 #undef elf_phdr
43478 #undef elf_shdr
43479 #undef elf_note
43480 +#undef elf_dyn
43481 #undef elf_addr_t
43482 #define elfhdr elf32_hdr
43483 #define elf_phdr elf32_phdr
43484 #define elf_shdr elf32_shdr
43485 #define elf_note elf32_note
43486 +#define elf_dyn Elf32_Dyn
43487 #define elf_addr_t Elf32_Addr
43488
43489 /*
43490 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
43491 index debdfe0..75d31d4 100644
43492 --- a/fs/compat_ioctl.c
43493 +++ b/fs/compat_ioctl.c
43494 @@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
43495
43496 err = get_user(palp, &up->palette);
43497 err |= get_user(length, &up->length);
43498 + if (err)
43499 + return -EFAULT;
43500
43501 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
43502 err = put_user(compat_ptr(palp), &up_native->palette);
43503 @@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
43504 return -EFAULT;
43505 if (__get_user(udata, &ss32->iomem_base))
43506 return -EFAULT;
43507 - ss.iomem_base = compat_ptr(udata);
43508 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
43509 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
43510 __get_user(ss.port_high, &ss32->port_high))
43511 return -EFAULT;
43512 @@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
43513 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
43514 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
43515 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
43516 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43517 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43518 return -EFAULT;
43519
43520 return ioctl_preallocate(file, p);
43521 @@ -1610,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
43522 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
43523 {
43524 unsigned int a, b;
43525 - a = *(unsigned int *)p;
43526 - b = *(unsigned int *)q;
43527 + a = *(const unsigned int *)p;
43528 + b = *(const unsigned int *)q;
43529 if (a > b)
43530 return 1;
43531 if (a < b)
43532 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
43533 index 7e6c52d..94bc756 100644
43534 --- a/fs/configfs/dir.c
43535 +++ b/fs/configfs/dir.c
43536 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43537 }
43538 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
43539 struct configfs_dirent *next;
43540 - const char * name;
43541 + const unsigned char * name;
43542 + char d_name[sizeof(next->s_dentry->d_iname)];
43543 int len;
43544 struct inode *inode = NULL;
43545
43546 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43547 continue;
43548
43549 name = configfs_get_name(next);
43550 - len = strlen(name);
43551 + if (next->s_dentry && name == next->s_dentry->d_iname) {
43552 + len = next->s_dentry->d_name.len;
43553 + memcpy(d_name, name, len);
43554 + name = d_name;
43555 + } else
43556 + len = strlen(name);
43557
43558 /*
43559 * We'll have a dentry and an inode for
43560 diff --git a/fs/dcache.c b/fs/dcache.c
43561 index b80531c..8ca7e2d 100644
43562 --- a/fs/dcache.c
43563 +++ b/fs/dcache.c
43564 @@ -3084,7 +3084,7 @@ void __init vfs_caches_init(unsigned long mempages)
43565 mempages -= reserve;
43566
43567 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
43568 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
43569 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
43570
43571 dcache_init();
43572 inode_init();
43573 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
43574 index b80bc84..0d46d1a 100644
43575 --- a/fs/debugfs/inode.c
43576 +++ b/fs/debugfs/inode.c
43577 @@ -408,7 +408,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
43578 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
43579 {
43580 return debugfs_create_file(name,
43581 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
43582 + S_IFDIR | S_IRWXU,
43583 +#else
43584 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
43585 +#endif
43586 parent, NULL, NULL);
43587 }
43588 EXPORT_SYMBOL_GPL(debugfs_create_dir);
43589 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
43590 index ab35b11..b30af66 100644
43591 --- a/fs/ecryptfs/inode.c
43592 +++ b/fs/ecryptfs/inode.c
43593 @@ -672,7 +672,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
43594 old_fs = get_fs();
43595 set_fs(get_ds());
43596 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
43597 - (char __user *)lower_buf,
43598 + (char __force_user *)lower_buf,
43599 lower_bufsiz);
43600 set_fs(old_fs);
43601 if (rc < 0)
43602 @@ -718,7 +718,7 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
43603 }
43604 old_fs = get_fs();
43605 set_fs(get_ds());
43606 - rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
43607 + rc = dentry->d_inode->i_op->readlink(dentry, (char __force_user *)buf, len);
43608 set_fs(old_fs);
43609 if (rc < 0) {
43610 kfree(buf);
43611 @@ -733,7 +733,7 @@ out:
43612 static void
43613 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
43614 {
43615 - char *buf = nd_get_link(nd);
43616 + const char *buf = nd_get_link(nd);
43617 if (!IS_ERR(buf)) {
43618 /* Free the char* */
43619 kfree(buf);
43620 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
43621 index c0038f6..47ab347 100644
43622 --- a/fs/ecryptfs/miscdev.c
43623 +++ b/fs/ecryptfs/miscdev.c
43624 @@ -355,7 +355,7 @@ check_list:
43625 goto out_unlock_msg_ctx;
43626 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
43627 if (msg_ctx->msg) {
43628 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
43629 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
43630 goto out_unlock_msg_ctx;
43631 i += packet_length_size;
43632 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
43633 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
43634 index b2a34a1..162fa69 100644
43635 --- a/fs/ecryptfs/read_write.c
43636 +++ b/fs/ecryptfs/read_write.c
43637 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
43638 return -EIO;
43639 fs_save = get_fs();
43640 set_fs(get_ds());
43641 - rc = vfs_write(lower_file, data, size, &offset);
43642 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
43643 set_fs(fs_save);
43644 mark_inode_dirty_sync(ecryptfs_inode);
43645 return rc;
43646 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
43647 return -EIO;
43648 fs_save = get_fs();
43649 set_fs(get_ds());
43650 - rc = vfs_read(lower_file, data, size, &offset);
43651 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
43652 set_fs(fs_save);
43653 return rc;
43654 }
43655 diff --git a/fs/exec.c b/fs/exec.c
43656 index 29e5f84..ec81452 100644
43657 --- a/fs/exec.c
43658 +++ b/fs/exec.c
43659 @@ -55,6 +55,15 @@
43660 #include <linux/pipe_fs_i.h>
43661 #include <linux/oom.h>
43662 #include <linux/compat.h>
43663 +#include <linux/random.h>
43664 +#include <linux/seq_file.h>
43665 +
43666 +#ifdef CONFIG_PAX_REFCOUNT
43667 +#include <linux/kallsyms.h>
43668 +#include <linux/kdebug.h>
43669 +#endif
43670 +
43671 +#include <trace/events/fs.h>
43672
43673 #include <asm/uaccess.h>
43674 #include <asm/mmu_context.h>
43675 @@ -66,6 +75,18 @@
43676
43677 #include <trace/events/sched.h>
43678
43679 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43680 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
43681 +{
43682 + 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");
43683 +}
43684 +#endif
43685 +
43686 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
43687 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
43688 +EXPORT_SYMBOL(pax_set_initial_flags_func);
43689 +#endif
43690 +
43691 int core_uses_pid;
43692 char core_pattern[CORENAME_MAX_SIZE] = "core";
43693 unsigned int core_pipe_limit;
43694 @@ -75,7 +96,7 @@ struct core_name {
43695 char *corename;
43696 int used, size;
43697 };
43698 -static atomic_t call_count = ATOMIC_INIT(1);
43699 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
43700
43701 /* The maximal length of core_pattern is also specified in sysctl.c */
43702
43703 @@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
43704 int write)
43705 {
43706 struct page *page;
43707 - int ret;
43708
43709 -#ifdef CONFIG_STACK_GROWSUP
43710 - if (write) {
43711 - ret = expand_downwards(bprm->vma, pos);
43712 - if (ret < 0)
43713 - return NULL;
43714 - }
43715 -#endif
43716 - ret = get_user_pages(current, bprm->mm, pos,
43717 - 1, write, 1, &page, NULL);
43718 - if (ret <= 0)
43719 + if (0 > expand_downwards(bprm->vma, pos))
43720 + return NULL;
43721 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
43722 return NULL;
43723
43724 if (write) {
43725 @@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
43726 if (size <= ARG_MAX)
43727 return page;
43728
43729 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43730 + // only allow 512KB for argv+env on suid/sgid binaries
43731 + // to prevent easy ASLR exhaustion
43732 + if (((bprm->cred->euid != current_euid()) ||
43733 + (bprm->cred->egid != current_egid())) &&
43734 + (size > (512 * 1024))) {
43735 + put_page(page);
43736 + return NULL;
43737 + }
43738 +#endif
43739 +
43740 /*
43741 * Limit to 1/4-th the stack size for the argv+env strings.
43742 * This ensures that:
43743 @@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
43744 vma->vm_end = STACK_TOP_MAX;
43745 vma->vm_start = vma->vm_end - PAGE_SIZE;
43746 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
43747 +
43748 +#ifdef CONFIG_PAX_SEGMEXEC
43749 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
43750 +#endif
43751 +
43752 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
43753 INIT_LIST_HEAD(&vma->anon_vma_chain);
43754
43755 @@ -291,6 +320,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
43756 mm->stack_vm = mm->total_vm = 1;
43757 up_write(&mm->mmap_sem);
43758 bprm->p = vma->vm_end - sizeof(void *);
43759 +
43760 +#ifdef CONFIG_PAX_RANDUSTACK
43761 + if (randomize_va_space)
43762 + bprm->p ^= random32() & ~PAGE_MASK;
43763 +#endif
43764 +
43765 return 0;
43766 err:
43767 up_write(&mm->mmap_sem);
43768 @@ -399,19 +434,7 @@ err:
43769 return err;
43770 }
43771
43772 -struct user_arg_ptr {
43773 -#ifdef CONFIG_COMPAT
43774 - bool is_compat;
43775 -#endif
43776 - union {
43777 - const char __user *const __user *native;
43778 -#ifdef CONFIG_COMPAT
43779 - compat_uptr_t __user *compat;
43780 -#endif
43781 - } ptr;
43782 -};
43783 -
43784 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
43785 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
43786 {
43787 const char __user *native;
43788
43789 @@ -420,14 +443,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
43790 compat_uptr_t compat;
43791
43792 if (get_user(compat, argv.ptr.compat + nr))
43793 - return ERR_PTR(-EFAULT);
43794 + return (const char __force_user *)ERR_PTR(-EFAULT);
43795
43796 return compat_ptr(compat);
43797 }
43798 #endif
43799
43800 if (get_user(native, argv.ptr.native + nr))
43801 - return ERR_PTR(-EFAULT);
43802 + return (const char __force_user *)ERR_PTR(-EFAULT);
43803
43804 return native;
43805 }
43806 @@ -446,7 +469,7 @@ static int count(struct user_arg_ptr argv, int max)
43807 if (!p)
43808 break;
43809
43810 - if (IS_ERR(p))
43811 + if (IS_ERR((const char __force_kernel *)p))
43812 return -EFAULT;
43813
43814 if (i++ >= max)
43815 @@ -480,7 +503,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
43816
43817 ret = -EFAULT;
43818 str = get_user_arg_ptr(argv, argc);
43819 - if (IS_ERR(str))
43820 + if (IS_ERR((const char __force_kernel *)str))
43821 goto out;
43822
43823 len = strnlen_user(str, MAX_ARG_STRLEN);
43824 @@ -562,7 +585,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
43825 int r;
43826 mm_segment_t oldfs = get_fs();
43827 struct user_arg_ptr argv = {
43828 - .ptr.native = (const char __user *const __user *)__argv,
43829 + .ptr.native = (const char __force_user *const __force_user *)__argv,
43830 };
43831
43832 set_fs(KERNEL_DS);
43833 @@ -597,7 +620,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
43834 unsigned long new_end = old_end - shift;
43835 struct mmu_gather tlb;
43836
43837 - BUG_ON(new_start > new_end);
43838 + if (new_start >= new_end || new_start < mmap_min_addr)
43839 + return -ENOMEM;
43840
43841 /*
43842 * ensure there are no vmas between where we want to go
43843 @@ -606,6 +630,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
43844 if (vma != find_vma(mm, new_start))
43845 return -EFAULT;
43846
43847 +#ifdef CONFIG_PAX_SEGMEXEC
43848 + BUG_ON(pax_find_mirror_vma(vma));
43849 +#endif
43850 +
43851 /*
43852 * cover the whole range: [new_start, old_end)
43853 */
43854 @@ -686,10 +714,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
43855 stack_top = arch_align_stack(stack_top);
43856 stack_top = PAGE_ALIGN(stack_top);
43857
43858 - if (unlikely(stack_top < mmap_min_addr) ||
43859 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
43860 - return -ENOMEM;
43861 -
43862 stack_shift = vma->vm_end - stack_top;
43863
43864 bprm->p -= stack_shift;
43865 @@ -701,8 +725,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
43866 bprm->exec -= stack_shift;
43867
43868 down_write(&mm->mmap_sem);
43869 +
43870 + /* Move stack pages down in memory. */
43871 + if (stack_shift) {
43872 + ret = shift_arg_pages(vma, stack_shift);
43873 + if (ret)
43874 + goto out_unlock;
43875 + }
43876 +
43877 vm_flags = VM_STACK_FLAGS;
43878
43879 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43880 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43881 + vm_flags &= ~VM_EXEC;
43882 +
43883 +#ifdef CONFIG_PAX_MPROTECT
43884 + if (mm->pax_flags & MF_PAX_MPROTECT)
43885 + vm_flags &= ~VM_MAYEXEC;
43886 +#endif
43887 +
43888 + }
43889 +#endif
43890 +
43891 /*
43892 * Adjust stack execute permissions; explicitly enable for
43893 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
43894 @@ -721,13 +765,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
43895 goto out_unlock;
43896 BUG_ON(prev != vma);
43897
43898 - /* Move stack pages down in memory. */
43899 - if (stack_shift) {
43900 - ret = shift_arg_pages(vma, stack_shift);
43901 - if (ret)
43902 - goto out_unlock;
43903 - }
43904 -
43905 /* mprotect_fixup is overkill to remove the temporary stack flags */
43906 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
43907
43908 @@ -785,6 +822,8 @@ struct file *open_exec(const char *name)
43909
43910 fsnotify_open(file);
43911
43912 + trace_open_exec(name);
43913 +
43914 err = deny_write_access(file);
43915 if (err)
43916 goto exit;
43917 @@ -808,7 +847,7 @@ int kernel_read(struct file *file, loff_t offset,
43918 old_fs = get_fs();
43919 set_fs(get_ds());
43920 /* The cast to a user pointer is valid due to the set_fs() */
43921 - result = vfs_read(file, (void __user *)addr, count, &pos);
43922 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
43923 set_fs(old_fs);
43924 return result;
43925 }
43926 @@ -1254,7 +1293,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
43927 }
43928 rcu_read_unlock();
43929
43930 - if (p->fs->users > n_fs) {
43931 + if (atomic_read(&p->fs->users) > n_fs) {
43932 bprm->unsafe |= LSM_UNSAFE_SHARE;
43933 } else {
43934 res = -EAGAIN;
43935 @@ -1451,6 +1490,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
43936
43937 EXPORT_SYMBOL(search_binary_handler);
43938
43939 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
43940 +static DEFINE_PER_CPU(u64, exec_counter);
43941 +static int __init init_exec_counters(void)
43942 +{
43943 + unsigned int cpu;
43944 +
43945 + for_each_possible_cpu(cpu) {
43946 + per_cpu(exec_counter, cpu) = (u64)cpu;
43947 + }
43948 +
43949 + return 0;
43950 +}
43951 +early_initcall(init_exec_counters);
43952 +static inline void increment_exec_counter(void)
43953 +{
43954 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
43955 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
43956 +}
43957 +#else
43958 +static inline void increment_exec_counter(void) {}
43959 +#endif
43960 +
43961 /*
43962 * sys_execve() executes a new program.
43963 */
43964 @@ -1459,6 +1520,11 @@ static int do_execve_common(const char *filename,
43965 struct user_arg_ptr envp,
43966 struct pt_regs *regs)
43967 {
43968 +#ifdef CONFIG_GRKERNSEC
43969 + struct file *old_exec_file;
43970 + struct acl_subject_label *old_acl;
43971 + struct rlimit old_rlim[RLIM_NLIMITS];
43972 +#endif
43973 struct linux_binprm *bprm;
43974 struct file *file;
43975 struct files_struct *displaced;
43976 @@ -1466,6 +1532,8 @@ static int do_execve_common(const char *filename,
43977 int retval;
43978 const struct cred *cred = current_cred();
43979
43980 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
43981 +
43982 /*
43983 * We move the actual failure in case of RLIMIT_NPROC excess from
43984 * set*uid() to execve() because too many poorly written programs
43985 @@ -1506,12 +1574,27 @@ static int do_execve_common(const char *filename,
43986 if (IS_ERR(file))
43987 goto out_unmark;
43988
43989 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
43990 + retval = -EPERM;
43991 + goto out_file;
43992 + }
43993 +
43994 sched_exec();
43995
43996 bprm->file = file;
43997 bprm->filename = filename;
43998 bprm->interp = filename;
43999
44000 + if (gr_process_user_ban()) {
44001 + retval = -EPERM;
44002 + goto out_file;
44003 + }
44004 +
44005 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
44006 + retval = -EACCES;
44007 + goto out_file;
44008 + }
44009 +
44010 retval = bprm_mm_init(bprm);
44011 if (retval)
44012 goto out_file;
44013 @@ -1528,24 +1611,65 @@ static int do_execve_common(const char *filename,
44014 if (retval < 0)
44015 goto out;
44016
44017 +#ifdef CONFIG_GRKERNSEC
44018 + old_acl = current->acl;
44019 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
44020 + old_exec_file = current->exec_file;
44021 + get_file(file);
44022 + current->exec_file = file;
44023 +#endif
44024 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44025 + /* limit suid stack to 8MB
44026 + we saved the old limits above and will restore them if this exec fails
44027 + */
44028 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
44029 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
44030 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
44031 +#endif
44032 +
44033 + if (!gr_tpe_allow(file)) {
44034 + retval = -EACCES;
44035 + goto out_fail;
44036 + }
44037 +
44038 + if (gr_check_crash_exec(file)) {
44039 + retval = -EACCES;
44040 + goto out_fail;
44041 + }
44042 +
44043 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
44044 + bprm->unsafe);
44045 + if (retval < 0)
44046 + goto out_fail;
44047 +
44048 retval = copy_strings_kernel(1, &bprm->filename, bprm);
44049 if (retval < 0)
44050 - goto out;
44051 + goto out_fail;
44052
44053 bprm->exec = bprm->p;
44054 retval = copy_strings(bprm->envc, envp, bprm);
44055 if (retval < 0)
44056 - goto out;
44057 + goto out_fail;
44058
44059 retval = copy_strings(bprm->argc, argv, bprm);
44060 if (retval < 0)
44061 - goto out;
44062 + goto out_fail;
44063 +
44064 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
44065 +
44066 + gr_handle_exec_args(bprm, argv);
44067
44068 retval = search_binary_handler(bprm,regs);
44069 if (retval < 0)
44070 - goto out;
44071 + goto out_fail;
44072 +#ifdef CONFIG_GRKERNSEC
44073 + if (old_exec_file)
44074 + fput(old_exec_file);
44075 +#endif
44076
44077 /* execve succeeded */
44078 +
44079 + increment_exec_counter();
44080 current->fs->in_exec = 0;
44081 current->in_execve = 0;
44082 acct_update_integrals(current);
44083 @@ -1554,6 +1678,14 @@ static int do_execve_common(const char *filename,
44084 put_files_struct(displaced);
44085 return retval;
44086
44087 +out_fail:
44088 +#ifdef CONFIG_GRKERNSEC
44089 + current->acl = old_acl;
44090 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
44091 + fput(current->exec_file);
44092 + current->exec_file = old_exec_file;
44093 +#endif
44094 +
44095 out:
44096 if (bprm->mm) {
44097 acct_arg_size(bprm, 0);
44098 @@ -1627,7 +1759,7 @@ static int expand_corename(struct core_name *cn)
44099 {
44100 char *old_corename = cn->corename;
44101
44102 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
44103 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
44104 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
44105
44106 if (!cn->corename) {
44107 @@ -1724,7 +1856,7 @@ static int format_corename(struct core_name *cn, long signr)
44108 int pid_in_pattern = 0;
44109 int err = 0;
44110
44111 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
44112 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
44113 cn->corename = kmalloc(cn->size, GFP_KERNEL);
44114 cn->used = 0;
44115
44116 @@ -1821,6 +1953,228 @@ out:
44117 return ispipe;
44118 }
44119
44120 +int pax_check_flags(unsigned long *flags)
44121 +{
44122 + int retval = 0;
44123 +
44124 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
44125 + if (*flags & MF_PAX_SEGMEXEC)
44126 + {
44127 + *flags &= ~MF_PAX_SEGMEXEC;
44128 + retval = -EINVAL;
44129 + }
44130 +#endif
44131 +
44132 + if ((*flags & MF_PAX_PAGEEXEC)
44133 +
44134 +#ifdef CONFIG_PAX_PAGEEXEC
44135 + && (*flags & MF_PAX_SEGMEXEC)
44136 +#endif
44137 +
44138 + )
44139 + {
44140 + *flags &= ~MF_PAX_PAGEEXEC;
44141 + retval = -EINVAL;
44142 + }
44143 +
44144 + if ((*flags & MF_PAX_MPROTECT)
44145 +
44146 +#ifdef CONFIG_PAX_MPROTECT
44147 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44148 +#endif
44149 +
44150 + )
44151 + {
44152 + *flags &= ~MF_PAX_MPROTECT;
44153 + retval = -EINVAL;
44154 + }
44155 +
44156 + if ((*flags & MF_PAX_EMUTRAMP)
44157 +
44158 +#ifdef CONFIG_PAX_EMUTRAMP
44159 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44160 +#endif
44161 +
44162 + )
44163 + {
44164 + *flags &= ~MF_PAX_EMUTRAMP;
44165 + retval = -EINVAL;
44166 + }
44167 +
44168 + return retval;
44169 +}
44170 +
44171 +EXPORT_SYMBOL(pax_check_flags);
44172 +
44173 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44174 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
44175 +{
44176 + struct task_struct *tsk = current;
44177 + struct mm_struct *mm = current->mm;
44178 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
44179 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
44180 + char *path_exec = NULL;
44181 + char *path_fault = NULL;
44182 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
44183 +
44184 + if (buffer_exec && buffer_fault) {
44185 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
44186 +
44187 + down_read(&mm->mmap_sem);
44188 + vma = mm->mmap;
44189 + while (vma && (!vma_exec || !vma_fault)) {
44190 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
44191 + vma_exec = vma;
44192 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
44193 + vma_fault = vma;
44194 + vma = vma->vm_next;
44195 + }
44196 + if (vma_exec) {
44197 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
44198 + if (IS_ERR(path_exec))
44199 + path_exec = "<path too long>";
44200 + else {
44201 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
44202 + if (path_exec) {
44203 + *path_exec = 0;
44204 + path_exec = buffer_exec;
44205 + } else
44206 + path_exec = "<path too long>";
44207 + }
44208 + }
44209 + if (vma_fault) {
44210 + start = vma_fault->vm_start;
44211 + end = vma_fault->vm_end;
44212 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
44213 + if (vma_fault->vm_file) {
44214 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
44215 + if (IS_ERR(path_fault))
44216 + path_fault = "<path too long>";
44217 + else {
44218 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
44219 + if (path_fault) {
44220 + *path_fault = 0;
44221 + path_fault = buffer_fault;
44222 + } else
44223 + path_fault = "<path too long>";
44224 + }
44225 + } else
44226 + path_fault = "<anonymous mapping>";
44227 + }
44228 + up_read(&mm->mmap_sem);
44229 + }
44230 + if (tsk->signal->curr_ip)
44231 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
44232 + else
44233 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
44234 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
44235 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
44236 + task_uid(tsk), task_euid(tsk), pc, sp);
44237 + free_page((unsigned long)buffer_exec);
44238 + free_page((unsigned long)buffer_fault);
44239 + pax_report_insns(regs, pc, sp);
44240 + do_coredump(SIGKILL, SIGKILL, regs);
44241 +}
44242 +#endif
44243 +
44244 +#ifdef CONFIG_PAX_REFCOUNT
44245 +void pax_report_refcount_overflow(struct pt_regs *regs)
44246 +{
44247 + if (current->signal->curr_ip)
44248 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44249 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
44250 + else
44251 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44252 + current->comm, task_pid_nr(current), current_uid(), current_euid());
44253 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
44254 + show_regs(regs);
44255 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
44256 +}
44257 +#endif
44258 +
44259 +#ifdef CONFIG_PAX_USERCOPY
44260 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
44261 +int object_is_on_stack(const void *obj, unsigned long len)
44262 +{
44263 + const void * const stack = task_stack_page(current);
44264 + const void * const stackend = stack + THREAD_SIZE;
44265 +
44266 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44267 + const void *frame = NULL;
44268 + const void *oldframe;
44269 +#endif
44270 +
44271 + if (obj + len < obj)
44272 + return -1;
44273 +
44274 + if (obj + len <= stack || stackend <= obj)
44275 + return 0;
44276 +
44277 + if (obj < stack || stackend < obj + len)
44278 + return -1;
44279 +
44280 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44281 + oldframe = __builtin_frame_address(1);
44282 + if (oldframe)
44283 + frame = __builtin_frame_address(2);
44284 + /*
44285 + low ----------------------------------------------> high
44286 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
44287 + ^----------------^
44288 + allow copies only within here
44289 + */
44290 + while (stack <= frame && frame < stackend) {
44291 + /* if obj + len extends past the last frame, this
44292 + check won't pass and the next frame will be 0,
44293 + causing us to bail out and correctly report
44294 + the copy as invalid
44295 + */
44296 + if (obj + len <= frame)
44297 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
44298 + oldframe = frame;
44299 + frame = *(const void * const *)frame;
44300 + }
44301 + return -1;
44302 +#else
44303 + return 1;
44304 +#endif
44305 +}
44306 +
44307 +__noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
44308 +{
44309 + if (current->signal->curr_ip)
44310 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44311 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44312 + else
44313 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44314 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44315 + dump_stack();
44316 + gr_handle_kernel_exploit();
44317 + do_group_exit(SIGKILL);
44318 +}
44319 +#endif
44320 +
44321 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
44322 +void pax_track_stack(void)
44323 +{
44324 + unsigned long sp = (unsigned long)&sp;
44325 + if (sp < current_thread_info()->lowest_stack &&
44326 + sp > (unsigned long)task_stack_page(current))
44327 + current_thread_info()->lowest_stack = sp;
44328 +}
44329 +EXPORT_SYMBOL(pax_track_stack);
44330 +#endif
44331 +
44332 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
44333 +void report_size_overflow(const char *file, unsigned int line, const char *func)
44334 +{
44335 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u\n", func, file, line);
44336 + dump_stack();
44337 + do_group_exit(SIGKILL);
44338 +}
44339 +EXPORT_SYMBOL(report_size_overflow);
44340 +#endif
44341 +
44342 static int zap_process(struct task_struct *start, int exit_code)
44343 {
44344 struct task_struct *t;
44345 @@ -2018,17 +2372,17 @@ static void wait_for_dump_helpers(struct file *file)
44346 pipe = file->f_path.dentry->d_inode->i_pipe;
44347
44348 pipe_lock(pipe);
44349 - pipe->readers++;
44350 - pipe->writers--;
44351 + atomic_inc(&pipe->readers);
44352 + atomic_dec(&pipe->writers);
44353
44354 - while ((pipe->readers > 1) && (!signal_pending(current))) {
44355 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
44356 wake_up_interruptible_sync(&pipe->wait);
44357 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
44358 pipe_wait(pipe);
44359 }
44360
44361 - pipe->readers--;
44362 - pipe->writers++;
44363 + atomic_dec(&pipe->readers);
44364 + atomic_inc(&pipe->writers);
44365 pipe_unlock(pipe);
44366
44367 }
44368 @@ -2089,7 +2443,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44369 int retval = 0;
44370 int flag = 0;
44371 int ispipe;
44372 - static atomic_t core_dump_count = ATOMIC_INIT(0);
44373 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
44374 struct coredump_params cprm = {
44375 .signr = signr,
44376 .regs = regs,
44377 @@ -2104,6 +2458,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44378
44379 audit_core_dumps(signr);
44380
44381 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
44382 + gr_handle_brute_attach(current, cprm.mm_flags);
44383 +
44384 binfmt = mm->binfmt;
44385 if (!binfmt || !binfmt->core_dump)
44386 goto fail;
44387 @@ -2171,7 +2528,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44388 }
44389 cprm.limit = RLIM_INFINITY;
44390
44391 - dump_count = atomic_inc_return(&core_dump_count);
44392 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
44393 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
44394 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
44395 task_tgid_vnr(current), current->comm);
44396 @@ -2198,6 +2555,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44397 } else {
44398 struct inode *inode;
44399
44400 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
44401 +
44402 if (cprm.limit < binfmt->min_coredump)
44403 goto fail_unlock;
44404
44405 @@ -2241,7 +2600,7 @@ close_fail:
44406 filp_close(cprm.file, NULL);
44407 fail_dropcount:
44408 if (ispipe)
44409 - atomic_dec(&core_dump_count);
44410 + atomic_dec_unchecked(&core_dump_count);
44411 fail_unlock:
44412 kfree(cn.corename);
44413 fail_corename:
44414 @@ -2260,7 +2619,7 @@ fail:
44415 */
44416 int dump_write(struct file *file, const void *addr, int nr)
44417 {
44418 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
44419 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
44420 }
44421 EXPORT_SYMBOL(dump_write);
44422
44423 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
44424 index a8cbe1b..fed04cb 100644
44425 --- a/fs/ext2/balloc.c
44426 +++ b/fs/ext2/balloc.c
44427 @@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
44428
44429 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44430 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44431 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44432 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
44433 sbi->s_resuid != current_fsuid() &&
44434 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
44435 return 0;
44436 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
44437 index baac1b1..1499b62 100644
44438 --- a/fs/ext3/balloc.c
44439 +++ b/fs/ext3/balloc.c
44440 @@ -1438,9 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
44441
44442 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44443 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44444 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44445 + if (free_blocks < root_blocks + 1 &&
44446 !use_reservation && sbi->s_resuid != current_fsuid() &&
44447 - (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
44448 + (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)) &&
44449 + !capable_nolog(CAP_SYS_RESOURCE)) {
44450 return 0;
44451 }
44452 return 1;
44453 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
44454 index 8da837b..ed3835b 100644
44455 --- a/fs/ext4/balloc.c
44456 +++ b/fs/ext4/balloc.c
44457 @@ -463,8 +463,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
44458 /* Hm, nope. Are (enough) root reserved clusters available? */
44459 if (sbi->s_resuid == current_fsuid() ||
44460 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
44461 - capable(CAP_SYS_RESOURCE) ||
44462 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
44463 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
44464 + capable_nolog(CAP_SYS_RESOURCE)) {
44465
44466 if (free_clusters >= (nclusters + dirty_clusters))
44467 return 1;
44468 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
44469 index 0e01e90..ae2bd5e 100644
44470 --- a/fs/ext4/ext4.h
44471 +++ b/fs/ext4/ext4.h
44472 @@ -1225,19 +1225,19 @@ struct ext4_sb_info {
44473 unsigned long s_mb_last_start;
44474
44475 /* stats for buddy allocator */
44476 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
44477 - atomic_t s_bal_success; /* we found long enough chunks */
44478 - atomic_t s_bal_allocated; /* in blocks */
44479 - atomic_t s_bal_ex_scanned; /* total extents scanned */
44480 - atomic_t s_bal_goals; /* goal hits */
44481 - atomic_t s_bal_breaks; /* too long searches */
44482 - atomic_t s_bal_2orders; /* 2^order hits */
44483 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
44484 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
44485 + atomic_unchecked_t s_bal_allocated; /* in blocks */
44486 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
44487 + atomic_unchecked_t s_bal_goals; /* goal hits */
44488 + atomic_unchecked_t s_bal_breaks; /* too long searches */
44489 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
44490 spinlock_t s_bal_lock;
44491 unsigned long s_mb_buddies_generated;
44492 unsigned long long s_mb_generation_time;
44493 - atomic_t s_mb_lost_chunks;
44494 - atomic_t s_mb_preallocated;
44495 - atomic_t s_mb_discarded;
44496 + atomic_unchecked_t s_mb_lost_chunks;
44497 + atomic_unchecked_t s_mb_preallocated;
44498 + atomic_unchecked_t s_mb_discarded;
44499 atomic_t s_lock_busy;
44500
44501 /* locality groups */
44502 diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
44503 index 1365903..9727522 100644
44504 --- a/fs/ext4/ioctl.c
44505 +++ b/fs/ext4/ioctl.c
44506 @@ -261,7 +261,6 @@ group_extend_out:
44507 err = ext4_move_extents(filp, donor_filp, me.orig_start,
44508 me.donor_start, me.len, &me.moved_len);
44509 mnt_drop_write_file(filp);
44510 - mnt_drop_write(filp->f_path.mnt);
44511
44512 if (copy_to_user((struct move_extent __user *)arg,
44513 &me, sizeof(me)))
44514 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
44515 index 6b0a57e..1955a44 100644
44516 --- a/fs/ext4/mballoc.c
44517 +++ b/fs/ext4/mballoc.c
44518 @@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
44519 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
44520
44521 if (EXT4_SB(sb)->s_mb_stats)
44522 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
44523 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
44524
44525 break;
44526 }
44527 @@ -2041,7 +2041,7 @@ repeat:
44528 ac->ac_status = AC_STATUS_CONTINUE;
44529 ac->ac_flags |= EXT4_MB_HINT_FIRST;
44530 cr = 3;
44531 - atomic_inc(&sbi->s_mb_lost_chunks);
44532 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
44533 goto repeat;
44534 }
44535 }
44536 @@ -2545,25 +2545,25 @@ int ext4_mb_release(struct super_block *sb)
44537 if (sbi->s_mb_stats) {
44538 ext4_msg(sb, KERN_INFO,
44539 "mballoc: %u blocks %u reqs (%u success)",
44540 - atomic_read(&sbi->s_bal_allocated),
44541 - atomic_read(&sbi->s_bal_reqs),
44542 - atomic_read(&sbi->s_bal_success));
44543 + atomic_read_unchecked(&sbi->s_bal_allocated),
44544 + atomic_read_unchecked(&sbi->s_bal_reqs),
44545 + atomic_read_unchecked(&sbi->s_bal_success));
44546 ext4_msg(sb, KERN_INFO,
44547 "mballoc: %u extents scanned, %u goal hits, "
44548 "%u 2^N hits, %u breaks, %u lost",
44549 - atomic_read(&sbi->s_bal_ex_scanned),
44550 - atomic_read(&sbi->s_bal_goals),
44551 - atomic_read(&sbi->s_bal_2orders),
44552 - atomic_read(&sbi->s_bal_breaks),
44553 - atomic_read(&sbi->s_mb_lost_chunks));
44554 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
44555 + atomic_read_unchecked(&sbi->s_bal_goals),
44556 + atomic_read_unchecked(&sbi->s_bal_2orders),
44557 + atomic_read_unchecked(&sbi->s_bal_breaks),
44558 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
44559 ext4_msg(sb, KERN_INFO,
44560 "mballoc: %lu generated and it took %Lu",
44561 sbi->s_mb_buddies_generated,
44562 sbi->s_mb_generation_time);
44563 ext4_msg(sb, KERN_INFO,
44564 "mballoc: %u preallocated, %u discarded",
44565 - atomic_read(&sbi->s_mb_preallocated),
44566 - atomic_read(&sbi->s_mb_discarded));
44567 + atomic_read_unchecked(&sbi->s_mb_preallocated),
44568 + atomic_read_unchecked(&sbi->s_mb_discarded));
44569 }
44570
44571 free_percpu(sbi->s_locality_groups);
44572 @@ -3045,16 +3045,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
44573 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
44574
44575 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
44576 - atomic_inc(&sbi->s_bal_reqs);
44577 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
44578 + atomic_inc_unchecked(&sbi->s_bal_reqs);
44579 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
44580 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
44581 - atomic_inc(&sbi->s_bal_success);
44582 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
44583 + atomic_inc_unchecked(&sbi->s_bal_success);
44584 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
44585 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
44586 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
44587 - atomic_inc(&sbi->s_bal_goals);
44588 + atomic_inc_unchecked(&sbi->s_bal_goals);
44589 if (ac->ac_found > sbi->s_mb_max_to_scan)
44590 - atomic_inc(&sbi->s_bal_breaks);
44591 + atomic_inc_unchecked(&sbi->s_bal_breaks);
44592 }
44593
44594 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
44595 @@ -3458,7 +3458,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
44596 trace_ext4_mb_new_inode_pa(ac, pa);
44597
44598 ext4_mb_use_inode_pa(ac, pa);
44599 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
44600 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
44601
44602 ei = EXT4_I(ac->ac_inode);
44603 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
44604 @@ -3518,7 +3518,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
44605 trace_ext4_mb_new_group_pa(ac, pa);
44606
44607 ext4_mb_use_group_pa(ac, pa);
44608 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44609 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44610
44611 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
44612 lg = ac->ac_lg;
44613 @@ -3607,7 +3607,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
44614 * from the bitmap and continue.
44615 */
44616 }
44617 - atomic_add(free, &sbi->s_mb_discarded);
44618 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
44619
44620 return err;
44621 }
44622 @@ -3625,7 +3625,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
44623 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
44624 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
44625 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
44626 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
44627 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
44628 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
44629
44630 return 0;
44631 diff --git a/fs/fcntl.c b/fs/fcntl.c
44632 index 75e7c1f..1eb3e4d 100644
44633 --- a/fs/fcntl.c
44634 +++ b/fs/fcntl.c
44635 @@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
44636 if (err)
44637 return err;
44638
44639 + if (gr_handle_chroot_fowner(pid, type))
44640 + return -ENOENT;
44641 + if (gr_check_protected_task_fowner(pid, type))
44642 + return -EACCES;
44643 +
44644 f_modown(filp, pid, type, force);
44645 return 0;
44646 }
44647 @@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
44648
44649 static int f_setown_ex(struct file *filp, unsigned long arg)
44650 {
44651 - struct f_owner_ex * __user owner_p = (void * __user)arg;
44652 + struct f_owner_ex __user *owner_p = (void __user *)arg;
44653 struct f_owner_ex owner;
44654 struct pid *pid;
44655 int type;
44656 @@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
44657
44658 static int f_getown_ex(struct file *filp, unsigned long arg)
44659 {
44660 - struct f_owner_ex * __user owner_p = (void * __user)arg;
44661 + struct f_owner_ex __user *owner_p = (void __user *)arg;
44662 struct f_owner_ex owner;
44663 int ret = 0;
44664
44665 @@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
44666 switch (cmd) {
44667 case F_DUPFD:
44668 case F_DUPFD_CLOEXEC:
44669 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
44670 if (arg >= rlimit(RLIMIT_NOFILE))
44671 break;
44672 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
44673 diff --git a/fs/fifo.c b/fs/fifo.c
44674 index cf6f434..3d7942c 100644
44675 --- a/fs/fifo.c
44676 +++ b/fs/fifo.c
44677 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
44678 */
44679 filp->f_op = &read_pipefifo_fops;
44680 pipe->r_counter++;
44681 - if (pipe->readers++ == 0)
44682 + if (atomic_inc_return(&pipe->readers) == 1)
44683 wake_up_partner(inode);
44684
44685 - if (!pipe->writers) {
44686 + if (!atomic_read(&pipe->writers)) {
44687 if ((filp->f_flags & O_NONBLOCK)) {
44688 /* suppress POLLHUP until we have
44689 * seen a writer */
44690 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
44691 * errno=ENXIO when there is no process reading the FIFO.
44692 */
44693 ret = -ENXIO;
44694 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
44695 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
44696 goto err;
44697
44698 filp->f_op = &write_pipefifo_fops;
44699 pipe->w_counter++;
44700 - if (!pipe->writers++)
44701 + if (atomic_inc_return(&pipe->writers) == 1)
44702 wake_up_partner(inode);
44703
44704 - if (!pipe->readers) {
44705 + if (!atomic_read(&pipe->readers)) {
44706 if (wait_for_partner(inode, &pipe->r_counter))
44707 goto err_wr;
44708 }
44709 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
44710 */
44711 filp->f_op = &rdwr_pipefifo_fops;
44712
44713 - pipe->readers++;
44714 - pipe->writers++;
44715 + atomic_inc(&pipe->readers);
44716 + atomic_inc(&pipe->writers);
44717 pipe->r_counter++;
44718 pipe->w_counter++;
44719 - if (pipe->readers == 1 || pipe->writers == 1)
44720 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
44721 wake_up_partner(inode);
44722 break;
44723
44724 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
44725 return 0;
44726
44727 err_rd:
44728 - if (!--pipe->readers)
44729 + if (atomic_dec_and_test(&pipe->readers))
44730 wake_up_interruptible(&pipe->wait);
44731 ret = -ERESTARTSYS;
44732 goto err;
44733
44734 err_wr:
44735 - if (!--pipe->writers)
44736 + if (atomic_dec_and_test(&pipe->writers))
44737 wake_up_interruptible(&pipe->wait);
44738 ret = -ERESTARTSYS;
44739 goto err;
44740
44741 err:
44742 - if (!pipe->readers && !pipe->writers)
44743 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
44744 free_pipe_info(inode);
44745
44746 err_nocleanup:
44747 diff --git a/fs/file.c b/fs/file.c
44748 index ba3f605..fade102 100644
44749 --- a/fs/file.c
44750 +++ b/fs/file.c
44751 @@ -15,6 +15,7 @@
44752 #include <linux/slab.h>
44753 #include <linux/vmalloc.h>
44754 #include <linux/file.h>
44755 +#include <linux/security.h>
44756 #include <linux/fdtable.h>
44757 #include <linux/bitops.h>
44758 #include <linux/interrupt.h>
44759 @@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
44760 * N.B. For clone tasks sharing a files structure, this test
44761 * will limit the total number of files that can be opened.
44762 */
44763 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
44764 if (nr >= rlimit(RLIMIT_NOFILE))
44765 return -EMFILE;
44766
44767 diff --git a/fs/filesystems.c b/fs/filesystems.c
44768 index 96f2428..f5eeb8e 100644
44769 --- a/fs/filesystems.c
44770 +++ b/fs/filesystems.c
44771 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
44772 int len = dot ? dot - name : strlen(name);
44773
44774 fs = __get_fs_type(name, len);
44775 +
44776 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
44777 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
44778 +#else
44779 if (!fs && (request_module("%.*s", len, name) == 0))
44780 +#endif
44781 fs = __get_fs_type(name, len);
44782
44783 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
44784 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
44785 index e159e68..e7d2a6f 100644
44786 --- a/fs/fs_struct.c
44787 +++ b/fs/fs_struct.c
44788 @@ -4,6 +4,7 @@
44789 #include <linux/path.h>
44790 #include <linux/slab.h>
44791 #include <linux/fs_struct.h>
44792 +#include <linux/grsecurity.h>
44793 #include "internal.h"
44794
44795 static inline void path_get_longterm(struct path *path)
44796 @@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
44797 write_seqcount_begin(&fs->seq);
44798 old_root = fs->root;
44799 fs->root = *path;
44800 + gr_set_chroot_entries(current, path);
44801 write_seqcount_end(&fs->seq);
44802 spin_unlock(&fs->lock);
44803 if (old_root.dentry)
44804 @@ -65,6 +67,17 @@ static inline int replace_path(struct path *p, const struct path *old, const str
44805 return 1;
44806 }
44807
44808 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
44809 +{
44810 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
44811 + return 0;
44812 + *p = *new;
44813 +
44814 + gr_set_chroot_entries(task, new);
44815 +
44816 + return 1;
44817 +}
44818 +
44819 void chroot_fs_refs(struct path *old_root, struct path *new_root)
44820 {
44821 struct task_struct *g, *p;
44822 @@ -79,7 +92,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
44823 int hits = 0;
44824 spin_lock(&fs->lock);
44825 write_seqcount_begin(&fs->seq);
44826 - hits += replace_path(&fs->root, old_root, new_root);
44827 + hits += replace_root_path(p, &fs->root, old_root, new_root);
44828 hits += replace_path(&fs->pwd, old_root, new_root);
44829 write_seqcount_end(&fs->seq);
44830 while (hits--) {
44831 @@ -111,7 +124,8 @@ void exit_fs(struct task_struct *tsk)
44832 task_lock(tsk);
44833 spin_lock(&fs->lock);
44834 tsk->fs = NULL;
44835 - kill = !--fs->users;
44836 + gr_clear_chroot_entries(tsk);
44837 + kill = !atomic_dec_return(&fs->users);
44838 spin_unlock(&fs->lock);
44839 task_unlock(tsk);
44840 if (kill)
44841 @@ -124,7 +138,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
44842 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
44843 /* We don't need to lock fs - think why ;-) */
44844 if (fs) {
44845 - fs->users = 1;
44846 + atomic_set(&fs->users, 1);
44847 fs->in_exec = 0;
44848 spin_lock_init(&fs->lock);
44849 seqcount_init(&fs->seq);
44850 @@ -133,6 +147,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
44851 spin_lock(&old->lock);
44852 fs->root = old->root;
44853 path_get_longterm(&fs->root);
44854 + /* instead of calling gr_set_chroot_entries here,
44855 + we call it from every caller of this function
44856 + */
44857 fs->pwd = old->pwd;
44858 path_get_longterm(&fs->pwd);
44859 spin_unlock(&old->lock);
44860 @@ -151,8 +168,9 @@ int unshare_fs_struct(void)
44861
44862 task_lock(current);
44863 spin_lock(&fs->lock);
44864 - kill = !--fs->users;
44865 + kill = !atomic_dec_return(&fs->users);
44866 current->fs = new_fs;
44867 + gr_set_chroot_entries(current, &new_fs->root);
44868 spin_unlock(&fs->lock);
44869 task_unlock(current);
44870
44871 @@ -165,13 +183,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
44872
44873 int current_umask(void)
44874 {
44875 - return current->fs->umask;
44876 + return current->fs->umask | gr_acl_umask();
44877 }
44878 EXPORT_SYMBOL(current_umask);
44879
44880 /* to be mentioned only in INIT_TASK */
44881 struct fs_struct init_fs = {
44882 - .users = 1,
44883 + .users = ATOMIC_INIT(1),
44884 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
44885 .seq = SEQCNT_ZERO,
44886 .umask = 0022,
44887 @@ -187,12 +205,13 @@ void daemonize_fs_struct(void)
44888 task_lock(current);
44889
44890 spin_lock(&init_fs.lock);
44891 - init_fs.users++;
44892 + atomic_inc(&init_fs.users);
44893 spin_unlock(&init_fs.lock);
44894
44895 spin_lock(&fs->lock);
44896 current->fs = &init_fs;
44897 - kill = !--fs->users;
44898 + gr_set_chroot_entries(current, &current->fs->root);
44899 + kill = !atomic_dec_return(&fs->users);
44900 spin_unlock(&fs->lock);
44901
44902 task_unlock(current);
44903 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
44904 index 9905350..02eaec4 100644
44905 --- a/fs/fscache/cookie.c
44906 +++ b/fs/fscache/cookie.c
44907 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
44908 parent ? (char *) parent->def->name : "<no-parent>",
44909 def->name, netfs_data);
44910
44911 - fscache_stat(&fscache_n_acquires);
44912 + fscache_stat_unchecked(&fscache_n_acquires);
44913
44914 /* if there's no parent cookie, then we don't create one here either */
44915 if (!parent) {
44916 - fscache_stat(&fscache_n_acquires_null);
44917 + fscache_stat_unchecked(&fscache_n_acquires_null);
44918 _leave(" [no parent]");
44919 return NULL;
44920 }
44921 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
44922 /* allocate and initialise a cookie */
44923 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
44924 if (!cookie) {
44925 - fscache_stat(&fscache_n_acquires_oom);
44926 + fscache_stat_unchecked(&fscache_n_acquires_oom);
44927 _leave(" [ENOMEM]");
44928 return NULL;
44929 }
44930 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
44931
44932 switch (cookie->def->type) {
44933 case FSCACHE_COOKIE_TYPE_INDEX:
44934 - fscache_stat(&fscache_n_cookie_index);
44935 + fscache_stat_unchecked(&fscache_n_cookie_index);
44936 break;
44937 case FSCACHE_COOKIE_TYPE_DATAFILE:
44938 - fscache_stat(&fscache_n_cookie_data);
44939 + fscache_stat_unchecked(&fscache_n_cookie_data);
44940 break;
44941 default:
44942 - fscache_stat(&fscache_n_cookie_special);
44943 + fscache_stat_unchecked(&fscache_n_cookie_special);
44944 break;
44945 }
44946
44947 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
44948 if (fscache_acquire_non_index_cookie(cookie) < 0) {
44949 atomic_dec(&parent->n_children);
44950 __fscache_cookie_put(cookie);
44951 - fscache_stat(&fscache_n_acquires_nobufs);
44952 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
44953 _leave(" = NULL");
44954 return NULL;
44955 }
44956 }
44957
44958 - fscache_stat(&fscache_n_acquires_ok);
44959 + fscache_stat_unchecked(&fscache_n_acquires_ok);
44960 _leave(" = %p", cookie);
44961 return cookie;
44962 }
44963 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
44964 cache = fscache_select_cache_for_object(cookie->parent);
44965 if (!cache) {
44966 up_read(&fscache_addremove_sem);
44967 - fscache_stat(&fscache_n_acquires_no_cache);
44968 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
44969 _leave(" = -ENOMEDIUM [no cache]");
44970 return -ENOMEDIUM;
44971 }
44972 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
44973 object = cache->ops->alloc_object(cache, cookie);
44974 fscache_stat_d(&fscache_n_cop_alloc_object);
44975 if (IS_ERR(object)) {
44976 - fscache_stat(&fscache_n_object_no_alloc);
44977 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
44978 ret = PTR_ERR(object);
44979 goto error;
44980 }
44981
44982 - fscache_stat(&fscache_n_object_alloc);
44983 + fscache_stat_unchecked(&fscache_n_object_alloc);
44984
44985 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
44986
44987 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
44988 struct fscache_object *object;
44989 struct hlist_node *_p;
44990
44991 - fscache_stat(&fscache_n_updates);
44992 + fscache_stat_unchecked(&fscache_n_updates);
44993
44994 if (!cookie) {
44995 - fscache_stat(&fscache_n_updates_null);
44996 + fscache_stat_unchecked(&fscache_n_updates_null);
44997 _leave(" [no cookie]");
44998 return;
44999 }
45000 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45001 struct fscache_object *object;
45002 unsigned long event;
45003
45004 - fscache_stat(&fscache_n_relinquishes);
45005 + fscache_stat_unchecked(&fscache_n_relinquishes);
45006 if (retire)
45007 - fscache_stat(&fscache_n_relinquishes_retire);
45008 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
45009
45010 if (!cookie) {
45011 - fscache_stat(&fscache_n_relinquishes_null);
45012 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
45013 _leave(" [no cookie]");
45014 return;
45015 }
45016 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45017
45018 /* wait for the cookie to finish being instantiated (or to fail) */
45019 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
45020 - fscache_stat(&fscache_n_relinquishes_waitcrt);
45021 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
45022 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
45023 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
45024 }
45025 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
45026 index f6aad48..88dcf26 100644
45027 --- a/fs/fscache/internal.h
45028 +++ b/fs/fscache/internal.h
45029 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
45030 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
45031 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
45032
45033 -extern atomic_t fscache_n_op_pend;
45034 -extern atomic_t fscache_n_op_run;
45035 -extern atomic_t fscache_n_op_enqueue;
45036 -extern atomic_t fscache_n_op_deferred_release;
45037 -extern atomic_t fscache_n_op_release;
45038 -extern atomic_t fscache_n_op_gc;
45039 -extern atomic_t fscache_n_op_cancelled;
45040 -extern atomic_t fscache_n_op_rejected;
45041 +extern atomic_unchecked_t fscache_n_op_pend;
45042 +extern atomic_unchecked_t fscache_n_op_run;
45043 +extern atomic_unchecked_t fscache_n_op_enqueue;
45044 +extern atomic_unchecked_t fscache_n_op_deferred_release;
45045 +extern atomic_unchecked_t fscache_n_op_release;
45046 +extern atomic_unchecked_t fscache_n_op_gc;
45047 +extern atomic_unchecked_t fscache_n_op_cancelled;
45048 +extern atomic_unchecked_t fscache_n_op_rejected;
45049
45050 -extern atomic_t fscache_n_attr_changed;
45051 -extern atomic_t fscache_n_attr_changed_ok;
45052 -extern atomic_t fscache_n_attr_changed_nobufs;
45053 -extern atomic_t fscache_n_attr_changed_nomem;
45054 -extern atomic_t fscache_n_attr_changed_calls;
45055 +extern atomic_unchecked_t fscache_n_attr_changed;
45056 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
45057 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
45058 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
45059 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
45060
45061 -extern atomic_t fscache_n_allocs;
45062 -extern atomic_t fscache_n_allocs_ok;
45063 -extern atomic_t fscache_n_allocs_wait;
45064 -extern atomic_t fscache_n_allocs_nobufs;
45065 -extern atomic_t fscache_n_allocs_intr;
45066 -extern atomic_t fscache_n_allocs_object_dead;
45067 -extern atomic_t fscache_n_alloc_ops;
45068 -extern atomic_t fscache_n_alloc_op_waits;
45069 +extern atomic_unchecked_t fscache_n_allocs;
45070 +extern atomic_unchecked_t fscache_n_allocs_ok;
45071 +extern atomic_unchecked_t fscache_n_allocs_wait;
45072 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
45073 +extern atomic_unchecked_t fscache_n_allocs_intr;
45074 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
45075 +extern atomic_unchecked_t fscache_n_alloc_ops;
45076 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
45077
45078 -extern atomic_t fscache_n_retrievals;
45079 -extern atomic_t fscache_n_retrievals_ok;
45080 -extern atomic_t fscache_n_retrievals_wait;
45081 -extern atomic_t fscache_n_retrievals_nodata;
45082 -extern atomic_t fscache_n_retrievals_nobufs;
45083 -extern atomic_t fscache_n_retrievals_intr;
45084 -extern atomic_t fscache_n_retrievals_nomem;
45085 -extern atomic_t fscache_n_retrievals_object_dead;
45086 -extern atomic_t fscache_n_retrieval_ops;
45087 -extern atomic_t fscache_n_retrieval_op_waits;
45088 +extern atomic_unchecked_t fscache_n_retrievals;
45089 +extern atomic_unchecked_t fscache_n_retrievals_ok;
45090 +extern atomic_unchecked_t fscache_n_retrievals_wait;
45091 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
45092 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
45093 +extern atomic_unchecked_t fscache_n_retrievals_intr;
45094 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
45095 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
45096 +extern atomic_unchecked_t fscache_n_retrieval_ops;
45097 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
45098
45099 -extern atomic_t fscache_n_stores;
45100 -extern atomic_t fscache_n_stores_ok;
45101 -extern atomic_t fscache_n_stores_again;
45102 -extern atomic_t fscache_n_stores_nobufs;
45103 -extern atomic_t fscache_n_stores_oom;
45104 -extern atomic_t fscache_n_store_ops;
45105 -extern atomic_t fscache_n_store_calls;
45106 -extern atomic_t fscache_n_store_pages;
45107 -extern atomic_t fscache_n_store_radix_deletes;
45108 -extern atomic_t fscache_n_store_pages_over_limit;
45109 +extern atomic_unchecked_t fscache_n_stores;
45110 +extern atomic_unchecked_t fscache_n_stores_ok;
45111 +extern atomic_unchecked_t fscache_n_stores_again;
45112 +extern atomic_unchecked_t fscache_n_stores_nobufs;
45113 +extern atomic_unchecked_t fscache_n_stores_oom;
45114 +extern atomic_unchecked_t fscache_n_store_ops;
45115 +extern atomic_unchecked_t fscache_n_store_calls;
45116 +extern atomic_unchecked_t fscache_n_store_pages;
45117 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
45118 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
45119
45120 -extern atomic_t fscache_n_store_vmscan_not_storing;
45121 -extern atomic_t fscache_n_store_vmscan_gone;
45122 -extern atomic_t fscache_n_store_vmscan_busy;
45123 -extern atomic_t fscache_n_store_vmscan_cancelled;
45124 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45125 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
45126 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
45127 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45128
45129 -extern atomic_t fscache_n_marks;
45130 -extern atomic_t fscache_n_uncaches;
45131 +extern atomic_unchecked_t fscache_n_marks;
45132 +extern atomic_unchecked_t fscache_n_uncaches;
45133
45134 -extern atomic_t fscache_n_acquires;
45135 -extern atomic_t fscache_n_acquires_null;
45136 -extern atomic_t fscache_n_acquires_no_cache;
45137 -extern atomic_t fscache_n_acquires_ok;
45138 -extern atomic_t fscache_n_acquires_nobufs;
45139 -extern atomic_t fscache_n_acquires_oom;
45140 +extern atomic_unchecked_t fscache_n_acquires;
45141 +extern atomic_unchecked_t fscache_n_acquires_null;
45142 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
45143 +extern atomic_unchecked_t fscache_n_acquires_ok;
45144 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
45145 +extern atomic_unchecked_t fscache_n_acquires_oom;
45146
45147 -extern atomic_t fscache_n_updates;
45148 -extern atomic_t fscache_n_updates_null;
45149 -extern atomic_t fscache_n_updates_run;
45150 +extern atomic_unchecked_t fscache_n_updates;
45151 +extern atomic_unchecked_t fscache_n_updates_null;
45152 +extern atomic_unchecked_t fscache_n_updates_run;
45153
45154 -extern atomic_t fscache_n_relinquishes;
45155 -extern atomic_t fscache_n_relinquishes_null;
45156 -extern atomic_t fscache_n_relinquishes_waitcrt;
45157 -extern atomic_t fscache_n_relinquishes_retire;
45158 +extern atomic_unchecked_t fscache_n_relinquishes;
45159 +extern atomic_unchecked_t fscache_n_relinquishes_null;
45160 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45161 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
45162
45163 -extern atomic_t fscache_n_cookie_index;
45164 -extern atomic_t fscache_n_cookie_data;
45165 -extern atomic_t fscache_n_cookie_special;
45166 +extern atomic_unchecked_t fscache_n_cookie_index;
45167 +extern atomic_unchecked_t fscache_n_cookie_data;
45168 +extern atomic_unchecked_t fscache_n_cookie_special;
45169
45170 -extern atomic_t fscache_n_object_alloc;
45171 -extern atomic_t fscache_n_object_no_alloc;
45172 -extern atomic_t fscache_n_object_lookups;
45173 -extern atomic_t fscache_n_object_lookups_negative;
45174 -extern atomic_t fscache_n_object_lookups_positive;
45175 -extern atomic_t fscache_n_object_lookups_timed_out;
45176 -extern atomic_t fscache_n_object_created;
45177 -extern atomic_t fscache_n_object_avail;
45178 -extern atomic_t fscache_n_object_dead;
45179 +extern atomic_unchecked_t fscache_n_object_alloc;
45180 +extern atomic_unchecked_t fscache_n_object_no_alloc;
45181 +extern atomic_unchecked_t fscache_n_object_lookups;
45182 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
45183 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
45184 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
45185 +extern atomic_unchecked_t fscache_n_object_created;
45186 +extern atomic_unchecked_t fscache_n_object_avail;
45187 +extern atomic_unchecked_t fscache_n_object_dead;
45188
45189 -extern atomic_t fscache_n_checkaux_none;
45190 -extern atomic_t fscache_n_checkaux_okay;
45191 -extern atomic_t fscache_n_checkaux_update;
45192 -extern atomic_t fscache_n_checkaux_obsolete;
45193 +extern atomic_unchecked_t fscache_n_checkaux_none;
45194 +extern atomic_unchecked_t fscache_n_checkaux_okay;
45195 +extern atomic_unchecked_t fscache_n_checkaux_update;
45196 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
45197
45198 extern atomic_t fscache_n_cop_alloc_object;
45199 extern atomic_t fscache_n_cop_lookup_object;
45200 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
45201 atomic_inc(stat);
45202 }
45203
45204 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
45205 +{
45206 + atomic_inc_unchecked(stat);
45207 +}
45208 +
45209 static inline void fscache_stat_d(atomic_t *stat)
45210 {
45211 atomic_dec(stat);
45212 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
45213
45214 #define __fscache_stat(stat) (NULL)
45215 #define fscache_stat(stat) do {} while (0)
45216 +#define fscache_stat_unchecked(stat) do {} while (0)
45217 #define fscache_stat_d(stat) do {} while (0)
45218 #endif
45219
45220 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
45221 index b6b897c..0ffff9c 100644
45222 --- a/fs/fscache/object.c
45223 +++ b/fs/fscache/object.c
45224 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45225 /* update the object metadata on disk */
45226 case FSCACHE_OBJECT_UPDATING:
45227 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
45228 - fscache_stat(&fscache_n_updates_run);
45229 + fscache_stat_unchecked(&fscache_n_updates_run);
45230 fscache_stat(&fscache_n_cop_update_object);
45231 object->cache->ops->update_object(object);
45232 fscache_stat_d(&fscache_n_cop_update_object);
45233 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45234 spin_lock(&object->lock);
45235 object->state = FSCACHE_OBJECT_DEAD;
45236 spin_unlock(&object->lock);
45237 - fscache_stat(&fscache_n_object_dead);
45238 + fscache_stat_unchecked(&fscache_n_object_dead);
45239 goto terminal_transit;
45240
45241 /* handle the parent cache of this object being withdrawn from
45242 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45243 spin_lock(&object->lock);
45244 object->state = FSCACHE_OBJECT_DEAD;
45245 spin_unlock(&object->lock);
45246 - fscache_stat(&fscache_n_object_dead);
45247 + fscache_stat_unchecked(&fscache_n_object_dead);
45248 goto terminal_transit;
45249
45250 /* complain about the object being woken up once it is
45251 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45252 parent->cookie->def->name, cookie->def->name,
45253 object->cache->tag->name);
45254
45255 - fscache_stat(&fscache_n_object_lookups);
45256 + fscache_stat_unchecked(&fscache_n_object_lookups);
45257 fscache_stat(&fscache_n_cop_lookup_object);
45258 ret = object->cache->ops->lookup_object(object);
45259 fscache_stat_d(&fscache_n_cop_lookup_object);
45260 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45261 if (ret == -ETIMEDOUT) {
45262 /* probably stuck behind another object, so move this one to
45263 * the back of the queue */
45264 - fscache_stat(&fscache_n_object_lookups_timed_out);
45265 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
45266 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45267 }
45268
45269 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
45270
45271 spin_lock(&object->lock);
45272 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45273 - fscache_stat(&fscache_n_object_lookups_negative);
45274 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
45275
45276 /* transit here to allow write requests to begin stacking up
45277 * and read requests to begin returning ENODATA */
45278 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
45279 * result, in which case there may be data available */
45280 spin_lock(&object->lock);
45281 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45282 - fscache_stat(&fscache_n_object_lookups_positive);
45283 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
45284
45285 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
45286
45287 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
45288 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45289 } else {
45290 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
45291 - fscache_stat(&fscache_n_object_created);
45292 + fscache_stat_unchecked(&fscache_n_object_created);
45293
45294 object->state = FSCACHE_OBJECT_AVAILABLE;
45295 spin_unlock(&object->lock);
45296 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
45297 fscache_enqueue_dependents(object);
45298
45299 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
45300 - fscache_stat(&fscache_n_object_avail);
45301 + fscache_stat_unchecked(&fscache_n_object_avail);
45302
45303 _leave("");
45304 }
45305 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45306 enum fscache_checkaux result;
45307
45308 if (!object->cookie->def->check_aux) {
45309 - fscache_stat(&fscache_n_checkaux_none);
45310 + fscache_stat_unchecked(&fscache_n_checkaux_none);
45311 return FSCACHE_CHECKAUX_OKAY;
45312 }
45313
45314 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45315 switch (result) {
45316 /* entry okay as is */
45317 case FSCACHE_CHECKAUX_OKAY:
45318 - fscache_stat(&fscache_n_checkaux_okay);
45319 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
45320 break;
45321
45322 /* entry requires update */
45323 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
45324 - fscache_stat(&fscache_n_checkaux_update);
45325 + fscache_stat_unchecked(&fscache_n_checkaux_update);
45326 break;
45327
45328 /* entry requires deletion */
45329 case FSCACHE_CHECKAUX_OBSOLETE:
45330 - fscache_stat(&fscache_n_checkaux_obsolete);
45331 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
45332 break;
45333
45334 default:
45335 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
45336 index 30afdfa..2256596 100644
45337 --- a/fs/fscache/operation.c
45338 +++ b/fs/fscache/operation.c
45339 @@ -17,7 +17,7 @@
45340 #include <linux/slab.h>
45341 #include "internal.h"
45342
45343 -atomic_t fscache_op_debug_id;
45344 +atomic_unchecked_t fscache_op_debug_id;
45345 EXPORT_SYMBOL(fscache_op_debug_id);
45346
45347 /**
45348 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
45349 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
45350 ASSERTCMP(atomic_read(&op->usage), >, 0);
45351
45352 - fscache_stat(&fscache_n_op_enqueue);
45353 + fscache_stat_unchecked(&fscache_n_op_enqueue);
45354 switch (op->flags & FSCACHE_OP_TYPE) {
45355 case FSCACHE_OP_ASYNC:
45356 _debug("queue async");
45357 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
45358 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
45359 if (op->processor)
45360 fscache_enqueue_operation(op);
45361 - fscache_stat(&fscache_n_op_run);
45362 + fscache_stat_unchecked(&fscache_n_op_run);
45363 }
45364
45365 /*
45366 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45367 if (object->n_ops > 1) {
45368 atomic_inc(&op->usage);
45369 list_add_tail(&op->pend_link, &object->pending_ops);
45370 - fscache_stat(&fscache_n_op_pend);
45371 + fscache_stat_unchecked(&fscache_n_op_pend);
45372 } else if (!list_empty(&object->pending_ops)) {
45373 atomic_inc(&op->usage);
45374 list_add_tail(&op->pend_link, &object->pending_ops);
45375 - fscache_stat(&fscache_n_op_pend);
45376 + fscache_stat_unchecked(&fscache_n_op_pend);
45377 fscache_start_operations(object);
45378 } else {
45379 ASSERTCMP(object->n_in_progress, ==, 0);
45380 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45381 object->n_exclusive++; /* reads and writes must wait */
45382 atomic_inc(&op->usage);
45383 list_add_tail(&op->pend_link, &object->pending_ops);
45384 - fscache_stat(&fscache_n_op_pend);
45385 + fscache_stat_unchecked(&fscache_n_op_pend);
45386 ret = 0;
45387 } else {
45388 /* not allowed to submit ops in any other state */
45389 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
45390 if (object->n_exclusive > 0) {
45391 atomic_inc(&op->usage);
45392 list_add_tail(&op->pend_link, &object->pending_ops);
45393 - fscache_stat(&fscache_n_op_pend);
45394 + fscache_stat_unchecked(&fscache_n_op_pend);
45395 } else if (!list_empty(&object->pending_ops)) {
45396 atomic_inc(&op->usage);
45397 list_add_tail(&op->pend_link, &object->pending_ops);
45398 - fscache_stat(&fscache_n_op_pend);
45399 + fscache_stat_unchecked(&fscache_n_op_pend);
45400 fscache_start_operations(object);
45401 } else {
45402 ASSERTCMP(object->n_exclusive, ==, 0);
45403 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
45404 object->n_ops++;
45405 atomic_inc(&op->usage);
45406 list_add_tail(&op->pend_link, &object->pending_ops);
45407 - fscache_stat(&fscache_n_op_pend);
45408 + fscache_stat_unchecked(&fscache_n_op_pend);
45409 ret = 0;
45410 } else if (object->state == FSCACHE_OBJECT_DYING ||
45411 object->state == FSCACHE_OBJECT_LC_DYING ||
45412 object->state == FSCACHE_OBJECT_WITHDRAWING) {
45413 - fscache_stat(&fscache_n_op_rejected);
45414 + fscache_stat_unchecked(&fscache_n_op_rejected);
45415 ret = -ENOBUFS;
45416 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
45417 fscache_report_unexpected_submission(object, op, ostate);
45418 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
45419
45420 ret = -EBUSY;
45421 if (!list_empty(&op->pend_link)) {
45422 - fscache_stat(&fscache_n_op_cancelled);
45423 + fscache_stat_unchecked(&fscache_n_op_cancelled);
45424 list_del_init(&op->pend_link);
45425 object->n_ops--;
45426 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
45427 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
45428 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
45429 BUG();
45430
45431 - fscache_stat(&fscache_n_op_release);
45432 + fscache_stat_unchecked(&fscache_n_op_release);
45433
45434 if (op->release) {
45435 op->release(op);
45436 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
45437 * lock, and defer it otherwise */
45438 if (!spin_trylock(&object->lock)) {
45439 _debug("defer put");
45440 - fscache_stat(&fscache_n_op_deferred_release);
45441 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
45442
45443 cache = object->cache;
45444 spin_lock(&cache->op_gc_list_lock);
45445 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
45446
45447 _debug("GC DEFERRED REL OBJ%x OP%x",
45448 object->debug_id, op->debug_id);
45449 - fscache_stat(&fscache_n_op_gc);
45450 + fscache_stat_unchecked(&fscache_n_op_gc);
45451
45452 ASSERTCMP(atomic_read(&op->usage), ==, 0);
45453
45454 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
45455 index 3f7a59b..cf196cc 100644
45456 --- a/fs/fscache/page.c
45457 +++ b/fs/fscache/page.c
45458 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45459 val = radix_tree_lookup(&cookie->stores, page->index);
45460 if (!val) {
45461 rcu_read_unlock();
45462 - fscache_stat(&fscache_n_store_vmscan_not_storing);
45463 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
45464 __fscache_uncache_page(cookie, page);
45465 return true;
45466 }
45467 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45468 spin_unlock(&cookie->stores_lock);
45469
45470 if (xpage) {
45471 - fscache_stat(&fscache_n_store_vmscan_cancelled);
45472 - fscache_stat(&fscache_n_store_radix_deletes);
45473 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
45474 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
45475 ASSERTCMP(xpage, ==, page);
45476 } else {
45477 - fscache_stat(&fscache_n_store_vmscan_gone);
45478 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
45479 }
45480
45481 wake_up_bit(&cookie->flags, 0);
45482 @@ -107,7 +107,7 @@ page_busy:
45483 /* we might want to wait here, but that could deadlock the allocator as
45484 * the work threads writing to the cache may all end up sleeping
45485 * on memory allocation */
45486 - fscache_stat(&fscache_n_store_vmscan_busy);
45487 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
45488 return false;
45489 }
45490 EXPORT_SYMBOL(__fscache_maybe_release_page);
45491 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
45492 FSCACHE_COOKIE_STORING_TAG);
45493 if (!radix_tree_tag_get(&cookie->stores, page->index,
45494 FSCACHE_COOKIE_PENDING_TAG)) {
45495 - fscache_stat(&fscache_n_store_radix_deletes);
45496 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
45497 xpage = radix_tree_delete(&cookie->stores, page->index);
45498 }
45499 spin_unlock(&cookie->stores_lock);
45500 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
45501
45502 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
45503
45504 - fscache_stat(&fscache_n_attr_changed_calls);
45505 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
45506
45507 if (fscache_object_is_active(object)) {
45508 fscache_stat(&fscache_n_cop_attr_changed);
45509 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45510
45511 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45512
45513 - fscache_stat(&fscache_n_attr_changed);
45514 + fscache_stat_unchecked(&fscache_n_attr_changed);
45515
45516 op = kzalloc(sizeof(*op), GFP_KERNEL);
45517 if (!op) {
45518 - fscache_stat(&fscache_n_attr_changed_nomem);
45519 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
45520 _leave(" = -ENOMEM");
45521 return -ENOMEM;
45522 }
45523 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45524 if (fscache_submit_exclusive_op(object, op) < 0)
45525 goto nobufs;
45526 spin_unlock(&cookie->lock);
45527 - fscache_stat(&fscache_n_attr_changed_ok);
45528 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
45529 fscache_put_operation(op);
45530 _leave(" = 0");
45531 return 0;
45532 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45533 nobufs:
45534 spin_unlock(&cookie->lock);
45535 kfree(op);
45536 - fscache_stat(&fscache_n_attr_changed_nobufs);
45537 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
45538 _leave(" = %d", -ENOBUFS);
45539 return -ENOBUFS;
45540 }
45541 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
45542 /* allocate a retrieval operation and attempt to submit it */
45543 op = kzalloc(sizeof(*op), GFP_NOIO);
45544 if (!op) {
45545 - fscache_stat(&fscache_n_retrievals_nomem);
45546 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45547 return NULL;
45548 }
45549
45550 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45551 return 0;
45552 }
45553
45554 - fscache_stat(&fscache_n_retrievals_wait);
45555 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
45556
45557 jif = jiffies;
45558 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
45559 fscache_wait_bit_interruptible,
45560 TASK_INTERRUPTIBLE) != 0) {
45561 - fscache_stat(&fscache_n_retrievals_intr);
45562 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45563 _leave(" = -ERESTARTSYS");
45564 return -ERESTARTSYS;
45565 }
45566 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45567 */
45568 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45569 struct fscache_retrieval *op,
45570 - atomic_t *stat_op_waits,
45571 - atomic_t *stat_object_dead)
45572 + atomic_unchecked_t *stat_op_waits,
45573 + atomic_unchecked_t *stat_object_dead)
45574 {
45575 int ret;
45576
45577 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45578 goto check_if_dead;
45579
45580 _debug(">>> WT");
45581 - fscache_stat(stat_op_waits);
45582 + fscache_stat_unchecked(stat_op_waits);
45583 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
45584 fscache_wait_bit_interruptible,
45585 TASK_INTERRUPTIBLE) < 0) {
45586 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45587
45588 check_if_dead:
45589 if (unlikely(fscache_object_is_dead(object))) {
45590 - fscache_stat(stat_object_dead);
45591 + fscache_stat_unchecked(stat_object_dead);
45592 return -ENOBUFS;
45593 }
45594 return 0;
45595 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45596
45597 _enter("%p,%p,,,", cookie, page);
45598
45599 - fscache_stat(&fscache_n_retrievals);
45600 + fscache_stat_unchecked(&fscache_n_retrievals);
45601
45602 if (hlist_empty(&cookie->backing_objects))
45603 goto nobufs;
45604 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45605 goto nobufs_unlock;
45606 spin_unlock(&cookie->lock);
45607
45608 - fscache_stat(&fscache_n_retrieval_ops);
45609 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
45610
45611 /* pin the netfs read context in case we need to do the actual netfs
45612 * read because we've encountered a cache read failure */
45613 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45614
45615 error:
45616 if (ret == -ENOMEM)
45617 - fscache_stat(&fscache_n_retrievals_nomem);
45618 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45619 else if (ret == -ERESTARTSYS)
45620 - fscache_stat(&fscache_n_retrievals_intr);
45621 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45622 else if (ret == -ENODATA)
45623 - fscache_stat(&fscache_n_retrievals_nodata);
45624 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
45625 else if (ret < 0)
45626 - fscache_stat(&fscache_n_retrievals_nobufs);
45627 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45628 else
45629 - fscache_stat(&fscache_n_retrievals_ok);
45630 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
45631
45632 fscache_put_retrieval(op);
45633 _leave(" = %d", ret);
45634 @@ -429,7 +429,7 @@ nobufs_unlock:
45635 spin_unlock(&cookie->lock);
45636 kfree(op);
45637 nobufs:
45638 - fscache_stat(&fscache_n_retrievals_nobufs);
45639 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45640 _leave(" = -ENOBUFS");
45641 return -ENOBUFS;
45642 }
45643 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45644
45645 _enter("%p,,%d,,,", cookie, *nr_pages);
45646
45647 - fscache_stat(&fscache_n_retrievals);
45648 + fscache_stat_unchecked(&fscache_n_retrievals);
45649
45650 if (hlist_empty(&cookie->backing_objects))
45651 goto nobufs;
45652 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45653 goto nobufs_unlock;
45654 spin_unlock(&cookie->lock);
45655
45656 - fscache_stat(&fscache_n_retrieval_ops);
45657 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
45658
45659 /* pin the netfs read context in case we need to do the actual netfs
45660 * read because we've encountered a cache read failure */
45661 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45662
45663 error:
45664 if (ret == -ENOMEM)
45665 - fscache_stat(&fscache_n_retrievals_nomem);
45666 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45667 else if (ret == -ERESTARTSYS)
45668 - fscache_stat(&fscache_n_retrievals_intr);
45669 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45670 else if (ret == -ENODATA)
45671 - fscache_stat(&fscache_n_retrievals_nodata);
45672 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
45673 else if (ret < 0)
45674 - fscache_stat(&fscache_n_retrievals_nobufs);
45675 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45676 else
45677 - fscache_stat(&fscache_n_retrievals_ok);
45678 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
45679
45680 fscache_put_retrieval(op);
45681 _leave(" = %d", ret);
45682 @@ -545,7 +545,7 @@ nobufs_unlock:
45683 spin_unlock(&cookie->lock);
45684 kfree(op);
45685 nobufs:
45686 - fscache_stat(&fscache_n_retrievals_nobufs);
45687 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45688 _leave(" = -ENOBUFS");
45689 return -ENOBUFS;
45690 }
45691 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45692
45693 _enter("%p,%p,,,", cookie, page);
45694
45695 - fscache_stat(&fscache_n_allocs);
45696 + fscache_stat_unchecked(&fscache_n_allocs);
45697
45698 if (hlist_empty(&cookie->backing_objects))
45699 goto nobufs;
45700 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45701 goto nobufs_unlock;
45702 spin_unlock(&cookie->lock);
45703
45704 - fscache_stat(&fscache_n_alloc_ops);
45705 + fscache_stat_unchecked(&fscache_n_alloc_ops);
45706
45707 ret = fscache_wait_for_retrieval_activation(
45708 object, op,
45709 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45710
45711 error:
45712 if (ret == -ERESTARTSYS)
45713 - fscache_stat(&fscache_n_allocs_intr);
45714 + fscache_stat_unchecked(&fscache_n_allocs_intr);
45715 else if (ret < 0)
45716 - fscache_stat(&fscache_n_allocs_nobufs);
45717 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
45718 else
45719 - fscache_stat(&fscache_n_allocs_ok);
45720 + fscache_stat_unchecked(&fscache_n_allocs_ok);
45721
45722 fscache_put_retrieval(op);
45723 _leave(" = %d", ret);
45724 @@ -625,7 +625,7 @@ nobufs_unlock:
45725 spin_unlock(&cookie->lock);
45726 kfree(op);
45727 nobufs:
45728 - fscache_stat(&fscache_n_allocs_nobufs);
45729 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
45730 _leave(" = -ENOBUFS");
45731 return -ENOBUFS;
45732 }
45733 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45734
45735 spin_lock(&cookie->stores_lock);
45736
45737 - fscache_stat(&fscache_n_store_calls);
45738 + fscache_stat_unchecked(&fscache_n_store_calls);
45739
45740 /* find a page to store */
45741 page = NULL;
45742 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45743 page = results[0];
45744 _debug("gang %d [%lx]", n, page->index);
45745 if (page->index > op->store_limit) {
45746 - fscache_stat(&fscache_n_store_pages_over_limit);
45747 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
45748 goto superseded;
45749 }
45750
45751 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
45752 spin_unlock(&cookie->stores_lock);
45753 spin_unlock(&object->lock);
45754
45755 - fscache_stat(&fscache_n_store_pages);
45756 + fscache_stat_unchecked(&fscache_n_store_pages);
45757 fscache_stat(&fscache_n_cop_write_page);
45758 ret = object->cache->ops->write_page(op, page);
45759 fscache_stat_d(&fscache_n_cop_write_page);
45760 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45761 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45762 ASSERT(PageFsCache(page));
45763
45764 - fscache_stat(&fscache_n_stores);
45765 + fscache_stat_unchecked(&fscache_n_stores);
45766
45767 op = kzalloc(sizeof(*op), GFP_NOIO);
45768 if (!op)
45769 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45770 spin_unlock(&cookie->stores_lock);
45771 spin_unlock(&object->lock);
45772
45773 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
45774 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
45775 op->store_limit = object->store_limit;
45776
45777 if (fscache_submit_op(object, &op->op) < 0)
45778 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45779
45780 spin_unlock(&cookie->lock);
45781 radix_tree_preload_end();
45782 - fscache_stat(&fscache_n_store_ops);
45783 - fscache_stat(&fscache_n_stores_ok);
45784 + fscache_stat_unchecked(&fscache_n_store_ops);
45785 + fscache_stat_unchecked(&fscache_n_stores_ok);
45786
45787 /* the work queue now carries its own ref on the object */
45788 fscache_put_operation(&op->op);
45789 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
45790 return 0;
45791
45792 already_queued:
45793 - fscache_stat(&fscache_n_stores_again);
45794 + fscache_stat_unchecked(&fscache_n_stores_again);
45795 already_pending:
45796 spin_unlock(&cookie->stores_lock);
45797 spin_unlock(&object->lock);
45798 spin_unlock(&cookie->lock);
45799 radix_tree_preload_end();
45800 kfree(op);
45801 - fscache_stat(&fscache_n_stores_ok);
45802 + fscache_stat_unchecked(&fscache_n_stores_ok);
45803 _leave(" = 0");
45804 return 0;
45805
45806 @@ -851,14 +851,14 @@ nobufs:
45807 spin_unlock(&cookie->lock);
45808 radix_tree_preload_end();
45809 kfree(op);
45810 - fscache_stat(&fscache_n_stores_nobufs);
45811 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
45812 _leave(" = -ENOBUFS");
45813 return -ENOBUFS;
45814
45815 nomem_free:
45816 kfree(op);
45817 nomem:
45818 - fscache_stat(&fscache_n_stores_oom);
45819 + fscache_stat_unchecked(&fscache_n_stores_oom);
45820 _leave(" = -ENOMEM");
45821 return -ENOMEM;
45822 }
45823 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
45824 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45825 ASSERTCMP(page, !=, NULL);
45826
45827 - fscache_stat(&fscache_n_uncaches);
45828 + fscache_stat_unchecked(&fscache_n_uncaches);
45829
45830 /* cache withdrawal may beat us to it */
45831 if (!PageFsCache(page))
45832 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
45833 unsigned long loop;
45834
45835 #ifdef CONFIG_FSCACHE_STATS
45836 - atomic_add(pagevec->nr, &fscache_n_marks);
45837 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
45838 #endif
45839
45840 for (loop = 0; loop < pagevec->nr; loop++) {
45841 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
45842 index 4765190..2a067f2 100644
45843 --- a/fs/fscache/stats.c
45844 +++ b/fs/fscache/stats.c
45845 @@ -18,95 +18,95 @@
45846 /*
45847 * operation counters
45848 */
45849 -atomic_t fscache_n_op_pend;
45850 -atomic_t fscache_n_op_run;
45851 -atomic_t fscache_n_op_enqueue;
45852 -atomic_t fscache_n_op_requeue;
45853 -atomic_t fscache_n_op_deferred_release;
45854 -atomic_t fscache_n_op_release;
45855 -atomic_t fscache_n_op_gc;
45856 -atomic_t fscache_n_op_cancelled;
45857 -atomic_t fscache_n_op_rejected;
45858 +atomic_unchecked_t fscache_n_op_pend;
45859 +atomic_unchecked_t fscache_n_op_run;
45860 +atomic_unchecked_t fscache_n_op_enqueue;
45861 +atomic_unchecked_t fscache_n_op_requeue;
45862 +atomic_unchecked_t fscache_n_op_deferred_release;
45863 +atomic_unchecked_t fscache_n_op_release;
45864 +atomic_unchecked_t fscache_n_op_gc;
45865 +atomic_unchecked_t fscache_n_op_cancelled;
45866 +atomic_unchecked_t fscache_n_op_rejected;
45867
45868 -atomic_t fscache_n_attr_changed;
45869 -atomic_t fscache_n_attr_changed_ok;
45870 -atomic_t fscache_n_attr_changed_nobufs;
45871 -atomic_t fscache_n_attr_changed_nomem;
45872 -atomic_t fscache_n_attr_changed_calls;
45873 +atomic_unchecked_t fscache_n_attr_changed;
45874 +atomic_unchecked_t fscache_n_attr_changed_ok;
45875 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
45876 +atomic_unchecked_t fscache_n_attr_changed_nomem;
45877 +atomic_unchecked_t fscache_n_attr_changed_calls;
45878
45879 -atomic_t fscache_n_allocs;
45880 -atomic_t fscache_n_allocs_ok;
45881 -atomic_t fscache_n_allocs_wait;
45882 -atomic_t fscache_n_allocs_nobufs;
45883 -atomic_t fscache_n_allocs_intr;
45884 -atomic_t fscache_n_allocs_object_dead;
45885 -atomic_t fscache_n_alloc_ops;
45886 -atomic_t fscache_n_alloc_op_waits;
45887 +atomic_unchecked_t fscache_n_allocs;
45888 +atomic_unchecked_t fscache_n_allocs_ok;
45889 +atomic_unchecked_t fscache_n_allocs_wait;
45890 +atomic_unchecked_t fscache_n_allocs_nobufs;
45891 +atomic_unchecked_t fscache_n_allocs_intr;
45892 +atomic_unchecked_t fscache_n_allocs_object_dead;
45893 +atomic_unchecked_t fscache_n_alloc_ops;
45894 +atomic_unchecked_t fscache_n_alloc_op_waits;
45895
45896 -atomic_t fscache_n_retrievals;
45897 -atomic_t fscache_n_retrievals_ok;
45898 -atomic_t fscache_n_retrievals_wait;
45899 -atomic_t fscache_n_retrievals_nodata;
45900 -atomic_t fscache_n_retrievals_nobufs;
45901 -atomic_t fscache_n_retrievals_intr;
45902 -atomic_t fscache_n_retrievals_nomem;
45903 -atomic_t fscache_n_retrievals_object_dead;
45904 -atomic_t fscache_n_retrieval_ops;
45905 -atomic_t fscache_n_retrieval_op_waits;
45906 +atomic_unchecked_t fscache_n_retrievals;
45907 +atomic_unchecked_t fscache_n_retrievals_ok;
45908 +atomic_unchecked_t fscache_n_retrievals_wait;
45909 +atomic_unchecked_t fscache_n_retrievals_nodata;
45910 +atomic_unchecked_t fscache_n_retrievals_nobufs;
45911 +atomic_unchecked_t fscache_n_retrievals_intr;
45912 +atomic_unchecked_t fscache_n_retrievals_nomem;
45913 +atomic_unchecked_t fscache_n_retrievals_object_dead;
45914 +atomic_unchecked_t fscache_n_retrieval_ops;
45915 +atomic_unchecked_t fscache_n_retrieval_op_waits;
45916
45917 -atomic_t fscache_n_stores;
45918 -atomic_t fscache_n_stores_ok;
45919 -atomic_t fscache_n_stores_again;
45920 -atomic_t fscache_n_stores_nobufs;
45921 -atomic_t fscache_n_stores_oom;
45922 -atomic_t fscache_n_store_ops;
45923 -atomic_t fscache_n_store_calls;
45924 -atomic_t fscache_n_store_pages;
45925 -atomic_t fscache_n_store_radix_deletes;
45926 -atomic_t fscache_n_store_pages_over_limit;
45927 +atomic_unchecked_t fscache_n_stores;
45928 +atomic_unchecked_t fscache_n_stores_ok;
45929 +atomic_unchecked_t fscache_n_stores_again;
45930 +atomic_unchecked_t fscache_n_stores_nobufs;
45931 +atomic_unchecked_t fscache_n_stores_oom;
45932 +atomic_unchecked_t fscache_n_store_ops;
45933 +atomic_unchecked_t fscache_n_store_calls;
45934 +atomic_unchecked_t fscache_n_store_pages;
45935 +atomic_unchecked_t fscache_n_store_radix_deletes;
45936 +atomic_unchecked_t fscache_n_store_pages_over_limit;
45937
45938 -atomic_t fscache_n_store_vmscan_not_storing;
45939 -atomic_t fscache_n_store_vmscan_gone;
45940 -atomic_t fscache_n_store_vmscan_busy;
45941 -atomic_t fscache_n_store_vmscan_cancelled;
45942 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45943 +atomic_unchecked_t fscache_n_store_vmscan_gone;
45944 +atomic_unchecked_t fscache_n_store_vmscan_busy;
45945 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45946
45947 -atomic_t fscache_n_marks;
45948 -atomic_t fscache_n_uncaches;
45949 +atomic_unchecked_t fscache_n_marks;
45950 +atomic_unchecked_t fscache_n_uncaches;
45951
45952 -atomic_t fscache_n_acquires;
45953 -atomic_t fscache_n_acquires_null;
45954 -atomic_t fscache_n_acquires_no_cache;
45955 -atomic_t fscache_n_acquires_ok;
45956 -atomic_t fscache_n_acquires_nobufs;
45957 -atomic_t fscache_n_acquires_oom;
45958 +atomic_unchecked_t fscache_n_acquires;
45959 +atomic_unchecked_t fscache_n_acquires_null;
45960 +atomic_unchecked_t fscache_n_acquires_no_cache;
45961 +atomic_unchecked_t fscache_n_acquires_ok;
45962 +atomic_unchecked_t fscache_n_acquires_nobufs;
45963 +atomic_unchecked_t fscache_n_acquires_oom;
45964
45965 -atomic_t fscache_n_updates;
45966 -atomic_t fscache_n_updates_null;
45967 -atomic_t fscache_n_updates_run;
45968 +atomic_unchecked_t fscache_n_updates;
45969 +atomic_unchecked_t fscache_n_updates_null;
45970 +atomic_unchecked_t fscache_n_updates_run;
45971
45972 -atomic_t fscache_n_relinquishes;
45973 -atomic_t fscache_n_relinquishes_null;
45974 -atomic_t fscache_n_relinquishes_waitcrt;
45975 -atomic_t fscache_n_relinquishes_retire;
45976 +atomic_unchecked_t fscache_n_relinquishes;
45977 +atomic_unchecked_t fscache_n_relinquishes_null;
45978 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45979 +atomic_unchecked_t fscache_n_relinquishes_retire;
45980
45981 -atomic_t fscache_n_cookie_index;
45982 -atomic_t fscache_n_cookie_data;
45983 -atomic_t fscache_n_cookie_special;
45984 +atomic_unchecked_t fscache_n_cookie_index;
45985 +atomic_unchecked_t fscache_n_cookie_data;
45986 +atomic_unchecked_t fscache_n_cookie_special;
45987
45988 -atomic_t fscache_n_object_alloc;
45989 -atomic_t fscache_n_object_no_alloc;
45990 -atomic_t fscache_n_object_lookups;
45991 -atomic_t fscache_n_object_lookups_negative;
45992 -atomic_t fscache_n_object_lookups_positive;
45993 -atomic_t fscache_n_object_lookups_timed_out;
45994 -atomic_t fscache_n_object_created;
45995 -atomic_t fscache_n_object_avail;
45996 -atomic_t fscache_n_object_dead;
45997 +atomic_unchecked_t fscache_n_object_alloc;
45998 +atomic_unchecked_t fscache_n_object_no_alloc;
45999 +atomic_unchecked_t fscache_n_object_lookups;
46000 +atomic_unchecked_t fscache_n_object_lookups_negative;
46001 +atomic_unchecked_t fscache_n_object_lookups_positive;
46002 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
46003 +atomic_unchecked_t fscache_n_object_created;
46004 +atomic_unchecked_t fscache_n_object_avail;
46005 +atomic_unchecked_t fscache_n_object_dead;
46006
46007 -atomic_t fscache_n_checkaux_none;
46008 -atomic_t fscache_n_checkaux_okay;
46009 -atomic_t fscache_n_checkaux_update;
46010 -atomic_t fscache_n_checkaux_obsolete;
46011 +atomic_unchecked_t fscache_n_checkaux_none;
46012 +atomic_unchecked_t fscache_n_checkaux_okay;
46013 +atomic_unchecked_t fscache_n_checkaux_update;
46014 +atomic_unchecked_t fscache_n_checkaux_obsolete;
46015
46016 atomic_t fscache_n_cop_alloc_object;
46017 atomic_t fscache_n_cop_lookup_object;
46018 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
46019 seq_puts(m, "FS-Cache statistics\n");
46020
46021 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
46022 - atomic_read(&fscache_n_cookie_index),
46023 - atomic_read(&fscache_n_cookie_data),
46024 - atomic_read(&fscache_n_cookie_special));
46025 + atomic_read_unchecked(&fscache_n_cookie_index),
46026 + atomic_read_unchecked(&fscache_n_cookie_data),
46027 + atomic_read_unchecked(&fscache_n_cookie_special));
46028
46029 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
46030 - atomic_read(&fscache_n_object_alloc),
46031 - atomic_read(&fscache_n_object_no_alloc),
46032 - atomic_read(&fscache_n_object_avail),
46033 - atomic_read(&fscache_n_object_dead));
46034 + atomic_read_unchecked(&fscache_n_object_alloc),
46035 + atomic_read_unchecked(&fscache_n_object_no_alloc),
46036 + atomic_read_unchecked(&fscache_n_object_avail),
46037 + atomic_read_unchecked(&fscache_n_object_dead));
46038 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
46039 - atomic_read(&fscache_n_checkaux_none),
46040 - atomic_read(&fscache_n_checkaux_okay),
46041 - atomic_read(&fscache_n_checkaux_update),
46042 - atomic_read(&fscache_n_checkaux_obsolete));
46043 + atomic_read_unchecked(&fscache_n_checkaux_none),
46044 + atomic_read_unchecked(&fscache_n_checkaux_okay),
46045 + atomic_read_unchecked(&fscache_n_checkaux_update),
46046 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
46047
46048 seq_printf(m, "Pages : mrk=%u unc=%u\n",
46049 - atomic_read(&fscache_n_marks),
46050 - atomic_read(&fscache_n_uncaches));
46051 + atomic_read_unchecked(&fscache_n_marks),
46052 + atomic_read_unchecked(&fscache_n_uncaches));
46053
46054 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
46055 " oom=%u\n",
46056 - atomic_read(&fscache_n_acquires),
46057 - atomic_read(&fscache_n_acquires_null),
46058 - atomic_read(&fscache_n_acquires_no_cache),
46059 - atomic_read(&fscache_n_acquires_ok),
46060 - atomic_read(&fscache_n_acquires_nobufs),
46061 - atomic_read(&fscache_n_acquires_oom));
46062 + atomic_read_unchecked(&fscache_n_acquires),
46063 + atomic_read_unchecked(&fscache_n_acquires_null),
46064 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
46065 + atomic_read_unchecked(&fscache_n_acquires_ok),
46066 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
46067 + atomic_read_unchecked(&fscache_n_acquires_oom));
46068
46069 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
46070 - atomic_read(&fscache_n_object_lookups),
46071 - atomic_read(&fscache_n_object_lookups_negative),
46072 - atomic_read(&fscache_n_object_lookups_positive),
46073 - atomic_read(&fscache_n_object_created),
46074 - atomic_read(&fscache_n_object_lookups_timed_out));
46075 + atomic_read_unchecked(&fscache_n_object_lookups),
46076 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
46077 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
46078 + atomic_read_unchecked(&fscache_n_object_created),
46079 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
46080
46081 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
46082 - atomic_read(&fscache_n_updates),
46083 - atomic_read(&fscache_n_updates_null),
46084 - atomic_read(&fscache_n_updates_run));
46085 + atomic_read_unchecked(&fscache_n_updates),
46086 + atomic_read_unchecked(&fscache_n_updates_null),
46087 + atomic_read_unchecked(&fscache_n_updates_run));
46088
46089 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
46090 - atomic_read(&fscache_n_relinquishes),
46091 - atomic_read(&fscache_n_relinquishes_null),
46092 - atomic_read(&fscache_n_relinquishes_waitcrt),
46093 - atomic_read(&fscache_n_relinquishes_retire));
46094 + atomic_read_unchecked(&fscache_n_relinquishes),
46095 + atomic_read_unchecked(&fscache_n_relinquishes_null),
46096 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
46097 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
46098
46099 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
46100 - atomic_read(&fscache_n_attr_changed),
46101 - atomic_read(&fscache_n_attr_changed_ok),
46102 - atomic_read(&fscache_n_attr_changed_nobufs),
46103 - atomic_read(&fscache_n_attr_changed_nomem),
46104 - atomic_read(&fscache_n_attr_changed_calls));
46105 + atomic_read_unchecked(&fscache_n_attr_changed),
46106 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
46107 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
46108 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
46109 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
46110
46111 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
46112 - atomic_read(&fscache_n_allocs),
46113 - atomic_read(&fscache_n_allocs_ok),
46114 - atomic_read(&fscache_n_allocs_wait),
46115 - atomic_read(&fscache_n_allocs_nobufs),
46116 - atomic_read(&fscache_n_allocs_intr));
46117 + atomic_read_unchecked(&fscache_n_allocs),
46118 + atomic_read_unchecked(&fscache_n_allocs_ok),
46119 + atomic_read_unchecked(&fscache_n_allocs_wait),
46120 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
46121 + atomic_read_unchecked(&fscache_n_allocs_intr));
46122 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
46123 - atomic_read(&fscache_n_alloc_ops),
46124 - atomic_read(&fscache_n_alloc_op_waits),
46125 - atomic_read(&fscache_n_allocs_object_dead));
46126 + atomic_read_unchecked(&fscache_n_alloc_ops),
46127 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
46128 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
46129
46130 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
46131 " int=%u oom=%u\n",
46132 - atomic_read(&fscache_n_retrievals),
46133 - atomic_read(&fscache_n_retrievals_ok),
46134 - atomic_read(&fscache_n_retrievals_wait),
46135 - atomic_read(&fscache_n_retrievals_nodata),
46136 - atomic_read(&fscache_n_retrievals_nobufs),
46137 - atomic_read(&fscache_n_retrievals_intr),
46138 - atomic_read(&fscache_n_retrievals_nomem));
46139 + atomic_read_unchecked(&fscache_n_retrievals),
46140 + atomic_read_unchecked(&fscache_n_retrievals_ok),
46141 + atomic_read_unchecked(&fscache_n_retrievals_wait),
46142 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
46143 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
46144 + atomic_read_unchecked(&fscache_n_retrievals_intr),
46145 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
46146 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
46147 - atomic_read(&fscache_n_retrieval_ops),
46148 - atomic_read(&fscache_n_retrieval_op_waits),
46149 - atomic_read(&fscache_n_retrievals_object_dead));
46150 + atomic_read_unchecked(&fscache_n_retrieval_ops),
46151 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
46152 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
46153
46154 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
46155 - atomic_read(&fscache_n_stores),
46156 - atomic_read(&fscache_n_stores_ok),
46157 - atomic_read(&fscache_n_stores_again),
46158 - atomic_read(&fscache_n_stores_nobufs),
46159 - atomic_read(&fscache_n_stores_oom));
46160 + atomic_read_unchecked(&fscache_n_stores),
46161 + atomic_read_unchecked(&fscache_n_stores_ok),
46162 + atomic_read_unchecked(&fscache_n_stores_again),
46163 + atomic_read_unchecked(&fscache_n_stores_nobufs),
46164 + atomic_read_unchecked(&fscache_n_stores_oom));
46165 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
46166 - atomic_read(&fscache_n_store_ops),
46167 - atomic_read(&fscache_n_store_calls),
46168 - atomic_read(&fscache_n_store_pages),
46169 - atomic_read(&fscache_n_store_radix_deletes),
46170 - atomic_read(&fscache_n_store_pages_over_limit));
46171 + atomic_read_unchecked(&fscache_n_store_ops),
46172 + atomic_read_unchecked(&fscache_n_store_calls),
46173 + atomic_read_unchecked(&fscache_n_store_pages),
46174 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
46175 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
46176
46177 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
46178 - atomic_read(&fscache_n_store_vmscan_not_storing),
46179 - atomic_read(&fscache_n_store_vmscan_gone),
46180 - atomic_read(&fscache_n_store_vmscan_busy),
46181 - atomic_read(&fscache_n_store_vmscan_cancelled));
46182 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
46183 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
46184 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
46185 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
46186
46187 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
46188 - atomic_read(&fscache_n_op_pend),
46189 - atomic_read(&fscache_n_op_run),
46190 - atomic_read(&fscache_n_op_enqueue),
46191 - atomic_read(&fscache_n_op_cancelled),
46192 - atomic_read(&fscache_n_op_rejected));
46193 + atomic_read_unchecked(&fscache_n_op_pend),
46194 + atomic_read_unchecked(&fscache_n_op_run),
46195 + atomic_read_unchecked(&fscache_n_op_enqueue),
46196 + atomic_read_unchecked(&fscache_n_op_cancelled),
46197 + atomic_read_unchecked(&fscache_n_op_rejected));
46198 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
46199 - atomic_read(&fscache_n_op_deferred_release),
46200 - atomic_read(&fscache_n_op_release),
46201 - atomic_read(&fscache_n_op_gc));
46202 + atomic_read_unchecked(&fscache_n_op_deferred_release),
46203 + atomic_read_unchecked(&fscache_n_op_release),
46204 + atomic_read_unchecked(&fscache_n_op_gc));
46205
46206 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
46207 atomic_read(&fscache_n_cop_alloc_object),
46208 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
46209 index 3426521..3b75162 100644
46210 --- a/fs/fuse/cuse.c
46211 +++ b/fs/fuse/cuse.c
46212 @@ -587,10 +587,12 @@ static int __init cuse_init(void)
46213 INIT_LIST_HEAD(&cuse_conntbl[i]);
46214
46215 /* inherit and extend fuse_dev_operations */
46216 - cuse_channel_fops = fuse_dev_operations;
46217 - cuse_channel_fops.owner = THIS_MODULE;
46218 - cuse_channel_fops.open = cuse_channel_open;
46219 - cuse_channel_fops.release = cuse_channel_release;
46220 + pax_open_kernel();
46221 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
46222 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
46223 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
46224 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
46225 + pax_close_kernel();
46226
46227 cuse_class = class_create(THIS_MODULE, "cuse");
46228 if (IS_ERR(cuse_class))
46229 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
46230 index 7df2b5e..5804aa7 100644
46231 --- a/fs/fuse/dev.c
46232 +++ b/fs/fuse/dev.c
46233 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
46234 ret = 0;
46235 pipe_lock(pipe);
46236
46237 - if (!pipe->readers) {
46238 + if (!atomic_read(&pipe->readers)) {
46239 send_sig(SIGPIPE, current, 0);
46240 if (!ret)
46241 ret = -EPIPE;
46242 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
46243 index bc43832..0cfe5a6 100644
46244 --- a/fs/fuse/dir.c
46245 +++ b/fs/fuse/dir.c
46246 @@ -1181,7 +1181,7 @@ static char *read_link(struct dentry *dentry)
46247 return link;
46248 }
46249
46250 -static void free_link(char *link)
46251 +static void free_link(const char *link)
46252 {
46253 if (!IS_ERR(link))
46254 free_page((unsigned long) link);
46255 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
46256 index a9ba244..d9df391 100644
46257 --- a/fs/gfs2/inode.c
46258 +++ b/fs/gfs2/inode.c
46259 @@ -1496,7 +1496,7 @@ out:
46260
46261 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46262 {
46263 - char *s = nd_get_link(nd);
46264 + const char *s = nd_get_link(nd);
46265 if (!IS_ERR(s))
46266 kfree(s);
46267 }
46268 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
46269 index 001ef01..f7d5f07 100644
46270 --- a/fs/hugetlbfs/inode.c
46271 +++ b/fs/hugetlbfs/inode.c
46272 @@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
46273 .kill_sb = kill_litter_super,
46274 };
46275
46276 -static struct vfsmount *hugetlbfs_vfsmount;
46277 +struct vfsmount *hugetlbfs_vfsmount;
46278
46279 static int can_do_hugetlb_shm(void)
46280 {
46281 diff --git a/fs/inode.c b/fs/inode.c
46282 index 9f4f5fe..6214688 100644
46283 --- a/fs/inode.c
46284 +++ b/fs/inode.c
46285 @@ -860,8 +860,8 @@ unsigned int get_next_ino(void)
46286
46287 #ifdef CONFIG_SMP
46288 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
46289 - static atomic_t shared_last_ino;
46290 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
46291 + static atomic_unchecked_t shared_last_ino;
46292 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
46293
46294 res = next - LAST_INO_BATCH;
46295 }
46296 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
46297 index 4a6cf28..d3a29d3 100644
46298 --- a/fs/jffs2/erase.c
46299 +++ b/fs/jffs2/erase.c
46300 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
46301 struct jffs2_unknown_node marker = {
46302 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
46303 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46304 - .totlen = cpu_to_je32(c->cleanmarker_size)
46305 + .totlen = cpu_to_je32(c->cleanmarker_size),
46306 + .hdr_crc = cpu_to_je32(0)
46307 };
46308
46309 jffs2_prealloc_raw_node_refs(c, jeb, 1);
46310 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
46311 index 74d9be1..d5dd140 100644
46312 --- a/fs/jffs2/wbuf.c
46313 +++ b/fs/jffs2/wbuf.c
46314 @@ -1022,7 +1022,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
46315 {
46316 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
46317 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46318 - .totlen = constant_cpu_to_je32(8)
46319 + .totlen = constant_cpu_to_je32(8),
46320 + .hdr_crc = constant_cpu_to_je32(0)
46321 };
46322
46323 /*
46324 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
46325 index 4a82950..bcaa0cb 100644
46326 --- a/fs/jfs/super.c
46327 +++ b/fs/jfs/super.c
46328 @@ -801,7 +801,7 @@ static int __init init_jfs_fs(void)
46329
46330 jfs_inode_cachep =
46331 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
46332 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
46333 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
46334 init_once);
46335 if (jfs_inode_cachep == NULL)
46336 return -ENOMEM;
46337 diff --git a/fs/libfs.c b/fs/libfs.c
46338 index 18d08f5..fe3dc64 100644
46339 --- a/fs/libfs.c
46340 +++ b/fs/libfs.c
46341 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46342
46343 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
46344 struct dentry *next;
46345 + char d_name[sizeof(next->d_iname)];
46346 + const unsigned char *name;
46347 +
46348 next = list_entry(p, struct dentry, d_u.d_child);
46349 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
46350 if (!simple_positive(next)) {
46351 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46352
46353 spin_unlock(&next->d_lock);
46354 spin_unlock(&dentry->d_lock);
46355 - if (filldir(dirent, next->d_name.name,
46356 + name = next->d_name.name;
46357 + if (name == next->d_iname) {
46358 + memcpy(d_name, name, next->d_name.len);
46359 + name = d_name;
46360 + }
46361 + if (filldir(dirent, name,
46362 next->d_name.len, filp->f_pos,
46363 next->d_inode->i_ino,
46364 dt_type(next->d_inode)) < 0)
46365 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
46366 index 8392cb8..80d6193 100644
46367 --- a/fs/lockd/clntproc.c
46368 +++ b/fs/lockd/clntproc.c
46369 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
46370 /*
46371 * Cookie counter for NLM requests
46372 */
46373 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
46374 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
46375
46376 void nlmclnt_next_cookie(struct nlm_cookie *c)
46377 {
46378 - u32 cookie = atomic_inc_return(&nlm_cookie);
46379 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
46380
46381 memcpy(c->data, &cookie, 4);
46382 c->len=4;
46383 diff --git a/fs/locks.c b/fs/locks.c
46384 index 6a64f15..3114738 100644
46385 --- a/fs/locks.c
46386 +++ b/fs/locks.c
46387 @@ -2075,16 +2075,16 @@ void locks_remove_flock(struct file *filp)
46388 return;
46389
46390 if (filp->f_op && filp->f_op->flock) {
46391 - struct file_lock fl = {
46392 + struct file_lock flock = {
46393 .fl_pid = current->tgid,
46394 .fl_file = filp,
46395 .fl_flags = FL_FLOCK,
46396 .fl_type = F_UNLCK,
46397 .fl_end = OFFSET_MAX,
46398 };
46399 - filp->f_op->flock(filp, F_SETLKW, &fl);
46400 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
46401 - fl.fl_ops->fl_release_private(&fl);
46402 + filp->f_op->flock(filp, F_SETLKW, &flock);
46403 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
46404 + flock.fl_ops->fl_release_private(&flock);
46405 }
46406
46407 lock_flocks();
46408 diff --git a/fs/namei.c b/fs/namei.c
46409 index c427919..232326c 100644
46410 --- a/fs/namei.c
46411 +++ b/fs/namei.c
46412 @@ -278,16 +278,32 @@ int generic_permission(struct inode *inode, int mask)
46413 if (ret != -EACCES)
46414 return ret;
46415
46416 +#ifdef CONFIG_GRKERNSEC
46417 + /* we'll block if we have to log due to a denied capability use */
46418 + if (mask & MAY_NOT_BLOCK)
46419 + return -ECHILD;
46420 +#endif
46421 +
46422 if (S_ISDIR(inode->i_mode)) {
46423 /* DACs are overridable for directories */
46424 - if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46425 - return 0;
46426 if (!(mask & MAY_WRITE))
46427 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46428 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
46429 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46430 return 0;
46431 + if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46432 + return 0;
46433 return -EACCES;
46434 }
46435 /*
46436 + * Searching includes executable on directories, else just read.
46437 + */
46438 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
46439 + if (mask == MAY_READ)
46440 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
46441 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46442 + return 0;
46443 +
46444 + /*
46445 * Read/write DACs are always overridable.
46446 * Executable DACs are overridable when there is
46447 * at least one exec bit set.
46448 @@ -296,14 +312,6 @@ int generic_permission(struct inode *inode, int mask)
46449 if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46450 return 0;
46451
46452 - /*
46453 - * Searching includes executable on directories, else just read.
46454 - */
46455 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
46456 - if (mask == MAY_READ)
46457 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46458 - return 0;
46459 -
46460 return -EACCES;
46461 }
46462
46463 @@ -652,11 +660,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
46464 return error;
46465 }
46466
46467 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
46468 + dentry->d_inode, dentry, nd->path.mnt)) {
46469 + error = -EACCES;
46470 + *p = ERR_PTR(error); /* no ->put_link(), please */
46471 + path_put(&nd->path);
46472 + return error;
46473 + }
46474 +
46475 nd->last_type = LAST_BIND;
46476 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
46477 error = PTR_ERR(*p);
46478 if (!IS_ERR(*p)) {
46479 - char *s = nd_get_link(nd);
46480 + const char *s = nd_get_link(nd);
46481 error = 0;
46482 if (s)
46483 error = __vfs_follow_link(nd, s);
46484 @@ -1355,6 +1371,9 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
46485 if (!res)
46486 res = walk_component(nd, path, &nd->last,
46487 nd->last_type, LOOKUP_FOLLOW);
46488 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode)) {
46489 + res = -EACCES;
46490 + }
46491 put_link(nd, &link, cookie);
46492 } while (res > 0);
46493
46494 @@ -1746,6 +1765,9 @@ static int path_lookupat(int dfd, const char *name,
46495 err = follow_link(&link, nd, &cookie);
46496 if (!err)
46497 err = lookup_last(nd, &path);
46498 + if (!err && gr_handle_symlink_owner(&link, nd->inode)) {
46499 + err = -EACCES;
46500 + }
46501 put_link(nd, &link, cookie);
46502 }
46503 }
46504 @@ -1753,6 +1775,21 @@ static int path_lookupat(int dfd, const char *name,
46505 if (!err)
46506 err = complete_walk(nd);
46507
46508 + if (!(nd->flags & LOOKUP_PARENT)) {
46509 +#ifdef CONFIG_GRKERNSEC
46510 + if (flags & LOOKUP_RCU) {
46511 + if (!err)
46512 + path_put(&nd->path);
46513 + err = -ECHILD;
46514 + } else
46515 +#endif
46516 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46517 + if (!err)
46518 + path_put(&nd->path);
46519 + err = -ENOENT;
46520 + }
46521 + }
46522 +
46523 if (!err && nd->flags & LOOKUP_DIRECTORY) {
46524 if (!nd->inode->i_op->lookup) {
46525 path_put(&nd->path);
46526 @@ -1780,6 +1817,15 @@ static int do_path_lookup(int dfd, const char *name,
46527 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
46528
46529 if (likely(!retval)) {
46530 + if (*name != '/' && nd->path.dentry && nd->inode) {
46531 +#ifdef CONFIG_GRKERNSEC
46532 + if (flags & LOOKUP_RCU)
46533 + return -ECHILD;
46534 +#endif
46535 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
46536 + return -ENOENT;
46537 + }
46538 +
46539 if (unlikely(!audit_dummy_context())) {
46540 if (nd->path.dentry && nd->inode)
46541 audit_inode(name, nd->path.dentry);
46542 @@ -2126,6 +2172,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
46543 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
46544 return -EPERM;
46545
46546 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
46547 + return -EPERM;
46548 + if (gr_handle_rawio(inode))
46549 + return -EPERM;
46550 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
46551 + return -EACCES;
46552 +
46553 return 0;
46554 }
46555
46556 @@ -2187,6 +2240,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46557 error = complete_walk(nd);
46558 if (error)
46559 return ERR_PTR(error);
46560 +#ifdef CONFIG_GRKERNSEC
46561 + if (nd->flags & LOOKUP_RCU) {
46562 + error = -ECHILD;
46563 + goto exit;
46564 + }
46565 +#endif
46566 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46567 + error = -ENOENT;
46568 + goto exit;
46569 + }
46570 audit_inode(pathname, nd->path.dentry);
46571 if (open_flag & O_CREAT) {
46572 error = -EISDIR;
46573 @@ -2197,6 +2260,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46574 error = complete_walk(nd);
46575 if (error)
46576 return ERR_PTR(error);
46577 +#ifdef CONFIG_GRKERNSEC
46578 + if (nd->flags & LOOKUP_RCU) {
46579 + error = -ECHILD;
46580 + goto exit;
46581 + }
46582 +#endif
46583 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
46584 + error = -ENOENT;
46585 + goto exit;
46586 + }
46587 audit_inode(pathname, dir);
46588 goto ok;
46589 }
46590 @@ -2218,6 +2291,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46591 error = complete_walk(nd);
46592 if (error)
46593 return ERR_PTR(error);
46594 +#ifdef CONFIG_GRKERNSEC
46595 + if (nd->flags & LOOKUP_RCU) {
46596 + error = -ECHILD;
46597 + goto exit;
46598 + }
46599 +#endif
46600 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46601 + error = -ENOENT;
46602 + goto exit;
46603 + }
46604
46605 error = -ENOTDIR;
46606 if (nd->flags & LOOKUP_DIRECTORY) {
46607 @@ -2258,6 +2341,12 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46608 /* Negative dentry, just create the file */
46609 if (!dentry->d_inode) {
46610 umode_t mode = op->mode;
46611 +
46612 + if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
46613 + error = -EACCES;
46614 + goto exit_mutex_unlock;
46615 + }
46616 +
46617 if (!IS_POSIXACL(dir->d_inode))
46618 mode &= ~current_umask();
46619 /*
46620 @@ -2281,6 +2370,8 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46621 error = vfs_create(dir->d_inode, dentry, mode, nd);
46622 if (error)
46623 goto exit_mutex_unlock;
46624 + else
46625 + gr_handle_create(path->dentry, path->mnt);
46626 mutex_unlock(&dir->d_inode->i_mutex);
46627 dput(nd->path.dentry);
46628 nd->path.dentry = dentry;
46629 @@ -2290,6 +2381,19 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46630 /*
46631 * It already exists.
46632 */
46633 +
46634 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
46635 + error = -ENOENT;
46636 + goto exit_mutex_unlock;
46637 + }
46638 +
46639 + /* only check if O_CREAT is specified, all other checks need to go
46640 + into may_open */
46641 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
46642 + error = -EACCES;
46643 + goto exit_mutex_unlock;
46644 + }
46645 +
46646 mutex_unlock(&dir->d_inode->i_mutex);
46647 audit_inode(pathname, path->dentry);
46648
46649 @@ -2407,8 +2511,14 @@ static struct file *path_openat(int dfd, const char *pathname,
46650 error = follow_link(&link, nd, &cookie);
46651 if (unlikely(error))
46652 filp = ERR_PTR(error);
46653 - else
46654 + else {
46655 filp = do_last(nd, &path, op, pathname);
46656 + if (!IS_ERR(filp) && gr_handle_symlink_owner(&link, nd->inode)) {
46657 + if (filp)
46658 + fput(filp);
46659 + filp = ERR_PTR(-EACCES);
46660 + }
46661 + }
46662 put_link(nd, &link, cookie);
46663 }
46664 out:
46665 @@ -2502,6 +2612,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
46666 *path = nd.path;
46667 return dentry;
46668 eexist:
46669 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
46670 + dput(dentry);
46671 + dentry = ERR_PTR(-ENOENT);
46672 + goto fail;
46673 + }
46674 dput(dentry);
46675 dentry = ERR_PTR(-EEXIST);
46676 fail:
46677 @@ -2524,6 +2639,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
46678 }
46679 EXPORT_SYMBOL(user_path_create);
46680
46681 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
46682 +{
46683 + char *tmp = getname(pathname);
46684 + struct dentry *res;
46685 + if (IS_ERR(tmp))
46686 + return ERR_CAST(tmp);
46687 + res = kern_path_create(dfd, tmp, path, is_dir);
46688 + if (IS_ERR(res))
46689 + putname(tmp);
46690 + else
46691 + *to = tmp;
46692 + return res;
46693 +}
46694 +
46695 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
46696 {
46697 int error = may_create(dir, dentry);
46698 @@ -2591,6 +2720,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
46699 error = mnt_want_write(path.mnt);
46700 if (error)
46701 goto out_dput;
46702 +
46703 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
46704 + error = -EPERM;
46705 + goto out_drop_write;
46706 + }
46707 +
46708 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
46709 + error = -EACCES;
46710 + goto out_drop_write;
46711 + }
46712 +
46713 error = security_path_mknod(&path, dentry, mode, dev);
46714 if (error)
46715 goto out_drop_write;
46716 @@ -2608,6 +2748,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
46717 }
46718 out_drop_write:
46719 mnt_drop_write(path.mnt);
46720 +
46721 + if (!error)
46722 + gr_handle_create(dentry, path.mnt);
46723 out_dput:
46724 dput(dentry);
46725 mutex_unlock(&path.dentry->d_inode->i_mutex);
46726 @@ -2661,12 +2804,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
46727 error = mnt_want_write(path.mnt);
46728 if (error)
46729 goto out_dput;
46730 +
46731 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
46732 + error = -EACCES;
46733 + goto out_drop_write;
46734 + }
46735 +
46736 error = security_path_mkdir(&path, dentry, mode);
46737 if (error)
46738 goto out_drop_write;
46739 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
46740 out_drop_write:
46741 mnt_drop_write(path.mnt);
46742 +
46743 + if (!error)
46744 + gr_handle_create(dentry, path.mnt);
46745 out_dput:
46746 dput(dentry);
46747 mutex_unlock(&path.dentry->d_inode->i_mutex);
46748 @@ -2746,6 +2898,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
46749 char * name;
46750 struct dentry *dentry;
46751 struct nameidata nd;
46752 + ino_t saved_ino = 0;
46753 + dev_t saved_dev = 0;
46754
46755 error = user_path_parent(dfd, pathname, &nd, &name);
46756 if (error)
46757 @@ -2774,6 +2928,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
46758 error = -ENOENT;
46759 goto exit3;
46760 }
46761 +
46762 + saved_ino = dentry->d_inode->i_ino;
46763 + saved_dev = gr_get_dev_from_dentry(dentry);
46764 +
46765 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
46766 + error = -EACCES;
46767 + goto exit3;
46768 + }
46769 +
46770 error = mnt_want_write(nd.path.mnt);
46771 if (error)
46772 goto exit3;
46773 @@ -2781,6 +2944,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
46774 if (error)
46775 goto exit4;
46776 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
46777 + if (!error && (saved_dev || saved_ino))
46778 + gr_handle_delete(saved_ino, saved_dev);
46779 exit4:
46780 mnt_drop_write(nd.path.mnt);
46781 exit3:
46782 @@ -2843,6 +3008,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46783 struct dentry *dentry;
46784 struct nameidata nd;
46785 struct inode *inode = NULL;
46786 + ino_t saved_ino = 0;
46787 + dev_t saved_dev = 0;
46788
46789 error = user_path_parent(dfd, pathname, &nd, &name);
46790 if (error)
46791 @@ -2865,6 +3032,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46792 if (!inode)
46793 goto slashes;
46794 ihold(inode);
46795 +
46796 + if (inode->i_nlink <= 1) {
46797 + saved_ino = inode->i_ino;
46798 + saved_dev = gr_get_dev_from_dentry(dentry);
46799 + }
46800 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
46801 + error = -EACCES;
46802 + goto exit2;
46803 + }
46804 +
46805 error = mnt_want_write(nd.path.mnt);
46806 if (error)
46807 goto exit2;
46808 @@ -2872,6 +3049,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
46809 if (error)
46810 goto exit3;
46811 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
46812 + if (!error && (saved_ino || saved_dev))
46813 + gr_handle_delete(saved_ino, saved_dev);
46814 exit3:
46815 mnt_drop_write(nd.path.mnt);
46816 exit2:
46817 @@ -2947,10 +3126,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
46818 error = mnt_want_write(path.mnt);
46819 if (error)
46820 goto out_dput;
46821 +
46822 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
46823 + error = -EACCES;
46824 + goto out_drop_write;
46825 + }
46826 +
46827 error = security_path_symlink(&path, dentry, from);
46828 if (error)
46829 goto out_drop_write;
46830 error = vfs_symlink(path.dentry->d_inode, dentry, from);
46831 + if (!error)
46832 + gr_handle_create(dentry, path.mnt);
46833 out_drop_write:
46834 mnt_drop_write(path.mnt);
46835 out_dput:
46836 @@ -3025,6 +3212,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
46837 {
46838 struct dentry *new_dentry;
46839 struct path old_path, new_path;
46840 + char *to = NULL;
46841 int how = 0;
46842 int error;
46843
46844 @@ -3048,7 +3236,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
46845 if (error)
46846 return error;
46847
46848 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
46849 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
46850 error = PTR_ERR(new_dentry);
46851 if (IS_ERR(new_dentry))
46852 goto out;
46853 @@ -3059,13 +3247,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
46854 error = mnt_want_write(new_path.mnt);
46855 if (error)
46856 goto out_dput;
46857 +
46858 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
46859 + old_path.dentry->d_inode,
46860 + old_path.dentry->d_inode->i_mode, to)) {
46861 + error = -EACCES;
46862 + goto out_drop_write;
46863 + }
46864 +
46865 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
46866 + old_path.dentry, old_path.mnt, to)) {
46867 + error = -EACCES;
46868 + goto out_drop_write;
46869 + }
46870 +
46871 error = security_path_link(old_path.dentry, &new_path, new_dentry);
46872 if (error)
46873 goto out_drop_write;
46874 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
46875 + if (!error)
46876 + gr_handle_create(new_dentry, new_path.mnt);
46877 out_drop_write:
46878 mnt_drop_write(new_path.mnt);
46879 out_dput:
46880 + putname(to);
46881 dput(new_dentry);
46882 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
46883 path_put(&new_path);
46884 @@ -3299,6 +3504,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
46885 if (new_dentry == trap)
46886 goto exit5;
46887
46888 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
46889 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
46890 + to);
46891 + if (error)
46892 + goto exit5;
46893 +
46894 error = mnt_want_write(oldnd.path.mnt);
46895 if (error)
46896 goto exit5;
46897 @@ -3308,6 +3519,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
46898 goto exit6;
46899 error = vfs_rename(old_dir->d_inode, old_dentry,
46900 new_dir->d_inode, new_dentry);
46901 + if (!error)
46902 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
46903 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
46904 exit6:
46905 mnt_drop_write(oldnd.path.mnt);
46906 exit5:
46907 @@ -3333,6 +3547,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
46908
46909 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
46910 {
46911 + char tmpbuf[64];
46912 + const char *newlink;
46913 int len;
46914
46915 len = PTR_ERR(link);
46916 @@ -3342,7 +3558,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
46917 len = strlen(link);
46918 if (len > (unsigned) buflen)
46919 len = buflen;
46920 - if (copy_to_user(buffer, link, len))
46921 +
46922 + if (len < sizeof(tmpbuf)) {
46923 + memcpy(tmpbuf, link, len);
46924 + newlink = tmpbuf;
46925 + } else
46926 + newlink = link;
46927 +
46928 + if (copy_to_user(buffer, newlink, len))
46929 len = -EFAULT;
46930 out:
46931 return len;
46932 diff --git a/fs/namespace.c b/fs/namespace.c
46933 index 4e46539..b28253c 100644
46934 --- a/fs/namespace.c
46935 +++ b/fs/namespace.c
46936 @@ -1156,6 +1156,9 @@ static int do_umount(struct mount *mnt, int flags)
46937 if (!(sb->s_flags & MS_RDONLY))
46938 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
46939 up_write(&sb->s_umount);
46940 +
46941 + gr_log_remount(mnt->mnt_devname, retval);
46942 +
46943 return retval;
46944 }
46945
46946 @@ -1175,6 +1178,9 @@ static int do_umount(struct mount *mnt, int flags)
46947 br_write_unlock(vfsmount_lock);
46948 up_write(&namespace_sem);
46949 release_mounts(&umount_list);
46950 +
46951 + gr_log_unmount(mnt->mnt_devname, retval);
46952 +
46953 return retval;
46954 }
46955
46956 @@ -2176,6 +2182,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
46957 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
46958 MS_STRICTATIME);
46959
46960 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
46961 + retval = -EPERM;
46962 + goto dput_out;
46963 + }
46964 +
46965 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
46966 + retval = -EPERM;
46967 + goto dput_out;
46968 + }
46969 +
46970 if (flags & MS_REMOUNT)
46971 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
46972 data_page);
46973 @@ -2190,6 +2206,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
46974 dev_name, data_page);
46975 dput_out:
46976 path_put(&path);
46977 +
46978 + gr_log_mount(dev_name, dir_name, retval);
46979 +
46980 return retval;
46981 }
46982
46983 @@ -2471,6 +2490,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
46984 if (error)
46985 goto out2;
46986
46987 + if (gr_handle_chroot_pivot()) {
46988 + error = -EPERM;
46989 + goto out2;
46990 + }
46991 +
46992 get_fs_root(current->fs, &root);
46993 error = lock_mount(&old);
46994 if (error)
46995 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
46996 index e8bbfa5..864f936 100644
46997 --- a/fs/nfs/inode.c
46998 +++ b/fs/nfs/inode.c
46999 @@ -152,7 +152,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
47000 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
47001 nfsi->attrtimeo_timestamp = jiffies;
47002
47003 - memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
47004 + memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
47005 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
47006 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
47007 else
47008 @@ -1005,16 +1005,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
47009 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
47010 }
47011
47012 -static atomic_long_t nfs_attr_generation_counter;
47013 +static atomic_long_unchecked_t nfs_attr_generation_counter;
47014
47015 static unsigned long nfs_read_attr_generation_counter(void)
47016 {
47017 - return atomic_long_read(&nfs_attr_generation_counter);
47018 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
47019 }
47020
47021 unsigned long nfs_inc_attr_generation_counter(void)
47022 {
47023 - return atomic_long_inc_return(&nfs_attr_generation_counter);
47024 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
47025 }
47026
47027 void nfs_fattr_init(struct nfs_fattr *fattr)
47028 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
47029 index 5686661..80a9a3a 100644
47030 --- a/fs/nfsd/vfs.c
47031 +++ b/fs/nfsd/vfs.c
47032 @@ -933,7 +933,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47033 } else {
47034 oldfs = get_fs();
47035 set_fs(KERNEL_DS);
47036 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
47037 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
47038 set_fs(oldfs);
47039 }
47040
47041 @@ -1037,7 +1037,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47042
47043 /* Write the data. */
47044 oldfs = get_fs(); set_fs(KERNEL_DS);
47045 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
47046 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
47047 set_fs(oldfs);
47048 if (host_err < 0)
47049 goto out_nfserr;
47050 @@ -1573,7 +1573,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
47051 */
47052
47053 oldfs = get_fs(); set_fs(KERNEL_DS);
47054 - host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
47055 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
47056 set_fs(oldfs);
47057
47058 if (host_err < 0)
47059 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
47060 index 3568c8a..e0240d8 100644
47061 --- a/fs/notify/fanotify/fanotify_user.c
47062 +++ b/fs/notify/fanotify/fanotify_user.c
47063 @@ -278,7 +278,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
47064 goto out_close_fd;
47065
47066 ret = -EFAULT;
47067 - if (copy_to_user(buf, &fanotify_event_metadata,
47068 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
47069 + copy_to_user(buf, &fanotify_event_metadata,
47070 fanotify_event_metadata.event_len))
47071 goto out_kill_access_response;
47072
47073 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
47074 index c887b13..0fdf472 100644
47075 --- a/fs/notify/notification.c
47076 +++ b/fs/notify/notification.c
47077 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
47078 * get set to 0 so it will never get 'freed'
47079 */
47080 static struct fsnotify_event *q_overflow_event;
47081 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47082 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47083
47084 /**
47085 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
47086 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47087 */
47088 u32 fsnotify_get_cookie(void)
47089 {
47090 - return atomic_inc_return(&fsnotify_sync_cookie);
47091 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
47092 }
47093 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
47094
47095 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
47096 index 99e3610..02c1068 100644
47097 --- a/fs/ntfs/dir.c
47098 +++ b/fs/ntfs/dir.c
47099 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
47100 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
47101 ~(s64)(ndir->itype.index.block_size - 1)));
47102 /* Bounds checks. */
47103 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47104 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47105 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
47106 "inode 0x%lx or driver bug.", vdir->i_ino);
47107 goto err_out;
47108 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
47109 index 8639169..76697aa 100644
47110 --- a/fs/ntfs/file.c
47111 +++ b/fs/ntfs/file.c
47112 @@ -2229,6 +2229,6 @@ const struct inode_operations ntfs_file_inode_ops = {
47113 #endif /* NTFS_RW */
47114 };
47115
47116 -const struct file_operations ntfs_empty_file_ops = {};
47117 +const struct file_operations ntfs_empty_file_ops __read_only;
47118
47119 -const struct inode_operations ntfs_empty_inode_ops = {};
47120 +const struct inode_operations ntfs_empty_inode_ops __read_only;
47121 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
47122 index 210c352..a174f83 100644
47123 --- a/fs/ocfs2/localalloc.c
47124 +++ b/fs/ocfs2/localalloc.c
47125 @@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
47126 goto bail;
47127 }
47128
47129 - atomic_inc(&osb->alloc_stats.moves);
47130 + atomic_inc_unchecked(&osb->alloc_stats.moves);
47131
47132 bail:
47133 if (handle)
47134 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
47135 index d355e6e..578d905 100644
47136 --- a/fs/ocfs2/ocfs2.h
47137 +++ b/fs/ocfs2/ocfs2.h
47138 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
47139
47140 struct ocfs2_alloc_stats
47141 {
47142 - atomic_t moves;
47143 - atomic_t local_data;
47144 - atomic_t bitmap_data;
47145 - atomic_t bg_allocs;
47146 - atomic_t bg_extends;
47147 + atomic_unchecked_t moves;
47148 + atomic_unchecked_t local_data;
47149 + atomic_unchecked_t bitmap_data;
47150 + atomic_unchecked_t bg_allocs;
47151 + atomic_unchecked_t bg_extends;
47152 };
47153
47154 enum ocfs2_local_alloc_state
47155 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
47156 index f169da4..9112253 100644
47157 --- a/fs/ocfs2/suballoc.c
47158 +++ b/fs/ocfs2/suballoc.c
47159 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
47160 mlog_errno(status);
47161 goto bail;
47162 }
47163 - atomic_inc(&osb->alloc_stats.bg_extends);
47164 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
47165
47166 /* You should never ask for this much metadata */
47167 BUG_ON(bits_wanted >
47168 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
47169 mlog_errno(status);
47170 goto bail;
47171 }
47172 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47173 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47174
47175 *suballoc_loc = res.sr_bg_blkno;
47176 *suballoc_bit_start = res.sr_bit_offset;
47177 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
47178 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
47179 res->sr_bits);
47180
47181 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47182 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47183
47184 BUG_ON(res->sr_bits != 1);
47185
47186 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
47187 mlog_errno(status);
47188 goto bail;
47189 }
47190 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47191 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47192
47193 BUG_ON(res.sr_bits != 1);
47194
47195 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47196 cluster_start,
47197 num_clusters);
47198 if (!status)
47199 - atomic_inc(&osb->alloc_stats.local_data);
47200 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
47201 } else {
47202 if (min_clusters > (osb->bitmap_cpg - 1)) {
47203 /* The only paths asking for contiguousness
47204 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47205 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
47206 res.sr_bg_blkno,
47207 res.sr_bit_offset);
47208 - atomic_inc(&osb->alloc_stats.bitmap_data);
47209 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
47210 *num_clusters = res.sr_bits;
47211 }
47212 }
47213 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
47214 index 68f4541..89cfe6a 100644
47215 --- a/fs/ocfs2/super.c
47216 +++ b/fs/ocfs2/super.c
47217 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
47218 "%10s => GlobalAllocs: %d LocalAllocs: %d "
47219 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
47220 "Stats",
47221 - atomic_read(&osb->alloc_stats.bitmap_data),
47222 - atomic_read(&osb->alloc_stats.local_data),
47223 - atomic_read(&osb->alloc_stats.bg_allocs),
47224 - atomic_read(&osb->alloc_stats.moves),
47225 - atomic_read(&osb->alloc_stats.bg_extends));
47226 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
47227 + atomic_read_unchecked(&osb->alloc_stats.local_data),
47228 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
47229 + atomic_read_unchecked(&osb->alloc_stats.moves),
47230 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
47231
47232 out += snprintf(buf + out, len - out,
47233 "%10s => State: %u Descriptor: %llu Size: %u bits "
47234 @@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
47235 spin_lock_init(&osb->osb_xattr_lock);
47236 ocfs2_init_steal_slots(osb);
47237
47238 - atomic_set(&osb->alloc_stats.moves, 0);
47239 - atomic_set(&osb->alloc_stats.local_data, 0);
47240 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
47241 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
47242 - atomic_set(&osb->alloc_stats.bg_extends, 0);
47243 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
47244 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
47245 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
47246 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
47247 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
47248
47249 /* Copy the blockcheck stats from the superblock probe */
47250 osb->osb_ecc_stats = *stats;
47251 diff --git a/fs/ocfs2/symlink.c b/fs/ocfs2/symlink.c
47252 index 5d22872..523db20 100644
47253 --- a/fs/ocfs2/symlink.c
47254 +++ b/fs/ocfs2/symlink.c
47255 @@ -142,7 +142,7 @@ bail:
47256
47257 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
47258 {
47259 - char *link = nd_get_link(nd);
47260 + const char *link = nd_get_link(nd);
47261 if (!IS_ERR(link))
47262 kfree(link);
47263 }
47264 diff --git a/fs/open.c b/fs/open.c
47265 index 3f1108b..822d7f7 100644
47266 --- a/fs/open.c
47267 +++ b/fs/open.c
47268 @@ -31,6 +31,8 @@
47269 #include <linux/ima.h>
47270 #include <linux/dnotify.h>
47271
47272 +#define CREATE_TRACE_POINTS
47273 +#include <trace/events/fs.h>
47274 #include "internal.h"
47275
47276 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
47277 @@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
47278 error = locks_verify_truncate(inode, NULL, length);
47279 if (!error)
47280 error = security_path_truncate(&path);
47281 +
47282 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
47283 + error = -EACCES;
47284 +
47285 if (!error)
47286 error = do_truncate(path.dentry, length, 0, NULL);
47287
47288 @@ -358,6 +364,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
47289 if (__mnt_is_readonly(path.mnt))
47290 res = -EROFS;
47291
47292 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
47293 + res = -EACCES;
47294 +
47295 out_path_release:
47296 path_put(&path);
47297 out:
47298 @@ -384,6 +393,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
47299 if (error)
47300 goto dput_and_out;
47301
47302 + gr_log_chdir(path.dentry, path.mnt);
47303 +
47304 set_fs_pwd(current->fs, &path);
47305
47306 dput_and_out:
47307 @@ -410,6 +421,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
47308 goto out_putf;
47309
47310 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
47311 +
47312 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
47313 + error = -EPERM;
47314 +
47315 + if (!error)
47316 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
47317 +
47318 if (!error)
47319 set_fs_pwd(current->fs, &file->f_path);
47320 out_putf:
47321 @@ -438,7 +456,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
47322 if (error)
47323 goto dput_and_out;
47324
47325 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
47326 + goto dput_and_out;
47327 +
47328 set_fs_root(current->fs, &path);
47329 +
47330 + gr_handle_chroot_chdir(&path);
47331 +
47332 error = 0;
47333 dput_and_out:
47334 path_put(&path);
47335 @@ -456,6 +480,16 @@ static int chmod_common(struct path *path, umode_t mode)
47336 if (error)
47337 return error;
47338 mutex_lock(&inode->i_mutex);
47339 +
47340 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
47341 + error = -EACCES;
47342 + goto out_unlock;
47343 + }
47344 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
47345 + error = -EACCES;
47346 + goto out_unlock;
47347 + }
47348 +
47349 error = security_path_chmod(path, mode);
47350 if (error)
47351 goto out_unlock;
47352 @@ -506,6 +540,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
47353 int error;
47354 struct iattr newattrs;
47355
47356 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
47357 + return -EACCES;
47358 +
47359 newattrs.ia_valid = ATTR_CTIME;
47360 if (user != (uid_t) -1) {
47361 newattrs.ia_valid |= ATTR_UID;
47362 @@ -987,6 +1024,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
47363 } else {
47364 fsnotify_open(f);
47365 fd_install(fd, f);
47366 + trace_do_sys_open(tmp, flags, mode);
47367 }
47368 }
47369 putname(tmp);
47370 diff --git a/fs/pipe.c b/fs/pipe.c
47371 index fec5e4a..f4210f9 100644
47372 --- a/fs/pipe.c
47373 +++ b/fs/pipe.c
47374 @@ -438,9 +438,9 @@ redo:
47375 }
47376 if (bufs) /* More to do? */
47377 continue;
47378 - if (!pipe->writers)
47379 + if (!atomic_read(&pipe->writers))
47380 break;
47381 - if (!pipe->waiting_writers) {
47382 + if (!atomic_read(&pipe->waiting_writers)) {
47383 /* syscall merging: Usually we must not sleep
47384 * if O_NONBLOCK is set, or if we got some data.
47385 * But if a writer sleeps in kernel space, then
47386 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
47387 mutex_lock(&inode->i_mutex);
47388 pipe = inode->i_pipe;
47389
47390 - if (!pipe->readers) {
47391 + if (!atomic_read(&pipe->readers)) {
47392 send_sig(SIGPIPE, current, 0);
47393 ret = -EPIPE;
47394 goto out;
47395 @@ -553,7 +553,7 @@ redo1:
47396 for (;;) {
47397 int bufs;
47398
47399 - if (!pipe->readers) {
47400 + if (!atomic_read(&pipe->readers)) {
47401 send_sig(SIGPIPE, current, 0);
47402 if (!ret)
47403 ret = -EPIPE;
47404 @@ -644,9 +644,9 @@ redo2:
47405 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
47406 do_wakeup = 0;
47407 }
47408 - pipe->waiting_writers++;
47409 + atomic_inc(&pipe->waiting_writers);
47410 pipe_wait(pipe);
47411 - pipe->waiting_writers--;
47412 + atomic_dec(&pipe->waiting_writers);
47413 }
47414 out:
47415 mutex_unlock(&inode->i_mutex);
47416 @@ -713,7 +713,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47417 mask = 0;
47418 if (filp->f_mode & FMODE_READ) {
47419 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
47420 - if (!pipe->writers && filp->f_version != pipe->w_counter)
47421 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
47422 mask |= POLLHUP;
47423 }
47424
47425 @@ -723,7 +723,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47426 * Most Unices do not set POLLERR for FIFOs but on Linux they
47427 * behave exactly like pipes for poll().
47428 */
47429 - if (!pipe->readers)
47430 + if (!atomic_read(&pipe->readers))
47431 mask |= POLLERR;
47432 }
47433
47434 @@ -737,10 +737,10 @@ pipe_release(struct inode *inode, int decr, int decw)
47435
47436 mutex_lock(&inode->i_mutex);
47437 pipe = inode->i_pipe;
47438 - pipe->readers -= decr;
47439 - pipe->writers -= decw;
47440 + atomic_sub(decr, &pipe->readers);
47441 + atomic_sub(decw, &pipe->writers);
47442
47443 - if (!pipe->readers && !pipe->writers) {
47444 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
47445 free_pipe_info(inode);
47446 } else {
47447 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
47448 @@ -830,7 +830,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
47449
47450 if (inode->i_pipe) {
47451 ret = 0;
47452 - inode->i_pipe->readers++;
47453 + atomic_inc(&inode->i_pipe->readers);
47454 }
47455
47456 mutex_unlock(&inode->i_mutex);
47457 @@ -847,7 +847,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
47458
47459 if (inode->i_pipe) {
47460 ret = 0;
47461 - inode->i_pipe->writers++;
47462 + atomic_inc(&inode->i_pipe->writers);
47463 }
47464
47465 mutex_unlock(&inode->i_mutex);
47466 @@ -865,9 +865,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
47467 if (inode->i_pipe) {
47468 ret = 0;
47469 if (filp->f_mode & FMODE_READ)
47470 - inode->i_pipe->readers++;
47471 + atomic_inc(&inode->i_pipe->readers);
47472 if (filp->f_mode & FMODE_WRITE)
47473 - inode->i_pipe->writers++;
47474 + atomic_inc(&inode->i_pipe->writers);
47475 }
47476
47477 mutex_unlock(&inode->i_mutex);
47478 @@ -959,7 +959,7 @@ void free_pipe_info(struct inode *inode)
47479 inode->i_pipe = NULL;
47480 }
47481
47482 -static struct vfsmount *pipe_mnt __read_mostly;
47483 +struct vfsmount *pipe_mnt __read_mostly;
47484
47485 /*
47486 * pipefs_dname() is called from d_path().
47487 @@ -989,7 +989,8 @@ static struct inode * get_pipe_inode(void)
47488 goto fail_iput;
47489 inode->i_pipe = pipe;
47490
47491 - pipe->readers = pipe->writers = 1;
47492 + atomic_set(&pipe->readers, 1);
47493 + atomic_set(&pipe->writers, 1);
47494 inode->i_fop = &rdwr_pipefifo_fops;
47495
47496 /*
47497 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
47498 index 15af622..0e9f4467 100644
47499 --- a/fs/proc/Kconfig
47500 +++ b/fs/proc/Kconfig
47501 @@ -30,12 +30,12 @@ config PROC_FS
47502
47503 config PROC_KCORE
47504 bool "/proc/kcore support" if !ARM
47505 - depends on PROC_FS && MMU
47506 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
47507
47508 config PROC_VMCORE
47509 bool "/proc/vmcore support"
47510 - depends on PROC_FS && CRASH_DUMP
47511 - default y
47512 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
47513 + default n
47514 help
47515 Exports the dump image of crashed kernel in ELF format.
47516
47517 @@ -59,8 +59,8 @@ config PROC_SYSCTL
47518 limited in memory.
47519
47520 config PROC_PAGE_MONITOR
47521 - default y
47522 - depends on PROC_FS && MMU
47523 + default n
47524 + depends on PROC_FS && MMU && !GRKERNSEC
47525 bool "Enable /proc page monitoring" if EXPERT
47526 help
47527 Various /proc files exist to monitor process memory utilization:
47528 diff --git a/fs/proc/array.c b/fs/proc/array.c
47529 index f9bd395..acb7847 100644
47530 --- a/fs/proc/array.c
47531 +++ b/fs/proc/array.c
47532 @@ -60,6 +60,7 @@
47533 #include <linux/tty.h>
47534 #include <linux/string.h>
47535 #include <linux/mman.h>
47536 +#include <linux/grsecurity.h>
47537 #include <linux/proc_fs.h>
47538 #include <linux/ioport.h>
47539 #include <linux/uaccess.h>
47540 @@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
47541 seq_putc(m, '\n');
47542 }
47543
47544 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47545 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
47546 +{
47547 + if (p->mm)
47548 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
47549 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
47550 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
47551 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
47552 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
47553 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
47554 + else
47555 + seq_printf(m, "PaX:\t-----\n");
47556 +}
47557 +#endif
47558 +
47559 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47560 struct pid *pid, struct task_struct *task)
47561 {
47562 @@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47563 task_cpus_allowed(m, task);
47564 cpuset_task_status_allowed(m, task);
47565 task_context_switch_counts(m, task);
47566 +
47567 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47568 + task_pax(m, task);
47569 +#endif
47570 +
47571 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
47572 + task_grsec_rbac(m, task);
47573 +#endif
47574 +
47575 return 0;
47576 }
47577
47578 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47579 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
47580 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
47581 + _mm->pax_flags & MF_PAX_SEGMEXEC))
47582 +#endif
47583 +
47584 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47585 struct pid *pid, struct task_struct *task, int whole)
47586 {
47587 @@ -378,6 +409,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47588 char tcomm[sizeof(task->comm)];
47589 unsigned long flags;
47590
47591 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47592 + if (current->exec_id != m->exec_id) {
47593 + gr_log_badprocpid("stat");
47594 + return 0;
47595 + }
47596 +#endif
47597 +
47598 state = *get_task_state(task);
47599 vsize = eip = esp = 0;
47600 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
47601 @@ -449,6 +487,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47602 gtime = task->gtime;
47603 }
47604
47605 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47606 + if (PAX_RAND_FLAGS(mm)) {
47607 + eip = 0;
47608 + esp = 0;
47609 + wchan = 0;
47610 + }
47611 +#endif
47612 +#ifdef CONFIG_GRKERNSEC_HIDESYM
47613 + wchan = 0;
47614 + eip =0;
47615 + esp =0;
47616 +#endif
47617 +
47618 /* scale priority and nice values from timeslices to -20..20 */
47619 /* to make it look like a "normal" Unix priority/nice value */
47620 priority = task_prio(task);
47621 @@ -485,9 +536,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47622 seq_put_decimal_ull(m, ' ', vsize);
47623 seq_put_decimal_ll(m, ' ', mm ? get_mm_rss(mm) : 0);
47624 seq_put_decimal_ull(m, ' ', rsslim);
47625 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47626 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
47627 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
47628 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
47629 +#else
47630 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
47631 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
47632 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
47633 +#endif
47634 seq_put_decimal_ull(m, ' ', esp);
47635 seq_put_decimal_ull(m, ' ', eip);
47636 /* The signal information here is obsolete.
47637 @@ -508,9 +565,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47638 seq_put_decimal_ull(m, ' ', delayacct_blkio_ticks(task));
47639 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
47640 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
47641 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47642 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((mm && permitted) ? mm->start_data : 0));
47643 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((mm && permitted) ? mm->end_data : 0));
47644 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((mm && permitted) ? mm->start_brk : 0));
47645 +#else
47646 seq_put_decimal_ull(m, ' ', (mm && permitted) ? mm->start_data : 0);
47647 seq_put_decimal_ull(m, ' ', (mm && permitted) ? mm->end_data : 0);
47648 seq_put_decimal_ull(m, ' ', (mm && permitted) ? mm->start_brk : 0);
47649 +#endif
47650 seq_putc(m, '\n');
47651 if (mm)
47652 mmput(mm);
47653 @@ -533,8 +596,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47654 struct pid *pid, struct task_struct *task)
47655 {
47656 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
47657 - struct mm_struct *mm = get_task_mm(task);
47658 + struct mm_struct *mm;
47659
47660 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47661 + if (current->exec_id != m->exec_id) {
47662 + gr_log_badprocpid("statm");
47663 + return 0;
47664 + }
47665 +#endif
47666 + mm = get_task_mm(task);
47667 if (mm) {
47668 size = task_statm(mm, &shared, &text, &data, &resident);
47669 mmput(mm);
47670 @@ -556,3 +626,18 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47671
47672 return 0;
47673 }
47674 +
47675 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
47676 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
47677 +{
47678 + u32 curr_ip = 0;
47679 + unsigned long flags;
47680 +
47681 + if (lock_task_sighand(task, &flags)) {
47682 + curr_ip = task->signal->curr_ip;
47683 + unlock_task_sighand(task, &flags);
47684 + }
47685 +
47686 + return sprintf(buffer, "%pI4\n", &curr_ip);
47687 +}
47688 +#endif
47689 diff --git a/fs/proc/base.c b/fs/proc/base.c
47690 index 9fc77b4..04761b8 100644
47691 --- a/fs/proc/base.c
47692 +++ b/fs/proc/base.c
47693 @@ -109,6 +109,14 @@ struct pid_entry {
47694 union proc_op op;
47695 };
47696
47697 +struct getdents_callback {
47698 + struct linux_dirent __user * current_dir;
47699 + struct linux_dirent __user * previous;
47700 + struct file * file;
47701 + int count;
47702 + int error;
47703 +};
47704 +
47705 #define NOD(NAME, MODE, IOP, FOP, OP) { \
47706 .name = (NAME), \
47707 .len = sizeof(NAME) - 1, \
47708 @@ -213,6 +221,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
47709 if (!mm->arg_end)
47710 goto out_mm; /* Shh! No looking before we're done */
47711
47712 + if (gr_acl_handle_procpidmem(task))
47713 + goto out_mm;
47714 +
47715 len = mm->arg_end - mm->arg_start;
47716
47717 if (len > PAGE_SIZE)
47718 @@ -240,12 +251,28 @@ out:
47719 return res;
47720 }
47721
47722 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47723 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
47724 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
47725 + _mm->pax_flags & MF_PAX_SEGMEXEC))
47726 +#endif
47727 +
47728 static int proc_pid_auxv(struct task_struct *task, char *buffer)
47729 {
47730 struct mm_struct *mm = mm_for_maps(task);
47731 int res = PTR_ERR(mm);
47732 if (mm && !IS_ERR(mm)) {
47733 unsigned int nwords = 0;
47734 +
47735 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47736 + /* allow if we're currently ptracing this task */
47737 + if (PAX_RAND_FLAGS(mm) &&
47738 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
47739 + mmput(mm);
47740 + return 0;
47741 + }
47742 +#endif
47743 +
47744 do {
47745 nwords += 2;
47746 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
47747 @@ -259,7 +286,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
47748 }
47749
47750
47751 -#ifdef CONFIG_KALLSYMS
47752 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47753 /*
47754 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
47755 * Returns the resolved symbol. If that fails, simply return the address.
47756 @@ -298,7 +325,7 @@ static void unlock_trace(struct task_struct *task)
47757 mutex_unlock(&task->signal->cred_guard_mutex);
47758 }
47759
47760 -#ifdef CONFIG_STACKTRACE
47761 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47762
47763 #define MAX_STACK_TRACE_DEPTH 64
47764
47765 @@ -489,7 +516,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
47766 return count;
47767 }
47768
47769 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
47770 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
47771 static int proc_pid_syscall(struct task_struct *task, char *buffer)
47772 {
47773 long nr;
47774 @@ -518,7 +545,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
47775 /************************************************************************/
47776
47777 /* permission checks */
47778 -static int proc_fd_access_allowed(struct inode *inode)
47779 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
47780 {
47781 struct task_struct *task;
47782 int allowed = 0;
47783 @@ -528,7 +555,10 @@ static int proc_fd_access_allowed(struct inode *inode)
47784 */
47785 task = get_proc_task(inode);
47786 if (task) {
47787 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
47788 + if (log)
47789 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
47790 + else
47791 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
47792 put_task_struct(task);
47793 }
47794 return allowed;
47795 @@ -566,10 +596,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
47796 struct task_struct *task,
47797 int hide_pid_min)
47798 {
47799 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47800 + return false;
47801 +
47802 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47803 + rcu_read_lock();
47804 + {
47805 + const struct cred *tmpcred = current_cred();
47806 + const struct cred *cred = __task_cred(task);
47807 +
47808 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
47809 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47810 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
47811 +#endif
47812 + ) {
47813 + rcu_read_unlock();
47814 + return true;
47815 + }
47816 + }
47817 + rcu_read_unlock();
47818 +
47819 + if (!pid->hide_pid)
47820 + return false;
47821 +#endif
47822 +
47823 if (pid->hide_pid < hide_pid_min)
47824 return true;
47825 if (in_group_p(pid->pid_gid))
47826 return true;
47827 +
47828 return ptrace_may_access(task, PTRACE_MODE_READ);
47829 }
47830
47831 @@ -587,7 +642,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
47832 put_task_struct(task);
47833
47834 if (!has_perms) {
47835 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47836 + {
47837 +#else
47838 if (pid->hide_pid == 2) {
47839 +#endif
47840 /*
47841 * Let's make getdents(), stat(), and open()
47842 * consistent with each other. If a process
47843 @@ -702,6 +761,10 @@ static int mem_open(struct inode* inode, struct file* file)
47844 file->f_mode |= FMODE_UNSIGNED_OFFSET;
47845 file->private_data = mm;
47846
47847 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47848 + file->f_version = current->exec_id;
47849 +#endif
47850 +
47851 return 0;
47852 }
47853
47854 @@ -713,6 +776,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
47855 ssize_t copied;
47856 char *page;
47857
47858 +#ifdef CONFIG_GRKERNSEC
47859 + if (write)
47860 + return -EPERM;
47861 +#endif
47862 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47863 + if (file->f_version != current->exec_id) {
47864 + gr_log_badprocpid("mem");
47865 + return 0;
47866 + }
47867 +#endif
47868 +
47869 if (!mm)
47870 return 0;
47871
47872 @@ -813,6 +887,9 @@ static ssize_t environ_read(struct file *file, char __user *buf,
47873 if (!task)
47874 goto out_no_task;
47875
47876 + if (gr_acl_handle_procpidmem(task))
47877 + goto out;
47878 +
47879 ret = -ENOMEM;
47880 page = (char *)__get_free_page(GFP_TEMPORARY);
47881 if (!page)
47882 @@ -1433,7 +1510,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
47883 path_put(&nd->path);
47884
47885 /* Are we allowed to snoop on the tasks file descriptors? */
47886 - if (!proc_fd_access_allowed(inode))
47887 + if (!proc_fd_access_allowed(inode, 0))
47888 goto out;
47889
47890 error = PROC_I(inode)->op.proc_get_link(dentry, &nd->path);
47891 @@ -1472,8 +1549,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
47892 struct path path;
47893
47894 /* Are we allowed to snoop on the tasks file descriptors? */
47895 - if (!proc_fd_access_allowed(inode))
47896 - goto out;
47897 + /* logging this is needed for learning on chromium to work properly,
47898 + but we don't want to flood the logs from 'ps' which does a readlink
47899 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
47900 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
47901 + */
47902 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
47903 + if (!proc_fd_access_allowed(inode,0))
47904 + goto out;
47905 + } else {
47906 + if (!proc_fd_access_allowed(inode,1))
47907 + goto out;
47908 + }
47909
47910 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
47911 if (error)
47912 @@ -1538,7 +1625,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
47913 rcu_read_lock();
47914 cred = __task_cred(task);
47915 inode->i_uid = cred->euid;
47916 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47917 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
47918 +#else
47919 inode->i_gid = cred->egid;
47920 +#endif
47921 rcu_read_unlock();
47922 }
47923 security_task_to_inode(task, inode);
47924 @@ -1574,10 +1665,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
47925 return -ENOENT;
47926 }
47927 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
47928 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47929 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
47930 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47931 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
47932 +#endif
47933 task_dumpable(task)) {
47934 cred = __task_cred(task);
47935 stat->uid = cred->euid;
47936 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47937 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
47938 +#else
47939 stat->gid = cred->egid;
47940 +#endif
47941 }
47942 }
47943 rcu_read_unlock();
47944 @@ -1615,11 +1715,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
47945
47946 if (task) {
47947 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
47948 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47949 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
47950 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47951 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
47952 +#endif
47953 task_dumpable(task)) {
47954 rcu_read_lock();
47955 cred = __task_cred(task);
47956 inode->i_uid = cred->euid;
47957 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
47958 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
47959 +#else
47960 inode->i_gid = cred->egid;
47961 +#endif
47962 rcu_read_unlock();
47963 } else {
47964 inode->i_uid = 0;
47965 @@ -1737,7 +1846,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
47966 int fd = proc_fd(inode);
47967
47968 if (task) {
47969 - files = get_files_struct(task);
47970 + if (!gr_acl_handle_procpidmem(task))
47971 + files = get_files_struct(task);
47972 put_task_struct(task);
47973 }
47974 if (files) {
47975 @@ -2338,11 +2448,21 @@ static const struct file_operations proc_map_files_operations = {
47976 */
47977 static int proc_fd_permission(struct inode *inode, int mask)
47978 {
47979 + struct task_struct *task;
47980 int rv = generic_permission(inode, mask);
47981 - if (rv == 0)
47982 - return 0;
47983 +
47984 if (task_pid(current) == proc_pid(inode))
47985 rv = 0;
47986 +
47987 + task = get_proc_task(inode);
47988 + if (task == NULL)
47989 + return rv;
47990 +
47991 + if (gr_acl_handle_procpidmem(task))
47992 + rv = -EACCES;
47993 +
47994 + put_task_struct(task);
47995 +
47996 return rv;
47997 }
47998
47999 @@ -2452,6 +2572,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
48000 if (!task)
48001 goto out_no_task;
48002
48003 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48004 + goto out;
48005 +
48006 /*
48007 * Yes, it does not scale. And it should not. Don't add
48008 * new entries into /proc/<tgid>/ without very good reasons.
48009 @@ -2496,6 +2619,9 @@ static int proc_pident_readdir(struct file *filp,
48010 if (!task)
48011 goto out_no_task;
48012
48013 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48014 + goto out;
48015 +
48016 ret = 0;
48017 i = filp->f_pos;
48018 switch (i) {
48019 @@ -2766,7 +2892,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
48020 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
48021 void *cookie)
48022 {
48023 - char *s = nd_get_link(nd);
48024 + const char *s = nd_get_link(nd);
48025 if (!IS_ERR(s))
48026 __putname(s);
48027 }
48028 @@ -2967,7 +3093,7 @@ static const struct pid_entry tgid_base_stuff[] = {
48029 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
48030 #endif
48031 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48032 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48033 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48034 INF("syscall", S_IRUGO, proc_pid_syscall),
48035 #endif
48036 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48037 @@ -2992,10 +3118,10 @@ static const struct pid_entry tgid_base_stuff[] = {
48038 #ifdef CONFIG_SECURITY
48039 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48040 #endif
48041 -#ifdef CONFIG_KALLSYMS
48042 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48043 INF("wchan", S_IRUGO, proc_pid_wchan),
48044 #endif
48045 -#ifdef CONFIG_STACKTRACE
48046 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48047 ONE("stack", S_IRUGO, proc_pid_stack),
48048 #endif
48049 #ifdef CONFIG_SCHEDSTATS
48050 @@ -3029,6 +3155,9 @@ static const struct pid_entry tgid_base_stuff[] = {
48051 #ifdef CONFIG_HARDWALL
48052 INF("hardwall", S_IRUGO, proc_pid_hardwall),
48053 #endif
48054 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48055 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
48056 +#endif
48057 };
48058
48059 static int proc_tgid_base_readdir(struct file * filp,
48060 @@ -3155,7 +3284,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
48061 if (!inode)
48062 goto out;
48063
48064 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48065 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
48066 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48067 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48068 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
48069 +#else
48070 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
48071 +#endif
48072 inode->i_op = &proc_tgid_base_inode_operations;
48073 inode->i_fop = &proc_tgid_base_operations;
48074 inode->i_flags|=S_IMMUTABLE;
48075 @@ -3197,7 +3333,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
48076 if (!task)
48077 goto out;
48078
48079 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48080 + goto out_put_task;
48081 +
48082 result = proc_pid_instantiate(dir, dentry, task, NULL);
48083 +out_put_task:
48084 put_task_struct(task);
48085 out:
48086 return result;
48087 @@ -3260,6 +3400,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
48088 static int fake_filldir(void *buf, const char *name, int namelen,
48089 loff_t offset, u64 ino, unsigned d_type)
48090 {
48091 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
48092 + __buf->error = -EINVAL;
48093 return 0;
48094 }
48095
48096 @@ -3326,7 +3468,7 @@ static const struct pid_entry tid_base_stuff[] = {
48097 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
48098 #endif
48099 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48100 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48101 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48102 INF("syscall", S_IRUGO, proc_pid_syscall),
48103 #endif
48104 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48105 @@ -3350,10 +3492,10 @@ static const struct pid_entry tid_base_stuff[] = {
48106 #ifdef CONFIG_SECURITY
48107 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48108 #endif
48109 -#ifdef CONFIG_KALLSYMS
48110 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48111 INF("wchan", S_IRUGO, proc_pid_wchan),
48112 #endif
48113 -#ifdef CONFIG_STACKTRACE
48114 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48115 ONE("stack", S_IRUGO, proc_pid_stack),
48116 #endif
48117 #ifdef CONFIG_SCHEDSTATS
48118 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
48119 index 82676e3..5f8518a 100644
48120 --- a/fs/proc/cmdline.c
48121 +++ b/fs/proc/cmdline.c
48122 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
48123
48124 static int __init proc_cmdline_init(void)
48125 {
48126 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48127 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
48128 +#else
48129 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
48130 +#endif
48131 return 0;
48132 }
48133 module_init(proc_cmdline_init);
48134 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
48135 index b143471..bb105e5 100644
48136 --- a/fs/proc/devices.c
48137 +++ b/fs/proc/devices.c
48138 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
48139
48140 static int __init proc_devices_init(void)
48141 {
48142 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48143 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
48144 +#else
48145 proc_create("devices", 0, NULL, &proc_devinfo_operations);
48146 +#endif
48147 return 0;
48148 }
48149 module_init(proc_devices_init);
48150 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
48151 index 205c922..2ee4c57 100644
48152 --- a/fs/proc/inode.c
48153 +++ b/fs/proc/inode.c
48154 @@ -21,11 +21,17 @@
48155 #include <linux/seq_file.h>
48156 #include <linux/slab.h>
48157 #include <linux/mount.h>
48158 +#include <linux/grsecurity.h>
48159
48160 #include <asm/uaccess.h>
48161
48162 #include "internal.h"
48163
48164 +#ifdef CONFIG_PROC_SYSCTL
48165 +extern const struct inode_operations proc_sys_inode_operations;
48166 +extern const struct inode_operations proc_sys_dir_operations;
48167 +#endif
48168 +
48169 static void proc_evict_inode(struct inode *inode)
48170 {
48171 struct proc_dir_entry *de;
48172 @@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
48173 ns_ops = PROC_I(inode)->ns_ops;
48174 if (ns_ops && ns_ops->put)
48175 ns_ops->put(PROC_I(inode)->ns);
48176 +
48177 +#ifdef CONFIG_PROC_SYSCTL
48178 + if (inode->i_op == &proc_sys_inode_operations ||
48179 + inode->i_op == &proc_sys_dir_operations)
48180 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
48181 +#endif
48182 +
48183 }
48184
48185 static struct kmem_cache * proc_inode_cachep;
48186 @@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
48187 if (de->mode) {
48188 inode->i_mode = de->mode;
48189 inode->i_uid = de->uid;
48190 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48191 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48192 +#else
48193 inode->i_gid = de->gid;
48194 +#endif
48195 }
48196 if (de->size)
48197 inode->i_size = de->size;
48198 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
48199 index 5f79bb8..eeccee4 100644
48200 --- a/fs/proc/internal.h
48201 +++ b/fs/proc/internal.h
48202 @@ -54,6 +54,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48203 struct pid *pid, struct task_struct *task);
48204 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48205 struct pid *pid, struct task_struct *task);
48206 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48207 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
48208 +#endif
48209 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
48210
48211 extern const struct file_operations proc_pid_maps_operations;
48212 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
48213 index 86c67ee..cdca321 100644
48214 --- a/fs/proc/kcore.c
48215 +++ b/fs/proc/kcore.c
48216 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48217 * the addresses in the elf_phdr on our list.
48218 */
48219 start = kc_offset_to_vaddr(*fpos - elf_buflen);
48220 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
48221 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
48222 + if (tsz > buflen)
48223 tsz = buflen;
48224 -
48225 +
48226 while (buflen) {
48227 struct kcore_list *m;
48228
48229 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48230 kfree(elf_buf);
48231 } else {
48232 if (kern_addr_valid(start)) {
48233 - unsigned long n;
48234 + char *elf_buf;
48235 + mm_segment_t oldfs;
48236
48237 - n = copy_to_user(buffer, (char *)start, tsz);
48238 - /*
48239 - * We cannot distinguish between fault on source
48240 - * and fault on destination. When this happens
48241 - * we clear too and hope it will trigger the
48242 - * EFAULT again.
48243 - */
48244 - if (n) {
48245 - if (clear_user(buffer + tsz - n,
48246 - n))
48247 + elf_buf = kmalloc(tsz, GFP_KERNEL);
48248 + if (!elf_buf)
48249 + return -ENOMEM;
48250 + oldfs = get_fs();
48251 + set_fs(KERNEL_DS);
48252 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
48253 + set_fs(oldfs);
48254 + if (copy_to_user(buffer, elf_buf, tsz)) {
48255 + kfree(elf_buf);
48256 return -EFAULT;
48257 + }
48258 }
48259 + set_fs(oldfs);
48260 + kfree(elf_buf);
48261 } else {
48262 if (clear_user(buffer, tsz))
48263 return -EFAULT;
48264 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48265
48266 static int open_kcore(struct inode *inode, struct file *filp)
48267 {
48268 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
48269 + return -EPERM;
48270 +#endif
48271 if (!capable(CAP_SYS_RAWIO))
48272 return -EPERM;
48273 if (kcore_need_update)
48274 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
48275 index 80e4645..53e5fcf 100644
48276 --- a/fs/proc/meminfo.c
48277 +++ b/fs/proc/meminfo.c
48278 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
48279 vmi.used >> 10,
48280 vmi.largest_chunk >> 10
48281 #ifdef CONFIG_MEMORY_FAILURE
48282 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
48283 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
48284 #endif
48285 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
48286 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
48287 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
48288 index b1822dd..df622cb 100644
48289 --- a/fs/proc/nommu.c
48290 +++ b/fs/proc/nommu.c
48291 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
48292 if (len < 1)
48293 len = 1;
48294 seq_printf(m, "%*c", len, ' ');
48295 - seq_path(m, &file->f_path, "");
48296 + seq_path(m, &file->f_path, "\n\\");
48297 }
48298
48299 seq_putc(m, '\n');
48300 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
48301 index 06e1cc1..177cd98 100644
48302 --- a/fs/proc/proc_net.c
48303 +++ b/fs/proc/proc_net.c
48304 @@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
48305 struct task_struct *task;
48306 struct nsproxy *ns;
48307 struct net *net = NULL;
48308 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48309 + const struct cred *cred = current_cred();
48310 +#endif
48311 +
48312 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48313 + if (cred->fsuid)
48314 + return net;
48315 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48316 + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
48317 + return net;
48318 +#endif
48319
48320 rcu_read_lock();
48321 task = pid_task(proc_pid(dir), PIDTYPE_PID);
48322 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
48323 index 21d836f..bebf3ee 100644
48324 --- a/fs/proc/proc_sysctl.c
48325 +++ b/fs/proc/proc_sysctl.c
48326 @@ -12,11 +12,15 @@
48327 #include <linux/module.h>
48328 #include "internal.h"
48329
48330 +extern int gr_handle_chroot_sysctl(const int op);
48331 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
48332 + const int op);
48333 +
48334 static const struct dentry_operations proc_sys_dentry_operations;
48335 static const struct file_operations proc_sys_file_operations;
48336 -static const struct inode_operations proc_sys_inode_operations;
48337 +const struct inode_operations proc_sys_inode_operations;
48338 static const struct file_operations proc_sys_dir_file_operations;
48339 -static const struct inode_operations proc_sys_dir_operations;
48340 +const struct inode_operations proc_sys_dir_operations;
48341
48342 void proc_sys_poll_notify(struct ctl_table_poll *poll)
48343 {
48344 @@ -470,8 +474,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
48345
48346 err = NULL;
48347 d_set_d_op(dentry, &proc_sys_dentry_operations);
48348 +
48349 + gr_handle_proc_create(dentry, inode);
48350 +
48351 d_add(dentry, inode);
48352
48353 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt))
48354 + err = ERR_PTR(-ENOENT);
48355 +
48356 out:
48357 sysctl_head_finish(head);
48358 return err;
48359 @@ -483,18 +493,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
48360 struct inode *inode = filp->f_path.dentry->d_inode;
48361 struct ctl_table_header *head = grab_header(inode);
48362 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
48363 + int op = write ? MAY_WRITE : MAY_READ;
48364 ssize_t error;
48365 size_t res;
48366
48367 if (IS_ERR(head))
48368 return PTR_ERR(head);
48369
48370 +
48371 /*
48372 * At this point we know that the sysctl was not unregistered
48373 * and won't be until we finish.
48374 */
48375 error = -EPERM;
48376 - if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
48377 + if (sysctl_perm(head->root, table, op))
48378 goto out;
48379
48380 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
48381 @@ -502,6 +514,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
48382 if (!table->proc_handler)
48383 goto out;
48384
48385 +#ifdef CONFIG_GRKERNSEC
48386 + error = -EPERM;
48387 + if (gr_handle_chroot_sysctl(op))
48388 + goto out;
48389 + dget(filp->f_path.dentry);
48390 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
48391 + dput(filp->f_path.dentry);
48392 + goto out;
48393 + }
48394 + dput(filp->f_path.dentry);
48395 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
48396 + goto out;
48397 + if (write && !capable(CAP_SYS_ADMIN))
48398 + goto out;
48399 +#endif
48400 +
48401 /* careful: calling conventions are nasty here */
48402 res = count;
48403 error = table->proc_handler(table, write, buf, &res, ppos);
48404 @@ -599,6 +627,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
48405 return -ENOMEM;
48406 } else {
48407 d_set_d_op(child, &proc_sys_dentry_operations);
48408 +
48409 + gr_handle_proc_create(child, inode);
48410 +
48411 d_add(child, inode);
48412 }
48413 } else {
48414 @@ -642,6 +673,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
48415 if ((*pos)++ < file->f_pos)
48416 return 0;
48417
48418 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
48419 + return 0;
48420 +
48421 if (unlikely(S_ISLNK(table->mode)))
48422 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
48423 else
48424 @@ -759,6 +793,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
48425 if (IS_ERR(head))
48426 return PTR_ERR(head);
48427
48428 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
48429 + return -ENOENT;
48430 +
48431 generic_fillattr(inode, stat);
48432 if (table)
48433 stat->mode = (stat->mode & S_IFMT) | table->mode;
48434 @@ -781,13 +818,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
48435 .llseek = generic_file_llseek,
48436 };
48437
48438 -static const struct inode_operations proc_sys_inode_operations = {
48439 +const struct inode_operations proc_sys_inode_operations = {
48440 .permission = proc_sys_permission,
48441 .setattr = proc_sys_setattr,
48442 .getattr = proc_sys_getattr,
48443 };
48444
48445 -static const struct inode_operations proc_sys_dir_operations = {
48446 +const struct inode_operations proc_sys_dir_operations = {
48447 .lookup = proc_sys_lookup,
48448 .permission = proc_sys_permission,
48449 .setattr = proc_sys_setattr,
48450 diff --git a/fs/proc/root.c b/fs/proc/root.c
48451 index eed44bf..abeb499 100644
48452 --- a/fs/proc/root.c
48453 +++ b/fs/proc/root.c
48454 @@ -188,7 +188,15 @@ void __init proc_root_init(void)
48455 #ifdef CONFIG_PROC_DEVICETREE
48456 proc_device_tree_init();
48457 #endif
48458 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48459 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48460 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
48461 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48462 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
48463 +#endif
48464 +#else
48465 proc_mkdir("bus", NULL);
48466 +#endif
48467 proc_sys_init();
48468 }
48469
48470 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
48471 index 7faaf2a..096c28b 100644
48472 --- a/fs/proc/task_mmu.c
48473 +++ b/fs/proc/task_mmu.c
48474 @@ -11,12 +11,19 @@
48475 #include <linux/rmap.h>
48476 #include <linux/swap.h>
48477 #include <linux/swapops.h>
48478 +#include <linux/grsecurity.h>
48479
48480 #include <asm/elf.h>
48481 #include <asm/uaccess.h>
48482 #include <asm/tlbflush.h>
48483 #include "internal.h"
48484
48485 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48486 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48487 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48488 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48489 +#endif
48490 +
48491 void task_mem(struct seq_file *m, struct mm_struct *mm)
48492 {
48493 unsigned long data, text, lib, swap;
48494 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48495 "VmExe:\t%8lu kB\n"
48496 "VmLib:\t%8lu kB\n"
48497 "VmPTE:\t%8lu kB\n"
48498 - "VmSwap:\t%8lu kB\n",
48499 - hiwater_vm << (PAGE_SHIFT-10),
48500 + "VmSwap:\t%8lu kB\n"
48501 +
48502 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48503 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
48504 +#endif
48505 +
48506 + ,hiwater_vm << (PAGE_SHIFT-10),
48507 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
48508 mm->locked_vm << (PAGE_SHIFT-10),
48509 mm->pinned_vm << (PAGE_SHIFT-10),
48510 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48511 data << (PAGE_SHIFT-10),
48512 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
48513 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
48514 - swap << (PAGE_SHIFT-10));
48515 + swap << (PAGE_SHIFT-10)
48516 +
48517 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48518 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48519 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
48520 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
48521 +#else
48522 + , mm->context.user_cs_base
48523 + , mm->context.user_cs_limit
48524 +#endif
48525 +#endif
48526 +
48527 + );
48528 }
48529
48530 unsigned long task_vsize(struct mm_struct *mm)
48531 @@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
48532 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
48533 }
48534
48535 - /* We don't show the stack guard page in /proc/maps */
48536 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48537 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
48538 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
48539 +#else
48540 start = vma->vm_start;
48541 - if (stack_guard_page_start(vma, start))
48542 - start += PAGE_SIZE;
48543 end = vma->vm_end;
48544 - if (stack_guard_page_end(vma, end))
48545 - end -= PAGE_SIZE;
48546 +#endif
48547
48548 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
48549 start,
48550 @@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
48551 flags & VM_WRITE ? 'w' : '-',
48552 flags & VM_EXEC ? 'x' : '-',
48553 flags & VM_MAYSHARE ? 's' : 'p',
48554 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48555 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
48556 +#else
48557 pgoff,
48558 +#endif
48559 MAJOR(dev), MINOR(dev), ino, &len);
48560
48561 /*
48562 @@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
48563 */
48564 if (file) {
48565 pad_len_spaces(m, len);
48566 - seq_path(m, &file->f_path, "\n");
48567 + seq_path(m, &file->f_path, "\n\\");
48568 goto done;
48569 }
48570
48571 @@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
48572 * Thread stack in /proc/PID/task/TID/maps or
48573 * the main process stack.
48574 */
48575 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
48576 - vma->vm_end >= mm->start_stack)) {
48577 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
48578 + (vma->vm_start <= mm->start_stack &&
48579 + vma->vm_end >= mm->start_stack)) {
48580 name = "[stack]";
48581 } else {
48582 /* Thread stack in /proc/PID/maps */
48583 @@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
48584 struct proc_maps_private *priv = m->private;
48585 struct task_struct *task = priv->task;
48586
48587 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48588 + if (current->exec_id != m->exec_id) {
48589 + gr_log_badprocpid("maps");
48590 + return 0;
48591 + }
48592 +#endif
48593 +
48594 show_map_vma(m, vma, is_pid);
48595
48596 if (m->count < m->size) /* vma is copied successfully */
48597 @@ -482,12 +518,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
48598 .private = &mss,
48599 };
48600
48601 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48602 + if (current->exec_id != m->exec_id) {
48603 + gr_log_badprocpid("smaps");
48604 + return 0;
48605 + }
48606 +#endif
48607 memset(&mss, 0, sizeof mss);
48608 - mss.vma = vma;
48609 - /* mmap_sem is held in m_start */
48610 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
48611 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
48612 -
48613 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48614 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
48615 +#endif
48616 + mss.vma = vma;
48617 + /* mmap_sem is held in m_start */
48618 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
48619 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
48620 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48621 + }
48622 +#endif
48623 show_map_vma(m, vma, is_pid);
48624
48625 seq_printf(m,
48626 @@ -505,7 +552,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
48627 "KernelPageSize: %8lu kB\n"
48628 "MMUPageSize: %8lu kB\n"
48629 "Locked: %8lu kB\n",
48630 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48631 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
48632 +#else
48633 (vma->vm_end - vma->vm_start) >> 10,
48634 +#endif
48635 mss.resident >> 10,
48636 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
48637 mss.shared_clean >> 10,
48638 @@ -1138,6 +1189,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
48639 int n;
48640 char buffer[50];
48641
48642 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48643 + if (current->exec_id != m->exec_id) {
48644 + gr_log_badprocpid("numa_maps");
48645 + return 0;
48646 + }
48647 +#endif
48648 +
48649 if (!mm)
48650 return 0;
48651
48652 @@ -1155,11 +1213,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
48653 mpol_to_str(buffer, sizeof(buffer), pol, 0);
48654 mpol_cond_put(pol);
48655
48656 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48657 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
48658 +#else
48659 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
48660 +#endif
48661
48662 if (file) {
48663 seq_printf(m, " file=");
48664 - seq_path(m, &file->f_path, "\n\t= ");
48665 + seq_path(m, &file->f_path, "\n\t\\= ");
48666 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
48667 seq_printf(m, " heap");
48668 } else {
48669 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
48670 index 74fe164..899e77b 100644
48671 --- a/fs/proc/task_nommu.c
48672 +++ b/fs/proc/task_nommu.c
48673 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48674 else
48675 bytes += kobjsize(mm);
48676
48677 - if (current->fs && current->fs->users > 1)
48678 + if (current->fs && atomic_read(&current->fs->users) > 1)
48679 sbytes += kobjsize(current->fs);
48680 else
48681 bytes += kobjsize(current->fs);
48682 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
48683
48684 if (file) {
48685 pad_len_spaces(m, len);
48686 - seq_path(m, &file->f_path, "");
48687 + seq_path(m, &file->f_path, "\n\\");
48688 } else if (mm) {
48689 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
48690
48691 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
48692 index d67908b..d13f6a6 100644
48693 --- a/fs/quota/netlink.c
48694 +++ b/fs/quota/netlink.c
48695 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
48696 void quota_send_warning(short type, unsigned int id, dev_t dev,
48697 const char warntype)
48698 {
48699 - static atomic_t seq;
48700 + static atomic_unchecked_t seq;
48701 struct sk_buff *skb;
48702 void *msg_head;
48703 int ret;
48704 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
48705 "VFS: Not enough memory to send quota warning.\n");
48706 return;
48707 }
48708 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
48709 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
48710 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
48711 if (!msg_head) {
48712 printk(KERN_ERR
48713 diff --git a/fs/readdir.c b/fs/readdir.c
48714 index cc0a822..43cb195 100644
48715 --- a/fs/readdir.c
48716 +++ b/fs/readdir.c
48717 @@ -17,6 +17,7 @@
48718 #include <linux/security.h>
48719 #include <linux/syscalls.h>
48720 #include <linux/unistd.h>
48721 +#include <linux/namei.h>
48722
48723 #include <asm/uaccess.h>
48724
48725 @@ -67,6 +68,7 @@ struct old_linux_dirent {
48726
48727 struct readdir_callback {
48728 struct old_linux_dirent __user * dirent;
48729 + struct file * file;
48730 int result;
48731 };
48732
48733 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
48734 buf->result = -EOVERFLOW;
48735 return -EOVERFLOW;
48736 }
48737 +
48738 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48739 + return 0;
48740 +
48741 buf->result++;
48742 dirent = buf->dirent;
48743 if (!access_ok(VERIFY_WRITE, dirent,
48744 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
48745
48746 buf.result = 0;
48747 buf.dirent = dirent;
48748 + buf.file = file;
48749
48750 error = vfs_readdir(file, fillonedir, &buf);
48751 if (buf.result)
48752 @@ -142,6 +149,7 @@ struct linux_dirent {
48753 struct getdents_callback {
48754 struct linux_dirent __user * current_dir;
48755 struct linux_dirent __user * previous;
48756 + struct file * file;
48757 int count;
48758 int error;
48759 };
48760 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
48761 buf->error = -EOVERFLOW;
48762 return -EOVERFLOW;
48763 }
48764 +
48765 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48766 + return 0;
48767 +
48768 dirent = buf->previous;
48769 if (dirent) {
48770 if (__put_user(offset, &dirent->d_off))
48771 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
48772 buf.previous = NULL;
48773 buf.count = count;
48774 buf.error = 0;
48775 + buf.file = file;
48776
48777 error = vfs_readdir(file, filldir, &buf);
48778 if (error >= 0)
48779 @@ -229,6 +242,7 @@ out:
48780 struct getdents_callback64 {
48781 struct linux_dirent64 __user * current_dir;
48782 struct linux_dirent64 __user * previous;
48783 + struct file *file;
48784 int count;
48785 int error;
48786 };
48787 @@ -244,6 +258,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
48788 buf->error = -EINVAL; /* only used if we fail.. */
48789 if (reclen > buf->count)
48790 return -EINVAL;
48791 +
48792 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48793 + return 0;
48794 +
48795 dirent = buf->previous;
48796 if (dirent) {
48797 if (__put_user(offset, &dirent->d_off))
48798 @@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
48799
48800 buf.current_dir = dirent;
48801 buf.previous = NULL;
48802 + buf.file = file;
48803 buf.count = count;
48804 buf.error = 0;
48805
48806 @@ -299,7 +318,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
48807 error = buf.error;
48808 lastdirent = buf.previous;
48809 if (lastdirent) {
48810 - typeof(lastdirent->d_off) d_off = file->f_pos;
48811 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
48812 if (__put_user(d_off, &lastdirent->d_off))
48813 error = -EFAULT;
48814 else
48815 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
48816 index 2b7882b..1c5ef48 100644
48817 --- a/fs/reiserfs/do_balan.c
48818 +++ b/fs/reiserfs/do_balan.c
48819 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
48820 return;
48821 }
48822
48823 - atomic_inc(&(fs_generation(tb->tb_sb)));
48824 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
48825 do_balance_starts(tb);
48826
48827 /* balance leaf returns 0 except if combining L R and S into
48828 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
48829 index 2c1ade6..8c59d8d 100644
48830 --- a/fs/reiserfs/procfs.c
48831 +++ b/fs/reiserfs/procfs.c
48832 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
48833 "SMALL_TAILS " : "NO_TAILS ",
48834 replay_only(sb) ? "REPLAY_ONLY " : "",
48835 convert_reiserfs(sb) ? "CONV " : "",
48836 - atomic_read(&r->s_generation_counter),
48837 + atomic_read_unchecked(&r->s_generation_counter),
48838 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
48839 SF(s_do_balance), SF(s_unneeded_left_neighbor),
48840 SF(s_good_search_by_key_reada), SF(s_bmaps),
48841 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
48842 index a59d271..e12d1cf 100644
48843 --- a/fs/reiserfs/reiserfs.h
48844 +++ b/fs/reiserfs/reiserfs.h
48845 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
48846 /* Comment? -Hans */
48847 wait_queue_head_t s_wait;
48848 /* To be obsoleted soon by per buffer seals.. -Hans */
48849 - atomic_t s_generation_counter; // increased by one every time the
48850 + atomic_unchecked_t s_generation_counter; // increased by one every time the
48851 // tree gets re-balanced
48852 unsigned long s_properties; /* File system properties. Currently holds
48853 on-disk FS format */
48854 @@ -1973,7 +1973,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
48855 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
48856
48857 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
48858 -#define get_generation(s) atomic_read (&fs_generation(s))
48859 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
48860 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
48861 #define __fs_changed(gen,s) (gen != get_generation (s))
48862 #define fs_changed(gen,s) \
48863 diff --git a/fs/select.c b/fs/select.c
48864 index 17d33d0..da0bf5c 100644
48865 --- a/fs/select.c
48866 +++ b/fs/select.c
48867 @@ -20,6 +20,7 @@
48868 #include <linux/export.h>
48869 #include <linux/slab.h>
48870 #include <linux/poll.h>
48871 +#include <linux/security.h>
48872 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
48873 #include <linux/file.h>
48874 #include <linux/fdtable.h>
48875 @@ -833,6 +834,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
48876 struct poll_list *walk = head;
48877 unsigned long todo = nfds;
48878
48879 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
48880 if (nfds > rlimit(RLIMIT_NOFILE))
48881 return -EINVAL;
48882
48883 diff --git a/fs/seq_file.c b/fs/seq_file.c
48884 index 0cbd049..cab1127 100644
48885 --- a/fs/seq_file.c
48886 +++ b/fs/seq_file.c
48887 @@ -9,6 +9,7 @@
48888 #include <linux/export.h>
48889 #include <linux/seq_file.h>
48890 #include <linux/slab.h>
48891 +#include <linux/sched.h>
48892
48893 #include <asm/uaccess.h>
48894 #include <asm/page.h>
48895 @@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
48896 memset(p, 0, sizeof(*p));
48897 mutex_init(&p->lock);
48898 p->op = op;
48899 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48900 + p->exec_id = current->exec_id;
48901 +#endif
48902
48903 /*
48904 * Wrappers around seq_open(e.g. swaps_open) need to be
48905 @@ -567,7 +571,7 @@ static void single_stop(struct seq_file *p, void *v)
48906 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
48907 void *data)
48908 {
48909 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
48910 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
48911 int res = -ENOMEM;
48912
48913 if (op) {
48914 diff --git a/fs/splice.c b/fs/splice.c
48915 index 5cac690..f833a99 100644
48916 --- a/fs/splice.c
48917 +++ b/fs/splice.c
48918 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
48919 pipe_lock(pipe);
48920
48921 for (;;) {
48922 - if (!pipe->readers) {
48923 + if (!atomic_read(&pipe->readers)) {
48924 send_sig(SIGPIPE, current, 0);
48925 if (!ret)
48926 ret = -EPIPE;
48927 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
48928 do_wakeup = 0;
48929 }
48930
48931 - pipe->waiting_writers++;
48932 + atomic_inc(&pipe->waiting_writers);
48933 pipe_wait(pipe);
48934 - pipe->waiting_writers--;
48935 + atomic_dec(&pipe->waiting_writers);
48936 }
48937
48938 pipe_unlock(pipe);
48939 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
48940 old_fs = get_fs();
48941 set_fs(get_ds());
48942 /* The cast to a user pointer is valid due to the set_fs() */
48943 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
48944 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
48945 set_fs(old_fs);
48946
48947 return res;
48948 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
48949 old_fs = get_fs();
48950 set_fs(get_ds());
48951 /* The cast to a user pointer is valid due to the set_fs() */
48952 - res = vfs_write(file, (const char __user *)buf, count, &pos);
48953 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
48954 set_fs(old_fs);
48955
48956 return res;
48957 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
48958 goto err;
48959
48960 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
48961 - vec[i].iov_base = (void __user *) page_address(page);
48962 + vec[i].iov_base = (void __force_user *) page_address(page);
48963 vec[i].iov_len = this_len;
48964 spd.pages[i] = page;
48965 spd.nr_pages++;
48966 @@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
48967 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
48968 {
48969 while (!pipe->nrbufs) {
48970 - if (!pipe->writers)
48971 + if (!atomic_read(&pipe->writers))
48972 return 0;
48973
48974 - if (!pipe->waiting_writers && sd->num_spliced)
48975 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
48976 return 0;
48977
48978 if (sd->flags & SPLICE_F_NONBLOCK)
48979 @@ -1185,7 +1185,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
48980 * out of the pipe right after the splice_to_pipe(). So set
48981 * PIPE_READERS appropriately.
48982 */
48983 - pipe->readers = 1;
48984 + atomic_set(&pipe->readers, 1);
48985
48986 current->splice_pipe = pipe;
48987 }
48988 @@ -1738,9 +1738,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
48989 ret = -ERESTARTSYS;
48990 break;
48991 }
48992 - if (!pipe->writers)
48993 + if (!atomic_read(&pipe->writers))
48994 break;
48995 - if (!pipe->waiting_writers) {
48996 + if (!atomic_read(&pipe->waiting_writers)) {
48997 if (flags & SPLICE_F_NONBLOCK) {
48998 ret = -EAGAIN;
48999 break;
49000 @@ -1772,7 +1772,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49001 pipe_lock(pipe);
49002
49003 while (pipe->nrbufs >= pipe->buffers) {
49004 - if (!pipe->readers) {
49005 + if (!atomic_read(&pipe->readers)) {
49006 send_sig(SIGPIPE, current, 0);
49007 ret = -EPIPE;
49008 break;
49009 @@ -1785,9 +1785,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49010 ret = -ERESTARTSYS;
49011 break;
49012 }
49013 - pipe->waiting_writers++;
49014 + atomic_inc(&pipe->waiting_writers);
49015 pipe_wait(pipe);
49016 - pipe->waiting_writers--;
49017 + atomic_dec(&pipe->waiting_writers);
49018 }
49019
49020 pipe_unlock(pipe);
49021 @@ -1823,14 +1823,14 @@ retry:
49022 pipe_double_lock(ipipe, opipe);
49023
49024 do {
49025 - if (!opipe->readers) {
49026 + if (!atomic_read(&opipe->readers)) {
49027 send_sig(SIGPIPE, current, 0);
49028 if (!ret)
49029 ret = -EPIPE;
49030 break;
49031 }
49032
49033 - if (!ipipe->nrbufs && !ipipe->writers)
49034 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
49035 break;
49036
49037 /*
49038 @@ -1927,7 +1927,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49039 pipe_double_lock(ipipe, opipe);
49040
49041 do {
49042 - if (!opipe->readers) {
49043 + if (!atomic_read(&opipe->readers)) {
49044 send_sig(SIGPIPE, current, 0);
49045 if (!ret)
49046 ret = -EPIPE;
49047 @@ -1972,7 +1972,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49048 * return EAGAIN if we have the potential of some data in the
49049 * future, otherwise just return 0
49050 */
49051 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
49052 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
49053 ret = -EAGAIN;
49054
49055 pipe_unlock(ipipe);
49056 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
49057 index 35a36d3..23424b2 100644
49058 --- a/fs/sysfs/dir.c
49059 +++ b/fs/sysfs/dir.c
49060 @@ -657,6 +657,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
49061 struct sysfs_dirent *sd;
49062 int rc;
49063
49064 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
49065 + const char *parent_name = parent_sd->s_name;
49066 +
49067 + mode = S_IFDIR | S_IRWXU;
49068 +
49069 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
49070 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
49071 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
49072 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
49073 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
49074 +#endif
49075 +
49076 /* allocate */
49077 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
49078 if (!sd)
49079 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
49080 index 00012e3..8392349 100644
49081 --- a/fs/sysfs/file.c
49082 +++ b/fs/sysfs/file.c
49083 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
49084
49085 struct sysfs_open_dirent {
49086 atomic_t refcnt;
49087 - atomic_t event;
49088 + atomic_unchecked_t event;
49089 wait_queue_head_t poll;
49090 struct list_head buffers; /* goes through sysfs_buffer.list */
49091 };
49092 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
49093 if (!sysfs_get_active(attr_sd))
49094 return -ENODEV;
49095
49096 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
49097 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
49098 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
49099
49100 sysfs_put_active(attr_sd);
49101 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
49102 return -ENOMEM;
49103
49104 atomic_set(&new_od->refcnt, 0);
49105 - atomic_set(&new_od->event, 1);
49106 + atomic_set_unchecked(&new_od->event, 1);
49107 init_waitqueue_head(&new_od->poll);
49108 INIT_LIST_HEAD(&new_od->buffers);
49109 goto retry;
49110 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
49111
49112 sysfs_put_active(attr_sd);
49113
49114 - if (buffer->event != atomic_read(&od->event))
49115 + if (buffer->event != atomic_read_unchecked(&od->event))
49116 goto trigger;
49117
49118 return DEFAULT_POLLMASK;
49119 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
49120
49121 od = sd->s_attr.open;
49122 if (od) {
49123 - atomic_inc(&od->event);
49124 + atomic_inc_unchecked(&od->event);
49125 wake_up_interruptible(&od->poll);
49126 }
49127
49128 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
49129 index a7ac78f..02158e1 100644
49130 --- a/fs/sysfs/symlink.c
49131 +++ b/fs/sysfs/symlink.c
49132 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
49133
49134 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
49135 {
49136 - char *page = nd_get_link(nd);
49137 + const char *page = nd_get_link(nd);
49138 if (!IS_ERR(page))
49139 free_page((unsigned long)page);
49140 }
49141 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
49142 index c175b4d..8f36a16 100644
49143 --- a/fs/udf/misc.c
49144 +++ b/fs/udf/misc.c
49145 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
49146
49147 u8 udf_tag_checksum(const struct tag *t)
49148 {
49149 - u8 *data = (u8 *)t;
49150 + const u8 *data = (const u8 *)t;
49151 u8 checksum = 0;
49152 int i;
49153 for (i = 0; i < sizeof(struct tag); ++i)
49154 diff --git a/fs/utimes.c b/fs/utimes.c
49155 index ba653f3..06ea4b1 100644
49156 --- a/fs/utimes.c
49157 +++ b/fs/utimes.c
49158 @@ -1,6 +1,7 @@
49159 #include <linux/compiler.h>
49160 #include <linux/file.h>
49161 #include <linux/fs.h>
49162 +#include <linux/security.h>
49163 #include <linux/linkage.h>
49164 #include <linux/mount.h>
49165 #include <linux/namei.h>
49166 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
49167 goto mnt_drop_write_and_out;
49168 }
49169 }
49170 +
49171 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
49172 + error = -EACCES;
49173 + goto mnt_drop_write_and_out;
49174 + }
49175 +
49176 mutex_lock(&inode->i_mutex);
49177 error = notify_change(path->dentry, &newattrs);
49178 mutex_unlock(&inode->i_mutex);
49179 diff --git a/fs/xattr.c b/fs/xattr.c
49180 index 3c8c1cc..a83c398 100644
49181 --- a/fs/xattr.c
49182 +++ b/fs/xattr.c
49183 @@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
49184 * Extended attribute SET operations
49185 */
49186 static long
49187 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
49188 +setxattr(struct path *path, const char __user *name, const void __user *value,
49189 size_t size, int flags)
49190 {
49191 int error;
49192 @@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
49193 }
49194 }
49195
49196 - error = vfs_setxattr(d, kname, kvalue, size, flags);
49197 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
49198 + error = -EACCES;
49199 + goto out;
49200 + }
49201 +
49202 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
49203 out:
49204 if (vvalue)
49205 vfree(vvalue);
49206 @@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
49207 return error;
49208 error = mnt_want_write(path.mnt);
49209 if (!error) {
49210 - error = setxattr(path.dentry, name, value, size, flags);
49211 + error = setxattr(&path, name, value, size, flags);
49212 mnt_drop_write(path.mnt);
49213 }
49214 path_put(&path);
49215 @@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
49216 return error;
49217 error = mnt_want_write(path.mnt);
49218 if (!error) {
49219 - error = setxattr(path.dentry, name, value, size, flags);
49220 + error = setxattr(&path, name, value, size, flags);
49221 mnt_drop_write(path.mnt);
49222 }
49223 path_put(&path);
49224 @@ -400,17 +405,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
49225 const void __user *,value, size_t, size, int, flags)
49226 {
49227 struct file *f;
49228 - struct dentry *dentry;
49229 int error = -EBADF;
49230
49231 f = fget(fd);
49232 if (!f)
49233 return error;
49234 - dentry = f->f_path.dentry;
49235 - audit_inode(NULL, dentry);
49236 + audit_inode(NULL, f->f_path.dentry);
49237 error = mnt_want_write_file(f);
49238 if (!error) {
49239 - error = setxattr(dentry, name, value, size, flags);
49240 + error = setxattr(&f->f_path, name, value, size, flags);
49241 mnt_drop_write_file(f);
49242 }
49243 fput(f);
49244 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
49245 index 69d06b0..c0996e5 100644
49246 --- a/fs/xattr_acl.c
49247 +++ b/fs/xattr_acl.c
49248 @@ -17,8 +17,8 @@
49249 struct posix_acl *
49250 posix_acl_from_xattr(const void *value, size_t size)
49251 {
49252 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
49253 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
49254 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
49255 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
49256 int count;
49257 struct posix_acl *acl;
49258 struct posix_acl_entry *acl_e;
49259 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
49260 index 85e7e32..5344e52 100644
49261 --- a/fs/xfs/xfs_bmap.c
49262 +++ b/fs/xfs/xfs_bmap.c
49263 @@ -190,7 +190,7 @@ xfs_bmap_validate_ret(
49264 int nmap,
49265 int ret_nmap);
49266 #else
49267 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
49268 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
49269 #endif /* DEBUG */
49270
49271 STATIC int
49272 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
49273 index 79d05e8..e3e5861 100644
49274 --- a/fs/xfs/xfs_dir2_sf.c
49275 +++ b/fs/xfs/xfs_dir2_sf.c
49276 @@ -852,7 +852,15 @@ xfs_dir2_sf_getdents(
49277 }
49278
49279 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
49280 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49281 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
49282 + char name[sfep->namelen];
49283 + memcpy(name, sfep->name, sfep->namelen);
49284 + if (filldir(dirent, name, sfep->namelen,
49285 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
49286 + *offset = off & 0x7fffffff;
49287 + return 0;
49288 + }
49289 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49290 off & 0x7fffffff, ino, DT_UNKNOWN)) {
49291 *offset = off & 0x7fffffff;
49292 return 0;
49293 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
49294 index 91f8ff5..0ce68f9 100644
49295 --- a/fs/xfs/xfs_ioctl.c
49296 +++ b/fs/xfs/xfs_ioctl.c
49297 @@ -128,7 +128,7 @@ xfs_find_handle(
49298 }
49299
49300 error = -EFAULT;
49301 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
49302 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
49303 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
49304 goto out_put;
49305
49306 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
49307 index 3011b87..1ab03e9 100644
49308 --- a/fs/xfs/xfs_iops.c
49309 +++ b/fs/xfs/xfs_iops.c
49310 @@ -397,7 +397,7 @@ xfs_vn_put_link(
49311 struct nameidata *nd,
49312 void *p)
49313 {
49314 - char *s = nd_get_link(nd);
49315 + const char *s = nd_get_link(nd);
49316
49317 if (!IS_ERR(s))
49318 kfree(s);
49319 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
49320 new file mode 100644
49321 index 0000000..b9e7d6f
49322 --- /dev/null
49323 +++ b/grsecurity/Kconfig
49324 @@ -0,0 +1,940 @@
49325 +#
49326 +# grecurity configuration
49327 +#
49328 +menu "Memory Protections"
49329 +depends on GRKERNSEC
49330 +
49331 +config GRKERNSEC_KMEM
49332 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
49333 + default y if GRKERNSEC_CONFIG_AUTO
49334 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
49335 + help
49336 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
49337 + be written to or read from to modify or leak the contents of the running
49338 + kernel. /dev/port will also not be allowed to be opened. If you have module
49339 + support disabled, enabling this will close up four ways that are
49340 + currently used to insert malicious code into the running kernel.
49341 + Even with all these features enabled, we still highly recommend that
49342 + you use the RBAC system, as it is still possible for an attacker to
49343 + modify the running kernel through privileged I/O granted by ioperm/iopl.
49344 + If you are not using XFree86, you may be able to stop this additional
49345 + case by enabling the 'Disable privileged I/O' option. Though nothing
49346 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
49347 + but only to video memory, which is the only writing we allow in this
49348 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
49349 + not be allowed to mprotect it with PROT_WRITE later.
49350 + It is highly recommended that you say Y here if you meet all the
49351 + conditions above.
49352 +
49353 +config GRKERNSEC_VM86
49354 + bool "Restrict VM86 mode"
49355 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
49356 + depends on X86_32
49357 +
49358 + help
49359 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
49360 + make use of a special execution mode on 32bit x86 processors called
49361 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
49362 + video cards and will still work with this option enabled. The purpose
49363 + of the option is to prevent exploitation of emulation errors in
49364 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
49365 + Nearly all users should be able to enable this option.
49366 +
49367 +config GRKERNSEC_IO
49368 + bool "Disable privileged I/O"
49369 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
49370 + depends on X86
49371 + select RTC_CLASS
49372 + select RTC_INTF_DEV
49373 + select RTC_DRV_CMOS
49374 +
49375 + help
49376 + If you say Y here, all ioperm and iopl calls will return an error.
49377 + Ioperm and iopl can be used to modify the running kernel.
49378 + Unfortunately, some programs need this access to operate properly,
49379 + the most notable of which are XFree86 and hwclock. hwclock can be
49380 + remedied by having RTC support in the kernel, so real-time
49381 + clock support is enabled if this option is enabled, to ensure
49382 + that hwclock operates correctly. XFree86 still will not
49383 + operate correctly with this option enabled, so DO NOT CHOOSE Y
49384 + IF YOU USE XFree86. If you use XFree86 and you still want to
49385 + protect your kernel against modification, use the RBAC system.
49386 +
49387 +config GRKERNSEC_PROC_MEMMAP
49388 + bool "Harden ASLR against information leaks and entropy reduction"
49389 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
49390 + depends on PAX_NOEXEC || PAX_ASLR
49391 + help
49392 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
49393 + give no information about the addresses of its mappings if
49394 + PaX features that rely on random addresses are enabled on the task.
49395 + In addition to sanitizing this information and disabling other
49396 + dangerous sources of information, this option causes reads of sensitive
49397 + /proc/<pid> entries where the file descriptor was opened in a different
49398 + task than the one performing the read. Such attempts are logged.
49399 + This option also limits argv/env strings for suid/sgid binaries
49400 + to 512KB to prevent a complete exhaustion of the stack entropy provided
49401 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
49402 + binaries to prevent alternative mmap layouts from being abused.
49403 +
49404 + If you use PaX it is essential that you say Y here as it closes up
49405 + several holes that make full ASLR useless locally.
49406 +
49407 +config GRKERNSEC_BRUTE
49408 + bool "Deter exploit bruteforcing"
49409 + default y if GRKERNSEC_CONFIG_AUTO
49410 + help
49411 + If you say Y here, attempts to bruteforce exploits against forking
49412 + daemons such as apache or sshd, as well as against suid/sgid binaries
49413 + will be deterred. When a child of a forking daemon is killed by PaX
49414 + or crashes due to an illegal instruction or other suspicious signal,
49415 + the parent process will be delayed 30 seconds upon every subsequent
49416 + fork until the administrator is able to assess the situation and
49417 + restart the daemon.
49418 + In the suid/sgid case, the attempt is logged, the user has all their
49419 + processes terminated, and they are prevented from executing any further
49420 + processes for 15 minutes.
49421 + It is recommended that you also enable signal logging in the auditing
49422 + section so that logs are generated when a process triggers a suspicious
49423 + signal.
49424 + If the sysctl option is enabled, a sysctl option with name
49425 + "deter_bruteforce" is created.
49426 +
49427 +
49428 +config GRKERNSEC_MODHARDEN
49429 + bool "Harden module auto-loading"
49430 + default y if GRKERNSEC_CONFIG_AUTO
49431 + depends on MODULES
49432 + help
49433 + If you say Y here, module auto-loading in response to use of some
49434 + feature implemented by an unloaded module will be restricted to
49435 + root users. Enabling this option helps defend against attacks
49436 + by unprivileged users who abuse the auto-loading behavior to
49437 + cause a vulnerable module to load that is then exploited.
49438 +
49439 + If this option prevents a legitimate use of auto-loading for a
49440 + non-root user, the administrator can execute modprobe manually
49441 + with the exact name of the module mentioned in the alert log.
49442 + Alternatively, the administrator can add the module to the list
49443 + of modules loaded at boot by modifying init scripts.
49444 +
49445 + Modification of init scripts will most likely be needed on
49446 + Ubuntu servers with encrypted home directory support enabled,
49447 + as the first non-root user logging in will cause the ecb(aes),
49448 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
49449 +
49450 +config GRKERNSEC_HIDESYM
49451 + bool "Hide kernel symbols"
49452 + default y if GRKERNSEC_CONFIG_AUTO
49453 + help
49454 + If you say Y here, getting information on loaded modules, and
49455 + displaying all kernel symbols through a syscall will be restricted
49456 + to users with CAP_SYS_MODULE. For software compatibility reasons,
49457 + /proc/kallsyms will be restricted to the root user. The RBAC
49458 + system can hide that entry even from root.
49459 +
49460 + This option also prevents leaking of kernel addresses through
49461 + several /proc entries.
49462 +
49463 + Note that this option is only effective provided the following
49464 + conditions are met:
49465 + 1) The kernel using grsecurity is not precompiled by some distribution
49466 + 2) You have also enabled GRKERNSEC_DMESG
49467 + 3) You are using the RBAC system and hiding other files such as your
49468 + kernel image and System.map. Alternatively, enabling this option
49469 + causes the permissions on /boot, /lib/modules, and the kernel
49470 + source directory to change at compile time to prevent
49471 + reading by non-root users.
49472 + If the above conditions are met, this option will aid in providing a
49473 + useful protection against local kernel exploitation of overflows
49474 + and arbitrary read/write vulnerabilities.
49475 +
49476 +config GRKERNSEC_KERN_LOCKOUT
49477 + bool "Active kernel exploit response"
49478 + default y if GRKERNSEC_CONFIG_AUTO
49479 + depends on X86 || ARM || PPC || SPARC
49480 + help
49481 + If you say Y here, when a PaX alert is triggered due to suspicious
49482 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
49483 + or an OOPS occurs due to bad memory accesses, instead of just
49484 + terminating the offending process (and potentially allowing
49485 + a subsequent exploit from the same user), we will take one of two
49486 + actions:
49487 + If the user was root, we will panic the system
49488 + If the user was non-root, we will log the attempt, terminate
49489 + all processes owned by the user, then prevent them from creating
49490 + any new processes until the system is restarted
49491 + This deters repeated kernel exploitation/bruteforcing attempts
49492 + and is useful for later forensics.
49493 +
49494 +endmenu
49495 +menu "Role Based Access Control Options"
49496 +depends on GRKERNSEC
49497 +
49498 +config GRKERNSEC_RBAC_DEBUG
49499 + bool
49500 +
49501 +config GRKERNSEC_NO_RBAC
49502 + bool "Disable RBAC system"
49503 + help
49504 + If you say Y here, the /dev/grsec device will be removed from the kernel,
49505 + preventing the RBAC system from being enabled. You should only say Y
49506 + here if you have no intention of using the RBAC system, so as to prevent
49507 + an attacker with root access from misusing the RBAC system to hide files
49508 + and processes when loadable module support and /dev/[k]mem have been
49509 + locked down.
49510 +
49511 +config GRKERNSEC_ACL_HIDEKERN
49512 + bool "Hide kernel processes"
49513 + help
49514 + If you say Y here, all kernel threads will be hidden to all
49515 + processes but those whose subject has the "view hidden processes"
49516 + flag.
49517 +
49518 +config GRKERNSEC_ACL_MAXTRIES
49519 + int "Maximum tries before password lockout"
49520 + default 3
49521 + help
49522 + This option enforces the maximum number of times a user can attempt
49523 + to authorize themselves with the grsecurity RBAC system before being
49524 + denied the ability to attempt authorization again for a specified time.
49525 + The lower the number, the harder it will be to brute-force a password.
49526 +
49527 +config GRKERNSEC_ACL_TIMEOUT
49528 + int "Time to wait after max password tries, in seconds"
49529 + default 30
49530 + help
49531 + This option specifies the time the user must wait after attempting to
49532 + authorize to the RBAC system with the maximum number of invalid
49533 + passwords. The higher the number, the harder it will be to brute-force
49534 + a password.
49535 +
49536 +endmenu
49537 +menu "Filesystem Protections"
49538 +depends on GRKERNSEC
49539 +
49540 +config GRKERNSEC_PROC
49541 + bool "Proc restrictions"
49542 + default y if GRKERNSEC_CONFIG_AUTO
49543 + help
49544 + If you say Y here, the permissions of the /proc filesystem
49545 + will be altered to enhance system security and privacy. You MUST
49546 + choose either a user only restriction or a user and group restriction.
49547 + Depending upon the option you choose, you can either restrict users to
49548 + see only the processes they themselves run, or choose a group that can
49549 + view all processes and files normally restricted to root if you choose
49550 + the "restrict to user only" option. NOTE: If you're running identd or
49551 + ntpd as a non-root user, you will have to run it as the group you
49552 + specify here.
49553 +
49554 +config GRKERNSEC_PROC_USER
49555 + bool "Restrict /proc to user only"
49556 + depends on GRKERNSEC_PROC
49557 + help
49558 + If you say Y here, non-root users will only be able to view their own
49559 + processes, and restricts them from viewing network-related information,
49560 + and viewing kernel symbol and module information.
49561 +
49562 +config GRKERNSEC_PROC_USERGROUP
49563 + bool "Allow special group"
49564 + default y if GRKERNSEC_CONFIG_AUTO
49565 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
49566 + help
49567 + If you say Y here, you will be able to select a group that will be
49568 + able to view all processes and network-related information. If you've
49569 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
49570 + remain hidden. This option is useful if you want to run identd as
49571 + a non-root user.
49572 +
49573 +config GRKERNSEC_PROC_GID
49574 + int "GID for special group"
49575 + depends on GRKERNSEC_PROC_USERGROUP
49576 + default 1001
49577 +
49578 +config GRKERNSEC_PROC_ADD
49579 + bool "Additional restrictions"
49580 + default y if GRKERNSEC_CONFIG_AUTO
49581 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
49582 + help
49583 + If you say Y here, additional restrictions will be placed on
49584 + /proc that keep normal users from viewing device information and
49585 + slabinfo information that could be useful for exploits.
49586 +
49587 +config GRKERNSEC_LINK
49588 + bool "Linking restrictions"
49589 + default y if GRKERNSEC_CONFIG_AUTO
49590 + help
49591 + If you say Y here, /tmp race exploits will be prevented, since users
49592 + will no longer be able to follow symlinks owned by other users in
49593 + world-writable +t directories (e.g. /tmp), unless the owner of the
49594 + symlink is the owner of the directory. users will also not be
49595 + able to hardlink to files they do not own. If the sysctl option is
49596 + enabled, a sysctl option with name "linking_restrictions" is created.
49597 +
49598 +config GRKERNSEC_SYMLINKOWN
49599 + bool "Kernel-enforced SymlinksIfOwnerMatch"
49600 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
49601 + help
49602 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
49603 + that prevents it from being used as a security feature. As Apache
49604 + verifies the symlink by performing a stat() against the target of
49605 + the symlink before it is followed, an attacker can setup a symlink
49606 + to point to a same-owned file, then replace the symlink with one
49607 + that targets another user's file just after Apache "validates" the
49608 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
49609 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
49610 + will be in place for the group you specify. If the sysctl option
49611 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
49612 + created.
49613 +
49614 +config GRKERNSEC_SYMLINKOWN_GID
49615 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
49616 + depends on GRKERNSEC_SYMLINKOWN
49617 + default 1006
49618 + help
49619 + Setting this GID determines what group kernel-enforced
49620 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
49621 + is enabled, a sysctl option with name "symlinkown_gid" is created.
49622 +
49623 +config GRKERNSEC_FIFO
49624 + bool "FIFO restrictions"
49625 + default y if GRKERNSEC_CONFIG_AUTO
49626 + help
49627 + If you say Y here, users will not be able to write to FIFOs they don't
49628 + own in world-writable +t directories (e.g. /tmp), unless the owner of
49629 + the FIFO is the same owner of the directory it's held in. If the sysctl
49630 + option is enabled, a sysctl option with name "fifo_restrictions" is
49631 + created.
49632 +
49633 +config GRKERNSEC_SYSFS_RESTRICT
49634 + bool "Sysfs/debugfs restriction"
49635 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
49636 + depends on SYSFS
49637 + help
49638 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
49639 + any filesystem normally mounted under it (e.g. debugfs) will be
49640 + mostly accessible only by root. These filesystems generally provide access
49641 + to hardware and debug information that isn't appropriate for unprivileged
49642 + users of the system. Sysfs and debugfs have also become a large source
49643 + of new vulnerabilities, ranging from infoleaks to local compromise.
49644 + There has been very little oversight with an eye toward security involved
49645 + in adding new exporters of information to these filesystems, so their
49646 + use is discouraged.
49647 + For reasons of compatibility, a few directories have been whitelisted
49648 + for access by non-root users:
49649 + /sys/fs/selinux
49650 + /sys/fs/fuse
49651 + /sys/devices/system/cpu
49652 +
49653 +config GRKERNSEC_ROFS
49654 + bool "Runtime read-only mount protection"
49655 + help
49656 + If you say Y here, a sysctl option with name "romount_protect" will
49657 + be created. By setting this option to 1 at runtime, filesystems
49658 + will be protected in the following ways:
49659 + * No new writable mounts will be allowed
49660 + * Existing read-only mounts won't be able to be remounted read/write
49661 + * Write operations will be denied on all block devices
49662 + This option acts independently of grsec_lock: once it is set to 1,
49663 + it cannot be turned off. Therefore, please be mindful of the resulting
49664 + behavior if this option is enabled in an init script on a read-only
49665 + filesystem. This feature is mainly intended for secure embedded systems.
49666 +
49667 +config GRKERNSEC_CHROOT
49668 + bool "Chroot jail restrictions"
49669 + default y if GRKERNSEC_CONFIG_AUTO
49670 + help
49671 + If you say Y here, you will be able to choose several options that will
49672 + make breaking out of a chrooted jail much more difficult. If you
49673 + encounter no software incompatibilities with the following options, it
49674 + is recommended that you enable each one.
49675 +
49676 +config GRKERNSEC_CHROOT_MOUNT
49677 + bool "Deny mounts"
49678 + default y if GRKERNSEC_CONFIG_AUTO
49679 + depends on GRKERNSEC_CHROOT
49680 + help
49681 + If you say Y here, processes inside a chroot will not be able to
49682 + mount or remount filesystems. If the sysctl option is enabled, a
49683 + sysctl option with name "chroot_deny_mount" is created.
49684 +
49685 +config GRKERNSEC_CHROOT_DOUBLE
49686 + bool "Deny double-chroots"
49687 + default y if GRKERNSEC_CONFIG_AUTO
49688 + depends on GRKERNSEC_CHROOT
49689 + help
49690 + If you say Y here, processes inside a chroot will not be able to chroot
49691 + again outside the chroot. This is a widely used method of breaking
49692 + out of a chroot jail and should not be allowed. If the sysctl
49693 + option is enabled, a sysctl option with name
49694 + "chroot_deny_chroot" is created.
49695 +
49696 +config GRKERNSEC_CHROOT_PIVOT
49697 + bool "Deny pivot_root in chroot"
49698 + default y if GRKERNSEC_CONFIG_AUTO
49699 + depends on GRKERNSEC_CHROOT
49700 + help
49701 + If you say Y here, processes inside a chroot will not be able to use
49702 + a function called pivot_root() that was introduced in Linux 2.3.41. It
49703 + works similar to chroot in that it changes the root filesystem. This
49704 + function could be misused in a chrooted process to attempt to break out
49705 + of the chroot, and therefore should not be allowed. If the sysctl
49706 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
49707 + created.
49708 +
49709 +config GRKERNSEC_CHROOT_CHDIR
49710 + bool "Enforce chdir(\"/\") on all chroots"
49711 + default y if GRKERNSEC_CONFIG_AUTO
49712 + depends on GRKERNSEC_CHROOT
49713 + help
49714 + If you say Y here, the current working directory of all newly-chrooted
49715 + applications will be set to the the root directory of the chroot.
49716 + The man page on chroot(2) states:
49717 + Note that this call does not change the current working
49718 + directory, so that `.' can be outside the tree rooted at
49719 + `/'. In particular, the super-user can escape from a
49720 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
49721 +
49722 + It is recommended that you say Y here, since it's not known to break
49723 + any software. If the sysctl option is enabled, a sysctl option with
49724 + name "chroot_enforce_chdir" is created.
49725 +
49726 +config GRKERNSEC_CHROOT_CHMOD
49727 + bool "Deny (f)chmod +s"
49728 + default y if GRKERNSEC_CONFIG_AUTO
49729 + depends on GRKERNSEC_CHROOT
49730 + help
49731 + If you say Y here, processes inside a chroot will not be able to chmod
49732 + or fchmod files to make them have suid or sgid bits. This protects
49733 + against another published method of breaking a chroot. If the sysctl
49734 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
49735 + created.
49736 +
49737 +config GRKERNSEC_CHROOT_FCHDIR
49738 + bool "Deny fchdir out of chroot"
49739 + default y if GRKERNSEC_CONFIG_AUTO
49740 + depends on GRKERNSEC_CHROOT
49741 + help
49742 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
49743 + to a file descriptor of the chrooting process that points to a directory
49744 + outside the filesystem will be stopped. If the sysctl option
49745 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
49746 +
49747 +config GRKERNSEC_CHROOT_MKNOD
49748 + bool "Deny mknod"
49749 + default y if GRKERNSEC_CONFIG_AUTO
49750 + depends on GRKERNSEC_CHROOT
49751 + help
49752 + If you say Y here, processes inside a chroot will not be allowed to
49753 + mknod. The problem with using mknod inside a chroot is that it
49754 + would allow an attacker to create a device entry that is the same
49755 + as one on the physical root of your system, which could range from
49756 + anything from the console device to a device for your harddrive (which
49757 + they could then use to wipe the drive or steal data). It is recommended
49758 + that you say Y here, unless you run into software incompatibilities.
49759 + If the sysctl option is enabled, a sysctl option with name
49760 + "chroot_deny_mknod" is created.
49761 +
49762 +config GRKERNSEC_CHROOT_SHMAT
49763 + bool "Deny shmat() out of chroot"
49764 + default y if GRKERNSEC_CONFIG_AUTO
49765 + depends on GRKERNSEC_CHROOT
49766 + help
49767 + If you say Y here, processes inside a chroot will not be able to attach
49768 + to shared memory segments that were created outside of the chroot jail.
49769 + It is recommended that you say Y here. If the sysctl option is enabled,
49770 + a sysctl option with name "chroot_deny_shmat" is created.
49771 +
49772 +config GRKERNSEC_CHROOT_UNIX
49773 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
49774 + default y if GRKERNSEC_CONFIG_AUTO
49775 + depends on GRKERNSEC_CHROOT
49776 + help
49777 + If you say Y here, processes inside a chroot will not be able to
49778 + connect to abstract (meaning not belonging to a filesystem) Unix
49779 + domain sockets that were bound outside of a chroot. It is recommended
49780 + that you say Y here. If the sysctl option is enabled, a sysctl option
49781 + with name "chroot_deny_unix" is created.
49782 +
49783 +config GRKERNSEC_CHROOT_FINDTASK
49784 + bool "Protect outside processes"
49785 + default y if GRKERNSEC_CONFIG_AUTO
49786 + depends on GRKERNSEC_CHROOT
49787 + help
49788 + If you say Y here, processes inside a chroot will not be able to
49789 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
49790 + getsid, or view any process outside of the chroot. If the sysctl
49791 + option is enabled, a sysctl option with name "chroot_findtask" is
49792 + created.
49793 +
49794 +config GRKERNSEC_CHROOT_NICE
49795 + bool "Restrict priority changes"
49796 + default y if GRKERNSEC_CONFIG_AUTO
49797 + depends on GRKERNSEC_CHROOT
49798 + help
49799 + If you say Y here, processes inside a chroot will not be able to raise
49800 + the priority of processes in the chroot, or alter the priority of
49801 + processes outside the chroot. This provides more security than simply
49802 + removing CAP_SYS_NICE from the process' capability set. If the
49803 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
49804 + is created.
49805 +
49806 +config GRKERNSEC_CHROOT_SYSCTL
49807 + bool "Deny sysctl writes"
49808 + default y if GRKERNSEC_CONFIG_AUTO
49809 + depends on GRKERNSEC_CHROOT
49810 + help
49811 + If you say Y here, an attacker in a chroot will not be able to
49812 + write to sysctl entries, either by sysctl(2) or through a /proc
49813 + interface. It is strongly recommended that you say Y here. If the
49814 + sysctl option is enabled, a sysctl option with name
49815 + "chroot_deny_sysctl" is created.
49816 +
49817 +config GRKERNSEC_CHROOT_CAPS
49818 + bool "Capability restrictions"
49819 + default y if GRKERNSEC_CONFIG_AUTO
49820 + depends on GRKERNSEC_CHROOT
49821 + help
49822 + If you say Y here, the capabilities on all processes within a
49823 + chroot jail will be lowered to stop module insertion, raw i/o,
49824 + system and net admin tasks, rebooting the system, modifying immutable
49825 + files, modifying IPC owned by another, and changing the system time.
49826 + This is left an option because it can break some apps. Disable this
49827 + if your chrooted apps are having problems performing those kinds of
49828 + tasks. If the sysctl option is enabled, a sysctl option with
49829 + name "chroot_caps" is created.
49830 +
49831 +endmenu
49832 +menu "Kernel Auditing"
49833 +depends on GRKERNSEC
49834 +
49835 +config GRKERNSEC_AUDIT_GROUP
49836 + bool "Single group for auditing"
49837 + help
49838 + If you say Y here, the exec, chdir, and (un)mount logging features
49839 + will only operate on a group you specify. This option is recommended
49840 + if you only want to watch certain users instead of having a large
49841 + amount of logs from the entire system. If the sysctl option is enabled,
49842 + a sysctl option with name "audit_group" is created.
49843 +
49844 +config GRKERNSEC_AUDIT_GID
49845 + int "GID for auditing"
49846 + depends on GRKERNSEC_AUDIT_GROUP
49847 + default 1007
49848 +
49849 +config GRKERNSEC_EXECLOG
49850 + bool "Exec logging"
49851 + help
49852 + If you say Y here, all execve() calls will be logged (since the
49853 + other exec*() calls are frontends to execve(), all execution
49854 + will be logged). Useful for shell-servers that like to keep track
49855 + of their users. If the sysctl option is enabled, a sysctl option with
49856 + name "exec_logging" is created.
49857 + WARNING: This option when enabled will produce a LOT of logs, especially
49858 + on an active system.
49859 +
49860 +config GRKERNSEC_RESLOG
49861 + bool "Resource logging"
49862 + default y if GRKERNSEC_CONFIG_AUTO
49863 + help
49864 + If you say Y here, all attempts to overstep resource limits will
49865 + be logged with the resource name, the requested size, and the current
49866 + limit. It is highly recommended that you say Y here. If the sysctl
49867 + option is enabled, a sysctl option with name "resource_logging" is
49868 + created. If the RBAC system is enabled, the sysctl value is ignored.
49869 +
49870 +config GRKERNSEC_CHROOT_EXECLOG
49871 + bool "Log execs within chroot"
49872 + help
49873 + If you say Y here, all executions inside a chroot jail will be logged
49874 + to syslog. This can cause a large amount of logs if certain
49875 + applications (eg. djb's daemontools) are installed on the system, and
49876 + is therefore left as an option. If the sysctl option is enabled, a
49877 + sysctl option with name "chroot_execlog" is created.
49878 +
49879 +config GRKERNSEC_AUDIT_PTRACE
49880 + bool "Ptrace logging"
49881 + help
49882 + If you say Y here, all attempts to attach to a process via ptrace
49883 + will be logged. If the sysctl option is enabled, a sysctl option
49884 + with name "audit_ptrace" is created.
49885 +
49886 +config GRKERNSEC_AUDIT_CHDIR
49887 + bool "Chdir logging"
49888 + help
49889 + If you say Y here, all chdir() calls will be logged. If the sysctl
49890 + option is enabled, a sysctl option with name "audit_chdir" is created.
49891 +
49892 +config GRKERNSEC_AUDIT_MOUNT
49893 + bool "(Un)Mount logging"
49894 + help
49895 + If you say Y here, all mounts and unmounts will be logged. If the
49896 + sysctl option is enabled, a sysctl option with name "audit_mount" is
49897 + created.
49898 +
49899 +config GRKERNSEC_SIGNAL
49900 + bool "Signal logging"
49901 + default y if GRKERNSEC_CONFIG_AUTO
49902 + help
49903 + If you say Y here, certain important signals will be logged, such as
49904 + SIGSEGV, which will as a result inform you of when a error in a program
49905 + occurred, which in some cases could mean a possible exploit attempt.
49906 + If the sysctl option is enabled, a sysctl option with name
49907 + "signal_logging" is created.
49908 +
49909 +config GRKERNSEC_FORKFAIL
49910 + bool "Fork failure logging"
49911 + help
49912 + If you say Y here, all failed fork() attempts will be logged.
49913 + This could suggest a fork bomb, or someone attempting to overstep
49914 + their process limit. If the sysctl option is enabled, a sysctl option
49915 + with name "forkfail_logging" is created.
49916 +
49917 +config GRKERNSEC_TIME
49918 + bool "Time change logging"
49919 + default y if GRKERNSEC_CONFIG_AUTO
49920 + help
49921 + If you say Y here, any changes of the system clock will be logged.
49922 + If the sysctl option is enabled, a sysctl option with name
49923 + "timechange_logging" is created.
49924 +
49925 +config GRKERNSEC_PROC_IPADDR
49926 + bool "/proc/<pid>/ipaddr support"
49927 + default y if GRKERNSEC_CONFIG_AUTO
49928 + help
49929 + If you say Y here, a new entry will be added to each /proc/<pid>
49930 + directory that contains the IP address of the person using the task.
49931 + The IP is carried across local TCP and AF_UNIX stream sockets.
49932 + This information can be useful for IDS/IPSes to perform remote response
49933 + to a local attack. The entry is readable by only the owner of the
49934 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
49935 + the RBAC system), and thus does not create privacy concerns.
49936 +
49937 +config GRKERNSEC_RWXMAP_LOG
49938 + bool 'Denied RWX mmap/mprotect logging'
49939 + default y if GRKERNSEC_CONFIG_AUTO
49940 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
49941 + help
49942 + If you say Y here, calls to mmap() and mprotect() with explicit
49943 + usage of PROT_WRITE and PROT_EXEC together will be logged when
49944 + denied by the PAX_MPROTECT feature. If the sysctl option is
49945 + enabled, a sysctl option with name "rwxmap_logging" is created.
49946 +
49947 +config GRKERNSEC_AUDIT_TEXTREL
49948 + bool 'ELF text relocations logging (READ HELP)'
49949 + depends on PAX_MPROTECT
49950 + help
49951 + If you say Y here, text relocations will be logged with the filename
49952 + of the offending library or binary. The purpose of the feature is
49953 + to help Linux distribution developers get rid of libraries and
49954 + binaries that need text relocations which hinder the future progress
49955 + of PaX. Only Linux distribution developers should say Y here, and
49956 + never on a production machine, as this option creates an information
49957 + leak that could aid an attacker in defeating the randomization of
49958 + a single memory region. If the sysctl option is enabled, a sysctl
49959 + option with name "audit_textrel" is created.
49960 +
49961 +endmenu
49962 +
49963 +menu "Executable Protections"
49964 +depends on GRKERNSEC
49965 +
49966 +config GRKERNSEC_DMESG
49967 + bool "Dmesg(8) restriction"
49968 + default y if GRKERNSEC_CONFIG_AUTO
49969 + help
49970 + If you say Y here, non-root users will not be able to use dmesg(8)
49971 + to view up to the last 4kb of messages in the kernel's log buffer.
49972 + The kernel's log buffer often contains kernel addresses and other
49973 + identifying information useful to an attacker in fingerprinting a
49974 + system for a targeted exploit.
49975 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
49976 + created.
49977 +
49978 +config GRKERNSEC_HARDEN_PTRACE
49979 + bool "Deter ptrace-based process snooping"
49980 + default y if GRKERNSEC_CONFIG_AUTO
49981 + help
49982 + If you say Y here, TTY sniffers and other malicious monitoring
49983 + programs implemented through ptrace will be defeated. If you
49984 + have been using the RBAC system, this option has already been
49985 + enabled for several years for all users, with the ability to make
49986 + fine-grained exceptions.
49987 +
49988 + This option only affects the ability of non-root users to ptrace
49989 + processes that are not a descendent of the ptracing process.
49990 + This means that strace ./binary and gdb ./binary will still work,
49991 + but attaching to arbitrary processes will not. If the sysctl
49992 + option is enabled, a sysctl option with name "harden_ptrace" is
49993 + created.
49994 +
49995 +config GRKERNSEC_PTRACE_READEXEC
49996 + bool "Require read access to ptrace sensitive binaries"
49997 + default y if GRKERNSEC_CONFIG_AUTO
49998 + help
49999 + If you say Y here, unprivileged users will not be able to ptrace unreadable
50000 + binaries. This option is useful in environments that
50001 + remove the read bits (e.g. file mode 4711) from suid binaries to
50002 + prevent infoleaking of their contents. This option adds
50003 + consistency to the use of that file mode, as the binary could normally
50004 + be read out when run without privileges while ptracing.
50005 +
50006 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
50007 + is created.
50008 +
50009 +config GRKERNSEC_SETXID
50010 + bool "Enforce consistent multithreaded privileges"
50011 + default y if GRKERNSEC_CONFIG_AUTO
50012 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
50013 + help
50014 + If you say Y here, a change from a root uid to a non-root uid
50015 + in a multithreaded application will cause the resulting uids,
50016 + gids, supplementary groups, and capabilities in that thread
50017 + to be propagated to the other threads of the process. In most
50018 + cases this is unnecessary, as glibc will emulate this behavior
50019 + on behalf of the application. Other libcs do not act in the
50020 + same way, allowing the other threads of the process to continue
50021 + running with root privileges. If the sysctl option is enabled,
50022 + a sysctl option with name "consistent_setxid" is created.
50023 +
50024 +config GRKERNSEC_TPE
50025 + bool "Trusted Path Execution (TPE)"
50026 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50027 + help
50028 + If you say Y here, you will be able to choose a gid to add to the
50029 + supplementary groups of users you want to mark as "untrusted."
50030 + These users will not be able to execute any files that are not in
50031 + root-owned directories writable only by root. If the sysctl option
50032 + is enabled, a sysctl option with name "tpe" is created.
50033 +
50034 +config GRKERNSEC_TPE_ALL
50035 + bool "Partially restrict all non-root users"
50036 + depends on GRKERNSEC_TPE
50037 + help
50038 + If you say Y here, all non-root users will be covered under
50039 + a weaker TPE restriction. This is separate from, and in addition to,
50040 + the main TPE options that you have selected elsewhere. Thus, if a
50041 + "trusted" GID is chosen, this restriction applies to even that GID.
50042 + Under this restriction, all non-root users will only be allowed to
50043 + execute files in directories they own that are not group or
50044 + world-writable, or in directories owned by root and writable only by
50045 + root. If the sysctl option is enabled, a sysctl option with name
50046 + "tpe_restrict_all" is created.
50047 +
50048 +config GRKERNSEC_TPE_INVERT
50049 + bool "Invert GID option"
50050 + depends on GRKERNSEC_TPE
50051 + help
50052 + If you say Y here, the group you specify in the TPE configuration will
50053 + decide what group TPE restrictions will be *disabled* for. This
50054 + option is useful if you want TPE restrictions to be applied to most
50055 + users on the system. If the sysctl option is enabled, a sysctl option
50056 + with name "tpe_invert" is created. Unlike other sysctl options, this
50057 + entry will default to on for backward-compatibility.
50058 +
50059 +config GRKERNSEC_TPE_GID
50060 + int "GID for untrusted users"
50061 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
50062 + default 1005
50063 + help
50064 + Setting this GID determines what group TPE restrictions will be
50065 + *enabled* for. If the sysctl option is enabled, a sysctl option
50066 + with name "tpe_gid" is created.
50067 +
50068 +config GRKERNSEC_TPE_GID
50069 + int "GID for trusted users"
50070 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
50071 + default 1005
50072 + help
50073 + Setting this GID determines what group TPE restrictions will be
50074 + *disabled* for. If the sysctl option is enabled, a sysctl option
50075 + with name "tpe_gid" is created.
50076 +
50077 +endmenu
50078 +menu "Network Protections"
50079 +depends on GRKERNSEC
50080 +
50081 +config GRKERNSEC_RANDNET
50082 + bool "Larger entropy pools"
50083 + default y if GRKERNSEC_CONFIG_AUTO
50084 + help
50085 + If you say Y here, the entropy pools used for many features of Linux
50086 + and grsecurity will be doubled in size. Since several grsecurity
50087 + features use additional randomness, it is recommended that you say Y
50088 + here. Saying Y here has a similar effect as modifying
50089 + /proc/sys/kernel/random/poolsize.
50090 +
50091 +config GRKERNSEC_BLACKHOLE
50092 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
50093 + default y if GRKERNSEC_CONFIG_AUTO
50094 + depends on NET
50095 + help
50096 + If you say Y here, neither TCP resets nor ICMP
50097 + destination-unreachable packets will be sent in response to packets
50098 + sent to ports for which no associated listening process exists.
50099 + This feature supports both IPV4 and IPV6 and exempts the
50100 + loopback interface from blackholing. Enabling this feature
50101 + makes a host more resilient to DoS attacks and reduces network
50102 + visibility against scanners.
50103 +
50104 + The blackhole feature as-implemented is equivalent to the FreeBSD
50105 + blackhole feature, as it prevents RST responses to all packets, not
50106 + just SYNs. Under most application behavior this causes no
50107 + problems, but applications (like haproxy) may not close certain
50108 + connections in a way that cleanly terminates them on the remote
50109 + end, leaving the remote host in LAST_ACK state. Because of this
50110 + side-effect and to prevent intentional LAST_ACK DoSes, this
50111 + feature also adds automatic mitigation against such attacks.
50112 + The mitigation drastically reduces the amount of time a socket
50113 + can spend in LAST_ACK state. If you're using haproxy and not
50114 + all servers it connects to have this option enabled, consider
50115 + disabling this feature on the haproxy host.
50116 +
50117 + If the sysctl option is enabled, two sysctl options with names
50118 + "ip_blackhole" and "lastack_retries" will be created.
50119 + While "ip_blackhole" takes the standard zero/non-zero on/off
50120 + toggle, "lastack_retries" uses the same kinds of values as
50121 + "tcp_retries1" and "tcp_retries2". The default value of 4
50122 + prevents a socket from lasting more than 45 seconds in LAST_ACK
50123 + state.
50124 +
50125 +config GRKERNSEC_SOCKET
50126 + bool "Socket restrictions"
50127 + depends on NET
50128 + help
50129 + If you say Y here, you will be able to choose from several options.
50130 + If you assign a GID on your system and add it to the supplementary
50131 + groups of users you want to restrict socket access to, this patch
50132 + will perform up to three things, based on the option(s) you choose.
50133 +
50134 +config GRKERNSEC_SOCKET_ALL
50135 + bool "Deny any sockets to group"
50136 + depends on GRKERNSEC_SOCKET
50137 + help
50138 + If you say Y here, you will be able to choose a GID of whose users will
50139 + be unable to connect to other hosts from your machine or run server
50140 + applications from your machine. If the sysctl option is enabled, a
50141 + sysctl option with name "socket_all" is created.
50142 +
50143 +config GRKERNSEC_SOCKET_ALL_GID
50144 + int "GID to deny all sockets for"
50145 + depends on GRKERNSEC_SOCKET_ALL
50146 + default 1004
50147 + help
50148 + Here you can choose the GID to disable socket access for. Remember to
50149 + add the users you want socket access disabled for to the GID
50150 + specified here. If the sysctl option is enabled, a sysctl option
50151 + with name "socket_all_gid" is created.
50152 +
50153 +config GRKERNSEC_SOCKET_CLIENT
50154 + bool "Deny client sockets to group"
50155 + depends on GRKERNSEC_SOCKET
50156 + help
50157 + If you say Y here, you will be able to choose a GID of whose users will
50158 + be unable to connect to other hosts from your machine, but will be
50159 + able to run servers. If this option is enabled, all users in the group
50160 + you specify will have to use passive mode when initiating ftp transfers
50161 + from the shell on your machine. If the sysctl option is enabled, a
50162 + sysctl option with name "socket_client" is created.
50163 +
50164 +config GRKERNSEC_SOCKET_CLIENT_GID
50165 + int "GID to deny client sockets for"
50166 + depends on GRKERNSEC_SOCKET_CLIENT
50167 + default 1003
50168 + help
50169 + Here you can choose the GID to disable client socket access for.
50170 + Remember to add the users you want client socket access disabled for to
50171 + the GID specified here. If the sysctl option is enabled, a sysctl
50172 + option with name "socket_client_gid" is created.
50173 +
50174 +config GRKERNSEC_SOCKET_SERVER
50175 + bool "Deny server sockets to group"
50176 + depends on GRKERNSEC_SOCKET
50177 + help
50178 + If you say Y here, you will be able to choose a GID of whose users will
50179 + be unable to run server applications from your machine. If the sysctl
50180 + option is enabled, a sysctl option with name "socket_server" is created.
50181 +
50182 +config GRKERNSEC_SOCKET_SERVER_GID
50183 + int "GID to deny server sockets for"
50184 + depends on GRKERNSEC_SOCKET_SERVER
50185 + default 1002
50186 + help
50187 + Here you can choose the GID to disable server socket access for.
50188 + Remember to add the users you want server socket access disabled for to
50189 + the GID specified here. If the sysctl option is enabled, a sysctl
50190 + option with name "socket_server_gid" is created.
50191 +
50192 +endmenu
50193 +menu "Sysctl Support"
50194 +depends on GRKERNSEC && SYSCTL
50195 +
50196 +config GRKERNSEC_SYSCTL
50197 + bool "Sysctl support"
50198 + default y if GRKERNSEC_CONFIG_AUTO
50199 + help
50200 + If you say Y here, you will be able to change the options that
50201 + grsecurity runs with at bootup, without having to recompile your
50202 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
50203 + to enable (1) or disable (0) various features. All the sysctl entries
50204 + are mutable until the "grsec_lock" entry is set to a non-zero value.
50205 + All features enabled in the kernel configuration are disabled at boot
50206 + if you do not say Y to the "Turn on features by default" option.
50207 + All options should be set at startup, and the grsec_lock entry should
50208 + be set to a non-zero value after all the options are set.
50209 + *THIS IS EXTREMELY IMPORTANT*
50210 +
50211 +config GRKERNSEC_SYSCTL_DISTRO
50212 + bool "Extra sysctl support for distro makers (READ HELP)"
50213 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
50214 + help
50215 + If you say Y here, additional sysctl options will be created
50216 + for features that affect processes running as root. Therefore,
50217 + it is critical when using this option that the grsec_lock entry be
50218 + enabled after boot. Only distros with prebuilt kernel packages
50219 + with this option enabled that can ensure grsec_lock is enabled
50220 + after boot should use this option.
50221 + *Failure to set grsec_lock after boot makes all grsec features
50222 + this option covers useless*
50223 +
50224 + Currently this option creates the following sysctl entries:
50225 + "Disable Privileged I/O": "disable_priv_io"
50226 +
50227 +config GRKERNSEC_SYSCTL_ON
50228 + bool "Turn on features by default"
50229 + default y if GRKERNSEC_CONFIG_AUTO
50230 + depends on GRKERNSEC_SYSCTL
50231 + help
50232 + If you say Y here, instead of having all features enabled in the
50233 + kernel configuration disabled at boot time, the features will be
50234 + enabled at boot time. It is recommended you say Y here unless
50235 + there is some reason you would want all sysctl-tunable features to
50236 + be disabled by default. As mentioned elsewhere, it is important
50237 + to enable the grsec_lock entry once you have finished modifying
50238 + the sysctl entries.
50239 +
50240 +endmenu
50241 +menu "Logging Options"
50242 +depends on GRKERNSEC
50243 +
50244 +config GRKERNSEC_FLOODTIME
50245 + int "Seconds in between log messages (minimum)"
50246 + default 10
50247 + help
50248 + This option allows you to enforce the number of seconds between
50249 + grsecurity log messages. The default should be suitable for most
50250 + people, however, if you choose to change it, choose a value small enough
50251 + to allow informative logs to be produced, but large enough to
50252 + prevent flooding.
50253 +
50254 +config GRKERNSEC_FLOODBURST
50255 + int "Number of messages in a burst (maximum)"
50256 + default 6
50257 + help
50258 + This option allows you to choose the maximum number of messages allowed
50259 + within the flood time interval you chose in a separate option. The
50260 + default should be suitable for most people, however if you find that
50261 + many of your logs are being interpreted as flooding, you may want to
50262 + raise this value.
50263 +
50264 +endmenu
50265 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
50266 new file mode 100644
50267 index 0000000..1b9afa9
50268 --- /dev/null
50269 +++ b/grsecurity/Makefile
50270 @@ -0,0 +1,38 @@
50271 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
50272 +# during 2001-2009 it has been completely redesigned by Brad Spengler
50273 +# into an RBAC system
50274 +#
50275 +# All code in this directory and various hooks inserted throughout the kernel
50276 +# are copyright Brad Spengler - Open Source Security, Inc., and released
50277 +# under the GPL v2 or higher
50278 +
50279 +KBUILD_CFLAGS += -Werror
50280 +
50281 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
50282 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
50283 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
50284 +
50285 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
50286 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
50287 + gracl_learn.o grsec_log.o
50288 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
50289 +
50290 +ifdef CONFIG_NET
50291 +obj-y += grsec_sock.o
50292 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
50293 +endif
50294 +
50295 +ifndef CONFIG_GRKERNSEC
50296 +obj-y += grsec_disabled.o
50297 +endif
50298 +
50299 +ifdef CONFIG_GRKERNSEC_HIDESYM
50300 +extra-y := grsec_hidesym.o
50301 +$(obj)/grsec_hidesym.o:
50302 + @-chmod -f 500 /boot
50303 + @-chmod -f 500 /lib/modules
50304 + @-chmod -f 500 /lib64/modules
50305 + @-chmod -f 500 /lib32/modules
50306 + @-chmod -f 700 .
50307 + @echo ' grsec: protected kernel image paths'
50308 +endif
50309 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
50310 new file mode 100644
50311 index 0000000..7a5922f
50312 --- /dev/null
50313 +++ b/grsecurity/gracl.c
50314 @@ -0,0 +1,4016 @@
50315 +#include <linux/kernel.h>
50316 +#include <linux/module.h>
50317 +#include <linux/sched.h>
50318 +#include <linux/mm.h>
50319 +#include <linux/file.h>
50320 +#include <linux/fs.h>
50321 +#include <linux/namei.h>
50322 +#include <linux/mount.h>
50323 +#include <linux/tty.h>
50324 +#include <linux/proc_fs.h>
50325 +#include <linux/lglock.h>
50326 +#include <linux/slab.h>
50327 +#include <linux/vmalloc.h>
50328 +#include <linux/types.h>
50329 +#include <linux/sysctl.h>
50330 +#include <linux/netdevice.h>
50331 +#include <linux/ptrace.h>
50332 +#include <linux/gracl.h>
50333 +#include <linux/gralloc.h>
50334 +#include <linux/security.h>
50335 +#include <linux/grinternal.h>
50336 +#include <linux/pid_namespace.h>
50337 +#include <linux/stop_machine.h>
50338 +#include <linux/fdtable.h>
50339 +#include <linux/percpu.h>
50340 +#include "../fs/mount.h"
50341 +
50342 +#include <asm/uaccess.h>
50343 +#include <asm/errno.h>
50344 +#include <asm/mman.h>
50345 +
50346 +static struct acl_role_db acl_role_set;
50347 +static struct name_db name_set;
50348 +static struct inodev_db inodev_set;
50349 +
50350 +/* for keeping track of userspace pointers used for subjects, so we
50351 + can share references in the kernel as well
50352 +*/
50353 +
50354 +static struct path real_root;
50355 +
50356 +static struct acl_subj_map_db subj_map_set;
50357 +
50358 +static struct acl_role_label *default_role;
50359 +
50360 +static struct acl_role_label *role_list;
50361 +
50362 +static u16 acl_sp_role_value;
50363 +
50364 +extern char *gr_shared_page[4];
50365 +static DEFINE_MUTEX(gr_dev_mutex);
50366 +DEFINE_RWLOCK(gr_inode_lock);
50367 +
50368 +struct gr_arg *gr_usermode;
50369 +
50370 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
50371 +
50372 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
50373 +extern void gr_clear_learn_entries(void);
50374 +
50375 +#ifdef CONFIG_GRKERNSEC_RESLOG
50376 +extern void gr_log_resource(const struct task_struct *task,
50377 + const int res, const unsigned long wanted, const int gt);
50378 +#endif
50379 +
50380 +unsigned char *gr_system_salt;
50381 +unsigned char *gr_system_sum;
50382 +
50383 +static struct sprole_pw **acl_special_roles = NULL;
50384 +static __u16 num_sprole_pws = 0;
50385 +
50386 +static struct acl_role_label *kernel_role = NULL;
50387 +
50388 +static unsigned int gr_auth_attempts = 0;
50389 +static unsigned long gr_auth_expires = 0UL;
50390 +
50391 +#ifdef CONFIG_NET
50392 +extern struct vfsmount *sock_mnt;
50393 +#endif
50394 +
50395 +extern struct vfsmount *pipe_mnt;
50396 +extern struct vfsmount *shm_mnt;
50397 +#ifdef CONFIG_HUGETLBFS
50398 +extern struct vfsmount *hugetlbfs_vfsmount;
50399 +#endif
50400 +
50401 +static struct acl_object_label *fakefs_obj_rw;
50402 +static struct acl_object_label *fakefs_obj_rwx;
50403 +
50404 +extern int gr_init_uidset(void);
50405 +extern void gr_free_uidset(void);
50406 +extern void gr_remove_uid(uid_t uid);
50407 +extern int gr_find_uid(uid_t uid);
50408 +
50409 +DECLARE_BRLOCK(vfsmount_lock);
50410 +
50411 +__inline__ int
50412 +gr_acl_is_enabled(void)
50413 +{
50414 + return (gr_status & GR_READY);
50415 +}
50416 +
50417 +#ifdef CONFIG_BTRFS_FS
50418 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
50419 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
50420 +#endif
50421 +
50422 +static inline dev_t __get_dev(const struct dentry *dentry)
50423 +{
50424 +#ifdef CONFIG_BTRFS_FS
50425 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
50426 + return get_btrfs_dev_from_inode(dentry->d_inode);
50427 + else
50428 +#endif
50429 + return dentry->d_inode->i_sb->s_dev;
50430 +}
50431 +
50432 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
50433 +{
50434 + return __get_dev(dentry);
50435 +}
50436 +
50437 +static char gr_task_roletype_to_char(struct task_struct *task)
50438 +{
50439 + switch (task->role->roletype &
50440 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
50441 + GR_ROLE_SPECIAL)) {
50442 + case GR_ROLE_DEFAULT:
50443 + return 'D';
50444 + case GR_ROLE_USER:
50445 + return 'U';
50446 + case GR_ROLE_GROUP:
50447 + return 'G';
50448 + case GR_ROLE_SPECIAL:
50449 + return 'S';
50450 + }
50451 +
50452 + return 'X';
50453 +}
50454 +
50455 +char gr_roletype_to_char(void)
50456 +{
50457 + return gr_task_roletype_to_char(current);
50458 +}
50459 +
50460 +__inline__ int
50461 +gr_acl_tpe_check(void)
50462 +{
50463 + if (unlikely(!(gr_status & GR_READY)))
50464 + return 0;
50465 + if (current->role->roletype & GR_ROLE_TPE)
50466 + return 1;
50467 + else
50468 + return 0;
50469 +}
50470 +
50471 +int
50472 +gr_handle_rawio(const struct inode *inode)
50473 +{
50474 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
50475 + if (inode && S_ISBLK(inode->i_mode) &&
50476 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
50477 + !capable(CAP_SYS_RAWIO))
50478 + return 1;
50479 +#endif
50480 + return 0;
50481 +}
50482 +
50483 +static int
50484 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
50485 +{
50486 + if (likely(lena != lenb))
50487 + return 0;
50488 +
50489 + return !memcmp(a, b, lena);
50490 +}
50491 +
50492 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
50493 +{
50494 + *buflen -= namelen;
50495 + if (*buflen < 0)
50496 + return -ENAMETOOLONG;
50497 + *buffer -= namelen;
50498 + memcpy(*buffer, str, namelen);
50499 + return 0;
50500 +}
50501 +
50502 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
50503 +{
50504 + return prepend(buffer, buflen, name->name, name->len);
50505 +}
50506 +
50507 +static int prepend_path(const struct path *path, struct path *root,
50508 + char **buffer, int *buflen)
50509 +{
50510 + struct dentry *dentry = path->dentry;
50511 + struct vfsmount *vfsmnt = path->mnt;
50512 + struct mount *mnt = real_mount(vfsmnt);
50513 + bool slash = false;
50514 + int error = 0;
50515 +
50516 + while (dentry != root->dentry || vfsmnt != root->mnt) {
50517 + struct dentry * parent;
50518 +
50519 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
50520 + /* Global root? */
50521 + if (!mnt_has_parent(mnt)) {
50522 + goto out;
50523 + }
50524 + dentry = mnt->mnt_mountpoint;
50525 + mnt = mnt->mnt_parent;
50526 + vfsmnt = &mnt->mnt;
50527 + continue;
50528 + }
50529 + parent = dentry->d_parent;
50530 + prefetch(parent);
50531 + spin_lock(&dentry->d_lock);
50532 + error = prepend_name(buffer, buflen, &dentry->d_name);
50533 + spin_unlock(&dentry->d_lock);
50534 + if (!error)
50535 + error = prepend(buffer, buflen, "/", 1);
50536 + if (error)
50537 + break;
50538 +
50539 + slash = true;
50540 + dentry = parent;
50541 + }
50542 +
50543 +out:
50544 + if (!error && !slash)
50545 + error = prepend(buffer, buflen, "/", 1);
50546 +
50547 + return error;
50548 +}
50549 +
50550 +/* this must be called with vfsmount_lock and rename_lock held */
50551 +
50552 +static char *__our_d_path(const struct path *path, struct path *root,
50553 + char *buf, int buflen)
50554 +{
50555 + char *res = buf + buflen;
50556 + int error;
50557 +
50558 + prepend(&res, &buflen, "\0", 1);
50559 + error = prepend_path(path, root, &res, &buflen);
50560 + if (error)
50561 + return ERR_PTR(error);
50562 +
50563 + return res;
50564 +}
50565 +
50566 +static char *
50567 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
50568 +{
50569 + char *retval;
50570 +
50571 + retval = __our_d_path(path, root, buf, buflen);
50572 + if (unlikely(IS_ERR(retval)))
50573 + retval = strcpy(buf, "<path too long>");
50574 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
50575 + retval[1] = '\0';
50576 +
50577 + return retval;
50578 +}
50579 +
50580 +static char *
50581 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
50582 + char *buf, int buflen)
50583 +{
50584 + struct path path;
50585 + char *res;
50586 +
50587 + path.dentry = (struct dentry *)dentry;
50588 + path.mnt = (struct vfsmount *)vfsmnt;
50589 +
50590 + /* we can use real_root.dentry, real_root.mnt, because this is only called
50591 + by the RBAC system */
50592 + res = gen_full_path(&path, &real_root, buf, buflen);
50593 +
50594 + return res;
50595 +}
50596 +
50597 +static char *
50598 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
50599 + char *buf, int buflen)
50600 +{
50601 + char *res;
50602 + struct path path;
50603 + struct path root;
50604 + struct task_struct *reaper = init_pid_ns.child_reaper;
50605 +
50606 + path.dentry = (struct dentry *)dentry;
50607 + path.mnt = (struct vfsmount *)vfsmnt;
50608 +
50609 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
50610 + get_fs_root(reaper->fs, &root);
50611 +
50612 + write_seqlock(&rename_lock);
50613 + br_read_lock(vfsmount_lock);
50614 + res = gen_full_path(&path, &root, buf, buflen);
50615 + br_read_unlock(vfsmount_lock);
50616 + write_sequnlock(&rename_lock);
50617 +
50618 + path_put(&root);
50619 + return res;
50620 +}
50621 +
50622 +static char *
50623 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
50624 +{
50625 + char *ret;
50626 + write_seqlock(&rename_lock);
50627 + br_read_lock(vfsmount_lock);
50628 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
50629 + PAGE_SIZE);
50630 + br_read_unlock(vfsmount_lock);
50631 + write_sequnlock(&rename_lock);
50632 + return ret;
50633 +}
50634 +
50635 +static char *
50636 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
50637 +{
50638 + char *ret;
50639 + char *buf;
50640 + int buflen;
50641 +
50642 + write_seqlock(&rename_lock);
50643 + br_read_lock(vfsmount_lock);
50644 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
50645 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
50646 + buflen = (int)(ret - buf);
50647 + if (buflen >= 5)
50648 + prepend(&ret, &buflen, "/proc", 5);
50649 + else
50650 + ret = strcpy(buf, "<path too long>");
50651 + br_read_unlock(vfsmount_lock);
50652 + write_sequnlock(&rename_lock);
50653 + return ret;
50654 +}
50655 +
50656 +char *
50657 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
50658 +{
50659 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
50660 + PAGE_SIZE);
50661 +}
50662 +
50663 +char *
50664 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
50665 +{
50666 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
50667 + PAGE_SIZE);
50668 +}
50669 +
50670 +char *
50671 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
50672 +{
50673 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
50674 + PAGE_SIZE);
50675 +}
50676 +
50677 +char *
50678 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
50679 +{
50680 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
50681 + PAGE_SIZE);
50682 +}
50683 +
50684 +char *
50685 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
50686 +{
50687 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
50688 + PAGE_SIZE);
50689 +}
50690 +
50691 +__inline__ __u32
50692 +to_gr_audit(const __u32 reqmode)
50693 +{
50694 + /* masks off auditable permission flags, then shifts them to create
50695 + auditing flags, and adds the special case of append auditing if
50696 + we're requesting write */
50697 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
50698 +}
50699 +
50700 +struct acl_subject_label *
50701 +lookup_subject_map(const struct acl_subject_label *userp)
50702 +{
50703 + unsigned int index = shash(userp, subj_map_set.s_size);
50704 + struct subject_map *match;
50705 +
50706 + match = subj_map_set.s_hash[index];
50707 +
50708 + while (match && match->user != userp)
50709 + match = match->next;
50710 +
50711 + if (match != NULL)
50712 + return match->kernel;
50713 + else
50714 + return NULL;
50715 +}
50716 +
50717 +static void
50718 +insert_subj_map_entry(struct subject_map *subjmap)
50719 +{
50720 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
50721 + struct subject_map **curr;
50722 +
50723 + subjmap->prev = NULL;
50724 +
50725 + curr = &subj_map_set.s_hash[index];
50726 + if (*curr != NULL)
50727 + (*curr)->prev = subjmap;
50728 +
50729 + subjmap->next = *curr;
50730 + *curr = subjmap;
50731 +
50732 + return;
50733 +}
50734 +
50735 +static struct acl_role_label *
50736 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
50737 + const gid_t gid)
50738 +{
50739 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
50740 + struct acl_role_label *match;
50741 + struct role_allowed_ip *ipp;
50742 + unsigned int x;
50743 + u32 curr_ip = task->signal->curr_ip;
50744 +
50745 + task->signal->saved_ip = curr_ip;
50746 +
50747 + match = acl_role_set.r_hash[index];
50748 +
50749 + while (match) {
50750 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
50751 + for (x = 0; x < match->domain_child_num; x++) {
50752 + if (match->domain_children[x] == uid)
50753 + goto found;
50754 + }
50755 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
50756 + break;
50757 + match = match->next;
50758 + }
50759 +found:
50760 + if (match == NULL) {
50761 + try_group:
50762 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
50763 + match = acl_role_set.r_hash[index];
50764 +
50765 + while (match) {
50766 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
50767 + for (x = 0; x < match->domain_child_num; x++) {
50768 + if (match->domain_children[x] == gid)
50769 + goto found2;
50770 + }
50771 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
50772 + break;
50773 + match = match->next;
50774 + }
50775 +found2:
50776 + if (match == NULL)
50777 + match = default_role;
50778 + if (match->allowed_ips == NULL)
50779 + return match;
50780 + else {
50781 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
50782 + if (likely
50783 + ((ntohl(curr_ip) & ipp->netmask) ==
50784 + (ntohl(ipp->addr) & ipp->netmask)))
50785 + return match;
50786 + }
50787 + match = default_role;
50788 + }
50789 + } else if (match->allowed_ips == NULL) {
50790 + return match;
50791 + } else {
50792 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
50793 + if (likely
50794 + ((ntohl(curr_ip) & ipp->netmask) ==
50795 + (ntohl(ipp->addr) & ipp->netmask)))
50796 + return match;
50797 + }
50798 + goto try_group;
50799 + }
50800 +
50801 + return match;
50802 +}
50803 +
50804 +struct acl_subject_label *
50805 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
50806 + const struct acl_role_label *role)
50807 +{
50808 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
50809 + struct acl_subject_label *match;
50810 +
50811 + match = role->subj_hash[index];
50812 +
50813 + while (match && (match->inode != ino || match->device != dev ||
50814 + (match->mode & GR_DELETED))) {
50815 + match = match->next;
50816 + }
50817 +
50818 + if (match && !(match->mode & GR_DELETED))
50819 + return match;
50820 + else
50821 + return NULL;
50822 +}
50823 +
50824 +struct acl_subject_label *
50825 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
50826 + const struct acl_role_label *role)
50827 +{
50828 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
50829 + struct acl_subject_label *match;
50830 +
50831 + match = role->subj_hash[index];
50832 +
50833 + while (match && (match->inode != ino || match->device != dev ||
50834 + !(match->mode & GR_DELETED))) {
50835 + match = match->next;
50836 + }
50837 +
50838 + if (match && (match->mode & GR_DELETED))
50839 + return match;
50840 + else
50841 + return NULL;
50842 +}
50843 +
50844 +static struct acl_object_label *
50845 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
50846 + const struct acl_subject_label *subj)
50847 +{
50848 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
50849 + struct acl_object_label *match;
50850 +
50851 + match = subj->obj_hash[index];
50852 +
50853 + while (match && (match->inode != ino || match->device != dev ||
50854 + (match->mode & GR_DELETED))) {
50855 + match = match->next;
50856 + }
50857 +
50858 + if (match && !(match->mode & GR_DELETED))
50859 + return match;
50860 + else
50861 + return NULL;
50862 +}
50863 +
50864 +static struct acl_object_label *
50865 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
50866 + const struct acl_subject_label *subj)
50867 +{
50868 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
50869 + struct acl_object_label *match;
50870 +
50871 + match = subj->obj_hash[index];
50872 +
50873 + while (match && (match->inode != ino || match->device != dev ||
50874 + !(match->mode & GR_DELETED))) {
50875 + match = match->next;
50876 + }
50877 +
50878 + if (match && (match->mode & GR_DELETED))
50879 + return match;
50880 +
50881 + match = subj->obj_hash[index];
50882 +
50883 + while (match && (match->inode != ino || match->device != dev ||
50884 + (match->mode & GR_DELETED))) {
50885 + match = match->next;
50886 + }
50887 +
50888 + if (match && !(match->mode & GR_DELETED))
50889 + return match;
50890 + else
50891 + return NULL;
50892 +}
50893 +
50894 +static struct name_entry *
50895 +lookup_name_entry(const char *name)
50896 +{
50897 + unsigned int len = strlen(name);
50898 + unsigned int key = full_name_hash(name, len);
50899 + unsigned int index = key % name_set.n_size;
50900 + struct name_entry *match;
50901 +
50902 + match = name_set.n_hash[index];
50903 +
50904 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
50905 + match = match->next;
50906 +
50907 + return match;
50908 +}
50909 +
50910 +static struct name_entry *
50911 +lookup_name_entry_create(const char *name)
50912 +{
50913 + unsigned int len = strlen(name);
50914 + unsigned int key = full_name_hash(name, len);
50915 + unsigned int index = key % name_set.n_size;
50916 + struct name_entry *match;
50917 +
50918 + match = name_set.n_hash[index];
50919 +
50920 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
50921 + !match->deleted))
50922 + match = match->next;
50923 +
50924 + if (match && match->deleted)
50925 + return match;
50926 +
50927 + match = name_set.n_hash[index];
50928 +
50929 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
50930 + match->deleted))
50931 + match = match->next;
50932 +
50933 + if (match && !match->deleted)
50934 + return match;
50935 + else
50936 + return NULL;
50937 +}
50938 +
50939 +static struct inodev_entry *
50940 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
50941 +{
50942 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
50943 + struct inodev_entry *match;
50944 +
50945 + match = inodev_set.i_hash[index];
50946 +
50947 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
50948 + match = match->next;
50949 +
50950 + return match;
50951 +}
50952 +
50953 +static void
50954 +insert_inodev_entry(struct inodev_entry *entry)
50955 +{
50956 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
50957 + inodev_set.i_size);
50958 + struct inodev_entry **curr;
50959 +
50960 + entry->prev = NULL;
50961 +
50962 + curr = &inodev_set.i_hash[index];
50963 + if (*curr != NULL)
50964 + (*curr)->prev = entry;
50965 +
50966 + entry->next = *curr;
50967 + *curr = entry;
50968 +
50969 + return;
50970 +}
50971 +
50972 +static void
50973 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
50974 +{
50975 + unsigned int index =
50976 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
50977 + struct acl_role_label **curr;
50978 + struct acl_role_label *tmp, *tmp2;
50979 +
50980 + curr = &acl_role_set.r_hash[index];
50981 +
50982 + /* simple case, slot is empty, just set it to our role */
50983 + if (*curr == NULL) {
50984 + *curr = role;
50985 + } else {
50986 + /* example:
50987 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
50988 + 2 -> 3
50989 + */
50990 + /* first check to see if we can already be reached via this slot */
50991 + tmp = *curr;
50992 + while (tmp && tmp != role)
50993 + tmp = tmp->next;
50994 + if (tmp == role) {
50995 + /* we don't need to add ourselves to this slot's chain */
50996 + return;
50997 + }
50998 + /* we need to add ourselves to this chain, two cases */
50999 + if (role->next == NULL) {
51000 + /* simple case, append the current chain to our role */
51001 + role->next = *curr;
51002 + *curr = role;
51003 + } else {
51004 + /* 1 -> 2 -> 3 -> 4
51005 + 2 -> 3 -> 4
51006 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
51007 + */
51008 + /* trickier case: walk our role's chain until we find
51009 + the role for the start of the current slot's chain */
51010 + tmp = role;
51011 + tmp2 = *curr;
51012 + while (tmp->next && tmp->next != tmp2)
51013 + tmp = tmp->next;
51014 + if (tmp->next == tmp2) {
51015 + /* from example above, we found 3, so just
51016 + replace this slot's chain with ours */
51017 + *curr = role;
51018 + } else {
51019 + /* we didn't find a subset of our role's chain
51020 + in the current slot's chain, so append their
51021 + chain to ours, and set us as the first role in
51022 + the slot's chain
51023 +
51024 + we could fold this case with the case above,
51025 + but making it explicit for clarity
51026 + */
51027 + tmp->next = tmp2;
51028 + *curr = role;
51029 + }
51030 + }
51031 + }
51032 +
51033 + return;
51034 +}
51035 +
51036 +static void
51037 +insert_acl_role_label(struct acl_role_label *role)
51038 +{
51039 + int i;
51040 +
51041 + if (role_list == NULL) {
51042 + role_list = role;
51043 + role->prev = NULL;
51044 + } else {
51045 + role->prev = role_list;
51046 + role_list = role;
51047 + }
51048 +
51049 + /* used for hash chains */
51050 + role->next = NULL;
51051 +
51052 + if (role->roletype & GR_ROLE_DOMAIN) {
51053 + for (i = 0; i < role->domain_child_num; i++)
51054 + __insert_acl_role_label(role, role->domain_children[i]);
51055 + } else
51056 + __insert_acl_role_label(role, role->uidgid);
51057 +}
51058 +
51059 +static int
51060 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
51061 +{
51062 + struct name_entry **curr, *nentry;
51063 + struct inodev_entry *ientry;
51064 + unsigned int len = strlen(name);
51065 + unsigned int key = full_name_hash(name, len);
51066 + unsigned int index = key % name_set.n_size;
51067 +
51068 + curr = &name_set.n_hash[index];
51069 +
51070 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
51071 + curr = &((*curr)->next);
51072 +
51073 + if (*curr != NULL)
51074 + return 1;
51075 +
51076 + nentry = acl_alloc(sizeof (struct name_entry));
51077 + if (nentry == NULL)
51078 + return 0;
51079 + ientry = acl_alloc(sizeof (struct inodev_entry));
51080 + if (ientry == NULL)
51081 + return 0;
51082 + ientry->nentry = nentry;
51083 +
51084 + nentry->key = key;
51085 + nentry->name = name;
51086 + nentry->inode = inode;
51087 + nentry->device = device;
51088 + nentry->len = len;
51089 + nentry->deleted = deleted;
51090 +
51091 + nentry->prev = NULL;
51092 + curr = &name_set.n_hash[index];
51093 + if (*curr != NULL)
51094 + (*curr)->prev = nentry;
51095 + nentry->next = *curr;
51096 + *curr = nentry;
51097 +
51098 + /* insert us into the table searchable by inode/dev */
51099 + insert_inodev_entry(ientry);
51100 +
51101 + return 1;
51102 +}
51103 +
51104 +static void
51105 +insert_acl_obj_label(struct acl_object_label *obj,
51106 + struct acl_subject_label *subj)
51107 +{
51108 + unsigned int index =
51109 + fhash(obj->inode, obj->device, subj->obj_hash_size);
51110 + struct acl_object_label **curr;
51111 +
51112 +
51113 + obj->prev = NULL;
51114 +
51115 + curr = &subj->obj_hash[index];
51116 + if (*curr != NULL)
51117 + (*curr)->prev = obj;
51118 +
51119 + obj->next = *curr;
51120 + *curr = obj;
51121 +
51122 + return;
51123 +}
51124 +
51125 +static void
51126 +insert_acl_subj_label(struct acl_subject_label *obj,
51127 + struct acl_role_label *role)
51128 +{
51129 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
51130 + struct acl_subject_label **curr;
51131 +
51132 + obj->prev = NULL;
51133 +
51134 + curr = &role->subj_hash[index];
51135 + if (*curr != NULL)
51136 + (*curr)->prev = obj;
51137 +
51138 + obj->next = *curr;
51139 + *curr = obj;
51140 +
51141 + return;
51142 +}
51143 +
51144 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
51145 +
51146 +static void *
51147 +create_table(__u32 * len, int elementsize)
51148 +{
51149 + unsigned int table_sizes[] = {
51150 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
51151 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
51152 + 4194301, 8388593, 16777213, 33554393, 67108859
51153 + };
51154 + void *newtable = NULL;
51155 + unsigned int pwr = 0;
51156 +
51157 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
51158 + table_sizes[pwr] <= *len)
51159 + pwr++;
51160 +
51161 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
51162 + return newtable;
51163 +
51164 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
51165 + newtable =
51166 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
51167 + else
51168 + newtable = vmalloc(table_sizes[pwr] * elementsize);
51169 +
51170 + *len = table_sizes[pwr];
51171 +
51172 + return newtable;
51173 +}
51174 +
51175 +static int
51176 +init_variables(const struct gr_arg *arg)
51177 +{
51178 + struct task_struct *reaper = init_pid_ns.child_reaper;
51179 + unsigned int stacksize;
51180 +
51181 + subj_map_set.s_size = arg->role_db.num_subjects;
51182 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
51183 + name_set.n_size = arg->role_db.num_objects;
51184 + inodev_set.i_size = arg->role_db.num_objects;
51185 +
51186 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
51187 + !name_set.n_size || !inodev_set.i_size)
51188 + return 1;
51189 +
51190 + if (!gr_init_uidset())
51191 + return 1;
51192 +
51193 + /* set up the stack that holds allocation info */
51194 +
51195 + stacksize = arg->role_db.num_pointers + 5;
51196 +
51197 + if (!acl_alloc_stack_init(stacksize))
51198 + return 1;
51199 +
51200 + /* grab reference for the real root dentry and vfsmount */
51201 + get_fs_root(reaper->fs, &real_root);
51202 +
51203 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51204 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
51205 +#endif
51206 +
51207 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
51208 + if (fakefs_obj_rw == NULL)
51209 + return 1;
51210 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
51211 +
51212 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
51213 + if (fakefs_obj_rwx == NULL)
51214 + return 1;
51215 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
51216 +
51217 + subj_map_set.s_hash =
51218 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
51219 + acl_role_set.r_hash =
51220 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
51221 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
51222 + inodev_set.i_hash =
51223 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
51224 +
51225 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
51226 + !name_set.n_hash || !inodev_set.i_hash)
51227 + return 1;
51228 +
51229 + memset(subj_map_set.s_hash, 0,
51230 + sizeof(struct subject_map *) * subj_map_set.s_size);
51231 + memset(acl_role_set.r_hash, 0,
51232 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
51233 + memset(name_set.n_hash, 0,
51234 + sizeof (struct name_entry *) * name_set.n_size);
51235 + memset(inodev_set.i_hash, 0,
51236 + sizeof (struct inodev_entry *) * inodev_set.i_size);
51237 +
51238 + return 0;
51239 +}
51240 +
51241 +/* free information not needed after startup
51242 + currently contains user->kernel pointer mappings for subjects
51243 +*/
51244 +
51245 +static void
51246 +free_init_variables(void)
51247 +{
51248 + __u32 i;
51249 +
51250 + if (subj_map_set.s_hash) {
51251 + for (i = 0; i < subj_map_set.s_size; i++) {
51252 + if (subj_map_set.s_hash[i]) {
51253 + kfree(subj_map_set.s_hash[i]);
51254 + subj_map_set.s_hash[i] = NULL;
51255 + }
51256 + }
51257 +
51258 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
51259 + PAGE_SIZE)
51260 + kfree(subj_map_set.s_hash);
51261 + else
51262 + vfree(subj_map_set.s_hash);
51263 + }
51264 +
51265 + return;
51266 +}
51267 +
51268 +static void
51269 +free_variables(void)
51270 +{
51271 + struct acl_subject_label *s;
51272 + struct acl_role_label *r;
51273 + struct task_struct *task, *task2;
51274 + unsigned int x;
51275 +
51276 + gr_clear_learn_entries();
51277 +
51278 + read_lock(&tasklist_lock);
51279 + do_each_thread(task2, task) {
51280 + task->acl_sp_role = 0;
51281 + task->acl_role_id = 0;
51282 + task->acl = NULL;
51283 + task->role = NULL;
51284 + } while_each_thread(task2, task);
51285 + read_unlock(&tasklist_lock);
51286 +
51287 + /* release the reference to the real root dentry and vfsmount */
51288 + path_put(&real_root);
51289 + memset(&real_root, 0, sizeof(real_root));
51290 +
51291 + /* free all object hash tables */
51292 +
51293 + FOR_EACH_ROLE_START(r)
51294 + if (r->subj_hash == NULL)
51295 + goto next_role;
51296 + FOR_EACH_SUBJECT_START(r, s, x)
51297 + if (s->obj_hash == NULL)
51298 + break;
51299 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51300 + kfree(s->obj_hash);
51301 + else
51302 + vfree(s->obj_hash);
51303 + FOR_EACH_SUBJECT_END(s, x)
51304 + FOR_EACH_NESTED_SUBJECT_START(r, s)
51305 + if (s->obj_hash == NULL)
51306 + break;
51307 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51308 + kfree(s->obj_hash);
51309 + else
51310 + vfree(s->obj_hash);
51311 + FOR_EACH_NESTED_SUBJECT_END(s)
51312 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
51313 + kfree(r->subj_hash);
51314 + else
51315 + vfree(r->subj_hash);
51316 + r->subj_hash = NULL;
51317 +next_role:
51318 + FOR_EACH_ROLE_END(r)
51319 +
51320 + acl_free_all();
51321 +
51322 + if (acl_role_set.r_hash) {
51323 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
51324 + PAGE_SIZE)
51325 + kfree(acl_role_set.r_hash);
51326 + else
51327 + vfree(acl_role_set.r_hash);
51328 + }
51329 + if (name_set.n_hash) {
51330 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
51331 + PAGE_SIZE)
51332 + kfree(name_set.n_hash);
51333 + else
51334 + vfree(name_set.n_hash);
51335 + }
51336 +
51337 + if (inodev_set.i_hash) {
51338 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
51339 + PAGE_SIZE)
51340 + kfree(inodev_set.i_hash);
51341 + else
51342 + vfree(inodev_set.i_hash);
51343 + }
51344 +
51345 + gr_free_uidset();
51346 +
51347 + memset(&name_set, 0, sizeof (struct name_db));
51348 + memset(&inodev_set, 0, sizeof (struct inodev_db));
51349 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
51350 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
51351 +
51352 + default_role = NULL;
51353 + kernel_role = NULL;
51354 + role_list = NULL;
51355 +
51356 + return;
51357 +}
51358 +
51359 +static __u32
51360 +count_user_objs(struct acl_object_label *userp)
51361 +{
51362 + struct acl_object_label o_tmp;
51363 + __u32 num = 0;
51364 +
51365 + while (userp) {
51366 + if (copy_from_user(&o_tmp, userp,
51367 + sizeof (struct acl_object_label)))
51368 + break;
51369 +
51370 + userp = o_tmp.prev;
51371 + num++;
51372 + }
51373 +
51374 + return num;
51375 +}
51376 +
51377 +static struct acl_subject_label *
51378 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
51379 +
51380 +static int
51381 +copy_user_glob(struct acl_object_label *obj)
51382 +{
51383 + struct acl_object_label *g_tmp, **guser;
51384 + unsigned int len;
51385 + char *tmp;
51386 +
51387 + if (obj->globbed == NULL)
51388 + return 0;
51389 +
51390 + guser = &obj->globbed;
51391 + while (*guser) {
51392 + g_tmp = (struct acl_object_label *)
51393 + acl_alloc(sizeof (struct acl_object_label));
51394 + if (g_tmp == NULL)
51395 + return -ENOMEM;
51396 +
51397 + if (copy_from_user(g_tmp, *guser,
51398 + sizeof (struct acl_object_label)))
51399 + return -EFAULT;
51400 +
51401 + len = strnlen_user(g_tmp->filename, PATH_MAX);
51402 +
51403 + if (!len || len >= PATH_MAX)
51404 + return -EINVAL;
51405 +
51406 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51407 + return -ENOMEM;
51408 +
51409 + if (copy_from_user(tmp, g_tmp->filename, len))
51410 + return -EFAULT;
51411 + tmp[len-1] = '\0';
51412 + g_tmp->filename = tmp;
51413 +
51414 + *guser = g_tmp;
51415 + guser = &(g_tmp->next);
51416 + }
51417 +
51418 + return 0;
51419 +}
51420 +
51421 +static int
51422 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
51423 + struct acl_role_label *role)
51424 +{
51425 + struct acl_object_label *o_tmp;
51426 + unsigned int len;
51427 + int ret;
51428 + char *tmp;
51429 +
51430 + while (userp) {
51431 + if ((o_tmp = (struct acl_object_label *)
51432 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
51433 + return -ENOMEM;
51434 +
51435 + if (copy_from_user(o_tmp, userp,
51436 + sizeof (struct acl_object_label)))
51437 + return -EFAULT;
51438 +
51439 + userp = o_tmp->prev;
51440 +
51441 + len = strnlen_user(o_tmp->filename, PATH_MAX);
51442 +
51443 + if (!len || len >= PATH_MAX)
51444 + return -EINVAL;
51445 +
51446 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51447 + return -ENOMEM;
51448 +
51449 + if (copy_from_user(tmp, o_tmp->filename, len))
51450 + return -EFAULT;
51451 + tmp[len-1] = '\0';
51452 + o_tmp->filename = tmp;
51453 +
51454 + insert_acl_obj_label(o_tmp, subj);
51455 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
51456 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
51457 + return -ENOMEM;
51458 +
51459 + ret = copy_user_glob(o_tmp);
51460 + if (ret)
51461 + return ret;
51462 +
51463 + if (o_tmp->nested) {
51464 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
51465 + if (IS_ERR(o_tmp->nested))
51466 + return PTR_ERR(o_tmp->nested);
51467 +
51468 + /* insert into nested subject list */
51469 + o_tmp->nested->next = role->hash->first;
51470 + role->hash->first = o_tmp->nested;
51471 + }
51472 + }
51473 +
51474 + return 0;
51475 +}
51476 +
51477 +static __u32
51478 +count_user_subjs(struct acl_subject_label *userp)
51479 +{
51480 + struct acl_subject_label s_tmp;
51481 + __u32 num = 0;
51482 +
51483 + while (userp) {
51484 + if (copy_from_user(&s_tmp, userp,
51485 + sizeof (struct acl_subject_label)))
51486 + break;
51487 +
51488 + userp = s_tmp.prev;
51489 + /* do not count nested subjects against this count, since
51490 + they are not included in the hash table, but are
51491 + attached to objects. We have already counted
51492 + the subjects in userspace for the allocation
51493 + stack
51494 + */
51495 + if (!(s_tmp.mode & GR_NESTED))
51496 + num++;
51497 + }
51498 +
51499 + return num;
51500 +}
51501 +
51502 +static int
51503 +copy_user_allowedips(struct acl_role_label *rolep)
51504 +{
51505 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
51506 +
51507 + ruserip = rolep->allowed_ips;
51508 +
51509 + while (ruserip) {
51510 + rlast = rtmp;
51511 +
51512 + if ((rtmp = (struct role_allowed_ip *)
51513 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
51514 + return -ENOMEM;
51515 +
51516 + if (copy_from_user(rtmp, ruserip,
51517 + sizeof (struct role_allowed_ip)))
51518 + return -EFAULT;
51519 +
51520 + ruserip = rtmp->prev;
51521 +
51522 + if (!rlast) {
51523 + rtmp->prev = NULL;
51524 + rolep->allowed_ips = rtmp;
51525 + } else {
51526 + rlast->next = rtmp;
51527 + rtmp->prev = rlast;
51528 + }
51529 +
51530 + if (!ruserip)
51531 + rtmp->next = NULL;
51532 + }
51533 +
51534 + return 0;
51535 +}
51536 +
51537 +static int
51538 +copy_user_transitions(struct acl_role_label *rolep)
51539 +{
51540 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
51541 +
51542 + unsigned int len;
51543 + char *tmp;
51544 +
51545 + rusertp = rolep->transitions;
51546 +
51547 + while (rusertp) {
51548 + rlast = rtmp;
51549 +
51550 + if ((rtmp = (struct role_transition *)
51551 + acl_alloc(sizeof (struct role_transition))) == NULL)
51552 + return -ENOMEM;
51553 +
51554 + if (copy_from_user(rtmp, rusertp,
51555 + sizeof (struct role_transition)))
51556 + return -EFAULT;
51557 +
51558 + rusertp = rtmp->prev;
51559 +
51560 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
51561 +
51562 + if (!len || len >= GR_SPROLE_LEN)
51563 + return -EINVAL;
51564 +
51565 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51566 + return -ENOMEM;
51567 +
51568 + if (copy_from_user(tmp, rtmp->rolename, len))
51569 + return -EFAULT;
51570 + tmp[len-1] = '\0';
51571 + rtmp->rolename = tmp;
51572 +
51573 + if (!rlast) {
51574 + rtmp->prev = NULL;
51575 + rolep->transitions = rtmp;
51576 + } else {
51577 + rlast->next = rtmp;
51578 + rtmp->prev = rlast;
51579 + }
51580 +
51581 + if (!rusertp)
51582 + rtmp->next = NULL;
51583 + }
51584 +
51585 + return 0;
51586 +}
51587 +
51588 +static struct acl_subject_label *
51589 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
51590 +{
51591 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
51592 + unsigned int len;
51593 + char *tmp;
51594 + __u32 num_objs;
51595 + struct acl_ip_label **i_tmp, *i_utmp2;
51596 + struct gr_hash_struct ghash;
51597 + struct subject_map *subjmap;
51598 + unsigned int i_num;
51599 + int err;
51600 +
51601 + s_tmp = lookup_subject_map(userp);
51602 +
51603 + /* we've already copied this subject into the kernel, just return
51604 + the reference to it, and don't copy it over again
51605 + */
51606 + if (s_tmp)
51607 + return(s_tmp);
51608 +
51609 + if ((s_tmp = (struct acl_subject_label *)
51610 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
51611 + return ERR_PTR(-ENOMEM);
51612 +
51613 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
51614 + if (subjmap == NULL)
51615 + return ERR_PTR(-ENOMEM);
51616 +
51617 + subjmap->user = userp;
51618 + subjmap->kernel = s_tmp;
51619 + insert_subj_map_entry(subjmap);
51620 +
51621 + if (copy_from_user(s_tmp, userp,
51622 + sizeof (struct acl_subject_label)))
51623 + return ERR_PTR(-EFAULT);
51624 +
51625 + len = strnlen_user(s_tmp->filename, PATH_MAX);
51626 +
51627 + if (!len || len >= PATH_MAX)
51628 + return ERR_PTR(-EINVAL);
51629 +
51630 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51631 + return ERR_PTR(-ENOMEM);
51632 +
51633 + if (copy_from_user(tmp, s_tmp->filename, len))
51634 + return ERR_PTR(-EFAULT);
51635 + tmp[len-1] = '\0';
51636 + s_tmp->filename = tmp;
51637 +
51638 + if (!strcmp(s_tmp->filename, "/"))
51639 + role->root_label = s_tmp;
51640 +
51641 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
51642 + return ERR_PTR(-EFAULT);
51643 +
51644 + /* copy user and group transition tables */
51645 +
51646 + if (s_tmp->user_trans_num) {
51647 + uid_t *uidlist;
51648 +
51649 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
51650 + if (uidlist == NULL)
51651 + return ERR_PTR(-ENOMEM);
51652 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
51653 + return ERR_PTR(-EFAULT);
51654 +
51655 + s_tmp->user_transitions = uidlist;
51656 + }
51657 +
51658 + if (s_tmp->group_trans_num) {
51659 + gid_t *gidlist;
51660 +
51661 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
51662 + if (gidlist == NULL)
51663 + return ERR_PTR(-ENOMEM);
51664 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
51665 + return ERR_PTR(-EFAULT);
51666 +
51667 + s_tmp->group_transitions = gidlist;
51668 + }
51669 +
51670 + /* set up object hash table */
51671 + num_objs = count_user_objs(ghash.first);
51672 +
51673 + s_tmp->obj_hash_size = num_objs;
51674 + s_tmp->obj_hash =
51675 + (struct acl_object_label **)
51676 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
51677 +
51678 + if (!s_tmp->obj_hash)
51679 + return ERR_PTR(-ENOMEM);
51680 +
51681 + memset(s_tmp->obj_hash, 0,
51682 + s_tmp->obj_hash_size *
51683 + sizeof (struct acl_object_label *));
51684 +
51685 + /* add in objects */
51686 + err = copy_user_objs(ghash.first, s_tmp, role);
51687 +
51688 + if (err)
51689 + return ERR_PTR(err);
51690 +
51691 + /* set pointer for parent subject */
51692 + if (s_tmp->parent_subject) {
51693 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
51694 +
51695 + if (IS_ERR(s_tmp2))
51696 + return s_tmp2;
51697 +
51698 + s_tmp->parent_subject = s_tmp2;
51699 + }
51700 +
51701 + /* add in ip acls */
51702 +
51703 + if (!s_tmp->ip_num) {
51704 + s_tmp->ips = NULL;
51705 + goto insert;
51706 + }
51707 +
51708 + i_tmp =
51709 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
51710 + sizeof (struct acl_ip_label *));
51711 +
51712 + if (!i_tmp)
51713 + return ERR_PTR(-ENOMEM);
51714 +
51715 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
51716 + *(i_tmp + i_num) =
51717 + (struct acl_ip_label *)
51718 + acl_alloc(sizeof (struct acl_ip_label));
51719 + if (!*(i_tmp + i_num))
51720 + return ERR_PTR(-ENOMEM);
51721 +
51722 + if (copy_from_user
51723 + (&i_utmp2, s_tmp->ips + i_num,
51724 + sizeof (struct acl_ip_label *)))
51725 + return ERR_PTR(-EFAULT);
51726 +
51727 + if (copy_from_user
51728 + (*(i_tmp + i_num), i_utmp2,
51729 + sizeof (struct acl_ip_label)))
51730 + return ERR_PTR(-EFAULT);
51731 +
51732 + if ((*(i_tmp + i_num))->iface == NULL)
51733 + continue;
51734 +
51735 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
51736 + if (!len || len >= IFNAMSIZ)
51737 + return ERR_PTR(-EINVAL);
51738 + tmp = acl_alloc(len);
51739 + if (tmp == NULL)
51740 + return ERR_PTR(-ENOMEM);
51741 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
51742 + return ERR_PTR(-EFAULT);
51743 + (*(i_tmp + i_num))->iface = tmp;
51744 + }
51745 +
51746 + s_tmp->ips = i_tmp;
51747 +
51748 +insert:
51749 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
51750 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
51751 + return ERR_PTR(-ENOMEM);
51752 +
51753 + return s_tmp;
51754 +}
51755 +
51756 +static int
51757 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
51758 +{
51759 + struct acl_subject_label s_pre;
51760 + struct acl_subject_label * ret;
51761 + int err;
51762 +
51763 + while (userp) {
51764 + if (copy_from_user(&s_pre, userp,
51765 + sizeof (struct acl_subject_label)))
51766 + return -EFAULT;
51767 +
51768 + /* do not add nested subjects here, add
51769 + while parsing objects
51770 + */
51771 +
51772 + if (s_pre.mode & GR_NESTED) {
51773 + userp = s_pre.prev;
51774 + continue;
51775 + }
51776 +
51777 + ret = do_copy_user_subj(userp, role);
51778 +
51779 + err = PTR_ERR(ret);
51780 + if (IS_ERR(ret))
51781 + return err;
51782 +
51783 + insert_acl_subj_label(ret, role);
51784 +
51785 + userp = s_pre.prev;
51786 + }
51787 +
51788 + return 0;
51789 +}
51790 +
51791 +static int
51792 +copy_user_acl(struct gr_arg *arg)
51793 +{
51794 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
51795 + struct sprole_pw *sptmp;
51796 + struct gr_hash_struct *ghash;
51797 + uid_t *domainlist;
51798 + unsigned int r_num;
51799 + unsigned int len;
51800 + char *tmp;
51801 + int err = 0;
51802 + __u16 i;
51803 + __u32 num_subjs;
51804 +
51805 + /* we need a default and kernel role */
51806 + if (arg->role_db.num_roles < 2)
51807 + return -EINVAL;
51808 +
51809 + /* copy special role authentication info from userspace */
51810 +
51811 + num_sprole_pws = arg->num_sprole_pws;
51812 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
51813 +
51814 + if (!acl_special_roles && num_sprole_pws)
51815 + return -ENOMEM;
51816 +
51817 + for (i = 0; i < num_sprole_pws; i++) {
51818 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
51819 + if (!sptmp)
51820 + return -ENOMEM;
51821 + if (copy_from_user(sptmp, arg->sprole_pws + i,
51822 + sizeof (struct sprole_pw)))
51823 + return -EFAULT;
51824 +
51825 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
51826 +
51827 + if (!len || len >= GR_SPROLE_LEN)
51828 + return -EINVAL;
51829 +
51830 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51831 + return -ENOMEM;
51832 +
51833 + if (copy_from_user(tmp, sptmp->rolename, len))
51834 + return -EFAULT;
51835 +
51836 + tmp[len-1] = '\0';
51837 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51838 + printk(KERN_ALERT "Copying special role %s\n", tmp);
51839 +#endif
51840 + sptmp->rolename = tmp;
51841 + acl_special_roles[i] = sptmp;
51842 + }
51843 +
51844 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
51845 +
51846 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
51847 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
51848 +
51849 + if (!r_tmp)
51850 + return -ENOMEM;
51851 +
51852 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
51853 + sizeof (struct acl_role_label *)))
51854 + return -EFAULT;
51855 +
51856 + if (copy_from_user(r_tmp, r_utmp2,
51857 + sizeof (struct acl_role_label)))
51858 + return -EFAULT;
51859 +
51860 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
51861 +
51862 + if (!len || len >= PATH_MAX)
51863 + return -EINVAL;
51864 +
51865 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51866 + return -ENOMEM;
51867 +
51868 + if (copy_from_user(tmp, r_tmp->rolename, len))
51869 + return -EFAULT;
51870 +
51871 + tmp[len-1] = '\0';
51872 + r_tmp->rolename = tmp;
51873 +
51874 + if (!strcmp(r_tmp->rolename, "default")
51875 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
51876 + default_role = r_tmp;
51877 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
51878 + kernel_role = r_tmp;
51879 + }
51880 +
51881 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
51882 + return -ENOMEM;
51883 +
51884 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
51885 + return -EFAULT;
51886 +
51887 + r_tmp->hash = ghash;
51888 +
51889 + num_subjs = count_user_subjs(r_tmp->hash->first);
51890 +
51891 + r_tmp->subj_hash_size = num_subjs;
51892 + r_tmp->subj_hash =
51893 + (struct acl_subject_label **)
51894 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
51895 +
51896 + if (!r_tmp->subj_hash)
51897 + return -ENOMEM;
51898 +
51899 + err = copy_user_allowedips(r_tmp);
51900 + if (err)
51901 + return err;
51902 +
51903 + /* copy domain info */
51904 + if (r_tmp->domain_children != NULL) {
51905 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
51906 + if (domainlist == NULL)
51907 + return -ENOMEM;
51908 +
51909 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
51910 + return -EFAULT;
51911 +
51912 + r_tmp->domain_children = domainlist;
51913 + }
51914 +
51915 + err = copy_user_transitions(r_tmp);
51916 + if (err)
51917 + return err;
51918 +
51919 + memset(r_tmp->subj_hash, 0,
51920 + r_tmp->subj_hash_size *
51921 + sizeof (struct acl_subject_label *));
51922 +
51923 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
51924 +
51925 + if (err)
51926 + return err;
51927 +
51928 + /* set nested subject list to null */
51929 + r_tmp->hash->first = NULL;
51930 +
51931 + insert_acl_role_label(r_tmp);
51932 + }
51933 +
51934 + if (default_role == NULL || kernel_role == NULL)
51935 + return -EINVAL;
51936 +
51937 + return err;
51938 +}
51939 +
51940 +static int
51941 +gracl_init(struct gr_arg *args)
51942 +{
51943 + int error = 0;
51944 +
51945 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
51946 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
51947 +
51948 + if (init_variables(args)) {
51949 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
51950 + error = -ENOMEM;
51951 + free_variables();
51952 + goto out;
51953 + }
51954 +
51955 + error = copy_user_acl(args);
51956 + free_init_variables();
51957 + if (error) {
51958 + free_variables();
51959 + goto out;
51960 + }
51961 +
51962 + if ((error = gr_set_acls(0))) {
51963 + free_variables();
51964 + goto out;
51965 + }
51966 +
51967 + pax_open_kernel();
51968 + gr_status |= GR_READY;
51969 + pax_close_kernel();
51970 +
51971 + out:
51972 + return error;
51973 +}
51974 +
51975 +/* derived from glibc fnmatch() 0: match, 1: no match*/
51976 +
51977 +static int
51978 +glob_match(const char *p, const char *n)
51979 +{
51980 + char c;
51981 +
51982 + while ((c = *p++) != '\0') {
51983 + switch (c) {
51984 + case '?':
51985 + if (*n == '\0')
51986 + return 1;
51987 + else if (*n == '/')
51988 + return 1;
51989 + break;
51990 + case '\\':
51991 + if (*n != c)
51992 + return 1;
51993 + break;
51994 + case '*':
51995 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
51996 + if (*n == '/')
51997 + return 1;
51998 + else if (c == '?') {
51999 + if (*n == '\0')
52000 + return 1;
52001 + else
52002 + ++n;
52003 + }
52004 + }
52005 + if (c == '\0') {
52006 + return 0;
52007 + } else {
52008 + const char *endp;
52009 +
52010 + if ((endp = strchr(n, '/')) == NULL)
52011 + endp = n + strlen(n);
52012 +
52013 + if (c == '[') {
52014 + for (--p; n < endp; ++n)
52015 + if (!glob_match(p, n))
52016 + return 0;
52017 + } else if (c == '/') {
52018 + while (*n != '\0' && *n != '/')
52019 + ++n;
52020 + if (*n == '/' && !glob_match(p, n + 1))
52021 + return 0;
52022 + } else {
52023 + for (--p; n < endp; ++n)
52024 + if (*n == c && !glob_match(p, n))
52025 + return 0;
52026 + }
52027 +
52028 + return 1;
52029 + }
52030 + case '[':
52031 + {
52032 + int not;
52033 + char cold;
52034 +
52035 + if (*n == '\0' || *n == '/')
52036 + return 1;
52037 +
52038 + not = (*p == '!' || *p == '^');
52039 + if (not)
52040 + ++p;
52041 +
52042 + c = *p++;
52043 + for (;;) {
52044 + unsigned char fn = (unsigned char)*n;
52045 +
52046 + if (c == '\0')
52047 + return 1;
52048 + else {
52049 + if (c == fn)
52050 + goto matched;
52051 + cold = c;
52052 + c = *p++;
52053 +
52054 + if (c == '-' && *p != ']') {
52055 + unsigned char cend = *p++;
52056 +
52057 + if (cend == '\0')
52058 + return 1;
52059 +
52060 + if (cold <= fn && fn <= cend)
52061 + goto matched;
52062 +
52063 + c = *p++;
52064 + }
52065 + }
52066 +
52067 + if (c == ']')
52068 + break;
52069 + }
52070 + if (!not)
52071 + return 1;
52072 + break;
52073 + matched:
52074 + while (c != ']') {
52075 + if (c == '\0')
52076 + return 1;
52077 +
52078 + c = *p++;
52079 + }
52080 + if (not)
52081 + return 1;
52082 + }
52083 + break;
52084 + default:
52085 + if (c != *n)
52086 + return 1;
52087 + }
52088 +
52089 + ++n;
52090 + }
52091 +
52092 + if (*n == '\0')
52093 + return 0;
52094 +
52095 + if (*n == '/')
52096 + return 0;
52097 +
52098 + return 1;
52099 +}
52100 +
52101 +static struct acl_object_label *
52102 +chk_glob_label(struct acl_object_label *globbed,
52103 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
52104 +{
52105 + struct acl_object_label *tmp;
52106 +
52107 + if (*path == NULL)
52108 + *path = gr_to_filename_nolock(dentry, mnt);
52109 +
52110 + tmp = globbed;
52111 +
52112 + while (tmp) {
52113 + if (!glob_match(tmp->filename, *path))
52114 + return tmp;
52115 + tmp = tmp->next;
52116 + }
52117 +
52118 + return NULL;
52119 +}
52120 +
52121 +static struct acl_object_label *
52122 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52123 + const ino_t curr_ino, const dev_t curr_dev,
52124 + const struct acl_subject_label *subj, char **path, const int checkglob)
52125 +{
52126 + struct acl_subject_label *tmpsubj;
52127 + struct acl_object_label *retval;
52128 + struct acl_object_label *retval2;
52129 +
52130 + tmpsubj = (struct acl_subject_label *) subj;
52131 + read_lock(&gr_inode_lock);
52132 + do {
52133 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
52134 + if (retval) {
52135 + if (checkglob && retval->globbed) {
52136 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
52137 + if (retval2)
52138 + retval = retval2;
52139 + }
52140 + break;
52141 + }
52142 + } while ((tmpsubj = tmpsubj->parent_subject));
52143 + read_unlock(&gr_inode_lock);
52144 +
52145 + return retval;
52146 +}
52147 +
52148 +static __inline__ struct acl_object_label *
52149 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52150 + struct dentry *curr_dentry,
52151 + const struct acl_subject_label *subj, char **path, const int checkglob)
52152 +{
52153 + int newglob = checkglob;
52154 + ino_t inode;
52155 + dev_t device;
52156 +
52157 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
52158 + as we don't want a / * rule to match instead of the / object
52159 + don't do this for create lookups that call this function though, since they're looking up
52160 + on the parent and thus need globbing checks on all paths
52161 + */
52162 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
52163 + newglob = GR_NO_GLOB;
52164 +
52165 + spin_lock(&curr_dentry->d_lock);
52166 + inode = curr_dentry->d_inode->i_ino;
52167 + device = __get_dev(curr_dentry);
52168 + spin_unlock(&curr_dentry->d_lock);
52169 +
52170 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
52171 +}
52172 +
52173 +static struct acl_object_label *
52174 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52175 + const struct acl_subject_label *subj, char *path, const int checkglob)
52176 +{
52177 + struct dentry *dentry = (struct dentry *) l_dentry;
52178 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52179 + struct mount *real_mnt = real_mount(mnt);
52180 + struct acl_object_label *retval;
52181 + struct dentry *parent;
52182 +
52183 + write_seqlock(&rename_lock);
52184 + br_read_lock(vfsmount_lock);
52185 +
52186 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
52187 +#ifdef CONFIG_NET
52188 + mnt == sock_mnt ||
52189 +#endif
52190 +#ifdef CONFIG_HUGETLBFS
52191 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
52192 +#endif
52193 + /* ignore Eric Biederman */
52194 + IS_PRIVATE(l_dentry->d_inode))) {
52195 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
52196 + goto out;
52197 + }
52198 +
52199 + for (;;) {
52200 + if (dentry == real_root.dentry && mnt == real_root.mnt)
52201 + break;
52202 +
52203 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52204 + if (!mnt_has_parent(real_mnt))
52205 + break;
52206 +
52207 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52208 + if (retval != NULL)
52209 + goto out;
52210 +
52211 + dentry = real_mnt->mnt_mountpoint;
52212 + real_mnt = real_mnt->mnt_parent;
52213 + mnt = &real_mnt->mnt;
52214 + continue;
52215 + }
52216 +
52217 + parent = dentry->d_parent;
52218 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52219 + if (retval != NULL)
52220 + goto out;
52221 +
52222 + dentry = parent;
52223 + }
52224 +
52225 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52226 +
52227 + /* real_root is pinned so we don't have to hold a reference */
52228 + if (retval == NULL)
52229 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
52230 +out:
52231 + br_read_unlock(vfsmount_lock);
52232 + write_sequnlock(&rename_lock);
52233 +
52234 + BUG_ON(retval == NULL);
52235 +
52236 + return retval;
52237 +}
52238 +
52239 +static __inline__ struct acl_object_label *
52240 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52241 + const struct acl_subject_label *subj)
52242 +{
52243 + char *path = NULL;
52244 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
52245 +}
52246 +
52247 +static __inline__ struct acl_object_label *
52248 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52249 + const struct acl_subject_label *subj)
52250 +{
52251 + char *path = NULL;
52252 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
52253 +}
52254 +
52255 +static __inline__ struct acl_object_label *
52256 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52257 + const struct acl_subject_label *subj, char *path)
52258 +{
52259 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
52260 +}
52261 +
52262 +static struct acl_subject_label *
52263 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52264 + const struct acl_role_label *role)
52265 +{
52266 + struct dentry *dentry = (struct dentry *) l_dentry;
52267 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52268 + struct mount *real_mnt = real_mount(mnt);
52269 + struct acl_subject_label *retval;
52270 + struct dentry *parent;
52271 +
52272 + write_seqlock(&rename_lock);
52273 + br_read_lock(vfsmount_lock);
52274 +
52275 + for (;;) {
52276 + if (dentry == real_root.dentry && mnt == real_root.mnt)
52277 + break;
52278 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52279 + if (!mnt_has_parent(real_mnt))
52280 + break;
52281 +
52282 + spin_lock(&dentry->d_lock);
52283 + read_lock(&gr_inode_lock);
52284 + retval =
52285 + lookup_acl_subj_label(dentry->d_inode->i_ino,
52286 + __get_dev(dentry), role);
52287 + read_unlock(&gr_inode_lock);
52288 + spin_unlock(&dentry->d_lock);
52289 + if (retval != NULL)
52290 + goto out;
52291 +
52292 + dentry = real_mnt->mnt_mountpoint;
52293 + real_mnt = real_mnt->mnt_parent;
52294 + mnt = &real_mnt->mnt;
52295 + continue;
52296 + }
52297 +
52298 + spin_lock(&dentry->d_lock);
52299 + read_lock(&gr_inode_lock);
52300 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52301 + __get_dev(dentry), role);
52302 + read_unlock(&gr_inode_lock);
52303 + parent = dentry->d_parent;
52304 + spin_unlock(&dentry->d_lock);
52305 +
52306 + if (retval != NULL)
52307 + goto out;
52308 +
52309 + dentry = parent;
52310 + }
52311 +
52312 + spin_lock(&dentry->d_lock);
52313 + read_lock(&gr_inode_lock);
52314 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52315 + __get_dev(dentry), role);
52316 + read_unlock(&gr_inode_lock);
52317 + spin_unlock(&dentry->d_lock);
52318 +
52319 + if (unlikely(retval == NULL)) {
52320 + /* real_root is pinned, we don't need to hold a reference */
52321 + read_lock(&gr_inode_lock);
52322 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
52323 + __get_dev(real_root.dentry), role);
52324 + read_unlock(&gr_inode_lock);
52325 + }
52326 +out:
52327 + br_read_unlock(vfsmount_lock);
52328 + write_sequnlock(&rename_lock);
52329 +
52330 + BUG_ON(retval == NULL);
52331 +
52332 + return retval;
52333 +}
52334 +
52335 +static void
52336 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
52337 +{
52338 + struct task_struct *task = current;
52339 + const struct cred *cred = current_cred();
52340 +
52341 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
52342 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52343 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52344 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
52345 +
52346 + return;
52347 +}
52348 +
52349 +static void
52350 +gr_log_learn_id_change(const char type, const unsigned int real,
52351 + const unsigned int effective, const unsigned int fs)
52352 +{
52353 + struct task_struct *task = current;
52354 + const struct cred *cred = current_cred();
52355 +
52356 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
52357 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52358 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52359 + type, real, effective, fs, &task->signal->saved_ip);
52360 +
52361 + return;
52362 +}
52363 +
52364 +__u32
52365 +gr_search_file(const struct dentry * dentry, const __u32 mode,
52366 + const struct vfsmount * mnt)
52367 +{
52368 + __u32 retval = mode;
52369 + struct acl_subject_label *curracl;
52370 + struct acl_object_label *currobj;
52371 +
52372 + if (unlikely(!(gr_status & GR_READY)))
52373 + return (mode & ~GR_AUDITS);
52374 +
52375 + curracl = current->acl;
52376 +
52377 + currobj = chk_obj_label(dentry, mnt, curracl);
52378 + retval = currobj->mode & mode;
52379 +
52380 + /* if we're opening a specified transfer file for writing
52381 + (e.g. /dev/initctl), then transfer our role to init
52382 + */
52383 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
52384 + current->role->roletype & GR_ROLE_PERSIST)) {
52385 + struct task_struct *task = init_pid_ns.child_reaper;
52386 +
52387 + if (task->role != current->role) {
52388 + task->acl_sp_role = 0;
52389 + task->acl_role_id = current->acl_role_id;
52390 + task->role = current->role;
52391 + rcu_read_lock();
52392 + read_lock(&grsec_exec_file_lock);
52393 + gr_apply_subject_to_task(task);
52394 + read_unlock(&grsec_exec_file_lock);
52395 + rcu_read_unlock();
52396 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
52397 + }
52398 + }
52399 +
52400 + if (unlikely
52401 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
52402 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
52403 + __u32 new_mode = mode;
52404 +
52405 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
52406 +
52407 + retval = new_mode;
52408 +
52409 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
52410 + new_mode |= GR_INHERIT;
52411 +
52412 + if (!(mode & GR_NOLEARN))
52413 + gr_log_learn(dentry, mnt, new_mode);
52414 + }
52415 +
52416 + return retval;
52417 +}
52418 +
52419 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
52420 + const struct dentry *parent,
52421 + const struct vfsmount *mnt)
52422 +{
52423 + struct name_entry *match;
52424 + struct acl_object_label *matchpo;
52425 + struct acl_subject_label *curracl;
52426 + char *path;
52427 +
52428 + if (unlikely(!(gr_status & GR_READY)))
52429 + return NULL;
52430 +
52431 + preempt_disable();
52432 + path = gr_to_filename_rbac(new_dentry, mnt);
52433 + match = lookup_name_entry_create(path);
52434 +
52435 + curracl = current->acl;
52436 +
52437 + if (match) {
52438 + read_lock(&gr_inode_lock);
52439 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
52440 + read_unlock(&gr_inode_lock);
52441 +
52442 + if (matchpo) {
52443 + preempt_enable();
52444 + return matchpo;
52445 + }
52446 + }
52447 +
52448 + // lookup parent
52449 +
52450 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
52451 +
52452 + preempt_enable();
52453 + return matchpo;
52454 +}
52455 +
52456 +__u32
52457 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
52458 + const struct vfsmount * mnt, const __u32 mode)
52459 +{
52460 + struct acl_object_label *matchpo;
52461 + __u32 retval;
52462 +
52463 + if (unlikely(!(gr_status & GR_READY)))
52464 + return (mode & ~GR_AUDITS);
52465 +
52466 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
52467 +
52468 + retval = matchpo->mode & mode;
52469 +
52470 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
52471 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
52472 + __u32 new_mode = mode;
52473 +
52474 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
52475 +
52476 + gr_log_learn(new_dentry, mnt, new_mode);
52477 + return new_mode;
52478 + }
52479 +
52480 + return retval;
52481 +}
52482 +
52483 +__u32
52484 +gr_check_link(const struct dentry * new_dentry,
52485 + const struct dentry * parent_dentry,
52486 + const struct vfsmount * parent_mnt,
52487 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
52488 +{
52489 + struct acl_object_label *obj;
52490 + __u32 oldmode, newmode;
52491 + __u32 needmode;
52492 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
52493 + GR_DELETE | GR_INHERIT;
52494 +
52495 + if (unlikely(!(gr_status & GR_READY)))
52496 + return (GR_CREATE | GR_LINK);
52497 +
52498 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
52499 + oldmode = obj->mode;
52500 +
52501 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
52502 + newmode = obj->mode;
52503 +
52504 + needmode = newmode & checkmodes;
52505 +
52506 + // old name for hardlink must have at least the permissions of the new name
52507 + if ((oldmode & needmode) != needmode)
52508 + goto bad;
52509 +
52510 + // if old name had restrictions/auditing, make sure the new name does as well
52511 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
52512 +
52513 + // don't allow hardlinking of suid/sgid files without permission
52514 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
52515 + needmode |= GR_SETID;
52516 +
52517 + if ((newmode & needmode) != needmode)
52518 + goto bad;
52519 +
52520 + // enforce minimum permissions
52521 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
52522 + return newmode;
52523 +bad:
52524 + needmode = oldmode;
52525 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
52526 + needmode |= GR_SETID;
52527 +
52528 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
52529 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
52530 + return (GR_CREATE | GR_LINK);
52531 + } else if (newmode & GR_SUPPRESS)
52532 + return GR_SUPPRESS;
52533 + else
52534 + return 0;
52535 +}
52536 +
52537 +int
52538 +gr_check_hidden_task(const struct task_struct *task)
52539 +{
52540 + if (unlikely(!(gr_status & GR_READY)))
52541 + return 0;
52542 +
52543 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
52544 + return 1;
52545 +
52546 + return 0;
52547 +}
52548 +
52549 +int
52550 +gr_check_protected_task(const struct task_struct *task)
52551 +{
52552 + if (unlikely(!(gr_status & GR_READY) || !task))
52553 + return 0;
52554 +
52555 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
52556 + task->acl != current->acl)
52557 + return 1;
52558 +
52559 + return 0;
52560 +}
52561 +
52562 +int
52563 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
52564 +{
52565 + struct task_struct *p;
52566 + int ret = 0;
52567 +
52568 + if (unlikely(!(gr_status & GR_READY) || !pid))
52569 + return ret;
52570 +
52571 + read_lock(&tasklist_lock);
52572 + do_each_pid_task(pid, type, p) {
52573 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
52574 + p->acl != current->acl) {
52575 + ret = 1;
52576 + goto out;
52577 + }
52578 + } while_each_pid_task(pid, type, p);
52579 +out:
52580 + read_unlock(&tasklist_lock);
52581 +
52582 + return ret;
52583 +}
52584 +
52585 +void
52586 +gr_copy_label(struct task_struct *tsk)
52587 +{
52588 + tsk->signal->used_accept = 0;
52589 + tsk->acl_sp_role = 0;
52590 + tsk->acl_role_id = current->acl_role_id;
52591 + tsk->acl = current->acl;
52592 + tsk->role = current->role;
52593 + tsk->signal->curr_ip = current->signal->curr_ip;
52594 + tsk->signal->saved_ip = current->signal->saved_ip;
52595 + if (current->exec_file)
52596 + get_file(current->exec_file);
52597 + tsk->exec_file = current->exec_file;
52598 + tsk->is_writable = current->is_writable;
52599 + if (unlikely(current->signal->used_accept)) {
52600 + current->signal->curr_ip = 0;
52601 + current->signal->saved_ip = 0;
52602 + }
52603 +
52604 + return;
52605 +}
52606 +
52607 +static void
52608 +gr_set_proc_res(struct task_struct *task)
52609 +{
52610 + struct acl_subject_label *proc;
52611 + unsigned short i;
52612 +
52613 + proc = task->acl;
52614 +
52615 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
52616 + return;
52617 +
52618 + for (i = 0; i < RLIM_NLIMITS; i++) {
52619 + if (!(proc->resmask & (1 << i)))
52620 + continue;
52621 +
52622 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
52623 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
52624 + }
52625 +
52626 + return;
52627 +}
52628 +
52629 +extern int __gr_process_user_ban(struct user_struct *user);
52630 +
52631 +int
52632 +gr_check_user_change(int real, int effective, int fs)
52633 +{
52634 + unsigned int i;
52635 + __u16 num;
52636 + uid_t *uidlist;
52637 + int curuid;
52638 + int realok = 0;
52639 + int effectiveok = 0;
52640 + int fsok = 0;
52641 +
52642 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
52643 + struct user_struct *user;
52644 +
52645 + if (real == -1)
52646 + goto skipit;
52647 +
52648 + user = find_user(real);
52649 + if (user == NULL)
52650 + goto skipit;
52651 +
52652 + if (__gr_process_user_ban(user)) {
52653 + /* for find_user */
52654 + free_uid(user);
52655 + return 1;
52656 + }
52657 +
52658 + /* for find_user */
52659 + free_uid(user);
52660 +
52661 +skipit:
52662 +#endif
52663 +
52664 + if (unlikely(!(gr_status & GR_READY)))
52665 + return 0;
52666 +
52667 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
52668 + gr_log_learn_id_change('u', real, effective, fs);
52669 +
52670 + num = current->acl->user_trans_num;
52671 + uidlist = current->acl->user_transitions;
52672 +
52673 + if (uidlist == NULL)
52674 + return 0;
52675 +
52676 + if (real == -1)
52677 + realok = 1;
52678 + if (effective == -1)
52679 + effectiveok = 1;
52680 + if (fs == -1)
52681 + fsok = 1;
52682 +
52683 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
52684 + for (i = 0; i < num; i++) {
52685 + curuid = (int)uidlist[i];
52686 + if (real == curuid)
52687 + realok = 1;
52688 + if (effective == curuid)
52689 + effectiveok = 1;
52690 + if (fs == curuid)
52691 + fsok = 1;
52692 + }
52693 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
52694 + for (i = 0; i < num; i++) {
52695 + curuid = (int)uidlist[i];
52696 + if (real == curuid)
52697 + break;
52698 + if (effective == curuid)
52699 + break;
52700 + if (fs == curuid)
52701 + break;
52702 + }
52703 + /* not in deny list */
52704 + if (i == num) {
52705 + realok = 1;
52706 + effectiveok = 1;
52707 + fsok = 1;
52708 + }
52709 + }
52710 +
52711 + if (realok && effectiveok && fsok)
52712 + return 0;
52713 + else {
52714 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
52715 + return 1;
52716 + }
52717 +}
52718 +
52719 +int
52720 +gr_check_group_change(int real, int effective, int fs)
52721 +{
52722 + unsigned int i;
52723 + __u16 num;
52724 + gid_t *gidlist;
52725 + int curgid;
52726 + int realok = 0;
52727 + int effectiveok = 0;
52728 + int fsok = 0;
52729 +
52730 + if (unlikely(!(gr_status & GR_READY)))
52731 + return 0;
52732 +
52733 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
52734 + gr_log_learn_id_change('g', real, effective, fs);
52735 +
52736 + num = current->acl->group_trans_num;
52737 + gidlist = current->acl->group_transitions;
52738 +
52739 + if (gidlist == NULL)
52740 + return 0;
52741 +
52742 + if (real == -1)
52743 + realok = 1;
52744 + if (effective == -1)
52745 + effectiveok = 1;
52746 + if (fs == -1)
52747 + fsok = 1;
52748 +
52749 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
52750 + for (i = 0; i < num; i++) {
52751 + curgid = (int)gidlist[i];
52752 + if (real == curgid)
52753 + realok = 1;
52754 + if (effective == curgid)
52755 + effectiveok = 1;
52756 + if (fs == curgid)
52757 + fsok = 1;
52758 + }
52759 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
52760 + for (i = 0; i < num; i++) {
52761 + curgid = (int)gidlist[i];
52762 + if (real == curgid)
52763 + break;
52764 + if (effective == curgid)
52765 + break;
52766 + if (fs == curgid)
52767 + break;
52768 + }
52769 + /* not in deny list */
52770 + if (i == num) {
52771 + realok = 1;
52772 + effectiveok = 1;
52773 + fsok = 1;
52774 + }
52775 + }
52776 +
52777 + if (realok && effectiveok && fsok)
52778 + return 0;
52779 + else {
52780 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
52781 + return 1;
52782 + }
52783 +}
52784 +
52785 +extern int gr_acl_is_capable(const int cap);
52786 +
52787 +void
52788 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
52789 +{
52790 + struct acl_role_label *role = task->role;
52791 + struct acl_subject_label *subj = NULL;
52792 + struct acl_object_label *obj;
52793 + struct file *filp;
52794 +
52795 + if (unlikely(!(gr_status & GR_READY)))
52796 + return;
52797 +
52798 + filp = task->exec_file;
52799 +
52800 + /* kernel process, we'll give them the kernel role */
52801 + if (unlikely(!filp)) {
52802 + task->role = kernel_role;
52803 + task->acl = kernel_role->root_label;
52804 + return;
52805 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
52806 + role = lookup_acl_role_label(task, uid, gid);
52807 +
52808 + /* don't change the role if we're not a privileged process */
52809 + if (role && task->role != role &&
52810 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
52811 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
52812 + return;
52813 +
52814 + /* perform subject lookup in possibly new role
52815 + we can use this result below in the case where role == task->role
52816 + */
52817 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
52818 +
52819 + /* if we changed uid/gid, but result in the same role
52820 + and are using inheritance, don't lose the inherited subject
52821 + if current subject is other than what normal lookup
52822 + would result in, we arrived via inheritance, don't
52823 + lose subject
52824 + */
52825 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
52826 + (subj == task->acl)))
52827 + task->acl = subj;
52828 +
52829 + task->role = role;
52830 +
52831 + task->is_writable = 0;
52832 +
52833 + /* ignore additional mmap checks for processes that are writable
52834 + by the default ACL */
52835 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
52836 + if (unlikely(obj->mode & GR_WRITE))
52837 + task->is_writable = 1;
52838 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
52839 + if (unlikely(obj->mode & GR_WRITE))
52840 + task->is_writable = 1;
52841 +
52842 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52843 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
52844 +#endif
52845 +
52846 + gr_set_proc_res(task);
52847 +
52848 + return;
52849 +}
52850 +
52851 +int
52852 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
52853 + const int unsafe_flags)
52854 +{
52855 + struct task_struct *task = current;
52856 + struct acl_subject_label *newacl;
52857 + struct acl_object_label *obj;
52858 + __u32 retmode;
52859 +
52860 + if (unlikely(!(gr_status & GR_READY)))
52861 + return 0;
52862 +
52863 + newacl = chk_subj_label(dentry, mnt, task->role);
52864 +
52865 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
52866 + did an exec
52867 + */
52868 + rcu_read_lock();
52869 + read_lock(&tasklist_lock);
52870 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
52871 + (task->parent->acl->mode & GR_POVERRIDE))) {
52872 + read_unlock(&tasklist_lock);
52873 + rcu_read_unlock();
52874 + goto skip_check;
52875 + }
52876 + read_unlock(&tasklist_lock);
52877 + rcu_read_unlock();
52878 +
52879 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
52880 + !(task->role->roletype & GR_ROLE_GOD) &&
52881 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
52882 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
52883 + if (unsafe_flags & LSM_UNSAFE_SHARE)
52884 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
52885 + else
52886 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
52887 + return -EACCES;
52888 + }
52889 +
52890 +skip_check:
52891 +
52892 + obj = chk_obj_label(dentry, mnt, task->acl);
52893 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
52894 +
52895 + if (!(task->acl->mode & GR_INHERITLEARN) &&
52896 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
52897 + if (obj->nested)
52898 + task->acl = obj->nested;
52899 + else
52900 + task->acl = newacl;
52901 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
52902 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
52903 +
52904 + task->is_writable = 0;
52905 +
52906 + /* ignore additional mmap checks for processes that are writable
52907 + by the default ACL */
52908 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
52909 + if (unlikely(obj->mode & GR_WRITE))
52910 + task->is_writable = 1;
52911 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
52912 + if (unlikely(obj->mode & GR_WRITE))
52913 + task->is_writable = 1;
52914 +
52915 + gr_set_proc_res(task);
52916 +
52917 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52918 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
52919 +#endif
52920 + return 0;
52921 +}
52922 +
52923 +/* always called with valid inodev ptr */
52924 +static void
52925 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
52926 +{
52927 + struct acl_object_label *matchpo;
52928 + struct acl_subject_label *matchps;
52929 + struct acl_subject_label *subj;
52930 + struct acl_role_label *role;
52931 + unsigned int x;
52932 +
52933 + FOR_EACH_ROLE_START(role)
52934 + FOR_EACH_SUBJECT_START(role, subj, x)
52935 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
52936 + matchpo->mode |= GR_DELETED;
52937 + FOR_EACH_SUBJECT_END(subj,x)
52938 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
52939 + if (subj->inode == ino && subj->device == dev)
52940 + subj->mode |= GR_DELETED;
52941 + FOR_EACH_NESTED_SUBJECT_END(subj)
52942 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
52943 + matchps->mode |= GR_DELETED;
52944 + FOR_EACH_ROLE_END(role)
52945 +
52946 + inodev->nentry->deleted = 1;
52947 +
52948 + return;
52949 +}
52950 +
52951 +void
52952 +gr_handle_delete(const ino_t ino, const dev_t dev)
52953 +{
52954 + struct inodev_entry *inodev;
52955 +
52956 + if (unlikely(!(gr_status & GR_READY)))
52957 + return;
52958 +
52959 + write_lock(&gr_inode_lock);
52960 + inodev = lookup_inodev_entry(ino, dev);
52961 + if (inodev != NULL)
52962 + do_handle_delete(inodev, ino, dev);
52963 + write_unlock(&gr_inode_lock);
52964 +
52965 + return;
52966 +}
52967 +
52968 +static void
52969 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
52970 + const ino_t newinode, const dev_t newdevice,
52971 + struct acl_subject_label *subj)
52972 +{
52973 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
52974 + struct acl_object_label *match;
52975 +
52976 + match = subj->obj_hash[index];
52977 +
52978 + while (match && (match->inode != oldinode ||
52979 + match->device != olddevice ||
52980 + !(match->mode & GR_DELETED)))
52981 + match = match->next;
52982 +
52983 + if (match && (match->inode == oldinode)
52984 + && (match->device == olddevice)
52985 + && (match->mode & GR_DELETED)) {
52986 + if (match->prev == NULL) {
52987 + subj->obj_hash[index] = match->next;
52988 + if (match->next != NULL)
52989 + match->next->prev = NULL;
52990 + } else {
52991 + match->prev->next = match->next;
52992 + if (match->next != NULL)
52993 + match->next->prev = match->prev;
52994 + }
52995 + match->prev = NULL;
52996 + match->next = NULL;
52997 + match->inode = newinode;
52998 + match->device = newdevice;
52999 + match->mode &= ~GR_DELETED;
53000 +
53001 + insert_acl_obj_label(match, subj);
53002 + }
53003 +
53004 + return;
53005 +}
53006 +
53007 +static void
53008 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
53009 + const ino_t newinode, const dev_t newdevice,
53010 + struct acl_role_label *role)
53011 +{
53012 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
53013 + struct acl_subject_label *match;
53014 +
53015 + match = role->subj_hash[index];
53016 +
53017 + while (match && (match->inode != oldinode ||
53018 + match->device != olddevice ||
53019 + !(match->mode & GR_DELETED)))
53020 + match = match->next;
53021 +
53022 + if (match && (match->inode == oldinode)
53023 + && (match->device == olddevice)
53024 + && (match->mode & GR_DELETED)) {
53025 + if (match->prev == NULL) {
53026 + role->subj_hash[index] = match->next;
53027 + if (match->next != NULL)
53028 + match->next->prev = NULL;
53029 + } else {
53030 + match->prev->next = match->next;
53031 + if (match->next != NULL)
53032 + match->next->prev = match->prev;
53033 + }
53034 + match->prev = NULL;
53035 + match->next = NULL;
53036 + match->inode = newinode;
53037 + match->device = newdevice;
53038 + match->mode &= ~GR_DELETED;
53039 +
53040 + insert_acl_subj_label(match, role);
53041 + }
53042 +
53043 + return;
53044 +}
53045 +
53046 +static void
53047 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
53048 + const ino_t newinode, const dev_t newdevice)
53049 +{
53050 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
53051 + struct inodev_entry *match;
53052 +
53053 + match = inodev_set.i_hash[index];
53054 +
53055 + while (match && (match->nentry->inode != oldinode ||
53056 + match->nentry->device != olddevice || !match->nentry->deleted))
53057 + match = match->next;
53058 +
53059 + if (match && (match->nentry->inode == oldinode)
53060 + && (match->nentry->device == olddevice) &&
53061 + match->nentry->deleted) {
53062 + if (match->prev == NULL) {
53063 + inodev_set.i_hash[index] = match->next;
53064 + if (match->next != NULL)
53065 + match->next->prev = NULL;
53066 + } else {
53067 + match->prev->next = match->next;
53068 + if (match->next != NULL)
53069 + match->next->prev = match->prev;
53070 + }
53071 + match->prev = NULL;
53072 + match->next = NULL;
53073 + match->nentry->inode = newinode;
53074 + match->nentry->device = newdevice;
53075 + match->nentry->deleted = 0;
53076 +
53077 + insert_inodev_entry(match);
53078 + }
53079 +
53080 + return;
53081 +}
53082 +
53083 +static void
53084 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
53085 +{
53086 + struct acl_subject_label *subj;
53087 + struct acl_role_label *role;
53088 + unsigned int x;
53089 +
53090 + FOR_EACH_ROLE_START(role)
53091 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
53092 +
53093 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
53094 + if ((subj->inode == ino) && (subj->device == dev)) {
53095 + subj->inode = ino;
53096 + subj->device = dev;
53097 + }
53098 + FOR_EACH_NESTED_SUBJECT_END(subj)
53099 + FOR_EACH_SUBJECT_START(role, subj, x)
53100 + update_acl_obj_label(matchn->inode, matchn->device,
53101 + ino, dev, subj);
53102 + FOR_EACH_SUBJECT_END(subj,x)
53103 + FOR_EACH_ROLE_END(role)
53104 +
53105 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
53106 +
53107 + return;
53108 +}
53109 +
53110 +static void
53111 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
53112 + const struct vfsmount *mnt)
53113 +{
53114 + ino_t ino = dentry->d_inode->i_ino;
53115 + dev_t dev = __get_dev(dentry);
53116 +
53117 + __do_handle_create(matchn, ino, dev);
53118 +
53119 + return;
53120 +}
53121 +
53122 +void
53123 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
53124 +{
53125 + struct name_entry *matchn;
53126 +
53127 + if (unlikely(!(gr_status & GR_READY)))
53128 + return;
53129 +
53130 + preempt_disable();
53131 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
53132 +
53133 + if (unlikely((unsigned long)matchn)) {
53134 + write_lock(&gr_inode_lock);
53135 + do_handle_create(matchn, dentry, mnt);
53136 + write_unlock(&gr_inode_lock);
53137 + }
53138 + preempt_enable();
53139 +
53140 + return;
53141 +}
53142 +
53143 +void
53144 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
53145 +{
53146 + struct name_entry *matchn;
53147 +
53148 + if (unlikely(!(gr_status & GR_READY)))
53149 + return;
53150 +
53151 + preempt_disable();
53152 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
53153 +
53154 + if (unlikely((unsigned long)matchn)) {
53155 + write_lock(&gr_inode_lock);
53156 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
53157 + write_unlock(&gr_inode_lock);
53158 + }
53159 + preempt_enable();
53160 +
53161 + return;
53162 +}
53163 +
53164 +void
53165 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
53166 + struct dentry *old_dentry,
53167 + struct dentry *new_dentry,
53168 + struct vfsmount *mnt, const __u8 replace)
53169 +{
53170 + struct name_entry *matchn;
53171 + struct inodev_entry *inodev;
53172 + struct inode *inode = new_dentry->d_inode;
53173 + ino_t old_ino = old_dentry->d_inode->i_ino;
53174 + dev_t old_dev = __get_dev(old_dentry);
53175 +
53176 + /* vfs_rename swaps the name and parent link for old_dentry and
53177 + new_dentry
53178 + at this point, old_dentry has the new name, parent link, and inode
53179 + for the renamed file
53180 + if a file is being replaced by a rename, new_dentry has the inode
53181 + and name for the replaced file
53182 + */
53183 +
53184 + if (unlikely(!(gr_status & GR_READY)))
53185 + return;
53186 +
53187 + preempt_disable();
53188 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
53189 +
53190 + /* we wouldn't have to check d_inode if it weren't for
53191 + NFS silly-renaming
53192 + */
53193 +
53194 + write_lock(&gr_inode_lock);
53195 + if (unlikely(replace && inode)) {
53196 + ino_t new_ino = inode->i_ino;
53197 + dev_t new_dev = __get_dev(new_dentry);
53198 +
53199 + inodev = lookup_inodev_entry(new_ino, new_dev);
53200 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
53201 + do_handle_delete(inodev, new_ino, new_dev);
53202 + }
53203 +
53204 + inodev = lookup_inodev_entry(old_ino, old_dev);
53205 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
53206 + do_handle_delete(inodev, old_ino, old_dev);
53207 +
53208 + if (unlikely((unsigned long)matchn))
53209 + do_handle_create(matchn, old_dentry, mnt);
53210 +
53211 + write_unlock(&gr_inode_lock);
53212 + preempt_enable();
53213 +
53214 + return;
53215 +}
53216 +
53217 +static int
53218 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
53219 + unsigned char **sum)
53220 +{
53221 + struct acl_role_label *r;
53222 + struct role_allowed_ip *ipp;
53223 + struct role_transition *trans;
53224 + unsigned int i;
53225 + int found = 0;
53226 + u32 curr_ip = current->signal->curr_ip;
53227 +
53228 + current->signal->saved_ip = curr_ip;
53229 +
53230 + /* check transition table */
53231 +
53232 + for (trans = current->role->transitions; trans; trans = trans->next) {
53233 + if (!strcmp(rolename, trans->rolename)) {
53234 + found = 1;
53235 + break;
53236 + }
53237 + }
53238 +
53239 + if (!found)
53240 + return 0;
53241 +
53242 + /* handle special roles that do not require authentication
53243 + and check ip */
53244 +
53245 + FOR_EACH_ROLE_START(r)
53246 + if (!strcmp(rolename, r->rolename) &&
53247 + (r->roletype & GR_ROLE_SPECIAL)) {
53248 + found = 0;
53249 + if (r->allowed_ips != NULL) {
53250 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
53251 + if ((ntohl(curr_ip) & ipp->netmask) ==
53252 + (ntohl(ipp->addr) & ipp->netmask))
53253 + found = 1;
53254 + }
53255 + } else
53256 + found = 2;
53257 + if (!found)
53258 + return 0;
53259 +
53260 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
53261 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
53262 + *salt = NULL;
53263 + *sum = NULL;
53264 + return 1;
53265 + }
53266 + }
53267 + FOR_EACH_ROLE_END(r)
53268 +
53269 + for (i = 0; i < num_sprole_pws; i++) {
53270 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
53271 + *salt = acl_special_roles[i]->salt;
53272 + *sum = acl_special_roles[i]->sum;
53273 + return 1;
53274 + }
53275 + }
53276 +
53277 + return 0;
53278 +}
53279 +
53280 +static void
53281 +assign_special_role(char *rolename)
53282 +{
53283 + struct acl_object_label *obj;
53284 + struct acl_role_label *r;
53285 + struct acl_role_label *assigned = NULL;
53286 + struct task_struct *tsk;
53287 + struct file *filp;
53288 +
53289 + FOR_EACH_ROLE_START(r)
53290 + if (!strcmp(rolename, r->rolename) &&
53291 + (r->roletype & GR_ROLE_SPECIAL)) {
53292 + assigned = r;
53293 + break;
53294 + }
53295 + FOR_EACH_ROLE_END(r)
53296 +
53297 + if (!assigned)
53298 + return;
53299 +
53300 + read_lock(&tasklist_lock);
53301 + read_lock(&grsec_exec_file_lock);
53302 +
53303 + tsk = current->real_parent;
53304 + if (tsk == NULL)
53305 + goto out_unlock;
53306 +
53307 + filp = tsk->exec_file;
53308 + if (filp == NULL)
53309 + goto out_unlock;
53310 +
53311 + tsk->is_writable = 0;
53312 +
53313 + tsk->acl_sp_role = 1;
53314 + tsk->acl_role_id = ++acl_sp_role_value;
53315 + tsk->role = assigned;
53316 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
53317 +
53318 + /* ignore additional mmap checks for processes that are writable
53319 + by the default ACL */
53320 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53321 + if (unlikely(obj->mode & GR_WRITE))
53322 + tsk->is_writable = 1;
53323 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
53324 + if (unlikely(obj->mode & GR_WRITE))
53325 + tsk->is_writable = 1;
53326 +
53327 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53328 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
53329 +#endif
53330 +
53331 +out_unlock:
53332 + read_unlock(&grsec_exec_file_lock);
53333 + read_unlock(&tasklist_lock);
53334 + return;
53335 +}
53336 +
53337 +int gr_check_secure_terminal(struct task_struct *task)
53338 +{
53339 + struct task_struct *p, *p2, *p3;
53340 + struct files_struct *files;
53341 + struct fdtable *fdt;
53342 + struct file *our_file = NULL, *file;
53343 + int i;
53344 +
53345 + if (task->signal->tty == NULL)
53346 + return 1;
53347 +
53348 + files = get_files_struct(task);
53349 + if (files != NULL) {
53350 + rcu_read_lock();
53351 + fdt = files_fdtable(files);
53352 + for (i=0; i < fdt->max_fds; i++) {
53353 + file = fcheck_files(files, i);
53354 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
53355 + get_file(file);
53356 + our_file = file;
53357 + }
53358 + }
53359 + rcu_read_unlock();
53360 + put_files_struct(files);
53361 + }
53362 +
53363 + if (our_file == NULL)
53364 + return 1;
53365 +
53366 + read_lock(&tasklist_lock);
53367 + do_each_thread(p2, p) {
53368 + files = get_files_struct(p);
53369 + if (files == NULL ||
53370 + (p->signal && p->signal->tty == task->signal->tty)) {
53371 + if (files != NULL)
53372 + put_files_struct(files);
53373 + continue;
53374 + }
53375 + rcu_read_lock();
53376 + fdt = files_fdtable(files);
53377 + for (i=0; i < fdt->max_fds; i++) {
53378 + file = fcheck_files(files, i);
53379 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
53380 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
53381 + p3 = task;
53382 + while (p3->pid > 0) {
53383 + if (p3 == p)
53384 + break;
53385 + p3 = p3->real_parent;
53386 + }
53387 + if (p3 == p)
53388 + break;
53389 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
53390 + gr_handle_alertkill(p);
53391 + rcu_read_unlock();
53392 + put_files_struct(files);
53393 + read_unlock(&tasklist_lock);
53394 + fput(our_file);
53395 + return 0;
53396 + }
53397 + }
53398 + rcu_read_unlock();
53399 + put_files_struct(files);
53400 + } while_each_thread(p2, p);
53401 + read_unlock(&tasklist_lock);
53402 +
53403 + fput(our_file);
53404 + return 1;
53405 +}
53406 +
53407 +static int gr_rbac_disable(void *unused)
53408 +{
53409 + pax_open_kernel();
53410 + gr_status &= ~GR_READY;
53411 + pax_close_kernel();
53412 +
53413 + return 0;
53414 +}
53415 +
53416 +ssize_t
53417 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
53418 +{
53419 + struct gr_arg_wrapper uwrap;
53420 + unsigned char *sprole_salt = NULL;
53421 + unsigned char *sprole_sum = NULL;
53422 + int error = sizeof (struct gr_arg_wrapper);
53423 + int error2 = 0;
53424 +
53425 + mutex_lock(&gr_dev_mutex);
53426 +
53427 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
53428 + error = -EPERM;
53429 + goto out;
53430 + }
53431 +
53432 + if (count != sizeof (struct gr_arg_wrapper)) {
53433 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
53434 + error = -EINVAL;
53435 + goto out;
53436 + }
53437 +
53438 +
53439 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
53440 + gr_auth_expires = 0;
53441 + gr_auth_attempts = 0;
53442 + }
53443 +
53444 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
53445 + error = -EFAULT;
53446 + goto out;
53447 + }
53448 +
53449 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
53450 + error = -EINVAL;
53451 + goto out;
53452 + }
53453 +
53454 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
53455 + error = -EFAULT;
53456 + goto out;
53457 + }
53458 +
53459 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
53460 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
53461 + time_after(gr_auth_expires, get_seconds())) {
53462 + error = -EBUSY;
53463 + goto out;
53464 + }
53465 +
53466 + /* if non-root trying to do anything other than use a special role,
53467 + do not attempt authentication, do not count towards authentication
53468 + locking
53469 + */
53470 +
53471 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
53472 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
53473 + current_uid()) {
53474 + error = -EPERM;
53475 + goto out;
53476 + }
53477 +
53478 + /* ensure pw and special role name are null terminated */
53479 +
53480 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
53481 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
53482 +
53483 + /* Okay.
53484 + * We have our enough of the argument structure..(we have yet
53485 + * to copy_from_user the tables themselves) . Copy the tables
53486 + * only if we need them, i.e. for loading operations. */
53487 +
53488 + switch (gr_usermode->mode) {
53489 + case GR_STATUS:
53490 + if (gr_status & GR_READY) {
53491 + error = 1;
53492 + if (!gr_check_secure_terminal(current))
53493 + error = 3;
53494 + } else
53495 + error = 2;
53496 + goto out;
53497 + case GR_SHUTDOWN:
53498 + if ((gr_status & GR_READY)
53499 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53500 + stop_machine(gr_rbac_disable, NULL, NULL);
53501 + free_variables();
53502 + memset(gr_usermode, 0, sizeof (struct gr_arg));
53503 + memset(gr_system_salt, 0, GR_SALT_LEN);
53504 + memset(gr_system_sum, 0, GR_SHA_LEN);
53505 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
53506 + } else if (gr_status & GR_READY) {
53507 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
53508 + error = -EPERM;
53509 + } else {
53510 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
53511 + error = -EAGAIN;
53512 + }
53513 + break;
53514 + case GR_ENABLE:
53515 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
53516 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
53517 + else {
53518 + if (gr_status & GR_READY)
53519 + error = -EAGAIN;
53520 + else
53521 + error = error2;
53522 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
53523 + }
53524 + break;
53525 + case GR_RELOAD:
53526 + if (!(gr_status & GR_READY)) {
53527 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
53528 + error = -EAGAIN;
53529 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53530 + stop_machine(gr_rbac_disable, NULL, NULL);
53531 + free_variables();
53532 + error2 = gracl_init(gr_usermode);
53533 + if (!error2)
53534 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
53535 + else {
53536 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
53537 + error = error2;
53538 + }
53539 + } else {
53540 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
53541 + error = -EPERM;
53542 + }
53543 + break;
53544 + case GR_SEGVMOD:
53545 + if (unlikely(!(gr_status & GR_READY))) {
53546 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
53547 + error = -EAGAIN;
53548 + break;
53549 + }
53550 +
53551 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53552 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
53553 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
53554 + struct acl_subject_label *segvacl;
53555 + segvacl =
53556 + lookup_acl_subj_label(gr_usermode->segv_inode,
53557 + gr_usermode->segv_device,
53558 + current->role);
53559 + if (segvacl) {
53560 + segvacl->crashes = 0;
53561 + segvacl->expires = 0;
53562 + }
53563 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
53564 + gr_remove_uid(gr_usermode->segv_uid);
53565 + }
53566 + } else {
53567 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
53568 + error = -EPERM;
53569 + }
53570 + break;
53571 + case GR_SPROLE:
53572 + case GR_SPROLEPAM:
53573 + if (unlikely(!(gr_status & GR_READY))) {
53574 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
53575 + error = -EAGAIN;
53576 + break;
53577 + }
53578 +
53579 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
53580 + current->role->expires = 0;
53581 + current->role->auth_attempts = 0;
53582 + }
53583 +
53584 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
53585 + time_after(current->role->expires, get_seconds())) {
53586 + error = -EBUSY;
53587 + goto out;
53588 + }
53589 +
53590 + if (lookup_special_role_auth
53591 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
53592 + && ((!sprole_salt && !sprole_sum)
53593 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
53594 + char *p = "";
53595 + assign_special_role(gr_usermode->sp_role);
53596 + read_lock(&tasklist_lock);
53597 + if (current->real_parent)
53598 + p = current->real_parent->role->rolename;
53599 + read_unlock(&tasklist_lock);
53600 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
53601 + p, acl_sp_role_value);
53602 + } else {
53603 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
53604 + error = -EPERM;
53605 + if(!(current->role->auth_attempts++))
53606 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
53607 +
53608 + goto out;
53609 + }
53610 + break;
53611 + case GR_UNSPROLE:
53612 + if (unlikely(!(gr_status & GR_READY))) {
53613 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
53614 + error = -EAGAIN;
53615 + break;
53616 + }
53617 +
53618 + if (current->role->roletype & GR_ROLE_SPECIAL) {
53619 + char *p = "";
53620 + int i = 0;
53621 +
53622 + read_lock(&tasklist_lock);
53623 + if (current->real_parent) {
53624 + p = current->real_parent->role->rolename;
53625 + i = current->real_parent->acl_role_id;
53626 + }
53627 + read_unlock(&tasklist_lock);
53628 +
53629 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
53630 + gr_set_acls(1);
53631 + } else {
53632 + error = -EPERM;
53633 + goto out;
53634 + }
53635 + break;
53636 + default:
53637 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
53638 + error = -EINVAL;
53639 + break;
53640 + }
53641 +
53642 + if (error != -EPERM)
53643 + goto out;
53644 +
53645 + if(!(gr_auth_attempts++))
53646 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
53647 +
53648 + out:
53649 + mutex_unlock(&gr_dev_mutex);
53650 + return error;
53651 +}
53652 +
53653 +/* must be called with
53654 + rcu_read_lock();
53655 + read_lock(&tasklist_lock);
53656 + read_lock(&grsec_exec_file_lock);
53657 +*/
53658 +int gr_apply_subject_to_task(struct task_struct *task)
53659 +{
53660 + struct acl_object_label *obj;
53661 + char *tmpname;
53662 + struct acl_subject_label *tmpsubj;
53663 + struct file *filp;
53664 + struct name_entry *nmatch;
53665 +
53666 + filp = task->exec_file;
53667 + if (filp == NULL)
53668 + return 0;
53669 +
53670 + /* the following is to apply the correct subject
53671 + on binaries running when the RBAC system
53672 + is enabled, when the binaries have been
53673 + replaced or deleted since their execution
53674 + -----
53675 + when the RBAC system starts, the inode/dev
53676 + from exec_file will be one the RBAC system
53677 + is unaware of. It only knows the inode/dev
53678 + of the present file on disk, or the absence
53679 + of it.
53680 + */
53681 + preempt_disable();
53682 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
53683 +
53684 + nmatch = lookup_name_entry(tmpname);
53685 + preempt_enable();
53686 + tmpsubj = NULL;
53687 + if (nmatch) {
53688 + if (nmatch->deleted)
53689 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
53690 + else
53691 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
53692 + if (tmpsubj != NULL)
53693 + task->acl = tmpsubj;
53694 + }
53695 + if (tmpsubj == NULL)
53696 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
53697 + task->role);
53698 + if (task->acl) {
53699 + task->is_writable = 0;
53700 + /* ignore additional mmap checks for processes that are writable
53701 + by the default ACL */
53702 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53703 + if (unlikely(obj->mode & GR_WRITE))
53704 + task->is_writable = 1;
53705 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53706 + if (unlikely(obj->mode & GR_WRITE))
53707 + task->is_writable = 1;
53708 +
53709 + gr_set_proc_res(task);
53710 +
53711 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53712 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53713 +#endif
53714 + } else {
53715 + return 1;
53716 + }
53717 +
53718 + return 0;
53719 +}
53720 +
53721 +int
53722 +gr_set_acls(const int type)
53723 +{
53724 + struct task_struct *task, *task2;
53725 + struct acl_role_label *role = current->role;
53726 + __u16 acl_role_id = current->acl_role_id;
53727 + const struct cred *cred;
53728 + int ret;
53729 +
53730 + rcu_read_lock();
53731 + read_lock(&tasklist_lock);
53732 + read_lock(&grsec_exec_file_lock);
53733 + do_each_thread(task2, task) {
53734 + /* check to see if we're called from the exit handler,
53735 + if so, only replace ACLs that have inherited the admin
53736 + ACL */
53737 +
53738 + if (type && (task->role != role ||
53739 + task->acl_role_id != acl_role_id))
53740 + continue;
53741 +
53742 + task->acl_role_id = 0;
53743 + task->acl_sp_role = 0;
53744 +
53745 + if (task->exec_file) {
53746 + cred = __task_cred(task);
53747 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
53748 + ret = gr_apply_subject_to_task(task);
53749 + if (ret) {
53750 + read_unlock(&grsec_exec_file_lock);
53751 + read_unlock(&tasklist_lock);
53752 + rcu_read_unlock();
53753 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
53754 + return ret;
53755 + }
53756 + } else {
53757 + // it's a kernel process
53758 + task->role = kernel_role;
53759 + task->acl = kernel_role->root_label;
53760 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
53761 + task->acl->mode &= ~GR_PROCFIND;
53762 +#endif
53763 + }
53764 + } while_each_thread(task2, task);
53765 + read_unlock(&grsec_exec_file_lock);
53766 + read_unlock(&tasklist_lock);
53767 + rcu_read_unlock();
53768 +
53769 + return 0;
53770 +}
53771 +
53772 +void
53773 +gr_learn_resource(const struct task_struct *task,
53774 + const int res, const unsigned long wanted, const int gt)
53775 +{
53776 + struct acl_subject_label *acl;
53777 + const struct cred *cred;
53778 +
53779 + if (unlikely((gr_status & GR_READY) &&
53780 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
53781 + goto skip_reslog;
53782 +
53783 +#ifdef CONFIG_GRKERNSEC_RESLOG
53784 + gr_log_resource(task, res, wanted, gt);
53785 +#endif
53786 + skip_reslog:
53787 +
53788 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
53789 + return;
53790 +
53791 + acl = task->acl;
53792 +
53793 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
53794 + !(acl->resmask & (1 << (unsigned short) res))))
53795 + return;
53796 +
53797 + if (wanted >= acl->res[res].rlim_cur) {
53798 + unsigned long res_add;
53799 +
53800 + res_add = wanted;
53801 + switch (res) {
53802 + case RLIMIT_CPU:
53803 + res_add += GR_RLIM_CPU_BUMP;
53804 + break;
53805 + case RLIMIT_FSIZE:
53806 + res_add += GR_RLIM_FSIZE_BUMP;
53807 + break;
53808 + case RLIMIT_DATA:
53809 + res_add += GR_RLIM_DATA_BUMP;
53810 + break;
53811 + case RLIMIT_STACK:
53812 + res_add += GR_RLIM_STACK_BUMP;
53813 + break;
53814 + case RLIMIT_CORE:
53815 + res_add += GR_RLIM_CORE_BUMP;
53816 + break;
53817 + case RLIMIT_RSS:
53818 + res_add += GR_RLIM_RSS_BUMP;
53819 + break;
53820 + case RLIMIT_NPROC:
53821 + res_add += GR_RLIM_NPROC_BUMP;
53822 + break;
53823 + case RLIMIT_NOFILE:
53824 + res_add += GR_RLIM_NOFILE_BUMP;
53825 + break;
53826 + case RLIMIT_MEMLOCK:
53827 + res_add += GR_RLIM_MEMLOCK_BUMP;
53828 + break;
53829 + case RLIMIT_AS:
53830 + res_add += GR_RLIM_AS_BUMP;
53831 + break;
53832 + case RLIMIT_LOCKS:
53833 + res_add += GR_RLIM_LOCKS_BUMP;
53834 + break;
53835 + case RLIMIT_SIGPENDING:
53836 + res_add += GR_RLIM_SIGPENDING_BUMP;
53837 + break;
53838 + case RLIMIT_MSGQUEUE:
53839 + res_add += GR_RLIM_MSGQUEUE_BUMP;
53840 + break;
53841 + case RLIMIT_NICE:
53842 + res_add += GR_RLIM_NICE_BUMP;
53843 + break;
53844 + case RLIMIT_RTPRIO:
53845 + res_add += GR_RLIM_RTPRIO_BUMP;
53846 + break;
53847 + case RLIMIT_RTTIME:
53848 + res_add += GR_RLIM_RTTIME_BUMP;
53849 + break;
53850 + }
53851 +
53852 + acl->res[res].rlim_cur = res_add;
53853 +
53854 + if (wanted > acl->res[res].rlim_max)
53855 + acl->res[res].rlim_max = res_add;
53856 +
53857 + /* only log the subject filename, since resource logging is supported for
53858 + single-subject learning only */
53859 + rcu_read_lock();
53860 + cred = __task_cred(task);
53861 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
53862 + task->role->roletype, cred->uid, cred->gid, acl->filename,
53863 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
53864 + "", (unsigned long) res, &task->signal->saved_ip);
53865 + rcu_read_unlock();
53866 + }
53867 +
53868 + return;
53869 +}
53870 +
53871 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
53872 +void
53873 +pax_set_initial_flags(struct linux_binprm *bprm)
53874 +{
53875 + struct task_struct *task = current;
53876 + struct acl_subject_label *proc;
53877 + unsigned long flags;
53878 +
53879 + if (unlikely(!(gr_status & GR_READY)))
53880 + return;
53881 +
53882 + flags = pax_get_flags(task);
53883 +
53884 + proc = task->acl;
53885 +
53886 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
53887 + flags &= ~MF_PAX_PAGEEXEC;
53888 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
53889 + flags &= ~MF_PAX_SEGMEXEC;
53890 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
53891 + flags &= ~MF_PAX_RANDMMAP;
53892 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
53893 + flags &= ~MF_PAX_EMUTRAMP;
53894 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
53895 + flags &= ~MF_PAX_MPROTECT;
53896 +
53897 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
53898 + flags |= MF_PAX_PAGEEXEC;
53899 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
53900 + flags |= MF_PAX_SEGMEXEC;
53901 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
53902 + flags |= MF_PAX_RANDMMAP;
53903 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
53904 + flags |= MF_PAX_EMUTRAMP;
53905 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
53906 + flags |= MF_PAX_MPROTECT;
53907 +
53908 + pax_set_flags(task, flags);
53909 +
53910 + return;
53911 +}
53912 +#endif
53913 +
53914 +int
53915 +gr_handle_proc_ptrace(struct task_struct *task)
53916 +{
53917 + struct file *filp;
53918 + struct task_struct *tmp = task;
53919 + struct task_struct *curtemp = current;
53920 + __u32 retmode;
53921 +
53922 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
53923 + if (unlikely(!(gr_status & GR_READY)))
53924 + return 0;
53925 +#endif
53926 +
53927 + read_lock(&tasklist_lock);
53928 + read_lock(&grsec_exec_file_lock);
53929 + filp = task->exec_file;
53930 +
53931 + while (tmp->pid > 0) {
53932 + if (tmp == curtemp)
53933 + break;
53934 + tmp = tmp->real_parent;
53935 + }
53936 +
53937 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
53938 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
53939 + read_unlock(&grsec_exec_file_lock);
53940 + read_unlock(&tasklist_lock);
53941 + return 1;
53942 + }
53943 +
53944 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
53945 + if (!(gr_status & GR_READY)) {
53946 + read_unlock(&grsec_exec_file_lock);
53947 + read_unlock(&tasklist_lock);
53948 + return 0;
53949 + }
53950 +#endif
53951 +
53952 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
53953 + read_unlock(&grsec_exec_file_lock);
53954 + read_unlock(&tasklist_lock);
53955 +
53956 + if (retmode & GR_NOPTRACE)
53957 + return 1;
53958 +
53959 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
53960 + && (current->acl != task->acl || (current->acl != current->role->root_label
53961 + && current->pid != task->pid)))
53962 + return 1;
53963 +
53964 + return 0;
53965 +}
53966 +
53967 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
53968 +{
53969 + if (unlikely(!(gr_status & GR_READY)))
53970 + return;
53971 +
53972 + if (!(current->role->roletype & GR_ROLE_GOD))
53973 + return;
53974 +
53975 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
53976 + p->role->rolename, gr_task_roletype_to_char(p),
53977 + p->acl->filename);
53978 +}
53979 +
53980 +int
53981 +gr_handle_ptrace(struct task_struct *task, const long request)
53982 +{
53983 + struct task_struct *tmp = task;
53984 + struct task_struct *curtemp = current;
53985 + __u32 retmode;
53986 +
53987 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
53988 + if (unlikely(!(gr_status & GR_READY)))
53989 + return 0;
53990 +#endif
53991 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
53992 + read_lock(&tasklist_lock);
53993 + while (tmp->pid > 0) {
53994 + if (tmp == curtemp)
53995 + break;
53996 + tmp = tmp->real_parent;
53997 + }
53998 +
53999 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
54000 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
54001 + read_unlock(&tasklist_lock);
54002 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54003 + return 1;
54004 + }
54005 + read_unlock(&tasklist_lock);
54006 + }
54007 +
54008 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54009 + if (!(gr_status & GR_READY))
54010 + return 0;
54011 +#endif
54012 +
54013 + read_lock(&grsec_exec_file_lock);
54014 + if (unlikely(!task->exec_file)) {
54015 + read_unlock(&grsec_exec_file_lock);
54016 + return 0;
54017 + }
54018 +
54019 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
54020 + read_unlock(&grsec_exec_file_lock);
54021 +
54022 + if (retmode & GR_NOPTRACE) {
54023 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54024 + return 1;
54025 + }
54026 +
54027 + if (retmode & GR_PTRACERD) {
54028 + switch (request) {
54029 + case PTRACE_SEIZE:
54030 + case PTRACE_POKETEXT:
54031 + case PTRACE_POKEDATA:
54032 + case PTRACE_POKEUSR:
54033 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
54034 + case PTRACE_SETREGS:
54035 + case PTRACE_SETFPREGS:
54036 +#endif
54037 +#ifdef CONFIG_X86
54038 + case PTRACE_SETFPXREGS:
54039 +#endif
54040 +#ifdef CONFIG_ALTIVEC
54041 + case PTRACE_SETVRREGS:
54042 +#endif
54043 + return 1;
54044 + default:
54045 + return 0;
54046 + }
54047 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
54048 + !(current->role->roletype & GR_ROLE_GOD) &&
54049 + (current->acl != task->acl)) {
54050 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54051 + return 1;
54052 + }
54053 +
54054 + return 0;
54055 +}
54056 +
54057 +static int is_writable_mmap(const struct file *filp)
54058 +{
54059 + struct task_struct *task = current;
54060 + struct acl_object_label *obj, *obj2;
54061 +
54062 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
54063 + !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))) {
54064 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54065 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
54066 + task->role->root_label);
54067 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
54068 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
54069 + return 1;
54070 + }
54071 + }
54072 + return 0;
54073 +}
54074 +
54075 +int
54076 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
54077 +{
54078 + __u32 mode;
54079 +
54080 + if (unlikely(!file || !(prot & PROT_EXEC)))
54081 + return 1;
54082 +
54083 + if (is_writable_mmap(file))
54084 + return 0;
54085 +
54086 + mode =
54087 + gr_search_file(file->f_path.dentry,
54088 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54089 + file->f_path.mnt);
54090 +
54091 + if (!gr_tpe_allow(file))
54092 + return 0;
54093 +
54094 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54095 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54096 + return 0;
54097 + } else if (unlikely(!(mode & GR_EXEC))) {
54098 + return 0;
54099 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54100 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54101 + return 1;
54102 + }
54103 +
54104 + return 1;
54105 +}
54106 +
54107 +int
54108 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
54109 +{
54110 + __u32 mode;
54111 +
54112 + if (unlikely(!file || !(prot & PROT_EXEC)))
54113 + return 1;
54114 +
54115 + if (is_writable_mmap(file))
54116 + return 0;
54117 +
54118 + mode =
54119 + gr_search_file(file->f_path.dentry,
54120 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54121 + file->f_path.mnt);
54122 +
54123 + if (!gr_tpe_allow(file))
54124 + return 0;
54125 +
54126 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54127 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54128 + return 0;
54129 + } else if (unlikely(!(mode & GR_EXEC))) {
54130 + return 0;
54131 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54132 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54133 + return 1;
54134 + }
54135 +
54136 + return 1;
54137 +}
54138 +
54139 +void
54140 +gr_acl_handle_psacct(struct task_struct *task, const long code)
54141 +{
54142 + unsigned long runtime;
54143 + unsigned long cputime;
54144 + unsigned int wday, cday;
54145 + __u8 whr, chr;
54146 + __u8 wmin, cmin;
54147 + __u8 wsec, csec;
54148 + struct timespec timeval;
54149 +
54150 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
54151 + !(task->acl->mode & GR_PROCACCT)))
54152 + return;
54153 +
54154 + do_posix_clock_monotonic_gettime(&timeval);
54155 + runtime = timeval.tv_sec - task->start_time.tv_sec;
54156 + wday = runtime / (3600 * 24);
54157 + runtime -= wday * (3600 * 24);
54158 + whr = runtime / 3600;
54159 + runtime -= whr * 3600;
54160 + wmin = runtime / 60;
54161 + runtime -= wmin * 60;
54162 + wsec = runtime;
54163 +
54164 + cputime = (task->utime + task->stime) / HZ;
54165 + cday = cputime / (3600 * 24);
54166 + cputime -= cday * (3600 * 24);
54167 + chr = cputime / 3600;
54168 + cputime -= chr * 3600;
54169 + cmin = cputime / 60;
54170 + cputime -= cmin * 60;
54171 + csec = cputime;
54172 +
54173 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
54174 +
54175 + return;
54176 +}
54177 +
54178 +void gr_set_kernel_label(struct task_struct *task)
54179 +{
54180 + if (gr_status & GR_READY) {
54181 + task->role = kernel_role;
54182 + task->acl = kernel_role->root_label;
54183 + }
54184 + return;
54185 +}
54186 +
54187 +#ifdef CONFIG_TASKSTATS
54188 +int gr_is_taskstats_denied(int pid)
54189 +{
54190 + struct task_struct *task;
54191 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54192 + const struct cred *cred;
54193 +#endif
54194 + int ret = 0;
54195 +
54196 + /* restrict taskstats viewing to un-chrooted root users
54197 + who have the 'view' subject flag if the RBAC system is enabled
54198 + */
54199 +
54200 + rcu_read_lock();
54201 + read_lock(&tasklist_lock);
54202 + task = find_task_by_vpid(pid);
54203 + if (task) {
54204 +#ifdef CONFIG_GRKERNSEC_CHROOT
54205 + if (proc_is_chrooted(task))
54206 + ret = -EACCES;
54207 +#endif
54208 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54209 + cred = __task_cred(task);
54210 +#ifdef CONFIG_GRKERNSEC_PROC_USER
54211 + if (cred->uid != 0)
54212 + ret = -EACCES;
54213 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54214 + if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
54215 + ret = -EACCES;
54216 +#endif
54217 +#endif
54218 + if (gr_status & GR_READY) {
54219 + if (!(task->acl->mode & GR_VIEW))
54220 + ret = -EACCES;
54221 + }
54222 + } else
54223 + ret = -ENOENT;
54224 +
54225 + read_unlock(&tasklist_lock);
54226 + rcu_read_unlock();
54227 +
54228 + return ret;
54229 +}
54230 +#endif
54231 +
54232 +/* AUXV entries are filled via a descendant of search_binary_handler
54233 + after we've already applied the subject for the target
54234 +*/
54235 +int gr_acl_enable_at_secure(void)
54236 +{
54237 + if (unlikely(!(gr_status & GR_READY)))
54238 + return 0;
54239 +
54240 + if (current->acl->mode & GR_ATSECURE)
54241 + return 1;
54242 +
54243 + return 0;
54244 +}
54245 +
54246 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
54247 +{
54248 + struct task_struct *task = current;
54249 + struct dentry *dentry = file->f_path.dentry;
54250 + struct vfsmount *mnt = file->f_path.mnt;
54251 + struct acl_object_label *obj, *tmp;
54252 + struct acl_subject_label *subj;
54253 + unsigned int bufsize;
54254 + int is_not_root;
54255 + char *path;
54256 + dev_t dev = __get_dev(dentry);
54257 +
54258 + if (unlikely(!(gr_status & GR_READY)))
54259 + return 1;
54260 +
54261 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54262 + return 1;
54263 +
54264 + /* ignore Eric Biederman */
54265 + if (IS_PRIVATE(dentry->d_inode))
54266 + return 1;
54267 +
54268 + subj = task->acl;
54269 + read_lock(&gr_inode_lock);
54270 + do {
54271 + obj = lookup_acl_obj_label(ino, dev, subj);
54272 + if (obj != NULL) {
54273 + read_unlock(&gr_inode_lock);
54274 + return (obj->mode & GR_FIND) ? 1 : 0;
54275 + }
54276 + } while ((subj = subj->parent_subject));
54277 + read_unlock(&gr_inode_lock);
54278 +
54279 + /* this is purely an optimization since we're looking for an object
54280 + for the directory we're doing a readdir on
54281 + if it's possible for any globbed object to match the entry we're
54282 + filling into the directory, then the object we find here will be
54283 + an anchor point with attached globbed objects
54284 + */
54285 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
54286 + if (obj->globbed == NULL)
54287 + return (obj->mode & GR_FIND) ? 1 : 0;
54288 +
54289 + is_not_root = ((obj->filename[0] == '/') &&
54290 + (obj->filename[1] == '\0')) ? 0 : 1;
54291 + bufsize = PAGE_SIZE - namelen - is_not_root;
54292 +
54293 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
54294 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
54295 + return 1;
54296 +
54297 + preempt_disable();
54298 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
54299 + bufsize);
54300 +
54301 + bufsize = strlen(path);
54302 +
54303 + /* if base is "/", don't append an additional slash */
54304 + if (is_not_root)
54305 + *(path + bufsize) = '/';
54306 + memcpy(path + bufsize + is_not_root, name, namelen);
54307 + *(path + bufsize + namelen + is_not_root) = '\0';
54308 +
54309 + tmp = obj->globbed;
54310 + while (tmp) {
54311 + if (!glob_match(tmp->filename, path)) {
54312 + preempt_enable();
54313 + return (tmp->mode & GR_FIND) ? 1 : 0;
54314 + }
54315 + tmp = tmp->next;
54316 + }
54317 + preempt_enable();
54318 + return (obj->mode & GR_FIND) ? 1 : 0;
54319 +}
54320 +
54321 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
54322 +EXPORT_SYMBOL(gr_acl_is_enabled);
54323 +#endif
54324 +EXPORT_SYMBOL(gr_learn_resource);
54325 +EXPORT_SYMBOL(gr_set_kernel_label);
54326 +#ifdef CONFIG_SECURITY
54327 +EXPORT_SYMBOL(gr_check_user_change);
54328 +EXPORT_SYMBOL(gr_check_group_change);
54329 +#endif
54330 +
54331 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
54332 new file mode 100644
54333 index 0000000..34fefda
54334 --- /dev/null
54335 +++ b/grsecurity/gracl_alloc.c
54336 @@ -0,0 +1,105 @@
54337 +#include <linux/kernel.h>
54338 +#include <linux/mm.h>
54339 +#include <linux/slab.h>
54340 +#include <linux/vmalloc.h>
54341 +#include <linux/gracl.h>
54342 +#include <linux/grsecurity.h>
54343 +
54344 +static unsigned long alloc_stack_next = 1;
54345 +static unsigned long alloc_stack_size = 1;
54346 +static void **alloc_stack;
54347 +
54348 +static __inline__ int
54349 +alloc_pop(void)
54350 +{
54351 + if (alloc_stack_next == 1)
54352 + return 0;
54353 +
54354 + kfree(alloc_stack[alloc_stack_next - 2]);
54355 +
54356 + alloc_stack_next--;
54357 +
54358 + return 1;
54359 +}
54360 +
54361 +static __inline__ int
54362 +alloc_push(void *buf)
54363 +{
54364 + if (alloc_stack_next >= alloc_stack_size)
54365 + return 1;
54366 +
54367 + alloc_stack[alloc_stack_next - 1] = buf;
54368 +
54369 + alloc_stack_next++;
54370 +
54371 + return 0;
54372 +}
54373 +
54374 +void *
54375 +acl_alloc(unsigned long len)
54376 +{
54377 + void *ret = NULL;
54378 +
54379 + if (!len || len > PAGE_SIZE)
54380 + goto out;
54381 +
54382 + ret = kmalloc(len, GFP_KERNEL);
54383 +
54384 + if (ret) {
54385 + if (alloc_push(ret)) {
54386 + kfree(ret);
54387 + ret = NULL;
54388 + }
54389 + }
54390 +
54391 +out:
54392 + return ret;
54393 +}
54394 +
54395 +void *
54396 +acl_alloc_num(unsigned long num, unsigned long len)
54397 +{
54398 + if (!len || (num > (PAGE_SIZE / len)))
54399 + return NULL;
54400 +
54401 + return acl_alloc(num * len);
54402 +}
54403 +
54404 +void
54405 +acl_free_all(void)
54406 +{
54407 + if (gr_acl_is_enabled() || !alloc_stack)
54408 + return;
54409 +
54410 + while (alloc_pop()) ;
54411 +
54412 + if (alloc_stack) {
54413 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
54414 + kfree(alloc_stack);
54415 + else
54416 + vfree(alloc_stack);
54417 + }
54418 +
54419 + alloc_stack = NULL;
54420 + alloc_stack_size = 1;
54421 + alloc_stack_next = 1;
54422 +
54423 + return;
54424 +}
54425 +
54426 +int
54427 +acl_alloc_stack_init(unsigned long size)
54428 +{
54429 + if ((size * sizeof (void *)) <= PAGE_SIZE)
54430 + alloc_stack =
54431 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
54432 + else
54433 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
54434 +
54435 + alloc_stack_size = size;
54436 +
54437 + if (!alloc_stack)
54438 + return 0;
54439 + else
54440 + return 1;
54441 +}
54442 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
54443 new file mode 100644
54444 index 0000000..6d21049
54445 --- /dev/null
54446 +++ b/grsecurity/gracl_cap.c
54447 @@ -0,0 +1,110 @@
54448 +#include <linux/kernel.h>
54449 +#include <linux/module.h>
54450 +#include <linux/sched.h>
54451 +#include <linux/gracl.h>
54452 +#include <linux/grsecurity.h>
54453 +#include <linux/grinternal.h>
54454 +
54455 +extern const char *captab_log[];
54456 +extern int captab_log_entries;
54457 +
54458 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
54459 +{
54460 + struct acl_subject_label *curracl;
54461 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
54462 + kernel_cap_t cap_audit = __cap_empty_set;
54463 +
54464 + if (!gr_acl_is_enabled())
54465 + return 1;
54466 +
54467 + curracl = task->acl;
54468 +
54469 + cap_drop = curracl->cap_lower;
54470 + cap_mask = curracl->cap_mask;
54471 + cap_audit = curracl->cap_invert_audit;
54472 +
54473 + while ((curracl = curracl->parent_subject)) {
54474 + /* if the cap isn't specified in the current computed mask but is specified in the
54475 + current level subject, and is lowered in the current level subject, then add
54476 + it to the set of dropped capabilities
54477 + otherwise, add the current level subject's mask to the current computed mask
54478 + */
54479 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
54480 + cap_raise(cap_mask, cap);
54481 + if (cap_raised(curracl->cap_lower, cap))
54482 + cap_raise(cap_drop, cap);
54483 + if (cap_raised(curracl->cap_invert_audit, cap))
54484 + cap_raise(cap_audit, cap);
54485 + }
54486 + }
54487 +
54488 + if (!cap_raised(cap_drop, cap)) {
54489 + if (cap_raised(cap_audit, cap))
54490 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
54491 + return 1;
54492 + }
54493 +
54494 + curracl = task->acl;
54495 +
54496 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
54497 + && cap_raised(cred->cap_effective, cap)) {
54498 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54499 + task->role->roletype, cred->uid,
54500 + cred->gid, task->exec_file ?
54501 + gr_to_filename(task->exec_file->f_path.dentry,
54502 + task->exec_file->f_path.mnt) : curracl->filename,
54503 + curracl->filename, 0UL,
54504 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
54505 + return 1;
54506 + }
54507 +
54508 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
54509 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
54510 +
54511 + return 0;
54512 +}
54513 +
54514 +int
54515 +gr_acl_is_capable(const int cap)
54516 +{
54517 + return gr_task_acl_is_capable(current, current_cred(), cap);
54518 +}
54519 +
54520 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
54521 +{
54522 + struct acl_subject_label *curracl;
54523 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
54524 +
54525 + if (!gr_acl_is_enabled())
54526 + return 1;
54527 +
54528 + curracl = task->acl;
54529 +
54530 + cap_drop = curracl->cap_lower;
54531 + cap_mask = curracl->cap_mask;
54532 +
54533 + while ((curracl = curracl->parent_subject)) {
54534 + /* if the cap isn't specified in the current computed mask but is specified in the
54535 + current level subject, and is lowered in the current level subject, then add
54536 + it to the set of dropped capabilities
54537 + otherwise, add the current level subject's mask to the current computed mask
54538 + */
54539 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
54540 + cap_raise(cap_mask, cap);
54541 + if (cap_raised(curracl->cap_lower, cap))
54542 + cap_raise(cap_drop, cap);
54543 + }
54544 + }
54545 +
54546 + if (!cap_raised(cap_drop, cap))
54547 + return 1;
54548 +
54549 + return 0;
54550 +}
54551 +
54552 +int
54553 +gr_acl_is_capable_nolog(const int cap)
54554 +{
54555 + return gr_task_acl_is_capable_nolog(current, cap);
54556 +}
54557 +
54558 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
54559 new file mode 100644
54560 index 0000000..88d0e87
54561 --- /dev/null
54562 +++ b/grsecurity/gracl_fs.c
54563 @@ -0,0 +1,435 @@
54564 +#include <linux/kernel.h>
54565 +#include <linux/sched.h>
54566 +#include <linux/types.h>
54567 +#include <linux/fs.h>
54568 +#include <linux/file.h>
54569 +#include <linux/stat.h>
54570 +#include <linux/grsecurity.h>
54571 +#include <linux/grinternal.h>
54572 +#include <linux/gracl.h>
54573 +
54574 +umode_t
54575 +gr_acl_umask(void)
54576 +{
54577 + if (unlikely(!gr_acl_is_enabled()))
54578 + return 0;
54579 +
54580 + return current->role->umask;
54581 +}
54582 +
54583 +__u32
54584 +gr_acl_handle_hidden_file(const struct dentry * dentry,
54585 + const struct vfsmount * mnt)
54586 +{
54587 + __u32 mode;
54588 +
54589 + if (unlikely(!dentry->d_inode))
54590 + return GR_FIND;
54591 +
54592 + mode =
54593 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
54594 +
54595 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
54596 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
54597 + return mode;
54598 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
54599 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
54600 + return 0;
54601 + } else if (unlikely(!(mode & GR_FIND)))
54602 + return 0;
54603 +
54604 + return GR_FIND;
54605 +}
54606 +
54607 +__u32
54608 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
54609 + int acc_mode)
54610 +{
54611 + __u32 reqmode = GR_FIND;
54612 + __u32 mode;
54613 +
54614 + if (unlikely(!dentry->d_inode))
54615 + return reqmode;
54616 +
54617 + if (acc_mode & MAY_APPEND)
54618 + reqmode |= GR_APPEND;
54619 + else if (acc_mode & MAY_WRITE)
54620 + reqmode |= GR_WRITE;
54621 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
54622 + reqmode |= GR_READ;
54623 +
54624 + mode =
54625 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
54626 + mnt);
54627 +
54628 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
54629 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
54630 + reqmode & GR_READ ? " reading" : "",
54631 + reqmode & GR_WRITE ? " writing" : reqmode &
54632 + GR_APPEND ? " appending" : "");
54633 + return reqmode;
54634 + } else
54635 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
54636 + {
54637 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
54638 + reqmode & GR_READ ? " reading" : "",
54639 + reqmode & GR_WRITE ? " writing" : reqmode &
54640 + GR_APPEND ? " appending" : "");
54641 + return 0;
54642 + } else if (unlikely((mode & reqmode) != reqmode))
54643 + return 0;
54644 +
54645 + return reqmode;
54646 +}
54647 +
54648 +__u32
54649 +gr_acl_handle_creat(const struct dentry * dentry,
54650 + const struct dentry * p_dentry,
54651 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
54652 + const int imode)
54653 +{
54654 + __u32 reqmode = GR_WRITE | GR_CREATE;
54655 + __u32 mode;
54656 +
54657 + if (acc_mode & MAY_APPEND)
54658 + reqmode |= GR_APPEND;
54659 + // if a directory was required or the directory already exists, then
54660 + // don't count this open as a read
54661 + if ((acc_mode & MAY_READ) &&
54662 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
54663 + reqmode |= GR_READ;
54664 + if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
54665 + reqmode |= GR_SETID;
54666 +
54667 + mode =
54668 + gr_check_create(dentry, p_dentry, p_mnt,
54669 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
54670 +
54671 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
54672 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
54673 + reqmode & GR_READ ? " reading" : "",
54674 + reqmode & GR_WRITE ? " writing" : reqmode &
54675 + GR_APPEND ? " appending" : "");
54676 + return reqmode;
54677 + } else
54678 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
54679 + {
54680 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
54681 + reqmode & GR_READ ? " reading" : "",
54682 + reqmode & GR_WRITE ? " writing" : reqmode &
54683 + GR_APPEND ? " appending" : "");
54684 + return 0;
54685 + } else if (unlikely((mode & reqmode) != reqmode))
54686 + return 0;
54687 +
54688 + return reqmode;
54689 +}
54690 +
54691 +__u32
54692 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
54693 + const int fmode)
54694 +{
54695 + __u32 mode, reqmode = GR_FIND;
54696 +
54697 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
54698 + reqmode |= GR_EXEC;
54699 + if (fmode & S_IWOTH)
54700 + reqmode |= GR_WRITE;
54701 + if (fmode & S_IROTH)
54702 + reqmode |= GR_READ;
54703 +
54704 + mode =
54705 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
54706 + mnt);
54707 +
54708 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
54709 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
54710 + reqmode & GR_READ ? " reading" : "",
54711 + reqmode & GR_WRITE ? " writing" : "",
54712 + reqmode & GR_EXEC ? " executing" : "");
54713 + return reqmode;
54714 + } else
54715 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
54716 + {
54717 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
54718 + reqmode & GR_READ ? " reading" : "",
54719 + reqmode & GR_WRITE ? " writing" : "",
54720 + reqmode & GR_EXEC ? " executing" : "");
54721 + return 0;
54722 + } else if (unlikely((mode & reqmode) != reqmode))
54723 + return 0;
54724 +
54725 + return reqmode;
54726 +}
54727 +
54728 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
54729 +{
54730 + __u32 mode;
54731 +
54732 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
54733 +
54734 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
54735 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
54736 + return mode;
54737 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
54738 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
54739 + return 0;
54740 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
54741 + return 0;
54742 +
54743 + return (reqmode);
54744 +}
54745 +
54746 +__u32
54747 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
54748 +{
54749 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
54750 +}
54751 +
54752 +__u32
54753 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
54754 +{
54755 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
54756 +}
54757 +
54758 +__u32
54759 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
54760 +{
54761 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
54762 +}
54763 +
54764 +__u32
54765 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
54766 +{
54767 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
54768 +}
54769 +
54770 +__u32
54771 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
54772 + umode_t *modeptr)
54773 +{
54774 + umode_t mode;
54775 +
54776 + *modeptr &= ~gr_acl_umask();
54777 + mode = *modeptr;
54778 +
54779 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
54780 + return 1;
54781 +
54782 + if (unlikely(mode & (S_ISUID | S_ISGID))) {
54783 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
54784 + GR_CHMOD_ACL_MSG);
54785 + } else {
54786 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
54787 + }
54788 +}
54789 +
54790 +__u32
54791 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
54792 +{
54793 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
54794 +}
54795 +
54796 +__u32
54797 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
54798 +{
54799 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
54800 +}
54801 +
54802 +__u32
54803 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
54804 +{
54805 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
54806 +}
54807 +
54808 +__u32
54809 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
54810 +{
54811 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
54812 + GR_UNIXCONNECT_ACL_MSG);
54813 +}
54814 +
54815 +/* hardlinks require at minimum create and link permission,
54816 + any additional privilege required is based on the
54817 + privilege of the file being linked to
54818 +*/
54819 +__u32
54820 +gr_acl_handle_link(const struct dentry * new_dentry,
54821 + const struct dentry * parent_dentry,
54822 + const struct vfsmount * parent_mnt,
54823 + const struct dentry * old_dentry,
54824 + const struct vfsmount * old_mnt, const char *to)
54825 +{
54826 + __u32 mode;
54827 + __u32 needmode = GR_CREATE | GR_LINK;
54828 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
54829 +
54830 + mode =
54831 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
54832 + old_mnt);
54833 +
54834 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
54835 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
54836 + return mode;
54837 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
54838 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
54839 + return 0;
54840 + } else if (unlikely((mode & needmode) != needmode))
54841 + return 0;
54842 +
54843 + return 1;
54844 +}
54845 +
54846 +__u32
54847 +gr_acl_handle_symlink(const struct dentry * new_dentry,
54848 + const struct dentry * parent_dentry,
54849 + const struct vfsmount * parent_mnt, const char *from)
54850 +{
54851 + __u32 needmode = GR_WRITE | GR_CREATE;
54852 + __u32 mode;
54853 +
54854 + mode =
54855 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
54856 + GR_CREATE | GR_AUDIT_CREATE |
54857 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
54858 +
54859 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
54860 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
54861 + return mode;
54862 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
54863 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
54864 + return 0;
54865 + } else if (unlikely((mode & needmode) != needmode))
54866 + return 0;
54867 +
54868 + return (GR_WRITE | GR_CREATE);
54869 +}
54870 +
54871 +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)
54872 +{
54873 + __u32 mode;
54874 +
54875 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
54876 +
54877 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
54878 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
54879 + return mode;
54880 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
54881 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
54882 + return 0;
54883 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
54884 + return 0;
54885 +
54886 + return (reqmode);
54887 +}
54888 +
54889 +__u32
54890 +gr_acl_handle_mknod(const struct dentry * new_dentry,
54891 + const struct dentry * parent_dentry,
54892 + const struct vfsmount * parent_mnt,
54893 + const int mode)
54894 +{
54895 + __u32 reqmode = GR_WRITE | GR_CREATE;
54896 + if (unlikely(mode & (S_ISUID | S_ISGID)))
54897 + reqmode |= GR_SETID;
54898 +
54899 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
54900 + reqmode, GR_MKNOD_ACL_MSG);
54901 +}
54902 +
54903 +__u32
54904 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
54905 + const struct dentry *parent_dentry,
54906 + const struct vfsmount *parent_mnt)
54907 +{
54908 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
54909 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
54910 +}
54911 +
54912 +#define RENAME_CHECK_SUCCESS(old, new) \
54913 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
54914 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
54915 +
54916 +int
54917 +gr_acl_handle_rename(struct dentry *new_dentry,
54918 + struct dentry *parent_dentry,
54919 + const struct vfsmount *parent_mnt,
54920 + struct dentry *old_dentry,
54921 + struct inode *old_parent_inode,
54922 + struct vfsmount *old_mnt, const char *newname)
54923 +{
54924 + __u32 comp1, comp2;
54925 + int error = 0;
54926 +
54927 + if (unlikely(!gr_acl_is_enabled()))
54928 + return 0;
54929 +
54930 + if (!new_dentry->d_inode) {
54931 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
54932 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
54933 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
54934 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
54935 + GR_DELETE | GR_AUDIT_DELETE |
54936 + GR_AUDIT_READ | GR_AUDIT_WRITE |
54937 + GR_SUPPRESS, old_mnt);
54938 + } else {
54939 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
54940 + GR_CREATE | GR_DELETE |
54941 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
54942 + GR_AUDIT_READ | GR_AUDIT_WRITE |
54943 + GR_SUPPRESS, parent_mnt);
54944 + comp2 =
54945 + gr_search_file(old_dentry,
54946 + GR_READ | GR_WRITE | GR_AUDIT_READ |
54947 + GR_DELETE | GR_AUDIT_DELETE |
54948 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
54949 + }
54950 +
54951 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
54952 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
54953 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
54954 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
54955 + && !(comp2 & GR_SUPPRESS)) {
54956 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
54957 + error = -EACCES;
54958 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
54959 + error = -EACCES;
54960 +
54961 + return error;
54962 +}
54963 +
54964 +void
54965 +gr_acl_handle_exit(void)
54966 +{
54967 + u16 id;
54968 + char *rolename;
54969 + struct file *exec_file;
54970 +
54971 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
54972 + !(current->role->roletype & GR_ROLE_PERSIST))) {
54973 + id = current->acl_role_id;
54974 + rolename = current->role->rolename;
54975 + gr_set_acls(1);
54976 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
54977 + }
54978 +
54979 + write_lock(&grsec_exec_file_lock);
54980 + exec_file = current->exec_file;
54981 + current->exec_file = NULL;
54982 + write_unlock(&grsec_exec_file_lock);
54983 +
54984 + if (exec_file)
54985 + fput(exec_file);
54986 +}
54987 +
54988 +int
54989 +gr_acl_handle_procpidmem(const struct task_struct *task)
54990 +{
54991 + if (unlikely(!gr_acl_is_enabled()))
54992 + return 0;
54993 +
54994 + if (task != current && task->acl->mode & GR_PROTPROCFD)
54995 + return -EACCES;
54996 +
54997 + return 0;
54998 +}
54999 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
55000 new file mode 100644
55001 index 0000000..58800a7
55002 --- /dev/null
55003 +++ b/grsecurity/gracl_ip.c
55004 @@ -0,0 +1,384 @@
55005 +#include <linux/kernel.h>
55006 +#include <asm/uaccess.h>
55007 +#include <asm/errno.h>
55008 +#include <net/sock.h>
55009 +#include <linux/file.h>
55010 +#include <linux/fs.h>
55011 +#include <linux/net.h>
55012 +#include <linux/in.h>
55013 +#include <linux/skbuff.h>
55014 +#include <linux/ip.h>
55015 +#include <linux/udp.h>
55016 +#include <linux/types.h>
55017 +#include <linux/sched.h>
55018 +#include <linux/netdevice.h>
55019 +#include <linux/inetdevice.h>
55020 +#include <linux/gracl.h>
55021 +#include <linux/grsecurity.h>
55022 +#include <linux/grinternal.h>
55023 +
55024 +#define GR_BIND 0x01
55025 +#define GR_CONNECT 0x02
55026 +#define GR_INVERT 0x04
55027 +#define GR_BINDOVERRIDE 0x08
55028 +#define GR_CONNECTOVERRIDE 0x10
55029 +#define GR_SOCK_FAMILY 0x20
55030 +
55031 +static const char * gr_protocols[IPPROTO_MAX] = {
55032 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
55033 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
55034 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
55035 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
55036 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
55037 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
55038 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
55039 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
55040 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
55041 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
55042 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
55043 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
55044 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
55045 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
55046 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
55047 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
55048 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
55049 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
55050 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
55051 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
55052 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
55053 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
55054 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
55055 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
55056 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
55057 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
55058 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
55059 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
55060 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
55061 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
55062 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
55063 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
55064 + };
55065 +
55066 +static const char * gr_socktypes[SOCK_MAX] = {
55067 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
55068 + "unknown:7", "unknown:8", "unknown:9", "packet"
55069 + };
55070 +
55071 +static const char * gr_sockfamilies[AF_MAX+1] = {
55072 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
55073 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
55074 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
55075 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
55076 + };
55077 +
55078 +const char *
55079 +gr_proto_to_name(unsigned char proto)
55080 +{
55081 + return gr_protocols[proto];
55082 +}
55083 +
55084 +const char *
55085 +gr_socktype_to_name(unsigned char type)
55086 +{
55087 + return gr_socktypes[type];
55088 +}
55089 +
55090 +const char *
55091 +gr_sockfamily_to_name(unsigned char family)
55092 +{
55093 + return gr_sockfamilies[family];
55094 +}
55095 +
55096 +int
55097 +gr_search_socket(const int domain, const int type, const int protocol)
55098 +{
55099 + struct acl_subject_label *curr;
55100 + const struct cred *cred = current_cred();
55101 +
55102 + if (unlikely(!gr_acl_is_enabled()))
55103 + goto exit;
55104 +
55105 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
55106 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
55107 + goto exit; // let the kernel handle it
55108 +
55109 + curr = current->acl;
55110 +
55111 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
55112 + /* the family is allowed, if this is PF_INET allow it only if
55113 + the extra sock type/protocol checks pass */
55114 + if (domain == PF_INET)
55115 + goto inet_check;
55116 + goto exit;
55117 + } else {
55118 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55119 + __u32 fakeip = 0;
55120 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55121 + current->role->roletype, cred->uid,
55122 + cred->gid, current->exec_file ?
55123 + gr_to_filename(current->exec_file->f_path.dentry,
55124 + current->exec_file->f_path.mnt) :
55125 + curr->filename, curr->filename,
55126 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
55127 + &current->signal->saved_ip);
55128 + goto exit;
55129 + }
55130 + goto exit_fail;
55131 + }
55132 +
55133 +inet_check:
55134 + /* the rest of this checking is for IPv4 only */
55135 + if (!curr->ips)
55136 + goto exit;
55137 +
55138 + if ((curr->ip_type & (1 << type)) &&
55139 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
55140 + goto exit;
55141 +
55142 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55143 + /* we don't place acls on raw sockets , and sometimes
55144 + dgram/ip sockets are opened for ioctl and not
55145 + bind/connect, so we'll fake a bind learn log */
55146 + if (type == SOCK_RAW || type == SOCK_PACKET) {
55147 + __u32 fakeip = 0;
55148 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55149 + current->role->roletype, cred->uid,
55150 + cred->gid, current->exec_file ?
55151 + gr_to_filename(current->exec_file->f_path.dentry,
55152 + current->exec_file->f_path.mnt) :
55153 + curr->filename, curr->filename,
55154 + &fakeip, 0, type,
55155 + protocol, GR_CONNECT, &current->signal->saved_ip);
55156 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
55157 + __u32 fakeip = 0;
55158 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55159 + current->role->roletype, cred->uid,
55160 + cred->gid, current->exec_file ?
55161 + gr_to_filename(current->exec_file->f_path.dentry,
55162 + current->exec_file->f_path.mnt) :
55163 + curr->filename, curr->filename,
55164 + &fakeip, 0, type,
55165 + protocol, GR_BIND, &current->signal->saved_ip);
55166 + }
55167 + /* we'll log when they use connect or bind */
55168 + goto exit;
55169 + }
55170 +
55171 +exit_fail:
55172 + if (domain == PF_INET)
55173 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
55174 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
55175 + else
55176 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
55177 + gr_socktype_to_name(type), protocol);
55178 +
55179 + return 0;
55180 +exit:
55181 + return 1;
55182 +}
55183 +
55184 +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)
55185 +{
55186 + if ((ip->mode & mode) &&
55187 + (ip_port >= ip->low) &&
55188 + (ip_port <= ip->high) &&
55189 + ((ntohl(ip_addr) & our_netmask) ==
55190 + (ntohl(our_addr) & our_netmask))
55191 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
55192 + && (ip->type & (1 << type))) {
55193 + if (ip->mode & GR_INVERT)
55194 + return 2; // specifically denied
55195 + else
55196 + return 1; // allowed
55197 + }
55198 +
55199 + return 0; // not specifically allowed, may continue parsing
55200 +}
55201 +
55202 +static int
55203 +gr_search_connectbind(const int full_mode, struct sock *sk,
55204 + struct sockaddr_in *addr, const int type)
55205 +{
55206 + char iface[IFNAMSIZ] = {0};
55207 + struct acl_subject_label *curr;
55208 + struct acl_ip_label *ip;
55209 + struct inet_sock *isk;
55210 + struct net_device *dev;
55211 + struct in_device *idev;
55212 + unsigned long i;
55213 + int ret;
55214 + int mode = full_mode & (GR_BIND | GR_CONNECT);
55215 + __u32 ip_addr = 0;
55216 + __u32 our_addr;
55217 + __u32 our_netmask;
55218 + char *p;
55219 + __u16 ip_port = 0;
55220 + const struct cred *cred = current_cred();
55221 +
55222 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
55223 + return 0;
55224 +
55225 + curr = current->acl;
55226 + isk = inet_sk(sk);
55227 +
55228 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
55229 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
55230 + addr->sin_addr.s_addr = curr->inaddr_any_override;
55231 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
55232 + struct sockaddr_in saddr;
55233 + int err;
55234 +
55235 + saddr.sin_family = AF_INET;
55236 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
55237 + saddr.sin_port = isk->inet_sport;
55238 +
55239 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55240 + if (err)
55241 + return err;
55242 +
55243 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55244 + if (err)
55245 + return err;
55246 + }
55247 +
55248 + if (!curr->ips)
55249 + return 0;
55250 +
55251 + ip_addr = addr->sin_addr.s_addr;
55252 + ip_port = ntohs(addr->sin_port);
55253 +
55254 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55255 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55256 + current->role->roletype, cred->uid,
55257 + cred->gid, current->exec_file ?
55258 + gr_to_filename(current->exec_file->f_path.dentry,
55259 + current->exec_file->f_path.mnt) :
55260 + curr->filename, curr->filename,
55261 + &ip_addr, ip_port, type,
55262 + sk->sk_protocol, mode, &current->signal->saved_ip);
55263 + return 0;
55264 + }
55265 +
55266 + for (i = 0; i < curr->ip_num; i++) {
55267 + ip = *(curr->ips + i);
55268 + if (ip->iface != NULL) {
55269 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
55270 + p = strchr(iface, ':');
55271 + if (p != NULL)
55272 + *p = '\0';
55273 + dev = dev_get_by_name(sock_net(sk), iface);
55274 + if (dev == NULL)
55275 + continue;
55276 + idev = in_dev_get(dev);
55277 + if (idev == NULL) {
55278 + dev_put(dev);
55279 + continue;
55280 + }
55281 + rcu_read_lock();
55282 + for_ifa(idev) {
55283 + if (!strcmp(ip->iface, ifa->ifa_label)) {
55284 + our_addr = ifa->ifa_address;
55285 + our_netmask = 0xffffffff;
55286 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55287 + if (ret == 1) {
55288 + rcu_read_unlock();
55289 + in_dev_put(idev);
55290 + dev_put(dev);
55291 + return 0;
55292 + } else if (ret == 2) {
55293 + rcu_read_unlock();
55294 + in_dev_put(idev);
55295 + dev_put(dev);
55296 + goto denied;
55297 + }
55298 + }
55299 + } endfor_ifa(idev);
55300 + rcu_read_unlock();
55301 + in_dev_put(idev);
55302 + dev_put(dev);
55303 + } else {
55304 + our_addr = ip->addr;
55305 + our_netmask = ip->netmask;
55306 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55307 + if (ret == 1)
55308 + return 0;
55309 + else if (ret == 2)
55310 + goto denied;
55311 + }
55312 + }
55313 +
55314 +denied:
55315 + if (mode == GR_BIND)
55316 + 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));
55317 + else if (mode == GR_CONNECT)
55318 + 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));
55319 +
55320 + return -EACCES;
55321 +}
55322 +
55323 +int
55324 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
55325 +{
55326 + /* always allow disconnection of dgram sockets with connect */
55327 + if (addr->sin_family == AF_UNSPEC)
55328 + return 0;
55329 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
55330 +}
55331 +
55332 +int
55333 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
55334 +{
55335 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
55336 +}
55337 +
55338 +int gr_search_listen(struct socket *sock)
55339 +{
55340 + struct sock *sk = sock->sk;
55341 + struct sockaddr_in addr;
55342 +
55343 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
55344 + addr.sin_port = inet_sk(sk)->inet_sport;
55345 +
55346 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
55347 +}
55348 +
55349 +int gr_search_accept(struct socket *sock)
55350 +{
55351 + struct sock *sk = sock->sk;
55352 + struct sockaddr_in addr;
55353 +
55354 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
55355 + addr.sin_port = inet_sk(sk)->inet_sport;
55356 +
55357 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
55358 +}
55359 +
55360 +int
55361 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
55362 +{
55363 + if (addr)
55364 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
55365 + else {
55366 + struct sockaddr_in sin;
55367 + const struct inet_sock *inet = inet_sk(sk);
55368 +
55369 + sin.sin_addr.s_addr = inet->inet_daddr;
55370 + sin.sin_port = inet->inet_dport;
55371 +
55372 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
55373 + }
55374 +}
55375 +
55376 +int
55377 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
55378 +{
55379 + struct sockaddr_in sin;
55380 +
55381 + if (unlikely(skb->len < sizeof (struct udphdr)))
55382 + return 0; // skip this packet
55383 +
55384 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
55385 + sin.sin_port = udp_hdr(skb)->source;
55386 +
55387 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
55388 +}
55389 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
55390 new file mode 100644
55391 index 0000000..25f54ef
55392 --- /dev/null
55393 +++ b/grsecurity/gracl_learn.c
55394 @@ -0,0 +1,207 @@
55395 +#include <linux/kernel.h>
55396 +#include <linux/mm.h>
55397 +#include <linux/sched.h>
55398 +#include <linux/poll.h>
55399 +#include <linux/string.h>
55400 +#include <linux/file.h>
55401 +#include <linux/types.h>
55402 +#include <linux/vmalloc.h>
55403 +#include <linux/grinternal.h>
55404 +
55405 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
55406 + size_t count, loff_t *ppos);
55407 +extern int gr_acl_is_enabled(void);
55408 +
55409 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
55410 +static int gr_learn_attached;
55411 +
55412 +/* use a 512k buffer */
55413 +#define LEARN_BUFFER_SIZE (512 * 1024)
55414 +
55415 +static DEFINE_SPINLOCK(gr_learn_lock);
55416 +static DEFINE_MUTEX(gr_learn_user_mutex);
55417 +
55418 +/* we need to maintain two buffers, so that the kernel context of grlearn
55419 + uses a semaphore around the userspace copying, and the other kernel contexts
55420 + use a spinlock when copying into the buffer, since they cannot sleep
55421 +*/
55422 +static char *learn_buffer;
55423 +static char *learn_buffer_user;
55424 +static int learn_buffer_len;
55425 +static int learn_buffer_user_len;
55426 +
55427 +static ssize_t
55428 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
55429 +{
55430 + DECLARE_WAITQUEUE(wait, current);
55431 + ssize_t retval = 0;
55432 +
55433 + add_wait_queue(&learn_wait, &wait);
55434 + set_current_state(TASK_INTERRUPTIBLE);
55435 + do {
55436 + mutex_lock(&gr_learn_user_mutex);
55437 + spin_lock(&gr_learn_lock);
55438 + if (learn_buffer_len)
55439 + break;
55440 + spin_unlock(&gr_learn_lock);
55441 + mutex_unlock(&gr_learn_user_mutex);
55442 + if (file->f_flags & O_NONBLOCK) {
55443 + retval = -EAGAIN;
55444 + goto out;
55445 + }
55446 + if (signal_pending(current)) {
55447 + retval = -ERESTARTSYS;
55448 + goto out;
55449 + }
55450 +
55451 + schedule();
55452 + } while (1);
55453 +
55454 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
55455 + learn_buffer_user_len = learn_buffer_len;
55456 + retval = learn_buffer_len;
55457 + learn_buffer_len = 0;
55458 +
55459 + spin_unlock(&gr_learn_lock);
55460 +
55461 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
55462 + retval = -EFAULT;
55463 +
55464 + mutex_unlock(&gr_learn_user_mutex);
55465 +out:
55466 + set_current_state(TASK_RUNNING);
55467 + remove_wait_queue(&learn_wait, &wait);
55468 + return retval;
55469 +}
55470 +
55471 +static unsigned int
55472 +poll_learn(struct file * file, poll_table * wait)
55473 +{
55474 + poll_wait(file, &learn_wait, wait);
55475 +
55476 + if (learn_buffer_len)
55477 + return (POLLIN | POLLRDNORM);
55478 +
55479 + return 0;
55480 +}
55481 +
55482 +void
55483 +gr_clear_learn_entries(void)
55484 +{
55485 + char *tmp;
55486 +
55487 + mutex_lock(&gr_learn_user_mutex);
55488 + spin_lock(&gr_learn_lock);
55489 + tmp = learn_buffer;
55490 + learn_buffer = NULL;
55491 + spin_unlock(&gr_learn_lock);
55492 + if (tmp)
55493 + vfree(tmp);
55494 + if (learn_buffer_user != NULL) {
55495 + vfree(learn_buffer_user);
55496 + learn_buffer_user = NULL;
55497 + }
55498 + learn_buffer_len = 0;
55499 + mutex_unlock(&gr_learn_user_mutex);
55500 +
55501 + return;
55502 +}
55503 +
55504 +void
55505 +gr_add_learn_entry(const char *fmt, ...)
55506 +{
55507 + va_list args;
55508 + unsigned int len;
55509 +
55510 + if (!gr_learn_attached)
55511 + return;
55512 +
55513 + spin_lock(&gr_learn_lock);
55514 +
55515 + /* leave a gap at the end so we know when it's "full" but don't have to
55516 + compute the exact length of the string we're trying to append
55517 + */
55518 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
55519 + spin_unlock(&gr_learn_lock);
55520 + wake_up_interruptible(&learn_wait);
55521 + return;
55522 + }
55523 + if (learn_buffer == NULL) {
55524 + spin_unlock(&gr_learn_lock);
55525 + return;
55526 + }
55527 +
55528 + va_start(args, fmt);
55529 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
55530 + va_end(args);
55531 +
55532 + learn_buffer_len += len + 1;
55533 +
55534 + spin_unlock(&gr_learn_lock);
55535 + wake_up_interruptible(&learn_wait);
55536 +
55537 + return;
55538 +}
55539 +
55540 +static int
55541 +open_learn(struct inode *inode, struct file *file)
55542 +{
55543 + if (file->f_mode & FMODE_READ && gr_learn_attached)
55544 + return -EBUSY;
55545 + if (file->f_mode & FMODE_READ) {
55546 + int retval = 0;
55547 + mutex_lock(&gr_learn_user_mutex);
55548 + if (learn_buffer == NULL)
55549 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
55550 + if (learn_buffer_user == NULL)
55551 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
55552 + if (learn_buffer == NULL) {
55553 + retval = -ENOMEM;
55554 + goto out_error;
55555 + }
55556 + if (learn_buffer_user == NULL) {
55557 + retval = -ENOMEM;
55558 + goto out_error;
55559 + }
55560 + learn_buffer_len = 0;
55561 + learn_buffer_user_len = 0;
55562 + gr_learn_attached = 1;
55563 +out_error:
55564 + mutex_unlock(&gr_learn_user_mutex);
55565 + return retval;
55566 + }
55567 + return 0;
55568 +}
55569 +
55570 +static int
55571 +close_learn(struct inode *inode, struct file *file)
55572 +{
55573 + if (file->f_mode & FMODE_READ) {
55574 + char *tmp = NULL;
55575 + mutex_lock(&gr_learn_user_mutex);
55576 + spin_lock(&gr_learn_lock);
55577 + tmp = learn_buffer;
55578 + learn_buffer = NULL;
55579 + spin_unlock(&gr_learn_lock);
55580 + if (tmp)
55581 + vfree(tmp);
55582 + if (learn_buffer_user != NULL) {
55583 + vfree(learn_buffer_user);
55584 + learn_buffer_user = NULL;
55585 + }
55586 + learn_buffer_len = 0;
55587 + learn_buffer_user_len = 0;
55588 + gr_learn_attached = 0;
55589 + mutex_unlock(&gr_learn_user_mutex);
55590 + }
55591 +
55592 + return 0;
55593 +}
55594 +
55595 +const struct file_operations grsec_fops = {
55596 + .read = read_learn,
55597 + .write = write_grsec_handler,
55598 + .open = open_learn,
55599 + .release = close_learn,
55600 + .poll = poll_learn,
55601 +};
55602 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
55603 new file mode 100644
55604 index 0000000..39645c9
55605 --- /dev/null
55606 +++ b/grsecurity/gracl_res.c
55607 @@ -0,0 +1,68 @@
55608 +#include <linux/kernel.h>
55609 +#include <linux/sched.h>
55610 +#include <linux/gracl.h>
55611 +#include <linux/grinternal.h>
55612 +
55613 +static const char *restab_log[] = {
55614 + [RLIMIT_CPU] = "RLIMIT_CPU",
55615 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
55616 + [RLIMIT_DATA] = "RLIMIT_DATA",
55617 + [RLIMIT_STACK] = "RLIMIT_STACK",
55618 + [RLIMIT_CORE] = "RLIMIT_CORE",
55619 + [RLIMIT_RSS] = "RLIMIT_RSS",
55620 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
55621 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
55622 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
55623 + [RLIMIT_AS] = "RLIMIT_AS",
55624 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
55625 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
55626 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
55627 + [RLIMIT_NICE] = "RLIMIT_NICE",
55628 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
55629 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
55630 + [GR_CRASH_RES] = "RLIMIT_CRASH"
55631 +};
55632 +
55633 +void
55634 +gr_log_resource(const struct task_struct *task,
55635 + const int res, const unsigned long wanted, const int gt)
55636 +{
55637 + const struct cred *cred;
55638 + unsigned long rlim;
55639 +
55640 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
55641 + return;
55642 +
55643 + // not yet supported resource
55644 + if (unlikely(!restab_log[res]))
55645 + return;
55646 +
55647 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
55648 + rlim = task_rlimit_max(task, res);
55649 + else
55650 + rlim = task_rlimit(task, res);
55651 +
55652 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
55653 + return;
55654 +
55655 + rcu_read_lock();
55656 + cred = __task_cred(task);
55657 +
55658 + if (res == RLIMIT_NPROC &&
55659 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
55660 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
55661 + goto out_rcu_unlock;
55662 + else if (res == RLIMIT_MEMLOCK &&
55663 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
55664 + goto out_rcu_unlock;
55665 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
55666 + goto out_rcu_unlock;
55667 + rcu_read_unlock();
55668 +
55669 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
55670 +
55671 + return;
55672 +out_rcu_unlock:
55673 + rcu_read_unlock();
55674 + return;
55675 +}
55676 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
55677 new file mode 100644
55678 index 0000000..5556be3
55679 --- /dev/null
55680 +++ b/grsecurity/gracl_segv.c
55681 @@ -0,0 +1,299 @@
55682 +#include <linux/kernel.h>
55683 +#include <linux/mm.h>
55684 +#include <asm/uaccess.h>
55685 +#include <asm/errno.h>
55686 +#include <asm/mman.h>
55687 +#include <net/sock.h>
55688 +#include <linux/file.h>
55689 +#include <linux/fs.h>
55690 +#include <linux/net.h>
55691 +#include <linux/in.h>
55692 +#include <linux/slab.h>
55693 +#include <linux/types.h>
55694 +#include <linux/sched.h>
55695 +#include <linux/timer.h>
55696 +#include <linux/gracl.h>
55697 +#include <linux/grsecurity.h>
55698 +#include <linux/grinternal.h>
55699 +
55700 +static struct crash_uid *uid_set;
55701 +static unsigned short uid_used;
55702 +static DEFINE_SPINLOCK(gr_uid_lock);
55703 +extern rwlock_t gr_inode_lock;
55704 +extern struct acl_subject_label *
55705 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
55706 + struct acl_role_label *role);
55707 +
55708 +#ifdef CONFIG_BTRFS_FS
55709 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
55710 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
55711 +#endif
55712 +
55713 +static inline dev_t __get_dev(const struct dentry *dentry)
55714 +{
55715 +#ifdef CONFIG_BTRFS_FS
55716 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
55717 + return get_btrfs_dev_from_inode(dentry->d_inode);
55718 + else
55719 +#endif
55720 + return dentry->d_inode->i_sb->s_dev;
55721 +}
55722 +
55723 +int
55724 +gr_init_uidset(void)
55725 +{
55726 + uid_set =
55727 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
55728 + uid_used = 0;
55729 +
55730 + return uid_set ? 1 : 0;
55731 +}
55732 +
55733 +void
55734 +gr_free_uidset(void)
55735 +{
55736 + if (uid_set)
55737 + kfree(uid_set);
55738 +
55739 + return;
55740 +}
55741 +
55742 +int
55743 +gr_find_uid(const uid_t uid)
55744 +{
55745 + struct crash_uid *tmp = uid_set;
55746 + uid_t buid;
55747 + int low = 0, high = uid_used - 1, mid;
55748 +
55749 + while (high >= low) {
55750 + mid = (low + high) >> 1;
55751 + buid = tmp[mid].uid;
55752 + if (buid == uid)
55753 + return mid;
55754 + if (buid > uid)
55755 + high = mid - 1;
55756 + if (buid < uid)
55757 + low = mid + 1;
55758 + }
55759 +
55760 + return -1;
55761 +}
55762 +
55763 +static __inline__ void
55764 +gr_insertsort(void)
55765 +{
55766 + unsigned short i, j;
55767 + struct crash_uid index;
55768 +
55769 + for (i = 1; i < uid_used; i++) {
55770 + index = uid_set[i];
55771 + j = i;
55772 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
55773 + uid_set[j] = uid_set[j - 1];
55774 + j--;
55775 + }
55776 + uid_set[j] = index;
55777 + }
55778 +
55779 + return;
55780 +}
55781 +
55782 +static __inline__ void
55783 +gr_insert_uid(const uid_t uid, const unsigned long expires)
55784 +{
55785 + int loc;
55786 +
55787 + if (uid_used == GR_UIDTABLE_MAX)
55788 + return;
55789 +
55790 + loc = gr_find_uid(uid);
55791 +
55792 + if (loc >= 0) {
55793 + uid_set[loc].expires = expires;
55794 + return;
55795 + }
55796 +
55797 + uid_set[uid_used].uid = uid;
55798 + uid_set[uid_used].expires = expires;
55799 + uid_used++;
55800 +
55801 + gr_insertsort();
55802 +
55803 + return;
55804 +}
55805 +
55806 +void
55807 +gr_remove_uid(const unsigned short loc)
55808 +{
55809 + unsigned short i;
55810 +
55811 + for (i = loc + 1; i < uid_used; i++)
55812 + uid_set[i - 1] = uid_set[i];
55813 +
55814 + uid_used--;
55815 +
55816 + return;
55817 +}
55818 +
55819 +int
55820 +gr_check_crash_uid(const uid_t uid)
55821 +{
55822 + int loc;
55823 + int ret = 0;
55824 +
55825 + if (unlikely(!gr_acl_is_enabled()))
55826 + return 0;
55827 +
55828 + spin_lock(&gr_uid_lock);
55829 + loc = gr_find_uid(uid);
55830 +
55831 + if (loc < 0)
55832 + goto out_unlock;
55833 +
55834 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
55835 + gr_remove_uid(loc);
55836 + else
55837 + ret = 1;
55838 +
55839 +out_unlock:
55840 + spin_unlock(&gr_uid_lock);
55841 + return ret;
55842 +}
55843 +
55844 +static __inline__ int
55845 +proc_is_setxid(const struct cred *cred)
55846 +{
55847 + if (cred->uid != cred->euid || cred->uid != cred->suid ||
55848 + cred->uid != cred->fsuid)
55849 + return 1;
55850 + if (cred->gid != cred->egid || cred->gid != cred->sgid ||
55851 + cred->gid != cred->fsgid)
55852 + return 1;
55853 +
55854 + return 0;
55855 +}
55856 +
55857 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
55858 +
55859 +void
55860 +gr_handle_crash(struct task_struct *task, const int sig)
55861 +{
55862 + struct acl_subject_label *curr;
55863 + struct task_struct *tsk, *tsk2;
55864 + const struct cred *cred;
55865 + const struct cred *cred2;
55866 +
55867 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
55868 + return;
55869 +
55870 + if (unlikely(!gr_acl_is_enabled()))
55871 + return;
55872 +
55873 + curr = task->acl;
55874 +
55875 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
55876 + return;
55877 +
55878 + if (time_before_eq(curr->expires, get_seconds())) {
55879 + curr->expires = 0;
55880 + curr->crashes = 0;
55881 + }
55882 +
55883 + curr->crashes++;
55884 +
55885 + if (!curr->expires)
55886 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
55887 +
55888 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
55889 + time_after(curr->expires, get_seconds())) {
55890 + rcu_read_lock();
55891 + cred = __task_cred(task);
55892 + if (cred->uid && proc_is_setxid(cred)) {
55893 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
55894 + spin_lock(&gr_uid_lock);
55895 + gr_insert_uid(cred->uid, curr->expires);
55896 + spin_unlock(&gr_uid_lock);
55897 + curr->expires = 0;
55898 + curr->crashes = 0;
55899 + read_lock(&tasklist_lock);
55900 + do_each_thread(tsk2, tsk) {
55901 + cred2 = __task_cred(tsk);
55902 + if (tsk != task && cred2->uid == cred->uid)
55903 + gr_fake_force_sig(SIGKILL, tsk);
55904 + } while_each_thread(tsk2, tsk);
55905 + read_unlock(&tasklist_lock);
55906 + } else {
55907 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
55908 + read_lock(&tasklist_lock);
55909 + read_lock(&grsec_exec_file_lock);
55910 + do_each_thread(tsk2, tsk) {
55911 + if (likely(tsk != task)) {
55912 + // if this thread has the same subject as the one that triggered
55913 + // RES_CRASH and it's the same binary, kill it
55914 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
55915 + gr_fake_force_sig(SIGKILL, tsk);
55916 + }
55917 + } while_each_thread(tsk2, tsk);
55918 + read_unlock(&grsec_exec_file_lock);
55919 + read_unlock(&tasklist_lock);
55920 + }
55921 + rcu_read_unlock();
55922 + }
55923 +
55924 + return;
55925 +}
55926 +
55927 +int
55928 +gr_check_crash_exec(const struct file *filp)
55929 +{
55930 + struct acl_subject_label *curr;
55931 +
55932 + if (unlikely(!gr_acl_is_enabled()))
55933 + return 0;
55934 +
55935 + read_lock(&gr_inode_lock);
55936 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
55937 + __get_dev(filp->f_path.dentry),
55938 + current->role);
55939 + read_unlock(&gr_inode_lock);
55940 +
55941 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
55942 + (!curr->crashes && !curr->expires))
55943 + return 0;
55944 +
55945 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
55946 + time_after(curr->expires, get_seconds()))
55947 + return 1;
55948 + else if (time_before_eq(curr->expires, get_seconds())) {
55949 + curr->crashes = 0;
55950 + curr->expires = 0;
55951 + }
55952 +
55953 + return 0;
55954 +}
55955 +
55956 +void
55957 +gr_handle_alertkill(struct task_struct *task)
55958 +{
55959 + struct acl_subject_label *curracl;
55960 + __u32 curr_ip;
55961 + struct task_struct *p, *p2;
55962 +
55963 + if (unlikely(!gr_acl_is_enabled()))
55964 + return;
55965 +
55966 + curracl = task->acl;
55967 + curr_ip = task->signal->curr_ip;
55968 +
55969 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
55970 + read_lock(&tasklist_lock);
55971 + do_each_thread(p2, p) {
55972 + if (p->signal->curr_ip == curr_ip)
55973 + gr_fake_force_sig(SIGKILL, p);
55974 + } while_each_thread(p2, p);
55975 + read_unlock(&tasklist_lock);
55976 + } else if (curracl->mode & GR_KILLPROC)
55977 + gr_fake_force_sig(SIGKILL, task);
55978 +
55979 + return;
55980 +}
55981 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
55982 new file mode 100644
55983 index 0000000..9d83a69
55984 --- /dev/null
55985 +++ b/grsecurity/gracl_shm.c
55986 @@ -0,0 +1,40 @@
55987 +#include <linux/kernel.h>
55988 +#include <linux/mm.h>
55989 +#include <linux/sched.h>
55990 +#include <linux/file.h>
55991 +#include <linux/ipc.h>
55992 +#include <linux/gracl.h>
55993 +#include <linux/grsecurity.h>
55994 +#include <linux/grinternal.h>
55995 +
55996 +int
55997 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
55998 + const time_t shm_createtime, const uid_t cuid, const int shmid)
55999 +{
56000 + struct task_struct *task;
56001 +
56002 + if (!gr_acl_is_enabled())
56003 + return 1;
56004 +
56005 + rcu_read_lock();
56006 + read_lock(&tasklist_lock);
56007 +
56008 + task = find_task_by_vpid(shm_cprid);
56009 +
56010 + if (unlikely(!task))
56011 + task = find_task_by_vpid(shm_lapid);
56012 +
56013 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
56014 + (task->pid == shm_lapid)) &&
56015 + (task->acl->mode & GR_PROTSHM) &&
56016 + (task->acl != current->acl))) {
56017 + read_unlock(&tasklist_lock);
56018 + rcu_read_unlock();
56019 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
56020 + return 0;
56021 + }
56022 + read_unlock(&tasklist_lock);
56023 + rcu_read_unlock();
56024 +
56025 + return 1;
56026 +}
56027 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
56028 new file mode 100644
56029 index 0000000..bc0be01
56030 --- /dev/null
56031 +++ b/grsecurity/grsec_chdir.c
56032 @@ -0,0 +1,19 @@
56033 +#include <linux/kernel.h>
56034 +#include <linux/sched.h>
56035 +#include <linux/fs.h>
56036 +#include <linux/file.h>
56037 +#include <linux/grsecurity.h>
56038 +#include <linux/grinternal.h>
56039 +
56040 +void
56041 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
56042 +{
56043 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
56044 + if ((grsec_enable_chdir && grsec_enable_group &&
56045 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
56046 + !grsec_enable_group)) {
56047 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
56048 + }
56049 +#endif
56050 + return;
56051 +}
56052 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
56053 new file mode 100644
56054 index 0000000..9807ee2
56055 --- /dev/null
56056 +++ b/grsecurity/grsec_chroot.c
56057 @@ -0,0 +1,368 @@
56058 +#include <linux/kernel.h>
56059 +#include <linux/module.h>
56060 +#include <linux/sched.h>
56061 +#include <linux/file.h>
56062 +#include <linux/fs.h>
56063 +#include <linux/mount.h>
56064 +#include <linux/types.h>
56065 +#include "../fs/mount.h"
56066 +#include <linux/grsecurity.h>
56067 +#include <linux/grinternal.h>
56068 +
56069 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
56070 +{
56071 +#ifdef CONFIG_GRKERNSEC
56072 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
56073 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
56074 + task->gr_is_chrooted = 1;
56075 + else
56076 + task->gr_is_chrooted = 0;
56077 +
56078 + task->gr_chroot_dentry = path->dentry;
56079 +#endif
56080 + return;
56081 +}
56082 +
56083 +void gr_clear_chroot_entries(struct task_struct *task)
56084 +{
56085 +#ifdef CONFIG_GRKERNSEC
56086 + task->gr_is_chrooted = 0;
56087 + task->gr_chroot_dentry = NULL;
56088 +#endif
56089 + return;
56090 +}
56091 +
56092 +int
56093 +gr_handle_chroot_unix(const pid_t pid)
56094 +{
56095 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
56096 + struct task_struct *p;
56097 +
56098 + if (unlikely(!grsec_enable_chroot_unix))
56099 + return 1;
56100 +
56101 + if (likely(!proc_is_chrooted(current)))
56102 + return 1;
56103 +
56104 + rcu_read_lock();
56105 + read_lock(&tasklist_lock);
56106 + p = find_task_by_vpid_unrestricted(pid);
56107 + if (unlikely(p && !have_same_root(current, p))) {
56108 + read_unlock(&tasklist_lock);
56109 + rcu_read_unlock();
56110 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
56111 + return 0;
56112 + }
56113 + read_unlock(&tasklist_lock);
56114 + rcu_read_unlock();
56115 +#endif
56116 + return 1;
56117 +}
56118 +
56119 +int
56120 +gr_handle_chroot_nice(void)
56121 +{
56122 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56123 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
56124 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
56125 + return -EPERM;
56126 + }
56127 +#endif
56128 + return 0;
56129 +}
56130 +
56131 +int
56132 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
56133 +{
56134 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56135 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
56136 + && proc_is_chrooted(current)) {
56137 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
56138 + return -EACCES;
56139 + }
56140 +#endif
56141 + return 0;
56142 +}
56143 +
56144 +int
56145 +gr_handle_chroot_rawio(const struct inode *inode)
56146 +{
56147 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56148 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
56149 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
56150 + return 1;
56151 +#endif
56152 + return 0;
56153 +}
56154 +
56155 +int
56156 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
56157 +{
56158 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56159 + struct task_struct *p;
56160 + int ret = 0;
56161 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
56162 + return ret;
56163 +
56164 + read_lock(&tasklist_lock);
56165 + do_each_pid_task(pid, type, p) {
56166 + if (!have_same_root(current, p)) {
56167 + ret = 1;
56168 + goto out;
56169 + }
56170 + } while_each_pid_task(pid, type, p);
56171 +out:
56172 + read_unlock(&tasklist_lock);
56173 + return ret;
56174 +#endif
56175 + return 0;
56176 +}
56177 +
56178 +int
56179 +gr_pid_is_chrooted(struct task_struct *p)
56180 +{
56181 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56182 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
56183 + return 0;
56184 +
56185 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
56186 + !have_same_root(current, p)) {
56187 + return 1;
56188 + }
56189 +#endif
56190 + return 0;
56191 +}
56192 +
56193 +EXPORT_SYMBOL(gr_pid_is_chrooted);
56194 +
56195 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
56196 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
56197 +{
56198 + struct path path, currentroot;
56199 + int ret = 0;
56200 +
56201 + path.dentry = (struct dentry *)u_dentry;
56202 + path.mnt = (struct vfsmount *)u_mnt;
56203 + get_fs_root(current->fs, &currentroot);
56204 + if (path_is_under(&path, &currentroot))
56205 + ret = 1;
56206 + path_put(&currentroot);
56207 +
56208 + return ret;
56209 +}
56210 +#endif
56211 +
56212 +int
56213 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
56214 +{
56215 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
56216 + if (!grsec_enable_chroot_fchdir)
56217 + return 1;
56218 +
56219 + if (!proc_is_chrooted(current))
56220 + return 1;
56221 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
56222 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
56223 + return 0;
56224 + }
56225 +#endif
56226 + return 1;
56227 +}
56228 +
56229 +int
56230 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56231 + const time_t shm_createtime)
56232 +{
56233 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
56234 + struct task_struct *p;
56235 + time_t starttime;
56236 +
56237 + if (unlikely(!grsec_enable_chroot_shmat))
56238 + return 1;
56239 +
56240 + if (likely(!proc_is_chrooted(current)))
56241 + return 1;
56242 +
56243 + rcu_read_lock();
56244 + read_lock(&tasklist_lock);
56245 +
56246 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
56247 + starttime = p->start_time.tv_sec;
56248 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
56249 + if (have_same_root(current, p)) {
56250 + goto allow;
56251 + } else {
56252 + read_unlock(&tasklist_lock);
56253 + rcu_read_unlock();
56254 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56255 + return 0;
56256 + }
56257 + }
56258 + /* creator exited, pid reuse, fall through to next check */
56259 + }
56260 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
56261 + if (unlikely(!have_same_root(current, p))) {
56262 + read_unlock(&tasklist_lock);
56263 + rcu_read_unlock();
56264 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56265 + return 0;
56266 + }
56267 + }
56268 +
56269 +allow:
56270 + read_unlock(&tasklist_lock);
56271 + rcu_read_unlock();
56272 +#endif
56273 + return 1;
56274 +}
56275 +
56276 +void
56277 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
56278 +{
56279 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
56280 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
56281 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
56282 +#endif
56283 + return;
56284 +}
56285 +
56286 +int
56287 +gr_handle_chroot_mknod(const struct dentry *dentry,
56288 + const struct vfsmount *mnt, const int mode)
56289 +{
56290 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
56291 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
56292 + proc_is_chrooted(current)) {
56293 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
56294 + return -EPERM;
56295 + }
56296 +#endif
56297 + return 0;
56298 +}
56299 +
56300 +int
56301 +gr_handle_chroot_mount(const struct dentry *dentry,
56302 + const struct vfsmount *mnt, const char *dev_name)
56303 +{
56304 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
56305 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
56306 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
56307 + return -EPERM;
56308 + }
56309 +#endif
56310 + return 0;
56311 +}
56312 +
56313 +int
56314 +gr_handle_chroot_pivot(void)
56315 +{
56316 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
56317 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
56318 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
56319 + return -EPERM;
56320 + }
56321 +#endif
56322 + return 0;
56323 +}
56324 +
56325 +int
56326 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
56327 +{
56328 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
56329 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
56330 + !gr_is_outside_chroot(dentry, mnt)) {
56331 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
56332 + return -EPERM;
56333 + }
56334 +#endif
56335 + return 0;
56336 +}
56337 +
56338 +extern const char *captab_log[];
56339 +extern int captab_log_entries;
56340 +
56341 +int
56342 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
56343 +{
56344 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56345 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
56346 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
56347 + if (cap_raised(chroot_caps, cap)) {
56348 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
56349 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
56350 + }
56351 + return 0;
56352 + }
56353 + }
56354 +#endif
56355 + return 1;
56356 +}
56357 +
56358 +int
56359 +gr_chroot_is_capable(const int cap)
56360 +{
56361 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56362 + return gr_task_chroot_is_capable(current, current_cred(), cap);
56363 +#endif
56364 + return 1;
56365 +}
56366 +
56367 +int
56368 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
56369 +{
56370 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56371 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
56372 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
56373 + if (cap_raised(chroot_caps, cap)) {
56374 + return 0;
56375 + }
56376 + }
56377 +#endif
56378 + return 1;
56379 +}
56380 +
56381 +int
56382 +gr_chroot_is_capable_nolog(const int cap)
56383 +{
56384 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56385 + return gr_task_chroot_is_capable_nolog(current, cap);
56386 +#endif
56387 + return 1;
56388 +}
56389 +
56390 +int
56391 +gr_handle_chroot_sysctl(const int op)
56392 +{
56393 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
56394 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
56395 + proc_is_chrooted(current))
56396 + return -EACCES;
56397 +#endif
56398 + return 0;
56399 +}
56400 +
56401 +void
56402 +gr_handle_chroot_chdir(struct path *path)
56403 +{
56404 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
56405 + if (grsec_enable_chroot_chdir)
56406 + set_fs_pwd(current->fs, path);
56407 +#endif
56408 + return;
56409 +}
56410 +
56411 +int
56412 +gr_handle_chroot_chmod(const struct dentry *dentry,
56413 + const struct vfsmount *mnt, const int mode)
56414 +{
56415 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
56416 + /* allow chmod +s on directories, but not files */
56417 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
56418 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
56419 + proc_is_chrooted(current)) {
56420 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
56421 + return -EPERM;
56422 + }
56423 +#endif
56424 + return 0;
56425 +}
56426 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
56427 new file mode 100644
56428 index 0000000..213ad8b
56429 --- /dev/null
56430 +++ b/grsecurity/grsec_disabled.c
56431 @@ -0,0 +1,437 @@
56432 +#include <linux/kernel.h>
56433 +#include <linux/module.h>
56434 +#include <linux/sched.h>
56435 +#include <linux/file.h>
56436 +#include <linux/fs.h>
56437 +#include <linux/kdev_t.h>
56438 +#include <linux/net.h>
56439 +#include <linux/in.h>
56440 +#include <linux/ip.h>
56441 +#include <linux/skbuff.h>
56442 +#include <linux/sysctl.h>
56443 +
56444 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56445 +void
56446 +pax_set_initial_flags(struct linux_binprm *bprm)
56447 +{
56448 + return;
56449 +}
56450 +#endif
56451 +
56452 +#ifdef CONFIG_SYSCTL
56453 +__u32
56454 +gr_handle_sysctl(const struct ctl_table * table, const int op)
56455 +{
56456 + return 0;
56457 +}
56458 +#endif
56459 +
56460 +#ifdef CONFIG_TASKSTATS
56461 +int gr_is_taskstats_denied(int pid)
56462 +{
56463 + return 0;
56464 +}
56465 +#endif
56466 +
56467 +int
56468 +gr_acl_is_enabled(void)
56469 +{
56470 + return 0;
56471 +}
56472 +
56473 +void
56474 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
56475 +{
56476 + return;
56477 +}
56478 +
56479 +int
56480 +gr_handle_rawio(const struct inode *inode)
56481 +{
56482 + return 0;
56483 +}
56484 +
56485 +void
56486 +gr_acl_handle_psacct(struct task_struct *task, const long code)
56487 +{
56488 + return;
56489 +}
56490 +
56491 +int
56492 +gr_handle_ptrace(struct task_struct *task, const long request)
56493 +{
56494 + return 0;
56495 +}
56496 +
56497 +int
56498 +gr_handle_proc_ptrace(struct task_struct *task)
56499 +{
56500 + return 0;
56501 +}
56502 +
56503 +void
56504 +gr_learn_resource(const struct task_struct *task,
56505 + const int res, const unsigned long wanted, const int gt)
56506 +{
56507 + return;
56508 +}
56509 +
56510 +int
56511 +gr_set_acls(const int type)
56512 +{
56513 + return 0;
56514 +}
56515 +
56516 +int
56517 +gr_check_hidden_task(const struct task_struct *tsk)
56518 +{
56519 + return 0;
56520 +}
56521 +
56522 +int
56523 +gr_check_protected_task(const struct task_struct *task)
56524 +{
56525 + return 0;
56526 +}
56527 +
56528 +int
56529 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
56530 +{
56531 + return 0;
56532 +}
56533 +
56534 +void
56535 +gr_copy_label(struct task_struct *tsk)
56536 +{
56537 + return;
56538 +}
56539 +
56540 +void
56541 +gr_set_pax_flags(struct task_struct *task)
56542 +{
56543 + return;
56544 +}
56545 +
56546 +int
56547 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
56548 + const int unsafe_share)
56549 +{
56550 + return 0;
56551 +}
56552 +
56553 +void
56554 +gr_handle_delete(const ino_t ino, const dev_t dev)
56555 +{
56556 + return;
56557 +}
56558 +
56559 +void
56560 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
56561 +{
56562 + return;
56563 +}
56564 +
56565 +void
56566 +gr_handle_crash(struct task_struct *task, const int sig)
56567 +{
56568 + return;
56569 +}
56570 +
56571 +int
56572 +gr_check_crash_exec(const struct file *filp)
56573 +{
56574 + return 0;
56575 +}
56576 +
56577 +int
56578 +gr_check_crash_uid(const uid_t uid)
56579 +{
56580 + return 0;
56581 +}
56582 +
56583 +void
56584 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
56585 + struct dentry *old_dentry,
56586 + struct dentry *new_dentry,
56587 + struct vfsmount *mnt, const __u8 replace)
56588 +{
56589 + return;
56590 +}
56591 +
56592 +int
56593 +gr_search_socket(const int family, const int type, const int protocol)
56594 +{
56595 + return 1;
56596 +}
56597 +
56598 +int
56599 +gr_search_connectbind(const int mode, const struct socket *sock,
56600 + const struct sockaddr_in *addr)
56601 +{
56602 + return 0;
56603 +}
56604 +
56605 +void
56606 +gr_handle_alertkill(struct task_struct *task)
56607 +{
56608 + return;
56609 +}
56610 +
56611 +__u32
56612 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
56613 +{
56614 + return 1;
56615 +}
56616 +
56617 +__u32
56618 +gr_acl_handle_hidden_file(const struct dentry * dentry,
56619 + const struct vfsmount * mnt)
56620 +{
56621 + return 1;
56622 +}
56623 +
56624 +__u32
56625 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
56626 + int acc_mode)
56627 +{
56628 + return 1;
56629 +}
56630 +
56631 +__u32
56632 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
56633 +{
56634 + return 1;
56635 +}
56636 +
56637 +__u32
56638 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
56639 +{
56640 + return 1;
56641 +}
56642 +
56643 +int
56644 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
56645 + unsigned int *vm_flags)
56646 +{
56647 + return 1;
56648 +}
56649 +
56650 +__u32
56651 +gr_acl_handle_truncate(const struct dentry * dentry,
56652 + const struct vfsmount * mnt)
56653 +{
56654 + return 1;
56655 +}
56656 +
56657 +__u32
56658 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
56659 +{
56660 + return 1;
56661 +}
56662 +
56663 +__u32
56664 +gr_acl_handle_access(const struct dentry * dentry,
56665 + const struct vfsmount * mnt, const int fmode)
56666 +{
56667 + return 1;
56668 +}
56669 +
56670 +__u32
56671 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
56672 + umode_t *mode)
56673 +{
56674 + return 1;
56675 +}
56676 +
56677 +__u32
56678 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
56679 +{
56680 + return 1;
56681 +}
56682 +
56683 +__u32
56684 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
56685 +{
56686 + return 1;
56687 +}
56688 +
56689 +void
56690 +grsecurity_init(void)
56691 +{
56692 + return;
56693 +}
56694 +
56695 +umode_t gr_acl_umask(void)
56696 +{
56697 + return 0;
56698 +}
56699 +
56700 +__u32
56701 +gr_acl_handle_mknod(const struct dentry * new_dentry,
56702 + const struct dentry * parent_dentry,
56703 + const struct vfsmount * parent_mnt,
56704 + const int mode)
56705 +{
56706 + return 1;
56707 +}
56708 +
56709 +__u32
56710 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
56711 + const struct dentry * parent_dentry,
56712 + const struct vfsmount * parent_mnt)
56713 +{
56714 + return 1;
56715 +}
56716 +
56717 +__u32
56718 +gr_acl_handle_symlink(const struct dentry * new_dentry,
56719 + const struct dentry * parent_dentry,
56720 + const struct vfsmount * parent_mnt, const char *from)
56721 +{
56722 + return 1;
56723 +}
56724 +
56725 +__u32
56726 +gr_acl_handle_link(const struct dentry * new_dentry,
56727 + const struct dentry * parent_dentry,
56728 + const struct vfsmount * parent_mnt,
56729 + const struct dentry * old_dentry,
56730 + const struct vfsmount * old_mnt, const char *to)
56731 +{
56732 + return 1;
56733 +}
56734 +
56735 +int
56736 +gr_acl_handle_rename(const struct dentry *new_dentry,
56737 + const struct dentry *parent_dentry,
56738 + const struct vfsmount *parent_mnt,
56739 + const struct dentry *old_dentry,
56740 + const struct inode *old_parent_inode,
56741 + const struct vfsmount *old_mnt, const char *newname)
56742 +{
56743 + return 0;
56744 +}
56745 +
56746 +int
56747 +gr_acl_handle_filldir(const struct file *file, const char *name,
56748 + const int namelen, const ino_t ino)
56749 +{
56750 + return 1;
56751 +}
56752 +
56753 +int
56754 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56755 + const time_t shm_createtime, const uid_t cuid, const int shmid)
56756 +{
56757 + return 1;
56758 +}
56759 +
56760 +int
56761 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
56762 +{
56763 + return 0;
56764 +}
56765 +
56766 +int
56767 +gr_search_accept(const struct socket *sock)
56768 +{
56769 + return 0;
56770 +}
56771 +
56772 +int
56773 +gr_search_listen(const struct socket *sock)
56774 +{
56775 + return 0;
56776 +}
56777 +
56778 +int
56779 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
56780 +{
56781 + return 0;
56782 +}
56783 +
56784 +__u32
56785 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
56786 +{
56787 + return 1;
56788 +}
56789 +
56790 +__u32
56791 +gr_acl_handle_creat(const struct dentry * dentry,
56792 + const struct dentry * p_dentry,
56793 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
56794 + const int imode)
56795 +{
56796 + return 1;
56797 +}
56798 +
56799 +void
56800 +gr_acl_handle_exit(void)
56801 +{
56802 + return;
56803 +}
56804 +
56805 +int
56806 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
56807 +{
56808 + return 1;
56809 +}
56810 +
56811 +void
56812 +gr_set_role_label(const uid_t uid, const gid_t gid)
56813 +{
56814 + return;
56815 +}
56816 +
56817 +int
56818 +gr_acl_handle_procpidmem(const struct task_struct *task)
56819 +{
56820 + return 0;
56821 +}
56822 +
56823 +int
56824 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
56825 +{
56826 + return 0;
56827 +}
56828 +
56829 +int
56830 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
56831 +{
56832 + return 0;
56833 +}
56834 +
56835 +void
56836 +gr_set_kernel_label(struct task_struct *task)
56837 +{
56838 + return;
56839 +}
56840 +
56841 +int
56842 +gr_check_user_change(int real, int effective, int fs)
56843 +{
56844 + return 0;
56845 +}
56846 +
56847 +int
56848 +gr_check_group_change(int real, int effective, int fs)
56849 +{
56850 + return 0;
56851 +}
56852 +
56853 +int gr_acl_enable_at_secure(void)
56854 +{
56855 + return 0;
56856 +}
56857 +
56858 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
56859 +{
56860 + return dentry->d_inode->i_sb->s_dev;
56861 +}
56862 +
56863 +EXPORT_SYMBOL(gr_learn_resource);
56864 +EXPORT_SYMBOL(gr_set_kernel_label);
56865 +#ifdef CONFIG_SECURITY
56866 +EXPORT_SYMBOL(gr_check_user_change);
56867 +EXPORT_SYMBOL(gr_check_group_change);
56868 +#endif
56869 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
56870 new file mode 100644
56871 index 0000000..abfa971
56872 --- /dev/null
56873 +++ b/grsecurity/grsec_exec.c
56874 @@ -0,0 +1,174 @@
56875 +#include <linux/kernel.h>
56876 +#include <linux/sched.h>
56877 +#include <linux/file.h>
56878 +#include <linux/binfmts.h>
56879 +#include <linux/fs.h>
56880 +#include <linux/types.h>
56881 +#include <linux/grdefs.h>
56882 +#include <linux/grsecurity.h>
56883 +#include <linux/grinternal.h>
56884 +#include <linux/capability.h>
56885 +#include <linux/module.h>
56886 +
56887 +#include <asm/uaccess.h>
56888 +
56889 +#ifdef CONFIG_GRKERNSEC_EXECLOG
56890 +static char gr_exec_arg_buf[132];
56891 +static DEFINE_MUTEX(gr_exec_arg_mutex);
56892 +#endif
56893 +
56894 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
56895 +
56896 +void
56897 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
56898 +{
56899 +#ifdef CONFIG_GRKERNSEC_EXECLOG
56900 + char *grarg = gr_exec_arg_buf;
56901 + unsigned int i, x, execlen = 0;
56902 + char c;
56903 +
56904 + if (!((grsec_enable_execlog && grsec_enable_group &&
56905 + in_group_p(grsec_audit_gid))
56906 + || (grsec_enable_execlog && !grsec_enable_group)))
56907 + return;
56908 +
56909 + mutex_lock(&gr_exec_arg_mutex);
56910 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
56911 +
56912 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
56913 + const char __user *p;
56914 + unsigned int len;
56915 +
56916 + p = get_user_arg_ptr(argv, i);
56917 + if (IS_ERR(p))
56918 + goto log;
56919 +
56920 + len = strnlen_user(p, 128 - execlen);
56921 + if (len > 128 - execlen)
56922 + len = 128 - execlen;
56923 + else if (len > 0)
56924 + len--;
56925 + if (copy_from_user(grarg + execlen, p, len))
56926 + goto log;
56927 +
56928 + /* rewrite unprintable characters */
56929 + for (x = 0; x < len; x++) {
56930 + c = *(grarg + execlen + x);
56931 + if (c < 32 || c > 126)
56932 + *(grarg + execlen + x) = ' ';
56933 + }
56934 +
56935 + execlen += len;
56936 + *(grarg + execlen) = ' ';
56937 + *(grarg + execlen + 1) = '\0';
56938 + execlen++;
56939 + }
56940 +
56941 + log:
56942 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
56943 + bprm->file->f_path.mnt, grarg);
56944 + mutex_unlock(&gr_exec_arg_mutex);
56945 +#endif
56946 + return;
56947 +}
56948 +
56949 +#ifdef CONFIG_GRKERNSEC
56950 +extern int gr_acl_is_capable(const int cap);
56951 +extern int gr_acl_is_capable_nolog(const int cap);
56952 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
56953 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
56954 +extern int gr_chroot_is_capable(const int cap);
56955 +extern int gr_chroot_is_capable_nolog(const int cap);
56956 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
56957 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
56958 +#endif
56959 +
56960 +const char *captab_log[] = {
56961 + "CAP_CHOWN",
56962 + "CAP_DAC_OVERRIDE",
56963 + "CAP_DAC_READ_SEARCH",
56964 + "CAP_FOWNER",
56965 + "CAP_FSETID",
56966 + "CAP_KILL",
56967 + "CAP_SETGID",
56968 + "CAP_SETUID",
56969 + "CAP_SETPCAP",
56970 + "CAP_LINUX_IMMUTABLE",
56971 + "CAP_NET_BIND_SERVICE",
56972 + "CAP_NET_BROADCAST",
56973 + "CAP_NET_ADMIN",
56974 + "CAP_NET_RAW",
56975 + "CAP_IPC_LOCK",
56976 + "CAP_IPC_OWNER",
56977 + "CAP_SYS_MODULE",
56978 + "CAP_SYS_RAWIO",
56979 + "CAP_SYS_CHROOT",
56980 + "CAP_SYS_PTRACE",
56981 + "CAP_SYS_PACCT",
56982 + "CAP_SYS_ADMIN",
56983 + "CAP_SYS_BOOT",
56984 + "CAP_SYS_NICE",
56985 + "CAP_SYS_RESOURCE",
56986 + "CAP_SYS_TIME",
56987 + "CAP_SYS_TTY_CONFIG",
56988 + "CAP_MKNOD",
56989 + "CAP_LEASE",
56990 + "CAP_AUDIT_WRITE",
56991 + "CAP_AUDIT_CONTROL",
56992 + "CAP_SETFCAP",
56993 + "CAP_MAC_OVERRIDE",
56994 + "CAP_MAC_ADMIN",
56995 + "CAP_SYSLOG",
56996 + "CAP_WAKE_ALARM"
56997 +};
56998 +
56999 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
57000 +
57001 +int gr_is_capable(const int cap)
57002 +{
57003 +#ifdef CONFIG_GRKERNSEC
57004 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
57005 + return 1;
57006 + return 0;
57007 +#else
57008 + return 1;
57009 +#endif
57010 +}
57011 +
57012 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57013 +{
57014 +#ifdef CONFIG_GRKERNSEC
57015 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
57016 + return 1;
57017 + return 0;
57018 +#else
57019 + return 1;
57020 +#endif
57021 +}
57022 +
57023 +int gr_is_capable_nolog(const int cap)
57024 +{
57025 +#ifdef CONFIG_GRKERNSEC
57026 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
57027 + return 1;
57028 + return 0;
57029 +#else
57030 + return 1;
57031 +#endif
57032 +}
57033 +
57034 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
57035 +{
57036 +#ifdef CONFIG_GRKERNSEC
57037 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
57038 + return 1;
57039 + return 0;
57040 +#else
57041 + return 1;
57042 +#endif
57043 +}
57044 +
57045 +EXPORT_SYMBOL(gr_is_capable);
57046 +EXPORT_SYMBOL(gr_is_capable_nolog);
57047 +EXPORT_SYMBOL(gr_task_is_capable);
57048 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
57049 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
57050 new file mode 100644
57051 index 0000000..d3ee748
57052 --- /dev/null
57053 +++ b/grsecurity/grsec_fifo.c
57054 @@ -0,0 +1,24 @@
57055 +#include <linux/kernel.h>
57056 +#include <linux/sched.h>
57057 +#include <linux/fs.h>
57058 +#include <linux/file.h>
57059 +#include <linux/grinternal.h>
57060 +
57061 +int
57062 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
57063 + const struct dentry *dir, const int flag, const int acc_mode)
57064 +{
57065 +#ifdef CONFIG_GRKERNSEC_FIFO
57066 + const struct cred *cred = current_cred();
57067 +
57068 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
57069 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
57070 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
57071 + (cred->fsuid != dentry->d_inode->i_uid)) {
57072 + if (!inode_permission(dentry->d_inode, acc_mode))
57073 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
57074 + return -EACCES;
57075 + }
57076 +#endif
57077 + return 0;
57078 +}
57079 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
57080 new file mode 100644
57081 index 0000000..8ca18bf
57082 --- /dev/null
57083 +++ b/grsecurity/grsec_fork.c
57084 @@ -0,0 +1,23 @@
57085 +#include <linux/kernel.h>
57086 +#include <linux/sched.h>
57087 +#include <linux/grsecurity.h>
57088 +#include <linux/grinternal.h>
57089 +#include <linux/errno.h>
57090 +
57091 +void
57092 +gr_log_forkfail(const int retval)
57093 +{
57094 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
57095 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
57096 + switch (retval) {
57097 + case -EAGAIN:
57098 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
57099 + break;
57100 + case -ENOMEM:
57101 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
57102 + break;
57103 + }
57104 + }
57105 +#endif
57106 + return;
57107 +}
57108 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
57109 new file mode 100644
57110 index 0000000..05a6015
57111 --- /dev/null
57112 +++ b/grsecurity/grsec_init.c
57113 @@ -0,0 +1,283 @@
57114 +#include <linux/kernel.h>
57115 +#include <linux/sched.h>
57116 +#include <linux/mm.h>
57117 +#include <linux/gracl.h>
57118 +#include <linux/slab.h>
57119 +#include <linux/vmalloc.h>
57120 +#include <linux/percpu.h>
57121 +#include <linux/module.h>
57122 +
57123 +int grsec_enable_ptrace_readexec;
57124 +int grsec_enable_setxid;
57125 +int grsec_enable_symlinkown;
57126 +int grsec_symlinkown_gid;
57127 +int grsec_enable_brute;
57128 +int grsec_enable_link;
57129 +int grsec_enable_dmesg;
57130 +int grsec_enable_harden_ptrace;
57131 +int grsec_enable_fifo;
57132 +int grsec_enable_execlog;
57133 +int grsec_enable_signal;
57134 +int grsec_enable_forkfail;
57135 +int grsec_enable_audit_ptrace;
57136 +int grsec_enable_time;
57137 +int grsec_enable_audit_textrel;
57138 +int grsec_enable_group;
57139 +int grsec_audit_gid;
57140 +int grsec_enable_chdir;
57141 +int grsec_enable_mount;
57142 +int grsec_enable_rofs;
57143 +int grsec_enable_chroot_findtask;
57144 +int grsec_enable_chroot_mount;
57145 +int grsec_enable_chroot_shmat;
57146 +int grsec_enable_chroot_fchdir;
57147 +int grsec_enable_chroot_double;
57148 +int grsec_enable_chroot_pivot;
57149 +int grsec_enable_chroot_chdir;
57150 +int grsec_enable_chroot_chmod;
57151 +int grsec_enable_chroot_mknod;
57152 +int grsec_enable_chroot_nice;
57153 +int grsec_enable_chroot_execlog;
57154 +int grsec_enable_chroot_caps;
57155 +int grsec_enable_chroot_sysctl;
57156 +int grsec_enable_chroot_unix;
57157 +int grsec_enable_tpe;
57158 +int grsec_tpe_gid;
57159 +int grsec_enable_blackhole;
57160 +#ifdef CONFIG_IPV6_MODULE
57161 +EXPORT_SYMBOL(grsec_enable_blackhole);
57162 +#endif
57163 +int grsec_lastack_retries;
57164 +int grsec_enable_tpe_all;
57165 +int grsec_enable_tpe_invert;
57166 +int grsec_enable_socket_all;
57167 +int grsec_socket_all_gid;
57168 +int grsec_enable_socket_client;
57169 +int grsec_socket_client_gid;
57170 +int grsec_enable_socket_server;
57171 +int grsec_socket_server_gid;
57172 +int grsec_resource_logging;
57173 +int grsec_disable_privio;
57174 +int grsec_enable_log_rwxmaps;
57175 +int grsec_lock;
57176 +
57177 +DEFINE_SPINLOCK(grsec_alert_lock);
57178 +unsigned long grsec_alert_wtime = 0;
57179 +unsigned long grsec_alert_fyet = 0;
57180 +
57181 +DEFINE_SPINLOCK(grsec_audit_lock);
57182 +
57183 +DEFINE_RWLOCK(grsec_exec_file_lock);
57184 +
57185 +char *gr_shared_page[4];
57186 +
57187 +char *gr_alert_log_fmt;
57188 +char *gr_audit_log_fmt;
57189 +char *gr_alert_log_buf;
57190 +char *gr_audit_log_buf;
57191 +
57192 +extern struct gr_arg *gr_usermode;
57193 +extern unsigned char *gr_system_salt;
57194 +extern unsigned char *gr_system_sum;
57195 +
57196 +void __init
57197 +grsecurity_init(void)
57198 +{
57199 + int j;
57200 + /* create the per-cpu shared pages */
57201 +
57202 +#ifdef CONFIG_X86
57203 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
57204 +#endif
57205 +
57206 + for (j = 0; j < 4; j++) {
57207 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
57208 + if (gr_shared_page[j] == NULL) {
57209 + panic("Unable to allocate grsecurity shared page");
57210 + return;
57211 + }
57212 + }
57213 +
57214 + /* allocate log buffers */
57215 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
57216 + if (!gr_alert_log_fmt) {
57217 + panic("Unable to allocate grsecurity alert log format buffer");
57218 + return;
57219 + }
57220 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
57221 + if (!gr_audit_log_fmt) {
57222 + panic("Unable to allocate grsecurity audit log format buffer");
57223 + return;
57224 + }
57225 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57226 + if (!gr_alert_log_buf) {
57227 + panic("Unable to allocate grsecurity alert log buffer");
57228 + return;
57229 + }
57230 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57231 + if (!gr_audit_log_buf) {
57232 + panic("Unable to allocate grsecurity audit log buffer");
57233 + return;
57234 + }
57235 +
57236 + /* allocate memory for authentication structure */
57237 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
57238 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
57239 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
57240 +
57241 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
57242 + panic("Unable to allocate grsecurity authentication structure");
57243 + return;
57244 + }
57245 +
57246 +
57247 +#ifdef CONFIG_GRKERNSEC_IO
57248 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
57249 + grsec_disable_privio = 1;
57250 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57251 + grsec_disable_privio = 1;
57252 +#else
57253 + grsec_disable_privio = 0;
57254 +#endif
57255 +#endif
57256 +
57257 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
57258 + /* for backward compatibility, tpe_invert always defaults to on if
57259 + enabled in the kernel
57260 + */
57261 + grsec_enable_tpe_invert = 1;
57262 +#endif
57263 +
57264 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57265 +#ifndef CONFIG_GRKERNSEC_SYSCTL
57266 + grsec_lock = 1;
57267 +#endif
57268 +
57269 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
57270 + grsec_enable_audit_textrel = 1;
57271 +#endif
57272 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57273 + grsec_enable_log_rwxmaps = 1;
57274 +#endif
57275 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
57276 + grsec_enable_group = 1;
57277 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
57278 +#endif
57279 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
57280 + grsec_enable_ptrace_readexec = 1;
57281 +#endif
57282 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57283 + grsec_enable_chdir = 1;
57284 +#endif
57285 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57286 + grsec_enable_harden_ptrace = 1;
57287 +#endif
57288 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57289 + grsec_enable_mount = 1;
57290 +#endif
57291 +#ifdef CONFIG_GRKERNSEC_LINK
57292 + grsec_enable_link = 1;
57293 +#endif
57294 +#ifdef CONFIG_GRKERNSEC_BRUTE
57295 + grsec_enable_brute = 1;
57296 +#endif
57297 +#ifdef CONFIG_GRKERNSEC_DMESG
57298 + grsec_enable_dmesg = 1;
57299 +#endif
57300 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
57301 + grsec_enable_blackhole = 1;
57302 + grsec_lastack_retries = 4;
57303 +#endif
57304 +#ifdef CONFIG_GRKERNSEC_FIFO
57305 + grsec_enable_fifo = 1;
57306 +#endif
57307 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57308 + grsec_enable_execlog = 1;
57309 +#endif
57310 +#ifdef CONFIG_GRKERNSEC_SETXID
57311 + grsec_enable_setxid = 1;
57312 +#endif
57313 +#ifdef CONFIG_GRKERNSEC_SIGNAL
57314 + grsec_enable_signal = 1;
57315 +#endif
57316 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
57317 + grsec_enable_forkfail = 1;
57318 +#endif
57319 +#ifdef CONFIG_GRKERNSEC_TIME
57320 + grsec_enable_time = 1;
57321 +#endif
57322 +#ifdef CONFIG_GRKERNSEC_RESLOG
57323 + grsec_resource_logging = 1;
57324 +#endif
57325 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57326 + grsec_enable_chroot_findtask = 1;
57327 +#endif
57328 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57329 + grsec_enable_chroot_unix = 1;
57330 +#endif
57331 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57332 + grsec_enable_chroot_mount = 1;
57333 +#endif
57334 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57335 + grsec_enable_chroot_fchdir = 1;
57336 +#endif
57337 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57338 + grsec_enable_chroot_shmat = 1;
57339 +#endif
57340 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
57341 + grsec_enable_audit_ptrace = 1;
57342 +#endif
57343 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57344 + grsec_enable_chroot_double = 1;
57345 +#endif
57346 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57347 + grsec_enable_chroot_pivot = 1;
57348 +#endif
57349 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57350 + grsec_enable_chroot_chdir = 1;
57351 +#endif
57352 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57353 + grsec_enable_chroot_chmod = 1;
57354 +#endif
57355 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57356 + grsec_enable_chroot_mknod = 1;
57357 +#endif
57358 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57359 + grsec_enable_chroot_nice = 1;
57360 +#endif
57361 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57362 + grsec_enable_chroot_execlog = 1;
57363 +#endif
57364 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57365 + grsec_enable_chroot_caps = 1;
57366 +#endif
57367 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57368 + grsec_enable_chroot_sysctl = 1;
57369 +#endif
57370 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
57371 + grsec_enable_symlinkown = 1;
57372 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
57373 +#endif
57374 +#ifdef CONFIG_GRKERNSEC_TPE
57375 + grsec_enable_tpe = 1;
57376 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
57377 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
57378 + grsec_enable_tpe_all = 1;
57379 +#endif
57380 +#endif
57381 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
57382 + grsec_enable_socket_all = 1;
57383 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
57384 +#endif
57385 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
57386 + grsec_enable_socket_client = 1;
57387 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
57388 +#endif
57389 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
57390 + grsec_enable_socket_server = 1;
57391 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
57392 +#endif
57393 +#endif
57394 +
57395 + return;
57396 +}
57397 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
57398 new file mode 100644
57399 index 0000000..35a96d1
57400 --- /dev/null
57401 +++ b/grsecurity/grsec_link.c
57402 @@ -0,0 +1,59 @@
57403 +#include <linux/kernel.h>
57404 +#include <linux/sched.h>
57405 +#include <linux/fs.h>
57406 +#include <linux/file.h>
57407 +#include <linux/grinternal.h>
57408 +
57409 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
57410 +{
57411 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
57412 + const struct inode *link_inode = link->dentry->d_inode;
57413 +
57414 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
57415 + /* ignore root-owned links, e.g. /proc/self */
57416 + link_inode->i_uid &&
57417 + link_inode->i_uid != target->i_uid) {
57418 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
57419 + return 1;
57420 + }
57421 +#endif
57422 + return 0;
57423 +}
57424 +
57425 +int
57426 +gr_handle_follow_link(const struct inode *parent,
57427 + const struct inode *inode,
57428 + const struct dentry *dentry, const struct vfsmount *mnt)
57429 +{
57430 +#ifdef CONFIG_GRKERNSEC_LINK
57431 + const struct cred *cred = current_cred();
57432 +
57433 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
57434 + (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
57435 + (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
57436 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
57437 + return -EACCES;
57438 + }
57439 +#endif
57440 + return 0;
57441 +}
57442 +
57443 +int
57444 +gr_handle_hardlink(const struct dentry *dentry,
57445 + const struct vfsmount *mnt,
57446 + struct inode *inode, const int mode, const char *to)
57447 +{
57448 +#ifdef CONFIG_GRKERNSEC_LINK
57449 + const struct cred *cred = current_cred();
57450 +
57451 + if (grsec_enable_link && cred->fsuid != inode->i_uid &&
57452 + (!S_ISREG(mode) || (mode & S_ISUID) ||
57453 + ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
57454 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
57455 + !capable(CAP_FOWNER) && cred->uid) {
57456 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
57457 + return -EPERM;
57458 + }
57459 +#endif
57460 + return 0;
57461 +}
57462 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
57463 new file mode 100644
57464 index 0000000..a45d2e9
57465 --- /dev/null
57466 +++ b/grsecurity/grsec_log.c
57467 @@ -0,0 +1,322 @@
57468 +#include <linux/kernel.h>
57469 +#include <linux/sched.h>
57470 +#include <linux/file.h>
57471 +#include <linux/tty.h>
57472 +#include <linux/fs.h>
57473 +#include <linux/grinternal.h>
57474 +
57475 +#ifdef CONFIG_TREE_PREEMPT_RCU
57476 +#define DISABLE_PREEMPT() preempt_disable()
57477 +#define ENABLE_PREEMPT() preempt_enable()
57478 +#else
57479 +#define DISABLE_PREEMPT()
57480 +#define ENABLE_PREEMPT()
57481 +#endif
57482 +
57483 +#define BEGIN_LOCKS(x) \
57484 + DISABLE_PREEMPT(); \
57485 + rcu_read_lock(); \
57486 + read_lock(&tasklist_lock); \
57487 + read_lock(&grsec_exec_file_lock); \
57488 + if (x != GR_DO_AUDIT) \
57489 + spin_lock(&grsec_alert_lock); \
57490 + else \
57491 + spin_lock(&grsec_audit_lock)
57492 +
57493 +#define END_LOCKS(x) \
57494 + if (x != GR_DO_AUDIT) \
57495 + spin_unlock(&grsec_alert_lock); \
57496 + else \
57497 + spin_unlock(&grsec_audit_lock); \
57498 + read_unlock(&grsec_exec_file_lock); \
57499 + read_unlock(&tasklist_lock); \
57500 + rcu_read_unlock(); \
57501 + ENABLE_PREEMPT(); \
57502 + if (x == GR_DONT_AUDIT) \
57503 + gr_handle_alertkill(current)
57504 +
57505 +enum {
57506 + FLOODING,
57507 + NO_FLOODING
57508 +};
57509 +
57510 +extern char *gr_alert_log_fmt;
57511 +extern char *gr_audit_log_fmt;
57512 +extern char *gr_alert_log_buf;
57513 +extern char *gr_audit_log_buf;
57514 +
57515 +static int gr_log_start(int audit)
57516 +{
57517 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
57518 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
57519 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57520 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
57521 + unsigned long curr_secs = get_seconds();
57522 +
57523 + if (audit == GR_DO_AUDIT)
57524 + goto set_fmt;
57525 +
57526 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
57527 + grsec_alert_wtime = curr_secs;
57528 + grsec_alert_fyet = 0;
57529 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
57530 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
57531 + grsec_alert_fyet++;
57532 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
57533 + grsec_alert_wtime = curr_secs;
57534 + grsec_alert_fyet++;
57535 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
57536 + return FLOODING;
57537 + }
57538 + else return FLOODING;
57539 +
57540 +set_fmt:
57541 +#endif
57542 + memset(buf, 0, PAGE_SIZE);
57543 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
57544 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
57545 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
57546 + } else if (current->signal->curr_ip) {
57547 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
57548 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
57549 + } else if (gr_acl_is_enabled()) {
57550 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
57551 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
57552 + } else {
57553 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
57554 + strcpy(buf, fmt);
57555 + }
57556 +
57557 + return NO_FLOODING;
57558 +}
57559 +
57560 +static void gr_log_middle(int audit, const char *msg, va_list ap)
57561 + __attribute__ ((format (printf, 2, 0)));
57562 +
57563 +static void gr_log_middle(int audit, const char *msg, va_list ap)
57564 +{
57565 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57566 + unsigned int len = strlen(buf);
57567 +
57568 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
57569 +
57570 + return;
57571 +}
57572 +
57573 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
57574 + __attribute__ ((format (printf, 2, 3)));
57575 +
57576 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
57577 +{
57578 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57579 + unsigned int len = strlen(buf);
57580 + va_list ap;
57581 +
57582 + va_start(ap, msg);
57583 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
57584 + va_end(ap);
57585 +
57586 + return;
57587 +}
57588 +
57589 +static void gr_log_end(int audit, int append_default)
57590 +{
57591 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57592 +
57593 + if (append_default) {
57594 + unsigned int len = strlen(buf);
57595 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
57596 + }
57597 +
57598 + printk("%s\n", buf);
57599 +
57600 + return;
57601 +}
57602 +
57603 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
57604 +{
57605 + int logtype;
57606 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
57607 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
57608 + void *voidptr = NULL;
57609 + int num1 = 0, num2 = 0;
57610 + unsigned long ulong1 = 0, ulong2 = 0;
57611 + struct dentry *dentry = NULL;
57612 + struct vfsmount *mnt = NULL;
57613 + struct file *file = NULL;
57614 + struct task_struct *task = NULL;
57615 + const struct cred *cred, *pcred;
57616 + va_list ap;
57617 +
57618 + BEGIN_LOCKS(audit);
57619 + logtype = gr_log_start(audit);
57620 + if (logtype == FLOODING) {
57621 + END_LOCKS(audit);
57622 + return;
57623 + }
57624 + va_start(ap, argtypes);
57625 + switch (argtypes) {
57626 + case GR_TTYSNIFF:
57627 + task = va_arg(ap, struct task_struct *);
57628 + 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);
57629 + break;
57630 + case GR_SYSCTL_HIDDEN:
57631 + str1 = va_arg(ap, char *);
57632 + gr_log_middle_varargs(audit, msg, result, str1);
57633 + break;
57634 + case GR_RBAC:
57635 + dentry = va_arg(ap, struct dentry *);
57636 + mnt = va_arg(ap, struct vfsmount *);
57637 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
57638 + break;
57639 + case GR_RBAC_STR:
57640 + dentry = va_arg(ap, struct dentry *);
57641 + mnt = va_arg(ap, struct vfsmount *);
57642 + str1 = va_arg(ap, char *);
57643 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
57644 + break;
57645 + case GR_STR_RBAC:
57646 + str1 = va_arg(ap, char *);
57647 + dentry = va_arg(ap, struct dentry *);
57648 + mnt = va_arg(ap, struct vfsmount *);
57649 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
57650 + break;
57651 + case GR_RBAC_MODE2:
57652 + dentry = va_arg(ap, struct dentry *);
57653 + mnt = va_arg(ap, struct vfsmount *);
57654 + str1 = va_arg(ap, char *);
57655 + str2 = va_arg(ap, char *);
57656 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
57657 + break;
57658 + case GR_RBAC_MODE3:
57659 + dentry = va_arg(ap, struct dentry *);
57660 + mnt = va_arg(ap, struct vfsmount *);
57661 + str1 = va_arg(ap, char *);
57662 + str2 = va_arg(ap, char *);
57663 + str3 = va_arg(ap, char *);
57664 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
57665 + break;
57666 + case GR_FILENAME:
57667 + dentry = va_arg(ap, struct dentry *);
57668 + mnt = va_arg(ap, struct vfsmount *);
57669 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
57670 + break;
57671 + case GR_STR_FILENAME:
57672 + str1 = va_arg(ap, char *);
57673 + dentry = va_arg(ap, struct dentry *);
57674 + mnt = va_arg(ap, struct vfsmount *);
57675 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
57676 + break;
57677 + case GR_FILENAME_STR:
57678 + dentry = va_arg(ap, struct dentry *);
57679 + mnt = va_arg(ap, struct vfsmount *);
57680 + str1 = va_arg(ap, char *);
57681 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
57682 + break;
57683 + case GR_FILENAME_TWO_INT:
57684 + dentry = va_arg(ap, struct dentry *);
57685 + mnt = va_arg(ap, struct vfsmount *);
57686 + num1 = va_arg(ap, int);
57687 + num2 = va_arg(ap, int);
57688 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
57689 + break;
57690 + case GR_FILENAME_TWO_INT_STR:
57691 + dentry = va_arg(ap, struct dentry *);
57692 + mnt = va_arg(ap, struct vfsmount *);
57693 + num1 = va_arg(ap, int);
57694 + num2 = va_arg(ap, int);
57695 + str1 = va_arg(ap, char *);
57696 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
57697 + break;
57698 + case GR_TEXTREL:
57699 + file = va_arg(ap, struct file *);
57700 + ulong1 = va_arg(ap, unsigned long);
57701 + ulong2 = va_arg(ap, unsigned long);
57702 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
57703 + break;
57704 + case GR_PTRACE:
57705 + task = va_arg(ap, struct task_struct *);
57706 + 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);
57707 + break;
57708 + case GR_RESOURCE:
57709 + task = va_arg(ap, struct task_struct *);
57710 + cred = __task_cred(task);
57711 + pcred = __task_cred(task->real_parent);
57712 + ulong1 = va_arg(ap, unsigned long);
57713 + str1 = va_arg(ap, char *);
57714 + ulong2 = va_arg(ap, unsigned long);
57715 + 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);
57716 + break;
57717 + case GR_CAP:
57718 + task = va_arg(ap, struct task_struct *);
57719 + cred = __task_cred(task);
57720 + pcred = __task_cred(task->real_parent);
57721 + str1 = va_arg(ap, char *);
57722 + 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);
57723 + break;
57724 + case GR_SIG:
57725 + str1 = va_arg(ap, char *);
57726 + voidptr = va_arg(ap, void *);
57727 + gr_log_middle_varargs(audit, msg, str1, voidptr);
57728 + break;
57729 + case GR_SIG2:
57730 + task = va_arg(ap, struct task_struct *);
57731 + cred = __task_cred(task);
57732 + pcred = __task_cred(task->real_parent);
57733 + num1 = va_arg(ap, int);
57734 + 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);
57735 + break;
57736 + case GR_CRASH1:
57737 + task = va_arg(ap, struct task_struct *);
57738 + cred = __task_cred(task);
57739 + pcred = __task_cred(task->real_parent);
57740 + ulong1 = va_arg(ap, unsigned long);
57741 + 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);
57742 + break;
57743 + case GR_CRASH2:
57744 + task = va_arg(ap, struct task_struct *);
57745 + cred = __task_cred(task);
57746 + pcred = __task_cred(task->real_parent);
57747 + ulong1 = va_arg(ap, unsigned long);
57748 + 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);
57749 + break;
57750 + case GR_RWXMAP:
57751 + file = va_arg(ap, struct file *);
57752 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
57753 + break;
57754 + case GR_PSACCT:
57755 + {
57756 + unsigned int wday, cday;
57757 + __u8 whr, chr;
57758 + __u8 wmin, cmin;
57759 + __u8 wsec, csec;
57760 + char cur_tty[64] = { 0 };
57761 + char parent_tty[64] = { 0 };
57762 +
57763 + task = va_arg(ap, struct task_struct *);
57764 + wday = va_arg(ap, unsigned int);
57765 + cday = va_arg(ap, unsigned int);
57766 + whr = va_arg(ap, int);
57767 + chr = va_arg(ap, int);
57768 + wmin = va_arg(ap, int);
57769 + cmin = va_arg(ap, int);
57770 + wsec = va_arg(ap, int);
57771 + csec = va_arg(ap, int);
57772 + ulong1 = va_arg(ap, unsigned long);
57773 + cred = __task_cred(task);
57774 + pcred = __task_cred(task->real_parent);
57775 +
57776 + 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);
57777 + }
57778 + break;
57779 + default:
57780 + gr_log_middle(audit, msg, ap);
57781 + }
57782 + va_end(ap);
57783 + // these don't need DEFAULTSECARGS printed on the end
57784 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
57785 + gr_log_end(audit, 0);
57786 + else
57787 + gr_log_end(audit, 1);
57788 + END_LOCKS(audit);
57789 +}
57790 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
57791 new file mode 100644
57792 index 0000000..f536303
57793 --- /dev/null
57794 +++ b/grsecurity/grsec_mem.c
57795 @@ -0,0 +1,40 @@
57796 +#include <linux/kernel.h>
57797 +#include <linux/sched.h>
57798 +#include <linux/mm.h>
57799 +#include <linux/mman.h>
57800 +#include <linux/grinternal.h>
57801 +
57802 +void
57803 +gr_handle_ioperm(void)
57804 +{
57805 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
57806 + return;
57807 +}
57808 +
57809 +void
57810 +gr_handle_iopl(void)
57811 +{
57812 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
57813 + return;
57814 +}
57815 +
57816 +void
57817 +gr_handle_mem_readwrite(u64 from, u64 to)
57818 +{
57819 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
57820 + return;
57821 +}
57822 +
57823 +void
57824 +gr_handle_vm86(void)
57825 +{
57826 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
57827 + return;
57828 +}
57829 +
57830 +void
57831 +gr_log_badprocpid(const char *entry)
57832 +{
57833 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
57834 + return;
57835 +}
57836 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
57837 new file mode 100644
57838 index 0000000..2131422
57839 --- /dev/null
57840 +++ b/grsecurity/grsec_mount.c
57841 @@ -0,0 +1,62 @@
57842 +#include <linux/kernel.h>
57843 +#include <linux/sched.h>
57844 +#include <linux/mount.h>
57845 +#include <linux/grsecurity.h>
57846 +#include <linux/grinternal.h>
57847 +
57848 +void
57849 +gr_log_remount(const char *devname, const int retval)
57850 +{
57851 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57852 + if (grsec_enable_mount && (retval >= 0))
57853 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
57854 +#endif
57855 + return;
57856 +}
57857 +
57858 +void
57859 +gr_log_unmount(const char *devname, const int retval)
57860 +{
57861 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57862 + if (grsec_enable_mount && (retval >= 0))
57863 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
57864 +#endif
57865 + return;
57866 +}
57867 +
57868 +void
57869 +gr_log_mount(const char *from, const char *to, const int retval)
57870 +{
57871 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57872 + if (grsec_enable_mount && (retval >= 0))
57873 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
57874 +#endif
57875 + return;
57876 +}
57877 +
57878 +int
57879 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
57880 +{
57881 +#ifdef CONFIG_GRKERNSEC_ROFS
57882 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
57883 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
57884 + return -EPERM;
57885 + } else
57886 + return 0;
57887 +#endif
57888 + return 0;
57889 +}
57890 +
57891 +int
57892 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
57893 +{
57894 +#ifdef CONFIG_GRKERNSEC_ROFS
57895 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
57896 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
57897 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
57898 + return -EPERM;
57899 + } else
57900 + return 0;
57901 +#endif
57902 + return 0;
57903 +}
57904 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
57905 new file mode 100644
57906 index 0000000..a3b12a0
57907 --- /dev/null
57908 +++ b/grsecurity/grsec_pax.c
57909 @@ -0,0 +1,36 @@
57910 +#include <linux/kernel.h>
57911 +#include <linux/sched.h>
57912 +#include <linux/mm.h>
57913 +#include <linux/file.h>
57914 +#include <linux/grinternal.h>
57915 +#include <linux/grsecurity.h>
57916 +
57917 +void
57918 +gr_log_textrel(struct vm_area_struct * vma)
57919 +{
57920 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
57921 + if (grsec_enable_audit_textrel)
57922 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
57923 +#endif
57924 + return;
57925 +}
57926 +
57927 +void
57928 +gr_log_rwxmmap(struct file *file)
57929 +{
57930 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57931 + if (grsec_enable_log_rwxmaps)
57932 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
57933 +#endif
57934 + return;
57935 +}
57936 +
57937 +void
57938 +gr_log_rwxmprotect(struct file *file)
57939 +{
57940 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57941 + if (grsec_enable_log_rwxmaps)
57942 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
57943 +#endif
57944 + return;
57945 +}
57946 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
57947 new file mode 100644
57948 index 0000000..f7f29aa
57949 --- /dev/null
57950 +++ b/grsecurity/grsec_ptrace.c
57951 @@ -0,0 +1,30 @@
57952 +#include <linux/kernel.h>
57953 +#include <linux/sched.h>
57954 +#include <linux/grinternal.h>
57955 +#include <linux/security.h>
57956 +
57957 +void
57958 +gr_audit_ptrace(struct task_struct *task)
57959 +{
57960 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
57961 + if (grsec_enable_audit_ptrace)
57962 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
57963 +#endif
57964 + return;
57965 +}
57966 +
57967 +int
57968 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
57969 +{
57970 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
57971 + const struct dentry *dentry = file->f_path.dentry;
57972 + const struct vfsmount *mnt = file->f_path.mnt;
57973 +
57974 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
57975 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
57976 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
57977 + return -EACCES;
57978 + }
57979 +#endif
57980 + return 0;
57981 +}
57982 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
57983 new file mode 100644
57984 index 0000000..7a5b2de
57985 --- /dev/null
57986 +++ b/grsecurity/grsec_sig.c
57987 @@ -0,0 +1,207 @@
57988 +#include <linux/kernel.h>
57989 +#include <linux/sched.h>
57990 +#include <linux/delay.h>
57991 +#include <linux/grsecurity.h>
57992 +#include <linux/grinternal.h>
57993 +#include <linux/hardirq.h>
57994 +
57995 +char *signames[] = {
57996 + [SIGSEGV] = "Segmentation fault",
57997 + [SIGILL] = "Illegal instruction",
57998 + [SIGABRT] = "Abort",
57999 + [SIGBUS] = "Invalid alignment/Bus error"
58000 +};
58001 +
58002 +void
58003 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
58004 +{
58005 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58006 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
58007 + (sig == SIGABRT) || (sig == SIGBUS))) {
58008 + if (t->pid == current->pid) {
58009 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
58010 + } else {
58011 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
58012 + }
58013 + }
58014 +#endif
58015 + return;
58016 +}
58017 +
58018 +int
58019 +gr_handle_signal(const struct task_struct *p, const int sig)
58020 +{
58021 +#ifdef CONFIG_GRKERNSEC
58022 + /* ignore the 0 signal for protected task checks */
58023 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
58024 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
58025 + return -EPERM;
58026 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
58027 + return -EPERM;
58028 + }
58029 +#endif
58030 + return 0;
58031 +}
58032 +
58033 +#ifdef CONFIG_GRKERNSEC
58034 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
58035 +
58036 +int gr_fake_force_sig(int sig, struct task_struct *t)
58037 +{
58038 + unsigned long int flags;
58039 + int ret, blocked, ignored;
58040 + struct k_sigaction *action;
58041 +
58042 + spin_lock_irqsave(&t->sighand->siglock, flags);
58043 + action = &t->sighand->action[sig-1];
58044 + ignored = action->sa.sa_handler == SIG_IGN;
58045 + blocked = sigismember(&t->blocked, sig);
58046 + if (blocked || ignored) {
58047 + action->sa.sa_handler = SIG_DFL;
58048 + if (blocked) {
58049 + sigdelset(&t->blocked, sig);
58050 + recalc_sigpending_and_wake(t);
58051 + }
58052 + }
58053 + if (action->sa.sa_handler == SIG_DFL)
58054 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
58055 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
58056 +
58057 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
58058 +
58059 + return ret;
58060 +}
58061 +#endif
58062 +
58063 +#ifdef CONFIG_GRKERNSEC_BRUTE
58064 +#define GR_USER_BAN_TIME (15 * 60)
58065 +
58066 +static int __get_dumpable(unsigned long mm_flags)
58067 +{
58068 + int ret;
58069 +
58070 + ret = mm_flags & MMF_DUMPABLE_MASK;
58071 + return (ret >= 2) ? 2 : ret;
58072 +}
58073 +#endif
58074 +
58075 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
58076 +{
58077 +#ifdef CONFIG_GRKERNSEC_BRUTE
58078 + uid_t uid = 0;
58079 +
58080 + if (!grsec_enable_brute)
58081 + return;
58082 +
58083 + rcu_read_lock();
58084 + read_lock(&tasklist_lock);
58085 + read_lock(&grsec_exec_file_lock);
58086 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
58087 + p->real_parent->brute = 1;
58088 + else {
58089 + const struct cred *cred = __task_cred(p), *cred2;
58090 + struct task_struct *tsk, *tsk2;
58091 +
58092 + if (!__get_dumpable(mm_flags) && cred->uid) {
58093 + struct user_struct *user;
58094 +
58095 + uid = cred->uid;
58096 +
58097 + /* this is put upon execution past expiration */
58098 + user = find_user(uid);
58099 + if (user == NULL)
58100 + goto unlock;
58101 + user->banned = 1;
58102 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
58103 + if (user->ban_expires == ~0UL)
58104 + user->ban_expires--;
58105 +
58106 + do_each_thread(tsk2, tsk) {
58107 + cred2 = __task_cred(tsk);
58108 + if (tsk != p && cred2->uid == uid)
58109 + gr_fake_force_sig(SIGKILL, tsk);
58110 + } while_each_thread(tsk2, tsk);
58111 + }
58112 + }
58113 +unlock:
58114 + read_unlock(&grsec_exec_file_lock);
58115 + read_unlock(&tasklist_lock);
58116 + rcu_read_unlock();
58117 +
58118 + if (uid)
58119 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
58120 +
58121 +#endif
58122 + return;
58123 +}
58124 +
58125 +void gr_handle_brute_check(void)
58126 +{
58127 +#ifdef CONFIG_GRKERNSEC_BRUTE
58128 + if (current->brute)
58129 + msleep(30 * 1000);
58130 +#endif
58131 + return;
58132 +}
58133 +
58134 +void gr_handle_kernel_exploit(void)
58135 +{
58136 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
58137 + const struct cred *cred;
58138 + struct task_struct *tsk, *tsk2;
58139 + struct user_struct *user;
58140 + uid_t uid;
58141 +
58142 + if (in_irq() || in_serving_softirq() || in_nmi())
58143 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
58144 +
58145 + uid = current_uid();
58146 +
58147 + if (uid == 0)
58148 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
58149 + else {
58150 + /* kill all the processes of this user, hold a reference
58151 + to their creds struct, and prevent them from creating
58152 + another process until system reset
58153 + */
58154 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
58155 + /* we intentionally leak this ref */
58156 + user = get_uid(current->cred->user);
58157 + if (user) {
58158 + user->banned = 1;
58159 + user->ban_expires = ~0UL;
58160 + }
58161 +
58162 + read_lock(&tasklist_lock);
58163 + do_each_thread(tsk2, tsk) {
58164 + cred = __task_cred(tsk);
58165 + if (cred->uid == uid)
58166 + gr_fake_force_sig(SIGKILL, tsk);
58167 + } while_each_thread(tsk2, tsk);
58168 + read_unlock(&tasklist_lock);
58169 + }
58170 +#endif
58171 +}
58172 +
58173 +int __gr_process_user_ban(struct user_struct *user)
58174 +{
58175 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58176 + if (unlikely(user->banned)) {
58177 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
58178 + user->banned = 0;
58179 + user->ban_expires = 0;
58180 + free_uid(user);
58181 + } else
58182 + return -EPERM;
58183 + }
58184 +#endif
58185 + return 0;
58186 +}
58187 +
58188 +int gr_process_user_ban(void)
58189 +{
58190 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58191 + return __gr_process_user_ban(current->cred->user);
58192 +#endif
58193 + return 0;
58194 +}
58195 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
58196 new file mode 100644
58197 index 0000000..4030d57
58198 --- /dev/null
58199 +++ b/grsecurity/grsec_sock.c
58200 @@ -0,0 +1,244 @@
58201 +#include <linux/kernel.h>
58202 +#include <linux/module.h>
58203 +#include <linux/sched.h>
58204 +#include <linux/file.h>
58205 +#include <linux/net.h>
58206 +#include <linux/in.h>
58207 +#include <linux/ip.h>
58208 +#include <net/sock.h>
58209 +#include <net/inet_sock.h>
58210 +#include <linux/grsecurity.h>
58211 +#include <linux/grinternal.h>
58212 +#include <linux/gracl.h>
58213 +
58214 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
58215 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
58216 +
58217 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
58218 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
58219 +
58220 +#ifdef CONFIG_UNIX_MODULE
58221 +EXPORT_SYMBOL(gr_acl_handle_unix);
58222 +EXPORT_SYMBOL(gr_acl_handle_mknod);
58223 +EXPORT_SYMBOL(gr_handle_chroot_unix);
58224 +EXPORT_SYMBOL(gr_handle_create);
58225 +#endif
58226 +
58227 +#ifdef CONFIG_GRKERNSEC
58228 +#define gr_conn_table_size 32749
58229 +struct conn_table_entry {
58230 + struct conn_table_entry *next;
58231 + struct signal_struct *sig;
58232 +};
58233 +
58234 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
58235 +DEFINE_SPINLOCK(gr_conn_table_lock);
58236 +
58237 +extern const char * gr_socktype_to_name(unsigned char type);
58238 +extern const char * gr_proto_to_name(unsigned char proto);
58239 +extern const char * gr_sockfamily_to_name(unsigned char family);
58240 +
58241 +static __inline__ int
58242 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
58243 +{
58244 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
58245 +}
58246 +
58247 +static __inline__ int
58248 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
58249 + __u16 sport, __u16 dport)
58250 +{
58251 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
58252 + sig->gr_sport == sport && sig->gr_dport == dport))
58253 + return 1;
58254 + else
58255 + return 0;
58256 +}
58257 +
58258 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
58259 +{
58260 + struct conn_table_entry **match;
58261 + unsigned int index;
58262 +
58263 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58264 + sig->gr_sport, sig->gr_dport,
58265 + gr_conn_table_size);
58266 +
58267 + newent->sig = sig;
58268 +
58269 + match = &gr_conn_table[index];
58270 + newent->next = *match;
58271 + *match = newent;
58272 +
58273 + return;
58274 +}
58275 +
58276 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
58277 +{
58278 + struct conn_table_entry *match, *last = NULL;
58279 + unsigned int index;
58280 +
58281 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58282 + sig->gr_sport, sig->gr_dport,
58283 + gr_conn_table_size);
58284 +
58285 + match = gr_conn_table[index];
58286 + while (match && !conn_match(match->sig,
58287 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
58288 + sig->gr_dport)) {
58289 + last = match;
58290 + match = match->next;
58291 + }
58292 +
58293 + if (match) {
58294 + if (last)
58295 + last->next = match->next;
58296 + else
58297 + gr_conn_table[index] = NULL;
58298 + kfree(match);
58299 + }
58300 +
58301 + return;
58302 +}
58303 +
58304 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
58305 + __u16 sport, __u16 dport)
58306 +{
58307 + struct conn_table_entry *match;
58308 + unsigned int index;
58309 +
58310 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
58311 +
58312 + match = gr_conn_table[index];
58313 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
58314 + match = match->next;
58315 +
58316 + if (match)
58317 + return match->sig;
58318 + else
58319 + return NULL;
58320 +}
58321 +
58322 +#endif
58323 +
58324 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
58325 +{
58326 +#ifdef CONFIG_GRKERNSEC
58327 + struct signal_struct *sig = task->signal;
58328 + struct conn_table_entry *newent;
58329 +
58330 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
58331 + if (newent == NULL)
58332 + return;
58333 + /* no bh lock needed since we are called with bh disabled */
58334 + spin_lock(&gr_conn_table_lock);
58335 + gr_del_task_from_ip_table_nolock(sig);
58336 + sig->gr_saddr = inet->inet_rcv_saddr;
58337 + sig->gr_daddr = inet->inet_daddr;
58338 + sig->gr_sport = inet->inet_sport;
58339 + sig->gr_dport = inet->inet_dport;
58340 + gr_add_to_task_ip_table_nolock(sig, newent);
58341 + spin_unlock(&gr_conn_table_lock);
58342 +#endif
58343 + return;
58344 +}
58345 +
58346 +void gr_del_task_from_ip_table(struct task_struct *task)
58347 +{
58348 +#ifdef CONFIG_GRKERNSEC
58349 + spin_lock_bh(&gr_conn_table_lock);
58350 + gr_del_task_from_ip_table_nolock(task->signal);
58351 + spin_unlock_bh(&gr_conn_table_lock);
58352 +#endif
58353 + return;
58354 +}
58355 +
58356 +void
58357 +gr_attach_curr_ip(const struct sock *sk)
58358 +{
58359 +#ifdef CONFIG_GRKERNSEC
58360 + struct signal_struct *p, *set;
58361 + const struct inet_sock *inet = inet_sk(sk);
58362 +
58363 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
58364 + return;
58365 +
58366 + set = current->signal;
58367 +
58368 + spin_lock_bh(&gr_conn_table_lock);
58369 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
58370 + inet->inet_dport, inet->inet_sport);
58371 + if (unlikely(p != NULL)) {
58372 + set->curr_ip = p->curr_ip;
58373 + set->used_accept = 1;
58374 + gr_del_task_from_ip_table_nolock(p);
58375 + spin_unlock_bh(&gr_conn_table_lock);
58376 + return;
58377 + }
58378 + spin_unlock_bh(&gr_conn_table_lock);
58379 +
58380 + set->curr_ip = inet->inet_daddr;
58381 + set->used_accept = 1;
58382 +#endif
58383 + return;
58384 +}
58385 +
58386 +int
58387 +gr_handle_sock_all(const int family, const int type, const int protocol)
58388 +{
58389 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58390 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
58391 + (family != AF_UNIX)) {
58392 + if (family == AF_INET)
58393 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
58394 + else
58395 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
58396 + return -EACCES;
58397 + }
58398 +#endif
58399 + return 0;
58400 +}
58401 +
58402 +int
58403 +gr_handle_sock_server(const struct sockaddr *sck)
58404 +{
58405 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58406 + if (grsec_enable_socket_server &&
58407 + in_group_p(grsec_socket_server_gid) &&
58408 + sck && (sck->sa_family != AF_UNIX) &&
58409 + (sck->sa_family != AF_LOCAL)) {
58410 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
58411 + return -EACCES;
58412 + }
58413 +#endif
58414 + return 0;
58415 +}
58416 +
58417 +int
58418 +gr_handle_sock_server_other(const struct sock *sck)
58419 +{
58420 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58421 + if (grsec_enable_socket_server &&
58422 + in_group_p(grsec_socket_server_gid) &&
58423 + sck && (sck->sk_family != AF_UNIX) &&
58424 + (sck->sk_family != AF_LOCAL)) {
58425 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
58426 + return -EACCES;
58427 + }
58428 +#endif
58429 + return 0;
58430 +}
58431 +
58432 +int
58433 +gr_handle_sock_client(const struct sockaddr *sck)
58434 +{
58435 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58436 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
58437 + sck && (sck->sa_family != AF_UNIX) &&
58438 + (sck->sa_family != AF_LOCAL)) {
58439 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
58440 + return -EACCES;
58441 + }
58442 +#endif
58443 + return 0;
58444 +}
58445 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
58446 new file mode 100644
58447 index 0000000..f55ef0f
58448 --- /dev/null
58449 +++ b/grsecurity/grsec_sysctl.c
58450 @@ -0,0 +1,469 @@
58451 +#include <linux/kernel.h>
58452 +#include <linux/sched.h>
58453 +#include <linux/sysctl.h>
58454 +#include <linux/grsecurity.h>
58455 +#include <linux/grinternal.h>
58456 +
58457 +int
58458 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
58459 +{
58460 +#ifdef CONFIG_GRKERNSEC_SYSCTL
58461 + if (dirname == NULL || name == NULL)
58462 + return 0;
58463 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
58464 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
58465 + return -EACCES;
58466 + }
58467 +#endif
58468 + return 0;
58469 +}
58470 +
58471 +#ifdef CONFIG_GRKERNSEC_ROFS
58472 +static int __maybe_unused one = 1;
58473 +#endif
58474 +
58475 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
58476 +struct ctl_table grsecurity_table[] = {
58477 +#ifdef CONFIG_GRKERNSEC_SYSCTL
58478 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
58479 +#ifdef CONFIG_GRKERNSEC_IO
58480 + {
58481 + .procname = "disable_priv_io",
58482 + .data = &grsec_disable_privio,
58483 + .maxlen = sizeof(int),
58484 + .mode = 0600,
58485 + .proc_handler = &proc_dointvec,
58486 + },
58487 +#endif
58488 +#endif
58489 +#ifdef CONFIG_GRKERNSEC_LINK
58490 + {
58491 + .procname = "linking_restrictions",
58492 + .data = &grsec_enable_link,
58493 + .maxlen = sizeof(int),
58494 + .mode = 0600,
58495 + .proc_handler = &proc_dointvec,
58496 + },
58497 +#endif
58498 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58499 + {
58500 + .procname = "enforce_symlinksifowner",
58501 + .data = &grsec_enable_symlinkown,
58502 + .maxlen = sizeof(int),
58503 + .mode = 0600,
58504 + .proc_handler = &proc_dointvec,
58505 + },
58506 + {
58507 + .procname = "symlinkown_gid",
58508 + .data = &grsec_symlinkown_gid,
58509 + .maxlen = sizeof(int),
58510 + .mode = 0600,
58511 + .proc_handler = &proc_dointvec,
58512 + },
58513 +#endif
58514 +#ifdef CONFIG_GRKERNSEC_BRUTE
58515 + {
58516 + .procname = "deter_bruteforce",
58517 + .data = &grsec_enable_brute,
58518 + .maxlen = sizeof(int),
58519 + .mode = 0600,
58520 + .proc_handler = &proc_dointvec,
58521 + },
58522 +#endif
58523 +#ifdef CONFIG_GRKERNSEC_FIFO
58524 + {
58525 + .procname = "fifo_restrictions",
58526 + .data = &grsec_enable_fifo,
58527 + .maxlen = sizeof(int),
58528 + .mode = 0600,
58529 + .proc_handler = &proc_dointvec,
58530 + },
58531 +#endif
58532 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58533 + {
58534 + .procname = "ptrace_readexec",
58535 + .data = &grsec_enable_ptrace_readexec,
58536 + .maxlen = sizeof(int),
58537 + .mode = 0600,
58538 + .proc_handler = &proc_dointvec,
58539 + },
58540 +#endif
58541 +#ifdef CONFIG_GRKERNSEC_SETXID
58542 + {
58543 + .procname = "consistent_setxid",
58544 + .data = &grsec_enable_setxid,
58545 + .maxlen = sizeof(int),
58546 + .mode = 0600,
58547 + .proc_handler = &proc_dointvec,
58548 + },
58549 +#endif
58550 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58551 + {
58552 + .procname = "ip_blackhole",
58553 + .data = &grsec_enable_blackhole,
58554 + .maxlen = sizeof(int),
58555 + .mode = 0600,
58556 + .proc_handler = &proc_dointvec,
58557 + },
58558 + {
58559 + .procname = "lastack_retries",
58560 + .data = &grsec_lastack_retries,
58561 + .maxlen = sizeof(int),
58562 + .mode = 0600,
58563 + .proc_handler = &proc_dointvec,
58564 + },
58565 +#endif
58566 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58567 + {
58568 + .procname = "exec_logging",
58569 + .data = &grsec_enable_execlog,
58570 + .maxlen = sizeof(int),
58571 + .mode = 0600,
58572 + .proc_handler = &proc_dointvec,
58573 + },
58574 +#endif
58575 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58576 + {
58577 + .procname = "rwxmap_logging",
58578 + .data = &grsec_enable_log_rwxmaps,
58579 + .maxlen = sizeof(int),
58580 + .mode = 0600,
58581 + .proc_handler = &proc_dointvec,
58582 + },
58583 +#endif
58584 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58585 + {
58586 + .procname = "signal_logging",
58587 + .data = &grsec_enable_signal,
58588 + .maxlen = sizeof(int),
58589 + .mode = 0600,
58590 + .proc_handler = &proc_dointvec,
58591 + },
58592 +#endif
58593 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58594 + {
58595 + .procname = "forkfail_logging",
58596 + .data = &grsec_enable_forkfail,
58597 + .maxlen = sizeof(int),
58598 + .mode = 0600,
58599 + .proc_handler = &proc_dointvec,
58600 + },
58601 +#endif
58602 +#ifdef CONFIG_GRKERNSEC_TIME
58603 + {
58604 + .procname = "timechange_logging",
58605 + .data = &grsec_enable_time,
58606 + .maxlen = sizeof(int),
58607 + .mode = 0600,
58608 + .proc_handler = &proc_dointvec,
58609 + },
58610 +#endif
58611 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58612 + {
58613 + .procname = "chroot_deny_shmat",
58614 + .data = &grsec_enable_chroot_shmat,
58615 + .maxlen = sizeof(int),
58616 + .mode = 0600,
58617 + .proc_handler = &proc_dointvec,
58618 + },
58619 +#endif
58620 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58621 + {
58622 + .procname = "chroot_deny_unix",
58623 + .data = &grsec_enable_chroot_unix,
58624 + .maxlen = sizeof(int),
58625 + .mode = 0600,
58626 + .proc_handler = &proc_dointvec,
58627 + },
58628 +#endif
58629 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58630 + {
58631 + .procname = "chroot_deny_mount",
58632 + .data = &grsec_enable_chroot_mount,
58633 + .maxlen = sizeof(int),
58634 + .mode = 0600,
58635 + .proc_handler = &proc_dointvec,
58636 + },
58637 +#endif
58638 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58639 + {
58640 + .procname = "chroot_deny_fchdir",
58641 + .data = &grsec_enable_chroot_fchdir,
58642 + .maxlen = sizeof(int),
58643 + .mode = 0600,
58644 + .proc_handler = &proc_dointvec,
58645 + },
58646 +#endif
58647 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58648 + {
58649 + .procname = "chroot_deny_chroot",
58650 + .data = &grsec_enable_chroot_double,
58651 + .maxlen = sizeof(int),
58652 + .mode = 0600,
58653 + .proc_handler = &proc_dointvec,
58654 + },
58655 +#endif
58656 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58657 + {
58658 + .procname = "chroot_deny_pivot",
58659 + .data = &grsec_enable_chroot_pivot,
58660 + .maxlen = sizeof(int),
58661 + .mode = 0600,
58662 + .proc_handler = &proc_dointvec,
58663 + },
58664 +#endif
58665 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58666 + {
58667 + .procname = "chroot_enforce_chdir",
58668 + .data = &grsec_enable_chroot_chdir,
58669 + .maxlen = sizeof(int),
58670 + .mode = 0600,
58671 + .proc_handler = &proc_dointvec,
58672 + },
58673 +#endif
58674 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58675 + {
58676 + .procname = "chroot_deny_chmod",
58677 + .data = &grsec_enable_chroot_chmod,
58678 + .maxlen = sizeof(int),
58679 + .mode = 0600,
58680 + .proc_handler = &proc_dointvec,
58681 + },
58682 +#endif
58683 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58684 + {
58685 + .procname = "chroot_deny_mknod",
58686 + .data = &grsec_enable_chroot_mknod,
58687 + .maxlen = sizeof(int),
58688 + .mode = 0600,
58689 + .proc_handler = &proc_dointvec,
58690 + },
58691 +#endif
58692 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58693 + {
58694 + .procname = "chroot_restrict_nice",
58695 + .data = &grsec_enable_chroot_nice,
58696 + .maxlen = sizeof(int),
58697 + .mode = 0600,
58698 + .proc_handler = &proc_dointvec,
58699 + },
58700 +#endif
58701 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58702 + {
58703 + .procname = "chroot_execlog",
58704 + .data = &grsec_enable_chroot_execlog,
58705 + .maxlen = sizeof(int),
58706 + .mode = 0600,
58707 + .proc_handler = &proc_dointvec,
58708 + },
58709 +#endif
58710 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58711 + {
58712 + .procname = "chroot_caps",
58713 + .data = &grsec_enable_chroot_caps,
58714 + .maxlen = sizeof(int),
58715 + .mode = 0600,
58716 + .proc_handler = &proc_dointvec,
58717 + },
58718 +#endif
58719 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58720 + {
58721 + .procname = "chroot_deny_sysctl",
58722 + .data = &grsec_enable_chroot_sysctl,
58723 + .maxlen = sizeof(int),
58724 + .mode = 0600,
58725 + .proc_handler = &proc_dointvec,
58726 + },
58727 +#endif
58728 +#ifdef CONFIG_GRKERNSEC_TPE
58729 + {
58730 + .procname = "tpe",
58731 + .data = &grsec_enable_tpe,
58732 + .maxlen = sizeof(int),
58733 + .mode = 0600,
58734 + .proc_handler = &proc_dointvec,
58735 + },
58736 + {
58737 + .procname = "tpe_gid",
58738 + .data = &grsec_tpe_gid,
58739 + .maxlen = sizeof(int),
58740 + .mode = 0600,
58741 + .proc_handler = &proc_dointvec,
58742 + },
58743 +#endif
58744 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58745 + {
58746 + .procname = "tpe_invert",
58747 + .data = &grsec_enable_tpe_invert,
58748 + .maxlen = sizeof(int),
58749 + .mode = 0600,
58750 + .proc_handler = &proc_dointvec,
58751 + },
58752 +#endif
58753 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58754 + {
58755 + .procname = "tpe_restrict_all",
58756 + .data = &grsec_enable_tpe_all,
58757 + .maxlen = sizeof(int),
58758 + .mode = 0600,
58759 + .proc_handler = &proc_dointvec,
58760 + },
58761 +#endif
58762 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58763 + {
58764 + .procname = "socket_all",
58765 + .data = &grsec_enable_socket_all,
58766 + .maxlen = sizeof(int),
58767 + .mode = 0600,
58768 + .proc_handler = &proc_dointvec,
58769 + },
58770 + {
58771 + .procname = "socket_all_gid",
58772 + .data = &grsec_socket_all_gid,
58773 + .maxlen = sizeof(int),
58774 + .mode = 0600,
58775 + .proc_handler = &proc_dointvec,
58776 + },
58777 +#endif
58778 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58779 + {
58780 + .procname = "socket_client",
58781 + .data = &grsec_enable_socket_client,
58782 + .maxlen = sizeof(int),
58783 + .mode = 0600,
58784 + .proc_handler = &proc_dointvec,
58785 + },
58786 + {
58787 + .procname = "socket_client_gid",
58788 + .data = &grsec_socket_client_gid,
58789 + .maxlen = sizeof(int),
58790 + .mode = 0600,
58791 + .proc_handler = &proc_dointvec,
58792 + },
58793 +#endif
58794 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58795 + {
58796 + .procname = "socket_server",
58797 + .data = &grsec_enable_socket_server,
58798 + .maxlen = sizeof(int),
58799 + .mode = 0600,
58800 + .proc_handler = &proc_dointvec,
58801 + },
58802 + {
58803 + .procname = "socket_server_gid",
58804 + .data = &grsec_socket_server_gid,
58805 + .maxlen = sizeof(int),
58806 + .mode = 0600,
58807 + .proc_handler = &proc_dointvec,
58808 + },
58809 +#endif
58810 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58811 + {
58812 + .procname = "audit_group",
58813 + .data = &grsec_enable_group,
58814 + .maxlen = sizeof(int),
58815 + .mode = 0600,
58816 + .proc_handler = &proc_dointvec,
58817 + },
58818 + {
58819 + .procname = "audit_gid",
58820 + .data = &grsec_audit_gid,
58821 + .maxlen = sizeof(int),
58822 + .mode = 0600,
58823 + .proc_handler = &proc_dointvec,
58824 + },
58825 +#endif
58826 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58827 + {
58828 + .procname = "audit_chdir",
58829 + .data = &grsec_enable_chdir,
58830 + .maxlen = sizeof(int),
58831 + .mode = 0600,
58832 + .proc_handler = &proc_dointvec,
58833 + },
58834 +#endif
58835 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58836 + {
58837 + .procname = "audit_mount",
58838 + .data = &grsec_enable_mount,
58839 + .maxlen = sizeof(int),
58840 + .mode = 0600,
58841 + .proc_handler = &proc_dointvec,
58842 + },
58843 +#endif
58844 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58845 + {
58846 + .procname = "audit_textrel",
58847 + .data = &grsec_enable_audit_textrel,
58848 + .maxlen = sizeof(int),
58849 + .mode = 0600,
58850 + .proc_handler = &proc_dointvec,
58851 + },
58852 +#endif
58853 +#ifdef CONFIG_GRKERNSEC_DMESG
58854 + {
58855 + .procname = "dmesg",
58856 + .data = &grsec_enable_dmesg,
58857 + .maxlen = sizeof(int),
58858 + .mode = 0600,
58859 + .proc_handler = &proc_dointvec,
58860 + },
58861 +#endif
58862 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58863 + {
58864 + .procname = "chroot_findtask",
58865 + .data = &grsec_enable_chroot_findtask,
58866 + .maxlen = sizeof(int),
58867 + .mode = 0600,
58868 + .proc_handler = &proc_dointvec,
58869 + },
58870 +#endif
58871 +#ifdef CONFIG_GRKERNSEC_RESLOG
58872 + {
58873 + .procname = "resource_logging",
58874 + .data = &grsec_resource_logging,
58875 + .maxlen = sizeof(int),
58876 + .mode = 0600,
58877 + .proc_handler = &proc_dointvec,
58878 + },
58879 +#endif
58880 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58881 + {
58882 + .procname = "audit_ptrace",
58883 + .data = &grsec_enable_audit_ptrace,
58884 + .maxlen = sizeof(int),
58885 + .mode = 0600,
58886 + .proc_handler = &proc_dointvec,
58887 + },
58888 +#endif
58889 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58890 + {
58891 + .procname = "harden_ptrace",
58892 + .data = &grsec_enable_harden_ptrace,
58893 + .maxlen = sizeof(int),
58894 + .mode = 0600,
58895 + .proc_handler = &proc_dointvec,
58896 + },
58897 +#endif
58898 + {
58899 + .procname = "grsec_lock",
58900 + .data = &grsec_lock,
58901 + .maxlen = sizeof(int),
58902 + .mode = 0600,
58903 + .proc_handler = &proc_dointvec,
58904 + },
58905 +#endif
58906 +#ifdef CONFIG_GRKERNSEC_ROFS
58907 + {
58908 + .procname = "romount_protect",
58909 + .data = &grsec_enable_rofs,
58910 + .maxlen = sizeof(int),
58911 + .mode = 0600,
58912 + .proc_handler = &proc_dointvec_minmax,
58913 + .extra1 = &one,
58914 + .extra2 = &one,
58915 + },
58916 +#endif
58917 + { }
58918 +};
58919 +#endif
58920 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
58921 new file mode 100644
58922 index 0000000..0dc13c3
58923 --- /dev/null
58924 +++ b/grsecurity/grsec_time.c
58925 @@ -0,0 +1,16 @@
58926 +#include <linux/kernel.h>
58927 +#include <linux/sched.h>
58928 +#include <linux/grinternal.h>
58929 +#include <linux/module.h>
58930 +
58931 +void
58932 +gr_log_timechange(void)
58933 +{
58934 +#ifdef CONFIG_GRKERNSEC_TIME
58935 + if (grsec_enable_time)
58936 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
58937 +#endif
58938 + return;
58939 +}
58940 +
58941 +EXPORT_SYMBOL(gr_log_timechange);
58942 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
58943 new file mode 100644
58944 index 0000000..07e0dc0
58945 --- /dev/null
58946 +++ b/grsecurity/grsec_tpe.c
58947 @@ -0,0 +1,73 @@
58948 +#include <linux/kernel.h>
58949 +#include <linux/sched.h>
58950 +#include <linux/file.h>
58951 +#include <linux/fs.h>
58952 +#include <linux/grinternal.h>
58953 +
58954 +extern int gr_acl_tpe_check(void);
58955 +
58956 +int
58957 +gr_tpe_allow(const struct file *file)
58958 +{
58959 +#ifdef CONFIG_GRKERNSEC
58960 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
58961 + const struct cred *cred = current_cred();
58962 + char *msg = NULL;
58963 + char *msg2 = NULL;
58964 +
58965 + // never restrict root
58966 + if (!cred->uid)
58967 + return 1;
58968 +
58969 + if (grsec_enable_tpe) {
58970 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58971 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
58972 + msg = "not being in trusted group";
58973 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
58974 + msg = "being in untrusted group";
58975 +#else
58976 + if (in_group_p(grsec_tpe_gid))
58977 + msg = "being in untrusted group";
58978 +#endif
58979 + }
58980 + if (!msg && gr_acl_tpe_check())
58981 + msg = "being in untrusted role";
58982 +
58983 + // not in any affected group/role
58984 + if (!msg)
58985 + goto next_check;
58986 +
58987 + if (inode->i_uid)
58988 + msg2 = "file in non-root-owned directory";
58989 + else if (inode->i_mode & S_IWOTH)
58990 + msg2 = "file in world-writable directory";
58991 + else if (inode->i_mode & S_IWGRP)
58992 + msg2 = "file in group-writable directory";
58993 +
58994 + if (msg && msg2) {
58995 + char fullmsg[70] = {0};
58996 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
58997 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
58998 + return 0;
58999 + }
59000 + msg = NULL;
59001 +next_check:
59002 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59003 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
59004 + return 1;
59005 +
59006 + if (inode->i_uid && (inode->i_uid != cred->uid))
59007 + msg = "directory not owned by user";
59008 + else if (inode->i_mode & S_IWOTH)
59009 + msg = "file in world-writable directory";
59010 + else if (inode->i_mode & S_IWGRP)
59011 + msg = "file in group-writable directory";
59012 +
59013 + if (msg) {
59014 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
59015 + return 0;
59016 + }
59017 +#endif
59018 +#endif
59019 + return 1;
59020 +}
59021 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
59022 new file mode 100644
59023 index 0000000..9f7b1ac
59024 --- /dev/null
59025 +++ b/grsecurity/grsum.c
59026 @@ -0,0 +1,61 @@
59027 +#include <linux/err.h>
59028 +#include <linux/kernel.h>
59029 +#include <linux/sched.h>
59030 +#include <linux/mm.h>
59031 +#include <linux/scatterlist.h>
59032 +#include <linux/crypto.h>
59033 +#include <linux/gracl.h>
59034 +
59035 +
59036 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
59037 +#error "crypto and sha256 must be built into the kernel"
59038 +#endif
59039 +
59040 +int
59041 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
59042 +{
59043 + char *p;
59044 + struct crypto_hash *tfm;
59045 + struct hash_desc desc;
59046 + struct scatterlist sg;
59047 + unsigned char temp_sum[GR_SHA_LEN];
59048 + volatile int retval = 0;
59049 + volatile int dummy = 0;
59050 + unsigned int i;
59051 +
59052 + sg_init_table(&sg, 1);
59053 +
59054 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
59055 + if (IS_ERR(tfm)) {
59056 + /* should never happen, since sha256 should be built in */
59057 + return 1;
59058 + }
59059 +
59060 + desc.tfm = tfm;
59061 + desc.flags = 0;
59062 +
59063 + crypto_hash_init(&desc);
59064 +
59065 + p = salt;
59066 + sg_set_buf(&sg, p, GR_SALT_LEN);
59067 + crypto_hash_update(&desc, &sg, sg.length);
59068 +
59069 + p = entry->pw;
59070 + sg_set_buf(&sg, p, strlen(p));
59071 +
59072 + crypto_hash_update(&desc, &sg, sg.length);
59073 +
59074 + crypto_hash_final(&desc, temp_sum);
59075 +
59076 + memset(entry->pw, 0, GR_PW_LEN);
59077 +
59078 + for (i = 0; i < GR_SHA_LEN; i++)
59079 + if (sum[i] != temp_sum[i])
59080 + retval = 1;
59081 + else
59082 + dummy = 1; // waste a cycle
59083 +
59084 + crypto_free_hash(tfm);
59085 +
59086 + return retval;
59087 +}
59088 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
59089 index f1c8ca6..b5c1cc7 100644
59090 --- a/include/acpi/acpi_bus.h
59091 +++ b/include/acpi/acpi_bus.h
59092 @@ -107,7 +107,7 @@ struct acpi_device_ops {
59093 acpi_op_bind bind;
59094 acpi_op_unbind unbind;
59095 acpi_op_notify notify;
59096 -};
59097 +} __no_const;
59098
59099 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
59100
59101 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
59102 index b7babf0..71e4e74 100644
59103 --- a/include/asm-generic/atomic-long.h
59104 +++ b/include/asm-generic/atomic-long.h
59105 @@ -22,6 +22,12 @@
59106
59107 typedef atomic64_t atomic_long_t;
59108
59109 +#ifdef CONFIG_PAX_REFCOUNT
59110 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
59111 +#else
59112 +typedef atomic64_t atomic_long_unchecked_t;
59113 +#endif
59114 +
59115 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
59116
59117 static inline long atomic_long_read(atomic_long_t *l)
59118 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59119 return (long)atomic64_read(v);
59120 }
59121
59122 +#ifdef CONFIG_PAX_REFCOUNT
59123 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59124 +{
59125 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59126 +
59127 + return (long)atomic64_read_unchecked(v);
59128 +}
59129 +#endif
59130 +
59131 static inline void atomic_long_set(atomic_long_t *l, long i)
59132 {
59133 atomic64_t *v = (atomic64_t *)l;
59134 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59135 atomic64_set(v, i);
59136 }
59137
59138 +#ifdef CONFIG_PAX_REFCOUNT
59139 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59140 +{
59141 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59142 +
59143 + atomic64_set_unchecked(v, i);
59144 +}
59145 +#endif
59146 +
59147 static inline void atomic_long_inc(atomic_long_t *l)
59148 {
59149 atomic64_t *v = (atomic64_t *)l;
59150 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59151 atomic64_inc(v);
59152 }
59153
59154 +#ifdef CONFIG_PAX_REFCOUNT
59155 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59156 +{
59157 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59158 +
59159 + atomic64_inc_unchecked(v);
59160 +}
59161 +#endif
59162 +
59163 static inline void atomic_long_dec(atomic_long_t *l)
59164 {
59165 atomic64_t *v = (atomic64_t *)l;
59166 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59167 atomic64_dec(v);
59168 }
59169
59170 +#ifdef CONFIG_PAX_REFCOUNT
59171 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59172 +{
59173 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59174 +
59175 + atomic64_dec_unchecked(v);
59176 +}
59177 +#endif
59178 +
59179 static inline void atomic_long_add(long i, atomic_long_t *l)
59180 {
59181 atomic64_t *v = (atomic64_t *)l;
59182 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59183 atomic64_add(i, v);
59184 }
59185
59186 +#ifdef CONFIG_PAX_REFCOUNT
59187 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59188 +{
59189 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59190 +
59191 + atomic64_add_unchecked(i, v);
59192 +}
59193 +#endif
59194 +
59195 static inline void atomic_long_sub(long i, atomic_long_t *l)
59196 {
59197 atomic64_t *v = (atomic64_t *)l;
59198 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59199 atomic64_sub(i, v);
59200 }
59201
59202 +#ifdef CONFIG_PAX_REFCOUNT
59203 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59204 +{
59205 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59206 +
59207 + atomic64_sub_unchecked(i, v);
59208 +}
59209 +#endif
59210 +
59211 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59212 {
59213 atomic64_t *v = (atomic64_t *)l;
59214 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59215 return (long)atomic64_inc_return(v);
59216 }
59217
59218 +#ifdef CONFIG_PAX_REFCOUNT
59219 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59220 +{
59221 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59222 +
59223 + return (long)atomic64_inc_return_unchecked(v);
59224 +}
59225 +#endif
59226 +
59227 static inline long atomic_long_dec_return(atomic_long_t *l)
59228 {
59229 atomic64_t *v = (atomic64_t *)l;
59230 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59231
59232 typedef atomic_t atomic_long_t;
59233
59234 +#ifdef CONFIG_PAX_REFCOUNT
59235 +typedef atomic_unchecked_t atomic_long_unchecked_t;
59236 +#else
59237 +typedef atomic_t atomic_long_unchecked_t;
59238 +#endif
59239 +
59240 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
59241 static inline long atomic_long_read(atomic_long_t *l)
59242 {
59243 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59244 return (long)atomic_read(v);
59245 }
59246
59247 +#ifdef CONFIG_PAX_REFCOUNT
59248 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59249 +{
59250 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59251 +
59252 + return (long)atomic_read_unchecked(v);
59253 +}
59254 +#endif
59255 +
59256 static inline void atomic_long_set(atomic_long_t *l, long i)
59257 {
59258 atomic_t *v = (atomic_t *)l;
59259 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59260 atomic_set(v, i);
59261 }
59262
59263 +#ifdef CONFIG_PAX_REFCOUNT
59264 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59265 +{
59266 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59267 +
59268 + atomic_set_unchecked(v, i);
59269 +}
59270 +#endif
59271 +
59272 static inline void atomic_long_inc(atomic_long_t *l)
59273 {
59274 atomic_t *v = (atomic_t *)l;
59275 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59276 atomic_inc(v);
59277 }
59278
59279 +#ifdef CONFIG_PAX_REFCOUNT
59280 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59281 +{
59282 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59283 +
59284 + atomic_inc_unchecked(v);
59285 +}
59286 +#endif
59287 +
59288 static inline void atomic_long_dec(atomic_long_t *l)
59289 {
59290 atomic_t *v = (atomic_t *)l;
59291 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59292 atomic_dec(v);
59293 }
59294
59295 +#ifdef CONFIG_PAX_REFCOUNT
59296 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59297 +{
59298 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59299 +
59300 + atomic_dec_unchecked(v);
59301 +}
59302 +#endif
59303 +
59304 static inline void atomic_long_add(long i, atomic_long_t *l)
59305 {
59306 atomic_t *v = (atomic_t *)l;
59307 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59308 atomic_add(i, v);
59309 }
59310
59311 +#ifdef CONFIG_PAX_REFCOUNT
59312 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59313 +{
59314 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59315 +
59316 + atomic_add_unchecked(i, v);
59317 +}
59318 +#endif
59319 +
59320 static inline void atomic_long_sub(long i, atomic_long_t *l)
59321 {
59322 atomic_t *v = (atomic_t *)l;
59323 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59324 atomic_sub(i, v);
59325 }
59326
59327 +#ifdef CONFIG_PAX_REFCOUNT
59328 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59329 +{
59330 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59331 +
59332 + atomic_sub_unchecked(i, v);
59333 +}
59334 +#endif
59335 +
59336 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59337 {
59338 atomic_t *v = (atomic_t *)l;
59339 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59340 return (long)atomic_inc_return(v);
59341 }
59342
59343 +#ifdef CONFIG_PAX_REFCOUNT
59344 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59345 +{
59346 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59347 +
59348 + return (long)atomic_inc_return_unchecked(v);
59349 +}
59350 +#endif
59351 +
59352 static inline long atomic_long_dec_return(atomic_long_t *l)
59353 {
59354 atomic_t *v = (atomic_t *)l;
59355 @@ -255,4 +393,49 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59356
59357 #endif /* BITS_PER_LONG == 64 */
59358
59359 +#ifdef CONFIG_PAX_REFCOUNT
59360 +static inline void pax_refcount_needs_these_functions(void)
59361 +{
59362 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
59363 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
59364 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
59365 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
59366 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
59367 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
59368 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
59369 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
59370 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
59371 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
59372 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
59373 +
59374 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
59375 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
59376 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
59377 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
59378 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
59379 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
59380 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
59381 +}
59382 +#else
59383 +#define atomic_read_unchecked(v) atomic_read(v)
59384 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
59385 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
59386 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
59387 +#define atomic_inc_unchecked(v) atomic_inc(v)
59388 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
59389 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
59390 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
59391 +#define atomic_dec_unchecked(v) atomic_dec(v)
59392 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
59393 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
59394 +
59395 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
59396 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
59397 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
59398 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
59399 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
59400 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
59401 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
59402 +#endif
59403 +
59404 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
59405 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
59406 index b18ce4f..2ee2843 100644
59407 --- a/include/asm-generic/atomic64.h
59408 +++ b/include/asm-generic/atomic64.h
59409 @@ -16,6 +16,8 @@ typedef struct {
59410 long long counter;
59411 } atomic64_t;
59412
59413 +typedef atomic64_t atomic64_unchecked_t;
59414 +
59415 #define ATOMIC64_INIT(i) { (i) }
59416
59417 extern long long atomic64_read(const atomic64_t *v);
59418 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
59419 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
59420 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
59421
59422 +#define atomic64_read_unchecked(v) atomic64_read(v)
59423 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
59424 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
59425 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
59426 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
59427 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
59428 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
59429 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
59430 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
59431 +
59432 #endif /* _ASM_GENERIC_ATOMIC64_H */
59433 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
59434 index 1bfcfe5..e04c5c9 100644
59435 --- a/include/asm-generic/cache.h
59436 +++ b/include/asm-generic/cache.h
59437 @@ -6,7 +6,7 @@
59438 * cache lines need to provide their own cache.h.
59439 */
59440
59441 -#define L1_CACHE_SHIFT 5
59442 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
59443 +#define L1_CACHE_SHIFT 5UL
59444 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
59445
59446 #endif /* __ASM_GENERIC_CACHE_H */
59447 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
59448 index 0d68a1e..b74a761 100644
59449 --- a/include/asm-generic/emergency-restart.h
59450 +++ b/include/asm-generic/emergency-restart.h
59451 @@ -1,7 +1,7 @@
59452 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
59453 #define _ASM_GENERIC_EMERGENCY_RESTART_H
59454
59455 -static inline void machine_emergency_restart(void)
59456 +static inline __noreturn void machine_emergency_restart(void)
59457 {
59458 machine_restart(NULL);
59459 }
59460 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
59461 index 0232ccb..13d9165 100644
59462 --- a/include/asm-generic/kmap_types.h
59463 +++ b/include/asm-generic/kmap_types.h
59464 @@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
59465 KMAP_D(17) KM_NMI,
59466 KMAP_D(18) KM_NMI_PTE,
59467 KMAP_D(19) KM_KDB,
59468 +KMAP_D(20) KM_CLEARPAGE,
59469 /*
59470 * Remember to update debug_kmap_atomic() when adding new kmap types!
59471 */
59472 -KMAP_D(20) KM_TYPE_NR
59473 +KMAP_D(21) KM_TYPE_NR
59474 };
59475
59476 #undef KMAP_D
59477 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
59478 index 9ceb03b..2efbcbd 100644
59479 --- a/include/asm-generic/local.h
59480 +++ b/include/asm-generic/local.h
59481 @@ -39,6 +39,7 @@ typedef struct
59482 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
59483 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
59484 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
59485 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
59486
59487 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
59488 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
59489 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
59490 index 725612b..9cc513a 100644
59491 --- a/include/asm-generic/pgtable-nopmd.h
59492 +++ b/include/asm-generic/pgtable-nopmd.h
59493 @@ -1,14 +1,19 @@
59494 #ifndef _PGTABLE_NOPMD_H
59495 #define _PGTABLE_NOPMD_H
59496
59497 -#ifndef __ASSEMBLY__
59498 -
59499 #include <asm-generic/pgtable-nopud.h>
59500
59501 -struct mm_struct;
59502 -
59503 #define __PAGETABLE_PMD_FOLDED
59504
59505 +#define PMD_SHIFT PUD_SHIFT
59506 +#define PTRS_PER_PMD 1
59507 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
59508 +#define PMD_MASK (~(PMD_SIZE-1))
59509 +
59510 +#ifndef __ASSEMBLY__
59511 +
59512 +struct mm_struct;
59513 +
59514 /*
59515 * Having the pmd type consist of a pud gets the size right, and allows
59516 * us to conceptually access the pud entry that this pmd is folded into
59517 @@ -16,11 +21,6 @@ struct mm_struct;
59518 */
59519 typedef struct { pud_t pud; } pmd_t;
59520
59521 -#define PMD_SHIFT PUD_SHIFT
59522 -#define PTRS_PER_PMD 1
59523 -#define PMD_SIZE (1UL << PMD_SHIFT)
59524 -#define PMD_MASK (~(PMD_SIZE-1))
59525 -
59526 /*
59527 * The "pud_xxx()" functions here are trivial for a folded two-level
59528 * setup: the pmd is never bad, and a pmd always exists (as it's folded
59529 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
59530 index 810431d..0ec4804f 100644
59531 --- a/include/asm-generic/pgtable-nopud.h
59532 +++ b/include/asm-generic/pgtable-nopud.h
59533 @@ -1,10 +1,15 @@
59534 #ifndef _PGTABLE_NOPUD_H
59535 #define _PGTABLE_NOPUD_H
59536
59537 -#ifndef __ASSEMBLY__
59538 -
59539 #define __PAGETABLE_PUD_FOLDED
59540
59541 +#define PUD_SHIFT PGDIR_SHIFT
59542 +#define PTRS_PER_PUD 1
59543 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
59544 +#define PUD_MASK (~(PUD_SIZE-1))
59545 +
59546 +#ifndef __ASSEMBLY__
59547 +
59548 /*
59549 * Having the pud type consist of a pgd gets the size right, and allows
59550 * us to conceptually access the pgd entry that this pud is folded into
59551 @@ -12,11 +17,6 @@
59552 */
59553 typedef struct { pgd_t pgd; } pud_t;
59554
59555 -#define PUD_SHIFT PGDIR_SHIFT
59556 -#define PTRS_PER_PUD 1
59557 -#define PUD_SIZE (1UL << PUD_SHIFT)
59558 -#define PUD_MASK (~(PUD_SIZE-1))
59559 -
59560 /*
59561 * The "pgd_xxx()" functions here are trivial for a folded two-level
59562 * setup: the pud is never bad, and a pud always exists (as it's folded
59563 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
59564 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
59565
59566 #define pgd_populate(mm, pgd, pud) do { } while (0)
59567 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
59568 /*
59569 * (puds are folded into pgds so this doesn't get actually called,
59570 * but the define is needed for a generic inline function.)
59571 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
59572 index c7ec2cd..909d125 100644
59573 --- a/include/asm-generic/pgtable.h
59574 +++ b/include/asm-generic/pgtable.h
59575 @@ -531,6 +531,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
59576 #endif
59577 }
59578
59579 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
59580 +static inline unsigned long pax_open_kernel(void) { return 0; }
59581 +#endif
59582 +
59583 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
59584 +static inline unsigned long pax_close_kernel(void) { return 0; }
59585 +#endif
59586 +
59587 #endif /* CONFIG_MMU */
59588
59589 #endif /* !__ASSEMBLY__ */
59590 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
59591 index 8aeadf6..f1dc019 100644
59592 --- a/include/asm-generic/vmlinux.lds.h
59593 +++ b/include/asm-generic/vmlinux.lds.h
59594 @@ -218,6 +218,7 @@
59595 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
59596 VMLINUX_SYMBOL(__start_rodata) = .; \
59597 *(.rodata) *(.rodata.*) \
59598 + *(.data..read_only) \
59599 *(__vermagic) /* Kernel version magic */ \
59600 . = ALIGN(8); \
59601 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
59602 @@ -716,17 +717,18 @@
59603 * section in the linker script will go there too. @phdr should have
59604 * a leading colon.
59605 *
59606 - * Note that this macros defines __per_cpu_load as an absolute symbol.
59607 + * Note that this macros defines per_cpu_load as an absolute symbol.
59608 * If there is no need to put the percpu section at a predetermined
59609 * address, use PERCPU_SECTION.
59610 */
59611 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
59612 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
59613 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
59614 + per_cpu_load = .; \
59615 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
59616 - LOAD_OFFSET) { \
59617 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
59618 PERCPU_INPUT(cacheline) \
59619 } phdr \
59620 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
59621 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
59622
59623 /**
59624 * PERCPU_SECTION - define output section for percpu area, simple version
59625 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
59626 index dd73104..fde86bd 100644
59627 --- a/include/drm/drmP.h
59628 +++ b/include/drm/drmP.h
59629 @@ -72,6 +72,7 @@
59630 #include <linux/workqueue.h>
59631 #include <linux/poll.h>
59632 #include <asm/pgalloc.h>
59633 +#include <asm/local.h>
59634 #include "drm.h"
59635
59636 #include <linux/idr.h>
59637 @@ -1074,7 +1075,7 @@ struct drm_device {
59638
59639 /** \name Usage Counters */
59640 /*@{ */
59641 - int open_count; /**< Outstanding files open */
59642 + local_t open_count; /**< Outstanding files open */
59643 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
59644 atomic_t vma_count; /**< Outstanding vma areas open */
59645 int buf_use; /**< Buffers in use -- cannot alloc */
59646 @@ -1085,7 +1086,7 @@ struct drm_device {
59647 /*@{ */
59648 unsigned long counters;
59649 enum drm_stat_type types[15];
59650 - atomic_t counts[15];
59651 + atomic_unchecked_t counts[15];
59652 /*@} */
59653
59654 struct list_head filelist;
59655 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
59656 index 37515d1..34fa8b0 100644
59657 --- a/include/drm/drm_crtc_helper.h
59658 +++ b/include/drm/drm_crtc_helper.h
59659 @@ -74,7 +74,7 @@ struct drm_crtc_helper_funcs {
59660
59661 /* disable crtc when not in use - more explicit than dpms off */
59662 void (*disable)(struct drm_crtc *crtc);
59663 -};
59664 +} __no_const;
59665
59666 struct drm_encoder_helper_funcs {
59667 void (*dpms)(struct drm_encoder *encoder, int mode);
59668 @@ -95,7 +95,7 @@ struct drm_encoder_helper_funcs {
59669 struct drm_connector *connector);
59670 /* disable encoder when not in use - more explicit than dpms off */
59671 void (*disable)(struct drm_encoder *encoder);
59672 -};
59673 +} __no_const;
59674
59675 struct drm_connector_helper_funcs {
59676 int (*get_modes)(struct drm_connector *connector);
59677 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
59678 index d6d1da4..fdd1ac5 100644
59679 --- a/include/drm/ttm/ttm_memory.h
59680 +++ b/include/drm/ttm/ttm_memory.h
59681 @@ -48,7 +48,7 @@
59682
59683 struct ttm_mem_shrink {
59684 int (*do_shrink) (struct ttm_mem_shrink *);
59685 -};
59686 +} __no_const;
59687
59688 /**
59689 * struct ttm_mem_global - Global memory accounting structure.
59690 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
59691 index e86dfca..40cc55f 100644
59692 --- a/include/linux/a.out.h
59693 +++ b/include/linux/a.out.h
59694 @@ -39,6 +39,14 @@ enum machine_type {
59695 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
59696 };
59697
59698 +/* Constants for the N_FLAGS field */
59699 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
59700 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
59701 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
59702 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
59703 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
59704 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
59705 +
59706 #if !defined (N_MAGIC)
59707 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
59708 #endif
59709 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
59710 index 06fd4bb..1caec0d 100644
59711 --- a/include/linux/atmdev.h
59712 +++ b/include/linux/atmdev.h
59713 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
59714 #endif
59715
59716 struct k_atm_aal_stats {
59717 -#define __HANDLE_ITEM(i) atomic_t i
59718 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
59719 __AAL_STAT_ITEMS
59720 #undef __HANDLE_ITEM
59721 };
59722 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
59723 index 366422b..1fa7f84 100644
59724 --- a/include/linux/binfmts.h
59725 +++ b/include/linux/binfmts.h
59726 @@ -89,6 +89,7 @@ struct linux_binfmt {
59727 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
59728 int (*load_shlib)(struct file *);
59729 int (*core_dump)(struct coredump_params *cprm);
59730 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
59731 unsigned long min_coredump; /* minimal dump size */
59732 };
59733
59734 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
59735 index 4d4ac24..2c3ccce 100644
59736 --- a/include/linux/blkdev.h
59737 +++ b/include/linux/blkdev.h
59738 @@ -1376,7 +1376,7 @@ struct block_device_operations {
59739 /* this callback is with swap_lock and sometimes page table lock held */
59740 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
59741 struct module *owner;
59742 -};
59743 +} __do_const;
59744
59745 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
59746 unsigned long);
59747 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
59748 index 4d1a074..88f929a 100644
59749 --- a/include/linux/blktrace_api.h
59750 +++ b/include/linux/blktrace_api.h
59751 @@ -162,7 +162,7 @@ struct blk_trace {
59752 struct dentry *dir;
59753 struct dentry *dropped_file;
59754 struct dentry *msg_file;
59755 - atomic_t dropped;
59756 + atomic_unchecked_t dropped;
59757 };
59758
59759 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
59760 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
59761 index 83195fb..0b0f77d 100644
59762 --- a/include/linux/byteorder/little_endian.h
59763 +++ b/include/linux/byteorder/little_endian.h
59764 @@ -42,51 +42,51 @@
59765
59766 static inline __le64 __cpu_to_le64p(const __u64 *p)
59767 {
59768 - return (__force __le64)*p;
59769 + return (__force const __le64)*p;
59770 }
59771 static inline __u64 __le64_to_cpup(const __le64 *p)
59772 {
59773 - return (__force __u64)*p;
59774 + return (__force const __u64)*p;
59775 }
59776 static inline __le32 __cpu_to_le32p(const __u32 *p)
59777 {
59778 - return (__force __le32)*p;
59779 + return (__force const __le32)*p;
59780 }
59781 static inline __u32 __le32_to_cpup(const __le32 *p)
59782 {
59783 - return (__force __u32)*p;
59784 + return (__force const __u32)*p;
59785 }
59786 static inline __le16 __cpu_to_le16p(const __u16 *p)
59787 {
59788 - return (__force __le16)*p;
59789 + return (__force const __le16)*p;
59790 }
59791 static inline __u16 __le16_to_cpup(const __le16 *p)
59792 {
59793 - return (__force __u16)*p;
59794 + return (__force const __u16)*p;
59795 }
59796 static inline __be64 __cpu_to_be64p(const __u64 *p)
59797 {
59798 - return (__force __be64)__swab64p(p);
59799 + return (__force const __be64)__swab64p(p);
59800 }
59801 static inline __u64 __be64_to_cpup(const __be64 *p)
59802 {
59803 - return __swab64p((__u64 *)p);
59804 + return __swab64p((const __u64 *)p);
59805 }
59806 static inline __be32 __cpu_to_be32p(const __u32 *p)
59807 {
59808 - return (__force __be32)__swab32p(p);
59809 + return (__force const __be32)__swab32p(p);
59810 }
59811 static inline __u32 __be32_to_cpup(const __be32 *p)
59812 {
59813 - return __swab32p((__u32 *)p);
59814 + return __swab32p((const __u32 *)p);
59815 }
59816 static inline __be16 __cpu_to_be16p(const __u16 *p)
59817 {
59818 - return (__force __be16)__swab16p(p);
59819 + return (__force const __be16)__swab16p(p);
59820 }
59821 static inline __u16 __be16_to_cpup(const __be16 *p)
59822 {
59823 - return __swab16p((__u16 *)p);
59824 + return __swab16p((const __u16 *)p);
59825 }
59826 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
59827 #define __le64_to_cpus(x) do { (void)(x); } while (0)
59828 diff --git a/include/linux/cache.h b/include/linux/cache.h
59829 index 4c57065..4307975 100644
59830 --- a/include/linux/cache.h
59831 +++ b/include/linux/cache.h
59832 @@ -16,6 +16,10 @@
59833 #define __read_mostly
59834 #endif
59835
59836 +#ifndef __read_only
59837 +#define __read_only __read_mostly
59838 +#endif
59839 +
59840 #ifndef ____cacheline_aligned
59841 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
59842 #endif
59843 diff --git a/include/linux/capability.h b/include/linux/capability.h
59844 index 12d52de..b5f7fa7 100644
59845 --- a/include/linux/capability.h
59846 +++ b/include/linux/capability.h
59847 @@ -548,6 +548,8 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
59848 extern bool capable(int cap);
59849 extern bool ns_capable(struct user_namespace *ns, int cap);
59850 extern bool nsown_capable(int cap);
59851 +extern bool capable_nolog(int cap);
59852 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
59853
59854 /* audit system wants to get cap info from files as well */
59855 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
59856 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
59857 index 42e55de..1cd0e66 100644
59858 --- a/include/linux/cleancache.h
59859 +++ b/include/linux/cleancache.h
59860 @@ -31,7 +31,7 @@ struct cleancache_ops {
59861 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
59862 void (*invalidate_inode)(int, struct cleancache_filekey);
59863 void (*invalidate_fs)(int);
59864 -};
59865 +} __no_const;
59866
59867 extern struct cleancache_ops
59868 cleancache_register_ops(struct cleancache_ops *ops);
59869 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
59870 index 2f40791..a62d196 100644
59871 --- a/include/linux/compiler-gcc4.h
59872 +++ b/include/linux/compiler-gcc4.h
59873 @@ -32,6 +32,16 @@
59874 #define __linktime_error(message) __attribute__((__error__(message)))
59875
59876 #if __GNUC_MINOR__ >= 5
59877 +
59878 +#ifdef CONSTIFY_PLUGIN
59879 +#define __no_const __attribute__((no_const))
59880 +#define __do_const __attribute__((do_const))
59881 +#endif
59882 +
59883 +#ifdef SIZE_OVERFLOW_PLUGIN
59884 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
59885 +#endif
59886 +
59887 /*
59888 * Mark a position in code as unreachable. This can be used to
59889 * suppress control flow warnings after asm blocks that transfer
59890 @@ -47,6 +57,11 @@
59891 #define __noclone __attribute__((__noclone__))
59892
59893 #endif
59894 +
59895 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
59896 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
59897 +#define __bos0(ptr) __bos((ptr), 0)
59898 +#define __bos1(ptr) __bos((ptr), 1)
59899 #endif
59900
59901 #if __GNUC_MINOR__ > 0
59902 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
59903 index 923d093..726c17f 100644
59904 --- a/include/linux/compiler.h
59905 +++ b/include/linux/compiler.h
59906 @@ -5,31 +5,62 @@
59907
59908 #ifdef __CHECKER__
59909 # define __user __attribute__((noderef, address_space(1)))
59910 +# define __force_user __force __user
59911 # define __kernel __attribute__((address_space(0)))
59912 +# define __force_kernel __force __kernel
59913 # define __safe __attribute__((safe))
59914 # define __force __attribute__((force))
59915 # define __nocast __attribute__((nocast))
59916 # define __iomem __attribute__((noderef, address_space(2)))
59917 +# define __force_iomem __force __iomem
59918 # define __acquires(x) __attribute__((context(x,0,1)))
59919 # define __releases(x) __attribute__((context(x,1,0)))
59920 # define __acquire(x) __context__(x,1)
59921 # define __release(x) __context__(x,-1)
59922 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
59923 # define __percpu __attribute__((noderef, address_space(3)))
59924 +# define __force_percpu __force __percpu
59925 #ifdef CONFIG_SPARSE_RCU_POINTER
59926 # define __rcu __attribute__((noderef, address_space(4)))
59927 +# define __force_rcu __force __rcu
59928 #else
59929 # define __rcu
59930 +# define __force_rcu
59931 #endif
59932 extern void __chk_user_ptr(const volatile void __user *);
59933 extern void __chk_io_ptr(const volatile void __iomem *);
59934 +#elif defined(CHECKER_PLUGIN)
59935 +//# define __user
59936 +//# define __force_user
59937 +//# define __kernel
59938 +//# define __force_kernel
59939 +# define __safe
59940 +# define __force
59941 +# define __nocast
59942 +# define __iomem
59943 +# define __force_iomem
59944 +# define __chk_user_ptr(x) (void)0
59945 +# define __chk_io_ptr(x) (void)0
59946 +# define __builtin_warning(x, y...) (1)
59947 +# define __acquires(x)
59948 +# define __releases(x)
59949 +# define __acquire(x) (void)0
59950 +# define __release(x) (void)0
59951 +# define __cond_lock(x,c) (c)
59952 +# define __percpu
59953 +# define __force_percpu
59954 +# define __rcu
59955 +# define __force_rcu
59956 #else
59957 # define __user
59958 +# define __force_user
59959 # define __kernel
59960 +# define __force_kernel
59961 # define __safe
59962 # define __force
59963 # define __nocast
59964 # define __iomem
59965 +# define __force_iomem
59966 # define __chk_user_ptr(x) (void)0
59967 # define __chk_io_ptr(x) (void)0
59968 # define __builtin_warning(x, y...) (1)
59969 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
59970 # define __release(x) (void)0
59971 # define __cond_lock(x,c) (c)
59972 # define __percpu
59973 +# define __force_percpu
59974 # define __rcu
59975 +# define __force_rcu
59976 #endif
59977
59978 #ifdef __KERNEL__
59979 @@ -264,6 +297,18 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
59980 # define __attribute_const__ /* unimplemented */
59981 #endif
59982
59983 +#ifndef __no_const
59984 +# define __no_const
59985 +#endif
59986 +
59987 +#ifndef __do_const
59988 +# define __do_const
59989 +#endif
59990 +
59991 +#ifndef __size_overflow
59992 +# define __size_overflow(...)
59993 +#endif
59994 +
59995 /*
59996 * Tell gcc if a function is cold. The compiler will assume any path
59997 * directly leading to the call is unlikely.
59998 @@ -273,6 +318,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
59999 #define __cold
60000 #endif
60001
60002 +#ifndef __alloc_size
60003 +#define __alloc_size(...)
60004 +#endif
60005 +
60006 +#ifndef __bos
60007 +#define __bos(ptr, arg)
60008 +#endif
60009 +
60010 +#ifndef __bos0
60011 +#define __bos0(ptr)
60012 +#endif
60013 +
60014 +#ifndef __bos1
60015 +#define __bos1(ptr)
60016 +#endif
60017 +
60018 /* Simple shorthand for a section definition */
60019 #ifndef __section
60020 # define __section(S) __attribute__ ((__section__(#S)))
60021 @@ -308,6 +369,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60022 * use is to mediate communication between process-level code and irq/NMI
60023 * handlers, all running on the same CPU.
60024 */
60025 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
60026 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
60027 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
60028
60029 #endif /* __LINUX_COMPILER_H */
60030 diff --git a/include/linux/cred.h b/include/linux/cred.h
60031 index adadf71..6af5560 100644
60032 --- a/include/linux/cred.h
60033 +++ b/include/linux/cred.h
60034 @@ -207,6 +207,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
60035 static inline void validate_process_creds(void)
60036 {
60037 }
60038 +static inline void validate_task_creds(struct task_struct *task)
60039 +{
60040 +}
60041 #endif
60042
60043 /**
60044 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
60045 index b92eadf..b4ecdc1 100644
60046 --- a/include/linux/crypto.h
60047 +++ b/include/linux/crypto.h
60048 @@ -373,7 +373,7 @@ struct cipher_tfm {
60049 const u8 *key, unsigned int keylen);
60050 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60051 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60052 -};
60053 +} __no_const;
60054
60055 struct hash_tfm {
60056 int (*init)(struct hash_desc *desc);
60057 @@ -394,13 +394,13 @@ struct compress_tfm {
60058 int (*cot_decompress)(struct crypto_tfm *tfm,
60059 const u8 *src, unsigned int slen,
60060 u8 *dst, unsigned int *dlen);
60061 -};
60062 +} __no_const;
60063
60064 struct rng_tfm {
60065 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
60066 unsigned int dlen);
60067 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
60068 -};
60069 +} __no_const;
60070
60071 #define crt_ablkcipher crt_u.ablkcipher
60072 #define crt_aead crt_u.aead
60073 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
60074 index 7925bf0..d5143d2 100644
60075 --- a/include/linux/decompress/mm.h
60076 +++ b/include/linux/decompress/mm.h
60077 @@ -77,7 +77,7 @@ static void free(void *where)
60078 * warnings when not needed (indeed large_malloc / large_free are not
60079 * needed by inflate */
60080
60081 -#define malloc(a) kmalloc(a, GFP_KERNEL)
60082 +#define malloc(a) kmalloc((a), GFP_KERNEL)
60083 #define free(a) kfree(a)
60084
60085 #define large_malloc(a) vmalloc(a)
60086 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
60087 index dfc099e..e583e66 100644
60088 --- a/include/linux/dma-mapping.h
60089 +++ b/include/linux/dma-mapping.h
60090 @@ -51,7 +51,7 @@ struct dma_map_ops {
60091 u64 (*get_required_mask)(struct device *dev);
60092 #endif
60093 int is_phys;
60094 -};
60095 +} __do_const;
60096
60097 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
60098
60099 diff --git a/include/linux/efi.h b/include/linux/efi.h
60100 index ec45ccd..9923c32 100644
60101 --- a/include/linux/efi.h
60102 +++ b/include/linux/efi.h
60103 @@ -635,7 +635,7 @@ struct efivar_operations {
60104 efi_get_variable_t *get_variable;
60105 efi_get_next_variable_t *get_next_variable;
60106 efi_set_variable_t *set_variable;
60107 -};
60108 +} __no_const;
60109
60110 struct efivars {
60111 /*
60112 diff --git a/include/linux/elf.h b/include/linux/elf.h
60113 index 999b4f5..57753b4 100644
60114 --- a/include/linux/elf.h
60115 +++ b/include/linux/elf.h
60116 @@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
60117 #define PT_GNU_EH_FRAME 0x6474e550
60118
60119 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
60120 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
60121 +
60122 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
60123 +
60124 +/* Constants for the e_flags field */
60125 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60126 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
60127 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
60128 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
60129 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60130 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60131
60132 /*
60133 * Extended Numbering
60134 @@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
60135 #define DT_DEBUG 21
60136 #define DT_TEXTREL 22
60137 #define DT_JMPREL 23
60138 +#define DT_FLAGS 30
60139 + #define DF_TEXTREL 0x00000004
60140 #define DT_ENCODING 32
60141 #define OLD_DT_LOOS 0x60000000
60142 #define DT_LOOS 0x6000000d
60143 @@ -243,6 +256,19 @@ typedef struct elf64_hdr {
60144 #define PF_W 0x2
60145 #define PF_X 0x1
60146
60147 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
60148 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
60149 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
60150 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
60151 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
60152 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
60153 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
60154 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
60155 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
60156 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
60157 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
60158 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
60159 +
60160 typedef struct elf32_phdr{
60161 Elf32_Word p_type;
60162 Elf32_Off p_offset;
60163 @@ -335,6 +361,8 @@ typedef struct elf64_shdr {
60164 #define EI_OSABI 7
60165 #define EI_PAD 8
60166
60167 +#define EI_PAX 14
60168 +
60169 #define ELFMAG0 0x7f /* EI_MAG */
60170 #define ELFMAG1 'E'
60171 #define ELFMAG2 'L'
60172 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
60173 #define elf_note elf32_note
60174 #define elf_addr_t Elf32_Off
60175 #define Elf_Half Elf32_Half
60176 +#define elf_dyn Elf32_Dyn
60177
60178 #else
60179
60180 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
60181 #define elf_note elf64_note
60182 #define elf_addr_t Elf64_Off
60183 #define Elf_Half Elf64_Half
60184 +#define elf_dyn Elf64_Dyn
60185
60186 #endif
60187
60188 diff --git a/include/linux/filter.h b/include/linux/filter.h
60189 index 8eeb205..d59bfa2 100644
60190 --- a/include/linux/filter.h
60191 +++ b/include/linux/filter.h
60192 @@ -134,6 +134,7 @@ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
60193
60194 struct sk_buff;
60195 struct sock;
60196 +struct bpf_jit_work;
60197
60198 struct sk_filter
60199 {
60200 @@ -141,6 +142,9 @@ struct sk_filter
60201 unsigned int len; /* Number of filter blocks */
60202 unsigned int (*bpf_func)(const struct sk_buff *skb,
60203 const struct sock_filter *filter);
60204 +#ifdef CONFIG_BPF_JIT
60205 + struct bpf_jit_work *work;
60206 +#endif
60207 struct rcu_head rcu;
60208 struct sock_filter insns[0];
60209 };
60210 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
60211 index cdc9b71..ce69fb5 100644
60212 --- a/include/linux/firewire.h
60213 +++ b/include/linux/firewire.h
60214 @@ -413,7 +413,7 @@ struct fw_iso_context {
60215 union {
60216 fw_iso_callback_t sc;
60217 fw_iso_mc_callback_t mc;
60218 - } callback;
60219 + } __no_const callback;
60220 void *callback_data;
60221 };
60222
60223 diff --git a/include/linux/fs.h b/include/linux/fs.h
60224 index 25c40b9..1bfd4f4 100644
60225 --- a/include/linux/fs.h
60226 +++ b/include/linux/fs.h
60227 @@ -1634,7 +1634,8 @@ struct file_operations {
60228 int (*setlease)(struct file *, long, struct file_lock **);
60229 long (*fallocate)(struct file *file, int mode, loff_t offset,
60230 loff_t len);
60231 -};
60232 +} __do_const;
60233 +typedef struct file_operations __no_const file_operations_no_const;
60234
60235 struct inode_operations {
60236 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
60237 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
60238 index 003dc0f..3c4ea97 100644
60239 --- a/include/linux/fs_struct.h
60240 +++ b/include/linux/fs_struct.h
60241 @@ -6,7 +6,7 @@
60242 #include <linux/seqlock.h>
60243
60244 struct fs_struct {
60245 - int users;
60246 + atomic_t users;
60247 spinlock_t lock;
60248 seqcount_t seq;
60249 int umask;
60250 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
60251 index ce31408..b1ad003 100644
60252 --- a/include/linux/fscache-cache.h
60253 +++ b/include/linux/fscache-cache.h
60254 @@ -102,7 +102,7 @@ struct fscache_operation {
60255 fscache_operation_release_t release;
60256 };
60257
60258 -extern atomic_t fscache_op_debug_id;
60259 +extern atomic_unchecked_t fscache_op_debug_id;
60260 extern void fscache_op_work_func(struct work_struct *work);
60261
60262 extern void fscache_enqueue_operation(struct fscache_operation *);
60263 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
60264 {
60265 INIT_WORK(&op->work, fscache_op_work_func);
60266 atomic_set(&op->usage, 1);
60267 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
60268 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60269 op->processor = processor;
60270 op->release = release;
60271 INIT_LIST_HEAD(&op->pend_link);
60272 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
60273 index a6dfe69..569586df 100644
60274 --- a/include/linux/fsnotify.h
60275 +++ b/include/linux/fsnotify.h
60276 @@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
60277 */
60278 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
60279 {
60280 - return kstrdup(name, GFP_KERNEL);
60281 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
60282 }
60283
60284 /*
60285 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
60286 index 91d0e0a3..035666b 100644
60287 --- a/include/linux/fsnotify_backend.h
60288 +++ b/include/linux/fsnotify_backend.h
60289 @@ -105,6 +105,7 @@ struct fsnotify_ops {
60290 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
60291 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
60292 };
60293 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
60294
60295 /*
60296 * A group is a "thing" that wants to receive notification about filesystem
60297 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
60298 index 176a939..1462211 100644
60299 --- a/include/linux/ftrace_event.h
60300 +++ b/include/linux/ftrace_event.h
60301 @@ -97,7 +97,7 @@ struct trace_event_functions {
60302 trace_print_func raw;
60303 trace_print_func hex;
60304 trace_print_func binary;
60305 -};
60306 +} __no_const;
60307
60308 struct trace_event {
60309 struct hlist_node node;
60310 @@ -263,7 +263,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
60311 extern int trace_add_event_call(struct ftrace_event_call *call);
60312 extern void trace_remove_event_call(struct ftrace_event_call *call);
60313
60314 -#define is_signed_type(type) (((type)(-1)) < 0)
60315 +#define is_signed_type(type) (((type)(-1)) < (type)1)
60316
60317 int trace_set_clr_event(const char *system, const char *event, int set);
60318
60319 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
60320 index 017a7fb..33a8507 100644
60321 --- a/include/linux/genhd.h
60322 +++ b/include/linux/genhd.h
60323 @@ -185,7 +185,7 @@ struct gendisk {
60324 struct kobject *slave_dir;
60325
60326 struct timer_rand_state *random;
60327 - atomic_t sync_io; /* RAID */
60328 + atomic_unchecked_t sync_io; /* RAID */
60329 struct disk_events *ev;
60330 #ifdef CONFIG_BLK_DEV_INTEGRITY
60331 struct blk_integrity *integrity;
60332 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
60333 new file mode 100644
60334 index 0000000..c938b1f
60335 --- /dev/null
60336 +++ b/include/linux/gracl.h
60337 @@ -0,0 +1,319 @@
60338 +#ifndef GR_ACL_H
60339 +#define GR_ACL_H
60340 +
60341 +#include <linux/grdefs.h>
60342 +#include <linux/resource.h>
60343 +#include <linux/capability.h>
60344 +#include <linux/dcache.h>
60345 +#include <asm/resource.h>
60346 +
60347 +/* Major status information */
60348 +
60349 +#define GR_VERSION "grsecurity 2.9.1"
60350 +#define GRSECURITY_VERSION 0x2901
60351 +
60352 +enum {
60353 + GR_SHUTDOWN = 0,
60354 + GR_ENABLE = 1,
60355 + GR_SPROLE = 2,
60356 + GR_RELOAD = 3,
60357 + GR_SEGVMOD = 4,
60358 + GR_STATUS = 5,
60359 + GR_UNSPROLE = 6,
60360 + GR_PASSSET = 7,
60361 + GR_SPROLEPAM = 8,
60362 +};
60363 +
60364 +/* Password setup definitions
60365 + * kernel/grhash.c */
60366 +enum {
60367 + GR_PW_LEN = 128,
60368 + GR_SALT_LEN = 16,
60369 + GR_SHA_LEN = 32,
60370 +};
60371 +
60372 +enum {
60373 + GR_SPROLE_LEN = 64,
60374 +};
60375 +
60376 +enum {
60377 + GR_NO_GLOB = 0,
60378 + GR_REG_GLOB,
60379 + GR_CREATE_GLOB
60380 +};
60381 +
60382 +#define GR_NLIMITS 32
60383 +
60384 +/* Begin Data Structures */
60385 +
60386 +struct sprole_pw {
60387 + unsigned char *rolename;
60388 + unsigned char salt[GR_SALT_LEN];
60389 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
60390 +};
60391 +
60392 +struct name_entry {
60393 + __u32 key;
60394 + ino_t inode;
60395 + dev_t device;
60396 + char *name;
60397 + __u16 len;
60398 + __u8 deleted;
60399 + struct name_entry *prev;
60400 + struct name_entry *next;
60401 +};
60402 +
60403 +struct inodev_entry {
60404 + struct name_entry *nentry;
60405 + struct inodev_entry *prev;
60406 + struct inodev_entry *next;
60407 +};
60408 +
60409 +struct acl_role_db {
60410 + struct acl_role_label **r_hash;
60411 + __u32 r_size;
60412 +};
60413 +
60414 +struct inodev_db {
60415 + struct inodev_entry **i_hash;
60416 + __u32 i_size;
60417 +};
60418 +
60419 +struct name_db {
60420 + struct name_entry **n_hash;
60421 + __u32 n_size;
60422 +};
60423 +
60424 +struct crash_uid {
60425 + uid_t uid;
60426 + unsigned long expires;
60427 +};
60428 +
60429 +struct gr_hash_struct {
60430 + void **table;
60431 + void **nametable;
60432 + void *first;
60433 + __u32 table_size;
60434 + __u32 used_size;
60435 + int type;
60436 +};
60437 +
60438 +/* Userspace Grsecurity ACL data structures */
60439 +
60440 +struct acl_subject_label {
60441 + char *filename;
60442 + ino_t inode;
60443 + dev_t device;
60444 + __u32 mode;
60445 + kernel_cap_t cap_mask;
60446 + kernel_cap_t cap_lower;
60447 + kernel_cap_t cap_invert_audit;
60448 +
60449 + struct rlimit res[GR_NLIMITS];
60450 + __u32 resmask;
60451 +
60452 + __u8 user_trans_type;
60453 + __u8 group_trans_type;
60454 + uid_t *user_transitions;
60455 + gid_t *group_transitions;
60456 + __u16 user_trans_num;
60457 + __u16 group_trans_num;
60458 +
60459 + __u32 sock_families[2];
60460 + __u32 ip_proto[8];
60461 + __u32 ip_type;
60462 + struct acl_ip_label **ips;
60463 + __u32 ip_num;
60464 + __u32 inaddr_any_override;
60465 +
60466 + __u32 crashes;
60467 + unsigned long expires;
60468 +
60469 + struct acl_subject_label *parent_subject;
60470 + struct gr_hash_struct *hash;
60471 + struct acl_subject_label *prev;
60472 + struct acl_subject_label *next;
60473 +
60474 + struct acl_object_label **obj_hash;
60475 + __u32 obj_hash_size;
60476 + __u16 pax_flags;
60477 +};
60478 +
60479 +struct role_allowed_ip {
60480 + __u32 addr;
60481 + __u32 netmask;
60482 +
60483 + struct role_allowed_ip *prev;
60484 + struct role_allowed_ip *next;
60485 +};
60486 +
60487 +struct role_transition {
60488 + char *rolename;
60489 +
60490 + struct role_transition *prev;
60491 + struct role_transition *next;
60492 +};
60493 +
60494 +struct acl_role_label {
60495 + char *rolename;
60496 + uid_t uidgid;
60497 + __u16 roletype;
60498 +
60499 + __u16 auth_attempts;
60500 + unsigned long expires;
60501 +
60502 + struct acl_subject_label *root_label;
60503 + struct gr_hash_struct *hash;
60504 +
60505 + struct acl_role_label *prev;
60506 + struct acl_role_label *next;
60507 +
60508 + struct role_transition *transitions;
60509 + struct role_allowed_ip *allowed_ips;
60510 + uid_t *domain_children;
60511 + __u16 domain_child_num;
60512 +
60513 + umode_t umask;
60514 +
60515 + struct acl_subject_label **subj_hash;
60516 + __u32 subj_hash_size;
60517 +};
60518 +
60519 +struct user_acl_role_db {
60520 + struct acl_role_label **r_table;
60521 + __u32 num_pointers; /* Number of allocations to track */
60522 + __u32 num_roles; /* Number of roles */
60523 + __u32 num_domain_children; /* Number of domain children */
60524 + __u32 num_subjects; /* Number of subjects */
60525 + __u32 num_objects; /* Number of objects */
60526 +};
60527 +
60528 +struct acl_object_label {
60529 + char *filename;
60530 + ino_t inode;
60531 + dev_t device;
60532 + __u32 mode;
60533 +
60534 + struct acl_subject_label *nested;
60535 + struct acl_object_label *globbed;
60536 +
60537 + /* next two structures not used */
60538 +
60539 + struct acl_object_label *prev;
60540 + struct acl_object_label *next;
60541 +};
60542 +
60543 +struct acl_ip_label {
60544 + char *iface;
60545 + __u32 addr;
60546 + __u32 netmask;
60547 + __u16 low, high;
60548 + __u8 mode;
60549 + __u32 type;
60550 + __u32 proto[8];
60551 +
60552 + /* next two structures not used */
60553 +
60554 + struct acl_ip_label *prev;
60555 + struct acl_ip_label *next;
60556 +};
60557 +
60558 +struct gr_arg {
60559 + struct user_acl_role_db role_db;
60560 + unsigned char pw[GR_PW_LEN];
60561 + unsigned char salt[GR_SALT_LEN];
60562 + unsigned char sum[GR_SHA_LEN];
60563 + unsigned char sp_role[GR_SPROLE_LEN];
60564 + struct sprole_pw *sprole_pws;
60565 + dev_t segv_device;
60566 + ino_t segv_inode;
60567 + uid_t segv_uid;
60568 + __u16 num_sprole_pws;
60569 + __u16 mode;
60570 +};
60571 +
60572 +struct gr_arg_wrapper {
60573 + struct gr_arg *arg;
60574 + __u32 version;
60575 + __u32 size;
60576 +};
60577 +
60578 +struct subject_map {
60579 + struct acl_subject_label *user;
60580 + struct acl_subject_label *kernel;
60581 + struct subject_map *prev;
60582 + struct subject_map *next;
60583 +};
60584 +
60585 +struct acl_subj_map_db {
60586 + struct subject_map **s_hash;
60587 + __u32 s_size;
60588 +};
60589 +
60590 +/* End Data Structures Section */
60591 +
60592 +/* Hash functions generated by empirical testing by Brad Spengler
60593 + Makes good use of the low bits of the inode. Generally 0-1 times
60594 + in loop for successful match. 0-3 for unsuccessful match.
60595 + Shift/add algorithm with modulus of table size and an XOR*/
60596 +
60597 +static __inline__ unsigned int
60598 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
60599 +{
60600 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
60601 +}
60602 +
60603 + static __inline__ unsigned int
60604 +shash(const struct acl_subject_label *userp, const unsigned int sz)
60605 +{
60606 + return ((const unsigned long)userp % sz);
60607 +}
60608 +
60609 +static __inline__ unsigned int
60610 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
60611 +{
60612 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
60613 +}
60614 +
60615 +static __inline__ unsigned int
60616 +nhash(const char *name, const __u16 len, const unsigned int sz)
60617 +{
60618 + return full_name_hash((const unsigned char *)name, len) % sz;
60619 +}
60620 +
60621 +#define FOR_EACH_ROLE_START(role) \
60622 + role = role_list; \
60623 + while (role) {
60624 +
60625 +#define FOR_EACH_ROLE_END(role) \
60626 + role = role->prev; \
60627 + }
60628 +
60629 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
60630 + subj = NULL; \
60631 + iter = 0; \
60632 + while (iter < role->subj_hash_size) { \
60633 + if (subj == NULL) \
60634 + subj = role->subj_hash[iter]; \
60635 + if (subj == NULL) { \
60636 + iter++; \
60637 + continue; \
60638 + }
60639 +
60640 +#define FOR_EACH_SUBJECT_END(subj,iter) \
60641 + subj = subj->next; \
60642 + if (subj == NULL) \
60643 + iter++; \
60644 + }
60645 +
60646 +
60647 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
60648 + subj = role->hash->first; \
60649 + while (subj != NULL) {
60650 +
60651 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
60652 + subj = subj->next; \
60653 + }
60654 +
60655 +#endif
60656 +
60657 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
60658 new file mode 100644
60659 index 0000000..323ecf2
60660 --- /dev/null
60661 +++ b/include/linux/gralloc.h
60662 @@ -0,0 +1,9 @@
60663 +#ifndef __GRALLOC_H
60664 +#define __GRALLOC_H
60665 +
60666 +void acl_free_all(void);
60667 +int acl_alloc_stack_init(unsigned long size);
60668 +void *acl_alloc(unsigned long len);
60669 +void *acl_alloc_num(unsigned long num, unsigned long len);
60670 +
60671 +#endif
60672 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
60673 new file mode 100644
60674 index 0000000..b30e9bc
60675 --- /dev/null
60676 +++ b/include/linux/grdefs.h
60677 @@ -0,0 +1,140 @@
60678 +#ifndef GRDEFS_H
60679 +#define GRDEFS_H
60680 +
60681 +/* Begin grsecurity status declarations */
60682 +
60683 +enum {
60684 + GR_READY = 0x01,
60685 + GR_STATUS_INIT = 0x00 // disabled state
60686 +};
60687 +
60688 +/* Begin ACL declarations */
60689 +
60690 +/* Role flags */
60691 +
60692 +enum {
60693 + GR_ROLE_USER = 0x0001,
60694 + GR_ROLE_GROUP = 0x0002,
60695 + GR_ROLE_DEFAULT = 0x0004,
60696 + GR_ROLE_SPECIAL = 0x0008,
60697 + GR_ROLE_AUTH = 0x0010,
60698 + GR_ROLE_NOPW = 0x0020,
60699 + GR_ROLE_GOD = 0x0040,
60700 + GR_ROLE_LEARN = 0x0080,
60701 + GR_ROLE_TPE = 0x0100,
60702 + GR_ROLE_DOMAIN = 0x0200,
60703 + GR_ROLE_PAM = 0x0400,
60704 + GR_ROLE_PERSIST = 0x0800
60705 +};
60706 +
60707 +/* ACL Subject and Object mode flags */
60708 +enum {
60709 + GR_DELETED = 0x80000000
60710 +};
60711 +
60712 +/* ACL Object-only mode flags */
60713 +enum {
60714 + GR_READ = 0x00000001,
60715 + GR_APPEND = 0x00000002,
60716 + GR_WRITE = 0x00000004,
60717 + GR_EXEC = 0x00000008,
60718 + GR_FIND = 0x00000010,
60719 + GR_INHERIT = 0x00000020,
60720 + GR_SETID = 0x00000040,
60721 + GR_CREATE = 0x00000080,
60722 + GR_DELETE = 0x00000100,
60723 + GR_LINK = 0x00000200,
60724 + GR_AUDIT_READ = 0x00000400,
60725 + GR_AUDIT_APPEND = 0x00000800,
60726 + GR_AUDIT_WRITE = 0x00001000,
60727 + GR_AUDIT_EXEC = 0x00002000,
60728 + GR_AUDIT_FIND = 0x00004000,
60729 + GR_AUDIT_INHERIT= 0x00008000,
60730 + GR_AUDIT_SETID = 0x00010000,
60731 + GR_AUDIT_CREATE = 0x00020000,
60732 + GR_AUDIT_DELETE = 0x00040000,
60733 + GR_AUDIT_LINK = 0x00080000,
60734 + GR_PTRACERD = 0x00100000,
60735 + GR_NOPTRACE = 0x00200000,
60736 + GR_SUPPRESS = 0x00400000,
60737 + GR_NOLEARN = 0x00800000,
60738 + GR_INIT_TRANSFER= 0x01000000
60739 +};
60740 +
60741 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
60742 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
60743 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
60744 +
60745 +/* ACL subject-only mode flags */
60746 +enum {
60747 + GR_KILL = 0x00000001,
60748 + GR_VIEW = 0x00000002,
60749 + GR_PROTECTED = 0x00000004,
60750 + GR_LEARN = 0x00000008,
60751 + GR_OVERRIDE = 0x00000010,
60752 + /* just a placeholder, this mode is only used in userspace */
60753 + GR_DUMMY = 0x00000020,
60754 + GR_PROTSHM = 0x00000040,
60755 + GR_KILLPROC = 0x00000080,
60756 + GR_KILLIPPROC = 0x00000100,
60757 + /* just a placeholder, this mode is only used in userspace */
60758 + GR_NOTROJAN = 0x00000200,
60759 + GR_PROTPROCFD = 0x00000400,
60760 + GR_PROCACCT = 0x00000800,
60761 + GR_RELAXPTRACE = 0x00001000,
60762 + GR_NESTED = 0x00002000,
60763 + GR_INHERITLEARN = 0x00004000,
60764 + GR_PROCFIND = 0x00008000,
60765 + GR_POVERRIDE = 0x00010000,
60766 + GR_KERNELAUTH = 0x00020000,
60767 + GR_ATSECURE = 0x00040000,
60768 + GR_SHMEXEC = 0x00080000
60769 +};
60770 +
60771 +enum {
60772 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
60773 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
60774 + GR_PAX_ENABLE_MPROTECT = 0x0004,
60775 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
60776 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
60777 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
60778 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
60779 + GR_PAX_DISABLE_MPROTECT = 0x0400,
60780 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
60781 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
60782 +};
60783 +
60784 +enum {
60785 + GR_ID_USER = 0x01,
60786 + GR_ID_GROUP = 0x02,
60787 +};
60788 +
60789 +enum {
60790 + GR_ID_ALLOW = 0x01,
60791 + GR_ID_DENY = 0x02,
60792 +};
60793 +
60794 +#define GR_CRASH_RES 31
60795 +#define GR_UIDTABLE_MAX 500
60796 +
60797 +/* begin resource learning section */
60798 +enum {
60799 + GR_RLIM_CPU_BUMP = 60,
60800 + GR_RLIM_FSIZE_BUMP = 50000,
60801 + GR_RLIM_DATA_BUMP = 10000,
60802 + GR_RLIM_STACK_BUMP = 1000,
60803 + GR_RLIM_CORE_BUMP = 10000,
60804 + GR_RLIM_RSS_BUMP = 500000,
60805 + GR_RLIM_NPROC_BUMP = 1,
60806 + GR_RLIM_NOFILE_BUMP = 5,
60807 + GR_RLIM_MEMLOCK_BUMP = 50000,
60808 + GR_RLIM_AS_BUMP = 500000,
60809 + GR_RLIM_LOCKS_BUMP = 2,
60810 + GR_RLIM_SIGPENDING_BUMP = 5,
60811 + GR_RLIM_MSGQUEUE_BUMP = 10000,
60812 + GR_RLIM_NICE_BUMP = 1,
60813 + GR_RLIM_RTPRIO_BUMP = 1,
60814 + GR_RLIM_RTTIME_BUMP = 1000000
60815 +};
60816 +
60817 +#endif
60818 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
60819 new file mode 100644
60820 index 0000000..c9292f7
60821 --- /dev/null
60822 +++ b/include/linux/grinternal.h
60823 @@ -0,0 +1,223 @@
60824 +#ifndef __GRINTERNAL_H
60825 +#define __GRINTERNAL_H
60826 +
60827 +#ifdef CONFIG_GRKERNSEC
60828 +
60829 +#include <linux/fs.h>
60830 +#include <linux/mnt_namespace.h>
60831 +#include <linux/nsproxy.h>
60832 +#include <linux/gracl.h>
60833 +#include <linux/grdefs.h>
60834 +#include <linux/grmsg.h>
60835 +
60836 +void gr_add_learn_entry(const char *fmt, ...)
60837 + __attribute__ ((format (printf, 1, 2)));
60838 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
60839 + const struct vfsmount *mnt);
60840 +__u32 gr_check_create(const struct dentry *new_dentry,
60841 + const struct dentry *parent,
60842 + const struct vfsmount *mnt, const __u32 mode);
60843 +int gr_check_protected_task(const struct task_struct *task);
60844 +__u32 to_gr_audit(const __u32 reqmode);
60845 +int gr_set_acls(const int type);
60846 +int gr_apply_subject_to_task(struct task_struct *task);
60847 +int gr_acl_is_enabled(void);
60848 +char gr_roletype_to_char(void);
60849 +
60850 +void gr_handle_alertkill(struct task_struct *task);
60851 +char *gr_to_filename(const struct dentry *dentry,
60852 + const struct vfsmount *mnt);
60853 +char *gr_to_filename1(const struct dentry *dentry,
60854 + const struct vfsmount *mnt);
60855 +char *gr_to_filename2(const struct dentry *dentry,
60856 + const struct vfsmount *mnt);
60857 +char *gr_to_filename3(const struct dentry *dentry,
60858 + const struct vfsmount *mnt);
60859 +
60860 +extern int grsec_enable_ptrace_readexec;
60861 +extern int grsec_enable_harden_ptrace;
60862 +extern int grsec_enable_link;
60863 +extern int grsec_enable_fifo;
60864 +extern int grsec_enable_execve;
60865 +extern int grsec_enable_shm;
60866 +extern int grsec_enable_execlog;
60867 +extern int grsec_enable_signal;
60868 +extern int grsec_enable_audit_ptrace;
60869 +extern int grsec_enable_forkfail;
60870 +extern int grsec_enable_time;
60871 +extern int grsec_enable_rofs;
60872 +extern int grsec_enable_chroot_shmat;
60873 +extern int grsec_enable_chroot_mount;
60874 +extern int grsec_enable_chroot_double;
60875 +extern int grsec_enable_chroot_pivot;
60876 +extern int grsec_enable_chroot_chdir;
60877 +extern int grsec_enable_chroot_chmod;
60878 +extern int grsec_enable_chroot_mknod;
60879 +extern int grsec_enable_chroot_fchdir;
60880 +extern int grsec_enable_chroot_nice;
60881 +extern int grsec_enable_chroot_execlog;
60882 +extern int grsec_enable_chroot_caps;
60883 +extern int grsec_enable_chroot_sysctl;
60884 +extern int grsec_enable_chroot_unix;
60885 +extern int grsec_enable_symlinkown;
60886 +extern int grsec_symlinkown_gid;
60887 +extern int grsec_enable_tpe;
60888 +extern int grsec_tpe_gid;
60889 +extern int grsec_enable_tpe_all;
60890 +extern int grsec_enable_tpe_invert;
60891 +extern int grsec_enable_socket_all;
60892 +extern int grsec_socket_all_gid;
60893 +extern int grsec_enable_socket_client;
60894 +extern int grsec_socket_client_gid;
60895 +extern int grsec_enable_socket_server;
60896 +extern int grsec_socket_server_gid;
60897 +extern int grsec_audit_gid;
60898 +extern int grsec_enable_group;
60899 +extern int grsec_enable_audit_textrel;
60900 +extern int grsec_enable_log_rwxmaps;
60901 +extern int grsec_enable_mount;
60902 +extern int grsec_enable_chdir;
60903 +extern int grsec_resource_logging;
60904 +extern int grsec_enable_blackhole;
60905 +extern int grsec_lastack_retries;
60906 +extern int grsec_enable_brute;
60907 +extern int grsec_lock;
60908 +
60909 +extern spinlock_t grsec_alert_lock;
60910 +extern unsigned long grsec_alert_wtime;
60911 +extern unsigned long grsec_alert_fyet;
60912 +
60913 +extern spinlock_t grsec_audit_lock;
60914 +
60915 +extern rwlock_t grsec_exec_file_lock;
60916 +
60917 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
60918 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
60919 + (tsk)->exec_file->f_vfsmnt) : "/")
60920 +
60921 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
60922 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
60923 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
60924 +
60925 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
60926 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
60927 + (tsk)->exec_file->f_vfsmnt) : "/")
60928 +
60929 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
60930 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
60931 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
60932 +
60933 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
60934 +
60935 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
60936 +
60937 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
60938 + (task)->pid, (cred)->uid, \
60939 + (cred)->euid, (cred)->gid, (cred)->egid, \
60940 + gr_parent_task_fullpath(task), \
60941 + (task)->real_parent->comm, (task)->real_parent->pid, \
60942 + (pcred)->uid, (pcred)->euid, \
60943 + (pcred)->gid, (pcred)->egid
60944 +
60945 +#define GR_CHROOT_CAPS {{ \
60946 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
60947 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
60948 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
60949 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
60950 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
60951 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
60952 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
60953 +
60954 +#define security_learn(normal_msg,args...) \
60955 +({ \
60956 + read_lock(&grsec_exec_file_lock); \
60957 + gr_add_learn_entry(normal_msg "\n", ## args); \
60958 + read_unlock(&grsec_exec_file_lock); \
60959 +})
60960 +
60961 +enum {
60962 + GR_DO_AUDIT,
60963 + GR_DONT_AUDIT,
60964 + /* used for non-audit messages that we shouldn't kill the task on */
60965 + GR_DONT_AUDIT_GOOD
60966 +};
60967 +
60968 +enum {
60969 + GR_TTYSNIFF,
60970 + GR_RBAC,
60971 + GR_RBAC_STR,
60972 + GR_STR_RBAC,
60973 + GR_RBAC_MODE2,
60974 + GR_RBAC_MODE3,
60975 + GR_FILENAME,
60976 + GR_SYSCTL_HIDDEN,
60977 + GR_NOARGS,
60978 + GR_ONE_INT,
60979 + GR_ONE_INT_TWO_STR,
60980 + GR_ONE_STR,
60981 + GR_STR_INT,
60982 + GR_TWO_STR_INT,
60983 + GR_TWO_INT,
60984 + GR_TWO_U64,
60985 + GR_THREE_INT,
60986 + GR_FIVE_INT_TWO_STR,
60987 + GR_TWO_STR,
60988 + GR_THREE_STR,
60989 + GR_FOUR_STR,
60990 + GR_STR_FILENAME,
60991 + GR_FILENAME_STR,
60992 + GR_FILENAME_TWO_INT,
60993 + GR_FILENAME_TWO_INT_STR,
60994 + GR_TEXTREL,
60995 + GR_PTRACE,
60996 + GR_RESOURCE,
60997 + GR_CAP,
60998 + GR_SIG,
60999 + GR_SIG2,
61000 + GR_CRASH1,
61001 + GR_CRASH2,
61002 + GR_PSACCT,
61003 + GR_RWXMAP
61004 +};
61005 +
61006 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
61007 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
61008 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
61009 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
61010 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
61011 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
61012 +#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)
61013 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
61014 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
61015 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
61016 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
61017 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
61018 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
61019 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
61020 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
61021 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
61022 +#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)
61023 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
61024 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
61025 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
61026 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
61027 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
61028 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
61029 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
61030 +#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)
61031 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
61032 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
61033 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
61034 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
61035 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
61036 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
61037 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
61038 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
61039 +#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)
61040 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
61041 +
61042 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
61043 +
61044 +#endif
61045 +
61046 +#endif
61047 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
61048 new file mode 100644
61049 index 0000000..54f4e85
61050 --- /dev/null
61051 +++ b/include/linux/grmsg.h
61052 @@ -0,0 +1,110 @@
61053 +#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"
61054 +#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"
61055 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
61056 +#define GR_STOPMOD_MSG "denied modification of module state by "
61057 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
61058 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
61059 +#define GR_IOPERM_MSG "denied use of ioperm() by "
61060 +#define GR_IOPL_MSG "denied use of iopl() by "
61061 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
61062 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
61063 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
61064 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
61065 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
61066 +#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"
61067 +#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"
61068 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
61069 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
61070 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
61071 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
61072 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
61073 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
61074 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
61075 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
61076 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
61077 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
61078 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
61079 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
61080 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
61081 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
61082 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
61083 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
61084 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
61085 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
61086 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
61087 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
61088 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
61089 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
61090 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
61091 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
61092 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
61093 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
61094 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
61095 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
61096 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
61097 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
61098 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
61099 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
61100 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
61101 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
61102 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
61103 +#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"
61104 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
61105 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
61106 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
61107 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
61108 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
61109 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
61110 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
61111 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
61112 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
61113 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
61114 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
61115 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
61116 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
61117 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
61118 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
61119 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
61120 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
61121 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
61122 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
61123 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
61124 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
61125 +#define GR_NICE_CHROOT_MSG "denied priority change by "
61126 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
61127 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
61128 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
61129 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
61130 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
61131 +#define GR_TIME_MSG "time set by "
61132 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
61133 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
61134 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
61135 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
61136 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
61137 +#define GR_BIND_MSG "denied bind() by "
61138 +#define GR_CONNECT_MSG "denied connect() by "
61139 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
61140 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
61141 +#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"
61142 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
61143 +#define GR_CAP_ACL_MSG "use of %s denied for "
61144 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
61145 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
61146 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
61147 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
61148 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
61149 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
61150 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
61151 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
61152 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
61153 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
61154 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
61155 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
61156 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
61157 +#define GR_VM86_MSG "denied use of vm86 by "
61158 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
61159 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
61160 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
61161 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
61162 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
61163 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
61164 new file mode 100644
61165 index 0000000..38bfb04
61166 --- /dev/null
61167 +++ b/include/linux/grsecurity.h
61168 @@ -0,0 +1,233 @@
61169 +#ifndef GR_SECURITY_H
61170 +#define GR_SECURITY_H
61171 +#include <linux/fs.h>
61172 +#include <linux/fs_struct.h>
61173 +#include <linux/binfmts.h>
61174 +#include <linux/gracl.h>
61175 +
61176 +/* notify of brain-dead configs */
61177 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61178 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
61179 +#endif
61180 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
61181 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
61182 +#endif
61183 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
61184 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
61185 +#endif
61186 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
61187 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
61188 +#endif
61189 +
61190 +#include <linux/compat.h>
61191 +
61192 +struct user_arg_ptr {
61193 +#ifdef CONFIG_COMPAT
61194 + bool is_compat;
61195 +#endif
61196 + union {
61197 + const char __user *const __user *native;
61198 +#ifdef CONFIG_COMPAT
61199 + compat_uptr_t __user *compat;
61200 +#endif
61201 + } ptr;
61202 +};
61203 +
61204 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
61205 +void gr_handle_brute_check(void);
61206 +void gr_handle_kernel_exploit(void);
61207 +int gr_process_user_ban(void);
61208 +
61209 +char gr_roletype_to_char(void);
61210 +
61211 +int gr_acl_enable_at_secure(void);
61212 +
61213 +int gr_check_user_change(int real, int effective, int fs);
61214 +int gr_check_group_change(int real, int effective, int fs);
61215 +
61216 +void gr_del_task_from_ip_table(struct task_struct *p);
61217 +
61218 +int gr_pid_is_chrooted(struct task_struct *p);
61219 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
61220 +int gr_handle_chroot_nice(void);
61221 +int gr_handle_chroot_sysctl(const int op);
61222 +int gr_handle_chroot_setpriority(struct task_struct *p,
61223 + const int niceval);
61224 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
61225 +int gr_handle_chroot_chroot(const struct dentry *dentry,
61226 + const struct vfsmount *mnt);
61227 +void gr_handle_chroot_chdir(struct path *path);
61228 +int gr_handle_chroot_chmod(const struct dentry *dentry,
61229 + const struct vfsmount *mnt, const int mode);
61230 +int gr_handle_chroot_mknod(const struct dentry *dentry,
61231 + const struct vfsmount *mnt, const int mode);
61232 +int gr_handle_chroot_mount(const struct dentry *dentry,
61233 + const struct vfsmount *mnt,
61234 + const char *dev_name);
61235 +int gr_handle_chroot_pivot(void);
61236 +int gr_handle_chroot_unix(const pid_t pid);
61237 +
61238 +int gr_handle_rawio(const struct inode *inode);
61239 +
61240 +void gr_handle_ioperm(void);
61241 +void gr_handle_iopl(void);
61242 +
61243 +umode_t gr_acl_umask(void);
61244 +
61245 +int gr_tpe_allow(const struct file *file);
61246 +
61247 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
61248 +void gr_clear_chroot_entries(struct task_struct *task);
61249 +
61250 +void gr_log_forkfail(const int retval);
61251 +void gr_log_timechange(void);
61252 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
61253 +void gr_log_chdir(const struct dentry *dentry,
61254 + const struct vfsmount *mnt);
61255 +void gr_log_chroot_exec(const struct dentry *dentry,
61256 + const struct vfsmount *mnt);
61257 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
61258 +void gr_log_remount(const char *devname, const int retval);
61259 +void gr_log_unmount(const char *devname, const int retval);
61260 +void gr_log_mount(const char *from, const char *to, const int retval);
61261 +void gr_log_textrel(struct vm_area_struct *vma);
61262 +void gr_log_rwxmmap(struct file *file);
61263 +void gr_log_rwxmprotect(struct file *file);
61264 +
61265 +int gr_handle_follow_link(const struct inode *parent,
61266 + const struct inode *inode,
61267 + const struct dentry *dentry,
61268 + const struct vfsmount *mnt);
61269 +int gr_handle_fifo(const struct dentry *dentry,
61270 + const struct vfsmount *mnt,
61271 + const struct dentry *dir, const int flag,
61272 + const int acc_mode);
61273 +int gr_handle_hardlink(const struct dentry *dentry,
61274 + const struct vfsmount *mnt,
61275 + struct inode *inode,
61276 + const int mode, const char *to);
61277 +
61278 +int gr_is_capable(const int cap);
61279 +int gr_is_capable_nolog(const int cap);
61280 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
61281 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
61282 +
61283 +void gr_learn_resource(const struct task_struct *task, const int limit,
61284 + const unsigned long wanted, const int gt);
61285 +void gr_copy_label(struct task_struct *tsk);
61286 +void gr_handle_crash(struct task_struct *task, const int sig);
61287 +int gr_handle_signal(const struct task_struct *p, const int sig);
61288 +int gr_check_crash_uid(const uid_t uid);
61289 +int gr_check_protected_task(const struct task_struct *task);
61290 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
61291 +int gr_acl_handle_mmap(const struct file *file,
61292 + const unsigned long prot);
61293 +int gr_acl_handle_mprotect(const struct file *file,
61294 + const unsigned long prot);
61295 +int gr_check_hidden_task(const struct task_struct *tsk);
61296 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
61297 + const struct vfsmount *mnt);
61298 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
61299 + const struct vfsmount *mnt);
61300 +__u32 gr_acl_handle_access(const struct dentry *dentry,
61301 + const struct vfsmount *mnt, const int fmode);
61302 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
61303 + const struct vfsmount *mnt, umode_t *mode);
61304 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
61305 + const struct vfsmount *mnt);
61306 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
61307 + const struct vfsmount *mnt);
61308 +int gr_handle_ptrace(struct task_struct *task, const long request);
61309 +int gr_handle_proc_ptrace(struct task_struct *task);
61310 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
61311 + const struct vfsmount *mnt);
61312 +int gr_check_crash_exec(const struct file *filp);
61313 +int gr_acl_is_enabled(void);
61314 +void gr_set_kernel_label(struct task_struct *task);
61315 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
61316 + const gid_t gid);
61317 +int gr_set_proc_label(const struct dentry *dentry,
61318 + const struct vfsmount *mnt,
61319 + const int unsafe_flags);
61320 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
61321 + const struct vfsmount *mnt);
61322 +__u32 gr_acl_handle_open(const struct dentry *dentry,
61323 + const struct vfsmount *mnt, int acc_mode);
61324 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
61325 + const struct dentry *p_dentry,
61326 + const struct vfsmount *p_mnt,
61327 + int open_flags, int acc_mode, const int imode);
61328 +void gr_handle_create(const struct dentry *dentry,
61329 + const struct vfsmount *mnt);
61330 +void gr_handle_proc_create(const struct dentry *dentry,
61331 + const struct inode *inode);
61332 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
61333 + const struct dentry *parent_dentry,
61334 + const struct vfsmount *parent_mnt,
61335 + const int mode);
61336 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
61337 + const struct dentry *parent_dentry,
61338 + const struct vfsmount *parent_mnt);
61339 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
61340 + const struct vfsmount *mnt);
61341 +void gr_handle_delete(const ino_t ino, const dev_t dev);
61342 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
61343 + const struct vfsmount *mnt);
61344 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
61345 + const struct dentry *parent_dentry,
61346 + const struct vfsmount *parent_mnt,
61347 + const char *from);
61348 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
61349 + const struct dentry *parent_dentry,
61350 + const struct vfsmount *parent_mnt,
61351 + const struct dentry *old_dentry,
61352 + const struct vfsmount *old_mnt, const char *to);
61353 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
61354 +int gr_acl_handle_rename(struct dentry *new_dentry,
61355 + struct dentry *parent_dentry,
61356 + const struct vfsmount *parent_mnt,
61357 + struct dentry *old_dentry,
61358 + struct inode *old_parent_inode,
61359 + struct vfsmount *old_mnt, const char *newname);
61360 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
61361 + struct dentry *old_dentry,
61362 + struct dentry *new_dentry,
61363 + struct vfsmount *mnt, const __u8 replace);
61364 +__u32 gr_check_link(const struct dentry *new_dentry,
61365 + const struct dentry *parent_dentry,
61366 + const struct vfsmount *parent_mnt,
61367 + const struct dentry *old_dentry,
61368 + const struct vfsmount *old_mnt);
61369 +int gr_acl_handle_filldir(const struct file *file, const char *name,
61370 + const unsigned int namelen, const ino_t ino);
61371 +
61372 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
61373 + const struct vfsmount *mnt);
61374 +void gr_acl_handle_exit(void);
61375 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
61376 +int gr_acl_handle_procpidmem(const struct task_struct *task);
61377 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
61378 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
61379 +void gr_audit_ptrace(struct task_struct *task);
61380 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
61381 +
61382 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
61383 +
61384 +#ifdef CONFIG_GRKERNSEC
61385 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
61386 +void gr_handle_vm86(void);
61387 +void gr_handle_mem_readwrite(u64 from, u64 to);
61388 +
61389 +void gr_log_badprocpid(const char *entry);
61390 +
61391 +extern int grsec_enable_dmesg;
61392 +extern int grsec_disable_privio;
61393 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61394 +extern int grsec_enable_chroot_findtask;
61395 +#endif
61396 +#ifdef CONFIG_GRKERNSEC_SETXID
61397 +extern int grsec_enable_setxid;
61398 +#endif
61399 +#endif
61400 +
61401 +#endif
61402 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
61403 new file mode 100644
61404 index 0000000..e7ffaaf
61405 --- /dev/null
61406 +++ b/include/linux/grsock.h
61407 @@ -0,0 +1,19 @@
61408 +#ifndef __GRSOCK_H
61409 +#define __GRSOCK_H
61410 +
61411 +extern void gr_attach_curr_ip(const struct sock *sk);
61412 +extern int gr_handle_sock_all(const int family, const int type,
61413 + const int protocol);
61414 +extern int gr_handle_sock_server(const struct sockaddr *sck);
61415 +extern int gr_handle_sock_server_other(const struct sock *sck);
61416 +extern int gr_handle_sock_client(const struct sockaddr *sck);
61417 +extern int gr_search_connect(struct socket * sock,
61418 + struct sockaddr_in * addr);
61419 +extern int gr_search_bind(struct socket * sock,
61420 + struct sockaddr_in * addr);
61421 +extern int gr_search_listen(struct socket * sock);
61422 +extern int gr_search_accept(struct socket * sock);
61423 +extern int gr_search_socket(const int domain, const int type,
61424 + const int protocol);
61425 +
61426 +#endif
61427 diff --git a/include/linux/hid.h b/include/linux/hid.h
61428 index 3a95da6..51986f1 100644
61429 --- a/include/linux/hid.h
61430 +++ b/include/linux/hid.h
61431 @@ -696,7 +696,7 @@ struct hid_ll_driver {
61432 unsigned int code, int value);
61433
61434 int (*parse)(struct hid_device *hdev);
61435 -};
61436 +} __no_const;
61437
61438 #define PM_HINT_FULLON 1<<5
61439 #define PM_HINT_NORMAL 1<<1
61440 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
61441 index d3999b4..1304cb4 100644
61442 --- a/include/linux/highmem.h
61443 +++ b/include/linux/highmem.h
61444 @@ -221,6 +221,18 @@ static inline void clear_highpage(struct page *page)
61445 kunmap_atomic(kaddr);
61446 }
61447
61448 +static inline void sanitize_highpage(struct page *page)
61449 +{
61450 + void *kaddr;
61451 + unsigned long flags;
61452 +
61453 + local_irq_save(flags);
61454 + kaddr = kmap_atomic(page);
61455 + clear_page(kaddr);
61456 + kunmap_atomic(kaddr);
61457 + local_irq_restore(flags);
61458 +}
61459 +
61460 static inline void zero_user_segments(struct page *page,
61461 unsigned start1, unsigned end1,
61462 unsigned start2, unsigned end2)
61463 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
61464 index 195d8b3..e20cfab 100644
61465 --- a/include/linux/i2c.h
61466 +++ b/include/linux/i2c.h
61467 @@ -365,6 +365,7 @@ struct i2c_algorithm {
61468 /* To determine what the adapter supports */
61469 u32 (*functionality) (struct i2c_adapter *);
61470 };
61471 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
61472
61473 /*
61474 * i2c_adapter is the structure used to identify a physical i2c bus along
61475 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
61476 index d23c3c2..eb63c81 100644
61477 --- a/include/linux/i2o.h
61478 +++ b/include/linux/i2o.h
61479 @@ -565,7 +565,7 @@ struct i2o_controller {
61480 struct i2o_device *exec; /* Executive */
61481 #if BITS_PER_LONG == 64
61482 spinlock_t context_list_lock; /* lock for context_list */
61483 - atomic_t context_list_counter; /* needed for unique contexts */
61484 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
61485 struct list_head context_list; /* list of context id's
61486 and pointers */
61487 #endif
61488 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
61489 index 58404b0..439ed95 100644
61490 --- a/include/linux/if_team.h
61491 +++ b/include/linux/if_team.h
61492 @@ -64,6 +64,7 @@ struct team_mode_ops {
61493 void (*port_leave)(struct team *team, struct team_port *port);
61494 void (*port_change_mac)(struct team *team, struct team_port *port);
61495 };
61496 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
61497
61498 enum team_option_type {
61499 TEAM_OPTION_TYPE_U32,
61500 @@ -112,7 +113,7 @@ struct team {
61501 struct list_head option_list;
61502
61503 const struct team_mode *mode;
61504 - struct team_mode_ops ops;
61505 + team_mode_ops_no_const ops;
61506 long mode_priv[TEAM_MODE_PRIV_LONGS];
61507 };
61508
61509 diff --git a/include/linux/init.h b/include/linux/init.h
61510 index 6b95109..4aca62c 100644
61511 --- a/include/linux/init.h
61512 +++ b/include/linux/init.h
61513 @@ -294,13 +294,13 @@ void __init parse_early_options(char *cmdline);
61514
61515 /* Each module must use one module_init(). */
61516 #define module_init(initfn) \
61517 - static inline initcall_t __inittest(void) \
61518 + static inline __used initcall_t __inittest(void) \
61519 { return initfn; } \
61520 int init_module(void) __attribute__((alias(#initfn)));
61521
61522 /* This is only required if you want to be unloadable. */
61523 #define module_exit(exitfn) \
61524 - static inline exitcall_t __exittest(void) \
61525 + static inline __used exitcall_t __exittest(void) \
61526 { return exitfn; } \
61527 void cleanup_module(void) __attribute__((alias(#exitfn)));
61528
61529 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
61530 index e4baff5..83bb175 100644
61531 --- a/include/linux/init_task.h
61532 +++ b/include/linux/init_task.h
61533 @@ -134,6 +134,12 @@ extern struct cred init_cred;
61534
61535 #define INIT_TASK_COMM "swapper"
61536
61537 +#ifdef CONFIG_X86
61538 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
61539 +#else
61540 +#define INIT_TASK_THREAD_INFO
61541 +#endif
61542 +
61543 /*
61544 * INIT_TASK is used to set up the first task table, touch at
61545 * your own risk!. Base=0, limit=0x1fffff (=2MB)
61546 @@ -172,6 +178,7 @@ extern struct cred init_cred;
61547 RCU_INIT_POINTER(.cred, &init_cred), \
61548 .comm = INIT_TASK_COMM, \
61549 .thread = INIT_THREAD, \
61550 + INIT_TASK_THREAD_INFO \
61551 .fs = &init_fs, \
61552 .files = &init_files, \
61553 .signal = &init_signals, \
61554 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
61555 index e6ca56d..8583707 100644
61556 --- a/include/linux/intel-iommu.h
61557 +++ b/include/linux/intel-iommu.h
61558 @@ -296,7 +296,7 @@ struct iommu_flush {
61559 u8 fm, u64 type);
61560 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
61561 unsigned int size_order, u64 type);
61562 -};
61563 +} __no_const;
61564
61565 enum {
61566 SR_DMAR_FECTL_REG,
61567 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
61568 index 2aea5d2..0b82f0c 100644
61569 --- a/include/linux/interrupt.h
61570 +++ b/include/linux/interrupt.h
61571 @@ -439,7 +439,7 @@ enum
61572 /* map softirq index to softirq name. update 'softirq_to_name' in
61573 * kernel/softirq.c when adding a new softirq.
61574 */
61575 -extern char *softirq_to_name[NR_SOFTIRQS];
61576 +extern const char * const softirq_to_name[NR_SOFTIRQS];
61577
61578 /* softirq mask and active fields moved to irq_cpustat_t in
61579 * asm/hardirq.h to get better cache usage. KAO
61580 @@ -447,12 +447,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
61581
61582 struct softirq_action
61583 {
61584 - void (*action)(struct softirq_action *);
61585 + void (*action)(void);
61586 };
61587
61588 asmlinkage void do_softirq(void);
61589 asmlinkage void __do_softirq(void);
61590 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
61591 +extern void open_softirq(int nr, void (*action)(void));
61592 extern void softirq_init(void);
61593 extern void __raise_softirq_irqoff(unsigned int nr);
61594
61595 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
61596 index 3875719..4cd454c 100644
61597 --- a/include/linux/kallsyms.h
61598 +++ b/include/linux/kallsyms.h
61599 @@ -15,7 +15,8 @@
61600
61601 struct module;
61602
61603 -#ifdef CONFIG_KALLSYMS
61604 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
61605 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
61606 /* Lookup the address for a symbol. Returns 0 if not found. */
61607 unsigned long kallsyms_lookup_name(const char *name);
61608
61609 @@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
61610 /* Stupid that this does nothing, but I didn't create this mess. */
61611 #define __print_symbol(fmt, addr)
61612 #endif /*CONFIG_KALLSYMS*/
61613 +#else /* when included by kallsyms.c, vsnprintf.c, or
61614 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
61615 +extern void __print_symbol(const char *fmt, unsigned long address);
61616 +extern int sprint_backtrace(char *buffer, unsigned long address);
61617 +extern int sprint_symbol(char *buffer, unsigned long address);
61618 +const char *kallsyms_lookup(unsigned long addr,
61619 + unsigned long *symbolsize,
61620 + unsigned long *offset,
61621 + char **modname, char *namebuf);
61622 +#endif
61623
61624 /* This macro allows us to keep printk typechecking */
61625 static __printf(1, 2)
61626 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
61627 index c4d2fc1..5df9c19 100644
61628 --- a/include/linux/kgdb.h
61629 +++ b/include/linux/kgdb.h
61630 @@ -53,7 +53,7 @@ extern int kgdb_connected;
61631 extern int kgdb_io_module_registered;
61632
61633 extern atomic_t kgdb_setting_breakpoint;
61634 -extern atomic_t kgdb_cpu_doing_single_step;
61635 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
61636
61637 extern struct task_struct *kgdb_usethread;
61638 extern struct task_struct *kgdb_contthread;
61639 @@ -252,7 +252,7 @@ struct kgdb_arch {
61640 void (*disable_hw_break)(struct pt_regs *regs);
61641 void (*remove_all_hw_break)(void);
61642 void (*correct_hw_break)(void);
61643 -};
61644 +} __do_const;
61645
61646 /**
61647 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
61648 @@ -277,7 +277,7 @@ struct kgdb_io {
61649 void (*pre_exception) (void);
61650 void (*post_exception) (void);
61651 int is_console;
61652 -};
61653 +} __do_const;
61654
61655 extern struct kgdb_arch arch_kgdb_ops;
61656
61657 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
61658 index dd99c32..da06047 100644
61659 --- a/include/linux/kmod.h
61660 +++ b/include/linux/kmod.h
61661 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
61662 * usually useless though. */
61663 extern __printf(2, 3)
61664 int __request_module(bool wait, const char *name, ...);
61665 +extern __printf(3, 4)
61666 +int ___request_module(bool wait, char *param_name, const char *name, ...);
61667 #define request_module(mod...) __request_module(true, mod)
61668 #define request_module_nowait(mod...) __request_module(false, mod)
61669 #define try_then_request_module(x, mod...) \
61670 diff --git a/include/linux/kref.h b/include/linux/kref.h
61671 index 9c07dce..a92fa71 100644
61672 --- a/include/linux/kref.h
61673 +++ b/include/linux/kref.h
61674 @@ -63,7 +63,7 @@ static inline void kref_get(struct kref *kref)
61675 static inline int kref_sub(struct kref *kref, unsigned int count,
61676 void (*release)(struct kref *kref))
61677 {
61678 - WARN_ON(release == NULL);
61679 + BUG_ON(release == NULL);
61680
61681 if (atomic_sub_and_test((int) count, &kref->refcount)) {
61682 release(kref);
61683 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
61684 index 72cbf08..dd0201d 100644
61685 --- a/include/linux/kvm_host.h
61686 +++ b/include/linux/kvm_host.h
61687 @@ -322,7 +322,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
61688 void vcpu_load(struct kvm_vcpu *vcpu);
61689 void vcpu_put(struct kvm_vcpu *vcpu);
61690
61691 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
61692 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
61693 struct module *module);
61694 void kvm_exit(void);
61695
61696 @@ -486,7 +486,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
61697 struct kvm_guest_debug *dbg);
61698 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
61699
61700 -int kvm_arch_init(void *opaque);
61701 +int kvm_arch_init(const void *opaque);
61702 void kvm_arch_exit(void);
61703
61704 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
61705 diff --git a/include/linux/libata.h b/include/linux/libata.h
61706 index 6e887c7..4539601 100644
61707 --- a/include/linux/libata.h
61708 +++ b/include/linux/libata.h
61709 @@ -910,7 +910,7 @@ struct ata_port_operations {
61710 * fields must be pointers.
61711 */
61712 const struct ata_port_operations *inherits;
61713 -};
61714 +} __do_const;
61715
61716 struct ata_port_info {
61717 unsigned long flags;
61718 diff --git a/include/linux/mca.h b/include/linux/mca.h
61719 index 3797270..7765ede 100644
61720 --- a/include/linux/mca.h
61721 +++ b/include/linux/mca.h
61722 @@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
61723 int region);
61724 void * (*mca_transform_memory)(struct mca_device *,
61725 void *memory);
61726 -};
61727 +} __no_const;
61728
61729 struct mca_bus {
61730 u64 default_dma_mask;
61731 diff --git a/include/linux/memory.h b/include/linux/memory.h
61732 index 1ac7f6e..a5794d0 100644
61733 --- a/include/linux/memory.h
61734 +++ b/include/linux/memory.h
61735 @@ -143,7 +143,7 @@ struct memory_accessor {
61736 size_t count);
61737 ssize_t (*write)(struct memory_accessor *, const char *buf,
61738 off_t offset, size_t count);
61739 -};
61740 +} __no_const;
61741
61742 /*
61743 * Kernel text modification mutex, used for code patching. Users of this lock
61744 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
61745 index ee96cd5..7823c3a 100644
61746 --- a/include/linux/mfd/abx500.h
61747 +++ b/include/linux/mfd/abx500.h
61748 @@ -455,6 +455,7 @@ struct abx500_ops {
61749 int (*event_registers_startup_state_get) (struct device *, u8 *);
61750 int (*startup_irq_enabled) (struct device *, unsigned int);
61751 };
61752 +typedef struct abx500_ops __no_const abx500_ops_no_const;
61753
61754 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
61755 void abx500_remove_ops(struct device *dev);
61756 diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
61757 index 9b07725..3d55001 100644
61758 --- a/include/linux/mfd/abx500/ux500_chargalg.h
61759 +++ b/include/linux/mfd/abx500/ux500_chargalg.h
61760 @@ -19,7 +19,7 @@ struct ux500_charger_ops {
61761 int (*enable) (struct ux500_charger *, int, int, int);
61762 int (*kick_wd) (struct ux500_charger *);
61763 int (*update_curr) (struct ux500_charger *, int);
61764 -};
61765 +} __no_const;
61766
61767 /**
61768 * struct ux500_charger - power supply ux500 charger sub class
61769 diff --git a/include/linux/mm.h b/include/linux/mm.h
61770 index 74aa71b..4ae97ba 100644
61771 --- a/include/linux/mm.h
61772 +++ b/include/linux/mm.h
61773 @@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
61774
61775 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
61776 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
61777 +
61778 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
61779 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
61780 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
61781 +#else
61782 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
61783 +#endif
61784 +
61785 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
61786 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
61787
61788 @@ -1013,34 +1020,6 @@ int set_page_dirty(struct page *page);
61789 int set_page_dirty_lock(struct page *page);
61790 int clear_page_dirty_for_io(struct page *page);
61791
61792 -/* Is the vma a continuation of the stack vma above it? */
61793 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
61794 -{
61795 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
61796 -}
61797 -
61798 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
61799 - unsigned long addr)
61800 -{
61801 - return (vma->vm_flags & VM_GROWSDOWN) &&
61802 - (vma->vm_start == addr) &&
61803 - !vma_growsdown(vma->vm_prev, addr);
61804 -}
61805 -
61806 -/* Is the vma a continuation of the stack vma below it? */
61807 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
61808 -{
61809 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
61810 -}
61811 -
61812 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
61813 - unsigned long addr)
61814 -{
61815 - return (vma->vm_flags & VM_GROWSUP) &&
61816 - (vma->vm_end == addr) &&
61817 - !vma_growsup(vma->vm_next, addr);
61818 -}
61819 -
61820 extern pid_t
61821 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
61822
61823 @@ -1139,6 +1118,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
61824 }
61825 #endif
61826
61827 +#ifdef CONFIG_MMU
61828 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
61829 +#else
61830 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
61831 +{
61832 + return __pgprot(0);
61833 +}
61834 +#endif
61835 +
61836 int vma_wants_writenotify(struct vm_area_struct *vma);
61837
61838 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
61839 @@ -1157,8 +1145,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
61840 {
61841 return 0;
61842 }
61843 +
61844 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
61845 + unsigned long address)
61846 +{
61847 + return 0;
61848 +}
61849 #else
61850 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
61851 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
61852 #endif
61853
61854 #ifdef __PAGETABLE_PMD_FOLDED
61855 @@ -1167,8 +1162,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
61856 {
61857 return 0;
61858 }
61859 +
61860 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
61861 + unsigned long address)
61862 +{
61863 + return 0;
61864 +}
61865 #else
61866 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
61867 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
61868 #endif
61869
61870 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
61871 @@ -1186,11 +1188,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
61872 NULL: pud_offset(pgd, address);
61873 }
61874
61875 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
61876 +{
61877 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
61878 + NULL: pud_offset(pgd, address);
61879 +}
61880 +
61881 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
61882 {
61883 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
61884 NULL: pmd_offset(pud, address);
61885 }
61886 +
61887 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
61888 +{
61889 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
61890 + NULL: pmd_offset(pud, address);
61891 +}
61892 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
61893
61894 #if USE_SPLIT_PTLOCKS
61895 @@ -1400,6 +1414,7 @@ extern unsigned long do_mmap(struct file *, unsigned long,
61896 unsigned long, unsigned long,
61897 unsigned long, unsigned long);
61898 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
61899 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
61900
61901 /* These take the mm semaphore themselves */
61902 extern unsigned long vm_brk(unsigned long, unsigned long);
61903 @@ -1462,6 +1477,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
61904 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
61905 struct vm_area_struct **pprev);
61906
61907 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
61908 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
61909 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
61910 +
61911 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
61912 NULL if none. Assume start_addr < end_addr. */
61913 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
61914 @@ -1490,15 +1509,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
61915 return vma;
61916 }
61917
61918 -#ifdef CONFIG_MMU
61919 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
61920 -#else
61921 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
61922 -{
61923 - return __pgprot(0);
61924 -}
61925 -#endif
61926 -
61927 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
61928 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
61929 unsigned long pfn, unsigned long size, pgprot_t);
61930 @@ -1602,7 +1612,7 @@ extern int unpoison_memory(unsigned long pfn);
61931 extern int sysctl_memory_failure_early_kill;
61932 extern int sysctl_memory_failure_recovery;
61933 extern void shake_page(struct page *p, int access);
61934 -extern atomic_long_t mce_bad_pages;
61935 +extern atomic_long_unchecked_t mce_bad_pages;
61936 extern int soft_offline_page(struct page *page, int flags);
61937
61938 extern void dump_page(struct page *page);
61939 @@ -1633,5 +1643,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
61940 static inline bool page_is_guard(struct page *page) { return false; }
61941 #endif /* CONFIG_DEBUG_PAGEALLOC */
61942
61943 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
61944 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
61945 +#else
61946 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
61947 +#endif
61948 +
61949 #endif /* __KERNEL__ */
61950 #endif /* _LINUX_MM_H */
61951 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
61952 index b35752f..41075a0 100644
61953 --- a/include/linux/mm_types.h
61954 +++ b/include/linux/mm_types.h
61955 @@ -262,6 +262,8 @@ struct vm_area_struct {
61956 #ifdef CONFIG_NUMA
61957 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
61958 #endif
61959 +
61960 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
61961 };
61962
61963 struct core_thread {
61964 @@ -336,7 +338,7 @@ struct mm_struct {
61965 unsigned long def_flags;
61966 unsigned long nr_ptes; /* Page table pages */
61967 unsigned long start_code, end_code, start_data, end_data;
61968 - unsigned long start_brk, brk, start_stack;
61969 + unsigned long brk_gap, start_brk, brk, start_stack;
61970 unsigned long arg_start, arg_end, env_start, env_end;
61971
61972 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
61973 @@ -398,6 +400,24 @@ struct mm_struct {
61974 #ifdef CONFIG_CPUMASK_OFFSTACK
61975 struct cpumask cpumask_allocation;
61976 #endif
61977 +
61978 +#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)
61979 + unsigned long pax_flags;
61980 +#endif
61981 +
61982 +#ifdef CONFIG_PAX_DLRESOLVE
61983 + unsigned long call_dl_resolve;
61984 +#endif
61985 +
61986 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
61987 + unsigned long call_syscall;
61988 +#endif
61989 +
61990 +#ifdef CONFIG_PAX_ASLR
61991 + unsigned long delta_mmap; /* randomized offset */
61992 + unsigned long delta_stack; /* randomized offset */
61993 +#endif
61994 +
61995 };
61996
61997 static inline void mm_init_cpumask(struct mm_struct *mm)
61998 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
61999 index 1d1b1e1..2a13c78 100644
62000 --- a/include/linux/mmu_notifier.h
62001 +++ b/include/linux/mmu_notifier.h
62002 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
62003 */
62004 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
62005 ({ \
62006 - pte_t __pte; \
62007 + pte_t ___pte; \
62008 struct vm_area_struct *___vma = __vma; \
62009 unsigned long ___address = __address; \
62010 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
62011 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
62012 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
62013 - __pte; \
62014 + ___pte; \
62015 })
62016
62017 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
62018 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
62019 index 5f6806b..49db2b2 100644
62020 --- a/include/linux/mmzone.h
62021 +++ b/include/linux/mmzone.h
62022 @@ -380,7 +380,7 @@ struct zone {
62023 unsigned long flags; /* zone flags, see below */
62024
62025 /* Zone statistics */
62026 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62027 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62028
62029 /*
62030 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
62031 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
62032 index 501da4c..ba79bb4 100644
62033 --- a/include/linux/mod_devicetable.h
62034 +++ b/include/linux/mod_devicetable.h
62035 @@ -12,7 +12,7 @@
62036 typedef unsigned long kernel_ulong_t;
62037 #endif
62038
62039 -#define PCI_ANY_ID (~0)
62040 +#define PCI_ANY_ID ((__u16)~0)
62041
62042 struct pci_device_id {
62043 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
62044 @@ -131,7 +131,7 @@ struct usb_device_id {
62045 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
62046 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
62047
62048 -#define HID_ANY_ID (~0)
62049 +#define HID_ANY_ID (~0U)
62050
62051 struct hid_device_id {
62052 __u16 bus;
62053 diff --git a/include/linux/module.h b/include/linux/module.h
62054 index fbcafe2..e5d9587 100644
62055 --- a/include/linux/module.h
62056 +++ b/include/linux/module.h
62057 @@ -17,6 +17,7 @@
62058 #include <linux/moduleparam.h>
62059 #include <linux/tracepoint.h>
62060 #include <linux/export.h>
62061 +#include <linux/fs.h>
62062
62063 #include <linux/percpu.h>
62064 #include <asm/module.h>
62065 @@ -273,19 +274,16 @@ struct module
62066 int (*init)(void);
62067
62068 /* If this is non-NULL, vfree after init() returns */
62069 - void *module_init;
62070 + void *module_init_rx, *module_init_rw;
62071
62072 /* Here is the actual code + data, vfree'd on unload. */
62073 - void *module_core;
62074 + void *module_core_rx, *module_core_rw;
62075
62076 /* Here are the sizes of the init and core sections */
62077 - unsigned int init_size, core_size;
62078 + unsigned int init_size_rw, core_size_rw;
62079
62080 /* The size of the executable code in each section. */
62081 - unsigned int init_text_size, core_text_size;
62082 -
62083 - /* Size of RO sections of the module (text+rodata) */
62084 - unsigned int init_ro_size, core_ro_size;
62085 + unsigned int init_size_rx, core_size_rx;
62086
62087 /* Arch-specific module values */
62088 struct mod_arch_specific arch;
62089 @@ -341,6 +339,10 @@ struct module
62090 #ifdef CONFIG_EVENT_TRACING
62091 struct ftrace_event_call **trace_events;
62092 unsigned int num_trace_events;
62093 + struct file_operations trace_id;
62094 + struct file_operations trace_enable;
62095 + struct file_operations trace_format;
62096 + struct file_operations trace_filter;
62097 #endif
62098 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
62099 unsigned int num_ftrace_callsites;
62100 @@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
62101 bool is_module_percpu_address(unsigned long addr);
62102 bool is_module_text_address(unsigned long addr);
62103
62104 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
62105 +{
62106 +
62107 +#ifdef CONFIG_PAX_KERNEXEC
62108 + if (ktla_ktva(addr) >= (unsigned long)start &&
62109 + ktla_ktva(addr) < (unsigned long)start + size)
62110 + return 1;
62111 +#endif
62112 +
62113 + return ((void *)addr >= start && (void *)addr < start + size);
62114 +}
62115 +
62116 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
62117 +{
62118 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
62119 +}
62120 +
62121 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
62122 +{
62123 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
62124 +}
62125 +
62126 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
62127 +{
62128 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
62129 +}
62130 +
62131 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
62132 +{
62133 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
62134 +}
62135 +
62136 static inline int within_module_core(unsigned long addr, struct module *mod)
62137 {
62138 - return (unsigned long)mod->module_core <= addr &&
62139 - addr < (unsigned long)mod->module_core + mod->core_size;
62140 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
62141 }
62142
62143 static inline int within_module_init(unsigned long addr, struct module *mod)
62144 {
62145 - return (unsigned long)mod->module_init <= addr &&
62146 - addr < (unsigned long)mod->module_init + mod->init_size;
62147 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
62148 }
62149
62150 /* Search for module by name: must hold module_mutex. */
62151 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
62152 index b2be02e..72d2f78 100644
62153 --- a/include/linux/moduleloader.h
62154 +++ b/include/linux/moduleloader.h
62155 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
62156
62157 /* Allocator used for allocating struct module, core sections and init
62158 sections. Returns NULL on failure. */
62159 -void *module_alloc(unsigned long size);
62160 +void *module_alloc(unsigned long size) __size_overflow(1);
62161 +
62162 +#ifdef CONFIG_PAX_KERNEXEC
62163 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
62164 +#else
62165 +#define module_alloc_exec(x) module_alloc(x)
62166 +#endif
62167
62168 /* Free memory returned from module_alloc. */
62169 void module_free(struct module *mod, void *module_region);
62170
62171 +#ifdef CONFIG_PAX_KERNEXEC
62172 +void module_free_exec(struct module *mod, void *module_region);
62173 +#else
62174 +#define module_free_exec(x, y) module_free((x), (y))
62175 +#endif
62176 +
62177 /* Apply the given relocation to the (simplified) ELF. Return -error
62178 or 0. */
62179 int apply_relocate(Elf_Shdr *sechdrs,
62180 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
62181 index 944bc18..042d291 100644
62182 --- a/include/linux/moduleparam.h
62183 +++ b/include/linux/moduleparam.h
62184 @@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
62185 * @len is usually just sizeof(string).
62186 */
62187 #define module_param_string(name, string, len, perm) \
62188 - static const struct kparam_string __param_string_##name \
62189 + static const struct kparam_string __param_string_##name __used \
62190 = { len, string }; \
62191 __module_param_call(MODULE_PARAM_PREFIX, name, \
62192 &param_ops_string, \
62193 @@ -424,7 +424,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
62194 */
62195 #define module_param_array_named(name, array, type, nump, perm) \
62196 param_check_##type(name, &(array)[0]); \
62197 - static const struct kparam_array __param_arr_##name \
62198 + static const struct kparam_array __param_arr_##name __used \
62199 = { .max = ARRAY_SIZE(array), .num = nump, \
62200 .ops = &param_ops_##type, \
62201 .elemsize = sizeof(array[0]), .elem = array }; \
62202 diff --git a/include/linux/namei.h b/include/linux/namei.h
62203 index ffc0213..2c1f2cb 100644
62204 --- a/include/linux/namei.h
62205 +++ b/include/linux/namei.h
62206 @@ -24,7 +24,7 @@ struct nameidata {
62207 unsigned seq;
62208 int last_type;
62209 unsigned depth;
62210 - char *saved_names[MAX_NESTED_LINKS + 1];
62211 + const char *saved_names[MAX_NESTED_LINKS + 1];
62212
62213 /* Intent data */
62214 union {
62215 @@ -94,12 +94,12 @@ extern int follow_up(struct path *);
62216 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
62217 extern void unlock_rename(struct dentry *, struct dentry *);
62218
62219 -static inline void nd_set_link(struct nameidata *nd, char *path)
62220 +static inline void nd_set_link(struct nameidata *nd, const char *path)
62221 {
62222 nd->saved_names[nd->depth] = path;
62223 }
62224
62225 -static inline char *nd_get_link(struct nameidata *nd)
62226 +static inline const char *nd_get_link(const struct nameidata *nd)
62227 {
62228 return nd->saved_names[nd->depth];
62229 }
62230 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
62231 index 33900a5..2072000 100644
62232 --- a/include/linux/netdevice.h
62233 +++ b/include/linux/netdevice.h
62234 @@ -1003,6 +1003,7 @@ struct net_device_ops {
62235 int (*ndo_neigh_construct)(struct neighbour *n);
62236 void (*ndo_neigh_destroy)(struct neighbour *n);
62237 };
62238 +typedef struct net_device_ops __no_const net_device_ops_no_const;
62239
62240 /*
62241 * The DEVICE structure.
62242 @@ -1064,7 +1065,7 @@ struct net_device {
62243 int iflink;
62244
62245 struct net_device_stats stats;
62246 - atomic_long_t rx_dropped; /* dropped packets by core network
62247 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
62248 * Do not use this in drivers.
62249 */
62250
62251 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
62252 new file mode 100644
62253 index 0000000..33f4af8
62254 --- /dev/null
62255 +++ b/include/linux/netfilter/xt_gradm.h
62256 @@ -0,0 +1,9 @@
62257 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
62258 +#define _LINUX_NETFILTER_XT_GRADM_H 1
62259 +
62260 +struct xt_gradm_mtinfo {
62261 + __u16 flags;
62262 + __u16 invflags;
62263 +};
62264 +
62265 +#endif
62266 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
62267 index c65a18a..0c05f3a 100644
62268 --- a/include/linux/of_pdt.h
62269 +++ b/include/linux/of_pdt.h
62270 @@ -32,7 +32,7 @@ struct of_pdt_ops {
62271
62272 /* return 0 on success; fill in 'len' with number of bytes in path */
62273 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
62274 -};
62275 +} __no_const;
62276
62277 extern void *prom_early_alloc(unsigned long size);
62278
62279 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
62280 index a4c5624..79d6d88 100644
62281 --- a/include/linux/oprofile.h
62282 +++ b/include/linux/oprofile.h
62283 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
62284 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
62285 char const * name, ulong * val);
62286
62287 -/** Create a file for read-only access to an atomic_t. */
62288 +/** Create a file for read-only access to an atomic_unchecked_t. */
62289 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
62290 - char const * name, atomic_t * val);
62291 + char const * name, atomic_unchecked_t * val);
62292
62293 /** create a directory */
62294 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
62295 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
62296 index ddbb6a9..be1680e 100644
62297 --- a/include/linux/perf_event.h
62298 +++ b/include/linux/perf_event.h
62299 @@ -879,8 +879,8 @@ struct perf_event {
62300
62301 enum perf_event_active_state state;
62302 unsigned int attach_state;
62303 - local64_t count;
62304 - atomic64_t child_count;
62305 + local64_t count; /* PaX: fix it one day */
62306 + atomic64_unchecked_t child_count;
62307
62308 /*
62309 * These are the total time in nanoseconds that the event
62310 @@ -931,8 +931,8 @@ struct perf_event {
62311 * These accumulate total time (in nanoseconds) that children
62312 * events have been enabled and running, respectively.
62313 */
62314 - atomic64_t child_total_time_enabled;
62315 - atomic64_t child_total_time_running;
62316 + atomic64_unchecked_t child_total_time_enabled;
62317 + atomic64_unchecked_t child_total_time_running;
62318
62319 /*
62320 * Protect attach/detach and child_list:
62321 diff --git a/include/linux/personality.h b/include/linux/personality.h
62322 index 8fc7dd1a..c19d89e 100644
62323 --- a/include/linux/personality.h
62324 +++ b/include/linux/personality.h
62325 @@ -44,6 +44,7 @@ enum {
62326 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
62327 ADDR_NO_RANDOMIZE | \
62328 ADDR_COMPAT_LAYOUT | \
62329 + ADDR_LIMIT_3GB | \
62330 MMAP_PAGE_ZERO)
62331
62332 /*
62333 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
62334 index e1ac1ce..0675fed 100644
62335 --- a/include/linux/pipe_fs_i.h
62336 +++ b/include/linux/pipe_fs_i.h
62337 @@ -45,9 +45,9 @@ struct pipe_buffer {
62338 struct pipe_inode_info {
62339 wait_queue_head_t wait;
62340 unsigned int nrbufs, curbuf, buffers;
62341 - unsigned int readers;
62342 - unsigned int writers;
62343 - unsigned int waiting_writers;
62344 + atomic_t readers;
62345 + atomic_t writers;
62346 + atomic_t waiting_writers;
62347 unsigned int r_counter;
62348 unsigned int w_counter;
62349 struct page *tmp_page;
62350 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
62351 index 609daae..5392427 100644
62352 --- a/include/linux/pm_runtime.h
62353 +++ b/include/linux/pm_runtime.h
62354 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
62355
62356 static inline void pm_runtime_mark_last_busy(struct device *dev)
62357 {
62358 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
62359 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
62360 }
62361
62362 #else /* !CONFIG_PM_RUNTIME */
62363 diff --git a/include/linux/poison.h b/include/linux/poison.h
62364 index 2110a81..13a11bb 100644
62365 --- a/include/linux/poison.h
62366 +++ b/include/linux/poison.h
62367 @@ -19,8 +19,8 @@
62368 * under normal circumstances, used to verify that nobody uses
62369 * non-initialized list entries.
62370 */
62371 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
62372 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
62373 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
62374 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
62375
62376 /********** include/linux/timer.h **********/
62377 /*
62378 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
62379 index 5a710b9..0b0dab9 100644
62380 --- a/include/linux/preempt.h
62381 +++ b/include/linux/preempt.h
62382 @@ -126,7 +126,7 @@ struct preempt_ops {
62383 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
62384 void (*sched_out)(struct preempt_notifier *notifier,
62385 struct task_struct *next);
62386 -};
62387 +} __no_const;
62388
62389 /**
62390 * preempt_notifier - key for installing preemption notifiers
62391 diff --git a/include/linux/printk.h b/include/linux/printk.h
62392 index 0525927..a5388b6 100644
62393 --- a/include/linux/printk.h
62394 +++ b/include/linux/printk.h
62395 @@ -94,6 +94,8 @@ void early_printk(const char *fmt, ...);
62396 extern int printk_needs_cpu(int cpu);
62397 extern void printk_tick(void);
62398
62399 +extern int kptr_restrict;
62400 +
62401 #ifdef CONFIG_PRINTK
62402 asmlinkage __printf(1, 0)
62403 int vprintk(const char *fmt, va_list args);
62404 @@ -117,7 +119,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
62405
62406 extern int printk_delay_msec;
62407 extern int dmesg_restrict;
62408 -extern int kptr_restrict;
62409
62410 void log_buf_kexec_setup(void);
62411 void __init setup_log_buf(int early);
62412 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
62413 index 85c5073..51fac8b 100644
62414 --- a/include/linux/proc_fs.h
62415 +++ b/include/linux/proc_fs.h
62416 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
62417 return proc_create_data(name, mode, parent, proc_fops, NULL);
62418 }
62419
62420 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
62421 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
62422 +{
62423 +#ifdef CONFIG_GRKERNSEC_PROC_USER
62424 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
62425 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62426 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
62427 +#else
62428 + return proc_create_data(name, mode, parent, proc_fops, NULL);
62429 +#endif
62430 +}
62431 +
62432 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
62433 umode_t mode, struct proc_dir_entry *base,
62434 read_proc_t *read_proc, void * data)
62435 @@ -258,7 +270,7 @@ union proc_op {
62436 int (*proc_show)(struct seq_file *m,
62437 struct pid_namespace *ns, struct pid *pid,
62438 struct task_struct *task);
62439 -};
62440 +} __no_const;
62441
62442 struct ctl_table_header;
62443 struct ctl_table;
62444 diff --git a/include/linux/random.h b/include/linux/random.h
62445 index 8f74538..02a1012 100644
62446 --- a/include/linux/random.h
62447 +++ b/include/linux/random.h
62448 @@ -69,12 +69,17 @@ void srandom32(u32 seed);
62449
62450 u32 prandom32(struct rnd_state *);
62451
62452 +static inline unsigned long pax_get_random_long(void)
62453 +{
62454 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
62455 +}
62456 +
62457 /*
62458 * Handle minimum values for seeds
62459 */
62460 static inline u32 __seed(u32 x, u32 m)
62461 {
62462 - return (x < m) ? x + m : x;
62463 + return (x <= m) ? x + m + 1 : x;
62464 }
62465
62466 /**
62467 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
62468 index e0879a7..a12f962 100644
62469 --- a/include/linux/reboot.h
62470 +++ b/include/linux/reboot.h
62471 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
62472 * Architecture-specific implementations of sys_reboot commands.
62473 */
62474
62475 -extern void machine_restart(char *cmd);
62476 -extern void machine_halt(void);
62477 -extern void machine_power_off(void);
62478 +extern void machine_restart(char *cmd) __noreturn;
62479 +extern void machine_halt(void) __noreturn;
62480 +extern void machine_power_off(void) __noreturn;
62481
62482 extern void machine_shutdown(void);
62483 struct pt_regs;
62484 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
62485 */
62486
62487 extern void kernel_restart_prepare(char *cmd);
62488 -extern void kernel_restart(char *cmd);
62489 -extern void kernel_halt(void);
62490 -extern void kernel_power_off(void);
62491 +extern void kernel_restart(char *cmd) __noreturn;
62492 +extern void kernel_halt(void) __noreturn;
62493 +extern void kernel_power_off(void) __noreturn;
62494
62495 extern int C_A_D; /* for sysctl */
62496 void ctrl_alt_del(void);
62497 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
62498 * Emergency restart, callable from an interrupt handler.
62499 */
62500
62501 -extern void emergency_restart(void);
62502 +extern void emergency_restart(void) __noreturn;
62503 #include <asm/emergency-restart.h>
62504
62505 #endif
62506 diff --git a/include/linux/relay.h b/include/linux/relay.h
62507 index 91cacc3..b55ff74 100644
62508 --- a/include/linux/relay.h
62509 +++ b/include/linux/relay.h
62510 @@ -160,7 +160,7 @@ struct rchan_callbacks
62511 * The callback should return 0 if successful, negative if not.
62512 */
62513 int (*remove_buf_file)(struct dentry *dentry);
62514 -};
62515 +} __no_const;
62516
62517 /*
62518 * CONFIG_RELAY kernel API, kernel/relay.c
62519 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
62520 index 6fdf027..ff72610 100644
62521 --- a/include/linux/rfkill.h
62522 +++ b/include/linux/rfkill.h
62523 @@ -147,6 +147,7 @@ struct rfkill_ops {
62524 void (*query)(struct rfkill *rfkill, void *data);
62525 int (*set_block)(void *data, bool blocked);
62526 };
62527 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
62528
62529 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
62530 /**
62531 diff --git a/include/linux/rio.h b/include/linux/rio.h
62532 index 4d50611..c6858a2 100644
62533 --- a/include/linux/rio.h
62534 +++ b/include/linux/rio.h
62535 @@ -315,7 +315,7 @@ struct rio_ops {
62536 int mbox, void *buffer, size_t len);
62537 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
62538 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
62539 -};
62540 +} __no_const;
62541
62542 #define RIO_RESOURCE_MEM 0x00000100
62543 #define RIO_RESOURCE_DOORBELL 0x00000200
62544 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
62545 index fd07c45..4676b8e 100644
62546 --- a/include/linux/rmap.h
62547 +++ b/include/linux/rmap.h
62548 @@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
62549 void anon_vma_init(void); /* create anon_vma_cachep */
62550 int anon_vma_prepare(struct vm_area_struct *);
62551 void unlink_anon_vmas(struct vm_area_struct *);
62552 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
62553 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
62554 void anon_vma_moveto_tail(struct vm_area_struct *);
62555 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
62556 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
62557
62558 static inline void anon_vma_merge(struct vm_area_struct *vma,
62559 struct vm_area_struct *next)
62560 diff --git a/include/linux/sched.h b/include/linux/sched.h
62561 index 7b06169..da44f01 100644
62562 --- a/include/linux/sched.h
62563 +++ b/include/linux/sched.h
62564 @@ -100,6 +100,7 @@ struct bio_list;
62565 struct fs_struct;
62566 struct perf_event_context;
62567 struct blk_plug;
62568 +struct linux_binprm;
62569
62570 /*
62571 * List of flags we want to share for kernel threads,
62572 @@ -382,10 +383,13 @@ struct user_namespace;
62573 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
62574
62575 extern int sysctl_max_map_count;
62576 +extern unsigned long sysctl_heap_stack_gap;
62577
62578 #include <linux/aio.h>
62579
62580 #ifdef CONFIG_MMU
62581 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
62582 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
62583 extern void arch_pick_mmap_layout(struct mm_struct *mm);
62584 extern unsigned long
62585 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
62586 @@ -643,6 +647,17 @@ struct signal_struct {
62587 #ifdef CONFIG_TASKSTATS
62588 struct taskstats *stats;
62589 #endif
62590 +
62591 +#ifdef CONFIG_GRKERNSEC
62592 + u32 curr_ip;
62593 + u32 saved_ip;
62594 + u32 gr_saddr;
62595 + u32 gr_daddr;
62596 + u16 gr_sport;
62597 + u16 gr_dport;
62598 + u8 used_accept:1;
62599 +#endif
62600 +
62601 #ifdef CONFIG_AUDIT
62602 unsigned audit_tty;
62603 struct tty_audit_buf *tty_audit_buf;
62604 @@ -726,6 +741,11 @@ struct user_struct {
62605 struct key *session_keyring; /* UID's default session keyring */
62606 #endif
62607
62608 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
62609 + unsigned int banned;
62610 + unsigned long ban_expires;
62611 +#endif
62612 +
62613 /* Hash table maintenance information */
62614 struct hlist_node uidhash_node;
62615 uid_t uid;
62616 @@ -1386,8 +1406,8 @@ struct task_struct {
62617 struct list_head thread_group;
62618
62619 struct completion *vfork_done; /* for vfork() */
62620 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
62621 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
62622 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
62623 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
62624
62625 cputime_t utime, stime, utimescaled, stimescaled;
62626 cputime_t gtime;
62627 @@ -1403,13 +1423,6 @@ struct task_struct {
62628 struct task_cputime cputime_expires;
62629 struct list_head cpu_timers[3];
62630
62631 -/* process credentials */
62632 - const struct cred __rcu *real_cred; /* objective and real subjective task
62633 - * credentials (COW) */
62634 - const struct cred __rcu *cred; /* effective (overridable) subjective task
62635 - * credentials (COW) */
62636 - struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
62637 -
62638 char comm[TASK_COMM_LEN]; /* executable name excluding path
62639 - access with [gs]et_task_comm (which lock
62640 it with task_lock())
62641 @@ -1426,8 +1439,16 @@ struct task_struct {
62642 #endif
62643 /* CPU-specific state of this task */
62644 struct thread_struct thread;
62645 +/* thread_info moved to task_struct */
62646 +#ifdef CONFIG_X86
62647 + struct thread_info tinfo;
62648 +#endif
62649 /* filesystem information */
62650 struct fs_struct *fs;
62651 +
62652 + const struct cred __rcu *cred; /* effective (overridable) subjective task
62653 + * credentials (COW) */
62654 +
62655 /* open file information */
62656 struct files_struct *files;
62657 /* namespaces */
62658 @@ -1469,6 +1490,11 @@ struct task_struct {
62659 struct rt_mutex_waiter *pi_blocked_on;
62660 #endif
62661
62662 +/* process credentials */
62663 + const struct cred __rcu *real_cred; /* objective and real subjective task
62664 + * credentials (COW) */
62665 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
62666 +
62667 #ifdef CONFIG_DEBUG_MUTEXES
62668 /* mutex deadlock detection */
62669 struct mutex_waiter *blocked_on;
62670 @@ -1585,6 +1611,27 @@ struct task_struct {
62671 unsigned long default_timer_slack_ns;
62672
62673 struct list_head *scm_work_list;
62674 +
62675 +#ifdef CONFIG_GRKERNSEC
62676 + /* grsecurity */
62677 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62678 + u64 exec_id;
62679 +#endif
62680 +#ifdef CONFIG_GRKERNSEC_SETXID
62681 + const struct cred *delayed_cred;
62682 +#endif
62683 + struct dentry *gr_chroot_dentry;
62684 + struct acl_subject_label *acl;
62685 + struct acl_role_label *role;
62686 + struct file *exec_file;
62687 + u16 acl_role_id;
62688 + /* is this the task that authenticated to the special role */
62689 + u8 acl_sp_role;
62690 + u8 is_writable;
62691 + u8 brute;
62692 + u8 gr_is_chrooted;
62693 +#endif
62694 +
62695 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
62696 /* Index of current stored address in ret_stack */
62697 int curr_ret_stack;
62698 @@ -1619,6 +1666,51 @@ struct task_struct {
62699 #endif
62700 };
62701
62702 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
62703 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
62704 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
62705 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
62706 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
62707 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
62708 +
62709 +#ifdef CONFIG_PAX_SOFTMODE
62710 +extern int pax_softmode;
62711 +#endif
62712 +
62713 +extern int pax_check_flags(unsigned long *);
62714 +
62715 +/* if tsk != current then task_lock must be held on it */
62716 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62717 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
62718 +{
62719 + if (likely(tsk->mm))
62720 + return tsk->mm->pax_flags;
62721 + else
62722 + return 0UL;
62723 +}
62724 +
62725 +/* if tsk != current then task_lock must be held on it */
62726 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
62727 +{
62728 + if (likely(tsk->mm)) {
62729 + tsk->mm->pax_flags = flags;
62730 + return 0;
62731 + }
62732 + return -EINVAL;
62733 +}
62734 +#endif
62735 +
62736 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
62737 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
62738 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
62739 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
62740 +#endif
62741 +
62742 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
62743 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
62744 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
62745 +extern __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type);
62746 +
62747 /* Future-safe accessor for struct task_struct's cpus_allowed. */
62748 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
62749
62750 @@ -2146,7 +2238,9 @@ void yield(void);
62751 extern struct exec_domain default_exec_domain;
62752
62753 union thread_union {
62754 +#ifndef CONFIG_X86
62755 struct thread_info thread_info;
62756 +#endif
62757 unsigned long stack[THREAD_SIZE/sizeof(long)];
62758 };
62759
62760 @@ -2179,6 +2273,7 @@ extern struct pid_namespace init_pid_ns;
62761 */
62762
62763 extern struct task_struct *find_task_by_vpid(pid_t nr);
62764 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
62765 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
62766 struct pid_namespace *ns);
62767
62768 @@ -2322,7 +2417,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
62769 extern void exit_itimers(struct signal_struct *);
62770 extern void flush_itimer_signals(void);
62771
62772 -extern void do_group_exit(int);
62773 +extern __noreturn void do_group_exit(int);
62774
62775 extern void daemonize(const char *, ...);
62776 extern int allow_signal(int);
62777 @@ -2523,13 +2618,17 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
62778
62779 #endif
62780
62781 -static inline int object_is_on_stack(void *obj)
62782 +static inline int object_starts_on_stack(void *obj)
62783 {
62784 - void *stack = task_stack_page(current);
62785 + const void *stack = task_stack_page(current);
62786
62787 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
62788 }
62789
62790 +#ifdef CONFIG_PAX_USERCOPY
62791 +extern int object_is_on_stack(const void *obj, unsigned long len);
62792 +#endif
62793 +
62794 extern void thread_info_cache_init(void);
62795
62796 #ifdef CONFIG_DEBUG_STACK_USAGE
62797 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
62798 index 899fbb4..1cb4138 100644
62799 --- a/include/linux/screen_info.h
62800 +++ b/include/linux/screen_info.h
62801 @@ -43,7 +43,8 @@ struct screen_info {
62802 __u16 pages; /* 0x32 */
62803 __u16 vesa_attributes; /* 0x34 */
62804 __u32 capabilities; /* 0x36 */
62805 - __u8 _reserved[6]; /* 0x3a */
62806 + __u16 vesapm_size; /* 0x3a */
62807 + __u8 _reserved[4]; /* 0x3c */
62808 } __attribute__((packed));
62809
62810 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
62811 diff --git a/include/linux/security.h b/include/linux/security.h
62812 index 673afbb..2b7454b 100644
62813 --- a/include/linux/security.h
62814 +++ b/include/linux/security.h
62815 @@ -26,6 +26,7 @@
62816 #include <linux/capability.h>
62817 #include <linux/slab.h>
62818 #include <linux/err.h>
62819 +#include <linux/grsecurity.h>
62820
62821 struct linux_binprm;
62822 struct cred;
62823 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
62824 index fc61854..d7c490b 100644
62825 --- a/include/linux/seq_file.h
62826 +++ b/include/linux/seq_file.h
62827 @@ -25,6 +25,9 @@ struct seq_file {
62828 struct mutex lock;
62829 const struct seq_operations *op;
62830 int poll_event;
62831 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62832 + u64 exec_id;
62833 +#endif
62834 void *private;
62835 };
62836
62837 @@ -34,6 +37,7 @@ struct seq_operations {
62838 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
62839 int (*show) (struct seq_file *m, void *v);
62840 };
62841 +typedef struct seq_operations __no_const seq_operations_no_const;
62842
62843 #define SEQ_SKIP 1
62844
62845 diff --git a/include/linux/shm.h b/include/linux/shm.h
62846 index 92808b8..c28cac4 100644
62847 --- a/include/linux/shm.h
62848 +++ b/include/linux/shm.h
62849 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
62850
62851 /* The task created the shm object. NULL if the task is dead. */
62852 struct task_struct *shm_creator;
62853 +#ifdef CONFIG_GRKERNSEC
62854 + time_t shm_createtime;
62855 + pid_t shm_lapid;
62856 +#endif
62857 };
62858
62859 /* shm_mode upper byte flags */
62860 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
62861 index c1bae8d..2dbcd31 100644
62862 --- a/include/linux/skbuff.h
62863 +++ b/include/linux/skbuff.h
62864 @@ -663,7 +663,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
62865 */
62866 static inline int skb_queue_empty(const struct sk_buff_head *list)
62867 {
62868 - return list->next == (struct sk_buff *)list;
62869 + return list->next == (const struct sk_buff *)list;
62870 }
62871
62872 /**
62873 @@ -676,7 +676,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
62874 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
62875 const struct sk_buff *skb)
62876 {
62877 - return skb->next == (struct sk_buff *)list;
62878 + return skb->next == (const struct sk_buff *)list;
62879 }
62880
62881 /**
62882 @@ -689,7 +689,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
62883 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
62884 const struct sk_buff *skb)
62885 {
62886 - return skb->prev == (struct sk_buff *)list;
62887 + return skb->prev == (const struct sk_buff *)list;
62888 }
62889
62890 /**
62891 @@ -1584,7 +1584,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
62892 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
62893 */
62894 #ifndef NET_SKB_PAD
62895 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
62896 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
62897 #endif
62898
62899 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
62900 diff --git a/include/linux/slab.h b/include/linux/slab.h
62901 index a595dce..c403597 100644
62902 --- a/include/linux/slab.h
62903 +++ b/include/linux/slab.h
62904 @@ -11,12 +11,20 @@
62905
62906 #include <linux/gfp.h>
62907 #include <linux/types.h>
62908 +#include <linux/err.h>
62909
62910 /*
62911 * Flags to pass to kmem_cache_create().
62912 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
62913 */
62914 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
62915 +
62916 +#ifdef CONFIG_PAX_USERCOPY
62917 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
62918 +#else
62919 +#define SLAB_USERCOPY 0x00000000UL
62920 +#endif
62921 +
62922 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
62923 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
62924 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
62925 @@ -87,10 +95,13 @@
62926 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
62927 * Both make kfree a no-op.
62928 */
62929 -#define ZERO_SIZE_PTR ((void *)16)
62930 +#define ZERO_SIZE_PTR \
62931 +({ \
62932 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
62933 + (void *)(-MAX_ERRNO-1L); \
62934 +})
62935
62936 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
62937 - (unsigned long)ZERO_SIZE_PTR)
62938 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
62939
62940 /*
62941 * struct kmem_cache related prototypes
62942 @@ -161,6 +172,7 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
62943 void kfree(const void *);
62944 void kzfree(const void *);
62945 size_t ksize(const void *);
62946 +void check_object_size(const void *ptr, unsigned long n, bool to);
62947
62948 /*
62949 * Allocator specific definitions. These are mainly used to establish optimized
62950 @@ -240,6 +252,7 @@ size_t ksize(const void *);
62951 * for general use, and so are not documented here. For a full list of
62952 * potential flags, always refer to linux/gfp.h.
62953 */
62954 +static void *kmalloc_array(size_t n, size_t size, gfp_t flags) __size_overflow(1, 2);
62955 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
62956 {
62957 if (size != 0 && n > ULONG_MAX / size)
62958 @@ -298,7 +311,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
62959 */
62960 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
62961 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
62962 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
62963 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
62964 #define kmalloc_track_caller(size, flags) \
62965 __kmalloc_track_caller(size, flags, _RET_IP_)
62966 #else
62967 @@ -317,7 +330,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
62968 */
62969 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
62970 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
62971 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
62972 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
62973 #define kmalloc_node_track_caller(size, flags, node) \
62974 __kmalloc_node_track_caller(size, flags, node, \
62975 _RET_IP_)
62976 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
62977 index fbd1117..d4d8ef8 100644
62978 --- a/include/linux/slab_def.h
62979 +++ b/include/linux/slab_def.h
62980 @@ -66,10 +66,10 @@ struct kmem_cache {
62981 unsigned long node_allocs;
62982 unsigned long node_frees;
62983 unsigned long node_overflow;
62984 - atomic_t allochit;
62985 - atomic_t allocmiss;
62986 - atomic_t freehit;
62987 - atomic_t freemiss;
62988 + atomic_unchecked_t allochit;
62989 + atomic_unchecked_t allocmiss;
62990 + atomic_unchecked_t freehit;
62991 + atomic_unchecked_t freemiss;
62992
62993 /*
62994 * If debugging is enabled, then the allocator can add additional
62995 @@ -107,7 +107,7 @@ struct cache_sizes {
62996 extern struct cache_sizes malloc_sizes[];
62997
62998 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
62999 -void *__kmalloc(size_t size, gfp_t flags);
63000 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63001
63002 #ifdef CONFIG_TRACING
63003 extern void *kmem_cache_alloc_trace(size_t size,
63004 @@ -160,7 +160,7 @@ found:
63005 }
63006
63007 #ifdef CONFIG_NUMA
63008 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
63009 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63010 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63011
63012 #ifdef CONFIG_TRACING
63013 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
63014 index 0ec00b3..39cb7fc 100644
63015 --- a/include/linux/slob_def.h
63016 +++ b/include/linux/slob_def.h
63017 @@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
63018 return kmem_cache_alloc_node(cachep, flags, -1);
63019 }
63020
63021 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
63022 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63023
63024 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63025 {
63026 @@ -29,6 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
63027 return __kmalloc_node(size, flags, -1);
63028 }
63029
63030 +static __always_inline void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63031 static __always_inline void *__kmalloc(size_t size, gfp_t flags)
63032 {
63033 return kmalloc(size, flags);
63034 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
63035 index c2f8c8b..be9e036 100644
63036 --- a/include/linux/slub_def.h
63037 +++ b/include/linux/slub_def.h
63038 @@ -92,7 +92,7 @@ struct kmem_cache {
63039 struct kmem_cache_order_objects max;
63040 struct kmem_cache_order_objects min;
63041 gfp_t allocflags; /* gfp flags to use on each alloc */
63042 - int refcount; /* Refcount for slab cache destroy */
63043 + atomic_t refcount; /* Refcount for slab cache destroy */
63044 void (*ctor)(void *);
63045 int inuse; /* Offset to metadata */
63046 int align; /* Alignment */
63047 @@ -153,6 +153,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
63048 * Sorry that the following has to be that ugly but some versions of GCC
63049 * have trouble with constant propagation and loops.
63050 */
63051 +static __always_inline int kmalloc_index(size_t size) __size_overflow(1);
63052 static __always_inline int kmalloc_index(size_t size)
63053 {
63054 if (!size)
63055 @@ -218,7 +219,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
63056 }
63057
63058 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63059 -void *__kmalloc(size_t size, gfp_t flags);
63060 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
63061
63062 static __always_inline void *
63063 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
63064 @@ -259,6 +260,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
63065 }
63066 #endif
63067
63068 +static __always_inline void *kmalloc_large(size_t size, gfp_t flags) __size_overflow(1);
63069 static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
63070 {
63071 unsigned int order = get_order(size);
63072 @@ -284,7 +286,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
63073 }
63074
63075 #ifdef CONFIG_NUMA
63076 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
63077 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63078 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63079
63080 #ifdef CONFIG_TRACING
63081 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
63082 index de8832d..0147b46 100644
63083 --- a/include/linux/sonet.h
63084 +++ b/include/linux/sonet.h
63085 @@ -61,7 +61,7 @@ struct sonet_stats {
63086 #include <linux/atomic.h>
63087
63088 struct k_sonet_stats {
63089 -#define __HANDLE_ITEM(i) atomic_t i
63090 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
63091 __SONET_ITEMS
63092 #undef __HANDLE_ITEM
63093 };
63094 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
63095 index 523547e..2cb7140 100644
63096 --- a/include/linux/sunrpc/clnt.h
63097 +++ b/include/linux/sunrpc/clnt.h
63098 @@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
63099 {
63100 switch (sap->sa_family) {
63101 case AF_INET:
63102 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
63103 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
63104 case AF_INET6:
63105 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
63106 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
63107 }
63108 return 0;
63109 }
63110 @@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
63111 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
63112 const struct sockaddr *src)
63113 {
63114 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
63115 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
63116 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
63117
63118 dsin->sin_family = ssin->sin_family;
63119 @@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
63120 if (sa->sa_family != AF_INET6)
63121 return 0;
63122
63123 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
63124 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
63125 }
63126
63127 #endif /* __KERNEL__ */
63128 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
63129 index dc0c3cc..8503fb6 100644
63130 --- a/include/linux/sunrpc/sched.h
63131 +++ b/include/linux/sunrpc/sched.h
63132 @@ -106,6 +106,7 @@ struct rpc_call_ops {
63133 void (*rpc_count_stats)(struct rpc_task *, void *);
63134 void (*rpc_release)(void *);
63135 };
63136 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
63137
63138 struct rpc_task_setup {
63139 struct rpc_task *task;
63140 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
63141 index 0b8e3e6..33e0a01 100644
63142 --- a/include/linux/sunrpc/svc_rdma.h
63143 +++ b/include/linux/sunrpc/svc_rdma.h
63144 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
63145 extern unsigned int svcrdma_max_requests;
63146 extern unsigned int svcrdma_max_req_size;
63147
63148 -extern atomic_t rdma_stat_recv;
63149 -extern atomic_t rdma_stat_read;
63150 -extern atomic_t rdma_stat_write;
63151 -extern atomic_t rdma_stat_sq_starve;
63152 -extern atomic_t rdma_stat_rq_starve;
63153 -extern atomic_t rdma_stat_rq_poll;
63154 -extern atomic_t rdma_stat_rq_prod;
63155 -extern atomic_t rdma_stat_sq_poll;
63156 -extern atomic_t rdma_stat_sq_prod;
63157 +extern atomic_unchecked_t rdma_stat_recv;
63158 +extern atomic_unchecked_t rdma_stat_read;
63159 +extern atomic_unchecked_t rdma_stat_write;
63160 +extern atomic_unchecked_t rdma_stat_sq_starve;
63161 +extern atomic_unchecked_t rdma_stat_rq_starve;
63162 +extern atomic_unchecked_t rdma_stat_rq_poll;
63163 +extern atomic_unchecked_t rdma_stat_rq_prod;
63164 +extern atomic_unchecked_t rdma_stat_sq_poll;
63165 +extern atomic_unchecked_t rdma_stat_sq_prod;
63166
63167 #define RPCRDMA_VERSION 1
63168
63169 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
63170 index c34b4c8..a65b67d 100644
63171 --- a/include/linux/sysctl.h
63172 +++ b/include/linux/sysctl.h
63173 @@ -155,7 +155,11 @@ enum
63174 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
63175 };
63176
63177 -
63178 +#ifdef CONFIG_PAX_SOFTMODE
63179 +enum {
63180 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
63181 +};
63182 +#endif
63183
63184 /* CTL_VM names: */
63185 enum
63186 @@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
63187
63188 extern int proc_dostring(struct ctl_table *, int,
63189 void __user *, size_t *, loff_t *);
63190 +extern int proc_dostring_modpriv(struct ctl_table *, int,
63191 + void __user *, size_t *, loff_t *);
63192 extern int proc_dointvec(struct ctl_table *, int,
63193 void __user *, size_t *, loff_t *);
63194 extern int proc_dointvec_minmax(struct ctl_table *, int,
63195 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
63196 index ff7dc08..893e1bd 100644
63197 --- a/include/linux/tty_ldisc.h
63198 +++ b/include/linux/tty_ldisc.h
63199 @@ -148,7 +148,7 @@ struct tty_ldisc_ops {
63200
63201 struct module *owner;
63202
63203 - int refcount;
63204 + atomic_t refcount;
63205 };
63206
63207 struct tty_ldisc {
63208 diff --git a/include/linux/types.h b/include/linux/types.h
63209 index 7f480db..175c256 100644
63210 --- a/include/linux/types.h
63211 +++ b/include/linux/types.h
63212 @@ -220,10 +220,26 @@ typedef struct {
63213 int counter;
63214 } atomic_t;
63215
63216 +#ifdef CONFIG_PAX_REFCOUNT
63217 +typedef struct {
63218 + int counter;
63219 +} atomic_unchecked_t;
63220 +#else
63221 +typedef atomic_t atomic_unchecked_t;
63222 +#endif
63223 +
63224 #ifdef CONFIG_64BIT
63225 typedef struct {
63226 long counter;
63227 } atomic64_t;
63228 +
63229 +#ifdef CONFIG_PAX_REFCOUNT
63230 +typedef struct {
63231 + long counter;
63232 +} atomic64_unchecked_t;
63233 +#else
63234 +typedef atomic64_t atomic64_unchecked_t;
63235 +#endif
63236 #endif
63237
63238 struct list_head {
63239 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
63240 index 5ca0951..ab496a5 100644
63241 --- a/include/linux/uaccess.h
63242 +++ b/include/linux/uaccess.h
63243 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
63244 long ret; \
63245 mm_segment_t old_fs = get_fs(); \
63246 \
63247 - set_fs(KERNEL_DS); \
63248 pagefault_disable(); \
63249 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
63250 - pagefault_enable(); \
63251 + set_fs(KERNEL_DS); \
63252 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
63253 set_fs(old_fs); \
63254 + pagefault_enable(); \
63255 ret; \
63256 })
63257
63258 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
63259 index 99c1b4d..bb94261 100644
63260 --- a/include/linux/unaligned/access_ok.h
63261 +++ b/include/linux/unaligned/access_ok.h
63262 @@ -6,32 +6,32 @@
63263
63264 static inline u16 get_unaligned_le16(const void *p)
63265 {
63266 - return le16_to_cpup((__le16 *)p);
63267 + return le16_to_cpup((const __le16 *)p);
63268 }
63269
63270 static inline u32 get_unaligned_le32(const void *p)
63271 {
63272 - return le32_to_cpup((__le32 *)p);
63273 + return le32_to_cpup((const __le32 *)p);
63274 }
63275
63276 static inline u64 get_unaligned_le64(const void *p)
63277 {
63278 - return le64_to_cpup((__le64 *)p);
63279 + return le64_to_cpup((const __le64 *)p);
63280 }
63281
63282 static inline u16 get_unaligned_be16(const void *p)
63283 {
63284 - return be16_to_cpup((__be16 *)p);
63285 + return be16_to_cpup((const __be16 *)p);
63286 }
63287
63288 static inline u32 get_unaligned_be32(const void *p)
63289 {
63290 - return be32_to_cpup((__be32 *)p);
63291 + return be32_to_cpup((const __be32 *)p);
63292 }
63293
63294 static inline u64 get_unaligned_be64(const void *p)
63295 {
63296 - return be64_to_cpup((__be64 *)p);
63297 + return be64_to_cpup((const __be64 *)p);
63298 }
63299
63300 static inline void put_unaligned_le16(u16 val, void *p)
63301 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
63302 index 547e59c..db6ad19 100644
63303 --- a/include/linux/usb/renesas_usbhs.h
63304 +++ b/include/linux/usb/renesas_usbhs.h
63305 @@ -39,7 +39,7 @@ enum {
63306 */
63307 struct renesas_usbhs_driver_callback {
63308 int (*notify_hotplug)(struct platform_device *pdev);
63309 -};
63310 +} __no_const;
63311
63312 /*
63313 * callback functions for platform
63314 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
63315 * VBUS control is needed for Host
63316 */
63317 int (*set_vbus)(struct platform_device *pdev, int enable);
63318 -};
63319 +} __no_const;
63320
63321 /*
63322 * parameters for renesas usbhs
63323 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
63324 index 6f8fbcf..8259001 100644
63325 --- a/include/linux/vermagic.h
63326 +++ b/include/linux/vermagic.h
63327 @@ -25,9 +25,35 @@
63328 #define MODULE_ARCH_VERMAGIC ""
63329 #endif
63330
63331 +#ifdef CONFIG_PAX_REFCOUNT
63332 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
63333 +#else
63334 +#define MODULE_PAX_REFCOUNT ""
63335 +#endif
63336 +
63337 +#ifdef CONSTIFY_PLUGIN
63338 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
63339 +#else
63340 +#define MODULE_CONSTIFY_PLUGIN ""
63341 +#endif
63342 +
63343 +#ifdef STACKLEAK_PLUGIN
63344 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
63345 +#else
63346 +#define MODULE_STACKLEAK_PLUGIN ""
63347 +#endif
63348 +
63349 +#ifdef CONFIG_GRKERNSEC
63350 +#define MODULE_GRSEC "GRSEC "
63351 +#else
63352 +#define MODULE_GRSEC ""
63353 +#endif
63354 +
63355 #define VERMAGIC_STRING \
63356 UTS_RELEASE " " \
63357 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
63358 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
63359 - MODULE_ARCH_VERMAGIC
63360 + MODULE_ARCH_VERMAGIC \
63361 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
63362 + MODULE_GRSEC
63363
63364 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
63365 index dcdfc2b..ec79ab5 100644
63366 --- a/include/linux/vmalloc.h
63367 +++ b/include/linux/vmalloc.h
63368 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
63369 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
63370 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
63371 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
63372 +
63373 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
63374 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
63375 +#endif
63376 +
63377 /* bits [20..32] reserved for arch specific ioremap internals */
63378
63379 /*
63380 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
63381 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
63382 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
63383 unsigned long start, unsigned long end, gfp_t gfp_mask,
63384 - pgprot_t prot, int node, void *caller);
63385 + pgprot_t prot, int node, void *caller) __size_overflow(1);
63386 extern void vfree(const void *addr);
63387
63388 extern void *vmap(struct page **pages, unsigned int count,
63389 @@ -123,8 +128,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
63390 extern void free_vm_area(struct vm_struct *area);
63391
63392 /* for /dev/kmem */
63393 -extern long vread(char *buf, char *addr, unsigned long count);
63394 -extern long vwrite(char *buf, char *addr, unsigned long count);
63395 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
63396 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
63397
63398 /*
63399 * Internals. Dont't use..
63400 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
63401 index 65efb92..137adbb 100644
63402 --- a/include/linux/vmstat.h
63403 +++ b/include/linux/vmstat.h
63404 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
63405 /*
63406 * Zone based page accounting with per cpu differentials.
63407 */
63408 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63409 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63410
63411 static inline void zone_page_state_add(long x, struct zone *zone,
63412 enum zone_stat_item item)
63413 {
63414 - atomic_long_add(x, &zone->vm_stat[item]);
63415 - atomic_long_add(x, &vm_stat[item]);
63416 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
63417 + atomic_long_add_unchecked(x, &vm_stat[item]);
63418 }
63419
63420 static inline unsigned long global_page_state(enum zone_stat_item item)
63421 {
63422 - long x = atomic_long_read(&vm_stat[item]);
63423 + long x = atomic_long_read_unchecked(&vm_stat[item]);
63424 #ifdef CONFIG_SMP
63425 if (x < 0)
63426 x = 0;
63427 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
63428 static inline unsigned long zone_page_state(struct zone *zone,
63429 enum zone_stat_item item)
63430 {
63431 - long x = atomic_long_read(&zone->vm_stat[item]);
63432 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
63433 #ifdef CONFIG_SMP
63434 if (x < 0)
63435 x = 0;
63436 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
63437 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
63438 enum zone_stat_item item)
63439 {
63440 - long x = atomic_long_read(&zone->vm_stat[item]);
63441 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
63442
63443 #ifdef CONFIG_SMP
63444 int cpu;
63445 @@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
63446
63447 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
63448 {
63449 - atomic_long_inc(&zone->vm_stat[item]);
63450 - atomic_long_inc(&vm_stat[item]);
63451 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
63452 + atomic_long_inc_unchecked(&vm_stat[item]);
63453 }
63454
63455 static inline void __inc_zone_page_state(struct page *page,
63456 @@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
63457
63458 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
63459 {
63460 - atomic_long_dec(&zone->vm_stat[item]);
63461 - atomic_long_dec(&vm_stat[item]);
63462 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
63463 + atomic_long_dec_unchecked(&vm_stat[item]);
63464 }
63465
63466 static inline void __dec_zone_page_state(struct page *page,
63467 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
63468 index e5d1220..ef6e406 100644
63469 --- a/include/linux/xattr.h
63470 +++ b/include/linux/xattr.h
63471 @@ -57,6 +57,11 @@
63472 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
63473 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
63474
63475 +/* User namespace */
63476 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
63477 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
63478 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
63479 +
63480 #ifdef __KERNEL__
63481
63482 #include <linux/types.h>
63483 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
63484 index 4aeff96..b378cdc 100644
63485 --- a/include/media/saa7146_vv.h
63486 +++ b/include/media/saa7146_vv.h
63487 @@ -163,7 +163,7 @@ struct saa7146_ext_vv
63488 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
63489
63490 /* the extension can override this */
63491 - struct v4l2_ioctl_ops ops;
63492 + v4l2_ioctl_ops_no_const ops;
63493 /* pointer to the saa7146 core ops */
63494 const struct v4l2_ioctl_ops *core_ops;
63495
63496 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
63497 index 96d2221..2292f89 100644
63498 --- a/include/media/v4l2-dev.h
63499 +++ b/include/media/v4l2-dev.h
63500 @@ -56,7 +56,7 @@ int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);
63501
63502
63503 struct v4l2_file_operations {
63504 - struct module *owner;
63505 + struct module * const owner;
63506 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
63507 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
63508 unsigned int (*poll) (struct file *, struct poll_table_struct *);
63509 @@ -71,6 +71,7 @@ struct v4l2_file_operations {
63510 int (*open) (struct file *);
63511 int (*release) (struct file *);
63512 };
63513 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
63514
63515 /*
63516 * Newer version of video_device, handled by videodev2.c
63517 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
63518 index 3cb939c..f23c6bb 100644
63519 --- a/include/media/v4l2-ioctl.h
63520 +++ b/include/media/v4l2-ioctl.h
63521 @@ -281,7 +281,7 @@ struct v4l2_ioctl_ops {
63522 long (*vidioc_default) (struct file *file, void *fh,
63523 bool valid_prio, int cmd, void *arg);
63524 };
63525 -
63526 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
63527
63528 /* v4l debugging and diagnostics */
63529
63530 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
63531 index 6db8ecf..8c23861 100644
63532 --- a/include/net/caif/caif_hsi.h
63533 +++ b/include/net/caif/caif_hsi.h
63534 @@ -98,7 +98,7 @@ struct cfhsi_drv {
63535 void (*rx_done_cb) (struct cfhsi_drv *drv);
63536 void (*wake_up_cb) (struct cfhsi_drv *drv);
63537 void (*wake_down_cb) (struct cfhsi_drv *drv);
63538 -};
63539 +} __no_const;
63540
63541 /* Structure implemented by HSI device. */
63542 struct cfhsi_dev {
63543 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
63544 index 9e5425b..8136ffc 100644
63545 --- a/include/net/caif/cfctrl.h
63546 +++ b/include/net/caif/cfctrl.h
63547 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
63548 void (*radioset_rsp)(void);
63549 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
63550 struct cflayer *client_layer);
63551 -};
63552 +} __no_const;
63553
63554 /* Link Setup Parameters for CAIF-Links. */
63555 struct cfctrl_link_param {
63556 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
63557 struct cfctrl {
63558 struct cfsrvl serv;
63559 struct cfctrl_rsp res;
63560 - atomic_t req_seq_no;
63561 - atomic_t rsp_seq_no;
63562 + atomic_unchecked_t req_seq_no;
63563 + atomic_unchecked_t rsp_seq_no;
63564 struct list_head list;
63565 /* Protects from simultaneous access to first_req list */
63566 spinlock_t info_list_lock;
63567 diff --git a/include/net/flow.h b/include/net/flow.h
63568 index 6c469db..7743b8e 100644
63569 --- a/include/net/flow.h
63570 +++ b/include/net/flow.h
63571 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
63572
63573 extern void flow_cache_flush(void);
63574 extern void flow_cache_flush_deferred(void);
63575 -extern atomic_t flow_cache_genid;
63576 +extern atomic_unchecked_t flow_cache_genid;
63577
63578 #endif
63579 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
63580 index 2040bff..f4c0733 100644
63581 --- a/include/net/inetpeer.h
63582 +++ b/include/net/inetpeer.h
63583 @@ -51,8 +51,8 @@ struct inet_peer {
63584 */
63585 union {
63586 struct {
63587 - atomic_t rid; /* Frag reception counter */
63588 - atomic_t ip_id_count; /* IP ID for the next packet */
63589 + atomic_unchecked_t rid; /* Frag reception counter */
63590 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
63591 __u32 tcp_ts;
63592 __u32 tcp_ts_stamp;
63593 };
63594 @@ -118,11 +118,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
63595 more++;
63596 inet_peer_refcheck(p);
63597 do {
63598 - old = atomic_read(&p->ip_id_count);
63599 + old = atomic_read_unchecked(&p->ip_id_count);
63600 new = old + more;
63601 if (!new)
63602 new = 1;
63603 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
63604 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
63605 return new;
63606 }
63607
63608 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
63609 index 10422ef..662570f 100644
63610 --- a/include/net/ip_fib.h
63611 +++ b/include/net/ip_fib.h
63612 @@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
63613
63614 #define FIB_RES_SADDR(net, res) \
63615 ((FIB_RES_NH(res).nh_saddr_genid == \
63616 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
63617 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
63618 FIB_RES_NH(res).nh_saddr : \
63619 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
63620 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
63621 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
63622 index 72522f0..2965e05 100644
63623 --- a/include/net/ip_vs.h
63624 +++ b/include/net/ip_vs.h
63625 @@ -510,7 +510,7 @@ struct ip_vs_conn {
63626 struct ip_vs_conn *control; /* Master control connection */
63627 atomic_t n_control; /* Number of controlled ones */
63628 struct ip_vs_dest *dest; /* real server */
63629 - atomic_t in_pkts; /* incoming packet counter */
63630 + atomic_unchecked_t in_pkts; /* incoming packet counter */
63631
63632 /* packet transmitter for different forwarding methods. If it
63633 mangles the packet, it must return NF_DROP or better NF_STOLEN,
63634 @@ -648,7 +648,7 @@ struct ip_vs_dest {
63635 __be16 port; /* port number of the server */
63636 union nf_inet_addr addr; /* IP address of the server */
63637 volatile unsigned flags; /* dest status flags */
63638 - atomic_t conn_flags; /* flags to copy to conn */
63639 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
63640 atomic_t weight; /* server weight */
63641
63642 atomic_t refcnt; /* reference counter */
63643 @@ -1356,7 +1356,7 @@ static inline void ip_vs_notrack(struct sk_buff *skb)
63644 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
63645
63646 if (!ct || !nf_ct_is_untracked(ct)) {
63647 - nf_reset(skb);
63648 + nf_conntrack_put(skb->nfct);
63649 skb->nfct = &nf_ct_untracked_get()->ct_general;
63650 skb->nfctinfo = IP_CT_NEW;
63651 nf_conntrack_get(skb->nfct);
63652 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
63653 index 69b610a..fe3962c 100644
63654 --- a/include/net/irda/ircomm_core.h
63655 +++ b/include/net/irda/ircomm_core.h
63656 @@ -51,7 +51,7 @@ typedef struct {
63657 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
63658 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
63659 struct ircomm_info *);
63660 -} call_t;
63661 +} __no_const call_t;
63662
63663 struct ircomm_cb {
63664 irda_queue_t queue;
63665 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
63666 index 59ba38bc..d515662 100644
63667 --- a/include/net/irda/ircomm_tty.h
63668 +++ b/include/net/irda/ircomm_tty.h
63669 @@ -35,6 +35,7 @@
63670 #include <linux/termios.h>
63671 #include <linux/timer.h>
63672 #include <linux/tty.h> /* struct tty_struct */
63673 +#include <asm/local.h>
63674
63675 #include <net/irda/irias_object.h>
63676 #include <net/irda/ircomm_core.h>
63677 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
63678 unsigned short close_delay;
63679 unsigned short closing_wait; /* time to wait before closing */
63680
63681 - int open_count;
63682 - int blocked_open; /* # of blocked opens */
63683 + local_t open_count;
63684 + local_t blocked_open; /* # of blocked opens */
63685
63686 /* Protect concurent access to :
63687 * o self->open_count
63688 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
63689 index cc7c197..9f2da2a 100644
63690 --- a/include/net/iucv/af_iucv.h
63691 +++ b/include/net/iucv/af_iucv.h
63692 @@ -141,7 +141,7 @@ struct iucv_sock {
63693 struct iucv_sock_list {
63694 struct hlist_head head;
63695 rwlock_t lock;
63696 - atomic_t autobind_name;
63697 + atomic_unchecked_t autobind_name;
63698 };
63699
63700 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
63701 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
63702 index 34c996f..bb3b4d4 100644
63703 --- a/include/net/neighbour.h
63704 +++ b/include/net/neighbour.h
63705 @@ -123,7 +123,7 @@ struct neigh_ops {
63706 void (*error_report)(struct neighbour *, struct sk_buff *);
63707 int (*output)(struct neighbour *, struct sk_buff *);
63708 int (*connected_output)(struct neighbour *, struct sk_buff *);
63709 -};
63710 +} __do_const;
63711
63712 struct pneigh_entry {
63713 struct pneigh_entry *next;
63714 diff --git a/include/net/netlink.h b/include/net/netlink.h
63715 index f394fe5..fd073f9 100644
63716 --- a/include/net/netlink.h
63717 +++ b/include/net/netlink.h
63718 @@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
63719 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
63720 {
63721 if (mark)
63722 - skb_trim(skb, (unsigned char *) mark - skb->data);
63723 + skb_trim(skb, (const unsigned char *) mark - skb->data);
63724 }
63725
63726 /**
63727 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
63728 index bbd023a..97c6d0d 100644
63729 --- a/include/net/netns/ipv4.h
63730 +++ b/include/net/netns/ipv4.h
63731 @@ -57,8 +57,8 @@ struct netns_ipv4 {
63732 unsigned int sysctl_ping_group_range[2];
63733 long sysctl_tcp_mem[3];
63734
63735 - atomic_t rt_genid;
63736 - atomic_t dev_addr_genid;
63737 + atomic_unchecked_t rt_genid;
63738 + atomic_unchecked_t dev_addr_genid;
63739
63740 #ifdef CONFIG_IP_MROUTE
63741 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
63742 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
63743 index a2ef814..31a8e3f 100644
63744 --- a/include/net/sctp/sctp.h
63745 +++ b/include/net/sctp/sctp.h
63746 @@ -318,9 +318,9 @@ do { \
63747
63748 #else /* SCTP_DEBUG */
63749
63750 -#define SCTP_DEBUG_PRINTK(whatever...)
63751 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
63752 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
63753 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
63754 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
63755 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
63756 #define SCTP_ENABLE_DEBUG
63757 #define SCTP_DISABLE_DEBUG
63758 #define SCTP_ASSERT(expr, str, func)
63759 diff --git a/include/net/sock.h b/include/net/sock.h
63760 index 5a0a58a..2e3d4d0 100644
63761 --- a/include/net/sock.h
63762 +++ b/include/net/sock.h
63763 @@ -302,7 +302,7 @@ struct sock {
63764 #ifdef CONFIG_RPS
63765 __u32 sk_rxhash;
63766 #endif
63767 - atomic_t sk_drops;
63768 + atomic_unchecked_t sk_drops;
63769 int sk_rcvbuf;
63770
63771 struct sk_filter __rcu *sk_filter;
63772 @@ -1691,7 +1691,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
63773 }
63774
63775 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
63776 - char __user *from, char *to,
63777 + char __user *from, unsigned char *to,
63778 int copy, int offset)
63779 {
63780 if (skb->ip_summed == CHECKSUM_NONE) {
63781 diff --git a/include/net/tcp.h b/include/net/tcp.h
63782 index f75a04d..702cf06 100644
63783 --- a/include/net/tcp.h
63784 +++ b/include/net/tcp.h
63785 @@ -1425,7 +1425,7 @@ struct tcp_seq_afinfo {
63786 char *name;
63787 sa_family_t family;
63788 const struct file_operations *seq_fops;
63789 - struct seq_operations seq_ops;
63790 + seq_operations_no_const seq_ops;
63791 };
63792
63793 struct tcp_iter_state {
63794 diff --git a/include/net/udp.h b/include/net/udp.h
63795 index 5d606d9..e879f7b 100644
63796 --- a/include/net/udp.h
63797 +++ b/include/net/udp.h
63798 @@ -244,7 +244,7 @@ struct udp_seq_afinfo {
63799 sa_family_t family;
63800 struct udp_table *udp_table;
63801 const struct file_operations *seq_fops;
63802 - struct seq_operations seq_ops;
63803 + seq_operations_no_const seq_ops;
63804 };
63805
63806 struct udp_iter_state {
63807 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
63808 index 96239e7..c85b032 100644
63809 --- a/include/net/xfrm.h
63810 +++ b/include/net/xfrm.h
63811 @@ -505,7 +505,7 @@ struct xfrm_policy {
63812 struct timer_list timer;
63813
63814 struct flow_cache_object flo;
63815 - atomic_t genid;
63816 + atomic_unchecked_t genid;
63817 u32 priority;
63818 u32 index;
63819 struct xfrm_mark mark;
63820 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
63821 index 1a046b1..ee0bef0 100644
63822 --- a/include/rdma/iw_cm.h
63823 +++ b/include/rdma/iw_cm.h
63824 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
63825 int backlog);
63826
63827 int (*destroy_listen)(struct iw_cm_id *cm_id);
63828 -};
63829 +} __no_const;
63830
63831 /**
63832 * iw_create_cm_id - Create an IW CM identifier.
63833 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
63834 index 8f9dfba..610ab6c 100644
63835 --- a/include/scsi/libfc.h
63836 +++ b/include/scsi/libfc.h
63837 @@ -756,6 +756,7 @@ struct libfc_function_template {
63838 */
63839 void (*disc_stop_final) (struct fc_lport *);
63840 };
63841 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
63842
63843 /**
63844 * struct fc_disc - Discovery context
63845 @@ -861,7 +862,7 @@ struct fc_lport {
63846 struct fc_vport *vport;
63847
63848 /* Operational Information */
63849 - struct libfc_function_template tt;
63850 + libfc_function_template_no_const tt;
63851 u8 link_up;
63852 u8 qfull;
63853 enum fc_lport_state state;
63854 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
63855 index ba96988..ecf2eb9 100644
63856 --- a/include/scsi/scsi_device.h
63857 +++ b/include/scsi/scsi_device.h
63858 @@ -163,9 +163,9 @@ struct scsi_device {
63859 unsigned int max_device_blocked; /* what device_blocked counts down from */
63860 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
63861
63862 - atomic_t iorequest_cnt;
63863 - atomic_t iodone_cnt;
63864 - atomic_t ioerr_cnt;
63865 + atomic_unchecked_t iorequest_cnt;
63866 + atomic_unchecked_t iodone_cnt;
63867 + atomic_unchecked_t ioerr_cnt;
63868
63869 struct device sdev_gendev,
63870 sdev_dev;
63871 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
63872 index 719faf1..d1154d4 100644
63873 --- a/include/scsi/scsi_transport_fc.h
63874 +++ b/include/scsi/scsi_transport_fc.h
63875 @@ -739,7 +739,7 @@ struct fc_function_template {
63876 unsigned long show_host_system_hostname:1;
63877
63878 unsigned long disable_target_scan:1;
63879 -};
63880 +} __do_const;
63881
63882
63883 /**
63884 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
63885 index 030b87c..98a6954 100644
63886 --- a/include/sound/ak4xxx-adda.h
63887 +++ b/include/sound/ak4xxx-adda.h
63888 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
63889 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
63890 unsigned char val);
63891 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
63892 -};
63893 +} __no_const;
63894
63895 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
63896
63897 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
63898 index 8c05e47..2b5df97 100644
63899 --- a/include/sound/hwdep.h
63900 +++ b/include/sound/hwdep.h
63901 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
63902 struct snd_hwdep_dsp_status *status);
63903 int (*dsp_load)(struct snd_hwdep *hw,
63904 struct snd_hwdep_dsp_image *image);
63905 -};
63906 +} __no_const;
63907
63908 struct snd_hwdep {
63909 struct snd_card *card;
63910 diff --git a/include/sound/info.h b/include/sound/info.h
63911 index 9ca1a49..aba1728 100644
63912 --- a/include/sound/info.h
63913 +++ b/include/sound/info.h
63914 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
63915 struct snd_info_buffer *buffer);
63916 void (*write)(struct snd_info_entry *entry,
63917 struct snd_info_buffer *buffer);
63918 -};
63919 +} __no_const;
63920
63921 struct snd_info_entry_ops {
63922 int (*open)(struct snd_info_entry *entry,
63923 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
63924 index 0d11128..814178e 100644
63925 --- a/include/sound/pcm.h
63926 +++ b/include/sound/pcm.h
63927 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
63928 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
63929 int (*ack)(struct snd_pcm_substream *substream);
63930 };
63931 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
63932
63933 /*
63934 *
63935 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
63936 index af1b49e..a5d55a5 100644
63937 --- a/include/sound/sb16_csp.h
63938 +++ b/include/sound/sb16_csp.h
63939 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
63940 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
63941 int (*csp_stop) (struct snd_sb_csp * p);
63942 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
63943 -};
63944 +} __no_const;
63945
63946 /*
63947 * CSP private data
63948 diff --git a/include/sound/soc.h b/include/sound/soc.h
63949 index 2ebf787..0276839 100644
63950 --- a/include/sound/soc.h
63951 +++ b/include/sound/soc.h
63952 @@ -711,7 +711,7 @@ struct snd_soc_platform_driver {
63953 /* platform IO - used for platform DAPM */
63954 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
63955 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
63956 -};
63957 +} __do_const;
63958
63959 struct snd_soc_platform {
63960 const char *name;
63961 @@ -887,7 +887,7 @@ struct snd_soc_pcm_runtime {
63962 struct snd_soc_dai_link *dai_link;
63963 struct mutex pcm_mutex;
63964 enum snd_soc_pcm_subclass pcm_subclass;
63965 - struct snd_pcm_ops ops;
63966 + snd_pcm_ops_no_const ops;
63967
63968 unsigned int complete:1;
63969 unsigned int dev_registered:1;
63970 diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
63971 index 4119966..1a4671c 100644
63972 --- a/include/sound/ymfpci.h
63973 +++ b/include/sound/ymfpci.h
63974 @@ -358,7 +358,7 @@ struct snd_ymfpci {
63975 spinlock_t reg_lock;
63976 spinlock_t voice_lock;
63977 wait_queue_head_t interrupt_sleep;
63978 - atomic_t interrupt_sleep_count;
63979 + atomic_unchecked_t interrupt_sleep_count;
63980 struct snd_info_entry *proc_entry;
63981 const struct firmware *dsp_microcode;
63982 const struct firmware *controller_microcode;
63983 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
63984 index aaccc5f..092d568 100644
63985 --- a/include/target/target_core_base.h
63986 +++ b/include/target/target_core_base.h
63987 @@ -447,7 +447,7 @@ struct t10_reservation_ops {
63988 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
63989 int (*t10_pr_register)(struct se_cmd *);
63990 int (*t10_pr_clear)(struct se_cmd *);
63991 -};
63992 +} __no_const;
63993
63994 struct t10_reservation {
63995 /* Reservation effects all target ports */
63996 @@ -576,7 +576,7 @@ struct se_cmd {
63997 atomic_t t_se_count;
63998 atomic_t t_task_cdbs_left;
63999 atomic_t t_task_cdbs_ex_left;
64000 - atomic_t t_task_cdbs_sent;
64001 + atomic_unchecked_t t_task_cdbs_sent;
64002 unsigned int transport_state;
64003 #define CMD_T_ABORTED (1 << 0)
64004 #define CMD_T_ACTIVE (1 << 1)
64005 @@ -802,7 +802,7 @@ struct se_device {
64006 spinlock_t stats_lock;
64007 /* Active commands on this virtual SE device */
64008 atomic_t simple_cmds;
64009 - atomic_t dev_ordered_id;
64010 + atomic_unchecked_t dev_ordered_id;
64011 atomic_t execute_tasks;
64012 atomic_t dev_ordered_sync;
64013 atomic_t dev_qf_count;
64014 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
64015 new file mode 100644
64016 index 0000000..2efe49d
64017 --- /dev/null
64018 +++ b/include/trace/events/fs.h
64019 @@ -0,0 +1,53 @@
64020 +#undef TRACE_SYSTEM
64021 +#define TRACE_SYSTEM fs
64022 +
64023 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
64024 +#define _TRACE_FS_H
64025 +
64026 +#include <linux/fs.h>
64027 +#include <linux/tracepoint.h>
64028 +
64029 +TRACE_EVENT(do_sys_open,
64030 +
64031 + TP_PROTO(char *filename, int flags, int mode),
64032 +
64033 + TP_ARGS(filename, flags, mode),
64034 +
64035 + TP_STRUCT__entry(
64036 + __string( filename, filename )
64037 + __field( int, flags )
64038 + __field( int, mode )
64039 + ),
64040 +
64041 + TP_fast_assign(
64042 + __assign_str(filename, filename);
64043 + __entry->flags = flags;
64044 + __entry->mode = mode;
64045 + ),
64046 +
64047 + TP_printk("\"%s\" %x %o",
64048 + __get_str(filename), __entry->flags, __entry->mode)
64049 +);
64050 +
64051 +TRACE_EVENT(open_exec,
64052 +
64053 + TP_PROTO(const char *filename),
64054 +
64055 + TP_ARGS(filename),
64056 +
64057 + TP_STRUCT__entry(
64058 + __string( filename, filename )
64059 + ),
64060 +
64061 + TP_fast_assign(
64062 + __assign_str(filename, filename);
64063 + ),
64064 +
64065 + TP_printk("\"%s\"",
64066 + __get_str(filename))
64067 +);
64068 +
64069 +#endif /* _TRACE_FS_H */
64070 +
64071 +/* This part must be outside protection */
64072 +#include <trace/define_trace.h>
64073 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
64074 index 1c09820..7f5ec79 100644
64075 --- a/include/trace/events/irq.h
64076 +++ b/include/trace/events/irq.h
64077 @@ -36,7 +36,7 @@ struct softirq_action;
64078 */
64079 TRACE_EVENT(irq_handler_entry,
64080
64081 - TP_PROTO(int irq, struct irqaction *action),
64082 + TP_PROTO(int irq, const struct irqaction *action),
64083
64084 TP_ARGS(irq, action),
64085
64086 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
64087 */
64088 TRACE_EVENT(irq_handler_exit,
64089
64090 - TP_PROTO(int irq, struct irqaction *action, int ret),
64091 + TP_PROTO(int irq, const struct irqaction *action, int ret),
64092
64093 TP_ARGS(irq, action, ret),
64094
64095 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
64096 index f9466fa..f4e2b81 100644
64097 --- a/include/video/udlfb.h
64098 +++ b/include/video/udlfb.h
64099 @@ -53,10 +53,10 @@ struct dlfb_data {
64100 u32 pseudo_palette[256];
64101 int blank_mode; /*one of FB_BLANK_ */
64102 /* blit-only rendering path metrics, exposed through sysfs */
64103 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64104 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
64105 - atomic_t bytes_sent; /* to usb, after compression including overhead */
64106 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
64107 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64108 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
64109 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
64110 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
64111 };
64112
64113 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
64114 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
64115 index 0993a22..32ba2fe 100644
64116 --- a/include/video/uvesafb.h
64117 +++ b/include/video/uvesafb.h
64118 @@ -177,6 +177,7 @@ struct uvesafb_par {
64119 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
64120 u8 pmi_setpal; /* PMI for palette changes */
64121 u16 *pmi_base; /* protected mode interface location */
64122 + u8 *pmi_code; /* protected mode code location */
64123 void *pmi_start;
64124 void *pmi_pal;
64125 u8 *vbe_state_orig; /*
64126 diff --git a/init/Kconfig b/init/Kconfig
64127 index 6cfd71d..16006e6 100644
64128 --- a/init/Kconfig
64129 +++ b/init/Kconfig
64130 @@ -790,6 +790,7 @@ endif # CGROUPS
64131
64132 config CHECKPOINT_RESTORE
64133 bool "Checkpoint/restore support" if EXPERT
64134 + depends on !GRKERNSEC
64135 default n
64136 help
64137 Enables additional kernel features in a sake of checkpoint/restore.
64138 @@ -1240,7 +1241,7 @@ config SLUB_DEBUG
64139
64140 config COMPAT_BRK
64141 bool "Disable heap randomization"
64142 - default y
64143 + default n
64144 help
64145 Randomizing heap placement makes heap exploits harder, but it
64146 also breaks ancient binaries (including anything libc5 based).
64147 @@ -1423,7 +1424,7 @@ config INIT_ALL_POSSIBLE
64148 config STOP_MACHINE
64149 bool
64150 default y
64151 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
64152 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
64153 help
64154 Need stop_machine() primitive.
64155
64156 diff --git a/init/do_mounts.c b/init/do_mounts.c
64157 index 42b0707..c06eef4 100644
64158 --- a/init/do_mounts.c
64159 +++ b/init/do_mounts.c
64160 @@ -326,11 +326,11 @@ static void __init get_fs_names(char *page)
64161 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
64162 {
64163 struct super_block *s;
64164 - int err = sys_mount(name, "/root", fs, flags, data);
64165 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
64166 if (err)
64167 return err;
64168
64169 - sys_chdir((const char __user __force *)"/root");
64170 + sys_chdir((const char __force_user *)"/root");
64171 s = current->fs->pwd.dentry->d_sb;
64172 ROOT_DEV = s->s_dev;
64173 printk(KERN_INFO
64174 @@ -450,18 +450,18 @@ void __init change_floppy(char *fmt, ...)
64175 va_start(args, fmt);
64176 vsprintf(buf, fmt, args);
64177 va_end(args);
64178 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
64179 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
64180 if (fd >= 0) {
64181 sys_ioctl(fd, FDEJECT, 0);
64182 sys_close(fd);
64183 }
64184 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
64185 - fd = sys_open("/dev/console", O_RDWR, 0);
64186 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
64187 if (fd >= 0) {
64188 sys_ioctl(fd, TCGETS, (long)&termios);
64189 termios.c_lflag &= ~ICANON;
64190 sys_ioctl(fd, TCSETSF, (long)&termios);
64191 - sys_read(fd, &c, 1);
64192 + sys_read(fd, (char __user *)&c, 1);
64193 termios.c_lflag |= ICANON;
64194 sys_ioctl(fd, TCSETSF, (long)&termios);
64195 sys_close(fd);
64196 @@ -555,6 +555,6 @@ void __init prepare_namespace(void)
64197 mount_root();
64198 out:
64199 devtmpfs_mount("dev");
64200 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
64201 - sys_chroot((const char __user __force *)".");
64202 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
64203 + sys_chroot((const char __force_user *)".");
64204 }
64205 diff --git a/init/do_mounts.h b/init/do_mounts.h
64206 index f5b978a..69dbfe8 100644
64207 --- a/init/do_mounts.h
64208 +++ b/init/do_mounts.h
64209 @@ -15,15 +15,15 @@ extern int root_mountflags;
64210
64211 static inline int create_dev(char *name, dev_t dev)
64212 {
64213 - sys_unlink(name);
64214 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
64215 + sys_unlink((char __force_user *)name);
64216 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
64217 }
64218
64219 #if BITS_PER_LONG == 32
64220 static inline u32 bstat(char *name)
64221 {
64222 struct stat64 stat;
64223 - if (sys_stat64(name, &stat) != 0)
64224 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
64225 return 0;
64226 if (!S_ISBLK(stat.st_mode))
64227 return 0;
64228 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
64229 static inline u32 bstat(char *name)
64230 {
64231 struct stat stat;
64232 - if (sys_newstat(name, &stat) != 0)
64233 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
64234 return 0;
64235 if (!S_ISBLK(stat.st_mode))
64236 return 0;
64237 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
64238 index 9047330..de0d1fb 100644
64239 --- a/init/do_mounts_initrd.c
64240 +++ b/init/do_mounts_initrd.c
64241 @@ -43,13 +43,13 @@ static void __init handle_initrd(void)
64242 create_dev("/dev/root.old", Root_RAM0);
64243 /* mount initrd on rootfs' /root */
64244 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
64245 - sys_mkdir("/old", 0700);
64246 - root_fd = sys_open("/", 0, 0);
64247 - old_fd = sys_open("/old", 0, 0);
64248 + sys_mkdir((const char __force_user *)"/old", 0700);
64249 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
64250 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
64251 /* move initrd over / and chdir/chroot in initrd root */
64252 - sys_chdir("/root");
64253 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
64254 - sys_chroot(".");
64255 + sys_chdir((const char __force_user *)"/root");
64256 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
64257 + sys_chroot((const char __force_user *)".");
64258
64259 /*
64260 * In case that a resume from disk is carried out by linuxrc or one of
64261 @@ -66,15 +66,15 @@ static void __init handle_initrd(void)
64262
64263 /* move initrd to rootfs' /old */
64264 sys_fchdir(old_fd);
64265 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
64266 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
64267 /* switch root and cwd back to / of rootfs */
64268 sys_fchdir(root_fd);
64269 - sys_chroot(".");
64270 + sys_chroot((const char __force_user *)".");
64271 sys_close(old_fd);
64272 sys_close(root_fd);
64273
64274 if (new_decode_dev(real_root_dev) == Root_RAM0) {
64275 - sys_chdir("/old");
64276 + sys_chdir((const char __force_user *)"/old");
64277 return;
64278 }
64279
64280 @@ -82,17 +82,17 @@ static void __init handle_initrd(void)
64281 mount_root();
64282
64283 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
64284 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
64285 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
64286 if (!error)
64287 printk("okay\n");
64288 else {
64289 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
64290 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
64291 if (error == -ENOENT)
64292 printk("/initrd does not exist. Ignored.\n");
64293 else
64294 printk("failed\n");
64295 printk(KERN_NOTICE "Unmounting old root\n");
64296 - sys_umount("/old", MNT_DETACH);
64297 + sys_umount((char __force_user *)"/old", MNT_DETACH);
64298 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
64299 if (fd < 0) {
64300 error = fd;
64301 @@ -115,11 +115,11 @@ int __init initrd_load(void)
64302 * mounted in the normal path.
64303 */
64304 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
64305 - sys_unlink("/initrd.image");
64306 + sys_unlink((const char __force_user *)"/initrd.image");
64307 handle_initrd();
64308 return 1;
64309 }
64310 }
64311 - sys_unlink("/initrd.image");
64312 + sys_unlink((const char __force_user *)"/initrd.image");
64313 return 0;
64314 }
64315 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
64316 index 32c4799..c27ee74 100644
64317 --- a/init/do_mounts_md.c
64318 +++ b/init/do_mounts_md.c
64319 @@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
64320 partitioned ? "_d" : "", minor,
64321 md_setup_args[ent].device_names);
64322
64323 - fd = sys_open(name, 0, 0);
64324 + fd = sys_open((char __force_user *)name, 0, 0);
64325 if (fd < 0) {
64326 printk(KERN_ERR "md: open failed - cannot start "
64327 "array %s\n", name);
64328 @@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
64329 * array without it
64330 */
64331 sys_close(fd);
64332 - fd = sys_open(name, 0, 0);
64333 + fd = sys_open((char __force_user *)name, 0, 0);
64334 sys_ioctl(fd, BLKRRPART, 0);
64335 }
64336 sys_close(fd);
64337 @@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
64338
64339 wait_for_device_probe();
64340
64341 - fd = sys_open((const char __user __force *) "/dev/md0", 0, 0);
64342 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
64343 if (fd >= 0) {
64344 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
64345 sys_close(fd);
64346 diff --git a/init/initramfs.c b/init/initramfs.c
64347 index 8216c30..25e8e32 100644
64348 --- a/init/initramfs.c
64349 +++ b/init/initramfs.c
64350 @@ -74,7 +74,7 @@ static void __init free_hash(void)
64351 }
64352 }
64353
64354 -static long __init do_utime(char __user *filename, time_t mtime)
64355 +static long __init do_utime(__force char __user *filename, time_t mtime)
64356 {
64357 struct timespec t[2];
64358
64359 @@ -109,7 +109,7 @@ static void __init dir_utime(void)
64360 struct dir_entry *de, *tmp;
64361 list_for_each_entry_safe(de, tmp, &dir_list, list) {
64362 list_del(&de->list);
64363 - do_utime(de->name, de->mtime);
64364 + do_utime((char __force_user *)de->name, de->mtime);
64365 kfree(de->name);
64366 kfree(de);
64367 }
64368 @@ -271,7 +271,7 @@ static int __init maybe_link(void)
64369 if (nlink >= 2) {
64370 char *old = find_link(major, minor, ino, mode, collected);
64371 if (old)
64372 - return (sys_link(old, collected) < 0) ? -1 : 1;
64373 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
64374 }
64375 return 0;
64376 }
64377 @@ -280,11 +280,11 @@ static void __init clean_path(char *path, umode_t mode)
64378 {
64379 struct stat st;
64380
64381 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
64382 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
64383 if (S_ISDIR(st.st_mode))
64384 - sys_rmdir(path);
64385 + sys_rmdir((char __force_user *)path);
64386 else
64387 - sys_unlink(path);
64388 + sys_unlink((char __force_user *)path);
64389 }
64390 }
64391
64392 @@ -305,7 +305,7 @@ static int __init do_name(void)
64393 int openflags = O_WRONLY|O_CREAT;
64394 if (ml != 1)
64395 openflags |= O_TRUNC;
64396 - wfd = sys_open(collected, openflags, mode);
64397 + wfd = sys_open((char __force_user *)collected, openflags, mode);
64398
64399 if (wfd >= 0) {
64400 sys_fchown(wfd, uid, gid);
64401 @@ -317,17 +317,17 @@ static int __init do_name(void)
64402 }
64403 }
64404 } else if (S_ISDIR(mode)) {
64405 - sys_mkdir(collected, mode);
64406 - sys_chown(collected, uid, gid);
64407 - sys_chmod(collected, mode);
64408 + sys_mkdir((char __force_user *)collected, mode);
64409 + sys_chown((char __force_user *)collected, uid, gid);
64410 + sys_chmod((char __force_user *)collected, mode);
64411 dir_add(collected, mtime);
64412 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
64413 S_ISFIFO(mode) || S_ISSOCK(mode)) {
64414 if (maybe_link() == 0) {
64415 - sys_mknod(collected, mode, rdev);
64416 - sys_chown(collected, uid, gid);
64417 - sys_chmod(collected, mode);
64418 - do_utime(collected, mtime);
64419 + sys_mknod((char __force_user *)collected, mode, rdev);
64420 + sys_chown((char __force_user *)collected, uid, gid);
64421 + sys_chmod((char __force_user *)collected, mode);
64422 + do_utime((char __force_user *)collected, mtime);
64423 }
64424 }
64425 return 0;
64426 @@ -336,15 +336,15 @@ static int __init do_name(void)
64427 static int __init do_copy(void)
64428 {
64429 if (count >= body_len) {
64430 - sys_write(wfd, victim, body_len);
64431 + sys_write(wfd, (char __force_user *)victim, body_len);
64432 sys_close(wfd);
64433 - do_utime(vcollected, mtime);
64434 + do_utime((char __force_user *)vcollected, mtime);
64435 kfree(vcollected);
64436 eat(body_len);
64437 state = SkipIt;
64438 return 0;
64439 } else {
64440 - sys_write(wfd, victim, count);
64441 + sys_write(wfd, (char __force_user *)victim, count);
64442 body_len -= count;
64443 eat(count);
64444 return 1;
64445 @@ -355,9 +355,9 @@ static int __init do_symlink(void)
64446 {
64447 collected[N_ALIGN(name_len) + body_len] = '\0';
64448 clean_path(collected, 0);
64449 - sys_symlink(collected + N_ALIGN(name_len), collected);
64450 - sys_lchown(collected, uid, gid);
64451 - do_utime(collected, mtime);
64452 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
64453 + sys_lchown((char __force_user *)collected, uid, gid);
64454 + do_utime((char __force_user *)collected, mtime);
64455 state = SkipIt;
64456 next_state = Reset;
64457 return 0;
64458 diff --git a/init/main.c b/init/main.c
64459 index b08c5f7..09f865e 100644
64460 --- a/init/main.c
64461 +++ b/init/main.c
64462 @@ -95,6 +95,8 @@ static inline void mark_rodata_ro(void) { }
64463 extern void tc_init(void);
64464 #endif
64465
64466 +extern void grsecurity_init(void);
64467 +
64468 /*
64469 * Debug helper: via this flag we know that we are in 'early bootup code'
64470 * where only the boot processor is running with IRQ disabled. This means
64471 @@ -148,6 +150,49 @@ static int __init set_reset_devices(char *str)
64472
64473 __setup("reset_devices", set_reset_devices);
64474
64475 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
64476 +extern char pax_enter_kernel_user[];
64477 +extern char pax_exit_kernel_user[];
64478 +extern pgdval_t clone_pgd_mask;
64479 +#endif
64480 +
64481 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
64482 +static int __init setup_pax_nouderef(char *str)
64483 +{
64484 +#ifdef CONFIG_X86_32
64485 + unsigned int cpu;
64486 + struct desc_struct *gdt;
64487 +
64488 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
64489 + gdt = get_cpu_gdt_table(cpu);
64490 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
64491 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
64492 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
64493 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
64494 + }
64495 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
64496 +#else
64497 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
64498 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
64499 + clone_pgd_mask = ~(pgdval_t)0UL;
64500 +#endif
64501 +
64502 + return 0;
64503 +}
64504 +early_param("pax_nouderef", setup_pax_nouderef);
64505 +#endif
64506 +
64507 +#ifdef CONFIG_PAX_SOFTMODE
64508 +int pax_softmode;
64509 +
64510 +static int __init setup_pax_softmode(char *str)
64511 +{
64512 + get_option(&str, &pax_softmode);
64513 + return 1;
64514 +}
64515 +__setup("pax_softmode=", setup_pax_softmode);
64516 +#endif
64517 +
64518 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
64519 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
64520 static const char *panic_later, *panic_param;
64521 @@ -674,6 +719,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
64522 {
64523 int count = preempt_count();
64524 int ret;
64525 + const char *msg1 = "", *msg2 = "";
64526
64527 if (initcall_debug)
64528 ret = do_one_initcall_debug(fn);
64529 @@ -686,15 +732,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
64530 sprintf(msgbuf, "error code %d ", ret);
64531
64532 if (preempt_count() != count) {
64533 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
64534 + msg1 = " preemption imbalance";
64535 preempt_count() = count;
64536 }
64537 if (irqs_disabled()) {
64538 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
64539 + msg2 = " disabled interrupts";
64540 local_irq_enable();
64541 }
64542 - if (msgbuf[0]) {
64543 - printk("initcall %pF returned with %s\n", fn, msgbuf);
64544 + if (msgbuf[0] || *msg1 || *msg2) {
64545 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
64546 }
64547
64548 return ret;
64549 @@ -865,7 +911,7 @@ static int __init kernel_init(void * unused)
64550 do_basic_setup();
64551
64552 /* Open the /dev/console on the rootfs, this should never fail */
64553 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
64554 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
64555 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
64556
64557 (void) sys_dup(0);
64558 @@ -878,11 +924,13 @@ static int __init kernel_init(void * unused)
64559 if (!ramdisk_execute_command)
64560 ramdisk_execute_command = "/init";
64561
64562 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
64563 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
64564 ramdisk_execute_command = NULL;
64565 prepare_namespace();
64566 }
64567
64568 + grsecurity_init();
64569 +
64570 /*
64571 * Ok, we have completed the initial bootup, and
64572 * we're essentially up and running. Get rid of the
64573 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
64574 index 28bd64d..c66b72a 100644
64575 --- a/ipc/mqueue.c
64576 +++ b/ipc/mqueue.c
64577 @@ -156,6 +156,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
64578 mq_bytes = (mq_msg_tblsz +
64579 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
64580
64581 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
64582 spin_lock(&mq_lock);
64583 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
64584 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
64585 diff --git a/ipc/msg.c b/ipc/msg.c
64586 index 7385de2..a8180e08 100644
64587 --- a/ipc/msg.c
64588 +++ b/ipc/msg.c
64589 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
64590 return security_msg_queue_associate(msq, msgflg);
64591 }
64592
64593 +static struct ipc_ops msg_ops = {
64594 + .getnew = newque,
64595 + .associate = msg_security,
64596 + .more_checks = NULL
64597 +};
64598 +
64599 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
64600 {
64601 struct ipc_namespace *ns;
64602 - struct ipc_ops msg_ops;
64603 struct ipc_params msg_params;
64604
64605 ns = current->nsproxy->ipc_ns;
64606
64607 - msg_ops.getnew = newque;
64608 - msg_ops.associate = msg_security;
64609 - msg_ops.more_checks = NULL;
64610 -
64611 msg_params.key = key;
64612 msg_params.flg = msgflg;
64613
64614 diff --git a/ipc/sem.c b/ipc/sem.c
64615 index 5215a81..cfc0cac 100644
64616 --- a/ipc/sem.c
64617 +++ b/ipc/sem.c
64618 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
64619 return 0;
64620 }
64621
64622 +static struct ipc_ops sem_ops = {
64623 + .getnew = newary,
64624 + .associate = sem_security,
64625 + .more_checks = sem_more_checks
64626 +};
64627 +
64628 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
64629 {
64630 struct ipc_namespace *ns;
64631 - struct ipc_ops sem_ops;
64632 struct ipc_params sem_params;
64633
64634 ns = current->nsproxy->ipc_ns;
64635 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
64636 if (nsems < 0 || nsems > ns->sc_semmsl)
64637 return -EINVAL;
64638
64639 - sem_ops.getnew = newary;
64640 - sem_ops.associate = sem_security;
64641 - sem_ops.more_checks = sem_more_checks;
64642 -
64643 sem_params.key = key;
64644 sem_params.flg = semflg;
64645 sem_params.u.nsems = nsems;
64646 diff --git a/ipc/shm.c b/ipc/shm.c
64647 index 406c5b2..bc66d67 100644
64648 --- a/ipc/shm.c
64649 +++ b/ipc/shm.c
64650 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
64651 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
64652 #endif
64653
64654 +#ifdef CONFIG_GRKERNSEC
64655 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64656 + const time_t shm_createtime, const uid_t cuid,
64657 + const int shmid);
64658 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64659 + const time_t shm_createtime);
64660 +#endif
64661 +
64662 void shm_init_ns(struct ipc_namespace *ns)
64663 {
64664 ns->shm_ctlmax = SHMMAX;
64665 @@ -508,6 +516,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
64666 shp->shm_lprid = 0;
64667 shp->shm_atim = shp->shm_dtim = 0;
64668 shp->shm_ctim = get_seconds();
64669 +#ifdef CONFIG_GRKERNSEC
64670 + {
64671 + struct timespec timeval;
64672 + do_posix_clock_monotonic_gettime(&timeval);
64673 +
64674 + shp->shm_createtime = timeval.tv_sec;
64675 + }
64676 +#endif
64677 shp->shm_segsz = size;
64678 shp->shm_nattch = 0;
64679 shp->shm_file = file;
64680 @@ -559,18 +575,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
64681 return 0;
64682 }
64683
64684 +static struct ipc_ops shm_ops = {
64685 + .getnew = newseg,
64686 + .associate = shm_security,
64687 + .more_checks = shm_more_checks
64688 +};
64689 +
64690 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
64691 {
64692 struct ipc_namespace *ns;
64693 - struct ipc_ops shm_ops;
64694 struct ipc_params shm_params;
64695
64696 ns = current->nsproxy->ipc_ns;
64697
64698 - shm_ops.getnew = newseg;
64699 - shm_ops.associate = shm_security;
64700 - shm_ops.more_checks = shm_more_checks;
64701 -
64702 shm_params.key = key;
64703 shm_params.flg = shmflg;
64704 shm_params.u.size = size;
64705 @@ -988,6 +1005,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
64706 f_mode = FMODE_READ | FMODE_WRITE;
64707 }
64708 if (shmflg & SHM_EXEC) {
64709 +
64710 +#ifdef CONFIG_PAX_MPROTECT
64711 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
64712 + goto out;
64713 +#endif
64714 +
64715 prot |= PROT_EXEC;
64716 acc_mode |= S_IXUGO;
64717 }
64718 @@ -1011,9 +1034,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
64719 if (err)
64720 goto out_unlock;
64721
64722 +#ifdef CONFIG_GRKERNSEC
64723 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
64724 + shp->shm_perm.cuid, shmid) ||
64725 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
64726 + err = -EACCES;
64727 + goto out_unlock;
64728 + }
64729 +#endif
64730 +
64731 path = shp->shm_file->f_path;
64732 path_get(&path);
64733 shp->shm_nattch++;
64734 +#ifdef CONFIG_GRKERNSEC
64735 + shp->shm_lapid = current->pid;
64736 +#endif
64737 size = i_size_read(path.dentry->d_inode);
64738 shm_unlock(shp);
64739
64740 diff --git a/kernel/acct.c b/kernel/acct.c
64741 index 02e6167..54824f7 100644
64742 --- a/kernel/acct.c
64743 +++ b/kernel/acct.c
64744 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
64745 */
64746 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
64747 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
64748 - file->f_op->write(file, (char *)&ac,
64749 + file->f_op->write(file, (char __force_user *)&ac,
64750 sizeof(acct_t), &file->f_pos);
64751 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
64752 set_fs(fs);
64753 diff --git a/kernel/audit.c b/kernel/audit.c
64754 index 1c7f2c6..9ba5359 100644
64755 --- a/kernel/audit.c
64756 +++ b/kernel/audit.c
64757 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
64758 3) suppressed due to audit_rate_limit
64759 4) suppressed due to audit_backlog_limit
64760 */
64761 -static atomic_t audit_lost = ATOMIC_INIT(0);
64762 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
64763
64764 /* The netlink socket. */
64765 static struct sock *audit_sock;
64766 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
64767 unsigned long now;
64768 int print;
64769
64770 - atomic_inc(&audit_lost);
64771 + atomic_inc_unchecked(&audit_lost);
64772
64773 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
64774
64775 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
64776 printk(KERN_WARNING
64777 "audit: audit_lost=%d audit_rate_limit=%d "
64778 "audit_backlog_limit=%d\n",
64779 - atomic_read(&audit_lost),
64780 + atomic_read_unchecked(&audit_lost),
64781 audit_rate_limit,
64782 audit_backlog_limit);
64783 audit_panic(message);
64784 @@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
64785 status_set.pid = audit_pid;
64786 status_set.rate_limit = audit_rate_limit;
64787 status_set.backlog_limit = audit_backlog_limit;
64788 - status_set.lost = atomic_read(&audit_lost);
64789 + status_set.lost = atomic_read_unchecked(&audit_lost);
64790 status_set.backlog = skb_queue_len(&audit_skb_queue);
64791 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
64792 &status_set, sizeof(status_set));
64793 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
64794 index af1de0f..06dfe57 100644
64795 --- a/kernel/auditsc.c
64796 +++ b/kernel/auditsc.c
64797 @@ -2288,7 +2288,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
64798 }
64799
64800 /* global counter which is incremented every time something logs in */
64801 -static atomic_t session_id = ATOMIC_INIT(0);
64802 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
64803
64804 /**
64805 * audit_set_loginuid - set current task's audit_context loginuid
64806 @@ -2312,7 +2312,7 @@ int audit_set_loginuid(uid_t loginuid)
64807 return -EPERM;
64808 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
64809
64810 - sessionid = atomic_inc_return(&session_id);
64811 + sessionid = atomic_inc_return_unchecked(&session_id);
64812 if (context && context->in_syscall) {
64813 struct audit_buffer *ab;
64814
64815 diff --git a/kernel/capability.c b/kernel/capability.c
64816 index 3f1adb6..c564db0 100644
64817 --- a/kernel/capability.c
64818 +++ b/kernel/capability.c
64819 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
64820 * before modification is attempted and the application
64821 * fails.
64822 */
64823 + if (tocopy > ARRAY_SIZE(kdata))
64824 + return -EFAULT;
64825 +
64826 if (copy_to_user(dataptr, kdata, tocopy
64827 * sizeof(struct __user_cap_data_struct))) {
64828 return -EFAULT;
64829 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
64830 int ret;
64831
64832 rcu_read_lock();
64833 - ret = security_capable(__task_cred(t), ns, cap);
64834 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
64835 + gr_task_is_capable(t, __task_cred(t), cap);
64836 rcu_read_unlock();
64837
64838 - return (ret == 0);
64839 + return ret;
64840 }
64841
64842 /**
64843 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
64844 int ret;
64845
64846 rcu_read_lock();
64847 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
64848 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
64849 rcu_read_unlock();
64850
64851 - return (ret == 0);
64852 + return ret;
64853 }
64854
64855 /**
64856 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
64857 BUG();
64858 }
64859
64860 - if (security_capable(current_cred(), ns, cap) == 0) {
64861 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
64862 current->flags |= PF_SUPERPRIV;
64863 return true;
64864 }
64865 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
64866 }
64867 EXPORT_SYMBOL(ns_capable);
64868
64869 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
64870 +{
64871 + if (unlikely(!cap_valid(cap))) {
64872 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
64873 + BUG();
64874 + }
64875 +
64876 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
64877 + current->flags |= PF_SUPERPRIV;
64878 + return true;
64879 + }
64880 + return false;
64881 +}
64882 +EXPORT_SYMBOL(ns_capable_nolog);
64883 +
64884 /**
64885 * capable - Determine if the current task has a superior capability in effect
64886 * @cap: The capability to be tested for
64887 @@ -408,6 +427,12 @@ bool capable(int cap)
64888 }
64889 EXPORT_SYMBOL(capable);
64890
64891 +bool capable_nolog(int cap)
64892 +{
64893 + return ns_capable_nolog(&init_user_ns, cap);
64894 +}
64895 +EXPORT_SYMBOL(capable_nolog);
64896 +
64897 /**
64898 * nsown_capable - Check superior capability to one's own user_ns
64899 * @cap: The capability in question
64900 diff --git a/kernel/compat.c b/kernel/compat.c
64901 index d2c67aa..a629b2e 100644
64902 --- a/kernel/compat.c
64903 +++ b/kernel/compat.c
64904 @@ -13,6 +13,7 @@
64905
64906 #include <linux/linkage.h>
64907 #include <linux/compat.h>
64908 +#include <linux/module.h>
64909 #include <linux/errno.h>
64910 #include <linux/time.h>
64911 #include <linux/signal.h>
64912 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
64913 mm_segment_t oldfs;
64914 long ret;
64915
64916 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
64917 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
64918 oldfs = get_fs();
64919 set_fs(KERNEL_DS);
64920 ret = hrtimer_nanosleep_restart(restart);
64921 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
64922 oldfs = get_fs();
64923 set_fs(KERNEL_DS);
64924 ret = hrtimer_nanosleep(&tu,
64925 - rmtp ? (struct timespec __user *)&rmt : NULL,
64926 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
64927 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
64928 set_fs(oldfs);
64929
64930 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
64931 mm_segment_t old_fs = get_fs();
64932
64933 set_fs(KERNEL_DS);
64934 - ret = sys_sigpending((old_sigset_t __user *) &s);
64935 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
64936 set_fs(old_fs);
64937 if (ret == 0)
64938 ret = put_user(s, set);
64939 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
64940 mm_segment_t old_fs = get_fs();
64941
64942 set_fs(KERNEL_DS);
64943 - ret = sys_old_getrlimit(resource, &r);
64944 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
64945 set_fs(old_fs);
64946
64947 if (!ret) {
64948 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
64949 mm_segment_t old_fs = get_fs();
64950
64951 set_fs(KERNEL_DS);
64952 - ret = sys_getrusage(who, (struct rusage __user *) &r);
64953 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
64954 set_fs(old_fs);
64955
64956 if (ret)
64957 @@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
64958 set_fs (KERNEL_DS);
64959 ret = sys_wait4(pid,
64960 (stat_addr ?
64961 - (unsigned int __user *) &status : NULL),
64962 - options, (struct rusage __user *) &r);
64963 + (unsigned int __force_user *) &status : NULL),
64964 + options, (struct rusage __force_user *) &r);
64965 set_fs (old_fs);
64966
64967 if (ret > 0) {
64968 @@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
64969 memset(&info, 0, sizeof(info));
64970
64971 set_fs(KERNEL_DS);
64972 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
64973 - uru ? (struct rusage __user *)&ru : NULL);
64974 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
64975 + uru ? (struct rusage __force_user *)&ru : NULL);
64976 set_fs(old_fs);
64977
64978 if ((ret < 0) || (info.si_signo == 0))
64979 @@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
64980 oldfs = get_fs();
64981 set_fs(KERNEL_DS);
64982 err = sys_timer_settime(timer_id, flags,
64983 - (struct itimerspec __user *) &newts,
64984 - (struct itimerspec __user *) &oldts);
64985 + (struct itimerspec __force_user *) &newts,
64986 + (struct itimerspec __force_user *) &oldts);
64987 set_fs(oldfs);
64988 if (!err && old && put_compat_itimerspec(old, &oldts))
64989 return -EFAULT;
64990 @@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
64991 oldfs = get_fs();
64992 set_fs(KERNEL_DS);
64993 err = sys_timer_gettime(timer_id,
64994 - (struct itimerspec __user *) &ts);
64995 + (struct itimerspec __force_user *) &ts);
64996 set_fs(oldfs);
64997 if (!err && put_compat_itimerspec(setting, &ts))
64998 return -EFAULT;
64999 @@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
65000 oldfs = get_fs();
65001 set_fs(KERNEL_DS);
65002 err = sys_clock_settime(which_clock,
65003 - (struct timespec __user *) &ts);
65004 + (struct timespec __force_user *) &ts);
65005 set_fs(oldfs);
65006 return err;
65007 }
65008 @@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
65009 oldfs = get_fs();
65010 set_fs(KERNEL_DS);
65011 err = sys_clock_gettime(which_clock,
65012 - (struct timespec __user *) &ts);
65013 + (struct timespec __force_user *) &ts);
65014 set_fs(oldfs);
65015 if (!err && put_compat_timespec(&ts, tp))
65016 return -EFAULT;
65017 @@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
65018
65019 oldfs = get_fs();
65020 set_fs(KERNEL_DS);
65021 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
65022 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
65023 set_fs(oldfs);
65024
65025 err = compat_put_timex(utp, &txc);
65026 @@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
65027 oldfs = get_fs();
65028 set_fs(KERNEL_DS);
65029 err = sys_clock_getres(which_clock,
65030 - (struct timespec __user *) &ts);
65031 + (struct timespec __force_user *) &ts);
65032 set_fs(oldfs);
65033 if (!err && tp && put_compat_timespec(&ts, tp))
65034 return -EFAULT;
65035 @@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
65036 long err;
65037 mm_segment_t oldfs;
65038 struct timespec tu;
65039 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
65040 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
65041
65042 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
65043 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
65044 oldfs = get_fs();
65045 set_fs(KERNEL_DS);
65046 err = clock_nanosleep_restart(restart);
65047 @@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
65048 oldfs = get_fs();
65049 set_fs(KERNEL_DS);
65050 err = sys_clock_nanosleep(which_clock, flags,
65051 - (struct timespec __user *) &in,
65052 - (struct timespec __user *) &out);
65053 + (struct timespec __force_user *) &in,
65054 + (struct timespec __force_user *) &out);
65055 set_fs(oldfs);
65056
65057 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
65058 diff --git a/kernel/configs.c b/kernel/configs.c
65059 index 42e8fa0..9e7406b 100644
65060 --- a/kernel/configs.c
65061 +++ b/kernel/configs.c
65062 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
65063 struct proc_dir_entry *entry;
65064
65065 /* create the current config file */
65066 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
65067 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
65068 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
65069 + &ikconfig_file_ops);
65070 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65071 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
65072 + &ikconfig_file_ops);
65073 +#endif
65074 +#else
65075 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
65076 &ikconfig_file_ops);
65077 +#endif
65078 +
65079 if (!entry)
65080 return -ENOMEM;
65081
65082 diff --git a/kernel/cred.c b/kernel/cred.c
65083 index e70683d..27761b6 100644
65084 --- a/kernel/cred.c
65085 +++ b/kernel/cred.c
65086 @@ -205,6 +205,15 @@ void exit_creds(struct task_struct *tsk)
65087 validate_creds(cred);
65088 put_cred(cred);
65089 }
65090 +
65091 +#ifdef CONFIG_GRKERNSEC_SETXID
65092 + cred = (struct cred *) tsk->delayed_cred;
65093 + if (cred) {
65094 + tsk->delayed_cred = NULL;
65095 + validate_creds(cred);
65096 + put_cred(cred);
65097 + }
65098 +#endif
65099 }
65100
65101 /**
65102 @@ -473,7 +482,7 @@ error_put:
65103 * Always returns 0 thus allowing this function to be tail-called at the end
65104 * of, say, sys_setgid().
65105 */
65106 -int commit_creds(struct cred *new)
65107 +static int __commit_creds(struct cred *new)
65108 {
65109 struct task_struct *task = current;
65110 const struct cred *old = task->real_cred;
65111 @@ -492,6 +501,8 @@ int commit_creds(struct cred *new)
65112
65113 get_cred(new); /* we will require a ref for the subj creds too */
65114
65115 + gr_set_role_label(task, new->uid, new->gid);
65116 +
65117 /* dumpability changes */
65118 if (old->euid != new->euid ||
65119 old->egid != new->egid ||
65120 @@ -541,6 +552,101 @@ int commit_creds(struct cred *new)
65121 put_cred(old);
65122 return 0;
65123 }
65124 +#ifdef CONFIG_GRKERNSEC_SETXID
65125 +extern int set_user(struct cred *new);
65126 +
65127 +void gr_delayed_cred_worker(void)
65128 +{
65129 + const struct cred *new = current->delayed_cred;
65130 + struct cred *ncred;
65131 +
65132 + current->delayed_cred = NULL;
65133 +
65134 + if (current_uid() && new != NULL) {
65135 + // from doing get_cred on it when queueing this
65136 + put_cred(new);
65137 + return;
65138 + } else if (new == NULL)
65139 + return;
65140 +
65141 + ncred = prepare_creds();
65142 + if (!ncred)
65143 + goto die;
65144 + // uids
65145 + ncred->uid = new->uid;
65146 + ncred->euid = new->euid;
65147 + ncred->suid = new->suid;
65148 + ncred->fsuid = new->fsuid;
65149 + // gids
65150 + ncred->gid = new->gid;
65151 + ncred->egid = new->egid;
65152 + ncred->sgid = new->sgid;
65153 + ncred->fsgid = new->fsgid;
65154 + // groups
65155 + if (set_groups(ncred, new->group_info) < 0) {
65156 + abort_creds(ncred);
65157 + goto die;
65158 + }
65159 + // caps
65160 + ncred->securebits = new->securebits;
65161 + ncred->cap_inheritable = new->cap_inheritable;
65162 + ncred->cap_permitted = new->cap_permitted;
65163 + ncred->cap_effective = new->cap_effective;
65164 + ncred->cap_bset = new->cap_bset;
65165 +
65166 + if (set_user(ncred)) {
65167 + abort_creds(ncred);
65168 + goto die;
65169 + }
65170 +
65171 + // from doing get_cred on it when queueing this
65172 + put_cred(new);
65173 +
65174 + __commit_creds(ncred);
65175 + return;
65176 +die:
65177 + // from doing get_cred on it when queueing this
65178 + put_cred(new);
65179 + do_group_exit(SIGKILL);
65180 +}
65181 +#endif
65182 +
65183 +int commit_creds(struct cred *new)
65184 +{
65185 +#ifdef CONFIG_GRKERNSEC_SETXID
65186 + int ret;
65187 + int schedule_it = 0;
65188 + struct task_struct *t;
65189 +
65190 + /* we won't get called with tasklist_lock held for writing
65191 + and interrupts disabled as the cred struct in that case is
65192 + init_cred
65193 + */
65194 + if (grsec_enable_setxid && !current_is_single_threaded() &&
65195 + !current_uid() && new->uid) {
65196 + schedule_it = 1;
65197 + }
65198 + ret = __commit_creds(new);
65199 + if (schedule_it) {
65200 + rcu_read_lock();
65201 + read_lock(&tasklist_lock);
65202 + for (t = next_thread(current); t != current;
65203 + t = next_thread(t)) {
65204 + if (t->delayed_cred == NULL) {
65205 + t->delayed_cred = get_cred(new);
65206 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
65207 + set_tsk_need_resched(t);
65208 + }
65209 + }
65210 + read_unlock(&tasklist_lock);
65211 + rcu_read_unlock();
65212 + }
65213 + return ret;
65214 +#else
65215 + return __commit_creds(new);
65216 +#endif
65217 +}
65218 +
65219 EXPORT_SYMBOL(commit_creds);
65220
65221 /**
65222 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
65223 index 0557f24..1a00d9a 100644
65224 --- a/kernel/debug/debug_core.c
65225 +++ b/kernel/debug/debug_core.c
65226 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
65227 */
65228 static atomic_t masters_in_kgdb;
65229 static atomic_t slaves_in_kgdb;
65230 -static atomic_t kgdb_break_tasklet_var;
65231 +static atomic_unchecked_t kgdb_break_tasklet_var;
65232 atomic_t kgdb_setting_breakpoint;
65233
65234 struct task_struct *kgdb_usethread;
65235 @@ -132,7 +132,7 @@ int kgdb_single_step;
65236 static pid_t kgdb_sstep_pid;
65237
65238 /* to keep track of the CPU which is doing the single stepping*/
65239 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
65240 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
65241
65242 /*
65243 * If you are debugging a problem where roundup (the collection of
65244 @@ -540,7 +540,7 @@ return_normal:
65245 * kernel will only try for the value of sstep_tries before
65246 * giving up and continuing on.
65247 */
65248 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
65249 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
65250 (kgdb_info[cpu].task &&
65251 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
65252 atomic_set(&kgdb_active, -1);
65253 @@ -634,8 +634,8 @@ cpu_master_loop:
65254 }
65255
65256 kgdb_restore:
65257 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
65258 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
65259 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
65260 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
65261 if (kgdb_info[sstep_cpu].task)
65262 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
65263 else
65264 @@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
65265 static void kgdb_tasklet_bpt(unsigned long ing)
65266 {
65267 kgdb_breakpoint();
65268 - atomic_set(&kgdb_break_tasklet_var, 0);
65269 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
65270 }
65271
65272 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
65273
65274 void kgdb_schedule_breakpoint(void)
65275 {
65276 - if (atomic_read(&kgdb_break_tasklet_var) ||
65277 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
65278 atomic_read(&kgdb_active) != -1 ||
65279 atomic_read(&kgdb_setting_breakpoint))
65280 return;
65281 - atomic_inc(&kgdb_break_tasklet_var);
65282 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
65283 tasklet_schedule(&kgdb_tasklet_breakpoint);
65284 }
65285 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
65286 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
65287 index 67b847d..93834dd 100644
65288 --- a/kernel/debug/kdb/kdb_main.c
65289 +++ b/kernel/debug/kdb/kdb_main.c
65290 @@ -1983,7 +1983,7 @@ static int kdb_lsmod(int argc, const char **argv)
65291 list_for_each_entry(mod, kdb_modules, list) {
65292
65293 kdb_printf("%-20s%8u 0x%p ", mod->name,
65294 - mod->core_size, (void *)mod);
65295 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
65296 #ifdef CONFIG_MODULE_UNLOAD
65297 kdb_printf("%4ld ", module_refcount(mod));
65298 #endif
65299 @@ -1993,7 +1993,7 @@ static int kdb_lsmod(int argc, const char **argv)
65300 kdb_printf(" (Loading)");
65301 else
65302 kdb_printf(" (Live)");
65303 - kdb_printf(" 0x%p", mod->module_core);
65304 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
65305
65306 #ifdef CONFIG_MODULE_UNLOAD
65307 {
65308 diff --git a/kernel/events/core.c b/kernel/events/core.c
65309 index fd126f8..70b755b 100644
65310 --- a/kernel/events/core.c
65311 +++ b/kernel/events/core.c
65312 @@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
65313 return 0;
65314 }
65315
65316 -static atomic64_t perf_event_id;
65317 +static atomic64_unchecked_t perf_event_id;
65318
65319 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
65320 enum event_type_t event_type);
65321 @@ -2659,7 +2659,7 @@ static void __perf_event_read(void *info)
65322
65323 static inline u64 perf_event_count(struct perf_event *event)
65324 {
65325 - return local64_read(&event->count) + atomic64_read(&event->child_count);
65326 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
65327 }
65328
65329 static u64 perf_event_read(struct perf_event *event)
65330 @@ -2983,9 +2983,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
65331 mutex_lock(&event->child_mutex);
65332 total += perf_event_read(event);
65333 *enabled += event->total_time_enabled +
65334 - atomic64_read(&event->child_total_time_enabled);
65335 + atomic64_read_unchecked(&event->child_total_time_enabled);
65336 *running += event->total_time_running +
65337 - atomic64_read(&event->child_total_time_running);
65338 + atomic64_read_unchecked(&event->child_total_time_running);
65339
65340 list_for_each_entry(child, &event->child_list, child_list) {
65341 total += perf_event_read(child);
65342 @@ -3393,10 +3393,10 @@ void perf_event_update_userpage(struct perf_event *event)
65343 userpg->offset -= local64_read(&event->hw.prev_count);
65344
65345 userpg->time_enabled = enabled +
65346 - atomic64_read(&event->child_total_time_enabled);
65347 + atomic64_read_unchecked(&event->child_total_time_enabled);
65348
65349 userpg->time_running = running +
65350 - atomic64_read(&event->child_total_time_running);
65351 + atomic64_read_unchecked(&event->child_total_time_running);
65352
65353 arch_perf_update_userpage(userpg, now);
65354
65355 @@ -3829,11 +3829,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
65356 values[n++] = perf_event_count(event);
65357 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
65358 values[n++] = enabled +
65359 - atomic64_read(&event->child_total_time_enabled);
65360 + atomic64_read_unchecked(&event->child_total_time_enabled);
65361 }
65362 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
65363 values[n++] = running +
65364 - atomic64_read(&event->child_total_time_running);
65365 + atomic64_read_unchecked(&event->child_total_time_running);
65366 }
65367 if (read_format & PERF_FORMAT_ID)
65368 values[n++] = primary_event_id(event);
65369 @@ -4511,12 +4511,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
65370 * need to add enough zero bytes after the string to handle
65371 * the 64bit alignment we do later.
65372 */
65373 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
65374 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
65375 if (!buf) {
65376 name = strncpy(tmp, "//enomem", sizeof(tmp));
65377 goto got_name;
65378 }
65379 - name = d_path(&file->f_path, buf, PATH_MAX);
65380 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
65381 if (IS_ERR(name)) {
65382 name = strncpy(tmp, "//toolong", sizeof(tmp));
65383 goto got_name;
65384 @@ -5929,7 +5929,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
65385 event->parent = parent_event;
65386
65387 event->ns = get_pid_ns(current->nsproxy->pid_ns);
65388 - event->id = atomic64_inc_return(&perf_event_id);
65389 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
65390
65391 event->state = PERF_EVENT_STATE_INACTIVE;
65392
65393 @@ -6491,10 +6491,10 @@ static void sync_child_event(struct perf_event *child_event,
65394 /*
65395 * Add back the child's count to the parent's count:
65396 */
65397 - atomic64_add(child_val, &parent_event->child_count);
65398 - atomic64_add(child_event->total_time_enabled,
65399 + atomic64_add_unchecked(child_val, &parent_event->child_count);
65400 + atomic64_add_unchecked(child_event->total_time_enabled,
65401 &parent_event->child_total_time_enabled);
65402 - atomic64_add(child_event->total_time_running,
65403 + atomic64_add_unchecked(child_event->total_time_running,
65404 &parent_event->child_total_time_running);
65405
65406 /*
65407 diff --git a/kernel/exit.c b/kernel/exit.c
65408 index 9d81012..d7911f1 100644
65409 --- a/kernel/exit.c
65410 +++ b/kernel/exit.c
65411 @@ -59,6 +59,10 @@
65412 #include <asm/pgtable.h>
65413 #include <asm/mmu_context.h>
65414
65415 +#ifdef CONFIG_GRKERNSEC
65416 +extern rwlock_t grsec_exec_file_lock;
65417 +#endif
65418 +
65419 static void exit_mm(struct task_struct * tsk);
65420
65421 static void __unhash_process(struct task_struct *p, bool group_dead)
65422 @@ -170,6 +174,10 @@ void release_task(struct task_struct * p)
65423 struct task_struct *leader;
65424 int zap_leader;
65425 repeat:
65426 +#ifdef CONFIG_NET
65427 + gr_del_task_from_ip_table(p);
65428 +#endif
65429 +
65430 /* don't need to get the RCU readlock here - the process is dead and
65431 * can't be modifying its own credentials. But shut RCU-lockdep up */
65432 rcu_read_lock();
65433 @@ -382,7 +390,7 @@ int allow_signal(int sig)
65434 * know it'll be handled, so that they don't get converted to
65435 * SIGKILL or just silently dropped.
65436 */
65437 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
65438 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
65439 recalc_sigpending();
65440 spin_unlock_irq(&current->sighand->siglock);
65441 return 0;
65442 @@ -418,6 +426,17 @@ void daemonize(const char *name, ...)
65443 vsnprintf(current->comm, sizeof(current->comm), name, args);
65444 va_end(args);
65445
65446 +#ifdef CONFIG_GRKERNSEC
65447 + write_lock(&grsec_exec_file_lock);
65448 + if (current->exec_file) {
65449 + fput(current->exec_file);
65450 + current->exec_file = NULL;
65451 + }
65452 + write_unlock(&grsec_exec_file_lock);
65453 +#endif
65454 +
65455 + gr_set_kernel_label(current);
65456 +
65457 /*
65458 * If we were started as result of loading a module, close all of the
65459 * user space pages. We don't need them, and if we didn't close them
65460 @@ -901,6 +920,8 @@ void do_exit(long code)
65461 struct task_struct *tsk = current;
65462 int group_dead;
65463
65464 + set_fs(USER_DS);
65465 +
65466 profile_task_exit(tsk);
65467
65468 WARN_ON(blk_needs_flush_plug(tsk));
65469 @@ -917,7 +938,6 @@ void do_exit(long code)
65470 * mm_release()->clear_child_tid() from writing to a user-controlled
65471 * kernel address.
65472 */
65473 - set_fs(USER_DS);
65474
65475 ptrace_event(PTRACE_EVENT_EXIT, code);
65476
65477 @@ -978,6 +998,9 @@ void do_exit(long code)
65478 tsk->exit_code = code;
65479 taskstats_exit(tsk, group_dead);
65480
65481 + gr_acl_handle_psacct(tsk, code);
65482 + gr_acl_handle_exit();
65483 +
65484 exit_mm(tsk);
65485
65486 if (group_dead)
65487 @@ -1094,7 +1117,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
65488 * Take down every thread in the group. This is called by fatal signals
65489 * as well as by sys_exit_group (below).
65490 */
65491 -void
65492 +__noreturn void
65493 do_group_exit(int exit_code)
65494 {
65495 struct signal_struct *sig = current->signal;
65496 diff --git a/kernel/fork.c b/kernel/fork.c
65497 index 8163333..aee97f3 100644
65498 --- a/kernel/fork.c
65499 +++ b/kernel/fork.c
65500 @@ -274,19 +274,24 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
65501 }
65502
65503 err = arch_dup_task_struct(tsk, orig);
65504 - if (err)
65505 - goto out;
65506
65507 + /*
65508 + * We defer looking at err, because we will need this setup
65509 + * for the clean up path to work correctly.
65510 + */
65511 tsk->stack = ti;
65512 -
65513 setup_thread_stack(tsk, orig);
65514 +
65515 + if (err)
65516 + goto out;
65517 +
65518 clear_user_return_notifier(tsk);
65519 clear_tsk_need_resched(tsk);
65520 stackend = end_of_stack(tsk);
65521 *stackend = STACK_END_MAGIC; /* for overflow detection */
65522
65523 #ifdef CONFIG_CC_STACKPROTECTOR
65524 - tsk->stack_canary = get_random_int();
65525 + tsk->stack_canary = pax_get_random_long();
65526 #endif
65527
65528 /*
65529 @@ -310,13 +315,78 @@ out:
65530 }
65531
65532 #ifdef CONFIG_MMU
65533 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
65534 +{
65535 + struct vm_area_struct *tmp;
65536 + unsigned long charge;
65537 + struct mempolicy *pol;
65538 + struct file *file;
65539 +
65540 + charge = 0;
65541 + if (mpnt->vm_flags & VM_ACCOUNT) {
65542 + unsigned long len;
65543 + len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
65544 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
65545 + goto fail_nomem;
65546 + charge = len;
65547 + }
65548 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
65549 + if (!tmp)
65550 + goto fail_nomem;
65551 + *tmp = *mpnt;
65552 + tmp->vm_mm = mm;
65553 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
65554 + pol = mpol_dup(vma_policy(mpnt));
65555 + if (IS_ERR(pol))
65556 + goto fail_nomem_policy;
65557 + vma_set_policy(tmp, pol);
65558 + if (anon_vma_fork(tmp, mpnt))
65559 + goto fail_nomem_anon_vma_fork;
65560 + tmp->vm_flags &= ~VM_LOCKED;
65561 + tmp->vm_next = tmp->vm_prev = NULL;
65562 + tmp->vm_mirror = NULL;
65563 + file = tmp->vm_file;
65564 + if (file) {
65565 + struct inode *inode = file->f_path.dentry->d_inode;
65566 + struct address_space *mapping = file->f_mapping;
65567 +
65568 + get_file(file);
65569 + if (tmp->vm_flags & VM_DENYWRITE)
65570 + atomic_dec(&inode->i_writecount);
65571 + mutex_lock(&mapping->i_mmap_mutex);
65572 + if (tmp->vm_flags & VM_SHARED)
65573 + mapping->i_mmap_writable++;
65574 + flush_dcache_mmap_lock(mapping);
65575 + /* insert tmp into the share list, just after mpnt */
65576 + vma_prio_tree_add(tmp, mpnt);
65577 + flush_dcache_mmap_unlock(mapping);
65578 + mutex_unlock(&mapping->i_mmap_mutex);
65579 + }
65580 +
65581 + /*
65582 + * Clear hugetlb-related page reserves for children. This only
65583 + * affects MAP_PRIVATE mappings. Faults generated by the child
65584 + * are not guaranteed to succeed, even if read-only
65585 + */
65586 + if (is_vm_hugetlb_page(tmp))
65587 + reset_vma_resv_huge_pages(tmp);
65588 +
65589 + return tmp;
65590 +
65591 +fail_nomem_anon_vma_fork:
65592 + mpol_put(pol);
65593 +fail_nomem_policy:
65594 + kmem_cache_free(vm_area_cachep, tmp);
65595 +fail_nomem:
65596 + vm_unacct_memory(charge);
65597 + return NULL;
65598 +}
65599 +
65600 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
65601 {
65602 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
65603 struct rb_node **rb_link, *rb_parent;
65604 int retval;
65605 - unsigned long charge;
65606 - struct mempolicy *pol;
65607
65608 down_write(&oldmm->mmap_sem);
65609 flush_cache_dup_mm(oldmm);
65610 @@ -328,8 +398,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
65611 mm->locked_vm = 0;
65612 mm->mmap = NULL;
65613 mm->mmap_cache = NULL;
65614 - mm->free_area_cache = oldmm->mmap_base;
65615 - mm->cached_hole_size = ~0UL;
65616 + mm->free_area_cache = oldmm->free_area_cache;
65617 + mm->cached_hole_size = oldmm->cached_hole_size;
65618 mm->map_count = 0;
65619 cpumask_clear(mm_cpumask(mm));
65620 mm->mm_rb = RB_ROOT;
65621 @@ -345,8 +415,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
65622
65623 prev = NULL;
65624 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
65625 - struct file *file;
65626 -
65627 if (mpnt->vm_flags & VM_DONTCOPY) {
65628 long pages = vma_pages(mpnt);
65629 mm->total_vm -= pages;
65630 @@ -354,54 +422,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
65631 -pages);
65632 continue;
65633 }
65634 - charge = 0;
65635 - if (mpnt->vm_flags & VM_ACCOUNT) {
65636 - unsigned long len;
65637 - len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
65638 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
65639 - goto fail_nomem;
65640 - charge = len;
65641 + tmp = dup_vma(mm, oldmm, mpnt);
65642 + if (!tmp) {
65643 + retval = -ENOMEM;
65644 + goto out;
65645 }
65646 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
65647 - if (!tmp)
65648 - goto fail_nomem;
65649 - *tmp = *mpnt;
65650 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
65651 - pol = mpol_dup(vma_policy(mpnt));
65652 - retval = PTR_ERR(pol);
65653 - if (IS_ERR(pol))
65654 - goto fail_nomem_policy;
65655 - vma_set_policy(tmp, pol);
65656 - tmp->vm_mm = mm;
65657 - if (anon_vma_fork(tmp, mpnt))
65658 - goto fail_nomem_anon_vma_fork;
65659 - tmp->vm_flags &= ~VM_LOCKED;
65660 - tmp->vm_next = tmp->vm_prev = NULL;
65661 - file = tmp->vm_file;
65662 - if (file) {
65663 - struct inode *inode = file->f_path.dentry->d_inode;
65664 - struct address_space *mapping = file->f_mapping;
65665 -
65666 - get_file(file);
65667 - if (tmp->vm_flags & VM_DENYWRITE)
65668 - atomic_dec(&inode->i_writecount);
65669 - mutex_lock(&mapping->i_mmap_mutex);
65670 - if (tmp->vm_flags & VM_SHARED)
65671 - mapping->i_mmap_writable++;
65672 - flush_dcache_mmap_lock(mapping);
65673 - /* insert tmp into the share list, just after mpnt */
65674 - vma_prio_tree_add(tmp, mpnt);
65675 - flush_dcache_mmap_unlock(mapping);
65676 - mutex_unlock(&mapping->i_mmap_mutex);
65677 - }
65678 -
65679 - /*
65680 - * Clear hugetlb-related page reserves for children. This only
65681 - * affects MAP_PRIVATE mappings. Faults generated by the child
65682 - * are not guaranteed to succeed, even if read-only
65683 - */
65684 - if (is_vm_hugetlb_page(tmp))
65685 - reset_vma_resv_huge_pages(tmp);
65686
65687 /*
65688 * Link in the new vma and copy the page table entries.
65689 @@ -424,6 +449,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
65690 if (retval)
65691 goto out;
65692 }
65693 +
65694 +#ifdef CONFIG_PAX_SEGMEXEC
65695 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
65696 + struct vm_area_struct *mpnt_m;
65697 +
65698 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
65699 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
65700 +
65701 + if (!mpnt->vm_mirror)
65702 + continue;
65703 +
65704 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
65705 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
65706 + mpnt->vm_mirror = mpnt_m;
65707 + } else {
65708 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
65709 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
65710 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
65711 + mpnt->vm_mirror->vm_mirror = mpnt;
65712 + }
65713 + }
65714 + BUG_ON(mpnt_m);
65715 + }
65716 +#endif
65717 +
65718 /* a new mm has just been created */
65719 arch_dup_mmap(oldmm, mm);
65720 retval = 0;
65721 @@ -432,14 +482,6 @@ out:
65722 flush_tlb_mm(oldmm);
65723 up_write(&oldmm->mmap_sem);
65724 return retval;
65725 -fail_nomem_anon_vma_fork:
65726 - mpol_put(pol);
65727 -fail_nomem_policy:
65728 - kmem_cache_free(vm_area_cachep, tmp);
65729 -fail_nomem:
65730 - retval = -ENOMEM;
65731 - vm_unacct_memory(charge);
65732 - goto out;
65733 }
65734
65735 static inline int mm_alloc_pgd(struct mm_struct *mm)
65736 @@ -676,8 +718,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
65737 return ERR_PTR(err);
65738
65739 mm = get_task_mm(task);
65740 - if (mm && mm != current->mm &&
65741 - !ptrace_may_access(task, mode)) {
65742 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
65743 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
65744 mmput(mm);
65745 mm = ERR_PTR(-EACCES);
65746 }
65747 @@ -899,13 +941,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
65748 spin_unlock(&fs->lock);
65749 return -EAGAIN;
65750 }
65751 - fs->users++;
65752 + atomic_inc(&fs->users);
65753 spin_unlock(&fs->lock);
65754 return 0;
65755 }
65756 tsk->fs = copy_fs_struct(fs);
65757 if (!tsk->fs)
65758 return -ENOMEM;
65759 + gr_set_chroot_entries(tsk, &tsk->fs->root);
65760 return 0;
65761 }
65762
65763 @@ -1172,6 +1215,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
65764 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
65765 #endif
65766 retval = -EAGAIN;
65767 +
65768 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
65769 +
65770 if (atomic_read(&p->real_cred->user->processes) >=
65771 task_rlimit(p, RLIMIT_NPROC)) {
65772 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
65773 @@ -1392,6 +1438,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
65774 /* Need tasklist lock for parent etc handling! */
65775 write_lock_irq(&tasklist_lock);
65776
65777 + /* synchronizes with gr_set_acls() */
65778 + gr_copy_label(p);
65779 +
65780 /* CLONE_PARENT re-uses the old parent */
65781 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
65782 p->real_parent = current->real_parent;
65783 @@ -1502,6 +1551,8 @@ bad_fork_cleanup_count:
65784 bad_fork_free:
65785 free_task(p);
65786 fork_out:
65787 + gr_log_forkfail(retval);
65788 +
65789 return ERR_PTR(retval);
65790 }
65791
65792 @@ -1602,6 +1653,8 @@ long do_fork(unsigned long clone_flags,
65793 if (clone_flags & CLONE_PARENT_SETTID)
65794 put_user(nr, parent_tidptr);
65795
65796 + gr_handle_brute_check();
65797 +
65798 if (clone_flags & CLONE_VFORK) {
65799 p->vfork_done = &vfork;
65800 init_completion(&vfork);
65801 @@ -1700,7 +1753,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
65802 return 0;
65803
65804 /* don't need lock here; in the worst case we'll do useless copy */
65805 - if (fs->users == 1)
65806 + if (atomic_read(&fs->users) == 1)
65807 return 0;
65808
65809 *new_fsp = copy_fs_struct(fs);
65810 @@ -1789,7 +1842,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
65811 fs = current->fs;
65812 spin_lock(&fs->lock);
65813 current->fs = new_fs;
65814 - if (--fs->users)
65815 + gr_set_chroot_entries(current, &current->fs->root);
65816 + if (atomic_dec_return(&fs->users))
65817 new_fs = NULL;
65818 else
65819 new_fs = fs;
65820 diff --git a/kernel/futex.c b/kernel/futex.c
65821 index e2b0fb9..db818ac 100644
65822 --- a/kernel/futex.c
65823 +++ b/kernel/futex.c
65824 @@ -54,6 +54,7 @@
65825 #include <linux/mount.h>
65826 #include <linux/pagemap.h>
65827 #include <linux/syscalls.h>
65828 +#include <linux/ptrace.h>
65829 #include <linux/signal.h>
65830 #include <linux/export.h>
65831 #include <linux/magic.h>
65832 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
65833 struct page *page, *page_head;
65834 int err, ro = 0;
65835
65836 +#ifdef CONFIG_PAX_SEGMEXEC
65837 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
65838 + return -EFAULT;
65839 +#endif
65840 +
65841 /*
65842 * The futex address must be "naturally" aligned.
65843 */
65844 @@ -2711,6 +2717,7 @@ static int __init futex_init(void)
65845 {
65846 u32 curval;
65847 int i;
65848 + mm_segment_t oldfs;
65849
65850 /*
65851 * This will fail and we want it. Some arch implementations do
65852 @@ -2722,8 +2729,11 @@ static int __init futex_init(void)
65853 * implementation, the non-functional ones will return
65854 * -ENOSYS.
65855 */
65856 + oldfs = get_fs();
65857 + set_fs(USER_DS);
65858 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
65859 futex_cmpxchg_enabled = 1;
65860 + set_fs(oldfs);
65861
65862 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
65863 plist_head_init(&futex_queues[i].chain);
65864 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
65865 index 9b22d03..6295b62 100644
65866 --- a/kernel/gcov/base.c
65867 +++ b/kernel/gcov/base.c
65868 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
65869 }
65870
65871 #ifdef CONFIG_MODULES
65872 -static inline int within(void *addr, void *start, unsigned long size)
65873 -{
65874 - return ((addr >= start) && (addr < start + size));
65875 -}
65876 -
65877 /* Update list and generate events when modules are unloaded. */
65878 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
65879 void *data)
65880 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
65881 prev = NULL;
65882 /* Remove entries located in module from linked list. */
65883 for (info = gcov_info_head; info; info = info->next) {
65884 - if (within(info, mod->module_core, mod->core_size)) {
65885 + if (within_module_core_rw((unsigned long)info, mod)) {
65886 if (prev)
65887 prev->next = info->next;
65888 else
65889 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
65890 index 6db7a5e..25b6648 100644
65891 --- a/kernel/hrtimer.c
65892 +++ b/kernel/hrtimer.c
65893 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
65894 local_irq_restore(flags);
65895 }
65896
65897 -static void run_hrtimer_softirq(struct softirq_action *h)
65898 +static void run_hrtimer_softirq(void)
65899 {
65900 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
65901
65902 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
65903 index 4304919..408c4c0 100644
65904 --- a/kernel/jump_label.c
65905 +++ b/kernel/jump_label.c
65906 @@ -13,6 +13,7 @@
65907 #include <linux/sort.h>
65908 #include <linux/err.h>
65909 #include <linux/static_key.h>
65910 +#include <linux/mm.h>
65911
65912 #ifdef HAVE_JUMP_LABEL
65913
65914 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
65915
65916 size = (((unsigned long)stop - (unsigned long)start)
65917 / sizeof(struct jump_entry));
65918 + pax_open_kernel();
65919 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
65920 + pax_close_kernel();
65921 }
65922
65923 static void jump_label_update(struct static_key *key, int enable);
65924 @@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
65925 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
65926 struct jump_entry *iter;
65927
65928 + pax_open_kernel();
65929 for (iter = iter_start; iter < iter_stop; iter++) {
65930 if (within_module_init(iter->code, mod))
65931 iter->code = 0;
65932 }
65933 + pax_close_kernel();
65934 }
65935
65936 static int
65937 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
65938 index 079f1d3..a407562 100644
65939 --- a/kernel/kallsyms.c
65940 +++ b/kernel/kallsyms.c
65941 @@ -11,6 +11,9 @@
65942 * Changed the compression method from stem compression to "table lookup"
65943 * compression (see scripts/kallsyms.c for a more complete description)
65944 */
65945 +#ifdef CONFIG_GRKERNSEC_HIDESYM
65946 +#define __INCLUDED_BY_HIDESYM 1
65947 +#endif
65948 #include <linux/kallsyms.h>
65949 #include <linux/module.h>
65950 #include <linux/init.h>
65951 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
65952
65953 static inline int is_kernel_inittext(unsigned long addr)
65954 {
65955 + if (system_state != SYSTEM_BOOTING)
65956 + return 0;
65957 +
65958 if (addr >= (unsigned long)_sinittext
65959 && addr <= (unsigned long)_einittext)
65960 return 1;
65961 return 0;
65962 }
65963
65964 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
65965 +#ifdef CONFIG_MODULES
65966 +static inline int is_module_text(unsigned long addr)
65967 +{
65968 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
65969 + return 1;
65970 +
65971 + addr = ktla_ktva(addr);
65972 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
65973 +}
65974 +#else
65975 +static inline int is_module_text(unsigned long addr)
65976 +{
65977 + return 0;
65978 +}
65979 +#endif
65980 +#endif
65981 +
65982 static inline int is_kernel_text(unsigned long addr)
65983 {
65984 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
65985 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
65986
65987 static inline int is_kernel(unsigned long addr)
65988 {
65989 +
65990 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
65991 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
65992 + return 1;
65993 +
65994 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
65995 +#else
65996 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
65997 +#endif
65998 +
65999 return 1;
66000 return in_gate_area_no_mm(addr);
66001 }
66002
66003 static int is_ksym_addr(unsigned long addr)
66004 {
66005 +
66006 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66007 + if (is_module_text(addr))
66008 + return 0;
66009 +#endif
66010 +
66011 if (all_var)
66012 return is_kernel(addr);
66013
66014 @@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
66015
66016 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
66017 {
66018 - iter->name[0] = '\0';
66019 iter->nameoff = get_symbol_offset(new_pos);
66020 iter->pos = new_pos;
66021 }
66022 @@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, void *p)
66023 {
66024 struct kallsym_iter *iter = m->private;
66025
66026 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66027 + if (current_uid())
66028 + return 0;
66029 +#endif
66030 +
66031 /* Some debugging symbols have no name. Ignore them. */
66032 if (!iter->name[0])
66033 return 0;
66034 @@ -540,7 +583,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
66035 struct kallsym_iter *iter;
66036 int ret;
66037
66038 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
66039 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
66040 if (!iter)
66041 return -ENOMEM;
66042 reset_iter(iter, 0);
66043 diff --git a/kernel/kexec.c b/kernel/kexec.c
66044 index 4e2e472..cd0c7ae 100644
66045 --- a/kernel/kexec.c
66046 +++ b/kernel/kexec.c
66047 @@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
66048 unsigned long flags)
66049 {
66050 struct compat_kexec_segment in;
66051 - struct kexec_segment out, __user *ksegments;
66052 + struct kexec_segment out;
66053 + struct kexec_segment __user *ksegments;
66054 unsigned long i, result;
66055
66056 /* Don't allow clients that don't understand the native
66057 diff --git a/kernel/kmod.c b/kernel/kmod.c
66058 index 05698a7..a4c1e3a 100644
66059 --- a/kernel/kmod.c
66060 +++ b/kernel/kmod.c
66061 @@ -66,7 +66,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
66062 kfree(info->argv);
66063 }
66064
66065 -static int call_modprobe(char *module_name, int wait)
66066 +static int call_modprobe(char *module_name, char *module_param, int wait)
66067 {
66068 static char *envp[] = {
66069 "HOME=/",
66070 @@ -75,7 +75,7 @@ static int call_modprobe(char *module_name, int wait)
66071 NULL
66072 };
66073
66074 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
66075 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
66076 if (!argv)
66077 goto out;
66078
66079 @@ -87,7 +87,8 @@ static int call_modprobe(char *module_name, int wait)
66080 argv[1] = "-q";
66081 argv[2] = "--";
66082 argv[3] = module_name; /* check free_modprobe_argv() */
66083 - argv[4] = NULL;
66084 + argv[4] = module_param;
66085 + argv[5] = NULL;
66086
66087 return call_usermodehelper_fns(modprobe_path, argv, envp,
66088 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
66089 @@ -112,9 +113,8 @@ out:
66090 * If module auto-loading support is disabled then this function
66091 * becomes a no-operation.
66092 */
66093 -int __request_module(bool wait, const char *fmt, ...)
66094 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
66095 {
66096 - va_list args;
66097 char module_name[MODULE_NAME_LEN];
66098 unsigned int max_modprobes;
66099 int ret;
66100 @@ -122,9 +122,7 @@ int __request_module(bool wait, const char *fmt, ...)
66101 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
66102 static int kmod_loop_msg;
66103
66104 - va_start(args, fmt);
66105 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
66106 - va_end(args);
66107 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
66108 if (ret >= MODULE_NAME_LEN)
66109 return -ENAMETOOLONG;
66110
66111 @@ -132,6 +130,20 @@ int __request_module(bool wait, const char *fmt, ...)
66112 if (ret)
66113 return ret;
66114
66115 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66116 + if (!current_uid()) {
66117 + /* hack to workaround consolekit/udisks stupidity */
66118 + read_lock(&tasklist_lock);
66119 + if (!strcmp(current->comm, "mount") &&
66120 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
66121 + read_unlock(&tasklist_lock);
66122 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
66123 + return -EPERM;
66124 + }
66125 + read_unlock(&tasklist_lock);
66126 + }
66127 +#endif
66128 +
66129 /* If modprobe needs a service that is in a module, we get a recursive
66130 * loop. Limit the number of running kmod threads to max_threads/2 or
66131 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
66132 @@ -160,11 +172,52 @@ int __request_module(bool wait, const char *fmt, ...)
66133
66134 trace_module_request(module_name, wait, _RET_IP_);
66135
66136 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
66137 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
66138
66139 atomic_dec(&kmod_concurrent);
66140 return ret;
66141 }
66142 +
66143 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
66144 +{
66145 + va_list args;
66146 + int ret;
66147 +
66148 + va_start(args, fmt);
66149 + ret = ____request_module(wait, module_param, fmt, args);
66150 + va_end(args);
66151 +
66152 + return ret;
66153 +}
66154 +
66155 +int __request_module(bool wait, const char *fmt, ...)
66156 +{
66157 + va_list args;
66158 + int ret;
66159 +
66160 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66161 + if (current_uid()) {
66162 + char module_param[MODULE_NAME_LEN];
66163 +
66164 + memset(module_param, 0, sizeof(module_param));
66165 +
66166 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
66167 +
66168 + va_start(args, fmt);
66169 + ret = ____request_module(wait, module_param, fmt, args);
66170 + va_end(args);
66171 +
66172 + return ret;
66173 + }
66174 +#endif
66175 +
66176 + va_start(args, fmt);
66177 + ret = ____request_module(wait, NULL, fmt, args);
66178 + va_end(args);
66179 +
66180 + return ret;
66181 +}
66182 +
66183 EXPORT_SYMBOL(__request_module);
66184 #endif /* CONFIG_MODULES */
66185
66186 @@ -267,7 +320,7 @@ static int wait_for_helper(void *data)
66187 *
66188 * Thus the __user pointer cast is valid here.
66189 */
66190 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
66191 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
66192
66193 /*
66194 * If ret is 0, either ____call_usermodehelper failed and the
66195 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
66196 index c62b854..cb67968 100644
66197 --- a/kernel/kprobes.c
66198 +++ b/kernel/kprobes.c
66199 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
66200 * kernel image and loaded module images reside. This is required
66201 * so x86_64 can correctly handle the %rip-relative fixups.
66202 */
66203 - kip->insns = module_alloc(PAGE_SIZE);
66204 + kip->insns = module_alloc_exec(PAGE_SIZE);
66205 if (!kip->insns) {
66206 kfree(kip);
66207 return NULL;
66208 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
66209 */
66210 if (!list_is_singular(&kip->list)) {
66211 list_del(&kip->list);
66212 - module_free(NULL, kip->insns);
66213 + module_free_exec(NULL, kip->insns);
66214 kfree(kip);
66215 }
66216 return 1;
66217 @@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
66218 {
66219 int i, err = 0;
66220 unsigned long offset = 0, size = 0;
66221 - char *modname, namebuf[128];
66222 + char *modname, namebuf[KSYM_NAME_LEN];
66223 const char *symbol_name;
66224 void *addr;
66225 struct kprobe_blackpoint *kb;
66226 @@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
66227 const char *sym = NULL;
66228 unsigned int i = *(loff_t *) v;
66229 unsigned long offset = 0;
66230 - char *modname, namebuf[128];
66231 + char *modname, namebuf[KSYM_NAME_LEN];
66232
66233 head = &kprobe_table[i];
66234 preempt_disable();
66235 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
66236 index 4e316e1..5501eef 100644
66237 --- a/kernel/ksysfs.c
66238 +++ b/kernel/ksysfs.c
66239 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
66240 {
66241 if (count+1 > UEVENT_HELPER_PATH_LEN)
66242 return -ENOENT;
66243 + if (!capable(CAP_SYS_ADMIN))
66244 + return -EPERM;
66245 memcpy(uevent_helper, buf, count);
66246 uevent_helper[count] = '\0';
66247 if (count && uevent_helper[count-1] == '\n')
66248 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
66249 index ea9ee45..67ebc8f 100644
66250 --- a/kernel/lockdep.c
66251 +++ b/kernel/lockdep.c
66252 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
66253 end = (unsigned long) &_end,
66254 addr = (unsigned long) obj;
66255
66256 +#ifdef CONFIG_PAX_KERNEXEC
66257 + start = ktla_ktva(start);
66258 +#endif
66259 +
66260 /*
66261 * static variable?
66262 */
66263 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
66264 if (!static_obj(lock->key)) {
66265 debug_locks_off();
66266 printk("INFO: trying to register non-static key.\n");
66267 + printk("lock:%pS key:%pS.\n", lock, lock->key);
66268 printk("the code is fine but needs lockdep annotation.\n");
66269 printk("turning off the locking correctness validator.\n");
66270 dump_stack();
66271 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
66272 if (!class)
66273 return 0;
66274 }
66275 - atomic_inc((atomic_t *)&class->ops);
66276 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
66277 if (very_verbose(class)) {
66278 printk("\nacquire class [%p] %s", class->key, class->name);
66279 if (class->name_version > 1)
66280 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
66281 index 91c32a0..b2c71c5 100644
66282 --- a/kernel/lockdep_proc.c
66283 +++ b/kernel/lockdep_proc.c
66284 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
66285
66286 static void print_name(struct seq_file *m, struct lock_class *class)
66287 {
66288 - char str[128];
66289 + char str[KSYM_NAME_LEN];
66290 const char *name = class->name;
66291
66292 if (!name) {
66293 diff --git a/kernel/module.c b/kernel/module.c
66294 index 78ac6ec..e87db0e 100644
66295 --- a/kernel/module.c
66296 +++ b/kernel/module.c
66297 @@ -58,6 +58,7 @@
66298 #include <linux/jump_label.h>
66299 #include <linux/pfn.h>
66300 #include <linux/bsearch.h>
66301 +#include <linux/grsecurity.h>
66302
66303 #define CREATE_TRACE_POINTS
66304 #include <trace/events/module.h>
66305 @@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
66306
66307 /* Bounds of module allocation, for speeding __module_address.
66308 * Protected by module_mutex. */
66309 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
66310 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
66311 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
66312
66313 int register_module_notifier(struct notifier_block * nb)
66314 {
66315 @@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
66316 return true;
66317
66318 list_for_each_entry_rcu(mod, &modules, list) {
66319 - struct symsearch arr[] = {
66320 + struct symsearch modarr[] = {
66321 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
66322 NOT_GPL_ONLY, false },
66323 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
66324 @@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
66325 #endif
66326 };
66327
66328 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
66329 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
66330 return true;
66331 }
66332 return false;
66333 @@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
66334 static int percpu_modalloc(struct module *mod,
66335 unsigned long size, unsigned long align)
66336 {
66337 - if (align > PAGE_SIZE) {
66338 + if (align-1 >= PAGE_SIZE) {
66339 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
66340 mod->name, align, PAGE_SIZE);
66341 align = PAGE_SIZE;
66342 @@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
66343 static ssize_t show_coresize(struct module_attribute *mattr,
66344 struct module_kobject *mk, char *buffer)
66345 {
66346 - return sprintf(buffer, "%u\n", mk->mod->core_size);
66347 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
66348 }
66349
66350 static struct module_attribute modinfo_coresize =
66351 @@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
66352 static ssize_t show_initsize(struct module_attribute *mattr,
66353 struct module_kobject *mk, char *buffer)
66354 {
66355 - return sprintf(buffer, "%u\n", mk->mod->init_size);
66356 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
66357 }
66358
66359 static struct module_attribute modinfo_initsize =
66360 @@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
66361 */
66362 #ifdef CONFIG_SYSFS
66363
66364 -#ifdef CONFIG_KALLSYMS
66365 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66366 static inline bool sect_empty(const Elf_Shdr *sect)
66367 {
66368 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
66369 @@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
66370
66371 static void unset_module_core_ro_nx(struct module *mod)
66372 {
66373 - set_page_attributes(mod->module_core + mod->core_text_size,
66374 - mod->module_core + mod->core_size,
66375 + set_page_attributes(mod->module_core_rw,
66376 + mod->module_core_rw + mod->core_size_rw,
66377 set_memory_x);
66378 - set_page_attributes(mod->module_core,
66379 - mod->module_core + mod->core_ro_size,
66380 + set_page_attributes(mod->module_core_rx,
66381 + mod->module_core_rx + mod->core_size_rx,
66382 set_memory_rw);
66383 }
66384
66385 static void unset_module_init_ro_nx(struct module *mod)
66386 {
66387 - set_page_attributes(mod->module_init + mod->init_text_size,
66388 - mod->module_init + mod->init_size,
66389 + set_page_attributes(mod->module_init_rw,
66390 + mod->module_init_rw + mod->init_size_rw,
66391 set_memory_x);
66392 - set_page_attributes(mod->module_init,
66393 - mod->module_init + mod->init_ro_size,
66394 + set_page_attributes(mod->module_init_rx,
66395 + mod->module_init_rx + mod->init_size_rx,
66396 set_memory_rw);
66397 }
66398
66399 @@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
66400
66401 mutex_lock(&module_mutex);
66402 list_for_each_entry_rcu(mod, &modules, list) {
66403 - if ((mod->module_core) && (mod->core_text_size)) {
66404 - set_page_attributes(mod->module_core,
66405 - mod->module_core + mod->core_text_size,
66406 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
66407 + set_page_attributes(mod->module_core_rx,
66408 + mod->module_core_rx + mod->core_size_rx,
66409 set_memory_rw);
66410 }
66411 - if ((mod->module_init) && (mod->init_text_size)) {
66412 - set_page_attributes(mod->module_init,
66413 - mod->module_init + mod->init_text_size,
66414 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
66415 + set_page_attributes(mod->module_init_rx,
66416 + mod->module_init_rx + mod->init_size_rx,
66417 set_memory_rw);
66418 }
66419 }
66420 @@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
66421
66422 mutex_lock(&module_mutex);
66423 list_for_each_entry_rcu(mod, &modules, list) {
66424 - if ((mod->module_core) && (mod->core_text_size)) {
66425 - set_page_attributes(mod->module_core,
66426 - mod->module_core + mod->core_text_size,
66427 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
66428 + set_page_attributes(mod->module_core_rx,
66429 + mod->module_core_rx + mod->core_size_rx,
66430 set_memory_ro);
66431 }
66432 - if ((mod->module_init) && (mod->init_text_size)) {
66433 - set_page_attributes(mod->module_init,
66434 - mod->module_init + mod->init_text_size,
66435 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
66436 + set_page_attributes(mod->module_init_rx,
66437 + mod->module_init_rx + mod->init_size_rx,
66438 set_memory_ro);
66439 }
66440 }
66441 @@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
66442
66443 /* This may be NULL, but that's OK */
66444 unset_module_init_ro_nx(mod);
66445 - module_free(mod, mod->module_init);
66446 + module_free(mod, mod->module_init_rw);
66447 + module_free_exec(mod, mod->module_init_rx);
66448 kfree(mod->args);
66449 percpu_modfree(mod);
66450
66451 /* Free lock-classes: */
66452 - lockdep_free_key_range(mod->module_core, mod->core_size);
66453 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
66454 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
66455
66456 /* Finally, free the core (containing the module structure) */
66457 unset_module_core_ro_nx(mod);
66458 - module_free(mod, mod->module_core);
66459 + module_free_exec(mod, mod->module_core_rx);
66460 + module_free(mod, mod->module_core_rw);
66461
66462 #ifdef CONFIG_MPU
66463 update_protections(current->mm);
66464 @@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66465 int ret = 0;
66466 const struct kernel_symbol *ksym;
66467
66468 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66469 + int is_fs_load = 0;
66470 + int register_filesystem_found = 0;
66471 + char *p;
66472 +
66473 + p = strstr(mod->args, "grsec_modharden_fs");
66474 + if (p) {
66475 + char *endptr = p + strlen("grsec_modharden_fs");
66476 + /* copy \0 as well */
66477 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
66478 + is_fs_load = 1;
66479 + }
66480 +#endif
66481 +
66482 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
66483 const char *name = info->strtab + sym[i].st_name;
66484
66485 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66486 + /* it's a real shame this will never get ripped and copied
66487 + upstream! ;(
66488 + */
66489 + if (is_fs_load && !strcmp(name, "register_filesystem"))
66490 + register_filesystem_found = 1;
66491 +#endif
66492 +
66493 switch (sym[i].st_shndx) {
66494 case SHN_COMMON:
66495 /* We compiled with -fno-common. These are not
66496 @@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66497 ksym = resolve_symbol_wait(mod, info, name);
66498 /* Ok if resolved. */
66499 if (ksym && !IS_ERR(ksym)) {
66500 + pax_open_kernel();
66501 sym[i].st_value = ksym->value;
66502 + pax_close_kernel();
66503 break;
66504 }
66505
66506 @@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66507 secbase = (unsigned long)mod_percpu(mod);
66508 else
66509 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
66510 + pax_open_kernel();
66511 sym[i].st_value += secbase;
66512 + pax_close_kernel();
66513 break;
66514 }
66515 }
66516
66517 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66518 + if (is_fs_load && !register_filesystem_found) {
66519 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
66520 + ret = -EPERM;
66521 + }
66522 +#endif
66523 +
66524 return ret;
66525 }
66526
66527 @@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
66528 || s->sh_entsize != ~0UL
66529 || strstarts(sname, ".init"))
66530 continue;
66531 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
66532 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
66533 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
66534 + else
66535 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
66536 pr_debug("\t%s\n", sname);
66537 }
66538 - switch (m) {
66539 - case 0: /* executable */
66540 - mod->core_size = debug_align(mod->core_size);
66541 - mod->core_text_size = mod->core_size;
66542 - break;
66543 - case 1: /* RO: text and ro-data */
66544 - mod->core_size = debug_align(mod->core_size);
66545 - mod->core_ro_size = mod->core_size;
66546 - break;
66547 - case 3: /* whole core */
66548 - mod->core_size = debug_align(mod->core_size);
66549 - break;
66550 - }
66551 }
66552
66553 pr_debug("Init section allocation order:\n");
66554 @@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
66555 || s->sh_entsize != ~0UL
66556 || !strstarts(sname, ".init"))
66557 continue;
66558 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
66559 - | INIT_OFFSET_MASK);
66560 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
66561 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
66562 + else
66563 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
66564 + s->sh_entsize |= INIT_OFFSET_MASK;
66565 pr_debug("\t%s\n", sname);
66566 }
66567 - switch (m) {
66568 - case 0: /* executable */
66569 - mod->init_size = debug_align(mod->init_size);
66570 - mod->init_text_size = mod->init_size;
66571 - break;
66572 - case 1: /* RO: text and ro-data */
66573 - mod->init_size = debug_align(mod->init_size);
66574 - mod->init_ro_size = mod->init_size;
66575 - break;
66576 - case 3: /* whole init */
66577 - mod->init_size = debug_align(mod->init_size);
66578 - break;
66579 - }
66580 }
66581 }
66582
66583 @@ -2266,7 +2284,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
66584
66585 /* Put symbol section at end of init part of module. */
66586 symsect->sh_flags |= SHF_ALLOC;
66587 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
66588 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
66589 info->index.sym) | INIT_OFFSET_MASK;
66590 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
66591
66592 @@ -2281,13 +2299,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
66593 }
66594
66595 /* Append room for core symbols at end of core part. */
66596 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
66597 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
66598 - mod->core_size += strtab_size;
66599 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
66600 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
66601 + mod->core_size_rx += strtab_size;
66602
66603 /* Put string table section at end of init part of module. */
66604 strsect->sh_flags |= SHF_ALLOC;
66605 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
66606 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
66607 info->index.str) | INIT_OFFSET_MASK;
66608 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
66609 }
66610 @@ -2305,12 +2323,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
66611 /* Make sure we get permanent strtab: don't use info->strtab. */
66612 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
66613
66614 + pax_open_kernel();
66615 +
66616 /* Set types up while we still have access to sections. */
66617 for (i = 0; i < mod->num_symtab; i++)
66618 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
66619
66620 - mod->core_symtab = dst = mod->module_core + info->symoffs;
66621 - mod->core_strtab = s = mod->module_core + info->stroffs;
66622 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
66623 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
66624 src = mod->symtab;
66625 *dst = *src;
66626 *s++ = 0;
66627 @@ -2323,6 +2343,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
66628 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
66629 }
66630 mod->core_num_syms = ndst;
66631 +
66632 + pax_close_kernel();
66633 }
66634 #else
66635 static inline void layout_symtab(struct module *mod, struct load_info *info)
66636 @@ -2356,17 +2378,33 @@ void * __weak module_alloc(unsigned long size)
66637 return size == 0 ? NULL : vmalloc_exec(size);
66638 }
66639
66640 -static void *module_alloc_update_bounds(unsigned long size)
66641 +static void *module_alloc_update_bounds_rw(unsigned long size)
66642 {
66643 void *ret = module_alloc(size);
66644
66645 if (ret) {
66646 mutex_lock(&module_mutex);
66647 /* Update module bounds. */
66648 - if ((unsigned long)ret < module_addr_min)
66649 - module_addr_min = (unsigned long)ret;
66650 - if ((unsigned long)ret + size > module_addr_max)
66651 - module_addr_max = (unsigned long)ret + size;
66652 + if ((unsigned long)ret < module_addr_min_rw)
66653 + module_addr_min_rw = (unsigned long)ret;
66654 + if ((unsigned long)ret + size > module_addr_max_rw)
66655 + module_addr_max_rw = (unsigned long)ret + size;
66656 + mutex_unlock(&module_mutex);
66657 + }
66658 + return ret;
66659 +}
66660 +
66661 +static void *module_alloc_update_bounds_rx(unsigned long size)
66662 +{
66663 + void *ret = module_alloc_exec(size);
66664 +
66665 + if (ret) {
66666 + mutex_lock(&module_mutex);
66667 + /* Update module bounds. */
66668 + if ((unsigned long)ret < module_addr_min_rx)
66669 + module_addr_min_rx = (unsigned long)ret;
66670 + if ((unsigned long)ret + size > module_addr_max_rx)
66671 + module_addr_max_rx = (unsigned long)ret + size;
66672 mutex_unlock(&module_mutex);
66673 }
66674 return ret;
66675 @@ -2543,8 +2581,14 @@ static struct module *setup_load_info(struct load_info *info)
66676 static int check_modinfo(struct module *mod, struct load_info *info)
66677 {
66678 const char *modmagic = get_modinfo(info, "vermagic");
66679 + const char *license = get_modinfo(info, "license");
66680 int err;
66681
66682 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
66683 + if (!license || !license_is_gpl_compatible(license))
66684 + return -ENOEXEC;
66685 +#endif
66686 +
66687 /* This is allowed: modprobe --force will invalidate it. */
66688 if (!modmagic) {
66689 err = try_to_force_load(mod, "bad vermagic");
66690 @@ -2567,7 +2611,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
66691 }
66692
66693 /* Set up license info based on the info section */
66694 - set_license(mod, get_modinfo(info, "license"));
66695 + set_license(mod, license);
66696
66697 return 0;
66698 }
66699 @@ -2661,7 +2705,7 @@ static int move_module(struct module *mod, struct load_info *info)
66700 void *ptr;
66701
66702 /* Do the allocs. */
66703 - ptr = module_alloc_update_bounds(mod->core_size);
66704 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
66705 /*
66706 * The pointer to this block is stored in the module structure
66707 * which is inside the block. Just mark it as not being a
66708 @@ -2671,23 +2715,50 @@ static int move_module(struct module *mod, struct load_info *info)
66709 if (!ptr)
66710 return -ENOMEM;
66711
66712 - memset(ptr, 0, mod->core_size);
66713 - mod->module_core = ptr;
66714 + memset(ptr, 0, mod->core_size_rw);
66715 + mod->module_core_rw = ptr;
66716
66717 - ptr = module_alloc_update_bounds(mod->init_size);
66718 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
66719 /*
66720 * The pointer to this block is stored in the module structure
66721 * which is inside the block. This block doesn't need to be
66722 * scanned as it contains data and code that will be freed
66723 * after the module is initialized.
66724 */
66725 - kmemleak_ignore(ptr);
66726 - if (!ptr && mod->init_size) {
66727 - module_free(mod, mod->module_core);
66728 + kmemleak_not_leak(ptr);
66729 + if (!ptr && mod->init_size_rw) {
66730 + module_free(mod, mod->module_core_rw);
66731 return -ENOMEM;
66732 }
66733 - memset(ptr, 0, mod->init_size);
66734 - mod->module_init = ptr;
66735 + memset(ptr, 0, mod->init_size_rw);
66736 + mod->module_init_rw = ptr;
66737 +
66738 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
66739 + kmemleak_not_leak(ptr);
66740 + if (!ptr) {
66741 + module_free(mod, mod->module_init_rw);
66742 + module_free(mod, mod->module_core_rw);
66743 + return -ENOMEM;
66744 + }
66745 +
66746 + pax_open_kernel();
66747 + memset(ptr, 0, mod->core_size_rx);
66748 + pax_close_kernel();
66749 + mod->module_core_rx = ptr;
66750 +
66751 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
66752 + kmemleak_not_leak(ptr);
66753 + if (!ptr && mod->init_size_rx) {
66754 + module_free_exec(mod, mod->module_core_rx);
66755 + module_free(mod, mod->module_init_rw);
66756 + module_free(mod, mod->module_core_rw);
66757 + return -ENOMEM;
66758 + }
66759 +
66760 + pax_open_kernel();
66761 + memset(ptr, 0, mod->init_size_rx);
66762 + pax_close_kernel();
66763 + mod->module_init_rx = ptr;
66764
66765 /* Transfer each section which specifies SHF_ALLOC */
66766 pr_debug("final section addresses:\n");
66767 @@ -2698,16 +2769,45 @@ static int move_module(struct module *mod, struct load_info *info)
66768 if (!(shdr->sh_flags & SHF_ALLOC))
66769 continue;
66770
66771 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
66772 - dest = mod->module_init
66773 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
66774 - else
66775 - dest = mod->module_core + shdr->sh_entsize;
66776 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
66777 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
66778 + dest = mod->module_init_rw
66779 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
66780 + else
66781 + dest = mod->module_init_rx
66782 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
66783 + } else {
66784 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
66785 + dest = mod->module_core_rw + shdr->sh_entsize;
66786 + else
66787 + dest = mod->module_core_rx + shdr->sh_entsize;
66788 + }
66789 +
66790 + if (shdr->sh_type != SHT_NOBITS) {
66791 +
66792 +#ifdef CONFIG_PAX_KERNEXEC
66793 +#ifdef CONFIG_X86_64
66794 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
66795 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
66796 +#endif
66797 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
66798 + pax_open_kernel();
66799 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
66800 + pax_close_kernel();
66801 + } else
66802 +#endif
66803
66804 - if (shdr->sh_type != SHT_NOBITS)
66805 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
66806 + }
66807 /* Update sh_addr to point to copy in image. */
66808 - shdr->sh_addr = (unsigned long)dest;
66809 +
66810 +#ifdef CONFIG_PAX_KERNEXEC
66811 + if (shdr->sh_flags & SHF_EXECINSTR)
66812 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
66813 + else
66814 +#endif
66815 +
66816 + shdr->sh_addr = (unsigned long)dest;
66817 pr_debug("\t0x%lx %s\n",
66818 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
66819 }
66820 @@ -2758,12 +2858,12 @@ static void flush_module_icache(const struct module *mod)
66821 * Do it before processing of module parameters, so the module
66822 * can provide parameter accessor functions of its own.
66823 */
66824 - if (mod->module_init)
66825 - flush_icache_range((unsigned long)mod->module_init,
66826 - (unsigned long)mod->module_init
66827 - + mod->init_size);
66828 - flush_icache_range((unsigned long)mod->module_core,
66829 - (unsigned long)mod->module_core + mod->core_size);
66830 + if (mod->module_init_rx)
66831 + flush_icache_range((unsigned long)mod->module_init_rx,
66832 + (unsigned long)mod->module_init_rx
66833 + + mod->init_size_rx);
66834 + flush_icache_range((unsigned long)mod->module_core_rx,
66835 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
66836
66837 set_fs(old_fs);
66838 }
66839 @@ -2833,8 +2933,10 @@ out:
66840 static void module_deallocate(struct module *mod, struct load_info *info)
66841 {
66842 percpu_modfree(mod);
66843 - module_free(mod, mod->module_init);
66844 - module_free(mod, mod->module_core);
66845 + module_free_exec(mod, mod->module_init_rx);
66846 + module_free_exec(mod, mod->module_core_rx);
66847 + module_free(mod, mod->module_init_rw);
66848 + module_free(mod, mod->module_core_rw);
66849 }
66850
66851 int __weak module_finalize(const Elf_Ehdr *hdr,
66852 @@ -2898,9 +3000,38 @@ static struct module *load_module(void __user *umod,
66853 if (err)
66854 goto free_unload;
66855
66856 + /* Now copy in args */
66857 + mod->args = strndup_user(uargs, ~0UL >> 1);
66858 + if (IS_ERR(mod->args)) {
66859 + err = PTR_ERR(mod->args);
66860 + goto free_unload;
66861 + }
66862 +
66863 /* Set up MODINFO_ATTR fields */
66864 setup_modinfo(mod, &info);
66865
66866 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66867 + {
66868 + char *p, *p2;
66869 +
66870 + if (strstr(mod->args, "grsec_modharden_netdev")) {
66871 + 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);
66872 + err = -EPERM;
66873 + goto free_modinfo;
66874 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
66875 + p += strlen("grsec_modharden_normal");
66876 + p2 = strstr(p, "_");
66877 + if (p2) {
66878 + *p2 = '\0';
66879 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
66880 + *p2 = '_';
66881 + }
66882 + err = -EPERM;
66883 + goto free_modinfo;
66884 + }
66885 + }
66886 +#endif
66887 +
66888 /* Fix up syms, so that st_value is a pointer to location. */
66889 err = simplify_symbols(mod, &info);
66890 if (err < 0)
66891 @@ -2916,13 +3047,6 @@ static struct module *load_module(void __user *umod,
66892
66893 flush_module_icache(mod);
66894
66895 - /* Now copy in args */
66896 - mod->args = strndup_user(uargs, ~0UL >> 1);
66897 - if (IS_ERR(mod->args)) {
66898 - err = PTR_ERR(mod->args);
66899 - goto free_arch_cleanup;
66900 - }
66901 -
66902 /* Mark state as coming so strong_try_module_get() ignores us. */
66903 mod->state = MODULE_STATE_COMING;
66904
66905 @@ -2980,11 +3104,10 @@ static struct module *load_module(void __user *umod,
66906 unlock:
66907 mutex_unlock(&module_mutex);
66908 synchronize_sched();
66909 - kfree(mod->args);
66910 - free_arch_cleanup:
66911 module_arch_cleanup(mod);
66912 free_modinfo:
66913 free_modinfo(mod);
66914 + kfree(mod->args);
66915 free_unload:
66916 module_unload_free(mod);
66917 free_module:
66918 @@ -3025,16 +3148,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
66919 MODULE_STATE_COMING, mod);
66920
66921 /* Set RO and NX regions for core */
66922 - set_section_ro_nx(mod->module_core,
66923 - mod->core_text_size,
66924 - mod->core_ro_size,
66925 - mod->core_size);
66926 + set_section_ro_nx(mod->module_core_rx,
66927 + mod->core_size_rx,
66928 + mod->core_size_rx,
66929 + mod->core_size_rx);
66930
66931 /* Set RO and NX regions for init */
66932 - set_section_ro_nx(mod->module_init,
66933 - mod->init_text_size,
66934 - mod->init_ro_size,
66935 - mod->init_size);
66936 + set_section_ro_nx(mod->module_init_rx,
66937 + mod->init_size_rx,
66938 + mod->init_size_rx,
66939 + mod->init_size_rx);
66940
66941 do_mod_ctors(mod);
66942 /* Start the module */
66943 @@ -3080,11 +3203,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
66944 mod->strtab = mod->core_strtab;
66945 #endif
66946 unset_module_init_ro_nx(mod);
66947 - module_free(mod, mod->module_init);
66948 - mod->module_init = NULL;
66949 - mod->init_size = 0;
66950 - mod->init_ro_size = 0;
66951 - mod->init_text_size = 0;
66952 + module_free(mod, mod->module_init_rw);
66953 + module_free_exec(mod, mod->module_init_rx);
66954 + mod->module_init_rw = NULL;
66955 + mod->module_init_rx = NULL;
66956 + mod->init_size_rw = 0;
66957 + mod->init_size_rx = 0;
66958 mutex_unlock(&module_mutex);
66959
66960 return 0;
66961 @@ -3115,10 +3239,16 @@ static const char *get_ksymbol(struct module *mod,
66962 unsigned long nextval;
66963
66964 /* At worse, next value is at end of module */
66965 - if (within_module_init(addr, mod))
66966 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
66967 + if (within_module_init_rx(addr, mod))
66968 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
66969 + else if (within_module_init_rw(addr, mod))
66970 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
66971 + else if (within_module_core_rx(addr, mod))
66972 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
66973 + else if (within_module_core_rw(addr, mod))
66974 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
66975 else
66976 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
66977 + return NULL;
66978
66979 /* Scan for closest preceding symbol, and next symbol. (ELF
66980 starts real symbols at 1). */
66981 @@ -3353,7 +3483,7 @@ static int m_show(struct seq_file *m, void *p)
66982 char buf[8];
66983
66984 seq_printf(m, "%s %u",
66985 - mod->name, mod->init_size + mod->core_size);
66986 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
66987 print_unload_info(m, mod);
66988
66989 /* Informative for users. */
66990 @@ -3362,7 +3492,7 @@ static int m_show(struct seq_file *m, void *p)
66991 mod->state == MODULE_STATE_COMING ? "Loading":
66992 "Live");
66993 /* Used by oprofile and other similar tools. */
66994 - seq_printf(m, " 0x%pK", mod->module_core);
66995 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
66996
66997 /* Taints info */
66998 if (mod->taints)
66999 @@ -3398,7 +3528,17 @@ static const struct file_operations proc_modules_operations = {
67000
67001 static int __init proc_modules_init(void)
67002 {
67003 +#ifndef CONFIG_GRKERNSEC_HIDESYM
67004 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67005 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67006 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67007 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
67008 +#else
67009 proc_create("modules", 0, NULL, &proc_modules_operations);
67010 +#endif
67011 +#else
67012 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67013 +#endif
67014 return 0;
67015 }
67016 module_init(proc_modules_init);
67017 @@ -3457,12 +3597,12 @@ struct module *__module_address(unsigned long addr)
67018 {
67019 struct module *mod;
67020
67021 - if (addr < module_addr_min || addr > module_addr_max)
67022 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
67023 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
67024 return NULL;
67025
67026 list_for_each_entry_rcu(mod, &modules, list)
67027 - if (within_module_core(addr, mod)
67028 - || within_module_init(addr, mod))
67029 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
67030 return mod;
67031 return NULL;
67032 }
67033 @@ -3496,11 +3636,20 @@ bool is_module_text_address(unsigned long addr)
67034 */
67035 struct module *__module_text_address(unsigned long addr)
67036 {
67037 - struct module *mod = __module_address(addr);
67038 + struct module *mod;
67039 +
67040 +#ifdef CONFIG_X86_32
67041 + addr = ktla_ktva(addr);
67042 +#endif
67043 +
67044 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
67045 + return NULL;
67046 +
67047 + mod = __module_address(addr);
67048 +
67049 if (mod) {
67050 /* Make sure it's within the text section. */
67051 - if (!within(addr, mod->module_init, mod->init_text_size)
67052 - && !within(addr, mod->module_core, mod->core_text_size))
67053 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
67054 mod = NULL;
67055 }
67056 return mod;
67057 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
67058 index 7e3443f..b2a1e6b 100644
67059 --- a/kernel/mutex-debug.c
67060 +++ b/kernel/mutex-debug.c
67061 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
67062 }
67063
67064 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67065 - struct thread_info *ti)
67066 + struct task_struct *task)
67067 {
67068 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
67069
67070 /* Mark the current thread as blocked on the lock: */
67071 - ti->task->blocked_on = waiter;
67072 + task->blocked_on = waiter;
67073 }
67074
67075 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67076 - struct thread_info *ti)
67077 + struct task_struct *task)
67078 {
67079 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
67080 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
67081 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
67082 - ti->task->blocked_on = NULL;
67083 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
67084 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
67085 + task->blocked_on = NULL;
67086
67087 list_del_init(&waiter->list);
67088 waiter->task = NULL;
67089 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
67090 index 0799fd3..d06ae3b 100644
67091 --- a/kernel/mutex-debug.h
67092 +++ b/kernel/mutex-debug.h
67093 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
67094 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
67095 extern void debug_mutex_add_waiter(struct mutex *lock,
67096 struct mutex_waiter *waiter,
67097 - struct thread_info *ti);
67098 + struct task_struct *task);
67099 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67100 - struct thread_info *ti);
67101 + struct task_struct *task);
67102 extern void debug_mutex_unlock(struct mutex *lock);
67103 extern void debug_mutex_init(struct mutex *lock, const char *name,
67104 struct lock_class_key *key);
67105 diff --git a/kernel/mutex.c b/kernel/mutex.c
67106 index a307cc9..27fd2e9 100644
67107 --- a/kernel/mutex.c
67108 +++ b/kernel/mutex.c
67109 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67110 spin_lock_mutex(&lock->wait_lock, flags);
67111
67112 debug_mutex_lock_common(lock, &waiter);
67113 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
67114 + debug_mutex_add_waiter(lock, &waiter, task);
67115
67116 /* add waiting tasks to the end of the waitqueue (FIFO): */
67117 list_add_tail(&waiter.list, &lock->wait_list);
67118 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67119 * TASK_UNINTERRUPTIBLE case.)
67120 */
67121 if (unlikely(signal_pending_state(state, task))) {
67122 - mutex_remove_waiter(lock, &waiter,
67123 - task_thread_info(task));
67124 + mutex_remove_waiter(lock, &waiter, task);
67125 mutex_release(&lock->dep_map, 1, ip);
67126 spin_unlock_mutex(&lock->wait_lock, flags);
67127
67128 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67129 done:
67130 lock_acquired(&lock->dep_map, ip);
67131 /* got the lock - rejoice! */
67132 - mutex_remove_waiter(lock, &waiter, current_thread_info());
67133 + mutex_remove_waiter(lock, &waiter, task);
67134 mutex_set_owner(lock);
67135
67136 /* set it to 0 if there are no waiters left: */
67137 diff --git a/kernel/panic.c b/kernel/panic.c
67138 index 9ed023b..e49543e 100644
67139 --- a/kernel/panic.c
67140 +++ b/kernel/panic.c
67141 @@ -402,7 +402,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
67142 const char *board;
67143
67144 printk(KERN_WARNING "------------[ cut here ]------------\n");
67145 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
67146 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
67147 board = dmi_get_system_info(DMI_PRODUCT_NAME);
67148 if (board)
67149 printk(KERN_WARNING "Hardware name: %s\n", board);
67150 @@ -457,7 +457,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
67151 */
67152 void __stack_chk_fail(void)
67153 {
67154 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
67155 + dump_stack();
67156 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
67157 __builtin_return_address(0));
67158 }
67159 EXPORT_SYMBOL(__stack_chk_fail);
67160 diff --git a/kernel/pid.c b/kernel/pid.c
67161 index 9f08dfa..6765c40 100644
67162 --- a/kernel/pid.c
67163 +++ b/kernel/pid.c
67164 @@ -33,6 +33,7 @@
67165 #include <linux/rculist.h>
67166 #include <linux/bootmem.h>
67167 #include <linux/hash.h>
67168 +#include <linux/security.h>
67169 #include <linux/pid_namespace.h>
67170 #include <linux/init_task.h>
67171 #include <linux/syscalls.h>
67172 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
67173
67174 int pid_max = PID_MAX_DEFAULT;
67175
67176 -#define RESERVED_PIDS 300
67177 +#define RESERVED_PIDS 500
67178
67179 int pid_max_min = RESERVED_PIDS + 1;
67180 int pid_max_max = PID_MAX_LIMIT;
67181 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
67182 */
67183 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
67184 {
67185 + struct task_struct *task;
67186 +
67187 rcu_lockdep_assert(rcu_read_lock_held(),
67188 "find_task_by_pid_ns() needs rcu_read_lock()"
67189 " protection");
67190 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
67191 +
67192 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
67193 +
67194 + if (gr_pid_is_chrooted(task))
67195 + return NULL;
67196 +
67197 + return task;
67198 }
67199
67200 struct task_struct *find_task_by_vpid(pid_t vnr)
67201 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
67202 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
67203 }
67204
67205 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
67206 +{
67207 + rcu_lockdep_assert(rcu_read_lock_held(),
67208 + "find_task_by_pid_ns() needs rcu_read_lock()"
67209 + " protection");
67210 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
67211 +}
67212 +
67213 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
67214 {
67215 struct pid *pid;
67216 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
67217 index 125cb67..a4d1c30 100644
67218 --- a/kernel/posix-cpu-timers.c
67219 +++ b/kernel/posix-cpu-timers.c
67220 @@ -6,6 +6,7 @@
67221 #include <linux/posix-timers.h>
67222 #include <linux/errno.h>
67223 #include <linux/math64.h>
67224 +#include <linux/security.h>
67225 #include <asm/uaccess.h>
67226 #include <linux/kernel_stat.h>
67227 #include <trace/events/timer.h>
67228 @@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
67229
67230 static __init int init_posix_cpu_timers(void)
67231 {
67232 - struct k_clock process = {
67233 + static struct k_clock process = {
67234 .clock_getres = process_cpu_clock_getres,
67235 .clock_get = process_cpu_clock_get,
67236 .timer_create = process_cpu_timer_create,
67237 .nsleep = process_cpu_nsleep,
67238 .nsleep_restart = process_cpu_nsleep_restart,
67239 };
67240 - struct k_clock thread = {
67241 + static struct k_clock thread = {
67242 .clock_getres = thread_cpu_clock_getres,
67243 .clock_get = thread_cpu_clock_get,
67244 .timer_create = thread_cpu_timer_create,
67245 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
67246 index 69185ae..cc2847a 100644
67247 --- a/kernel/posix-timers.c
67248 +++ b/kernel/posix-timers.c
67249 @@ -43,6 +43,7 @@
67250 #include <linux/idr.h>
67251 #include <linux/posix-clock.h>
67252 #include <linux/posix-timers.h>
67253 +#include <linux/grsecurity.h>
67254 #include <linux/syscalls.h>
67255 #include <linux/wait.h>
67256 #include <linux/workqueue.h>
67257 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
67258 * which we beg off on and pass to do_sys_settimeofday().
67259 */
67260
67261 -static struct k_clock posix_clocks[MAX_CLOCKS];
67262 +static struct k_clock *posix_clocks[MAX_CLOCKS];
67263
67264 /*
67265 * These ones are defined below.
67266 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
67267 */
67268 static __init int init_posix_timers(void)
67269 {
67270 - struct k_clock clock_realtime = {
67271 + static struct k_clock clock_realtime = {
67272 .clock_getres = hrtimer_get_res,
67273 .clock_get = posix_clock_realtime_get,
67274 .clock_set = posix_clock_realtime_set,
67275 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
67276 .timer_get = common_timer_get,
67277 .timer_del = common_timer_del,
67278 };
67279 - struct k_clock clock_monotonic = {
67280 + static struct k_clock clock_monotonic = {
67281 .clock_getres = hrtimer_get_res,
67282 .clock_get = posix_ktime_get_ts,
67283 .nsleep = common_nsleep,
67284 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
67285 .timer_get = common_timer_get,
67286 .timer_del = common_timer_del,
67287 };
67288 - struct k_clock clock_monotonic_raw = {
67289 + static struct k_clock clock_monotonic_raw = {
67290 .clock_getres = hrtimer_get_res,
67291 .clock_get = posix_get_monotonic_raw,
67292 };
67293 - struct k_clock clock_realtime_coarse = {
67294 + static struct k_clock clock_realtime_coarse = {
67295 .clock_getres = posix_get_coarse_res,
67296 .clock_get = posix_get_realtime_coarse,
67297 };
67298 - struct k_clock clock_monotonic_coarse = {
67299 + static struct k_clock clock_monotonic_coarse = {
67300 .clock_getres = posix_get_coarse_res,
67301 .clock_get = posix_get_monotonic_coarse,
67302 };
67303 - struct k_clock clock_boottime = {
67304 + static struct k_clock clock_boottime = {
67305 .clock_getres = hrtimer_get_res,
67306 .clock_get = posix_get_boottime,
67307 .nsleep = common_nsleep,
67308 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
67309 return;
67310 }
67311
67312 - posix_clocks[clock_id] = *new_clock;
67313 + posix_clocks[clock_id] = new_clock;
67314 }
67315 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
67316
67317 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
67318 return (id & CLOCKFD_MASK) == CLOCKFD ?
67319 &clock_posix_dynamic : &clock_posix_cpu;
67320
67321 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
67322 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
67323 return NULL;
67324 - return &posix_clocks[id];
67325 + return posix_clocks[id];
67326 }
67327
67328 static int common_timer_create(struct k_itimer *new_timer)
67329 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
67330 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
67331 return -EFAULT;
67332
67333 + /* only the CLOCK_REALTIME clock can be set, all other clocks
67334 + have their clock_set fptr set to a nosettime dummy function
67335 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
67336 + call common_clock_set, which calls do_sys_settimeofday, which
67337 + we hook
67338 + */
67339 +
67340 return kc->clock_set(which_clock, &new_tp);
67341 }
67342
67343 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
67344 index d523593..68197a4 100644
67345 --- a/kernel/power/poweroff.c
67346 +++ b/kernel/power/poweroff.c
67347 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
67348 .enable_mask = SYSRQ_ENABLE_BOOT,
67349 };
67350
67351 -static int pm_sysrq_init(void)
67352 +static int __init pm_sysrq_init(void)
67353 {
67354 register_sysrq_key('o', &sysrq_poweroff_op);
67355 return 0;
67356 diff --git a/kernel/power/process.c b/kernel/power/process.c
67357 index 19db29f..33b52b6 100644
67358 --- a/kernel/power/process.c
67359 +++ b/kernel/power/process.c
67360 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
67361 u64 elapsed_csecs64;
67362 unsigned int elapsed_csecs;
67363 bool wakeup = false;
67364 + bool timedout = false;
67365
67366 do_gettimeofday(&start);
67367
67368 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
67369
67370 while (true) {
67371 todo = 0;
67372 + if (time_after(jiffies, end_time))
67373 + timedout = true;
67374 read_lock(&tasklist_lock);
67375 do_each_thread(g, p) {
67376 if (p == current || !freeze_task(p))
67377 @@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
67378 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
67379 * transition can't race with task state testing here.
67380 */
67381 - if (!task_is_stopped_or_traced(p) &&
67382 - !freezer_should_skip(p))
67383 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
67384 todo++;
67385 + if (timedout) {
67386 + printk(KERN_ERR "Task refusing to freeze:\n");
67387 + sched_show_task(p);
67388 + }
67389 + }
67390 } while_each_thread(g, p);
67391 read_unlock(&tasklist_lock);
67392
67393 @@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
67394 todo += wq_busy;
67395 }
67396
67397 - if (!todo || time_after(jiffies, end_time))
67398 + if (!todo || timedout)
67399 break;
67400
67401 if (pm_wakeup_pending()) {
67402 diff --git a/kernel/printk.c b/kernel/printk.c
67403 index b663c2c..1d6ba7a 100644
67404 --- a/kernel/printk.c
67405 +++ b/kernel/printk.c
67406 @@ -316,6 +316,11 @@ static int check_syslog_permissions(int type, bool from_file)
67407 if (from_file && type != SYSLOG_ACTION_OPEN)
67408 return 0;
67409
67410 +#ifdef CONFIG_GRKERNSEC_DMESG
67411 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
67412 + return -EPERM;
67413 +#endif
67414 +
67415 if (syslog_action_restricted(type)) {
67416 if (capable(CAP_SYSLOG))
67417 return 0;
67418 diff --git a/kernel/profile.c b/kernel/profile.c
67419 index 76b8e77..a2930e8 100644
67420 --- a/kernel/profile.c
67421 +++ b/kernel/profile.c
67422 @@ -39,7 +39,7 @@ struct profile_hit {
67423 /* Oprofile timer tick hook */
67424 static int (*timer_hook)(struct pt_regs *) __read_mostly;
67425
67426 -static atomic_t *prof_buffer;
67427 +static atomic_unchecked_t *prof_buffer;
67428 static unsigned long prof_len, prof_shift;
67429
67430 int prof_on __read_mostly;
67431 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
67432 hits[i].pc = 0;
67433 continue;
67434 }
67435 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
67436 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
67437 hits[i].hits = hits[i].pc = 0;
67438 }
67439 }
67440 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
67441 * Add the current hit(s) and flush the write-queue out
67442 * to the global buffer:
67443 */
67444 - atomic_add(nr_hits, &prof_buffer[pc]);
67445 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
67446 for (i = 0; i < NR_PROFILE_HIT; ++i) {
67447 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
67448 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
67449 hits[i].pc = hits[i].hits = 0;
67450 }
67451 out:
67452 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
67453 {
67454 unsigned long pc;
67455 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
67456 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
67457 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
67458 }
67459 #endif /* !CONFIG_SMP */
67460
67461 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
67462 return -EFAULT;
67463 buf++; p++; count--; read++;
67464 }
67465 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
67466 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
67467 if (copy_to_user(buf, (void *)pnt, count))
67468 return -EFAULT;
67469 read += count;
67470 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
67471 }
67472 #endif
67473 profile_discard_flip_buffers();
67474 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
67475 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
67476 return count;
67477 }
67478
67479 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
67480 index ee8d49b..bd3d790 100644
67481 --- a/kernel/ptrace.c
67482 +++ b/kernel/ptrace.c
67483 @@ -280,7 +280,7 @@ static int ptrace_attach(struct task_struct *task, long request,
67484
67485 if (seize)
67486 flags |= PT_SEIZED;
67487 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
67488 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
67489 flags |= PT_PTRACE_CAP;
67490 task->ptrace = flags;
67491
67492 @@ -487,7 +487,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
67493 break;
67494 return -EIO;
67495 }
67496 - if (copy_to_user(dst, buf, retval))
67497 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
67498 return -EFAULT;
67499 copied += retval;
67500 src += retval;
67501 @@ -672,7 +672,7 @@ int ptrace_request(struct task_struct *child, long request,
67502 bool seized = child->ptrace & PT_SEIZED;
67503 int ret = -EIO;
67504 siginfo_t siginfo, *si;
67505 - void __user *datavp = (void __user *) data;
67506 + void __user *datavp = (__force void __user *) data;
67507 unsigned long __user *datalp = datavp;
67508 unsigned long flags;
67509
67510 @@ -874,14 +874,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
67511 goto out;
67512 }
67513
67514 + if (gr_handle_ptrace(child, request)) {
67515 + ret = -EPERM;
67516 + goto out_put_task_struct;
67517 + }
67518 +
67519 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
67520 ret = ptrace_attach(child, request, addr, data);
67521 /*
67522 * Some architectures need to do book-keeping after
67523 * a ptrace attach.
67524 */
67525 - if (!ret)
67526 + if (!ret) {
67527 arch_ptrace_attach(child);
67528 + gr_audit_ptrace(child);
67529 + }
67530 goto out_put_task_struct;
67531 }
67532
67533 @@ -907,7 +914,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
67534 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
67535 if (copied != sizeof(tmp))
67536 return -EIO;
67537 - return put_user(tmp, (unsigned long __user *)data);
67538 + return put_user(tmp, (__force unsigned long __user *)data);
67539 }
67540
67541 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
67542 @@ -1017,14 +1024,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
67543 goto out;
67544 }
67545
67546 + if (gr_handle_ptrace(child, request)) {
67547 + ret = -EPERM;
67548 + goto out_put_task_struct;
67549 + }
67550 +
67551 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
67552 ret = ptrace_attach(child, request, addr, data);
67553 /*
67554 * Some architectures need to do book-keeping after
67555 * a ptrace attach.
67556 */
67557 - if (!ret)
67558 + if (!ret) {
67559 arch_ptrace_attach(child);
67560 + gr_audit_ptrace(child);
67561 + }
67562 goto out_put_task_struct;
67563 }
67564
67565 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
67566 index 37a5444..eec170a 100644
67567 --- a/kernel/rcutiny.c
67568 +++ b/kernel/rcutiny.c
67569 @@ -46,7 +46,7 @@
67570 struct rcu_ctrlblk;
67571 static void invoke_rcu_callbacks(void);
67572 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
67573 -static void rcu_process_callbacks(struct softirq_action *unused);
67574 +static void rcu_process_callbacks(void);
67575 static void __call_rcu(struct rcu_head *head,
67576 void (*func)(struct rcu_head *rcu),
67577 struct rcu_ctrlblk *rcp);
67578 @@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
67579 rcu_is_callbacks_kthread()));
67580 }
67581
67582 -static void rcu_process_callbacks(struct softirq_action *unused)
67583 +static void rcu_process_callbacks(void)
67584 {
67585 __rcu_process_callbacks(&rcu_sched_ctrlblk);
67586 __rcu_process_callbacks(&rcu_bh_ctrlblk);
67587 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
67588 index 22ecea0..3789898 100644
67589 --- a/kernel/rcutiny_plugin.h
67590 +++ b/kernel/rcutiny_plugin.h
67591 @@ -955,7 +955,7 @@ static int rcu_kthread(void *arg)
67592 have_rcu_kthread_work = morework;
67593 local_irq_restore(flags);
67594 if (work)
67595 - rcu_process_callbacks(NULL);
67596 + rcu_process_callbacks();
67597 schedule_timeout_interruptible(1); /* Leave CPU for others. */
67598 }
67599
67600 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
67601 index a89b381..efdcad8 100644
67602 --- a/kernel/rcutorture.c
67603 +++ b/kernel/rcutorture.c
67604 @@ -158,12 +158,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
67605 { 0 };
67606 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
67607 { 0 };
67608 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
67609 -static atomic_t n_rcu_torture_alloc;
67610 -static atomic_t n_rcu_torture_alloc_fail;
67611 -static atomic_t n_rcu_torture_free;
67612 -static atomic_t n_rcu_torture_mberror;
67613 -static atomic_t n_rcu_torture_error;
67614 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
67615 +static atomic_unchecked_t n_rcu_torture_alloc;
67616 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
67617 +static atomic_unchecked_t n_rcu_torture_free;
67618 +static atomic_unchecked_t n_rcu_torture_mberror;
67619 +static atomic_unchecked_t n_rcu_torture_error;
67620 static long n_rcu_torture_boost_ktrerror;
67621 static long n_rcu_torture_boost_rterror;
67622 static long n_rcu_torture_boost_failure;
67623 @@ -253,11 +253,11 @@ rcu_torture_alloc(void)
67624
67625 spin_lock_bh(&rcu_torture_lock);
67626 if (list_empty(&rcu_torture_freelist)) {
67627 - atomic_inc(&n_rcu_torture_alloc_fail);
67628 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
67629 spin_unlock_bh(&rcu_torture_lock);
67630 return NULL;
67631 }
67632 - atomic_inc(&n_rcu_torture_alloc);
67633 + atomic_inc_unchecked(&n_rcu_torture_alloc);
67634 p = rcu_torture_freelist.next;
67635 list_del_init(p);
67636 spin_unlock_bh(&rcu_torture_lock);
67637 @@ -270,7 +270,7 @@ rcu_torture_alloc(void)
67638 static void
67639 rcu_torture_free(struct rcu_torture *p)
67640 {
67641 - atomic_inc(&n_rcu_torture_free);
67642 + atomic_inc_unchecked(&n_rcu_torture_free);
67643 spin_lock_bh(&rcu_torture_lock);
67644 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
67645 spin_unlock_bh(&rcu_torture_lock);
67646 @@ -390,7 +390,7 @@ rcu_torture_cb(struct rcu_head *p)
67647 i = rp->rtort_pipe_count;
67648 if (i > RCU_TORTURE_PIPE_LEN)
67649 i = RCU_TORTURE_PIPE_LEN;
67650 - atomic_inc(&rcu_torture_wcount[i]);
67651 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
67652 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
67653 rp->rtort_mbtest = 0;
67654 rcu_torture_free(rp);
67655 @@ -437,7 +437,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
67656 i = rp->rtort_pipe_count;
67657 if (i > RCU_TORTURE_PIPE_LEN)
67658 i = RCU_TORTURE_PIPE_LEN;
67659 - atomic_inc(&rcu_torture_wcount[i]);
67660 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
67661 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
67662 rp->rtort_mbtest = 0;
67663 list_del(&rp->rtort_free);
67664 @@ -926,7 +926,7 @@ rcu_torture_writer(void *arg)
67665 i = old_rp->rtort_pipe_count;
67666 if (i > RCU_TORTURE_PIPE_LEN)
67667 i = RCU_TORTURE_PIPE_LEN;
67668 - atomic_inc(&rcu_torture_wcount[i]);
67669 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
67670 old_rp->rtort_pipe_count++;
67671 cur_ops->deferred_free(old_rp);
67672 }
67673 @@ -1007,7 +1007,7 @@ static void rcu_torture_timer(unsigned long unused)
67674 }
67675 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
67676 if (p->rtort_mbtest == 0)
67677 - atomic_inc(&n_rcu_torture_mberror);
67678 + atomic_inc_unchecked(&n_rcu_torture_mberror);
67679 spin_lock(&rand_lock);
67680 cur_ops->read_delay(&rand);
67681 n_rcu_torture_timers++;
67682 @@ -1071,7 +1071,7 @@ rcu_torture_reader(void *arg)
67683 }
67684 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
67685 if (p->rtort_mbtest == 0)
67686 - atomic_inc(&n_rcu_torture_mberror);
67687 + atomic_inc_unchecked(&n_rcu_torture_mberror);
67688 cur_ops->read_delay(&rand);
67689 preempt_disable();
67690 pipe_count = p->rtort_pipe_count;
67691 @@ -1133,10 +1133,10 @@ rcu_torture_printk(char *page)
67692 rcu_torture_current,
67693 rcu_torture_current_version,
67694 list_empty(&rcu_torture_freelist),
67695 - atomic_read(&n_rcu_torture_alloc),
67696 - atomic_read(&n_rcu_torture_alloc_fail),
67697 - atomic_read(&n_rcu_torture_free),
67698 - atomic_read(&n_rcu_torture_mberror),
67699 + atomic_read_unchecked(&n_rcu_torture_alloc),
67700 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
67701 + atomic_read_unchecked(&n_rcu_torture_free),
67702 + atomic_read_unchecked(&n_rcu_torture_mberror),
67703 n_rcu_torture_boost_ktrerror,
67704 n_rcu_torture_boost_rterror,
67705 n_rcu_torture_boost_failure,
67706 @@ -1146,7 +1146,7 @@ rcu_torture_printk(char *page)
67707 n_online_attempts,
67708 n_offline_successes,
67709 n_offline_attempts);
67710 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
67711 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
67712 n_rcu_torture_boost_ktrerror != 0 ||
67713 n_rcu_torture_boost_rterror != 0 ||
67714 n_rcu_torture_boost_failure != 0)
67715 @@ -1154,7 +1154,7 @@ rcu_torture_printk(char *page)
67716 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
67717 if (i > 1) {
67718 cnt += sprintf(&page[cnt], "!!! ");
67719 - atomic_inc(&n_rcu_torture_error);
67720 + atomic_inc_unchecked(&n_rcu_torture_error);
67721 WARN_ON_ONCE(1);
67722 }
67723 cnt += sprintf(&page[cnt], "Reader Pipe: ");
67724 @@ -1168,7 +1168,7 @@ rcu_torture_printk(char *page)
67725 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
67726 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
67727 cnt += sprintf(&page[cnt], " %d",
67728 - atomic_read(&rcu_torture_wcount[i]));
67729 + atomic_read_unchecked(&rcu_torture_wcount[i]));
67730 }
67731 cnt += sprintf(&page[cnt], "\n");
67732 if (cur_ops->stats)
67733 @@ -1676,7 +1676,7 @@ rcu_torture_cleanup(void)
67734
67735 if (cur_ops->cleanup)
67736 cur_ops->cleanup();
67737 - if (atomic_read(&n_rcu_torture_error))
67738 + if (atomic_read_unchecked(&n_rcu_torture_error))
67739 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
67740 else if (n_online_successes != n_online_attempts ||
67741 n_offline_successes != n_offline_attempts)
67742 @@ -1744,17 +1744,17 @@ rcu_torture_init(void)
67743
67744 rcu_torture_current = NULL;
67745 rcu_torture_current_version = 0;
67746 - atomic_set(&n_rcu_torture_alloc, 0);
67747 - atomic_set(&n_rcu_torture_alloc_fail, 0);
67748 - atomic_set(&n_rcu_torture_free, 0);
67749 - atomic_set(&n_rcu_torture_mberror, 0);
67750 - atomic_set(&n_rcu_torture_error, 0);
67751 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
67752 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
67753 + atomic_set_unchecked(&n_rcu_torture_free, 0);
67754 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
67755 + atomic_set_unchecked(&n_rcu_torture_error, 0);
67756 n_rcu_torture_boost_ktrerror = 0;
67757 n_rcu_torture_boost_rterror = 0;
67758 n_rcu_torture_boost_failure = 0;
67759 n_rcu_torture_boosts = 0;
67760 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
67761 - atomic_set(&rcu_torture_wcount[i], 0);
67762 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
67763 for_each_possible_cpu(cpu) {
67764 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
67765 per_cpu(rcu_torture_count, cpu)[i] = 0;
67766 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
67767 index d0c5baf..109b2e7 100644
67768 --- a/kernel/rcutree.c
67769 +++ b/kernel/rcutree.c
67770 @@ -357,9 +357,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
67771 rcu_prepare_for_idle(smp_processor_id());
67772 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
67773 smp_mb__before_atomic_inc(); /* See above. */
67774 - atomic_inc(&rdtp->dynticks);
67775 + atomic_inc_unchecked(&rdtp->dynticks);
67776 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
67777 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
67778 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
67779
67780 /*
67781 * The idle task is not permitted to enter the idle loop while
67782 @@ -448,10 +448,10 @@ void rcu_irq_exit(void)
67783 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
67784 {
67785 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
67786 - atomic_inc(&rdtp->dynticks);
67787 + atomic_inc_unchecked(&rdtp->dynticks);
67788 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
67789 smp_mb__after_atomic_inc(); /* See above. */
67790 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
67791 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
67792 rcu_cleanup_after_idle(smp_processor_id());
67793 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
67794 if (!is_idle_task(current)) {
67795 @@ -545,14 +545,14 @@ void rcu_nmi_enter(void)
67796 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
67797
67798 if (rdtp->dynticks_nmi_nesting == 0 &&
67799 - (atomic_read(&rdtp->dynticks) & 0x1))
67800 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
67801 return;
67802 rdtp->dynticks_nmi_nesting++;
67803 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
67804 - atomic_inc(&rdtp->dynticks);
67805 + atomic_inc_unchecked(&rdtp->dynticks);
67806 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
67807 smp_mb__after_atomic_inc(); /* See above. */
67808 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
67809 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
67810 }
67811
67812 /**
67813 @@ -571,9 +571,9 @@ void rcu_nmi_exit(void)
67814 return;
67815 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
67816 smp_mb__before_atomic_inc(); /* See above. */
67817 - atomic_inc(&rdtp->dynticks);
67818 + atomic_inc_unchecked(&rdtp->dynticks);
67819 smp_mb__after_atomic_inc(); /* Force delay to next write. */
67820 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
67821 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
67822 }
67823
67824 #ifdef CONFIG_PROVE_RCU
67825 @@ -589,7 +589,7 @@ int rcu_is_cpu_idle(void)
67826 int ret;
67827
67828 preempt_disable();
67829 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
67830 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
67831 preempt_enable();
67832 return ret;
67833 }
67834 @@ -659,7 +659,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
67835 */
67836 static int dyntick_save_progress_counter(struct rcu_data *rdp)
67837 {
67838 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
67839 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
67840 return (rdp->dynticks_snap & 0x1) == 0;
67841 }
67842
67843 @@ -674,7 +674,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
67844 unsigned int curr;
67845 unsigned int snap;
67846
67847 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
67848 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
67849 snap = (unsigned int)rdp->dynticks_snap;
67850
67851 /*
67852 @@ -704,10 +704,10 @@ static int jiffies_till_stall_check(void)
67853 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
67854 */
67855 if (till_stall_check < 3) {
67856 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
67857 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
67858 till_stall_check = 3;
67859 } else if (till_stall_check > 300) {
67860 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
67861 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
67862 till_stall_check = 300;
67863 }
67864 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
67865 @@ -1766,7 +1766,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
67866 /*
67867 * Do RCU core processing for the current CPU.
67868 */
67869 -static void rcu_process_callbacks(struct softirq_action *unused)
67870 +static void rcu_process_callbacks(void)
67871 {
67872 trace_rcu_utilization("Start RCU core");
67873 __rcu_process_callbacks(&rcu_sched_state,
67874 @@ -1949,8 +1949,8 @@ void synchronize_rcu_bh(void)
67875 }
67876 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
67877
67878 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
67879 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
67880 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
67881 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
67882
67883 static int synchronize_sched_expedited_cpu_stop(void *data)
67884 {
67885 @@ -2011,7 +2011,7 @@ void synchronize_sched_expedited(void)
67886 int firstsnap, s, snap, trycount = 0;
67887
67888 /* Note that atomic_inc_return() implies full memory barrier. */
67889 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
67890 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
67891 get_online_cpus();
67892 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
67893
67894 @@ -2033,7 +2033,7 @@ void synchronize_sched_expedited(void)
67895 }
67896
67897 /* Check to see if someone else did our work for us. */
67898 - s = atomic_read(&sync_sched_expedited_done);
67899 + s = atomic_read_unchecked(&sync_sched_expedited_done);
67900 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
67901 smp_mb(); /* ensure test happens before caller kfree */
67902 return;
67903 @@ -2048,7 +2048,7 @@ void synchronize_sched_expedited(void)
67904 * grace period works for us.
67905 */
67906 get_online_cpus();
67907 - snap = atomic_read(&sync_sched_expedited_started);
67908 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
67909 smp_mb(); /* ensure read is before try_stop_cpus(). */
67910 }
67911
67912 @@ -2059,12 +2059,12 @@ void synchronize_sched_expedited(void)
67913 * than we did beat us to the punch.
67914 */
67915 do {
67916 - s = atomic_read(&sync_sched_expedited_done);
67917 + s = atomic_read_unchecked(&sync_sched_expedited_done);
67918 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
67919 smp_mb(); /* ensure test happens before caller kfree */
67920 break;
67921 }
67922 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
67923 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
67924
67925 put_online_cpus();
67926 }
67927 @@ -2262,7 +2262,7 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
67928 rdp->qlen = 0;
67929 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
67930 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
67931 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
67932 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
67933 rdp->cpu = cpu;
67934 rdp->rsp = rsp;
67935 raw_spin_unlock_irqrestore(&rnp->lock, flags);
67936 @@ -2290,8 +2290,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
67937 rdp->n_force_qs_snap = rsp->n_force_qs;
67938 rdp->blimit = blimit;
67939 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
67940 - atomic_set(&rdp->dynticks->dynticks,
67941 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
67942 + atomic_set_unchecked(&rdp->dynticks->dynticks,
67943 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
67944 rcu_prepare_for_idle_init(cpu);
67945 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
67946
67947 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
67948 index cdd1be0..5b2efb4 100644
67949 --- a/kernel/rcutree.h
67950 +++ b/kernel/rcutree.h
67951 @@ -87,7 +87,7 @@ struct rcu_dynticks {
67952 long long dynticks_nesting; /* Track irq/process nesting level. */
67953 /* Process level is worth LLONG_MAX/2. */
67954 int dynticks_nmi_nesting; /* Track NMI nesting level. */
67955 - atomic_t dynticks; /* Even value for idle, else odd. */
67956 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
67957 };
67958
67959 /* RCU's kthread states for tracing. */
67960 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
67961 index c023464..7f57225 100644
67962 --- a/kernel/rcutree_plugin.h
67963 +++ b/kernel/rcutree_plugin.h
67964 @@ -909,7 +909,7 @@ void synchronize_rcu_expedited(void)
67965
67966 /* Clean up and exit. */
67967 smp_mb(); /* ensure expedited GP seen before counter increment. */
67968 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
67969 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
67970 unlock_mb_ret:
67971 mutex_unlock(&sync_rcu_preempt_exp_mutex);
67972 mb_ret:
67973 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
67974 index ed459ed..a03c3fa 100644
67975 --- a/kernel/rcutree_trace.c
67976 +++ b/kernel/rcutree_trace.c
67977 @@ -68,7 +68,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
67978 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
67979 rdp->qs_pending);
67980 seq_printf(m, " dt=%d/%llx/%d df=%lu",
67981 - atomic_read(&rdp->dynticks->dynticks),
67982 + atomic_read_unchecked(&rdp->dynticks->dynticks),
67983 rdp->dynticks->dynticks_nesting,
67984 rdp->dynticks->dynticks_nmi_nesting,
67985 rdp->dynticks_fqs);
67986 @@ -140,7 +140,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
67987 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
67988 rdp->qs_pending);
67989 seq_printf(m, ",%d,%llx,%d,%lu",
67990 - atomic_read(&rdp->dynticks->dynticks),
67991 + atomic_read_unchecked(&rdp->dynticks->dynticks),
67992 rdp->dynticks->dynticks_nesting,
67993 rdp->dynticks->dynticks_nmi_nesting,
67994 rdp->dynticks_fqs);
67995 diff --git a/kernel/resource.c b/kernel/resource.c
67996 index 7e8ea66..1efd11f 100644
67997 --- a/kernel/resource.c
67998 +++ b/kernel/resource.c
67999 @@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
68000
68001 static int __init ioresources_init(void)
68002 {
68003 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
68004 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68005 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
68006 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
68007 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68008 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
68009 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
68010 +#endif
68011 +#else
68012 proc_create("ioports", 0, NULL, &proc_ioports_operations);
68013 proc_create("iomem", 0, NULL, &proc_iomem_operations);
68014 +#endif
68015 return 0;
68016 }
68017 __initcall(ioresources_init);
68018 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
68019 index 98ec494..4241d6d 100644
68020 --- a/kernel/rtmutex-tester.c
68021 +++ b/kernel/rtmutex-tester.c
68022 @@ -20,7 +20,7 @@
68023 #define MAX_RT_TEST_MUTEXES 8
68024
68025 static spinlock_t rttest_lock;
68026 -static atomic_t rttest_event;
68027 +static atomic_unchecked_t rttest_event;
68028
68029 struct test_thread_data {
68030 int opcode;
68031 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68032
68033 case RTTEST_LOCKCONT:
68034 td->mutexes[td->opdata] = 1;
68035 - td->event = atomic_add_return(1, &rttest_event);
68036 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68037 return 0;
68038
68039 case RTTEST_RESET:
68040 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68041 return 0;
68042
68043 case RTTEST_RESETEVENT:
68044 - atomic_set(&rttest_event, 0);
68045 + atomic_set_unchecked(&rttest_event, 0);
68046 return 0;
68047
68048 default:
68049 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68050 return ret;
68051
68052 td->mutexes[id] = 1;
68053 - td->event = atomic_add_return(1, &rttest_event);
68054 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68055 rt_mutex_lock(&mutexes[id]);
68056 - td->event = atomic_add_return(1, &rttest_event);
68057 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68058 td->mutexes[id] = 4;
68059 return 0;
68060
68061 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68062 return ret;
68063
68064 td->mutexes[id] = 1;
68065 - td->event = atomic_add_return(1, &rttest_event);
68066 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68067 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
68068 - td->event = atomic_add_return(1, &rttest_event);
68069 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68070 td->mutexes[id] = ret ? 0 : 4;
68071 return ret ? -EINTR : 0;
68072
68073 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68074 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
68075 return ret;
68076
68077 - td->event = atomic_add_return(1, &rttest_event);
68078 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68079 rt_mutex_unlock(&mutexes[id]);
68080 - td->event = atomic_add_return(1, &rttest_event);
68081 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68082 td->mutexes[id] = 0;
68083 return 0;
68084
68085 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68086 break;
68087
68088 td->mutexes[dat] = 2;
68089 - td->event = atomic_add_return(1, &rttest_event);
68090 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68091 break;
68092
68093 default:
68094 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68095 return;
68096
68097 td->mutexes[dat] = 3;
68098 - td->event = atomic_add_return(1, &rttest_event);
68099 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68100 break;
68101
68102 case RTTEST_LOCKNOWAIT:
68103 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68104 return;
68105
68106 td->mutexes[dat] = 1;
68107 - td->event = atomic_add_return(1, &rttest_event);
68108 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68109 return;
68110
68111 default:
68112 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
68113 index 0984a21..939f183 100644
68114 --- a/kernel/sched/auto_group.c
68115 +++ b/kernel/sched/auto_group.c
68116 @@ -11,7 +11,7 @@
68117
68118 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
68119 static struct autogroup autogroup_default;
68120 -static atomic_t autogroup_seq_nr;
68121 +static atomic_unchecked_t autogroup_seq_nr;
68122
68123 void __init autogroup_init(struct task_struct *init_task)
68124 {
68125 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
68126
68127 kref_init(&ag->kref);
68128 init_rwsem(&ag->lock);
68129 - ag->id = atomic_inc_return(&autogroup_seq_nr);
68130 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
68131 ag->tg = tg;
68132 #ifdef CONFIG_RT_GROUP_SCHED
68133 /*
68134 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
68135 index 817bf70..9099fb4 100644
68136 --- a/kernel/sched/core.c
68137 +++ b/kernel/sched/core.c
68138 @@ -4038,6 +4038,8 @@ int can_nice(const struct task_struct *p, const int nice)
68139 /* convert nice value [19,-20] to rlimit style value [1,40] */
68140 int nice_rlim = 20 - nice;
68141
68142 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
68143 +
68144 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
68145 capable(CAP_SYS_NICE));
68146 }
68147 @@ -4071,7 +4073,8 @@ SYSCALL_DEFINE1(nice, int, increment)
68148 if (nice > 19)
68149 nice = 19;
68150
68151 - if (increment < 0 && !can_nice(current, nice))
68152 + if (increment < 0 && (!can_nice(current, nice) ||
68153 + gr_handle_chroot_nice()))
68154 return -EPERM;
68155
68156 retval = security_task_setnice(current, nice);
68157 @@ -4228,6 +4231,7 @@ recheck:
68158 unsigned long rlim_rtprio =
68159 task_rlimit(p, RLIMIT_RTPRIO);
68160
68161 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
68162 /* can't set/change the rt policy */
68163 if (policy != p->policy && !rlim_rtprio)
68164 return -EPERM;
68165 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
68166 index e955364..eacd2a4 100644
68167 --- a/kernel/sched/fair.c
68168 +++ b/kernel/sched/fair.c
68169 @@ -5107,7 +5107,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
68170 * run_rebalance_domains is triggered when needed from the scheduler tick.
68171 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
68172 */
68173 -static void run_rebalance_domains(struct softirq_action *h)
68174 +static void run_rebalance_domains(void)
68175 {
68176 int this_cpu = smp_processor_id();
68177 struct rq *this_rq = cpu_rq(this_cpu);
68178 diff --git a/kernel/signal.c b/kernel/signal.c
68179 index 17afcaf..4500b05 100644
68180 --- a/kernel/signal.c
68181 +++ b/kernel/signal.c
68182 @@ -47,12 +47,12 @@ static struct kmem_cache *sigqueue_cachep;
68183
68184 int print_fatal_signals __read_mostly;
68185
68186 -static void __user *sig_handler(struct task_struct *t, int sig)
68187 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
68188 {
68189 return t->sighand->action[sig - 1].sa.sa_handler;
68190 }
68191
68192 -static int sig_handler_ignored(void __user *handler, int sig)
68193 +static int sig_handler_ignored(__sighandler_t handler, int sig)
68194 {
68195 /* Is it explicitly or implicitly ignored? */
68196 return handler == SIG_IGN ||
68197 @@ -61,7 +61,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
68198
68199 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
68200 {
68201 - void __user *handler;
68202 + __sighandler_t handler;
68203
68204 handler = sig_handler(t, sig);
68205
68206 @@ -365,6 +365,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
68207 atomic_inc(&user->sigpending);
68208 rcu_read_unlock();
68209
68210 + if (!override_rlimit)
68211 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
68212 +
68213 if (override_rlimit ||
68214 atomic_read(&user->sigpending) <=
68215 task_rlimit(t, RLIMIT_SIGPENDING)) {
68216 @@ -489,7 +492,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
68217
68218 int unhandled_signal(struct task_struct *tsk, int sig)
68219 {
68220 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
68221 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
68222 if (is_global_init(tsk))
68223 return 1;
68224 if (handler != SIG_IGN && handler != SIG_DFL)
68225 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
68226 }
68227 }
68228
68229 + /* allow glibc communication via tgkill to other threads in our
68230 + thread group */
68231 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
68232 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
68233 + && gr_handle_signal(t, sig))
68234 + return -EPERM;
68235 +
68236 return security_task_kill(t, info, sig, 0);
68237 }
68238
68239 @@ -1204,7 +1214,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
68240 return send_signal(sig, info, p, 1);
68241 }
68242
68243 -static int
68244 +int
68245 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68246 {
68247 return send_signal(sig, info, t, 0);
68248 @@ -1241,6 +1251,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68249 unsigned long int flags;
68250 int ret, blocked, ignored;
68251 struct k_sigaction *action;
68252 + int is_unhandled = 0;
68253
68254 spin_lock_irqsave(&t->sighand->siglock, flags);
68255 action = &t->sighand->action[sig-1];
68256 @@ -1255,9 +1266,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68257 }
68258 if (action->sa.sa_handler == SIG_DFL)
68259 t->signal->flags &= ~SIGNAL_UNKILLABLE;
68260 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
68261 + is_unhandled = 1;
68262 ret = specific_send_sig_info(sig, info, t);
68263 spin_unlock_irqrestore(&t->sighand->siglock, flags);
68264
68265 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
68266 + normal operation */
68267 + if (is_unhandled) {
68268 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
68269 + gr_handle_crash(t, sig);
68270 + }
68271 +
68272 return ret;
68273 }
68274
68275 @@ -1324,8 +1344,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
68276 ret = check_kill_permission(sig, info, p);
68277 rcu_read_unlock();
68278
68279 - if (!ret && sig)
68280 + if (!ret && sig) {
68281 ret = do_send_sig_info(sig, info, p, true);
68282 + if (!ret)
68283 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
68284 + }
68285
68286 return ret;
68287 }
68288 @@ -2840,7 +2863,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
68289 int error = -ESRCH;
68290
68291 rcu_read_lock();
68292 - p = find_task_by_vpid(pid);
68293 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68294 + /* allow glibc communication via tgkill to other threads in our
68295 + thread group */
68296 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
68297 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
68298 + p = find_task_by_vpid_unrestricted(pid);
68299 + else
68300 +#endif
68301 + p = find_task_by_vpid(pid);
68302 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
68303 error = check_kill_permission(sig, info, p);
68304 /*
68305 diff --git a/kernel/smp.c b/kernel/smp.c
68306 index 2f8b10e..a41bc14 100644
68307 --- a/kernel/smp.c
68308 +++ b/kernel/smp.c
68309 @@ -580,22 +580,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
68310 }
68311 EXPORT_SYMBOL(smp_call_function);
68312
68313 -void ipi_call_lock(void)
68314 +void ipi_call_lock(void) __acquires(call_function.lock)
68315 {
68316 raw_spin_lock(&call_function.lock);
68317 }
68318
68319 -void ipi_call_unlock(void)
68320 +void ipi_call_unlock(void) __releases(call_function.lock)
68321 {
68322 raw_spin_unlock(&call_function.lock);
68323 }
68324
68325 -void ipi_call_lock_irq(void)
68326 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
68327 {
68328 raw_spin_lock_irq(&call_function.lock);
68329 }
68330
68331 -void ipi_call_unlock_irq(void)
68332 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
68333 {
68334 raw_spin_unlock_irq(&call_function.lock);
68335 }
68336 diff --git a/kernel/softirq.c b/kernel/softirq.c
68337 index 671f959..91c51cb 100644
68338 --- a/kernel/softirq.c
68339 +++ b/kernel/softirq.c
68340 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
68341
68342 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
68343
68344 -char *softirq_to_name[NR_SOFTIRQS] = {
68345 +const char * const softirq_to_name[NR_SOFTIRQS] = {
68346 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
68347 "TASKLET", "SCHED", "HRTIMER", "RCU"
68348 };
68349 @@ -235,7 +235,7 @@ restart:
68350 kstat_incr_softirqs_this_cpu(vec_nr);
68351
68352 trace_softirq_entry(vec_nr);
68353 - h->action(h);
68354 + h->action();
68355 trace_softirq_exit(vec_nr);
68356 if (unlikely(prev_count != preempt_count())) {
68357 printk(KERN_ERR "huh, entered softirq %u %s %p"
68358 @@ -381,9 +381,11 @@ void __raise_softirq_irqoff(unsigned int nr)
68359 or_softirq_pending(1UL << nr);
68360 }
68361
68362 -void open_softirq(int nr, void (*action)(struct softirq_action *))
68363 +void open_softirq(int nr, void (*action)(void))
68364 {
68365 - softirq_vec[nr].action = action;
68366 + pax_open_kernel();
68367 + *(void **)&softirq_vec[nr].action = action;
68368 + pax_close_kernel();
68369 }
68370
68371 /*
68372 @@ -437,7 +439,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
68373
68374 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
68375
68376 -static void tasklet_action(struct softirq_action *a)
68377 +static void tasklet_action(void)
68378 {
68379 struct tasklet_struct *list;
68380
68381 @@ -472,7 +474,7 @@ static void tasklet_action(struct softirq_action *a)
68382 }
68383 }
68384
68385 -static void tasklet_hi_action(struct softirq_action *a)
68386 +static void tasklet_hi_action(void)
68387 {
68388 struct tasklet_struct *list;
68389
68390 diff --git a/kernel/sys.c b/kernel/sys.c
68391 index e7006eb..8fb7c51 100644
68392 --- a/kernel/sys.c
68393 +++ b/kernel/sys.c
68394 @@ -158,6 +158,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
68395 error = -EACCES;
68396 goto out;
68397 }
68398 +
68399 + if (gr_handle_chroot_setpriority(p, niceval)) {
68400 + error = -EACCES;
68401 + goto out;
68402 + }
68403 +
68404 no_nice = security_task_setnice(p, niceval);
68405 if (no_nice) {
68406 error = no_nice;
68407 @@ -581,6 +587,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
68408 goto error;
68409 }
68410
68411 + if (gr_check_group_change(new->gid, new->egid, -1))
68412 + goto error;
68413 +
68414 if (rgid != (gid_t) -1 ||
68415 (egid != (gid_t) -1 && egid != old->gid))
68416 new->sgid = new->egid;
68417 @@ -610,6 +619,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
68418 old = current_cred();
68419
68420 retval = -EPERM;
68421 +
68422 + if (gr_check_group_change(gid, gid, gid))
68423 + goto error;
68424 +
68425 if (nsown_capable(CAP_SETGID))
68426 new->gid = new->egid = new->sgid = new->fsgid = gid;
68427 else if (gid == old->gid || gid == old->sgid)
68428 @@ -627,7 +640,7 @@ error:
68429 /*
68430 * change the user struct in a credentials set to match the new UID
68431 */
68432 -static int set_user(struct cred *new)
68433 +int set_user(struct cred *new)
68434 {
68435 struct user_struct *new_user;
68436
68437 @@ -697,6 +710,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
68438 goto error;
68439 }
68440
68441 + if (gr_check_user_change(new->uid, new->euid, -1))
68442 + goto error;
68443 +
68444 if (new->uid != old->uid) {
68445 retval = set_user(new);
68446 if (retval < 0)
68447 @@ -741,6 +757,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
68448 old = current_cred();
68449
68450 retval = -EPERM;
68451 +
68452 + if (gr_check_crash_uid(uid))
68453 + goto error;
68454 + if (gr_check_user_change(uid, uid, uid))
68455 + goto error;
68456 +
68457 if (nsown_capable(CAP_SETUID)) {
68458 new->suid = new->uid = uid;
68459 if (uid != old->uid) {
68460 @@ -795,6 +817,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
68461 goto error;
68462 }
68463
68464 + if (gr_check_user_change(ruid, euid, -1))
68465 + goto error;
68466 +
68467 if (ruid != (uid_t) -1) {
68468 new->uid = ruid;
68469 if (ruid != old->uid) {
68470 @@ -859,6 +884,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
68471 goto error;
68472 }
68473
68474 + if (gr_check_group_change(rgid, egid, -1))
68475 + goto error;
68476 +
68477 if (rgid != (gid_t) -1)
68478 new->gid = rgid;
68479 if (egid != (gid_t) -1)
68480 @@ -905,6 +933,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
68481 old = current_cred();
68482 old_fsuid = old->fsuid;
68483
68484 + if (gr_check_user_change(-1, -1, uid))
68485 + goto error;
68486 +
68487 if (uid == old->uid || uid == old->euid ||
68488 uid == old->suid || uid == old->fsuid ||
68489 nsown_capable(CAP_SETUID)) {
68490 @@ -915,6 +946,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
68491 }
68492 }
68493
68494 +error:
68495 abort_creds(new);
68496 return old_fsuid;
68497
68498 @@ -941,12 +973,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
68499 if (gid == old->gid || gid == old->egid ||
68500 gid == old->sgid || gid == old->fsgid ||
68501 nsown_capable(CAP_SETGID)) {
68502 + if (gr_check_group_change(-1, -1, gid))
68503 + goto error;
68504 +
68505 if (gid != old_fsgid) {
68506 new->fsgid = gid;
68507 goto change_okay;
68508 }
68509 }
68510
68511 +error:
68512 abort_creds(new);
68513 return old_fsgid;
68514
68515 @@ -1198,7 +1234,10 @@ static int override_release(char __user *release, int len)
68516 }
68517 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
68518 snprintf(buf, len, "2.6.%u%s", v, rest);
68519 - ret = copy_to_user(release, buf, len);
68520 + if (len > sizeof(buf))
68521 + ret = -EFAULT;
68522 + else
68523 + ret = copy_to_user(release, buf, len);
68524 }
68525 return ret;
68526 }
68527 @@ -1252,19 +1291,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
68528 return -EFAULT;
68529
68530 down_read(&uts_sem);
68531 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
68532 + error = __copy_to_user(name->sysname, &utsname()->sysname,
68533 __OLD_UTS_LEN);
68534 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
68535 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
68536 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
68537 __OLD_UTS_LEN);
68538 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
68539 - error |= __copy_to_user(&name->release, &utsname()->release,
68540 + error |= __copy_to_user(name->release, &utsname()->release,
68541 __OLD_UTS_LEN);
68542 error |= __put_user(0, name->release + __OLD_UTS_LEN);
68543 - error |= __copy_to_user(&name->version, &utsname()->version,
68544 + error |= __copy_to_user(name->version, &utsname()->version,
68545 __OLD_UTS_LEN);
68546 error |= __put_user(0, name->version + __OLD_UTS_LEN);
68547 - error |= __copy_to_user(&name->machine, &utsname()->machine,
68548 + error |= __copy_to_user(name->machine, &utsname()->machine,
68549 __OLD_UTS_LEN);
68550 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
68551 up_read(&uts_sem);
68552 @@ -1847,7 +1886,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
68553 error = get_dumpable(me->mm);
68554 break;
68555 case PR_SET_DUMPABLE:
68556 - if (arg2 < 0 || arg2 > 1) {
68557 + if (arg2 > 1) {
68558 error = -EINVAL;
68559 break;
68560 }
68561 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
68562 index 4ab1187..0b75ced 100644
68563 --- a/kernel/sysctl.c
68564 +++ b/kernel/sysctl.c
68565 @@ -91,7 +91,6 @@
68566
68567
68568 #if defined(CONFIG_SYSCTL)
68569 -
68570 /* External variables not in a header file. */
68571 extern int sysctl_overcommit_memory;
68572 extern int sysctl_overcommit_ratio;
68573 @@ -169,10 +168,8 @@ static int proc_taint(struct ctl_table *table, int write,
68574 void __user *buffer, size_t *lenp, loff_t *ppos);
68575 #endif
68576
68577 -#ifdef CONFIG_PRINTK
68578 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
68579 void __user *buffer, size_t *lenp, loff_t *ppos);
68580 -#endif
68581
68582 #ifdef CONFIG_MAGIC_SYSRQ
68583 /* Note: sysrq code uses it's own private copy */
68584 @@ -196,6 +193,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
68585
68586 #endif
68587
68588 +extern struct ctl_table grsecurity_table[];
68589 +
68590 static struct ctl_table kern_table[];
68591 static struct ctl_table vm_table[];
68592 static struct ctl_table fs_table[];
68593 @@ -210,6 +209,20 @@ extern struct ctl_table epoll_table[];
68594 int sysctl_legacy_va_layout;
68595 #endif
68596
68597 +#ifdef CONFIG_PAX_SOFTMODE
68598 +static ctl_table pax_table[] = {
68599 + {
68600 + .procname = "softmode",
68601 + .data = &pax_softmode,
68602 + .maxlen = sizeof(unsigned int),
68603 + .mode = 0600,
68604 + .proc_handler = &proc_dointvec,
68605 + },
68606 +
68607 + { }
68608 +};
68609 +#endif
68610 +
68611 /* The default sysctl tables: */
68612
68613 static struct ctl_table sysctl_base_table[] = {
68614 @@ -256,6 +269,22 @@ static int max_extfrag_threshold = 1000;
68615 #endif
68616
68617 static struct ctl_table kern_table[] = {
68618 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
68619 + {
68620 + .procname = "grsecurity",
68621 + .mode = 0500,
68622 + .child = grsecurity_table,
68623 + },
68624 +#endif
68625 +
68626 +#ifdef CONFIG_PAX_SOFTMODE
68627 + {
68628 + .procname = "pax",
68629 + .mode = 0500,
68630 + .child = pax_table,
68631 + },
68632 +#endif
68633 +
68634 {
68635 .procname = "sched_child_runs_first",
68636 .data = &sysctl_sched_child_runs_first,
68637 @@ -540,7 +569,7 @@ static struct ctl_table kern_table[] = {
68638 .data = &modprobe_path,
68639 .maxlen = KMOD_PATH_LEN,
68640 .mode = 0644,
68641 - .proc_handler = proc_dostring,
68642 + .proc_handler = proc_dostring_modpriv,
68643 },
68644 {
68645 .procname = "modules_disabled",
68646 @@ -707,16 +736,20 @@ static struct ctl_table kern_table[] = {
68647 .extra1 = &zero,
68648 .extra2 = &one,
68649 },
68650 +#endif
68651 {
68652 .procname = "kptr_restrict",
68653 .data = &kptr_restrict,
68654 .maxlen = sizeof(int),
68655 .mode = 0644,
68656 .proc_handler = proc_dointvec_minmax_sysadmin,
68657 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68658 + .extra1 = &two,
68659 +#else
68660 .extra1 = &zero,
68661 +#endif
68662 .extra2 = &two,
68663 },
68664 -#endif
68665 {
68666 .procname = "ngroups_max",
68667 .data = &ngroups_max,
68668 @@ -1215,6 +1248,13 @@ static struct ctl_table vm_table[] = {
68669 .proc_handler = proc_dointvec_minmax,
68670 .extra1 = &zero,
68671 },
68672 + {
68673 + .procname = "heap_stack_gap",
68674 + .data = &sysctl_heap_stack_gap,
68675 + .maxlen = sizeof(sysctl_heap_stack_gap),
68676 + .mode = 0644,
68677 + .proc_handler = proc_doulongvec_minmax,
68678 + },
68679 #else
68680 {
68681 .procname = "nr_trim_pages",
68682 @@ -1645,6 +1685,16 @@ int proc_dostring(struct ctl_table *table, int write,
68683 buffer, lenp, ppos);
68684 }
68685
68686 +int proc_dostring_modpriv(struct ctl_table *table, int write,
68687 + void __user *buffer, size_t *lenp, loff_t *ppos)
68688 +{
68689 + if (write && !capable(CAP_SYS_MODULE))
68690 + return -EPERM;
68691 +
68692 + return _proc_do_string(table->data, table->maxlen, write,
68693 + buffer, lenp, ppos);
68694 +}
68695 +
68696 static size_t proc_skip_spaces(char **buf)
68697 {
68698 size_t ret;
68699 @@ -1750,6 +1800,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
68700 len = strlen(tmp);
68701 if (len > *size)
68702 len = *size;
68703 + if (len > sizeof(tmp))
68704 + len = sizeof(tmp);
68705 if (copy_to_user(*buf, tmp, len))
68706 return -EFAULT;
68707 *size -= len;
68708 @@ -1942,7 +1994,6 @@ static int proc_taint(struct ctl_table *table, int write,
68709 return err;
68710 }
68711
68712 -#ifdef CONFIG_PRINTK
68713 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
68714 void __user *buffer, size_t *lenp, loff_t *ppos)
68715 {
68716 @@ -1951,7 +2002,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
68717
68718 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
68719 }
68720 -#endif
68721
68722 struct do_proc_dointvec_minmax_conv_param {
68723 int *min;
68724 @@ -2066,8 +2116,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
68725 *i = val;
68726 } else {
68727 val = convdiv * (*i) / convmul;
68728 - if (!first)
68729 + if (!first) {
68730 err = proc_put_char(&buffer, &left, '\t');
68731 + if (err)
68732 + break;
68733 + }
68734 err = proc_put_long(&buffer, &left, val, false);
68735 if (err)
68736 break;
68737 @@ -2459,6 +2512,12 @@ int proc_dostring(struct ctl_table *table, int write,
68738 return -ENOSYS;
68739 }
68740
68741 +int proc_dostring_modpriv(struct ctl_table *table, int write,
68742 + void __user *buffer, size_t *lenp, loff_t *ppos)
68743 +{
68744 + return -ENOSYS;
68745 +}
68746 +
68747 int proc_dointvec(struct ctl_table *table, int write,
68748 void __user *buffer, size_t *lenp, loff_t *ppos)
68749 {
68750 @@ -2515,5 +2574,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
68751 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
68752 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
68753 EXPORT_SYMBOL(proc_dostring);
68754 +EXPORT_SYMBOL(proc_dostring_modpriv);
68755 EXPORT_SYMBOL(proc_doulongvec_minmax);
68756 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
68757 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
68758 index a650694..aaeeb20 100644
68759 --- a/kernel/sysctl_binary.c
68760 +++ b/kernel/sysctl_binary.c
68761 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
68762 int i;
68763
68764 set_fs(KERNEL_DS);
68765 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
68766 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
68767 set_fs(old_fs);
68768 if (result < 0)
68769 goto out_kfree;
68770 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
68771 }
68772
68773 set_fs(KERNEL_DS);
68774 - result = vfs_write(file, buffer, str - buffer, &pos);
68775 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
68776 set_fs(old_fs);
68777 if (result < 0)
68778 goto out_kfree;
68779 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
68780 int i;
68781
68782 set_fs(KERNEL_DS);
68783 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
68784 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
68785 set_fs(old_fs);
68786 if (result < 0)
68787 goto out_kfree;
68788 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
68789 }
68790
68791 set_fs(KERNEL_DS);
68792 - result = vfs_write(file, buffer, str - buffer, &pos);
68793 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
68794 set_fs(old_fs);
68795 if (result < 0)
68796 goto out_kfree;
68797 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
68798 int i;
68799
68800 set_fs(KERNEL_DS);
68801 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
68802 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
68803 set_fs(old_fs);
68804 if (result < 0)
68805 goto out;
68806 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
68807 __le16 dnaddr;
68808
68809 set_fs(KERNEL_DS);
68810 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
68811 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
68812 set_fs(old_fs);
68813 if (result < 0)
68814 goto out;
68815 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
68816 le16_to_cpu(dnaddr) & 0x3ff);
68817
68818 set_fs(KERNEL_DS);
68819 - result = vfs_write(file, buf, len, &pos);
68820 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
68821 set_fs(old_fs);
68822 if (result < 0)
68823 goto out;
68824 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
68825 index e660464..c8b9e67 100644
68826 --- a/kernel/taskstats.c
68827 +++ b/kernel/taskstats.c
68828 @@ -27,9 +27,12 @@
68829 #include <linux/cgroup.h>
68830 #include <linux/fs.h>
68831 #include <linux/file.h>
68832 +#include <linux/grsecurity.h>
68833 #include <net/genetlink.h>
68834 #include <linux/atomic.h>
68835
68836 +extern int gr_is_taskstats_denied(int pid);
68837 +
68838 /*
68839 * Maximum length of a cpumask that can be specified in
68840 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
68841 @@ -556,6 +559,9 @@ err:
68842
68843 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
68844 {
68845 + if (gr_is_taskstats_denied(current->pid))
68846 + return -EACCES;
68847 +
68848 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
68849 return cmd_attr_register_cpumask(info);
68850 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
68851 diff --git a/kernel/time.c b/kernel/time.c
68852 index ba744cf..267b7c5 100644
68853 --- a/kernel/time.c
68854 +++ b/kernel/time.c
68855 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
68856 return error;
68857
68858 if (tz) {
68859 + /* we log in do_settimeofday called below, so don't log twice
68860 + */
68861 + if (!tv)
68862 + gr_log_timechange();
68863 +
68864 sys_tz = *tz;
68865 update_vsyscall_tz();
68866 if (firsttime) {
68867 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
68868 index 8a538c5..def79d4 100644
68869 --- a/kernel/time/alarmtimer.c
68870 +++ b/kernel/time/alarmtimer.c
68871 @@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
68872 struct platform_device *pdev;
68873 int error = 0;
68874 int i;
68875 - struct k_clock alarm_clock = {
68876 + static struct k_clock alarm_clock = {
68877 .clock_getres = alarm_clock_getres,
68878 .clock_get = alarm_clock_get,
68879 .timer_create = alarm_timer_create,
68880 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
68881 index f113755..ec24223 100644
68882 --- a/kernel/time/tick-broadcast.c
68883 +++ b/kernel/time/tick-broadcast.c
68884 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
68885 * then clear the broadcast bit.
68886 */
68887 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
68888 - int cpu = smp_processor_id();
68889 + cpu = smp_processor_id();
68890
68891 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
68892 tick_broadcast_clear_oneshot(cpu);
68893 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
68894 index 7c50de8..e29a94d 100644
68895 --- a/kernel/time/timekeeping.c
68896 +++ b/kernel/time/timekeeping.c
68897 @@ -14,6 +14,7 @@
68898 #include <linux/init.h>
68899 #include <linux/mm.h>
68900 #include <linux/sched.h>
68901 +#include <linux/grsecurity.h>
68902 #include <linux/syscore_ops.h>
68903 #include <linux/clocksource.h>
68904 #include <linux/jiffies.h>
68905 @@ -388,6 +389,8 @@ int do_settimeofday(const struct timespec *tv)
68906 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
68907 return -EINVAL;
68908
68909 + gr_log_timechange();
68910 +
68911 write_seqlock_irqsave(&timekeeper.lock, flags);
68912
68913 timekeeping_forward_now();
68914 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
68915 index 3258455..f35227d 100644
68916 --- a/kernel/time/timer_list.c
68917 +++ b/kernel/time/timer_list.c
68918 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
68919
68920 static void print_name_offset(struct seq_file *m, void *sym)
68921 {
68922 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68923 + SEQ_printf(m, "<%p>", NULL);
68924 +#else
68925 char symname[KSYM_NAME_LEN];
68926
68927 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
68928 SEQ_printf(m, "<%pK>", sym);
68929 else
68930 SEQ_printf(m, "%s", symname);
68931 +#endif
68932 }
68933
68934 static void
68935 @@ -112,7 +116,11 @@ next_one:
68936 static void
68937 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
68938 {
68939 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68940 + SEQ_printf(m, " .base: %p\n", NULL);
68941 +#else
68942 SEQ_printf(m, " .base: %pK\n", base);
68943 +#endif
68944 SEQ_printf(m, " .index: %d\n",
68945 base->index);
68946 SEQ_printf(m, " .resolution: %Lu nsecs\n",
68947 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
68948 {
68949 struct proc_dir_entry *pe;
68950
68951 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
68952 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
68953 +#else
68954 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
68955 +#endif
68956 if (!pe)
68957 return -ENOMEM;
68958 return 0;
68959 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
68960 index 0b537f2..9e71eca 100644
68961 --- a/kernel/time/timer_stats.c
68962 +++ b/kernel/time/timer_stats.c
68963 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
68964 static unsigned long nr_entries;
68965 static struct entry entries[MAX_ENTRIES];
68966
68967 -static atomic_t overflow_count;
68968 +static atomic_unchecked_t overflow_count;
68969
68970 /*
68971 * The entries are in a hash-table, for fast lookup:
68972 @@ -140,7 +140,7 @@ static void reset_entries(void)
68973 nr_entries = 0;
68974 memset(entries, 0, sizeof(entries));
68975 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
68976 - atomic_set(&overflow_count, 0);
68977 + atomic_set_unchecked(&overflow_count, 0);
68978 }
68979
68980 static struct entry *alloc_entry(void)
68981 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
68982 if (likely(entry))
68983 entry->count++;
68984 else
68985 - atomic_inc(&overflow_count);
68986 + atomic_inc_unchecked(&overflow_count);
68987
68988 out_unlock:
68989 raw_spin_unlock_irqrestore(lock, flags);
68990 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
68991
68992 static void print_name_offset(struct seq_file *m, unsigned long addr)
68993 {
68994 +#ifdef CONFIG_GRKERNSEC_HIDESYM
68995 + seq_printf(m, "<%p>", NULL);
68996 +#else
68997 char symname[KSYM_NAME_LEN];
68998
68999 if (lookup_symbol_name(addr, symname) < 0)
69000 seq_printf(m, "<%p>", (void *)addr);
69001 else
69002 seq_printf(m, "%s", symname);
69003 +#endif
69004 }
69005
69006 static int tstats_show(struct seq_file *m, void *v)
69007 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
69008
69009 seq_puts(m, "Timer Stats Version: v0.2\n");
69010 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
69011 - if (atomic_read(&overflow_count))
69012 + if (atomic_read_unchecked(&overflow_count))
69013 seq_printf(m, "Overflow: %d entries\n",
69014 - atomic_read(&overflow_count));
69015 + atomic_read_unchecked(&overflow_count));
69016
69017 for (i = 0; i < nr_entries; i++) {
69018 entry = entries + i;
69019 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
69020 {
69021 struct proc_dir_entry *pe;
69022
69023 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69024 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
69025 +#else
69026 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
69027 +#endif
69028 if (!pe)
69029 return -ENOMEM;
69030 return 0;
69031 diff --git a/kernel/timer.c b/kernel/timer.c
69032 index a297ffc..5e16b0b 100644
69033 --- a/kernel/timer.c
69034 +++ b/kernel/timer.c
69035 @@ -1354,7 +1354,7 @@ void update_process_times(int user_tick)
69036 /*
69037 * This function runs timers and the timer-tq in bottom half context.
69038 */
69039 -static void run_timer_softirq(struct softirq_action *h)
69040 +static void run_timer_softirq(void)
69041 {
69042 struct tvec_base *base = __this_cpu_read(tvec_bases);
69043
69044 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
69045 index c0bd030..62a1927 100644
69046 --- a/kernel/trace/blktrace.c
69047 +++ b/kernel/trace/blktrace.c
69048 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
69049 struct blk_trace *bt = filp->private_data;
69050 char buf[16];
69051
69052 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
69053 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
69054
69055 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
69056 }
69057 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
69058 return 1;
69059
69060 bt = buf->chan->private_data;
69061 - atomic_inc(&bt->dropped);
69062 + atomic_inc_unchecked(&bt->dropped);
69063 return 0;
69064 }
69065
69066 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
69067
69068 bt->dir = dir;
69069 bt->dev = dev;
69070 - atomic_set(&bt->dropped, 0);
69071 + atomic_set_unchecked(&bt->dropped, 0);
69072
69073 ret = -EIO;
69074 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
69075 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
69076 index 0fa92f6..89950b2 100644
69077 --- a/kernel/trace/ftrace.c
69078 +++ b/kernel/trace/ftrace.c
69079 @@ -1800,12 +1800,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
69080 if (unlikely(ftrace_disabled))
69081 return 0;
69082
69083 + ret = ftrace_arch_code_modify_prepare();
69084 + FTRACE_WARN_ON(ret);
69085 + if (ret)
69086 + return 0;
69087 +
69088 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
69089 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
69090 if (ret) {
69091 ftrace_bug(ret, ip);
69092 - return 0;
69093 }
69094 - return 1;
69095 + return ret ? 0 : 1;
69096 }
69097
69098 /*
69099 @@ -2917,7 +2922,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
69100
69101 int
69102 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
69103 - void *data)
69104 + void *data)
69105 {
69106 struct ftrace_func_probe *entry;
69107 struct ftrace_page *pg;
69108 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
69109 index 55e4d4c..8c915ec 100644
69110 --- a/kernel/trace/trace.c
69111 +++ b/kernel/trace/trace.c
69112 @@ -4316,10 +4316,9 @@ static const struct file_operations tracing_dyn_info_fops = {
69113 };
69114 #endif
69115
69116 -static struct dentry *d_tracer;
69117 -
69118 struct dentry *tracing_init_dentry(void)
69119 {
69120 + static struct dentry *d_tracer;
69121 static int once;
69122
69123 if (d_tracer)
69124 @@ -4339,10 +4338,9 @@ struct dentry *tracing_init_dentry(void)
69125 return d_tracer;
69126 }
69127
69128 -static struct dentry *d_percpu;
69129 -
69130 struct dentry *tracing_dentry_percpu(void)
69131 {
69132 + static struct dentry *d_percpu;
69133 static int once;
69134 struct dentry *d_tracer;
69135
69136 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
69137 index 29111da..d190fe2 100644
69138 --- a/kernel/trace/trace_events.c
69139 +++ b/kernel/trace/trace_events.c
69140 @@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
69141 struct ftrace_module_file_ops {
69142 struct list_head list;
69143 struct module *mod;
69144 - struct file_operations id;
69145 - struct file_operations enable;
69146 - struct file_operations format;
69147 - struct file_operations filter;
69148 };
69149
69150 static struct ftrace_module_file_ops *
69151 @@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
69152
69153 file_ops->mod = mod;
69154
69155 - file_ops->id = ftrace_event_id_fops;
69156 - file_ops->id.owner = mod;
69157 -
69158 - file_ops->enable = ftrace_enable_fops;
69159 - file_ops->enable.owner = mod;
69160 -
69161 - file_ops->filter = ftrace_event_filter_fops;
69162 - file_ops->filter.owner = mod;
69163 -
69164 - file_ops->format = ftrace_event_format_fops;
69165 - file_ops->format.owner = mod;
69166 + pax_open_kernel();
69167 + *(void **)&mod->trace_id.owner = mod;
69168 + *(void **)&mod->trace_enable.owner = mod;
69169 + *(void **)&mod->trace_filter.owner = mod;
69170 + *(void **)&mod->trace_format.owner = mod;
69171 + pax_close_kernel();
69172
69173 list_add(&file_ops->list, &ftrace_module_file_list);
69174
69175 @@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
69176
69177 for_each_event(call, start, end) {
69178 __trace_add_event_call(*call, mod,
69179 - &file_ops->id, &file_ops->enable,
69180 - &file_ops->filter, &file_ops->format);
69181 + &mod->trace_id, &mod->trace_enable,
69182 + &mod->trace_filter, &mod->trace_format);
69183 }
69184 }
69185
69186 diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
69187 index 580a05e..9b31acb 100644
69188 --- a/kernel/trace/trace_kprobe.c
69189 +++ b/kernel/trace/trace_kprobe.c
69190 @@ -217,7 +217,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69191 long ret;
69192 int maxlen = get_rloc_len(*(u32 *)dest);
69193 u8 *dst = get_rloc_data(dest);
69194 - u8 *src = addr;
69195 + const u8 __user *src = (const u8 __force_user *)addr;
69196 mm_segment_t old_fs = get_fs();
69197 if (!maxlen)
69198 return;
69199 @@ -229,7 +229,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69200 pagefault_disable();
69201 do
69202 ret = __copy_from_user_inatomic(dst++, src++, 1);
69203 - while (dst[-1] && ret == 0 && src - (u8 *)addr < maxlen);
69204 + while (dst[-1] && ret == 0 && src - (const u8 __force_user *)addr < maxlen);
69205 dst[-1] = '\0';
69206 pagefault_enable();
69207 set_fs(old_fs);
69208 @@ -238,7 +238,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69209 ((u8 *)get_rloc_data(dest))[0] = '\0';
69210 *(u32 *)dest = make_data_rloc(0, get_rloc_offs(*(u32 *)dest));
69211 } else
69212 - *(u32 *)dest = make_data_rloc(src - (u8 *)addr,
69213 + *(u32 *)dest = make_data_rloc(src - (const u8 __force_user *)addr,
69214 get_rloc_offs(*(u32 *)dest));
69215 }
69216 /* Return the length of string -- including null terminal byte */
69217 @@ -252,7 +252,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string_size)(struct pt_regs *regs,
69218 set_fs(KERNEL_DS);
69219 pagefault_disable();
69220 do {
69221 - ret = __copy_from_user_inatomic(&c, (u8 *)addr + len, 1);
69222 + ret = __copy_from_user_inatomic(&c, (const u8 __force_user *)addr + len, 1);
69223 len++;
69224 } while (c && ret == 0 && len < MAX_STRING_SIZE);
69225 pagefault_enable();
69226 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
69227 index fd3c8aa..5f324a6 100644
69228 --- a/kernel/trace/trace_mmiotrace.c
69229 +++ b/kernel/trace/trace_mmiotrace.c
69230 @@ -24,7 +24,7 @@ struct header_iter {
69231 static struct trace_array *mmio_trace_array;
69232 static bool overrun_detected;
69233 static unsigned long prev_overruns;
69234 -static atomic_t dropped_count;
69235 +static atomic_unchecked_t dropped_count;
69236
69237 static void mmio_reset_data(struct trace_array *tr)
69238 {
69239 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
69240
69241 static unsigned long count_overruns(struct trace_iterator *iter)
69242 {
69243 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
69244 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
69245 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
69246
69247 if (over > prev_overruns)
69248 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
69249 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
69250 sizeof(*entry), 0, pc);
69251 if (!event) {
69252 - atomic_inc(&dropped_count);
69253 + atomic_inc_unchecked(&dropped_count);
69254 return;
69255 }
69256 entry = ring_buffer_event_data(event);
69257 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
69258 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
69259 sizeof(*entry), 0, pc);
69260 if (!event) {
69261 - atomic_inc(&dropped_count);
69262 + atomic_inc_unchecked(&dropped_count);
69263 return;
69264 }
69265 entry = ring_buffer_event_data(event);
69266 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
69267 index df611a0..10d8b32 100644
69268 --- a/kernel/trace/trace_output.c
69269 +++ b/kernel/trace/trace_output.c
69270 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
69271
69272 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
69273 if (!IS_ERR(p)) {
69274 - p = mangle_path(s->buffer + s->len, p, "\n");
69275 + p = mangle_path(s->buffer + s->len, p, "\n\\");
69276 if (p) {
69277 s->len = p - s->buffer;
69278 return 1;
69279 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
69280 index d4545f4..a9010a1 100644
69281 --- a/kernel/trace/trace_stack.c
69282 +++ b/kernel/trace/trace_stack.c
69283 @@ -53,7 +53,7 @@ static inline void check_stack(void)
69284 return;
69285
69286 /* we do not handle interrupt stacks yet */
69287 - if (!object_is_on_stack(&this_size))
69288 + if (!object_starts_on_stack(&this_size))
69289 return;
69290
69291 local_irq_save(flags);
69292 diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c
69293 index 209b379..7f76423 100644
69294 --- a/kernel/trace/trace_workqueue.c
69295 +++ b/kernel/trace/trace_workqueue.c
69296 @@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
69297 int cpu;
69298 pid_t pid;
69299 /* Can be inserted from interrupt or user context, need to be atomic */
69300 - atomic_t inserted;
69301 + atomic_unchecked_t inserted;
69302 /*
69303 * Don't need to be atomic, works are serialized in a single workqueue thread
69304 * on a single CPU.
69305 @@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
69306 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
69307 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
69308 if (node->pid == wq_thread->pid) {
69309 - atomic_inc(&node->inserted);
69310 + atomic_inc_unchecked(&node->inserted);
69311 goto found;
69312 }
69313 }
69314 @@ -210,7 +210,7 @@ static int workqueue_stat_show(struct seq_file *s, void *p)
69315 tsk = get_pid_task(pid, PIDTYPE_PID);
69316 if (tsk) {
69317 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
69318 - atomic_read(&cws->inserted), cws->executed,
69319 + atomic_read_unchecked(&cws->inserted), cws->executed,
69320 tsk->comm);
69321 put_task_struct(tsk);
69322 }
69323 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
69324 index 6777153..8519f60 100644
69325 --- a/lib/Kconfig.debug
69326 +++ b/lib/Kconfig.debug
69327 @@ -1132,6 +1132,7 @@ config LATENCYTOP
69328 depends on DEBUG_KERNEL
69329 depends on STACKTRACE_SUPPORT
69330 depends on PROC_FS
69331 + depends on !GRKERNSEC_HIDESYM
69332 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
69333 select KALLSYMS
69334 select KALLSYMS_ALL
69335 diff --git a/lib/bitmap.c b/lib/bitmap.c
69336 index b5a8b6a..a69623c 100644
69337 --- a/lib/bitmap.c
69338 +++ b/lib/bitmap.c
69339 @@ -421,7 +421,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
69340 {
69341 int c, old_c, totaldigits, ndigits, nchunks, nbits;
69342 u32 chunk;
69343 - const char __user __force *ubuf = (const char __user __force *)buf;
69344 + const char __user *ubuf = (const char __force_user *)buf;
69345
69346 bitmap_zero(maskp, nmaskbits);
69347
69348 @@ -506,7 +506,7 @@ int bitmap_parse_user(const char __user *ubuf,
69349 {
69350 if (!access_ok(VERIFY_READ, ubuf, ulen))
69351 return -EFAULT;
69352 - return __bitmap_parse((const char __force *)ubuf,
69353 + return __bitmap_parse((const char __force_kernel *)ubuf,
69354 ulen, 1, maskp, nmaskbits);
69355
69356 }
69357 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
69358 {
69359 unsigned a, b;
69360 int c, old_c, totaldigits;
69361 - const char __user __force *ubuf = (const char __user __force *)buf;
69362 + const char __user *ubuf = (const char __force_user *)buf;
69363 int exp_digit, in_range;
69364
69365 totaldigits = c = 0;
69366 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
69367 {
69368 if (!access_ok(VERIFY_READ, ubuf, ulen))
69369 return -EFAULT;
69370 - return __bitmap_parselist((const char __force *)ubuf,
69371 + return __bitmap_parselist((const char __force_kernel *)ubuf,
69372 ulen, 1, maskp, nmaskbits);
69373 }
69374 EXPORT_SYMBOL(bitmap_parselist_user);
69375 diff --git a/lib/bug.c b/lib/bug.c
69376 index a28c141..2bd3d95 100644
69377 --- a/lib/bug.c
69378 +++ b/lib/bug.c
69379 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
69380 return BUG_TRAP_TYPE_NONE;
69381
69382 bug = find_bug(bugaddr);
69383 + if (!bug)
69384 + return BUG_TRAP_TYPE_NONE;
69385
69386 file = NULL;
69387 line = 0;
69388 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
69389 index 0ab9ae8..f01ceca 100644
69390 --- a/lib/debugobjects.c
69391 +++ b/lib/debugobjects.c
69392 @@ -288,7 +288,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
69393 if (limit > 4)
69394 return;
69395
69396 - is_on_stack = object_is_on_stack(addr);
69397 + is_on_stack = object_starts_on_stack(addr);
69398 if (is_on_stack == onstack)
69399 return;
69400
69401 diff --git a/lib/devres.c b/lib/devres.c
69402 index 80b9c76..9e32279 100644
69403 --- a/lib/devres.c
69404 +++ b/lib/devres.c
69405 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
69406 void devm_iounmap(struct device *dev, void __iomem *addr)
69407 {
69408 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
69409 - (void *)addr));
69410 + (void __force *)addr));
69411 iounmap(addr);
69412 }
69413 EXPORT_SYMBOL(devm_iounmap);
69414 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
69415 {
69416 ioport_unmap(addr);
69417 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
69418 - devm_ioport_map_match, (void *)addr));
69419 + devm_ioport_map_match, (void __force *)addr));
69420 }
69421 EXPORT_SYMBOL(devm_ioport_unmap);
69422
69423 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
69424 index 13ef233..5241683 100644
69425 --- a/lib/dma-debug.c
69426 +++ b/lib/dma-debug.c
69427 @@ -924,7 +924,7 @@ out:
69428
69429 static void check_for_stack(struct device *dev, void *addr)
69430 {
69431 - if (object_is_on_stack(addr))
69432 + if (object_starts_on_stack(addr))
69433 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
69434 "stack [addr=%p]\n", addr);
69435 }
69436 diff --git a/lib/extable.c b/lib/extable.c
69437 index 4cac81e..63e9b8f 100644
69438 --- a/lib/extable.c
69439 +++ b/lib/extable.c
69440 @@ -13,6 +13,7 @@
69441 #include <linux/init.h>
69442 #include <linux/sort.h>
69443 #include <asm/uaccess.h>
69444 +#include <asm/pgtable.h>
69445
69446 #ifndef ARCH_HAS_SORT_EXTABLE
69447 /*
69448 @@ -36,8 +37,10 @@ static int cmp_ex(const void *a, const void *b)
69449 void sort_extable(struct exception_table_entry *start,
69450 struct exception_table_entry *finish)
69451 {
69452 + pax_open_kernel();
69453 sort(start, finish - start, sizeof(struct exception_table_entry),
69454 cmp_ex, NULL);
69455 + pax_close_kernel();
69456 }
69457
69458 #ifdef CONFIG_MODULES
69459 diff --git a/lib/inflate.c b/lib/inflate.c
69460 index 013a761..c28f3fc 100644
69461 --- a/lib/inflate.c
69462 +++ b/lib/inflate.c
69463 @@ -269,7 +269,7 @@ static void free(void *where)
69464 malloc_ptr = free_mem_ptr;
69465 }
69466 #else
69467 -#define malloc(a) kmalloc(a, GFP_KERNEL)
69468 +#define malloc(a) kmalloc((a), GFP_KERNEL)
69469 #define free(a) kfree(a)
69470 #endif
69471
69472 diff --git a/lib/ioremap.c b/lib/ioremap.c
69473 index 0c9216c..863bd89 100644
69474 --- a/lib/ioremap.c
69475 +++ b/lib/ioremap.c
69476 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
69477 unsigned long next;
69478
69479 phys_addr -= addr;
69480 - pmd = pmd_alloc(&init_mm, pud, addr);
69481 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
69482 if (!pmd)
69483 return -ENOMEM;
69484 do {
69485 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
69486 unsigned long next;
69487
69488 phys_addr -= addr;
69489 - pud = pud_alloc(&init_mm, pgd, addr);
69490 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
69491 if (!pud)
69492 return -ENOMEM;
69493 do {
69494 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
69495 index bd2bea9..6b3c95e 100644
69496 --- a/lib/is_single_threaded.c
69497 +++ b/lib/is_single_threaded.c
69498 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
69499 struct task_struct *p, *t;
69500 bool ret;
69501
69502 + if (!mm)
69503 + return true;
69504 +
69505 if (atomic_read(&task->signal->live) != 1)
69506 return false;
69507
69508 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
69509 index 3ac50dc..240bb7e 100644
69510 --- a/lib/radix-tree.c
69511 +++ b/lib/radix-tree.c
69512 @@ -79,7 +79,7 @@ struct radix_tree_preload {
69513 int nr;
69514 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
69515 };
69516 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
69517 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
69518
69519 static inline void *ptr_to_indirect(void *ptr)
69520 {
69521 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
69522 index abbabec..362988d 100644
69523 --- a/lib/vsprintf.c
69524 +++ b/lib/vsprintf.c
69525 @@ -16,6 +16,9 @@
69526 * - scnprintf and vscnprintf
69527 */
69528
69529 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69530 +#define __INCLUDED_BY_HIDESYM 1
69531 +#endif
69532 #include <stdarg.h>
69533 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
69534 #include <linux/types.h>
69535 @@ -433,7 +436,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
69536 char sym[KSYM_SYMBOL_LEN];
69537 if (ext == 'B')
69538 sprint_backtrace(sym, value);
69539 - else if (ext != 'f' && ext != 's')
69540 + else if (ext != 'f' && ext != 's' && ext != 'a')
69541 sprint_symbol(sym, value);
69542 else
69543 kallsyms_lookup(value, NULL, NULL, NULL, sym);
69544 @@ -809,7 +812,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
69545 return number(buf, end, *(const netdev_features_t *)addr, spec);
69546 }
69547
69548 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69549 +int kptr_restrict __read_mostly = 2;
69550 +#else
69551 int kptr_restrict __read_mostly;
69552 +#endif
69553
69554 /*
69555 * Show a '%p' thing. A kernel extension is that the '%p' is followed
69556 @@ -823,6 +830,8 @@ int kptr_restrict __read_mostly;
69557 * - 'S' For symbolic direct pointers with offset
69558 * - 's' For symbolic direct pointers without offset
69559 * - 'B' For backtraced symbolic direct pointers with offset
69560 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
69561 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
69562 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
69563 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
69564 * - 'M' For a 6-byte MAC address, it prints the address in the
69565 @@ -868,12 +877,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
69566 {
69567 if (!ptr && *fmt != 'K') {
69568 /*
69569 - * Print (null) with the same width as a pointer so it makes
69570 + * Print (nil) with the same width as a pointer so it makes
69571 * tabular output look nice.
69572 */
69573 if (spec.field_width == -1)
69574 spec.field_width = 2 * sizeof(void *);
69575 - return string(buf, end, "(null)", spec);
69576 + return string(buf, end, "(nil)", spec);
69577 }
69578
69579 switch (*fmt) {
69580 @@ -883,6 +892,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
69581 /* Fallthrough */
69582 case 'S':
69583 case 's':
69584 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69585 + break;
69586 +#else
69587 + return symbol_string(buf, end, ptr, spec, *fmt);
69588 +#endif
69589 + case 'A':
69590 + case 'a':
69591 case 'B':
69592 return symbol_string(buf, end, ptr, spec, *fmt);
69593 case 'R':
69594 @@ -1653,11 +1669,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
69595 typeof(type) value; \
69596 if (sizeof(type) == 8) { \
69597 args = PTR_ALIGN(args, sizeof(u32)); \
69598 - *(u32 *)&value = *(u32 *)args; \
69599 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
69600 + *(u32 *)&value = *(const u32 *)args; \
69601 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
69602 } else { \
69603 args = PTR_ALIGN(args, sizeof(type)); \
69604 - value = *(typeof(type) *)args; \
69605 + value = *(const typeof(type) *)args; \
69606 } \
69607 args += sizeof(type); \
69608 value; \
69609 @@ -1720,7 +1736,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
69610 case FORMAT_TYPE_STR: {
69611 const char *str_arg = args;
69612 args += strlen(str_arg) + 1;
69613 - str = string(str, end, (char *)str_arg, spec);
69614 + str = string(str, end, str_arg, spec);
69615 break;
69616 }
69617
69618 diff --git a/localversion-grsec b/localversion-grsec
69619 new file mode 100644
69620 index 0000000..7cd6065
69621 --- /dev/null
69622 +++ b/localversion-grsec
69623 @@ -0,0 +1 @@
69624 +-grsec
69625 diff --git a/mm/Kconfig b/mm/Kconfig
69626 index e338407..4210331 100644
69627 --- a/mm/Kconfig
69628 +++ b/mm/Kconfig
69629 @@ -247,10 +247,10 @@ config KSM
69630 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
69631
69632 config DEFAULT_MMAP_MIN_ADDR
69633 - int "Low address space to protect from user allocation"
69634 + int "Low address space to protect from user allocation"
69635 depends on MMU
69636 - default 4096
69637 - help
69638 + default 65536
69639 + help
69640 This is the portion of low virtual memory which should be protected
69641 from userspace allocation. Keeping a user from writing to low pages
69642 can help reduce the impact of kernel NULL pointer bugs.
69643 @@ -280,7 +280,7 @@ config MEMORY_FAILURE
69644
69645 config HWPOISON_INJECT
69646 tristate "HWPoison pages injector"
69647 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
69648 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
69649 select PROC_PAGE_MONITOR
69650
69651 config NOMMU_INITIAL_TRIM_EXCESS
69652 diff --git a/mm/filemap.c b/mm/filemap.c
69653 index 79c4b2b..596b417 100644
69654 --- a/mm/filemap.c
69655 +++ b/mm/filemap.c
69656 @@ -1762,7 +1762,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
69657 struct address_space *mapping = file->f_mapping;
69658
69659 if (!mapping->a_ops->readpage)
69660 - return -ENOEXEC;
69661 + return -ENODEV;
69662 file_accessed(file);
69663 vma->vm_ops = &generic_file_vm_ops;
69664 vma->vm_flags |= VM_CAN_NONLINEAR;
69665 @@ -2168,6 +2168,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
69666 *pos = i_size_read(inode);
69667
69668 if (limit != RLIM_INFINITY) {
69669 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
69670 if (*pos >= limit) {
69671 send_sig(SIGXFSZ, current, 0);
69672 return -EFBIG;
69673 diff --git a/mm/fremap.c b/mm/fremap.c
69674 index 9ed4fd4..c42648d 100644
69675 --- a/mm/fremap.c
69676 +++ b/mm/fremap.c
69677 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
69678 retry:
69679 vma = find_vma(mm, start);
69680
69681 +#ifdef CONFIG_PAX_SEGMEXEC
69682 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
69683 + goto out;
69684 +#endif
69685 +
69686 /*
69687 * Make sure the vma is shared, that it supports prefaulting,
69688 * and that the remapped range is valid and fully within
69689 diff --git a/mm/highmem.c b/mm/highmem.c
69690 index 57d82c6..e9e0552 100644
69691 --- a/mm/highmem.c
69692 +++ b/mm/highmem.c
69693 @@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
69694 * So no dangers, even with speculative execution.
69695 */
69696 page = pte_page(pkmap_page_table[i]);
69697 + pax_open_kernel();
69698 pte_clear(&init_mm, (unsigned long)page_address(page),
69699 &pkmap_page_table[i]);
69700 -
69701 + pax_close_kernel();
69702 set_page_address(page, NULL);
69703 need_flush = 1;
69704 }
69705 @@ -186,9 +187,11 @@ start:
69706 }
69707 }
69708 vaddr = PKMAP_ADDR(last_pkmap_nr);
69709 +
69710 + pax_open_kernel();
69711 set_pte_at(&init_mm, vaddr,
69712 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
69713 -
69714 + pax_close_kernel();
69715 pkmap_count[last_pkmap_nr] = 1;
69716 set_page_address(page, (void *)vaddr);
69717
69718 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
69719 index f0e5306..cb9398e 100644
69720 --- a/mm/huge_memory.c
69721 +++ b/mm/huge_memory.c
69722 @@ -733,7 +733,7 @@ out:
69723 * run pte_offset_map on the pmd, if an huge pmd could
69724 * materialize from under us from a different thread.
69725 */
69726 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
69727 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
69728 return VM_FAULT_OOM;
69729 /* if an huge pmd materialized from under us just retry later */
69730 if (unlikely(pmd_trans_huge(*pmd)))
69731 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
69732 index 263e177..3f36aec 100644
69733 --- a/mm/hugetlb.c
69734 +++ b/mm/hugetlb.c
69735 @@ -2446,6 +2446,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
69736 return 1;
69737 }
69738
69739 +#ifdef CONFIG_PAX_SEGMEXEC
69740 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
69741 +{
69742 + struct mm_struct *mm = vma->vm_mm;
69743 + struct vm_area_struct *vma_m;
69744 + unsigned long address_m;
69745 + pte_t *ptep_m;
69746 +
69747 + vma_m = pax_find_mirror_vma(vma);
69748 + if (!vma_m)
69749 + return;
69750 +
69751 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
69752 + address_m = address + SEGMEXEC_TASK_SIZE;
69753 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
69754 + get_page(page_m);
69755 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
69756 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
69757 +}
69758 +#endif
69759 +
69760 /*
69761 * Hugetlb_cow() should be called with page lock of the original hugepage held.
69762 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
69763 @@ -2558,6 +2579,11 @@ retry_avoidcopy:
69764 make_huge_pte(vma, new_page, 1));
69765 page_remove_rmap(old_page);
69766 hugepage_add_new_anon_rmap(new_page, vma, address);
69767 +
69768 +#ifdef CONFIG_PAX_SEGMEXEC
69769 + pax_mirror_huge_pte(vma, address, new_page);
69770 +#endif
69771 +
69772 /* Make the old page be freed below */
69773 new_page = old_page;
69774 mmu_notifier_invalidate_range_end(mm,
69775 @@ -2712,6 +2738,10 @@ retry:
69776 && (vma->vm_flags & VM_SHARED)));
69777 set_huge_pte_at(mm, address, ptep, new_pte);
69778
69779 +#ifdef CONFIG_PAX_SEGMEXEC
69780 + pax_mirror_huge_pte(vma, address, page);
69781 +#endif
69782 +
69783 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
69784 /* Optimization, do the COW without a second fault */
69785 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
69786 @@ -2741,6 +2771,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69787 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
69788 struct hstate *h = hstate_vma(vma);
69789
69790 +#ifdef CONFIG_PAX_SEGMEXEC
69791 + struct vm_area_struct *vma_m;
69792 +#endif
69793 +
69794 address &= huge_page_mask(h);
69795
69796 ptep = huge_pte_offset(mm, address);
69797 @@ -2754,6 +2788,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
69798 VM_FAULT_SET_HINDEX(h - hstates);
69799 }
69800
69801 +#ifdef CONFIG_PAX_SEGMEXEC
69802 + vma_m = pax_find_mirror_vma(vma);
69803 + if (vma_m) {
69804 + unsigned long address_m;
69805 +
69806 + if (vma->vm_start > vma_m->vm_start) {
69807 + address_m = address;
69808 + address -= SEGMEXEC_TASK_SIZE;
69809 + vma = vma_m;
69810 + h = hstate_vma(vma);
69811 + } else
69812 + address_m = address + SEGMEXEC_TASK_SIZE;
69813 +
69814 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
69815 + return VM_FAULT_OOM;
69816 + address_m &= HPAGE_MASK;
69817 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
69818 + }
69819 +#endif
69820 +
69821 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
69822 if (!ptep)
69823 return VM_FAULT_OOM;
69824 diff --git a/mm/internal.h b/mm/internal.h
69825 index 2189af4..f2ca332 100644
69826 --- a/mm/internal.h
69827 +++ b/mm/internal.h
69828 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
69829 * in mm/page_alloc.c
69830 */
69831 extern void __free_pages_bootmem(struct page *page, unsigned int order);
69832 +extern void free_compound_page(struct page *page);
69833 extern void prep_compound_page(struct page *page, unsigned long order);
69834 #ifdef CONFIG_MEMORY_FAILURE
69835 extern bool is_free_buddy_page(struct page *page);
69836 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
69837 index 45eb621..6ccd8ea 100644
69838 --- a/mm/kmemleak.c
69839 +++ b/mm/kmemleak.c
69840 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
69841
69842 for (i = 0; i < object->trace_len; i++) {
69843 void *ptr = (void *)object->trace[i];
69844 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
69845 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
69846 }
69847 }
69848
69849 diff --git a/mm/maccess.c b/mm/maccess.c
69850 index d53adf9..03a24bf 100644
69851 --- a/mm/maccess.c
69852 +++ b/mm/maccess.c
69853 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
69854 set_fs(KERNEL_DS);
69855 pagefault_disable();
69856 ret = __copy_from_user_inatomic(dst,
69857 - (__force const void __user *)src, size);
69858 + (const void __force_user *)src, size);
69859 pagefault_enable();
69860 set_fs(old_fs);
69861
69862 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
69863
69864 set_fs(KERNEL_DS);
69865 pagefault_disable();
69866 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
69867 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
69868 pagefault_enable();
69869 set_fs(old_fs);
69870
69871 diff --git a/mm/madvise.c b/mm/madvise.c
69872 index 55f645c..cde5320 100644
69873 --- a/mm/madvise.c
69874 +++ b/mm/madvise.c
69875 @@ -46,6 +46,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
69876 pgoff_t pgoff;
69877 unsigned long new_flags = vma->vm_flags;
69878
69879 +#ifdef CONFIG_PAX_SEGMEXEC
69880 + struct vm_area_struct *vma_m;
69881 +#endif
69882 +
69883 switch (behavior) {
69884 case MADV_NORMAL:
69885 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
69886 @@ -117,6 +121,13 @@ success:
69887 /*
69888 * vm_flags is protected by the mmap_sem held in write mode.
69889 */
69890 +
69891 +#ifdef CONFIG_PAX_SEGMEXEC
69892 + vma_m = pax_find_mirror_vma(vma);
69893 + if (vma_m)
69894 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
69895 +#endif
69896 +
69897 vma->vm_flags = new_flags;
69898
69899 out:
69900 @@ -175,6 +186,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
69901 struct vm_area_struct ** prev,
69902 unsigned long start, unsigned long end)
69903 {
69904 +
69905 +#ifdef CONFIG_PAX_SEGMEXEC
69906 + struct vm_area_struct *vma_m;
69907 +#endif
69908 +
69909 *prev = vma;
69910 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
69911 return -EINVAL;
69912 @@ -187,6 +203,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
69913 zap_page_range(vma, start, end - start, &details);
69914 } else
69915 zap_page_range(vma, start, end - start, NULL);
69916 +
69917 +#ifdef CONFIG_PAX_SEGMEXEC
69918 + vma_m = pax_find_mirror_vma(vma);
69919 + if (vma_m) {
69920 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
69921 + struct zap_details details = {
69922 + .nonlinear_vma = vma_m,
69923 + .last_index = ULONG_MAX,
69924 + };
69925 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
69926 + } else
69927 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
69928 + }
69929 +#endif
69930 +
69931 return 0;
69932 }
69933
69934 @@ -394,6 +425,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
69935 if (end < start)
69936 goto out;
69937
69938 +#ifdef CONFIG_PAX_SEGMEXEC
69939 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
69940 + if (end > SEGMEXEC_TASK_SIZE)
69941 + goto out;
69942 + } else
69943 +#endif
69944 +
69945 + if (end > TASK_SIZE)
69946 + goto out;
69947 +
69948 error = 0;
69949 if (end == start)
69950 goto out;
69951 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
69952 index 97cc273..6ed703f 100644
69953 --- a/mm/memory-failure.c
69954 +++ b/mm/memory-failure.c
69955 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
69956
69957 int sysctl_memory_failure_recovery __read_mostly = 1;
69958
69959 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
69960 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
69961
69962 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
69963
69964 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
69965 pfn, t->comm, t->pid);
69966 si.si_signo = SIGBUS;
69967 si.si_errno = 0;
69968 - si.si_addr = (void *)addr;
69969 + si.si_addr = (void __user *)addr;
69970 #ifdef __ARCH_SI_TRAPNO
69971 si.si_trapno = trapno;
69972 #endif
69973 @@ -1036,7 +1036,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
69974 }
69975
69976 nr_pages = 1 << compound_trans_order(hpage);
69977 - atomic_long_add(nr_pages, &mce_bad_pages);
69978 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
69979
69980 /*
69981 * We need/can do nothing about count=0 pages.
69982 @@ -1066,7 +1066,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
69983 if (!PageHWPoison(hpage)
69984 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
69985 || (p != hpage && TestSetPageHWPoison(hpage))) {
69986 - atomic_long_sub(nr_pages, &mce_bad_pages);
69987 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69988 return 0;
69989 }
69990 set_page_hwpoison_huge_page(hpage);
69991 @@ -1124,7 +1124,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
69992 }
69993 if (hwpoison_filter(p)) {
69994 if (TestClearPageHWPoison(p))
69995 - atomic_long_sub(nr_pages, &mce_bad_pages);
69996 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
69997 unlock_page(hpage);
69998 put_page(hpage);
69999 return 0;
70000 @@ -1319,7 +1319,7 @@ int unpoison_memory(unsigned long pfn)
70001 return 0;
70002 }
70003 if (TestClearPageHWPoison(p))
70004 - atomic_long_sub(nr_pages, &mce_bad_pages);
70005 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70006 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
70007 return 0;
70008 }
70009 @@ -1333,7 +1333,7 @@ int unpoison_memory(unsigned long pfn)
70010 */
70011 if (TestClearPageHWPoison(page)) {
70012 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
70013 - atomic_long_sub(nr_pages, &mce_bad_pages);
70014 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70015 freeit = 1;
70016 if (PageHuge(page))
70017 clear_page_hwpoison_huge_page(page);
70018 @@ -1446,7 +1446,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
70019 }
70020 done:
70021 if (!PageHWPoison(hpage))
70022 - atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
70023 + atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
70024 set_page_hwpoison_huge_page(hpage);
70025 dequeue_hwpoisoned_huge_page(hpage);
70026 /* keep elevated page count for bad page */
70027 @@ -1577,7 +1577,7 @@ int soft_offline_page(struct page *page, int flags)
70028 return ret;
70029
70030 done:
70031 - atomic_long_add(1, &mce_bad_pages);
70032 + atomic_long_add_unchecked(1, &mce_bad_pages);
70033 SetPageHWPoison(page);
70034 /* keep elevated page count for bad page */
70035 return ret;
70036 diff --git a/mm/memory.c b/mm/memory.c
70037 index 6105f47..3363489 100644
70038 --- a/mm/memory.c
70039 +++ b/mm/memory.c
70040 @@ -434,8 +434,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
70041 return;
70042
70043 pmd = pmd_offset(pud, start);
70044 +
70045 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
70046 pud_clear(pud);
70047 pmd_free_tlb(tlb, pmd, start);
70048 +#endif
70049 +
70050 }
70051
70052 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
70053 @@ -466,9 +470,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
70054 if (end - 1 > ceiling - 1)
70055 return;
70056
70057 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
70058 pud = pud_offset(pgd, start);
70059 pgd_clear(pgd);
70060 pud_free_tlb(tlb, pud, start);
70061 +#endif
70062 +
70063 }
70064
70065 /*
70066 @@ -1597,12 +1604,6 @@ no_page_table:
70067 return page;
70068 }
70069
70070 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
70071 -{
70072 - return stack_guard_page_start(vma, addr) ||
70073 - stack_guard_page_end(vma, addr+PAGE_SIZE);
70074 -}
70075 -
70076 /**
70077 * __get_user_pages() - pin user pages in memory
70078 * @tsk: task_struct of target task
70079 @@ -1675,10 +1676,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70080 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
70081 i = 0;
70082
70083 - do {
70084 + while (nr_pages) {
70085 struct vm_area_struct *vma;
70086
70087 - vma = find_extend_vma(mm, start);
70088 + vma = find_vma(mm, start);
70089 if (!vma && in_gate_area(mm, start)) {
70090 unsigned long pg = start & PAGE_MASK;
70091 pgd_t *pgd;
70092 @@ -1726,7 +1727,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70093 goto next_page;
70094 }
70095
70096 - if (!vma ||
70097 + if (!vma || start < vma->vm_start ||
70098 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
70099 !(vm_flags & vma->vm_flags))
70100 return i ? : -EFAULT;
70101 @@ -1753,11 +1754,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70102 int ret;
70103 unsigned int fault_flags = 0;
70104
70105 - /* For mlock, just skip the stack guard page. */
70106 - if (foll_flags & FOLL_MLOCK) {
70107 - if (stack_guard_page(vma, start))
70108 - goto next_page;
70109 - }
70110 if (foll_flags & FOLL_WRITE)
70111 fault_flags |= FAULT_FLAG_WRITE;
70112 if (nonblocking)
70113 @@ -1831,7 +1827,7 @@ next_page:
70114 start += PAGE_SIZE;
70115 nr_pages--;
70116 } while (nr_pages && start < vma->vm_end);
70117 - } while (nr_pages);
70118 + }
70119 return i;
70120 }
70121 EXPORT_SYMBOL(__get_user_pages);
70122 @@ -2038,6 +2034,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
70123 page_add_file_rmap(page);
70124 set_pte_at(mm, addr, pte, mk_pte(page, prot));
70125
70126 +#ifdef CONFIG_PAX_SEGMEXEC
70127 + pax_mirror_file_pte(vma, addr, page, ptl);
70128 +#endif
70129 +
70130 retval = 0;
70131 pte_unmap_unlock(pte, ptl);
70132 return retval;
70133 @@ -2072,10 +2072,22 @@ out:
70134 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
70135 struct page *page)
70136 {
70137 +
70138 +#ifdef CONFIG_PAX_SEGMEXEC
70139 + struct vm_area_struct *vma_m;
70140 +#endif
70141 +
70142 if (addr < vma->vm_start || addr >= vma->vm_end)
70143 return -EFAULT;
70144 if (!page_count(page))
70145 return -EINVAL;
70146 +
70147 +#ifdef CONFIG_PAX_SEGMEXEC
70148 + vma_m = pax_find_mirror_vma(vma);
70149 + if (vma_m)
70150 + vma_m->vm_flags |= VM_INSERTPAGE;
70151 +#endif
70152 +
70153 vma->vm_flags |= VM_INSERTPAGE;
70154 return insert_page(vma, addr, page, vma->vm_page_prot);
70155 }
70156 @@ -2161,6 +2173,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
70157 unsigned long pfn)
70158 {
70159 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
70160 + BUG_ON(vma->vm_mirror);
70161
70162 if (addr < vma->vm_start || addr >= vma->vm_end)
70163 return -EFAULT;
70164 @@ -2368,7 +2381,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
70165
70166 BUG_ON(pud_huge(*pud));
70167
70168 - pmd = pmd_alloc(mm, pud, addr);
70169 + pmd = (mm == &init_mm) ?
70170 + pmd_alloc_kernel(mm, pud, addr) :
70171 + pmd_alloc(mm, pud, addr);
70172 if (!pmd)
70173 return -ENOMEM;
70174 do {
70175 @@ -2388,7 +2403,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
70176 unsigned long next;
70177 int err;
70178
70179 - pud = pud_alloc(mm, pgd, addr);
70180 + pud = (mm == &init_mm) ?
70181 + pud_alloc_kernel(mm, pgd, addr) :
70182 + pud_alloc(mm, pgd, addr);
70183 if (!pud)
70184 return -ENOMEM;
70185 do {
70186 @@ -2476,6 +2493,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
70187 copy_user_highpage(dst, src, va, vma);
70188 }
70189
70190 +#ifdef CONFIG_PAX_SEGMEXEC
70191 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
70192 +{
70193 + struct mm_struct *mm = vma->vm_mm;
70194 + spinlock_t *ptl;
70195 + pte_t *pte, entry;
70196 +
70197 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
70198 + entry = *pte;
70199 + if (!pte_present(entry)) {
70200 + if (!pte_none(entry)) {
70201 + BUG_ON(pte_file(entry));
70202 + free_swap_and_cache(pte_to_swp_entry(entry));
70203 + pte_clear_not_present_full(mm, address, pte, 0);
70204 + }
70205 + } else {
70206 + struct page *page;
70207 +
70208 + flush_cache_page(vma, address, pte_pfn(entry));
70209 + entry = ptep_clear_flush(vma, address, pte);
70210 + BUG_ON(pte_dirty(entry));
70211 + page = vm_normal_page(vma, address, entry);
70212 + if (page) {
70213 + update_hiwater_rss(mm);
70214 + if (PageAnon(page))
70215 + dec_mm_counter_fast(mm, MM_ANONPAGES);
70216 + else
70217 + dec_mm_counter_fast(mm, MM_FILEPAGES);
70218 + page_remove_rmap(page);
70219 + page_cache_release(page);
70220 + }
70221 + }
70222 + pte_unmap_unlock(pte, ptl);
70223 +}
70224 +
70225 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
70226 + *
70227 + * the ptl of the lower mapped page is held on entry and is not released on exit
70228 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
70229 + */
70230 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
70231 +{
70232 + struct mm_struct *mm = vma->vm_mm;
70233 + unsigned long address_m;
70234 + spinlock_t *ptl_m;
70235 + struct vm_area_struct *vma_m;
70236 + pmd_t *pmd_m;
70237 + pte_t *pte_m, entry_m;
70238 +
70239 + BUG_ON(!page_m || !PageAnon(page_m));
70240 +
70241 + vma_m = pax_find_mirror_vma(vma);
70242 + if (!vma_m)
70243 + return;
70244 +
70245 + BUG_ON(!PageLocked(page_m));
70246 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70247 + address_m = address + SEGMEXEC_TASK_SIZE;
70248 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70249 + pte_m = pte_offset_map(pmd_m, address_m);
70250 + ptl_m = pte_lockptr(mm, pmd_m);
70251 + if (ptl != ptl_m) {
70252 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70253 + if (!pte_none(*pte_m))
70254 + goto out;
70255 + }
70256 +
70257 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
70258 + page_cache_get(page_m);
70259 + page_add_anon_rmap(page_m, vma_m, address_m);
70260 + inc_mm_counter_fast(mm, MM_ANONPAGES);
70261 + set_pte_at(mm, address_m, pte_m, entry_m);
70262 + update_mmu_cache(vma_m, address_m, entry_m);
70263 +out:
70264 + if (ptl != ptl_m)
70265 + spin_unlock(ptl_m);
70266 + pte_unmap(pte_m);
70267 + unlock_page(page_m);
70268 +}
70269 +
70270 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
70271 +{
70272 + struct mm_struct *mm = vma->vm_mm;
70273 + unsigned long address_m;
70274 + spinlock_t *ptl_m;
70275 + struct vm_area_struct *vma_m;
70276 + pmd_t *pmd_m;
70277 + pte_t *pte_m, entry_m;
70278 +
70279 + BUG_ON(!page_m || PageAnon(page_m));
70280 +
70281 + vma_m = pax_find_mirror_vma(vma);
70282 + if (!vma_m)
70283 + return;
70284 +
70285 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70286 + address_m = address + SEGMEXEC_TASK_SIZE;
70287 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70288 + pte_m = pte_offset_map(pmd_m, address_m);
70289 + ptl_m = pte_lockptr(mm, pmd_m);
70290 + if (ptl != ptl_m) {
70291 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70292 + if (!pte_none(*pte_m))
70293 + goto out;
70294 + }
70295 +
70296 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
70297 + page_cache_get(page_m);
70298 + page_add_file_rmap(page_m);
70299 + inc_mm_counter_fast(mm, MM_FILEPAGES);
70300 + set_pte_at(mm, address_m, pte_m, entry_m);
70301 + update_mmu_cache(vma_m, address_m, entry_m);
70302 +out:
70303 + if (ptl != ptl_m)
70304 + spin_unlock(ptl_m);
70305 + pte_unmap(pte_m);
70306 +}
70307 +
70308 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
70309 +{
70310 + struct mm_struct *mm = vma->vm_mm;
70311 + unsigned long address_m;
70312 + spinlock_t *ptl_m;
70313 + struct vm_area_struct *vma_m;
70314 + pmd_t *pmd_m;
70315 + pte_t *pte_m, entry_m;
70316 +
70317 + vma_m = pax_find_mirror_vma(vma);
70318 + if (!vma_m)
70319 + return;
70320 +
70321 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70322 + address_m = address + SEGMEXEC_TASK_SIZE;
70323 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70324 + pte_m = pte_offset_map(pmd_m, address_m);
70325 + ptl_m = pte_lockptr(mm, pmd_m);
70326 + if (ptl != ptl_m) {
70327 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70328 + if (!pte_none(*pte_m))
70329 + goto out;
70330 + }
70331 +
70332 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
70333 + set_pte_at(mm, address_m, pte_m, entry_m);
70334 +out:
70335 + if (ptl != ptl_m)
70336 + spin_unlock(ptl_m);
70337 + pte_unmap(pte_m);
70338 +}
70339 +
70340 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
70341 +{
70342 + struct page *page_m;
70343 + pte_t entry;
70344 +
70345 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
70346 + goto out;
70347 +
70348 + entry = *pte;
70349 + page_m = vm_normal_page(vma, address, entry);
70350 + if (!page_m)
70351 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
70352 + else if (PageAnon(page_m)) {
70353 + if (pax_find_mirror_vma(vma)) {
70354 + pte_unmap_unlock(pte, ptl);
70355 + lock_page(page_m);
70356 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
70357 + if (pte_same(entry, *pte))
70358 + pax_mirror_anon_pte(vma, address, page_m, ptl);
70359 + else
70360 + unlock_page(page_m);
70361 + }
70362 + } else
70363 + pax_mirror_file_pte(vma, address, page_m, ptl);
70364 +
70365 +out:
70366 + pte_unmap_unlock(pte, ptl);
70367 +}
70368 +#endif
70369 +
70370 /*
70371 * This routine handles present pages, when users try to write
70372 * to a shared page. It is done by copying the page to a new address
70373 @@ -2687,6 +2884,12 @@ gotten:
70374 */
70375 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
70376 if (likely(pte_same(*page_table, orig_pte))) {
70377 +
70378 +#ifdef CONFIG_PAX_SEGMEXEC
70379 + if (pax_find_mirror_vma(vma))
70380 + BUG_ON(!trylock_page(new_page));
70381 +#endif
70382 +
70383 if (old_page) {
70384 if (!PageAnon(old_page)) {
70385 dec_mm_counter_fast(mm, MM_FILEPAGES);
70386 @@ -2738,6 +2941,10 @@ gotten:
70387 page_remove_rmap(old_page);
70388 }
70389
70390 +#ifdef CONFIG_PAX_SEGMEXEC
70391 + pax_mirror_anon_pte(vma, address, new_page, ptl);
70392 +#endif
70393 +
70394 /* Free the old page.. */
70395 new_page = old_page;
70396 ret |= VM_FAULT_WRITE;
70397 @@ -3017,6 +3224,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
70398 swap_free(entry);
70399 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
70400 try_to_free_swap(page);
70401 +
70402 +#ifdef CONFIG_PAX_SEGMEXEC
70403 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
70404 +#endif
70405 +
70406 unlock_page(page);
70407 if (swapcache) {
70408 /*
70409 @@ -3040,6 +3252,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
70410
70411 /* No need to invalidate - it was non-present before */
70412 update_mmu_cache(vma, address, page_table);
70413 +
70414 +#ifdef CONFIG_PAX_SEGMEXEC
70415 + pax_mirror_anon_pte(vma, address, page, ptl);
70416 +#endif
70417 +
70418 unlock:
70419 pte_unmap_unlock(page_table, ptl);
70420 out:
70421 @@ -3059,40 +3276,6 @@ out_release:
70422 }
70423
70424 /*
70425 - * This is like a special single-page "expand_{down|up}wards()",
70426 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
70427 - * doesn't hit another vma.
70428 - */
70429 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
70430 -{
70431 - address &= PAGE_MASK;
70432 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
70433 - struct vm_area_struct *prev = vma->vm_prev;
70434 -
70435 - /*
70436 - * Is there a mapping abutting this one below?
70437 - *
70438 - * That's only ok if it's the same stack mapping
70439 - * that has gotten split..
70440 - */
70441 - if (prev && prev->vm_end == address)
70442 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
70443 -
70444 - expand_downwards(vma, address - PAGE_SIZE);
70445 - }
70446 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
70447 - struct vm_area_struct *next = vma->vm_next;
70448 -
70449 - /* As VM_GROWSDOWN but s/below/above/ */
70450 - if (next && next->vm_start == address + PAGE_SIZE)
70451 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
70452 -
70453 - expand_upwards(vma, address + PAGE_SIZE);
70454 - }
70455 - return 0;
70456 -}
70457 -
70458 -/*
70459 * We enter with non-exclusive mmap_sem (to exclude vma changes,
70460 * but allow concurrent faults), and pte mapped but not yet locked.
70461 * We return with mmap_sem still held, but pte unmapped and unlocked.
70462 @@ -3101,27 +3284,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
70463 unsigned long address, pte_t *page_table, pmd_t *pmd,
70464 unsigned int flags)
70465 {
70466 - struct page *page;
70467 + struct page *page = NULL;
70468 spinlock_t *ptl;
70469 pte_t entry;
70470
70471 - pte_unmap(page_table);
70472 -
70473 - /* Check if we need to add a guard page to the stack */
70474 - if (check_stack_guard_page(vma, address) < 0)
70475 - return VM_FAULT_SIGBUS;
70476 -
70477 - /* Use the zero-page for reads */
70478 if (!(flags & FAULT_FLAG_WRITE)) {
70479 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
70480 vma->vm_page_prot));
70481 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
70482 + ptl = pte_lockptr(mm, pmd);
70483 + spin_lock(ptl);
70484 if (!pte_none(*page_table))
70485 goto unlock;
70486 goto setpte;
70487 }
70488
70489 /* Allocate our own private page. */
70490 + pte_unmap(page_table);
70491 +
70492 if (unlikely(anon_vma_prepare(vma)))
70493 goto oom;
70494 page = alloc_zeroed_user_highpage_movable(vma, address);
70495 @@ -3140,6 +3319,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
70496 if (!pte_none(*page_table))
70497 goto release;
70498
70499 +#ifdef CONFIG_PAX_SEGMEXEC
70500 + if (pax_find_mirror_vma(vma))
70501 + BUG_ON(!trylock_page(page));
70502 +#endif
70503 +
70504 inc_mm_counter_fast(mm, MM_ANONPAGES);
70505 page_add_new_anon_rmap(page, vma, address);
70506 setpte:
70507 @@ -3147,6 +3331,12 @@ setpte:
70508
70509 /* No need to invalidate - it was non-present before */
70510 update_mmu_cache(vma, address, page_table);
70511 +
70512 +#ifdef CONFIG_PAX_SEGMEXEC
70513 + if (page)
70514 + pax_mirror_anon_pte(vma, address, page, ptl);
70515 +#endif
70516 +
70517 unlock:
70518 pte_unmap_unlock(page_table, ptl);
70519 return 0;
70520 @@ -3290,6 +3480,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70521 */
70522 /* Only go through if we didn't race with anybody else... */
70523 if (likely(pte_same(*page_table, orig_pte))) {
70524 +
70525 +#ifdef CONFIG_PAX_SEGMEXEC
70526 + if (anon && pax_find_mirror_vma(vma))
70527 + BUG_ON(!trylock_page(page));
70528 +#endif
70529 +
70530 flush_icache_page(vma, page);
70531 entry = mk_pte(page, vma->vm_page_prot);
70532 if (flags & FAULT_FLAG_WRITE)
70533 @@ -3309,6 +3505,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70534
70535 /* no need to invalidate: a not-present page won't be cached */
70536 update_mmu_cache(vma, address, page_table);
70537 +
70538 +#ifdef CONFIG_PAX_SEGMEXEC
70539 + if (anon)
70540 + pax_mirror_anon_pte(vma, address, page, ptl);
70541 + else
70542 + pax_mirror_file_pte(vma, address, page, ptl);
70543 +#endif
70544 +
70545 } else {
70546 if (cow_page)
70547 mem_cgroup_uncharge_page(cow_page);
70548 @@ -3462,6 +3666,12 @@ int handle_pte_fault(struct mm_struct *mm,
70549 if (flags & FAULT_FLAG_WRITE)
70550 flush_tlb_fix_spurious_fault(vma, address);
70551 }
70552 +
70553 +#ifdef CONFIG_PAX_SEGMEXEC
70554 + pax_mirror_pte(vma, address, pte, pmd, ptl);
70555 + return 0;
70556 +#endif
70557 +
70558 unlock:
70559 pte_unmap_unlock(pte, ptl);
70560 return 0;
70561 @@ -3478,6 +3688,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70562 pmd_t *pmd;
70563 pte_t *pte;
70564
70565 +#ifdef CONFIG_PAX_SEGMEXEC
70566 + struct vm_area_struct *vma_m;
70567 +#endif
70568 +
70569 __set_current_state(TASK_RUNNING);
70570
70571 count_vm_event(PGFAULT);
70572 @@ -3489,6 +3703,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70573 if (unlikely(is_vm_hugetlb_page(vma)))
70574 return hugetlb_fault(mm, vma, address, flags);
70575
70576 +#ifdef CONFIG_PAX_SEGMEXEC
70577 + vma_m = pax_find_mirror_vma(vma);
70578 + if (vma_m) {
70579 + unsigned long address_m;
70580 + pgd_t *pgd_m;
70581 + pud_t *pud_m;
70582 + pmd_t *pmd_m;
70583 +
70584 + if (vma->vm_start > vma_m->vm_start) {
70585 + address_m = address;
70586 + address -= SEGMEXEC_TASK_SIZE;
70587 + vma = vma_m;
70588 + } else
70589 + address_m = address + SEGMEXEC_TASK_SIZE;
70590 +
70591 + pgd_m = pgd_offset(mm, address_m);
70592 + pud_m = pud_alloc(mm, pgd_m, address_m);
70593 + if (!pud_m)
70594 + return VM_FAULT_OOM;
70595 + pmd_m = pmd_alloc(mm, pud_m, address_m);
70596 + if (!pmd_m)
70597 + return VM_FAULT_OOM;
70598 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
70599 + return VM_FAULT_OOM;
70600 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
70601 + }
70602 +#endif
70603 +
70604 pgd = pgd_offset(mm, address);
70605 pud = pud_alloc(mm, pgd, address);
70606 if (!pud)
70607 @@ -3518,7 +3760,7 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70608 * run pte_offset_map on the pmd, if an huge pmd could
70609 * materialize from under us from a different thread.
70610 */
70611 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
70612 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
70613 return VM_FAULT_OOM;
70614 /* if an huge pmd materialized from under us just retry later */
70615 if (unlikely(pmd_trans_huge(*pmd)))
70616 @@ -3555,6 +3797,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
70617 spin_unlock(&mm->page_table_lock);
70618 return 0;
70619 }
70620 +
70621 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
70622 +{
70623 + pud_t *new = pud_alloc_one(mm, address);
70624 + if (!new)
70625 + return -ENOMEM;
70626 +
70627 + smp_wmb(); /* See comment in __pte_alloc */
70628 +
70629 + spin_lock(&mm->page_table_lock);
70630 + if (pgd_present(*pgd)) /* Another has populated it */
70631 + pud_free(mm, new);
70632 + else
70633 + pgd_populate_kernel(mm, pgd, new);
70634 + spin_unlock(&mm->page_table_lock);
70635 + return 0;
70636 +}
70637 #endif /* __PAGETABLE_PUD_FOLDED */
70638
70639 #ifndef __PAGETABLE_PMD_FOLDED
70640 @@ -3585,6 +3844,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
70641 spin_unlock(&mm->page_table_lock);
70642 return 0;
70643 }
70644 +
70645 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
70646 +{
70647 + pmd_t *new = pmd_alloc_one(mm, address);
70648 + if (!new)
70649 + return -ENOMEM;
70650 +
70651 + smp_wmb(); /* See comment in __pte_alloc */
70652 +
70653 + spin_lock(&mm->page_table_lock);
70654 +#ifndef __ARCH_HAS_4LEVEL_HACK
70655 + if (pud_present(*pud)) /* Another has populated it */
70656 + pmd_free(mm, new);
70657 + else
70658 + pud_populate_kernel(mm, pud, new);
70659 +#else
70660 + if (pgd_present(*pud)) /* Another has populated it */
70661 + pmd_free(mm, new);
70662 + else
70663 + pgd_populate_kernel(mm, pud, new);
70664 +#endif /* __ARCH_HAS_4LEVEL_HACK */
70665 + spin_unlock(&mm->page_table_lock);
70666 + return 0;
70667 +}
70668 #endif /* __PAGETABLE_PMD_FOLDED */
70669
70670 int make_pages_present(unsigned long addr, unsigned long end)
70671 @@ -3622,7 +3905,7 @@ static int __init gate_vma_init(void)
70672 gate_vma.vm_start = FIXADDR_USER_START;
70673 gate_vma.vm_end = FIXADDR_USER_END;
70674 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
70675 - gate_vma.vm_page_prot = __P101;
70676 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
70677
70678 return 0;
70679 }
70680 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
70681 index bf5b485..e44c2cb 100644
70682 --- a/mm/mempolicy.c
70683 +++ b/mm/mempolicy.c
70684 @@ -619,6 +619,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
70685 unsigned long vmstart;
70686 unsigned long vmend;
70687
70688 +#ifdef CONFIG_PAX_SEGMEXEC
70689 + struct vm_area_struct *vma_m;
70690 +#endif
70691 +
70692 vma = find_vma(mm, start);
70693 if (!vma || vma->vm_start > start)
70694 return -EFAULT;
70695 @@ -672,6 +676,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
70696 if (err)
70697 goto out;
70698 }
70699 +
70700 +#ifdef CONFIG_PAX_SEGMEXEC
70701 + vma_m = pax_find_mirror_vma(vma);
70702 + if (vma_m && vma_m->vm_ops && vma_m->vm_ops->set_policy) {
70703 + err = vma_m->vm_ops->set_policy(vma_m, new_pol);
70704 + if (err)
70705 + goto out;
70706 + }
70707 +#endif
70708 +
70709 }
70710
70711 out:
70712 @@ -1105,6 +1119,17 @@ static long do_mbind(unsigned long start, unsigned long len,
70713
70714 if (end < start)
70715 return -EINVAL;
70716 +
70717 +#ifdef CONFIG_PAX_SEGMEXEC
70718 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
70719 + if (end > SEGMEXEC_TASK_SIZE)
70720 + return -EINVAL;
70721 + } else
70722 +#endif
70723 +
70724 + if (end > TASK_SIZE)
70725 + return -EINVAL;
70726 +
70727 if (end == start)
70728 return 0;
70729
70730 @@ -1328,8 +1353,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
70731 */
70732 tcred = __task_cred(task);
70733 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
70734 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
70735 - !capable(CAP_SYS_NICE)) {
70736 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
70737 rcu_read_unlock();
70738 err = -EPERM;
70739 goto out_put;
70740 @@ -1360,6 +1384,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
70741 goto out;
70742 }
70743
70744 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
70745 + if (mm != current->mm &&
70746 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
70747 + mmput(mm);
70748 + err = -EPERM;
70749 + goto out;
70750 + }
70751 +#endif
70752 +
70753 err = do_migrate_pages(mm, old, new,
70754 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
70755
70756 diff --git a/mm/mlock.c b/mm/mlock.c
70757 index ef726e8..13e0901 100644
70758 --- a/mm/mlock.c
70759 +++ b/mm/mlock.c
70760 @@ -13,6 +13,7 @@
70761 #include <linux/pagemap.h>
70762 #include <linux/mempolicy.h>
70763 #include <linux/syscalls.h>
70764 +#include <linux/security.h>
70765 #include <linux/sched.h>
70766 #include <linux/export.h>
70767 #include <linux/rmap.h>
70768 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
70769 return -EINVAL;
70770 if (end == start)
70771 return 0;
70772 + if (end > TASK_SIZE)
70773 + return -EINVAL;
70774 +
70775 vma = find_vma(current->mm, start);
70776 if (!vma || vma->vm_start > start)
70777 return -ENOMEM;
70778 @@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
70779 for (nstart = start ; ; ) {
70780 vm_flags_t newflags;
70781
70782 +#ifdef CONFIG_PAX_SEGMEXEC
70783 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
70784 + break;
70785 +#endif
70786 +
70787 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
70788
70789 newflags = vma->vm_flags | VM_LOCKED;
70790 @@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
70791 lock_limit >>= PAGE_SHIFT;
70792
70793 /* check against resource limits */
70794 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
70795 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
70796 error = do_mlock(start, len, 1);
70797 up_write(&current->mm->mmap_sem);
70798 @@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
70799 static int do_mlockall(int flags)
70800 {
70801 struct vm_area_struct * vma, * prev = NULL;
70802 - unsigned int def_flags = 0;
70803
70804 if (flags & MCL_FUTURE)
70805 - def_flags = VM_LOCKED;
70806 - current->mm->def_flags = def_flags;
70807 + current->mm->def_flags |= VM_LOCKED;
70808 + else
70809 + current->mm->def_flags &= ~VM_LOCKED;
70810 if (flags == MCL_FUTURE)
70811 goto out;
70812
70813 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
70814 vm_flags_t newflags;
70815
70816 +#ifdef CONFIG_PAX_SEGMEXEC
70817 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
70818 + break;
70819 +#endif
70820 +
70821 + BUG_ON(vma->vm_end > TASK_SIZE);
70822 newflags = vma->vm_flags | VM_LOCKED;
70823 if (!(flags & MCL_CURRENT))
70824 newflags &= ~VM_LOCKED;
70825 @@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
70826 lock_limit >>= PAGE_SHIFT;
70827
70828 ret = -ENOMEM;
70829 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
70830 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
70831 capable(CAP_IPC_LOCK))
70832 ret = do_mlockall(flags);
70833 diff --git a/mm/mmap.c b/mm/mmap.c
70834 index 848ef52..d2b586c 100644
70835 --- a/mm/mmap.c
70836 +++ b/mm/mmap.c
70837 @@ -46,6 +46,16 @@
70838 #define arch_rebalance_pgtables(addr, len) (addr)
70839 #endif
70840
70841 +static inline void verify_mm_writelocked(struct mm_struct *mm)
70842 +{
70843 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
70844 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
70845 + up_read(&mm->mmap_sem);
70846 + BUG();
70847 + }
70848 +#endif
70849 +}
70850 +
70851 static void unmap_region(struct mm_struct *mm,
70852 struct vm_area_struct *vma, struct vm_area_struct *prev,
70853 unsigned long start, unsigned long end);
70854 @@ -71,22 +81,32 @@ static void unmap_region(struct mm_struct *mm,
70855 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
70856 *
70857 */
70858 -pgprot_t protection_map[16] = {
70859 +pgprot_t protection_map[16] __read_only = {
70860 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
70861 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
70862 };
70863
70864 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
70865 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
70866 {
70867 - return __pgprot(pgprot_val(protection_map[vm_flags &
70868 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
70869 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
70870 pgprot_val(arch_vm_get_page_prot(vm_flags)));
70871 +
70872 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
70873 + if (!(__supported_pte_mask & _PAGE_NX) &&
70874 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
70875 + (vm_flags & (VM_READ | VM_WRITE)))
70876 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
70877 +#endif
70878 +
70879 + return prot;
70880 }
70881 EXPORT_SYMBOL(vm_get_page_prot);
70882
70883 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
70884 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
70885 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
70886 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
70887 /*
70888 * Make sure vm_committed_as in one cacheline and not cacheline shared with
70889 * other variables. It can be updated by several CPUs frequently.
70890 @@ -228,6 +248,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
70891 struct vm_area_struct *next = vma->vm_next;
70892
70893 might_sleep();
70894 + BUG_ON(vma->vm_mirror);
70895 if (vma->vm_ops && vma->vm_ops->close)
70896 vma->vm_ops->close(vma);
70897 if (vma->vm_file) {
70898 @@ -274,6 +295,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
70899 * not page aligned -Ram Gupta
70900 */
70901 rlim = rlimit(RLIMIT_DATA);
70902 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
70903 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
70904 (mm->end_data - mm->start_data) > rlim)
70905 goto out;
70906 @@ -690,6 +712,12 @@ static int
70907 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
70908 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
70909 {
70910 +
70911 +#ifdef CONFIG_PAX_SEGMEXEC
70912 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
70913 + return 0;
70914 +#endif
70915 +
70916 if (is_mergeable_vma(vma, file, vm_flags) &&
70917 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
70918 if (vma->vm_pgoff == vm_pgoff)
70919 @@ -709,6 +737,12 @@ static int
70920 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
70921 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
70922 {
70923 +
70924 +#ifdef CONFIG_PAX_SEGMEXEC
70925 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
70926 + return 0;
70927 +#endif
70928 +
70929 if (is_mergeable_vma(vma, file, vm_flags) &&
70930 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
70931 pgoff_t vm_pglen;
70932 @@ -751,13 +785,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
70933 struct vm_area_struct *vma_merge(struct mm_struct *mm,
70934 struct vm_area_struct *prev, unsigned long addr,
70935 unsigned long end, unsigned long vm_flags,
70936 - struct anon_vma *anon_vma, struct file *file,
70937 + struct anon_vma *anon_vma, struct file *file,
70938 pgoff_t pgoff, struct mempolicy *policy)
70939 {
70940 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
70941 struct vm_area_struct *area, *next;
70942 int err;
70943
70944 +#ifdef CONFIG_PAX_SEGMEXEC
70945 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
70946 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
70947 +
70948 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
70949 +#endif
70950 +
70951 /*
70952 * We later require that vma->vm_flags == vm_flags,
70953 * so this tests vma->vm_flags & VM_SPECIAL, too.
70954 @@ -773,6 +814,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
70955 if (next && next->vm_end == end) /* cases 6, 7, 8 */
70956 next = next->vm_next;
70957
70958 +#ifdef CONFIG_PAX_SEGMEXEC
70959 + if (prev)
70960 + prev_m = pax_find_mirror_vma(prev);
70961 + if (area)
70962 + area_m = pax_find_mirror_vma(area);
70963 + if (next)
70964 + next_m = pax_find_mirror_vma(next);
70965 +#endif
70966 +
70967 /*
70968 * Can it merge with the predecessor?
70969 */
70970 @@ -792,9 +842,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
70971 /* cases 1, 6 */
70972 err = vma_adjust(prev, prev->vm_start,
70973 next->vm_end, prev->vm_pgoff, NULL);
70974 - } else /* cases 2, 5, 7 */
70975 +
70976 +#ifdef CONFIG_PAX_SEGMEXEC
70977 + if (!err && prev_m)
70978 + err = vma_adjust(prev_m, prev_m->vm_start,
70979 + next_m->vm_end, prev_m->vm_pgoff, NULL);
70980 +#endif
70981 +
70982 + } else { /* cases 2, 5, 7 */
70983 err = vma_adjust(prev, prev->vm_start,
70984 end, prev->vm_pgoff, NULL);
70985 +
70986 +#ifdef CONFIG_PAX_SEGMEXEC
70987 + if (!err && prev_m)
70988 + err = vma_adjust(prev_m, prev_m->vm_start,
70989 + end_m, prev_m->vm_pgoff, NULL);
70990 +#endif
70991 +
70992 + }
70993 if (err)
70994 return NULL;
70995 khugepaged_enter_vma_merge(prev);
70996 @@ -808,12 +873,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
70997 mpol_equal(policy, vma_policy(next)) &&
70998 can_vma_merge_before(next, vm_flags,
70999 anon_vma, file, pgoff+pglen)) {
71000 - if (prev && addr < prev->vm_end) /* case 4 */
71001 + if (prev && addr < prev->vm_end) { /* case 4 */
71002 err = vma_adjust(prev, prev->vm_start,
71003 addr, prev->vm_pgoff, NULL);
71004 - else /* cases 3, 8 */
71005 +
71006 +#ifdef CONFIG_PAX_SEGMEXEC
71007 + if (!err && prev_m)
71008 + err = vma_adjust(prev_m, prev_m->vm_start,
71009 + addr_m, prev_m->vm_pgoff, NULL);
71010 +#endif
71011 +
71012 + } else { /* cases 3, 8 */
71013 err = vma_adjust(area, addr, next->vm_end,
71014 next->vm_pgoff - pglen, NULL);
71015 +
71016 +#ifdef CONFIG_PAX_SEGMEXEC
71017 + if (!err && area_m)
71018 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
71019 + next_m->vm_pgoff - pglen, NULL);
71020 +#endif
71021 +
71022 + }
71023 if (err)
71024 return NULL;
71025 khugepaged_enter_vma_merge(area);
71026 @@ -922,14 +1002,11 @@ none:
71027 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
71028 struct file *file, long pages)
71029 {
71030 - const unsigned long stack_flags
71031 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
71032 -
71033 if (file) {
71034 mm->shared_vm += pages;
71035 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
71036 mm->exec_vm += pages;
71037 - } else if (flags & stack_flags)
71038 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
71039 mm->stack_vm += pages;
71040 if (flags & (VM_RESERVED|VM_IO))
71041 mm->reserved_vm += pages;
71042 @@ -969,7 +1046,7 @@ static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71043 * (the exception is when the underlying filesystem is noexec
71044 * mounted, in which case we dont add PROT_EXEC.)
71045 */
71046 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
71047 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
71048 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
71049 prot |= PROT_EXEC;
71050
71051 @@ -995,7 +1072,7 @@ static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71052 /* Obtain the address to map to. we verify (or select) it and ensure
71053 * that it represents a valid section of the address space.
71054 */
71055 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
71056 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
71057 if (addr & ~PAGE_MASK)
71058 return addr;
71059
71060 @@ -1006,6 +1083,36 @@ static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71061 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
71062 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
71063
71064 +#ifdef CONFIG_PAX_MPROTECT
71065 + if (mm->pax_flags & MF_PAX_MPROTECT) {
71066 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
71067 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
71068 + gr_log_rwxmmap(file);
71069 +
71070 +#ifdef CONFIG_PAX_EMUPLT
71071 + vm_flags &= ~VM_EXEC;
71072 +#else
71073 + return -EPERM;
71074 +#endif
71075 +
71076 + }
71077 +
71078 + if (!(vm_flags & VM_EXEC))
71079 + vm_flags &= ~VM_MAYEXEC;
71080 +#else
71081 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
71082 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
71083 +#endif
71084 + else
71085 + vm_flags &= ~VM_MAYWRITE;
71086 + }
71087 +#endif
71088 +
71089 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71090 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
71091 + vm_flags &= ~VM_PAGEEXEC;
71092 +#endif
71093 +
71094 if (flags & MAP_LOCKED)
71095 if (!can_do_mlock())
71096 return -EPERM;
71097 @@ -1017,6 +1124,7 @@ static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71098 locked += mm->locked_vm;
71099 lock_limit = rlimit(RLIMIT_MEMLOCK);
71100 lock_limit >>= PAGE_SHIFT;
71101 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
71102 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
71103 return -EAGAIN;
71104 }
71105 @@ -1087,6 +1195,9 @@ static unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71106 if (error)
71107 return error;
71108
71109 + if (!gr_acl_handle_mmap(file, prot))
71110 + return -EACCES;
71111 +
71112 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
71113 }
71114
71115 @@ -1192,7 +1303,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
71116 vm_flags_t vm_flags = vma->vm_flags;
71117
71118 /* If it was private or non-writable, the write bit is already clear */
71119 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
71120 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
71121 return 0;
71122
71123 /* The backer wishes to know when pages are first written to? */
71124 @@ -1241,14 +1352,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
71125 unsigned long charged = 0;
71126 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
71127
71128 +#ifdef CONFIG_PAX_SEGMEXEC
71129 + struct vm_area_struct *vma_m = NULL;
71130 +#endif
71131 +
71132 + /*
71133 + * mm->mmap_sem is required to protect against another thread
71134 + * changing the mappings in case we sleep.
71135 + */
71136 + verify_mm_writelocked(mm);
71137 +
71138 /* Clear old maps */
71139 error = -ENOMEM;
71140 -munmap_back:
71141 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71142 if (vma && vma->vm_start < addr + len) {
71143 if (do_munmap(mm, addr, len))
71144 return -ENOMEM;
71145 - goto munmap_back;
71146 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71147 + BUG_ON(vma && vma->vm_start < addr + len);
71148 }
71149
71150 /* Check against address space limit. */
71151 @@ -1297,6 +1418,16 @@ munmap_back:
71152 goto unacct_error;
71153 }
71154
71155 +#ifdef CONFIG_PAX_SEGMEXEC
71156 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
71157 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71158 + if (!vma_m) {
71159 + error = -ENOMEM;
71160 + goto free_vma;
71161 + }
71162 + }
71163 +#endif
71164 +
71165 vma->vm_mm = mm;
71166 vma->vm_start = addr;
71167 vma->vm_end = addr + len;
71168 @@ -1321,6 +1452,19 @@ munmap_back:
71169 error = file->f_op->mmap(file, vma);
71170 if (error)
71171 goto unmap_and_free_vma;
71172 +
71173 +#ifdef CONFIG_PAX_SEGMEXEC
71174 + if (vma_m && (vm_flags & VM_EXECUTABLE))
71175 + added_exe_file_vma(mm);
71176 +#endif
71177 +
71178 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71179 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
71180 + vma->vm_flags |= VM_PAGEEXEC;
71181 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
71182 + }
71183 +#endif
71184 +
71185 if (vm_flags & VM_EXECUTABLE)
71186 added_exe_file_vma(mm);
71187
71188 @@ -1358,6 +1502,11 @@ munmap_back:
71189 vma_link(mm, vma, prev, rb_link, rb_parent);
71190 file = vma->vm_file;
71191
71192 +#ifdef CONFIG_PAX_SEGMEXEC
71193 + if (vma_m)
71194 + BUG_ON(pax_mirror_vma(vma_m, vma));
71195 +#endif
71196 +
71197 /* Once vma denies write, undo our temporary denial count */
71198 if (correct_wcount)
71199 atomic_inc(&inode->i_writecount);
71200 @@ -1366,6 +1515,7 @@ out:
71201
71202 mm->total_vm += len >> PAGE_SHIFT;
71203 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
71204 + track_exec_limit(mm, addr, addr + len, vm_flags);
71205 if (vm_flags & VM_LOCKED) {
71206 if (!mlock_vma_pages_range(vma, addr, addr + len))
71207 mm->locked_vm += (len >> PAGE_SHIFT);
71208 @@ -1383,6 +1533,12 @@ unmap_and_free_vma:
71209 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
71210 charged = 0;
71211 free_vma:
71212 +
71213 +#ifdef CONFIG_PAX_SEGMEXEC
71214 + if (vma_m)
71215 + kmem_cache_free(vm_area_cachep, vma_m);
71216 +#endif
71217 +
71218 kmem_cache_free(vm_area_cachep, vma);
71219 unacct_error:
71220 if (charged)
71221 @@ -1390,6 +1546,44 @@ unacct_error:
71222 return error;
71223 }
71224
71225 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
71226 +{
71227 + if (!vma) {
71228 +#ifdef CONFIG_STACK_GROWSUP
71229 + if (addr > sysctl_heap_stack_gap)
71230 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
71231 + else
71232 + vma = find_vma(current->mm, 0);
71233 + if (vma && (vma->vm_flags & VM_GROWSUP))
71234 + return false;
71235 +#endif
71236 + return true;
71237 + }
71238 +
71239 + if (addr + len > vma->vm_start)
71240 + return false;
71241 +
71242 + if (vma->vm_flags & VM_GROWSDOWN)
71243 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
71244 +#ifdef CONFIG_STACK_GROWSUP
71245 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
71246 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
71247 +#endif
71248 +
71249 + return true;
71250 +}
71251 +
71252 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
71253 +{
71254 + if (vma->vm_start < len)
71255 + return -ENOMEM;
71256 + if (!(vma->vm_flags & VM_GROWSDOWN))
71257 + return vma->vm_start - len;
71258 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
71259 + return vma->vm_start - len - sysctl_heap_stack_gap;
71260 + return -ENOMEM;
71261 +}
71262 +
71263 /* Get an address range which is currently unmapped.
71264 * For shmat() with addr=0.
71265 *
71266 @@ -1416,18 +1610,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
71267 if (flags & MAP_FIXED)
71268 return addr;
71269
71270 +#ifdef CONFIG_PAX_RANDMMAP
71271 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
71272 +#endif
71273 +
71274 if (addr) {
71275 addr = PAGE_ALIGN(addr);
71276 - vma = find_vma(mm, addr);
71277 - if (TASK_SIZE - len >= addr &&
71278 - (!vma || addr + len <= vma->vm_start))
71279 - return addr;
71280 + if (TASK_SIZE - len >= addr) {
71281 + vma = find_vma(mm, addr);
71282 + if (check_heap_stack_gap(vma, addr, len))
71283 + return addr;
71284 + }
71285 }
71286 if (len > mm->cached_hole_size) {
71287 - start_addr = addr = mm->free_area_cache;
71288 + start_addr = addr = mm->free_area_cache;
71289 } else {
71290 - start_addr = addr = TASK_UNMAPPED_BASE;
71291 - mm->cached_hole_size = 0;
71292 + start_addr = addr = mm->mmap_base;
71293 + mm->cached_hole_size = 0;
71294 }
71295
71296 full_search:
71297 @@ -1438,34 +1637,40 @@ full_search:
71298 * Start a new search - just in case we missed
71299 * some holes.
71300 */
71301 - if (start_addr != TASK_UNMAPPED_BASE) {
71302 - addr = TASK_UNMAPPED_BASE;
71303 - start_addr = addr;
71304 + if (start_addr != mm->mmap_base) {
71305 + start_addr = addr = mm->mmap_base;
71306 mm->cached_hole_size = 0;
71307 goto full_search;
71308 }
71309 return -ENOMEM;
71310 }
71311 - if (!vma || addr + len <= vma->vm_start) {
71312 - /*
71313 - * Remember the place where we stopped the search:
71314 - */
71315 - mm->free_area_cache = addr + len;
71316 - return addr;
71317 - }
71318 + if (check_heap_stack_gap(vma, addr, len))
71319 + break;
71320 if (addr + mm->cached_hole_size < vma->vm_start)
71321 mm->cached_hole_size = vma->vm_start - addr;
71322 addr = vma->vm_end;
71323 }
71324 +
71325 + /*
71326 + * Remember the place where we stopped the search:
71327 + */
71328 + mm->free_area_cache = addr + len;
71329 + return addr;
71330 }
71331 #endif
71332
71333 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
71334 {
71335 +
71336 +#ifdef CONFIG_PAX_SEGMEXEC
71337 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
71338 + return;
71339 +#endif
71340 +
71341 /*
71342 * Is this a new hole at the lowest possible address?
71343 */
71344 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
71345 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
71346 mm->free_area_cache = addr;
71347 }
71348
71349 @@ -1481,7 +1686,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71350 {
71351 struct vm_area_struct *vma;
71352 struct mm_struct *mm = current->mm;
71353 - unsigned long addr = addr0, start_addr;
71354 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
71355
71356 /* requested length too big for entire address space */
71357 if (len > TASK_SIZE)
71358 @@ -1490,13 +1695,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71359 if (flags & MAP_FIXED)
71360 return addr;
71361
71362 +#ifdef CONFIG_PAX_RANDMMAP
71363 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
71364 +#endif
71365 +
71366 /* requesting a specific address */
71367 if (addr) {
71368 addr = PAGE_ALIGN(addr);
71369 - vma = find_vma(mm, addr);
71370 - if (TASK_SIZE - len >= addr &&
71371 - (!vma || addr + len <= vma->vm_start))
71372 - return addr;
71373 + if (TASK_SIZE - len >= addr) {
71374 + vma = find_vma(mm, addr);
71375 + if (check_heap_stack_gap(vma, addr, len))
71376 + return addr;
71377 + }
71378 }
71379
71380 /* check if free_area_cache is useful for us */
71381 @@ -1520,7 +1730,7 @@ try_again:
71382 * return with success:
71383 */
71384 vma = find_vma(mm, addr);
71385 - if (!vma || addr+len <= vma->vm_start)
71386 + if (check_heap_stack_gap(vma, addr, len))
71387 /* remember the address as a hint for next time */
71388 return (mm->free_area_cache = addr);
71389
71390 @@ -1529,8 +1739,8 @@ try_again:
71391 mm->cached_hole_size = vma->vm_start - addr;
71392
71393 /* try just below the current vma->vm_start */
71394 - addr = vma->vm_start-len;
71395 - } while (len < vma->vm_start);
71396 + addr = skip_heap_stack_gap(vma, len);
71397 + } while (!IS_ERR_VALUE(addr));
71398
71399 fail:
71400 /*
71401 @@ -1553,13 +1763,21 @@ fail:
71402 * can happen with large stack limits and large mmap()
71403 * allocations.
71404 */
71405 + mm->mmap_base = TASK_UNMAPPED_BASE;
71406 +
71407 +#ifdef CONFIG_PAX_RANDMMAP
71408 + if (mm->pax_flags & MF_PAX_RANDMMAP)
71409 + mm->mmap_base += mm->delta_mmap;
71410 +#endif
71411 +
71412 + mm->free_area_cache = mm->mmap_base;
71413 mm->cached_hole_size = ~0UL;
71414 - mm->free_area_cache = TASK_UNMAPPED_BASE;
71415 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
71416 /*
71417 * Restore the topdown base:
71418 */
71419 - mm->free_area_cache = mm->mmap_base;
71420 + mm->mmap_base = base;
71421 + mm->free_area_cache = base;
71422 mm->cached_hole_size = ~0UL;
71423
71424 return addr;
71425 @@ -1568,6 +1786,12 @@ fail:
71426
71427 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
71428 {
71429 +
71430 +#ifdef CONFIG_PAX_SEGMEXEC
71431 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
71432 + return;
71433 +#endif
71434 +
71435 /*
71436 * Is this a new hole at the highest possible address?
71437 */
71438 @@ -1575,8 +1799,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
71439 mm->free_area_cache = addr;
71440
71441 /* dont allow allocations above current base */
71442 - if (mm->free_area_cache > mm->mmap_base)
71443 + if (mm->free_area_cache > mm->mmap_base) {
71444 mm->free_area_cache = mm->mmap_base;
71445 + mm->cached_hole_size = ~0UL;
71446 + }
71447 }
71448
71449 unsigned long
71450 @@ -1672,6 +1898,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
71451 return vma;
71452 }
71453
71454 +#ifdef CONFIG_PAX_SEGMEXEC
71455 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
71456 +{
71457 + struct vm_area_struct *vma_m;
71458 +
71459 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
71460 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
71461 + BUG_ON(vma->vm_mirror);
71462 + return NULL;
71463 + }
71464 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
71465 + vma_m = vma->vm_mirror;
71466 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
71467 + BUG_ON(vma->vm_file != vma_m->vm_file);
71468 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
71469 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
71470 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
71471 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
71472 + return vma_m;
71473 +}
71474 +#endif
71475 +
71476 /*
71477 * Verify that the stack growth is acceptable and
71478 * update accounting. This is shared with both the
71479 @@ -1688,6 +1936,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
71480 return -ENOMEM;
71481
71482 /* Stack limit test */
71483 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
71484 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
71485 return -ENOMEM;
71486
71487 @@ -1698,6 +1947,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
71488 locked = mm->locked_vm + grow;
71489 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
71490 limit >>= PAGE_SHIFT;
71491 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
71492 if (locked > limit && !capable(CAP_IPC_LOCK))
71493 return -ENOMEM;
71494 }
71495 @@ -1728,37 +1978,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
71496 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
71497 * vma is the last one with address > vma->vm_end. Have to extend vma.
71498 */
71499 +#ifndef CONFIG_IA64
71500 +static
71501 +#endif
71502 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
71503 {
71504 int error;
71505 + bool locknext;
71506
71507 if (!(vma->vm_flags & VM_GROWSUP))
71508 return -EFAULT;
71509
71510 + /* Also guard against wrapping around to address 0. */
71511 + if (address < PAGE_ALIGN(address+1))
71512 + address = PAGE_ALIGN(address+1);
71513 + else
71514 + return -ENOMEM;
71515 +
71516 /*
71517 * We must make sure the anon_vma is allocated
71518 * so that the anon_vma locking is not a noop.
71519 */
71520 if (unlikely(anon_vma_prepare(vma)))
71521 return -ENOMEM;
71522 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
71523 + if (locknext && anon_vma_prepare(vma->vm_next))
71524 + return -ENOMEM;
71525 vma_lock_anon_vma(vma);
71526 + if (locknext)
71527 + vma_lock_anon_vma(vma->vm_next);
71528
71529 /*
71530 * vma->vm_start/vm_end cannot change under us because the caller
71531 * is required to hold the mmap_sem in read mode. We need the
71532 - * anon_vma lock to serialize against concurrent expand_stacks.
71533 - * Also guard against wrapping around to address 0.
71534 + * anon_vma locks to serialize against concurrent expand_stacks
71535 + * and expand_upwards.
71536 */
71537 - if (address < PAGE_ALIGN(address+4))
71538 - address = PAGE_ALIGN(address+4);
71539 - else {
71540 - vma_unlock_anon_vma(vma);
71541 - return -ENOMEM;
71542 - }
71543 error = 0;
71544
71545 /* Somebody else might have raced and expanded it already */
71546 - if (address > vma->vm_end) {
71547 + 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)
71548 + error = -ENOMEM;
71549 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
71550 unsigned long size, grow;
71551
71552 size = address - vma->vm_start;
71553 @@ -1773,6 +2034,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
71554 }
71555 }
71556 }
71557 + if (locknext)
71558 + vma_unlock_anon_vma(vma->vm_next);
71559 vma_unlock_anon_vma(vma);
71560 khugepaged_enter_vma_merge(vma);
71561 return error;
71562 @@ -1786,6 +2049,8 @@ int expand_downwards(struct vm_area_struct *vma,
71563 unsigned long address)
71564 {
71565 int error;
71566 + bool lockprev = false;
71567 + struct vm_area_struct *prev;
71568
71569 /*
71570 * We must make sure the anon_vma is allocated
71571 @@ -1799,6 +2064,15 @@ int expand_downwards(struct vm_area_struct *vma,
71572 if (error)
71573 return error;
71574
71575 + prev = vma->vm_prev;
71576 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
71577 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
71578 +#endif
71579 + if (lockprev && anon_vma_prepare(prev))
71580 + return -ENOMEM;
71581 + if (lockprev)
71582 + vma_lock_anon_vma(prev);
71583 +
71584 vma_lock_anon_vma(vma);
71585
71586 /*
71587 @@ -1808,9 +2082,17 @@ int expand_downwards(struct vm_area_struct *vma,
71588 */
71589
71590 /* Somebody else might have raced and expanded it already */
71591 - if (address < vma->vm_start) {
71592 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
71593 + error = -ENOMEM;
71594 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
71595 unsigned long size, grow;
71596
71597 +#ifdef CONFIG_PAX_SEGMEXEC
71598 + struct vm_area_struct *vma_m;
71599 +
71600 + vma_m = pax_find_mirror_vma(vma);
71601 +#endif
71602 +
71603 size = vma->vm_end - address;
71604 grow = (vma->vm_start - address) >> PAGE_SHIFT;
71605
71606 @@ -1820,11 +2102,22 @@ int expand_downwards(struct vm_area_struct *vma,
71607 if (!error) {
71608 vma->vm_start = address;
71609 vma->vm_pgoff -= grow;
71610 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
71611 +
71612 +#ifdef CONFIG_PAX_SEGMEXEC
71613 + if (vma_m) {
71614 + vma_m->vm_start -= grow << PAGE_SHIFT;
71615 + vma_m->vm_pgoff -= grow;
71616 + }
71617 +#endif
71618 +
71619 perf_event_mmap(vma);
71620 }
71621 }
71622 }
71623 vma_unlock_anon_vma(vma);
71624 + if (lockprev)
71625 + vma_unlock_anon_vma(prev);
71626 khugepaged_enter_vma_merge(vma);
71627 return error;
71628 }
71629 @@ -1894,6 +2187,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
71630 do {
71631 long nrpages = vma_pages(vma);
71632
71633 +#ifdef CONFIG_PAX_SEGMEXEC
71634 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
71635 + vma = remove_vma(vma);
71636 + continue;
71637 + }
71638 +#endif
71639 +
71640 mm->total_vm -= nrpages;
71641 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
71642 vma = remove_vma(vma);
71643 @@ -1939,6 +2239,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
71644 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
71645 vma->vm_prev = NULL;
71646 do {
71647 +
71648 +#ifdef CONFIG_PAX_SEGMEXEC
71649 + if (vma->vm_mirror) {
71650 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
71651 + vma->vm_mirror->vm_mirror = NULL;
71652 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
71653 + vma->vm_mirror = NULL;
71654 + }
71655 +#endif
71656 +
71657 rb_erase(&vma->vm_rb, &mm->mm_rb);
71658 mm->map_count--;
71659 tail_vma = vma;
71660 @@ -1967,14 +2277,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71661 struct vm_area_struct *new;
71662 int err = -ENOMEM;
71663
71664 +#ifdef CONFIG_PAX_SEGMEXEC
71665 + struct vm_area_struct *vma_m, *new_m = NULL;
71666 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
71667 +#endif
71668 +
71669 if (is_vm_hugetlb_page(vma) && (addr &
71670 ~(huge_page_mask(hstate_vma(vma)))))
71671 return -EINVAL;
71672
71673 +#ifdef CONFIG_PAX_SEGMEXEC
71674 + vma_m = pax_find_mirror_vma(vma);
71675 +#endif
71676 +
71677 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
71678 if (!new)
71679 goto out_err;
71680
71681 +#ifdef CONFIG_PAX_SEGMEXEC
71682 + if (vma_m) {
71683 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
71684 + if (!new_m) {
71685 + kmem_cache_free(vm_area_cachep, new);
71686 + goto out_err;
71687 + }
71688 + }
71689 +#endif
71690 +
71691 /* most fields are the same, copy all, and then fixup */
71692 *new = *vma;
71693
71694 @@ -1987,6 +2316,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71695 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
71696 }
71697
71698 +#ifdef CONFIG_PAX_SEGMEXEC
71699 + if (vma_m) {
71700 + *new_m = *vma_m;
71701 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
71702 + new_m->vm_mirror = new;
71703 + new->vm_mirror = new_m;
71704 +
71705 + if (new_below)
71706 + new_m->vm_end = addr_m;
71707 + else {
71708 + new_m->vm_start = addr_m;
71709 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
71710 + }
71711 + }
71712 +#endif
71713 +
71714 pol = mpol_dup(vma_policy(vma));
71715 if (IS_ERR(pol)) {
71716 err = PTR_ERR(pol);
71717 @@ -2012,6 +2357,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71718 else
71719 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
71720
71721 +#ifdef CONFIG_PAX_SEGMEXEC
71722 + if (!err && vma_m) {
71723 + if (anon_vma_clone(new_m, vma_m))
71724 + goto out_free_mpol;
71725 +
71726 + mpol_get(pol);
71727 + vma_set_policy(new_m, pol);
71728 +
71729 + if (new_m->vm_file) {
71730 + get_file(new_m->vm_file);
71731 + if (vma_m->vm_flags & VM_EXECUTABLE)
71732 + added_exe_file_vma(mm);
71733 + }
71734 +
71735 + if (new_m->vm_ops && new_m->vm_ops->open)
71736 + new_m->vm_ops->open(new_m);
71737 +
71738 + if (new_below)
71739 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
71740 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
71741 + else
71742 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
71743 +
71744 + if (err) {
71745 + if (new_m->vm_ops && new_m->vm_ops->close)
71746 + new_m->vm_ops->close(new_m);
71747 + if (new_m->vm_file) {
71748 + if (vma_m->vm_flags & VM_EXECUTABLE)
71749 + removed_exe_file_vma(mm);
71750 + fput(new_m->vm_file);
71751 + }
71752 + mpol_put(pol);
71753 + }
71754 + }
71755 +#endif
71756 +
71757 /* Success. */
71758 if (!err)
71759 return 0;
71760 @@ -2024,10 +2405,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71761 removed_exe_file_vma(mm);
71762 fput(new->vm_file);
71763 }
71764 - unlink_anon_vmas(new);
71765 out_free_mpol:
71766 mpol_put(pol);
71767 out_free_vma:
71768 +
71769 +#ifdef CONFIG_PAX_SEGMEXEC
71770 + if (new_m) {
71771 + unlink_anon_vmas(new_m);
71772 + kmem_cache_free(vm_area_cachep, new_m);
71773 + }
71774 +#endif
71775 +
71776 + unlink_anon_vmas(new);
71777 kmem_cache_free(vm_area_cachep, new);
71778 out_err:
71779 return err;
71780 @@ -2040,6 +2429,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
71781 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
71782 unsigned long addr, int new_below)
71783 {
71784 +
71785 +#ifdef CONFIG_PAX_SEGMEXEC
71786 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
71787 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
71788 + if (mm->map_count >= sysctl_max_map_count-1)
71789 + return -ENOMEM;
71790 + } else
71791 +#endif
71792 +
71793 if (mm->map_count >= sysctl_max_map_count)
71794 return -ENOMEM;
71795
71796 @@ -2051,11 +2449,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
71797 * work. This now handles partial unmappings.
71798 * Jeremy Fitzhardinge <jeremy@goop.org>
71799 */
71800 +#ifdef CONFIG_PAX_SEGMEXEC
71801 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71802 {
71803 + int ret = __do_munmap(mm, start, len);
71804 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
71805 + return ret;
71806 +
71807 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
71808 +}
71809 +
71810 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71811 +#else
71812 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71813 +#endif
71814 +{
71815 unsigned long end;
71816 struct vm_area_struct *vma, *prev, *last;
71817
71818 + /*
71819 + * mm->mmap_sem is required to protect against another thread
71820 + * changing the mappings in case we sleep.
71821 + */
71822 + verify_mm_writelocked(mm);
71823 +
71824 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
71825 return -EINVAL;
71826
71827 @@ -2130,6 +2547,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
71828 /* Fix up all other VM information */
71829 remove_vma_list(mm, vma);
71830
71831 + track_exec_limit(mm, start, end, 0UL);
71832 +
71833 return 0;
71834 }
71835 EXPORT_SYMBOL(do_munmap);
71836 @@ -2139,6 +2558,13 @@ int vm_munmap(unsigned long start, size_t len)
71837 int ret;
71838 struct mm_struct *mm = current->mm;
71839
71840 +
71841 +#ifdef CONFIG_PAX_SEGMEXEC
71842 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
71843 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
71844 + return -EINVAL;
71845 +#endif
71846 +
71847 down_write(&mm->mmap_sem);
71848 ret = do_munmap(mm, start, len);
71849 up_write(&mm->mmap_sem);
71850 @@ -2152,16 +2578,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
71851 return vm_munmap(addr, len);
71852 }
71853
71854 -static inline void verify_mm_writelocked(struct mm_struct *mm)
71855 -{
71856 -#ifdef CONFIG_DEBUG_VM
71857 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
71858 - WARN_ON(1);
71859 - up_read(&mm->mmap_sem);
71860 - }
71861 -#endif
71862 -}
71863 -
71864 /*
71865 * this is really a simplified "do_mmap". it only handles
71866 * anonymous maps. eventually we may be able to do some
71867 @@ -2175,6 +2591,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
71868 struct rb_node ** rb_link, * rb_parent;
71869 pgoff_t pgoff = addr >> PAGE_SHIFT;
71870 int error;
71871 + unsigned long charged;
71872
71873 len = PAGE_ALIGN(len);
71874 if (!len)
71875 @@ -2186,16 +2603,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
71876
71877 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
71878
71879 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
71880 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
71881 + flags &= ~VM_EXEC;
71882 +
71883 +#ifdef CONFIG_PAX_MPROTECT
71884 + if (mm->pax_flags & MF_PAX_MPROTECT)
71885 + flags &= ~VM_MAYEXEC;
71886 +#endif
71887 +
71888 + }
71889 +#endif
71890 +
71891 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
71892 if (error & ~PAGE_MASK)
71893 return error;
71894
71895 + charged = len >> PAGE_SHIFT;
71896 +
71897 /*
71898 * mlock MCL_FUTURE?
71899 */
71900 if (mm->def_flags & VM_LOCKED) {
71901 unsigned long locked, lock_limit;
71902 - locked = len >> PAGE_SHIFT;
71903 + locked = charged;
71904 locked += mm->locked_vm;
71905 lock_limit = rlimit(RLIMIT_MEMLOCK);
71906 lock_limit >>= PAGE_SHIFT;
71907 @@ -2212,22 +2643,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
71908 /*
71909 * Clear old maps. this also does some error checking for us
71910 */
71911 - munmap_back:
71912 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71913 if (vma && vma->vm_start < addr + len) {
71914 if (do_munmap(mm, addr, len))
71915 return -ENOMEM;
71916 - goto munmap_back;
71917 - }
71918 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71919 + BUG_ON(vma && vma->vm_start < addr + len);
71920 + }
71921
71922 /* Check against address space limits *after* clearing old maps... */
71923 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
71924 + if (!may_expand_vm(mm, charged))
71925 return -ENOMEM;
71926
71927 if (mm->map_count > sysctl_max_map_count)
71928 return -ENOMEM;
71929
71930 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
71931 + if (security_vm_enough_memory_mm(mm, charged))
71932 return -ENOMEM;
71933
71934 /* Can we just expand an old private anonymous mapping? */
71935 @@ -2241,7 +2672,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
71936 */
71937 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71938 if (!vma) {
71939 - vm_unacct_memory(len >> PAGE_SHIFT);
71940 + vm_unacct_memory(charged);
71941 return -ENOMEM;
71942 }
71943
71944 @@ -2255,11 +2686,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
71945 vma_link(mm, vma, prev, rb_link, rb_parent);
71946 out:
71947 perf_event_mmap(vma);
71948 - mm->total_vm += len >> PAGE_SHIFT;
71949 + mm->total_vm += charged;
71950 if (flags & VM_LOCKED) {
71951 if (!mlock_vma_pages_range(vma, addr, addr + len))
71952 - mm->locked_vm += (len >> PAGE_SHIFT);
71953 + mm->locked_vm += charged;
71954 }
71955 + track_exec_limit(mm, addr, addr + len, flags);
71956 return addr;
71957 }
71958
71959 @@ -2315,8 +2747,10 @@ void exit_mmap(struct mm_struct *mm)
71960 * Walk the list again, actually closing and freeing it,
71961 * with preemption enabled, without holding any MM locks.
71962 */
71963 - while (vma)
71964 + while (vma) {
71965 + vma->vm_mirror = NULL;
71966 vma = remove_vma(vma);
71967 + }
71968
71969 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
71970 }
71971 @@ -2330,6 +2764,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
71972 struct vm_area_struct * __vma, * prev;
71973 struct rb_node ** rb_link, * rb_parent;
71974
71975 +#ifdef CONFIG_PAX_SEGMEXEC
71976 + struct vm_area_struct *vma_m = NULL;
71977 +#endif
71978 +
71979 + if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
71980 + return -EPERM;
71981 +
71982 /*
71983 * The vm_pgoff of a purely anonymous vma should be irrelevant
71984 * until its first write fault, when page's anon_vma and index
71985 @@ -2352,7 +2793,22 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
71986 if ((vma->vm_flags & VM_ACCOUNT) &&
71987 security_vm_enough_memory_mm(mm, vma_pages(vma)))
71988 return -ENOMEM;
71989 +
71990 +#ifdef CONFIG_PAX_SEGMEXEC
71991 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
71992 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71993 + if (!vma_m)
71994 + return -ENOMEM;
71995 + }
71996 +#endif
71997 +
71998 vma_link(mm, vma, prev, rb_link, rb_parent);
71999 +
72000 +#ifdef CONFIG_PAX_SEGMEXEC
72001 + if (vma_m)
72002 + BUG_ON(pax_mirror_vma(vma_m, vma));
72003 +#endif
72004 +
72005 return 0;
72006 }
72007
72008 @@ -2371,6 +2827,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
72009 struct mempolicy *pol;
72010 bool faulted_in_anon_vma = true;
72011
72012 + BUG_ON(vma->vm_mirror);
72013 +
72014 /*
72015 * If anonymous vma has not yet been faulted, update new pgoff
72016 * to match new location, to increase its chance of merging.
72017 @@ -2438,6 +2896,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
72018 return NULL;
72019 }
72020
72021 +#ifdef CONFIG_PAX_SEGMEXEC
72022 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
72023 +{
72024 + struct vm_area_struct *prev_m;
72025 + struct rb_node **rb_link_m, *rb_parent_m;
72026 + struct mempolicy *pol_m;
72027 +
72028 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
72029 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
72030 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
72031 + *vma_m = *vma;
72032 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
72033 + if (anon_vma_clone(vma_m, vma))
72034 + return -ENOMEM;
72035 + pol_m = vma_policy(vma_m);
72036 + mpol_get(pol_m);
72037 + vma_set_policy(vma_m, pol_m);
72038 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
72039 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
72040 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
72041 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
72042 + if (vma_m->vm_file)
72043 + get_file(vma_m->vm_file);
72044 + if (vma_m->vm_ops && vma_m->vm_ops->open)
72045 + vma_m->vm_ops->open(vma_m);
72046 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
72047 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
72048 + vma_m->vm_mirror = vma;
72049 + vma->vm_mirror = vma_m;
72050 + return 0;
72051 +}
72052 +#endif
72053 +
72054 /*
72055 * Return true if the calling process may expand its vm space by the passed
72056 * number of pages
72057 @@ -2449,6 +2940,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
72058
72059 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
72060
72061 +#ifdef CONFIG_PAX_RANDMMAP
72062 + if (mm->pax_flags & MF_PAX_RANDMMAP)
72063 + cur -= mm->brk_gap;
72064 +#endif
72065 +
72066 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
72067 if (cur + npages > lim)
72068 return 0;
72069 return 1;
72070 @@ -2519,6 +3016,22 @@ int install_special_mapping(struct mm_struct *mm,
72071 vma->vm_start = addr;
72072 vma->vm_end = addr + len;
72073
72074 +#ifdef CONFIG_PAX_MPROTECT
72075 + if (mm->pax_flags & MF_PAX_MPROTECT) {
72076 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
72077 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
72078 + return -EPERM;
72079 + if (!(vm_flags & VM_EXEC))
72080 + vm_flags &= ~VM_MAYEXEC;
72081 +#else
72082 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72083 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72084 +#endif
72085 + else
72086 + vm_flags &= ~VM_MAYWRITE;
72087 + }
72088 +#endif
72089 +
72090 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
72091 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72092
72093 diff --git a/mm/mprotect.c b/mm/mprotect.c
72094 index a409926..8b32e6d 100644
72095 --- a/mm/mprotect.c
72096 +++ b/mm/mprotect.c
72097 @@ -23,10 +23,17 @@
72098 #include <linux/mmu_notifier.h>
72099 #include <linux/migrate.h>
72100 #include <linux/perf_event.h>
72101 +
72102 +#ifdef CONFIG_PAX_MPROTECT
72103 +#include <linux/elf.h>
72104 +#include <linux/binfmts.h>
72105 +#endif
72106 +
72107 #include <asm/uaccess.h>
72108 #include <asm/pgtable.h>
72109 #include <asm/cacheflush.h>
72110 #include <asm/tlbflush.h>
72111 +#include <asm/mmu_context.h>
72112
72113 #ifndef pgprot_modify
72114 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
72115 @@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
72116 flush_tlb_range(vma, start, end);
72117 }
72118
72119 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
72120 +/* called while holding the mmap semaphor for writing except stack expansion */
72121 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
72122 +{
72123 + unsigned long oldlimit, newlimit = 0UL;
72124 +
72125 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
72126 + return;
72127 +
72128 + spin_lock(&mm->page_table_lock);
72129 + oldlimit = mm->context.user_cs_limit;
72130 + if ((prot & VM_EXEC) && oldlimit < end)
72131 + /* USER_CS limit moved up */
72132 + newlimit = end;
72133 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
72134 + /* USER_CS limit moved down */
72135 + newlimit = start;
72136 +
72137 + if (newlimit) {
72138 + mm->context.user_cs_limit = newlimit;
72139 +
72140 +#ifdef CONFIG_SMP
72141 + wmb();
72142 + cpus_clear(mm->context.cpu_user_cs_mask);
72143 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
72144 +#endif
72145 +
72146 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
72147 + }
72148 + spin_unlock(&mm->page_table_lock);
72149 + if (newlimit == end) {
72150 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
72151 +
72152 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
72153 + if (is_vm_hugetlb_page(vma))
72154 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
72155 + else
72156 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
72157 + }
72158 +}
72159 +#endif
72160 +
72161 int
72162 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72163 unsigned long start, unsigned long end, unsigned long newflags)
72164 @@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72165 int error;
72166 int dirty_accountable = 0;
72167
72168 +#ifdef CONFIG_PAX_SEGMEXEC
72169 + struct vm_area_struct *vma_m = NULL;
72170 + unsigned long start_m, end_m;
72171 +
72172 + start_m = start + SEGMEXEC_TASK_SIZE;
72173 + end_m = end + SEGMEXEC_TASK_SIZE;
72174 +#endif
72175 +
72176 if (newflags == oldflags) {
72177 *pprev = vma;
72178 return 0;
72179 }
72180
72181 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
72182 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
72183 +
72184 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
72185 + return -ENOMEM;
72186 +
72187 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
72188 + return -ENOMEM;
72189 + }
72190 +
72191 /*
72192 * If we make a private mapping writable we increase our commit;
72193 * but (without finer accounting) cannot reduce our commit if we
72194 @@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72195 }
72196 }
72197
72198 +#ifdef CONFIG_PAX_SEGMEXEC
72199 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
72200 + if (start != vma->vm_start) {
72201 + error = split_vma(mm, vma, start, 1);
72202 + if (error)
72203 + goto fail;
72204 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
72205 + *pprev = (*pprev)->vm_next;
72206 + }
72207 +
72208 + if (end != vma->vm_end) {
72209 + error = split_vma(mm, vma, end, 0);
72210 + if (error)
72211 + goto fail;
72212 + }
72213 +
72214 + if (pax_find_mirror_vma(vma)) {
72215 + error = __do_munmap(mm, start_m, end_m - start_m);
72216 + if (error)
72217 + goto fail;
72218 + } else {
72219 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72220 + if (!vma_m) {
72221 + error = -ENOMEM;
72222 + goto fail;
72223 + }
72224 + vma->vm_flags = newflags;
72225 + error = pax_mirror_vma(vma_m, vma);
72226 + if (error) {
72227 + vma->vm_flags = oldflags;
72228 + goto fail;
72229 + }
72230 + }
72231 + }
72232 +#endif
72233 +
72234 /*
72235 * First try to merge with previous and/or next vma.
72236 */
72237 @@ -204,9 +307,21 @@ success:
72238 * vm_flags and vm_page_prot are protected by the mmap_sem
72239 * held in write mode.
72240 */
72241 +
72242 +#ifdef CONFIG_PAX_SEGMEXEC
72243 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
72244 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
72245 +#endif
72246 +
72247 vma->vm_flags = newflags;
72248 +
72249 +#ifdef CONFIG_PAX_MPROTECT
72250 + if (mm->binfmt && mm->binfmt->handle_mprotect)
72251 + mm->binfmt->handle_mprotect(vma, newflags);
72252 +#endif
72253 +
72254 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
72255 - vm_get_page_prot(newflags));
72256 + vm_get_page_prot(vma->vm_flags));
72257
72258 if (vma_wants_writenotify(vma)) {
72259 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
72260 @@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72261 end = start + len;
72262 if (end <= start)
72263 return -ENOMEM;
72264 +
72265 +#ifdef CONFIG_PAX_SEGMEXEC
72266 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
72267 + if (end > SEGMEXEC_TASK_SIZE)
72268 + return -EINVAL;
72269 + } else
72270 +#endif
72271 +
72272 + if (end > TASK_SIZE)
72273 + return -EINVAL;
72274 +
72275 if (!arch_validate_prot(prot))
72276 return -EINVAL;
72277
72278 @@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72279 /*
72280 * Does the application expect PROT_READ to imply PROT_EXEC:
72281 */
72282 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72283 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72284 prot |= PROT_EXEC;
72285
72286 vm_flags = calc_vm_prot_bits(prot);
72287 @@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72288 if (start > vma->vm_start)
72289 prev = vma;
72290
72291 +#ifdef CONFIG_PAX_MPROTECT
72292 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
72293 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
72294 +#endif
72295 +
72296 for (nstart = start ; ; ) {
72297 unsigned long newflags;
72298
72299 @@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72300
72301 /* newflags >> 4 shift VM_MAY% in place of VM_% */
72302 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
72303 + if (prot & (PROT_WRITE | PROT_EXEC))
72304 + gr_log_rwxmprotect(vma->vm_file);
72305 +
72306 + error = -EACCES;
72307 + goto out;
72308 + }
72309 +
72310 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
72311 error = -EACCES;
72312 goto out;
72313 }
72314 @@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72315 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
72316 if (error)
72317 goto out;
72318 +
72319 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
72320 +
72321 nstart = tmp;
72322
72323 if (nstart < prev->vm_end)
72324 diff --git a/mm/mremap.c b/mm/mremap.c
72325 index db8d983..76506cb 100644
72326 --- a/mm/mremap.c
72327 +++ b/mm/mremap.c
72328 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
72329 continue;
72330 pte = ptep_get_and_clear(mm, old_addr, old_pte);
72331 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
72332 +
72333 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
72334 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
72335 + pte = pte_exprotect(pte);
72336 +#endif
72337 +
72338 set_pte_at(mm, new_addr, new_pte, pte);
72339 }
72340
72341 @@ -299,6 +305,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
72342 if (is_vm_hugetlb_page(vma))
72343 goto Einval;
72344
72345 +#ifdef CONFIG_PAX_SEGMEXEC
72346 + if (pax_find_mirror_vma(vma))
72347 + goto Einval;
72348 +#endif
72349 +
72350 /* We can't remap across vm area boundaries */
72351 if (old_len > vma->vm_end - addr)
72352 goto Efault;
72353 @@ -355,20 +366,25 @@ static unsigned long mremap_to(unsigned long addr,
72354 unsigned long ret = -EINVAL;
72355 unsigned long charged = 0;
72356 unsigned long map_flags;
72357 + unsigned long pax_task_size = TASK_SIZE;
72358
72359 if (new_addr & ~PAGE_MASK)
72360 goto out;
72361
72362 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
72363 +#ifdef CONFIG_PAX_SEGMEXEC
72364 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
72365 + pax_task_size = SEGMEXEC_TASK_SIZE;
72366 +#endif
72367 +
72368 + pax_task_size -= PAGE_SIZE;
72369 +
72370 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
72371 goto out;
72372
72373 /* Check if the location we're moving into overlaps the
72374 * old location at all, and fail if it does.
72375 */
72376 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
72377 - goto out;
72378 -
72379 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
72380 + if (addr + old_len > new_addr && new_addr + new_len > addr)
72381 goto out;
72382
72383 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
72384 @@ -440,6 +456,7 @@ unsigned long do_mremap(unsigned long addr,
72385 struct vm_area_struct *vma;
72386 unsigned long ret = -EINVAL;
72387 unsigned long charged = 0;
72388 + unsigned long pax_task_size = TASK_SIZE;
72389
72390 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
72391 goto out;
72392 @@ -458,6 +475,17 @@ unsigned long do_mremap(unsigned long addr,
72393 if (!new_len)
72394 goto out;
72395
72396 +#ifdef CONFIG_PAX_SEGMEXEC
72397 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
72398 + pax_task_size = SEGMEXEC_TASK_SIZE;
72399 +#endif
72400 +
72401 + pax_task_size -= PAGE_SIZE;
72402 +
72403 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
72404 + old_len > pax_task_size || addr > pax_task_size-old_len)
72405 + goto out;
72406 +
72407 if (flags & MREMAP_FIXED) {
72408 if (flags & MREMAP_MAYMOVE)
72409 ret = mremap_to(addr, old_len, new_addr, new_len);
72410 @@ -507,6 +535,7 @@ unsigned long do_mremap(unsigned long addr,
72411 addr + new_len);
72412 }
72413 ret = addr;
72414 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
72415 goto out;
72416 }
72417 }
72418 @@ -533,7 +562,13 @@ unsigned long do_mremap(unsigned long addr,
72419 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
72420 if (ret)
72421 goto out;
72422 +
72423 + map_flags = vma->vm_flags;
72424 ret = move_vma(vma, addr, old_len, new_len, new_addr);
72425 + if (!(ret & ~PAGE_MASK)) {
72426 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
72427 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
72428 + }
72429 }
72430 out:
72431 if (ret & ~PAGE_MASK)
72432 diff --git a/mm/nommu.c b/mm/nommu.c
72433 index bb8f4f0..40d3e02 100644
72434 --- a/mm/nommu.c
72435 +++ b/mm/nommu.c
72436 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
72437 int sysctl_overcommit_ratio = 50; /* default is 50% */
72438 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
72439 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
72440 -int heap_stack_gap = 0;
72441
72442 atomic_long_t mmap_pages_allocated;
72443
72444 @@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
72445 EXPORT_SYMBOL(find_vma);
72446
72447 /*
72448 - * find a VMA
72449 - * - we don't extend stack VMAs under NOMMU conditions
72450 - */
72451 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
72452 -{
72453 - return find_vma(mm, addr);
72454 -}
72455 -
72456 -/*
72457 * expand a stack to a given address
72458 * - not supported under NOMMU conditions
72459 */
72460 @@ -1580,6 +1570,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72461
72462 /* most fields are the same, copy all, and then fixup */
72463 *new = *vma;
72464 + INIT_LIST_HEAD(&new->anon_vma_chain);
72465 *region = *vma->vm_region;
72466 new->vm_region = region;
72467
72468 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
72469 index 918330f..ae99ae1 100644
72470 --- a/mm/page_alloc.c
72471 +++ b/mm/page_alloc.c
72472 @@ -335,7 +335,7 @@ out:
72473 * This usage means that zero-order pages may not be compound.
72474 */
72475
72476 -static void free_compound_page(struct page *page)
72477 +void free_compound_page(struct page *page)
72478 {
72479 __free_pages_ok(page, compound_order(page));
72480 }
72481 @@ -692,6 +692,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
72482 int i;
72483 int bad = 0;
72484
72485 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
72486 + unsigned long index = 1UL << order;
72487 +#endif
72488 +
72489 trace_mm_page_free(page, order);
72490 kmemcheck_free_shadow(page, order);
72491
72492 @@ -707,6 +711,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
72493 debug_check_no_obj_freed(page_address(page),
72494 PAGE_SIZE << order);
72495 }
72496 +
72497 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
72498 + for (; index; --index)
72499 + sanitize_highpage(page + index - 1);
72500 +#endif
72501 +
72502 arch_free_page(page, order);
72503 kernel_map_pages(page, 1 << order, 0);
72504
72505 @@ -830,8 +840,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
72506 arch_alloc_page(page, order);
72507 kernel_map_pages(page, 1 << order, 1);
72508
72509 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
72510 if (gfp_flags & __GFP_ZERO)
72511 prep_zero_page(page, order, gfp_flags);
72512 +#endif
72513
72514 if (order && (gfp_flags & __GFP_COMP))
72515 prep_compound_page(page, order);
72516 @@ -3523,7 +3535,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
72517 unsigned long pfn;
72518
72519 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
72520 +#ifdef CONFIG_X86_32
72521 + /* boot failures in VMware 8 on 32bit vanilla since
72522 + this change */
72523 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
72524 +#else
72525 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
72526 +#endif
72527 return 1;
72528 }
72529 return 0;
72530 diff --git a/mm/percpu.c b/mm/percpu.c
72531 index bb4be74..a43ea85 100644
72532 --- a/mm/percpu.c
72533 +++ b/mm/percpu.c
72534 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
72535 static unsigned int pcpu_high_unit_cpu __read_mostly;
72536
72537 /* the address of the first chunk which starts with the kernel static area */
72538 -void *pcpu_base_addr __read_mostly;
72539 +void *pcpu_base_addr __read_only;
72540 EXPORT_SYMBOL_GPL(pcpu_base_addr);
72541
72542 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
72543 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
72544 index c20ff48..137702a 100644
72545 --- a/mm/process_vm_access.c
72546 +++ b/mm/process_vm_access.c
72547 @@ -13,6 +13,7 @@
72548 #include <linux/uio.h>
72549 #include <linux/sched.h>
72550 #include <linux/highmem.h>
72551 +#include <linux/security.h>
72552 #include <linux/ptrace.h>
72553 #include <linux/slab.h>
72554 #include <linux/syscalls.h>
72555 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
72556 size_t iov_l_curr_offset = 0;
72557 ssize_t iov_len;
72558
72559 + return -ENOSYS; // PaX: until properly audited
72560 +
72561 /*
72562 * Work out how many pages of struct pages we're going to need
72563 * when eventually calling get_user_pages
72564 */
72565 for (i = 0; i < riovcnt; i++) {
72566 iov_len = rvec[i].iov_len;
72567 - if (iov_len > 0) {
72568 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
72569 - + iov_len)
72570 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
72571 - / PAGE_SIZE + 1;
72572 - nr_pages = max(nr_pages, nr_pages_iov);
72573 - }
72574 + if (iov_len <= 0)
72575 + continue;
72576 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
72577 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
72578 + nr_pages = max(nr_pages, nr_pages_iov);
72579 }
72580
72581 if (nr_pages == 0)
72582 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
72583 goto free_proc_pages;
72584 }
72585
72586 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
72587 + rc = -EPERM;
72588 + goto put_task_struct;
72589 + }
72590 +
72591 mm = mm_access(task, PTRACE_MODE_ATTACH);
72592 if (!mm || IS_ERR(mm)) {
72593 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
72594 diff --git a/mm/rmap.c b/mm/rmap.c
72595 index 5b5ad58..0f77903 100644
72596 --- a/mm/rmap.c
72597 +++ b/mm/rmap.c
72598 @@ -167,6 +167,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
72599 struct anon_vma *anon_vma = vma->anon_vma;
72600 struct anon_vma_chain *avc;
72601
72602 +#ifdef CONFIG_PAX_SEGMEXEC
72603 + struct anon_vma_chain *avc_m = NULL;
72604 +#endif
72605 +
72606 might_sleep();
72607 if (unlikely(!anon_vma)) {
72608 struct mm_struct *mm = vma->vm_mm;
72609 @@ -176,6 +180,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
72610 if (!avc)
72611 goto out_enomem;
72612
72613 +#ifdef CONFIG_PAX_SEGMEXEC
72614 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
72615 + if (!avc_m)
72616 + goto out_enomem_free_avc;
72617 +#endif
72618 +
72619 anon_vma = find_mergeable_anon_vma(vma);
72620 allocated = NULL;
72621 if (!anon_vma) {
72622 @@ -189,6 +199,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
72623 /* page_table_lock to protect against threads */
72624 spin_lock(&mm->page_table_lock);
72625 if (likely(!vma->anon_vma)) {
72626 +
72627 +#ifdef CONFIG_PAX_SEGMEXEC
72628 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
72629 +
72630 + if (vma_m) {
72631 + BUG_ON(vma_m->anon_vma);
72632 + vma_m->anon_vma = anon_vma;
72633 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
72634 + avc_m = NULL;
72635 + }
72636 +#endif
72637 +
72638 vma->anon_vma = anon_vma;
72639 anon_vma_chain_link(vma, avc, anon_vma);
72640 allocated = NULL;
72641 @@ -199,12 +221,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
72642
72643 if (unlikely(allocated))
72644 put_anon_vma(allocated);
72645 +
72646 +#ifdef CONFIG_PAX_SEGMEXEC
72647 + if (unlikely(avc_m))
72648 + anon_vma_chain_free(avc_m);
72649 +#endif
72650 +
72651 if (unlikely(avc))
72652 anon_vma_chain_free(avc);
72653 }
72654 return 0;
72655
72656 out_enomem_free_avc:
72657 +
72658 +#ifdef CONFIG_PAX_SEGMEXEC
72659 + if (avc_m)
72660 + anon_vma_chain_free(avc_m);
72661 +#endif
72662 +
72663 anon_vma_chain_free(avc);
72664 out_enomem:
72665 return -ENOMEM;
72666 @@ -240,7 +274,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
72667 * Attach the anon_vmas from src to dst.
72668 * Returns 0 on success, -ENOMEM on failure.
72669 */
72670 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
72671 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
72672 {
72673 struct anon_vma_chain *avc, *pavc;
72674 struct anon_vma *root = NULL;
72675 @@ -318,7 +352,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
72676 * the corresponding VMA in the parent process is attached to.
72677 * Returns 0 on success, non-zero on failure.
72678 */
72679 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
72680 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
72681 {
72682 struct anon_vma_chain *avc;
72683 struct anon_vma *anon_vma;
72684 diff --git a/mm/shmem.c b/mm/shmem.c
72685 index 9d65a02..7c877e7 100644
72686 --- a/mm/shmem.c
72687 +++ b/mm/shmem.c
72688 @@ -31,7 +31,7 @@
72689 #include <linux/export.h>
72690 #include <linux/swap.h>
72691
72692 -static struct vfsmount *shm_mnt;
72693 +struct vfsmount *shm_mnt;
72694
72695 #ifdef CONFIG_SHMEM
72696 /*
72697 @@ -74,7 +74,7 @@ static struct vfsmount *shm_mnt;
72698 #define BOGO_DIRENT_SIZE 20
72699
72700 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
72701 -#define SHORT_SYMLINK_LEN 128
72702 +#define SHORT_SYMLINK_LEN 64
72703
72704 struct shmem_xattr {
72705 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
72706 @@ -2236,8 +2236,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
72707 int err = -ENOMEM;
72708
72709 /* Round up to L1_CACHE_BYTES to resist false sharing */
72710 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
72711 - L1_CACHE_BYTES), GFP_KERNEL);
72712 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
72713 if (!sbinfo)
72714 return -ENOMEM;
72715
72716 diff --git a/mm/slab.c b/mm/slab.c
72717 index e901a36..ee8fe97 100644
72718 --- a/mm/slab.c
72719 +++ b/mm/slab.c
72720 @@ -153,7 +153,7 @@
72721
72722 /* Legal flag mask for kmem_cache_create(). */
72723 #if DEBUG
72724 -# define CREATE_MASK (SLAB_RED_ZONE | \
72725 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
72726 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
72727 SLAB_CACHE_DMA | \
72728 SLAB_STORE_USER | \
72729 @@ -161,7 +161,7 @@
72730 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
72731 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
72732 #else
72733 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
72734 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
72735 SLAB_CACHE_DMA | \
72736 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
72737 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
72738 @@ -290,7 +290,7 @@ struct kmem_list3 {
72739 * Need this for bootstrapping a per node allocator.
72740 */
72741 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
72742 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
72743 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
72744 #define CACHE_CACHE 0
72745 #define SIZE_AC MAX_NUMNODES
72746 #define SIZE_L3 (2 * MAX_NUMNODES)
72747 @@ -391,10 +391,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
72748 if ((x)->max_freeable < i) \
72749 (x)->max_freeable = i; \
72750 } while (0)
72751 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
72752 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
72753 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
72754 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
72755 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
72756 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
72757 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
72758 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
72759 #else
72760 #define STATS_INC_ACTIVE(x) do { } while (0)
72761 #define STATS_DEC_ACTIVE(x) do { } while (0)
72762 @@ -542,7 +542,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
72763 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
72764 */
72765 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
72766 - const struct slab *slab, void *obj)
72767 + const struct slab *slab, const void *obj)
72768 {
72769 u32 offset = (obj - slab->s_mem);
72770 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
72771 @@ -568,7 +568,7 @@ struct cache_names {
72772 static struct cache_names __initdata cache_names[] = {
72773 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
72774 #include <linux/kmalloc_sizes.h>
72775 - {NULL,}
72776 + {NULL}
72777 #undef CACHE
72778 };
72779
72780 @@ -1588,7 +1588,7 @@ void __init kmem_cache_init(void)
72781 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
72782 sizes[INDEX_AC].cs_size,
72783 ARCH_KMALLOC_MINALIGN,
72784 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
72785 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
72786 NULL);
72787
72788 if (INDEX_AC != INDEX_L3) {
72789 @@ -1596,7 +1596,7 @@ void __init kmem_cache_init(void)
72790 kmem_cache_create(names[INDEX_L3].name,
72791 sizes[INDEX_L3].cs_size,
72792 ARCH_KMALLOC_MINALIGN,
72793 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
72794 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
72795 NULL);
72796 }
72797
72798 @@ -1614,7 +1614,7 @@ void __init kmem_cache_init(void)
72799 sizes->cs_cachep = kmem_cache_create(names->name,
72800 sizes->cs_size,
72801 ARCH_KMALLOC_MINALIGN,
72802 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
72803 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
72804 NULL);
72805 }
72806 #ifdef CONFIG_ZONE_DMA
72807 @@ -4390,10 +4390,10 @@ static int s_show(struct seq_file *m, void *p)
72808 }
72809 /* cpu stats */
72810 {
72811 - unsigned long allochit = atomic_read(&cachep->allochit);
72812 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
72813 - unsigned long freehit = atomic_read(&cachep->freehit);
72814 - unsigned long freemiss = atomic_read(&cachep->freemiss);
72815 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
72816 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
72817 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
72818 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
72819
72820 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
72821 allochit, allocmiss, freehit, freemiss);
72822 @@ -4652,13 +4652,62 @@ static int __init slab_proc_init(void)
72823 {
72824 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
72825 #ifdef CONFIG_DEBUG_SLAB_LEAK
72826 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
72827 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
72828 #endif
72829 return 0;
72830 }
72831 module_init(slab_proc_init);
72832 #endif
72833
72834 +void check_object_size(const void *ptr, unsigned long n, bool to)
72835 +{
72836 +
72837 +#ifdef CONFIG_PAX_USERCOPY
72838 + struct page *page;
72839 + struct kmem_cache *cachep = NULL;
72840 + struct slab *slabp;
72841 + unsigned int objnr;
72842 + unsigned long offset;
72843 + const char *type;
72844 +
72845 + if (!n)
72846 + return;
72847 +
72848 + type = "<null>";
72849 + if (ZERO_OR_NULL_PTR(ptr))
72850 + goto report;
72851 +
72852 + if (!virt_addr_valid(ptr))
72853 + return;
72854 +
72855 + page = virt_to_head_page(ptr);
72856 +
72857 + type = "<process stack>";
72858 + if (!PageSlab(page)) {
72859 + if (object_is_on_stack(ptr, n) == -1)
72860 + goto report;
72861 + return;
72862 + }
72863 +
72864 + cachep = page_get_cache(page);
72865 + type = cachep->name;
72866 + if (!(cachep->flags & SLAB_USERCOPY))
72867 + goto report;
72868 +
72869 + slabp = page_get_slab(page);
72870 + objnr = obj_to_index(cachep, slabp, ptr);
72871 + BUG_ON(objnr >= cachep->num);
72872 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
72873 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
72874 + return;
72875 +
72876 +report:
72877 + pax_report_usercopy(ptr, n, to, type);
72878 +#endif
72879 +
72880 +}
72881 +EXPORT_SYMBOL(check_object_size);
72882 +
72883 /**
72884 * ksize - get the actual amount of memory allocated for a given object
72885 * @objp: Pointer to the object
72886 diff --git a/mm/slob.c b/mm/slob.c
72887 index 8105be4..e045f96 100644
72888 --- a/mm/slob.c
72889 +++ b/mm/slob.c
72890 @@ -29,7 +29,7 @@
72891 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
72892 * alloc_pages() directly, allocating compound pages so the page order
72893 * does not have to be separately tracked, and also stores the exact
72894 - * allocation size in page->private so that it can be used to accurately
72895 + * allocation size in slob_page->size so that it can be used to accurately
72896 * provide ksize(). These objects are detected in kfree() because slob_page()
72897 * is false for them.
72898 *
72899 @@ -58,6 +58,7 @@
72900 */
72901
72902 #include <linux/kernel.h>
72903 +#include <linux/sched.h>
72904 #include <linux/slab.h>
72905 #include <linux/mm.h>
72906 #include <linux/swap.h> /* struct reclaim_state */
72907 @@ -102,7 +103,8 @@ struct slob_page {
72908 unsigned long flags; /* mandatory */
72909 atomic_t _count; /* mandatory */
72910 slobidx_t units; /* free units left in page */
72911 - unsigned long pad[2];
72912 + unsigned long pad[1];
72913 + unsigned long size; /* size when >=PAGE_SIZE */
72914 slob_t *free; /* first free slob_t in page */
72915 struct list_head list; /* linked list of free pages */
72916 };
72917 @@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
72918 */
72919 static inline int is_slob_page(struct slob_page *sp)
72920 {
72921 - return PageSlab((struct page *)sp);
72922 + return PageSlab((struct page *)sp) && !sp->size;
72923 }
72924
72925 static inline void set_slob_page(struct slob_page *sp)
72926 @@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
72927
72928 static inline struct slob_page *slob_page(const void *addr)
72929 {
72930 - return (struct slob_page *)virt_to_page(addr);
72931 + return (struct slob_page *)virt_to_head_page(addr);
72932 }
72933
72934 /*
72935 @@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
72936 /*
72937 * Return the size of a slob block.
72938 */
72939 -static slobidx_t slob_units(slob_t *s)
72940 +static slobidx_t slob_units(const slob_t *s)
72941 {
72942 if (s->units > 0)
72943 return s->units;
72944 @@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
72945 /*
72946 * Return the next free slob block pointer after this one.
72947 */
72948 -static slob_t *slob_next(slob_t *s)
72949 +static slob_t *slob_next(const slob_t *s)
72950 {
72951 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
72952 slobidx_t next;
72953 @@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
72954 /*
72955 * Returns true if s is the last free block in its page.
72956 */
72957 -static int slob_last(slob_t *s)
72958 +static int slob_last(const slob_t *s)
72959 {
72960 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
72961 }
72962 @@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
72963 if (!page)
72964 return NULL;
72965
72966 + set_slob_page(page);
72967 return page_address(page);
72968 }
72969
72970 @@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
72971 if (!b)
72972 return NULL;
72973 sp = slob_page(b);
72974 - set_slob_page(sp);
72975
72976 spin_lock_irqsave(&slob_lock, flags);
72977 sp->units = SLOB_UNITS(PAGE_SIZE);
72978 sp->free = b;
72979 + sp->size = 0;
72980 INIT_LIST_HEAD(&sp->list);
72981 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
72982 set_slob_page_free(sp, slob_list);
72983 @@ -476,10 +479,9 @@ out:
72984 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
72985 */
72986
72987 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72988 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
72989 {
72990 - unsigned int *m;
72991 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
72992 + slob_t *m;
72993 void *ret;
72994
72995 gfp &= gfp_allowed_mask;
72996 @@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
72997
72998 if (!m)
72999 return NULL;
73000 - *m = size;
73001 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
73002 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
73003 + m[0].units = size;
73004 + m[1].units = align;
73005 ret = (void *)m + align;
73006
73007 trace_kmalloc_node(_RET_IP_, ret,
73008 @@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73009 gfp |= __GFP_COMP;
73010 ret = slob_new_pages(gfp, order, node);
73011 if (ret) {
73012 - struct page *page;
73013 - page = virt_to_page(ret);
73014 - page->private = size;
73015 + struct slob_page *sp;
73016 + sp = slob_page(ret);
73017 + sp->size = size;
73018 }
73019
73020 trace_kmalloc_node(_RET_IP_, ret,
73021 size, PAGE_SIZE << order, gfp, node);
73022 }
73023
73024 - kmemleak_alloc(ret, size, 1, gfp);
73025 + return ret;
73026 +}
73027 +
73028 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73029 +{
73030 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73031 + void *ret = __kmalloc_node_align(size, gfp, node, align);
73032 +
73033 + if (!ZERO_OR_NULL_PTR(ret))
73034 + kmemleak_alloc(ret, size, 1, gfp);
73035 return ret;
73036 }
73037 EXPORT_SYMBOL(__kmalloc_node);
73038 @@ -533,13 +547,92 @@ void kfree(const void *block)
73039 sp = slob_page(block);
73040 if (is_slob_page(sp)) {
73041 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73042 - unsigned int *m = (unsigned int *)(block - align);
73043 - slob_free(m, *m + align);
73044 - } else
73045 + slob_t *m = (slob_t *)(block - align);
73046 + slob_free(m, m[0].units + align);
73047 + } else {
73048 + clear_slob_page(sp);
73049 + free_slob_page(sp);
73050 + sp->size = 0;
73051 put_page(&sp->page);
73052 + }
73053 }
73054 EXPORT_SYMBOL(kfree);
73055
73056 +void check_object_size(const void *ptr, unsigned long n, bool to)
73057 +{
73058 +
73059 +#ifdef CONFIG_PAX_USERCOPY
73060 + struct slob_page *sp;
73061 + const slob_t *free;
73062 + const void *base;
73063 + unsigned long flags;
73064 + const char *type;
73065 +
73066 + if (!n)
73067 + return;
73068 +
73069 + type = "<null>";
73070 + if (ZERO_OR_NULL_PTR(ptr))
73071 + goto report;
73072 +
73073 + if (!virt_addr_valid(ptr))
73074 + return;
73075 +
73076 + type = "<process stack>";
73077 + sp = slob_page(ptr);
73078 + if (!PageSlab((struct page *)sp)) {
73079 + if (object_is_on_stack(ptr, n) == -1)
73080 + goto report;
73081 + return;
73082 + }
73083 +
73084 + type = "<slob>";
73085 + if (sp->size) {
73086 + base = page_address(&sp->page);
73087 + if (base <= ptr && n <= sp->size - (ptr - base))
73088 + return;
73089 + goto report;
73090 + }
73091 +
73092 + /* some tricky double walking to find the chunk */
73093 + spin_lock_irqsave(&slob_lock, flags);
73094 + base = (void *)((unsigned long)ptr & PAGE_MASK);
73095 + free = sp->free;
73096 +
73097 + while (!slob_last(free) && (void *)free <= ptr) {
73098 + base = free + slob_units(free);
73099 + free = slob_next(free);
73100 + }
73101 +
73102 + while (base < (void *)free) {
73103 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
73104 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
73105 + int offset;
73106 +
73107 + if (ptr < base + align)
73108 + break;
73109 +
73110 + offset = ptr - base - align;
73111 + if (offset >= m) {
73112 + base += size;
73113 + continue;
73114 + }
73115 +
73116 + if (n > m - offset)
73117 + break;
73118 +
73119 + spin_unlock_irqrestore(&slob_lock, flags);
73120 + return;
73121 + }
73122 +
73123 + spin_unlock_irqrestore(&slob_lock, flags);
73124 +report:
73125 + pax_report_usercopy(ptr, n, to, type);
73126 +#endif
73127 +
73128 +}
73129 +EXPORT_SYMBOL(check_object_size);
73130 +
73131 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
73132 size_t ksize(const void *block)
73133 {
73134 @@ -552,10 +645,10 @@ size_t ksize(const void *block)
73135 sp = slob_page(block);
73136 if (is_slob_page(sp)) {
73137 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73138 - unsigned int *m = (unsigned int *)(block - align);
73139 - return SLOB_UNITS(*m) * SLOB_UNIT;
73140 + slob_t *m = (slob_t *)(block - align);
73141 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
73142 } else
73143 - return sp->page.private;
73144 + return sp->size;
73145 }
73146 EXPORT_SYMBOL(ksize);
73147
73148 @@ -571,8 +664,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73149 {
73150 struct kmem_cache *c;
73151
73152 +#ifdef CONFIG_PAX_USERCOPY
73153 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
73154 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
73155 +#else
73156 c = slob_alloc(sizeof(struct kmem_cache),
73157 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
73158 +#endif
73159
73160 if (c) {
73161 c->name = name;
73162 @@ -614,17 +712,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
73163
73164 lockdep_trace_alloc(flags);
73165
73166 +#ifdef CONFIG_PAX_USERCOPY
73167 + b = __kmalloc_node_align(c->size, flags, node, c->align);
73168 +#else
73169 if (c->size < PAGE_SIZE) {
73170 b = slob_alloc(c->size, flags, c->align, node);
73171 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
73172 SLOB_UNITS(c->size) * SLOB_UNIT,
73173 flags, node);
73174 } else {
73175 + struct slob_page *sp;
73176 +
73177 b = slob_new_pages(flags, get_order(c->size), node);
73178 + sp = slob_page(b);
73179 + sp->size = c->size;
73180 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
73181 PAGE_SIZE << get_order(c->size),
73182 flags, node);
73183 }
73184 +#endif
73185
73186 if (c->ctor)
73187 c->ctor(b);
73188 @@ -636,10 +742,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
73189
73190 static void __kmem_cache_free(void *b, int size)
73191 {
73192 - if (size < PAGE_SIZE)
73193 + struct slob_page *sp = slob_page(b);
73194 +
73195 + if (is_slob_page(sp))
73196 slob_free(b, size);
73197 - else
73198 + else {
73199 + clear_slob_page(sp);
73200 + free_slob_page(sp);
73201 + sp->size = 0;
73202 slob_free_pages(b, get_order(size));
73203 + }
73204 }
73205
73206 static void kmem_rcu_free(struct rcu_head *head)
73207 @@ -652,17 +764,31 @@ static void kmem_rcu_free(struct rcu_head *head)
73208
73209 void kmem_cache_free(struct kmem_cache *c, void *b)
73210 {
73211 + int size = c->size;
73212 +
73213 +#ifdef CONFIG_PAX_USERCOPY
73214 + if (size + c->align < PAGE_SIZE) {
73215 + size += c->align;
73216 + b -= c->align;
73217 + }
73218 +#endif
73219 +
73220 kmemleak_free_recursive(b, c->flags);
73221 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
73222 struct slob_rcu *slob_rcu;
73223 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
73224 - slob_rcu->size = c->size;
73225 + slob_rcu = b + (size - sizeof(struct slob_rcu));
73226 + slob_rcu->size = size;
73227 call_rcu(&slob_rcu->head, kmem_rcu_free);
73228 } else {
73229 - __kmem_cache_free(b, c->size);
73230 + __kmem_cache_free(b, size);
73231 }
73232
73233 +#ifdef CONFIG_PAX_USERCOPY
73234 + trace_kfree(_RET_IP_, b);
73235 +#else
73236 trace_kmem_cache_free(_RET_IP_, b);
73237 +#endif
73238 +
73239 }
73240 EXPORT_SYMBOL(kmem_cache_free);
73241
73242 diff --git a/mm/slub.c b/mm/slub.c
73243 index 71de9b5..dd263c5 100644
73244 --- a/mm/slub.c
73245 +++ b/mm/slub.c
73246 @@ -209,7 +209,7 @@ struct track {
73247
73248 enum track_item { TRACK_ALLOC, TRACK_FREE };
73249
73250 -#ifdef CONFIG_SYSFS
73251 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73252 static int sysfs_slab_add(struct kmem_cache *);
73253 static int sysfs_slab_alias(struct kmem_cache *, const char *);
73254 static void sysfs_slab_remove(struct kmem_cache *);
73255 @@ -538,7 +538,7 @@ static void print_track(const char *s, struct track *t)
73256 if (!t->addr)
73257 return;
73258
73259 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
73260 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
73261 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
73262 #ifdef CONFIG_STACKTRACE
73263 {
73264 @@ -2603,6 +2603,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
73265
73266 page = virt_to_head_page(x);
73267
73268 + BUG_ON(!PageSlab(page));
73269 +
73270 slab_free(s, page, x, _RET_IP_);
73271
73272 trace_kmem_cache_free(_RET_IP_, x);
73273 @@ -2636,7 +2638,7 @@ static int slub_min_objects;
73274 * Merge control. If this is set then no merging of slab caches will occur.
73275 * (Could be removed. This was introduced to pacify the merge skeptics.)
73276 */
73277 -static int slub_nomerge;
73278 +static int slub_nomerge = 1;
73279
73280 /*
73281 * Calculate the order of allocation given an slab object size.
73282 @@ -3089,7 +3091,7 @@ static int kmem_cache_open(struct kmem_cache *s,
73283 else
73284 s->cpu_partial = 30;
73285
73286 - s->refcount = 1;
73287 + atomic_set(&s->refcount, 1);
73288 #ifdef CONFIG_NUMA
73289 s->remote_node_defrag_ratio = 1000;
73290 #endif
73291 @@ -3193,8 +3195,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
73292 void kmem_cache_destroy(struct kmem_cache *s)
73293 {
73294 down_write(&slub_lock);
73295 - s->refcount--;
73296 - if (!s->refcount) {
73297 + if (atomic_dec_and_test(&s->refcount)) {
73298 list_del(&s->list);
73299 up_write(&slub_lock);
73300 if (kmem_cache_close(s)) {
73301 @@ -3405,6 +3406,50 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
73302 EXPORT_SYMBOL(__kmalloc_node);
73303 #endif
73304
73305 +void check_object_size(const void *ptr, unsigned long n, bool to)
73306 +{
73307 +
73308 +#ifdef CONFIG_PAX_USERCOPY
73309 + struct page *page;
73310 + struct kmem_cache *s = NULL;
73311 + unsigned long offset;
73312 + const char *type;
73313 +
73314 + if (!n)
73315 + return;
73316 +
73317 + type = "<null>";
73318 + if (ZERO_OR_NULL_PTR(ptr))
73319 + goto report;
73320 +
73321 + if (!virt_addr_valid(ptr))
73322 + return;
73323 +
73324 + page = virt_to_head_page(ptr);
73325 +
73326 + type = "<process stack>";
73327 + if (!PageSlab(page)) {
73328 + if (object_is_on_stack(ptr, n) == -1)
73329 + goto report;
73330 + return;
73331 + }
73332 +
73333 + s = page->slab;
73334 + type = s->name;
73335 + if (!(s->flags & SLAB_USERCOPY))
73336 + goto report;
73337 +
73338 + offset = (ptr - page_address(page)) % s->size;
73339 + if (offset <= s->objsize && n <= s->objsize - offset)
73340 + return;
73341 +
73342 +report:
73343 + pax_report_usercopy(ptr, n, to, type);
73344 +#endif
73345 +
73346 +}
73347 +EXPORT_SYMBOL(check_object_size);
73348 +
73349 size_t ksize(const void *object)
73350 {
73351 struct page *page;
73352 @@ -3679,7 +3724,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
73353 int node;
73354
73355 list_add(&s->list, &slab_caches);
73356 - s->refcount = -1;
73357 + atomic_set(&s->refcount, -1);
73358
73359 for_each_node_state(node, N_NORMAL_MEMORY) {
73360 struct kmem_cache_node *n = get_node(s, node);
73361 @@ -3799,17 +3844,17 @@ void __init kmem_cache_init(void)
73362
73363 /* Caches that are not of the two-to-the-power-of size */
73364 if (KMALLOC_MIN_SIZE <= 32) {
73365 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
73366 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
73367 caches++;
73368 }
73369
73370 if (KMALLOC_MIN_SIZE <= 64) {
73371 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
73372 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
73373 caches++;
73374 }
73375
73376 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
73377 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
73378 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
73379 caches++;
73380 }
73381
73382 @@ -3877,7 +3922,7 @@ static int slab_unmergeable(struct kmem_cache *s)
73383 /*
73384 * We may have set a slab to be unmergeable during bootstrap.
73385 */
73386 - if (s->refcount < 0)
73387 + if (atomic_read(&s->refcount) < 0)
73388 return 1;
73389
73390 return 0;
73391 @@ -3936,7 +3981,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73392 down_write(&slub_lock);
73393 s = find_mergeable(size, align, flags, name, ctor);
73394 if (s) {
73395 - s->refcount++;
73396 + atomic_inc(&s->refcount);
73397 /*
73398 * Adjust the object sizes so that we clear
73399 * the complete object on kzalloc.
73400 @@ -3945,7 +3990,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73401 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
73402
73403 if (sysfs_slab_alias(s, name)) {
73404 - s->refcount--;
73405 + atomic_dec(&s->refcount);
73406 goto err;
73407 }
73408 up_write(&slub_lock);
73409 @@ -4074,7 +4119,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
73410 }
73411 #endif
73412
73413 -#ifdef CONFIG_SYSFS
73414 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73415 static int count_inuse(struct page *page)
73416 {
73417 return page->inuse;
73418 @@ -4461,12 +4506,12 @@ static void resiliency_test(void)
73419 validate_slab_cache(kmalloc_caches[9]);
73420 }
73421 #else
73422 -#ifdef CONFIG_SYSFS
73423 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73424 static void resiliency_test(void) {};
73425 #endif
73426 #endif
73427
73428 -#ifdef CONFIG_SYSFS
73429 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73430 enum slab_stat_type {
73431 SL_ALL, /* All slabs */
73432 SL_PARTIAL, /* Only partially allocated slabs */
73433 @@ -4709,7 +4754,7 @@ SLAB_ATTR_RO(ctor);
73434
73435 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
73436 {
73437 - return sprintf(buf, "%d\n", s->refcount - 1);
73438 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
73439 }
73440 SLAB_ATTR_RO(aliases);
73441
73442 @@ -5280,6 +5325,7 @@ static char *create_unique_id(struct kmem_cache *s)
73443 return name;
73444 }
73445
73446 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73447 static int sysfs_slab_add(struct kmem_cache *s)
73448 {
73449 int err;
73450 @@ -5342,6 +5388,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
73451 kobject_del(&s->kobj);
73452 kobject_put(&s->kobj);
73453 }
73454 +#endif
73455
73456 /*
73457 * Need to buffer aliases during bootup until sysfs becomes
73458 @@ -5355,6 +5402,7 @@ struct saved_alias {
73459
73460 static struct saved_alias *alias_list;
73461
73462 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73463 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
73464 {
73465 struct saved_alias *al;
73466 @@ -5377,6 +5425,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
73467 alias_list = al;
73468 return 0;
73469 }
73470 +#endif
73471
73472 static int __init slab_sysfs_init(void)
73473 {
73474 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
73475 index 1b7e22a..3fcd4f3 100644
73476 --- a/mm/sparse-vmemmap.c
73477 +++ b/mm/sparse-vmemmap.c
73478 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
73479 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
73480 if (!p)
73481 return NULL;
73482 - pud_populate(&init_mm, pud, p);
73483 + pud_populate_kernel(&init_mm, pud, p);
73484 }
73485 return pud;
73486 }
73487 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
73488 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
73489 if (!p)
73490 return NULL;
73491 - pgd_populate(&init_mm, pgd, p);
73492 + pgd_populate_kernel(&init_mm, pgd, p);
73493 }
73494 return pgd;
73495 }
73496 diff --git a/mm/swap.c b/mm/swap.c
73497 index 5c13f13..f1cfc13 100644
73498 --- a/mm/swap.c
73499 +++ b/mm/swap.c
73500 @@ -30,6 +30,7 @@
73501 #include <linux/backing-dev.h>
73502 #include <linux/memcontrol.h>
73503 #include <linux/gfp.h>
73504 +#include <linux/hugetlb.h>
73505
73506 #include "internal.h"
73507
73508 @@ -70,6 +71,8 @@ static void __put_compound_page(struct page *page)
73509
73510 __page_cache_release(page);
73511 dtor = get_compound_page_dtor(page);
73512 + if (!PageHuge(page))
73513 + BUG_ON(dtor != free_compound_page);
73514 (*dtor)(page);
73515 }
73516
73517 diff --git a/mm/swapfile.c b/mm/swapfile.c
73518 index 38186d9..bfba6d3 100644
73519 --- a/mm/swapfile.c
73520 +++ b/mm/swapfile.c
73521 @@ -61,7 +61,7 @@ static DEFINE_MUTEX(swapon_mutex);
73522
73523 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
73524 /* Activity counter to indicate that a swapon or swapoff has occurred */
73525 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
73526 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
73527
73528 static inline unsigned char swap_count(unsigned char ent)
73529 {
73530 @@ -1671,7 +1671,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
73531 }
73532 filp_close(swap_file, NULL);
73533 err = 0;
73534 - atomic_inc(&proc_poll_event);
73535 + atomic_inc_unchecked(&proc_poll_event);
73536 wake_up_interruptible(&proc_poll_wait);
73537
73538 out_dput:
73539 @@ -1687,8 +1687,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
73540
73541 poll_wait(file, &proc_poll_wait, wait);
73542
73543 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
73544 - seq->poll_event = atomic_read(&proc_poll_event);
73545 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
73546 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
73547 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
73548 }
73549
73550 @@ -1786,7 +1786,7 @@ static int swaps_open(struct inode *inode, struct file *file)
73551 return ret;
73552
73553 seq = file->private_data;
73554 - seq->poll_event = atomic_read(&proc_poll_event);
73555 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
73556 return 0;
73557 }
73558
73559 @@ -2123,7 +2123,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
73560 (p->flags & SWP_DISCARDABLE) ? "D" : "");
73561
73562 mutex_unlock(&swapon_mutex);
73563 - atomic_inc(&proc_poll_event);
73564 + atomic_inc_unchecked(&proc_poll_event);
73565 wake_up_interruptible(&proc_poll_wait);
73566
73567 if (S_ISREG(inode->i_mode))
73568 diff --git a/mm/util.c b/mm/util.c
73569 index ae962b3..0bba886 100644
73570 --- a/mm/util.c
73571 +++ b/mm/util.c
73572 @@ -284,6 +284,12 @@ done:
73573 void arch_pick_mmap_layout(struct mm_struct *mm)
73574 {
73575 mm->mmap_base = TASK_UNMAPPED_BASE;
73576 +
73577 +#ifdef CONFIG_PAX_RANDMMAP
73578 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73579 + mm->mmap_base += mm->delta_mmap;
73580 +#endif
73581 +
73582 mm->get_unmapped_area = arch_get_unmapped_area;
73583 mm->unmap_area = arch_unmap_area;
73584 }
73585 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
73586 index 1196c77..2e608e8 100644
73587 --- a/mm/vmalloc.c
73588 +++ b/mm/vmalloc.c
73589 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
73590
73591 pte = pte_offset_kernel(pmd, addr);
73592 do {
73593 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
73594 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
73595 +
73596 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
73597 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
73598 + BUG_ON(!pte_exec(*pte));
73599 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
73600 + continue;
73601 + }
73602 +#endif
73603 +
73604 + {
73605 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
73606 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
73607 + }
73608 } while (pte++, addr += PAGE_SIZE, addr != end);
73609 }
73610
73611 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
73612 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
73613 {
73614 pte_t *pte;
73615 + int ret = -ENOMEM;
73616
73617 /*
73618 * nr is a running index into the array which helps higher level
73619 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
73620 pte = pte_alloc_kernel(pmd, addr);
73621 if (!pte)
73622 return -ENOMEM;
73623 +
73624 + pax_open_kernel();
73625 do {
73626 struct page *page = pages[*nr];
73627
73628 - if (WARN_ON(!pte_none(*pte)))
73629 - return -EBUSY;
73630 - if (WARN_ON(!page))
73631 - return -ENOMEM;
73632 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
73633 + if (pgprot_val(prot) & _PAGE_NX)
73634 +#endif
73635 +
73636 + if (WARN_ON(!pte_none(*pte))) {
73637 + ret = -EBUSY;
73638 + goto out;
73639 + }
73640 + if (WARN_ON(!page)) {
73641 + ret = -ENOMEM;
73642 + goto out;
73643 + }
73644 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
73645 (*nr)++;
73646 } while (pte++, addr += PAGE_SIZE, addr != end);
73647 - return 0;
73648 + ret = 0;
73649 +out:
73650 + pax_close_kernel();
73651 + return ret;
73652 }
73653
73654 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
73655 @@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
73656 pmd_t *pmd;
73657 unsigned long next;
73658
73659 - pmd = pmd_alloc(&init_mm, pud, addr);
73660 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
73661 if (!pmd)
73662 return -ENOMEM;
73663 do {
73664 @@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
73665 pud_t *pud;
73666 unsigned long next;
73667
73668 - pud = pud_alloc(&init_mm, pgd, addr);
73669 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
73670 if (!pud)
73671 return -ENOMEM;
73672 do {
73673 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
73674 * and fall back on vmalloc() if that fails. Others
73675 * just put it in the vmalloc space.
73676 */
73677 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
73678 +#ifdef CONFIG_MODULES
73679 +#ifdef MODULES_VADDR
73680 unsigned long addr = (unsigned long)x;
73681 if (addr >= MODULES_VADDR && addr < MODULES_END)
73682 return 1;
73683 #endif
73684 +
73685 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
73686 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
73687 + return 1;
73688 +#endif
73689 +
73690 +#endif
73691 +
73692 return is_vmalloc_addr(x);
73693 }
73694
73695 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
73696
73697 if (!pgd_none(*pgd)) {
73698 pud_t *pud = pud_offset(pgd, addr);
73699 +#ifdef CONFIG_X86
73700 + if (!pud_large(*pud))
73701 +#endif
73702 if (!pud_none(*pud)) {
73703 pmd_t *pmd = pmd_offset(pud, addr);
73704 +#ifdef CONFIG_X86
73705 + if (!pmd_large(*pmd))
73706 +#endif
73707 if (!pmd_none(*pmd)) {
73708 pte_t *ptep, pte;
73709
73710 @@ -332,6 +372,10 @@ static void purge_vmap_area_lazy(void);
73711 static struct vmap_area *alloc_vmap_area(unsigned long size,
73712 unsigned long align,
73713 unsigned long vstart, unsigned long vend,
73714 + int node, gfp_t gfp_mask) __size_overflow(1);
73715 +static struct vmap_area *alloc_vmap_area(unsigned long size,
73716 + unsigned long align,
73717 + unsigned long vstart, unsigned long vend,
73718 int node, gfp_t gfp_mask)
73719 {
73720 struct vmap_area *va;
73721 @@ -1320,6 +1364,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
73722 struct vm_struct *area;
73723
73724 BUG_ON(in_interrupt());
73725 +
73726 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
73727 + if (flags & VM_KERNEXEC) {
73728 + if (start != VMALLOC_START || end != VMALLOC_END)
73729 + return NULL;
73730 + start = (unsigned long)MODULES_EXEC_VADDR;
73731 + end = (unsigned long)MODULES_EXEC_END;
73732 + }
73733 +#endif
73734 +
73735 if (flags & VM_IOREMAP) {
73736 int bit = fls(size);
73737
73738 @@ -1552,6 +1606,11 @@ void *vmap(struct page **pages, unsigned int count,
73739 if (count > totalram_pages)
73740 return NULL;
73741
73742 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
73743 + if (!(pgprot_val(prot) & _PAGE_NX))
73744 + flags |= VM_KERNEXEC;
73745 +#endif
73746 +
73747 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
73748 __builtin_return_address(0));
73749 if (!area)
73750 @@ -1653,6 +1712,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
73751 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
73752 goto fail;
73753
73754 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
73755 + if (!(pgprot_val(prot) & _PAGE_NX))
73756 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
73757 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
73758 + else
73759 +#endif
73760 +
73761 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
73762 start, end, node, gfp_mask, caller);
73763 if (!area)
73764 @@ -1826,10 +1892,9 @@ EXPORT_SYMBOL(vzalloc_node);
73765 * For tight control over page level allocator and protection flags
73766 * use __vmalloc() instead.
73767 */
73768 -
73769 void *vmalloc_exec(unsigned long size)
73770 {
73771 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
73772 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
73773 -1, __builtin_return_address(0));
73774 }
73775
73776 @@ -2124,6 +2189,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
73777 unsigned long uaddr = vma->vm_start;
73778 unsigned long usize = vma->vm_end - vma->vm_start;
73779
73780 + BUG_ON(vma->vm_mirror);
73781 +
73782 if ((PAGE_SIZE-1) & (unsigned long)addr)
73783 return -EINVAL;
73784
73785 @@ -2376,8 +2443,8 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
73786 return NULL;
73787 }
73788
73789 - vms = kzalloc(sizeof(vms[0]) * nr_vms, GFP_KERNEL);
73790 - vas = kzalloc(sizeof(vas[0]) * nr_vms, GFP_KERNEL);
73791 + vms = kcalloc(nr_vms, sizeof(vms[0]), GFP_KERNEL);
73792 + vas = kcalloc(nr_vms, sizeof(vas[0]), GFP_KERNEL);
73793 if (!vas || !vms)
73794 goto err_free2;
73795
73796 diff --git a/mm/vmscan.c b/mm/vmscan.c
73797 index 4607cc6..be5bc0a 100644
73798 --- a/mm/vmscan.c
73799 +++ b/mm/vmscan.c
73800 @@ -3013,7 +3013,10 @@ static void kswapd_try_to_sleep(pg_data_t *pgdat, int order, int classzone_idx)
73801 * them before going back to sleep.
73802 */
73803 set_pgdat_percpu_threshold(pgdat, calculate_normal_threshold);
73804 - schedule();
73805 +
73806 + if (!kthread_should_stop())
73807 + schedule();
73808 +
73809 set_pgdat_percpu_threshold(pgdat, calculate_pressure_threshold);
73810 } else {
73811 if (remaining)
73812 diff --git a/mm/vmstat.c b/mm/vmstat.c
73813 index 7db1b9b..e9f6b07 100644
73814 --- a/mm/vmstat.c
73815 +++ b/mm/vmstat.c
73816 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
73817 *
73818 * vm_stat contains the global counters
73819 */
73820 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
73821 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
73822 EXPORT_SYMBOL(vm_stat);
73823
73824 #ifdef CONFIG_SMP
73825 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
73826 v = p->vm_stat_diff[i];
73827 p->vm_stat_diff[i] = 0;
73828 local_irq_restore(flags);
73829 - atomic_long_add(v, &zone->vm_stat[i]);
73830 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
73831 global_diff[i] += v;
73832 #ifdef CONFIG_NUMA
73833 /* 3 seconds idle till flush */
73834 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
73835
73836 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
73837 if (global_diff[i])
73838 - atomic_long_add(global_diff[i], &vm_stat[i]);
73839 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
73840 }
73841
73842 #endif
73843 @@ -1208,10 +1208,20 @@ static int __init setup_vmstat(void)
73844 start_cpu_timer(cpu);
73845 #endif
73846 #ifdef CONFIG_PROC_FS
73847 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
73848 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
73849 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
73850 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
73851 + {
73852 + mode_t gr_mode = S_IRUGO;
73853 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
73854 + gr_mode = S_IRUSR;
73855 +#endif
73856 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
73857 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
73858 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
73859 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
73860 +#else
73861 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
73862 +#endif
73863 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
73864 + }
73865 #endif
73866 return 0;
73867 }
73868 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
73869 index efea35b..9c8dd0b 100644
73870 --- a/net/8021q/vlan.c
73871 +++ b/net/8021q/vlan.c
73872 @@ -554,8 +554,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
73873 err = -EPERM;
73874 if (!capable(CAP_NET_ADMIN))
73875 break;
73876 - if ((args.u.name_type >= 0) &&
73877 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
73878 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
73879 struct vlan_net *vn;
73880
73881 vn = net_generic(net, vlan_net_id);
73882 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
73883 index fccae26..e7ece2f 100644
73884 --- a/net/9p/trans_fd.c
73885 +++ b/net/9p/trans_fd.c
73886 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
73887 oldfs = get_fs();
73888 set_fs(get_ds());
73889 /* The cast to a user pointer is valid due to the set_fs() */
73890 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
73891 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
73892 set_fs(oldfs);
73893
73894 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
73895 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
73896 index 876fbe8..8bbea9f 100644
73897 --- a/net/atm/atm_misc.c
73898 +++ b/net/atm/atm_misc.c
73899 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
73900 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
73901 return 1;
73902 atm_return(vcc, truesize);
73903 - atomic_inc(&vcc->stats->rx_drop);
73904 + atomic_inc_unchecked(&vcc->stats->rx_drop);
73905 return 0;
73906 }
73907 EXPORT_SYMBOL(atm_charge);
73908 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
73909 }
73910 }
73911 atm_return(vcc, guess);
73912 - atomic_inc(&vcc->stats->rx_drop);
73913 + atomic_inc_unchecked(&vcc->stats->rx_drop);
73914 return NULL;
73915 }
73916 EXPORT_SYMBOL(atm_alloc_charge);
73917 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
73918
73919 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
73920 {
73921 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
73922 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
73923 __SONET_ITEMS
73924 #undef __HANDLE_ITEM
73925 }
73926 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
73927
73928 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
73929 {
73930 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
73931 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
73932 __SONET_ITEMS
73933 #undef __HANDLE_ITEM
73934 }
73935 diff --git a/net/atm/lec.h b/net/atm/lec.h
73936 index dfc0719..47c5322 100644
73937 --- a/net/atm/lec.h
73938 +++ b/net/atm/lec.h
73939 @@ -48,7 +48,7 @@ struct lane2_ops {
73940 const u8 *tlvs, u32 sizeoftlvs);
73941 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
73942 const u8 *tlvs, u32 sizeoftlvs);
73943 -};
73944 +} __no_const;
73945
73946 /*
73947 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
73948 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
73949 index 0919a88..a23d54e 100644
73950 --- a/net/atm/mpc.h
73951 +++ b/net/atm/mpc.h
73952 @@ -33,7 +33,7 @@ struct mpoa_client {
73953 struct mpc_parameters parameters; /* parameters for this client */
73954
73955 const struct net_device_ops *old_ops;
73956 - struct net_device_ops new_ops;
73957 + net_device_ops_no_const new_ops;
73958 };
73959
73960
73961 diff --git a/net/atm/proc.c b/net/atm/proc.c
73962 index 0d020de..011c7bb 100644
73963 --- a/net/atm/proc.c
73964 +++ b/net/atm/proc.c
73965 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
73966 const struct k_atm_aal_stats *stats)
73967 {
73968 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
73969 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
73970 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
73971 - atomic_read(&stats->rx_drop));
73972 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
73973 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
73974 + atomic_read_unchecked(&stats->rx_drop));
73975 }
73976
73977 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
73978 diff --git a/net/atm/resources.c b/net/atm/resources.c
73979 index 23f45ce..c748f1a 100644
73980 --- a/net/atm/resources.c
73981 +++ b/net/atm/resources.c
73982 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
73983 static void copy_aal_stats(struct k_atm_aal_stats *from,
73984 struct atm_aal_stats *to)
73985 {
73986 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
73987 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
73988 __AAL_STAT_ITEMS
73989 #undef __HANDLE_ITEM
73990 }
73991 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
73992 static void subtract_aal_stats(struct k_atm_aal_stats *from,
73993 struct atm_aal_stats *to)
73994 {
73995 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
73996 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
73997 __AAL_STAT_ITEMS
73998 #undef __HANDLE_ITEM
73999 }
74000 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
74001 index a6d5d63..1cc6c2b 100644
74002 --- a/net/batman-adv/bat_iv_ogm.c
74003 +++ b/net/batman-adv/bat_iv_ogm.c
74004 @@ -539,7 +539,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
74005
74006 /* change sequence number to network order */
74007 batman_ogm_packet->seqno =
74008 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
74009 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
74010
74011 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
74012 batman_ogm_packet->tt_crc = htons((uint16_t)
74013 @@ -559,7 +559,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
74014 else
74015 batman_ogm_packet->gw_flags = NO_FLAGS;
74016
74017 - atomic_inc(&hard_iface->seqno);
74018 + atomic_inc_unchecked(&hard_iface->seqno);
74019
74020 slide_own_bcast_window(hard_iface);
74021 bat_iv_ogm_queue_add(bat_priv, hard_iface->packet_buff,
74022 @@ -917,7 +917,7 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
74023 return;
74024
74025 /* could be changed by schedule_own_packet() */
74026 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
74027 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
74028
74029 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
74030
74031 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
74032 index 3778977..f6a9450 100644
74033 --- a/net/batman-adv/hard-interface.c
74034 +++ b/net/batman-adv/hard-interface.c
74035 @@ -328,8 +328,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
74036 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
74037 dev_add_pack(&hard_iface->batman_adv_ptype);
74038
74039 - atomic_set(&hard_iface->seqno, 1);
74040 - atomic_set(&hard_iface->frag_seqno, 1);
74041 + atomic_set_unchecked(&hard_iface->seqno, 1);
74042 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
74043 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
74044 hard_iface->net_dev->name);
74045
74046 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
74047 index a5590f4..8d31969 100644
74048 --- a/net/batman-adv/soft-interface.c
74049 +++ b/net/batman-adv/soft-interface.c
74050 @@ -645,7 +645,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
74051
74052 /* set broadcast sequence number */
74053 bcast_packet->seqno =
74054 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
74055 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
74056
74057 add_bcast_packet_to_list(bat_priv, skb, 1);
74058
74059 @@ -841,7 +841,7 @@ struct net_device *softif_create(const char *name)
74060 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
74061
74062 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
74063 - atomic_set(&bat_priv->bcast_seqno, 1);
74064 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
74065 atomic_set(&bat_priv->ttvn, 0);
74066 atomic_set(&bat_priv->tt_local_changes, 0);
74067 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
74068 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
74069 index 302efb5..1590365 100644
74070 --- a/net/batman-adv/types.h
74071 +++ b/net/batman-adv/types.h
74072 @@ -38,8 +38,8 @@ struct hard_iface {
74073 int16_t if_num;
74074 char if_status;
74075 struct net_device *net_dev;
74076 - atomic_t seqno;
74077 - atomic_t frag_seqno;
74078 + atomic_unchecked_t seqno;
74079 + atomic_unchecked_t frag_seqno;
74080 unsigned char *packet_buff;
74081 int packet_len;
74082 struct kobject *hardif_obj;
74083 @@ -155,7 +155,7 @@ struct bat_priv {
74084 atomic_t orig_interval; /* uint */
74085 atomic_t hop_penalty; /* uint */
74086 atomic_t log_level; /* uint */
74087 - atomic_t bcast_seqno;
74088 + atomic_unchecked_t bcast_seqno;
74089 atomic_t bcast_queue_left;
74090 atomic_t batman_queue_left;
74091 atomic_t ttvn; /* translation table version number */
74092 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
74093 index 676f6a6..3b4e668 100644
74094 --- a/net/batman-adv/unicast.c
74095 +++ b/net/batman-adv/unicast.c
74096 @@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
74097 frag1->flags = UNI_FRAG_HEAD | large_tail;
74098 frag2->flags = large_tail;
74099
74100 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
74101 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
74102 frag1->seqno = htons(seqno - 1);
74103 frag2->seqno = htons(seqno);
74104
74105 diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
74106 index 5238b6b..c9798ce 100644
74107 --- a/net/bluetooth/hci_conn.c
74108 +++ b/net/bluetooth/hci_conn.c
74109 @@ -233,7 +233,7 @@ void hci_le_ltk_reply(struct hci_conn *conn, u8 ltk[16])
74110 memset(&cp, 0, sizeof(cp));
74111
74112 cp.handle = cpu_to_le16(conn->handle);
74113 - memcpy(cp.ltk, ltk, sizeof(ltk));
74114 + memcpy(cp.ltk, ltk, sizeof(cp.ltk));
74115
74116 hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
74117 }
74118 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
74119 index 6f9c25b..d19fd66 100644
74120 --- a/net/bluetooth/l2cap_core.c
74121 +++ b/net/bluetooth/l2cap_core.c
74122 @@ -2466,8 +2466,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
74123 break;
74124
74125 case L2CAP_CONF_RFC:
74126 - if (olen == sizeof(rfc))
74127 - memcpy(&rfc, (void *)val, olen);
74128 + if (olen != sizeof(rfc))
74129 + break;
74130 +
74131 + memcpy(&rfc, (void *)val, olen);
74132
74133 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
74134 rfc.mode != chan->mode)
74135 @@ -2585,8 +2587,10 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
74136
74137 switch (type) {
74138 case L2CAP_CONF_RFC:
74139 - if (olen == sizeof(rfc))
74140 - memcpy(&rfc, (void *)val, olen);
74141 + if (olen != sizeof(rfc))
74142 + break;
74143 +
74144 + memcpy(&rfc, (void *)val, olen);
74145 goto done;
74146 }
74147 }
74148 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
74149 index 5fe2ff3..10968b5 100644
74150 --- a/net/bridge/netfilter/ebtables.c
74151 +++ b/net/bridge/netfilter/ebtables.c
74152 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
74153 tmp.valid_hooks = t->table->valid_hooks;
74154 }
74155 mutex_unlock(&ebt_mutex);
74156 - if (copy_to_user(user, &tmp, *len) != 0){
74157 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
74158 BUGPRINT("c2u Didn't work\n");
74159 ret = -EFAULT;
74160 break;
74161 diff --git a/net/caif/caif_dev.c b/net/caif/caif_dev.c
74162 index aa6f716..7bf4c21 100644
74163 --- a/net/caif/caif_dev.c
74164 +++ b/net/caif/caif_dev.c
74165 @@ -562,9 +562,9 @@ static int __init caif_device_init(void)
74166
74167 static void __exit caif_device_exit(void)
74168 {
74169 - unregister_pernet_subsys(&caif_net_ops);
74170 unregister_netdevice_notifier(&caif_device_notifier);
74171 dev_remove_pack(&caif_packet_type);
74172 + unregister_pernet_subsys(&caif_net_ops);
74173 }
74174
74175 module_init(caif_device_init);
74176 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
74177 index 5cf5222..6f704ad 100644
74178 --- a/net/caif/cfctrl.c
74179 +++ b/net/caif/cfctrl.c
74180 @@ -9,6 +9,7 @@
74181 #include <linux/stddef.h>
74182 #include <linux/spinlock.h>
74183 #include <linux/slab.h>
74184 +#include <linux/sched.h>
74185 #include <net/caif/caif_layer.h>
74186 #include <net/caif/cfpkt.h>
74187 #include <net/caif/cfctrl.h>
74188 @@ -42,8 +43,8 @@ struct cflayer *cfctrl_create(void)
74189 memset(&dev_info, 0, sizeof(dev_info));
74190 dev_info.id = 0xff;
74191 cfsrvl_init(&this->serv, 0, &dev_info, false);
74192 - atomic_set(&this->req_seq_no, 1);
74193 - atomic_set(&this->rsp_seq_no, 1);
74194 + atomic_set_unchecked(&this->req_seq_no, 1);
74195 + atomic_set_unchecked(&this->rsp_seq_no, 1);
74196 this->serv.layer.receive = cfctrl_recv;
74197 sprintf(this->serv.layer.name, "ctrl");
74198 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
74199 @@ -129,8 +130,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
74200 struct cfctrl_request_info *req)
74201 {
74202 spin_lock_bh(&ctrl->info_list_lock);
74203 - atomic_inc(&ctrl->req_seq_no);
74204 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
74205 + atomic_inc_unchecked(&ctrl->req_seq_no);
74206 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
74207 list_add_tail(&req->list, &ctrl->list);
74208 spin_unlock_bh(&ctrl->info_list_lock);
74209 }
74210 @@ -148,7 +149,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
74211 if (p != first)
74212 pr_warn("Requests are not received in order\n");
74213
74214 - atomic_set(&ctrl->rsp_seq_no,
74215 + atomic_set_unchecked(&ctrl->rsp_seq_no,
74216 p->sequence_no);
74217 list_del(&p->list);
74218 goto out;
74219 diff --git a/net/can/gw.c b/net/can/gw.c
74220 index 3d79b12..8de85fa 100644
74221 --- a/net/can/gw.c
74222 +++ b/net/can/gw.c
74223 @@ -96,7 +96,7 @@ struct cf_mod {
74224 struct {
74225 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
74226 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
74227 - } csumfunc;
74228 + } __no_const csumfunc;
74229 };
74230
74231
74232 diff --git a/net/compat.c b/net/compat.c
74233 index e055708..3f80795 100644
74234 --- a/net/compat.c
74235 +++ b/net/compat.c
74236 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
74237 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
74238 __get_user(kmsg->msg_flags, &umsg->msg_flags))
74239 return -EFAULT;
74240 - kmsg->msg_name = compat_ptr(tmp1);
74241 - kmsg->msg_iov = compat_ptr(tmp2);
74242 - kmsg->msg_control = compat_ptr(tmp3);
74243 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
74244 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
74245 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
74246 return 0;
74247 }
74248
74249 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74250
74251 if (kern_msg->msg_namelen) {
74252 if (mode == VERIFY_READ) {
74253 - int err = move_addr_to_kernel(kern_msg->msg_name,
74254 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
74255 kern_msg->msg_namelen,
74256 kern_address);
74257 if (err < 0)
74258 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74259 kern_msg->msg_name = NULL;
74260
74261 tot_len = iov_from_user_compat_to_kern(kern_iov,
74262 - (struct compat_iovec __user *)kern_msg->msg_iov,
74263 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
74264 kern_msg->msg_iovlen);
74265 if (tot_len >= 0)
74266 kern_msg->msg_iov = kern_iov;
74267 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74268
74269 #define CMSG_COMPAT_FIRSTHDR(msg) \
74270 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
74271 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
74272 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
74273 (struct compat_cmsghdr __user *)NULL)
74274
74275 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
74276 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
74277 (ucmlen) <= (unsigned long) \
74278 ((mhdr)->msg_controllen - \
74279 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
74280 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
74281
74282 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
74283 struct compat_cmsghdr __user *cmsg, int cmsg_len)
74284 {
74285 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
74286 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
74287 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
74288 msg->msg_controllen)
74289 return NULL;
74290 return (struct compat_cmsghdr __user *)ptr;
74291 @@ -219,7 +219,7 @@ Efault:
74292
74293 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
74294 {
74295 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
74296 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
74297 struct compat_cmsghdr cmhdr;
74298 int cmlen;
74299
74300 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
74301
74302 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
74303 {
74304 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
74305 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
74306 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
74307 int fdnum = scm->fp->count;
74308 struct file **fp = scm->fp->fp;
74309 @@ -372,7 +372,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
74310 return -EFAULT;
74311 old_fs = get_fs();
74312 set_fs(KERNEL_DS);
74313 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
74314 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
74315 set_fs(old_fs);
74316
74317 return err;
74318 @@ -433,7 +433,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
74319 len = sizeof(ktime);
74320 old_fs = get_fs();
74321 set_fs(KERNEL_DS);
74322 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
74323 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
74324 set_fs(old_fs);
74325
74326 if (!err) {
74327 @@ -576,7 +576,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
74328 case MCAST_JOIN_GROUP:
74329 case MCAST_LEAVE_GROUP:
74330 {
74331 - struct compat_group_req __user *gr32 = (void *)optval;
74332 + struct compat_group_req __user *gr32 = (void __user *)optval;
74333 struct group_req __user *kgr =
74334 compat_alloc_user_space(sizeof(struct group_req));
74335 u32 interface;
74336 @@ -597,7 +597,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
74337 case MCAST_BLOCK_SOURCE:
74338 case MCAST_UNBLOCK_SOURCE:
74339 {
74340 - struct compat_group_source_req __user *gsr32 = (void *)optval;
74341 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
74342 struct group_source_req __user *kgsr = compat_alloc_user_space(
74343 sizeof(struct group_source_req));
74344 u32 interface;
74345 @@ -618,7 +618,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
74346 }
74347 case MCAST_MSFILTER:
74348 {
74349 - struct compat_group_filter __user *gf32 = (void *)optval;
74350 + struct compat_group_filter __user *gf32 = (void __user *)optval;
74351 struct group_filter __user *kgf;
74352 u32 interface, fmode, numsrc;
74353
74354 @@ -656,7 +656,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
74355 char __user *optval, int __user *optlen,
74356 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
74357 {
74358 - struct compat_group_filter __user *gf32 = (void *)optval;
74359 + struct compat_group_filter __user *gf32 = (void __user *)optval;
74360 struct group_filter __user *kgf;
74361 int __user *koptlen;
74362 u32 interface, fmode, numsrc;
74363 diff --git a/net/core/datagram.c b/net/core/datagram.c
74364 index e4fbfd6..6a6ac94 100644
74365 --- a/net/core/datagram.c
74366 +++ b/net/core/datagram.c
74367 @@ -290,7 +290,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
74368 }
74369
74370 kfree_skb(skb);
74371 - atomic_inc(&sk->sk_drops);
74372 + atomic_inc_unchecked(&sk->sk_drops);
74373 sk_mem_reclaim_partial(sk);
74374
74375 return err;
74376 diff --git a/net/core/dev.c b/net/core/dev.c
74377 index 533c586..f78a55f 100644
74378 --- a/net/core/dev.c
74379 +++ b/net/core/dev.c
74380 @@ -1136,9 +1136,13 @@ void dev_load(struct net *net, const char *name)
74381 if (no_module && capable(CAP_NET_ADMIN))
74382 no_module = request_module("netdev-%s", name);
74383 if (no_module && capable(CAP_SYS_MODULE)) {
74384 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
74385 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
74386 +#else
74387 if (!request_module("%s", name))
74388 pr_err("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
74389 name);
74390 +#endif
74391 }
74392 }
74393 EXPORT_SYMBOL(dev_load);
74394 @@ -1602,7 +1606,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
74395 {
74396 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
74397 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
74398 - atomic_long_inc(&dev->rx_dropped);
74399 + atomic_long_inc_unchecked(&dev->rx_dropped);
74400 kfree_skb(skb);
74401 return NET_RX_DROP;
74402 }
74403 @@ -1612,7 +1616,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
74404 nf_reset(skb);
74405
74406 if (unlikely(!is_skb_forwardable(dev, skb))) {
74407 - atomic_long_inc(&dev->rx_dropped);
74408 + atomic_long_inc_unchecked(&dev->rx_dropped);
74409 kfree_skb(skb);
74410 return NET_RX_DROP;
74411 }
74412 @@ -2042,7 +2046,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
74413
74414 struct dev_gso_cb {
74415 void (*destructor)(struct sk_buff *skb);
74416 -};
74417 +} __no_const;
74418
74419 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
74420
74421 @@ -2877,7 +2881,7 @@ enqueue:
74422
74423 local_irq_restore(flags);
74424
74425 - atomic_long_inc(&skb->dev->rx_dropped);
74426 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
74427 kfree_skb(skb);
74428 return NET_RX_DROP;
74429 }
74430 @@ -2949,7 +2953,7 @@ int netif_rx_ni(struct sk_buff *skb)
74431 }
74432 EXPORT_SYMBOL(netif_rx_ni);
74433
74434 -static void net_tx_action(struct softirq_action *h)
74435 +static void net_tx_action(void)
74436 {
74437 struct softnet_data *sd = &__get_cpu_var(softnet_data);
74438
74439 @@ -3237,7 +3241,7 @@ ncls:
74440 if (pt_prev) {
74441 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
74442 } else {
74443 - atomic_long_inc(&skb->dev->rx_dropped);
74444 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
74445 kfree_skb(skb);
74446 /* Jamal, now you will not able to escape explaining
74447 * me how you were going to use this. :-)
74448 @@ -3797,7 +3801,7 @@ void netif_napi_del(struct napi_struct *napi)
74449 }
74450 EXPORT_SYMBOL(netif_napi_del);
74451
74452 -static void net_rx_action(struct softirq_action *h)
74453 +static void net_rx_action(void)
74454 {
74455 struct softnet_data *sd = &__get_cpu_var(softnet_data);
74456 unsigned long time_limit = jiffies + 2;
74457 @@ -4267,8 +4271,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
74458 else
74459 seq_printf(seq, "%04x", ntohs(pt->type));
74460
74461 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74462 + seq_printf(seq, " %-8s %p\n",
74463 + pt->dev ? pt->dev->name : "", NULL);
74464 +#else
74465 seq_printf(seq, " %-8s %pF\n",
74466 pt->dev ? pt->dev->name : "", pt->func);
74467 +#endif
74468 }
74469
74470 return 0;
74471 @@ -5818,7 +5827,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
74472 } else {
74473 netdev_stats_to_stats64(storage, &dev->stats);
74474 }
74475 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
74476 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
74477 return storage;
74478 }
74479 EXPORT_SYMBOL(dev_get_stats);
74480 diff --git a/net/core/flow.c b/net/core/flow.c
74481 index e318c7e..168b1d0 100644
74482 --- a/net/core/flow.c
74483 +++ b/net/core/flow.c
74484 @@ -61,7 +61,7 @@ struct flow_cache {
74485 struct timer_list rnd_timer;
74486 };
74487
74488 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
74489 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
74490 EXPORT_SYMBOL(flow_cache_genid);
74491 static struct flow_cache flow_cache_global;
74492 static struct kmem_cache *flow_cachep __read_mostly;
74493 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
74494
74495 static int flow_entry_valid(struct flow_cache_entry *fle)
74496 {
74497 - if (atomic_read(&flow_cache_genid) != fle->genid)
74498 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
74499 return 0;
74500 if (fle->object && !fle->object->ops->check(fle->object))
74501 return 0;
74502 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
74503 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
74504 fcp->hash_count++;
74505 }
74506 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
74507 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
74508 flo = fle->object;
74509 if (!flo)
74510 goto ret_object;
74511 @@ -280,7 +280,7 @@ nocache:
74512 }
74513 flo = resolver(net, key, family, dir, flo, ctx);
74514 if (fle) {
74515 - fle->genid = atomic_read(&flow_cache_genid);
74516 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
74517 if (!IS_ERR(flo))
74518 fle->object = flo;
74519 else
74520 diff --git a/net/core/iovec.c b/net/core/iovec.c
74521 index 7e7aeb0..2a998cb 100644
74522 --- a/net/core/iovec.c
74523 +++ b/net/core/iovec.c
74524 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
74525 if (m->msg_namelen) {
74526 if (mode == VERIFY_READ) {
74527 void __user *namep;
74528 - namep = (void __user __force *) m->msg_name;
74529 + namep = (void __force_user *) m->msg_name;
74530 err = move_addr_to_kernel(namep, m->msg_namelen,
74531 address);
74532 if (err < 0)
74533 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
74534 }
74535
74536 size = m->msg_iovlen * sizeof(struct iovec);
74537 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
74538 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
74539 return -EFAULT;
74540
74541 m->msg_iov = iov;
74542 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
74543 index 90430b7..0032ec0 100644
74544 --- a/net/core/rtnetlink.c
74545 +++ b/net/core/rtnetlink.c
74546 @@ -56,7 +56,7 @@ struct rtnl_link {
74547 rtnl_doit_func doit;
74548 rtnl_dumpit_func dumpit;
74549 rtnl_calcit_func calcit;
74550 -};
74551 +} __no_const;
74552
74553 static DEFINE_MUTEX(rtnl_mutex);
74554
74555 diff --git a/net/core/scm.c b/net/core/scm.c
74556 index 611c5ef..88f6d6d 100644
74557 --- a/net/core/scm.c
74558 +++ b/net/core/scm.c
74559 @@ -219,7 +219,7 @@ EXPORT_SYMBOL(__scm_send);
74560 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
74561 {
74562 struct cmsghdr __user *cm
74563 - = (__force struct cmsghdr __user *)msg->msg_control;
74564 + = (struct cmsghdr __force_user *)msg->msg_control;
74565 struct cmsghdr cmhdr;
74566 int cmlen = CMSG_LEN(len);
74567 int err;
74568 @@ -242,7 +242,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
74569 err = -EFAULT;
74570 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
74571 goto out;
74572 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
74573 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
74574 goto out;
74575 cmlen = CMSG_SPACE(len);
74576 if (msg->msg_controllen < cmlen)
74577 @@ -258,7 +258,7 @@ EXPORT_SYMBOL(put_cmsg);
74578 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
74579 {
74580 struct cmsghdr __user *cm
74581 - = (__force struct cmsghdr __user*)msg->msg_control;
74582 + = (struct cmsghdr __force_user *)msg->msg_control;
74583
74584 int fdmax = 0;
74585 int fdnum = scm->fp->count;
74586 @@ -278,7 +278,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
74587 if (fdnum < fdmax)
74588 fdmax = fdnum;
74589
74590 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
74591 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
74592 i++, cmfptr++)
74593 {
74594 int new_fd;
74595 diff --git a/net/core/sock.c b/net/core/sock.c
74596 index 0f8402e..f0b6338 100644
74597 --- a/net/core/sock.c
74598 +++ b/net/core/sock.c
74599 @@ -340,7 +340,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74600 struct sk_buff_head *list = &sk->sk_receive_queue;
74601
74602 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
74603 - atomic_inc(&sk->sk_drops);
74604 + atomic_inc_unchecked(&sk->sk_drops);
74605 trace_sock_rcvqueue_full(sk, skb);
74606 return -ENOMEM;
74607 }
74608 @@ -350,7 +350,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74609 return err;
74610
74611 if (!sk_rmem_schedule(sk, skb->truesize)) {
74612 - atomic_inc(&sk->sk_drops);
74613 + atomic_inc_unchecked(&sk->sk_drops);
74614 return -ENOBUFS;
74615 }
74616
74617 @@ -370,7 +370,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74618 skb_dst_force(skb);
74619
74620 spin_lock_irqsave(&list->lock, flags);
74621 - skb->dropcount = atomic_read(&sk->sk_drops);
74622 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
74623 __skb_queue_tail(list, skb);
74624 spin_unlock_irqrestore(&list->lock, flags);
74625
74626 @@ -390,7 +390,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
74627 skb->dev = NULL;
74628
74629 if (sk_rcvqueues_full(sk, skb)) {
74630 - atomic_inc(&sk->sk_drops);
74631 + atomic_inc_unchecked(&sk->sk_drops);
74632 goto discard_and_relse;
74633 }
74634 if (nested)
74635 @@ -408,7 +408,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
74636 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
74637 } else if (sk_add_backlog(sk, skb)) {
74638 bh_unlock_sock(sk);
74639 - atomic_inc(&sk->sk_drops);
74640 + atomic_inc_unchecked(&sk->sk_drops);
74641 goto discard_and_relse;
74642 }
74643
74644 @@ -984,7 +984,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
74645 if (len > sizeof(peercred))
74646 len = sizeof(peercred);
74647 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
74648 - if (copy_to_user(optval, &peercred, len))
74649 + if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
74650 return -EFAULT;
74651 goto lenout;
74652 }
74653 @@ -997,7 +997,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
74654 return -ENOTCONN;
74655 if (lv < len)
74656 return -EINVAL;
74657 - if (copy_to_user(optval, address, len))
74658 + if (len > sizeof(address) || copy_to_user(optval, address, len))
74659 return -EFAULT;
74660 goto lenout;
74661 }
74662 @@ -1043,7 +1043,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
74663
74664 if (len > lv)
74665 len = lv;
74666 - if (copy_to_user(optval, &v, len))
74667 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
74668 return -EFAULT;
74669 lenout:
74670 if (put_user(len, optlen))
74671 @@ -2131,7 +2131,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
74672 */
74673 smp_wmb();
74674 atomic_set(&sk->sk_refcnt, 1);
74675 - atomic_set(&sk->sk_drops, 0);
74676 + atomic_set_unchecked(&sk->sk_drops, 0);
74677 }
74678 EXPORT_SYMBOL(sock_init_data);
74679
74680 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
74681 index b9868e1..849f809 100644
74682 --- a/net/core/sock_diag.c
74683 +++ b/net/core/sock_diag.c
74684 @@ -16,20 +16,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
74685
74686 int sock_diag_check_cookie(void *sk, __u32 *cookie)
74687 {
74688 +#ifndef CONFIG_GRKERNSEC_HIDESYM
74689 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
74690 cookie[1] != INET_DIAG_NOCOOKIE) &&
74691 ((u32)(unsigned long)sk != cookie[0] ||
74692 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
74693 return -ESTALE;
74694 else
74695 +#endif
74696 return 0;
74697 }
74698 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
74699
74700 void sock_diag_save_cookie(void *sk, __u32 *cookie)
74701 {
74702 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74703 + cookie[0] = 0;
74704 + cookie[1] = 0;
74705 +#else
74706 cookie[0] = (u32)(unsigned long)sk;
74707 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
74708 +#endif
74709 }
74710 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
74711
74712 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
74713 index 02e75d1..9a57a7c 100644
74714 --- a/net/decnet/sysctl_net_decnet.c
74715 +++ b/net/decnet/sysctl_net_decnet.c
74716 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
74717
74718 if (len > *lenp) len = *lenp;
74719
74720 - if (copy_to_user(buffer, addr, len))
74721 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
74722 return -EFAULT;
74723
74724 *lenp = len;
74725 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
74726
74727 if (len > *lenp) len = *lenp;
74728
74729 - if (copy_to_user(buffer, devname, len))
74730 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
74731 return -EFAULT;
74732
74733 *lenp = len;
74734 diff --git a/net/econet/Kconfig b/net/econet/Kconfig
74735 index 39a2d29..f39c0fe 100644
74736 --- a/net/econet/Kconfig
74737 +++ b/net/econet/Kconfig
74738 @@ -4,7 +4,7 @@
74739
74740 config ECONET
74741 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
74742 - depends on EXPERIMENTAL && INET
74743 + depends on EXPERIMENTAL && INET && BROKEN
74744 ---help---
74745 Econet is a fairly old and slow networking protocol mainly used by
74746 Acorn computers to access file and print servers. It uses native
74747 diff --git a/net/ipv4/cipso_ipv4.c b/net/ipv4/cipso_ipv4.c
74748 index c48adc5..667c1d4 100644
74749 --- a/net/ipv4/cipso_ipv4.c
74750 +++ b/net/ipv4/cipso_ipv4.c
74751 @@ -1725,8 +1725,10 @@ int cipso_v4_validate(const struct sk_buff *skb, unsigned char **option)
74752 case CIPSO_V4_TAG_LOCAL:
74753 /* This is a non-standard tag that we only allow for
74754 * local connections, so if the incoming interface is
74755 - * not the loopback device drop the packet. */
74756 - if (!(skb->dev->flags & IFF_LOOPBACK)) {
74757 + * not the loopback device drop the packet. Further,
74758 + * there is no legitimate reason for setting this from
74759 + * userspace so reject it if skb is NULL. */
74760 + if (skb == NULL || !(skb->dev->flags & IFF_LOOPBACK)) {
74761 err_offset = opt_iter;
74762 goto validate_return_locked;
74763 }
74764 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
74765 index cbe3a68..a879b75 100644
74766 --- a/net/ipv4/fib_frontend.c
74767 +++ b/net/ipv4/fib_frontend.c
74768 @@ -969,12 +969,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
74769 #ifdef CONFIG_IP_ROUTE_MULTIPATH
74770 fib_sync_up(dev);
74771 #endif
74772 - atomic_inc(&net->ipv4.dev_addr_genid);
74773 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
74774 rt_cache_flush(dev_net(dev), -1);
74775 break;
74776 case NETDEV_DOWN:
74777 fib_del_ifaddr(ifa, NULL);
74778 - atomic_inc(&net->ipv4.dev_addr_genid);
74779 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
74780 if (ifa->ifa_dev->ifa_list == NULL) {
74781 /* Last address was deleted from this interface.
74782 * Disable IP.
74783 @@ -1010,7 +1010,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
74784 #ifdef CONFIG_IP_ROUTE_MULTIPATH
74785 fib_sync_up(dev);
74786 #endif
74787 - atomic_inc(&net->ipv4.dev_addr_genid);
74788 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
74789 rt_cache_flush(dev_net(dev), -1);
74790 break;
74791 case NETDEV_DOWN:
74792 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
74793 index 8861f91..ab1e3c1 100644
74794 --- a/net/ipv4/fib_semantics.c
74795 +++ b/net/ipv4/fib_semantics.c
74796 @@ -698,7 +698,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
74797 nh->nh_saddr = inet_select_addr(nh->nh_dev,
74798 nh->nh_gw,
74799 nh->nh_parent->fib_scope);
74800 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
74801 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
74802
74803 return nh->nh_saddr;
74804 }
74805 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
74806 index 984ec65..97ac518 100644
74807 --- a/net/ipv4/inet_hashtables.c
74808 +++ b/net/ipv4/inet_hashtables.c
74809 @@ -18,12 +18,15 @@
74810 #include <linux/sched.h>
74811 #include <linux/slab.h>
74812 #include <linux/wait.h>
74813 +#include <linux/security.h>
74814
74815 #include <net/inet_connection_sock.h>
74816 #include <net/inet_hashtables.h>
74817 #include <net/secure_seq.h>
74818 #include <net/ip.h>
74819
74820 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
74821 +
74822 /*
74823 * Allocate and initialize a new local port bind bucket.
74824 * The bindhash mutex for snum's hash chain must be held here.
74825 @@ -530,6 +533,8 @@ ok:
74826 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
74827 spin_unlock(&head->lock);
74828
74829 + gr_update_task_in_ip_table(current, inet_sk(sk));
74830 +
74831 if (tw) {
74832 inet_twsk_deschedule(tw, death_row);
74833 while (twrefcnt) {
74834 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
74835 index dfba343..c827d50 100644
74836 --- a/net/ipv4/inetpeer.c
74837 +++ b/net/ipv4/inetpeer.c
74838 @@ -487,8 +487,8 @@ relookup:
74839 if (p) {
74840 p->daddr = *daddr;
74841 atomic_set(&p->refcnt, 1);
74842 - atomic_set(&p->rid, 0);
74843 - atomic_set(&p->ip_id_count,
74844 + atomic_set_unchecked(&p->rid, 0);
74845 + atomic_set_unchecked(&p->ip_id_count,
74846 (daddr->family == AF_INET) ?
74847 secure_ip_id(daddr->addr.a4) :
74848 secure_ipv6_id(daddr->addr.a6));
74849 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
74850 index 3727e23..517f5df 100644
74851 --- a/net/ipv4/ip_fragment.c
74852 +++ b/net/ipv4/ip_fragment.c
74853 @@ -318,7 +318,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
74854 return 0;
74855
74856 start = qp->rid;
74857 - end = atomic_inc_return(&peer->rid);
74858 + end = atomic_inc_return_unchecked(&peer->rid);
74859 qp->rid = end;
74860
74861 rc = qp->q.fragments && (end - start) > max;
74862 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
74863 index 2fd0fba..83fac99 100644
74864 --- a/net/ipv4/ip_sockglue.c
74865 +++ b/net/ipv4/ip_sockglue.c
74866 @@ -1137,7 +1137,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
74867 len = min_t(unsigned int, len, opt->optlen);
74868 if (put_user(len, optlen))
74869 return -EFAULT;
74870 - if (copy_to_user(optval, opt->__data, len))
74871 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
74872 + copy_to_user(optval, opt->__data, len))
74873 return -EFAULT;
74874 return 0;
74875 }
74876 @@ -1268,7 +1269,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
74877 if (sk->sk_type != SOCK_STREAM)
74878 return -ENOPROTOOPT;
74879
74880 - msg.msg_control = optval;
74881 + msg.msg_control = (void __force_kernel *)optval;
74882 msg.msg_controllen = len;
74883 msg.msg_flags = flags;
74884
74885 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
74886 index 92ac7e7..13f93d9 100644
74887 --- a/net/ipv4/ipconfig.c
74888 +++ b/net/ipv4/ipconfig.c
74889 @@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
74890
74891 mm_segment_t oldfs = get_fs();
74892 set_fs(get_ds());
74893 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
74894 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
74895 set_fs(oldfs);
74896 return res;
74897 }
74898 @@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
74899
74900 mm_segment_t oldfs = get_fs();
74901 set_fs(get_ds());
74902 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
74903 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
74904 set_fs(oldfs);
74905 return res;
74906 }
74907 @@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
74908
74909 mm_segment_t oldfs = get_fs();
74910 set_fs(get_ds());
74911 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
74912 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
74913 set_fs(oldfs);
74914 return res;
74915 }
74916 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
74917 index 50009c7..5996a9f 100644
74918 --- a/net/ipv4/ping.c
74919 +++ b/net/ipv4/ping.c
74920 @@ -838,7 +838,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
74921 sk_rmem_alloc_get(sp),
74922 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
74923 atomic_read(&sp->sk_refcnt), sp,
74924 - atomic_read(&sp->sk_drops), len);
74925 + atomic_read_unchecked(&sp->sk_drops), len);
74926 }
74927
74928 static int ping_seq_show(struct seq_file *seq, void *v)
74929 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
74930 index bbd604c..4d5469c 100644
74931 --- a/net/ipv4/raw.c
74932 +++ b/net/ipv4/raw.c
74933 @@ -304,7 +304,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
74934 int raw_rcv(struct sock *sk, struct sk_buff *skb)
74935 {
74936 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
74937 - atomic_inc(&sk->sk_drops);
74938 + atomic_inc_unchecked(&sk->sk_drops);
74939 kfree_skb(skb);
74940 return NET_RX_DROP;
74941 }
74942 @@ -740,16 +740,20 @@ static int raw_init(struct sock *sk)
74943
74944 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
74945 {
74946 + struct icmp_filter filter;
74947 +
74948 if (optlen > sizeof(struct icmp_filter))
74949 optlen = sizeof(struct icmp_filter);
74950 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
74951 + if (copy_from_user(&filter, optval, optlen))
74952 return -EFAULT;
74953 + raw_sk(sk)->filter = filter;
74954 return 0;
74955 }
74956
74957 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
74958 {
74959 int len, ret = -EFAULT;
74960 + struct icmp_filter filter;
74961
74962 if (get_user(len, optlen))
74963 goto out;
74964 @@ -759,8 +763,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
74965 if (len > sizeof(struct icmp_filter))
74966 len = sizeof(struct icmp_filter);
74967 ret = -EFAULT;
74968 - if (put_user(len, optlen) ||
74969 - copy_to_user(optval, &raw_sk(sk)->filter, len))
74970 + filter = raw_sk(sk)->filter;
74971 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
74972 goto out;
74973 ret = 0;
74974 out: return ret;
74975 @@ -988,7 +992,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
74976 sk_wmem_alloc_get(sp),
74977 sk_rmem_alloc_get(sp),
74978 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
74979 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
74980 + atomic_read(&sp->sk_refcnt),
74981 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74982 + NULL,
74983 +#else
74984 + sp,
74985 +#endif
74986 + atomic_read_unchecked(&sp->sk_drops));
74987 }
74988
74989 static int raw_seq_show(struct seq_file *seq, void *v)
74990 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
74991 index 167ea10..4b15883 100644
74992 --- a/net/ipv4/route.c
74993 +++ b/net/ipv4/route.c
74994 @@ -312,7 +312,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
74995
74996 static inline int rt_genid(struct net *net)
74997 {
74998 - return atomic_read(&net->ipv4.rt_genid);
74999 + return atomic_read_unchecked(&net->ipv4.rt_genid);
75000 }
75001
75002 #ifdef CONFIG_PROC_FS
75003 @@ -936,7 +936,7 @@ static void rt_cache_invalidate(struct net *net)
75004 unsigned char shuffle;
75005
75006 get_random_bytes(&shuffle, sizeof(shuffle));
75007 - atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
75008 + atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
75009 inetpeer_invalidate_tree(AF_INET);
75010 }
75011
75012 @@ -3009,7 +3009,7 @@ static int rt_fill_info(struct net *net,
75013 error = rt->dst.error;
75014 if (peer) {
75015 inet_peer_refcheck(rt->peer);
75016 - id = atomic_read(&peer->ip_id_count) & 0xffff;
75017 + id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
75018 if (peer->tcp_ts_stamp) {
75019 ts = peer->tcp_ts;
75020 tsage = get_seconds() - peer->tcp_ts_stamp;
75021 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
75022 index 0cb86ce..8e7fda8 100644
75023 --- a/net/ipv4/tcp_ipv4.c
75024 +++ b/net/ipv4/tcp_ipv4.c
75025 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
75026 EXPORT_SYMBOL(sysctl_tcp_low_latency);
75027
75028
75029 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75030 +extern int grsec_enable_blackhole;
75031 +#endif
75032 +
75033 #ifdef CONFIG_TCP_MD5SIG
75034 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
75035 __be32 daddr, __be32 saddr, const struct tcphdr *th);
75036 @@ -1641,6 +1645,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
75037 return 0;
75038
75039 reset:
75040 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75041 + if (!grsec_enable_blackhole)
75042 +#endif
75043 tcp_v4_send_reset(rsk, skb);
75044 discard:
75045 kfree_skb(skb);
75046 @@ -1703,12 +1710,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
75047 TCP_SKB_CB(skb)->sacked = 0;
75048
75049 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
75050 - if (!sk)
75051 + if (!sk) {
75052 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75053 + ret = 1;
75054 +#endif
75055 goto no_tcp_socket;
75056 -
75057 + }
75058 process:
75059 - if (sk->sk_state == TCP_TIME_WAIT)
75060 + if (sk->sk_state == TCP_TIME_WAIT) {
75061 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75062 + ret = 2;
75063 +#endif
75064 goto do_time_wait;
75065 + }
75066
75067 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
75068 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
75069 @@ -1758,6 +1772,10 @@ no_tcp_socket:
75070 bad_packet:
75071 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
75072 } else {
75073 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75074 + if (!grsec_enable_blackhole || (ret == 1 &&
75075 + (skb->dev->flags & IFF_LOOPBACK)))
75076 +#endif
75077 tcp_v4_send_reset(NULL, skb);
75078 }
75079
75080 @@ -2419,7 +2437,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
75081 0, /* non standard timer */
75082 0, /* open_requests have no inode */
75083 atomic_read(&sk->sk_refcnt),
75084 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75085 + NULL,
75086 +#else
75087 req,
75088 +#endif
75089 len);
75090 }
75091
75092 @@ -2469,7 +2491,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
75093 sock_i_uid(sk),
75094 icsk->icsk_probes_out,
75095 sock_i_ino(sk),
75096 - atomic_read(&sk->sk_refcnt), sk,
75097 + atomic_read(&sk->sk_refcnt),
75098 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75099 + NULL,
75100 +#else
75101 + sk,
75102 +#endif
75103 jiffies_to_clock_t(icsk->icsk_rto),
75104 jiffies_to_clock_t(icsk->icsk_ack.ato),
75105 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
75106 @@ -2497,7 +2524,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
75107 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
75108 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
75109 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
75110 - atomic_read(&tw->tw_refcnt), tw, len);
75111 + atomic_read(&tw->tw_refcnt),
75112 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75113 + NULL,
75114 +#else
75115 + tw,
75116 +#endif
75117 + len);
75118 }
75119
75120 #define TMPSZ 150
75121 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
75122 index 3cabafb..640525b 100644
75123 --- a/net/ipv4/tcp_minisocks.c
75124 +++ b/net/ipv4/tcp_minisocks.c
75125 @@ -27,6 +27,10 @@
75126 #include <net/inet_common.h>
75127 #include <net/xfrm.h>
75128
75129 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75130 +extern int grsec_enable_blackhole;
75131 +#endif
75132 +
75133 int sysctl_tcp_syncookies __read_mostly = 1;
75134 EXPORT_SYMBOL(sysctl_tcp_syncookies);
75135
75136 @@ -753,6 +757,10 @@ listen_overflow:
75137
75138 embryonic_reset:
75139 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
75140 +
75141 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75142 + if (!grsec_enable_blackhole)
75143 +#endif
75144 if (!(flg & TCP_FLAG_RST))
75145 req->rsk_ops->send_reset(sk, skb);
75146
75147 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
75148 index a981cdc..48f4c3a 100644
75149 --- a/net/ipv4/tcp_probe.c
75150 +++ b/net/ipv4/tcp_probe.c
75151 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
75152 if (cnt + width >= len)
75153 break;
75154
75155 - if (copy_to_user(buf + cnt, tbuf, width))
75156 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
75157 return -EFAULT;
75158 cnt += width;
75159 }
75160 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
75161 index 34d4a02..3b57f86 100644
75162 --- a/net/ipv4/tcp_timer.c
75163 +++ b/net/ipv4/tcp_timer.c
75164 @@ -22,6 +22,10 @@
75165 #include <linux/gfp.h>
75166 #include <net/tcp.h>
75167
75168 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75169 +extern int grsec_lastack_retries;
75170 +#endif
75171 +
75172 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
75173 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
75174 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
75175 @@ -196,6 +200,13 @@ static int tcp_write_timeout(struct sock *sk)
75176 }
75177 }
75178
75179 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75180 + if ((sk->sk_state == TCP_LAST_ACK) &&
75181 + (grsec_lastack_retries > 0) &&
75182 + (grsec_lastack_retries < retry_until))
75183 + retry_until = grsec_lastack_retries;
75184 +#endif
75185 +
75186 if (retransmits_timed_out(sk, retry_until,
75187 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
75188 /* Has it gone just too far? */
75189 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
75190 index fe14105..0618260 100644
75191 --- a/net/ipv4/udp.c
75192 +++ b/net/ipv4/udp.c
75193 @@ -87,6 +87,7 @@
75194 #include <linux/types.h>
75195 #include <linux/fcntl.h>
75196 #include <linux/module.h>
75197 +#include <linux/security.h>
75198 #include <linux/socket.h>
75199 #include <linux/sockios.h>
75200 #include <linux/igmp.h>
75201 @@ -109,6 +110,10 @@
75202 #include <trace/events/udp.h>
75203 #include "udp_impl.h"
75204
75205 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75206 +extern int grsec_enable_blackhole;
75207 +#endif
75208 +
75209 struct udp_table udp_table __read_mostly;
75210 EXPORT_SYMBOL(udp_table);
75211
75212 @@ -567,6 +572,9 @@ found:
75213 return s;
75214 }
75215
75216 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
75217 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
75218 +
75219 /*
75220 * This routine is called by the ICMP module when it gets some
75221 * sort of error condition. If err < 0 then the socket should
75222 @@ -858,9 +866,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
75223 dport = usin->sin_port;
75224 if (dport == 0)
75225 return -EINVAL;
75226 +
75227 + err = gr_search_udp_sendmsg(sk, usin);
75228 + if (err)
75229 + return err;
75230 } else {
75231 if (sk->sk_state != TCP_ESTABLISHED)
75232 return -EDESTADDRREQ;
75233 +
75234 + err = gr_search_udp_sendmsg(sk, NULL);
75235 + if (err)
75236 + return err;
75237 +
75238 daddr = inet->inet_daddr;
75239 dport = inet->inet_dport;
75240 /* Open fast path for connected socket.
75241 @@ -1102,7 +1119,7 @@ static unsigned int first_packet_length(struct sock *sk)
75242 udp_lib_checksum_complete(skb)) {
75243 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
75244 IS_UDPLITE(sk));
75245 - atomic_inc(&sk->sk_drops);
75246 + atomic_inc_unchecked(&sk->sk_drops);
75247 __skb_unlink(skb, rcvq);
75248 __skb_queue_tail(&list_kill, skb);
75249 }
75250 @@ -1188,6 +1205,10 @@ try_again:
75251 if (!skb)
75252 goto out;
75253
75254 + err = gr_search_udp_recvmsg(sk, skb);
75255 + if (err)
75256 + goto out_free;
75257 +
75258 ulen = skb->len - sizeof(struct udphdr);
75259 copied = len;
75260 if (copied > ulen)
75261 @@ -1489,7 +1510,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75262
75263 drop:
75264 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
75265 - atomic_inc(&sk->sk_drops);
75266 + atomic_inc_unchecked(&sk->sk_drops);
75267 kfree_skb(skb);
75268 return -1;
75269 }
75270 @@ -1508,7 +1529,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
75271 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
75272
75273 if (!skb1) {
75274 - atomic_inc(&sk->sk_drops);
75275 + atomic_inc_unchecked(&sk->sk_drops);
75276 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
75277 IS_UDPLITE(sk));
75278 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
75279 @@ -1677,6 +1698,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
75280 goto csum_error;
75281
75282 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
75283 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75284 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
75285 +#endif
75286 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
75287
75288 /*
75289 @@ -2094,8 +2118,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
75290 sk_wmem_alloc_get(sp),
75291 sk_rmem_alloc_get(sp),
75292 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75293 - atomic_read(&sp->sk_refcnt), sp,
75294 - atomic_read(&sp->sk_drops), len);
75295 + atomic_read(&sp->sk_refcnt),
75296 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75297 + NULL,
75298 +#else
75299 + sp,
75300 +#endif
75301 + atomic_read_unchecked(&sp->sk_drops), len);
75302 }
75303
75304 int udp4_seq_show(struct seq_file *seq, void *v)
75305 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
75306 index 7d5cb97..c56564f 100644
75307 --- a/net/ipv6/addrconf.c
75308 +++ b/net/ipv6/addrconf.c
75309 @@ -2142,7 +2142,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
75310 p.iph.ihl = 5;
75311 p.iph.protocol = IPPROTO_IPV6;
75312 p.iph.ttl = 64;
75313 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
75314 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
75315
75316 if (ops->ndo_do_ioctl) {
75317 mm_segment_t oldfs = get_fs();
75318 diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
75319 index 02dd203..e03fcc9 100644
75320 --- a/net/ipv6/inet6_connection_sock.c
75321 +++ b/net/ipv6/inet6_connection_sock.c
75322 @@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
75323 #ifdef CONFIG_XFRM
75324 {
75325 struct rt6_info *rt = (struct rt6_info *)dst;
75326 - rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
75327 + rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
75328 }
75329 #endif
75330 }
75331 @@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
75332 #ifdef CONFIG_XFRM
75333 if (dst) {
75334 struct rt6_info *rt = (struct rt6_info *)dst;
75335 - if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
75336 + if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
75337 __sk_dst_reset(sk);
75338 dst = NULL;
75339 }
75340 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
75341 index 63dd1f8..e7f53ca 100644
75342 --- a/net/ipv6/ipv6_sockglue.c
75343 +++ b/net/ipv6/ipv6_sockglue.c
75344 @@ -990,7 +990,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
75345 if (sk->sk_type != SOCK_STREAM)
75346 return -ENOPROTOOPT;
75347
75348 - msg.msg_control = optval;
75349 + msg.msg_control = (void __force_kernel *)optval;
75350 msg.msg_controllen = len;
75351 msg.msg_flags = flags;
75352
75353 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
75354 index 5bddea7..82d9d67 100644
75355 --- a/net/ipv6/raw.c
75356 +++ b/net/ipv6/raw.c
75357 @@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
75358 {
75359 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
75360 skb_checksum_complete(skb)) {
75361 - atomic_inc(&sk->sk_drops);
75362 + atomic_inc_unchecked(&sk->sk_drops);
75363 kfree_skb(skb);
75364 return NET_RX_DROP;
75365 }
75366 @@ -405,7 +405,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
75367 struct raw6_sock *rp = raw6_sk(sk);
75368
75369 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
75370 - atomic_inc(&sk->sk_drops);
75371 + atomic_inc_unchecked(&sk->sk_drops);
75372 kfree_skb(skb);
75373 return NET_RX_DROP;
75374 }
75375 @@ -429,7 +429,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
75376
75377 if (inet->hdrincl) {
75378 if (skb_checksum_complete(skb)) {
75379 - atomic_inc(&sk->sk_drops);
75380 + atomic_inc_unchecked(&sk->sk_drops);
75381 kfree_skb(skb);
75382 return NET_RX_DROP;
75383 }
75384 @@ -602,7 +602,7 @@ out:
75385 return err;
75386 }
75387
75388 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
75389 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
75390 struct flowi6 *fl6, struct dst_entry **dstp,
75391 unsigned int flags)
75392 {
75393 @@ -914,12 +914,15 @@ do_confirm:
75394 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
75395 char __user *optval, int optlen)
75396 {
75397 + struct icmp6_filter filter;
75398 +
75399 switch (optname) {
75400 case ICMPV6_FILTER:
75401 if (optlen > sizeof(struct icmp6_filter))
75402 optlen = sizeof(struct icmp6_filter);
75403 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
75404 + if (copy_from_user(&filter, optval, optlen))
75405 return -EFAULT;
75406 + raw6_sk(sk)->filter = filter;
75407 return 0;
75408 default:
75409 return -ENOPROTOOPT;
75410 @@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
75411 char __user *optval, int __user *optlen)
75412 {
75413 int len;
75414 + struct icmp6_filter filter;
75415
75416 switch (optname) {
75417 case ICMPV6_FILTER:
75418 @@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
75419 len = sizeof(struct icmp6_filter);
75420 if (put_user(len, optlen))
75421 return -EFAULT;
75422 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
75423 + filter = raw6_sk(sk)->filter;
75424 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
75425 return -EFAULT;
75426 return 0;
75427 default:
75428 @@ -1250,7 +1255,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
75429 0, 0L, 0,
75430 sock_i_uid(sp), 0,
75431 sock_i_ino(sp),
75432 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
75433 + atomic_read(&sp->sk_refcnt),
75434 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75435 + NULL,
75436 +#else
75437 + sp,
75438 +#endif
75439 + atomic_read_unchecked(&sp->sk_drops));
75440 }
75441
75442 static int raw6_seq_show(struct seq_file *seq, void *v)
75443 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
75444 index 98256cf..7f16dbd 100644
75445 --- a/net/ipv6/tcp_ipv6.c
75446 +++ b/net/ipv6/tcp_ipv6.c
75447 @@ -94,6 +94,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
75448 }
75449 #endif
75450
75451 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75452 +extern int grsec_enable_blackhole;
75453 +#endif
75454 +
75455 static void tcp_v6_hash(struct sock *sk)
75456 {
75457 if (sk->sk_state != TCP_CLOSE) {
75458 @@ -1542,6 +1546,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
75459 return 0;
75460
75461 reset:
75462 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75463 + if (!grsec_enable_blackhole)
75464 +#endif
75465 tcp_v6_send_reset(sk, skb);
75466 discard:
75467 if (opt_skb)
75468 @@ -1623,12 +1630,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
75469 TCP_SKB_CB(skb)->sacked = 0;
75470
75471 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
75472 - if (!sk)
75473 + if (!sk) {
75474 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75475 + ret = 1;
75476 +#endif
75477 goto no_tcp_socket;
75478 + }
75479
75480 process:
75481 - if (sk->sk_state == TCP_TIME_WAIT)
75482 + if (sk->sk_state == TCP_TIME_WAIT) {
75483 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75484 + ret = 2;
75485 +#endif
75486 goto do_time_wait;
75487 + }
75488
75489 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
75490 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
75491 @@ -1676,6 +1691,10 @@ no_tcp_socket:
75492 bad_packet:
75493 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
75494 } else {
75495 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75496 + if (!grsec_enable_blackhole || (ret == 1 &&
75497 + (skb->dev->flags & IFF_LOOPBACK)))
75498 +#endif
75499 tcp_v6_send_reset(NULL, skb);
75500 }
75501
75502 @@ -1930,7 +1949,13 @@ static void get_openreq6(struct seq_file *seq,
75503 uid,
75504 0, /* non standard timer */
75505 0, /* open_requests have no inode */
75506 - 0, req);
75507 + 0,
75508 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75509 + NULL
75510 +#else
75511 + req
75512 +#endif
75513 + );
75514 }
75515
75516 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
75517 @@ -1980,7 +2005,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
75518 sock_i_uid(sp),
75519 icsk->icsk_probes_out,
75520 sock_i_ino(sp),
75521 - atomic_read(&sp->sk_refcnt), sp,
75522 + atomic_read(&sp->sk_refcnt),
75523 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75524 + NULL,
75525 +#else
75526 + sp,
75527 +#endif
75528 jiffies_to_clock_t(icsk->icsk_rto),
75529 jiffies_to_clock_t(icsk->icsk_ack.ato),
75530 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
75531 @@ -2015,7 +2045,13 @@ static void get_timewait6_sock(struct seq_file *seq,
75532 dest->s6_addr32[2], dest->s6_addr32[3], destp,
75533 tw->tw_substate, 0, 0,
75534 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
75535 - atomic_read(&tw->tw_refcnt), tw);
75536 + atomic_read(&tw->tw_refcnt),
75537 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75538 + NULL
75539 +#else
75540 + tw
75541 +#endif
75542 + );
75543 }
75544
75545 static int tcp6_seq_show(struct seq_file *seq, void *v)
75546 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
75547 index 37b0699..d323408 100644
75548 --- a/net/ipv6/udp.c
75549 +++ b/net/ipv6/udp.c
75550 @@ -50,6 +50,10 @@
75551 #include <linux/seq_file.h>
75552 #include "udp_impl.h"
75553
75554 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75555 +extern int grsec_enable_blackhole;
75556 +#endif
75557 +
75558 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
75559 {
75560 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
75561 @@ -551,7 +555,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
75562
75563 return 0;
75564 drop:
75565 - atomic_inc(&sk->sk_drops);
75566 + atomic_inc_unchecked(&sk->sk_drops);
75567 drop_no_sk_drops_inc:
75568 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
75569 kfree_skb(skb);
75570 @@ -627,7 +631,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
75571 continue;
75572 }
75573 drop:
75574 - atomic_inc(&sk->sk_drops);
75575 + atomic_inc_unchecked(&sk->sk_drops);
75576 UDP6_INC_STATS_BH(sock_net(sk),
75577 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
75578 UDP6_INC_STATS_BH(sock_net(sk),
75579 @@ -782,6 +786,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
75580 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
75581 proto == IPPROTO_UDPLITE);
75582
75583 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75584 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
75585 +#endif
75586 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
75587
75588 kfree_skb(skb);
75589 @@ -798,7 +805,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
75590 if (!sock_owned_by_user(sk))
75591 udpv6_queue_rcv_skb(sk, skb);
75592 else if (sk_add_backlog(sk, skb)) {
75593 - atomic_inc(&sk->sk_drops);
75594 + atomic_inc_unchecked(&sk->sk_drops);
75595 bh_unlock_sock(sk);
75596 sock_put(sk);
75597 goto discard;
75598 @@ -1411,8 +1418,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
75599 0, 0L, 0,
75600 sock_i_uid(sp), 0,
75601 sock_i_ino(sp),
75602 - atomic_read(&sp->sk_refcnt), sp,
75603 - atomic_read(&sp->sk_drops));
75604 + atomic_read(&sp->sk_refcnt),
75605 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75606 + NULL,
75607 +#else
75608 + sp,
75609 +#endif
75610 + atomic_read_unchecked(&sp->sk_drops));
75611 }
75612
75613 int udp6_seq_show(struct seq_file *seq, void *v)
75614 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
75615 index 6b9d5a0..4dffaf1 100644
75616 --- a/net/irda/ircomm/ircomm_tty.c
75617 +++ b/net/irda/ircomm/ircomm_tty.c
75618 @@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
75619 add_wait_queue(&self->open_wait, &wait);
75620
75621 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
75622 - __FILE__,__LINE__, tty->driver->name, self->open_count );
75623 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
75624
75625 /* As far as I can see, we protect open_count - Jean II */
75626 spin_lock_irqsave(&self->spinlock, flags);
75627 if (!tty_hung_up_p(filp)) {
75628 extra_count = 1;
75629 - self->open_count--;
75630 + local_dec(&self->open_count);
75631 }
75632 spin_unlock_irqrestore(&self->spinlock, flags);
75633 - self->blocked_open++;
75634 + local_inc(&self->blocked_open);
75635
75636 while (1) {
75637 if (tty->termios->c_cflag & CBAUD) {
75638 @@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
75639 }
75640
75641 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
75642 - __FILE__,__LINE__, tty->driver->name, self->open_count );
75643 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
75644
75645 schedule();
75646 }
75647 @@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
75648 if (extra_count) {
75649 /* ++ is not atomic, so this should be protected - Jean II */
75650 spin_lock_irqsave(&self->spinlock, flags);
75651 - self->open_count++;
75652 + local_inc(&self->open_count);
75653 spin_unlock_irqrestore(&self->spinlock, flags);
75654 }
75655 - self->blocked_open--;
75656 + local_dec(&self->blocked_open);
75657
75658 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
75659 - __FILE__,__LINE__, tty->driver->name, self->open_count);
75660 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
75661
75662 if (!retval)
75663 self->flags |= ASYNC_NORMAL_ACTIVE;
75664 @@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
75665 }
75666 /* ++ is not atomic, so this should be protected - Jean II */
75667 spin_lock_irqsave(&self->spinlock, flags);
75668 - self->open_count++;
75669 + local_inc(&self->open_count);
75670
75671 tty->driver_data = self;
75672 self->tty = tty;
75673 spin_unlock_irqrestore(&self->spinlock, flags);
75674
75675 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
75676 - self->line, self->open_count);
75677 + self->line, local_read(&self->open_count));
75678
75679 /* Not really used by us, but lets do it anyway */
75680 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
75681 @@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
75682 return;
75683 }
75684
75685 - if ((tty->count == 1) && (self->open_count != 1)) {
75686 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
75687 /*
75688 * Uh, oh. tty->count is 1, which means that the tty
75689 * structure will be freed. state->count should always
75690 @@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
75691 */
75692 IRDA_DEBUG(0, "%s(), bad serial port count; "
75693 "tty->count is 1, state->count is %d\n", __func__ ,
75694 - self->open_count);
75695 - self->open_count = 1;
75696 + local_read(&self->open_count));
75697 + local_set(&self->open_count, 1);
75698 }
75699
75700 - if (--self->open_count < 0) {
75701 + if (local_dec_return(&self->open_count) < 0) {
75702 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
75703 - __func__, self->line, self->open_count);
75704 - self->open_count = 0;
75705 + __func__, self->line, local_read(&self->open_count));
75706 + local_set(&self->open_count, 0);
75707 }
75708 - if (self->open_count) {
75709 + if (local_read(&self->open_count)) {
75710 spin_unlock_irqrestore(&self->spinlock, flags);
75711
75712 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
75713 @@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
75714 tty->closing = 0;
75715 self->tty = NULL;
75716
75717 - if (self->blocked_open) {
75718 + if (local_read(&self->blocked_open)) {
75719 if (self->close_delay)
75720 schedule_timeout_interruptible(self->close_delay);
75721 wake_up_interruptible(&self->open_wait);
75722 @@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
75723 spin_lock_irqsave(&self->spinlock, flags);
75724 self->flags &= ~ASYNC_NORMAL_ACTIVE;
75725 self->tty = NULL;
75726 - self->open_count = 0;
75727 + local_set(&self->open_count, 0);
75728 spin_unlock_irqrestore(&self->spinlock, flags);
75729
75730 wake_up_interruptible(&self->open_wait);
75731 @@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
75732 seq_putc(m, '\n');
75733
75734 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
75735 - seq_printf(m, "Open count: %d\n", self->open_count);
75736 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
75737 seq_printf(m, "Max data size: %d\n", self->max_data_size);
75738 seq_printf(m, "Max header size: %d\n", self->max_header_size);
75739
75740 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
75741 index cd6f7a9..e63fe89 100644
75742 --- a/net/iucv/af_iucv.c
75743 +++ b/net/iucv/af_iucv.c
75744 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
75745
75746 write_lock_bh(&iucv_sk_list.lock);
75747
75748 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
75749 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
75750 while (__iucv_get_sock_by_name(name)) {
75751 sprintf(name, "%08x",
75752 - atomic_inc_return(&iucv_sk_list.autobind_name));
75753 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
75754 }
75755
75756 write_unlock_bh(&iucv_sk_list.lock);
75757 diff --git a/net/key/af_key.c b/net/key/af_key.c
75758 index 7e5d927..cdbb54e 100644
75759 --- a/net/key/af_key.c
75760 +++ b/net/key/af_key.c
75761 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
75762 static u32 get_acqseq(void)
75763 {
75764 u32 res;
75765 - static atomic_t acqseq;
75766 + static atomic_unchecked_t acqseq;
75767
75768 do {
75769 - res = atomic_inc_return(&acqseq);
75770 + res = atomic_inc_return_unchecked(&acqseq);
75771 } while (!res);
75772 return res;
75773 }
75774 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
75775 index db8fae5..ff070cd 100644
75776 --- a/net/mac80211/ieee80211_i.h
75777 +++ b/net/mac80211/ieee80211_i.h
75778 @@ -28,6 +28,7 @@
75779 #include <net/ieee80211_radiotap.h>
75780 #include <net/cfg80211.h>
75781 #include <net/mac80211.h>
75782 +#include <asm/local.h>
75783 #include "key.h"
75784 #include "sta_info.h"
75785
75786 @@ -842,7 +843,7 @@ struct ieee80211_local {
75787 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
75788 spinlock_t queue_stop_reason_lock;
75789
75790 - int open_count;
75791 + local_t open_count;
75792 int monitors, cooked_mntrs;
75793 /* number of interfaces with corresponding FIF_ flags */
75794 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
75795 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
75796 index 48f937e..4ccd7b8 100644
75797 --- a/net/mac80211/iface.c
75798 +++ b/net/mac80211/iface.c
75799 @@ -222,7 +222,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75800 break;
75801 }
75802
75803 - if (local->open_count == 0) {
75804 + if (local_read(&local->open_count) == 0) {
75805 res = drv_start(local);
75806 if (res)
75807 goto err_del_bss;
75808 @@ -246,7 +246,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75809 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
75810
75811 if (!is_valid_ether_addr(dev->dev_addr)) {
75812 - if (!local->open_count)
75813 + if (!local_read(&local->open_count))
75814 drv_stop(local);
75815 return -EADDRNOTAVAIL;
75816 }
75817 @@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75818 mutex_unlock(&local->mtx);
75819
75820 if (coming_up)
75821 - local->open_count++;
75822 + local_inc(&local->open_count);
75823
75824 if (hw_reconf_flags)
75825 ieee80211_hw_config(local, hw_reconf_flags);
75826 @@ -360,7 +360,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
75827 err_del_interface:
75828 drv_remove_interface(local, sdata);
75829 err_stop:
75830 - if (!local->open_count)
75831 + if (!local_read(&local->open_count))
75832 drv_stop(local);
75833 err_del_bss:
75834 sdata->bss = NULL;
75835 @@ -491,7 +491,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
75836 }
75837
75838 if (going_down)
75839 - local->open_count--;
75840 + local_dec(&local->open_count);
75841
75842 switch (sdata->vif.type) {
75843 case NL80211_IFTYPE_AP_VLAN:
75844 @@ -562,7 +562,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
75845
75846 ieee80211_recalc_ps(local, -1);
75847
75848 - if (local->open_count == 0) {
75849 + if (local_read(&local->open_count) == 0) {
75850 if (local->ops->napi_poll)
75851 napi_disable(&local->napi);
75852 ieee80211_clear_tx_pending(local);
75853 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
75854 index 1633648..d45ebfa 100644
75855 --- a/net/mac80211/main.c
75856 +++ b/net/mac80211/main.c
75857 @@ -164,7 +164,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
75858 local->hw.conf.power_level = power;
75859 }
75860
75861 - if (changed && local->open_count) {
75862 + if (changed && local_read(&local->open_count)) {
75863 ret = drv_config(local, changed);
75864 /*
75865 * Goal:
75866 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
75867 index ef8eba1..5c63952 100644
75868 --- a/net/mac80211/pm.c
75869 +++ b/net/mac80211/pm.c
75870 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
75871 struct ieee80211_sub_if_data *sdata;
75872 struct sta_info *sta;
75873
75874 - if (!local->open_count)
75875 + if (!local_read(&local->open_count))
75876 goto suspend;
75877
75878 ieee80211_scan_cancel(local);
75879 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
75880 cancel_work_sync(&local->dynamic_ps_enable_work);
75881 del_timer_sync(&local->dynamic_ps_timer);
75882
75883 - local->wowlan = wowlan && local->open_count;
75884 + local->wowlan = wowlan && local_read(&local->open_count);
75885 if (local->wowlan) {
75886 int err = drv_suspend(local, wowlan);
75887 if (err < 0) {
75888 @@ -128,7 +128,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
75889 }
75890
75891 /* stop hardware - this must stop RX */
75892 - if (local->open_count)
75893 + if (local_read(&local->open_count))
75894 ieee80211_stop_device(local);
75895
75896 suspend:
75897 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
75898 index 3313c11..bec9f17 100644
75899 --- a/net/mac80211/rate.c
75900 +++ b/net/mac80211/rate.c
75901 @@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
75902
75903 ASSERT_RTNL();
75904
75905 - if (local->open_count)
75906 + if (local_read(&local->open_count))
75907 return -EBUSY;
75908
75909 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
75910 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
75911 index c97a065..ff61928 100644
75912 --- a/net/mac80211/rc80211_pid_debugfs.c
75913 +++ b/net/mac80211/rc80211_pid_debugfs.c
75914 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
75915
75916 spin_unlock_irqrestore(&events->lock, status);
75917
75918 - if (copy_to_user(buf, pb, p))
75919 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
75920 return -EFAULT;
75921
75922 return p;
75923 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
75924 index eb9d7c0..d34b832 100644
75925 --- a/net/mac80211/util.c
75926 +++ b/net/mac80211/util.c
75927 @@ -1179,7 +1179,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
75928 }
75929 #endif
75930 /* everything else happens only if HW was up & running */
75931 - if (!local->open_count)
75932 + if (!local_read(&local->open_count))
75933 goto wake_up;
75934
75935 /*
75936 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
75937 index 0c6f67e..d02cdfc 100644
75938 --- a/net/netfilter/Kconfig
75939 +++ b/net/netfilter/Kconfig
75940 @@ -836,6 +836,16 @@ config NETFILTER_XT_MATCH_ESP
75941
75942 To compile it as a module, choose M here. If unsure, say N.
75943
75944 +config NETFILTER_XT_MATCH_GRADM
75945 + tristate '"gradm" match support'
75946 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
75947 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
75948 + ---help---
75949 + The gradm match allows to match on grsecurity RBAC being enabled.
75950 + It is useful when iptables rules are applied early on bootup to
75951 + prevent connections to the machine (except from a trusted host)
75952 + while the RBAC system is disabled.
75953 +
75954 config NETFILTER_XT_MATCH_HASHLIMIT
75955 tristate '"hashlimit" match support'
75956 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
75957 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
75958 index ca36765..0882e7c 100644
75959 --- a/net/netfilter/Makefile
75960 +++ b/net/netfilter/Makefile
75961 @@ -86,6 +86,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
75962 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
75963 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
75964 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
75965 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
75966 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
75967 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
75968 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
75969 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
75970 index 29fa5ba..8debc79 100644
75971 --- a/net/netfilter/ipvs/ip_vs_conn.c
75972 +++ b/net/netfilter/ipvs/ip_vs_conn.c
75973 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
75974 /* Increase the refcnt counter of the dest */
75975 atomic_inc(&dest->refcnt);
75976
75977 - conn_flags = atomic_read(&dest->conn_flags);
75978 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
75979 if (cp->protocol != IPPROTO_UDP)
75980 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
75981 /* Bind with the destination and its corresponding transmitter */
75982 @@ -869,7 +869,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
75983 atomic_set(&cp->refcnt, 1);
75984
75985 atomic_set(&cp->n_control, 0);
75986 - atomic_set(&cp->in_pkts, 0);
75987 + atomic_set_unchecked(&cp->in_pkts, 0);
75988
75989 atomic_inc(&ipvs->conn_count);
75990 if (flags & IP_VS_CONN_F_NO_CPORT)
75991 @@ -1149,7 +1149,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
75992
75993 /* Don't drop the entry if its number of incoming packets is not
75994 located in [0, 8] */
75995 - i = atomic_read(&cp->in_pkts);
75996 + i = atomic_read_unchecked(&cp->in_pkts);
75997 if (i > 8 || i < 0) return 0;
75998
75999 if (!todrop_rate[i]) return 0;
76000 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
76001 index 00bdb1d..6725a48 100644
76002 --- a/net/netfilter/ipvs/ip_vs_core.c
76003 +++ b/net/netfilter/ipvs/ip_vs_core.c
76004 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
76005 ret = cp->packet_xmit(skb, cp, pd->pp);
76006 /* do not touch skb anymore */
76007
76008 - atomic_inc(&cp->in_pkts);
76009 + atomic_inc_unchecked(&cp->in_pkts);
76010 ip_vs_conn_put(cp);
76011 return ret;
76012 }
76013 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
76014 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
76015 pkts = sysctl_sync_threshold(ipvs);
76016 else
76017 - pkts = atomic_add_return(1, &cp->in_pkts);
76018 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
76019
76020 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
76021 cp->protocol == IPPROTO_SCTP) {
76022 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
76023 index f558998..7dfb054 100644
76024 --- a/net/netfilter/ipvs/ip_vs_ctl.c
76025 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
76026 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
76027 ip_vs_rs_hash(ipvs, dest);
76028 write_unlock_bh(&ipvs->rs_lock);
76029 }
76030 - atomic_set(&dest->conn_flags, conn_flags);
76031 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
76032
76033 /* bind the service */
76034 if (!dest->svc) {
76035 @@ -1521,11 +1521,12 @@ static int ip_vs_dst_event(struct notifier_block *this, unsigned long event,
76036 {
76037 struct net_device *dev = ptr;
76038 struct net *net = dev_net(dev);
76039 + struct netns_ipvs *ipvs = net_ipvs(net);
76040 struct ip_vs_service *svc;
76041 struct ip_vs_dest *dest;
76042 unsigned int idx;
76043
76044 - if (event != NETDEV_UNREGISTER)
76045 + if (event != NETDEV_UNREGISTER || !ipvs)
76046 return NOTIFY_DONE;
76047 IP_VS_DBG(3, "%s() dev=%s\n", __func__, dev->name);
76048 EnterFunction(2);
76049 @@ -1551,7 +1552,7 @@ static int ip_vs_dst_event(struct notifier_block *this, unsigned long event,
76050 }
76051 }
76052
76053 - list_for_each_entry(dest, &net_ipvs(net)->dest_trash, n_list) {
76054 + list_for_each_entry(dest, &ipvs->dest_trash, n_list) {
76055 __ip_vs_dev_reset(dest, dev);
76056 }
76057 mutex_unlock(&__ip_vs_mutex);
76058 @@ -2028,7 +2029,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
76059 " %-7s %-6d %-10d %-10d\n",
76060 &dest->addr.in6,
76061 ntohs(dest->port),
76062 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
76063 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
76064 atomic_read(&dest->weight),
76065 atomic_read(&dest->activeconns),
76066 atomic_read(&dest->inactconns));
76067 @@ -2039,7 +2040,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
76068 "%-7s %-6d %-10d %-10d\n",
76069 ntohl(dest->addr.ip),
76070 ntohs(dest->port),
76071 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
76072 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
76073 atomic_read(&dest->weight),
76074 atomic_read(&dest->activeconns),
76075 atomic_read(&dest->inactconns));
76076 @@ -2509,7 +2510,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
76077
76078 entry.addr = dest->addr.ip;
76079 entry.port = dest->port;
76080 - entry.conn_flags = atomic_read(&dest->conn_flags);
76081 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
76082 entry.weight = atomic_read(&dest->weight);
76083 entry.u_threshold = dest->u_threshold;
76084 entry.l_threshold = dest->l_threshold;
76085 @@ -3042,7 +3043,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
76086 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
76087
76088 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
76089 - atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
76090 + atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
76091 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
76092 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
76093 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
76094 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
76095 index 8a0d6d6..90ec197 100644
76096 --- a/net/netfilter/ipvs/ip_vs_sync.c
76097 +++ b/net/netfilter/ipvs/ip_vs_sync.c
76098 @@ -649,7 +649,7 @@ control:
76099 * i.e only increment in_pkts for Templates.
76100 */
76101 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
76102 - int pkts = atomic_add_return(1, &cp->in_pkts);
76103 + int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
76104
76105 if (pkts % sysctl_sync_period(ipvs) != 1)
76106 return;
76107 @@ -795,7 +795,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
76108
76109 if (opt)
76110 memcpy(&cp->in_seq, opt, sizeof(*opt));
76111 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
76112 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
76113 cp->state = state;
76114 cp->old_state = cp->state;
76115 /*
76116 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
76117 index 7fd66de..e6fb361 100644
76118 --- a/net/netfilter/ipvs/ip_vs_xmit.c
76119 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
76120 @@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
76121 else
76122 rc = NF_ACCEPT;
76123 /* do not touch skb anymore */
76124 - atomic_inc(&cp->in_pkts);
76125 + atomic_inc_unchecked(&cp->in_pkts);
76126 goto out;
76127 }
76128
76129 @@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
76130 else
76131 rc = NF_ACCEPT;
76132 /* do not touch skb anymore */
76133 - atomic_inc(&cp->in_pkts);
76134 + atomic_inc_unchecked(&cp->in_pkts);
76135 goto out;
76136 }
76137
76138 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
76139 index 66b2c54..c7884e3 100644
76140 --- a/net/netfilter/nfnetlink_log.c
76141 +++ b/net/netfilter/nfnetlink_log.c
76142 @@ -70,7 +70,7 @@ struct nfulnl_instance {
76143 };
76144
76145 static DEFINE_SPINLOCK(instances_lock);
76146 -static atomic_t global_seq;
76147 +static atomic_unchecked_t global_seq;
76148
76149 #define INSTANCE_BUCKETS 16
76150 static struct hlist_head instance_table[INSTANCE_BUCKETS];
76151 @@ -502,7 +502,7 @@ __build_packet_message(struct nfulnl_instance *inst,
76152 /* global sequence number */
76153 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
76154 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
76155 - htonl(atomic_inc_return(&global_seq)));
76156 + htonl(atomic_inc_return_unchecked(&global_seq)));
76157
76158 if (data_len) {
76159 struct nlattr *nla;
76160 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
76161 new file mode 100644
76162 index 0000000..6905327
76163 --- /dev/null
76164 +++ b/net/netfilter/xt_gradm.c
76165 @@ -0,0 +1,51 @@
76166 +/*
76167 + * gradm match for netfilter
76168 + * Copyright © Zbigniew Krzystolik, 2010
76169 + *
76170 + * This program is free software; you can redistribute it and/or modify
76171 + * it under the terms of the GNU General Public License; either version
76172 + * 2 or 3 as published by the Free Software Foundation.
76173 + */
76174 +#include <linux/module.h>
76175 +#include <linux/moduleparam.h>
76176 +#include <linux/skbuff.h>
76177 +#include <linux/netfilter/x_tables.h>
76178 +#include <linux/grsecurity.h>
76179 +#include <linux/netfilter/xt_gradm.h>
76180 +
76181 +static bool
76182 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
76183 +{
76184 + const struct xt_gradm_mtinfo *info = par->matchinfo;
76185 + bool retval = false;
76186 + if (gr_acl_is_enabled())
76187 + retval = true;
76188 + return retval ^ info->invflags;
76189 +}
76190 +
76191 +static struct xt_match gradm_mt_reg __read_mostly = {
76192 + .name = "gradm",
76193 + .revision = 0,
76194 + .family = NFPROTO_UNSPEC,
76195 + .match = gradm_mt,
76196 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
76197 + .me = THIS_MODULE,
76198 +};
76199 +
76200 +static int __init gradm_mt_init(void)
76201 +{
76202 + return xt_register_match(&gradm_mt_reg);
76203 +}
76204 +
76205 +static void __exit gradm_mt_exit(void)
76206 +{
76207 + xt_unregister_match(&gradm_mt_reg);
76208 +}
76209 +
76210 +module_init(gradm_mt_init);
76211 +module_exit(gradm_mt_exit);
76212 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
76213 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
76214 +MODULE_LICENSE("GPL");
76215 +MODULE_ALIAS("ipt_gradm");
76216 +MODULE_ALIAS("ip6t_gradm");
76217 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
76218 index 4fe4fb4..87a89e5 100644
76219 --- a/net/netfilter/xt_statistic.c
76220 +++ b/net/netfilter/xt_statistic.c
76221 @@ -19,7 +19,7 @@
76222 #include <linux/module.h>
76223
76224 struct xt_statistic_priv {
76225 - atomic_t count;
76226 + atomic_unchecked_t count;
76227 } ____cacheline_aligned_in_smp;
76228
76229 MODULE_LICENSE("GPL");
76230 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
76231 break;
76232 case XT_STATISTIC_MODE_NTH:
76233 do {
76234 - oval = atomic_read(&info->master->count);
76235 + oval = atomic_read_unchecked(&info->master->count);
76236 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
76237 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
76238 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
76239 if (nval == 0)
76240 ret = !ret;
76241 break;
76242 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
76243 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
76244 if (info->master == NULL)
76245 return -ENOMEM;
76246 - atomic_set(&info->master->count, info->u.nth.count);
76247 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
76248
76249 return 0;
76250 }
76251 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
76252 index faa48f7..65f7f54 100644
76253 --- a/net/netlink/af_netlink.c
76254 +++ b/net/netlink/af_netlink.c
76255 @@ -741,7 +741,7 @@ static void netlink_overrun(struct sock *sk)
76256 sk->sk_error_report(sk);
76257 }
76258 }
76259 - atomic_inc(&sk->sk_drops);
76260 + atomic_inc_unchecked(&sk->sk_drops);
76261 }
76262
76263 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
76264 @@ -2013,7 +2013,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
76265 sk_wmem_alloc_get(s),
76266 nlk->cb,
76267 atomic_read(&s->sk_refcnt),
76268 - atomic_read(&s->sk_drops),
76269 + atomic_read_unchecked(&s->sk_drops),
76270 sock_i_ino(s)
76271 );
76272
76273 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
76274 index 06592d8..64860f6 100644
76275 --- a/net/netrom/af_netrom.c
76276 +++ b/net/netrom/af_netrom.c
76277 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
76278 struct sock *sk = sock->sk;
76279 struct nr_sock *nr = nr_sk(sk);
76280
76281 + memset(sax, 0, sizeof(*sax));
76282 lock_sock(sk);
76283 if (peer != 0) {
76284 if (sk->sk_state != TCP_ESTABLISHED) {
76285 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
76286 *uaddr_len = sizeof(struct full_sockaddr_ax25);
76287 } else {
76288 sax->fsa_ax25.sax25_family = AF_NETROM;
76289 - sax->fsa_ax25.sax25_ndigis = 0;
76290 sax->fsa_ax25.sax25_call = nr->source_addr;
76291 *uaddr_len = sizeof(struct sockaddr_ax25);
76292 }
76293 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
76294 index 4f2c0df..f0ff342 100644
76295 --- a/net/packet/af_packet.c
76296 +++ b/net/packet/af_packet.c
76297 @@ -1687,7 +1687,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
76298
76299 spin_lock(&sk->sk_receive_queue.lock);
76300 po->stats.tp_packets++;
76301 - skb->dropcount = atomic_read(&sk->sk_drops);
76302 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
76303 __skb_queue_tail(&sk->sk_receive_queue, skb);
76304 spin_unlock(&sk->sk_receive_queue.lock);
76305 sk->sk_data_ready(sk, skb->len);
76306 @@ -1696,7 +1696,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
76307 drop_n_acct:
76308 spin_lock(&sk->sk_receive_queue.lock);
76309 po->stats.tp_drops++;
76310 - atomic_inc(&sk->sk_drops);
76311 + atomic_inc_unchecked(&sk->sk_drops);
76312 spin_unlock(&sk->sk_receive_queue.lock);
76313
76314 drop_n_restore:
76315 @@ -3294,7 +3294,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
76316 case PACKET_HDRLEN:
76317 if (len > sizeof(int))
76318 len = sizeof(int);
76319 - if (copy_from_user(&val, optval, len))
76320 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
76321 return -EFAULT;
76322 switch (val) {
76323 case TPACKET_V1:
76324 @@ -3344,7 +3344,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
76325
76326 if (put_user(len, optlen))
76327 return -EFAULT;
76328 - if (copy_to_user(optval, data, len))
76329 + if (len > sizeof(st) || copy_to_user(optval, data, len))
76330 return -EFAULT;
76331 return 0;
76332 }
76333 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
76334 index d65f699..05aa6ce 100644
76335 --- a/net/phonet/af_phonet.c
76336 +++ b/net/phonet/af_phonet.c
76337 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
76338 {
76339 struct phonet_protocol *pp;
76340
76341 - if (protocol >= PHONET_NPROTO)
76342 + if (protocol < 0 || protocol >= PHONET_NPROTO)
76343 return NULL;
76344
76345 rcu_read_lock();
76346 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
76347 {
76348 int err = 0;
76349
76350 - if (protocol >= PHONET_NPROTO)
76351 + if (protocol < 0 || protocol >= PHONET_NPROTO)
76352 return -EINVAL;
76353
76354 err = proto_register(pp->prot, 1);
76355 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
76356 index 9726fe6..fc4e3a4 100644
76357 --- a/net/phonet/pep.c
76358 +++ b/net/phonet/pep.c
76359 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
76360
76361 case PNS_PEP_CTRL_REQ:
76362 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
76363 - atomic_inc(&sk->sk_drops);
76364 + atomic_inc_unchecked(&sk->sk_drops);
76365 break;
76366 }
76367 __skb_pull(skb, 4);
76368 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
76369 }
76370
76371 if (pn->rx_credits == 0) {
76372 - atomic_inc(&sk->sk_drops);
76373 + atomic_inc_unchecked(&sk->sk_drops);
76374 err = -ENOBUFS;
76375 break;
76376 }
76377 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
76378 }
76379
76380 if (pn->rx_credits == 0) {
76381 - atomic_inc(&sk->sk_drops);
76382 + atomic_inc_unchecked(&sk->sk_drops);
76383 err = NET_RX_DROP;
76384 break;
76385 }
76386 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
76387 index 4c7eff3..59c727f 100644
76388 --- a/net/phonet/socket.c
76389 +++ b/net/phonet/socket.c
76390 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
76391 pn->resource, sk->sk_state,
76392 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
76393 sock_i_uid(sk), sock_i_ino(sk),
76394 - atomic_read(&sk->sk_refcnt), sk,
76395 - atomic_read(&sk->sk_drops), &len);
76396 + atomic_read(&sk->sk_refcnt),
76397 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76398 + NULL,
76399 +#else
76400 + sk,
76401 +#endif
76402 + atomic_read_unchecked(&sk->sk_drops), &len);
76403 }
76404 seq_printf(seq, "%*s\n", 127 - len, "");
76405 return 0;
76406 diff --git a/net/rds/cong.c b/net/rds/cong.c
76407 index e5b65ac..f3b6fb7 100644
76408 --- a/net/rds/cong.c
76409 +++ b/net/rds/cong.c
76410 @@ -78,7 +78,7 @@
76411 * finds that the saved generation number is smaller than the global generation
76412 * number, it wakes up the process.
76413 */
76414 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
76415 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
76416
76417 /*
76418 * Congestion monitoring
76419 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
76420 rdsdebug("waking map %p for %pI4\n",
76421 map, &map->m_addr);
76422 rds_stats_inc(s_cong_update_received);
76423 - atomic_inc(&rds_cong_generation);
76424 + atomic_inc_unchecked(&rds_cong_generation);
76425 if (waitqueue_active(&map->m_waitq))
76426 wake_up(&map->m_waitq);
76427 if (waitqueue_active(&rds_poll_waitq))
76428 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
76429
76430 int rds_cong_updated_since(unsigned long *recent)
76431 {
76432 - unsigned long gen = atomic_read(&rds_cong_generation);
76433 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
76434
76435 if (likely(*recent == gen))
76436 return 0;
76437 diff --git a/net/rds/ib.h b/net/rds/ib.h
76438 index edfaaaf..8c89879 100644
76439 --- a/net/rds/ib.h
76440 +++ b/net/rds/ib.h
76441 @@ -128,7 +128,7 @@ struct rds_ib_connection {
76442 /* sending acks */
76443 unsigned long i_ack_flags;
76444 #ifdef KERNEL_HAS_ATOMIC64
76445 - atomic64_t i_ack_next; /* next ACK to send */
76446 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
76447 #else
76448 spinlock_t i_ack_lock; /* protect i_ack_next */
76449 u64 i_ack_next; /* next ACK to send */
76450 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
76451 index a1e1162..265e129 100644
76452 --- a/net/rds/ib_cm.c
76453 +++ b/net/rds/ib_cm.c
76454 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
76455 /* Clear the ACK state */
76456 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
76457 #ifdef KERNEL_HAS_ATOMIC64
76458 - atomic64_set(&ic->i_ack_next, 0);
76459 + atomic64_set_unchecked(&ic->i_ack_next, 0);
76460 #else
76461 ic->i_ack_next = 0;
76462 #endif
76463 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
76464 index 8d19491..05a3e65 100644
76465 --- a/net/rds/ib_recv.c
76466 +++ b/net/rds/ib_recv.c
76467 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
76468 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
76469 int ack_required)
76470 {
76471 - atomic64_set(&ic->i_ack_next, seq);
76472 + atomic64_set_unchecked(&ic->i_ack_next, seq);
76473 if (ack_required) {
76474 smp_mb__before_clear_bit();
76475 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
76476 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
76477 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
76478 smp_mb__after_clear_bit();
76479
76480 - return atomic64_read(&ic->i_ack_next);
76481 + return atomic64_read_unchecked(&ic->i_ack_next);
76482 }
76483 #endif
76484
76485 diff --git a/net/rds/iw.h b/net/rds/iw.h
76486 index 04ce3b1..48119a6 100644
76487 --- a/net/rds/iw.h
76488 +++ b/net/rds/iw.h
76489 @@ -134,7 +134,7 @@ struct rds_iw_connection {
76490 /* sending acks */
76491 unsigned long i_ack_flags;
76492 #ifdef KERNEL_HAS_ATOMIC64
76493 - atomic64_t i_ack_next; /* next ACK to send */
76494 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
76495 #else
76496 spinlock_t i_ack_lock; /* protect i_ack_next */
76497 u64 i_ack_next; /* next ACK to send */
76498 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
76499 index a91e1db..cf3053f 100644
76500 --- a/net/rds/iw_cm.c
76501 +++ b/net/rds/iw_cm.c
76502 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
76503 /* Clear the ACK state */
76504 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
76505 #ifdef KERNEL_HAS_ATOMIC64
76506 - atomic64_set(&ic->i_ack_next, 0);
76507 + atomic64_set_unchecked(&ic->i_ack_next, 0);
76508 #else
76509 ic->i_ack_next = 0;
76510 #endif
76511 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
76512 index 4503335..db566b4 100644
76513 --- a/net/rds/iw_recv.c
76514 +++ b/net/rds/iw_recv.c
76515 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
76516 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
76517 int ack_required)
76518 {
76519 - atomic64_set(&ic->i_ack_next, seq);
76520 + atomic64_set_unchecked(&ic->i_ack_next, seq);
76521 if (ack_required) {
76522 smp_mb__before_clear_bit();
76523 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
76524 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
76525 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
76526 smp_mb__after_clear_bit();
76527
76528 - return atomic64_read(&ic->i_ack_next);
76529 + return atomic64_read_unchecked(&ic->i_ack_next);
76530 }
76531 #endif
76532
76533 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
76534 index edac9ef..16bcb98 100644
76535 --- a/net/rds/tcp.c
76536 +++ b/net/rds/tcp.c
76537 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
76538 int val = 1;
76539
76540 set_fs(KERNEL_DS);
76541 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
76542 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
76543 sizeof(val));
76544 set_fs(oldfs);
76545 }
76546 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
76547 index 1b4fd68..2234175 100644
76548 --- a/net/rds/tcp_send.c
76549 +++ b/net/rds/tcp_send.c
76550 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
76551
76552 oldfs = get_fs();
76553 set_fs(KERNEL_DS);
76554 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
76555 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
76556 sizeof(val));
76557 set_fs(oldfs);
76558 }
76559 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
76560 index 74c064c..fdec26f 100644
76561 --- a/net/rxrpc/af_rxrpc.c
76562 +++ b/net/rxrpc/af_rxrpc.c
76563 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
76564 __be32 rxrpc_epoch;
76565
76566 /* current debugging ID */
76567 -atomic_t rxrpc_debug_id;
76568 +atomic_unchecked_t rxrpc_debug_id;
76569
76570 /* count of skbs currently in use */
76571 atomic_t rxrpc_n_skbs;
76572 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
76573 index c3126e8..21facc7 100644
76574 --- a/net/rxrpc/ar-ack.c
76575 +++ b/net/rxrpc/ar-ack.c
76576 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
76577
76578 _enter("{%d,%d,%d,%d},",
76579 call->acks_hard, call->acks_unacked,
76580 - atomic_read(&call->sequence),
76581 + atomic_read_unchecked(&call->sequence),
76582 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
76583
76584 stop = 0;
76585 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
76586
76587 /* each Tx packet has a new serial number */
76588 sp->hdr.serial =
76589 - htonl(atomic_inc_return(&call->conn->serial));
76590 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
76591
76592 hdr = (struct rxrpc_header *) txb->head;
76593 hdr->serial = sp->hdr.serial;
76594 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
76595 */
76596 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
76597 {
76598 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
76599 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
76600 }
76601
76602 /*
76603 @@ -629,7 +629,7 @@ process_further:
76604
76605 latest = ntohl(sp->hdr.serial);
76606 hard = ntohl(ack.firstPacket);
76607 - tx = atomic_read(&call->sequence);
76608 + tx = atomic_read_unchecked(&call->sequence);
76609
76610 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
76611 latest,
76612 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
76613 goto maybe_reschedule;
76614
76615 send_ACK_with_skew:
76616 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
76617 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
76618 ntohl(ack.serial));
76619 send_ACK:
76620 mtu = call->conn->trans->peer->if_mtu;
76621 @@ -1173,7 +1173,7 @@ send_ACK:
76622 ackinfo.rxMTU = htonl(5692);
76623 ackinfo.jumbo_max = htonl(4);
76624
76625 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
76626 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
76627 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
76628 ntohl(hdr.serial),
76629 ntohs(ack.maxSkew),
76630 @@ -1191,7 +1191,7 @@ send_ACK:
76631 send_message:
76632 _debug("send message");
76633
76634 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
76635 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
76636 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
76637 send_message_2:
76638
76639 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
76640 index bf656c2..48f9d27 100644
76641 --- a/net/rxrpc/ar-call.c
76642 +++ b/net/rxrpc/ar-call.c
76643 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
76644 spin_lock_init(&call->lock);
76645 rwlock_init(&call->state_lock);
76646 atomic_set(&call->usage, 1);
76647 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
76648 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
76649 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
76650
76651 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
76652 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
76653 index 4106ca9..a338d7a 100644
76654 --- a/net/rxrpc/ar-connection.c
76655 +++ b/net/rxrpc/ar-connection.c
76656 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
76657 rwlock_init(&conn->lock);
76658 spin_lock_init(&conn->state_lock);
76659 atomic_set(&conn->usage, 1);
76660 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
76661 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
76662 conn->avail_calls = RXRPC_MAXCALLS;
76663 conn->size_align = 4;
76664 conn->header_size = sizeof(struct rxrpc_header);
76665 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
76666 index e7ed43a..6afa140 100644
76667 --- a/net/rxrpc/ar-connevent.c
76668 +++ b/net/rxrpc/ar-connevent.c
76669 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
76670
76671 len = iov[0].iov_len + iov[1].iov_len;
76672
76673 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
76674 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
76675 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
76676
76677 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
76678 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
76679 index 1a2b0633..e8d1382 100644
76680 --- a/net/rxrpc/ar-input.c
76681 +++ b/net/rxrpc/ar-input.c
76682 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
76683 /* track the latest serial number on this connection for ACK packet
76684 * information */
76685 serial = ntohl(sp->hdr.serial);
76686 - hi_serial = atomic_read(&call->conn->hi_serial);
76687 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
76688 while (serial > hi_serial)
76689 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
76690 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
76691 serial);
76692
76693 /* request ACK generation for any ACK or DATA packet that requests
76694 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
76695 index 8e22bd3..f66d1c0 100644
76696 --- a/net/rxrpc/ar-internal.h
76697 +++ b/net/rxrpc/ar-internal.h
76698 @@ -272,8 +272,8 @@ struct rxrpc_connection {
76699 int error; /* error code for local abort */
76700 int debug_id; /* debug ID for printks */
76701 unsigned call_counter; /* call ID counter */
76702 - atomic_t serial; /* packet serial number counter */
76703 - atomic_t hi_serial; /* highest serial number received */
76704 + atomic_unchecked_t serial; /* packet serial number counter */
76705 + atomic_unchecked_t hi_serial; /* highest serial number received */
76706 u8 avail_calls; /* number of calls available */
76707 u8 size_align; /* data size alignment (for security) */
76708 u8 header_size; /* rxrpc + security header size */
76709 @@ -346,7 +346,7 @@ struct rxrpc_call {
76710 spinlock_t lock;
76711 rwlock_t state_lock; /* lock for state transition */
76712 atomic_t usage;
76713 - atomic_t sequence; /* Tx data packet sequence counter */
76714 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
76715 u32 abort_code; /* local/remote abort code */
76716 enum { /* current state of call */
76717 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
76718 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
76719 */
76720 extern atomic_t rxrpc_n_skbs;
76721 extern __be32 rxrpc_epoch;
76722 -extern atomic_t rxrpc_debug_id;
76723 +extern atomic_unchecked_t rxrpc_debug_id;
76724 extern struct workqueue_struct *rxrpc_workqueue;
76725
76726 /*
76727 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
76728 index 87f7135..74d3703 100644
76729 --- a/net/rxrpc/ar-local.c
76730 +++ b/net/rxrpc/ar-local.c
76731 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
76732 spin_lock_init(&local->lock);
76733 rwlock_init(&local->services_lock);
76734 atomic_set(&local->usage, 1);
76735 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
76736 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
76737 memcpy(&local->srx, srx, sizeof(*srx));
76738 }
76739
76740 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
76741 index 16ae887..d24f12b 100644
76742 --- a/net/rxrpc/ar-output.c
76743 +++ b/net/rxrpc/ar-output.c
76744 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
76745 sp->hdr.cid = call->cid;
76746 sp->hdr.callNumber = call->call_id;
76747 sp->hdr.seq =
76748 - htonl(atomic_inc_return(&call->sequence));
76749 + htonl(atomic_inc_return_unchecked(&call->sequence));
76750 sp->hdr.serial =
76751 - htonl(atomic_inc_return(&conn->serial));
76752 + htonl(atomic_inc_return_unchecked(&conn->serial));
76753 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
76754 sp->hdr.userStatus = 0;
76755 sp->hdr.securityIndex = conn->security_ix;
76756 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
76757 index 2754f09..b20e38f 100644
76758 --- a/net/rxrpc/ar-peer.c
76759 +++ b/net/rxrpc/ar-peer.c
76760 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
76761 INIT_LIST_HEAD(&peer->error_targets);
76762 spin_lock_init(&peer->lock);
76763 atomic_set(&peer->usage, 1);
76764 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
76765 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
76766 memcpy(&peer->srx, srx, sizeof(*srx));
76767
76768 rxrpc_assess_MTU_size(peer);
76769 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
76770 index 38047f7..9f48511 100644
76771 --- a/net/rxrpc/ar-proc.c
76772 +++ b/net/rxrpc/ar-proc.c
76773 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
76774 atomic_read(&conn->usage),
76775 rxrpc_conn_states[conn->state],
76776 key_serial(conn->key),
76777 - atomic_read(&conn->serial),
76778 - atomic_read(&conn->hi_serial));
76779 + atomic_read_unchecked(&conn->serial),
76780 + atomic_read_unchecked(&conn->hi_serial));
76781
76782 return 0;
76783 }
76784 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
76785 index 92df566..87ec1bf 100644
76786 --- a/net/rxrpc/ar-transport.c
76787 +++ b/net/rxrpc/ar-transport.c
76788 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
76789 spin_lock_init(&trans->client_lock);
76790 rwlock_init(&trans->conn_lock);
76791 atomic_set(&trans->usage, 1);
76792 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
76793 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
76794
76795 if (peer->srx.transport.family == AF_INET) {
76796 switch (peer->srx.transport_type) {
76797 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
76798 index 7635107..4670276 100644
76799 --- a/net/rxrpc/rxkad.c
76800 +++ b/net/rxrpc/rxkad.c
76801 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
76802
76803 len = iov[0].iov_len + iov[1].iov_len;
76804
76805 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
76806 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
76807 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
76808
76809 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
76810 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
76811
76812 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
76813
76814 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
76815 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
76816 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
76817
76818 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
76819 diff --git a/net/sctp/input.c b/net/sctp/input.c
76820 index 80f71af..be772c0 100644
76821 --- a/net/sctp/input.c
76822 +++ b/net/sctp/input.c
76823 @@ -736,15 +736,12 @@ static void __sctp_unhash_endpoint(struct sctp_endpoint *ep)
76824
76825 epb = &ep->base;
76826
76827 - if (hlist_unhashed(&epb->node))
76828 - return;
76829 -
76830 epb->hashent = sctp_ep_hashfn(epb->bind_addr.port);
76831
76832 head = &sctp_ep_hashtable[epb->hashent];
76833
76834 sctp_write_lock(&head->lock);
76835 - __hlist_del(&epb->node);
76836 + hlist_del_init(&epb->node);
76837 sctp_write_unlock(&head->lock);
76838 }
76839
76840 @@ -825,7 +822,7 @@ static void __sctp_unhash_established(struct sctp_association *asoc)
76841 head = &sctp_assoc_hashtable[epb->hashent];
76842
76843 sctp_write_lock(&head->lock);
76844 - __hlist_del(&epb->node);
76845 + hlist_del_init(&epb->node);
76846 sctp_write_unlock(&head->lock);
76847 }
76848
76849 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
76850 index 1e2eee8..ce3967e 100644
76851 --- a/net/sctp/proc.c
76852 +++ b/net/sctp/proc.c
76853 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
76854 seq_printf(seq,
76855 "%8pK %8pK %-3d %-3d %-2d %-4d "
76856 "%4d %8d %8d %7d %5lu %-5d %5d ",
76857 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
76858 + assoc, sk,
76859 + sctp_sk(sk)->type, sk->sk_state,
76860 assoc->state, hash,
76861 assoc->assoc_id,
76862 assoc->sndbuf_used,
76863 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
76864 index 92ba71d..9352c05 100644
76865 --- a/net/sctp/socket.c
76866 +++ b/net/sctp/socket.c
76867 @@ -1231,8 +1231,14 @@ out_free:
76868 SCTP_DEBUG_PRINTK("About to exit __sctp_connect() free asoc: %p"
76869 " kaddrs: %p err: %d\n",
76870 asoc, kaddrs, err);
76871 - if (asoc)
76872 + if (asoc) {
76873 + /* sctp_primitive_ASSOCIATE may have added this association
76874 + * To the hash table, try to unhash it, just in case, its a noop
76875 + * if it wasn't hashed so we're safe
76876 + */
76877 + sctp_unhash_established(asoc);
76878 sctp_association_free(asoc);
76879 + }
76880 return err;
76881 }
76882
76883 @@ -1942,8 +1948,10 @@ SCTP_STATIC int sctp_sendmsg(struct kiocb *iocb, struct sock *sk,
76884 goto out_unlock;
76885
76886 out_free:
76887 - if (new_asoc)
76888 + if (new_asoc) {
76889 + sctp_unhash_established(asoc);
76890 sctp_association_free(asoc);
76891 + }
76892 out_unlock:
76893 sctp_release_sock(sk);
76894
76895 @@ -4569,7 +4577,7 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
76896 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
76897 if (space_left < addrlen)
76898 return -ENOMEM;
76899 - if (copy_to_user(to, &temp, addrlen))
76900 + if (addrlen > sizeof(temp) || copy_to_user(to, &temp, addrlen))
76901 return -EFAULT;
76902 to += addrlen;
76903 cnt++;
76904 diff --git a/net/socket.c b/net/socket.c
76905 index 851edcd..b786851 100644
76906 --- a/net/socket.c
76907 +++ b/net/socket.c
76908 @@ -88,6 +88,7 @@
76909 #include <linux/nsproxy.h>
76910 #include <linux/magic.h>
76911 #include <linux/slab.h>
76912 +#include <linux/in.h>
76913
76914 #include <asm/uaccess.h>
76915 #include <asm/unistd.h>
76916 @@ -105,6 +106,8 @@
76917 #include <linux/sockios.h>
76918 #include <linux/atalk.h>
76919
76920 +#include <linux/grsock.h>
76921 +
76922 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
76923 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
76924 unsigned long nr_segs, loff_t pos);
76925 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
76926 &sockfs_dentry_operations, SOCKFS_MAGIC);
76927 }
76928
76929 -static struct vfsmount *sock_mnt __read_mostly;
76930 +struct vfsmount *sock_mnt __read_mostly;
76931
76932 static struct file_system_type sock_fs_type = {
76933 .name = "sockfs",
76934 @@ -1207,6 +1210,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
76935 return -EAFNOSUPPORT;
76936 if (type < 0 || type >= SOCK_MAX)
76937 return -EINVAL;
76938 + if (protocol < 0)
76939 + return -EINVAL;
76940
76941 /* Compatibility.
76942
76943 @@ -1339,6 +1344,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
76944 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
76945 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
76946
76947 + if(!gr_search_socket(family, type, protocol)) {
76948 + retval = -EACCES;
76949 + goto out;
76950 + }
76951 +
76952 + if (gr_handle_sock_all(family, type, protocol)) {
76953 + retval = -EACCES;
76954 + goto out;
76955 + }
76956 +
76957 retval = sock_create(family, type, protocol, &sock);
76958 if (retval < 0)
76959 goto out;
76960 @@ -1451,6 +1466,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
76961 if (sock) {
76962 err = move_addr_to_kernel(umyaddr, addrlen, &address);
76963 if (err >= 0) {
76964 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
76965 + err = -EACCES;
76966 + goto error;
76967 + }
76968 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
76969 + if (err)
76970 + goto error;
76971 +
76972 err = security_socket_bind(sock,
76973 (struct sockaddr *)&address,
76974 addrlen);
76975 @@ -1459,6 +1482,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
76976 (struct sockaddr *)
76977 &address, addrlen);
76978 }
76979 +error:
76980 fput_light(sock->file, fput_needed);
76981 }
76982 return err;
76983 @@ -1482,10 +1506,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
76984 if ((unsigned)backlog > somaxconn)
76985 backlog = somaxconn;
76986
76987 + if (gr_handle_sock_server_other(sock->sk)) {
76988 + err = -EPERM;
76989 + goto error;
76990 + }
76991 +
76992 + err = gr_search_listen(sock);
76993 + if (err)
76994 + goto error;
76995 +
76996 err = security_socket_listen(sock, backlog);
76997 if (!err)
76998 err = sock->ops->listen(sock, backlog);
76999
77000 +error:
77001 fput_light(sock->file, fput_needed);
77002 }
77003 return err;
77004 @@ -1529,6 +1563,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
77005 newsock->type = sock->type;
77006 newsock->ops = sock->ops;
77007
77008 + if (gr_handle_sock_server_other(sock->sk)) {
77009 + err = -EPERM;
77010 + sock_release(newsock);
77011 + goto out_put;
77012 + }
77013 +
77014 + err = gr_search_accept(sock);
77015 + if (err) {
77016 + sock_release(newsock);
77017 + goto out_put;
77018 + }
77019 +
77020 /*
77021 * We don't need try_module_get here, as the listening socket (sock)
77022 * has the protocol module (sock->ops->owner) held.
77023 @@ -1567,6 +1613,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
77024 fd_install(newfd, newfile);
77025 err = newfd;
77026
77027 + gr_attach_curr_ip(newsock->sk);
77028 +
77029 out_put:
77030 fput_light(sock->file, fput_needed);
77031 out:
77032 @@ -1599,6 +1647,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
77033 int, addrlen)
77034 {
77035 struct socket *sock;
77036 + struct sockaddr *sck;
77037 struct sockaddr_storage address;
77038 int err, fput_needed;
77039
77040 @@ -1609,6 +1658,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
77041 if (err < 0)
77042 goto out_put;
77043
77044 + sck = (struct sockaddr *)&address;
77045 +
77046 + if (gr_handle_sock_client(sck)) {
77047 + err = -EACCES;
77048 + goto out_put;
77049 + }
77050 +
77051 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
77052 + if (err)
77053 + goto out_put;
77054 +
77055 err =
77056 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
77057 if (err)
77058 @@ -1966,7 +2026,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
77059 * checking falls down on this.
77060 */
77061 if (copy_from_user(ctl_buf,
77062 - (void __user __force *)msg_sys->msg_control,
77063 + (void __force_user *)msg_sys->msg_control,
77064 ctl_len))
77065 goto out_freectl;
77066 msg_sys->msg_control = ctl_buf;
77067 @@ -2136,7 +2196,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
77068 * kernel msghdr to use the kernel address space)
77069 */
77070
77071 - uaddr = (__force void __user *)msg_sys->msg_name;
77072 + uaddr = (void __force_user *)msg_sys->msg_name;
77073 uaddr_len = COMPAT_NAMELEN(msg);
77074 if (MSG_CMSG_COMPAT & flags) {
77075 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
77076 @@ -2758,7 +2818,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
77077 }
77078
77079 ifr = compat_alloc_user_space(buf_size);
77080 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
77081 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
77082
77083 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
77084 return -EFAULT;
77085 @@ -2782,12 +2842,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
77086 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
77087
77088 if (copy_in_user(rxnfc, compat_rxnfc,
77089 - (void *)(&rxnfc->fs.m_ext + 1) -
77090 - (void *)rxnfc) ||
77091 + (void __user *)(&rxnfc->fs.m_ext + 1) -
77092 + (void __user *)rxnfc) ||
77093 copy_in_user(&rxnfc->fs.ring_cookie,
77094 &compat_rxnfc->fs.ring_cookie,
77095 - (void *)(&rxnfc->fs.location + 1) -
77096 - (void *)&rxnfc->fs.ring_cookie) ||
77097 + (void __user *)(&rxnfc->fs.location + 1) -
77098 + (void __user *)&rxnfc->fs.ring_cookie) ||
77099 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
77100 sizeof(rxnfc->rule_cnt)))
77101 return -EFAULT;
77102 @@ -2799,12 +2859,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
77103
77104 if (convert_out) {
77105 if (copy_in_user(compat_rxnfc, rxnfc,
77106 - (const void *)(&rxnfc->fs.m_ext + 1) -
77107 - (const void *)rxnfc) ||
77108 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
77109 + (const void __user *)rxnfc) ||
77110 copy_in_user(&compat_rxnfc->fs.ring_cookie,
77111 &rxnfc->fs.ring_cookie,
77112 - (const void *)(&rxnfc->fs.location + 1) -
77113 - (const void *)&rxnfc->fs.ring_cookie) ||
77114 + (const void __user *)(&rxnfc->fs.location + 1) -
77115 + (const void __user *)&rxnfc->fs.ring_cookie) ||
77116 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
77117 sizeof(rxnfc->rule_cnt)))
77118 return -EFAULT;
77119 @@ -2874,7 +2934,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
77120 old_fs = get_fs();
77121 set_fs(KERNEL_DS);
77122 err = dev_ioctl(net, cmd,
77123 - (struct ifreq __user __force *) &kifr);
77124 + (struct ifreq __force_user *) &kifr);
77125 set_fs(old_fs);
77126
77127 return err;
77128 @@ -2983,7 +3043,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
77129
77130 old_fs = get_fs();
77131 set_fs(KERNEL_DS);
77132 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
77133 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
77134 set_fs(old_fs);
77135
77136 if (cmd == SIOCGIFMAP && !err) {
77137 @@ -3088,7 +3148,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
77138 ret |= __get_user(rtdev, &(ur4->rt_dev));
77139 if (rtdev) {
77140 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
77141 - r4.rt_dev = (char __user __force *)devname;
77142 + r4.rt_dev = (char __force_user *)devname;
77143 devname[15] = 0;
77144 } else
77145 r4.rt_dev = NULL;
77146 @@ -3314,8 +3374,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
77147 int __user *uoptlen;
77148 int err;
77149
77150 - uoptval = (char __user __force *) optval;
77151 - uoptlen = (int __user __force *) optlen;
77152 + uoptval = (char __force_user *) optval;
77153 + uoptlen = (int __force_user *) optlen;
77154
77155 set_fs(KERNEL_DS);
77156 if (level == SOL_SOCKET)
77157 @@ -3335,7 +3395,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
77158 char __user *uoptval;
77159 int err;
77160
77161 - uoptval = (char __user __force *) optval;
77162 + uoptval = (char __force_user *) optval;
77163
77164 set_fs(KERNEL_DS);
77165 if (level == SOL_SOCKET)
77166 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
77167 index 994cfea..5343b6b 100644
77168 --- a/net/sunrpc/sched.c
77169 +++ b/net/sunrpc/sched.c
77170 @@ -240,9 +240,9 @@ static int rpc_wait_bit_killable(void *word)
77171 #ifdef RPC_DEBUG
77172 static void rpc_task_set_debuginfo(struct rpc_task *task)
77173 {
77174 - static atomic_t rpc_pid;
77175 + static atomic_unchecked_t rpc_pid;
77176
77177 - task->tk_pid = atomic_inc_return(&rpc_pid);
77178 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
77179 }
77180 #else
77181 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
77182 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
77183 index 8343737..677025e 100644
77184 --- a/net/sunrpc/xprtrdma/svc_rdma.c
77185 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
77186 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
77187 static unsigned int min_max_inline = 4096;
77188 static unsigned int max_max_inline = 65536;
77189
77190 -atomic_t rdma_stat_recv;
77191 -atomic_t rdma_stat_read;
77192 -atomic_t rdma_stat_write;
77193 -atomic_t rdma_stat_sq_starve;
77194 -atomic_t rdma_stat_rq_starve;
77195 -atomic_t rdma_stat_rq_poll;
77196 -atomic_t rdma_stat_rq_prod;
77197 -atomic_t rdma_stat_sq_poll;
77198 -atomic_t rdma_stat_sq_prod;
77199 +atomic_unchecked_t rdma_stat_recv;
77200 +atomic_unchecked_t rdma_stat_read;
77201 +atomic_unchecked_t rdma_stat_write;
77202 +atomic_unchecked_t rdma_stat_sq_starve;
77203 +atomic_unchecked_t rdma_stat_rq_starve;
77204 +atomic_unchecked_t rdma_stat_rq_poll;
77205 +atomic_unchecked_t rdma_stat_rq_prod;
77206 +atomic_unchecked_t rdma_stat_sq_poll;
77207 +atomic_unchecked_t rdma_stat_sq_prod;
77208
77209 /* Temporary NFS request map and context caches */
77210 struct kmem_cache *svc_rdma_map_cachep;
77211 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
77212 len -= *ppos;
77213 if (len > *lenp)
77214 len = *lenp;
77215 - if (len && copy_to_user(buffer, str_buf, len))
77216 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
77217 return -EFAULT;
77218 *lenp = len;
77219 *ppos += len;
77220 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
77221 {
77222 .procname = "rdma_stat_read",
77223 .data = &rdma_stat_read,
77224 - .maxlen = sizeof(atomic_t),
77225 + .maxlen = sizeof(atomic_unchecked_t),
77226 .mode = 0644,
77227 .proc_handler = read_reset_stat,
77228 },
77229 {
77230 .procname = "rdma_stat_recv",
77231 .data = &rdma_stat_recv,
77232 - .maxlen = sizeof(atomic_t),
77233 + .maxlen = sizeof(atomic_unchecked_t),
77234 .mode = 0644,
77235 .proc_handler = read_reset_stat,
77236 },
77237 {
77238 .procname = "rdma_stat_write",
77239 .data = &rdma_stat_write,
77240 - .maxlen = sizeof(atomic_t),
77241 + .maxlen = sizeof(atomic_unchecked_t),
77242 .mode = 0644,
77243 .proc_handler = read_reset_stat,
77244 },
77245 {
77246 .procname = "rdma_stat_sq_starve",
77247 .data = &rdma_stat_sq_starve,
77248 - .maxlen = sizeof(atomic_t),
77249 + .maxlen = sizeof(atomic_unchecked_t),
77250 .mode = 0644,
77251 .proc_handler = read_reset_stat,
77252 },
77253 {
77254 .procname = "rdma_stat_rq_starve",
77255 .data = &rdma_stat_rq_starve,
77256 - .maxlen = sizeof(atomic_t),
77257 + .maxlen = sizeof(atomic_unchecked_t),
77258 .mode = 0644,
77259 .proc_handler = read_reset_stat,
77260 },
77261 {
77262 .procname = "rdma_stat_rq_poll",
77263 .data = &rdma_stat_rq_poll,
77264 - .maxlen = sizeof(atomic_t),
77265 + .maxlen = sizeof(atomic_unchecked_t),
77266 .mode = 0644,
77267 .proc_handler = read_reset_stat,
77268 },
77269 {
77270 .procname = "rdma_stat_rq_prod",
77271 .data = &rdma_stat_rq_prod,
77272 - .maxlen = sizeof(atomic_t),
77273 + .maxlen = sizeof(atomic_unchecked_t),
77274 .mode = 0644,
77275 .proc_handler = read_reset_stat,
77276 },
77277 {
77278 .procname = "rdma_stat_sq_poll",
77279 .data = &rdma_stat_sq_poll,
77280 - .maxlen = sizeof(atomic_t),
77281 + .maxlen = sizeof(atomic_unchecked_t),
77282 .mode = 0644,
77283 .proc_handler = read_reset_stat,
77284 },
77285 {
77286 .procname = "rdma_stat_sq_prod",
77287 .data = &rdma_stat_sq_prod,
77288 - .maxlen = sizeof(atomic_t),
77289 + .maxlen = sizeof(atomic_unchecked_t),
77290 .mode = 0644,
77291 .proc_handler = read_reset_stat,
77292 },
77293 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
77294 index 41cb63b..c4a1489 100644
77295 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
77296 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
77297 @@ -501,7 +501,7 @@ next_sge:
77298 svc_rdma_put_context(ctxt, 0);
77299 goto out;
77300 }
77301 - atomic_inc(&rdma_stat_read);
77302 + atomic_inc_unchecked(&rdma_stat_read);
77303
77304 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
77305 chl_map->ch[ch_no].count -= read_wr.num_sge;
77306 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
77307 dto_q);
77308 list_del_init(&ctxt->dto_q);
77309 } else {
77310 - atomic_inc(&rdma_stat_rq_starve);
77311 + atomic_inc_unchecked(&rdma_stat_rq_starve);
77312 clear_bit(XPT_DATA, &xprt->xpt_flags);
77313 ctxt = NULL;
77314 }
77315 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
77316 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
77317 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
77318 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
77319 - atomic_inc(&rdma_stat_recv);
77320 + atomic_inc_unchecked(&rdma_stat_recv);
77321
77322 /* Build up the XDR from the receive buffers. */
77323 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
77324 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
77325 index 42eb7ba..c887c45 100644
77326 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
77327 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
77328 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
77329 write_wr.wr.rdma.remote_addr = to;
77330
77331 /* Post It */
77332 - atomic_inc(&rdma_stat_write);
77333 + atomic_inc_unchecked(&rdma_stat_write);
77334 if (svc_rdma_send(xprt, &write_wr))
77335 goto err;
77336 return 0;
77337 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
77338 index 73b428b..5f3f8f3 100644
77339 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
77340 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
77341 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
77342 return;
77343
77344 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
77345 - atomic_inc(&rdma_stat_rq_poll);
77346 + atomic_inc_unchecked(&rdma_stat_rq_poll);
77347
77348 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
77349 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
77350 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
77351 }
77352
77353 if (ctxt)
77354 - atomic_inc(&rdma_stat_rq_prod);
77355 + atomic_inc_unchecked(&rdma_stat_rq_prod);
77356
77357 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
77358 /*
77359 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
77360 return;
77361
77362 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
77363 - atomic_inc(&rdma_stat_sq_poll);
77364 + atomic_inc_unchecked(&rdma_stat_sq_poll);
77365 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
77366 if (wc.status != IB_WC_SUCCESS)
77367 /* Close the transport */
77368 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
77369 }
77370
77371 if (ctxt)
77372 - atomic_inc(&rdma_stat_sq_prod);
77373 + atomic_inc_unchecked(&rdma_stat_sq_prod);
77374 }
77375
77376 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
77377 @@ -1266,7 +1266,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
77378 spin_lock_bh(&xprt->sc_lock);
77379 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
77380 spin_unlock_bh(&xprt->sc_lock);
77381 - atomic_inc(&rdma_stat_sq_starve);
77382 + atomic_inc_unchecked(&rdma_stat_sq_starve);
77383
77384 /* See if we can opportunistically reap SQ WR to make room */
77385 sq_cq_reap(xprt);
77386 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
77387 index c3e65ae..f512a2b 100644
77388 --- a/net/sysctl_net.c
77389 +++ b/net/sysctl_net.c
77390 @@ -47,7 +47,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
77391 struct ctl_table *table)
77392 {
77393 /* Allow network administrator to have same access as root. */
77394 - if (capable(CAP_NET_ADMIN)) {
77395 + if (capable_nolog(CAP_NET_ADMIN)) {
77396 int mode = (table->mode >> 6) & 7;
77397 return (mode << 6) | (mode << 3) | mode;
77398 }
77399 diff --git a/net/tipc/link.c b/net/tipc/link.c
77400 index b4b9b30..5b62131 100644
77401 --- a/net/tipc/link.c
77402 +++ b/net/tipc/link.c
77403 @@ -1203,7 +1203,7 @@ static int link_send_sections_long(struct tipc_port *sender,
77404 struct tipc_msg fragm_hdr;
77405 struct sk_buff *buf, *buf_chain, *prev;
77406 u32 fragm_crs, fragm_rest, hsz, sect_rest;
77407 - const unchar *sect_crs;
77408 + const unchar __user *sect_crs;
77409 int curr_sect;
77410 u32 fragm_no;
77411
77412 @@ -1247,7 +1247,7 @@ again:
77413
77414 if (!sect_rest) {
77415 sect_rest = msg_sect[++curr_sect].iov_len;
77416 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
77417 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
77418 }
77419
77420 if (sect_rest < fragm_rest)
77421 @@ -1266,7 +1266,7 @@ error:
77422 }
77423 } else
77424 skb_copy_to_linear_data_offset(buf, fragm_crs,
77425 - sect_crs, sz);
77426 + (const void __force_kernel *)sect_crs, sz);
77427 sect_crs += sz;
77428 sect_rest -= sz;
77429 fragm_crs += sz;
77430 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
77431 index e3afe16..333ea83 100644
77432 --- a/net/tipc/msg.c
77433 +++ b/net/tipc/msg.c
77434 @@ -99,7 +99,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
77435 msg_sect[cnt].iov_len);
77436 else
77437 skb_copy_to_linear_data_offset(*buf, pos,
77438 - msg_sect[cnt].iov_base,
77439 + (const void __force_kernel *)msg_sect[cnt].iov_base,
77440 msg_sect[cnt].iov_len);
77441 pos += msg_sect[cnt].iov_len;
77442 }
77443 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
77444 index b2964e9..fdf2e27 100644
77445 --- a/net/tipc/subscr.c
77446 +++ b/net/tipc/subscr.c
77447 @@ -101,7 +101,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
77448 {
77449 struct iovec msg_sect;
77450
77451 - msg_sect.iov_base = (void *)&sub->evt;
77452 + msg_sect.iov_base = (void __force_user *)&sub->evt;
77453 msg_sect.iov_len = sizeof(struct tipc_event);
77454
77455 sub->evt.event = htohl(event, sub->swap);
77456 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
77457 index d510353..26c8a32 100644
77458 --- a/net/unix/af_unix.c
77459 +++ b/net/unix/af_unix.c
77460 @@ -779,6 +779,12 @@ static struct sock *unix_find_other(struct net *net,
77461 err = -ECONNREFUSED;
77462 if (!S_ISSOCK(inode->i_mode))
77463 goto put_fail;
77464 +
77465 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
77466 + err = -EACCES;
77467 + goto put_fail;
77468 + }
77469 +
77470 u = unix_find_socket_byinode(inode);
77471 if (!u)
77472 goto put_fail;
77473 @@ -799,6 +805,13 @@ static struct sock *unix_find_other(struct net *net,
77474 if (u) {
77475 struct dentry *dentry;
77476 dentry = unix_sk(u)->path.dentry;
77477 +
77478 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
77479 + err = -EPERM;
77480 + sock_put(u);
77481 + goto fail;
77482 + }
77483 +
77484 if (dentry)
77485 touch_atime(&unix_sk(u)->path);
77486 } else
77487 @@ -881,11 +894,18 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
77488 err = security_path_mknod(&path, dentry, mode, 0);
77489 if (err)
77490 goto out_mknod_drop_write;
77491 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
77492 + err = -EACCES;
77493 + goto out_mknod_drop_write;
77494 + }
77495 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
77496 out_mknod_drop_write:
77497 mnt_drop_write(path.mnt);
77498 if (err)
77499 goto out_mknod_dput;
77500 +
77501 + gr_handle_create(dentry, path.mnt);
77502 +
77503 mutex_unlock(&path.dentry->d_inode->i_mutex);
77504 dput(path.dentry);
77505 path.dentry = dentry;
77506 diff --git a/net/wireless/core.h b/net/wireless/core.h
77507 index 3ac2dd0..fbe533e 100644
77508 --- a/net/wireless/core.h
77509 +++ b/net/wireless/core.h
77510 @@ -27,7 +27,7 @@ struct cfg80211_registered_device {
77511 struct mutex mtx;
77512
77513 /* rfkill support */
77514 - struct rfkill_ops rfkill_ops;
77515 + rfkill_ops_no_const rfkill_ops;
77516 struct rfkill *rfkill;
77517 struct work_struct rfkill_sync;
77518
77519 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
77520 index af648e0..6185d3a 100644
77521 --- a/net/wireless/wext-core.c
77522 +++ b/net/wireless/wext-core.c
77523 @@ -747,8 +747,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
77524 */
77525
77526 /* Support for very large requests */
77527 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
77528 - (user_length > descr->max_tokens)) {
77529 + if (user_length > descr->max_tokens) {
77530 /* Allow userspace to GET more than max so
77531 * we can support any size GET requests.
77532 * There is still a limit : -ENOMEM.
77533 @@ -787,22 +786,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
77534 }
77535 }
77536
77537 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
77538 - /*
77539 - * If this is a GET, but not NOMAX, it means that the extra
77540 - * data is not bounded by userspace, but by max_tokens. Thus
77541 - * set the length to max_tokens. This matches the extra data
77542 - * allocation.
77543 - * The driver should fill it with the number of tokens it
77544 - * provided, and it may check iwp->length rather than having
77545 - * knowledge of max_tokens. If the driver doesn't change the
77546 - * iwp->length, this ioctl just copies back max_token tokens
77547 - * filled with zeroes. Hopefully the driver isn't claiming
77548 - * them to be valid data.
77549 - */
77550 - iwp->length = descr->max_tokens;
77551 - }
77552 -
77553 err = handler(dev, info, (union iwreq_data *) iwp, extra);
77554
77555 iwp->length += essid_compat;
77556 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
77557 index a15d2a0..12142af 100644
77558 --- a/net/xfrm/xfrm_policy.c
77559 +++ b/net/xfrm/xfrm_policy.c
77560 @@ -299,7 +299,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
77561 {
77562 policy->walk.dead = 1;
77563
77564 - atomic_inc(&policy->genid);
77565 + atomic_inc_unchecked(&policy->genid);
77566
77567 if (del_timer(&policy->timer))
77568 xfrm_pol_put(policy);
77569 @@ -583,7 +583,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
77570 hlist_add_head(&policy->bydst, chain);
77571 xfrm_pol_hold(policy);
77572 net->xfrm.policy_count[dir]++;
77573 - atomic_inc(&flow_cache_genid);
77574 + atomic_inc_unchecked(&flow_cache_genid);
77575 if (delpol)
77576 __xfrm_policy_unlink(delpol, dir);
77577 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
77578 @@ -1530,7 +1530,7 @@ free_dst:
77579 goto out;
77580 }
77581
77582 -static int inline
77583 +static inline int
77584 xfrm_dst_alloc_copy(void **target, const void *src, int size)
77585 {
77586 if (!*target) {
77587 @@ -1542,7 +1542,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
77588 return 0;
77589 }
77590
77591 -static int inline
77592 +static inline int
77593 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
77594 {
77595 #ifdef CONFIG_XFRM_SUB_POLICY
77596 @@ -1554,7 +1554,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
77597 #endif
77598 }
77599
77600 -static int inline
77601 +static inline int
77602 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
77603 {
77604 #ifdef CONFIG_XFRM_SUB_POLICY
77605 @@ -1648,7 +1648,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
77606
77607 xdst->num_pols = num_pols;
77608 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
77609 - xdst->policy_genid = atomic_read(&pols[0]->genid);
77610 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
77611
77612 return xdst;
77613 }
77614 @@ -2348,7 +2348,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
77615 if (xdst->xfrm_genid != dst->xfrm->genid)
77616 return 0;
77617 if (xdst->num_pols > 0 &&
77618 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
77619 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
77620 return 0;
77621
77622 mtu = dst_mtu(dst->child);
77623 @@ -2885,7 +2885,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
77624 sizeof(pol->xfrm_vec[i].saddr));
77625 pol->xfrm_vec[i].encap_family = mp->new_family;
77626 /* flush bundles */
77627 - atomic_inc(&pol->genid);
77628 + atomic_inc_unchecked(&pol->genid);
77629 }
77630 }
77631
77632 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
77633 index ff1720d..ed8475e 100644
77634 --- a/scripts/Makefile.build
77635 +++ b/scripts/Makefile.build
77636 @@ -111,7 +111,7 @@ endif
77637 endif
77638
77639 # Do not include host rules unless needed
77640 -ifneq ($(hostprogs-y)$(hostprogs-m),)
77641 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
77642 include scripts/Makefile.host
77643 endif
77644
77645 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
77646 index 686cb0d..9d653bf 100644
77647 --- a/scripts/Makefile.clean
77648 +++ b/scripts/Makefile.clean
77649 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
77650 __clean-files := $(extra-y) $(always) \
77651 $(targets) $(clean-files) \
77652 $(host-progs) \
77653 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
77654 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
77655 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
77656
77657 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
77658
77659 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
77660 index 1ac414f..38575f7 100644
77661 --- a/scripts/Makefile.host
77662 +++ b/scripts/Makefile.host
77663 @@ -31,6 +31,8 @@
77664 # Note: Shared libraries consisting of C++ files are not supported
77665
77666 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
77667 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
77668 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
77669
77670 # C code
77671 # Executables compiled from a single .c file
77672 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
77673 # Shared libaries (only .c supported)
77674 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
77675 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
77676 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
77677 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
77678 # Remove .so files from "xxx-objs"
77679 host-cobjs := $(filter-out %.so,$(host-cobjs))
77680 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
77681
77682 -#Object (.o) files used by the shared libaries
77683 +# Object (.o) files used by the shared libaries
77684 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
77685 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
77686
77687 # output directory for programs/.o files
77688 # hostprogs-y := tools/build may have been specified. Retrieve directory
77689 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
77690 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
77691 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
77692 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
77693 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
77694 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
77695 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
77696 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
77697
77698 obj-dirs += $(host-objdirs)
77699 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
77700 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
77701 $(call if_changed_dep,host-cshobjs)
77702
77703 +# Compile .c file, create position independent .o file
77704 +# host-cxxshobjs -> .o
77705 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
77706 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
77707 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
77708 + $(call if_changed_dep,host-cxxshobjs)
77709 +
77710 # Link a shared library, based on position independent .o files
77711 # *.o -> .so shared library (host-cshlib)
77712 quiet_cmd_host-cshlib = HOSTLLD -shared $@
77713 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
77714 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
77715 $(call if_changed,host-cshlib)
77716
77717 +# Link a shared library, based on position independent .o files
77718 +# *.o -> .so shared library (host-cxxshlib)
77719 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
77720 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
77721 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
77722 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
77723 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
77724 + $(call if_changed,host-cxxshlib)
77725 +
77726 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
77727 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
77728 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
77729
77730 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
77731 index cb1f50c..cef2a7c 100644
77732 --- a/scripts/basic/fixdep.c
77733 +++ b/scripts/basic/fixdep.c
77734 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
77735 /*
77736 * Lookup a value in the configuration string.
77737 */
77738 -static int is_defined_config(const char *name, int len, unsigned int hash)
77739 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
77740 {
77741 struct item *aux;
77742
77743 @@ -211,10 +211,10 @@ static void clear_config(void)
77744 /*
77745 * Record the use of a CONFIG_* word.
77746 */
77747 -static void use_config(const char *m, int slen)
77748 +static void use_config(const char *m, unsigned int slen)
77749 {
77750 unsigned int hash = strhash(m, slen);
77751 - int c, i;
77752 + unsigned int c, i;
77753
77754 if (is_defined_config(m, slen, hash))
77755 return;
77756 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
77757
77758 static void parse_config_file(const char *map, size_t len)
77759 {
77760 - const int *end = (const int *) (map + len);
77761 + const unsigned int *end = (const unsigned int *) (map + len);
77762 /* start at +1, so that p can never be < map */
77763 - const int *m = (const int *) map + 1;
77764 + const unsigned int *m = (const unsigned int *) map + 1;
77765 const char *p, *q;
77766
77767 for (; m < end; m++) {
77768 @@ -406,7 +406,7 @@ static void print_deps(void)
77769 static void traps(void)
77770 {
77771 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
77772 - int *p = (int *)test;
77773 + unsigned int *p = (unsigned int *)test;
77774
77775 if (*p != INT_CONF) {
77776 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
77777 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
77778 new file mode 100644
77779 index 0000000..008ac1a
77780 --- /dev/null
77781 +++ b/scripts/gcc-plugin.sh
77782 @@ -0,0 +1,17 @@
77783 +#!/bin/bash
77784 +plugincc=`$1 -x c -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
77785 +#include "gcc-plugin.h"
77786 +#include "tree.h"
77787 +#include "tm.h"
77788 +#include "rtl.h"
77789 +#ifdef ENABLE_BUILD_WITH_CXX
77790 +#warning $2
77791 +#else
77792 +#warning $1
77793 +#endif
77794 +EOF`
77795 +if [ $? -eq 0 ]
77796 +then
77797 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
77798 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
77799 +fi
77800 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
77801 index 44ddaa5..a3119bd 100644
77802 --- a/scripts/mod/file2alias.c
77803 +++ b/scripts/mod/file2alias.c
77804 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
77805 unsigned long size, unsigned long id_size,
77806 void *symval)
77807 {
77808 - int i;
77809 + unsigned int i;
77810
77811 if (size % id_size || size < id_size) {
77812 if (cross_build != 0)
77813 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
77814 /* USB is special because the bcdDevice can be matched against a numeric range */
77815 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
77816 static void do_usb_entry(struct usb_device_id *id,
77817 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
77818 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
77819 unsigned char range_lo, unsigned char range_hi,
77820 unsigned char max, struct module *mod)
77821 {
77822 @@ -259,7 +259,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
77823 {
77824 unsigned int devlo, devhi;
77825 unsigned char chi, clo, max;
77826 - int ndigits;
77827 + unsigned int ndigits;
77828
77829 id->match_flags = TO_NATIVE(id->match_flags);
77830 id->idVendor = TO_NATIVE(id->idVendor);
77831 @@ -501,7 +501,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
77832 for (i = 0; i < count; i++) {
77833 const char *id = (char *)devs[i].id;
77834 char acpi_id[sizeof(devs[0].id)];
77835 - int j;
77836 + unsigned int j;
77837
77838 buf_printf(&mod->dev_table_buf,
77839 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
77840 @@ -531,7 +531,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
77841
77842 for (j = 0; j < PNP_MAX_DEVICES; j++) {
77843 const char *id = (char *)card->devs[j].id;
77844 - int i2, j2;
77845 + unsigned int i2, j2;
77846 int dup = 0;
77847
77848 if (!id[0])
77849 @@ -557,7 +557,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
77850 /* add an individual alias for every device entry */
77851 if (!dup) {
77852 char acpi_id[sizeof(card->devs[0].id)];
77853 - int k;
77854 + unsigned int k;
77855
77856 buf_printf(&mod->dev_table_buf,
77857 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
77858 @@ -882,7 +882,7 @@ static void dmi_ascii_filter(char *d, const char *s)
77859 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
77860 char *alias)
77861 {
77862 - int i, j;
77863 + unsigned int i, j;
77864
77865 sprintf(alias, "dmi*");
77866
77867 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
77868 index c4e7d15..4241aef 100644
77869 --- a/scripts/mod/modpost.c
77870 +++ b/scripts/mod/modpost.c
77871 @@ -922,6 +922,7 @@ enum mismatch {
77872 ANY_INIT_TO_ANY_EXIT,
77873 ANY_EXIT_TO_ANY_INIT,
77874 EXPORT_TO_INIT_EXIT,
77875 + DATA_TO_TEXT
77876 };
77877
77878 struct sectioncheck {
77879 @@ -1030,6 +1031,12 @@ const struct sectioncheck sectioncheck[] = {
77880 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
77881 .mismatch = EXPORT_TO_INIT_EXIT,
77882 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
77883 +},
77884 +/* Do not reference code from writable data */
77885 +{
77886 + .fromsec = { DATA_SECTIONS, NULL },
77887 + .tosec = { TEXT_SECTIONS, NULL },
77888 + .mismatch = DATA_TO_TEXT
77889 }
77890 };
77891
77892 @@ -1152,10 +1159,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
77893 continue;
77894 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
77895 continue;
77896 - if (sym->st_value == addr)
77897 - return sym;
77898 /* Find a symbol nearby - addr are maybe negative */
77899 d = sym->st_value - addr;
77900 + if (d == 0)
77901 + return sym;
77902 if (d < 0)
77903 d = addr - sym->st_value;
77904 if (d < distance) {
77905 @@ -1434,6 +1441,14 @@ static void report_sec_mismatch(const char *modname,
77906 tosym, prl_to, prl_to, tosym);
77907 free(prl_to);
77908 break;
77909 + case DATA_TO_TEXT:
77910 +/*
77911 + fprintf(stderr,
77912 + "The variable %s references\n"
77913 + "the %s %s%s%s\n",
77914 + fromsym, to, sec2annotation(tosec), tosym, to_p);
77915 +*/
77916 + break;
77917 }
77918 fprintf(stderr, "\n");
77919 }
77920 @@ -1668,7 +1683,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
77921 static void check_sec_ref(struct module *mod, const char *modname,
77922 struct elf_info *elf)
77923 {
77924 - int i;
77925 + unsigned int i;
77926 Elf_Shdr *sechdrs = elf->sechdrs;
77927
77928 /* Walk through all sections */
77929 @@ -1766,7 +1781,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
77930 va_end(ap);
77931 }
77932
77933 -void buf_write(struct buffer *buf, const char *s, int len)
77934 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
77935 {
77936 if (buf->size - buf->pos < len) {
77937 buf->size += len + SZ;
77938 @@ -1984,7 +1999,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
77939 if (fstat(fileno(file), &st) < 0)
77940 goto close_write;
77941
77942 - if (st.st_size != b->pos)
77943 + if (st.st_size != (off_t)b->pos)
77944 goto close_write;
77945
77946 tmp = NOFAIL(malloc(b->pos));
77947 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
77948 index 51207e4..f7d603d 100644
77949 --- a/scripts/mod/modpost.h
77950 +++ b/scripts/mod/modpost.h
77951 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
77952
77953 struct buffer {
77954 char *p;
77955 - int pos;
77956 - int size;
77957 + unsigned int pos;
77958 + unsigned int size;
77959 };
77960
77961 void __attribute__((format(printf, 2, 3)))
77962 buf_printf(struct buffer *buf, const char *fmt, ...);
77963
77964 void
77965 -buf_write(struct buffer *buf, const char *s, int len);
77966 +buf_write(struct buffer *buf, const char *s, unsigned int len);
77967
77968 struct module {
77969 struct module *next;
77970 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
77971 index 9dfcd6d..099068e 100644
77972 --- a/scripts/mod/sumversion.c
77973 +++ b/scripts/mod/sumversion.c
77974 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
77975 goto out;
77976 }
77977
77978 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
77979 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
77980 warn("writing sum in %s failed: %s\n",
77981 filename, strerror(errno));
77982 goto out;
77983 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
77984 index 5c11312..72742b5 100644
77985 --- a/scripts/pnmtologo.c
77986 +++ b/scripts/pnmtologo.c
77987 @@ -237,14 +237,14 @@ static void write_header(void)
77988 fprintf(out, " * Linux logo %s\n", logoname);
77989 fputs(" */\n\n", out);
77990 fputs("#include <linux/linux_logo.h>\n\n", out);
77991 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
77992 + fprintf(out, "static unsigned char %s_data[] = {\n",
77993 logoname);
77994 }
77995
77996 static void write_footer(void)
77997 {
77998 fputs("\n};\n\n", out);
77999 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
78000 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
78001 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
78002 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
78003 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
78004 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
78005 fputs("\n};\n\n", out);
78006
78007 /* write logo clut */
78008 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
78009 + fprintf(out, "static unsigned char %s_clut[] = {\n",
78010 logoname);
78011 write_hex_cnt = 0;
78012 for (i = 0; i < logo_clutsize; i++) {
78013 diff --git a/security/Kconfig b/security/Kconfig
78014 index ccc61f8..7244cf1 100644
78015 --- a/security/Kconfig
78016 +++ b/security/Kconfig
78017 @@ -4,6 +4,861 @@
78018
78019 menu "Security options"
78020
78021 +menu "Grsecurity"
78022 +
78023 + config ARCH_TRACK_EXEC_LIMIT
78024 + bool
78025 +
78026 + config PAX_KERNEXEC_PLUGIN
78027 + bool
78028 +
78029 + config PAX_PER_CPU_PGD
78030 + bool
78031 +
78032 + config TASK_SIZE_MAX_SHIFT
78033 + int
78034 + depends on X86_64
78035 + default 47 if !PAX_PER_CPU_PGD
78036 + default 42 if PAX_PER_CPU_PGD
78037 +
78038 + config PAX_ENABLE_PAE
78039 + bool
78040 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
78041 +
78042 +config GRKERNSEC
78043 + bool "Grsecurity"
78044 + select CRYPTO
78045 + select CRYPTO_SHA256
78046 + select STOP_MACHINE
78047 + help
78048 + If you say Y here, you will be able to configure many features
78049 + that will enhance the security of your system. It is highly
78050 + recommended that you say Y here and read through the help
78051 + for each option so that you fully understand the features and
78052 + can evaluate their usefulness for your machine.
78053 +
78054 +choice
78055 + prompt "Configuration Method"
78056 + depends on GRKERNSEC
78057 + default GRKERNSEC_CONFIG_CUSTOM
78058 + help
78059 +
78060 +config GRKERNSEC_CONFIG_AUTO
78061 + bool "Automatic"
78062 + help
78063 + If you choose this configuration method, you'll be able to answer a small
78064 + number of simple questions about how you plan to use this kernel.
78065 + The settings of grsecurity and PaX will be automatically configured for
78066 + the highest commonly-used settings within the provided constraints.
78067 +
78068 + If you require additional configuration, custom changes can still be made
78069 + from the "custom configuration" menu.
78070 +
78071 +config GRKERNSEC_CONFIG_CUSTOM
78072 + bool "Custom"
78073 + help
78074 + If you choose this configuration method, you'll be able to configure all
78075 + grsecurity and PaX settings manually. Via this method, no options are
78076 + automatically enabled.
78077 +
78078 +endchoice
78079 +
78080 +choice
78081 + prompt "Usage Type"
78082 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
78083 + default GRKERNSEC_CONFIG_SERVER
78084 + help
78085 +
78086 +config GRKERNSEC_CONFIG_SERVER
78087 + bool "Server"
78088 + help
78089 + Choose this option if you plan to use this kernel on a server.
78090 +
78091 +config GRKERNSEC_CONFIG_DESKTOP
78092 + bool "Desktop"
78093 + help
78094 + Choose this option if you plan to use this kernel on a desktop.
78095 +
78096 +endchoice
78097 +
78098 +choice
78099 + prompt "Virtualization Type"
78100 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
78101 + default GRKERNSEC_CONFIG_VIRT_NONE
78102 + help
78103 +
78104 +config GRKERNSEC_CONFIG_VIRT_NONE
78105 + bool "None"
78106 + help
78107 + Choose this option if this kernel will be run on bare metal.
78108 +
78109 +config GRKERNSEC_CONFIG_VIRT_GUEST
78110 + bool "Guest"
78111 + help
78112 + Choose this option if this kernel will be run as a VM guest.
78113 +
78114 +config GRKERNSEC_CONFIG_VIRT_HOST
78115 + bool "Host"
78116 + help
78117 + Choose this option if this kernel will be run as a VM host.
78118 +
78119 +endchoice
78120 +
78121 +choice
78122 + prompt "Virtualization Hardware"
78123 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
78124 + help
78125 +
78126 +config GRKERNSEC_CONFIG_VIRT_EPT
78127 + bool "EPT/RVI Processor Support"
78128 + depends on X86
78129 + help
78130 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
78131 + hardware virtualization. This allows for additional kernel hardening protections
78132 + to operate without additional performance impact.
78133 +
78134 + To see if your Intel processor supports EPT, see:
78135 + http://ark.intel.com/Products/VirtualizationTechnology
78136 + (Most Core i3/5/7 support EPT)
78137 +
78138 + To see if your AMD processor supports RVI, see:
78139 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
78140 +
78141 +config GRKERNSEC_CONFIG_VIRT_SOFT
78142 + bool "First-gen/No Hardware Virtualization"
78143 + help
78144 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
78145 + support hardware virtualization or doesn't support the EPT/RVI extensions.
78146 +
78147 +endchoice
78148 +
78149 +choice
78150 + prompt "Virtualization Software"
78151 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
78152 + help
78153 +
78154 +config GRKERNSEC_CONFIG_VIRT_XEN
78155 + bool "Xen"
78156 + help
78157 + Choose this option if this kernel is running as a Xen guest or host.
78158 +
78159 +config GRKERNSEC_CONFIG_VIRT_VMWARE
78160 + bool "VMWare"
78161 + help
78162 + Choose this option if this kernel is running as a VMWare guest or host.
78163 +
78164 +config GRKERNSEC_CONFIG_VIRT_KVM
78165 + bool "KVM"
78166 + help
78167 + Choose this option if this kernel is running as a KVM guest or host.
78168 +
78169 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
78170 + bool "VirtualBox"
78171 + help
78172 + Choose this option if this kernel is running as a VirtualBox guest or host.
78173 +
78174 +endchoice
78175 +
78176 +choice
78177 + prompt "Required Priorities"
78178 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
78179 + default GRKERNSEC_CONFIG_PRIORITY_PERF
78180 + help
78181 +
78182 +config GRKERNSEC_CONFIG_PRIORITY_PERF
78183 + bool "Performance"
78184 + help
78185 + Choose this option if performance is of highest priority for this deployment
78186 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
78187 + and freed memory sanitizing will be disabled.
78188 +
78189 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
78190 + bool "Security"
78191 + help
78192 + Choose this option if security is of highest priority for this deployment of
78193 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
78194 + be enabled for this kernel. In a worst-case scenario, these features can
78195 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
78196 +
78197 +endchoice
78198 +
78199 +menu "Default Special Groups"
78200 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
78201 +
78202 +config GRKERNSEC_PROC_GID
78203 + int "GID exempted from /proc restrictions"
78204 + default 1001
78205 + help
78206 + Setting this GID determines which group will be exempted from
78207 + grsecurity's /proc restrictions, allowing users of the specified
78208 + group to view network statistics and the existence of other users'
78209 + processes on the system.
78210 +
78211 +config GRKERNSEC_TPE_GID
78212 + int "GID for untrusted users"
78213 + depends on GRKERNSEC_CONFIG_SERVER
78214 + default 1005
78215 + help
78216 + Setting this GID determines which group untrusted users should
78217 + be added to. These users will be placed under grsecurity's Trusted Path
78218 + Execution mechanism, preventing them from executing their own binaries.
78219 + The users will only be able to execute binaries in directories owned and
78220 + writable only by the root user.
78221 +
78222 +config GRKERNSEC_SYMLINKOWN_GID
78223 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
78224 + depends on GRKERNSEC_CONFIG_SERVER
78225 + default 1006
78226 + help
78227 + Setting this GID determines what group kernel-enforced
78228 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
78229 + is enabled, a sysctl option with name "symlinkown_gid" is created.
78230 +
78231 +
78232 +endmenu
78233 +
78234 +menu "Customize Configuration"
78235 +depends on GRKERNSEC
78236 +
78237 +menu "PaX"
78238 +
78239 +config PAX
78240 + bool "Enable various PaX features"
78241 + default y if GRKERNSEC_CONFIG_AUTO
78242 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
78243 + help
78244 + This allows you to enable various PaX features. PaX adds
78245 + intrusion prevention mechanisms to the kernel that reduce
78246 + the risks posed by exploitable memory corruption bugs.
78247 +
78248 +menu "PaX Control"
78249 + depends on PAX
78250 +
78251 +config PAX_SOFTMODE
78252 + bool 'Support soft mode'
78253 + help
78254 + Enabling this option will allow you to run PaX in soft mode, that
78255 + is, PaX features will not be enforced by default, only on executables
78256 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
78257 + support as they are the only way to mark executables for soft mode use.
78258 +
78259 + Soft mode can be activated by using the "pax_softmode=1" kernel command
78260 + line option on boot. Furthermore you can control various PaX features
78261 + at runtime via the entries in /proc/sys/kernel/pax.
78262 +
78263 +config PAX_EI_PAX
78264 + bool 'Use legacy ELF header marking'
78265 + default y if GRKERNSEC_CONFIG_AUTO
78266 + help
78267 + Enabling this option will allow you to control PaX features on
78268 + a per executable basis via the 'chpax' utility available at
78269 + http://pax.grsecurity.net/. The control flags will be read from
78270 + an otherwise reserved part of the ELF header. This marking has
78271 + numerous drawbacks (no support for soft-mode, toolchain does not
78272 + know about the non-standard use of the ELF header) therefore it
78273 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
78274 + support.
78275 +
78276 + If you have applications not marked by the PT_PAX_FLAGS ELF program
78277 + header and you cannot use XATTR_PAX_FLAGS then you MUST enable this
78278 + option otherwise they will not get any protection.
78279 +
78280 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
78281 + support as well, they will override the legacy EI_PAX marks.
78282 +
78283 +config PAX_PT_PAX_FLAGS
78284 + bool 'Use ELF program header marking'
78285 + default y if GRKERNSEC_CONFIG_AUTO
78286 + help
78287 + Enabling this option will allow you to control PaX features on
78288 + a per executable basis via the 'paxctl' utility available at
78289 + http://pax.grsecurity.net/. The control flags will be read from
78290 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
78291 + has the benefits of supporting both soft mode and being fully
78292 + integrated into the toolchain (the binutils patch is available
78293 + from http://pax.grsecurity.net).
78294 +
78295 + If you have applications not marked by the PT_PAX_FLAGS ELF program
78296 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
78297 + support otherwise they will not get any protection.
78298 +
78299 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
78300 + must make sure that the marks are the same if a binary has both marks.
78301 +
78302 + Note that if you enable the legacy EI_PAX marking support as well,
78303 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
78304 +
78305 +config PAX_XATTR_PAX_FLAGS
78306 + bool 'Use filesystem extended attributes marking'
78307 + default y if GRKERNSEC_CONFIG_AUTO
78308 + select CIFS_XATTR if CIFS
78309 + select EXT2_FS_XATTR if EXT2_FS
78310 + select EXT3_FS_XATTR if EXT3_FS
78311 + select EXT4_FS_XATTR if EXT4_FS
78312 + select JFFS2_FS_XATTR if JFFS2_FS
78313 + select REISERFS_FS_XATTR if REISERFS_FS
78314 + select SQUASHFS_XATTR if SQUASHFS
78315 + select TMPFS_XATTR if TMPFS
78316 + select UBIFS_FS_XATTR if UBIFS_FS
78317 + help
78318 + Enabling this option will allow you to control PaX features on
78319 + a per executable basis via the 'setfattr' utility. The control
78320 + flags will be read from the user.pax.flags extended attribute of
78321 + the file. This marking has the benefit of supporting binary-only
78322 + applications that self-check themselves (e.g., skype) and would
78323 + not tolerate chpax/paxctl changes. The main drawback is that
78324 + extended attributes are not supported by some filesystems (e.g.,
78325 + isofs, udf, vfat) so copying files through such filesystems will
78326 + lose the extended attributes and these PaX markings.
78327 +
78328 + If you have applications not marked by the PT_PAX_FLAGS ELF program
78329 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
78330 + support otherwise they will not get any protection.
78331 +
78332 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
78333 + must make sure that the marks are the same if a binary has both marks.
78334 +
78335 + Note that if you enable the legacy EI_PAX marking support as well,
78336 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
78337 +
78338 +choice
78339 + prompt 'MAC system integration'
78340 + default PAX_HAVE_ACL_FLAGS
78341 + help
78342 + Mandatory Access Control systems have the option of controlling
78343 + PaX flags on a per executable basis, choose the method supported
78344 + by your particular system.
78345 +
78346 + - "none": if your MAC system does not interact with PaX,
78347 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
78348 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
78349 +
78350 + NOTE: this option is for developers/integrators only.
78351 +
78352 + config PAX_NO_ACL_FLAGS
78353 + bool 'none'
78354 +
78355 + config PAX_HAVE_ACL_FLAGS
78356 + bool 'direct'
78357 +
78358 + config PAX_HOOK_ACL_FLAGS
78359 + bool 'hook'
78360 +endchoice
78361 +
78362 +endmenu
78363 +
78364 +menu "Non-executable pages"
78365 + depends on PAX
78366 +
78367 +config PAX_NOEXEC
78368 + bool "Enforce non-executable pages"
78369 + default y if GRKERNSEC_CONFIG_AUTO
78370 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
78371 + help
78372 + By design some architectures do not allow for protecting memory
78373 + pages against execution or even if they do, Linux does not make
78374 + use of this feature. In practice this means that if a page is
78375 + readable (such as the stack or heap) it is also executable.
78376 +
78377 + There is a well known exploit technique that makes use of this
78378 + fact and a common programming mistake where an attacker can
78379 + introduce code of his choice somewhere in the attacked program's
78380 + memory (typically the stack or the heap) and then execute it.
78381 +
78382 + If the attacked program was running with different (typically
78383 + higher) privileges than that of the attacker, then he can elevate
78384 + his own privilege level (e.g. get a root shell, write to files for
78385 + which he does not have write access to, etc).
78386 +
78387 + Enabling this option will let you choose from various features
78388 + that prevent the injection and execution of 'foreign' code in
78389 + a program.
78390 +
78391 + This will also break programs that rely on the old behaviour and
78392 + expect that dynamically allocated memory via the malloc() family
78393 + of functions is executable (which it is not). Notable examples
78394 + are the XFree86 4.x server, the java runtime and wine.
78395 +
78396 +config PAX_PAGEEXEC
78397 + bool "Paging based non-executable pages"
78398 + default y if GRKERNSEC_CONFIG_AUTO
78399 + 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)
78400 + select S390_SWITCH_AMODE if S390
78401 + select S390_EXEC_PROTECT if S390
78402 + select ARCH_TRACK_EXEC_LIMIT if X86_32
78403 + help
78404 + This implementation is based on the paging feature of the CPU.
78405 + On i386 without hardware non-executable bit support there is a
78406 + variable but usually low performance impact, however on Intel's
78407 + P4 core based CPUs it is very high so you should not enable this
78408 + for kernels meant to be used on such CPUs.
78409 +
78410 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
78411 + with hardware non-executable bit support there is no performance
78412 + impact, on ppc the impact is negligible.
78413 +
78414 + Note that several architectures require various emulations due to
78415 + badly designed userland ABIs, this will cause a performance impact
78416 + but will disappear as soon as userland is fixed. For example, ppc
78417 + userland MUST have been built with secure-plt by a recent toolchain.
78418 +
78419 +config PAX_SEGMEXEC
78420 + bool "Segmentation based non-executable pages"
78421 + default y if GRKERNSEC_CONFIG_AUTO
78422 + depends on PAX_NOEXEC && X86_32
78423 + help
78424 + This implementation is based on the segmentation feature of the
78425 + CPU and has a very small performance impact, however applications
78426 + will be limited to a 1.5 GB address space instead of the normal
78427 + 3 GB.
78428 +
78429 +config PAX_EMUTRAMP
78430 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
78431 + default y if PARISC
78432 + help
78433 + There are some programs and libraries that for one reason or
78434 + another attempt to execute special small code snippets from
78435 + non-executable memory pages. Most notable examples are the
78436 + signal handler return code generated by the kernel itself and
78437 + the GCC trampolines.
78438 +
78439 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
78440 + such programs will no longer work under your kernel.
78441 +
78442 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
78443 + utilities to enable trampoline emulation for the affected programs
78444 + yet still have the protection provided by the non-executable pages.
78445 +
78446 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
78447 + your system will not even boot.
78448 +
78449 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
78450 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
78451 + for the affected files.
78452 +
78453 + NOTE: enabling this feature *may* open up a loophole in the
78454 + protection provided by non-executable pages that an attacker
78455 + could abuse. Therefore the best solution is to not have any
78456 + files on your system that would require this option. This can
78457 + be achieved by not using libc5 (which relies on the kernel
78458 + signal handler return code) and not using or rewriting programs
78459 + that make use of the nested function implementation of GCC.
78460 + Skilled users can just fix GCC itself so that it implements
78461 + nested function calls in a way that does not interfere with PaX.
78462 +
78463 +config PAX_EMUSIGRT
78464 + bool "Automatically emulate sigreturn trampolines"
78465 + depends on PAX_EMUTRAMP && PARISC
78466 + default y
78467 + help
78468 + Enabling this option will have the kernel automatically detect
78469 + and emulate signal return trampolines executing on the stack
78470 + that would otherwise lead to task termination.
78471 +
78472 + This solution is intended as a temporary one for users with
78473 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
78474 + Modula-3 runtime, etc) or executables linked to such, basically
78475 + everything that does not specify its own SA_RESTORER function in
78476 + normal executable memory like glibc 2.1+ does.
78477 +
78478 + On parisc you MUST enable this option, otherwise your system will
78479 + not even boot.
78480 +
78481 + NOTE: this feature cannot be disabled on a per executable basis
78482 + and since it *does* open up a loophole in the protection provided
78483 + by non-executable pages, the best solution is to not have any
78484 + files on your system that would require this option.
78485 +
78486 +config PAX_MPROTECT
78487 + bool "Restrict mprotect()"
78488 + default y if GRKERNSEC_CONFIG_AUTO
78489 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
78490 + help
78491 + Enabling this option will prevent programs from
78492 + - changing the executable status of memory pages that were
78493 + not originally created as executable,
78494 + - making read-only executable pages writable again,
78495 + - creating executable pages from anonymous memory,
78496 + - making read-only-after-relocations (RELRO) data pages writable again.
78497 +
78498 + You should say Y here to complete the protection provided by
78499 + the enforcement of non-executable pages.
78500 +
78501 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
78502 + this feature on a per file basis.
78503 +
78504 +config PAX_MPROTECT_COMPAT
78505 + bool "Use legacy/compat protection demoting (read help)"
78506 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
78507 + depends on PAX_MPROTECT
78508 + help
78509 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
78510 + by sending the proper error code to the application. For some broken
78511 + userland, this can cause problems with Python or other applications. The
78512 + current implementation however allows for applications like clamav to
78513 + detect if JIT compilation/execution is allowed and to fall back gracefully
78514 + to an interpreter-based mode if it does not. While we encourage everyone
78515 + to use the current implementation as-is and push upstream to fix broken
78516 + userland (note that the RWX logging option can assist with this), in some
78517 + environments this may not be possible. Having to disable MPROTECT
78518 + completely on certain binaries reduces the security benefit of PaX,
78519 + so this option is provided for those environments to revert to the old
78520 + behavior.
78521 +
78522 +config PAX_ELFRELOCS
78523 + bool "Allow ELF text relocations (read help)"
78524 + depends on PAX_MPROTECT
78525 + default n
78526 + help
78527 + Non-executable pages and mprotect() restrictions are effective
78528 + in preventing the introduction of new executable code into an
78529 + attacked task's address space. There remain only two venues
78530 + for this kind of attack: if the attacker can execute already
78531 + existing code in the attacked task then he can either have it
78532 + create and mmap() a file containing his code or have it mmap()
78533 + an already existing ELF library that does not have position
78534 + independent code in it and use mprotect() on it to make it
78535 + writable and copy his code there. While protecting against
78536 + the former approach is beyond PaX, the latter can be prevented
78537 + by having only PIC ELF libraries on one's system (which do not
78538 + need to relocate their code). If you are sure this is your case,
78539 + as is the case with all modern Linux distributions, then leave
78540 + this option disabled. You should say 'n' here.
78541 +
78542 +config PAX_ETEXECRELOCS
78543 + bool "Allow ELF ET_EXEC text relocations"
78544 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
78545 + select PAX_ELFRELOCS
78546 + default y
78547 + help
78548 + On some architectures there are incorrectly created applications
78549 + that require text relocations and would not work without enabling
78550 + this option. If you are an alpha, ia64 or parisc user, you should
78551 + enable this option and disable it once you have made sure that
78552 + none of your applications need it.
78553 +
78554 +config PAX_EMUPLT
78555 + bool "Automatically emulate ELF PLT"
78556 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
78557 + default y
78558 + help
78559 + Enabling this option will have the kernel automatically detect
78560 + and emulate the Procedure Linkage Table entries in ELF files.
78561 + On some architectures such entries are in writable memory, and
78562 + become non-executable leading to task termination. Therefore
78563 + it is mandatory that you enable this option on alpha, parisc,
78564 + sparc and sparc64, otherwise your system would not even boot.
78565 +
78566 + NOTE: this feature *does* open up a loophole in the protection
78567 + provided by the non-executable pages, therefore the proper
78568 + solution is to modify the toolchain to produce a PLT that does
78569 + not need to be writable.
78570 +
78571 +config PAX_DLRESOLVE
78572 + bool 'Emulate old glibc resolver stub'
78573 + depends on PAX_EMUPLT && SPARC
78574 + default n
78575 + help
78576 + This option is needed if userland has an old glibc (before 2.4)
78577 + that puts a 'save' instruction into the runtime generated resolver
78578 + stub that needs special emulation.
78579 +
78580 +config PAX_KERNEXEC
78581 + bool "Enforce non-executable kernel pages"
78582 + 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))
78583 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
78584 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
78585 + select PAX_KERNEXEC_PLUGIN if X86_64
78586 + help
78587 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
78588 + that is, enabling this option will make it harder to inject
78589 + and execute 'foreign' code in kernel memory itself.
78590 +
78591 + Note that on x86_64 kernels there is a known regression when
78592 + this feature and KVM/VMX are both enabled in the host kernel.
78593 +
78594 +choice
78595 + prompt "Return Address Instrumentation Method"
78596 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
78597 + depends on PAX_KERNEXEC_PLUGIN
78598 + help
78599 + Select the method used to instrument function pointer dereferences.
78600 + Note that binary modules cannot be instrumented by this approach.
78601 +
78602 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
78603 + bool "bts"
78604 + help
78605 + This method is compatible with binary only modules but has
78606 + a higher runtime overhead.
78607 +
78608 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
78609 + bool "or"
78610 + depends on !PARAVIRT
78611 + help
78612 + This method is incompatible with binary only modules but has
78613 + a lower runtime overhead.
78614 +endchoice
78615 +
78616 +config PAX_KERNEXEC_PLUGIN_METHOD
78617 + string
78618 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
78619 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
78620 + default ""
78621 +
78622 +config PAX_KERNEXEC_MODULE_TEXT
78623 + int "Minimum amount of memory reserved for module code"
78624 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
78625 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
78626 + depends on PAX_KERNEXEC && X86_32 && MODULES
78627 + help
78628 + Due to implementation details the kernel must reserve a fixed
78629 + amount of memory for module code at compile time that cannot be
78630 + changed at runtime. Here you can specify the minimum amount
78631 + in MB that will be reserved. Due to the same implementation
78632 + details this size will always be rounded up to the next 2/4 MB
78633 + boundary (depends on PAE) so the actually available memory for
78634 + module code will usually be more than this minimum.
78635 +
78636 + The default 4 MB should be enough for most users but if you have
78637 + an excessive number of modules (e.g., most distribution configs
78638 + compile many drivers as modules) or use huge modules such as
78639 + nvidia's kernel driver, you will need to adjust this amount.
78640 + A good rule of thumb is to look at your currently loaded kernel
78641 + modules and add up their sizes.
78642 +
78643 +endmenu
78644 +
78645 +menu "Address Space Layout Randomization"
78646 + depends on PAX
78647 +
78648 +config PAX_ASLR
78649 + bool "Address Space Layout Randomization"
78650 + default y if GRKERNSEC_CONFIG_AUTO
78651 + help
78652 + Many if not most exploit techniques rely on the knowledge of
78653 + certain addresses in the attacked program. The following options
78654 + will allow the kernel to apply a certain amount of randomization
78655 + to specific parts of the program thereby forcing an attacker to
78656 + guess them in most cases. Any failed guess will most likely crash
78657 + the attacked program which allows the kernel to detect such attempts
78658 + and react on them. PaX itself provides no reaction mechanisms,
78659 + instead it is strongly encouraged that you make use of Nergal's
78660 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
78661 + (http://www.grsecurity.net/) built-in crash detection features or
78662 + develop one yourself.
78663 +
78664 + By saying Y here you can choose to randomize the following areas:
78665 + - top of the task's kernel stack
78666 + - top of the task's userland stack
78667 + - base address for mmap() requests that do not specify one
78668 + (this includes all libraries)
78669 + - base address of the main executable
78670 +
78671 + It is strongly recommended to say Y here as address space layout
78672 + randomization has negligible impact on performance yet it provides
78673 + a very effective protection.
78674 +
78675 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
78676 + this feature on a per file basis.
78677 +
78678 +config PAX_RANDKSTACK
78679 + bool "Randomize kernel stack base"
78680 + default y if GRKERNSEC_CONFIG_AUTO
78681 + depends on X86_TSC && X86
78682 + help
78683 + By saying Y here the kernel will randomize every task's kernel
78684 + stack on every system call. This will not only force an attacker
78685 + to guess it but also prevent him from making use of possible
78686 + leaked information about it.
78687 +
78688 + Since the kernel stack is a rather scarce resource, randomization
78689 + may cause unexpected stack overflows, therefore you should very
78690 + carefully test your system. Note that once enabled in the kernel
78691 + configuration, this feature cannot be disabled on a per file basis.
78692 +
78693 +config PAX_RANDUSTACK
78694 + bool "Randomize user stack base"
78695 + default y if GRKERNSEC_CONFIG_AUTO
78696 + depends on PAX_ASLR
78697 + help
78698 + By saying Y here the kernel will randomize every task's userland
78699 + stack. The randomization is done in two steps where the second
78700 + one may apply a big amount of shift to the top of the stack and
78701 + cause problems for programs that want to use lots of memory (more
78702 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
78703 + For this reason the second step can be controlled by 'chpax' or
78704 + 'paxctl' on a per file basis.
78705 +
78706 +config PAX_RANDMMAP
78707 + bool "Randomize mmap() base"
78708 + default y if GRKERNSEC_CONFIG_AUTO
78709 + depends on PAX_ASLR
78710 + help
78711 + By saying Y here the kernel will use a randomized base address for
78712 + mmap() requests that do not specify one themselves. As a result
78713 + all dynamically loaded libraries will appear at random addresses
78714 + and therefore be harder to exploit by a technique where an attacker
78715 + attempts to execute library code for his purposes (e.g. spawn a
78716 + shell from an exploited program that is running at an elevated
78717 + privilege level).
78718 +
78719 + Furthermore, if a program is relinked as a dynamic ELF file, its
78720 + base address will be randomized as well, completing the full
78721 + randomization of the address space layout. Attacking such programs
78722 + becomes a guess game. You can find an example of doing this at
78723 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
78724 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
78725 +
78726 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
78727 + feature on a per file basis.
78728 +
78729 +endmenu
78730 +
78731 +menu "Miscellaneous hardening features"
78732 +
78733 +config PAX_MEMORY_SANITIZE
78734 + bool "Sanitize all freed memory"
78735 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
78736 + depends on !HIBERNATION
78737 + help
78738 + By saying Y here the kernel will erase memory pages as soon as they
78739 + are freed. This in turn reduces the lifetime of data stored in the
78740 + pages, making it less likely that sensitive information such as
78741 + passwords, cryptographic secrets, etc stay in memory for too long.
78742 +
78743 + This is especially useful for programs whose runtime is short, long
78744 + lived processes and the kernel itself benefit from this as long as
78745 + they operate on whole memory pages and ensure timely freeing of pages
78746 + that may hold sensitive information.
78747 +
78748 + The tradeoff is performance impact, on a single CPU system kernel
78749 + compilation sees a 3% slowdown, other systems and workloads may vary
78750 + and you are advised to test this feature on your expected workload
78751 + before deploying it.
78752 +
78753 + Note that this feature does not protect data stored in live pages,
78754 + e.g., process memory swapped to disk may stay there for a long time.
78755 +
78756 +config PAX_MEMORY_STACKLEAK
78757 + bool "Sanitize kernel stack"
78758 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
78759 + depends on X86
78760 + help
78761 + By saying Y here the kernel will erase the kernel stack before it
78762 + returns from a system call. This in turn reduces the information
78763 + that a kernel stack leak bug can reveal.
78764 +
78765 + Note that such a bug can still leak information that was put on
78766 + the stack by the current system call (the one eventually triggering
78767 + the bug) but traces of earlier system calls on the kernel stack
78768 + cannot leak anymore.
78769 +
78770 + The tradeoff is performance impact: on a single CPU system kernel
78771 + compilation sees a 1% slowdown, other systems and workloads may vary
78772 + and you are advised to test this feature on your expected workload
78773 + before deploying it.
78774 +
78775 + Note: full support for this feature requires gcc with plugin support
78776 + so make sure your compiler is at least gcc 4.5.0. Using older gcc
78777 + versions means that functions with large enough stack frames may
78778 + leave uninitialized memory behind that may be exposed to a later
78779 + syscall leaking the stack.
78780 +
78781 +config PAX_MEMORY_UDEREF
78782 + bool "Prevent invalid userland pointer dereference"
78783 + default y if GRKERNSEC_CONFIG_AUTO && (X86_32 || (X86_64 && GRKERNSEC_CONFIG_PRIORITY_SECURITY)) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
78784 + depends on X86 && !UML_X86 && !XEN
78785 + select PAX_PER_CPU_PGD if X86_64
78786 + help
78787 + By saying Y here the kernel will be prevented from dereferencing
78788 + userland pointers in contexts where the kernel expects only kernel
78789 + pointers. This is both a useful runtime debugging feature and a
78790 + security measure that prevents exploiting a class of kernel bugs.
78791 +
78792 + The tradeoff is that some virtualization solutions may experience
78793 + a huge slowdown and therefore you should not enable this feature
78794 + for kernels meant to run in such environments. Whether a given VM
78795 + solution is affected or not is best determined by simply trying it
78796 + out, the performance impact will be obvious right on boot as this
78797 + mechanism engages from very early on. A good rule of thumb is that
78798 + VMs running on CPUs without hardware virtualization support (i.e.,
78799 + the majority of IA-32 CPUs) will likely experience the slowdown.
78800 +
78801 +config PAX_REFCOUNT
78802 + bool "Prevent various kernel object reference counter overflows"
78803 + default y if GRKERNSEC_CONFIG_AUTO
78804 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
78805 + help
78806 + By saying Y here the kernel will detect and prevent overflowing
78807 + various (but not all) kinds of object reference counters. Such
78808 + overflows can normally occur due to bugs only and are often, if
78809 + not always, exploitable.
78810 +
78811 + The tradeoff is that data structures protected by an overflowed
78812 + refcount will never be freed and therefore will leak memory. Note
78813 + that this leak also happens even without this protection but in
78814 + that case the overflow can eventually trigger the freeing of the
78815 + data structure while it is still being used elsewhere, resulting
78816 + in the exploitable situation that this feature prevents.
78817 +
78818 + Since this has a negligible performance impact, you should enable
78819 + this feature.
78820 +
78821 +config PAX_USERCOPY
78822 + bool "Harden heap object copies between kernel and userland"
78823 + default y if GRKERNSEC_CONFIG_AUTO
78824 + depends on X86 || PPC || SPARC || ARM
78825 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
78826 + help
78827 + By saying Y here the kernel will enforce the size of heap objects
78828 + when they are copied in either direction between the kernel and
78829 + userland, even if only a part of the heap object is copied.
78830 +
78831 + Specifically, this checking prevents information leaking from the
78832 + kernel heap during kernel to userland copies (if the kernel heap
78833 + object is otherwise fully initialized) and prevents kernel heap
78834 + overflows during userland to kernel copies.
78835 +
78836 + Note that the current implementation provides the strictest bounds
78837 + checks for the SLUB allocator.
78838 +
78839 + Enabling this option also enables per-slab cache protection against
78840 + data in a given cache being copied into/out of via userland
78841 + accessors. Though the whitelist of regions will be reduced over
78842 + time, it notably protects important data structures like task structs.
78843 +
78844 + If frame pointers are enabled on x86, this option will also restrict
78845 + copies into and out of the kernel stack to local variables within a
78846 + single frame.
78847 +
78848 + Since this has a negligible performance impact, you should enable
78849 + this feature.
78850 +
78851 +config PAX_SIZE_OVERFLOW
78852 + bool "Prevent various integer overflows in function size parameters"
78853 + default y if GRKERNSEC_CONFIG_AUTO
78854 + depends on X86
78855 + help
78856 + By saying Y here the kernel recomputes expressions of function
78857 + arguments marked by a size_overflow attribute with double integer
78858 + precision (DImode/TImode for 32/64 bit integer types).
78859 +
78860 + The recomputed argument is checked against INT_MAX and an event
78861 + is logged on overflow and the triggering process is killed.
78862 +
78863 + Homepage:
78864 + http://www.grsecurity.net/~ephox/overflow_plugin/
78865 +
78866 +endmenu
78867 +
78868 +endmenu
78869 +
78870 +source grsecurity/Kconfig
78871 +
78872 +endmenu
78873 +
78874 +endmenu
78875 +
78876 config KEYS
78877 bool "Enable access key retention support"
78878 help
78879 @@ -169,7 +1024,7 @@ config INTEL_TXT
78880 config LSM_MMAP_MIN_ADDR
78881 int "Low address space for LSM to protect from user allocation"
78882 depends on SECURITY && SECURITY_SELINUX
78883 - default 32768 if ARM
78884 + default 32768 if ALPHA || ARM || PARISC || SPARC32
78885 default 65536
78886 help
78887 This is the portion of low virtual memory which should be protected
78888 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
78889 index ad05d39..afffccb 100644
78890 --- a/security/apparmor/lsm.c
78891 +++ b/security/apparmor/lsm.c
78892 @@ -622,7 +622,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
78893 return error;
78894 }
78895
78896 -static struct security_operations apparmor_ops = {
78897 +static struct security_operations apparmor_ops __read_only = {
78898 .name = "apparmor",
78899
78900 .ptrace_access_check = apparmor_ptrace_access_check,
78901 diff --git a/security/commoncap.c b/security/commoncap.c
78902 index 71a166a..851bb3e 100644
78903 --- a/security/commoncap.c
78904 +++ b/security/commoncap.c
78905 @@ -576,6 +576,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
78906 {
78907 const struct cred *cred = current_cred();
78908
78909 + if (gr_acl_enable_at_secure())
78910 + return 1;
78911 +
78912 if (cred->uid != 0) {
78913 if (bprm->cap_effective)
78914 return 1;
78915 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
78916 index 3ccf7ac..d73ad64 100644
78917 --- a/security/integrity/ima/ima.h
78918 +++ b/security/integrity/ima/ima.h
78919 @@ -86,8 +86,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
78920 extern spinlock_t ima_queue_lock;
78921
78922 struct ima_h_table {
78923 - atomic_long_t len; /* number of stored measurements in the list */
78924 - atomic_long_t violations;
78925 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
78926 + atomic_long_unchecked_t violations;
78927 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
78928 };
78929 extern struct ima_h_table ima_htable;
78930 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
78931 index 88a2788..581ab92 100644
78932 --- a/security/integrity/ima/ima_api.c
78933 +++ b/security/integrity/ima/ima_api.c
78934 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
78935 int result;
78936
78937 /* can overflow, only indicator */
78938 - atomic_long_inc(&ima_htable.violations);
78939 + atomic_long_inc_unchecked(&ima_htable.violations);
78940
78941 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
78942 if (!entry) {
78943 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
78944 index e1aa2b4..52027bf 100644
78945 --- a/security/integrity/ima/ima_fs.c
78946 +++ b/security/integrity/ima/ima_fs.c
78947 @@ -28,12 +28,12 @@
78948 static int valid_policy = 1;
78949 #define TMPBUFLEN 12
78950 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
78951 - loff_t *ppos, atomic_long_t *val)
78952 + loff_t *ppos, atomic_long_unchecked_t *val)
78953 {
78954 char tmpbuf[TMPBUFLEN];
78955 ssize_t len;
78956
78957 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
78958 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
78959 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
78960 }
78961
78962 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
78963 index 55a6271..ad829c3 100644
78964 --- a/security/integrity/ima/ima_queue.c
78965 +++ b/security/integrity/ima/ima_queue.c
78966 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
78967 INIT_LIST_HEAD(&qe->later);
78968 list_add_tail_rcu(&qe->later, &ima_measurements);
78969
78970 - atomic_long_inc(&ima_htable.len);
78971 + atomic_long_inc_unchecked(&ima_htable.len);
78972 key = ima_hash_key(entry->digest);
78973 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
78974 return 0;
78975 diff --git a/security/keys/compat.c b/security/keys/compat.c
78976 index 4c48e13..7abdac9 100644
78977 --- a/security/keys/compat.c
78978 +++ b/security/keys/compat.c
78979 @@ -44,7 +44,7 @@ long compat_keyctl_instantiate_key_iov(
78980 if (ret == 0)
78981 goto no_payload_free;
78982
78983 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
78984 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
78985
78986 if (iov != iovstack)
78987 kfree(iov);
78988 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
78989 index fb767c6..b9c49c0 100644
78990 --- a/security/keys/keyctl.c
78991 +++ b/security/keys/keyctl.c
78992 @@ -935,7 +935,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
78993 /*
78994 * Copy the iovec data from userspace
78995 */
78996 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
78997 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
78998 unsigned ioc)
78999 {
79000 for (; ioc > 0; ioc--) {
79001 @@ -957,7 +957,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
79002 * If successful, 0 will be returned.
79003 */
79004 long keyctl_instantiate_key_common(key_serial_t id,
79005 - const struct iovec *payload_iov,
79006 + const struct iovec __user *payload_iov,
79007 unsigned ioc,
79008 size_t plen,
79009 key_serial_t ringid)
79010 @@ -1052,7 +1052,7 @@ long keyctl_instantiate_key(key_serial_t id,
79011 [0].iov_len = plen
79012 };
79013
79014 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
79015 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
79016 }
79017
79018 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
79019 @@ -1085,7 +1085,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
79020 if (ret == 0)
79021 goto no_payload_free;
79022
79023 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
79024 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
79025
79026 if (iov != iovstack)
79027 kfree(iov);
79028 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
79029 index d605f75..2bc6be9 100644
79030 --- a/security/keys/keyring.c
79031 +++ b/security/keys/keyring.c
79032 @@ -214,15 +214,15 @@ static long keyring_read(const struct key *keyring,
79033 ret = -EFAULT;
79034
79035 for (loop = 0; loop < klist->nkeys; loop++) {
79036 + key_serial_t serial;
79037 key = klist->keys[loop];
79038 + serial = key->serial;
79039
79040 tmp = sizeof(key_serial_t);
79041 if (tmp > buflen)
79042 tmp = buflen;
79043
79044 - if (copy_to_user(buffer,
79045 - &key->serial,
79046 - tmp) != 0)
79047 + if (copy_to_user(buffer, &serial, tmp))
79048 goto error;
79049
79050 buflen -= tmp;
79051 diff --git a/security/min_addr.c b/security/min_addr.c
79052 index f728728..6457a0c 100644
79053 --- a/security/min_addr.c
79054 +++ b/security/min_addr.c
79055 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
79056 */
79057 static void update_mmap_min_addr(void)
79058 {
79059 +#ifndef SPARC
79060 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
79061 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
79062 mmap_min_addr = dac_mmap_min_addr;
79063 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
79064 #else
79065 mmap_min_addr = dac_mmap_min_addr;
79066 #endif
79067 +#endif
79068 }
79069
79070 /*
79071 diff --git a/security/security.c b/security/security.c
79072 index bf619ff..8179030 100644
79073 --- a/security/security.c
79074 +++ b/security/security.c
79075 @@ -20,6 +20,7 @@
79076 #include <linux/ima.h>
79077 #include <linux/evm.h>
79078 #include <linux/fsnotify.h>
79079 +#include <linux/mm.h>
79080 #include <net/flow.h>
79081
79082 #define MAX_LSM_EVM_XATTR 2
79083 @@ -28,8 +29,8 @@
79084 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
79085 CONFIG_DEFAULT_SECURITY;
79086
79087 -static struct security_operations *security_ops;
79088 -static struct security_operations default_security_ops = {
79089 +static struct security_operations *security_ops __read_only;
79090 +static struct security_operations default_security_ops __read_only = {
79091 .name = "default",
79092 };
79093
79094 @@ -70,7 +71,9 @@ int __init security_init(void)
79095
79096 void reset_security_ops(void)
79097 {
79098 + pax_open_kernel();
79099 security_ops = &default_security_ops;
79100 + pax_close_kernel();
79101 }
79102
79103 /* Save user chosen LSM */
79104 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
79105 index d85b793..a164832 100644
79106 --- a/security/selinux/hooks.c
79107 +++ b/security/selinux/hooks.c
79108 @@ -95,8 +95,6 @@
79109
79110 #define NUM_SEL_MNT_OPTS 5
79111
79112 -extern struct security_operations *security_ops;
79113 -
79114 /* SECMARK reference count */
79115 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
79116
79117 @@ -5520,7 +5518,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
79118
79119 #endif
79120
79121 -static struct security_operations selinux_ops = {
79122 +static struct security_operations selinux_ops __read_only = {
79123 .name = "selinux",
79124
79125 .ptrace_access_check = selinux_ptrace_access_check,
79126 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
79127 index c220f31..89fab3f 100644
79128 --- a/security/selinux/include/xfrm.h
79129 +++ b/security/selinux/include/xfrm.h
79130 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
79131
79132 static inline void selinux_xfrm_notify_policyload(void)
79133 {
79134 - atomic_inc(&flow_cache_genid);
79135 + atomic_inc_unchecked(&flow_cache_genid);
79136 }
79137 #else
79138 static inline int selinux_xfrm_enabled(void)
79139 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
79140 index 45c32f0..0038be2 100644
79141 --- a/security/smack/smack_lsm.c
79142 +++ b/security/smack/smack_lsm.c
79143 @@ -3500,7 +3500,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
79144 return 0;
79145 }
79146
79147 -struct security_operations smack_ops = {
79148 +struct security_operations smack_ops __read_only = {
79149 .name = "smack",
79150
79151 .ptrace_access_check = smack_ptrace_access_check,
79152 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
79153 index 620d37c..e2ad89b 100644
79154 --- a/security/tomoyo/tomoyo.c
79155 +++ b/security/tomoyo/tomoyo.c
79156 @@ -501,7 +501,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
79157 * tomoyo_security_ops is a "struct security_operations" which is used for
79158 * registering TOMOYO.
79159 */
79160 -static struct security_operations tomoyo_security_ops = {
79161 +static struct security_operations tomoyo_security_ops __read_only = {
79162 .name = "tomoyo",
79163 .cred_alloc_blank = tomoyo_cred_alloc_blank,
79164 .cred_prepare = tomoyo_cred_prepare,
79165 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
79166 index 51d6709..1f3dbe2 100644
79167 --- a/security/yama/Kconfig
79168 +++ b/security/yama/Kconfig
79169 @@ -1,6 +1,6 @@
79170 config SECURITY_YAMA
79171 bool "Yama support"
79172 - depends on SECURITY
79173 + depends on SECURITY && !GRKERNSEC
79174 select SECURITYFS
79175 select SECURITY_PATH
79176 default n
79177 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
79178 index 270790d..c67dfcb 100644
79179 --- a/sound/aoa/codecs/onyx.c
79180 +++ b/sound/aoa/codecs/onyx.c
79181 @@ -54,7 +54,7 @@ struct onyx {
79182 spdif_locked:1,
79183 analog_locked:1,
79184 original_mute:2;
79185 - int open_count;
79186 + local_t open_count;
79187 struct codec_info *codec_info;
79188
79189 /* mutex serializes concurrent access to the device
79190 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
79191 struct onyx *onyx = cii->codec_data;
79192
79193 mutex_lock(&onyx->mutex);
79194 - onyx->open_count++;
79195 + local_inc(&onyx->open_count);
79196 mutex_unlock(&onyx->mutex);
79197
79198 return 0;
79199 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
79200 struct onyx *onyx = cii->codec_data;
79201
79202 mutex_lock(&onyx->mutex);
79203 - onyx->open_count--;
79204 - if (!onyx->open_count)
79205 + if (local_dec_and_test(&onyx->open_count))
79206 onyx->spdif_locked = onyx->analog_locked = 0;
79207 mutex_unlock(&onyx->mutex);
79208
79209 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
79210 index ffd2025..df062c9 100644
79211 --- a/sound/aoa/codecs/onyx.h
79212 +++ b/sound/aoa/codecs/onyx.h
79213 @@ -11,6 +11,7 @@
79214 #include <linux/i2c.h>
79215 #include <asm/pmac_low_i2c.h>
79216 #include <asm/prom.h>
79217 +#include <asm/local.h>
79218
79219 /* PCM3052 register definitions */
79220
79221 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
79222 index 08fde00..0bf641a 100644
79223 --- a/sound/core/oss/pcm_oss.c
79224 +++ b/sound/core/oss/pcm_oss.c
79225 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
79226 if (in_kernel) {
79227 mm_segment_t fs;
79228 fs = snd_enter_user();
79229 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
79230 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
79231 snd_leave_user(fs);
79232 } else {
79233 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
79234 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
79235 }
79236 if (ret != -EPIPE && ret != -ESTRPIPE)
79237 break;
79238 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
79239 if (in_kernel) {
79240 mm_segment_t fs;
79241 fs = snd_enter_user();
79242 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
79243 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
79244 snd_leave_user(fs);
79245 } else {
79246 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
79247 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
79248 }
79249 if (ret == -EPIPE) {
79250 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
79251 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
79252 struct snd_pcm_plugin_channel *channels;
79253 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
79254 if (!in_kernel) {
79255 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
79256 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
79257 return -EFAULT;
79258 buf = runtime->oss.buffer;
79259 }
79260 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
79261 }
79262 } else {
79263 tmp = snd_pcm_oss_write2(substream,
79264 - (const char __force *)buf,
79265 + (const char __force_kernel *)buf,
79266 runtime->oss.period_bytes, 0);
79267 if (tmp <= 0)
79268 goto err;
79269 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
79270 struct snd_pcm_runtime *runtime = substream->runtime;
79271 snd_pcm_sframes_t frames, frames1;
79272 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
79273 - char __user *final_dst = (char __force __user *)buf;
79274 + char __user *final_dst = (char __force_user *)buf;
79275 if (runtime->oss.plugin_first) {
79276 struct snd_pcm_plugin_channel *channels;
79277 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
79278 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
79279 xfer += tmp;
79280 runtime->oss.buffer_used -= tmp;
79281 } else {
79282 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
79283 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
79284 runtime->oss.period_bytes, 0);
79285 if (tmp <= 0)
79286 goto err;
79287 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
79288 size1);
79289 size1 /= runtime->channels; /* frames */
79290 fs = snd_enter_user();
79291 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
79292 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
79293 snd_leave_user(fs);
79294 }
79295 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
79296 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
79297 index 91cdf94..4085161 100644
79298 --- a/sound/core/pcm_compat.c
79299 +++ b/sound/core/pcm_compat.c
79300 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
79301 int err;
79302
79303 fs = snd_enter_user();
79304 - err = snd_pcm_delay(substream, &delay);
79305 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
79306 snd_leave_user(fs);
79307 if (err < 0)
79308 return err;
79309 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
79310 index 3fe99e6..26952e4 100644
79311 --- a/sound/core/pcm_native.c
79312 +++ b/sound/core/pcm_native.c
79313 @@ -2770,11 +2770,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
79314 switch (substream->stream) {
79315 case SNDRV_PCM_STREAM_PLAYBACK:
79316 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
79317 - (void __user *)arg);
79318 + (void __force_user *)arg);
79319 break;
79320 case SNDRV_PCM_STREAM_CAPTURE:
79321 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
79322 - (void __user *)arg);
79323 + (void __force_user *)arg);
79324 break;
79325 default:
79326 result = -EINVAL;
79327 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
79328 index 5cf8d65..912a79c 100644
79329 --- a/sound/core/seq/seq_device.c
79330 +++ b/sound/core/seq/seq_device.c
79331 @@ -64,7 +64,7 @@ struct ops_list {
79332 int argsize; /* argument size */
79333
79334 /* operators */
79335 - struct snd_seq_dev_ops ops;
79336 + struct snd_seq_dev_ops *ops;
79337
79338 /* registred devices */
79339 struct list_head dev_list; /* list of devices */
79340 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
79341
79342 mutex_lock(&ops->reg_mutex);
79343 /* copy driver operators */
79344 - ops->ops = *entry;
79345 + ops->ops = entry;
79346 ops->driver |= DRIVER_LOADED;
79347 ops->argsize = argsize;
79348
79349 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
79350 dev->name, ops->id, ops->argsize, dev->argsize);
79351 return -EINVAL;
79352 }
79353 - if (ops->ops.init_device(dev) >= 0) {
79354 + if (ops->ops->init_device(dev) >= 0) {
79355 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
79356 ops->num_init_devices++;
79357 } else {
79358 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
79359 dev->name, ops->id, ops->argsize, dev->argsize);
79360 return -EINVAL;
79361 }
79362 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
79363 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
79364 dev->status = SNDRV_SEQ_DEVICE_FREE;
79365 dev->driver_data = NULL;
79366 ops->num_init_devices--;
79367 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
79368 index 621e60e..f4543f5 100644
79369 --- a/sound/drivers/mts64.c
79370 +++ b/sound/drivers/mts64.c
79371 @@ -29,6 +29,7 @@
79372 #include <sound/initval.h>
79373 #include <sound/rawmidi.h>
79374 #include <sound/control.h>
79375 +#include <asm/local.h>
79376
79377 #define CARD_NAME "Miditerminal 4140"
79378 #define DRIVER_NAME "MTS64"
79379 @@ -67,7 +68,7 @@ struct mts64 {
79380 struct pardevice *pardev;
79381 int pardev_claimed;
79382
79383 - int open_count;
79384 + local_t open_count;
79385 int current_midi_output_port;
79386 int current_midi_input_port;
79387 u8 mode[MTS64_NUM_INPUT_PORTS];
79388 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
79389 {
79390 struct mts64 *mts = substream->rmidi->private_data;
79391
79392 - if (mts->open_count == 0) {
79393 + if (local_read(&mts->open_count) == 0) {
79394 /* We don't need a spinlock here, because this is just called
79395 if the device has not been opened before.
79396 So there aren't any IRQs from the device */
79397 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
79398
79399 msleep(50);
79400 }
79401 - ++(mts->open_count);
79402 + local_inc(&mts->open_count);
79403
79404 return 0;
79405 }
79406 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
79407 struct mts64 *mts = substream->rmidi->private_data;
79408 unsigned long flags;
79409
79410 - --(mts->open_count);
79411 - if (mts->open_count == 0) {
79412 + if (local_dec_return(&mts->open_count) == 0) {
79413 /* We need the spinlock_irqsave here because we can still
79414 have IRQs at this point */
79415 spin_lock_irqsave(&mts->lock, flags);
79416 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
79417
79418 msleep(500);
79419
79420 - } else if (mts->open_count < 0)
79421 - mts->open_count = 0;
79422 + } else if (local_read(&mts->open_count) < 0)
79423 + local_set(&mts->open_count, 0);
79424
79425 return 0;
79426 }
79427 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
79428 index b953fb4..1999c01 100644
79429 --- a/sound/drivers/opl4/opl4_lib.c
79430 +++ b/sound/drivers/opl4/opl4_lib.c
79431 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
79432 MODULE_DESCRIPTION("OPL4 driver");
79433 MODULE_LICENSE("GPL");
79434
79435 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
79436 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
79437 {
79438 int timeout = 10;
79439 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
79440 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
79441 index 3e32bd3..46fc152 100644
79442 --- a/sound/drivers/portman2x4.c
79443 +++ b/sound/drivers/portman2x4.c
79444 @@ -48,6 +48,7 @@
79445 #include <sound/initval.h>
79446 #include <sound/rawmidi.h>
79447 #include <sound/control.h>
79448 +#include <asm/local.h>
79449
79450 #define CARD_NAME "Portman 2x4"
79451 #define DRIVER_NAME "portman"
79452 @@ -85,7 +86,7 @@ struct portman {
79453 struct pardevice *pardev;
79454 int pardev_claimed;
79455
79456 - int open_count;
79457 + local_t open_count;
79458 int mode[PORTMAN_NUM_INPUT_PORTS];
79459 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
79460 };
79461 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
79462 index 87657dd..a8268d4 100644
79463 --- a/sound/firewire/amdtp.c
79464 +++ b/sound/firewire/amdtp.c
79465 @@ -371,7 +371,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
79466 ptr = s->pcm_buffer_pointer + data_blocks;
79467 if (ptr >= pcm->runtime->buffer_size)
79468 ptr -= pcm->runtime->buffer_size;
79469 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
79470 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
79471
79472 s->pcm_period_pointer += data_blocks;
79473 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
79474 @@ -511,7 +511,7 @@ EXPORT_SYMBOL(amdtp_out_stream_start);
79475 */
79476 void amdtp_out_stream_update(struct amdtp_out_stream *s)
79477 {
79478 - ACCESS_ONCE(s->source_node_id_field) =
79479 + ACCESS_ONCE_RW(s->source_node_id_field) =
79480 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
79481 }
79482 EXPORT_SYMBOL(amdtp_out_stream_update);
79483 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
79484 index 537a9cb..8e8c8e9 100644
79485 --- a/sound/firewire/amdtp.h
79486 +++ b/sound/firewire/amdtp.h
79487 @@ -146,7 +146,7 @@ static inline void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s)
79488 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
79489 struct snd_pcm_substream *pcm)
79490 {
79491 - ACCESS_ONCE(s->pcm) = pcm;
79492 + ACCESS_ONCE_RW(s->pcm) = pcm;
79493 }
79494
79495 /**
79496 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
79497 index d428ffe..751ef78 100644
79498 --- a/sound/firewire/isight.c
79499 +++ b/sound/firewire/isight.c
79500 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
79501 ptr += count;
79502 if (ptr >= runtime->buffer_size)
79503 ptr -= runtime->buffer_size;
79504 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
79505 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
79506
79507 isight->period_counter += count;
79508 if (isight->period_counter >= runtime->period_size) {
79509 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
79510 if (err < 0)
79511 return err;
79512
79513 - ACCESS_ONCE(isight->pcm_active) = true;
79514 + ACCESS_ONCE_RW(isight->pcm_active) = true;
79515
79516 return 0;
79517 }
79518 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
79519 {
79520 struct isight *isight = substream->private_data;
79521
79522 - ACCESS_ONCE(isight->pcm_active) = false;
79523 + ACCESS_ONCE_RW(isight->pcm_active) = false;
79524
79525 mutex_lock(&isight->mutex);
79526 isight_stop_streaming(isight);
79527 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
79528
79529 switch (cmd) {
79530 case SNDRV_PCM_TRIGGER_START:
79531 - ACCESS_ONCE(isight->pcm_running) = true;
79532 + ACCESS_ONCE_RW(isight->pcm_running) = true;
79533 break;
79534 case SNDRV_PCM_TRIGGER_STOP:
79535 - ACCESS_ONCE(isight->pcm_running) = false;
79536 + ACCESS_ONCE_RW(isight->pcm_running) = false;
79537 break;
79538 default:
79539 return -EINVAL;
79540 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
79541 index 7bd5e33..1fcab12 100644
79542 --- a/sound/isa/cmi8330.c
79543 +++ b/sound/isa/cmi8330.c
79544 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
79545
79546 struct snd_pcm *pcm;
79547 struct snd_cmi8330_stream {
79548 - struct snd_pcm_ops ops;
79549 + snd_pcm_ops_no_const ops;
79550 snd_pcm_open_callback_t open;
79551 void *private_data; /* sb or wss */
79552 } streams[2];
79553 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
79554 index 733b014..56ce96f 100644
79555 --- a/sound/oss/sb_audio.c
79556 +++ b/sound/oss/sb_audio.c
79557 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
79558 buf16 = (signed short *)(localbuf + localoffs);
79559 while (c)
79560 {
79561 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
79562 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
79563 if (copy_from_user(lbuf8,
79564 userbuf+useroffs + p,
79565 locallen))
79566 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
79567 index 09d4648..cf234c7 100644
79568 --- a/sound/oss/swarm_cs4297a.c
79569 +++ b/sound/oss/swarm_cs4297a.c
79570 @@ -2606,7 +2606,6 @@ static int __init cs4297a_init(void)
79571 {
79572 struct cs4297a_state *s;
79573 u32 pwr, id;
79574 - mm_segment_t fs;
79575 int rval;
79576 #ifndef CONFIG_BCM_CS4297A_CSWARM
79577 u64 cfg;
79578 @@ -2696,22 +2695,23 @@ static int __init cs4297a_init(void)
79579 if (!rval) {
79580 char *sb1250_duart_present;
79581
79582 +#if 0
79583 + mm_segment_t fs;
79584 fs = get_fs();
79585 set_fs(KERNEL_DS);
79586 -#if 0
79587 val = SOUND_MASK_LINE;
79588 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
79589 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
79590 val = initvol[i].vol;
79591 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
79592 }
79593 + set_fs(fs);
79594 // cs4297a_write_ac97(s, 0x18, 0x0808);
79595 #else
79596 // cs4297a_write_ac97(s, 0x5e, 0x180);
79597 cs4297a_write_ac97(s, 0x02, 0x0808);
79598 cs4297a_write_ac97(s, 0x18, 0x0808);
79599 #endif
79600 - set_fs(fs);
79601
79602 list_add(&s->list, &cs4297a_devs);
79603
79604 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
79605 index 56b4f74..7cfd41a 100644
79606 --- a/sound/pci/hda/hda_codec.h
79607 +++ b/sound/pci/hda/hda_codec.h
79608 @@ -611,7 +611,7 @@ struct hda_bus_ops {
79609 /* notify power-up/down from codec to controller */
79610 void (*pm_notify)(struct hda_bus *bus);
79611 #endif
79612 -};
79613 +} __no_const;
79614
79615 /* template to pass to the bus constructor */
79616 struct hda_bus_template {
79617 @@ -713,6 +713,7 @@ struct hda_codec_ops {
79618 #endif
79619 void (*reboot_notify)(struct hda_codec *codec);
79620 };
79621 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
79622
79623 /* record for amp information cache */
79624 struct hda_cache_head {
79625 @@ -743,7 +744,7 @@ struct hda_pcm_ops {
79626 struct snd_pcm_substream *substream);
79627 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
79628 struct snd_pcm_substream *substream);
79629 -};
79630 +} __no_const;
79631
79632 /* PCM information for each substream */
79633 struct hda_pcm_stream {
79634 @@ -801,7 +802,7 @@ struct hda_codec {
79635 const char *modelname; /* model name for preset */
79636
79637 /* set by patch */
79638 - struct hda_codec_ops patch_ops;
79639 + hda_codec_ops_no_const patch_ops;
79640
79641 /* PCM to create, set by patch_ops.build_pcms callback */
79642 unsigned int num_pcms;
79643 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
79644 index 0da778a..bc38b84 100644
79645 --- a/sound/pci/ice1712/ice1712.h
79646 +++ b/sound/pci/ice1712/ice1712.h
79647 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
79648 unsigned int mask_flags; /* total mask bits */
79649 struct snd_akm4xxx_ops {
79650 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
79651 - } ops;
79652 + } __no_const ops;
79653 };
79654
79655 struct snd_ice1712_spdif {
79656 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
79657 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
79658 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
79659 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
79660 - } ops;
79661 + } __no_const ops;
79662 };
79663
79664
79665 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
79666 index a8159b81..5f006a5 100644
79667 --- a/sound/pci/ymfpci/ymfpci_main.c
79668 +++ b/sound/pci/ymfpci/ymfpci_main.c
79669 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
79670 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
79671 break;
79672 }
79673 - if (atomic_read(&chip->interrupt_sleep_count)) {
79674 - atomic_set(&chip->interrupt_sleep_count, 0);
79675 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
79676 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
79677 wake_up(&chip->interrupt_sleep);
79678 }
79679 __end:
79680 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
79681 continue;
79682 init_waitqueue_entry(&wait, current);
79683 add_wait_queue(&chip->interrupt_sleep, &wait);
79684 - atomic_inc(&chip->interrupt_sleep_count);
79685 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
79686 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
79687 remove_wait_queue(&chip->interrupt_sleep, &wait);
79688 }
79689 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
79690 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
79691 spin_unlock(&chip->reg_lock);
79692
79693 - if (atomic_read(&chip->interrupt_sleep_count)) {
79694 - atomic_set(&chip->interrupt_sleep_count, 0);
79695 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
79696 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
79697 wake_up(&chip->interrupt_sleep);
79698 }
79699 }
79700 @@ -2398,7 +2398,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
79701 spin_lock_init(&chip->reg_lock);
79702 spin_lock_init(&chip->voice_lock);
79703 init_waitqueue_head(&chip->interrupt_sleep);
79704 - atomic_set(&chip->interrupt_sleep_count, 0);
79705 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
79706 chip->card = card;
79707 chip->pci = pci;
79708 chip->irq = -1;
79709 diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
79710 index 0ad8dca..7186339 100644
79711 --- a/sound/soc/soc-pcm.c
79712 +++ b/sound/soc/soc-pcm.c
79713 @@ -641,7 +641,7 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
79714 struct snd_soc_platform *platform = rtd->platform;
79715 struct snd_soc_dai *codec_dai = rtd->codec_dai;
79716 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
79717 - struct snd_pcm_ops *soc_pcm_ops = &rtd->ops;
79718 + snd_pcm_ops_no_const *soc_pcm_ops = &rtd->ops;
79719 struct snd_pcm *pcm;
79720 char new_name[64];
79721 int ret = 0, playback = 0, capture = 0;
79722 diff --git a/sound/usb/card.h b/sound/usb/card.h
79723 index da5fa1a..113cd02 100644
79724 --- a/sound/usb/card.h
79725 +++ b/sound/usb/card.h
79726 @@ -45,6 +45,7 @@ struct snd_urb_ops {
79727 int (*prepare_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
79728 int (*retire_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
79729 };
79730 +typedef struct snd_urb_ops __no_const snd_urb_ops_no_const;
79731
79732 struct snd_usb_substream {
79733 struct snd_usb_stream *stream;
79734 @@ -94,7 +95,7 @@ struct snd_usb_substream {
79735 struct snd_pcm_hw_constraint_list rate_list; /* limited rates */
79736 spinlock_t lock;
79737
79738 - struct snd_urb_ops ops; /* callbacks (must be filled at init) */
79739 + snd_urb_ops_no_const ops; /* callbacks (must be filled at init) */
79740 int last_frame_number; /* stored frame number */
79741 int last_delay; /* stored delay */
79742 };
79743 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
79744 new file mode 100644
79745 index 0000000..f4f9986
79746 --- /dev/null
79747 +++ b/tools/gcc/Makefile
79748 @@ -0,0 +1,41 @@
79749 +#CC := gcc
79750 +#PLUGIN_SOURCE_FILES := pax_plugin.c
79751 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
79752 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
79753 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
79754 +
79755 +ifeq ($(PLUGINCC),$(HOSTCC))
79756 +HOSTLIBS := hostlibs
79757 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
79758 +else
79759 +HOSTLIBS := hostcxxlibs
79760 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
79761 +endif
79762 +
79763 +$(HOSTLIBS)-y := constify_plugin.so
79764 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
79765 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
79766 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
79767 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
79768 +$(HOSTLIBS)-y += colorize_plugin.so
79769 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
79770 +
79771 +always := $($(HOSTLIBS)-y)
79772 +
79773 +constify_plugin-objs := constify_plugin.o
79774 +stackleak_plugin-objs := stackleak_plugin.o
79775 +kallocstat_plugin-objs := kallocstat_plugin.o
79776 +kernexec_plugin-objs := kernexec_plugin.o
79777 +checker_plugin-objs := checker_plugin.o
79778 +colorize_plugin-objs := colorize_plugin.o
79779 +size_overflow_plugin-objs := size_overflow_plugin.o
79780 +
79781 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
79782 +
79783 +quiet_cmd_build_size_overflow_hash = GENHASH $@
79784 + cmd_build_size_overflow_hash = \
79785 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
79786 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
79787 + $(call if_changed,build_size_overflow_hash)
79788 +
79789 +targets += size_overflow_hash.h
79790 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
79791 new file mode 100644
79792 index 0000000..d41b5af
79793 --- /dev/null
79794 +++ b/tools/gcc/checker_plugin.c
79795 @@ -0,0 +1,171 @@
79796 +/*
79797 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
79798 + * Licensed under the GPL v2
79799 + *
79800 + * Note: the choice of the license means that the compilation process is
79801 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
79802 + * but for the kernel it doesn't matter since it doesn't link against
79803 + * any of the gcc libraries
79804 + *
79805 + * gcc plugin to implement various sparse (source code checker) features
79806 + *
79807 + * TODO:
79808 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
79809 + *
79810 + * BUGS:
79811 + * - none known
79812 + */
79813 +#include "gcc-plugin.h"
79814 +#include "config.h"
79815 +#include "system.h"
79816 +#include "coretypes.h"
79817 +#include "tree.h"
79818 +#include "tree-pass.h"
79819 +#include "flags.h"
79820 +#include "intl.h"
79821 +#include "toplev.h"
79822 +#include "plugin.h"
79823 +//#include "expr.h" where are you...
79824 +#include "diagnostic.h"
79825 +#include "plugin-version.h"
79826 +#include "tm.h"
79827 +#include "function.h"
79828 +#include "basic-block.h"
79829 +#include "gimple.h"
79830 +#include "rtl.h"
79831 +#include "emit-rtl.h"
79832 +#include "tree-flow.h"
79833 +#include "target.h"
79834 +
79835 +extern void c_register_addr_space (const char *str, addr_space_t as);
79836 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
79837 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
79838 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
79839 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
79840 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
79841 +
79842 +extern void print_gimple_stmt(FILE *, gimple, int, int);
79843 +extern rtx emit_move_insn(rtx x, rtx y);
79844 +
79845 +int plugin_is_GPL_compatible;
79846 +
79847 +static struct plugin_info checker_plugin_info = {
79848 + .version = "201111150100",
79849 +};
79850 +
79851 +#define ADDR_SPACE_KERNEL 0
79852 +#define ADDR_SPACE_FORCE_KERNEL 1
79853 +#define ADDR_SPACE_USER 2
79854 +#define ADDR_SPACE_FORCE_USER 3
79855 +#define ADDR_SPACE_IOMEM 0
79856 +#define ADDR_SPACE_FORCE_IOMEM 0
79857 +#define ADDR_SPACE_PERCPU 0
79858 +#define ADDR_SPACE_FORCE_PERCPU 0
79859 +#define ADDR_SPACE_RCU 0
79860 +#define ADDR_SPACE_FORCE_RCU 0
79861 +
79862 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
79863 +{
79864 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
79865 +}
79866 +
79867 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
79868 +{
79869 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
79870 +}
79871 +
79872 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
79873 +{
79874 + return default_addr_space_valid_pointer_mode(mode, as);
79875 +}
79876 +
79877 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
79878 +{
79879 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
79880 +}
79881 +
79882 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
79883 +{
79884 + return default_addr_space_legitimize_address(x, oldx, mode, as);
79885 +}
79886 +
79887 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
79888 +{
79889 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
79890 + return true;
79891 +
79892 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
79893 + return true;
79894 +
79895 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
79896 + return true;
79897 +
79898 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
79899 + return true;
79900 +
79901 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
79902 + return true;
79903 +
79904 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
79905 + return true;
79906 +
79907 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
79908 + return true;
79909 +
79910 + return subset == superset;
79911 +}
79912 +
79913 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
79914 +{
79915 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
79916 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
79917 +
79918 + return op;
79919 +}
79920 +
79921 +static void register_checker_address_spaces(void *event_data, void *data)
79922 +{
79923 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
79924 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
79925 + c_register_addr_space("__user", ADDR_SPACE_USER);
79926 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
79927 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
79928 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
79929 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
79930 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
79931 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
79932 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
79933 +
79934 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
79935 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
79936 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
79937 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
79938 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
79939 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
79940 + targetm.addr_space.convert = checker_addr_space_convert;
79941 +}
79942 +
79943 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
79944 +{
79945 + const char * const plugin_name = plugin_info->base_name;
79946 + const int argc = plugin_info->argc;
79947 + const struct plugin_argument * const argv = plugin_info->argv;
79948 + int i;
79949 +
79950 + if (!plugin_default_version_check(version, &gcc_version)) {
79951 + error(G_("incompatible gcc/plugin versions"));
79952 + return 1;
79953 + }
79954 +
79955 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
79956 +
79957 + for (i = 0; i < argc; ++i)
79958 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
79959 +
79960 + if (TARGET_64BIT == 0)
79961 + return 0;
79962 +
79963 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
79964 +
79965 + return 0;
79966 +}
79967 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
79968 new file mode 100644
79969 index 0000000..7a5e311
79970 --- /dev/null
79971 +++ b/tools/gcc/colorize_plugin.c
79972 @@ -0,0 +1,148 @@
79973 +/*
79974 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
79975 + * Licensed under the GPL v2
79976 + *
79977 + * Note: the choice of the license means that the compilation process is
79978 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
79979 + * but for the kernel it doesn't matter since it doesn't link against
79980 + * any of the gcc libraries
79981 + *
79982 + * gcc plugin to colorize diagnostic output
79983 + *
79984 + */
79985 +
79986 +#include "gcc-plugin.h"
79987 +#include "config.h"
79988 +#include "system.h"
79989 +#include "coretypes.h"
79990 +#include "tree.h"
79991 +#include "tree-pass.h"
79992 +#include "flags.h"
79993 +#include "intl.h"
79994 +#include "toplev.h"
79995 +#include "plugin.h"
79996 +#include "diagnostic.h"
79997 +#include "plugin-version.h"
79998 +#include "tm.h"
79999 +
80000 +int plugin_is_GPL_compatible;
80001 +
80002 +static struct plugin_info colorize_plugin_info = {
80003 + .version = "201203092200",
80004 + .help = NULL,
80005 +};
80006 +
80007 +#define GREEN "\033[32m\033[2m"
80008 +#define LIGHTGREEN "\033[32m\033[1m"
80009 +#define YELLOW "\033[33m\033[2m"
80010 +#define LIGHTYELLOW "\033[33m\033[1m"
80011 +#define RED "\033[31m\033[2m"
80012 +#define LIGHTRED "\033[31m\033[1m"
80013 +#define BLUE "\033[34m\033[2m"
80014 +#define LIGHTBLUE "\033[34m\033[1m"
80015 +#define BRIGHT "\033[m\033[1m"
80016 +#define NORMAL "\033[m"
80017 +
80018 +static diagnostic_starter_fn old_starter;
80019 +static diagnostic_finalizer_fn old_finalizer;
80020 +
80021 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
80022 +{
80023 + const char *color;
80024 + char *newprefix;
80025 +
80026 + switch (diagnostic->kind) {
80027 + case DK_NOTE:
80028 + color = LIGHTBLUE;
80029 + break;
80030 +
80031 + case DK_PEDWARN:
80032 + case DK_WARNING:
80033 + color = LIGHTYELLOW;
80034 + break;
80035 +
80036 + case DK_ERROR:
80037 + case DK_FATAL:
80038 + case DK_ICE:
80039 + case DK_PERMERROR:
80040 + case DK_SORRY:
80041 + color = LIGHTRED;
80042 + break;
80043 +
80044 + default:
80045 + color = NORMAL;
80046 + }
80047 +
80048 + old_starter(context, diagnostic);
80049 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
80050 + return;
80051 + pp_destroy_prefix(context->printer);
80052 + pp_set_prefix(context->printer, newprefix);
80053 +}
80054 +
80055 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
80056 +{
80057 + old_finalizer(context, diagnostic);
80058 +}
80059 +
80060 +static void colorize_arm(void)
80061 +{
80062 + old_starter = diagnostic_starter(global_dc);
80063 + old_finalizer = diagnostic_finalizer(global_dc);
80064 +
80065 + diagnostic_starter(global_dc) = start_colorize;
80066 + diagnostic_finalizer(global_dc) = finalize_colorize;
80067 +}
80068 +
80069 +static unsigned int execute_colorize_rearm(void)
80070 +{
80071 + if (diagnostic_starter(global_dc) == start_colorize)
80072 + return 0;
80073 +
80074 + colorize_arm();
80075 + return 0;
80076 +}
80077 +
80078 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
80079 + .pass = {
80080 + .type = SIMPLE_IPA_PASS,
80081 + .name = "colorize_rearm",
80082 + .gate = NULL,
80083 + .execute = execute_colorize_rearm,
80084 + .sub = NULL,
80085 + .next = NULL,
80086 + .static_pass_number = 0,
80087 + .tv_id = TV_NONE,
80088 + .properties_required = 0,
80089 + .properties_provided = 0,
80090 + .properties_destroyed = 0,
80091 + .todo_flags_start = 0,
80092 + .todo_flags_finish = 0
80093 + }
80094 +};
80095 +
80096 +static void colorize_start_unit(void *gcc_data, void *user_data)
80097 +{
80098 + colorize_arm();
80099 +}
80100 +
80101 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80102 +{
80103 + const char * const plugin_name = plugin_info->base_name;
80104 + struct register_pass_info colorize_rearm_pass_info = {
80105 + .pass = &pass_ipa_colorize_rearm.pass,
80106 + .reference_pass_name = "*free_lang_data",
80107 + .ref_pass_instance_number = 0,
80108 + .pos_op = PASS_POS_INSERT_AFTER
80109 + };
80110 +
80111 + if (!plugin_default_version_check(version, &gcc_version)) {
80112 + error(G_("incompatible gcc/plugin versions"));
80113 + return 1;
80114 + }
80115 +
80116 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
80117 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
80118 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
80119 + return 0;
80120 +}
80121 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
80122 new file mode 100644
80123 index 0000000..89b7f56
80124 --- /dev/null
80125 +++ b/tools/gcc/constify_plugin.c
80126 @@ -0,0 +1,328 @@
80127 +/*
80128 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
80129 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
80130 + * Licensed under the GPL v2, or (at your option) v3
80131 + *
80132 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
80133 + *
80134 + * Homepage:
80135 + * http://www.grsecurity.net/~ephox/const_plugin/
80136 + *
80137 + * Usage:
80138 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
80139 + * $ gcc -fplugin=constify_plugin.so test.c -O2
80140 + */
80141 +
80142 +#include "gcc-plugin.h"
80143 +#include "config.h"
80144 +#include "system.h"
80145 +#include "coretypes.h"
80146 +#include "tree.h"
80147 +#include "tree-pass.h"
80148 +#include "flags.h"
80149 +#include "intl.h"
80150 +#include "toplev.h"
80151 +#include "plugin.h"
80152 +#include "diagnostic.h"
80153 +#include "plugin-version.h"
80154 +#include "tm.h"
80155 +#include "function.h"
80156 +#include "basic-block.h"
80157 +#include "gimple.h"
80158 +#include "rtl.h"
80159 +#include "emit-rtl.h"
80160 +#include "tree-flow.h"
80161 +
80162 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
80163 +
80164 +int plugin_is_GPL_compatible;
80165 +
80166 +static struct plugin_info const_plugin_info = {
80167 + .version = "201205300030",
80168 + .help = "no-constify\tturn off constification\n",
80169 +};
80170 +
80171 +static void deconstify_tree(tree node);
80172 +
80173 +static void deconstify_type(tree type)
80174 +{
80175 + tree field;
80176 +
80177 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
80178 + tree type = TREE_TYPE(field);
80179 +
80180 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
80181 + continue;
80182 + if (!TYPE_READONLY(type))
80183 + continue;
80184 +
80185 + deconstify_tree(field);
80186 + }
80187 + TYPE_READONLY(type) = 0;
80188 + C_TYPE_FIELDS_READONLY(type) = 0;
80189 +}
80190 +
80191 +static void deconstify_tree(tree node)
80192 +{
80193 + tree old_type, new_type, field;
80194 +
80195 + old_type = TREE_TYPE(node);
80196 +
80197 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
80198 +
80199 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
80200 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
80201 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
80202 + DECL_FIELD_CONTEXT(field) = new_type;
80203 +
80204 + deconstify_type(new_type);
80205 +
80206 + TREE_READONLY(node) = 0;
80207 + TREE_TYPE(node) = new_type;
80208 +}
80209 +
80210 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
80211 +{
80212 + tree type;
80213 +
80214 + *no_add_attrs = true;
80215 + if (TREE_CODE(*node) == FUNCTION_DECL) {
80216 + error("%qE attribute does not apply to functions", name);
80217 + return NULL_TREE;
80218 + }
80219 +
80220 + if (TREE_CODE(*node) == VAR_DECL) {
80221 + error("%qE attribute does not apply to variables", name);
80222 + return NULL_TREE;
80223 + }
80224 +
80225 + if (TYPE_P(*node)) {
80226 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
80227 + *no_add_attrs = false;
80228 + else
80229 + error("%qE attribute applies to struct and union types only", name);
80230 + return NULL_TREE;
80231 + }
80232 +
80233 + type = TREE_TYPE(*node);
80234 +
80235 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
80236 + error("%qE attribute applies to struct and union types only", name);
80237 + return NULL_TREE;
80238 + }
80239 +
80240 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
80241 + error("%qE attribute is already applied to the type", name);
80242 + return NULL_TREE;
80243 + }
80244 +
80245 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
80246 + error("%qE attribute used on type that is not constified", name);
80247 + return NULL_TREE;
80248 + }
80249 +
80250 + if (TREE_CODE(*node) == TYPE_DECL) {
80251 + deconstify_tree(*node);
80252 + return NULL_TREE;
80253 + }
80254 +
80255 + return NULL_TREE;
80256 +}
80257 +
80258 +static void constify_type(tree type)
80259 +{
80260 + TYPE_READONLY(type) = 1;
80261 + C_TYPE_FIELDS_READONLY(type) = 1;
80262 +}
80263 +
80264 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
80265 +{
80266 + *no_add_attrs = true;
80267 + if (!TYPE_P(*node)) {
80268 + error("%qE attribute applies to types only", name);
80269 + return NULL_TREE;
80270 + }
80271 +
80272 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
80273 + error("%qE attribute applies to struct and union types only", name);
80274 + return NULL_TREE;
80275 + }
80276 +
80277 + *no_add_attrs = false;
80278 + constify_type(*node);
80279 + return NULL_TREE;
80280 +}
80281 +
80282 +static struct attribute_spec no_const_attr = {
80283 + .name = "no_const",
80284 + .min_length = 0,
80285 + .max_length = 0,
80286 + .decl_required = false,
80287 + .type_required = false,
80288 + .function_type_required = false,
80289 + .handler = handle_no_const_attribute,
80290 +#if BUILDING_GCC_VERSION >= 4007
80291 + .affects_type_identity = true
80292 +#endif
80293 +};
80294 +
80295 +static struct attribute_spec do_const_attr = {
80296 + .name = "do_const",
80297 + .min_length = 0,
80298 + .max_length = 0,
80299 + .decl_required = false,
80300 + .type_required = false,
80301 + .function_type_required = false,
80302 + .handler = handle_do_const_attribute,
80303 +#if BUILDING_GCC_VERSION >= 4007
80304 + .affects_type_identity = true
80305 +#endif
80306 +};
80307 +
80308 +static void register_attributes(void *event_data, void *data)
80309 +{
80310 + register_attribute(&no_const_attr);
80311 + register_attribute(&do_const_attr);
80312 +}
80313 +
80314 +static bool is_fptr(tree field)
80315 +{
80316 + tree ptr = TREE_TYPE(field);
80317 +
80318 + if (TREE_CODE(ptr) != POINTER_TYPE)
80319 + return false;
80320 +
80321 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
80322 +}
80323 +
80324 +static bool walk_struct(tree node)
80325 +{
80326 + tree field;
80327 +
80328 + if (TYPE_FIELDS(node) == NULL_TREE)
80329 + return false;
80330 +
80331 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
80332 + gcc_assert(!TYPE_READONLY(node));
80333 + deconstify_type(node);
80334 + return false;
80335 + }
80336 +
80337 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
80338 + tree type = TREE_TYPE(field);
80339 + enum tree_code code = TREE_CODE(type);
80340 + if (code == RECORD_TYPE || code == UNION_TYPE) {
80341 + if (!(walk_struct(type)))
80342 + return false;
80343 + } else if (!is_fptr(field) && !TREE_READONLY(field))
80344 + return false;
80345 + }
80346 + return true;
80347 +}
80348 +
80349 +static void finish_type(void *event_data, void *data)
80350 +{
80351 + tree type = (tree)event_data;
80352 +
80353 + if (type == NULL_TREE)
80354 + return;
80355 +
80356 + if (TYPE_READONLY(type))
80357 + return;
80358 +
80359 + if (walk_struct(type))
80360 + constify_type(type);
80361 +}
80362 +
80363 +static unsigned int check_local_variables(void);
80364 +
80365 +struct gimple_opt_pass pass_local_variable = {
80366 + {
80367 + .type = GIMPLE_PASS,
80368 + .name = "check_local_variables",
80369 + .gate = NULL,
80370 + .execute = check_local_variables,
80371 + .sub = NULL,
80372 + .next = NULL,
80373 + .static_pass_number = 0,
80374 + .tv_id = TV_NONE,
80375 + .properties_required = 0,
80376 + .properties_provided = 0,
80377 + .properties_destroyed = 0,
80378 + .todo_flags_start = 0,
80379 + .todo_flags_finish = 0
80380 + }
80381 +};
80382 +
80383 +static unsigned int check_local_variables(void)
80384 +{
80385 + tree var;
80386 + referenced_var_iterator rvi;
80387 +
80388 +#if BUILDING_GCC_VERSION == 4005
80389 + FOR_EACH_REFERENCED_VAR(var, rvi) {
80390 +#else
80391 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
80392 +#endif
80393 + tree type = TREE_TYPE(var);
80394 +
80395 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
80396 + continue;
80397 +
80398 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
80399 + continue;
80400 +
80401 + if (!TYPE_READONLY(type))
80402 + continue;
80403 +
80404 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
80405 +// continue;
80406 +
80407 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
80408 +// continue;
80409 +
80410 + if (walk_struct(type)) {
80411 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
80412 + return 1;
80413 + }
80414 + }
80415 + return 0;
80416 +}
80417 +
80418 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80419 +{
80420 + const char * const plugin_name = plugin_info->base_name;
80421 + const int argc = plugin_info->argc;
80422 + const struct plugin_argument * const argv = plugin_info->argv;
80423 + int i;
80424 + bool constify = true;
80425 +
80426 + struct register_pass_info local_variable_pass_info = {
80427 + .pass = &pass_local_variable.pass,
80428 + .reference_pass_name = "*referenced_vars",
80429 + .ref_pass_instance_number = 0,
80430 + .pos_op = PASS_POS_INSERT_AFTER
80431 + };
80432 +
80433 + if (!plugin_default_version_check(version, &gcc_version)) {
80434 + error(G_("incompatible gcc/plugin versions"));
80435 + return 1;
80436 + }
80437 +
80438 + for (i = 0; i < argc; ++i) {
80439 + if (!(strcmp(argv[i].key, "no-constify"))) {
80440 + constify = false;
80441 + continue;
80442 + }
80443 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80444 + }
80445 +
80446 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
80447 + if (constify) {
80448 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
80449 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
80450 + }
80451 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
80452 +
80453 + return 0;
80454 +}
80455 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
80456 new file mode 100644
80457 index 0000000..a0fe8b2
80458 --- /dev/null
80459 +++ b/tools/gcc/generate_size_overflow_hash.sh
80460 @@ -0,0 +1,94 @@
80461 +#!/bin/bash
80462 +
80463 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
80464 +
80465 +header1="size_overflow_hash.h"
80466 +database="size_overflow_hash.data"
80467 +n=65536
80468 +
80469 +usage() {
80470 +cat <<EOF
80471 +usage: $0 options
80472 +OPTIONS:
80473 + -h|--help help
80474 + -o header file
80475 + -d database file
80476 + -n hash array size
80477 +EOF
80478 + return 0
80479 +}
80480 +
80481 +while true
80482 +do
80483 + case "$1" in
80484 + -h|--help) usage && exit 0;;
80485 + -n) n=$2; shift 2;;
80486 + -o) header1="$2"; shift 2;;
80487 + -d) database="$2"; shift 2;;
80488 + --) shift 1; break ;;
80489 + *) break ;;
80490 + esac
80491 +done
80492 +
80493 +create_defines() {
80494 + for i in `seq 1 10`
80495 + do
80496 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
80497 + done
80498 + echo >> "$header1"
80499 +}
80500 +
80501 +create_structs () {
80502 + rm -f "$header1"
80503 +
80504 + create_defines
80505 +
80506 + cat "$database" | while read data
80507 + do
80508 + data_array=($data)
80509 + struct_hash_name="${data_array[0]}"
80510 + funcn="${data_array[1]}"
80511 + params="${data_array[2]}"
80512 + next="${data_array[5]}"
80513 +
80514 + echo "struct size_overflow_hash $struct_hash_name = {" >> "$header1"
80515 +
80516 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
80517 + echo -en "\t.param\t= " >> "$header1"
80518 + line=
80519 + for param_num in ${params//-/ };
80520 + do
80521 + line="${line}PARAM"$param_num"|"
80522 + done
80523 +
80524 + echo -e "${line%?},\n};\n" >> "$header1"
80525 + done
80526 +}
80527 +
80528 +create_headers () {
80529 + echo "struct size_overflow_hash *size_overflow_hash[$n] = {" >> "$header1"
80530 +}
80531 +
80532 +create_array_elements () {
80533 + index=0
80534 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
80535 + do
80536 + data_array=($data)
80537 + i="${data_array[3]}"
80538 + hash="${data_array[4]}"
80539 + while [[ $index -lt $i ]]
80540 + do
80541 + echo -e "\t["$index"]\t= NULL," >> "$header1"
80542 + index=$(($index + 1))
80543 + done
80544 + index=$(($index + 1))
80545 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
80546 + done
80547 + echo '};' >> $header1
80548 +}
80549 +
80550 +create_structs
80551 +create_headers
80552 +create_array_elements
80553 +
80554 +exit 0
80555 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
80556 new file mode 100644
80557 index 0000000..a5eabce
80558 --- /dev/null
80559 +++ b/tools/gcc/kallocstat_plugin.c
80560 @@ -0,0 +1,167 @@
80561 +/*
80562 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
80563 + * Licensed under the GPL v2
80564 + *
80565 + * Note: the choice of the license means that the compilation process is
80566 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80567 + * but for the kernel it doesn't matter since it doesn't link against
80568 + * any of the gcc libraries
80569 + *
80570 + * gcc plugin to find the distribution of k*alloc sizes
80571 + *
80572 + * TODO:
80573 + *
80574 + * BUGS:
80575 + * - none known
80576 + */
80577 +#include "gcc-plugin.h"
80578 +#include "config.h"
80579 +#include "system.h"
80580 +#include "coretypes.h"
80581 +#include "tree.h"
80582 +#include "tree-pass.h"
80583 +#include "flags.h"
80584 +#include "intl.h"
80585 +#include "toplev.h"
80586 +#include "plugin.h"
80587 +//#include "expr.h" where are you...
80588 +#include "diagnostic.h"
80589 +#include "plugin-version.h"
80590 +#include "tm.h"
80591 +#include "function.h"
80592 +#include "basic-block.h"
80593 +#include "gimple.h"
80594 +#include "rtl.h"
80595 +#include "emit-rtl.h"
80596 +
80597 +extern void print_gimple_stmt(FILE *, gimple, int, int);
80598 +
80599 +int plugin_is_GPL_compatible;
80600 +
80601 +static const char * const kalloc_functions[] = {
80602 + "__kmalloc",
80603 + "kmalloc",
80604 + "kmalloc_large",
80605 + "kmalloc_node",
80606 + "kmalloc_order",
80607 + "kmalloc_order_trace",
80608 + "kmalloc_slab",
80609 + "kzalloc",
80610 + "kzalloc_node",
80611 +};
80612 +
80613 +static struct plugin_info kallocstat_plugin_info = {
80614 + .version = "201111150100",
80615 +};
80616 +
80617 +static unsigned int execute_kallocstat(void);
80618 +
80619 +static struct gimple_opt_pass kallocstat_pass = {
80620 + .pass = {
80621 + .type = GIMPLE_PASS,
80622 + .name = "kallocstat",
80623 + .gate = NULL,
80624 + .execute = execute_kallocstat,
80625 + .sub = NULL,
80626 + .next = NULL,
80627 + .static_pass_number = 0,
80628 + .tv_id = TV_NONE,
80629 + .properties_required = 0,
80630 + .properties_provided = 0,
80631 + .properties_destroyed = 0,
80632 + .todo_flags_start = 0,
80633 + .todo_flags_finish = 0
80634 + }
80635 +};
80636 +
80637 +static bool is_kalloc(const char *fnname)
80638 +{
80639 + size_t i;
80640 +
80641 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
80642 + if (!strcmp(fnname, kalloc_functions[i]))
80643 + return true;
80644 + return false;
80645 +}
80646 +
80647 +static unsigned int execute_kallocstat(void)
80648 +{
80649 + basic_block bb;
80650 +
80651 + // 1. loop through BBs and GIMPLE statements
80652 + FOR_EACH_BB(bb) {
80653 + gimple_stmt_iterator gsi;
80654 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
80655 + // gimple match:
80656 + tree fndecl, size;
80657 + gimple call_stmt;
80658 + const char *fnname;
80659 +
80660 + // is it a call
80661 + call_stmt = gsi_stmt(gsi);
80662 + if (!is_gimple_call(call_stmt))
80663 + continue;
80664 + fndecl = gimple_call_fndecl(call_stmt);
80665 + if (fndecl == NULL_TREE)
80666 + continue;
80667 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
80668 + continue;
80669 +
80670 + // is it a call to k*alloc
80671 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
80672 + if (!is_kalloc(fnname))
80673 + continue;
80674 +
80675 + // is the size arg the result of a simple const assignment
80676 + size = gimple_call_arg(call_stmt, 0);
80677 + while (true) {
80678 + gimple def_stmt;
80679 + expanded_location xloc;
80680 + size_t size_val;
80681 +
80682 + if (TREE_CODE(size) != SSA_NAME)
80683 + break;
80684 + def_stmt = SSA_NAME_DEF_STMT(size);
80685 + if (!def_stmt || !is_gimple_assign(def_stmt))
80686 + break;
80687 + if (gimple_num_ops(def_stmt) != 2)
80688 + break;
80689 + size = gimple_assign_rhs1(def_stmt);
80690 + if (!TREE_CONSTANT(size))
80691 + continue;
80692 + xloc = expand_location(gimple_location(def_stmt));
80693 + if (!xloc.file)
80694 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
80695 + size_val = TREE_INT_CST_LOW(size);
80696 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
80697 + break;
80698 + }
80699 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
80700 +//debug_tree(gimple_call_fn(call_stmt));
80701 +//print_node(stderr, "pax", fndecl, 4);
80702 + }
80703 + }
80704 +
80705 + return 0;
80706 +}
80707 +
80708 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80709 +{
80710 + const char * const plugin_name = plugin_info->base_name;
80711 + struct register_pass_info kallocstat_pass_info = {
80712 + .pass = &kallocstat_pass.pass,
80713 + .reference_pass_name = "ssa",
80714 + .ref_pass_instance_number = 0,
80715 + .pos_op = PASS_POS_INSERT_AFTER
80716 + };
80717 +
80718 + if (!plugin_default_version_check(version, &gcc_version)) {
80719 + error(G_("incompatible gcc/plugin versions"));
80720 + return 1;
80721 + }
80722 +
80723 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
80724 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
80725 +
80726 + return 0;
80727 +}
80728 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
80729 new file mode 100644
80730 index 0000000..d8a8da2
80731 --- /dev/null
80732 +++ b/tools/gcc/kernexec_plugin.c
80733 @@ -0,0 +1,427 @@
80734 +/*
80735 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
80736 + * Licensed under the GPL v2
80737 + *
80738 + * Note: the choice of the license means that the compilation process is
80739 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80740 + * but for the kernel it doesn't matter since it doesn't link against
80741 + * any of the gcc libraries
80742 + *
80743 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
80744 + *
80745 + * TODO:
80746 + *
80747 + * BUGS:
80748 + * - none known
80749 + */
80750 +#include "gcc-plugin.h"
80751 +#include "config.h"
80752 +#include "system.h"
80753 +#include "coretypes.h"
80754 +#include "tree.h"
80755 +#include "tree-pass.h"
80756 +#include "flags.h"
80757 +#include "intl.h"
80758 +#include "toplev.h"
80759 +#include "plugin.h"
80760 +//#include "expr.h" where are you...
80761 +#include "diagnostic.h"
80762 +#include "plugin-version.h"
80763 +#include "tm.h"
80764 +#include "function.h"
80765 +#include "basic-block.h"
80766 +#include "gimple.h"
80767 +#include "rtl.h"
80768 +#include "emit-rtl.h"
80769 +#include "tree-flow.h"
80770 +
80771 +extern void print_gimple_stmt(FILE *, gimple, int, int);
80772 +extern rtx emit_move_insn(rtx x, rtx y);
80773 +
80774 +int plugin_is_GPL_compatible;
80775 +
80776 +static struct plugin_info kernexec_plugin_info = {
80777 + .version = "201111291120",
80778 + .help = "method=[bts|or]\tinstrumentation method\n"
80779 +};
80780 +
80781 +static unsigned int execute_kernexec_reload(void);
80782 +static unsigned int execute_kernexec_fptr(void);
80783 +static unsigned int execute_kernexec_retaddr(void);
80784 +static bool kernexec_cmodel_check(void);
80785 +
80786 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
80787 +static void (*kernexec_instrument_retaddr)(rtx);
80788 +
80789 +static struct gimple_opt_pass kernexec_reload_pass = {
80790 + .pass = {
80791 + .type = GIMPLE_PASS,
80792 + .name = "kernexec_reload",
80793 + .gate = kernexec_cmodel_check,
80794 + .execute = execute_kernexec_reload,
80795 + .sub = NULL,
80796 + .next = NULL,
80797 + .static_pass_number = 0,
80798 + .tv_id = TV_NONE,
80799 + .properties_required = 0,
80800 + .properties_provided = 0,
80801 + .properties_destroyed = 0,
80802 + .todo_flags_start = 0,
80803 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
80804 + }
80805 +};
80806 +
80807 +static struct gimple_opt_pass kernexec_fptr_pass = {
80808 + .pass = {
80809 + .type = GIMPLE_PASS,
80810 + .name = "kernexec_fptr",
80811 + .gate = kernexec_cmodel_check,
80812 + .execute = execute_kernexec_fptr,
80813 + .sub = NULL,
80814 + .next = NULL,
80815 + .static_pass_number = 0,
80816 + .tv_id = TV_NONE,
80817 + .properties_required = 0,
80818 + .properties_provided = 0,
80819 + .properties_destroyed = 0,
80820 + .todo_flags_start = 0,
80821 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
80822 + }
80823 +};
80824 +
80825 +static struct rtl_opt_pass kernexec_retaddr_pass = {
80826 + .pass = {
80827 + .type = RTL_PASS,
80828 + .name = "kernexec_retaddr",
80829 + .gate = kernexec_cmodel_check,
80830 + .execute = execute_kernexec_retaddr,
80831 + .sub = NULL,
80832 + .next = NULL,
80833 + .static_pass_number = 0,
80834 + .tv_id = TV_NONE,
80835 + .properties_required = 0,
80836 + .properties_provided = 0,
80837 + .properties_destroyed = 0,
80838 + .todo_flags_start = 0,
80839 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
80840 + }
80841 +};
80842 +
80843 +static bool kernexec_cmodel_check(void)
80844 +{
80845 + tree section;
80846 +
80847 + if (ix86_cmodel != CM_KERNEL)
80848 + return false;
80849 +
80850 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
80851 + if (!section || !TREE_VALUE(section))
80852 + return true;
80853 +
80854 + section = TREE_VALUE(TREE_VALUE(section));
80855 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
80856 + return true;
80857 +
80858 + return false;
80859 +}
80860 +
80861 +/*
80862 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
80863 + */
80864 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
80865 +{
80866 + gimple asm_movabs_stmt;
80867 +
80868 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
80869 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
80870 + gimple_asm_set_volatile(asm_movabs_stmt, true);
80871 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
80872 + update_stmt(asm_movabs_stmt);
80873 +}
80874 +
80875 +/*
80876 + * find all asm() stmts that clobber r10 and add a reload of r10
80877 + */
80878 +static unsigned int execute_kernexec_reload(void)
80879 +{
80880 + basic_block bb;
80881 +
80882 + // 1. loop through BBs and GIMPLE statements
80883 + FOR_EACH_BB(bb) {
80884 + gimple_stmt_iterator gsi;
80885 +
80886 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
80887 + // gimple match: __asm__ ("" : : : "r10");
80888 + gimple asm_stmt;
80889 + size_t nclobbers;
80890 +
80891 + // is it an asm ...
80892 + asm_stmt = gsi_stmt(gsi);
80893 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
80894 + continue;
80895 +
80896 + // ... clobbering r10
80897 + nclobbers = gimple_asm_nclobbers(asm_stmt);
80898 + while (nclobbers--) {
80899 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
80900 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
80901 + continue;
80902 + kernexec_reload_fptr_mask(&gsi);
80903 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
80904 + break;
80905 + }
80906 + }
80907 + }
80908 +
80909 + return 0;
80910 +}
80911 +
80912 +/*
80913 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
80914 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
80915 + */
80916 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
80917 +{
80918 + gimple assign_intptr, assign_new_fptr, call_stmt;
80919 + tree intptr, old_fptr, new_fptr, kernexec_mask;
80920 +
80921 + call_stmt = gsi_stmt(*gsi);
80922 + old_fptr = gimple_call_fn(call_stmt);
80923 +
80924 + // create temporary unsigned long variable used for bitops and cast fptr to it
80925 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
80926 + add_referenced_var(intptr);
80927 + mark_sym_for_renaming(intptr);
80928 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
80929 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
80930 + update_stmt(assign_intptr);
80931 +
80932 + // apply logical or to temporary unsigned long and bitmask
80933 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
80934 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
80935 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
80936 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
80937 + update_stmt(assign_intptr);
80938 +
80939 + // cast temporary unsigned long back to a temporary fptr variable
80940 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
80941 + add_referenced_var(new_fptr);
80942 + mark_sym_for_renaming(new_fptr);
80943 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
80944 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
80945 + update_stmt(assign_new_fptr);
80946 +
80947 + // replace call stmt fn with the new fptr
80948 + gimple_call_set_fn(call_stmt, new_fptr);
80949 + update_stmt(call_stmt);
80950 +}
80951 +
80952 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
80953 +{
80954 + gimple asm_or_stmt, call_stmt;
80955 + tree old_fptr, new_fptr, input, output;
80956 + VEC(tree, gc) *inputs = NULL;
80957 + VEC(tree, gc) *outputs = NULL;
80958 +
80959 + call_stmt = gsi_stmt(*gsi);
80960 + old_fptr = gimple_call_fn(call_stmt);
80961 +
80962 + // create temporary fptr variable
80963 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
80964 + add_referenced_var(new_fptr);
80965 + mark_sym_for_renaming(new_fptr);
80966 +
80967 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
80968 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
80969 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
80970 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
80971 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
80972 + VEC_safe_push(tree, gc, inputs, input);
80973 + VEC_safe_push(tree, gc, outputs, output);
80974 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
80975 + gimple_asm_set_volatile(asm_or_stmt, true);
80976 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
80977 + update_stmt(asm_or_stmt);
80978 +
80979 + // replace call stmt fn with the new fptr
80980 + gimple_call_set_fn(call_stmt, new_fptr);
80981 + update_stmt(call_stmt);
80982 +}
80983 +
80984 +/*
80985 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
80986 + */
80987 +static unsigned int execute_kernexec_fptr(void)
80988 +{
80989 + basic_block bb;
80990 +
80991 + // 1. loop through BBs and GIMPLE statements
80992 + FOR_EACH_BB(bb) {
80993 + gimple_stmt_iterator gsi;
80994 +
80995 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
80996 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
80997 + tree fn;
80998 + gimple call_stmt;
80999 +
81000 + // is it a call ...
81001 + call_stmt = gsi_stmt(gsi);
81002 + if (!is_gimple_call(call_stmt))
81003 + continue;
81004 + fn = gimple_call_fn(call_stmt);
81005 + if (TREE_CODE(fn) == ADDR_EXPR)
81006 + continue;
81007 + if (TREE_CODE(fn) != SSA_NAME)
81008 + gcc_unreachable();
81009 +
81010 + // ... through a function pointer
81011 + fn = SSA_NAME_VAR(fn);
81012 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
81013 + continue;
81014 + fn = TREE_TYPE(fn);
81015 + if (TREE_CODE(fn) != POINTER_TYPE)
81016 + continue;
81017 + fn = TREE_TYPE(fn);
81018 + if (TREE_CODE(fn) != FUNCTION_TYPE)
81019 + continue;
81020 +
81021 + kernexec_instrument_fptr(&gsi);
81022 +
81023 +//debug_tree(gimple_call_fn(call_stmt));
81024 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
81025 + }
81026 + }
81027 +
81028 + return 0;
81029 +}
81030 +
81031 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
81032 +static void kernexec_instrument_retaddr_bts(rtx insn)
81033 +{
81034 + rtx btsq;
81035 + rtvec argvec, constraintvec, labelvec;
81036 + int line;
81037 +
81038 + // create asm volatile("btsq $63,(%%rsp)":::)
81039 + argvec = rtvec_alloc(0);
81040 + constraintvec = rtvec_alloc(0);
81041 + labelvec = rtvec_alloc(0);
81042 + line = expand_location(RTL_LOCATION(insn)).line;
81043 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
81044 + MEM_VOLATILE_P(btsq) = 1;
81045 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
81046 + emit_insn_before(btsq, insn);
81047 +}
81048 +
81049 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
81050 +static void kernexec_instrument_retaddr_or(rtx insn)
81051 +{
81052 + rtx orq;
81053 + rtvec argvec, constraintvec, labelvec;
81054 + int line;
81055 +
81056 + // create asm volatile("orq %%r10,(%%rsp)":::)
81057 + argvec = rtvec_alloc(0);
81058 + constraintvec = rtvec_alloc(0);
81059 + labelvec = rtvec_alloc(0);
81060 + line = expand_location(RTL_LOCATION(insn)).line;
81061 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
81062 + MEM_VOLATILE_P(orq) = 1;
81063 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
81064 + emit_insn_before(orq, insn);
81065 +}
81066 +
81067 +/*
81068 + * find all asm level function returns and forcibly set the highest bit of the return address
81069 + */
81070 +static unsigned int execute_kernexec_retaddr(void)
81071 +{
81072 + rtx insn;
81073 +
81074 + // 1. find function returns
81075 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
81076 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
81077 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
81078 + rtx body;
81079 +
81080 + // is it a retn
81081 + if (!JUMP_P(insn))
81082 + continue;
81083 + body = PATTERN(insn);
81084 + if (GET_CODE(body) == PARALLEL)
81085 + body = XVECEXP(body, 0, 0);
81086 + if (GET_CODE(body) != RETURN)
81087 + continue;
81088 + kernexec_instrument_retaddr(insn);
81089 + }
81090 +
81091 +// print_simple_rtl(stderr, get_insns());
81092 +// print_rtl(stderr, get_insns());
81093 +
81094 + return 0;
81095 +}
81096 +
81097 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81098 +{
81099 + const char * const plugin_name = plugin_info->base_name;
81100 + const int argc = plugin_info->argc;
81101 + const struct plugin_argument * const argv = plugin_info->argv;
81102 + int i;
81103 + struct register_pass_info kernexec_reload_pass_info = {
81104 + .pass = &kernexec_reload_pass.pass,
81105 + .reference_pass_name = "ssa",
81106 + .ref_pass_instance_number = 0,
81107 + .pos_op = PASS_POS_INSERT_AFTER
81108 + };
81109 + struct register_pass_info kernexec_fptr_pass_info = {
81110 + .pass = &kernexec_fptr_pass.pass,
81111 + .reference_pass_name = "ssa",
81112 + .ref_pass_instance_number = 0,
81113 + .pos_op = PASS_POS_INSERT_AFTER
81114 + };
81115 + struct register_pass_info kernexec_retaddr_pass_info = {
81116 + .pass = &kernexec_retaddr_pass.pass,
81117 + .reference_pass_name = "pro_and_epilogue",
81118 + .ref_pass_instance_number = 0,
81119 + .pos_op = PASS_POS_INSERT_AFTER
81120 + };
81121 +
81122 + if (!plugin_default_version_check(version, &gcc_version)) {
81123 + error(G_("incompatible gcc/plugin versions"));
81124 + return 1;
81125 + }
81126 +
81127 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
81128 +
81129 + if (TARGET_64BIT == 0)
81130 + return 0;
81131 +
81132 + for (i = 0; i < argc; ++i) {
81133 + if (!strcmp(argv[i].key, "method")) {
81134 + if (!argv[i].value) {
81135 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81136 + continue;
81137 + }
81138 + if (!strcmp(argv[i].value, "bts")) {
81139 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
81140 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
81141 + } else if (!strcmp(argv[i].value, "or")) {
81142 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
81143 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
81144 + fix_register("r10", 1, 1);
81145 + } else
81146 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
81147 + continue;
81148 + }
81149 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81150 + }
81151 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
81152 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
81153 +
81154 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
81155 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
81156 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
81157 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
81158 +
81159 + return 0;
81160 +}
81161 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
81162 new file mode 100644
81163 index 0000000..daaa86c
81164 --- /dev/null
81165 +++ b/tools/gcc/size_overflow_hash.data
81166 @@ -0,0 +1,2486 @@
81167 +_000001_hash alloc_dr 2 65495 _000001_hash NULL
81168 +_000002_hash __copy_from_user 3 10918 _000002_hash NULL
81169 +_000003_hash copy_from_user 3 17559 _000003_hash NULL
81170 +_000004_hash __copy_from_user_inatomic 3 4365 _000004_hash NULL
81171 +_000005_hash __copy_from_user_nocache 3 39351 _000005_hash NULL
81172 +_000006_hash __copy_to_user_inatomic 3 19214 _000006_hash NULL
81173 +_000007_hash do_xip_mapping_read 5 60297 _000007_hash NULL
81174 +_000008_hash hugetlbfs_read 3 11268 _000008_hash NULL
81175 +_000009_hash kmalloc 1 60432 _002597_hash NULL nohasharray
81176 +_000010_hash kmalloc_array 1-2 9444 _000010_hash NULL
81177 +_000012_hash kmalloc_slab 1 11917 _000012_hash NULL
81178 +_000013_hash kmemdup 2 64015 _000013_hash NULL
81179 +_000014_hash __krealloc 2 14857 _000331_hash NULL nohasharray
81180 +_000015_hash memdup_user 2 59590 _000015_hash NULL
81181 +_000016_hash module_alloc 1 63630 _000016_hash NULL
81182 +_000017_hash read_default_ldt 2 14302 _000017_hash NULL
81183 +_000018_hash read_kcore 3 63488 _000018_hash NULL
81184 +_000019_hash read_ldt 2 47570 _000019_hash NULL
81185 +_000020_hash read_zero 3 19366 _000020_hash NULL
81186 +_000021_hash __vmalloc_node 1 39308 _000021_hash NULL
81187 +_000022_hash vm_map_ram 2 23078 _001054_hash NULL nohasharray
81188 +_000023_hash aa_simple_write_to_buffer 4-3 49683 _000023_hash NULL
81189 +_000024_hash ablkcipher_copy_iv 3 64140 _000024_hash NULL
81190 +_000025_hash ablkcipher_next_slow 4 47274 _000025_hash NULL
81191 +_000026_hash acpi_battery_write_alarm 3 1240 _000026_hash NULL
81192 +_000027_hash acpi_os_allocate 1 14892 _000027_hash NULL
81193 +_000028_hash acpi_system_write_wakeup_device 3 34853 _000028_hash NULL
81194 +_000029_hash adu_write 3 30487 _000029_hash NULL
81195 +_000030_hash aer_inject_write 3 52399 _000030_hash NULL
81196 +_000031_hash afs_alloc_flat_call 2-3 36399 _000031_hash NULL
81197 +_000033_hash afs_proc_cells_write 3 61139 _000033_hash NULL
81198 +_000034_hash afs_proc_rootcell_write 3 15822 _000034_hash NULL
81199 +_000035_hash agp_3_5_isochronous_node_enable 3 49465 _000035_hash NULL
81200 +_000036_hash agp_alloc_page_array 1 22554 _000036_hash NULL
81201 +_000037_hash ah_alloc_tmp 2 54378 _000037_hash NULL
81202 +_000038_hash ahash_setkey_unaligned 3 33521 _000038_hash NULL
81203 +_000039_hash alg_setkey 3 31485 _000039_hash NULL
81204 +_000040_hash aligned_kmalloc 1 3628 _000040_hash NULL
81205 +_000041_hash alloc_context 1 3194 _000041_hash NULL
81206 +_000042_hash alloc_ep_req 2 54860 _000042_hash NULL
81207 +_000043_hash alloc_fdmem 1 27083 _000043_hash NULL
81208 +_000044_hash alloc_flex_gd 1 57259 _000044_hash NULL
81209 +_000045_hash alloc_sglist 1-3-2 22960 _000045_hash NULL
81210 +_000046_hash aoedev_flush 2 44398 _000046_hash NULL
81211 +_000047_hash append_to_buffer 3 63550 _000047_hash NULL
81212 +_000048_hash asix_read_cmd 5 13245 _000048_hash NULL
81213 +_000049_hash asix_write_cmd 5 58192 _000049_hash NULL
81214 +_000050_hash asn1_octets_decode 2 9991 _000050_hash NULL
81215 +_000051_hash asn1_oid_decode 2 4999 _000051_hash NULL
81216 +_000052_hash at76_set_card_command 4 4471 _000052_hash NULL
81217 +_000053_hash ath6kl_add_bss_if_needed 6 24317 _000053_hash NULL
81218 +_000054_hash ath6kl_debug_roam_tbl_event 3 5224 _000054_hash NULL
81219 +_000055_hash ath6kl_mgmt_powersave_ap 6 13791 _000055_hash NULL
81220 +_000056_hash ath6kl_send_go_probe_resp 3 21113 _000056_hash NULL
81221 +_000057_hash ath6kl_set_ap_probe_resp_ies 3 50539 _000057_hash NULL
81222 +_000058_hash ath6kl_set_assoc_req_ies 3 43185 _000058_hash NULL
81223 +_000059_hash ath6kl_wmi_bssinfo_event_rx 3 2275 _000059_hash NULL
81224 +_000060_hash ath6kl_wmi_send_action_cmd 7 58860 _000060_hash NULL
81225 +_000061_hash __ath6kl_wmi_send_mgmt_cmd 7 38971 _000061_hash NULL
81226 +_000062_hash attach_hdlc_protocol 3 19986 _000062_hash NULL
81227 +_000063_hash audio_write 4 54261 _001597_hash NULL nohasharray
81228 +_000064_hash audit_unpack_string 3 13748 _000064_hash NULL
81229 +_000065_hash av7110_vbi_write 3 34384 _000065_hash NULL
81230 +_000066_hash ax25_setsockopt 5 42740 _000066_hash NULL
81231 +_000067_hash b43_debugfs_write 3 34838 _000067_hash NULL
81232 +_000068_hash b43legacy_debugfs_write 3 28556 _000068_hash NULL
81233 +_000069_hash bch_alloc 1 4593 _000069_hash NULL
81234 +_000070_hash befs_nls2utf 3 17163 _000070_hash NULL
81235 +_000071_hash befs_utf2nls 3 25628 _000071_hash NULL
81236 +_000072_hash bfad_debugfs_write_regrd 3 15218 _000072_hash NULL
81237 +_000073_hash bfad_debugfs_write_regwr 3 61841 _000073_hash NULL
81238 +_000074_hash bio_alloc_map_data 1-2 50782 _000074_hash NULL
81239 +_000076_hash bio_kmalloc 2 54672 _000076_hash NULL
81240 +_000077_hash blkcipher_copy_iv 3 24075 _000077_hash NULL
81241 +_000078_hash blkcipher_next_slow 4 52733 _000078_hash NULL
81242 +_000079_hash bl_pipe_downcall 3 34264 _000079_hash NULL
81243 +_000080_hash bnad_debugfs_write_regrd 3 6706 _000080_hash NULL
81244 +_000081_hash bnad_debugfs_write_regwr 3 57500 _000081_hash NULL
81245 +_000082_hash bnx2fc_cmd_mgr_alloc 2-3 24873 _000082_hash NULL
81246 +_000084_hash bnx2_nvram_write 4 7790 _000084_hash NULL
81247 +_000085_hash brcmf_sdbrcm_downloadvars 3 42064 _000085_hash NULL
81248 +_000086_hash btmrvl_gpiogap_write 3 35053 _000086_hash NULL
81249 +_000087_hash btmrvl_hscfgcmd_write 3 27143 _000087_hash NULL
81250 +_000088_hash btmrvl_hscmd_write 3 27089 _000088_hash NULL
81251 +_000089_hash btmrvl_hsmode_write 3 42252 _000089_hash NULL
81252 +_000090_hash btmrvl_pscmd_write 3 29504 _000090_hash NULL
81253 +_000091_hash btmrvl_psmode_write 3 3703 _000091_hash NULL
81254 +_000092_hash btrfs_alloc_delayed_item 1 11678 _000092_hash NULL
81255 +_000093_hash cache_do_downcall 3 6926 _000093_hash NULL
81256 +_000094_hash cachefiles_cook_key 2 33274 _000094_hash NULL
81257 +_000095_hash cachefiles_daemon_write 3 43535 _000095_hash NULL
81258 +_000096_hash capi_write 3 35104 _000096_hash NULL
81259 +_000097_hash carl9170_debugfs_write 3 50857 _000097_hash NULL
81260 +_000098_hash cciss_allocate_sg_chain_blocks 2-3 5368 _000098_hash NULL
81261 +_000100_hash cciss_proc_write 3 10259 _000100_hash NULL
81262 +_000101_hash cdrom_read_cdda_old 4 27664 _000101_hash NULL
81263 +_000102_hash ceph_alloc_page_vector 1 18710 _000102_hash NULL
81264 +_000103_hash ceph_buffer_new 1 35974 _000103_hash NULL
81265 +_000104_hash ceph_copy_user_to_page_vector 4 656 _000104_hash NULL
81266 +_000105_hash ceph_get_direct_page_vector 2 41917 _000105_hash NULL
81267 +_000106_hash ceph_msg_new 2 5846 _000106_hash NULL
81268 +_000107_hash ceph_setxattr 4 18913 _000107_hash NULL
81269 +_000108_hash cfi_read_pri 3 24366 _000108_hash NULL
81270 +_000109_hash cgroup_write_string 5 10900 _000109_hash NULL
81271 +_000110_hash cgroup_write_X64 5 54514 _000110_hash NULL
81272 +_000111_hash change_xattr 5 61390 _000111_hash NULL
81273 +_000112_hash check_load_and_stores 2 2143 _000112_hash NULL
81274 +_000113_hash cifs_idmap_key_instantiate 3 54503 _000113_hash NULL
81275 +_000114_hash cifs_security_flags_proc_write 3 5484 _000114_hash NULL
81276 +_000115_hash cifs_setxattr 4 23957 _000115_hash NULL
81277 +_000116_hash cifs_spnego_key_instantiate 3 23588 _000116_hash NULL
81278 +_000117_hash ci_ll_write 4 3740 _000117_hash NULL
81279 +_000118_hash cld_pipe_downcall 3 15058 _000118_hash NULL
81280 +_000119_hash clear_refs_write 3 61904 _000119_hash NULL
81281 +_000120_hash clusterip_proc_write 3 44729 _000120_hash NULL
81282 +_000121_hash cm4040_write 3 58079 _000121_hash NULL
81283 +_000122_hash cm_copy_private_data 2 3649 _000122_hash NULL
81284 +_000123_hash cmm_write 3 2896 _000123_hash NULL
81285 +_000124_hash cm_write 3 36858 _000124_hash NULL
81286 +_000125_hash coda_psdev_write 3 1711 _000125_hash NULL
81287 +_000126_hash codec_reg_read_file 3 36280 _000126_hash NULL
81288 +_000127_hash command_file_write 3 31318 _000127_hash NULL
81289 +_000128_hash command_write 3 58841 _000128_hash NULL
81290 +_000129_hash comm_write 3 44537 _001532_hash NULL nohasharray
81291 +_000130_hash concat_writev 3 21451 _000130_hash NULL
81292 +_000131_hash copy_and_check 3 19089 _000131_hash NULL
81293 +_000132_hash copy_from_user_toio 3 31966 _000132_hash NULL
81294 +_000133_hash copy_items 6 50140 _000133_hash NULL
81295 +_000134_hash copy_macs 4 45534 _000134_hash NULL
81296 +_000135_hash __copy_to_user 3 17551 _000135_hash NULL
81297 +_000136_hash copy_vm86_regs_from_user 3 45340 _000136_hash NULL
81298 +_000137_hash cosa_write 3 1774 _000137_hash NULL
81299 +_000138_hash create_entry 2 33479 _000138_hash NULL
81300 +_000139_hash create_queues 2-3 9088 _000139_hash NULL
81301 +_000141_hash create_xattr 5 54106 _000141_hash NULL
81302 +_000142_hash create_xattr_datum 5 33356 _000142_hash NULL
81303 +_000143_hash csum_partial_copy_fromiovecend 3-4 9957 _000143_hash NULL
81304 +_000145_hash ctrl_out 3-5 8712 _000145_hash NULL
81305 +_000147_hash cx24116_writeregN 4 41975 _000147_hash NULL
81306 +_000148_hash cxacru_cm_get_array 4 4412 _000148_hash NULL
81307 +_000149_hash cxgbi_alloc_big_mem 1 4707 _000149_hash NULL
81308 +_000150_hash dac960_user_command_proc_write 3 3071 _000150_hash NULL
81309 +_000151_hash datablob_format 2 39571 _002156_hash NULL nohasharray
81310 +_000152_hash dccp_feat_clone_sp_val 3 11942 _000152_hash NULL
81311 +_000153_hash dccp_setsockopt_ccid 4 30701 _000153_hash NULL
81312 +_000154_hash dccp_setsockopt_cscov 2 37766 _000154_hash NULL
81313 +_000155_hash dccp_setsockopt_service 4 65336 _000155_hash NULL
81314 +_000156_hash ddb_output_write 3 31902 _000156_hash NULL
81315 +_000157_hash ddebug_proc_write 3 18055 _000157_hash NULL
81316 +_000158_hash dev_config 3 8506 _000158_hash NULL
81317 +_000159_hash device_write 3 45156 _000159_hash NULL
81318 +_000160_hash devm_kzalloc 2 4966 _000160_hash NULL
81319 +_000161_hash devres_alloc 2 551 _000161_hash NULL
81320 +_000162_hash dfs_file_write 3 41196 _000162_hash NULL
81321 +_000163_hash direct_entry 3 38836 _000163_hash NULL
81322 +_000164_hash dispatch_proc_write 3 44320 _000164_hash NULL
81323 +_000165_hash diva_os_copy_from_user 4 7792 _000165_hash NULL
81324 +_000166_hash dlm_alloc_pagevec 1 54296 _000166_hash NULL
81325 +_000167_hash dlmfs_file_read 3 28385 _000167_hash NULL
81326 +_000168_hash dlmfs_file_write 3 6892 _000168_hash NULL
81327 +_000169_hash dm_read 3 15674 _000169_hash NULL
81328 +_000170_hash dm_write 3 2513 _000170_hash NULL
81329 +_000171_hash __dn_setsockopt 5 13060 _000171_hash NULL
81330 +_000172_hash dns_query 3 9676 _000172_hash NULL
81331 +_000173_hash dns_resolver_instantiate 3 63314 _000173_hash NULL
81332 +_000174_hash do_add_counters 3 3992 _000174_hash NULL
81333 +_000175_hash __do_config_autodelink 3 58763 _000175_hash NULL
81334 +_000176_hash do_ip_setsockopt 5 41852 _000176_hash NULL
81335 +_000177_hash do_ipv6_setsockopt 5 18215 _000177_hash NULL
81336 +_000178_hash do_ip_vs_set_ctl 4 48641 _000178_hash NULL
81337 +_000179_hash do_kimage_alloc 3 64827 _000179_hash NULL
81338 +_000180_hash do_register_entry 4 29478 _000180_hash NULL
81339 +_000181_hash do_tty_write 5 44896 _000181_hash NULL
81340 +_000182_hash do_update_counters 4 2259 _000182_hash NULL
81341 +_000183_hash dsp_write 2 46218 _000183_hash NULL
81342 +_000184_hash dup_to_netobj 3 26363 _000184_hash NULL
81343 +_000185_hash dvb_aplay 3 56296 _000185_hash NULL
81344 +_000186_hash dvb_ca_en50221_io_write 3 43533 _000186_hash NULL
81345 +_000187_hash dvbdmx_write 3 19423 _000187_hash NULL
81346 +_000188_hash dvb_play 3 50814 _000188_hash NULL
81347 +_000189_hash dw210x_op_rw 6 39915 _000189_hash NULL
81348 +_000190_hash dwc3_link_state_write 3 12641 _000190_hash NULL
81349 +_000191_hash dwc3_mode_write 3 51997 _000191_hash NULL
81350 +_000192_hash dwc3_testmode_write 3 30516 _000192_hash NULL
81351 +_000193_hash ecryptfs_copy_filename 4 11868 _000193_hash NULL
81352 +_000194_hash ecryptfs_miscdev_write 3 26847 _000194_hash NULL
81353 +_000195_hash ecryptfs_send_miscdev 2 64816 _000195_hash NULL
81354 +_000196_hash efx_tsoh_heap_alloc 2 58545 _000196_hash NULL
81355 +_000197_hash emi26_writememory 4 57908 _000197_hash NULL
81356 +_000198_hash emi62_writememory 4 29731 _000198_hash NULL
81357 +_000199_hash encrypted_instantiate 3 3168 _000199_hash NULL
81358 +_000200_hash encrypted_update 3 13414 _000200_hash NULL
81359 +_000201_hash ep0_write 3 14536 _001328_hash NULL nohasharray
81360 +_000202_hash ep_read 3 58813 _000202_hash NULL
81361 +_000203_hash ep_write 3 59008 _000203_hash NULL
81362 +_000204_hash erst_dbg_write 3 46715 _000204_hash NULL
81363 +_000205_hash esp_alloc_tmp 2 40558 _000205_hash NULL
81364 +_000206_hash exofs_read_lookup_dev_table 3 17733 _000206_hash NULL
81365 +_000207_hash ext4_kvmalloc 1 14796 _000207_hash NULL
81366 +_000208_hash ezusb_writememory 4 45976 _000208_hash NULL
81367 +_000209_hash fanotify_write 3 64623 _000209_hash NULL
81368 +_000210_hash fd_copyin 3 56247 _000210_hash NULL
81369 +_000211_hash ffs_epfile_io 3 64886 _000211_hash NULL
81370 +_000212_hash ffs_prepare_buffer 2 59892 _000212_hash NULL
81371 +_000213_hash f_hidg_write 3 7932 _000213_hash NULL
81372 +_000214_hash file_read_actor 4 1401 _000214_hash NULL
81373 +_000215_hash fill_write_buffer 3 3142 _000215_hash NULL
81374 +_000216_hash fl_create 5 56435 _000216_hash NULL
81375 +_000217_hash ftdi_elan_write 3 57309 _000217_hash NULL
81376 +_000218_hash fuse_conn_limit_write 3 30777 _000218_hash NULL
81377 +_000219_hash fw_iso_buffer_init 3 54582 _000219_hash NULL
81378 +_000220_hash garmin_write_bulk 3 58191 _000220_hash NULL
81379 +_000221_hash garp_attr_create 3 3883 _000221_hash NULL
81380 +_000222_hash get_arg 3 5694 _000222_hash NULL
81381 +_000223_hash getdqbuf 1 62908 _000223_hash NULL
81382 +_000224_hash get_fdb_entries 3 41916 _000224_hash NULL
81383 +_000225_hash get_indirect_ea 4 51869 _000225_hash NULL
81384 +_000226_hash get_registers 3 26187 _000226_hash NULL
81385 +_000227_hash get_scq 2 10897 _000227_hash NULL
81386 +_000228_hash get_server_iovec 2 16804 _000228_hash NULL
81387 +_000229_hash get_ucode_user 3 38202 _000229_hash NULL
81388 +_000230_hash get_user_cpu_mask 2 14861 _000230_hash NULL
81389 +_000231_hash gfs2_alloc_sort_buffer 1 18275 _000231_hash NULL
81390 +_000232_hash gfs2_glock_nq_m 1 20347 _000232_hash NULL
81391 +_000233_hash gigaset_initcs 2 43753 _000233_hash NULL
81392 +_000234_hash gigaset_initdriver 2 1060 _000234_hash NULL
81393 +_000235_hash gs_alloc_req 2 58883 _000235_hash NULL
81394 +_000236_hash gs_buf_alloc 2 25067 _000236_hash NULL
81395 +_000237_hash gsm_data_alloc 3 42437 _000237_hash NULL
81396 +_000238_hash gss_pipe_downcall 3 23182 _000238_hash NULL
81397 +_000239_hash handle_request 9 10024 _000239_hash NULL
81398 +_000240_hash hash_new 1 62224 _000240_hash NULL
81399 +_000241_hash hashtab_create 3 33769 _000241_hash NULL
81400 +_000242_hash hcd_buffer_alloc 2 27495 _000242_hash NULL
81401 +_000243_hash hci_sock_setsockopt 5 28993 _000243_hash NULL
81402 +_000244_hash heap_init 2 49617 _000244_hash NULL
81403 +_000245_hash hest_ghes_dev_register 1 46766 _000245_hash NULL
81404 +_000246_hash hidraw_get_report 3 45609 _000246_hash NULL
81405 +_000247_hash hidraw_report_event 3 49578 _000509_hash NULL nohasharray
81406 +_000248_hash hidraw_send_report 3 23449 _000248_hash NULL
81407 +_000249_hash hpfs_translate_name 3 41497 _000249_hash NULL
81408 +_000250_hash hysdn_conf_write 3 52145 _000250_hash NULL
81409 +_000251_hash hysdn_log_write 3 48694 _000251_hash NULL
81410 +_000252_hash __i2400mu_send_barker 3 23652 _000252_hash NULL
81411 +_000253_hash i2cdev_read 3 1206 _000253_hash NULL
81412 +_000254_hash i2cdev_write 3 23310 _000254_hash NULL
81413 +_000255_hash i2o_parm_field_get 5 34477 _000255_hash NULL
81414 +_000256_hash i2o_parm_table_get 6 61635 _000256_hash NULL
81415 +_000257_hash ib_copy_from_udata 3 59502 _000257_hash NULL
81416 +_000258_hash ib_ucm_alloc_data 3 36885 _000258_hash NULL
81417 +_000259_hash ib_umad_write 3 47993 _000259_hash NULL
81418 +_000260_hash ib_uverbs_unmarshall_recv 5 12251 _000260_hash NULL
81419 +_000261_hash icn_writecmd 2 38629 _000261_hash NULL
81420 +_000262_hash ide_driver_proc_write 3 32493 _000262_hash NULL
81421 +_000263_hash ide_settings_proc_write 3 35110 _000263_hash NULL
81422 +_000264_hash idetape_chrdev_write 3 53976 _000264_hash NULL
81423 +_000265_hash idmap_pipe_downcall 3 14591 _000265_hash NULL
81424 +_000266_hash ieee80211_build_probe_req 7 27660 _000266_hash NULL
81425 +_000267_hash ieee80211_if_write 3 34894 _000267_hash NULL
81426 +_000268_hash if_write 3 51756 _000268_hash NULL
81427 +_000269_hash ilo_write 3 64378 _000269_hash NULL
81428 +_000270_hash ima_write_policy 3 40548 _000270_hash NULL
81429 +_000271_hash init_data_container 1 60709 _000271_hash NULL
81430 +_000272_hash init_send_hfcd 1 34586 _000272_hash NULL
81431 +_000273_hash insert_dent 7 65034 _000273_hash NULL
81432 +_000274_hash interpret_user_input 2 19393 _000274_hash NULL
81433 +_000275_hash int_proc_write 3 39542 _000275_hash NULL
81434 +_000276_hash ioctl_private_iw_point 7 1273 _000276_hash NULL
81435 +_000277_hash iov_iter_copy_from_user 4 31942 _000277_hash NULL
81436 +_000278_hash iov_iter_copy_from_user_atomic 4 56368 _000278_hash NULL
81437 +_000279_hash iowarrior_write 3 18604 _000279_hash NULL
81438 +_000280_hash ipc_alloc 1 1192 _000280_hash NULL
81439 +_000281_hash ipc_rcu_alloc 1 21208 _000281_hash NULL
81440 +_000282_hash ip_options_get_from_user 4 64958 _000282_hash NULL
81441 +_000283_hash ipv6_renew_option 3 38813 _000283_hash NULL
81442 +_000284_hash ip_vs_conn_fill_param_sync 6 29771 _002404_hash NULL nohasharray
81443 +_000285_hash ip_vs_create_timeout_table 2 64478 _000285_hash NULL
81444 +_000286_hash ipw_queue_tx_init 3 49161 _000286_hash NULL
81445 +_000287_hash irda_setsockopt 5 19824 _000287_hash NULL
81446 +_000288_hash irias_new_octseq_value 2 13596 _000288_hash NULL
81447 +_000289_hash ir_lirc_transmit_ir 3 64403 _000289_hash NULL
81448 +_000290_hash irnet_ctrl_write 3 24139 _000290_hash NULL
81449 +_000291_hash isdn_add_channels 3 40905 _000291_hash NULL
81450 +_000292_hash isdn_ppp_fill_rq 2 41428 _000292_hash NULL
81451 +_000293_hash isdn_ppp_write 4 29109 _000293_hash NULL
81452 +_000294_hash isdn_read 3 50021 _000294_hash NULL
81453 +_000295_hash isdn_v110_open 3 2418 _000295_hash NULL
81454 +_000296_hash isdn_writebuf_stub 4 52383 _000296_hash NULL
81455 +_000297_hash islpci_mgt_transmit 5 34133 _000297_hash NULL
81456 +_000298_hash iso_callback 3 43208 _000298_hash NULL
81457 +_000299_hash iso_packets_buffer_init 3 29061 _000299_hash NULL
81458 +_000300_hash it821x_firmware_command 3 8628 _000300_hash NULL
81459 +_000301_hash ivtv_buf_copy_from_user 4 25502 _000301_hash NULL
81460 +_000302_hash iwch_alloc_fastreg_pbl 2 40153 _000302_hash NULL
81461 +_000303_hash iwl_calib_set 3 34400 _002188_hash NULL nohasharray
81462 +_000304_hash jbd2_journal_init_revoke_table 1 36336 _000304_hash NULL
81463 +_000305_hash jffs2_alloc_full_dirent 1 60179 _001111_hash NULL nohasharray
81464 +_000306_hash journal_init_revoke_table 1 56331 _000306_hash NULL
81465 +_000307_hash kcalloc 1-2 27770 _000307_hash NULL
81466 +_000309_hash keyctl_instantiate_key_common 4 47889 _000309_hash NULL
81467 +_000310_hash keyctl_update_key 3 26061 _000310_hash NULL
81468 +_000311_hash __kfifo_alloc 2-3 22173 _000311_hash NULL
81469 +_000313_hash kfifo_copy_from_user 3 5091 _000313_hash NULL
81470 +_000314_hash kmalloc_node 1 50163 _000314_hash NULL
81471 +_000315_hash kmalloc_parameter 1 65279 _000315_hash NULL
81472 +_000316_hash kmem_alloc 1 31920 _000316_hash NULL
81473 +_000317_hash kobj_map 2-3 9566 _000317_hash NULL
81474 +_000319_hash kone_receive 4 4690 _000319_hash NULL
81475 +_000320_hash kone_send 4 63435 _000320_hash NULL
81476 +_000321_hash krealloc 2 14908 _000321_hash NULL
81477 +_000322_hash kvmalloc 1 32646 _000322_hash NULL
81478 +_000323_hash kvm_read_guest_atomic 4 10765 _000323_hash NULL
81479 +_000324_hash kvm_read_guest_cached 4 39666 _000324_hash NULL
81480 +_000325_hash kvm_read_guest_page 5 18074 _000325_hash NULL
81481 +_000326_hash kzalloc 1 54740 _000326_hash NULL
81482 +_000327_hash l2cap_sock_setsockopt 5 50207 _000327_hash NULL
81483 +_000328_hash l2cap_sock_setsockopt_old 4 29346 _000328_hash NULL
81484 +_000329_hash lane2_associate_req 4 45398 _000329_hash NULL
81485 +_000330_hash lbs_debugfs_write 3 48413 _000330_hash NULL
81486 +_000331_hash lcd_write 3 14857 _000331_hash &_000014_hash
81487 +_000332_hash ldm_frag_add 2 5611 _000332_hash NULL
81488 +_000333_hash __lgread 4 31668 _000333_hash NULL
81489 +_000334_hash libipw_alloc_txb 1 27579 _000334_hash NULL
81490 +_000335_hash link_send_sections_long 4 46556 _000335_hash NULL
81491 +_000336_hash listxattr 3 12769 _000336_hash NULL
81492 +_000337_hash LoadBitmap 2 19658 _000337_hash NULL
81493 +_000338_hash load_msg 2 95 _000338_hash NULL
81494 +_000339_hash lpfc_debugfs_dif_err_write 3 17424 _000339_hash NULL
81495 +_000340_hash lp_write 3 9511 _000340_hash NULL
81496 +_000341_hash mb_cache_create 2 17307 _000341_hash NULL
81497 +_000342_hash mce_write 3 26201 _000342_hash NULL
81498 +_000343_hash mcs7830_get_reg 3 33308 _000343_hash NULL
81499 +_000344_hash mcs7830_set_reg 3 31413 _000344_hash NULL
81500 +_000345_hash memcpy_fromiovec 3 55247 _000345_hash NULL
81501 +_000346_hash memcpy_fromiovecend 3-4 2707 _000346_hash NULL
81502 +_000348_hash mempool_kmalloc 2 53831 _000348_hash NULL
81503 +_000349_hash mempool_resize 2 47983 _001821_hash NULL nohasharray
81504 +_000350_hash mem_rw 3 22085 _000350_hash NULL
81505 +_000351_hash mgmt_control 3 7349 _000351_hash NULL
81506 +_000352_hash mgmt_pending_add 5 46976 _000352_hash NULL
81507 +_000353_hash mlx4_ib_alloc_fast_reg_page_list 2 46119 _000353_hash NULL
81508 +_000354_hash mmc_alloc_sg 1 21504 _000354_hash NULL
81509 +_000355_hash mmc_send_bus_test 4 18285 _000355_hash NULL
81510 +_000356_hash mmc_send_cxd_data 5 38655 _000356_hash NULL
81511 +_000357_hash module_alloc_update_bounds 1 47205 _000357_hash NULL
81512 +_000358_hash move_addr_to_kernel 2 32673 _000358_hash NULL
81513 +_000359_hash mpi_alloc_limb_space 1 23190 _000359_hash NULL
81514 +_000360_hash mpi_resize 2 44674 _000360_hash NULL
81515 +_000361_hash mptctl_getiocinfo 2 28545 _000361_hash NULL
81516 +_000362_hash mtdchar_readoob 4 31200 _000362_hash NULL
81517 +_000363_hash mtdchar_write 3 56831 _000363_hash NULL
81518 +_000364_hash mtdchar_writeoob 4 3393 _000364_hash NULL
81519 +_000365_hash mtd_device_parse_register 5 5024 _000365_hash NULL
81520 +_000366_hash mtf_test_write 3 18844 _000366_hash NULL
81521 +_000367_hash mtrr_write 3 59622 _000367_hash NULL
81522 +_000368_hash musb_test_mode_write 3 33518 _000368_hash NULL
81523 +_000369_hash mwifiex_get_common_rates 3 17131 _000369_hash NULL
81524 +_000370_hash mwifiex_update_curr_bss_params 5 16908 _000370_hash NULL
81525 +_000371_hash nand_bch_init 2-3 16280 _001341_hash NULL nohasharray
81526 +_000373_hash ncp_file_write 3 3813 _000373_hash NULL
81527 +_000374_hash ncp__vol2io 5 4804 _000374_hash NULL
81528 +_000375_hash nes_alloc_fast_reg_page_list 2 33523 _000375_hash NULL
81529 +_000376_hash nfc_targets_found 3 29886 _000376_hash NULL
81530 +_000377_hash nfs4_acl_new 1 49806 _000377_hash NULL
81531 +_000378_hash nfs4_write_cached_acl 4 15070 _000378_hash NULL
81532 +_000379_hash nfsd_cache_update 3 59574 _000379_hash NULL
81533 +_000380_hash nfsd_symlink 6 63442 _000380_hash NULL
81534 +_000381_hash nfs_idmap_get_desc 2-4 42990 _000381_hash NULL
81535 +_000383_hash nfs_readdir_make_qstr 3 12509 _000383_hash NULL
81536 +_000384_hash note_last_dentry 3 12285 _000384_hash NULL
81537 +_000385_hash ntfs_copy_from_user 3-5 15072 _000385_hash NULL
81538 +_000387_hash __ntfs_copy_from_user_iovec_inatomic 3-4 38153 _000387_hash NULL
81539 +_000389_hash ntfs_ucstonls 3 23097 _000389_hash NULL
81540 +_000390_hash nvme_alloc_iod 1 56027 _000390_hash NULL
81541 +_000391_hash nvram_write 3 3894 _000391_hash NULL
81542 +_000392_hash o2hb_debug_create 4 18744 _000392_hash NULL
81543 +_000393_hash o2net_send_message_vec 4 879 _001792_hash NULL nohasharray
81544 +_000394_hash ocfs2_control_cfu 2 37750 _000394_hash NULL
81545 +_000395_hash oom_adjust_write 3 41116 _000395_hash NULL
81546 +_000396_hash oom_score_adj_write 3 42594 _000396_hash NULL
81547 +_000397_hash opera1_xilinx_rw 5 31453 _000397_hash NULL
81548 +_000398_hash oprofilefs_ulong_from_user 3 57251 _000398_hash NULL
81549 +_000399_hash opticon_write 4 60775 _000399_hash NULL
81550 +_000400_hash orig_node_add_if 2 32833 _000400_hash NULL
81551 +_000401_hash orig_node_del_if 2 28371 _000401_hash NULL
81552 +_000402_hash p9_check_zc_errors 4 15534 _000402_hash NULL
81553 +_000403_hash packet_buffer_init 2 1607 _000403_hash NULL
81554 +_000404_hash packet_setsockopt 5 17662 _000404_hash NULL
81555 +_000405_hash parse_command 2 37079 _000405_hash NULL
81556 +_000406_hash pcbit_writecmd 2 12332 _000406_hash NULL
81557 +_000407_hash pcmcia_replace_cis 3 57066 _000407_hash NULL
81558 +_000408_hash pgctrl_write 3 50453 _000408_hash NULL
81559 +_000409_hash pg_write 3 40766 _000409_hash NULL
81560 +_000410_hash pidlist_allocate 1 64404 _000410_hash NULL
81561 +_000411_hash pipe_iov_copy_from_user 3 23102 _000411_hash NULL
81562 +_000412_hash pipe_iov_copy_to_user 3 3447 _000412_hash NULL
81563 +_000413_hash pkt_add 3 39897 _000413_hash NULL
81564 +_000414_hash pktgen_if_write 3 55628 _000414_hash NULL
81565 +_000415_hash platform_device_add_data 3 310 _000415_hash NULL
81566 +_000416_hash platform_device_add_resources 3 13289 _000416_hash NULL
81567 +_000417_hash pm_qos_power_write 3 52513 _000417_hash NULL
81568 +_000418_hash pnpbios_proc_write 3 19758 _000418_hash NULL
81569 +_000419_hash pool_allocate 3 42012 _000419_hash NULL
81570 +_000420_hash posix_acl_alloc 1 48063 _000420_hash NULL
81571 +_000421_hash ppp_cp_parse_cr 4 5214 _000421_hash NULL
81572 +_000422_hash ppp_write 3 34034 _000422_hash NULL
81573 +_000423_hash pp_read 3 33210 _000423_hash NULL
81574 +_000424_hash pp_write 3 39554 _000424_hash NULL
81575 +_000425_hash printer_req_alloc 2 62687 _001807_hash NULL nohasharray
81576 +_000426_hash printer_write 3 60276 _000426_hash NULL
81577 +_000427_hash prism2_set_genericelement 3 29277 _000427_hash NULL
81578 +_000428_hash __probe_kernel_read 3 61119 _000428_hash NULL
81579 +_000429_hash __probe_kernel_write 3 29842 _000429_hash NULL
81580 +_000430_hash proc_coredump_filter_write 3 25625 _000430_hash NULL
81581 +_000431_hash _proc_do_string 2 6376 _000431_hash NULL
81582 +_000432_hash process_vm_rw_pages 5-6 15954 _000432_hash NULL
81583 +_000434_hash proc_loginuid_write 3 63648 _000434_hash NULL
81584 +_000435_hash proc_pid_attr_write 3 63845 _000435_hash NULL
81585 +_000436_hash proc_scsi_devinfo_write 3 32064 _000436_hash NULL
81586 +_000437_hash proc_scsi_write 3 29142 _000437_hash NULL
81587 +_000438_hash proc_scsi_write_proc 3 267 _000438_hash NULL
81588 +_000439_hash pstore_mkfile 5 50830 _000439_hash NULL
81589 +_000440_hash pti_char_write 3 60960 _000440_hash NULL
81590 +_000441_hash ptrace_writedata 4 45021 _000441_hash NULL
81591 +_000442_hash pt_write 3 40159 _000442_hash NULL
81592 +_000443_hash pvr2_ioread_set_sync_key 3 59882 _000443_hash NULL
81593 +_000444_hash pvr2_stream_buffer_count 2 33719 _000444_hash NULL
81594 +_000445_hash qdisc_class_hash_alloc 1 18262 _000445_hash NULL
81595 +_000446_hash r3964_write 4 57662 _000446_hash NULL
81596 +_000447_hash raw_seticmpfilter 3 6888 _000447_hash NULL
81597 +_000448_hash raw_setsockopt 5 45800 _000448_hash NULL
81598 +_000449_hash rawv6_seticmpfilter 5 12137 _000449_hash NULL
81599 +_000450_hash ray_cs_essid_proc_write 3 17875 _000450_hash NULL
81600 +_000451_hash rbd_add 3 16366 _000451_hash NULL
81601 +_000452_hash rbd_snap_add 4 19678 _000452_hash NULL
81602 +_000453_hash rdma_set_ib_paths 3 45592 _000453_hash NULL
81603 +_000454_hash rds_page_copy_user 4 35691 _000454_hash NULL
81604 +_000455_hash read 3 9397 _000455_hash NULL
81605 +_000456_hash read_buf 2 20469 _000456_hash NULL
81606 +_000457_hash read_cis_cache 4 29735 _000457_hash NULL
81607 +_000458_hash realloc_buffer 2 25816 _000458_hash NULL
81608 +_000459_hash realloc_packet_buffer 2 25569 _000459_hash NULL
81609 +_000460_hash receive_DataRequest 3 9904 _000460_hash NULL
81610 +_000461_hash recent_mt_proc_write 3 8206 _000461_hash NULL
81611 +_000462_hash regmap_access_read_file 3 37223 _000462_hash NULL
81612 +_000463_hash regmap_bulk_write 4 59049 _000463_hash NULL
81613 +_000464_hash regmap_map_read_file 3 37685 _000464_hash NULL
81614 +_000465_hash regset_tls_set 4 18459 _000465_hash NULL
81615 +_000466_hash reg_w_buf 3 27724 _000466_hash NULL
81616 +_000467_hash reg_w_ixbuf 4 34736 _000467_hash NULL
81617 +_000468_hash remote_settings_file_write 3 22987 _000468_hash NULL
81618 +_000469_hash request_key_auth_new 3 38092 _000469_hash NULL
81619 +_000470_hash restore_i387_fxsave 2 17528 _000470_hash NULL
81620 +_000471_hash revalidate 2 19043 _000471_hash NULL
81621 +_000472_hash rfcomm_sock_setsockopt 5 18254 _000472_hash NULL
81622 +_000473_hash rndis_add_response 2 58544 _000473_hash NULL
81623 +_000474_hash rndis_set_oid 4 6547 _000474_hash NULL
81624 +_000475_hash rngapi_reset 3 34366 _000475_hash NULL
81625 +_000476_hash roccat_common_receive 4 53407 _000476_hash NULL
81626 +_000477_hash roccat_common_send 4 12284 _000477_hash NULL
81627 +_000478_hash rpc_malloc 2 43573 _000478_hash NULL
81628 +_000479_hash rt2x00debug_write_bbp 3 8212 _000479_hash NULL
81629 +_000480_hash rt2x00debug_write_csr 3 64753 _000480_hash NULL
81630 +_000481_hash rt2x00debug_write_eeprom 3 23091 _000481_hash NULL
81631 +_000482_hash rt2x00debug_write_rf 3 38195 _000482_hash NULL
81632 +_000483_hash rts51x_read_mem 4 26577 _000483_hash NULL
81633 +_000484_hash rts51x_read_status 4 11830 _000484_hash NULL
81634 +_000485_hash rts51x_write_mem 4 17598 _000485_hash NULL
81635 +_000486_hash rw_copy_check_uvector 3 34271 _000486_hash NULL
81636 +_000487_hash rxrpc_request_key 3 27235 _000487_hash NULL
81637 +_000488_hash rxrpc_server_keyring 3 16431 _000488_hash NULL
81638 +_000489_hash savemem 3 58129 _000489_hash NULL
81639 +_000490_hash sb16_copy_from_user 10-7-6 55836 _000490_hash NULL
81640 +_000493_hash sched_autogroup_write 3 10984 _000493_hash NULL
81641 +_000494_hash scsi_mode_select 6 37330 _000494_hash NULL
81642 +_000495_hash scsi_tgt_copy_sense 3 26933 _000495_hash NULL
81643 +_000496_hash sctp_auth_create_key 1 51641 _000496_hash NULL
81644 +_000497_hash sctp_getsockopt_delayed_ack 2 9232 _000497_hash NULL
81645 +_000498_hash sctp_getsockopt_local_addrs 2 25178 _000498_hash NULL
81646 +_000499_hash sctp_make_abort_user 3 29654 _000499_hash NULL
81647 +_000500_hash sctp_setsockopt_active_key 3 43755 _000500_hash NULL
81648 +_000501_hash sctp_setsockopt_adaptation_layer 3 26935 _001925_hash NULL nohasharray
81649 +_000502_hash sctp_setsockopt_associnfo 3 51684 _000502_hash NULL
81650 +_000503_hash sctp_setsockopt_auth_chunk 3 30843 _000503_hash NULL
81651 +_000504_hash sctp_setsockopt_auth_key 3 3793 _000504_hash NULL
81652 +_000505_hash sctp_setsockopt_autoclose 3 5775 _000505_hash NULL
81653 +_000506_hash sctp_setsockopt_bindx 3 49870 _000506_hash NULL
81654 +_000507_hash __sctp_setsockopt_connectx 3 46949 _000507_hash NULL
81655 +_000508_hash sctp_setsockopt_context 3 31091 _000508_hash NULL
81656 +_000509_hash sctp_setsockopt_default_send_param 3 49578 _000509_hash &_000247_hash
81657 +_000510_hash sctp_setsockopt_delayed_ack 3 40129 _000510_hash NULL
81658 +_000511_hash sctp_setsockopt_del_key 3 42304 _002281_hash NULL nohasharray
81659 +_000512_hash sctp_setsockopt_events 3 18862 _000512_hash NULL
81660 +_000513_hash sctp_setsockopt_hmac_ident 3 11687 _000513_hash NULL
81661 +_000514_hash sctp_setsockopt_initmsg 3 1383 _000514_hash NULL
81662 +_000515_hash sctp_setsockopt_maxburst 3 28041 _000515_hash NULL
81663 +_000516_hash sctp_setsockopt_maxseg 3 11829 _000516_hash NULL
81664 +_000517_hash sctp_setsockopt_peer_addr_params 3 734 _000517_hash NULL
81665 +_000518_hash sctp_setsockopt_peer_primary_addr 3 13440 _000518_hash NULL
81666 +_000519_hash sctp_setsockopt_rtoinfo 3 30941 _000519_hash NULL
81667 +_000520_hash security_context_to_sid_core 2 29248 _000520_hash NULL
81668 +_000521_hash sel_commit_bools_write 3 46077 _000521_hash NULL
81669 +_000522_hash sel_write_avc_cache_threshold 3 2256 _000522_hash NULL
81670 +_000523_hash sel_write_bool 3 46996 _000523_hash NULL
81671 +_000524_hash sel_write_checkreqprot 3 60774 _000524_hash NULL
81672 +_000525_hash sel_write_disable 3 10511 _000525_hash NULL
81673 +_000526_hash sel_write_enforce 3 48998 _000526_hash NULL
81674 +_000527_hash sel_write_load 3 63830 _000527_hash NULL
81675 +_000528_hash send_bulk_static_data 3 61932 _000528_hash NULL
81676 +_000529_hash send_control_msg 6 48498 _000529_hash NULL
81677 +_000530_hash set_aoe_iflist 2 42737 _000530_hash NULL
81678 +_000531_hash setkey_unaligned 3 39474 _000531_hash NULL
81679 +_000532_hash set_registers 3 53582 _000532_hash NULL
81680 +_000533_hash setsockopt 5 54539 _000533_hash NULL
81681 +_000534_hash setup_req 3 5848 _000534_hash NULL
81682 +_000535_hash setup_window 7 59178 _000535_hash NULL
81683 +_000536_hash setxattr 4 37006 _000536_hash NULL
81684 +_000537_hash sfq_alloc 1 2861 _000537_hash NULL
81685 +_000538_hash sg_kmalloc 1 50240 _000538_hash NULL
81686 +_000539_hash sgl_map_user_pages 2 30610 _000539_hash NULL
81687 +_000540_hash shash_setkey_unaligned 3 8620 _000540_hash NULL
81688 +_000541_hash shmem_xattr_alloc 2 61190 _000541_hash NULL
81689 +_000542_hash sierra_setup_urb 5 46029 _000542_hash NULL
81690 +_000543_hash simple_transaction_get 3 50633 _000543_hash NULL
81691 +_000544_hash simple_write_to_buffer 2-5 3122 _000544_hash NULL
81692 +_000546_hash sisusb_send_bulk_msg 3 17864 _000546_hash NULL
81693 +_000547_hash skb_add_data 3 48363 _000547_hash NULL
81694 +_000548_hash skb_do_copy_data_nocache 5 12465 _000548_hash NULL
81695 +_000549_hash sl_alloc_bufs 2 50380 _000549_hash NULL
81696 +_000550_hash sl_realloc_bufs 2 64086 _000550_hash NULL
81697 +_000551_hash smk_write_ambient 3 45691 _000551_hash NULL
81698 +_000552_hash smk_write_cipso 3 17989 _000552_hash NULL
81699 +_000553_hash smk_write_direct 3 46363 _000553_hash NULL
81700 +_000554_hash smk_write_doi 3 49621 _000554_hash NULL
81701 +_000555_hash smk_write_load_list 3 52280 _000555_hash NULL
81702 +_000556_hash smk_write_logging 3 2618 _000556_hash NULL
81703 +_000557_hash smk_write_netlbladdr 3 42525 _000557_hash NULL
81704 +_000558_hash smk_write_onlycap 3 14400 _000558_hash NULL
81705 +_000559_hash snd_ctl_elem_user_tlv 3 11695 _000559_hash NULL
81706 +_000560_hash snd_emu10k1_fx8010_read 5 9605 _000560_hash NULL
81707 +_000561_hash snd_emu10k1_synth_copy_from_user 3-5 9061 _000561_hash NULL
81708 +_000563_hash snd_gus_dram_poke 4 18525 _000563_hash NULL
81709 +_000564_hash snd_hdsp_playback_copy 5 20676 _000564_hash NULL
81710 +_000565_hash snd_info_entry_write 3 63474 _000565_hash NULL
81711 +_000566_hash snd_korg1212_copy_from 6 36169 _000566_hash NULL
81712 +_000567_hash snd_mem_proc_write 3 9786 _000567_hash NULL
81713 +_000568_hash snd_midi_channel_init_set 1 30092 _000568_hash NULL
81714 +_000569_hash snd_midi_event_new 1 9893 _000750_hash NULL nohasharray
81715 +_000570_hash snd_opl4_mem_proc_write 5 9670 _000570_hash NULL
81716 +_000571_hash snd_pcm_aio_read 3 13900 _000571_hash NULL
81717 +_000572_hash snd_pcm_aio_write 3 28738 _000572_hash NULL
81718 +_000573_hash snd_pcm_oss_write1 3 10872 _000573_hash NULL
81719 +_000574_hash snd_pcm_oss_write2 3 27332 _000574_hash NULL
81720 +_000575_hash snd_rawmidi_kernel_write1 4 56847 _000575_hash NULL
81721 +_000576_hash snd_rme9652_playback_copy 5 20970 _000576_hash NULL
81722 +_000577_hash snd_sb_csp_load_user 3 45190 _000577_hash NULL
81723 +_000578_hash snd_usb_ctl_msg 8 8436 _000578_hash NULL
81724 +_000579_hash sock_bindtodevice 3 50942 _000579_hash NULL
81725 +_000580_hash sock_kmalloc 2 62205 _000580_hash NULL
81726 +_000581_hash spidev_write 3 44510 _000581_hash NULL
81727 +_000582_hash squashfs_read_table 3 16945 _000582_hash NULL
81728 +_000583_hash srpt_alloc_ioctx 2-3 51042 _000583_hash NULL
81729 +_000585_hash srpt_alloc_ioctx_ring 2 49330 _000585_hash NULL
81730 +_000586_hash st5481_setup_isocpipes 6-4 61340 _000586_hash NULL
81731 +_000587_hash sta_agg_status_write 3 45164 _000587_hash NULL
81732 +_000588_hash svc_setsockopt 5 36876 _000588_hash NULL
81733 +_000589_hash sys_add_key 4 61288 _000589_hash NULL
81734 +_000590_hash sys_modify_ldt 3 18824 _000590_hash NULL
81735 +_000591_hash sys_semtimedop 3 4486 _000591_hash NULL
81736 +_000592_hash sys_setdomainname 2 4373 _000592_hash NULL
81737 +_000593_hash sys_sethostname 2 42962 _000593_hash NULL
81738 +_000594_hash tda10048_writeregbulk 4 11050 _000594_hash NULL
81739 +_000595_hash tipc_log_resize 1 34803 _000595_hash NULL
81740 +_000596_hash tomoyo_write_self 3 45161 _000596_hash NULL
81741 +_000597_hash tower_write 3 8580 _000597_hash NULL
81742 +_000598_hash tpm_write 3 50798 _000598_hash NULL
81743 +_000599_hash trusted_instantiate 3 4710 _000599_hash NULL
81744 +_000600_hash trusted_update 3 12664 _000600_hash NULL
81745 +_000601_hash tt_changes_fill_buffer 3 62649 _000601_hash NULL
81746 +_000602_hash tty_buffer_alloc 2 45437 _000602_hash NULL
81747 +_000603_hash __tun_chr_ioctl 4 22300 _000603_hash NULL
81748 +_000604_hash ubi_more_leb_change_data 4 63534 _000604_hash NULL
81749 +_000605_hash ubi_more_update_data 4 39189 _000605_hash NULL
81750 +_000606_hash ubi_resize_volume 2 50172 _000606_hash NULL
81751 +_000607_hash udf_alloc_i_data 2 35786 _000607_hash NULL
81752 +_000608_hash uea_idma_write 3 64139 _000608_hash NULL
81753 +_000609_hash uea_request 4 47613 _000609_hash NULL
81754 +_000610_hash uea_send_modem_cmd 3 3888 _000610_hash NULL
81755 +_000611_hash uio_write 3 43202 _000611_hash NULL
81756 +_000612_hash um_idi_write 3 18293 _000612_hash NULL
81757 +_000613_hash us122l_ctl_msg 8 13330 _000613_hash NULL
81758 +_000614_hash usb_alloc_urb 1 43436 _000614_hash NULL
81759 +_000615_hash usblp_new_writeurb 2 22894 _000615_hash NULL
81760 +_000616_hash usblp_write 3 23178 _000616_hash NULL
81761 +_000617_hash usbtest_alloc_urb 3-5 34446 _000617_hash NULL
81762 +_000619_hash usbtmc_write 3 64340 _000619_hash NULL
81763 +_000620_hash user_instantiate 3 26131 _000620_hash NULL
81764 +_000621_hash user_update 3 41332 _000621_hash NULL
81765 +_000622_hash uvc_simplify_fraction 3 31303 _000622_hash NULL
81766 +_000623_hash uwb_rc_cmd_done 4 35892 _000623_hash NULL
81767 +_000624_hash uwb_rc_neh_grok_event 3 55799 _000624_hash NULL
81768 +_000625_hash v9fs_alloc_rdir_buf 2 42150 _000625_hash NULL
81769 +_000626_hash __vb2_perform_fileio 3 63033 _000626_hash NULL
81770 +_000627_hash vc_do_resize 3-4 48842 _000627_hash NULL
81771 +_000629_hash vcs_write 3 3910 _000629_hash NULL
81772 +_000630_hash vfd_write 3 14717 _000630_hash NULL
81773 +_000631_hash vga_arb_write 3 36112 _000631_hash NULL
81774 +_000632_hash vga_switcheroo_debugfs_write 3 33984 _000632_hash NULL
81775 +_000633_hash vhci_get_user 3 45039 _000633_hash NULL
81776 +_000634_hash video_proc_write 3 6724 _000634_hash NULL
81777 +_000635_hash vlsi_alloc_ring 3-4 57003 _000635_hash NULL
81778 +_000637_hash __vmalloc 1 61168 _000637_hash NULL
81779 +_000638_hash vmalloc_32 1 1135 _000638_hash NULL
81780 +_000639_hash vmalloc_32_user 1 37519 _000639_hash NULL
81781 +_000640_hash vmalloc_exec 1 36132 _000640_hash NULL
81782 +_000641_hash vmalloc_node 1 58700 _000641_hash NULL
81783 +_000642_hash __vmalloc_node_flags 1 30352 _000642_hash NULL
81784 +_000643_hash vmalloc_user 1 32308 _000643_hash NULL
81785 +_000644_hash vol_cdev_direct_write 3 20751 _000644_hash NULL
81786 +_000645_hash vp_request_msix_vectors 2 28849 _000645_hash NULL
81787 +_000646_hash vring_add_indirect 3-4 20737 _000646_hash NULL
81788 +_000648_hash vring_new_virtqueue 1 9671 _000648_hash NULL
81789 +_000649_hash vxge_os_dma_malloc 2 46184 _000649_hash NULL
81790 +_000650_hash vxge_os_dma_malloc_async 3 56348 _000650_hash NULL
81791 +_000651_hash wdm_write 3 53735 _000651_hash NULL
81792 +_000652_hash wiimote_hid_send 3 48528 _000652_hash NULL
81793 +_000653_hash wl1273_fm_fops_write 3 60621 _000653_hash NULL
81794 +_000654_hash wlc_phy_loadsampletable_nphy 3 64367 _000654_hash NULL
81795 +_000655_hash write 3 62671 _000655_hash NULL
81796 +_000656_hash write_flush 3 50803 _000656_hash NULL
81797 +_000657_hash write_rio 3 54837 _000657_hash NULL
81798 +_000658_hash x25_asy_change_mtu 2 26928 _000658_hash NULL
81799 +_000659_hash xdi_copy_from_user 4 8395 _000659_hash NULL
81800 +_000660_hash xfrm_dst_alloc_copy 3 3034 _000660_hash NULL
81801 +_000661_hash xfrm_user_policy 4 62573 _000661_hash NULL
81802 +_000662_hash xfs_attrmulti_attr_set 4 59346 _000662_hash NULL
81803 +_000663_hash xfs_handle_to_dentry 3 12135 _000663_hash NULL
81804 +_000664_hash __xip_file_write 3 2733 _000664_hash NULL
81805 +_000665_hash xprt_rdma_allocate 2 31372 _000665_hash NULL
81806 +_000666_hash zd_usb_iowrite16v_async 3 23984 _000666_hash NULL
81807 +_000667_hash zd_usb_read_fw 4 22049 _000667_hash NULL
81808 +_000668_hash zerocopy_sg_from_iovec 3 11828 _000668_hash NULL
81809 +_000669_hash zoran_write 3 22404 _000669_hash NULL
81810 +_000671_hash acpi_ex_allocate_name_string 2 7685 _000671_hash NULL
81811 +_000672_hash acpi_os_allocate_zeroed 1 37422 _000672_hash NULL
81812 +_000673_hash acpi_ut_initialize_buffer 2 47143 _002314_hash NULL nohasharray
81813 +_000674_hash ad7879_spi_xfer 3 36311 _000674_hash NULL
81814 +_000675_hash add_new_gdb 3 27643 _000675_hash NULL
81815 +_000676_hash add_numbered_child 5 14273 _000676_hash NULL
81816 +_000677_hash add_res_range 4 21310 _000677_hash NULL
81817 +_000678_hash addtgt 3 54703 _000678_hash NULL
81818 +_000679_hash add_uuid 4 49831 _000679_hash NULL
81819 +_000680_hash afs_cell_alloc 2 24052 _000680_hash NULL
81820 +_000681_hash aggr_recv_addba_req_evt 4 38037 _000681_hash NULL
81821 +_000682_hash agp_create_memory 1 1075 _000682_hash NULL
81822 +_000683_hash agp_create_user_memory 1 62955 _000683_hash NULL
81823 +_000684_hash alg_setsockopt 5 20985 _000684_hash NULL
81824 +_000685_hash alloc_async 1 14208 _000685_hash NULL
81825 +_000686_hash ___alloc_bootmem_nopanic 1 53626 _000686_hash NULL
81826 +_000687_hash alloc_buf 1 34532 _000687_hash NULL
81827 +_000688_hash alloc_chunk 1 49575 _000688_hash NULL
81828 +_000689_hash alloc_context 1 41283 _000689_hash NULL
81829 +_000690_hash alloc_ctrl_packet 1 44667 _000690_hash NULL
81830 +_000691_hash alloc_data_packet 1 46698 _000691_hash NULL
81831 +_000692_hash alloc_dca_provider 2 59670 _000692_hash NULL
81832 +_000693_hash __alloc_dev_table 2 54343 _000693_hash NULL
81833 +_000694_hash alloc_ep 1 17269 _000694_hash NULL
81834 +_000695_hash __alloc_extent_buffer 3 15093 _000695_hash NULL
81835 +_000696_hash alloc_group_attrs 2 9194 _000719_hash NULL nohasharray
81836 +_000697_hash alloc_large_system_hash 2 64490 _000697_hash NULL
81837 +_000698_hash alloc_netdev_mqs 1 30030 _000698_hash NULL
81838 +_000699_hash __alloc_objio_seg 1 7203 _000699_hash NULL
81839 +_000700_hash alloc_ring 2-4 15345 _000700_hash NULL
81840 +_000701_hash alloc_ring 2-4 39151 _000701_hash NULL
81841 +_000704_hash alloc_session 1-2 64171 _000704_hash NULL
81842 +_000708_hash alloc_smp_req 1 51337 _000708_hash NULL
81843 +_000709_hash alloc_smp_resp 1 3566 _000709_hash NULL
81844 +_000710_hash alloc_ts_config 1 45775 _000710_hash NULL
81845 +_000711_hash alloc_upcall 2 62186 _000711_hash NULL
81846 +_000712_hash altera_drscan 2 48698 _000712_hash NULL
81847 +_000713_hash altera_irscan 2 62396 _000713_hash NULL
81848 +_000714_hash altera_set_dr_post 2 54291 _000714_hash NULL
81849 +_000715_hash altera_set_dr_pre 2 64862 _000715_hash NULL
81850 +_000716_hash altera_set_ir_post 2 20948 _000716_hash NULL
81851 +_000717_hash altera_set_ir_pre 2 54103 _000717_hash NULL
81852 +_000718_hash altera_swap_dr 2 50090 _000718_hash NULL
81853 +_000719_hash altera_swap_ir 2 9194 _000719_hash &_000696_hash
81854 +_000720_hash amd_create_gatt_pages 1 20537 _000720_hash NULL
81855 +_000721_hash aoechr_write 3 62883 _001352_hash NULL nohasharray
81856 +_000722_hash applesmc_create_nodes 2 49392 _000722_hash NULL
81857 +_000723_hash array_zalloc 1-2 7519 _000723_hash NULL
81858 +_000725_hash arvo_sysfs_read 6 31617 _000725_hash NULL
81859 +_000726_hash arvo_sysfs_write 6 3311 _000726_hash NULL
81860 +_000727_hash asd_store_update_bios 4 10165 _000727_hash NULL
81861 +_000728_hash ata_host_alloc 2 46094 _000728_hash NULL
81862 +_000729_hash atalk_sendmsg 4 21677 _000729_hash NULL
81863 +_000730_hash ath6kl_cfg80211_connect_event 7-9-8 13443 _000730_hash NULL
81864 +_000731_hash ath6kl_mgmt_tx 9 21153 _000731_hash NULL
81865 +_000732_hash ath6kl_wmi_roam_tbl_event_rx 3 43440 _000732_hash NULL
81866 +_000733_hash ath6kl_wmi_send_mgmt_cmd 7 17347 _000733_hash NULL
81867 +_000734_hash ath_descdma_setup 5 12257 _000734_hash NULL
81868 +_000735_hash ath_rx_edma_init 2 65483 _000735_hash NULL
81869 +_000736_hash ati_create_gatt_pages 1 4722 _000736_hash NULL
81870 +_000737_hash au0828_init_isoc 2-3 61917 _000737_hash NULL
81871 +_000739_hash audit_init_entry 1 38644 _000739_hash NULL
81872 +_000740_hash ax25_sendmsg 4 62770 _000740_hash NULL
81873 +_000741_hash b1_alloc_card 1 36155 _000741_hash NULL
81874 +_000742_hash b43_nphy_load_samples 3 36481 _000742_hash NULL
81875 +_000743_hash bio_copy_user_iov 4 37660 _000743_hash NULL
81876 +_000744_hash __bio_map_kern 2-3 47379 _000744_hash NULL
81877 +_000746_hash blk_register_region 1-2 51424 _000746_hash NULL
81878 +_000748_hash bm_entry_write 3 28338 _000748_hash NULL
81879 +_000749_hash bm_realloc_pages 2 9431 _000749_hash NULL
81880 +_000750_hash bm_register_write 3 9893 _000750_hash &_000569_hash
81881 +_000751_hash bm_status_write 3 12964 _000751_hash NULL
81882 +_000752_hash br_mdb_rehash 2 42643 _000752_hash NULL
81883 +_000753_hash btrfs_copy_from_user 3 43806 _000753_hash NULL
81884 +_000754_hash btrfs_insert_delayed_dir_index 4 63720 _000754_hash NULL
81885 +_000755_hash __btrfs_map_block 3 49839 _000755_hash NULL
81886 +_000756_hash __c4iw_init_resource_fifo 3 8334 _000756_hash NULL
81887 +_000757_hash cache_downcall 3 13666 _000757_hash NULL
81888 +_000758_hash cache_slow_downcall 2 8570 _000758_hash NULL
81889 +_000759_hash ca_extend 2 64541 _000759_hash NULL
81890 +_000760_hash caif_seqpkt_sendmsg 4 22961 _000760_hash NULL
81891 +_000761_hash caif_stream_sendmsg 4 9110 _000761_hash NULL
81892 +_000762_hash carl9170_cmd_buf 3 950 _000762_hash NULL
81893 +_000763_hash cdev_add 2-3 38176 _000763_hash NULL
81894 +_000765_hash cdrom_read_cdda 4 50478 _000765_hash NULL
81895 +_000766_hash ceph_dns_resolve_name 1 62488 _000766_hash NULL
81896 +_000767_hash ceph_msgpool_get 2 54258 _000767_hash NULL
81897 +_000768_hash cfg80211_connect_result 4-6 56515 _000768_hash NULL
81898 +_000770_hash cfg80211_disconnected 4 57 _000770_hash NULL
81899 +_000771_hash cfg80211_inform_bss 8 19332 _000771_hash NULL
81900 +_000772_hash cfg80211_inform_bss_frame 4 41078 _000772_hash NULL
81901 +_000773_hash cfg80211_mlme_register_mgmt 5 19852 _000773_hash NULL
81902 +_000774_hash cfg80211_roamed_bss 4-6 50198 _000774_hash NULL
81903 +_000776_hash cifs_readdata_alloc 1 50318 _000776_hash NULL
81904 +_000777_hash cifs_readv_from_socket 3 19109 _000777_hash NULL
81905 +_000778_hash cifs_writedata_alloc 1 32880 _000778_hash NULL
81906 +_000779_hash cnic_alloc_dma 3 34641 _000779_hash NULL
81907 +_000780_hash configfs_write_file 3 61621 _000780_hash NULL
81908 +_000781_hash construct_key 3 11329 _000781_hash NULL
81909 +_000782_hash context_alloc 3 24645 _000782_hash NULL
81910 +_000783_hash copy_to_user 3 57835 _000783_hash NULL
81911 +_000784_hash create_attr_set 1 22861 _000784_hash NULL
81912 +_000785_hash create_bounce_buffer 3 39155 _000785_hash NULL
81913 +_000786_hash create_gpadl_header 2 19064 _000786_hash NULL
81914 +_000787_hash _create_sg_bios 4 31244 _000787_hash NULL
81915 +_000788_hash cryptd_alloc_instance 2-3 18048 _000788_hash NULL
81916 +_000790_hash crypto_ahash_setkey 3 55134 _000790_hash NULL
81917 +_000791_hash crypto_alloc_instance2 3 25277 _000791_hash NULL
81918 +_000792_hash crypto_shash_setkey 3 60483 _000792_hash NULL
81919 +_000793_hash cx231xx_init_bulk 3-2 47024 _000793_hash NULL
81920 +_000794_hash cx231xx_init_isoc 2-3 56453 _000794_hash NULL
81921 +_000796_hash cx231xx_init_vbi_isoc 2-3 28053 _000796_hash NULL
81922 +_000798_hash cxgb_alloc_mem 1 24007 _000798_hash NULL
81923 +_000799_hash cxgbi_device_portmap_create 3 25747 _000799_hash NULL
81924 +_000800_hash cxgbi_device_register 1-2 36746 _000800_hash NULL
81925 +_000802_hash __cxio_init_resource_fifo 3 23447 _000802_hash NULL
81926 +_000803_hash dccp_sendmsg 4 56058 _000803_hash NULL
81927 +_000804_hash ddp_make_gl 1 12179 _000804_hash NULL
81928 +_000805_hash depth_write 3 3021 _000805_hash NULL
81929 +_000806_hash dev_irnet_write 3 11398 _000806_hash NULL
81930 +_000807_hash dev_set_alias 3 50084 _000807_hash NULL
81931 +_000808_hash dev_write 3 7708 _000808_hash NULL
81932 +_000809_hash dfs_global_file_write 3 6112 _000809_hash NULL
81933 +_000810_hash dgram_sendmsg 4 45679 _000810_hash NULL
81934 +_000811_hash disconnect 4 32521 _000811_hash NULL
81935 +_000812_hash dma_attach 6-7 50831 _000812_hash NULL
81936 +_000814_hash dn_sendmsg 4 38390 _000814_hash NULL
81937 +_000815_hash do_dccp_setsockopt 5 54377 _000815_hash NULL
81938 +_000816_hash do_jffs2_setxattr 5 25910 _000816_hash NULL
81939 +_000817_hash do_msgsnd 4 1387 _000817_hash NULL
81940 +_000818_hash do_raw_setsockopt 5 55215 _000818_hash NULL
81941 +_000819_hash do_readv_writev 4 51849 _000819_hash NULL
81942 +_000820_hash do_sync 1 9604 _000820_hash NULL
81943 +_000821_hash dup_array 3 33551 _000821_hash NULL
81944 +_000822_hash dvb_audio_write 3 51275 _000822_hash NULL
81945 +_000823_hash dvb_ca_en50221_init 4 45718 _000823_hash NULL
81946 +_000824_hash dvb_video_write 3 754 _000824_hash NULL
81947 +_000825_hash econet_sendmsg 4 51430 _000825_hash NULL
81948 +_000826_hash ecryptfs_decode_and_decrypt_filename 5 10379 _000826_hash NULL
81949 +_000827_hash ecryptfs_encrypt_and_encode_filename 6 2109 _000827_hash NULL
81950 +_000828_hash ecryptfs_send_message_locked 2 31801 _000828_hash NULL
81951 +_000829_hash edac_device_alloc_ctl_info 1 5941 _000829_hash NULL
81952 +_000830_hash edac_mc_alloc 1 54846 _000830_hash NULL
81953 +_000831_hash edac_pci_alloc_ctl_info 1 63388 _000831_hash NULL
81954 +_000832_hash efivar_create_sysfs_entry 2 19485 _000832_hash NULL
81955 +_000833_hash em28xx_alloc_isoc 4 46892 _000833_hash NULL
81956 +_000834_hash enable_write 3 30456 _000834_hash NULL
81957 +_000835_hash enclosure_register 3 57412 _000835_hash NULL
81958 +_000836_hash ext4_kvzalloc 1 47605 _000836_hash NULL
81959 +_000837_hash extend_netdev_table 2 31680 _000837_hash NULL
81960 +_000838_hash __feat_register_sp 6 64712 _000838_hash NULL
81961 +_000839_hash __ffs_ep0_read_events 3 48868 _000839_hash NULL
81962 +_000840_hash ffs_ep0_write 3 9438 _000840_hash NULL
81963 +_000841_hash ffs_epfile_read 3 18775 _000841_hash NULL
81964 +_000842_hash ffs_epfile_write 3 48014 _000842_hash NULL
81965 +_000843_hash fib_info_hash_alloc 1 9075 _000843_hash NULL
81966 +_000844_hash fillonedir 3 41746 _000844_hash NULL
81967 +_000845_hash flexcop_device_kmalloc 1 54793 _000845_hash NULL
81968 +_000846_hash frame_alloc 4 15981 _000846_hash NULL
81969 +_000847_hash fw_node_create 2 9559 _000847_hash NULL
81970 +_000848_hash garmin_read_process 3 27509 _000848_hash NULL
81971 +_000849_hash garp_request_join 4 7471 _000849_hash NULL
81972 +_000850_hash get_derived_key 4 61100 _000850_hash NULL
81973 +_000851_hash get_entry 4 16003 _000851_hash NULL
81974 +_000852_hash get_free_de 2 33714 _000852_hash NULL
81975 +_000853_hash get_new_cssid 2 51665 _000853_hash NULL
81976 +_000854_hash getxattr 4 24398 _000854_hash NULL
81977 +_000855_hash gspca_dev_probe2 4 59833 _000855_hash NULL
81978 +_000856_hash hcd_alloc_coherent 5 55862 _000856_hash NULL
81979 +_000857_hash hci_sock_sendmsg 4 37420 _000857_hash NULL
81980 +_000858_hash hid_register_field 2-3 4874 _000858_hash NULL
81981 +_000860_hash hid_report_raw_event 4 7024 _000860_hash NULL
81982 +_000861_hash hpi_alloc_control_cache 1 35351 _000861_hash NULL
81983 +_000862_hash hugetlbfs_read_actor 2-5-4 34547 _000862_hash NULL
81984 +_000865_hash hvc_alloc 4 12579 _000865_hash NULL
81985 +_000866_hash __hwahc_dev_set_key 5 46328 _000866_hash NULL
81986 +_000867_hash i2400m_zrealloc_2x 3 54166 _001430_hash NULL nohasharray
81987 +_000868_hash ib_alloc_device 1 26483 _000868_hash NULL
81988 +_000869_hash ib_create_send_mad 5 1196 _000869_hash NULL
81989 +_000870_hash ibmasm_new_command 2 25714 _000870_hash NULL
81990 +_000871_hash ib_send_cm_drep 3 50186 _000871_hash NULL
81991 +_000872_hash ib_send_cm_mra 4 60202 _000872_hash NULL
81992 +_000873_hash ib_send_cm_rtu 3 63138 _000873_hash NULL
81993 +_000874_hash ieee80211_key_alloc 3 19065 _000874_hash NULL
81994 +_000875_hash ieee80211_mgmt_tx 9 46860 _000875_hash NULL
81995 +_000876_hash ieee80211_send_probe_req 6 6924 _000876_hash NULL
81996 +_000877_hash if_writecmd 2 815 _000877_hash NULL
81997 +_000878_hash init_bch 1-2 64130 _000878_hash NULL
81998 +_000880_hash init_ipath 1 48187 _000880_hash NULL
81999 +_000881_hash init_list_set 2-3 39188 _000881_hash NULL
82000 +_000883_hash init_q 4 132 _000883_hash NULL
82001 +_000884_hash init_state 2 60165 _000884_hash NULL
82002 +_000885_hash init_tag_map 3 57515 _000885_hash NULL
82003 +_000886_hash input_ff_create 2 21240 _000886_hash NULL
82004 +_000887_hash input_mt_init_slots 2 31183 _000887_hash NULL
82005 +_000888_hash interfaces 2 38859 _000888_hash NULL
82006 +_000889_hash ioat2_alloc_ring 2 11172 _000889_hash NULL
82007 +_000890_hash ip_generic_getfrag 3-4 12187 _000890_hash NULL
82008 +_000892_hash ipr_alloc_ucode_buffer 1 40199 _000892_hash NULL
82009 +_000893_hash ip_set_alloc 1 57953 _000893_hash NULL
82010 +_000894_hash ipv6_flowlabel_opt 3 58135 _001125_hash NULL nohasharray
82011 +_000895_hash ipv6_renew_options 5 28867 _000895_hash NULL
82012 +_000896_hash ipxrtr_route_packet 4 54036 _000896_hash NULL
82013 +_000897_hash irda_sendmsg 4 4388 _000897_hash NULL
82014 +_000898_hash irda_sendmsg_dgram 4 38563 _000898_hash NULL
82015 +_000899_hash irda_sendmsg_ultra 4 42047 _000899_hash NULL
82016 +_000900_hash irias_add_octseq_attrib 4 29983 _000900_hash NULL
82017 +_000901_hash irq_alloc_generic_chip 2 26650 _000901_hash NULL
82018 +_000902_hash irq_domain_add_linear 2 29236 _000902_hash NULL
82019 +_000903_hash iscsi_alloc_session 3 49390 _000903_hash NULL
82020 +_000904_hash iscsi_create_conn 2 50425 _000904_hash NULL
82021 +_000905_hash iscsi_create_endpoint 1 15193 _000905_hash NULL
82022 +_000906_hash iscsi_create_iface 5 38510 _000906_hash NULL
82023 +_000907_hash iscsi_decode_text_input 4 58292 _000907_hash NULL
82024 +_000908_hash iscsi_pool_init 2-4 54913 _000908_hash NULL
82025 +_000910_hash iscsit_dump_data_payload 2 38683 _000910_hash NULL
82026 +_000911_hash isdn_write 3 45863 _000911_hash NULL
82027 +_000912_hash isku_receive 4 54130 _000912_hash NULL
82028 +_000913_hash isku_send 4 41542 _000913_hash NULL
82029 +_000914_hash islpci_mgt_transaction 5 23610 _000914_hash NULL
82030 +_000915_hash iso_sched_alloc 1 13377 _002079_hash NULL nohasharray
82031 +_000916_hash ivtv_v4l2_write 3 39226 _000916_hash NULL
82032 +_000917_hash iwl_trans_txq_alloc 3 36147 _000917_hash NULL
82033 +_000918_hash iwmct_fw_parser_init 4 37876 _000918_hash NULL
82034 +_000919_hash iwm_notif_send 6 12295 _000919_hash NULL
82035 +_000920_hash iwm_ntf_calib_res 3 11686 _000920_hash NULL
82036 +_000921_hash iwm_umac_set_config_var 4 17320 _000921_hash NULL
82037 +_000922_hash ixgbe_alloc_q_vector 3-5 45428 _000922_hash NULL
82038 +_000924_hash jbd2_journal_init_revoke 2 51088 _000924_hash NULL
82039 +_000925_hash jffs2_write_dirent 5 37311 _000925_hash NULL
82040 +_000926_hash journal_init_revoke 2 56933 _000926_hash NULL
82041 +_000927_hash keyctl_instantiate_key 3 41855 _000927_hash NULL
82042 +_000928_hash keyctl_instantiate_key_iov 3 16969 _000928_hash NULL
82043 +_000929_hash __kfifo_from_user 3 20399 _000929_hash NULL
82044 +_000930_hash kimage_crash_alloc 3 3233 _000930_hash NULL
82045 +_000931_hash kimage_normal_alloc 3 31140 _000931_hash NULL
82046 +_000932_hash kmem_realloc 2 37489 _000932_hash NULL
82047 +_000933_hash kmem_zalloc 1 11510 _000933_hash NULL
82048 +_000934_hash koneplus_send 4 18226 _000934_hash NULL
82049 +_000935_hash koneplus_sysfs_read 6 42792 _000935_hash NULL
82050 +_000936_hash kovaplus_send 4 10009 _000936_hash NULL
82051 +_000937_hash kvm_read_guest_page_mmu 6 37611 _000937_hash NULL
82052 +_000938_hash kvm_set_irq_routing 3 48704 _000938_hash NULL
82053 +_000939_hash kvm_write_guest_cached 4 11106 _000939_hash NULL
82054 +_000940_hash kvm_write_guest_page 5 63555 _000940_hash NULL
82055 +_000941_hash l2cap_skbuff_fromiovec 3-4 35003 _000941_hash NULL
82056 +_000943_hash l2tp_ip_sendmsg 4 50411 _000943_hash NULL
82057 +_000944_hash l2tp_session_create 1 25286 _000944_hash NULL
82058 +_000945_hash lc_create 3 48662 _000945_hash NULL
82059 +_000946_hash leaf_dealloc 3 29566 _000946_hash NULL
82060 +_000947_hash linear_conf 2 23485 _000947_hash NULL
82061 +_000948_hash lirc_buffer_init 2-3 53282 _000948_hash NULL
82062 +_000950_hash llc_ui_sendmsg 4 24987 _000950_hash NULL
82063 +_000951_hash lpfc_sli4_queue_alloc 3 62646 _000951_hash NULL
82064 +_000952_hash mce_request_packet 3 1073 _000952_hash NULL
82065 +_000953_hash mdiobus_alloc_size 1 52259 _000953_hash NULL
82066 +_000954_hash media_entity_init 2-4 15870 _001556_hash NULL nohasharray
82067 +_000956_hash memstick_alloc_host 1 142 _000956_hash NULL
82068 +_000957_hash mesh_table_alloc 1 22305 _000957_hash NULL
82069 +_000958_hash mfd_add_devices 4 56753 _000958_hash NULL
82070 +_000959_hash mISDN_sock_sendmsg 4 41035 _000959_hash NULL
82071 +_000960_hash mmc_alloc_host 1 48097 _000960_hash NULL
82072 +_000961_hash mmc_test_alloc_mem 3 28102 _000961_hash NULL
82073 +_000962_hash mpi_alloc 1 18094 _000962_hash NULL
82074 +_000963_hash mpihelp_mul_karatsuba_case 5-3 23918 _000963_hash NULL
82075 +_000964_hash mpihelp_mul_n 4 16405 _000964_hash NULL
82076 +_000965_hash mpi_set_bit 2 15104 _000965_hash NULL
82077 +_000966_hash mpi_set_highbit 2 37327 _001420_hash NULL nohasharray
82078 +_000967_hash mtd_concat_create 2 14416 _000967_hash NULL
82079 +_000968_hash mvumi_alloc_mem_resource 3 47750 _000968_hash NULL
82080 +_000969_hash mwifiex_11n_create_rx_reorder_tbl 4 63806 _000969_hash NULL
82081 +_000970_hash mwifiex_alloc_sdio_mpa_buffers 2-3 60961 _000970_hash NULL
82082 +_000972_hash mwl8k_cmd_set_beacon 4 23110 _000972_hash NULL
82083 +_000973_hash neigh_hash_alloc 1 17595 _000973_hash NULL
82084 +_000974_hash netlink_sendmsg 4 33708 _001172_hash NULL nohasharray
82085 +_000975_hash netxen_alloc_sds_rings 2 13417 _000975_hash NULL
82086 +_000976_hash new_bind_ctl 2 35324 _000976_hash NULL
82087 +_000977_hash new_dir 3 31919 _000977_hash NULL
82088 +_000978_hash new_tape_buffer 2 32866 _000978_hash NULL
82089 +_000979_hash nfc_llcp_build_tlv 3 19536 _000979_hash NULL
82090 +_000980_hash nfc_llcp_send_i_frame 3 59130 _000980_hash NULL
82091 +_000981_hash nfs4_alloc_slots 1 2454 _000981_hash NULL
82092 +_000982_hash nfsctl_transaction_write 3 64800 _000982_hash NULL
82093 +_000983_hash nfs_idmap_request_key 3 30208 _000983_hash NULL
82094 +_000984_hash nfs_readdata_alloc 1 9990 _000984_hash NULL
82095 +_000985_hash nfs_writedata_alloc 1 62868 _000985_hash NULL
82096 +_000986_hash nl_pid_hash_zalloc 1 23314 _000986_hash NULL
82097 +_000987_hash nr_sendmsg 4 53656 _000987_hash NULL
82098 +_000988_hash nsm_create_handle 4 38060 _000988_hash NULL
82099 +_000989_hash ntfs_copy_from_user_iovec 3-6 49829 _000989_hash NULL
82100 +_000991_hash ntfs_file_buffered_write 4-6 41442 _000991_hash NULL
82101 +_000993_hash __ntfs_malloc 1 34022 _000993_hash NULL
82102 +_000994_hash nvme_alloc_queue 3 46865 _000994_hash NULL
82103 +_000995_hash ocfs2_acl_from_xattr 2 21604 _000995_hash NULL
82104 +_000996_hash ocfs2_control_message 3 19564 _000996_hash NULL
82105 +_000997_hash opera1_usb_i2c_msgxfer 4 64521 _000997_hash NULL
82106 +_000998_hash _ore_get_io_state 3 2166 _000998_hash NULL
82107 +_000999_hash orig_hash_add_if 2 53676 _000999_hash NULL
82108 +_001000_hash orig_hash_del_if 2 45080 _001000_hash NULL
82109 +_001001_hash orinoco_set_key 5-7 17878 _001001_hash NULL
82110 +_001003_hash osdmap_set_max_osd 2 57630 _001003_hash NULL
82111 +_001004_hash _osd_realloc_seg 3 54352 _001004_hash NULL
82112 +_001005_hash OSDSetBlock 2-4 38986 _001005_hash NULL
82113 +_001007_hash osst_execute 7-6 17607 _001007_hash NULL
82114 +_001008_hash osst_write 3 31581 _001008_hash NULL
82115 +_001009_hash otp_read 2-5-4 10594 _001009_hash NULL
82116 +_001012_hash ovs_vport_alloc 1 33475 _001012_hash NULL
82117 +_001013_hash packet_sendmsg_spkt 4 28885 _001013_hash NULL
82118 +_001014_hash pair_device 4 61175 _001708_hash NULL nohasharray
82119 +_001015_hash pccard_store_cis 6 18176 _001015_hash NULL
82120 +_001016_hash pci_add_cap_save_buffer 3 3426 _001016_hash NULL
82121 +_001017_hash pcnet32_realloc_rx_ring 3 36598 _001017_hash NULL
82122 +_001018_hash pcnet32_realloc_tx_ring 3 38428 _001018_hash NULL
82123 +_001019_hash pcpu_mem_zalloc 1 22948 _001019_hash NULL
82124 +_001020_hash pep_sendmsg 4 62524 _001020_hash NULL
82125 +_001021_hash pfkey_sendmsg 4 47394 _001021_hash NULL
82126 +_001022_hash pidlist_resize 2 496 _001022_hash NULL
82127 +_001023_hash pin_code_reply 4 46510 _001023_hash NULL
82128 +_001024_hash ping_getfrag 3-4 8360 _001024_hash NULL
82129 +_001026_hash pipe_set_size 2 5204 _001026_hash NULL
82130 +_001027_hash pkt_bio_alloc 1 48284 _001027_hash NULL
82131 +_001028_hash platform_create_bundle 4-6 12785 _001028_hash NULL
82132 +_001030_hash play_iframe 3 8219 _001030_hash NULL
82133 +_001031_hash pm8001_store_update_fw 4 55716 _001031_hash NULL
82134 +_001032_hash pmcraid_alloc_sglist 1 9864 _001032_hash NULL
82135 +_001033_hash pn533_dep_link_up 5 7659 _001033_hash NULL
82136 +_001034_hash pnp_alloc 1 24869 _001419_hash NULL nohasharray
82137 +_001035_hash pn_sendmsg 4 12640 _001035_hash NULL
82138 +_001036_hash pppoe_sendmsg 4 48039 _001036_hash NULL
82139 +_001037_hash pppol2tp_sendmsg 4 56420 _001037_hash NULL
82140 +_001038_hash process_vm_rw 3-5 47533 _001038_hash NULL
82141 +_001040_hash process_vm_rw_single_vec 1-2 26213 _001040_hash NULL
82142 +_001042_hash proc_write 3 51003 _001042_hash NULL
82143 +_001043_hash profile_load 3 58267 _001043_hash NULL
82144 +_001044_hash profile_remove 3 8556 _001044_hash NULL
82145 +_001045_hash profile_replace 3 14652 _001045_hash NULL
82146 +_001046_hash pscsi_get_bio 1 56103 _001046_hash NULL
82147 +_001047_hash pyra_send 4 12061 _001047_hash NULL
82148 +_001048_hash qc_capture 3 19298 _001048_hash NULL
82149 +_001049_hash qla4xxx_alloc_work 2 44813 _001049_hash NULL
82150 +_001050_hash qlcnic_alloc_msix_entries 2 46160 _001050_hash NULL
82151 +_001051_hash qlcnic_alloc_sds_rings 2 26795 _001051_hash NULL
82152 +_001052_hash queue_received_packet 5 9657 _001052_hash NULL
82153 +_001053_hash raw_send_hdrinc 4 58803 _001053_hash NULL
82154 +_001054_hash raw_sendmsg 4 23078 _001054_hash &_000022_hash
82155 +_001055_hash rawsock_sendmsg 4 60010 _001055_hash NULL
82156 +_001056_hash rawv6_send_hdrinc 3 35425 _001056_hash NULL
82157 +_001057_hash rb_alloc 1 3102 _001057_hash NULL
82158 +_001058_hash rbd_alloc_coll 1 33678 _001058_hash NULL
82159 +_001059_hash rbd_create_rw_ops 2 4605 _001059_hash NULL
82160 +_001060_hash rds_ib_inc_copy_to_user 3 55007 _001060_hash NULL
82161 +_001061_hash rds_iw_inc_copy_to_user 3 29214 _001061_hash NULL
82162 +_001062_hash rds_message_alloc 1 10517 _001062_hash NULL
82163 +_001063_hash rds_message_copy_from_user 3 45510 _001063_hash NULL
82164 +_001064_hash rds_message_inc_copy_to_user 3 26540 _001064_hash NULL
82165 +_001065_hash redrat3_transmit_ir 3 64244 _001065_hash NULL
82166 +_001066_hash regcache_rbtree_insert_to_block 5 58009 _001066_hash NULL
82167 +_001067_hash _regmap_raw_write 4 42652 _001067_hash NULL
82168 +_001068_hash regmap_register_patch 3 21681 _001068_hash NULL
82169 +_001069_hash relay_alloc_page_array 1 52735 _001069_hash NULL
82170 +_001070_hash remove_uuid 4 64505 _001070_hash NULL
82171 +_001071_hash reshape_ring 2 29147 _001071_hash NULL
82172 +_001072_hash RESIZE_IF_NEEDED 2 56286 _001072_hash NULL
82173 +_001073_hash resize_stripes 2 61650 _001073_hash NULL
82174 +_001074_hash rfcomm_sock_sendmsg 4 37661 _001074_hash NULL
82175 +_001075_hash rose_sendmsg 4 20249 _001075_hash NULL
82176 +_001076_hash rxrpc_send_data 5 21553 _001076_hash NULL
82177 +_001077_hash rxrpc_setsockopt 5 50286 _001077_hash NULL
82178 +_001078_hash saa7146_vmalloc_build_pgtable 2 19780 _001078_hash NULL
82179 +_001079_hash saa7164_buffer_alloc_user 2 9627 _001079_hash NULL
82180 +_001081_hash sco_send_frame 3 41815 _001081_hash NULL
82181 +_001082_hash scsi_host_alloc 2 63041 _001082_hash NULL
82182 +_001083_hash scsi_tgt_kspace_exec 8 9522 _001083_hash NULL
82183 +_001084_hash sctp_sendmsg 4 61919 _001084_hash NULL
82184 +_001085_hash sctp_setsockopt 5 44788 _001085_hash NULL
82185 +_001086_hash sctp_setsockopt_connectx 3 6073 _001086_hash NULL
82186 +_001087_hash sctp_setsockopt_connectx_old 3 22631 _001087_hash NULL
82187 +_001088_hash sctp_tsnmap_init 2 36446 _001088_hash NULL
82188 +_001089_hash sctp_user_addto_chunk 2-3 62047 _001089_hash NULL
82189 +_001091_hash security_context_to_sid 2 19839 _001091_hash NULL
82190 +_001092_hash security_context_to_sid_default 2 3492 _001092_hash NULL
82191 +_001093_hash security_context_to_sid_force 2 20724 _001093_hash NULL
82192 +_001094_hash selinux_transaction_write 3 59038 _001094_hash NULL
82193 +_001095_hash sel_write_access 3 51704 _001095_hash NULL
82194 +_001096_hash sel_write_create 3 11353 _001096_hash NULL
82195 +_001097_hash sel_write_member 3 28800 _001097_hash NULL
82196 +_001098_hash sel_write_relabel 3 55195 _001098_hash NULL
82197 +_001099_hash sel_write_user 3 45060 _001099_hash NULL
82198 +_001100_hash __seq_open_private 3 40715 _001100_hash NULL
82199 +_001101_hash serverworks_create_gatt_pages 1 46582 _001101_hash NULL
82200 +_001102_hash set_connectable 4 56458 _001102_hash NULL
82201 +_001103_hash set_dev_class 4 39645 _001697_hash NULL nohasharray
82202 +_001104_hash set_discoverable 4 48141 _001104_hash NULL
82203 +_001105_hash setkey 3 14987 _001105_hash NULL
82204 +_001106_hash set_le 4 30581 _001106_hash NULL
82205 +_001107_hash set_link_security 4 4502 _001107_hash NULL
82206 +_001108_hash set_local_name 4 55757 _001108_hash NULL
82207 +_001109_hash set_powered 4 12129 _001109_hash NULL
82208 +_001110_hash set_ssp 4 62411 _001110_hash NULL
82209 +_001111_hash sg_build_sgat 3 60179 _001111_hash &_000305_hash
82210 +_001112_hash sg_read_oxfer 3 51724 _001112_hash NULL
82211 +_001113_hash shmem_xattr_set 4 11843 _001113_hash NULL
82212 +_001114_hash simple_alloc_urb 3 60420 _001114_hash NULL
82213 +_001115_hash sisusb_send_bridge_packet 2 11649 _001115_hash NULL
82214 +_001116_hash sisusb_send_packet 2 20891 _001116_hash NULL
82215 +_001117_hash skb_add_data_nocache 4 4682 _001117_hash NULL
82216 +_001118_hash skb_copy_datagram_from_iovec 2-5-4 52014 _001118_hash NULL
82217 +_001121_hash skb_copy_to_page_nocache 6 58624 _001121_hash NULL
82218 +_001122_hash sk_chk_filter 2 42095 _001122_hash NULL
82219 +_001123_hash skcipher_sendmsg 4 30290 _001123_hash NULL
82220 +_001124_hash sl_change_mtu 2 7396 _001124_hash NULL
82221 +_001125_hash slhc_init 1-2 58135 _001125_hash &_000894_hash
82222 +_001127_hash sm501_create_subdev 3-4 48668 _001127_hash NULL
82223 +_001129_hash smk_write_access 3 49561 _001129_hash NULL
82224 +_001130_hash snapshot_write 3 28351 _001130_hash NULL
82225 +_001131_hash snd_ac97_pcm_assign 2 30218 _001131_hash NULL
82226 +_001132_hash snd_card_create 4 64418 _001411_hash NULL nohasharray
82227 +_001133_hash snd_emux_create_port 3 42533 _001133_hash NULL
82228 +_001134_hash snd_gus_dram_write 4 38784 _001134_hash NULL
82229 +_001135_hash snd_midi_channel_alloc_set 1 28153 _001135_hash NULL
82230 +_001136_hash _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 _001136_hash NULL
82231 +_001137_hash snd_pcm_oss_sync1 2 45298 _001137_hash NULL
82232 +_001138_hash snd_pcm_oss_write 3 38108 _001138_hash NULL
82233 +_001139_hash snd_pcm_plugin_build 5 25505 _001139_hash NULL
82234 +_001140_hash snd_rawmidi_kernel_write 3 25106 _001140_hash NULL
82235 +_001141_hash snd_rawmidi_write 3 28008 _001141_hash NULL
82236 +_001142_hash snd_rme32_playback_copy 5 43732 _001142_hash NULL
82237 +_001143_hash snd_rme96_playback_copy 5 13111 _001143_hash NULL
82238 +_001144_hash snd_seq_device_new 4 31753 _001144_hash NULL
82239 +_001145_hash snd_seq_oss_readq_new 2 14283 _001145_hash NULL
82240 +_001146_hash snd_vx_create 4 40948 _001146_hash NULL
82241 +_001147_hash sock_setsockopt 5 50088 _001147_hash NULL
82242 +_001148_hash sound_write 3 5102 _001148_hash NULL
82243 +_001149_hash _sp2d_alloc 1 16944 _001149_hash NULL
82244 +_001150_hash spi_alloc_master 2 45223 _001150_hash NULL
82245 +_001151_hash spidev_message 3 5518 _001151_hash NULL
82246 +_001152_hash spi_register_board_info 2 35651 _001152_hash NULL
82247 +_001153_hash squashfs_cache_init 2 41656 _001153_hash NULL
82248 +_001154_hash squashfs_read_data 6 59440 _001154_hash NULL
82249 +_001155_hash srp_alloc_iu 2 44227 _001155_hash NULL
82250 +_001156_hash srp_iu_pool_alloc 2 17920 _001156_hash NULL
82251 +_001157_hash srp_ring_alloc 2 26760 _001157_hash NULL
82252 +_001159_hash start_isoc_chain 2 565 _001159_hash NULL
82253 +_001160_hash stk_prepare_sio_buffers 2 57168 _001160_hash NULL
82254 +_001161_hash store_iwmct_log_level 4 60209 _001161_hash NULL
82255 +_001162_hash store_iwmct_log_level_fw 4 1974 _001162_hash NULL
82256 +_001163_hash st_write 3 16874 _001163_hash NULL
82257 +_001164_hash svc_pool_map_alloc_arrays 2 47181 _001164_hash NULL
82258 +_001165_hash symtab_init 2 61050 _001165_hash NULL
82259 +_001166_hash sys_bind 3 10799 _001166_hash NULL
82260 +_001167_hash sys_connect 3 15291 _001167_hash NULL
82261 +_001168_hash sys_flistxattr 3 41407 _001168_hash NULL
82262 +_001169_hash sys_fsetxattr 4 49736 _001169_hash NULL
82263 +_001170_hash sysfs_write_file 3 57116 _001170_hash NULL
82264 +_001171_hash sys_ipc 3 4889 _001171_hash NULL
82265 +_001172_hash sys_keyctl 4 33708 _001172_hash &_000974_hash
82266 +_001173_hash sys_listxattr 3 27833 _001173_hash NULL
82267 +_001174_hash sys_llistxattr 3 4532 _001174_hash NULL
82268 +_001175_hash sys_lsetxattr 4 61177 _001175_hash NULL
82269 +_001176_hash sys_mq_timedsend 3 57661 _001176_hash NULL
82270 +_001177_hash sys_sched_setaffinity 2 32046 _001177_hash NULL
82271 +_001178_hash sys_semop 3 39457 _001178_hash NULL
82272 +_001179_hash sys_sendto 6 20809 _001179_hash NULL
82273 +_001180_hash sys_setxattr 4 37880 _001180_hash NULL
82274 +_001181_hash t4_alloc_mem 1 32342 _001181_hash NULL
82275 +_001182_hash tcf_hash_create 4 54360 _001182_hash NULL
82276 +_001183_hash __team_options_register 3 63941 _001183_hash NULL
82277 +_001184_hash test_unaligned_bulk 3 52333 _001184_hash NULL
82278 +_001185_hash tifm_alloc_adapter 1 10903 _001185_hash NULL
82279 +_001186_hash timeout_write 3 50991 _001186_hash NULL
82280 +_001187_hash tipc_link_send_sections_fast 4 37920 _001187_hash NULL
82281 +_001188_hash tipc_subseq_alloc 1 5957 _001188_hash NULL
82282 +_001189_hash tm6000_read_write_usb 7 50774 _001189_hash NULL
82283 +_001190_hash tnode_alloc 1 49407 _001190_hash NULL
82284 +_001191_hash tomoyo_commit_ok 2 20167 _001191_hash NULL
82285 +_001192_hash tomoyo_scan_bprm 2-4 15642 _001192_hash NULL
82286 +_001194_hash tps65910_i2c_write 3 39531 _001194_hash NULL
82287 +_001195_hash ts_write 3 64336 _001195_hash NULL
82288 +_001196_hash ttusb2_msg 4 3100 _001196_hash NULL
82289 +_001197_hash tty_write 3 5494 _001197_hash NULL
82290 +_001198_hash ubi_dbg_check_all_ff 4 59810 _001198_hash NULL
82291 +_001199_hash ubi_dbg_check_write 5 48525 _001199_hash NULL
82292 +_001200_hash ubifs_setxattr 4 59650 _001370_hash NULL nohasharray
82293 +_001201_hash udf_sb_alloc_partition_maps 2 62313 _001201_hash NULL
82294 +_001202_hash udplite_getfrag 3-4 14479 _001202_hash NULL
82295 +_001204_hash ulong_write_file 3 26485 _001204_hash NULL
82296 +_001205_hash unix_dgram_sendmsg 4 45699 _001205_hash NULL
82297 +_001206_hash unix_stream_sendmsg 4 61455 _001206_hash NULL
82298 +_001207_hash unlink_queued 3-4 645 _001207_hash NULL
82299 +_001208_hash update_pmkid 4 2481 _001208_hash NULL
82300 +_001209_hash usb_alloc_coherent 2 65444 _001209_hash NULL
82301 +_001210_hash uvc_alloc_buffers 2 9656 _001210_hash NULL
82302 +_001211_hash uvc_alloc_entity 3 20836 _001211_hash NULL
82303 +_001212_hash v4l2_ctrl_new 7 38725 _001212_hash NULL
82304 +_001213_hash v4l2_event_subscribe 3 19510 _001213_hash NULL
82305 +_001214_hash vb2_read 3 42703 _001214_hash NULL
82306 +_001215_hash vb2_write 3 31948 _001215_hash NULL
82307 +_001216_hash vc_resize 2-3 3585 _001216_hash NULL
82308 +_001218_hash __vhost_add_used_n 3 26554 _001218_hash NULL
82309 +_001219_hash __videobuf_alloc_vb 1 27062 _001219_hash NULL
82310 +_001220_hash videobuf_dma_init_kernel 3 6963 _001220_hash NULL
82311 +_001221_hash virtqueue_add_buf 3-4 59470 _001221_hash NULL
82312 +_001223_hash vmalloc 1 15464 _001223_hash NULL
82313 +_001224_hash vmalloc_to_sg 2 58354 _001224_hash NULL
82314 +_001225_hash vol_cdev_write 3 40915 _001225_hash NULL
82315 +_001226_hash vxge_device_register 4 7752 _001226_hash NULL
82316 +_001227_hash __vxge_hw_channel_allocate 3 55462 _001227_hash NULL
82317 +_001228_hash vzalloc 1 47421 _001228_hash NULL
82318 +_001229_hash vzalloc_node 1 23424 _001229_hash NULL
82319 +_001230_hash wa_nep_queue 2 8858 _001230_hash NULL
82320 +_001231_hash __wa_xfer_setup_segs 2 56725 _001231_hash NULL
82321 +_001232_hash wiphy_new 2 2482 _001232_hash NULL
82322 +_001233_hash wpan_phy_alloc 1 48056 _001233_hash NULL
82323 +_001234_hash wusb_ccm_mac 7 32199 _001234_hash NULL
82324 +_001235_hash x25_sendmsg 4 12487 _001235_hash NULL
82325 +_001236_hash xfrm_hash_alloc 1 10997 _001236_hash NULL
82326 +_001237_hash _xfs_buf_get_pages 2 46811 _001237_hash NULL
82327 +_001238_hash xfs_da_buf_make 1 55845 _001238_hash NULL
82328 +_001239_hash xfs_da_grow_inode_int 3 21785 _001239_hash NULL
82329 +_001240_hash xfs_dir_cilookup_result 3 64288 _001240_hash NULL
82330 +_001241_hash xfs_iext_add_indirect_multi 3 32400 _001241_hash NULL
82331 +_001242_hash xfs_iext_inline_to_direct 2 12384 _001242_hash NULL
82332 +_001243_hash xfs_iroot_realloc 2 46826 _001243_hash NULL
82333 +_001244_hash xhci_alloc_stream_info 3 63902 _001244_hash NULL
82334 +_001245_hash xlog_recover_add_to_trans 4 62839 _001245_hash NULL
82335 +_001246_hash xprt_alloc 2 1475 _001246_hash NULL
82336 +_001247_hash xt_alloc_table_info 1 57903 _001247_hash NULL
82337 +_001248_hash _zd_iowrite32v_async_locked 3 39034 _001248_hash NULL
82338 +_001249_hash zd_usb_iowrite16v 3 49744 _001249_hash NULL
82339 +_001250_hash acpi_ds_build_internal_package_obj 3 58271 _001250_hash NULL
82340 +_001251_hash acpi_system_read_event 3 55362 _001251_hash NULL
82341 +_001252_hash acpi_ut_create_buffer_object 1 42030 _001252_hash NULL
82342 +_001253_hash acpi_ut_create_package_object 1 17594 _001253_hash NULL
82343 +_001254_hash acpi_ut_create_string_object 1 15360 _001254_hash NULL
82344 +_001255_hash ad7879_spi_multi_read 3 8218 _001255_hash NULL
82345 +_001256_hash add_child 4 45201 _001256_hash NULL
82346 +_001257_hash add_port 2 54941 _001257_hash NULL
82347 +_001258_hash adu_read 3 24177 _001258_hash NULL
82348 +_001259_hash afs_cell_create 2 27346 _001259_hash NULL
82349 +_001260_hash agp_generic_alloc_user 1 9470 _001260_hash NULL
82350 +_001261_hash alloc_agpphysmem_i8xx 1 39427 _001261_hash NULL
82351 +_001262_hash allocate_cnodes 1 5329 _001262_hash NULL
82352 +_001263_hash ___alloc_bootmem 1 11410 _001263_hash NULL
82353 +_001264_hash __alloc_bootmem_nopanic 1 65397 _001264_hash NULL
82354 +_001265_hash alloc_bulk_urbs_generic 5 12127 _001265_hash NULL
82355 +_001266_hash alloc_candev 1-2 7776 _001266_hash NULL
82356 +_001268_hash ____alloc_ei_netdev 1 51475 _001268_hash NULL
82357 +_001269_hash alloc_etherdev_mqs 1 36450 _001269_hash NULL
82358 +_001270_hash alloc_extent_buffer 3 52824 _001270_hash NULL
82359 +_001271_hash alloc_fcdev 1 18780 _001271_hash NULL
82360 +_001272_hash alloc_fddidev 1 15382 _001272_hash NULL
82361 +_001273_hash alloc_hippi_dev 1 51320 _001273_hash NULL
82362 +_001274_hash alloc_irdadev 1 19140 _001274_hash NULL
82363 +_001275_hash alloc_ltalkdev 1 38071 _001275_hash NULL
82364 +_001276_hash alloc_one_pg_vec_page 1 10747 _001276_hash NULL
82365 +_001277_hash alloc_orinocodev 1 21371 _001277_hash NULL
82366 +_001279_hash alloc_trdev 1 16399 _001279_hash NULL
82367 +_001280_hash async_setkey 3 35521 _001280_hash NULL
82368 +_001281_hash ata_host_alloc_pinfo 3 17325 _001281_hash NULL
82369 +_001284_hash ath6kl_connect_event 7-9-8 14267 _001284_hash NULL
82370 +_001285_hash ath6kl_fwlog_block_read 3 49836 _001285_hash NULL
82371 +_001286_hash ath6kl_fwlog_read 3 32101 _001286_hash NULL
82372 +_001287_hash ath_rx_init 2 43564 _001287_hash NULL
82373 +_001288_hash ath_tx_init 2 60515 _001288_hash NULL
82374 +_001289_hash atm_get_addr 3 31221 _001289_hash NULL
82375 +_001290_hash av7110_ipack_init 2 46655 _001290_hash NULL
82376 +_001291_hash bdx_rxdb_create 1 46525 _001291_hash NULL
82377 +_001292_hash bdx_tx_db_init 2 41719 _001292_hash NULL
82378 +_001293_hash bio_map_kern 3 64751 _001293_hash NULL
82379 +_001294_hash bits_to_user 3 47733 _001294_hash NULL
82380 +_001295_hash __blk_queue_init_tags 2 9778 _001295_hash NULL
82381 +_001296_hash blk_queue_resize_tags 2 28670 _001296_hash NULL
82382 +_001297_hash blk_rq_map_user_iov 5 16772 _001297_hash NULL
82383 +_001298_hash bm_init 2 13529 _001298_hash NULL
82384 +_001299_hash brcmf_alloc_wdev 1 60347 _001299_hash NULL
82385 +_001300_hash btrfs_insert_dir_item 4 59304 _001300_hash NULL
82386 +_001301_hash btrfs_map_block 3 64379 _001301_hash NULL
82387 +_001302_hash c4_add_card 3 54968 _001302_hash NULL
82388 +_001303_hash cache_read 3 24790 _001303_hash NULL
82389 +_001304_hash cache_write 3 13589 _001304_hash NULL
82390 +_001305_hash calc_hmac 3 32010 _001305_hash NULL
82391 +_001306_hash ccid_getsockopt_builtin_ccids 2 53634 _001306_hash NULL
82392 +_001307_hash ceph_copy_page_vector_to_user 4 31270 _001307_hash NULL
82393 +_001308_hash ceph_read_dir 3 17005 _001308_hash NULL
82394 +_001309_hash cfg80211_roamed 5-7 32632 _001309_hash NULL
82395 +_001311_hash ci_ll_init 3 12930 _001311_hash NULL
82396 +_001312_hash coda_psdev_read 3 35029 _001312_hash NULL
82397 +_001313_hash construct_key_and_link 4 8321 _001313_hash NULL
82398 +_001314_hash copy_counters_to_user 5 17027 _001824_hash NULL nohasharray
82399 +_001315_hash copy_entries_to_user 1 52367 _001315_hash NULL
82400 +_001316_hash copy_from_buf 4 27308 _001316_hash NULL
82401 +_001317_hash copy_oldmem_page 3 26164 _001317_hash NULL
82402 +_001318_hash copy_to_user_fromio 3 57432 _001318_hash NULL
82403 +_001319_hash cryptd_hash_setkey 3 42781 _001319_hash NULL
82404 +_001320_hash crypto_authenc_esn_setkey 3 6985 _001320_hash NULL
82405 +_001321_hash crypto_authenc_setkey 3 80 _001321_hash NULL
82406 +_001322_hash cx18_copy_buf_to_user 4 22735 _001322_hash NULL
82407 +_001324_hash cxgbi_ddp_reserve 4 30091 _001324_hash NULL
82408 +_001325_hash datablob_hmac_append 3 40038 _001325_hash NULL
82409 +_001326_hash datablob_hmac_verify 4 24786 _001326_hash NULL
82410 +_001327_hash dataflash_read_fact_otp 3-2 33204 _001327_hash NULL
82411 +_001328_hash dataflash_read_user_otp 3-2 14536 _001328_hash &_000201_hash
82412 +_001329_hash dccp_feat_register_sp 5 17914 _001329_hash NULL
82413 +_001330_hash ddb_input_read 3 9743 _001330_hash NULL
82414 +_001331_hash dev_read 3 56369 _001331_hash NULL
82415 +_001332_hash diva_os_copy_to_user 4 48508 _001332_hash NULL
82416 +_001333_hash diva_os_malloc 2 16406 _001333_hash NULL
82417 +_001334_hash dlm_dir_lookup 4 56662 _001334_hash NULL
82418 +_001335_hash dm_vcalloc 1-2 16814 _001335_hash NULL
82419 +_001337_hash do_proc_readlink 3 14096 _001337_hash NULL
82420 +_001338_hash do_readlink 2 43518 _001338_hash NULL
82421 +_001339_hash __do_replace 5 37227 _001339_hash NULL
82422 +_001340_hash do_sigpending 2 9766 _001340_hash NULL
82423 +_001341_hash drbd_setsockopt 5 16280 _001341_hash &_000371_hash
82424 +_001342_hash dsp_buffer_alloc 2 11684 _001342_hash NULL
82425 +_001343_hash dump_midi 3 51040 _001343_hash NULL
82426 +_001344_hash dvb_dmxdev_set_buffer_size 2 55643 _001344_hash NULL
82427 +_001345_hash dvb_dvr_set_buffer_size 2 9840 _001345_hash NULL
82428 +_001346_hash dvb_ringbuffer_pkt_read_user 3-5 4303 _001346_hash NULL
82429 +_001348_hash dvb_ringbuffer_read_user 3 56702 _001348_hash NULL
82430 +_001349_hash ecryptfs_filldir 3 6622 _001349_hash NULL
82431 +_001350_hash ecryptfs_readlink 3 40775 _001350_hash NULL
82432 +_001351_hash ecryptfs_send_message 2 18322 _001351_hash NULL
82433 +_001352_hash em28xx_init_isoc 4 62883 _001352_hash &_000721_hash
82434 +_001353_hash et61x251_read 3 25420 _001353_hash NULL
82435 +_001354_hash ext4_add_new_descs 3 19509 _001354_hash NULL
82436 +_001355_hash fat_ioctl_filldir 3 36621 _001355_hash NULL
82437 +_001356_hash fd_copyout 3 59323 _001356_hash NULL
82438 +_001357_hash f_hidg_read 3 6238 _001357_hash NULL
82439 +_001358_hash filldir 3 55137 _001358_hash NULL
82440 +_001359_hash filldir64 3 46469 _001359_hash NULL
82441 +_001360_hash fops_read 3 40672 _001360_hash NULL
82442 +_001361_hash from_buffer 3 18625 _001361_hash NULL
82443 +_001362_hash fsm_init 2 16134 _001362_hash NULL
82444 +_001363_hash get_subdir 3 62581 _001363_hash NULL
82445 +_001364_hash gspca_dev_probe 4 2570 _001364_hash NULL
82446 +_001365_hash handle_received_packet 3 22457 _001365_hash NULL
82447 +_001366_hash hash_setkey 3 48310 _001366_hash NULL
82448 +_001367_hash hdlcdrv_register 2 6792 _001367_hash NULL
82449 +_001368_hash hdpvr_read 3 9273 _001368_hash NULL
82450 +_001369_hash hid_input_report 4 32458 _001369_hash NULL
82451 +_001370_hash hidraw_read 3 59650 _001370_hash &_001200_hash
82452 +_001371_hash HiSax_readstatus 2 15752 _001371_hash NULL
82453 +_001373_hash __hwahc_op_set_gtk 4 42038 _001373_hash NULL
82454 +_001374_hash __hwahc_op_set_ptk 5 36510 _001374_hash NULL
82455 +_001375_hash ib_copy_to_udata 3 27525 _001375_hash NULL
82456 +_001376_hash idetape_chrdev_read 3 2097 _001376_hash NULL
82457 +_001377_hash ieee80211_alloc_hw 1 43829 _001377_hash NULL
82458 +_001378_hash ieee80211_bss_info_update 4 13991 _001378_hash NULL
82459 +_001379_hash ilo_read 3 32531 _001379_hash NULL
82460 +_001380_hash init_map_ipmac 3-4 63896 _001380_hash NULL
82461 +_001382_hash init_tid_tabs 2-4-3 13252 _001382_hash NULL
82462 +_001385_hash iowarrior_read 3 53483 _001385_hash NULL
82463 +_001386_hash ipv6_getsockopt_sticky 5 56711 _001386_hash NULL
82464 +_001387_hash ipwireless_send_packet 4 8328 _001387_hash NULL
82465 +_001388_hash ipx_sendmsg 4 1362 _001388_hash NULL
82466 +_001389_hash iscsi_conn_setup 2 35159 _001389_hash NULL
82467 +_001390_hash iscsi_create_session 3 51647 _001390_hash NULL
82468 +_001391_hash iscsi_host_alloc 2 36671 _001391_hash NULL
82469 +_001392_hash iscsi_session_setup 4-5 196 _001392_hash NULL
82470 +_001394_hash iscsit_find_cmd_from_itt_or_dump 3 17194 _001701_hash NULL nohasharray
82471 +_001395_hash isdn_ppp_read 4 50356 _001395_hash NULL
82472 +_001396_hash isku_sysfs_read 6 58806 _001396_hash NULL
82473 +_001397_hash isku_sysfs_write 6 49767 _001397_hash NULL
82474 +_001398_hash iso_alloc_urb 4-5 45206 _001398_hash NULL
82475 +_001400_hash ivtv_copy_buf_to_user 4 6159 _001400_hash NULL
82476 +_001401_hash iwm_rx_handle 3 24899 _001401_hash NULL
82477 +_001402_hash iwm_wdev_alloc 1 38415 _001402_hash NULL
82478 +_001403_hash jbd2_alloc 1 41359 _001403_hash NULL
82479 +_001404_hash jffs2_do_link 6 42048 _001404_hash NULL
82480 +_001405_hash jffs2_do_unlink 4 62020 _001405_hash NULL
82481 +_001406_hash jffs2_security_setxattr 4 62107 _001406_hash NULL
82482 +_001407_hash jffs2_trusted_setxattr 4 17048 _001407_hash NULL
82483 +_001408_hash jffs2_user_setxattr 4 10182 _001408_hash NULL
82484 +_001409_hash kernel_setsockopt 5 35913 _001409_hash NULL
82485 +_001410_hash keyctl_describe_key 3 36853 _001410_hash NULL
82486 +_001411_hash keyctl_get_security 3 64418 _001411_hash &_001132_hash
82487 +_001412_hash keyring_read 3 13438 _001412_hash NULL
82488 +_001413_hash kfifo_copy_to_user 3 20646 _001413_hash NULL
82489 +_001414_hash kmem_zalloc_large 1 56128 _001414_hash NULL
82490 +_001415_hash kmp_init 2 41373 _001415_hash NULL
82491 +_001416_hash koneplus_sysfs_write 6 35993 _001416_hash NULL
82492 +_001417_hash kvm_clear_guest_page 4 2308 _001417_hash NULL
82493 +_001418_hash kvm_read_nested_guest_page 5 13337 _001418_hash NULL
82494 +_001419_hash l2cap_create_basic_pdu 3 24869 _001419_hash &_001034_hash
82495 +_001420_hash l2cap_create_connless_pdu 3 37327 _001420_hash &_000966_hash
82496 +_001421_hash l2cap_create_iframe_pdu 3 51801 _001421_hash NULL
82497 +_001422_hash __lgwrite 4 57669 _001422_hash NULL
82498 +_001423_hash libfc_host_alloc 2 7917 _001423_hash NULL
82499 +_001424_hash llcp_sock_sendmsg 4 1092 _001424_hash NULL
82500 +_001425_hash macvtap_get_user 4 28185 _001425_hash NULL
82501 +_001426_hash mcam_v4l_read 3 36513 _001426_hash NULL
82502 +_001427_hash mce_async_out 3 58056 _001427_hash NULL
82503 +_001428_hash mce_flush_rx_buffer 2 14976 _001428_hash NULL
82504 +_001429_hash mdc800_device_read 3 22896 _001429_hash NULL
82505 +_001430_hash memcpy_toiovec 3 54166 _001430_hash &_000867_hash
82506 +_001431_hash memcpy_toiovecend 3-4 19736 _001431_hash NULL
82507 +_001433_hash mgt_set_varlen 4 60916 _001433_hash NULL
82508 +_001434_hash mlx4_en_create_rx_ring 3 62498 _001434_hash NULL
82509 +_001435_hash mlx4_en_create_tx_ring 4 48501 _001435_hash NULL
82510 +_001436_hash mon_bin_get_event 4 52863 _001436_hash NULL
82511 +_001437_hash mousedev_read 3 47123 _001437_hash NULL
82512 +_001438_hash move_addr_to_user 2 2868 _001438_hash NULL
82513 +_001439_hash mpihelp_mul 5-3 27805 _001439_hash NULL
82514 +_001441_hash mpi_lshift_limbs 2 9337 _001441_hash NULL
82515 +_001442_hash msnd_fifo_alloc 2 23179 _001442_hash NULL
82516 +_001443_hash mtdswap_init 2 55719 _001443_hash NULL
82517 +_001444_hash neigh_hash_grow 2 17283 _001444_hash NULL
82518 +_001445_hash nfs4_realloc_slot_table 2 22859 _001445_hash NULL
82519 +_001446_hash nfs_idmap_get_key 2 39616 _001446_hash NULL
82520 +_001447_hash nsm_get_handle 4 52089 _001447_hash NULL
82521 +_001448_hash ntfs_malloc_nofs 1 49572 _001448_hash NULL
82522 +_001449_hash ntfs_malloc_nofs_nofail 1 63631 _001449_hash NULL
82523 +_001450_hash nvme_create_queue 3 170 _001450_hash NULL
82524 +_001451_hash ocfs2_control_write 3 54737 _001451_hash NULL
82525 +_001452_hash orinoco_add_extscan_result 3 18207 _001452_hash NULL
82526 +_001454_hash override_release 2 52032 _001454_hash NULL
82527 +_001455_hash packet_snd 3 13634 _001455_hash NULL
82528 +_001456_hash pcbit_stat 2 27364 _001456_hash NULL
82529 +_001457_hash pcpu_extend_area_map 2 12589 _001457_hash NULL
82530 +_001458_hash pg_read 3 17276 _001458_hash NULL
82531 +_001459_hash picolcd_debug_eeprom_read 3 14549 _001459_hash NULL
82532 +_001460_hash pkt_alloc_packet_data 1 37928 _001460_hash NULL
82533 +_001461_hash pmcraid_build_passthrough_ioadls 2 62034 _001461_hash NULL
82534 +_001462_hash pms_capture 4 27142 _001462_hash NULL
82535 +_001463_hash posix_clock_register 2 5662 _001463_hash NULL
82536 +_001464_hash printer_read 3 54851 _001464_hash NULL
82537 +_001465_hash __proc_file_read 3 54978 _001465_hash NULL
82538 +_001466_hash pt_read 3 49136 _001466_hash NULL
82539 +_001467_hash put_cmsg 4 36589 _001467_hash NULL
82540 +_001468_hash pvr2_ioread_read 3 10720 _001505_hash NULL nohasharray
82541 +_001469_hash pwc_video_read 3 51735 _001469_hash NULL
82542 +_001470_hash px_raw_event 4 49371 _001470_hash NULL
82543 +_001471_hash qcam_read 3 13977 _001471_hash NULL
82544 +_001472_hash rawv6_sendmsg 4 20080 _001472_hash NULL
82545 +_001473_hash rds_sendmsg 4 40976 _001473_hash NULL
82546 +_001474_hash read_flush 3 43851 _001474_hash NULL
82547 +_001475_hash read_profile 3 27859 _001475_hash NULL
82548 +_001476_hash read_vmcore 3 26501 _001476_hash NULL
82549 +_001477_hash redirected_tty_write 3 65297 _001477_hash NULL
82550 +_001478_hash __register_chrdev 2-3 54223 _001478_hash NULL
82551 +_001480_hash regmap_raw_write 4 53803 _001480_hash NULL
82552 +_001481_hash reiserfs_allocate_list_bitmaps 3 21732 _001481_hash NULL
82553 +_001482_hash reiserfs_resize 2 34377 _001482_hash NULL
82554 +_001483_hash request_key_auth_read 3 24109 _001483_hash NULL
82555 +_001484_hash rfkill_fop_read 3 54711 _001484_hash NULL
82556 +_001485_hash rng_dev_read 3 41581 _001485_hash NULL
82557 +_001486_hash roccat_read 3 41093 _001486_hash NULL
82558 +_001487_hash sco_sock_sendmsg 4 62542 _001487_hash NULL
82559 +_001488_hash scsi_register 2 49094 _001488_hash NULL
82560 +_001489_hash sctp_getsockopt_events 2 3607 _001489_hash NULL
82561 +_001490_hash sctp_getsockopt_maxburst 2 42941 _001490_hash NULL
82562 +_001491_hash sctp_getsockopt_maxseg 2 10737 _001491_hash NULL
82563 +_001492_hash sctpprobe_read 3 17741 _001492_hash NULL
82564 +_001493_hash sdhci_alloc_host 2 7509 _001493_hash NULL
82565 +_001494_hash selinux_inode_post_setxattr 4 26037 _001494_hash NULL
82566 +_001495_hash selinux_inode_setsecurity 4 18148 _001495_hash NULL
82567 +_001496_hash selinux_inode_setxattr 4 10708 _001496_hash NULL
82568 +_001497_hash selinux_secctx_to_secid 2 63744 _001497_hash NULL
82569 +_001498_hash selinux_setprocattr 4 55611 _001498_hash NULL
82570 +_001499_hash sel_write_context 3 25726 _002397_hash NULL nohasharray
82571 +_001500_hash seq_copy_in_user 3 18543 _001500_hash NULL
82572 +_001501_hash seq_open_net 4 8968 _001594_hash NULL nohasharray
82573 +_001502_hash seq_open_private 3 61589 _001502_hash NULL
82574 +_001503_hash set_arg 3 42824 _001503_hash NULL
82575 +_001504_hash sg_read 3 25799 _001504_hash NULL
82576 +_001505_hash shash_async_setkey 3 10720 _001505_hash &_001468_hash
82577 +_001506_hash shash_compat_setkey 3 12267 _001506_hash NULL
82578 +_001507_hash shmem_setxattr 4 55867 _001507_hash NULL
82579 +_001508_hash simple_read_from_buffer 2-5 55957 _001508_hash NULL
82580 +_001511_hash sm_checker_extend 2 23615 _001511_hash NULL
82581 +_001512_hash sn9c102_read 3 29305 _001512_hash NULL
82582 +_001513_hash snd_es1938_capture_copy 5 25930 _001513_hash NULL
82583 +_001514_hash snd_gus_dram_peek 4 9062 _001514_hash NULL
82584 +_001515_hash snd_hdsp_capture_copy 5 4011 _001515_hash NULL
82585 +_001516_hash snd_korg1212_copy_to 6 92 _001516_hash NULL
82586 +_001517_hash snd_opl4_mem_proc_read 5 63774 _001517_hash NULL
82587 +_001518_hash snd_pcm_alloc_vmalloc_buffer 2 44595 _001518_hash NULL
82588 +_001519_hash snd_pcm_oss_read1 3 63771 _001519_hash NULL
82589 +_001520_hash snd_rawmidi_kernel_read1 4 36740 _001520_hash NULL
82590 +_001521_hash snd_rme9652_capture_copy 5 10287 _001521_hash NULL
82591 +_001522_hash srp_target_alloc 3 37288 _001522_hash NULL
82592 +_001523_hash stk_allocate_buffers 2 16291 _001523_hash NULL
82593 +_001524_hash store_ifalias 4 35088 _001524_hash NULL
82594 +_001525_hash store_msg 3 56417 _001525_hash NULL
82595 +_001526_hash str_to_user 2 11411 _001526_hash NULL
82596 +_001527_hash subbuf_read_actor 3 2071 _001527_hash NULL
82597 +_001528_hash sys_fgetxattr 4 25166 _001528_hash NULL
82598 +_001529_hash sys_gethostname 2 49698 _001529_hash NULL
82599 +_001530_hash sys_getxattr 4 37418 _001530_hash NULL
82600 +_001531_hash sys_kexec_load 2 14222 _001531_hash NULL
82601 +_001532_hash sys_msgsnd 3 44537 _001532_hash &_000129_hash
82602 +_001533_hash sys_process_vm_readv 3-5 19090 _001533_hash NULL
82603 +_001535_hash sys_process_vm_writev 3-5 4928 _001535_hash NULL
82604 +_001537_hash sys_sched_getaffinity 2 60033 _001537_hash NULL
82605 +_001538_hash sys_setsockopt 5 35320 _001538_hash NULL
82606 +_001539_hash t3_init_l2t 1 8261 _001539_hash NULL
82607 +_001540_hash team_options_register 3 20091 _001540_hash NULL
82608 +_001541_hash tipc_send2name 6 16809 _001541_hash NULL
82609 +_001542_hash tipc_send2port 5 63935 _001542_hash NULL
82610 +_001543_hash tipc_send 4 51238 _001543_hash NULL
82611 +_001544_hash tm6000_i2c_recv_regs16 5 2949 _001544_hash NULL
82612 +_001545_hash tm6000_i2c_recv_regs 5 46215 _001545_hash NULL
82613 +_001546_hash tm6000_i2c_send_regs 5 20250 _001546_hash NULL
82614 +_001547_hash tnode_new 3 44757 _001547_hash NULL
82615 +_001548_hash tomoyo_read_self 3 33539 _001548_hash NULL
82616 +_001549_hash tomoyo_update_domain 2 5498 _001549_hash NULL
82617 +_001550_hash tomoyo_update_policy 2 40458 _001550_hash NULL
82618 +_001551_hash tpm_read 3 50344 _001551_hash NULL
82619 +_001552_hash TSS_rawhmac 3 17486 _001552_hash NULL
82620 +_001553_hash tt3650_ci_msg 4 57219 _001553_hash NULL
82621 +_001554_hash tun_get_user 3 33178 _001554_hash NULL
82622 +_001555_hash ubi_dbg_dump_flash 4 3870 _001555_hash NULL
82623 +_001556_hash ubi_io_write 4-5 15870 _001556_hash &_000954_hash
82624 +_001558_hash uio_read 3 49300 _001558_hash NULL
82625 +_001559_hash unix_seqpacket_sendmsg 4 27893 _001559_hash NULL
82626 +_001560_hash unlink1 3 63059 _001560_hash NULL
82627 +_001562_hash usb_allocate_stream_buffers 3 8964 _001562_hash NULL
82628 +_001563_hash usbdev_read 3 45114 _001563_hash NULL
82629 +_001564_hash usblp_read 3 57342 _001564_hash NULL
82630 +_001565_hash usbtmc_read 3 32377 _001565_hash NULL
82631 +_001566_hash usbvision_v4l2_read 3 34386 _001566_hash NULL
82632 +_001567_hash _usb_writeN_sync 4 31682 _001567_hash NULL
82633 +_001568_hash user_read 3 51881 _001568_hash NULL
82634 +_001569_hash v4l_stk_read 3 39672 _001569_hash NULL
82635 +_001570_hash vcs_read 3 8017 _001570_hash NULL
82636 +_001571_hash vdma_mem_alloc 1 6171 _001571_hash NULL
82637 +_001572_hash venus_create 4 20555 _001572_hash NULL
82638 +_001573_hash venus_link 5 32165 _001573_hash NULL
82639 +_001574_hash venus_lookup 4 8121 _001574_hash NULL
82640 +_001575_hash venus_mkdir 4 8967 _001575_hash NULL
82641 +_001576_hash venus_remove 4 59781 _001576_hash NULL
82642 +_001577_hash venus_rename 4-5 17707 _001577_hash NULL
82643 +_001579_hash venus_rmdir 4 45564 _001579_hash NULL
82644 +_001580_hash venus_symlink 4-6 23570 _001580_hash NULL
82645 +_001582_hash vfs_readlink 3 54368 _001582_hash NULL
82646 +_001583_hash vfs_readv 3 38011 _001583_hash NULL
82647 +_001584_hash vfs_writev 3 25278 _001584_hash NULL
82648 +_001585_hash vga_arb_read 3 4886 _001585_hash NULL
82649 +_001586_hash vhci_put_user 4 12604 _001586_hash NULL
82650 +_001587_hash vhost_add_used_n 3 10760 _001587_hash NULL
82651 +_001588_hash __videobuf_copy_to_user 4 15423 _001588_hash NULL
82652 +_001589_hash videobuf_pages_to_sg 2 3708 _001589_hash NULL
82653 +_001590_hash videobuf_vmalloc_to_sg 2 4548 _001590_hash NULL
82654 +_001591_hash virtnet_send_command 5-6 61993 _001591_hash NULL
82655 +_001593_hash vmbus_establish_gpadl 3 4495 _001593_hash NULL
82656 +_001594_hash vol_cdev_read 3 8968 _001594_hash &_001501_hash
82657 +_001595_hash w9966_v4l_read 3 31148 _001595_hash NULL
82658 +_001596_hash wdm_read 3 6549 _001596_hash NULL
82659 +_001597_hash wusb_prf 7 54261 _001597_hash &_000063_hash
82660 +_001598_hash xdi_copy_to_user 4 48900 _001598_hash NULL
82661 +_001599_hash xfs_buf_get_uncached 2 51477 _001599_hash NULL
82662 +_001600_hash xfs_efd_init 3 5463 _001600_hash NULL
82663 +_001601_hash xfs_efi_init 2 5476 _001601_hash NULL
82664 +_001602_hash xfs_iext_realloc_direct 2 20521 _001602_hash NULL
82665 +_001603_hash xfs_iext_realloc_indirect 2 59211 _001603_hash NULL
82666 +_001604_hash xfs_inumbers_fmt 3 12817 _001604_hash NULL
82667 +_001605_hash xlog_recover_add_to_cont_trans 4 44102 _001605_hash NULL
82668 +_001606_hash xz_dec_lzma2_create 2 36353 _001606_hash NULL
82669 +_001607_hash _zd_iowrite32v_locked 3 44725 _001607_hash NULL
82670 +_001608_hash aat2870_reg_read_file 3 12221 _001608_hash NULL
82671 +_001609_hash add_sctp_bind_addr 3 12269 _001609_hash NULL
82672 +_001610_hash aes_decrypt_fail_read 3 54815 _001610_hash NULL
82673 +_001611_hash aes_decrypt_interrupt_read 3 19910 _001611_hash NULL
82674 +_001612_hash aes_decrypt_packets_read 3 10155 _001612_hash NULL
82675 +_001613_hash aes_encrypt_fail_read 3 32562 _001613_hash NULL
82676 +_001614_hash aes_encrypt_interrupt_read 3 39919 _001614_hash NULL
82677 +_001615_hash aes_encrypt_packets_read 3 48666 _001615_hash NULL
82678 +_001616_hash afs_cell_lookup 2 8482 _001616_hash NULL
82679 +_001617_hash agp_allocate_memory 2 58761 _001617_hash NULL
82680 +_001618_hash __alloc_bootmem 1 31498 _001618_hash NULL
82681 +_001619_hash __alloc_bootmem_low 1 43423 _001619_hash NULL
82682 +_001620_hash __alloc_bootmem_node_nopanic 2 6432 _001620_hash NULL
82683 +_001621_hash alloc_cc770dev 1 48186 _001621_hash NULL
82684 +_001622_hash __alloc_ei_netdev 1 29338 _001622_hash NULL
82685 +_001623_hash __alloc_eip_netdev 1 51549 _001623_hash NULL
82686 +_001624_hash alloc_libipw 1 22708 _001624_hash NULL
82687 +_001625_hash alloc_pg_vec 2 8533 _001625_hash NULL
82688 +_001626_hash alloc_sja1000dev 1 17868 _001626_hash NULL
82689 +_001627_hash alloc_targets 2 8074 _001627_hash NULL
82690 +_001630_hash ath6kl_disconnect_timeout_read 3 3650 _001630_hash NULL
82691 +_001631_hash ath6kl_endpoint_stats_read 3 41554 _001631_hash NULL
82692 +_001632_hash ath6kl_fwlog_mask_read 3 2050 _001632_hash NULL
82693 +_001633_hash ath6kl_keepalive_read 3 44303 _001633_hash NULL
82694 +_001634_hash ath6kl_listen_int_read 3 10355 _001634_hash NULL
82695 +_001635_hash ath6kl_lrssi_roam_read 3 61022 _001635_hash NULL
82696 +_001636_hash ath6kl_regdump_read 3 14393 _001636_hash NULL
82697 +_001637_hash ath6kl_regread_read 3 25884 _001637_hash NULL
82698 +_001638_hash ath6kl_regwrite_read 3 48747 _001638_hash NULL
82699 +_001639_hash ath6kl_roam_table_read 3 26166 _001639_hash NULL
82700 +_001640_hash ath9k_debugfs_read_buf 3 25316 _001640_hash NULL
82701 +_001641_hash atk_debugfs_ggrp_read 3 29522 _001641_hash NULL
82702 +_001642_hash b43_debugfs_read 3 24425 _001642_hash NULL
82703 +_001643_hash b43legacy_debugfs_read 3 2473 _001643_hash NULL
82704 +_001644_hash bcm_recvmsg 4 43992 _001644_hash NULL
82705 +_001645_hash bfad_debugfs_read 3 13119 _001645_hash NULL
82706 +_001646_hash bfad_debugfs_read_regrd 3 57830 _001646_hash NULL
82707 +_001647_hash blk_init_tags 1 30592 _001647_hash NULL
82708 +_001648_hash blk_queue_init_tags 2 44355 _001648_hash NULL
82709 +_001649_hash blk_rq_map_kern 4 47004 _001649_hash NULL
82710 +_001650_hash bm_entry_read 3 10976 _001650_hash NULL
82711 +_001651_hash bm_status_read 3 19583 _001651_hash NULL
82712 +_001652_hash bnad_debugfs_read 3 50665 _001652_hash NULL
82713 +_001653_hash bnad_debugfs_read_regrd 3 51308 _001653_hash NULL
82714 +_001654_hash btmrvl_curpsmode_read 3 46939 _001654_hash NULL
82715 +_001655_hash btmrvl_gpiogap_read 3 4718 _001655_hash NULL
82716 +_001656_hash btmrvl_hscfgcmd_read 3 56303 _001656_hash NULL
82717 +_001657_hash btmrvl_hscmd_read 3 1614 _001657_hash NULL
82718 +_001658_hash btmrvl_hsmode_read 3 1647 _001658_hash NULL
82719 +_001659_hash btmrvl_hsstate_read 3 920 _001659_hash NULL
82720 +_001660_hash btmrvl_pscmd_read 3 24308 _001660_hash NULL
82721 +_001661_hash btmrvl_psmode_read 3 22395 _001661_hash NULL
82722 +_001662_hash btmrvl_psstate_read 3 50683 _001662_hash NULL
82723 +_001663_hash btmrvl_txdnldready_read 3 413 _001663_hash NULL
82724 +_001664_hash btrfs_add_link 5 9973 _001664_hash NULL
82725 +_001665_hash btrfs_discard_extent 2 38547 _001665_hash NULL
82726 +_001666_hash btrfs_find_create_tree_block 3 55812 _001666_hash NULL
82727 +_001667_hash btrfsic_map_block 2 56751 _001667_hash NULL
82728 +_001668_hash caif_stream_recvmsg 4 13173 _001668_hash NULL
82729 +_001669_hash carl9170_alloc 1 27 _001669_hash NULL
82730 +_001670_hash carl9170_debugfs_read 3 47738 _001670_hash NULL
82731 +_001671_hash cgroup_read_s64 5 19570 _001671_hash NULL
82732 +_001672_hash cgroup_read_u64 5 45532 _001672_hash NULL
82733 +_001673_hash channel_type_read 3 47308 _001673_hash NULL
82734 +_001674_hash codec_list_read_file 3 24910 _001674_hash NULL
82735 +_001675_hash configfs_read_file 3 1683 _001675_hash NULL
82736 +_001676_hash cpuset_common_file_read 5 8800 _001676_hash NULL
82737 +_001677_hash create_subvol 4 2347 _001677_hash NULL
82738 +_001678_hash cx18_copy_mdl_to_user 4 45549 _001678_hash NULL
82739 +_001679_hash dai_list_read_file 3 25421 _001679_hash NULL
82740 +_001680_hash dapm_bias_read_file 3 64715 _001680_hash NULL
82741 +_001681_hash dapm_widget_power_read_file 3 59950 _001754_hash NULL nohasharray
82742 +_001684_hash dbgfs_frame 3 45917 _001684_hash NULL
82743 +_001685_hash dbgfs_state 3 38894 _001685_hash NULL
82744 +_001686_hash debugfs_read 3 62535 _001686_hash NULL
82745 +_001687_hash debug_output 3 18575 _001687_hash NULL
82746 +_001688_hash debug_read 3 19322 _001688_hash NULL
82747 +_001689_hash dfs_file_read 3 18116 _001689_hash NULL
82748 +_001690_hash dma_memcpy_pg_to_iovec 6 1725 _001690_hash NULL
82749 +_001691_hash dma_memcpy_to_iovec 5 12173 _001691_hash NULL
82750 +_001692_hash dma_rx_errors_read 3 52045 _001692_hash NULL
82751 +_001693_hash dma_rx_requested_read 3 65354 _001693_hash NULL
82752 +_001694_hash dma_show_regs 3 35266 _001694_hash NULL
82753 +_001695_hash dma_tx_errors_read 3 46060 _001695_hash NULL
82754 +_001696_hash dma_tx_requested_read 3 16110 _001775_hash NULL nohasharray
82755 +_001697_hash dm_exception_table_init 2 39645 _001697_hash &_001103_hash
82756 +_001698_hash dn_recvmsg 4 17213 _001698_hash NULL
82757 +_001699_hash dns_resolver_read 3 54658 _001699_hash NULL
82758 +_001700_hash do_msgrcv 4 5590 _001700_hash NULL
82759 +_001701_hash driver_state_read 3 17194 _001701_hash &_001394_hash
82760 +_001702_hash dvb_demux_do_ioctl 3 34871 _001702_hash NULL
82761 +_001703_hash dvb_dmxdev_buffer_read 4 20682 _001703_hash NULL
82762 +_001704_hash dvb_dvr_do_ioctl 3 43355 _001704_hash NULL
82763 +_001705_hash econet_recvmsg 4 40978 _001705_hash NULL
82764 +_001706_hash event_calibration_read 3 21083 _001706_hash NULL
82765 +_001707_hash event_heart_beat_read 3 48961 _001707_hash NULL
82766 +_001708_hash event_oom_late_read 3 61175 _001708_hash &_001014_hash
82767 +_001709_hash event_phy_transmit_error_read 3 10471 _001709_hash NULL
82768 +_001710_hash event_rx_mem_empty_read 3 40363 _001710_hash NULL
82769 +_001711_hash event_rx_mismatch_read 3 38518 _001711_hash NULL
82770 +_001712_hash event_rx_pool_read 3 25792 _001712_hash NULL
82771 +_001713_hash event_tx_stuck_read 3 19305 _001713_hash NULL
82772 +_001714_hash excessive_retries_read 3 60425 _001714_hash NULL
82773 +_001715_hash fallback_on_nodma_alloc 2 35332 _001715_hash NULL
82774 +_001716_hash filter_read 3 61692 _001716_hash NULL
82775 +_001717_hash format_devstat_counter 3 32550 _001717_hash NULL
82776 +_001718_hash fragmentation_threshold_read 3 61718 _001718_hash NULL
82777 +_001719_hash fuse_conn_limit_read 3 20084 _001719_hash NULL
82778 +_001720_hash fuse_conn_waiting_read 3 49762 _001720_hash NULL
82779 +_001721_hash generic_readlink 3 32654 _001721_hash NULL
82780 +_001722_hash gpio_power_read 3 36059 _001722_hash NULL
82781 +_001723_hash hash_recvmsg 4 50924 _001723_hash NULL
82782 +_001724_hash ht40allow_map_read 3 55209 _001724_hash NULL
82783 +_001725_hash hwflags_read 3 52318 _001725_hash NULL
82784 +_001726_hash hysdn_conf_read 3 42324 _001726_hash NULL
82785 +_001727_hash i2400m_rx_stats_read 3 57706 _001727_hash NULL
82786 +_001728_hash i2400m_tx_stats_read 3 28527 _001728_hash NULL
82787 +_001729_hash idmouse_read 3 63374 _001729_hash NULL
82788 +_001730_hash ieee80211_if_read 3 6785 _001730_hash NULL
82789 +_001731_hash ieee80211_rx_bss_info 3 61630 _001731_hash NULL
82790 +_001732_hash ikconfig_read_current 3 1658 _001732_hash NULL
82791 +_001733_hash il3945_sta_dbgfs_stats_table_read 3 48802 _001733_hash NULL
82792 +_001734_hash il3945_ucode_general_stats_read 3 46111 _001734_hash NULL
82793 +_001735_hash il3945_ucode_rx_stats_read 3 3048 _001735_hash NULL
82794 +_001736_hash il3945_ucode_tx_stats_read 3 36016 _001736_hash NULL
82795 +_001737_hash il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 _001737_hash NULL
82796 +_001738_hash il4965_rs_sta_dbgfs_scale_table_read 3 38564 _001738_hash NULL
82797 +_001739_hash il4965_rs_sta_dbgfs_stats_table_read 3 49206 _001739_hash NULL
82798 +_001740_hash il4965_ucode_general_stats_read 3 56277 _001740_hash NULL
82799 +_001741_hash il4965_ucode_rx_stats_read 3 61948 _001741_hash NULL
82800 +_001742_hash il4965_ucode_tx_stats_read 3 12064 _001742_hash NULL
82801 +_001743_hash il_dbgfs_chain_noise_read 3 38044 _001743_hash NULL
82802 +_001744_hash il_dbgfs_channels_read 3 25005 _001744_hash NULL
82803 +_001745_hash il_dbgfs_disable_ht40_read 3 42386 _001745_hash NULL
82804 +_001746_hash il_dbgfs_fh_reg_read 3 40993 _001746_hash NULL
82805 +_001747_hash il_dbgfs_force_reset_read 3 57517 _001747_hash NULL
82806 +_001748_hash il_dbgfs_interrupt_read 3 3351 _001748_hash NULL
82807 +_001749_hash il_dbgfs_missed_beacon_read 3 59956 _001749_hash NULL
82808 +_001750_hash il_dbgfs_nvm_read 3 12288 _001750_hash NULL
82809 +_001751_hash il_dbgfs_power_save_status_read 3 43165 _001751_hash NULL
82810 +_001752_hash il_dbgfs_qos_read 3 33615 _001752_hash NULL
82811 +_001753_hash il_dbgfs_rxon_filter_flags_read 3 19281 _001753_hash NULL
82812 +_001754_hash il_dbgfs_rxon_flags_read 3 59950 _001754_hash &_001681_hash
82813 +_001755_hash il_dbgfs_rx_queue_read 3 11221 _001755_hash NULL
82814 +_001756_hash il_dbgfs_rx_stats_read 3 15243 _001756_hash NULL
82815 +_001757_hash il_dbgfs_sensitivity_read 3 2370 _001757_hash NULL
82816 +_001758_hash il_dbgfs_sram_read 3 62296 _001758_hash NULL
82817 +_001759_hash il_dbgfs_stations_read 3 21532 _001759_hash NULL
82818 +_001760_hash il_dbgfs_status_read 3 58388 _001760_hash NULL
82819 +_001761_hash il_dbgfs_tx_queue_read 3 55668 _001761_hash NULL
82820 +_001762_hash il_dbgfs_tx_stats_read 3 32913 _001762_hash NULL
82821 +_001763_hash ima_show_htable_value 2 57136 _001763_hash NULL
82822 +_001765_hash ipw_write 3 59807 _001765_hash NULL
82823 +_001766_hash irda_recvmsg_stream 4 35280 _001766_hash NULL
82824 +_001767_hash iscsi_tcp_conn_setup 2 16376 _001767_hash NULL
82825 +_001768_hash isr_cmd_cmplt_read 3 53439 _001768_hash NULL
82826 +_001769_hash isr_commands_read 3 41398 _001769_hash NULL
82827 +_001770_hash isr_decrypt_done_read 3 49490 _001770_hash NULL
82828 +_001771_hash isr_dma0_done_read 3 8574 _001771_hash NULL
82829 +_001772_hash isr_dma1_done_read 3 48159 _001772_hash NULL
82830 +_001773_hash isr_fiqs_read 3 34687 _001773_hash NULL
82831 +_001774_hash isr_host_acknowledges_read 3 54136 _001774_hash NULL
82832 +_001775_hash isr_hw_pm_mode_changes_read 3 16110 _001775_hash &_001696_hash
82833 +_001776_hash isr_irqs_read 3 9181 _001776_hash NULL
82834 +_001777_hash isr_low_rssi_read 3 64789 _001777_hash NULL
82835 +_001778_hash isr_pci_pm_read 3 30271 _001778_hash NULL
82836 +_001779_hash isr_rx_headers_read 3 38325 _001779_hash NULL
82837 +_001780_hash isr_rx_mem_overflow_read 3 43025 _001780_hash NULL
82838 +_001781_hash isr_rx_procs_read 3 31804 _001781_hash NULL
82839 +_001782_hash isr_rx_rdys_read 3 35283 _001782_hash NULL
82840 +_001783_hash isr_tx_exch_complete_read 3 16103 _001783_hash NULL
82841 +_001784_hash isr_tx_procs_read 3 23084 _001784_hash NULL
82842 +_001785_hash isr_wakeups_read 3 49607 _001785_hash NULL
82843 +_001786_hash ivtv_read 3 57796 _001786_hash NULL
82844 +_001787_hash iwl_dbgfs_bt_traffic_read 3 35534 _001787_hash NULL
82845 +_001788_hash iwl_dbgfs_chain_noise_read 3 46355 _001788_hash NULL
82846 +_001789_hash iwl_dbgfs_channels_read 3 6784 _001789_hash NULL
82847 +_001790_hash iwl_dbgfs_current_sleep_command_read 3 2081 _001790_hash NULL
82848 +_001791_hash iwl_dbgfs_disable_ht40_read 3 35761 _001791_hash NULL
82849 +_001792_hash iwl_dbgfs_fh_reg_read 3 879 _001792_hash &_000393_hash
82850 +_001793_hash iwl_dbgfs_force_reset_read 3 62628 _001793_hash NULL
82851 +_001794_hash iwl_dbgfs_interrupt_read 3 23574 _001794_hash NULL
82852 +_001795_hash iwl_dbgfs_log_event_read 3 2107 _001795_hash NULL
82853 +_001796_hash iwl_dbgfs_missed_beacon_read 3 50584 _001796_hash NULL
82854 +_001797_hash iwl_dbgfs_nvm_read 3 23845 _001797_hash NULL
82855 +_001798_hash iwl_dbgfs_plcp_delta_read 3 55407 _001798_hash NULL
82856 +_001799_hash iwl_dbgfs_power_save_status_read 3 54392 _001799_hash NULL
82857 +_001800_hash iwl_dbgfs_protection_mode_read 3 13943 _001800_hash NULL
82858 +_001801_hash iwl_dbgfs_qos_read 3 11753 _001801_hash NULL
82859 +_001802_hash iwl_dbgfs_reply_tx_error_read 3 19205 _001802_hash NULL
82860 +_001803_hash iwl_dbgfs_rx_handlers_read 3 18708 _001803_hash NULL
82861 +_001804_hash iwl_dbgfs_rxon_filter_flags_read 3 28832 _001804_hash NULL
82862 +_001805_hash iwl_dbgfs_rxon_flags_read 3 20795 _001805_hash NULL
82863 +_001806_hash iwl_dbgfs_rx_queue_read 3 19943 _001806_hash NULL
82864 +_001807_hash iwl_dbgfs_rx_statistics_read 3 62687 _001807_hash &_000425_hash
82865 +_001808_hash iwl_dbgfs_sensitivity_read 3 63116 _001808_hash NULL
82866 +_001809_hash iwl_dbgfs_sleep_level_override_read 3 3038 _001809_hash NULL
82867 +_001810_hash iwl_dbgfs_sram_read 3 44505 _001810_hash NULL
82868 +_001811_hash iwl_dbgfs_stations_read 3 9309 _001811_hash NULL
82869 +_001812_hash iwl_dbgfs_status_read 3 5171 _001812_hash NULL
82870 +_001813_hash iwl_dbgfs_temperature_read 3 29224 _001813_hash NULL
82871 +_001814_hash iwl_dbgfs_thermal_throttling_read 3 38779 _001814_hash NULL
82872 +_001815_hash iwl_dbgfs_traffic_log_read 3 58870 _001815_hash NULL
82873 +_001816_hash iwl_dbgfs_tx_queue_read 3 4635 _001816_hash NULL
82874 +_001817_hash iwl_dbgfs_tx_statistics_read 3 314 _001817_hash NULL
82875 +_001818_hash iwl_dbgfs_ucode_bt_stats_read 3 42820 _001818_hash NULL
82876 +_001819_hash iwl_dbgfs_ucode_general_stats_read 3 49199 _001819_hash NULL
82877 +_001820_hash iwl_dbgfs_ucode_rx_stats_read 3 58023 _001820_hash NULL
82878 +_001821_hash iwl_dbgfs_ucode_tracing_read 3 47983 _001821_hash &_000349_hash
82879 +_001822_hash iwl_dbgfs_ucode_tx_stats_read 3 31611 _001822_hash NULL
82880 +_001823_hash iwl_dbgfs_wowlan_sram_read 3 540 _001823_hash NULL
82881 +_001824_hash iwm_if_alloc 1 17027 _001824_hash &_001314_hash
82882 +_001825_hash kernel_readv 3 35617 _001825_hash NULL
82883 +_001826_hash key_algorithm_read 3 57946 _001826_hash NULL
82884 +_001827_hash key_icverrors_read 3 20895 _001827_hash NULL
82885 +_001828_hash key_key_read 3 3241 _001828_hash NULL
82886 +_001829_hash key_replays_read 3 62746 _001829_hash NULL
82887 +_001830_hash key_rx_spec_read 3 12736 _001830_hash NULL
82888 +_001831_hash key_tx_spec_read 3 4862 _001831_hash NULL
82889 +_001832_hash __kfifo_to_user 3 36555 _002199_hash NULL nohasharray
82890 +_001833_hash __kfifo_to_user_r 3 39123 _001833_hash NULL
82891 +_001834_hash kmem_zalloc_greedy 2-3 65268 _001834_hash NULL
82892 +_001836_hash l2cap_chan_send 3 49995 _001836_hash NULL
82893 +_001837_hash l2cap_sar_segment_sdu 3 27701 _001837_hash NULL
82894 +_001838_hash lbs_debugfs_read 3 30721 _001838_hash NULL
82895 +_001839_hash lbs_dev_info 3 51023 _001839_hash NULL
82896 +_001840_hash lbs_host_sleep_read 3 31013 _001840_hash NULL
82897 +_001841_hash lbs_rdbbp_read 3 45805 _001841_hash NULL
82898 +_001842_hash lbs_rdmac_read 3 418 _001842_hash NULL
82899 +_001843_hash lbs_rdrf_read 3 41431 _001843_hash NULL
82900 +_001844_hash lbs_sleepparams_read 3 10840 _001844_hash NULL
82901 +_001845_hash lbs_threshold_read 5 21046 _001845_hash NULL
82902 +_001846_hash libfc_vport_create 2 4415 _001846_hash NULL
82903 +_001847_hash lkdtm_debugfs_read 3 45752 _001847_hash NULL
82904 +_001848_hash llcp_sock_recvmsg 4 13556 _001848_hash NULL
82905 +_001849_hash long_retry_limit_read 3 59766 _001849_hash NULL
82906 +_001850_hash lpfc_debugfs_dif_err_read 3 36303 _001850_hash NULL
82907 +_001851_hash lpfc_debugfs_read 3 16566 _001851_hash NULL
82908 +_001852_hash lpfc_idiag_baracc_read 3 58466 _002447_hash NULL nohasharray
82909 +_001853_hash lpfc_idiag_ctlacc_read 3 33943 _001853_hash NULL
82910 +_001854_hash lpfc_idiag_drbacc_read 3 15948 _001854_hash NULL
82911 +_001855_hash lpfc_idiag_extacc_read 3 48301 _001855_hash NULL
82912 +_001856_hash lpfc_idiag_mbxacc_read 3 28061 _001856_hash NULL
82913 +_001857_hash lpfc_idiag_pcicfg_read 3 50334 _001857_hash NULL
82914 +_001858_hash lpfc_idiag_queacc_read 3 13950 _001858_hash NULL
82915 +_001859_hash lpfc_idiag_queinfo_read 3 55662 _001859_hash NULL
82916 +_001860_hash mac80211_format_buffer 2 41010 _001860_hash NULL
82917 +_001861_hash macvtap_put_user 4 55609 _001861_hash NULL
82918 +_001862_hash macvtap_sendmsg 4 30629 _001862_hash NULL
82919 +_001863_hash mic_calc_failure_read 3 59700 _001863_hash NULL
82920 +_001864_hash mic_rx_pkts_read 3 27972 _001864_hash NULL
82921 +_001865_hash minstrel_stats_read 3 17290 _001865_hash NULL
82922 +_001866_hash mmc_ext_csd_read 3 13205 _001866_hash NULL
82923 +_001867_hash mon_bin_read 3 6841 _001867_hash NULL
82924 +_001868_hash mon_stat_read 3 25238 _001868_hash NULL
82925 +_001870_hash mqueue_read_file 3 6228 _001870_hash NULL
82926 +_001871_hash mwifiex_debug_read 3 53074 _001871_hash NULL
82927 +_001872_hash mwifiex_getlog_read 3 54269 _001872_hash NULL
82928 +_001873_hash mwifiex_info_read 3 53447 _001873_hash NULL
82929 +_001874_hash mwifiex_rdeeprom_read 3 51429 _001874_hash NULL
82930 +_001875_hash mwifiex_regrdwr_read 3 34472 _001875_hash NULL
82931 +_001876_hash nfsd_vfs_read 6 62605 _001876_hash NULL
82932 +_001877_hash nfsd_vfs_write 6 54577 _001877_hash NULL
82933 +_001878_hash nfs_idmap_lookup_id 2 10660 _001878_hash NULL
82934 +_001879_hash o2hb_debug_read 3 37851 _001879_hash NULL
82935 +_001880_hash o2net_debug_read 3 52105 _001880_hash NULL
82936 +_001881_hash ocfs2_control_read 3 56405 _001881_hash NULL
82937 +_001882_hash ocfs2_debug_read 3 14507 _001882_hash NULL
82938 +_001883_hash ocfs2_readlink 3 50656 _001883_hash NULL
82939 +_001884_hash oom_adjust_read 3 25127 _001884_hash NULL
82940 +_001885_hash oom_score_adj_read 3 39921 _002116_hash NULL nohasharray
82941 +_001886_hash oprofilefs_str_to_user 3 42182 _001886_hash NULL
82942 +_001887_hash oprofilefs_ulong_to_user 3 11582 _001887_hash NULL
82943 +_001888_hash _osd_req_list_objects 6 4204 _001888_hash NULL
82944 +_001889_hash osd_req_read_kern 5 59990 _001889_hash NULL
82945 +_001890_hash osd_req_write_kern 5 53486 _001890_hash NULL
82946 +_001891_hash p54_init_common 1 23850 _001891_hash NULL
82947 +_001892_hash packet_sendmsg 4 24954 _001892_hash NULL
82948 +_001893_hash page_readlink 3 23346 _001893_hash NULL
82949 +_001894_hash pcf50633_write_block 3 2124 _001894_hash NULL
82950 +_001895_hash platform_list_read_file 3 34734 _001895_hash NULL
82951 +_001896_hash pm860x_bulk_write 3 43875 _001896_hash NULL
82952 +_001897_hash pm_qos_power_read 3 55891 _001897_hash NULL
82953 +_001898_hash pms_read 3 53873 _001898_hash NULL
82954 +_001899_hash port_show_regs 3 5904 _001899_hash NULL
82955 +_001900_hash proc_coredump_filter_read 3 39153 _001900_hash NULL
82956 +_001901_hash proc_fdinfo_read 3 62043 _001901_hash NULL
82957 +_001902_hash proc_info_read 3 63344 _001902_hash NULL
82958 +_001903_hash proc_loginuid_read 3 15631 _001903_hash NULL
82959 +_001904_hash proc_pid_attr_read 3 10173 _001904_hash NULL
82960 +_001905_hash proc_pid_readlink 3 52186 _001905_hash NULL
82961 +_001906_hash proc_read 3 43614 _001906_hash NULL
82962 +_001907_hash proc_self_readlink 3 38094 _001907_hash NULL
82963 +_001908_hash proc_sessionid_read 3 6911 _002038_hash NULL nohasharray
82964 +_001909_hash provide_user_output 3 41105 _001909_hash NULL
82965 +_001910_hash ps_pspoll_max_apturn_read 3 6699 _001910_hash NULL
82966 +_001911_hash ps_pspoll_timeouts_read 3 11776 _001911_hash NULL
82967 +_001912_hash ps_pspoll_utilization_read 3 5361 _001912_hash NULL
82968 +_001913_hash pstore_file_read 3 57288 _001913_hash NULL
82969 +_001914_hash ps_upsd_max_apturn_read 3 19918 _001914_hash NULL
82970 +_001915_hash ps_upsd_max_sptime_read 3 63362 _001915_hash NULL
82971 +_001916_hash ps_upsd_timeouts_read 3 28924 _001916_hash NULL
82972 +_001917_hash ps_upsd_utilization_read 3 51669 _001917_hash NULL
82973 +_001918_hash pvr2_v4l2_read 3 18006 _001918_hash NULL
82974 +_001919_hash pwr_disable_ps_read 3 13176 _001919_hash NULL
82975 +_001920_hash pwr_elp_enter_read 3 5324 _001920_hash NULL
82976 +_001921_hash pwr_enable_ps_read 3 17686 _001921_hash NULL
82977 +_001922_hash pwr_fix_tsf_ps_read 3 26627 _001922_hash NULL
82978 +_001923_hash pwr_missing_bcns_read 3 25824 _001923_hash NULL
82979 +_001924_hash pwr_power_save_off_read 3 18355 _001924_hash NULL
82980 +_001925_hash pwr_ps_enter_read 3 26935 _001925_hash &_000501_hash
82981 +_001926_hash pwr_rcvd_awake_beacons_read 3 50505 _001926_hash NULL
82982 +_001927_hash pwr_rcvd_beacons_read 3 52836 _001927_hash NULL
82983 +_001928_hash pwr_tx_without_ps_read 3 48423 _001928_hash NULL
82984 +_001929_hash pwr_tx_with_ps_read 3 60851 _001929_hash NULL
82985 +_001930_hash pwr_wake_on_host_read 3 26321 _001930_hash NULL
82986 +_001931_hash pwr_wake_on_timer_exp_read 3 22640 _001931_hash NULL
82987 +_001932_hash queues_read 3 24877 _001932_hash NULL
82988 +_001933_hash raw_recvmsg 4 17277 _001933_hash NULL
82989 +_001934_hash rcname_read 3 25919 _001934_hash NULL
82990 +_001935_hash read_4k_modal_eeprom 3 30212 _001935_hash NULL
82991 +_001936_hash read_9287_modal_eeprom 3 59327 _001936_hash NULL
82992 +_001937_hash reada_find_extent 2 63486 _001937_hash NULL
82993 +_001938_hash read_def_modal_eeprom 3 14041 _001938_hash NULL
82994 +_001939_hash read_enabled_file_bool 3 37744 _001939_hash NULL
82995 +_001940_hash read_file_ani 3 23161 _001940_hash NULL
82996 +_001941_hash read_file_antenna 3 13574 _001941_hash NULL
82997 +_001942_hash read_file_base_eeprom 3 42168 _001942_hash NULL
82998 +_001943_hash read_file_beacon 3 32595 _001943_hash NULL
82999 +_001944_hash read_file_blob 3 57406 _001944_hash NULL
83000 +_001945_hash read_file_bool 3 4180 _001945_hash NULL
83001 +_001946_hash read_file_credit_dist_stats 3 54367 _001946_hash NULL
83002 +_001947_hash read_file_debug 3 58256 _001947_hash NULL
83003 +_001948_hash read_file_disable_ani 3 6536 _001948_hash NULL
83004 +_001949_hash read_file_dma 3 9530 _001949_hash NULL
83005 +_001950_hash read_file_dump_nfcal 3 18766 _001950_hash NULL
83006 +_001951_hash read_file_frameerrors 3 64001 _001951_hash NULL
83007 +_001952_hash read_file_interrupt 3 61742 _001959_hash NULL nohasharray
83008 +_001953_hash read_file_misc 3 9948 _001953_hash NULL
83009 +_001954_hash read_file_modal_eeprom 3 39909 _001954_hash NULL
83010 +_001955_hash read_file_queue 3 40895 _001955_hash NULL
83011 +_001956_hash read_file_rcstat 3 22854 _001956_hash NULL
83012 +_001957_hash read_file_recv 3 48232 _001957_hash NULL
83013 +_001958_hash read_file_regidx 3 33370 _001958_hash NULL
83014 +_001959_hash read_file_regval 3 61742 _001959_hash &_001952_hash
83015 +_001960_hash read_file_reset 3 52310 _001960_hash NULL
83016 +_001961_hash read_file_rx_chainmask 3 41605 _001961_hash NULL
83017 +_001962_hash read_file_slot 3 50111 _001962_hash NULL
83018 +_001963_hash read_file_stations 3 35795 _001963_hash NULL
83019 +_001964_hash read_file_tgt_int_stats 3 20697 _001964_hash NULL
83020 +_001965_hash read_file_tgt_rx_stats 3 33944 _001965_hash NULL
83021 +_001966_hash read_file_tgt_stats 3 8959 _001966_hash NULL
83022 +_001967_hash read_file_tgt_tx_stats 3 51847 _001967_hash NULL
83023 +_001968_hash read_file_tx_chainmask 3 3829 _001968_hash NULL
83024 +_001969_hash read_file_war_stats 3 292 _001969_hash NULL
83025 +_001970_hash read_file_xmit 3 21487 _001970_hash NULL
83026 +_001971_hash read_from_oldmem 2 3337 _001971_hash NULL
83027 +_001972_hash read_oldmem 3 55658 _001972_hash NULL
83028 +_001973_hash regmap_name_read_file 3 39379 _001973_hash NULL
83029 +_001974_hash repair_io_failure 4 4815 _001974_hash NULL
83030 +_001975_hash request_key_and_link 4 42693 _001975_hash NULL
83031 +_001976_hash res_counter_read 4 33499 _001976_hash NULL
83032 +_001977_hash retry_count_read 3 52129 _001977_hash NULL
83033 +_001978_hash rs_sta_dbgfs_rate_scale_data_read 3 47165 _001978_hash NULL
83034 +_001979_hash rs_sta_dbgfs_scale_table_read 3 40262 _001979_hash NULL
83035 +_001980_hash rs_sta_dbgfs_stats_table_read 3 56573 _001980_hash NULL
83036 +_001981_hash rts_threshold_read 3 44384 _001981_hash NULL
83037 +_001982_hash rx_dropped_read 3 44799 _001982_hash NULL
83038 +_001983_hash rx_fcs_err_read 3 62844 _001983_hash NULL
83039 +_001984_hash rx_hdr_overflow_read 3 64407 _001984_hash NULL
83040 +_001985_hash rx_hw_stuck_read 3 57179 _001985_hash NULL
83041 +_001986_hash rx_out_of_mem_read 3 10157 _001986_hash NULL
83042 +_001987_hash rx_path_reset_read 3 23801 _001987_hash NULL
83043 +_001988_hash rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 _001988_hash NULL
83044 +_001989_hash rxpipe_descr_host_int_trig_rx_data_read 3 22001 _001989_hash NULL
83045 +_001990_hash rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 _001990_hash NULL
83046 +_001991_hash rxpipe_rx_prep_beacon_drop_read 3 2403 _001991_hash NULL
83047 +_001992_hash rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 _001992_hash NULL
83048 +_001993_hash rx_reset_counter_read 3 58001 _001993_hash NULL
83049 +_001994_hash rx_xfr_hint_trig_read 3 40283 _001994_hash NULL
83050 +_001995_hash s5m_bulk_write 3 4833 _001995_hash NULL
83051 +_001996_hash scrub_setup_recheck_block 3-4 56245 _001996_hash NULL
83052 +_001998_hash scsi_adjust_queue_depth 3 12802 _001998_hash NULL
83053 +_001999_hash selinux_inode_notifysecctx 3 36896 _001999_hash NULL
83054 +_002000_hash sel_read_avc_cache_threshold 3 33942 _002000_hash NULL
83055 +_002001_hash sel_read_avc_hash_stats 3 1984 _002001_hash NULL
83056 +_002002_hash sel_read_bool 3 24236 _002002_hash NULL
83057 +_002003_hash sel_read_checkreqprot 3 33068 _002003_hash NULL
83058 +_002004_hash sel_read_class 3 12669 _002541_hash NULL nohasharray
83059 +_002005_hash sel_read_enforce 3 2828 _002005_hash NULL
83060 +_002006_hash sel_read_handle_status 3 56139 _002006_hash NULL
83061 +_002007_hash sel_read_handle_unknown 3 57933 _002007_hash NULL
83062 +_002008_hash sel_read_initcon 3 32362 _002008_hash NULL
83063 +_002009_hash sel_read_mls 3 25369 _002009_hash NULL
83064 +_002010_hash sel_read_perm 3 42302 _002010_hash NULL
83065 +_002011_hash sel_read_policy 3 55947 _002011_hash NULL
83066 +_002012_hash sel_read_policycap 3 28544 _002012_hash NULL
83067 +_002013_hash sel_read_policyvers 3 55 _002013_hash NULL
83068 +_002014_hash send_msg 4 37323 _002014_hash NULL
83069 +_002015_hash send_packet 4 52960 _002015_hash NULL
83070 +_002016_hash short_retry_limit_read 3 4687 _002016_hash NULL
83071 +_002017_hash simple_attr_read 3 24738 _002017_hash NULL
83072 +_002018_hash simple_transaction_read 3 17076 _002018_hash NULL
83073 +_002019_hash skb_copy_datagram_const_iovec 2-5-4 48102 _002019_hash NULL
83074 +_002022_hash skb_copy_datagram_iovec 2-4 5806 _002022_hash NULL
83075 +_002024_hash smk_read_ambient 3 61220 _002024_hash NULL
83076 +_002025_hash smk_read_direct 3 15803 _002025_hash NULL
83077 +_002026_hash smk_read_doi 3 30813 _002026_hash NULL
83078 +_002027_hash smk_read_logging 3 37804 _002027_hash NULL
83079 +_002028_hash smk_read_onlycap 3 3855 _002028_hash NULL
83080 +_002029_hash snapshot_read 3 22601 _002029_hash NULL
83081 +_002030_hash snd_cs4281_BA0_read 5 6847 _002030_hash NULL
83082 +_002031_hash snd_cs4281_BA1_read 5 20323 _002031_hash NULL
83083 +_002032_hash snd_cs46xx_io_read 5 45734 _002032_hash NULL
83084 +_002033_hash snd_gus_dram_read 4 56686 _002033_hash NULL
83085 +_002034_hash snd_pcm_oss_read 3 28317 _002034_hash NULL
83086 +_002035_hash snd_rme32_capture_copy 5 39653 _002035_hash NULL
83087 +_002036_hash snd_rme96_capture_copy 5 58484 _002036_hash NULL
83088 +_002037_hash snd_soc_hw_bulk_write_raw 4 14245 _002037_hash NULL
83089 +_002038_hash spi_show_regs 3 6911 _002038_hash &_001908_hash
83090 +_002039_hash sta_agg_status_read 3 14058 _002039_hash NULL
83091 +_002040_hash sta_connected_time_read 3 17435 _002040_hash NULL
83092 +_002041_hash sta_flags_read 3 56710 _002041_hash NULL
83093 +_002042_hash sta_ht_capa_read 3 10366 _002042_hash NULL
83094 +_002043_hash sta_last_seq_ctrl_read 3 19106 _002043_hash NULL
83095 +_002044_hash sta_num_ps_buf_frames_read 3 1488 _002044_hash NULL
83096 +_002045_hash st_read 3 51251 _002045_hash NULL
83097 +_002046_hash supply_map_read_file 3 10608 _002046_hash NULL
83098 +_002047_hash sysfs_read_file 3 42113 _002047_hash NULL
83099 +_002048_hash sys_lgetxattr 4 45531 _002048_hash NULL
83100 +_002049_hash sys_preadv 3 17100 _002049_hash NULL
83101 +_002050_hash sys_pwritev 3 41722 _002050_hash NULL
83102 +_002051_hash sys_readv 3 50664 _002051_hash NULL
83103 +_002052_hash sys_rt_sigpending 2 24961 _002052_hash NULL
83104 +_002053_hash sys_writev 3 28384 _002053_hash NULL
83105 +_002054_hash test_iso_queue 5 62534 _002054_hash NULL
83106 +_002055_hash ts_read 3 44687 _002055_hash NULL
83107 +_002056_hash TSS_authhmac 3 12839 _002056_hash NULL
83108 +_002057_hash TSS_checkhmac1 5 31429 _002057_hash NULL
83109 +_002058_hash TSS_checkhmac2 5-7 40520 _002058_hash NULL
83110 +_002060_hash tt3650_ci_msg_locked 4 8013 _002060_hash NULL
83111 +_002061_hash tun_sendmsg 4 10337 _002061_hash NULL
83112 +_002062_hash tx_internal_desc_overflow_read 3 47300 _002062_hash NULL
83113 +_002063_hash tx_queue_len_read 3 1463 _002063_hash NULL
83114 +_002064_hash tx_queue_status_read 3 44978 _002064_hash NULL
83115 +_002065_hash ubi_io_write_data 4-5 40305 _002065_hash NULL
83116 +_002067_hash uhci_debug_read 3 5911 _002067_hash NULL
83117 +_002068_hash unix_stream_recvmsg 4 35210 _002068_hash NULL
83118 +_002069_hash uvc_debugfs_stats_read 3 56651 _002069_hash NULL
83119 +_002070_hash vhost_add_used_and_signal_n 4 8038 _002070_hash NULL
83120 +_002071_hash vifs_state_read 3 33762 _002071_hash NULL
83121 +_002072_hash vmbus_open 2-3 12154 _002072_hash NULL
83122 +_002074_hash waiters_read 3 40902 _002074_hash NULL
83123 +_002075_hash wep_addr_key_count_read 3 20174 _002075_hash NULL
83124 +_002076_hash wep_decrypt_fail_read 3 58567 _002076_hash NULL
83125 +_002077_hash wep_default_key_count_read 3 43035 _002077_hash NULL
83126 +_002078_hash wep_interrupt_read 3 41492 _002078_hash NULL
83127 +_002079_hash wep_key_not_found_read 3 13377 _002079_hash &_000915_hash
83128 +_002080_hash wep_packets_read 3 18751 _002080_hash NULL
83129 +_002081_hash wl1271_format_buffer 2 20834 _002081_hash NULL
83130 +_002082_hash wm8994_bulk_write 3 13615 _002082_hash NULL
83131 +_002083_hash wusb_prf_256 7 29203 _002083_hash NULL
83132 +_002084_hash wusb_prf_64 7 51065 _002084_hash NULL
83133 +_002085_hash xfs_buf_read_uncached 4 27519 _002085_hash NULL
83134 +_002086_hash xfs_iext_add 3 41422 _002086_hash NULL
83135 +_002087_hash xfs_iext_remove_direct 3 40744 _002087_hash NULL
83136 +_002088_hash xfs_trans_get_efd 3 51148 _002088_hash NULL
83137 +_002089_hash xfs_trans_get_efi 2 7898 _002089_hash NULL
83138 +_002090_hash xlog_get_bp 2 23229 _002090_hash NULL
83139 +_002091_hash xz_dec_init 2 29029 _002091_hash NULL
83140 +_002092_hash aac_change_queue_depth 2 825 _002092_hash NULL
83141 +_002093_hash agp_allocate_memory_wrap 1 16576 _002093_hash NULL
83142 +_002094_hash arcmsr_adjust_disk_queue_depth 2 16756 _002094_hash NULL
83143 +_002095_hash atalk_recvmsg 4 22053 _002095_hash NULL
83144 +_002097_hash atomic_read_file 3 16227 _002097_hash NULL
83145 +_002098_hash ax25_recvmsg 4 64441 _002098_hash NULL
83146 +_002099_hash beacon_interval_read 3 7091 _002099_hash NULL
83147 +_002100_hash btrfs_init_new_buffer 4 55761 _002100_hash NULL
83148 +_002101_hash btrfs_mksubvol 3 39479 _002101_hash NULL
83149 +_002102_hash bt_sock_recvmsg 4 12316 _002102_hash NULL
83150 +_002103_hash bt_sock_stream_recvmsg 4 52518 _002103_hash NULL
83151 +_002104_hash caif_seqpkt_recvmsg 4 32241 _002104_hash NULL
83152 +_002105_hash cpu_type_read 3 36540 _002105_hash NULL
83153 +_002106_hash cx18_read 3 23699 _002106_hash NULL
83154 +_002107_hash dccp_recvmsg 4 16056 _002107_hash NULL
83155 +_002108_hash depth_read 3 31112 _002108_hash NULL
83156 +_002109_hash dfs_global_file_read 3 7787 _002109_hash NULL
83157 +_002110_hash dgram_recvmsg 4 23104 _002110_hash NULL
83158 +_002111_hash dma_skb_copy_datagram_iovec 3-5 21516 _002111_hash NULL
83159 +_002113_hash dtim_interval_read 3 654 _002113_hash NULL
83160 +_002114_hash dynamic_ps_timeout_read 3 10110 _002114_hash NULL
83161 +_002115_hash enable_read 3 2117 _002115_hash NULL
83162 +_002116_hash exofs_read_kern 6 39921 _002116_hash &_001885_hash
83163 +_002117_hash fc_change_queue_depth 2 36841 _002117_hash NULL
83164 +_002118_hash forced_ps_read 3 31685 _002118_hash NULL
83165 +_002119_hash frequency_read 3 64031 _002119_hash NULL
83166 +_002120_hash get_alua_req 3 4166 _002120_hash NULL
83167 +_002121_hash get_rdac_req 3 45882 _002121_hash NULL
83168 +_002122_hash hci_sock_recvmsg 4 7072 _002122_hash NULL
83169 +_002123_hash hpsa_change_queue_depth 2 15449 _002123_hash NULL
83170 +_002124_hash hptiop_adjust_disk_queue_depth 2 20122 _002124_hash NULL
83171 +_002125_hash ide_queue_pc_tail 5 11673 _002125_hash NULL
83172 +_002126_hash ide_raw_taskfile 4 42355 _002126_hash NULL
83173 +_002127_hash idetape_queue_rw_tail 3 29562 _002127_hash NULL
83174 +_002128_hash ieee80211_if_read_aid 3 9705 _002128_hash NULL
83175 +_002129_hash ieee80211_if_read_auto_open_plinks 3 38268 _002129_hash NULL
83176 +_002130_hash ieee80211_if_read_ave_beacon 3 64924 _002130_hash NULL
83177 +_002131_hash ieee80211_if_read_bssid 3 35161 _002131_hash NULL
83178 +_002132_hash ieee80211_if_read_channel_type 3 23884 _002132_hash NULL
83179 +_002133_hash ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 _002133_hash NULL
83180 +_002134_hash ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 _002134_hash NULL
83181 +_002135_hash ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 _002135_hash NULL
83182 +_002136_hash ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 _002136_hash NULL
83183 +_002137_hash ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 _002137_hash NULL
83184 +_002138_hash ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 _002138_hash NULL
83185 +_002139_hash ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 _002139_hash NULL
83186 +_002140_hash ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 _002140_hash NULL
83187 +_002141_hash ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 _002141_hash NULL
83188 +_002142_hash ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 _002142_hash NULL
83189 +_002143_hash ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 _002143_hash NULL
83190 +_002144_hash ieee80211_if_read_dot11MeshMaxRetries 3 12756 _002144_hash NULL
83191 +_002145_hash ieee80211_if_read_dot11MeshRetryTimeout 3 52168 _002145_hash NULL
83192 +_002146_hash ieee80211_if_read_dot11MeshTTL 3 58307 _002146_hash NULL
83193 +_002147_hash ieee80211_if_read_dropped_frames_congestion 3 32603 _002147_hash NULL
83194 +_002148_hash ieee80211_if_read_dropped_frames_no_route 3 33383 _002148_hash NULL
83195 +_002149_hash ieee80211_if_read_dropped_frames_ttl 3 44500 _002149_hash NULL
83196 +_002150_hash ieee80211_if_read_drop_unencrypted 3 37053 _002150_hash NULL
83197 +_002151_hash ieee80211_if_read_dtim_count 3 38419 _002151_hash NULL
83198 +_002152_hash ieee80211_if_read_element_ttl 3 18869 _002152_hash NULL
83199 +_002153_hash ieee80211_if_read_estab_plinks 3 32533 _002153_hash NULL
83200 +_002154_hash ieee80211_if_read_flags 3 57470 _002389_hash NULL nohasharray
83201 +_002155_hash ieee80211_if_read_fwded_frames 3 36520 _002155_hash NULL
83202 +_002156_hash ieee80211_if_read_fwded_mcast 3 39571 _002156_hash &_000151_hash
83203 +_002157_hash ieee80211_if_read_fwded_unicast 3 59740 _002157_hash NULL
83204 +_002158_hash ieee80211_if_read_last_beacon 3 31257 _002158_hash NULL
83205 +_002159_hash ieee80211_if_read_min_discovery_timeout 3 13946 _002159_hash NULL
83206 +_002160_hash ieee80211_if_read_num_buffered_multicast 3 12716 _002160_hash NULL
83207 +_002161_hash ieee80211_if_read_num_sta_authorized 3 56177 _002161_hash NULL
83208 +_002162_hash ieee80211_if_read_num_sta_ps 3 34722 _002162_hash NULL
83209 +_002163_hash ieee80211_if_read_path_refresh_time 3 25545 _002163_hash NULL
83210 +_002164_hash ieee80211_if_read_peer 3 45233 _002164_hash NULL
83211 +_002165_hash ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 _002165_hash NULL
83212 +_002166_hash ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 _002166_hash NULL
83213 +_002167_hash ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 _002167_hash NULL
83214 +_002168_hash ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 _002168_hash NULL
83215 +_002169_hash ieee80211_if_read_rssi_threshold 3 49260 _002169_hash NULL
83216 +_002170_hash ieee80211_if_read_smps 3 27416 _002170_hash NULL
83217 +_002171_hash ieee80211_if_read_state 3 9813 _002280_hash NULL nohasharray
83218 +_002172_hash ieee80211_if_read_tkip_mic_test 3 19565 _002172_hash NULL
83219 +_002173_hash ieee80211_if_read_tsf 3 16420 _002173_hash NULL
83220 +_002174_hash ieee80211_if_read_uapsd_max_sp_len 3 15067 _002174_hash NULL
83221 +_002175_hash ieee80211_if_read_uapsd_queues 3 55150 _002175_hash NULL
83222 +_002176_hash ieee80211_rx_mgmt_beacon 3 24430 _002176_hash NULL
83223 +_002177_hash ieee80211_rx_mgmt_probe_resp 3 6918 _002177_hash NULL
83224 +_002178_hash ima_show_htable_violations 3 10619 _002178_hash NULL
83225 +_002179_hash ima_show_measurements_count 3 23536 _002179_hash NULL
83226 +_002180_hash insert_one_name 7 61668 _002180_hash NULL
83227 +_002181_hash ipr_change_queue_depth 2 6431 _002181_hash NULL
83228 +_002182_hash ip_recv_error 3 23109 _002182_hash NULL
83229 +_002183_hash ipv6_recv_error 3 56347 _002183_hash NULL
83230 +_002184_hash ipv6_recv_rxpmtu 3 7142 _002184_hash NULL
83231 +_002185_hash ipx_recvmsg 4 44366 _002185_hash NULL
83232 +_002186_hash irda_recvmsg_dgram 4 32631 _002186_hash NULL
83233 +_002187_hash iscsi_change_queue_depth 2 23416 _002187_hash NULL
83234 +_002188_hash ivtv_read_pos 3 34400 _002188_hash &_000303_hash
83235 +_002189_hash key_conf_hw_key_idx_read 3 25003 _002189_hash NULL
83236 +_002190_hash key_conf_keyidx_read 3 42443 _002190_hash NULL
83237 +_002191_hash key_conf_keylen_read 3 49758 _002191_hash NULL
83238 +_002192_hash key_flags_read 3 25931 _002192_hash NULL
83239 +_002193_hash key_ifindex_read 3 31411 _002193_hash NULL
83240 +_002194_hash key_tx_rx_count_read 3 44742 _002194_hash NULL
83241 +_002195_hash l2cap_sock_sendmsg 4 63427 _002195_hash NULL
83242 +_002196_hash l2tp_ip_recvmsg 4 22681 _002196_hash NULL
83243 +_002197_hash llc_ui_recvmsg 4 3826 _002197_hash NULL
83244 +_002198_hash lpfc_change_queue_depth 2 25905 _002198_hash NULL
83245 +_002199_hash macvtap_do_read 4 36555 _002199_hash &_001832_hash
83246 +_002200_hash megaraid_change_queue_depth 2 64815 _002200_hash NULL
83247 +_002201_hash megasas_change_queue_depth 2 32747 _002201_hash NULL
83248 +_002202_hash mptscsih_change_queue_depth 2 26036 _002202_hash NULL
83249 +_002203_hash NCR_700_change_queue_depth 2 31742 _002203_hash NULL
83250 +_002204_hash netlink_recvmsg 4 61600 _002204_hash NULL
83251 +_002205_hash nfsctl_transaction_read 3 48250 _002205_hash NULL
83252 +_002206_hash nfs_map_group_to_gid 3 15892 _002206_hash NULL
83253 +_002207_hash nfs_map_name_to_uid 3 51132 _002207_hash NULL
83254 +_002208_hash nr_recvmsg 4 12649 _002208_hash NULL
83255 +_002209_hash osd_req_list_collection_objects 5 36664 _002209_hash NULL
83256 +_002210_hash osd_req_list_partition_objects 5 56464 _002210_hash NULL
83257 +_002212_hash packet_recv_error 3 16669 _002212_hash NULL
83258 +_002213_hash packet_recvmsg 4 47700 _002213_hash NULL
83259 +_002214_hash pep_recvmsg 4 19402 _002214_hash NULL
83260 +_002215_hash pfkey_recvmsg 4 53604 _002215_hash NULL
83261 +_002216_hash ping_recvmsg 4 25597 _002216_hash NULL
83262 +_002217_hash pmcraid_change_queue_depth 2 9116 _002217_hash NULL
83263 +_002218_hash pn_recvmsg 4 30887 _002218_hash NULL
83264 +_002219_hash pointer_size_read 3 51863 _002219_hash NULL
83265 +_002220_hash power_read 3 15939 _002220_hash NULL
83266 +_002221_hash pppoe_recvmsg 4 15073 _002221_hash NULL
83267 +_002222_hash pppol2tp_recvmsg 4 57742 _002222_hash NULL
83268 +_002223_hash qla2x00_adjust_sdev_qdepth_up 2 20097 _002223_hash NULL
83269 +_002224_hash qla2x00_change_queue_depth 2 24742 _002224_hash NULL
83270 +_002225_hash raw_recvmsg 4 52529 _002225_hash NULL
83271 +_002226_hash rawsock_recvmsg 4 12144 _002226_hash NULL
83272 +_002227_hash rawv6_recvmsg 4 30265 _002227_hash NULL
83273 +_002228_hash reada_add_block 2 54247 _002228_hash NULL
83274 +_002229_hash readahead_tree_block 3 36285 _002229_hash NULL
83275 +_002230_hash reada_tree_block_flagged 3 18402 _002230_hash NULL
83276 +_002231_hash read_tree_block 3 841 _002231_hash NULL
83277 +_002232_hash recover_peb 6-7 29238 _002232_hash NULL
83278 +_002234_hash recv_msg 4 48709 _002234_hash NULL
83279 +_002235_hash recv_stream 4 30138 _002235_hash NULL
83280 +_002236_hash _req_append_segment 2 41031 _002236_hash NULL
83281 +_002237_hash request_key_async 4 6990 _002237_hash NULL
83282 +_002238_hash request_key_async_with_auxdata 4 46624 _002238_hash NULL
83283 +_002239_hash request_key_with_auxdata 4 24515 _002239_hash NULL
83284 +_002240_hash rose_recvmsg 4 2368 _002240_hash NULL
83285 +_002241_hash rxrpc_recvmsg 4 26233 _002241_hash NULL
83286 +_002242_hash rx_streaming_always_read 3 49401 _002242_hash NULL
83287 +_002243_hash rx_streaming_interval_read 3 55291 _002243_hash NULL
83288 +_002244_hash sas_change_queue_depth 2 18555 _002244_hash NULL
83289 +_002245_hash scsi_activate_tcq 2 42640 _002245_hash NULL
83290 +_002246_hash scsi_deactivate_tcq 2 47086 _002246_hash NULL
83291 +_002247_hash scsi_execute 5 33596 _002247_hash NULL
83292 +_002248_hash _scsih_adjust_queue_depth 2 1083 _002248_hash NULL
83293 +_002249_hash scsi_init_shared_tag_map 2 59812 _002249_hash NULL
83294 +_002250_hash scsi_track_queue_full 2 44239 _002250_hash NULL
83295 +_002251_hash sctp_recvmsg 4 23265 _002251_hash NULL
83296 +_002252_hash send_stream 4 3397 _002252_hash NULL
83297 +_002253_hash skb_copy_and_csum_datagram_iovec 2 24466 _002253_hash NULL
83298 +_002255_hash snd_gf1_mem_proc_dump 5 16926 _002255_hash NULL
83299 +_002256_hash split_scan_timeout_read 3 20029 _002256_hash NULL
83300 +_002257_hash sta_dev_read 3 14782 _002257_hash NULL
83301 +_002258_hash sta_inactive_ms_read 3 25690 _002258_hash NULL
83302 +_002259_hash sta_last_signal_read 3 31818 _002259_hash NULL
83303 +_002260_hash stats_dot11ACKFailureCount_read 3 45558 _002260_hash NULL
83304 +_002261_hash stats_dot11FCSErrorCount_read 3 28154 _002261_hash NULL
83305 +_002262_hash stats_dot11RTSFailureCount_read 3 43948 _002262_hash NULL
83306 +_002263_hash stats_dot11RTSSuccessCount_read 3 33065 _002263_hash NULL
83307 +_002264_hash storvsc_connect_to_vsp 2 22 _002264_hash NULL
83308 +_002265_hash suspend_dtim_interval_read 3 64971 _002265_hash NULL
83309 +_002266_hash sys_msgrcv 3 959 _002266_hash NULL
83310 +_002267_hash tcm_loop_change_queue_depth 2 42454 _002267_hash NULL
83311 +_002268_hash tcp_copy_to_iovec 3 28344 _002268_hash NULL
83312 +_002269_hash tcp_recvmsg 4 31238 _002269_hash NULL
83313 +_002270_hash timeout_read 3 47915 _002270_hash NULL
83314 +_002271_hash total_ps_buffered_read 3 16365 _002271_hash NULL
83315 +_002272_hash tun_put_user 4 59849 _002272_hash NULL
83316 +_002273_hash twa_change_queue_depth 2 48808 _002273_hash NULL
83317 +_002274_hash tw_change_queue_depth 2 11116 _002274_hash NULL
83318 +_002275_hash twl_change_queue_depth 2 41342 _002275_hash NULL
83319 +_002276_hash ubi_eba_write_leb 5-6 19826 _002276_hash NULL
83320 +_002278_hash ubi_eba_write_leb_st 5 27896 _002278_hash NULL
83321 +_002279_hash udp_recvmsg 4 42558 _002279_hash NULL
83322 +_002280_hash udpv6_recvmsg 4 9813 _002280_hash &_002171_hash
83323 +_002281_hash ulong_read_file 3 42304 _002281_hash &_000511_hash
83324 +_002282_hash unix_dgram_recvmsg 4 14952 _002282_hash NULL
83325 +_002283_hash user_power_read 3 39414 _002283_hash NULL
83326 +_002284_hash vcc_recvmsg 4 37198 _002284_hash NULL
83327 +_002285_hash wep_iv_read 3 54744 _002285_hash NULL
83328 +_002286_hash x25_recvmsg 4 42777 _002286_hash NULL
83329 +_002287_hash xfs_iext_insert 3 18667 _002287_hash NULL
83330 +_002288_hash xfs_iext_remove 3 50909 _002288_hash NULL
83331 +_002289_hash xlog_find_verify_log_record 2 18870 _002289_hash NULL
83332 +_002290_hash btrfs_alloc_free_block 3 29982 _002290_hash NULL
83333 +_002291_hash cx18_read_pos 3 4683 _002291_hash NULL
83334 +_002292_hash l2cap_sock_recvmsg 4 59886 _002292_hash NULL
83335 +_002293_hash osd_req_list_dev_partitions 4 60027 _002293_hash NULL
83336 +_002294_hash osd_req_list_partition_collections 5 38223 _002294_hash NULL
83337 +_002295_hash osst_do_scsi 4 44410 _002295_hash NULL
83338 +_002296_hash qla2x00_handle_queue_full 2 24365 _002296_hash NULL
83339 +_002297_hash rfcomm_sock_recvmsg 4 22227 _002297_hash NULL
83340 +_002298_hash scsi_execute_req 5 42088 _002298_hash NULL
83341 +_002299_hash _scsih_change_queue_depth 2 26230 _002299_hash NULL
83342 +_002300_hash spi_execute 5 28736 _002300_hash NULL
83343 +_002301_hash submit_inquiry 3 42108 _002301_hash NULL
83344 +_002302_hash tcp_dma_try_early_copy 3 37651 _002302_hash NULL
83345 +_002303_hash tun_do_read 4 50800 _002303_hash NULL
83346 +_002304_hash ubi_eba_atomic_leb_change 5 13041 _002304_hash NULL
83347 +_002305_hash ubi_leb_write 4-5 41691 _002305_hash NULL
83348 +_002307_hash unix_seqpacket_recvmsg 4 23062 _002307_hash NULL
83349 +_002308_hash write_leb 5 36957 _002308_hash NULL
83350 +_002309_hash ch_do_scsi 4 31171 _002309_hash NULL
83351 +_002310_hash dbg_leb_write 4-5 20478 _002310_hash NULL
83352 +_002312_hash scsi_mode_sense 5 16835 _002312_hash NULL
83353 +_002313_hash scsi_vpd_inquiry 4 30040 _002313_hash NULL
83354 +_002314_hash ses_recv_diag 4 47143 _002314_hash &_000673_hash
83355 +_002315_hash ses_send_diag 4 64527 _002315_hash NULL
83356 +_002316_hash spi_dv_device_echo_buffer 2-3 39846 _002316_hash NULL
83357 +_002318_hash ubifs_leb_write 4-5 61226 _002318_hash NULL
83358 +_002320_hash ubi_leb_change 4 14899 _002320_hash NULL
83359 +_002321_hash ubi_write 4-5 30809 _002321_hash NULL
83360 +_002322_hash dbg_leb_change 4 19969 _002322_hash NULL
83361 +_002323_hash gluebi_write 3 27905 _002323_hash NULL
83362 +_002324_hash scsi_get_vpd_page 4 51951 _002324_hash NULL
83363 +_002325_hash sd_do_mode_sense 5 11507 _002325_hash NULL
83364 +_002326_hash ubifs_leb_change 4 22399 _002436_hash NULL nohasharray
83365 +_002327_hash ubifs_write_node 5 15088 _002327_hash NULL
83366 +_002328_hash fixup_leb 3 43256 _002328_hash NULL
83367 +_002329_hash recover_head 3 17904 _002329_hash NULL
83368 +_002330_hash alloc_cpu_rmap 1 65363 _002330_hash NULL
83369 +_002331_hash alloc_ebda_hpc 1-2 50046 _002331_hash NULL
83370 +_002333_hash alloc_sched_domains 1 28972 _002333_hash NULL
83371 +_002334_hash amthi_read 4 45831 _002334_hash NULL
83372 +_002335_hash bcm_char_read 3 31750 _002335_hash NULL
83373 +_002336_hash BcmCopySection 5 2035 _002336_hash NULL
83374 +_002337_hash buffer_from_user 3 51826 _002337_hash NULL
83375 +_002338_hash buffer_to_user 3 35439 _002338_hash NULL
83376 +_002339_hash c4iw_init_resource_fifo 3 48090 _002339_hash NULL
83377 +_002340_hash c4iw_init_resource_fifo_random 3 25547 _002340_hash NULL
83378 +_002341_hash card_send_command 3 40757 _002341_hash NULL
83379 +_002342_hash chd_dec_fetch_cdata 3 50926 _002342_hash NULL
83380 +_002343_hash crystalhd_create_dio_pool 2 3427 _002343_hash NULL
83381 +_002344_hash crystalhd_user_data 3 18407 _002344_hash NULL
83382 +_002345_hash cxio_init_resource_fifo 3 28764 _002345_hash NULL
83383 +_002346_hash cxio_init_resource_fifo_random 3 47151 _002346_hash NULL
83384 +_002347_hash do_pages_stat 2 4437 _002347_hash NULL
83385 +_002348_hash do_read_log_to_user 4 3236 _002348_hash NULL
83386 +_002349_hash do_write_log_from_user 3 39362 _002349_hash NULL
83387 +_002350_hash dt3155_read 3 59226 _002350_hash NULL
83388 +_002351_hash easycap_alsa_vmalloc 2 14426 _002351_hash NULL
83389 +_002352_hash evm_read_key 3 54674 _002352_hash NULL
83390 +_002353_hash evm_write_key 3 27715 _002353_hash NULL
83391 +_002354_hash fir16_create 3 5574 _002354_hash NULL
83392 +_002355_hash iio_allocate_device 1 18821 _002355_hash NULL
83393 +_002356_hash __iio_allocate_kfifo 2-3 55738 _002356_hash NULL
83394 +_002358_hash __iio_allocate_sw_ring_buffer 3 4843 _002358_hash NULL
83395 +_002359_hash iio_debugfs_read_reg 3 60908 _002359_hash NULL
83396 +_002360_hash iio_debugfs_write_reg 3 22742 _002360_hash NULL
83397 +_002361_hash iio_event_chrdev_read 3 54757 _002361_hash NULL
83398 +_002362_hash iio_read_first_n_kfifo 2 57910 _002362_hash NULL
83399 +_002363_hash iio_read_first_n_sw_rb 2 51911 _002363_hash NULL
83400 +_002364_hash ioapic_setup_resources 1 35255 _002364_hash NULL
83401 +_002365_hash keymap_store 4 45406 _002365_hash NULL
83402 +_002366_hash kzalloc_node 1 24352 _002366_hash NULL
83403 +_002367_hash line6_alloc_sysex_buffer 4 28225 _002367_hash NULL
83404 +_002368_hash line6_dumpreq_initbuf 3 53123 _002368_hash NULL
83405 +_002369_hash line6_midibuf_init 2 52425 _002369_hash NULL
83406 +_002370_hash lirc_write 3 20604 _002370_hash NULL
83407 +_002371_hash _malloc 1 54077 _002371_hash NULL
83408 +_002372_hash mei_read 3 6507 _002372_hash NULL
83409 +_002373_hash mei_write 3 4005 _002373_hash NULL
83410 +_002374_hash mempool_create_node 1 44715 _002374_hash NULL
83411 +_002375_hash msg_set 3 51725 _002375_hash NULL
83412 +_002376_hash newpart 6 47485 _002376_hash NULL
83413 +_002377_hash OS_kmalloc 1 36909 _002377_hash NULL
83414 +_002378_hash pcpu_alloc_bootmem 2 62074 _002378_hash NULL
83415 +_002379_hash pcpu_get_vm_areas 3 50085 _002379_hash NULL
83416 +_002380_hash resource_from_user 3 30341 _002380_hash NULL
83417 +_002381_hash sca3000_read_data 4 57064 _002381_hash NULL
83418 +_002382_hash sca3000_read_first_n_hw_rb 2 11479 _002382_hash NULL
83419 +_002383_hash send_midi_async 3 57463 _002383_hash NULL
83420 +_002384_hash sep_create_dcb_dmatables_context 6 37551 _002384_hash NULL
83421 +_002385_hash sep_create_dcb_dmatables_context_kernel 6 49728 _002385_hash NULL
83422 +_002386_hash sep_create_msgarea_context 4 33829 _002386_hash NULL
83423 +_002387_hash sep_lli_table_secure_dma 2-3 64042 _002387_hash NULL
83424 +_002389_hash sep_lock_user_pages 2-3 57470 _002389_hash &_002154_hash
83425 +_002391_hash sep_prepare_input_output_dma_table_in_dcb 4-5 63087 _002391_hash NULL
83426 +_002393_hash sep_read 3 17161 _002393_hash NULL
83427 +_002394_hash TransmitTcb 4 12989 _002394_hash NULL
83428 +_002395_hash ValidateDSDParamsChecksum 3 63654 _002395_hash NULL
83429 +_002396_hash Wb35Reg_BurstWrite 4 62327 _002396_hash NULL
83430 +_002397_hash __alloc_bootmem_low_node 2 25726 _002397_hash &_001499_hash
83431 +_002398_hash __alloc_bootmem_node 2 1992 _002398_hash NULL
83432 +_002399_hash alloc_irq_cpu_rmap 1 28459 _002399_hash NULL
83433 +_002400_hash alloc_ring 2-4 18278 _002400_hash NULL
83434 +_002402_hash c4iw_init_resource 2-3 30393 _002402_hash NULL
83435 +_002404_hash cxio_hal_init_resource 2-7-6 29771 _002404_hash &_000284_hash
83436 +_002407_hash cxio_hal_init_rhdl_resource 1 25104 _002407_hash NULL
83437 +_002408_hash disk_expand_part_tbl 2 30561 _002408_hash NULL
83438 +_002409_hash InterfaceTransmitPacket 3 42058 _002409_hash NULL
83439 +_002410_hash line6_dumpreq_init 3 34473 _002410_hash NULL
83440 +_002411_hash mempool_create 1 29437 _002411_hash NULL
83441 +_002412_hash pcpu_fc_alloc 2 11818 _002412_hash NULL
83442 +_002413_hash pod_alloc_sysex_buffer 3 31651 _002413_hash NULL
83443 +_002414_hash r8712_usbctrl_vendorreq 6 48489 _002414_hash NULL
83444 +_002415_hash r871x_set_wpa_ie 3 7000 _002415_hash NULL
83445 +_002416_hash sys_move_pages 2 42626 _002416_hash NULL
83446 +_002417_hash variax_alloc_sysex_buffer 3 15237 _002417_hash NULL
83447 +_002418_hash vme_user_write 3 15587 _002418_hash NULL
83448 +_002419_hash add_partition 2 55588 _002419_hash NULL
83449 +_002420_hash __alloc_bootmem_node_high 2 65076 _002420_hash NULL
83450 +_002421_hash ceph_msgpool_init 3 33312 _002421_hash NULL
83451 +_002423_hash mempool_create_kmalloc_pool 1 41650 _002423_hash NULL
83452 +_002424_hash mempool_create_page_pool 1 30189 _002424_hash NULL
83453 +_002425_hash mempool_create_slab_pool 1 62907 _002425_hash NULL
83454 +_002426_hash variax_set_raw2 4 32374 _002426_hash NULL
83455 +_002427_hash bioset_create 1 5580 _002427_hash NULL
83456 +_002428_hash bioset_integrity_create 2 62708 _002428_hash NULL
83457 +_002429_hash biovec_create_pools 2 9575 _002429_hash NULL
83458 +_002430_hash i2o_pool_alloc 4 55485 _002430_hash NULL
83459 +_002431_hash prison_create 1 43623 _002431_hash NULL
83460 +_002432_hash unlink_simple 3 47506 _002432_hash NULL
83461 +_002433_hash alloc_ieee80211 1 20063 _002433_hash NULL
83462 +_002434_hash alloc_ieee80211_rsl 1 34564 _002434_hash NULL
83463 +_002435_hash alloc_page_cgroup 1 2919 _002435_hash NULL
83464 +_002436_hash alloc_private 2 22399 _002436_hash &_002326_hash
83465 +_002437_hash alloc_rtllib 1 51136 _002437_hash NULL
83466 +_002438_hash alloc_rx_desc_ring 2 18016 _002438_hash NULL
83467 +_002439_hash alloc_subdevices 2 43300 _002439_hash NULL
83468 +_002440_hash atomic_counters_read 3 48827 _002440_hash NULL
83469 +_002441_hash atomic_stats_read 3 36228 _002441_hash NULL
83470 +_002442_hash capabilities_read 3 58457 _002442_hash NULL
83471 +_002443_hash comedi_read 3 13199 _002443_hash NULL
83472 +_002444_hash comedi_write 3 47926 _002444_hash NULL
83473 +_002445_hash compat_do_arpt_set_ctl 4 12184 _002445_hash NULL
83474 +_002446_hash compat_do_ip6t_set_ctl 4 3184 _002446_hash NULL
83475 +_002447_hash compat_do_ipt_set_ctl 4 58466 _002447_hash &_001852_hash
83476 +_002448_hash compat_filldir 3 32999 _002448_hash NULL
83477 +_002449_hash compat_filldir64 3 35354 _002449_hash NULL
83478 +_002450_hash compat_fillonedir 3 15620 _002450_hash NULL
83479 +_002451_hash compat_rw_copy_check_uvector 3 25242 _002451_hash NULL
83480 +_002452_hash compat_sock_setsockopt 5 23 _002452_hash NULL
83481 +_002453_hash compat_sys_kexec_load 2 35674 _002453_hash NULL
83482 +_002454_hash compat_sys_keyctl 4 9639 _002454_hash NULL
83483 +_002455_hash compat_sys_move_pages 2 5861 _002455_hash NULL
83484 +_002456_hash compat_sys_mq_timedsend 3 31060 _002456_hash NULL
83485 +_002457_hash compat_sys_msgrcv 2 7482 _002457_hash NULL
83486 +_002458_hash compat_sys_msgsnd 2 10738 _002458_hash NULL
83487 +_002459_hash compat_sys_semtimedop 3 3606 _002459_hash NULL
83488 +_002460_hash __copy_in_user 3 34790 _002460_hash NULL
83489 +_002461_hash copy_in_user 3 57502 _002461_hash NULL
83490 +_002462_hash dev_counters_read 3 19216 _002462_hash NULL
83491 +_002463_hash dev_names_read 3 38509 _002463_hash NULL
83492 +_002464_hash do_arpt_set_ctl 4 51053 _002464_hash NULL
83493 +_002465_hash do_ip6t_set_ctl 4 60040 _002465_hash NULL
83494 +_002466_hash do_ipt_set_ctl 4 56238 _002466_hash NULL
83495 +_002467_hash drbd_bm_resize 2 20522 _002467_hash NULL
83496 +_002468_hash driver_names_read 3 60399 _002468_hash NULL
83497 +_002469_hash driver_stats_read 3 8944 _002469_hash NULL
83498 +_002470_hash __earlyonly_bootmem_alloc 2 23824 _002470_hash NULL
83499 +_002471_hash evtchn_read 3 3569 _002471_hash NULL
83500 +_002472_hash ext_sd_execute_read_data 9 48589 _002472_hash NULL
83501 +_002473_hash ext_sd_execute_write_data 9 8175 _002473_hash NULL
83502 +_002474_hash fat_compat_ioctl_filldir 3 36328 _002474_hash NULL
83503 +_002475_hash firmwareUpload 3 32794 _002475_hash NULL
83504 +_002476_hash flash_read 3 57843 _002476_hash NULL
83505 +_002477_hash flash_write 3 62354 _002477_hash NULL
83506 +_002478_hash gather_array 3 56641 _002478_hash NULL
83507 +_002479_hash ghash_async_setkey 3 60001 _002479_hash NULL
83508 +_002480_hash gntdev_alloc_map 2 35145 _002480_hash NULL
83509 +_002481_hash gnttab_map 2 56439 _002481_hash NULL
83510 +_002482_hash gru_alloc_gts 2-3 60056 _002482_hash NULL
83511 +_002484_hash handle_eviocgbit 3 44193 _002484_hash NULL
83512 +_002485_hash hid_parse_report 3 51737 _002485_hash NULL
83513 +_002486_hash ieee80211_alloc_txb 1 52477 _002486_hash NULL
83514 +_002487_hash ieee80211_wx_set_gen_ie 3 51399 _002487_hash NULL
83515 +_002488_hash ieee80211_wx_set_gen_ie_rsl 3 3521 _002488_hash NULL
83516 +_002489_hash init_cdev 1 8274 _002489_hash NULL
83517 +_002490_hash init_per_cpu 1 17880 _002490_hash NULL
83518 +_002491_hash ipath_create_cq 2 45586 _002491_hash NULL
83519 +_002492_hash ipath_get_base_info 3 7043 _002492_hash NULL
83520 +_002493_hash ipath_init_qp_table 2 25167 _002493_hash NULL
83521 +_002494_hash ipath_resize_cq 2 712 _002494_hash NULL
83522 +_002495_hash ni_gpct_device_construct 5 610 _002495_hash NULL
83523 +_002496_hash options_write 3 47243 _002496_hash NULL
83524 +_002497_hash portcntrs_1_read 3 47253 _002497_hash NULL
83525 +_002498_hash portcntrs_2_read 3 56586 _002498_hash NULL
83526 +_002499_hash portnames_read 3 41958 _002499_hash NULL
83527 +_002500_hash ptc_proc_write 3 12076 _002500_hash NULL
83528 +_002501_hash put_cmsg_compat 4 35937 _002501_hash NULL
83529 +_002502_hash qib_alloc_devdata 2 51819 _002502_hash NULL
83530 +_002503_hash qib_alloc_fast_reg_page_list 2 10507 _002503_hash NULL
83531 +_002504_hash qib_cdev_init 1 34778 _002504_hash NULL
83532 +_002505_hash qib_create_cq 2 27497 _002505_hash NULL
83533 +_002506_hash qib_diag_write 3 62133 _002506_hash NULL
83534 +_002507_hash qib_get_base_info 3 11369 _002507_hash NULL
83535 +_002508_hash qib_resize_cq 2 53090 _002508_hash NULL
83536 +_002509_hash qsfp_1_read 3 21915 _002509_hash NULL
83537 +_002510_hash qsfp_2_read 3 31491 _002510_hash NULL
83538 +_002511_hash queue_reply 3 22416 _002511_hash NULL
83539 +_002512_hash Realloc 2 34961 _002512_hash NULL
83540 +_002513_hash rfc4106_set_key 3 54519 _002513_hash NULL
83541 +_002514_hash rtllib_alloc_txb 1 21687 _002514_hash NULL
83542 +_002515_hash rtllib_wx_set_gen_ie 3 59808 _002515_hash NULL
83543 +_002516_hash rts51x_transfer_data_partial 6 5735 _002516_hash NULL
83544 +_002517_hash sparse_early_usemaps_alloc_node 4 9269 _002517_hash NULL
83545 +_002518_hash split 2 11691 _002518_hash NULL
83546 +_002519_hash stats_read_ul 3 32751 _002519_hash NULL
83547 +_002520_hash store_debug_level 3 35652 _002520_hash NULL
83548 +_002521_hash sys32_ipc 3 7238 _002521_hash NULL
83549 +_002522_hash sys32_rt_sigpending 2 25814 _002522_hash NULL
83550 +_002523_hash tunables_read 3 36385 _002523_hash NULL
83551 +_002524_hash tunables_write 3 59563 _002524_hash NULL
83552 +_002525_hash u32_array_read 3 2219 _002525_hash NULL
83553 +_002526_hash usb_buffer_alloc 2 36276 _002526_hash NULL
83554 +_002527_hash xenbus_file_write 3 6282 _002527_hash NULL
83555 +_002528_hash xpc_kmalloc_cacheline_aligned 1 42895 _002528_hash NULL
83556 +_002529_hash xpc_kzalloc_cacheline_aligned 1 65433 _002529_hash NULL
83557 +_002530_hash xsd_read 3 15653 _002530_hash NULL
83558 +_002531_hash compat_do_readv_writev 4 49102 _002531_hash NULL
83559 +_002532_hash compat_keyctl_instantiate_key_iov 3 57431 _002532_hash NULL
83560 +_002533_hash compat_process_vm_rw 3-5 22254 _002533_hash NULL
83561 +_002535_hash compat_sys_setsockopt 5 3326 _002535_hash NULL
83562 +_002536_hash ipath_cdev_init 1 37752 _002536_hash NULL
83563 +_002537_hash ms_read_multiple_pages 4-5 8052 _002537_hash NULL
83564 +_002539_hash ms_write_multiple_pages 5-6 10362 _002539_hash NULL
83565 +_002541_hash sparse_mem_maps_populate_node 4 12669 _002541_hash &_002004_hash
83566 +_002542_hash vmemmap_alloc_block 1 43245 _002542_hash NULL
83567 +_002543_hash xd_read_multiple_pages 4-5 11422 _002543_hash NULL
83568 +_002545_hash xd_write_multiple_pages 5-6 53633 _002545_hash NULL
83569 +_002546_hash compat_readv 3 30273 _002546_hash NULL
83570 +_002547_hash compat_sys_process_vm_readv 3-5 15374 _002547_hash NULL
83571 +_002549_hash compat_sys_process_vm_writev 3-5 41194 _002549_hash NULL
83572 +_002551_hash compat_writev 3 60063 _002551_hash NULL
83573 +_002552_hash ms_rw_multi_sector 4 7459 _002552_hash NULL
83574 +_002553_hash sparse_early_mem_maps_alloc_node 4 36971 _002553_hash NULL
83575 +_002554_hash vmemmap_alloc_block_buf 1 61126 _002554_hash NULL
83576 +_002555_hash xd_rw 4 49020 _002555_hash NULL
83577 +_002556_hash compat_sys_preadv64 3 24283 _002556_hash NULL
83578 +_002557_hash compat_sys_pwritev64 3 51151 _002557_hash NULL
83579 +_002558_hash compat_sys_readv 3 20911 _002558_hash NULL
83580 +_002559_hash compat_sys_writev 3 5784 _002559_hash NULL
83581 +_002560_hash ms_rw 4 17220 _002560_hash NULL
83582 +_002561_hash compat_sys_preadv 3 583 _002561_hash NULL
83583 +_002562_hash compat_sys_pwritev 3 17886 _002562_hash NULL
83584 +_002563_hash alloc_apertures 1 56561 _002563_hash NULL
83585 +_002564_hash bin_uuid 3 28999 _002564_hash NULL
83586 +_002565_hash __copy_from_user_inatomic_nocache 3 49921 _002565_hash NULL
83587 +_002566_hash do_dmabuf_dirty_sou 7 3017 _002566_hash NULL
83588 +_002567_hash do_surface_dirty_sou 7 39678 _002567_hash NULL
83589 +_002568_hash drm_agp_bind_pages 3 56748 _002568_hash NULL
83590 +_002569_hash drm_calloc_large 1-2 65421 _002569_hash NULL
83591 +_002571_hash drm_fb_helper_init 3-4 19044 _002571_hash NULL
83592 +_002573_hash drm_ht_create 2 18853 _002573_hash NULL
83593 +_002574_hash drm_malloc_ab 1-2 16831 _002574_hash NULL
83594 +_002576_hash drm_mode_crtc_set_gamma_size 2 31881 _002576_hash NULL
83595 +_002577_hash drm_plane_init 6 28731 _002577_hash NULL
83596 +_002578_hash drm_property_create 4 51239 _002578_hash NULL
83597 +_002579_hash drm_property_create_blob 2 7414 _002579_hash NULL
83598 +_002580_hash drm_vblank_init 2 11362 _002580_hash NULL
83599 +_002581_hash drm_vmalloc_dma 1 14550 _002581_hash NULL
83600 +_002582_hash fb_alloc_cmap_gfp 2 20792 _002582_hash NULL
83601 +_002583_hash fbcon_prepare_logo 5 6246 _002583_hash NULL
83602 +_002584_hash fb_read 3 33506 _002584_hash NULL
83603 +_002585_hash fb_write 3 46924 _002585_hash NULL
83604 +_002586_hash framebuffer_alloc 1 59145 _002586_hash NULL
83605 +_002587_hash i915_cache_sharing_read 3 24775 _002587_hash NULL
83606 +_002588_hash i915_cache_sharing_write 3 57961 _002588_hash NULL
83607 +_002589_hash i915_max_freq_read 3 20581 _002589_hash NULL
83608 +_002590_hash i915_max_freq_write 3 11350 _002590_hash NULL
83609 +_002591_hash i915_wedged_read 3 35474 _002591_hash NULL
83610 +_002592_hash i915_wedged_write 3 47771 _002592_hash NULL
83611 +_002593_hash p9_client_read 5 19750 _002593_hash NULL
83612 +_002594_hash probe_kernel_write 3 17481 _002594_hash NULL
83613 +_002595_hash sched_feat_write 3 55202 _002595_hash NULL
83614 +_002596_hash sd_alloc_ctl_entry 1 29708 _002596_hash NULL
83615 +_002597_hash tstats_write 3 60432 _002597_hash &_000009_hash
83616 +_002598_hash ttm_bo_fbdev_io 4 9805 _002598_hash NULL
83617 +_002599_hash ttm_bo_io 5 47000 _002599_hash NULL
83618 +_002600_hash ttm_dma_page_pool_free 2 34135 _002600_hash NULL
83619 +_002601_hash ttm_page_pool_free 2 61661 _002601_hash NULL
83620 +_002602_hash vmw_execbuf_process 5 22885 _002602_hash NULL
83621 +_002603_hash vmw_fifo_reserve 2 12141 _002603_hash NULL
83622 +_002604_hash vmw_kms_present 9 38130 _002604_hash NULL
83623 +_002605_hash vmw_kms_readback 6 5727 _002605_hash NULL
83624 +_002606_hash do_dmabuf_dirty_ldu 6 52241 _002606_hash NULL
83625 +_002607_hash drm_mode_create_tv_properties 2 23122 _002607_hash NULL
83626 +_002608_hash drm_property_create_enum 5 29201 _002608_hash NULL
83627 +_002609_hash fast_user_write 5 20494 _002609_hash NULL
83628 +_002610_hash fb_alloc_cmap 2 6554 _002610_hash NULL
83629 +_002611_hash i915_gem_execbuffer_relocate_slow 7 25355 _002611_hash NULL
83630 +_002612_hash kgdb_hex2mem 3 24755 _002612_hash NULL
83631 +_002613_hash ttm_object_device_init 2 10321 _002613_hash NULL
83632 +_002614_hash ttm_object_file_init 2 27804 _002614_hash NULL
83633 +_002615_hash vmw_cursor_update_image 3-4 16332 _002615_hash NULL
83634 +_002617_hash vmw_gmr2_bind 3 21305 _002617_hash NULL
83635 +_002618_hash vmw_cursor_update_dmabuf 3-4 32045 _002618_hash NULL
83636 +_002620_hash vmw_gmr_bind 3 44130 _002620_hash NULL
83637 +_002621_hash vmw_du_crtc_cursor_set 4-5 28479 _002621_hash NULL
83638 +_002622_hash __module_alloc 1 50004 _002622_hash NULL
83639 +_002623_hash module_alloc_update_bounds_rw 1 63233 _002623_hash NULL
83640 +_002624_hash module_alloc_update_bounds_rx 1 58634 _002624_hash NULL
83641 +_002625_hash acpi_system_write_alarm 3 40205 _002625_hash NULL
83642 +_002626_hash create_table 2 16213 _002626_hash NULL
83643 +_002627_hash mem_read 3 57631 _002627_hash NULL
83644 +_002628_hash mem_write 3 22232 _002628_hash NULL
83645 +_002629_hash proc_fault_inject_read 3 36802 _002629_hash NULL
83646 +_002630_hash proc_fault_inject_write 3 21058 _002630_hash NULL
83647 +_002631_hash v9fs_fid_readn 4 60544 _002631_hash NULL
83648 +_002632_hash v9fs_file_read 3 40858 _002632_hash NULL
83649 +_002633_hash __devres_alloc 2 25598 _002633_hash NULL
83650 +_002634_hash acl_alloc 1 35979 _002634_hash NULL
83651 +_002635_hash acl_alloc_stack_init 1 60630 _002635_hash NULL
83652 +_002636_hash acl_alloc_num 1-2 60778 _002636_hash NULL
83653 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
83654 new file mode 100644
83655 index 0000000..cc96254
83656 --- /dev/null
83657 +++ b/tools/gcc/size_overflow_plugin.c
83658 @@ -0,0 +1,1204 @@
83659 +/*
83660 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
83661 + * Licensed under the GPL v2, or (at your option) v3
83662 + *
83663 + * Homepage:
83664 + * http://www.grsecurity.net/~ephox/overflow_plugin/
83665 + *
83666 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
83667 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
83668 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
83669 + *
83670 + * Usage:
83671 + * $ 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
83672 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
83673 + */
83674 +
83675 +#include "gcc-plugin.h"
83676 +#include "config.h"
83677 +#include "system.h"
83678 +#include "coretypes.h"
83679 +#include "tree.h"
83680 +#include "tree-pass.h"
83681 +#include "intl.h"
83682 +#include "plugin-version.h"
83683 +#include "tm.h"
83684 +#include "toplev.h"
83685 +#include "function.h"
83686 +#include "tree-flow.h"
83687 +#include "plugin.h"
83688 +#include "gimple.h"
83689 +#include "c-common.h"
83690 +#include "diagnostic.h"
83691 +#include "cfgloop.h"
83692 +
83693 +struct size_overflow_hash {
83694 + struct size_overflow_hash *next;
83695 + const char *name;
83696 + unsigned int param;
83697 +};
83698 +
83699 +#include "size_overflow_hash.h"
83700 +
83701 +#define __unused __attribute__((__unused__))
83702 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
83703 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
83704 +#define BEFORE_STMT true
83705 +#define AFTER_STMT false
83706 +#define CREATE_NEW_VAR NULL_TREE
83707 +#define CODES_LIMIT 32
83708 +#define MAX_PARAM 10
83709 +
83710 +#if BUILDING_GCC_VERSION == 4005
83711 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
83712 +#endif
83713 +
83714 +int plugin_is_GPL_compatible;
83715 +void debug_gimple_stmt(gimple gs);
83716 +
83717 +static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var);
83718 +static tree signed_size_overflow_type;
83719 +static tree unsigned_size_overflow_type;
83720 +static tree report_size_overflow_decl;
83721 +static tree const_char_ptr_type_node;
83722 +static unsigned int handle_function(void);
83723 +
83724 +static struct plugin_info size_overflow_plugin_info = {
83725 + .version = "20120618beta",
83726 + .help = "no-size-overflow\tturn off size overflow checking\n",
83727 +};
83728 +
83729 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
83730 +{
83731 + unsigned int arg_count = type_num_arguments(*node);
83732 +
83733 + for (; args; args = TREE_CHAIN(args)) {
83734 + tree position = TREE_VALUE(args);
83735 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
83736 + error("handle_size_overflow_attribute: overflow parameter outside range.");
83737 + *no_add_attrs = true;
83738 + }
83739 + }
83740 + return NULL_TREE;
83741 +}
83742 +
83743 +static struct attribute_spec no_size_overflow_attr = {
83744 + .name = "size_overflow",
83745 + .min_length = 1,
83746 + .max_length = -1,
83747 + .decl_required = false,
83748 + .type_required = true,
83749 + .function_type_required = true,
83750 + .handler = handle_size_overflow_attribute,
83751 +#if BUILDING_GCC_VERSION >= 4007
83752 + .affects_type_identity = false
83753 +#endif
83754 +};
83755 +
83756 +static void register_attributes(void __unused *event_data, void __unused *data)
83757 +{
83758 + register_attribute(&no_size_overflow_attr);
83759 +}
83760 +
83761 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
83762 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
83763 +{
83764 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
83765 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
83766 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
83767 +
83768 + const unsigned int m = 0x57559429;
83769 + const unsigned int n = 0x5052acdb;
83770 + const unsigned int *key4 = (const unsigned int *)key;
83771 + unsigned int h = len;
83772 + unsigned int k = len + seed + n;
83773 + unsigned long long p;
83774 +
83775 + while (len >= 8) {
83776 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
83777 + len -= 8;
83778 + }
83779 + if (len >= 4) {
83780 + cwmixb(key4[0]) key4 += 1;
83781 + len -= 4;
83782 + }
83783 + if (len)
83784 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
83785 + cwmixb(h ^ (k + n));
83786 + return k ^ h;
83787 +
83788 +#undef cwfold
83789 +#undef cwmixa
83790 +#undef cwmixb
83791 +}
83792 +
83793 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
83794 +{
83795 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
83796 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
83797 + return fn ^ codes;
83798 +}
83799 +
83800 +static inline tree get_original_function_decl(tree fndecl)
83801 +{
83802 + if (DECL_ABSTRACT_ORIGIN(fndecl))
83803 + return DECL_ABSTRACT_ORIGIN(fndecl);
83804 + return fndecl;
83805 +}
83806 +
83807 +static inline gimple get_def_stmt(tree node)
83808 +{
83809 + gcc_assert(TREE_CODE(node) == SSA_NAME);
83810 + return SSA_NAME_DEF_STMT(node);
83811 +}
83812 +
83813 +static unsigned char get_tree_code(tree type)
83814 +{
83815 + switch (TREE_CODE(type)) {
83816 + case ARRAY_TYPE:
83817 + return 0;
83818 + case BOOLEAN_TYPE:
83819 + return 1;
83820 + case ENUMERAL_TYPE:
83821 + return 2;
83822 + case FUNCTION_TYPE:
83823 + return 3;
83824 + case INTEGER_TYPE:
83825 + return 4;
83826 + case POINTER_TYPE:
83827 + return 5;
83828 + case RECORD_TYPE:
83829 + return 6;
83830 + case UNION_TYPE:
83831 + return 7;
83832 + case VOID_TYPE:
83833 + return 8;
83834 + case REAL_TYPE:
83835 + return 9;
83836 + case VECTOR_TYPE:
83837 + return 10;
83838 + case REFERENCE_TYPE:
83839 + return 11;
83840 + default:
83841 + debug_tree(type);
83842 + gcc_unreachable();
83843 + }
83844 +}
83845 +
83846 +static size_t add_type_codes(tree type, unsigned char *tree_codes, size_t len)
83847 +{
83848 + gcc_assert(type != NULL_TREE);
83849 +
83850 + while (type && len < CODES_LIMIT) {
83851 + tree_codes[len] = get_tree_code(type);
83852 + len++;
83853 + type = TREE_TYPE(type);
83854 + }
83855 + return len;
83856 +}
83857 +
83858 +static unsigned int get_function_decl(tree fndecl, unsigned char *tree_codes)
83859 +{
83860 + tree arg, result, type = TREE_TYPE(fndecl);
83861 + enum tree_code code = TREE_CODE(type);
83862 + size_t len = 0;
83863 +
83864 + gcc_assert(code == FUNCTION_TYPE);
83865 +
83866 + arg = TYPE_ARG_TYPES(type);
83867 + // skip builtins __builtin_constant_p
83868 + if (!arg && DECL_BUILT_IN(fndecl))
83869 + return 0;
83870 + gcc_assert(arg != NULL_TREE);
83871 +
83872 + if (TREE_CODE_CLASS(code) == tcc_type)
83873 + result = type;
83874 + else
83875 + result = DECL_RESULT(fndecl);
83876 +
83877 + gcc_assert(result != NULL_TREE);
83878 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
83879 +
83880 + while (arg && len < CODES_LIMIT) {
83881 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
83882 + arg = TREE_CHAIN(arg);
83883 + }
83884 +
83885 + gcc_assert(len != 0);
83886 + return len;
83887 +}
83888 +
83889 +static struct size_overflow_hash *get_function_hash(tree fndecl)
83890 +{
83891 + unsigned int hash;
83892 + struct size_overflow_hash *entry;
83893 + unsigned char tree_codes[CODES_LIMIT];
83894 + size_t len;
83895 + const char *func_name = NAME(fndecl);
83896 +
83897 + len = get_function_decl(fndecl, tree_codes);
83898 + if (len == 0)
83899 + return NULL;
83900 +
83901 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
83902 +
83903 + entry = size_overflow_hash[hash];
83904 + while (entry) {
83905 + if (!strcmp(entry->name, func_name))
83906 + return entry;
83907 + entry = entry->next;
83908 + }
83909 +
83910 + return NULL;
83911 +}
83912 +
83913 +static void check_arg_type(tree var)
83914 +{
83915 + tree type = TREE_TYPE(var);
83916 + enum tree_code code = TREE_CODE(type);
83917 +
83918 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
83919 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
83920 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
83921 +}
83922 +
83923 +static int find_arg_number(tree arg, tree func)
83924 +{
83925 + tree var;
83926 + bool match = false;
83927 + unsigned int argnum = 1;
83928 +
83929 + if (TREE_CODE(arg) == SSA_NAME)
83930 + arg = SSA_NAME_VAR(arg);
83931 +
83932 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
83933 + if (strcmp(NAME(arg), NAME(var))) {
83934 + argnum++;
83935 + continue;
83936 + }
83937 + check_arg_type(var);
83938 +
83939 + match = true;
83940 + break;
83941 + }
83942 + if (!match) {
83943 + warning(0, "find_arg_number: cannot find the %s argument in %s", NAME(arg), NAME(func));
83944 + return 0;
83945 + }
83946 + return argnum;
83947 +}
83948 +
83949 +static void print_missing_msg(tree func, unsigned int argnum)
83950 +{
83951 + unsigned int new_hash;
83952 + size_t len;
83953 + unsigned char tree_codes[CODES_LIMIT];
83954 + location_t loc = DECL_SOURCE_LOCATION(func);
83955 + const char *curfunc = NAME(func);
83956 +
83957 + len = get_function_decl(func, tree_codes);
83958 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
83959 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%d+%u+", curfunc, curfunc, argnum, new_hash);
83960 +}
83961 +
83962 +static void check_missing_attribute(tree arg)
83963 +{
83964 + tree type, func = get_original_function_decl(current_function_decl);
83965 + unsigned int argnum;
83966 + struct size_overflow_hash *hash;
83967 +
83968 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
83969 +
83970 + type = TREE_TYPE(arg);
83971 + // skip function pointers
83972 + if (TREE_CODE(type) == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == FUNCTION_TYPE)
83973 + return;
83974 +
83975 + if (lookup_attribute("size_overflow", TYPE_ATTRIBUTES(TREE_TYPE(func))))
83976 + return;
83977 +
83978 + argnum = find_arg_number(arg, func);
83979 + if (argnum == 0)
83980 + return;
83981 +
83982 + hash = get_function_hash(func);
83983 + if (!hash || !(hash->param & (1U << argnum)))
83984 + print_missing_msg(func, argnum);
83985 +}
83986 +
83987 +static tree create_new_var(tree type)
83988 +{
83989 + tree new_var = create_tmp_var(type, "cicus");
83990 +
83991 + add_referenced_var(new_var);
83992 + mark_sym_for_renaming(new_var);
83993 + return new_var;
83994 +}
83995 +
83996 +static bool is_bool(tree node)
83997 +{
83998 + tree type;
83999 +
84000 + if (node == NULL_TREE)
84001 + return false;
84002 +
84003 + type = TREE_TYPE(node);
84004 + if (!INTEGRAL_TYPE_P(type))
84005 + return false;
84006 + if (TREE_CODE(type) == BOOLEAN_TYPE)
84007 + return true;
84008 + if (TYPE_PRECISION(type) == 1)
84009 + return true;
84010 + return false;
84011 +}
84012 +
84013 +static tree cast_a_tree(tree type, tree var)
84014 +{
84015 + gcc_assert(type != NULL_TREE && var != NULL_TREE);
84016 + gcc_assert(fold_convertible_p(type, var));
84017 +
84018 + return fold_convert(type, var);
84019 +}
84020 +
84021 +static tree signed_cast(tree var)
84022 +{
84023 + return cast_a_tree(signed_size_overflow_type, var);
84024 +}
84025 +
84026 +static gimple build_cast_stmt(tree type, tree var, tree new_var, location_t loc)
84027 +{
84028 + gimple assign;
84029 +
84030 + if (new_var == CREATE_NEW_VAR)
84031 + new_var = create_new_var(type);
84032 +
84033 + assign = gimple_build_assign(new_var, cast_a_tree(type, var));
84034 + gimple_set_location(assign, loc);
84035 + gimple_set_lhs(assign, make_ssa_name(new_var, assign));
84036 +
84037 + return assign;
84038 +}
84039 +
84040 +static tree create_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree rhs1, bool before)
84041 +{
84042 + tree oldstmt_rhs1;
84043 + enum tree_code code;
84044 + gimple stmt;
84045 + gimple_stmt_iterator gsi;
84046 +
84047 + if (!*potentionally_overflowed)
84048 + return NULL_TREE;
84049 +
84050 + if (rhs1 == NULL_TREE) {
84051 + debug_gimple_stmt(oldstmt);
84052 + error("create_assign: rhs1 is NULL_TREE");
84053 + gcc_unreachable();
84054 + }
84055 +
84056 + oldstmt_rhs1 = gimple_assign_rhs1(oldstmt);
84057 + code = TREE_CODE(oldstmt_rhs1);
84058 + if (code == PARM_DECL || (code == SSA_NAME && gimple_code(get_def_stmt(oldstmt_rhs1)) == GIMPLE_NOP))
84059 + check_missing_attribute(oldstmt_rhs1);
84060 +
84061 + stmt = build_cast_stmt(signed_size_overflow_type, rhs1, CREATE_NEW_VAR, gimple_location(oldstmt));
84062 + gsi = gsi_for_stmt(oldstmt);
84063 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
84064 + basic_block next_bb, cur_bb;
84065 + edge e;
84066 +
84067 + gcc_assert(before == false);
84068 + gcc_assert(stmt_can_throw_internal(oldstmt));
84069 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
84070 + gcc_assert(!gsi_end_p(gsi));
84071 +
84072 + cur_bb = gimple_bb(oldstmt);
84073 + next_bb = cur_bb->next_bb;
84074 + e = find_edge(cur_bb, next_bb);
84075 + gcc_assert(e != NULL);
84076 + gcc_assert(e->flags & EDGE_FALLTHRU);
84077 +
84078 + gsi = gsi_after_labels(next_bb);
84079 + gcc_assert(!gsi_end_p(gsi));
84080 + before = true;
84081 + }
84082 + if (before)
84083 + gsi_insert_before(&gsi, stmt, GSI_NEW_STMT);
84084 + else
84085 + gsi_insert_after(&gsi, stmt, GSI_NEW_STMT);
84086 + update_stmt(stmt);
84087 + pointer_set_insert(visited, oldstmt);
84088 + return gimple_get_lhs(stmt);
84089 +}
84090 +
84091 +static tree dup_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree rhs1, tree rhs2, tree __unused rhs3)
84092 +{
84093 + tree new_var, lhs = gimple_get_lhs(oldstmt);
84094 + gimple stmt;
84095 + gimple_stmt_iterator gsi;
84096 +
84097 + if (!*potentionally_overflowed)
84098 + return NULL_TREE;
84099 +
84100 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
84101 + rhs1 = gimple_assign_rhs1(oldstmt);
84102 + rhs1 = create_assign(visited, potentionally_overflowed, oldstmt, rhs1, BEFORE_STMT);
84103 + }
84104 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
84105 + rhs2 = gimple_assign_rhs2(oldstmt);
84106 + rhs2 = create_assign(visited, potentionally_overflowed, oldstmt, rhs2, BEFORE_STMT);
84107 + }
84108 +
84109 + stmt = gimple_copy(oldstmt);
84110 + gimple_set_location(stmt, gimple_location(oldstmt));
84111 +
84112 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
84113 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
84114 +
84115 + if (is_bool(lhs))
84116 + new_var = SSA_NAME_VAR(lhs);
84117 + else
84118 + new_var = create_new_var(signed_size_overflow_type);
84119 + new_var = make_ssa_name(new_var, stmt);
84120 + gimple_set_lhs(stmt, new_var);
84121 +
84122 + if (rhs1 != NULL_TREE) {
84123 + if (!gimple_assign_cast_p(oldstmt))
84124 + rhs1 = signed_cast(rhs1);
84125 + gimple_assign_set_rhs1(stmt, rhs1);
84126 + }
84127 +
84128 + if (rhs2 != NULL_TREE)
84129 + gimple_assign_set_rhs2(stmt, rhs2);
84130 +#if BUILDING_GCC_VERSION >= 4007
84131 + if (rhs3 != NULL_TREE)
84132 + gimple_assign_set_rhs3(stmt, rhs3);
84133 +#endif
84134 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
84135 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
84136 +
84137 + gsi = gsi_for_stmt(oldstmt);
84138 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
84139 + update_stmt(stmt);
84140 + pointer_set_insert(visited, oldstmt);
84141 + return gimple_get_lhs(stmt);
84142 +}
84143 +
84144 +static gimple overflow_create_phi_node(gimple oldstmt, tree var)
84145 +{
84146 + basic_block bb;
84147 + gimple phi;
84148 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
84149 +
84150 + bb = gsi_bb(gsi);
84151 +
84152 + phi = create_phi_node(var, bb);
84153 + gsi = gsi_last(phi_nodes(bb));
84154 + gsi_remove(&gsi, false);
84155 +
84156 + gsi = gsi_for_stmt(oldstmt);
84157 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
84158 + gimple_set_bb(phi, bb);
84159 + return phi;
84160 +}
84161 +
84162 +static basic_block create_a_first_bb(void)
84163 +{
84164 + basic_block first_bb;
84165 +
84166 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
84167 + if (dom_info_available_p(CDI_DOMINATORS))
84168 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
84169 + return first_bb;
84170 +}
84171 +
84172 +static gimple cast_old_phi_arg(gimple oldstmt, tree arg, tree new_var, unsigned int i)
84173 +{
84174 + basic_block bb;
84175 + gimple newstmt, def_stmt;
84176 + gimple_stmt_iterator gsi;
84177 +
84178 + newstmt = build_cast_stmt(signed_size_overflow_type, arg, new_var, gimple_location(oldstmt));
84179 + if (TREE_CODE(arg) == SSA_NAME) {
84180 + def_stmt = get_def_stmt(arg);
84181 + if (gimple_code(def_stmt) != GIMPLE_NOP) {
84182 + gsi = gsi_for_stmt(def_stmt);
84183 + gsi_insert_after(&gsi, newstmt, GSI_NEW_STMT);
84184 + return newstmt;
84185 + }
84186 + }
84187 +
84188 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
84189 + if (bb->index == 0)
84190 + bb = create_a_first_bb();
84191 + gsi = gsi_after_labels(bb);
84192 + gsi_insert_before(&gsi, newstmt, GSI_NEW_STMT);
84193 + return newstmt;
84194 +}
84195 +
84196 +static gimple handle_new_phi_arg(tree arg, tree new_var, tree new_rhs)
84197 +{
84198 + gimple newstmt;
84199 + gimple_stmt_iterator gsi;
84200 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
84201 + gimple def_newstmt = get_def_stmt(new_rhs);
84202 +
84203 + gsi_insert = gsi_insert_after;
84204 + gsi = gsi_for_stmt(def_newstmt);
84205 +
84206 + switch (gimple_code(get_def_stmt(arg))) {
84207 + case GIMPLE_PHI:
84208 + newstmt = gimple_build_assign(new_var, new_rhs);
84209 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
84210 + gsi_insert = gsi_insert_before;
84211 + break;
84212 + case GIMPLE_ASM:
84213 + case GIMPLE_CALL:
84214 + newstmt = gimple_build_assign(new_var, new_rhs);
84215 + break;
84216 + case GIMPLE_ASSIGN:
84217 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
84218 + break;
84219 + default:
84220 + /* unknown gimple_code (handle_build_new_phi_arg) */
84221 + gcc_unreachable();
84222 + }
84223 +
84224 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
84225 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
84226 + update_stmt(newstmt);
84227 + return newstmt;
84228 +}
84229 +
84230 +static tree build_new_phi_arg(struct pointer_set_t *visited, bool *potentionally_overflowed, tree arg, tree new_var)
84231 +{
84232 + gimple newstmt;
84233 + tree new_rhs;
84234 +
84235 + new_rhs = expand(visited, potentionally_overflowed, arg);
84236 +
84237 + if (new_rhs == NULL_TREE)
84238 + return NULL_TREE;
84239 +
84240 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
84241 + return gimple_get_lhs(newstmt);
84242 +}
84243 +
84244 +static tree build_new_phi(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt)
84245 +{
84246 + gimple phi;
84247 + tree new_var = create_new_var(signed_size_overflow_type);
84248 + unsigned int i, n = gimple_phi_num_args(oldstmt);
84249 +
84250 + pointer_set_insert(visited, oldstmt);
84251 + phi = overflow_create_phi_node(oldstmt, new_var);
84252 + for (i = 0; i < n; i++) {
84253 + tree arg, lhs;
84254 +
84255 + arg = gimple_phi_arg_def(oldstmt, i);
84256 + if (is_gimple_constant(arg))
84257 + arg = signed_cast(arg);
84258 + lhs = build_new_phi_arg(visited, potentionally_overflowed, arg, new_var);
84259 + if (lhs == NULL_TREE)
84260 + lhs = gimple_get_lhs(cast_old_phi_arg(oldstmt, arg, new_var, i));
84261 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
84262 + }
84263 +
84264 + update_stmt(phi);
84265 + return gimple_phi_result(phi);
84266 +}
84267 +
84268 +static tree handle_unary_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
84269 +{
84270 + gimple def_stmt = get_def_stmt(var);
84271 + tree new_rhs1, rhs1 = gimple_assign_rhs1(def_stmt);
84272 +
84273 + *potentionally_overflowed = true;
84274 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
84275 + if (new_rhs1 == NULL_TREE) {
84276 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
84277 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
84278 + else
84279 + return create_assign(visited, potentionally_overflowed, def_stmt, rhs1, AFTER_STMT);
84280 + }
84281 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, NULL_TREE, NULL_TREE);
84282 +}
84283 +
84284 +static tree handle_unary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
84285 +{
84286 + gimple def_stmt = get_def_stmt(var);
84287 + tree rhs1 = gimple_assign_rhs1(def_stmt);
84288 +
84289 + if (is_gimple_constant(rhs1))
84290 + return dup_assign(visited, potentionally_overflowed, def_stmt, signed_cast(rhs1), NULL_TREE, NULL_TREE);
84291 +
84292 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
84293 + switch (TREE_CODE(rhs1)) {
84294 + case SSA_NAME:
84295 + return handle_unary_rhs(visited, potentionally_overflowed, var);
84296 +
84297 + case ARRAY_REF:
84298 + case BIT_FIELD_REF:
84299 + case ADDR_EXPR:
84300 + case COMPONENT_REF:
84301 + case INDIRECT_REF:
84302 +#if BUILDING_GCC_VERSION >= 4006
84303 + case MEM_REF:
84304 +#endif
84305 + case PARM_DECL:
84306 + case TARGET_MEM_REF:
84307 + case VAR_DECL:
84308 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
84309 +
84310 + default:
84311 + debug_gimple_stmt(def_stmt);
84312 + debug_tree(rhs1);
84313 + gcc_unreachable();
84314 + }
84315 +}
84316 +
84317 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
84318 +{
84319 + gimple cond_stmt;
84320 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
84321 +
84322 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
84323 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
84324 + update_stmt(cond_stmt);
84325 +}
84326 +
84327 +static tree create_string_param(tree string)
84328 +{
84329 + tree i_type, a_type;
84330 + int length = TREE_STRING_LENGTH(string);
84331 +
84332 + gcc_assert(length > 0);
84333 +
84334 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
84335 + a_type = build_array_type(char_type_node, i_type);
84336 +
84337 + TREE_TYPE(string) = a_type;
84338 + TREE_CONSTANT(string) = 1;
84339 + TREE_READONLY(string) = 1;
84340 +
84341 + return build1(ADDR_EXPR, ptr_type_node, string);
84342 +}
84343 +
84344 +static void insert_cond_result(basic_block bb_true, gimple stmt, tree arg)
84345 +{
84346 + gimple func_stmt, def_stmt;
84347 + tree current_func, loc_file, loc_line;
84348 + expanded_location xloc;
84349 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
84350 +
84351 + def_stmt = get_def_stmt(arg);
84352 + xloc = expand_location(gimple_location(def_stmt));
84353 +
84354 + if (!gimple_has_location(def_stmt)) {
84355 + xloc = expand_location(gimple_location(stmt));
84356 + if (!gimple_has_location(stmt))
84357 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
84358 + }
84359 +
84360 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
84361 +
84362 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
84363 + loc_file = create_string_param(loc_file);
84364 +
84365 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
84366 + current_func = create_string_param(current_func);
84367 +
84368 + // void report_size_overflow(const char *file, unsigned int line, const char *func)
84369 + func_stmt = gimple_build_call(report_size_overflow_decl, 3, loc_file, loc_line, current_func);
84370 +
84371 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
84372 +}
84373 +
84374 +static void __unused print_the_code_insertions(gimple stmt)
84375 +{
84376 + location_t loc = gimple_location(stmt);
84377 +
84378 + inform(loc, "Integer size_overflow check applied here.");
84379 +}
84380 +
84381 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value)
84382 +{
84383 + basic_block cond_bb, join_bb, bb_true;
84384 + edge e;
84385 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
84386 +
84387 + cond_bb = gimple_bb(stmt);
84388 + gsi_prev(&gsi);
84389 + if (gsi_end_p(gsi))
84390 + e = split_block_after_labels(cond_bb);
84391 + else
84392 + e = split_block(cond_bb, gsi_stmt(gsi));
84393 + cond_bb = e->src;
84394 + join_bb = e->dest;
84395 + e->flags = EDGE_FALSE_VALUE;
84396 + e->probability = REG_BR_PROB_BASE;
84397 +
84398 + bb_true = create_empty_bb(cond_bb);
84399 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
84400 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
84401 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
84402 +
84403 + if (dom_info_available_p(CDI_DOMINATORS)) {
84404 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
84405 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
84406 + }
84407 +
84408 + if (current_loops != NULL) {
84409 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
84410 + add_bb_to_loop(bb_true, cond_bb->loop_father);
84411 + }
84412 +
84413 + insert_cond(cond_bb, arg, cond_code, type_value);
84414 + insert_cond_result(bb_true, stmt, arg);
84415 +
84416 +// print_the_code_insertions(stmt);
84417 +}
84418 +
84419 +static gimple cast_to_unsigned_size_overflow_type(gimple stmt, tree cast_rhs)
84420 +{
84421 + gimple ucast_stmt;
84422 + gimple_stmt_iterator gsi;
84423 + location_t loc = gimple_location(stmt);
84424 +
84425 + ucast_stmt = build_cast_stmt(unsigned_size_overflow_type, cast_rhs, CREATE_NEW_VAR, loc);
84426 + gsi = gsi_for_stmt(stmt);
84427 + gsi_insert_before(&gsi, ucast_stmt, GSI_SAME_STMT);
84428 + return ucast_stmt;
84429 +}
84430 +
84431 +static void check_size_overflow(gimple stmt, tree cast_rhs, tree rhs, bool *potentionally_overflowed)
84432 +{
84433 + tree type_max, type_min, rhs_type = TREE_TYPE(rhs);
84434 + gimple ucast_stmt;
84435 +
84436 + if (!*potentionally_overflowed)
84437 + return;
84438 +
84439 + if (TYPE_UNSIGNED(rhs_type)) {
84440 + ucast_stmt = cast_to_unsigned_size_overflow_type(stmt, cast_rhs);
84441 + type_max = cast_a_tree(unsigned_size_overflow_type, TYPE_MAX_VALUE(rhs_type));
84442 + insert_check_size_overflow(stmt, GT_EXPR, gimple_get_lhs(ucast_stmt), type_max);
84443 + } else {
84444 + type_max = signed_cast(TYPE_MAX_VALUE(rhs_type));
84445 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max);
84446 +
84447 + type_min = signed_cast(TYPE_MIN_VALUE(rhs_type));
84448 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min);
84449 + }
84450 +}
84451 +
84452 +static tree change_assign_rhs(gimple stmt, tree orig_rhs, tree new_rhs)
84453 +{
84454 + gimple assign;
84455 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
84456 + tree origtype = TREE_TYPE(orig_rhs);
84457 +
84458 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
84459 +
84460 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, gimple_location(stmt));
84461 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
84462 + update_stmt(assign);
84463 + return gimple_get_lhs(assign);
84464 +}
84465 +
84466 +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))
84467 +{
84468 + tree new_rhs;
84469 +
84470 + if (gimple_assign_rhs_code(def_stmt) == MIN_EXPR)
84471 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, NULL_TREE);
84472 +
84473 + if (var_rhs == NULL_TREE)
84474 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
84475 +
84476 + new_rhs = change_assign_rhs(def_stmt, orig_rhs, var_rhs);
84477 + gimple_assign_set_rhs(def_stmt, new_rhs);
84478 + update_stmt(def_stmt);
84479 +
84480 + check_size_overflow(def_stmt, var_rhs, orig_rhs, potentionally_overflowed);
84481 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
84482 +}
84483 +
84484 +static tree handle_binary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
84485 +{
84486 + tree rhs1, rhs2;
84487 + gimple def_stmt = get_def_stmt(var);
84488 + tree new_rhs1 = NULL_TREE;
84489 + tree new_rhs2 = NULL_TREE;
84490 +
84491 + rhs1 = gimple_assign_rhs1(def_stmt);
84492 + rhs2 = gimple_assign_rhs2(def_stmt);
84493 +
84494 + /* no DImode/TImode division in the 32/64 bit kernel */
84495 + switch (gimple_assign_rhs_code(def_stmt)) {
84496 + case RDIV_EXPR:
84497 + case TRUNC_DIV_EXPR:
84498 + case CEIL_DIV_EXPR:
84499 + case FLOOR_DIV_EXPR:
84500 + case ROUND_DIV_EXPR:
84501 + case TRUNC_MOD_EXPR:
84502 + case CEIL_MOD_EXPR:
84503 + case FLOOR_MOD_EXPR:
84504 + case ROUND_MOD_EXPR:
84505 + case EXACT_DIV_EXPR:
84506 + case POINTER_PLUS_EXPR:
84507 + case BIT_AND_EXPR:
84508 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
84509 + default:
84510 + break;
84511 + }
84512 +
84513 + *potentionally_overflowed = true;
84514 +
84515 + if (TREE_CODE(rhs1) == SSA_NAME)
84516 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
84517 + if (TREE_CODE(rhs2) == SSA_NAME)
84518 + new_rhs2 = expand(visited, potentionally_overflowed, rhs2);
84519 +
84520 + if (is_gimple_constant(rhs2))
84521 + return handle_const_assign(visited, potentionally_overflowed, def_stmt, var, rhs1, new_rhs1, new_rhs1, signed_cast(rhs2), &gimple_assign_set_rhs1);
84522 +
84523 + if (is_gimple_constant(rhs1))
84524 + return handle_const_assign(visited, potentionally_overflowed, def_stmt, var, rhs2, new_rhs2, signed_cast(rhs1), new_rhs2, &gimple_assign_set_rhs2);
84525 +
84526 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, NULL_TREE);
84527 +}
84528 +
84529 +#if BUILDING_GCC_VERSION >= 4007
84530 +static tree get_new_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, tree rhs)
84531 +{
84532 + if (is_gimple_constant(rhs))
84533 + return signed_cast(rhs);
84534 + if (TREE_CODE(rhs) != SSA_NAME)
84535 + return NULL_TREE;
84536 + return expand(visited, potentionally_overflowed, rhs);
84537 +}
84538 +
84539 +static tree handle_ternary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
84540 +{
84541 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3;
84542 + gimple def_stmt = get_def_stmt(var);
84543 +
84544 + *potentionally_overflowed = true;
84545 +
84546 + rhs1 = gimple_assign_rhs1(def_stmt);
84547 + rhs2 = gimple_assign_rhs2(def_stmt);
84548 + rhs3 = gimple_assign_rhs3(def_stmt);
84549 + new_rhs1 = get_new_rhs(visited, potentionally_overflowed, rhs1);
84550 + new_rhs2 = get_new_rhs(visited, potentionally_overflowed, rhs2);
84551 + new_rhs3 = get_new_rhs(visited, potentionally_overflowed, rhs3);
84552 +
84553 + if (new_rhs1 == NULL_TREE && new_rhs2 != NULL_TREE && new_rhs3 != NULL_TREE)
84554 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, new_rhs3);
84555 + error("handle_ternary_ops: unknown rhs");
84556 + gcc_unreachable();
84557 +}
84558 +#endif
84559 +
84560 +static void set_size_overflow_type(tree node)
84561 +{
84562 + switch (TYPE_MODE(TREE_TYPE(node))) {
84563 + case SImode:
84564 + signed_size_overflow_type = intDI_type_node;
84565 + unsigned_size_overflow_type = unsigned_intDI_type_node;
84566 + break;
84567 + case DImode:
84568 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode)) {
84569 + signed_size_overflow_type = intDI_type_node;
84570 + unsigned_size_overflow_type = unsigned_intDI_type_node;
84571 + } else {
84572 + signed_size_overflow_type = intTI_type_node;
84573 + unsigned_size_overflow_type = unsigned_intTI_type_node;
84574 + }
84575 + break;
84576 + default:
84577 + error("set_size_overflow_type: unsupported gcc configuration.");
84578 + gcc_unreachable();
84579 + }
84580 +}
84581 +
84582 +static tree expand_visited(gimple def_stmt)
84583 +{
84584 + gimple tmp;
84585 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
84586 +
84587 + gsi_next(&gsi);
84588 + tmp = gsi_stmt(gsi);
84589 + switch (gimple_code(tmp)) {
84590 + case GIMPLE_ASSIGN:
84591 + return gimple_get_lhs(tmp);
84592 + case GIMPLE_PHI:
84593 + return gimple_phi_result(tmp);
84594 + case GIMPLE_CALL:
84595 + return gimple_call_lhs(tmp);
84596 + default:
84597 + return NULL_TREE;
84598 + }
84599 +}
84600 +
84601 +static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
84602 +{
84603 + gimple def_stmt;
84604 + enum tree_code code = TREE_CODE(TREE_TYPE(var));
84605 +
84606 + if (is_gimple_constant(var))
84607 + return NULL_TREE;
84608 +
84609 + if (TREE_CODE(var) == ADDR_EXPR)
84610 + return NULL_TREE;
84611 +
84612 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
84613 + if (code != INTEGER_TYPE)
84614 + return NULL_TREE;
84615 +
84616 + if (SSA_NAME_IS_DEFAULT_DEF(var)) {
84617 + check_missing_attribute(var);
84618 + return NULL_TREE;
84619 + }
84620 +
84621 + def_stmt = get_def_stmt(var);
84622 +
84623 + if (!def_stmt)
84624 + return NULL_TREE;
84625 +
84626 + if (pointer_set_contains(visited, def_stmt))
84627 + return expand_visited(def_stmt);
84628 +
84629 + switch (gimple_code(def_stmt)) {
84630 + case GIMPLE_NOP:
84631 + check_missing_attribute(var);
84632 + return NULL_TREE;
84633 + case GIMPLE_PHI:
84634 + return build_new_phi(visited, potentionally_overflowed, def_stmt);
84635 + case GIMPLE_CALL:
84636 + case GIMPLE_ASM:
84637 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
84638 + case GIMPLE_ASSIGN:
84639 + switch (gimple_num_ops(def_stmt)) {
84640 + case 2:
84641 + return handle_unary_ops(visited, potentionally_overflowed, var);
84642 + case 3:
84643 + return handle_binary_ops(visited, potentionally_overflowed, var);
84644 +#if BUILDING_GCC_VERSION >= 4007
84645 + case 4:
84646 + return handle_ternary_ops(visited, potentionally_overflowed, var);
84647 +#endif
84648 + }
84649 + default:
84650 + debug_gimple_stmt(def_stmt);
84651 + error("expand: unknown gimple code");
84652 + gcc_unreachable();
84653 + }
84654 +}
84655 +
84656 +static void change_function_arg(gimple stmt, tree origarg, unsigned int argnum, tree newarg)
84657 +{
84658 + gimple assign;
84659 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
84660 + tree origtype = TREE_TYPE(origarg);
84661 +
84662 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
84663 +
84664 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, gimple_location(stmt));
84665 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
84666 + update_stmt(assign);
84667 +
84668 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
84669 + update_stmt(stmt);
84670 +}
84671 +
84672 +static tree get_function_arg(unsigned int argnum, gimple stmt, tree fndecl)
84673 +{
84674 + const char *origid;
84675 + tree arg, origarg;
84676 +
84677 + if (!DECL_ABSTRACT_ORIGIN(fndecl)) {
84678 + gcc_assert(gimple_call_num_args(stmt) > argnum);
84679 + return gimple_call_arg(stmt, argnum);
84680 + }
84681 +
84682 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
84683 + while (origarg && argnum) {
84684 + argnum--;
84685 + origarg = TREE_CHAIN(origarg);
84686 + }
84687 +
84688 + gcc_assert(argnum == 0);
84689 +
84690 + gcc_assert(origarg != NULL_TREE);
84691 + origid = NAME(origarg);
84692 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
84693 + if (!strcmp(origid, NAME(arg)))
84694 + return arg;
84695 + }
84696 + return NULL_TREE;
84697 +}
84698 +
84699 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
84700 +{
84701 + struct pointer_set_t *visited;
84702 + tree arg, newarg;
84703 + bool potentionally_overflowed;
84704 +
84705 + arg = get_function_arg(argnum, stmt, fndecl);
84706 + if (arg == NULL_TREE)
84707 + return;
84708 +
84709 + if (is_gimple_constant(arg))
84710 + return;
84711 + if (TREE_CODE(arg) != SSA_NAME)
84712 + return;
84713 +
84714 + check_arg_type(arg);
84715 +
84716 + set_size_overflow_type(arg);
84717 +
84718 + visited = pointer_set_create();
84719 + potentionally_overflowed = false;
84720 + newarg = expand(visited, &potentionally_overflowed, arg);
84721 + pointer_set_destroy(visited);
84722 +
84723 + if (newarg == NULL_TREE || !potentionally_overflowed)
84724 + return;
84725 +
84726 + change_function_arg(stmt, arg, argnum, newarg);
84727 +
84728 + check_size_overflow(stmt, newarg, arg, &potentionally_overflowed);
84729 +}
84730 +
84731 +static void handle_function_by_attribute(gimple stmt, tree attr, tree fndecl)
84732 +{
84733 + tree p = TREE_VALUE(attr);
84734 + do {
84735 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
84736 + p = TREE_CHAIN(p);
84737 + } while (p);
84738 +}
84739 +
84740 +static void handle_function_by_hash(gimple stmt, tree fndecl)
84741 +{
84742 + tree orig_fndecl;
84743 + unsigned int num;
84744 + struct size_overflow_hash *hash;
84745 +
84746 + orig_fndecl = get_original_function_decl(fndecl);
84747 + hash = get_function_hash(orig_fndecl);
84748 + if (!hash)
84749 + return;
84750 +
84751 + for (num = 1; num <= MAX_PARAM; num++)
84752 + if (hash->param & (1U << num))
84753 + handle_function_arg(stmt, fndecl, num - 1);
84754 +}
84755 +
84756 +static unsigned int handle_function(void)
84757 +{
84758 + basic_block bb = ENTRY_BLOCK_PTR->next_bb;
84759 + int saved_last_basic_block = last_basic_block;
84760 +
84761 + do {
84762 + gimple_stmt_iterator gsi;
84763 + basic_block next = bb->next_bb;
84764 +
84765 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
84766 + tree fndecl, attr;
84767 + gimple stmt = gsi_stmt(gsi);
84768 +
84769 + if (!(is_gimple_call(stmt)))
84770 + continue;
84771 + fndecl = gimple_call_fndecl(stmt);
84772 + if (fndecl == NULL_TREE)
84773 + continue;
84774 + if (gimple_call_num_args(stmt) == 0)
84775 + continue;
84776 + attr = lookup_attribute("size_overflow", TYPE_ATTRIBUTES(TREE_TYPE(fndecl)));
84777 + if (!attr || !TREE_VALUE(attr))
84778 + handle_function_by_hash(stmt, fndecl);
84779 + else
84780 + handle_function_by_attribute(stmt, attr, fndecl);
84781 + gsi = gsi_for_stmt(stmt);
84782 + }
84783 + bb = next;
84784 + } while (bb && bb->index <= saved_last_basic_block);
84785 + return 0;
84786 +}
84787 +
84788 +static struct gimple_opt_pass size_overflow_pass = {
84789 + .pass = {
84790 + .type = GIMPLE_PASS,
84791 + .name = "size_overflow",
84792 + .gate = NULL,
84793 + .execute = handle_function,
84794 + .sub = NULL,
84795 + .next = NULL,
84796 + .static_pass_number = 0,
84797 + .tv_id = TV_NONE,
84798 + .properties_required = PROP_cfg | PROP_referenced_vars,
84799 + .properties_provided = 0,
84800 + .properties_destroyed = 0,
84801 + .todo_flags_start = 0,
84802 + .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
84803 + }
84804 +};
84805 +
84806 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
84807 +{
84808 + tree fntype;
84809 +
84810 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
84811 +
84812 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func)
84813 + fntype = build_function_type_list(void_type_node,
84814 + const_char_ptr_type_node,
84815 + unsigned_type_node,
84816 + const_char_ptr_type_node,
84817 + NULL_TREE);
84818 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
84819 +
84820 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
84821 + TREE_PUBLIC(report_size_overflow_decl) = 1;
84822 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
84823 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
84824 +}
84825 +
84826 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84827 +{
84828 + int i;
84829 + const char * const plugin_name = plugin_info->base_name;
84830 + const int argc = plugin_info->argc;
84831 + const struct plugin_argument * const argv = plugin_info->argv;
84832 + bool enable = true;
84833 +
84834 + struct register_pass_info size_overflow_pass_info = {
84835 + .pass = &size_overflow_pass.pass,
84836 + .reference_pass_name = "ssa",
84837 + .ref_pass_instance_number = 1,
84838 + .pos_op = PASS_POS_INSERT_AFTER
84839 + };
84840 +
84841 + if (!plugin_default_version_check(version, &gcc_version)) {
84842 + error(G_("incompatible gcc/plugin versions"));
84843 + return 1;
84844 + }
84845 +
84846 + for (i = 0; i < argc; ++i) {
84847 + if (!strcmp(argv[i].key, "no-size-overflow")) {
84848 + enable = false;
84849 + continue;
84850 + }
84851 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
84852 + }
84853 +
84854 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
84855 + if (enable) {
84856 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
84857 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
84858 + }
84859 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
84860 +
84861 + return 0;
84862 +}
84863 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
84864 new file mode 100644
84865 index 0000000..b87ec9d
84866 --- /dev/null
84867 +++ b/tools/gcc/stackleak_plugin.c
84868 @@ -0,0 +1,313 @@
84869 +/*
84870 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
84871 + * Licensed under the GPL v2
84872 + *
84873 + * Note: the choice of the license means that the compilation process is
84874 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
84875 + * but for the kernel it doesn't matter since it doesn't link against
84876 + * any of the gcc libraries
84877 + *
84878 + * gcc plugin to help implement various PaX features
84879 + *
84880 + * - track lowest stack pointer
84881 + *
84882 + * TODO:
84883 + * - initialize all local variables
84884 + *
84885 + * BUGS:
84886 + * - none known
84887 + */
84888 +#include "gcc-plugin.h"
84889 +#include "config.h"
84890 +#include "system.h"
84891 +#include "coretypes.h"
84892 +#include "tree.h"
84893 +#include "tree-pass.h"
84894 +#include "flags.h"
84895 +#include "intl.h"
84896 +#include "toplev.h"
84897 +#include "plugin.h"
84898 +//#include "expr.h" where are you...
84899 +#include "diagnostic.h"
84900 +#include "plugin-version.h"
84901 +#include "tm.h"
84902 +#include "function.h"
84903 +#include "basic-block.h"
84904 +#include "gimple.h"
84905 +#include "rtl.h"
84906 +#include "emit-rtl.h"
84907 +
84908 +extern void print_gimple_stmt(FILE *, gimple, int, int);
84909 +
84910 +int plugin_is_GPL_compatible;
84911 +
84912 +static int track_frame_size = -1;
84913 +static const char track_function[] = "pax_track_stack";
84914 +static const char check_function[] = "pax_check_alloca";
84915 +static bool init_locals;
84916 +
84917 +static struct plugin_info stackleak_plugin_info = {
84918 + .version = "201203140940",
84919 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
84920 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
84921 +};
84922 +
84923 +static bool gate_stackleak_track_stack(void);
84924 +static unsigned int execute_stackleak_tree_instrument(void);
84925 +static unsigned int execute_stackleak_final(void);
84926 +
84927 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
84928 + .pass = {
84929 + .type = GIMPLE_PASS,
84930 + .name = "stackleak_tree_instrument",
84931 + .gate = gate_stackleak_track_stack,
84932 + .execute = execute_stackleak_tree_instrument,
84933 + .sub = NULL,
84934 + .next = NULL,
84935 + .static_pass_number = 0,
84936 + .tv_id = TV_NONE,
84937 + .properties_required = PROP_gimple_leh | PROP_cfg,
84938 + .properties_provided = 0,
84939 + .properties_destroyed = 0,
84940 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
84941 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
84942 + }
84943 +};
84944 +
84945 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
84946 + .pass = {
84947 + .type = RTL_PASS,
84948 + .name = "stackleak_final",
84949 + .gate = gate_stackleak_track_stack,
84950 + .execute = execute_stackleak_final,
84951 + .sub = NULL,
84952 + .next = NULL,
84953 + .static_pass_number = 0,
84954 + .tv_id = TV_NONE,
84955 + .properties_required = 0,
84956 + .properties_provided = 0,
84957 + .properties_destroyed = 0,
84958 + .todo_flags_start = 0,
84959 + .todo_flags_finish = TODO_dump_func
84960 + }
84961 +};
84962 +
84963 +static bool gate_stackleak_track_stack(void)
84964 +{
84965 + return track_frame_size >= 0;
84966 +}
84967 +
84968 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
84969 +{
84970 + gimple check_alloca;
84971 + tree fntype, fndecl, alloca_size;
84972 +
84973 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
84974 + fndecl = build_fn_decl(check_function, fntype);
84975 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
84976 +
84977 + // insert call to void pax_check_alloca(unsigned long size)
84978 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
84979 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
84980 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
84981 +}
84982 +
84983 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
84984 +{
84985 + gimple track_stack;
84986 + tree fntype, fndecl;
84987 +
84988 + fntype = build_function_type_list(void_type_node, NULL_TREE);
84989 + fndecl = build_fn_decl(track_function, fntype);
84990 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
84991 +
84992 + // insert call to void pax_track_stack(void)
84993 + track_stack = gimple_build_call(fndecl, 0);
84994 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
84995 +}
84996 +
84997 +#if BUILDING_GCC_VERSION == 4005
84998 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
84999 +{
85000 + tree fndecl;
85001 +
85002 + if (!is_gimple_call(stmt))
85003 + return false;
85004 + fndecl = gimple_call_fndecl(stmt);
85005 + if (!fndecl)
85006 + return false;
85007 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
85008 + return false;
85009 +// print_node(stderr, "pax", fndecl, 4);
85010 + return DECL_FUNCTION_CODE(fndecl) == code;
85011 +}
85012 +#endif
85013 +
85014 +static bool is_alloca(gimple stmt)
85015 +{
85016 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
85017 + return true;
85018 +
85019 +#if BUILDING_GCC_VERSION >= 4007
85020 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
85021 + return true;
85022 +#endif
85023 +
85024 + return false;
85025 +}
85026 +
85027 +static unsigned int execute_stackleak_tree_instrument(void)
85028 +{
85029 + basic_block bb, entry_bb;
85030 + bool prologue_instrumented = false, is_leaf = true;
85031 +
85032 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
85033 +
85034 + // 1. loop through BBs and GIMPLE statements
85035 + FOR_EACH_BB(bb) {
85036 + gimple_stmt_iterator gsi;
85037 +
85038 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
85039 + gimple stmt;
85040 +
85041 + stmt = gsi_stmt(gsi);
85042 +
85043 + if (is_gimple_call(stmt))
85044 + is_leaf = false;
85045 +
85046 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
85047 + if (!is_alloca(stmt))
85048 + continue;
85049 +
85050 + // 2. insert stack overflow check before each __builtin_alloca call
85051 + stackleak_check_alloca(&gsi);
85052 +
85053 + // 3. insert track call after each __builtin_alloca call
85054 + stackleak_add_instrumentation(&gsi);
85055 + if (bb == entry_bb)
85056 + prologue_instrumented = true;
85057 + }
85058 + }
85059 +
85060 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
85061 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
85062 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
85063 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
85064 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
85065 + return 0;
85066 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
85067 + return 0;
85068 +
85069 + // 4. insert track call at the beginning
85070 + if (!prologue_instrumented) {
85071 + gimple_stmt_iterator gsi;
85072 +
85073 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
85074 + if (dom_info_available_p(CDI_DOMINATORS))
85075 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
85076 + gsi = gsi_start_bb(bb);
85077 + stackleak_add_instrumentation(&gsi);
85078 + }
85079 +
85080 + return 0;
85081 +}
85082 +
85083 +static unsigned int execute_stackleak_final(void)
85084 +{
85085 + rtx insn;
85086 +
85087 + if (cfun->calls_alloca)
85088 + return 0;
85089 +
85090 + // keep calls only if function frame is big enough
85091 + if (get_frame_size() >= track_frame_size)
85092 + return 0;
85093 +
85094 + // 1. find pax_track_stack calls
85095 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
85096 + // 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))
85097 + rtx body;
85098 +
85099 + if (!CALL_P(insn))
85100 + continue;
85101 + body = PATTERN(insn);
85102 + if (GET_CODE(body) != CALL)
85103 + continue;
85104 + body = XEXP(body, 0);
85105 + if (GET_CODE(body) != MEM)
85106 + continue;
85107 + body = XEXP(body, 0);
85108 + if (GET_CODE(body) != SYMBOL_REF)
85109 + continue;
85110 + if (strcmp(XSTR(body, 0), track_function))
85111 + continue;
85112 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
85113 + // 2. delete call
85114 + insn = delete_insn_and_edges(insn);
85115 +#if BUILDING_GCC_VERSION >= 4007
85116 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
85117 + insn = delete_insn_and_edges(insn);
85118 +#endif
85119 + }
85120 +
85121 +// print_simple_rtl(stderr, get_insns());
85122 +// print_rtl(stderr, get_insns());
85123 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
85124 +
85125 + return 0;
85126 +}
85127 +
85128 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85129 +{
85130 + const char * const plugin_name = plugin_info->base_name;
85131 + const int argc = plugin_info->argc;
85132 + const struct plugin_argument * const argv = plugin_info->argv;
85133 + int i;
85134 + struct register_pass_info stackleak_tree_instrument_pass_info = {
85135 + .pass = &stackleak_tree_instrument_pass.pass,
85136 +// .reference_pass_name = "tree_profile",
85137 + .reference_pass_name = "optimized",
85138 + .ref_pass_instance_number = 0,
85139 + .pos_op = PASS_POS_INSERT_BEFORE
85140 + };
85141 + struct register_pass_info stackleak_final_pass_info = {
85142 + .pass = &stackleak_final_rtl_opt_pass.pass,
85143 + .reference_pass_name = "final",
85144 + .ref_pass_instance_number = 0,
85145 + .pos_op = PASS_POS_INSERT_BEFORE
85146 + };
85147 +
85148 + if (!plugin_default_version_check(version, &gcc_version)) {
85149 + error(G_("incompatible gcc/plugin versions"));
85150 + return 1;
85151 + }
85152 +
85153 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
85154 +
85155 + for (i = 0; i < argc; ++i) {
85156 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
85157 + if (!argv[i].value) {
85158 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85159 + continue;
85160 + }
85161 + track_frame_size = atoi(argv[i].value);
85162 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
85163 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
85164 + continue;
85165 + }
85166 + if (!strcmp(argv[i].key, "initialize-locals")) {
85167 + if (argv[i].value) {
85168 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
85169 + continue;
85170 + }
85171 + init_locals = true;
85172 + continue;
85173 + }
85174 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85175 + }
85176 +
85177 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
85178 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
85179 +
85180 + return 0;
85181 +}
85182 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
85183 index 6789d78..4afd019 100644
85184 --- a/tools/perf/util/include/asm/alternative-asm.h
85185 +++ b/tools/perf/util/include/asm/alternative-asm.h
85186 @@ -5,4 +5,7 @@
85187
85188 #define altinstruction_entry #
85189
85190 + .macro pax_force_retaddr rip=0, reload=0
85191 + .endm
85192 +
85193 #endif
85194 diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
85195 index af0f22f..9a7d479 100644
85196 --- a/usr/gen_init_cpio.c
85197 +++ b/usr/gen_init_cpio.c
85198 @@ -303,7 +303,7 @@ static int cpio_mkfile(const char *name, const char *location,
85199 int retval;
85200 int rc = -1;
85201 int namesize;
85202 - int i;
85203 + unsigned int i;
85204
85205 mode |= S_IFREG;
85206
85207 @@ -392,9 +392,10 @@ static char *cpio_replace_env(char *new_location)
85208 *env_var = *expanded = '\0';
85209 strncat(env_var, start + 2, end - start - 2);
85210 strncat(expanded, new_location, start - new_location);
85211 - strncat(expanded, getenv(env_var), PATH_MAX);
85212 - strncat(expanded, end + 1, PATH_MAX);
85213 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
85214 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
85215 strncpy(new_location, expanded, PATH_MAX);
85216 + new_location[PATH_MAX] = 0;
85217 } else
85218 break;
85219 }
85220 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
85221 index 9739b53..6d457e3 100644
85222 --- a/virt/kvm/kvm_main.c
85223 +++ b/virt/kvm/kvm_main.c
85224 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
85225
85226 static cpumask_var_t cpus_hardware_enabled;
85227 static int kvm_usage_count = 0;
85228 -static atomic_t hardware_enable_failed;
85229 +static atomic_unchecked_t hardware_enable_failed;
85230
85231 struct kmem_cache *kvm_vcpu_cache;
85232 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
85233 @@ -2247,7 +2247,7 @@ static void hardware_enable_nolock(void *junk)
85234
85235 if (r) {
85236 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
85237 - atomic_inc(&hardware_enable_failed);
85238 + atomic_inc_unchecked(&hardware_enable_failed);
85239 printk(KERN_INFO "kvm: enabling virtualization on "
85240 "CPU%d failed\n", cpu);
85241 }
85242 @@ -2301,10 +2301,10 @@ static int hardware_enable_all(void)
85243
85244 kvm_usage_count++;
85245 if (kvm_usage_count == 1) {
85246 - atomic_set(&hardware_enable_failed, 0);
85247 + atomic_set_unchecked(&hardware_enable_failed, 0);
85248 on_each_cpu(hardware_enable_nolock, NULL, 1);
85249
85250 - if (atomic_read(&hardware_enable_failed)) {
85251 + if (atomic_read_unchecked(&hardware_enable_failed)) {
85252 hardware_disable_all_nolock();
85253 r = -EBUSY;
85254 }
85255 @@ -2667,7 +2667,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
85256 kvm_arch_vcpu_put(vcpu);
85257 }
85258
85259 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
85260 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
85261 struct module *module)
85262 {
85263 int r;
85264 @@ -2730,7 +2730,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
85265 if (!vcpu_align)
85266 vcpu_align = __alignof__(struct kvm_vcpu);
85267 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
85268 - 0, NULL);
85269 + SLAB_USERCOPY, NULL);
85270 if (!kvm_vcpu_cache) {
85271 r = -ENOMEM;
85272 goto out_free_3;
85273 @@ -2740,9 +2740,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
85274 if (r)
85275 goto out_free;
85276
85277 - kvm_chardev_ops.owner = module;
85278 - kvm_vm_fops.owner = module;
85279 - kvm_vcpu_fops.owner = module;
85280 + pax_open_kernel();
85281 + *(void **)&kvm_chardev_ops.owner = module;
85282 + *(void **)&kvm_vm_fops.owner = module;
85283 + *(void **)&kvm_vcpu_fops.owner = module;
85284 + pax_close_kernel();
85285
85286 r = misc_register(&kvm_dev);
85287 if (r) {