Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp875061rdh; Thu, 26 Oct 2023 20:03:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFeqgYt0WjGymrGp8S9kAd5YquQfIV38FChnauaigtcOfXfyr6L5YW8qm0yXwJBz7n1K39i X-Received: by 2002:a25:5f4d:0:b0:da0:44fa:6cb1 with SMTP id h13-20020a255f4d000000b00da044fa6cb1mr2669424ybm.6.1698375833524; Thu, 26 Oct 2023 20:03:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698375833; cv=none; d=google.com; s=arc-20160816; b=eguHncKNRXgYmF4BtVLACFro4xj0VsbffUoVE4Yu+Z4RFoMa+UZOll4wQDWlG8qfet eUl+BneQpqFjBAMgu1lRu52Pn/gibpmeZzb223cCK18GLAMyf99soioLOAzUrgPJPLAg x6LSnjvMVA7dw1+PZXuBgTSolipAVzkdv0PSImpJk7jK8o8lmCLS4qUtqTTSa1Wpj+TT 1On4/n28JdlLTA9jOS2trCcVFOhcHkrAkkiVF56/F25qVTGYjBnCMLVbCjfmYqji+rPb pc8zdSgpU+ZC2NDBqqsgWmKD9cEHyo3ctEC8NzNJI3FiU+/ssLNcla0i6gLOqG9jtn9/ dWUw== 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=6EOx1Hx1IAPQ1YOKRVGNCkYTk+hHI63wiG6ySEOWqsw=; fh=Uywu/NjO59SL4o39MIaUXRHRT9hQTO/L4EejnLqOMcA=; b=LVMgKHl/ezJzcnDfCSZd8ScKEW+F8dxBV1wPOc/0gSdmwd8LRlltmSmXzGKCH0fBZ8 tNWl46n+s5h3MEgkcCZ3n+Ek2rLNvq6rSNjlzTv0jkw6kXA+ZUE5UYovwJ6ElD0H78vF iuCKTKpg0gKwF/fUg4HcTI2VBH82q4vfFS4E8RG7G98vD9IU2N9YqG34hcAPMa+YZrvD gXjdCFGKFKDSRwZRC+Ke6h+A0bEwrOG27kTwTVfXpOdsKD4o4vHj0aHhEfzj8PyCwiP5 S7OlSPxKLb0l9Um70WAEyqBehaSUvF5VbY+AkZ9crGSgtsxnqawUFwipATdLRakRjPew BxLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=OdDYMYgK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id a65-20020a254d44000000b00da049a21baesi1207644ybb.117.2023.10.26.20.03.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 20:03:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=OdDYMYgK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id A05E38051AB5; Thu, 26 Oct 2023 20:03:37 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230307AbjJ0DDX (ORCPT + 99 others); Thu, 26 Oct 2023 23:03:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229437AbjJ0DDV (ORCPT ); Thu, 26 Oct 2023 23:03:21 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4653F129; Thu, 26 Oct 2023 20:03:19 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id d9443c01a7336-1cac20789e8so3053345ad.1; Thu, 26 Oct 2023 20:03:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698375799; x=1698980599; 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=6EOx1Hx1IAPQ1YOKRVGNCkYTk+hHI63wiG6ySEOWqsw=; b=OdDYMYgKyBVpQnrS24hArShy7Z1Tdd/bRseMd7hFzVqMBeA/sCMpA/gckgYsEFDYii s+MvtgRbrdfQAvkHhWDTFkFhCZ2xmQRtav0ZPvYvpFBkjbrx++Bp/TV/tJ78ZpYS88q7 mEwrak+CHMylQlNQwMRE1UvzZ4X+7SdmjBFNtCToI4LdNpTv/dcK+Izo5BYI19U+DgvW 3F+rOSJsX9r/Rbk/AraogAWi36gonPTHsUZzxL4dwrbe3TpuV2cYwJqNOSHv8kf/CyOg ck9sTDxEMS6OF//+TZWi4/IBfUMNjeMs24iKst/FnQxLfuzCRttevFeMavdFDZ6cMDU2 NhIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698375799; x=1698980599; 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=6EOx1Hx1IAPQ1YOKRVGNCkYTk+hHI63wiG6ySEOWqsw=; b=ev+AhFppn353sy+hqiVW3Ay60eB8vhnbY988TEiTVgw3BFd4cYaXb8eWZctqrtxR5B VlTFlmNUmQ7hDnlGomsREmMFzREO0M2U8xdLr7zVAXcf+hLCaTp2WpEoc3VDBnYOj/ee JxROpE6OBo2nQqzmfwFghH/l0aYEFIYPbuj4IUaar7KzSc0Zud3upRHaUzlk9WXnAeQa zAEupiyH2UJBL1zGdb/2VtBCxXhMAUmS+Ij8hhtS9ON/L69ex1s88bFMRn47jXGn4OFq fiueyFVuJZwvMJ8z0rGXgMcg30oRgLtAkxvNDgSjW9LjbDW1XpX/39zebNS5E+HN1Ifv q8Rw== X-Gm-Message-State: AOJu0YzzVpA70jJGEoq4pOwOeSwdY5eOmqc3zOvaNFISN/rp/yv8DRVs edrRuxhx7V0ijGFTahbDm18= X-Received: by 2002:a17:902:f213:b0:1c4:1cd3:8062 with SMTP id m19-20020a170902f21300b001c41cd38062mr1465649plc.2.1698375798663; Thu, 26 Oct 2023 20:03:18 -0700 (PDT) Received: from hbh25y.mshome.net (059149129201.ctinets.com. [59.149.129.201]) by smtp.gmail.com with ESMTPSA id q12-20020a170902a3cc00b001bde65894c8sm407508plb.268.2023.10.26.20.03.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 20:03:18 -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 Cc: v9fs@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Hangyu Hua Subject: [PATCH v2] net: 9p: fix possible memory leak in p9_check_errors() Date: Fri, 27 Oct 2023 11:03:02 +0800 Message-Id: <20231027030302.11927-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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Thu, 26 Oct 2023 20:03:37 -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: 51a87c552dfd ("9p: rework client code to use new protocol support functions") Reviewed-by: Christian Schoenebeck Signed-off-by: Hangyu Hua --- v2: change the Fixes tag and remove "ename != NULL" 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 86bbc7147fc1..b0e7cb7e1a54 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.34.1