From nobody Sun Jun 14 11:25:57 2026 Received: from mail-vs1-f46.google.com (mail-vs1-f46.google.com [209.85.217.46]) (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 CB5C12D9ECB for ; Thu, 2 Apr 2026 15:38:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.217.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775144294; cv=none; b=keGtBhNLcOUtwzo05mfnrfMXeh2xlwfFIITf6JoQ4NfiSIe8PlvM98yyObwkSfVbyQ7ZIb8V/fZuEh+daqeLgp8miwta2f99XlucFOvxaNN3gEx9mdiZGy43x8fpmSUsxwtDnwfz13wcNB76fgp7kbTcYkpqLzh8Rs6eSc0upl8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775144294; c=relaxed/simple; bh=AUcfU7ozLC1fJxQaa8e9OfGKpGskpsFLA2RJUD+6vuQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=egVcT0OwnJLPZGtkJDNNKxRNP5iDKhp+AZ55oNW9rl1f5cZFQ5AftH0aiHkVkTVNebqqgAyywYpsWMsNFcYvq7KvFNEYM4C13kAfpAjpL2vIRlPEOjl3+NjdYCoMhukYfO1KJG1QuQiHKFuVCgOuJ8LKkGPVHi0ar+bvOaqwR3s= 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=pMiyVePK; arc=none smtp.client-ip=209.85.217.46 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="pMiyVePK" Received: by mail-vs1-f46.google.com with SMTP id ada2fe7eead31-60580b17793so302511137.1 for ; Thu, 02 Apr 2026 08:38:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775144292; x=1775749092; 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=vwEOZMEaU0+lFHsy/ODF1F7HIytWIXRTEWV+IDHWPtY=; b=pMiyVePKlHzqWtBzxIZbOEbTL5/8ew2aubm/vS52ZhvHAhvR+1Y8dc71j45jtstHOl 0RiF+wvkqDHI/ItGlBmqlUp+8Z+42TlpFW90fIRLX8BLhdkZfybsLzmSQ0QlAYIWcebO 8VAybTUy1aZDsaR3D5TLinC4uf+JdJVwXj0Ew4v368HJjnC9toqScG/UI7F5Ukvmh5Eo j7P/TrQR7J3aSnWZI4FiMQde15gvG+VEQ9JZynnH22hQXcx50KkIW2D06FSu9DtcAAFm m+R7Ez9SWdAyva4Od/vg0ro8vqpJSghSukf5tRsBmtSIIIB5/8aiY/Xzkv78lqeiDmWY emsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775144292; x=1775749092; 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=vwEOZMEaU0+lFHsy/ODF1F7HIytWIXRTEWV+IDHWPtY=; b=gR6BXmT5hlhbWVr5OsfEvx5RpCeI6xpKjOfOM6TaGLsg5fDSpoA63ISZ5VapBCeo/N Q7g2zTUKaf8ABdUQsj8zKw46eZqhE+Hy2I173Bxn9+3Aao/k9cmL8ap1zwT1czY3x2d2 KQNfbMrips0Frv7JHSLGweqaTX83MxoupBoqYztvXc2/S2NOfO6ABqN/I3NwLbE0p9v3 H9jZ/Q39pNQJ41QDsx0ucf6ETINZ5VFLD+O0pk9FfIwZoufXIC78CgfbS3hbSJcAIwv9 /3QDOER66fQ3lJ3MUvcEAyzcPXtt1HhcwQnSPomqv+I8NIyvgBI52choudL+hg841Ir9 FCcw== X-Forwarded-Encrypted: i=1; AJvYcCUjbMd7qux1ufKEIu5J+dymF33YIHgmE7JcPf0PXdENk98jVuPnLMnvWuyImWFWEMgyQQC2udzo80C67vE=@vger.kernel.org X-Gm-Message-State: AOJu0Yz9GKbDdUERqj2JxmzWwusz8dLAjqC2Y/LL9xWrhMLQ0yYpxdqV Rvq/89Y8vCh+qTqIrMi5nSMlEJIE1gJ+pNIf/JLp1TPo3bVja82FSvtm X-Gm-Gg: ATEYQzxT8p/OYhovzgxO2uCw1QVTX6BJN/VF7kSnq0WjugbzwdiTXTQMA0dpIxzd+aJ SmtMzclYJzp5JgQ3n/7VrGiwo1mR5DL9ciiJichVeAo6JtvQAs75MsUeGCW1mbjALqHv6fknOX0 nhONXn4fsnyOR47DTnh9oEZcTGAFSvaAg1+1rQd8A44KD8dFixh0FR+zT4nVBDigCPZuCFpDThF iM6qMmtBraZsmioUruQD4P4ESzTEI3JAU5faEbcWcfK16bEObPhIAX3xihtU0JRCtrUhpaSaD4U f9qZ04Ve6WaKK5OT3djCQEDCkw3IVJysMkPMy+bhdHWl4egJb+Tee/cqO+5pmXMVnSPVGgv+vpv DP8gTljg4DPh74pmfSNGFbX0tzy8Yg63AWxN8Rw2K3CaOkH73JeUad8nNvPwRDdOjJAXivIPeR5 8eUESoCt09gQLeH3ceqxOVxnvA X-Received: by 2002:a05:6102:4492:b0:5ff:f366:dbe1 with SMTP id ada2fe7eead31-60567e7ef70mr3209136137.15.1775144291611; Thu, 02 Apr 2026 08:38:11 -0700 (PDT) Received: from localhost.localdomain ([2a09:bac5:6d72:aa::11:17b]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-60582e1d1edsm4103633137.1.2026.04.02.08.38.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Apr 2026 08:38:10 -0700 (PDT) From: Sebastian Alba Vives To: linux-fpga@vger.kernel.org Cc: yilun.xu@linux.intel.com, conor.dooley@microchip.com, mdf@kernel.org, linux-kernel@vger.kernel.org, Sebastian Josue Alba Vives , stable@vger.kernel.org Subject: [PATCH v2] fpga: microchip-spi: add bounds checks in mpf_ops_parse_header() Date: Thu, 2 Apr 2026 09:37:52 -0600 Message-ID: <20260402153752.3793055-1-sebasjosue84@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260402125446.3776153-3-sebasjosue84@gmail.com> References: <20260402125446.3776153-3-sebasjosue84@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: quoted-printable Content-Type: text/plain; charset="utf-8" From: Sebastian Josue Alba Vives mpf_ops_parse_header() reads several fields from the bitstream file and uses them as offsets and sizes without validating them against the buffer size, leading to multiple out-of-bounds read vulnerabilities: 1. There is no check that count is large enough to read header_size at MPF_HEADER_SIZE_OFFSET (24). Add a minimum count check. 2. When header_size (u8 from file) is 0, the expression *(buf + header_size - 1) reads one byte before the buffer. Return -EINVAL since retrying with a larger buffer cannot fix a zero header_size. 3. In the block lookup loop, block_id_offset and block_start_offset advance by MPF_LOOKUP_TABLE_RECORD_SIZE (9) each iteration with blocks_num (u8) controlling the count. With a small buffer, these offsets exceed count, causing OOB reads via get_unaligned_le32(). Return -EAGAIN since a larger buffer may resolve the issue. 4. components_size_start (from file) and component_size_byte_num (derived from components_num, u16 from file) are used as offsets into buf without validation, allowing arbitrary OOB reads. Add bounds checks for all four cases. Fixes: 5f8d4a9008307 ("fpga: microchip-spi: add Microchip MPF FPGA manager") Cc: stable@vger.kernel.org Signed-off-by: Sebastian Alba Vives --- drivers/fpga/microchip-spi.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/fpga/microchip-spi.c b/drivers/fpga/microchip-spi.c index 6134cea..00fa2d6 100644 --- a/drivers/fpga/microchip-spi.c +++ b/drivers/fpga/microchip-spi.c @@ -115,7 +115,13 @@ static int mpf_ops_parse_header(struct fpga_manager *m= gr, return -EINVAL; } =20 + if (count < MPF_HEADER_SIZE_OFFSET + 1) + return -EINVAL; + header_size =3D *(buf + MPF_HEADER_SIZE_OFFSET); + if (!header_size) + return -EINVAL; + if (header_size > count) { info->header_size =3D header_size; return -EAGAIN; @@ -139,6 +145,10 @@ static int mpf_ops_parse_header(struct fpga_manager *m= gr, bitstream_start =3D 0; =20 while (blocks_num--) { + if (block_id_offset >=3D count || + block_start_offset + sizeof(u32) > count) + return -EAGAIN; + block_id =3D *(buf + block_id_offset); block_start =3D get_unaligned_le32(buf + block_start_offset); =20 @@ -183,6 +193,10 @@ static int mpf_ops_parse_header(struct fpga_manager *m= gr, component_size_byte_off =3D (i * MPF_BITS_PER_COMPONENT_SIZE) % BITS_PER_BYTE; =20 + if (components_size_start + component_size_byte_num + + sizeof(u32) > count) + return -EINVAL; + component_size =3D get_unaligned_le32(buf + components_size_start + component_size_byte_num); --=20 2.43.0