Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp7108490ybi; Thu, 13 Jun 2019 09:41:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqyUBGUJNdzE8j7VKhftUBCMSpMCmjOt9oxpOy14YvWEggJjxsLx8ysNP2fwyC/KfjjrE22u X-Received: by 2002:a63:6fce:: with SMTP id k197mr31747729pgc.140.1560444090270; Thu, 13 Jun 2019 09:41:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560444090; cv=none; d=google.com; s=arc-20160816; b=yOwQpIz1dCzGfG7KW8OLfyVLuEw250//sIGtMS2/D2n974SCnxuErtLGjTTa+MRSYW ThMuG7ekwfLr9nK3HnMf6BAHPdWHVlHWVvas+xBeerzDoidZQwuJmqsMTeLVbCHRgcsJ bQHou3RURemNBiAnMxoZVTqE7LRNCHI7RCzbgOMeHbTZSBeqALJ+0bPTfUsExLfLYBIf racjbnYUQpSQKBvaf/OHwiU+MdaSWoAfCOnoi/w+q6Ipe3BcvSfpEfKoK/ym1ffK0DE5 1+0e8lIZc3Ruxqw6wtGm2X2GexnKVtDTSPq8mF3clfGDOnYQv5hXMLm5hiOJv+epY09e 6Cyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=LwLehbDYOvahxjXvZeMcDnh+/NAn2sqjke/GXujxB2Y=; b=ez7W0qJQrs5Dpiz9ieJGgC5JJ2NlPJb8YKBs4wyEWbs9pl0689cxOY9XDJZuXb+J9K cM55RxP8q5/njZS90dpH8XL79qiRyR7ZeIXjXXDraAZ1StI65rMX8yQodzaBPKenFqXA GDkVNbIciAYSTPL5xnpLl+8xEqiiD9JEE9YnPKOJAEHQxgwzE9l7JwFaMxH+Zo6CxEFr tWT/hMgCrp0z9vjQa5tmnK6h82i3f+KdAdeWxCH4m+jvL4NTbr2JCnYACULb/sQO8zmf gO8LpTunZPP7r49QkyBLM35/AtcqrWGcVRMMfbymtjyWXQ9XtaBDkHmgh6gXVNYgOrd9 lxlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=I7fdzUpQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w125si86705pfb.10.2019.06.13.09.41.15; Thu, 13 Jun 2019 09:41:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=I7fdzUpQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392828AbfFMQlL (ORCPT + 99 others); Thu, 13 Jun 2019 12:41:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:59174 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726959AbfFMQlJ (ORCPT ); Thu, 13 Jun 2019 12:41:09 -0400 Received: from sol.localdomain (c-24-5-143-220.hsd1.ca.comcast.net [24.5.143.220]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E48E220644; Thu, 13 Jun 2019 16:41:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560444069; bh=C34ebvo6AEFxf3EflJEFb177I+rCto2FjRJcZW9t0Io=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=I7fdzUpQNPCk2YfMQVrLWDVqmuu43ACjuslQSremYqJQYV4iZABsStKEgi+mQA5A1 ykJh+be+IyEGMtFTcsz0+PwyXSpLqAN/s89hUbH5dSgiwrN87aS2d0L/nI5CRC7g8u 8Tdr9FHQ7nY1S7pVnpQiX6aJ+xqIBFhfDsxFi8zk= Date: Thu, 13 Jun 2019 09:41:07 -0700 From: Eric Biggers To: Miklos Szeredi Cc: David Howells , Alexander Viro , linux-fsdevel@vger.kernel.org, Mark Rutland , linux-kernel@vger.kernel.org Subject: Re: [PATCH] vfs: fsmount: add missing mntget() Message-ID: <20190613164107.GA686@sol.localdomain> References: <20190610183031.GE63833@gmail.com> <20190612184313.143456-1-ebiggers@kernel.org> <20190613084728.GA32129@miu.piliscsaba.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190613084728.GA32129@miu.piliscsaba.redhat.com> User-Agent: Mutt/1.12.0 (2019-05-25) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 13, 2019 at 10:47:28AM +0200, Miklos Szeredi wrote: > On Wed, Jun 12, 2019 at 11:43:13AM -0700, Eric Biggers wrote: > > From: Eric Biggers > > > > sys_fsmount() needs to take a reference to the new mount when adding it > > to the anonymous mount namespace. Otherwise the filesystem can be > > unmounted while it's still in use, as found by syzkaller. > > So it needs one count for the file (which dentry_open() obtains) and one for the > attachment into the anonymous namespace. The latter one is dropped at cleanup > time, so your patch appears to be correct at getting that ref. Yes. > > I wonder why such a blatant use-after-free was missed in normal testing. RCU > delayed freeing, I guess? It's because mount freeing is delayed by task_work_add(), so normally the refcnt would be dropped to -1 when the file is closed without problems. The problems only showed up if you took another reference, e.g. by fchdir(). > > How about this additional sanity checking patch? Seems like a good idea. Without my fix, the WARNING is triggered by the following program (no fchdir() needed): int main(void) { int fs; fs = syscall(__NR_fsopen, "ramfs", 0); syscall(__NR_fsconfig, fs, 6, 0, 0, 0); syscall(__NR_fsmount, fs, 0, 0); } Can you send it as a formal patch? - Eric