mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Lawrence <joe.lawrence@redhat.com>
To: Miroslav Benes <mbenes@suse.cz>
Cc: live-patching@vger.kernel.org, linux-kernel@vger.kernel.org,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	Jessica Yu <jeyu@kernel.org>, Jiri Kosina <jikos@kernel.org>,
	Petr Mladek <pmladek@suse.com>,
	Chris J Arges <chris.j.arges@canonical.com>
Subject: Re: [PATCH v5 1/3] livepatch: add (un)patch callbacks
Date: Tue, 12 Sep 2017 18:05:44 -0400	[thread overview]
Message-ID: <20170912220544.zdgh65o4aqmd5ni4@redhat.com> (raw)
In-Reply-To: <c50de669-e630-dff2-7bc4-d0a8997d204e@redhat.com>

On Tue, Sep 12, 2017 at 11:48:48AM -0400, Joe Lawrence wrote:
> On 09/12/2017 04:53 AM, Miroslav Benes wrote:
> >> @@ -871,13 +882,27 @@ int klp_module_coming(struct module *mod)
> >>  			pr_notice("applying patch '%s' to loading module '%s'\n",
> >>  				  patch->mod->name, obj->mod->name);
> >>  
> >> +			ret = klp_pre_patch_callback(obj);
> >> +			if (ret) {
> >> +				pr_warn("pre-patch callback failed for object '%s'\n",
> >> +					obj->name);
> >> +				goto err;
> >> +			}
> > 
> > There is a problem here. We cycle through all enabled patches (or 
> > klp_transition_patch) and call klp_pre_patch_callback() everytime an 
> > enabled patch contains a patch for a coming module. Now, it can easily 
> > happen that klp_pre_patch_callback() fails. And not the first one from the 
> > first relevant patch, but the next one. In that case we need to call 
> > klp_post_unpatch_callback() for all already processed relevant patches in 
> > the error path.
> 
> Good test case, if I understand you correctly:
> 
>  - Load target modules mod1 and mod2
>  - Load a livepatch that targets mod1 and mod2
>    - pre-patch succeeds for mod1
>    - pre-patch fails for mod2
> 
> and then we should:
> 
>  - NOT run post-patch or pre/post-unpatch handlers for mod2
>  - NOT run post-patch or pre-unpatch handlers for mod1
>  - do run post-unpatch handler for mod1
>  - Refuse to load the livepatch
> 
> Does that sound right?

Erm, probably not...

> > Unfortunately, we need to do the same for klp_patch_object() below, 
> > because there is the same problem and we missed it.
> > 
> >> +
> >>  			ret = klp_patch_object(obj);
> >>  			if (ret) {
> >>  				pr_warn("failed to apply patch '%s' to module '%s' (%d)\n",
> >>  					patch->mod->name, obj->mod->name, ret);
> >> +
> >> +				if (patch != klp_transition_patch)
> >> +					klp_post_unpatch_callback(obj);
> >> +
> >>  				goto err;
> > 
> > Here.
> > 
> > Could you do it as a part of the patch set (or send it separately), 
> > please?

I've re-read this a few times, and I think I might have been originally
off-base with what I thought you were concerned about.  But I think I
grok it now: the problem you pointed out arises because
klp_module_coming() iterates like so:

  for each klp_patch
    for each kobj in klp_patch

which means that we may have made pre-patch callbacks and patched a
given kobj for an earlier klp_patch that now fails for a later
klp_patch.

What should be the defined behavior in this case?  I would expect that
we need to unpatch all similar kobjs across klp_patches which have
already been successfully patched.  In turn, their post-unpatch
callbacks should be invoked.

If that's true, maybe this would make a better follow-on patch.

-- Joe

  reply	other threads:[~2017-09-12 22:05 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-31 14:53 [PATCH v5 0/3] livepatch callbacks Joe Lawrence
2017-08-31 14:53 ` [PATCH v5 1/3] livepatch: add (un)patch callbacks Joe Lawrence
2017-09-12  8:53   ` Miroslav Benes
2017-09-12 15:48     ` Joe Lawrence
2017-09-12 22:05       ` Joe Lawrence [this message]
2017-09-12 22:22         ` Josh Poimboeuf
2017-09-13  7:29           ` Miroslav Benes
2017-09-13 13:53             ` Joe Lawrence
2017-09-13 21:36               ` [RFC] livepatch: unpatch all klp_objects if klp_module_coming fails Joe Lawrence
2017-09-20 11:19                 ` Miroslav Benes
2017-09-20 15:17                   ` Joe Lawrence
2017-09-27 12:17                 ` Petr Mladek
2017-09-13  7:22       ` [PATCH v5 1/3] livepatch: add (un)patch callbacks Miroslav Benes
2017-09-26 14:49   ` Petr Mladek
2017-09-26 19:01     ` Joe Lawrence
2017-09-27  8:02       ` Petr Mladek
2017-08-31 14:53 ` [PATCH v5 2/3] livepatch: move transition "complete" notice into klp_complete_transition() Joe Lawrence
2017-09-12  9:09   ` Miroslav Benes
2017-09-27 11:35   ` Petr Mladek
2017-08-31 14:53 ` [PATCH v5 3/3] livepatch: add transition notices Joe Lawrence
2017-09-12  9:29   ` Miroslav Benes
2017-09-27 11:49   ` Petr Mladek
2017-09-27 15:45     ` Joe Lawrence

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170912220544.zdgh65o4aqmd5ni4@redhat.com \
    --to=joe.lawrence@redhat.com \
    --cc=chris.j.arges@canonical.com \
    --cc=jeyu@kernel.org \
    --cc=jikos@kernel.org \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=live-patching@vger.kernel.org \
    --cc=mbenes@suse.cz \
    --cc=pmladek@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®