From nobody Mon Jun 15 13:55:59 2026 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 CD9C12877F6 for ; Fri, 10 Apr 2026 12:56:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775825782; cv=none; b=YBeRnNekSNj3UOwXVUXEDtiN2qfxpYXHk2jawyw93YxXGCABPrBirslVI+gd0AyndUlSHOAM+ol0ELWAG8lmxD6h4lkf0rqcloN0LS7zUAvjoqAFTFjHqEyN6v3LAdceBIwwjGdMvob6odsVtmLm1yRTNkai2SP35tiabBlcmYM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775825782; c=relaxed/simple; bh=jQ0D9YP29owC0fujodI0kwK6Vi7Aoh6n+jNjA5ohHZ4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=FSiTOwgIkiWD6j7VXnV3Hu5k9zpm4f1HXlIF/ZnIeB8wk1uo46ocLHfVJSTyTvHtdDW6sqQkjdR5vFxkGkAAjK6iCGTlWE9w6yIC4PA9O0uTBJJpbioPUr0y1EhuGGp2yAlBa/ccXiAqKPAqxepU9Gj3/HGOIIYRSSccILMupSY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=CrXB3YU9; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="CrXB3YU9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775825776; 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; bh=rQok3OB45+l4fCfg+tNaYuiwZC4TiksQDUZba1BoN2I=; b=CrXB3YU92srYIABRwjC9bPMjXo3XW4WSBIHOb7ejXyXpTbOJeuwExjR4jJyGDCGXTmN3Qu XsOTmDSgxYzWXGrsd7zaXjLAtwKozCMoevMQAFK7dfzP2S9LxGU5ZgkdQt04S0tABMKX0d 1tfRC4ncBa7GhowsfnSGgczKu5T/ZwA= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-572-P0xdzv9YMdqDyi2Pbcy56A-1; Fri, 10 Apr 2026 08:56:11 -0400 X-MC-Unique: P0xdzv9YMdqDyi2Pbcy56A-1 X-Mimecast-MFC-AGG-ID: P0xdzv9YMdqDyi2Pbcy56A_1775825768 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 46F98180044D; Fri, 10 Apr 2026 12:56:08 +0000 (UTC) Received: from ezulian-p1gen7.rmtde.csb (unknown [10.44.48.169]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A350B1955F2E; Fri, 10 Apr 2026 12:56:05 +0000 (UTC) From: Eder Zulian To: joro@8bytes.org, suravee.suthikulpanit@amd.com, will@kernel.org, robin.murphy@arm.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org Cc: Eder Zulian Subject: [PATCH] iommu/amd: Remove latent out-of-bounds access in IOMMU debugfs Date: Fri, 10 Apr 2026 14:55:50 +0200 Message-ID: <20260410125550.187398-1-ezulian@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: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Content-Type: text/plain; charset="utf-8" In iommu_mmio_write() and iommu_capability_write(), the variables dbg_mmio_offset and dbg_cap_offset are declared as int. However, they are populated using kstrtou32_from_user(). If a user provides a sufficiently large value, it can become a negative integer. Prior to this patch, the AMD IOMMU debugfs implementation was already protected by different mechanisms. 1. #define OFS_IN_SZ 8 ensures the user string <=3D 8 bytes, so e.g. 0xffffffff isn't a valid input. if (cnt > OFS_IN_SZ) return -EINVAL; 2. Implicit type promotion in iommu_mmio_write(), dbg_mmio_offset is int and iommu->mmio_phys_end is u64 if (dbg_mmio_offset > iommu->mmio_phys_end - sizeof(u64)) return -EINVAL; 3. The show handlers would currently catch the negative number and refuse to perform the read. Replace kstrtou32_from_user() with kstrtos32_from_user() to parse the input, and check for negative values to explicitly prevent out-of-bounds memory accesses directly in iommu_mmio_write() and iommu_capability_write(). Signed-off-by: Eder Zulian --- drivers/iommu/amd/debugfs.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/amd/debugfs.c b/drivers/iommu/amd/debugfs.c index 4e66473d7cea..4c53b6361314 100644 --- a/drivers/iommu/amd/debugfs.c +++ b/drivers/iommu/amd/debugfs.c @@ -31,11 +31,12 @@ static ssize_t iommu_mmio_write(struct file *filp, cons= t char __user *ubuf, if (cnt > OFS_IN_SZ) return -EINVAL; =20 - ret =3D kstrtou32_from_user(ubuf, cnt, 0, &dbg_mmio_offset); + ret =3D kstrtos32_from_user(ubuf, cnt, 0, &dbg_mmio_offset); if (ret) return ret; =20 - if (dbg_mmio_offset > iommu->mmio_phys_end - sizeof(u64)) + if (dbg_mmio_offset < 0 || dbg_mmio_offset > + iommu->mmio_phys_end - sizeof(u64)) return -EINVAL; =20 iommu->dbg_mmio_offset =3D dbg_mmio_offset; @@ -71,12 +72,12 @@ static ssize_t iommu_capability_write(struct file *filp= , const char __user *ubuf if (cnt > OFS_IN_SZ) return -EINVAL; =20 - ret =3D kstrtou32_from_user(ubuf, cnt, 0, &dbg_cap_offset); + ret =3D kstrtos32_from_user(ubuf, cnt, 0, &dbg_cap_offset); if (ret) return ret; =20 /* Capability register at offset 0x14 is the last IOMMU capability regist= er. */ - if (dbg_cap_offset > 0x14) + if (dbg_cap_offset < 0 || dbg_cap_offset > 0x14) return -EINVAL; =20 iommu->dbg_cap_offset =3D dbg_cap_offset; --=20 2.53.0