Fix read length handling#45
Merged
Merged
Conversation
jserv
requested changes
Jun 1, 2026
Collaborator
jserv
left a comment
There was a problem hiding this comment.
Check https://cbea.ms/git-commit/ carefully and enforce the rules.
The read callback may copy more bytes than the static string contains when the requested read length exceeds strlen(str). It also never updates *offset, so readers such as cat do not observe EOF. Use simple_read_from_buffer() to cap the read length and advance the file offset correctly. Signed-off-by: Shaoen-Lin <shaoen.lin92@gmail.com>
e47947c to
7bf0aba
Compare
Contributor
Author
|
I've modified my commit message. test case to reproduce: This test case verifies that reading sudo insmod ./vcam.ko
sudo timeout 2 cat /dev/vcamctl
echo $?
sudo rmmod vcamoutput before fix: 124output after fix: Virtual V4L2 compatible camera device
0 |
Collaborator
|
Thank @Shaoen-Lin for contributing! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Function
control_read()usesstrlen(str)as the source length, but replaces it with the user supplied length when the user buffer is larger. This makescopy_to_user()read past the end of the static string.The callback also ignores the file offset, so repeated reads do not reach EOF as expected.
Use
simple_read_from_buffer()to limit the copy to the requested count and update the offset consistently.Summary by cubic
Fix control_read to cap read length and honor file offsets by using simple_read_from_buffer, preventing reads past the static string and making repeated reads reach EOF.
Written for commit 7bf0aba. Summary will update on new commits.