Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp296460rdh; Thu, 26 Oct 2023 02:24:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFAxCBQNpZVLi70HGiD5uwrAkBXBtWslGrfvbFtO19GQ/BDV3TVxXZmJIsI9tTt4za7dvN0 X-Received: by 2002:a25:330a:0:b0:da0:4b92:6a05 with SMTP id z10-20020a25330a000000b00da04b926a05mr7390809ybz.29.1698312277605; Thu, 26 Oct 2023 02:24:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698312277; cv=none; d=google.com; s=arc-20160816; b=D7DXY6Z12xsW0MtJCo5jM6vi7d4G2jYHIOPuF3XMyd4pc0UegjU38yzJkq9f8OXISi lO3TQcqf5q18No/bj4aHr3ohqgKdugyYhpOotyfNoI/q1INtjlgSzeGHgZe/bH/o7JWB 5pcMTYtEafy2w33SwykFImnJ8QP+kR7/14tV6KHxSSeU83+8BiNgtByP9PJflJDP/Dt5 mQhS57GTNGoRi9DKp2F9bTjuf2oi1RYJKhq2HtE+4w3sVeUkmO+D9JpKS+jYTfuj3P4L +hRYI8qaGn94nzbQSu82IFAsxnS5+bd138GtNLtbBhbmxWstKsSlMf5H/HJ8TwIXimJu U4Ew== 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; bh=Ydp47NijRNhsTd2ijrQYlgBAO7+uhRDGUkD8hJL4r/Q=; fh=zV1lyuxLM0zi05p8ACD9winizS8lygsOmmdPnY13lfg=; b=XLX8glADAXg6exOXLTCAQ9U4zgJN8nb//b33Rz+4/65LZR8kJ4xmLnY7wH8AGlRdeC RG14nLY/0ulzlJEJcyet0xps52/1MmxlQYWvob352R1OR5zP3lb4bbNLLt6iRU0fjSZ1 8IuKkv2e1GMAzEKUnCVcMa8UVbJL2KnMnQXzMQ2zAmFBl00jx0HQ9J7SXWM0EIAbnD20 j7qh1rRaGoXzDb8ULr3as5pNQalZKVkQFD8gqkyvprFZAZsSnvW7+DqGEiqu+drfKgBJ U+bAa9BHyRv6dSsCJ+DMIWL3lbsZaYu/AfRdWh6Z5gkpoCUDBymmr0lRFucztS/I+gt5 6dyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="WEhn/7GI"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id a32-20020a25ae20000000b00d7b295f411csi14069420ybj.607.2023.10.26.02.24.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 02:24:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="WEhn/7GI"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 35480822C62B; Thu, 26 Oct 2023 02:24:33 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344603AbjJZJYN (ORCPT + 99 others); Thu, 26 Oct 2023 05:24:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344572AbjJZJYL (ORCPT ); Thu, 26 Oct 2023 05:24:11 -0400 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C02B6186; Thu, 26 Oct 2023 02:24:09 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id 41be03b00d2f7-51f64817809so81601a12.1; Thu, 26 Oct 2023 02:24:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698312249; x=1698917049; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Ydp47NijRNhsTd2ijrQYlgBAO7+uhRDGUkD8hJL4r/Q=; b=WEhn/7GI1vD8PGRG0bZDsj4neEVzlZk4sX6Ha/mIpD6a1GKw33/vZ9UssMLEBzWUFe 8TNCzdbZ5EBqwaZKmDfSJC06O4XtsuKKcYOz6pfOOQXf5cJyIKLwy2bdvuorzbG6FUAB EPYe1AxTGgLY16n8Lrdl1EZsScNAYPE3io6rbOD7jk85e1/qUk1hLI+VAs5BsRv9n2Pd CeINLS6fOgvieapzCm+ZRIMAW0WGUFgIepv1Wz6aK8ke4OoZ4dsOW92KixRguZKRlcXA t9hRIPz5ie+5ItoJGWpmht+8EYVw+X9LkSRG4WZ1bCAChbNsd97rq8nMr+JkoZA/0ZKL il8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698312249; x=1698917049; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Ydp47NijRNhsTd2ijrQYlgBAO7+uhRDGUkD8hJL4r/Q=; b=Vao0TCQYgD/KAfSkFEUR0yMTGX/wKqaes3q/V7vINEi5l1EBGlHw5zLWRB2x86p1SD Mc/51W/xG99Cznd5HIybIYe0LxvQm6bKJVT4qpvgW0Ru6lcTFHhkwoQHD39qGuSCOpsi LkbVLX9nVV2n7+lObrKap4ekXHJ5ha7p0I3LlXXACJlRoZOfc1HXx51IzMitlLIecaBh JoQU+YxwkV+FnrzfqT70P3hPit6P5n2sxS53SHNC5mr57VfM3lv0ACZE8GZvCNbARWFx vmTvwMBoSF3p5Qm92hhb1GI9EeDZbUciyF3tP2XM++pFeZYPC8kcnpDyDjNnjAfHGPNp fxyg== X-Gm-Message-State: AOJu0Ywf5DjArtVIgXV2fMMT/J47SoQqrEI4VpAVliWqCV5tZgFSRdaO CFfLqxYeSxbUPp66qhv0P/I= X-Received: by 2002:a05:6a20:8f05:b0:163:57ba:2ad4 with SMTP id b5-20020a056a208f0500b0016357ba2ad4mr21534848pzk.2.1698312249140; Thu, 26 Oct 2023 02:24:09 -0700 (PDT) Received: from hbh25y.mshome.net (059149129201.ctinets.com. [59.149.129.201]) by smtp.gmail.com with ESMTPSA id f11-20020a170902ce8b00b001c5076ae6absm10565631plg.126.2023.10.26.02.24.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 02:24:08 -0700 (PDT) From: Hangyu Hua To: 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, jvrao@linux.vnet.ibm.com Cc: v9fs@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Hangyu Hua Subject: [PATCH] net: 9p: fix possible memory leak in p9_check_errors() Date: Thu, 26 Oct 2023 17:23:51 +0800 Message-Id: <20231026092351.30572-1-hbh25y@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Thu, 26 Oct 2023 02:24:33 -0700 (PDT) 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: ca41bb3e21d7 ("[net/9p] Handle Zero Copy TREAD/RERROR case in !dotl case.") Signed-off-by: Hangyu Hua --- 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 86bbc7147fc1..6c7cd765b714 100644 --- a/net/9p/client.c +++ b/net/9p/client.c @@ -540,12 +540,15 @@ 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) { + if (ename != NULL) + kfree(ename); goto out_err; + } if (p9_is_proto_dotu(c) && ecode < 512) err = -ecode; -- 2.34.1