From: Andrew Lunn <andrew@lunn.ch>
To: Miaoqian Lin <linmq006@gmail.com>
Cc: Rasesh Mody <rmody@marvell.com>,
Sudarsana Kalluru <skalluru@marvell.com>,
GR-Linux-NIC-Dev@marvell.com, Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Ivan Vecera <ivecera@redhat.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH] bna: prevent bad user input in bnad_debugfs_write_regrd()
Date: Thu, 30 Oct 2025 18:37:55 +0100 [thread overview]
Message-ID: <75e4c931-3e17-430a-a902-60f9d8161bc3@lunn.ch> (raw)
In-Reply-To: <20251030053411.710-1-linmq006@gmail.com>
On Thu, Oct 30, 2025 at 01:34:10PM +0800, Miaoqian Lin wrote:
> A malicious user could pass an arbitrarily bad value
> to memdup_user_nul(), potentially causing kernel crash.
How would it crash the kernel? I would expect memdup_user_nul() to
either succeed or fail and return a NULL.
However, adding a range check does make sense.
> This follows the same pattern as commit ee76746387f6
> ("netdevsim: prevent bad user input in nsim_dev_health_break_write()")
> and commit 7ef4c19d245f
> ("smackfs: restrict bytes count in smackfs write functions")
>
> Found via static analysis and code review.
>
> Fixes: d0e6a8064c42 ("bna: use memdup_user to copy userspace buffers")
> Cc: stable@vger.kernel.org
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
> drivers/net/ethernet/brocade/bna/bnad_debugfs.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/net/ethernet/brocade/bna/bnad_debugfs.c b/drivers/net/ethernet/brocade/bna/bnad_debugfs.c
> index 8f0972e6737c..ad33ab1d266d 100644
> --- a/drivers/net/ethernet/brocade/bna/bnad_debugfs.c
> +++ b/drivers/net/ethernet/brocade/bna/bnad_debugfs.c
> @@ -311,6 +311,9 @@ bnad_debugfs_write_regrd(struct file *file, const char __user *buf,
> unsigned long flags;
> void *kern_buf;
>
> + if (nbytes == 0 || nbytes > PAGE_SIZE)
> + return -EINVAL;
> +
> /* Copy the user space buf */
> kern_buf = memdup_user_nul(buf, nbytes);
> if (IS_ERR(kern_buf))
Look at what it does next:
rc = sscanf(kern_buf, "%x:%x", &addr, &len);
What is the maximum length of "%x:%x" ? A lot less than PAGE_SIZE. So
you can make the range check much smaller.
Also, what about bnad_debugfs_write_regwr()? If you find a bug, look
around, the same bug might be repeated close by. You might also want
to look at your static analysis tool and find out why it did not
report that function.
Andrew
---
pw-bot: cr
prev parent reply other threads:[~2025-10-30 17:38 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-30 5:34 Miaoqian Lin
2025-10-30 17:37 ` Andrew Lunn [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=75e4c931-3e17-430a-a902-60f9d8161bc3@lunn.ch \
--to=andrew@lunn.ch \
--cc=GR-Linux-NIC-Dev@marvell.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=ivecera@redhat.com \
--cc=kuba@kernel.org \
--cc=linmq006@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rmody@marvell.com \
--cc=skalluru@marvell.com \
--cc=stable@vger.kernel.org \
/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®