From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 766FC25601 for ; Mon, 15 Apr 2024 22:15:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713219310; cv=none; b=YVrQ5ZTzYdufwePsdudLNOhKQ4mipnGXDs0WADBXn8GtKwdvPl059dTB26RB8bfRlVFfHE6pUXQPNGay/LaqT+tIqFmWPijOTZ6niVHeayimY7zIMwSATA+YxbPxSLC+fXwPAxE/irmww1r1aaEt1e+JwNYXTzdynSbDnh/N1ps= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713219310; c=relaxed/simple; bh=PY44UZjjjuhrlz20AyxwSiMqoFKLANo/z/GnBHE0Uj4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OGIwT4fSrCXr2Q4gOx3UK9/OGNk1ypfxH+ViaIzxnrkbsYjp7yILRkyGnrhb7Cr5dv47hVU6XP2tAqA9vpx1ekgbp4EU2mq4V1FE+DGTKeg5/5Ib5Ap6M/jWbKMdBpbuVaJMkzhnpQi1+s1CN/SIq5XiAWLEIm9EariKkw6kURs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=XQgDpiY/; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="XQgDpiY/" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=anUTzNn+XCSh5szgQ2VdZfjbgbKcul8tT9KISExHK4I=; b=XQgDpiY/ZLRUxbAWj8QHZRpuce 4fLm0z3rwhAL7vNnOmZs49/ktsbPbNe/bfVJ+gLne6S0NkdmxIwWHOLW1fnQ6qVdQqsricx07yIbl 24ODbemxB4zUtxJQPL2MJ6GbdF1hxMR+NO1F2enzLcA0YLx1ZLepzUVK9BhHq17WoJ6bmt1vKgQvT U+qjyCIv9JwQUFvXfWbGDinewWPPPZzfrs5phOhykyIwxY2tTJGsDKJdDf86xbl7WP+Si2OfOOI6K GDTk08AtsfpucR24DmB2SdfWRdCtdc96FmIfUYPzHTEAR/EV6qhZShIgxi3hsVF6o2YmF0rfh1YnE tB/VKGeQ==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rwUbP-0000000GbxN-28TT; Mon, 15 Apr 2024 22:15:03 +0000 Date: Mon, 15 Apr 2024 23:15:03 +0100 From: Matthew Wilcox To: Vishal Moola Cc: syzbot , akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, muchun.song@linux.dev, syzkaller-bugs@googlegroups.com Subject: Re: [syzbot] [mm?] KASAN: slab-use-after-free Read in __vma_reservation_common Message-ID: References: <000000000000daf1e10615e64dcb@google.com> <000000000000ae5d410615fea3bf@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Mon, Apr 15, 2024 at 03:05:44PM -0700, Vishal Moola wrote: > Commit 9acad7ba3e25 ("hugetlb: use vmf_anon_prepare() instead of > anon_vma_prepare()") may bailout after allocating a folio if we do not > hold the mmap lock. When this occurs, vmf_anon_prepare() will release the > vma lock. Hugetlb then attempts to call restore_reserve_on_error(), > which depends on the vma lock being held. > > We can move vmf_anon_prepare() prior to the folio allocation in order to > avoid calling restore_reserve_on_error() without the vma lock. But now you're calling vmf_anon_prepare() in the wrong place -- before we've determined that we need an anon folio. So we'll create an anon_vma even when we don't need one for this vma. This is definitely a pre-existing bug which you've exposed by making it happen more easily. Needs a different fix though.