Received: by 2002:ab2:7855:0:b0:1f9:5764:f03e with SMTP id m21csp612853lqp; Wed, 22 May 2024 14:16:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVGmEC4kxektwWEjaGxQFPTcN0KeukjRLQ7MTKve4z7Gt+Wk7nV9CEJ6sufwN6/qapA7xEcL7JRRHANyu10QH+xlWmRcjSFgEVlD6/SHA== X-Google-Smtp-Source: AGHT+IHLuHqD2tWW2bBiZs2MxLMA+kiGcGwHKvTZ9NfdJRUTlO9aTk/iMHKg1gOV5M0+7W0igIET X-Received: by 2002:a17:902:784e:b0:1eb:3daf:ebaf with SMTP id d9443c01a7336-1f31ca367b3mr27362085ad.57.1716412580035; Wed, 22 May 2024 14:16:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716412580; cv=pass; d=google.com; s=arc-20160816; b=Gumhz9ZulN+mcWgl3ohete2xUX2ARXuVBF2iZW57YBrgMP7V4sdxxxfKsfsBVSNblv cIV7XlJl/2m84SNUM14+fUmeokgWpfn5OiZwUCK27pf3EBQE1ALqHJp02/fkTnQ+50HZ bXJy9brs8ka9y2C0BxULINPpL4ex1gZ1g+FypHg7FZUBfat3VJkZ5fZtgn2XKoZKClki HVXpCqzM7SAr6Ib5LfVOxAP2HHRheeN46oQb6dt4n2CO7k9oZYGqdAlHW7+2Ni7GsHhZ Ruh2QwyagMseJ5VgTOPGrLLijT8V/q78EXdDhWpHu9ejGQWyU0yBpxRQ+OxgcrOP3saH M7Mg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:in-reply-to:date:mime-version :list-unsubscribe:list-subscribe:list-id:precedence; bh=58r0grKkGQMG2BdWLBCqIftRrEEgAxNVyp/0nd1EmWw=; fh=eEp8IScafFAvq92kpt5HZkkbwkzX+/JoChCtn9PjcJ0=; b=yziqW8dWjdqOTfn32K2BL1lif7Z8I/jftaZ/orgRWYI0wyK+DXRBLktCtZzt8n5rEV R1sR0REnydkhmisrUECAb+aFSvyWM3rrrkAci/TvWjQnnyazouK6H7SwkPPNz/xFueo1 WBQ9ZcCaTg0BsXVtqsc8jln8mwsGj0VNUTnFeKukIX8lD9lZs8j5kInNZiKr/CdgXJZ6 PuKItx5EocJNDxdzDovYqYTqoJe1FqH9WhYAA8yUDtq+lovsw59XHhOd95SXm1fvipFa GZ1QHMWMW0M16dRn+BILJXJlphhmdiTrPTOt7HFvkUMGOL/WtalAyk6Lx8147NWPEWCE 54zg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=m3kw2wvrgufz5godrsrytgd7.apphosting.bounces.google.com); spf=pass (google.com: domain of linux-kernel+bounces-186719-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-186719-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=appspotmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-634103f6eafsi144594a12.421.2024.05.22.14.16.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 14:16:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-186719-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=m3kw2wvrgufz5godrsrytgd7.apphosting.bounces.google.com); spf=pass (google.com: domain of linux-kernel+bounces-186719-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-186719-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=appspotmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 1BBA92838A3 for ; Wed, 22 May 2024 21:09:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1DD1F146D4F; Wed, 22 May 2024 21:09:18 +0000 (UTC) Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0DA97146A6F for ; Wed, 22 May 2024 21:09:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.72 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716412157; cv=none; b=RlFvh8mw0g/JyiPLBHnGLmViKupbFM7kDQ3LmEos4a4a45NqXipy5NY94A9qU/haaCqp3mqMfscp282oVRV4dOoI4ZnqtKOxHSvY6AcQ8dLCppUd/+eSBT1vVcIHK3luqOtPwyD5lUwrG58JgECCxzhHotXrqYy5+BpuotKupdw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716412157; c=relaxed/simple; bh=aXxds2gS8M6g8+0jbtaEsKDlYla8S/tUCwUza+959xA=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To:Cc: Content-Type; b=WCwUsY/ZBzCB8V3fNccOn3/Usdx17z8oYtkkrdCpfRouYaYejFZFD8FdlDhbJpVCMf7XqhInZtxHxKxxKm+/mT4XSvD5PPodJB64WxCMMrcdlBOnD5j55xBLRHPYWjPDRy4jdxpREnRb2dnP0qs8oxlbujZALUAKsaHF3xLNsoU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com; arc=none smtp.client-ip=209.85.166.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com Received: by mail-io1-f72.google.com with SMTP id ca18e2360f4ac-7e1d3928fd4so84752439f.3 for ; Wed, 22 May 2024 14:09:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716412154; x=1717016954; h=cc:to:from:subject:message-id:in-reply-to:date:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=58r0grKkGQMG2BdWLBCqIftRrEEgAxNVyp/0nd1EmWw=; b=MxKdJYLTAsioqILue2iqO53P3wqC79aaZEhx8BkzybsvTJ11Hl9cGmF19OiDfpeQpU uKTUYLm6s1742yuKZITPYnM3oqF+36TiFZZKyd23TJOUxYLP1wRIu3ntvsgnj5LW/2gk kw9W3wY0cs18njNZGBvdSQezvekxsSyrQPKWdoHuhoCCLa+9WYuqsRMcSrSUzbK5fCyQ JdnjmjbcX2SECij0GbsTKYQbQR67Rxp7ljgmhVFTdFbRjB+yVzg0LVZiL0loI9nD/Bwo oLwp/in+QTXrhqfXH68kuYwj2WUVwOXfF9xbRC8yqnDTfbcTCVwLInEQFKjB/JuOv4RC 2svA== X-Forwarded-Encrypted: i=1; AJvYcCWZm5aaXYNApbM46xiv0vtDSVIzp3+V9hjl4RVMozcp3Gb+EBzQeKuGTLrBQ1vdfF26qxjPzs2lkb8n5Hkbqbuvu8yvU+Hgo76fVsMc X-Gm-Message-State: AOJu0Yxcmf3B58Pdh63n89jz4Jr2/9Ia+YN0lKf+MqTrDLeki3JDK9NQ 6CN6rwlUlZGos7+rAapvjHI/FRjbKctvQJrRjE0mW9eRIiWRjMuFDiXq3ZlvoLBOPROyTpB4Smg 8+CZieIl61RPl9gSftxIqWayRsfJDQFCZoHCjSU7ZM2ZjveHyoUQgc3g= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Received: by 2002:a05:6e02:20e8:b0:36c:4c5b:ce1 with SMTP id e9e14a558f8ab-371fb92092dmr2126305ab.5.1716412154315; Wed, 22 May 2024 14:09:14 -0700 (PDT) Date: Wed, 22 May 2024 14:09:14 -0700 In-Reply-To: <463668.1716412143@warthog.procyon.org.uk> X-Google-Appengine-App-Id: s~syzkaller X-Google-Appengine-App-Id-Alias: syzkaller Message-ID: <000000000000bf1a9806191158b5@google.com> Subject: Re: [syzbot] [v9fs?] KASAN: slab-use-after-free Write in v9fs_free_request From: syzbot To: dhowells@redhat.com Cc: asmadeus@codewreck.org, brauner@kernel.org, dhowells@redhat.com, ericvh@kernel.org, jlayton@kernel.org, linux-afs@lists.infradead.org, linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org, linux_oss@crudebyte.com, lucho@ionkov.net, netfs@lists.linux.dev, sfrench@samba.org, syzkaller-bugs@googlegroups.com, v9fs@lists.linux.dev Content-Type: text/plain; charset="UTF-8" > #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master This crash does not have a reproducer. I cannot test it. > > netfs, 9p: Fix race between umount and async request completion > > There's a problem in 9p's interaction with netfslib whereby a crash occurs > because the 9p_fid structs get forcibly destroyed during client teardown > (without paying attention to their refcounts) before netfslib has finished > with them. However, it's not a simple case of deferring the clunking that > p9_fid_put() does as that requires the client. > > The problem is that netfslib has to unlock pages and clear the IN_PROGRESS > flag before destroying the objects involved - including the pid - and, in > any case, nothing checks to see if writeback completed barring looking at > the page flags. > > Fix this by keeping a count of outstanding I/O requests (of any type) and > waiting for it to quiesce during inode eviction. > > Signed-off-by: David Howells > cc: Eric Van Hensbergen > cc: Latchesar Ionkov > cc: Dominique Martinet > cc: Christian Schoenebeck > cc: Jeff Layton > cc: Steve French > cc: v9fs@lists.linux.dev > cc: linux-afs@lists.infradead.org > cc: linux-cifs@vger.kernel.org > cc: netfs@lists.linux.dev > cc: linux-fsdevel@vger.kernel.org > --- > fs/9p/vfs_inode.c | 5 ++++- > fs/afs/inode.c | 1 + > fs/netfs/objects.c | 5 +++++ > fs/smb/client/cifsfs.c | 1 + > include/linux/netfs.h | 18 ++++++++++++++++++ > 5 files changed, 29 insertions(+), 1 deletion(-) > > diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c > index 8c9a896d691e..57cfa9f65046 100644 > --- a/fs/9p/vfs_inode.c > +++ b/fs/9p/vfs_inode.c > @@ -354,6 +354,7 @@ void v9fs_evict_inode(struct inode *inode) > version = cpu_to_le32(v9inode->qid.version); > netfs_clear_inode_writeback(inode, &version); > > + netfs_wait_for_outstanding_io(inode); > clear_inode(inode); > filemap_fdatawrite(&inode->i_data); > > @@ -361,8 +362,10 @@ void v9fs_evict_inode(struct inode *inode) > if (v9fs_inode_cookie(v9inode)) > fscache_relinquish_cookie(v9fs_inode_cookie(v9inode), false); > #endif > - } else > + } else { > + netfs_wait_for_outstanding_io(inode); > clear_inode(inode); > + } > } > > struct inode * > diff --git a/fs/afs/inode.c b/fs/afs/inode.c > index 94fc049aff58..c831e711a4ac 100644 > --- a/fs/afs/inode.c > +++ b/fs/afs/inode.c > @@ -652,6 +652,7 @@ void afs_evict_inode(struct inode *inode) > > afs_set_cache_aux(vnode, &aux); > netfs_clear_inode_writeback(inode, &aux); > + netfs_wait_for_outstanding_io(inode); > clear_inode(inode); > > while (!list_empty(&vnode->wb_keys)) { > diff --git a/fs/netfs/objects.c b/fs/netfs/objects.c > index c90d482b1650..f4a642727479 100644 > --- a/fs/netfs/objects.c > +++ b/fs/netfs/objects.c > @@ -72,6 +72,7 @@ struct netfs_io_request *netfs_alloc_request(struct address_space *mapping, > } > } > > + atomic_inc(&ctx->io_count); > trace_netfs_rreq_ref(rreq->debug_id, 1, netfs_rreq_trace_new); > netfs_proc_add_rreq(rreq); > netfs_stat(&netfs_n_rh_rreq); > @@ -124,6 +125,7 @@ static void netfs_free_request(struct work_struct *work) > { > struct netfs_io_request *rreq = > container_of(work, struct netfs_io_request, work); > + struct netfs_inode *ictx = netfs_inode(rreq->inode); > unsigned int i; > > trace_netfs_rreq(rreq, netfs_rreq_trace_free); > @@ -142,6 +144,9 @@ static void netfs_free_request(struct work_struct *work) > } > kvfree(rreq->direct_bv); > } > + > + if (atomic_dec_and_test(&ictx->io_count)) > + wake_up_var(&ictx->io_count); > call_rcu(&rreq->rcu, netfs_free_request_rcu); > } > > diff --git a/fs/smb/client/cifsfs.c b/fs/smb/client/cifsfs.c > index ec5b639f421a..21c9e173ea9a 100644 > --- a/fs/smb/client/cifsfs.c > +++ b/fs/smb/client/cifsfs.c > @@ -435,6 +435,7 @@ cifs_evict_inode(struct inode *inode) > if (inode->i_state & I_PINNING_NETFS_WB) > cifs_fscache_unuse_inode_cookie(inode, true); > cifs_fscache_release_inode_cookie(inode); > + netfs_wait_for_outstanding_io(inode); > clear_inode(inode); > } > > diff --git a/include/linux/netfs.h b/include/linux/netfs.h > index d2d291a9cdad..3ca3906bb8da 100644 > --- a/include/linux/netfs.h > +++ b/include/linux/netfs.h > @@ -68,6 +68,7 @@ struct netfs_inode { > loff_t remote_i_size; /* Size of the remote file */ > loff_t zero_point; /* Size after which we assume there's no data > * on the server */ > + atomic_t io_count; /* Number of outstanding reqs */ > unsigned long flags; > #define NETFS_ICTX_ODIRECT 0 /* The file has DIO in progress */ > #define NETFS_ICTX_UNBUFFERED 1 /* I/O should not use the pagecache */ > @@ -474,6 +475,7 @@ static inline void netfs_inode_init(struct netfs_inode *ctx, > ctx->remote_i_size = i_size_read(&ctx->inode); > ctx->zero_point = LLONG_MAX; > ctx->flags = 0; > + atomic_set(&ctx->io_count, 0); > #if IS_ENABLED(CONFIG_FSCACHE) > ctx->cache = NULL; > #endif > @@ -517,4 +519,20 @@ static inline struct fscache_cookie *netfs_i_cookie(struct netfs_inode *ctx) > #endif > } > > +/** > + * netfs_wait_for_outstanding_io - Wait for outstanding I/O to complete > + * @ctx: The netfs inode to wait on > + * > + * Wait for outstanding I/O requests of any type to complete. This is intended > + * to be called from inode eviction routines. This makes sure that any > + * resources held by those requests are cleaned up before we let the inode get > + * cleaned up. > + */ > +static inline void netfs_wait_for_outstanding_io(struct inode *inode) > +{ > + struct netfs_inode *ictx = netfs_inode(inode); > + > + wait_var_event(&ictx->io_count, atomic_read(&ictx->io_count) == 0); > +} > + > #endif /* _LINUX_NETFS_H */ >