Skip to content

Commit 6f06d96

Browse files
saschahauerrichardweinberger
authored andcommitted
ubifs: Add auth nodes to garbage collector journal head
To be able to authenticate the garbage collector journal head add authentication nodes to the buds the garbage collector creates. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Richard Weinberger <richard@nod.at>
1 parent 6a98bc4 commit 6f06d96

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

fs/ubifs/gc.c

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,27 +365,35 @@ static int move_nodes(struct ubifs_info *c, struct ubifs_scan_leb *sleb)
365365

366366
/* Write nodes to their new location. Use the first-fit strategy */
367367
while (1) {
368-
int avail;
368+
int avail, moved = 0;
369369
struct ubifs_scan_node *snod, *tmp;
370370

371371
/* Move data nodes */
372372
list_for_each_entry_safe(snod, tmp, &sleb->nodes, list) {
373-
avail = c->leb_size - wbuf->offs - wbuf->used;
373+
avail = c->leb_size - wbuf->offs - wbuf->used -
374+
ubifs_auth_node_sz(c);
374375
if (snod->len > avail)
375376
/*
376377
* Do not skip data nodes in order to optimize
377378
* bulk-read.
378379
*/
379380
break;
380381

382+
err = ubifs_shash_update(c, c->jheads[GCHD].log_hash,
383+
snod->node, snod->len);
384+
if (err)
385+
goto out;
386+
381387
err = move_node(c, sleb, snod, wbuf);
382388
if (err)
383389
goto out;
390+
moved = 1;
384391
}
385392

386393
/* Move non-data nodes */
387394
list_for_each_entry_safe(snod, tmp, &nondata, list) {
388-
avail = c->leb_size - wbuf->offs - wbuf->used;
395+
avail = c->leb_size - wbuf->offs - wbuf->used -
396+
ubifs_auth_node_sz(c);
389397
if (avail < min)
390398
break;
391399

@@ -403,9 +411,41 @@ static int move_nodes(struct ubifs_info *c, struct ubifs_scan_leb *sleb)
403411
continue;
404412
}
405413

414+
err = ubifs_shash_update(c, c->jheads[GCHD].log_hash,
415+
snod->node, snod->len);
416+
if (err)
417+
goto out;
418+
406419
err = move_node(c, sleb, snod, wbuf);
407420
if (err)
408421
goto out;
422+
moved = 1;
423+
}
424+
425+
if (ubifs_authenticated(c) && moved) {
426+
struct ubifs_auth_node *auth;
427+
428+
auth = kmalloc(ubifs_auth_node_sz(c), GFP_NOFS);
429+
if (!auth) {
430+
err = -ENOMEM;
431+
goto out;
432+
}
433+
434+
err = ubifs_prepare_auth_node(c, auth,
435+
c->jheads[GCHD].log_hash);
436+
if (err) {
437+
kfree(auth);
438+
goto out;
439+
}
440+
441+
err = ubifs_wbuf_write_nolock(wbuf, auth,
442+
ubifs_auth_node_sz(c));
443+
if (err) {
444+
kfree(auth);
445+
goto out;
446+
}
447+
448+
ubifs_add_dirt(c, wbuf->lnum, ubifs_auth_node_sz(c));
409449
}
410450

411451
if (list_empty(&sleb->nodes) && list_empty(&nondata))

0 commit comments

Comments
 (0)