Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1945975ybv; Fri, 14 Feb 2020 08:40:20 -0800 (PST) X-Google-Smtp-Source: APXvYqzEhKNm7ZxSJjDGxDMx+9obwiYWLPmSrzEfTTu4o7B+bY92Uf7yS1lSqKsu6piUMZSGNHbM X-Received: by 2002:a54:4003:: with SMTP id x3mr2390392oie.0.1581698420194; Fri, 14 Feb 2020 08:40:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581698420; cv=none; d=google.com; s=arc-20160816; b=USlZoob4a8vTrARYxV9Kitx1M1MdRYJ8gQ0Va23ey2LU3nL/eG/9cXhrwEvxfX9zMy /1ZjO+faN4hlm4lzbbqCKcMQihuIZUOuPJQqoJ7lH3V1l5XORv4ikxP2uYpaJYo5Qh5g jLuiiTEisciQPU/8Ylj+/ze1bzP87HERbVo4HZ6jE9YfDwBleTIWCc6ZZdgDbz5mJvb3 7CWB3WdyBiaat2syDCGtUOgj6bGu9z63GioLYJl/jLSEjgA6K/JwJFqY7ZMcdkiClIat QXVVu9FNGF9yP2mmdsR3gqPmrY/FX3wpPs+RwIIIJVNRaiAzdoHRNWE1hHKEy5jy1VhR uEig== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=FoM7ET16oOer39QmRHlV5CQuT7aORda5n7MqNhUoQSg=; b=gF+TqAhbWoMP9zU/SFr38qL8cR7mqbW2vkhX51GFbaxmKupTZHfqMVFKFttInNqP6b yr3aYPXJMDwdS4rcm/A5jybeO93kwp0AQtaDU5C9r1tyYf++wji09B2iI5iGh6eVC7Op SZQHkiGhHHF+3uYKTwzNyiSZY9n49zNmFI66Y6kPsl2fKRhFkhhwGwjD0g0yB8iCK865 nYQfDGoVdDyPYNPo48Rh9ZEKB4lU5J7Zk861BsNihCfKcfiuYVR0ebdVUEfsuNIUZd/f rhsSp/2Js0rjsKWTpwcsHntAmvxRxfbheiSZWp6hZe6pV2eLI3NzWvzF5+AwclGXyPP9 MOpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JaHtPS9v; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l11si3249110oth.286.2020.02.14.08.40.08; Fri, 14 Feb 2020 08:40:20 -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=JaHtPS9v; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405555AbgBNQXM (ORCPT + 99 others); Fri, 14 Feb 2020 11:23:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:56662 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404392AbgBNQVs (ORCPT ); Fri, 14 Feb 2020 11:21:48 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BF4E7246AC; Fri, 14 Feb 2020 16:21:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581697307; bh=k+XzV/W9UPSf5JZG4LsaLccqrAu0LZ7Ag9WTLrAZBPE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JaHtPS9vqjFLGeIAXKfy8qIf9fwO+roV/ejpA0X3IvWGwatVFZe+a/PHh9LgRj9u3 u9xS/9mLGnWbjHBXsBnfj7kRqcCnlCqEXH65ZsTr9vtwEgEqzebK9c45L+bc5xdRGk cRckJAESama3i8d5nFkcIuPtGAE0Jk0V7obAkFx4= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jia-Ju Bai , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH AUTOSEL 4.9 019/141] uio: fix a sleep-in-atomic-context bug in uio_dmem_genirq_irqcontrol() Date: Fri, 14 Feb 2020 11:19:19 -0500 Message-Id: <20200214162122.19794-19-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200214162122.19794-1-sashal@kernel.org> References: <20200214162122.19794-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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