Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp876257imu; Thu, 13 Dec 2018 06:02:30 -0800 (PST) X-Google-Smtp-Source: AFSGD/UuRBTSsYP/E+bcwAuR53q9bDRk1omfHiCYYayCVTeP1MDdlF8PYRtHpqmDKQcXpLYFYIwH X-Received: by 2002:a63:78cd:: with SMTP id t196mr22001353pgc.62.1544709750417; Thu, 13 Dec 2018 06:02:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544709750; cv=none; d=google.com; s=arc-20160816; b=j+Hgxiaxkel9aPVwtLcgzHhlxId/abgk4JCxujJPcBGDgRgB90+NYOwBzWhk764yuC iswNIZr65iRsth7tsNS7ZOPWTHNFXY7oBMOlVlcEt4EiUV4TFs/EsXK29NSzIOSB9U/L JKKut+6eUxyMiwHF5n86DVsGFJBPvgDnXE12VMxyyddCgwky85EnUF02WyJYcIWjwFcT Xgd0XU0Yulm0dVQJQxJNPoVZneb4/xYprUREyKyuB+jGRkx3psBib/Pxx/VTr8UOeY7x V0gkTWg3JOZEIGMHKwV7oDNkDZNJFxT47Ps9GjxGVzByirqchMmAUYFvJki6Pf1QLnS+ vI+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=9nPIAxUxKitf5a6S4DvcG1Wh8gl4tmM+wi+2vfN0l0o=; b=IbeVrMUH8Bgq85uHFXsGkZjFkEKqCqoCgCYNkOmgyOuBEaUWkghGrtT6Q2w6rWXd14 pRCdHKIOtM5pFMAwYoBR5jzdPfprVgOcrhmvJoibxri8uz1Ko3k20Pbxc3keJtYrwIQS H5LAmgCp/K+NWw69MpAb5i5tko06vywl3kBfkf+O2vLqm5t3hMvaShBfR8d4bq6EdMep eGPf6W8G3xPXZj9OXg7TLtbTawL8gPZHMUS9q9UolfgWsEh9hVbakRoyKntpUyJuRG2P 4fTK5+7v4hbvx07HGTKzlO0KYqNKMG0X8NuF6OcJBi6WnhZf8i6yWIygvPawKohkZ6+M kGKw== 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 t12si1492684plr.311.2018.12.13.06.02.07; Thu, 13 Dec 2018 06:02:30 -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 S1729550AbeLMOBE (ORCPT + 99 others); Thu, 13 Dec 2018 09:01:04 -0500 Received: from 178.115.242.59.static.drei.at ([178.115.242.59]:52285 "EHLO mail.osadl.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729430AbeLMOBD (ORCPT ); Thu, 13 Dec 2018 09:01:03 -0500 Received: by mail.osadl.at (Postfix, from userid 1001) id 0BE9F5C22C4; Thu, 13 Dec 2018 15:00:58 +0100 (CET) Date: Thu, 13 Dec 2018 15:00:58 +0100 From: Nicholas Mc Guire To: Petr Mladek Cc: Nicholas Mc Guire , Josh Poimboeuf , Jessica Yu , Jiri Kosina , Miroslav Benes , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] livepatch: handle kzalloc failure Message-ID: <20181213140057.GA29272@osadl.at> References: <1544699390-15673-1-git-send-email-hofrat@osadl.org> <20181213123139.oukmwpkw2yfap6oa@pathway.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181213123139.oukmwpkw2yfap6oa@pathway.suse.cz> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Dec 13, 2018 at 01:31:39PM +0100, Petr Mladek wrote: > On Thu 2018-12-13 12:09:49, 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 > > livepatch_fix1_dummy_alloc() should return NULL. > > > > Signed-off-by: Nicholas Mc Guire > > --- > > > > Problem was 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 > > (with some unrelated sparse warnings on symbols not being static) > > > > Patch is against 4.20-rc6 (localversion-next is next-20181213) > > > > samples/livepatch/livepatch-shadow-fix1.c | 3 +++ > > 1 file changed, 3 insertions(+) > > > > diff --git a/samples/livepatch/livepatch-shadow-fix1.c b/samples/livepatch/livepatch-shadow-fix1.c > > index 49b1355..a0e8f04 100644 > > --- a/samples/livepatch/livepatch-shadow-fix1.c > > +++ b/samples/livepatch/livepatch-shadow-fix1.c > > @@ -89,6 +89,9 @@ struct dummy *livepatch_fix1_dummy_alloc(void) > > * pointer to handle resource release. > > */ > > leak = kzalloc(sizeof(int), GFP_KERNEL); > > + if (!leak) > > + return NULL; > > It should be: > > if (!leak) { > kfree(d); > return NULL; > } > > Note that The check is not strictly needed in this artificial > example because we never read/write any data there. But I agree > that we should add the check to promote the the right programming > patterns. > thanks for catching this ! will send a V2. thx! hofrat