Skip to contentSkip to conversation

drm/amdgpu: Prevent debugfs nullptr dereference

PATCH In review Amadeusz Sławiński 2 participants 3 messages Oct 27 – Oct 29

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

PATCH 1/2 drm/amdgpu: Prevent debugfs nullptr dereference

Running
cat /sys/kernel/debug/dri/0/psp_spirom_dump
with amdgpu card that doesn't support it leads to nullptr dereference. Add checks to prevent that.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 6 ++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +6 -0
index 82a2684dbd2e..627c74f16914 100644
@@ -5381,6 +5381,9 @@ static int psp_read_spirom_debugfs_open(struct inode *inode, struct file *filp)
 	struct spirom_bo *bo_triplet;
 	int ret;
 
+	if (!adev->psp.funcs || !adev->psp.funcs->dump_spirom)
+		return -EOPNOTSUPP;
+
 	/* serialize the open() file calling */
 	if (!mutex_trylock(&adev->psp.mutex))
 		return -EBUSY;
@@ -5473,6 +5476,9 @@ void amdgpu_psp_debugfs_init(struct amdgpu_device *adev)
 #if defined(CONFIG_DEBUG_FS)
 	struct drm_minor *minor = adev_to_drm(adev)->primary;
 
+	if (!adev->psp.funcs || !adev->psp.funcs->dump_spirom)
+		return;
+
 	debugfs_create_file_size("psp_spirom_dump", 0444, minor->debugfs_root,
 				 adev, &psp_dump_spirom_debugfs_ops, AMD_VBIOS_FILE_MAX_SIZE_B * 2);
 #endif
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +1 -1
index a4ec60f6c317..975d12359358 100644
@@ -574,7 +574,7 @@ struct amdgpu_psp_funcs {
 	(psp)->funcs->update_spirom((psp), fw_pri_mc_addr) : -EINVAL)
 
 #define psp_dump_spirom(psp, fw_pri_mc_addr) \
-	((psp)->funcs->dump_spirom ? \
+	(((psp)->funcs && (psp)->funcs->dump_spirom) ? \
 	(psp)->funcs->dump_spirom((psp), fw_pri_mc_addr) : -EINVAL)
 
 #define psp_vbflash_status(psp) \

base-commit: 83f32c773255720a661aa45d83e36278135f23f5

Signature · 1 line
2.56.0
#1 lore raw

PATCH 2/2 drm/amd/display: Prevent debugfs nullptr dereference

Running
cat /sys/kernel/debug/dri/0/amdgpu_dm_dmub_trace_mask
with amdgpu card that doesn't support it leads to nullptr dereference. Add checks to prevent that.

---
 .../amd/display/amdgpu_dm/amdgpu_dm_debugfs.c | 20 +++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c +16 -4
index 36f32ed4b87c..3621da877efa 100644
@@ -3558,14 +3558,20 @@ static int disallow_edp_enter_replay_set(void *data, u64 val)
 static int dmub_trace_mask_set(void *data, u64 val)
 {
 	struct amdgpu_device *adev = data;
-	struct dmub_srv *srv = adev->dm.dc->ctx->dmub_srv->dmub;
+	struct dc_dmub_srv *dc_dmub_srv;
+	struct dmub_srv *srv;
 	enum dmub_gpint_command cmd;
 	u64 mask = 0xffff;
 	u8 shift = 0;
 	u32 res;
 	int i;
 
-	if (!srv->fw_version)
+	if (!adev->dm.dc || !adev->dm.dc->ctx || !adev->dm.dc->ctx->dmub_srv)
+		return -EINVAL;
+
+	dc_dmub_srv = adev->dm.dc->ctx->dmub_srv;
+	srv = dc_dmub_srv->dmub;
+	if (!srv || !srv->fw_version)
 		return -EINVAL;
 
 	for (i = 0;  i < 4; i++) {
@@ -3602,13 +3608,19 @@ static int dmub_trace_mask_show(void *data, u64 *val)
 {
 	enum dmub_gpint_command cmd = DMUB_GPINT__GET_TRACE_BUFFER_MASK_WORD0;
 	struct amdgpu_device *adev = data;
-	struct dmub_srv *srv = adev->dm.dc->ctx->dmub_srv->dmub;
+	struct dc_dmub_srv *dc_dmub_srv;
+	struct dmub_srv *srv;
 	u8 shift = 0;
 	u64 raw = 0;
 	u64 res = 0;
 	int i = 0;
 
-	if (!srv->fw_version)
+	if (!adev->dm.dc || !adev->dm.dc->ctx || !adev->dm.dc->ctx->dmub_srv)
+		return -EINVAL;
+
+	dc_dmub_srv = adev->dm.dc->ctx->dmub_srv;
+	srv = dc_dmub_srv->dmub;
+	if (!srv || !srv->fw_version)
 		return -EINVAL;
 
 	while (i < 4) {
Signature · 1 line
2.56.0
#2 lore raw
In reply to Amadeusz Sławiński

Reviewed and applied the series.

Thanks!

Alex

Quoted 54 lines · Amadeusz Sławiński

Running
cat /sys/kernel/debug/dri/0/psp_spirom_dump
with amdgpu card that doesn't support it leads to nullptr dereference. Add checks to prevent that.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 6 ++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +6 -0
index 82a2684dbd2e..627c74f16914 100644
@@ -5381,6 +5381,9 @@ static int psp_read_spirom_debugfs_open(struct inode *inode, struct file *filp)
        struct spirom_bo *bo_triplet;
        int ret;
 
+       if (!adev->psp.funcs || !adev->psp.funcs->dump_spirom)
+               return -EOPNOTSUPP;
+
        /* serialize the open() file calling */
        if (!mutex_trylock(&adev->psp.mutex))
                return -EBUSY;
@@ -5473,6 +5476,9 @@ void amdgpu_psp_debugfs_init(struct amdgpu_device *adev)
 #if defined(CONFIG_DEBUG_FS)
        struct drm_minor *minor = adev_to_drm(adev)->primary;
 
+       if (!adev->psp.funcs || !adev->psp.funcs->dump_spirom)
+               return;
+
        debugfs_create_file_size("psp_spirom_dump", 0444, minor->debugfs_root,
                                 adev, &psp_dump_spirom_debugfs_ops, AMD_VBIOS_FILE_MAX_SIZE_B * 2);
 #endif
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +1 -1
index a4ec60f6c317..975d12359358 100644
@@ -574,7 +574,7 @@ struct amdgpu_psp_funcs {
        (psp)->funcs->update_spirom((psp), fw_pri_mc_addr) : -EINVAL)
 
 #define psp_dump_spirom(psp, fw_pri_mc_addr) \
-       ((psp)->funcs->dump_spirom ? \
+       (((psp)->funcs && (psp)->funcs->dump_spirom) ? \
        (psp)->funcs->dump_spirom((psp), fw_pri_mc_addr) : -EINVAL)
 
 #define psp_vbflash_status(psp) \

base-commit: 83f32c773255720a661aa45d83e36278135f23f5 --
2.56.0