From nobody Sun May 12 00:08:34 2024 X-Original-To: dev-commits-src-branches@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 4VcNJ33fVbz5Jb7X; Sun, 12 May 2024 00:08:35 +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 4VcNJ31T69z4t5x; Sun, 12 May 2024 00:08:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715472515; 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=VElqOUfu3JSg6S4nqkCDhc3etzZDAfmV4EPw1PHR3zc=; b=ry0ITDh1vmPI7wDNrvB6UoJu3GWJMPQE5fLuvC7rAiAGiG5RnSP4mDLUjEX59LkR+39Z7o EUpl6uDXpkxCcPen+AamDZch+GqU2cJHZTZ9Fag/QKGav9t91Da0CZPHMDe5SBuhOM5ake zE8bs7I8xg+QV8/iQjIQLYUhjS4vASAEc3QsIadPCPGwn8Q/h9NW5f47xbkLx8ICWui8Ff WkXxeDMI3KI/TJDrfxJx5N368cL96VNrKAsOt68aT5Nb8wy7N4YoHFqjl+47CHKr/xWWeN CtJ0UDRoXwRBKWvNorZWVjNRGyUhrkKoEkw+MP43kTZZZoHw72gFRLbIjTEEvg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1715472515; a=rsa-sha256; cv=none; b=af5REt6Gfz4YyH1HLa6K/yGvCPpDesyk39dUKFBIljfd+I3Geh1yBOBOlMM/C0i6W2wgLS xvMmAHaQE1CtaUUirPt1bjAPC0IJCSpAWg0iyF8MwMBfcn04Y+AYZUFSDe+0BYQsMSU9Er PH6K3Ma7IooNttWm19WfZzlOsKXoffr6mt5BSWSU2hJ8nU3YExh1yia5A8GVX8rgQvBbjf rLAc2/39YvYVM/c7FNl60enNUwVA7xGhdCWszAkeuqLOXlhMWnnBNc27EVKfIMBLA7TQly 6RrXWtUZfFizu3+S5QEJRu3qDq1oHECOsUWqmKVFYY/2mR5lIQLjqLtMMCYYZQ== 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=1715472515; 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=VElqOUfu3JSg6S4nqkCDhc3etzZDAfmV4EPw1PHR3zc=; b=SopucH1L3NdBB0kAMFndli8QNm2nmzX/sx9AiuLHYuH9wkjn84E6Tr0EH0iRwYMnTGjmll tqGwKZuVp94/NpJ4NhKrvlwghORrmf5+Frl7Khgr7hKbq3EvA0tVIavVPNM/HRabN+QWwy plpkFtQvaPiQAfahooV0/g68IRR9N/rQdf8bHAE3lW4B3yBw2x4ijpf16B9HMh6mmkxd3X M1iFRPzInmDyA0yLFjNOthnfQ8gmC3IjObjqQMaOCiH3gDThqflQnkK/SHCC7Fz1yDYAaC PiTbon1rmNAtZK8D6HA6410ieJnCdG0Snhd5MrOo5O4/V2e8uLJAcDN/tzUSAg== 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 4VcNJ30XcDzhh7; Sun, 12 May 2024 00:08:35 +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 44C08YxD002129; Sun, 12 May 2024 00:08:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44C08YbG002126; Sun, 12 May 2024 00:08:34 GMT (envelope-from git) Date: Sun, 12 May 2024 00:08:34 GMT Message-Id: <202405120008.44C08YbG002126@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Jake Freeland Subject: git: d0ca50b414be - stable/14 - uipc_shm: Copyin userpath for ktrace(2) List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jfree X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: d0ca50b414beebe5e61154541c9a2fb085df37f0 Auto-Submitted: auto-generated The branch stable/14 has been updated by jfree: URL: https://cgit.FreeBSD.org/src/commit/?id=d0ca50b414beebe5e61154541c9a2fb085df37f0 commit d0ca50b414beebe5e61154541c9a2fb085df37f0 Author: Jake Freeland AuthorDate: 2024-04-10 02:17:11 +0000 Commit: Jake Freeland CommitDate: 2024-05-11 23:57:44 +0000 uipc_shm: Copyin userpath for ktrace(2) If userpath is not SHM_ANON, then copy it in early so ktrace(2) can record it. Without this change, ktrace(2) will attempt to strcpy a userspace string and trigger a page fault. Reported by: syzbot+490b9c2a89f53b1b9779@syzkaller.appspotmail.com Fixes: 0cd9cde767c3 Approved by: markj (mentor) Reviewed by: markj MFC after: 1 month Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D44702 (cherry picked from commit b112232e4fb931ebafae9d79fbc970e3df020b57) --- sys/kern/uipc_shm.c | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/sys/kern/uipc_shm.c b/sys/kern/uipc_shm.c index 613656ca0a5a..31c80913be84 100644 --- a/sys/kern/uipc_shm.c +++ b/sys/kern/uipc_shm.c @@ -1172,18 +1172,6 @@ kern_shm_open2(struct thread *td, const char *userpath, int flags, mode_t mode, if ((shmflags & SHM_ALLOW_SEALING) != 0) initial_seals &= ~F_SEAL_SEAL; -#ifdef CAPABILITY_MODE - /* - * shm_open(2) is only allowed for anonymous objects. - */ - if (userpath != SHM_ANON) { - if (CAP_TRACING(td)) - ktrcapfail(CAPFAIL_NAMEI, userpath); - if (IN_CAPABILITY_MODE(td)) - return (ECAPMODE); - } -#endif - AUDIT_ARG_FFLAGS(flags); AUDIT_ARG_MODE(mode); @@ -1208,6 +1196,26 @@ kern_shm_open2(struct thread *td, const char *userpath, int flags, mode_t mode, if ((initial_seals & ~F_SEAL_SEAL) != 0) return (EINVAL); + if (userpath != SHM_ANON) { + error = shm_copyin_path(td, userpath, &path); + if (error != 0) + return (error); + +#ifdef CAPABILITY_MODE + /* + * shm_open(2) is only allowed for anonymous objects. + */ + if (CAP_TRACING(td)) + ktrcapfail(CAPFAIL_NAMEI, path); + if (IN_CAPABILITY_MODE(td)) { + free(path, M_SHMFD); + return (ECAPMODE); + } +#endif + + AUDIT_ARG_UPATH1_CANON(path); + } + pdp = td->td_proc->p_pd; cmode = (mode & ~pdp->pd_cmask) & ACCESSPERMS; @@ -1219,8 +1227,10 @@ kern_shm_open2(struct thread *td, const char *userpath, int flags, mode_t mode, * in sys_shm_open() to keep this implementation compliant. */ error = falloc_caps(td, &fp, &fd, flags & O_CLOEXEC, fcaps); - if (error) + if (error) { + free(path, M_SHMFD); return (error); + } /* A SHM_ANON path pointer creates an anonymous object. */ if (userpath == SHM_ANON) { @@ -1234,14 +1244,6 @@ kern_shm_open2(struct thread *td, const char *userpath, int flags, mode_t mode, shmfd->shm_seals = initial_seals; shmfd->shm_flags = shmflags; } else { - error = shm_copyin_path(td, userpath, &path); - if (error != 0) { - fdclose(td, fp, fd); - fdrop(fp, td); - return (error); - } - - AUDIT_ARG_UPATH1_CANON(path); fnv = fnv_32_str(path, FNV1_32_INIT); sx_xlock(&shm_dict_lock); shmfd = shm_lookup(path, fnv);