Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4618112pxv; Tue, 20 Jul 2021 07:53:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhZGWFnuGN0NslKmkAQAW0upakqsKWFwJGAGI/E3PSBMKaWgdYBlWmr8ubELq5gJG0Bn+f X-Received: by 2002:a17:906:131a:: with SMTP id w26mr33402999ejb.46.1626792825027; Tue, 20 Jul 2021 07:53:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626792825; cv=none; d=google.com; s=arc-20160816; b=Wu4OQ37hBsYzu6HGVM9GFnXjkpCoDs+V+LjkJ+9i6vIn1btl/8PG8MYKySb+LTHMnI FG7TcYHNNFe50BZWiCbUanixLRDSZffAzB9yTcQv2911WGYipkOJwJelFS2vmwPetj/H /SB1Ta4jEw3izG3gMqD2QhtmicJYrHIY8nsOM+i0DO3ez2XFmu5pHm69GPztIvGbfnx+ dfzHUNrytRbQT321kZsU5gchMVQqXo7S3XWTJGIk0Vde+PYXZQPDBqCZBAoAPuUhW/pN CPzQyL1luaACu/P3usFDZuFaGuIXhBeaY0Rw82mS1BPfTm9onvL+mEsy3Xudaes3dRL3 F1BQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:mime-version :content-transfer-encoding:references:in-reply-to:subject:cc:to:from :date:dkim-signature; bh=jstlg1OkIV+dXI2YL7TkI17AWwqIokJ73bq9059nTsE=; b=Ea8vMZd7DAtkLV4nRcXdQaz/0dy/14oFLJQ09cejZzeUn2E7M147VK3qPFg1W+en8j Crxx3YkR8TMimoNWZmCCx78PrD+785MVl5ZimzRBDF6rdHukpwuXMAo1ay75H0AQV70N 3zPZwnk0TyBVnjvfA7+h7sp4vh/a0z2Z39RXnb8xvjwzDGZfXRN9iyRm01gPpWbIyScD KH/9w+4NsMn5oukpAcL3UdynKItg7eLxmfJkAUsIjueWKqzbiXXKJCklRmgtouLSA6bn sbJgZG9VMxJnvceEVP6Jc4i1cOpx7eO9wD/hsXbxacGLghtzHqBu2v+6acsrnEZoA3Wi 2qfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mail.ustc.edu.cn header.s=dkim header.b=jNrphBq+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mail.ustc.edu.cn Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id se23si6556497ejb.471.2021.07.20.07.53.16; Tue, 20 Jul 2021 07:53:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@mail.ustc.edu.cn header.s=dkim header.b=jNrphBq+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mail.ustc.edu.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232455AbhGTOKc (ORCPT + 99 others); Tue, 20 Jul 2021 10:10:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239525AbhGTN5h (ORCPT ); Tue, 20 Jul 2021 09:57:37 -0400 Received: from ustc.edu.cn (email6.ustc.edu.cn [IPv6:2001:da8:d800::8]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 52997C061574 for ; Tue, 20 Jul 2021 07:38:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mail.ustc.edu.cn; s=dkim; h=Received:Date:From:To:Cc:Subject: In-Reply-To:References:Content-Transfer-Encoding:Content-Type: MIME-Version:Message-ID; bh=jstlg1OkIV+dXI2YL7TkI17AWwqIokJ73bq9 059nTsE=; b=jNrphBq+WnYsFHfbR4jHK7OYsy6XYmDi+svXgc5BTH4lUL7IE/eo 9t7jY1ty/UAHUPDpddgxyesF4SFdTpLpIkqqew7XgHDhYv5b3qYHQ31Vi+JxlY0c J4bGlq1iLEdDXv8bs0qzrJVCEgu1HykiV9FQFVxhGDnjZNB4XUCTyxE= Received: by ajax-webmail-newmailweb.ustc.edu.cn (Coremail) ; Tue, 20 Jul 2021 22:37:57 +0800 (GMT+08:00) X-Originating-IP: [117.61.244.66] Date: Tue, 20 Jul 2021 22:37:57 +0800 (GMT+08:00) X-CM-HeaderCharset: UTF-8 From: lyl2019@mail.ustc.edu.cn To: "Dongliang Mu" Cc: siglesias@igalia.com, jens.taprogge@taprogge.org, "Greg KH" , industrypack-devel@lists.sourceforge.net, linux-kernel Subject: Re: Doubts about Patch "ipack/carriers/tpci200: Fix a double free in tpci200_pci_probe" X-Priority: 3 X-Mailer: Coremail Webmail Server Version XT3.0.8 dev build 20210401(c5ff3689) Copyright (c) 2002-2021 www.mailtech.cn ustccn In-Reply-To: References: X-SendMailWithSms: false Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=UTF-8 MIME-Version: 1.0 Message-ID: <77df3e1f.22e1.17ac45a1bd9.Coremail.lyl2019@mail.ustc.edu.cn> X-Coremail-Locale: zh_CN X-CM-TRANSID: LkAmygDX3x_F3_ZgqsYEAA--.0W X-CM-SenderInfo: ho1ojiyrz6zt1loo32lwfovvfxof0/1tbiAQsIBlQhn9BleAAAsj X-Coremail-Antispam: 1Ur529EdanIXcx71UUUUU7IcSsGvfJ3iIAIbVAYjsxI4VWxJw CS07vEb4IE77IF4wCS07vE1I0E4x80FVAKz4kxMIAIbVAFxVCaYxvI4VCIwcAKzIAtYxBI daVFxhVjvjDU= Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Dongliang Mu, > Depending on if CONFIG_PCI defines, the "tpci200->info->cfg_regs" may > not be freed. > > #ifdef CONFIG_PCI > /* Destroy a virtual mapping cookie for a PCI BAR (memory or IO) */ > struct pci_dev; > extern void pci_iounmap(struct pci_dev *dev, void __iomem *); > #elif defined(CONFIG_GENERIC_IOMAP) > struct pci_dev; > static inline void pci_iounmap(struct pci_dev *dev, void __iomem *addr) > { } > #endif I think only `CONFIG_PCI=n` and `CONFIG_GENERIC_IOMAP=y` cause pci_iounmap an empty implementation. Actually, `CONFIG_PCI` is a default option when run `make defconfig`, pci_iounmap() usually is acted as an extern function. > Even if CONFIG_PCI is undefined, it is possible that > tpci200->info->cfg_regs is not freed at all. Therefore, this patch > would cause memory leak. Take a look at the following code: > > void pci_iounmap(struct pci_dev *dev, void __iomem * addr) > { > IO_COND(addr, /* nothing */, iounmap(addr)); > } Here i am not sure this is the final implementation of pci_iounmap(), because pci_iounmap() is re-implementated in many architectures. Even so, i observed there still many call-sites of pci_iounmap() have reset `the addr = NULL` after calling. Can you have some ways to determine the actual implementation of pci_iounmap in our cases? > #define IO_COND(addr, is_pio, is_mmio) do { \ > unsigned long port = (unsigned long __force)addr; \ > if (port >= PIO_RESERVED) { \ > is_mmio; \ > } else if (port > PIO_OFFSET) { \ > port &= PIO_MASK; \ > is_pio; \ > } else \ > bad_io_access(port, #is_pio ); \ > } while (0) > Although the above codes is actually called, the addr might be freed if `port >= PIO_RESERVED` is true. The double free still existed. If I make any mistakes, please tell me. Thanks your report. --- Lv Yunlong