From: Petr Pavlu <petr.pavlu@suse.com>
To: Pengpeng Hou <pengpeng@iscas.ac.cn>
Cc: Daniel Gomez <da.gomez@samsung.com>,
Sami Tolvanen <samitolvanen@google.com>,
Kees Cook <kees@kernel.org>, Aaron Tomlin <atomlin@atomlin.com>,
Dmitry Antipov <dmantipov@yandex.ru>,
Thorsten Blum <thorsten.blum@linux.dev>,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH v2] params: bound array element output to the caller's page buffer
Date: Mon, 25 May 2026 09:23:44 +0200 [thread overview]
Message-ID: <dc0c1bff-2d1a-4863-a22b-29d14a73361e@suse.com> (raw)
In-Reply-To: <20260521022854.38938-1-pengpeng@iscas.ac.cn>
On 5/21/26 4:28 AM, Pengpeng Hou wrote:
> Hi Petr,
>
> You're right, that changelog bullet was misleading.
>
> v1 already broke out of the loop once off reached PAGE_SIZE - 1, so it
> would not enter another iteration with no remaining byte in the caller's
> page buffer.
>
> The v2 change was narrower: after the element getter returns, it clamps
> the number of bytes to copy and only rewrites the previous '\n' separator
> when that clamped length is non-zero. That avoids turning the previous
> separator into ',' when the next element contributes no visible bytes
> after clamping, or if a getter returns 0.
The updated code in v2 looks as follows:
for (i = off = 0; i < (arr->num ? *arr->num : arr->max); i++) {
p.arg = arr->elem + arr->elemsize * i;
check_kparam_locked(p.mod);
ret = arr->ops->get(elem_buf, &p);
if (ret < 0)
goto out;
ret = min(ret, (int)(PAGE_SIZE - 1 - off));
if (!ret)
break;
/* Replace the previous element's trailing newline with a comma. */
if (i)
buffer[off - 1] = ',';
memcpy(buffer + off, elem_buf, ret);
off += ret;
if (off == PAGE_SIZE - 1)
break;
}
The clamping is done by:
ret = min(ret, (int)(PAGE_SIZE - 1 - off));
My understanding is that the expression '(int)(PAGE_SIZE - 1 - off)'
cannot return 0 because otherwise the loop would have already broken out
in the previous iteration due to the final check
'if (off == PAGE_SIZE - 1)'.
The input ret value to the min() calculation comes from the
arr->ops->get() call. The kernel_param_ops::get() API requires the
resulting string to be terminated by '\n', so on success the call should
never return 0. Even if it does and we want to make param_array_get()
tighter, I believe it should be treated as an error rather than silently
returning success from this function.
--
Thanks,
Petr
prev parent reply other threads:[~2026-05-25 7:23 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-17 7:50 [PATCH] " Pengpeng Hou
2026-04-23 9:34 ` Petr Pavlu
2026-04-23 22:49 ` Pengpeng Hou
2026-05-05 9:08 ` Petr Pavlu
2026-05-07 8:21 ` [PATCH v2] " Pengpeng Hou
2026-05-11 20:03 ` Kees Cook
2026-05-14 8:06 ` Petr Pavlu
2026-05-21 2:28 ` Pengpeng Hou
2026-05-25 7:23 ` Petr Pavlu [this message]
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=dc0c1bff-2d1a-4863-a22b-29d14a73361e@suse.com \
--to=petr.pavlu@suse.com \
--cc=atomlin@atomlin.com \
--cc=da.gomez@samsung.com \
--cc=dmantipov@yandex.ru \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pengpeng@iscas.ac.cn \
--cc=samitolvanen@google.com \
--cc=stable@vger.kernel.org \
--cc=thorsten.blum@linux.dev \
/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®