Skip to contentSkip to conversation

drm/nouveau: fix another off-by-one in nvbios_addr

PATCH In review Timur Tabi 2 participants 2 messages May 11, 2022

Subsystems (3)
lore
Share & tools
lore

Timur Tabi

author
#0 lore raw

PATCH 1/1 drm/nouveau: fix another off-by-one in nvbios_addr

This check determines whether a given address is part of image 0 or image 1. Image 1 starts at offset image0_size, so that address should be included.

Fixes 4d4e9907ff572 ("drm/nouveau/bios: guard against out-of-bounds accesses to image")
---
 drivers/gpu/drm/nouveau/nvkm/subdev/bios/base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/nouveau/nvkm/subdev/bios/base.c +1 -1
index 64e423dddd9e..6c318e41bde0 100644
@@ -33,7 +33,7 @@ nvbios_addr(struct nvkm_bios *bios, u32 *addr, u8 size)
 {
 	u32 p = *addr;
 
-	if (*addr > bios->image0_size && bios->imaged_addr) {
+	if (*addr >= bios->image0_size && bios->imaged_addr) {
 		*addr -= bios->image0_size;
 		*addr += bios->imaged_addr;
 	}
Signature · 1 line
2.36.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 25 lines · Timur Tabi

This check determines whether a given address is part of image 0 or image 1. Image 1 starts at offset image0_size, so that address should be included.

Fixes 4d4e9907ff572 ("drm/nouveau/bios: guard against out-of-bounds accesses to image")
---
 drivers/gpu/drm/nouveau/nvkm/subdev/bios/base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/nouveau/nvkm/subdev/bios/base.c +1 -2
index 64e423dddd9e..6c318e41bde0 100644
@@ -33,7 +33,7 @@ nvbios_addr(struct nvkm_bios *bios, u32 *addr, u8 size)
 {
        u32 p = *addr;
 
-       if (*addr > bios->image0_size && bios->imaged_addr) {
+       if (*addr >= bios->image0_size && bios->imaged_addr) {
                *addr -= bios->image0_size;
                *addr += bios->imaged_addr;
        }
--
Quoted 2 lines

2.36.0

I don't like how this could fail for values spanning both images, but at least this looks more correct.

I think in the future we should keep a copy without that gap on the host side to make access to the vbios image cheaper. What do you say Ben?