Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1149125pxj; Fri, 21 May 2021 07:34:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzexXxKuF8Qij0w0MhXOGFUDttVLrMss6QZvWWXp0uuN7Ozip4zDudjt9g6HUqWorZ3BTNo X-Received: by 2002:a05:6402:1052:: with SMTP id e18mr11882472edu.366.1621607696007; Fri, 21 May 2021 07:34:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621607696; cv=none; d=google.com; s=arc-20160816; b=Aw/gac9yP50gFT6yEjOfZaXxR8MRRJkH8LZeWhfd40HdrbPuWE2IwZrBoaBA5xsPiR VCLiM6K+YrXsarIKV8tvZX7fktciE7YFYPVObUo7FfmnxkZEmywkf2g/v3QidzM7wZDl D4vnNIzzwxnRbcWdIAySXTe2K7qImiIqqWdZVb8XMQZ8u1jTOeMliy6rTzeUZYerGgaq abrzBczWk1Ex3lHe4ACG64+a/hU4asYUCYKdy7wlvVF/eGk1C5q9n2WoKavK3T56mBZg JtxFAFEP2Y83v8WxKKyTEfNT9P6uBJs1EDyQ3D03vWs+TPLGSQ/vP+GWxXSnEzVNYYkK CQwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=M8hqVgNQf+om50EjQbuWLvBSRMEEuDC2cfNombgOqIA=; b=qhBt9SBfm0nXYjcX7yOBtntjeBJfSbiBzMU1WW0bq9f0lMYBdH8Jcr2cznVhdFBRSe FqnlTYPerIts+fgpz/z1ekoDWzKJ+EMtx5e6hVWfh9vg/JpoUKd/uT8Vw19BqWbiTbmR 3qu/e09dY6Fkegfo4Wum2pTFwPxxBkX+/kIkRW94UCibn/7nVnsCQIviB1KgUPvpdVXA 3+NO3d56e2SJ7uBCpInXc22Kw+ObpM9a53vKKg+B1Sy27AdV9h7TcqH3A5Ov00tXnP4T fb4vFyK7kQ74WyV8U8AbcXmix7oWeBI5oppZ9no98hrsOWsidaycHjk1qX14whW2n0Rj QlVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=tu3s2Wt5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ca23si4127826edb.521.2021.05.21.07.34.32; Fri, 21 May 2021 07:34:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=tu3s2Wt5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231719AbhETOzD (ORCPT + 99 others); Thu, 20 May 2021 10:55:03 -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