From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 357E7F55431 for ; Tue, 24 Feb 2026 23:45:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5ACB86B0005; Tue, 24 Feb 2026 18:45:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 55A746B0089; Tue, 24 Feb 2026 18:45:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 43BF96B008A; Tue, 24 Feb 2026 18:45:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 29ABE6B0005 for ; Tue, 24 Feb 2026 18:45:17 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 9BA0E8B1FF for ; Tue, 24 Feb 2026 23:45:16 +0000 (UTC) X-FDA: 84480983832.13.28F98BC Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf11.hostedemail.com (Postfix) with ESMTP id F408940003 for ; Tue, 24 Feb 2026 23:45:14 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="i/UCxPaF"; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf11.hostedemail.com: domain of kees@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=kees@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1771976715; a=rsa-sha256; cv=none; b=emKhVsdsFDgkWqY3FOKtsZ3lo8mphkiPlfU+NX1Lt5RGkcCLepKoyLvZd9N5oexK0kb5ee g5GzQFZR6hdM86wsnQpAvMSf8wNza/b6F/KZmpB0IRtR2ziv0Tq/efT1l09PHKrx4kxGP/ MUaoHCY0QH+pdapKuyGwJNjv3Sb2f+g= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="i/UCxPaF"; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf11.hostedemail.com: domain of kees@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=kees@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1771976715; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ezX10oK5/u+NTgYSFdiQ6Hdd1Z6R4dOgw7jwXcbCAZ4=; b=AYUQ7c9Xrn3GhDjo8pDITWC/wK2jIHFBCtcDPTCDPOlL/9YZTFAo2FsnVqw5/dZkwxylQa VF5axR4C6dKRp1vcleaqbRqkVaJE5I5KJAVDrfawYWh8im3GkJtn1eHyj/JmLxzlhfRy3C Q8kLUHhF4yTq6Gzwrma+46Ykfnw2dAw= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id 44E6860053; Tue, 24 Feb 2026 23:45:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E2756C116D0; Tue, 24 Feb 2026 23:45:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1771976714; bh=5uvJhF5LDkPTld+1CeJL8wog5w0F76/q9pZPlIbrTVo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=i/UCxPaFsPqa+xdPI+yB+vtq/dghbqe5ao7qw2QhsssZyTjiJFZoRDeDg0C+V+F6D btqHA6Ce0RsaFpsCG0phcfSDCWCGHEtDFifDJ/fGz9vUe9gQb85sktY/zDkOUPRBTy lbVlB+mAMllViQm2yDW0sYPLNKChX2FtIXxjXvIByDit8prF0wE8RrNrSPE9aDHfgE /YkMvY/DRKm4lF/LlPMBpgYCpc9dabq0AC3SjzEkhdpBRp5qYxa87cFPqpyTwx4z0d AL8uxuu9jRkVzCPb3IiX2g9AHxWa9hGVNE1d39cKrtH4CXqWb6u3ZcbXuDyWwQtmbo IitiGV/DnD/+A== Date: Tue, 24 Feb 2026 15:45:13 -0800 From: Kees Cook To: Lorenzo Stoakes Cc: Vlastimil Babka , Jonathan Corbet , Andrew Morton , Christoph Lameter , David Rientjes , Roman Gushchin , Harry Yoo , "Gustavo A. R. Silva" , workflows@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-hardening@vger.kernel.org, Linus Torvalds , Randy Dunlap , Miguel Ojeda , Przemek Kitszel , Matthew Wilcox , John Hubbard , Joe Perches , Christoph Lameter , Marco Elver , Vegard Nossum , Pekka Enberg , Joonsoo Kim , Bill Wendling , Justin Stitt , Jann Horn , Greg Kroah-Hartman , Sasha Levin , Nathan Chancellor , Peter Zijlstra , Nick Desaulniers , Jakub Kicinski , Yafang Shao , Tony Ambardar , Alexander Lobakin , Jan Hendrik Farr , Alexander Potapenko , linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH v6 4/5] slab: Introduce kmalloc_flex() and family Message-ID: <202602241541.65DBBD8CB@keescook> References: <20251203233029.it.641-kees@kernel.org> <20251203233036.3212363-4-kees@kernel.org> <675ec547-dac8-465f-b3c9-a0f97c5bdef7@lucifer.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <675ec547-dac8-465f-b3c9-a0f97c5bdef7@lucifer.local> X-Stat-Signature: korjnst49c7as7ceha1qpwnii54nm4uw X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-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Nonhyqpu4jvOYUEbltINhqs/mSMjIDkxOh8TzpwlEHTuS2Ntx3J91wlySOJqniG5yntjwRiNzf4Lw7BpNcAVPaxC6kQP4/ZHX4dMViv6QnuDPavFCnIzy0AOBXcLUpcbPBInR1fy8EVQQUmklZR8l9bfzS3qLMB3loBV/ptempB4h1HM8rh79EVcxoM59R4eRUV3S28Wx4EI/fFItTURL4PpX8eKcvvEWVPhkb4HB/MTVywAYiWmqsu07Ix2ekWqwl3LUh66MxIKVkVue0BaUEIDJejYSBVcCGTFsRAirf/TRRLmcapiNDwlG9llZ3wG3EKkWLEg== Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Tue, Feb 24, 2026 at 10:26:36AM +0000, Lorenzo Stoakes wrote: > Annnd now I typed that I realise that Linus fixed this up in mainline and I was > working with a stale version of this file :)) > > Anyway, I see that the comment isn't fixed up, so I think that's something we > should patch, like: > > * Returns: true if @COUNT can be represented in the @FAM's counter. When > * @FAM is not annotated with __counted_by(), always returns true. > > -> > > * Returns: true if @COUNT cannot be represented in the @FAM's counter. When > * @FAM is not annotated with __counted_by(), always returns false. Yeah, I'm working on fixing this up correctly. I think Linux is right that we need to put the overflow checking entirely within the counter setting. That way the checks will only happen for the cases where counted_by is actually in use. I am, however, still pondering that the size check (as I _intended_ it, not as it actually manifested), would catch negative sizes (i.e. negative can't be represented in a size_t -- the default type when the counter type is unknown) and refuse to allocate, though honestly the allocator would probably also refuse to allocate them since they would be very very large when cast back to size_t for the allocation itself. -- Kees Cook