From nobody Thu Aug 21 19:01:38 2025 X-Original-To: dev-commits-ports-main@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 4c7CNM0vGrz65XGT; Thu, 21 Aug 2025 19:01:39 +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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4c7CNL6phzz3pvM; Thu, 21 Aug 2025 19:01:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1755802899; 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=XlxTfoW3AsvnztIL6eI/PFmEo9EQdEVP0HJP/WStelU=; b=Y+/uB8kPW6C2lkr2Qsyw4FM6S8UPNCwWQH10stcFUFs707qn9pkNid4mGAQUj2XsJOrsub 3VGq67TQvG8+WQFKfAnaJKV2wpR6RcIVLwyc88NR1NDs7drsTA+XNmpqIVuXxpHyEhGakj WoD4Xn4DQgPW6xnotQS2Qmj74o5COuN+B9EV9UymJ664yZ9xglanH231GYJviKUSvf36Yk 1OiMRIB35rBbx8Phu885/X/dW7RYyyDAlCyGKKy+DUKbu1P8M2UysyQSPFbmP8wbWVYjsl OvavQosPhogOhOF+dBGABcgWKA70U52seIfwOm+zTKkUnJcbOHmSDUYsWSSywg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1755802899; 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=XlxTfoW3AsvnztIL6eI/PFmEo9EQdEVP0HJP/WStelU=; b=xnfB8mJ7jCy6z5h2MRvV++JUdsi/Yez/wTFfvSt9JcQYY7IIIU8Wj0f1IeWAwhD6lI+/NG Pdz+RixKba/hFeeGQZJPOpuPQfrLCuac9rBIAEgdRvUvSZmsstv/VZ2n74GwL1gMZCWXCE 5i9fVv4i5YE5KhSGOhA7hRv2LQRFmvaspPKgFsvskvDbwT4kZxkJrYumuwE5sv20KGxnbM uNe+ZeQUSBarn3TrL1YD8N2rtejHqEVxyezh9k3RQG58jbqH3ZMlSID83m2CdQlPLx9+yY qMTg5kzcwoy5fLQyrAw8aGSLwWvKm1/1Ga/sItIw7zHWmJWHCNiZCl0Zg8XCbA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1755802899; a=rsa-sha256; cv=none; b=XMCeb6vF32kaBpX5P6yyXBGdCvk95cG7K3IiRsLbKOiGmfruQRSGYnZXwlUQkz2hZgLHz/ 0nJfiUwHleCznHkzwWEVvx7sujahXRKXStXccpeayNXO2OAJCNQEhpy1XaY7Pxpqby2Xn2 riApN5JhQ7j6xNe5UPeoG5RVqkrAWSvqw56f9AeS7LK+Oyfny5eZli0ebBU/X+0pPk7UPf Ju+n0XJxUNLG1kFlNXLFdRH5GYxcg22X7YrirElp+oDYgWgOPDR4muJfpvyQdE/nIQWfJp YfsV2dBAJcEAw+ZLSoScqF79LgL3ySEmTN3xkzJNcH59CGIxdSaUGvKyc9mKHQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4c7CNL6MWPz19l0; Thu, 21 Aug 2025 19:01:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 57LJ1ceX016260; Thu, 21 Aug 2025 19:01:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 57LJ1cSK016257; Thu, 21 Aug 2025 19:01:38 GMT (envelope-from git) Date: Thu, 21 Aug 2025 19:01:38 GMT Message-Id: <202508211901.57LJ1cSK016257@gitrepo.freebsd.org> To: ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-main@FreeBSD.org From: Dimitry Andric Subject: git: a60d74e32eee - main - net/samba420: fix fdescfs handling which causes several issues List-Id: Commits to the main branch of the FreeBSD ports repository List-Archive: https://lists.freebsd.org/archives/dev-commits-ports-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-ports-main@freebsd.org Sender: owner-dev-commits-ports-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dim X-Git-Repository: ports X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a60d74e32eeedfcec40f37ba6a4e409fe53dbeeb Auto-Submitted: auto-generated The branch main has been updated by dim: URL: https://cgit.FreeBSD.org/ports/commit/?id=a60d74e32eeedfcec40f37ba6a4e409fe53dbeeb commit a60d74e32eeedfcec40f37ba6a4e409fe53dbeeb Author: Dimitry Andric AuthorDate: 2025-06-30 12:43:18 +0000 Commit: Dimitry Andric CommitDate: 2025-08-21 19:01:17 +0000 net/samba420: fix fdescfs handling which causes several issues Issue from bug 284623: several PANIC errors in log.smbd, similar to: [2025/02/02 16:56:09.823293, 0] ../../lib/util/fault.c:193(smb_panic_log) PANIC (pid 8625): async open timeout in 4.20.7 [2025/02/02 16:56:09.827129, 0] ../../lib/util/fault.c:304(log_stack_trace) BACKTRACE: 20 stack frames: #0 0x3645750f6ec7 at /usr/local/lib/samba4/private/libgenrand-private-samba.so #1 0x3645750f6f9e at /usr/local/lib/samba4/private/libgenrand-private-samba.so #2 0x36456b707b24 at /usr/local/lib/samba4/private/libsmbd-base-private-samba.so #3 0x36456b707981 at /usr/local/lib/samba4/private/libsmbd-base-private-samba.so #4 0x364575394bcc at /usr/local/lib/samba4/private/libsmbd-shim-private-samba.so #5 0x36456b6b2b10 at /usr/local/lib/samba4/private/libsmbd-base-private-samba.so #6 0x364575935dff at /usr/local/lib/libtevent.so.0 #7 0x364575935fa4 at /usr/local/lib/libtevent.so.0 #8 0x3645759337c5 at /usr/local/lib/libtevent.so.0 #9 0x36457592f36a <_tevent_loop_once+0xea> at /usr/local/lib/libtevent.so.0 #10 0x36457592f5f2 at /usr/local/lib/libtevent.so.0 #11 0x36456b6cd34b at /usr/local/lib/samba4/private/libsmbd-base-private-samba.so #12 0x363d4788f9bd at /usr/local/sbin/smbd #13 0x36457593067e at /usr/local/lib/libtevent.so.0 #14 0x364575933a44 at /usr/local/lib/libtevent.so.0 #15 0x36457592f36a <_tevent_loop_once+0xea> at /usr/local/lib/libtevent.so.0 #16 0x36457592f5f2 at /usr/local/lib/libtevent.so.0 #17 0x363d4788df3f at /usr/local/sbin/smbd #18 0x363d4788cbac at /usr/local/sbin/smbd #19 0x36457742ac3a <__libc_start1+0x12a> at /lib/libc.so.7 Issue from bug 286821: accessing Samba shares from macOS clients results in error dialogs titled: "There was a problem connecting to the server", with content "The share does not exist on the server. Please check the share name and then try again". The problems are caused by fdescfs handling: * patch 0028-s3-lib-system-add-FreeBSD-proc_fd_pattern.patch was how Timur solved the fd problem for Samba 4.19 (mounting fdescfs nodup under /var/run/samba4/fd); * if only this had been accepted upstream, we would not have had this problem in 4.20... :( * in any case this code is now unused in 4.20, where Samba went even more Linux-only; * patch 0101-FreeBSD-add-fdescfs-paths-workaround.patch was a naive tentative to solve the same problem for 4.20, apparently without taking into account what had been done before; it's broken by design, brokenly implementated and it simply doesn't work. Apply a patch by Andrea Venturoli , which drops the 0101 patch, and modifies the older 0028 patch to revive what Timur had done. PR: 284623, 286821 Tested by: O. Hartmann and others Approved by: samba (0mp) MFH: 2025Q3 --- net/samba420/Makefile | 3 +- ...s3-lib-system-add-FreeBSD-proc_fd_pattern.patch | 112 ++++++++++----------- ...0101-FreeBSD-add-fdescfs-paths-workaround.patch | 71 ------------- 3 files changed, 57 insertions(+), 129 deletions(-) diff --git a/net/samba420/Makefile b/net/samba420/Makefile index 6d6c72c1f552..3696bb72befa 100644 --- a/net/samba420/Makefile +++ b/net/samba420/Makefile @@ -1,6 +1,6 @@ PORTNAME= ${SAMBA4_BASENAME}420 PORTVERSION= ${SAMBA4_VERSION} -PORTREVISION= 9 +PORTREVISION= 10 CATEGORIES?= net MASTER_SITES= SAMBA/samba/stable SAMBA/samba/rc DISTNAME= ${SAMBA4_DISTNAME} @@ -47,7 +47,6 @@ EXTRA_PATCHES= \ ${PATCHDIR}/0028-Fix-rl_completion_func_t.patch:-p1 \ ${PATCHDIR}/0028-s3-lib-system-add-FreeBSD-proc_fd_pattern.patch \ ${PATCHDIR}/0100-Fix-pathref-handling-for-FreeBSD-13plus_samba42x.patch:-p1 \ - ${PATCHDIR}/0101-FreeBSD-add-fdescfs-paths-workaround.patch:-p1 \ ${PATCHDIR}/0102-FreeBSD-vfs_freebsd-fix-sys_proc_fd_path-args.patch:-p1 SAMBA4_BASENAME= samba diff --git a/net/samba420/files/0028-s3-lib-system-add-FreeBSD-proc_fd_pattern.patch b/net/samba420/files/0028-s3-lib-system-add-FreeBSD-proc_fd_pattern.patch index cda9c7ed1c95..2721be912c76 100644 --- a/net/samba420/files/0028-s3-lib-system-add-FreeBSD-proc_fd_pattern.patch +++ b/net/samba420/files/0028-s3-lib-system-add-FreeBSD-proc_fd_pattern.patch @@ -1,14 +1,24 @@ ---- source3/lib/system.c.orig 2024-02-02 10:33:51.188489400 +0100 -+++ source3/lib/system.c 2025-01-22 17:39:58.625028000 +0100 -@@ -1047,22 +1047,108 @@ +From 584c69e77abb537a7345222648a397a9963c01b7 Mon Sep 17 00:00:00 2001 +From: "Timur I. Bakeyev" +Date: Sat, 15 Oct 2022 04:02:43 +0200 +Subject: [PATCH 28/28] s3:lib:system - add FreeBSD proc_fd_pattern + +Add support for FreeBSD equivalent of /proc/self/fd through a special +fdescfs mount with option "nodup". This filesystem should be mounted +either to the private $PIDDIR/fd/ directory or to /dev/fd in order to +provide security and performance characteristics similar to Linux. + +Signed-off-by: Timur I. Bakeyev +Adapted for Samba 4.20 by: Andrea venturoli +--- +--- source3/lib/system.c.orig 2025-06-27 15:05:05 UTC ++++ source3/lib/system.c +@@ -1047,6 +1047,68 @@ int sys_get_number_of_cores(void) } #endif --bool sys_have_proc_fds(void) +static bool freebsd_fdesc_check(const char *pattern) - { -- static bool checked = false; -- static bool have_proc_fds = false; ++{ + char fdesc_path[PATH_MAX]; + int fd, fd2; + @@ -49,26 +59,6 @@ + return true; +} + -+static char* linux_pattern(char *buf, size_t bufsize) -+{ -+ char proc_fd_path[PATH_MAX]; -+ const char *pattern = "/proc/self/fd/%lu"; - struct stat sb; -- int ret; - -- if (checked) { -- return have_proc_fds; -+ snprintf(proc_fd_path, sizeof(proc_fd_path), pattern, 0); -+ if(stat(proc_fd_path, &sb) == 0) { -+ snprintf(buf, bufsize, "%s", pattern); -+ return buf; - } -+ return NULL; -+} - -- ret = stat("/proc/self/fd/0", &sb); -- have_proc_fds = (ret == 0); -- checked = true; +static char* freebsd_pattern(char *buf, size_t bufsize) { + const char** base; + const char* base_dir[] = { @@ -76,8 +66,7 @@ + "/dev", + NULL + }; - -- return have_proc_fds; ++ + for(base = &base_dir[0]; *base != NULL; base++) { + snprintf(buf, bufsize, "%s/fd/%%lu", *base); + if(freebsd_fdesc_check(buf)) { @@ -87,35 +76,46 @@ + return NULL; +} + -+static char* (*proc_fd_patterns[])(char *, size_t) = { -+ linux_pattern, -+ freebsd_pattern, -+ NULL -+}; -+ +static char proc_fd_pattern_buf[PATH_MAX]; +static const char *proc_fd_pattern = NULL; -+ -+bool sys_have_proc_fds(void) -+{ -+ static bool checked = false; -+ static bool have_proc_fds = false; -+ char* (**pattern_func)(char *, size_t) = NULL; -+ -+ if (checked) { -+ return have_proc_fds; -+ } -+ -+ for (pattern_func = &proc_fd_patterns[0]; *pattern_func != NULL; pattern_func++) { -+ if((*pattern_func)(proc_fd_pattern_buf, sizeof(proc_fd_pattern_buf)) != NULL) { -+ have_proc_fds = true; -+ proc_fd_pattern = proc_fd_pattern_buf; -+ break; -+ } -+ } + -+ checked = true; -+ return have_proc_fds; - } + bool sys_have_proc_fds(void) + { + static bool checked = false; +@@ -1058,8 +1078,12 @@ bool sys_have_proc_fds(void) + return have_proc_fds; + } + +- ret = stat("/proc/self/fd/0", &sb); +- have_proc_fds = (ret == 0); ++ if (freebsd_pattern(proc_fd_pattern_buf, sizeof(proc_fd_pattern_buf)) != NULL) { ++ have_proc_fds = true; ++ proc_fd_pattern = proc_fd_pattern_buf; ++ } else ++ have_proc_fds = false; ++ + checked = true; + + return have_proc_fds; +@@ -1067,10 +1091,18 @@ char *sys_proc_fd_path(int fd, struct sys_proc_fd_path char *sys_proc_fd_path(int fd, struct sys_proc_fd_path_buf *buf) + { ++ bool have_proc_fds = sys_have_proc_fds(); ++ SMB_ASSERT(have_proc_fds); ++#if defined(__clang__) ++#pragma clang diagnostic push ++#pragma clang diagnostic ignored "-Wformat-nonliteral" ++#endif + int written = +- snprintf(buf->buf, sizeof(buf->buf), "/proc/self/fd/%d", fd); +- +- SMB_ASSERT(sys_have_proc_fds() && (written >= 0)); ++ snprintf(buf->buf, sizeof(buf->buf), proc_fd_pattern, fd); ++#if defined(__clang__) ++#pragma clang diagnostic pop ++#endif ++ SMB_ASSERT(written >= 0); + + return buf->buf; + } diff --git a/net/samba420/files/0101-FreeBSD-add-fdescfs-paths-workaround.patch b/net/samba420/files/0101-FreeBSD-add-fdescfs-paths-workaround.patch deleted file mode 100644 index 714ad6ae52ef..000000000000 --- a/net/samba420/files/0101-FreeBSD-add-fdescfs-paths-workaround.patch +++ /dev/null @@ -1,71 +0,0 @@ -# 2024-08-05 -# NOTE: Upstream Samba commit 9f63fad392f3 removed the static array defining Linux and FreeBSD -# fdescfs paths and hardcoded a Linux-specific /proc path, with the note that if any -# others need to be added, they can be done so via #ifdef's. This patch attempts to -# do that, but in a way that minimizes the necessary #ifdefs by defining a simplistic -# #define macro to generate the appropriate path for fdescfs based on the running OS. -# -# See: https://git.samba.org/?p=samba.git;a=commitdiff;h=9f63fad392f3cff34d6a8e318e0427499170c417 - -diff -Naurp a/lib/fuzzing/fuzz_regfio.c b/lib/fuzzing/fuzz_regfio.c ---- a/lib/fuzzing/fuzz_regfio.c 2024-02-02 04:33:50.952488000 -0500 -+++ b/lib/fuzzing/fuzz_regfio.c 2024-08-05 20:41:16.624793000 -0400 -@@ -31,7 +31,7 @@ int LLVMFuzzerInitialize(int *argc, char ***argv) - { - fp = tmpfile(); - -- (void)snprintf(filename, sizeof(filename), "/proc/self/fd/%d", fileno(fp)); -+ (void)snprintf(filename, sizeof(filename), PROC_FD_PATH_MKSTR(%d), fileno(fp)); - - return 0; - } -diff -Naurp a/lib/replace/closefrom.c b/lib/replace/closefrom.c ---- a/lib/replace/closefrom.c 2024-02-02 04:33:50.984488200 -0500 -+++ b/lib/replace/closefrom.c 2024-08-05 20:41:16.625141000 -0400 -@@ -53,7 +53,7 @@ static int closefrom_procfs(int lower) - size_t i; - int ret = ENOMEM; - -- dirp = opendir("/proc/self/fd"); -+ dirp = opendir(PROC_FD_PATH_MKSTR()); - if (dirp == NULL) { - return errno; - } -diff -Naurp a/source3/include/proto.h b/source3/include/proto.h ---- a/source3/include/proto.h 2024-08-05 20:40:38.434560000 -0400 -+++ b/source3/include/proto.h 2024-08-05 20:41:26.063626000 -0400 -@@ -205,8 +205,21 @@ int sys_get_number_of_cores(void); - int sys_get_number_of_cores(void); - #endif - -+#ifdef __FreeBSD__ -+#define PROC_FD_PATH_STR "/compat/linux/dev/fd/" -+#define PROC_FD_PATH_SZ 42 -+#else /* Linux */ -+#define PROC_FD_PATH_STR "/proc/self/fd/" -+#define PROC_FD_PATH_SZ 35 -+#endif -+ -+#define _S(_t) #_t -+#define _V(...) _S(__VA_ARGS__) -+#define _X(_t) _t -+#define PROC_FD_PATH_MKSTR(_fd) _V(_X(PROC_FD_PATH_STR)_X(_fd)) -+ - struct sys_proc_fd_path_buf { -- char buf[35]; /* "/proc/self/fd/" + strlen(2^64) + 0-terminator */ -+ char buf[PROC_FD_PATH_SZ]; /* strlen(PROC_FD_PATH_STR) + strlen(2^64) + 0-terminator */ - }; - bool sys_have_proc_fds(void); - char *sys_proc_fd_path(int fd, struct sys_proc_fd_path_buf *buf); -diff -Naurp a/source3/lib/system.c b/source3/lib/system.c ---- a/source3/lib/system.c 2024-08-05 20:40:38.434801000 -0400 -+++ b/source3/lib/system.c 2024-08-05 20:41:16.625938000 -0400 -@@ -1068,7 +1068,7 @@ char *sys_proc_fd_path(int fd, struct sys_proc_fd_path - char *sys_proc_fd_path(int fd, struct sys_proc_fd_path_buf *buf) - { - int written = -- snprintf(buf->buf, sizeof(buf->buf), "/proc/self/fd/%d", fd); -+ snprintf(buf->buf, sizeof(buf->buf), PROC_FD_PATH_MKSTR(%d), fd); - - SMB_ASSERT(sys_have_proc_fds() && (written >= 0)); -