Skip to content

Commit f0d189d

Browse files
efarmangregkh
authored andcommitted
s390/vfio_ccw: Calculate idal length based on idaw type
commit 4f6fdc6 upstream. Sashiko pointed out that get_guest_idal() unconditionally calculates the length of the IDAL presuming everything is a Format-2 IDAW. The output of vfio-ccw is always Format-2, but the input can be either Format-1 (31-bit addresses) or Format-2 (64-bit addresses). As a result, the size of the guest IDAL may be incorrect and should be trimmed down. Reported-by: sashiko-bot <sashiko-bot@kernel.org> Link: https://lore.kernel.org/r/20260720203400.7328E1F000E9@smtp.kernel.org/ Fixes: 1b676fe ("vfio/ccw: handle a guest Format-1 IDAL") Cc: stable@vger.kernel.org Reviewed-by: Matthew Rosato <mjrosato@linux.ibm.com> Signed-off-by: Eric Farman <farman@linux.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@linux.ibm.com> [farman@linux.ibm.com: resolved merge conflict] Signed-off-by: Eric Farman <farman@linux.ibm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 460b977 commit f0d189d

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

drivers/s390/cio/vfio_ccw_cp.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ static void convert_ccw0_to_ccw1(struct ccw1 *source, unsigned long len)
233233
}
234234

235235
#define idal_is_2k(_cp) (!(_cp)->orb.cmd.c64 || (_cp)->orb.cmd.i2k)
236+
#define get_idaw_size(_cp) ((_cp)->orb.cmd.c64 ? sizeof(u64) : sizeof(u32))
236237

237238
/*
238239
* Helpers to operate ccwchain.
@@ -522,7 +523,7 @@ static unsigned long *get_guest_idal(struct ccw1 *ccw,
522523
unsigned long *idaws;
523524
unsigned int *idaws_f1;
524525
u64 first_idaw;
525-
int idal_len = idaw_nr * sizeof(*idaws);
526+
int idal_len = idaw_nr * get_idaw_size(cp);
526527
int idaw_size = idal_is_2k(cp) ? PAGE_SIZE / 2 : PAGE_SIZE;
527528
int idaw_mask = ~(idaw_size - 1);
528529
int i, ret;
@@ -587,7 +588,7 @@ static int ccw_count_idaws(struct ccw1 *ccw,
587588
struct vfio_device *vdev =
588589
&container_of(cp, struct vfio_ccw_private, cp)->vdev;
589590
u64 iova;
590-
int size = cp->orb.cmd.c64 ? sizeof(u64) : sizeof(u32);
591+
int size = get_idaw_size(cp);
591592
int ret;
592593
int bytes = 1;
593594

0 commit comments

Comments
 (0)