From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.70 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796210453; b=R/gZE1KIm8OD0X3iE5uYT9Yd9sDvhJOtxziEIj/YNsyXeA7M/wTzxb0C+uHlIexXcQFK iyPVYdugLp6YqDYt2rVxdQr5RGMLRRlkbXIwjct6xlFIxvpxOkk24u0MpOCgHGeKx9Gkm PyYpk6EpF7eCp905FhskFsoVWYcAq0RT5P8GjPxtxjif2M+XW8jFTWLqS4xH7YypKpi2y RpRgg8KsLOkOxAf7kxM5TWKLJdNXKh37z5EvQGT5NMqJs03APqh/r5ekKdKJYzJTIvGvi YqzjnvWqFwBgBBeT7dLVlfxbw9jLxFI2cTtc+KkXXL3Fia/NF3if8UIigKAdCbFI6rw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796210453; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Received:Date:In-Reply-To:Mime-Version: References:X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=QuZeJ7b8DixlpLRIqaS6iZUNdG8Hy7hb8gtlDgo3u6Y=; b=D7yM6M6hlMka66oOuNPWQODvdt4J5950X1Is5lpBSqJ9+Pq4aRP56OAh6ukfEebDVAzb RyUJuCE9h2DKCgB4L3tngGtDDDqNczrwWIem5KL2AVT09h5/Mom7XxE7ryphfbauZ5X6+ ZYzbhr8GQKMdSNWdyclp2FeiPbdJcJdwZoRaqJi2TlMeQF47OJpuJs16yIhH0r1WVtI3+ 7DI7l5oszgAHq0GUJmErUr3FbTlpZuAxgQp2lMVG+5jwDQQFjB4Y+yjGjIdkfSguAPBTH a8jaJw/9ehaFcIzJZsyPwXkbwDIyyeGE+lQSTRfzwh4IXLpW7/Zizm//a3scpBK6yDQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--smostafa.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=k7jK1Cet; arc=none smtp.remote-ip=209.85.128.70 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F0D0606A6AE for ; Wed, 2 Dec 2026 11:20:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6F0D0606A6AE Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--smostafa.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=k7jK1Cet Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4b9f8c66f72so19160285e9.2 for ; Wed, 02 Dec 2026 03:20:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796210452; x=1796815252; darn=lists.linux.dev; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=QuZeJ7b8DixlpLRIqaS6iZUNdG8Hy7hb8gtlDgo3u6Y=; b=k7jK1Cet5t+bOxRsKGpket4fScf753fgfgqnGX+9kXrva3nf3ipUjqellIIKQo6TUS Lqhnm0XNKsUV2pLOnmC7HYWD1XhKGETy8QjJulRzumgBBHugccRrL0dg4Zqo61/PY5ij CfowQfcxbnAGffRETDXDPGqN+14lYE6J6P/qfYN+8VqpWBndzQC2aW4Maf55fDjX3IL9 6D723NMfAzGp5KctOtXHr+IQ4Z31/Cg5XugC3f+74g0o2OQEyGpAZRGA3q88cqKyrgR8 J/6SnxqGandGlkNMRqGRW7zyQ0xB22gZk8dQ3sK7RJHbk5KCqJWDlKXJVljZz8Y699AJ IG2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796210452; x=1796815252; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=QuZeJ7b8DixlpLRIqaS6iZUNdG8Hy7hb8gtlDgo3u6Y=; b=oKkSug17pxPqRGkksXPggZxsIPG/bTkJliFiiHfMQsE2jdGb7IsXW4U1INM5dEqonb 8l6tcRxT0n2Btfkgif76dHCkI3nVR985T1ZVXD8B570TfgAZ6XasJ+B3mSLpszzo6G9O fKiRV27OU0kjNnKqLZJRFZPctJIkceQjNCJR9VczMpuoeOSh+LpTkFWdX8RKWXF+j1J4 XT8m9ypgSmS2C3xuUCkmCNMTLY0wYDPSCHvY0/OuLWOHQ7yz+KxHpSikaTUTFG2oKp9m KkYQe5nasZZm2vG67wodsBpWuhvvEMqXXMYCipN76jBOrlloBWM7MskRR31QagIzOf4n hO5g== X-Gm-Message-State: APuU4Z90B/j5LgA+YnvSTE/kxKZS1zFYw4nv0aIiGIREd6YM8j9toX9T TnQ6jIcocwmGcRaPssjphAj13MXHiPTAfKouxOrFMYRrun+mI5ABiACsQ9tk04+tcB4ZJFsPa3B VlKXtBAw1rJXLLN1JRj4Go9JLKMRBaMPonCx21R+m0fX92cY7t19vRoy5bzewCU6+fDOXV+dWxN 39x+e4mpoWl/qGkIgWYT+o+nHos1k2VDJ+GM28B7y9A8oddA== X-Received: from wmpr22.prod.google.com ([2002:a05:600c:3216:b0:4a1:e780:89af]) (user=smostafa job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:800e:b0:4bb:7757:fe58 with SMTP id 5b1f17b1804b1-4bb8881b9d7mr820292775e9.19.1796210451605; Wed, 02 Dec 2026 03:20:51 -0800 (PST) Date: Wed, 2 Dec 2026 11:20:45 +0000 In-Reply-To: <20261202112047.509228-1-smostafa@google.com> X-Mailing-List: iommu@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261202112047.509228-1-smostafa@google.com> X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog Message-ID: <20261202112047.509228-2-smostafa@google.com> Subject: [PATCH v2 1/2] iommu: debug-pagealloc: Fix overflow checks From: Mostafa Saleh To: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Cc: joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, Mostafa Saleh , Sashiko Content-Type: text/plain; charset="UTF-8" There are few corner cases with the overflow checks: - __iommu_debug_map() checks phys + size for overflow into a size_t. On a 32-bit kernel with a 64-bit phys_addr_t (as ARM_LPAE) this would report an overflow for every mapping that ends at or above 4 GiB. The mapping warns and is not counted, and its unmap then underflows the page refcounts. - check_add_overflow() uses size instead of "size - 1" which would fire if the top of the range was mapped. And while at it, make the end in __iommu_debug_update_iova() an unsigned long instead of size_t for consistency. Reported-by: Sashiko Link: https://sashiko.dev/#/patchset/20261111185931.94882-1-griffoul%40gmail.com Fixes: 7e84593795b3 ("iommu: debug-pagealloc: Track IOMMU pages") Signed-off-by: Mostafa Saleh --- drivers/iommu/iommu-debug-pagealloc.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/iommu-debug-pagealloc.c b/drivers/iommu/iommu-debug-pagealloc.c index 80164df5bab1..5faf53aa29f9 100644 --- a/drivers/iommu/iommu-debug-pagealloc.c +++ b/drivers/iommu/iommu-debug-pagealloc.c @@ -98,10 +98,11 @@ void __iommu_debug_check_unmapped(const struct page *page, int numpages) void __iommu_debug_map(struct iommu_domain *domain, phys_addr_t phys, size_t size) { - size_t off, end; + size_t off; + phys_addr_t end; size_t page_size = iommu_debug_page_size(domain); - if (WARN_ON(!phys || check_add_overflow(phys, size, &end))) + if (!size || WARN_ON(!phys || check_add_overflow(phys, size - 1, &end))) return; for (off = 0 ; off < size ; off += page_size) @@ -111,10 +112,11 @@ void __iommu_debug_map(struct iommu_domain *domain, phys_addr_t phys, size_t siz static void __iommu_debug_update_iova(struct iommu_domain *domain, unsigned long iova, size_t size, bool inc) { - size_t off, end; + size_t off; + unsigned long end; size_t page_size = iommu_debug_page_size(domain); - if (WARN_ON(check_add_overflow(iova, size, &end))) + if (!size || WARN_ON(check_add_overflow(iova, size - 1, &end))) return; for (off = 0 ; off < size ; off += page_size) { -- 2.56.1.911.g883d8bcb20-goog