Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp336952pxk; Wed, 23 Sep 2020 04:46:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx2+INouRO/P8wVvnfY1jKhr8PL5bFCwldA14crUwgZeKQEvCfOAyOfVNQsxMJikkG8YfDg X-Received: by 2002:a17:906:b285:: with SMTP id q5mr9624768ejz.545.1600861567168; Wed, 23 Sep 2020 04:46:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600861567; cv=none; d=google.com; s=arc-20160816; b=v+W1aDzFSEia2iN+dBhYVepJo+50eFd2Fx2rKgLqeUJw/4K9ABwrOewJqlOgM5/xQ6 9ug4kEgmBSBXQcxCy/X2UKYUSOxaMUyTdpuBG+AN6J4tB8vs6xBXoFA5sKuKphUYYdUy Yi5iZtHlytPu3NoaulCCcZCk5v3hSRPvORn0OL7yXQw3xQRcVRsKknDKEZkIdBPvPFr0 kbN2P8FH3XYEm2FJXSkgDPrYjvRbpsQ5WSGO1E7Kvsr9JdJQph+djmVqxIlaWjY+aH8x 0gMjxcfKoU2puV/NSvhcXQwkIipeWngHW4v+e58Fji94/5CVBGqEvWsh8R2jxrO0mDTF z+hg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Yr5ceun1c0XjkFqzZiGqBJsZB++H8ShVuyzsBejSWgA=; b=vtEEUTxW0xKkCz8zXoiTW36ekpSWrMl09FhYJk4idJ2OtAIw2PltkFwypXUcVJGpRf QSajBds2ucKefOcr0jLlSzjvms3OXsoAV/vDePx/qLOnW90UenG7rWw2hfkBUKFDzvC4 w1XWqxIY0/mHO90UGhE4fJvfHxRqKTHcbFTLK5oBz4kpJfV1Mwb7cwc0ZMrzdhKaYqO7 b1jhz3asB71x9SW8sO3XxYEjWQUZ23twiypAZ3s8Huv0jyc9v+cf0uVPX7rhAgl/rHVw qmK0yX7xzPuA+6pa8uYw0uN/WUvbr1/7gTOkCQwmE3i6g0/b2nYgkUIYWU3BqYlWb5ZB 2XvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=1E+UfLc3; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cf14si12548984ejb.441.2020.09.23.04.45.44; Wed, 23 Sep 2020 04:46:07 -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=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=1E+UfLc3; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726574AbgIWLor (ORCPT + 99 others); Wed, 23 Sep 2020 07:44:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726500AbgIWLoq (ORCPT ); Wed, 23 Sep 2020 07:44:46 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67EB5C0613D2 for ; Wed, 23 Sep 2020 04:44:46 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id o25so9287033pgm.0 for ; Wed, 23 Sep 2020 04:44:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Yr5ceun1c0XjkFqzZiGqBJsZB++H8ShVuyzsBejSWgA=; b=1E+UfLc3ed9Nzd/69B6wR8oqAK1nzlpJras5WEGa4NXD+pmf9w9quHEfuDIKdnvWK2 /n4QHu4D1NR1buVZtglkdBJVR8vdsU1FrK0zCzWi1ayUNztSlnguwwCrSkN+/v0XSZpp N0Rdz6AAY6uMEhh+UZo1YFMLueR1fNBmSeuOOPjtLmyMXVwb8p89Q8OQOcgG/WYy5Vaj 3pEPyMeLIYeNzwS3SKPngJbUsYg1xxXZPdqALipIYd1lZlPcvdUFWiSgDolC6s3V46YQ i9QJuFMZFM3K9IRllLtMF3eYCwi3cUestYfcVC9QsRsdgZ/ImIva9aTUlMDDKQ9qD06G MESg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=Yr5ceun1c0XjkFqzZiGqBJsZB++H8ShVuyzsBejSWgA=; b=eN4+eoYes2I25J82moYXTLP+nh3uMypeZXmQHlqoHEoHRS1Mrog+9xy/FL0VEqFPYM gQw+TST46zB8+9U+DKsRRk+JC+qQf+atHZ87Th6nj7qhZqXzi+YK3iJd4hQBaIFsWzmO +7UqAh0IbEP613tLZf/mjqskg+s9qYth2Dd1yVaHXCdQ6DVumDHO6PQokhB9kNwchovj EOgU37bZ0klAnGL/5qsPHrTKeYigZ5Q1WG/UhZSAyMpMegxRzpnejVxHylE5VLAu4456 zb4u9cDsiEOUelhUv1bk0qVVp6bIX0iGGDj80vO8n8uadTmR0ZnVdq3Y+5qxhXQGHHMg e/OQ== X-Gm-Message-State: AOAM5329JRf48uvcf/hgIn1YsFSLz27Sxb7ir8ozjUzadP3Ma2GeqKf+ wsco7fwUujRFMgpOmKimpgJsEA== X-Received: by 2002:a63:1d5a:: with SMTP id d26mr7257874pgm.432.1600861485971; Wed, 23 Sep 2020 04:44:45 -0700 (PDT) Received: from Smcdef-MBP.local.net ([103.136.220.72]) by smtp.gmail.com with ESMTPSA id a13sm17632155pfl.184.2020.09.23.04.44.43 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Sep 2020 04:44:45 -0700 (PDT) From: Muchun Song To: axboe@kernel.dk, viro@zeniv.linux.org.uk Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, zhuyinyin@bytedance.com Subject: [PATCH v2 1/5] io_uring: Fix resource leaking when kill the process Date: Wed, 23 Sep 2020 19:44:15 +0800 Message-Id: <20200923114419.71218-2-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20200923114419.71218-1-songmuchun@bytedance.com> References: <20200923114419.71218-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yinyin Zhu The commit 1c4404efcf2c0> ("") doesn't solve the resource leak problem totally! When kworker is doing a io task for the io_uring, The process which submitted the io task has received a SIGKILL signal from the user. Then the io_cancel_async_work function could have sent a SIGINT signal to the kworker, but the judging condition is wrong. So it doesn't send a SIGINT signal to the kworker, then caused the resource leaking problem. Why the juding condition is wrong? The process is a multi-threaded process, we call the thread of the process which has submitted the io task Thread1. So the req->task is the current macro of the Thread1. when all the threads of the process have done exit procedure, the last thread will call the io_cancel_async_work, but the last thread may not the Thread1, so the task is not equal and doesn't send the SIGINT signal. To fix this bug, we alter the task attribute of the req with struct files_struct. And check the files instead. Fixes: 1c4404efcf2c0 ("io_uring: make sure async workqueue is canceled on exit") Signed-off-by: Yinyin Zhu --- fs/io_uring.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 454cef93a39e8..a1350c7c50055 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -339,7 +339,7 @@ struct io_kiocb { u64 user_data; u32 result; u32 sequence; - struct task_struct *task; + struct files_struct *files; struct fs_struct *fs; @@ -513,7 +513,7 @@ static inline void io_queue_async_work(struct io_ring_ctx *ctx, } } - req->task = current; + req->files = current->files; spin_lock_irqsave(&ctx->task_lock, flags); list_add(&req->task_list, &ctx->task_list); @@ -3717,7 +3717,7 @@ static int io_uring_fasync(int fd, struct file *file, int on) } static void io_cancel_async_work(struct io_ring_ctx *ctx, - struct task_struct *task) + struct files_struct *files) { if (list_empty(&ctx->task_list)) return; @@ -3729,7 +3729,7 @@ static void io_cancel_async_work(struct io_ring_ctx *ctx, req = list_first_entry(&ctx->task_list, struct io_kiocb, task_list); list_del_init(&req->task_list); req->flags |= REQ_F_CANCEL; - if (req->work_task && (!task || req->task == task)) + if (req->work_task && (!files || req->files == files)) send_sig(SIGINT, req->work_task, 1); } spin_unlock_irq(&ctx->task_lock); @@ -3754,7 +3754,7 @@ static int io_uring_flush(struct file *file, void *data) struct io_ring_ctx *ctx = file->private_data; if (fatal_signal_pending(current) || (current->flags & PF_EXITING)) - io_cancel_async_work(ctx, current); + io_cancel_async_work(ctx, data); return 0; } -- 2.11.0