From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.176]) (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 F37CE2E228D for ; Wed, 15 Apr 2026 12:32:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776256353; cv=none; b=AjJ13+XQpEoCb9b+8V3iJYwM5CZcRyIfxaVZ1z0ctMzsP+Xce+NjtLlkQdI6p5NO+shycivZn6z7grjY3HeJyzDB81SnXbEVC5yX2ED4zh7s4Dba3jgokVDAxLiXwcBlnrrVLQxgz4W3VAuQo7qKfmWOTaduF7uYtdWHn5U9HC8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776256353; c=relaxed/simple; bh=yy8Ncc37XYKb193wi7SYVyUlnpHGTC4Pmm6nqvvfk7o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sSm+Wnmzw5qYrCYttHx7mD6mFO5A3rkPKUjcNlUVgy5OWoR6dYoqjcKRfyrjqfkdDxsdnSS9ixLK/SieEDsqNMbqnv/OEbfhAhHVe8yT/RVnQ9zUYVXGen3nnwDNb0TTeWP1pODIK1Mgwka9oPWqTuq4K2Q1Yy+DWsKZyc92T8c= 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=ozgPSYWH; arc=none smtp.client-ip=209.85.160.176 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="ozgPSYWH" Received: by mail-qt1-f176.google.com with SMTP id d75a77b69052e-506a747448dso52603321cf.0 for ; Wed, 15 Apr 2026 05:32:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776256350; x=1776861150; 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=snQIRoJJuRpCmh2yyUJKgsvwSWDhZnmvhy2vz0AOQb4=; b=ozgPSYWHjnMWbbuIXyxSvs9/ztHJDmRvnYgkVAX/ONc2aBicbgde6HX6ywfRPJY5fs w+NMbG9C1N80aQM5ZrQjCH26mFhOjke67RdjqRdGshuLWKnQdHlj2Xa0l7nZMJRUP6Rm UNe9S8qcWb1B8B/wwVkulvqXN8RXhO17fwVjKYdGO92oZIDXRzV9XQo69WKt250rMxaR e0bslEUa7tmzx2etmYF8UJS++n5NE06MH/f6NdzYfFvVlqCbksEgmOhP84zTlX83d0nb qEB6MtbYUI2nebMmx8YFkIETtcHOjPzuQvAA5ugI9jDdS3rH3PrAmy9ItDDqQ2Cv3V5M QDTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776256350; x=1776861150; 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=snQIRoJJuRpCmh2yyUJKgsvwSWDhZnmvhy2vz0AOQb4=; b=QP/QMZztyhJ/DXwrETeaQPp3W13wyuOVAuGlqsRsfRCR4/jztpdNATq0JCmfWZl3c5 4s9dNEv6GpknlxOAIHdlh7JyTwoyoYU+Tiw3PCOHH6mLhWNEqUqupIiiLQLz1wMMVwMC aWa/fUpQ9ikuwKAi3Sp6+7UXP1LTJwOHeM9Uk1/pMcpksZCcA9dIy/1sBepBwHkO+Jzp Jw4FXpY5rH9z7e3oVXkWpJ33lioBzwP0ApOk8HftnC8rkKmUz2fyCD4KpdbZ8wbe4txA Csa7GR5AXMX3/iweKfhVQSvspMYRnRICSgjZVzU0dXhfLhFQVG4y+fcN3Fukly3+qFjO vDKQ== X-Forwarded-Encrypted: i=1; AFNElJ/QSvJqy5C9CE/LL9FN160FnQj3bXdad6QoZZVd6bWSoo7RmI9tL6VEBBcwtpbJ10nX+M4PA/OitcOxe1c=@vger.kernel.org X-Gm-Message-State: AOJu0Yyk98bf4YOQWu689Y0w6MFYa/M3BeXKxliq9Gi3PMDj6T4wmMqK lVqnT0Xr4faRvzO//rvqHlcKWvdif08+qmnQBwLp0wr8ubEJDopZjHuA X-Gm-Gg: AeBDietBiMCmEgQN4F05IqDBhRbziAnVCYV07tRAFZE7G6WbI5mXaNgpdPFSWq5NWvW z5omK8vM4flYwq4D+o2o51jh8ih/ZMXtxjjE1xHhk1Kw9W1yZa2CFZB6zhzPv4rJE1axMUO+l9m /IlJdkiXhHHnGDEy9WFqgqbl47XPgAuzBu4ELiHVY1EmM+rI/Y3BLZZ9WX0PkDE+zDmdsBkfKDX PI0GJl36oRxhU7V6Tqig/t7gnCyX/Mh7VAtt3fGP0rh09+JFetG3b7G1l2yPBNzIA/FDHFz0NmE s43wQrjVQcCmUOoQL0D/D3jNsseujHWATSja2kj7jA3nUljZXpMN7wKMhIzYwL8ACGOphjT9CT4 uMEHt1u8qx0IUJAJ8sQCoKkdcuzHPTDBaJkV8wBzOtoD9iZgY+fLLZg45d/3+DxwAmvKlIFoQiD MKKM1XTXztYaTaiR+IAFUcjVVvbT6Vw7GGCnqRnEqpmAqwOUr52I3usOZsqogJUXbosxjga7/TA WmiPbAe04d/1xXZya7T4DhUkwgKqqSPAHX1tGM58NgMH2u4S5X8gM0mKJO5W8bc X-Received: by 2002:a05:622a:4811:b0:50d:6b06:a44e with SMTP id d75a77b69052e-50dd5ad8901mr325245731cf.17.1776256349793; Wed, 15 Apr 2026 05:32:29 -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-50e1af9dc5fsm11747771cf.16.2026.04.15.05.32.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2026 05:32:29 -0700 (PDT) From: Michael Bommarito To: linux-usb@vger.kernel.org, Mika Westerberg Cc: Andreas Noever , Yehezkel Bernat , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v2 3/4] thunderbolt: property: cap recursion depth in __tb_property_parse_dir() Date: Wed, 15 Apr 2026 08:32:19 -0400 Message-ID: <20260415123221.225149-4-michael.bommarito@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260415123221.225149-1-michael.bommarito@gmail.com> References: <20260415032335.2826412-1-michael.bommarito@gmail.com> <20260415045246.GR3552@black.igk.intel.com> <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 A DIRECTORY entry's value field is used as the dir_offset for a recursive call into __tb_property_parse_dir() with no depth counter. A crafted peer that chains DIRECTORY entries into a back-reference loop drives the parser until the kernel stack is exhausted and the guard page fires. Any untrusted XDomain peer (cable, dock, in-line inspector, adjacent host) that reaches the PROPERTIES_REQUEST control-plane exchange can trigger this without authentication. Thread a depth counter through tb_property_parse() and __tb_property_parse_dir(), and reject blocks that exceed TB_PROPERTY_MAX_DEPTH = 8. That is comfortably larger than any observed legitimate XDomain layout. Operators who do not need XDomain host-to-host discovery can disable the path entirely with thunderbolt.xdomain=0 on the kernel command line. Fixes: e69b6c02b4c3 ("thunderbolt: Add functions for parsing and creating XDomain property blocks") 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 | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/thunderbolt/property.c b/drivers/thunderbolt/property.c index 274b555d27c8..99ee7089456c 100644 --- a/drivers/thunderbolt/property.c +++ b/drivers/thunderbolt/property.c @@ -35,10 +35,11 @@ struct tb_property_dir_entry { }; #define TB_PROPERTY_ROOTDIR_MAGIC 0x55584401 +#define TB_PROPERTY_MAX_DEPTH 8 static struct tb_property_dir *__tb_property_parse_dir(const u32 *block, size_t block_len, unsigned int dir_offset, size_t dir_len, - bool is_root); + bool is_root, unsigned int depth); static inline void parse_dwdata(void *dst, const void *src, size_t dwords) { @@ -97,7 +98,8 @@ tb_property_alloc(const char *key, enum tb_property_type type) } static struct tb_property *tb_property_parse(const u32 *block, size_t block_len, - const struct tb_property_entry *entry) + const struct tb_property_entry *entry, + unsigned int depth) { char key[TB_PROPERTY_KEY_SIZE + 1]; struct tb_property *property; @@ -118,7 +120,7 @@ static struct tb_property *tb_property_parse(const u32 *block, size_t block_len, switch (property->type) { case TB_PROPERTY_TYPE_DIRECTORY: dir = __tb_property_parse_dir(block, block_len, entry->value, - entry->length, false); + entry->length, false, depth + 1); if (!dir) { kfree(property); return NULL; @@ -163,13 +165,17 @@ static struct tb_property *tb_property_parse(const u32 *block, size_t block_len, } static struct tb_property_dir *__tb_property_parse_dir(const u32 *block, - size_t block_len, unsigned int dir_offset, size_t dir_len, bool is_root) + size_t block_len, unsigned int dir_offset, size_t dir_len, bool is_root, + unsigned int depth) { const struct tb_property_entry *entries; size_t i, content_len, nentries; unsigned int content_offset; struct tb_property_dir *dir; + if (depth > TB_PROPERTY_MAX_DEPTH) + return NULL; + dir = kzalloc_obj(*dir); if (!dir) return NULL; @@ -199,7 +205,8 @@ static struct tb_property_dir *__tb_property_parse_dir(const u32 *block, for (i = 0; i < nentries; i++) { struct tb_property *property; - property = tb_property_parse(block, block_len, &entries[i]); + property = tb_property_parse(block, block_len, &entries[i], + depth); if (!property) { tb_property_free_dir(dir); return NULL; @@ -238,7 +245,7 @@ struct tb_property_dir *tb_property_parse_dir(const u32 *block, return NULL; return __tb_property_parse_dir(block, block_len, 0, rootdir->length, - true); + true, 0); } /** -- 2.53.0