aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXin LI <delphij@FreeBSD.org>2023-03-05 09:40:13 +0000
committerXin LI <delphij@FreeBSD.org>2023-03-08 03:51:36 +0000
commit139825753995ca25a1d40df9f067a1fa4e847d44 (patch)
treeda9dcf608430a6c7e949315de0271a487648ac17
parent96064e0924d8e456f50252205bf3b221cb2e835c (diff)
downloadsrc-139825753995ca25a1d40df9f067a1fa4e847d44.tar.gz
src-139825753995ca25a1d40df9f067a1fa4e847d44.zip
xz: Improve compatibility with systems without capability mode support
When the kernel is built without capability mode support, or when using an emulator like qemu-user-static that does not translate system calls, these calls will return a negative number and set the errno to ENOSYS. However, this error does not indicate a real programming or runtime error and is generally ignored by base system applications built with capability mode sandboxing. Match this behavior by making xz(1) to ignore ENOSYS errors when calling capability mode system calls too. PR: 269185 Reported by: Dan Kotowski Approved by: re (cperciva) (cherry picked from commit c237c10a2346dec422233db05b2012afd45363fa) (cherry picked from commit 0cc2deb476bec103ad7c8dbeb650aa2937d6a0da)
-rw-r--r--contrib/xz/src/xz/file_io.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/contrib/xz/src/xz/file_io.c b/contrib/xz/src/xz/file_io.c
index a5841b370302..3625393a5dc7 100644
--- a/contrib/xz/src/xz/file_io.c
+++ b/contrib/xz/src/xz/file_io.c
@@ -193,23 +193,24 @@ io_sandbox_enter(int src_fd)
cap_rights_t rights;
if (cap_rights_limit(src_fd, cap_rights_init(&rights,
- CAP_EVENT, CAP_FCNTL, CAP_LOOKUP, CAP_READ, CAP_SEEK)))
+ CAP_EVENT, CAP_FCNTL, CAP_LOOKUP, CAP_READ, CAP_SEEK)) < 0 &&
+ errno != ENOSYS)
goto error;
if (cap_rights_limit(STDOUT_FILENO, cap_rights_init(&rights,
CAP_EVENT, CAP_FCNTL, CAP_FSTAT, CAP_LOOKUP,
- CAP_WRITE, CAP_SEEK)))
+ CAP_WRITE, CAP_SEEK)) < 0 && errno != ENOSYS)
goto error;
if (cap_rights_limit(user_abort_pipe[0], cap_rights_init(&rights,
- CAP_EVENT)))
+ CAP_EVENT)) < 0 && errno != ENOSYS)
goto error;
if (cap_rights_limit(user_abort_pipe[1], cap_rights_init(&rights,
- CAP_WRITE)))
+ CAP_WRITE)) < 0 && errno != ENOSYS)
goto error;
- if (cap_enter())
+ if (cap_enter() < 0 && errno != ENOSYS)
goto error;
#elif defined(HAVE_PLEDGE)