Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp689544imm; Fri, 12 Oct 2018 05:15:01 -0700 (PDT) X-Google-Smtp-Source: ACcGV62MeTm9xEryT3dbynOP02DfIPH22wfMv1YA+uw2Krvc+qTPyDea0OShfyEKsDFydEqEJ5GO X-Received: by 2002:a62:9fc4:: with SMTP id v65-v6mr5884298pfk.130.1539346501195; Fri, 12 Oct 2018 05:15:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539346501; cv=none; d=google.com; s=arc-20160816; b=c60F6uzgI639v4fCcbfgcNq4Veawxwf/61mVidstcZ+qyseqmuLw6ZTjl4hhPBqr/G /IpRacXrNj691ktFsRULmNqit3l0rKXDFiuAoJ/GkKzxSULXboFgQNniQjt+r+Xx47sM eUK87iGgaFcCLpdKbxWYKTVE/2CfHBsxjSuvxooSMNKxB+Ysfm36edNNSrp31Zmxx+ne wW1A3GGgXpaAnM+ndU4F2C9Vab9KLHOEkJpGLyEH/ETdDalFlE+MU89U7ge14NvzQXa/ jKtinLolyz1McifTAuUJBCH1WdEpLciTTT+NdaT+RXtnyJNUoIObCB0dpG4GpUHYcYD4 0cFA== 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=nKMv0vzu2E2PAwv1YpCMlaoAWET0fbrXZ2mzhzTT0Bs=; b=q9mSQe16+6kZYGpoPWtYBOoUXiFkNFCSlGS/aeJSvJOOrW+g4ZN2BKegOTvs6ooIfX 5FpvU5MaZTQI8Qfd2bu4Riy9oT5YSc5im+vJHtJlm1tNRlaHry//rWG5UEeLhum5Zj22 Nuo74VAJCRClvjSGecE0+9ZhYhZP2zsVCPqLP9S+rf2DXZrUKxJQJFm6lTAAEQ1vjucA DxFkNUmRRt3yIK8F4p8/O9e1sAGr4zpqZlTs3/EXHOxHcXxVAIEZjPEzS9SVTPL5tcCP vt3AXY7AkHo++1N6IW/HUNMHKRuo8Si6ZdKvx2jDtXJ6IYjqTfUje3/B52BLE7frXlEa 3WqQ== 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 v128-v6si1230882pfc.193.2018.10.12.05.14.46; Fri, 12 Oct 2018 05:15:01 -0700 (PDT) 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 S1728524AbeJLTor (ORCPT + 99 others); Fri, 12 Oct 2018 15:44:47 -0400 Received: from mx2.suse.de ([195.135.220.15]:38762 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728145AbeJLToq (ORCPT ); Fri, 12 Oct 2018 15:44:46 -0400 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 BC875AE29; Fri, 12 Oct 2018 12:12:34 +0000 (UTC) Date: Fri, 12 Oct 2018 14:12:34 +0200 From: Petr Mladek To: Miroslav Benes Cc: Jiri Kosina , Josh Poimboeuf , Jason Baron , Joe Lawrence , Jessica Yu , Evgenii Shatokhin , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v12 07/12] livepatch: Use lists to manage patches, objects and functions Message-ID: <20181012121234.rgaamxlumrgz6ohb@pathway.suse.cz> References: <20180828143603.4442-1-pmladek@suse.com> <20180828143603.4442-8-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 2018-09-03 18:00:45, Miroslav Benes wrote: > > > -#define klp_for_each_object(patch, obj) \ > > +#define klp_for_each_object_static(patch, obj) \ > > for (obj = patch->objs; obj->funcs || obj->name; obj++) > > > > -#define klp_for_each_func(obj, func) \ > > +#define klp_for_each_object(patch, obj) \ > > + list_for_each_entry(obj, &patch->obj_list, node) > > + > > +#define klp_for_each_func_static(obj, func) \ > > for (func = obj->funcs; \ > > func->old_name || func->new_addr || func->old_sympos; \ > > func++) > > > > +#define klp_for_each_func(obj, func) \ > > + list_for_each_entry(func, &obj->func_list, node) > > + > > int klp_enable_patch(struct klp_patch *); > > > > void arch_klp_init_object_loaded(struct klp_patch *patch, > > diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c > > index 6a47b36a6c9a..7bc23a106b5b 100644 > > --- a/kernel/livepatch/core.c > > +++ b/kernel/livepatch/core.c > > @@ -50,6 +50,21 @@ LIST_HEAD(klp_patches); > > > > static struct kobject *klp_root_kobj; > > > > +static void klp_init_lists(struct klp_patch *patch) > > +{ > > + struct klp_object *obj; > > + struct klp_func *func; > > + > > + INIT_LIST_HEAD(&patch->obj_list); > > + klp_for_each_object_static(patch, obj) { > > + list_add(&obj->node, &patch->obj_list); > > + > > + INIT_LIST_HEAD(&obj->func_list); > > + klp_for_each_func_static(obj, func) > > + list_add(&func->node, &obj->func_list); > > + } > > +} > > + > > static bool klp_is_module(struct klp_object *obj) > > { > > return obj->name; > > @@ -664,6 +679,7 @@ static int klp_init_patch(struct klp_patch *patch) > > patch->module_put = false; > > INIT_LIST_HEAD(&patch->list); > > init_completion(&patch->finish); > > + klp_init_lists(patch); > > This could explode easily if patch->objs is NULL. The check is just below. > > > if (!patch->objs) > > return -EINVAL; > > Here. > > klp_init_lists() calls klp_for_each_object_static() which accesses > obj->name without a check for obj. Great catch! > since the check is already there, could you move klp_init_lists() > call after the check? The same problem is with accessing obj->funcs by klp_for_each_func_static(). I have moved both checks into klp_init_lists(). I made sure that the lists were initialized to be usable with the free functions even in case of error. Best Regards, Petr