Files
nomad/command/agent/host/windows.go
Tim Gross 110d93ab25 windows: remove LazyDLL calls for system modules (#19925)
On Windows, Nomad uses `syscall.NewLazyDLL` and `syscall.LoadDLL` functions to
load a few system DLL files, which does not prevent DLL hijacking
attacks. Hypothetically a local attacker on the client host that can place an
abusive library in a specific location could use this to escalate privileges to
the Nomad process. Although this attack does not fall within the Nomad security
model, it doesn't hurt to follow good practices here.

We can remove two of these DLL loads by using wrapper functions provided by the
stdlib in `x/sys/windows`

Co-authored-by: dduzgun-security <deniz.duzgun@hashicorp.com>
2024-02-09 08:47:48 -05:00

61 lines
891 B
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
//go:build windows
// +build windows
package host
import (
"os"
"syscall"
"golang.org/x/sys/windows"
)
func uname() string {
return ""
}
func resolvConf() string {
return ""
}
func etcHosts() string {
return ""
}
func mountedPaths() (disks []string) {
for _, c := range "ABCDEFGHIJKLMNOPQRSTUVWXYZ" {
d := string(c) + ":\\"
_, err := os.Stat(d)
if err == nil {
disks = append(disks, d)
}
}
return disks
}
type df struct {
size uint64 // "systemFree" less quotas
avail uint64
systemFree uint64
}
func makeDf(path string) (*df, error) {
df := &df{}
err := windows.GetDiskFreeSpaceEx(
syscall.StringToUTF16Ptr(path),
&df.avail, &df.size, &df.systemFree)
return df, err
}
func (d *df) total() uint64 {
return d.size
}
func (d *df) available() uint64 {
return d.avail
}