Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1olcn3-00035d-Fs for mharc-grub-devel@gnu.org; Thu, 20 Oct 2022 17:09:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1olcn1-00032Z-Ui for grub-devel@gnu.org; Thu, 20 Oct 2022 17:09:19 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1olcn0-0002Jq-5f for grub-devel@gnu.org; Thu, 20 Oct 2022 17:09:19 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29KKkmDX027814 for ; Thu, 20 Oct 2022 21:09:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2022-7-12; bh=wBT2o40UScrdWae+d0iah2UL0TmbvXFnc584WgA27XQ=; b=VNoePf+1PxichCs7e8WxA5dF4lkM32Eyu1KKYkStckgsg9IcOQDSHwXmQgistE3bVOww VNUMvLNpzvPDfXSqzGkSJu2SI1RobmogLJfUiBuT3dkc4WiG2bpnTGvyBTTaZb8TjpM9 oKetHn3PxtO51KDgou9vw1TJKI6VbGJpUVGiIz30VxQ4MsFHp/9Hs7W5ArNpNzYn/AKh YUk1xhKxLowOX3vftUBADTvTPi6Elh5MDr1Zfw3cQbH+yWHTbv88FeVORC7fCyXU8+zV RuaoVtEUI2f1behVNCGrqZZ8Vl5iNcftMgewWs8xjedjzDihRrpjBQD/pXHyC2TBj0rh 7A== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3k7mu06tuh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 20 Oct 2022 21:09:13 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 29KKs0fe014683 for ; Thu, 20 Oct 2022 21:09:12 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3k8hu950h9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 20 Oct 2022 21:09:12 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 29KL9CfM015864 for ; Thu, 20 Oct 2022 21:09:12 GMT Received: from localhost (dhcp-10-152-14-18.usdhcp.oraclecorp.com [10.152.14.18]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3k8hu950h3-1; Thu, 20 Oct 2022 21:09:12 +0000 From: Alec Brown To: grub-devel@gnu.org Cc: daniel.kiper@oracle.com, alec.r.brown@oracle.com, darren.kenny@oracle.com Subject: [PATCH 2/2] video/readers/jpeg: Check next_marker is within file size Date: Thu, 20 Oct 2022 17:11:14 -0400 Message-Id: <1666300274-2151-3-git-send-email-alec.r.brown@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1666300274-2151-1-git-send-email-alec.r.brown@oracle.com> References: <1666300274-2151-1-git-send-email-alec.r.brown@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-20_11,2022-10-20_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 suspectscore=0 phishscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2210200132 X-Proofpoint-ORIG-GUID: N9lK2_TqdTfj9hhoQAhudOMy02raEkxc X-Proofpoint-GUID: N9lK2_TqdTfj9hhoQAhudOMy02raEkxc Received-SPF: pass client-ip=205.220.177.32; envelope-from=alec.r.brown@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Oct 2022 21:09:20 -0000 In grub-core/video/readers/jpeg.c, the function grub_jpeg_decode_huff_table() has the variable next_marker which reads data from grub_jpeg_get_word() and then uses it as an upper limit in a while loop. However, the function isn't checking that next_marker is within the file size, so this check is being added to the function. Signed-off-by: Alec Brown --- grub-core/video/readers/jpeg.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/grub-core/video/readers/jpeg.c b/grub-core/video/readers/jpeg.c index 0eeea0e63..c0f95fbf9 100644 --- a/grub-core/video/readers/jpeg.c +++ b/grub-core/video/readers/jpeg.c @@ -199,6 +199,12 @@ grub_jpeg_decode_huff_table (struct grub_jpeg_data *data) next_marker = data->file->offset; next_marker += grub_jpeg_get_word (data); + if (next_marker > data->file->size) + { + /* Should never be set beyond the size of the file. */ + return grub_error (GRUB_ERR_BAD_FILE_TYPE, "jpeg: invalid next reference"); + } + while (data->file->offset + sizeof (count) + 1 <= next_marker) { id = grub_jpeg_get_byte (data); -- 2.27.0