Skip to content
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

Deallocation of control->suffix corrupts Heap Memory #216

Closed
pietroborrello opened this issue Feb 24, 2022 · 5 comments
Closed

Deallocation of control->suffix corrupts Heap Memory #216

pietroborrello opened this issue Feb 24, 2022 · 5 comments

Comments

@pietroborrello
Copy link

The suffix field in the static rzip_control structure is initialized to point to global memory in initialize_control

lrzip/lrzip.c

Line 1341 in 64eb4a8

control->suffix = ".lrz";

and in the lrzip main.

lrzip/main.c

Line 496 in 6a1600b

control->suffix = optarg;

However the field is then treated as a heap allocated variable while freeing the rzip_control variable.
Both in rzip_control_free

lrzip/rzip.c

Line 1269 in 465afe8

dealloc(control->suffix);

and when setting a new suffix

dealloc(lr->control->suffix);

Impact

Corrupting the heap state may result in an exploitable vulnerability, especially if initialized with optarg that points to global RW memory.

Fix
It is sufficient to initialize control->suffix using the return value of a strdup of the strings.

@pete4abw
Copy link
Contributor

Good grief! This has been around since v0.1 and rzip before, even before I became involved (v0.19). The initialise function should be used for setting constants or like-size variables, like compression level, etc. Setting control->suffix to equal optarg is probably a mistake if there will be recursion. I think the dealloc of suffix is incorrect too. It does not need to be. HOWEVER, the ability to pipe input to lrzip sort of makes recursion obsolete and unnecessary. strdup will work and I'll see about implementing it in lrzip-next. Thank you

@pietroborrello
Copy link
Author

Great, thank you! Will checkout lrzip-next

@ckolivas
Copy link
Owner

Fixed in master.

@carnil
Copy link

carnil commented Apr 16, 2022

Retrospective note: This seems to have been a CVE assigned, which is CVE-2022-28044.

@utkarsh2102
Copy link

Hello, is there a simple reproducer for this one?

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

No branches or pull requests

5 participants