From nobody Mon Apr 4 19:19:15 2022 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 DDB871A82F33; Mon, 4 Apr 2022 19:19:15 +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 4KXLDg54yNz3w4v; Mon, 4 Apr 2022 19:19:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649099955; 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=IfcPjfOsa0pmNswmyriJGMSjbHo0ZQqAmPfWqIOlleo=; b=VNbSJDr34OzpUTMiNm/8sKmTiWrOPx93CzO2ljtxOz/bY29Gu4/nfkBMMAr4pG37zkLk5r BtuBgBHfSlZPGeuE3JpmoRoJOJpo7EeLrupVJ1mNfTB4+FeHOMQWnE2bXgljk+lFiQmQ7H Ek88FraguB1EZ99yceCMCTKGyqa2lEE2mJ0OSPXmaoIcXG8no3tXEi8MGOT6Vp1+s1zVp3 EuYjRrSh/1c6Z9gyPaQRN/hTO7xdMZl2IpRWnyzDeu6UogBXNCsX3/ewwKRNmOLG9PKNT+ 5tGVFM8bWeKckbOQSdl+vjX3mvsNT+1Xla9dP25JY1W6FHNPqGenW7Rsq7cAhQ== 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 7B34917C6B; Mon, 4 Apr 2022 19:19:15 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 234JJFem053144; Mon, 4 Apr 2022 19:19:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 234JJFMY053143; Mon, 4 Apr 2022 19:19:15 GMT (envelope-from git) Date: Mon, 4 Apr 2022 19:19:15 GMT Message-Id: <202204041919.234JJFMY053143@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Guzik Subject: git: 792ebbb1557e - stable/13 - vfs: fixup WANTIOCTLCAPS on open 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: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 792ebbb1557e290805d84b87653110681c7338a0 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1649099955; 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=IfcPjfOsa0pmNswmyriJGMSjbHo0ZQqAmPfWqIOlleo=; b=hBJ5w5kzLO6oyoCj9UCX6vMePUpxoot8w3Jr5vPCrj9yBUz8Gsgzkr3QtSLkQEL/Ig1zyd 2v/P7ltXDvsUX1GpuQxiatuYVz9hf63qUoXSzNs3PHLhPbRG6J9iJQCFSJht+WQSvDsp3V BITIOMoHwRhYlJgxHWNLNdwcD3umDzJ0/MGRgoQGqBQ4Mnv71YaSj8qtbK5vmxNDRNAOT9 kTXZaddQsk49LnS2C6OV7kMwO2pf4vS8sHnq1ininGATw1yrFNMPlrN5Y6xeWVvUtiF5wH thKsRjttewadnbFmYXOKfBm676Pf+3kt2F2bAxYEKY2AIhErdHmHPp4IAIcdCA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1649099955; a=rsa-sha256; cv=none; b=OmfZ1eSEvnCpTCmfn5/6nJPUfQIfLDHP2PTZOd0G8QvjI571WhvKp8aMQqO9YWCZrj8TR5 Z4kyav7HolUQByVMcS/JylwSNJ/7uQrfoa6OP3znCfbTMMi9dv5eHQlw44/Q31cTpRw0ZX VMpbnHoap/WvawHP67yU+wbxGioeqxkeTNoBHzbCI3mCQ/pRwtmWtV+Vcxln53cknQ876V 3xWyXc5nrhgTLbMXH8feofOl/y+DNbKzLBDQwNnzr3JMkgCdK2MJ/6J1u+c+AwDIHyvA8E hsppq5xJG2i+CIXuCkLhWUNnydgwJPEW3Ykv4WBuXZNB9Edb+6Yse1ULH56okQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=792ebbb1557e290805d84b87653110681c7338a0 commit 792ebbb1557e290805d84b87653110681c7338a0 Author: Mateusz Guzik AuthorDate: 2022-04-02 18:35:58 +0000 Commit: Mateusz Guzik CommitDate: 2022-04-04 19:17:05 +0000 vfs: fixup WANTIOCTLCAPS on open In some cases vn_open_cred overwrites cn_flags, effectively nullifying initialisation done in NDINIT. This will have to be fixed. In the meantime make sure the flag is passed. Reported by: jenkins Noted by: Mathieu (cherry picked from commit b7262756e2f471f6481070e2473af7853506b150) --- sys/kern/kern_descrip.c | 5 +++++ sys/kern/vfs_syscalls.c | 3 ++- sys/kern/vfs_vnops.c | 2 ++ sys/sys/vnode.h | 1 + 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 8eb83ea44159..b4bb74e02c4e 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -1846,9 +1846,14 @@ filecaps_validate(const struct filecaps *fcaps, const char *func) KASSERT(fcaps->fc_fcntls == 0 || cap_rights_is_set(&fcaps->fc_rights, CAP_FCNTL), ("%s: fcntls without CAP_FCNTL", func)); + /* + * open calls without WANTIOCTLCAPS free caps but leave the counter + */ +#if 0 KASSERT(fcaps->fc_ioctls != NULL ? fcaps->fc_nioctls > 0 : (fcaps->fc_nioctls == -1 || fcaps->fc_nioctls == 0), ("%s: invalid ioctls", func)); +#endif KASSERT(fcaps->fc_nioctls == 0 || cap_rights_is_set(&fcaps->fc_rights, CAP_IOCTL), ("%s: ioctls without CAP_IOCTL", func)); diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index ed75316f8add..32868eb7a4d5 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -1156,7 +1156,8 @@ kern_openat(struct thread *td, int fd, const char *path, enum uio_seg pathseg, NDINIT_ATRIGHTS(&nd, LOOKUP, FOLLOW | AUDITVNODE1 | WANTIOCTLCAPS, pathseg, path, fd, &rights, td); td->td_dupfd = -1; /* XXX check for fdopen */ - error = vn_open(&nd, &flags, cmode, fp); + error = vn_open_cred(&nd, &flags, cmode, VN_OPEN_WANTIOCTLCAPS, + td->td_ucred, fp); if (error != 0) { /* * If the vn_open replaced the method vector, something diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index bde0403b2a51..b82db887b241 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -207,6 +207,8 @@ open2nameif(int fmode, u_int vn_open_flags) res |= AUDITVNODE1; if ((vn_open_flags & VN_OPEN_NOCAPCHECK) != 0) res |= NOCAPCHECK; + if ((vn_open_flags & VN_OPEN_WANTIOCTLCAPS) != 0) + res |= WANTIOCTLCAPS; return (res); } diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h index 66e8a7c0a87e..92978eae8846 100644 --- a/sys/sys/vnode.h +++ b/sys/sys/vnode.h @@ -612,6 +612,7 @@ typedef void vop_getpages_iodone_t(void *, vm_page_t *, int, int); #define VN_OPEN_NOCAPCHECK 0x00000002 #define VN_OPEN_NAMECACHE 0x00000004 #define VN_OPEN_INVFS 0x00000008 +#define VN_OPEN_WANTIOCTLCAPS 0x00000010 /* copy_file_range kernel flags */ #define COPY_FILE_RANGE_KFLAGS 0xff000000