Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5228650rdb; Wed, 13 Dec 2023 02:49:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IE4lqhaPtIERRzjzMeJsKfS43A1K3c9PHTBy1xTHRf1j/ftmPZPpgDmTnlgW3zjVyBOyQg/ X-Received: by 2002:a05:6a00:b4a:b0:6ce:2731:a07b with SMTP id p10-20020a056a000b4a00b006ce2731a07bmr8567027pfo.42.1702464588158; Wed, 13 Dec 2023 02:49:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702464588; cv=none; d=google.com; s=arc-20160816; b=GL9KEZIie/a+Nm/vaPI5V5+OTVCM0UpavBGNRTRWziXDA62P++PiOspfMGH3osEAYt fN0AEPr5lpENcR/DObZ2rQLeklXQMKyxTv2HwZehGxpyHH/u2ZACXeJAnJB4i2yv1qPF TezbgAlUtH8qpWYC01wHSn/VP22noFzxfLz4o/2wHFZAmMKlEj1pPTYY3PDMnCj+pbeQ fAXV74sfo7OekxxPFRMIf96hNeK4tqWvHUAz+miDFZ17YTPris0s4oXGwTV4BoeawW87 nNOsLcjYXT9tw2CqtCFBeDyEpnyeFq/YpKUnZHHOQNugeZAUYK7WUt2Gf7g2PRVtZkvs M68A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NoDK23LlK5p4IgH6ZTqMMZELxs6CauTLQ4NGvi9HnM4=; fh=pvthNihVFviQ+zW2qM9/pSdOLuZcwnsNgc+5FSX/1K0=; b=Ko1Pn0mOKaZ06dH4n6Y67mZC4PnyY0oHc5d7NBFb/zetkAz7rHFI3Ocm/F5YPoV3E1 7X8n+YbSTduD68pP2Q/d5qdMSStVfrvMZn+cqw0K7c1XSK/6kfHtK4AKI7jrxGB9yeCS qQ29F7nIR/QkVA/oCjoheLk5Gm1V1ugoakUpAqYGO1tZsF4Q9An+Ebr45z2bBfVbFyxV Y3gRtuk774191RADK9NtopYPAjcPcVLxGuWgQlm8qET5RQdsUyrXXsd58CJ4ssdzqeGg gq/gw7IrBfU2I9Um5w75XdjA1iDuEWcNCm4+nLjWSFEWjTveH3iakn89N5VlCyT01+gp IYQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UXZcC0eG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id u10-20020a056a00124a00b006ce63e17f29si9436272pfi.341.2023.12.13.02.49.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 02:49:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UXZcC0eG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id D2A8480BE2DC; Wed, 13 Dec 2023 02:49:45 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377908AbjLMKtc (ORCPT + 99 others); Wed, 13 Dec 2023 05:49:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377876AbjLMKtb (ORCPT ); Wed, 13 Dec 2023 05:49:31 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 884CB99 for ; Wed, 13 Dec 2023 02:49:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702464574; 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=UXZcC0eGhRmFPV/dLLlTjq6U1zG2P/SpEL+PeFp8lAOIk6F8yz9Jxnq73KFY6S/cckwSRl R55oNeNApmajVU/T4GiajuEP9ZAkUhm4eBZ62xRjOh/Qj0IYZei/yKWteiEeD/GHDDLhjH vxM+Q4d967VqRszN7ZnVgzfMekUir3I= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-548-UGb9cAUsNCyZg0QpEJtpaA-1; Wed, 13 Dec 2023 05:49:33 -0500 X-MC-Unique: UGb9cAUsNCyZg0QpEJtpaA-1 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a1fae8cca5bso60145466b.1 for ; Wed, 13 Dec 2023 02:49:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702464572; x=1703069372; 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=eUW/avKTaA1fT34/AjQdj1d4sJYLfBmUpEgMOzPfpVKliyvO2PGAABUceyKBWiB5UJ aDdHgUc+Vv0KfrsysyBfZawCJRY5ezwFJT40ZkjEe9jETJnSALAQBWkfhzzqhHYF7LiX xun1jVGMsHSmsqk/o9fvBkQmPRlN/cLOPzweqOqT6+5IF23uQWH2EzDW9Btl9VejAJtG DSmtz2BRM3MXbcdhggsgLQdQm5vrXoq+FfvFzs/tZBTNo3SsqoGTBaA/mYBZJbIjRO0a pDd0RsOUsFM81SfHlSy6Qw22+2A226pkkjr9JvgqJzt0sthk7nwmhw50zbdjqNDBxs0i Mt1g== X-Gm-Message-State: AOJu0YyEcE8EtGPUtcvABG0lbb2H3HuzoBfTN8gSIGp/ZRGBMggRJ+VB wQ5nvM36hXpOvuJlHmxDnrxnPWNY+YEKUOq9YbhSMc8eZvINVxtjLXWsMh+1Rg0VsY4k2ufTN0o BNPCjgUMlRoJiZgSBeSB56zmJ X-Received: by 2002:a17:907:d384:b0:a1b:1daf:8270 with SMTP id vh4-20020a170907d38400b00a1b1daf8270mr8780439ejc.5.1702464572485; Wed, 13 Dec 2023 02:49:32 -0800 (PST) X-Received: by 2002:a17:907:d384:b0:a1b:1daf:8270 with SMTP id vh4-20020a170907d38400b00a1b1daf8270mr8780419ejc.5.1702464572286; Wed, 13 Dec 2023 02:49:32 -0800 (PST) Received: from pstanner-thinkpadt14sgen1.remote.csb ([2a01:599:914:ed27:4fa9:dbce:10f5:d0b9]) by smtp.gmail.com with ESMTPSA id vu8-20020a170907a64800b00a1d5c52d628sm7527135ejc.3.2023.12.13.02.49.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 02:49:31 -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 1/5] lib/pci_iomap.c: fix cleanup bugs in pci_iounmap() Date: Wed, 13 Dec 2023 11:49:18 +0100 Message-ID: <20231213104922.13894-2-pstanner@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231213104922.13894-1-pstanner@redhat.com> References: <20231213104922.13894-1-pstanner@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,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 lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Wed, 13 Dec 2023 02:49:45 -0800 (PST) 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