From 5f30b2e823484ce6a79f2b59901b6351c15effa6 Mon Sep 17 00:00:00 2001 From: Nicholas Mc Guire Date: Fri, 14 Dec 2018 17:56:10 +0100 Subject: livepatch: check kzalloc return values kzalloc() return should always be checked - notably in example code where this may be seen as reference. On failure of allocation in livepatch_fix1_dummy_alloc() respectively dummy_alloc() previous allocation is freed (thanks to Petr Mladek for catching this) and NULL returned. Signed-off-by: Nicholas Mc Guire Fixes: 439e7271dc2b ("livepatch: introduce shadow variable API") Acked-by: Joe Lawrence Reviewed-by: Petr Mladek Acked-by: Miroslav Benes Signed-off-by: Jiri Kosina --- samples/livepatch/livepatch-shadow-fix1.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'samples/livepatch/livepatch-shadow-fix1.c') diff --git a/samples/livepatch/livepatch-shadow-fix1.c b/samples/livepatch/livepatch-shadow-fix1.c index 49b13553eaae..e8f1bd6b29b1 100644 --- a/samples/livepatch/livepatch-shadow-fix1.c +++ b/samples/livepatch/livepatch-shadow-fix1.c @@ -89,6 +89,11 @@ struct dummy *livepatch_fix1_dummy_alloc(void) * pointer to handle resource release. */ leak = kzalloc(sizeof(int), GFP_KERNEL); + if (!leak) { + kfree(d); + return NULL; + } + klp_shadow_alloc(d, SV_LEAK, sizeof(leak), GFP_KERNEL, shadow_leak_ctor, leak); -- cgit v1.2.3