util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] blkzone: deny destructive ioctls on busy blockdev
@ 2020-05-15  8:41 Johannes Thumshirn
  2020-05-15  8:50 ` Chris Hofstaedtler
  2020-05-15 12:58 ` Karel Zak
  0 siblings, 2 replies; 5+ messages in thread
From: Johannes Thumshirn @ 2020-05-15  8:41 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux, Johannes Thumshirn, Coly Li, Damien Le Moal

If a user submits a zone management ioctl from user-space, like a zone
reset and a file-system (like zonefs or f2fs) is mounted on the zoned
block device, the zone will get reset and the file-system's cached value
of the zone's write-pointer becomes invalid.

Subsequent writes to this zone from the file-system will result in
unaligned writes and the drive will error out.

Open the block device file in exclusive mode for submitting these ioctls.
If a file-system is mounted the kernel will return -EBUSY and we can't
continue issuing the ioctl.

Reported-by: Coly Li <colyli@suse.de>
Cc: Damien Le Moal <Damien.LeMoal@wdc.com>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 sys-utils/blkzone.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/sys-utils/blkzone.c b/sys-utils/blkzone.c
index 8d9de2e1bba7..a4b59754616e 100644
--- a/sys-utils/blkzone.c
+++ b/sys-utils/blkzone.c
@@ -301,7 +301,9 @@ static int blkzone_action(struct blkzone_control *ctl)
 	if (!zonesize)
 		errx(EXIT_FAILURE, _("%s: unable to determine zone size"), ctl->devname);
 
-	fd = init_device(ctl, O_WRONLY);
+	fd = init_device(ctl, O_WRONLY | O_EXCL);
+	if (fd < 0)
+		errx(EXIT_FAILURE, _("%s: unable to open"), ctl->devname);
 
 	if (ctl->offset & (zonesize - 1))
 		errx(EXIT_FAILURE, _("%s: offset %" PRIu64 " is not aligned "
-- 
2.24.1


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

end of thread, other threads:[~2020-05-15 12:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-15  8:41 [PATCH] blkzone: deny destructive ioctls on busy blockdev Johannes Thumshirn
2020-05-15  8:50 ` Chris Hofstaedtler
2020-05-15  9:53   ` Johannes Thumshirn
2020-05-15 10:37     ` Karel Zak
2020-05-15 12:58 ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).