From: Samuel Holland <samuel.holland@sifive.com>
To: Marcos Oduardo <marcos.oduardo@gmail.com>, opensbi@lists.infradead.org
Subject: Re: [PATCH] lib: sbi: KASan implementation for OpenSBI
Date: Wed, 14 Jan 2026 13:08:15 -0600 [thread overview]
Message-ID: <f7f86129-0118-4eaf-8699-69bd4398a0bb@sifive.com> (raw)
In-Reply-To: <20260114184316.45312-1-marcos.oduardo@gmail.com>
Hi Marcos,
On 2026-01-14 12:43 PM, Marcos Oduardo wrote:
> From: marcos <marcos.oduardo@gmail.com>
>
> KASan (Kernel Address Sanitizer) is a tool implemented using compiler
> instrumentation at runtime that allows checking for memory management
> bugs such as heap OOB access, stack overflow or global OOB write.
> Compiling and testing the OpenSBI firmware against KASan will print a
> message in the console highlighting the memory access that caused the
> bug and its address.
>
> Support for this implementation involves two main components:
> 1. The KASan implementation hooks: Custom malloc, memset, memcpy to
> check for bugs and the handlers when finding a bug.
> 2. A test suite to verify correct operation at runtime.
>
> KASan needs to keep a copy of the sanitized memory region. This copy is
> named shadowmap, and each byte of this map corresponds to 8 bytes of
> real memory. KASan keeps a record of the state of each address and
> checks each memory access performed by OpenSBI.
>
> In addition, this patch increases FW_PAYLOAD_OFFSET to accommodate the
> memory overhead when both KASan and UBSan are enabled simultaneously,
> ensuring that the OpenSBI binary fits within the limits.
>
> Users may compile OpenSBI with the KASan instrumentation by adding the
> flag ENABLEKASAN=y to the make command. To compile with the tests, add
> the flag ENABLEKASANTESTS=y.
>
> Note that the implementation of KASan adds a certain overhead caused by
> the checks performed at runtime and the shadowmap loaded in memory;
> therefore, it is only expected to be used in development builds, never
> in production. If ENABLEKASAN is not set, tests won't be compiled even
> if the ENABLEKASANTESTS flag is enabled.
>
> Signed-off-by: Marcos Oduardo <marcos.oduardo@gmail.com>
> ---
> Makefile | 32 ++++
> firmware/fw_base.S | 4 +-
> firmware/fw_base.ldS | 9 +-
> include/sbi/sbi_heap.h | 22 ++-
> include/sbi/sbi_kasan.h | 35 ++++
> include/sbi/sbi_kasan_test.h | 24 +++
> include/sbi/sbi_string.h | 13 +-
> include/sbi/sbi_types.h | 1 +
> lib/sbi/objects.mk | 3 +
> lib/sbi/sbi_heap.c | 5 +-
> lib/sbi/sbi_init.c | 19 ++
> lib/sbi/sbi_kasan.c | 343 +++++++++++++++++++++++++++++++++++
> lib/sbi/sbi_kasan_test.c | 60 ++++++
> lib/sbi/sbi_string.c | 55 +++++-
> platform/generic/objects.mk | 5 +-
> 15 files changed, 616 insertions(+), 14 deletions(-)
> create mode 100644 include/sbi/sbi_kasan.h
> create mode 100644 include/sbi/sbi_kasan_test.h
> create mode 100644 lib/sbi/sbi_kasan.c
> create mode 100644 lib/sbi/sbi_kasan_test.c
...
> diff --git a/include/sbi/sbi_kasan.h b/include/sbi/sbi_kasan.h
> new file mode 100644
> index 00000000..2a3c027a
> --- /dev/null
> +++ b/include/sbi/sbi_kasan.h
> @@ -0,0 +1,35 @@
> +/*
> + * Copyright 2024 Google LLC
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * version 2 as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + */
This looks like it would be a very useful feature, but you have added several
files under a license that is not compatible with the remainder of the OpenSBI
project, which uses the BSD-2-Clause license. I don't think this patch can be
reviewed in its current state.
Regards,
Samuel
--
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
next prev parent reply other threads:[~2026-01-14 19:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-14 18:43 [PATCH] lib: sbi: KASan implementation for OpenSBI Marcos Oduardo
2026-01-14 19:08 ` Samuel Holland [this message]
2026-01-22 23:31 ` [PATCH v2] lib: sbi: Add " Marcos Oduardo
2026-01-22 23:42 ` Marcos Oduardo
2026-01-24 9:35 ` Bo Gan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f7f86129-0118-4eaf-8699-69bd4398a0bb@sifive.com \
--to=samuel.holland@sifive.com \
--cc=marcos.oduardo@gmail.com \
--cc=opensbi@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox