Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2931770ybk; Mon, 18 May 2020 11:24:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcn7S1qKGGZ0GG+erpTv9A2hij4kG+Pu3hiGUzwQZIRQspx1y7xICIUNoQQANHzzdPeCn9 X-Received: by 2002:aa7:d492:: with SMTP id b18mr15186561edr.28.1589826260626; Mon, 18 May 2020 11:24:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589826260; cv=none; d=google.com; s=arc-20160816; b=CWjEJKKglb6WnSXm4XW3+ye64URSsd7ZQhCXLCSK7+PT+iCPKysUvaBgXhw0CmNfUo 3mnMNNAEE8ElwGnAsJX4jwg6C6s6LYbBcXrb0NaxUzVOhv9aPy9MUsPOvp+fehx4YG+7 ppa+PaBZJD/r0NYWvEsa65BbrfKulPBnHB4E7M9hHo95R2JIdpnONN/lxks6fGD5vdx/ k2DbGFJgPG/xv6AoyuN/qrVy1iFOzCJrsARxWH92AuVxGFDsSAL+vXoxMJLXDlqwqepI V5vaBBPdXVDEBb+RmyyQXHxU0Sn4RKABLIVdj0a9XMAWzgAEnvUteFBBj66SqqphG//d +ijg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=GA7mBVh9ie/swwNu31IYOQUPTEHwVqrLDBnR5FG2S1I=; b=zxi7j/ck3U2sJvc5sPUFc05HDLpn7VLRfUru/Je/HSEX6nx/ThkQDkZnAADDeToxWA rJc6V2opq4MremFSxTOqUUKWCESdMzjBMI8W24ocvmXXcY7v3artDqvCq3vOoQAjbCAf 5z9TbbumjIgu2rFW/4eRFVuaXU7yeOzF0dU4K45UYBF46Pwc9VIn4648/+FaGmTnpU0t /fMkqTf5/S2RDObfFyimPnQ0KA4biUenGgkdU7Z2F7ysrvFQNyFV3DSMn9bbG3UWqZBp LssaJ49wkybfYrtxWYWGay6OvQeq0bFJCeuOOl/hmf+5uaidZxNUc6xHM/S++W93ry8C A3tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fsBpyGhM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dt5si5450929ejc.335.2020.05.18.11.23.56; Mon, 18 May 2020 11:24:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fsBpyGhM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730809AbgERRvF (ORCPT + 99 others); Mon, 18 May 2020 13:51:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:53382 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730768AbgERRu6 (ORCPT ); Mon, 18 May 2020 13:50:58 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 07342207C4; Mon, 18 May 2020 17:50:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589824257; bh=l42xB4oGlhaeR8PUztWRNqvqP554Gac2q5JPYzz4pVk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fsBpyGhMySQNvDGMZ2INmTu1rNIPRTxwCAyV2Yzq8P/rVBTWPCgh6hCLEWqeoh6e9 uRrIDch3E1Vuu8N/S99fVpTI1jqAMIBRk+ITX6xNfk5Ye4igiNGpgP+wauFRc1cT8G MA9A3PAjClctQoTn+j/YPEPmzU/GUI8AT5XNzAgA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+c8a8197c8852f566b9d9@syzkaller.appspotmail.com, syzbot+40b71e145e73f78f81ad@syzkaller.appspotmail.com, Hugh Dickins , Andrew Morton , Yang Shi , Linus Torvalds , Sasha Levin Subject: [PATCH 4.19 02/80] shmem: fix possible deadlocks on shmlock_user_lock Date: Mon, 18 May 2020 19:36:20 +0200 Message-Id: <20200518173450.633393924@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200518173450.097837707@linuxfoundation.org> References: <20200518173450.097837707@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hugh Dickins [ Upstream commit ea0dfeb4209b4eab954d6e00ed136bc6b48b380d ] Recent commit 71725ed10c40 ("mm: huge tmpfs: try to split_huge_page() when punching hole") has allowed syzkaller to probe deeper, uncovering a long-standing lockdep issue between the irq-unsafe shmlock_user_lock, the irq-safe xa_lock on mapping->i_pages, and shmem inode's info->lock which nests inside xa_lock (or tree_lock) since 4.8's shmem_uncharge(). user_shm_lock(), servicing SysV shmctl(SHM_LOCK), wants shmlock_user_lock while its caller shmem_lock() holds info->lock with interrupts disabled; but hugetlbfs_file_setup() calls user_shm_lock() with interrupts enabled, and might be interrupted by a writeback endio wanting xa_lock on i_pages. This may not risk an actual deadlock, since shmem inodes do not take part in writeback accounting, but there are several easy ways to avoid it. Requiring interrupts disabled for shmlock_user_lock would be easy, but it's a high-level global lock for which that seems inappropriate. Instead, recall that the use of info->lock to guard info->flags in shmem_lock() dates from pre-3.1 days, when races with SHMEM_PAGEIN and SHMEM_TRUNCATE could occur: nowadays it serves no purpose, the only flag added or removed is VM_LOCKED itself, and calls to shmem_lock() an inode are already serialized by the caller. Take info->lock out of the chain and the possibility of deadlock or lockdep warning goes away. Fixes: 4595ef88d136 ("shmem: make shmem_inode_info::lock irq-safe") Reported-by: syzbot+c8a8197c8852f566b9d9@syzkaller.appspotmail.com Reported-by: syzbot+40b71e145e73f78f81ad@syzkaller.appspotmail.com Signed-off-by: Hugh Dickins Signed-off-by: Andrew Morton Acked-by: Yang Shi Cc: Yang Shi Link: http://lkml.kernel.org/r/alpine.LSU.2.11.2004161707410.16322@eggly.anvils Link: https://lore.kernel.org/lkml/000000000000e5838c05a3152f53@google.com/ Link: https://lore.kernel.org/lkml/0000000000003712b305a331d3b1@google.com/ Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/shmem.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 0a2e1e7801d68..dea5120565d30 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2149,7 +2149,11 @@ int shmem_lock(struct file *file, int lock, struct user_struct *user) struct shmem_inode_info *info = SHMEM_I(inode); int retval = -ENOMEM; - spin_lock_irq(&info->lock); + /* + * What serializes the accesses to info->flags? + * ipc_lock_object() when called from shmctl_do_lock(), + * no serialization needed when called from shm_destroy(). + */ if (lock && !(info->flags & VM_LOCKED)) { if (!user_shm_lock(inode->i_size, user)) goto out_nomem; @@ -2164,7 +2168,6 @@ int shmem_lock(struct file *file, int lock, struct user_struct *user) retval = 0; out_nomem: - spin_unlock_irq(&info->lock); return retval; } -- 2.20.1