Skip to content

__readlink_chk, __readlinkat_chk: properly pass buffer length#115

Open
yorickvP wants to merge 1 commit into
dex4er:masterfrom
yorickvP:fix-readlinkat
Open

__readlink_chk, __readlinkat_chk: properly pass buffer length#115
yorickvP wants to merge 1 commit into
dex4er:masterfrom
yorickvP:fix-readlinkat

Conversation

@yorickvP
Copy link
Copy Markdown

Fixes #114

Copy link
Copy Markdown

@josch josch left a comment

Choose a reason for hiding this comment

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

This effectively circumvents the check that is done in __readlink_chk which checks if (len > buflen) by passing FAKECHROOT_PATH_MAX-1 for both arguments.

Comment thread src/__readlink_chk.c
if ((linksize = nextcall(__readlink_chk)(path, tmp, FAKECHROOT_PATH_MAX-1, buflen)) == -1) {
if (__builtin_expect(!!(bufsiz > buflen), 0)) {
printf("readlink: prevented write past end of buffer\n");
exit(-1);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

why the exit? why not just return failure?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Because _chk functions should exit on overflow. Actually __chk_fail should be called (similar to __realpath_chk).
https://refspecs.linuxbase.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/libc---readlink-chk-1.html

Comment thread src/__readlink_chk.c

if ((linksize = nextcall(__readlink_chk)(path, tmp, FAKECHROOT_PATH_MAX-1, buflen)) == -1) {
if (__builtin_expect(!!(bufsiz > buflen), 0)) {
printf("readlink: prevented write past end of buffer\n");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

why the printf to stdout? at most there is a print to stderr done in the rest of the codebase

Comment thread src/__readlink_chk.c
expand_chroot_path(path);

if ((linksize = nextcall(__readlink_chk)(path, tmp, FAKECHROOT_PATH_MAX-1, buflen)) == -1) {
if (__builtin_expect(!!(bufsiz > buflen), 0)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

why the double exclamation mark? bufsiz > buflen is already a boolean

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.

buffer-overflow FORTIFY_SOURCE=2

3 participants