Skip to content

Commit 18d6271

Browse files
cladischStefan Richter
authored andcommitted
firewire: prevent dropping of completed iso packet header data
The buffer for the header data of completed iso packets has a fixed size, so it is possible to configure a stream with a big interval between interrupt packets or with big headers so that this buffer would overflow. Previously, ohci.c would drop any data that would not fit, but this could make unsuspecting applications believe that fewer than the actual number of packets have completed. Instead of dropping data, add calls to flush_iso_completion() so that there are as many events as needed to report all of the data. Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
1 parent 910e76c commit 18d6271

3 files changed

Lines changed: 17 additions & 12 deletions

File tree

‎drivers/firewire/core-cdev.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
/*
5252
* ABI version history is documented in linux/firewire-cdev.h.
5353
*/
54-
#define FW_CDEV_KERNEL_VERSION 4
54+
#define FW_CDEV_KERNEL_VERSION 5
5555
#define FW_CDEV_VERSION_EVENT_REQUEST2 4
5656
#define FW_CDEV_VERSION_ALLOCATE_REGION_END 4
5757

‎drivers/firewire/ohci.c‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2689,7 +2689,7 @@ static void copy_iso_headers(struct iso_context *ctx, const u32 *dma_hdr)
26892689
u32 *ctx_hdr;
26902690

26912691
if (ctx->header_length + ctx->base.header_size > PAGE_SIZE)
2692-
return;
2692+
flush_iso_completions(ctx);
26932693

26942694
ctx_hdr = ctx->header + ctx->header_length;
26952695
ctx->last_timestamp = (u16)le32_to_cpu((__force __le32)dma_hdr[0]);
@@ -2826,16 +2826,16 @@ static int handle_it_packet(struct context *context,
28262826

28272827
sync_it_packet_for_cpu(context, d);
28282828

2829-
if (ctx->header_length + 4 < PAGE_SIZE) {
2830-
ctx_hdr = ctx->header + ctx->header_length;
2831-
/* Present this value as big-endian to match the receive code */
2832-
*ctx_hdr = cpu_to_be32(
2833-
((u32)le16_to_cpu(pd->transfer_status) << 16) |
2834-
le16_to_cpu(pd->res_count));
2835-
ctx->header_length += 4;
2836-
}
2829+
if (ctx->header_length + 4 > PAGE_SIZE)
2830+
flush_iso_completions(ctx);
28372831

2832+
ctx_hdr = ctx->header + ctx->header_length;
28382833
ctx->last_timestamp = le16_to_cpu(last->res_count);
2834+
/* Present this value as big-endian to match the receive code */
2835+
*ctx_hdr = cpu_to_be32((le16_to_cpu(pd->transfer_status) << 16) |
2836+
le16_to_cpu(pd->res_count));
2837+
ctx->header_length += 4;
2838+
28392839
if (last->control & cpu_to_le16(DESCRIPTOR_IRQ_ALWAYS))
28402840
flush_iso_completions(ctx);
28412841

‎include/linux/firewire-cdev.h‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,15 @@ struct fw_cdev_event_request2 {
207207
* @closure: See &fw_cdev_event_common;
208208
* set by %FW_CDEV_CREATE_ISO_CONTEXT ioctl
209209
* @type: See &fw_cdev_event_common; always %FW_CDEV_EVENT_ISO_INTERRUPT
210-
* @cycle: Cycle counter of the interrupt packet
210+
* @cycle: Cycle counter of the last completed packet
211211
* @header_length: Total length of following headers, in bytes
212212
* @header: Stripped headers, if any
213213
*
214214
* This event is sent when the controller has completed an &fw_cdev_iso_packet
215-
* with the %FW_CDEV_ISO_INTERRUPT bit set.
215+
* with the %FW_CDEV_ISO_INTERRUPT bit set, or when there have been so many
216+
* completed packets without the interrupt bit set that the kernel's internal
217+
* buffer for @header is about to overflow. (In the latter case, kernels with
218+
* ABI version < 5 drop header data up to the next interrupt packet.)
216219
*
217220
* Isochronous transmit events (context type %FW_CDEV_ISO_CONTEXT_TRANSMIT):
218221
*
@@ -440,6 +443,8 @@ union fw_cdev_event {
440443
* - added %FW_CDEV_EVENT_ISO_INTERRUPT_MULTICHANNEL,
441444
* %FW_CDEV_ISO_CONTEXT_RECEIVE_MULTICHANNEL, and
442445
* %FW_CDEV_IOC_SET_ISO_CHANNELS
446+
* 5 (3.4) - send %FW_CDEV_EVENT_ISO_INTERRUPT events when needed to
447+
* avoid dropping data
443448
*/
444449

445450
/**

0 commit comments

Comments
 (0)