From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=172.105.4.254 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796046078; b=Sj13fyv//pSkO3dMXbNZ9OK/+L/HOzjVCzmHm7Z0Qf1feS0mOMtU/cfZGT64Q/bxHmlO c21vrrczrQKjKqlwrINKe0GPzj0WiMhItvf7CyLrTQsqSl7KvQVQp/ijeoQS+BTSFFRLH ARbHBxbZjDErvcb9o6P9xgS8PKgdKKW8M1BemuKp7TbYf3BJ/J/DIre68EtFYbiaoy/3R J+w1Zw1MAo/k2F9tAMQap6fSLtXmHKksYWAOoCfjDDHGk258vG/+726ipRFe9VNibfBJG a0JLi/tyHvLTHPiZvByFyGvrcJH1mEE+URPwzwnqy3Ad2HhpdISlKvM449jGFaiaPEA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796046078; h=DMARC-Filter:Received:Received:DKIM-Signature:Date:From:To:Cc: Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; bh=ylUAmm9QTaDVFHRhNXlKxUV7knwd4vw4rik9KRszG5c=; b=0j4YIfNhwoClkfxsqS7Yrnq/FFMUPhX9TPBfMqEH7j4F6pnIMj5ng3jCewKZXuF3GOEz nuQiNu7sdHrMqfMDXLGsMTMM9xGEFkF0di2wbbjYxm7OBKDU8/TmDH76iuiL8/YDoDQQ+ dO2Ct/fu4E7oQmChxgoQ4HlvS+PI4lgHh0woLh5PJMkfhaS2LLU67Ixx3GJ3HvyCW61ym hcchGBcQ17097VLfJYg8FUWtxty9RLWHjPbkorc4eJMlB0OXVyyQ2yHntmTol4mdNUp5T dmhWl5GY2xJoHkL+y3s9Cs976Ma1foa9TVqhg6i7nrdEvIY+R14gfBlfSkqLjV2UDng== 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=nhSJD7qZ; arc=none smtp.remote-ip=172.105.4.254 Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) (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 04D55606A31C for ; Mon, 30 Nov 2026 13:41:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 04D55606A31C 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=nhSJD7qZ Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 7AD7D6205A; Mon, 30 Nov 2026 13:41:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 441B61F00897; Mon, 30 Nov 2026 13:41:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796046075; bh=ylUAmm9QTaDVFHRhNXlKxUV7knwd4vw4rik9KRszG5c=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=nhSJD7qZMaJ3vDQMLmQ+jCQdi4UVuFa2orjucvP68fqPvDWEqzkG687xCzo9hXiU9 /B7qjep9I2i0RFNjcFej/0E0NA1GXgsxK/IdEazzLzsOv2C72fjHm2TtM3Ty1Jqm5o SHaVjV/WZkvhzaeZYshunIhehpolDz9iwXqAuHa3NjIOjRfFIguow4Y7Z//yiFJ+uf t+p9/c91JbX71U0Lo8+0JHDJ8S3YncJ68OAcl7B05ayRN0EbEPvTwbLZzYcjzvHLt0 z4uxrBfei/BkgT/sR0F84VjaPUccqpGwWVkA2SPXU80vIM8EcEyiH1SvzgLH5dFize 9UCDVvKm51x4g== Date: Mon, 30 Nov 2026 14:41:10 +0100 From: Thorsten Blum To: Geert Uytterhoeven , Philip Blundell , Joshua Thompson , Daniel Palmer , Sam Creasey , Michael Schmitz , Miro Kropacek , Kuan-Wei Chiu Cc: linux-m68k@lists.linux-m68k.org Subject: Re: [PATCH] m68k: Bound writes in *_get_model() callbacks Message-ID: References: <20261130133611.1442856-2-blum@kernel.org> 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 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261130133611.1442856-2-blum@kernel.org> Compile-tested only using {multi,virt,sun3}_defconfig. On Mon, Nov 30, 2026 at 02:35:54PM +0100, Thorsten Blum wrote: > 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) > {