Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7594483rdb; Thu, 4 Jan 2024 01:07:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IFj/39YLkSj1FQM6H82A9iesqu6kDj02+1pxEJ1T2mcu0wW+em9S0p5DaWMlMXVDPlY/phT X-Received: by 2002:a05:6a20:969b:b0:196:8f76:d706 with SMTP id hp27-20020a056a20969b00b001968f76d706mr251137pzc.51.1704359258642; Thu, 04 Jan 2024 01:07:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704359258; cv=none; d=google.com; s=arc-20160816; b=EpxUes7IAjw7srhV1R9pOLleggufGvLb/Q0mKw5L184ekVIbavm2gdErZEgZUPadA/ lISA7IYgCHiUD1q8iawkCacTiyGdhSo5jYO/WAaGFp+/QbRRdx3p6BPZ+1+ccSC6gC2S Lklkt4944sCIECn1/dZWSstEVbHVRP6l2Iazikgkj2KT4Zqjs966cWyVwHsM1cSwM0pk Z8si6oJkKv9QsmQrcToyK30fFI9G171qlRTgb6yvAaelk5bZBUtisZ1O5sqKutUE9PSA gmBbwbQDK0oqo07X0IAt9kslW+KQ9S9sS1zH9vAHHBZnhotebV/6hTaEIxUft169jagY LSIw== 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=kGdM0EfuZR/H7f70HShHRRNNEVlxb/jNIQpkioD8QujT6ciq+LkR6P/Btei12eQZ1e j3pZjTDe57fjTINzTOg2tu7ZR3uOlHyJBnjflXSxxbYK3V8Uc1wm42tc9i8zApO9Cn4k iAH6vZSk8w2Rn44OsdnS65p4wQqxc3PFU8Xi7iThx/8ppsW01tYA6uNI2jhpmtTIz1g/ W4KjeemSZdo00zGsjz35WHfAc8MjkNRSf5VcwP3A5j8TuFNKh3ipzmV9/18Mqmirt/S/ Iid7zvtqe0nSFdN9vEdAzkdDydXxsV1xekNHxOas28QoA7N5mFsrVwt7O6U+abFUR9nv pyuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=a0jZ3uHY; spf=pass (google.com: domain of linux-kernel+bounces-16418-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16418-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id f66-20020a625145000000b006d9b8e39129si17311227pfb.245.2024.01.04.01.07.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 01:07:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-16418-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=a0jZ3uHY; spf=pass (google.com: domain of linux-kernel+bounces-16418-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16418-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 4C2C52836AE for ; Thu, 4 Jan 2024 09:07:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C3D7A20309; Thu, 4 Jan 2024 09:07:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="a0jZ3uHY" X-Original-To: linux-kernel@vger.kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 8D62A2030F for ; Thu, 4 Jan 2024 09:07:26 +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=1704359245; 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=a0jZ3uHYMca+MD8tZbIb41B+cMT9VZF7ULx1U5q+kxRjGFu1CR55b9sAA843syvCdmqnol eaUeTINo7WjpmNCV6um1JlMtghDfM52CE4g+IXf/qzBfUMkGCSzbSxc7RuF2EylPWVUdEQ jm8RkXBh4b7pOVcJMn9OamY50m6p4lQ= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-472-HAhkJWpENJ2EWeZaDCopGA-1; Thu, 04 Jan 2024 04:07:24 -0500 X-MC-Unique: HAhkJWpENJ2EWeZaDCopGA-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-40d87d87654so728265e9.0 for ; Thu, 04 Jan 2024 01:07:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704359243; x=1704964043; 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=p0bKz2q1JLEDgCQafpVgpzSCbpLOMxsDRcPI+jrqMcICjJfbNQKYjXWEHZQ9GxxSe3 O7udkfPD5ImWEz7dyWgM9u5mY1QxAKzk87nX2L/e3s1dEL9rIAB1jxKJ/O7aL/qgxGOW 2yvEIZW45L9c+aP3MRUhD7zT7243hclB2zDzbEuIJadrlp5WW3Cnp28wsVm5bQxCeUao 2yeZzXGNGhO6tMVFH+ugVQYY1T4YUWEPWBz8xrKslzmDu5nyhGqAz4tu8EYAteUEZpYY l5M7fEmHwltufGa8CjlAyxjmqGzpz51fNv4zLU5DtlgVvcq23c0TkZF4Ptn5UPaSNya6 PfCA== X-Gm-Message-State: AOJu0YwD1Q79zhq+jbMNEjw66vUp2nEnjpXGXgCr6+V/ewR3PWHn9txJ u3oqYJd8QxKjrNanM5MjWhOse7pmBkyF8RvwVh4IdsB20B9gLejzh0h8N8B/YRIig4rJm2Ye9V9 xqhC3ytuMH+5f2nZj8FtTdZC33Saskijl X-Received: by 2002:a5d:5f95:0:b0:337:3cf6:ed4c with SMTP id dr21-20020a5d5f95000000b003373cf6ed4cmr443073wrb.4.1704359243214; Thu, 04 Jan 2024 01:07:23 -0800 (PST) X-Received: by 2002:a5d:5f95:0:b0:337:3cf6:ed4c with SMTP id dr21-20020a5d5f95000000b003373cf6ed4cmr443049wrb.4.1704359242584; Thu, 04 Jan 2024 01:07:22 -0800 (PST) Received: from pstanner-thinkpadt14sgen1.muc.redhat.com (nat-pool-muc-t.redhat.com. [149.14.88.26]) by smtp.gmail.com with ESMTPSA id h15-20020a5d430f000000b0033740e109adsm8720864wrq.75.2024.01.04.01.07.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 01:07:22 -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: Thu, 4 Jan 2024 10:07:05 +0100 Message-ID: <20240104090708.10571-3-pstanner@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240104090708.10571-2-pstanner@redhat.com> References: <20240104090708.10571-2-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