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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60CE8C3DA49 for ; Sun, 14 Jul 2024 14:33:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A80106B0085; Sun, 14 Jul 2024 10:33:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A08566B0088; Sun, 14 Jul 2024 10:33:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8CF0D6B0089; Sun, 14 Jul 2024 10:33:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 6F0456B0085 for ; Sun, 14 Jul 2024 10:33:57 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id DBBAA141280 for ; Sun, 14 Jul 2024 14:33:56 +0000 (UTC) X-FDA: 82338602472.05.5A855F6 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by imf30.hostedemail.com (Postfix) with ESMTP id D2DEF8000D for ; Sun, 14 Jul 2024 14:33:53 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=linux.microsoft.com header.s=default header.b=UOxJtaa3; dmarc=pass (policy=none) header.from=linux.microsoft.com; spf=pass (imf30.hostedemail.com: domain of romank@linux.microsoft.com designates 13.77.154.182 as permitted sender) smtp.mailfrom=romank@linux.microsoft.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720967607; a=rsa-sha256; cv=none; b=LZkF+8pcdllEWxmnXw0uYiWBW0t512BQc1xCep/AGRJHkpVrtk6PrTn+J3F+i4vYRT7cwd Mk2/l0S/ClOVUCil92/J+6cFmWeJT5iXt1q+BLa5NvCDCc8Hl8uf7yMcvnaRVv1hI+s1IU opb7yrnvbIgsH0qu7NNmhwwTVeAix3g= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=linux.microsoft.com header.s=default header.b=UOxJtaa3; dmarc=pass (policy=none) header.from=linux.microsoft.com; spf=pass (imf30.hostedemail.com: domain of romank@linux.microsoft.com designates 13.77.154.182 as permitted sender) smtp.mailfrom=romank@linux.microsoft.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720967607; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=583exBE87er5wi2OkjlShNrw0hTE/HfFZ3UGUoxDu4Q=; b=UMKi84J0e0PeVJy/ZRXReGwTh5RrRkohEQ/WeoFjsHKEJonvqoNedLOIdC4Q27zgPXZ4ns QzWXrm+a3V7tSPRPBydvMQKOPOQbKYa6Fe+bUO2AUhM4VMuuz8MYmYzhf82DstZu9czzlW avzP8WTxDj5+mn3kisNQUdIxriqoW5c= Received: from [10.137.186.190] (unknown [131.107.159.62]) by linux.microsoft.com (Postfix) with ESMTPSA id 7D4E520B7165; Sun, 14 Jul 2024 07:33:52 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 7D4E520B7165 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1720967632; bh=583exBE87er5wi2OkjlShNrw0hTE/HfFZ3UGUoxDu4Q=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=UOxJtaa3GSi5Wqs/8u7Ilei583xycFz8UEAppGArByVT9+2HpOtDEfh15LJpx1nUs sPjk1HaYUY8zOlHrIIa/YQJskxjgJ3tK1s7qZW7NW3wTaZAztDehV0rp4AKClN2F72 bpgVv8QpuCdmUag7UlxGHNwS+fS6Hrg/vezm2WXw= Message-ID: Date: Sun, 14 Jul 2024 07:33:53 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 1/1] binfmt_elf, coredump: Log the reason of the failed core dumps To: Kees Cook Cc: akpm@linux-foundation.org, apais@linux.microsoft.com, ardb@kernel.org, bigeasy@linutronix.de, brauner@kernel.org, ebiederm@xmission.com, jack@suse.cz, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, nagvijay@microsoft.com, oleg@redhat.com, tandersen@netflix.com, vincent.whitchurch@axis.com, viro@zeniv.linux.org.uk, apais@microsoft.com, benhill@microsoft.com, ssengar@microsoft.com, sunilmut@microsoft.com, vdso@hexbites.dev References: <20240712215223.605363-1-romank@linux.microsoft.com> <20240712215223.605363-2-romank@linux.microsoft.com> <202407130840.67879B31@keescook> Content-Language: en-US From: Roman Kisel In-Reply-To: <202407130840.67879B31@keescook> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: D2DEF8000D X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: upzymqymxmy4toh456chxubjc93jndyn X-HE-Tag: 1720967633-666335 X-HE-Meta: U2FsdGVkX18+J56XtwIg8Y0sTudECBKtMy+GNYf0h8lVcBYodCXE7B0W8taoYm5MrMrWNlYu0OvWNAxn/VuaQw6V1WMvS/vNa8uwndxgEdK/dicJLAnYOfPklQzTYOLoSBas/RjAoixXEXt19isYvdxUOnGNI82WKkzZQQxKjZ2XoFfAS+56pQ3HL7KDj+jQLzFA4uZsvQokO013VFBB2MPXsiCSJYcRA7XSYJ+QD8EFJXCjjqRI3NZY2jbE1kLGer9I9ljIZOj6I1Rz2X6jVajRI5eo0veYLLxSIXuPNtAon1uOb7t9SFpqY3w0i6Uc2CyIyxjxhUPbpIwuCd6eql7HWOHFvXVI/NkMuuCrYpURwhVFPfpBx6wWGWDRUdbog9/4QRYFw78OU0eFNTpULTWBHN01Q0XYA5+BE8/8F9WS6byxhul+vnfd3phxssElCDGJr7l1/EibbTr9djem+4eyFBXCnxoZBl1P+OB5ojQOVwzDVww/KmtyHRaKliHdQ55nxYR+wNtR/U2NeLzF6xAOz8F6mb+lQ4w7pTnCKbgmcZ2ysL5UALhRChpKTQaj9Uary8sLxkVUez3rOOMlTWv/LKlJIyafaFC4Ut9E/PgxsHe1IgmoY0Qn26pSsfWcRfcK3nhu/VUvwpIu/QH3Jt6a5kP0PGYTsxBuuXq38eyWQdoBV7uiApSpr7vP4ds28BX2d1LBcjUJFxWN2znwmKviwuk7WQPUywwCqw7yAlX30jw+1ype2obwpqy1qzaxfBE0xAhDHPOLcRjbM0ZaRkKTqkdqyzOuzFtONz1rS6WTBcYPrq22XyymBSKVOuZiTrKlWtZ2MNV5Yw7wX159RyA9bE/4aE8+KJZl5+OSx5tOiNjSCvG3XRTw067zk/xladZvg4tgDeW2IGHfCRKOzJlMHvYLHRNOJ2aR7g4WIuC3qGe1dRGbppxM8yNbIJIf21cC23JiIvy2ex53LuU q7BXIh5F LOJ1+9RscYL4gsP7HIxA/mVGRIXzzldUIhwDnUuFg/xgWyGv2a1qd8y8rTE9Uur0nfHs8lhVLMKoiPDNPsCTpsyYpmjdJXDcdNdz4CDWQpSjVTAk0Le8TtrAfhNp+KAmqqkGtj+G5CXnXssgQ3fOPS6z2dbwEh7r+m3K1GUlh94IW1nY2N/ffRYogZdDxnAZ7NL75nofqWNsXdcf3+5Z0qn6qjpYgeCrHRPkJPkah4Ohn8EuUd99XPkVDohcOY7ZnVU2T8BEmgHJnAUHHpAM+4RVNsGET73XySk91XhdcjGo3V0B6KXn0/s/n8059OEPPEwZOBBWbtbS/Mf+y5yPJlNPWA4GZ0btmOdDiiZKWsWkkYps= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 7/13/2024 9:31 AM, Kees Cook wrote: > On Fri, Jul 12, 2024 at 02:50:56PM -0700, Roman Kisel wrote: >> Missing, failed, or corrupted core dumps might impede crash >> investigations. To improve reliability of that process and consequently >> the programs themselves, one needs to trace the path from producing >> a core dumpfile to analyzing it. That path starts from the core dump file >> written to the disk by the kernel or to the standard input of a user >> mode helper program to which the kernel streams the coredump contents. >> There are cases where the kernel will interrupt writing the core out or >> produce a truncated/not-well-formed core dump without leaving a note. >> >> Add logging for the core dump collection failure paths to be able to reason >> what has gone wrong when the core dump is malformed or missing. >> >> Signed-off-by: Roman Kisel >> --- >> fs/binfmt_elf.c | 60 ++++++++++++++++----- >> fs/coredump.c | 109 ++++++++++++++++++++++++++++++++------- >> include/linux/coredump.h | 8 ++- >> kernel/signal.c | 22 +++++++- >> 4 files changed, 165 insertions(+), 34 deletions(-) >> >> diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c >> index a43897b03ce9..cfe84b9436af 100644 >> --- a/fs/binfmt_elf.c >> +++ b/fs/binfmt_elf.c >> @@ -1994,8 +1994,11 @@ static int elf_core_dump(struct coredump_params *cprm) >> * Collect all the non-memory information about the process for the >> * notes. This also sets up the file header. >> */ >> - if (!fill_note_info(&elf, e_phnum, &info, cprm)) >> + if (!fill_note_info(&elf, e_phnum, &info, cprm)) { >> + pr_err_ratelimited("Error collecting note info, core dump of %s(PID %d) failed\n", >> + current->comm, current->pid); > > A couple things come to mind for me as I scanned through this: > > - Do we want to report pid or tgid? > - Do we want to report the global value or the current pid namespace > mapping? > > Because I notice that the existing code: > >> printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n", >> task_tgid_vnr(current), current->comm); > > Is reporting tgid for current's pid namespace. We should be consistent. > Thanks, will update the code to be consistent with the existing logging. > I think all of this might need cleaning up first before adding new > reports. We should consolidate the reporting into a single function so > this is easier to extend in the future. Right now the proposed patch is > hand-building the report, and putting pid/comm in different places (at > the end, at the beginning, with/without "of", etc), which is really just > boilerplate repetition. 100% agreed. > > How about creating: > > static void coredump_report_failure(const char *msg) > { > char comm[TASK_COMM_LEN]; > > task_get_comm(current, comm); > > pr_warn_ratelimited("coredump: %d(%*pE): %s\n", > task_tgid_vnr(current), strlen(comm), comm, msg); > } > > Then in a new first patch, convert all the existing stuff: > > printk(KERN_WARNING ...) > pr_info(...) > etc > > Since even the existing warnings are inconsistent and don't escape > newlines, etc. :) > > Then in patch 2 use this to add the new warnings? Absolutely love that! Couldn't possibly appreciate your help more :) > -- Thank you, Roman