From: Marcos Oduardo <marcos.oduardo@gmail.com>
To: opensbi@lists.infradead.org
Cc: marcos <marcos.oduardo@gmail.com>
Subject: [PATCH] include: sbi: fix illegal shift in sbi_domain.h: sbi_domain_memregion_is_subset
Date: Mon, 23 Feb 2026 00:51:50 +0100 [thread overview]
Message-ID: <20260222235219.276432-1-marcos.oduardo@gmail.com> (raw)
From: marcos <marcos.oduardo@gmail.com>
In sbi_domain.h, when checking if a memory region is a subset of another,
an undefined behavior arithmetic operation was caught when sanitizing with
UBSan (shift exponent 64).
This patch adds a check to handle the case where the region order is 64,
avoiding the illegal shift and ensuring the operation remains defined.
Please let me know if there’s any other most suitable solution for this bug.
Signed-off-by: Marcos Oduardo <marcos.oduardo@gmail.com>
---
include/sbi/sbi_domain.h | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/include/sbi/sbi_domain.h b/include/sbi/sbi_domain.h
index c8a6da99..6e6dd33a 100644
--- a/include/sbi/sbi_domain.h
+++ b/include/sbi/sbi_domain.h
@@ -170,9 +170,11 @@ static inline bool sbi_domain_memregion_is_subset(
const struct sbi_domain_memregion *regB)
{
ulong regA_start = regA->base;
- ulong regA_end = regA->base + (BIT(regA->order) - 1);
+ ulong regA_mask = (regA->order >= 64) ? ~0UL : (BIT(regA->order) - 1);
+ ulong regA_end = regA_start + regA_mask;
ulong regB_start = regB->base;
- ulong regB_end = regB->base + (BIT(regB->order) - 1);
+ ulong regB_mask = (regB->order >= 64) ? ~0UL : (BIT(regB->order) - 1);
+ ulong regB_end = regB_start + regB_mask;
if ((regB_start <= regA_start) &&
(regA_start < regB_end) &&
--
2.53.0
--
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
next reply other threads:[~2026-02-22 23:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-22 23:51 Marcos Oduardo [this message]
2026-03-09 8:59 ` [PATCH] include: sbi: fix illegal shift in sbi_domain.h: sbi_domain_memregion_is_subset Anup Patel
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=20260222235219.276432-1-marcos.oduardo@gmail.com \
--to=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