From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (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 21CC938399B for ; Sat, 25 Jul 2026 15:55:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784994906; cv=none; b=kgyVWYjGE2A98ynR6VI4p4refJGD+HlD5ModjvGgbXMSCx3UtYCEA/KpYmm1ccKdnxQbJxSOtfNxahNXvuNq54mqvKy/US5TTkvrTGMndArMWIuagLfShm8FH3ijWWwgG3cuf+9ELw7y8VxMPtKZDjk95b1oV/ujv9cL3zAOlXU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784994906; c=relaxed/simple; bh=LXXx4iui5GP0CMusKZB3cA9kH6gnGvwfJ4aB0+wEQwE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Wv9o+yvsMy7CuaUfT87m31ZhQtdcDh/NT68fTtZmOYF5JWGKsqRjpmndVdkqL+mdhWf5kK+sZwSg+x4b/IdocvNTOn6GiYauWvGJyC6VmPxzlFvn2eNGS0AxyGfHjIQaq28xJyb5XtLuamUGF2MTc70XO8o4Heohsu5feep7YcY= 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=elxv7Zo2; arc=none smtp.client-ip=209.85.215.174 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="elxv7Zo2" Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-ca957432c7fso1032580a12.1 for ; Sat, 25 Jul 2026 08:55:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784994902; x=1785599702; 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:content-type; bh=0z39j0t7gIpxyd9ijxIwMptAYy4j9g07bnUO1cf++t8=; b=elxv7Zo2+uCIXqFYOyb7roISglbICWiNnqBVYDMm5WjQA3JBaIOxvzQpO+uPjfbj67 GjVryhZECqP8npk2PPDt2tab9UT/8oeGg7Dmiyww98DWNvzZnWynoYneqQsaobWbntg1 +Vg/7FYTEXZkqEWFtLQkOBWMGes6fz/qlyTJhSDSQht40Da/Fd7ULJLibe6bsNsCLuSC sKbcQgSkjK/vZi0oPs2RIUnT4VRfGvRAJWZtssYJ5LeZb1td4NzJWjxwS+wnM4mc+R1h Vmo6wKyaRpT7LYYXSJVUccH3DjBlVYF6Cxl4jS3Gf5yL3tWu2XQo5vrOYYmW8n+0GcuM QSIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784994902; x=1785599702; 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:content-type; bh=0z39j0t7gIpxyd9ijxIwMptAYy4j9g07bnUO1cf++t8=; b=oWBbYbP1j859MkXZLbZrYn01BKJdmgMKl2Y3a166c0ZobCCXWCkpkchgC1VkRZ6LKp 4Zf0C0b+qVyJ+RJ6t+nVizuUmHP08XCaL9oEvl8eS077GhS1UmVcyrS2xQ1cPbSPd1aS afP8sWhPMBtqVhbK5YjdWmXMYP5PsL68LFVVN4mHN7L3KjxQZ9HWG3MjPdLp9yRwWb4x KZgefT9/i6cbv3pPWT4wmZwdInnRUYLOlgvHZ57p8zFrjxnMNDh40ul4oPW/IlSgyAL2 p+Ox1DNZKlopxAW8TZGh3DH5cQ/51idG28Zp7f02sNzz6IkRxpC0UlpDAAwnS42pkQCk qSBg== X-Forwarded-Encrypted: i=1; AHgh+RrCI8a8XCsG+QEvFNtuzLsAF0fTB0OBSNdkVqNu+XjmU3HHPIV9qBGZtMdXvPimrNwtGV9h5ae0mLFeq5M=@vger.kernel.org X-Gm-Message-State: AOJu0YxYIyM5Zb7r/UFStcst+xNPp0NaVVDu/L0xqvnZXsb1FP0wLv3c fmVTEXCueszeE4X9JqN5MbOVbOLsFEqKyjuJ/J+l6YXAg7/smj6GV1wc X-Gm-Gg: AR+sD13sLj8uS9bNJGVVXLrzYNXCfocayu8L6uxohN7mKXPXJqvyPhyOQIbDOy5gg/O rasjGWQfUrhg+gVcTZi4lQSoYXbaJVrkWndhlpYT4r0JuZaM/K1tkTAH9HIfXGXhle2Mv4zyByb b6Jdy3BwvtbqQegJfiH3vYKRMXBKGEwHtMgVlwnZaM0bqT0MCn6PdHfZ+N5o9EF5QU0QGeISw4C HrIBePrULsyUjtoRlBrqUDqB9beiXWyvBgSWs7Oi/GHF/VTz4Ce5+qnh77hdHw+PBSaR1WO/87q hC79u1GzVlSLSMVV54IQDnmk37jfZFoNqLdsyCOAf+Gw1mKfZAu8fLOUIDH39Z9n4RrHccVF7eB Xj6fYpflfHMahwsgQGrmHAWGCdXzG3A/TLwVh1wYgOybQI/MWcTQ1OpisRWJuakIu3/hHHeUQqK GauXAD4L385GucfHzLeYh4H7oa6w== X-Received: by 2002:a05:6a21:9983:b0:3c3:9a32:70ac with SMTP id adf61e73a8af0-3c67e071badmr2563773637.48.1784994902054; Sat, 25 Jul 2026 08:55:02 -0700 (PDT) Received: from localhost.localdomain ([103.149.158.159]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-314bc549b11sm12630500eec.18.2026.07.25.08.54.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jul 2026 08:55:01 -0700 (PDT) From: Sreeraj S Kurup To: o-takashi@sakamocchi.jp Cc: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Sreeraj S Kurup Subject: [PATCH V3 v3 2/2] firewire: core: validate sub-block lengths in fw_core_add_descriptor() Date: Sat, 25 Jul 2026 15:52:55 +0000 Message-ID: <20260725155255.3054-3-sreekuttan2156239@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260725155255.3054-1-sreekuttan2156239@gmail.com> References: <20260725155255.3054-1-sreekuttan2156239@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 When traversing internal block structures of a descriptor in fw_core_add_descriptor(), each sub-block header specifies its own length in the upper 16 bits of its header quadlet. If a malformed or corrupted descriptor provides a sub-block length that exceeds the remaining total length of the descriptor buffer, the parsing loop advances past the allocated boundary of desc->data, leading to an out-of-bounds read access. Validate each sub-block's length against the remaining descriptor size before advancing the offset pointer to ensure loop bounds safety. Signed-off-by: Sreeraj S Kurup --- drivers/firewire/core-card.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c index eaec54ea287a..7b5d324aa7cc 100644 --- a/drivers/firewire/core-card.c +++ b/drivers/firewire/core-card.c @@ -173,9 +173,25 @@ int fw_core_add_descriptor(struct fw_descriptor *desc) return -EINVAL; i = 0; - while (i < desc->length) - i += (desc->data[i] >> 16) + 1; + /* + * Validate internal block structures within the descriptor. Each sub-block + * encodes its length in the top 16 bits of its header quadlet. + */ + while (i < desc->length) { + u16 block_len = desc->data[i] >> 16; + + /* + * Guard against corrupted descriptors where an individual block length + * claims to extend past the allocated end of desc->data, avoiding + * out-of-bounds reads. + */ + if (block_len >= desc->length - i) + return -EINVAL; + + i += block_len + 1; + } + /* The sum of sub-block lengths must match total descriptor length */ if (i != desc->length) return -EINVAL; -- 2.54.0