Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2563689lqp; Mon, 25 Mar 2024 02:44:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXLuCMn/m6scwuuBasQ+nguNjT72G3Jt59N4/fyTJQ/oB499pkQ62U+zrzk5uHN6dAfFlwMM9hMUkqHfC+EdqO1RfZ56lCUh9QU1+DUhQ== X-Google-Smtp-Source: AGHT+IFxlP2ex8seciYvEpIdkT0ioUug4kaUdDfgIeaFN6+1UVbWGmCDFKIYY9DQ5iLjGnMF1tub X-Received: by 2002:a17:906:607:b0:a47:3887:db68 with SMTP id s7-20020a170906060700b00a473887db68mr3892981ejb.38.1711359864685; Mon, 25 Mar 2024 02:44:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711359864; cv=pass; d=google.com; s=arc-20160816; b=o4prRqfPIvMiQc7jjMOHxgdYKUJtmi1dIcaeDxzOy5GI5EIu5wRTfr/9IpGIyo12bd jNThuBHoF8AipMzEsE06kNSol6ne0WFihu0IohVJwa7stTyz2S5egJDQjchhtd/uPDwT bpROPsHDcMGUTiQxvDxSsN4H/ZZ+QSOn2Wma4ANYdVc6ByWo9pMB0yJXrgog0qGx/rBj ZUfkmi65SJprV+JCyuc8UBXuVxO3umzLqjtg6U/9vaL25F+p4nCyoaUDXwsRvPFRoCw3 8CFtKKtSNs+2N/vLTKlsdFyqD8OIEO9l9JxQb5l0UGwuFqAMQxt12E8lFG9JHPBkFZJx DbtQ== ARC-Message-Signature: i=2; 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=o5Q5GYgSVZtfeuMj66m7BU1Fu+vYsH6m6XH7aAzHeLQ=; fh=JtvlRgBfIkycKjj0h8ciibqw0W7BciHY4NFAcA81PDQ=; b=MtMddDyxXCilJKbbgzynOABNvKDKOtkFJfHI7aJyc1b56FUzMMgwUppo9QYFSjPjop n/+D7uGgU/UuVLeBw7P8NtN9a9/fbxSoF5HyCSJPDdM2dB7us8rpDDc0PdTzV4qsU3wq 3+BvQ950IxfLZC+LvhG1AKd7Q43t91sbTdLpIvlBMfwVaZ6+XDul9Y9IHjSiQF70sGE1 iIgP+u5huL+gJzENDQLf3z/9dZSfHS6sl9o0b9nf4anGCsxTsbAPcmE6lMVaYcn/mapH ClzzjWWAKaDcE5cXjGYEYf1RdIpBY7ND9hIyoiqYgAUFKgKJVpGQ04jlu56X5rAQUup0 kHAA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NSMoKyOO; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115903-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115903-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id n8-20020a170906724800b00a469368a86csi2297405ejk.344.2024.03.25.02.44.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 02:44:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-115903-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NSMoKyOO; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115903-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115903-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 040BC1F2E4CF for ; Mon, 25 Mar 2024 09:43:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B1381388192; Mon, 25 Mar 2024 03:03:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NSMoKyOO" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 386021487C5; Sun, 24 Mar 2024 23:15:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711322112; cv=none; b=Ix8AomSfOUDdpo0m6NjHAzktVT+3Yu127izN7PoNZD2IfuYR3yyncaD005lhFS/+fKZJToIiS54r1qfpEiDC7HYQmn8Xuc5ag174F7EdJhWSLHFgVd8h3ZiBVGf2WbcZX4IVHySE7GoRpzInssyTa6iXVqCP0qaRU4uD/83MM/Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711322112; c=relaxed/simple; bh=uRoRsaHWAWpKpAmF0MLAb2S1bcEcuSVKZ2mxImqiWlo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O5KhXph0XkfNJfTbSsELgq7G1jVnfvAGRWdKFWY32kBZIvWCv3wwRqJ45W/6SB0e5J14WQDeZTeArdHsoYKoFqXN7qAPrgstXC26kz3ureaRiBd40CrTUHivo7jJWQbF5pgQb1oCcvWcRivtV2JX6SNLc7/Iz6adbT3sUwGPSyo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NSMoKyOO; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76A80C433C7; Sun, 24 Mar 2024 23:15:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711322111; bh=uRoRsaHWAWpKpAmF0MLAb2S1bcEcuSVKZ2mxImqiWlo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NSMoKyOOSw26R2vSQRKXUWXNn3aLbSfyUnpm3qCVwXrzqqI7zmPQc4ZnkrpWBXp47 sV5mWHhkKiTbnfQkiXdDKpO5pjCO/4ZiRXo3YHL8KHpauqmhsLwzs+lnE6rt1Yn7U7 sibOorirpvAKIUfSylD5ivxadVsSaltsnh1cSil9ai3gsl1nGFyEO4e6dVrt61aqPK SkzQQWtSu6eAAFN87QHgxW2RDPe87arOPNKJnCDbOHioByJ/veCjCJwmXxFJUib5b3 0YWutrETKatjn0Ez0d7yZa4rdB1nrTvztGwi6FjpFqZ6GZwyJl5IHMoJXlUHOtF+Rn 0wfSlYY8kFuRQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Zhipeng Lu , Chuck Lever , Sasha Levin Subject: [PATCH 6.1 186/451] SUNRPC: fix some memleaks in gssx_dec_option_array Date: Sun, 24 Mar 2024 19:07:42 -0400 Message-ID: <20240324231207.1351418-187-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324231207.1351418-1-sashal@kernel.org> References: <20240324231207.1351418-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Zhipeng Lu [ Upstream commit 3cfcfc102a5e57b021b786a755a38935e357797d ] The creds and oa->data need to be freed in the error-handling paths after their 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 Signed-off-by: Chuck Lever Signed-off-by: Sasha Levin --- 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 d79f12c2550ac..cb32ab9a83952 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.43.0