Bug 226294 - Use timingsafe_bcmp() in WTF::constantTimeMemcmp() when available
Summary: Use timingsafe_bcmp() in WTF::constantTimeMemcmp() when available
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-05-26 14:26 PDT by Chris Dumez
Modified: 2021-05-30 09:57 PDT (History)
8 users (show)

See Also:


Attachments
Patch (1.79 KB, patch)
2021-05-26 14:28 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (2.54 KB, patch)
2021-05-26 18:01 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2021-05-26 14:26:50 PDT
Use timingsafe_bcmp() in WTF::constantTimeMemcmp() when available, instead of our own custom implementation.
Comment 1 Chris Dumez 2021-05-26 14:28:28 PDT
Created attachment 429795 [details]
Patch
Comment 2 Alex Christensen 2021-05-26 16:47:12 PDT
Comment on attachment 429795 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=429795&action=review

> Source/WTF/wtf/CryptographicUtilities.cpp:36
> +    return timingsafe_bcmp(voidA, voidB, length);

Why not timingsafe_memcmp, or should we rename constantTimeMemcmp to constantTimeBCmp?
Comment 3 Chris Dumez 2021-05-26 16:50:25 PDT
(In reply to Alex Christensen from comment #2)
> Comment on attachment 429795 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=429795&action=review
> 
> > Source/WTF/wtf/CryptographicUtilities.cpp:36
> > +    return timingsafe_bcmp(voidA, voidB, length);
> 
> Why not timingsafe_memcmp, or should we rename constantTimeMemcmp to
> constantTimeBCmp?

I didn't choose how the system API is called :) No, I cannot rename the system API to timingsafe_memcmp. We could rename the WTF:: constantTimeMemcmp to match BSD's naming but I personally prefer the memcmp naming.
Comment 4 Alex Christensen 2021-05-26 17:02:57 PDT
Comment on attachment 429795 [details]
Patch

Oh, I was looking at the bsd documentation, which has both.
memcmp implies a directional return value that can be used in sorting, but this doesn't have that property.  Our use only checks whether it's zero, though, so it's fine so far.
Comment 5 Alexey Proskuryakov 2021-05-26 17:26:59 PDT
Comment on attachment 429795 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=429795&action=review

> Source/WTF/wtf/CryptographicUtilities.cpp:33
>  NEVER_INLINE int constantTimeMemcmp(const void* voidA, const void* voidB, size_t length)

This wrapper that's in a different dylib and forces no inlining is slightly wasteful when calling the system API. Perhaps implement the system API path in the header?
Comment 6 EWS 2021-05-26 17:39:13 PDT
Committed r278140 (238185@main): <https://commits.webkit.org/238185@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 429795 [details].
Comment 7 Radar WebKit Bug Importer 2021-05-26 17:40:17 PDT
<rdar://problem/78542643>
Comment 8 Chris Dumez 2021-05-26 17:56:06 PDT
(In reply to Alexey Proskuryakov from comment #5)
> Comment on attachment 429795 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=429795&action=review
> 
> > Source/WTF/wtf/CryptographicUtilities.cpp:33
> >  NEVER_INLINE int constantTimeMemcmp(const void* voidA, const void* voidB, size_t length)
> 
> This wrapper that's in a different dylib and forces no inlining is slightly
> wasteful when calling the system API. Perhaps implement the system API path
> in the header?

Sure, I can do that. I actually had hesitated to do that. I'll follow-up.
Comment 9 Chris Dumez 2021-05-26 18:01:44 PDT
Reopening to attach new patch.
Comment 10 Chris Dumez 2021-05-26 18:01:45 PDT
Created attachment 429821 [details]
Patch
Comment 11 EWS 2021-05-26 18:49:02 PDT
Committed r278144 (238188@main): <https://commits.webkit.org/238188@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 429821 [details].
Comment 12 Sam Weinig 2021-05-28 17:50:13 PDT
This should probably use a new HAVE macro.
Comment 13 Chris Dumez 2021-05-28 17:51:15 PDT
(In reply to Sam Weinig from comment #12)
> This should probably use a new HAVE macro.

It's there, don't you see it? http://trac.webkit.org/r278178 :D
Comment 14 Sam Weinig 2021-05-30 09:57:07 PDT
(In reply to Chris Dumez from comment #13)
> (In reply to Sam Weinig from comment #12)
> > This should probably use a new HAVE macro.
> 
> It's there, don't you see it? http://trac.webkit.org/r278178 :D

Great!