From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x33.google.com (mail-oa1-x33.google.com [IPv6:2001:4860:4864:20::33]) by sourceware.org (Postfix) with ESMTPS id 58EB03858D1E for ; Mon, 13 Mar 2023 19:34:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 58EB03858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oa1-x33.google.com with SMTP id 586e51a60fabf-176d93cd0daso14935409fac.4 for ; Mon, 13 Mar 2023 12:34:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678736064; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=o2kbbnYjuCdT/O7LmO3zuptNa63/akmNgQcSGmfWPyQ=; b=Ar7hFp6nMFvog6hoPNdcdAFWdwyeY+hz9PKUigTy3VVBPA/F7CRz13B6RKpXeMSuAY Y6wEMGe0xbkgv4QRd0fee6rVHaGM0Dzxi4b+mmDvTWCXlfHf1ASJOKzd1t+NgeoeQAWD PY2fpzutHAxEyOh3JJmiO4o8BMiU0t+b0ZiEZ2a5PRuKohDL2wcmWqRvurOZ/UEs7tMz KkOIvREW4IlHXXkRgU1khNAUGb8DVbomwXwWWYCOI8Jy/8X7GbpYVpJq9ue17t6b7k7o lg45oK5I64fVUzHLcA8y1wG+twFu5QdbQnbUEX5SUewCor7gCUIyvvSAg8WrfqeiJULI 6zHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678736064; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=o2kbbnYjuCdT/O7LmO3zuptNa63/akmNgQcSGmfWPyQ=; b=FMDxn4CcUniSltF7Xf/Dchx4BMk1UUgdBhfEAq36PiXWvwamclb0sIz2u7TS2/dNl6 MFBcbDnBTw+ilr+MQcBGLxjNwvywGJNKIty1rpBEZrjGJ0Jy35tvHPWomBY6C0i/VcMK JJt9Z04CGLN7h1bmba1nYYakxhd7L569e3yJ33YzkXlq4RZSy38AqW/xqUdTP6gOFo2S 3fWgjSU5yeqG0G0uA8rdH4DXXMz3+Hc2EpJIcy0Il6DcN/IeBJkH+hysiGu+A8jWLhr3 VOpfsOOvJ8MTGzZFnUvkLivIiUIfWmnc5u6f/GIDwoqISYpd3s/GIcbAYZ6czr1ESJdN cwuA== X-Gm-Message-State: AO0yUKXrNuQP1wMZau8CHJtCfPBfZf0cpngNl6yqSE+BXfLIHe3P7dPI LR3SV7VOpmujvHEmKR6qCDwytrdu6lNx76K1OUaM5g== X-Google-Smtp-Source: AK7set9sHDoycd6prui/eO2niy0ZAzw9vvCN1lpC4w+gFgRuY8vGUa3k7uAe44n6dMR1xAwOOYGitg== X-Received: by 2002:a05:6870:128f:b0:177:c522:56e with SMTP id 15-20020a056870128f00b00177c522056emr1692764oal.24.1678736064435; Mon, 13 Mar 2023 12:34:24 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:544b:9bad:e673:fbfa:30eb]) by smtp.gmail.com with ESMTPSA id zf9-20020a0568716a8900b00172426ebe58sm325724oab.27.2023.03.13.12.34.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Mar 2023 12:34:23 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org, "Andreas K . Huettel" , Paul Eggert , Florian Weimer Subject: [PATCH v7 0/3] Fix opendir regression on some FS Date: Mon, 13 Mar 2023 16:34:16 -0300 Message-Id: <20230313193419.36985-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Some filesystem might return a non-representable d_off on getdents call, even if there are few entries in the directories (for instance ext4, which returns an internal FS hash). This trigger issues with non-LFS readdir when it finds the first non representable entry, and also for LFS interface when used along with telldir (which return a 'long int', while d_off is potentially off64_t). For instance, arm32 dirent and io tests running on qemu-user show the following failures: FAIL: dirent/list FAIL: dirent/tst-scandir FAIL: io/tst-fts FAIL: io/tst-fts-lfs FAIL: io/tst-fts-time64 This patch changes non-LFS readdir so it clamps the d_off value if it overflows. It now uses getdents64 and maintains an internal map between d_off that can not be represented by 'long int' (telldir returned value). seekdir will then set the correct offset by using the input argument as a key to the internal list. I have checked on x86_64-linux-gnu, i686-linux-gnu, and arm-linux-gnueabihf. Changes from v6: * Fix xreallocarray based on gnulib code. * Added comments on telldir.h. Changes from v5: * Use non-LFS getdents logic on non-LFS readdir. * Clamp overflow d_off values. * Removed unrequired readdir64 refactor. Changes from v4: * Allocate the telldir map an readdir, thus avoid telldir failure. * The translation buffer now uses a fixed size struct. * Fixed the condition to use the long to off64_t map. Changes from v3: * Rebase against master. * Fixed a missing lock unlock on telldir. * Renamed tst-seekdir2 to tst-opendir-nolfs and check the opendir result against getdents64. Adhemerval Zanella (3): linux: Use getdents64 on non-LFS readdir support: Add xreallocarray linux: Set internal DIR filepos as off64_t (BZ #23960, BZ #24050) Adhemerval Zanella (3): linux: Use getdents64 on non-LFS readdir support: Add xreallocarray linux: Set internal DIR filepos as off64_t (BZ #23960, BZ #24050) include/dirent.h | 2 +- support/Makefile | 1 + support/support.h | 2 + support/xreallocarray.c | 29 ++++ sysdeps/unix/sysv/linux/Makefile | 2 + sysdeps/unix/sysv/linux/alpha/bits/dirent.h | 3 + sysdeps/unix/sysv/linux/bits/dirent.h | 4 + sysdeps/unix/sysv/linux/closedir.c | 4 + sysdeps/unix/sysv/linux/dirstream.h | 9 +- sysdeps/unix/sysv/linux/opendir.c | 3 + sysdeps/unix/sysv/linux/readdir.c | 107 +++++++++++---- sysdeps/unix/sysv/linux/readdir64.c | 11 ++ sysdeps/unix/sysv/linux/rewinddir.c | 5 + sysdeps/unix/sysv/linux/seekdir.c | 30 +++- sysdeps/unix/sysv/linux/telldir.c | 36 +++++ sysdeps/unix/sysv/linux/telldir.h | 70 ++++++++++ sysdeps/unix/sysv/linux/tst-opendir-lfs.c | 2 + sysdeps/unix/sysv/linux/tst-opendir.c | 145 ++++++++++++++++++++ 18 files changed, 435 insertions(+), 30 deletions(-) create mode 100644 support/xreallocarray.c create mode 100644 sysdeps/unix/sysv/linux/telldir.h create mode 100644 sysdeps/unix/sysv/linux/tst-opendir-lfs.c create mode 100644 sysdeps/unix/sysv/linux/tst-opendir.c -- 2.34.1