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

Fix null pointer dereference in getName/getString #127

Merged
merged 3 commits into from
May 20, 2018
Merged

Conversation

hlef
Copy link
Contributor

@hlef hlef commented Mar 15, 2018

Whenever getString or getName are called with an act such that act->p.String is a NULL pointer, a NULL pointer dereference might happen (strlen(act->p.string) is called).

In this commit we add checks at the beginning of the PUSH_STRING block so that a warning is displayed and an empty string is returned in this case.

This PR (partially) fixes #121. In fact I am still working on another patch which would involve patching pushdup to do deep copies instead of shallow copies, but before I will have to analyze the specification in order to be able to clearly state which interpretation is the right one.

Whenever getString or getName are called with an act such that act->p.String
is a NULL pointer, a NULL pointer dereference might happen
(strlen(act->p.string) is called).

In this commit we add checks at the beginning of the PUSH_STRING block so
that a warning is displayed and an empty string is returned in this case.

This patch fixes libming#121.
@hlef
Copy link
Contributor Author

hlef commented Mar 16, 2018

I have just added another commit addressing #116.

@strk
Copy link
Member

strk commented Mar 20, 2018 via email

getString is allocating a 4-bytes buffer to store an 'R' and an
8-bit number.

t=malloc(4); /* Rdd */
sprintf(t,"R%d", act->p.RegisterNumber );
return t;

Since up to three digits can be required to store the 8-bit
number, the buffer has to be 5 bytes long.

In this commit we also fix the PUSH_DOUBLE case by dynamically
computing the required buffer size.

This commit fixes libming#116 (CVE-2018-7867).
@hlef
Copy link
Contributor Author

hlef commented Mar 21, 2018

Thanks Sandro for the feedback. I have pushed an updated patch which also handles the case where snprintf would return negative needed_length (error code). Not sure in which circumstances this might happen, but better check it.

@hlef
Copy link
Contributor Author

hlef commented Apr 1, 2018

I have just pushed the changes to pushdup. See commit message for more information. This PR now fully adresses #121 and #116.

@hlef
Copy link
Contributor Author

hlef commented Apr 1, 2018

Oh well, wait, looks like something is still going wrong.

I'm going to push an updated version of this PR soon.

Until now, the element duplication in pushdup was performed via
t->val = Stack->val.

While this is perfectly fine for integer/double/register values,
this may create nasty, hard to debug issues with Strings. In fact,
when called with a String at the top of the stack, pushdup would
only push *a reference* to the same String element (shallow copy),
later allowing to modify several stack elements at once, which may
potentially lead to NULL pointer dereferences or any other
unspecified impact.

In this patch we implement deep copy in pushdup:
* If the type of the stack element is 's' (for String), we
  allocate a new buffer and copy the String into it.
* Otherwise we simply proceed as before, that is we do t->val = Stack->val
  which is perfectly fine since we are not dealing with pointers.

This patch is the last part of the patch for libming#121 (fixes libming#121), which
should now be completely fixed.
@hlef
Copy link
Contributor Author

hlef commented Apr 1, 2018

It should be fine now. There is a fairly high amount of changes, so even if I already tested everything, a careful review would be nice.

Thanks !

@strk
Copy link
Member

strk commented Apr 5, 2018 via email

@hlef
Copy link
Contributor Author

hlef commented Apr 8, 2018

While I indeed think writing unit tests would be a very important step towards more stability in libming, this is most likely not something that I can do as part of my Debian LTS duties, and I don't have much spare time currently...

Is there any bug report on this build system issue ? If I can get a precise description of the problem, I'll maybe check if can do something.

@hlef
Copy link
Contributor Author

hlef commented Apr 8, 2018

But anyways, this is not something I'd do in this PR.

@strk strk merged commit 6f1ab31 into libming:master May 20, 2018
@strk
Copy link
Member

strk commented May 20, 2018

Ok thanks, tests postponed

@hlef
Copy link
Contributor Author

hlef commented May 21, 2018

Thanks !

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.

Null pointer dereference vulnerability in getName (util/decompile.c:380)
2 participants