Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp369326rdb; Tue, 5 Dec 2023 07:39:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IGrWDfM6Sky7UJZkTXfJ//P91U0bD+CR2RwQBsBGyVBf96wxe+aEidLUxEpE5BmVzXA45o6 X-Received: by 2002:a05:6358:5e14:b0:16f:eee7:728a with SMTP id q20-20020a0563585e1400b0016feee7728amr8060272rwn.8.1701790742111; Tue, 05 Dec 2023 07:39:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701790742; cv=none; d=google.com; s=arc-20160816; b=j4BcIwtM6P3LU7RhtJYyrXDmInsN5s/lbnYiFiA2xC8tcZIEGRGKfjsf2YqnSMF/97 0P/89bHhUExoKjJZ4F9CBviQs3K61NJIgWKFslk4guLaTjGKKXBXKsuHpFNhqd+MbfMV ARn0iDdndnI6L1B+AKacvQqAT5i3Ng0CTAXQEWtUM45c3a6UGPSoSqSrgcGqmlRZYCST Odq3lbRlRsY2IRWC697d43CjW15xeMZBkFUsn0Nerjj7AoMWFsBevmsFjH3fdLmW6NBD 01SiARRND6ziLQJ3V1VfD8BWjj+w59FmnbG586WZJL5tKIjvYhJTzFF8iHWXK/DU/C7U PNWw== 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=dq1nWOk99Iuf2R/M3fcAK6et7xpaYsmaMZwbjaxcu9baqZQfzo5CSN73MKooTfxR0R 7+LKxW95C6EBBvsc0WMFieDfBb2A5nrk4MzGsx0YMz0WxlneH4YPwDyGNdMw49k2HptV N+gXD3RhNHc9NENyIzfozLdohy91WXcSWxFb1snFtNk43KuagK6OS6X0amLvlUHTz35r ApmAY3wByK/eBXzgM6zKXORzIanyZVH9V4pNcVRG+RSQGWE41IUV11O3JpoHLX2k8Kxv J+sELWFNUfHX2eDgQFd3XjoPvtW9MK+/k6lSJaIZGjU7jTGbRZ23OqRhr9cKJjk0gLZG Jkyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=N3kw6rDy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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. [23.128.96.37]) by mx.google.com with ESMTPS id bm2-20020a656e82000000b005b8ea4a4ab6si10360934pgb.623.2023.12.05.07.39.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 07:39:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=N3kw6rDy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 EFFD98092201; Tue, 5 Dec 2023 07:39:00 -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 S1442441AbjLEPiq (ORCPT + 99 others); Tue, 5 Dec 2023 10:38:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442439AbjLEPip (ORCPT ); Tue, 5 Dec 2023 10:38:45 -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 34AA483 for ; Tue, 5 Dec 2023 07:38:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701790730; 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=N3kw6rDyr94qyK+OsXWnvGsGgv24XSuPC3YEVr9KhIF+qhB3e8qBorY5SGKV3fq/W9yk03 HK59APqX0SU79U95esvNr1XobP/icVuElUusFWdQbov9JmfMWfAax1MA+d5DDsbHcw+QzV LSIp3bh9GueJI2Yo2ThMmVdqm9Z1o9c= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-302-xwj0RPsdP5eDHz9Vm4sFOQ-1; Tue, 05 Dec 2023 10:38:03 -0500 X-MC-Unique: xwj0RPsdP5eDHz9Vm4sFOQ-1 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-54cc7651e4eso131456a12.0 for ; Tue, 05 Dec 2023 07:37:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701790673; x=1702395473; 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=q4QrdIxN9u4BmlTPTMATWietESfkguhAxoSrWMD5Sooq/ymNdfzZBjlPb/qv+V61+O qe3YtzHwwJZ7847MjQKcCAkW0dXmTD37E89LFmKtZ/i6AHcDvTj3/eN8304pEFPvSQPP WsFg/TmgPH9fooAqICQmQDfhtfgXvXkMsN54b4yzzcUZ4CO337qc27Wp8fnph+2mJGdf J57qoJx3tVsDzPOvXAQWGqTN5kgeQb1X6BpZdjX0egGVsfM0XSis1buggNY2V3gKqedk 9UIrCuUxkuD3Se11UJ9408pPPk6UjoC8dwGQ4F6uPwxDZZnQbsp2fsnI5rev/bjzRak2 yr5A== X-Gm-Message-State: AOJu0YxxKTJzX919DS9dYCB2C9i9eEDuCVeSgQADo7ynGw6I2fsu021+ 5fhgfBIr/sQpEB2pbsXomAwJUzGqsLbkg31woU21NeVhwu6jZhEgnw/dkUFGiFHRHlaTu/5tmKt DQfHZUuUJGlE0FEQg4EbFX7NS X-Received: by 2002:a05:6402:1d0e:b0:54d:2efd:369e with SMTP id dg14-20020a0564021d0e00b0054d2efd369emr1100573edb.1.1701790673581; Tue, 05 Dec 2023 07:37:53 -0800 (PST) X-Received: by 2002:a05:6402:1d0e:b0:54d:2efd:369e with SMTP id dg14-20020a0564021d0e00b0054d2efd369emr1100547edb.1.1701790673178; Tue, 05 Dec 2023 07:37:53 -0800 (PST) Received: from pstanner-thinkpadt14sgen1.remote.csb ([2a01:599:912:71c8:c243:7b37:30b:a236]) by smtp.gmail.com with ESMTPSA id r15-20020a056402018f00b0054c21d1fda7sm1244578edv.1.2023.12.05.07.37.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 07:37:52 -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 v4 1/5] lib/pci_iomap.c: fix cleanup bugs in pci_iounmap() Date: Tue, 5 Dec 2023 16:36:26 +0100 Message-ID: <20231205153629.26020-3-pstanner@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231205153629.26020-2-pstanner@redhat.com> References: <20231205153629.26020-2-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]); Tue, 05 Dec 2023 07:39:01 -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