-
Notifications
You must be signed in to change notification settings - Fork 74
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
__readlink_chk, __readlinkat_chk: properly pass buffer length #115
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
@@ -41,7 +42,12 @@ wrapper(__readlink_chk, ssize_t, (const char * path, char * buf, size_t bufsiz, | |||
debug("__readlink_chk(\"%s\", &buf, %zd, %zd)", path, bufsiz, buflen); | |||
expand_chroot_path(path); | |||
|
|||
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"); |
There was a problem hiding this comment.
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
@@ -41,7 +42,12 @@ wrapper(__readlink_chk, ssize_t, (const char * path, char * buf, size_t bufsiz, | |||
debug("__readlink_chk(\"%s\", &buf, %zd, %zd)", path, bufsiz, buflen); | |||
expand_chroot_path(path); | |||
|
|||
if ((linksize = nextcall(__readlink_chk)(path, tmp, FAKECHROOT_PATH_MAX-1, buflen)) == -1) { | |||
if (__builtin_expect(!!(bufsiz > buflen), 0)) { |
There was a problem hiding this comment.
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
Fixes #114