lslogins: fix lastlog2 tty/host buffer overflow in get_lastlog2#4418
Merged
Conversation
get_lastlog2() copies the TTY and host strings read from the lastlog2 database into heap buffers of sizeof(ut_line)+1 and sizeof(ut_host)+1 bytes, but passed strlen(value)+1 as the mem2strcpy() limit. mem2strcpy() zero-fills and copies that many bytes regardless of the destination, so a database value longer than the field overflows the buffer. Cap the limit to the destination field size, matching the wtmp and plain-lastlog paths in the same function. Signed-off-by: aizu-m <aizumusheer2@gmail.com>
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.
Comparing the lastlog2 reader against the wtmp branch in the same function, the last mem2strcpy() argument looked wrong, so I traced it.
Under ASAN a host longer than 256 bytes gives a heap-buffer-overflow one byte after the 257-byte buffer (the memset). The values reach the database from pam_lastlog2 (PAM_TTY/PAM_RHOST, stored untruncated) or from any database handed to lslogins with --lastlog2-file. Capped the limit to the destination field size, which is what the wtmp and plain-lastlog branches just above already do.