mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Combine file mode and isDir arguments
Updates #1035 PiperOrigin-RevId: 303021328
This commit is contained in:
committed by
gVisor bot
parent
ce0a69ea97
commit
de694e5484
@@ -41,7 +41,7 @@ func stepLocked(rp *vfs.ResolvingPath, d *dentry) (*dentry, error) {
|
||||
if !d.inode.isDir() {
|
||||
return nil, syserror.ENOTDIR
|
||||
}
|
||||
if err := d.inode.checkPermissions(rp.Credentials(), vfs.MayExec, true); err != nil {
|
||||
if err := d.inode.checkPermissions(rp.Credentials(), vfs.MayExec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
afterSymlink:
|
||||
@@ -125,7 +125,7 @@ func (fs *filesystem) doCreateAt(rp *vfs.ResolvingPath, dir bool, create func(pa
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := parent.inode.checkPermissions(rp.Credentials(), vfs.MayWrite|vfs.MayExec, true /* isDir */); err != nil {
|
||||
if err := parent.inode.checkPermissions(rp.Credentials(), vfs.MayWrite|vfs.MayExec); err != nil {
|
||||
return err
|
||||
}
|
||||
name := rp.Component()
|
||||
@@ -163,7 +163,7 @@ func (fs *filesystem) AccessAt(ctx context.Context, rp *vfs.ResolvingPath, creds
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return d.inode.checkPermissions(creds, ats, d.inode.isDir())
|
||||
return d.inode.checkPermissions(creds, ats)
|
||||
}
|
||||
|
||||
// GetDentryAt implements vfs.FilesystemImpl.GetDentryAt.
|
||||
@@ -178,7 +178,7 @@ func (fs *filesystem) GetDentryAt(ctx context.Context, rp *vfs.ResolvingPath, op
|
||||
if !d.inode.isDir() {
|
||||
return nil, syserror.ENOTDIR
|
||||
}
|
||||
if err := d.inode.checkPermissions(rp.Credentials(), vfs.MayExec, true /* isDir */); err != nil {
|
||||
if err := d.inode.checkPermissions(rp.Credentials(), vfs.MayExec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
@@ -301,7 +301,7 @@ afterTrailingSymlink:
|
||||
return nil, err
|
||||
}
|
||||
// Check for search permission in the parent directory.
|
||||
if err := parent.inode.checkPermissions(rp.Credentials(), vfs.MayExec, true); err != nil {
|
||||
if err := parent.inode.checkPermissions(rp.Credentials(), vfs.MayExec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Reject attempts to open directories with O_CREAT.
|
||||
@@ -316,7 +316,7 @@ afterTrailingSymlink:
|
||||
child, err := stepLocked(rp, parent)
|
||||
if err == syserror.ENOENT {
|
||||
// Already checked for searchability above; now check for writability.
|
||||
if err := parent.inode.checkPermissions(rp.Credentials(), vfs.MayWrite, true); err != nil {
|
||||
if err := parent.inode.checkPermissions(rp.Credentials(), vfs.MayWrite); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rp.Mount().CheckBeginWrite(); err != nil {
|
||||
@@ -347,7 +347,7 @@ afterTrailingSymlink:
|
||||
func (d *dentry) open(ctx context.Context, rp *vfs.ResolvingPath, opts *vfs.OpenOptions, afterCreate bool) (*vfs.FileDescription, error) {
|
||||
ats := vfs.AccessTypesForOpenFlags(opts)
|
||||
if !afterCreate {
|
||||
if err := d.inode.checkPermissions(rp.Credentials(), ats, d.inode.isDir()); err != nil {
|
||||
if err := d.inode.checkPermissions(rp.Credentials(), ats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
@@ -428,7 +428,7 @@ func (fs *filesystem) RenameAt(ctx context.Context, rp *vfs.ResolvingPath, oldPa
|
||||
defer mnt.EndWrite()
|
||||
|
||||
oldParent := oldParentVD.Dentry().Impl().(*dentry)
|
||||
if err := oldParent.inode.checkPermissions(rp.Credentials(), vfs.MayWrite|vfs.MayExec, true /* isDir */); err != nil {
|
||||
if err := oldParent.inode.checkPermissions(rp.Credentials(), vfs.MayWrite|vfs.MayExec); err != nil {
|
||||
return err
|
||||
}
|
||||
// Call vfs.Dentry.Child() instead of stepLocked() or rp.ResolveChild(),
|
||||
@@ -445,7 +445,7 @@ func (fs *filesystem) RenameAt(ctx context.Context, rp *vfs.ResolvingPath, oldPa
|
||||
}
|
||||
if oldParent != newParent {
|
||||
// Writability is needed to change renamed's "..".
|
||||
if err := renamed.inode.checkPermissions(rp.Credentials(), vfs.MayWrite, true /* isDir */); err != nil {
|
||||
if err := renamed.inode.checkPermissions(rp.Credentials(), vfs.MayWrite); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -455,7 +455,7 @@ func (fs *filesystem) RenameAt(ctx context.Context, rp *vfs.ResolvingPath, oldPa
|
||||
}
|
||||
}
|
||||
|
||||
if err := newParent.inode.checkPermissions(rp.Credentials(), vfs.MayWrite|vfs.MayExec, true /* isDir */); err != nil {
|
||||
if err := newParent.inode.checkPermissions(rp.Credentials(), vfs.MayWrite|vfs.MayExec); err != nil {
|
||||
return err
|
||||
}
|
||||
replacedVFSD := newParent.vfsd.Child(newName)
|
||||
@@ -528,7 +528,7 @@ func (fs *filesystem) RmdirAt(ctx context.Context, rp *vfs.ResolvingPath) error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := parent.inode.checkPermissions(rp.Credentials(), vfs.MayWrite|vfs.MayExec, true /* isDir */); err != nil {
|
||||
if err := parent.inode.checkPermissions(rp.Credentials(), vfs.MayWrite|vfs.MayExec); err != nil {
|
||||
return err
|
||||
}
|
||||
name := rp.Component()
|
||||
@@ -621,7 +621,7 @@ func (fs *filesystem) UnlinkAt(ctx context.Context, rp *vfs.ResolvingPath) error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := parent.inode.checkPermissions(rp.Credentials(), vfs.MayWrite|vfs.MayExec, true /* isDir */); err != nil {
|
||||
if err := parent.inode.checkPermissions(rp.Credentials(), vfs.MayWrite|vfs.MayExec); err != nil {
|
||||
return err
|
||||
}
|
||||
name := rp.Component()
|
||||
|
||||
@@ -245,8 +245,9 @@ func (i *inode) decRef() {
|
||||
}
|
||||
}
|
||||
|
||||
func (i *inode) checkPermissions(creds *auth.Credentials, ats vfs.AccessTypes, isDir bool) error {
|
||||
return vfs.GenericCheckPermissions(creds, ats, isDir, uint16(atomic.LoadUint32(&i.mode)), auth.KUID(atomic.LoadUint32(&i.uid)), auth.KGID(atomic.LoadUint32(&i.gid)))
|
||||
func (i *inode) checkPermissions(creds *auth.Credentials, ats vfs.AccessTypes) error {
|
||||
mode := linux.FileMode(atomic.LoadUint32(&i.mode))
|
||||
return vfs.GenericCheckPermissions(creds, ats, mode, auth.KUID(atomic.LoadUint32(&i.uid)), auth.KGID(atomic.LoadUint32(&i.gid)))
|
||||
}
|
||||
|
||||
// Go won't inline this function, and returning linux.Statx (which is quite
|
||||
@@ -299,7 +300,8 @@ func (i *inode) setStat(ctx context.Context, creds *auth.Credentials, stat *linu
|
||||
if stat.Mask&^(linux.STATX_MODE|linux.STATX_UID|linux.STATX_GID|linux.STATX_ATIME|linux.STATX_MTIME|linux.STATX_CTIME|linux.STATX_SIZE) != 0 {
|
||||
return syserror.EPERM
|
||||
}
|
||||
if err := vfs.CheckSetStat(ctx, creds, stat, uint16(atomic.LoadUint32(&i.mode))&^linux.S_IFMT, auth.KUID(atomic.LoadUint32(&i.uid)), auth.KGID(atomic.LoadUint32(&i.gid))); err != nil {
|
||||
mode := linux.FileMode(atomic.LoadUint32(&i.mode))
|
||||
if err := vfs.CheckSetStat(ctx, creds, stat, mode, auth.KUID(atomic.LoadUint32(&i.uid)), auth.KGID(atomic.LoadUint32(&i.gid))); err != nil {
|
||||
return err
|
||||
}
|
||||
i.mu.Lock()
|
||||
|
||||
Reference in New Issue
Block a user