-
Notifications
You must be signed in to change notification settings - Fork 7.5k
fs: fuse: Fix possible buffer overflow #63079
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
subsys/fs/fuse_fs_access.c
Outdated
sprintf(mount_path, "%.*s/", MIN(strlen(path), | ||
(PATH_MAX - 2)), path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be more proper to check first whether the additional '/' fits with string to the mount point and use strcpy
, or similar rather than heavy snprintf, and fill in missing '/'.
Above is also dangerous because you can get path that is still existing path, but not a path you want to access.
For example you can cut something like "/bi/ba/bu" to "/bi/ba//" which is still valid path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep ... thought about it but decided to just truncate the contents and send to the upper level to keep it as closes as the original implementation ...
But it is probably better just return an error here and avoid propagate inaccurate data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
Ensure that the path in fuse_fs_access_readdir does not overflow the local buffer. Signed-off-by: Flavio Ceolin <[email protected]>
@@ -176,9 +176,15 @@ static int fuse_fs_access_readdir(const char *path, void *buf, | |||
* directory but FUSE strips the trailing slashes from | |||
* directory names so add it back. | |||
*/ | |||
char mount_path[PATH_MAX]; | |||
char mount_path[PATH_MAX] = {0}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note for the future: if you are planning to overwrite the buffer with whatevercpy
do not initialize it this way, because this will be replaced by loop putting 0 in the array; just do all the copy you need and then place the final 0 where it belongs, as you will know where to place it anyway.
|
||
sprintf(mount_path, "%s/", path); | ||
if (len >= (PATH_MAX - 2)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (len > (PATH_MAX - 2)) {
suffices, leaving one byte for /
and \0
each.
return -ENOMEM; | ||
} | ||
|
||
memcpy(mount_path, path, len) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing semicolon, did this patch pass CI?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clearly the CI is not running this code path, could you send a PR with the fix?
Ensure that the path in fuse_fs_access_readdir does not overflow the local buffer.