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

libkmod: Fix file error handling regression #242

Closed
wants to merge 1 commit into from

Conversation

stoeckmann
Copy link
Contributor

@stoeckmann stoeckmann commented Nov 13, 2024

The propagation of errors from loading function through errno must make sure that errno is positive, otherwise errors are not correctly spotted.

Proof of Concept:

  1. Create invalid module files of different file types
base64 -d <<< AAAAAAAAAA== > poc.ko
base64 -d <<< H4sAAAAAAA== > poc.ko.gz
base64 -d <<< /Td6WFoAAA== > poc.ko.xz
base64 -d <<< KLUv/QAAAA== > poc.ko.zst
  1. Run modinfo and check exit code
for i in poc.ko*
do
        echo "$i:"
        modinfo $i
        echo $?
done

The regression occurs in kmod 33 already. Its output is:

poc.ko:
filename:       /tmp/poc.ko
modinfo: ERROR: could not get modinfo from 'poc': Exec format error
1
poc.ko.gz:
filename:       /tmp/poc.ko.gz
libkmod: kmod_file_load_zlib: gzip: <fd:4>: unknown compression method
0
poc.ko.xz:
filename:       /tmp/poc.ko.xz
libkmod: xz_uncompress_belch: xz: Unexpected end of input
0
poc.ko.zst:
filename:       /tmp/poc.ko.zst
modinfo: ERROR: could not get modinfo from 'poc': Exec format error
1

With current master, we see:

poc.ko:
filename:       /tmp/poc.ko
modinfo: ERROR: could not get modinfo from 'poc': Exec format error
1
poc.ko.gz:
filename:       /tmp/poc.ko.gz
libkmod: ERROR: kmod_file_load_zlib: gzip: <fd:4>: unknown compression method
0
poc.ko.xz:
filename:       /tmp/poc.ko.xz
libkmod: ERROR: xz_uncompress_belch: xz: Unexpected end of input
0
poc.ko.zst:
filename:       /tmp/poc.ko.zst
libkmod: ERROR: kmod_file_load_zstd: zstd: Failed to determine decompression size
0

The propagation of errors from loading function through errno must make
sure that errno is positive, otherwise errors are not correctly spotted.

Fixes: 81e5c79 ("libkmod: propagate {zstd,xz,zlib}_load errors")
Signed-off-by: Tobias Stoeckmann <[email protected]>
Copy link

codecov bot commented Nov 13, 2024

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
libkmod/libkmod-file-zstd.c 0.00% 1 Missing ⚠️
libkmod/libkmod-file.c 0.00% 1 Missing ⚠️
Files with missing lines Coverage Δ
libkmod/libkmod-file-zstd.c 52.50% <0.00%> (ø)
libkmod/libkmod-file.c 71.01% <0.00%> (ø)

🚨 Try these New Features:

Copy link
Collaborator

@evelikov evelikov left a comment

Choose a reason for hiding this comment

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

Not sure if I call this a regression - nevertheless, nicely spotted.

lucasdemarchi pushed a commit that referenced this pull request Nov 19, 2024
The propagation of errors from loading function through errno must make
sure that errno is positive, otherwise errors are not correctly spotted.

Fixes: 81e5c79 ("libkmod: propagate {zstd,xz,zlib}_load errors")
Signed-off-by: Tobias Stoeckmann <[email protected]>
Reviewed-by: Emil Velikov <[email protected]>
Link: #242
Signed-off-by: Lucas De Marchi <[email protected]>
@lucasdemarchi
Copy link
Contributor

Applied, thanks

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

Successfully merging this pull request may close these issues.

3 participants