From 690ae8a2025ca1ce58d08a90a1df1645c81392ea Mon Sep 17 00:00:00 2001 From: Kirk McKusick Date: Thu, 21 Aug 2025 22:33:48 -0700 Subject: [PATCH] Bail out of corrupt directory entries during boot A directory with a zero-valued d_reclen causes boot to hang, This patch checks for directory entries with value zero and bails out rather than spin forever. The hope is that the user has other options. Sadly this was reported on Jun 16 2015 and is just now attended to as part of a sweep of old unclosed phabricator reports. Reported-by: Daniel O'Connor darius-dons.net.au Differential Revision: https://reviews.freebsd.org/D2844 MFC-after: 1 week Sponsored-by: Netflix --- stand/libsa/ufs.c | 6 ++++++ stand/libsa/ufsread.c | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/stand/libsa/ufs.c b/stand/libsa/ufs.c index 86cd3be9a27..868e8d47dbb 100644 --- a/stand/libsa/ufs.c +++ b/stand/libsa/ufs.c @@ -891,6 +891,12 @@ ufs_readdir(struct open_file *f, struct dirent *d) if (error) return (error); dp = (struct direct *)buf; + /* + * Check for corrupt directory entry and bail out rather + * than spin forever hoping that the user has other options. + */ + if (dp->d_reclen == 0) + return (0); fp->f_seekp += dp->d_reclen; } while (dp->d_ino == (ino_t)0); diff --git a/stand/libsa/ufsread.c b/stand/libsa/ufsread.c index 0f9b9bb4e2f..86ac8fbbbab 100644 --- a/stand/libsa/ufsread.c +++ b/stand/libsa/ufsread.c @@ -108,6 +108,13 @@ fsfind(const char *name, ufs_ino_t * ino) *ino = d.d_ino; return d.d_type; } + /* + * Check for corrupt directory entry and bail out + * rather than spin forever hoping that the user + * has other options. + */ + if (d.d_reclen == 0) + return 0; s += d.d_reclen; } if (n != -1 && ls)