2011-02-03 21:28:08

by Jesper Juhl

[permalink] [raw]
Subject: [PATCH] ServerEngines, benet: Avoid potential null deref in be_cmd_get_seeprom_data()

wrb_from_mccq() may return null, so we may crash on a null deref in
be_cmd_get_seeprom_data().
This avoids that potential crash.

Signed-off-by: Jesper Juhl <[email protected]>
---
be_cmds.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/net/benet/be_cmds.c b/drivers/net/benet/be_cmds.c
index 0c7811f..ec4a21d 100644
--- a/drivers/net/benet/be_cmds.c
+++ b/drivers/net/benet/be_cmds.c
@@ -1786,6 +1786,8 @@ int be_cmd_get_seeprom_data(struct be_adapter *adapter,
spin_lock_bh(&adapter->mcc_lock);

wrb = wrb_from_mccq(adapter);
+ if (!wrb)
+ return -EBUSY;
req = nonemb_cmd->va;
sge = nonembedded_sgl(wrb);


--
Jesper Juhl <[email protected]> http://www.chaosbits.net/
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please.


2011-02-05 03:18:59

by Ajit Khaparde

[permalink] [raw]
Subject: Re: [PATCH] ServerEngines, benet: Avoid potential null deref in be_cmd_get_seeprom_data()

> From: Jesper Juhl [[email protected]]
> ent: Thursday, February 03, 2011 3:27 PM
> To: [email protected]
> Cc: linux-drivers; [email protected]; Khaparde, Ajit; Bandi, Sarveshwar; Seetharaman, Subramanian; Perla, Sathya
> Subject: [PATCH] ServerEngines, benet: Avoid potential null deref in be_cmd_get_seeprom_data()

> wrb_from_mccq() may return null, so we may crash on a null deref in
> be_cmd_get_seeprom_data().
> This avoids that potential crash.

> Signed-off-by: Jesper Juhl <[email protected]>

Thanks Jesper.
But because we have acquired a lock, we need to release it.
I would suggest considering the following patch.

---

[PATCH] ServerEngines, benet: Avoid potential null deref in be_cmd_get_seeprom_data()

Found by: Jesper Juhl <[email protected]>

Signed-off-by: Ajit Khaparde <[email protected]>
---
drivers/net/benet/be_cmds.c | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/drivers/net/benet/be_cmds.c b/drivers/net/benet/be_cmds.c
index 0c7811f..a179cc6 100644
--- a/drivers/net/benet/be_cmds.c
+++ b/drivers/net/benet/be_cmds.c
@@ -1786,6 +1786,10 @@ int be_cmd_get_seeprom_data(struct be_adapter *adapter,
spin_lock_bh(&adapter->mcc_lock);

wrb = wrb_from_mccq(adapter);
+ if (!wrb) {
+ status = -EBUSY;
+ goto err;
+ }
req = nonemb_cmd->va;
sge = nonembedded_sgl(wrb);

@@ -1801,6 +1805,7 @@ int be_cmd_get_seeprom_data(struct be_adapter *adapter,

status = be_mcc_notify_wait(adapter);

+err:
spin_unlock_bh(&adapter->mcc_lock);
return status;
}
--
1.7.1

2011-02-06 01:58:00

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] ServerEngines, benet: Avoid potential null deref in be_cmd_get_seeprom_data()

From: Ajit Khaparde <[email protected]>
Date: Fri, 4 Feb 2011 21:18:28 -0600

> [PATCH] ServerEngines, benet: Avoid potential null deref in be_cmd_get_seeprom_data()
>
> Found by: Jesper Juhl <[email protected]>
>
> Signed-off-by: Ajit Khaparde <[email protected]>

Applied, thanks.