Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3405535pxf; Mon, 22 Mar 2021 05:50:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw8NfOOIa9KSDzFRMtq7v2udVtlBsLaGaL+0rj2MXxPmBN8/uNM6enF5OmzIFN5v54rwR2k X-Received: by 2002:a05:6402:145a:: with SMTP id d26mr25389424edx.182.1616417435712; Mon, 22 Mar 2021 05:50:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616417435; cv=none; d=google.com; s=arc-20160816; b=SHLyviZUvMcFH5uSXo5pgo2w90/nh1YY6UplpksgAP1wyTTElOflDAC1Zje1vz1w+i 30pZSgavqrBW4YSwmoUhoGyNUrD2iQ9IC6Du1maL8dvpp3NNZphykKqR7iA3WgzYDZeq yhR6QmS+Ejdff9uE8y6xdwTrS9Sl/zL0bmLfSXA9m9lnpfG+DiW4tkRRNy8XOsthR0L5 l8h7hk5qvBj5jgjryVz7acXozsSW+7DOxuq8cUB0MvooeSaW3n7QKzMvo8ojgC0CPAkt Twf0fT1zh9rupeaWjvnHOR6Aptig1CWTiSs9pqw+RRz6ZgMuSF7R0eL2TtZi+5o27uv7 yNqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9g9D+NUbIWP12aPrYfrRXL/MZRkT/OuwYe1y9g5rDEM=; b=eCVb+Kpm/A+E+oZJOPE+BPqCu+09xoirKbuZJABJzWSEkF4/ZAHmvjo+iKrD3nDSjH JZnwY10bpLc3C+f0bZyIS9oDbiVpHyW96TUo0g73Ra/GGgWc8aydqYj4OPC/2aMQyzNG gaM6onaXeEm6DAdSEdD7xW1tzR2QNkMs5OaJH52V7tyNxsRuMfdjZhw25HhkAZbFMyB0 moRWlgBfJ4kYQnrmw+WY5Ly+zlNLnC4qd1YW/pNWr7wqnKIawElOSuSBiiZQZKZ3ypy2 Lm2YP3mQwui3W+gl095sBQ2YgH4Fs3DkQ3ph8I7lU1IPIN7iH5NmqjPbusFL2MZhGhqN tVAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ObQiOg0P; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v3si11284589edr.497.2021.03.22.05.50.13; Mon, 22 Mar 2021 05:50:35 -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=@linuxfoundation.org header.s=korg header.b=ObQiOg0P; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231536AbhCVMsf (ORCPT + 99 others); Mon, 22 Mar 2021 08:48:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:58776 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232063AbhCVMkL (ORCPT ); Mon, 22 Mar 2021 08:40:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 56C5A6188B; Mon, 22 Mar 2021 12:38:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1616416731; bh=ZEtzDDbnh3c/hw/gbw38AJehE2J3aSW+9X5J2FREbdk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ObQiOg0PzTsqShgxFscfd/pHcMSfBB3M+HVhIXdKyWazR7xahcWJfkwHPkSRla6zg LNGY20u6kX+V08cc0UzzSNss1xoPD4HFsube8nA8L5qF5Ack0Hgm/dFrMaFkfLi614 blX082/TrocdWpiQltIfUYUrWPbrq7MSm7b1epp8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+81d17233a2b02eafba33@syzkaller.appspotmail.com, Pavel Begunkov , Jens Axboe , Sasha Levin Subject: [PATCH 5.10 098/157] io_uring: fix inconsistent lock state Date: Mon, 22 Mar 2021 13:27:35 +0100 Message-Id: <20210322121936.884364967@linuxfoundation.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210322121933.746237845@linuxfoundation.org> References: <20210322121933.746237845@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pavel Begunkov [ Upstream commit 9ae1f8dd372e0e4c020b345cf9e09f519265e981 ] WARNING: inconsistent lock state inconsistent {HARDIRQ-ON-W} -> {IN-HARDIRQ-W} usage. syz-executor217/8450 [HC1[1]:SC0[0]:HE0:SE1] takes: ffff888023d6e620 (&fs->lock){?.+.}-{2:2}, at: spin_lock include/linux/spinlock.h:354 [inline] ffff888023d6e620 (&fs->lock){?.+.}-{2:2}, at: io_req_clean_work fs/io_uring.c:1398 [inline] ffff888023d6e620 (&fs->lock){?.+.}-{2:2}, at: io_dismantle_req+0x66f/0xf60 fs/io_uring.c:2029 other info that might help us debug this: Possible unsafe locking scenario: CPU0 ---- lock(&fs->lock); lock(&fs->lock); *** DEADLOCK *** 1 lock held by syz-executor217/8450: #0: ffff88802417c3e8 (&ctx->uring_lock){+.+.}-{3:3}, at: __do_sys_io_uring_enter+0x1071/0x1f30 fs/io_uring.c:9442 stack backtrace: CPU: 1 PID: 8450 Comm: syz-executor217 Not tainted 5.11.0-rc5-next-20210129-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Call Trace: [...] _raw_spin_lock+0x2a/0x40 kernel/locking/spinlock.c:151 spin_lock include/linux/spinlock.h:354 [inline] io_req_clean_work fs/io_uring.c:1398 [inline] io_dismantle_req+0x66f/0xf60 fs/io_uring.c:2029 __io_free_req+0x3d/0x2e0 fs/io_uring.c:2046 io_free_req fs/io_uring.c:2269 [inline] io_double_put_req fs/io_uring.c:2392 [inline] io_put_req+0xf9/0x570 fs/io_uring.c:2388 io_link_timeout_fn+0x30c/0x480 fs/io_uring.c:6497 __run_hrtimer kernel/time/hrtimer.c:1519 [inline] __hrtimer_run_queues+0x609/0xe40 kernel/time/hrtimer.c:1583 hrtimer_interrupt+0x334/0x940 kernel/time/hrtimer.c:1645 local_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1085 [inline] __sysvec_apic_timer_interrupt+0x146/0x540 arch/x86/kernel/apic/apic.c:1102 asm_call_irq_on_stack+0xf/0x20 __run_sysvec_on_irqstack arch/x86/include/asm/irq_stack.h:37 [inline] run_sysvec_on_irqstack_cond arch/x86/include/asm/irq_stack.h:89 [inline] sysvec_apic_timer_interrupt+0xbd/0x100 arch/x86/kernel/apic/apic.c:1096 asm_sysvec_apic_timer_interrupt+0x12/0x20 arch/x86/include/asm/idtentry.h:629 RIP: 0010:__raw_spin_unlock_irq include/linux/spinlock_api_smp.h:169 [inline] RIP: 0010:_raw_spin_unlock_irq+0x25/0x40 kernel/locking/spinlock.c:199 spin_unlock_irq include/linux/spinlock.h:404 [inline] io_queue_linked_timeout+0x194/0x1f0 fs/io_uring.c:6525 __io_queue_sqe+0x328/0x1290 fs/io_uring.c:6594 io_queue_sqe+0x631/0x10d0 fs/io_uring.c:6639 io_queue_link_head fs/io_uring.c:6650 [inline] io_submit_sqe fs/io_uring.c:6697 [inline] io_submit_sqes+0x19b5/0x2720 fs/io_uring.c:6960 __do_sys_io_uring_enter+0x107d/0x1f30 fs/io_uring.c:9443 do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46 entry_SYSCALL_64_after_hwframe+0x44/0xa9 Don't free requests from under hrtimer context (softirq) as it may sleep or take spinlocks improperly (e.g. non-irq versions). Cc: stable@vger.kernel.org # 5.6+ Reported-by: syzbot+81d17233a2b02eafba33@syzkaller.appspotmail.com Signed-off-by: Pavel Begunkov Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- fs/io_uring.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index dcc77af5320e..5746998799ab 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -6234,9 +6234,10 @@ static enum hrtimer_restart io_link_timeout_fn(struct hrtimer *timer) if (prev) { req_set_fail_links(prev); io_async_find_and_cancel(ctx, req, prev->user_data, -ETIME); - io_put_req(prev); + io_put_req_deferred(prev, 1); } else { - io_req_complete(req, -ETIME); + io_cqring_add_event(req, -ETIME, 0); + io_put_req_deferred(req, 1); } return HRTIMER_NORESTART; } -- 2.30.1