From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ua1-f46.google.com (mail-ua1-f46.google.com [209.85.222.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 BF3E23B9DA7 for ; Tue, 7 Apr 2026 14:06:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775570793; cv=none; b=N0UQ+O1sCB7rhcPkfK8gw9YqlKp3ObbsSx816fWQ6Z2JaOs9Tc8so2u5h713/coPCiujpSisym8Y2AGBCqK40+M0akquCFq2hT6V2xJRY4R0cjO9sFJeGzRwVx3JiIVkh6a5hqc4+U4JUW1lInsw7eDJGk9M/seCcHFKNtxzLyk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775570793; c=relaxed/simple; bh=yCOF9NIHRG2RRR8gjB6MF/3vecVWbHAdrOgCPcYdB5Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dmhqx5zD5V9bo92rsArOEWDQIdcsYompCzjt/Huw8p8ehool/p55E/cfdVNHIWirl2BwgGpToDIs1O9dm8J6dNo1IOWusZRX01pQYZKG92Veiw+m3C3y2Q2J1f3pFLxRs8Dl9Nu4ely9MFkSJmiQZNUW0ziIpoKgs5CzvKBx79E= 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=igQj9Qx+; arc=none smtp.client-ip=209.85.222.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="igQj9Qx+" Received: by mail-ua1-f46.google.com with SMTP id a1e0cc1a2514c-94b07fddecbso2775024241.1 for ; Tue, 07 Apr 2026 07:06:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775570791; x=1776175591; 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=igQj9Qx+ojHyahMVQXEdXHFBUM5E05YGbzmwmuXJLtmjDeeBMkhqCABl+Qn4xPxpNY wLchJ2Jkj3dKrYG4tCfRV8SrKurBjGywFPfsBfc2rvF/nLfug+kvx8kMnJJ3pj6fqsED 0iu8eEAb8q9mI35y1nL7efJx15IiiQRDhiCOgrXWq6Uyfhzo5+xYigcgyU63iUI+JiL9 dTq8ezmuA9Xk5uL3IkK5a1mjBdkY0m819QZyRvv+55NsXbgEba9cTwfi0UgcxMN9rWmv 6P9GqntKv6UvRPWSaVR4LQvKjmk4rMw7c/vik3xy4Vu8htUUdEERXS48kVhTzjq7bqOD +lpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775570791; x=1776175591; 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=LSgLXf8LddDff0rhRyM2YEX1/cszTdtBggvevgUKQaz2jrHlJ17essnDvD5ehDwxD0 TwMzv/nR76HEGcyYwI86+MhtrCynMFtALZO20Qj3r5Vx8M4ceKa5iMZVtvPq5MM7m18O JdQGysGTvvzzmXr+a0D/DNi6Nutu6GVkhTw56hO2UOKA3foRfqNPrfirttNWa1+dW5Nw 8P+aAy1cJSYZMkIqMOr5UsFyVg19agQ//ucgK1i8qrirj/Jg1PA/cMdtwAEa/xIs/jyz AaNRBWWTAZYCyphQZeVNTyzEFO2VkGZlJxqIttkKEl5/1LwdslAdPmsJnkOF/K5uK98p jLuA== X-Forwarded-Encrypted: i=1; AJvYcCUDl6ii1EWy4TK59qkmNgv3XQ3Fp7lDF7B5JUekYPBu7mVr0cA3m0GZwGv60kh9Tu594Z6ngHE4KhCx+bs=@vger.kernel.org X-Gm-Message-State: AOJu0Yy/MQ2DSGLhNHYEIFVXDLXO9Zq9p23ZEpdEVO8F4mYcE6UCcsUm mp8vdaELu5IUpVKvhbhgDExtmOQmRBLVHOiDsZ2CA48alfJwkLBjCQ0Bnsfskb0HjaE= X-Gm-Gg: AeBDieu+xHBhahJ2xFC1JH/uCd1+ChZUncqzhHwr5LiLjf6kZuFtR9F7IHRBmG1zwkl jhWygDdavIU+G7z+f5VgFhugloiDIV5TrYPZilEU0aarfwrIM6HqK9VOKOfz9K0kVgeCq5Fd6/o aWVwvr8Q0Veobec8FS7YAxwoYpgY3MSTl90OAUvGtIIdw0evFa1fqy7P7XLc2X5Wc2Ft0wprnp9 Eu/QFgXYbUkqMqJGEctGhYdw0iivscnrG+W+68dnwykeTfBIZBx1mCifwQ/omSDd2R09nIzGpZU GMAf6HHCWMxke8z86hsSJywrrPad2kbLKPQdbil9KYDSx8qgbS3BicBpquwPu4+h1fyPBaf2WHt uwUPZjw0iCVW5vLIodyA1bpe1aYoyqNSiN6TUB/qb04EVE22ALNIfr9vvkTNIj2oVhbY03k3hOX a+GiVKQRgZTjT3a+MSceMykI0= X-Received: by 2002:a05:6102:e0a:b0:605:218d:ae0f with SMTP id ada2fe7eead31-605a5050bf8mr6961394137.18.1775570790454; Tue, 07 Apr 2026 07:06:30 -0700 (PDT) Received: from localhost.localdomain ([2a09:bac5:6d73:aa::11:1b5]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-6058304a726sm19814641137.9.2026.04.07.07.06.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2026 07:06:29 -0700 (PDT) From: Sebastian Alba Vives To: yilun.xu@linux.intel.com Cc: linux-fpga@vger.kernel.org, conor.dooley@microchip.com, mdf@kernel.org, linux-kernel@vger.kernel.org, Sebastian Josue Alba Vives Subject: [PATCH v2 3/3] fpga: microchip-spi: add bounds checks in mpf_ops_parse_header() Date: Tue, 7 Apr 2026 08:06:01 -0600 Message-ID: <20260407140601.15006-3-sebasjosue84@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260407140601.15006-1-sebasjosue84@gmail.com> References: <20260402125446.3776153-1-sebasjosue84@gmail.com> <20260407140601.15006-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