From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) (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 560563A5E64 for ; Sun, 10 May 2026 23:17:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778455040; cv=none; b=DdtxO+tG7mturNfnCJWckcXx/mGV24ajjlVCdjytLSYmazIq/Zc5104kcyInMWKHxYk8n2BR77VzG197r+vGoE2QWEiaOQ/F5Fqvzkl9/HyfyXy671TUhKpIEGZoiOy5oXX96noD6RT2Zerx7uAusvvEHpZarAxT2gbPK3k9qGA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778455040; c=relaxed/simple; bh=dF5X1LUG4r0lQCtZsSoClebMfzIDwW0CmxgsuMikSXg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WxtW/pTqPCruonUiQk9agZACDHVg36Ilp8AFJAqcQCsldzGo3xPLrrZLbGc5Im/ncaAEV0QpbVv6gQTYf0nr53xNgogQBIocim/B1+bPSuagrg76cPvV598bCYt79vLCyQxD58b1u5r36Bf2uGLALOqOLRROkJvJOlrcLEffY8k= 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=MpJmxHLT; arc=none smtp.client-ip=209.85.160.171 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="MpJmxHLT" Received: by mail-qt1-f171.google.com with SMTP id d75a77b69052e-50d7c12e48eso33511221cf.1 for ; Sun, 10 May 2026 16:17:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778455038; x=1779059838; 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=494zAqIk8zsiLJlcWBVQHIjNxVWqGVKEvJi7UcMRGg8=; b=MpJmxHLT/RYdk48gXTuE2zW7wR2N4qIz+GMK+X5jFZ6b942obo319ubHmJDOl1tKOG Ms+ZYR09foP3qTzXn1IrTTqdtzY6m726rPLD1C/uNkTlm7QrLaLls61b23aUviRRFV3P HWIY+bjLiHwv1ASy6C1tVWHP18vHAlgDhZHyuLKiZht33vrQZl+i5jQG5skFGiQm0P9w kPxPINAXBHVtTOADgXgNbvrWSg4Fs1m6j7DPkvz0W5QLFpXshjBvMbixugbfPD8uimao nReRlHz1kjd5NWrmfxqhRTJ2qzK+/4RGJcndJi/WEHv6zfOcWQ2SfApvgXTUqPMIS25D MSPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778455038; x=1779059838; 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=494zAqIk8zsiLJlcWBVQHIjNxVWqGVKEvJi7UcMRGg8=; b=cHBq8ju/zFxRSYDd5ASLvR7y9CGKn6lrqal/7Ei1uHw7s4vYfstxSHi5H0lYUj6CNV XnqfwU5KRsSIfyE0JR/qfcl5iBI9ZcCTiuYamoS4t1aJsQDGOVJbyhkXwYVclS1zyqVK jPfrHIjiQp+vUs4vBz35Wk2nGLe9iQRLaQJmu4oP30GtcT9bSs5SO12UjkBb90GrsCUn kYUtyvami7SWTbKvdYDVGjKqE73ojprpLlVhISKC8RAAVLtZjFPJt9hF8nIACs5tbQ2r gWHYMqThGQ0GjKNKNnOW/JwnmA3Z+k2t57lt2jgO0kG4YdJswnc0Hvg7awERogvLfHKr bH0w== X-Forwarded-Encrypted: i=1; AFNElJ+Fnj1y48nwol7p0bpf4NJnBRwOw5tQyNylCJXzqgcuW9htZfu9iAVm0Bt2gGt57l/+w2ujer9e2R7oq8Y=@vger.kernel.org X-Gm-Message-State: AOJu0YxJY+EGIWY5VuabLisHlOBi+wE1sMNAOmiwktpGIZj8T2dJXBs4 ya8tLvE+tWxosiaNNjNoJzhZKuxLRY4cZnuEZoNgl+LOtzoFppBBLY9R X-Gm-Gg: Acq92OE3qLDUGknWS2OemU9fABIdaADaAl/RVhmb4OvFalB97q2Bqp1KTFZKgH24SoN 12UTxiJIPbMqFgOVaSqiHOdKykAB+WvRPYd/Y5Zx1mE+U5KKFmVFwESIKm4k7DvvQ46k/BJM5IA 0Ryfotl56wCfhoJWWeNQdc8p1rh1xdUam5nnMUKTPyfvKXPx1ee4L9i9BNCXcT3C4EHKCBhhwJC QMr0qn8YExrq+aCICWceHlknVB1x05fwRXkJRVpSiYOH/0Kn48EBVn2vB6pcxfHv0DdMWiexy0K z80/92r/Fzw7xxxosHDxKOcKjTt5PamyR4LhArMEGi2iQnam9eqBAdWI5DBXlj2hUWoIP5wOll5 njP/qK9imtA0B1IbZn6mps11gxVR0lL69eA79ZRJ7KIISP4JkZ+uST4BMjK/NzAT2D1QNr73tsU xJPG80vGnvXBgGVVp8jXOo4IQEFzwSDpr9xZZgwHgrk3tt1fnw2LTYaxg3PlgN7FBqvDUTmv1O4 75IbuM+dWbEJGAFO/XhGl91WLGV3TXWK2LFllqz50BmyjDKUhzfPA== X-Received: by 2002:a05:622a:2b48:b0:510:4174:507d with SMTP id d75a77b69052e-51475c8cdd4mr207655871cf.29.1778455038269; Sun, 10 May 2026 16:17:18 -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 d75a77b69052e-5148e830ddfsm75015031cf.27.2026.05.10.16.17.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 May 2026 16:17:17 -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 v4 2/4] thunderbolt: property: reject dir_len < 4 to prevent size_t underflow Date: Sun, 10 May 2026 19:16:57 -0400 Message-ID: <20260510231715.2215605-2-michael.bommarito@gmail.com> 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 --- drivers/thunderbolt/property.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/thunderbolt/property.c b/drivers/thunderbolt/property.c index 29cd60c11ac4..74c92f9801ff 100644 --- a/drivers/thunderbolt/property.c +++ b/drivers/thunderbolt/property.c @@ -174,10 +174,16 @@ static struct tb_property_dir *__tb_property_parse_dir(const u32 *block, 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 +197,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