Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp311041rwp; Wed, 12 Jul 2023 13:47:06 -0700 (PDT) X-Google-Smtp-Source: APBJJlHMXtw7ZFIj1HeRt++h7JB5/XteL+BwlOdJRXujThT1BgjhO/+Tt8HQjGuG2Sq1usWjXrDk X-Received: by 2002:a17:906:2202:b0:993:fe68:569c with SMTP id s2-20020a170906220200b00993fe68569cmr11530518ejs.6.1689194826480; Wed, 12 Jul 2023 13:47:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689194826; cv=none; d=google.com; s=arc-20160816; b=ysJToYFXQBZ/UpuWIOp54bW28QkBj0j2p6NDyXy0JqglyXS7SUpIDBl2j3zR92X1YL HemjaaJRnGZtUaSRXVF5G+19qBHttX/GEXfjDK+QLPiqYnH75uC+MPtGvptrEZ0tJvaG p6Roa4aG7cexRLzfLET6ZNY9nGiGDn0Uj6Z/luh8tBX9Dqqau5U/Nt+CUWVtkpLiK2ed MAuvGvjPr4phZXdAylhhk5EcbH1qx5fJQ2Ds0ZHI+lTnhOHnpomwm0zphUDeTk+IlRjX nnzHmeUEYG+YUUqkjqb0LT1i9C0DK9F7hXdH+U5wFAcaXW5lHnt5eadOLoY95AlfujSd yRcw== 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:date:dkim-signature; bh=IM1dSYo+80BYxXSJlIL/sk/xBjg6Ots+Pol0AVH4Yb0=; fh=X/BRXd2joRtg9XXu90kSrs8q5gqG+P8MNR0iaPNYRzA=; b=K6N9HbbKQlyOPxKxECBwCnYMrnU9eUnICQHQtmgGFLapILoxkn5p4Iphx9QAbBFXx+ KseB1/zrhpItbEecKC1EwnUXTsBtT2VbRSgi6PPVx3V4mlnXA52OFsjzRpsJwTLYx9PJ FedEQ9jm25tqrVLEKlt2nFwt8Gr2Zki9i2kNtw3jjeVTdQTtXLjSE+YuWwdIHHoy4gV7 yHe0UO011pytRJt4jxv4FieI/iwBClOqbyo9mHE/5O3mOUPCLEmaWYofBW49Dv8u3MDu 1UsUSaYC5IDrSSwGNfWcQa7/QwT+bJkHzj9ax3WaXiWG04RThd6y3655ozmhX9n0UXez 9tbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=kN0riAjm; 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=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l15-20020a170906a40f00b0098734429161si5416376ejz.181.2023.07.12.13.46.41; Wed, 12 Jul 2023 13:47:06 -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=@chromium.org header.s=google header.b=kN0riAjm; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230321AbjGLT67 (ORCPT + 99 others); Wed, 12 Jul 2023 15:58:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232504AbjGLT65 (ORCPT ); Wed, 12 Jul 2023 15:58:57 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6D1E1FE4 for ; Wed, 12 Jul 2023 12:58:55 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-666ecf9a0ceso4245038b3a.2 for ; Wed, 12 Jul 2023 12:58:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1689191935; x=1691783935; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=IM1dSYo+80BYxXSJlIL/sk/xBjg6Ots+Pol0AVH4Yb0=; b=kN0riAjmUZltvjS1ZZu/cmL9YDBQwpNyRLMnVeyJUsFYI7J0wzmmClyaLlqoVavvmR HX0aXQxW3ZgAMNfjI5b5Zwx9uGTFHByzmco0yjmVtRRTEK4R9DkGvVDg6OGwrOpdcj56 K19maljE78z0Ngq7vlqpfwfvl2QxEWWBAC8oo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689191935; x=1691783935; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=IM1dSYo+80BYxXSJlIL/sk/xBjg6Ots+Pol0AVH4Yb0=; b=IbCgIXAI7qhgHyW/zXcjkGEcIKfWoEX4FMuhxdX3YGgqWhPRj/Z9LxhH8Xnj2p/dMK kJ4w6+cuxNc1QfeBIBkpVj8CxnzOY610/0Wh/gezJ4c8zsK0NA00JkY9BdvUEyUcUQVg U9bUtJfU38EhP6Ph4InCTr8dTwNAoZhM+VAC/b03aDmh9F0sy9pyxUwmdVIy7J5m75Gk LoXMV8U5ShFf++GGbjk4QEVkWuaqFcj2viy/S+np8KbLyLpatR8b3MikiQ25P8NnNqna oNNrgPXHobAqhOnBrwKB0trtg0HPTnLtj12B2UuFnV+xLWE9t8nEN5OoSGSJMXSP/R6K A6kA== X-Gm-Message-State: ABy/qLZJN566a5cN0zqm9OqKIvyn7+7EMu9KU+/sz/7bV8vfKmJHBxGy mnwn+rSAQBvU+juXXPxhKpCtPg== X-Received: by 2002:a05:6a20:e685:b0:132:c11d:4582 with SMTP id mz5-20020a056a20e68500b00132c11d4582mr2302449pzb.3.1689191935305; Wed, 12 Jul 2023 12:58:55 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id u22-20020aa78396000000b0068285a7f107sm4080729pfm.177.2023.07.12.12.58.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 12:58:54 -0700 (PDT) Date: Wed, 12 Jul 2023 12:58:54 -0700 From: Kees Cook To: Kent Overstreet 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: <202307121248.36919B223@keescook> References: <20230509165657.1735798-1-kent.overstreet@linux.dev> <20230509165657.1735798-30-kent.overstreet@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230509165657.1735798-30-kent.overstreet@linux.dev> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable 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 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. > [...] > @@ -126,8 +126,8 @@ void string_get_size(u64 size, u64 blk_size, const enum string_size_units units, > else > unit = units_str[units][i]; > > - snprintf(buf, len, "%u%s %s", (u32)size, > - tmp, unit); > + return snprintf(buf, len, "%u%s %s", (u32)size, > + tmp, unit); -Kees [1] https://github.com/KSPP/linux/issues/105 -- Kees Cook