Commit a8eed0b
hfsplus: refactor b-tree map page access and add node-type validation
In HFS+ b-trees, the node allocation bitmap is stored across multiple
records. The first chunk resides in the b-tree Header Node at record
index 2, while all subsequent chunks are stored in dedicated Map Nodes
at record index 0.
This structural quirk forces callers like hfs_bmap_alloc() and
hfs_bmap_free() to duplicate boilerplate code to validate offsets, correct
lengths, and map the underlying pages via kmap_local_page(). There is
also currently no strict node-type validation before reading these
records, leaving the allocator vulnerable if a corrupted image points a
map linkage to an Index or Leaf node.
Introduce a unified bit-level API to encapsulate the map record access:
1. A new `struct hfs_bmap_ctx` to cleanly pass state and safely handle
page math across all architectures.
2. `hfs_bmap_get_map_page()`: Automatically validates node types
(HFS_NODE_HEADER vs HFS_NODE_MAP), infers the correct record index,
handles page-boundary math, and returns the unmapped `struct page *`
directly to the caller to avoid asymmetric mappings.
3. `hfs_bmap_clear_bit()`: A clean wrapper that internally handles page
mapping/unmapping for single-bit operations.
Refactor hfs_bmap_alloc() and hfs_bmap_free() to utilize this new API.
This deduplicates the allocator logic, hardens the map traversal against
fuzzed images, and provides the exact abstractions needed for upcoming
mount-time validation checks.
Signed-off-by: Shardul Bankar <[email protected]>
Reviewed-by: Viacheslav Dubeyko <[email protected]>
Tested-by: Viacheslav Dubeyko <[email protected]>
Signed-off-by: Viacheslav Dubeyko <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Viacheslav Dubeyko <[email protected]>1 parent b099ed5 commit a8eed0b
2 files changed
Lines changed: 124 additions & 47 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
132 | 221 | | |
133 | 222 | | |
134 | 223 | | |
| |||
374 | 463 | | |
375 | 464 | | |
376 | 465 | | |
377 | | - | |
| 466 | + | |
| 467 | + | |
378 | 468 | | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | 469 | | |
383 | 470 | | |
384 | 471 | | |
| |||
390 | 477 | | |
391 | 478 | | |
392 | 479 | | |
393 | | - | |
394 | | - | |
395 | 480 | | |
396 | | - | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
397 | 484 | | |
398 | | - | |
| 485 | + | |
399 | 486 | | |
400 | | - | |
401 | 487 | | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
| 488 | + | |
406 | 489 | | |
407 | 490 | | |
408 | 491 | | |
409 | | - | |
410 | | - | |
| 492 | + | |
| 493 | + | |
411 | 494 | | |
412 | 495 | | |
413 | 496 | | |
414 | 497 | | |
415 | | - | |
416 | | - | |
| 498 | + | |
| 499 | + | |
417 | 500 | | |
418 | 501 | | |
419 | 502 | | |
| |||
423 | 506 | | |
424 | 507 | | |
425 | 508 | | |
426 | | - | |
| 509 | + | |
427 | 510 | | |
428 | | - | |
429 | | - | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
430 | 514 | | |
431 | 515 | | |
432 | | - | |
| 516 | + | |
433 | 517 | | |
434 | 518 | | |
435 | 519 | | |
| |||
443 | 527 | | |
444 | 528 | | |
445 | 529 | | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
451 | | - | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
452 | 537 | | |
453 | 538 | | |
454 | 539 | | |
455 | 540 | | |
456 | 541 | | |
457 | 542 | | |
458 | | - | |
459 | 543 | | |
460 | 544 | | |
461 | | - | |
| 545 | + | |
462 | 546 | | |
463 | 547 | | |
464 | 548 | | |
| |||
495 | 579 | | |
496 | 580 | | |
497 | 581 | | |
498 | | - | |
499 | | - | |
500 | | - | |
501 | | - | |
502 | | - | |
503 | | - | |
504 | | - | |
505 | | - | |
506 | | - | |
507 | | - | |
508 | | - | |
509 | | - | |
510 | | - | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
511 | 590 | | |
512 | | - | |
513 | | - | |
514 | | - | |
| 591 | + | |
515 | 592 | | |
516 | | - | |
517 | | - | |
518 | 593 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
510 | 510 | | |
511 | 511 | | |
512 | 512 | | |
| 513 | + | |
| 514 | + | |
513 | 515 | | |
514 | 516 | | |
515 | 517 | | |
| |||
0 commit comments