Skip to content

Commit 5ba6de9

Browse files
eaugerawilliam
authored andcommitted
vfio: fix vfio_info_cap_add/shift
Capability header next field is an offset relative to the start of the INFO buffer. tmp->next is assigned the proper value but iterations implemented in vfio_info_cap_add and vfio_info_cap_shift use next as an offset between the headers. When coping with multiple capabilities this leads to an Oops. Signed-off-by: Eric Auger <[email protected]> Reviewed-by: David Hildenbrand <[email protected]> Signed-off-by: Alex Williamson <[email protected]>
1 parent f4cb410 commit 5ba6de9

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/vfio/vfio.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,7 +1780,7 @@ struct vfio_info_cap_header *vfio_info_cap_add(struct vfio_info_cap *caps,
17801780
header->version = version;
17811781

17821782
/* Add to the end of the capability chain */
1783-
for (tmp = caps->buf; tmp->next; tmp = (void *)tmp + tmp->next)
1783+
for (tmp = buf; tmp->next; tmp = buf + tmp->next)
17841784
; /* nothing */
17851785

17861786
tmp->next = caps->size;
@@ -1793,8 +1793,9 @@ EXPORT_SYMBOL_GPL(vfio_info_cap_add);
17931793
void vfio_info_cap_shift(struct vfio_info_cap *caps, size_t offset)
17941794
{
17951795
struct vfio_info_cap_header *tmp;
1796+
void *buf = (void *)caps->buf;
17961797

1797-
for (tmp = caps->buf; tmp->next; tmp = (void *)tmp + tmp->next - offset)
1798+
for (tmp = buf; tmp->next; tmp = buf + tmp->next - offset)
17981799
tmp->next += offset;
17991800
}
18001801
EXPORT_SYMBOL(vfio_info_cap_shift);

0 commit comments

Comments
 (0)