Skip to content

Commit

Permalink
ubifs: Check link count of inodes when killing orphans.
Browse files Browse the repository at this point in the history
O_TMPFILE files can change their link count back to non-zero.
This corner case needs to get addressed in the orphans subsystem
too.

Fixes: 474b937 ("ubifs: Implement O_TMPFILE")
Reported-by: Lars Persson <lists@bofh.nu>
Signed-off-by: Richard Weinberger <richard@nod.at>
  • Loading branch information
richardweinberger committed Jul 8, 2019
1 parent eeabb98 commit ee1438c
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions fs/ubifs/orphan.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ static int do_kill_orphans(struct ubifs_info *c, struct ubifs_scan_leb *sleb,
{
struct ubifs_scan_node *snod;
struct ubifs_orph_node *orph;
struct ubifs_ino_node *ino = NULL;
unsigned long long cmt_no;
ino_t inum;
int i, n, err, first = 1;
Expand Down Expand Up @@ -676,23 +677,40 @@ static int do_kill_orphans(struct ubifs_info *c, struct ubifs_scan_leb *sleb,
if (first)
first = 0;

ino = kmalloc(UBIFS_MAX_INO_NODE_SZ, GFP_NOFS);
if (!ino)
return -ENOMEM;

n = (le32_to_cpu(orph->ch.len) - UBIFS_ORPH_NODE_SZ) >> 3;
for (i = 0; i < n; i++) {
union ubifs_key key1, key2;

inum = le64_to_cpu(orph->inos[i]);
dbg_rcvry("deleting orphaned inode %lu",
(unsigned long)inum);

lowest_ino_key(c, &key1, inum);
highest_ino_key(c, &key2, inum);

err = ubifs_tnc_remove_range(c, &key1, &key2);
ino_key_init(c, &key1, inum);
err = ubifs_tnc_lookup(c, &key1, ino);
if (err)
return err;
goto out_free;

/*
* Check whether an inode can really get deleted.
* linkat() with O_TMPFILE allows rebirth of an inode.
*/
if (ino->nlink == 0) {
dbg_rcvry("deleting orphaned inode %lu",
(unsigned long)inum);

lowest_ino_key(c, &key1, inum);
highest_ino_key(c, &key2, inum);

err = ubifs_tnc_remove_range(c, &key1, &key2);
if (err)
goto out_ro;
}

err = insert_dead_orphan(c, inum);
if (err)
return err;
goto out_free;
}

*last_cmt_no = cmt_no;
Expand All @@ -704,7 +722,15 @@ static int do_kill_orphans(struct ubifs_info *c, struct ubifs_scan_leb *sleb,
*last_flagged = 0;
}

return 0;
err = 0;
out_free:
kfree(ino);
return err;

out_ro:
ubifs_ro_mode(c, err);
kfree(ino);
return err;
}

/**
Expand Down

0 comments on commit ee1438c

Please sign in to comment.