From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.4 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76F15C433E9 for ; Mon, 18 Jan 2021 16:52:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4D17D222BB for ; Mon, 18 Jan 2021 16:52:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405905AbhARQww (ORCPT ); Mon, 18 Jan 2021 11:52:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405492AbhARPMf (ORCPT ); Mon, 18 Jan 2021 10:12:35 -0500 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36E39C061573 for ; Mon, 18 Jan 2021 07:11:54 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id j18so2911775wmi.3 for ; Mon, 18 Jan 2021 07:11:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:references:autocrypt:subject:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=GOmbV8+L6/e88bzFo5oJ8ttOHkwh41s7X8e8VSWJaNA=; b=bS7OG9W4Fa0iE4N6A9KohTCjauW5cG839K0+A2NHAWhOCp0JVPaEHnGx0RwE9RdnB8 n+o5wdRSaOrKz7EDrGG4WXMDtwHiZcMMbUJFseMzBC6X9BCEqcIUsCDX81/emduac8DP URDQhI+8D4toIOiql+6aAms7USQbPZbasZJ4wJGC4tlFc/kZTyD6jx69DAyUeL9AoALr 3SWWdImextabr8hOYbQtyGxc4Dti/G9yN9i0PTRT2E+l2OShwJ7OLjv/fct5pAt89uDh O8OkDa6q30SIZRqA3HK/3ytSQgiUI0BxrxqgvueHCMtKodLZe8n5sqsuGFuuWl3Ogumt wOQg== 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:references:autocrypt:subject :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=GOmbV8+L6/e88bzFo5oJ8ttOHkwh41s7X8e8VSWJaNA=; b=HnHc3gW58ZkN9iApwLoE+CApW7kc+5YvZWOprUJyK6uib5nDyVhU3IH8uPtdNpKrql lsoOt45LS8fvsl/fB8Pwzs5yXHBL9fcjwER0eAJ3hmz+nz4FclqFEP6LoTWnPHvGBjUC DI0amaRS4KvtYx65a1hTh+1xvBWB3q5W1zbOSbiFgQNDYstEYWXEZfvSB2Osi4N9J2xf jNA47vnToMEvsc+Swaw+8wVzc63FhMzWgFOoJxqtzZC+isCgao77yXHVT2+9wQrJEj7b 0x7WveTq3mq49t7qvPhIPFT/A5AvTkdiDr3xT4EMQaNnmDDik8gBbin3Fh/llq6SXkx9 3vSw== X-Gm-Message-State: AOAM5307PjJGqmQIRqWSjLktaWq1A+GH76yreROlsJYYTdJHfVBvZlWi KUwWrWUmHOUUrfQrTa/6u4H5tBsjmWBW/Q== X-Google-Smtp-Source: ABdhPJwWE7iUmoErSD7SxMFO6fSaxUxpiTdG7vyP5wE1S1MomoG1sSh1UnrNNSRDjDzYys35+/CWkA== X-Received: by 2002:a1c:7f8c:: with SMTP id a134mr21366086wmd.184.1610982712965; Mon, 18 Jan 2021 07:11:52 -0800 (PST) Received: from [192.168.8.130] ([85.255.234.152]) by smtp.gmail.com with ESMTPSA id l7sm22584463wmg.41.2021.01.18.07.11.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 Jan 2021 07:11:52 -0800 (PST) From: Pavel Begunkov To: Joseph Qi , Jens Axboe Cc: io-uring@vger.kernel.org, Xiaoguang Wang References: <1610963424-27129-1-git-send-email-joseph.qi@linux.alibaba.com> <4f1a8b42-8440-0e9a-ca01-497ccd438b56@gmail.com> Autocrypt: addr=asml.silence@gmail.com; prefer-encrypt=mutual; keydata= mQINBFmKBOQBEAC76ZFxLAKpDw0bKQ8CEiYJRGn8MHTUhURL02/7n1t0HkKQx2K1fCXClbps bdwSHrhOWdW61pmfMbDYbTj6ZvGRvhoLWfGkzujB2wjNcbNTXIoOzJEGISHaPf6E2IQx1ik9 6uqVkK1OMb7qRvKH0i7HYP4WJzYbEWVyLiAxUj611mC9tgd73oqZ2pLYzGTqF2j6a/obaqha +hXuWTvpDQXqcOZJXIW43atprH03G1tQs7VwR21Q1eq6Yvy2ESLdc38EqCszBfQRMmKy+cfp W3U9Mb1w0L680pXrONcnlDBCN7/sghGeMHjGKfNANjPc+0hzz3rApPxpoE7HC1uRiwC4et83 CKnncH1l7zgeBT9Oa3qEiBlaa1ZCBqrA4dY+z5fWJYjMpwI1SNp37RtF8fKXbKQg+JuUjAa9 Y6oXeyEvDHMyJYMcinl6xCqCBAXPHnHmawkMMgjr3BBRzODmMr+CPVvnYe7BFYfoajzqzq+h EyXSl3aBf0IDPTqSUrhbmjj5OEOYgRW5p+mdYtY1cXeK8copmd+fd/eTkghok5li58AojCba jRjp7zVOLOjDlpxxiKhuFmpV4yWNh5JJaTbwCRSd04sCcDNlJj+TehTr+o1QiORzc2t+N5iJ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iq4ooeb5VkQ7UZxbCWt UVMKkOCdFhutRmYp0mbv2e87IK4erwNHQRkHUkzbsuym8RVpAZbLzLPIYK/J3RTErL6Z99N2 m3J6pjwSJY/zNwuFPs9zGEnRO4g0BUbwGdbuvDzaq6/3OJLKohr5eLXNU3JkT+3HezydWm3W OPhauth7W0db74Qd49HXK0xe/aPrK+Cp+kU1HRactyNtF8jZQbhMCC8vMGukZtWaAwpjWiiH bA== Subject: Re: [PATCH] io_uring: fix NULL pointer dereference for async cancel close Message-ID: Date: Mon, 18 Jan 2021 15:08:15 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.3.0 MIME-Version: 1.0 In-Reply-To: <4f1a8b42-8440-0e9a-ca01-497ccd438b56@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org On 18/01/2021 12:23, Pavel Begunkov wrote: > On 18/01/2021 09:50, Joseph Qi wrote: >> Abaci reported the following crash: >> >> [ 31.252589] BUG: kernel NULL pointer dereference, address: 00000000000000d8 >> [ 31.253942] #PF: supervisor read access in kernel mode >> [ 31.254945] #PF: error_code(0x0000) - not-present page >> [ 31.255964] PGD 800000010b76f067 P4D 800000010b76f067 PUD 10b462067 PMD 0 >> [ 31.257221] Oops: 0000 [#1] SMP PTI >> [ 31.257923] CPU: 1 PID: 1788 Comm: io_uring-sq Not tainted 5.11.0-rc4 #1 >> [ 31.259175] Hardware name: Red Hat KVM, BIOS 0.5.1 01/01/2011 >> [ 31.260232] RIP: 0010:__lock_acquire+0x19d/0x18c0 >> [ 31.261144] Code: 00 00 8b 1d fd 56 dd 08 85 db 0f 85 43 05 00 00 48 c7 c6 98 7b 95 82 48 c7 c7 57 96 93 82 e8 9a bc f5 ff 0f 0b e9 2b 05 00 00 <48> 81 3f c0 ca 67 8a b8 00 00 00 00 41 0f 45 c0 89 04 24 e9 81 fe >> [ 31.264297] RSP: 0018:ffffc90001933828 EFLAGS: 00010002 >> [ 31.265320] RAX: 0000000000000001 RBX: 0000000000000001 RCX: 0000000000000000 >> [ 31.266594] RDX: 0000000000000000 RSI: 0000000000000000 RDI: 00000000000000d8 >> [ 31.267922] RBP: 0000000000000246 R08: 0000000000000001 R09: 0000000000000000 >> [ 31.269262] R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000 >> [ 31.270550] R13: 0000000000000000 R14: ffff888106e8a140 R15: 00000000000000d8 >> [ 31.271760] FS: 0000000000000000(0000) GS:ffff88813bd00000(0000) knlGS:0000000000000000 >> [ 31.273269] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 >> [ 31.274330] CR2: 00000000000000d8 CR3: 0000000106efa004 CR4: 00000000003706e0 >> [ 31.275613] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 >> [ 31.276855] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 >> [ 31.278065] Call Trace: >> [ 31.278649] lock_acquire+0x31a/0x440 >> [ 31.279404] ? close_fd_get_file+0x39/0x160 >> [ 31.280276] ? __lock_acquire+0x647/0x18c0 >> [ 31.281112] _raw_spin_lock+0x2c/0x40 >> [ 31.281821] ? close_fd_get_file+0x39/0x160 >> [ 31.282586] close_fd_get_file+0x39/0x160 >> [ 31.283338] io_issue_sqe+0x1334/0x14e0 >> [ 31.284053] ? lock_acquire+0x31a/0x440 >> [ 31.284763] ? __io_free_req+0xcf/0x2e0 >> [ 31.285504] ? __io_free_req+0x175/0x2e0 >> [ 31.286247] ? find_held_lock+0x28/0xb0 >> [ 31.286968] ? io_wq_submit_work+0x7f/0x240 >> [ 31.287733] io_wq_submit_work+0x7f/0x240 >> [ 31.288486] io_wq_cancel_cb+0x161/0x580 >> [ 31.289230] ? io_wqe_wake_worker+0x114/0x360 >> [ 31.290020] ? io_uring_get_socket+0x40/0x40 >> [ 31.290832] io_async_find_and_cancel+0x3b/0x140 >> [ 31.291676] io_issue_sqe+0xbe1/0x14e0 >> [ 31.292405] ? __lock_acquire+0x647/0x18c0 >> [ 31.293207] ? __io_queue_sqe+0x10b/0x5f0 >> [ 31.293986] __io_queue_sqe+0x10b/0x5f0 >> [ 31.294747] ? io_req_prep+0xdb/0x1150 >> [ 31.295485] ? mark_held_locks+0x6d/0xb0 >> [ 31.296252] ? mark_held_locks+0x6d/0xb0 >> [ 31.297019] ? io_queue_sqe+0x235/0x4b0 >> [ 31.297774] io_queue_sqe+0x235/0x4b0 >> [ 31.298496] io_submit_sqes+0xd7e/0x12a0 >> [ 31.299275] ? _raw_spin_unlock_irq+0x24/0x30 >> [ 31.300121] ? io_sq_thread+0x3ae/0x940 >> [ 31.300873] io_sq_thread+0x207/0x940 >> [ 31.301606] ? do_wait_intr_irq+0xc0/0xc0 >> [ 31.302396] ? __ia32_sys_io_uring_enter+0x650/0x650 >> [ 31.303321] kthread+0x134/0x180 >> [ 31.303982] ? kthread_create_worker_on_cpu+0x90/0x90 >> [ 31.304886] ret_from_fork+0x1f/0x30 >> >> This is caused by NULL files when async cancel close, which has >> IO_WQ_WORK_NO_CANCEL set and continue to do work. Fix it by also setting >> needs_files for IORING_OP_ASYNC_CANCEL. > > Looks good enough for a quick late-rc fix, > Reviewed-by: Pavel Begunkov Hmm, I hastened, for files we need IO_WQ_WORK_FILES, +IO_WQ_WORK_BLKCG for same reasons. needs_file would make it to grab a struct file, that is wrong. Probably worked out because it just grabbed fd=0/stdin. > > But we need need to rework this NO_CANCEL case for the future. A > reproducer would help much, do you have one? Or even better a liburing > test? > >> >> Reported-by: Abaci >> Cc: stable@vger.kernel.org # 5.6+ >> Signed-off-by: Joseph Qi >> --- >> fs/io_uring.c | 5 ++++- >> 1 file changed, 4 insertions(+), 1 deletion(-) >> >> diff --git a/fs/io_uring.c b/fs/io_uring.c >> index 985a9e3..8eb1349 100644 >> --- a/fs/io_uring.c >> +++ b/fs/io_uring.c >> @@ -883,7 +883,10 @@ struct io_op_def { >> .pollin = 1, >> .work_flags = IO_WQ_WORK_MM | IO_WQ_WORK_FILES, >> }, >> - [IORING_OP_ASYNC_CANCEL] = {}, >> + [IORING_OP_ASYNC_CANCEL] = { >> + /* for async cancel close */ >> + .needs_file = 1, >> + }, >> [IORING_OP_LINK_TIMEOUT] = { >> .needs_async_data = 1, >> .async_size = sizeof(struct io_timeout_data), >> > -- Pavel Begunkov