From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) (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 422133CCFDC for ; Sun, 3 May 2026 14:15:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777817734; cv=none; b=b4eOzJRPZwXMDfgu3R61rUgo4sSWq+7Zt/rlPmLeFIgoKTK4hqgcBtwEE/pr5JhEEhn+073jIu73VMi0zXavrAmC5K9J97yUuEduth2GC2TeEUvOJ6UD2PC3/OYIGRUMoyX/mZfEp49s7PoFkcRUk9qhQ7vCdji/p25Q9S5DfhI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777817734; c=relaxed/simple; bh=DJX8ceKuZncvVsVqGihXF8M5N6EDLWVTekpwhupNHa4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KMHsGgXH2E+yWYWPJKz+GHWWbbuGlaRPONJfpGZU9iCuF6dbPsq+r3kj/Ex2f+bsxJ2ANnWqt6Auqya1vkq21JhoBG2C7vLEddg2WL+oTCWJ8vIsm0ilxRNsoD7U8T1oPAER10N1o7VepQZyMNY5G4Ie2a2g+H7g/gzLAO22kAU= 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=RqUGr8//; arc=none smtp.client-ip=209.85.222.177 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="RqUGr8//" Received: by mail-qk1-f177.google.com with SMTP id af79cd13be357-8d7e7f48499so353176985a.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=4Dz71hQc8J8ElMRCoaWUAkz9HmQbH5aLVTYzizz+yMo=; b=RqUGr8//Wj3a9VELBdVmZpLUQflfTvDuQezU/yypkbdrse5QeNfQPDiNB0BSQJWRO+ 3AA0gYif/+bNPJy5y5VZPzJIdZzFTa5fSBBGrBxdA1J55Na70KCbAvCfsh/vaCPUAzh+ 9FhejfY1F32Fgq/iHABQwQTavdFF3l1TGvfWXXwVM7kH7WmVBw5c1etNdAESeYexziac h7YgUFafO2F8l0ditWikIYk5cZnAmpPH7UPyrP712Eucq2fBphytFaNJxmsTfI41WJOd I7wmFn5gFBSa1ZMXPztNI9RvKNxX00zMTLA0VbtBTRMmmhC7skymgBSvxeoGSs2xwBzr +2rA== 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=4Dz71hQc8J8ElMRCoaWUAkz9HmQbH5aLVTYzizz+yMo=; b=JnSqF9MPTxNIRIeBrXGg2LvFb9dg+AnJcSWX0tGCJRLTJCgrAigzj1IrxEZIc7YDJE 612AePLKRCkXuASxAkmNfTQAyfVb5Iz55ZLisUHu59tybMv3eI2LokU2LGdkI7fcNnz+ dn9USmRqKY2SrRkm/OZS4ygbOw2MTq8Cg1PlwB4V3647um+uGhFIjXzTJ6HYXf2w+RGR dE4VTKVo1LwEsAT1i4YA0uhJAdPdJFwTvXvY0yR9PFlojmtTGckTTq1wyvuK+GGxmCZ0 e2D+eH29HKQFAvJ/NuKgZryxpNdpbBtweWtSxlFQA3oIcrvwhrt/SpKrSX8yBS1kC78H Mbww== X-Forwarded-Encrypted: i=1; AFNElJ8X5FPMFZzHtsr/K04VFEu3Q9jrsmQXGCfMwlRJuH+Z2Xv2lkQj4ktohOPavgFwB23rvfKoNZlTHpQgUDE=@vger.kernel.org X-Gm-Message-State: AOJu0YzUxeyDTasod5LCjXxRPd53BO0JHFVKFe/pSypXunpW50Pl1dTJ B8U5Egb6a09PqlenErkaMU3kJrNDvrNQkRFpZzR+4OQgoMB6LwUX9rB/ X-Gm-Gg: AeBDieuDdaXQlWwn4a/EnolmJISq+HpyIuQgBT3XpOJRIsEwRtiVQa5UniYx1CgpTKS /q39nIIRNOUdar1Rn5uBwjwOWBN6w+sBIAi14mlmT2JP8kKxIoEvbiRaQYB9OZE1LFCPbq1Y1Dc D+zd8Yl8ahpLxyyIU2oT5qi7IImgKwyH93021N33rgkb0EakG4mNa1VIh3bxapOhNc9jAJzaktV zsDgBFTgee92rzadirmvKG/j6vxrd5R4uekiqGIeo6CiEb98aAVKbhLaZoFlmhebuuHaKdq4cfC 1szy0l3H/hPivxKKq3GZ6ImeZI8zTGWfwYMSd++5uf4BmfMtLEZknRxXzLgNzrj9GxgKDiLOaJK S6cPKWlouLdJ68hXtaEvIlsGN538ESWE3HH0bScTGw257a3Rs5XAepTY31hMIcp9rsi2nwBkdRD DeWGLGn7TODE/QRIWokPH3e+c+pwjexdbHsN7NpjWf7WkWbg0Vt/YLIafG67faDAjKCtaCxYj5s y4GXvcDKEG3UXCM X-Received: by 2002:a05:620a:4613:b0:8da:cfe6:c67c with SMTP id af79cd13be357-8fd17c4f15fmr981271585a.28.1777817732086; Sun, 03 May 2026 07:15:32 -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.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 May 2026 07:15:30 -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 3/4] thunderbolt: property: cap recursion depth in __tb_property_parse_dir() Date: Sun, 3 May 2026 10:15:07 -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 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: 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: - Fix Fixes: SHA (was e69b6c02b4c3; correct is cdae7c07e3e3). 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 90fa6f760963..8db56922011b 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