Skip to contentSkip to conversation

ALSA: fireface: fix info leak in hwdep_read()

PATCH In review Dan Carpenter 4 participants 9 messages Jan 21, 2021 – Jan 25, 2021

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

PATCH 1/1 ALSA: fireface: fix info leak in hwdep_read()

If "ff->dev_lock_changed" has not changed and "count" is too large then this will copy data beyond the end of the struct to user space.

Fixes f656edd5fb33 ("ALSA: fireface: add hwdep interface")
---
 sound/firewire/fireface/ff-hwdep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/firewire/fireface/ff-hwdep.c +1 -1
index 4b2e0dff5ddb..b84dde609a03 100644
@@ -35,12 +35,12 @@ static long hwdep_read(struct snd_hwdep *hwdep, char __user *buf,  long count,
 	}
 
 	memset(&event, 0, sizeof(event));
+	count = min_t(long, count, sizeof(event.lock_status));
 	if (ff->dev_lock_changed) {
 		event.lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS;
 		event.lock_status.status = (ff->dev_lock_count > 0);
 		ff->dev_lock_changed = false;
 
-		count = min_t(long, count, sizeof(event.lock_status));
 	}
 
 	spin_unlock_irq(&ff->lock);
Signature · 1 line
2.29.2
#1 lore raw

Hi Dan,

Le 21/01/2021 à 07:10, Dan Carpenter a écrit :

Quoted 1 line

If "ff->dev_lock_changed" has not changed

According to the "while (!ff->dev_lock_changed) { ... }" just above and the lock in place, can this ever happen?

In other word, I wonder if the "if (ff->dev_lock_changed)" test makes sense and if it could be removed.

(same for your other patch against sound/firewire/oxfw/oxfw-hwdep.c)

CJ

Quoted 28 lines

and "count" is too large then
this will copy data beyond the end of the struct to user space.

Fixes f656edd5fb33 ("ALSA: fireface: add hwdep interface")
---
  sound/firewire/fireface/ff-hwdep.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
sound/firewire/fireface/ff-hwdep.c +1 -1
index 4b2e0dff5ddb..b84dde609a03 100644
@@ -35,12 +35,12 @@ static long hwdep_read(struct snd_hwdep *hwdep, char __user *buf,  long count,
  	}
 
  	memset(&event, 0, sizeof(event));
+	count = min_t(long, count, sizeof(event.lock_status));
  	if (ff->dev_lock_changed) {
  		event.lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS;
  		event.lock_status.status = (ff->dev_lock_count > 0);
  		ff->dev_lock_changed = false;
 
-		count = min_t(long, count, sizeof(event.lock_status));
  	}
 
  	spin_unlock_irq(&ff->lock);
#2 lore raw
Quoted 5 lines · Christophe JAILLET

Hi Dan,

Le 21/01/2021 à 07:10, Dan Carpenter a écrit :

Quoted 1 line

If "ff->dev_lock_changed" has not changed

Quoted 9 lines

According to the "while (!ff->dev_lock_changed) { ... }" just above and the lock in place, can this ever happen?

In other word, I wonder if the "if (ff->dev_lock_changed)" test makes sense and if it could be removed.

(same for your other patch against sound/firewire/oxfw/oxfw-hwdep.c)

Yeah. That's a good point. I'll resend.

regards,
dan carpenter

#3 lore raw

PATCH v2 1/2 ALSA: oxfw: remove an unnecessary condition in hwdep_read()

Smatch complains that "count" isn't clamped properly and "oxfw->dev_lock_changed" is false then it leads to an information leak. But it turns out that "oxfw->dev_lock_changed" is always set and the condition can be removed.

---
v2: this version just removes the condition

 sound/firewire/oxfw/oxfw-hwdep.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
sound/firewire/oxfw/oxfw-hwdep.c +4 -6
index 9e1b3e151bad..a0fe99618554 100644
@@ -35,13 +35,11 @@ static long hwdep_read(struct snd_hwdep *hwdep, char __user *buf,  long count,
 	}
 
 	memset(&event, 0, sizeof(event));
-	if (oxfw->dev_lock_changed) {
-		event.lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS;
-		event.lock_status.status = (oxfw->dev_lock_count > 0);
-		oxfw->dev_lock_changed = false;
+	event.lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS;
+	event.lock_status.status = (oxfw->dev_lock_count > 0);
+	oxfw->dev_lock_changed = false;
 
-		count = min_t(long, count, sizeof(event.lock_status));
-	}
+	count = min_t(long, count, sizeof(event.lock_status));
 
 	spin_unlock_irq(&oxfw->lock);
 
Signature · 1 line
2.29.2
maintainer Acked-by on v2 1/2
#4 lore raw

Re: [PATCH v2 1/2] ALSA: oxfw: remove an unnecessary condition in hwdep_read()

Quoted 11 lines · Dan Carpenter

Smatch complains that "count" isn't clamped properly and "oxfw->dev_lock_changed" is false then it leads to an information leak. But it turns out that "oxfw->dev_lock_changed" is always set and the condition can be removed.

---
v2: this version just removes the condition

 sound/firewire/oxfw/oxfw-hwdep.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
Quoted 24 lines
sound/firewire/oxfw/oxfw-hwdep.c +4 -6
index 9e1b3e151bad..a0fe99618554 100644
@@ -35,13 +35,11 @@ static long hwdep_read(struct snd_hwdep *hwdep, char __user *buf,  long count,
 	}
 
 	memset(&event, 0, sizeof(event));
-	if (oxfw->dev_lock_changed) {
-		event.lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS;
-		event.lock_status.status = (oxfw->dev_lock_count > 0);
-		oxfw->dev_lock_changed = false;
+	event.lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS;
+	event.lock_status.status = (oxfw->dev_lock_count > 0);
+	oxfw->dev_lock_changed = false;
 
-		count = min_t(long, count, sizeof(event.lock_status));
-	}
+	count = min_t(long, count, sizeof(event.lock_status));
 
 	spin_unlock_irq(&oxfw->lock);
 
Signature · 1 line
2.29.2

Regards

Takashi Sakamoto

#5 lore raw

Re: [PATCH v2 1/2] ALSA: oxfw: remove an unnecessary condition in hwdep_read()

In reply to Dan Carpenter
Quoted 9 lines · Dan Carpenter

Smatch complains that "count" isn't clamped properly and "oxfw->dev_lock_changed" is false then it leads to an information leak. But it turns out that "oxfw->dev_lock_changed" is always set and the condition can be removed.

---
v2: this version just removes the condition

Applied now. Thanks.

Takashi

#6 lore raw

PATCH v2 2/2 ALSA: fireface: remove unnecessary condition in hwdep_read()

In reply to Dan Carpenter

Smatch complains that "count" is not clamped when "ff->dev_lock_changed" and it leads to an information leak. Fortunately, that's not actually possible and the condition can be deleted.

---
v2: just delet the condition

 sound/firewire/fireface/ff-hwdep.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
sound/firewire/fireface/ff-hwdep.c +4 -6
index 4b2e0dff5ddb..ea64a2a41eea 100644
@@ -35,13 +35,11 @@ static long hwdep_read(struct snd_hwdep *hwdep, char __user *buf,  long count,
 	}
 
 	memset(&event, 0, sizeof(event));
-	if (ff->dev_lock_changed) {
-		event.lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS;
-		event.lock_status.status = (ff->dev_lock_count > 0);
-		ff->dev_lock_changed = false;
+	event.lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS;
+	event.lock_status.status = (ff->dev_lock_count > 0);
+	ff->dev_lock_changed = false;
 
-		count = min_t(long, count, sizeof(event.lock_status));
-	}
+	count = min_t(long, count, sizeof(event.lock_status));
 
 	spin_unlock_irq(&ff->lock);
 
Signature · 1 line
2.29.2
maintainer Acked-by on v2 2/2
#7 lore raw

Re: [PATCH v2 2/2] ALSA: fireface: remove unnecessary condition in hwdep_read()

Hi,

Quoted 10 lines · Dan Carpenter

Smatch complains that "count" is not clamped when "ff->dev_lock_changed" and it leads to an information leak. Fortunately, that's not actually possible and the condition can be deleted.

---
v2: just delet the condition

 sound/firewire/fireface/ff-hwdep.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

ALSA firewire stack includes some drivers. Although some of them implement unique event as well as the lock event, the others supports the lock event only. The condition statement comes from the former, I guess. ALSA BeBoB, OXFW, and Fireface drivers are the latter. Later I'll post the similar patch for ALSA BeBoB driver.

Anyway, thank you to find the issue ;)

Quoted 24 lines
sound/firewire/fireface/ff-hwdep.c +4 -6
index 4b2e0dff5ddb..ea64a2a41eea 100644
@@ -35,13 +35,11 @@ static long hwdep_read(struct snd_hwdep *hwdep, char __user *buf,  long count,
 	}
 
 	memset(&event, 0, sizeof(event));
-	if (ff->dev_lock_changed) {
-		event.lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS;
-		event.lock_status.status = (ff->dev_lock_count > 0);
-		ff->dev_lock_changed = false;
+	event.lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS;
+	event.lock_status.status = (ff->dev_lock_count > 0);
+	ff->dev_lock_changed = false;
 
-		count = min_t(long, count, sizeof(event.lock_status));
-	}
+	count = min_t(long, count, sizeof(event.lock_status));
 
 	spin_unlock_irq(&ff->lock);
 
Signature · 1 line
2.29.2

Thanks

Takashi Sakamoto

#8 lore raw

Re: [PATCH v2 2/2] ALSA: fireface: remove unnecessary condition in hwdep_read()

In reply to Dan Carpenter
Quoted 8 lines · Dan Carpenter

Smatch complains that "count" is not clamped when "ff->dev_lock_changed" and it leads to an information leak. Fortunately, that's not actually possible and the condition can be deleted.

---
v2: just delet the condition

Applied now. Thanks.

Takashi