Message ID | 20231224082424.3539726-1-alexious@zju.edu.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-10657-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp2036957dyi; Sun, 24 Dec 2023 00:25:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IF3r0zfldRt05bR3hpoWLNTApbHs4u67olkeLREdNO2d9raG42HurjKXPGXbxvitqYLbmdq X-Received: by 2002:a05:6a00:909a:b0:6d9:9612:e455 with SMTP id jo26-20020a056a00909a00b006d99612e455mr1363430pfb.22.1703406346422; Sun, 24 Dec 2023 00:25:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703406346; cv=none; d=google.com; s=arc-20160816; b=BY2otAz+S8mQqfOHBzgguam3sNKavsQRW6nb+8QlpcO5UvbmLiSsLb8WWz+66y72jW ugPSk22M8Z0HVarB4I/Q0Oz8P2I5o2nNvOSvMkKYh+zJaDf2qSTCXbcD99p50vh/P0r9 CqQyqi9SkrDwuJNuyqY42bv1V+RrzWXXFgFH9yLUeqk9R9KyAamkFyS8640MrNPsBBmN DGwRLoVcaiND1hVkOkOsElDxn9eBO4pZSmNzlDK5RnzTFPTwyTIc0i8/uNUJV48KhDXR U0G9TaUTB+u6L6Hcv0iCU9g+azGb+WrB3W0nr6oZhHnh2YgMn9Gr9q8209lI7rroGqlV nJxA== 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=lHD5kuT9xlgtEx5gADIVuZKzw6spr/++Kgrw9rRtEYM=; fh=TcvqGbvduZXr6CspQPmBrI84LVdDDgzeEPyar4o/eTM=; b=oIhFuQmxbAUM+DWQCxRDK35rmAaU0p9ZVWIepbh7ikQAxx9HK6TYgZLogV9gJk0Yi/ MqpbfCY1CeWIS+6t799MFBarbd9cGwyGPpVKPomjJHfeASrxUFWPJ/lSI+qSOzUWYPJ4 7q+x4LxAovWpZA7W8Oxng0x8LLgoAb8e2PtRh4m6muy5SInO3+hLegKlkY6levM4raTf fC0GVh1dZJrraEdAXYoimIkxlmoJBZhioNNQlMZSslAWEDYQYm3XgQnzsaT4c8eEPRxM miLchwzjSep7xR404KwbD17ad+nkOh7htZO37So1LUEA7xjZxfFa26/6bV/AatXKWGt9 Wuew== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-10657-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10657-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id j2-20020aa78002000000b006d98b964333si3621673pfi.30.2023.12.24.00.25.46 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Dec 2023 00:25:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10657-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-10657-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10657-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 791B8B21551 for <ouuuleilei@gmail.com>; Sun, 24 Dec 2023 08:25:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C8C8823C3; Sun, 24 Dec 2023 08:25:26 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from zg8tndyumtaxlji0oc4xnzya.icoremail.net (zg8tndyumtaxlji0oc4xnzya.icoremail.net [46.101.248.176]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D730E20E0; Sun, 24 Dec 2023 08:25:20 +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_KCgCHjBnQ6odlNstjAQ--.7480S2; Sun, 24 Dec 2023 16:24:48 +0800 (CST) From: Zhipeng Lu <alexious@zju.edu.cn> To: alexious@zju.edu.cn Cc: Chuck Lever <chuck.lever@oracle.com>, Jeff Layton <jlayton@kernel.org>, Neil Brown <neilb@suse.de>, Olga Kornievskaia <kolga@netapp.com>, Dai Ngo <Dai.Ngo@oracle.com>, Tom Talpey <tom@talpey.com>, Trond Myklebust <trond.myklebust@hammerspace.com>, Anna Schumaker <anna@kernel.org>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, "J. Bruce Fields" <bfields@fieldses.org>, Simo Sorce <simo@redhat.com>, linux-nfs@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] SUNRPC: fix some memleaks in gssx_dec_option_array Date: Sun, 24 Dec 2023 16:24:22 +0800 Message-Id: <20231224082424.3539726-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: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Enco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VAFwI0_Gr0_Gr1UYxBIdaVFxh VjvjDU0xZFpf9x0JU6T5dUUUUU= X-CM-SenderInfo: qrsrjiarszq6lmxovvfxof0/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786151013276416301 X-GMAIL-MSGID: 1786151013276416301 |
Series |
SUNRPC: fix some memleaks in gssx_dec_option_array
|
|
Commit Message
Zhipeng Lu
Dec. 24, 2023, 8:24 a.m. UTC
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 <alexious@zju.edu.cn>
---
net/sunrpc/auth_gss/gss_rpc_xdr.c | 28 ++++++++++++++++++++--------
1 file changed, 20 insertions(+), 8 deletions(-)
Comments
On Sun, Dec 24, 2023 at 04:24:22PM +0800, Zhipeng Lu wrote: > 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 <alexious@zju.edu.cn> ... > diff --git a/net/sunrpc/auth_gss/gss_rpc_xdr.c b/net/sunrpc/auth_gss/gss_rpc_xdr.c ... > @@ -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 Hi Zhipeng Lu, unfortunately the line above causes a build failure. ...
> > On Sun, Dec 24, 2023 at 04:24:22PM +0800, Zhipeng Lu wrote: > > 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 <alexious@zju.edu.cn> > > ... > > > diff --git a/net/sunrpc/auth_gss/gss_rpc_xdr.c b/net/sunrpc/auth_gss/gss_rpc_xdr.c > > ... > > > @@ -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 > > Hi Zhipeng Lu, > > unfortunately the line above causes a build failure. > > ... Sorry for my mistake, I'll send a version 2 of this patch soon.
Hi Zhipeng, kernel test robot noticed the following build errors: [auto build test ERROR on linus/master] [also build test ERROR on v6.7-rc7 next-20231222] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Zhipeng-Lu/SUNRPC-fix-some-memleaks-in-gssx_dec_option_array/20231225-152918 base: linus/master patch link: https://lore.kernel.org/r/20231224082424.3539726-1-alexious%40zju.edu.cn patch subject: [PATCH] SUNRPC: fix some memleaks in gssx_dec_option_array config: nios2-randconfig-r081-20231225 (https://download.01.org/0day-ci/archive/20231226/202312260138.JJkoofSt-lkp@intel.com/config) compiler: nios2-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231226/202312260138.JJkoofSt-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202312260138.JJkoofSt-lkp@intel.com/ All error/warnings (new ones prefixed by >>): net/sunrpc/auth_gss/gss_rpc_xdr.c: In function 'gssx_dec_option_array': >> net/sunrpc/auth_gss/gss_rpc_xdr.c:270:25: error: expected ';' before 'goto' 270 | goto free_creds; | ^~~~ net/sunrpc/auth_gss/gss_rpc_xdr.c:277:25: error: expected ';' before 'goto' 277 | goto free_creds; | ^~~~ >> net/sunrpc/auth_gss/gss_rpc_xdr.c:301:1: warning: label 'err' defined but not used [-Wunused-label] 301 | err: | ^~~ vim +270 net/sunrpc/auth_gss/gss_rpc_xdr.c 228 229 static int gssx_dec_option_array(struct xdr_stream *xdr, 230 struct gssx_option_array *oa) 231 { 232 struct svc_cred *creds; 233 u32 count, i; 234 __be32 *p; 235 int err; 236 237 p = xdr_inline_decode(xdr, 4); 238 if (unlikely(p == NULL)) 239 return -ENOSPC; 240 count = be32_to_cpup(p++); 241 if (!count) 242 return 0; 243 244 /* we recognize only 1 currently: CREDS_VALUE */ 245 oa->count = 1; 246 247 oa->data = kmalloc(sizeof(struct gssx_option), GFP_KERNEL); 248 if (!oa->data) 249 return -ENOMEM; 250 251 creds = kzalloc(sizeof(struct svc_cred), GFP_KERNEL); 252 if (!creds) { 253 err = -ENOMEM; 254 goto free_oa; 255 } 256 257 oa->data[0].option.data = CREDS_VALUE; 258 oa->data[0].option.len = sizeof(CREDS_VALUE); 259 oa->data[0].value.data = (void *)creds; 260 oa->data[0].value.len = 0; 261 262 for (i = 0; i < count; i++) { 263 gssx_buffer dummy = { 0, NULL }; 264 u32 length; 265 266 /* option buffer */ 267 p = xdr_inline_decode(xdr, 4); 268 if (unlikely(p == NULL)) { 269 err = -ENOSPC > 270 goto free_creds; 271 } 272 273 length = be32_to_cpup(p); 274 p = xdr_inline_decode(xdr, length); 275 if (unlikely(p == NULL)) { 276 err = -ENOSPC 277 goto free_creds; 278 } 279 280 if (length == sizeof(CREDS_VALUE) && 281 memcmp(p, CREDS_VALUE, sizeof(CREDS_VALUE)) == 0) { 282 /* We have creds here. parse them */ 283 err = gssx_dec_linux_creds(xdr, creds); 284 if (err) 285 goto free_creds; 286 oa->data[0].value.len = 1; /* presence */ 287 } else { 288 /* consume uninteresting buffer */ 289 err = gssx_dec_buffer(xdr, &dummy); 290 if (err) 291 goto free_creds; 292 } 293 } 294 return 0; 295 296 free_creds: 297 kfree(creds); 298 free_oa: 299 kfree(oa->data); 300 oa->data = NULL; > 301 err: 302 return err; 303 } 304
diff --git a/net/sunrpc/auth_gss/gss_rpc_xdr.c b/net/sunrpc/auth_gss/gss_rpc_xdr.c index d79f12c2550a..de533b20231b 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,