All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fs/block_dev: fix potential NULL ptr deref in freeze_bdev()
@ 2016-08-23 15:55 Andrey Ryabinin
  2016-08-25  7:38 ` Christoph Hellwig
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Andrey Ryabinin @ 2016-08-23 15:55 UTC (permalink / raw
  To: Jens Axboe, Alexander Viro
  Cc: linux-fsdevel, Maxim Patlasov, Christoph Hellwig, linux-kernel,
	Andrey Ryabinin

Calling freeze_bdev() twice on the same block device without mounted
filesystem get_super() will return NULL, which will lead to NULL-ptr
dereference later in drop_super().

Check get_super() result to fix that.

Note, that this is a purely theoretical issue. We have only 3
freeze_bdev() callers. 2 of them are in filesystem code and used on a
device with mounted fs. The third one in lock_fs() has protection in
upper-layer code against freezing block device the second time without
thawing it first.

Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
---
 fs/block_dev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/block_dev.c b/fs/block_dev.c
index c3cdde8..c18b083 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -249,7 +249,8 @@ struct super_block *freeze_bdev(struct block_device *bdev)
 		 * thaw_bdev drops it.
 		 */
 		sb = get_super(bdev);
-		drop_super(sb);
+		if (sb)
+			drop_super(sb);
 		mutex_unlock(&bdev->bd_fsfreeze_mutex);
 		return sb;
 	}
-- 
2.7.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] fs/block_dev: fix potential NULL ptr deref in freeze_bdev()
  2016-08-23 15:55 [PATCH] fs/block_dev: fix potential NULL ptr deref in freeze_bdev() Andrey Ryabinin
@ 2016-08-25  7:38 ` Christoph Hellwig
  2016-08-25 14:38 ` Jens Axboe
  2016-08-25 14:39 ` Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2016-08-25  7:38 UTC (permalink / raw
  To: Andrey Ryabinin
  Cc: Jens Axboe, Alexander Viro, linux-fsdevel, Maxim Patlasov,
	Christoph Hellwig, linux-kernel

On Tue, Aug 23, 2016 at 06:55:31PM +0300, Andrey Ryabinin wrote:
> Calling freeze_bdev() twice on the same block device without mounted
> filesystem get_super() will return NULL, which will lead to NULL-ptr
> dereference later in drop_super().
> 
> Check get_super() result to fix that.
> 
> Note, that this is a purely theoretical issue. We have only 3
> freeze_bdev() callers. 2 of them are in filesystem code and used on a
> device with mounted fs. The third one in lock_fs() has protection in
> upper-layer code against freezing block device the second time without
> thawing it first.
> 
> Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>

Looks fine,

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] fs/block_dev: fix potential NULL ptr deref in freeze_bdev()
  2016-08-23 15:55 [PATCH] fs/block_dev: fix potential NULL ptr deref in freeze_bdev() Andrey Ryabinin
  2016-08-25  7:38 ` Christoph Hellwig
@ 2016-08-25 14:38 ` Jens Axboe
  2016-08-25 14:39 ` Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2016-08-25 14:38 UTC (permalink / raw
  To: Andrey Ryabinin, Alexander Viro
  Cc: linux-fsdevel, Maxim Patlasov, Christoph Hellwig, linux-kernel

On 08/23/2016 09:55 AM, Andrey Ryabinin wrote:
> Calling freeze_bdev() twice on the same block device without mounted
> filesystem get_super() will return NULL, which will lead to NULL-ptr
> dereference later in drop_super().
>
> Check get_super() result to fix that.
>
> Note, that this is a purely theoretical issue. We have only 3
> freeze_bdev() callers. 2 of them are in filesystem code and used on a
> device with mounted fs. The third one in lock_fs() has protection in
> upper-layer code against freezing block device the second time without
> thawing it first.

Applied, thanks.

-- 
Jens Axboe

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] fs/block_dev: fix potential NULL ptr deref in freeze_bdev()
  2016-08-23 15:55 [PATCH] fs/block_dev: fix potential NULL ptr deref in freeze_bdev() Andrey Ryabinin
  2016-08-25  7:38 ` Christoph Hellwig
  2016-08-25 14:38 ` Jens Axboe
@ 2016-08-25 14:39 ` Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2016-08-25 14:39 UTC (permalink / raw
  To: Andrey Ryabinin, Alexander Viro
  Cc: linux-fsdevel, Maxim Patlasov, Christoph Hellwig, linux-kernel

On 08/23/2016 09:55 AM, Andrey Ryabinin wrote:
> Calling freeze_bdev() twice on the same block device without mounted
> filesystem get_super() will return NULL, which will lead to NULL-ptr
> dereference later in drop_super().
>
> Check get_super() result to fix that.
>
> Note, that this is a purely theoretical issue. We have only 3
> freeze_bdev() callers. 2 of them are in filesystem code and used on a
> device with mounted fs. The third one in lock_fs() has protection in
> upper-layer code against freezing block device the second time without
> thawing it first.

Applied, thanks.

-- 
Jens Axboe

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-08-25 14:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-23 15:55 [PATCH] fs/block_dev: fix potential NULL ptr deref in freeze_bdev() Andrey Ryabinin
2016-08-25  7:38 ` Christoph Hellwig
2016-08-25 14:38 ` Jens Axboe
2016-08-25 14:39 ` Jens Axboe

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.