Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1507224rdd; Thu, 11 Jan 2024 00:56:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IGl2wuh/eJFEkqCHa6V+Fqv4x9HRs9YN9pcA9pNIE6Z3QvQUXigIxF3gisYxAGYjRgq41xN X-Received: by 2002:a17:907:3202:b0:a27:b22d:f1e3 with SMTP id xg2-20020a170907320200b00a27b22df1e3mr263370ejb.181.1704963407533; Thu, 11 Jan 2024 00:56:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704963407; cv=none; d=google.com; s=arc-20160816; b=xGkewvWkysWMK8nbFlGNVuVIWWZvWt+Z2WwYS7/P1+xPKsti+vLVDnY3sDxOe35Cb2 J6oqgl4v22pWc0z4NavoJXRF4IWSKJPZM19piDMT5eEi7voQqrEdLpkkDk2BBT6KYK6a KAj02EFyhSms6x+ZHmLvovETaJc8zdH1Mhg7+HkBPnmDbn3FoBANea0Qo+ZiHvJWSkPo lBwQmq8hcGCRtUgnsO/Jtp9hHFH+QSdSB/flbmGcEKheI7WY8C0i+2z671xq5d1RW0KV XXLJQPxcOLrO2e//1rMsX3PDUrwIQqi2dt4w0xM5xLaqADhV3XF9Hh6b06uNhS5W0Tee TLUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=NoDK23LlK5p4IgH6ZTqMMZELxs6CauTLQ4NGvi9HnM4=; fh=pvthNihVFviQ+zW2qM9/pSdOLuZcwnsNgc+5FSX/1K0=; b=MkkFRzVGXBkD1YbtUyAozjUD7TFF4t2bxfsQIIaiSIZZYo34R3amdvFT/DW/77xSCH kLvIsk7o/WAH1KFSJ03QjoMLqAUR7GCmV7M4tky33bwmH3rdfmAUY0sgD9uNAYLo73qJ ugt2ejocKBuCoaIUzBx4ZtzSsdrxn0g2xKM2Ytm1wXNeLFxUQ+N0OimQCmnfOOleDOGc nPrayIM0nSBvbhOp8nFHUozHYwg8iQ3578sFHav865L2jBLDDvh6Kxs8VXxdbxVVML7m 3ED2cat9iSPZ07GQTWG2q7HJxQ+53gGLNHEA6bsJIidFAvYgvK56ISOpm9I0FV7CY5Dt +DAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UQysp1DM; spf=pass (google.com: domain of linux-kernel+bounces-23255-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23255-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id m9-20020a1709061ec900b00a2b67a0b12dsi287866ejj.987.2024.01.11.00.56.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 00:56:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-23255-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UQysp1DM; spf=pass (google.com: domain of linux-kernel+bounces-23255-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23255-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 136981F243A6 for ; Thu, 11 Jan 2024 08:56:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CBBE8125BE; Thu, 11 Jan 2024 08:56:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="UQysp1DM" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F75210A38 for ; Thu, 11 Jan 2024 08:56:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704963368; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NoDK23LlK5p4IgH6ZTqMMZELxs6CauTLQ4NGvi9HnM4=; b=UQysp1DMcYb7IPbjxa0mp79Aba+6fVPCPwB1HfAbySquJLjZ8WVFJ+S22iGjcZQrBFXfdk damusRROEx9L/LVk/nYi5EWI2Tb8EB2I0wpkAAkG2fq2jGNuSELevFKHbrP2l7pfgGk4mD bWuZ97dFgXQrB+5SVr5xpAa40ysJa/g= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-31-nawnymhkPPmyCmDzHu-zpw-1; Thu, 11 Jan 2024 03:56:06 -0500 X-MC-Unique: nawnymhkPPmyCmDzHu-zpw-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-680b74cba78so13216626d6.1 for ; Thu, 11 Jan 2024 00:56:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704963366; x=1705568166; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NoDK23LlK5p4IgH6ZTqMMZELxs6CauTLQ4NGvi9HnM4=; b=SdV4zG92Uzw8KDaHmStU/ShjF2zVRIffsDyO+pfe9jIo6lDKhAgry3uIHJrRscNP5y xsv4bS8knUxahpxD2RsyjSlXEVeOXZ0u9eSP42rd0LBcyfn1itKzh4KN+at5tssv+Cpl Z0WD46beRjSznkT80fvGPnZCgTI1FuYK2pLtoi3Jsoi9HsLVWxdW4L8ZM6hfavEXvdk6 lYRW0RbJ8CqIB7/ngjc5W+zfjozj+2v9xqc0h0EKDrylcyqzcvO1Xiq8FfVZIhI5tdLj JKpLNagcHRsJJFo4equSMD2Ggu91HN4il3QGTwkhzvMnJTXrGf7V/Tht0vzJj8z/ASxE Z7JQ== X-Gm-Message-State: AOJu0YwtLhDeXalX8Y+GWNeB3IiewBTi8A0zGVtwkgS6RyDPbQLc6+pL dI1kwAce8bNsUjqXDZOlWpRudfNS45yW0bK7Wa3QtqSy+o11xWCqc9Y+q0hIeZNgU70bqZTuTwm 65v1JqIT6RjoNic82wgjfqKOl6e71Whkp X-Received: by 2002:a05:6214:2a8c:b0:680:feea:fb6a with SMTP id jr12-20020a0562142a8c00b00680feeafb6amr1473369qvb.5.1704963366142; Thu, 11 Jan 2024 00:56:06 -0800 (PST) X-Received: by 2002:a05:6214:2a8c:b0:680:feea:fb6a with SMTP id jr12-20020a0562142a8c00b00680feeafb6amr1473359qvb.5.1704963365935; Thu, 11 Jan 2024 00:56:05 -0800 (PST) Received: from pstanner-thinkpadt14sgen1.remote.csb (nat-pool-muc-t.redhat.com. [149.14.88.26]) by smtp.gmail.com with ESMTPSA id e16-20020a0cd650000000b0067f7d131256sm168341qvj.17.2024.01.11.00.56.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 00:56:05 -0800 (PST) From: Philipp Stanner To: Bjorn Helgaas , Arnd Bergmann , Johannes Berg , Randy Dunlap , NeilBrown , John Sanpe , Kent Overstreet , Niklas Schnelle , Philipp Stanner , Dave Jiang , Uladzislau Koshchanka , "Masami Hiramatsu (Google)" , David Gow , Kees Cook , Rae Moar , Geert Uytterhoeven , "wuqiang.matt" , Yury Norov , Jason Baron , Thomas Gleixner , Marco Elver , Andrew Morton , Ben Dooks , dakr@redhat.com Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-arch@vger.kernel.org, stable@vger.kernel.org, Arnd Bergmann Subject: [PATCH v5 RESEND 1/5] lib/pci_iomap.c: fix cleanup bugs in pci_iounmap() Date: Thu, 11 Jan 2024 09:55:36 +0100 Message-ID: <20240111085540.7740-2-pstanner@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240111085540.7740-1-pstanner@redhat.com> References: <20240111085540.7740-1-pstanner@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit pci_iounmap() in lib/pci_iomap.c is supposed to check whether an address is within ioport-range IF the config specifies that ioports exist. If so, the port should be unmapped with ioport_unmap(). If not, it's a generic MMIO address that has to be passed to iounmap(). The bugs are: 1. ioport_unmap() is missing entirely, so this function will never actually unmap a port. 2. the #ifdef for the ioport-ranges accidentally also guards iounmap(), potentially compiling an empty function. This would cause the mapping to be leaked. Implement the missing call to ioport_unmap(). Move the guard so that iounmap() will always be part of the function. CC: # v5.15+ Fixes: 316e8d79a095 ("pci_iounmap'2: Electric Boogaloo: try to make sense of it all") Reported-by: Danilo Krummrich Suggested-by: Arnd Bergmann Signed-off-by: Philipp Stanner Reviewed-by: Arnd Bergmann --- lib/pci_iomap.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/pci_iomap.c b/lib/pci_iomap.c index ce39ce9f3526..6e144b017c48 100644 --- a/lib/pci_iomap.c +++ b/lib/pci_iomap.c @@ -168,10 +168,12 @@ void pci_iounmap(struct pci_dev *dev, void __iomem *p) uintptr_t start = (uintptr_t) PCI_IOBASE; uintptr_t addr = (uintptr_t) p; - if (addr >= start && addr < start + IO_SPACE_LIMIT) + if (addr >= start && addr < start + IO_SPACE_LIMIT) { + ioport_unmap(p); return; - iounmap(p); + } #endif + iounmap(p); } EXPORT_SYMBOL(pci_iounmap); -- 2.43.0