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 4BE4D288C08 for ; Tue, 21 Apr 2026 09:08:30 +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=1776762510; cv=none; b=hQCsbFCbgnzXgBmRzYNqpcQQxmr4Kmw8i6RcO9GmgXDavKLUyQ1WGERXhDD+7BffBgT4fTheMZ/PnAfeTV43GZ2vQDV00YaNNaqcccR8hlImQi9MsQye6O+CviEFWVckIPqSH+9joMzolAZY1ALMYOurfjYYyGauun4CI0jNJT4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776762510; c=relaxed/simple; bh=JnjFXHz/DzaxlCC1EjhtvgOWVsZUYZ1qXPlyL5Gg3Mk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ilSQd5UUpXs5e21ntOMmePYvjcXjy7kqvUM/U1+TTLIAUXWvm2oLBTxSwVu6sLPfJETbUpvg1i3+w9UFgRx9mLO4rkRHLdBE02OEZSUcXEGPUObQN+wTtHNZ9LaNXJiIti034pclZnJs+gYjtFjD5BQ4EADYI850Jzx5YtO+kA0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qHrgWQHh; 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="qHrgWQHh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4575C2BCB5; Tue, 21 Apr 2026 09:08:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776762509; bh=JnjFXHz/DzaxlCC1EjhtvgOWVsZUYZ1qXPlyL5Gg3Mk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=qHrgWQHhOHD+v7BkML+OGgs7w/nKJBfA8bmC5rZq1RqPZcVUc4LkU4Tp2G0Xekbsf T/ngt4IGDVyFGM2c1dXeWNIJzARNeIZZUr3sKEbXj5zohufQJ7YZ0JoSnGqQMzZIAd wQiCG8b3OuEmQyj/3cAEB6wnRhlkQ64luJuEKnHXe1rf6VTjmscUi4+RwtH1qr6Miz M37r41MIXPe7jmsjSbOzCjsqmJHZJ2nR5BEdHqulAHA1Gg3/S99IHJRjrJ5JTwCx0l kVX2E4Z5FhEBG6sMoXScopZXMVgzM5M2UCqUKH36sWcXh6A60qcGA1S01NTwCVQHKT j8308YPwRtrJw== Date: Tue, 21 Apr 2026 10:08:23 +0100 From: Lorenzo Stoakes To: Ye Liu Cc: Andrew Morton , David Hildenbrand , "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> 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: <20260421085056.26033-1-ye.liu@linux.dev> NAK, expected allocation failures (even if practically impossible) should not cause arbitrary kernel warnings. But also this is very silly, you would need INT_MAX references on the anon_name to happen first... On Tue, Apr 21, 2026 at 04:50:55PM +0800, 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. We assign NULL if the allocation failed. And every code path understands vma->anon_vma_name being NULL to be a valid situation of that VMA not having a name. In the case you're failing an allocation that small, the system is under extreme memory pressure. Not propagating an anon_vma_name, which is cosmetic, is totally fine under those circumstances. But also, you'd require the anon_vma_name to be saturated at REFCOUNT_MAX == INT_MAX. So this is just silly. > > 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. It's not? Your whole thesis is that allocation failures can happen here and cause a problem, so you can't simultaneously say it's 'unexpected'? > - In replace_anon_vma_name(), return -ENOMEM to propagate the allocation > failure to the caller. > > These changes improve robustness against memory allocation failures. No, they add a bunch of noise, then make an allocation failure into an arbitrary, new kernel warning. > > 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); > + } This is horrible code, but as I said above, this is not only wrong it's actively bad - you're causing an allocation failure to result in a kernel warning. We don't mind anon_vma_name not being propagated after billions of references and under maximally extreme memory pressure/fatal signal propagation. > } > > static inline void free_anon_vma_name(struct vm_area_struct *vma) > diff --git a/mm/madvise.c b/mm/madvise.c > index 69708e953cf5..ccb937a37e70 100644 > --- a/mm/madvise.c > +++ b/mm/madvise.c > @@ -118,6 +118,7 @@ static int replace_anon_vma_name(struct vm_area_struct *vma, > struct anon_vma_name *anon_name) > { > struct anon_vma_name *orig_name = anon_vma_name(vma); > + struct anon_vma_name *new_name; > > if (!anon_name) { > vma->anon_name = NULL; > @@ -128,7 +129,11 @@ static int replace_anon_vma_name(struct vm_area_struct *vma, > if (anon_vma_name_eq(orig_name, anon_name)) > return 0; > > - vma->anon_name = anon_vma_name_reuse(anon_name); > + new_name = anon_vma_name_reuse(anon_name); > + if (!new_name) > + return -ENOMEM; > + > + vma->anon_name = new_name; This is pointless noise. Billions of references, extreme memory pressure (practically impossible anyway). > anon_vma_name_put(orig_name); > > return 0; > -- > 2.43.0 > Thanks, Lorenzo