From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web11.65887.1669950354789739341 for ; Thu, 01 Dec 2022 19:05:55 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DAFtRuZt; spf=pass (domain: redhat.com, ip: 170.10.133.124, mailfrom: jmaloy@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669950353; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ZsjNLp3ZGT+ELwB3cL3cYfefxg1yNZL7FY7CAUgXDho=; b=DAFtRuZtF1f56JljeDzmZfjU53QG2FVMU2rDixystuxUMX1Xl0dUK6G1sIuRzcrzxgEWHd kGEmIyt6t8GL84ZTfo/ZBJ0FXxr63nJ9X7iwasSUOaTXdnMsezWnx6jF4CgVR31AcWytbF Xsig81v898gHKuh9Wa4Ib2Zq3BLPr0k= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-614-8rut0jpbNvykHhhRWWOTig-1; Thu, 01 Dec 2022 22:05:50 -0500 X-MC-Unique: 8rut0jpbNvykHhhRWWOTig-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BAA1E85A588; Fri, 2 Dec 2022 03:05:49 +0000 (UTC) Received: from fenrir.redhat.com (unknown [10.22.10.171]) by smtp.corp.redhat.com (Postfix) with ESMTP id 195AB2166BB6; Fri, 2 Dec 2022 03:05:48 +0000 (UTC) From: "Jon Maloy" To: devel@edk2.groups.io Cc: kraxel@redhat.com, lersek@redhat.com, jmaloy@redhat.com, Jiewen Yao , Jian J Wang , Min Xu Subject: [edk2-devel] [PATCH] SecurityPkg: check return value of GetEfiGlobalVariable2() in DxeImageVerificationHandler() Date: Thu, 1 Dec 2022 22:05:26 -0500 Message-Id: <20221202030526.71113-1-jmaloy@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true Fixes: CVE-2019-14560 GetEfiGlobalVariable2() is used in some instances when looking up the SecureBoot UEFI variable. The API can fail in certain circumstances, for example, if AllocatePool() fails or if gRT->GetVariable() fails. In the case of secure boot checks, it is critical that this return value is checked. if an attacker can cause the API to fail, it would currently constitute a secure boot bypass. This return value check is missing in the function DxeImageVerificationHandler(), so we add it here. This commit is almost identical to one suggested by Jian J Wang on 2019-09-09, but that one was for some reason never posted to the edk2-devel list. We now make a new attempt to get it reviewed and applied. Cc: Jiewen Yao Cc: Jian J Wang Cc: Min Xu Cc: devel@edk2.groups.io Signed-off-by: Jon Maloy --- .../DxeImageVerificationLib.c | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c index 66e2f5eaa3c0..4ae0bd8b20db 100644 --- a/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c +++ b/SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.c @@ -1686,6 +1686,7 @@ DxeImageVerificationHandler ( RETURN_STATUS PeCoffStatus; EFI_STATUS HashStatus; EFI_STATUS DbStatus; + EFI_STATUS SecBootStatus; BOOLEAN IsFound; SignatureList = NULL; @@ -1742,23 +1743,29 @@ DxeImageVerificationHandler ( CpuDeadLoop (); } - GetEfiGlobalVariable2 (EFI_SECURE_BOOT_MODE_NAME, (VOID **)&SecureBoot, NULL); - // - // Skip verification if SecureBoot variable doesn't exist. - // - if (SecureBoot == NULL) { - return EFI_SUCCESS; - } + SecBootStatus = GetEfiGlobalVariable2 (EFI_SECURE_BOOT_MODE_NAME, (VOID **)&SecureBoot, NULL); + if (!EFI_ERROR (SecBootStatus)) { + if (SecureBoot == NULL) { + // + // Skip verification if SecureBoot variable doesn't exist. + // + return EFI_SUCCESS; + } else { + // + // Skip verification if SecureBoot is disabled but not AuditMode + // + if (*SecureBoot == SECURE_BOOT_MODE_DISABLE) { + FreePool (SecureBoot); + return EFI_SUCCESS; + } + FreePool (SecureBoot); + } + } else { + // + // Assume SecureBoot enabled in the case of error. + // + } - // - // Skip verification if SecureBoot is disabled but not AuditMode - // - if (*SecureBoot == SECURE_BOOT_MODE_DISABLE) { - FreePool (SecureBoot); - return EFI_SUCCESS; - } - - FreePool (SecureBoot); // // Read the Dos header. -- 2.35.3