From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 7819D347503 for ; Thu, 12 Mar 2026 20:49:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773348564; cv=none; b=V8arQ6TmGfUr172/mqSwTCvB4kFCvn9hLtHtATySN5YGYp+6ukzDMjD0m8F40VCeyMHA+xiISP23Fc4w2nwUlNrdN3whYpkWbhkVP5fCU2+wJfujDomeIS00jzjJYt+dadjx3yysjwH0PlszfqhM/UB5jSb5JvL6WSpwoqJliO8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773348564; c=relaxed/simple; bh=lcxaHBH06BievOHzyx1+73CNXFI2tJTwpc5M6kHZ1Mc=; h=Date:From:To:Cc:Message-ID:In-Reply-To:References:Subject: MIME-Version:Content-Type; b=nRxednclJ4eRbYBI1VtWJbJxD0xLa51xvQxjDMt59W1pnT1PA4TwL5w4zM9M8pWG4LRAQcdRJIzCH/OAoj46t4Bv6Z4t3570dectrdUe7lkrnIgxvRrITWjIsJSYCWrNjlOmFkVQIPozaMfhjiPMRpRUWcwONQq8FiLmmWOFuWg= 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=O3Vnxdyp; arc=none smtp.client-ip=209.85.128.42 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="O3Vnxdyp" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-48539cbb7b1so8319685e9.3 for ; Thu, 12 Mar 2026 13:49:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773348562; x=1773953362; 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=lcxaHBH06BievOHzyx1+73CNXFI2tJTwpc5M6kHZ1Mc=; b=O3VnxdypGCMlr9VBMqvocni1x8s8k3IK8wswWsU8B+OlpHdSuEU7zJe97KunbZyCJj KK27KHZpD7Q0FJdK4ZuGlMAHmCwY9eyfXj8KUUqcJHmEh7VguuM1iZclhV/kzyd5MBZw TZ/4pOy5vY/vZktfq1U4EkYtvJo3yZySEyriW3xOIkkX4R982LfzniBj4iH8gG8hwvWw xTt+/LxlhLC5wIy52SUa8aDuIdTAswSOByYDsQgBLZ6WTRs7ma+hzUqypxBms0T2atsT qnaTQv8EjONn+EWN4LkmASOZyNh0Gdm5TmmiJKlbat0WLI6qBfnzBp5CIjrgctwsjmc/ jJ+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773348562; x=1773953362; 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=lcxaHBH06BievOHzyx1+73CNXFI2tJTwpc5M6kHZ1Mc=; b=QXHbDKRQURqaibobyy199cU192T7kQlUs/7oi2m5WTHIdLOjk50e1VlWpX+q8ERDFJ eksYTr3GL1dsyJRdeQl85PGi5ogfZWJW32nYDEKCb8l9/e8owp+SLr3IG26clASIzBLf O9HXzlVP7XtBcHMDVg9kiYz4ayC2lRlr7UocnpSAh/Jh1jRQHvG7+BcIZUvir4bI2XwC OfQqyxzcv04xtESgJLwoUDaIzuDPoSY6xxUtu8f86Xp75GAbQotLKrzcYf8SgVr+RimK LgTv7zp6r3CCqjMl2ogVVMwYN6l3EuqSKfljYYll5zv7K0ChwRS+ApRX6IJiAiaJRDs/ OaZg== X-Forwarded-Encrypted: i=1; AJvYcCV97pK9ILoLuUkj915zrN98dPup0FSFs4pB9CFRptHTz6WtOZkaOwyHEuV/WnOXVZ26ohwb+IzVZGxuTH0=@vger.kernel.org X-Gm-Message-State: AOJu0YyY4nHOL30eUscHD3ahlO1bxcTTcjhUT94Nfx1QnQ3HenoJ6SAt i976i6Kub7pTdayD0jKRF+l34jSCdTt1MUtKc/CPC1SsKAA9ELCtZWv9 X-Gm-Gg: ATEYQzxv9/kbkp+CyNXt5pM4Dl7/I8PGKk5rinEr9L0qCNOV9gBnGjWtOCs2WIP4meQ mtxnnn4zuEwZu5z346d6QPtOyT4Bp8xvd0UO8QL18LQhUGj9p1mq9ddq3B/ZfZ5bYGIlOQSBUue IKF6Gw9anKeHSK8cULxMrnwUcVkdTskUt80YCJRVlVXJU+iNEJaqN0BXlX+TMl+3rbIuEIsJPyS aLJzW+GnRkcT/FnBS/A3oYnC8e4ZO+9ueJpCuXSckdDuHnydQFjeXJQbSasZQOzX2iFP+7vL8NL bUo593rL4RNoUSOP+XoxHVsGnkjOP5LnLsWlsWyMtF6VthtKWhMI+XVhvZaNubCMCmfuFGKmZfV Hg8xpynqvU2T38JQ/WKy26fG5iVFSO0hnyyjSzeLqYFIY4o6EWfhkGLzu+k//6xHSE9fWczTWXf rjhtTTOQUhiG2oyEXQg3Q0OGf+gQ== X-Received: by 2002:a05:600c:46d2:b0:485:3a03:ced1 with SMTP id 5b1f17b1804b1-4855672737fmr12323915e9.28.1773348561566; Thu, 12 Mar 2026 13:49:21 -0700 (PDT) Received: from ?IPv6:::1? ([2a00:23ee:2968:90cb:1c6d:1979:bcad:501a]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4855778d268sm3646795e9.8.2026.03.12.13.49.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 12 Mar 2026 13:49:21 -0700 (PDT) Date: Thu, 12 Mar 2026 20:49:20 +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: In-Reply-To: <20260312134531.49c1f9171b4b0bc8352e678d@linux-foundation.org> References: <20260312184054.23481-1-objecting@objecting.org> <20260312134531.49c1f9171b4b0bc8352e678d@linux-foundation.org> 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: 12 Mar 2026 20:45:32 Andrew Morton : > 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) >> =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_cache,= 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 wro= ng! We will continue anyway", NOWARN is quite bad for logging that that wen= t 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 bai= ls, 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? V/R Josh law