mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: James Bottomley <James.Bottomley@HansenPartnership.com>
To: Roland Dreier <roland@kernel.org>
Cc: "Jens Axboe" <axboe@kernel.dk>,
	"Doug Gilbert" <dgilbert@interlog.com>,
	"Costa Sapuntzakis" <costa@purestorage.com>,
	"Jörn Engel" <joern@purestorage.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	linux-scsi <linux-scsi@vger.kernel.org>
Subject: Re: [PATCH] [SCSI] sg: Fix user memory corruption when SG_IO is interrupted by a signal
Date: Mon, 05 Aug 2013 16:43:09 -0700	[thread overview]
Message-ID: <1375746189.18481.23.camel@dabdike.int.hansenpartnership.com> (raw)
In-Reply-To: <CAG4TOxP6H9isOHYJN=oKgHPna=wWqfOgg2Zh5cpvNFsgNkh8xA@mail.gmail.com>

On Mon, 2013-08-05 at 16:38 -0700, Roland Dreier wrote:
> On Mon, Aug 5, 2013 at 4:31 PM, James Bottomley
> <James.Bottomley@hansenpartnership.com> wrote:
> > I agree with the analysis.  The fix is a bit draconian, though.  A
> > workqueue actually runs in a kernel thread and there's a simple test for
> > that (!current->mm), so how about this instead (which is much less
> > intrusive)
> 
> > ---
> 
> > diff --git a/fs/bio.c b/fs/bio.c
> > index 94bbc04..e2ab39c 100644
> > --- a/fs/bio.c
> > +++ b/fs/bio.c
> > @@ -1045,12 +1045,22 @@ static int __bio_copy_iov(struct bio *bio, struct bio_vec *iovecs,
> >  int bio_uncopy_user(struct bio *bio)
> >  {
> >         struct bio_map_data *bmd = bio->bi_private;
> > -       int ret = 0;
> > +       struct bio_vec *bvec;
> > +       int ret = 0, i;
> >
> > -       if (!bio_flagged(bio, BIO_NULL_MAPPED))
> > -               ret = __bio_copy_iov(bio, bmd->iovecs, bmd->sgvecs,
> > -                                    bmd->nr_sgvecs, bio_data_dir(bio) == READ,
> > -                                    0, bmd->is_our_pages);
> > +       if (!bio_flagged(bio, BIO_NULL_MAPPED)) {
> > +               /*
> > +                * if we're in a workqueue, the request is orphaned, so
> > +                * don't copy into the kernel address space, just free
> > +                */
> > +               if (current->mm)
> > +                       ret = __bio_copy_iov(bio, bmd->iovecs, bmd->sgvecs,
> > +                                            bmd->nr_sgvecs, bio_data_dir(bio) == READ,
> > +                                            0, bmd->is_our_pages);
> > +               else if (bmd->is_our_pages)
> > +                       bio_for_each_segment_all(bvec, bio, i)
> > +                               __free_page(bvec->bv_page);
> > +       }
> >         bio_free_map_data(bmd);
> >         bio_put(bio);
> >         return ret;
> 
> Yes, looks reasonable -- I can't think of any reason why anyone would
> ever want the bio code to copy to a random userspace address space.
> 
> Acked-by: Roland Dreier <roland@purestorage.com>

You did all the work ... just replace this patch with your previous one
and keep the original tags. (test it first, of course ...)

James



  reply	other threads:[~2013-08-05 23:43 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-05 22:02 Roland Dreier
2013-08-05 23:31 ` James Bottomley
2013-08-05 23:38   ` Roland Dreier
2013-08-05 23:43     ` James Bottomley [this message]
2013-08-06  0:55       ` [PATCH v2] " Roland Dreier
2013-08-07 14:38         ` David Milburn
2013-08-07 15:50           ` Roland Dreier
2013-08-07 16:17             ` David Milburn
2013-08-07 16:31             ` Douglas Gilbert
2013-08-08 18:27               ` Roland Dreier
2013-08-15 16:45           ` Roland Dreier
2013-08-15 17:01             ` Douglas Gilbert
2013-08-06  0:19 ` [PATCH] " Douglas Gilbert
2013-08-06  3:54 ` Peter Chang
2013-08-06 14:56   ` 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=1375746189.18481.23.camel@dabdike.int.hansenpartnership.com \
    --to=james.bottomley@hansenpartnership.com \
    --cc=axboe@kernel.dk \
    --cc=costa@purestorage.com \
    --cc=dgilbert@interlog.com \
    --cc=joern@purestorage.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=roland@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

all inboxes | Powered by JetHome®