Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp306483rwp; Wed, 12 Jul 2023 13:41:22 -0700 (PDT) X-Google-Smtp-Source: APBJJlE+xJmDnn68MAOXr/evpZKmp6UiLzyZbD4wHpVqSB8aU6zCjzY5GbA0Jcg2uyv8uQdTejG6 X-Received: by 2002:aa7:d842:0:b0:51d:8835:90a1 with SMTP id f2-20020aa7d842000000b0051d883590a1mr17452752eds.30.1689194482633; Wed, 12 Jul 2023 13:41:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689194482; cv=none; d=google.com; s=arc-20160816; b=CoPmvh0bsGxe7EPZBg/MoAURmiQpmoR0zJBHdStlLYwib8xzmqOAZUQ2xJ22a8XFEy vqRahW+9p1Ep9AzFTQ03e7miFeodKzPkjSRPwg0eXZhMTr2ptXr1J2xxR40jhB8ujK/L I6ukkrj+gt7Pe2diYyxlE2qGPiW+Pk8CSXbQDv/i1OP7jRrOQJlVtK8qPlv8oG5Qc7cb Bpq/zbj7Wm0hprq9+7ekhyunFhzCWNU3mMkUlOB51wzEWJ3bEMZrwQwHJyEVkenJVPMI H/Oipqt19SOXbMMnwvpCf6qkoeYIAViwdH9ZohQqnDRjPyY8VFBjWbCz7jaznZZb23dM 3jKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:dkim-signature:date; bh=O9LvR5bBybAqINY/tThhzAwh8w6r/n6f3PKsc23fjQ8=; fh=jj7Exx1G2j+BtVmuqG+29cxdB6KC9LNpaUf38Yun7Kw=; b=Mt9hKrnSycN4PjUIAhqhrqVRrnZ1oBKwRZ4LDkZWgYhBDqlit2B7e4IWNpxNDH3zAf g3030rTlYcDQjyBG6LMwjfzWtTJghP6tuE5sg+mrXETQOkFoU20Nc8kNZKjI2gGolYY1 NW6xApb0WGvLOIn6z28lw666uIVE7ZAsUEOQmXtjQLsY8iU6WKJoyAGV9UAFmi5bbPau KkZufqg8TjpBqssUESbwCd49PQYuVv+3Jc6eObTCFyihJJM/naHgc8aLz/Uu+3YbmCJA zbuPdOfaNcYpe27Ovh0rAfmJjd/N9TovBVNtpvLcOJ8KQg7nAg9/WTIzsbk+SvClLaFI 7fmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=eQcEMMhG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bf11-20020a0564021a4b00b0051df1a854e0si5047108edb.182.2023.07.12.13.40.58; Wed, 12 Jul 2023 13:41:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=eQcEMMhG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232483AbjGLUXQ (ORCPT + 99 others); Wed, 12 Jul 2023 16:23:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230402AbjGLUXP (ORCPT ); Wed, 12 Jul 2023 16:23:15 -0400 Received: from out-36.mta1.migadu.com (out-36.mta1.migadu.com [IPv6:2001:41d0:203:375::24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8835A1FE4 for ; Wed, 12 Jul 2023 13:23:14 -0700 (PDT) Date: Wed, 12 Jul 2023 16:23:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1689193393; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=O9LvR5bBybAqINY/tThhzAwh8w6r/n6f3PKsc23fjQ8=; b=eQcEMMhG+id6up2M5ZTsoYpylJMtAQoLNBS9UQhRhs+YEj3HUY7dRx//Xc7hvzcNI4WR9Z QMJsLUtkB4gqIFtBtOo0m1RurV0C4jUNiGbQCxL0zkzBm6ioFz9qaeczVDlguhzedKzPux erFCPO0y+iUm+lHou0uiAhv7GJ2kR/g= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kent Overstreet To: Kees Cook Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-bcachefs@vger.kernel.org, Kent Overstreet , linux-hardening@vger.kernel.org Subject: Re: [PATCH 29/32] lib/string_helpers: string_get_size() now returns characters wrote Message-ID: <20230712202309.xqtggydzf65p2cd7@moria.home.lan> References: <20230509165657.1735798-1-kent.overstreet@linux.dev> <20230509165657.1735798-30-kent.overstreet@linux.dev> <202307121248.36919B223@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202307121248.36919B223@keescook> X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 12, 2023 at 12:58:54PM -0700, Kees Cook wrote: > On Tue, May 09, 2023 at 12:56:54PM -0400, Kent Overstreet wrote: > > From: Kent Overstreet > > > > printbuf now needs to know the number of characters that would have been > > written if the buffer was too small, like snprintf(); this changes > > string_get_size() to return the the return value of snprintf(). > > Unfortunately, snprintf doesn't return characters written, it return > what it TRIED to write, and can cause a lot of problems[1]. This patch > would be fine with me if the snprintf was also replaced by scnprintf, > which will return the actual string length copied (or 0) *not* including > the trailing %NUL. Anyways, I can't use scnprintf here, printbufs/seq_buf both need the number of characters that would have been written, but I'll update the comment.