public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Douglas Gilbert <dougg@torque.net>
To: Linus Torvalds <torvalds@osdl.org>
Cc: linux-scsi@vger.kernel.org
Subject: Re: cd burning with plextor drives.
Date: Sun, 30 Jul 2006 14:02:46 -0400	[thread overview]
Message-ID: <44CCF446.9000007@torque.net> (raw)
In-Reply-To: <Pine.LNX.4.64.0607291314500.4168@g5.osdl.org>

Linus Torvalds wrote:
> 
> On Sat, 29 Jul 2006, Douglas Gilbert wrote:
>> See below. Non-root users do not usually have read
>> or write permissions to a _disk_. We were talking
>> about a different class of devices: cd/dvd drives.
> 
> What has that got to do with _anything_?
> 
> What do you think is the difference between a disk and a CD drive?
> 
> And do you really think that it's the _medium_ that looks at the commands? 
> I don't think so. Regardless of whether it's a disk or a CD-ROM, it's the 
> controller in the _drive_ that looks and acts on those commands.
> 
> And that CD drive (that you have write access to) also has things like 
> firmware. And how do you think that firmware is updated? By magic? Or by 
> SCSI commands sent to the drive?

<snip>

Hard disks and CD/DVD drives are quite different from
a command set point of view. Both have high level
read operations that map very cleanly to the block
layer. The write side is very different. Disks have
a high level write operation that is symmetric with
the read operation and the write can be called many times
on the same lba with provision for multi user access
(locking). Writes and reads can be interspersed in
rapid succession.

OTOH CD/DVD drive media are written once (leaving aside
the "-RW" hack) and that write is done at a much
lower level (command set wise) than the read. The
application writing the cd/dvd media is assumed to
have exclusive access for the duration of the write
operation (which may be some time). During a write
operation the rest of the cd/dvd media is unavailable
for reading. That low level write operation assumes
the application knows a lot more about the drive and
the media than the OS would ever want to know. Another
difference is that the cd/dvd media is not only
removable but that a user expects to be able to
read it 5 or 10 years after it was burnt on a drive
from another manufacturer.

To cope with the lower level write once operation of a
cd/dvd drive, we need applications like cdrecord and
nero and they need a pass through interface. Just like
you, I have been abused by Joerg Schilling but there
was some technical merit in what he was saying and
it is reflected in the SG_IO ioctl design. Actually
the idea of the SG_IO ioctl itself came from Joerg
Schilling.


I have pointed out that the block layer SG_IO ioctl is
broken in various ways. Here is an example chosen because
it will be very difficult to exploit. The MMC command
set must not use opcodes (the first byte of a SCSI cdb)
that are used by the SCSI Primary Commands (SPC) but it
can overlap with other device specific command sets.
A quite important device specific command set is SBC (for
block devices including hard disks). The GET PERFORMANCE
MMC command is set for O_RDONLY access by the block layer
SG_IO filter and O_RDWR by the sg driver. That command uses
opcode 0xac . From a MMC point of view that opcode is "safe".
Now checking my references I observe that for the optical
block memory device type (covered by SBC) that is an
ERASE(12) operation. Choose your poison!


Also be aware that we have been in a world of multiple command
sets (and multiple transports) for some time. Take ATAPI devices:
one can send many SPC and MMC (SCSI) commands to such a device.
One can also send certain (transport and identification related)
ATA commands. The most obvious example of the latter is the
IDENTIFY PACKET DEVICE (ATA) command. As of lk 2.6.15 one can
send that ATA command two ways:
  - via the long standing ATA specific ioctls (e.g. the
    HDIO_GET_IDENTITY ioctl **)
  - if the device is libata connected (or any other SAT
    compliant layer), via the ATA PASS THROUGH SCSI command

The IDENTIFY PACKET DEVICE (ATA) command is "safe" and
should be allowed O_RDONLY but not all ATA commands that can
be sent to ATAPI device (e.g. SET FEATURES) could be
considered "safe". Once we move lower into the transport
domain, things can become even murkier with ATAPI
possibly conveyed across SATA (S-ATAPI) which in turn may
be conveyed across STP in SAS. Sometimes transport
characteristics can be tweaked "in-band", that is, down the
same path that commands are sent.


The point I'm trying to make is that opcode based filtering
may have been sufficient in 1992 (circa SCSI-2) but 14
years later it most certainly ain't.


Doug Gilbert

** Last time I looked the HDIO_GET_IDENTITY ioctl returned
   cached information. IMO that is incorrect, it should go
   out to the command each time.

  parent reply	other threads:[~2006-07-30 18:02 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-29  4:52 cd burning with plextor drives Dave Jones
2006-07-29 11:12 ` Jens Axboe
2006-07-29 13:40   ` James Bottomley
2006-07-29 15:39     ` Christer Weinigel
2006-07-29 17:06     ` Linus Torvalds
2006-07-29 17:30       ` James Bottomley
2006-07-29 17:49         ` Linus Torvalds
2006-07-30 16:02           ` Christer Weinigel
2006-07-30 19:57             ` Linus Torvalds
2006-07-30 20:18               ` Christian Iversen
2006-07-31  0:12               ` Christer Weinigel
2006-07-31 20:32                 ` Linus Torvalds
2006-07-31 20:38                   ` Dave Jones
2006-07-31 20:41                   ` Jens Axboe
2006-07-31 20:46                     ` Linus Torvalds
2006-08-01  6:54                       ` Jens Axboe
2006-07-29 18:39       ` Douglas Gilbert
2006-07-29 18:54         ` Linus Torvalds
2006-07-29 20:12           ` Douglas Gilbert
2006-07-29 20:33             ` Linus Torvalds
2006-07-29 20:53               ` Linus Torvalds
2006-07-29 22:13                 ` Arjan van de Ven
2006-07-30  5:57                   ` Matthew Wilcox
2006-07-30  9:38               ` Rogier Wolff
2006-07-30 18:02               ` Douglas Gilbert [this message]
2006-07-30 20:06                 ` Linus Torvalds
2006-07-29 21:40           ` Christer Weinigel
2006-07-30  5:56             ` Linus Torvalds
2006-07-29 17:04   ` Linus Torvalds
2006-07-29 17:22     ` Dave Jones
2006-07-30 10:21       ` Rogier Wolff
2006-07-30 10:31         ` Arjan van de Ven
2006-07-30 11:09         ` Steve McIntyre
2006-07-31  9:33       ` Jens Axboe
2006-07-31  9:32     ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=44CCF446.9000007@torque.net \
    --to=dougg@torque.net \
    --cc=linux-scsi@vger.kernel.org \
    --cc=torvalds@osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox