fs: returns EBADF on negative file descriptor (#1391)

This changes file descriptors from uint32 to int32 and the
corresponding file table to reject negative values. This ensures
invalid values aren't mistaken for very large descriptor entries, which
can use a lot of memory as the table implementation isn't designed to
be sparse.

See https://pubs.opengroup.org/onlinepubs/9699919799/functions/dirfd.html#tag_16_90

Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
Crypt Keeper
2023-04-21 16:08:35 +02:00
committed by GitHub
parent 010f0a93a2
commit 40341af448
16 changed files with 306 additions and 226 deletions

View File

@@ -142,7 +142,7 @@ func (m *ModuleInstance) setExitCode(exitCode uint32, flag exitCodeFlag) bool {
// Multiple calls to this function is safe.
func (m *ModuleInstance) ensureResourcesClosed(ctx context.Context) (err error) {
if sysCtx := m.Sys; sysCtx != nil { // nil if from HostModuleBuilder
if err = sysCtx.FS().Close(ctx); err != nil {
if err = sysCtx.FS().Close(); err != nil {
return err
}
m.Sys = nil