Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Narrow bounds on kernel malloc allocations. #2261

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from
Prev Previous commit
Next Next commit
uma: Set bounds on slab_data().
This prevents possible overflows into the slab header.
qwattash committed Dec 5, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 3b947dd57cde2bf2a704f5450f387b6d972cf896
21 changes: 17 additions & 4 deletions sys/vm/uma_int.h
Original file line number Diff line number Diff line change
@@ -413,11 +413,24 @@ slab_tohashslab(uma_slab_t slab)
static inline void *
slab_data(uma_slab_t slab, uma_keg_t keg)
{
void *data;

if ((keg->uk_flags & UMA_ZFLAG_OFFPAGE) == 0)
return ((void *)((uintptr_t)slab - keg->uk_pgoff));
else
return (slab_tohashslab(slab)->uhs_data);
if ((keg->uk_flags & UMA_ZFLAG_OFFPAGE) == 0) {
data = (void *)cheri_kern_setboundsexact(
(uintptr_t)slab - keg->uk_pgoff, keg->uk_pgoff);
#ifdef __CHERI_PURE_CAPABILITY__
KASSERT(cheri_gettag(data),
("Unrepresentable slab uk_pgoff %x", keg->uk_pgoff));
#endif
} else {
data = slab_tohashslab(slab)->uhs_data;
#ifdef __CHERI_PURE_CAPABILITY__
KASSERT(cheri_getlen(data) == keg->uk_ppera * PAGE_SIZE,
("Unexpected offpage slab capability: %#p, "
"expected %d pages", data, keg->uk_ppera));
#endif
}
return (data);
}

static inline void *