Skip to content

Conversation

@bmastbergen
Copy link
Collaborator

Background

The original intent was to backport 9c53de76fa599 drm/gem: Acquire references on GEM handles for framebuffers to address CVE-2025-38449. This ended up requiring one prerequisite (7df34a6) and had one upstream bugfix (f6bfc9a). There are some differences from the upstream mostly because the original change uses guard(mutex) which this kernel does not have. The change to mutex_lock/mutex_unlock is straightforward though and noted in the upstream-diff sections.

Commits

    drm/gem-shmem: When drm_gem_object_init failed, should release object

    jira VULN-136707
    cve-pre CVE-2025-38449
    commit-author ChunyouTang <tangchunyou@163.com>
    commit 7df34a619f59439f38e56d389df02ee7e9e8cc97
    drm/gem: Acquire references on GEM handles for framebuffers

    jira VULN-136707
    cve CVE-2025-38449
    commit-author Thomas Zimmermann <tzimmermann@suse.de>
    commit 5307dce878d4126e1b375587318955bd019c3741
    upstream-diff Use mutex_lock/mutex_unlock in
                  drm_gem_object_handle_get_unlocked instead of
                  guard(mutex), which is not available in this
                  kernel
    drm/framebuffer: Acquire internal references on GEM handles

    jira VULN-136707
    cve-bf CVE-2025-38449
    commit-author Thomas Zimmermann <tzimmermann@suse.de>
    commit f6bfc9afc7510cb5e6fbe0a17c507917b0120280
    upstream-diff Minor conflict in drm_framebuffer.h due to different
                  fields being present in struct drm_framebuffer.
                  Also, add mutex_unlock in the new return path in
                  drm_gem_object_handle_get_if_exists_unlocked since
                  this version of the kernel is not using guard(mutex)

Build Log

  CLEAN   scripts/mod
  CLEAN   scripts/selinux/genheaders
  CLEAN   scripts/selinux/mdp
  CLEAN   scripts
  CLEAN   include/config include/generated arch/x86/include/generated .config .config.old .version Module.symvers certs/signing_key.pem certs/signing_key.x509 certs/x509.genkey
[TIMER]{MRPROPER}: 17s
x86_64 architecture detected, copying config
'configs/kernel-x86_64-rhel.config' -> '.config'
Setting Local Version for build
CONFIG_LOCALVERSION="-bmastbergen_ciqlts9_2_vuln-136707-60eb1cf93533"
Making olddefconfig
--
  HOSTCC  scripts/kconfig/util.o
  HOSTLD  scripts/kconfig/conf
#
# configuration written to .config
#
Starting Build
  SYSHDR  arch/x86/include/generated/uapi/asm/unistd_32.h
  SYSHDR  arch/x86/include/generated/uapi/asm/unistd_64.h
  SYSHDR  arch/x86/include/generated/uapi/asm/unistd_x32.h
  SYSTBL  arch/x86/include/generated/asm/syscalls_32.h
  SYSHDR  arch/x86/include/generated/asm/unistd_64_x32.h
--
  BTF [M] sound/usb/usx2y/snd-usb-usx2y.ko
  BTF [M] virt/lib/irqbypass.ko
  BTF [M] sound/virtio/virtio_snd.ko
  BTF [M] sound/x86/snd-hdmi-lpe-audio.ko
  BTF [M] sound/xen/snd_xen_front.ko
[TIMER]{BUILD}: 910s
Making Modules
  INSTALL /lib/modules/5.14.0-bmastbergen_ciqlts9_2_vuln-136707-60eb1cf93533+/kernel/arch/x86/crypto/blake2s-x86_64.ko
  INSTALL /lib/modules/5.14.0-bmastbergen_ciqlts9_2_vuln-136707-60eb1cf93533+/kernel/arch/x86/crypto/camellia-aesni-avx-x86_64.ko
  INSTALL /lib/modules/5.14.0-bmastbergen_ciqlts9_2_vuln-136707-60eb1cf93533+/kernel/arch/x86/crypto/blowfish-x86_64.ko
  INSTALL /lib/modules/5.14.0-bmastbergen_ciqlts9_2_vuln-136707-60eb1cf93533+/kernel/arch/x86/crypto/cast5-avx-x86_64.ko
--
  SIGN    /lib/modules/5.14.0-bmastbergen_ciqlts9_2_vuln-136707-60eb1cf93533+/kernel/sound/x86/snd-hdmi-lpe-audio.ko
  SIGN    /lib/modules/5.14.0-bmastbergen_ciqlts9_2_vuln-136707-60eb1cf93533+/kernel/sound/usb/usx2y/snd-usb-usx2y.ko
  SIGN    /lib/modules/5.14.0-bmastbergen_ciqlts9_2_vuln-136707-60eb1cf93533+/kernel/sound/virtio/virtio_snd.ko
  SIGN    /lib/modules/5.14.0-bmastbergen_ciqlts9_2_vuln-136707-60eb1cf93533+/kernel/sound/xen/snd_xen_front.ko
  DEPMOD  /lib/modules/5.14.0-bmastbergen_ciqlts9_2_vuln-136707-60eb1cf93533+
[TIMER]{MODULES}: 8s
Making Install
sh ./arch/x86/boot/install.sh \
	5.14.0-bmastbergen_ciqlts9_2_vuln-136707-60eb1cf93533+ arch/x86/boot/bzImage \
	System.map "/boot"
[TIMER]{INSTALL}: 56s
Checking kABI
kABI check passed
Setting Default Kernel to /boot/vmlinuz-5.14.0-bmastbergen_ciqlts9_2_vuln-136707-60eb1cf93533+ and Index to 2
Hopefully Grub2.0 took everything ... rebooting after time metrices
[TIMER]{MRPROPER}: 17s
[TIMER]{BUILD}: 910s
[TIMER]{MODULES}: 8s
[TIMER]{INSTALL}: 56s
[TIMER]{TOTAL} 1010s
Rebooting in 10 seconds

Testing

selftest-5.14.0-284.30.1.el9_2.92ciq_lts.12.1.x86_64-1.log

selftest-5.14.0-bmastbergen_ciqlts9_2_vuln-136707-60eb1cf93533+-1.log

brett@lycia ~/ciq/vuln-136707 % grep ^ok selftest-5.14.0-284.30.1.el9_2.92ciq_lts.12.1.x86_64-1.log | wc -l
330
brett@lycia ~/ciq/vuln-136707 % grep ^ok selftest-5.14.0-bmastbergen_ciqlts9_2_vuln-136707-60eb1cf93533+-1.log | wc -l
331
brett@lycia ~/ciq/vuln-136707 % grep ok <(diff -adU0 <(grep -a ^ok selftest-5.14.0-284.30.1.el9_2.92ciq_lts.12.1.x86_64-1.log | sort -h) <(grep -a ^ok selftest-5.14.0-bmastbergen_ciqlts9_2_vuln-136707-60eb1cf93533+-1.log | sort -h))
-ok 18 selftests: net: ip_defrag.sh
-ok 1 selftests: livepatch: test-livepatch.sh # SKIP
+ok 1 selftests: livepatch: test-livepatch.sh
-ok 1 selftests: zram: zram.sh # SKIP
+ok 1 selftests: zram: zram.sh
-ok 2 selftests: livepatch: test-callbacks.sh # SKIP
+ok 2 selftests: livepatch: test-callbacks.sh
+ok 32 selftests: net: l2tp.sh
-ok 3 selftests: livepatch: test-shadow-vars.sh # SKIP
+ok 3 selftests: livepatch: test-shadow-vars.sh
+ok 47 selftests: net: drop_monitor_tests.sh
-ok 4 selftests: livepatch: test-state.sh # SKIP
+ok 4 selftests: livepatch: test-state.sh
-ok 53 selftests: net: gro.sh
-ok 58 selftests: kvm: max_guest_memory_test
-ok 5 selftests: livepatch: test-ftrace.sh # SKIP
+ok 5 selftests: livepatch: test-ftrace.sh
+ok 6 selftests: net: tls
+ok 9 selftests: net: test_bpf.sh
brett@lycia ~/ciq/vuln-136707 %

jira VULN-136707
cve-pre CVE-2025-38449
commit-author ChunyouTang <tangchunyou@163.com>
commit 7df34a6

when goto err_free, the object had init, so it should be release when fail.

	Signed-off-by: ChunyouTang <tangchunyou@163.com>
	Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20221119064131.364-1-tangchunyou@163.com
(cherry picked from commit 7df34a6)
	Signed-off-by: Brett Mastbergen <bmastbergen@ciq.com>
jira VULN-136707
cve CVE-2025-38449
commit-author Thomas Zimmermann <tzimmermann@suse.de>
commit 5307dce
upstream-diff Use mutex_lock/mutex_unlock in
              drm_gem_object_handle_get_unlocked instead of
              guard(mutex), which is not available in this
              kernel

A GEM handle can be released while the GEM buffer object is attached
to a DRM framebuffer. This leads to the release of the dma-buf backing
the buffer object, if any. [1] Trying to use the framebuffer in further
mode-setting operations leads to a segmentation fault. Most easily
happens with driver that use shadow planes for vmap-ing the dma-buf
during a page flip. An example is shown below.

[  156.791968] ------------[ cut here ]------------
[  156.796830] WARNING: CPU: 2 PID: 2255 at drivers/dma-buf/dma-buf.c:1527 dma_buf_vmap+0x224/0x430
[...]
[  156.942028] RIP: 0010:dma_buf_vmap+0x224/0x430
[  157.043420] Call Trace:
[  157.045898]  <TASK>
[  157.048030]  ? show_trace_log_lvl+0x1af/0x2c0
[  157.052436]  ? show_trace_log_lvl+0x1af/0x2c0
[  157.056836]  ? show_trace_log_lvl+0x1af/0x2c0
[  157.061253]  ? drm_gem_shmem_vmap+0x74/0x710
[  157.065567]  ? dma_buf_vmap+0x224/0x430
[  157.069446]  ? __warn.cold+0x58/0xe4
[  157.073061]  ? dma_buf_vmap+0x224/0x430
[  157.077111]  ? report_bug+0x1dd/0x390
[  157.080842]  ? handle_bug+0x5e/0xa0
[  157.084389]  ? exc_invalid_op+0x14/0x50
[  157.088291]  ? asm_exc_invalid_op+0x16/0x20
[  157.092548]  ? dma_buf_vmap+0x224/0x430
[  157.096663]  ? dma_resv_get_singleton+0x6d/0x230
[  157.101341]  ? __pfx_dma_buf_vmap+0x10/0x10
[  157.105588]  ? __pfx_dma_resv_get_singleton+0x10/0x10
[  157.110697]  drm_gem_shmem_vmap+0x74/0x710
[  157.114866]  drm_gem_vmap+0xa9/0x1b0
[  157.118763]  drm_gem_vmap_unlocked+0x46/0xa0
[  157.123086]  drm_gem_fb_vmap+0xab/0x300
[  157.126979]  drm_atomic_helper_prepare_planes.part.0+0x487/0xb10
[  157.133032]  ? lockdep_init_map_type+0x19d/0x880
[  157.137701]  drm_atomic_helper_commit+0x13d/0x2e0
[  157.142671]  ? drm_atomic_nonblocking_commit+0xa0/0x180
[  157.147988]  drm_mode_atomic_ioctl+0x766/0xe40
[...]
[  157.346424] ---[ end trace 0000000000000000 ]---

Acquiring GEM handles for the framebuffer's GEM buffer objects prevents
this from happening. The framebuffer's cleanup later puts the handle
references.

Commit 1a148af ("drm/gem-shmem: Use dma_buf from GEM object
instance") triggers the segmentation fault easily by using the dma-buf
field more widely. The underlying issue with reference counting has
been present before.

v2:
- acquire the handle instead of the BO (Christian)
- fix comment style (Christian)
- drop the Fixes tag (Christian)
- rename err_ gotos
- add missing Link tag

	Suggested-by: Christian König <christian.koenig@amd.com>
	Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://elixir.bootlin.com/linux/v6.15/source/drivers/gpu/drm/drm_gem.c#L241 # [1]
	Cc: Thomas Zimmermann <tzimmermann@suse.de>
	Cc: Anusha Srivatsa <asrivats@redhat.com>
	Cc: Christian König <christian.koenig@amd.com>
	Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
	Cc: Maxime Ripard <mripard@kernel.org>
	Cc: Sumit Semwal <sumit.semwal@linaro.org>
	Cc: "Christian König" <christian.koenig@amd.com>
	Cc: linux-media@vger.kernel.org
	Cc: dri-devel@lists.freedesktop.org
	Cc: linaro-mm-sig@lists.linaro.org
	Cc: <stable@vger.kernel.org>
	Reviewed-by: Christian König <christian.koenig@amd.com>
Link: https://lore.kernel.org/r/20250630084001.293053-1-tzimmermann@suse.de
(cherry picked from commit 5307dce)
	Signed-off-by: Brett Mastbergen <bmastbergen@ciq.com>

squsah with acquire
@bmastbergen bmastbergen requested a review from a team October 21, 2025 20:51
Copy link
Collaborator

@kerneltoast kerneltoast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interdiff made this a lot easier (and faster) to review, which helped me spot the missing braces on the if-statement.

jira VULN-136707
cve-bf CVE-2025-38449
commit-author Thomas Zimmermann <tzimmermann@suse.de>
commit f6bfc9a
upstream-diff Minor conflict in drm_framebuffer.h due to different
              fields being present in struct drm_framebuffer.
              Also, add mutex_unlock in the new return path in
              drm_gem_object_handle_get_if_exists_unlocked since
              this version of the kernel is not using guard(mutex)

Acquire GEM handles in drm_framebuffer_init() and release them in
the corresponding drm_framebuffer_cleanup(). Ties the handle's
lifetime to the framebuffer. Not all GEM buffer objects have GEM
handles. If not set, no refcounting takes place. This is the case
for some fbdev emulation. This is not a problem as these GEM objects
do not use dma-bufs and drivers will not release them while fbdev
emulation is running. Framebuffer flags keep a bit per color plane
of which the framebuffer holds a GEM handle reference.

As all drivers use drm_framebuffer_init(), they will now all hold
dma-buf references as fixed in commit 5307dce ("drm/gem: Acquire
references on GEM handles for framebuffers").

In the GEM framebuffer helpers, restore the original ref counting
on buffer objects. As the helpers for handle refcounting are now
no longer called from outside the DRM core, unexport the symbols.

v3:
- don't mix internal flags with mode flags (Christian)
v2:
- track framebuffer handle refs by flag
- drop gma500 cleanup (Christian)

	Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Fixes: 5307dce ("drm/gem: Acquire references on GEM handles for framebuffers")
	Reported-by: Bert Karwatzki <spasswolf@web.de>
Closes: https://lore.kernel.org/dri-devel/20250703115915.3096-1-spasswolf@web.de/
	Tested-by: Bert Karwatzki <spasswolf@web.de>
	Tested-by: Mario Limonciello <superm1@kernel.org>
	Tested-by: Borislav Petkov (AMD) <bp@alien8.de>
	Cc: Thomas Zimmermann <tzimmermann@suse.de>
	Cc: Anusha Srivatsa <asrivats@redhat.com>
	Cc: Christian König <christian.koenig@amd.com>
	Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
	Cc: Maxime Ripard <mripard@kernel.org>
	Cc: Sumit Semwal <sumit.semwal@linaro.org>
	Cc: "Christian König" <christian.koenig@amd.com>
	Cc: linux-media@vger.kernel.org
	Cc: dri-devel@lists.freedesktop.org
	Cc: linaro-mm-sig@lists.linaro.org
	Cc: <stable@vger.kernel.org>
	Reviewed-by: Christian König <christian.koenig@amd.com>
Link: https://lore.kernel.org/r/20250707131224.249496-1-tzimmermann@suse.de
(cherry picked from commit f6bfc9a)
	Signed-off-by: Brett Mastbergen <bmastbergen@ciq.com>
@bmastbergen bmastbergen force-pushed the bmastbergen_ciqlts9_2/vuln-136707 branch from 60eb1cf to 3bf6994 Compare October 22, 2025 13:37
@bmastbergen
Copy link
Collaborator Author

Added braces! Moved internal_flags. Thanks reviewers!

@PlaidCat PlaidCat requested review from a team and PlaidCat October 23, 2025 15:50
Copy link
Collaborator

@kerneltoast kerneltoast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢

Copy link
Collaborator

@PlaidCat PlaidCat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@bmastbergen bmastbergen merged commit 6d1b009 into ciqlts9_2 Oct 24, 2025
4 checks passed
@bmastbergen bmastbergen deleted the bmastbergen_ciqlts9_2/vuln-136707 branch October 24, 2025 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants