<table><tr><td style="">davidedmundson created this revision.<br />davidedmundson added a reviewer: Plasma.<br />Restricted Application added projects: Plasma on Wayland, Frameworks.<br />Restricted Application added subscribers: Frameworks, plasma-devel.
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D7870" rel="noreferrer">View Revision</a></tr></table><br /><div><strong>REVISION SUMMARY</strong><div><p>There is a race condition in the following situation:</p>

<ul class="remarkup-list">
<li class="remarkup-list-item">Server creates a global</li>
<li class="remarkup-list-item">Client binds to that global (making a new resource for that global)</li>
</ul>

<p>Simultaneously:</p>

<ul class="remarkup-list">
<li class="remarkup-list-item">The client uses this resource</li>
<li class="remarkup-list-item">The server deletes the global</li>
</ul>

<p>We then process an event for a resource linked to a deleted global.</p>

<p>This is noted in the specification, the client documentation says:<br />
"The object remains valid and requests to the object will be<br />
ignored until the client destroys it, to avoid races between the global<br />
going away and a client sending a request to it. "</p>

<p>KWayland does not handle this at all.</p>

<p>The global's user data refer to our C++ wrapper<br />
The resource's user data refer to *the same* C++ wrapper</p>

<p>When the global is deleted the resource user data now refers to garbage.</p>

<p>To fix the issue, instead of setting the resource userdata to the<br />
global, we set it to a smartpointer to the global stored on the heap.</p>

<p>We can then validate if our global is still valid.</p>

<p>Theoretically this applies to every global</p>

<p>Practically there are only 3 globals that don't have the lifespan of the<br />
server. Output (which is read only and doesn't matter), Blur and<br />
BackgroundContrast.</p>

<p>Blur resets it's global when a screen geometry changes.</p>

<p>Unfotunately this exactly at the same time that Plasmashell is <br />
doing a lot of processing and creating some blurs.</p></div></div><br /><div><strong>TEST PLAN</strong><div><p>See unit test</p></div></div><br /><div><strong>REPOSITORY</strong><div><div>R127 KWayland</div></div></div><br /><div><strong>BRANCH</strong><div><div>globalref</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D7870" rel="noreferrer">https://phabricator.kde.org/D7870</a></div></div><br /><div><strong>AFFECTED FILES</strong><div><div>autotests/client/test_wayland_registry.cpp<br />
src/server/blur_interface.cpp</div></div></div><br /><div><strong>To: </strong>davidedmundson, Plasma<br /><strong>Cc: </strong>plasma-devel, Frameworks, leezu, ZrenBot, alexeymin, progwolff, lesliezhai, ali-mohamed, jensreuterberg, abetts, eliasp, sebas, apol, mart, hein<br /></div>