From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70413C54FB9 for ; Wed, 15 Nov 2023 19:48:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235332AbjKOTsz (ORCPT ); Wed, 15 Nov 2023 14:48:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235337AbjKOTsx (ORCPT ); Wed, 15 Nov 2023 14:48:53 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6F98B9 for ; Wed, 15 Nov 2023 11:48:50 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58C81C433C7; Wed, 15 Nov 2023 19:48:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1700077730; bh=bT5gV/UyI3dBmNF3sAYOHIzJeMbxxef+ukFdCC9tMMg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yr+scg1fi3QXcLudz9g5xxezafv7DHxjF6LCd121BHB4VOu/AjGh0n5amFgWHyhqn /o9J68p2vEn3ABmVI31eiTkClGb0PVKzcqNxeIgB3zTQzuHLDugS1Y8+qiQDY/ycMW FJbccwJx7FUmvuxDYMWjWbDCgN/GavnQdRChAzas= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Christian Schoenebeck , Hangyu Hua , Dominique Martinet , Sasha Levin Subject: [PATCH 6.6 484/603] 9p/net: fix possible memory leak in p9_check_errors() Date: Wed, 15 Nov 2023 14:17:09 -0500 Message-ID: <20231115191645.864623753@linuxfoundation.org> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20231115191613.097702445@linuxfoundation.org> References: <20231115191613.097702445@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ 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 --- net/9p/client.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/9p/client.c b/net/9p/client.c index 86bbc7147fc14..b0e7cb7e1a54a 100644 --- a/net/9p/client.c +++ b/net/9p/client.c @@ -540,12 +540,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; -- 2.42.0