Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp888810imu; Thu, 13 Dec 2018 06:11:42 -0800 (PST) X-Google-Smtp-Source: AFSGD/XCcky2d2QMtrd3jJr3rKOd05G1W2P18cMztROFj2ssdXLualodvPq0ks3i+bdwdVGmjF0h X-Received: by 2002:a17:902:6bc9:: with SMTP id m9mr23408856plt.173.1544710302088; Thu, 13 Dec 2018 06:11:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544710302; cv=none; d=google.com; s=arc-20160816; b=Wwli9PvqJynfFdlL5Sa6nkaB+IM7HSOJCdHutUFAPitm4TtV9Mek+DtDCPkzl1b3u4 BxWrrTA1T9OPM5J5dj1fwouKjemJjtoqxDOBh6NWjKX8Tqkh9MHF3UBHMOZCXwBj4/Ls JHkuC18dL2G8rrM0S5MlgrS4Xef4Os6aVHkaOrZEZcWu70PKAlpXDpCpys+YDv1m41vB 13fUOoKwGjub6Jy2e4e/mVNmBm3KlwJBMhivUSf7eAzb6Wy3LPFDbjEzRHRI/TUkPEjl mf/MP0cSvsANEjvfEOB5jna9lAxr7MYtj6IPk8VtFWofdQ1IClnm/+qnjqOAkgj0KjHg QCZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=SDmeu4AXMss12QAR/scSyIkch/76aGBdginoy1QZCrM=; b=0DORQKlh1CNszx0m+OfDrVQrmtAi22jdj+YxfHVXpgS4orxcRX1u2ezfRjILFY5M8C TsjdAJutoexCrZW4xclUtAxvxKyH+YJoMVYvE7+DPFX6e98Sr1coskJx3tTilG3WcEGE C9nRIcE2x0+qsNuL9MFMdSyptvcYbyRvXudsw8Nj09ywQH4XxGudiOb6AaCkdnrYmm7c M77OTvCCX84QS3yeV9Z4zCoei2DWJD2KcnnFNv7gBINs1w5lOX2FVA5VVy/Jc7ojmQHK ZOC3644IX5by3Wlj9fYTzaCyE2A81UV3+GzdconKFutyQ0p3HXUQTR6yR5nMnk03Rv2S Yz/w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j39si1596959plb.272.2018.12.13.06.10.50; Thu, 13 Dec 2018 06:11:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728612AbeLMOJm (ORCPT + 99 others); Thu, 13 Dec 2018 09:09:42 -0500 Received: from www.osadl.org ([62.245.132.105]:56305 "EHLO www.osadl.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728239AbeLMOJl (ORCPT ); Thu, 13 Dec 2018 09:09:41 -0500 Received: from debian01.hofrr.at (178.115.242.59.static.drei.at [178.115.242.59]) by www.osadl.org (8.13.8/8.13.8/OSADL-2007092901) with ESMTP id wBDE9Cw7015727; Thu, 13 Dec 2018 15:09:20 +0100 From: Nicholas Mc Guire To: Josh Poimboeuf Cc: Jessica Yu , Jiri Kosina , Miroslav Benes , Petr Mladek , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, Nicholas Mc Guire Subject: [PATCH 2/2 V2] livepatch: handle kzalloc failure properly Date: Thu, 13 Dec 2018 15:05:56 +0100 Message-Id: <1544709956-16701-2-git-send-email-hofrat@osadl.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1544709956-16701-1-git-send-email-hofrat@osadl.org> References: <1544709956-16701-1-git-send-email-hofrat@osadl.org> X-Spam-Status: No, score=0.4 required=6.0 tests=BAYES_00,DATE_IN_FUTURE_96_Q autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on www.osadl.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org kzalloc() return should be checked. On dummy_alloc() failing in kzalloc() NULL should be returned. Signed-off-by: Nicholas Mc Guire --- Problem was located with an experimental coccinelle script V2: returning NULL is ok but not without cleanup - thanks to Petr Mladek for catching this. Patch was compile tested with: x86_64_defconfig + FTRACE=y FUNCTION_TRACER=y, EXPERT=y, LATENCYTOP=y, SAMPLES=y, SAMPLE_LIVEPATCH=y (with a number of unrelated sparse warnings on symbols not being static) Patch is against 4.20-rc6 (localversion-next is next-20181213) samples/livepatch/livepatch-shadow-mod.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/samples/livepatch/livepatch-shadow-mod.c b/samples/livepatch/livepatch-shadow-mod.c index 4c54b25..4aa8a88 100644 --- a/samples/livepatch/livepatch-shadow-mod.c +++ b/samples/livepatch/livepatch-shadow-mod.c @@ -118,6 +118,10 @@ noinline struct dummy *dummy_alloc(void) /* Oops, forgot to save leak! */ leak = kzalloc(sizeof(int), GFP_KERNEL); + if (!leak) { + kfree(d); + return NULL; + } pr_info("%s: dummy @ %p, expires @ %lx\n", __func__, d, d->jiffies_expire); -- 2.1.4