Skip to content

Commit 6de7145

Browse files
mstsirkinNicholas Bellinger
authored andcommitted
tcm_vhost: Fix vhost_scsi_target structure alignment
Here TRANSPORT_IQN_LEN is 224, which is a multiple of 4. Since vhost_tpgt is 2 bytes and abi_version is 4, the total size would be 230. But gcc needs struct size be aligned to first field size, which is 4 bytes, so it pads the structure by extra 2 bytes to the total of 232. This padding is very undesirable in an ABI: - it can not be initialized easily - it can not be checked easily - it can leak information between kernel and userspace Simplest solution is probably just to make the padding explicit. (v2: Add check for zero'ed backend->reserved field for VHOST_SCSI_SET_ENDPOINT and VHOST_SCSI_CLEAR_ENDPOINT ops as requested by MST) Reported-by: Michael S. Tsirkin <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Signed-off-by: Nicholas Bellinger <[email protected]>
1 parent 74f4cf2 commit 6de7145

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

drivers/vhost/tcm_vhost.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,11 +995,15 @@ static long vhost_scsi_ioctl(struct file *f, unsigned int ioctl,
995995
case VHOST_SCSI_SET_ENDPOINT:
996996
if (copy_from_user(&backend, argp, sizeof backend))
997997
return -EFAULT;
998+
if (backend.reserved != 0)
999+
return -EOPNOTSUPP;
9981000

9991001
return vhost_scsi_set_endpoint(vs, &backend);
10001002
case VHOST_SCSI_CLEAR_ENDPOINT:
10011003
if (copy_from_user(&backend, argp, sizeof backend))
10021004
return -EFAULT;
1005+
if (backend.reserved != 0)
1006+
return -EOPNOTSUPP;
10031007

10041008
return vhost_scsi_clear_endpoint(vs, &backend);
10051009
case VHOST_SCSI_GET_ABI_VERSION:

drivers/vhost/tcm_vhost.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ struct vhost_scsi_target {
9393
int abi_version;
9494
char vhost_wwpn[TRANSPORT_IQN_LEN];
9595
unsigned short vhost_tpgt;
96+
unsigned short reserved;
9697
};
9798

9899
/* VHOST_SCSI specific defines */

0 commit comments

Comments
 (0)