From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Manfred Spraul <manfred@colorfullife.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
netfilter-devel@vger.kernel.org,
Davidlohr Bueso <dave@stgolabs.net>,
"Paul E . McKenney" <paulmck@kernel.org>,
1vier1@web.de
Subject: Re: [PATCH 1/2] net/netfilter/nf_conntrack_core: Mark access for KCSAN
Date: Wed, 7 Jul 2021 01:06:41 +0200 [thread overview]
Message-ID: <20210706230641.GA13147@salvia> (raw)
In-Reply-To: <20210627161919.3196-2-manfred@colorfullife.com>
On Sun, Jun 27, 2021 at 06:19:18PM +0200, Manfred Spraul wrote:
> KCSAN detected an data race with ipc/sem.c that is intentional.
>
> As nf_conntrack_lock() uses the same algorithm: Update
> nf_conntrack_core as well:
>
> nf_conntrack_lock() contains
> a1) spin_lock()
> a2) smp_load_acquire(nf_conntrack_locks_all).
>
> a1) actually accesses one lock from an array of locks.
>
> nf_conntrack_locks_all() contains
> b1) nf_conntrack_locks_all=true (normal write)
> b2) spin_lock()
> b3) spin_unlock()
>
> b2 and b3 are done for every lock.
>
> This guarantees that nf_conntrack_locks_all() prevents any
> concurrent nf_conntrack_lock() owners:
> If a thread past a1), then b2) will block until that thread releases
> the lock.
> If the threat is before a1, then b3)+a1) ensure the write b1) is
> visible, thus a2) is guaranteed to see the updated value.
>
> But: This is only the latest time when b1) becomes visible.
> It may also happen that b1) is visible an undefined amount of time
> before the b3). And thus KCSAN will notice a data race.
>
> In addition, the compiler might be too clever.
>
> Solution: Use WRITE_ONCE().
Applied, thanks.
next prev parent reply other threads:[~2021-07-06 23:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-27 16:19 [PATCH 0/2] Fixes for KCSAN findings Manfred Spraul
2021-06-27 16:19 ` [PATCH 1/2] net/netfilter/nf_conntrack_core: Mark access for KCSAN Manfred Spraul
2021-07-06 23:06 ` Pablo Neira Ayuso [this message]
2021-06-27 16:19 ` [PATCH 2/2] ipc/sem.c: use READ_ONCE()/WRITE_ONCE() for use_global_lock Manfred Spraul
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=20210706230641.GA13147@salvia \
--to=pablo@netfilter.org \
--cc=1vier1@web.de \
--cc=akpm@linux-foundation.org \
--cc=dave@stgolabs.net \
--cc=linux-kernel@vger.kernel.org \
--cc=manfred@colorfullife.com \
--cc=netfilter-devel@vger.kernel.org \
--cc=paulmck@kernel.org \
/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).