From 049405989b684ebf5c4c5ae4324b6de5488039c5 Mon Sep 17 00:00:00 2001 From: hasslesstech Date: Sat, 17 May 2025 22:40:02 +0300 Subject: [PATCH] add symlink follow counter --- config.h | 4 ++-- src/fs.c | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/config.h b/config.h index 63dc731..73cc541 100644 --- a/config.h +++ b/config.h @@ -26,8 +26,8 @@ #define FS_MAX_PATH_LEN 512 #define FS_MAX_OPEN_FD 32 #define FS_MAX_FNAME_LEN 11 -#define FS_MAX_DIRECTORY_DEPTH 512 -#define FS_MAX_SYMLINK_FOLLOWING_DEPTH 1024 +#define FS_MAX_DIRECTORY_DEPTH 2048 +#define FS_MAX_SYMLINK_FOLLOWS 1024 #endif diff --git a/src/fs.c b/src/fs.c index 8bca2b9..751ed25 100644 --- a/src/fs.c +++ b/src/fs.c @@ -935,6 +935,8 @@ static void resolve_path(struct resolved_path * const rp, const char * const ori int current_inode_ptr; int i; + unsigned int symlinks_followed = 0; + if (path[0] == '/') { current_inode_ptr = 0; rp->parent_inode_ptr = 0; @@ -978,6 +980,14 @@ static void resolve_path(struct resolved_path * const rp, const char * const ori if (d.ftype == SYMLINK) { if (i+1 < path_len) { + symlinks_followed++; + if (symlinks_followed > FS_MAX_SYMLINK_FOLLOWS) { + pr_err("too many symlink follows\n"); + rp->parent_inode_ptr = -1; + rp->target_inode_ptr = -1; + break; + } + char symlink_path[FS_MAX_PATH_LEN+1]; int symlink_path_len = read_symlink(res, symlink_path); @@ -1017,6 +1027,14 @@ static void resolve_path(struct resolved_path * const rp, const char * const ori break; } + symlinks_followed++; + if (symlinks_followed > FS_MAX_SYMLINK_FOLLOWS) { + pr_err("too many symlink follows\n"); + rp->parent_inode_ptr = -1; + rp->target_inode_ptr = -1; + break; + } + char symlink_path[FS_MAX_PATH_LEN+1]; int symlink_path_len = read_symlink(res, symlink_path);