Skip to contentSkip to conversation

drm/amdgpu: double free error and freeing uninitialized null pointer

PATCH Applied Sebin Sebastian 4 participants 4 messages Jul 30, 2022 – Aug 10, 2022

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

PATCH v2 1/1 drm/amdgpu: double free error and freeing uninitialized null pointer

Fix a double free and an uninitialized pointer read error. Both tmp and new are pointing at same address and both are freed which leads to double free. Adding a check to verify if new and tmp are free in the error_free label fixes the double free issue. new is not initialized to null which also leads to a free on an uninitialized pointer.

Suggested by: S. Amaranath <[email protected]>

---
Changes in v2:
Updated patch body as suggested by André Almeida <[email protected]> Reworked to implement a check in error_free for fixing double free error as suggested by S. Amaranath <[email protected]>

 drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +3 -2
index e2eec985adb3..cb00c7d6f50b 100644
@@ -1705,7 +1705,7 @@ static ssize_t amdgpu_reset_dump_register_list_write(struct file *f,
 {
 	struct amdgpu_device *adev = (struct amdgpu_device *)file_inode(f)->i_private;
 	char reg_offset[11];
-	uint32_t *new, *tmp = NULL;
+	uint32_t *new = NULL, *tmp = NULL;
 	int ret, i = 0, len = 0;
 
 	do {
@@ -1747,7 +1747,8 @@ static ssize_t amdgpu_reset_dump_register_list_write(struct file *f,
 	ret = size;
 
 error_free:
-	kfree(tmp);
+	if (tmp != new)
+		kfree(tmp);
 	kfree(new);
 	return ret;
 }
Signature · 1 line
2.34.1
Reviewed-by on v2 1/1
#1 lore raw

[AMD Official Use Only - General]

Quoted 62 lines

-----Original Message-----
From: Sebin Sebastian <[email protected]>
Sent: Saturday, July 30, 2022 11:47 AM
Cc: [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Pan, Xinhui <[email protected]>; David Airlie <[email protected]>; Daniel Vetter <[email protected]>; Nirmoy Das <[email protected]>; Lazar, Lijo <[email protected]>; Quan, Evan <[email protected]>; StDenis, Tom <[email protected]>; Somalapuram, Amaranath <[email protected]>; André Almeida <[email protected]>; [email protected]; dri- [email protected]; [email protected]
Subject: [PATCHv2 -next] drm/amdgpu: double free error and freeing uninitialized null pointer

Fix a double free and an uninitialized pointer read error. Both tmp and new are pointing at same address and both are freed which leads to double free. Adding a check to verify if new and tmp are free in the error_free label fixes the double free issue. new is not initialized to null which also leads to a free on an uninitialized pointer.

Suggested by: S. Amaranath <[email protected]>

---
Changes in v2:
Updated patch body as suggested by André Almeida <[email protected]>
Reworked to implement a check in error_free for fixing double free error as suggested by S. Amaranath <[email protected]>

 drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +1 -1
index e2eec985adb3..cb00c7d6f50b 100644
@@ -1705,7 +1705,7 @@ static ssize_t
 amdgpu_reset_dump_register_list_write(struct file *f,
 {
 	struct amdgpu_device *adev = (struct amdgpu_device
 *)file_inode(f)->i_private;
 	char reg_offset[11];
-	uint32_t *new, *tmp = NULL;
+	uint32_t *new = NULL, *tmp = NULL;
 	int ret, i = 0, len = 0;
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +2 -1
 	do {
@@ -1747,7 +1747,8 @@ static ssize_t
 amdgpu_reset_dump_register_list_write(struct file *f,
 	ret = size;
 
 error_free:
-	kfree(tmp);
+	if (tmp != new)
+		kfree(tmp);
 	kfree(new);
 	return ret;

}
--
2.34.1

Reviewed-by on v2 1/1
#2 lore raw
In reply to Sebin Sebastian

Às 00:46 de 30/07/22, Sebin Sebastian escreveu:

Quoted 8 lines

Fix a double free and an uninitialized pointer read error. Both tmp and new are pointing at same address and both are freed which leads to double free. Adding a check to verify if new and tmp are free in the error_free label fixes the double free issue. new is not initialized to null which also leads to a free on an uninitialized pointer.

Suggested by: S. Amaranath <[email protected]>

Applied
#3 lore raw

Applied. Thanks!

Alex

Quoted 12 lines · André Almeida

Às 00:46 de 30/07/22, Sebin Sebastian escreveu:

Quoted 8 lines

Fix a double free and an uninitialized pointer read error. Both tmp and new are pointing at same address and both are freed which leads to double free. Adding a check to verify if new and tmp are free in the error_free label fixes the double free issue. new is not initialized to null which also leads to a free on an uninitialized pointer.

Suggested by: S. Amaranath <[email protected]>