Skip to contentSkip to conversation

ALSA: compress: avoid integer overflow for long duration offload playback

PATCH In review [email protected] 3 participants 3 messages Jun 18, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: compress: avoid integer overflow for long duration offload playback

From: Banajit Goswami <[email protected]>

Currently a 32 bit variable is used for storing number of bytes copied to DSP, which can overflow when playback continues for a long duration.
Change data type for this variable to __u64 to prevent overflow.

---
 include/uapi/sound/compress_offload.h | 2 +-
 sound/core/compress_offload.c         | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
include/uapi/sound/compress_offload.h +1 -1
index 56d9567..db5edf3 100644
@@ -67,7 +67,7 @@ struct snd_compr_params {
  */
 struct snd_compr_tstamp {
 	__u32 byte_offset;
-	__u32 copied_total;
+	__u64 copied_total;
 	__u32 pcm_frames;
 	__u32 pcm_io_frames;
 	__u32 sampling_rate;
sound/core/compress_offload.c +1 -1
index a1a6fd7..2d0a709 100644
@@ -184,7 +184,7 @@ static int snd_compr_update_tstamp(struct snd_compr_stream *stream,
 	if (!stream->ops->pointer)
 		return -ENOTSUPP;
 	stream->ops->pointer(stream, tstamp);
-	pr_debug("dsp consumed till %d total %d bytes\n",
+	pr_debug("dsp consumed till %d total %llu bytes\n",
 		tstamp->byte_offset, tstamp->copied_total);
 	if (stream->direction == SND_COMPRESS_PLAYBACK)
 		stream->runtime->total_bytes_transferred = tstamp->copied_total;
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#1 lore raw
Quoted 6 lines · On 6/18/19 9:44 AM, [email protected] wrote:

From: Banajit Goswami <[email protected]>

Currently a 32 bit variable is used for storing number of bytes copied to DSP, which can overflow when playback continues for a long duration.
Change data type for this variable to __u64 to prevent overflow.

This clearly looks like a bug, the number of bytes transferred is stored as u64 in the runtime. I have no memories of this being intentional.

That said, it seems odd to me that you have an overflow on the number of bytes but not on the number of PCM frames. Shouldn't both the pcm_frames and pcm_io_frames fields also be changed to u64 while we are at it?

And the second issue is that this may impact apps. This is a ABI change, isn't it?

Quoted 35 lines
---
  include/uapi/sound/compress_offload.h | 2 +-
  sound/core/compress_offload.c         | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
include/uapi/sound/compress_offload.h +1 -1
index 56d9567..db5edf3 100644
@@ -67,7 +67,7 @@ struct snd_compr_params {
   */
  struct snd_compr_tstamp {
  	__u32 byte_offset;
-	__u32 copied_total;
+	__u64 copied_total;
  	__u32 pcm_frames;
  	__u32 pcm_io_frames;
  	__u32 sampling_rate;
sound/core/compress_offload.c +1 -1
index a1a6fd7..2d0a709 100644
@@ -184,7 +184,7 @@ static int snd_compr_update_tstamp(struct snd_compr_stream *stream,
  	if (!stream->ops->pointer)
  		return -ENOTSUPP;
  	stream->ops->pointer(stream, tstamp);
-	pr_debug("dsp consumed till %d total %d bytes\n",
+	pr_debug("dsp consumed till %d total %llu bytes\n",
  		tstamp->byte_offset, tstamp->copied_total);
  	if (stream->direction == SND_COMPRESS_PLAYBACK)
  		stream->runtime->total_bytes_transferred = tstamp->copied_total;
#2 lore raw
Quoted 13 lines · Pierre-Louis Bossart
Quoted 6 lines · On 6/18/19 9:44 AM, [email protected] wrote:

From: Banajit Goswami <[email protected]>

Currently a 32 bit variable is used for storing number of bytes copied to DSP, which can overflow when playback continues for a long duration.
Change data type for this variable to __u64 to prevent overflow.

This clearly looks like a bug, the number of bytes transferred is stored as u64 in the runtime. I have no memories of this being intentional.

Quoted 7 lines

That said, it seems odd to me that you have an overflow on the number of bytes but not on the number of PCM frames. Shouldn't both the pcm_frames and pcm_io_frames fields also be changed to u64 while we are at it?

And the second issue is that this may impact apps. This is a ABI change, isn't it?

Yes, it breaks ABI, and we can't take this as is.

If we need 64bit values, a new ioctl must be provided while keeping the old one still working.

thanks,

Takashi

Quoted 41 lines
Quoted 27 lines
---
  include/uapi/sound/compress_offload.h | 2 +-
  sound/core/compress_offload.c         | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
include/uapi/sound/compress_offload.h +1 -1
index 56d9567..db5edf3 100644
@@ -67,7 +67,7 @@ struct snd_compr_params {
   */
  struct snd_compr_tstamp {
  	__u32 byte_offset;
-	__u32 copied_total;
+	__u64 copied_total;
  	__u32 pcm_frames;
  	__u32 pcm_io_frames;
  	__u32 sampling_rate;
sound/core/compress_offload.c +0 -0
index a1a6fd7..2d0a709 100644

sound/core/compress_offload.c static int snd_compr_update_tstamp(struct snd_compr_stream *stream, · line 190

Quoted 8 lines
sound/core/compress_offload.c +1 -1
@@ -184,7 +184,7 @@ static int snd_compr_update_tstamp(struct snd_compr_stream *stream,
  	if (!stream->ops->pointer)
  		return -ENOTSUPP;
  	stream->ops->pointer(stream, tstamp);
-	pr_debug("dsp consumed till %d total %d bytes\n",
+	pr_debug("dsp consumed till %d total %llu bytes\n",
  		tstamp->byte_offset, tstamp->copied_total);
  	if (stream->direction == SND_COMPRESS_PLAYBACK)
  		stream->runtime->total_bytes_transferred = tstamp->copied_total;

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel