From nobody Fri Dec 15 22:09:19 2023 X-Original-To: dev-commits-src-all@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 4SsNfm10gpz5497q; Fri, 15 Dec 2023 22:09:20 +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 4SsNfl59Z2z3dqq; Fri, 15 Dec 2023 22:09:19 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1702678159; 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=tIfifwJku5x5ey3DQ6YR5eqfzLXkwLNcdkuUMJUvJm0=; b=nMl3q+Upasui2PmYVepIt4BEcks5uhDe37mKmSSTRNHULqICnoViLcYrBU1ZN7qcjkAQNP fVJcWzWUTfryyFKnAUm/xHhOffw74fIVpJsuWuMiHalppMTPouUOqFd9cBxwVazP175CUe 9u34/XJHFFlxiQnxjIDkrmnhmnSHT7RDwZ0SD7h3hoSkHgUdu72G4St06ta/w0kY9l7LXn sT3aOJ2iPKeWXjR2l/z6EcYy01WZf19/tkPf4abh4luxXx4PXnRLK1MQdPalYOOUmNnWvm /WtCFwv7vHp6/5FQf2f2r4jFYa+voY3bOOxl5IBg1odYOeKHOv2Q3ASbqkBfWQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1702678159; a=rsa-sha256; cv=none; b=I/LCkjF3I9Do4ZmGH5ZO+h+laInIuuQKOfJNik7TPamYjnwY2b0eBTFlqMvWRsQV3VQwHe jrKZUJfulPqIT34J3jEYTGN3E7wB+ERf0FnlAkqAXHJdaQc+1W+7BAj2llVJHt828Y6zZV KcpdYUdITu6d1ganfIbHSbppRtejmrbBm50wt6mZIzeWuw55aVhZbeuCj+dRnO3OgxzPMm CRSje7ajwzFayOwZoBHePVxG87oMdfzO+s4hZ+dwRxbTqIsALdSm/m6Sg09ic26re1lAlY v0DaLxhL5KbwRHGOLiSRc0Dvfw4ybhfi6Q+NQUhtq537lg1ycicc12tRgHsfwA== 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=1702678159; 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=tIfifwJku5x5ey3DQ6YR5eqfzLXkwLNcdkuUMJUvJm0=; b=NpY5EkHBusQvA+vcuuxRiZ5gAZJkS2IFdB0qwIdws4pHYY7CLgbBgda8zSybdqQV9bJ9Vx FdpeGmF7Jb2166lm8vdkDsXOSQQsdMIWOVE4lHZz/78PMCOtNs2Y26hb4Mh3miyYTygmQY p9WUqxcY4eOE+tlyZKwDcYrJxj6FmH1hhvA7wuVl8iUYyNeVnQbma0iL4jSTspW+tZop+q tY+NeNp2vC+kf6phzknynjGolR3JNLorfs50hvFVT3Jp71IMr05Fy07jfT7NpFZMozA9k3 8Zn8ym0C646QxhQ2x88b2AlLAnNX+kbb/c0mXKHWY5BPvWREqYFoknMX1E214g== 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 4SsNfl4DtLzD8k; Fri, 15 Dec 2023 22:09:19 +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 3BFM9JYQ038545; Fri, 15 Dec 2023 22:09:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BFM9J2o038542; Fri, 15 Dec 2023 22:09:19 GMT (envelope-from git) Date: Fri, 15 Dec 2023 22:09:19 GMT Message-Id: <202312152209.3BFM9J2o038542@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: ca39f23347e1 - main - ufs: do not leave around empty buffers shadowing disk content List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org 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: ca39f23347e1416a28dde13279bfe5841ad9a746 Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=ca39f23347e1416a28dde13279bfe5841ad9a746 commit ca39f23347e1416a28dde13279bfe5841ad9a746 Author: Konstantin Belousov AuthorDate: 2023-12-11 22:57:28 +0000 Commit: Konstantin Belousov CommitDate: 2023-12-15 22:06:10 +0000 ufs: do not leave around empty buffers shadowing disk content If the ffs_write() operation specified to overwrite the whole buffer, ffs tries to save the read by not validating allocated buffer. Then uiommove() might fail with EFAULT, in which case pages are left zeroed and marked valid but not read from the disk. Then vn_io_fault() logic retries the write after holding the user pages to avoid EFAULTs. In erronous case of really faulty buffer, or in contrived case of writing from file to itself, we are left with zeroed buffer instead of valid content written back to disk. Handle the situation by releasing non-cached buffer on fault, instead of clearing it. Note that buffers with alive dependencies cannot be released, but also either they cannot have valid content on the disk because dependency on data buffer means that it was not yet written, or they were reallocated by fragment extension or ffs_reallocbks(), and are already fully valid. Reported by: kevans Discussed with: mav In collaboration with: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week --- sys/ufs/ffs/ffs_vnops.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sys/ufs/ffs/ffs_vnops.c b/sys/ufs/ffs/ffs_vnops.c index 0a327aab155b..e9849008cde2 100644 --- a/sys/ufs/ffs/ffs_vnops.c +++ b/sys/ufs/ffs/ffs_vnops.c @@ -978,8 +978,15 @@ ffs_write( * validated the pages. */ if (error != 0 && (bp->b_flags & B_CACHE) == 0 && - fs->fs_bsize == xfersize) - vfs_bio_clrbuf(bp); + fs->fs_bsize == xfersize) { + if (error == EFAULT && LIST_EMPTY(&bp->b_dep)) { + bp->b_flags |= B_INVAL | B_RELBUF | B_NOCACHE; + brelse(bp); + break; + } else { + vfs_bio_clrbuf(bp); + } + } vfs_bio_set_flags(bp, ioflag);