Skip to contentSkip to conversation

orangefs: fix double-free of trailer_buf on readdir copy failure

PATCH In review Yifei Gao 2 participants 2 messages Aug 3

Subsystems (2)
lore
Share & tools
lore

Yifei Gao

author
#0 lore raw

PATCH 1/1 orangefs: fix double-free of trailer_buf on readdir copy failure

On a readdir downcall, orangefs_devreq_write_iter() frees op->downcall.trailer_buf with vfree() when copy_from_iter_full() fails, but does not clear the pointer before goto Efault. The waiter in do_readdir() is then woken with a negative status and frees the same pointer again on its r < 0 path, causing a deterministic double-free. A client holding /dev/pvfs2-req triggers it by sending a readdir downcall whose declared trailer_size exceeds the bytes it supplies.

Clear the pointer after freeing so the readdir-side vfree() becomes a no-op.

Fixes 382f4581e67f ("orangefs: rewrite readdir to fix several bugs")
Assisted-by Claude:claude-opus-4-8
---
 fs/orangefs/devorangefs-req.c | 1 +
 1 file changed, 1 insertion(+)
fs/orangefs/devorangefs-req.c +1 -0
index 33ee8cb32f83..e5c60da7e677 100644
@@ -474,6 +474,7 @@ static ssize_t orangefs_devreq_write_iter(struct kiocb *iocb,
 			         op->downcall.trailer_size, iter)) {
 		gossip_err("%s: failed to copy trailer.\n", __func__);
 		vfree(op->downcall.trailer_buf);
+		op->downcall.trailer_buf = NULL;
 		goto Efault;
 	}
 
Signature · 1 line
2.43.0
maintainer
#1 lore raw

Thanks! I'll add that to my linux-next...

-Mike

Quoted 35 lines · Yifei Gao

On a readdir downcall, orangefs_devreq_write_iter() frees op->downcall.trailer_buf with vfree() when copy_from_iter_full() fails, but does not clear the pointer before goto Efault. The waiter in do_readdir() is then woken with a negative status and frees the same pointer again on its r < 0 path, causing a deterministic double-free. A client holding /dev/pvfs2-req triggers it by sending a readdir downcall whose declared trailer_size exceeds the bytes it supplies.

Clear the pointer after freeing so the readdir-side vfree() becomes a no-op.

Fixes 382f4581e67f ("orangefs: rewrite readdir to fix several bugs")
Assisted-by Claude:claude-opus-4-8
---
 fs/orangefs/devorangefs-req.c | 1 +
 1 file changed, 1 insertion(+)
fs/orangefs/devorangefs-req.c +1 -1
index 33ee8cb32f83..e5c60da7e677 100644
@@ -474,6 +474,7 @@ static ssize_t orangefs_devreq_write_iter(struct kiocb *iocb,
                                 op->downcall.trailer_size, iter)) {
                gossip_err("%s: failed to copy trailer.\n", __func__);
                vfree(op->downcall.trailer_buf);
+               op->downcall.trailer_buf = NULL;
                goto Efault;
        }
 
--

2.43.0