Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp5527186ima; Tue, 5 Feb 2019 13:19:16 -0800 (PST) X-Google-Smtp-Source: AHgI3Ibeq2QffFhVx643ZylPpdr31BjC21GBu2Eho9SOHNUBLHbUhj0ifhkEyjYFenSDNndKTalI X-Received: by 2002:a62:5ec5:: with SMTP id s188mr6930487pfb.145.1549401555994; Tue, 05 Feb 2019 13:19:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549401555; cv=none; d=google.com; s=arc-20160816; b=XCqJVrkhQaE+bQnhQl30N/IKXM3NHAqSAXlgcCDAA4z4UWMApCcmtG3p4VyXIx6g10 0AH9jhNJKfhaFAG3g7l0GKwZUIs/PF77aEv3+Lcj2YCn3o8yclecPK8hPPxwrUgro7w9 Xu9S/DWM08e2GjTE7jsOompNCRhXSVNUaUpzVF9HuKLnSu50VNy7Ns2eECsBLPg/vJ6Y 5p6z4lINahSUGUPSdmgqdCLNV4BCCElb/bRTO/e0XWvd2lIXV8Diml2Z1DffUdOpv+0s yDna8pt7dclue8INH6ISjsCNL5c88cqmv9LI4ZDGsggzIsTu7cYfSl2PW5uqGWOouTHr /qIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=pQ6WJreuZ/M6UdTyb0U0vfICXFjFkSzmeU2PQ2ji2c0=; b=uUQIQMUwVSxQSHUV4KZ9FODfM/3WLgRAxciJVxQOqDsAGjfubLZTEyksRe1+5EIUI6 TtPJGVKoIMaPK684UvWi/ShAxs3BBpaUEnU01OqNbffxyq9b7vmxHDdCnJwkrnJKijgn Xt6LqvLsIXmIc4PItvCe0MKPhQvrWk3VXUOiS0tlHLL5FQImL9ZtInJ1Xpau/S0lrrtP tSAMFPaeZz6NqO9qCEbrl+F6o2dVUKVzJ4SAlAShdLmYC+v6Ddy11AAsZxFq8nbfV/eB 0tbjTZqClqZszxmRHYYs1ZVd9h8RTZup3lAASTyiCnIJad8QHNAYgB9tvllXMJegA36g umJw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n24si3958616pgv.119.2019.02.05.13.18.58; Tue, 05 Feb 2019 13:19: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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728419AbfBEVRQ (ORCPT + 99 others); Tue, 5 Feb 2019 16:17:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43136 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726114AbfBEVRP (ORCPT ); Tue, 5 Feb 2019 16:17:15 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4FC1B89AC5; Tue, 5 Feb 2019 21:17:15 +0000 (UTC) Received: from [10.18.17.208] (dhcp-17-208.bos.redhat.com [10.18.17.208]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6B4C31054FC9; Tue, 5 Feb 2019 21:17:14 +0000 (UTC) Subject: Re: [PATCH v2 3/4] livepatch: Proper error handling in the shadow variables selftest To: Petr Mladek , Jiri Kosina , Josh Poimboeuf , Miroslav Benes Cc: Jason Baron , Evgenii Shatokhin , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org References: <20190204135653.31406-1-pmladek@suse.com> <20190204135653.31406-4-pmladek@suse.com> From: Joe Lawrence Message-ID: <6c313c97-fd7b-8ab6-446f-6dac4c34a30c@redhat.com> Date: Tue, 5 Feb 2019 16:17:13 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <20190204135653.31406-4-pmladek@suse.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 05 Feb 2019 21:17:15 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/4/19 8:56 AM, Petr Mladek wrote: > Add proper error handling when allocating or getting shadow variables > in the selftest. It prevents an invalid pointer access in some situations. > It shows the good programming practice in the others. > > The error codes are just the best guess and specific for this particular > test. In general, klp_shadow_alloc() returns NULL also when the given > shadow variable has already been allocated. In addition, both > klp_shadow_alloc() and klp_shadow_get_or_alloc() might fail from > other reasons when the constructor fails. > > Note, that the error code is not really important even in the real life. > The use of shadow variables should be transparent for the original > livepatched code. > > Signed-off-by: Petr Mladek > --- > lib/livepatch/test_klp_shadow_vars.c | 22 ++++++++++++++++++++++ > 1 file changed, 22 insertions(+) > > diff --git a/lib/livepatch/test_klp_shadow_vars.c b/lib/livepatch/test_klp_shadow_vars.c > index f5441c193166..fe5c413efe96 100644 > --- a/lib/livepatch/test_klp_shadow_vars.c > +++ b/lib/livepatch/test_klp_shadow_vars.c > @@ -154,22 +154,37 @@ static int test_klp_shadow_vars_init(void) > * Allocate a few shadow variables with different and . > */ > sv1 = shadow_alloc(obj, id, size, gfp_flags, shadow_ctor, &var1); > + if (!sv1) > + return -ENOMEM; > + > sv2 = shadow_alloc(obj + 1, id, size, gfp_flags, shadow_ctor, &var2); > + if (!sv2) > + return -ENOMEM; > + > sv3 = shadow_alloc(obj, id + 1, size, gfp_flags, shadow_ctor, &var3); > + if (!sv3) > + return -ENOMEM; > > /* > * Verify we can find our new shadow variables and that they point > * to expected data. > */ > ret = shadow_get(obj, id); > + if (!ret) > + return -EINVAL; > if (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) > + return -EINVAL; > if (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) > + return -EINVAL; > if (ret == sv3 && *sv3 == &var3) > pr_info(" got expected PTR%d -> PTR%d result\n", > ptr_id(sv3), ptr_id(*sv3)); > @@ -179,7 +194,12 @@ static int test_klp_shadow_vars_init(void) > * The second invocation should return the same shadow var. > */ > sv4 = shadow_get_or_alloc(obj + 2, id, size, gfp_flags, shadow_ctor, &var4); > + if (!sv4) > + return -ENOMEM; > + > ret = shadow_get_or_alloc(obj + 2, id, size, gfp_flags, shadow_ctor, &var4); > + if (!ret) > + return -EINVAL; > if (ret == sv4 && *sv4 == &var4) > pr_info(" got expected PTR%d -> PTR%d result\n", > ptr_id(sv4), ptr_id(*sv4)); > @@ -207,6 +227,8 @@ static int test_klp_shadow_vars_init(void) > * We should still find an variable. > */ > ret = shadow_get(obj, id + 1); > + if (!ret) > + return -EINVAL; > if (ret == sv3 && *sv3 == &var3) > pr_info(" got expected PTR%d -> PTR%d result\n", > ptr_id(sv3), ptr_id(*sv3)); > Fixes look good to me, Acked-by: Joe Lawrence -- Joe