From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795932301; b=QoQmU5kJrrI4y3/5sSLt44BVnRspEEJs/I9L8sLbw9NW10j96q0wFForkve8Z8O88Old egX3gcQja79PJJjJMui8wHkX3R7RlyvxEjAbinJLNc6lfU/2iXoYx3VMxhXRyiTACWYRq kNcmsm125j/jYI6MUC61N7cAnuRysjZkbsZ9btM022trDWKCNV0smW7B2+hq9am53/dSx S4VFCWh3TNtuuvP6/Agbqi4SlYC9qZ89lYYo/oVHQQkVtyxRLEOJFMJD2e1blrbsy/1V7 M3r+eWJCH2evMA8n06yFGRX5w6buvq0uoUUidDl9GJ0RZOxlX2KeEBJt0nqGHdZXZdQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795932301; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=9URZIJO7+/9ybR+Qn0SsQzxeavWfzyaXeB3sSlkPEQ0=; b=cMkbcsEjvQNsO8gp8bgm+yOIrBBEY1syHnHxmn/PyW2kaKZAUS858igQA45GjFi1SRsc PwVpHoNTy1Z3a0+oID+TcLqc0cGkth0LrYolV9AmB9UPYpEjIJ27JVPPnxNg+LSU9YcWG PCwh9rGYzVpGP5R+ORF7pR3h5iOXcMZq3WAzkpchndBS4CtYv1ga/i0Jr5YqIue1ehslY KKr4hmWcJ4d4loiSMLK4870aNNyR9bpF9oDP6jrTuGsUgZ10LPoXK7ZFVByczTLhakdKG u0T7X0mlP9T/9zG3R9+cp4014d3y3PJFioBvJJYlEWTOC4mblkDLE2TcGt6kemJbriw== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=fJ1p7y4l; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 851FF606A31C; Sun, 29 Nov 2026 06:05:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=fJ1p7y4l Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1795932301; b=bnm31xAnqzAV7OdbbOVV11B64//8nX3nhDPyWRHJAvf5vyiMK3asjpoyyiYfAbVojp/a Q2ZftIXqVKZG6PwR9az4iCHT9MzbgcirNy+mgXRrVqCOoiPeoAznOu6tVrR3I8eCLF3aL /DIbWQvIOmTtNHEtcqPxReTlkUpI0in6v6cWE750aAO/QN9ZwtuyePe9OJF2mkwYLhHX4 dnnwPp6AlmBdqlEtYI62jnaubnn6+NhUiqTU/9f/hDnxwer04IcL5+o5z8EXZgNWHHT7G POzD+XtJU8BX2+3AL53PjRDKMtA9ve7N2Z4oWj1OqFGvdOaabO8h8gahulHhJZOR4BA== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1795932301; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=9URZIJO7+/9ybR+Qn0SsQzxeavWfzyaXeB3sSlkPEQ0=; b=jNgKQjPeKFLIxS1X3CTVEURAqYi68Y0BiP7Bg7gfsWLDjjTDOvB15KvZmqEMyw6X9iUz 6yCjtOnS2Ff2we1hiO+Ce7AviWEyuOwjZP3czzGS0CR8e+9EICB4sbomqpv6vzJHniugu 2H62wtM07uC2GzhHnadEpboWTprzpugWL3+3cn51OMB5jwvB3JsQEhz0g4OXHr+9UJTKv NhCciVXn00gGU9m6alZQz1vhlP+uL9ncIMjg0QmZOGPm9daGD6/N9ERc5MKUa76XWJrNN 7CICGdCEfeo4NuBNswq2L2UyxNy+oH7UsUqqXFCGoBYDnd6jreCsqAKJVaBumJSv2hg== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id 95A1C1F000C1; Sun, 29 Nov 2026 06:04:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795932301; bh=9URZIJO7+/9ybR+Qn0SsQzxeavWfzyaXeB3sSlkPEQ0=; h=From:Date:Subject:To:Cc:Reply-To; b=fJ1p7y4lsbvNbJjwQzU1UqNzx/Q2VppZ1T0c92kgkbMkOMVmWyv7kxvykf+WVgMu+ fbnr5a1UiC60kBO4rkIcNTC1KLqItuGSa1qaRdPTfO8zimZpsz12BULD3Beh9muOxb CcitwLKlyziFzAV4HxZcsJx9/07VhAU9i3mwHvigcGHnJ3cnIpJfCQdSr0CQ92CwxD rL0BQFLPO7Ha3jLTb5UPdzWpjJX79MWQ49UNH0aFFg7XS46PgaZlk4xUpzoOHb2EOp r6qua3aIbQ/de2hujq/lW8LgJrTJgV8q0euUpCQ5ZDcYJR8Yk48pwIx8Ojul1wmkzF 1fYvTssraqJzQ== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id E5D3B4E35A; Sun, 29 Nov 2026 06:04:56 +0000 (UTC) From: Arina Kharlamova via B4 Relay Date: Sun, 29 Nov 2026 10:04:53 +0400 Subject: [PATCH v2] slab: fix the kernel-doc of kmalloc_flex() on counter overflow X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261129-slab-doc-v2-1-666aeac2fcc3@mbzuai.ac.ae> X-B4-Tracking: v=1; b=H4sIAAAAAAAC/22NQQ6CMBBFr0JmbUmnaRBceQ/DokwHGaNgWiAq6 d0F3Lp8yfvvLxA5CEc4ZQsEniXK0K9gDhlQ5/orK/Erg9GmQDRWxbtrlB9IYVlZctp6rQtY9Wf gVl576lL/OE7NjWnc9pvRSRyH8N6/Zty8P9kZFaqqRetbYnuk8vxoPpOT3FHuGOqU0hc+4AULt QAAAA== X-Change-ID: 20261124-slab-doc-1894ca04d006 To: Jonathan Corbet , Shuah Khan , Randy Dunlap , Kees Cook , "Gustavo A. R. Silva" , Vlastimil Babka , Harry Yoo , Hao Li , Christoph Lameter , David Rientjes , Roman Gushchin Cc: workflows@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, linux-mm@kvack.org, Arina Kharlamova X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1795932295; l=4445; i=arina.kharlamova@mbzuai.ac.ae; s=20261123; h=from:subject:message-id; bh=XIKvcz34odH/K3g1Cn7Nbr7etS5HIBTl+aGX9+bQk50=; b=XauT25nQ41EyElYKSwBA+IP2VCWXx2wfz9oe5u2uK1sJmoOxAAdW3gMC1pJsjnqaTRP1UkZKz cKNJ2Xp1JlvAic/BRieacY7uq4kAS8BkP7vCTjkdpqd7AuZJ63RExVJ X-Developer-Key: i=arina.kharlamova@mbzuai.ac.ae; a=ed25519; pk=DzQWwMpUtJvSDuzprqvRdbrC72n4Sq8dW6cq3NRt2Mk= X-Endpoint-Received: by B4 Relay for arina.kharlamova@mbzuai.ac.ae/20261123 with auth_id=1625 X-Original-From: Arina Kharlamova Reply-To: arina.kharlamova@mbzuai.ac.ae Content-Transfer-Encoding: 7bit From: Arina Kharlamova Commit fa5c82f4d2bb ("slab.h: disable completely broken overflow handling in flex allocations") removed the counter overflow check from __alloc_flex(), but the kernel-doc and deprecated.rst still say that the allocation fails if COUNT does not fit in the __counted_by() counter. Update them to match the code. While at it, fix the Returns: line of overflows_flex_counter_type(), where true and false are swapped. Fixes: fa5c82f4d2bb ("slab.h: disable completely broken overflow handling in flex allocations") Signed-off-by: Arina Kharlamova --- Found by checks derived from the spec2patch kernel API specifications, with the help of an AI coding assistant (Claude); I reviewed the analysis and the fix. --- Changes in v2: - Shorten the changelog and the comments (Harry Yoo) - Rebase on slab/for-next - Link to v1: https://patch.msgid.link/20261124-slab-doc-v1-1-9f14dfce47c8@mbzuai.ac.ae --- Documentation/process/deprecated.rst | 7 +++---- include/linux/overflow.h | 5 +++-- include/linux/slab.h | 10 ++++------ 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Documentation/process/deprecated.rst b/Documentation/process/deprecated.rst index 22a5e62c92ea..ea392cf36fb8 100644 --- a/Documentation/process/deprecated.rst +++ b/Documentation/process/deprecated.rst @@ -405,7 +405,6 @@ become, respectively:: __auto_type ptr = kmalloc_obj(struct foo [, gfp] ); The argument gfp is optional, the default value is GFP_KERNEL. -If `ptr->flex_member` is annotated with __counted_by(), the allocation -will automatically fail if `count` is larger than the maximum -representable value that can be stored in the counter member associated -with `flex_member`. +If `ptr->flex_member` is annotated with __counted_by(), the caller must +make sure that `count` fits in the counter member associated with +`flex_member`. diff --git a/include/linux/overflow.h b/include/linux/overflow.h index d0f04436343e..2eb5490c2f2c 100644 --- a/include/linux/overflow.h +++ b/include/linux/overflow.h @@ -566,8 +566,9 @@ static __always_inline size_t __must_check size_sub(size_t minuend, size_t subtr * @FAM: Member name of the FAM within @TYPE. * @COUNT: Value to check against the __counted_by annotated @FAM's counter. * - * 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(), @COUNT is checked + * against size_t. */ #define overflows_flex_counter_type(TYPE, FAM, COUNT) \ (overflows_type(COUNT, typeof_flex_counter(((TYPE *)NULL)->FAM))) diff --git a/include/linux/slab.h b/include/linux/slab.h index ad645967a3ee..5d67144c5a81 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -1092,9 +1092,8 @@ void *kmalloc_nolock(size_t size, gfp_t gfp_flags, int node); * @COUNT: how many @FAM elements to allocate space for. * * Returns: Newly allocated pointer to @TYPE with @COUNT-many trailing - * @FAM elements, or NULL on failure or if @COUNT cannot be represented - * by the member of @TYPE that counts the @FAM elements (annotated via - * __counted_by()). + * @FAM elements, or NULL on failure. @COUNT is not checked against the + * type of the __counted_by() counter of @FAM. */ #define __alloc_flex(KMALLOC, GFP, TYPE, FAM, COUNT) \ ({ \ @@ -1137,9 +1136,8 @@ void *kmalloc_nolock(size_t size, gfp_t gfp_flags, int node); * @...: optional GFP flags for the allocation (GFP_KERNEL when not specified). * * Returns: newly allocated pointer to @VAR_OR_TYPE on success, NULL on - * failure. If @FAM has been annotated with __counted_by(), the allocation - * will immediately fail if @COUNT is larger than what the type of the - * struct's counter variable can represent. + * failure. If @FAM has been annotated with __counted_by(), the caller + * must make sure that @COUNT fits in the struct's counter variable. */ #define kmalloc_flex(VAR_OR_TYPE, FAM, COUNT, ...) \ __alloc_flex(kmalloc, default_gfp(__VA_ARGS__), typeof(VAR_OR_TYPE), FAM, COUNT) --- base-commit: 0b0985aeb9979c5fa5c3b872cecdf97ed4ed2b3e change-id: 20261124-slab-doc-1894ca04d006 Best regards, -- Arina Kharlamova