From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Suchit Karunakaran <suchitkarunakaran@gmail.com>,
Nicolas Schier <nicolas.schier@linux.dev>,
Masahiro Yamada <masahiroy@kernel.org>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH AUTOSEL 6.16-5.4] kconfig: lxdialog: replace strcpy() with strncpy() in inputbox.c
Date: Sat, 9 Aug 2025 20:21:00 -0400 [thread overview]
Message-ID: <20250810002104.1545396-11-sashal@kernel.org> (raw)
In-Reply-To: <20250810002104.1545396-1-sashal@kernel.org>
From: Suchit Karunakaran <suchitkarunakaran@gmail.com>
[ Upstream commit 5ac726653a1029a2eccba93bbe59e01fc9725828 ]
strcpy() performs no bounds checking and can lead to buffer overflows if
the input string exceeds the destination buffer size. This patch replaces
it with strncpy(), and null terminates the input string.
Signed-off-by: Suchit Karunakaran <suchitkarunakaran@gmail.com>
Reviewed-by: Nicolas Schier <nicolas.schier@linux.dev>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
LLM Generated explanations, may be completely bogus:
Based on my analysis of the commit and the code context I was able to
examine, here's my assessment:
**Backport Status: YES**
## Extensive Explanation:
This commit should be backported to stable kernel trees for the
following reasons:
### 1. **Security Bug Fix**
The commit fixes a potential buffer overflow vulnerability in the
kconfig lxdialog inputbox code. Looking at the code changes:
- The original code uses `strcpy(instr, init)` at line 43 without any
bounds checking
- `instr` points to `dialog_input_result` which is defined as `char
dialog_input_result[MAX_LEN + 1]` (line 11)
- From dialog.h, `MAX_LEN` is defined as 2048 (line 25)
- If `init` string exceeds 2048 characters, it would overflow the buffer
### 2. **Simple and Contained Fix**
The fix is minimal and straightforward:
```c
- else
- strcpy(instr, init);
+ else {
+ strncpy(instr, init, sizeof(dialog_input_result) - 1);
+ instr[sizeof(dialog_input_result) - 1] = '\0';
+ }
```
- Replaces unsafe `strcpy()` with bounded `strncpy()`
- Properly null-terminates the string to prevent unterminated string
issues
- Uses `sizeof(dialog_input_result) - 1` to ensure proper bounds
### 3. **Low Risk of Regression**
- The change is localized to a single function in the kconfig tool
- It doesn't alter the logic flow, only makes the string copy safer
- The kconfig lxdialog is used during kernel configuration, not runtime
kernel code
- The fix maintains the same functionality while adding safety
### 4. **Meets Stable Criteria**
According to stable kernel rules, this commit qualifies because it:
- Fixes a real bug (buffer overflow vulnerability)
- Is obviously correct and tested (has review from Nicolas Schier)
- Is small (only 4 lines changed)
- Doesn't add new features or change architecture
- Has no functional side effects beyond the security fix
### 5. **Potential Security Impact**
While this is in the build tools rather than runtime kernel code, buffer
overflows in build tools can still be exploited:
- Could be triggered by malicious Kconfig files
- Could affect kernel developers or automated build systems
- Even build-time vulnerabilities should be fixed in stable trees
The commit is a textbook example of a security fix that should be
backported - it's small, focused, fixes a clear vulnerability, and has
minimal risk of causing regressions.
scripts/kconfig/lxdialog/inputbox.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/scripts/kconfig/lxdialog/inputbox.c b/scripts/kconfig/lxdialog/inputbox.c
index 3c6e24b20f5b..5e4a131724f2 100644
--- a/scripts/kconfig/lxdialog/inputbox.c
+++ b/scripts/kconfig/lxdialog/inputbox.c
@@ -39,8 +39,10 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width
if (!init)
instr[0] = '\0';
- else
- strcpy(instr, init);
+ else {
+ strncpy(instr, init, sizeof(dialog_input_result) - 1);
+ instr[sizeof(dialog_input_result) - 1] = '\0';
+ }
do_resize:
if (getmaxy(stdscr) <= (height - INPUTBOX_HEIGHT_MIN))
--
2.39.5
next prev parent reply other threads:[~2025-08-10 0:21 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-10 0:20 [PATCH AUTOSEL 6.16-5.4] kconfig: gconf: avoid hardcoding model2 in on_treeview2_cursor_changed() Sasha Levin
2025-08-10 0:20 ` [PATCH AUTOSEL 6.16-6.15] kheaders: rebuild kheaders_data.tar.xz when a file is modified within a minute Sasha Levin
2025-08-10 0:20 ` [PATCH AUTOSEL 6.16-5.4] kconfig: lxdialog: fix 'space' to (de)select options Sasha Levin
2025-08-10 0:20 ` [PATCH AUTOSEL 6.16-5.4] scsi: aacraid: Stop using PCI_IRQ_AFFINITY Sasha Levin
2025-08-10 0:20 ` [PATCH AUTOSEL 6.16-5.4] kconfig: gconf: fix potential memory leak in renderer_edited() Sasha Levin
2025-08-10 0:20 ` [PATCH AUTOSEL 6.16-5.15] scsi: target: core: Generate correct identifiers for PR OUT transport IDs Sasha Levin
2025-08-10 0:20 ` [PATCH AUTOSEL 6.16-5.4] ipmi: Fix strcpy source and destination the same Sasha Levin
2025-08-10 0:20 ` [PATCH AUTOSEL 6.16-5.4] scsi: Fix sas_user_scan() to handle wildcard and multi-channel scans Sasha Levin
2025-08-10 0:20 ` [PATCH AUTOSEL 6.16-6.1] vfio/mlx5: fix possible overflow in tracking max message size Sasha Levin
2025-08-10 0:20 ` [PATCH AUTOSEL 6.16-5.4] kconfig: nconf: Ensure null termination where strncpy is used Sasha Levin
2025-08-10 0:21 ` Sasha Levin [this message]
2025-08-10 0:21 ` [PATCH AUTOSEL 6.16-5.15] vfio/type1: conditional rescheduling while pinning Sasha Levin
2025-08-10 0:21 ` [PATCH AUTOSEL 6.16-5.4] ipmi: Use dev_warn_ratelimited() for incorrect message warnings 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=20250810002104.1545396-11-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=masahiroy@kernel.org \
--cc=nicolas.schier@linux.dev \
--cc=patches@lists.linux.dev \
--cc=stable@vger.kernel.org \
--cc=suchitkarunakaran@gmail.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