Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1598534rdb; Mon, 2 Oct 2023 15:00:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHJ16pJKiGsk2ldN8no0OCOE3E2Mf4xtn63ADlnE2MakN8hpJt+mg9yso0S5MfA139Zr2zf X-Received: by 2002:a05:6a21:7891:b0:15e:9923:3e35 with SMTP id bf17-20020a056a21789100b0015e99233e35mr1344926pzc.19.1696284039768; Mon, 02 Oct 2023 15:00:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696284039; cv=none; d=google.com; s=arc-20160816; b=o4uHyB1RWCkT2WHZR8Eqb26Ojjq8ZxBCnsJ2X/BeXNx0pMJn2D88vth73gP/LVj4+y SMKUxOMjwxBnv52UMO+hCv9PrEOwmmPU+aIvlP7Ro/RKrH1ymk1lh/Z8IVcigAEr5f09 0d2buibI86yMTQw2++QJy2csCPlKB0b9wOe1HE0LpvjjyR3muyTxmFCoIg+7FPBbYAcp SxJJo0GMyQf3um6aePs2uzzUocxRey5CJ4CSBaqfKjFYMA5nZEBKOZDeL5N3hxwP9zcY lHork9Q909yFvKRtZSFii0jhPqD38idyk+2Ik7rmUpuOfZZDOWqH3WS+8fFHiwYF5xyU 9WGw== 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=LYcUk7eapL0u7BOO7YlNH4OBXGFayR53WAp/OvFIzcY=; fh=FirTlRGFovUKjvbwRrk+YwSu+Hh3V/t5Ob+62PJGQbA=; b=mfw7bLHGYchuFoY0BL1a1yi0PDfqQb7zPkzJBXMRLFd0nHF2cOTyolG5u8mOf9HuAO YIW2h0nWadyAmL+eDpw9CyYZmnRBsXE5PFvr2m+V3G0C73Y3baIU6wmoM4hphNpnvyac 7HaUWH6y6bJNAH1CsLSIlItnP8Jn0siJ/gaY2j3RsOO66AFTlJXHyYQaBj0lmms7Ctlo /yFXNaSUa/ObZ/9q/g7lJZIKD7oyXyVtSwMsaX5+KVcf/bcjqDKG3kNHHFEaD/jVEfgJ SCBArJpaujt/oFmLLFEnnXPD6FnhnvchJ3ItSyz61fPE1bwy7RFUoGQnEq3OvclASW6m Ef+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=US5bw17J; dkim=neutral (no key) header.i=@suse.cz header.b=yPe7Cw+S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id n18-20020a637212000000b0055793097dbesi16540370pgc.469.2023.10.02.15.00.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 15:00:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=US5bw17J; dkim=neutral (no key) header.i=@suse.cz header.b=yPe7Cw+S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 56BDB80D44C8; Mon, 2 Oct 2023 00:26:16 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235739AbjJBH0J (ORCPT + 99 others); Mon, 2 Oct 2023 03:26:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235696AbjJBH0J (ORCPT ); Mon, 2 Oct 2023 03:26:09 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC0F78E; Mon, 2 Oct 2023 00:26:04 -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 AE47221846; Mon, 2 Oct 2023 07:26:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1696231563; 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=LYcUk7eapL0u7BOO7YlNH4OBXGFayR53WAp/OvFIzcY=; b=US5bw17J+0Iki685lLs7lp6J+ensi9UDi2MWyWSMHSaFrtyKOUAhyknJnT7V/cQ0geUM94 TyfWOgmnizPgyN840e9v9o3dWqZvLsZVmj4pxbZVES1GP9gRW2ObhjuPJQOmFxNRT8M9zI z9v0VY/w+uIEmFZEzPDd7bb0e3EtzNE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1696231563; 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=LYcUk7eapL0u7BOO7YlNH4OBXGFayR53WAp/OvFIzcY=; b=yPe7Cw+SZkaGLF5b5L5kWkoRpXulmIWu00NLTcP3sBUCbdEDS3Ln2L1g1U39vcpit6DlQr KMr+FqozU9dk54AQ== 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 8B2BE13434; Mon, 2 Oct 2023 07:26:03 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id z6EnIYtwGmX+fwAAMHmgww (envelope-from ); Mon, 02 Oct 2023 07:26:03 +0000 Message-ID: Date: Mon, 2 Oct 2023 09:26:03 +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 2/3] mmap: Fix error paths with dup_anon_vma() Content-Language: en-US To: Lorenzo Stoakes , "Liam R. Howlett" Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Jann Horn , Suren Baghdasaryan , Matthew Wilcox , stable@vger.kernel.org References: <20230929183041.2835469-1-Liam.Howlett@oracle.com> <20230929183041.2835469-3-Liam.Howlett@oracle.com> <843f059f-dd54-4481-b46a-e87e56274db3@lucifer.local> From: Vlastimil Babka In-Reply-To: <843f059f-dd54-4481-b46a-e87e56274db3@lucifer.local> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 02 Oct 2023 00:26:16 -0700 (PDT) On 9/30/23 00:28, Lorenzo Stoakes wrote: > On Fri, Sep 29, 2023 at 02:30:40PM -0400, Liam R. Howlett wrote: >> When the calling function fails after the dup_anon_vma(), the >> duplication of the anon_vma is not being undone. Add the necessary >> unlink_anon_vma() call to the error paths that are missing them. >> >> This issue showed up during inspection of the error path in vma_merge() >> for an unrelated vma iterator issue. >> >> Users may experience increased memory usage, which may be problematic as >> the failure would likely be caused by a low memory situation. >> >> Fixes: d4af56c5c7c6 ("mm: start tracking VMAs with maple tree") >> Cc: stable@vger.kernel.org >> Cc: Jann Horn >> Signed-off-by: Liam R. Howlett >> --- >> mm/mmap.c | 30 ++++++++++++++++++++++-------- >> 1 file changed, 22 insertions(+), 8 deletions(-) >> >> diff --git a/mm/mmap.c b/mm/mmap.c >> index acb7dea49e23..f9f0a5fe4db4 100644 >> --- a/mm/mmap.c >> +++ b/mm/mmap.c >> @@ -583,11 +583,12 @@ static inline void vma_complete(struct vma_prepare *vp, >> * dup_anon_vma() - Helper function to duplicate anon_vma >> * @dst: The destination VMA >> * @src: The source VMA >> + * @dup: Pointer to the destination VMA when successful. >> * >> * Returns: 0 on success. > > Being a bit nitpicky/refactory here, but anon_vma_clone() appears to have > two possible return values - 0 for success, and -ENOMEM. > > As a result, it's not really gaining us much passing through this value. > > It'd be nice if dup_anon_vma() and anon_vma_clone() were therefore updated > to instead return NULL on ENOMEM and the dst otherwise. But we also need to represent that dup_anon_vma() had nothing to do, because "(src->anon_vma && !dst->anon_vma)" was false, and in that case we should not be returning dst from there? So maybe we could return NULL for that case and ERR_PTR(ret) for the -ENOMEM from anon_vma_clone() ? > Then we could de-clunk this whole code path, and the quite natural fact of > 'thing didn't return a pointer therefore had no memory to allocate it' fals > out. > > But this isn't exactly an earth-shattering concern :) >