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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20250728135556.20583-1-laishangzhen@163.com>
Date: Mon, 28 Jul 2025 06:55:56 -0700
From: laishangzhen <laishangzhen@....com>
To: Matthew Wilcox <willy@...radead.org>,
	Andrew Morton <akpm@...ux-foundation.org>
Cc: linux-fsdevel@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	laishangzhen <laishangzhen@....com>
Subject: [PATCH] mm: Removing the card during write operations blocks the I/O process when during the process Issue encountered: When formatting an SD card to ext4 using mkfs.ext4, if the card is ejected during the process, the formatting process blocks at balance_dirty_pages_ratelimited.

Modification approach:
After card ejection,
the dev in the bdi (backing_dev_info) is
released in del_gendisk.
Within generic_perform_write,
if writeback is supported,
it directly checks whether bdi->dev is NULL to determine
if the card has been ejected.
Once ejected, it becomes unnecessary to proceed
with page allocation and data writing.

Signed-off-by: laishangzhen <laishangzhen@....com>
---
 mm/filemap.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/mm/filemap.c b/mm/filemap.c
index 6af6d8f29..5d6ba9f02 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -4087,6 +4087,8 @@ ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i)
 	struct address_space *mapping = file->f_mapping;
 	const struct address_space_operations *a_ops = mapping->a_ops;
 	size_t chunk = mapping_max_folio_size(mapping);
+	struct inode *inode = mapping->host;
+	struct backing_dev_info *bdi = inode_to_bdi(inode);
 	long status = 0;
 	ssize_t written = 0;
 
@@ -4101,6 +4103,12 @@ ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i)
 retry:
 		offset = pos & (chunk - 1);
 		bytes = min(chunk - offset, bytes);
+		if (bdi->capabilities & BDI_CAP_WRITEBACK) {
+			if (bdi->dev == NULL) {
+				status = -ENODEV;
+				break;
+			}
+		}
 		balance_dirty_pages_ratelimited(mapping);
 
 		if (fatal_signal_pending(current)) {
-- 
2.25.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ