Skip to content

evmctl: reject a zero-length IMA digest field - #47

Open
Eusgor wants to merge 1 commit into
linux-integrity:next-testingfrom
Eusgor:evmctl-digest-field-bounds
Open

Eusgor wants to merge 1 commit into
linux-integrity:next-testingfrom
Eusgor:evmctl-digest-field-bounds

Conversation

@Eusgor

@Eusgor Eusgor commented Sep 23, 2026

Copy link
Copy Markdown

ima_ng_show() already rejects a digest field longer than the remaining template data. A zero length still passes that test: field_len - 1 wraps to UINT32_MAX and is passed to strnlen(), which reads past the template buffer. Subtracting that length from field_len can wrap as well.

Require a non-zero digest field before using field_len - 1 as the strnlen() limit. strnlen() then returns at most field_len - 1, so the existing field_len - len subtraction stays in range.

ima_ng_show() already rejects a digest field longer than the
remaining template data. A zero length still passes that test:
field_len - 1 wraps to UINT32_MAX and is passed to strnlen(), which
reads past the template buffer. Subtracting that length from
field_len can wrap as well.

Require a non-zero digest field before using field_len - 1 as the
strnlen() limit. strnlen() then returns at most field_len - 1, so
the existing field_len - len subtraction stays in range.

Signed-off-by: Evgeniy Gorbanyov <esgor@altlinux.org>
@mimizohar

Copy link
Copy Markdown
Collaborator

This patch looks good. Could you fix the other field_len usage as well, maybe as a separate patch.

@Eusgor

Eusgor commented Sep 25, 2026

Copy link
Copy Markdown
Author

The remaining total_len < field_len checks are for the signature and ima-buf fields. A zero length is valid there: it means the signature or buffer is absent. Both paths already skip the field when field_len is 0, so the length is not used in pointer or size arithmetic.
Rejecting field_len == 0 for those fields would fail ordinary measurement-list records. I do not think a separate patch is needed.

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