Skip to contentSkip to conversation

drm/radeon: Fix stack data leak

PATCH In review Jean Delvare 2 participants 2 messages Aug 15, 2010 – Aug 16, 2010

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

PATCH 1/1 drm/radeon: Fix stack data leak

Always zero-init a structure on the stack which is returned by a function. Otherwise you may leak random stack data from previous function calls.

This fixes the following warning I was seeing:
CC [M] drivers/gpu/drm/radeon/radeon_atombios.o
drivers/gpu/drm/radeon/radeon_atombios.c: In function "radeon_atom_get_hpd_info_from_gpio":
drivers/gpu/drm/radeon/radeon_atombios.c:261: warning: "hpd.plugged_state" is used uninitialized in this function

Cc David Airlie <[email protected]>
Cc Alex Deucher <[email protected]>

---
As a side, note, passing whole structures on the stack this way seems suboptimal. Passing structures by address would be faster (and safer, as it stands.)

 drivers/gpu/drm/radeon/radeon_atombios.c |    2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/radeon/radeon_atombios.c +2 -0
@@ -226,6 +226,8 @@ static struct radeon_hpd radeon_atom_get
 	struct radeon_hpd hpd;
 	u32 reg;
 
+	memset(&hpd, 0, sizeof(struct radeon_hpd));
+
 	if (ASIC_IS_DCE4(rdev))
 		reg = EVERGREEN_DC_GPIO_HPD_A;
 	else
Signature · 1 line
Jean Delvare
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Jean Delvare

Always zero-init a structure on the stack which is returned by a function. Otherwise you may leak random stack data from previous function calls.

This fixes the following warning I was seeing:
 CC [M]  drivers/gpu/drm/radeon/radeon_atombios.o
drivers/gpu/drm/radeon/radeon_atombios.c: In function "radeon_atom_get_hpd_info_from_gpio":
drivers/gpu/drm/radeon/radeon_atombios.c:261: warning: "hpd.plugged_state" is used uninitialized in this function

Quoted 7 lines
Cc David Airlie <[email protected]>
Cc Alex Deucher <[email protected]>

---
As a side, note, passing whole structures on the stack this way seems suboptimal. Passing structures by address would be faster (and safer, as it stands.)

There are a few places in the connector/encoder init code where this needs to be cleaned up, just haven't gotten to it yet. Patch looks good. Thanks!

Quoted 20 lines

 drivers/gpu/drm/radeon/radeon_atombios.c |    2 ++

 1 file changed, 2 insertions(+)
drivers/gpu/drm/radeon/radeon_atombios.c   2010-08-15 13:52:31.000000000 +0200 renamed from drivers/gpu/drm/radeon/radeon_atombios.c      2010-08-15 10:24:49.000000000 +0200 +2 -0
@@ -226,6 +226,8 @@ static struct radeon_hpd radeon_atom_get
        struct radeon_hpd hpd;
        u32 reg;
 
+       memset(&hpd, 0, sizeof(struct radeon_hpd));
+
        if (ASIC_IS_DCE4(rdev))
                reg = EVERGREEN_DC_GPIO_HPD_A;

       else

--
Jean Delvare