Skip to contentSkip to conversation

ipmi/powernv: Fix potential invalid pointer dereference

PATCH In review Neelesh Gupta 3 participants 5 messages Jul 16, 2015 – Jul 29, 2015 1 message not in the archive

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

PATCH 1/1 ipmi/powernv: Fix potential invalid pointer dereference

If the OPAL call to receive the ipmi message fails, then we free up the smi message and return. But, the driver still holds the reference to old smi message in the 'cur_msg' which can potentially be accessed later and freed again leading to kernel oops. To fix it up,

The kernel driver should reset the 'cur_msg' and send reply to the user in addition to freeing the message.

---
 drivers/char/ipmi/ipmi_powernv.c |   13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/char/ipmi/ipmi_powernv.c +10 -3
index 9b409c0..637486d 100644
@@ -143,9 +143,16 @@ static int ipmi_powernv_recv(struct ipmi_smi_powernv *smi)
 	pr_devel("%s:   -> %d (size %lld)\n", __func__,
 			rc, rc == 0 ? size : 0);
 	if (rc) {
-		spin_unlock_irqrestore(&smi->msg_lock, flags);
-		ipmi_free_smi_msg(msg);
-		return 0;
+		/* If came via the poll, and response was not yet ready */
+		if (rc == OPAL_EMPTY) {
+			spin_unlock_irqrestore(&smi->msg_lock, flags);
+			return 0;
+		} else {
+			smi->cur_msg = NULL;
+			spin_unlock_irqrestore(&smi->msg_lock, flags);
+			send_error_reply(smi, msg, IPMI_ERR_UNSPECIFIED);
+			return 0;
+		}
 	}
 
 	if (size < sizeof(*opal_msg)) {
#1 lore raw

Ok, this looks fine. A couple of question...

Do I need to send this upstream right now? How well has this been tested?

Do you want this backported to 4.0 stable?

-corey

Quoted 38 lines · Neelesh Gupta

If the OPAL call to receive the ipmi message fails, then we free up the smi message and return. But, the driver still holds the reference to old smi message in the 'cur_msg' which can potentially be accessed later and freed again leading to kernel oops. To fix it up,

The kernel driver should reset the 'cur_msg' and send reply to the user in addition to freeing the message.

---
 drivers/char/ipmi/ipmi_powernv.c |   13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/char/ipmi/ipmi_powernv.c +10 -3
index 9b409c0..637486d 100644
@@ -143,9 +143,16 @@ static int ipmi_powernv_recv(struct ipmi_smi_powernv *smi)
 	pr_devel("%s:   -> %d (size %lld)\n", __func__,
 			rc, rc == 0 ? size : 0);
 	if (rc) {
-		spin_unlock_irqrestore(&smi->msg_lock, flags);
-		ipmi_free_smi_msg(msg);
-		return 0;
+		/* If came via the poll, and response was not yet ready */
+		if (rc == OPAL_EMPTY) {
+			spin_unlock_irqrestore(&smi->msg_lock, flags);
+			return 0;
+		} else {
+			smi->cur_msg = NULL;
+			spin_unlock_irqrestore(&smi->msg_lock, flags);
+			send_error_reply(smi, msg, IPMI_ERR_UNSPECIFIED);
+			return 0;
+		}
 	}
 
 	if (size < sizeof(*opal_msg)) {
#2 lore raw

Hi Corey,

Quoted 3 lines · Corey Minyard

Ok, this looks fine. A couple of question...

Do I need to send this upstream right now? How well has this been tested?

I would want either Jeremy or Alistair to review this patch before you send this upstream. There is also firmware piece http://patchwork.ozlabs.org/patch/496645/
awaiting review.

In the testing front, I manually made the opal_ipmi_recv() function to fail for testing the error path and see if the driver recovers from it and subsequent ipmi commands work all good.

Quoted 2 lines

Do you want this backported to 4.0 stable?

Yes, I want this to be be backported to 4.0 stable.

Thanks,
Neelesh.

Quoted 42 lines

-corey

Quoted 38 lines · Neelesh Gupta

If the OPAL call to receive the ipmi message fails, then we free up the smi message and return. But, the driver still holds the reference to old smi message in the 'cur_msg' which can potentially be accessed later and freed again leading to kernel oops. To fix it up,

The kernel driver should reset the 'cur_msg' and send reply to the user in addition to freeing the message.

---
  drivers/char/ipmi/ipmi_powernv.c |   13 ++++++++++---
  1 file changed, 10 insertions(+), 3 deletions(-)
drivers/char/ipmi/ipmi_powernv.c +10 -3
index 9b409c0..637486d 100644
@@ -143,9 +143,16 @@ static int ipmi_powernv_recv(struct ipmi_smi_powernv *smi)
  	pr_devel("%s:   -> %d (size %lld)\n", __func__,
  			rc, rc == 0 ? size : 0);
  	if (rc) {
-		spin_unlock_irqrestore(&smi->msg_lock, flags);
-		ipmi_free_smi_msg(msg);
-		return 0;
+		/* If came via the poll, and response was not yet ready */
+		if (rc == OPAL_EMPTY) {
+			spin_unlock_irqrestore(&smi->msg_lock, flags);
+			return 0;
+		} else {
+			smi->cur_msg = NULL;
+			spin_unlock_irqrestore(&smi->msg_lock, flags);
+			send_error_reply(smi, msg, IPMI_ERR_UNSPECIFIED);
+			return 0;
+		}
  	}
 
  	if (size < sizeof(*opal_msg)) {
Reviewed-by
#4 lore raw
In reply to a message not in the archive

Hi Neelesh,

This fix looks reasonable to me, although Jeremy would be the best person to comment if he has time. I wonder why we bother polling at all given that our event interface should call opal_ipmi_recv() whenever a message is ready?

Also the firmware fix you refer to and this fix are independent of each other so there's no ordering issues there.

Quoted 8 lines · On Tue, 28 Jul 2015 13:20:07 Neelesh Gupta wrote:
Quoted 6 lines · Neelesh Gupta

Hi Corey,

Quoted 3 lines · Corey Minyard

Ok, this looks fine. A couple of question...

Do I need to send this upstream right now? How well has this been

tested?

Quoted 39 lines
Quoted 7 lines

I would want either Jeremy or Alistair to review this patch before you send this
upstream. There is also firmware piece
http://patchwork.ozlabs.org/patch/496645/
awaiting review.

Quoted 5 lines

In the testing front, I manually made the opal_ipmi_recv() function to fail for testing
the error path and see if the driver recovers from it and subsequent ipmi commands
work all good.

Hi Jeremy/Alistair,

Could you please review it and the corresponding skiboot patch...

Thanks,
Neelesh.

Quoted 19 lines
Quoted 2 lines

Do you want this backported to 4.0 stable?

Yes, I want this to be be backported to 4.0 stable.

Thanks,
Neelesh.

Quoted 11 lines

-corey

Quoted 8 lines · Neelesh Gupta

If the OPAL call to receive the ipmi message fails, then we free up the smi message and return. But, the driver still holds the reference to old smi message in the 'cur_msg' which can potentially be accessed later and freed again leading to kernel oops. To fix it up,

The kernel driver should reset the 'cur_msg' and send reply to the user in addition to freeing the message.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Review

Quoted 6 lines
---
  drivers/char/ipmi/ipmi_powernv.c |   13 ++++++++++---
  1 file changed, 10 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/char/ipmi/ipmi_powernv.c

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/char/ipmi/ipmi_powernv.c static int ipmi_powernv_recv(struct

Quoted 4 lines

index 9b409c0..637486d 100644

drivers/char/ipmi/ipmi_powernv.c +0 -0
@@ -143,9 +143,16 @@ static int ipmi_powernv_recv(struct 

ipmi_smi_powernv *smi)

Quoted 28 lines
Quoted 27 lines
Quoted 18 lines
Quoted 18 lines
drivers/char/ipmi/ipmi_powernv.c +10 -3
  	pr_devel("%s:   -> %d (size %lld)\n", __func__,
  			rc, rc == 0 ? size : 0);
  	if (rc) {
-		spin_unlock_irqrestore(&smi->msg_lock, flags);
-		ipmi_free_smi_msg(msg);
-		return 0;
+		/* If came via the poll, and response was not yet ready */
+		if (rc == OPAL_EMPTY) {
+			spin_unlock_irqrestore(&smi->msg_lock, flags);
+			return 0;
+		} else {
+			smi->cur_msg = NULL;
+			spin_unlock_irqrestore(&smi->msg_lock, flags);
+			send_error_reply(smi, msg, IPMI_ERR_UNSPECIFIED);
+			return 0;
+		}
  	}
 
Quoted 2 lines

drivers/char/ipmi/ipmi_powernv.c static int ipmi_powernv_recv(struct ipmi_smi_powernv *smi) · line 158

Quoted 2 lines
drivers/char/ipmi/ipmi_powernv.c +0 -0
  	if (size < sizeof(*opal_msg)) {

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev

#5 lore raw

Hi Alistair,

Thanks for the review.

Quoted 5 lines · Alistair Popple

Hi Neelesh,

This fix looks reasonable to me, although Jeremy would be the best person to comment if he has time. I wonder why we bother polling at all given that our event interface should call opal_ipmi_recv() whenever a message is ready?

Agree. I thought about it and didn't find any reason to have it as we have event mechanism.. but didn't think of changing as it is not causing any issue..

Quoted 3 lines

Also the firmware fix you refer to and this fix are independent of each other so there's no ordering issues there.

Correct. Though, there is no relation, but I figured out the skiboot issue after this change.. yes, they are independent. Please find time to review the skiboot patch.

Corey,

Please queue this patch for upstream if you Ok with it.

Thanks,
Neelesh.

Quoted 85 lines
Quoted 7 lines · On Tue, 28 Jul 2015 13:20:07 Neelesh Gupta wrote:
Quoted 6 lines · Neelesh Gupta

Hi Corey,

Quoted 3 lines · Corey Minyard

Ok, this looks fine. A couple of question...

Do I need to send this upstream right now? How well has this been

tested?

Quoted 35 lines
Quoted 11 lines

I would want either Jeremy or Alistair to review this patch before you send this
upstream. There is also firmware piece
http://patchwork.ozlabs.org/patch/496645/
awaiting review.

In the testing front, I manually made the opal_ipmi_recv() function to fail for testing
the error path and see if the driver recovers from it and subsequent ipmi commands
work all good.

Hi Jeremy/Alistair,

Could you please review it and the corresponding skiboot patch...

Thanks,
Neelesh.

Quoted 17 lines
Quoted 1 line

Do you want this backported to 4.0 stable?

Yes, I want this to be be backported to 4.0 stable.

Thanks,
Neelesh.

Quoted 11 lines

-corey

Quoted 8 lines · Neelesh Gupta

If the OPAL call to receive the ipmi message fails, then we free up the smi message and return. But, the driver still holds the reference to old smi message in the 'cur_msg' which can potentially be accessed later and freed again leading to kernel oops. To fix it up,

The kernel driver should reset the 'cur_msg' and send reply to the user in addition to freeing the message.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Review

Quoted 6 lines
---
   drivers/char/ipmi/ipmi_powernv.c |   13 ++++++++++---
   1 file changed, 10 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/char/ipmi/ipmi_powernv.c

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

drivers/char/ipmi/ipmi_powernv.c static int ipmi_powernv_recv(struct

Quoted 4 lines

index 9b409c0..637486d 100644

drivers/char/ipmi/ipmi_powernv.c +0 -0
@@ -143,9 +143,16 @@ static int ipmi_powernv_recv(struct

ipmi_smi_powernv *smi)

Quoted 26 lines
Quoted 26 lines
Quoted 18 lines
Quoted 18 lines
drivers/char/ipmi/ipmi_powernv.c +10 -3
   	pr_devel("%s:   -> %d (size %lld)\n", __func__,
   			rc, rc == 0 ? size : 0);
   	if (rc) {
-		spin_unlock_irqrestore(&smi->msg_lock, flags);
-		ipmi_free_smi_msg(msg);
-		return 0;
+		/* If came via the poll, and response was not yet ready */
+		if (rc == OPAL_EMPTY) {
+			spin_unlock_irqrestore(&smi->msg_lock, flags);
+			return 0;
+		} else {
+			smi->cur_msg = NULL;
+			spin_unlock_irqrestore(&smi->msg_lock, flags);
+			send_error_reply(smi, msg, IPMI_ERR_UNSPECIFIED);
+			return 0;
+		}
   	}
 
Quoted 2 lines

drivers/char/ipmi/ipmi_powernv.c static int ipmi_powernv_recv(struct ipmi_smi_powernv *smi) · line 158

Quoted 2 lines
drivers/char/ipmi/ipmi_powernv.c +0 -0
   	if (size < sizeof(*opal_msg)) {

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev