From owner-svn-src-all@freebsd.org Thu Mar 22 15:32:58 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2797BF4EEAE; Thu, 22 Mar 2018 15:32:58 +0000 (UTC) (envelope-from andrew@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id C8C0E7B2BD; Thu, 22 Mar 2018 15:32:57 +0000 (UTC) (envelope-from andrew@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C2483132F4; Thu, 22 Mar 2018 15:32:57 +0000 (UTC) (envelope-from andrew@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w2MFWv2p047089; Thu, 22 Mar 2018 15:32:57 GMT (envelope-from andrew@FreeBSD.org) Received: (from andrew@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w2MFWv8W047088; Thu, 22 Mar 2018 15:32:57 GMT (envelope-from andrew@FreeBSD.org) Message-Id: <201803221532.w2MFWv8W047088@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: andrew set sender to andrew@FreeBSD.org using -f From: Andrew Turner Date: Thu, 22 Mar 2018 15:32:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r331361 - head/sys/dev/efidev X-SVN-Group: head X-SVN-Commit-Author: andrew X-SVN-Commit-Paths: head/sys/dev/efidev X-SVN-Commit-Revision: 331361 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Mar 2018 15:32:58 -0000 Author: andrew Date: Thu Mar 22 15:32:57 2018 New Revision: 331361 URL: https://svnweb.freebsd.org/changeset/base/331361 Log: Enter into the EFI environment before dereferencing the runtime services pointer. This may be within the EFI address space and not the FreeBSD kernel address space. X-MFC-With: r330868 Sponsored by: DARPA, AFRL Modified: head/sys/dev/efidev/efirt.c Modified: head/sys/dev/efidev/efirt.c ============================================================================== --- head/sys/dev/efidev/efirt.c Thu Mar 22 15:24:26 2018 (r331360) +++ head/sys/dev/efidev/efirt.c Thu Mar 22 15:32:57 2018 (r331361) @@ -88,6 +88,9 @@ static int efi_status2err[25] = { EPROTO /* EFI_PROTOCOL_ERROR */ }; +static int efi_enter(void); +static void efi_leave(void); + static int efi_status_to_errno(efi_status status) { @@ -190,9 +193,14 @@ efi_init(void) * call RS->SetVirtualAddressMap. As this is not always the case, e.g. * with an old loader.efi, check if the RS->GetTime function is within * the EFI map, and fail to attach if not. + * + * We need to enter into the EFI environment as efi_runtime may point + * to an EFI address. */ + efi_enter(); if (!efi_is_in_map(map, efihdr->memory_size / efihdr->descriptor_size, efihdr->descriptor_size, (vm_offset_t)efi_runtime->rt_gettime)) { + efi_leave(); if (bootverbose) printf( "EFI runtime services table has an invalid pointer\n"); @@ -200,6 +208,7 @@ efi_init(void) efi_destroy_1t1_map(); return (ENXIO); } + efi_leave(); return (0); }