From patchwork Sat Jun 10 02:57:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Demi Marie Obenour X-Patchwork-Id: 105884 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1332537vqr; Fri, 9 Jun 2023 20:49:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5hgILguhBmWWRYA5YoL+SWRDPkcQqQEejW7DXk91LOm+ILU7azzEBtMlZIGcf+wxX2LBJ4 X-Received: by 2002:a05:6a00:988:b0:645:834c:f521 with SMTP id u8-20020a056a00098800b00645834cf521mr9730582pfg.17.1686368949305; Fri, 09 Jun 2023 20:49:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686368949; cv=none; d=google.com; s=arc-20160816; b=rb4t+EZgM3qEM2/V1VJ5nClcPL1qyjK8lTyQzxJ368karWk+eGP6l4GM71P6KfpDlz SP1DMm2Uyd0QrOe8gnvCyX2M9lPflGiZoOuqUBrP8pD6wF6VJWgfILlY7lAFTPUL8PaD o7pLxRMqQY3ijVelcDUtW7cUDNZ4wvWvTDMP+VuliZ2yVfHwZ9CKmemE63fkgBQdd8d9 4FLVkWynR4EaDcvvlrLeJxmKB6n9GPx6gk9/ASjQfLJmpAlqtbo+y1I1h/J1i7vBn1wf KIhglZUaocxwd6izAM3Wrmq0UgdGUsOCLUUgCk46ab7iNEWZUHICidBIzK39RK6V1C01 /WZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:feedback-id:dkim-signature :dkim-signature; bh=fqqfREt6el0H4FUtv/UFCMik/ekaqDFx+K8V6xPHXrA=; b=taElAXcP74bR/pkAYR3EQCmqnM3qmTByDoiEUN3DTxEhGmsmX6NtxQca5F7pHrPVr2 Tau72TOOsF8ZxtWEfzlH986hpVM6Z2dVFAyVbsh+SkhvbqaDkxTi1eUbtfzLTsrI/RYU U2ixL79Qu5Drt3OoPEIkUvgzqSuIu2oSfSoilVp8SN+Y7R6iJ9TH4IYnMctJEePN5LDg Ha5sXHX3PxGga8b/cHw37cI06kb20GAkcM4UIl3o6UqZwm5D3qD1GyAWdF+RBlMu6XWE owJHmsyviQwIt2RjY6CCXAB40II+ZJuMcESXglrmVUkmpwyaEVa21QS91avrW6VxJuAV nf+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@invisiblethingslab.com header.s=fm1 header.b="XHmMz2/T"; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=bCkb0S9q; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t189-20020a6381c6000000b005346d98e741si398097pgd.50.2023.06.09.20.48.57; Fri, 09 Jun 2023 20:49:09 -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=@invisiblethingslab.com header.s=fm1 header.b="XHmMz2/T"; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=bCkb0S9q; 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 S230142AbjFJC7e (ORCPT + 99 others); Fri, 9 Jun 2023 22:59:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbjFJC7c (ORCPT ); Fri, 9 Jun 2023 22:59:32 -0400 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B855F3AAC; Fri, 9 Jun 2023 19:59:30 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id E7BC45C019F; Fri, 9 Jun 2023 22:59:29 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Fri, 09 Jun 2023 22:59:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:from:from:in-reply-to :message-id:mime-version:reply-to:sender:subject:subject:to:to; s=fm1; t=1686365969; x=1686452369; bh=fqqfREt6el0H4FUtv/UFCMik/ ekaqDFx+K8V6xPHXrA=; b=XHmMz2/TUW0yymNJduvfAI7TWUn2doI7XIGh3aeMi I9DOUUxXtUb5JpEW4XKybSf1DLiIyxjVOKBlUxJAbvPa9vD/FrysI9DXX6YuZe9q EyBAgoQbm/ddgbTsskP4aTOVq/brmhpYAwII7cZqgveNtm65I6gruAHDHGHmy3Lj IqvkKK1ityrxYmqMlR5xLhHMX1lSjD56PQe0WoayB936GgRCViGp2qSECeLef98L WjHF7grogPlYLGCm4aaN5KA+In9aS5p5RmTJf03XJyhWfNfCmdNtPiYxaV0ofdwy p/4WcorAeRumhBXEOOiz2qW6yVznVvsVLc86K12yw0+Mg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:message-id:mime-version:reply-to:sender :subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1686365969; x=1686452369; bh=f qqfREt6el0H4FUtv/UFCMik/ekaqDFx+K8V6xPHXrA=; b=bCkb0S9qaYw8Fhd54 5wZBtSL6oakDSto/n91eKd2nRtAH3fjbIPrtzAaCpNTNiaHXo7GyJsRq9aJ1Qk9R 4R4N3PbYB1MI8x+1KG0n40mpSuu9AaWPtWnNfsDe+EF5OpPd7JUPOao1gWU0p7+/ ksbXJ8YcliKzdza+3AFj8c/lGWp8AA0xHq/RADyqjWolew1utIAZ9jW1UQxMIAgM p6XhFilcTIrtUjumjzTiDgYe8ePoz05Bcls31udSVFyYyoXOnnlMPwqeWcXWB0Sz y4ECLpJJdNdccFKAMkMV83KhVtQ2Td7i9VXieZ5ZLXPnK7NZEWurQ6vdMIuojKcP yTTbg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgedtledgieegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofggtgfgsehtkeertdertdejnecuhfhrohhmpeffvghmihcu ofgrrhhivgcuqfgsvghnohhurhcuoeguvghmihesihhnvhhishhisghlvghthhhinhhgsh hlrggsrdgtohhmqeenucggtffrrghtthgvrhhnpeekieeljeeutefgieejfffglefhieet veffleefudefjeegleejvdelvdefueffveenucffohhmrghinhepkhgvrhhnvghlrdhorh hgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepuggv mhhisehinhhvihhsihgslhgvthhhihhnghhslhgrsgdrtghomh X-ME-Proxy: Feedback-ID: iac594737:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 9 Jun 2023 22:59:26 -0400 (EDT) From: Demi Marie Obenour To: Dwaipayan Ray , Lukas Bulwahn , Joe Perches , Jonathan Corbet , Federico Vaga , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Lee Jones , Andy Lutomirski , Thomas Gleixner , Vincenzo Frascino , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko , Rasmus Villemoes Cc: Demi Marie Obenour , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Subject: [PATCH 1/4] Rip out simple_strtoll() Date: Fri, 9 Jun 2023 22:57:56 -0400 Message-Id: <20230610025759.1813-1-demi@invisiblethingslab.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE, 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768286007581535608?= X-GMAIL-MSGID: =?utf-8?q?1768286007581535608?= It is not used anywhere but its own unit tests. Signed-off-by: Demi Marie Obenour Reviewed-by: Christoph Hellwig --- Documentation/dev-tools/checkpatch.rst | 9 ++++----- Documentation/process/deprecated.rst | 5 ++--- .../translations/it_IT/process/deprecated.rst | 9 ++++----- .../translations/sp_SP/process/deprecated.rst | 14 +++++++------- include/linux/kstrtox.h | 1 - lib/kstrtox.c | 2 +- lib/test_scanf.c | 10 ---------- lib/vsprintf.c | 14 -------------- 8 files changed, 18 insertions(+), 46 deletions(-) diff --git a/Documentation/dev-tools/checkpatch.rst b/Documentation/dev-tools/checkpatch.rst index c3389c6f38381f038ed5d9a884f2d333a749f8a2..0ae0ca80beb0c0171e8c04306cb5b9ccbc9fa713 100644 --- a/Documentation/dev-tools/checkpatch.rst +++ b/Documentation/dev-tools/checkpatch.rst @@ -290,11 +290,10 @@ API usage See: https://www.kernel.org/doc/html/latest/process/deprecated.html#bug-and-bug-on **CONSIDER_KSTRTO** - The simple_strtol(), simple_strtoll(), simple_strtoul(), and - simple_strtoull() functions explicitly ignore overflows, which - may lead to unexpected results in callers. The respective kstrtol(), - kstrtoll(), kstrtoul(), and kstrtoull() functions tend to be the - correct replacements. + The simple_strtol(), simple_strtoul(), and simple_strtoull() functions + explicitly ignore overflows, which may lead to unexpected results in + callers. The respective kstrtol(), kstrtoll(), kstrtoul(), and kstrtoull() + functions tend to be the correct replacements. See: https://www.kernel.org/doc/html/latest/process/deprecated.html#simple-strtol-simple-strtoll-simple-strtoul-simple-strtoull diff --git a/Documentation/process/deprecated.rst b/Documentation/process/deprecated.rst index f91b8441f2ef70576c5bad079e631e4077eabed6..b2f677eb6d6b12df63003b00960ef27b1656e4c3 100644 --- a/Documentation/process/deprecated.rst +++ b/Documentation/process/deprecated.rst @@ -109,10 +109,9 @@ For more details, also see array3_size() and flex_array_size(), as well as the related check_mul_overflow(), check_add_overflow(), check_sub_overflow(), and check_shl_overflow() family of functions. -simple_strtol(), simple_strtoll(), simple_strtoul(), simple_strtoull() +simple_strtol(), simple_strtoul(), simple_strtoull() ---------------------------------------------------------------------- -The simple_strtol(), simple_strtoll(), -simple_strtoul(), and simple_strtoull() functions +The simple_strtol(), simple_strtoul(), and simple_strtoull() functions explicitly ignore overflows, which may lead to unexpected results in callers. The respective kstrtol(), kstrtoll(), kstrtoul(), and kstrtoull() functions tend to be the diff --git a/Documentation/translations/it_IT/process/deprecated.rst b/Documentation/translations/it_IT/process/deprecated.rst index ba0ed7dc154c95e0e973cb51cc36b95e786079a8..cdc0aa107bce7f4018ad241a02b4f701974e52b4 100644 --- a/Documentation/translations/it_IT/process/deprecated.rst +++ b/Documentation/translations/it_IT/process/deprecated.rst @@ -118,12 +118,11 @@ Per maggiori dettagli fate riferimento a array3_size() e flex_array_size(), ma anche le funzioni della famiglia check_mul_overflow(), check_add_overflow(), check_sub_overflow(), e check_shl_overflow(). -simple_strtol(), simple_strtoll(), simple_strtoul(), simple_strtoull() +simple_strtol(), simple_strtoul(), simple_strtoull() ---------------------------------------------------------------------- -Le funzioni simple_strtol(), simple_strtoll(), -simple_strtoul(), e simple_strtoull() ignorano volutamente -i possibili overflow, e questo può portare il chiamante a generare risultati -inaspettati. Le rispettive funzioni kstrtol(), kstrtoll(), +Le funzioni simple_strtol(), simple_strtoul(), e simple_strtoull() ignorano +volutamente i possibili overflow, e questo può portare il chiamante a generare +risultati inaspettati. Le rispettive funzioni kstrtol(), kstrtoll(), kstrtoul(), e kstrtoull() sono da considerarsi le corrette sostitute; tuttavia va notato che queste richiedono che la stringa sia terminata con il carattere NUL o quello di nuova riga. diff --git a/Documentation/translations/sp_SP/process/deprecated.rst b/Documentation/translations/sp_SP/process/deprecated.rst index d52120e0d75354d0d32c33d631f9f364eba32f82..f0ba93e7188f02ae98a8533e2dfee4c82cf78c5c 100644 --- a/Documentation/translations/sp_SP/process/deprecated.rst +++ b/Documentation/translations/sp_SP/process/deprecated.rst @@ -117,14 +117,14 @@ como también la familia de funciones relacionadas check_mul_overflow(), check_add_overflow(), check_sub_overflow(), y check_shl_overflow(). -simple_strtol(), simple_strtoll(), simple_strtoul(), simple_strtoull() +simple_strtol(), simple_strtoul(), simple_strtoull() ---------------------------------------------------------------------- -Las funciones: simple_strtol(), simple_strtoll(), simple_strtoul(), y -simple_strtoull() explícitamente ignoran los desbordamientos, lo que puede -llevar a resultados inesperados por las funciones que las llaman. Las -funciones respectivas kstrtol(), kstrtoll(), kstrtoul(), y kstrtoull() -tienden a ser reemplazos correctos, aunque nótese que necesitarán que la -cadena de caracteres termine en NUL o en el carácter de línea nueva. +Las funciones: simple_strtol(), simple_strtoul(), y simple_strtoull() +explícitamente ignoran los desbordamientos, lo que puede llevar a +resultados inesperados por las funciones que las llaman. Las funciones +respectivas kstrtol(), kstrtoll(), kstrtoul(), y kstrtoull() tienden a +ser reemplazos correctos, aunque nótese que necesitarán que la cadena de +caracteres termine en NUL o en el carácter de línea nueva. strcpy() diff --git a/include/linux/kstrtox.h b/include/linux/kstrtox.h index 529974e22ea799adf5c07b48d803ac9bfc1f85a4..c3ed0ce20be49fba185937e3fd0f949e7be6f9a4 100644 --- a/include/linux/kstrtox.h +++ b/include/linux/kstrtox.h @@ -145,7 +145,6 @@ static inline int __must_check kstrtos32_from_user(const char __user *s, size_t extern unsigned long simple_strtoul(const char *,char **,unsigned int); extern long simple_strtol(const char *,char **,unsigned int); extern unsigned long long simple_strtoull(const char *,char **,unsigned int); -extern long long simple_strtoll(const char *,char **,unsigned int); static inline int strtobool(const char *s, bool *res) { diff --git a/lib/kstrtox.c b/lib/kstrtox.c index 08c14019841af9df6d1c354b4503ecee4c7a9da0..3397a91e07dbad814bb0f2c93d19761a375bedc5 100644 --- a/lib/kstrtox.c +++ b/lib/kstrtox.c @@ -150,7 +150,7 @@ EXPORT_SYMBOL(kstrtoull); * @res: Where to write the result of the conversion on success. * * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error. - * Preferred over simple_strtoll(). Return code must be checked. + * Return code must be checked. */ noinline int kstrtoll(const char *s, unsigned int base, long long *res) diff --git a/lib/test_scanf.c b/lib/test_scanf.c index b620cf7de503542a98f38c45c76e9043b242746e..73e6e912f39c7746b1aaaf35eeb562c9c2d3fac8 100644 --- a/lib/test_scanf.c +++ b/lib/test_scanf.c @@ -727,15 +727,6 @@ static void __init test_simple_strtoull(void) test_simple_strtoxx(unsigned long long, simple_strtoull, "0x%llx", 0); } -static void __init test_simple_strtoll(void) -{ - test_simple_strtoxx(long long, simple_strtoll, "%lld", 10); - test_simple_strtoxx(long long, simple_strtoll, "%lld", 0); - test_simple_strtoxx(long long, simple_strtoll, "%llx", 16); - test_simple_strtoxx(long long, simple_strtoll, "0x%llx", 16); - test_simple_strtoxx(long long, simple_strtoll, "0x%llx", 0); -} - static void __init test_simple_strtoul(void) { test_simple_strtoxx(unsigned long, simple_strtoul, "%lu", 10); @@ -800,7 +791,6 @@ static void __init selftest(void) test_numbers(); test_simple_strtoull(); - test_simple_strtoll(); test_simple_strtoul(); test_simple_strtol(); diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 40f560959b169b4c4ac6154d658cfe76cfd0c5a6..a60d348efb276d66ca07fe464883408df7fdab97 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -144,20 +144,6 @@ static long long simple_strntoll(const char *cp, size_t max_chars, char **endp, return simple_strntoull(cp, max_chars, endp, base); } -/** - * simple_strtoll - convert a string to a signed long long - * @cp: The start of the string - * @endp: A pointer to the end of the parsed string will be placed here - * @base: The number base to use - * - * This function has caveats. Please use kstrtoll instead. - */ -long long simple_strtoll(const char *cp, char **endp, unsigned int base) -{ - return simple_strntoll(cp, INT_MAX, endp, base); -} -EXPORT_SYMBOL(simple_strtoll); - static noinline_for_stack int skip_atoi(const char **s) { From patchwork Sat Jun 10 02:57:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Demi Marie Obenour X-Patchwork-Id: 105882 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1323205vqr; Fri, 9 Jun 2023 20:14:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4SgB/lE0ndo+ZtmSaEBwLDz6BmNWFRRAv7ftlRw9oqefDs+760R2x7kuuJlCDB8dyQcZx0 X-Received: by 2002:a17:902:ea0e:b0:1b0:3576:c2a9 with SMTP id s14-20020a170902ea0e00b001b03576c2a9mr698193plg.33.1686366882706; Fri, 09 Jun 2023 20:14:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686366882; cv=none; d=google.com; s=arc-20160816; b=mtNkik0KW0pUwLd768LRyiUY9+dcuBEsoBvxutXW1kL9cOOjAhRnGUbGzcYXimBLGr WMNxjeM1YIAaOUlYPVJZPTwZEoMAA5dcRKkXpjuA0FVGA5M58aba5tOcz10A0FAkeAzw yq+Ro6LbvLCtn3CrIdsor+e/po5dpoUoQ23pJY2yTSDM8JVxlJt1LVIEDC3AoMXVrhfi sUi0n26oMsd2/K9CSg07/6StgPmc+KYI3cHAE/PD+TlfRuWD5s+WYD5Tysw5iRSmxpEb gajvpxP/xF3mmIFBQ8s/nblkDvjWH1aOa5fUR91JKQgPDXnhyyQk6HrXmB+0ORDUWlKp jfHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=j0YDtre0//ptA/N4P+hKQMixT1796glMqb4pGlu2kos=; b=sFrIYx2L0HRO9AClBqYaABcspYm4F+OR+ViPuMXcOejSUgpRj0wBihmnYeYRYS/Ezs 98vwrIL/GXGLIzfg+rWE5iDtSsW6lhTOPSR14XO1Ov1q505BdLlTE1q5eVpkMwCcRVd3 jFICX7G037evJWmKYK8A/ZxzJAldING0cyVFF0+P+WnDNKOaOX010oAiSZEpboXVMTKc I38Q9vimjLAXbwXM1D1MB7xdEsMAhzc6sVg+I+auinUzbCkeX15BiEJb0s8HKLN0Cqc/ pkc3cuLB6HT8CTO+aHa0apsMHSkNdhJwBmyXZZ2E6WpA3SKCkxGuOqIiLyg/HpF2K4G4 Mijw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@invisiblethingslab.com header.s=fm1 header.b=m++JwYZh; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=pM89UBlv; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p13-20020a170902ebcd00b001b041591a5fsi3664067plg.459.2023.06.09.20.14.30; Fri, 09 Jun 2023 20:14:42 -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=@invisiblethingslab.com header.s=fm1 header.b=m++JwYZh; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=pM89UBlv; 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 S232693AbjFJC7k (ORCPT + 99 others); Fri, 9 Jun 2023 22:59:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230210AbjFJC7i (ORCPT ); Fri, 9 Jun 2023 22:59:38 -0400 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A76D30D6; Fri, 9 Jun 2023 19:59:36 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id E87D25C01A1; Fri, 9 Jun 2023 22:59:35 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Fri, 09 Jun 2023 22:59:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:cc:content-transfer-encoding :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm1; t=1686365975; x=1686452375; bh=j0YDtre0// ptA/N4P+hKQMixT1796glMqb4pGlu2kos=; b=m++JwYZhL4VFQQOGC4U7artSFR tHnKhyypdzTNFYqmUHkPIQ88g/YldbEc7fTPaqvBJoa6WmId3+Rcib97/knWOkkF Uy0mGW6LAof+uXS8TWAyZ6OyN0F8OZKBLLCxpL0F3xBoQTBCY7u2JrsPdSo9Zkv8 irJTHJcMLzH6Umq1tlaOxVopNjkYNOA8aeRx/EGtKjceOsuk70VpRPpSLFiKdIo0 GmsqXpCNHlvcHodK/kthEToV0s94id0LARIheJ4nZOhXuRTq8YyZjznp+cDTldlD DUywT0TY+w27GQtMwTTC/ZqtXwAxWg+CUoG52uj2Nw3uaU/u1HZZubj3PfPA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1686365975; x= 1686452375; bh=j0YDtre0//ptA/N4P+hKQMixT1796glMqb4pGlu2kos=; b=p M89UBlvVv2Nm/NeszM8jdZ+s549xstoIdFOqnHi6jPL5iTS7vVOfIpQht4W3sEP4 SNxKU0y3QQnIytP+OAE24bUtVwj79W8dtHusLOTM1QDzzOS/Q07dZqTCHES5dXk9 f5zAPa+9Rdcsv8rujbNFjwr/9pB8eczGJCEQSgAD3brahOtIJx0mUoxbTHbCKIJP xqo3zDLQn741Laou6bQ37ioja+eiXnl7jjk0Ntk6g155jjg5j0IAHGem7n4CkK/2 /z1/yh5wnCkp0R7w2gllGN7vkke3pjPzznDh20SbSzBILzubdemkqigbZ3RLKDpB bDz7kuR9oaGKJFuHtWnew== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgedtledgieehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepffgvmhhi ucforghrihgvucfqsggvnhhouhhruceouggvmhhisehinhhvihhsihgslhgvthhhihhngh hslhgrsgdrtghomheqnecuggftrfgrthhtvghrnhepjeffjefggfeugeduvedvjeekgfeh gffhhfffjeetkeelueefffetfffhtdduheetnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepuggvmhhisehinhhvihhsihgslhgvthhhihhnghhs lhgrsgdrtghomh X-ME-Proxy: Feedback-ID: iac594737:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 9 Jun 2023 22:59:34 -0400 (EDT) From: Demi Marie Obenour To: Dwaipayan Ray , Lukas Bulwahn , Joe Perches , Jonathan Corbet , Federico Vaga , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Lee Jones , Andy Lutomirski , Thomas Gleixner , Vincenzo Frascino , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko , Rasmus Villemoes Cc: Demi Marie Obenour , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Subject: [PATCH 2/4] vsscanf(): Return -ERANGE on integer overflow Date: Fri, 9 Jun 2023 22:57:57 -0400 Message-Id: <20230610025759.1813-2-demi@invisiblethingslab.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230610025759.1813-1-demi@invisiblethingslab.com> References: <20230610025759.1813-1-demi@invisiblethingslab.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE, 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768283840090477699?= X-GMAIL-MSGID: =?utf-8?q?1768283840090477699?= Userspace sets errno to ERANGE, but the kernel can't do that. Signed-off-by: Demi Marie Obenour --- include/linux/limits.h | 1 + include/linux/mfd/wl1273-core.h | 3 -- include/vdso/limits.h | 3 ++ lib/vsprintf.c | 80 ++++++++++++++++++++++++--------- 4 files changed, 63 insertions(+), 24 deletions(-) diff --git a/include/linux/limits.h b/include/linux/limits.h index f6bcc936901071f496e3e85bb6e1d93905b12e32..8f7fd85b41fb46e6992d9e5912da00424119227a 100644 --- a/include/linux/limits.h +++ b/include/linux/limits.h @@ -8,6 +8,7 @@ #define SIZE_MAX (~(size_t)0) #define SSIZE_MAX ((ssize_t)(SIZE_MAX >> 1)) +#define SSIZE_MIN (-SSIZE_MAX - 1) #define PHYS_ADDR_MAX (~(phys_addr_t)0) #define U8_MAX ((u8)~0U) diff --git a/include/linux/mfd/wl1273-core.h b/include/linux/mfd/wl1273-core.h index c28cf76d5c31ee1c94a9319a2e2d318bf00283a6..b81a229135ed9f756c749122a8341816031c8311 100644 --- a/include/linux/mfd/wl1273-core.h +++ b/include/linux/mfd/wl1273-core.h @@ -204,9 +204,6 @@ WL1273_IS2_TRI_OPT | \ WL1273_IS2_RATE_48K) -#define SCHAR_MIN (-128) -#define SCHAR_MAX 127 - #define WL1273_FR_EVENT BIT(0) #define WL1273_BL_EVENT BIT(1) #define WL1273_RDS_EVENT BIT(2) diff --git a/include/vdso/limits.h b/include/vdso/limits.h index 0197888ad0e00b2f853d3f25ffa764f61cca7385..0cad0a2490e5efc194d874025eb3e3b846a5c7b4 100644 --- a/include/vdso/limits.h +++ b/include/vdso/limits.h @@ -2,6 +2,9 @@ #ifndef __VDSO_LIMITS_H #define __VDSO_LIMITS_H +#define UCHAR_MAX ((unsigned char)~0U) +#define SCHAR_MAX ((signed char)(UCHAR_MAX >> 1)) +#define SCHAR_MIN ((signed char)(-SCHAR_MAX - 1)) #define USHRT_MAX ((unsigned short)~0U) #define SHRT_MAX ((short)(USHRT_MAX >> 1)) #define SHRT_MIN ((short)(-SHRT_MAX - 1)) diff --git a/lib/vsprintf.c b/lib/vsprintf.c index a60d348efb276d66ca07fe464883408df7fdab97..9846d2385f5b9e8f3945a5664d81047e97cf10d5 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -59,7 +59,7 @@ bool no_hash_pointers __ro_after_init; EXPORT_SYMBOL_GPL(no_hash_pointers); -static noinline unsigned long long simple_strntoull(const char *startp, size_t max_chars, char **endp, unsigned int base) +static noinline unsigned long long simple_strntoull(const char *startp, size_t max_chars, char **endp, unsigned int base, bool *overflow) { const char *cp; unsigned long long result = 0ULL; @@ -71,6 +71,8 @@ static noinline unsigned long long simple_strntoull(const char *startp, size_t m if (prefix_chars < max_chars) { rv = _parse_integer_limit(cp, base, &result, max_chars - prefix_chars); /* FIXME */ + if (overflow) + *overflow = !!(rv & KSTRTOX_OVERFLOW); cp += (rv & ~KSTRTOX_OVERFLOW); } else { /* Field too short for prefix + digit, skip over without converting */ @@ -94,7 +96,7 @@ static noinline unsigned long long simple_strntoull(const char *startp, size_t m noinline unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base) { - return simple_strntoull(cp, INT_MAX, endp, base); + return simple_strntoull(cp, INT_MAX, endp, base, NULL); } EXPORT_SYMBOL(simple_strtoull); @@ -130,18 +132,22 @@ long simple_strtol(const char *cp, char **endp, unsigned int base) EXPORT_SYMBOL(simple_strtol); static long long simple_strntoll(const char *cp, size_t max_chars, char **endp, - unsigned int base) + unsigned int base, bool *overflow) { + unsigned long long minand; + bool negate; + /* * simple_strntoull() safely handles receiving max_chars==0 in the * case cp[0] == '-' && max_chars == 1. * If max_chars == 0 we can drop through and pass it to simple_strntoull() * and the content of *cp is irrelevant. */ - if (*cp == '-' && max_chars > 0) - return -simple_strntoull(cp + 1, max_chars - 1, endp, base); - - return simple_strntoull(cp, max_chars, endp, base); + negate = *cp == '-' && max_chars > 0; + minand = simple_strntoull(cp + negate, max_chars - negate, endp, base, overflow); + if (minand > (unsigned long long)LONG_MAX + negate) + *overflow = true; + return negate ? -minand : minand; } static noinline_for_stack @@ -3427,7 +3433,7 @@ int vsscanf(const char *buf, const char *fmt, va_list args) unsigned long long u; } val; s16 field_width; - bool is_sign; + bool is_sign, overflow; while (*fmt) { /* skip any white space in format */ @@ -3635,45 +3641,77 @@ int vsscanf(const char *buf, const char *fmt, va_list args) if (is_sign) val.s = simple_strntoll(str, field_width >= 0 ? field_width : INT_MAX, - &next, base); + &next, base, &overflow); else val.u = simple_strntoull(str, field_width >= 0 ? field_width : INT_MAX, - &next, base); + &next, base, &overflow); + if (unlikely(overflow)) + return -ERANGE; switch (qualifier) { case 'H': /* that's 'hh' in format */ - if (is_sign) + if (is_sign) { + if (unlikely(val.s < SCHAR_MIN || val.s > SCHAR_MAX)) + return -ERANGE; *va_arg(args, signed char *) = val.s; - else + } else { + if (unlikely(val.u > UCHAR_MAX)) + return -ERANGE; *va_arg(args, unsigned char *) = val.u; + } break; case 'h': - if (is_sign) + if (is_sign) { + if (unlikely(val.s < SHRT_MIN || val.s > SHRT_MAX)) + return -ERANGE; *va_arg(args, short *) = val.s; - else + } else { + if (unlikely(val.u > USHRT_MAX)) + return -ERANGE; *va_arg(args, unsigned short *) = val.u; + } break; case 'l': - if (is_sign) + if (is_sign) { + if (unlikely(val.s < LONG_MIN || val.s > LONG_MAX)) + return -ERANGE; *va_arg(args, long *) = val.s; - else + } else { + if (unlikely(val.u > ULONG_MAX)) + return -ERANGE; *va_arg(args, unsigned long *) = val.u; + } break; case 'L': - if (is_sign) + /* No overflow check needed */ + if (is_sign) { *va_arg(args, long long *) = val.s; - else + } else { *va_arg(args, unsigned long long *) = val.u; + } break; case 'z': - *va_arg(args, size_t *) = val.u; + if (is_sign) { + if (unlikely(val.s < SSIZE_MIN || val.s > SSIZE_MAX)) + return -ERANGE; + *va_arg(args, ssize_t *) = val.s; + } else { + if (unlikely(val.u > SIZE_MAX)) + return -ERANGE; + *va_arg(args, size_t *) = val.u; + } break; default: - if (is_sign) + if (is_sign) { + if (unlikely(val.s < INT_MIN || val.s > INT_MAX)) + return -ERANGE; *va_arg(args, int *) = val.s; - else + } else { + if (unlikely(val.u > UINT_MAX)) + return -ERANGE; *va_arg(args, unsigned int *) = val.u; + } break; } num++; From patchwork Sat Jun 10 02:57:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Demi Marie Obenour X-Patchwork-Id: 105881 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1322747vqr; Fri, 9 Jun 2023 20:13:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5S6XlHfngjMXXG7cI1M31R5Ui5SPlCJt96k9/em7RWHzRSLxSF8DXuK1dOLX3KaOYK/S8T X-Received: by 2002:a17:902:f687:b0:1a6:6fe3:df8d with SMTP id l7-20020a170902f68700b001a66fe3df8dmr996199plg.8.1686366785533; Fri, 09 Jun 2023 20:13:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686366785; cv=none; d=google.com; s=arc-20160816; b=0d26EvTvIP0JXwDSw7ut0kZlTrHZbnfCXXbPcWB2CqJmtrciPXI9JVeQiLo0pj1G6s vIhQkX12/NgbZA9Tdmyg4ehGwrUSn2j7jPc5MlSEvmTBkwmSWOqgD7pETLY+CG06WNOG WBH5C8KxSMfFRyl7tG3t1hXOInm6L7GXz4b65gdYZhB0tzpNcj6B70DgefRS8yItN5MF NeguFC6mMCvkuvwNTc5K+tGxjuHRYAC6BgZ52/IkUEpJ4Prx0IPuXYMh1FWG9R1BLPR/ eGxNvPLtpnmjOBGXzzQDRja3me2AsPlb8ea1HTivTZIS7z6nWORPM6GJnzzjrLp8nkvt POhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=e12eRh5lyvIG/KvFdPXdCrr7zx2xKqvfBfJtwKk/UpE=; b=C3ttjxRBdtcO0xCfbey38PcAMCIZTWrN434xnoDTmpoeBupYD+43808HFSyoYYCnJu ShDWDY5emN1Wx6mIxGWmQ3uCOttl4xs+C0Kf9pzUMm9RA7oA7c+yUJFtV7MBIHyB+z9P jgjOQkTMW8QAMlT42dJMzVU2M0ZSGXKvaBxRVvr3AsUR6jSvobAfZ5SshrWrKDl9kPfC zC35UHZGqIR/1Au1xr+0UFy2XNi47A9Pj2EVtcdOy64PPSrU7+k7zIJhst6cky7XM2Ck /KYZ4uBhUTOgEQHP80TNbh26Rm21ObLlbjO1G9b+7ntgV6SWjvo8b8Oihz0mCTVe+jEh OxgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@invisiblethingslab.com header.s=fm1 header.b=AKQPI0PH; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=G9VxVZvz; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p13-20020a170902ebcd00b001b041591a5fsi3664067plg.459.2023.06.09.20.12.52; Fri, 09 Jun 2023 20:13:05 -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=@invisiblethingslab.com header.s=fm1 header.b=AKQPI0PH; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=G9VxVZvz; 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 S233168AbjFJC7m (ORCPT + 99 others); Fri, 9 Jun 2023 22:59:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232666AbjFJC7k (ORCPT ); Fri, 9 Jun 2023 22:59:40 -0400 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77EC03AAC; Fri, 9 Jun 2023 19:59:39 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id E44D75C01A2; Fri, 9 Jun 2023 22:59:38 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Fri, 09 Jun 2023 22:59:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:cc:content-transfer-encoding :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm1; t=1686365978; x=1686452378; bh=e12eRh5lyv IG/KvFdPXdCrr7zx2xKqvfBfJtwKk/UpE=; b=AKQPI0PHuEOU5fmJQ9qD4WkgYQ aNoiEv1lfrVM0NCY9ewgg8yFu5cfmny1yi8ZTNrtfImDp1pGhuDRkui/TEHC5s+K /xhOVAL5AQHfiqgCeBetpDfYF+GaDlidqVKEsi6C0xbUzHx/PqDUoPV6QFq6aB0C OOg0YoA7t8x2EWeZFwRJG97M00gjgS83Yl6TlolCRF6hGmsfSTI1ujrLvHwJZL0W M+woz3GhEN1YABJ8oG7BW769tXKF258OMnnper1WHFH+X07RwCndRpFuDFfE7T+s n72DZrUVHVYow5+16yXo6hevd822TTGQ2Fdv5qHENyPTDOZPdcvDunwPJiTQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1686365978; x= 1686452378; bh=e12eRh5lyvIG/KvFdPXdCrr7zx2xKqvfBfJtwKk/UpE=; b=G 9VxVZvzIe9D+6jHeneyaWFSJNodZvgGP36tWCCmi9ous9JGq8T+LtFFMVNxNKBVP MresaRrefOqjnUcrB4yiDWx8qfazyFcNbts2DK6HNnEehk882KT2F6Zj8juL1H+F EGMd5nnB1BCD3epAfyfTbNELCE+L5PN2BYKbpdok84A3GH/TGBG0/FjPZPQbfcac IgY9AimP0eNkEX3UHJZealznt+phzF/ZWd7R3S5A0LdrA4WRjrcrpszwDQQEdYgf CHUT3mfooyG1vP/tzzRKIamZBiNqmWCfoaecQR88wlj9ZWEAdZGDmnvVnmHOsYQZ DTk3wKN7CU9rnuuMR4IcA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgedtledgieehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepffgvmhhi ucforghrihgvucfqsggvnhhouhhruceouggvmhhisehinhhvihhsihgslhgvthhhihhngh hslhgrsgdrtghomheqnecuggftrfgrthhtvghrnhepjeffjefggfeugeduvedvjeekgfeh gffhhfffjeetkeelueefffetfffhtdduheetnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepuggvmhhisehinhhvihhsihgslhgvthhhihhnghhs lhgrsgdrtghomh X-ME-Proxy: Feedback-ID: iac594737:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 9 Jun 2023 22:59:37 -0400 (EDT) From: Demi Marie Obenour To: Dwaipayan Ray , Lukas Bulwahn , Joe Perches , Jonathan Corbet , Federico Vaga , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Lee Jones , Andy Lutomirski , Thomas Gleixner , Vincenzo Frascino , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko , Rasmus Villemoes Cc: Demi Marie Obenour , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Subject: [PATCH 3/4] Add strict version of vsscanf() Date: Fri, 9 Jun 2023 22:57:58 -0400 Message-Id: <20230610025759.1813-3-demi@invisiblethingslab.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230610025759.1813-1-demi@invisiblethingslab.com> References: <20230610025759.1813-1-demi@invisiblethingslab.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE, 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768283738337794457?= X-GMAIL-MSGID: =?utf-8?q?1768283738337794457?= Signed-off-by: Demi Marie Obenour --- include/linux/kernel.h | 4 ++++ lib/vsprintf.c | 43 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 0d91e0af01250c1d82f4a2ea562d2619b9cc6e9c..b348b84ce9c4e95031f67e0cbac5de8deca69aac 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -227,8 +227,12 @@ const char *kvasprintf_const(gfp_t gfp, const char *fmt, va_list args); extern __scanf(2, 3) int sscanf(const char *, const char *, ...); +extern __scanf(2, 3) +int sscanf_strict(const char *, const char *, ...); extern __scanf(2, 0) int vsscanf(const char *, const char *, va_list); +extern __scanf(2, 0) +int vsscanf_strict(const char *, const char *, va_list); extern int no_hash_pointers_enable(char *str); diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 9846d2385f5b9e8f3945a5664d81047e97cf10d5..2dae357b367e1da8b1004ed6e85e051a045ca36b 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -3414,6 +3414,8 @@ EXPORT_SYMBOL_GPL(bprintf); #endif /* CONFIG_BINARY_PRINTF */ +static int vsscanf_internal(const char *buf, const char *fmt, va_list args, bool strict); + /** * vsscanf - Unformat a buffer into a list of arguments * @buf: input buffer @@ -3421,6 +3423,23 @@ EXPORT_SYMBOL_GPL(bprintf); * @args: arguments */ int vsscanf(const char *buf, const char *fmt, va_list args) +{ + return vsscanf_internal(buf, fmt, args, false); +} + +/** + * vsscanf_strict - Unformat a buffer into a list of arguments, but + * do not skip spaces. + * @buf: input buffer + * @fmt: format of buffer + * @args: arguments + */ +int vsscanf_strict(const char *buf, const char *fmt, va_list args) +{ + return vsscanf_internal(buf, fmt, args, true); +} + +static int vsscanf_internal(const char *buf, const char *fmt, va_list args, bool strict) { const char *str = buf; char *next; @@ -3530,8 +3549,10 @@ int vsscanf(const char *buf, const char *fmt, va_list args) char *s = (char *)va_arg(args, char *); if (field_width == -1) field_width = SHRT_MAX; - /* first, skip leading white space in buffer */ - str = skip_spaces(str); + if (!strict) { + /* first, skip leading white space in buffer */ + str = skip_spaces(str); + } /* now copy until next white space */ while (*str && !isspace(*str) && field_width--) @@ -3621,7 +3642,8 @@ int vsscanf(const char *buf, const char *fmt, va_list args) /* have some sort of integer conversion. * first, skip white space in buffer. */ - str = skip_spaces(str); + if (!strict) + str = skip_spaces(str); digit = *str; if (is_sign && digit == '-') { @@ -3721,6 +3743,9 @@ int vsscanf(const char *buf, const char *fmt, va_list args) str = next; } + if (strict && *str) + return -EINVAL; + return num; } EXPORT_SYMBOL(vsscanf); @@ -3743,3 +3768,15 @@ int sscanf(const char *buf, const char *fmt, ...) return i; } EXPORT_SYMBOL(sscanf); +int sscanf_strict(const char *buf, const char *fmt, ...) +{ + va_list args; + int i; + + va_start(args, fmt); + i = vsscanf_strict(buf, fmt, args); + va_end(args); + + return i; +} +EXPORT_SYMBOL(sscanf_strict); From patchwork Sat Jun 10 02:57:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Demi Marie Obenour X-Patchwork-Id: 105883 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1325790vqr; Fri, 9 Jun 2023 20:23:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6/nwCZdctQvHjHdB13Qqb1j6imuqJ+STnbR6+RfRxNvtQPeWM/AAuIY+bVO3N1XpKgu74r X-Received: by 2002:a17:906:dac5:b0:974:6335:4239 with SMTP id xi5-20020a170906dac500b0097463354239mr3296207ejb.34.1686367435666; Fri, 09 Jun 2023 20:23:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686367435; cv=none; d=google.com; s=arc-20160816; b=LEqeCwwm0DH4qpb6YH5ggWtvDoyrV5s/STP/jilWwxUQP+yWXBSwhjqn5qM7zhvvdm u8szD5dPAVws/0QBeMBY+YPuanSu+gsr4dKdiZF2rp0bBruVQqCE8nFnZjoErD65eyMI 1cu3NaC3oa+DKm1frLzZpyFfSfpYtOENDs0tP/bCTnTZUTSqwileaGX+xAgMfPIb7psg gHy9L8RKzgJk0QmGtdaBt6jiMkWtHn4KdmCkDR1yCvoa9Z+mZktuTCdrS3FxpBczedTu rH8SDpu4crqrlervz1A+wmltnPNDh0VI+7vqtNyofkt+f7yO5dDv/O7TSlTSCGVrzGLr SNcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=9jx1BPUbfcVgExhjQbchVzVzEh8/1tbELFoG8PhPivY=; b=uisxLitVmNwzffJ2mrWogjgXHK6BjI3kO4A6a8PyJrDx9jTRApB1Yk2HyxUQ5T97QE +dyqyfAdGQFQrlWPG6ZclPgZiNYjtiqmz44c3FfSQ/qWekcst0XFAAeOHXTvBWJmQmOl Uu8CUA3V7b+HLcriRMo/fq7uR1Bnndlvv+S/f8yFMk3HMwLmv1jN+5q1h3qouDK/LP9x GPMPtNUdYGariFltgC1UlDXsHXsjzEE1mGkDHYLCm5CvATIykCXYM9hV8OcRfdYVOikN WR7Cn/M1M55ZVW2/CRiM/d0pmujm0QKIsE1askGN3hdHJxr9TuIpPUlgZ82ikPsXPD2J qwzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@invisiblethingslab.com header.s=fm1 header.b=KzDj4AYY; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=ZvSpafDB; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r9-20020a17090638c900b00978723b8e69si2080845ejd.425.2023.06.09.20.23.30; Fri, 09 Jun 2023 20:23:55 -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=@invisiblethingslab.com header.s=fm1 header.b=KzDj4AYY; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=ZvSpafDB; 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 S233405AbjFJC7q (ORCPT + 99 others); Fri, 9 Jun 2023 22:59:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233051AbjFJC7m (ORCPT ); Fri, 9 Jun 2023 22:59:42 -0400 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F259830D6; Fri, 9 Jun 2023 19:59:41 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 6E1B05C01A3; Fri, 9 Jun 2023 22:59:41 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Fri, 09 Jun 2023 22:59:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:cc:content-transfer-encoding :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm1; t=1686365981; x=1686452381; bh=9jx1BPUbfc VgExhjQbchVzVzEh8/1tbELFoG8PhPivY=; b=KzDj4AYYzePpimX6H5wkYZwkks NHGbQDu8jIRMdcSSSgF3b3PCmK7D2vOotKxA1DfVlTP2e08oG9cNjOaC0kyc2A/A Woeqakefd0epg23qLeX6igy3kxTwzSX6HLFhahqzHc+vqvIKm4sAeWi9aoNSXRR6 wCI5HfGLfst2I2vTH2hIA7ZxZ26JHuWYOCEEPQPqUdH0cH2Rrtx60UFtXGXkXHdo oHHe5NzrKGAz0eOgRzDoxWrkDYMlWiOGDPj/JZbnnXGfaI+2MtyHouaGMcEBMaZV jdSrar5Q0z3nIwuLL3W3Xx2b6XH6XjVb12K0C8yZS0BhFD3XVFZWGvJ79QUg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1686365981; x= 1686452381; bh=9jx1BPUbfcVgExhjQbchVzVzEh8/1tbELFoG8PhPivY=; b=Z vSpafDBLwDL8H2CTo8lfIfv0lBZ6g4SdgNNNWgwt9+71cFO74vFRkfX5OQ0eun+2 V9U7u1FWaanTOidIYHn+FaDRXl+fpQTdsWaByWb8JDChI4RHKW0Er7WreEW70XSH F7ovWDNSgioIcLiDVSE1DlAfe687KvI/kOFQUYI5cJrhQ5FVuqQj+0k+MXIqK2ZF 5YIcEJ5iqfquW6njaZXeLisvjATivHd3InKEgpO6av2xMmSPYJ9xVUx7M/y8yarE v1ZhBTL4ViFGSyXf3rk89tTMCKeP0BpWjJ6L5NGJkGZn6HsrPPsYg/Mr1c8kHU06 REVYBioVQJyWfzr6tnZjw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgedtledgieegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepffgvmhhi ucforghrihgvucfqsggvnhhouhhruceouggvmhhisehinhhvihhsihgslhgvthhhihhngh hslhgrsgdrtghomheqnecuggftrfgrthhtvghrnhepjeffjefggfeugeduvedvjeekgfeh gffhhfffjeetkeelueefffetfffhtdduheetnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepuggvmhhisehinhhvihhsihgslhgvthhhihhnghhs lhgrsgdrtghomh X-ME-Proxy: Feedback-ID: iac594737:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 9 Jun 2023 22:59:40 -0400 (EDT) From: Demi Marie Obenour To: Dwaipayan Ray , Lukas Bulwahn , Joe Perches , Jonathan Corbet , Federico Vaga , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Lee Jones , Andy Lutomirski , Thomas Gleixner , Vincenzo Frascino , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko , Rasmus Villemoes Cc: Demi Marie Obenour , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Subject: [PATCH 4/4] Strict XenStore entry parsing Date: Fri, 9 Jun 2023 22:57:59 -0400 Message-Id: <20230610025759.1813-4-demi@invisiblethingslab.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230610025759.1813-1-demi@invisiblethingslab.com> References: <20230610025759.1813-1-demi@invisiblethingslab.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE, 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768284420301284532?= X-GMAIL-MSGID: =?utf-8?q?1768284420301284532?= This uses the newly-introduced strict version of sscanf(). Signed-off-by: Demi Marie Obenour --- drivers/xen/xenbus/xenbus_xs.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/xen/xenbus/xenbus_xs.c b/drivers/xen/xenbus/xenbus_xs.c index 12e02eb01f5991b31db451cc57037205359b347f..88e94269c9221d16d1a97e59399058e870675729 100644 --- a/drivers/xen/xenbus/xenbus_xs.c +++ b/drivers/xen/xenbus/xenbus_xs.c @@ -569,16 +569,20 @@ int xenbus_scanf(struct xenbus_transaction t, const char *dir, const char *node, const char *fmt, ...) { va_list ap; - int ret; + int ret = 0; + unsigned int len; char *val; - val = xenbus_read(t, dir, node, NULL); + val = xenbus_read(t, dir, node, &len); if (IS_ERR(val)) return PTR_ERR(val); + if (strlen(val) != len) + goto bad; va_start(ap, fmt); - ret = vsscanf(val, fmt, ap); + ret = vsscanf_strict(val, fmt, ap); va_end(ap); +bad: kfree(val); /* Distinctive errno. */ if (ret == 0) @@ -636,15 +640,18 @@ int xenbus_gather(struct xenbus_transaction t, const char *dir, ...) while (ret == 0 && (name = va_arg(ap, char *)) != NULL) { const char *fmt = va_arg(ap, char *); void *result = va_arg(ap, void *); + unsigned len; char *p; - p = xenbus_read(t, dir, name, NULL); + p = xenbus_read(t, dir, name, &len); if (IS_ERR(p)) { ret = PTR_ERR(p); break; } - if (fmt) { - if (sscanf(p, fmt, result) == 0) + if (strlen(p) != len) + ret = -EINVAL; + else if (fmt) { + if (sscanf_strict(p, fmt, result) <= 0) ret = -EINVAL; kfree(p); } else