Module Name:    src
Committed By:   riastradh
Date:           Wed May 24 00:02:51 UTC 2023

Modified Files:
        src/sys/dev: efi.c

Log Message:
efi(4): Fix logic to handle buffer sizing.

Can't KASSERT(datasize <= databufsize) because the caller is allowed
to pass in a too-small size and get ERR_BUFFER_TOO_SMALL back, with
the actual size returned so it can resize its buffer.  So just clamp
the size to the smaller of what the caller provided and what the
firwmare provided, instead of asserting anything.

PR kern/57076

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/efi.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/efi.c
diff -u src/sys/dev/efi.c:1.8 src/sys/dev/efi.c:1.9
--- src/sys/dev/efi.c:1.8	Mon May 22 16:28:16 2023
+++ src/sys/dev/efi.c	Wed May 24 00:02:51 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: efi.c,v 1.8 2023/05/22 16:28:16 riastradh Exp $ */
+/* $NetBSD: efi.c,v 1.9 2023/05/24 00:02:51 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2021 Jared McNeill <jmcne...@invisible.ca>
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: efi.c,v 1.8 2023/05/22 16:28:16 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: efi.c,v 1.9 2023/05/24 00:02:51 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/conf.h>
@@ -377,10 +377,10 @@ efi_ioctl_var_get(struct efi_var_ioc *va
 		error = efi_status_to_error(status);
 		goto done;
 	}
-	KASSERT(datasize <= databufsize);
 	var->datasize = datasize;
-	if (status == EFI_SUCCESS && databuf != NULL) {
-		error = copyout(databuf, var->data, var->datasize);
+	if (status == EFI_SUCCESS && databufsize != 0) {
+		error = copyout(databuf, var->data,
+		    MIN(datasize, databufsize));
 	} else {
 		var->data = NULL;
 	}
@@ -423,10 +423,10 @@ efi_ioctl_var_next(struct efi_var_ioc *v
 		error = efi_status_to_error(status);
 		goto done;
 	}
-	KASSERT(namesize <= namebufsize);
 	var->namesize = namesize;
 	if (status == EFI_SUCCESS) {
-		error = copyout(namebuf, var->name, var->namesize);
+		error = copyout(namebuf, var->name,
+		    MIN(namesize, namebufsize));
 	} else {
 		var->name = NULL;
 	}

Reply via email to