xrpcrdma: add missing error checks in rpcrdma_ep_destroy
Subsystems (3)
PATCH 1/1 xrpcrdma: add missing error checks in rpcrdma_ep_destroy
These pointers can be non-NULL and contain errors if initialization is aborted early. This is similar to how __svc_rdma_free takes care of it.
--- net/sunrpc/xprtrdma/verbs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/sunrpc/xprtrdma/verbs.c +3 -3
@@ -336,14 +336,14 @@ static void rpcrdma_ep_destroy(struct kref *kref) ep->re_id->qp =NULL ; } -if (ep->re_attr.recv_cq) +if (ep->re_attr.recv_cq && !IS_ERR (ep->re_attr.recv_cq))ib_free_cq (ep->re_attr.recv_cq); ep->re_attr.recv_cq =NULL ; -if (ep->re_attr.send_cq) +if (ep->re_attr.send_cq && !IS_ERR (ep->re_attr.send_cq))ib_free_cq (ep->re_attr.send_cq); ep->re_attr.send_cq =NULL ; -if (ep->re_pd) +if (ep->re_pd && !IS_ERR (ep->re_pd))ib_dealloc_pd (ep->re_pd); ep->re_pd =NULL ;
Signature · 1 line
2.23.0
Quoted 7 lines · Dan Aloni
These pointers can be non-NULL and contain errors if initialization is aborted early. This is similar to how
__svc_rdma_freetakes care of it.
IIUC the only place that can set these values to an ERR_PTR is rpcrdma_ep_create() ? I think I'd rather have rpcrdma_ep_create() set the fields to NULL in the error cases.
Good catch. I'm afraid to ask how you found this.
Quoted 30 lines
Signed-off-by Dan Aloni <[email protected]>---
net/sunrpc/xprtrdma/verbs.c| 6 +++---1 file changed, 3 insertions(+), 3 deletions(-)net/sunrpc/xprtrdma/verbs.c +3
-3@@ -336,14 +336,14 @@ static void rpcrdma_ep_destroy(struct kref *kref) ep->re_id->qp =NULL ; } -if (ep->re_attr.recv_cq) +if (ep->re_attr.recv_cq && !IS_ERR (ep->re_attr.recv_cq))ib_free_cq (ep->re_attr.recv_cq); ep->re_attr.recv_cq =NULL ; -if (ep->re_attr.send_cq) +if (ep->re_attr.send_cq && !IS_ERR (ep->re_attr.send_cq))ib_free_cq (ep->re_attr.send_cq); ep->re_attr.send_cq =NULL ; -if (ep->re_pd) +if (ep->re_pd && !IS_ERR (ep->re_pd))ib_dealloc_pd (ep->re_pd); ep->re_pd =NULL ;Signature · 1 line
2.23.0
--
Chuck Lever
Quoted 4 lines · Chuck Lever III
Quoted 4 lines · Dan Aloni
Quoted 8 lines
Quoted 3 lines
These pointers can be non-NULL and contain errors if initialization is aborted early. This is similar to how
__svc_rdma_freetakes care of it.IIUC the only place that can set these values to an
ERR_PTRisrpcrdma_ep_create()? I think I'd rather haverpcrdma_ep_create()set the fields to NULL in the error cases.
Actually that was my initialization draft but then I saw __svc_rdma_free. Will send over.
Quoted 1 line
Good catch. I'm afraid to ask how you found this.
Just some adapter entering error state in firmware.
Signature · 1 line
Dan Aloni
PATCH 1/1 xprtrdma: fix pointer derefs in error cases of rpcrdma_ep_create
In reply to Chuck Lever IIIIf there are failures then we must not leave the non-NULL pointers with the error value, otherwise rpcrdma_ep_destroy gets confused and tries free them, resulting in an Oops.
--- net/sunrpc/xprtrdma/verbs.c | 3 +++ 1 file changed, 3 insertions(+)
net/sunrpc/xprtrdma/verbs.c +3 -0
@@ -436,6 +436,7 @@ static int rpcrdma_ep_create(struct rpcrdma_xprt *r_xprt) IB_POLL_WORKQUEUE);if (IS_ERR (ep->re_attr.send_cq)) { rc =PTR_ERR (ep->re_attr.send_cq); + ep->re_attr.send_cq =NULL ; goto out_destroy; }
@@ -444,6 +445,7 @@ static int rpcrdma_ep_create(struct rpcrdma_xprt *r_xprt) IB_POLL_WORKQUEUE);if (IS_ERR (ep->re_attr.recv_cq)) { rc =PTR_ERR (ep->re_attr.recv_cq); + ep->re_attr.recv_cq =NULL ; goto out_destroy; } ep->re_receive_count =0 ;
@@ -482,6 +484,7 @@ static int rpcrdma_ep_create(struct rpcrdma_xprt *r_xprt) ep->re_pd =ib_alloc_pd (device,0 );if (IS_ERR (ep->re_pd)) { rc =PTR_ERR (ep->re_pd); + ep->re_pd =NULL ; goto out_destroy; }
Signature · 1 line
2.23.0
Re: [PATCH] xprtrdma: fix pointer derefs in error cases of rpcrdma_ep_create
Hi Anna-
Quoted 7 lines · Dan Aloni
If there are failures then we must not leave the non-NULL pointers with the error value, otherwise
rpcrdma_ep_destroygets confused and tries free them, resulting in an Oops.Signed-off-by Dan Aloni <[email protected]>
Quoted 35 lines
---
net/sunrpc/xprtrdma/verbs.c| 3 +++1 file changed, 3 insertions(+)net/sunrpc/xprtrdma/verbs.c +3
-0@@ -436,6 +436,7 @@ static int rpcrdma_ep_create(struct rpcrdma_xprt *r_xprt) IB_POLL_WORKQUEUE);if (IS_ERR (ep->re_attr.send_cq)) { rc =PTR_ERR (ep->re_attr.send_cq); + ep->re_attr.send_cq =NULL ; goto out_destroy; }@@ -444,6 +445,7 @@ static int rpcrdma_ep_create(struct rpcrdma_xprt *r_xprt) IB_POLL_WORKQUEUE);if (IS_ERR (ep->re_attr.recv_cq)) { rc =PTR_ERR (ep->re_attr.recv_cq); + ep->re_attr.recv_cq =NULL ; goto out_destroy; } ep->re_receive_count =0 ;@@ -482,6 +484,7 @@ static int rpcrdma_ep_create(struct rpcrdma_xprt *r_xprt) ep->re_pd =ib_alloc_pd (device,0 );if (IS_ERR (ep->re_pd)) { rc =PTR_ERR (ep->re_pd); + ep->re_pd =NULL ; goto out_destroy; }Signature · 1 line
2.23.0
--
Chuck Lever