From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752182AbbJEQL1 (ORCPT ); Mon, 5 Oct 2015 12:11:27 -0400 Received: from mail-wi0-f175.google.com ([209.85.212.175]:34384 "EHLO mail-wi0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751379AbbJEQL0 (ORCPT ); Mon, 5 Oct 2015 12:11:26 -0400 Date: Mon, 5 Oct 2015 18:11:22 +0200 From: Ingo Molnar To: Alexey Dobriyan Cc: cmetcalf@ezchip.com, Linux Kernel , Linus Torvalds , Peter Zijlstra , Thomas Gleixner , "H. Peter Anvin" , Borislav Petkov Subject: Re: [PATCH] string: Improve the generic strlcpy() implementation Message-ID: <20151005161121.GA10776@gmail.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Alexey Dobriyan wrote: > I want to say two things: > > 1) strlcpy race > > > * In addition, the implementation is robust to the string changing out > > * from underneath it, unlike the current strlcpy() implementation. > > Canonical OpenBSD version does byte-by-byte copying, > this race is purely Linux invention. > > 2) strscpy() will copy garbage past NUL from source into destination. > It won't fault but still, who knows what lies after string. So I think your argument is nonsense on several levels: 1) In 99% of the cases the source string access is not racy so the point is moot. 2) In the remaining 1% of cases, where the source string might indeed be modified in a racy fashion, the only result is that we might get some harmless copy of the end of the string _that we would have copied had we been a bit faster_. I.e. it's violently not 'garbage' - it's portion of a valid string that was valid literally a few cycles ago. It's not uninitialized data and it's not data of something we should never have gotten access to. 3) The strscpy() based Linux variant suggested by Linus (for which I sent the patch) does not have that small (and harmless) race and is much faster than the OpenBSD implementation. Thanks, Ingo