From nobody Thu Sep 02 04:16:21 2021 X-Original-To: freebsd-fs@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id E40B117AADC5 for ; Thu, 2 Sep 2021 04:16:36 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4H0SKw4Kwpz3mPG for ; Thu, 2 Sep 2021 04:16:36 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.16.1/8.16.1) with ESMTPS id 1824GLi1056881 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Thu, 2 Sep 2021 07:16:24 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 1824GLi1056881 Received: (from kostik@localhost) by tom.home (8.16.1/8.16.1/Submit) id 1824GLbL056880; Thu, 2 Sep 2021 07:16:21 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 2 Sep 2021 07:16:21 +0300 From: Konstantin Belousov To: Alexander Lochmann Cc: freebsd-fs , Horst Schirmeier Subject: Re: Various unprotected accesses to buf and vnode Message-ID: References: <55f3661e-2173-793e-4834-bbcd79d3d99e@tu-dortmund.de> <380bdcc8-bede-2a64-8e5e-031552231d82@tu-dortmund.de> <46649402-d28a-6f81-f0a8-39180b681f4c@tu-dortmund.de> List-Id: Filesystems List-Archive: https://lists.freebsd.org/archives/freebsd-fs List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-fs@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.5 X-Spam-Checker-Version: SpamAssassin 3.4.5 (2021-03-20) on tom.home X-Rspamd-Queue-Id: 4H0SKw4Kwpz3mPG X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] X-ThisMailContainsUnwantedMimeParts: N On Wed, Sep 01, 2021 at 03:10:53PM +0200, Alexander Lochmann wrote: > On 31.08.21 16:44, Konstantin Belousov wrote: > >> So in all of those call sequences the buffer lock is not acquired. > >> However, I'd not rule out that our tooling could be broken as well. > > Buffer is locked inside UFS_BALLOC(), which returns it to the ffs_write() > > use. > I took a deep dive into our data, and had a closer look at two samples. > In both cases the b_lock is not acquired. > > Since the debug information seems to be damaged, I had to use 'objdump > -S' to translate the pc of the unguarded memory access to a source code > position. > It seems to be vp->v_lasta = bp->b_blkno; in > https://thasos.cs.tu-dortmund.de/freebsd-lockdoc/lockdoc-v13.0-0.6/source/sys/kern/vfs_cluster.c#L802. > > It was release in binsfree() and bq_insert(): > https://thasos.cs.tu-dortmund.de/freebsd-lockdoc/latest/source/sys/kern/vfs_bio.c#L1537 > https://thasos.cs.tu-dortmund.de/freebsd-lockdoc/latest/source/sys/kern/vfs_bio.c#L1977 Ah, it is bp->b_blkno access after the b*write() functions were called to write out and release the buffer, right. I put the patch to fix this into https://reviews.freebsd.org/D31780 Please remind me what attributions to use for 'Reported by:' tagline. > > Read e.g. sys/ufs/ufs/inode.h gerald comment above struct inode definition. > > It provides more detailed exposure. > Aaah. Thx. This is about the struct inode. So I assume it also applies > for a vnode belonging to an inode. Am I right?> Vnode lock is a lock > obtained with vn_lock(). It is up to filesystem When needed, yes, it is a reasonable locking strategy. But I am not sure that we actually use for any of the struct vnode fields proper, Something closer to it is for v_writecount, but formally it is under the vnode interlock. Although I do not think we ever modify it without holding vnode lock, in some mode. > > to implement VOP_LOCK() which locks the vnode. > > > > Default VOP_LOCK() locks vp->v_vnlock, which again by default points > > to &vp->v_lock. > > > > There are several special cases. For instance, for FFS and snapshot vnodes, > > v_vnlock points to the snapdata->sn_lock (snapdata is unique per FFS mount). > > For nullfs non-reclaimed vnodes, v_vnlock points to the lower vnode lock. > > > Thx! Is this written down somewhere? No, but it is rather clear from the code.