Skip to contentSkip to conversation

drm/amdgpu: block the register writing if security lockdown

PATCH In review Shiwu Zhang 2 participants 2 messages May 28 – May 29

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: block the register writing if security lockdown

In case of security lockdown with integrity, prevent the root from changing kernel/firmware state by register writing to comply with the LSM security requirement.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +19 -0
index 0ce6e2e4342c..3f9e5020722e 100644
@@ -27,6 +27,7 @@
 #include <linux/pci.h>
 #include <linux/uaccess.h>
 #include <linux/pm_runtime.h>
+#include <linux/security.h>
 
 #include "amdgpu.h"
 #include "amdgpu_pm.h"
@@ -200,6 +201,9 @@ static ssize_t amdgpu_debugfs_regs_read(struct file *f, char __user *buf,
 static ssize_t amdgpu_debugfs_regs_write(struct file *f, const char __user *buf,
 					 size_t size, loff_t *pos)
 {
+	if (security_locked_down(LOCKDOWN_DEBUGFS))
+		return -EPERM;
+
 	return amdgpu_debugfs_process_reg_op(false, f, (char __user *)buf, size, pos);
 }
 
@@ -365,6 +369,9 @@ static ssize_t amdgpu_debugfs_regs2_read(struct file *f, char __user *buf, size_
 
 static ssize_t amdgpu_debugfs_regs2_write(struct file *f, const char __user *buf, size_t size, loff_t *pos)
 {
+	if (security_locked_down(LOCKDOWN_DEBUGFS))
+		return -EPERM;
+
 	return amdgpu_debugfs_regs2_op(f, (char __user *)buf, *pos, size, 1);
 }
 
@@ -577,6 +584,9 @@ static ssize_t amdgpu_debugfs_regs_pcie_write(struct file *f, const char __user
 	ssize_t result = 0;
 	int r;
 
+	if (security_locked_down(LOCKDOWN_DEBUGFS))
+		return -EPERM;
+
 	if (size & 0x3 || *pos & 0x3)
 		return -EINVAL;
 
@@ -684,6 +694,9 @@ static ssize_t amdgpu_debugfs_regs_pcie64_write(struct file *f, const char __use
 	ssize_t result = 0;
 	int r;
 
+	if (security_locked_down(LOCKDOWN_DEBUGFS))
+		return -EPERM;
+
 	if (size & 0x7 || *pos & 0x7)
 		return -EINVAL;
 
@@ -798,6 +811,9 @@ static ssize_t amdgpu_debugfs_regs_didt_write(struct file *f, const char __user
 	ssize_t result = 0;
 	int r;
 
+	if (security_locked_down(LOCKDOWN_DEBUGFS))
+		return -EPERM;
+
 	if (size & 0x3 || *pos & 0x3)
 		return -EINVAL;
 
@@ -915,6 +931,9 @@ static ssize_t amdgpu_debugfs_regs_smc_write(struct file *f, const char __user *
 	ssize_t result = 0;
 	int r;
 
+	if (security_locked_down(LOCKDOWN_DEBUGFS))
+		return -EPERM;
+
 	if (!adev->reg.smc.wreg)
 		return -EOPNOTSUPP;
 
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw

AMD General

Regards,
Hawking
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Shiwu Zhang
Sent: Thursday, May 28, 2026 3:10 PM
To: [email protected]
Subject: [PATCH] drm/amdgpu: block the register writing if security lockdown

In case of security lockdown with integrity, prevent the root from changing kernel/firmware state by register writing to comply with the LSM security requirement.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +19 -0
index 0ce6e2e4342c..3f9e5020722e 100644
@@ -27,6 +27,7 @@
 #include <linux/pci.h>
 #include <linux/uaccess.h>
 #include <linux/pm_runtime.h>
+#include <linux/security.h>
 
 #include "amdgpu.h"
 #include "amdgpu_pm.h"
@@ -200,6 +201,9 @@ static ssize_t amdgpu_debugfs_regs_read(struct file *f, char __user *buf,  static ssize_t amdgpu_debugfs_regs_write(struct file *f, const char __user *buf,
                                         size_t size, loff_t *pos)
 {
+       if (security_locked_down(LOCKDOWN_DEBUGFS))
+               return -EPERM;
+
        return amdgpu_debugfs_process_reg_op(false, f, (char __user *)buf, size, pos);  }
 
@@ -365,6 +369,9 @@ static ssize_t amdgpu_debugfs_regs2_read(struct file *f, char __user *buf, size_
 
 static ssize_t amdgpu_debugfs_regs2_write(struct file *f, const char __user *buf, size_t size, loff_t *pos)  {
+       if (security_locked_down(LOCKDOWN_DEBUGFS))
+               return -EPERM;
+
        return amdgpu_debugfs_regs2_op(f, (char __user *)buf, *pos, size, 1);  }
 
@@ -577,6 +584,9 @@ static ssize_t amdgpu_debugfs_regs_pcie_write(struct file *f, const char __user
        ssize_t result = 0;
        int r;
 
+       if (security_locked_down(LOCKDOWN_DEBUGFS))
+               return -EPERM;
+
        if (size & 0x3 || *pos & 0x3)
                return -EINVAL;
 
@@ -684,6 +694,9 @@ static ssize_t amdgpu_debugfs_regs_pcie64_write(struct file *f, const char __use
        ssize_t result = 0;
        int r;
 
+       if (security_locked_down(LOCKDOWN_DEBUGFS))
+               return -EPERM;
+
        if (size & 0x7 || *pos & 0x7)
                return -EINVAL;
 
@@ -798,6 +811,9 @@ static ssize_t amdgpu_debugfs_regs_didt_write(struct file *f, const char __user
        ssize_t result = 0;
        int r;
 
+       if (security_locked_down(LOCKDOWN_DEBUGFS))
+               return -EPERM;
+
        if (size & 0x3 || *pos & 0x3)
                return -EINVAL;
 
@@ -915,6 +931,9 @@ static ssize_t amdgpu_debugfs_regs_smc_write(struct file *f, const char __user *
        ssize_t result = 0;
        int r;
 
+       if (security_locked_down(LOCKDOWN_DEBUGFS))
+               return -EPERM;
+
        if (!adev->reg.smc.wreg)
                return -EOPNOTSUPP;
 

--
2.43.0