Skip to content

Commit 06b4e09

Browse files
committed
pstore/ram: Set freed addresses to NULL
For good measure, set all the freed addresses to NULL when managing przs. Cc: Anton Vorontsov <[email protected]> Cc: Colin Cross <[email protected]> Cc: Tony Luck <[email protected]> Signed-off-by: Kees Cook <[email protected]> Reviewed-and-tested-by: Guilherme G. Piccoli <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 8bd4da0 commit 06b4e09

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

fs/pstore/ram.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -453,25 +453,27 @@ static void ramoops_free_przs(struct ramoops_context *cxt)
453453
int i;
454454

455455
/* Free pmsg PRZ */
456-
persistent_ram_free(cxt->mprz);
456+
persistent_ram_free(&cxt->mprz);
457457

458458
/* Free console PRZ */
459-
persistent_ram_free(cxt->cprz);
459+
persistent_ram_free(&cxt->cprz);
460460

461461
/* Free dump PRZs */
462462
if (cxt->dprzs) {
463463
for (i = 0; i < cxt->max_dump_cnt; i++)
464-
persistent_ram_free(cxt->dprzs[i]);
464+
persistent_ram_free(&cxt->dprzs[i]);
465465

466466
kfree(cxt->dprzs);
467+
cxt->dprzs = NULL;
467468
cxt->max_dump_cnt = 0;
468469
}
469470

470471
/* Free ftrace PRZs */
471472
if (cxt->fprzs) {
472473
for (i = 0; i < cxt->max_ftrace_cnt; i++)
473-
persistent_ram_free(cxt->fprzs[i]);
474+
persistent_ram_free(&cxt->fprzs[i]);
474475
kfree(cxt->fprzs);
476+
cxt->fprzs = NULL;
475477
cxt->max_ftrace_cnt = 0;
476478
}
477479
}
@@ -555,9 +557,10 @@ static int ramoops_init_przs(const char *name,
555557

556558
while (i > 0) {
557559
i--;
558-
persistent_ram_free(prz_ar[i]);
560+
persistent_ram_free(&prz_ar[i]);
559561
}
560562
kfree(prz_ar);
563+
prz_ar = NULL;
561564
goto fail;
562565
}
563566
*paddr += zone_sz;

fs/pstore/ram_core.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,14 @@ static int persistent_ram_post_init(struct persistent_ram_zone *prz, u32 sig,
544544
return 0;
545545
}
546546

547-
void persistent_ram_free(struct persistent_ram_zone *prz)
547+
void persistent_ram_free(struct persistent_ram_zone **_prz)
548548
{
549+
struct persistent_ram_zone *prz;
550+
551+
if (!_prz)
552+
return;
553+
554+
prz = *_prz;
549555
if (!prz)
550556
return;
551557

@@ -569,6 +575,7 @@ void persistent_ram_free(struct persistent_ram_zone *prz)
569575
persistent_ram_free_old(prz);
570576
kfree(prz->label);
571577
kfree(prz);
578+
*_prz = NULL;
572579
}
573580

574581
struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size,
@@ -605,6 +612,6 @@ struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size,
605612

606613
return prz;
607614
err:
608-
persistent_ram_free(prz);
615+
persistent_ram_free(&prz);
609616
return ERR_PTR(ret);
610617
}

fs/pstore/ram_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ struct persistent_ram_zone {
8282
struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size,
8383
u32 sig, struct persistent_ram_ecc_info *ecc_info,
8484
unsigned int memtype, u32 flags, char *label);
85-
void persistent_ram_free(struct persistent_ram_zone *prz);
85+
void persistent_ram_free(struct persistent_ram_zone **_prz);
8686
void persistent_ram_zap(struct persistent_ram_zone *prz);
8787

8888
int persistent_ram_write(struct persistent_ram_zone *prz, const void *s,

0 commit comments

Comments
 (0)