Skip to content

Commit d365be8

Browse files
JIT: Fix invalid containment of vector broadcasts (#92371)
The containment checks for vector broadcasts were missing a size check, meaning that a uint broadcast could contain a ubyte/ushort indirection. That would lead to out-of-bounds reads. Fix #83387 Co-authored-by: Jakob Botsch Nielsen <jakob.botsch.nielsen@gmail.com>
1 parent 073588e commit d365be8

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

src/coreclr/jit/gentree.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -19639,8 +19639,8 @@ GenTree* Compiler::gtNewSimdBinOpNode(
1963919639
}
1964019640
else
1964119641
{
19642-
assert(op2->TypeIs(type, simdBaseType, genActualType(simdBaseType)) ||
19643-
(op2->TypeIs(TYP_SIMD12) && type == TYP_SIMD16));
19642+
assert((genActualType(op2) == genActualType(type)) || (genActualType(op2) == genActualType(simdBaseType)) ||
19643+
(op2->TypeIs(TYP_SIMD12) && (type == TYP_SIMD16)));
1964419644
}
1964519645

1964619646
NamedIntrinsic intrinsic = NI_Illegal;

src/coreclr/jit/lowerxarch.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -7956,6 +7956,9 @@ bool Lowering::IsContainableHWIntrinsicOp(GenTreeHWIntrinsic* parentNode, GenTre
79567956
// The memory form of this already takes a pointer and should be treated like a MemoryLoad
79577957
supportsGeneralLoads = !childNode->OperIsHWIntrinsic();
79587958
}
7959+
7960+
supportsGeneralLoads =
7961+
supportsGeneralLoads && (genTypeSize(childNode) >= genTypeSize(parentNode->GetSimdBaseType()));
79597962
break;
79607963
}
79617964

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Runtime.CompilerServices;
5+
using System.Runtime.Intrinsics;
6+
using Xunit;
7+
8+
public class Runtime_83387
9+
{
10+
[MethodImpl(MethodImplOptions.NoOptimization)]
11+
[Fact]
12+
public static int TestEntryPoint()
13+
{
14+
(ushort A, ushort R) c = (1, 65535);
15+
Vector128<uint> v1 = Vector128.Create((uint)100);
16+
v1 = v1 * c.A;
17+
return (int)v1.ToScalar();
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<Optimize>True</Optimize>
4+
</PropertyGroup>
5+
<ItemGroup>
6+
<Compile Include="$(MSBuildProjectName).cs" />
7+
</ItemGroup>
8+
</Project>

0 commit comments

Comments
 (0)