Skip to content

Conversation

@vathpela
Copy link
Member

These are fixes discovered through cov-scan, clang's scan-build, and gcc -fanalyzer.

vathpela added 10 commits March 12, 2025 15:52
If variable_create_esl_with_one_signature() succeeds but
CreateTimeBasedPayload() fails, we leak the allocation for our
certificate.

This patch frees it.

Resolves: Coverity CID 457504
Signed-off-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Peter Jones <pjones@redhat.com>
Resolves: Coverity CID 457502
Signed-off-by: Peter Jones <pjones@redhat.com>
Resolves: Coverity CID 457507
Signed-off-by: Peter Jones <pjones@redhat.com>
Coverity identified a resource leak of namen8 in mirror_mok_db(), and
upon further examination nothing is even using it any more; we're
allocating it and populating it for nothing.

This removes all that.

Resolves: Coverity CID 457510
Signed-off-by: Peter Jones <pjones@redhat.com>
If measuring a mok variable to the TPM returns failure, this function
returns, but never frees the data intended to be measured.

This frees it.

Resolves: Coverity CID 457503
Signed-off-by: Peter Jones <pjones@redhat.com>
When we've split a mok variable into name0..nameN, we re-use the same
buffer over and over, but we never free it at the end.

This frees it.

Resolves: Coverity CID 457501
Signed-off-by: Peter Jones <pjones@redhat.com>
scan-build notes that we assign bprop.hnd, an EFI_HANDLE for the device
path protocol, to our loaded_image->li.DeviceHandle, and it thinks since
bprop is uninitialized that means it can be NULL or garbage.

I don't think that's actually true, because every path to that requires
either returning an error or doing some variety of:

  status = BS->LocateDevicePath(&gEfiDevicePathProtocolGuid, &bp, &hnd)

and checking its error, but only one of those paths explicitly sets a
value, and static checkers can't tell what BS->LocateDevicePath does
with the pointer.

This patch avoids the issue by initializing the whole bprop structure to
begin with.

Signed-off-by: Peter Jones <pjones@redhat.com>
"gcc -fanalyzer" thinks that in simple_dir_filter(), we can get "next"
to be a NULL pointer even when simple_dir_read_all() return success and
we're iterating the total number of entries it claimed it returned.

I don't think this is true, but to make it stop complaining I've added
tests to that pointer that'll make it stop if it gets to the end of the
list.

Signed-off-by: Peter Jones <pjones@redhat.com>
It breaks every time somehow.

Signed-off-by: Peter Jones <pjones@redhat.com>
@vathpela vathpela marked this pull request as ready for review March 14, 2025 15:05
@vathpela vathpela merged commit db1f1da into rhboot:main Mar 14, 2025
20 checks passed
@vathpela vathpela deleted the cov-scan-shim-16 branch March 14, 2025 15:05
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