From owner-dev-commits-src-all@freebsd.org Thu Sep 9 01:22:11 2021 Return-Path: Delivered-To: dev-commits-src-all@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 647C2666601; Thu, 9 Sep 2021 01:22:11 +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 4H4h7R2RT6z4rv7; Thu, 9 Sep 2021 01:22:11 +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 31F0910758; Thu, 9 Sep 2021 01:22:11 +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 1891MBMW082842; Thu, 9 Sep 2021 01:22:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1891MBKH082841; Thu, 9 Sep 2021 01:22:11 GMT (envelope-from git) Date: Thu, 9 Sep 2021 01:22:11 GMT Message-Id: <202109090122.1891MBKH082841@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: f09db311a9fb - stable/13 - 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/stable/13 X-Git-Reftype: branch X-Git-Commit: f09db311a9fb52ca74810866dbdf95b79cdd4ca9 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Sep 2021 01:22:11 -0000 The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=f09db311a9fb52ca74810866dbdf95b79cdd4ca9 commit f09db311a9fb52ca74810866dbdf95b79cdd4ca9 Author: Konstantin Belousov AuthorDate: 2021-09-02 04:04:23 +0000 Commit: Konstantin Belousov CommitDate: 2021-09-09 01:21:44 +0000 cluster_write(): do not access buffer after it is released (cherry picked from commit 5cc82c563eda97b70120f06e9635ab6c1c24fecd) --- 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 60f22fd38764..c9af1282fd11 100644 --- a/sys/kern/vfs_cluster.c +++ b/sys/kern/vfs_cluster.c @@ -646,7 +646,7 @@ void cluster_write(struct vnode *vp, 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; @@ -752,14 +752,16 @@ cluster_write(struct vnode *vp, struct buf *bp, u_quad_t filesize, int seqcount, (bp->b_blkno == bp->b_lblkno) && (VOP_BMAP(vp, lbn, NULL, &bp->b_blkno, &maxclen, NULL) || bp->b_blkno == -1)) { + pbn = bp->b_blkno; bawrite(bp); vp->v_clen = 0; - vp->v_lasta = bp->b_blkno; + vp->v_lasta = pbn; vp->v_cstart = lbn + 1; vp->v_lastw = lbn; return; } vp->v_clen = maxclen; + pbn = bp->b_blkno; if (!async && maxclen == 0) { /* I/O not contiguous */ vp->v_cstart = lbn + 1; bawrite(bp); @@ -773,6 +775,7 @@ cluster_write(struct vnode *vp, struct buf *bp, u_quad_t filesize, int seqcount, * 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, vp->v_cstart, @@ -784,15 +787,17 @@ cluster_write(struct vnode *vp, struct buf *bp, u_quad_t filesize, int seqcount, /* * 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); } vp->v_lastw = lbn; - vp->v_lasta = bp->b_blkno; + vp->v_lasta = pbn; } /*