diff --git a/kernels/portable/cpu/op_convolution.cpp b/kernels/portable/cpu/op_convolution.cpp index bf848bc53c2..efb6e5898cf 100644 --- a/kernels/portable/cpu/op_convolution.cpp +++ b/kernels/portable/cpu/op_convolution.cpp @@ -203,6 +203,15 @@ void convolution_wrapper( bool transposed, int64_t groups, Tensor& out) { + // Defense-in-depth: get_load_to_compute_fn returns nullptr (and sets + // ctx.fail()) when bias' scalar_type is outside the dispatcher's + // supported set. check_convolution_args() in kernel_ops_util.cpp now + // rejects such bias tensors at the trust boundary, but we keep this guard + // so any future caller of convolution_wrapper is safe; load_bias is + // dereferenced inside the wrapper / conv2d_impl whenever bias has data. + if (bias.has_value() && load_bias == nullptr) { + return; + } SizesArrayRef in_sizes = in.sizes(); SizesArrayRef weight_sizes = weight.sizes(); SizesArrayRef out_sizes = out.sizes(); diff --git a/kernels/portable/cpu/op_cumsum.cpp b/kernels/portable/cpu/op_cumsum.cpp index 3a518d30715..2ad35941c8b 100644 --- a/kernels/portable/cpu/op_cumsum.cpp +++ b/kernels/portable/cpu/op_cumsum.cpp @@ -44,6 +44,14 @@ void cumsum_tensors( if (self.numel() == 0) { return; } + // Defense-in-depth: get_load_to_compute_fn returns nullptr (and sets + // ctx.fail()) when the input tensor's scalar_type is outside the dispatcher's + // supported set. check_cumsum_args() in kernel_ops_util.cpp now rejects such + // inputs at the trust boundary, but we keep this guard so any future caller + // of cumsum_tensors is safe. + if (load_self == nullptr) { + return; + } const char* const input_data_base = reinterpret_cast(self.const_data_ptr()); diff --git a/kernels/portable/cpu/util/kernel_ops_util.cpp b/kernels/portable/cpu/util/kernel_ops_util.cpp index 2e0ceee07e5..0bc20dcd5a2 100644 --- a/kernels/portable/cpu/util/kernel_ops_util.cpp +++ b/kernels/portable/cpu/util/kernel_ops_util.cpp @@ -380,6 +380,8 @@ bool check_convolution_args( int64_t groups, const Tensor& out) { ET_LOG_AND_RETURN_IF_FALSE(tensors_have_same_dtype(in, weight, out)); + ET_LOG_AND_RETURN_IF_FALSE( + executorch::runtime::tensor_is_realhbf16_type(in)); ET_LOG_AND_RETURN_IF_FALSE(tensor_is_default_or_channels_last_dim_order(in)); ET_LOG_AND_RETURN_IF_FALSE( @@ -395,6 +397,8 @@ bool check_convolution_args( if (bias.has_value()) { ET_LOG_AND_RETURN_IF_FALSE(tensor_is_rank(bias.value(), 1)); + ET_LOG_AND_RETURN_IF_FALSE( + executorch::runtime::tensor_is_realhbf16_type(bias.value())); ET_CHECK_OR_RETURN_FALSE( bias.value().size(0) == transposed ? groups * weight.size(1) : weight.size(0), @@ -510,6 +514,10 @@ bool check_cumsum_args( optional dtype, Tensor& out) { ET_LOG_AND_RETURN_IF_FALSE(dim_is_valid(dim, in.dim())); + ET_LOG_AND_RETURN_IF_FALSE( + executorch::runtime::tensor_is_realhbbf16_type(in)); + ET_LOG_AND_RETURN_IF_FALSE( + executorch::runtime::tensor_is_realhbbf16_type(out)); if (dtype.has_value()) { ET_LOG_AND_RETURN_IF_FALSE(dtype.value() == out.scalar_type());