From: Evgeniy Polyakov <johnpol@2ka.mipt.ru>
To: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: netdev@vger.kernel.org, netfilter-devel@vger.kernel.org
Subject: Re: Passive OS fingerprinting.
Date: Wed, 2 Jul 2008 01:21:40 +0400 [thread overview]
Message-ID: <20080701212139.GA18619@2ka.mipt.ru> (raw)
In-Reply-To: <20080701195648.GD7488@linux.vnet.ibm.com>
Hi Paul.
On Tue, Jul 01, 2008 at 12:56:48PM -0700, Paul E. McKenney (paulmck@linux.vnet.ibm.com) wrote:
> > static int ipt_osf_proc_read(char *buf, char **start, off_t off, int count,
> > int *eof, void *data)
> > {
> > struct ipt_osf_finger *f = NULL;
> > int i, __count, err;
> >
> > *eof = 1;
> > __count = count;
> > count = 0;
> >
> > rcu_read_lock();
> > list_for_each_entry(f, &ipt_finger_list, flist) {
>
> Does the above need to be list_for_each_entry_rcu()?
Yeah, I messed with procfs handlers.
...
> > static int ipt_osf_proc_write(struct file *file, const char *buffer,
> > unsigned long count, void *data)
> > {
> > int cnt, i;
> > char obuf[MAXOPTSTRLEN];
> > struct ipt_osf_finger *finger, *n;
> > char *pbeg, *pend;
> >
> > if (count > 0xffff)
> > return -E2BIG;
> >
> > if (count == strlen(OSFFLUSH) && !strncmp(buffer, OSFFLUSH, strlen(OSFFLUSH))) {
> > int i = 0;
> > synchronize_rcu();
> > spin_lock_bh(&ipt_osf_lock);
> > list_for_each_entry_safe(finger, n, &ipt_finger_list, flist) {
>
> This is OK -- we hold the update-side lock, so don't need _rcu.
>
> > i++;
> > list_del_rcu(&finger->flist);
> > ipt_osf_finger_free(finger);
>
> Why is it safe to immediately free the element that we just removed from
> an RCU-protected list? The above synchronize_rcu() won't help us given
> that it is still in the list at that point.
>
> This could be fixed by using call_rcu() in ipt_osf_finger_free().
Yup, it is safe on UP machine, since without lock it is only accessed
from the bottom half, which is disabled, but running it on different CPU
will lead to crash.
procfs was not a very good choice here :)
> > cnt = snprintf(finger->details,
> > ((count - (pbeg - buffer) + 1) >
> > MAXDETLEN) ? MAXDETLEN : (count - (pbeg - buffer) + 1),
> > "%s", pbeg);
> >
> > log("%s - %s[%s] : %s\n",
> > finger->genre, finger->version, finger->subtype, finger->details);
> >
> > ipt_osf_parse_opt(finger->opt, &finger->opt_num, obuf, sizeof(obuf));
> >
> > synchronize_rcu();
>
> I don't understand what this synchronize_rcu() is doing for us.
>
> Is the idea to make sure that all RCU readers see the prior deletes as
> having happened before we do the below addition? If so, please add a
> comment to this effect.
Just to be sure, that return from the call does update the list.
It is not needed in practice.
> > static void __devexit ipt_osf_fini(void)
> > {
> > struct ipt_osf_finger *f, *n;
> >
> > remove_proc_entry("osf", proc_net_netfilter);
> > xt_unregister_match(&ipt_osf_match);
> >
> > list_for_each_entry_safe(f, n, &ipt_finger_list, flist) {
>
> Why is it safe to do the above without being in an RCU read-side critical
> section? Have all possible RCU readers somehow been banished? If so,
> how have they been banished?
>
> > list_del(&f->flist);
>
> Ditto for why the list_del() is safe without the update-side lock and
> why it doesn't have to be list_del_rcu().
Procfs was messed, it should use proper rcu freeing path, and although
procefs entry was removed, there may be some reference.
Thanks a lot for your review Paul.
--
Evgeniy Polyakov
next prev parent reply other threads:[~2008-07-01 21:21 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-01 11:39 Passive OS fingerprinting Evgeniy Polyakov
2008-07-01 11:53 ` Patrick McHardy
2008-07-01 12:03 ` Evgeniy Polyakov
2008-07-01 12:35 ` Patrick McHardy
2008-07-01 13:08 ` Evgeniy Polyakov
2008-07-01 13:41 ` Patrick McHardy
2008-07-01 14:14 ` Evgeniy Polyakov
2008-07-01 14:16 ` Patrick McHardy
2008-07-01 14:48 ` Evgeniy Polyakov
2008-07-01 14:54 ` Patrick McHardy
2008-07-01 14:26 ` Jan Engelhardt
2008-07-01 14:25 ` Patrick McHardy
2008-07-01 13:32 ` Jeff Garzik
2008-07-01 13:35 ` Patrick McHardy
2008-07-01 13:47 ` Evgeniy Polyakov
2008-07-01 15:34 ` Jeff Garzik
2008-07-01 15:44 ` Patrick McHardy
2008-07-01 13:39 ` Evgeniy Polyakov
2008-07-01 19:56 ` Paul E. McKenney
2008-07-01 21:21 ` Evgeniy Polyakov [this message]
[not found] ` <20080701224149.GA8449@linux.vnet.ibm.com>
2008-07-02 4:46 ` Evgeniy Polyakov
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=20080701212139.GA18619@2ka.mipt.ru \
--to=johnpol@2ka.mipt.ru \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=paulmck@linux.vnet.ibm.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).