From patchwork Sun Dec 24 08:24:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhipeng Lu X-Patchwork-Id: 183036 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp2036957dyi; Sun, 24 Dec 2023 00:25:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IF3r0zfldRt05bR3hpoWLNTApbHs4u67olkeLREdNO2d9raG42HurjKXPGXbxvitqYLbmdq X-Received: by 2002:a05:6a00:909a:b0:6d9:9612:e455 with SMTP id jo26-20020a056a00909a00b006d99612e455mr1363430pfb.22.1703406346422; Sun, 24 Dec 2023 00:25:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703406346; cv=none; d=google.com; s=arc-20160816; b=BY2otAz+S8mQqfOHBzgguam3sNKavsQRW6nb+8QlpcO5UvbmLiSsLb8WWz+66y72jW ugPSk22M8Z0HVarB4I/Q0Oz8P2I5o2nNvOSvMkKYh+zJaDf2qSTCXbcD99p50vh/P0r9 CqQyqi9SkrDwuJNuyqY42bv1V+RrzWXXFgFH9yLUeqk9R9KyAamkFyS8640MrNPsBBmN DGwRLoVcaiND1hVkOkOsElDxn9eBO4pZSmNzlDK5RnzTFPTwyTIc0i8/uNUJV48KhDXR U0G9TaUTB+u6L6Hcv0iCU9g+azGb+WrB3W0nr6oZhHnh2YgMn9Gr9q8209lI7rroGqlV nJxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=lHD5kuT9xlgtEx5gADIVuZKzw6spr/++Kgrw9rRtEYM=; fh=TcvqGbvduZXr6CspQPmBrI84LVdDDgzeEPyar4o/eTM=; b=oIhFuQmxbAUM+DWQCxRDK35rmAaU0p9ZVWIepbh7ikQAxx9HK6TYgZLogV9gJk0Yi/ MqpbfCY1CeWIS+6t799MFBarbd9cGwyGPpVKPomjJHfeASrxUFWPJ/lSI+qSOzUWYPJ4 7q+x4LxAovWpZA7W8Oxng0x8LLgoAb8e2PtRh4m6muy5SInO3+hLegKlkY6levM4raTf fC0GVh1dZJrraEdAXYoimIkxlmoJBZhioNNQlMZSslAWEDYQYm3XgQnzsaT4c8eEPRxM miLchwzjSep7xR404KwbD17ad+nkOh7htZO37So1LUEA7xjZxfFa26/6bV/AatXKWGt9 Wuew== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-10657-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10657-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id j2-20020aa78002000000b006d98b964333si3621673pfi.30.2023.12.24.00.25.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Dec 2023 00:25:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10657-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-10657-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10657-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 791B8B21551 for ; Sun, 24 Dec 2023 08:25:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C8C8823C3; Sun, 24 Dec 2023 08:25:26 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from zg8tndyumtaxlji0oc4xnzya.icoremail.net (zg8tndyumtaxlji0oc4xnzya.icoremail.net [46.101.248.176]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D730E20E0; Sun, 24 Dec 2023 08:25:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zju.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zju.edu.cn Received: from luzhipeng.223.5.5.5 (unknown [122.235.137.177]) by mail-app3 (Coremail) with SMTP id cC_KCgCHjBnQ6odlNstjAQ--.7480S2; Sun, 24 Dec 2023 16:24:48 +0800 (CST) From: Zhipeng Lu To: alexious@zju.edu.cn Cc: Chuck Lever , Jeff Layton , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "J. Bruce Fields" , Simo Sorce , linux-nfs@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] SUNRPC: fix some memleaks in gssx_dec_option_array Date: Sun, 24 Dec 2023 16:24:22 +0800 Message-Id: <20231224082424.3539726-1-alexious@zju.edu.cn> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cC_KCgCHjBnQ6odlNstjAQ--.7480S2 X-Coremail-Antispam: 1UD129KBjvJXoW7Ar48AFWkWw48KrykAr1xAFb_yoW8Cw18pF Z3Kr98AF1Iqr1xJF1aywsYv3WYyFs5tFW7Wry2kanxZw1fJr1F9w4vkryjgF1ayrZ3uw1U W3WUury8uwn0yFUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvK14x267AKxVW5JVWrJwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4U JVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gc CE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_Jrv_JF1lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7CjxVA2 Y2ka0xkIwI1lc2xSY4AK67AK6r43MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r 1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CE b7AF67AKxVW8ZVWrXwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0x vE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF 0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxh VjvjDU0xZFpf9x0JU6T5dUUUUU= X-CM-SenderInfo: qrsrjiarszq6lmxovvfxof0/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786151013276416301 X-GMAIL-MSGID: 1786151013276416301 The creds and oa->data need to be freed in the error-handling paths after there allocation. So this patch add these deallocations in the corresponding paths. Fixes: 1d658336b05f ("SUNRPC: Add RPC based upcall mechanism for RPCGSS auth") Signed-off-by: Zhipeng Lu --- net/sunrpc/auth_gss/gss_rpc_xdr.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/net/sunrpc/auth_gss/gss_rpc_xdr.c b/net/sunrpc/auth_gss/gss_rpc_xdr.c index d79f12c2550a..de533b20231b 100644 --- a/net/sunrpc/auth_gss/gss_rpc_xdr.c +++ b/net/sunrpc/auth_gss/gss_rpc_xdr.c @@ -250,8 +250,8 @@ static int gssx_dec_option_array(struct xdr_stream *xdr, creds = kzalloc(sizeof(struct svc_cred), GFP_KERNEL); if (!creds) { - kfree(oa->data); - return -ENOMEM; + err = -ENOMEM; + goto free_oa; } oa->data[0].option.data = CREDS_VALUE; @@ -265,29 +265,41 @@ static int gssx_dec_option_array(struct xdr_stream *xdr, /* option buffer */ p = xdr_inline_decode(xdr, 4); - if (unlikely(p == NULL)) - return -ENOSPC; + if (unlikely(p == NULL)) { + err = -ENOSPC + goto free_creds; + } length = be32_to_cpup(p); p = xdr_inline_decode(xdr, length); - if (unlikely(p == NULL)) - return -ENOSPC; + if (unlikely(p == NULL)) { + err = -ENOSPC + goto free_creds; + } if (length == sizeof(CREDS_VALUE) && memcmp(p, CREDS_VALUE, sizeof(CREDS_VALUE)) == 0) { /* We have creds here. parse them */ err = gssx_dec_linux_creds(xdr, creds); if (err) - return err; + goto free_creds; oa->data[0].value.len = 1; /* presence */ } else { /* consume uninteresting buffer */ err = gssx_dec_buffer(xdr, &dummy); if (err) - return err; + goto free_creds; } } return 0; + +free_creds: + kfree(creds); +free_oa: + kfree(oa->data); + oa->data = NULL; +err: + return err; } static int gssx_dec_status(struct xdr_stream *xdr,