[Bug 271704] O_PATH and acl_get_fd_np doesn't work on FreeBSD 13(.2) and causes vfs_zfsacl in Samba to fail

From: <bugzilla-noreply_at_freebsd.org>
Date: Mon, 29 May 2023 12:25:40 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=271704

            Bug ID: 271704
           Summary: O_PATH and acl_get_fd_np doesn't work on FreeBSD
                    13(.2) and causes vfs_zfsacl in Samba to fail
           Product: Base System
           Version: 13.2-RELEASE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Many People
          Priority: ---
         Component: kern
          Assignee: bugs@FreeBSD.org
          Reporter: pen@lysator.liu.se

The new O_PATH support in FreeBSD 13 doesn't seem to work with trying to read
ZFS ACLs via acl_get_fd_np().

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/acl.h>
#include <sys/stat.h>


int
main(int argc,
     char *argv[]) {
  int i, j, fd;
  acl_t a;
  char *path = ".";
  int flags = O_PATH;
  struct stat sb;


  for (i = 1; i < argc && argv[i][0] == '-'; i++) {
    for (j = 1; argv[i][j]; j++) {
      switch (argv[i][j]) {
      case 'n':
        flags = 0;
        break;
      }
    }
  }

  if (i < argc)
    path = argv[i];

  fd = open(path, O_RDONLY|flags);
  if (fd < 0) {
    fprintf(stderr, "%s: Error: %s: open: %s\n", argv[0], path,
strerror(errno));
    exit(1);
  }

  if (fstat(fd, &sb) < 0) {
    fprintf(stderr, "%s: Error: %s: fstat: %s\n", argv[0], path,
strerror(errno));
  }

  a = acl_get_fd_np(fd, ACL_TYPE_NFS4);
  if (!a) {
    fprintf(stderr, "%s: Error: %s: acl_get_fd_np: %s\n", argv[0], path,
strerror(errno));
  }

  return 0;
}


root@runur00:~Lpeter86 # ./t 
./t: Error: .: acl_get_fd_np: Bad file descriptor

root@runur00:~Lpeter86 # ./t -n

root@runur00:~Lpeter86 # getfacl .
# file: .
# owner: Lpeter86
# group: Ladmins
            owner@:rwxp--aARWcCos:-------:allow
            group@:------a-R-c--s:-------:allow
         everyone@:------a-R-c--s:-------:allow



This seems to cause atleast the Samba "zfsacl" module to fail.

-- 
You are receiving this mail because:
You are the assignee for the bug.