Skip to content

EGL translator: concurrent eglCreatePbufferSurface() calls can get the same surface handle #241

Open

Description

@RieBi

Summary

EglSurface gets its handle from ++s_nextSurfaceHndl (host/gl/glestranslator/egl/egl_surface.h).
The counter is a plain unsigned int. eglCreatePbufferSurface() constructs the surface before
it takes graphicsDriverLock(). Thus, two threads can increment the counter at the same time and
get the same handle.

Cause

  1. egl_imp.cpp, eglCreatePbufferSurface(): new EglPbufferSurface(dpy, cfg) runs before
    AutoLock mutex(*graphicsDriverLock()).
  2. The EglSurface constructor does m_hndl = ++s_nextSurfaceHndl;. This is a data race when
    two render threads create pbuffer surfaces at the same time.
  3. EglDisplay::addSurface() does not add a surface if its handle is already in the map. It
    returns the existing handle.
  4. The second caller gets the handle of the first surface. Its own surface is released.

Window surfaces and contexts get their handles while the lock is held. They are not affected.
~EglContext also creates an EglPbufferSurface. It can run outside the lock, for example when
a thread exits.

Result

Two EmulatedEglWindowSurface objects can share one host EGL surface. When one is destroyed,
calls on the other fail with EGL_BAD_SURFACE.

Expected result

Each surface gets a unique handle.

Proposed fix

Make s_nextSurfaceHndl a std::atomic<unsigned int>. The increment then gives a unique value
without the lock. PR: #243.

Notes

We found this by code review. We did not see it occur.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions