Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1324945rdb; Mon, 2 Oct 2023 06:25:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFXcHqdXFuphJ4Dr8caUx96n3UvhcG4kq18d3x7JpYG42t5XqMymah12EtmQVISGfemanT0 X-Received: by 2002:a17:903:1251:b0:1c5:59ea:84de with SMTP id u17-20020a170903125100b001c559ea84demr11595560plh.29.1696253104895; Mon, 02 Oct 2023 06:25:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696253104; cv=none; d=google.com; s=arc-20160816; b=KMbZVFAYVp1YX+kVQ6O82kMByTiyfqM62kUkznF6CJeiEV6Ct963UzAdv5cQIiKJLF rQZRTRU4T+Yag2fo7ztZ2Wrt0ZM8q49UiSzkHBZDUyI+hEBbOpCZ6TtspiHtQOt/5AiK 7XaJuMkDs5X2yl7BnW9LJIsM0d0Gl9l27ojjuoYdSB9mI/nq5fQBfuSazm59TopQlhSe e7R9nhWPeua6O9SQHbuDaKFmeocGsKDALZ44kk+t6hWOSHyNar4+0Mcy/n3j3vqwtp1X Jw3Z/NJ/tWZr+Ks2JI5iT42rFauVh4u58Mm1T6E+wPGzIRn2n5TxeBF6e3f/upcCSgRi ouBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-signature; bh=8vcbNq67Xl3f2iKsCH4we0sJgW4X2ca2S7bOAsiex1Q=; fh=6M5ep/xA7byG41PvLXc6skGUTVKf7xR0ukeVPSqrBrI=; b=FmqJFoFBzLKXpH0u4obA28CBpyMKJcoPVMz3iX6Qze9AEq6WwMMqSH/M3NfURq9C2g 26fu8+8Fc0RlbTevDTbiyjsDMEbGdEL63h/ipl5DfBd4FLgy/5rUFjyH1PiUqI8UfenT XkqLLH8pvpEzZGb5YqzHnCL/2C5s7954D4Yll/u3jr4r9Xe7xaAXSwOaXblbqy7aL69S few+bZNlQB/2jJbGMUTpF+TkMwjHDbBVzsvDzCWHP+uvS+z/vSsTcK7N0XuLLkDvkpkE CqQibeOzvNJrWRjubFSojIjowYD5y/9WNXwdTuQ7t25uzy9U1h93CmvqI46YeKOdZIxE lXDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=sYBuE9Dm; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id b1-20020a170902d50100b001baff05d890si14695609plg.313.2023.10.02.06.25.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 06:25:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=sYBuE9Dm; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id CB617809B742; Mon, 2 Oct 2023 00:09:37 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235630AbjJBHJ1 (ORCPT + 99 others); Mon, 2 Oct 2023 03:09:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235599AbjJBHJ0 (ORCPT ); Mon, 2 Oct 2023 03:09:26 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C5218E; Mon, 2 Oct 2023 00:09:24 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id BD2C121853; Mon, 2 Oct 2023 07:09:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1696230562; 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; bh=8vcbNq67Xl3f2iKsCH4we0sJgW4X2ca2S7bOAsiex1Q=; b=sYBuE9DmG1frwKtVsSRTG3Ale2r5OTm85xqfZD4SMQgyARAWCQuqkgePAMH2qt5USeFSzU +3vTGLz702iOSggMMRZMufC+M6m+JAsB/esv//AAAKxAUUcVtuITmwd1siIpONwABSppuA O+ZYuCQ4dJgnDNq4hb0wZ7Qj8p6sC3Q= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1696230562; 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; bh=8vcbNq67Xl3f2iKsCH4we0sJgW4X2ca2S7bOAsiex1Q=; b=Je9vocE06l6uaNRhWqNdvU+Sf0X8KCDs3p9+1pNsnpesOSRzY1tacE+DfjZuDBsZ5JmuP6 Mk1KJum7qrwXhKCg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 92F6613456; Mon, 2 Oct 2023 07:09:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id xE9RI6JsGmWqeAAAMHmgww (envelope-from ); Mon, 02 Oct 2023 07:09:22 +0000 Message-ID: <8055dadf-a8ee-6706-79b3-6fc61d77c71e@suse.cz> Date: Mon, 2 Oct 2023 09:09:22 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH v3 1/3] mmap: Fix vma_iterator in error path of vma_merge() Content-Language: en-US To: "Liam R. Howlett" , Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Jann Horn , Lorenzo Stoakes , Suren Baghdasaryan , Matthew Wilcox , stable@vger.kernel.org References: <20230929183041.2835469-1-Liam.Howlett@oracle.com> <20230929183041.2835469-2-Liam.Howlett@oracle.com> From: Vlastimil Babka In-Reply-To: <20230929183041.2835469-2-Liam.Howlett@oracle.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 02 Oct 2023 00:09:38 -0700 (PDT) On 9/29/23 20:30, Liam R. Howlett wrote: > During the error path, the vma iterator may not be correctly positioned > or set to the correct range. Undo the vma_prev() call by resetting to > the passed in address. Re-walking to the same range will fix the range > to the area previously passed in. > > Users would notice increased cycles as vma_merge() would be called an > extra time with vma == prev, and thus would fail to merge and return. > > Link: https://lore.kernel.org/linux-mm/CAG48ez12VN1JAOtTNMY+Y2YnsU45yL5giS-Qn=ejtiHpgJAbdQ@mail.gmail.com/ > Closes: https://lore.kernel.org/linux-mm/CAG48ez12VN1JAOtTNMY+Y2YnsU45yL5giS-Qn=ejtiHpgJAbdQ@mail.gmail.com/ > Fixes: 18b098af2890 ("vma_merge: set vma iterator to correct position.") > Cc: stable@vger.kernel.org > Cc: Jann Horn > Signed-off-by: Liam R. Howlett Acked-by: Vlastimil Babka > --- > mm/mmap.c | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) > > diff --git a/mm/mmap.c b/mm/mmap.c > index b56a7f0c9f85..acb7dea49e23 100644 > --- a/mm/mmap.c > +++ b/mm/mmap.c > @@ -975,7 +975,7 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, > > /* Error in anon_vma clone. */ > if (err) > - return NULL; > + goto anon_vma_fail; > > if (vma_start < vma->vm_start || vma_end > vma->vm_end) > vma_expanded = true; > @@ -988,7 +988,7 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, > } > > if (vma_iter_prealloc(vmi, vma)) > - return NULL; > + goto prealloc_fail; > > init_multi_vma_prep(&vp, vma, adjust, remove, remove2); > VM_WARN_ON(vp.anon_vma && adjust && adjust->anon_vma && > @@ -1016,6 +1016,12 @@ struct vm_area_struct *vma_merge(struct vma_iterator *vmi, struct mm_struct *mm, > vma_complete(&vp, vmi, mm); > khugepaged_enter_vma(res, vm_flags); > return res; > + > +prealloc_fail: > +anon_vma_fail: > + vma_iter_set(vmi, addr); > + vma_iter_load(vmi); > + return NULL; > } > > /*