lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1455618965-26699-1-git-send-email-dmonakhov@openvz.org>
Date:	Tue, 16 Feb 2016 14:36:04 +0400
From:	Dmitry Monakhov <dmonakhov@...nvz.org>
To:	linux-ext4@...r.kernel.org
Cc:	tytso@....edu, Dmitry Monakhov <dmonakhov@...nvz.org>
Subject: [PATCH 1/2] ext4: Prevent panic for destroyed devices

Some devices(nbd) can becomes unoperatable via kill_bdev
so its pagecache will be invalidated and all buffers becomes unmapped.
In that situation we will trigger BUGON on submit_bh.

#Testcase
mkdir  -p a/mnt
cd a
truncate -s 1G img
mkfs.ext4 -F img
qemu-nbd -c /dev/nbd0 img
mount /dev/nbd0 /mnt
cp -r /bin/ /mnt&
# Disconnect nbd while cp is active
qemu-nbd -d /dev/nbd0
sync

Signed-off-by: Dmitry Monakhov <dmonakhov@...nvz.org>
---
 fs/ext4/super.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 3ed01ec..617d8b4a 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -4320,7 +4320,7 @@ static int ext4_commit_super(struct super_block *sb, int sync)
 	struct buffer_head *sbh = EXT4_SB(sb)->s_sbh;
 	int error = 0;
 
-	if (!sbh || block_device_ejected(sb))
+	if (!sbh || !buffer_mapped(sbh) || block_device_ejected(sb))
 		return error;
 	if (buffer_write_io_error(sbh)) {
 		/*
@@ -4368,8 +4368,26 @@ static int ext4_commit_super(struct super_block *sb, int sync)
 	ext4_superblock_csum_set(sb);
 	mark_buffer_dirty(sbh);
 	if (sync) {
-		error = __sync_dirty_buffer(sbh,
-			test_opt(sb, BARRIER) ? WRITE_FUA : WRITE_SYNC);
+		lock_buffer(sbh);
+		/* superblock bh may be invalidated due to drive failure */
+		if (!buffer_mapped(sbh)) {
+			unlock_buffer(sbh);
+			ext4_msg(sb, KERN_ERR, "Can not write superblock "
+				 "because disk cache was invalidated");
+			return -EIO;
+		}
+		if (test_clear_buffer_dirty(sbh)) {
+			get_bh(sbh);
+			sbh->b_end_io = end_buffer_write_sync;
+			error = submit_bh(test_opt(sb, BARRIER) ?
+					  WRITE_FUA : WRITE_SYNC, sbh);
+			wait_on_buffer(sbh);
+			if (!error && !buffer_uptodate(sbh))
+				error = -EIO;
+		} else {
+			unlock_buffer(sbh);
+		}
+
 		if (error)
 			return error;
 
-- 
1.8.3.1

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ