Skip to content
Memory corruption Write-up Advanced

I Found a 9.8 Critical Integer Overflow in Google’s TensorFlow. Google Refused to Pay Me.

An integer overflow in TensorFlow Lite Micro's element count calculation could cause a heap buffer overflow when processing a malicious model file. An attacker could potentially achieve denial of service, information disclosure, or remote code execution on affected devices.

0xanubiis Follow

Published on medium.com

Cybersecurity

Aser Ahmed, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 8 min read.

Context

TensorFlow Lite Micro (tflite-micro) is Google's framework for running machine learning models on microcontrollers and embedded devices, the kind of hardware found in smart home devices, industrial sensors, medical equipment and automotive systems. Models are shipped as .tflite files, and the interpreter reads the tensor dimensions declared in that file to work out how much memory each tensor needs.

The function at the centre of this story lives in micro_utils.cc and computes the total number of elements in a tensor by multiplying its dimensions together. That count is then converted into a byte size and used to allocate buffers. If the count can be made to wrap, the allocation and the subsequent writes disagree about how much memory exists.

From the original on medium.com

Setup

The work was done by auditing the tflite-micro source directly, then confirming the arithmetic in isolation and finally exercising the interpreter with a crafted model. The tools involved were:

  • A minimal C++ program compiled with UndefinedBehaviorSanitizer (UBSan) to prove the signed integer overflow.
  • A test harness that loads a malicious .tflite model and runs it under AddressSanitizer (ASan) to observe the resulting memory error.
  • The Google IssueTracker and the tflite-micro GitHub repository for reporting, patching and tracking.

No special access, account or privilege on a target device was needed: the attack vector is a malicious model file, so the precondition is simply that an attacker can get a crafted model loaded by the interpreter.

Finding it

While auditing micro_utils.cc, the researcher found this function:

Text
int ElementCount(const TfLiteIntArray& dims) { int result = 1; for (int i = 0; i < dims.size; ++i) { result *= dims.data[i];  } return result;}
From the original on medium.com

The function multiplies every dimension of a tensor into a 32-bit signed int, with no overflow check at any point. A tensor with dimensions such as [65536, 65536] produces:

Text
65536 × 65536 = 4,294,967,296
From the original on medium.com

A 32-bit signed integer can only hold values up to 2,147,483,647, so the result wraps around to 0. The overflowed value is not used in isolation: it feeds EvalTensorBytes():

Text
size_t EvalTensorBytes(const TfLiteEvalTensor* tensor) { size_t bytes_per_element; TFLITE_DCHECK(kTfLiteOk == TfLiteTypeSizeOf(tensor->type, &bytes_per_element)); return ElementCount(*tensor->dims) * bytes_per_element;}

When ElementCount() returns 0, the byte size becomes 0. The interpreter then allocates a zero-byte buffer, and when it writes tensor data into that buffer a heap buffer overflow occurs.

The researcher's own summary of the issue:

Aspect Details
Vulnerability Integer Overflow → Heap Buffer Overflow
CWE CWE-190
CVSS Score 9.8 (Critical)
Attack Vector Remote (malicious model file)
Authentication None required
Impact DoS, Information Disclosure, potential RCE

Exploitation

Step 1: confirm the arithmetic overflow with UBSan

A minimal C++ program reproducing the multiplication was compiled with UBSan. The sanitizer output was:

Text
arith_overflow.cc:7:16: runtime error: signed integer overflow: 65536 * 65536 cannot be represented in type 'int'Shape: [65536, 65536]Mathematical product: 4,294,967,296Actual result (32-bit int): 0OVERFLOW confirmed!
From the original on medium.com

This confirms the mathematical product, the wrapped 32-bit result of 0, and that the compiler's own sanitizer flags the operation as undefined behaviour.

Step 2: trigger the crash in the interpreter with ASan

A test harness was built that loads a malicious .tflite model and runs it under AddressSanitizer. The output was:

Text
Bytes reported: 262144AddressSanitizer:DEADLYSIGNAL===================================================================29539==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000004==29539==The signal is caused by a READ memory access.==29539==Hint: address points to the zero page.
From the original on medium.com

The harness prints a byte count and ASan then reports a segmentation fault caused by a read from a near-null address. Together with the zero-byte allocation described above, this shows the size calculation and the actual memory access diverging.

Step 3: write and submit a patch

The proposed fix changes the return type to size_t and adds an overflow check before each multiplication:

Text
size_t ElementCount(const TfLiteIntArray& dims) { size_t result = 1; for (int i = 0; i < dims.size; ++i) { if (dims.data[i] > 0 && result > SIZE_MAX / dims.data[i]) { return 0;  } result *= dims.data[i]; } return result;}

The patch was submitted as PR #3658 to the tflite-micro repository. All automated checks passed, the fix was verified, and the IssueTracker was updated with the link.

From the original on medium.com

Step 4: the report is closed as Won't Fix

On 11 August, Google VRP responded to the initial report, marking it Won't Fix (Intended Behaviour) and explaining that for OT1/OT0 projects they require either exact OSS-Fuzz reproduction steps or a committed and merged patch.

From the original on medium.com

Step 5: the pull request is closed

On 12 August the researcher asked the maintainers to review the PR. Maintainer ddavis-2015 closed it immediately with this comment:

"This type change will not be implemented prior to the upstream LiteRT adopting such changes in the common/shared code."

From the original on medium.com

Step 6: VRP declines to act

Also on 12 August, the researcher went back to Google VRP explaining that the PR had been closed but the bug was real. The response:

"Since the maintainers have closed your pull request, we won't be taking any further action on this report."

From the original on medium.com

A follow-up asked whether there was any way to get credit or a smaller reward. The reply:

"As per the program rules, we only reward vulnerabilities that result in a fix or an internal security bug."

From the original on medium.com

Step 7: checking the upstream claim

On 20 August the researcher asked the maintainers for guidance: if the fix had to go upstream to LiteRT, where in the LiteRT codebase should the patch be submitted?

From the original on medium.com

On 30 August the researcher audited the google-ai-edge/LiteRT repository from top to bottom and found that the vulnerable ElementCount() function does not exist upstream. The production kernel utilities in LiteRT use safe, checked versions, for example CheckedElementCount. The vulnerability is entirely specific to tflite-micro. The GitHub PR and the Google IssueTracker were updated with this proof, asking for the PR to be reconsidered since the upstream dependency was a myth.

From the original on medium.com

Step 8: sent upstream anyway

On 18 September Google VRP replied:

"Hi Aser, Please report this directly upstream. If the maintainers recognise it as a security vulnerability, feel free to reopen this report."

From the original on medium.com

Step 9: the issue is opened and closed without explanation

On 22 September, trapped in the loop, the researcher opened Issue #3761 on the tflite-micro GitHub repository, asking the maintainers explicitly:

  1. Is this a security vulnerability in tflite-micro?
  2. If yes, can you provide a statement so I can reopen my report with Google's VRP?
  3. If no, please explain why it is not considered a vulnerability.
From the original on medium.com

On 2 October the researcher pinged the maintainers again asking for an acknowledgment. On 1 November, maintainer veblush closed Issue #3761 with a single tag, Not planned, with no explanation and no acknowledgment.

From the original on medium.com

The loop

  • Google VRP says: get the fix merged and we will pay you.
  • Maintainers say: we won't merge until it goes upstream to LiteRT.
  • The reality: the vulnerable code does not exist upstream in LiteRT.
  • The result: the ticket is closed and the bug remains in the codebase.

Root cause

The defect is a signed integer overflow in ElementCount(). The function accumulates the product of tensor dimensions in a 32-bit signed int and performs no check before each multiplication. Dimensions are attacker-controlled through the model file, so a pair such as [65536, 65536] wraps the product to 0. EvalTensorBytes() multiplies that 0 by the element size and returns 0, so the interpreter allocates a zero-byte buffer while the code that follows still writes tensor data into it, producing a heap buffer overflow.

Impact

According to the researcher, the bug could lead to heap buffer overflows, denial of service and potentially remote code execution on IoT devices running tflite-micro. The attack vector is a malicious model file, no authentication is required, and the researcher rates it 9.8 Critical (CWE-190).

Fix

The fix submitted as PR #3658 changes the return type of ElementCount() to size_t and adds an overflow check before each multiplication, returning 0 when the next multiplication would exceed SIZE_MAX. All automated checks passed and the researcher verified the fix, but the PR was closed by the maintainers on the grounds that the type change would not be implemented before upstream LiteRT adopted it in the common/shared code. The PR was closed, so the fix was not merged.

  • Other dimension products in the same interpreter. Look for any place that multiplies tensor dimensions or strides into a fixed-width integer without a check. A positive result is a sanitizer report of signed overflow, or a computed byte count that is smaller than the product of the dimensions.
  • Zero-size allocations followed by writes. Search for allocation sites whose size comes from a multiplication and whose buffer is written afterwards. A positive result is an ASan report on a write into a buffer whose reported size is 0 or far below the data written.
  • Checked helpers versus unchecked ones. Where a codebase has both a checked variant (such as CheckedElementCount) and an unchecked one, trace which call sites still use the unchecked version. A positive result is a reachable path from parsed input to the unchecked helper.
  • Model-file parsers generally. Craft models with extreme or boundary dimensions (values near powers of two, and pairs whose product crosses the signed maximum) and run them under ASan and UBSan. A positive result is a crash or sanitizer finding that traces back to size arithmetic rather than to malformed structure parsing.
  • Upstream versus downstream divergence. When a maintainer claims a fix belongs upstream, diff the two codebases for the affected function. A positive result is the vulnerable function existing only in the downstream project, which removes the stated blocker and is worth attaching to the report.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 22 min read.

What happened, in plain words

A security researcher named Aser Ahmed spent time reading the source code of a Google open-source project called TensorFlow Lite Micro. Source code is the human-readable text that programmers write; it is later turned into the program that actually runs. While reading one small file, he found a mistake in how the program does arithmetic. That mistake can make the program believe a piece of data is tiny when it is actually enormous, and that mismatch can crash the device or, in the worst case, potentially let an attacker run their own code on it.

He proved the mistake was real with two small experiments, wrote a corrected version of the code, and sent it to the project as a proposed change. Google's bug bounty programme, which pays people for finding security problems, told him it only pays when a fix is actually merged into the project. The people who maintain the project refused to merge his fix, saying the change had to happen in a different, upstream project first. He then checked that upstream project and found the broken code did not exist there at all. So he was stuck: the bounty programme wanted a merged fix, the maintainers wanted an upstream change, and the upstream change was impossible because there was nothing to change. In the end the issue was closed with a single label, "Not planned", and he received no reward.

This article walks through the whole story for someone who has never done security work. Every technical idea is explained where it first appears.

From the original on medium.com

Background: what the software is and why its arithmetic matters

What TensorFlow Lite Micro does

TensorFlow is Google's well-known toolkit for building machine learning models. A machine learning model is a large collection of numbers, produced by training a computer on examples, that lets the computer make predictions or decisions. TensorFlow Lite is a slimmed-down version of that toolkit made for small devices. TensorFlow Lite Micro, usually shortened to tflite-micro, is the slimmest version of all: it is designed to run models on microcontrollers, which are tiny computers with very little memory and processing power.

Think of the difference between a full desktop computer and the chip inside a washing machine. Both compute, but the washing machine chip has a tiny fraction of the memory and speed. tflite-micro is built for that second kind of hardware. The report lists the kinds of products it appears in: smart home devices, industrial sensors, medical equipment and automotive systems. It says the software is used by millions of devices worldwide.

What a model file is

A trained model is stored in a file with the extension .tflite. You can think of this file as a recipe card: it contains the numbers the model learned plus a description of how those numbers are arranged. That description includes tensor dimensions.

A tensor is just a block of numbers arranged in a grid. A single number is a tensor with no dimensions. A list of numbers is a one-dimensional tensor. A table with rows and columns is two-dimensional. A tensor's dimensions say how big it is along each direction: a table with 3 rows and 4 columns has dimensions [3, 4]. The total number of individual numbers in it is 3 times 4, which is 12.

Why the program multiplies dimensions

Before the interpreter (the part of the program that actually runs the model) can work with a tensor, it has to reserve memory for it. To know how much memory to reserve, it first works out how many individual numbers the tensor holds, then multiplies that count by how many bytes each number takes. A byte is the basic unit of computer memory; one byte can hold a small number or one character of text.

So the chain is: multiply the dimensions to get an element count, multiply the element count by the size of one element to get a byte count, then reserve that many bytes. If the first multiplication goes wrong, everything after it goes wrong too. That is exactly what happened here.

From the original on medium.com

The setup: how the researcher worked

The researcher did not attack a live website or a real device. He read the project's source code, then confirmed his reasoning with two small programs on his own computer, and finally used Google's public issue tracker and the project's public code repository to report and discuss the problem.

The tools involved were:

  • A minimal C++ program compiled with UndefinedBehaviorSanitizer (UBSan). C++ is a programming language; a compiler turns C++ text into a runnable program. A sanitizer is a tool built into the compiler that adds extra checks to the running program and shouts when something illegal happens. UBSan specifically watches for operations whose result the language standard does not define, such as arithmetic that overflows.
  • A test harness that loads a malicious .tflite model and runs it under AddressSanitizer (ASan). A test harness is a small program written only to feed a specific input to the code under test. ASan watches memory: it notices when a program reads or writes memory it should not touch.
  • The Google IssueTracker, a website where Google tracks bug reports, and the tflite-micro GitHub repository, a website where the project's source code and proposed changes live. A repository (repo) is a project's folder of code plus its full history of changes.

No special access was needed. The attack vector, meaning the route an attacker uses to deliver the bad input, is simply a malicious model file. The only precondition is that an attacker can get a crafted model loaded by the interpreter. In plain terms: if a device or app lets you supply a model file, you can supply a hostile one.

Finding the bug

The function

While reading the file micro_utils.cc, the researcher found this function:

Text
int ElementCount(const TfLiteIntArray& dims) { int result = 1; for (int i = 0; i < dims.size; ++i) { result *= dims.data[i];  } return result;}
From the original on medium.com

Line by line, in plain words:

  • int ElementCount(const TfLiteIntArray& dims) declares a function called ElementCount. A function is a named block of code that takes some inputs and gives back a result. This one takes dims, which describes the dimensions of a tensor, and promises to return an int, a whole number.
  • int result = 1; creates a working variable called result and starts it at 1. Starting at 1 matters because the function is going to multiply things together; starting at 0 would make every product 0.
  • for (int i = 0; i < dims.size; ++i) is a loop. It runs once for each dimension: i starts at 0 and goes up to one less than the number of dimensions.
  • result *= dims.data[i]; multiplies result by the current dimension and stores the answer back in result. After the loop, result holds the product of all the dimensions, which is the total number of elements.
  • return result; hands that number back to whoever called the function.

The problem is the word int. In C++, int is a 32-bit signed integer: a whole number stored in 32 bits of memory, which can be positive or negative. Its maximum value is 2,147,483,647. The function multiplies into this type with no check at any point, so if the running product ever exceeds that maximum, the arithmetic silently goes wrong.

The overflow

A tensor with dimensions such as [65536, 65536] produces:

Text
65536 × 65536 = 4,294,967,296
From the original on medium.com

Mathematically the answer is 4,294,967,296. But a 32-bit signed integer can only hold values up to 2,147,483,647, so the result wraps around to 0. This is called an integer overflow: the number is too big for the container, and the container silently keeps the wrong value instead of complaining.

An everyday comparison: imagine a car odometer with only four digits. Drive past 9,999 and it flips back to 0000. The car has travelled further, but the display says zero. Here the "display" is the int, and it says zero when the real count is over four billion.

Why zero is dangerous

The overflowed value is not used on its own. It feeds another function, EvalTensorBytes():

Text
size_t EvalTensorBytes(const TfLiteEvalTensor* tensor) { size_t bytes_per_element; TFLITE_DCHECK(kTfLiteOk == TfLiteTypeSizeOf(tensor->type, &bytes_per_element)); return ElementCount(*tensor->dims) * bytes_per_element;}

Line by line:

  • size_t EvalTensorBytes(const TfLiteEvalTensor* tensor) declares a function that takes a description of a tensor and returns a size_t. A size_t is an unsigned whole number type meant for sizes and counts; being unsigned, it cannot go negative, and on typical systems it is wider than a 32-bit int.
  • size_t bytes_per_element; creates a variable to hold how many bytes one element of this tensor occupies.
  • TFLITE_DCHECK(kTfLiteOk == TfLiteTypeSizeOf(tensor->type, &bytes_per_element)); asks a helper to fill in bytes_per_element based on the tensor's data type, and checks that the helper succeeded. TFLITE_DCHECK is a debug assertion: a check that is normally compiled out of release builds.
  • return ElementCount(*tensor->dims) * bytes_per_element; calls the broken function and multiplies its answer by the element size.

When ElementCount() returns 0, the byte size becomes 0. The interpreter then reserves a zero-byte buffer. A buffer is a reserved block of memory; a zero-byte buffer is a reservation of nothing at all. But the code that follows still writes the tensor's data into that buffer. Writing more data than a buffer can hold is a heap buffer overflow. The heap is the pool of memory a program uses for data whose size is decided while it runs, and overflowing it corrupts whatever sits next to the buffer in memory.

The researcher's own summary of the issue:

Aspect Details
Vulnerability Integer Overflow → Heap Buffer Overflow
CWE CWE-190
CVSS Score 9.8 (Critical)
Attack Vector Remote (malicious model file)
Authentication None required
Impact DoS, Information Disclosure, potential RCE

A few of those terms need unpacking. CWE stands for Common Weakness Enumeration, a public catalogue that gives each kind of software mistake a number; CWE-190 is the entry for integer overflow. CVSS is the Common Vulnerability Scoring System, a 0 to 10 scale for how serious a flaw is; 9.8 is near the top and is labelled Critical. DoS means denial of service: making a system crash or stop responding. Information Disclosure means leaking data the attacker should not see. RCE means remote code execution: an attacker getting their own code to run on the victim's device, which is the most severe outcome.

Proving it: the two experiments

Step 1: confirm the arithmetic overflow with UBSan

A minimal C++ program reproducing the multiplication was compiled with UBSan. The sanitizer output was:

Text
arith_overflow.cc:7:16: runtime error: signed integer overflow: 65536 * 65536 cannot be represented in type 'int'Shape: [65536, 65536]Mathematical product: 4,294,967,296Actual result (32-bit int): 0OVERFLOW confirmed!
From the original on medium.com

What each part says:

  • arith_overflow.cc:7:16: runtime error: signed integer overflow: 65536 * 65536 cannot be represented in type 'int' is UBSan's complaint. It names the file (arith_overflow.cc), the line and column (7:16), and states that the multiplication cannot be represented in an int. In other words, the compiler's own checker agrees the operation is illegal.
  • Shape: [65536, 65536] is the program printing the dimensions it used.
  • Mathematical product: 4,294,967,296 is the true answer.
  • Actual result (32-bit int): 0 is what the 32-bit integer actually held after the wrap.
  • OVERFLOW confirmed! is the program's own conclusion.

Why this step matters: before blaming a huge project, you want to show the arithmetic itself is broken in isolation, with nothing else involved. This experiment does exactly that.

Step 2: trigger the crash in the interpreter with ASan

A test harness was built that loads a malicious .tflite model and runs it under AddressSanitizer. The output was:

Text
Bytes reported: 262144AddressSanitizer:DEADLYSIGNAL===================================================================29539==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000004==29539==The signal is caused by a READ memory access.==29539==Hint: address points to the zero page.
From the original on medium.com

What each part says:

  • Bytes reported: 262144 is a byte count printed by the harness.
  • AddressSanitizer:DEADLYSIGNAL means ASan saw a signal that normally kills the program.
  • ERROR: AddressSanitizer: SEGV on unknown address 0x000000000004 reports a segmentation fault (SEGV), which is what happens when a program touches memory it is not allowed to touch, at a very small address.
  • The signal is caused by a READ memory access. says the program was trying to read, not write, when it crashed.
  • Hint: address points to the zero page. explains that the address is near zero.

Why this step matters: the first experiment proved the arithmetic is wrong. This one proves the wrong arithmetic actually reaches memory in the real interpreter and causes a crash. Together with the zero-byte allocation described above, the output shows the size calculation and the actual memory access disagreeing.

Step 3: write and submit a patch

The proposed fix changes the return type to size_t and adds an overflow check before each multiplication:

Text
size_t ElementCount(const TfLiteIntArray& dims) { size_t result = 1; for (int i = 0; i < dims.size; ++i) { if (dims.data[i] > 0 && result > SIZE_MAX / dims.data[i]) { return 0;  } result *= dims.data[i]; } return result;}

Line by line:

  • size_t ElementCount(const TfLiteIntArray& dims) now returns a size_t, an unsigned type wide enough for realistic sizes, instead of a 32-bit signed int.
  • size_t result = 1; starts the running product as a size_t too, so the multiplication happens in the wider type.
  • for (int i = 0; i < dims.size; ++i) is the same loop over the dimensions as before.
  • if (dims.data[i] > 0 && result > SIZE_MAX / dims.data[i]) is the new guard. SIZE_MAX is the largest value a size_t can hold. Dividing it by the next dimension tells you the largest result that can safely be multiplied by that dimension. If the current result is bigger than that, the multiplication would overflow.
  • return 0; is what happens in that case: the function refuses to produce a bogus count and reports zero instead, which the caller can treat as an error.
  • result *= dims.data[i]; performs the multiplication only when it is known to be safe.
  • return result; hands back the correct count.

The patch was submitted as PR #3658 to the tflite-micro repository. A PR, or pull request, is a formal proposal on a code hosting site: "here is a change, please review it and merge it into the project". Merging means accepting the change into the official code. All automated checks passed, the fix was verified, and the IssueTracker was updated with the link.

From the original on medium.com

The bureaucracy: what happened after the fix

This is where a technical success turned into a process problem. The dates below come from the Google IssueTracker and GitHub.

Step 4: the report is closed as Won't Fix

On 11 August, Google VRP responded to the initial report, marking it Won't Fix (Intended Behaviour) and explaining that for OT1/OT0 projects they require either exact OSS-Fuzz reproduction steps or a committed and merged patch.

Some terms here: VRP stands for Vulnerability Reward Program, Google's bug bounty scheme. OT1/OT0 are project tiers Google refers to in its VRP rules. "Exact OSS-Fuzz reproduction steps" means a recipe that reproduces the crash inside that service. "Committed and merged patch" means the fix is already part of the official code.

From the original on medium.com

Step 5: the pull request is closed

On 12 August the researcher asked the maintainers to review the PR. Maintainers are the people with permission to accept or reject changes to a project; many are volunteers or busy engineers. Maintainer ddavis-2015 closed it immediately with this comment:

"This type change will not be implemented prior to the upstream LiteRT adopting such changes in the common/shared code."

In plain words: we will not change this type here until the upstream project, LiteRT, makes the same change in the code the two projects share. Upstream means the project that another project is derived from or depends on; changes are expected to flow from upstream down, not the other way round.

From the original on medium.com

Step 6: VRP declines to act

Also on 12 August, the researcher went back to Google VRP explaining that the PR had been closed but the bug was real. The response:

"Since the maintainers have closed your pull request, we won't be taking any further action on this report."

From the original on medium.com

A follow-up asked whether there was any way to get credit or a smaller reward. The reply:

"As per the program rules, we only reward vulnerabilities that result in a fix or an internal security bug."

From the original on medium.com

Step 7: checking the upstream claim

On 20 August the researcher asked the maintainers for guidance: if the fix had to go upstream to LiteRT, where in the LiteRT codebase should the patch be submitted?

From the original on medium.com

On 30 August the researcher audited the google-ai-edge/LiteRT repository from top to bottom and found that the vulnerable ElementCount() function does not exist upstream. The production kernel utilities in LiteRT use safe, checked versions, for example CheckedElementCount. The vulnerability is entirely specific to tflite-micro. The GitHub PR and the Google IssueTracker were updated with this proof, asking for the PR to be reconsidered since the upstream dependency was a myth.

Why this step matters: the maintainers' reason for refusing the fix was that it had to happen upstream first. If the broken code is not upstream at all, that reason cannot apply. The researcher was removing the stated blocker with evidence.

From the original on medium.com

Step 8: sent upstream anyway

On 18 September Google VRP replied:

"Hi Aser, Please report this directly upstream. If the maintainers recognise it as a security vulnerability, feel free to reopen this report."

From the original on medium.com

Step 9: the issue is opened and closed without explanation

On 22 September, trapped in the loop, the researcher opened Issue #3761 on the tflite-micro GitHub repository. An issue is a public discussion thread attached to a repository, used to report bugs or ask questions. He asked the maintainers explicitly:

  1. Is this a security vulnerability in tflite-micro?
  2. If yes, can you provide a statement so I can reopen my report with Google's VRP?
  3. If no, please explain why it is not considered a vulnerability.
From the original on medium.com

On 2 October the researcher pinged the maintainers again asking for an acknowledgment. On 1 November, maintainer veblush closed Issue #3761 with a single tag, Not planned, with no explanation and no acknowledgment.

From the original on medium.com

The loop

  • Google VRP says: get the fix merged and we will pay you.
  • Maintainers say: we won't merge until it goes upstream to LiteRT.
  • The reality: the vulnerable code does not exist upstream in LiteRT.
  • The result: the ticket is closed and the bug remains in the codebase.

A catch-22 is a situation where each side's requirement can only be met by the other side acting first, so nothing can happen. That is exactly the shape of this story.

Root cause

The defect is a signed integer overflow in ElementCount(). The function accumulates the product of tensor dimensions in a 32-bit signed int and performs no check before each multiplication. Dimensions are attacker-controlled through the model file, so a pair such as [65536, 65536] wraps the product to 0. EvalTensorBytes() multiplies that 0 by the element size and returns 0, so the interpreter allocates a zero-byte buffer while the code that follows still writes tensor data into it, producing a heap buffer overflow.

Impact

According to the researcher, the bug could lead to heap buffer overflows, denial of service and potentially remote code execution on IoT devices running tflite-micro. IoT stands for Internet of Things: everyday devices with small computers inside them, connected to a network. The attack vector is a malicious model file, no authentication is required, and the researcher rates it 9.8 Critical (CWE-190).

Fix

The fix submitted as PR #3658 changes the return type of ElementCount() to size_t and adds an overflow check before each multiplication, returning 0 when the next multiplication would exceed SIZE_MAX. All automated checks passed and the researcher verified the fix, but the PR was closed by the maintainers on the grounds that the type change would not be implemented before upstream LiteRT adopted it in the common/shared code. The PR was closed, so the fix was not merged.

If you want to look for similar problems yourself, these are the directions the researcher suggests. Each one describes what to look for and what a positive result would look like.

  • Other dimension products in the same interpreter. Look for any place that multiplies tensor dimensions or strides into a fixed-width integer without a check. A stride is the step size used to move from one element to the next in memory. A positive result is a sanitizer report of signed overflow, or a computed byte count that is smaller than the product of the dimensions.
  • Zero-size allocations followed by writes. Search for allocation sites whose size comes from a multiplication and whose buffer is written afterwards. A positive result is an ASan report on a write into a buffer whose reported size is 0 or far below the data written.
  • Checked helpers versus unchecked ones. Where a codebase has both a checked variant (such as CheckedElementCount) and an unchecked one, trace which call sites still use the unchecked version. A call site is a place in the code where a function is invoked. A positive result is a reachable path from parsed input to the unchecked helper.
  • Model-file parsers generally. A parser is the part of a program that reads a file and turns its contents into usable data. Craft models with extreme or boundary dimensions (values near powers of two, and pairs whose product crosses the signed maximum) and run them under ASan and UBSan. A positive result is a crash or sanitizer finding that traces back to size arithmetic rather than to malformed structure parsing.
  • Upstream versus downstream divergence. When a maintainer claims a fix belongs upstream, diff the two codebases for the affected function. A diff is a side-by-side comparison of two versions of code. A positive result is the vulnerable function existing only in the downstream project, which removes the stated blocker and is worth attaching to the report.

Lessons from the process

The researcher's own conclusions, in plain terms:

  1. Open-source governance is complicated, and sometimes hostile. Maintainers are often volunteers or busy engineers with their own priorities. An external contribution, even a correct one that fixes a critical memory corruption, may not fit their immediate roadmap.
  2. Reward programme rules have strict requirements. For memory corruption bugs in high-tier projects, Google requires either exact OSS-Fuzz reproduction steps or a merged patch. Without one of these, the report will not be rewarded, no matter how valid the bug is.
  3. Do not submit public PRs for bugs you plan to claim a bounty on. Because the PR was public, the vulnerability details became public. It was no longer a zero-day, meaning a flaw that is not yet publicly known and therefore still dangerous. Google may consider public bugs less valuable, and the maintainers felt comfortable ignoring it once the pressure of a private disclosure was gone.
  4. The real reward is the experience. The researcher lists what he learned: how to audit C++ code for memory safety bugs, how to build proofs of concept with UBSan and ASan, how to navigate open-source politics, and why you should always double-check whether a programme requires a merged patch before investing weeks of your life.

His closing advice for people starting in security research:

  1. Read the reward programme guidelines carefully. If they require a merged patch, be prepared for a fight.
  2. Choose your targets wisely. Some projects have clearer reward paths than others.
  3. Document everything. Your report, your proof of concept and your issue tracker screenshots are your only evidence.
  4. Focus on the skills, not just the bounty.

The bug was real. The fix was correct. The system did not reward him. But, in his words, he is a better security researcher because of it.

Glossary

  • AddressSanitizer (ASan): a compiler tool that adds checks to a running program and reports when it reads or writes memory it should not touch.
  • Attack vector: the route an attacker uses to deliver hostile input to a target.
  • Buffer: a reserved block of memory used to hold data.
  • Byte: the basic unit of computer memory, enough for a small number or one character.
  • C++: a programming language commonly used for performance-sensitive software.
  • Call site: a place in code where a function is invoked.
  • Catch-22: a situation where each side's requirement can only be met if the other side acts first, so nothing can progress.
  • Compiler: a program that turns source code text into a runnable program.
  • CVSS: the Common Vulnerability Scoring System, a 0 to 10 scale for rating the severity of a flaw.
  • CWE: Common Weakness Enumeration, a public catalogue that numbers each kind of software mistake; CWE-190 is integer overflow.
  • Debug assertion (TFLITE_DCHECK): a check that is normally removed from release builds, so it protects nothing in production.
  • Denial of service (DoS): making a system crash or stop responding.
  • Diff: a side-by-side comparison of two versions of code.
  • Dimensions (of a tensor): the sizes of a tensor along each direction, such as [3, 4] for a table with 3 rows and 4 columns.
  • Function: a named block of code that takes inputs and returns a result.
  • Heap: the pool of memory a program uses for data whose size is decided while it runs.
  • Heap buffer overflow: writing more data into a heap buffer than it can hold, corrupting neighbouring memory.
  • Information disclosure: leaking data the attacker should not be able to see.
  • Integer overflow: a number growing too large for its storage type, so the stored value silently becomes wrong.
  • int (32-bit signed integer): a whole-number type stored in 32 bits, able to hold values up to 2,147,483,647.
  • IoT (Internet of Things): everyday devices with small computers inside them, connected to a network.
  • Issue: a public discussion thread attached to a code repository, used to report bugs or ask questions.
  • Maintainer: a person with permission to accept or reject changes to a project.
  • Merge: to accept a proposed change into the official code.
  • Microcontroller: a tiny computer with very little memory and processing power, used inside devices.
  • Model (machine learning): a large collection of numbers produced by training, used to make predictions or decisions.
  • OSS-Fuzz: Google's service that continuously feeds random and malformed inputs to open-source software to find crashes.
  • OT1/OT0: internal tiers Google uses to classify open-source projects by how much security support they get.
  • Parser: the part of a program that reads a file and turns its contents into usable data.
  • PR (pull request): a formal proposal on a code hosting site to review and merge a change into a project.
  • Proof of concept (PoC): a small, controlled demonstration that a flaw is real.
  • Remote code execution (RCE): an attacker getting their own code to run on the victim's device.
  • Repository (repo): a project's folder of code plus its full history of changes.
  • Sanitizer: a compiler tool that adds extra checks to a running program and reports illegal behaviour.
  • Segmentation fault (SEGV): the crash that happens when a program touches memory it is not allowed to touch.
  • size_t: an unsigned whole-number type meant for sizes and counts.
  • SIZE_MAX: the largest value a size_t can hold.
  • Source code: the human-readable text programmers write, which is later turned into a running program.
  • Stride: the step size used to move from one element to the next in memory.
  • Tensor: a block of numbers arranged in a grid, with a number of dimensions.
  • Test harness: a small program written only to feed a specific input to the code under test.
  • tflite-micro: TensorFlow Lite Micro, Google's framework for running machine learning models on microcontrollers and embedded devices.
  • Undefined behaviour: an operation whose result the programming language standard does not define, such as signed integer overflow.
  • UndefinedBehaviorSanitizer (UBSan): a compiler tool that reports operations with undefined behaviour, such as arithmetic overflow.
  • Upstream: the project that another project is derived from or depends on; changes are expected to flow from upstream down.
  • VRP: Vulnerability Reward Program, Google's bug bounty scheme.
  • Zero page: the very start of a program's address space, deliberately left unmapped so that null or near-null pointer use crashes immediately.
  • Zero-day: a flaw that is not yet publicly known and therefore still dangerous.

More by 0xanubiis

View all

3 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.