lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <51354ca5-acd2-f542-95e0-85ed8418f483@tum.de>
Date:   Wed, 24 May 2023 21:53:01 +0200
From:   Josef Schönberger <josef.schoenberger@....de>
To:     Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Tejun Heo <tj@...nel.org>
Cc:     linux-kernel@...r.kernel.org
Subject: KernFS: Missing IN_DELETE_SELF or IN_IGNORED inotify events

Hi everybody,

I'm currently working on event listeners for cgroups for a long running
daemon. I found that the removal of cgroups that I'm currently listening
for produces neither an IN_DELETE_SELF nor an IN_IGNORED event; which is
unfortunate, since I need to maintain a map from watch descriptors to
paths, from which I would like to remove all obsolete entries.

Since this is not the documented behaviour and since I could not find
any material that would specify an intention behind this, I'm assuming
that this is a bug?

I've found that the same applies to the sysfs. Taking a look at the
kernel code, I'd guess that the issue might be in KernFS.

I've appended a minimal reproducible example.

Thanks
Josef



#include <stdlib.h>
#include <err.h>
#include <sys/inotify.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/stat.h>
#include <signal.h>

void cleanup(int signo) {
    (void) signo;
    printf("Removing /sys/fs/cgroup/demo again...\n");
    if (rmdir("/sys/fs/cgroup/demo"))
        err(EXIT_FAILURE, "Could not remove /sys/fs/cgroup/demo");
    exit(0);
}

int main(void) {
    if (geteuid() != 0)
        fprintf(stderr, "Need root privileges.\n"
                "Will probably not be able to cgroup without.\n"
                "Giving it a shot regardless...\n");

    int fd = inotify_init();
    if (fd < 0)
        err(EXIT_FAILURE, "Could not create inotify fd");

    if (mkdir("/sys/fs/cgroup/demo", 755))
        err(EXIT_FAILURE, "Could not create cgroup @ /sys/fs/cgroup/demo");

    signal(SIGINT, cleanup);

    int wd = inotify_add_watch(fd, "/sys/fs/cgroup/demo", IN_DELETE_SELF);
    if (wd < 0)
        err(EXIT_FAILURE, "Could not add /sys/fs/cgroup/demo to inotify
fd");

    printf("Expecting to read an IN_DELETE_SELF or IN_IGNORED event...\n");
    char buf[512];
    ssize_t nbytes = read(fd, buf, sizeof(buf));
    if (nbytes < 0)
        err(EXIT_FAILURE, "Could not read from inotify fd");

    printf("Read %zd bytes\n", nbytes);
    cleanup(0);
}

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ