]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
ocfs2: fix ocfs2 corrupt when iputting an inode
authorWangyan <wangyan122@huawei.com>
Mon, 23 Aug 2021 23:58:53 +0000 (09:58 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Wed, 25 Aug 2021 23:33:24 +0000 (09:33 +1000)
In this condition, it will cause an bug on error.
ocfs2_mkdir()
  ->ocfs2_mknod()
    ->ocfs2_mknod_locked()
      ->__ocfs2_mknod_locked()
        //Assume inode->i_generation is genN.
        ->inode->i_generation = osb->s_next_generation++;
        // The inode lockres has been initialized.
        ->ocfs2_populate_inode()
        ->ocfs2_create_new_inode_locks()
            ->An error happened, returned value is non-zero
      // free the start_bit x in bg_blkno
      ->ocfs2_free_suballoc_bits()
    ->...  /* Another process execute mkdir success in this place,
              and it occupied the start_bit x in bg_blkno
              which has been freed before. Its inode->i_generation
              is genN + 1 */
    ->iput(inode)
      ->evict()
        ->ocfs2_evict_inode()
          ->ocfs2_delete_inode()
            ->ocfs2_inode_lock()
              ->ocfs2_inode_lock_update()
                /* Bug on here, genN != genN + 1 */
                ->mlog_bug_on_msg(inode->i_generation !=
                  le32_to_cpu(fe->i_generation))

So, we need not to reclaim the inode when the inode->ip_inode_lockres
has been initialized. It will be freed in iput().

Link: http://lkml.kernel.org/r/ef080ca3-5d74-e276-17a1-d9e7c7e662c9@huawei.com
Fixes: b1529a41f777 ("ocfs2: should reclaim the inode if '__ocfs2_mknod_locked' returns an error")
Signed-off-by: Yan Wang <wangyan122@huawei.com>
Reviewed-by: Jun Piao <piaojun@huawei.com>
Cc: Mark Fasheh <mark@fasheh.com>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Junxiao Bi <junxiao.bi@oracle.com>
Cc: Joseph Qi <jiangqi903@gmail.com>
Cc: Changwei Ge <gechangwei@live.cn>
Cc: Gang He <ghe@suse.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
fs/ocfs2/namei.c

index a5c975715aa05a3d3aa58fd75c7234e2634701ac..0939186f010e32115a5e6b6a98aa22174c06e16a 100644 (file)
@@ -640,7 +640,8 @@ static int ocfs2_mknod_locked(struct ocfs2_super *osb,
        status = __ocfs2_mknod_locked(dir, inode, dev, new_fe_bh,
                                    parent_fe_bh, handle, inode_ac,
                                    fe_blkno, suballoc_loc, suballoc_bit);
-       if (status < 0) {
+       if (status < 0 && !(OCFS2_I(inode)->ip_inode_lockres.l_flags &
+                               OCFS2_LOCK_INITIALIZED)) {
                u64 bg_blkno = ocfs2_which_suballoc_group(fe_blkno, suballoc_bit);
                int tmp = ocfs2_free_suballoc_bits(handle, inode_ac->ac_inode,
                                inode_ac->ac_bh, suballoc_bit, bg_blkno, 1);