From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54C51C4345F for ; Wed, 17 Apr 2024 21:31:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C6E706B009C; Wed, 17 Apr 2024 17:31:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C1EDA6B009D; Wed, 17 Apr 2024 17:31:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ABF566B009E; Wed, 17 Apr 2024 17:31:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 8EAE76B009C for ; Wed, 17 Apr 2024 17:31:17 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 414ACA1C6A for ; Wed, 17 Apr 2024 21:31:17 +0000 (UTC) X-FDA: 82020319794.27.F351554 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf11.hostedemail.com (Postfix) with ESMTP id 987774001F for ; Wed, 17 Apr 2024 21:31:15 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=Qc1llDWP; spf=pass (imf11.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713389475; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=7irB1lmvnAVHb0OTYjXT4fA79/uWQEq8EQhfjzh8ihQ=; b=k4r+wNJ4B4cPXavb4kQmVWrN7+AYya3bGS+W0Zb1Wcaqj4eWrn5GIg1Cy4VEoiWmuPIBbl I540FQ/QbuQHujzU1/AU055tT4L0hy9K3B4kNeayEsq0goPxRx1OdBX59FuqGCdc3jltR4 jD/O1LL7XUWKNTiiBt7vPFSDZDozuHU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713389475; a=rsa-sha256; cv=none; b=bdzCBCWJ/ZnEx6ASHvS8sVZ9ET0DLB6tZKsCCF1m2o535uA7lVjrfZHwGoe/cpEkgxjzSH l481l7AUoT40HDYAuFCdbMf5vSMiT97kncCEXXTSDJMke94M+kI4Eba1RD4hfeIRph293e TH/ZawS2GCqyORhMyK4BRbrEWZgGfik= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=Qc1llDWP; spf=pass (imf11.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 77064615F7; Wed, 17 Apr 2024 21:31:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB04CC072AA; Wed, 17 Apr 2024 21:31:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1713389474; bh=BUvNBDN8ASj+mIKXlPKJ5UdnbvlyYutLvYoQLGXc4wI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Qc1llDWPkmmexlecR7t7m9hPyzRNjGUKegtPtvV4t9OU3Ki6bf4DrCbOH0jCC/mK+ UQle3IettyM3nCBs/5FdGl2w/O1IoWdHveaggrY8f93h1L0/S8s65M/9EwCnCeXnXI XrDjuB/yJlPn6jyJDDP/kHDTVxh39Zq94hXfvUsE= Date: Wed, 17 Apr 2024 14:31:13 -0700 From: Andrew Morton To: Oscar Salvador Cc: Matthew Wilcox , Vishal Moola , syzbot , 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: <20240417143113.23df96102dcdd2b0c3805329@linux-foundation.org> In-Reply-To: References: <000000000000daf1e10615e64dcb@google.com> <000000000000ae5d410615fea3bf@google.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 987774001F X-Rspam-User: X-Stat-Signature: e1kpk4jcm9pcx3etojge3nbqx81ixmk5 X-HE-Tag: 1713389475-91191 X-HE-Meta: U2FsdGVkX18o8R8ek3zQ/Stu4H3gvxMyYdjLzXYoylVRSCjncWVDAYEnD2/9nLqdLt2GquTEREPnFiPSP8EO9+Fqhi9VYnGqICzBo8fXpmqXYm6zL624Ow+F6jJpDwS+F7irF8qoX7C9U6r4ii4/DRtXp1ksW35z8SKNyk8sHzA6swxegBaWMw0skqOsY3N+upNGdVsOyOd/xSc1vF8J5O/bOS9vIluLt8Av5YjH5+pxVveqY9rljXef9H01BzAKjjNu+jFzXztmX6nP7N5Sjj04LDKA5BZNH6SN1Gk/7lsAPUWZlUqjMLauuwcXJ4/hUYgxOK1IoRoymp7NYleIjNmZcJY1KglaEEcXwsP1oyIeeoY+oP82paDQLoaCbccIfubV+OjozYLKaryDXtYNV57CTPjxmkH2TSS+5e0WJlURCr9WbH+sfVLd8RSrfEwgDndn3keqPvmwDsO9kry3oW0ueHpEOs0hxM05bItZhIqItZAm6bNDutBTTNj/yhgDQ9JzInQeFJymyvjm9MwIgx89KzB1v0ja5OG/8LlVDbRzAm4sm3ZLtsQ9I1W+DPa1xnKlSo/3Ghj7l/f+C2k7iogPYQ39PteJYs2l57PcGBqEIXCW3xqkL4slAsEVWdrDwYsoezzGcRTtl8nenthDGfsEp/rjpdeih4RAx4ZhR8kSa1BJlKOF+X6GA41IUt0zThEpVOSWHfJxEoaCzBY3iMO7zxd5+ibNx4ovE1GaeUE/WYCanotv5sRCrljfTq4Io0BYZP+61fM9yOw/7xDdprpanOkw6YR3G+QHbzigvdiLEgb0/Op5JQMRRuSwAfMGKHzTZWu+1oYZX4NVYoN3Tx1MBTO/EB+m88gjZq7KpowTuM1aPLK6abzGvR61bz1VOyA3CWHD7Y4uOkGn81A+nGRPF5ngBEas7kbI8ZtE3vRGIsilKArOVTSS1Xdi4oxmyz6rCgGubqwQtlat2eT Vz33f7A0 CqYmrwlRGrThIfOf6HR1QPHUyAiUhx3/3KG2CAsD2rOFH9CQfHHGuyRL+2r8MvWrZN8PhXwsEhaIKNPi7zg3YamXvgwv44rEoZa4RXPMALZRsiFcPJXfhwD8meank/s0KuqrHP5n9q2lHWUA= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Tue, 16 Apr 2024 10:13:31 +0200 Oscar Salvador wrote: > On Mon, Apr 15, 2024 at 11:15:03PM +0100, Matthew Wilcox wrote: > > 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. > > I do not think this is a pre-existing bug. > Prior to 'commit: 7c43a553792a ("hugetlb: allow faults to be handled under > the VMA lock"), we would just bail out if we had FAULT_FLAG_VMA_LOCK. > So there was no danger in calling functions that fiddle with vmas like > restore_reserve_on_error() does. > After that, we allow it but vmf_anon_prepare() releases the lock and returns > VM_FAULT_RETRY if we really need to allocate an anon_vma. > The problem is that now restore_reserve_on_error() will re-adjust the > reservations without the vma lock, completely unsafe. > > I think the safest way to tackle this is just as Vishal did, call > vmf_anon_prepare() upfront only for non VM_MAYSHARE faults. Thanks. I didn't apply anything at this stage, because this patch appears to be against linux-next/mm-unstable whereas for a -stable backportable thing it would best be against current -linus. So can we please sort out a suitable Fixes:, redo the patch against current mainline, add the cc:stable and await further input from Matthew?