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>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed,  3 May 2023 18:38:14 +0000
From:   John Garry <john.g.garry@...cle.com>
To:     axboe@...nel.dk, kbusch@...nel.org, hch@....de, sagi@...mberg.me,
        martin.petersen@...cle.com, djwong@...nel.org,
        viro@...iv.linux.org.uk, brauner@...nel.org, dchinner@...hat.com,
        jejb@...ux.ibm.com
Cc:     linux-block@...r.kernel.org, linux-kernel@...r.kernel.org,
        linux-nvme@...ts.infradead.org, linux-scsi@...r.kernel.org,
        linux-xfs@...r.kernel.org, linux-fsdevel@...r.kernel.org,
        linux-security-module@...r.kernel.org, paul@...l-moore.com,
        jmorris@...ei.org, serge@...lyn.com,
        John Garry <john.g.garry@...cle.com>
Subject: [PATCH RFC 09/16] block: Add blk_validate_atomic_write_op()

Validate that an atomic write bio size satisfies atomic_write_unit_min
and atomic_write_unit and that the sector satisfies atomic_write_unit.

Also set REQ_NOMERGE - we do not support it yet.

Signed-off-by: John Garry <john.g.garry@...cle.com>
---
 block/blk-core.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/block/blk-core.c b/block/blk-core.c
index 42926e6cb83c..91abf8cc2b62 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -591,6 +591,27 @@ static inline blk_status_t blk_check_zone_append(struct request_queue *q,
 	return BLK_STS_OK;
 }
 
+static blk_status_t blk_validate_atomic_write_op(struct request_queue *q,
+						 struct bio *bio)
+{
+	struct queue_limits *limits = &q->limits;
+
+	if (bio->bi_iter.bi_size % bio->atomic_write_unit)
+		return BLK_STS_IOERR;
+
+	if ((bio->bi_iter.bi_size >> SECTOR_SHIFT) %
+	    limits->atomic_write_unit_min)
+		return BLK_STS_IOERR;
+
+	if (bio->bi_iter.bi_sector % limits->atomic_write_unit_min)
+		return BLK_STS_IOERR;
+
+	/* No support to merge yet, so disable */
+	bio->bi_opf |= REQ_NOMERGE;
+
+	return BLK_STS_OK;
+}
+
 static void __submit_bio(struct bio *bio)
 {
 	struct gendisk *disk = bio->bi_bdev->bd_disk;
@@ -770,6 +791,13 @@ void submit_bio_noacct(struct bio *bio)
 		bio_clear_polled(bio);
 
 	switch (bio_op(bio)) {
+	case REQ_OP_WRITE:
+		if (bio->bi_opf & REQ_ATOMIC) {
+			status = blk_validate_atomic_write_op(q, bio);
+			if (status != BLK_STS_OK)
+				goto end_io;
+		}
+		break;
 	case REQ_OP_DISCARD:
 		if (!bdev_max_discard_sectors(bdev))
 			goto not_supported;
-- 
2.31.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ