mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: Dongli Zhang <dongli.zhang@oracle.com>, linux-block@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, jack@suse.cz,
	penguin-kernel@i-love.sakura.ne.jp
Subject: Re: [PATCH 1/1] loop: access lo_backing_file only when the loop device is Lo_bound
Date: Mon, 18 Mar 2019 08:21:39 -0600	[thread overview]
Message-ID: <2debdd71-c444-a04b-c308-097d8e51ee4c@kernel.dk> (raw)
In-Reply-To: <1552911797-20455-1-git-send-email-dongli.zhang@oracle.com>

On 3/18/19 6:23 AM, Dongli Zhang wrote:
> Commit 758a58d0bc67 ("loop: set GENHD_FL_NO_PART_SCAN after
> blkdev_reread_part()") separates "lo->lo_backing_file = NULL" and
> "lo->lo_state = Lo_unbound" into different critical regions protected by
> loop_ctl_mutex.
> 
> However, there is below race that the NULL lo->lo_backing_file would be
> accessed when the backend of a loop is another loop device, e.g., loop0's
> backend is a file, while loop1's backend is loop0.
> 
> loop0's backend is file            loop1's backend is loop0
> 
> __loop_clr_fd()
>   mutex_lock(&loop_ctl_mutex);
>   lo->lo_backing_file = NULL; --> set to NULL
>   mutex_unlock(&loop_ctl_mutex);
>                                    loop_set_fd()
>                                      mutex_lock_killable(&loop_ctl_mutex);
>                                      loop_validate_file()
>                                        f = l->lo_backing_file; --> NULL
>                                          access if loop0 is not Lo_unbound
>   mutex_lock(&loop_ctl_mutex);
>   lo->lo_state = Lo_unbound;
>   mutex_unlock(&loop_ctl_mutex);
> 
> lo->lo_backing_file should be accessed only when the loop device is
> Lo_bound.
> 
> In fact, the problem has been introduced already in commit 7ccd0791d985
> ("loop: Push loop_ctl_mutex down into loop_clr_fd()") after which
> loop_validate_file() could see devices in Lo_rundown state with which it
> did not count. It was harmless at that point but still.

Thanks, applied.

-- 
Jens Axboe


      reply	other threads:[~2019-03-18 14:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-18 12:23 Dongli Zhang
2019-03-18 14:21 ` Jens Axboe [this message]

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=2debdd71-c444-a04b-c308-097d8e51ee4c@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=dongli.zhang@oracle.com \
    --cc=jack@suse.cz \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=penguin-kernel@i-love.sakura.ne.jp \
    /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

Powered by JetHome