Home | History | Annotate | Download | only in kern
History log of /src/sys/kern/subr_asan.c
RevisionDateAuthorComments
 1.28  09-Apr-2023  riastradh kern: KASSERT(A && B) -> KASSERT(A); KASSERT(B)
 1.27  18-Dec-2020  martin While we are inside ddb, allow all memory access.
 1.26  10-Sep-2020  maxv branches: 1.26.2;
kasan: fix the copyright notices
 1.25  05-Sep-2020  riastradh 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@
 1.24  10-Jul-2020  skrll Expose KASAN_SHADOW_SCALE_SHIFT. OK'ed by maxv.
 1.23  03-Jul-2020  skrll Make this compile/work on 32-bit archs. OK'ed my maxv

I thought about uintptr_t, but didn't change from Elf_Addr
 1.22  30-Jun-2020  maxv 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.
 1.21  13-Apr-2020  maxv Add KASAN-DMA support on aarch64, same as amd64. Discussed with skrll@.
 1.20  03-Apr-2020  maxv branches: 1.20.2;
Add KASAN instrumentation on strcat/strchr/strrchr.
 1.19  03-Apr-2020  maxv Add KASAN instrumentation on on-stack VLAs.
 1.18  08-Feb-2020  maxv Sync the codes with reality: partial replaced by mid, and use-after-ret
added.
 1.17  25-Jan-2020  maxv Actually, uio_vmspace is never NULL, the check should be against
pmap_kernel.
 1.16  10-Oct-2019  maxv branches: 1.16.2;
Add KASAN instrumentation on ucas and ufetch.
 1.15  04-Oct-2019  maxv Add DMA instrumentation in KASAN. We note the original buffer and length in
the map, and check the buffer on each bus_dmamap_sync. This allows us to
find DMA buffer overflows and UAFs, which couldn't be found before because
the device accesses to memory are outside of KASAN's control.
 1.14  22-Sep-2019  maxv Fix KASAN on aarch64: the bus_space_* functions are macros, so we can't
redefine them. Introduce __HAVE_KASAN_INSTR_BUS, which indicates whether
to instrument the bus functions. Defined on amd64 only.
 1.13  07-Sep-2019  maxv Add KASAN instrumentation on the bus_space functions that handle buffers.
 1.12  07-Sep-2019  maxv Add KASAN instrumentation for memmove.
 1.11  05-Sep-2019  maxv Add KASAN instrumentation on the atomic functions. Use macros to simplify.
These macros are prerequisites for future changes.
 1.10  15-Jun-2019  maxv Add KASAN_PANIC, an option to turn KASAN warning into kernel panics,
requested by Siddharth. While here clarify a little.
 1.9  04-May-2019  maxv branches: 1.9.2;
Rewrite kasan_mark() to fix a still existing race in pool_cache_get_paddr()
that could cause false positives. Now a buffer initially valid remains
valid, with no invalid->valid dance.
 1.8  04-May-2019  maxv Add KASAN instrumentation for kcopy and copystr.
 1.7  11-Apr-2019  maxv Add KASAN instrumentation for copyin/copyinstr/copyoutstr. No copyout for
now, because mm.c needs whitelisting.
 1.6  07-Apr-2019  maxv Provide a code argument in kasan_mark(), and give a code to each caller.
Five codes used: GenericRedZone, MallocRedZone, KmemRedZone, PoolRedZone,
and PoolUseAfterFree.

This can greatly help debugging complex memory corruptions.
 1.5  24-Feb-2019  maxv Improve the KASAN output, provide an error code, to help distinguish
classes of bugs.
 1.4  24-Feb-2019  maxv Add support for use-after-scope detection in KASAN. It is available since
GCC7, and we have GCC7 by default now.

Slightly reorder the code, and remove a duplicated KASSERT too.

Tested on amd64-KASAN. Not yet enabled on aarch64-KASAN, but it should
work as-is.
 1.3  13-Feb-2019  kamil Align the kASan message style with kUBSan

Print messages with initial 'ASan', simiarly to kUBSan printing 'UBSan'.
 1.2  23-Dec-2018  maxv Simplify the KASAN API, use only kasan_mark() and explain briefly. The
alloc/free naming was too confusing.
 1.1  31-Oct-2018  maxv branches: 1.1.2;
Move the MI parts of KASAN into kern/subr_asan.c. This file includes
machine/asan.h, which contains the MD functions. We use an include rather
than a plain C file, because we want GCC to optimize/inline some functions
into one single block.

The amd64 MD parts of KASAN are moved accordingly.

The naming convention we use is:

kasan_*
a generic kasan object, declared in subr_asan.c
kasan_md_*
an MD kasan object, declared in machine/asan.h, and used
in subr_asan.c
__md_*
an MD object, declared in machine/asan.h, and not used
outside

Overall this makes it easier to add KASAN support on more architectures.

Discussed with several people.
 1.1.2.3  26-Dec-2018  pgoyette Sync with HEAD, resolve a few conflicts
 1.1.2.2  26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.1.2.1  31-Oct-2018  pgoyette file subr_asan.c was added on branch pgoyette-compat on 2018-11-26 01:52:50 +0000
 1.9.2.4  21-Apr-2020  martin Sync with HEAD
 1.9.2.3  13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.9.2.2  10-Jun-2019  christos Sync with HEAD
 1.9.2.1  04-May-2019  christos file subr_asan.c was added on branch phil-wifi on 2019-06-10 22:09:03 +0000
 1.16.2.2  29-Feb-2020  ad Sync with head.
 1.16.2.1  25-Jan-2020  ad Sync with head.
 1.20.2.1  20-Apr-2020  bouyer Sync with HEAD
 1.26.2.1  03-Jan-2021  thorpej Sync w/ HEAD.

RSS XML Feed