patches.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Jocelyn Falempe <jfalempe@redhat.com>,
	Javier Martinez Canillas <javierm@redhat.com>,
	Sasha Levin <sashal@kernel.org>,
	maarten.lankhorst@linux.intel.com, mripard@kernel.org,
	tzimmermann@suse.de, dri-devel@lists.freedesktop.org
Subject: [PATCH AUTOSEL 6.17-6.12] drm/panic: Fix divide by 0 if the screen width < font width
Date: Tue, 28 Oct 2025 08:48:09 -0400	[thread overview]
Message-ID: <20251028124815.1058740-9-sashal@kernel.org> (raw)
In-Reply-To: <20251028124815.1058740-1-sashal@kernel.org>

From: Jocelyn Falempe <jfalempe@redhat.com>

[ Upstream commit 2e337dd278c6c38982b520c309f36e0f88696e6e ]

In the unlikely case that the screen is tiny, and smaller than the
font width, it leads to a divide by 0:

draw_line_with_wrap()
chars_per_row = sb->width / font->width = 0
line_wrap.len = line->len % chars_per_row;

This will trigger a divide by 0

Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Link: https://lore.kernel.org/r/20251009122955.562888-6-jfalempe@redhat.com
Signed-off-by: Jocelyn Falempe <jfalempe@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---

LLM Generated explanations, may be completely bogus:

Based on my comprehensive analysis of the Linux kernel repository using
multiple tools, here is my assessment:

## **Backport Status: YES**

### Analysis Summary

I used the following tools and methods to analyze this commit:
1. **git log/show**: To examine commit history, dates, and affected
   versions
2. **Read tool**: To examine the actual code and understand the bug
   context
3. **Grep tool**: To trace function calls and usage patterns
4. **git tag analysis**: To determine version impact (v6.11 through
   v6.17 affected)

### Detailed Findings

#### 1. **Bug Severity - HIGH PRIORITY**
- **Type**: Divide-by-zero crash in kernel panic handler
- **Location**: `drivers/gpu/drm/drm_panic.c:479` and `484`
- **Call chain discovered**:
  - `drm_panic()` (panic callback) →
  - `draw_panic_plane()` →
  - `draw_panic_dispatch()` →
  - `draw_panic_static_kmsg()` →
  - `draw_line_with_wrap()` (where crash occurs at lines 479 and 484)

**Critical Impact**: When a kernel panic occurs, the system attempts to
display panic information on screen. If `sb->width < font->width`, then
`chars_per_row = sb->width / font->width = 0`, leading to `line_wrap.len
= line->len % 0` which triggers a divide-by-zero exception **during
panic handling**. This prevents users from seeing any panic information.

#### 2. **Scope Analysis - SMALL AND CONTAINED**
- **Files changed**: 1 file (`drivers/gpu/drm/drm_panic.c`)
- **Lines changed**: 1 line (adding condition `|| font->width >
  sb->width`)
- **Change type**: Defensive check only, no behavioral changes to normal
  path
- **Fix location**: Line 523, adding early return condition

#### 3. **Version Impact - SIGNIFICANT RANGE**
- **Introduced in**: v6.11 (commit `54034bebb22fd`, June 2024 -
  "drm/panic: Add a kmsg panic screen")
- **Affected versions**: v6.11, v6.12, v6.13, v6.14, v6.15, v6.16, v6.17
- **Fixed in**: v6.18-rc3 (October 2025)
- **Backport target**: All stable trees from v6.11 onwards

#### 4. **Risk Assessment - MINIMAL**
- **Risk of regression**: Very low - only adds a safety check
- **Side effects**: None - function returns early if condition met
- **Testing**: The fix prevents a crash path; no valid use case affected
- **Font width range**: 4-16 pixels (from my analysis of `lib/fonts/`)
- **Trigger condition**: Screen width < 4 pixels (extremely rare but
  possible with embedded/weird displays)

#### 5. **Subsystem Context - MATURING FEATURE**
My analysis revealed:
- **drm/panic introduced**: v6.10 (April 2024) - relatively new
  subsystem
- **Bug count**: Found 23 "drm/panic: Fix" commits since June 2024
- **Pattern**: This is part of ongoing stabilization of a new feature
- **Similar fixes**: Multiple other drawing/bounds checking fixes in
  same timeframe

#### 6. **Stable Tree Compliance - MEETS ALL CRITERIA**
✅ **Fixes a real bug**: Divide-by-zero crash
✅ **Small change**: 1-line modification
✅ **Low regression risk**: Only adds defensive check
✅ **No new features**: Pure bug fix
✅ **No architectural changes**: Localized to one function
✅ **Already reviewed**: Has Reviewed-by tag from Javier Martinez
Canillas
❌ **Missing stable tag**: No "Cc: stable@vger.kernel.org" (but this
doesn't disqualify it)

### Code-Specific Analysis

**Original vulnerable code** (line 479):
```c
int chars_per_row = sb->width / font->width;  // Can be 0!
```

**Crash trigger** (line 484):
```c
line_wrap.len = line->len % chars_per_row;  // Divide by 0 if
chars_per_row == 0
```

**Fix applied** (line 523):
```c
- if (!font)
+       if (!font || font->width > sb->width)
                return;
```

This simple check prevents entering the drawing code path when the
screen is too narrow, avoiding the divide-by-zero entirely.

### Recommendation Rationale

Despite the "unlikely" scenario mentioned in the commit message, this
should be backported because:

1. **Critical code path**: Occurs during panic handling when system
   stability is already compromised
2. **Clean fix**: Minimal, obvious, and safe change
3. **Subsystem maturity**: drm/panic is new and actively being
   stabilized with multiple fixes
4. **No downsides**: Zero risk of breaking working configurations
5. **Completeness**: Part of a series of drawing boundary fixes that
   should all be backported together

The commit follows the stable kernel rule: "It must fix a real bug that
bothers people" - while rare, a crash during panic display is a serious
issue that prevents debugging.

### Similar Commits for Reference
Other drm/panic fixes from same timeframe that should also be
considered:
- `a119caf6af5ed`: "Fix 24bit pixel crossing page boundaries"
- `16ded1e690422`: "Fix drawing the logo on a small narrow screen"
- `e9b36fe063004`: "Fix kmsg text drawing rectangle"

**CONCLUSION**: This commit should be backported to all stable trees
containing the drm/panic kmsg screen feature (v6.11+).

 drivers/gpu/drm/drm_panic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_panic.c b/drivers/gpu/drm/drm_panic.c
index ea6a64e5ddd76..4c994656ea1ab 100644
--- a/drivers/gpu/drm/drm_panic.c
+++ b/drivers/gpu/drm/drm_panic.c
@@ -520,7 +520,7 @@ static void draw_panic_static_kmsg(struct drm_scanout_buffer *sb)
 	struct drm_panic_line line;
 	int yoffset;
 
-	if (!font)
+	if (!font || font->width > sb->width)
 		return;
 
 	yoffset = sb->height - font->height - (sb->height % font->height) / 2;
-- 
2.51.0


      parent reply	other threads:[~2025-10-28 12:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-28 12:48 [PATCH AUTOSEL 6.17-6.1] spi: intel-pci: Add support for Intel Wildcat Lake SPI serial flash Sasha Levin
2025-10-28 12:48 ` [PATCH AUTOSEL 6.17] erofs: consolidate z_erofs_extent_lookback() Sasha Levin
2025-10-28 12:48 ` [PATCH AUTOSEL 6.17-6.12] drm/panic: Fix overlap between qr code and logo Sasha Levin
2025-10-28 12:48 ` [PATCH AUTOSEL 6.17-6.1] net: datagram: introduce datagram_poll_queue for custom receive queues Sasha Levin
2025-10-28 12:48 ` [PATCH AUTOSEL 6.17-5.4] of/irq: Fix OF node refcount in of_msi_get_domain() Sasha Levin
2025-10-28 12:48 ` [PATCH AUTOSEL 6.17-6.1] riscv: mm: Define MAX_POSSIBLE_PHYSMEM_BITS for zsmalloc Sasha Levin
2025-10-28 12:48 ` [PATCH AUTOSEL 6.17-6.6] firmware: arm_scmi: Skip RAW initialization on failure Sasha Levin
2025-10-28 12:48 ` [PATCH AUTOSEL 6.17-6.1] spi: intel-pci: Add support for Arrow Lake-H SPI serial flash Sasha Levin
2025-10-28 12:48 ` Sasha Levin [this message]

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=20251028124815.1058740-9-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=javierm@redhat.com \
    --cc=jfalempe@redhat.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=patches@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=tzimmermann@suse.de \
    /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;
as well as URLs for NNTP newsgroup(s).