Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5393490rwd; Mon, 12 Jun 2023 04:39:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5FhN/ic6r0ei6iFQRJplRXHVr9+A74gpzBin62QwO0hwLDbSKtDbpuYYBJm3UJgl1dRThq X-Received: by 2002:aa7:d756:0:b0:516:416b:f736 with SMTP id a22-20020aa7d756000000b00516416bf736mr5059570eds.35.1686569941797; Mon, 12 Jun 2023 04:39:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686569941; cv=none; d=google.com; s=arc-20160816; b=ZQ809zkw+V3L7qhMQA0H2S+9VzN4nOWuM05kJ5iVOe8FuxR5sowQ/wsLXmLUbNVarf f9RYWXiAyDS9WesJLdcFDpDvd7HhQuX5G4FtRNZ6sxFMd4ZRhLm9/fabVNleDztbzHCQ ZIZIJekgWgmV4/FXrlzxYF52A54gZ98BlBzrtzQBpCKKKzaM3jlGxTn4LrTBZigNHD41 HBizyVjl+ppszuZn35w0eROvZ9xrJCxKTUd85vp8IaqEhaZ0vAPWfJxuKuPyzRb+ch1H V9vTejmxjz2LmnaFMvUjVKPXoPOyx08rVj14zIH/I8JWq4efebzAB8aquvPD1UU/gRwo J2ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=8SLBrnwbHCvnK+EhlE8eJ/+pq9MyO6Q+aOHOn+73hw8=; b=Q8065ZVsybBGyTLwU8PQNZ6yYC+MPbh3YTlH8S2FbwfikTQHAkTM9AAR2aoVQeWwPu bX4nvUByo9o8rA1VmhZ0mYYjlncdG7YfDkcjnXwruud5mj9Zhm0LZ7daP6wYj3INXiOu w3Hg23iCQUkLS9/DzJQuCsNxjNFSRX0YDngpJ8wrvOSpsd+rtcg+ImaGqRm9/hbPrfuz c2Ye5Rmv/eY+R8Q4xNokJknMwPWRpV35DpReeEs7juvx3BO/eW+PbObJbSKJ1DyWF6tX mdB35Oa4M2WGxFwzAPpCFmstFsbF4NJLQ/Xmbp90Ba5wuyEe61dEe9JVEkVMWdZYkq3p rBVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=I4Jo53At; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id se21-20020a170906ce5500b00977cd6c72b9si4861209ejb.125.2023.06.12.04.38.36; Mon, 12 Jun 2023 04:39:01 -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=@rasmusvillemoes.dk header.s=google header.b=I4Jo53At; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237582AbjFLLFk (ORCPT + 99 others); Mon, 12 Jun 2023 07:05:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238088AbjFLLEy (ORCPT ); Mon, 12 Jun 2023 07:04:54 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 793DB93F8 for ; Mon, 12 Jun 2023 03:53:11 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-51491b87565so7328721a12.1 for ; Mon, 12 Jun 2023 03:53:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; t=1686567190; x=1689159190; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=8SLBrnwbHCvnK+EhlE8eJ/+pq9MyO6Q+aOHOn+73hw8=; b=I4Jo53AtXKUAWujuX6TPrsPzylsWLanXZel9thkXkSIXOVui0kQwzZh7YdgZmor2Jt tf80rFrTpAgnDS6xkg4Y4x6JU6myT/iURXuMuHmCcitBuH5EU/XswWhVMDm6BPH7P2nw YALTxnobGGv+uPJIXW5C/Hq8IwS3T/UAFliuw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686567190; x=1689159190; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8SLBrnwbHCvnK+EhlE8eJ/+pq9MyO6Q+aOHOn+73hw8=; b=QlUQQYY43xy5uRDhwl4a6RLYG1pWyrJqss/c/B/yG5NoVJ7nE06QOp1+64s+5G2HqL CDvD+/EUYsW9ZtFAt56VQ35OCFVnUgrTd9VlVQuCbwxQfgu8EptWZtl/tHjb2ZaEStil Wp3pYh0BR7Iyc0K/bFbvTel7haUHi8gXrIpHj6/HugLP3TbhxiIiBLZ66XcZhG8FXv0q qhQnn95nCgcmI/s9Jg+3LYr75fcqWm7dT07b8uzxs+wHLzIYOO5J42Zpx++fkgHs5L5q UjAmVyFO9/99ebAZbmVx3Jb9J0gZXUlHRXp/bvxsNEB9ubEkC3MkfQv8TtoodU6N0ZLy 7/BQ== X-Gm-Message-State: AC+VfDwrNcQ/hW6SekPcEj/MgY5QRUjKroH8G692X4vpbye3fAp/Lg6v PDFkXP81GSLOeagHpgIgfsV7RA== X-Received: by 2002:aa7:d40e:0:b0:510:8ee2:2b05 with SMTP id z14-20020aa7d40e000000b005108ee22b05mr5081219edq.38.1686567189783; Mon, 12 Jun 2023 03:53:09 -0700 (PDT) Received: from [172.16.11.116] ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id g20-20020aa7c854000000b005169cd0edffsm4876752edt.35.2023.06.12.03.53.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 12 Jun 2023 03:53:09 -0700 (PDT) Message-ID: <96b45245-bdd8-119d-e7a9-44eb36be0f97@rasmusvillemoes.dk> Date: Mon, 12 Jun 2023 12:53:06 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH v3 2/4] vsscanf(): Integer overflow is a conversion failure Content-Language: en-US, da To: Demi Marie Obenour , Hans de Goede , Mauro Carvalho Chehab , Sakari Ailus , Greg Kroah-Hartman , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Lee Jones , Andy Lutomirski , Thomas Gleixner , Vincenzo Frascino , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko Cc: linux-media@vger.kernel.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, Linus Torvalds References: <20230610204044.3653-1-demi@invisiblethingslab.com> <20230610204044.3653-3-demi@invisiblethingslab.com> From: Rasmus Villemoes In-Reply-To: <20230610204044.3653-3-demi@invisiblethingslab.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 10/06/2023 22.40, Demi Marie Obenour wrote: > sscanf() and friends currently ignore integer overflow, but this is a > bad idea. It is much better to detect integer overflow errors and > consider this a conversion failure. Perhaps. And maybe I even agree. But not like this: > while (*fmt) { > /* skip any white space in format */ > @@ -3464,6 +3474,9 @@ int vsscanf(const char *buf, const char *fmt, va_list args) > break; > ++fmt; > > + allow_overflow = *fmt == '!'; > + fmt += (int)allow_overflow; > + You can't do that. Or, at least, you won't be able to actually use %!d anywhere, because the compiler will yell at you: lib/vsprintf.c: In function ‘foobar’: lib/vsprintf.c:3727:26: error: unknown conversion type character ‘!’ in format [-Werror=format=] 3727 | ret = sscanf("12345", "%!d", &val); | ^ So NAK. Also, when you make significant changes to the sscanf implementation, I'd expect the diffstat for the patch series to contain lib/test_scanf.c. Rasmus