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=-2.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 7D38EC2D0BF for ; Tue, 10 Dec 2019 23:10:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5CD6D2073D for ; Tue, 10 Dec 2019 23:10:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727330AbfLJXKZ (ORCPT ); Tue, 10 Dec 2019 18:10:25 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:48608 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726631AbfLJXKY (ORCPT ); Tue, 10 Dec 2019 18:10:24 -0500 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1ieodt-00083G-9G; Tue, 10 Dec 2019 23:10:09 +0000 Date: Tue, 10 Dec 2019 23:10:09 +0000 From: Al Viro To: Eric Biggers Cc: Tiezhu Yang , "Theodore Y. Ts'o" , Jaegeuk Kim , Chao Yu , Tyler Hicks , linux-fsdevel@vger.kernel.org, ecryptfs@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4] fs: introduce is_dot_or_dotdot helper for cleanup Message-ID: <20191210231009.GB4203@ZenIV.linux.org.uk> References: <1575979801-32569-1-git-send-email-yangtiezhu@loongson.cn> <20191210191912.GA99557@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191210191912.GA99557@gmail.com> User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 10, 2019 at 11:19:13AM -0800, Eric Biggers wrote: > > +static inline bool is_dot_or_dotdot(const unsigned char *name, size_t len) > > +{ > > + if (unlikely(name[0] == '.')) { > > + if (len < 2 || (len == 2 && name[1] == '.')) > > + return true; > > + } > > + > > + return false; > > +} > > This doesn't handle the len=0 case. Did you check that none of the users pass > in zero-length names? It looks like fscrypt_fname_disk_to_usr() can, if the > directory entry on-disk has a zero-length name. Currently it will return > -EUCLEAN in that case, but with this patch it may think it's the name ".". > > So I think there needs to either be a len >= 1 check added, *or* you need to > make an argument for why it's okay to not care about the empty name case. Frankly, the only caller that matters in practice is link_path_walk(); _that_ is by far the hottest path that might make use of that thing. BTW, the callers that might end up passing 0 for len really ought to take a good look at another thing - that name[0] is, in fact, mapped. Something along the lines of if (name + len > end_of_buffer) sod off if ((name, len)) .... is not enough, for obvious reasons.