Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6867886imu; Thu, 31 Jan 2019 00:42:15 -0800 (PST) X-Google-Smtp-Source: ALg8bN4VCHurmch5XWBkY2TQ4zCM4Eny98BYYZT0uEfcie8As3YqvDa3ic1DNg66Zj4GyYXLGrZd X-Received: by 2002:a63:9256:: with SMTP id s22mr29775528pgn.224.1548924135527; Thu, 31 Jan 2019 00:42:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548924135; cv=none; d=google.com; s=arc-20160816; b=MIN5uZVusuq+2psJaJVx2/dUsk1Uv+bScL1MrD9zq5YluvfYOaGauaXiVP1jAJfYoI Lcp2xBxFinX4p0uMtx0TW36VpaAyR30wm9icqKPnAvutOlzCepBJYeo9apq3GYMNMu+n kfIhnkwkERbLf6oyKZot1w02NgJ62XD2rp/OxDpHA+vMDMW6YoclPfFDkzZZX8fqTIbj 5WGrk2r3ZS5fvwf4xa60DtnlAsPRC6lWEbMm0yaO9dE392GeyvY0/KGpKXFkUrml/AU4 jNYi9SYd86E/Ecx0ja3x1ghD0wViHQVpW7HYyk01wA8lCTd9sjfcIgXG+QYiP39YrvRp W3Cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=Sxd8ALl2b7gJE5RFYH6mJ+YvlPnxw3tzGA71I33XftE=; b=lVkwWOWSUAuzQiiUXqF+X2sRsaTDsFFyDAfeVRxjkutC177OVg0HOXfwjbNIyannaJ 7HyEARvTBKkVSaG+18UncydRN4m0z0+/yTPBTydFiwaFhnduKfg590oEocQkYCklK9ek 50pKmyWuhWWlXXYW0UwZS/Mm8Enlu723qpgr4o8MBpCQwu7P/+7Tm71MBe5zfiXQ1WCB o0yC0oBNYpkInrpXXUQ2wNbhfm53j24vV4KId6Xo9Qxk1sdb+JzUiVWBVpuhS9TnNj+S g2QfWOgtGMkXYmLuk09CAgMknDtdeb32Fa8xNhCGLjmJyGRYxbJNMlx6PI4YD/aB7fej s+Bg== 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 61si3916246plz.117.2019.01.31.00.41.59; Thu, 31 Jan 2019 00:42:15 -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 S1726603AbfAaIk2 (ORCPT + 99 others); Thu, 31 Jan 2019 03:40:28 -0500 Received: from mx2.suse.de ([195.135.220.15]:56072 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725797AbfAaIk2 (ORCPT ); Thu, 31 Jan 2019 03:40:28 -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 4B23FAFD2; Thu, 31 Jan 2019 08:40:26 +0000 (UTC) Date: Thu, 31 Jan 2019 09:40:25 +0100 (CET) From: Miroslav Benes To: Petr Mladek 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 In-Reply-To: <20190130084603.bxm57h6wf47b45fs@pathway.suse.cz> Message-ID: References: <20190116161720.796-1-pmladek@suse.com> <20190116161720.796-3-pmladek@suse.com> <20190130084603.bxm57h6wf47b45fs@pathway.suse.cz> User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 30 Jan 2019, Petr Mladek wrote: > 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. Yes, but I meant that if only klp_shadow_alloc() or klp_shadow_get() failed, it would be caught by ret == sv1 comparison and you would not need to add checking of ret at the beginning. > > > 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. I think so. > > > 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. Yes, but if it failed, you would not notice. The message would not be printed and that's all. So it is possible to run into the same problematic error condition here. > But it is a bad practice. We should always check the output. > I'll do so in v2. Agreed. Miroslav