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=1796210454; b=iTEQQPiHCLAos4is9xY5T9kW7aPCY9Gzzbs8Bp0tGXcD97jwzHnZCSMCkMFCIqmaR5P1 8ER2tBjTkkJ5zhM/H6M5EAbuYqiK3/fTe2oVLnZ4wWIXzagszlZrXBN9SX4BcjP6kCbLr sGRqykCXehpO58JNcbFLiXFjoLJOuncJXUdGqzz/pxT6SwgDd/KAW7qFKCbQlwkkou8wH zwxU3Xo44y9YRBiWNEwcz+jm5HlRV6j4vzH/R4tMBfPYZOqKHcPlSXt/bK6J9QxhaImES Bd9bdq758W2y0G2bL5zv9Y5xHoc+T4sl7tP3cvcO9nbwx3f0uj051SsdKwpvH4dZR+w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796210454; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted: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=B+jBmLTRRZTtvhA7lxon1aXY/BpXo2/DzcOtEy311LINtGtPRNbsVJaRWpVMcdbyEfiY PZiuna2EyJumfuU1VbsVaiywvXuHm0pydMRbvMxdEuotr3dJByLQzzWFcJ+/L9J+v4Mik I+RWcoeYIkSSVsVSqNldh7WcDE7eZ5AFel+Ob46/u8C2dBMFW8OmC4dCTEY8auvqJ8rqp fPFp0RPjechBs1jCTgB2GpfIQnRyxvnCA4ZzU2L7IdDhh9T1VFqR7K156mUgo1oTx+emG jUStlMYfqZxizv/na+EkSXmk4366LbeaG0CtPHyZFaBF/aUsTlKRWRzl8gNZvYbIZ5w== 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=FVAetaj5; 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 6FB73606A6AF for ; Wed, 2 Dec 2026 11:20:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6FB73606A6AF 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=FVAetaj5 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4a1fdde384cso95577645e9.3 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=vger.kernel.org; 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=FVAetaj5iuX8F1oXCbUxz3pdP4uZes2RWFnAg9bfFyesP6fR48Fz3TX58OKs3Fn6hQ HPAfKg04WqFhkQtBZrN57nEaFMn2bNZ3RZZWFo2XWXV/s8Y8JazQ7RPxjxOBsBcqpgai BUY+dysu2gW6vyBy5oUK4Rm9HqZ7dRQjzmCuggXgelQtbg+9dlo1e26LU96PjqHo/rMc eIztRwQjDWRHCuIOB5uPg6Vhrw6MM+kgSB+aopn2D9bS+mkVKQDha2qv0o3Pmj7qRf81 fkbVqyNdMQyQV3pXMmMO1JvwC2VYfdXAcYNYcTtHertLVBAqqKPCErxiqgzwaa5On1aJ J04g== 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=rwBgK81m5TkwwGpgAOX6t7j09Nt9NlFDtmxOgaH4tjGSrGbeRywjG9+A40zmZ2KPPm JFZSM0+trnrHH8oeYnE3DR0eKmvSJ2jB7FCviq35kxA8KzMpbvzFkEcbozN8BO+4q9Ot WsAuOdkQKMeit1HgpdKJkdKOv+l83NNPVfjta2Q4XqW/slj7ndp4a6XLhfV6/pgDKB0W Md5sBEyi2bCx128R5cAXs0jxrOmukZAd/Vgs2CspPPt8/wxb4CQrAFCCCyjOJ49Q4ig7 Npnzt/9e5CfgSWrdu7uPgJ8QvQ7eVRGQPJRv8PDanRYoTJSWN+xfaDDZVDfjpNZs/PSY irMQ== X-Forwarded-Encrypted: i=1; AL+hErFcFHEG5doTJ6KRIM6ByMCgqyu9fUxbStURKvIJIDFiK4HpZg+sGhshe9TSSpU5OnYzsBGRoiyPCgwwvqo=@vger.kernel.org X-Gm-Message-State: APuU4Z+hrJn0ZWf1XxFApHrLzt32Df/F6P66AvqoeeVd3QGcBR5aTNIL P+O/X2LIuNMqI0oOyo83KYeFSvFfeh5plOoeZT68h+tnge3ixIUOXCBKaJDDUxkOdHSfkZE0OVj 65urXgiAXzK9vuQ== 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: linux-kernel@vger.kernel.org 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