Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp989680imu; Thu, 13 Dec 2018 07:42:27 -0800 (PST) X-Google-Smtp-Source: AFSGD/UsW7u5A+Mfb8XIP9agVnBgrhGnDIbQwr9ckaPBpLzd37vwq4JF4qHfs7wYDwGbWhXfT4qE X-Received: by 2002:a62:4181:: with SMTP id g1mr24416568pfd.45.1544715747731; Thu, 13 Dec 2018 07:42:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544715747; cv=none; d=google.com; s=arc-20160816; b=tGtvHMdfv9ZBPI3hDQ+AeLjefKwnlWgrzDIxHiLC2jT13/oAjWt5nvfAzOQ/p+6Dky 3WbKvs/Y0ut/LV76bjwaDVzoEt2lWn2EZDL8Kwz6siOSHRkL3TScIbLFSR/qqWJP2Huz KQpaBb2imbFt26cID3Q8uFvExXhyJRw4Q1BXDAg58oTGGLISEYQT+7w9Vz924bgF1jXm ckyCTu811HGTavXcQREWsvzuWDlDxR6280Hcjj3K5l2VfOekxz3MCX8M0t3fSAEYg5/D PWGzrQRRWy17GByo0I2P+hkaS5vmBbDBGkHA2LSQMpwmp8dwAQ1UCXnwus1Wvfstfata lUPg== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=BuvSWFxSenCC1rhfZWAWJnayrB6ppUmzF6PRDyUZB4k=; b=SEMr3YsetjB/w69aQKlgbzhQ9CC+0Gt6C39qBRxCuaIO9ukZPHuEavzWrHWcKNndT3 ffAk+0C6+VQ+Vd6tSS5uHS4TCmTi16QdS+7UDOMBXHvcw5j1cE7m/VKITX+ho+7Md+k9 OFN7dXcuHwnf9l1sbhBelVqwtKEb1u5w8t8elctju8sGd+yc1aA0a+ZEAFb8AH+LNUx+ 5hqhqn8jKzNytKarfVLz+bm5w2IWu3eXdY/EqKsHy74l/ucPF9ggk5c/9C5nK1fafRjE JtIG2byw3khV3V2lUWMZ/j6y3Nx61LbLBHDZF1tJsJ9ouOaC4jX3QbE18zWdNWwydOO6 7fnQ== 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 l33si1794399pld.142.2018.12.13.07.42.09; Thu, 13 Dec 2018 07:42:27 -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 S1729552AbeLMPkB (ORCPT + 99 others); Thu, 13 Dec 2018 10:40:01 -0500 Received: from 178.115.242.59.static.drei.at ([178.115.242.59]:52386 "EHLO mail.osadl.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728445AbeLMPkA (ORCPT ); Thu, 13 Dec 2018 10:40:00 -0500 Received: by mail.osadl.at (Postfix, from userid 1001) id 0E6A05C22C4; Thu, 13 Dec 2018 16:39:55 +0100 (CET) Date: Thu, 13 Dec 2018 16:39:55 +0100 From: Nicholas Mc Guire To: Joe Lawrence Cc: Nicholas Mc Guire , Josh Poimboeuf , Jessica Yu , Jiri Kosina , Miroslav Benes , Petr Mladek , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2 V2] livepatch: handle kzalloc failure properly Message-ID: <20181213153954.GA9816@osadl.at> References: <1544709956-16701-1-git-send-email-hofrat@osadl.org> <1544709956-16701-2-git-send-email-hofrat@osadl.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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 09:14:18AM -0500, Joe Lawrence wrote: > On 12/13/2018 09:05 AM, Nicholas Mc Guire wrote: > > 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); > > > > Hi Nicholas, > > Thanks for finding and fixing these up... can we either squash these two > patches into a single commit or give them unique subject lines? Code > looks good (including Petr's suggested fix) otherwise. > yup - makes sense to pop it into a single patch - I assumed that this would not be acceptable - so I actually split it up :) I?ll send a V3 then. BTW: wanted to fix up the sparse warnings but I think thats not going to be that simple as the functions/structs sparse complains about are actually being shared: CHECK samples/livepatch/livepatch-shadow-fix1.c samples/livepatch/livepatch-shadow-fix1.c:74:14: warning: symbol 'livepatch_fix1_dummy alloc' was not declared. Should it be static? samples/livepatch/livepatch-shadow-fix1.c:116:6: warning: symbol 'livepatch_fix1_dummy free' was not declared. Should it be static? CHECK samples/livepatch/livepatch-shadow-mod.c samples/livepatch/livepatch-shadow-mod.c:99:1: warning: symbol 'dummy_list' was not declared. Should it be static? samples/livepatch/livepatch-shadow-mod.c:100:1: warning: symbol 'dummy_list_mutex' was not declared. Should it be static? samples/livepatch/livepatch-shadow-mod.c:107:23: warning: symbol 'dummy_alloc' was not declared. Should it be static? samples/livepatch/livepatch-shadow-mod.c:132:15: warning: symbol 'dummy_free' was not declared. Should it be static? samples/livepatch/livepatch-shadow-mod.c:140:15: warning: symbol 'dummy_check' was not declared. Should it be static? so to clean that appropriate declarations should probably go into a .h file. Technically its maybe not important as this is not production code - it would though be nice if sample code is sparse/smatch/cocci clean. would it be acceptable to clean this up with an additional livepatch-shadow-mod.h ? thx! hofrat