Re: [PATCH] loop: prevent bdev freeing while device in use

2013-04-02 Thread Al Viro
On Mon, Apr 01, 2013 at 10:58:55PM -0700, Anatol Pomozov wrote: > >> > >> loop_set_fd/loop_clr_fd (and any other loop ioctl) is called under > >> loop_device->lo_ctl_mutex. > > > > Ok, good enough for me, I applied it, and it's commit > > c1681bf8a7b1b98edee8b862a42c19c4e53205fd in my tree. > > >

Re: [PATCH] loop: prevent bdev freeing while device in use

2013-04-02 Thread Al Viro
On Mon, Apr 01, 2013 at 10:58:55PM -0700, Anatol Pomozov wrote: loop_set_fd/loop_clr_fd (and any other loop ioctl) is called under loop_device-lo_ctl_mutex. Ok, good enough for me, I applied it, and it's commit c1681bf8a7b1b98edee8b862a42c19c4e53205fd in my tree. I assume it should

Re: [PATCH] loop: prevent bdev freeing while device in use

2013-04-01 Thread Anatol Pomozov
Hi On Mon, Apr 1, 2013 at 3:53 PM, Linus Torvalds wrote: > On Mon, Apr 1, 2013 at 10:00 AM, Anatol Pomozov > wrote: >> Hi >> >> On Mon, Apr 1, 2013 at 8:16 AM, Linus Torvalds >> wrote: >>> On Mon, Apr 1, 2013 at 4:58 AM, Anatol Pomozov >>> wrote: To prevent use-after-free we need

Re: [PATCH] loop: prevent bdev freeing while device in use

2013-04-01 Thread Linus Torvalds
On Mon, Apr 1, 2013 at 10:00 AM, Anatol Pomozov wrote: > Hi > > On Mon, Apr 1, 2013 at 8:16 AM, Linus Torvalds > wrote: >> On Mon, Apr 1, 2013 at 4:58 AM, Anatol Pomozov >> wrote: >>> >>> To prevent use-after-free we need to hold device inode in loop_set_fd() >>> and put it later in

Re: [PATCH] loop: prevent bdev freeing while device in use

2013-04-01 Thread Anatol Pomozov
Hi On Mon, Apr 1, 2013 at 8:16 AM, Linus Torvalds wrote: > On Mon, Apr 1, 2013 at 4:58 AM, Anatol Pomozov > 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

[PATCH] loop: prevent bdev freeing while device in use

2013-04-01 Thread Anatol Pomozov
struct block_device lifecycle is defined by its inode (see fs/block_dev.c) - block_device allocated first time we access /dev/loopXX and deallocated on bdev_destroy_inode. When we create the device "losetup /dev/loopXX afile" we want that block_device stay alive until we destroy the loop device

Re: [PATCH] loop: prevent bdev freeing while device in use

2013-04-01 Thread Anatol Pomozov
Hi On Mon, Apr 1, 2013 at 9:28 AM, Al Viro wrote: > On Mon, Apr 01, 2013 at 04:58:05AM -0700, Anatol Pomozov wrote: >> lo->lo_flags |= LO_FLAGS_PARTSCAN; >> if (lo->lo_flags & LO_FLAGS_PARTSCAN) >> ioctl_by_bdev(bdev, BLKRRPART, 0); >> + >> + /* bdev

Re: [PATCH] loop: prevent bdev freeing while device in use

2013-04-01 Thread Al Viro
On Mon, Apr 01, 2013 at 04:58:05AM -0700, Anatol Pomozov wrote: > lo->lo_flags |= LO_FLAGS_PARTSCAN; > if (lo->lo_flags & LO_FLAGS_PARTSCAN) > ioctl_by_bdev(bdev, BLKRRPART, 0); > + > + /* bdev lifecycle is defined by its bd_inode (see > + * struct

Re: [PATCH] loop: prevent bdev freeing while device in use

2013-04-01 Thread Linus Torvalds
On Mon, Apr 1, 2013 at 4:58 AM, Anatol Pomozov 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()? IOW, what protects us from

[PATCH] loop: prevent bdev freeing while device in use

2013-04-01 Thread Anatol Pomozov
struct block_device lifecycle is defined by its inode (see fs/block_dev.c) - block_device allocated first time we access /dev/loopXX and deallocated on bdev_destroy_inode. When we create the device "losetup /dev/loopXX afile" we want that block_device stay alive until we destroy the loop device

[PATCH] loop: prevent bdev freeing while device in use

2013-04-01 Thread Anatol Pomozov
struct block_device lifecycle is defined by its inode (see fs/block_dev.c) - block_device allocated first time we access /dev/loopXX and deallocated on bdev_destroy_inode. When we create the device losetup /dev/loopXX afile we want that block_device stay alive until we destroy the loop device with

Re: [PATCH] loop: prevent bdev freeing while device in use

2013-04-01 Thread Linus Torvalds
On Mon, Apr 1, 2013 at 4:58 AM, Anatol Pomozov anatol.pomo...@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()? IOW,

Re: [PATCH] loop: prevent bdev freeing while device in use

2013-04-01 Thread Al Viro
On Mon, Apr 01, 2013 at 04:58:05AM -0700, Anatol Pomozov wrote: lo-lo_flags |= LO_FLAGS_PARTSCAN; if (lo-lo_flags LO_FLAGS_PARTSCAN) ioctl_by_bdev(bdev, BLKRRPART, 0); + + /* bdev lifecycle is defined by its bd_inode (see + * struct bdev_inode

Re: [PATCH] loop: prevent bdev freeing while device in use

2013-04-01 Thread Anatol Pomozov
Hi On Mon, Apr 1, 2013 at 9:28 AM, Al Viro v...@zeniv.linux.org.uk wrote: On Mon, Apr 01, 2013 at 04:58:05AM -0700, Anatol Pomozov wrote: lo-lo_flags |= LO_FLAGS_PARTSCAN; if (lo-lo_flags LO_FLAGS_PARTSCAN) ioctl_by_bdev(bdev, BLKRRPART, 0); + + /*

[PATCH] loop: prevent bdev freeing while device in use

2013-04-01 Thread Anatol Pomozov
struct block_device lifecycle is defined by its inode (see fs/block_dev.c) - block_device allocated first time we access /dev/loopXX and deallocated on bdev_destroy_inode. When we create the device losetup /dev/loopXX afile we want that block_device stay alive until we destroy the loop device with

Re: [PATCH] loop: prevent bdev freeing while device in use

2013-04-01 Thread Anatol Pomozov
Hi On Mon, Apr 1, 2013 at 8:16 AM, Linus Torvalds torva...@linux-foundation.org wrote: On Mon, Apr 1, 2013 at 4:58 AM, Anatol Pomozov anatol.pomo...@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

Re: [PATCH] loop: prevent bdev freeing while device in use

2013-04-01 Thread Linus Torvalds
On Mon, Apr 1, 2013 at 10:00 AM, Anatol Pomozov anatol.pomo...@gmail.com wrote: Hi On Mon, Apr 1, 2013 at 8:16 AM, Linus Torvalds torva...@linux-foundation.org wrote: On Mon, Apr 1, 2013 at 4:58 AM, Anatol Pomozov anatol.pomo...@gmail.com wrote: To prevent use-after-free we need to hold

Re: [PATCH] loop: prevent bdev freeing while device in use

2013-04-01 Thread Anatol Pomozov
Hi On Mon, Apr 1, 2013 at 3:53 PM, Linus Torvalds torva...@linux-foundation.org wrote: On Mon, Apr 1, 2013 at 10:00 AM, Anatol Pomozov anatol.pomo...@gmail.com wrote: Hi On Mon, Apr 1, 2013 at 8:16 AM, Linus Torvalds torva...@linux-foundation.org wrote: On Mon, Apr 1, 2013 at 4:58 AM,