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 90DC83803D2 for ; Thu, 12 Mar 2026 20:45:32 +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=1773348332; cv=none; b=GhOeez8Pz419U9x89ZVD7/KlKR3q/HdglqObzhcJtN/fIrbDO/AgtisqrOZZt/HYQ7vYgXRt/Gs5obzTHjk4DHgZ7JflxPKq1lQiTn/Zvu/MT+Bq/hRIO6jlk9nqOHk01H30/5wgkvbFtQ5gZfa3K7Y9/ULj+MjWHxdDC5wVZrQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773348332; c=relaxed/simple; bh=umv05h/lV7uW20G8zu2OJsYgPUR2/AkzPCaK8nNLqMI=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=G4SH8zd7Ink1CjgyxT2mUV59TU++6S4Q6v7YQySN/RyIQu81Kt8+2GCn6qmkKtGAayInVyjV/odclDdbTnQKcD9/EgMnrXX9XHyW7HVjgoZI2LUBQUiu3Gphr6CrfOMMWYGBAEepPKQwUFJ/hsAqH/lnTqx0o+C/tsWAzg+Br5c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=zRwSWLe2; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="zRwSWLe2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4671C4CEF7; Thu, 12 Mar 2026 20:45:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1773348332; bh=umv05h/lV7uW20G8zu2OJsYgPUR2/AkzPCaK8nNLqMI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=zRwSWLe2T+UL0IDelWoEmMF9JySpjCCW2zqSCdEYf+3uQvZ/3+L1S/M0FafYlkw0C CC7JiQVCt/Wzx+j4qG7EY+Xv/ntzuj9tVfgEAZzqziZeKcgXMpGiALfozDM9WO33My k6vzUeH82w9WgrMC1TuVOVox7ovX5uLAgExbER+4= Date: Thu, 12 Mar 2026 13:45:31 -0700 From: Andrew Morton To: Josh Law Cc: "Liam R . Howlett" , Alice Ryhl , Andrew Ballance , Josh Law , maple-tree@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/3] lib/maple_tree: fix potential NULL dereference in mas_pop_node() Message-Id: <20260312134531.49c1f9171b4b0bc8352e678d@linux-foundation.org> In-Reply-To: <20260312184054.23481-1-objecting@objecting.org> References: <20260312184054.23481-1-objecting@objecting.org> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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-Transfer-Encoding: 7bit On Thu, 12 Mar 2026 18:40:53 +0000 Josh Law wrote: > If kmem_cache_alloc_from_sheaf() returns NULL (possible under > GFP_NOWAIT pressure), mas_pop_node() falls through to the out label > and dereferences the NULL pointer in memset(ret, 0, sizeof(*ret)). This is such a glaring bug that I wonder if we're missing something. > Add a WARN_ON_ONCE NULL check after the sheaf allocation to bail out > early, matching the existing pattern for the !mas->sheaf case above. > > Signed-off-by: Josh Law > --- > lib/maple_tree.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/lib/maple_tree.c b/lib/maple_tree.c > index 739918e859e5..87a2ba6468ca 100644 > --- a/lib/maple_tree.c > +++ b/lib/maple_tree.c > @@ -1063,6 +1063,8 @@ static __always_inline struct maple_node *mas_pop_node(struct ma_state *mas) > return NULL; > > ret = kmem_cache_alloc_from_sheaf(maple_node_cache, GFP_NOWAIT, mas->sheaf); > + if (WARN_ON_ONCE(!ret)) > + return NULL; If we're going to do this then we may as well restore !__GFP_NOWARN, get more relevant information. But a GFP_NOWAIT allocation attempt can fail relatively easily so callers must be equipped to handle it - perhaps no need for any warning.