Commit 06b4e09a authored by Kees Cook's avatar Kees Cook

pstore/ram: Set freed addresses to NULL

For good measure, set all the freed addresses to NULL when managing
przs.

Cc: Anton Vorontsov <anton@enomsg.org>
Cc: Colin Cross <ccross@android.com>
Cc: Tony Luck <tony.luck@intel.com>
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Reviewed-and-tested-by: default avatarGuilherme G. Piccoli <gpiccoli@igalia.com>
Link: https://lore.kernel.org/r/20221011200112.731334-5-keescook@chromium.org
parent 8bd4da0f
...@@ -453,25 +453,27 @@ static void ramoops_free_przs(struct ramoops_context *cxt) ...@@ -453,25 +453,27 @@ static void ramoops_free_przs(struct ramoops_context *cxt)
int i; int i;
/* Free pmsg PRZ */ /* Free pmsg PRZ */
persistent_ram_free(cxt->mprz); persistent_ram_free(&cxt->mprz);
/* Free console PRZ */ /* Free console PRZ */
persistent_ram_free(cxt->cprz); persistent_ram_free(&cxt->cprz);
/* Free dump PRZs */ /* Free dump PRZs */
if (cxt->dprzs) { if (cxt->dprzs) {
for (i = 0; i < cxt->max_dump_cnt; i++) for (i = 0; i < cxt->max_dump_cnt; i++)
persistent_ram_free(cxt->dprzs[i]); persistent_ram_free(&cxt->dprzs[i]);
kfree(cxt->dprzs); kfree(cxt->dprzs);
cxt->dprzs = NULL;
cxt->max_dump_cnt = 0; cxt->max_dump_cnt = 0;
} }
/* Free ftrace PRZs */ /* Free ftrace PRZs */
if (cxt->fprzs) { if (cxt->fprzs) {
for (i = 0; i < cxt->max_ftrace_cnt; i++) for (i = 0; i < cxt->max_ftrace_cnt; i++)
persistent_ram_free(cxt->fprzs[i]); persistent_ram_free(&cxt->fprzs[i]);
kfree(cxt->fprzs); kfree(cxt->fprzs);
cxt->fprzs = NULL;
cxt->max_ftrace_cnt = 0; cxt->max_ftrace_cnt = 0;
} }
} }
...@@ -555,9 +557,10 @@ static int ramoops_init_przs(const char *name, ...@@ -555,9 +557,10 @@ static int ramoops_init_przs(const char *name,
while (i > 0) { while (i > 0) {
i--; i--;
persistent_ram_free(prz_ar[i]); persistent_ram_free(&prz_ar[i]);
} }
kfree(prz_ar); kfree(prz_ar);
prz_ar = NULL;
goto fail; goto fail;
} }
*paddr += zone_sz; *paddr += zone_sz;
......
...@@ -544,8 +544,14 @@ static int persistent_ram_post_init(struct persistent_ram_zone *prz, u32 sig, ...@@ -544,8 +544,14 @@ static int persistent_ram_post_init(struct persistent_ram_zone *prz, u32 sig,
return 0; return 0;
} }
void persistent_ram_free(struct persistent_ram_zone *prz) void persistent_ram_free(struct persistent_ram_zone **_prz)
{ {
struct persistent_ram_zone *prz;
if (!_prz)
return;
prz = *_prz;
if (!prz) if (!prz)
return; return;
...@@ -569,6 +575,7 @@ void persistent_ram_free(struct persistent_ram_zone *prz) ...@@ -569,6 +575,7 @@ void persistent_ram_free(struct persistent_ram_zone *prz)
persistent_ram_free_old(prz); persistent_ram_free_old(prz);
kfree(prz->label); kfree(prz->label);
kfree(prz); kfree(prz);
*_prz = NULL;
} }
struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size, 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, ...@@ -605,6 +612,6 @@ struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size,
return prz; return prz;
err: err:
persistent_ram_free(prz); persistent_ram_free(&prz);
return ERR_PTR(ret); return ERR_PTR(ret);
} }
...@@ -82,7 +82,7 @@ struct persistent_ram_zone { ...@@ -82,7 +82,7 @@ struct persistent_ram_zone {
struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size, struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size,
u32 sig, struct persistent_ram_ecc_info *ecc_info, u32 sig, struct persistent_ram_ecc_info *ecc_info,
unsigned int memtype, u32 flags, char *label); unsigned int memtype, u32 flags, char *label);
void persistent_ram_free(struct persistent_ram_zone *prz); void persistent_ram_free(struct persistent_ram_zone **_prz);
void persistent_ram_zap(struct persistent_ram_zone *prz); void persistent_ram_zap(struct persistent_ram_zone *prz);
int persistent_ram_write(struct persistent_ram_zone *prz, const void *s, int persistent_ram_write(struct persistent_ram_zone *prz, const void *s,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment