Skip to contentSkip to conversation

ide-tape: Don't leak kernel stack information

PATCH In review Michael Buesch 4 participants 8 messages Jul 19, 2009 – Jul 22, 2009 libata

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ide-tape: Don't leak kernel stack information

Don't leak kernel stack information through uninitialized structure members.

---

This patch is only compile tested.

---
 drivers/ide/ide-tape.c |    1 +
 1 file changed, 1 insertion(+)
drivers/ide/ide-tape.c +1 -0
@@ -1057,20 +1057,21 @@ static int idetape_blkdev_ioctl(ide_driv
 
 	debug_log(DBG_PROCS, "Enter %s\n", __func__);
 
 	switch (cmd) {
 	case 0x0340:
 		if (copy_from_user(&config, argp, sizeof(config)))
 			return -EFAULT;
 		tape->best_dsc_rw_freq = config.dsc_rw_frequency;
 		break;
 	case 0x0350:
+		memset(&config, 0, sizeof(config));
 		config.dsc_rw_frequency = (int) tape->best_dsc_rw_freq;
 		config.nr_stages = 1;
 		if (copy_to_user(argp, &config, sizeof(config)))
 			return -EFAULT;
 		break;
 	default:
 		return -EIO;
 	}
 	return 0;
 }
Signature · 1 line
Greetings, Michael.
#1 lore raw
Quoted 17 lines · Michael Buesch

Don't leak kernel stack information through uninitialized structure members.

---

This patch is only compile tested.

---
 drivers/ide/ide-tape.c |    1 +
 1 file changed, 1 insertion(+)
drivers/ide/ide-tape.c +0 -0
@@ -1057,20 +1057,21 @@ static int idetape_blkdev_ioctl(ide_driv
 

drivers/ide/ide-tape.c static int idetape_blkdev_ioctl(ide_driv · line 1067

Quoted 10 lines
drivers/ide/ide-tape.c +1 -0
 	debug_log(DBG_PROCS, "Enter %s\n", __func__);
 
 	switch (cmd) {
 	case 0x0340:
 		if (copy_from_user(&config, argp, sizeof(config)))
 			return -EFAULT;
 		tape->best_dsc_rw_freq = config.dsc_rw_frequency;
 		break;
 	case 0x0350:
+		memset(&config, 0, sizeof(config));

Well, I can't find config.dsc_media_access_frequency as being used anywhere since the git years of the kernel. I found¹ some archaic kernels from 1995 (1.3 series) which used to have IDETAPE_RESET_IOCTL defined as 0x0350 but can't seem to find any userspace use of that ioctl.

If there's none, you might just as well remove config.dsc_media_access_frequency as an alternative solution.

@Bart: Any historic info I'm missing here?

¹http://www.google.com/search?q=IDETAPE_RESET_IOCTL

Signature · 2 lines
Regards/Gruss,
    Boris.
#2 lore raw
Quoted 35 lines · On Monday 20 July 2009 09:38:14 Borislav Petkov wrote:
Quoted 17 lines · Michael Buesch

Don't leak kernel stack information through uninitialized structure members.

---

This patch is only compile tested.

---
 drivers/ide/ide-tape.c |    1 +
 1 file changed, 1 insertion(+)
drivers/ide/ide-tape.c +0 -0
@@ -1057,20 +1057,21 @@ static int idetape_blkdev_ioctl(ide_driv
 

drivers/ide/ide-tape.c static int idetape_blkdev_ioctl(ide_driv · line 1067

Quoted 10 lines
drivers/ide/ide-tape.c +1 -0
 	debug_log(DBG_PROCS, "Enter %s\n", __func__);
 
 	switch (cmd) {
 	case 0x0340:
 		if (copy_from_user(&config, argp, sizeof(config)))
 			return -EFAULT;
 		tape->best_dsc_rw_freq = config.dsc_rw_frequency;
 		break;
 	case 0x0350:
+		memset(&config, 0, sizeof(config));

Well, I can't find config.dsc_media_access_frequency as being used anywhere since the git years of the kernel. I found¹ some archaic kernels from 1995 (1.3 series) which used to have IDETAPE_RESET_IOCTL defined as 0x0350 but can't seem to find any userspace use of that ioctl.

Quoted 4 lines

If there's none, you might just as well remove config.dsc_media_access_frequency as an alternative solution.

@Bart: Any historic info I'm missing here?

We need to preserve struct idetape_config layout to not break the ioctl (regardless if the field is really used by some user-space apps or not)..

#3 lore raw
Quoted 36 lines · Bartlomiej Zolnierkiewicz
Quoted 35 lines · On Monday 20 July 2009 09:38:14 Borislav Petkov wrote:
Quoted 20 lines · Michael Buesch

Don't leak kernel stack information through uninitialized structure members.

---

This patch is only compile tested.

---
 drivers/ide/ide-tape.c |    1 +

 1 file changed, 1 insertion(+)
drivers/ide/ide-tape.c +0 -0
@@ -1057,20 +1057,21 @@ static int idetape_blkdev_ioctl(ide_driv
 
     debug_log(DBG_PROCS, "Enter %s\n", __func__);
 
     switch (cmd) {
Quoted 7 lines

    case 0x0340:
            if (copy_from_user(&config, argp, sizeof(config))) return -EFAULT; tape->best_dsc_rw_freq = config.dsc_rw_frequency; break;
    case 0x0350:
+           memset(&config, 0, sizeof(config));

Well, I can't find config.dsc_media_access_frequency as being used anywhere since the git years of the kernel. I found¹ some archaic kernels from 1995 (1.3 series) which used to have IDETAPE_RESET_IOCTL defined as 0x0350 but can't seem to find any userspace use of that ioctl.

Quoted 7 lines
Quoted 4 lines

If there's none, you might just as well remove config.dsc_media_access_frequency as an alternative solution.

@Bart: Any historic info I'm missing here?

We need to preserve struct idetape_config layout to not break the ioctl (regardless if the field is really used by some user-space apps or not)..

I know that. However, I can't seem to find any definition of that ioctl, ioctl_list(2) manpage doesn't document it, so my question was whether there is an agreed-upon definition of that ioctl and of struct config at all. If not, we could simply remove that variable since the struct layout is simply arbitrary in that case. Especially if there's no corresponing driver functionality on the kernel side which makes config.dsc_media_access_frequency the more useless.

Signature · 2 lines
Regards/Gruss,
Boris
#4 lore raw
Quoted 43 lines · On Monday 20 July 2009 12:45:37 Borislav Petkov wrote:
Quoted 41 lines · Bartlomiej Zolnierkiewicz
Quoted 39 lines · On Monday 20 July 2009 09:38:14 Borislav Petkov wrote:
Quoted 17 lines · Michael Buesch

Don't leak kernel stack information through uninitialized structure members.

---

This patch is only compile tested.

---
 drivers/ide/ide-tape.c |    1 +
 1 file changed, 1 insertion(+)
drivers/ide/ide-tape.c +0 -0
@@ -1057,20 +1057,21 @@ static int idetape_blkdev_ioctl(ide_driv
 

drivers/ide/ide-tape.c static int idetape_blkdev_ioctl(ide_driv · line 1067

Quoted 10 lines
drivers/ide/ide-tape.c +1 -0
    debug_log(DBG_PROCS, "Enter %s\n", __func__);
 
    switch (cmd) {
    case 0x0340:
            if (copy_from_user(&config, argp, sizeof(config)))
                    return -EFAULT;
            tape->best_dsc_rw_freq = config.dsc_rw_frequency;
            break;
    case 0x0350:
+           memset(&config, 0, sizeof(config));

Well, I can't find config.dsc_media_access_frequency as being used anywhere since the git years of the kernel. I found¹ some archaic kernels from 1995 (1.3 series) which used to have IDETAPE_RESET_IOCTL defined as 0x0350 but can't seem to find any userspace use of that ioctl.

If there's none, you might just as well remove config.dsc_media_access_frequency as an alternative solution.

@Bart: Any historic info I'm missing here?

Quoted 8 lines
Quoted 2 lines

We need to preserve struct idetape_config layout to not break the ioctl (regardless if the field is really used by some user-space apps or not)..

I know that. However, I can't seem to find any definition of that ioctl, ioctl_list(2) manpage doesn't document it, so my question was whether there is an agreed-upon definition of that ioctl and of struct config at all. If not, we could simply remove that variable since the struct layout is simply arbitrary in that case. Especially if there's

It is not, user-space (theoretically) depends on the current layout (we copy_to_user() the _whole_ structure).

Quoted 2 lines

no corresponing driver functionality on the kernel side which makes config.dsc_media_access_frequency the more useless.

We don't do arbitrary changes to existing ioctls.

Either it stays the way it is or we may eventually remove it completely (if really nothing uses it, though I still don't see much point in it given "the deep maintenance" mode of IDE subsystem).

#5 lore raw

On Tue, Jul 21, 2009 at 2:10 PM, Bartlomiej
Zolnierkiewicz<[email protected]> wrote:

[..]

Quoted 3 lines

Either it stays the way it is or we may eventually remove it completely (if really nothing uses it, though I still don't see much point in it given "the deep maintenance" mode of IDE subsystem).

Ok, let's opt for the less intrusive/no breakage option. The deep maintenance mode argument clearly prevails here.

Signature · 2 lines
Regards/Gruss,
Boris
#6 lore raw

From: Borislav Petkov <[email protected]>
Date: Mon, 20 Jul 2009 14:49:12 +0200

Quoted 5 lines

On Tue, Jul 21, 2009 at 2:10 PM, Bartlomiej
Zolnierkiewicz<[email protected]> wrote:

[..]

Quoted 8 lines
Quoted 3 lines

Either it stays the way it is or we may eventually remove it completely (if really nothing uses it, though I still don't see much point in it given "the deep maintenance" mode of IDE subsystem).

Ok, let's opt for the less intrusive/no breakage option. The deep maintenance mode argument clearly prevails here.

Agreed, applied and queued to -stable, thanks.

#7 lore raw
In reply to Borislav Petkov
Quoted 35 lines · On Monday 20 July 2009 09:38:14 Borislav Petkov wrote:
Quoted 17 lines · Michael Buesch

Don't leak kernel stack information through uninitialized structure members.

---

This patch is only compile tested.

---
 drivers/ide/ide-tape.c |    1 +
 1 file changed, 1 insertion(+)
drivers/ide/ide-tape.c +0 -0
@@ -1057,20 +1057,21 @@ static int idetape_blkdev_ioctl(ide_driv
 

drivers/ide/ide-tape.c static int idetape_blkdev_ioctl(ide_driv · line 1067

Quoted 10 lines
drivers/ide/ide-tape.c +1 -0
 	debug_log(DBG_PROCS, "Enter %s\n", __func__);
 
 	switch (cmd) {
 	case 0x0340:
 		if (copy_from_user(&config, argp, sizeof(config)))
 			return -EFAULT;
 		tape->best_dsc_rw_freq = config.dsc_rw_frequency;
 		break;
 	case 0x0350:
+		memset(&config, 0, sizeof(config));

Well, I can't find config.dsc_media_access_frequency as being used anywhere since the git years of the kernel. I found¹ some archaic kernels from 1995 (1.3 series) which used to have IDETAPE_RESET_IOCTL defined as 0x0350 but can't seem to find any userspace use of that ioctl.

Quoted 8 lines

If there's none, you might just as well remove config.dsc_media_access_frequency as an alternative solution.

@Bart: Any historic info I'm missing here?

¹http://www.google.com/search?q=IDETAPE_RESET_IOCTL

Well, I don't feel so good changing the ABI of ancient drivers. So I think it's best to just fix the bug (zero out the struct) instead of removing the whole call. Who knows. Maybe some proprietary program in the depths of some corporation's servers uses this ioctl...

So let's just zero out the structure properly to avoid the possibility of leaking kernel stack information.

Signature · 1 line
Greetings, Michael.