Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Kees Cook <keescook@chromium.org>
Reviewed-and-tested-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
Link: https://lore.kernel.org/r/20221011200112.731334-5-keescook@chromium.org

+18 -8
+8 -5
fs/pstore/ram.c
··· 453 453 int i; 454 454 455 455 /* Free pmsg PRZ */ 456 - persistent_ram_free(cxt->mprz); 456 + persistent_ram_free(&cxt->mprz); 457 457 458 458 /* Free console PRZ */ 459 - persistent_ram_free(cxt->cprz); 459 + persistent_ram_free(&cxt->cprz); 460 460 461 461 /* Free dump PRZs */ 462 462 if (cxt->dprzs) { 463 463 for (i = 0; i < cxt->max_dump_cnt; i++) 464 - persistent_ram_free(cxt->dprzs[i]); 464 + persistent_ram_free(&cxt->dprzs[i]); 465 465 466 466 kfree(cxt->dprzs); 467 + cxt->dprzs = NULL; 467 468 cxt->max_dump_cnt = 0; 468 469 } 469 470 470 471 /* Free ftrace PRZs */ 471 472 if (cxt->fprzs) { 472 473 for (i = 0; i < cxt->max_ftrace_cnt; i++) 473 - persistent_ram_free(cxt->fprzs[i]); 474 + persistent_ram_free(&cxt->fprzs[i]); 474 475 kfree(cxt->fprzs); 476 + cxt->fprzs = NULL; 475 477 cxt->max_ftrace_cnt = 0; 476 478 } 477 479 } ··· 557 555 558 556 while (i > 0) { 559 557 i--; 560 - persistent_ram_free(prz_ar[i]); 558 + persistent_ram_free(&prz_ar[i]); 561 559 } 562 560 kfree(prz_ar); 561 + prz_ar = NULL; 563 562 goto fail; 564 563 } 565 564 *paddr += zone_sz;
+9 -2
fs/pstore/ram_core.c
··· 544 544 return 0; 545 545 } 546 546 547 - void persistent_ram_free(struct persistent_ram_zone *prz) 547 + void persistent_ram_free(struct persistent_ram_zone **_prz) 548 548 { 549 + struct persistent_ram_zone *prz; 550 + 551 + if (!_prz) 552 + return; 553 + 554 + prz = *_prz; 549 555 if (!prz) 550 556 return; 551 557 ··· 575 569 persistent_ram_free_old(prz); 576 570 kfree(prz->label); 577 571 kfree(prz); 572 + *_prz = NULL; 578 573 } 579 574 580 575 struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size, ··· 612 605 613 606 return prz; 614 607 err: 615 - persistent_ram_free(prz); 608 + persistent_ram_free(&prz); 616 609 return ERR_PTR(ret); 617 610 }
+1 -1
fs/pstore/ram_internal.h
··· 82 82 struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size, 83 83 u32 sig, struct persistent_ram_ecc_info *ecc_info, 84 84 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); 86 86 void persistent_ram_zap(struct persistent_ram_zone *prz); 87 87 88 88 int persistent_ram_write(struct persistent_ram_zone *prz, const void *s,