google / gvisor

Application Kernel for Containers
https://gvisor.dev
Apache License 2.0
15.82k stars 1.3k forks source link

vfs2 fail to create hard link for socket file #6577

Open DarcySail opened 3 years ago

DarcySail commented 3 years ago

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 commented 3 years ago

 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

hbhasker commented 3 years ago

@ayushr2 could you take a look?

DarcySail commented 3 years ago

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

github-actions[bot] commented 1 year ago

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

github-actions[bot] commented 11 months ago

This issue has been closed due to lack of activity.

ayushr2 commented 11 months ago

This issue is still exists.

github-actions[bot] commented 6 months ago

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

github-actions[bot] commented 2 months ago

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