** Description changed:

  [ Impact ]
  
  A screen cast of a virtual monitor whose height is not a multiple of the
  monitor scale writes past the end of the negotiated PipeWire buffer on
  every frame. gnome-shell can crash with SIGSEGV (or corrupt memory) when
  the overflow reaches an unmapped page. Remote-desktop servers that size a
  virtual monitor from the remote client are typically affected.
  
  The fix paints into an offscreen framebuffer of the buffer's own size and
  reads back exactly the negotiated width and height.
  
  [ Test Plan ]
  
  Prerequisites:
   * Run the commands below as root.
   * Ubuntu 26.04 with GNOME on Wayland (a headless gnome-shell is enough).
   * Packages: python3-gi, gstreamer1.0-tools, gstreamer1.0-pipewire.
   * The reproducer attached to this bug as repro-virtual-odd-height.py.
  
  1. Create a scratch user and enable lingering. This starts the user
     manager and keeps it alive between the commands below:
  
       useradd -m repro-test
       loginctl enable-linger repro-test
  
  2. Save the attached repro-virtual-odd-height.py as
     /tmp/repro-virtual-odd-height.py.
  
  3. Set scale 2 and start a headless gnome-shell in the scratch user's
     user manager:
  
       systemd-run --user --machine=repro-test@ --wait --pipe --collect \
         gsettings set org.gnome.desktop.interface scaling-factor 2
  
       systemd-run --user --machine=repro-test@ \
         --unit=repro-shell --collect \
         --setenv=XDG_SESSION_TYPE=wayland \
         --setenv=MUTTER_DEBUG=screen-cast \
         gnome-shell --wayland --headless --no-x11 --virtual-monitor 1280x720
       sleep 12
  
  4. Run the reproducer:
  
       systemd-run --user --machine=repro-test@ --wait --pipe --collect \
         python3 /tmp/repro-virtual-odd-height.py 1800 951
  
     The script runs six 10-second casts by default. Each cast creates a
     virtual monitor through org.gnome.Mutter.ScreenCast.RecordVirtual,
     pulls WIDTH x HEIGHT frames with gst-launch-1.0 pipewiresrc, and moves
     the pointer over the monitor through org.gnome.Mutter.RemoteDesktop so
     frames keep being recorded.
  
     With the fix it prints "PASS: gnome-shell survived 6 casts".
     Without the fix it prints "FAIL: gnome-shell went away during cast N"
     and the journal shows a gnome-shell SIGSEGV in the GL driver (or, if
     the overflow lands in mapped memory, silent corruption). A single cast
     overruns on every frame but does not always fault, which is why the
     script repeats the cast.
  
     The fixed code only runs for casts without dma-buf. Check that the
     casts used shared memory:
  
       journalctl _UID=$(id -u repro-test) --since "5 min ago" \
         | grep -E "Allocating (MemFd|DMA) buffer"
  
     Only "Allocating MemFd buffer" lines must be shown.
  
  5. Repeat for the remaining sizes/scales (step 4 already covers 1800x951
     at scale 2). For each scale:
     a. stop the shell (if it crashed, this may report that the unit is not
        loaded; that is expected):
          systemd-run --user --machine=repro-test@ --wait --pipe --collect \
            systemctl --user stop repro-shell
     b. set the new scale:
          systemd-run --user --machine=repro-test@ --wait --pipe --collect \
            gsettings set org.gnome.desktop.interface scaling-factor N
     c. start the shell again (same command as step 3) and wait 12 s.
     d. run the reproducer with the new size (same command as step 4).
  
     Cases:
       scale 2: 1800x951 (already run in step 4; fails without the fix)
                1800x950 (control, passes)
       scale 3: 1800x950 (fails without the fix)
       scale 4: 1800x950 (fails without the fix)
       scale 1: 1800x951 (control, passes)
  
  6. Regression checks: with the fix, a normal monitor cast
     (--monitor CONNECTOR) and an area cast with any portal client still
     deliver complete frames, with and without dma-buf; a fullscreen window
-    still uses direct scanout when nothing is being cast. On real hardware,
-    switching the monitor from 3840x2160 at 200% to 1920x1080 at 100% (and
-    back) while a monitor cast without dma-buf is running still delivers
-    the full screen at the new size, without cropping or garbage.
+    still uses direct scanout when nothing is being cast.
  
  7. Cleanup:
  
       loginctl disable-linger repro-test
       userdel -r repro-test
  
     If userdel reports that the user is still in use, run
     `loginctl terminate-user repro-test` first.
  
  [ Where problems could occur ]
  
  The change is in the screen-cast record-to-buffer path, used by virtual,
  monitor and area casts without dma-buf. A regression could show up as
  corrupt or incomplete casts, wrong colours, or a crash in the record
  path. Test virtual, monitor, and area casts, including dma-buf consumers.

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2174817

Title:
  gnome-shell crashes when a virtual-monitor screen cast's size isn't a
  multiple of the scale

To manage notifications about this bug go to:
https://bugs.launchpad.net/mutter/+bug/2174817/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to