[LTP] [PATCH] tst_kconfig: Avoid buffer overflow when parsing /proc/cmdline

Li Wang liwang@redhat.com
Wed Jun 19 12:20:06 CEST 2024


On Wed, Jun 19, 2024 at 3:47 PM Petr Vorel <pvorel@suse.cz> wrote:

> > When the test is run with a kernel booting with many parameters, the
> > buffer size is often not large enough to store the complete command
> > line. This results in a buffer overflow and the test complains with
> > the following message:
>
> >   tst_kconfig.c:609: TWARN: Buffer overflowed while parsing /proc/cmdline
>
> Thanks for the fix!
>
> Reviewed-by: Petr Vorel <pvorel@suse.cz>
> Fixes: 180834982 ("kconfig: add funtion to parse /proc/cmdline")
>
> NOTE tst_kconfig_read() has char line[128], also struct tst_kcmdline_var
> member
>

Typically 128 is long enough for Linux kernel parameters, otherwise it hard
for people to memorize the name and value.



> has this length. The longest line on some on my systems is 109, it's still
> OK,
> hopefully it stays :).
>

Hmm, good point. After thinking it over, seems too hasty to enlarge the
buf[] size to 512.

We'd better keep the size same between 'tst_kcmdline_var.value' to the
local 'buf[]'.
And the overflow is not a problem, it just drops some unused info[1] to
reloop to
the head for saving our target parameter.

[1] BOOT_IMAGE=(hd0,gpt2)/ostree/centos-dd7415ed2c7cc3f65bdc4bf8f9a63b95bbb13ee0fee633f6b92a872944d1d6e4/vmlinuz-5.14.0-4xx.4xx.4495_1336583944.el9iv.x86_64

I'm thinking of lowering the priority info from TWARN to TINFO in that line:
    tst_res(TWARN, "Buffer overflowed while parsing /proc/cmdline");

I will send a patch V2 once get a better solution.


-- 
Regards,
Li Wang


More information about the ltp mailing list