Skip to content

Fix abd leak, kmem_free correct size of abd_t #12295

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

Merged
merged 1 commit into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/sys/abd_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void abd_free_struct(abd_t *);
*/

abd_t *abd_alloc_struct_impl(size_t);
abd_t *abd_get_offset_scatter(abd_t *, abd_t *, size_t);
abd_t *abd_get_offset_scatter(abd_t *, abd_t *, size_t, size_t);
void abd_free_struct_impl(abd_t *);
void abd_alloc_chunks(abd_t *, size_t);
void abd_free_chunks(abd_t *);
Expand Down
9 changes: 6 additions & 3 deletions module/os/freebsd/zfs/abd_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,14 +374,17 @@ abd_alloc_for_io(size_t size, boolean_t is_metadata)
}

abd_t *
abd_get_offset_scatter(abd_t *abd, abd_t *sabd, size_t off)
abd_get_offset_scatter(abd_t *abd, abd_t *sabd, size_t off,
size_t size)
{
abd_verify(sabd);
ASSERT3U(off, <=, sabd->abd_size);

size_t new_offset = ABD_SCATTER(sabd).abd_offset + off;
uint_t chunkcnt = abd_scatter_chunkcnt(sabd) -
(new_offset / zfs_abd_chunk_size);
size_t chunkcnt = abd_chunkcnt_for_bytes(
(new_offset % zfs_abd_chunk_size) + size);

ASSERT3U(chunkcnt, <=, abd_scatter_chunkcnt(sabd));

/*
* If an abd struct is provided, it is only the minimum size. If we
Expand Down
3 changes: 2 additions & 1 deletion module/os/linux/zfs/abd_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,8 @@ abd_alloc_for_io(size_t size, boolean_t is_metadata)
}

abd_t *
abd_get_offset_scatter(abd_t *abd, abd_t *sabd, size_t off)
abd_get_offset_scatter(abd_t *abd, abd_t *sabd, size_t off,
size_t size)
{
int i = 0;
struct scatterlist *sg = NULL;
Expand Down
2 changes: 1 addition & 1 deletion module/zfs/abd.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ abd_get_offset_impl(abd_t *abd, abd_t *sabd, size_t off, size_t size)
}
ASSERT3U(left, ==, 0);
} else {
abd = abd_get_offset_scatter(abd, sabd, off);
abd = abd_get_offset_scatter(abd, sabd, off, size);
}

ASSERT3P(abd, !=, NULL);
Expand Down