From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: YuanZhe Liu <25031212351@stu.xidian.edu.cn>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
"Bin Yu" <byu@xidian.edu.cn>,
"Cheng Wen" <wencheng@xidian.edu.cn>
Subject: Re: [PATCH] iio: buffer: kfifo: reject lengths exceeding the kmalloc limit
Date: Fri, 20 Nov 2026 18:23:12 +0200 [thread overview]
Message-ID: <awBz8LVSYVBFOANe@ashevche-desk.local> (raw)
In-Reply-To: <20261120132129.3110-1-25031212351@stu.xidian.edu.cn>
On Fri, Nov 20, 2026 at 09:21:29PM +0800, YuanZhe Liu wrote:
> __iio_allocate_kfifo() rejects lengths that would overflow an unsigned
> int after kfifo rounds them up to the next power of two, but the byte
> size handed to __kfifo_alloc() can still be beyond what kmalloc() can
> serve.
>
> The kfifo buffer is allocated with kmalloc(), which is limited to
> KMALLOC_MAX_SIZE. A larger request has an allocation order above
> MAX_PAGE_ORDER, so the page allocator's order sanity check fires and
> enabling the buffer ends with a WARNING instead of a clean error.
>
> The buffer length is set through buffer/length, which accepts any value
> up to UINT_MAX. With the voltage and timestamp scan channels enabled,
> a length of 262349 makes the rounded up size exceed KMALLOC_MAX_SIZE
> and triggers the warning on buffer/enable.
>
> Also reject lengths whose rounded up size does not fit into
> KMALLOC_MAX_SIZE, so that enabling the buffer fails with -EINVAL.
...
> if (roundup_pow_of_two(length) > UINT_MAX / bytes_per_datum)
> return -EINVAL;
So many developers of this patch and there is no clarification
why we need to keep this check.
> + /*
> + * The kfifo memory is allocated with kmalloc(), so the size must also
> + * fit into the largest allocation kmalloc() can serve. Larger
> + * requests need an order above MAX_PAGE_ORDER and are refused by the
> + * page allocator with a warning.
> + */
> + if (roundup_pow_of_two(length) > KMALLOC_MAX_SIZE / bytes_per_datum)
> + return -EINVAL;
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-11-20 16:23 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 13:21 YuanZhe Liu
2026-11-20 16:23 ` Andy Shevchenko [this message]
2026-11-20 16:44 ` [PATCH v2] " YuanZhe Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=awBz8LVSYVBFOANe@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=25031212351@stu.xidian.edu.cn \
--cc=andy@kernel.org \
--cc=byu@xidian.edu.cn \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=wencheng@xidian.edu.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®