Skip to contentSkip to conversation

drm/amdgpu: just disallow reading untouched registers

PATCH In review Christian König 3 participants 7 messages Mar 28, 2017 – Mar 29, 2017 6 messages not in the archive

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

PATCH 1/1 drm/amdgpu: just disallow reading untouched registers

From: Christian König <[email protected]>

Not sure what the original intention was here, but returning a random piece of kernel memory to userspace because we didn't set the value at all is clearly not a good idea.

This patch disallows reading the register and returns a proper error code instead.

---
 drivers/gpu/drm/amd/amdgpu/vi.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/vi.c +0 -6
index 5c02ec4..f1c2bff 100644
@@ -465,15 +465,9 @@ static void vi_detect_hw_virtualization(struct amdgpu_device *adev)
 }
 
 static const struct amdgpu_allowed_register_entry tonga_allowed_read_registers[] = {
-	{mmGB_MACROTILE_MODE7, true},
 };
 
 static const struct amdgpu_allowed_register_entry cz_allowed_read_registers[] = {
-	{mmGB_TILE_MODE7, true},
-	{mmGB_TILE_MODE12, true},
-	{mmGB_TILE_MODE17, true},
-	{mmGB_TILE_MODE23, true},
-	{mmGB_MACROTILE_MODE7, true},
 };
 
 static const struct amdgpu_allowed_register_entry vi_allowed_read_registers[] = {
Signature · 6 lines
2.5.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1490700278-3374-1-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

#2 lore raw

Ping!

Does anybody of you guys know what the background of those "untouched" registers is?

That we leak uninitialized memory to userspace is a bit bad.

Thanks,
Christian.

Am 28.03.2017 um 13:24 schrieb Christian König:

Quoted 24 lines

From: Christian König <[email protected]>

Not sure what the original intention was here, but returning a random piece of kernel memory to userspace because we didn't set the value at all is clearly not a good idea.

This patch disallows reading the register and returns a proper error code instead.

---
  drivers/gpu/drm/amd/amdgpu/vi.c | 6 ------
  1 file changed, 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/vi.c +0 -1
index 5c02ec4..f1c2bff 100644
@@ -465,15 +465,9 @@ static void vi_detect_hw_virtualization(struct amdgpu_device *adev)
  }
 
  static const struct amdgpu_allowed_register_entry tonga_allowed_read_registers[] = {
-	{mmGB_MACROTILE_MODE7, true},
  };

drivers/gpu/drm/amd/amdgpu/vi.c static void vi_detect_hw_virtualization(struct amdgpu_device *adev) · line 473

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/vi.c +0 -5
 
  static const struct amdgpu_allowed_register_entry cz_allowed_read_registers[] = {
-	{mmGB_TILE_MODE7, true},
-	{mmGB_TILE_MODE12, true},
-	{mmGB_TILE_MODE17, true},
-	{mmGB_TILE_MODE23, true},
-	{mmGB_MACROTILE_MODE7, true},
  };
 
  static const struct amdgpu_allowed_register_entry vi_allowed_read_registers[] = {

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): a6b9d45a-be2d-6cb8-929f-540c5cd0b38d-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

#4 lore raw
Quoted 6 lines · Christian König

Ping!

Does anybody of you guys know what the background of those "untouched" registers is?

That we leak uninitialized memory to userspace is a bit bad.

I don't know the history but wouldn't reading these just read the MMIO registers? Or these are cached and we're reading kernel mem?

It seems sensible to remove them though and the patch looks clean so I'll give an ack-by.

Tom

Quoted 41 lines

Thanks,
Christian.

Am 28.03.2017 um 13:24 schrieb Christian König:

Quoted 36 lines

From: Christian König <[email protected]>

Not sure what the original intention was here, but returning a random piece of
kernel memory to userspace because we didn't set the value at all is clearly
not a good idea.

This patch disallows reading the register and returns a proper error code instead.

---
  drivers/gpu/drm/amd/amdgpu/vi.c | 6 ------
  1 file changed, 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/vi.c +0 -6
index 5c02ec4..f1c2bff 100644
@@ -465,15 +465,9 @@ static void vi_detect_hw_virtualization(struct
 amdgpu_device *adev)
  }
    static const struct amdgpu_allowed_register_entry
 tonga_allowed_read_registers[] = {
-    {mmGB_MACROTILE_MODE7, true},
  };
    static const struct amdgpu_allowed_register_entry
 cz_allowed_read_registers[] = {
-    {mmGB_TILE_MODE7, true},
-    {mmGB_TILE_MODE12, true},
-    {mmGB_TILE_MODE17, true},
-    {mmGB_TILE_MODE23, true},
-    {mmGB_MACROTILE_MODE7, true},
  };
Quoted 8 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/vi.c +0 -0
    static const struct amdgpu_allowed_register_entry

vi_allowed_read_registers[] = {

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 39974fc4-74bc-b2d7-3707-35282faea6d0-5C7GfCeVMHo@public.gmane.org

#6 lore raw

Am 29.03.2017 um 14:28 schrieb Tom St Denis:

Quoted 9 lines · Christian König
Quoted 6 lines

Ping!

Does anybody of you guys know what the background of those "untouched" registers is?

That we leak uninitialized memory to userspace is a bit bad.

I don't know the history but wouldn't reading these just read the MMIO registers? Or these are cached and we're reading kernel mem?

The crux is we actually don't read them, but just ignore them.

In other words we copy back random kernel memory to userspace because we didn't initialize the returned value.

That is strange at best, but I can't figure out the background here.

Christian.

Quoted 55 lines

It seems sensible to remove them though and the patch looks clean so I'll give an ack-by.

Tom

Quoted 41 lines

Thanks,
Christian.

Am 28.03.2017 um 13:24 schrieb Christian König:

Quoted 36 lines

From: Christian König <[email protected]>

Not sure what the original intention was here, but returning a random piece of
kernel memory to userspace because we didn't set the value at all is clearly
not a good idea.

This patch disallows reading the register and returns a proper error code instead.

---
  drivers/gpu/drm/amd/amdgpu/vi.c | 6 ------
  1 file changed, 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/vi.c +0 -6
index 5c02ec4..f1c2bff 100644
@@ -465,15 +465,9 @@ static void vi_detect_hw_virtualization(struct
 amdgpu_device *adev)
  }
    static const struct amdgpu_allowed_register_entry
 tonga_allowed_read_registers[] = {
-    {mmGB_MACROTILE_MODE7, true},
  };
    static const struct amdgpu_allowed_register_entry
 cz_allowed_read_registers[] = {
-    {mmGB_TILE_MODE7, true},
-    {mmGB_TILE_MODE12, true},
-    {mmGB_TILE_MODE17, true},
-    {mmGB_TILE_MODE23, true},
-    {mmGB_MACROTILE_MODE7, true},
  };
Quoted 8 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/vi.c +0 -0
    static const struct amdgpu_allowed_register_entry

vi_allowed_read_registers[] = {

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 8c7ecc25-dfc1-b451-542c-f55be429c8dd-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

#8 lore raw
Quoted 12 lines · Christian König

Am 29.03.2017 um 14:28 schrieb Tom St Denis:

Quoted 11 lines · Christian König
Quoted 7 lines

Ping!

Does anybody of you guys know what the background of those "untouched" registers is?

That we leak uninitialized memory to userspace is a bit bad.

Quoted 8 lines
Quoted 2 lines

I don't know the history but wouldn't reading these just read the MMIO registers? Or these are cached and we're reading kernel mem?

The crux is we actually don't read them, but just ignore them.

In other words we copy back random kernel memory to userspace because we didn't initialize the returned value.

Well, it's zeroed memory, so it's not random. They just return 0.

Quoted 2 lines

That is strange at best, but I can't figure out the background here.

No idea why they were added separately. AFAIK, those indices are not used.

Alex

Quoted 70 lines

Christian.

Quoted 59 lines

It seems sensible to remove them though and the patch looks clean so I'll give an ack-by.

Tom

Quoted 43 lines

Thanks,
Christian.

Am 28.03.2017 um 13:24 schrieb Christian König:

Quoted 38 lines

From: Christian König <[email protected]>

Not sure what the original intention was here, but returning a random piece of
kernel memory to userspace because we didn't set the value at all is clearly
not a good idea.

This patch disallows reading the register and returns a proper error code instead.

---
  drivers/gpu/drm/amd/amdgpu/vi.c | 6 ------
  1 file changed, 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/vi.c +0 -6
index 5c02ec4..f1c2bff 100644
@@ -465,15 +465,9 @@ static void vi_detect_hw_virtualization(struct
 amdgpu_device *adev)
  }
    static const struct amdgpu_allowed_register_entry
 tonga_allowed_read_registers[] = {
-    {mmGB_MACROTILE_MODE7, true},
  };
    static const struct amdgpu_allowed_register_entry
 cz_allowed_read_registers[] = {
-    {mmGB_TILE_MODE7, true},
-    {mmGB_TILE_MODE12, true},
-    {mmGB_TILE_MODE17, true},
-    {mmGB_TILE_MODE23, true},
-    {mmGB_MACROTILE_MODE7, true},
  };
    static const struct amdgpu_allowed_register_entry
Quoted 8 lines
Quoted 1 line

vi_allowed_read_registers[] = {

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): CADnq5_M-OhOo7HzY4wdb-Lq0Q-s7s9rXaZHaOei3Uxo-3A-dQg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#10 lore raw

Am 29.03.2017 um 15:29 schrieb Alex Deucher:

Quoted 11 lines
Quoted 9 lines · Christian König

Am 29.03.2017 um 14:28 schrieb Tom St Denis:

Quoted 8 lines · Christian König
Quoted 6 lines

Ping!

Does anybody of you guys know what the background of those "untouched" registers is?

That we leak uninitialized memory to userspace is a bit bad.

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

I don't know the history but wouldn't reading these just read the MMIO registers? Or these are cached and we're reading kernel mem?

The crux is we actually don't read them, but just ignore them.

In other words we copy back random kernel memory to userspace because we didn't initialize the returned value.

Well, it's zeroed memory, so it's not random. They just return 0.

No, the IOCTL is using kmalloc_array, not kcalloc or kzalloc.

That's why I stumbled over it in the first place.

Quoted 3 lines
Quoted 2 lines

That is strange at best, but I can't figure out the background here.

No idea why they were added separately. AFAIK, those indices are not used.

Dare to put an rb or ack-by on it?

Christian.

Quoted 70 lines

Alex

Quoted 67 lines

Christian.

Quoted 54 lines

It seems sensible to remove them though and the patch looks clean so I'll give an ack-by.

Tom

Quoted 40 lines

Thanks,
Christian.

Am 28.03.2017 um 13:24 schrieb Christian König:

Quoted 36 lines

From: Christian König <[email protected]>

Not sure what the original intention was here, but returning a random piece of
kernel memory to userspace because we didn't set the value at all is clearly
not a good idea.

This patch disallows reading the register and returns a proper error code instead.

---
   drivers/gpu/drm/amd/amdgpu/vi.c | 6 ------
   1 file changed, 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/vi.c +0 -6
index 5c02ec4..f1c2bff 100644
@@ -465,15 +465,9 @@ static void vi_detect_hw_virtualization(struct
 amdgpu_device *adev)
   }
     static const struct amdgpu_allowed_register_entry
 tonga_allowed_read_registers[] = {
-    {mmGB_MACROTILE_MODE7, true},
   };
     static const struct amdgpu_allowed_register_entry
 cz_allowed_read_registers[] = {
-    {mmGB_TILE_MODE7, true},
-    {mmGB_TILE_MODE12, true},
-    {mmGB_TILE_MODE17, true},
-    {mmGB_TILE_MODE23, true},
-    {mmGB_MACROTILE_MODE7, true},
   };
Quoted 8 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/vi.c +0 -0
     static const struct amdgpu_allowed_register_entry

vi_allowed_read_registers[] = {

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 79548a48-7c1c-5340-f67c-ab991bd74a42-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

Acked-by
#12 lore raw
Quoted 26 lines · Christian König

Am 29.03.2017 um 15:29 schrieb Alex Deucher:

Quoted 25 lines
Quoted 21 lines · Christian König

Am 29.03.2017 um 14:28 schrieb Tom St Denis:

Quoted 13 lines · Christian König
Quoted 7 lines

Ping!

Does anybody of you guys know what the background of those "untouched" registers is?

That we leak uninitialized memory to userspace is a bit bad.

I don't know the history but wouldn't reading these just read the MMIO registers? Or these are cached and we're reading kernel mem?

The crux is we actually don't read them, but just ignore them.

In other words we copy back random kernel memory to userspace because we didn't initialize the returned value.

Quoted 6 lines
Quoted 1 line

Well, it's zeroed memory, so it's not random. They just return 0.

No, the IOCTL is using kmalloc_array, not kcalloc or kzalloc.

That's why I stumbled over it in the first place.

But the register is read from the cached copy which is zeroed.

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

That is strange at best, but I can't figure out the background here.

No idea why they were added separately. AFAIK, those indices are not used.

Dare to put an rb or ack-by on it?

Quoted 82 lines

Christian.

Quoted 75 lines

Alex

Quoted 72 lines

Christian.

Quoted 58 lines

It seems sensible to remove them though and the patch looks clean so I'll
give an ack-by.

Tom

Quoted 42 lines

Thanks,
Christian.

Am 28.03.2017 um 13:24 schrieb Christian König:

Quoted 38 lines

From: Christian König <[email protected]>

Not sure what the original intention was here, but returning a random piece of
kernel memory to userspace because we didn't set the value at all is clearly
not a good idea.

This patch disallows reading the register and returns a proper error code instead.

---
   drivers/gpu/drm/amd/amdgpu/vi.c | 6 ------
   1 file changed, 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/vi.c +0 -6
index 5c02ec4..f1c2bff 100644
@@ -465,15 +465,9 @@ static void vi_detect_hw_virtualization(struct
 amdgpu_device *adev)
   }
     static const struct amdgpu_allowed_register_entry
 tonga_allowed_read_registers[] = {
-    {mmGB_MACROTILE_MODE7, true},
   };
     static const struct amdgpu_allowed_register_entry
 cz_allowed_read_registers[] = {
-    {mmGB_TILE_MODE7, true},
-    {mmGB_TILE_MODE12, true},
-    {mmGB_TILE_MODE17, true},
-    {mmGB_TILE_MODE23, true},
-    {mmGB_MACROTILE_MODE7, true},
   };
     static const struct amdgpu_allowed_register_entry
Quoted 8 lines
Quoted 1 line

vi_allowed_read_registers[] = {

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx