From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (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 788313B634A for ; Thu, 12 Mar 2026 21:15:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773350104; cv=none; b=ibfKpJXW8IBT59tIToh3dExJepMclgLppIJdqBm9U5gneOSdHy7S91XL5u4nca1hzFeAzy/xzgy1emnaMjZsLxEMHn6S47817Py6YDDpIciUxL6CVuyBZq4bn5Z2qoKB6Fp6iQqZY5NcniwsZ3RHnHqakVvr5I7CiGVM2IAydhA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773350104; c=relaxed/simple; bh=upuRHqFHxionje3foNDE/tZRWHhvJD8JwOgP1S0egAg=; h=Date:From:To:Cc:Message-ID:In-Reply-To:References:Subject: MIME-Version:Content-Type; b=HAaO33qmx2gQRzrbZGHpZP6s+u41VRiJ6i7/nbVaPQtSNKRfVhBXnOqCITxXl2OBcLaez4MbtF6eISVhjvtEMTnQYSqgNW3Ycn6M1An011OzuBuNmEFsZ7K1aR3uCQ23kwAkKsv/K+vrLbTAVt72WoxwIjN37pDxJPMu49CQXN0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=YxjVKVeA; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YxjVKVeA" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-4853c3c2fe7so8160775e9.0 for ; Thu, 12 Mar 2026 14:15:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773350100; x=1773954900; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=upuRHqFHxionje3foNDE/tZRWHhvJD8JwOgP1S0egAg=; b=YxjVKVeAMg+YYtviIgX4efieq5oZOqx32d9iAKM51FeUUXjvqldZTQye3Egjnim4Gk VdyXXPnM4RilR/FNEzumXn1YS3DS61wHIPMoSvqGJvLuIeHFDcLZFOV0n2LKua/MPRHs IzUnVtA6PbAWeRoS/KVrG3YwI5cxKai6oHQc6FJQLPcC0ZAuxB6pfkB42O3M8QrT18K/ RftzhSznux2+YUHxdt9iShbVX5mwox9895P6rVLspeOfh2A1kXVKreQq3k5C/014L9fL uwi88gZjsx4HRNclj1T4IRwO1TXZLDudy3CahKPJOkdtDE4tVmdQth5iJK6rXtoxd9IG NlFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773350100; x=1773954900; h=content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=upuRHqFHxionje3foNDE/tZRWHhvJD8JwOgP1S0egAg=; b=SLO/kBcCzgdXE0045rpTaAK9nJzMDGjzTxPjX2BkdH0xgdGXrJAzItgLGO4yY8hkXN xrzVTDzZWThAQHRim7wHt6cyTiussWM6QFTMZ4Olj8uqWQ3MxFAALHliaGZ8VlcLFBXu FqxhmBB5vwoGxNGTFhuMBCHuqOCkhDmGxAOGmKDd3QydpBRZQqcWV5uM0ZkOcdgzfh5Z 1y8LVuxTf1rs1ympDbqtMotyudRW/A8aTAuZOnb5Sjee7g1xZsJHf2FlnlqpskLKS/89 m7vzGXirMLuJ0iQOUdlXzqTuF3yuObXWzmNvAuoLpBmXKHEMECF6JwcJcwLqycw8c5/4 1FHg== X-Forwarded-Encrypted: i=1; AJvYcCW6+9KyRG/npUisOcz5Z4C4WMTDHVZvtIdigOBu+Jrn8WSQ0qOuUwV0q9Fume2PB0ZlKq45/Yw+qoCbMao=@vger.kernel.org X-Gm-Message-State: AOJu0YxZfzGTCRcyvebJnfh6+Vo4LbtSThd7hc6mY5/QwHLz6r/7sXan w4oLc71hLGOLwQgJug0GSmo/PBBx40E2oNyjPk3ISGhlK0c4u9bbM2dO X-Gm-Gg: ATEYQzx20rJKwQUrGWtCDL4qZ+3YcEAKf2AST2aTnMg3NGrhGZsAKolEW64iHaeGu7n YC1kePoTsiIwjD5Df8IjIQKR6aZJkJX2R+9m9THYuRcvNr5UwCKrvf3JkSUHDrElphco9h0DEc1 z5L76hb1/6ywCaBO5D39MExWotMMI6UFPup5GEhb+6W/Ohd8idzq/m9sFwq6sKioZu4X9+0+VGx RLQtOrlGyPrta9PRePS5Tw+hiig9eOrIf/JcTG9GKTn6e6tnHBkPK/I7SBIZ1f6AGQEEZmtDNdZ 9HysSbPVqc4OCT+S03DOas4V/+Aq94oJg+c0u5h59LYtPG9YyAu1tcBP6PS34uxprSI9hmWKsee xUQQxEo+WSl09DoJCXAqkxWYbZJ3GXnD95rH1eP7oDNLopUDQGmIqq489r/jStMKIKO9poSJX06 goMMxaOvHxpBNv7lG/aMhPMoTbaeF7GQ== X-Received: by 2002:a05:600c:4e08:b0:483:8062:b2f with SMTP id 5b1f17b1804b1-485566ca9b4mr12529245e9.6.1773350099541; Thu, 12 Mar 2026 14:14:59 -0700 (PDT) Received: from [127.0.0.1] ([31.94.74.44]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4854b65fe27sm164501485e9.9.2026.03.12.14.14.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 12 Mar 2026 14:14:59 -0700 (PDT) Date: Thu, 12 Mar 2026 21:14:58 +0000 From: Josh Law To: Andrew Morton Cc: "Liam R . Howlett" , Alice Ryhl , Andrew Ballance , Josh Law , maple-tree@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Message-ID: <2760a688-0c0e-4f6e-b4ea-6d4fe7ecc6cb@gmail.com> In-Reply-To: <14071af4-6886-43ac-8502-5f5c9763cc5b@gmail.com> References: <20260312184054.23481-1-objecting@objecting.org> <20260312134531.49c1f9171b4b0bc8352e678d@linux-foundation.org> <14071af4-6886-43ac-8502-5f5c9763cc5b@gmail.com> Subject: Re: [PATCH 1/3] lib/maple_tree: fix potential NULL dereference in mas_pop_node() 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=UTF-8 Content-Transfer-Encoding: quoted-printable X-Correlation-ID: <2760a688-0c0e-4f6e-b4ea-6d4fe7ecc6cb@gmail.com> 12 Mar 2026 20:56:16 Josh Law : > 12 Mar 2026 20:49:21 Josh Law : > >> 12 Mar 2026 20:45:32 Andrew Morton : >> >>> 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. >> >> 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, wh= ich 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 yo= ur opinion on this, do you think a NOWARN is better then warn on once? >> >> >> V/R >> >> >> >> Josh law > > I checked the callers as you suggested. In lib/maple_tree.c at lines 2352= and 6039, mas_pop_node() is called inside loops where the return value is = used immediately (passed to ma_mnode_ptr or bitwise-ORed) without any NULL = validation. > If kmem_cache_alloc_from_sheaf() fails under GFP_NOWAIT pressure, these c= allers will trigger a kernel panic. Yeah in my opinion I think this may need to be merged.. if you would like I= can add the NOWARN V/R