Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6361739rdb; Mon, 1 Jan 2024 21:44:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IEcIJJQPitwcQ1w409MjWGW7csjriUre/LmZ9DBY00sZ2d7E4RZ0KlHS/Te1nfwPA7wx4Yx X-Received: by 2002:ac8:5955:0:b0:428:271d:27ca with SMTP id 21-20020ac85955000000b00428271d27camr2545921qtz.5.1704174294331; Mon, 01 Jan 2024 21:44:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704174294; cv=none; d=google.com; s=arc-20160816; b=PXBjvMtZSKMCVKNe+PjqAHo63R/dvIMkcSeL7JILhA4wLsd7ahSFzWKVS4vnfYW67t Iu2xFsc+WO4yfH+mfCV9qTZ2LeixZZjXk2gPKokzF7HkW3tCABGd/zfouN56NKyW7uer r9Vm3U5g5vUonWuqjPsqvPQ7cdqaDfKKjbM2N1HMR4W6msagpiixLwUMWsrrcpFvvwVP rK+j9hO1UeGCMEJSdaVEgB5Am6eUYAdC5Vi2ZVtGycmxK/sFnXFuLIbYRre/xWJHbQxE XUo1IFudafAKmYqeVFuH0BbzX8f1d600DsFuIl4PHIpRoe6Vd80N9Mt39yaYS4VYVZX8 2LmA== 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=oMVvkkN+7/jkHnTOVJgoqn1q9mcMTFme1Jvkn4Qzvko=; fh=1BEoX8YewgHIll7amv3kvMHeXAPO1f03x+kNHFxpEbA=; b=lVJRONLVT/skY6Sers6PYrOsy1ipFEw/qb7HTLMmM+mwVPtVhKNRbdaOya9l4Wb/V1 q9TdSdij4YlFmv1xv+gKfmZllM5/3lf7mADnU0lkROyfHBuj8ZFdZr6Qygv/cveg0aLJ fAdaq0HjX78tPHWkUL7QCwZPfWAHVcgXpo3X/dYXHxKbkGAtk0xNrPK7qXMBnWIGWO6P BPsbbs1F3jEQWgXaAF/2syFYQUGTfCZp6DmtKvgiO6eEsVgKtkYyjdpxxb2OBY6Wtdqw Xm4PUpMFXRbeQKnLqiAxxt3UI8xi7mv1bwhXICNMx66Irk1lGFCKmD06wj4ccdzGu/su vWtQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs+bounces-855-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-nfs+bounces-855-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id o18-20020a05622a139200b00427e8bb628csi14278670qtk.447.2024.01.01.21.44.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jan 2024 21:44:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs+bounces-855-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-nfs+bounces-855-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-nfs+bounces-855-linux.lists.archive=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 040EA1C2120F for ; Tue, 2 Jan 2024 05:44:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5111C2585; Tue, 2 Jan 2024 05:44:51 +0000 (UTC) X-Original-To: linux-nfs@vger.kernel.org Received: from azure-sdnproxy.icoremail.net (azure-sdnproxy.icoremail.net [52.237.72.81]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6A7532583; Tue, 2 Jan 2024 05:44:45 +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 [115.200.224.203]) by mail-app4 (Coremail) with SMTP id cS_KCgCXn58bopNlTqUlAA--.40716S2; Tue, 02 Jan 2024 13:41:48 +0800 (CST) From: Zhipeng Lu To: alexious@zju.edu.cn Cc: Trond Myklebust , Anna Schumaker , Chuck Lever , Jeff Layton , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , "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] [v3] SUNRPC: fix some memleaks in gssx_dec_option_array Date: Tue, 2 Jan 2024 13:38:13 +0800 Message-Id: <20240102053815.3611872-1-alexious@zju.edu.cn> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:cS_KCgCXn58bopNlTqUlAA--.40716S2 X-Coremail-Antispam: 1UD129KBjvJXoW7Ar48AFWkWw48uw43Aw15CFg_yoW8ZF13pF Z3Kr9xAF10qr1xXF1ayw4Fvw1YyFs5trW7Wry2ka13Zw1fJr1F9w40kryj9Fy2yrZ3Ww1U ZF1j9ry8u3Z0y3JanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvG14x267AKxVW5JVWrJwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4U JVW0owA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628v n2kIc2xKxwCY02Avz4vE14v_GrWl42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr 0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY 17CE14v26r4a6rW5MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcV C0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY 6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa 73UjIFyTuYvjfUYDGYDUUUU X-CM-SenderInfo: qrsrjiarszq6lmxovvfxof0/ 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 --- Changelog: v2: correct some syntactic problems. v3: delete unused label err. --- net/sunrpc/auth_gss/gss_rpc_xdr.c | 27 +++++++++++++++++++-------- 1 file changed, 19 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..cb32ab9a8395 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,40 @@ 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; + return err; } static int gssx_dec_status(struct xdr_stream *xdr, -- 2.34.1