gvisor icon indicating copy to clipboard operation
gvisor copied to clipboard

vfs2 fail to create hard link for socket file

Open DarcySail opened this issue 4 years ago • 8 comments

Description

vfs2 fail to creat hard link for socket file, the following code can reproduce the case on the master branch latest commit. but the same code works fine in vfs1.

#include <stdio.h>
#include <sys/socket.h>
#include <sys/un.h>

int main() {
    int fd;
    struct sockaddr_un addr;
    int ret;
    char buff[8192];
    struct sockaddr_un from;
    int len;
    socklen_t fromlen = sizeof(from);

    if ((fd = socket(PF_UNIX, SOCK_DGRAM, 0)) < 0) {
        perror("socket");
    }

    memset(&addr, 0, sizeof(addr));
    addr.sun_family = AF_UNIX;
    strcpy(addr.sun_path, "server.sock");
    unlink("server.sock");
    if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
        perror("bind");
    }

    ret = link("server.sock", "./tmp");
    if (ret) {
        perror("link");
    }

    if (fd >= 0) {
        close(fd);
    }

    return 0;
}

Steps to reproduce

No response

runsc version

No response

docker version (if using docker)

No response

uname

No response

kubectl (if using Kubernetes)

No response

repo state (if built from source)

No response

runsc debug logs (if available)

No response

DarcySail avatar Sep 14 '21 03:09 DarcySail

 0  0x00000000007a9d9b in gvisor.dev/gvisor/pkg/p9.(*clientFile).Link     at pkg/p9/client_file.go:633  1  0x0000000000c36c2f in gvisor.dev/gvisor/pkg/sentry/fsimpl/gofer.p9file.link     at pkg/sentry/fsimpl/gofer/p9file.go:188  2  0x0000000000c49d14 in gvisor.dev/gvisor/pkg/sentry/fsimpl/gofer.(*filesystem).LinkAt.func1     at pkg/sentry/fsimpl/gofer/filesystem.go:679  3  0x0000000000c2184a in gvisor.dev/gvisor/pkg/sentry/fsimpl/gofer.(*filesystem).doCreateAt     at pkg/sentry/fsimpl/gofer/filesystem.go:416  4  0x0000000000c23758 in gvisor.dev/gvisor/pkg/sentry/fsimpl/gofer.(*filesystem).LinkAt     at pkg/sentry/fsimpl/gofer/filesystem.go:659  5  0x0000000000784a1d in gvisor.dev/gvisor/pkg/sentry/vfs.(*VirtualFilesystem).LinkAt     at pkg/sentry/vfs/vfs.go:291  6  0x0000000000e319b7 in gvisor.dev/gvisor/pkg/sentry/syscalls/linux/vfs2.linkat     at pkg/sentry/syscalls/linux/vfs2/filesystem.go:71 ?  7  0x0000000000e3166e in gvisor.dev/gvisor/pkg/sentry/syscalls/linux/vfs2.Linkat     at pkg/sentry/syscalls/linux/vfs2/filesystem.go:40

DarcySail avatar Sep 14 '21 05:09 DarcySail

@ayushr2 could you take a look?

hbhasker avatar Sep 15 '21 01:09 hbhasker

here is my fix: https://github.com/google/gvisor/pull/6588

DarcySail avatar Sep 15 '21 11:09 DarcySail

A friendly reminder that this issue had no activity for 120 days.

github-actions[bot] avatar Sep 13 '23 00:09 github-actions[bot]

This issue has been closed due to lack of activity.

github-actions[bot] avatar Dec 13 '23 00:12 github-actions[bot]

This issue is still exists.

ayushr2 avatar Dec 14 '23 05:12 ayushr2

A friendly reminder that this issue had no activity for 120 days.

github-actions[bot] avatar Apr 14 '24 00:04 github-actions[bot]

A friendly reminder that this issue had no activity for 120 days.

github-actions[bot] avatar Aug 14 '24 00:08 github-actions[bot]