From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (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 BE25F36683B for ; Fri, 13 Mar 2026 07:17:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773386249; cv=none; b=sJIN/mvdmP5a+upgYYA4Vlh87oQXzUhWPK2vCHmNFk9B+nrhkYObkGTKcy4BHGnHWtF+0V9484ireg4Ub5W/yVbQ+2xzdtKAgJYqlAaGgSNKa6LmwHtO9ZLaWASpS9xO73sqNZ42ElUsLNglqrdBDHgezVJcKPaPIKTCDQ6o6So= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773386249; c=relaxed/simple; bh=UeLGjTj3/SNp/8jfrblTEUJIyAwouu4tbKdrGWTfuik=; h=Date:From:To:Cc:Message-ID:In-Reply-To:References:Subject: MIME-Version:Content-Type; b=jBGZBUIEtMVJBJoveHFy3tLFqHwTP9kyOogeNgk8Z9vW4J/dxgpiU52Al6alX52IAzWvU317/bbkaUjQD05yEgE50BJUVKXW9/McGKJrZw9QzBK5WBQ8Ik8snRSwVxFnVhbZBJCktm+7/iE2D+sDbl4rFRZnHBRme5HmZLB+oFw= 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=jgfyFSOl; arc=none smtp.client-ip=209.85.221.44 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="jgfyFSOl" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-439d8dc4ae4so1957575f8f.2 for ; Fri, 13 Mar 2026 00:17:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773386243; x=1773991043; 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=UeLGjTj3/SNp/8jfrblTEUJIyAwouu4tbKdrGWTfuik=; b=jgfyFSOlEfnjv2D+jWjRR1Ja/w7LZJdHkjk1k2yXQeafRs3OxUhUZkhwM7wS0gWKBS 0DyTP1RTJQI9xWimEnkkGYrlmF0zuspEMFfa4tqHD6IQxasKSrBGF6ydLk5W6WC4Wjo3 /ZjHzQIfXvrz0fxY6OJlqZ0EsK4scnAFgTuvb9hX1tfGFo6z3SqWsrtG7wGxSyTk3puv KSlaaswI20Nsw9YU5PeSUfq/piKbjA9VXw9zPZxsNrVGyL3bje3EcapjXZLBzXMPPw31 ru5LvCk8L8jZp3QZjGOIcB4o4bTNtDOkqOjE5mmno6reKR3OSSgHN5t1uh9zK8NgzwnT TRJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773386243; x=1773991043; 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=UeLGjTj3/SNp/8jfrblTEUJIyAwouu4tbKdrGWTfuik=; b=fmFMDNiALsuryjSqfulRBaFoK9prTDHb7Aw8Y5HLDriwAZZZy5dW/IlmUtB8o/0W5u uc2eRpGfZTlB5aW+76wDQwXbH62ycpWLAAAnQNtwXz3/b87W5atwoTopLDlJ1UcEYIwa eQPPhGGJkwjgqilMwGyeaMFVIw6lho35g9pqYXlVVUNIZgSEPbqE558w6u11Ylq6GV2Y SG38fivfChBokpuJwlBPHw3AHw1wOkG7BLs2nlIu/MVDOQ/sq3iqw8pQ6vD2iZJtTx4U u5oLu3sX/s+p9U/vIsyfC0MMs6CryGcwqoRO5rxdsn5wExzHrQbqTzx+gF358/SyCDuo R6Yw== X-Forwarded-Encrypted: i=1; AJvYcCUYfxcMNBnZu7WvAqvTgA8tz0vwGlzVU/7c8tGnLiDjPNNE13oH3ly+zQLm5q6ItUu6a5y6cch5dYwtrLc=@vger.kernel.org X-Gm-Message-State: AOJu0YyWzb7lH6K2a3LRM0G45AUmPYN06PE/16fhqhdrwZo6QDt6wkTl rPzOBjqvbkKnnl31VyLKpie+ferFFg+klIKfC7x75YgM08SHM/j47Xj3 X-Gm-Gg: ATEYQzycGQ6QwisCBIwRx+l6ks6mwrLH51k0QKwhG91y7G1oN7c/51zzW1kBm8mx+vK 0HOlyX9zO1+wcojHGemj1czDBOvk2ufuEM/O7UnwfkUaR2WpQDX07ijLf/c0bYb7zeu8S6TdPjs U2r56BeVi3Rx9A1KuZsWIygVptIAkuAr4CDALRgM319Cx/xhEeRx+xIeAoFiPAm0CM+ejc7FBpN cBYQDF6lz7dj/q8VbVZcJgrDyJSW6jp7BoYZQ8gWMQzJherHMhrkd6icuk0uxNuc3DKpD8VjOL5 ucH3FbsjXORH1wwKl+GCujejW1XA/G8Vgz+TA0YQ0Qkz8pQQm+5WDhaaCbwBU/BMhOgszhKyWcw /fOwr4aibDszBlPNmbT8uKalc4G9+X865vPceGb2UQGGVDByJNklafXlCHo34XSu6wKZG/I/Ggl HxVxg+Queg9qC07M0m X-Received: by 2002:a05:6000:2482:b0:439:afcd:b629 with SMTP id ffacd0b85a97d-43a04dcbb44mr3955380f8f.55.1773386242867; Fri, 13 Mar 2026 00:17:22 -0700 (PDT) Received: from [127.0.0.1] ([86.1.69.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-439fe19acc6sm15140932f8f.8.2026.03.13.00.17.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 13 Mar 2026 00:17:21 -0700 (PDT) Date: Fri, 13 Mar 2026 07:17:17 +0000 From: Josh Law To: Pedro Falcato Cc: Andrew Morton , "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: 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 23:22:48 Pedro Falcato : > On Thu, Mar 12, 2026 at 01:45:31PM -0700, Andrew Morton wrote: >> On Thu, 12 Mar 2026 18:40:53 +0000 Josh Law wrot= e: >> >>> 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. > > According to my local copy of lib/maple_tree.c: > > mas_pop_node() - Get a previously allocated maple node from the maple sta= te. > > Note the "previously" :) kmem_cache_alloc_from_sheaf() can only fail if y= ou > run out of objects in the sheaf. > > So yeah, this "bug" looks bogus. > > -- > Pedro Hi Pedro, I see the comment regarding 'previously allocated' nodes. However, mas_pop_node() explicitly calls kmem_cache_alloc_from_sheaf() with GFP_NOWAIT. If there is any path=E2=80=94even an unexpected one=E2=80=94whe= re the sheaf is exhausted or the allocator fails, the code immediately performs a memset on the NULL pointer. Even if this is a 'should never happen' scenario, returning NULL is safer than a kernel panic. As Andrew noted, the current structure allows a fall-through directly into a dereference. My patch ensures we handle that edge case safely.