Skip to contentSkip to conversation

scsi: Silence unnecessary warnings about ioctl to partition

PATCH In review Jan Kara 5 participants 28 messages May 2, 2012 – Jun 15, 2012

Subsystems (2)
lore
Share & tools
lore

Jan Kara

author
#0 lore raw

PATCH 1/1 scsi: Silence unnecessary warnings about ioctl to partition

Sometimes, warnings about ioctls to partition happen often enough that they form majority of the warnings in the kernel log and users complain. In some cases warnings are about ioctls such as SG_IO so it's not good to get rid of the warnings completely as they can ease debugging of userspace problems when ioctl is refused.

Since I have seen warnings from lots of commands, including some proprietary userspace applications, I don't think disallowing the ioctls for processes with CAP_SYS_RAWIO will happen in the near future if ever. So lets just stop warning for processes with CAP_SYS_RAWIO for which ioctl is allowed.

CC Paolo Bonzini <[email protected]>
CC Jens Axboe <[email protected]>
CC James Bottomley <[email protected]>
---
 block/scsi_ioctl.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
block/scsi_ioctl.c +4 -1
index 260fa80..9a87daa 100644
@@ -721,11 +721,14 @@ int scsi_verify_blk_ioctl(struct block_device *bd, unsigned int cmd)
 		break;
 	}
 
+	if (capable(CAP_SYS_RAWIO))
+		return 0;
+
 	/* In particular, rule out all resets and host-specific ioctls.  */
 	printk_ratelimited(KERN_WARNING
 			   "%s: sending ioctl %x to a partition!\n", current->comm, cmd);
 
-	return capable(CAP_SYS_RAWIO) ? 0 : -ENOIOCTLCMD;
+	return -ENOIOCTLCMD;
 }
 EXPORT_SYMBOL(scsi_verify_blk_ioctl);
 
Signature · 1 line
1.7.1
#1 lore raw

Il 02/05/2012 12:10, Jan Kara ha scritto:

Quoted 10 lines

Sometimes, warnings about ioctls to partition happen often enough that they form majority of the warnings in the kernel log and users complain. In some cases warnings are about ioctls such as SG_IO so it's not good to get rid of the warnings completely as they can ease debugging of userspace problems when ioctl is refused.

Since I have seen warnings from lots of commands, including some proprietary userspace applications, I don't think disallowing the ioctls for processes with CAP_SYS_RAWIO will happen in the near future if ever. So lets just stop warning for processes with CAP_SYS_RAWIO for which ioctl is allowed.

NACK. I would bet that all the warnings you've seen are for ioctl that would have failed anyway with ENOTTY.

The right fix has already been posted, we've been carrying it in RHEL for over six months and not a single bug has been seen.

Paolo

maintainer
#2 lore raw
Quoted 12 lines · Paolo Bonzini

Il 02/05/2012 12:10, Jan Kara ha scritto:

Quoted 10 lines

Sometimes, warnings about ioctls to partition happen often enough that they form majority of the warnings in the kernel log and users complain. In some cases warnings are about ioctls such as SG_IO so it's not good to get rid of the warnings completely as they can ease debugging of userspace problems when ioctl is refused.

Since I have seen warnings from lots of commands, including some proprietary userspace applications, I don't think disallowing the ioctls for processes with CAP_SYS_RAWIO will happen in the near future if ever. So lets just stop warning for processes with CAP_SYS_RAWIO for which ioctl is allowed.

Quoted 5 lines

NACK. I would bet that all the warnings you've seen are for ioctl that would have failed anyway with ENOTTY.

The right fix has already been posted, we've been carrying it in RHEL for over six months and not a single bug has been seen.

I don't remember seeing the "right" fix. The messages are really annoying, so lets please get it resubmitted so that we can merge it.

Signature · 1 line
Jens Axboe
#3 lore raw
In reply to Paolo Bonzini
Quoted 7 lines · On Wed, 02 May 2012 12:15:10 +0200 Paolo Bonzini <[email protected]> wrote:

Il 02/05/2012 12:10, Jan Kara ha scritto:

Quoted 6 lines

Sometimes, warnings about ioctls to partition happen often enough that they form majority of the warnings in the kernel log and users complain. In some cases warnings are about ioctls such as SG_IO so it's not good to get rid of the warnings completely as they can ease debugging of userspace problems when ioctl is refused.

Quoted 7 lines
Quoted 4 lines

Since I have seen warnings from lots of commands, including some proprietary userspace applications, I don't think disallowing the ioctls for processes with CAP_SYS_RAWIO will happen in the near future if ever. So lets just stop warning for processes with CAP_SYS_RAWIO for which ioctl is allowed.

NACK. I would bet that all the warnings you've seen are for ioctl that would have failed anyway with ENOTTY.

Then we don't need the bogus warning do we.

Alan

#4 lore raw

Il 02/05/2012 12:54, Alan Cox ha scritto:

Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

Since I have seen warnings from lots of commands, including some proprietary userspace applications, I don't think disallowing the ioctls for processes with CAP_SYS_RAWIO will happen in the near future if ever. So lets just stop warning for processes with CAP_SYS_RAWIO for which ioctl is allowed.

NACK. I would bet that all the warnings you've seen are for ioctl that would have failed anyway with ENOTTY.

Then we don't need the bogus warning do we.

Sure, but then disallowing the ioctls for processes with CAP_SYS_RAWIO will not cause regressions and _can_ happen. The transition period only needs to be prolonged for SG_IO, the only one that was reported in the wild, until people have time to fix their bugs or (I hope not) we give up and implement a very restrictive filter for SCSI commands sent to partition.

The right patch is one that prepares for these step,
http://permalink.gmane.org/gmane.linux.kernel/1254625 for example. It leaves the warning only for SG_IO, and silently blocks the rest (more rationale in the commit message there).

However, that patch should be applied only at the beginning of the merge window, not at the end of the release cycle.

Paolo

#5 lore raw
Quoted 2 lines

Sure, but then disallowing the ioctls for processes with CAP_SYS_RAWIO will not cause regressions and _can_ happen. The transition period only

The user has CAP_SYS_RAWIO, they can already do it by poking the registers on the chip directly. It is a nonsense to attempt to block or warn about this.

Quoted 2 lines

up and implement a very restrictive filter for SCSI commands sent to partition.

The process has CAP_SYS_RAWIO it can already bypass any check you try and put in place.

Quoted 1 line

The right patch is one that prepares for these step,

Doesn't look very right to me.

Quoted 3 lines

http://permalink.gmane.org/gmane.linux.kernel/1254625 for example. It leaves the warning only for SG_IO, and silently blocks the rest (more rationale in the commit message there).

Even the printk in that patch is wrong. We have capabilities. Being a "root" user is a meaningless distinction here so your ratelimited printk isn't just bogus - its wrong. It may have got into RHEL somehow but the kernel QA process is a bit higher standard than this proposed patch.

A process with CAP_SYS_RAWIO has total power. It's assumed to know what it is doing. Trying to block it doing stuff like that simply makes authors do them via different more crass methods.

Alan

#6 lore raw

Il 02/05/2012 13:12, Alan Cox ha scritto:

Quoted 6 lines
Quoted 2 lines

Sure, but then disallowing the ioctls for processes with CAP_SYS_RAWIO will not cause regressions and _can_ happen. The transition period only

The user has CAP_SYS_RAWIO, they can already do it by poking the registers on the chip directly. It is a nonsense to attempt to block or warn about this.

Not true, for example CAP_SYS_RAWIO is still subject to access control.
Even simple Unix DAC can prevent you from issuing register writes to
/dev/sdb, while letting you do so on /dev/sda and access /dev/sdb1. I'm not inventing anything, the old ATA subsystem is already blocking most "dangerous" ioctls for partitions, even if you have CAP_SYS_RAWIO.

Now of course CAP_SYS_RAWIO lets you use ioperm or iopl, but that's a separate issue and only limited to x86.

Quoted 5 lines
Quoted 2 lines

up and implement a very restrictive filter for SCSI commands sent to partition.

The process has CAP_SYS_RAWIO it can already bypass any check you try and put in place.

Almost any capability can be abused to bypass checks. True, CAP_SYS_RAWIO is especially good at that, but still you can try.

Quoted 4 lines
Quoted 1 line

The right patch is one that prepares for these step,

Doesn't look very right to me.

Quoted 8 lines
Quoted 3 lines

http://permalink.gmane.org/gmane.linux.kernel/1254625 for example. It leaves the warning only for SG_IO, and silently blocks the rest (more rationale in the commit message there).

Even the printk in that patch is wrong. We have capabilities. Being a "root" user is a meaningless distinction here so your ratelimited printk isn't just bogus - its wrong. It may have got into RHEL somehow but the kernel QA process is a bit higher standard than this proposed patch.

Indeed, RHEL doesn't have the warning at all and blocks all ioctls including SG_IO (and in the past six months nobody has complained that something stopped working for them). Never said the patch is perfect...

Quoted 3 lines

A process with CAP_SYS_RAWIO has total power. It's assumed to know what it is doing. Trying to block it doing stuff like that simply makes authors do them via different more crass methods.

Getting appropriate permission on device nodes is less crass than abusing partition device nodes.

Paolo

#7 lore raw
Quoted 2 lines

not inventing anything, the old ATA subsystem is already blocking most "dangerous" ioctls for partitions, even if you have CAP_SYS_RAWIO.

It blocked a few by default to protect hardware. It's a tricky tradeoff, which is quite different to this.

Quoted 2 lines

Now of course CAP_SYS_RAWIO lets you use ioperm or iopl, but that's a separate issue and only limited to x86.

Ie only 99.99% of the systems running desktop/server Linux OS designs.

Quoted 2 lines

Almost any capability can be abused to bypass checks. True, CAP_SYS_RAWIO is especially good at that, but still you can try.

Why try - you are seeking to arbitarily impose your own worldview on the interface (and in doing so break back compatibility). The whole basis of the Unix philosophy is that the OS shouldn't try and micromanage the priviledged apps because that just leads to crap code.

Think "small government" on this aspect of design. And with the patch you propose the analogy for your patch is the TSA.

Quoted 6 lines
Quoted 3 lines

A process with CAP_SYS_RAWIO has total power. It's assumed to know what it is doing. Trying to block it doing stuff like that simply makes authors do them via different more crass methods.

Getting appropriate permission on device nodes is less crass than abusing partition device nodes.

Given a passed file handle how do you do that securely. Remember that open /dev/foo while you have a handle on /dev/foo1 could open a different disk if a hotplug has occurred.

So there are good reasons to keep the partition behaviour.

Alan

#8 lore raw
Quoted 7 lines
Quoted 4 lines

not inventing anything, the old ATA subsystem is already blocking most
"dangerous" ioctls for partitions, even if you have CAP_SYS_RAWIO.

It blocked a few by default to protect hardware. It's a tricky tradeoff, which is quite different to this.

I agree it's tricky.

Quoted 5 lines
Quoted 2 lines

Now of course CAP_SYS_RAWIO lets you use ioperm or iopl, but that's a separate issue and only limited to x86.

Ie only 99.99% of the systems running desktop/server Linux OS designs.

You can still block those in other ways, seccompv2 could be one.

Quoted 7 lines
Quoted 2 lines

Almost any capability can be abused to bypass checks. True, CAP_SYS_RAWIO is especially good at that, but still you can try.

Why try - you are seeking to arbitarily impose your own worldview on the interface (and in doing so break back compatibility). The whole basis of the Unix philosophy is that the OS shouldn't try and micromanage the priviledged apps because that just leads to crap code.

The whole point of capabilities, SELinux, etc. is micromanaging privileged apps. Linux has gone beyond the Unix philosophy, it seems.

Besides, privileged apps can and do use capabilities to micromanage themselves. Sure, ioperm/iopl do mean that a compromised CAP_SYS_RAWIO app has free reins. However, until that app is compromised, it may like to get help from the OS in making effective use of access control.

Quoted 10 lines
Quoted 6 lines
Quoted 3 lines

A process with CAP_SYS_RAWIO has total power. It's assumed to know what it is doing. Trying to block it doing stuff like that simply makes authors do them via different more crass methods.

Getting appropriate permission on device nodes is less crass than abusing partition device nodes.

Given a passed file handle how do you do that securely. Remember that open /dev/foo while you have a handle on /dev/foo1 could open a different disk if a hotplug has occurred.

What is the exact use case for this, where you wouldn't have gotten an fd for /dev/foo in the first place? And what command do you want to send to the disk? The only "valid" case found in the wild was using SG_IO to send "SYNCHRONIZE CACHE", which is wrong anyway (does not flush the OS cache). fdatasync could and should have been used instead.

Paolo

author
#19 lore raw
In reply to Paolo Bonzini
Quoted 7 lines · Paolo Bonzini

Il 02/05/2012 12:10, Jan Kara ha scritto:

Quoted 6 lines

Sometimes, warnings about ioctls to partition happen often enough that they form majority of the warnings in the kernel log and users complain. In some cases warnings are about ioctls such as SG_IO so it's not good to get rid of the warnings completely as they can ease debugging of userspace problems when ioctl is refused.

Quoted 7 lines
Quoted 4 lines

Since I have seen warnings from lots of commands, including some proprietary userspace applications, I don't think disallowing the ioctls for processes with CAP_SYS_RAWIO will happen in the near future if ever. So lets just stop warning for processes with CAP_SYS_RAWIO for which ioctl is allowed.

NACK. I would bet that all the warnings you've seen are for ioctl that would have failed anyway with ENOTTY.

Actually, you would loose the bet ;) The customer was complaining about
warning about SG_IO ioctl. Apparently some Veritas filesystem thread generates a *lot* of these (I don't know if they happen to do all the filesystem IO with SG_IO and I'm not sure I want to know ;). Given this I don't think we want to block SG_IO for CAP_SYS_RAWIO threads in the near future if ever...

Quoted 2 lines

The right fix has already been posted, we've been carrying it in RHEL for over six months and not a single bug has been seen.

Your patch won't work for our customer because you still generate
messages for SG_IO. Also I tend to side with Alan that I don't quite see the point in trying to restrict CAP_SYS_RAWIO threads and thus breaking the compatibility (if ioctls would be restricted for partitions from the beginning, then sure it seems like a cleaner choice). But I don't feel that strongly about it.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#20 lore raw

Il 02/05/2012 15:51, Jan Kara ha scritto:

Quoted 3 lines
Quoted 2 lines
Quoted 2 lines

NACK. I would bet that all the warnings you've seen are for ioctl that would have failed anyway with ENOTTY.

Actually, you would loose the bet ;)

Doh. :)

Quoted 4 lines

The customer was complaining about
warning about SG_IO ioctl. Apparently some Veritas filesystem thread generates a *lot* of these (I don't know if they happen to do all the filesystem IO with SG_IO and I'm not sure I want to know ;).

Can you at least ask the customer for help finding which command was sent? And perhaps have them try a kernel that blocks SG_IO to see what breaks if anything?

Quoted 3 lines

Also I tend to side with Alan that I don't quite see
the point in trying to restrict CAP_SYS_RAWIO threads and thus breaking the compatibility

For example, we have a customer that wants this:

* a VM should be able to send vendor-specific commands to a disk via SG_IO (vendor-specific commands require CAP_SYS_RAWIO).

* they want to assign logical volumes or partitions to the same VM without letting it read or write outside the logical volume or partition.

Of course a better solution for this would be customizable filters for SG_IO commands, where a privileged application would open the block device with CAP_SYS_RAWIO, set the filter and hand the file descriptor to QEMU. Or alternatively some extension of the device cgroup. But either solution would require a large amount of work.

Paolo

Quoted 3 lines

(if ioctls would be restricted for partitions from the beginning, then sure it seems like a cleaner choice). But I don't feel that strongly about it.

#21 lore raw
Quoted 11 lines
Quoted 3 lines

Also I tend to side with Alan that I don't quite see
the point in trying to restrict CAP_SYS_RAWIO threads and thus breaking the compatibility

For example, we have a customer that wants this:

* a VM should be able to send vendor-specific commands to a disk via SG_IO (vendor-specific commands require CAP_SYS_RAWIO).

* they want to assign logical volumes or partitions to the same VM without letting it read or write outside the logical volume or partition.

And if the process has CAP_SYS_RAWIO it can do it anyway. So not only is your agenda destructive - it doesn't actually work.

Quoted 5 lines

Of course a better solution for this would be customizable filters for SG_IO commands, where a privileged application would open the block device with CAP_SYS_RAWIO, set the filter and hand the file descriptor to QEMU. Or alternatively some extension of the device cgroup. But either solution would require a large amount of work.

Or you could just do the special case ioctl magic out of band in the apps. It's hardly an ultra performance critical path for the SG_IO cases.

Customisable filters are not hard. We've got all the filtering code in kernel and the ability to verify filters, even the ability to JIT them. Just support adding/removing/running a BPF filter on the channel in question.

So it shouldn't be much code to do what you want.

Alan

Acked-by
#22 lore raw

Il 02/05/2012 17:10, Alan Cox ha scritto:

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

Also I tend to side with Alan that I don't quite see
the point in trying to restrict CAP_SYS_RAWIO threads and thus breaking the compatibility

For example, we have a customer that wants this:

Quoted 7 lines
Quoted 5 lines

* a VM should be able to send vendor-specific commands to a disk via SG_IO (vendor-specific commands require CAP_SYS_RAWIO).

* they want to assign logical volumes or partitions to the same VM without letting it read or write outside the logical volume or partition.

And if the process has CAP_SYS_RAWIO it can do it anyway.

How so? Assuming /dev/sdb is not accessible, /dev/sdb1 is accessible, and no iopl/ioperm.

Quoted 1 line

Or you could just do the special case ioctl magic out of band in the apps.

You mentioned crass/gross hacks. Forcing apps to detect if you're targeting a partition or a block device _is_ gross.

Quoted 1 line

It's hardly an ultra performance critical path for the SG_IO cases.

That I agree with.

Quoted 6 lines
Quoted 5 lines

Of course a better solution for this would be customizable filters for SG_IO commands, where a privileged application would open the block device with CAP_SYS_RAWIO, set the filter and hand the file descriptor to QEMU. Or alternatively some extension of the device cgroup. But either solution would require a large amount of work.

Quoted 6 lines

Customisable filters are not hard. We've got all the filtering code in kernel and the ability to verify filters, even the ability to JIT them. Just support adding/removing/running a BPF filter on the channel in question.

So it shouldn't be much code to do what you want.

Yes, it's not much code if I don't get into cgroups land and stick with a ioctl to add and remove BPF filters that look at CDBs. One downside is that such filtering would likely be enabled by CAP_SYS_RAWIO. Because of this, tweaking the filter on the fly is still not too easy because I want to run as unprivileged as possible. I guess some privileged helper program can set the filter and send me back the file descriptor via SCM_RIGHTS. The filter will be preserved across that, right?

I still believe this is suboptimal in the general case, and that Jan's customer has a bug. But hey I would have ended up implementing the filters anyway sooner or later, so I'd rather avoid further flames and work on them with someone supporting the idea. :) Reluctantly

Paolo

#9 lore raw
In reply to Paolo Bonzini
Quoted 4 lines · Paolo Bonzini

Indeed, RHEL doesn't have the warning at all and blocks all ioctls including SG_IO (and in the past six months nobody has complained that something stopped working for them). Never said the patch is perfect...

hdparm.

author
#24 lore raw
In reply to Paolo Bonzini
Quoted 7 lines · Paolo Bonzini

Il 02/05/2012 15:51, Jan Kara ha scritto:

Quoted 3 lines
Quoted 2 lines
Quoted 2 lines

NACK. I would bet that all the warnings you've seen are for ioctl that would have failed anyway with ENOTTY.

Actually, you would loose the bet ;)

Doh. :)

Quoted 8 lines
Quoted 4 lines

The customer was complaining about
warning about SG_IO ioctl. Apparently some Veritas filesystem thread generates a *lot* of these (I don't know if they happen to do all the filesystem IO with SG_IO and I'm not sure I want to know ;).

Can you at least ask the customer for help finding which command was sent? And perhaps have them try a kernel that blocks SG_IO to see what breaks if anything?

I'm not sure they would be willing to try a different kernel because it's
a production system. But maybe I can find out what SG_IO command is sent via strace?

Quoted 11 lines
Quoted 3 lines

Also I tend to side with Alan that I don't quite see
the point in trying to restrict CAP_SYS_RAWIO threads and thus breaking the compatibility

For example, we have a customer that wants this:

* a VM should be able to send vendor-specific commands to a disk via SG_IO (vendor-specific commands require CAP_SYS_RAWIO).

* they want to assign logical volumes or partitions to the same VM without letting it read or write outside the logical volume or partition.

But then it seems like they really want to be able to forbid sending
SG_IO commands to some devices while allowing them for other devices and the distinction by partition / non-partition is a bit arbitrary?

Quoted 5 lines

Of course a better solution for this would be customizable filters for SG_IO commands, where a privileged application would open the block device with CAP_SYS_RAWIO, set the filter and hand the file descriptor to QEMU. Or alternatively some extension of the device cgroup. But either solution would require a large amount of work.

I'm not sure whether you need to filter individual SG_IO commands or not.
For your use case it seems that being able to forbid SG_IO completely for some fd (which would be passed to qemu) would be enough? But maybe filters are simpler to implement because they already exist, I don't really know...

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#23 lore raw
In reply to Paolo Bonzini

Il 02/05/2012 17:49, Paolo Bonzini ha scritto:

Quoted 8 lines
Quoted 6 lines
Quoted 6 lines

Customisable filters are not hard. We've got all the filtering code in kernel and the ability to verify filters, even the ability to JIT them. Just support adding/removing/running a BPF filter on the channel in question.

So it shouldn't be much code to do what you want.

Yes, it's not much code if I don't get into cgroups land and stick with a ioctl to add and remove BPF filters that look at CDBs.

Except that then I need to access some "struct file" member in SG_IO, thus changing ioctl from block_device/fmode to block_device/file. This would partially undo the 2007 switch from inode/file by Al Viro. Somehow I'm not that optimist anymore, though I'd be happy to be proven wrong.

Paolo

#25 lore raw
In reply to Jan Kara

Il 02/05/2012 21:49, Jan Kara ha scritto:

Quoted 3 lines

I'm not sure they would be willing to try a different kernel because it's
a production system. But maybe I can find out what SG_IO command is sent via strace?

Yes.

Hmm, you mentioned Veritas and that reminds me of
https://bugzilla.redhat.com/show_bug.cgi?id=740504. If that is the case, the filesystem is simply pinging the destination with INQUIRY commands, something for which it would be worthwhile to have a non-privileged ioctl anyway.

Quoted 9 lines
Quoted 9 lines
Quoted 3 lines

Also I tend to side with Alan that I don't quite see
the point in trying to restrict CAP_SYS_RAWIO threads and thus breaking the compatibility

For example, we have a customer that wants this:

* a VM should be able to send vendor-specific commands to a disk via SG_IO (vendor-specific commands require CAP_SYS_RAWIO).

Quoted 6 lines
Quoted 2 lines

* they want to assign logical volumes or partitions to the same VM without letting it read or write outside the logical volume or partition.

But then it seems like they really want to be able to forbid sending
SG_IO commands to some devices while allowing them for other devices and the distinction by partition / non-partition is a bit arbitrary?

Yes, forbidding SG_IO commands on some disks would be nice. Still, partition/non-partition is an important distinction. If you pass a whole disk and give CAP_SYS_RAWIO to QEMU, the guest may do some damage but not more than what a bare-metal system could do. If you pass a partition, the guest can stomp on other VMs or the host's data and even write them, which is a security problem.

So you could add a more restrictive filter to partitions, but then you're adding hack above hack to justify a wrong decision.

Quoted 10 lines
Quoted 5 lines

Of course a better solution for this would be customizable filters for SG_IO commands, where a privileged application would open the block device with CAP_SYS_RAWIO, set the filter and hand the file descriptor to QEMU. Or alternatively some extension of the device cgroup. But either solution would require a large amount of work.

I'm not sure whether you need to filter individual SG_IO commands or not.
For your use case it seems that being able to forbid SG_IO completely for some fd (which would be passed to qemu) would be enough? But maybe filters are simpler to implement because they already exist, I don't really know...

If you implement a yes/no toggle, some use case will pop up later for filters (in fact, a rudimentary filter based on CAP_SYS_RAWIO is _already_ in the kernel which already proves this).

Paolo

#10 lore raw
In reply to Mark Lord

Il 02/05/2012 21:38, Mark Lord ha scritto:

Quoted 6 lines
Quoted 4 lines
Quoted 4 lines

Indeed, RHEL doesn't have the warning at all and blocks all ioctls including SG_IO (and in the past six months nobody has complained that something stopped working for them). Never said the patch is perfect...

hdparm.

Breaking "hdparm --write-sector /dev/sda1"? I call it a security fix.

Paolo

#11 lore raw
Quoted 9 lines · Paolo Bonzini

Il 02/05/2012 21:38, Mark Lord ha scritto:

Quoted 6 lines
Quoted 4 lines
Quoted 4 lines

Indeed, RHEL doesn't have the warning at all and blocks all ioctls including SG_IO (and in the past six months nobody has complained that something stopped working for them). Never said the patch is perfect...

hdparm.

Breaking "hdparm --write-sector /dev/sda1"? I call it a security fix.

No, that would plain stupid on both our parts. :)
The --write-sector flag is allowed only for non-partitions by hdparm itself.

But other flags commonly used by distros at boot time seem to be triggering the current in-kernel noise. Dunno which flags, I'm just ignoring them and waiting for the noise message to get reverted.

Cheers

#12 lore raw

Il 03/05/2012 14:40, Mark Lord ha scritto:

Quoted 4 lines
Quoted 2 lines
Quoted 2 lines

Breaking "hdparm --write-sector /dev/sda1"? I call it a security fix.

No, that would plain stupid on both our parts. :)
The --write-sector flag is allowed only for non-partitions by hdparm itself.

Excuse my laziness--how does it check? Most programs I looked at check at the shape of the file and some are even fooled by "ln -sf /dev/sda1 ./sda".

Quoted 4 lines

But other flags commonly used by distros at boot time seem to be triggering the current in-kernel noise. Dunno which flags, I'm just ignoring them and waiting for the noise message to get reverted.

That's exactly the behavior I hoped to get when I added the warnings. Or maybe not. :) What are the messages? i.e. what ioctl do they complain about?

Paolo

#13 lore raw
Quoted 7 lines · Paolo Bonzini

Il 03/05/2012 14:40, Mark Lord ha scritto:

Quoted 4 lines
Quoted 2 lines
Quoted 2 lines

Breaking "hdparm --write-sector /dev/sda1"? I call it a security fix.

No, that would plain stupid on both our parts. :)
The --write-sector flag is allowed only for non-partitions by hdparm itself.

Excuse my laziness--how does it check?

I don't know if there's a feasible fool-proof method or not. But what hdparm does is look at the sector offset of the device. Partitions normally have a non-zero offset.

Quoted 8 lines
Quoted 4 lines

But other flags commonly used by distros at boot time seem to be triggering the current in-kernel noise. Dunno which flags, I'm just ignoring them and waiting for the noise message to get reverted.

That's exactly the behavior I hoped to get when I added the warnings. Or maybe not. :) What are the messages?
i.e. what ioctl do they complain about?

As above:

Quoted 2 lines
Quoted 2 lines

Dunno which flags, I'm just ignoring them and waiting for the noise message to get reverted.

#14 lore raw

Il 03/05/2012 19:36, Mark Lord ha scritto:

Quoted 4 lines
Quoted 1 line
Quoted 1 line

Excuse my laziness--how does it check?

I don't know if there's a feasible fool-proof method or not. But what hdparm does is look at the sector offset of the device. Partitions normally have a non-zero offset.

Yeah, that should work.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines

But other flags commonly used by distros at boot time seem to be triggering the current in-kernel noise. Dunno which flags, I'm just ignoring them and waiting for the noise message to get reverted.

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

That's exactly the behavior I hoped to get when I added the warnings. Or maybe not. :) What are the messages?
i.e. what ioctl do they complain about?

As above:

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Dunno which flags, I'm just ignoring them and waiting for the noise message to get reverted.

I said which ioctls, not which options. I.e. cut-and-paste from dmesg.

Paolo

#15 lore raw
Quoted 6 lines · Paolo Bonzini

Il 03/05/2012 19:36, Mark Lord ha scritto:

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Dunno which flags, I'm just ignoring them and waiting for the noise message to get reverted.

I said which ioctls, not which options. I.e. cut-and-paste from dmesg.

Here are some:

messages.1:Apr 28 14:08:09 zbox5 kernel: [  268.800536] hdparm: sending ioctl 330 to a partition!
messages.1:Apr 28 14:08:09 zbox5 kernel: [  268.800547] hdparm: sending ioctl 330 to a partition!
messages.1:Apr 28 14:08:57 zbox5 kernel: [  316.413944] hdparm: sending ioctl 330 to a partition!
messages.1:Apr 28 14:08:57 zbox5 kernel: [  316.413951] hdparm: sending ioctl 330 to a partition!
messages.1:Apr 28 14:20:10 zbox5 kernel: [  989.525085] hdparm: sending ioctl 330 to a partition!
messages.1:Apr 28 14:20:10 zbox5 kernel: [  989.525093] hdparm: sending ioctl 330 to a partition!

The in <linux/hdreg.h> say this about 330:

...
/* 0x330 is reserved - used to be HDIO_GETGEO_BIG */
...

So it's HDIO_GETGEO_BIG, which doesn't exist in newer kernels. I wonder when that got removed? Minor userspace breakage there.

hdparm issues it first as a backward-compatibility thing, before falling back to the even-more obsolete HDIO_GETGEO, which curiously enough is still in modern kernels.

Cheers

#16 lore raw

Il 04/05/2012 15:06, Mark Lord ha scritto:

Quoted 2 lines
Quoted 1 line
Quoted 1 line

I said which ioctls, not which options. I.e. cut-and-paste from dmesg.

Here are some:

Thanks!

Quoted 13 lines
messages.1:Apr 28 14:08:09 zbox5 kernel: [  268.800536] hdparm: sending ioctl 330 to a partition!
messages.1:Apr 28 14:08:09 zbox5 kernel: [  268.800547] hdparm: sending ioctl 330 to a partition!
messages.1:Apr 28 14:08:57 zbox5 kernel: [  316.413944] hdparm: sending ioctl 330 to a partition!
messages.1:Apr 28 14:08:57 zbox5 kernel: [  316.413951] hdparm: sending ioctl 330 to a partition!
messages.1:Apr 28 14:20:10 zbox5 kernel: [  989.525085] hdparm: sending ioctl 330 to a partition!
messages.1:Apr 28 14:20:10 zbox5 kernel: [  989.525093] hdparm: sending ioctl 330 to a partition!

The in <linux/hdreg.h> say this about 330:

...
/* 0x330 is reserved - used to be HDIO_GETGEO_BIG */
...

Quoted 6 lines

So it's HDIO_GETGEO_BIG, which doesn't exist in newer kernels. I wonder when that got removed? Minor userspace breakage there.

hdparm issues it first as a backward-compatibility thing, before falling back to the even-more obsolete HDIO_GETGEO, which curiously enough is still in modern kernels.

Ok, so hdparm is not broken. My patch (which left the warning only for SG_IO, and failed all other ioctls) would have worked, too.

Paolo

#17 lore raw
In reply to Mark Lord
Quoted 18 lines · Mark Lord
Quoted 6 lines · Paolo Bonzini

Il 03/05/2012 19:36, Mark Lord ha scritto:

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Dunno which flags, I'm just ignoring them and waiting for the noise message to get reverted.

I said which ioctls, not which options. I.e. cut-and-paste from dmesg.

Here are some:

messages.1:Apr 28 14:08:09 zbox5 kernel: [  268.800536] hdparm: sending ioctl 330 to a partition!
messages.1:Apr 28 14:08:09 zbox5 kernel: [  268.800547] hdparm: sending ioctl 330 to a partition!
messages.1:Apr 28 14:08:57 zbox5 kernel: [  316.413944] hdparm: sending ioctl 330 to a partition!
messages.1:Apr 28 14:08:57 zbox5 kernel: [  316.413951] hdparm: sending ioctl 330 to a partition!
messages.1:Apr 28 14:20:10 zbox5 kernel: [  989.525085] hdparm: sending ioctl 330 to a partition!
messages.1:Apr 28 14:20:10 zbox5 kernel: [  989.525093] hdparm: sending ioctl 330 to a partition!
Quoted 8 lines

The in <linux/hdreg.h> say this about 330:

...
/* 0x330 is reserved - used to be HDIO_GETGEO_BIG */
...

So it's HDIO_GETGEO_BIG, which doesn't exist in newer kernels. I wonder when that got removed? Minor userspace breakage there.

Looks like it got removed about 10 years ago, either in 2.5.xx or early 2.6.xx, so that's all fine now. hdparm still issues it for backward compatibility with kernels that lack more modern methods. Currently we don't try to inspect the kernel version at run-time, because version numbers are not as reliable as simply issuing the ioctl().

Quoted 10 lines

hdparm issues it first as a backward-compatibility thing, before falling back to the even-more obsolete HDIO_GETGEO, which curiously enough is still in modern kernels.

Cheers
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#18 lore raw
Quoted 1 line · Mark Lord

On 12-05-04 09:06 AM, Mark Lord wrote:

..

Quoted 10 lines
Quoted 9 lines

kernel: [ 989.525093] hdparm: sending ioctl 330 to a partition!

The in <linux/hdreg.h> say this about 330:
...
/* 0x330 is reserved - used to be HDIO_GETGEO_BIG */
...

So it's HDIO_GETGEO_BIG, which doesn't exist in newer kernels. I wonder when that got removed? Minor userspace breakage there.

Quoted 7 lines

Looks like it got removed about 10 years ago, either in 2.5.xx or early 2.6.xx, so that's all fine now. hdparm still issues it for backward compatibility with kernels that lack more modern methods. Currently we don't try to inspect the kernel version at run-time, because version numbers are not as reliable as simply issuing the ioctl().

I will update hdparm regardless (version 9.40, not out yet) to try and avoid HDIO_GETGEO_BIG when possible. It will still use it under some circumstances (like when sysfs isn't mounted, which should catch 2.4.xx kernels and older), but mostly not.

Cheers

#26 lore raw
In reply to Jan Kara

Il 02/05/2012 12:10, Jan Kara ha scritto:

Quoted 31 lines

Sometimes, warnings about ioctls to partition happen often enough that they form majority of the warnings in the kernel log and users complain. In some cases warnings are about ioctls such as SG_IO so it's not good to get rid of the warnings completely as they can ease debugging of userspace problems when ioctl is refused.

Since I have seen warnings from lots of commands, including some proprietary userspace applications, I don't think disallowing the ioctls for processes with CAP_SYS_RAWIO will happen in the near future if ever. So lets just stop warning for processes with CAP_SYS_RAWIO for which ioctl is allowed.

CC Paolo Bonzini <[email protected]>
CC Jens Axboe <[email protected]>
CC James Bottomley <[email protected]>
---
 block/scsi_ioctl.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
block/scsi_ioctl.c +2 -0
index 260fa80..9a87daa 100644
@@ -721,11 +721,14 @@ int scsi_verify_blk_ioctl(struct block_device *bd, unsigned int cmd)
 		break;
 	}
 
+	if (capable(CAP_SYS_RAWIO))
+		return 0;

block/scsi_ioctl.c int scsi_verify_blk_ioctl(struct block_device *bd, unsigned int cmd) · line 734

Quoted 10 lines
block/scsi_ioctl.c +2 -1
+
 	/* In particular, rule out all resets and host-specific ioctls.  */
 	printk_ratelimited(KERN_WARNING
 			   "%s: sending ioctl %x to a partition!\n", current->comm, cmd);
 
-	return capable(CAP_SYS_RAWIO) ? 0 : -ENOIOCTLCMD;
+	return -ENOIOCTLCMD;
 }
 EXPORT_SYMBOL(scsi_verify_blk_ioctl);
 

Ping?

Paolo

author
#27 lore raw
Quoted 36 lines · Paolo Bonzini

Il 02/05/2012 12:10, Jan Kara ha scritto:

Quoted 35 lines

Sometimes, warnings about ioctls to partition happen often enough that they form majority of the warnings in the kernel log and users complain. In some cases warnings are about ioctls such as SG_IO so it's not good to get rid of the warnings completely as they can ease debugging of userspace problems when ioctl is refused.

Since I have seen warnings from lots of commands, including some proprietary userspace applications, I don't think disallowing the ioctls for processes with CAP_SYS_RAWIO will happen in the near future if ever. So lets just stop warning for processes with CAP_SYS_RAWIO for which ioctl is allowed.

CC Paolo Bonzini <[email protected]>
CC Jens Axboe <[email protected]>
CC James Bottomley <[email protected]>
---
 block/scsi_ioctl.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
block/scsi_ioctl.c +3 -0
index 260fa80..9a87daa 100644
@@ -721,11 +721,14 @@ int scsi_verify_blk_ioctl(struct block_device *bd, unsigned int cmd)
 		break;
 	}
 
+	if (capable(CAP_SYS_RAWIO))
+		return 0;
+
 	/* In particular, rule out all resets and host-specific ioctls.  */
 	printk_ratelimited(KERN_WARNING
 			   "%s: sending ioctl %x to a partition!\n", current->comm, cmd);
 
Quoted 8 lines

block/scsi_ioctl.c int scsi_verify_blk_ioctl(struct block_device *bd, unsigned int cmd) · line 734

Quoted 6 lines
block/scsi_ioctl.c +1 -1
-	return capable(CAP_SYS_RAWIO) ? 0 : -ENOIOCTLCMD;
+	return -ENOIOCTLCMD;
 }
 EXPORT_SYMBOL(scsi_verify_blk_ioctl);
 

Ping?

Good that you bring this up :). I've asked the customer about whether
they can find out the particular SG_IO ioctl Veritas issues but never heard back. So will we merge my patch? I remember you gave it reluctant ack once ;).

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR