The NetBSD Project

CVS log for src/sys/kern/subr_msan.c

[BACK] Up to [cvs.NetBSD.org] / src / sys / kern

Request diff between arbitrary revisions


Default branch: MAIN
Current tag: MAIN


Revision 1.19 / (download) - annotate - [select for diffs], Tue Apr 11 10:19:56 2023 UTC (12 months, 1 week ago) by riastradh
Branch: MAIN
CVS Tags: thorpej-ifq-base, thorpej-ifq, thorpej-altq-separation-base, thorpej-altq-separation, HEAD
Changes since 1.18: +21 -5 lines
Diff to previous 1.18 (colored)

kmsan: Format exact instruction addresses relative to symbols.

Revision 1.18 / (download) - annotate - [select for diffs], Wed Oct 26 23:38:09 2022 UTC (17 months, 3 weeks ago) by riastradh
Branch: MAIN
CVS Tags: netbsd-10-base, netbsd-10-0-RELEASE, netbsd-10-0-RC6, netbsd-10-0-RC5, netbsd-10-0-RC4, netbsd-10-0-RC3, netbsd-10-0-RC2, netbsd-10-0-RC1, netbsd-10
Changes since 1.17: +4 -4 lines
Diff to previous 1.17 (colored)

ddb/db_active.h: New home for extern db_active.

This can be included unconditionally, and db_active can then be
queried unconditionally; if DDB is not in the kernel, then db_active
is a constant zero.  Reduces need for #include opt_ddb.h, #ifdef DDB.

Revision 1.17 / (download) - annotate - [select for diffs], Sat Sep 11 10:09:55 2021 UTC (2 years, 7 months ago) by riastradh
Branch: MAIN
CVS Tags: bouyer-sunxi-drm-base, bouyer-sunxi-drm
Changes since 1.16: +8 -2 lines
Diff to previous 1.16 (colored)

ksyms: Use pserialize(9) for kernel access to ksyms.

This makes it available in interrupt context, e.g. for printing
messages with kernel symbol names for return addresses as drm wants
to do.

Revision 1.16 / (download) - annotate - [select for diffs], Tue Sep 7 16:56:13 2021 UTC (2 years, 7 months ago) by riastradh
Branch: MAIN
Changes since 1.15: +2 -8 lines
Diff to previous 1.15 (colored)

Revert "ksyms: Use pserialize(9) for kernel access to ksyms."

Revision 1.15 / (download) - annotate - [select for diffs], Tue Sep 7 11:00:02 2021 UTC (2 years, 7 months ago) by riastradh
Branch: MAIN
Changes since 1.14: +8 -2 lines
Diff to previous 1.14 (colored)

ksyms: Use pserialize(9) for kernel access to ksyms.

This makes it available in interrupt context, e.g. for printing
messages with kernel symbol names for return addresses as drm wants
to do.

Revision 1.14 / (download) - annotate - [select for diffs], Wed Sep 9 16:29:59 2020 UTC (3 years, 7 months ago) by maxv
Branch: MAIN
CVS Tags: thorpej-i2c-spi-conf2-base, thorpej-i2c-spi-conf2, thorpej-i2c-spi-conf-base, thorpej-i2c-spi-conf, thorpej-futex2-base, thorpej-futex2, thorpej-futex-base, thorpej-futex, thorpej-cfargs2-base, thorpej-cfargs2, thorpej-cfargs-base, thorpej-cfargs, cjep_sun2x-base1, cjep_sun2x-base, cjep_sun2x, cjep_staticlib_x-base1, cjep_staticlib_x-base, cjep_staticlib_x
Changes since 1.13: +15 -16 lines
Diff to previous 1.13 (colored)

kmsan: update the copyright notices

Revision 1.13 / (download) - annotate - [select for diffs], Sat Sep 5 16:30:12 2020 UTC (3 years, 7 months ago) by riastradh
Branch: MAIN
Changes since 1.12: +2 -4 lines
Diff to previous 1.12 (colored)

Round of uvm.h cleanup.

The poorly named uvm.h is generally supposed to be for uvm-internal
users only.

- Narrow it to files that actually need it -- mostly files that need
  to query whether curlwp is the pagedaemon, which should maybe be
  exposed by an external header.

- Use uvm_extern.h where feasible and uvm_*.h for things not exposed
  by it.  We should split up uvm_extern.h but this will serve for now
  to reduce the uvm.h dependencies.

- Use uvm_stat.h and #ifdef UVMHIST uvm.h for files that use
  UVMHIST(ubchist), since ubchist is declared in uvm.h but the
  reference evaporates if UVMHIST is not defined, so we reduce header
  file dependencies.

- Make uvm_device.h and uvm_swap.h independently includable while
  here.

ok chs@

Revision 1.12 / (download) - annotate - [select for diffs], Tue Jun 30 16:20:02 2020 UTC (3 years, 9 months ago) by maxv
Branch: MAIN
Changes since 1.11: +2 -25 lines
Diff to previous 1.11 (colored)

Make copystr() a MI C function, part of libkern and shared on all
architectures.

Notes:

 - On alpha and ia64 the function is kept but gets renamed locally to avoid
   symbol collision. This is because on these two arches, I am not sure
   whether the ASM callers do not rely on fixed registers, so I prefer to
   keep the ASM body for now.
 - On Vax, only the symbol is removed, because the body is used from other
   functions.
 - On RISC-V, this change fixes a bug: copystr() was just a wrapper around
   strlcpy(), but strlcpy() makes the operation less safe (strlen on the
   source beyond its size).
 - The kASan, kCSan and kMSan wrappers are removed, because now that
   copystr() is in C, the compiler transformations are applied to it,
   without the need for manual wrappers.

Could test on amd64 only, but should be fine.

Revision 1.11 / (download) - annotate - [select for diffs], Fri May 15 07:47:53 2020 UTC (3 years, 11 months ago) by maxv
Branch: MAIN
Changes since 1.10: +3 -3 lines
Diff to previous 1.10 (colored)

Use a generic description when scanning mbufs.

Revision 1.10 / (download) - annotate - [select for diffs], Wed Apr 15 16:28:28 2020 UTC (4 years ago) by maxv
Branch: MAIN
CVS Tags: phil-wifi-20200421, bouyer-xenpvh-base2, bouyer-xenpvh-base1
Changes since 1.9: +5 -5 lines
Diff to previous 1.9 (colored)

Use large pages for the kMSan shadows. This greatly improves performance,
and slightly reduces memory consumption.

Revision 1.9 / (download) - annotate - [select for diffs], Fri Apr 3 18:26:14 2020 UTC (4 years ago) by maxv
Branch: MAIN
CVS Tags: phil-wifi-20200411, phil-wifi-20200406, bouyer-xenpvh-base
Branch point for: phil-wifi, bouyer-xenpvh
Changes since 1.8: +4 -4 lines
Diff to previous 1.8 (colored)

Verify that the terminating '\0', too, is initialized.

Revision 1.8 / (download) - annotate - [select for diffs], Sat Feb 22 20:08:39 2020 UTC (4 years, 1 month ago) by maxv
Branch: MAIN
CVS Tags: is-mlppp-base, is-mlppp, ad-namecache-base3
Changes since 1.7: +3 -3 lines
Diff to previous 1.7 (colored)

Be less strict: when copyinstr() returns ENAMETOOLONG, it does initialize
the buffer, so mark it as such.

Revision 1.7 / (download) - annotate - [select for diffs], Fri Jan 31 08:26:10 2020 UTC (4 years, 2 months ago) by maxv
Branch: MAIN
Changes since 1.6: +100 -84 lines
Diff to previous 1.6 (colored)

Be more informative.

Revision 1.6 / (download) - annotate - [select for diffs], Sat Jan 25 15:55:33 2020 UTC (4 years, 2 months ago) by maxv
Branch: MAIN
CVS Tags: ad-namecache-base2
Changes since 1.5: +4 -4 lines
Diff to previous 1.5 (colored)

Actually, uio_vmspace is never NULL, the check should be against
pmap_kernel.

Revision 1.5 / (download) - annotate - [select for diffs], Sun Dec 8 11:53:54 2019 UTC (4 years, 4 months ago) by maxv
Branch: MAIN
CVS Tags: ad-namecache-base1, ad-namecache-base
Branch point for: ad-namecache
Changes since 1.4: +2 -4 lines
Diff to previous 1.4 (colored)

Use the inlines; it is actually fine, since the compiler drops the inlines
if the caller is kmsan-instrumented, forcing a white-listing of the memory
access.

Revision 1.4 / (download) - annotate - [select for diffs], Fri Dec 6 16:54:47 2019 UTC (4 years, 4 months ago) by maxv
Branch: MAIN
Changes since 1.3: +28 -15 lines
Diff to previous 1.3 (colored)

cast to proper type

Revision 1.3 / (download) - annotate - [select for diffs], Fri Nov 22 14:28:46 2019 UTC (4 years, 4 months ago) by maxv
Branch: MAIN
Changes since 1.2: +49 -4 lines
Diff to previous 1.2 (colored)

Ah, strcat/strchr/strrchr are ASM functions, so instrument them.

Revision 1.2 / (download) - annotate - [select for diffs], Fri Nov 15 12:18:46 2019 UTC (4 years, 5 months ago) by maxv
Branch: MAIN
CVS Tags: phil-wifi-20191119
Changes since 1.1: +187 -2 lines
Diff to previous 1.1 (colored)

Instrument ufetch/ustore in kMSan, these were the last remaining functions.

Revision 1.1 / (download) - annotate - [select for diffs], Thu Nov 14 16:23:52 2019 UTC (4 years, 5 months ago) by maxv
Branch: MAIN

Add support for Kernel Memory Sanitizer (kMSan). It detects uninitialized
memory used by the kernel at run time, and just like kASan and kCSan, it
is an excellent feature. It has already detected 38 uninitialized variables
in the kernel during my testing, which I have since discreetly fixed.

We use two shadows:
 - "shad", to track uninitialized memory with a bit granularity (1:1).
   Each bit set to 1 in the shad corresponds to one uninitialized bit of
   real kernel memory.
 - "orig", to track the origin of the memory with a 4-byte granularity
   (1:1). Each uint32_t cell in the orig indicates the origin of the
   associated uint32_t of real kernel memory.

The memory consumption of these shadows is consequent, so at least 4GB of
RAM is recommended to run kMSan.

The compiler inserts calls to specific __msan_* functions on each memory
access, to manage both the shad and the orig and detect uninitialized
memory accesses that change the execution flow (like an "if" on an
uninitialized variable).

We mark as uninit several types of memory buffers (stack, pools, kmem,
malloc, uvm_km), and check each buffer passed to copyout, copyoutstr,
bwrite, if_transmit_lock and DMA operations, to detect uninitialized memory
that leaves the system. This allows us to detect kernel info leaks in a way
that is more efficient and also more user-friendly than KLEAK.

Contrary to kASan, kMSan requires comprehensive coverage, ie we cannot
tolerate having one non-instrumented function, because this could cause
false positives. kMSan cannot instrument ASM functions, so I converted
most of them to __asm__ inlines, which kMSan is able to instrument. Those
that remain receive special treatment.

Contrary to kASan again, kMSan uses a TLS, so we must context-switch this
TLS during interrupts. We use different contexts depending on the interrupt
level.

The orig tracks precisely the origin of a buffer. We use a special encoding
for the orig values, and pack together in each uint32_t cell of the orig:
 - a code designating the type of memory (Stack, Pool, etc), and
 - a compressed pointer, which points either (1) to a string containing
   the name of the variable associated with the cell, or (2) to an area
   in the kernel .text section which we resolve to a symbol name + offset.

This encoding allows us not to consume extra memory for associating
information with each cell, and produces a precise output, that can tell
for example the name of an uninitialized variable on the stack, the
function in which it was pushed on the stack, and the function where we
accessed this uninitialized variable.

kMSan is available with LLVM, but not with GCC.

The code is organized in a way that is similar to kASan and kCSan, so it
means that other architectures than amd64 can be supported.

This form allows you to request diff's between any two revisions of a file. You may select a symbolic revision name using the selection box or you may type in a numeric name using the type-in text box.




CVSweb <webmaster@jp.NetBSD.org>