hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/md/dm-flakey.c
....@@ -124,9 +124,9 @@
124124 * Direction r or w?
125125 */
126126 arg_name = dm_shift_arg(as);
127
- if (!strcasecmp(arg_name, "w"))
127
+ if (arg_name && !strcasecmp(arg_name, "w"))
128128 fc->corrupt_bio_rw = WRITE;
129
- else if (!strcasecmp(arg_name, "r"))
129
+ else if (arg_name && !strcasecmp(arg_name, "r"))
130130 fc->corrupt_bio_rw = READ;
131131 else {
132132 ti->error = "Invalid corrupt bio direction (r or w)";
....@@ -301,8 +301,11 @@
301301 */
302302 bio_for_each_segment(bvec, bio, iter) {
303303 if (bio_iter_len(bio, iter) > corrupt_bio_byte) {
304
- char *segment = (page_address(bio_iter_page(bio, iter))
305
- + bio_iter_offset(bio, iter));
304
+ char *segment;
305
+ struct page *page = bio_iter_page(bio, iter);
306
+ if (unlikely(page == ZERO_PAGE(0)))
307
+ break;
308
+ segment = (page_address(page) + bio_iter_offset(bio, iter));
306309 segment[corrupt_bio_byte] = fc->corrupt_bio_value;
307310 DMDEBUG("Corrupting data bio=%p by writing %u to byte %u "
308311 "(rw=%c bi_opf=%u bi_sector=%llu size=%u)\n",
....@@ -359,9 +362,11 @@
359362 /*
360363 * Corrupt matching writes.
361364 */
362
- if (fc->corrupt_bio_byte && (fc->corrupt_bio_rw == WRITE)) {
363
- if (all_corrupt_bio_flags_match(bio, fc))
364
- corrupt_bio_data(bio, fc);
365
+ if (fc->corrupt_bio_byte) {
366
+ if (fc->corrupt_bio_rw == WRITE) {
367
+ if (all_corrupt_bio_flags_match(bio, fc))
368
+ corrupt_bio_data(bio, fc);
369
+ }
365370 goto map_bio;
366371 }
367372
....@@ -387,13 +392,14 @@
387392 return DM_ENDIO_DONE;
388393
389394 if (!*error && pb->bio_submitted && (bio_data_dir(bio) == READ)) {
390
- if (fc->corrupt_bio_byte && (fc->corrupt_bio_rw == READ) &&
391
- all_corrupt_bio_flags_match(bio, fc)) {
392
- /*
393
- * Corrupt successful matching READs while in down state.
394
- */
395
- corrupt_bio_data(bio, fc);
396
-
395
+ if (fc->corrupt_bio_byte) {
396
+ if ((fc->corrupt_bio_rw == READ) &&
397
+ all_corrupt_bio_flags_match(bio, fc)) {
398
+ /*
399
+ * Corrupt successful matching READs while in down state.
400
+ */
401
+ corrupt_bio_data(bio, fc);
402
+ }
397403 } else if (!test_bit(DROP_WRITES, &fc->flags) &&
398404 !test_bit(ERROR_WRITES, &fc->flags)) {
399405 /*