netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Cong Wang <xiyou.wangcong@gmail.com>
To: Sowmini Varadhan <sowmini.varadhan@oracle.com>
Cc: Santosh Shilimkar <santosh.shilimkar@oracle.com>,
	Linux Kernel Network Developers <netdev@vger.kernel.org>,
	rds-devel@oss.oracle.com
Subject: Re: [Patch net] rds: mark bound socket with SOCK_RCU_FREE
Date: Mon, 10 Sep 2018 16:51:11 -0700	[thread overview]
Message-ID: <CAM_iQpUAGvFOw4_1PxM2wmQ_ZQMsgYSdDkWwfPD25-iX7i134w@mail.gmail.com> (raw)
In-Reply-To: <20180910233007.GJ4668@oracle.com>

On Mon, Sep 10, 2018 at 4:30 PM Sowmini Varadhan
<sowmini.varadhan@oracle.com> wrote:
>
> On (09/10/18 15:43), Santosh Shilimkar wrote:
> > On 9/10/2018 3:24 PM, Cong Wang wrote:
> > >When a rds sock is bound, it is inserted into the bind_hash_table
> > >which is protected by RCU. But when releasing rd sock, after it
> > >is removed from this hash table, it is freed immediately without
> > >respecting RCU grace period. This could cause some use-after-free
> > >as reported by syzbot.
> > >
> > Indeed.
> >
> > >Mark the rds sock as SOCK_RCU_FREE before inserting it into the
> > >bind_hash_table, so that it would be always freed after a RCU grace
> > >period.
>
> So I'm not sure I understand.
>
> Yes, Cong's fix may eliminate *some* of the syzbot failures, but the
> basic problem is not solved.
>
> To take one example of possible races (one that was discussed in
>   https://www.spinics.net/lists/netdev/msg475074.html)
> rds_recv_incoming->rds_find_bound is being called in rds_send_worker
> context and the rds_find_bound code is
>
>      63         rs = rhashtable_lookup_fast(&bind_hash_table, &key, ht_parms);
>      64         if (rs && !sock_flag(rds_rs_to_sk(rs), SOCK_DEAD))
>      65                 rds_sock_addref(rs);
>      66         else
>      67                 rs = NULL;
>      68
>
> After we find an rs at line 63, how can we be sure that the entire
> logic of rds_release does not execute on another cpu, and free the rs,
> before we hit line 64 with the bad rs?

This is a different problem. The RCU grace period should be just
extended:

diff --git a/net/rds/bind.c b/net/rds/bind.c
index 3ab55784b637..fa7592d0760c 100644
--- a/net/rds/bind.c
+++ b/net/rds/bind.c
@@ -76,11 +76,13 @@ struct rds_sock *rds_find_bound(const struct
in6_addr *addr, __be16 port,
        struct rds_sock *rs;

        __rds_create_bind_key(key, addr, port, scope_id);
-       rs = rhashtable_lookup_fast(&bind_hash_table, key, ht_parms);
+       rcu_read_lock();
+       rs = rhashtable_lookup(&bind_hash_table, key, ht_parms);
        if (rs && !sock_flag(rds_rs_to_sk(rs), SOCK_DEAD))
                rds_sock_addref(rs);
        else
                rs = NULL;
+       rcu_read_unlock();

        rdsdebug("returning rs %p for %pI6c:%u\n", rs, addr,
                 ntohs(port));

>
> Normally synchronize_rcu() or synchronize_net() in rds_release() would
> ensure this. How do we ensure this with SOCK_RCU_FREE (or is the
> intention to just reduce *some* of the syzbot failures)?

Although sock release path is not a very hot path, but blocking
it isn't a good idea either, especially when you can use call_rcu(),
which has the same effect.

I don't see any reason we should prefer synchronize_rcu() here.

  reply	other threads:[~2018-09-11  4:47 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-10 22:24 [Patch net] rds: mark bound socket with SOCK_RCU_FREE Cong Wang
2018-09-10 22:34 ` Sowmini Varadhan
2018-09-10 22:43 ` Santosh Shilimkar
2018-09-10 23:30   ` Sowmini Varadhan
2018-09-10 23:51     ` Cong Wang [this message]
2018-09-11  0:04       ` Sowmini Varadhan
2018-09-11  0:16         ` Cong Wang
2018-09-11  0:24           ` Sowmini Varadhan
2018-09-11  0:39             ` Cong Wang
2018-09-11  0:26           ` Santosh Shilimkar
2018-09-11  0:45             ` Cong Wang
2018-09-11  0:56               ` Santosh Shilimkar
2018-09-11  0:59                 ` Cong Wang

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=CAM_iQpUAGvFOw4_1PxM2wmQ_ZQMsgYSdDkWwfPD25-iX7i134w@mail.gmail.com \
    --to=xiyou.wangcong@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=rds-devel@oss.oracle.com \
    --cc=santosh.shilimkar@oracle.com \
    --cc=sowmini.varadhan@oracle.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).