From patchwork Thu Apr 7 18:45:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 12805619 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EDE4FC4332F for ; Thu, 7 Apr 2022 18:52:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230229AbiDGSye (ORCPT ); Thu, 7 Apr 2022 14:54:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347013AbiDGSya (ORCPT ); Thu, 7 Apr 2022 14:54:30 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6508196096 for ; Thu, 7 Apr 2022 11:52:29 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 98BF6B82970 for ; Thu, 7 Apr 2022 18:52:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37D88C385A0 for ; Thu, 7 Apr 2022 18:52:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649357547; bh=xdv+jPjcRgWYaV6oupqdJ5g63CNqVsQ8fEK8trdMFHM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=D/jJiIFeMF8394isyd5lVsivHmKxUHO8IqBH2Ly+zJNlyut+Ji2bKZtabz18tTdSE jhpEnbFbl6EFevmRwZvAiZLyGtYV+kqcs2VwnLLSCQ2EChvEzuUgdQptKlTR5cog2m uY3n2Zot9Q1GVH2z0cYU7zBB0DcNgVuBVCORbvPs7oKyir4BFfn+e1fYf1dnBiUZV7 9FMS52KKfJrGMALMzsvu3+sDfWO2EycVu0vKSss+KWkM0GQcY1F2ed4GBTBP2pVjfj ldYV5fVjgSnL7B2Kc151rtFeHSvSI+HVP1X8Iy9ZYVCX8b5IVOA5kGB4BNzxHHf6LC gvTlo7I0ZuaGw== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH v2 6/8] SUNRPC: Handle allocation failure in rpc_new_task() Date: Thu, 7 Apr 2022 14:45:59 -0400 Message-Id: <20220407184601.1064640-6-trondmy@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220407184601.1064640-5-trondmy@kernel.org> References: <20220407184601.1064640-1-trondmy@kernel.org> <20220407184601.1064640-2-trondmy@kernel.org> <20220407184601.1064640-3-trondmy@kernel.org> <20220407184601.1064640-4-trondmy@kernel.org> <20220407184601.1064640-5-trondmy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust 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 Fixes: 910ad38697d9 ("NFS: Fix memory allocation in rpc_alloc_task()") Signed-off-by: Trond Myklebust --- net/sunrpc/clnt.c | 7 +++++++ net/sunrpc/sched.c | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c index 6757b0fa5367..af0174d7ce5a 100644 --- a/net/sunrpc/clnt.c +++ b/net/sunrpc/clnt.c @@ -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; diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c index b258b87a3ec2..7f70c1e608b7 100644 --- a/net/sunrpc/sched.c +++ b/net/sunrpc/sched.c @@ -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; }