util/nvmutil: harden pledge/unveil calls (OpenBSD)

*Open* files at the start, then unveil. The same overall
behaviour is observed. In the case that invalid arguments
are given, simply opening a file does not cause much
performance impact (if any).

Restrict operations as early as possible in code.

Bonus:

writeGbeFile also hardened; if flags is O_RDONLY, it aborts.

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2023-06-01 13:35:34 +01:00
parent adf3aece6f
commit 69fa333e25
2 changed files with 25 additions and 16 deletions
+3 -2
View File
@@ -13,7 +13,8 @@
#include <string.h>
#include <unistd.h>
void readGbeFile(const char *path, int flags);
void openFiles(const char *path);
void readGbeFile(const char *path);
void cmd_setmac(const char *strMac);
int invalidMacAddress(const char *strMac, uint16_t *mac);
uint8_t hextonum(char chs);
@@ -42,7 +43,7 @@ uint8_t *buf = (uint8_t *) &buf16;
size_t nf = 128, gbe[2];
uint8_t skipread[2] = {0, 0};
int fd = -1, part, gbeFileModified = 0;
int flags = O_RDWR, fd = -1, part, gbeFileModified = 0;
uint8_t nvmPartModified[2] = {0, 0};
int test = 1;