google / gvisor

Application Kernel for Containers

Home Page:https://gvisor.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

vfs2 fail to create hard link for socket file

DarcySail opened this issue · 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

 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

@ayushr2 could you take a look?

here is my fix:
#6588

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

This issue has been closed due to lack of activity.

This issue is still exists.

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