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

netlink: Re-derive the base capability of the snl msg_buffer in realloc #2281

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

RoundofThree
Copy link
Member

If the new base pointer obtained in snl_realloc_msg_buffer does not have the same bounds as the original base pointer, we need to re-derive all the capabilities that are relative to the base. This was found while fuzzing.

Tagging @YiChenChai.

If the new base pointer obtained in snl_realloc_msg_buffer
does not have the same bounds as the original base pointer,
we need to re-derive all the capabilities that are relative to
the base.
Comment on lines +1102 to +1104
int hdr_off = (char *)(nw->hdr) - nw->base;
nw->hdr = (struct nlmsghdr *)
(void *)((char *)nw->base + hdr_off);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int hdr_off = (char *)(nw->hdr) - nw->base;
nw->hdr = (struct nlmsghdr *)
(void *)((char *)nw->base + hdr_off);
int hdr_off = (char *)(nw->hdr) - nw->base;
nw->hdr = (struct nlmsghdr *)
(void *)((char *)nw->base + hdr_off);

to match existing formatting

@@ -1095,6 +1095,16 @@ snl_realloc_msg_buffer(struct snl_writer *nw, size_t sz)
}
nw->base = (char *)new_base;
}
#ifdef __CHERI_PURE_CAPABILITY__
if (cheri_getlen(new_base) != cheri_getlen(nw->base)) {
nw->base = (char *)cheri_setboundsexact(new_base, nw->size);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't snl_allocz already do this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants