From nobody Mon Sep 16 11:51:24 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4X6jtX5dzPz5XGg0; Mon, 16 Sep 2024 11:51:32 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4X6jtW6mH2z4vvb; Mon, 16 Sep 2024 11:51:31 +0000 (UTC) (envelope-from kostikbel@gmail.com) Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=gmail.com (policy=none); spf=softfail (mx1.freebsd.org: 2001:470:d5e7:1::1 is neither permitted nor denied by domain of kostikbel@gmail.com) smtp.mailfrom=kostikbel@gmail.com Received: from tom.home (kib@localhost [127.0.0.1] (may be forged)) by kib.kiev.ua (8.18.1/8.18.1) with ESMTP id 48GBpOt5055696; Mon, 16 Sep 2024 14:51:27 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 48GBpOt5055696 Received: (from kostik@localhost) by tom.home (8.18.1/8.18.1/Submit) id 48GBpOJo055695; Mon, 16 Sep 2024 14:51:24 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 16 Sep 2024 14:51:24 +0300 From: Konstantin Belousov To: Kyle Evans Cc: Robert Clausecker , src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Subject: Re: git: 76c2b331bcd9 - main - lib/libc/amd64/string: add timingsafe_bcmp(3) scalar, baseline implementations Message-ID: References: <202310151931.39FJVIpF088761@gitrepo.freebsd.org> <46ddb4e7-2dfe-4f00-9210-1d482e03ef27@FreeBSD.org> List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <46ddb4e7-2dfe-4f00-9210-1d482e03ef27@FreeBSD.org> X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on tom.home X-Spamd-Bar: - X-Spamd-Result: default: False [-1.38 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_SPAM_SHORT(0.62)[0.623]; MIME_GOOD(-0.10)[text/plain]; DMARC_POLICY_SOFTFAIL(0.10)[gmail.com : No valid SPF, No valid DKIM,none]; ARC_NA(0.00)[]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US]; MIME_TRACE(0.00)[0:+]; MISSING_XM_UA(0.00)[]; FREEMAIL_FROM(0.00)[gmail.com]; TO_DN_SOME(0.00)[]; HAS_XAW(0.00)[]; MLMMJ_DEST(0.00)[dev-commits-src-all@freebsd.org,dev-commits-src-main@freebsd.org]; FREEMAIL_ENVFROM(0.00)[gmail.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; R_DKIM_NA(0.00)[]; R_SPF_SOFTFAIL(0.00)[~all:c]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_TLS_LAST(0.00)[]; RCPT_COUNT_FIVE(0.00)[5] X-Rspamd-Queue-Id: 4X6jtW6mH2z4vvb On Thu, Sep 12, 2024 at 10:14:36AM -0500, Kyle Evans wrote: > On 10/15/23 14:31, Robert Clausecker wrote: > > The branch main has been updated by fuz: > > > > URL: https://cgit.FreeBSD.org/src/commit/?id=76c2b331bcd9f73c5c8c43a06e328fa0c7b8c39a > > > > commit 76c2b331bcd9f73c5c8c43a06e328fa0c7b8c39a > > Author: Robert Clausecker > > AuthorDate: 2023-08-30 15:37:26 +0000 > > Commit: Robert Clausecker > > CommitDate: 2023-10-15 19:19:04 +0000 > > > > lib/libc/amd64/string: add timingsafe_bcmp(3) scalar, baseline implementations > > Very straightforward and similar to memcmp(3). The code has > > been written to use only instructions specified as having > > data operand independent timing by Intel. > > Sponsored by: The FreeBSD Foundation > > Approved by: security (cperciva) > > Differential Revision: https://reviews.freebsd.org/D41673 > > Hi Robert, > > I only just noticed this, but I have to admit that I'm pretty uncomfortable > with the idea of rolling our own timingsafe assembly implementations in > general. > > My main concern is that, e.g., auditing timingsafe_bcmp.S will clearly take > a lot longer than auditing the C counterpart, but also the audit > requirements have gone up for every architecture you want to support that > might be using this from a single simple C implementation to C + however > many architectures end up rolling their own implementation in assembly after > this. > > Are these really used in enough perf-critical context to justify the > additional complexity? Did anyone *actually* verify the constant-time > properties of these implementations? I didn't really find any written > confirmation of that, which I was really hoping for- we should have a much > higher bar for changes like this. Is such audit/ensurance is even possible at all for C implementation? It can be only done against specific version of C compiler, and cannot be extended to other compilers, at least with the current state of C definition. While CPU vendors do provide time-invariant guarantees for ISA. For instance, Intel published a guidance https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/best-practices/data-operand-independent-timing-isa-guidance.html that makes the property part of ISA. I.e. for me it seems that only an assembler version can be timingsafe ATM.