From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Tiffany Yang <ynaffit@google.com>,
Carlos Llamas <cmllamas@google.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Sasha Levin <sashal@kernel.org>,
arve@android.com, tkjos@android.com, maco@android.com,
joelagnelf@nvidia.com, surenb@google.com,
linux-kernel@vger.kernel.org
Subject: [PATCH AUTOSEL 6.16 18/85] binder: Fix selftest page indexing
Date: Sun, 3 Aug 2025 20:22:27 -0400 [thread overview]
Message-ID: <20250804002335.3613254-18-sashal@kernel.org> (raw)
In-Reply-To: <20250804002335.3613254-1-sashal@kernel.org>
From: Tiffany Yang <ynaffit@google.com>
[ Upstream commit bea3e7bfa2957d986683543cbf57092715f9a91b ]
The binder allocator selftest was only checking the last page of buffers
that ended on a page boundary. Correct the page indexing to account for
buffers that are not page-aligned.
Signed-off-by: Tiffany Yang <ynaffit@google.com>
Acked-by: Carlos Llamas <cmllamas@google.com>
Link: https://lore.kernel.org/r/20250714185321.2417234-2-ynaffit@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
LLM Generated explanations, may be completely bogus:
**Backport Status: YES**
This commit fixes a genuine bug in the binder allocator selftest that
causes incorrect page boundary checking. The bug is an off-by-one error
in the page indexing calculation.
**Detailed Analysis:**
1. **Bug Description**: The original code uses `i < end / PAGE_SIZE`
which misses checking the last page when buffers end exactly on a
page boundary. For example:
- If `end = 8192` (exactly 2 pages), `end / PAGE_SIZE = 2`, so the
loop checks pages 0 and 1
- However, when a buffer ends at byte 8192, it actually spans into
the third page (pages 0, 1, and 2)
- The fix `i <= (end - 1) / PAGE_SIZE` correctly calculates the last
page index
2. **Impact**: This bug causes the selftest to skip validation of the
last page for buffers that end on page boundaries, potentially
missing memory allocation issues that the selftest is designed to
catch.
3. **Fix Quality**: The fix is minimal (single line change),
mathematically correct, and focused solely on fixing the indexing bug
without introducing new functionality.
4. **Backport Criteria Met**:
- **Bug fix**: Yes - fixes incorrect test coverage
- **Small and contained**: Yes - single line change in selftest code
- **No architectural changes**: Yes - simple indexing fix
- **Minimal regression risk**: Yes - only affects selftest code, not
production binder functionality
- **Clear benefit**: Yes - ensures proper testing coverage for memory
allocation
5. **Additional Evidence**:
- The commit is acked by Carlos Llamas, a binder maintainer
- The fix is in selftest code, which has lower risk than production
code changes
- The mathematical correction is straightforward and verifiable
This is an ideal candidate for stable backporting as it fixes a testing
gap that could allow memory allocation bugs to go undetected in stable
kernels.
drivers/android/binder_alloc_selftest.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/android/binder_alloc_selftest.c b/drivers/android/binder_alloc_selftest.c
index c88735c54848..486af3ec3c02 100644
--- a/drivers/android/binder_alloc_selftest.c
+++ b/drivers/android/binder_alloc_selftest.c
@@ -142,12 +142,12 @@ static void binder_selftest_free_buf(struct binder_alloc *alloc,
for (i = 0; i < BUFFER_NUM; i++)
binder_alloc_free_buf(alloc, buffers[seq[i]]);
- for (i = 0; i < end / PAGE_SIZE; i++) {
/**
* Error message on a free page can be false positive
* if binder shrinker ran during binder_alloc_free_buf
* calls above.
*/
+ for (i = 0; i <= (end - 1) / PAGE_SIZE; i++) {
if (list_empty(page_to_lru(alloc->pages[i]))) {
pr_err_size_seq(sizes, seq);
pr_err("expect lru but is %s at page index %d\n",
--
2.39.5
next prev parent reply other threads:[~2025-08-04 0:24 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20250804002335.3613254-1-sashal@kernel.org>
2025-08-04 0:22 ` [PATCH AUTOSEL 6.16 09/85] regulator: core: repeat voltage setting request for stepped regulators Sasha Levin
2025-08-04 11:36 ` Mark Brown
2025-08-16 13:09 ` Sasha Levin
2025-08-04 0:22 ` Sasha Levin [this message]
2025-08-04 0:22 ` [PATCH AUTOSEL 6.16 49/85] irqchip/renesas-rzv2h: Enable SKIP_SET_WAKE and MASK_ON_SUSPEND Sasha Levin
2025-08-04 0:22 ` [PATCH AUTOSEL 6.16 50/85] selftests: vDSO: vdso_test_getrandom: Always print TAP header Sasha Levin
2025-08-04 0:23 ` [PATCH AUTOSEL 6.16 56/85] mei: bus: Check for still connected devices in mei_cl_bus_dev_release() Sasha Levin
2025-08-04 0:23 ` [PATCH AUTOSEL 6.16 67/85] irqchip/mips-gic: Allow forced affinity Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250804002335.3613254-18-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=arve@android.com \
--cc=cmllamas@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=joelagnelf@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maco@android.com \
--cc=patches@lists.linux.dev \
--cc=stable@vger.kernel.org \
--cc=surenb@google.com \
--cc=tkjos@android.com \
--cc=ynaffit@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox