Commit f7b5fa8
xfs: bounds-check buffer log item's dirty bitmap
[ Upstream commit 813f813 ]
xlog_recover_do_reg_buffer() replays each dirty region described by a
buffer log item's bitmap into the buffer read for that item:
memcpy(xfs_buf_offset(bp, (uint)bit << XFS_BLF_SHIFT),
item->ri_buf[i].iov_base,
nbits << XFS_BLF_SHIFT);
The destination offset (bit/nbits, from the logged dirty bitmap) and the
buffer size (from the logged blf_len) are both attacker-controlled and
otherwise unrelated, yet the only thing bounding the copy is an ASSERT(),
which compiles away on production kernels. A crafted image logging a
small blf_len together with a bitmap bit past the end of that buffer
drives the memcpy() past the buffer's allocation, corrupting adjacent
kernel heap during mount-time log recovery. This is reachable by anyone
who can get a crafted image mounted -- the malicious-filesystem threat
model XFS already guards against elsewhere.
Turn the ASSERT() into a real XFS_IS_CORRUPT() check that aborts recovery
of the buffer with -EFSCORRUPTED, consistent with the validate-and-fail
idiom already used in xlog_recover_do_inode_buffer() and
xfs_dquot_item_recover.c. xlog_recover_do_reg_buffer() therefore becomes
STATIC int and its three callers propagate the error.
Found and confirmed with KASAN on a CONFIG_XFS_DEBUG=n build: the crafted
image trips a slab-out-of-bounds write before this change and fails
recovery cleanly with -EFSCORRUPTED after it.
Fixes: 1da177e ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Signed-off-by: Ibrahim Hashimov <security@auditcode.ai>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
[ dropped the `xlog_recover_do_primary_sb_buffer()` error-propagation hunk and its primary-SB/rtsb arm since that helper doesn't exist, keeping only the `error = 0;` reset ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>1 parent cacb124 commit f7b5fa8
1 file changed
Lines changed: 38 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
441 | 441 | | |
442 | 442 | | |
443 | 443 | | |
444 | | - | |
| 444 | + | |
445 | 445 | | |
446 | 446 | | |
447 | 447 | | |
| |||
469 | 469 | | |
470 | 470 | | |
471 | 471 | | |
472 | | - | |
473 | | - | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
474 | 490 | | |
475 | 491 | | |
476 | 492 | | |
| |||
524 | 540 | | |
525 | 541 | | |
526 | 542 | | |
| 543 | + | |
527 | 544 | | |
528 | 545 | | |
529 | 546 | | |
| |||
532 | 549 | | |
533 | 550 | | |
534 | 551 | | |
535 | | - | |
536 | | - | |
| 552 | + | |
| 553 | + | |
537 | 554 | | |
538 | | - | |
| 555 | + | |
539 | 556 | | |
540 | 557 | | |
541 | 558 | | |
| |||
544 | 561 | | |
545 | 562 | | |
546 | 563 | | |
| 564 | + | |
547 | 565 | | |
548 | 566 | | |
549 | 567 | | |
550 | 568 | | |
551 | 569 | | |
552 | 570 | | |
553 | 571 | | |
554 | | - | |
| 572 | + | |
555 | 573 | | |
556 | 574 | | |
557 | 575 | | |
| |||
564 | 582 | | |
565 | 583 | | |
566 | 584 | | |
567 | | - | |
| 585 | + | |
568 | 586 | | |
569 | | - | |
570 | | - | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
571 | 591 | | |
572 | 592 | | |
573 | 593 | | |
| |||
962 | 982 | | |
963 | 983 | | |
964 | 984 | | |
965 | | - | |
966 | | - | |
967 | | - | |
968 | | - | |
| 985 | + | |
| 986 | + | |
969 | 987 | | |
| 988 | + | |
| 989 | + | |
970 | 990 | | |
971 | | - | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
972 | 995 | | |
973 | 996 | | |
974 | 997 | | |
| |||
0 commit comments