All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: Jens Axboe <axboe@fb.com>,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	Christoph Hellwig <hch@lst.de>,
	linux-scsi@vger.kernel.org, linux-block@vger.kernel.org,
	John Garry <john.garry@huawei.com>,
	Bart Van Assche <bart.vanassche@sandisk.com>,
	Omar Sandoval <osandov@fb.com>, Hannes Reinecke <hare@suse.com>
Subject: Re: [PATCH V4] scsi_debugfs: fix crash in scsi_show_rq()
Date: Wed, 6 Dec 2017 00:55:45 +0800	[thread overview]
Message-ID: <20171205165543.GD23788@ming.t460p> (raw)
In-Reply-To: <20171115120449.GD908@ming.t460p>

On Wed, Nov 15, 2017 at 08:04:49PM +0800, Ming Lei wrote:
> On Wed, Nov 15, 2017 at 07:28:00PM +0900, James Bottomley wrote:
> > On Wed, 2017-11-15 at 18:09 +0800, Ming Lei wrote:
> > > On Tue, Nov 14, 2017 at 10:14:52AM -0800, James Bottomley wrote:
> > > > 
> > > > On Tue, 2017-11-14 at 08:55 +0800, Ming Lei wrote:
> > > > > 
> > > > > Hi James,
> > > > > 
> > > > > On Mon, Nov 13, 2017 at 10:55:52AM -0800, James Bottomley wrote:
> > > > > > 
> > > > > > 
> > > > > > On Sat, 2017-11-11 at 10:43 +0800, Ming Lei wrote:
> > > > > > > 
> > > > > > > 
> > > > > > > So from CPU1's review, cmd->cmnd is in a remote NUMA node,
> > > > > > > __scsi_format_command() is executed much slower than
> > > > > > > mempool_free().
> > > > > > > So when mempool_free() returns, __scsi_format_command() may
> > > > > > > not fetched the buffer in L1 cache yet, then use-after-free
> > > > > > > is still triggered.
> > > > > > > 
> > > > > > > That is why I say this use-after-free is inevitable no matter
> > > > > > > 'setting SCpnt->cmnd to NULL before calling mempool_free()'
> > > > > > > or not.
> > > > > > 
> > > > > > The bottom line is that there are several creative ways around
> > > > > > this but the proposed code is currently broken and simply
> > > > > > putting a comment in saying so doesn't make it acceptable.
> > > > > 
> > > > > As I explained above, I didn't see one really workable way. Or
> > > > > please correct it if I am wrong.
> > > > 
> > > > I simply can't believe it's beyond the wit of man to solve a use
> > > > after free race. �About 40% of kernel techniques are devoted to
> > > > this. �All I really care about is not losing the PI information we
> > > > previously had. �I agree with Bart that NULL cmnd is a good
> > > > indicator, so it seems reasonable to use it. �If you have another
> > > > mechanism, feel free to propose it.
> > > 
> > > Hi James,
> > > 
> > > This patch is my proposal, no others thought of yet.
> > > 
> > > We can fix the use-after-free easily via lock, rcu and ..., but some
> > > cost has to pay. In this case, we can't wait too long in show_rq(),
> > > otherwise we may lose important debug info, so I do not have better
> > > way.
> > > 
> > > IMO this use-after-free is actually no harm, I don't think we have to
> > > fix it, but it should be better to not let utility warn on this case.
> > 
> > Fine, so lose the snide comment and set the cmnd to NULL *before*
> > calling free so we narrow the race window.
> 
> Hi James,
> 
> Given we can't avoid the use-after-free, how about not do that way so
> we won't lose the precious debug info too early?

Hi James,

Are you fine with V4?

As I explained, the use-after-free can't be avoided, we have to make
scsi_show_rq() to survive that, so we don't need to touch code in free path.
Also we won't lose debug info too early in this way, not like 'set the cmnd
to NULL *before* calling free'.

Thanks,
Ming

WARNING: multiple messages have this Message-ID (diff)
From: Ming Lei <ming.lei@redhat.com>
To: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: Jens Axboe <axboe@fb.com>,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	Christoph Hellwig <hch@lst.de>,
	linux-scsi@vger.kernel.org, linux-block@vger.kernel.org,
	John Garry <john.garry@huawei.com>,
	Bart Van Assche <bart.vanassche@sandisk.com>,
	Omar Sandoval <osandov@fb.com>, Hannes Reinecke <hare@suse.com>
Subject: Re: [PATCH V4] scsi_debugfs: fix crash in scsi_show_rq()
Date: Wed, 6 Dec 2017 00:55:45 +0800	[thread overview]
Message-ID: <20171205165543.GD23788@ming.t460p> (raw)
In-Reply-To: <20171115120449.GD908@ming.t460p>

On Wed, Nov 15, 2017 at 08:04:49PM +0800, Ming Lei wrote:
> On Wed, Nov 15, 2017 at 07:28:00PM +0900, James Bottomley wrote:
> > On Wed, 2017-11-15 at 18:09 +0800, Ming Lei wrote:
> > > On Tue, Nov 14, 2017 at 10:14:52AM -0800, James Bottomley wrote:
> > > > 
> > > > On Tue, 2017-11-14 at 08:55 +0800, Ming Lei wrote:
> > > > > 
> > > > > Hi James,
> > > > > 
> > > > > On Mon, Nov 13, 2017 at 10:55:52AM -0800, James Bottomley wrote:
> > > > > > 
> > > > > > 
> > > > > > On Sat, 2017-11-11 at 10:43 +0800, Ming Lei wrote:
> > > > > > > 
> > > > > > > 
> > > > > > > So from CPU1's review, cmd->cmnd is in a remote NUMA node,
> > > > > > > __scsi_format_command() is executed much slower than
> > > > > > > mempool_free().
> > > > > > > So when mempool_free() returns, __scsi_format_command() may
> > > > > > > not fetched the buffer in L1 cache yet, then use-after-free
> > > > > > > is still triggered.
> > > > > > > 
> > > > > > > That is why I say this use-after-free is inevitable no matter
> > > > > > > 'setting SCpnt->cmnd to NULL before calling mempool_free()'
> > > > > > > or not.
> > > > > > 
> > > > > > The bottom line is that there are several creative ways around
> > > > > > this but the proposed code is currently broken and simply
> > > > > > putting a comment in saying so doesn't make it acceptable.
> > > > > 
> > > > > As I explained above, I didn't see one really workable way. Or
> > > > > please correct it if I am wrong.
> > > > 
> > > > I simply can't believe it's beyond the wit of man to solve a use
> > > > after free race.  About 40% of kernel techniques are devoted to
> > > > this.  All I really care about is not losing the PI information we
> > > > previously had.  I agree with Bart that NULL cmnd is a good
> > > > indicator, so it seems reasonable to use it.  If you have another
> > > > mechanism, feel free to propose it.
> > > 
> > > Hi James,
> > > 
> > > This patch is my proposal, no others thought of yet.
> > > 
> > > We can fix the use-after-free easily via lock, rcu and ..., but some
> > > cost has to pay. In this case, we can't wait too long in show_rq(),
> > > otherwise we may lose important debug info, so I do not have better
> > > way.
> > > 
> > > IMO this use-after-free is actually no harm, I don't think we have to
> > > fix it, but it should be better to not let utility warn on this case.
> > 
> > Fine, so lose the snide comment and set the cmnd to NULL *before*
> > calling free so we narrow the race window.
> 
> Hi James,
> 
> Given we can't avoid the use-after-free, how about not do that way so
> we won't lose the precious debug info too early?

Hi James,

Are you fine with V4?

As I explained, the use-after-free can't be avoided, we have to make
scsi_show_rq() to survive that, so we don't need to touch code in free path.
Also we won't lose debug info too early in this way, not like 'set the cmnd
to NULL *before* calling free'.

Thanks,
Ming

  reply	other threads:[~2017-12-05 16:56 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-10  9:01 [PATCH V4] scsi_debugfs: fix crash in scsi_show_rq() Ming Lei
2017-11-10 16:51 ` James Bottomley
2017-11-11  2:43   ` Ming Lei
2017-11-11  2:43     ` Ming Lei
2017-11-13 18:55     ` James Bottomley
2017-11-14  0:55       ` Ming Lei
2017-11-14  0:55         ` Ming Lei
2017-11-14 18:14         ` James Bottomley
2017-11-15 10:09           ` Ming Lei
2017-11-15 10:09             ` Ming Lei
2017-11-15 10:28             ` James Bottomley
2017-11-15 12:04               ` Ming Lei
2017-11-15 12:04                 ` Ming Lei
2017-12-05 16:55                 ` Ming Lei [this message]
2017-12-05 16:55                   ` Ming Lei

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=20171205165543.GD23788@ming.t460p \
    --to=ming.lei@redhat.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=axboe@fb.com \
    --cc=bart.vanassche@sandisk.com \
    --cc=hare@suse.com \
    --cc=hch@lst.de \
    --cc=john.garry@huawei.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=osandov@fb.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.