]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob
b04b4fdadd222406f91398f1223f1e29713d7324
[thirdparty/kernel/stable-queue.git] /
1 From foo@baz Mon Jun 6 07:00:47 PM CEST 2022
2 From: Amir Goldstein <amir73il@gmail.com>
3 Date: Mon, 6 Jun 2022 17:32:51 +0300
4 Subject: xfs: fix incorrect root dquot corruption error when switching group/project quota types
5 To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
6 Cc: Sasha Levin <sashal@kernel.org>, Dave Chinner <david@fromorbit.com>, "Darrick J . Wong" <djwong@kernel.org>, Christoph Hellwig <hch@lst.de>, Brian Foster <bfoster@redhat.com>, Christian Brauner <brauner@kernel.org>, Luis Chamberlain <mcgrof@kernel.org>, Leah Rumancik <leah.rumancik@gmail.com>, Adam Manzanares <a.manzanares@samsung.com>, linux-xfs@vger.kernel.org, stable@vger.kernel.org, Chandan Babu R <chandanrlinux@gmail.com>
7 Message-ID: <20220606143255.685988-5-amir73il@gmail.com>
8
9 From: "Darrick J. Wong" <djwong@kernel.org>
10
11 commit 45068063efb7dd0a8d115c106aa05d9ab0946257 upstream.
12
13 While writing up a regression test for broken behavior when a chprojid
14 request fails, I noticed that we were logging corruption notices about
15 the root dquot of the group/project quota file at mount time when
16 testing V4 filesystems.
17
18 In commit afeda6000b0c, I was trying to improve ondisk dquot validation
19 by making sure that when we load an ondisk dquot into memory on behalf
20 of an incore dquot, the dquot id and type matches. Unfortunately, I
21 forgot that V4 filesystems only have two quota files, and can switch
22 that file between group and project quota types at mount time. When we
23 perform that switch, we'll try to load the default quota limits from the
24 root dquot prior to running quotacheck and log a corruption error when
25 the types don't match.
26
27 This is inconsequential because quotacheck will reset the second quota
28 file as part of doing the switch, but we shouldn't leave scary messages
29 in the kernel log.
30
31 Fixes: afeda6000b0c ("xfs: validate ondisk/incore dquot flags")
32 Signed-off-by: Darrick J. Wong <djwong@kernel.org>
33 Reviewed-by: Brian Foster <bfoster@redhat.com>
34 Reviewed-by: Chandan Babu R <chandanrlinux@gmail.com>
35 Signed-off-by: Amir Goldstein <amir73il@gmail.com>
36 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
37 ---
38 fs/xfs/xfs_dquot.c | 39 +++++++++++++++++++++++++++++++++++++--
39 1 file changed, 37 insertions(+), 2 deletions(-)
40
41 --- a/fs/xfs/xfs_dquot.c
42 +++ b/fs/xfs/xfs_dquot.c
43 @@ -500,6 +500,42 @@ xfs_dquot_alloc(
44 return dqp;
45 }
46
47 +/* Check the ondisk dquot's id and type match what the incore dquot expects. */
48 +static bool
49 +xfs_dquot_check_type(
50 + struct xfs_dquot *dqp,
51 + struct xfs_disk_dquot *ddqp)
52 +{
53 + uint8_t ddqp_type;
54 + uint8_t dqp_type;
55 +
56 + ddqp_type = ddqp->d_type & XFS_DQTYPE_REC_MASK;
57 + dqp_type = xfs_dquot_type(dqp);
58 +
59 + if (be32_to_cpu(ddqp->d_id) != dqp->q_id)
60 + return false;
61 +
62 + /*
63 + * V5 filesystems always expect an exact type match. V4 filesystems
64 + * expect an exact match for user dquots and for non-root group and
65 + * project dquots.
66 + */
67 + if (xfs_sb_version_hascrc(&dqp->q_mount->m_sb) ||
68 + dqp_type == XFS_DQTYPE_USER || dqp->q_id != 0)
69 + return ddqp_type == dqp_type;
70 +
71 + /*
72 + * V4 filesystems support either group or project quotas, but not both
73 + * at the same time. The non-user quota file can be switched between
74 + * group and project quota uses depending on the mount options, which
75 + * means that we can encounter the other type when we try to load quota
76 + * defaults. Quotacheck will soon reset the the entire quota file
77 + * (including the root dquot) anyway, but don't log scary corruption
78 + * reports to dmesg.
79 + */
80 + return ddqp_type == XFS_DQTYPE_GROUP || ddqp_type == XFS_DQTYPE_PROJ;
81 +}
82 +
83 /* Copy the in-core quota fields in from the on-disk buffer. */
84 STATIC int
85 xfs_dquot_from_disk(
86 @@ -512,8 +548,7 @@ xfs_dquot_from_disk(
87 * Ensure that we got the type and ID we were looking for.
88 * Everything else was checked by the dquot buffer verifier.
89 */
90 - if ((ddqp->d_type & XFS_DQTYPE_REC_MASK) != xfs_dquot_type(dqp) ||
91 - be32_to_cpu(ddqp->d_id) != dqp->q_id) {
92 + if (!xfs_dquot_check_type(dqp, ddqp)) {
93 xfs_alert_tag(bp->b_mount, XFS_PTAG_VERIFIER_ERROR,
94 "Metadata corruption detected at %pS, quota %u",
95 __this_address, dqp->q_id);