vfio: fix vfio_info_cap_add/shift
Subsystems (2)
PATCH 1/1 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.
--- drivers/vfio/vfio.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/vfio/vfio.c +3 -2
@@ -1763,7 +1763,7 @@ struct vfio_info_cap_header *vfio_info_cap_add(struct vfio_info_cap *caps, header->version = version;/* Add to the end of the capability chain */ -for (tmp = caps->buf; tmp->next; tmp = (void *)tmp + tmp->next) +for (tmp = buf; tmp->next; tmp = buf + tmp->next) ;/* nothing */ tmp->next = caps->size;
@@ -1776,8 +1776,9 @@ EXPORT_SYMBOL_GPL(vfio_info_cap_add);void vfio_info_cap_shift (struct vfio_info_cap *caps,size_t offset) {struct vfio_info_cap_header *tmp; +void *buf = (void *)caps->buf; -for (tmp = caps->buf; tmp->next; tmp = (void *)tmp + tmp->next - offset) +for (tmp = buf; tmp->next; tmp = buf + tmp->next - offset) tmp->next += offset; }EXPORT_SYMBOL_GPL (vfio_info_cap_shift);
Signature · 1 line
2.5.5
Am 21.11.2016 um 07:21 schrieb Eric Auger:
Quoted 16 lines
Capability header next field is an offset relative to the start of the INFO buffer.
tmp->nextis assigned the proper value but iterations implemented invfio_info_cap_addandvfio_info_cap_shiftuse next as an offset between the headers. When coping with multiple capabilities this leads to an Oops.Signed-off-by Eric Auger <[email protected]>--- drivers/vfio/vfio.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/vfio/vfio.c +0
-0
drivers/vfio/vfio.c struct vfio_info_cap_header *vfio_info_cap_add(struct vfio_info_cap *caps, · line 1768
Quoted 7 lines
drivers/vfio/vfio.c +1
-1@@ -1763,7 +1763,7 @@ struct vfio_info_cap_header *vfio_info_cap_add(struct vfio_info_cap *caps, header->version = version;/* Add to the end of the capability chain */ -for (tmp = caps->buf; tmp->next; tmp = (void *)tmp + tmp->next) +for (tmp = buf; tmp->next; tmp = buf + tmp->next) ;/* nothing */
Looks sane to me, tmp->next is always set to the old size, which corresponds to the offset from the start of the buffer.
drivers/vfio/vfio.c EXPORT_SYMBOL_GPL(vfio_info_cap_add); · line 1782
Quoted 10 lines
drivers/vfio/vfio.c +2
-1tmp->next = caps->size;@@ -1776,8 +1776,9 @@ EXPORT_SYMBOL_GPL(vfio_info_cap_add);void vfio_info_cap_shift (struct vfio_info_cap *caps,size_t offset) {struct vfio_info_cap_header *tmp; +void *buf = (void *)caps->buf; -for (tmp = caps->buf; tmp->next; tmp = (void *)tmp + tmp->next - offset) +for (tmp = buf; tmp->next; tmp = buf + tmp->next - offset) tmp->next += offset;
Signature · 1 line
David
Quoted 25 lines · On Mon, 21 Nov 2016 07:21:02 +0100 Eric Auger <[email protected]> wrote:
Capability header next field is an offset relative to the start of the INFO buffer.
tmp->nextis assigned the proper value but iterations implemented invfio_info_cap_addandvfio_info_cap_shiftuse next as an offset between the headers. When coping with multiple capabilities this leads to an Oops.Signed-off-by Eric Auger <[email protected]>--- drivers/vfio/vfio.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/vfio/vfio.c +1
-1@@ -1763,7 +1763,7 @@ struct vfio_info_cap_header *vfio_info_cap_add(struct vfio_info_cap *caps, header->version = version;/* Add to the end of the capability chain */ -for (tmp = caps->buf; tmp->next; tmp = (void *)tmp + tmp->next) +for (tmp = buf; tmp->next; tmp = buf + tmp->next) ;/* nothing */ tmp->next = caps->size;
drivers/vfio/vfio.c EXPORT_SYMBOL_GPL(vfio_info_cap_add); · line 1784
Quoted 10 lines
drivers/vfio/vfio.c +2
-1@@ -1776,8 +1776,9 @@ EXPORT_SYMBOL_GPL(vfio_info_cap_add);void vfio_info_cap_shift (struct vfio_info_cap *caps,size_t offset) {struct vfio_info_cap_header *tmp; +void *buf = (void *)caps->buf; -for (tmp = caps->buf; tmp->next; tmp = (void *)tmp + tmp->next - offset) +for (tmp = buf; tmp->next; tmp = buf + tmp->next - offset) tmp->next += offset; }EXPORT_SYMBOL_GPL (vfio_info_cap_shift);
Thanks, good to get this fixed before we start getting multiple entries in the chain and expose it via mdev. For that same reason I also don't see that this needs any sort of stable backport as the existing code works for the single entries in the tree. Applied to next branch for 4.10 with David's R-b. Thanks,
Alex