x86/tsc: Fix early boot crash with bare tsc_early_khz parameter
PATCH 1/1 x86/tsc: Fix early boot crash with bare tsc_early_khz parameter
When a bare tsc_early_khz parameter is specified on the kernel command line without the '=' separator, early parameter parsing passes NULL to tsc_early_khz_setup(), which dereferences it in kstrtouint() and can crash the system during early boot.
Reject a NULL argument in tsc_early_khz_setup() by returning -EINVAL so early parameter parsing reports the malformed option instead.
--- arch/x86/kernel/tsc.c | 3 +++ 1 file changed, 3 insertions(+)
arch/x86/kernel/tsc.c +3 -0
@@ -70,6 +70,9 @@ static DEFINE_PER_CPU_ALIGNED(struct cyc2ns, cyc2ns);static int __init tsc_early_khz_setup (char *buf) { +if (!buf) +return -EINVAL ; +return kstrtouint (buf,0 , &tsc_early_khz); }early_param ("tsc_early_khz" , tsc_early_khz_setup);
arch/x86/kernel/tsc.c static DEFINE_PER_CPU_ALIGNED(struct cyc2ns, cyc2ns); · line 77
Quoted 7 lines · Thorsten Blum
static int
__inittsc_early_khz_setup(char *buf)
{arch/x86/kernel/tsc.c +3
-0+if (!buf) +return -EINVAL ; +return kstrtouint (buf,0 , &tsc_early_khz); }
This _seems_ like the kind of thing that should ideally just be done in kstrtouint().
Is there a reason we can't just do what kstrtobool() does when handed buf=NULL?
Quoted 12 lines · Dave Hansen
arch/x86/kernel/tsc.c static DEFINE_PER_CPU_ALIGNED(struct cyc2ns, cyc2ns); · line 77
Quoted 7 lines · Thorsten Blum
static int
__inittsc_early_khz_setup(char *buf)
{arch/x86/kernel/tsc.c +3
-0+if (!buf) +return -EINVAL ; +return kstrtouint (buf,0 , &tsc_early_khz); }This _seems_ like the kind of thing that should ideally just be done in
kstrtouint().
Quoted 2 lines
Is there a reason we can't just do what
kstrtobool()does when handed buf=NULL?
I don't see a technical reason why we couldn't, but that would potentially change the behavior of every kstrto*() caller and be a broader change than this fix.
Here NULL is expected (for params without the '=' separator), so I kept the check local to match other early_param handlers that use kstrto*(), e.g., set_corruption_check(), set_corruption_check_period(), and parse_mtrr_spare_reg().