Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp23915imu; Fri, 14 Dec 2018 13:41:32 -0800 (PST) X-Google-Smtp-Source: AFSGD/UkK0dxEduLioBHgqYeniB8P7KrEOt2Axhlp9KEQITFZJCAhvGynKCpPM3i6aQYGof3DycD X-Received: by 2002:a17:902:142:: with SMTP id 60mr4516702plb.330.1544823692277; Fri, 14 Dec 2018 13:41:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544823692; cv=none; d=google.com; s=arc-20160816; b=g5vS8djpAaJ565WRsskiQuQo1afzJVIuWLS9J2Rm2G5AECaozDjTeCKLyHk4TY8Bcq Qkp5JwjLTxxDz3zZkjUQ07urb3xLBt/oOz+Gr9qTVVvlUSlvcnH9sxrj5smV8IbQRLs5 fGcc734RQfzAC+Gp+LS6hooBjLliB0o+bjDX4IHDS7etKp97Ud1WyFdQVUET+kn8v7js D1LHdj91F+TAWuHGJZ9pLlur3Xy+XXT7mx1hf7glLHcHFAhezocWnXxG5tHqzTddM3Jv AV7QULvs0mIhtQRvaFGYiuTw9O1uCVK742PCkWxEbZp1PrjGMTT8ViN1FR3LgSfA7gD3 MB/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject; bh=676HxL/Ky0NZoZ90PiiGzWDqvvTOVBbpnHIIS5LbS2A=; b=Hbitjs0s5wH5NtrQI/O1PDQ98RQt4+rS9h9aesZwfCCi41IeXczLQU8LT0XrisSeX2 gm9DAMuLUrVzMrjni9GXr73IhD9P5//VadB3GKw7nApidzxtaaNq2xunaH+D1iC1ZZ/u ZW/9JtAziB3HZ6Vfd8buEPLqd/RVdncBtBtr1XzwEQqd/m1obKs7aznoUFBb8QdybHk+ NbQ9iy9/ZrOWv2XanrOa+mBIWP6Ug7/UT2z7NVoEB2gydi6GuDko4NnmOJPw7aMGW9UO 7zziCVDUH49ZhWVdiJ+EKpTZgRc+eKVABk39PIK3fqsU2xLqIzAQLgfR5KWwqNtJE9Bg WUvA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z63si4992657pfz.132.2018.12.14.13.41.16; Fri, 14 Dec 2018 13:41:32 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731092AbeLNVjl (ORCPT + 99 others); Fri, 14 Dec 2018 16:39:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47878 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730887AbeLNVjl (ORCPT ); Fri, 14 Dec 2018 16:39:41 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E465540258; Fri, 14 Dec 2018 21:39:40 +0000 (UTC) Received: from jlaw-desktop.bos.csb (dhcp-17-208.bos.redhat.com [10.18.17.208]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1859D608E0; Fri, 14 Dec 2018 21:39:40 +0000 (UTC) Subject: Re: [PATCH 2/2] livepatch: check kzalloc return values To: Nicholas Mc Guire , Josh Poimboeuf Cc: Jessica Yu , Jiri Kosina , Miroslav Benes , Petr Mladek , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org References: <1544806570-21299-1-git-send-email-hofrat@osadl.org> <1544806570-21299-2-git-send-email-hofrat@osadl.org> From: Joe Lawrence Organization: Red Hat Message-ID: Date: Fri, 14 Dec 2018 16:39:39 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: <1544806570-21299-2-git-send-email-hofrat@osadl.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 14 Dec 2018 21:39:41 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/14/2018 11:56 AM, Nicholas Mc Guire wrote: > 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") > --- > > Problem located with an experimental coccinelle script > > Patch was compile tested with: x86_64_defconfig + FTRACE=y > FUNCTION_TRACER=y, EXPERT=y, LATENCYTOP=y, SAMPLES=y, > SAMPLE_LIVEPATCH=y > > Patch is against 4.20-rc6 (localversion-next is next-20181214) > on top of 0001-livepatch-fix-non-static-warnings.patch > > samples/livepatch/livepatch-shadow-fix1.c | 5 +++++ > samples/livepatch/livepatch-shadow-mod.c | 4 ++++ > 2 files changed, 9 insertions(+) > > diff --git a/samples/livepatch/livepatch-shadow-fix1.c b/samples/livepatch/livepatch-shadow-fix1.c > index eaab10f..1974eb5 100644 > --- a/samples/livepatch/livepatch-shadow-fix1.c > +++ b/samples/livepatch/livepatch-shadow-fix1.c > @@ -89,6 +89,11 @@ static __noclone 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); > > diff --git a/samples/livepatch/livepatch-shadow-mod.c b/samples/livepatch/livepatch-shadow-mod.c > index dc69da0..b4ece36 100644 > --- a/samples/livepatch/livepatch-shadow-mod.c > +++ b/samples/livepatch/livepatch-shadow-mod.c > @@ -123,6 +123,10 @@ static __noclone 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); > Patch v2 2/2 looks good, thanks for combining. Acked-by: Joe Lawrence -- Joe