Skip to content

Distribute and run LLMs with a single file.

Disable pledge on systems with GPUs

Justine Tunney61944b590b90
diff --git a/README.md b/README.md
index 7a6a119a..5fef658c 100644
--- a/README.md
+++ b/README.md
@@ -325,42 +325,6 @@ mv server.com server
Congratulations. You've just made your own LLM executable that's easy to
share with your friends.
-## Security
-
-llamafile adds pledge() and SECCOMP sandboxing to llama.cpp. This is
-enabled by default. It can be turned off by passing the `--unsecure`
-flag. Sandboxing is currently only supported on Linux and OpenBSD; on
-other platforms it'll simply log a warning.
-
-Our approach to security has these benefits:
-
-1. After it starts up, your HTTP server isn't able to access the
- filesystem at all. This is good, since it means if someone discovers
- a bug in the llama.cpp server, then it's much less likely they'll be
- able to access sensitive information on your machine or make changes
- to its configuration. On Linux, we're able to sandbox things even
- further; the only networking related system call the HTTP server will
- allowed to use after starting up, is accept(). That further limits an
- attacker's ability to exfiltrate information, in the event that your
- HTTP server is compromised.
-
-2. The main CLI command won't be able to access the network at all. This
- is enforced by the operating system kernel. It also won't be able to
- write to the file system. This keeps your computer safe in the event
- that a bug is ever discovered in the the GGUF file format that lets
- an attacker craft malicious weights files and post them online. The
- only exception to this rule is if you pass the `--prompt-cache` flag
- without also specifying `--prompt-cache-ro`. In that case, security
- currently needs to be weakened to allow `cpath` and `wpath` access,
- but network access will remain forbidden.
-
-Therefore your llamafile is able to protect itself against the outside
-world, but that doesn't mean you're protected from llamafile. Sandboxing
-is self-imposed. If you obtained your llamafile from an untrusted source
-then its author could have simply modified it to not do that. In that
-case, you can run the untrusted llamafile inside another sandbox, such
-as a virtual machine, to make sure it behaves how you expect.
-
## zipalign documentation
```
@@ -487,6 +451,42 @@ The example llamafiles provided above should not be interpreted as
endorsements or recommendations of specific models, licenses, or data
sets on the part of Mozilla.
+## Security
+
+llamafile adds pledge() and SECCOMP sandboxing to llama.cpp. This is
+enabled by default. It can be turned off by passing the `--unsecure`
+flag. Sandboxing is currently only supported on Linux and OpenBSD on
+systems without GPUs; on other platforms it'll simply log a warning.
+
+Our approach to security has these benefits:
+
+1. After it starts up, your HTTP server isn't able to access the
+ filesystem at all. This is good, since it means if someone discovers
+ a bug in the llama.cpp server, then it's much less likely they'll be
+ able to access sensitive information on your machine or make changes
+ to its configuration. On Linux, we're able to sandbox things even
+ further; the only networking related system call the HTTP server will
+ allowed to use after starting up, is accept(). That further limits an
+ attacker's ability to exfiltrate information, in the event that your
+ HTTP server is compromised.
+
+2. The main CLI command won't be able to access the network at all. This
+ is enforced by the operating system kernel. It also won't be able to
+ write to the file system. This keeps your computer safe in the event
+ that a bug is ever discovered in the the GGUF file format that lets
+ an attacker craft malicious weights files and post them online. The
+ only exception to this rule is if you pass the `--prompt-cache` flag
+ without also specifying `--prompt-cache-ro`. In that case, security
+ currently needs to be weakened to allow `cpath` and `wpath` access,
+ but network access will remain forbidden.
+
+Therefore your llamafile is able to protect itself against the outside
+world, but that doesn't mean you're protected from llamafile. Sandboxing
+is self-imposed. If you obtained your llamafile from an untrusted source
+then its author could have simply modified it to not do that. In that
+case, you can run the untrusted llamafile inside another sandbox, such
+as a virtual machine, to make sure it behaves how you expect.
+
## Licensing
While the llamafile project is Apache 2.0-licensed, our changes
diff --git a/llama.cpp/main/main.cc b/llama.cpp/main/main.cc
index 53f88335..801891b1 100644
--- a/llama.cpp/main/main.cc
+++ b/llama.cpp/main/main.cc
@@ -2,6 +2,8 @@
// vi: set net ft=c++ ts=4 sts=4 sw=4 fenc=utf-8 :vi
#include <cosmo.h>
+#include "llama.cpp/ggml-metal.h"
+#include "llama.cpp/ggml-cuda.h"
#include "tool/args/args.h"
#include "llama.cpp/common.h"
@@ -130,7 +132,7 @@ int main(int argc, char ** argv) {
atexit([]() { console::cleanup(); });
is_terminal = isatty(2);
- if (!params.unsecure) {
+ if (!params.unsecure && !ggml_metal_supported() && !ggml_cuda_supported()) {
// Enable pledge() security on Linux and OpenBSD.
// - We do this *after* opening the log file for writing.
// - We do this *before* loading any weights or graphdefs.
diff --git a/llama.cpp/server/server.cpp b/llama.cpp/server/server.cpp
index dc2123ce..9919534b 100644
--- a/llama.cpp/server/server.cpp
+++ b/llama.cpp/server/server.cpp
@@ -7,6 +7,8 @@
#include "llama.cpp/grammar-parser.h"
#include "llama.cpp/llava/clip.h"
#include "llama.cpp/stb_image.h"
+#include "llama.cpp/ggml-metal.h"
+#include "llama.cpp/ggml-cuda.h"
#include "llamafile/llamafile.h"
#define CPPHTTPLIB_NO_EXCEPTIONS 1
@@ -3004,7 +3006,7 @@ int main(int argc, char **argv)
llamafile_launch_browser(url);
}
- if (!sparams.unsecure) {
+ if (!sparams.unsecure && !ggml_metal_supported() && !ggml_cuda_supported()) {
// Enables pledge() security on Linux and OpenBSD.
// - We do this *after* binding the server socket.
// - We do this *after* opening the log file for writing.