Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp740231ybb; Fri, 3 Apr 2020 10:56:55 -0700 (PDT) X-Google-Smtp-Source: APiQypK0+BCn7bwYUhh5DyB2u/Awh0jgghr7CVH3r3d5X0tT7JgdZFf0WbYXdYpJtZBC5QgrziUb X-Received: by 2002:a9d:8e4:: with SMTP id 91mr7903483otf.130.1585936615619; Fri, 03 Apr 2020 10:56:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585936615; cv=none; d=google.com; s=arc-20160816; b=uuGorHhaJs5iy0djQCWqJ9tJXxX0vaU+EZ8+oRPMGeUqO51ZnvK0MK0euQqL0frSbC CzFZkvPYyvXm3pzNuCPPFscRsdzUaRx5bmxFdwRsCpqFwFRboupXaiz0u8YhQBOZA3Mi v1zU3ycJ7+L5Wzj0ZYnoA/McGrKfXfK05EQzbvrBhYrlYMwugyGrhasPskkwG5qPvNiH dvOSEbZTElgQXuvoLYIHtV5aP0fTR+axPdyqRnni2JM9hH+nTsR0d+b+jPL6JWnsu/dp xzeU1U+wBBV/ZPc9E9u+2bbEDGmF8QCnsUwDw0TmCKfbXJuzt+mOTRSiQfjRvwDYYtma SQ2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=m/sN5U1KWfQeBEyLLOyOkjJBPzSeLq7M2YpI/ghADG0=; b=Zh24E7MIJ8L6kQr56TNzH2VbbQPO/p6eHL972VpOQ242gnPd1pnWiv5vIbVUnjtX6i qYEdiOxfe5uybw/B07lg+ZXyWYPQCmstDtVs/zOfFES72UmsHY93KmjvZqyjpU73Uc6g BpyDuG2SIYYkYwoxilNx1AW5NsEzFtVj7jKszxtNOu/NQ1xE0TkXiURz4+/KkckWgjhn dtynlu7n3xTvsezFSs28Z44QmaAaCwdrdgQuMBSsisgturXWp7RS7BekT1On9BDYVJXn 9VzyYWXAH26L/o1MvAIJh4jsTSuHZV3DNIen8CRsmIJu54H64VJaRB2UVu4RYbyrIZEX o7zQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Q+J4VQzh; 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=pass (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 o63si4260083oih.74.2020.04.03.10.56.42; Fri, 03 Apr 2020 10:56:55 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Q+J4VQzh; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728552AbgDCRyg (ORCPT + 99 others); Fri, 3 Apr 2020 13:54:36 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:41479 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727167AbgDCRyf (ORCPT ); Fri, 3 Apr 2020 13:54:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585936474; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=m/sN5U1KWfQeBEyLLOyOkjJBPzSeLq7M2YpI/ghADG0=; b=Q+J4VQzhqICfIfmchwBrb3wU7Igj6UGpL36ss4Gl6Qaizn/mVC3tQbt1sA9FzA0dkEGwLy nUczet5p4tOb0ypDu9AQ6FuB3FzVDbXQV/TzpUDz49I0HNnEfQzwscz/hh1Vz1gsGy1KZy RFlvHDOV1z9V/AIbe2FrejjX8IUUONc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-495-dYKjhh3uNNiiE1b8mvym5A-1; Fri, 03 Apr 2020 13:54:32 -0400 X-MC-Unique: dYKjhh3uNNiiE1b8mvym5A-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C834D1005F6D; Fri, 3 Apr 2020 17:54:30 +0000 (UTC) Received: from redhat.com (ovpn-114-27.phx2.redhat.com [10.3.114.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E15D360BF3; Fri, 3 Apr 2020 17:54:29 +0000 (UTC) Date: Fri, 3 Apr 2020 13:54:28 -0400 From: Joe Lawrence To: Petr Mladek Cc: Jiri Kosina , Josh Poimboeuf , Miroslav Benes , Kamalesh Babulal , Nicolai Stange , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [POC 04/23] livepatch: Prevent loading livepatch sub-module unintentionally. Message-ID: <20200403175428.GA30284@redhat.com> References: <20200117150323.21801-1-pmladek@suse.com> <20200117150323.21801-5-pmladek@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200117150323.21801-5-pmladek@suse.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 17, 2020 at 04:03:04PM +0100, Petr Mladek wrote: > Livepatch is split into several modules. The main module is for livepatching > vmlinux. The rest is for livepatching other modules. > > Only the livepatch module for vmlinux can be loaded by users. Others are > loaded automatically when the related module is or gets loaded. > > Users might try to load any livepatch module. It must be allowed > only when the related livepatch module for vmlinux and the livepatched > module are loaded. > > Also it is important to check that obj->name is listed in patch->obj_names. > Otherwise this module would not be loaded automatically. And it would > lead into inconsistent behavier. Anyway, the missing name means a mistake > somewhere and must be reported. > > klp_add_object() is taking over the job done by klp_module_coming(). > The error message is taken from there so that selftests do not need > to get updated. > > Signed-off-by: Petr Mladek > --- > kernel/livepatch/core.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 77 insertions(+), 1 deletion(-) > > diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c > index ec7ffc7db3a7..e2c7dc6c2d5f 100644 > --- a/kernel/livepatch/core.c > +++ b/kernel/livepatch/core.c > > [ ... snip ... ] > > int klp_add_object(struct klp_object *obj) > { > + struct klp_patch *patch; > int ret; > > ret = klp_check_object(obj, true); > if (ret) > return ret; > > + mutex_lock(&klp_mutex); > + > + patch = klp_find_patch(obj->patch_name); > + if (!patch) { > + pr_err("Can't load livepatch (%s) for module when the livepatch (%s) for vmcore is not loaded\n", > + obj->mod->name, obj->patch_name); nit: s/vmcore/vmlinux in the error message? > + ret = -EINVAL; > + goto err; Minor code snafu: !patch for this exit path means ... > + } > + > + if (!klp_is_object_compatible(patch, obj)) { > + ret = -EINVAL; > + goto err; > + } > + > + mutex_unlock(&klp_mutex); > return 0; > + > +err: > + /* > + * If a patch is unsuccessfully applied, return > + * error to the module loader. > + */ > + pr_warn("patch '%s' failed for module '%s', refusing to load module '%s'\n", > + patch->obj->patch_name, obj->name, obj->name); ... we can't access patch->obj->patch_name here. -- Joe