diff mbox series

net: liquidio: fix NULL pointer dereferences

Message ID 20190311054615.11760-1-kjlu@umn.edu
State Changes Requested
Delegated to: David Miller
Headers show
Series net: liquidio: fix NULL pointer dereferences | expand

Commit Message

Kangjie Lu March 11, 2019, 5:46 a.m. UTC
In case octeon_alloc_soft_command fails, the fix reports the
error and returns to avoid NULL pointer dereferences.

Signed-off-by: Kangjie Lu <kjlu@umn.edu>
---
 drivers/net/ethernet/cavium/liquidio/lio_vf_main.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

David Miller March 11, 2019, 7:17 p.m. UTC | #1
From: Kangjie Lu <kjlu@umn.edu>
Date: Mon, 11 Mar 2019 00:46:15 -0500

> @@ -1960,6 +1966,12 @@ static int setup_nic_devices(struct octeon_device *octeon_dev)
>  		sc = (struct octeon_soft_command *)
>  			octeon_alloc_soft_command(octeon_dev, data_size,
>  						  resp_size, 0);
> +		if (!sc) {
> +			dev_err(&octeon_dev->pci_dev->dev,
> +				"Failed to allocate octeon_soft_command\n");
> +			return -ENOMEM;
> +		}

Again, very sloppy.  You have to branch to setup_nic_dev_free in this situation
otherwise you leak devices allocated and setup from previous iterations of the
loop this code is in.
Kangjie Lu March 12, 2019, 5:26 a.m. UTC | #2
> On Mar 11, 2019, at 2:17 PM, David Miller <davem@davemloft.net> wrote:
> 
> From: Kangjie Lu <kjlu@umn.edu>
> Date: Mon, 11 Mar 2019 00:46:15 -0500
> 
>> @@ -1960,6 +1966,12 @@ static int setup_nic_devices(struct octeon_device *octeon_dev)
>> 		sc = (struct octeon_soft_command *)
>> 			octeon_alloc_soft_command(octeon_dev, data_size,
>> 						  resp_size, 0);
>> +		if (!sc) {
>> +			dev_err(&octeon_dev->pci_dev->dev,
>> +				"Failed to allocate octeon_soft_command\n");
>> +			return -ENOMEM;
>> +		}
> 
> Again, very sloppy.  You have to branch to setup_nic_dev_free in this situation
> otherwise you leak devices allocated and setup from previous iterations of the
> loop this code is in.

I was referring to how the following code handles errors. 
Does that mean that the returns at line 2004, 2012, and 2019 are also leaking 
devices?

>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c b/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c
index 54b245797d2e..cc081cda847c 100644
--- a/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c
+++ b/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c
@@ -611,6 +611,12 @@  static void send_rx_ctrl_cmd(struct lio *lio, int start_stop)
 	sc = (struct octeon_soft_command *)
 		octeon_alloc_soft_command(oct, OCTNET_CMD_SIZE,
 					  16, 0);
+	if (!sc) {
+		netif_info(lio, rx_err, lio->netdev,
+			   "Failed to allocate octeon_soft_command\n");
+		return;
+	}
+
 
 	ncmd = (union octnet_cmd *)sc->virtdptr;
 
@@ -1960,6 +1966,12 @@  static int setup_nic_devices(struct octeon_device *octeon_dev)
 		sc = (struct octeon_soft_command *)
 			octeon_alloc_soft_command(octeon_dev, data_size,
 						  resp_size, 0);
+		if (!sc) {
+			dev_err(&octeon_dev->pci_dev->dev,
+				"Failed to allocate octeon_soft_command\n");
+			return -ENOMEM;
+		}
+
 		resp = (struct liquidio_if_cfg_resp *)sc->virtrptr;
 		vdata = (struct lio_version *)sc->virtdptr;