Skip to contentSkip to conversation

relay: replay_file_open(): NULL ptr deref in CPU hotplugs

PATCH In review Yichun Zhang (agentzh) 2 participants 2 messages Sep 8, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 relay: replay_file_open(): NULL ptr deref in CPU hotplugs

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.

---
 kernel/relay.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/relay.c +3 -0
index 6a611e779e95..2db69fd527d1 100644
@@ -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;
 
Signature · 1 line
2.17.2
maintainer
#1 lore raw
Quoted 14 lines · Yichun Zhang (agentzh)

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.

---
 kernel/relay.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/relay.c +0 -0
index 6a611e779e95..2db69fd527d1 100644

kernel/relay.c EXPORT_SYMBOL_GPL(relay_flush); · line 823

Quoted 8 lines
kernel/relay.c +3 -0
@@ -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?

Signature · 1 line
Jens Axboe