RFR: 8280468: Crashes in getConfigColormap, getConfigVisualId, XVisualIDFromVisual on Linux [v4]

Maxim Kartashev duke at openjdk.java.net
Fri Apr 8 06:36:24 UTC 2022


> These crashes were not reproducible, so the fix is based on a hypothesis that there are two possible reasons for them:
> 1. `makeDefaultConfig()` returning `NULL`.
> 2. A race condition when the number of screens changes.
> The race scenario: `X11GraphisDevice.makeDefaultConfiguration()` is called on EDT so the call can race with `X11GraphisDevice.invalidate()` that re-sets the screen number of the device; the latter is invoked on the `AWT-XAWT` thread from `X11GraphicsEnvironment.rebuildDevices()`. So by the time `makeDefaultConfiguration()` makes a native call with the device's current screen number, the `x11Screens` array maintained by the native code could have become shorter. And the native methods like `Java_sun_awt_X11GraphicsDevice_getConfigColormap()` assume that the number passed to them is always current and valid. The AWT lock only protects against the changes during the native methods invocation and does not protect against them being called with an outdated screen number. With a larger screen number, those methods read past the end of the `x11Screens` array.
> 
> The fix for (1) is to die gracefully instead of crashing in an attempt to de-reference a `NULL` pointer, which might happen upon returning from `makeDefaultConfig()` in `getAllConfigs()`.
> 
> The fix for (2) is to eliminate the race by protecting `X11GraphisDevice.screen` with the AWT lock such that it doesn't change when the native methods working with it are active.
> 
> We've been shipping JetBrains Runtime with this fix for a few months now and there were no crash reports with those specific patterns against the versions with the fix.

Maxim Kartashev has updated the pull request incrementally with one additional commit since the last revision:

  Made the diff of X11GraphicsDevice.java less disruptive

-------------

Changes:
  - all: https://git.openjdk.java.net/jdk/pull/7182/files
  - new: https://git.openjdk.java.net/jdk/pull/7182/files/37017309..1c5ad928

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=7182&range=03
 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=7182&range=02-03

  Stats: 111 lines in 1 file changed: 35 ins; 35 del; 41 mod
  Patch: https://git.openjdk.java.net/jdk/pull/7182.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/7182/head:pull/7182

PR: https://git.openjdk.java.net/jdk/pull/7182



More information about the client-libs-dev mailing list