From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=172.234.252.31 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796045812; b=P4mLq9Jrd7vqjksKsedknlzQYTaykAcpksMd18IvAnvlfoVEyr5/7SqClP1kfNDGinDe 6MT4E9RxI13CWZi5gVJN5yXYJ/Tc7XjzHIKNCnTp87RwrReBB7yuQ9c3WeDZct/pvP5U5 IiAmG9Tt7lNmGLMizqKR6j1BVq9Pyt+BRJU8ypZoD7hw9AUdhGUAGokBA6QmxeCGZ+G6A dJvTKvXgaf7pdtosDfFJsuohRBUjYO7TXF5WF6wZFCtdHfIarOUvthkKZ53sQwEercMt+ syri0ZiROGi6RRGJd+MI3NTgqbu3d+ddiDBmQ5q5PxvRzdXkjIzzX2Fw2L6nJYeijbA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796045812; h=DMARC-Filter:Received:Received:DKIM-Signature:From:To:Cc:Subject: Date:Message-ID:X-Mailer:MIME-Version:X-Developer-Signature: X-Developer-Key:Content-Transfer-Encoding; bh=YqkLkvEHS/KwtEktfDkZlIt5cKTYolYmveJdFlpirAc=; b=aoBsczI7JhkqUJcVHqIJNAtyuy9gRlYlDiJ60RF9CY7A5LjqTqsxL5qTjt2Hx+GKnjJm 8pUfetyvduM/OPwFaddXwdSSoCy6cgR2VHm6PaTq5WTDUfEYyjTSneUW5KgWsK4REGMjc Pfe3CwxzSmbjtSbNW6EePmM6L9qLS09+/2+zNyHaPlUitrbEguDtDJmRlJqSMCx7dchxt /e2qzvmdGLInq16uAh/lO3ehOVxMYGPP96q7U5nALtIUmRUB4d+EovY5HaT55+qcCFLzR dulc0wQKfbghCN5dWGy+gAM0zrmOwQybzR15a1tYDv949JqpBnmvNVjJDNz7MJs15kw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=kernel.org; spf=pass smtp.mailfrom=kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=I64q1tgs; arc=none smtp.remote-ip=172.234.252.31 Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 721A0606A325 for ; Mon, 30 Nov 2026 13:36:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 721A0606A325 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=I64q1tgs Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id D35FB4035A; Mon, 30 Nov 2026 13:36:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C4001F0092A; Mon, 30 Nov 2026 13:36:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796045810; bh=YqkLkvEHS/KwtEktfDkZlIt5cKTYolYmveJdFlpirAc=; h=From:To:Cc:Subject:Date; b=I64q1tgsZ9ga1vPuY8posqL7AwD5HSHmyth239OFTvHJ6pL0rG+SO8V8Npat0paUC lEamj7mNyzvTW2e0qEO2AFuGmBGyD9L9K2ByhFWahe4HSy06JU7z2w9vliUgLKA6lm 1SmTQnlQgwloGiCmaSas+stiVB6+NOEtSo/DJNTGlmZR/oSyTYNjjUBg9xxqyItybu flgzYVrtp3hSA1WwuY8Ni+8cDTgt2QFBtBmJuljtk0VaS5V/mfZCI/hhgFU5j6fC31 Yb842lKNdHbsD5iK41HdOkuQKvK4j7EyNemyUPu6iLkAu8Rv3/7BriqLMcr7zeHTXW +H8uc3dvzQgOQ== From: Thorsten Blum To: Geert Uytterhoeven , Philip Blundell , Joshua Thompson , Daniel Palmer , Sam Creasey , Thorsten Blum , Michael Schmitz , Miro Kropacek , Kuan-Wei Chiu 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 Message-ID: <20261130133611.1442856-2-blum@kernel.org> X-Mailer: git-send-email 2.56.1 X-Mailing-List: linux-m68k@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=13647; i=blum@kernel.org; h=from:subject; bh=LVCx546LvlS6hqgUtFDS+ubsuvMR4lhEitAdQkYFUTE=; b=owGbwMvMwCUWt7pQ4caZUj3G02pJDNm81aeX2sWf38y3eMvRxdHzWpnybauTnlzWfX3n9MlGl hfuk2bpdpSyMIhxMciKKbI8mPVjhm9pTeUmk4idMHNYmUCGMHBxCsBErEMZGZa96Eq+an48d0Jo 0pO9fCeupvvv25QpLLFPqy77l1Z1XTEjw6uHmptXm5Xnhq1/b5n+b/qZM5Z9sfklEdGzknXuWnQ cYQMA X-Developer-Key: i=blum@kernel.org; a=openpgp; fpr=1D60735E8AEF3BE473B69D84733678FD8DFEEAD4 Content-Transfer-Encoding: 8bit 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 --- 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 #include -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 +#include 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) {