mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-18 14:12:44 +02:00
util/nvmutil: don't pledge on OLD openbsd
only pledge/unveil where available, on versions that have it. this patch disables it on older versions, allowing nvmutil to compile. Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
+46
-6
@@ -2,6 +2,9 @@
|
|||||||
/* Copyright (c) 2022-2026 Leah Rowe <leah@libreboot.org> */
|
/* Copyright (c) 2022-2026 Leah Rowe <leah@libreboot.org> */
|
||||||
/* Copyright (c) 2023 Riku Viitanen <riku.viitanen@protonmail.com> */
|
/* Copyright (c) 2023 Riku Viitanen <riku.viitanen@protonmail.com> */
|
||||||
|
|
||||||
|
#ifdef __OpenBSD__
|
||||||
|
#include <sys/param.h>
|
||||||
|
#endif
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@@ -13,11 +16,37 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The BSD versions that could realistically build
|
||||||
|
* nvmutil almost certainly have arc4random (first
|
||||||
|
* introduced in 1990s or early 2000s in most of
|
||||||
|
* them - you can just patch as needed, on old BSD.
|
||||||
|
*/
|
||||||
#if defined(__OpenBSD__) || defined(__FreeBSD__) || \
|
#if defined(__OpenBSD__) || defined(__FreeBSD__) || \
|
||||||
defined(__NetBSD__) || defined(__APPLE__) || \
|
defined(__NetBSD__) || defined(__APPLE__) || \
|
||||||
defined(__DragonFly__)
|
defined(__DragonFly__)
|
||||||
#ifndef HAVE_ARC4RANDOM_BUF
|
#ifndef HAVE_ARC4RANDOM_BUF
|
||||||
#define HAVE_ARC4RANDOM_BUF
|
#define HAVE_ARC4RANDOM_BUF 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Older versions of BSD to the early 2000s
|
||||||
|
* could compile nvmutil, but pledge was
|
||||||
|
* added in the 2010s. Therefore, for extra
|
||||||
|
* portability, we will only pledge/unveil
|
||||||
|
* on OpenBSD versions that have it.
|
||||||
|
*/
|
||||||
|
#if defined(__OpenBSD__) && defined(OpenBSD)
|
||||||
|
#if OpenBSD >= 604
|
||||||
|
#ifndef NVMUTIL_UNVEIL
|
||||||
|
#define NVMUTIL_UNVEIL 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#if OpenBSD >= 509
|
||||||
|
#ifndef NVMUTIL_PLEDGE
|
||||||
|
#define NVMUTIL_PLEDGE 1
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -289,12 +318,16 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
fname = argv[1];
|
fname = argv[1];
|
||||||
|
|
||||||
#ifdef __OpenBSD__
|
#ifdef NVMUTIL_PLEDGE
|
||||||
|
#ifdef NVMUTIL_UNVEIL
|
||||||
if (pledge("stdio rpath wpath unveil", NULL) == -1)
|
if (pledge("stdio rpath wpath unveil", NULL) == -1)
|
||||||
err(ECANCELED, "pledge");
|
err(ECANCELED, "pledge");
|
||||||
|
|
||||||
if (unveil("/dev/null", "r") == -1)
|
if (unveil("/dev/null", "r") == -1)
|
||||||
err(ECANCELED, "unveil '/dev/null'");
|
err(ECANCELED, "unveil '/dev/null'");
|
||||||
|
#else
|
||||||
|
if (pledge("stdio rpath wpath", NULL) == -1)
|
||||||
|
err(ECANCELED, "pledge");
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sanitize_command_list();
|
sanitize_command_list();
|
||||||
@@ -303,7 +336,8 @@ main(int argc, char *argv[])
|
|||||||
set_cmd_args(argc, argv);
|
set_cmd_args(argc, argv);
|
||||||
set_io_flags(argc, argv);
|
set_io_flags(argc, argv);
|
||||||
|
|
||||||
#ifdef __OpenBSD__
|
#ifdef NVMUTIL_PLEDGE
|
||||||
|
#ifdef NVMUTIL_UNVEIL
|
||||||
if (gbe_flags == O_RDONLY) {
|
if (gbe_flags == O_RDONLY) {
|
||||||
if (unveil(fname, "r") == -1)
|
if (unveil(fname, "r") == -1)
|
||||||
err(ECANCELED, "unveil ro '%s'", fname);
|
err(ECANCELED, "unveil ro '%s'", fname);
|
||||||
@@ -319,6 +353,12 @@ main(int argc, char *argv[])
|
|||||||
if (pledge("stdio rpath wpath", NULL) == -1)
|
if (pledge("stdio rpath wpath", NULL) == -1)
|
||||||
err(ECANCELED, "pledge rw (kill unveil)");
|
err(ECANCELED, "pledge rw (kill unveil)");
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
if (gbe_flags == O_RDONLY) {
|
||||||
|
if (pledge("stdio rpath", NULL) == -1)
|
||||||
|
err(ECANCELED, "pledge ro");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_ARC4RANDOM_BUF
|
#ifndef HAVE_ARC4RANDOM_BUF
|
||||||
@@ -332,7 +372,7 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
open_gbe_file();
|
open_gbe_file();
|
||||||
|
|
||||||
#ifdef __OpenBSD__
|
#ifdef NVMUTIL_PLEDGE
|
||||||
if (pledge("stdio", NULL) == -1)
|
if (pledge("stdio", NULL) == -1)
|
||||||
err(ECANCELED, "pledge stdio (main)");
|
err(ECANCELED, "pledge stdio (main)");
|
||||||
#endif
|
#endif
|
||||||
@@ -1169,7 +1209,7 @@ usage(uint8_t usage_exit)
|
|||||||
{
|
{
|
||||||
const char *util = getnvmprogname();
|
const char *util = getnvmprogname();
|
||||||
|
|
||||||
#ifdef __OpenBSD__
|
#ifdef NVMUTIL_PLEDGE
|
||||||
if (pledge("stdio", NULL) == -1)
|
if (pledge("stdio", NULL) == -1)
|
||||||
err(ECANCELED, "pledge");
|
err(ECANCELED, "pledge");
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user