From patchwork Tue Dec 26 07:20:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhipeng Lu X-Patchwork-Id: 183278 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp723333dyb; Mon, 25 Dec 2023 23:21:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IEQ3UgzLir9PCeyRAi3l7xLnoozEOo19pRtbkGGwgfU0uxfaP4+Qgm5R0VIYeXcnjRPNEtS X-Received: by 2002:a05:600c:2b0e:b0:40d:1382:386b with SMTP id y14-20020a05600c2b0e00b0040d1382386bmr2990420wme.73.1703575304327; Mon, 25 Dec 2023 23:21:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703575304; cv=none; d=google.com; s=arc-20160816; b=dYNMirJgrY+8Qdlbg4GPD6siLN6zpOQlGrrg/QcFhNxTUS2rD3+DcNwu1cjouVJG6m KQEVBGMOK5NtWYKTIC7uoZKEgNWq6Hjq87r4NH8odixwhRTdW1qUCkoq67bJZOZ0mKQw 0GvcvUxrYABmVgGnEHC0IDBBKutxyn49OBG4i2NuM4cCLHa/8QJZhtXC9j6ZwCx62lt7 VH06BDArG58rooPIS7zdkka+AzczCN6FhETlVi9+LPEJEkzXuO5UZipegllto81Iz9hf 5ayy6qOGbn/cya1DdpdRVFNWI5t3CMul59XY/cCC81Tfg+0cqQD5dZl+oq/SrH/+32tZ NRAA== 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=xYSQJIW+b5RMYxJiALta3j7aTY4JLpEvBz1c46RFtpo=; fh=TcvqGbvduZXr6CspQPmBrI84LVdDDgzeEPyar4o/eTM=; b=deIt/cTCcGEmIGDJ9SE3UdPPtKTbUFE/yMMFLdYICUxsNvDWdA10KEEnYrr7DEIAKq luewBS6XXIk/K1mpBv/jFiDnuw9EqqXrX2DwrOHsprZ/YD/yu7wDiEuUJmk9Sd4xysAE O4z5jVk5x0QrXmy9cBStmR0hN5sPUMTBbm9PhczHFtdJsZJBkfuRcDgyhvYIMvZ56xjU Qsvs6bjnmANHSpfsWxk6+u146s6m1qmI6qzK3/aU2u5oRm9vLkmI7mDLnzq4JvSQtPF4 CMsIBSzeg8C2hO/fhJe/c+s9IDxfUMlHl4k8luHFIWiznmih2DHuD8jszMZt/9GTMQoQ C6uA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-11396-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11396-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 u18-20020a170906b11200b00a2362beec73si5202506ejy.958.2023.12.25.23.21.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Dec 2023 23:21:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-11396-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-11396-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11396-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 E34441F2243B for ; Tue, 26 Dec 2023 07:21:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E06324C63F; Tue, 26 Dec 2023 07:21:22 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from zg8tmtyylji0my4xnjqumte4.icoremail.net (zg8tmtyylji0my4xnjqumte4.icoremail.net [162.243.164.118]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CD0B84C601; Tue, 26 Dec 2023 07:21:16 +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 [125.120.146.113]) by mail-app4 (Coremail) with SMTP id cS_KCgBnbDTHfoplfMIDAQ--.23882S2; Tue, 26 Dec 2023 15:20:40 +0800 (CST) From: Zhipeng Lu To: alexious@zju.edu.cn Cc: Chuck Lever , Jeff Layton , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , "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] [v2] SUNRPC: fix some memleaks in gssx_dec_option_array Date: Tue, 26 Dec 2023 15:20:19 +0800 Message-Id: <20231226072021.3550114-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: cS_KCgBnbDTHfoplfMIDAQ--.23882S2 X-Coremail-Antispam: 1UD129KBjvJXoW7Ar48AFWkWw48uw43Cr4Uurg_yoW8ZryDpF Z3Kr98CFn2qr1xJF1ayw4Fv3WYyFs5tFW7Wry2ka13Zw1fJr1F9w4vkryj9F12yrZ3uw1U u3Wj9348uwn0y3JanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvG14x267AKxVW5JVWrJwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4U JVW0owA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628v n2kIc2xKxwCY02Avz4vE14v_GF4l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr 0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY 17CE14v26r4a6rW5MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcV C0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY 6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa 73UjIFyTuYvjfUY-BMDUUUU X-CM-SenderInfo: qrsrjiarszq6lmxovvfxof0/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786328178533660854 X-GMAIL-MSGID: 1786328178533660854 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. --- net/sunrpc/auth_gss/gss_rpc_xdr.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 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..c69f5abf696e 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,41 @@ 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; +err: + return err; } static int gssx_dec_status(struct xdr_stream *xdr,