From owner-dev-commits-src-branches@freebsd.org Tue May 18 20:22:43 2021 Return-Path: Delivered-To: dev-commits-src-branches@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 6FF286568F0; Tue, 18 May 2021 20:22:43 +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 4Fl6r32n08z4s2n; Tue, 18 May 2021 20:22:43 +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 4833D25CE8; Tue, 18 May 2021 20:22:43 +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 14IKMhxN004499; Tue, 18 May 2021 20:22:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 14IKMhSO004498; Tue, 18 May 2021 20:22:43 GMT (envelope-from git) Date: Tue, 18 May 2021 20:22:43 GMT Message-Id: <202105182022.14IKMhSO004498@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kirk McKusick Subject: git: e2a49768a4ad - stable/13 - Ensure that files with no allocated blocks are trimmed to zero length. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mckusick X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: e2a49768a4ad938c4dc0b9ce11298b409832a9ab Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 May 2021 20:22:43 -0000 The branch stable/13 has been updated by mckusick: URL: https://cgit.FreeBSD.org/src/commit/?id=e2a49768a4ad938c4dc0b9ce11298b409832a9ab commit e2a49768a4ad938c4dc0b9ce11298b409832a9ab Author: Kirk McKusick AuthorDate: 2021-05-11 21:51:06 +0000 Commit: Kirk McKusick CommitDate: 2021-05-18 20:26:00 +0000 Ensure that files with no allocated blocks are trimmed to zero length. (cherry picked from commit a3628327e7b62c955e7bad9e43044cdb01984d80) --- sbin/fsck_ffs/pass1.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/sbin/fsck_ffs/pass1.c b/sbin/fsck_ffs/pass1.c index c1f1b1ec04f5..319a324cc070 100644 --- a/sbin/fsck_ffs/pass1.c +++ b/sbin/fsck_ffs/pass1.c @@ -248,7 +248,7 @@ checkinode(ino_t inumber, struct inodesc *idesc, int rebuildcg) off_t kernmaxfilesize; ufs2_daddr_t ndb; mode_t mode; - uintmax_t fixsize; + intmax_t size, fixsize; int j, ret, offset; if ((dp = getnextinode(inumber, rebuildcg)) == NULL) @@ -429,25 +429,37 @@ checkinode(ino_t inumber, struct inodesc *idesc, int rebuildcg) } } /* + * UFS does not allow files to end with a hole; it requires that + * the last block of a file be allocated. The last allocated block + * in a file is tracked in id_lballoc. Here, we check for a size + * past the last allocated block of the file and if that is found, + * shorten the file to reference the last allocated block to avoid + * having it reference a hole at its end. + * * Soft updates will always ensure that the file size is correct * for files that contain only direct block pointers. However * soft updates does not roll back sizes for files with indirect * blocks that it has set to unallocated because their contents * have not yet been written to disk. Hence, the file can appear * to have a hole at its end because the block pointer has been - * rolled back to zero. Thus, id_lballoc tracks the last allocated - * block in the file. Here, for files that extend into indirect - * blocks, we check for a size past the last allocated block of - * the file and if that is found, shorten the file to reference - * the last allocated block to avoid having it reference a hole - * at its end. + * rolled back to zero. Thus finding a hole at the end of a file + * that is located in an indirect block receives only a warning + * while finding a hole at the end of a file in a direct block + * receives a fatal error message. */ - if (DIP(dp, di_size) > UFS_NDADDR * sblock.fs_bsize && - idesc->id_lballoc < lblkno(&sblock, DIP(dp, di_size) - 1)) { - fixsize = lblktosize(&sblock, idesc->id_lballoc + 1); - pwarn("INODE %lu: FILE SIZE %ju BEYOND END OF ALLOCATED FILE, " - "SIZE SHOULD BE %ju", (u_long)inumber, - (uintmax_t)DIP(dp, di_size), fixsize); + size = DIP(dp, di_size); + if (idesc->id_lballoc < lblkno(&sblock, size - 1) && + /* exclude embedded symbolic links */ + ((mode != IFLNK) || size >= sblock.fs_maxsymlinklen)) { + fixsize = lblktosize(&sblock, idesc->id_lballoc + 1); + if (size > UFS_NDADDR * sblock.fs_bsize) + pwarn("INODE %lu: FILE SIZE %ju BEYOND END OF " + "ALLOCATED FILE, SIZE SHOULD BE %ju", + (u_long)inumber, size, fixsize); + else + pfatal("INODE %lu: FILE SIZE %ju BEYOND END OF " + "ALLOCATED FILE, SIZE SHOULD BE %ju", + (u_long)inumber, size, fixsize); if (preen) printf(" (ADJUSTED)\n"); else if (reply("ADJUST") == 0)