From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) (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 7BF153CD8AC for ; Sun, 3 May 2026 14:15:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777817734; cv=none; b=A0WMnSOiv6jDHxrtjRBh0xanlxxNa8EH9csdOzA2YtXH+QNLlNIQfiROv9yjOKSjNjPULFNFEFvRixN6drRri0OyYEx4Gwsh1rLnGtjo0TYZr3Q84wWsB4FHlN2kjnHiKQviedF+QVccfIxehEbFBF/F3cC7yCVqIyOSI2VXZN4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777817734; c=relaxed/simple; bh=sNYg3v35X3Zb6ai1EEiwl45wwE7v2/fvnp/4sYLMCpA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BYjS3YPdDvmWFggHcfFI716cIrqz3IEto2uiDm+HOmkNmN07f4YrtzDr5W5hVhAi8WkUzzkMQpOya8c9xDPbc0zzGVgKy99s+hIiS0HXvdrWzB0XiRL1nxXdDhdXGWX0OJVf1AScFsrBJ4jQ877GAgxhpOaDGHf6NFX3oy9VCV0= 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=N4OZm5fB; arc=none smtp.client-ip=209.85.222.179 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="N4OZm5fB" Received: by mail-qk1-f179.google.com with SMTP id af79cd13be357-8f0a87e23daso344456185a.1 for ; Sun, 03 May 2026 07:15:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777817732; x=1778422532; 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=i+ka8zjHbzrAJc7Li4EgptLPQUFhFF6o2unBqDH+EWo=; b=N4OZm5fBSV3d40wA+/gFKdacCBK6iqA8fy7trjJrmUP4dRQA7fmYPnXeAs1A9bVQY9 E7NbdUNv7A/FxerTZFSI3du2E4zHhbczBeb609Dcf1GkWuSvLSUv2LUSe4zw3Rd+bfbj 8b2giS4luaKrFSY3gwc7R+JF+c6Ww7sCIh0xybWrOA6P5DtqEJRUdb/ZKYet8QmVQ+UE PdhGbkRe2SCUMoFx2Ud0xnE+FQYqigDaQIcMnLcMrXZEastvivnqgSvk5x2Z6sAa1Qxj jnTHZQ4iVuNDD0+TmVJDA/4I2sySGXFKIvxZDv1whb/9D2ipl1detkOGGTHTmkkKU6iU qHJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777817732; x=1778422532; 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=i+ka8zjHbzrAJc7Li4EgptLPQUFhFF6o2unBqDH+EWo=; b=m9YRgeBurkg/M4YGIxLywHTNFSNpmmvlEoETLK+ib33dvYraOiqZE9IPLI6oSQfhcr u23jKX8Srt/fGIKq9no1X9XpNzqzwAm3KoM+VdG3NGlD9H+UdImPPTn33Ept5huHZJ7l nNDlqVi5xwrPEp8SwOgdqE210h6T8KbGmImiU+dwRHcNs3Jeo4tBIHBNpZ8d2lzyFgZR lm4ivlchJhZWS21YurEcScsq/9b2V/iqmKWnWXdadnjc2TPRbar8nDUmZJrmgOWbhtEc pmz0QR5GcFJ4PG6887brSDTcU+Xz1m7XyoiZx+QdhgD+nvJw5FQbwpwe947zbBMrSthZ JHuw== X-Forwarded-Encrypted: i=1; AFNElJ9Je8NnifYoyRPACLOiZa6lbpLw/1zIznmVrHQWhIxN0SCcefx5fYQsCytk2rjrTxE2z6QnTzx3reNhAz0=@vger.kernel.org X-Gm-Message-State: AOJu0Ywb6dm7pyGA2EUOO4SPq/Z5awRGQMaubb7I9Q8I1SPH6UM8VsnN RDa5+TIyL9s/duEbfs99Y8FhqAHRfhSiU0LF+uZujPMkzBq8MJjKR+f4 X-Gm-Gg: AeBDieu28oig7mJFBSOnVYirPTrZUoRMD+CCm+JOw6cf6FANYenczZtT3gjowUN3gbG hwf3j6ND+4M/wUuBEgy/9yPod6S48FGwtxJZaNEdEQYZeOUS/HQWKGKJdAfkG+/AwdbBBJk6y1S kYyZdlgtf9/Zpj+uWERAvA+SOmxkGwtoHVYWDZjZA6S1Lctbxcs7LnODbwel4o4hrJXpAf+qsOl rgobohX/2JT8GuCGXkQ92oDWzFVmlt3Qdl/OKjqLmeRIu+Bz9NNf/m5O4tGTUs+vi9uWewVklNN aUzuQAB0BoFVVNG5Jl/3AxajR6DALo6J4w9RIPkoP0epCIcOZzszUnN5S0nI1S45b3Yf2rVRgAj 1ZyHsPdsJyeUQ0zrdu7909Y5IepGV+fO+J4ijM/38caWhn4N2xd0jx/+ke/jkLhnt0atw+UZz9g qWqLraYUy5FnCN6KrLGDOvX34K1t6jl7endT0Nz6GL/pUuoDd4wvnqcikyLp6ToqVg7Ti8yznoj 6nbsK2i2F5zk5IFPxxBza7RA9Ls42k= X-Received: by 2002:a05:620a:450c:b0:8d7:e3ab:4c17 with SMTP id af79cd13be357-8fd1824178bmr976368885a.41.1777817730017; Sun, 03 May 2026 07:15:30 -0700 (PDT) Received: from server1 (c-68-48-65-54.hsd1.mi.comcast.net. [68.48.65.54]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8fc2938e0b9sm766261985a.9.2026.05.03.07.15.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 May 2026 07:15:29 -0700 (PDT) From: Michael Bommarito To: Mika Westerberg , linux-usb@vger.kernel.org Cc: Andreas Noever , Yehezkel Bernat , Andy Shevchenko , Michael Jamet , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v3 2/4] thunderbolt: property: reject dir_len < 4 to prevent size_t underflow Date: Sun, 3 May 2026 10:15:06 -0400 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: <20260415123221.225149-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: 8bit On the non-root path, __tb_property_parse_dir() takes dir_len from entry->length (u16 widened to size_t). Two distinct OOB conditions follow when entry->length < 4: 1. The non-root path begins with kmemdup(&block[dir_offset], sizeof(*dir->uuid), ...) which always reads 4 dwords from dir_offset. tb_property_entry_valid() only enforces dir_offset + entry->length <= block_len, so a crafted entry with dir_offset close to the end of the property block and entry->length in 0..3 passes that gate but lets the UUID copy run off the block (e.g. dir_offset = 497, dir_len = 3 in a 500-dword block reads block[497..501]). 2. After the kmemdup, content_len = dir_len - 4 underflows size_t to ~SIZE_MAX, nentries becomes SIZE_MAX / 4, and the entry walk runs OOB on each iteration until an entry fails validation or the kernel oopses on an unmapped page. Reject dir_len < 4 on the non-root path *before* the UUID kmemdup, which closes both holes. Also move INIT_LIST_HEAD(&dir->properties) up to immediately after the dir allocation so the new error-return path (and the existing uuid-alloc failure path) calling tb_property_free_dir() sees a walkable list rather than the zero-initialized NULL next/prev that list_for_each_entry_safe() would oops on. Fixes: cdae7c07e3e3 ("thunderbolt: Add support for XDomain properties") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-4-6 Assisted-by: Codex:gpt-5-4 Signed-off-by: Michael Bommarito --- v2 -> v3 (material): - Move dir_len < 4 reject before the UUID kmemdup in the non-root branch. v2 ordering let dir_offset near end of block + dir_len in 0..3 OOB-read the kmemdup before the reject ran (dir_offset=497, dir_len=3, block_len=500 passes value+length<=block_len but kmemdup reads block[497..501]). - Fix Fixes: SHA (was e69b6c02b4c3; correct is cdae7c07e3e3). drivers/thunderbolt/property.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/thunderbolt/property.c b/drivers/thunderbolt/property.c index f5ee8f531300..90fa6f760963 100644 --- a/drivers/thunderbolt/property.c +++ b/drivers/thunderbolt/property.c @@ -173,11 +173,16 @@ static struct tb_property_dir *__tb_property_parse_dir(const u32 *block, dir = kzalloc_obj(*dir); if (!dir) return NULL; + INIT_LIST_HEAD(&dir->properties); if (is_root) { content_offset = dir_offset + 2; content_len = dir_len; } else { + if (dir_len < 4) { + tb_property_free_dir(dir); + return NULL; + } dir->uuid = kmemdup(&block[dir_offset], sizeof(*dir->uuid), GFP_KERNEL); if (!dir->uuid) { @@ -191,8 +196,6 @@ static struct tb_property_dir *__tb_property_parse_dir(const u32 *block, entries = (const struct tb_property_entry *)&block[content_offset]; nentries = content_len / (sizeof(*entries) / 4); - INIT_LIST_HEAD(&dir->properties); - for (i = 0; i < nentries; i++) { struct tb_property *property; -- 2.53.0