Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5641088imu; Wed, 30 Jan 2019 00:46:30 -0800 (PST) X-Google-Smtp-Source: ALg8bN78FvGmWkx+51XbX69G4hsKWbIETfH0JweQUeZTPonrFfWVUwa8aFtc8CCn7JglQig2Ejvw X-Received: by 2002:a17:902:2e01:: with SMTP id q1mr28572839plb.97.1548837990533; Wed, 30 Jan 2019 00:46:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548837990; cv=none; d=google.com; s=arc-20160816; b=fXHx6nmKDACm7JSZz7SfZ2U/PcHRSKbErON5MeEyn6LI1XoURTdB488Xby7izvnjoX cV/3PKv4pfc3LJ0Wdmmsbro5Gi51E5n5iVJ0e1lunUUfchpmS/YL29TqC2KL/1fwPFcc A4Af0oipegJgcX5Ol8tkZn9T6RiVLuWVxG2Jie9xr8b9PTOlOrJtE2YRDm2QjNELlZxq t+2lVlcreFA9hpf2s5q3t7f3HkfDIuAdGK2frE+cLMoFzed5Kg1Ng9BRlOrFtGNxE375 F98nzmicSAZmscPPd+WdkKSg9EdK66AqhoGsScWbtyOzclgoxVvhNNuPQC/be4M8LH9H ZDgQ== 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=24sU9DQ0eysgqZYyaYdNfgulINXWNh8fSCVHA2mI8WA=; b=SxDiyEZxYceS0mU0OhQfRY0dmGOvbJatXryPGI91FQVgQT9cyoY17lvYPXbcGEglaN mBJstxahnIx7mbJDNAqRnC5sO5G1VKP3Ur6SL3Xyy9G1VUUfkcmhySVGCQA+KGOYGJfZ I3tSph0kVDIIsFPp/6c+xVX5ALHgtq+/ctdquYNlq+411PVw1PWHHSu55r5e9bT+lDkO HZ46vM3GvOve4v0fO9De3QgG7nW8le8HcPAsg2TNS4KI45yOQrEAswqRVKAPjAAVLat7 S1wT2MSpJe9FE2R9uZ3kRsnb69osYJg8rQR4nhCrzJP6xL90sveh2KLtn0oLlWMVSnwe tXAA== 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 c65si938352pfe.202.2019.01.30.00.46.14; Wed, 30 Jan 2019 00:46: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 S1730223AbfA3IqF (ORCPT + 99 others); Wed, 30 Jan 2019 03:46:05 -0500 Received: from mx2.suse.de ([195.135.220.15]:38320 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725850AbfA3IqF (ORCPT ); Wed, 30 Jan 2019 03:46:05 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 4EE75AEB4; Wed, 30 Jan 2019 08:46:04 +0000 (UTC) Date: Wed, 30 Jan 2019 09:46:03 +0100 From: Petr Mladek To: Miroslav Benes Cc: Jiri Kosina , Josh Poimboeuf , Jason Baron , Joe Lawrence , Evgenii Shatokhin , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/4] livepatch: Handle failing allocation of shadow variables in the selftest Message-ID: <20190130084603.bxm57h6wf47b45fs@pathway.suse.cz> References: <20190116161720.796-1-pmladek@suse.com> <20190116161720.796-3-pmladek@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Mon 2019-01-21 13:14:38, Miroslav Benes wrote: > Hi, > > On Wed, 16 Jan 2019, Petr Mladek wrote: > > > Do not dereference pointers to the shadow variables when either > > klp_shadow_alloc() or klp_shadow_get() fail. > > I may misunderstand the patch, so bear with me, please. Is this because of > a possible null pointer dereference? If yes, shouldn't this say rather > "when both klp_shadow_alloc() and klp_shadow_get() fail"? Well, klp_shadow_get() could fail also from other reasons if there is a bug in the implementation. > > There is no need to check the other locations explicitly. The test > > would fail if any allocation fails. And the existing messages, printed > > during the test, provide enough information to debug eventual problems. Heh, this is actually the reason why I did not add the check for shadow_alloc(). Any error would be detected later with klp_shadow_get() calls that should get tested anyway. Hmm, when I think about it. A good practice is to handle klp_shadow_allow() or klp_shadow_get() failures immediately. After all, it is the sample code that people might follow. > > Signed-off-by: Petr Mladek > > --- > > lib/livepatch/test_klp_shadow_vars.c | 8 ++++---- > > 1 file changed, 4 insertions(+), 4 deletions(-) > > > > diff --git a/lib/livepatch/test_klp_shadow_vars.c b/lib/livepatch/test_klp_shadow_vars.c > > index 02f892f941dc..55e6820430dc 100644 > > --- a/lib/livepatch/test_klp_shadow_vars.c > > +++ b/lib/livepatch/test_klp_shadow_vars.c > > @@ -162,15 +162,15 @@ static int test_klp_shadow_vars_init(void) > > * to expected data. > > */ > > ret = shadow_get(obj, id); > > - if (ret == sv1 && *sv1 == &var1) > > + if (ret && ret == sv1 && *sv1 == &var1) > > pr_info(" got expected PTR%d -> PTR%d result\n", > > ptr_id(sv1), ptr_id(*sv1)); > > ret = shadow_get(obj + 1, id); > > - if (ret == sv2 && *sv2 == &var2) > > + if (ret && ret == sv2 && *sv2 == &var2) > > pr_info(" got expected PTR%d -> PTR%d result\n", > > ptr_id(sv2), ptr_id(*sv2)); > > ret = shadow_get(obj, id + 1); > > - if (ret == sv3 && *sv3 == &var3) > > + if (ret && ret == sv3 && *sv3 == &var3) > > pr_info(" got expected PTR%d -> PTR%d result\n", > > ptr_id(sv3), ptr_id(*sv3)); > > There is one more similar site calling shadow_get(obj, id + 1) which is > fixed. Heh, I think that I did not add the check there on purpose. If we are here, shadow_get(obj, id + 1) must have already succeeded above. But it is a bad practice. We should always check the output. I'll do so in v2. Best Regards, Petr