All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Nikolay Borisov <nborisov@suse.com>, Qu Wenruo <wqu@suse.com>,
	linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 1/1] btrfs: locking: Allow btrfs_tree_lock() to return error to avoid deadlock
Date: Mon, 30 Jul 2018 15:26:52 +0800	[thread overview]
Message-ID: <91772b2d-49fb-4aa8-17ad-99d8f56dcc86@gmx.com> (raw)
In-Reply-To: <66cf31bb-126f-68d7-83ee-c4214c6129c1@suse.com>



On 2018年07月30日 15:18, Nikolay Borisov wrote:
> 
> 
> On 30.07.2018 09:17, Qu Wenruo wrote:
>> -void btrfs_tree_lock(struct extent_buffer *eb)
>> +int btrfs_tree_lock(struct extent_buffer *eb)
>>  {
>> -	WARN_ON(eb->lock_owner == current->pid);
>> +	if (unlikely(eb->lock_owner == current->pid)) {
>> +		WARN(1,
>> +"tree block %llu already locked by current (pid=%llu), refuse to lock",
>> +		     eb->start, current->pid);
>> +		return -EUCLEAN;
>> +	}
> 
> If this happens it should point to a logical bug in which case we need
> to halt the kernel. Furthermore this seems the wrong abstraction level
> at which to solve the problem. eb->lock_owner is a runtime
> characteristic of the eb, yet when it has an unexpected value you return
> EUCLEAN which is an error for an on-disk error.

On-disk corruption leads to unexpected runtime error, this looks valid
to me at least.
Especially when we can't really verify on-disk data for it's cross
reference.

> 
> I don't think it's productive to try and solve every possible
> fuzz-inspired corruption.

Surprisingly, we should.

The point here is, such image can be used to do kernel deny-of-service
attack.
(Such debate happened a long time ago, and at that time I was thinking
the same as you)

No one likes a USB stick to cause kernel deadlock, even for desktop users.

> In the worst case this corruption should be
> caught a lot earlier rather than when we are locking an in-memory
> structure.

This makes sense, although not that doable.
For early detection, we need to do some level cross check, which could
be time and IO consuming.

Currently this fix is the least performance-impacting one I could think of.

Thanks,
Qu

> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

  reply	other threads:[~2018-07-30  9:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-30  6:17 [PATCH 0/1] btrfs: Tree lock return value enhancement to avoid deadlock on crafted image Qu Wenruo
2018-07-30  6:17 ` [PATCH 1/1] btrfs: locking: Allow btrfs_tree_lock() to return error to avoid deadlock Qu Wenruo
2018-07-30  7:18   ` Nikolay Borisov
2018-07-30  7:26     ` Qu Wenruo [this message]
2018-07-31  6:48   ` Su Yue
2018-07-31  6:44     ` Qu Wenruo
2018-07-31  6:47       ` Qu Wenruo
2018-07-31  6:52   ` [PATCH v2] " Qu Wenruo
2018-08-01 13:27     ` David Sterba
2018-08-01 13:45       ` Qu Wenruo
2018-08-02  8:38         ` Qu Wenruo

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=91772b2d-49fb-4aa8-17ad-99d8f56dcc86@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=nborisov@suse.com \
    --cc=wqu@suse.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.