From bea41f8d6a1b0b3941debc0f93acbf8291769397 Mon Sep 17 00:00:00 2001 From: Doug Schaapveld Date: Mon, 19 Aug 2024 13:20:21 -0500 Subject: [PATCH] Enforce dirent count limit [FS-1222] (#527) ... to prevent painful site outages. Follow-up to FS-1111. --- src/fusedav.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/fusedav.c b/src/fusedav.c index 82c0e91..fd48166 100644 --- a/src/fusedav.c +++ b/src/fusedav.c @@ -1396,14 +1396,9 @@ static int dav_mkdir(const char *path, mode_t mode) { } else { direntcnt = log_dirent_count(config->cache, parentpath); if(direntcnt > MAX_DIRENTS_IN_DIR) { - log_print(LOG_WARNING, SECTION_FUSEDAV_DIR, "dav_mkdir: %s; dirent count (%u) above threshold for %s", path, direntcnt, parentpath); - // TODO: This is currently just logging but not preventing the dav_mkdir operation. - // Once we are confident on the decision to go ahead with blocking the writes, - // uncomment/modify the code below to enforce it. - - // log_print(LOG_WARNING, SECTION_FUSEDAV_DIR, "dav_mkdir: %s aborted; dirent count (%u) above threshold for %s", path, direntcnt, parentpath); - // g_set_error(&gerr, fusedav_quark(), ENOSPC, "aborted; dirent count above threshold"); - // return processed_gerror("dav_mkdir: ", path, &gerr); + log_print(LOG_WARNING, SECTION_FUSEDAV_DIR, "dav_mkdir: %s aborted; dirent count (%u) above threshold for %s", path, direntcnt, parentpath); + g_set_error(&gerr, fusedav_quark(), ENOSPC, "aborted; dirent count above threshold"); + return processed_gerror("dav_mkdir: ", path, &gerr); } } free(parentpath); @@ -2170,14 +2165,9 @@ static int dav_create(const char *path, mode_t mode, struct fuse_file_info *info } else { direntcnt = log_dirent_count(config->cache, parentpath); if(direntcnt > MAX_DIRENTS_IN_DIR) { - log_print(LOG_WARNING, SECTION_FUSEDAV_FILE, "dav_create: %s; dirent count (%u) above threshold for %s", path, direntcnt, parentpath); - // TODO: This is currently just logging but not preventing the dav_create operation. - // Once we are confident on the decision to go ahead with blocking the writes, - // uncomment/modify the code below to enforce it. - - // log_print(LOG_WARNING, SECTION_FUSEDAV_FILE, "dav_create: %s aborted; dirent count (%u) above threshold for %s", path, direntcnt, parentpath); - // g_set_error(&gerr, fusedav_quark(), ENOSPC, "aborted; dirent count above threshold"); - // return processed_gerror("dav_create: ", path, &gerr); + log_print(LOG_WARNING, SECTION_FUSEDAV_FILE, "dav_create: %s aborted; dirent count (%u) above threshold for %s", path, direntcnt, parentpath); + g_set_error(&gerr, fusedav_quark(), ENOSPC, "aborted; dirent count above threshold"); + return processed_gerror("dav_create: ", path, &gerr); } } free(parentpath);