From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-vk1-f178.google.com (mail-vk1-f178.google.com [209.85.221.178]) (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 CB5D63E6DE7 for ; Thu, 2 Apr 2026 12:55:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775134533; cv=none; b=tvVM/ChLF97WJgdIrFuJvgmsUGFQ0UGH+l8gI9tZZssHGcBOtw67EYWt4erQGmtFZCllTb4RqZWNaJHfuNmctvRAo1n2aGuY7wuWr/wMChlv1xSg4gjBSBesiKY9DJBGCTvWFWbNODjVfplCwIXMcjFCqCadh5nW7FhsnEyqObA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775134533; c=relaxed/simple; bh=yCOF9NIHRG2RRR8gjB6MF/3vecVWbHAdrOgCPcYdB5Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MHImrm//LIuyHXyw/pupa+zfFGrd5xbLLKgl6HFl8/w3OChUScc9KK4EIW7k1+PVVd8JS2FiTE0hMU/Q6fIfhFaZMeyyoNYaAm2ScYQxye0vLAx7iFcFt55fenfzpYS2hpNij4xJjO7RAlnVP6ytCwLxvDtsn6YHq4IKAyYUzHk= 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=jFCzbwoI; arc=none smtp.client-ip=209.85.221.178 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="jFCzbwoI" Received: by mail-vk1-f178.google.com with SMTP id 71dfb90a1353d-56d85e76d73so706453e0c.2 for ; Thu, 02 Apr 2026 05:55:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775134524; x=1775739324; 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=0cnJhXHQf7uIWrznQwZx4iuuJLrGPih0M+p7FEUCw8E=; b=jFCzbwoIKcuZI6r45Usqc8kVWp9YwCjhbE+e5+SCVIyg2iyJDS7yD/tkgZmfCB6+Ni UXu/7tcaEXV6An1TB3BuXJDf5KdwePxu3VAO/sznRC+f7Kr76l86PbZI+b6fFw8RNnKF z2xhh+S/QOiXU6KSwFbzNAzNigxto9HJsbSXpyOGLVX91aXcdELfMqoMP2vVmJy5j2mk WkjDyOA7ZktqeRwl5bYa5hlymTjyA2sZkuFFd3Hpfhm3raGCBZL/wsb5cE6m14cM8WNh PtUa9RvVs4kkMfh1sP5pFfqCDQR2DGImU8hFOi5qr/fjuDxLCkIOCXpyKSAGSAPgD7xJ CEFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775134524; x=1775739324; 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=0cnJhXHQf7uIWrznQwZx4iuuJLrGPih0M+p7FEUCw8E=; b=qTmLRJOI8gxwEjRlObx4AzAUOZPNt1jYnkT0RCkFqMcZNuWK7Jhjbf6USWdHW9bxKr 8X583c2LIPHeUd2phGizB5uOdMGJfV61MPsSpJ8FqSiKdND5ewnZgiyVFBULNCLBK0DU 0cjXdEUNuNusMPRN/2bhA2ellN3YDQFTR2dYmar84OiGVNonR+oU4D2m1K2sTgpQ0xdf rpr8g+W/PDNZ7NBRsyM7cNInaAXEgj6mtcFnJcq8h3MNtF7j7uuRo55Et4O+zSs6cfZP 8Y5Q6KUq/xB0QIjsGGJuwjp5xdr9pIpL2eueZAlrBvdT+42tr2txLyPyRX6IndkwKGDW UYZg== X-Forwarded-Encrypted: i=1; AJvYcCUtXQbjG/Ap9cJ77mF3LJrooONrQ+HXrfJGP6SwMD0Hznpb5swYgYKTCwfJ+3oK1V2I8alsXCUlBiC7S6g=@vger.kernel.org X-Gm-Message-State: AOJu0YxNHzZfU3i+PI4AceCX3GaqcufN/0J6YxjRxJLGA/5WdqzezT99 +uyup5W6P4KuKrbthDnxvMiZ2xgZNzORvrSDZCNi5C3YxyFnUKieRRVX X-Gm-Gg: ATEYQzwezN5dRYaMy4lMG4JeHTwnKYV35eTlEi/KZY70so6D92FfoIw45tNRJwNVxvy b04ZID9jeUbpNBY51wsCg6SxpP0Fuyqu18mTXjTw5O5VzdPgdoM7A2sSoTR+SU+APv22MMGL0D/ vS0vXDz+kWgJ83FnWO6ZnpTVEhKolunm0+e0zyW/zQzBRrh2QbxYZMkRs2kMMm0KdBZPRjQGdww tPNCeYv+W11FRmvojeUilUXA3+/Cag01TNWwGcxT7bPA2/DsyspndR1GjF1JPeE9sWzdJlM3H+g HZR8/3MSHWrUA31wGmvedQ7t8yF5fNFnoijkkWzNMd40pdXZDUfeFSlyN+Y2T3rAc9Ek5MmLDuH ztrPe0/ijbNt/kiBz46WP7XvIikMfppMOUXLu9+5GwDuq23rYMFeGKS86Doa/DWlDTp2l7s90nw bZEmU49pD/izuYgBiVXJqSxEzURfbDPtCcaQ== X-Received: by 2002:a05:6122:698c:b0:55b:d85:5073 with SMTP id 71dfb90a1353d-56d8a834f8emr3573421e0c.4.1775134523627; Thu, 02 Apr 2026 05:55:23 -0700 (PDT) Received: from localhost.localdomain ([2a09:bac5:6d73:aa::11:178]) by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-953fba6af44sm3080950241.8.2026.04.02.05.55.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Apr 2026 05:55:23 -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 Subject: [PATCH 3/3] fpga: microchip-spi: add bounds checks in mpf_ops_parse_header() Date: Thu, 2 Apr 2026 06:54:46 -0600 Message-ID: <20260402125446.3776153-3-sebasjosue84@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260402125446.3776153-1-sebasjosue84@gmail.com> References: <20260402125446.3776153-1-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: 8bit 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. When header_size (u8 from file) is 0, the expression *(buf + header_size - 1) reads one byte before the buffer. 2. 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(). 3. 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 three cases: reject header_size of 0, validate offsets in the block lookup loop, and validate the component size read offset. Signed-off-by: Sebastian Alba Vives --- drivers/fpga/microchip-spi.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/fpga/microchip-spi.c b/drivers/fpga/microchip-spi.c index 6134cea..7954dd0 100644 --- a/drivers/fpga/microchip-spi.c +++ b/drivers/fpga/microchip-spi.c @@ -116,7 +116,7 @@ static int mpf_ops_parse_header(struct fpga_manager *mgr, } header_size = *(buf + MPF_HEADER_SIZE_OFFSET); - if (header_size > count) { + if (!header_size || header_size > count) { info->header_size = header_size; return -EAGAIN; } @@ -139,6 +139,10 @@ static int mpf_ops_parse_header(struct fpga_manager *mgr, bitstream_start = 0; while (blocks_num--) { + if (block_id_offset >= count || + block_start_offset + sizeof(u32) > count) + return -EINVAL; + block_id = *(buf + block_id_offset); block_start = get_unaligned_le32(buf + block_start_offset); @@ -183,6 +187,10 @@ static int mpf_ops_parse_header(struct fpga_manager *mgr, component_size_byte_off = (i * MPF_BITS_PER_COMPONENT_SIZE) % BITS_PER_BYTE; + if (components_size_start + component_size_byte_num + + sizeof(u32) > count) + return -EINVAL; + component_size = get_unaligned_le32(buf + components_size_start + component_size_byte_num); -- 2.43.0