Received: by 10.213.65.68 with SMTP id h4csp249377imn; Fri, 23 Mar 2018 03:55:34 -0700 (PDT) X-Google-Smtp-Source: AG47ELv5GE4fNlSQOOsEVGSFQc8dOa4VohWqbE57dIByMkDSU2tgkO1k+J/bE/yx4LEL9MjOpLT4 X-Received: by 10.99.60.6 with SMTP id j6mr20061498pga.73.1521802534288; Fri, 23 Mar 2018 03:55:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521802534; cv=none; d=google.com; s=arc-20160816; b=l2KxAj31l2XAL8lQu+ZTXnneLpTyHF2NChSWR2oEZkNMks9wym7MlFRoc6ESftgIVD jZbb2EwMXBwg/rqbzhpj7A2dV39hL3BkbW6yEw+XSBs6MkFUaAo0SJCpEACg78ncdxdH IZ2pdEpApJapbc0E4nI5LiKYk1sqh7fhhE2MZP/uf8bK57+z2LedhC39O00QIsUi4gw0 c8QR1VyJQL9139+LD5b10J+30aONsmESl8yNCxbg/m6nTbjQMjtE/pj9w3nojzYLC/6x 4IIU1RZc4OH9nE4mNR1FFUxGc5VTL8pEFBXW7QtYX/0bD16NAktmboB3fKoMWwdzMzs+ TZZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=ALjsDzKmvOKYRsFsNX+Gm6Rn9YleBzaF6iaJKr56b+M=; b=f07sM/hVM3VD5rRySpG3XPnXFiH7cGLIHfEue4MqETTjpZvOoXdOhFxs+PSScY3SEd G5qVH5a2gI+Jo3qJeNSaFQVdAglbIE0ycelC1IL4/ecjq9WHttDR8MDa4vfkZTpIMMt7 uTDnu1dfYX21HRb2e66Xb4KjtDBQV+gESonVKMrSj0ZEE4I7l1LusvCFiy1jVEQtRi4d HbcsbsfYnaO8QDtm39KwTv0F3AaX0unDRJAglJkmVPIMq4rGJOGZ0eNACNS58pBPCALZ +6pLHEtJ0s+5giTo/L0kQgQIgQMzM3W8M0K8BPFbAdV07ITP16PBKdhX5Th+DUYKm86k ykkQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id az5-v6si8038230plb.617.2018.03.23.03.55.19; Fri, 23 Mar 2018 03:55:34 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755886AbeCWKNb (ORCPT + 99 others); Fri, 23 Mar 2018 06:13:31 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:44816 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755860AbeCWKN2 (ORCPT ); Fri, 23 Mar 2018 06:13:28 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 6BCBC11EE; Fri, 23 Mar 2018 10:13:27 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+d7a918a7a8e1c952bc36@syzkaller.appspotmail.com, Yisheng Xie , "Joel Fernandes (Google)" Subject: [PATCH 4.4 05/97] staging: android: ashmem: Fix possible deadlock in ashmem_ioctl Date: Fri, 23 Mar 2018 10:53:52 +0100 Message-Id: <20180323094157.843632674@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180323094157.535925724@linuxfoundation.org> References: <20180323094157.535925724@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yisheng Xie commit 740a5759bf222332fbb5eda42f89aa25ba38f9b2 upstream. ashmem_mutex may create a chain of dependencies like: CPU0 CPU1 mmap syscall ioctl syscall -> mmap_sem (acquired) -> ashmem_ioctl -> ashmem_mmap -> ashmem_mutex (acquired) -> ashmem_mutex (try to acquire) -> copy_from_user -> mmap_sem (try to acquire) There is a lock odering problem between mmap_sem and ashmem_mutex causing a lockdep splat[1] during a syzcaller test. This patch fixes the problem by move copy_from_user out of ashmem_mutex. [1] https://www.spinics.net/lists/kernel/msg2733200.html Fixes: ce8a3a9e76d0 (staging: android: ashmem: Fix a race condition in pin ioctls) Reported-by: syzbot+d7a918a7a8e1c952bc36@syzkaller.appspotmail.com Signed-off-by: Yisheng Xie Cc: "Joel Fernandes (Google)" Signed-off-by: Greg Kroah-Hartman --- drivers/staging/android/ashmem.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) --- a/drivers/staging/android/ashmem.c +++ b/drivers/staging/android/ashmem.c @@ -703,16 +703,14 @@ static int ashmem_pin_unpin(struct ashme size_t pgstart, pgend; int ret = -EINVAL; + if (unlikely(copy_from_user(&pin, p, sizeof(pin)))) + return -EFAULT; + mutex_lock(&ashmem_mutex); if (unlikely(!asma->file)) goto out_unlock; - if (unlikely(copy_from_user(&pin, p, sizeof(pin)))) { - ret = -EFAULT; - goto out_unlock; - } - /* per custom, you can pass zero for len to mean "everything onward" */ if (!pin.len) pin.len = PAGE_ALIGN(asma->size) - pin.offset;