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 14303C4345F for ; Tue, 16 Apr 2024 08:13:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A10C46B0087; Tue, 16 Apr 2024 04:13:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9BF566B0088; Tue, 16 Apr 2024 04:13:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 886A96B0089; Tue, 16 Apr 2024 04:13:41 -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 64ED26B0087 for ; Tue, 16 Apr 2024 04:13:41 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 2DFCF1A09E9 for ; Tue, 16 Apr 2024 08:13:41 +0000 (UTC) X-FDA: 82014681042.03.6B85199 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf15.hostedemail.com (Postfix) with ESMTP id ED31CA0006 for ; Tue, 16 Apr 2024 08:13:38 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=MstkI6ty; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=PzknxHhZ; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=MstkI6ty; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=PzknxHhZ; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf15.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713255219; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=JSsAJ0gSvxccqjp8rLcQxKaSqVsIpKD8OJPWNVMymHY=; b=8B4hlmKILfObt0YL/j/D6ijJlCC+bWYIWiTYk+zHM7Chdqpsg4BdzYGZo5gmkAGUqqRVnl GfFuzizmXoeACuOqooJqaOpOCUN611ENuUaTkKV2WY+gANZaHEbX//+TYzGF14H8lbe69P 0TaowMDfcHFHcLY33G9cTblXi4mGptc= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=MstkI6ty; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=PzknxHhZ; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=MstkI6ty; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=PzknxHhZ; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf15.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713255219; a=rsa-sha256; cv=none; b=ectknStC3bLg0vsKIaqGBKq/3SJc0O77yg8D1NFLqDTNIqlSF2uFE7rPqyztwAbhdK3PPl ulJfSjpeqs88xQWq1p9UOFWWY33zbDk0IBlSRX8MfE3AcXcLdkKW9PsM/nlFYcutbiUild gX1ztrsGUkoqpRrc91emwKV5vR6T/nk= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 33AAA37974; Tue, 16 Apr 2024 08:13:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1713255217; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=JSsAJ0gSvxccqjp8rLcQxKaSqVsIpKD8OJPWNVMymHY=; b=MstkI6tyg/UOxpd2f3JPoXc/6slqx01nWhbOxaxAmf2I3WgX3DnuyiZ5Dy62fgpddhZjic JRTLPSS58dYmt78FwqnjfEWxTbC0s+sf8alinqriTdSaP3wTUEHgbB/iA3onbrE8dCIUgs jWEjKty4Wk3g51Vyc8xDe6HZoWOnkB4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1713255217; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=JSsAJ0gSvxccqjp8rLcQxKaSqVsIpKD8OJPWNVMymHY=; b=PzknxHhZKyOPn/VKIR+Wcyne1YjdjyUPCnZOnFPMvjJ1D4YqlGblLz/7X8x4um1XC0cujq 392jdD1992iKsIBg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1713255217; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=JSsAJ0gSvxccqjp8rLcQxKaSqVsIpKD8OJPWNVMymHY=; b=MstkI6tyg/UOxpd2f3JPoXc/6slqx01nWhbOxaxAmf2I3WgX3DnuyiZ5Dy62fgpddhZjic JRTLPSS58dYmt78FwqnjfEWxTbC0s+sf8alinqriTdSaP3wTUEHgbB/iA3onbrE8dCIUgs jWEjKty4Wk3g51Vyc8xDe6HZoWOnkB4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1713255217; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=JSsAJ0gSvxccqjp8rLcQxKaSqVsIpKD8OJPWNVMymHY=; b=PzknxHhZKyOPn/VKIR+Wcyne1YjdjyUPCnZOnFPMvjJ1D4YqlGblLz/7X8x4um1XC0cujq 392jdD1992iKsIBg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id AD63713432; Tue, 16 Apr 2024 08:13:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 6b+NJzAzHma/ZAAAD6G6ig (envelope-from ); Tue, 16 Apr 2024 08:13:36 +0000 Date: Tue, 16 Apr 2024 10:13:31 +0200 From: Oscar Salvador To: Matthew Wilcox Cc: Vishal Moola , 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Action: no action X-Rspam-User: X-Stat-Signature: a87bie11ccdgzijk98er911ee38pcex9 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: ED31CA0006 X-HE-Tag: 1713255218-575142 X-HE-Meta: U2FsdGVkX1+rhiJcdqaGPR4NIax7xGM3N2x6xO1Eoprs698yUQWuHZtkHkUIBVM7lwjP2+WnTlot8wxbQdsMSAVkB+Ay9H7coDdOWSlBsMOu1QGeyp0Q7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c0PygfxRbztkd2LUv5SSqU48DolowbBGKaQEZ8EAvOyn6KodTpoa1AzcL9i+8laHMDn1HIbQ5VOBksa4k3cts1/jg225QgNR1MIDnr3bn50c2sZWnUAT5/6RY8k6DiijmcLKoPfSFPo/3rZkNaws/3gn5syybG8wXG4VH1SquguEAKMqovwEroPQpSO3takqYWN5QmZ5vABRJqcEt484= 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 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. -- Oscar Salvador SUSE Labs