linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] IB/mthca: Fix possible uninitialized-variable access in mthca_SYS_EN()
@ 2021-08-11 12:34 Tuo Li
  2021-08-11 12:49 ` Leon Romanovsky
  0 siblings, 1 reply; 2+ messages in thread
From: Tuo Li @ 2021-08-11 12:34 UTC (permalink / raw)
  To: dledford, jgg; +Cc: linux-rdma, linux-kernel, baijiaju1990, Tuo Li, TOTE Robot

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().

Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
Signed-off-by: Tuo Li <islituo@gmail.com>
---
 drivers/infiniband/hw/mthca/mthca_cmd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
index bdf5ed38de22..86584982e496 100644
--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
@@ -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);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] IB/mthca: Fix possible uninitialized-variable access in mthca_SYS_EN()
  2021-08-11 12:34 [PATCH] IB/mthca: Fix possible uninitialized-variable access in mthca_SYS_EN() Tuo Li
@ 2021-08-11 12:49 ` Leon Romanovsky
  0 siblings, 0 replies; 2+ messages in thread
From: Leon Romanovsky @ 2021-08-11 12:49 UTC (permalink / raw)
  To: Tuo Li; +Cc: dledford, jgg, linux-rdma, linux-kernel, baijiaju1990, TOTE Robot

On Wed, Aug 11, 2021 at 05:34:15AM -0700, Tuo Li wrote:
> 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().
> 
> Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>
> Signed-off-by: Tuo Li <islituo@gmail.com>
> ---
>  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

> 
> diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
> index bdf5ed38de22..86584982e496 100644
> --- a/drivers/infiniband/hw/mthca/mthca_cmd.c
> +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
> @@ -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);
> -- 
> 2.25.1
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-11 12:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-11 12:34 [PATCH] IB/mthca: Fix possible uninitialized-variable access in mthca_SYS_EN() Tuo Li
2021-08-11 12:49 ` Leon Romanovsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).