From owner-svn-src-all@freebsd.org Tue Aug 8 20:44:18 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 609FBDCF4C8; Tue, 8 Aug 2017 20:44:18 +0000 (UTC) (envelope-from imp@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 mx1.freebsd.org (Postfix) with ESMTPS id 32C417312E; Tue, 8 Aug 2017 20:44:18 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v78KiHlr002792; Tue, 8 Aug 2017 20:44:17 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v78KiH9F002789; Tue, 8 Aug 2017 20:44:17 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201708082044.v78KiH9F002789@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Tue, 8 Aug 2017 20:44:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r322278 - in head/sys: amd64/amd64 amd64/include dev/efidev X-SVN-Group: head X-SVN-Commit-Author: imp X-SVN-Commit-Paths: in head/sys: amd64/amd64 amd64/include dev/efidev X-SVN-Commit-Revision: 322278 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.23 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: Tue, 08 Aug 2017 20:44:18 -0000 Author: imp Date: Tue Aug 8 20:44:16 2017 New Revision: 322278 URL: https://svnweb.freebsd.org/changeset/base/322278 Log: Fail to open efirt device when no EFI on system. libefivar expects opening /dev/efi to indicate if the we can make efi runtime calls. With a null routine, it was always succeeding leading efi_variables_supported() to return the wrong value. Only succeed if we have an efi_runtime table. Also, while I'm hear, out of an abundance of caution, add a likely redundant check to make sure efi_systbl is not NULL before dereferencing it. I know it can't be NULL if efi_cfgtbl is non-NULL, but the compiler doesn't. Modified: head/sys/amd64/amd64/efirt.c head/sys/amd64/include/efi.h head/sys/dev/efidev/efidev.c Modified: head/sys/amd64/amd64/efirt.c ============================================================================== --- head/sys/amd64/amd64/efirt.c Tue Aug 8 20:17:07 2017 (r322277) +++ head/sys/amd64/amd64/efirt.c Tue Aug 8 20:44:16 2017 (r322278) @@ -421,12 +421,21 @@ efi_uninit(void) } int +efi_rt_ok(void) +{ + + if (efi_runtime == NULL) + return (ENXIO); + return (0); +} + +int efi_get_table(struct uuid *uuid, void **ptr) { struct efi_cfgtbl *ct; u_long count; - if (efi_cfgtbl == NULL) + if (efi_cfgtbl == NULL || efi_systbl == NULL) return (ENXIO); count = efi_systbl->st_entries; ct = efi_cfgtbl; Modified: head/sys/amd64/include/efi.h ============================================================================== --- head/sys/amd64/include/efi.h Tue Aug 8 20:17:07 2017 (r322277) +++ head/sys/amd64/include/efi.h Tue Aug 8 20:44:16 2017 (r322278) @@ -49,6 +49,7 @@ struct uuid; struct efi_tm; +int efi_rt_ok(void); int efi_get_table(struct uuid *uuid, void **ptr); int efi_get_time(struct efi_tm *tm); int efi_get_time_locked(struct efi_tm *tm); Modified: head/sys/dev/efidev/efidev.c ============================================================================== --- head/sys/dev/efidev/efidev.c Tue Aug 8 20:17:07 2017 (r322277) +++ head/sys/dev/efidev/efidev.c Tue Aug 8 20:44:16 2017 (r322278) @@ -39,14 +39,27 @@ __FBSDID("$FreeBSD$"); #include #include +static d_open_t efidev_open; static d_ioctl_t efidev_ioctl; static struct cdevsw efi_cdevsw = { .d_name = "efi", .d_version = D_VERSION, + .d_open = efidev_open, .d_ioctl = efidev_ioctl, }; +static int +efidev_open(struct cdev *dev __unused, int oflags __unused, + int devtype __unused, struct thread *td __unused) +{ + /* + * Only return success when we have an actual runtime to call. + */ + + return efi_rt_ok(); +} + static int efidev_ioctl(struct cdev *dev __unused, u_long cmd, caddr_t addr, int flags __unused, struct thread *td __unused)