Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1235639pxj; Fri, 4 Jun 2021 09:14:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqxfBXhqL9mAVfjRn/SdH8twK5LQhcMo+qyFpeHzn1r0CSumgO0lFdOEfmnv031Mk8GX86 X-Received: by 2002:a50:ee8b:: with SMTP id f11mr5402626edr.329.1622823243767; Fri, 04 Jun 2021 09:14:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622823243; cv=none; d=google.com; s=arc-20160816; b=Zaxp0FFe7Gzj0KOnpAviRrTGHnkx7z2B26f2+1JKA6fJHCGZcvAQunYDejiA+9f92u Nf3y9wpEr2PAsldM2Egh74gB+0lGtfSumfTE75G0txxxK9rJESliE3QawhtIleC8MI/J SiU9hx+6t9OET2Dq726TxpuORKZpfGhwMj/2Z5wxjq0NVXTHU/dVj6IHF2kDniV5h96P 4EqUkcK1rHl4gQI9sZPEMWIoJGzC+YQcnN/pR5eDGjwLbGdmVLYuJbpxd36H9l8d/lZ2 RYRt4l5WqZsCfUrjPGA+j/znLLD3UcryrEbKehrgdEV5i/H4JA9WmEWwwH2HBBntA4MS oaKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=rPBBgNKY8qEl1FTP8Z/Nlro4bvKvHveyCZkjG0ImQ5U=; b=rjX8sbw4oC2n3xEtG3s2eSiygJKFYHgBXGqJJaEvo2EYQS/Uz+IlShhX7oV6uKGnBI pyWBTn4QAM4ZLKj+6T5M3ikpZZuuYn+X0Xa6vLFYf2Wjxo3RnMWelsJY37rGFhMxko4j W8Zu+05voQJoXpNsWk/Gzbtk/2LryxvWWjbGl8Hh+BG6l2pHR6kWAbpKEd81azeeSRjQ Db1XeKwASZ5HyX5OvjQoDmD9ouxj7osMWh5Hjl7yw5ckAfq/Nr71hAZOl34Zu6igd7X3 B4cIDxNFWCK6nBquWr8elr7S1nXCGFOxra4sj/YVdgwE/Ge1IhQ60Mytg+Cjcd3jZ9HH mHFQ== 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 jg40si4987946ejc.465.2021.06.04.09.13.39; Fri, 04 Jun 2021 09:14:03 -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 S231253AbhFDQOD convert rfc822-to-8bit (ORCPT + 99 others); Fri, 4 Jun 2021 12:14:03 -0400 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:35044 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230453AbhFDQOC (ORCPT ); Fri, 4 Jun 2021 12:14:02 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-177-_9AFksQQM9iDjBrWox_Xcg-1; Fri, 04 Jun 2021 12:12:14 -0400 X-MC-Unique: _9AFksQQM9iDjBrWox_Xcg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 80AF9801817; Fri, 4 Jun 2021 16:12:13 +0000 (UTC) Received: from bahia.lan (ovpn-112-232.ams2.redhat.com [10.36.112.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 15F3060CEC; Fri, 4 Jun 2021 16:12:11 +0000 (UTC) From: Greg Kurz To: Miklos Szeredi Cc: linux-kernel@vger.kernel.org, Max Reitz , linux-fsdevel@vger.kernel.org, virtio-fs@redhat.com, Vivek Goyal , Greg Kurz Subject: [PATCH v2 2/7] fuse: Fix crash if superblock of submount gets killed early Date: Fri, 4 Jun 2021 18:11:51 +0200 Message-Id: <20210604161156.408496-3-groug@kaod.org> In-Reply-To: <20210604161156.408496-1-groug@kaod.org> References: <20210604161156.408496-1-groug@kaod.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org Content-Transfer-Encoding: 8BIT Content-Type: text/plain; charset=WINDOWS-1252 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As soon as fuse_dentry_automount() does up_write(&sb->s_umount), the superblock can theoretically be killed. If this happens before the submount was added to the &fc->mounts list, fuse_mount_remove() later crashes in list_del_init() because it assumes the submount to be already there. Add the submount before dropping sb->s_umount to fix the inconsistency. It is okay to nest fc->killsb under sb->s_umount, we already do this on the ->kill_sb() path. Signed-off-by: Greg Kurz --- fs/fuse/dir.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index 01559061cbfb..3fd1b71e546b 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -346,15 +346,15 @@ static struct vfsmount *fuse_dentry_automount(struct path *path) goto out_put_sb; } + down_write(&fc->killsb); + list_add_tail(&fm->fc_entry, &fc->mounts); + up_write(&fc->killsb); + sb->s_flags |= SB_ACTIVE; fsc->root = dget(sb->s_root); /* We are done configuring the superblock, so unlock it */ up_write(&sb->s_umount); - down_write(&fc->killsb); - list_add_tail(&fm->fc_entry, &fc->mounts); - up_write(&fc->killsb); - /* Create the submount */ mnt = vfs_create_mount(fsc); if (IS_ERR(mnt)) { -- 2.31.1