Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2281480imm; Thu, 7 Jun 2018 08:08:39 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLmb7DZRcoS0yPIamss1nZU8CAHWEkIViICNaSdbHjDSa6Bpz9cR+v8cTx5TruuB3d/v9Nf X-Received: by 2002:a63:7a49:: with SMTP id j9-v6mr1885942pgn.353.1528384119044; Thu, 07 Jun 2018 08:08:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528384119; cv=none; d=google.com; s=arc-20160816; b=Cg2zlQcaDYWlQaZUZf13svuZifIu/kZ3PWxHBGMkE2DhOhIk4vUHDwnwgmw/xP7j+d V59y/aC9/Lkh392qExtQkR4joiUDLs//akFvDyVfHdnZQ+ME6yIa0a6NqNDIcQmE6FRW iKavnTnhLxqkKnXQYTWeSHjTaOlqqPvoubkHnxu4I4dU1wtyeGBewb9guhmL1d2S7wKE zlSIceYLl5PqZ5fr0g2nQKsbjs/sq9zA+I5pEx6kFzvGgJU+XVMS97xovgRwc1acU77I QHxkHrrtoMEBcHFLqhmo7QQQT34JbV+s/VMRqno3aqW0+ryBJOVwh/7vbyN3Z7jGCNoo Jang== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=H5IsO9zU7LiEgMZYLp1DhDb39vYv6d3aNWOmF+Dmd1s=; b=GrnQpBwYV5KVzJP9BZV068ugcsa8cjL2KgTPlWTmLlBZTRGoFb5mEdtiKNtyNlQs1D TXxrboIpJGofqZb5lU3WE2RCRbDF6Af4/Lid9cb/sWRA4dNY7Zs2yyhIDQXpP2XAx4s+ yttARkeWqcxB98nFFuyFx+JlClk1THlC3D5vcSN0FT425jb9S1z8945xCHkhcDfnIs9D ycs9nCJuVUqi3o90yn9yu4O0GckcUFoKBMaUBM6v0hvD8pZ5a9PNnFRFPmnmQoop/iGJ HSAH4INNYfREITRhcoRP8i+a3jf79jy/kzEQ9VFDE9h5SceITC+qck9j0H1SFQKcVGvf oddA== 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 d1-v6si22560463pln.471.2018.06.07.08.08.23; Thu, 07 Jun 2018 08:08:39 -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 S935888AbeFGPFo (ORCPT + 99 others); Thu, 7 Jun 2018 11:05:44 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:41570 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933405AbeFGPEH (ORCPT ); Thu, 7 Jun 2018 11:04:07 -0400 Received: from [148.252.241.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1fQvbb-0005hK-Jz; Thu, 07 Jun 2018 15:09:35 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvb8-00034a-4e; Thu, 07 Jun 2018 15:09:06 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, syzbot+d7a918a7a8e1c952bc36@syzkaller.appspotmail.com, "Yisheng Xie" , "Greg Kroah-Hartman" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 249/410] staging: android: ashmem: Fix possible deadlock in ashmem_ioctl In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.57-rc1 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 Signed-off-by: Greg Kroah-Hartman Signed-off-by: Ben Hutchings --- 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;