Check hard link target's mount compatibility before kernfs.Dentry cast.

Reported-by: syzbot+65dcd89bab032fdb8ac8@syzkaller.appspotmail.com
PiperOrigin-RevId: 507832777
This commit is contained in:
Ayush Ranjan
2023-02-07 11:17:27 -08:00
committed by gVisor bot
parent be5314c5a6
commit 8373fb5db8
+5 -5
View File
@@ -362,8 +362,9 @@ func (fs *Filesystem) LinkAt(ctx context.Context, rp *vfs.ResolvingPath, vd vfs.
return err
}
parent.dirMu.Lock()
defer parent.dirMu.Unlock()
if rp.Mount() != vd.Mount() {
return linuxerr.EXDEV
}
inode := vd.Dentry().Impl().(*Dentry).Inode()
if inode.Mode().IsDir() {
return linuxerr.EPERM
@@ -371,6 +372,8 @@ func (fs *Filesystem) LinkAt(ctx context.Context, rp *vfs.ResolvingPath, vd vfs.
if err := vfs.MayLink(rp.Credentials(), inode.Mode(), inode.UID(), inode.GID()); err != nil {
return err
}
parent.dirMu.Lock()
defer parent.dirMu.Unlock()
pc := rp.Component()
if err := checkCreateLocked(ctx, rp.Credentials(), pc, parent); err != nil {
return err
@@ -378,9 +381,6 @@ func (fs *Filesystem) LinkAt(ctx context.Context, rp *vfs.ResolvingPath, vd vfs.
if rp.MustBeDir() {
return linuxerr.ENOENT
}
if rp.Mount() != vd.Mount() {
return linuxerr.EXDEV
}
if err := rp.Mount().CheckBeginWrite(); err != nil {
return err
}