]> git.baikalelectronics.ru Git - kernel.git/commitdiff
SUNRPC: Handle allocation failure in rpc_new_task()
authorTrond Myklebust <trond.myklebust@hammerspace.com>
Thu, 7 Apr 2022 02:36:19 +0000 (22:36 -0400)
committerTrond Myklebust <trond.myklebust@hammerspace.com>
Thu, 7 Apr 2022 20:20:00 +0000 (16:20 -0400)
If the call to rpc_alloc_task() fails, then ensure that the calldata is
released, and that rpc_run_task() and rpc_run_bc_task() bail out early.

Reported-by: NeilBrown <neilb@suse.de>
Fixes: 5543d8f2d30f ("NFS: Fix memory allocation in rpc_alloc_task()")
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
net/sunrpc/clnt.c
net/sunrpc/sched.c

index 6757b0fa5367c83e6623d1f725f35682d109c7d2..af0174d7ce5a8a4373151f62ec5ccf7d1141a89c 100644 (file)
@@ -1127,6 +1127,8 @@ struct rpc_task *rpc_run_task(const struct rpc_task_setup *task_setup_data)
        struct rpc_task *task;
 
        task = rpc_new_task(task_setup_data);
+       if (IS_ERR(task))
+               return task;
 
        if (!RPC_IS_ASYNC(task))
                task->tk_flags |= RPC_TASK_CRED_NOREF;
@@ -1227,6 +1229,11 @@ struct rpc_task *rpc_run_bc_task(struct rpc_rqst *req)
         * Create an rpc_task to send the data
         */
        task = rpc_new_task(&task_setup_data);
+       if (IS_ERR(task)) {
+               xprt_free_bc_request(req);
+               return task;
+       }
+
        xprt_init_bc_request(req, task);
 
        task->tk_action = call_bc_encode;
index b258b87a3ec22c54bc2f815e7db27b8d7eacf5d6..7f70c1e608b7ce4f07f3651e70a764050c292dc5 100644 (file)
@@ -1128,6 +1128,11 @@ struct rpc_task *rpc_new_task(const struct rpc_task_setup *setup_data)
 
        if (task == NULL) {
                task = rpc_alloc_task();
+               if (task == NULL) {
+                       rpc_release_calldata(setup_data->callback_ops,
+                                            setup_data->callback_data);
+                       return ERR_PTR(-ENOMEM);
+               }
                flags = RPC_TASK_DYNAMIC;
        }