Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev efi(4): Fix logic to handle buffer sizing.



details:   https://anonhg.NetBSD.org/src/rev/95ff27bff85e
branches:  trunk
changeset: 375978:95ff27bff85e
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Wed May 24 00:02:51 2023 +0000

description:
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

diffstat:

 sys/dev/efi.c |  14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)

diffs (45 lines):

diff -r ed68feb20864 -r 95ff27bff85e sys/dev/efi.c
--- a/sys/dev/efi.c     Tue May 23 20:26:52 2023 +0000
+++ b/sys/dev/efi.c     Wed May 24 00:02:51 2023 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -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;
        }



Home | Main Index | Thread Index | Old Index