From ac11771348146087eb577d20162ec10a81358a7e Mon Sep 17 00:00:00 2001 From: Tom Englund Date: Fri, 28 Jun 2024 22:24:32 +0200 Subject: [PATCH 1/3] core: fix a few ubsan issues reported at exit of hyprland (#6699) * watchdog: dont detach and cause race condition instead of detaching and causing a race condition on destruction where the thread is alive and watchdog has been destroyed, check if its joinable and join it on destruction. causes heap use after free on exit of compositor. * render: add checks for compositor shutting down avoid member call on null pointer, if the g_pHyprRenderer is destroyed we can call the member makeEGLCurrent on it, causes undefined behaviour on destruction of the compositor/hyprrenderer. found with ubsan. --- src/helpers/Watchdog.cpp | 6 +++--- src/render/Renderbuffer.cpp | 2 +- src/render/Texture.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/helpers/Watchdog.cpp b/src/helpers/Watchdog.cpp index afb8a946..b9f654da 100644 --- a/src/helpers/Watchdog.cpp +++ b/src/helpers/Watchdog.cpp @@ -7,7 +7,9 @@ CWatchdog::~CWatchdog() { m_bExitThread = true; m_bNotified = true; m_cvWatchdogCondition.notify_all(); - m_pWatchdog.reset(); + + if (m_pWatchdog && m_pWatchdog->joinable()) + m_pWatchdog->join(); } CWatchdog::CWatchdog() { @@ -33,8 +35,6 @@ CWatchdog::CWatchdog() { m_bNotified = false; } }); - - m_pWatchdog->detach(); } void CWatchdog::startWatching() { diff --git a/src/render/Renderbuffer.cpp b/src/render/Renderbuffer.cpp index 694485c2..b55a921b 100644 --- a/src/render/Renderbuffer.cpp +++ b/src/render/Renderbuffer.cpp @@ -6,7 +6,7 @@ #include CRenderbuffer::~CRenderbuffer() { - if (!g_pCompositor) + if (!g_pCompositor || g_pCompositor->m_bIsShuttingDown || !g_pHyprRenderer) return; g_pHyprRenderer->makeEGLCurrent(); diff --git a/src/render/Texture.cpp b/src/render/Texture.cpp index 5560db97..46c501a0 100644 --- a/src/render/Texture.cpp +++ b/src/render/Texture.cpp @@ -9,7 +9,7 @@ CTexture::CTexture() { } CTexture::~CTexture() { - if (m_bNonOwning) + if (m_bNonOwning || !g_pCompositor || g_pCompositor->m_bIsShuttingDown || !g_pHyprRenderer) return; g_pHyprRenderer->makeEGLCurrent(); From d16c6aa1db52a0ee60ca1f53a9aa9ed1a2537ff2 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 29 Jun 2024 00:18:18 +0200 Subject: [PATCH 2/3] pointer-constraint: set lifetime correctly ref #6679 --- src/protocols/PointerConstraints.cpp | 8 ++++---- src/protocols/PointerConstraints.hpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/protocols/PointerConstraints.cpp b/src/protocols/PointerConstraints.cpp index a17fa6cd..fd15242d 100644 --- a/src/protocols/PointerConstraints.cpp +++ b/src/protocols/PointerConstraints.cpp @@ -7,8 +7,8 @@ #define LOGM PROTO::constraints->protoLog -CPointerConstraint::CPointerConstraint(SP resource_, SP surf, wl_resource* region_, zwpPointerConstraintsV1Lifetime lifetime) : - resourceL(resource_), locked(true) { +CPointerConstraint::CPointerConstraint(SP resource_, SP surf, wl_resource* region_, zwpPointerConstraintsV1Lifetime lifetime_) : + resourceL(resource_), locked(true), lifetime(lifetime_) { if (!resource_->resource()) return; @@ -46,8 +46,8 @@ CPointerConstraint::CPointerConstraint(SP resource_, SP resource_, SP surf, wl_resource* region_, zwpPointerConstraintsV1Lifetime lifetime) : - resourceC(resource_), locked(false) { +CPointerConstraint::CPointerConstraint(SP resource_, SP surf, wl_resource* region_, zwpPointerConstraintsV1Lifetime lifetime_) : + resourceC(resource_), locked(false), lifetime(lifetime_) { if (!resource_->resource()) return; diff --git a/src/protocols/PointerConstraints.hpp b/src/protocols/PointerConstraints.hpp index faf28b32..35d60632 100644 --- a/src/protocols/PointerConstraints.hpp +++ b/src/protocols/PointerConstraints.hpp @@ -16,8 +16,8 @@ class CWLSurfaceResource; class CPointerConstraint { public: - CPointerConstraint(SP resource_, SP surf, wl_resource* region, zwpPointerConstraintsV1Lifetime lifetime); - CPointerConstraint(SP resource_, SP surf, wl_resource* region, zwpPointerConstraintsV1Lifetime lifetime); + CPointerConstraint(SP resource_, SP surf, wl_resource* region, zwpPointerConstraintsV1Lifetime lifetime_); + CPointerConstraint(SP resource_, SP surf, wl_resource* region, zwpPointerConstraintsV1Lifetime lifetime_); ~CPointerConstraint(); bool good(); From 9c5dd59d4b1927b7d88e8e3c2e260eb01d95794b Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 29 Jun 2024 00:23:02 +0200 Subject: [PATCH 3/3] input: fix capabilities enum types passed hyprland down to the seat protocol impl expects IHID capabilities, not WL_ ones ref #6702 #6196 --- src/managers/input/InputManager.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 81a46f97..b3621520 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -1473,14 +1473,7 @@ void CInputManager::updateCapabilities() { if (h.expired()) continue; - auto cap = h->getCapabilities(); - - if (cap & HID_INPUT_CAPABILITY_KEYBOARD) - caps |= WL_SEAT_CAPABILITY_KEYBOARD; - if (cap & HID_INPUT_CAPABILITY_POINTER) - caps |= WL_SEAT_CAPABILITY_POINTER; - if (cap & HID_INPUT_CAPABILITY_TOUCH) - caps |= WL_SEAT_CAPABILITY_TOUCH; + caps |= h->getCapabilities(); } g_pSeatManager->updateCapabilities(caps);