mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Remove various uses of 'whitelist'
Updates #2972 PiperOrigin-RevId: 317113059
This commit is contained in:
committed by
gVisor bot
parent
07ff909e76
commit
3970c12743
@@ -767,7 +767,7 @@ func TestSimpleFilter(t *testing.T) {
|
||||
expectedRet: 0,
|
||||
},
|
||||
{
|
||||
desc: "Whitelisted syscall is allowed",
|
||||
desc: "Allowed syscall is indeed allowed",
|
||||
seccompData: seccompData{nr: 231 /* __NR_exit_group */, arch: 0xc000003e},
|
||||
expectedRet: 0x7fff0000,
|
||||
},
|
||||
|
||||
@@ -312,8 +312,9 @@ func HostFeatureSet() *FeatureSet {
|
||||
}
|
||||
}
|
||||
|
||||
// Reads bogomips from host /proc/cpuinfo. Must run before whitelisting.
|
||||
// This value is used to create the fake /proc/cpuinfo from a FeatureSet.
|
||||
// Reads bogomips from host /proc/cpuinfo. Must run before syscall filter
|
||||
// installation. This value is used to create the fake /proc/cpuinfo from a
|
||||
// FeatureSet.
|
||||
func initCPUInfo() {
|
||||
cpuinfob, err := ioutil.ReadFile("/proc/cpuinfo")
|
||||
if err != nil {
|
||||
|
||||
@@ -1057,9 +1057,9 @@ func HostFeatureSet() *FeatureSet {
|
||||
}
|
||||
}
|
||||
|
||||
// Reads max cpu frequency from host /proc/cpuinfo. Must run before
|
||||
// whitelisting. This value is used to create the fake /proc/cpuinfo from a
|
||||
// FeatureSet.
|
||||
// Reads max cpu frequency from host /proc/cpuinfo. Must run before syscall
|
||||
// filter installation. This value is used to create the fake /proc/cpuinfo
|
||||
// from a FeatureSet.
|
||||
func initCPUFreq() {
|
||||
cpuinfob, err := ioutil.ReadFile("/proc/cpuinfo")
|
||||
if err != nil {
|
||||
@@ -1106,7 +1106,6 @@ func initFeaturesFromString() {
|
||||
}
|
||||
|
||||
func init() {
|
||||
// initCpuFreq must be run before whitelists are enabled.
|
||||
initCPUFreq()
|
||||
initFeaturesFromString()
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ func (a AllowValue) String() (s string) {
|
||||
return fmt.Sprintf("%#x ", uintptr(a))
|
||||
}
|
||||
|
||||
// Rule stores the whitelist of syscall arguments.
|
||||
// Rule stores the allowed syscall arguments.
|
||||
//
|
||||
// For example:
|
||||
// rule := Rule {
|
||||
@@ -82,7 +82,7 @@ func (r Rule) String() (s string) {
|
||||
return
|
||||
}
|
||||
|
||||
// SyscallRules stores a map of OR'ed whitelist rules indexed by the syscall number.
|
||||
// SyscallRules stores a map of OR'ed argument rules indexed by the syscall number.
|
||||
// If the 'Rules' is empty, we treat it as any argument is allowed.
|
||||
//
|
||||
// For example:
|
||||
|
||||
@@ -87,20 +87,6 @@ func RegisterFilesystem(f Filesystem) {
|
||||
filesystems.registered[f.Name()] = f
|
||||
}
|
||||
|
||||
// UnregisterFilesystem removes a file system from the global set. To keep the
|
||||
// file system set compatible with save/restore, UnregisterFilesystem must be
|
||||
// called before save/restore methods.
|
||||
//
|
||||
// For instance, packages may unregister their file system after it is mounted.
|
||||
// This makes sense for pseudo file systems that should not be visible or
|
||||
// mountable. See whitelistfs in fs/host/fs.go for one example.
|
||||
func UnregisterFilesystem(name string) {
|
||||
filesystems.mu.Lock()
|
||||
defer filesystems.mu.Unlock()
|
||||
|
||||
delete(filesystems.registered, name)
|
||||
}
|
||||
|
||||
// FindFilesystem returns a Filesystem registered at name or (nil, false) if name
|
||||
// is not a file system type that can be found in /proc/filesystems.
|
||||
func FindFilesystem(name string) (Filesystem, bool) {
|
||||
|
||||
@@ -476,8 +476,9 @@ func (i *inode) open(ctx context.Context, d *vfs.Dentry, mnt *vfs.Mount, flags u
|
||||
return unixsocket.NewFileDescription(ep, ep.Type(), flags, mnt, d, &i.locks)
|
||||
}
|
||||
|
||||
// TODO(gvisor.dev/issue/1672): Whitelist specific file types here, so that
|
||||
// we don't allow importing arbitrary file types without proper support.
|
||||
// TODO(gvisor.dev/issue/1672): Allow only specific file types here, so
|
||||
// that we don't allow importing arbitrary file types without proper
|
||||
// support.
|
||||
if i.isTTY {
|
||||
fd := &TTYFileDescription{
|
||||
fileDescription: fileDescription{inode: i},
|
||||
|
||||
@@ -324,7 +324,7 @@ func (s *socketOpsCommon) GetSockOpt(t *kernel.Task, level int, name int, outPtr
|
||||
return nil, syserr.ErrInvalidArgument
|
||||
}
|
||||
|
||||
// Whitelist options and constrain option length.
|
||||
// Only allow known and safe options.
|
||||
optlen := getSockOptLen(t, level, name)
|
||||
switch level {
|
||||
case linux.SOL_IP:
|
||||
@@ -369,7 +369,7 @@ func (s *socketOpsCommon) GetSockOpt(t *kernel.Task, level int, name int, outPtr
|
||||
|
||||
// SetSockOpt implements socket.Socket.SetSockOpt.
|
||||
func (s *socketOpsCommon) SetSockOpt(t *kernel.Task, level int, name int, opt []byte) *syserr.Error {
|
||||
// Whitelist options and constrain option length.
|
||||
// Only allow known and safe options.
|
||||
optlen := setSockOptLen(t, level, name)
|
||||
switch level {
|
||||
case linux.SOL_IP:
|
||||
@@ -415,7 +415,7 @@ func (s *socketOpsCommon) SetSockOpt(t *kernel.Task, level int, name int, opt []
|
||||
|
||||
// RecvMsg implements socket.Socket.RecvMsg.
|
||||
func (s *socketOpsCommon) RecvMsg(t *kernel.Task, dst usermem.IOSequence, flags int, haveDeadline bool, deadline ktime.Time, senderRequested bool, controlLen uint64) (int, int, linux.SockAddr, uint32, socket.ControlMessages, *syserr.Error) {
|
||||
// Whitelist flags.
|
||||
// Only allow known and safe flags.
|
||||
//
|
||||
// FIXME(jamieliu): We can't support MSG_ERRQUEUE because it uses ancillary
|
||||
// messages that gvisor/pkg/tcpip/transport/unix doesn't understand. Kill the
|
||||
@@ -537,7 +537,7 @@ func (s *socketOpsCommon) RecvMsg(t *kernel.Task, dst usermem.IOSequence, flags
|
||||
|
||||
// SendMsg implements socket.Socket.SendMsg.
|
||||
func (s *socketOpsCommon) SendMsg(t *kernel.Task, src usermem.IOSequence, to []byte, flags int, haveDeadline bool, deadline ktime.Time, controlMessages socket.ControlMessages) (int, *syserr.Error) {
|
||||
// Whitelist flags.
|
||||
// Only allow known and safe flags.
|
||||
if flags&^(syscall.MSG_DONTWAIT|syscall.MSG_EOR|syscall.MSG_FASTOPEN|syscall.MSG_MORE|syscall.MSG_NOSIGNAL) != 0 {
|
||||
return 0, syserr.ErrInvalidArgument
|
||||
}
|
||||
|
||||
@@ -169,8 +169,6 @@ This construction, which is essentially a type-safe analogue to Linux's
|
||||
|
||||
- binder, which is similarly far too incomplete to use.
|
||||
|
||||
- whitelistfs, which we are already actively attempting to remove.
|
||||
|
||||
- Save/restore. For instance, it is unclear if the current implementation of
|
||||
the `state` package supports the inheritance pattern described above.
|
||||
|
||||
|
||||
@@ -73,9 +73,10 @@ TEST_F(XattrTest, XattrLargeName) {
|
||||
std::string name = "user.";
|
||||
name += std::string(XATTR_NAME_MAX - name.length(), 'a');
|
||||
|
||||
// An xattr should be whitelisted before it can be accessed--do not allow
|
||||
// arbitrary xattrs to be read/written in gVisor.
|
||||
if (!IsRunningOnGvisor()) {
|
||||
// In gVisor, access to xattrs is controlled with an explicit list of
|
||||
// allowed names. This name isn't going to be configured to allow access, so
|
||||
// don't test it.
|
||||
EXPECT_THAT(setxattr(path, name.c_str(), nullptr, 0, /*flags=*/0),
|
||||
SyscallSucceeds());
|
||||
EXPECT_THAT(getxattr(path, name.c_str(), nullptr, 0),
|
||||
|
||||
+16
-11
@@ -27,10 +27,15 @@ type matcher interface {
|
||||
ShouldReport(d analysis.Diagnostic, fs *token.FileSet) bool
|
||||
}
|
||||
|
||||
// pathRegexps excludes explicit paths.
|
||||
// pathRegexps filters explicit paths.
|
||||
type pathRegexps struct {
|
||||
expr []*regexp.Regexp
|
||||
whitelist bool
|
||||
expr []*regexp.Regexp
|
||||
|
||||
// include, if true, indicates that paths matching any regexp in expr
|
||||
// match.
|
||||
//
|
||||
// If false, paths matching no regexps in expr match.
|
||||
include bool
|
||||
}
|
||||
|
||||
// buildRegexps builds a list of regular expressions.
|
||||
@@ -49,33 +54,33 @@ func (p *pathRegexps) ShouldReport(d analysis.Diagnostic, fs *token.FileSet) boo
|
||||
fullPos := fs.Position(d.Pos).String()
|
||||
for _, path := range p.expr {
|
||||
if path.MatchString(fullPos) {
|
||||
return p.whitelist
|
||||
return p.include
|
||||
}
|
||||
}
|
||||
return !p.whitelist
|
||||
return !p.include
|
||||
}
|
||||
|
||||
// internalExcluded excludes specific internal paths.
|
||||
func internalExcluded(paths ...string) *pathRegexps {
|
||||
return &pathRegexps{
|
||||
expr: buildRegexps(internalPrefix, paths...),
|
||||
whitelist: false,
|
||||
expr: buildRegexps(internalPrefix, paths...),
|
||||
include: false,
|
||||
}
|
||||
}
|
||||
|
||||
// excludedExcluded excludes specific external paths.
|
||||
func externalExcluded(paths ...string) *pathRegexps {
|
||||
return &pathRegexps{
|
||||
expr: buildRegexps(externalPrefix, paths...),
|
||||
whitelist: false,
|
||||
expr: buildRegexps(externalPrefix, paths...),
|
||||
include: false,
|
||||
}
|
||||
}
|
||||
|
||||
// internalMatches returns a path matcher for internal packages.
|
||||
func internalMatches() *pathRegexps {
|
||||
return &pathRegexps{
|
||||
expr: buildRegexps(internalPrefix, ".*"),
|
||||
whitelist: true,
|
||||
expr: buildRegexps(internalPrefix, ".*"),
|
||||
include: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user