[PATCH] um: line: Free the read IRQ when the write IRQ request fails

Suyuan Wang via B4 Relay posted 1 patch 21 hours ago
arch/um/drivers/line.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
[PATCH] um: line: Free the read IRQ when the write IRQ request fails
Posted by Suyuan Wang via B4 Relay 21 hours ago
From: Suyuan Wang <stevewong@hust.edu.cn>

line_setup_irq() requests the read IRQ first and then the write IRQ.
If the write IRQ request fails, it returns the error without freeing
the read IRQ. Its caller, open_chan(), then calls close_chan(), but
close_one_chan() only frees the IRQs of a channel that is enabled, and
the channel was never marked enabled. So the read IRQ stays registered
for an fd that close_one_chan() then closes.

Free the read IRQ in line_setup_irq() before returning the error.

Found with a static analysis tool and checked by hand.

Fixes: d14ad81f800a ("uml: handle errors on opening host side of consoles")
Cc: stable@vger.kernel.org
Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
---
Compile tested with ARCH=um (W=1, no new warnings); the failure path wasn't run.
---
 arch/um/drivers/line.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/um/drivers/line.c b/arch/um/drivers/line.c
index c851a592809c..5589fa68871e 100644
--- a/arch/um/drivers/line.c
+++ b/arch/um/drivers/line.c
@@ -273,8 +273,12 @@ int line_setup_irq(int fd, int input, int output, struct line *line, void *data)
 		err = um_request_irq(UM_IRQ_ALLOC, fd, IRQ_WRITE,
 				     line_write_interrupt, 0,
 				     driver->write_irq_name, data);
-		if (err < 0)
+		if (err < 0) {
+			/* the caller won't free it, the channel isn't enabled */
+			if (input)
+				um_free_irq(line->read_irq, data);
 			return err;
+		}
 
 		line->write_irq = err;
 	}