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

mok: Avoid underflow in maximum variable size calculation #587

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions mok.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,12 +423,20 @@ mirror_mok_db(CHAR16 *name, CHAR8 *name8, EFI_GUID *guid, UINT32 attrs,
}

/* The name counts towards the size of the variable */
max_var_sz -= (StrLen(namen) + 1) * 2;
SIZE_T namen_sz = (StrLen(namen) + 1) * 2;
if (max_var_sz > namen_sz)
max_var_sz -= namen_sz;
else
max_var_sz = 0;
dprint(L"max_var_sz - name: %lx\n", max_var_sz);

SIZE_T howmany;
howmany = MIN((max_var_sz - sizeof(*esl)) / esl->SignatureSize,
(esl_end_pos - pos) / esl->SignatureSize);
if (max_var_sz > sizeof(*esl))
howmany = MIN((max_var_sz - sizeof(*esl)) / esl->SignatureSize,
(esl_end_pos - pos) / esl->SignatureSize);
else
howmany = 0;

if (howmany == 0) {
/* No signatures from this ESL can be mirrored in to a
* single variable, so skip it.
Expand Down