Skip to content

Conversation

@yorickvP
Copy link

Fixes #114

Copy link

@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.

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

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

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


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

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

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

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