From: Thorsten Blum <blum@kernel.org>
To: Geert Uytterhoeven <geert@linux-m68k.org>,
Philip Blundell <philb@gnu.org>,
Joshua Thompson <funaho@jurai.org>,
Daniel Palmer <daniel@thingy.jp>, Sam Creasey <sammy@sammy.net>,
Thorsten Blum <blum@kernel.org>,
Michael Schmitz <schmitzmic@gmail.com>,
Miro Kropacek <miro.kropacek@gmail.com>,
Kuan-Wei Chiu <visitorckw@gmail.com>
Cc: linux-m68k@lists.linux-m68k.org
Subject: [PATCH] m68k: Bound writes in *_get_model() callbacks
Date: Mon, 30 Nov 2026 14:35:54 +0100 [thread overview]
Message-ID: <20261130133611.1442856-2-blum@kernel.org> (raw)
The machine-specific callbacks use unbounded string operations and rely
on the caller to provide a sufficiently large buffer.
Pass the destination buffer size to the callbacks and use snprintf() and
strscpy() to bound the writes.
In mvme16x_get_model(), format the suffix directly and remove the
temporary buffer. In atari_get_model(), select the model name before
formatting. And in bvme6000_get_model(), copy the whole model string.
Signed-off-by: Thorsten Blum <blum@kernel.org>
---
arch/m68k/amiga/config.c | 6 +++---
arch/m68k/apollo/config.c | 12 ++++++-----
arch/m68k/atari/config.c | 36 +++++++++++++--------------------
arch/m68k/bvme6000/config.c | 6 +++---
arch/m68k/hp300/config.c | 4 ++--
arch/m68k/include/asm/machdep.h | 2 +-
arch/m68k/kernel/setup_mm.c | 4 ++--
arch/m68k/mac/config.c | 7 +++----
arch/m68k/mvme147/config.c | 6 +++---
arch/m68k/mvme16x/config.c | 17 ++++++----------
arch/m68k/q40/config.c | 6 +++---
arch/m68k/sun3/idprom.c | 4 ++--
arch/m68k/sun3/sun3.h | 3 ++-
arch/m68k/virt/config.c | 11 +++++-----
14 files changed, 56 insertions(+), 68 deletions(-)
diff --git a/arch/m68k/amiga/config.c b/arch/m68k/amiga/config.c
index 6e89e7f7e98b..e2869bb4bf5e 100644
--- a/arch/m68k/amiga/config.c
+++ b/arch/m68k/amiga/config.c
@@ -94,7 +94,7 @@ static char *amiga_models[] __initdata = {
static char amiga_model_name[13] = "Amiga ";
static void amiga_sched_init(void);
-static void amiga_get_model(char *model);
+static void amiga_get_model(char *model, size_t model_size);
static void amiga_get_hardware_list(struct seq_file *m);
static void amiga_reset(void) __noreturn;
static void amiga_mem_console_write(struct console *co, const char *b,
@@ -771,9 +771,9 @@ static void amiga_heartbeat(int on)
* Amiga specific parts of /proc
*/
-static void amiga_get_model(char *model)
+static void amiga_get_model(char *model, size_t model_size)
{
- strcpy(model, amiga_model_name);
+ strscpy(model, amiga_model_name, model_size);
}
diff --git a/arch/m68k/apollo/config.c b/arch/m68k/apollo/config.c
index e324c5f671de..0f9af1f89c70 100644
--- a/arch/m68k/apollo/config.c
+++ b/arch/m68k/apollo/config.c
@@ -33,7 +33,7 @@ static void dn_dummy_reset(void);
static void dn_heartbeat(int on);
#endif
static irqreturn_t dn_timer_int(int irq,void *);
-static void dn_get_model(char *model);
+static void dn_get_model(char *model, size_t model_size);
static const char *apollo_models[] = {
[APOLLO_DN3000-APOLLO_DN3000] = "DN3000 (Otter)",
[APOLLO_DN3010-APOLLO_DN3000] = "DN3010 (Otter)",
@@ -214,11 +214,13 @@ static void dn_dummy_reset(void)
}
-static void dn_get_model(char *model)
+static void dn_get_model(char *model, size_t model_size)
{
- strcpy(model, "Apollo ");
- if (apollo_model >= APOLLO_DN3000 && apollo_model <= APOLLO_DN4500)
- strcat(model, apollo_models[apollo_model - APOLLO_DN3000]);
+ if (apollo_model >= APOLLO_DN3000 && apollo_model <= APOLLO_DN4500)
+ snprintf(model, model_size, "Apollo %s",
+ apollo_models[apollo_model - APOLLO_DN3000]);
+ else
+ strscpy(model, "Apollo", model_size);
}
#ifdef CONFIG_HEARTBEAT
diff --git a/arch/m68k/atari/config.c b/arch/m68k/atari/config.c
index bdafc86241b7..4a6225e2064f 100644
--- a/arch/m68k/atari/config.c
+++ b/arch/m68k/atari/config.c
@@ -69,7 +69,7 @@ int atari_rtc_year_offset;
/* local function prototypes */
static void atari_reset(void);
-static void atari_get_model(char *model);
+static void atari_get_model(char *model, size_t model_size);
static void atari_get_hardware_list(struct seq_file *m);
#ifdef CONFIG_HEARTBEAT
static void atari_heartbeat(int on);
@@ -565,39 +565,31 @@ static void atari_reset(void)
}
-static void atari_get_model(char *model)
+static void atari_get_model(char *model, size_t model_size)
{
- strcpy(model, "Atari ");
+ const char *name;
+
switch (atari_mch_cookie >> 16) {
case ATARI_MCH_ST:
- if (ATARIHW_PRESENT(MSTE_CLK))
- strcat(model, "Mega ST");
- else
- strcat(model, "ST");
+ name = ATARIHW_PRESENT(MSTE_CLK) ? "Mega ST" : "ST";
break;
case ATARI_MCH_STE:
- if (MACH_IS_MSTE)
- strcat(model, "Mega STE");
- else
- strcat(model, "STE");
+ name = MACH_IS_MSTE ? "Mega STE" : "STE";
break;
case ATARI_MCH_TT:
- if (MACH_IS_MEDUSA)
- /* Medusa has TT _MCH cookie */
- strcat(model, "Medusa");
- else
- strcat(model, "TT");
+ /* Medusa has TT _MCH cookie */
+ name = MACH_IS_MEDUSA ? "Medusa" : "TT";
break;
case ATARI_MCH_FALCON:
- strcat(model, "Falcon");
- if (MACH_IS_AB40)
- strcat(model, " (with Afterburner040)");
+ name = MACH_IS_AB40 ? "Falcon (with Afterburner040)" : "Falcon";
break;
default:
- sprintf(model + strlen(model), "(unknown mach cookie 0x%lx)",
- atari_mch_cookie);
- break;
+ snprintf(model, model_size, "Atari (unknown mach cookie 0x%lx)",
+ atari_mch_cookie);
+ return;
}
+
+ snprintf(model, model_size, "Atari %s", name);
}
diff --git a/arch/m68k/bvme6000/config.c b/arch/m68k/bvme6000/config.c
index 8a2ee69a09f6..d5f91006741d 100644
--- a/arch/m68k/bvme6000/config.c
+++ b/arch/m68k/bvme6000/config.c
@@ -34,7 +34,7 @@
#include <asm/bvme6000hw.h>
#include <asm/config.h>
-static void bvme6000_get_model(char *model);
+static void bvme6000_get_model(char *model, size_t model_size);
extern void bvme6000_sched_init(void);
extern int bvme6000_hwclk (int, struct rtc_time *);
extern void bvme6000_reset (void);
@@ -65,9 +65,9 @@ void bvme6000_reset(void)
;
}
-static void bvme6000_get_model(char *model)
+static void bvme6000_get_model(char *model, size_t model_size)
{
- sprintf(model, "BVME%d000", m68k_cputype == CPU_68060 ? 6 : 4);
+ strscpy(model, m68k_cputype == CPU_68060 ? "BVME6000" : "BVME4000", model_size);
}
/*
diff --git a/arch/m68k/hp300/config.c b/arch/m68k/hp300/config.c
index 1a2739852351..370b28b47708 100644
--- a/arch/m68k/hp300/config.c
+++ b/arch/m68k/hp300/config.c
@@ -104,9 +104,9 @@ static void hp300_pulse(int x)
}
#endif
-static void hp300_get_model(char *model)
+static void hp300_get_model(char *model, size_t model_size)
{
- strcpy(model, hp300_model_name);
+ strscpy(model, hp300_model_name, model_size);
}
#define RTCBASE 0xf0420000
diff --git a/arch/m68k/include/asm/machdep.h b/arch/m68k/include/asm/machdep.h
index 48d27f1fecc7..f33b31d1ed15 100644
--- a/arch/m68k/include/asm/machdep.h
+++ b/arch/m68k/include/asm/machdep.h
@@ -15,7 +15,7 @@ struct buffer_head;
extern void (*mach_sched_init) (void);
/* machine dependent irq functions */
extern void (*mach_init_IRQ) (void);
-extern void (*mach_get_model) (char *model);
+extern void (*mach_get_model)(char *model, size_t model_size);
extern void (*mach_get_hardware_list) (struct seq_file *m);
/* machine dependent timer functions */
extern int (*mach_hwclk)(int, struct rtc_time*);
diff --git a/arch/m68k/kernel/setup_mm.c b/arch/m68k/kernel/setup_mm.c
index c7e8de0d34bb..aea17e202a57 100644
--- a/arch/m68k/kernel/setup_mm.c
+++ b/arch/m68k/kernel/setup_mm.c
@@ -87,7 +87,7 @@ static char m68k_command_line[CL_SIZE] __initdata;
void (*mach_sched_init) (void) __initdata = NULL;
/* machine dependent irq functions */
void (*mach_init_IRQ) (void) __initdata = NULL;
-void (*mach_get_model) (char *model);
+void (*mach_get_model)(char *model, size_t model_size);
void (*mach_get_hardware_list) (struct seq_file *m);
void (*mach_reset)( void );
void (*mach_halt)( void );
@@ -482,7 +482,7 @@ static int hardware_proc_show(struct seq_file *m, void *v)
int i;
if (mach_get_model)
- mach_get_model(model);
+ mach_get_model(model, sizeof(model));
else
strscpy(model, "Unknown m68k");
diff --git a/arch/m68k/mac/config.c b/arch/m68k/mac/config.c
index b745cf20a71f..de51025cbd05 100644
--- a/arch/m68k/mac/config.c
+++ b/arch/m68k/mac/config.c
@@ -56,7 +56,7 @@ struct mac_booter_data mac_bi_data;
/* The phys. video addr. - might be bogus on some machines */
static unsigned long mac_orig_videoaddr;
-static void mac_get_model(char *str);
+static void mac_get_model(char *str, size_t str_size);
static void mac_identify(void);
static void mac_report_hardware(void);
@@ -864,10 +864,9 @@ static void __init mac_report_hardware(void)
pr_info("Apple Macintosh %s\n", macintosh_config->name);
}
-static void mac_get_model(char *str)
+static void mac_get_model(char *str, size_t str_size)
{
- strcpy(str, "Macintosh ");
- strcat(str, macintosh_config->name);
+ snprintf(str, str_size, "Macintosh %s", macintosh_config->name);
}
static const struct resource mac_scsi_iifx_rsrc[] __initconst = {
diff --git a/arch/m68k/mvme147/config.c b/arch/m68k/mvme147/config.c
index 3054d3857efa..894bd86ae723 100644
--- a/arch/m68k/mvme147/config.c
+++ b/arch/m68k/mvme147/config.c
@@ -35,7 +35,7 @@
#include "mvme147.h"
-static void mvme147_get_model(char *model);
+static void mvme147_get_model(char *model, size_t model_size);
static void __init mvme147_sched_init(void);
extern void mvme147_reset (void);
@@ -58,9 +58,9 @@ void mvme147_reset(void)
;
}
-static void mvme147_get_model(char *model)
+static void mvme147_get_model(char *model, size_t model_size)
{
- sprintf(model, "Motorola MVME147");
+ strscpy(model, "Motorola MVME147", model_size);
}
/*
diff --git a/arch/m68k/mvme16x/config.c b/arch/m68k/mvme16x/config.c
index 99768fe8da73..d294550992ac 100644
--- a/arch/m68k/mvme16x/config.c
+++ b/arch/m68k/mvme16x/config.c
@@ -40,7 +40,7 @@
extern t_bdid mvme_bdid;
-static void mvme16x_get_model(char *model);
+static void mvme16x_get_model(char *model, size_t model_size);
extern void mvme16x_sched_init(void);
extern void mvme16x_reset (void);
@@ -66,17 +66,12 @@ void mvme16x_reset(void)
*(volatile char *)0xfff40107 = 0x80;
}
-static void mvme16x_get_model(char *model)
+static void mvme16x_get_model(char *model, size_t model_size)
{
- p_bdid p = &mvme_bdid;
- char suf[4];
-
- suf[1] = p->brdsuffix[0];
- suf[2] = p->brdsuffix[1];
- suf[3] = '\0';
- suf[0] = suf[1] ? '-' : '\0';
+ p_bdid p = &mvme_bdid;
- sprintf(model, "Motorola MVME%x%s", be16_to_cpu(p->brdno), suf);
+ snprintf(model, model_size, "Motorola MVME%x%s%.2s",
+ be16_to_cpu(p->brdno), *p->brdsuffix ? "-" : "", p->brdsuffix);
}
@@ -279,7 +274,7 @@ void __init config_mvme16x(void)
if (vme_brdtype == 0)
vme_brdtype = brdno;
- mvme16x_get_model(id);
+ mvme16x_get_model(id, sizeof(id));
pr_info("BRD_ID: %s BUG %x.%x %02x/%02x/%02x\n", id, p->rev >> 4,
p->rev & 0xf, p->yr, p->mth, p->day);
if (brdno == 0x0162 || brdno == 0x172)
diff --git a/arch/m68k/q40/config.c b/arch/m68k/q40/config.c
index ed59a742baae..d69f96f660f2 100644
--- a/arch/m68k/q40/config.c
+++ b/arch/m68k/q40/config.c
@@ -33,7 +33,7 @@
#include "q40.h"
-static void q40_get_model(char *model);
+static void q40_get_model(char *model, size_t model_size);
static int q40_hwclk(int, struct rtc_time *);
static int q40_get_rtc_pll(struct rtc_pll_info *pll);
@@ -119,9 +119,9 @@ static void q40_halt(void)
;
}
-static void q40_get_model(char *model)
+static void q40_get_model(char *model, size_t model_size)
{
- sprintf(model, "Q40");
+ strscpy(model, "Q40", model_size);
}
static unsigned int serports[] =
diff --git a/arch/m68k/sun3/idprom.c b/arch/m68k/sun3/idprom.c
index ca633a5f5eb1..4ab7f9658cee 100644
--- a/arch/m68k/sun3/idprom.c
+++ b/arch/m68k/sun3/idprom.c
@@ -85,13 +85,13 @@ static void __init display_system_type(unsigned char machtype)
prom_halt();
}
-void sun3_get_model(char *model)
+void sun3_get_model(char *model, size_t model_size)
{
register int i;
for (i = 0; i < NUM_SUN_MACHINES; i++) {
if(Sun_Machines[i].id_machtype == idprom->id_machtype) {
- strcpy(model, Sun_Machines[i].name);
+ strscpy(model, Sun_Machines[i].name, model_size);
return;
}
}
diff --git a/arch/m68k/sun3/sun3.h b/arch/m68k/sun3/sun3.h
index 8d98c0aaedc0..82de0edd62b3 100644
--- a/arch/m68k/sun3/sun3.h
+++ b/arch/m68k/sun3/sun3.h
@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0 */
#include <linux/linkage.h>
+#include <linux/types.h>
struct rtc_time;
@@ -8,7 +9,7 @@ struct rtc_time;
asmlinkage void sun3_init(void);
/* idprom.c */
-void sun3_get_model(char *model);
+void sun3_get_model(char *model, size_t model_size);
/* intersil.c */
int sun3_hwclk(int set, struct rtc_time *t);
diff --git a/arch/m68k/virt/config.c b/arch/m68k/virt/config.c
index b338e2a8da6a..a77562d20f3a 100644
--- a/arch/m68k/virt/config.c
+++ b/arch/m68k/virt/config.c
@@ -13,13 +13,12 @@
struct virt_booter_data virt_bi_data;
-static void virt_get_model(char *str)
+static void virt_get_model(char *str, size_t str_size)
{
- /* str is 80 characters long */
- sprintf(str, "QEMU Virtual M68K Machine (%u.%u.%u)",
- (u8)(virt_bi_data.qemu_version >> 24),
- (u8)(virt_bi_data.qemu_version >> 16),
- (u8)(virt_bi_data.qemu_version >> 8));
+ snprintf(str, str_size, "QEMU Virtual M68K Machine (%u.%u.%u)",
+ (u8)(virt_bi_data.qemu_version >> 24),
+ (u8)(virt_bi_data.qemu_version >> 16),
+ (u8)(virt_bi_data.qemu_version >> 8));
}
static void virt_reset(void)
{
next reply other threads:[~2026-11-30 13:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 13:35 Thorsten Blum [this message]
2026-11-30 13:41 ` [PATCH] m68k: Bound writes in *_get_model() callbacks Thorsten Blum
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=20261130133611.1442856-2-blum@kernel.org \
--to=blum@kernel.org \
--cc=daniel@thingy.jp \
--cc=funaho@jurai.org \
--cc=geert@linux-m68k.org \
--cc=linux-m68k@lists.linux-m68k.org \
--cc=miro.kropacek@gmail.com \
--cc=philb@gnu.org \
--cc=sammy@sammy.net \
--cc=schmitzmic@gmail.com \
--cc=visitorckw@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.