Skip to content

Commit b46ae77

Browse files
committed
Merge tag 'xfs-6.7-fixes-3' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
Pull xfs fix from Chandan Babu: - Validate quota records recovered from the log before writing them to the disk. * tag 'xfs-6.7-fixes-3' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux: xfs: dquot recovery does not validate the recovered dquot xfs: clean up dqblk extraction
2 parents 2821c39 + 9c235df commit b46ae77

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

fs/xfs/xfs_dquot.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,8 @@ xfs_dquot_from_disk(
562562
struct xfs_dquot *dqp,
563563
struct xfs_buf *bp)
564564
{
565-
struct xfs_disk_dquot *ddqp = bp->b_addr + dqp->q_bufoffset;
565+
struct xfs_dqblk *dqb = xfs_buf_offset(bp, dqp->q_bufoffset);
566+
struct xfs_disk_dquot *ddqp = &dqb->dd_diskdq;
566567

567568
/*
568569
* Ensure that we got the type and ID we were looking for.
@@ -1250,7 +1251,7 @@ xfs_qm_dqflush(
12501251
}
12511252

12521253
/* Flush the incore dquot to the ondisk buffer. */
1253-
dqblk = bp->b_addr + dqp->q_bufoffset;
1254+
dqblk = xfs_buf_offset(bp, dqp->q_bufoffset);
12541255
xfs_dquot_to_disk(&dqblk->dd_diskdq, dqp);
12551256

12561257
/*

fs/xfs/xfs_dquot_item_recover.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "xfs_log.h"
2020
#include "xfs_log_priv.h"
2121
#include "xfs_log_recover.h"
22+
#include "xfs_error.h"
2223

2324
STATIC void
2425
xlog_recover_dquot_ra_pass2(
@@ -65,6 +66,7 @@ xlog_recover_dquot_commit_pass2(
6566
{
6667
struct xfs_mount *mp = log->l_mp;
6768
struct xfs_buf *bp;
69+
struct xfs_dqblk *dqb;
6870
struct xfs_disk_dquot *ddq, *recddq;
6971
struct xfs_dq_logformat *dq_f;
7072
xfs_failaddr_t fa;
@@ -130,14 +132,14 @@ xlog_recover_dquot_commit_pass2(
130132
return error;
131133

132134
ASSERT(bp);
133-
ddq = xfs_buf_offset(bp, dq_f->qlf_boffset);
135+
dqb = xfs_buf_offset(bp, dq_f->qlf_boffset);
136+
ddq = &dqb->dd_diskdq;
134137

135138
/*
136139
* If the dquot has an LSN in it, recover the dquot only if it's less
137140
* than the lsn of the transaction we are replaying.
138141
*/
139142
if (xfs_has_crc(mp)) {
140-
struct xfs_dqblk *dqb = (struct xfs_dqblk *)ddq;
141143
xfs_lsn_t lsn = be64_to_cpu(dqb->dd_lsn);
142144

143145
if (lsn && lsn != -1 && XFS_LSN_CMP(lsn, current_lsn) >= 0) {
@@ -147,10 +149,23 @@ xlog_recover_dquot_commit_pass2(
147149

148150
memcpy(ddq, recddq, item->ri_buf[1].i_len);
149151
if (xfs_has_crc(mp)) {
150-
xfs_update_cksum((char *)ddq, sizeof(struct xfs_dqblk),
152+
xfs_update_cksum((char *)dqb, sizeof(struct xfs_dqblk),
151153
XFS_DQUOT_CRC_OFF);
152154
}
153155

156+
/* Validate the recovered dquot. */
157+
fa = xfs_dqblk_verify(log->l_mp, dqb, dq_f->qlf_id);
158+
if (fa) {
159+
XFS_CORRUPTION_ERROR("Bad dquot after recovery",
160+
XFS_ERRLEVEL_LOW, mp, dqb,
161+
sizeof(struct xfs_dqblk));
162+
xfs_alert(mp,
163+
"Metadata corruption detected at %pS, dquot 0x%x",
164+
fa, dq_f->qlf_id);
165+
error = -EFSCORRUPTED;
166+
goto out_release;
167+
}
168+
154169
ASSERT(dq_f->qlf_size == 2);
155170
ASSERT(bp->b_mount == mp);
156171
bp->b_flags |= _XBF_LOGRECOVERY;

0 commit comments

Comments
 (0)