drm/amdgpu: block the register writing if security lockdown
Subsystems (2)
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.
Signed-off-by Shiwu Zhang <[email protected]>
--- drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +19 -0
@@ -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 __userssize_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 __usessize_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 __userssize_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
AMD General
Reviewed-by Hawking Zhang <[email protected]>
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.
Signed-off-by Shiwu Zhang <[email protected]>
--- drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +19 -0
@@ -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 __userssize_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 __usessize_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 __userssize_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