From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934546AbbJIJKp (ORCPT ); Fri, 9 Oct 2015 05:10:45 -0400 Received: from mail-lb0-f182.google.com ([209.85.217.182]:33387 "EHLO mail-lb0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964903AbbJIJKh (ORCPT ); Fri, 9 Oct 2015 05:10:37 -0400 From: Rasmus Villemoes To: Ingo Molnar Cc: Linus Torvalds , Chris Metcalf , open list , Peter Zijlstra , Thomas Gleixner , "H. Peter Anvin" , Borislav Petkov Subject: [RFC 0/3] eliminate potential race in string() (was: [PATCH] string: Improve the generic strlcpy() implementation) Organization: D03 References: <55F1DD53.1070102@ezchip.com> <20151005112700.GA1096@gmail.com> <87h9m57xwa.fsf@rasmusvillemoes.dk> <20151006080346.GB11523@gmail.com> <8737xnbqtn.fsf@rasmusvillemoes.dk> <20151007071821.GD7837@gmail.com> <87y4ffuk0r.fsf@rasmusvillemoes.dk> <20151008084837.GA4729@gmail.com> <87vbagwjgc.fsf@rasmusvillemoes.dk> X-Hashcash: 1:20:151009:a.p.zijlstra@chello.nl::svF1HaonEsKXvLSl:00000000000000000000000000000000000000003GD X-Hashcash: 1:20:151009:cmetcalf@ezchip.com::5i3qk0CAuC9SCaHo:0000000000000000000000000000000000000000000V8u X-Hashcash: 1:20:151009:tglx@linutronix.de::lpDVxmN2Hwy/l8Uz:000000000000000000000000000000000000000000018Yt X-Hashcash: 1:20:151009:mingo@kernel.org::NRuR5pMEfG/gxItV:024us X-Hashcash: 1:20:151009:hpa@zytor.com::lmrXNPi4Zp9+0xrr:000026kz X-Hashcash: 1:20:151009:bp@alien8.de::fOwuoGq+1+7bo6r8:000002Q27 X-Hashcash: 1:20:151009:linux-kernel@vger.kernel.org::Hldv6n6og0sg97uX:0000000000000000000000000000000002J78 X-Hashcash: 1:20:151009:torvalds@linux-foundation.org::IfQp+Ro4yThYSjDp:000000000000000000000000000000009Nh3 Date: Fri, 09 Oct 2015 11:10:33 +0200 In-Reply-To: <87vbagwjgc.fsf@rasmusvillemoes.dk> (Rasmus Villemoes's message of "Fri, 09 Oct 2015 10:10:43 +0200") Message-ID: <87r3l4wgom.fsf_-_@rasmusvillemoes.dk> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 09 2015, Rasmus Villemoes wrote: > It's hard not to agree with the overall "let's make it more robust if it > can be done sanely+cheaply+cleanly". I was a bit skeptical about whether > those three requirements could be met, since we'd have to do > byte-by-byte traversal of the string, maybe-copying it to the output as > we go along, but then right-alignment would require us to do a memmove, > but not before we've done some complicated bookkeeping > exercise. However, now that I read the source again, it seems that Al > Viro already did that exercise when he added dentry(). So maybe it's > doable without a net increase in LOC. Something like this. The net increase is because I added a comment. Passes the new printf test suite, but I'm not sure that's thorough enough yet - still, it's better than nothing. There's also this small bonus: $ scripts/bloat-o-meter /tmp/vsprintf.o.{old,new} add/remove: 1/0 grow/shrink: 0/2 up/down: 178/-245 (-67) function old new delta widen_string.isra - 178 +178 string.isra 186 109 -77 dentry_name.isra 358 190 -168 Rasmus Villemoes (3): lib/vsprintf.c: pull out padding code from dentry_name() lib/vsprintf.c: move string() below widen_string() lib/vsprintf.c: eliminate potential race in string() lib/vsprintf.c | 98 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 52 insertions(+), 46 deletions(-)