From nobody Thu May 23 19:42:08 2024 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 4Vldq514Glz5L9tK; Thu, 23 May 2024 19:42:09 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Vldq508fMz557H; Thu, 23 May 2024 19:42:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716493329; 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=/sUBjn32/aqHZCVyXzL8t/wKJUfUaAO2mVXqLoMKov8=; b=JnaQMwBW2WdAIPzok+ubdtk5Vky5ds34McM0EkDJ9Zh2tWNsHU2WgqL5X5fb9sLne6+1lN GafulQq+cCtDO/bSaZfGh8rhI7a2rULRqFoe7xrxlg/KlsroCCTk4+GvUHUaJ1ho7rRsbK HZ+XAu5xweKYo1XxMkQtI++LomFk9jedlpBg7ot8mEcPMLvVevNrXqMK5j0n+NuG9HhxLt xEYu/a83ubnIcVzrVkYd/qMJl9n+5BppNlZan7FY7VSk1eNOreEeWxNzwPmZYLSOsOd90e KRd4JIEIwgTiGnBoKeMdulxf5eda+eQ/2HfV8bjyyF+N+/zs633kIsPN9yx2PA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1716493329; a=rsa-sha256; cv=none; b=yko9mgr82HdUBVSSF2F2j4VciNSHCm8hIDJujRkl/TOhDWYrbfwFxIaESxpQ+lM/hy1xNg buIxPIU5XIKkMBMC5AfkmnJ4/Kecwg9++vpzQUuRy1KQmBaJtBAaqy/cK5uwu+ZY+gZG0R 7F1YMfD36kwFrvjZ3lsX+C4R4An1iq6GokvnnFdR1vnvNJ/GtiluRBAYRc6j21PUTWzwlS EJoXdlWet/7CYHDwjdU1qD5SN70a1ui3sQ8257ff1LBrBI0ano6oxh2m26jL1u/FfbjDQw 2z8ruTcHU94w422rWo9YVJCGqQdW5WrOTaHSMzbrLpTY0EQ3RfsoRZd9Si3a3A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716493329; 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=/sUBjn32/aqHZCVyXzL8t/wKJUfUaAO2mVXqLoMKov8=; b=HQe4PdNT4XMbqzLtUJXlf9Q5tdARe90JyQiIkjh5zNsckptPA6OGUg4/qeY73cFHPZskjG zz2TeoRrYFMPntSrIJcZh922Vl6ZG85PjYqkZzKOjv4CRyyAjlysuRhQkAwY8+GO/N5X8T yX+6RDFJCP4ZKo+XD26Q/7+4JtUgsj9MHsM9cWuApOO4C2kMj+arWu85uvNuYCv2rJeLfO pL/DJ6PMgj8Sduj3kWTLxB9lHi5pB+y6Ja3UdJUA+laeJI+ENzPgy1rw/cg15NM+nO0mPx u9WVCiXiAaTMvv9vXm/6/H+5Vj5+tgzDKoxxWKuD06AexD2XeEuzaNgF912GPA== 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 4Vldq46v5Yz131B; Thu, 23 May 2024 19:42:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 44NJg8oO082553; Thu, 23 May 2024 19:42:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44NJg84L082550; Thu, 23 May 2024 19:42:08 GMT (envelope-from git) Date: Thu, 23 May 2024 19:42:08 GMT Message-Id: <202405231942.44NJg84L082550@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: ddbfb544c6c9 - main - mqueuefs: Relax restriction that path must begin with a slash List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ddbfb544c6c9726ae97bcaf105d11dec8b292877 Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=ddbfb544c6c9726ae97bcaf105d11dec8b292877 commit ddbfb544c6c9726ae97bcaf105d11dec8b292877 Author: Ricardo Branco AuthorDate: 2024-05-15 20:56:15 +0000 Commit: Warner Losh CommitDate: 2024-05-23 19:40:46 +0000 mqueuefs: Relax restriction that path must begin with a slash This is needed to support Linux implementation which discards the leading slash when calling mq_open(2) Reviewed by: imp, kib Pull Request: https://github.com/freebsd/freebsd-src/pull/1248 --- lib/libsys/mq_open.2 | 4 ++-- sys/kern/uipc_mqueue.c | 34 ++++++++++++++++++++++------------ 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/lib/libsys/mq_open.2 b/lib/libsys/mq_open.2 index 484fe95432da..4800ab18de59 100644 --- a/lib/libsys/mq_open.2 +++ b/lib/libsys/mq_open.2 @@ -35,7 +35,7 @@ .\" the referee document. The original Standard can be obtained online at .\" http://www.opengroup.org/unix/online.html. .\" -.Dd September 26, 2023 +.Dd May 15, 2024 .Dt MQ_OPEN 2 .Os .Sh NAME @@ -322,7 +322,7 @@ Support for POSIX message queues first appeared in .Sh BUGS This implementation places strict requirements on the value of .Fa name : -it must begin with a slash +it may begin with a slash .Pq Ql / and contain no other slash characters. .Pp diff --git a/sys/kern/uipc_mqueue.c b/sys/kern/uipc_mqueue.c index 2efdfc9dd04c..9276c918565f 100644 --- a/sys/kern/uipc_mqueue.c +++ b/sys/kern/uipc_mqueue.c @@ -2007,7 +2007,7 @@ static int kern_kmq_open(struct thread *td, const char *upath, int flags, mode_t mode, const struct mq_attr *attr) { - char path[MQFS_NAMELEN + 1]; + char *path, pathbuf[MQFS_NAMELEN + 1]; struct mqfs_node *pn; struct pwddesc *pdp; struct file *fp; @@ -2027,32 +2027,37 @@ kern_kmq_open(struct thread *td, const char *upath, int flags, mode_t mode, return (EINVAL); } + path = pathbuf; error = copyinstr(upath, path, MQFS_NAMELEN + 1, NULL); if (error) return (error); /* - * The first character of name must be a slash (/) character + * The first character of name may be a slash (/) character * and the remaining characters of name cannot include any slash * characters. */ len = strlen(path); - if (len < 2 || path[0] != '/' || strchr(path + 1, '/') != NULL) + if (len < 2 || strchr(path + 1, '/') != NULL) return (EINVAL); + if (path[0] == '/') { + path++; + len--; + } /* * "." and ".." are magic directories, populated on the fly, and cannot * be opened as queues. */ - if (strcmp(path, "/.") == 0 || strcmp(path, "/..") == 0) + if (strcmp(path, ".") == 0 || strcmp(path, "..") == 0) return (EINVAL); - AUDIT_ARG_UPATH1_CANON(path); + AUDIT_ARG_UPATH1_CANON(pathbuf); error = falloc(td, &fp, &fd, O_CLOEXEC); if (error) return (error); sx_xlock(&mqfs_data.mi_lock); - pn = mqfs_search(mqfs_data.mi_root, path + 1, len - 1, td->td_ucred); + pn = mqfs_search(mqfs_data.mi_root, path, len, td->td_ucred); if (pn == NULL) { if (!(flags & O_CREAT)) { error = ENOENT; @@ -2062,7 +2067,7 @@ kern_kmq_open(struct thread *td, const char *upath, int flags, mode_t mode, error = ENFILE; } else { pn = mqfs_create_file(mqfs_data.mi_root, - path + 1, len - 1, td->td_ucred, + path, len, td->td_ucred, cmode); if (pn == NULL) { error = ENOSPC; @@ -2134,23 +2139,28 @@ sys_kmq_open(struct thread *td, struct kmq_open_args *uap) int sys_kmq_unlink(struct thread *td, struct kmq_unlink_args *uap) { - char path[MQFS_NAMELEN+1]; + char *path, pathbuf[MQFS_NAMELEN + 1]; struct mqfs_node *pn; int error, len; + path = pathbuf; error = copyinstr(uap->path, path, MQFS_NAMELEN + 1, NULL); if (error) return (error); len = strlen(path); - if (len < 2 || path[0] != '/' || strchr(path + 1, '/') != NULL) + if (len < 2 || strchr(path + 1, '/') != NULL) return (EINVAL); - if (strcmp(path, "/.") == 0 || strcmp(path, "/..") == 0) + if (path[0] == '/') { + path++; + len--; + } + if (strcmp(path, ".") == 0 || strcmp(path, "..") == 0) return (EINVAL); - AUDIT_ARG_UPATH1_CANON(path); + AUDIT_ARG_UPATH1_CANON(pathbuf); sx_xlock(&mqfs_data.mi_lock); - pn = mqfs_search(mqfs_data.mi_root, path + 1, len - 1, td->td_ucred); + pn = mqfs_search(mqfs_data.mi_root, path, len, td->td_ucred); if (pn != NULL) error = do_unlink(pn, td->td_ucred); else