Messages in this thread | | | Date | Mon, 1 Apr 2013 10:00:35 -0700 | Subject | Re: [PATCH] loop: prevent bdev freeing while device in use | From | Anatol Pomozov <> |
| |
Hi
On Mon, Apr 1, 2013 at 8:16 AM, Linus Torvalds <torvalds@linux-foundation.org> wrote: > On Mon, Apr 1, 2013 at 4:58 AM, Anatol Pomozov <anatol.pomozov@gmail.com> wrote: >> >> To prevent use-after-free we need to hold device inode in loop_set_fd() >> and put it later in loop_clr_fd(). > > Is there something that guarantees that there's only one loop_set_fd() > and one paired loop_clr_fd()?
Yes there is such guarantee.
Every time we call loop_set_fd() we check that loop_device->lo_state is Lo_unbound and set it to Lo_bound If somebody will try to set_fd again it will get EBUSY. And if we try to loop_clr_fd() on unbound loop device we'll get ENXIO.
loop_set_fd/loop_clr_fd (and any other loop ioctl) is called under loop_device->lo_ctl_mutex.
> > IOW, what protects us from somebody doing loop_clr_fd() on a device > that hasn't been set up yet, or doing multiple loop_set_fd calls?
> I suspect the "lo->lo_state" is part of the answer, but it's very much > not obvious, and I'd want this to be explicitly explained. > > Linus
| |