Re: [PATCH v5 02/11] block: Block Device Filtering Mechanism

From: Yu Kuai
Date: Wed Jul 12 2023 - 08:35:10 EST


Hi,

在 2023/07/12 18:04, Yu Kuai 写道:
Hi,

在 2023/07/11 10:02, Yu Kuai 写道:

+static bool submit_bio_filter(struct bio *bio)
+{
+    if (bio_flagged(bio, BIO_FILTERED))
+        return false;
+
+    bio_set_flag(bio, BIO_FILTERED);
+    return bio->bi_bdev->bd_filter->ops->submit_bio(bio);
+}
+
  static void __submit_bio(struct bio *bio)
  {
+    /*
+     * If there is a filter driver attached, check if the BIO needs to go to
+     * the filter driver first, which can then pass on the bio or consume it.
+     */
+    if (bio->bi_bdev->bd_filter && submit_bio_filter(bio))
+        return;
+
      if (unlikely(!blk_crypto_bio_prep(&bio)))
          return;

...

+static void __blkfilter_detach(struct block_device *bdev)
+{
+    struct blkfilter *flt = bdev->bd_filter;
+    const struct blkfilter_operations *ops = flt->ops;
+
+    bdev->bd_filter = NULL;
+    ops->detach(flt);
+    module_put(ops->owner);
+}
+
+void blkfilter_detach(struct block_device *bdev)
+{
+    if (bdev->bd_filter) {
+        blk_mq_freeze_queue(bdev->bd_queue);

And this is not sate as well, for bio-based device, q_usage_counter is
not grabbed while submit_bio_filter() is called, hence there is a risk
of uaf from submit_bio_filter().

And there is another question, can blkfilter_detach() from
del_gendisk/delete_partiton and ioctl concurrent? I think it's a
problem.

Thanks,
Kuai

Thanks,
Kuai

.