From owner-dev-commits-src-main@freebsd.org Thu Sep 2 18:36:54 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id F24FA663F5C; Thu, 2 Sep 2021 18:36:54 +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 4H0qQZ6RgTz4Sk9; Thu, 2 Sep 2021 18:36:54 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 C60A51E084; Thu, 2 Sep 2021 18:36:54 +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 182IasGM083382; Thu, 2 Sep 2021 18:36:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 182IasYo083381; Thu, 2 Sep 2021 18:36:54 GMT (envelope-from git) Date: Thu, 2 Sep 2021 18:36:54 GMT Message-Id: <202109021836.182IasYo083381@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 5cc82c563eda - main - cluster_write(): do not access buffer after it is released MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 5cc82c563eda97b70120f06e9635ab6c1c24fecd Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Sep 2021 18:36:55 -0000 The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=5cc82c563eda97b70120f06e9635ab6c1c24fecd commit 5cc82c563eda97b70120f06e9635ab6c1c24fecd Author: Konstantin Belousov AuthorDate: 2021-09-02 04:04:23 +0000 Commit: Konstantin Belousov CommitDate: 2021-09-02 18:36:33 +0000 cluster_write(): do not access buffer after it is released The issue was reported by Alexander Lochmann , who found the problem by performing lock analysis using LockDoc, see https://doi.org/10.1145/3302424.3303948. Reviewed by: mckusick Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D31780 --- sys/kern/vfs_cluster.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sys/kern/vfs_cluster.c b/sys/kern/vfs_cluster.c index 7ca67c390b91..d3b303f28f6b 100644 --- a/sys/kern/vfs_cluster.c +++ b/sys/kern/vfs_cluster.c @@ -646,7 +646,7 @@ void cluster_write(struct vnode *vp, struct vn_clusterw *vnc, struct buf *bp, u_quad_t filesize, int seqcount, int gbflags) { - daddr_t lbn; + daddr_t lbn, pbn; int maxclen, cursize; int lblocksize; int async; @@ -753,14 +753,16 @@ cluster_write(struct vnode *vp, struct vn_clusterw *vnc, struct buf *bp, bp->b_blkno == bp->b_lblkno && (VOP_BMAP(vp, lbn, NULL, &bp->b_blkno, &maxclen, NULL) != 0 || bp->b_blkno == -1)) { + pbn = bp->b_blkno; bawrite(bp); vnc->v_clen = 0; - vnc->v_lasta = bp->b_blkno; + vnc->v_lasta = pbn; vnc->v_cstart = lbn + 1; vnc->v_lastw = lbn; return; } vnc->v_clen = maxclen; + pbn = bp->b_blkno; if (!async && maxclen == 0) { /* I/O not contiguous */ vnc->v_cstart = lbn + 1; bawrite(bp); @@ -774,6 +776,7 @@ cluster_write(struct vnode *vp, struct vn_clusterw *vnc, struct buf *bp, * are operating sequentially, otherwise let the buf or * update daemon handle it. */ + pbn = bp->b_blkno; bdwrite(bp); if (seqcount > 1) { cluster_wbuild_wb(vp, lblocksize, vnc->v_cstart, @@ -785,15 +788,17 @@ cluster_write(struct vnode *vp, struct vn_clusterw *vnc, struct buf *bp, /* * We are low on memory, get it going NOW */ + pbn = bp->b_blkno; bawrite(bp); } else { /* * In the middle of a cluster, so just delay the I/O for now. */ + pbn = bp->b_blkno; bdwrite(bp); } vnc->v_lastw = lbn; - vnc->v_lasta = bp->b_blkno; + vnc->v_lasta = pbn; } /*