From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-4.0 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id 1421C1F5AD for ; Fri, 10 Apr 2020 00:09:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727221AbgDJAJc (ORCPT ); Thu, 9 Apr 2020 20:09:32 -0400 Received: from pb-smtp1.pobox.com ([64.147.108.70]:55105 "EHLO pb-smtp1.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726916AbgDJAJc (ORCPT ); Thu, 9 Apr 2020 20:09:32 -0400 Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id BE11841C88; Thu, 9 Apr 2020 20:09:30 -0400 (EDT) (envelope-from junio@pobox.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=vcLvjeIF9Ic3CmUPqYjKZljrGDU=; b=iMY3UN /miByVsjgo6rSO7KT0x2L81C6QV5vkTPsQkKpMTEPRgoOL9tdffSeJViDaREMcv2 0bw8tUT+uBjgQBDGwDKw7ViOdjp7vQq/WjGceMwd2bjDBt9qzokwbd6Me/OOXW/6 NZ7ZFGVLd9CxLcX+tK+q/vmQUTbC/aTHnOxdk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=sasl; b=HSbJg4eX40VRL9CM/OHiurL/RIiW5yrv gWIK+r4CqacuzI3F6ocX75AgupZOxjQ+pYEb5qufKC+O+uLnDUM8H8lMNlCNLatz hht4LBwKlXJDXEggcPg/Gc1hofZEEnTq5osh7/izAMDn9dfAQRK4GP9ZmlhF5is9 JiSJK3jGn/8= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id B64AD41C87; Thu, 9 Apr 2020 20:09:30 -0400 (EDT) (envelope-from junio@pobox.com) Received: from pobox.com (unknown [34.74.119.39]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id 4246541C86; Thu, 9 Apr 2020 20:09:30 -0400 (EDT) (envelope-from junio@pobox.com) From: Junio C Hamano To: "brian m. carlson" Cc: , Jeff King Subject: Re: [PATCH] builtin/receive-pack: use constant-time comparison for HMAC value References: <20200409233730.680612-1-sandals@crustytoothpaste.net> Date: Thu, 09 Apr 2020 17:09:29 -0700 In-Reply-To: <20200409233730.680612-1-sandals@crustytoothpaste.net> (brian m. carlson's message of "Thu, 9 Apr 2020 23:37:30 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Pobox-Relay-ID: 8C81D046-7ABF-11EA-A47D-C28CBED8090B-77302942!pb-smtp1.pobox.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org "brian m. carlson" writes: > When we're comparing a push cert nonce, we currently do so using strcmp. > Most implementations of strcmp short-circuit and exit as soon as they > know whether two values are equal. This, however, is a problem when > we're comparing the output of HMAC, as it leaks information in the time > taken about how much of the two values match if they do indeed differ. > > In our case, the nonce is used to prevent replay attacks against our > server via the embedded timestamp and replay attacks using requests from > a different server via the HMAC. Push certs, which contain the nonces, > are signed, so an attacker cannot tamper with the nonces without > breaking validation of the signature. They can, of course, create their > own signatures with invalid nonces, but they can also create their own > signatures with valid nonces, so there's nothing to be gained. Thus, > there is no security problem. > > Even though it doesn't appear that there are any negative consequences > from the current technique, for safety and to encourage good practices, > let's use a constant time comparison function for nonce verification. > POSIX does not provide one, but they are easy to write. Devil's advocate mode on. If the HMAC plus digital signature are the real security, even though writing this patch may be a nice mental exercise, is there a merit in deliberately adding more code and making the code immesurably slower by applying it? You just established in the previous paragraph that "for safety" is a red herring.