* [PATCH] net: liquidio: fix NULL pointer dereferences @ 2019-03-11 5:46 Kangjie Lu 2019-03-11 19:17 ` David Miller 0 siblings, 1 reply; 6+ messages in thread From: Kangjie Lu @ 2019-03-11 5:46 UTC (permalink / raw) To: kjlu Cc: pakki001, Derek Chickles, Satanand Burla, Felix Manlunas, David S. Miller, netdev, linux-kernel 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(+) 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; -- 2.17.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] net: liquidio: fix NULL pointer dereferences 2019-03-11 5:46 [PATCH] net: liquidio: fix NULL pointer dereferences Kangjie Lu @ 2019-03-11 19:17 ` David Miller 2019-03-12 5:26 ` Kangjie Lu 2019-03-23 3:24 ` [PATCH v2] " Kangjie Lu 0 siblings, 2 replies; 6+ messages in thread From: David Miller @ 2019-03-11 19:17 UTC (permalink / raw) To: kjlu; +Cc: pakki001, dchickles, sburla, fmanlunas, netdev, linux-kernel 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. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] net: liquidio: fix NULL pointer dereferences 2019-03-11 19:17 ` David Miller @ 2019-03-12 5:26 ` Kangjie Lu 2019-03-23 3:24 ` [PATCH v2] " Kangjie Lu 1 sibling, 0 replies; 6+ messages in thread From: Kangjie Lu @ 2019-03-12 5:26 UTC (permalink / raw) To: David Miller; +Cc: pakki001, dchickles, sburla, fmanlunas, netdev, linux-kernel > 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? > ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] net: liquidio: fix NULL pointer dereferences 2019-03-11 19:17 ` David Miller 2019-03-12 5:26 ` Kangjie Lu @ 2019-03-23 3:24 ` Kangjie Lu 2019-03-25 12:41 ` Ulf Hansson 2019-03-26 0:14 ` David Miller 1 sibling, 2 replies; 6+ messages in thread From: Kangjie Lu @ 2019-03-23 3:24 UTC (permalink / raw) To: kjlu Cc: pakki001, Ulf Hansson, Derek Chickles, Satanand Burla, Felix Manlunas, David S. Miller, Linus Walleij, Laurent Pinchart, Jonathan Neuschäfer, linux-mmc, linux-kernel, netdev In case octeon_alloc_soft_command fails, the fix reports the error and goes to cleanup to avoid NULL pointer dereferences. Signed-off-by: Kangjie Lu <kjlu@umn.edu> --- V2: goto setup_nic_dev_free for cleanup --- drivers/mmc/host/mmc_spi.c | 2 +- drivers/net/ethernet/cavium/liquidio/lio_vf_main.c | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c index 32fea585262b..a3533935e282 100644 --- a/drivers/mmc/host/mmc_spi.c +++ b/drivers/mmc/host/mmc_spi.c @@ -820,7 +820,7 @@ mmc_spi_readblock(struct mmc_spi_host *host, struct spi_transfer *t, status = spi_sync_locked(spi, &host->m); if (status < 0) { - dev_dbg(&spi->dev, "read error %02x (%d)\n", status, status); + dev_dbg(&spi->dev, "read error %d\n", status); return status; } diff --git a/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c b/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c index 54b245797d2e..e653072846b0 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"); + goto setup_nic_dev_free; + } + resp = (struct liquidio_if_cfg_resp *)sc->virtrptr; vdata = (struct lio_version *)sc->virtdptr; -- 2.17.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2] net: liquidio: fix NULL pointer dereferences 2019-03-23 3:24 ` [PATCH v2] " Kangjie Lu @ 2019-03-25 12:41 ` Ulf Hansson 2019-03-26 0:14 ` David Miller 1 sibling, 0 replies; 6+ messages in thread From: Ulf Hansson @ 2019-03-25 12:41 UTC (permalink / raw) To: Kangjie Lu Cc: pakki001, Derek Chickles, Satanand Burla, Felix Manlunas, David S. Miller, Linus Walleij, Laurent Pinchart, Jonathan Neuschäfer, linux-mmc, Linux Kernel Mailing List, netdev On Sat, 23 Mar 2019 at 04:24, Kangjie Lu <kjlu@umn.edu> wrote: > > In case octeon_alloc_soft_command fails, the fix reports the > error and goes to cleanup to avoid NULL pointer dereferences. > > Signed-off-by: Kangjie Lu <kjlu@umn.edu> > --- > V2: goto setup_nic_dev_free for cleanup > --- > drivers/mmc/host/mmc_spi.c | 2 +- > drivers/net/ethernet/cavium/liquidio/lio_vf_main.c | 12 ++++++++++++ > 2 files changed, 13 insertions(+), 1 deletion(-) > > diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c > index 32fea585262b..a3533935e282 100644 > --- a/drivers/mmc/host/mmc_spi.c > +++ b/drivers/mmc/host/mmc_spi.c > @@ -820,7 +820,7 @@ mmc_spi_readblock(struct mmc_spi_host *host, struct spi_transfer *t, > > status = spi_sync_locked(spi, &host->m); > if (status < 0) { > - dev_dbg(&spi->dev, "read error %02x (%d)\n", status, status); > + dev_dbg(&spi->dev, "read error %d\n", status); Looks like a leftover from debugging? [...] Kind regards Uffe ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] net: liquidio: fix NULL pointer dereferences 2019-03-23 3:24 ` [PATCH v2] " Kangjie Lu 2019-03-25 12:41 ` Ulf Hansson @ 2019-03-26 0:14 ` David Miller 1 sibling, 0 replies; 6+ messages in thread From: David Miller @ 2019-03-26 0:14 UTC (permalink / raw) To: kjlu Cc: pakki001, ulf.hansson, dchickles, sburla, fmanlunas, linus.walleij, laurent.pinchart+renesas, j.neuschaefer, linux-mmc, linux-kernel, netdev From: Kangjie Lu <kjlu@umn.edu> Date: Fri, 22 Mar 2019 22:24:19 -0500 > In case octeon_alloc_soft_command fails, the fix reports the > error and goes to cleanup to avoid NULL pointer dereferences. > > Signed-off-by: Kangjie Lu <kjlu@umn.edu> > --- > V2: goto setup_nic_dev_free for cleanup > --- > drivers/mmc/host/mmc_spi.c | 2 +- > drivers/net/ethernet/cavium/liquidio/lio_vf_main.c | 12 ++++++++++++ > 2 files changed, 13 insertions(+), 1 deletion(-) > > diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c > index 32fea585262b..a3533935e282 100644 > --- a/drivers/mmc/host/mmc_spi.c > +++ b/drivers/mmc/host/mmc_spi.c > @@ -820,7 +820,7 @@ mmc_spi_readblock(struct mmc_spi_host *host, struct spi_transfer *t, > > status = spi_sync_locked(spi, &host->m); > if (status < 0) { > - dev_dbg(&spi->dev, "read error %02x (%d)\n", status, status); > + dev_dbg(&spi->dev, "read error %d\n", status); > return status; > } This is: 1) Unrelated to your bug fix. 2) It is often the case that people print values in hex and decimal intentionally for debugging. I've done this myself countless times. ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-03-26 0:14 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2019-03-11 5:46 [PATCH] net: liquidio: fix NULL pointer dereferences Kangjie Lu 2019-03-11 19:17 ` David Miller 2019-03-12 5:26 ` Kangjie Lu 2019-03-23 3:24 ` [PATCH v2] " Kangjie Lu 2019-03-25 12:41 ` Ulf Hansson 2019-03-26 0:14 ` David Miller
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).