Skip to content

Removing directory with unlinked open file fails #79

@Slava0135

Description

@Slava0135

Also see #78.

Our fuzzer DIFFuzzer (source is closed at the moment) found this bug on commit 2cc2af5030f8bf831cd8355bc4780a34acbf6faa (tag: v2.7.10)

#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>

int main() {
  int res;
  res = mkdir("1", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
  int fd = creat("1/2", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
  res = unlink("1/2");
  printf("UNLINK %d(%s)\n", res, strerror(errno));
  res = rmdir("1");
  printf("RMDIR %d(%s)\n", res, strerror(errno));
  res = close(fd);
  printf("CLOSE %d(%s)\n", res, strerror(errno));
}

// ::Expected::
// UNLINK 0(Success)
// RMDIR 0(Success)
// CLOSE 0(Success)

// ::Actual::
// UNLINK 0(Success)
// RMDIR -1(Directory not empty)
// CLOSE 0(Directory not empty)

If file with open file descriptor is deleted using unlink, rmdir will still fail.

System info:

Ubuntu 22.04.5 LTS
Kernel 5.15.178
gcc 11.4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions