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

8289697: buffer overflow in MTLVertexCache.m: MTLVertexCache_AddGlyphQuad #9368

Closed
wants to merge 8 commits into from

Conversation

VladimirKempik
Copy link

@VladimirKempik VladimirKempik commented Jul 4, 2022

Please review this simple patch. When running idea on jdk17 with asan I have found this buffer overflow.
The code checks the cache for at least one free element, while placing 6 elements to the cache.
The fix checks the presence of 6 free elements.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8289697: buffer overflow in MTLVertexCache.m: MTLVertexCache_AddGlyphQuad

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/9368/head:pull/9368
$ git checkout pull/9368

Update a local copy of the PR:
$ git checkout pull/9368
$ git pull https://git.openjdk.org/jdk pull/9368/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 9368

View PR using the GUI difftool:
$ git pr show -t 9368

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/9368.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 4, 2022

👋 Welcome back vkempik! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Jul 4, 2022
@openjdk
Copy link

openjdk bot commented Jul 4, 2022

@VladimirKempik The following label will be automatically applied to this pull request:

  • client

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the client client-libs-dev@openjdk.org label Jul 4, 2022
@mlbridge
Copy link

mlbridge bot commented Jul 4, 2022

@avu
Copy link
Contributor

avu commented Jul 4, 2022

Looks good for me

@VladimirKempik
Copy link
Author

Linux test failure unrelated, this commit changes only macos's code

Copy link
Contributor

@aghaisas aghaisas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good catch and fix.

There is another place in this file where MTLVC_ADD_TRIANGLES is used.
Although it is a corner case, it is worth adding the check for additional 6 vertices at that place as well.
Adding a separate check at the beginning of the MTLVertexCache_AddMaskQuad method where there is a check for maskCacheIndex seems logical to me. What do you think?

@VladimirKempik
Copy link
Author

Added one more check into MTLVertexCache_AddMaskQuad, to the first if condition.

Copy link
Contributor

@prrace prrace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any other cases like this ? We should look around. (PS I see Ajit asked the same question and perhaps even answered it !)
Did you find this by inspection or did you hit it ?
Can we use a defined constant instead of "6" ?

@VladimirKempik
Copy link
Author

VladimirKempik commented Jul 5, 2022

Are there any other cases like this ? We should look around. (PS I see Ajit asked the same question and perhaps even answered it !) Did you find this by inspection or did you hit it ?

I hit this bug when running IDEA on asan-enabled build of ojdk

ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6210011b94a8 at pc 0x0001707b9c0e bp 0x70001358e8f0 sp 0x70001358e8e8
WRITE of size 4 at 0x6210011b94a8 thread T56
#0 0x1707b9c0d in MTLVertexCache_AddGlyphQuad+0x5ed (libawt_lwawt.dylib:x86_64+0x1cbc0d)
....
0x6210011b94a8 is located 8 bytes to the right of 4000-byte region [0x6210011b8500,0x6210011b94a0)
allocated by thread T56 here:
#0 0x106857400 in wrap_malloc+0xa0 (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x44400)
#1 0x1707b8277 in MTLVertexCache_InitVertexCache+0x17 (libawt_lwawt.dylib:x86_64+0x1ca277)

Can we use a defined constant instead of "6" ?

#define TRI_IN_VERT 6 ?

VladimirKempik pushed a commit to JetBrains/JetBrainsRuntime that referenced this pull request Jul 6, 2022
@aghaisas
Copy link
Contributor

aghaisas commented Jul 6, 2022

I will submit a full test run with this patch and then approve on it's successful completion.

Copy link
Contributor

@aghaisas aghaisas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The full test run is good with this change.
2 comments in the code still use MTL_TRIS_IN_VERTEX. These need to be corrected.

@VladimirKempik
Copy link
Author

Yeah, missed that, thanks for noticing

@aghaisas
Copy link
Contributor

aghaisas commented Jul 7, 2022

Yeah, missed that, thanks for noticing

There is one instance of MTL_TRIS_IN_VERTEX still remaining in a comment!

avu pushed a commit to JetBrains/JetBrainsRuntime that referenced this pull request Jul 7, 2022
Copy link
Contributor

@prrace prrace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM although I'd really (really!) like you to break up those long lines before pushing.

@openjdk
Copy link

openjdk bot commented Jul 7, 2022

@VladimirKempik This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8289697: buffer overflow in MTLVertexCache.m: MTLVertexCache_AddGlyphQuad

Reviewed-by: prr

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 482 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jul 7, 2022
avu pushed a commit to JetBrains/JetBrainsRuntime that referenced this pull request Jul 8, 2022
@VladimirKempik
Copy link
Author

/reviewer credit aghaisas

@openjdk
Copy link

openjdk bot commented Jul 8, 2022

@VladimirKempik Reviewer aghaisas has already made an authenticated review of this PR, and does not need to be credited manually.

@VladimirKempik
Copy link
Author

/integrate

@openjdk
Copy link

openjdk bot commented Jul 8, 2022

Going to push as commit d852e99.
Since your change was applied there have been 484 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jul 8, 2022
@openjdk openjdk bot closed this Jul 8, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jul 8, 2022
@openjdk
Copy link

openjdk bot commented Jul 8, 2022

@VladimirKempik Pushed as commit d852e99.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

vprovodin pushed a commit to JetBrains/JetBrainsRuntime that referenced this pull request Jul 8, 2022
@VladimirKempik VladimirKempik deleted the JDK-8289697 branch March 29, 2023 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client client-libs-dev@openjdk.org integrated Pull request has been integrated
4 participants