Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2674599rdb; Mon, 4 Dec 2023 04:39:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IGAKYeHwYyqyfJK7DwbOVZRiVcP1jbdP5uj7bJlcP9Ltbd40pWSFIT0rQBn8CfDCGUKfXqH X-Received: by 2002:a05:6a00:1484:b0:6ce:2732:588 with SMTP id v4-20020a056a00148400b006ce27320588mr3544146pfu.57.1701693563851; Mon, 04 Dec 2023 04:39:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701693563; cv=none; d=google.com; s=arc-20160816; b=j89bzrlXpNSTu9Yy5LkETXQV0mTh1LJALxbPXwRnWfVNnn34aE4XYsxoPhN+9eLrnl Kh3Jk1f2Bz2Ml84IMu6GVp5FtNmp+lZd7mCzBh8IRkC9vsO6UYLfeY9E7gv/ZKyGF519 Zyf2CfVc6EJ/d0zq/0OxgU7mhPxzhoLgO2VyHQpp/IAq3IPbzC8vt3Z9p3FNTc7Jt6cx KMV0NT8chk4iygHUtmJidhAx4KjBdAgOvY2jdgGPO45rcHyX+8p6o0nCkFlgFodEzh+G madko3c5EXHZHk0T9EqjZiORU3EmujEEUw3ZUqSKPxZ/uuXdIU1tdsQYAgbR5IMZP6up r/LA== 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=FFtPPFlPjH6SVTrSMMFZ3PPUy8xNeziB9aHHtXxHnVY=; fh=2vwwX+iCPu3LS81nXQGahmvHbfQp52wqZUB9rI0GyOE=; b=kKWrH9lNqZFmdzT98JoE7hKt4rNvLxwMvDokWAGx+OMVAs8JAswGM+m/IUkQ4QQz28 2n6wg+2mJh29Bv/wmPVnYZK61C+Y7ok+5mT/AWFqyuCg/TaV0ULl938Kgszb1ZoF0QOY 2E2TCjhH8j4HtYBIoVPJOPO2MUygKIx+ZE3ZxJak6PZSD89KN2Uk7TafPII5A/7rEPrs 5Fn4SmCk18JRKyW0sa9W0pr77Gn+/RSDmKh0Z+dQ4Bk6TX4FjZImqmd3uWu9IBA0To9U i5L3ogIRbA55d63x14MQ/RXbUGhiE6hqREJ37wxfIZGLhbhSWZ34RgeSNIGVEpItffNL XBUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UwcVCVE2; 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 f8-20020a654008000000b005bde6fae09asi3490758pgp.135.2023.12.04.04.39.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 04:39:23 -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=UwcVCVE2; 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 C8C5580A186E; Mon, 4 Dec 2023 04:39:22 -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 S233202AbjLDMjJ (ORCPT + 99 others); Mon, 4 Dec 2023 07:39:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233582AbjLDMjA (ORCPT ); Mon, 4 Dec 2023 07:39:00 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CE08199 for ; Mon, 4 Dec 2023 04:39:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701693544; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FFtPPFlPjH6SVTrSMMFZ3PPUy8xNeziB9aHHtXxHnVY=; b=UwcVCVE2Gn26ki5ZPyKX8Ez4rSR/Ftv5OelqtDSUGonTDPFgKuJUqMX1qWV7aRzf95GVau jlBdKFxYDlik3qS0bRZiD9VoIeFFLlvhZj9xl8Ci9i7BuL79LWf4/FOsdFArdPIHHZ/BGv h+EDWeQ/Tc9NTcIlyhedELA9S7PL/f4= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-681-I4_SdcEyOP-VNarMYYOOVg-1; Mon, 04 Dec 2023 07:39:03 -0500 X-MC-Unique: I4_SdcEyOP-VNarMYYOOVg-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-40b2afd72ecso6422825e9.1 for ; Mon, 04 Dec 2023 04:39:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701693542; x=1702298342; 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=FFtPPFlPjH6SVTrSMMFZ3PPUy8xNeziB9aHHtXxHnVY=; b=ZqiIx1xxg5SfQGoJp950mQbLQrXqWr8Yp4A3RmrkOZNQP4oJeWB36gYyN+Rix0vfbs /DIbX3Gt4z/75b5eVXogzCr93YUhcZe3WD29x1G1ZTensG6utJSoGekYY7CIm9EfoW4N g8bAK/3bTPhalBb6qzWaYBKA6BjCpS2XyrHiclW0x7EYtv9uI3BzwEPp8Shvxr9w/9cL 9t4V+7fbXLeND/J8Ys/g1CNCgYn/fZtgIt0Yf+IEYSlP1lCU4MWhOcpKW97/atlXPlVU OnRMygBxyv0mAXbpqkTGGqcSlZtYkKdQFmjEz9OMRJTZtoGatAv+a90fZCc0hTtQWAci TQBQ== X-Gm-Message-State: AOJu0YzP7yz1h0Gn5sneUXsKBzY3M02beIh1pzzIlpa8zTgA1qg9Iqic hHp+GqAQfk09vyCQ4p8Us/dd7vekujNv9eqD0gcP26rvJRUCo2fjlkdPRo+2ouUb5WFXffrqM4i o58ae2BGPlLCJPdIC3ADMIRir X-Received: by 2002:a05:600c:993:b0:40b:3d90:884e with SMTP id w19-20020a05600c099300b0040b3d90884emr20346569wmp.2.1701693542494; Mon, 04 Dec 2023 04:39:02 -0800 (PST) X-Received: by 2002:a05:600c:993:b0:40b:3d90:884e with SMTP id w19-20020a05600c099300b0040b3d90884emr20346552wmp.2.1701693542121; Mon, 04 Dec 2023 04:39:02 -0800 (PST) Received: from pstanner-thinkpadt14sgen1.remote.csb ([2001:9e8:32c8:b00:227b:d2ff:fe26:2a7a]) by smtp.gmail.com with ESMTPSA id d4-20020a05600c3ac400b0040b538047b4sm18355935wms.3.2023.12.04.04.39.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 04:39:01 -0800 (PST) From: Philipp Stanner To: Bjorn Helgaas , Arnd Bergmann , Hanjun Guo , NeilBrown , Kent Overstreet , Jakub Kicinski , Niklas Schnelle , Uladzislau Koshchanka , John Sanpe , Dave Jiang , Philipp Stanner , "Masami Hiramatsu (Google)" , Kees Cook , David Gow , Herbert Xu , Shuah Khan , "wuqiang.matt" , Yury Norov , Jason Baron , 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 v3 1/5] lib/pci_iomap.c: fix cleanup bugs in pci_iounmap() Date: Mon, 4 Dec 2023 13:38:28 +0100 Message-ID: <20231204123834.29247-2-pstanner@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231204123834.29247-1-pstanner@redhat.com> References: <20231204123834.29247-1-pstanner@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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_NONE, RCVD_IN_MSPIKE_H4,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]); Mon, 04 Dec 2023 04:39:22 -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 --- In case someone wants to look into that and provide patches for kernels older than v5.15: Note that this patch only applies to v5.15+ – the leaks, however, are older. I went through the log briefly and it seems f5810e5c32923 already contains them in asm-generic/io.h. --- 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