Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp127507rdb; Tue, 5 Dec 2023 00:06:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IGpsW15eXHWnQ8AwEhFpuz9g2wh1ln+dH7OCgWyabL9fuYh3WtDQWyK46nbIzDkK/IDiraK X-Received: by 2002:a92:c08e:0:b0:35d:59a2:2b6 with SMTP id h14-20020a92c08e000000b0035d59a202b6mr6969245ile.86.1701763604987; Tue, 05 Dec 2023 00:06:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701763604; cv=none; d=google.com; s=arc-20160816; b=Xg+0t/9BvFucx/zUjm4HIuQKlJ4wVFS0D8MzaPtHgAGPYdHw46PH8fUvIkYAUZUvH+ W5w5kAMFLFLb1uChy7D+ewx4e7rc8jFXiuY+dHsAtXGdi3hLDP982W7hdttd07gqCnh4 mNJpv7srwhRUEKDpcoC7OaRK5bhmbB9EswvJ2BjfTbPWMBzaJM3hAQA2hsQAmp7IRf+h DG+0JGu2LY39OXOCCNepvW47f80Zx0UgsFtHIEnjWoqSIJZqvC4D+Zkp/xQzFmU257q1 mq5OT0fe1CIS6Ywix8R57XFF5sAs0PVEyiuMr0/9YM0xgXv4UY9fa7yNmVoprehd9cmJ Iw9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature:dkim-filter; bh=JTEXi8TgIL4mRes1RKwLHstGL+1Ht9ZpBqt+VDl25fI=; fh=a/+lDpLnb9ZEU22c8vR2gmAFKVHBY8JZcw4FuHpJe4E=; b=SP9FvF1nRIVRs/Y25PipkjrAtXlyQRLefrtAS/9nq7SLD+ZaiM6bKPeh5kTep//N3z atYwJ1a9R+1Uoeq6RpbDmA26aJ0t5Z9tHeGWhkNqBZ9tdvL33jsiVOvUUXj5YAVy7sZ7 DG65zp1UL3effgIDd+D1zvV67NV7sGk7mP5UcT7Cl8f5wjy8Cr9vxEn6ozpfz7n9Mhw5 qG8j9RtSSDzbaqAuDguwLSI2y3qPpDjhL7ZqYjYQy6cLZIyNw17gk/1eP+7aWlvZLhgC jxJacxm3/iog43Oj0dCwLR4Pm8XjO84kFyNUQayYAgZDAGyufJ6Eg7EozkyECF4MerEw 5f3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=ZeGt7KND; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id u16-20020a63ef10000000b005c65ac797acsi5647695pgh.360.2023.12.05.00.06.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 00:06:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=ZeGt7KND; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 6D63D805F2C6; Tue, 5 Dec 2023 00:06:42 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234880AbjLEIG1 (ORCPT + 99 others); Tue, 5 Dec 2023 03:06:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346395AbjLEIGG (ORCPT ); Tue, 5 Dec 2023 03:06:06 -0500 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72AA6D41; Tue, 5 Dec 2023 00:05:48 -0800 (PST) Received: from localhost.ispras.ru (unknown [10.10.165.7]) by mail.ispras.ru (Postfix) with ESMTPSA id BF7DB40F1DE9; Tue, 5 Dec 2023 08:05:40 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru BF7DB40F1DE9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1701763546; bh=JTEXi8TgIL4mRes1RKwLHstGL+1Ht9ZpBqt+VDl25fI=; h=From:To:Cc:Subject:Date:From; b=ZeGt7KNDwgTR4NzwLFREB5RIzRFIzKzj8J8UY8T9MJ56stiHkXx6ciQse+PccqsEC GysZq/0K7yIzDBSDAsN/QgKIspYqMjWRgsZ1mIa33nFG0HiaJX+g+waEXIPT7atVY5 HmTZUSaAsMxczUfMalOl3hYFHECIm4diML+dyO8k= From: Fedor Pchelkin To: Eric Van Hensbergen Cc: Fedor Pchelkin , Latchesar Ionkov , Dominique Martinet , Christian Schoenebeck , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , v9fs@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Alexey Khoroshilov , lvc-project@linuxtesting.org Subject: [PATCH] net: 9p: avoid freeing uninit memory in p9pdu_vreadf Date: Tue, 5 Dec 2023 11:05:22 +0300 Message-ID: <20231205080524.6635-1-pchelkin@ispras.ru> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Tue, 05 Dec 2023 00:06:42 -0800 (PST) If an error occurs while processing an array of strings in p9pdu_vreadf then uninitialized members of *wnames array are freed. Fix this by iterating over only lower indices of the array. Found by Linux Verification Center (linuxtesting.org). Fixes: ace51c4dd2f9 ("9p: add new protocol support code") Signed-off-by: Fedor Pchelkin --- net/9p/protocol.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/net/9p/protocol.c b/net/9p/protocol.c index 4e3a2a1ffcb3..d33387e74a66 100644 --- a/net/9p/protocol.c +++ b/net/9p/protocol.c @@ -393,6 +393,7 @@ p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt, case 'T':{ uint16_t *nwname = va_arg(ap, uint16_t *); char ***wnames = va_arg(ap, char ***); + int i; errcode = p9pdu_readf(pdu, proto_version, "w", nwname); @@ -406,8 +407,6 @@ p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt, } if (!errcode) { - int i; - for (i = 0; i < *nwname; i++) { errcode = p9pdu_readf(pdu, @@ -421,9 +420,7 @@ p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt, if (errcode) { if (*wnames) { - int i; - - for (i = 0; i < *nwname; i++) + while (--i >= 0) kfree((*wnames)[i]); } kfree(*wnames); -- 2.43.0