Linux-SCTP Archive mirror
 help / color / mirror / Atom feed
From: Xin Long <lucien.xin@gmail.com>
To: Sishuai Gong <sishuai.system@gmail.com>
Cc: marcelo.leitner@gmail.com, linux-sctp@vger.kernel.org
Subject: Re: Racy addr->valid in sctp_inet6addr_event() and sctp_copy_laddrs()
Date: Wed, 9 Aug 2023 12:26:50 -0400	[thread overview]
Message-ID: <CADvbK_edcx5A3ij_LbehqwoyNEft-NB+4bgbYbsOh_yJ-hqgRQ@mail.gmail.com> (raw)
In-Reply-To: <72339335-4072-429C-9494-ACCDC5572F54@gmail.com>

On Tue, Aug 8, 2023 at 3:07 PM Sishuai Gong <sishuai.system@gmail.com> wrote:
>
> Hello,
>
> We observed a data race over addr->valid between sctp_inet6addr_event() and
> sctp_copy_laddrs(). Under the following execution order, sctp_copy_laddrs()
> might copy the addr that is no longer valid.
>
> sctp_copy_laddrs()              sctp_inet6addr_event()
> if (!addr->valid)
>         continue;
>                                                 addr->valid = 0;
> memcpy(&temp, &addr->a, sizeof(temp));
>
Yes, there's no lock protecting valid's read and write. But it doesn't
seem to matter.

Even if we put a lock there, after calling sctp_copy_laddrs() or
sctp_copy_local_addr_list() this addr can still be deleted in
NETDEV_DOWN event, which could happen anytime.

Checking addr->valid can only ensure the addr is available at that moment,
which doesn't look really helpful IMHO, considering an address can be
deleted, or the same address as the one already deleted can be added
anytime.

addr->valid and addr>rcu were introduced to fix an use-after-free. But it
seems to me that addr->rcu is enough for this purpose, we can actually
deleted addr->valid.

      reply	other threads:[~2023-08-09 16:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-08 19:07 Racy addr->valid in sctp_inet6addr_event() and sctp_copy_laddrs() Sishuai Gong
2023-08-09 16:26 ` Xin Long [this message]

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=CADvbK_edcx5A3ij_LbehqwoyNEft-NB+4bgbYbsOh_yJ-hqgRQ@mail.gmail.com \
    --to=lucien.xin@gmail.com \
    --cc=linux-sctp@vger.kernel.org \
    --cc=marcelo.leitner@gmail.com \
    --cc=sishuai.system@gmail.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 read-only IMAP folder(s) and NNTP newsgroup(s).