From patchwork Sun Dec 24 08:20:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhipeng Lu X-Patchwork-Id: 183035 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp2036234dyi; Sun, 24 Dec 2023 00:22:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IFtVlza3fPNR+pE/rQ0QpbRmcgTALHEtTMizj07Ya7upkdndbKKBBmX3IytKaPd8oBp/MqY X-Received: by 2002:a50:d549:0:b0:54c:e719:64ae with SMTP id f9-20020a50d549000000b0054ce71964aemr1634741edj.94.1703406173994; Sun, 24 Dec 2023 00:22:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703406173; cv=none; d=google.com; s=arc-20160816; b=eke9iw+v9clBOpO6FZY6rafSRWO/YqvecHWblSQ9L2VanOCFUJPNou9vi+/iiCqE9E lHhV+YoyoUhNOOQqCuC+KOVkVIE6UHQM0PlIDa038BnMdWulTBlRBqC6et7gW8ZiZjBl h7MIPr5fJf2V5a/WVrIRBmMOkJiuoEK+Wy/sfsuS4qjpGrtlc7L+bv0Wx8QSu3n89xbi V0xMdb14DNTqKHuvKRq1skVtScx4/8SswUxs2cEyOdwKMqNUpFtlmWIM3ToTVBCBtvUT cNvMoUnYzfdxv3ff/jFjT0VYbY8W3av1MjcZsaorhmy3va28JCDQKL/KrKQjTGSJtp1C khNA== 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=yVKMqqDdwt67FI91JhpAis/I2gEm2OkH/Olxhe1G6hs=; fh=1xiDAqkkVHZii2GdWpMofN9yB5ISN5eVVPZabuSIzY4=; b=XatOu8dhEi1+ulHBdcvbIGDqYKFNNBIRWR8k54OWQvq+03tIVifiSI5mnRdax5EgZp /T6eHU4bL1h5lwOp6oNichH61XbDYnIgMbieE8Qek90f/oVMZO/GcB4ArZ0f0wrJhyzf 0O4JR3grTn7vpLp1PC13vGhHyCupbD9K26A8d/7Wov9WIsBn8gO6uoQuKYoE9Leqm0k7 bgFAvOS/KsyvkR+N4yRbsM+q+/pJMvWqqocpArW1586oGqa/lBG8LbMnVvEXr24zQBuI Td89dTw+wGfX5KPBDdQPiTXTOXFHFJnRfuhUA12LHklc7ga0yOkrJ3bOKlEyz4edZgE/ myDg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-10655-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10655-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id vz9-20020a17090704c900b00a26e2482dddsi691701ejb.1030.2023.12.24.00.22.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Dec 2023 00:22:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10655-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-10655-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10655-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 9C8881F21900 for ; Sun, 24 Dec 2023 08:22:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3695323A8; Sun, 24 Dec 2023 08:22:34 +0000 (UTC) X-Original-To: linux-kernel@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 6EC655663; Sun, 24 Dec 2023 08:22:26 +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_KCgCnERga6odlIsVjAQ--.39108S2; Sun, 24 Dec 2023 16:21:47 +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 , Simo Sorce , Steve Dickson , Kevin Coffman , linux-nfs@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] SUNRPC: fix a memleak in gss_import_v2_context Date: Sun, 24 Dec 2023 16:20:33 +0800 Message-Id: <20231224082035.3538560-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_KCgCnERga6odlIsVjAQ--.39108S2 X-Coremail-Antispam: 1UD129KBjvJXoW7CFWkGFWxKF4DGryxGr1fXrb_yoW8GFW7pF Z8Z347trZ8WFWIyFySka4jv3WxCw4kJryUWanFqw43ArnaqFykK3WUuryq9FWrZr4rXFyU CF1DGF98Z3WDuwUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvC14x267AKxVW5JVWrJwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4U JVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gc CE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7CjxVA2 Y2ka0xkIwI1lc2xSY4AK67AK6r43MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r 1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CE b7AF67AKxVW8ZVWrXwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0x vE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAI cVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2Kf nxnUUI43ZEXa7VUjXTm3UUUUU== X-CM-SenderInfo: qrsrjiarszq6lmxovvfxof0/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786150832339329450 X-GMAIL-MSGID: 1786150832339329450 The ctx->mech_used.data allocated by kmemdup is not freed in neither gss_import_v2_context nor it only caller radeon_driver_open_kms. 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 --- net/sunrpc/auth_gss/gss_krb5_mech.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/net/sunrpc/auth_gss/gss_krb5_mech.c b/net/sunrpc/auth_gss/gss_krb5_mech.c index e31cfdf7eadc..1e54bd63e3f0 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,14 @@ 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; + }; +out_free: + kfree(ctx->mech_used.data); out_err: return PTR_ERR(p); }