add symlink follow counter

This commit is contained in:
ІО-23 Шмуляр Олег 2025-05-17 22:40:02 +03:00
parent 1dbdbd20d3
commit 049405989b
2 changed files with 20 additions and 2 deletions

View File

@ -26,8 +26,8 @@
#define FS_MAX_PATH_LEN 512 #define FS_MAX_PATH_LEN 512
#define FS_MAX_OPEN_FD 32 #define FS_MAX_OPEN_FD 32
#define FS_MAX_FNAME_LEN 11 #define FS_MAX_FNAME_LEN 11
#define FS_MAX_DIRECTORY_DEPTH 512 #define FS_MAX_DIRECTORY_DEPTH 2048
#define FS_MAX_SYMLINK_FOLLOWING_DEPTH 1024 #define FS_MAX_SYMLINK_FOLLOWS 1024
#endif #endif

View File

@ -935,6 +935,8 @@ static void resolve_path(struct resolved_path * const rp, const char * const ori
int current_inode_ptr; int current_inode_ptr;
int i; int i;
unsigned int symlinks_followed = 0;
if (path[0] == '/') { if (path[0] == '/') {
current_inode_ptr = 0; current_inode_ptr = 0;
rp->parent_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 (d.ftype == SYMLINK) {
if (i+1 < path_len) { 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]; char symlink_path[FS_MAX_PATH_LEN+1];
int symlink_path_len = read_symlink(res, symlink_path); 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; 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]; char symlink_path[FS_MAX_PATH_LEN+1];
int symlink_path_len = read_symlink(res, symlink_path); int symlink_path_len = read_symlink(res, symlink_path);