git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "brian m. carlson" <sandals@crustytoothpaste.net>
Cc: <git@vger.kernel.org>, Jeff King <peff@peff.net>
Subject: Re: [PATCH] builtin/receive-pack: use constant-time comparison for HMAC value
Date: Thu, 09 Apr 2020 17:21:07 -0700	[thread overview]
Message-ID: <xmqqmu7kkx70.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <xmqqr1wwkxqe.fsf@gitster.c.googlers.com> (Junio C. Hamano's message of "Thu, 09 Apr 2020 17:09:29 -0700")

Junio C Hamano <gitster@pobox.com> writes:

> "brian m. carlson" <sandals@crustytoothpaste.net> 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.

Ooops, sorry, I sent it a bit too soon.

"They are easy to write" is one thing, but there is cost for keeping
two variants of memcmp() and forcing the users to choose which one
to call.  If we were to encourage good practices, what we would
encourage would not be "when in doubt, always use this pessimized
version.", but "analyse the risk, and when there can be a valid
timing analysis threat, use this one."  And to lead by example, we
would *not* be calling it in this codepath.

A patch that adds constant_memequal() *without* calling it from
check_nonce(), because we realize that there is no legitimate threat
that deserves to be protected by a call to it in this codepath,
would be a very good thing to have, in other words, as that does
encourage good practices.

End of "Devil's advocate mode".

It's not like we have audited _other_ codepaths that may benefit by
having this helper, so if we were to add constant_memequal(), let's
do so in a more library-ish place, in wrapper.c perhaps.

Thanks.


  reply	other threads:[~2020-04-10  0:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-09 23:37 [PATCH] builtin/receive-pack: use constant-time comparison for HMAC value brian m. carlson
2020-04-10  0:09 ` Junio C Hamano
2020-04-10  0:21   ` Junio C Hamano [this message]
2020-04-10  0:56   ` brian m. carlson
2020-04-22 10:27 ` SZEDER Gábor
2020-04-22 15:57   ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqmu7kkx70.fsf@gitster.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    --cc=sandals@crustytoothpaste.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).