Received: by 10.223.185.116 with SMTP id b49csp5544281wrg; Wed, 7 Mar 2018 13:42:30 -0800 (PST) X-Google-Smtp-Source: AG47ELvL99PmoN4URBzH8MoVZB+zsgQ8sOqyPz9c4XcK3gXuS4+Mp34O6BF8T0poxlv8RnxRUISF X-Received: by 2002:a17:902:8f97:: with SMTP id z23-v6mr21835135plo.162.1520458950256; Wed, 07 Mar 2018 13:42:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520458950; cv=none; d=google.com; s=arc-20160816; b=kBrI1PX68GjKXxYwLcy09MbLrk0WUFdwRBuMXcVhW574Jghr7kIOdC8Y4y99jPG+Ff n6rqUGZGq6ntXl2lK9dh28qMZNlw09qsSUnzDrBcVzV5lLEW1dkRGzs38WH7mpM8804h mFstjtVbFH1ImZBX2x3bL4tfqSzD0BW0wQCirBNnkb8xC+nrUBEVRZtEK5w3t2mswjiC XG+DOsZe1046YgTVvydoaRobFE703e+ypwuWIitwP3MscncDszhTA+8qOP4zNcwrCl8f 14LtF6tu57fWFX1+XlKVPxcgxeZB6qpEFaiHCSxzl5+n6/U7DTY2Bx1Bp3zfpffr3O9x O1+w== 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 :dkim-signature:arc-authentication-results; bh=u4Vhm/eZ+riIyfjjPrRuoBA80Cv/bPWVvRfrRQPJIoM=; b=Nn+CztYfrKV473XircojdVgx/Q67mzB7Oyhp+5JSjRV/NtfkjwxafsAkeY5+OXMLPK AQC5h6r+xd9Wwqx+DCnXIsjiOChp4RoE2Kb9I95Mm1ZN37aOO8v8vrZPumr1RyGXpBOu O03vGRQvlfuHHWR6CTZ9Sq9BMomriRd0IE+aZS8kQiKXd1V7rD2ShschU9zySe2GphoA QKjWjCFSDc6B6Rd8K6qetBzYbRD0bz3dhBpO7OdFplgrEdr5PRL07hGsnv5dwvv/ieW9 F9k3ZvI+s7avtfThbnF7GHYtP2M6lIVWS9Y5sXaOnsuLC4R9WTFfAq5yahAnGlcqLWGn E39A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=mWuU5wTX; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3-v6si11774427pla.678.2018.03.07.13.42.16; Wed, 07 Mar 2018 13:42:30 -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=@google.com header.s=20161025 header.b=mWuU5wTX; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754867AbeCGVkx (ORCPT + 99 others); Wed, 7 Mar 2018 16:40:53 -0500 Received: from mail-pl0-f67.google.com ([209.85.160.67]:34827 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754745AbeCGVkv (ORCPT ); Wed, 7 Mar 2018 16:40:51 -0500 Received: by mail-pl0-f67.google.com with SMTP id w22-v6so2115790pll.2 for ; Wed, 07 Mar 2018 13:40:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=u4Vhm/eZ+riIyfjjPrRuoBA80Cv/bPWVvRfrRQPJIoM=; b=mWuU5wTXNhh+22BFM0hpw6QPrLh0xdOZH9JLnwMcYzriZr5n87QAlKYGjtgwKycVnk 0x8Gu9JVd8/spuNaQf3eMSLxSiWdEkIVjJgoizz6cSmarmaIUR3JlgRBYZPQ+229zVwX e1doJ5pITx3cf4DdRBDEh1s8kFiamDoX8dgYWSoX2hFnblHqZTvtJGzUEs90wLivMIUu 5GcTLsL1e8NbHnnLQKonF8QxAyxnttrhaAYwO5EeIAsR3exUo4MHb8OcLpMMTZkfbiBg QPUGvGcqyKWTsF4PkdyKD9UPsY7hMYIxzQKCdG3ApkppQu5Ub68USugYetXXmFmvn2Kv 0upA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=u4Vhm/eZ+riIyfjjPrRuoBA80Cv/bPWVvRfrRQPJIoM=; b=IUg4cdCy/5roJPwSoj0tHtvG3bN10t/ll6Mqd5/4V8UEjhZwJhOc1XL0xObkoS00Am rJQBA5fS6/7MfSvRXaJDJ8iHOszyIpZ1VWawHzg11JZ93oSNYav+ZXfyVTKN+m3UYATn IwNzlkMrWy88VByE+eqgNgZMke4BkZ2DXVDH4ZL3ke+N+OyotCB1YuAVt0VvogifIBlr P8l9fH9l/2WbENH5b0OB+rZDoNHcz/ya999YOUlYaJjAlZOaxADKb7qMAbiMy5W9qgck GIBVjHt1FkVx+sHphuZ7vMSLx79H6lEbOupzY6pXWaCZBNtpq0n6zvaAEub7lO9qdFA8 48oA== X-Gm-Message-State: APf1xPADGJoG/W4Z6MPy6h8qDCqYBFFRGUS3lskU/azVbm+R6jLBKWA7 df99wzSLOHgz93dGd0meOIUPhqGL8/M= X-Received: by 2002:a17:902:aa83:: with SMTP id d3-v6mr21519291plr.36.1520458850551; Wed, 07 Mar 2018 13:40:50 -0800 (PST) Received: from paullawrence.mtv.corp.google.com ([2620:0:1000:1601:fdd6:ccc8:df14:d6cd]) by smtp.gmail.com with ESMTPSA id h10sm22643571pgf.19.2018.03.07.13.40.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Mar 2018 13:40:49 -0800 (PST) From: Paul Lawrence To: linux-kernel@vger.kernel.org Cc: Paul Lawrence , stable@vger.kernel.org, Ben Hutchings , Greg Kroah-Hartman , =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Martijn Coenen , devel@driverdev.osuosl.org Subject: [PATCH] staging: android: ashmem: Remove deadlock Date: Wed, 7 Mar 2018 13:40:30 -0800 Message-Id: <20180307214042.135109-1-paullawrence@google.com> X-Mailer: git-send-email 2.16.2.395.g2e18187dfd-goog Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Regression introduced in commit ce8a3a9e76d0193e2e8d74a06d275b3c324ca652 ("staging: android: ashmem: Fix a race condition in pin ioctls") causing deadlock. No need to hold ashmem_mutex while copying from user Stacks are: ashmem_mmap+0x53/0x400 drivers/staging/android/ashmem.c:379 mmap_region+0x7dd/0xfd0 mm/mmap.c:1694 do_mmap+0x57b/0xbe0 mm/mmap.c:1473 and lock_acquire+0x12e/0x410 kernel/locking/lockdep.c:3756 __might_fault+0x14a/0x1d0 mm/memory.c:4014 copy_from_user arch/x86/include/asm/uaccess.h:705 [inline] ashmem_pin_unpin drivers/staging/android/ashmem.c:719 [inline] Signed-off-by: Paul Lawrence Cc: # 4.9.x Cc: # 4.4.x Cc: # 3.18.x: ce8a3a9e76d01 Cc: # 3.18.x Cc: Ben Hutchings --- drivers/staging/android/ashmem.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c index 6dbba5aff191..8c55706c2cfa 100644 --- a/drivers/staging/android/ashmem.c +++ b/drivers/staging/android/ashmem.c @@ -702,16 +702,14 @@ static int ashmem_pin_unpin(struct ashmem_area *asma, unsigned long cmd, 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; -- 2.16.2.395.g2e18187dfd-goog