From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS, URIBL_RED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AFA9EC433B4 for ; Thu, 20 May 2021 14:53:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9454C61073 for ; Thu, 20 May 2021 14:53:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231865AbhETOzF (ORCPT ); Thu, 20 May 2021 10:55:05 -0400 Received: from mx2.suse.de ([195.135.220.15]:36254 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231418AbhETOzC (ORCPT ); Thu, 20 May 2021 10:55:02 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1621522419; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=M8hqVgNQf+om50EjQbuWLvBSRMEEuDC2cfNombgOqIA=; b=tu3s2Wt5SshdfJXLmnHlL4WqWSI4s+yOHxwVBO4l8aV+a3YzJBruqkUV3bF4j5FE9IDyuy 2JUPeVuDHwqzd4A9WTnznq7MDD5VcKOZ/ITIsQ4H8/7u7mybX2h1kGP7EyoAx1VT+/0YXH N/slWUMzz91Dblog3HCzXN6c5mhMO7g= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 9B812ABE8; Thu, 20 May 2021 14:53:39 +0000 (UTC) Date: Thu, 20 May 2021 16:53:38 +0200 From: Petr Mladek To: Justin He Cc: Al Viro , Linus Torvalds , Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko , Rasmus Villemoes , Jonathan Corbet , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , "Eric W . Biederman" , "Darrick J. Wong" , "Peter Zijlstra (Intel)" , Ira Weiny , Eric Biggers , "Ahmed S. Darwish" , "open list:DOCUMENTATION" , Linux Kernel Mailing List , linux-s390 , linux-fsdevel Subject: Re: [PATCH 08/14] d_path: make prepend_name() boolean Message-ID: References: <20210519004901.3829541-1-viro@zeniv.linux.org.uk> <20210519004901.3829541-8-viro@zeniv.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 2021-05-20 09:12:34, Justin He wrote: > Hi Al > > > -----Original Message----- > > From: Al Viro On Behalf Of Al Viro > > Sent: Wednesday, May 19, 2021 8:49 AM > > To: Linus Torvalds > > Cc: Justin He ; Petr Mladek ; Steven > > Rostedt ; Sergey Senozhatsky > > ; Andy Shevchenko > > ; Rasmus Villemoes > > ; Jonathan Corbet ; Heiko > > Carstens ; Vasily Gorbik ; Christian > > Borntraeger ; Eric W . Biederman > > ; Darrick J. Wong ; Peter > > Zijlstra (Intel) ; Ira Weiny ; > > Eric Biggers ; Ahmed S. Darwish > > ; open list:DOCUMENTATION > doc@vger.kernel.org>; Linux Kernel Mailing List > kernel@vger.kernel.org>; linux-s390 ; linux- > > fsdevel > > Subject: [PATCH 08/14] d_path: make prepend_name() boolean > > > > It returns only 0 or -ENAMETOOLONG and both callers only check if > > the result is negative. Might as well return true on success and > > false on failure... > > > > Signed-off-by: Al Viro > > --- > > fs/d_path.c | 12 ++++++------ > > 1 file changed, 6 insertions(+), 6 deletions(-) > > > > diff --git a/fs/d_path.c b/fs/d_path.c > > index 327cc3744554..83db83446afd 100644 > > --- a/fs/d_path.c > > +++ b/fs/d_path.c > > @@ -34,15 +34,15 @@ static void prepend(char **buffer, int *buflen, const > > char *str, int namelen) > > * > > * Load acquire is needed to make sure that we see that terminating NUL. > > */ > > -static int prepend_name(char **buffer, int *buflen, const struct qstr > > *name) > > +static bool prepend_name(char **buffer, int *buflen, const struct qstr > > *name) > > { > > const char *dname = smp_load_acquire(&name->name); /* ^^^ */ > > u32 dlen = READ_ONCE(name->len); > > char *p; > > > > *buflen -= dlen + 1; > > - if (*buflen < 0) > > - return -ENAMETOOLONG; > > + if (unlikely(*buflen < 0)) > > + return false; > > I don't object to this patch itself. > Just wonder whether we need to relax the check condition of "*buflen < 0" ? > > Given that in vsnprintf code path, sometimes the *buflen is < 0. > > Please see https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/lib/vsprintf.c#n2698 IMHO, the patch is fine. It is likely some misunderstanding. The above link points to: 2693 str = buf; 2694 end = buf + size; 2695 2696 /* Make sure end is always >= buf */ 2697 if (end < buf) { 2698 end = ((void *)-1); 2699 size = end - buf; 2700 } "end" points right behind the end of the buffer. It is later used instead of the buffer size. The above code handles a potential overflow of "buf + size". I causes that "end" will be 0xffffffff in case of the overflow. That said. vsnprintf() returns the number of characters which would be generated for the given input. But only the "size" is written. This require copying the characters one by one. It is useful to see how many characters were lost. But I am not sure if this ever worked for the dentry functions. Best Regards, Petr