netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ben Greear <greearb@candelatech.com>
To: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Eric Dumazet <eric.dumazet@gmail.com>,
	Francesco Ruggeri <fruggeri@aristanetworks.com>,
	netdev@vger.kernel.org, Stephen Hemminger <shemminger@vyatta.com>
Subject: Re: Race condition in ipv6 code
Date: Sat, 14 Jan 2012 10:31:04 -0800	[thread overview]
Message-ID: <4F11C9E8.7040300@candelatech.com> (raw)
In-Reply-To: <m139biesze.fsf@fess.ebiederm.org>

On 01/13/2012 09:46 PM, Eric W. Biederman wrote:
> Ben Greear<greearb@candelatech.com>  writes:
>
>> On 01/12/2012 11:40 PM, Eric W. Biederman wrote:
>>
>>> So I really think the best solution to avoid the locking craziness is to
>>> have a wrapper that gets the value from userspace and calls
>>> schedule_work to get another thread to actually process the change.  I
>>> don't see any problems with writing a helper function for that.  The
>>> only downside with using schedule_work is that we return to userspace
>>> before the change has been fully installed in the kernel.  I don't
>>> expect that would be a problem but stranger things have happened.
>>
>> That sounds a bit risky to me.  If something sets a value, and then
>> queries it, it should always show the proper result for the previous
>> calls.
>
> Which is easy to do if you keep two values.  One integer
> for the userspace control and another integer for the internal
> kernel state.
>
> The problem is that we have exactly one integer currently.
>
>> If the queries also went through the the same sched-work queue
>> then maybe it would be OK.
>
> We can't want for anything that has to take the rtnl_lock.  That would
> be the same as taking the rtnl_lock from a locking perspective.
>
> I expect I would use something like:
> struct rtnl_protected_knob {
> 	struct work_struct work;
>          int userspace_value;
>          int *kernel_var;
>          void (*func)(int new_value, *kernel_var);
> };
>
> userspace_value would be what userspace sees, and kernel_var would be a
> pointer to the value that we manipulate in the kernel.

What if valid values are 0-5 and user sets value to 6 and then immediately
queries the value?  Would your method possibly return 6, when in fact when
the kernel does the work it will internally either reject the setting and
stay with the old value or round the 6 down to 5?

Thanks,
Ben

-- 
Ben Greear <greearb@candelatech.com>
Candela Technologies Inc  http://www.candelatech.com

  reply	other threads:[~2012-01-14 18:31 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-12  2:13 Race condition in ipv6 code Francesco Ruggeri
2012-01-12  6:31 ` Eric Dumazet
2012-01-12  6:44   ` David Miller
2012-01-12 20:48     ` Francesco Ruggeri
2012-01-13  0:11   ` Eric W. Biederman
2012-01-13  6:02     ` Eric Dumazet
2012-01-13  7:40       ` Eric W. Biederman
2012-01-13 17:04         ` Ben Greear
2012-01-14  5:46           ` Eric W. Biederman
2012-01-14 18:31             ` Ben Greear [this message]
2012-01-20  2:54               ` Eric W. Biederman
2012-01-13  1:17 ` Eric W. Biederman
2012-01-13  1:57   ` Stephen Hemminger
2012-01-13 22:02   ` Francesco Ruggeri

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=4F11C9E8.7040300@candelatech.com \
    --to=greearb@candelatech.com \
    --cc=ebiederm@xmission.com \
    --cc=eric.dumazet@gmail.com \
    --cc=fruggeri@aristanetworks.com \
    --cc=netdev@vger.kernel.org \
    --cc=shemminger@vyatta.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).