From 8318b2e325695a9004536d95a6b6a2c4cfce5151 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Fri, 29 May 2026 19:04:38 -0400 Subject: [PATCH] Attempt to fix unexpected EOF on Solaris --- daemon/2server.go | 10 +++++++--- daemon/2serverSolaris.go | 2 +- daemon/2serverUNIXGeneric.go | 18 +++++++++++++++--- daemon/2serverWindows.go | 18 +++++++++++++++--- wrappers/sanityCheck.go | 2 +- 5 files changed, 39 insertions(+), 11 deletions(-) diff --git a/daemon/2server.go b/daemon/2server.go index 92acc68..960b01f 100644 --- a/daemon/2server.go +++ b/daemon/2server.go @@ -2,6 +2,7 @@ package daemon import ( "crypto/sha256" + "errors" "io" "os" @@ -35,10 +36,13 @@ func (h *RCWService) EncryptRequest(decBytes []byte, reply *[]byte) error { } // getFileHash returns the SHA256 hash of the file at the given path. -func getFileHash(path string) []byte { - file, _ := os.Open(path) +func getFileHash(path string) ([]byte, error) { + file, err := os.Open(path) + if err != nil { + return nil, errors.New("unable to read path (" + path + ") for hashing: " + err.Error()) + } defer file.Close() hash := sha256.New() io.Copy(hash, file) - return hash.Sum(nil) + return hash.Sum(nil), nil } diff --git a/daemon/2serverSolaris.go b/daemon/2serverSolaris.go index 42f849d..620b558 100644 --- a/daemon/2serverSolaris.go +++ b/daemon/2serverSolaris.go @@ -2,4 +2,4 @@ package daemon -const pidPathFile = "execname" +const pidPathFile = "path/a.out" diff --git a/daemon/2serverUNIXGeneric.go b/daemon/2serverUNIXGeneric.go index 44a5dd8..5f75af8 100644 --- a/daemon/2serverUNIXGeneric.go +++ b/daemon/2serverUNIXGeneric.go @@ -24,12 +24,16 @@ func Start(password []byte) { globalPassword = password // register RCWService with the RPC package - if err := rpc.Register(&RCWService{}); err != nil { + err := rpc.Register(&RCWService{}) + if err != nil { log.Fatalf("Error registering RPC service: %v", err) } // store the hash of the daemon binary - daemonHash = getFileHash(binPath) + daemonHash, err = getFileHash(binPath) + if err != nil { + log.Fatalf("Error hashing daemon binary: %v", err) + } // listen on the Unix domain socket listener, err := net.Listen("unix", socketPath) @@ -80,7 +84,15 @@ func handleConn(conn net.Conn, sigChan chan os.Signal) { // check if the RPC call is coming from an identical binary and from the same user callingBinPath := pidToPath(ucred.PID) - if ucred.UID == strconv.Itoa(os.Getuid()) && bytes.Equal(getFileHash(callingBinPath), daemonHash) { + callingBinHash, err := getFileHash(callingBinPath) + if err != nil { + // calling binary hash failure + conn.Close() + log.Printf("Failed to hash calling binary: PID(%d), UID(%s), Path(%s) - %v", ucred.PID, ucred.UID, callingBinPath, err) + sigChan <- syscall.SIGTERM // this zeroizes globalPassword and triggers os.Exit(0) + return // explicitly return to avoid race + } + if ucred.UID == strconv.Itoa(os.Getuid()) && bytes.Equal(callingBinHash, daemonHash) { // valid client; hand off the connection to the RPC server rpc.ServeConn(conn) } else { diff --git a/daemon/2serverWindows.go b/daemon/2serverWindows.go index 3600a7b..e9d89eb 100644 --- a/daemon/2serverWindows.go +++ b/daemon/2serverWindows.go @@ -29,12 +29,16 @@ func Start(password []byte) { globalPassword = password // register RCWService with the RPC package - if err := rpc.Register(&RCWService{}); err != nil { + err := rpc.Register(&RCWService{}) + if err != nil { log.Fatalf("Error registering RPC service: %v", err) } // store the hash of the daemon binary - daemonHash = getFileHash(binPath) + daemonHash, err = getFileHash(binPath) + if err != nil { + log.Fatalf("Error hashing daemon binary: %v", err) + } // configure the named pipe pipeConfig := &winio.PipeConfig{ @@ -104,7 +108,15 @@ func handleConn(conn net.Conn, sigChan chan os.Signal) { // check if the RPC call is coming from an identical binary and from the same user callingBinPath := pidToPath(uint32(ucred.PID)) - if ucred.UID == user.User.Sid.String() && bytes.Equal(getFileHash(callingBinPath), daemonHash) { + callingBinHash, err := getFileHash(callingBinPath) + if err != nil { + // calling binary hash failure + conn.Close() + log.Printf("Failed to hash calling binary: PID(%d), UID(%s), Path(%s) - %v", ucred.PID, ucred.UID, callingBinPath, err) + sigChan <- os.Interrupt // this zeroizes globalPassword and triggers os.Exit(0) + return // explicitly return to avoid race + } + if ucred.UID == user.User.Sid.String() && bytes.Equal(callingBinHash, daemonHash) { rpc.ServeConn(conn) } else { // invalid client; close the connection w/o a response, diff --git a/wrappers/sanityCheck.go b/wrappers/sanityCheck.go index 2b9c3ec..1d312d0 100644 --- a/wrappers/sanityCheck.go +++ b/wrappers/sanityCheck.go @@ -20,7 +20,7 @@ func GenSanityCheck(path string, password []byte, zeroizePassword bool) error { func RunSanityCheck(path string, password []byte) error { encBytes, err := os.ReadFile(path) if err != nil { - return errors.New("Failed to read sanity check file (" + path + ")") + return errors.New("unable to read sanity check file (" + path + "): " + err.Error()) } decBytes, err := Decrypt(encBytes, password, false) if err == nil {