blk-mq: avoid sysfs buffer overflow with too many CPU cores
authorMing Lei <ming.lei@redhat.com>
Sat, 2 Nov 2019 08:02:15 +0000 (16:02 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 17 Dec 2019 18:56:14 +0000 (19:56 +0100)
commit285b07348946818dcdc17aea67427627e957be0d
treebd196803ccc7d39936268276c7c1b5d2527a398c
parentf020809b8450598ae7ae83d7f480463acf9486ac
blk-mq: avoid sysfs buffer overflow with too many CPU cores

commit 8962842ca5abdcf98e22ab3b2b45a103f0408b95 upstream.

It is reported that sysfs buffer overflow can be triggered if the system
has too many CPU cores(>841 on 4K PAGE_SIZE) when showing CPUs of
hctx via /sys/block/$DEV/mq/$N/cpu_list.

Use snprintf to avoid the potential buffer overflow.

This version doesn't change the attribute format, and simply stops
showing CPU numbers if the buffer is going to overflow.

Cc: stable@vger.kernel.org
Fixes: 676141e48af7("blk-mq: don't dump CPU -> hw queue map on driver load")
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
block/blk-mq-sysfs.c