Skip to content

Commit

Permalink
btrfs: add the missing error handling inside get_canonical_dev_path
Browse files Browse the repository at this point in the history
Inside function get_canonical_dev_path(), we call d_path() to get the
final device path.

But d_path() can return error, and in that case the next strscpy() call
will trigger an invalid memory access.

Add back the missing error handling for d_path().

Reported-by: Boris Burkov <boris@bur.io>
Fixes: 7e06de7 ("btrfs: canonicalize the device path before adding it")
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
  • Loading branch information
adam900710 authored and kdave committed Jan 23, 2025
1 parent c4c101c commit a431b3c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions fs/btrfs/volumes.c
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,10 @@ static int get_canonical_dev_path(const char *dev_path, char *canonical)
if (ret)
goto out;
resolved_path = d_path(&path, path_buf, PATH_MAX);
if (IS_ERR(resolved_path)) {
ret = PTR_ERR(resolved_path);
goto out;
}
ret = strscpy(canonical, resolved_path, PATH_MAX);
out:
kfree(path_buf);
Expand Down

0 comments on commit a431b3c

Please sign in to comment.