Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2379853lqp; Sun, 24 Mar 2024 16:49:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVHZ0UR5sJM/wUdPiVbd0HCw96pm2W8guiAzFsswLPwPGWfycmHrHLjrLgL4vQPunotJ15crOMHjxmoByFugI2Pfjccy2ledKU4jqLo1A== X-Google-Smtp-Source: AGHT+IGDdy+sa5xzg/3toU2TwS/saBObgJRzWk4g5JXZwNGP663tQRZqiMQaXAPkfe/oK5LJwHfN X-Received: by 2002:a17:902:dac1:b0:1e0:cea:257e with SMTP id q1-20020a170902dac100b001e00cea257emr7300670plx.2.1711324172705; Sun, 24 Mar 2024 16:49:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711324172; cv=pass; d=google.com; s=arc-20160816; b=IOTp8xkn9uFLsnESxANdnd4f4T7NsK+4JzQyCzrLc//FJnCaPLN9vegy/2RCJ84KHb 6loDkPGQSXl/cJKxkzhwmtUY/w2rwaHLJzDWg+ypbNrcO+9BtEc+V/+gtlwlfBMuwIpI 6/7DdGkSI1tEIDlQ0rYGflPYynBsGYgDo1YRCwUZ2UNFOhgmT/EYnsyCaD52iOBBmehL tcm0DGkovHdxz40xT2iVHyJ404eLb/XNPa68FIfp0pvoz7rV0lJmsOg+X9cvXRNsip0v Rr8gQ4cCFihqBMiiWGt0b7RevCM53oadQANoPbbPz5B2cEjfdO69bvWqWpG7qUJR+eb3 nCqg== 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=yA45wVe13p6Iccv9KvCXqFU9V5qNG6YBS4KsqPNvb7G4FgN1/JA3BY1iv4gIE2lWKC OX7KEbZQs4ncHZ8MCq8/JZrdAzfUmWaDECs4YwrbWu40C3Vo1RqKClDg3qhHIm9tggDN BEPNatEoJTUYEJO0+myhzs+MXNe9eUQMHSGH3GPTVduH1u7a8k7CFbieP+p5FvVC9uuG UlSttE8bjVl2xAB/3YRcDWkA60//P/eGkKceu4o0yu2VirUXpUtwUYSB2uy7ZGDudAEH utstmL+nujEaYZiGOZbvbRGWE0wr4qnlY2A3ZdcUp2pxFdc22pYg00G2H3A3HwpTF1K7 mN3g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=R7i+cr7C; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113172-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113172-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id b5-20020a170902d30500b001dddbe5ab7csi3923811plc.640.2024.03.24.16.49.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 16:49:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113172-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=R7i+cr7C; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113172-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113172-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id CDD82B222D1 for ; Sun, 24 Mar 2024 23:36:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 49FCE17557A; Sun, 24 Mar 2024 22:39:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="R7i+cr7C" 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 61BBF17555A; Sun, 24 Mar 2024 22:39:34 +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=1711319974; cv=none; b=p8QEAdvGkGQdcBy2YsWx+seh4jrQq016ylV1JTy5daNrBvxInHW4pBrq7cmPJ4sZ2bdipPQp64BGfo5q1xRiOYgBGo2MH9Xhi/kIX2mcZ9bbfxR2NM1rWZ9TIJeQlEyrhd9FmXy5Xqz2LiyZGvXOCZlUwA5hleE1nSzMkbHHq8A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711319974; c=relaxed/simple; bh=uRoRsaHWAWpKpAmF0MLAb2S1bcEcuSVKZ2mxImqiWlo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bIpjvG7Gut5sgKvmuuQxKanZf1c+eLEh3vp2U5AWAHocoWk/vRGQyWOtQFE/XguXSMNrU/KPRhKUGJ325gFXCbh5USSfxsaRc7gi1mql8dbYzREN7QsYlJu1SL0XMa/XbSGjPpQTXemJuv2tdCw+ODj5e+FBQasuWSRfIgr9Sy4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=R7i+cr7C; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C3ABC43399; Sun, 24 Mar 2024 22:39:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711319974; bh=uRoRsaHWAWpKpAmF0MLAb2S1bcEcuSVKZ2mxImqiWlo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R7i+cr7CH/1cHzjq5YtWg7d72+nupUWRoahdfWsRa1ai+aqJxOD8/j8V3SRkmIelU 0gROC2mQNgchNTyswvHx50JK/Vl2k8mCZM8ttVNDAP7IAvm+ZqPBN4aXoR7R/dG4My oKk5KTSGkmownV5nEEvr+07LwozCF219MMa2TY9y9SmtZJXQEXAKPL24K0LQV9E+HW WksYpoWNxwwLmHbiREgzwkoCnSgVKgjvz+jCi3sEEVvv157enCOuAVilGfX8itooCb kyOFnXgMDoqUE/LjTY7/y72yjNpqSmm9MbDk6my7j3MMuEwhv8HknRt2ADPgKkzzOZ bW04sZvecs1RQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Zhipeng Lu , Chuck Lever , Sasha Levin Subject: [PATCH 6.8 281/715] SUNRPC: fix some memleaks in gssx_dec_option_array Date: Sun, 24 Mar 2024 18:27:40 -0400 Message-ID: <20240324223455.1342824-282-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-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