Commit 55951be8 authored by Roberto Sassu's avatar Roberto Sassu Committed by Chen Zhongjin
Browse files

um: Add winch to winch_handlers before registering winch IRQ

stable inclusion
from stable-v5.10.219
commit 351d1a64544944b44732f6a64ed65573b00b9e14
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/IA7YJR
CVE: CVE-2024-39292

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=351d1a64544944b44732f6a64ed65573b00b9e14



--------------------------------

[ Upstream commit a0fbbd36c156b9f7b2276871d499c9943dfe5101 ]

Registering a winch IRQ is racy, an interrupt may occur before the winch is
added to the winch_handlers list.

If that happens, register_winch_irq() adds to that list a winch that is
scheduled to be (or has already been) freed, causing a panic later in
winch_cleanup().

Avoid the race by adding the winch to the winch_handlers list before
registering the IRQ, and rolling back if um_request_irq() fails.

Fixes: 42a359e3 ("uml: SIGIO support cleanup")
Signed-off-by: default avatarRoberto Sassu <roberto.sassu@huawei.com>
Reviewed-by: default avatarJohannes Berg <johannes@sipsolutions.net>
Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarChen Zhongjin <chenzhongjin@huawei.com>
parent b6c86296
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -668,23 +668,25 @@ void register_winch_irq(int fd, int tty_fd, int pid, struct tty_port *port,
		goto cleanup;
	}

	*winch = ((struct winch) { .list  	= LIST_HEAD_INIT(winch->list),
				   .fd  	= fd,
	*winch = ((struct winch) { .fd  	= fd,
				   .tty_fd 	= tty_fd,
				   .pid  	= pid,
				   .port 	= port,
				   .stack	= stack });

	spin_lock(&winch_handler_lock);
	list_add(&winch->list, &winch_handlers);
	spin_unlock(&winch_handler_lock);

	if (um_request_irq(WINCH_IRQ, fd, IRQ_READ, winch_interrupt,
			   IRQF_SHARED, "winch", winch) < 0) {
		printk(KERN_ERR "register_winch_irq - failed to register "
		       "IRQ\n");
		goto out_free;
	}

		spin_lock(&winch_handler_lock);
	list_add(&winch->list, &winch_handlers);
		list_del(&winch->list);
		spin_unlock(&winch_handler_lock);
		goto out_free;
	}

	return;