Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70863 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 31864 invoked from network); 23 Dec 2013 14:15:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Dec 2013 14:15:09 -0000 Authentication-Results: pb1.pair.com header.from=tjerk.meesters@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tjerk.meesters@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.51 as permitted sender) X-PHP-List-Original-Sender: tjerk.meesters@gmail.com X-Host-Fingerprint: 209.85.212.51 mail-vb0-f51.google.com Received: from [209.85.212.51] ([209.85.212.51:43450] helo=mail-vb0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 17/79-08405-C6548B25 for ; Mon, 23 Dec 2013 09:15:09 -0500 Received: by mail-vb0-f51.google.com with SMTP id 11so2769841vbe.38 for ; Mon, 23 Dec 2013 06:15:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=0F+OevS/M2jdruExmF7rMq5tqoHNjLNTLspDAj/cF/w=; b=VTvAHpS5Y7cEH+3RuMrz7lRkXrVYUVc/gCywKdPvxBj552NTtV3XZT6AZ98evm61Th 73chHDsmWp8Si+5QZuTT5X/3rYN+Kr1VvTS29Z02GfQH59HPqZTuJNgUNXHwI0zmJOF4 5gNDE7QVzp+czTlFlqW5DTSPxjGsw9Ilr9P7/jilzamxnQ20ok7cQsJTRkZWR8oyaTXx /l4+cpZJ+ohs5Rsh3NNUNUvgf+bNDz1neVFcYujU/lsd8XdZ2Z42EMwJJKhUFB5BbmZ9 uYpL2K1ZOLeo4WtDp10ezPSrr7t4Y5OzXmCbSiEcwcWedbuVmbxGhchtsdMxGEAaY14E BzMg== MIME-Version: 1.0 X-Received: by 10.220.64.69 with SMTP id d5mr13677132vci.11.1387808106325; Mon, 23 Dec 2013 06:15:06 -0800 (PST) Received: by 10.58.128.33 with HTTP; Mon, 23 Dec 2013 06:15:06 -0800 (PST) In-Reply-To: <3EFE191D-2A93-47E9-805D-538950849C96@rouvenwessling.de> References: <3014595E-B155-47F6-AC7B-71083D89525D@rouvenwessling.de> <52B7209C.2040802@ajf.me> <3EFE191D-2A93-47E9-805D-538950849C96@rouvenwessling.de> Date: Mon, 23 Dec 2013 22:15:06 +0800 Message-ID: To: =?ISO-8859-1?Q?Rouven_We=DFling?= Cc: Andrea Faulds , Yasuo Ohgaki , Joe Watkins , List PHP Mailing List Content-Type: multipart/alternative; boundary=089e010d973031dda604ee3441d3 Subject: Re: [PHP-DEV] [RFC] Timing attack safe string comparison function From: tjerk.meesters@gmail.com (Tjerk Meesters) --089e010d973031dda604ee3441d3 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Mon, Dec 23, 2013 at 5:45 PM, Rouven We=DFling wro= te: > Thanks everyone for your feedback, answers inline. > > On 22.12.2013, at 18:25, Andrea Faulds wrote: > > > I note your patch uses C++-style (// foobar) comments. However, > according to the coding standards[0], only C-style (/* foobar */) comment= s > should be used. > > Thanks for the hint, I changed the patch accordingly. > > On 23.12.2013, at 00:55, Yasuo Ohgaki wrote: > > > As you mentioned in code, users should not use when known or user > supplied string > > is null. > > > > How about add E_NOTICE error for that case? > > If user shouldn't then we are better to warn them. > > That's a fair point, but I expect people would in that case just do their > own check of strlen() =3D=3D=3D 0 and error out and nothing is gained. Ma= ybe we > can find a way to not need the check at all. (see next response) > > > Comparison is good since it always does the same operation based on use= r > supplied > > string. (Unless compiler does optimizations that I don't expect) > > Thanks for checking that, the people do the better. > > On 23.12.2013, at 02:26, Tjerk Meesters wrote: > > > On the whole it looks okay. > > > > The special branch for `known_len =3D=3D 0 && user_len !=3D 0` can be a= voided > by doing something like this: > > > > mod_len =3D max(known_len, 1); > > > > And then use `j % mod_len` instead of `j % known_len` to avoid a > division by zero; since `x mod 1` always yields `0` you will always be > comparing against the null byte of the known string. > > This looks like a good approach, but I was under the impression, that PHP > strings aren't guaranteed to have a terminating null byte. Am I mistaken? > Strings are binary safe, but they're still null terminated, as can be seen from the definitions of ZVAL_STRING() and ZVAL_STRINGL(). http://lxr.php.net/xref/PHP_5_6/Zend/zend_API.h#576 > > On 23.12.2013, at 10:09, Joe Watkins wrote: > > > This does not appear to solve any problems, it appears to add > another function, for that function to solve any problems it must be > deployed. > > So the RFC relies on everyone swapping out every security > sensitive string comparison with the new function, which simply will not > happen. > > It's true that adding this function won't magically make any application > safer. The whole point is making it easier for application developers - > especially those not using a huge framework - to use a string comparison > algorithm that - hopefully - many people have reviewed. Also if there's a= n > issue, this will be fixed by the regular PHP updates (or distributions > backports) > > > I'm up for doing something about security, however, this doesn't > actually do that, what it does is add a (generically named) function that > nobody is very likely to deploy, and doesn't fix the vulnerability in > existing code ... which surely has to be the aim of anything targeted at > security - existing code. > > > > Obviously, we cannot really change all string comparisons to use > security sensitive logic, so this isn't something we can really solve > everywhere from the core, some action must be taken by the user ... > > As you mention yourself, we obviously can't force every string comparison > to be time constant. This means there's no "magic bullet" and I think thi= s > is the second best thing to do. > > > It might have more traction if the function were named > password_compare or hash_compare or something similar that gives everyone > the idea that it is not simply a string comparison function but the corre= ct > way to verify in particular passwords/hashes or whatever. I'd be much mor= e > inclined to say that's a good idea, providing a full set of tools for > password related foo. > > I don't care about the name at all (it's mentioned as an open issue in th= e > RFC), it's admittedly the second one that came to my mind (after > str_compare_time_constant which is way too long). hash_compare does sound > pretty good though. > > Best regards > Rouven --=20 -- Tjerk --089e010d973031dda604ee3441d3--