Skip to content

Commit

Permalink
Move is_removable_media_path() to a shared location.
Browse files Browse the repository at this point in the history
We need to use is_removable_media_path(), and potentially other helpers,
from Mok as well as shim.

This moves it to a file just for Device Path utility functions to make
that simpler.

Signed-off-by: Peter Jones <[email protected]>
  • Loading branch information
vathpela committed Jan 17, 2025
1 parent 27562ea commit 1508ece
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 36 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ CFLAGS += -DENABLE_SHIM_CERT
else
TARGETS += $(MMNAME) $(FBNAME)
endif
OBJS = shim.o globals.o mok.o netboot.o cert.o replacements.o tpm.o version.o errlog.o sbat.o sbat_data.o sbat_var.o pe.o pe-relocate.o httpboot.o csv.o load-options.o
OBJS = shim.o globals.o mok.o netboot.o cert.o dp.o replacements.o tpm.o version.o errlog.o sbat.o sbat_data.o sbat_var.o pe.o pe-relocate.o httpboot.o csv.o load-options.o
KEYS = shim_cert.h ocsp.* ca.* shim.crt shim.csr shim.p12 shim.pem shim.key shim.cer
ORIG_SOURCES = shim.c globals.c mok.c netboot.c replacements.c tpm.c errlog.c sbat.c pe.c pe-relocate.c httpboot.c shim.h version.h $(wildcard include/*.h) cert.S sbat_var.S
MOK_OBJS = MokManager.o PasswordCrypt.o crypt_blowfish.o errlog.o sbat_data.o globals.o
ORIG_SOURCES = shim.c globals.c mok.c netboot.c dp.c replacements.c tpm.c errlog.c sbat.c pe.c pe-relocate.c httpboot.c shim.h version.h $(wildcard include/*.h) cert.S sbat_var.S
MOK_OBJS = MokManager.o PasswordCrypt.o crypt_blowfish.o errlog.o sbat_data.o globals.o dp.o
ORIG_MOK_SOURCES = MokManager.c PasswordCrypt.c crypt_blowfish.c shim.h $(wildcard include/*.h)
FALLBACK_OBJS = fallback.o tpm.o errlog.o sbat_data.o globals.o
ORIG_FALLBACK_SRCS = fallback.c
Expand Down
43 changes: 43 additions & 0 deletions dp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-License-Identifier: BSD-2-Clause-Patent
/*
* dp.c - device path helpers
* Copyright Peter Jones <[email protected]>
*/

#include "shim.h"

int
is_removable_media_path(EFI_LOADED_IMAGE *li)
{
unsigned int pathlen = 0;
CHAR16 *bootpath = NULL;
int ret = 0;

bootpath = DevicePathToStr(li->FilePath);

/* Check the beginning of the string and the end, to avoid
* caring about which arch this is. */
/* I really don't know why, but sometimes bootpath gives us
* L"\\EFI\\BOOT\\/BOOTX64.EFI". So just handle that here...
*/
if (StrnCaseCmp(bootpath, L"\\EFI\\BOOT\\BOOT", 14) &&
StrnCaseCmp(bootpath, L"\\EFI\\BOOT\\/BOOT", 15) &&
StrnCaseCmp(bootpath, L"EFI\\BOOT\\BOOT", 13) &&
StrnCaseCmp(bootpath, L"EFI\\BOOT\\/BOOT", 14))
goto error;

pathlen = StrLen(bootpath);
if (pathlen < 5 || StrCaseCmp(bootpath + pathlen - 4, L".EFI"))
goto error;

ret = 1;

error:
if (bootpath)
FreePool(bootpath);

return ret;
}


// vim:fenc=utf-8:tw=75:noet
14 changes: 14 additions & 0 deletions include/dp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: BSD-2-Clause-Patent
/*
* dp.h - device path helper functions
* Copyright Peter Jones <[email protected]>
*/

#ifndef DP_H_
#define DP_H_

int
is_removable_media_path(EFI_LOADED_IMAGE *li);

#endif /* !DP_H_ */
// vim:fenc=utf-8:tw=75:noet
33 changes: 0 additions & 33 deletions shim.c
Original file line number Diff line number Diff line change
Expand Up @@ -778,39 +778,6 @@ verify_buffer (char *data, int datasize,
return verify_buffer_sbat(data, datasize, context);
}

static int
is_removable_media_path(EFI_LOADED_IMAGE *li)
{
unsigned int pathlen = 0;
CHAR16 *bootpath = NULL;
int ret = 0;

bootpath = DevicePathToStr(li->FilePath);

/* Check the beginning of the string and the end, to avoid
* caring about which arch this is. */
/* I really don't know why, but sometimes bootpath gives us
* L"\\EFI\\BOOT\\/BOOTX64.EFI". So just handle that here...
*/
if (StrnCaseCmp(bootpath, L"\\EFI\\BOOT\\BOOT", 14) &&
StrnCaseCmp(bootpath, L"\\EFI\\BOOT\\/BOOT", 15) &&
StrnCaseCmp(bootpath, L"EFI\\BOOT\\BOOT", 13) &&
StrnCaseCmp(bootpath, L"EFI\\BOOT\\/BOOT", 14))
goto error;

pathlen = StrLen(bootpath);
if (pathlen < 5 || StrCaseCmp(bootpath + pathlen - 4, L".EFI"))
goto error;

ret = 1;

error:
if (bootpath)
FreePool(bootpath);

return ret;
}

static int
should_use_fallback(EFI_HANDLE image_handle)
{
Expand Down
1 change: 1 addition & 0 deletions shim.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
#include "include/configtable.h"
#include "include/console.h"
#include "include/crypt_blowfish.h"
#include "include/dp.h"
#include "include/efiauthenticated.h"
#include "include/errors.h"
#include "include/execute.h"
Expand Down

0 comments on commit 1508ece

Please sign in to comment.