From patchwork Thu Dec 21 11:01:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Panov X-Patchwork-Id: 182154 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp329510dyi; Thu, 21 Dec 2023 03:03:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IGIcj+dhPvuldTxSFiBx72vdzU8iOdSRQOPagoupvb1SDCaTP1onyiGFbP1MI165X9ByAE7 X-Received: by 2002:a05:6402:2553:b0:554:35b4:60 with SMTP id l19-20020a056402255300b0055435b40060mr217511edb.28.1703156586340; Thu, 21 Dec 2023 03:03:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703156586; cv=none; d=google.com; s=arc-20160816; b=MQ+6pt7s19tXqbEA3QeWqn1V3+p+qXo+NhcMS30KdPGM7pn5cY7ODgiGkoE0pJKkqi SY1imxEqu8Wwm66CdfDKoxCHJaUyCtqe5Z5Qa7TBLC/p89gMGERKzl++njCNVUWrqRam itd1deK6bXYNsL5I5j7tOtpYh+VLd371HglrFPsKN/5soeabfRj5yFGj6dIjOuykbsod zn/3HNvusdXc6Pp5WMSnMsEf7d50y8U7/TJf4fRAMXoxyZgdNPgRrYuQjlm+4SrgzLuS vS4JwN/VTWAzh/70T5ILCJfVN9iqkZagUSqaSEN/p9Fa2KfVt7es2MM7LCePil9EBbC/ xTBA== 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:references:in-reply-to:message-id :date:subject:cc:to:from; bh=vDJKOAsx8MVCfsw5lOp3NxiKeURcAbHuT2NY/AsWtsM=; fh=FQ8SOQxSqn7XlrEwZI/jQGrdWFEj0k/jJOS9L3uoDPA=; b=tme/lYFFZS90Jp4psBQdap4BrNkmvHfqGhUWtzw0vnBKMCuL+yaGXRMxmCAm+lf/YB Q6fxz6PF2oZRVoKS0UDNgiYzWnxzT7xKFSiB51fMwV92AGLWqCL5abwDEh7sM7TFK1sk 5CjRWRgNmd844/Y/Ke9kIkr5QAc2dlOQ+wvzNwozcfSbSI4RqBB8Tmf4RlF0zv1WhocR /dtf+W399w01h+sre4HHy4T97DryoNMnHvGBQQaUCB0I/Td/lk07qjl3iC7nEWtFeILI HDZZXIGMEBiK5qswiJSjPlw3fST3Wkq25W0VAh+xWuf21RYPsay3pSnBKsuHWiUL9jUr IEsw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-8260-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8260-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 f17-20020a056402355100b005534a8b8ec1si766236edd.329.2023.12.21.03.03.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 03:03:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-8260-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-8260-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8260-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 EE9851F25250 for ; Thu, 21 Dec 2023 11:03:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2B52C6EB6E; Thu, 21 Dec 2023 11:02:11 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from mail.astralinux.ru (mail.astralinux.ru [217.74.38.119]) (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 6F3906BB3D; Thu, 21 Dec 2023 11:02:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=astralinux.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=astralinux.ru Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.astralinux.ru (Postfix) with ESMTP id B20161868DE9; Thu, 21 Dec 2023 14:02:05 +0300 (MSK) Received: from mail.astralinux.ru ([127.0.0.1]) by localhost (rbta-msk-vsrv-mail01.astralinux.ru [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id uNA77BV8vq19; Thu, 21 Dec 2023 14:02:05 +0300 (MSK) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.astralinux.ru (Postfix) with ESMTP id 49B811868DC5; Thu, 21 Dec 2023 14:02:05 +0300 (MSK) X-Virus-Scanned: amavisd-new at astralinux.ru Received: from mail.astralinux.ru ([127.0.0.1]) by localhost (rbta-msk-vsrv-mail01.astralinux.ru [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 1z0oOcMoKVIi; Thu, 21 Dec 2023 14:02:05 +0300 (MSK) Received: from new-mail.astralinux.ru (unknown [10.177.185.102]) by mail.astralinux.ru (Postfix) with ESMTPS id 997A11868E4C; Thu, 21 Dec 2023 14:02:04 +0300 (MSK) Received: from rbta-msk-lt-156703.astralinux.ru (unknown [10.177.232.135]) by new-mail.astralinux.ru (Postfix) with ESMTPA id 4SwnZ34sJVzfYks; Thu, 21 Dec 2023 14:02:03 +0300 (MSK) From: Alexey Panov To: stable@vger.kernel.org, Greg Kroah-Hartman Cc: Alexey Panov , ericvh@kernel.org, lucho@ionkov.net, asmadeus@codewreck.org, linux_oss@crudebyte.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, v9fs@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org, Hangyu Hua , Sasha Levin Subject: [PATCH 5.10 1/1] 9p/net: fix possible memory leak in p9_check_errors() Date: Thu, 21 Dec 2023 14:01:22 +0300 Message-Id: <20231221110122.9838-2-apanov@astralinux.ru> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20231221110122.9838-1-apanov@astralinux.ru> References: <20231221110122.9838-1-apanov@astralinux.ru> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785889080555207539 X-GMAIL-MSGID: 1785889120736527578 From: Hangyu Hua [ Upstream commit ce07087964208eee2ca2f9ee4a98f8b5d9027fe6 ] When p9pdu_readf() is called with "s?d" attribute, it allocates a pointer that will store a string. But when p9pdu_readf() fails while handling "d" then this pointer will not be freed in p9_check_errors(). Fixes: 51a87c552dfd ("9p: rework client code to use new protocol support functions") Reviewed-by: Christian Schoenebeck Signed-off-by: Hangyu Hua Message-ID: <20231027030302.11927-1-hbh25y@gmail.com> Signed-off-by: Dominique Martinet Signed-off-by: Sasha Levin Link: https://bugzilla.kernel.org/show_bug.cgi?id=218235 Signed-off-by: Alexey Panov --- net/9p/client.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/net/9p/client.c b/net/9p/client.c index e8862cd4f91b..cd85a4b6448b 100644 --- a/net/9p/client.c +++ b/net/9p/client.c @@ -520,11 +520,14 @@ static int p9_check_errors(struct p9_client *c, struct p9_req_t *req) return 0; if (!p9_is_proto_dotl(c)) { - char *ename; + char *ename = NULL; + err = p9pdu_readf(&req->rc, c->proto_version, "s?d", &ename, &ecode); - if (err) + if (err) { + kfree(ename); goto out_err; + } if (p9_is_proto_dotu(c) && ecode < 512) err = -ecode;