From nobody Mon Jan 20 02:40:37 2025 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 4Ybvhj3JVbz5k6pb; Mon, 20 Jan 2025 02:40:37 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Ybvhj28qNz3p13; Mon, 20 Jan 2025 02:40:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737340837; 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=xLLwKh+1QMyrDSwPpftDcmXMUVKloqqAjK6KQvDh31A=; b=aPHrlF4fGS17XsgoXTeh8q/GuHIsek5Z+kZ1RjQ/Ke0oLiEwTz9LgnFEh03MeKeK+VBsV0 39H0NmYYFxa/b9eCdXIUcapm9L5yI+TMYhcsmBnFBuUI+rOleTeM2kNnyLM8UsnBcwUmZn nTVlmoTsKO0hfkl+vQ3GW98vSN3GeB8TYND8tj26MGlpx8WeY6N6Amt2HmOxgO89ZR92F3 ueagsJEjbidbkgZZjbsdX20v6u4fKVMyY23WJg1ifBFUyQ7CWhXQjF4rWiA6Hlma6WY4qK Bm+bYc/aEV13TvlmXCff3yNMBa/hTS0eLfyG/YsmHmocM5s03U4JV1Jrl/pQ3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737340837; 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=xLLwKh+1QMyrDSwPpftDcmXMUVKloqqAjK6KQvDh31A=; b=UsVE45LVMV464hGXE1J0eqNw9fxUnkbDpBBKYcGnBf2If0ypyprF/Qo26+0fUMkp1RL8G0 QVWgqnyUZMm3NOGoql0nRFsezYNGCJaBD6jwyXa4vEafB/60+QuJBKGP2zOkX2O6d5YTgk RTitUH5QROI7vx0/H5jSdWlZzm9KA33ymlXBxmDt9ZcWyHEyswxhPCRnpfxWsYDlJ7agVO 4TqKDwwrAXByKdRG6jpKhI8iWZDR4Ip69suy+J0hIdQlx++E3nvdI3iev6LvS61DVNayaX dH9Il/vnPESYTdTDNw7XgR/Go0ttH5UcvZuAKv+oTftLXxHieiwJcmyqsXy+MA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1737340837; a=rsa-sha256; cv=none; b=WDCPvndWq3BxuR53LaGh5VcIkjGswo/BHIKbtcsOeGND5BjP8Fn5h7DNB6+lWEBIKkDE2A aomdZse5AImtDczDnx0hkJR+kngZHoobfm4NurSUpxTnfJGW96BCgRCi3TsAubXeMybkDD W0yvBpLahlFC21tjWx1bv6PAokrieEJDCCR2PUK6GOFnyGjeLiFscGm06POnAkepi5pIoM 3DZK02kQRoJzD3eBI+oowC+Qw2C98WOs7CKpOrPkCArsjIS1AE9i52C/ef20Fklnkn7hSz U+hoSZD8EzsIKoDA0qr0ea9zlYBeRJGJdWuL8fljBYbAl+12NBMO5AI5DRIVXg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4Ybvhj1Prmz1Fxj; Mon, 20 Jan 2025 02:40:37 +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 50K2ebFv069541; Mon, 20 Jan 2025 02:40:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50K2eb44069534; Mon, 20 Jan 2025 02:40:37 GMT (envelope-from git) Date: Mon, 20 Jan 2025 02:40:37 GMT Message-Id: <202501200240.50K2eb44069534@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: 6149261d549b - stable/14 - ffs_reallocblks(): ensure that pref cg is valid 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-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/stable/14 X-Git-Reftype: branch X-Git-Commit: 6149261d549b3b5072fe69b498f26e8172de1623 Auto-Submitted: auto-generated The branch stable/14 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=6149261d549b3b5072fe69b498f26e8172de1623 commit 6149261d549b3b5072fe69b498f26e8172de1623 Author: Konstantin Belousov AuthorDate: 2025-01-05 22:51:23 +0000 Commit: Konstantin Belousov CommitDate: 2025-01-20 02:40:09 +0000 ffs_reallocblks(): ensure that pref cg is valid (cherry picked from commit dc37121d3210d08c96a883ebfed780660e7e2b39) --- sys/ufs/ffs/ffs_alloc.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/sys/ufs/ffs/ffs_alloc.c b/sys/ufs/ffs/ffs_alloc.c index d08a51264fdb..b586ab8e126a 100644 --- a/sys/ufs/ffs/ffs_alloc.c +++ b/sys/ufs/ffs/ffs_alloc.c @@ -683,6 +683,7 @@ ffs_reallocblks_ufs1( * groups that we will search. */ cg = dtog(fs, pref); + MPASS(cg < fs->fs_ncg); for (i = min(maxclustersearch, fs->fs_ncg); i > 0; i--) { if ((newblk = ffs_clusteralloc(ip, cg, pref, len)) != 0) break; @@ -949,6 +950,7 @@ ffs_reallocblks_ufs2( * groups that we will search. */ cg = dtog(fs, pref); + MPASS(cg < fs->fs_ncg); for (i = min(maxclustersearch, fs->fs_ncg); i > 0; i--) { if ((newblk = ffs_clusteralloc(ip, cg, pref, len)) != 0) break; @@ -1440,8 +1442,11 @@ ffs_blkpref_ufs1(struct inode *ip, * place it immediately following the last direct block. */ if (indx == -1 && lbn < UFS_NDADDR + NINDIR(fs) && - ip->i_din1->di_db[UFS_NDADDR - 1] != 0) + ip->i_din1->di_db[UFS_NDADDR - 1] != 0) { pref = ip->i_din1->di_db[UFS_NDADDR - 1] + fs->fs_frag; + if (dtog(fs, pref) >= fs->fs_ncg) + pref = 0; + } return (pref); } /* @@ -1452,8 +1457,11 @@ ffs_blkpref_ufs1(struct inode *ip, if (lbn == UFS_NDADDR) { pref = ip->i_din1->di_ib[0]; if (pref != 0 && pref >= cgdata(fs, inocg) && - pref < cgbase(fs, inocg + 1)) + pref < cgbase(fs, inocg + 1)) { + if (dtog(fs, pref + fs->fs_frag) >= fs->fs_ncg) + return (0); return (pref + fs->fs_frag); + } } /* * If we are at the beginning of a file, or we have already allocated @@ -1508,6 +1516,8 @@ ffs_blkpref_ufs1(struct inode *ip, /* * Otherwise, we just always try to lay things out contiguously. */ + if (dtog(fs, prevbn + fs->fs_frag) >= fs->fs_ncg) + return (0); return (prevbn + fs->fs_frag); } @@ -1552,8 +1562,11 @@ ffs_blkpref_ufs2(struct inode *ip, * place it immediately following the last direct block. */ if (indx == -1 && lbn < UFS_NDADDR + NINDIR(fs) && - ip->i_din2->di_db[UFS_NDADDR - 1] != 0) + ip->i_din2->di_db[UFS_NDADDR - 1] != 0) { pref = ip->i_din2->di_db[UFS_NDADDR - 1] + fs->fs_frag; + if (dtog(fs, pref) >= fs->fs_ncg) + pref = 0; + } return (pref); } /* @@ -1564,8 +1577,11 @@ ffs_blkpref_ufs2(struct inode *ip, if (lbn == UFS_NDADDR) { pref = ip->i_din2->di_ib[0]; if (pref != 0 && pref >= cgdata(fs, inocg) && - pref < cgbase(fs, inocg + 1)) + pref < cgbase(fs, inocg + 1)) { + if (dtog(fs, pref + fs->fs_frag) >= fs->fs_ncg) + return (0); return (pref + fs->fs_frag); + } } /* * If we are at the beginning of a file, or we have already allocated @@ -1620,6 +1636,8 @@ ffs_blkpref_ufs2(struct inode *ip, /* * Otherwise, we just always try to lay things out contiguously. */ + if (dtog(fs, prevbn + fs->fs_frag) >= fs->fs_ncg) + return (0); return (prevbn + fs->fs_frag); } @@ -1970,6 +1988,7 @@ ffs_clusteralloc(struct inode *ip, ump = ITOUMP(ip); fs = ump->um_fs; + MPASS(cg < fs->fs_ncg); if (fs->fs_maxcluster[cg] < len) return (0); UFS_UNLOCK(ump);