m68k: Bound writes in *_get_model() callbacks
Subsystems (5)
PATCH 1/1 m68k: Bound writes in *_get_model() callbacks
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.
--- 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(-)
arch/m68k/amiga/config.c +3 -3
@@ -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); }
arch/m68k/apollo/config.c +7 -5
@@ -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
arch/m68k/atari/config.c +14 -22
@@ -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); }
arch/m68k/bvme6000/config.c +3 -3
@@ -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); }/*
arch/m68k/hp300/config.c +2 -2
@@ -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
arch/m68k/include/asm/machdep.h +1 -1
@@ -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 *);
arch/m68k/kernel/setup_mm.c +2 -2
@@ -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" );
arch/m68k/mac/config.c +3 -4
@@ -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 = {
arch/m68k/mvme147/config.c +3 -3
@@ -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); }/*
arch/m68k/mvme16x/config.c +6 -11
@@ -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 )
arch/m68k/q40/config.c +3 -3
@@ -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[] =
arch/m68k/sun3/idprom.c +2 -2
@@ -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) { registerint 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 ; } }
arch/m68k/sun3/sun3.h +2 -1
@@ -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);
arch/m68k/virt/config.c +5 -6
@@ -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 ) {
Compile-tested only using {multi,virt,sun3}_defconfig.
Quoted 410 lines · Thorsten Blum
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()andstrscpy()to bound the writes.In
mvme16x_get_model(), format the suffix directly and remove the temporary buffer. Inatari_get_model(), select the model name before formatting. And inbvme6000_get_model(), copy the whole model string.Signed-off-by Thorsten Blum <[email protected]>--- 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(-)arch/m68k/amiga/config.c +3
-3@@ -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); }arch/m68k/apollo/config.c +7
-5@@ -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 arch/m68k/atari/config.c +14
-22@@ -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); }arch/m68k/bvme6000/config.c +3
-3@@ -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); }/* arch/m68k/hp300/config.c +2
-2@@ -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 0xf0420000arch/m68k/include/asm/machdep.h +1
-1@@ -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 *);arch/m68k/kernel/setup_mm.c +2
-2@@ -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" );arch/m68k/mac/config.c +3
-4@@ -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 = {arch/m68k/mvme147/config.c +3
-3@@ -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); }/* arch/m68k/mvme16x/config.c +6
-11@@ -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 )arch/m68k/q40/config.c +3
-3@@ -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[] =arch/m68k/sun3/idprom.c +2
-2@@ -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) { registerint 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 ; } }arch/m68k/sun3/sun3.h +2
-1@@ -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);arch/m68k/virt/config.c +5
-6@@ -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 ) {
Hi Thorsten,
Quoted 3 lines · Thorsten Blum
The machine-specific callbacks use unbounded string operations and rely on the caller to provide a sufficiently large buffer.
I guess this is to just clean up unsafe string function usage. I build/boot tested on Amiga 4000 and MVME147.
Quoted 9 lines · Daniel Palmer
Hi Thorsten,
Quoted 3 lines · Thorsten Blum
The machine-specific callbacks use unbounded string operations and rely on the caller to provide a sufficiently large buffer.
I guess this is to just clean up unsafe string function usage. I build/boot tested on Amiga 4000 and MVME147.
Yes, I should have added "No functional change".
Quoted 1 line
Thanks.
Quoted 11 lines · Thorsten Blum
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()andstrscpy()to bound the writes.In
mvme16x_get_model(), format the suffix directly and remove the temporary buffer. Inatari_get_model(), select the model name before formatting. And inbvme6000_get_model(), copy the whole model string.Signed-off-by Thorsten Blum <[email protected]>
i.e. will queue in the m68k tree for v7.5.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds