Re: `Unix-domain socket path "..." is too long (maximum 107 bytes)` can we change that?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Aug 22, 2024 at 10:09:56PM +0300, Peter Pentchev wrote:
> On Thu, Aug 22, 2024 at 05:06:53PM +0200, Florian Weimer wrote:
> > * Lennart Poettering:
> > 
> > > On Mi, 07.08.24 13:09, Vít Ondruch (vondruch@xxxxxxxxxx) wrote:
> > >
> > >> With new RPM, I hit the limit in two packages:
> > >>
> > >> https://koschei.fedoraproject.org/package/rubygem-abrt
> > >>
> > >> https://koschei.fedoraproject.org/package/rubygem-pg
> > >>
> > >>
> > >> I have read:
> > >>
> > >> https://unix.stackexchange.com/questions/367008/why-is-socket-path-length-limited-to-a-hundred-chars
> > >>
> > >> https://stackoverflow.com/questions/34829600/why-is-the-maximal-path-length-allowed-for-unix-sockets-on-linux-108
> > >>
> > >>
> > >> But I still wonder why we should live with such limitation in 21st century.
> > >
> > > You don't really have to live with such a limitation. In systemd we
> > > have code that works around this limitation via O_PATH. i.e. when
> > > connect()ing you first open the socket inode with O_PATH, and then you
> > > fire the connect() specifying /proc/self/fd/<fd> as path. That always
> > > fits into the 108ch limit.
> > 
> > Do you think this is useful more generally?  What about opening files
> > with names longer than PATH_MAX?
> > 
> > > bind()ing to an overly long unix socket path is also doable, but
> > > harder (since you cannot O_PATH on an inode that doesn't exist
> > > yet). The way I'd do it is via chdir() to the dir of the target path
> > > and binding to a relative path then. But chdir() is of course icky,
> > > since it's a global property of a process, hence will affect all
> > > threads. Hence, maybe do this in a short-lived forked off process.
> > 
> > I would have expected that it's possible to use a directory descriptor
> > under /proc/self/fd as the base, but that doesn't seem to work for some
> > reason.
> 
> I think the reason is O_PATH - bind(2) is not among the syscalls that
> it is documented to allow. However, see the attached program that
> creates a subdirectory with a long name in the current working
> directory, opens it without O_PATH, but with O_DIRECTORY, and then
> binds a Unix-domain socket to /proc/self/fd/N; it works for me at
> least on Debian testing and a month-or-two-old Fedora pre-42 Rawhide.
> ("Works for me" in the sense that "cd this-...; nc -v -U meow" says
> that it has connected to the Unix-domain socket; of course, the program
> does not attempt to communicate with connected clients)

...and of course I forgot to attach the program, did I not...

> > You could also use a long-lived service thread that has called
> > unshare(CLONE_FS), so that it has its own current directory.  This is a
> > bit iffy because glibc won't know about it, but it's already used by
> > some popular file servers, so it should be okay.  I've posted a patch
> > that implements a proper NPTL facility for this, but it met with a
> > surprising amount of resistance.  I suppose I could dust it off and
> > repost it.
> 
> That might actually work, yeah.
> 
> G'luck,
> Peter
> 
> -- 
> Peter Pentchev  roam@xxxxxxxxxxx roam@xxxxxxxxxx peter@xxxxxxxxxxxxxx
> PGP key:        https://www.ringlet.net/roam/roam.key.asc
> Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13



> -- 
> _______________________________________________
> devel mailing list -- devel@xxxxxxxxxxxxxxxxxxxxxxx
> To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxxxxxxxx
> Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
> List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
> List Archives: https://lists.fedoraproject.org/archives/list/devel@xxxxxxxxxxxxxxxxxxxxxxx
> Do not reply to spam, report it: https://pagure.io/fedora-infrastructure/new_issue


-- 
-- 
Peter Pentchev  roam@xxxxxxxxxxx roam@xxxxxxxxxx peter@xxxxxxxxxxxxxx
PGP key:        https://www.ringlet.net/roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/un.h>

#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>

#define DIRNAME		"this-is-a-directory-with-a-really-long-name-and-stuff-and-such-and-stuff-and-such-and-stuff-and-such-and-stuff-and-such"
#define SLEEP_TIME	120

int main(void)
{
    puts("Hell world");

    printf("Trying to create a directory if it does not exist: %s\n", DIRNAME);
    if (mkdir(DIRNAME, 0755) == -1 && errno != EEXIST)
        err(1, "mkdir");

    const int dirfd = open(DIRNAME, O_RDONLY | O_DIRECTORY);
    if (dirfd == -1)
        err(1, "open");
    printf("got dirfd %d\n", dirfd);

    const int sock = socket(AF_UNIX, SOCK_STREAM, 0);
    if (sock == -1)
        err(1, "socket");
    struct sockaddr_un sun = { 0 };
    sun.sun_family = AF_UNIX;
    snprintf(sun.sun_path, sizeof(sun.sun_path), "/proc/self/fd/%d/meow", dirfd);
    printf("Trying to bind to %s\n", sun.sun_path);
    if (bind(sock, (const struct sockaddr *)&sun, sizeof(sun)) == -1)
        err(1, "bind");
    puts("uh... got it?");
    printf("Trying to listen on socket %d\n", sock);
    if (listen(sock, 10) == -1)
        err(1, "listen");

    printf("sleeping for %u seconds\n", SLEEP_TIME);
    sleep(SLEEP_TIME);
    puts("shutting down");
    return 0;
}

Attachment: signature.asc
Description: PGP signature

-- 
_______________________________________________
devel mailing list -- devel@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxxxxxxxx
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/devel@xxxxxxxxxxxxxxxxxxxxxxx
Do not reply to spam, report it: https://pagure.io/fedora-infrastructure/new_issue

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Fedora Announce]     [Fedora Users]     [Fedora Kernel]     [Fedora Testing]     [Fedora Formulas]     [Fedora PHP Devel]     [Kernel Development]     [Fedora Legacy]     [Fedora Maintainers]     [Fedora Desktop]     [PAM]     [Red Hat Development]     [Gimp]     [Yosemite News]

  Powered by Linux