Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2308414imm; Thu, 7 Jun 2018 08:32:34 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIbfJW515WOVBelJE9qfXR1ibFmnFd2sKc6mxkyOvUZKCqvTTRoxUrqW+tg99vJ5gBGYcdg X-Received: by 2002:a17:902:26a:: with SMTP id 97-v6mr2537198plc.367.1528385554420; Thu, 07 Jun 2018 08:32:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528385554; cv=none; d=google.com; s=arc-20160816; b=MWQyMoEJP3rhTi6NB35RfbAry+Wd7UT1y+gy/064yfWJJRAaXF0wsxuJnlKOg3LXih uWxIehVQkTjmizs5XIMTMeeSKWXc3foBnGr1qFBpf6jWinQp0ecEEKxH8771+UQ/0P+s xuDL9EgD/Fxf0BHDnmnrxyzw4++gfIm4Yr3CqrLZ51WbGxYZVBknKb5yntmCvksJwARF qX846j+nOLjFu3IspVt9HqGSoSSt6ZX6yFvNeqLEDOLy7+VM3GTioDL2/Kr8LEW6ljpX Iszk0+qAXSkeIbW6J9kxEmveFhjgWL6r+3r1olmQs2k7q6HRhRG7MxCgFlJYQDPypVim cEdw== 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=4Fk3TiLF548lr2xNTwo8D8xM1wZ1Dnt0N+J8T4DmMJM=; b=DSYgeILoN+dBCV5xy5/2GbtkcP4pmxPamjx2AVWfKA9qavVvI7Qrhouaxd2UYysegN /Mk3AxM2Xfk8od2XRCa6GKTnOhLOy87aop7cUuwXmNTMPD3S6P96PXAiVCgzKWjPbIDx S7r/eEmt2JEC3QWSdp+GgSgME+pJ9OCvs34lYFNN+lFUyocPYj3BKfk3AeMuu106V5+w GemDULu6kCPnMYKJCyFNap5nrVsnhejgQWxturrAzHF/o4gyLmAW/Ox8QbGOqMJX/34e IOMKYWvBJLafKBLUhz1PgR2j73Y7eswthGPnCE3mGrqcLM+dI9GA1zxwT3QDaGq3zv/R kc8w== 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 u2-v6si32313781plr.598.2018.06.07.08.32.19; Thu, 07 Jun 2018 08:32: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 S935321AbeFGOyD (ORCPT + 99 others); Thu, 7 Jun 2018 10:54:03 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:40966 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935307AbeFGOyA (ORCPT ); Thu, 7 Jun 2018 10:54:00 -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 1fQvbU-0005Zq-Bp; Thu, 07 Jun 2018 15:09:28 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvbB-0003Ay-58; Thu, 07 Jun 2018 15:09:09 +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, "Greg Hackmann" , "Arve Hjonnevag" , "Todd Kjos" , "Joel Fernandes" , "Greg Kroah-Hartman" , syzbot+8ec30bb7bf1a981a2012@syzkaller.appspotmail.com Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 316/410] staging: android: ashmem: Fix lockdep issue during llseek 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: Joel Fernandes commit cb57469c9573f6018cd1302953dd45d6e05aba7b upstream. ashmem_mutex create a chain of dependencies like so: (1) mmap syscall -> mmap_sem -> (acquired) ashmem_mmap ashmem_mutex (try to acquire) (block) (2) llseek syscall -> ashmem_llseek -> ashmem_mutex -> (acquired) inode_lock -> inode->i_rwsem (try to acquire) (block) (3) getdents -> iterate_dir -> inode_lock -> inode->i_rwsem (acquired) copy_to_user -> mmap_sem (try to acquire) There is a lock ordering created between mmap_sem and inode->i_rwsem causing a lockdep splat [2] during a syzcaller test, this patch fixes the issue by unlocking the mutex earlier. Functionally that's Ok since we don't need to protect vfs_llseek. [1] https://patchwork.kernel.org/patch/10185031/ [2] https://lkml.org/lkml/2018/1/10/48 Acked-by: Todd Kjos Cc: Arve Hjonnevag Reported-by: syzbot+8ec30bb7bf1a981a2012@syzkaller.appspotmail.com Signed-off-by: Joel Fernandes Acked-by: Greg Hackmann Signed-off-by: Greg Kroah-Hartman [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- drivers/staging/android/ashmem.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) --- a/drivers/staging/android/ashmem.c +++ b/drivers/staging/android/ashmem.c @@ -330,24 +330,23 @@ static loff_t ashmem_llseek(struct file mutex_lock(&ashmem_mutex); if (asma->size == 0) { - ret = -EINVAL; - goto out; + mutex_unlock(&ashmem_mutex); + return -EINVAL; } if (!asma->file) { - ret = -EBADF; - goto out; + mutex_unlock(&ashmem_mutex); + return -EBADF; } + mutex_unlock(&ashmem_mutex); + ret = asma->file->f_op->llseek(asma->file, offset, origin); if (ret < 0) - goto out; + return ret; /** Copy f_pos from backing file, since f_ops->llseek() sets it */ file->f_pos = asma->file->f_pos; - -out: - mutex_unlock(&ashmem_mutex); return ret; }