Skip to content

Commit a6590b9

Browse files
committed
Merge tag 'upstream-3.9-rc1' of git://git.infradead.org/linux-ubifs
Pull ubifs updates from Artem Bityutskiy: "It's been quite silent and we have only a couple of bug-fixes for the orphans handling code plus one cosmetic change." * tag 'upstream-3.9-rc1' of git://git.infradead.org/linux-ubifs: UBIFS: fix double free of ubifs_orphan objects UBIFS: fix use of freed ubifs_orphan objects UBIFS: rename random32() to prandom_u32()
2 parents 1085db4 + 8afd500 commit a6590b9

5 files changed

Lines changed: 27 additions & 15 deletions

File tree

‎fs/ubifs/debug.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2459,7 +2459,7 @@ int dbg_check_nondata_nodes_order(struct ubifs_info *c, struct list_head *head)
24592459

24602460
static inline int chance(unsigned int n, unsigned int out_of)
24612461
{
2462-
return !!((random32() % out_of) + 1 <= n);
2462+
return !!((prandom_u32() % out_of) + 1 <= n);
24632463

24642464
}
24652465

@@ -2477,13 +2477,13 @@ static int power_cut_emulated(struct ubifs_info *c, int lnum, int write)
24772477
if (chance(1, 2)) {
24782478
d->pc_delay = 1;
24792479
/* Fail withing 1 minute */
2480-
delay = random32() % 60000;
2480+
delay = prandom_u32() % 60000;
24812481
d->pc_timeout = jiffies;
24822482
d->pc_timeout += msecs_to_jiffies(delay);
24832483
ubifs_warn("failing after %lums", delay);
24842484
} else {
24852485
d->pc_delay = 2;
2486-
delay = random32() % 10000;
2486+
delay = prandom_u32() % 10000;
24872487
/* Fail within 10000 operations */
24882488
d->pc_cnt_max = delay;
24892489
ubifs_warn("failing after %lu calls", delay);
@@ -2563,7 +2563,7 @@ static int corrupt_data(const struct ubifs_info *c, const void *buf,
25632563
unsigned int from, to, ffs = chance(1, 2);
25642564
unsigned char *p = (void *)buf;
25652565

2566-
from = random32() % (len + 1);
2566+
from = prandom_u32() % (len + 1);
25672567
/* Corruption may only span one max. write unit */
25682568
to = min(len, ALIGN(from, c->max_write_size));
25692569

‎fs/ubifs/lpt_commit.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2007,28 +2007,28 @@ static int dbg_populate_lsave(struct ubifs_info *c)
20072007

20082008
if (!dbg_is_chk_gen(c))
20092009
return 0;
2010-
if (random32() & 3)
2010+
if (prandom_u32() & 3)
20112011
return 0;
20122012

20132013
for (i = 0; i < c->lsave_cnt; i++)
20142014
c->lsave[i] = c->main_first;
20152015

20162016
list_for_each_entry(lprops, &c->empty_list, list)
2017-
c->lsave[random32() % c->lsave_cnt] = lprops->lnum;
2017+
c->lsave[prandom_u32() % c->lsave_cnt] = lprops->lnum;
20182018
list_for_each_entry(lprops, &c->freeable_list, list)
2019-
c->lsave[random32() % c->lsave_cnt] = lprops->lnum;
2019+
c->lsave[prandom_u32() % c->lsave_cnt] = lprops->lnum;
20202020
list_for_each_entry(lprops, &c->frdi_idx_list, list)
2021-
c->lsave[random32() % c->lsave_cnt] = lprops->lnum;
2021+
c->lsave[prandom_u32() % c->lsave_cnt] = lprops->lnum;
20222022

20232023
heap = &c->lpt_heap[LPROPS_DIRTY_IDX - 1];
20242024
for (i = 0; i < heap->cnt; i++)
2025-
c->lsave[random32() % c->lsave_cnt] = heap->arr[i]->lnum;
2025+
c->lsave[prandom_u32() % c->lsave_cnt] = heap->arr[i]->lnum;
20262026
heap = &c->lpt_heap[LPROPS_DIRTY - 1];
20272027
for (i = 0; i < heap->cnt; i++)
2028-
c->lsave[random32() % c->lsave_cnt] = heap->arr[i]->lnum;
2028+
c->lsave[prandom_u32() % c->lsave_cnt] = heap->arr[i]->lnum;
20292029
heap = &c->lpt_heap[LPROPS_FREE - 1];
20302030
for (i = 0; i < heap->cnt; i++)
2031-
c->lsave[random32() % c->lsave_cnt] = heap->arr[i]->lnum;
2031+
c->lsave[prandom_u32() % c->lsave_cnt] = heap->arr[i]->lnum;
20322032

20332033
return 1;
20342034
}

‎fs/ubifs/orphan.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,14 @@ void ubifs_delete_orphan(struct ubifs_info *c, ino_t inum)
126126
else if (inum > o->inum)
127127
p = p->rb_right;
128128
else {
129-
if (o->dnext) {
129+
if (o->del) {
130130
spin_unlock(&c->orphan_lock);
131131
dbg_gen("deleted twice ino %lu",
132132
(unsigned long)inum);
133133
return;
134134
}
135-
if (o->cnext) {
135+
if (o->cmt) {
136+
o->del = 1;
136137
o->dnext = c->orph_dnext;
137138
c->orph_dnext = o;
138139
spin_unlock(&c->orphan_lock);
@@ -172,7 +173,9 @@ int ubifs_orphan_start_commit(struct ubifs_info *c)
172173
last = &c->orph_cnext;
173174
list_for_each_entry(orphan, &c->orph_new, new_list) {
174175
ubifs_assert(orphan->new);
176+
ubifs_assert(!orphan->cmt);
175177
orphan->new = 0;
178+
orphan->cmt = 1;
176179
*last = orphan;
177180
last = &orphan->cnext;
178181
}
@@ -299,7 +302,9 @@ static int write_orph_node(struct ubifs_info *c, int atomic)
299302
cnext = c->orph_cnext;
300303
for (i = 0; i < cnt; i++) {
301304
orphan = cnext;
305+
ubifs_assert(orphan->cmt);
302306
orph->inos[i] = cpu_to_le64(orphan->inum);
307+
orphan->cmt = 0;
303308
cnext = orphan->cnext;
304309
orphan->cnext = NULL;
305310
}
@@ -378,6 +383,7 @@ static int consolidate(struct ubifs_info *c)
378383
list_for_each_entry(orphan, &c->orph_list, list) {
379384
if (orphan->new)
380385
continue;
386+
orphan->cmt = 1;
381387
*last = orphan;
382388
last = &orphan->cnext;
383389
cnt += 1;
@@ -442,6 +448,7 @@ static void erase_deleted(struct ubifs_info *c)
442448
orphan = dnext;
443449
dnext = orphan->dnext;
444450
ubifs_assert(!orphan->new);
451+
ubifs_assert(orphan->del);
445452
rb_erase(&orphan->rb, &c->orph_tree);
446453
list_del(&orphan->list);
447454
c->tot_orphans -= 1;
@@ -531,6 +538,7 @@ static int insert_dead_orphan(struct ubifs_info *c, ino_t inum)
531538
rb_link_node(&orphan->rb, parent, p);
532539
rb_insert_color(&orphan->rb, &c->orph_tree);
533540
list_add_tail(&orphan->list, &c->orph_list);
541+
orphan->del = 1;
534542
orphan->dnext = c->orph_dnext;
535543
c->orph_dnext = orphan;
536544
dbg_mnt("ino %lu, new %d, tot %d", (unsigned long)inum,

‎fs/ubifs/tnc_commit.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ static int alloc_idx_lebs(struct ubifs_info *c, int cnt)
683683
c->ilebs[c->ileb_cnt++] = lnum;
684684
dbg_cmt("LEB %d", lnum);
685685
}
686-
if (dbg_is_chk_index(c) && !(random32() & 7))
686+
if (dbg_is_chk_index(c) && !(prandom_u32() & 7))
687687
return -ENOSPC;
688688
return 0;
689689
}

‎fs/ubifs/ubifs.h‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,8 @@ struct ubifs_budget_req {
904904
* @dnext: next orphan to delete
905905
* @inum: inode number
906906
* @new: %1 => added since the last commit, otherwise %0
907+
* @cmt: %1 => commit pending, otherwise %0
908+
* @del: %1 => delete pending, otherwise %0
907909
*/
908910
struct ubifs_orphan {
909911
struct rb_node rb;
@@ -912,7 +914,9 @@ struct ubifs_orphan {
912914
struct ubifs_orphan *cnext;
913915
struct ubifs_orphan *dnext;
914916
ino_t inum;
915-
int new;
917+
unsigned new:1;
918+
unsigned cmt:1;
919+
unsigned del:1;
916920
};
917921

918922
/**

0 commit comments

Comments
 (0)