Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795018365; b=bU2LJH9no83a4yoWHaFKsdXz60GxRfcUc87vs04ls4rUGC8HKG2ndIXArzUAaPoIxl49 QWVqa/DeCuJzcOny8uqoR4QfCCpetEn1Xav56mYZj8jao436Q3+ZJKov2rl0LzFO7CSo8 FFR9pVKet/aHz0OWnIAvWm7pIS5EZkUldVyJGH+K6QYIk43T4At2npLFzO/uKca6h7bOj bkxnQLXmEeKgDKcomqQgPrXaLdJr6NE2J9W/MkGeTEApBda9tkqGov4FoJRUipoNMRXHl oCffils+sCzsm9XV+oQ1IFrVh/8BbfaFV/6HkhbqwPupqQFg6GaZbV9BuX3I4B++H0Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795018365; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=zyNTiW6ptaDmCG/OxMtfRElgmuSth4lJ6R+T/MD5Fyo=; b=qlHNcZ/jHyt2pEilcO/s3lX1WVhb+Q6JinPJI5bg9TSiaiiI9b8U7UbpFVvVyGqE1Dyv 3CR0BKRHf95QyPILF0bhri6AzrNdjAtTSW82769Yca1vfSBfPhuzC3cJBHV7ftUqDwz2W CD3pyZpClZKgNG8PX0HfWEeow6PvuWKluh2pvIS5yz9T3RwykGDxc6BG+CPFSKhDtbeVw S5rH0N4P4G+buDEjNMOLg13yWCkHEjlR+dtQs9bVITrZreoriefU2p9nkRUUgqeN80msG caLaOSmPwNKe0rGvZwGpyXH4Cuf+7wKXuDcZ/PIMP1wmaBKwQ8M9HztWpKUuB93v30Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=r7WC86Q+; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 56664606A32F; Wed, 18 Nov 2026 16:12:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=r7WC86Q+ Received: by smtp.kernel.org (Postfix) with ESMTPSA id B740A1F000C4; Wed, 18 Nov 2026 16:12:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795018365; bh=zyNTiW6ptaDmCG/OxMtfRElgmuSth4lJ6R+T/MD5Fyo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=r7WC86Q+0DcwX+DhSIlE5qdd2EvK30P0jGQrZYeP8LwJA2gpOkptHjz4eFY8zMh8o 2EwHb2pFI2pe3HzFYZscdPmUPyXFXGWRKywzTTOg5Ta5QK//19mt5rBXm3hlE6gN/d QGjxmzpQYlQvZyzSHMhFRLEQM1zwxTQhePqIQavY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Nicolin Chen , Jason Gunthorpe , Mostafa Saleh , Pranjal Shrivastava , Will Deacon , Sasha Levin Subject: [PATCH 7.3 1177/2651] iommu/arm-smmu-v3-test: Fix UBSAN error Date: Wed, 18 Nov 2026 15:40:17 +0100 Message-ID: <20261118150330.384308605@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150247.972732815@linuxfoundation.org> References: <20261118150247.972732815@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mostafa Saleh [ Upstream commit b370a5e979f8bb8f34e30ad126ade734d8f128c0 ] struct arm_smmu_invs marks its flexible array member inv[] with the __counted_by(max_invs). arm_smmu_v3_invs_test() uses invs1 to invs5 which has num_invs = 3 but omit max_invs. This causes the following UBSAN error: [ 2.333240] UBSAN: array-index-out-of-bounds in drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c:1116:21 [ 2.333604] # arm_smmu_v3_invs_test: lib/ubsan.c:228: array-index-out-of-bounds in drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c [ 2.334129] index 1 is out of range for type 'struct arm_smmu_inv[] __counted_by(max_invs)' (aka 'struct arm_smmu_inv[]') [ 2.335375] CPU: 6 UID: 0 PID: 155 Comm: kunit_try_catch Tainted: G N 7.2.0-g8dcb331fbb72 #2 PREEMPT [ 2.335759] Tainted: [N]=TEST [ 2.335791] Hardware name: linux,dummy-virt (DT) [ 2.336254] Call trace: [ 2.336932] show_stack+0x18/0x24 (C) [ 2.338443] __dump_stack+0x28/0x38 [ 2.338494] dump_stack_lvl+0x54/0x6c [ 2.338518] dump_stack+0x18/0x24 [ 2.338541] ubsan_epilogue+0x10/0x44 [ 2.338565] __ubsan_handle_out_of_bounds+0xb8/0xbc [ 2.338834] arm_smmu_invs_merge+0x688/0x8ac [ 2.338862] arm_smmu_v3_invs_test+0xd4/0x598 [ 2.338890] kunit_try_run_case+0x64/0x160 [ 2.338914] kunit_generic_run_threadfn_adapter+0x28/0x4c [ 2.338955] kthread+0x10c/0x12c [ 2.338984] ret_from_fork+0x10/0x20 [ 2.339433] ---[ end trace ]--- Explicitly set max_invs = 3 on the test arrays to match the number of elements. Fixes: 15a2a5645ad7 ("iommu/arm-smmu-v3: Introduce a per-domain arm_smmu_invs array") Reviewed-by: Nicolin Chen Reviewed-by: Jason Gunthorpe Signed-off-by: Mostafa Saleh Reviewed-by: Pranjal Shrivastava Tested-by: Nicolin Chen Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c index 244cf34e5a0b8..e52a7d95c919d 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c @@ -654,6 +654,7 @@ static void arm_smmu_v3_invs_test_verify(struct kunit *test, } static struct arm_smmu_invs invs1 = { + .max_invs = 3, .num_invs = 3, .inv = { { .type = INV_TYPE_S2_VMID, .id = 1, }, { .type = INV_TYPE_S2_VMID_S1_CLEAR, .id = 1, }, @@ -661,6 +662,7 @@ static struct arm_smmu_invs invs1 = { }; static struct arm_smmu_invs invs2 = { + .max_invs = 3, .num_invs = 3, .inv = { { .type = INV_TYPE_S2_VMID, .id = 1, }, /* duplicated */ { .type = INV_TYPE_ATS, .id = 4, }, @@ -668,6 +670,7 @@ static struct arm_smmu_invs invs2 = { }; static struct arm_smmu_invs invs3 = { + .max_invs = 3, .num_invs = 3, .inv = { { .type = INV_TYPE_S2_VMID, .id = 1, }, /* duplicated */ { .type = INV_TYPE_ATS, .id = 5, }, /* recover a trash */ @@ -675,6 +678,7 @@ static struct arm_smmu_invs invs3 = { }; static struct arm_smmu_invs invs4 = { + .max_invs = 3, .num_invs = 3, .inv = { { .type = INV_TYPE_ATS, .id = 10, .ssid = 1 }, { .type = INV_TYPE_ATS, .id = 10, .ssid = 3 }, @@ -682,6 +686,7 @@ static struct arm_smmu_invs invs4 = { }; static struct arm_smmu_invs invs5 = { + .max_invs = 3, .num_invs = 3, .inv = { { .type = INV_TYPE_ATS, .id = 10, .ssid = 2 }, { .type = INV_TYPE_ATS, .id = 10, .ssid = 3 }, /* duplicate */ -- 2.53.0