Skip to contentSkip to conversation

SUNRPC: Fix potential memory scribble in xprt_free_bc_request()

PATCH In review Trond Myklebust 2 participants 3 messages Feb 11, 2014 – Feb 12, 2014

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 SUNRPC: Fix potential memory scribble in xprt_free_bc_request()

The call to xprt_free_allocation() will call list_del() on req->rq_bc_pa_list, which is not attached to a list. This patch moves the list_del() out of xprt_free_allocation() and into those callers that need it.

---
 net/sunrpc/backchannel_rqst.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
net/sunrpc/backchannel_rqst.c +4 -2
index 890a29912d5a..e860d4f7ed2a 100644
@@ -64,7 +64,6 @@ static void xprt_free_allocation(struct rpc_rqst *req)
 	free_page((unsigned long)xbufp->head[0].iov_base);
 	xbufp = &req->rq_snd_buf;
 	free_page((unsigned long)xbufp->head[0].iov_base);
-	list_del(&req->rq_bc_pa_list);
 	kfree(req);
 }
 
@@ -168,8 +167,10 @@ out_free:
 	/*
 	 * Memory allocation failed, free the temporary list
 	 */
-	list_for_each_entry_safe(req, tmp, &tmp_list, rq_bc_pa_list)
+	list_for_each_entry_safe(req, tmp, &tmp_list, rq_bc_pa_list) {
+		list_del(&req->rq_bc_pa_list);
 		xprt_free_allocation(req);
+	}
 
 	dprintk("RPC:       setup backchannel transport failed\n");
 	return -ENOMEM;
@@ -198,6 +199,7 @@ void xprt_destroy_backchannel(struct rpc_xprt *xprt, unsigned int max_reqs)
 	xprt_dec_alloc_count(xprt, max_reqs);
 	list_for_each_entry_safe(req, tmp, &xprt->bc_pa_list, rq_bc_pa_list) {
 		dprintk("RPC:        req=%p\n", req);
+		list_del(&req->rq_bc_pa_list);
 		xprt_free_allocation(req);
 		if (--max_reqs == 0)
 			break;
Signature · 1 line
1.8.5.3
#1 lore raw

2014-02-12 3:43 GMT+08:00 Trond Myklebust <[email protected]>:

Quoted 2 lines

The call to xprt_free_allocation() will call list_del() on req->rq_bc_pa_list, which is not attached to a list.

Since the type of req->rq_bc_pa_list is struct list_head, I think it is right on the tmp_list or
the xprt->bc_pa_list. Do I misunderstand sth?

Quoted 47 lines

This patch moves the list_del() out of xprt_free_allocation() and into those callers that need it.

---
 net/sunrpc/backchannel_rqst.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
net/sunrpc/backchannel_rqst.c +4 -3
index 890a29912d5a..e860d4f7ed2a 100644
@@ -64,7 +64,6 @@ static void xprt_free_allocation(struct rpc_rqst *req)
        free_page((unsigned long)xbufp->head[0].iov_base);
        xbufp = &req->rq_snd_buf;
        free_page((unsigned long)xbufp->head[0].iov_base);
-       list_del(&req->rq_bc_pa_list);
        kfree(req);
 }
 
@@ -168,8 +167,10 @@ out_free:
        /*
         * Memory allocation failed, free the temporary list
         */
-       list_for_each_entry_safe(req, tmp, &tmp_list, rq_bc_pa_list)
+       list_for_each_entry_safe(req, tmp, &tmp_list, rq_bc_pa_list) {
+               list_del(&req->rq_bc_pa_list);
                xprt_free_allocation(req);
+       }
 
        dprintk("RPC:       setup backchannel transport failed\n");
        return -ENOMEM;
@@ -198,6 +199,7 @@ void xprt_destroy_backchannel(struct rpc_xprt *xprt, unsigned int max_reqs)
        xprt_dec_alloc_count(xprt, max_reqs);
        list_for_each_entry_safe(req, tmp, &xprt->bc_pa_list, rq_bc_pa_list) {
                dprintk("RPC:        req=%p\n", req);
+               list_del(&req->rq_bc_pa_list);
                xprt_free_allocation(req);
                if (--max_reqs == 0)
                        break;
--

1.8.5.3

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
Quoted 7 lines · shaobingqing

2014-02-12 3:43 GMT+08:00 Trond Myklebust <[email protected]>:

Quoted 2 lines

The call to xprt_free_allocation() will call list_del() on req->rq_bc_pa_list, which is not attached to a list.

Since the type of req->rq_bc_pa_list is struct list_head, I think it is right on the tmp_list or
the xprt->bc_pa_list. Do I misunderstand sth?

Not when xprt_free_bc_request() calls xprt_free_allocation().

Quoted 2 lines
Quoted 2 lines

This patch moves the list_del() out of xprt_free_allocation() and into those callers that need it.

…and the point is that we do not add the list_del() to xprt_free_bc_request().

_________________________________
Trond Myklebust
Linux NFS client maintainer, PrimaryData
[email protected]