From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from rcdn-iport-4.cisco.com ([173.37.86.75]:5643 "EHLO rcdn-iport-4.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725859AbeJXGFl (ORCPT ); Wed, 24 Oct 2018 02:05:41 -0400 Subject: Re: [PATCH v2] kernel/signal: Signal-based pre-coredump notification References: <458c04d8-d189-4a26-729a-bb1d1d751534@cisco.com> <20181023092348.GA14340@redhat.com> <1e68a3ce-32cd-b058-3d1d-36455ceca848@cisco.com> From: Enke Chen Message-ID: Date: Tue, 23 Oct 2018 14:40:10 -0700 MIME-Version: 1.0 In-Reply-To: <1e68a3ce-32cd-b058-3d1d-36455ceca848@cisco.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-arch-owner@vger.kernel.org List-ID: To: Oleg Nesterov Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Peter Zijlstra , Arnd Bergmann , "Eric W. Biederman" , Khalid Aziz , Kate Stewart , Helge Deller , Greg Kroah-Hartman , Al Viro , Andrew Morton , Christian Brauner , Catalin Marinas , Will Deacon , Dave Martin , Mauro Carvalho Chehab , Michal Hocko , Rik van Riel , "Kirill A. Shutemov" , Roman Gushchin , Marcos Paulo de Souza , Dominik Brodowski , Cyrill Gorcunov , Yang Shi , Jann Horn , Kees Cook , x86@kernel.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, "Victor Kamensky (kamensky)" , xe-linux-external@cisco.com, Stefan Strogin , Enke Chen Message-ID: <20181023214010.WY0LnCAHrTvZMfgSmy5ZTjCG7AfZDbEp5DooUmOkU6s@z> Hi, Oleg: On 10/23/18 12:43 PM, Enke Chen wrote: >> >>> --- a/fs/coredump.c >>> +++ b/fs/coredump.c >>> @@ -546,6 +546,7 @@ void do_coredump(const kernel_siginfo_t *siginfo) >>> struct cred *cred; >>> int retval = 0; >>> int ispipe; >>> + bool notify; >>> struct files_struct *displaced; >>> /* require nonrelative corefile path and be extra careful */ >>> bool need_suid_safe = false; >>> @@ -590,6 +591,15 @@ void do_coredump(const kernel_siginfo_t *siginfo) >>> if (retval < 0) >>> goto fail_creds; >>> >>> + /* >>> + * Send the pre-coredump signal to the parent if requested. >>> + */ >>> + read_lock(&tasklist_lock); >>> + notify = do_notify_parent_predump(current); >>> + read_unlock(&tasklist_lock); >>> + if (notify) >>> + cond_resched(); >> >> Hmm. I do not understand why do we need cond_resched(). And even if we need it, >> why we can't call it unconditionally? > > Remember the goal is to allow the parent (e.g., a process manager) to take early > action. The "yield" before doing coredump will help. > > The yield is made conditional because the notification is conditional. > Is that ok? Given this is in do_coredump(), it is ok to make it unconditional for simplicity. >> >>> +bool do_notify_parent_predump(struct task_struct *tsk) >>> +{ >>> + struct sighand_struct *sighand; >>> + struct kernel_siginfo info; >>> + struct task_struct *parent; >>> + unsigned long flags; >>> + pid_t pid; >>> + int sig; >>> + >>> + parent = tsk->parent; >>> + sighand = parent->sighand; >>> + pid = task_tgid_vnr(tsk); >>> + >>> + spin_lock_irqsave(&sighand->siglock, flags); >>> + sig = parent->signal->predump_signal; >>> + if (!valid_predump_signal(sig)) { >>> + spin_unlock_irqrestore(&sighand->siglock, flags); >>> + return false; >>> + } >> >> Why do we need to check parent->signal->predump_signal under ->siglock? >> This complicates the code for no reason, afaics. Will simplify. Thanks. -- Enke