mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mark Bloch <mbloch@nvidia.com>
To: Aibing Chen <chenaibing@cmss.chinamobile.com>,
	Saeed Mahameed <saeedm@nvidia.com>,
	Leon Romanovsky <leon@kernel.org>,
	Tariq Toukan <tariqt@nvidia.com>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	netdev@vger.kernel.org, linux-rdma@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v2] net/mlx5: fix a stack over-read in the QP debugfs
Date: Mon, 23 Nov 2026 14:21:02 +0200	[thread overview]
Message-ID: <c136c508-ed03-4679-b7b4-f8fd89859ae0@nvidia.com> (raw)
In-Reply-To: <20261122145152.1473-1-chenaibing@cmss.chinamobile.com>



On 22/11/2026 16:51, Aibing Chen wrote:
> dbg_read() formats the field into char tbuf[18] and passes the return
> value of snprintf() to simple_read_from_buffer() as the number of
> available bytes.  snprintf() returns the length the output would have
> had, not the number of bytes written, so when the string does not fit
> that value is larger than the buffer: the longest QP transport string is
> "Invalid transport type" (22 characters), so with the trailing newline
> the function returns 23 while only 18 bytes were written.
> 
> simple_read_from_buffer() uses that length to bound the copy to
> userspace, so reading .../qp/<qpn>/transport copies up to 23 bytes out of
> the 18 byte stack array, leaking 5 bytes of stack.
> 
> Enlarge the buffer so the longest string fits and use scnprintf(), which
> returns the number of bytes actually written.
> 
> Fixes: db81a5c374b5 ("mlx5_core: Improve debugfs readability")
> Signed-off-by: Aibing Chen <chenaibing@cmss.chinamobile.com>

Acked-by: Mark Bloch <mbloch@nvidia.com>

> ---
> v2:
> - add the Fixes tag for the commit that introduced the tbuf/is_str
>   formatting, as suggested in the review.
> 
>  drivers/net/ethernet/mellanox/mlx5/core/debugfs.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/debugfs.c b/drivers/net/ethernet/mellanox/mlx5/core/debugfs.c
> index 30be2b631..3e75f66f7 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/debugfs.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/debugfs.c
> @@ -496,7 +496,7 @@ static ssize_t dbg_read(struct file *filp, char __user *buf, size_t count,
>  {
>  	struct mlx5_field_desc *desc;
>  	struct mlx5_rsc_debug *d;
> -	char tbuf[18];
> +	char tbuf[24];
>  	int is_str = 0;
>  	u64 field;
>  	int ret;
> @@ -522,9 +522,10 @@ static ssize_t dbg_read(struct file *filp, char __user *buf, size_t count,
>  	}
>  
>  	if (is_str)
> -		ret = snprintf(tbuf, sizeof(tbuf), "%s\n", (const char *)(unsigned long)field);
> +		ret = scnprintf(tbuf, sizeof(tbuf), "%s\n",
> +				(const char *)(unsigned long)field);
>  	else
> -		ret = snprintf(tbuf, sizeof(tbuf), "0x%llx\n", field);
> +		ret = scnprintf(tbuf, sizeof(tbuf), "0x%llx\n", field);
>  
>  	return simple_read_from_buffer(buf, count, pos, tbuf, ret);
>  }
> 
> 
> 


      parent reply	other threads:[~2026-11-23 12:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22 14:51 Aibing Chen
2026-11-22 14:57 ` netdev-bot+sinfo
2026-11-23  4:53 ` Moshe Shemesh
2026-11-23 12:21 ` Mark Bloch [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=c136c508-ed03-4679-b7b4-f8fd89859ae0@nvidia.com \
    --to=mbloch@nvidia.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=chenaibing@cmss.chinamobile.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=saeedm@nvidia.com \
    --cc=tariqt@nvidia.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®