Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp2302124ybc; Wed, 20 Nov 2019 11:59:12 -0800 (PST) X-Google-Smtp-Source: APXvYqwpeO7IYuaB3Jp4WueG34j2TrMm7MqPK4jgTPQgb0s2YHxWi6hnWMW6QKGMQhL2BqU06Vk0 X-Received: by 2002:a17:906:edd2:: with SMTP id sb18mr7790378ejb.112.1574279952766; Wed, 20 Nov 2019 11:59:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574279952; cv=none; d=google.com; s=arc-20160816; b=NTgfKuhCLltFkTkanHDTO+bJfZvqvkombCJ2vEWO1m1Gi6Bu/vMrVDGoQkguLLDftZ CUDkkcNtXv2cJRkiwRvp8Y8aNzOvjARcmwKAoMYdk1z4cz2e9ik5mUsu48iYwu9a8paB jkBbcL/1Z/KlZWXf2ICLU1qo6YeyUJTYEHz1ZKJCskf0es7N+c0Mp/mNhgzqZhQoUPf5 OYMlxqpBgHSVglifhLRpFvp73FycP4eX+qSgb7wJ7eFXXFwutkpEDyNWSCVUmjZQIamD EYbd0hPWBNBJiWvcjHIpd35fpxce5/hhV8O6MUZqJu7juKiDNL8KSgP1TReqUIi7p5sG TNPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:in-reply-to:date :references:subject:cc:to:from; bh=xG45dyD+Y5BXhJvqG+++9nt6irluYKZ1hrFPTYRCElw=; b=tF787cMJqC1YPCfBdMOcM/lG1ROL14uGN0CBGLieU37kzGkwL6VQe8/6ut/K0l75Mg lOuegF+DJwM+sVYHykUqRGqs1C3J5SuxMwRceaLoGWyvKZSRG5O6wBT0xvXZt1OQvNLr VxFyMTrrpvAZw/7A7m2+UAZ3Eg4uY5ukwmlHlvZsQ7RqEeU1VGx+Tz/fI46K9aTf9BR0 xpwefFUBdQT/bkJkQTi0B+2bFh/Zz8P14+ogc7ijVkBRx4hNF7VWXX1O/Kgcd6SMTq3s AUkMdge2MHRh3/i1OlOeyiUsHYD7bHN1A2FKlIxLTSAQuLcOrPSLwF5f44XXXQvKtI1A +O6w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n12si357330edr.448.2019.11.20.11.58.48; Wed, 20 Nov 2019 11:59:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727530AbfKTT5g (ORCPT + 99 others); Wed, 20 Nov 2019 14:57:36 -0500 Received: from albireo.enyo.de ([37.24.231.21]:58154 "EHLO albireo.enyo.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727085AbfKTT5g (ORCPT ); Wed, 20 Nov 2019 14:57:36 -0500 Received: from [172.17.203.2] (helo=deneb.enyo.de) by albireo.enyo.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) id 1iXW6X-0001jY-1c; Wed, 20 Nov 2019 19:57:33 +0000 Received: from fw by deneb.enyo.de with local (Exim 4.92) (envelope-from ) id 1iXW6W-0006rH-Vv; Wed, 20 Nov 2019 20:57:32 +0100 From: Florian Weimer To: Rich Felker Cc: linux-fsdevel@vger.kernel.org, musl@lists.openwall.com, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org Subject: Re: [musl] getdents64 lost direntries with SMB/NFS and buffer size < unknown threshold References: <20191120001522.GA25139@brightrain.aerifal.cx> Date: Wed, 20 Nov 2019 20:57:32 +0100 In-Reply-To: <20191120001522.GA25139@brightrain.aerifal.cx> (Rich Felker's message of "Tue, 19 Nov 2019 19:15:22 -0500") Message-ID: <8736eiqq1f.fsf@mid.deneb.enyo.de> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Rich Felker: > An issue was reported today on the Alpine Linux tracker at > https://gitlab.alpinelinux.org/alpine/aports/issues/10960 regarding > readdir results from SMB/NFS shares with musl libc. > > After a good deal of analysis, we determined the root cause to be that > the second and subsequent calls to getdents64 are dropping/skipping > direntries (that have not yet been deleted) when some entries were > deleted following the previous call. The issue appears to happen only > when the buffer size passed to getdents64 is below some threshold > greater than 2k (the size musl uses) but less than 32k (the size glibc > uses, with which we were unable to reproduce the issue). From the Gitlab issue: while ((dp = readdir(dir)) != NULL) { unlink(dp->d_name); ++file_cnt; } I'm not sure that this is valid code to delete the contents of a directory. It's true that POSIX says this: | If a file is removed from or added to the directory after the most | recent call to opendir() or rewinddir(), whether a subsequent call | to readdir() returns an entry for that file is unspecified. But many file systems simply provide not the necessary on-disk data structures which are need to ensure stable iteration in the face of modification of the directory. There are hacks, of course, such as compacting the on-disk directory only on file creation, which solves the file removal case. For deleting an entire directory, that is not really a problem because you can stick another loop around this while loop which re-reads the directory after rewinddir. Eventually, it will become empty.