public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Cc: alexey.zaytsev@gmail.com, jens.axboe@oracle.com,
	linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org,
	James.Bottomley@HansenPartnership.com
Subject: Re: [PATCH] Fix sg_io_hdr.info corruption.
Date: Wed, 31 Dec 2008 01:15:47 -0800	[thread overview]
Message-ID: <20081231011547.745e579d.akpm@linux-foundation.org> (raw)
In-Reply-To: <20081231180759X.fujita.tomonori@lab.ntt.co.jp>

On Wed, 31 Dec 2008 18:08:02 +0900 FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> wrote:

> On Tue, 30 Dec 2008 15:46:03 -0800
> Andrew Morton <akpm@linux-foundation.org> wrote:
> 
> > On Sun, 28 Dec 2008 17:50:35 +0300
> > Alexey Zaytsev <alexey.zaytsev@gmail.com> wrote:
> > 
> > > sizeof(unsigned (short)) is actually sizeof(function), == 1.
> > > Spotted by sparse.
> > > 
> > > Signed-off-by: Alexey Zaytsev <alexey.zaytsev@gmail.com>
> > > ---
> > >  fs/compat_ioctl.c |    2 +-
> > >  1 files changed, 1 insertions(+), 1 deletions(-)
> > > 
> > > diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
> > > index 5235c67..7c2d617 100644
> > > --- a/fs/compat_ioctl.c
> > > +++ b/fs/compat_ioctl.c
> > > @@ -784,7 +784,7 @@ static int sg_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
> > >  
> > >  	if (copy_in_user(&sgio->status, &sgio32->status,
> > >  			 (4 * sizeof(unsigned char)) +
> > > -			 (2 * sizeof(unsigned (short))) +
> > > +			 (2 * sizeof(unsigned short)) +
> > >  			 (3 * sizeof(int))))
> > >  		return -EFAULT;
> > 
> > gack.
> > 
> > akpm:/home/akpm> cat t.c
> > main()
> > {
> > 	        printf("%d\n", sizeof(unsigned (short)));
> > 	        printf("%d\n", sizeof(unsigned short));
> > }
> > akpm:/home/akpm> ./a.out
> > 1
> > 2
> > 
> > 
> > the code has been like this for years and years.  Why hasn't anyone
> > noticed?  
> 
> The members from 'status' in struct sg_io_hdr to the last are used to
> transfer information from kernel to user space. The values that user
> space sets are just ignored.

OK.

> typedef struct sg_io_hdr
> {
>     int interface_id;           /* [i] 'S' for SCSI generic (required) */
>     int dxfer_direction;        /* [i] data transfer direction  */
>     unsigned char cmd_len;      /* [i] SCSI command length ( <= 16 bytes) */
>     unsigned char mx_sb_len;    /* [i] max length to write to sbp */
>     unsigned short iovec_count; /* [i] 0 implies no scatter gather */
>     unsigned int dxfer_len;     /* [i] byte count of data transfer */
>     void __user *dxferp;	/* [i], [*io] points to data transfer memory
> 					      or scatter gather list */
>     unsigned char __user *cmdp; /* [i], [*i] points to command to perform */
>     void __user *sbp;		/* [i], [*o] points to sense_buffer memory */
>     unsigned int timeout;       /* [i] MAX_UINT->no timeout (unit: millisec) */
>     unsigned int flags;         /* [i] 0 -> default, see SG_FLAG... */
>     int pack_id;                /* [i->o] unused internally (normally) */
>     void __user * usr_ptr;      /* [i->o] unused internally */
>     unsigned char status;       /* [o] scsi status */
>     unsigned char masked_status;/* [o] shifted, masked scsi status */
>     unsigned char msg_status;   /* [o] messaging level data (optional) */
>     unsigned char sb_len_wr;    /* [o] byte count actually written to sbp */
>     unsigned short host_status; /* [o] errors from host adapter */
>     unsigned short driver_status;/* [o] errors from software driver */
>     int resid;                  /* [o] dxfer_len - actual_transferred */
>     unsigned int duration;      /* [o] time taken by cmd (unit: millisec) */
>     unsigned int info;          /* [o] auxiliary information */
> } sg_io_hdr_t;  /* 64 bytes long (on i386) */

So if for some reason the kernel doesn't write to .info, we'll leak two
bytes of kernel memory. 


  reply	other threads:[~2008-12-31  9:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20081228144946.30288.67559.stgit@zaytsev.su>
2008-12-30 23:46 ` [PATCH] Fix sg_io_hdr.info corruption Andrew Morton
2008-12-31  9:08   ` FUJITA Tomonori
2008-12-31  9:15     ` Andrew Morton [this message]
2008-12-31 10:51     ` (unknown) Alexey Zaytsev
2009-01-01 11:08     ` [PATCH] Fix sg_io_hdr.info corruption Alexey Zaytsev
2009-01-01 14:54       ` Douglas Gilbert

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=20081231011547.745e579d.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=alexey.zaytsev@gmail.com \
    --cc=fujita.tomonori@lab.ntt.co.jp \
    --cc=jens.axboe@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.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