public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Michael Holzheu <holzheu@linux.vnet.ibm.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Martin Schwidefsky <schwidefsky@de.ibm.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: [PATCH] bpf: Call rcu_read_unlock() before copy_to_user()
Date: Thu, 22 Jan 2015 18:54:12 +0100	[thread overview]
Message-ID: <20150122185412.66a0a920@holzheu> (raw)
In-Reply-To: <CAADnVQLnrAgk3vTppugqCtSsHL4XiZeQJrQi3cqhgLCCq1v8Pg@mail.gmail.com>

On Thu, 22 Jan 2015 09:27:21 -0800
Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote:

> On Thu, Jan 22, 2015 at 7:57 AM, Michael Holzheu
> <holzheu@linux.vnet.ibm.com> wrote:
> > We must not hold locks when calling copy_to_user():
> >
> > BUG: sleeping function called from invalid context at mm/memory.c:3732
> > in_atomic(): 0, irqs_disabled(): 0, pid: 671, name: test_maps
> > 1 lock held by test_maps/671:
> >  #0:  (rcu_read_lock){......}, at: [<0000000000264190>] map_lookup_elem+0xe8/0x260
> > Preemption disabled at:[<00000000001be3b6>] vprintk_default+0x56/0x68
> >
> > CPU: 0 PID: 671 Comm: test_maps Not tainted 3.19.0-rc5-00117-g5eb11d6-dirty #424
> >        000000001e447bb0 000000001e447c40 0000000000000002 0000000000000000
> >        000000001e447ce0 000000001e447c58 000000001e447c58 0000000000115c8a
> >        0000000000000000 0000000000c08246 0000000000c27e8a 000000000000000b
> >        000000001e447ca0 000000001e447c40 0000000000000000 0000000000000000
> >        0000000000000000 0000000000115c8a 000000001e447c40 000000001e447ca0
> > Call Trace:
> > ([<0000000000115b7e>] show_trace+0x12e/0x150)
> >  [<0000000000115c40>] show_stack+0xa0/0x100
> >  [<00000000009b163c>] dump_stack+0x74/0xc8
> >  [<000000000017424a>] ___might_sleep+0x23a/0x248
> >  [<00000000002b58e8>] might_fault+0x70/0xe8
> >  [<0000000000264230>] map_lookup_elem+0x188/0x260
> >  [<0000000000264716>] SyS_bpf+0x20e/0x840
> >  [<00000000009bbe3a>] system_call+0xd6/0x24c
> >  [<000003fffd15f566>] 0x3fffd15f566
> > 1 lock held by test_maps/671:
> >  #0:  (rcu_read_lock){......}, at: [<0000000000264190>] map_lookup_elem+0xe8/0x260
> >
> > So call rcu_read_unlock() before copy_to_user(). We can
> > release the lock earlier because it is not needed for copy_to_user().
> 
> we cannot move the rcu unlock this way, since it protects the value.
> So we need to copy the value while still under rcu.

Ok, right. I assume you will provide the correct fix.

> I'm puzzled how I missed this warning.
> I guess you have CONFIG_PREEMPT_RCU=y ?

Yes.

Regards,
Michael

  reply	other threads:[~2015-01-22 17:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-22 17:27 [PATCH] bpf: Call rcu_read_unlock() before copy_to_user() Alexei Starovoitov
2015-01-22 17:54 ` Michael Holzheu [this message]
  -- strict thread matches above, loose matches on Subject: below --
2015-01-22 18:03 Alexei Starovoitov

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=20150122185412.66a0a920@holzheu \
    --to=holzheu@linux.vnet.ibm.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=ast@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=schwidefsky@de.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