From nobody Fri Jul 24 21:53:03 2026 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 77F90421220 for ; Fri, 24 Jul 2026 10:14:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784888090; cv=none; b=D2B+bwQpm3rPwaZK+kppoV319icXyZIh/J82MJMQ4IX5SsjKrgNHVrTS+nVgmdcn+Bx8Yob9vaCnu4ZYSKmOHATs6Y02T4moc6Ym8mm4R753ymHAKQSTZ4136kXW8+HHrfJOQkw5F+LIO51lzta8PFygk0Oxz1uFURv0aSBRPrQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784888090; c=relaxed/simple; bh=7A3EsD3+Md/Csc9j5ZXhLERaGgdJMzYaTzgo5cVpJAo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=AmFFqcqX/D6lKl3Ja//3qzCGApkLAaJt70XS4gpWBn7yKu1bCXauQxdvi32fQ2LYIst/L+qot7n/yLlftF+1PCu3SWP2h3/HLXONBq9ecfcFVdgQzcvssxUFoMma6lbTh9yDW0yMys6vMN9E8YZzBETyqLGxYLdCeRgVcUvxa58= 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=CMweBOOj; arc=none smtp.client-ip=209.85.214.170 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="CMweBOOj" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-2cedda2ce6fso2237225ad.1 for ; Fri, 24 Jul 2026 03:14:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784888089; x=1785492889; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=kGOd+K18EKh7Hyj0j7KP1RHy8Vb51HuPeqWLoBOkqu0=; b=CMweBOOj0vvY4xgGey3s8M94G7DAOwxB9w5mDKQs8dPYgrPdRssN7inm8gobLCGigt bCuutDubOP3y5Y3xmgf8mzhXhi3iy6KTBeU9XtrfjXmhyLkO0olfczfhI+GfjsdbySIu EAmMdo/hWcJcgK3W1d9vjsvb68+g/UJ+hTSOZEhCKp5unUQ0lV7uNIGMPUxPCCYJD/hX WDQlwEgFWgY84X1T0bdZDZxlUFNBVpn8CfWmoxdhQ5aZWaQzYDOX+xOcokkTUhMCRbD3 jiLDCFRw/KWwVkWcfCYnLAevH+cTyVkK7/vedYornf7ee5Q9TfIgKC+HcPn283YJX6zg FG+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784888089; x=1785492889; h=content-transfer-encoding:mime-version: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=kGOd+K18EKh7Hyj0j7KP1RHy8Vb51HuPeqWLoBOkqu0=; b=hLcaHNNh2gLp+3XnxvF5LWgOZSy5hlSPwz5Tn4zJZuG4tttROVTBv0Ut346m8rMDca j2V/5RVCwM3Z+YCALD6ad+YHh1TYD2geQ3JejxwUS04fUOlRg767LeEVy0jNr5Vihntk BJkz0wPDIZkPa9uTftWElOax47lp9cSuytXxxYaD2/0S0zctnUUibeetYO4g/UDeWJgc nJQJfNdCVOTA78WLXyayE5jXpHFIAhPMieAZuk7pa8eWpoDKazUp2QEoS3zaCPSomobD qwGxG1yZX8pNGEMLFJvDb6FUWMvo4qQmeFAZ2F/nQ/ZUgEL5GR5RQopKRL3MPdpNZFSv aZ3w== X-Forwarded-Encrypted: i=1; AHgh+Rp7jHSh6sdN0+bLZmfj9mBUTD5FL6ZlLbOFG5r5ERG1U/NZU6O1dbXoV9vsx5JV7G+QSim+MdDDH35mRDE=@vger.kernel.org X-Gm-Message-State: AOJu0Yx5djre6k7FbAjAK7FIo0khzkHJND5c/fjpBhp+v4Os6vlByQY3 L1+AhTT58Wl8QefgG76TO0Ky4C9IgmqCpcv0j+NwA9zmYS1FGOKwC5kT X-Gm-Gg: AR+sD12mMcXIFt3hFSoAUEf5MhaBBFh79k2kpGJW/AxCYhBlyZnaUUHWWgsyRZ+Lrtw hBmmjjdZd1AOo+quL7yToo8VEqTlyY89NsnlrnfDVhIsMUC2VALOqlvHFTsvYHDavSwGkNPC/fO X6rAyYOK9EYQ+CIqgQ9ZfxztsY2kTXTxHQXCJEmjz3y2OMritpD/bZRXwhCrU1OtoII226CFKcS v0rADAQ4cN0h4p87QRkIjWny4M7OYBgD1c2zBdRwh+lyd34ioraPjZWEtxR92N/RVA/8eUmxK2s TreFSD03aiCc5ChGvjOKG1+BP04ajXd30tshqd/jRQLZUP7AOYzrsKdJopt5PFaIvyQIjX0UNGW N26Xjya1DXKlAYoifbUHMq/ggjZ1t9CGwjGiY8Ie9OuHMS2bfeDaMlBbe3YJEESnbx8BZDsdXr8 0uhna412kU+WylJIed3yIw5c9AJA== X-Received: by 2002:a17:902:ce84:b0:2ca:ed41:d337 with SMTP id d9443c01a7336-2cfa6f7fbfbmr77662495ad.43.1784888088457; Fri, 24 Jul 2026 03:14:48 -0700 (PDT) Received: from localhost.localdomain ([103.177.252.241]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3147dc9d932sm28542614eec.12.2026.07.24.03.14.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jul 2026 03:14:47 -0700 (PDT) From: Sreeraj S Kurup To: Takashi Sakamoto Cc: linux1394-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Sreeraj S Kurup Subject: [PATCH v2] firewire: core: validate descriptor bounds in fw_core_add_descriptor() Date: Fri, 24 Jul 2026 10:14:06 +0000 Message-ID: <20260724101406.18673-1-sreekuttan2156239@gmail.com> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In fw_core_add_descriptor(), incoming descriptor data is processed without prior bounds verification of individual sub-block headers. A malformed or corrupted descriptor containing an oversized block length field can cause the parsing loop to read past the end of the desc->data buffer, leading to an out-of-bounds memory access. Add validation logic at the start of fw_core_add_descriptor() to: 1. Reject empty descriptors (length =3D=3D 0) or descriptors exceeding the maximum configuration ROM size (256 quadlets). 2. Validate each sub-block header's embedded length against the remaining descriptor length before advancing the loop pointer. 3. Ensure the inner loop explicitly increments by (block_len + 1) quadlets to prevent hangs or buffer overflows. Signed-off-by: Sreeraj S Kurup --- v2: - Fixed tab indentation to 8-space tabs per kernel coding style. - Added explicit loop increment (i +=3D block_len + 1) to prevent kernel h= angs. - Isolated changes strictly to drivers/firewire/core-card.c. - Added descriptor bounds validation in fw_core_add_descriptor(). drivers/firewire/core-card.c | 57 +++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c index 97439da6f480..cb8ce491fe9d 100644 --- a/drivers/firewire/core-card.c +++ b/drivers/firewire/core-card.c @@ -169,36 +169,47 @@ static size_t required_space(struct fw_descriptor *de= sc) =20 int fw_core_add_descriptor(struct fw_descriptor *desc) { - size_t i; + size_t i; =20 - /* Extra validation: reject empty or oversized descriptors */ - if (desc->length =3D=3D 0 || desc->length > 256) - return -EINVAL; + /* Reject empty or oversized descriptors early */ + if (desc->length =3D=3D 0 || desc->length > 256) + return -EINVAL; + i =3D 0; + /* + * Validate internal block structures within the descriptor. Each sub-blo= ck + * encodes its length in the top 16 bits of its header quadlet. + */ + while (i < desc->length) { + u16 block_len =3D 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 >=3D desc->length - i) + return -EINVAL; =20 - /* - * Check descriptor is valid, the length of all blocks in the - * descriptor has to add up to exactly the length of the block. - */ - i =3D 0; - while (i < desc->length) - i +=3D (desc->data[i] >> 16) + 1; + i +=3D block_len + 1; + } =20 - if (i !=3D desc->length) - return -EINVAL; + /* The sum of sub-block lengths must match total descriptor length */ + if (i !=3D desc->length) + return -EINVAL; =20 - guard(mutex)(&card_mutex); + guard(mutex)(&card_mutex); =20 - if (config_rom_length + required_space(desc) > 256) - return -EBUSY; + if (config_rom_length + required_space(desc) > 256) + return -EBUSY; =20 - list_add_tail(&desc->link, &descriptor_list); - config_rom_length +=3D required_space(desc); - descriptor_count++; - if (desc->immediate > 0) - descriptor_count++; - update_config_roms(); + list_add_tail(&desc->link, &descriptor_list); + config_rom_length +=3D required_space(desc); + descriptor_count++; + if (desc->immediate > 0) + descriptor_count++; + update_config_roms(); =20 - return 0; + return 0; } EXPORT_SYMBOL(fw_core_add_descriptor); =20 --=20 2.54.0