Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp5047104pxv; Tue, 6 Jul 2021 16:11:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmwbcYzTYLrli09GbrSB6YWhad+WjrVt/OR4HrQAagiTSpWhTkXVCEDMqMJiBIUyJEx4dx X-Received: by 2002:a17:906:478b:: with SMTP id cw11mr20426734ejc.241.1625613084768; Tue, 06 Jul 2021 16:11:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625613084; cv=none; d=google.com; s=arc-20160816; b=j1gD+H89YhKNSVhh7poUgOLbDmGEV7aSzEE4H5BMykuSmhfMAWoGb+i4CrCBFB8u4s 5C8BmnovxSHzFcQkjxc1YQVjD1sEu4L7b13YctI5NCTL03Z5iuCe0msAB+SMWx4WZT7F JwHsjAmCf3lEa1BE8PyiA3kZnCo7WDekhVQkzjNFDPZT0Fa1ave8djwTxOC42mzyA0Zf +Atoqye9tA4M7UX2rfTZdWd1Yx+GJ2KFSbRspvQuTpZgfzqqRNYrka27x7RjNIwQdhA4 MFQa638S913NQp501CB4O82D5AXp0lJ2xhzlPt7fID+ONbtmT6gnoi7cB32WTeb2xc0f c54w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=7bwGu0uWlET0KmZm+wUDedK1z4n4vTZQSdHTk67Nzps=; b=n0ehCYUQfG2fz/6segKGIbBLsIqd8BjBvwk9OOLEXLwlkxFI7h/cJJSBRrZR2YeBLX i5ZFQErEm1tY0NIpPDr8bcFxJuc/Fa654ln/vdIoLsUJwk6Lo8AQKmBx22/7Lh6EBDQ4 fPsMwO3I/K3/byFg4OJ6IYjBklEe2psJC0+fFpvY+Q7RLis1QA0XYJT925nfcboCT2Tx Jevvrc0qXbFC/bu/6r9B6/saSjoJCEuwdQ0h4fjoPAqv+U/OCDKu/SpUp4mcXbNUIVLo EuucQFTRO0XjCcZvd4PZuQtEzmM6RAIt6Efm0YsMky+/61OJaiWjuSxhqsy+8vtxXKpf 68oA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jg12si7995307ejc.724.2021.07.06.16.10.50; Tue, 06 Jul 2021 16:11:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229956AbhGFXJY (ORCPT + 99 others); Tue, 6 Jul 2021 19:09:24 -0400 Received: from mail.netfilter.org ([217.70.188.207]:52846 "EHLO mail.netfilter.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229811AbhGFXJY (ORCPT ); Tue, 6 Jul 2021 19:09:24 -0400 Received: from netfilter.org (unknown [90.77.255.23]) by mail.netfilter.org (Postfix) with ESMTPSA id 423736164E; Wed, 7 Jul 2021 01:06:33 +0200 (CEST) Date: Wed, 7 Jul 2021 01:06:41 +0200 From: Pablo Neira Ayuso To: Manfred Spraul Cc: LKML , Andrew Morton , netfilter-devel@vger.kernel.org, Davidlohr Bueso , "Paul E . McKenney" , 1vier1@web.de Subject: Re: [PATCH 1/2] net/netfilter/nf_conntrack_core: Mark access for KCSAN Message-ID: <20210706230641.GA13147@salvia> References: <20210627161919.3196-1-manfred@colorfullife.com> <20210627161919.3196-2-manfred@colorfullife.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210627161919.3196-2-manfred@colorfullife.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.