From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 093A026B777 for ; Tue, 21 Apr 2026 09:10:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776762609; cv=none; b=LivGIelQEXdCMYov8k23O160FZ+oUNmISiy8amjCaa1dMfpTXkBuJWuBmYvIn5aQ4hrbX0aC4abtA6QXXAU3BUymbgOek+0GvzViB0vU73xO25jnNX5/qwLIT4TkgDenjL0s/enNDMruYyt/QFnjmvqvbKhA+r6JgOd5PKa3FFc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776762609; c=relaxed/simple; bh=EOuIqzkpcmELzfvgEwMB+wOPJGwzb6s9drDlHWs1PX0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ac1Q39ie4hZqML+e0MWAf5WaFkr3EtQvbhKfaZgn/hJiUS+dd03eMZFFeaEWe+5OUW0OYBX0xZHQjrOb66v4zcausYSdAgSfOOqDZ8rqpXpNz5+hufCzQnYRKCighBd87CS9ts+4gE3py7Oia3cW8lCf9yeiTSpm4JsT675A0U8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sSf9asM5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="sSf9asM5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F0A9C2BCB0; Tue, 21 Apr 2026 09:10:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776762608; bh=EOuIqzkpcmELzfvgEwMB+wOPJGwzb6s9drDlHWs1PX0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=sSf9asM5BJy4OtU9Ler+mm48ofhrpMopAx5N2doKVLinZiIPOYFvxoZbdgE7DO+rD TKuInnli9Dp4RphmUAoSN7M6sS607GgWgKTz7LiaRYVRAZjxZYN9z3Kp6DjKJCIWTM EkZQYTvSldOmUNLEYPHIa5WS8eXkxeJvTPU6EjqnUQUFp1EqpFb+RwFp7WcynOuOmk SoM7AezHNgMEIfojY7+RFlFgopJw/Ds4ZZoXLKiZ7B82icmpwCECV3ywPtxOwY4VE2 WnNhqbfV+WuqDkER2R1DWlKWSa9K6yJWR3p5ji3JkGQuAvkyc+tlTdTT7C4a/JboAB jAqYPbpgSRjOw== Date: Tue, 21 Apr 2026 10:10:02 +0100 From: Lorenzo Stoakes To: "David Hildenbrand (Arm)" Cc: Ye Liu , Andrew Morton , "Liam R. Howlett" , Ye Liu , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Jann Horn , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm: handle potential NULL return from anon_vma_name_reuse() Message-ID: References: <20260421085056.26033-1-ye.liu@linux.dev> <2f4a1999-fbd2-4cbb-8062-5574d3c1e7ce@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2f4a1999-fbd2-4cbb-8062-5574d3c1e7ce@kernel.org> On Tue, Apr 21, 2026 at 10:55:16AM +0200, David Hildenbrand (Arm) wrote: > On 4/21/26 10:50, Ye Liu wrote: > > From: Ye Liu > > > > The anon_vma_name_reuse() function may return NULL if memory allocation > > fails in anon_vma_name_alloc(). Currently, callers dup_anon_vma_name() > > and replace_anon_vma_name() do not check the return value, which could > > lead to NULL pointer dereferences. > > When, where? > > If we set vma->anon_name = NULL, it just looks like there is no anon > VMA, or what am I missing? > > > > > This patch adds proper error handling: > > - In dup_anon_vma_name(), if anon_vma_name_reuse() returns NULL, emit a > > warning via WARN_ON_ONCE(1) since this is an unexpected condition. > > - In replace_anon_vma_name(), return -ENOMEM to propagate the allocation > > failure to the caller. > > > > These changes improve robustness against memory allocation failures. > > > > Signed-off-by: Ye Liu > > --- > > include/linux/mm_inline.h | 12 +++++++++--- > > mm/madvise.c | 7 ++++++- > > 2 files changed, 15 insertions(+), 4 deletions(-) > > > > diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h > > index a171070e15f0..9bbaf8287806 100644 > > --- a/include/linux/mm_inline.h > > +++ b/include/linux/mm_inline.h > > @@ -421,9 +421,15 @@ static inline void dup_anon_vma_name(struct vm_area_struct *orig_vma, > > struct vm_area_struct *new_vma) > > { > > struct anon_vma_name *anon_name = anon_vma_name(orig_vma); > > - > > - if (anon_name) > > - new_vma->anon_name = anon_vma_name_reuse(anon_name); > > + struct anon_vma_name *new_name; > > + > > + if (anon_name) { > > + new_name = anon_vma_name_reuse(anon_name); > > + if (new_name) > > + new_vma->anon_name = new_name; > > + else > > + WARN_ON_ONCE(1); > > Triggering a warning when an allocation fails? Certainly not. It's pleasing to reply independently and see that we've reached the same conclusions here :P I mean, yeah agreed obviously! > > -- > Cheers, > > David Cheers, Lorenzo