]> git.baikalelectronics.ru Git - kernel.git/commit
pstore/ram: Regularize prz label allocation lifetime
authorKees Cook <keescook@chromium.org>
Wed, 8 Jan 2020 18:06:54 +0000 (10:06 -0800)
committerKees Cook <keescook@chromium.org>
Thu, 9 Jan 2020 01:05:45 +0000 (17:05 -0800)
commit0efd554e4c95e9f59a4b2f15d49a97af2205d5bb
tree55fd934daa0d7389213d6bcf7b6df94e73e1a03d
parent2c2e411ec802d0d8743b857489786a9877960f77
pstore/ram: Regularize prz label allocation lifetime

In my attempt to fix a memory leak, I introduced a double-free in the
pstore error path. Instead of trying to manage the allocation lifetime
between persistent_ram_new() and its callers, adjust the logic so
persistent_ram_new() always takes a kstrdup() copy, and leaves the
caller's allocation lifetime up to the caller. Therefore callers are
_always_ responsible for freeing their label. Before, it only needed
freeing when the prz itself failed to allocate, and not in any of the
other prz failure cases, which callers would have no visibility into,
which is the root design problem that lead to both the leak and now
double-free bugs.

Reported-by: Cengiz Can <cengiz@kernel.wtf>
Link: https://lore.kernel.org/lkml/d4ec59002ede4aaf9928c7f7526da87c@kernel.wtf
Fixes: 3123bce688eb ("pstore/ram: Fix error-path memory leak in persistent_ram_new() callers")
Cc: stable@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
fs/pstore/ram.c
fs/pstore/ram_core.c