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]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39BB3C83F1A for ; Thu, 17 Jul 2025 23:44:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B10208D0002; Thu, 17 Jul 2025 19:44:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AC0698D0001; Thu, 17 Jul 2025 19:44:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B0178D0002; Thu, 17 Jul 2025 19:44:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 893828D0001 for ; Thu, 17 Jul 2025 19:44:35 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 356DE1A025C for ; Thu, 17 Jul 2025 23:44:35 +0000 (UTC) X-FDA: 83675388510.14.103C85A Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf19.hostedemail.com (Postfix) with ESMTP id 6F7491A0006 for ; Thu, 17 Jul 2025 23:44:33 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=SzfaH+Fh; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf19.hostedemail.com: domain of kees@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=kees@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1752795873; a=rsa-sha256; cv=none; b=WqDOy27NTffYeS2Rw0OjPn6p2/xVVMyA8zyYqydxsrlgSnOtmwRCLceJDIzgsyyfg0rsrZ +Bqsd8MU7IUesfOwvm1WDz0Bm7+XiwYkgz4L+ZDh5ihA5+XCRnBU5OGov45YH7UK7N3vP9 EScFNuFGtEXrrvnTKOFeOnih9C/2OW8= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=SzfaH+Fh; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf19.hostedemail.com: domain of kees@kernel.org designates 172.234.252.31 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=1752795873; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=VjgPfxy/JZnEml13t3c0HaQUwX1qYUBpOmj6F5DrhUM=; b=3xEKbxwnqnqpxVErvsgC7FdZi0ZKxd7aKiiLST5PorKqMPgDAZREnhPxEK6Ir1DDjUWh1C edMChErJseuUo/VIIZbHEVp4Ox7TLYddFn40CwR3lT51H5NZQXyAAz8hw3PSB6rKk3akLU OCcBBT7Q3A4/Kt6KuGEn1GCUvTKbD5o= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 6D81344846; Thu, 17 Jul 2025 23:44:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48199C4CEE3; Thu, 17 Jul 2025 23:44:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1752795872; bh=p+zcJCk2jQCao3tbaNCKX2gTkeKcqcP1LFqr4M5zOWw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=SzfaH+FhFmxrsnixPz4XGiqkapozOWi8ChI7CSEpCZPXUIYgDLoaIe0U5ADzTbQJ7 f1OqUQWtXS1H/Pr2YdLygl9awACVlG0md/OtapEra+hfYKeuBztSV2Ryr5syzFO+Jz o4UqzSAWuhqu62sWGMkoLiQQuo2cfuXvkrxxr6NcECBDf7WjrzrvuejOEt8CsO0VSv cRIhC8TeBImb38mMiUC8+KqWNwkv/slpjN6FvPz6YACfYPzKS7JyX/A73nqxxiNf3f 353JwtjtJggSriJkQRXcu63oXn2G1Icb9B5kCoDHuVXsWo7/hIPFWXRmatT02Q/+2X VHhSRY2NMGoPw== Date: Thu, 17 Jul 2025 16:44:31 -0700 From: Kees Cook To: Martin Uecker Cc: Linus Torvalds , David Laight , Alejandro Colomar , linux-mm@kvack.org, linux-hardening@vger.kernel.org, Christopher Bazley , shadow <~hallyn/shadow@lists.sr.ht>, linux-kernel@vger.kernel.org, Andrew Morton , kasan-dev@googlegroups.com, Dmitry Vyukov , Alexander Potapenko , Marco Elver , Christoph Lameter , David Rientjes , Vlastimil Babka , Roman Gushchin , Harry Yoo , Andrew Clayton , Rasmus Villemoes , Michal Hocko , Al Viro , Sam James , Andrew Pinski Subject: Re: [RFC v5 6/7] sprintf: Add [v]sprintf_array() Message-ID: <202507171640.F649D58897@keescook> References: <04c1e026a67f1609167e834471d0f2fe977d9cb0.1752182685.git.alx@kernel.org> <28c8689c7976b4755c0b5c2937326b0a3627ebf6.camel@gmail.com> <20250711184541.68d770b9@pumpkin> <202507142211.F1E0730A@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Stat-Signature: oax85oz7yf3k71o7fy76c9t8nt3xuxsw X-Rspam-User: X-Rspamd-Queue-Id: 6F7491A0006 X-Rspamd-Server: rspam02 X-HE-Tag: 1752795873-144616 X-HE-Meta: U2FsdGVkX180EesSDfjUbnfEDBiJiOJfMcVMIvYQyIlwQoJ5VEwLhORLS12jxDBS19zDdAhEwyRwpv0U39GbC+t07Jma0duT3YG2w9S6vTtVAxVm39k2c+aliWTU+SC7ZLnIpVvs3oVxwjPvzTRCD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Qn8IXgJhoZl2Soak8xH7GCd6DEeRc0jFaADzoNsEf8jPeslXY3fhVly5Zi2oLGXFOAsPYLrupLVjStL/aBGUY5xY7d9hCpMYW0h5eVyLmy6v10gPBUn1FRpyalgxnCtU39mo7sxzqtfi7K3YMvSPGboFcCLSApBkV/10z5r7m1arceug= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Tue, Jul 15, 2025 at 08:24:29AM +0200, Martin Uecker wrote: > Am Montag, dem 14.07.2025 um 22:19 -0700 schrieb Kees Cook: > > On Fri, Jul 11, 2025 at 10:58:56AM -0700, Linus Torvalds wrote: > > > struct seq_buf s; > > > seq_buf_init(&s, buf, szie); > > > > And because some folks didn't like this "declaration that requires a > > function call", we even added: > > > > DECLARE_SEQ_BUF(s, 32); > > > > to do it in 1 line. :P > > > > I would love to see more string handling replaced with seq_buf. > > Why not have? > > struct seq_buf s = SEQ_BUF(32); > > > So the kernel has safe abstractions, there are just not used enough. Yeah, that should be fine. The trouble is encapsulating the actual buffer itself. But things like spinlocks need initialization too, so it's not too unusual to need a constructor for things living in a struct. If the struct had DECLARE which created 2 variables, then an INIT could just reuse the special name... > The string builder is for safely construcing new strings, the > string view is for safely accessing parts of existing strings. seq_buf doesn't currently have a "view" API, just a "make sure the result is NUL terminated, please enjoy this char *" > Also what I found really convenient and useful in this context > was to have an accessor macro that expose the  buffer as a  > regular array cast to the correct size: > > *( (char(*)[(x)->N]) (x)->data ) > > (put into statement expressions to avoid double evaluation) > > instead of simply returning a char* Yeah, I took a look through your proposed C string library routines. I think it would be pretty nice, but it does feel like it has to go through a lot of hoops when C should have something native. Though to be clear, I'm not saying seq_buf is the answer. :) -- Kees Cook