All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: yangshiguang1011@163.com
Cc: rafael@kernel.org, dakr@kernel.org, peterz@infradead.org,
	linux-kernel@vger.kernel.org, yangshiguang@xiaomi.com,
	stable@vger.kernel.org
Subject: Re: [PATCH] debugfs: Fix NULL pointer dereference at debugfs_read_file_str
Date: Mon, 22 Dec 2025 12:54:22 +0100	[thread overview]
Message-ID: <2025122234-crazy-remix-3098@gregkh> (raw)
In-Reply-To: <20251222093615.663252-2-yangshiguang1011@163.com>

On Mon, Dec 22, 2025 at 05:36:16PM +0800, yangshiguang1011@163.com wrote:
> From: yangshiguang <yangshiguang@xiaomi.com>
> 
> Check in debugfs_read_file_str() if the string pointer is NULL.
> 
> When creating a node using debugfs_create_str(), the string parameter
> value can be NULL to indicate empty/unused/ignored.

Why would you create an empty debugfs string file?  That is not ok, we
should change that to not allow this.

> However, reading this node using debugfs_read_file_str() will cause a
> kernel panic.
> This should not be fatal, so return an invalid error.
> 
> Signed-off-by: yangshiguang <yangshiguang@xiaomi.com>
> Fixes: 9af0440ec86e ("debugfs: Implement debugfs_create_str()")
> Cc: stable@vger.kernel.org
> ---
>  fs/debugfs/file.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
> index 3ec3324c2060..a22ff0ceb230 100644
> --- a/fs/debugfs/file.c
> +++ b/fs/debugfs/file.c
> @@ -1026,6 +1026,9 @@ ssize_t debugfs_read_file_str(struct file *file, char __user *user_buf,
>  		return ret;
>  
>  	str = *(char **)file->private_data;
> +	if (!str)
> +		return -EINVAL;

What in kernel user causes this to happen?  Let's fix that up instead
please.

thanks,

greg k-h

  reply	other threads:[~2025-12-22 11:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-22  9:36 [PATCH] debugfs: Fix NULL pointer dereference at debugfs_read_file_str yangshiguang1011
2025-12-22 11:54 ` Greg KH [this message]
2025-12-22 12:41   ` yangshiguang
2025-12-22 14:11     ` Greg KH
2025-12-23  2:12       ` yangshiguang
2025-12-23  9:19         ` Greg KH

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=2025122234-crazy-remix-3098@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=dakr@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=rafael@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=yangshiguang1011@163.com \
    --cc=yangshiguang@xiaomi.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.