Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2376204lqp; Sun, 24 Mar 2024 16:36:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVYQarOXCsugCghvu2ZQBZsA7tSdYbg7iTefEX1AaCRC8bTnpOy+yt+yhHlMcL9VD+QA6J77F9ZoxP5V/b/quZMEcgKAhQ48vpz/wHI1w== X-Google-Smtp-Source: AGHT+IEVxioHG/d9GVNzAIYEBKf14hngerB/+9NqElxOwLh/u4owOq+oZPlGinJYniKo064ZHIV0 X-Received: by 2002:a05:6214:1241:b0:696:4656:f92b with SMTP id r1-20020a056214124100b006964656f92bmr6218869qvv.63.1711323364742; Sun, 24 Mar 2024 16:36:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711323364; cv=pass; d=google.com; s=arc-20160816; b=wv6JQ5ruPcRpq6P+i6fkTFTy8GFqAKI/25jiJEFMpUIJ0kd8Bvv9giqhPQvkWXKc2d WIGtOyuTq3gVcwGDaIlUZ81VSBJc9VfEnF6fmRyS29VkYKWToLam55fz5UtbJZSwmkMt Td2Rj4XP/1ses1kFDFK3ixZYigZiPeI5Cbl/Qdu9bXBCxiTjupbEm+0s3xJwgueU8E+l 5OSxhV0dqcH9cvr6M7NoXm6AvUVYMSurvRkcWh4NUAT4NcQlKci85Ta1LH4k03YEYn6+ TifeVXcs7RyIgsbqsbe/q3gJWhmv61X1nfLWmk5rEGufLIhcvrBnG8G9Dya/22JqO5LF l0iw== 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=J83XK9GTeTrynEdl5fd2e6dCNUejyZKqoUB184RvSuI=; fh=sjIczi46/ssqWnnryT9kHVfU7APj97LBNqhcB5qp3pY=; b=AY7K/aCc5Q75/uWIKjX9wsKCMjU//P4rZOsAEL232HEvM/COQPnGsx7+hpSLKuUc23 h7x0ChVOUN8IeVi7gw+5VzMN8YGA2NVRbPjdP7YPoT5cwLe0VZ/ZCqzZxnTqJ2NvQp3g ss7aAar7Y69sCu8ffmUfMD7ktIcCpkhstoANg7RoPNB5tJZXrGGfjykclP7eD+KKwoMf 21F3eHp2JnfNNOfkxxSw2869CqqnIFZAUeZ+KDpDbvfDKTJzs/us0/lfkvhqkrj+3uQ7 UPxVIxM5TajpScMqVktEn9t6gordXzeiLAuHBrggbH/mMI62HLE1YIKTGocJXEBXoB+V OEmQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qUmSTNkv; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113171-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113171-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 q2-20020ad45ca2000000b0069682ce41e5si2914124qvh.174.2024.03.24.16.36.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 16:36:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113171-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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qUmSTNkv; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113171-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113171-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 6D3251C222FF for ; Sun, 24 Mar 2024 23:36:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A3E3E175563; Sun, 24 Mar 2024 22:39:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qUmSTNkv" 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 BFF52175546; Sun, 24 Mar 2024 22:39:33 +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=1711319973; cv=none; b=KxvAjEJkhZVMsSHlj7ScUbWJzB75/d0Kg1A7kM4hFfZ+WbemCBzbE9/xcU5mwGE2PC+KlYN7ejQmRKEbKPtGsEI2h7q2xilGTxW7dY+VvZEm5KA1wHdE1Yioo+27cMGHcz+GRJE4dPlineueAIr/uGaPvKPt1fEyuez8jkw1QKM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711319973; c=relaxed/simple; bh=dxYv9j9I1vk7dVkAyDPF9nCoByCOZRCBcJTWm36K76w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lvVWW6EOdM6XhUQnFP1DeuNlATLsjAQmZ0PQPncYLPLnmpRe8oA8o5ZOzt+C90Xojv2hcbEGI5nXBR2iJOUUAXbnIlOmBs4VV9Ap+IX2Ej5mertIItZXVQYq3ebg67UFdOYTwk+3FiW7xXAxGiIKTmgaOSCSXALGlcp9gEZ22Mc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qUmSTNkv; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9FF89C433B1; Sun, 24 Mar 2024 22:39:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711319973; bh=dxYv9j9I1vk7dVkAyDPF9nCoByCOZRCBcJTWm36K76w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qUmSTNkv5wQEcHW+BknOv+IyzOdwXQa8Eo+pIyMVvOZ6T5CGqmuE9PqCELQGygC7d kAwze90mgVx+kwXulx1JsM6LodT7fsXlraFmiDxJhdlxN9DKtnPgioBYVAReQotFX7 oA8bkfUdHERD4CiMZ0VJPp0oTdLAP9+aT3LK+b3dBF74eLPLa2bJeiTFdPfLNoXKUN pYjaUG//oNFbJWzHlgFAx0Zr51XWe0GJ2qX3Xat5J6L1lLKpul5B5fU1Eb4x+PkLaX vIX7NsFjuEpPnvqml3tL+3TUM0NbQNGqTfk2g2QdchJLPbALd9rc3j7rUj6qky3cr7 cGjug4xhE7axw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Zhipeng Lu , Jeff Layton , Chuck Lever , Sasha Levin Subject: [PATCH 6.8 280/715] SUNRPC: fix a memleak in gss_import_v2_context Date: Sun, 24 Mar 2024 18:27:39 -0400 Message-ID: <20240324223455.1342824-281-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 e67b652d8e8591d3b1e569dbcdfcee15993e91fa ] The ctx->mech_used.data allocated by kmemdup is not freed in neither gss_import_v2_context nor it only caller gss_krb5_import_sec_context, which frees ctx on error. Thus, this patch reform the last call of gss_import_v2_context to the gss_krb5_import_ctx_v2, preventing the memleak while keepping the return formation. Fixes: 47d848077629 ("gss_krb5: handle new context format from gssd") Signed-off-by: Zhipeng Lu Reviewed-by: Jeff Layton Signed-off-by: Chuck Lever Signed-off-by: Sasha Levin --- net/sunrpc/auth_gss/gss_krb5_mech.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/net/sunrpc/auth_gss/gss_krb5_mech.c b/net/sunrpc/auth_gss/gss_krb5_mech.c index 64cff717c3d9b..3366505bc669a 100644 --- a/net/sunrpc/auth_gss/gss_krb5_mech.c +++ b/net/sunrpc/auth_gss/gss_krb5_mech.c @@ -398,6 +398,7 @@ gss_import_v2_context(const void *p, const void *end, struct krb5_ctx *ctx, u64 seq_send64; int keylen; u32 time32; + int ret; p = simple_get_bytes(p, end, &ctx->flags, sizeof(ctx->flags)); if (IS_ERR(p)) @@ -450,8 +451,16 @@ gss_import_v2_context(const void *p, const void *end, struct krb5_ctx *ctx, } ctx->mech_used.len = gss_kerberos_mech.gm_oid.len; - return gss_krb5_import_ctx_v2(ctx, gfp_mask); + ret = gss_krb5_import_ctx_v2(ctx, gfp_mask); + if (ret) { + p = ERR_PTR(ret); + goto out_free; + } + return 0; + +out_free: + kfree(ctx->mech_used.data); out_err: return PTR_ERR(p); } -- 2.43.0