From: Sunday Clement <Sunday.Clement@amd.com>
To: <amd-gfx@lists.freedesktop.org>
Cc: <Sunday.Clement@amd.com>, <Flora.Cui@amd.com>,
<Russell.Kent@amd.com>, Sunday Clement <sunday.clement@amd.com>
Subject: [PATCH] drm/amd/dkms: Fix TOCTOU symlink race in build directory creation
Date: Tue, 28 Jul 2026 16:45:13 -0400 [thread overview]
Message-ID: <20260728204513.5589-1-Sunday.Clement@amd.com> (raw)
The DKMS Makefile used mktemp -u to generate a temporary directory name
without atomically creating it, then root-privileged pre-build.sh later
created a symlink at that path. A local unprivileged attacker could race
to create a malicious symlink at the predicted path between name
generation and actual use, redirecting root file writes or rm -rf
cleanup to arbitrary paths. This attack recurs on every DKMS rebuild
during kernel updates.
Fix by replacing mktemp -ut with mktemp -dt to atomically create the
directory with mode 0700. Update pre-build.sh to remove the directory
and recreate as symlink.
Signed-off-by: Sunday Clement <sunday.clement@amd.com>
---
drivers/gpu/drm/amd/dkms/Makefile | 2 +-
drivers/gpu/drm/amd/dkms/pre-build.sh | 4 ++++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/amd/dkms/Makefile b/drivers/gpu/drm/amd/dkms/Makefile
index 8112b9746c8f..02eea52ae0e7 100644
--- a/drivers/gpu/drm/amd/dkms/Makefile
+++ b/drivers/gpu/drm/amd/dkms/Makefile
@@ -4,7 +4,7 @@ else
KERNELVER ?= $(shell uname -r)
kernel_build_dir := /lib/modules/$(KERNELVER)/build
module_src_dir := $(CURDIR)
-module_build_dir := $(shell mktemp -ut amd.XXXXXXXX)
+module_build_dir := $(shell mktemp -dt amd.XXXXXXXX)
module_build_flags :=
num_cpu_cores := $(shell which nproc > /dev/null && nproc || echo "1")
CC := gcc
diff --git a/drivers/gpu/drm/amd/dkms/pre-build.sh b/drivers/gpu/drm/amd/dkms/pre-build.sh
index 66f7177b6cf9..24f5a13ad854 100755
--- a/drivers/gpu/drm/amd/dkms/pre-build.sh
+++ b/drivers/gpu/drm/amd/dkms/pre-build.sh
@@ -100,6 +100,10 @@ if version_lt 6.0; then
fi
export KERNELVER
+# Security: MODULE_BUILD_DIR is now atomically created by mktemp -d (mode 0700)
+# to eliminate TOCTOU symlink race. We need MODULE_BUILD_DIR to be
+# a symlink to DKMS_TREE, so remove the directory and recreate as symlink.
+rmdir $MODULE_BUILD_DIR
ln -s $DKMS_TREE $MODULE_BUILD_DIR
echo "PATH=$PATH" >$MODULE_BUILD_DIR/.env
--
2.43.0
reply other threads:[~2026-07-28 20:45 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260728204513.5589-1-Sunday.Clement@amd.com \
--to=sunday.clement@amd.com \
--cc=Flora.Cui@amd.com \
--cc=Russell.Kent@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox