From patchwork Sun Aug 22 21:05:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivier Langlois X-Patchwork-Id: 12451693 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=-13.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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 16D6DC4320E for ; Sun, 22 Aug 2021 21:05:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E15126128A for ; Sun, 22 Aug 2021 21:05:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233180AbhHVVGg (ORCPT ); Sun, 22 Aug 2021 17:06:36 -0400 Received: from cloud48395.mywhc.ca ([173.209.37.211]:36180 "EHLO cloud48395.mywhc.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232539AbhHVVGf (ORCPT ); Sun, 22 Aug 2021 17:06:35 -0400 Received: from modemcable064.203-130-66.mc.videotron.ca ([66.130.203.64]:52708 helo=localhost) by cloud48395.mywhc.ca with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mHufA-0001rP-JR; Sun, 22 Aug 2021 17:05:52 -0400 Date: Sun, 22 Aug 2021 17:05:51 -0400 Message-Id: <5eee1da51b7aaac3f55d6923e96182012b00deaa.1629655338.git.olivier@trillion01.com> In-Reply-To: References: From: Olivier Langlois To: Jens Axboe , Pavel Begunkov , Oleg Nesterov , Steven Rostedt , Ingo Molnar , "Eric W. Biederman" , io-uring@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] tracehook: Add a return value to tracehook_notify_signal X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - cloud48395.mywhc.ca X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - trillion01.com X-Get-Message-Sender-Via: cloud48395.mywhc.ca: authenticated_id: olivier@trillion01.com X-Authenticated-Sender: cloud48395.mywhc.ca: olivier@trillion01.com X-Source: X-Source-Args: X-Source-Dir: Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The return value indicates if task_work_run has been called. This knowledge can be of value to the caller. In particular, it allows io_uring to easily replace calls to io_run_task_work with tracehook_notify_signal when clearing TIF_NOTIFY_SIGNAL is needed. Signed-off-by: Olivier Langlois --- include/linux/tracehook.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h index 3e80c4bc66f7..1f778ed9c6e2 100644 --- a/include/linux/tracehook.h +++ b/include/linux/tracehook.h @@ -204,12 +204,16 @@ static inline void tracehook_notify_resume(struct pt_regs *regs) * is currently used by TWA_SIGNAL based task_work, which requires breaking * wait loops to ensure that task_work is noticed and run. */ -static inline void tracehook_notify_signal(void) +static inline bool tracehook_notify_signal(void) { + bool ret; + clear_thread_flag(TIF_NOTIFY_SIGNAL); smp_mb__after_atomic(); - if (current->task_works) + ret = current->task_works; + if (ret) task_work_run(); + return ret; } /* From patchwork Sun Aug 22 21:05:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivier Langlois X-Patchwork-Id: 12451695 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=-13.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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 ED231C4320A for ; Sun, 22 Aug 2021 21:06:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D56376136A for ; Sun, 22 Aug 2021 21:06:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233319AbhHVVGo (ORCPT ); Sun, 22 Aug 2021 17:06:44 -0400 Received: from cloud48395.mywhc.ca ([173.209.37.211]:36416 "EHLO cloud48395.mywhc.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232539AbhHVVGn (ORCPT ); Sun, 22 Aug 2021 17:06:43 -0400 Received: from modemcable064.203-130-66.mc.videotron.ca ([66.130.203.64]:52710 helo=localhost) by cloud48395.mywhc.ca with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mHufI-0001s6-7Z; Sun, 22 Aug 2021 17:06:00 -0400 Date: Sun, 22 Aug 2021 17:05:59 -0400 Message-Id: <76eef510a89966e04184893a3c53c6cc67b81579.1629655338.git.olivier@trillion01.com> In-Reply-To: References: From: Olivier Langlois To: Jens Axboe , Pavel Begunkov , Oleg Nesterov , Steven Rostedt , Ingo Molnar , "Eric W. Biederman" , io-uring@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] io_uring: Clear TIF_NOTIFY_SIGNAL when cancelling requests X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - cloud48395.mywhc.ca X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - trillion01.com X-Get-Message-Sender-Via: cloud48395.mywhc.ca: authenticated_id: olivier@trillion01.com X-Authenticated-Sender: cloud48395.mywhc.ca: olivier@trillion01.com X-Source: X-Source-Args: X-Source-Dir: Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org It is a reasonable expectation from a function to leave the task struct in a clean state. During io_uring_try_cancel_requests TIF_NOTIFY_SIGNAL can be set. Make sure that it is cleared by replacing calls to io_run_task_work with tracehook_notify_signal Signed-off-by: Olivier Langlois --- fs/io_uring.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index a2e20a6fbfed..a9c83a5fc9f1 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -9032,7 +9032,7 @@ static void io_uring_try_cancel_requests(struct io_ring_ctx *ctx, ret |= io_poll_remove_all(ctx, task, cancel_all); ret |= io_kill_timeouts(ctx, task, cancel_all); if (task) - ret |= io_run_task_work(); + ret |= tracehook_notify_signal(); if (!ret) break; cond_resched(); From patchwork Sun Aug 22 21:06:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivier Langlois X-Patchwork-Id: 12451697 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=-13.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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 B2530C4320E for ; Sun, 22 Aug 2021 21:06:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B7CE61051 for ; Sun, 22 Aug 2021 21:06:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233333AbhHVVGu (ORCPT ); Sun, 22 Aug 2021 17:06:50 -0400 Received: from cloud48395.mywhc.ca ([173.209.37.211]:36814 "EHLO cloud48395.mywhc.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232539AbhHVVGt (ORCPT ); Sun, 22 Aug 2021 17:06:49 -0400 Received: from modemcable064.203-130-66.mc.videotron.ca ([66.130.203.64]:52712 helo=localhost) by cloud48395.mywhc.ca with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mHufP-0001tb-7O; Sun, 22 Aug 2021 17:06:07 -0400 Date: Sun, 22 Aug 2021 17:06:06 -0400 Message-Id: <1625bc89782bf83d9d8c7c63e8ffcb651ccb15fa.1629655338.git.olivier@trillion01.com> In-Reply-To: References: From: Olivier Langlois To: Jens Axboe , Pavel Begunkov , Oleg Nesterov , Steven Rostedt , Ingo Molnar , "Eric W. Biederman" , io-uring@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] coredump: cancel io_uring requests before dumping core X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - cloud48395.mywhc.ca X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - trillion01.com X-Get-Message-Sender-Via: cloud48395.mywhc.ca: authenticated_id: olivier@trillion01.com X-Authenticated-Sender: cloud48395.mywhc.ca: olivier@trillion01.com X-Source: X-Source-Args: X-Source-Dir: Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The previous solution of ignoring the TIF_NOTIFY_SIGNAL bit while dumping core is only working when the core dump is sent in a file. When a pipe is used, pipe_write returns -ERESTARTSYS if signal_pending which includes TIF_NOTIFY_SIGNAL is true. A more robust solution is to make sure that io_uring will not set TIF_NOTIFY_SIGNAL while the core dump is generated by cancelling all the io_uring requests made by the current task before starting. Fixes: 06af8679449d ("coredump: Limit what can interrupt coredumps") Signed-off-by: Olivier Langlois --- fs/coredump.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/coredump.c b/fs/coredump.c index 07afb5ddb1c4..9aceb4b3b40d 100644 --- a/fs/coredump.c +++ b/fs/coredump.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -625,6 +626,8 @@ void do_coredump(const kernel_siginfo_t *siginfo) need_suid_safe = true; } + io_uring_task_cancel(); + retval = coredump_wait(siginfo->si_signo, &core_state); if (retval < 0) goto fail_creds;