From nobody Fri Jul 18 14:30:44 2025 X-Original-To: dev-commits-src-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 4bkBzS5TwDz62P3m; Fri, 18 Jul 2025 14:30:44 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bkBzS4F5Nz3rnq; Fri, 18 Jul 2025 14:30:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1752849044; 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=Z75daaBpL/CE3T41H+Y/H++Mol3VU/XB6UqK6qySg9g=; b=R/Am3RF1bV2cwCUM2EJKtxcJgDWE1hkwmSKR8lGlY8HFl2Rm8biqREwnAPsboA7PwRm1xE gPExR/SeYDI62j7N5+xJU4MwEyuh7kgla1/rXS1jpagIeBZihHGq9l/uxqxj2h20jmHxyJ GU40GwUPFPVaGX4pcQpKh2o2AXxfx8useUNDqs4bUDSO6Cj9sdOxpvVOWLM72zbYkwwFae D6eTmwHaVqSSqd4NTAPkC/HUbOz+3Om67zs+2bsTuGQkVjYzDFXjF/93TQx0FOO9ME/cBT SLOluSD0R9OhcSnpj7MatwwEDlOq6+iLT8QTbqAz6CRgWQV/xWXjjIwU45QJbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1752849044; 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=Z75daaBpL/CE3T41H+Y/H++Mol3VU/XB6UqK6qySg9g=; b=nlsyZGskKEzBL56YUl0DZd6cQcKOsCeZQoPncEejSlVlTG7Tl5LyZyaNj2XsqoRBmm6COZ JTJzPTUuN0I8CGx+MSbGQ5inbOJQInqLeYXLoYQpGhdRNaIJoA2M6E7BmUdvg12YIaXLJb 9jTH3GrsdYrOCB/qVWWT5aTcwXjZwKD3wtj1XY5afFZpRjq7iu7eAAkkWihY5JE2nAQgh7 rIQ8gvRD6kEzAdPjV4yRtL9NAwXMY4y06IbLx9ztGlw3gqMWEU9qxm2IyHx0NgX6ISlVrJ nxl+U3ORFs31Ttv7blysRm6QPg4Jw5xMeQAk/RCTBMp8q8MfIX31ji4ZawhA9w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1752849044; a=rsa-sha256; cv=none; b=UyBIQQlUHuBcB9NijX874HH6HzETMkhl4iFZXydyh0kgdb9OPeXyWDXdxaBoNpQJSD01q/ AE2A4dAtTyZW7yC8h3jtQKK5mqLSVoGKDmaUufNP2yqx1qyy3XFcuN0cP/JGJPc3Ny5OvE y1HdZfShzb6jIp49JHC4yxDizMkOATcz96lFvixj+GRSWoakjfjx0UKIyNpIdtnQnmPW1Q s/ODeSaHp3rRNhDRVuWxJMao/uQRNKIoQBezj2bAtB8WONRZM27RzEGyDiaGlFA6OCv7Bw lzORKOQ2KvWdLRNq1OBolexNUz+qxumTItO8ayWyU7PSaAmdK2JgJ+Jwf1VbWA== 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 4bkBzS2cQ0zkbn; Fri, 18 Jul 2025 14:30:44 +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 56IEUi5q064485; Fri, 18 Jul 2025 14:30:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 56IEUiRc064482; Fri, 18 Jul 2025 14:30:44 GMT (envelope-from git) Date: Fri, 18 Jul 2025 14:30:44 GMT Message-Id: <202507181430.56IEUiRc064482@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: af0ec3fa29ca - main - inotify: Fix a couple of locking bugs List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: af0ec3fa29cad823d0196538381f1e832f5974a7 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=af0ec3fa29cad823d0196538381f1e832f5974a7 commit af0ec3fa29cad823d0196538381f1e832f5974a7 Author: Mark Johnston AuthorDate: 2025-07-18 14:25:28 +0000 Commit: Mark Johnston CommitDate: 2025-07-18 14:25:28 +0000 inotify: Fix a couple of locking bugs When hooking vop_rename_post(), the preexisting dst vnode will be unlocked. But, we need to invoke VOP_GETATTR on it in vn_inotify() to check its link count. In inotify_unlink_watch_locked(), the vnode interlock is not held, so don't use vn_irflag_unset_locked(). Reviewed by: kib Fixes: f1f230439fa4 ("vfs: Initial revision of inotify") Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D51401 --- sys/kern/vfs_inotify.c | 5 +++-- sys/sys/inotify.h | 14 +++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/sys/kern/vfs_inotify.c b/sys/kern/vfs_inotify.c index 2b42228465a4..d3cd0d1f9832 100644 --- a/sys/kern/vfs_inotify.c +++ b/sys/kern/vfs_inotify.c @@ -371,7 +371,7 @@ inotify_unlink_watch_locked(struct inotify_softc *sc, struct inotify_watch *watc TAILQ_REMOVE(&vp->v_pollinfo->vpi_inotify, watch, vlink); if (TAILQ_EMPTY(&vp->v_pollinfo->vpi_inotify)) - vn_irflag_unset_locked(vp, VIRF_INOTIFY); + vn_irflag_unset(vp, VIRF_INOTIFY); } /* @@ -675,7 +675,8 @@ vn_inotify(struct vnode *vp, struct vnode *dvp, struct componentname *cnp, struct vattr va; int error; - error = VOP_GETATTR(vp, &va, cnp->cn_cred); + error = VOP_GETATTR(vp, &va, + cnp->cn_cred); if (error == 0 && va.va_nlink != 0) selfevent = 0; } diff --git a/sys/sys/inotify.h b/sys/sys/inotify.h index 65dc5dba43f3..d1f23d5898bb 100644 --- a/sys/sys/inotify.h +++ b/sys/sys/inotify.h @@ -107,11 +107,18 @@ void vn_inotify_revoke(struct vnode *); } while (0) /* Log an inotify event using a specific name for the vnode. */ -#define INOTIFY_NAME(vp, dvp, cnp, ev) do { \ +#define INOTIFY_NAME_LOCK(vp, dvp, cnp, ev, lock) do { \ if (__predict_false((vn_irflag_read(vp) & VIRF_INOTIFY) != 0 || \ - (vn_irflag_read(dvp) & VIRF_INOTIFY) != 0)) \ + (vn_irflag_read(dvp) & VIRF_INOTIFY) != 0)) { \ + if (lock) \ + vn_lock((vp), LK_SHARED | LK_RETRY); \ VOP_INOTIFY((vp), (dvp), (cnp), (ev), 0); \ + if (lock) \ + VOP_UNLOCK(vp); \ + } \ } while (0) +#define INOTIFY_NAME(vp, dvp, cnp, ev) \ + INOTIFY_NAME_LOCK((vp), (dvp), (cnp), (ev), false) extern __uint32_t inotify_rename_cookie; @@ -126,7 +133,8 @@ extern __uint32_t inotify_rename_cookie; VOP_INOTIFY((vp), (tdvp), (tcnp), IN_MOVED_TO, cookie); \ } \ if ((tvp) != NULL) \ - INOTIFY_NAME((tvp), (tdvp), (tcnp), _IN_MOVE_DELETE); \ + INOTIFY_NAME_LOCK((tvp), (tdvp), (tcnp), \ + _IN_MOVE_DELETE, true); \ } while (0) #define INOTIFY_REVOKE(vp) do { \