From: Dave Jiang <dave.jiang@intel.com>
To: yangqixiao <yangqixiao@inspur.com>, jdmason@kudzu.us
Cc: allenbh@gmail.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1] ntb/ntb_tool: correct sscanf format for u64 and size_t in tool_peer_mw_trans_write
Date: Mon, 5 Jan 2026 09:42:30 -0700 [thread overview]
Message-ID: <1e3f6c31-366e-41d7-8692-32c031383530@intel.com> (raw)
In-Reply-To: <20251230124656.4709-1-yangqixiao@inspur.com>
On 12/30/25 5:46 AM, yangqixiao wrote:
> The sscanf() call in tool_peer_mw_trans_write() uses "%lli:%zi" to parse
> user input into 'u64 addr' and 'size_t wsize'. This is incorrect:
>
> - "%lli" expects a signed long long *, but 'addr' is u64 (unsigned).
> Input like "0x8000000000000000" is misinterpreted as negative,
> leading to corrupted address values.
>
> - "%zi" expects a signed ssize_t *, but 'wsize' is size_t (unsigned).
> Input of "-1" is successfully parsed and stored as SIZE_MAX
> (e.g., 0xFFFFFFFFFFFFFFFF), which may cause buffer overflows
> or infinite loops in subsequent memory operations.
>
> Fix by using format specifiers that match the actual variable types:
> - "%llu" for u64 (supports hex/decimal, standard for kernel u64 parsing)
> - "%zu" for size_t (standard and safe; rejects negative input)
>
> Signed-off-by: yangqixiao <yangqixiao@inspur.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
> ---
> drivers/ntb/test/ntb_tool.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/ntb/test/ntb_tool.c b/drivers/ntb/test/ntb_tool.c
> index 641cb7e05a47..06881047f5bc 100644
> --- a/drivers/ntb/test/ntb_tool.c
> +++ b/drivers/ntb/test/ntb_tool.c
> @@ -936,7 +936,7 @@ static ssize_t tool_peer_mw_trans_write(struct file *filep,
>
> buf[buf_size] = '\0';
>
> - n = sscanf(buf, "%lli:%zi", &addr, &wsize);
> + n = sscanf(buf, "%llu:%zu", &addr, &wsize);
> if (n != 2)
> return -EINVAL;
>
prev parent reply other threads:[~2026-01-05 16:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-30 12:46 yangqixiao
2026-01-05 16:42 ` Dave Jiang [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=1e3f6c31-366e-41d7-8692-32c031383530@intel.com \
--to=dave.jiang@intel.com \
--cc=allenbh@gmail.com \
--cc=jdmason@kudzu.us \
--cc=linux-kernel@vger.kernel.org \
--cc=yangqixiao@inspur.com \
/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®