From nobody Tue Nov 17 11:56:49 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4jTNW56cHrz71Jx4 for ; Tue, 17 Nov 2026 11:56:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jTNW54cbVz4HFW for ; Tue, 17 Nov 2026 11:56:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794916609; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TT8Cpi09Kn1ywssY8Q4gy9bRfcrmFe7R04pQPxnsrMw=; b=fKKG20H3vCD1BITsFaeP6qouhKDintlGhcOra/e/QdA1SgehD8V6rXu3XVTKhINQeLyjzi mjvx5KONSk3nX0UovRFriGHfqFK2+9lyxN/B+H05NbQOraL+jfxSIEm1fsU2fGqosAAnPK i/BWeDLS7Du4xfXU0zOiPfkoBrkmkTLaL0aIdi3bQSZBAzrWXfF0oKf9ebuTCVDFXkUpop H7Gi4OOc4/s4rbjgviBfZMS+JdZMBU9eTrk7lq1B/YXEIbZoUXhzZ0pojzAuN953MI5qAf IoK27H69XhGoQum0ryKcrT4/W7dq8oD3MOHEo/a09Sde9DGuHtV/9JaUisiIWA== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794916609; b=QqykfgRLrQQhYVlm5SPiBomtQxoFkN+v6dpBxzoRZHnSSXB6duRMohQx+2AaFuuEHKv9rZ X07fJbCgUXPge/eZtbDeKAmvYYrygNqqzZbdkp7Br2INNy8rfo+1QriuU+07agiayYoyAf VZ+QtX8EUHlJ6CPYflJLXP0Vhg7omuRKCLcJRAOSM0RnaTY7rqHbQ3UH4/Yhk5tKEhOT5b r0kAeTd2dqz+n/QyjIYlPZL1TDYQzcZmgBcepfKXlE/KTIaDdGKZIpYeKkZc2Rd1+W4DNV ACkzDe6oMRTaftYNSiCOkpfFxnO6D16jn94m3EPgRnlLEnwW48HpXweyBBHP2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794916609; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TT8Cpi09Kn1ywssY8Q4gy9bRfcrmFe7R04pQPxnsrMw=; b=SyTru8R90LKIMDggnJr3gCAZXNEtetbVLQmjrduwpxOgAjpCMhNRE25bANPLxucGsbTZ/j eF3/YNHjFiaN3sA+LgbQ3RIWUCT0MjjDHJ8SyZT3/NhwnvujESQnNwa51VUYRSiHTDOaQk ZNS9KkmxyecrFzGLe+uvlWvguv9kWj/H+DW7PpVeZwv5whMbVwe7p8RfpN3PVsVkebxdph KE+9Xh/BaZEJRTnPoj/v5c3oqQLnH04x268/JjYZVFvrOFnK2w0+xymkGMiqlIFvr5jOSo WxnmqpMOqwrpMnIEelvmUtpsyT4Lov8pLfcQP7SV1rdx4R5ZRVTIaPePIybqLQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jTNW53z3Yzgw4 for ; Tue, 17 Nov 2026 11:56:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1e829 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 17 Nov 2026 11:56:49 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Baptiste Daroussin Subject: git: f417e2a5036e - main - pkg-serve: stat the opened descriptor instead of the path List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bapt X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f417e2a5036ed2d2beff7ed77db5883d726d2c42 Auto-Submitted: auto-generated Date: Tue, 17 Nov 2026 11:56:49 +0000 Message-Id: <6afc4101.1e829.4c945370@gitrepo.freebsd.org> The branch main has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=f417e2a5036ed2d2beff7ed77db5883d726d2c42 commit f417e2a5036ed2d2beff7ed77db5883d726d2c42 Author: Baptiste Daroussin AuthorDate: 2026-11-17 11:47:42 +0000 Commit: Baptiste Daroussin CommitDate: 2026-11-17 11:55:19 +0000 pkg-serve: stat the opened descriptor instead of the path Open first and fstat() that fd, so the file checked is the one served. O_NONBLOCK avoids blocking on a FIFO. --- libexec/pkg-serve/pkg-serve.c | 27 +++++++++++++++++++-------- libexec/pkg-serve/tests/pkg_serve_test.sh | 20 ++++++++++++++++++++ 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/libexec/pkg-serve/pkg-serve.c b/libexec/pkg-serve/pkg-serve.c index ebfacc3e3e00..cbe3c7689a93 100644 --- a/libexec/pkg-serve/pkg-serve.c +++ b/libexec/pkg-serve/pkg-serve.c @@ -65,7 +65,7 @@ int main(int argc, char *argv[]) { struct stat st; - cap_rights_t rights; + cap_rights_t rights, ffdrights; char line[MAXLINE]; char *file, *age; size_t r, toread; @@ -85,8 +85,7 @@ main(int argc, char *argv[]) if ((fd = open(basedir, O_DIRECTORY | O_RDONLY | O_CLOEXEC)) < 0) err(EXIT_FAILURE, "open(%s)", basedir); - cap_rights_init(&rights, CAP_READ, CAP_FSTATAT, CAP_LOOKUP, - CAP_FCNTL); + cap_rights_init(&rights, CAP_READ, CAP_FSTAT, CAP_LOOKUP); if (cap_rights_limit(fd, &rights) < 0 && errno != ENOSYS) err(EXIT_FAILURE, "cap_rights_limit"); @@ -158,28 +157,40 @@ main(int argc, char *argv[]) continue; } - if (fstatat(fd, file, &st, AT_RESOLVE_BENEATH) == -1) { + ffd = openat(fd, file, + O_RDONLY | O_NONBLOCK | O_RESOLVE_BENEATH | O_CLOEXEC); + if (ffd == -1) { + printf("ko: file not found\n"); + fflush(stdout); + continue; + } + + if (fstat(ffd, &st) == -1) { + close(ffd); printf("ko: file not found\n"); fflush(stdout); continue; } if (!S_ISREG(st.st_mode)) { + close(ffd); printf("ko: not a file\n"); fflush(stdout); continue; } if (st.st_mtime <= mtime) { + close(ffd); printf("ok: 0\n"); fflush(stdout); continue; } - if ((ffd = openat(fd, file, O_RDONLY | O_RESOLVE_BENEATH)) == -1) { - printf("ko: file not found\n"); - fflush(stdout); - continue; + /* Only reading is needed from now on. */ + cap_rights_init(&ffdrights, CAP_READ); + if (cap_rights_limit(ffd, &ffdrights) < 0 && errno != ENOSYS) { + close(ffd); + err(EXIT_FAILURE, "cap_rights_limit"); } printf("ok: %" PRIdMAX "\n", (intmax_t)st.st_size); diff --git a/libexec/pkg-serve/tests/pkg_serve_test.sh b/libexec/pkg-serve/tests/pkg_serve_test.sh index 9c872f3ecdb4..60ab92e2114c 100644 --- a/libexec/pkg-serve/tests/pkg_serve_test.sh +++ b/libexec/pkg-serve/tests/pkg_serve_test.sh @@ -152,6 +152,25 @@ get_empty_arg_body() atf_fail "expected bad command get" } +atf_test_case get_fifo +get_fifo_head() +{ + atf_set "descr" "Requesting a FIFO returns ko without blocking" +} +get_fifo_body() +{ + mkdir repo + mkfifo repo/fifo + output=$(printf 'get fifo 0\nquit\n' | timeout 10 "${PKG_SERVE}" repo) + case "$output" in + *"ko: not a file"*) + ;; + *) + atf_fail "expected 'not a file', got: ${output}" + ;; + esac +} + atf_test_case path_traversal path_traversal_head() { @@ -256,6 +275,7 @@ atf_init_test_cases() atf_add_test_case get_bad_age atf_add_test_case get_empty_arg atf_add_test_case command_too_long + atf_add_test_case get_fifo atf_add_test_case path_traversal atf_add_test_case get_subdir_file atf_add_test_case multiple_gets