summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fsimpl/devtmpfs/devtmpfs.go
diff options
context:
space:
mode:
authorNicolas Lacasse <nlacasse@google.com>2020-08-21 12:08:25 -0700
committergVisor bot <gvisor-bot@google.com>2020-08-21 12:10:14 -0700
commit2c422b7f21b3503e9b1ab52bdf8f0de7fcf4b8ce (patch)
treed544118fed7f4d10406c0b329696278311681761 /pkg/sentry/fsimpl/devtmpfs/devtmpfs.go
parentc24db90be5cb4d81e71e7923fe85740721ec9d1e (diff)
Fix parent directory creation in CreateDeviceFile.
It was not properly creating recursive directories. Added tests for this case. Updates #1196 PiperOrigin-RevId: 327850811
Diffstat (limited to 'pkg/sentry/fsimpl/devtmpfs/devtmpfs.go')
-rw-r--r--pkg/sentry/fsimpl/devtmpfs/devtmpfs.go13
1 files changed, 6 insertions, 7 deletions
diff --git a/pkg/sentry/fsimpl/devtmpfs/devtmpfs.go b/pkg/sentry/fsimpl/devtmpfs/devtmpfs.go
index 2ed5fa8a9..52f44f66d 100644
--- a/pkg/sentry/fsimpl/devtmpfs/devtmpfs.go
+++ b/pkg/sentry/fsimpl/devtmpfs/devtmpfs.go
@@ -18,6 +18,7 @@ package devtmpfs
import (
"fmt"
+ "path"
"gvisor.dev/gvisor/pkg/abi/linux"
"gvisor.dev/gvisor/pkg/context"
@@ -150,13 +151,11 @@ func (a *Accessor) CreateDeviceFile(ctx context.Context, pathname string, kind v
// Create any parent directories. See
// devtmpfs.c:handle_create()=>path_create().
- for it := fspath.Parse(pathname).Begin; it.NextOk(); it = it.Next() {
- pop := a.pathOperationAt(it.String())
- if err := a.vfsObj.MkdirAt(actx, a.creds, pop, &vfs.MkdirOptions{
- Mode: 0755,
- }); err != nil {
- return fmt.Errorf("failed to create directory %q: %v", it.String(), err)
- }
+ parent := path.Dir(pathname)
+ if err := a.vfsObj.MkdirAllAt(ctx, parent, a.root, a.creds, &vfs.MkdirOptions{
+ Mode: 0755,
+ }); err != nil {
+ return fmt.Errorf("failed to create device parent directory %q: %v", parent, err)
}
// NOTE: Linux's devtmpfs refuses to automatically delete files it didn't