mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] relay: replay_file_open(): NULL ptr deref in CPU hotplugs
@ 2022-09-08 21:17 Yichun Zhang (agentzh)
  2022-09-08 21:19 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Yichun Zhang (agentzh) @ 2022-09-08 21:17 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: Yichun Zhang (agentzh),
	Colin Ian King, Andrew Morton, Jens Axboe, linux-kernel

CPU hotplug may introduce race conditions. We reproduced kernel panics
due to this NULL ptr deref error when doing frequent random CPU hotplugs
in a KVM guest.

Signed-off-by: Yichun Zhang (agentzh) <yichun@openresty.com>
---
 kernel/relay.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/relay.c b/kernel/relay.c
index 6a611e779e95..2db69fd527d1 100644
--- a/kernel/relay.c
+++ b/kernel/relay.c
@@ -816,6 +816,9 @@ EXPORT_SYMBOL_GPL(relay_flush);
 static int relay_file_open(struct inode *inode, struct file *filp)
 {
 	struct rchan_buf *buf = inode->i_private;
+	if (unlikely(buf == NULL))
+		return -ENOENT;
+
 	kref_get(&buf->kref);
 	filp->private_data = buf;
 
-- 
2.17.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] relay: replay_file_open(): NULL ptr deref in CPU hotplugs
  2022-09-08 21:17 [PATCH] relay: replay_file_open(): NULL ptr deref in CPU hotplugs Yichun Zhang (agentzh)
@ 2022-09-08 21:19 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2022-09-08 21:19 UTC (permalink / raw)
  To: Yichun Zhang (agentzh), linux-fsdevel
  Cc: Colin Ian King, Andrew Morton, linux-kernel

On 9/8/22 3:17 PM, Yichun Zhang (agentzh) wrote:
> CPU hotplug may introduce race conditions. We reproduced kernel panics
> due to this NULL ptr deref error when doing frequent random CPU hotplugs
> in a KVM guest.
> 
> Signed-off-by: Yichun Zhang (agentzh) <yichun@openresty.com>
> ---
>  kernel/relay.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/kernel/relay.c b/kernel/relay.c
> index 6a611e779e95..2db69fd527d1 100644
> --- a/kernel/relay.c
> +++ b/kernel/relay.c
> @@ -816,6 +816,9 @@ EXPORT_SYMBOL_GPL(relay_flush);
>  static int relay_file_open(struct inode *inode, struct file *filp)
>  {
>  	struct rchan_buf *buf = inode->i_private;
> +	if (unlikely(buf == NULL))
> +		return -ENOENT;
> +
>  	kref_get(&buf->kref);
>  	filp->private_data = buf;

If it can go away before open is called, what prevents it from going
away after that check but before kref_get() is called?

-- 
Jens Axboe



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-08 21:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-08 21:17 [PATCH] relay: replay_file_open(): NULL ptr deref in CPU hotplugs Yichun Zhang (agentzh)
2022-09-08 21:19 ` Jens Axboe

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®