mwifiex: prevent corruption instead of just warning
Subsystems (2)
PATCH 3/4 mwifiex: prevent corruption instead of just warning
We may as well put a return here instead of just printing a warning message and then corrupting memory. The caller doesn't check the return code.
drivers/net/wireless/mwifiex/pcie.c +3 -1
@@ -1228,9 +1228,11 @@ static int mwifiex_pcie_event_complete(struct mwifiex_adapter *adapter,if (!skb)return 0 ; -if (rdptr >=MWIFIEX_MAX_EVT_BD ) +if (rdptr >=MWIFIEX_MAX_EVT_BD ) {dev_err (adapter->dev,"event_complete: Invalid rdptr 0x%x\n" , rdptr); +return -EINVAL ; + }/* Read the event ring write pointer set by firmware */ if (mwifiex_read_reg (adapter,REG_EVTBD_WRPTR , &wrptr)) {
Hi Dan,
Quoted 18 lines
-----Original Message-----
From: Dan Carpenter [mailto:[email protected]]
Sent: Monday, October 17, 2011 11:15 PM
To: Bing Zhao
Cc: John W. Linville; [email protected]; [email protected]
Subject: [patch 3/4] mwifiex: prevent corruption instead of just warningWe may as well put a return here instead of just printing a warning message and then corrupting memory. The caller doesn't check the return code.
Signed-off-by Dan Carpenter <[email protected]>drivers/net/wireless/mwifiex/pcie.c +0
-0
drivers/net/wireless/mwifiex/pcie.c static int mwifiex_pcie_event_complete(struct mwifiex_adapter *adapter, · line 1234
Quoted 8 lines
drivers/net/wireless/mwifiex/pcie.c +2
-1@@ -1228,9 +1228,11 @@ static int mwifiex_pcie_event_complete(struct mwifiex_adapter *adapter,if (!skb)return 0 ; -if (rdptr >=MWIFIEX_MAX_EVT_BD ) +if (rdptr >=MWIFIEX_MAX_EVT_BD ) {dev_err (adapter->dev,"event_complete: Invalid rdptr 0x%x\n" , rdptr); +return -EINVAL ;
Instead of returning directly, we should set the error code and go through the error handling:
ret = -EINVAL; goto done;
Could you please resend v2?
Thanks,
Bing
Quoted 4 lines
drivers/net/wireless/mwifiex/pcie.c +1
-0+ }/* Read the event ring write pointer set by firmware */ if (mwifiex_read_reg (adapter,REG_EVTBD_WRPTR , &wrptr)) {
Johannes Berg
maintainerQuoted 11 lines · Bing Zhao
drivers/net/wireless/mwifiex/pcie.c static int mwifiex_pcie_event_complete(struct mwifiex_adapter *adapter, · line 1234
Quoted 9 lines
drivers/net/wireless/mwifiex/pcie.c +2
-1@@ -1228,9 +1228,11 @@ static int mwifiex_pcie_event_complete(struct mwifiex_adapter *adapter,if (!skb)return 0 ; -if (rdptr >=MWIFIEX_MAX_EVT_BD ) +if (rdptr >=MWIFIEX_MAX_EVT_BD ) {dev_err (adapter->dev,"event_complete: Invalid rdptr 0x%x\n" , rdptr); +return -EINVAL ;Instead of returning directly, we should set the error code and go through the error handling:
Quoted 2 lines
ret = -EINVAL; goto done;
Are you sure? You don't go to error handling a few lines earlier.
johannes
SGkgSm9oYW5uZXMsDQoNClRoYW5rcyBmb3IgeW91ciBjb21tZW50Lg0KDQo+IC0tLS0tT3JpZ2lu YWwgTWVzc2FnZS0tLS0tDQo+IEZyb206IEpvaGFubmVzIEJlcmcgW21haWx0bzpqb2hhbm5lc0Bz aXBzb2x1dGlvbnMubmV0XQ0KPiBTZW50OiBUdWVzZGF5LCBPY3RvYmVyIDE4LCAyMDExIDExOjIz IEFNDQo+IFRvOiBCaW5nIFpoYW8NCj4gQ2M6IERhbiBDYXJwZW50ZXI7IEpvaG4gVy4gTGludmls bGU7IGxpbnV4LXdpcmVsZXNzQHZnZXIua2VybmVsLm9yZzsga2VybmVsLWphbml0b3JzQHZnZXIu a2VybmVsLm9yZw0KPiBTdWJqZWN0OiBSRTogW3BhdGNoIDMvNF0gbXdpZmlleDogcHJldmVudCBj b3JydXB0aW9uIGluc3RlYWQgb2YganVzdCB3YXJuaW5nDQo+IA0KPiBPbiBUdWUsIDIwMTEtMTAt MTggYXQgMTE6MTkgLTA3MDAsIEJpbmcgWmhhbyB3cm90ZToNCj4gDQo+ID4gPiBAQCAtMTIyOCw5 ICsxMjI4LDExIEBAIHN0YXRpYyBpbnQgbXdpZmlleF9wY2llX2V2ZW50X2NvbXBsZXRlKHN0cnVj dCBtd2lmaWV4X2FkYXB0ZXIgKmFkYXB0ZXIsDQo+ID4gPiAgCWlmICghc2tiKQ0KPiA+ID4gIAkJ cmV0dXJuIDA7DQo+ID4gPg0KPiA+ID4gLQlpZiAocmRwdHIgPj0gTVdJRklFWF9NQVhfRVZUX0JE KQ0KPiA+ID4gKwlpZiAocmRwdHIgPj0gTVdJRklFWF9NQVhfRVZUX0JEKSB7DQo+ID4gPiAgCQlk ZXZfZXJyKGFkYXB0ZXItPmRldiwgImV2ZW50X2NvbXBsZXRlOiBJbnZhbGlkIHJkcHRyIDB4JXhc biIsDQo+ID4gPiAgCQkJCQlyZHB0cik7DQo+ID4gPiArCQlyZXR1cm4gLUVJTlZBTDsNCj4gPg0K PiA+IEluc3RlYWQgb2YgcmV0dXJuaW5nIGRpcmVjdGx5LCB3ZSBzaG91bGQgc2V0IHRoZSBlcnJv ciBjb2RlIGFuZCBnbyB0aHJvdWdoIHRoZSBlcnJvciBoYW5kbGluZzoNCj4gPiAJCXJldCA9IC1F SU5WQUw7DQo+ID4gCQlnb3RvIGRvbmU7DQo+IA0KPiBBcmUgeW91IHN1cmU/IFlvdSBkb24ndCBn byB0byBlcnJvciBoYW5kbGluZyBhIGZldyBsaW5lcyBlYXJsaWVyLg0KDQpUaGUgZXJyb3IgaGFu ZGxpbmcgd2lsbCBmcmVlIHRoZSBza2IuIElmIHNrYiBpcyBOVUxMIHRoZXJlIGlzIG5vIG5lZWQg dG8gZnJlZS4NCg0KVGhhbmtzLA0KQmluZw0KDQo+IA0KPiBqb2hhbm5lcw0KDQo
PATCH v2 3/4 mwifiex: prevent corruption instead of just warning
In reply to Bing ZhaoProbably we never hit this condition, but in case we do, we may as well put a return here instead of just printing a warning message and then corrupting memory. The caller doesn't check the return code.
---
v2: Use the error handling code to free the skb before returning.
drivers/net/wireless/mwifiex/pcie.c +4 -1
@@ -1228,9 +1228,12 @@ static int mwifiex_pcie_event_complete(struct mwifiex_adapter *adapter,if (!skb)return 0 ; -if (rdptr >=MWIFIEX_MAX_EVT_BD ) +if (rdptr >=MWIFIEX_MAX_EVT_BD ) {dev_err (adapter->dev,"event_complete: Invalid rdptr 0x%x\n" , rdptr); + ret = -EINVAL ; + goto done; + }/* Read the event ring write pointer set by firmware */ if (mwifiex_read_reg (adapter,REG_EVTBD_WRPTR , &wrptr)) {
RE: [patch 3/4 v2] mwifiex: prevent corruption instead of just
Hi Dan,
Thanks for the patch.
Quoted 7 lines
-----Original Message-----
From: Dan Carpenter [mailto:[email protected]]
Sent: Wednesday, October 19, 2011 12:32 AM
To: Bing Zhao
Cc: John W. Linville; [email protected]; [email protected]
Subject: [patch 3/4 v2] mwifiex: prevent corruption instead of just warning
Quoted 5 lines
Probably we never hit this condition, but in case we do, we may as well put a return here instead of just printing a warning message and then corrupting memory. The caller doesn't check the return code.
Signed-off-by Dan Carpenter <[email protected]>
Regards,
Bing
Quoted 21 lines
---
v2: Use the error handling code to free the skb before returning.drivers/net/wireless/mwifiex/pcie.c +4
-1@@ -1228,9 +1228,12 @@ static int mwifiex_pcie_event_complete(struct mwifiex_adapter *adapter,if (!skb)return 0 ; -if (rdptr >=MWIFIEX_MAX_EVT_BD ) +if (rdptr >=MWIFIEX_MAX_EVT_BD ) {dev_err (adapter->dev,"event_complete: Invalid rdptr 0x%x\n" , rdptr); + ret = -EINVAL ; + goto done; + }/* Read the event ring write pointer set by firmware */ if (mwifiex_read_reg (adapter,REG_EVTBD_WRPTR , &wrptr)) {