Commit cdaf25df authored by Dan Carpenter's avatar Dan Carpenter Committed by David S. Miller

smc: some potential use after free bugs

Say we got really unlucky and these failed on the last iteration, then
it could lead to a use after free bug.

Fixes: cd6851f3 ("smc: remote memory buffers (RMBs)")
Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarUrsula Braun <ubraun@linux.vnet.ibm.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1930b603
...@@ -532,6 +532,7 @@ int smc_sndbuf_create(struct smc_sock *smc) ...@@ -532,6 +532,7 @@ int smc_sndbuf_create(struct smc_sock *smc)
__GFP_NORETRY); __GFP_NORETRY);
if (!sndbuf_desc->cpu_addr) { if (!sndbuf_desc->cpu_addr) {
kfree(sndbuf_desc); kfree(sndbuf_desc);
sndbuf_desc = NULL;
/* if send buffer allocation has failed, /* if send buffer allocation has failed,
* try a smaller one * try a smaller one
*/ */
...@@ -543,6 +544,7 @@ int smc_sndbuf_create(struct smc_sock *smc) ...@@ -543,6 +544,7 @@ int smc_sndbuf_create(struct smc_sock *smc)
if (rc) { if (rc) {
kfree(sndbuf_desc->cpu_addr); kfree(sndbuf_desc->cpu_addr);
kfree(sndbuf_desc); kfree(sndbuf_desc);
sndbuf_desc = NULL;
continue; /* if mapping failed, try smaller one */ continue; /* if mapping failed, try smaller one */
} }
sndbuf_desc->used = 1; sndbuf_desc->used = 1;
...@@ -596,6 +598,7 @@ int smc_rmb_create(struct smc_sock *smc) ...@@ -596,6 +598,7 @@ int smc_rmb_create(struct smc_sock *smc)
__GFP_NORETRY); __GFP_NORETRY);
if (!rmb_desc->cpu_addr) { if (!rmb_desc->cpu_addr) {
kfree(rmb_desc); kfree(rmb_desc);
rmb_desc = NULL;
/* if RMB allocation has failed, /* if RMB allocation has failed,
* try a smaller one * try a smaller one
*/ */
...@@ -607,6 +610,7 @@ int smc_rmb_create(struct smc_sock *smc) ...@@ -607,6 +610,7 @@ int smc_rmb_create(struct smc_sock *smc)
if (rc) { if (rc) {
kfree(rmb_desc->cpu_addr); kfree(rmb_desc->cpu_addr);
kfree(rmb_desc); kfree(rmb_desc);
rmb_desc = NULL;
continue; /* if mapping failed, try smaller one */ continue; /* if mapping failed, try smaller one */
} }
rc = smc_ib_get_memory_region(lgr->lnk[SMC_SINGLE_LINK].roce_pd, rc = smc_ib_get_memory_region(lgr->lnk[SMC_SINGLE_LINK].roce_pd,
...@@ -619,6 +623,7 @@ int smc_rmb_create(struct smc_sock *smc) ...@@ -619,6 +623,7 @@ int smc_rmb_create(struct smc_sock *smc)
DMA_FROM_DEVICE); DMA_FROM_DEVICE);
kfree(rmb_desc->cpu_addr); kfree(rmb_desc->cpu_addr);
kfree(rmb_desc); kfree(rmb_desc);
rmb_desc = NULL;
continue; continue;
} }
rmb_desc->used = 1; rmb_desc->used = 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment