Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1285374pxy; Fri, 23 Apr 2021 04:51:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxOEUrMBmhhh5LsPhHa/VGqiToSTdBtThE51tsGvXmMSXTgsiMsGU7URkxVEJtwCMJcGf0D X-Received: by 2002:a05:6402:10c6:: with SMTP id p6mr3986406edu.241.1619178689656; Fri, 23 Apr 2021 04:51:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619178689; cv=none; d=google.com; s=arc-20160816; b=Y9ypCMBZsvpfkI1RiPfWqjVRuPVYgZGbiBooj0GUQs/ISBonp18ukKhd6lskDIZL4r vgxlJlK1W10bucI0SFpYiDP4IRdspgn2h2lqyay7DXRCvHEG93DIUpx/8CJR30ANDuTP x89/o2To3t7ksOZLZftPugCLuB0HL0ZSEimQhWZJVrawu0zs04WBWL+ibyWsCd3OWQ0w EvzbUorvK9NgIs6xLMp6L3dpqxawbF3/Rlo95n3HqxgidtihLMZSPLGiX6oyfrTgctwf hGNJTAh6Om1hu7epByy1pzXNvetkV+VVBoseIPT4PfNTKlUGblAbc61VGnSfhJwaVMbp l40Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=iPby8n/oKiSg9iosJsx9rxTWFJNSezrrmzL3UQ0jX3w=; b=FXoutXzx0oi+j9vEGh4aOagGsopPVtrbEll5er6uisMhZPiRM1TPN1B+lV1pSVw2SJ ulFUVnLTz/+mv8aoW0ALEIxyZdV/UOX3QNvhLQHyrflD57LVAPR9fdsQ9oD8/zzZzDGf pvGtYHQ6D5oCb9l7fvxwv7S+EwqIa78pt78Yg1xfBqr0Bcui1ClMdY+b+gxkWHaKgPEd 2DOFv1CY87Rr7p5mFBNQBNl7pQ+I1SDedUZF1fSY7IbtVR1GoRV19Sq3UjnXIwj2qLIA NW2S4bWMYxIWMtv31W4az2Z0n6jF2DKmDK2qQP0Bn+Dfa3Vtx+kJPzWJqVparZQEQQww +Pkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=T66eUBCC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v26si4333150edq.297.2021.04.23.04.51.06; Fri, 23 Apr 2021 04:51:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=T66eUBCC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242153AbhDWLta (ORCPT + 99 others); Fri, 23 Apr 2021 07:49:30 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:39662 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229957AbhDWLt3 (ORCPT ); Fri, 23 Apr 2021 07:49:29 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 13NBcwRV034176; Fri, 23 Apr 2021 11:48:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : mime-version : content-type; s=corp-2020-01-29; bh=iPby8n/oKiSg9iosJsx9rxTWFJNSezrrmzL3UQ0jX3w=; b=T66eUBCC0JclzjlmpGtcL8C33MI1jV9nSKjMGW+vpV55thrQz0Qelu9x5nCEDX0pXeBq nt4N1TohtoMWVhXNILiOb2GE/WjBR3Dprm9XTrOupSRyMqyIXfzqdJ8t1f86JYS/Chkh Z3Zeo80A8OqVPjBzmCMbsPLVtZx8XdN7zeqPKEJX/LQvHK2LTV4vP649qxBMfI2NhUqq MdOcIp1wvtV0qCYNVTmNaXBxaZxggJI0yZcy1A+u3QV5Y5pWrbliTgvYGzUHM79YT3nw uIPBlJ08Pj4M4f0et2ySqkt9KUvrwgfns/Du7zWpI2vrcVie1hfHimw+cWxIMpDsbfJ3 Bw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 37yqmnr69j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 23 Apr 2021 11:48:45 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 13NBjTEL009544; Fri, 23 Apr 2021 11:48:45 GMT Received: from pps.reinject (localhost [127.0.0.1]) by aserp3020.oracle.com with ESMTP id 383cbf3436-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 23 Apr 2021 11:48:45 +0000 Received: from aserp3020.oracle.com (aserp3020.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 13NBmiSS035729; Fri, 23 Apr 2021 11:48:44 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3020.oracle.com with ESMTP id 383cbf3425-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 23 Apr 2021 11:48:44 +0000 Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 13NBmbqu002744; Fri, 23 Apr 2021 11:48:37 GMT Received: from mwanda (/102.36.221.92) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 23 Apr 2021 04:48:37 -0700 Date: Fri, 23 Apr 2021 14:48:31 +0300 From: Dan Carpenter To: Ard Biesheuvel Cc: Arvind Sankar , Philipp Fent , linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH] efi/libstub: prevent read overflow in find_file_option() Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Mailer: git-send-email haha only kidding X-Proofpoint-ORIG-GUID: 5ap1h2IUpdIXpA20rB1QYLJ-3aVVhSg9 X-Proofpoint-GUID: 5ap1h2IUpdIXpA20rB1QYLJ-3aVVhSg9 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9962 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxscore=0 adultscore=0 impostorscore=0 spamscore=0 malwarescore=0 clxscore=1011 lowpriorityscore=0 priorityscore=1501 suspectscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104230076 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If the buffer has slashes up to the end then this will read past the end of the array. I don't anticipate that this is an issue for many people in real life, but it's the right thing to do and it makes static checkers happy. Fixes: 7a88a6227dc7 ("efi/libstub: Fix path separator regression") Signed-off-by: Dan Carpenter --- drivers/firmware/efi/libstub/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/firmware/efi/libstub/file.c b/drivers/firmware/efi/libstub/file.c index 4e81c6077188..dd95f330fe6e 100644 --- a/drivers/firmware/efi/libstub/file.c +++ b/drivers/firmware/efi/libstub/file.c @@ -103,7 +103,7 @@ static int find_file_option(const efi_char16_t *cmdline, int cmdline_len, return 0; /* Skip any leading slashes */ - while (cmdline[i] == L'/' || cmdline[i] == L'\\') + while (i < cmdline_len && (cmdline[i] == L'/' || cmdline[i] == L'\\')) i++; while (--result_len > 0 && i < cmdline_len) { -- 2.30.2