From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f47.google.com (mail-qv1-f47.google.com [209.85.219.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8DA2A3E639B for ; Mon, 25 May 2026 09:29:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779701358; cv=none; b=acHEe5VLUYxRJTvVFfKrFeU1/UbKN/LXbSJrfmmKz1FUoW7upSCH7k+ZtWxrookdBXsuSKYMv4e/gNDZD4H/7swIbEtcB/dTvzLTobBLtWKsTjMBcNkSuSrFYNBKOBjNGikX9qPCwpS0PZIqkQoXRrzQ5nj7ow+sNZLyt23UGFw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779701358; c=relaxed/simple; bh=fe/hnE8GZQrLciu77A+fejlNUzSNd3LNX6x61CvRXJg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qpwdlZOcEYgMdHAaHNbVTCbLotRxoYCkrQBVWHdOM3qXLui3jjYJSjun97fR4Xy4ItLByutH/hI9srmotvq9k831Ry/C3YNukTYMYNb//R/sv+a9tPYZJu0vZjuDzKgiBYZrmhpa8KgpJtqf2dCFVXGiGT6UPvIs3ChNghIwjAg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dPtEfQOQ; arc=none smtp.client-ip=209.85.219.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dPtEfQOQ" Received: by mail-qv1-f47.google.com with SMTP id 6a1803df08f44-8b701756684so110501686d6.1 for ; Mon, 25 May 2026 02:29:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779701344; x=1780306144; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8Iq5ZhrKPSPdMYnMkmpf5M3ZZW+Mtt1BsX+A9zE8LaQ=; b=dPtEfQOQyndCd2aaxBQmWPzup4sjsvtS0ZhfkYkObzTz/S6YdAdphSN+wXB8gfn74M Trsf+Iw+lstOB7ncvOziZECbtdVT+16TDfzIDUC+LvNgTQ8C5HduGsvvaaoteLDXmq02 BM7IgdSY2t9iTN3t/411+fdmbWHbVO9v6qy29bGgvj/UVljl+SpQEdO3PzqxFudCp98/ msOLvLp5WcWFtDtEBkzkTV3KZk/ruNcNH0I/DrO+6Hqk0mpfcZsiHXGnr7ondV7c9quR hnc06KSLiL4T7Hey6l1q2U2Qu8B5sABmulfaxdHBoP9zmeQ2NC97yp7wW9cUm9zVRgin v2xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779701344; x=1780306144; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=8Iq5ZhrKPSPdMYnMkmpf5M3ZZW+Mtt1BsX+A9zE8LaQ=; b=Xcj5FrZasaDNpP0k8mUOMGIu3ZuDpQB+pEq2Obmp+u10HHirvTU1HRIcTodDBFGQI0 BYKP8SFZf4Wo/zEuf1TWKLxqfEoAkqLM+qkucYuhk7k6N5/jIzozru3+Vy3EKkSSDg44 fJPYU+Yr5AE59ChoAorfWsQwzu8/yVVWXxYwPC3PqUh2vvbS9RPItePnFD6LqoSDSUcH tr4i+8WHSxO2X/zGcfyRHgjeUv/o2pUBO7heAUElTcULN+LaT0lXRJGd8vUTDfD3QIA4 t4COZ/5wwp84bwVon8oNjzNkTuY/nxfVj6UeVYo3XvaDz5xmh5f0oOiPHetkM29INgS+ tc5Q== X-Forwarded-Encrypted: i=1; AFNElJ+ozm39FO9+cOsBxH0hqYMVfT+xjzUC5ZBHD4Z9C+dZA8wCx8vPDG31Y0IlBy8dehfdknpI4wwnSNo9tWk=@vger.kernel.org X-Gm-Message-State: AOJu0YxTmKk7ZfskjYgujxRw9CPEG4LYITd4xUZyEDg/bCdjXVEEenxe evkTZ7boLbLKJZCucI9yRJYPUkDICNyqO1TMkB5EdlIgR2AtI7JYD53i X-Gm-Gg: Acq92OHK6p3GE9ucZSGnKh96g3H0r5Khbm1wOPnnaiX0X8VlctkcBkKdd3ILvxEdw/p pesv/QBUswNuhmlt5/aY2+r/ng9LUkCQXPUiAMkPYvoi/rPfABzEvIDRpkGrckpYvAPvTQF+snX EGhHCiuSBWNHCzkpSRYo+e1ueVu9LlTb8pXm2TrdtMKXn4tN9sXgigu1yk8SUaD08OTygBj8wtM ByHUXj2BECbeZdxh9LZ8YOO2mi4Xr4+fZ+oEMw4HksGOoOElye5K0IX08rlmWUZ9np9G8A3SqOx zS1Ue4YgetpM7d4pAn75buuo5tPdvXXGBqONOhtXuCG3yjuBey16+hT/bBJMFApDar2Hj1HGJOP esi7DHys0VAUcCzEcZZkailByeMmjq4rJ/9T+9Zo4ijQNLWBNjD14Oo0bg14HQ7aDZ0xkseSwzp YMfetYb+7tfjx1yRII16JRQ1jL6i5SdiQM/Llgl4uxhQmwF+4qCxHTEqLry8QMhyUKJlGWNhPYj A+FnLmSaoH8W2br6+fjUzq8y2bEFdSWbNTAQ7fQt0M= X-Received: by 2002:a05:6214:5882:b0:8a7:164c:d5c8 with SMTP id 6a1803df08f44-8cc7bf194acmr185185226d6.24.1779701344361; Mon, 25 May 2026 02:29:04 -0700 (PDT) Received: from server0.tail6e7dd.ts.net (c-68-48-65-54.hsd1.mi.comcast.net. [68.48.65.54]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8cc80dcf4a9sm104255826d6.2.2026.05.25.02.29.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 May 2026 02:29:03 -0700 (PDT) From: Michael Bommarito To: Mika Westerberg , Andreas Noever , Yehezkel Bernat Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/6] thunderbolt: test: add KUnit tests for property parser bounds checks Date: Mon, 25 May 2026 05:28:30 -0400 Message-ID: <20260525092830.735472-7-michael.bommarito@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260525092830.735472-1-michael.bommarito@gmail.com> References: <20260525092830.735472-1-michael.bommarito@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Add regression tests for the zero-length entry and root directory bounds fixes: - tb_test_property_parse_zero_length: TEXT entry with length 0 must be rejected by the validator. - tb_test_property_parse_rootdir_overflow: root directory whose content_offset + content_len exceeds block_len must be rejected. Assisted-by: Claude:claude-opus-4-7 Signed-off-by: Michael Bommarito --- drivers/thunderbolt/test.c | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/drivers/thunderbolt/test.c b/drivers/thunderbolt/test.c index 1f4318249c226..345f39ecd233f 100644 --- a/drivers/thunderbolt/test.c +++ b/drivers/thunderbolt/test.c @@ -2852,6 +2852,44 @@ static void tb_test_property_copy(struct kunit *test) tb_property_free_dir(src); } +static void tb_test_property_parse_zero_length(struct kunit *test) +{ + u32 *block = kunit_kzalloc(test, 6 * sizeof(u32), GFP_KERNEL); + struct tb_property_dir *dir; + + KUNIT_ASSERT_NOT_NULL(test, block); + + block[0] = 0x55584401; /* rootdir magic */ + block[1] = 0x00000004; /* root length: one entry */ + + block[2] = 0x61616161; /* key_hi */ + block[3] = 0x61616161; /* key_lo */ + block[4] = 0x74000000; /* type=TEXT, reserved=0, length=0 */ + block[5] = 0x00000000; /* value */ + + dir = tb_property_parse_dir(block, 6); + KUNIT_EXPECT_NULL(test, dir); + tb_property_free_dir(dir); +} + +static void tb_test_property_parse_rootdir_overflow(struct kunit *test) +{ + u32 *block = kunit_kzalloc(test, 4 * sizeof(u32), GFP_KERNEL); + struct tb_property_dir *dir; + + KUNIT_ASSERT_NOT_NULL(test, block); + + block[0] = 0x55584401; /* rootdir magic */ + block[1] = 0x00000004; /* root length claims 4 dwords of content */ + block[2] = 0x61616161; + block[3] = 0x61616161; + + /* content_offset(2) + content_len(4) = 6 > block_len(4) */ + dir = tb_property_parse_dir(block, 4); + KUNIT_EXPECT_NULL(test, dir); + tb_property_free_dir(dir); +} + static struct kunit_case tb_test_cases[] = { KUNIT_CASE(tb_test_path_basic), KUNIT_CASE(tb_test_path_not_connected_walk), @@ -2892,6 +2930,8 @@ static struct kunit_case tb_test_cases[] = { KUNIT_CASE(tb_test_property_parse), KUNIT_CASE(tb_test_property_format), KUNIT_CASE(tb_test_property_copy), + KUNIT_CASE(tb_test_property_parse_zero_length), + KUNIT_CASE(tb_test_property_parse_rootdir_overflow), { } }; -- 2.53.0