From 110c0c27be93d60bcf05e2a5a2b18af48c8d657c Mon Sep 17 00:00:00 2001 From: toninov Date: Thu, 4 Sep 2025 19:57:43 +0200 Subject: [PATCH] Change error codes for invalid DISCARDs --- dm-sflc/src/lite/discard.c | 5 +++-- dm-sflc/src/lite/sflc_lite.c | 10 ++++------ dm-sflc/src/lite/volume.c | 3 --- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/dm-sflc/src/lite/discard.c b/dm-sflc/src/lite/discard.c index d41d59b..a1d81d1 100644 --- a/dm-sflc/src/lite/discard.c +++ b/dm-sflc/src/lite/discard.c @@ -46,8 +46,8 @@ void sflite_discard_work_fn(struct work_struct *work) /* Check if the slice is mapped */ if (psi == SFLITE_PSI_INVALID) { - /* Attempted to discard an unmapped slice; fail silently, otherwise errors - will be reported under normal operation and confuse the userspace tools. */ + /* Fail silent: returning a specific error code would break + plausible deniability */ goto unlock; } @@ -63,6 +63,7 @@ unlock: /* WARNING: it is crucial that the original bio is terminated here and never reaches the block device, otherwise the effect of a TRIM on the block device would be obvious, and likely to break plausible deniability */ + orig_bio->bi_status = BLK_STS_OK; bio_endio(orig_bio); return; } diff --git a/dm-sflc/src/lite/sflc_lite.c b/dm-sflc/src/lite/sflc_lite.c index aef9a84..0f0a30d 100644 --- a/dm-sflc/src/lite/sflc_lite.c +++ b/dm-sflc/src/lite/sflc_lite.c @@ -48,10 +48,9 @@ static int sflite_map(struct dm_target *ti, struct bio *bio) if (unlikely(bio_op(bio) == REQ_OP_DISCARD)) { /* Ensure the discard request falls within a single slice */ if (unlikely(bio->bi_iter.bi_size != SFLITE_BLOCK_SIZE * SFLITE_SLICE_SCALE)) { - DMWARN("Wrong discard bio size: %u", bio->bi_iter.bi_size); - - /* We have to fail silently, otherwise the filesystem will abort the entire - TRIM operation, even if there are valid 1 MiB slices to be discarded. */ + DMINFO("Wrong discard bio size: %u", bio->bi_iter.bi_size); + // TODO investigate where these are coming from + bio->bi_status = BLK_STS_INVAL; bio_endio(bio); return DM_MAPIO_SUBMITTED; } @@ -59,8 +58,7 @@ static int sflite_map(struct dm_target *ti, struct bio *bio) /* Ensure the logical block number is aligned with the beginning of a slice */ if (unlikely(lblk_num % SFLITE_SLICE_SCALE != 0)) { DMWARN("Unaligned discard bio!"); - - /* Same reason as above, fail silently */ + bio->bi_status = BLK_STS_INVAL; bio_endio(bio); return DM_MAPIO_SUBMITTED; } diff --git a/dm-sflc/src/lite/volume.c b/dm-sflc/src/lite/volume.c index 6166e1f..56cfc0c 100644 --- a/dm-sflc/src/lite/volume.c +++ b/dm-sflc/src/lite/volume.c @@ -148,9 +148,6 @@ struct sflc_volume_base *sflite_vol_ctr(struct sflc_device_base *sd_base, ti->per_io_data_size = sizeof(struct sflite_io); ti->private = svol; - /* Used for testing */ - // DMWARN("%u MiB mapped, %u MiB free", svol->posmap.nr_mapped_slices, sdev->nr_free_slices); - return &svol->sv_base;