linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josh Poimboeuf <jpoimboe@redhat.com>
To: Miroslav Benes <mbenes@suse.cz>
Cc: Chris J Arges <chris.j.arges@canonical.com>,
	live-patching@vger.kernel.org, jeyu@redhat.com,
	Seth Jennings <sjenning@redhat.com>,
	Jiri Kosina <jikos@kernel.org>, Vojtech Pavlik <vojtech@suse.com>,
	linux-api@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] livepatch: old_name.number scheme in livepatch sysfs directory
Date: Tue, 3 Nov 2015 10:50:58 -0600	[thread overview]
Message-ID: <20151103165058.GM27488@treble.redhat.com> (raw)
In-Reply-To: <alpine.LNX.2.00.1511031705340.6257@pobox.suse.cz>

On Tue, Nov 03, 2015 at 05:09:48PM +0100, Miroslav Benes wrote:
> On Tue, 3 Nov 2015, Josh Poimboeuf wrote:
> 
> > On Tue, Nov 03, 2015 at 11:52:08AM +0100, Miroslav Benes wrote:
> > > On Mon, 2 Nov 2015, Chris J Arges wrote:
> > > 
> > > [...]
> > > 
> > > > +static int klp_get_func_pos_callback(void *data, const char *name,
> > > > +				      struct module *mod, unsigned long addr)
> > > > +{
> > > > +	struct klp_find_arg *args = data;
> > > > +
> > > > +	if ((mod && !args->objname) || (!mod && args->objname))
> > > > +		return 0;
> > > > +
> > > > +	if (strcmp(args->name, name))
> > > > +		return 0;
> > > > +
> > > > +	if (args->objname && strcmp(args->objname, mod->name))
> > > > +		return 0;
> > > > +
> > > > +	/* on address match, return 1 to break kallsyms_on_each_symbol loop */
> > > > +	if (args->addr == addr)
> > > > +		return 1;
> > > > +
> > > > +	/* if we don't match addr, count instance of named symbol */
> > > > +	args->count++;
> > > > +
> > > > +	return 0;
> > > > +}
> > > > +
> > > > +static int klp_get_func_pos(struct klp_object *obj, struct klp_func *func)
> > > > +{
> > > > +	struct klp_find_arg args = {
> > > > +		.objname = obj->name,
> > > > +		.name = func->old_name,
> > > > +		.addr = func->old_addr,
> > > > +		.count = 0,
> > > > +	};
> > > > +
> > > > +	mutex_lock(&module_mutex);
> > > > +	kallsyms_on_each_symbol(klp_get_func_pos_callback, &args);
> > > > +	mutex_unlock(&module_mutex);
> > > > +
> > > > +	return args.count;
> > > > +}
> > > > +
> > > >  static int klp_init_func(struct klp_object *obj, struct klp_func *func)
> > > >  {
> > > >  	INIT_LIST_HEAD(&func->stack_node);
> > > >  	func->state = KLP_DISABLED;
> > > >  
> > > >  	return kobject_init_and_add(&func->kobj, &klp_ktype_func,
> > > > -				    &obj->kobj, "%s", func->old_name);
> > > > +				    &obj->kobj, "%s,%d", func->old_name,
> > > > +				    klp_get_func_pos(obj, func));
> > > >  }
> > > 
> > > There is a problem which I missed before. klp_init_func() is called before 
> > > klp_find_verify_func_addr() in klp_init_object(). This means that 
> > > func->old_addr is either not verified yet or worse it is still 0. This 
> > > means that klp_get_func_pos_callback() never returns 1 and is thus called 
> > > on each symbol. So if you for example patched cmdline_proc_show the 
> > > resulting directory in sysfs would be called cmdline_proc_show,1 because 
> > > addr is never matched. Had old_addr been specified the name would have 
> > > been probably correct, but not for sure.
> > > 
> > > This should be fixed as well.
> > 
> > Even worse, klp_init_func() can be called even if the object hasn't been
> > loaded.  In that case there's no way to know what the value of n is, and
> > therefore no way to reliably create the sysfs entry.
> 
> Ah, right.
> 
> > Should we create "func,n" in klp_init_object_loaded() instead of
> > klp_init_func()?
> 
> So that the function entries in sysfs would be created only when the 
> object is loaded? Well, why not, but in that case it could easily confuse 
> the user.

Maybe, but I think it would be fine if we document it.  It should only
be relied on by tools, anyway.

> Object entry would be empty for not loaded object. I would not 
> dare to propose to remove such object entries. It would make things worse. 

Why would removing an empty object entry make things worse?

> So maybe we could introduce an attribute in sysfs object entry which would 
> say if the object is loaded or not. Or something like that.

Hm, I'm not sure I see how this would help.

> Hm, we can easily mess this up :)

Agreed 100% :-)

-- 
Josh

  reply	other threads:[~2015-11-03 16:50 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-02 17:58 [PATCH] livepatch: old_name.number scheme in livepatch sysfs directory Chris J Arges
2015-11-02 19:15 ` Jessica Yu
     [not found] ` <1446487137-8469-1-git-send-email-chris.j.arges-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
2015-11-02 19:52   ` [PATCH] " Josh Poimboeuf
2015-11-02 20:16     ` Chris J Arges
2015-11-02 20:32       ` Josh Poimboeuf
     [not found]         ` <20151102203241.GF27488-8wJ5/zUtDR0XGNroddHbYwC/G2K4zDHf@public.gmane.org>
2015-11-02 22:59           ` [PATCH v2] " Chris J Arges
2015-11-03  9:50             ` Miroslav Benes
2015-11-03 15:03               ` Josh Poimboeuf
     [not found]             ` <1446505187-28970-1-git-send-email-chris.j.arges-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
2015-11-03 10:52               ` Miroslav Benes
     [not found]                 ` <alpine.LNX.2.00.1511031146070.6257-ztGlSCb7Y1iN3ZZ/Hiejyg@public.gmane.org>
2015-11-03 12:44                   ` Petr Mladek
     [not found]                     ` <20151103124440.GK2599-KsEp0d+Q8qECVLCxKZUutA@public.gmane.org>
2015-11-03 15:03                       ` Josh Poimboeuf
2015-11-03 19:57                       ` Jiri Kosina
     [not found]                         ` <alpine.LNX.2.00.1511032055570.22567-ztGlSCb7Y1iN3ZZ/Hiejyg@public.gmane.org>
2015-11-03 20:06                           ` Josh Poimboeuf
     [not found]                             ` <1447259366-7055-1-git-send-email-chris.j.arges@canonical.com>
2015-11-11 16:29                               ` [PATCH 3/3 v4] livepatch: old_name,number " Chris J Arges
     [not found]                                 ` <1447259366-7055-4-git-send-email-chris.j.arges-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
2015-11-11 18:01                                   ` Josh Poimboeuf
     [not found]                               ` <1447347595-30728-1-git-send-email-chris.j.arges@canonical.com>
2015-11-12 16:59                                 ` [PATCH 4/4 v5] livepatch: function,sympos " Chris J Arges
     [not found]                                 ` <1447431804-18786-1-git-send-email-chris.j.arges@canonical.com>
2015-11-13 16:23                                   ` [PATCH 3/3 v6] " Chris J Arges
     [not found]                                   ` <1447693391-10065-1-git-send-email-chris.j.arges@canonical.com>
2015-11-16 17:03                                     ` [PATCH 3/3 v7] " Chris J Arges
     [not found]                                     ` <1448040325-32498-1-git-send-email-chris.j.arges@canonical.com>
2015-11-20 17:25                                       ` [PATCH 3/3 v8] " Chris J Arges
2015-11-23  9:47                                         ` Miroslav Benes
     [not found]                                       ` <1449024076-16034-1-git-send-email-chris.j.arges@canonical.com>
2015-12-02  2:40                                         ` [PATCH 3/3 v9] " Chris J Arges
2015-11-03 14:58                 ` [PATCH v2] livepatch: old_name.number " Josh Poimboeuf
2015-11-03 16:09                   ` Miroslav Benes
2015-11-03 16:50                     ` Josh Poimboeuf [this message]
     [not found]                       ` <20151103165058.GM27488-8wJ5/zUtDR0XGNroddHbYwC/G2K4zDHf@public.gmane.org>
2015-11-03 20:42                         ` Chris J Arges
2015-11-04  9:52                         ` Miroslav Benes
2015-11-04 16:03                           ` Josh Poimboeuf
     [not found]                             ` <20151104160354.GA29899-8wJ5/zUtDR0XGNroddHbYwC/G2K4zDHf@public.gmane.org>
2015-11-04 16:17                               ` Chris J Arges
2015-11-05 15:18                             ` Miroslav Benes
2015-11-05 15:56                               ` Josh Poimboeuf
2015-11-05 16:07                                 ` Chris J Arges
     [not found]                                 ` <20151105155656.GD28254-8wJ5/zUtDR0XGNroddHbYwC/G2K4zDHf@public.gmane.org>
2015-11-09 16:16                                   ` [PATCH v3] livepatch: old_name,number " Chris J Arges
2015-11-09 20:56                                     ` Josh Poimboeuf
     [not found]                                       ` <20151109205608.GC3914-8wJ5/zUtDR0XGNroddHbYwC/G2K4zDHf@public.gmane.org>
2015-11-09 23:01                                         ` Chris J Arges
2015-11-10  4:54                                           ` Josh Poimboeuf
2015-11-10  8:49                                             ` Miroslav Benes
     [not found]                                               ` <alpine.LNX.2.00.1511100944120.16914-ztGlSCb7Y1iN3ZZ/Hiejyg@public.gmane.org>
2015-11-10 13:40                                                 ` Josh Poimboeuf
2015-11-10  9:02                                     ` Miroslav Benes

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=20151103165058.GM27488@treble.redhat.com \
    --to=jpoimboe@redhat.com \
    --cc=chris.j.arges@canonical.com \
    --cc=jeyu@redhat.com \
    --cc=jikos@kernel.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=live-patching@vger.kernel.org \
    --cc=mbenes@suse.cz \
    --cc=sjenning@redhat.com \
    --cc=vojtech@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;
as well as URLs for NNTP newsgroup(s).