#
2dd10e69 |
| 01-Nov-2024 |
riastradh <riastradh@NetBSD.org> |
string.h: Fix various symbol visibility issues.
1. Order declarations according to POSIX 2024 to make this easier to review side-by-side with the spec. 2. Fix visibility of memccpy: XSI-only, not
string.h: Fix various symbol visibility issues.
1. Order declarations according to POSIX 2024 to make this easier to review side-by-side with the spec. 2. Fix visibility of memccpy: XSI-only, not POSIX in general; require _XOPEN_SOURCE, not just _POSIX_C_SOURCE. 3. Omit redundant _XOPEN_SOURCE test around stpcpy/stpncpy. 4. Hide strdup in POSIX 2001. Not POSIX (without XSI) until 2008. 5. Hide strerror_r until POSIX 2001. Can't find evidence of it in any earlier POSIX or X/Open. (Not 100% sure on this one, maybe someone can double-check my research.) 6. Add restrict to strlcat/strlcpy. 7. Omit redundant _XOPEN_SOURCE test around strndup and strnlen. 8. Hide strtok_r until POSIX 2001. Can't find evidence of it in any earlier POSIX or X/Open. (Not 100% sure on this one, maybe someone can double-check my research.)
Carry the restrict qualifiers on strlcat/strlcpy to libkern too.
Main reference: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/string.h.html
PR standards/58804: string.h: wrong visibility for memccpy
show more ...
|
#
1b6856f7 |
| 09-Oct-2024 |
christos <christos@NetBSD.org> |
deduplicate offsetof (stddef.h) and container_of (container_of.h)
|
#
41aabe1d |
| 06-Sep-2023 |
mrg <mrg@NetBSD.org> |
fix the example for container_of().
needs to be a pointer into the containing structure, not the value of a pointer inside the structure.
|
#
57efa05d |
| 31-Dec-2021 |
riastradh <riastradh@NetBSD.org> |
libkern: Make KASSERT verify expression is valid if !DIAGNOSTIC.
This way it is no longer necessary to mark variables __diagused if they are used in KASSERT conditions.
Fix fallout from this by rem
libkern: Make KASSERT verify expression is valid if !DIAGNOSTIC.
This way it is no longer necessary to mark variables __diagused if they are used in KASSERT conditions.
Fix fallout from this by removing now-unnecessary and `#ifdef DIAGNOSTIC'.
Don't do the same for KDASSERT if !DEBUG -- unlike KASSERT and DIAGNOSTIC, variables needed by KDASSERT and DEBUG are likely to be expensive to compute (and potentially difficult for a compiler to prove flushable), so we don't want to require them under !DEBUG.
show more ...
|
#
7de9d97f |
| 17-May-2021 |
mrg <mrg@NetBSD.org> |
move bi-endian disklabel support from the kernel and libsa into libkern.
- dkcksum() and dkcksum_sized() move from subr_disk.c and from libsa into libkern/dkcksum.c (which is missing _sized() vers
move bi-endian disklabel support from the kernel and libsa into libkern.
- dkcksum() and dkcksum_sized() move from subr_disk.c and from libsa into libkern/dkcksum.c (which is missing _sized() version), using the version from usr.sbin/disklabel.
- swap_disklabel() moves from subr_disk_mbr.c into libkern, now called disklabel_swap(). (the sh3 version should be updated to use this.)
- DISKLABEL_EI becomes a first-class option with opt_disklabel.h.
- add libkern.h to libsa/disklabel.c.
this enables future work for bi-endian libsa/ufs.c (relevant for ffsv1, ffsv2, lfsv1, and lfsv2), as well as making it possible for ports not using subr_disk_mbr.c to include bi-endian disklabel support (which, afaict, includes any disk on mbr-supporting platforms that do not have an mbr as well as disklabel.)
builds successsfully on: alpha, i386, amd64, sun2, sun3, evbarm64, evbarm64-eb, sparc, and sparc64. tested in anita on i386 and sparc, testing in hardware on evbarm64*.
show more ...
|
#
fa320c3f |
| 21-Jan-2021 |
thorpej <thorpej@NetBSD.org> |
Add a generic set of routines for interacting with OpenFirmware-style string lists.
|
#
6aca65cc |
| 16-Jan-2021 |
chs <chs@NetBSD.org> |
remove unused "_DIAGNOSTIC" option and opt_diagnostic.h. note that this is unrelated to the widely used "DIAGNOSTIC" option.
|
#
b734c22d |
| 17-Apr-2020 |
maxv <maxv@NetBSD.org> |
Slightly reorder for clarity, and add header.
|
#
a6a8f007 |
| 07-Apr-2020 |
skrll <skrll@NetBSD.org> |
Fix KASAN build on aarch64
|
#
bbece984 |
| 03-Apr-2020 |
maxv <maxv@NetBSD.org> |
Add KASAN instrumentation on strcat/strchr/strrchr.
|
#
bd6c4f7f |
| 14-Dec-2019 |
riastradh <riastradh@NetBSD.org> |
Remove never-used Mersenne twister from libkern.
|
#
957ea672 |
| 05-Dec-2019 |
riastradh <riastradh@NetBSD.org> |
#ifdef notyet ---> never
|
#
ce425234 |
| 22-Nov-2019 |
maxv <maxv@NetBSD.org> |
Ah, strcat/strchr/strrchr are ASM functions, so instrument them.
|
#
10c5b023 |
| 14-Nov-2019 |
maxv <maxv@NetBSD.org> |
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
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.
show more ...
|
#
b7edd3d1 |
| 05-Nov-2019 |
maxv <maxv@NetBSD.org> |
Add Kernel Concurrency Sanitizer (kCSan) support. This sanitizer allows us to detect race conditions at runtime. It is a variation of TSan that is easy to implement and more suited to kernel internal
Add Kernel Concurrency Sanitizer (kCSan) support. This sanitizer allows us to detect race conditions at runtime. It is a variation of TSan that is easy to implement and more suited to kernel internals, albeit theoretically less precise than TSan's happens-before.
We do basically two things:
- On every KCSAN_NACCESSES (=2000) memory accesses, we create a cell describing the access, and delay the calling CPU (10ms).
- On all memory accesses, we verify if the memory we're reading/writing is referenced in a cell already.
The combination of the two means that, if for example cpu0 does a read that is selected and cpu1 does a write at the same address, kCSan will fire, because cpu1's write collides with cpu0's read cell.
The coverage of the instrumentation is the same as that of kASan. Also, the code is organized in a way similar to kASan, so it is easy to add support for more architectures than amd64. kCSan is compatible with KCOV.
Reviewed by Kamil.
show more ...
|
#
b0bea7da |
| 20-Sep-2019 |
maxv <maxv@NetBSD.org> |
Add ifdefs to eliminate false positives on lgtm, same as coverity.
|
#
1f8d4ff4 |
| 07-Sep-2019 |
maxv <maxv@NetBSD.org> |
Add KASAN instrumentation for memmove.
|
#
d1579b2d |
| 03-Sep-2018 |
riastradh <riastradh@NetBSD.org> |
Rename min/max -> uimin/uimax for better honesty.
These functions are defined on unsigned int. The generic name min/max should not silently truncate to 32 bits on 64-bit systems. This is purely a n
Rename min/max -> uimin/uimax for better honesty.
These functions are defined on unsigned int. The generic name min/max should not silently truncate to 32 bits on 64-bit systems. This is purely a name change -- no functional change intended.
HOWEVER! Some subsystems have
#define min(a, b) ((a) < (b) ? (a) : (b)) #define max(a, b) ((a) > (b) ? (a) : (b))
even though our standard name for that is MIN/MAX. Although these may invite multiple evaluation bugs, these do _not_ cause integer truncation.
To avoid `fixing' these cases, I first changed the name in libkern, and then compile-tested every file where min/max occurred in order to confirm that it failed -- and thus confirm that nothing shadowed min/max -- before changing it.
I have left a handful of bootloaders that are too annoying to compile-test, and some dead code:
cobalt ews4800mips hp300 hppa ia64 luna68k vax acorn32/if_ie.c (not included in any kernels) macppc/if_gm.c (superseded by gem(4))
It should be easy to fix the fallout once identified -- this way of doing things fails safe, and the goal here, after all, is to _avoid_ silent integer truncations, not introduce them.
Maybe one day we can reintroduce min/max as type-generic things that never silently truncate. But we should avoid doing that for a while, so that existing code has a chance to be detected by the compiler for conversion to uimin/uimax without changing the semantics until we can properly audit it all. (Who knows, maybe in some cases integer truncation is actually intended!)
show more ...
|
#
a0301d65 |
| 27-Aug-2018 |
maxv <maxv@NetBSD.org> |
Add kasan interceptors for strcpy/strcmp/strlen.
|
#
acb25765 |
| 20-Aug-2018 |
maxv <maxv@NetBSD.org> |
Add support for kASan on amd64. Written by me, with some parts inspired from Siddharth Muralee's initial work. This feature can detect several kinds of memory bugs, and it's an excellent feature.
It
Add support for kASan on amd64. Written by me, with some parts inspired from Siddharth Muralee's initial work. This feature can detect several kinds of memory bugs, and it's an excellent feature.
It can be enabled by uncommenting these three lines in GENERIC:
#makeoptions KASAN=1 # Kernel Address Sanitizer #options KASAN #no options SVS
The kernel is compiled without SVS, without DMAP and without PCPU area. A shadow area is created at boot time, and it can cover the upper 128TB of the address space. This area is populated gradually as we allocate memory. With this design the memory consumption is kept at its lowest level.
The compiler calls the __asan_* functions each time a memory access is done. We verify whether this access is legal by looking at the shadow area.
We declare our own special memcpy/memset/etc functions, because the compiler's builtins don't add the __asan_* instrumentation.
Initially all the mappings are marked as valid. During dynamic allocations, we add a redzone, which we mark as invalid. Any access on it will trigger a kASan error message. Additionally, the compiler adds a redzone on global variables, and we mark these redzones as invalid too. The illegal-access detection works with a 1-byte granularity.
For now, we cover three areas:
- global variables - kmem_alloc-ated areas - malloc-ated areas
More will come, but that's a good start.
show more ...
|
#
4231a89c |
| 08-Jul-2018 |
christos <christos@NetBSD.org> |
provide memmem
|
#
489063e9 |
| 09-Dec-2017 |
christos <christos@NetBSD.org> |
Even smaller and takes print function.
|
#
4a1f5c48 |
| 08-Dec-2017 |
christos <christos@NetBSD.org> |
coalesce the two copies of hexdump into libkern
|
#
8bc54e5b |
| 07-Jul-2016 |
msaitoh <msaitoh@NetBSD.org> |
KNF. Remove extra spaces. No functional change.
|
#
a44831a8 |
| 11-May-2016 |
rtr <rtr@NetBSD.org> |
provide const versions of container_of macros.
discussed with riastradh@ by email
|