From 9b72c3a0890317cca7baf47d8c052f04cb2f2f8b Mon Sep 17 00:00:00 2001 From: Simon South Date: Thu, 11 Jul 2019 18:21:42 -0400 Subject: [PATCH] kernel: Specify buffer size in certain ioctl calls. In cases where scsi_periph checks the size of the buffer supplied to an ioctl call (functionality added in commit ff4af513e1) this information needs to be provided by the caller to avoid failure. Fixes #15094. Change-Id: I37f2776edbe977e9825ec1837fb763a3b2aa7220 Reviewed-on: https://review.haiku-os.org/c/1584 Reviewed-by: waddlesplash --- src/add-ons/kernel/file_systems/cdda/cdda.cpp | 2 +- src/add-ons/kernel/partitioning_systems/session/Disc.cpp | 3 ++- src/add-ons/kernel/partitioning_systems/session/session.cpp | 2 +- src/system/kernel/disk_device_manager/KDiskDevice.cpp | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/add-ons/kernel/file_systems/cdda/cdda.cpp b/src/add-ons/kernel/file_systems/cdda/cdda.cpp index 9de57360ec..31bddb5ac7 100644 --- a/src/add-ons/kernel/file_systems/cdda/cdda.cpp +++ b/src/add-ons/kernel/file_systems/cdda/cdda.cpp @@ -559,7 +559,7 @@ read_table_of_contents(int fd, uint32 track, uint8 format, uint8 *buffer, raw.sense_data = senseData; raw.sense_data_length = sizeof(kSenseSize); - if (ioctl(fd, B_RAW_DEVICE_COMMAND, &raw) == 0 + if (ioctl(fd, B_RAW_DEVICE_COMMAND, &raw, sizeof(raw)) == 0 && raw.scsi_status == 0 && raw.cam_status == 1) { free(senseData); return B_OK; diff --git a/src/add-ons/kernel/partitioning_systems/session/Disc.cpp b/src/add-ons/kernel/partitioning_systems/session/Disc.cpp index b42254f7e2..fb102e3f05 100644 --- a/src/add-ons/kernel/partitioning_systems/session/Disc.cpp +++ b/src/add-ons/kernel/partitioning_systems/session/Disc.cpp @@ -277,7 +277,8 @@ read_table_of_contents(int deviceFD, uint32 first_session, uchar* buffer, memset(raw_command.sense_data, 0, raw_command.sense_data_length); raw_command.timeout = kScsiTimeout; - if (ioctl(deviceFD, B_RAW_DEVICE_COMMAND, &raw_command) == 0) { + if (ioctl(deviceFD, B_RAW_DEVICE_COMMAND, &raw_command, + sizeof(raw_command)) == 0) { if (raw_command.scsi_status == 0 && raw_command.cam_status == 1) { // SUCCESS!!! DBG(dump_full_table_of_contents(buffer, buffer_length)); diff --git a/src/add-ons/kernel/partitioning_systems/session/session.cpp b/src/add-ons/kernel/partitioning_systems/session/session.cpp index 8d9a7ff3ef..73fcbe0f49 100644 --- a/src/add-ons/kernel/partitioning_systems/session/session.cpp +++ b/src/add-ons/kernel/partitioning_systems/session/session.cpp @@ -48,7 +48,7 @@ identify_partition(int fd, partition_data *partition, void **cookie) float result = -1; if ((partition->flags & B_PARTITION_IS_DEVICE) != 0 && partition->block_size == 2048 - && ioctl(fd, B_GET_GEOMETRY, &geometry) == 0 + && ioctl(fd, B_GET_GEOMETRY, &geometry, sizeof(geometry)) == 0 && geometry.device_type == B_CD) { Disc *disc = new(std::nothrow) Disc(fd); if (disc != NULL && disc->InitCheck() == B_OK) { diff --git a/src/system/kernel/disk_device_manager/KDiskDevice.cpp b/src/system/kernel/disk_device_manager/KDiskDevice.cpp index 251c8a9a50..1756026497 100644 --- a/src/system/kernel/disk_device_manager/KDiskDevice.cpp +++ b/src/system/kernel/disk_device_manager/KDiskDevice.cpp @@ -358,7 +358,7 @@ status_t KDiskDevice::GetMediaStatus(status_t* mediaStatus) { status_t error = B_OK; - if (ioctl(fFD, B_GET_MEDIA_STATUS, mediaStatus) != 0) + if (ioctl(fFD, B_GET_MEDIA_STATUS, mediaStatus, sizeof(*mediaStatus)) != 0) error = errno; // maybe the device driver doesn't implement this ioctl -- see, if getting // the device geometry succeeds @@ -380,7 +380,7 @@ KDiskDevice::GetMediaStatus(status_t* mediaStatus) status_t KDiskDevice::GetGeometry(device_geometry* geometry) { - if (ioctl(fFD, B_GET_GEOMETRY, geometry) != 0) + if (ioctl(fFD, B_GET_GEOMETRY, geometry, sizeof(*geometry)) != 0) return errno; return B_OK; }