Skip to contentSkip to conversation

ALSA: dice: fix array limits in dice_proc_read()

PATCH Applied Dan Carpenter 4 participants 5 messages Nov 29, 2013

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

PATCH 1/1 ALSA: dice: fix array limits in dice_proc_read()

The array limits are supposed to be in units of u32 instead of in bytes. The current code has a potential array overflow.

Fixes c614475b0ea9 ('ALSA: dice: add a proc file to show device information')
sound/firewire/dice.c +2 -2
index 57bcd31fcc12..c0aa64941cee 100644
@@ -1019,7 +1019,7 @@ static void dice_proc_read(struct snd_info_entry *entry,
 
 	if (dice_proc_read_mem(dice, &tx_rx_header, sections[2], 2) < 0)
 		return;
-	quadlets = min_t(u32, tx_rx_header.size, sizeof(buf.tx));
+	quadlets = min_t(u32, tx_rx_header.size, sizeof(buf.tx) / 4);
 	for (stream = 0; stream < tx_rx_header.number; ++stream) {
 		if (dice_proc_read_mem(dice, &buf.tx, sections[2] + 2 +
 				       stream * tx_rx_header.size,
@@ -1045,7 +1045,7 @@ static void dice_proc_read(struct snd_info_entry *entry,
 
 	if (dice_proc_read_mem(dice, &tx_rx_header, sections[4], 2) < 0)
 		return;
-	quadlets = min_t(u32, tx_rx_header.size, sizeof(buf.rx));
+	quadlets = min_t(u32, tx_rx_header.size, sizeof(buf.rx) / 4);
 	for (stream = 0; stream < tx_rx_header.number; ++stream) {
 		if (dice_proc_read_mem(dice, &buf.rx, sections[4] + 2 +
 				       stream * tx_rx_header.size,
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Dan Carpenter

The array limits are supposed to be in units of u32 instead of in bytes. The current code has a potential array overflow.

Fixes c614475b0ea9 ('ALSA: dice: add a proc file to show device information')
Quoted 22 lines
sound/firewire/dice.c +2 -2
index 57bcd31fcc12..c0aa64941cee 100644
@@ -1019,7 +1019,7 @@ static void dice_proc_read(struct snd_info_entry *entry,
 
 	if (dice_proc_read_mem(dice, &tx_rx_header, sections[2], 2) < 0)
 		return;
-	quadlets = min_t(u32, tx_rx_header.size, sizeof(buf.tx));
+	quadlets = min_t(u32, tx_rx_header.size, sizeof(buf.tx) / 4);
 	for (stream = 0; stream < tx_rx_header.number; ++stream) {
 		if (dice_proc_read_mem(dice, &buf.tx, sections[2] + 2 +
 				       stream * tx_rx_header.size,
@@ -1045,7 +1045,7 @@ static void dice_proc_read(struct snd_info_entry *entry,
 
 	if (dice_proc_read_mem(dice, &tx_rx_header, sections[4], 2) < 0)
 		return;
-	quadlets = min_t(u32, tx_rx_header.size, sizeof(buf.rx));
+	quadlets = min_t(u32, tx_rx_header.size, sizeof(buf.rx) / 4);
 	for (stream = 0; stream < tx_rx_header.number; ++stream) {
 		if (dice_proc_read_mem(dice, &buf.rx, sections[4] + 2 +
 				       stream * tx_rx_header.size,
Applied
#2 lore raw
In reply to Dan Carpenter

At Fri, 29 Nov 2013 11:14:09 +0300,

Quoted 6 lines · Dan Carpenter

The array limits are supposed to be in units of u32 instead of in bytes. The current code has a potential array overflow.

Fixes c614475b0ea9 ('ALSA: dice: add a proc file to show device information')

Thanks, applied.

Takashi

Quoted 24 lines
sound/firewire/dice.c +2 -2
index 57bcd31fcc12..c0aa64941cee 100644
@@ -1019,7 +1019,7 @@ static void dice_proc_read(struct snd_info_entry *entry,
 
 	if (dice_proc_read_mem(dice, &tx_rx_header, sections[2], 2) < 0)
 		return;
-	quadlets = min_t(u32, tx_rx_header.size, sizeof(buf.tx));
+	quadlets = min_t(u32, tx_rx_header.size, sizeof(buf.tx) / 4);
 	for (stream = 0; stream < tx_rx_header.number; ++stream) {
 		if (dice_proc_read_mem(dice, &buf.tx, sections[2] + 2 +
 				       stream * tx_rx_header.size,
@@ -1045,7 +1045,7 @@ static void dice_proc_read(struct snd_info_entry *entry,
 
 	if (dice_proc_read_mem(dice, &tx_rx_header, sections[4], 2) < 0)
 		return;
-	quadlets = min_t(u32, tx_rx_header.size, sizeof(buf.rx));
+	quadlets = min_t(u32, tx_rx_header.size, sizeof(buf.rx) / 4);
 	for (stream = 0; stream < tx_rx_header.number; ++stream) {
 		if (dice_proc_read_mem(dice, &buf.rx, sections[4] + 2 +
 				       stream * tx_rx_header.size,
#3 lore raw
In reply to Dan Carpenter

Am 29.11.2013 09:14, schrieb Dan Carpenter:

Quoted 11 lines

The array limits are supposed to be in units of u32 instead of in bytes. The current code has a potential array overflow.

Fixes c614475b0ea9 ('ALSA: dice: add a proc file to show device information')
sound/firewire/dice.c +0 -0
index 57bcd31fcc12..c0aa64941cee 100644

sound/firewire/dice.c static void dice_proc_read(struct snd_info_entry *entry, · line 1022

Quoted 5 lines
sound/firewire/dice.c +1 -1
@@ -1019,7 +1019,7 @@ static void dice_proc_read(struct snd_info_entry *entry,
 
 	if (dice_proc_read_mem(dice, &tx_rx_header, sections[2], 2) < 0)
 		return;
-	quadlets = min_t(u32, tx_rx_header.size, sizeof(buf.tx));
+	quadlets = min_t(u32, tx_rx_header.size, sizeof(buf.tx) / 4);

it is a bit late but ...

sizeof(buf.tx) / 4 looks like ARRAY_SIZE(buf.tx)

If yes i suggest ARRAY_SIZE() because it gets rid of the "magic" 4.

re,
wh

Quoted 17 lines
sound/firewire/dice.c +1 -2
 	for (stream = 0; stream < tx_rx_header.number; ++stream) {
 		if (dice_proc_read_mem(dice, &buf.tx, sections[2] + 2 +
 				       stream * tx_rx_header.size,
@@ -1045,7 +1045,7 @@ static void dice_proc_read(struct snd_info_entry *entry,
 
 	if (dice_proc_read_mem(dice, &tx_rx_header, sections[4], 2) < 0)
 		return;
-	quadlets = min_t(u32, tx_rx_header.size, sizeof(buf.rx));
+	quadlets = min_t(u32, tx_rx_header.size, sizeof(buf.rx) / 4);
 	for (stream = 0; stream < tx_rx_header.number; ++stream) {
 		if (dice_proc_read_mem(dice, &buf.rx, sections[4] + 2 +
 				       stream * tx_rx_header.size,
--

To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw

At Fri, 29 Nov 2013 10:48:28 +0100,

Quoted 16 lines · walter harms

Am 29.11.2013 09:14, schrieb Dan Carpenter:

Quoted 12 lines

The array limits are supposed to be in units of u32 instead of in bytes. The current code has a potential array overflow.

Fixes c614475b0ea9 ('ALSA: dice: add a proc file to show device information')
sound/firewire/dice.c +0 -0
index 57bcd31fcc12..c0aa64941cee 100644
@@ -1019,7 +1019,7 @@ static void dice_proc_read(struct snd_info_entry *entry,
 
Quoted 8 lines

sound/firewire/dice.c static void dice_proc_read(struct snd_info_entry *entry, · line 1022

Quoted 4 lines
sound/firewire/dice.c +1 -1
 	if (dice_proc_read_mem(dice, &tx_rx_header, sections[2], 2) < 0)
 		return;
-	quadlets = min_t(u32, tx_rx_header.size, sizeof(buf.tx));
+	quadlets = min_t(u32, tx_rx_header.size, sizeof(buf.tx) / 4);

it is a bit late but ...

sizeof(buf.tx) / 4 looks like ARRAY_SIZE(buf.tx)

Not in this case :)
I thought of it at first, too, but understood it after reading the code.

Takashi

Quoted 25 lines

If yes i suggest ARRAY_SIZE() because it gets rid of the "magic" 4.

re,
wh

Quoted 17 lines
sound/firewire/dice.c +1 -2
 	for (stream = 0; stream < tx_rx_header.number; ++stream) {
 		if (dice_proc_read_mem(dice, &buf.tx, sections[2] + 2 +
 				       stream * tx_rx_header.size,
@@ -1045,7 +1045,7 @@ static void dice_proc_read(struct snd_info_entry *entry,
 
 	if (dice_proc_read_mem(dice, &tx_rx_header, sections[4], 2) < 0)
 		return;
-	quadlets = min_t(u32, tx_rx_header.size, sizeof(buf.rx));
+	quadlets = min_t(u32, tx_rx_header.size, sizeof(buf.rx) / 4);
 	for (stream = 0; stream < tx_rx_header.number; ++stream) {
 		if (dice_proc_read_mem(dice, &buf.rx, sections[4] + 2 +
 				       stream * tx_rx_header.size,
--

To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html