Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1614112ybv; Fri, 21 Feb 2020 00:18:35 -0800 (PST) X-Google-Smtp-Source: APXvYqzlFyFNpXjfW15i2c5btP69U4iere2eBUiriwmObZ5fR/YPkqlKV9MTcBAEIXD6zQ2TgWCQ X-Received: by 2002:aca:b608:: with SMTP id g8mr1059111oif.142.1582273115453; Fri, 21 Feb 2020 00:18:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582273115; cv=none; d=google.com; s=arc-20160816; b=IOlB3WMmdGOGxIdRZhyg2EpJpzgwpc0r1WCOTvv0DWCm6QM0zsGgYFG66GbZz724qM x4wT2dalhYTbU6H0gXgPCIY9jK0eIpKqqzJjS36vaXoxzqTmoDGEN3hnE2WrpFbw0raN 7n9obyHAgX0aNACbuwOpjqYbrob70Yc2iCOkOwEXQJ3+PAbPHLuKEbmJqYg39uU9GmbV e/nYgld01qo9nYyrzNcmY7aoswl6FrnV3VPQ49QUzKqshYdbxKRmNW17BW6xOU3/bh0D sUbeXfkyqq2DRyKyVfi0CJUmwjSLpw9W//Ic9m39vATQIwM/x+H2wwYnMo2QxPLWHg84 DL9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FoM7ET16oOer39QmRHlV5CQuT7aORda5n7MqNhUoQSg=; b=IuMB9h00GLFMNu1ELJ2Pp66+9A+N0QCWpM330trbqyHlS1bBH9Zk37wzp5kRHdln++ vn2XIOkQKPVCA2TC/tKc/iWhCoKXwAa7grn7qFyLYt2/jsRiYEsMwH4R6EqwXH9OOLUQ htt461vWKhCEwXVtKxtVlpPrJzIiLvl4Wzrtxs0DPG87wAMz+O8HNmKAqh7QcfisfXaD 9DY7Ldd+yysrURuA3hFyypq+mKvWk+eHyDotT5UAvrGkaORXycijawhsUCEaD74NeCkf fiQKZunbrZNrJU6I2g17iLM1IjwCph3QxyjkAvG8z+W+znh7NiiWyh9s0iQZdQYavrc+ 5IUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kcS6FeJB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a10si506521oia.232.2020.02.21.00.18.23; Fri, 21 Feb 2020 00:18:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kcS6FeJB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387708AbgBUIRl (ORCPT + 99 others); Fri, 21 Feb 2020 03:17:41 -0500 Received: from mail.kernel.org ([198.145.29.99]:55192 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387686AbgBUIRj (ORCPT ); Fri, 21 Feb 2020 03:17:39 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E41CC24690; Fri, 21 Feb 2020 08:17:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582273058; bh=k+XzV/W9UPSf5JZG4LsaLccqrAu0LZ7Ag9WTLrAZBPE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kcS6FeJBSlFALfKaRw+P8iXX2pzOHKGN/TFRstCzvAeYhZQEmaRf66mHCTXBZVMrZ 3vw5HRqW17ASQCjOTaZFkzrDRpqxA3hQn4no4g6FSGeZAAs0Z3uHAy9lnDDKN8VIqv iNBhV6GmYJ6lzSEwCLj4oKzAPD9GQix4tse794fI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jia-Ju Bai , Sasha Levin Subject: [PATCH 4.19 031/191] uio: fix a sleep-in-atomic-context bug in uio_dmem_genirq_irqcontrol() Date: Fri, 21 Feb 2020 08:40:04 +0100 Message-Id: <20200221072254.985632417@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200221072250.732482588@linuxfoundation.org> References: <20200221072250.732482588@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jia-Ju Bai [ Upstream commit b74351287d4bd90636c3f48bc188c2f53824c2d4 ] The driver may sleep while holding a spinlock. The function call path (from bottom to top) in Linux 4.19 is: kernel/irq/manage.c, 523: synchronize_irq in disable_irq drivers/uio/uio_dmem_genirq.c, 140: disable_irq in uio_dmem_genirq_irqcontrol drivers/uio/uio_dmem_genirq.c, 134: _raw_spin_lock_irqsave in uio_dmem_genirq_irqcontrol synchronize_irq() can sleep at runtime. To fix this bug, disable_irq() is called without holding the spinlock. This bug is found by a static analysis tool STCheck written by myself. Signed-off-by: Jia-Ju Bai Link: https://lore.kernel.org/r/20191218094405.6009-1-baijiaju1990@gmail.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/uio/uio_dmem_genirq.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/uio/uio_dmem_genirq.c b/drivers/uio/uio_dmem_genirq.c index e1134a4d97f3f..a00b4aee6c799 100644 --- a/drivers/uio/uio_dmem_genirq.c +++ b/drivers/uio/uio_dmem_genirq.c @@ -135,11 +135,13 @@ static int uio_dmem_genirq_irqcontrol(struct uio_info *dev_info, s32 irq_on) if (irq_on) { if (test_and_clear_bit(0, &priv->flags)) enable_irq(dev_info->irq); + spin_unlock_irqrestore(&priv->lock, flags); } else { - if (!test_and_set_bit(0, &priv->flags)) + if (!test_and_set_bit(0, &priv->flags)) { + spin_unlock_irqrestore(&priv->lock, flags); disable_irq(dev_info->irq); + } } - spin_unlock_irqrestore(&priv->lock, flags); return 0; } -- 2.20.1