<div dir="ltr"><div class="gmail_quote" style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">Hey Adam,</div><div class="gmail_quote" style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><br></div><div class="gmail_quote" style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">On 22 January 2018 at 19:57, Adam Jackson<span> </span><span dir="ltr"><<a href="mailto:ajax@nwnk.net" target="_blank" style="color:rgb(17,85,204)">ajax@nwnk.net</a>></span><span> </span>wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span>On Thu, 2018-01-18 at 11:41 +0100, Olivier Fourdan wrote:<br>> This is a rare occurrence of a crash in Xwayland for which I don't have<br>> the reproducing steps, just a core file.<br>><br>> The backtrace looks as follow:<br>><br>>  [...]<br>><br>> The crash is caused by dereferencing “xwl_pixmap->buffer” in<br>> xwl_glamor_pixmap_get_wl_buffe<wbr>r() because “xwl_pixmap” is NULL.<br>><br>> Reason for this is because the corresponding pixmap has a size of 0×0<br>> and no xwl_pixmap is created for pixmaps of size 0×0.<br><br></span>That can't really be the problem. X drawables are never 0x0.<br></blockquote><div><br></div><div>Yeap, I don't know how we end with a pximap of size <span>0×0:</span></div><div><span><br></span></div><div><div>(gdb) bt</div><div>#0  0x00007f00239a31a7 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56</div><div>#1  0x00007f00239a4898 in __GI_abort () at abort.c:90</div><div>#2  0x000000000058f1da in OsAbort () at utils.c:1361</div><div>#3  0x0000000000594ce3 in AbortServer () at log.c:877</div><div>#4  0x0000000000595b2d in FatalError (f=f@entry=0x5b7490 "Caught signal %d (%s). Server aborting\n") at log.c:1015</div><div>#5  0x000000000058c43c in OsSigHandler (signo=11, sip=<optimized out>, unused=<optimized out>) at osinit.c:154</div><div>#6  <signal handler called></div><div>#7  xwl_glamor_pixmap_get_wl_buffer (pixmap=pixmap@entry=0x1e5b6f0) at xwayland-glamor.c:162</div><div>#8  0x0000000000424da5 in xwl_screen_post_damage (xwl_screen=0x161d750) at xwayland.c:514</div><div>#9  block_handler (data=0x161d750, timeout=<optimized out>) at xwayland.c:665</div><div>#10 0x0000000000557e46 in BlockHandler (pTimeout=pTimeout@entry=0x7ffeb514bf54) at dixutils.c:388</div><div>#11 0x0000000000585ed9 in WaitForSomething (are_ready=0) at WaitFor.c:219</div><div>#12 0x00000000005531e1 in Dispatch () at dispatch.c:422</div><div>#13 0x000000000055744a in dix_main (argc=11, argv=0x7ffeb514c138, envp=<optimized out>) at main.c:287</div><div>#14 0x00007f002398f377 in __libc_start_main (main=0x4240d0 <main>, argc=11, ubp_av=0x7ffeb514c138, init=<optimized out>, fini=<optimized out>, </div><div>    rtld_fini=<optimized out>, stack_end=0x7ffeb514c128) at ../csu/libc-start.c:274</div><div>#15 0x00000000004240fe in _start ()</div><div><br></div><div>(gdb) f 7</div><div>#7  xwl_glamor_pixmap_get_wl_buffer (pixmap=pixmap@entry=0x1e5b6f0) at xwayland-glamor.c:162</div><div>162<span style="white-space:pre"> </span>    if (xwl_pixmap->buffer)</div><div><br></div><div>(gdb) p *pixmap</div><div>$1 = {drawable = {type = 1 '\001', class = 0 '\000', depth = 24 '\030', bitsPerPixel = 32 ' ', id = 0, x = 0, y = 0, width = 0, height = 0, </div><div>    pScreen = 0x161d200, serialNumber = 1}, devPrivates = 0x1e5b738, refcnt = 1, devKind = 0, devPrivate = {ptr = 0x1e5b7c0, val = 31832000, </div><div>    uval = 31832000, fptr = 0x1e5b7c0}, screen_x = 0, screen_y = 0, usage_hint = 0, master_pixmap = 0x0}</div></div><div><br></div><div>How we end up here is unclear though, xwl_pixmap is “optimized out” but considering it's a segfault I assume it's NULL.</div><div><br></div><div>If we also assume the pixmap was of size <span>0×0 when xwl_glamor_create_pixmap() was called, then we wouldn't be calling xwl_glamor_create_pixmap_for_bo() which would not call xwl_pixmap_set_private():</span></div><div><span><br></span></div><div><span>  <a href="https://cgit.freedesktop.org/xorg/xserver/tree/hw/xwayland/xwayland-glamor.c#n183">https://cgit.freedesktop.org/xorg/xserver/tree/hw/xwayland/xwayland-glamor.c#n183</a><br></span></div><div><br></div><div>Instead we would call glamor_create_pixmap() which invokes fbCreatePixmap() for pixmaps of size <span>0×0:</span></div><div><span><br></span></div><div><span>  <a href="https://cgit.freedesktop.org/xorg/xserver/tree/glamor/glamor.c#n180">https://cgit.freedesktop.org/xorg/xserver/tree/glamor/glamor.c#n180</a><br></span></div><div><span><br></span></div><div><span>And the values found in the core file match what is set for by </span><span>fbCreatePixmap():</span></div><div><span><br></span></div><div><span> <a href="https://cgit.freedesktop.org/xorg/xserver/tree/fb/fbpixmap.c#n31">https://cgit.freedesktop.org/xorg/xserver/tree/fb/fbpixmap.c#n31</a><br> </span></div><div><br></div><div>So that matches.<br></div><div><br></div><div>Also that doesn't look like a use after free (As Daniel said), because the pixmap has a refcnt =1 and also because on unrealize, we delete the list, destroy the damage and remove the callback (where the crash occurs):</div><div><br></div><div>  <a href="https://cgit.freedesktop.org/xorg/xserver/tree/hw/xwayland/xwayland.c#n577">https://cgit.freedesktop.org/xorg/xserver/tree/hw/xwayland/xwayland.c#n577</a><br></div><div><br></div><div>The pixmap in question comes from GetWindowPixmap():</div><div><br></div><div>  <a href="https://cgit.freedesktop.org/xorg/xserver/tree/hw/xwayland/xwayland.c#n637">https://cgit.freedesktop.org/xorg/xserver/tree/hw/xwayland/xwayland.c#n637</a><br></div><div><br></div><div>In our case, _fbGetWindowPixmap():</div><div><br></div><div><div>(gdb) p xwl_screen->screen->GetWindowPixmap</div><div>$2 = (GetWindowPixmapProcPtr) 0x4520d0 <_fbGetWindowPixmap></div></div><div><br></div><div>Considering that the corresponding SetWindowPixmap is damageSetWindowPixmap... I have no idea how we can end up with a pixmap of size 0×0...</div><div><br></div><div>Cheers,</div><div>Olivier</div></div></div>