[PATCH] Check actual length of data read from env file

4 views
Skip to first unread message

Jan Kiszka

unread,
Feb 22, 2022, 12:28:23 PM2/22/22
to efibootguard-dev
From: Jan Kiszka <jan.k...@siemens.com>

Better safe than sorry: If the env file is shorter than BG_ENVDATA, bail
out early rather than just relying on the CRC32 check to catch this.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
env/fatvars.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/env/fatvars.c b/env/fatvars.c
index ca15f5e..7572e83 100644
--- a/env/fatvars.c
+++ b/env/fatvars.c
@@ -135,7 +135,8 @@ BG_STATUS load_config(BG_LOADER_PARAMS *bglp)
continue;
}
UINTN readlen = sizeof(BG_ENVDATA);
- if (EFI_ERROR(read_cfg_file(fh, &readlen, (VOID *)&env[i]))) {
+ if (EFI_ERROR(read_cfg_file(fh, &readlen, (VOID *)&env[i])) ||
+ readlen < sizeof(BG_ENVDATA)) {
ERROR(L"Cannot read environment from config partition %d.\n", i);
env_invalid[i] = 1;
if (EFI_ERROR(close_cfg_file(v->root, fh))) {
--
2.34.1
Reply all
Reply to author
Forward
0 new messages