Skip to content

Commit c223d3c

Browse files
committed
statx: fallback to lstat if ENOSYS is returned in errno.
- Security mechanisms used in Linux VMs, eg libseccomp and Docker's security policy may block certain system calls if they are new and unknown to the library and ENOSYS may be returned instead of EPERM. - Update the use of statx() to disable future calls and fallback to lstat() if ENOSYS is returned.
1 parent eca9e18 commit c223d3c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Foundation/FileManager+POSIX.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -915,10 +915,14 @@ extension FileManager {
915915
let statxErrno = _stat_with_btime(fsRep, &statInfo, &btime)
916916
guard statxErrno == 0 else {
917917
switch statxErrno {
918-
case EPERM:
919-
return try _statxFallback(atPath: path, withFileSystemRepresentation: fsRep)
918+
case EPERM, ENOSYS:
919+
// statx() may be blocked by a security mechanism (eg libseccomp or Docker) even if the kernel verison is new enough. EPERM or ENONSYS may be reported.
920+
// Dont try to use it in future and fallthough to a normal lstat() call.
921+
supportsStatx = false
922+
return try _statxFallback(atPath: path, withFileSystemRepresentation: fsRep)
923+
920924
default:
921-
throw _NSErrorWithErrno(statxErrno, reading: true, path: path)
925+
throw _NSErrorWithErrno(statxErrno, reading: true, path: path)
922926
}
923927
}
924928

0 commit comments

Comments
 (0)