From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16CBC1FF7C8 for ; Thu, 12 Mar 2026 23:00:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773356457; cv=none; b=iUq8rhFrsIG4PBf9utqYgDCwQZ3q7lRLQlXXIhsphhIelQ4iFHfH0MOUelpVsSA8Q2eCY/RIkwpX2UNqC6vrpepdbLtmZV/YRkjoXMm0HSdaFszq858L/kykAwGypgpnXKZU+eHbli8kymfQLADWCXNjS41e2oAUvjwvrhH3NZg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773356457; c=relaxed/simple; bh=RahmB0SI0/OXu1AwTitQIvAtW4esW43+GBpFJHtqabU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=iMTzgncbPabFEphhScQ+Ya5MFTar4mZN9xB4MUO+ygJXlDs0mLe71dqhIkVQtGi5qX2egbYE7ddG7LW0nQFYt/N+3gLN1I8LGi7mIiMWg9fZHu/32kxrPnJSal1p8jh53i9x9HnD3Atwlp+24p0JwmdMhiVgL6Jy65lav4QddBI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Ypf9bVdT; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Ypf9bVdT" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-4837b6f6b93so12051745e9.3 for ; Thu, 12 Mar 2026 16:00:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1773356454; x=1773961254; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=RahmB0SI0/OXu1AwTitQIvAtW4esW43+GBpFJHtqabU=; b=Ypf9bVdTH5QWR1llfsbcsuqU/n7rWwo5+0YUbidzOP1kQQ86MJpTGcqfhB0BrKyOyx d9xsjo3V1xDXUaC3zuVEwk9R+TazrPzpFEkmR4l/aFNx9m499V3We1Zj67g+E5Lkk5V2 9Sns1nKw63eSmyfdoK/DXyh/MOmgBjTbTCuGf6HprBRs96zUTJyzLKHWr9bJlcjl3HbO o4lNXn2xTwJQ8fv6ugBV7gO9kkr6iGd5FjD6fRkj5t5fP9ndtH+QPjE4DbSpCGXNfuKd SJxFuLkHeU+shZ63O5+bEfMNYIf9ZzubfXnC31Tg8qkQQAKF44MJdHYsWTTIEB+oZPaV 0xDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773356454; x=1773961254; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=RahmB0SI0/OXu1AwTitQIvAtW4esW43+GBpFJHtqabU=; b=W/F9jSQI8Zg/H8IHhf6flZ2+U7OyFmt7zaJOyq1ol0rUbmC5LUqVOdwyc1EIQ/Ourc mTsFQu5V8K2lBS/oBGg1eTYkhB0nxyXdGVaQly+cHz5q0StPFWWsR/7p39SzqGNQXvGU JXhqXvnjdALD2NVkHmsPyv/XGQWF7dvyTD7XtwpJuP+gUFxMjQZwecT8rea9M6zT3xTO dzHcWog62cYwdz5FQb5Xan/olnp7WQTkpnQF5hWLclotGph31765mkETOPex2+RQNfRA f8OXtFO3gJeEqo8kngP+toHC8gxTLqYtD2jyVUD/v+gKy87LLUuLam5pJ4xubROUMZkj Wi5Q== X-Forwarded-Encrypted: i=1; AJvYcCXoU/p6dECYhZ2vDzvxl7U4j0BzQhwudhyRzqaJuw5iNH5dK8Qx8bmRlG2a+dI/oqZib5rezksEyXrsbKw=@vger.kernel.org X-Gm-Message-State: AOJu0YxLrpIyxu3WU0Gr79d1EtMpsnj671+2c3tf9U4jxjlcEKzgkLnx 8ORjGa7OXsqx5AhkvPSfi7AE4HXT3mwp+UosCeL/FfavYrH2iO63jVeSuxKfFe30mxf1jg7NSx4 Ea3I1qwVgJjNoEvRCjA== X-Received: from wmoo20.prod.google.com ([2002:a05:600d:114:b0:483:a1ee:5eb8]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:698e:b0:483:1403:c47f with SMTP id 5b1f17b1804b1-485566ca5cdmr17223985e9.6.1773356454305; Thu, 12 Mar 2026 16:00:54 -0700 (PDT) Date: Thu, 12 Mar 2026 23:00:53 +0000 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260312184054.23481-1-objecting@objecting.org> <20260312134531.49c1f9171b4b0bc8352e678d@linux-foundation.org> Message-ID: Subject: Re: [PATCH 1/3] lib/maple_tree: fix potential NULL dereference in mas_pop_node() From: Alice Ryhl To: Josh Law Cc: Andrew Morton , "Liam R . Howlett" , Andrew Ballance , Josh Law , maple-tree@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Thu, Mar 12, 2026 at 08:49:20PM +0000, Josh Law wrote: > 12 Mar 2026 20:45:32 Andrew Morton : >=20 > > On Thu, 12 Mar 2026 18:40:53 +0000 Josh Law wro= te: > > > >> 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_po= p_node(struct ma_state *mas) > >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return NULL; > >> > >> =C2=A0=C2=A0=C2=A0 ret =3D kmem_cache_alloc_from_sheaf(maple_node_cach= e, GFP_NOWAIT, mas->sheaf); > >> +=C2=A0=C2=A0 if (WARN_ON_ONCE(!ret)) > >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 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. >=20 > Well, fair enough, but WARN_ON is equivalent to a "oops! Something > went wrong! We will continue anyway", NOWARN is quite bad for logging > that that went wrong, usually it's BUG_ON that causes said kernel > panics and that, which is a bit overkill, that's why I didn't add it, > and it warns once, then bails, that's why I'm a bit on the iffy side > about adding NOWARN, what's your opinion on this, do you think a > NOWARN is better then warn on once? The WARN_ON option must only be used for conditions that indicate a kernel bug. Memory pressure is not a kernel bug, so WARN_ON is wrong here. In fact, depending on kernel configuration, WARN_ON_ONCE may crash the kernel. Alice