diff --git a/headers/private/kernel/syscalls.h b/headers/private/kernel/syscalls.h index 5f45d407c9..92a69098e0 100644 --- a/headers/private/kernel/syscalls.h +++ b/headers/private/kernel/syscalls.h @@ -127,7 +127,7 @@ extern status_t _kern_get_next_image_info(team_id team, int32 *cookie, image_in // VFS functions extern dev_t _kern_mount(const char *path, const char *device, - const char *fs_name, uint32 flags, const char *args); + const char *fs_name, uint32 flags, const char *args, size_t argsLength); extern status_t _kern_unmount(const char *path, uint32 flags); extern status_t _kern_read_fs_info(dev_t device, struct fs_info *info); extern status_t _kern_write_fs_info(dev_t device, const struct fs_info *info, int mask); diff --git a/headers/private/kernel/vfs.h b/headers/private/kernel/vfs.h index 9fe3d96f88..942e3ffd1e 100644 --- a/headers/private/kernel/vfs.h +++ b/headers/private/kernel/vfs.h @@ -111,7 +111,7 @@ status_t resolve_mount_point_to_volume_root(mount_id mountID, vnode_id nodeID, /* calls the syscall dispatcher should use for user file I/O */ dev_t _user_mount(const char *path, const char *device, const char *fs_name, - uint32 flags, const char *args); + uint32 flags, const char *args, size_t argsLength); status_t _user_unmount(const char *path, uint32 flags); status_t _user_read_fs_info(dev_t device, struct fs_info *info); status_t _user_write_fs_info(dev_t device, const struct fs_info *info, int mask); diff --git a/src/system/kernel/fs/vfs.cpp b/src/system/kernel/fs/vfs.cpp index 0cc2910d04..ff00b92eb3 100644 --- a/src/system/kernel/fs/vfs.cpp +++ b/src/system/kernel/fs/vfs.cpp @@ -5498,7 +5498,7 @@ err: dev_t _kern_mount(const char *path, const char *device, const char *fsName, - uint32 flags, const char *args) + uint32 flags, const char *args, size_t argsLength) { KPath pathBuffer(path, false, B_PATH_NAME_LENGTH + 1); if (pathBuffer.InitCheck() != B_OK) @@ -6199,7 +6199,7 @@ _kern_setcwd(int fd, const char *path) dev_t _user_mount(const char *userPath, const char *userDevice, const char *userFileSystem, - uint32 flags, const char *userArgs) + uint32 flags, const char *userArgs, size_t argsLength) { char fileSystem[B_OS_NAME_LENGTH]; KPath path, device; @@ -6225,29 +6225,17 @@ _user_mount(const char *userPath, const char *userDevice, const char *userFileSy && user_strlcpy(device.LockBuffer(), userDevice, B_PATH_NAME_LENGTH) < B_OK) return B_BAD_ADDRESS; - if (userArgs != NULL) { - // We have no real length restriction, so we need to create - // a buffer large enough to hold the argument string - // ToDo: we could think about determinung the length of the string - // in userland :) - ssize_t length = user_strlcpy(args, userArgs, 0); - if (length < B_OK) + if (userArgs != NULL && argsLength > 0) { + if (argsLength >= 65536) + return B_BAD_VALUE; + args = (char *)malloc(argsLength + 1); + if (args == NULL) + return B_NO_MEMORY; + if (user_strlcpy(args, userArgs, argsLength + 1) < B_OK) { + free(args); return B_BAD_ADDRESS; - - // this is a safety restriction - if (length > 32 * 1024) - return B_NAME_TOO_LONG; - - if (length > 0) { - args = (char *)malloc(length + 1); - if (args == NULL) - return B_NO_MEMORY; - - if (user_strlcpy(args, userArgs, length + 1) < B_OK) { - free(args); - return B_BAD_ADDRESS; - } } + } path.UnlockBuffer(); device.UnlockBuffer(); diff --git a/src/system/kernel/fs/vfs_boot.cpp b/src/system/kernel/fs/vfs_boot.cpp index 62571a124c..9ba68b0f47 100644 --- a/src/system/kernel/fs/vfs_boot.cpp +++ b/src/system/kernel/fs/vfs_boot.cpp @@ -191,7 +191,7 @@ vfs_bootstrap_file_systems(void) status_t status; // bootstrap the root filesystem - status = _kern_mount("/", NULL, "rootfs", 0, NULL); + status = _kern_mount("/", NULL, "rootfs", 0, NULL, 0); if (status < B_OK) panic("error mounting rootfs!\n"); @@ -199,13 +199,13 @@ vfs_bootstrap_file_systems(void) // bootstrap the devfs _kern_create_dir(-1, "/dev", 0755); - status = _kern_mount("/dev", NULL, "devfs", 0, NULL); + status = _kern_mount("/dev", NULL, "devfs", 0, NULL, 0); if (status < B_OK) panic("error mounting devfs\n"); // bootstrap the pipefs _kern_create_dir(-1, "/pipe", 0755); - status = _kern_mount("/pipe", NULL, "pipefs", 0, NULL); + status = _kern_mount("/pipe", NULL, "pipefs", 0, NULL, 0); if (status < B_OK) panic("error mounting pipefs\n"); @@ -240,7 +240,7 @@ vfs_mount_boot_file_system(kernel_args *args) if (bootPartition->GetPath(&path) != B_OK) panic("could not get boot device!\n"); - gBootDevice = _kern_mount("/boot", path.Path(), NULL, 0, NULL); + gBootDevice = _kern_mount("/boot", path.Path(), NULL, 0, NULL, 0); if (gBootDevice >= B_OK) break; } diff --git a/src/system/libroot/os/fs_volume.c b/src/system/libroot/os/fs_volume.c index 54e5b8fb92..265335c67a 100644 --- a/src/system/libroot/os/fs_volume.c +++ b/src/system/libroot/os/fs_volume.c @@ -12,7 +12,7 @@ dev_t fs_mount_volume(const char *where, const char *device, const char *fileSystem, uint32 flags, const char *parameters) { - return _kern_mount(where, device, fileSystem, flags, (void *)parameters); + return _kern_mount(where, device, fileSystem, flags, (void *)parameters, parameters ? strlen(parameters) : 0); }