Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3632694imm; Mon, 30 Jul 2018 00:13:06 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdPBLTjnPmMoFLVec+jQDTpo7JZ9ZqqgX8TAShGZYYWZl6K1RDpiLnCDR8ClUWZfcTlu9Gc X-Received: by 2002:a17:902:8a8e:: with SMTP id p14-v6mr15298512plo.213.1532934786790; Mon, 30 Jul 2018 00:13:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532934786; cv=none; d=google.com; s=arc-20160816; b=n815A3OM4KoKSC0B37XJsLRt7ddXAVzsDQmYiJGmXGlBgtxnlV7lIeVJJAkhIK08dl 2nmh9T2oi7x6pPF5jW0Y290GKCEIZfjXFH4NLNHSpNT1cO9+XxSq0mBAA8OqsPoi4yKf 5YrKvtFrj/rvFCJHjVMqPYZJZxfFqn45yoMONds1HuKk0yV/0y3B5ceNyM/aOGaCuShF OtSu6NT1abWjGBi0VG5HnPERAq7SrylVTdku3mqMfFHpiY/ENoQUQomKfi8EvNFCDDsK Il/utQGd0/bNhgT6awX19HltiHj4tO7g7QLfI1SCMNZz+lve1iDpU8+ZWGdL7zojjKXs fS5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=eDZ77fEldcnBvtCgmI5P4UPCwfUWRPBe/Qt2l6chtQc=; b=NtxnzVRskYKAAj02kPi73dfM3hhFPRENhqNVaCyZRSolKUXgcrxAIELqwJGdIBOW9D 8HFVT5vXcm/eXfifRilYB4q0no+PEZgtCWwTay+Es3j5PE5glbwp+oPFH4jEc3e1XiMp lxmzxJWl1osNTMzSxfZLcuX62BSvc75bd8POTbsO6kwq7qehaO8A4GsmJTL2d075r9t0 U/+/qS8TDrqC/eSOgcfCzI4Bc5feRtK50AGFeU5OHkI72Wlgsl/1czJCXkwh+DeSugej /VlYhXRSCNGkLzFF0MYZvpDZShDce1jLbjf2AG1u6JY8r7/O3l097PCMhNk8rN4fA7ip BkRw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j38-v6si9180394pgj.613.2018.07.30.00.12.52; Mon, 30 Jul 2018 00:13:06 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726623AbeG3Ipa (ORCPT + 99 others); Mon, 30 Jul 2018 04:45:30 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53270 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726344AbeG3Ipa (ORCPT ); Mon, 30 Jul 2018 04:45:30 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 651297C6A9; Mon, 30 Jul 2018 07:11:55 +0000 (UTC) Received: from rhel3.localdomain (ovpn-12-81.pek2.redhat.com [10.72.12.81]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F2A02156701; Mon, 30 Jul 2018 07:11:53 +0000 (UTC) From: xiubli@redhat.com To: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org Cc: mchristi@redhat.com Subject: [PATCH] uio: fix possible circular locking dependency Date: Mon, 30 Jul 2018 03:11:48 -0400 Message-Id: <1532934708-101561-1-git-send-email-xiubli@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 30 Jul 2018 07:11:55 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 30 Jul 2018 07:11:55 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'xiubli@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xiubo Li The call trace: XXX/1910 is trying to acquire lock: (&mm->mmap_sem){++++++}, at: [] might_fault+0x57/0xb0 but task is already holding lock: (&idev->info_lock){+.+...}, at: [] uio_write+0x46/0x130 [uio] which lock already depends on the new lock. the existing dependency chain (in reverse order) is: -> #1 (&idev->info_lock){+.+...}: [] lock_acquire+0x99/0x1e0 [] mutex_lock_nested+0x93/0x410 [] uio_mmap+0x2d/0x170 [uio] [] mmap_region+0x428/0x650 [] do_mmap+0x3b8/0x4e0 [] vm_mmap_pgoff+0xd3/0x120 [] SyS_mmap_pgoff+0x1f1/0x270 [] SyS_mmap+0x22/0x30 [] system_call_fastpath+0x1c/0x21 -> #0 (&mm->mmap_sem){++++++}: [] __lock_acquire+0xdac/0x15f0 [] lock_acquire+0x99/0x1e0 [] might_fault+0x84/0xb0 [] uio_write+0xb4/0x130 [uio] [] vfs_write+0xc3/0x1f0 [] SyS_write+0x8a/0x100 [] system_call_fastpath+0x1c/0x21 other info that might help us debug this: Possible unsafe locking scenario: CPU0 CPU1 ---- ---- lock(&idev->info_lock); lock(&mm->mmap_sem); lock(&idev->info_lock); lock(&mm->mmap_sem); *** DEADLOCK *** 1 lock held by XXX/1910: #0: (&idev->info_lock){+.+...}, at: [] uio_write+0x46/0x130 [uio] stack backtrace: CPU: 0 PID: 1910 Comm: XXX Kdump: loaded Not tainted #1 Hardware name: VMware, Inc. VMware Virtual Platform/440BX Desktop Reference Platform, BIOS 6.00 05/19/2017 Call Trace: [] dump_stack+0x19/0x1b [] print_circular_bug+0x1f9/0x207 [] check_prevs_add+0x957/0x960 [] __lock_acquire+0xdac/0x15f0 [] ? mark_held_locks+0xb9/0x140 [] lock_acquire+0x99/0x1e0 [] ? might_fault+0x57/0xb0 [] might_fault+0x84/0xb0 [] ? might_fault+0x57/0xb0 [] uio_write+0xb4/0x130 [uio] [] vfs_write+0xc3/0x1f0 [] ? fget_light+0xfc/0x510 [] SyS_write+0x8a/0x100 [] system_call_fastpath+0x1c/0x21 Signed-off-by: Xiubo Li --- drivers/uio/uio.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c index 5d421d7..7b5daba 100644 --- a/drivers/uio/uio.c +++ b/drivers/uio/uio.c @@ -625,6 +625,12 @@ static ssize_t uio_write(struct file *filep, const char __user *buf, ssize_t retval; s32 irq_on; + if (count != sizeof(s32)) + return -EINVAL; + + if (copy_from_user(&irq_on, buf, count)) + return -EFAULT; + mutex_lock(&idev->info_lock); if (!idev->info) { retval = -EINVAL; @@ -636,21 +642,11 @@ static ssize_t uio_write(struct file *filep, const char __user *buf, goto out; } - if (count != sizeof(s32)) { - retval = -EINVAL; - goto out; - } - if (!idev->info->irqcontrol) { retval = -ENOSYS; goto out; } - if (copy_from_user(&irq_on, buf, count)) { - retval = -EFAULT; - goto out; - } - retval = idev->info->irqcontrol(idev->info, irq_on); out: -- 1.8.3.1