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

Bug report or patch? #136

Open
junwha0511 opened this issue Oct 30, 2023 · 10 comments
Open

Bug report or patch? #136

junwha0511 opened this issue Oct 30, 2023 · 10 comments

Comments

@junwha0511
Copy link

junwha0511 commented Oct 30, 2023

Dear @cbbarber, I found a vulnerability from qhull and reported it to qhull_bug@qhull.org, but this project seems not actively in maintenance.
So do you want me to patch the bug and open a Pull Request? or could you check the bug report in the email?

Thank you.

@cbbarber
Copy link
Collaborator

cbbarber commented Nov 1, 2023

This email was not received. Please try again

@junwha0511
Copy link
Author

I sent the email to both qhull_bug@qhull.org and qhull@qhull.org again.
Thank you for taking your time.

@junwha0511
Copy link
Author

Did the email arrive?

@cbbarber
Copy link
Collaborator

cbbarber commented Nov 6, 2023 via email

@junwha0511
Copy link
Author

junwha0511 commented Nov 6, 2023

I sent the email again!:)

@cbbarber
Copy link
Collaborator

cbbarber commented Nov 7, 2023

Good catch. Many thanks for reporting the problem and your good bug report.

It needs to be fixed, but should not cause problems for most Qhull users. The loop in qh_triangulate calls qh_delfacet, It does not allocate facets or other memory structures. For most users, qh_delfacet adds the facet's memory to qhmem.freelists via mem_r.cpp ("short memory"). The facet's memory is not released, instead it is reused later for other facets.

I'll fix the problem later this month.


Your email
The explanation is based on poly2_r.c.
there was an use after free where the function qh_triangulate processes facet of triangulated_facet_list.
it frees a facet using qh_delfacet at the line 3585 if the condition is satisfied. the problem is that, no matter it is freed or not, it updates facet->degenerate at line 3621. thus it leads to use-after-free.

@junwha0511
Copy link
Author

@cbbarber Thank you for looking our report!:)
we found another use-after-free, and sent you an email again.

we would appreciate it if you could confirm this bug when you have enough time

@cbbarber
Copy link
Collaborator

qh_freebuild is only called from qh_freeqhull which frees all memory and zero-outs qhmemT.

Is your code calling qh_freebuild from elsewhere? If so, it is likely a mistake.

In any case your email needs further review, best done when I fix this problem.

@junwha0511
Copy link
Author

As I understood, qh_build_withrestart calls qh_freebuild and then qh_initbuild, so it is likely to be used after qh_freebuild. but the facet_next would not be referenced after free in most cases, because qh_initbuild reinitializes the qh with new facet list (but in our log, it accessed at final logging).

I think it's a bug more about the correctness.

As a security researcher, we need your confirmation of the bug, although it is negligible because UAF is only occurs during logging, so could I politely ask you for the confirmation when you have enough time to review this bug?

Thank you for taking your time for our bug reports:)

@cbbarber
Copy link
Collaborator

Your analysis is good. I need to check if similar problems occur elsewhere. Expect a fix after I review the open issues and requests.

qh_build_withrestart in libqhull_r.c is used with option 'QJ' for joggled input. Merged facets (the default) usually produce a more accurate convex hull when the input contains geometric degeneracies (e.g., nearly coplanar facets). Joggled input avoids merging altogether allowing a simpler implementation. qh_build_withrestart calls qh_freebuild at each restart. qh_freebuild clears the facet lists after deleting the sentinel facet.

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

2 participants