Skip to content

Commit 2b19226

Browse files
victorgomesMichal Klocek
authored andcommitted
[463][Backport] CVE-2025-7656: Integer overflow in V8
Cherry-pick of patch originally reviewed on https://chromium-review.googlesource.com/c/v8/v8/+/6683635: Ensure InstructionAccurateScope is called with correct count The scope prevents veneer pool generation. We need to pass the correct count of instructions to CheckVeneerPool inside the scope constructor, otherwise we might overflow the veneer distance margin in the next check (after the scope has ended). Fixed: 425583995 Change-Id: Iebb81898c4f7999137fc784ce6704773614c2bb5 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/6683635 Auto-Submit: Victor Gomes <victorgomes@chromium.org> Commit-Queue: Victor Gomes <victorgomes@chromium.org> Commit-Queue: Igor Sheludko <ishell@chromium.org> Reviewed-by: Igor Sheludko <ishell@chromium.org> Cr-Commit-Position: refs/heads/main@{#101089} Reviewed-on: https://codereview.qt-project.org/c/qt/qtwebengine-chromium/+/665064 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
1 parent d92fc14 commit 2b19226

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

chromium/v8/src/codegen/arm64/macro-assembler-arm64.cc

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,7 @@ void MacroAssembler::PushHelper(int count, int size, const CPURegister& src0,
12761276
const CPURegister& src2,
12771277
const CPURegister& src3) {
12781278
// Ensure that we don't unintentially modify scratch or debug registers.
1279-
InstructionAccurateScope scope(this);
1279+
InstructionAccurateScope scope(this, count <= 2 ? 1 : 2);
12801280

12811281
DCHECK(AreSameSizeAndType(src0, src1, src2, src3));
12821282
DCHECK(size == src0.SizeInBytes());
@@ -1313,7 +1313,7 @@ void MacroAssembler::PopHelper(int count, int size, const CPURegister& dst0,
13131313
const CPURegister& dst1, const CPURegister& dst2,
13141314
const CPURegister& dst3) {
13151315
// Ensure that we don't unintentially modify scratch or debug registers.
1316-
InstructionAccurateScope scope(this);
1316+
InstructionAccurateScope scope(this, count <= 2 ? 1 : 2);
13171317

13181318
DCHECK(AreSameSizeAndType(dst0, dst1, dst2, dst3));
13191319
DCHECK(size == dst0.SizeInBytes());
@@ -1363,8 +1363,14 @@ void MacroAssembler::PeekPair(const CPURegister& dst1, const CPURegister& dst2,
13631363

13641364
void MacroAssembler::PushCalleeSavedRegisters() {
13651365
ASM_CODE_COMMENT(this);
1366+
#ifdef V8_ENABLE_CONTROL_FLOW_INTEGRITY
1367+
constexpr int kInstrCount = 11;
1368+
#else
1369+
constexpr int kInstrCount = 10;
1370+
#endif
1371+
13661372
// Ensure that the macro-assembler doesn't use any scratch registers.
1367-
InstructionAccurateScope scope(this);
1373+
InstructionAccurateScope scope(this, kInstrCount);
13681374

13691375
MemOperand tos(sp, -2 * static_cast<int>(kXRegSize), PreIndex);
13701376

@@ -1397,8 +1403,14 @@ void MacroAssembler::PushCalleeSavedRegisters() {
13971403

13981404
void MacroAssembler::PopCalleeSavedRegisters() {
13991405
ASM_CODE_COMMENT(this);
1406+
#ifdef V8_ENABLE_CONTROL_FLOW_INTEGRITY
1407+
constexpr int kInstrCount = 11;
1408+
#else
1409+
constexpr int kInstrCount = 10;
1410+
#endif
1411+
14001412
// Ensure that the macro-assembler doesn't use any scratch registers.
1401-
InstructionAccurateScope scope(this);
1413+
InstructionAccurateScope scope(this, kInstrCount);
14021414

14031415
MemOperand tos(sp, 2 * kXRegSize, PostIndex);
14041416

chromium/v8/src/codegen/arm64/macro-assembler-arm64.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2458,20 +2458,19 @@ class V8_EXPORT_PRIVATE MacroAssembler : public MacroAssemblerBase {
24582458
// emitted is what you specified when creating the scope.
24592459
class V8_NODISCARD InstructionAccurateScope {
24602460
public:
2461-
explicit InstructionAccurateScope(MacroAssembler* masm, size_t count = 0)
2461+
explicit InstructionAccurateScope(MacroAssembler* masm, size_t count)
24622462
: masm_(masm),
24632463
block_pool_(masm, count * kInstrSize)
24642464
#ifdef DEBUG
24652465
,
24662466
size_(count * kInstrSize)
24672467
#endif
24682468
{
2469+
DCHECK_GT(count, 0);
24692470
masm_->CheckVeneerPool(false, true, count * kInstrSize);
24702471
masm_->StartBlockVeneerPool();
24712472
#ifdef DEBUG
2472-
if (count != 0) {
2473-
masm_->bind(&start_);
2474-
}
2473+
masm_->bind(&start_);
24752474
previous_allow_macro_instructions_ = masm_->allow_macro_instructions();
24762475
masm_->set_allow_macro_instructions(false);
24772476
#endif
@@ -2480,9 +2479,7 @@ class V8_NODISCARD InstructionAccurateScope {
24802479
~InstructionAccurateScope() {
24812480
masm_->EndBlockVeneerPool();
24822481
#ifdef DEBUG
2483-
if (start_.is_bound()) {
2484-
DCHECK(masm_->SizeOfCodeGeneratedSince(&start_) == size_);
2485-
}
2482+
DCHECK(masm_->SizeOfCodeGeneratedSince(&start_) == size_);
24862483
masm_->set_allow_macro_instructions(previous_allow_macro_instructions_);
24872484
#endif
24882485
}

0 commit comments

Comments
 (0)