Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp785641imu; Thu, 13 Dec 2018 04:33:45 -0800 (PST) X-Google-Smtp-Source: AFSGD/UYZ6mpLcVruIKTkUL+KLcoVhjFWTOk9VbeUGxUN9TYI6lpiDjIkoyR0I7Nm+7Vpd/lv5pQ X-Received: by 2002:a17:902:724a:: with SMTP id c10mr24078957pll.51.1544704425850; Thu, 13 Dec 2018 04:33:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544704425; cv=none; d=google.com; s=arc-20160816; b=pb8jKAlkiVyFciPeTfYsrpFGq0RtDkGUBJTfnrwzaw4GtcVw78mJDAvht3tJj8VYUX nDHuMCZ0UihI0dWEgWx6rMb3HuPfqFqZeakX5zC5XuqSUGqDZJ6rDB/qrc0N8Ho/ks8z YZL8SJQi1gSMYYHOqVZ4rPLsXfa0mxvq4BjqzysSNXvmFJrqeB/lsGRQfGbgIlfC+m6i Z/jFztYS6q982Hh0LT3LiBVr614Wr04Wkg15cEQNrBS30UdMCsq7LUeZh0AE0jZcgTfD 5f6MTjeJVqLem78Ossv7X7XerP5oGeB3vPLeSgg6YiBaqbbLUsv22PvxZVHAs819JVwl Cujw== 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=j8nzIA7Ua7dhPvIT2KTqBeQpJWyBvQle/MJzrqs2x18=; b=VGWHNZkOCT3N+JkciVaeTBGZ0gZLT4GWtJuyp00fHAFBDNgB/OCMAmFJuUIWRJW71O QneIVQYpBjd2nKSmiXegCKsa2BvPmnQuYGE/dt9m86S/SjkaM9e2LE2ZlJTcGqnxjqkn 0AT2xSlWJ6nVD+0sXC49ICJ6viOTH3U4yFAtMAWNLZYf4lhhcPqoryla8YQ+WV5KQ/tG 7ZZQ1sRlBny0Cx79sOplN43jN/bepP+l9sHgomZ40kqzbdkK7CcMehb4Dzb39rXxpf7v IoCptUrBlOunrGe5OBL5MPuI43VutibnABvj8yLdIvQl0hGiZG7/D/bXucyFNYWnPGmL 7HrA== 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 o22si1410684pgb.584.2018.12.13.04.33.31; Thu, 13 Dec 2018 04:33:45 -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 S1728992AbeLMMbm (ORCPT + 99 others); Thu, 13 Dec 2018 07:31:42 -0500 Received: from mx2.suse.de ([195.135.220.15]:56694 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728859AbeLMMbm (ORCPT ); Thu, 13 Dec 2018 07:31:42 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id C52CFAC24; Thu, 13 Dec 2018 12:31:39 +0000 (UTC) Date: Thu, 13 Dec 2018 13:31:39 +0100 From: Petr Mladek To: Nicholas Mc Guire Cc: 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: <20181213123139.oukmwpkw2yfap6oa@pathway.suse.cz> References: <1544699390-15673-1-git-send-email-hofrat@osadl.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1544699390-15673-1-git-send-email-hofrat@osadl.org> User-Agent: NeoMutt/20170421 (1.8.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Best Regards, Petr