Various code assumes that the integrity interval is at least 1 sector
and evenly divides the logical block size. Add these checks to
blk_validate_integrity_limits(). This guards against block drivers that
report invalid interval_exp values.

Signed-off-by: Caleb Sander Mateos <[email protected]>
---
 block/blk-settings.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/block/blk-settings.c b/block/blk-settings.c
index d138abc973bb..a9e65dc090da 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -191,12 +191,17 @@ static int blk_validate_integrity_limits(struct 
queue_limits *lim)
                        return -EINVAL;
                }
                break;
        }
 
-       if (!bi->interval_exp)
+       if (!bi->interval_exp) {
                bi->interval_exp = ilog2(lim->logical_block_size);
+       } else if (bi->interval_exp < SECTOR_SHIFT ||
+                  bi->interval_exp > ilog2(lim->logical_block_size)) {
+               pr_warn("invalid interval_exp %u\n", bi->interval_exp);
+               return -EINVAL;
+       }
 
        /*
         * The PI generation / validation helpers do not expect intervals to
         * straddle multiple bio_vecs.  Enforce alignment so that those are
         * never generated, and that each buffer is aligned as expected.
-- 
2.45.2


Reply via email to