From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6FBCA1D12FE; Tue, 19 Nov 2024 20:48:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732049338; cv=none; b=pe51yFHHVCSnckEAQG48eji9swF85vubPsgmwNfYFrviGyY0wAisGg0K5ioB8FXa6rfzm+1zxy661hiL3fEA+BzKNx/cEapBaB73Gw1WDzy36VTANgcliOB2HbNg3p5F4vZ9ZDMf+5zv0rnOkr4HWDdc1FqktKQUSBZH2kzIMcw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732049338; c=relaxed/simple; bh=gIw6ZvAwgn9OHrhXwJZ598dYTvnysBtFLmFA6JqK+1I=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=EsvdCvT0K5FvhvSHyP+yABmYmhUsxDuATf5jfQgCb1RJMa8IHVLoC/WQs2MDyeuKP76T2zb+M609augLvZhnByu649UMenYY2KtivmixYgcrtQSNtiCUYkhQoqikimo42U4Cid7BviJfSDyJ61ljD4V+6WRNSghHtl+8cuFo6nM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz; spf=pass smtp.mailfrom=suse.cz; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=kIXZOoxz; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=18dOPRYo; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=kIXZOoxz; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=18dOPRYo; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.cz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="kIXZOoxz"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="18dOPRYo"; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="kIXZOoxz"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="18dOPRYo" 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 7A41B21A01; Tue, 19 Nov 2024 20:48:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1732049334; h=from:from:reply-to: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:autocrypt:autocrypt; bh=A/Bs+ZefnbNeOqmsS+J9RuwLygMWmMJvadh+ULF0z5E=; b=kIXZOoxz/l4kk+EYr69jmq1nIamuxRlcWRAZGo7Fy7kvdAqvBkfhUbxTY/iyljtdvcNqgt 1HdeOcYxgnXRci67PL8rsQ4a41H/Zk6Vvbl2Nmg2N15PeiAVru13UevO1Nx44Hw/W44sE1 W7iygK+RscAYo1gMDlmmgAf/LWe34G4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1732049334; h=from:from:reply-to: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:autocrypt:autocrypt; bh=A/Bs+ZefnbNeOqmsS+J9RuwLygMWmMJvadh+ULF0z5E=; b=18dOPRYoopFOEttynKZoLSuCSP2gMA8XGlpNKbjNaIb2MfoZ7c8xpzohQBjzg+WK/oz3kg jLeuFiUhMtAuhnDw== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=kIXZOoxz; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=18dOPRYo DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1732049334; h=from:from:reply-to: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:autocrypt:autocrypt; bh=A/Bs+ZefnbNeOqmsS+J9RuwLygMWmMJvadh+ULF0z5E=; b=kIXZOoxz/l4kk+EYr69jmq1nIamuxRlcWRAZGo7Fy7kvdAqvBkfhUbxTY/iyljtdvcNqgt 1HdeOcYxgnXRci67PL8rsQ4a41H/Zk6Vvbl2Nmg2N15PeiAVru13UevO1Nx44Hw/W44sE1 W7iygK+RscAYo1gMDlmmgAf/LWe34G4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1732049334; h=from:from:reply-to: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:autocrypt:autocrypt; bh=A/Bs+ZefnbNeOqmsS+J9RuwLygMWmMJvadh+ULF0z5E=; b=18dOPRYoopFOEttynKZoLSuCSP2gMA8XGlpNKbjNaIb2MfoZ7c8xpzohQBjzg+WK/oz3kg jLeuFiUhMtAuhnDw== 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 655761376E; Tue, 19 Nov 2024 20:48:54 +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 bylcGLb5PGdfAQAAD6G6ig (envelope-from ); Tue, 19 Nov 2024 20:48:54 +0000 Message-ID: Date: Tue, 19 Nov 2024 21:48:54 +0100 Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 6.12.y v2] mm/mmap: fix __mmap_region() error handling in rare merge failure case Content-Language: en-US To: "Liam R. Howlett" , stable@vger.kernel.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Lorenzo Stoakes , Jann Horn , syzbot+bc6bfc25a68b7a020ee1@syzkaller.appspotmail.com References: <20241119175945.2600945-1-Liam.Howlett@oracle.com> From: Vlastimil Babka Autocrypt: addr=vbabka@suse.cz; keydata= xsFNBFZdmxYBEADsw/SiUSjB0dM+vSh95UkgcHjzEVBlby/Fg+g42O7LAEkCYXi/vvq31JTB KxRWDHX0R2tgpFDXHnzZcQywawu8eSq0LxzxFNYMvtB7sV1pxYwej2qx9B75qW2plBs+7+YB 87tMFA+u+L4Z5xAzIimfLD5EKC56kJ1CsXlM8S/LHcmdD9Ctkn3trYDNnat0eoAcfPIP2OZ+ 9oe9IF/R28zmh0ifLXyJQQz5ofdj4bPf8ecEW0rhcqHfTD8k4yK0xxt3xW+6Exqp9n9bydiy tcSAw/TahjW6yrA+6JhSBv1v2tIm+itQc073zjSX8OFL51qQVzRFr7H2UQG33lw2QrvHRXqD Ot7ViKam7v0Ho9wEWiQOOZlHItOOXFphWb2yq3nzrKe45oWoSgkxKb97MVsQ+q2SYjJRBBH4 8qKhphADYxkIP6yut/eaj9ImvRUZZRi0DTc8xfnvH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cv0NjIQi8867H3uLjz+mQy63fAitsDwLmR EP+ylKVEKb0Q2A== In-Reply-To: <20241119175945.2600945-1-Liam.Howlett@oracle.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 7A41B21A01 X-Spam-Level: X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; SUSPICIOUS_RECIPS(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; TAGGED_RCPT(0.00)[bc6bfc25a68b7a020ee1]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; MIME_TRACE(0.00)[0:+]; RCPT_COUNT_SEVEN(0.00)[8]; RCVD_TLS_ALL(0.00)[]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.cz:email,suse.cz:dkim,suse.cz:mid]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.cz:+] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spam-Score: -3.01 X-Spam-Flag: NO On 11/19/24 18:59, Liam R. Howlett wrote: > From: "Liam R. Howlett" > > The mmap_region() function tries to install a new vma, which requires a > pre-allocation for the maple tree write due to the complex locking > scenarios involved. > > Recent efforts to simplify the error recovery required the relocation of > the preallocation of the maple tree nodes (via vma_iter_prealloc() > calling mas_preallocate()) higher in the function. > > The relocation of the preallocation meant that, if there was a file > associated with the vma and the driver call (mmap_file()) modified the > vma flags, then a new merge of the new vma with existing vmas is > attempted. > > During the attempt to merge the existing vma with the new vma, the vma > iterator is used - the same iterator that would be used for the next > write attempt to the tree. In the event of needing a further allocation > and if the new allocations fails, the vma iterator (and contained maple > state) will cleaned up, including freeing all previous allocations and > will be reset internally. > > Upon returning to the __mmap_region() function, the error is available > in the vma_merge_struct and can be used to detect the -ENOMEM status. > > Hitting an -ENOMEM scenario after the driver callback leaves the system > in a state that undoing the mapping is worse than continuing by dipping > into the reserve. > > A preallocation should be performed in the case of an -ENOMEM and the > allocations were lost during the failure scenario. The __GFP_NOFAIL > flag is used in the allocation to ensure the allocation succeeds after > implicitly telling the driver that the mapping was happening. > > The range is already set in the vma_iter_store() call below, so it is > not necessary and is dropped. > > Reported-by: syzbot+bc6bfc25a68b7a020ee1@syzkaller.appspotmail.com > Closes: https://syzkaller.appspot.com/x/log.txt?x=17b0ace8580000 > Fixes: 5de195060b2e2 ("mm: resolve faulty mmap_region() error path behaviour") > Signed-off-by: Liam R. Howlett > Cc: Lorenzo Stoakes > Cc: Vlastimil Babka > Cc: Jann Horn > Cc: Reviewed-by: Vlastimil Babka