diff --git a/pkg/sentry/fs/proc/fds.go b/pkg/sentry/fs/proc/fds.go index cca8f874c..dada8f982 100644 --- a/pkg/sentry/fs/proc/fds.go +++ b/pkg/sentry/fs/proc/fds.go @@ -94,7 +94,7 @@ type fd struct { *fs.File } -// newFD returns a new fd based on an existing file. +// newFd returns a new fd based on an existing file. // // This inherits one reference to the file. func newFd(t *kernel.Task, f *fs.File, msrc *fs.MountSource) *fs.Inode { @@ -131,6 +131,11 @@ func (f *fd) Truncate(context.Context, *fs.Inode, int64) error { return nil } +func (f *fd) Release(ctx context.Context) { + f.Symlink.Release(ctx) + f.File.DecRef() +} + // Close releases the reference on the file. func (f *fd) Close() error { f.DecRef() @@ -204,13 +209,14 @@ func (f *fdDir) DeprecatedReaddir(ctx context.Context, dirCtx *fs.DirCtx, offset type fdInfo struct { ramfs.File + file *fs.File flags fs.FileFlags fdFlags kernel.FDFlags } // newFdInfo returns a new fdInfo based on an existing file. func newFdInfo(t *kernel.Task, file *fs.File, fdFlags kernel.FDFlags, msrc *fs.MountSource) *fs.Inode { - fdi := &fdInfo{flags: file.Flags(), fdFlags: fdFlags} + fdi := &fdInfo{file: file, flags: file.Flags(), fdFlags: fdFlags} fdi.InitFile(t, fs.RootOwner, fs.FilePermissions{User: fs.PermMask{Read: true}}) // TODO: Get pos, locks, and other data. For now we only // have flags. @@ -231,6 +237,11 @@ func (*fdInfo) Truncate(ctx context.Context, inode *fs.Inode, size int64) error return ramfs.ErrInvalidOp } +func (f *fdInfo) Release(ctx context.Context) { + f.File.Release(ctx) + f.file.DecRef() +} + // fdInfoDir implements /proc/TID/fdinfo. It embeds an fdDir, but overrides // Lookup and Readdir. //