Skip to contentSkip to conversation

drm/amd: Make sure image is written to trigger VBIOS image update flow

PATCH In review Mario Limonciello 1 participant 3 messages Jun 7, 2023 – Jun 8, 2023

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

PATCH 1/2 drm/amd: Make sure image is written to trigger VBIOS image update flow

The VBIOS image update flow requires userspace to:
1) Write the image to psp_vbflash
2) Read psp_vbflash
3) Poll psp_vbflash_status to check for completion

If userspace reads psp_vbflash before writing an image, it's possible that it causes problems that can put the dGPU into an invalid state.

Explicitly check that an image has been written before letting a read succeed.

Fixes 8424f2ccb3c0 ("drm/amdgpu/psp: Add vbflash sysfs interface support")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +3 -0
index 27559a05a67b..8c60db176119 100644
@@ -3617,6 +3617,9 @@ static ssize_t amdgpu_psp_vbflash_read(struct file *filp, struct kobject *kobj,
 	void *fw_pri_cpu_addr;
 	int ret;
 
+	if (adev->psp.vbflash_image_size == 0)
+		return -EINVAL;
+
 	dev_info(adev->dev, "VBIOS flash to PSP started");
 
 	ret = amdgpu_bo_create_kernel(adev, adev->psp.vbflash_image_size,
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/2 drm/amd: Tighten permissions on VBIOS flashing attributes

Non-root users shouldn't be able to try to trigger a VBIOS flash or query the flashing status. This should be reserved for users with the appropriate permissions.

Fixes 8424f2ccb3c0 ("drm/amdgpu/psp: Add vbflash sysfs interface support")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +2 -2
index 8c60db176119..488d5b7ab97c 100644
@@ -3671,13 +3671,13 @@ static ssize_t amdgpu_psp_vbflash_status(struct device *dev,
 }
 
 static const struct bin_attribute psp_vbflash_bin_attr = {
-	.attr = {.name = "psp_vbflash", .mode = 0664},
+	.attr = {.name = "psp_vbflash", .mode = 0220},
 	.size = 0,
 	.write = amdgpu_psp_vbflash_write,
 	.read = amdgpu_psp_vbflash_read,
 };
 
-static DEVICE_ATTR(psp_vbflash_status, 0444, amdgpu_psp_vbflash_status, NULL);
+static DEVICE_ATTR(psp_vbflash_status, 0440, amdgpu_psp_vbflash_status, NULL);
 
 int amdgpu_psp_sysfs_init(struct amdgpu_device *adev)
 {
Signature · 1 line
2.34.1
#2 lore raw

RE: [PATCH 2/2] drm/amd: Tighten permissions on VBIOS flashing attributes

[AMD Official Use Only - General]

Quoted 26 lines

-----Original Message-----
From: Limonciello, Mario <[email protected]>
Sent: Wednesday, June 7, 2023 1:53 AM
To: [email protected]
Cc: Limonciello, Mario <[email protected]>
Subject: [PATCH 2/2] drm/amd: Tighten permissions on VBIOS flashing attributes

Non-root users shouldn't be able to try to trigger a VBIOS flash or query the flashing status. This should be reserved for users with the appropriate permissions.

Fixes 8424f2ccb3c0 ("drm/amdgpu/psp: Add vbflash sysfs interface

support")

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +0 -0
index 8c60db176119..488d5b7ab97c 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c static ssize_t · line 3675

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +1 -1
@@ -3671,13 +3671,13 @@ static ssize_t
 amdgpu_psp_vbflash_status(struct device *dev,
 }
 
 static const struct bin_attribute psp_vbflash_bin_attr = {
-     .attr = {.name = "psp_vbflash", .mode = 0664},
+     .attr = {.name = "psp_vbflash", .mode = 0220},

I noticed a mistake with this, it should be 0660.

If no other feedback I'll correct it when committing.

Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +1 -1
      .size = 0,
      .write = amdgpu_psp_vbflash_write,
      .read = amdgpu_psp_vbflash_read,
 };
 
-static DEVICE_ATTR(psp_vbflash_status, 0444, amdgpu_psp_vbflash_status,
 NULL);
+static DEVICE_ATTR(psp_vbflash_status, 0440, amdgpu_psp_vbflash_status,
 NULL);

int amdgpu_psp_sysfs_init(struct amdgpu_device *adev) {
--
2.34.1