Skip to contentSkip to conversation

IB/mthca: Fix possible uninitialized-variable access in mthca_SYS_EN()

PATCH In review Tuo Li 2 participants 2 messages Aug 11, 2021 InfiniBand

lore
Share & tools
lore

Tuo Li

author
#0 lore raw

PATCH 1/1 IB/mthca: Fix possible uninitialized-variable access in mthca_SYS_EN()

The variable out is declared without initialization, and its address is passed to mthca_cmd_imm():
ret = mthca_cmd_imm(dev, 0, &out, 0, 0, CMD_SYS_EN, CMD_TIME_CLASS_D);

In this function, mthca_cmd_wait() or mthca_cmd_poll() will be called with the argument out_param, which is the address of the varialbe out. In these two called functions, mthca_cmd_post() will be called with *out_param, whose value comes from the uninitialized variable out.
err = mthca_cmd_post(dev, in_param, out_param ? *out_param : 0, ...)

In mthca_cmd_post(), mthca_cmd_post_dbell() or mthca_cmd_post_hcr() will be called, in which the value from the uninitialized varialble out may be used:
__raw_writel((__force u32) cpu_to_be32(out_param >> 32), ptr + offs[3]);

To fix this possible uninitialized-variable access, initialized out to 0 at the begining of mthca_SYS_EN().

---
 drivers/infiniband/hw/mthca/mthca_cmd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/mthca/mthca_cmd.c +1 -1
index bdf5ed38de22..86584982e496 100644
@@ -635,7 +635,7 @@ void mthca_free_mailbox(struct mthca_dev *dev, struct mthca_mailbox *mailbox)
 
 int mthca_SYS_EN(struct mthca_dev *dev)
 {
-	u64 out;
+	u64 out = 0;
 	int ret;
 
 	ret = mthca_cmd_imm(dev, 0, &out, 0, 0, CMD_SYS_EN, CMD_TIME_CLASS_D);
Signature · 1 line
2.25.1
#1 lore raw
Quoted 15 lines · Tuo Li

The variable out is declared without initialization, and its address is passed to mthca_cmd_imm():
ret = mthca_cmd_imm(dev, 0, &out, 0, 0, CMD_SYS_EN, CMD_TIME_CLASS_D);

In this function, mthca_cmd_wait() or mthca_cmd_poll() will be called with the argument out_param, which is the address of the varialbe out. In these two called functions, mthca_cmd_post() will be called with *out_param, whose value comes from the uninitialized variable out.
err = mthca_cmd_post(dev, in_param, out_param ? *out_param : 0, ...)

In mthca_cmd_post(), mthca_cmd_post_dbell() or mthca_cmd_post_hcr() will be called, in which the value from the uninitialized varialble out may be used:
__raw_writel((__force u32) cpu_to_be32(out_param >> 32), ptr + offs[3]);

Quoted 8 lines

To fix this possible uninitialized-variable access, initialized out to 0 at the begining of mthca_SYS_EN().

---
 drivers/infiniband/hw/mthca/mthca_cmd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Analysis is right, but I don't think that "out" value is important in this flow.

Thanks

Quoted 17 lines
drivers/infiniband/hw/mthca/mthca_cmd.c +1 -1
index bdf5ed38de22..86584982e496 100644
@@ -635,7 +635,7 @@ void mthca_free_mailbox(struct mthca_dev *dev, struct mthca_mailbox *mailbox)
 
 int mthca_SYS_EN(struct mthca_dev *dev)
 {
-	u64 out;
+	u64 out = 0;
 	int ret;
 
 	ret = mthca_cmd_imm(dev, 0, &out, 0, 0, CMD_SYS_EN, CMD_TIME_CLASS_D);
Signature · 1 line
2.25.1