xprtrdma: Double free in rpcrdma_sendctxs_create()
Subsystems (4)
PATCH 2/2 xprtrdma: Double free in rpcrdma_sendctxs_create()
The clean up is handled by the caller, rpcrdma_buffer_create(), so this call to rpcrdma_sendctxs_destroy() leads to a double free.
--- net/sunrpc/xprtrdma/verbs.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
net/sunrpc/xprtrdma/verbs.c +1 -5
@@ -845,17 +845,13 @@ static int rpcrdma_sendctxs_create(struct rpcrdma_xprt *r_xprt)for (i =0 ; i <= buf->rb_sc_last; i++) { sc =rpcrdma_sendctx_create (&r_xprt->rx_ia);if (!sc) - goto out_destroy; +return -ENOMEM ; sc->sc_xprt = r_xprt; buf->rb_sc_ctxs[i] = sc; }return 0 ; - -out_destroy: -rpcrdma_sendctxs_destroy (buf); -return -ENOMEM ; }/* The sendctx queue is not guaranteed to have a size that is a
Signature · 1 line
2.17.1
Quoted 5 lines · Dan Carpenter
The clean up is handled by the caller,
rpcrdma_buffer_create(), so this call torpcrdma_sendctxs_destroy()leads to a double free.
True. This fix is adequate, but I'm wondering if rpcrdma_sendctxs_destroy should be made more careful about being called twice. Hm.
Quoted 32 lines
Fixes ae72950abf99 ("xprtrdma: Add data structure to manage RDMA Send arguments")Signed-off-by Dan Carpenter <[email protected]>---
net/sunrpc/xprtrdma/verbs.c| 6 +-----1 file changed, 1 insertion(+), 5 deletions(-)net/sunrpc/xprtrdma/verbs.c +1
-5@@ -845,17 +845,13 @@ static int rpcrdma_sendctxs_create(struct rpcrdma_xprt *r_xprt)for (i =0 ; i <= buf->rb_sc_last; i++) { sc =rpcrdma_sendctx_create (&r_xprt->rx_ia);if (!sc) - goto out_destroy; +return -ENOMEM ; sc->sc_xprt = r_xprt; buf->rb_sc_ctxs[i] = sc; }return 0 ; - -out_destroy: -rpcrdma_sendctxs_destroy (buf); -return -ENOMEM ; }/* The sendctx queue is not guaranteed to have a size that is a Signature · 1 line
2.17.1
--
Chuck Lever
Quoted 10 lines · Chuck Lever
Quoted 5 lines · Dan Carpenter
The clean up is handled by the caller,
rpcrdma_buffer_create(), so this call torpcrdma_sendctxs_destroy()leads to a double free.True. This fix is adequate, but I'm wondering if
rpcrdma_sendctxs_destroyshould be made more careful about being called twice. Hm.Reviewed-by Chuck Lever <[email protected]>
I'm assuming Trond or Anna will pick this up.--b.
Quoted 39 lines
Quoted 34 lines
Fixes ae72950abf99 ("xprtrdma: Add data structure to manage RDMA Send arguments")Signed-off-by Dan Carpenter <[email protected]>---
net/sunrpc/xprtrdma/verbs.c| 6 +-----1 file changed, 1 insertion(+), 5 deletions(-)net/sunrpc/xprtrdma/verbs.c +1
-5@@ -845,17 +845,13 @@ static int rpcrdma_sendctxs_create(struct rpcrdma_xprt *r_xprt)for (i =0 ; i <= buf->rb_sc_last; i++) { sc =rpcrdma_sendctx_create (&r_xprt->rx_ia);if (!sc) - goto out_destroy; +return -ENOMEM ; sc->sc_xprt = r_xprt; buf->rb_sc_ctxs[i] = sc; }return 0 ; - -out_destroy: -rpcrdma_sendctxs_destroy (buf); -return -ENOMEM ; }/* The sendctx queue is not guaranteed to have a size that is a Signature · 1 line
2.17.1--
Chuck Lever
DQpPbiBNb24sIDIwMTktMDEtMDcgYXQgMTI6MjIgLTA1MDAsIEJydWNlIEZpZWxkcyB3cm90ZToN Cj4gT24gU2F0LCBKYW4gMDUsIDIwMTkgYXQgMTE6MjQ6NDVBTSAtMDUwMCwgQ2h1Y2sgTGV2ZXIg d3JvdGU6DQo+ID4gPiBPbiBKYW4gNSwgMjAxOSwgYXQgODowNiBBTSwgRGFuIENhcnBlbnRlciA8 ZGFuLmNhcnBlbnRlckBvcmFjbGUuY29tPg0KPiA+ID4gd3JvdGU6DQo+ID4gPiANCj4gPiA+IFRo ZSBjbGVhbiB1cCBpcyBoYW5kbGVkIGJ5IHRoZSBjYWxsZXIsIHJwY3JkbWFfYnVmZmVyX2NyZWF0 ZSgpLCBzbyB0aGlzDQo+ID4gPiBjYWxsIHRvIHJwY3JkbWFfc2Vu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IA0K
Quoted 9 lines · Chuck Lever
Quoted 5 lines · Dan Carpenter
The clean up is handled by the caller,
rpcrdma_buffer_create(), so this call torpcrdma_sendctxs_destroy()leads to a double free.True. This fix is adequate, but I'm wondering if
rpcrdma_sendctxs_destroyshould be made more careful about being called twice. Hm.
I actually wrote the patch like that originally, but then this way made for an easier patch description so I re-wrote it. Let me send the other patch and you can apply that or both if you want.
regards,
dan carpenter
PATCH 1/1 xprtrdma: Make rpcrdma_sendctxs_destroy() more robust
In reply to Chuck LeverThere was a double free in the error handling here recently. It was a bit subtle which function was supposed to call rpcrdma_sendctxs_destroy() so it was called in both.
This patch makes it so we can call rpcrdma_sendctxs_destroy() twice in a row without crashing.
--- net/sunrpc/xprtrdma/verbs.c | 3 +++ 1 file changed, 3 insertions(+)
net/sunrpc/xprtrdma/verbs.c +3 -0
@@ -802,9 +802,12 @@ static void rpcrdma_sendctxs_destroy(struct rpcrdma_buffer *buf) {unsigned long i; +if (!buf->rb_sc_ctxs) +return ;for (i =0 ; i <= buf->rb_sc_last; i++)kfree (buf->rb_sc_ctxs[i]);kfree (buf->rb_sc_ctxs); + buf->rb_sc_ctxs =NULL ; }static struct rpcrdma_sendctx *rpcrdma_sendctx_create (struct rpcrdma_ia *ia)
Signature · 1 line
2.17.1
Re: [PATCH] xprtrdma: Make rpcrdma_sendctxs_destroy() more robust
Quoted 10 lines · Dan Carpenter
There was a double free in the error handling here recently. It was a bit subtle which function was supposed to call
rpcrdma_sendctxs_destroy()so it was called in both.This patch makes it so we can call
rpcrdma_sendctxs_destroy()twice in a row without crashing.
Belt-and-braces. I think the other patch "must" be applied, and this one "should" be applied.
Quoted 25 lines
Signed-off-by Dan Carpenter <[email protected]>---
net/sunrpc/xprtrdma/verbs.c| 3 +++1 file changed, 3 insertions(+)net/sunrpc/xprtrdma/verbs.c +3
-0@@ -802,9 +802,12 @@ static void rpcrdma_sendctxs_destroy(struct rpcrdma_buffer *buf) {unsigned long i; +if (!buf->rb_sc_ctxs) +return ;for (i =0 ; i <= buf->rb_sc_last; i++)kfree (buf->rb_sc_ctxs[i]);kfree (buf->rb_sc_ctxs); + buf->rb_sc_ctxs =NULL ; }static struct rpcrdma_sendctx *rpcrdma_sendctx_create (struct rpcrdma_ia *ia)Signature · 1 line
2.17.1
--
Chuck Lever