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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A68AC433FE for ; Tue, 8 Nov 2022 23:49:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229980AbiKHXtC (ORCPT ); Tue, 8 Nov 2022 18:49:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229880AbiKHXsu (ORCPT ); Tue, 8 Nov 2022 18:48:50 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AAA045EFA for ; Tue, 8 Nov 2022 15:48:50 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E7D62B81CB7 for ; Tue, 8 Nov 2022 23:48:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58F1DC433C1; Tue, 8 Nov 2022 23:48:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1667951327; bh=Fcu2qv9zwXGmJE/pBRUkdiIpewsCdUgeUAAdyR1Vl6o=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=qLx9SpuwIqKig1y5bJ60qem3PGGvfT5r3ke/qbkfxuubLb8yLZ5Mg4OV5rvOmzpid qScV+9dTVEqnW2w9hBrogWu5AiQevRlbb12NlmyP+QCVrRl8qAlEJRJ8pWeANYNbUc pGl5e8pOizvJygRknyXw4GBPeZzBiy87BGTMri7U= Date: Tue, 8 Nov 2022 15:48:46 -0800 From: Andrew Morton To: Stephen Brennan Cc: Baoquan He , Vivek Goyal , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, Dave Young Subject: Re: [PATCH] vmcoreinfo: Warn if we exceed vmcoreinfo data size Message-Id: <20221108154846.11584119794413c7682280fc@linux-foundation.org> In-Reply-To: <20221027205008.312534-1-stephen.s.brennan@oracle.com> References: <20221027205008.312534-1-stephen.s.brennan@oracle.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 27 Oct 2022 13:50:08 -0700 Stephen Brennan wrote: > Though vmcoreinfo is intended to be small, at just one page, useful > information is still added to it, so we risk running out of space. > Currently there is no runtime check to see whether the vmcoreinfo buffer > has been exhausted. Add a warning for this case. > > Currently, my static checking tool[1] indicates that a good upper bound > for vmcoreinfo size is currently 3415 bytes, but the best time to add > warnings is before the risk becomes too high. > > ... > > --- a/kernel/crash_core.c > +++ b/kernel/crash_core.c > @@ -383,6 +383,9 @@ void vmcoreinfo_append_str(const char *fmt, ...) > memcpy(&vmcoreinfo_data[vmcoreinfo_size], buf, r); > > vmcoreinfo_size += r; > + > + WARN_ONCE(vmcoreinfo_size == VMCOREINFO_BYTES, > + "vmcoreinfo data exceeds allocated size, truncating"); > } Seems that vmcoreinfo_append_str() will truncate (ie: corrupt) the final entry when limiting the overall data size to VMCOREINFO_BYTES. And that final entry will be missing any terminating \n or \0. Is all this desirable, or should we be checking for (and warning about) sufficient space _before_ appending this string?