aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-01-18 11:59:33 +0900
committerOphestra <cat@gensokyo.uk>2025-01-18 11:59:33 +0900
commit7baca66a56f67fa5722b689cbff747eac12b857e (patch)
treea2e6bf668d2a5ea52b5e113c08d65141dbcd5101
parent27d2914286495bf83b163172d5084a91222e7ed7 (diff)
proc: remove duplicate compile-time fortify reference
This is no longer needed since shim and init are now part of the main program. Signed-off-by: Ophestra <cat@gensokyo.uk>
-rw-r--r--cmd/fpkg/proc.go8
-rwxr-xr-xdist/release.sh1
-rw-r--r--internal/path.go3
-rw-r--r--internal/proc/priv/shim/main.go10
-rw-r--r--internal/proc/priv/shim/manager.go2
-rw-r--r--internal/proc/self.go26
-rw-r--r--package.nix1
7 files changed, 36 insertions, 15 deletions
diff --git a/cmd/fpkg/proc.go b/cmd/fpkg/proc.go
index a995c9f1..7fa6df5a 100644
--- a/cmd/fpkg/proc.go
+++ b/cmd/fpkg/proc.go
@@ -12,12 +12,18 @@ import (
"git.gensokyo.uk/security/fortify/internal/fmsg"
)
+const compPoison = "INVALIDINVALIDINVALIDINVALIDINVALID"
+
+var (
+ Fmain = compPoison
+)
+
func fortifyApp(config *fst.Config, beforeFail func()) {
var (
cmd *exec.Cmd
st io.WriteCloser
)
- if p, ok := internal.Check(internal.Fortify); !ok {
+ if p, ok := internal.Path(Fmain); !ok {
beforeFail()
fmsg.Fatal("invalid fortify path, this copy of fpkg is not compiled correctly")
panic("unreachable")
diff --git a/dist/release.sh b/dist/release.sh
index 53f21dcc..05be8404 100755
--- a/dist/release.sh
+++ b/dist/release.sh
@@ -11,7 +11,6 @@ cp -rv "comp" "${out}"
go generate ./...
go build -trimpath -v -o "${out}/bin/" -ldflags "-s -w -buildid= -extldflags '-static'
-X git.gensokyo.uk/security/fortify/internal.Version=${VERSION}
- -X git.gensokyo.uk/security/fortify/internal.Fortify=/usr/bin/fortify
-X git.gensokyo.uk/security/fortify/internal.Fsu=/usr/bin/fsu
-X main.Fmain=/usr/bin/fortify" ./...
diff --git a/internal/path.go b/internal/path.go
index 8c6a2e53..9f3e1cfc 100644
--- a/internal/path.go
+++ b/internal/path.go
@@ -3,8 +3,7 @@ package internal
import "path"
var (
- Fortify = compPoison
- Fsu = compPoison
+ Fsu = compPoison
)
func Path(p string) (string, bool) {
diff --git a/internal/proc/priv/shim/main.go b/internal/proc/priv/shim/main.go
index 91ff8d28..3ade2868 100644
--- a/internal/proc/priv/shim/main.go
+++ b/internal/proc/priv/shim/main.go
@@ -37,14 +37,6 @@ func Main() {
}
}
- // check path to fortify
- var fortifyPath string
- if p, ok := internal.Path(internal.Fortify); !ok {
- fmsg.Fatal("invalid fortify path, this copy of fortify is not compiled correctly")
- } else {
- fortifyPath = p
- }
-
// receive setup payload
var (
payload Payload
@@ -135,7 +127,7 @@ func Main() {
// bind fortify inside sandbox
innerSbin := path.Join(fst.Tmp, "sbin")
fortifyInnerPath := path.Join(innerSbin, "fortify")
- conf.Bind(fortifyPath, fortifyInnerPath)
+ conf.Bind(proc.MustExecutable(), fortifyInnerPath)
conf.Symlink(fortifyInnerPath, path.Join(innerSbin, "init"))
helper.BubblewrapName = payload.Exec[0] // resolved bwrap path by parent
diff --git a/internal/proc/priv/shim/manager.go b/internal/proc/priv/shim/manager.go
index 26b54925..1d1210b6 100644
--- a/internal/proc/priv/shim/manager.go
+++ b/internal/proc/priv/shim/manager.go
@@ -56,7 +56,7 @@ func (s *Shim) WaitFallback() chan error {
func (s *Shim) Start() (*time.Time, error) {
// prepare user switcher invocation
var fsu string
- if p, ok := internal.Check(internal.Fsu); !ok {
+ if p, ok := internal.Path(internal.Fsu); !ok {
fmsg.Fatal("invalid fsu path, this copy of fortify is not compiled correctly")
panic("unreachable")
} else {
diff --git a/internal/proc/self.go b/internal/proc/self.go
new file mode 100644
index 00000000..6dc92eb7
--- /dev/null
+++ b/internal/proc/self.go
@@ -0,0 +1,26 @@
+package proc
+
+import (
+ "os"
+ "sync"
+
+ "git.gensokyo.uk/security/fortify/internal/fmsg"
+)
+
+var (
+ executable string
+ executableOnce sync.Once
+)
+
+func copyExecutable() {
+ if name, err := os.Executable(); err != nil {
+ fmsg.Fatalf("cannot read executable path: %v", err)
+ } else {
+ executable = name
+ }
+}
+
+func MustExecutable() string {
+ executableOnce.Do(copyExecutable)
+ return executable
+}
diff --git a/package.nix b/package.nix
index 4c715ec0..8c8f8693 100644
--- a/package.nix
+++ b/package.nix
@@ -37,7 +37,6 @@ buildGoModule rec {
{
Version = "v${version}";
Fsu = "/run/wrappers/bin/fsu";
- Fortify = "${placeholder "out"}/bin/fortify";
};
# nix build environment does not allow acls