Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp4376876rwb; Tue, 8 Nov 2022 16:28:38 -0800 (PST) X-Google-Smtp-Source: AMsMyM7tBcq+UJLx0jD7zV6PRFsZZxdZrEmXIuHFIMTC8a+BdQnhMabWU41y/jKrIx4LsmnPCe/w X-Received: by 2002:a05:6402:210:b0:464:67ff:5e47 with SMTP id t16-20020a056402021000b0046467ff5e47mr25621686edv.417.1667953718734; Tue, 08 Nov 2022 16:28:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667953718; cv=none; d=google.com; s=arc-20160816; b=qSxapSNXs74Lz8djj8Z4orDn91/RHk0jW9t10QvG0/s+4XtmRVi9LSDR0B907+dNFE lHcQafIvEyaGYGnPoOyXIEt01OEv1MWft3ruBCjNC0kAzD+Uikee74BuSjfRtPkA4sEL zAoJwiFKwCUFsA4MRzWdY+UVN3gRXRoshtMIU8tn6z179naS4dv9P/IILHpW2DysaXNN +A9Ig2hwIXhyevv+lo7zvJhecFc7drwxSTyU4IKMYeOHqcUqwSR4wT2bWG5PcJty5AMj FU+d6/Fz5vH1DPGaZqnlcv0B5ZrQB/yPXi8t3j1IOy6QRX5gHkPZLGgrvm9d8EiW7ftX CSEA== 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:subject:cc:to:from:date :dkim-signature; bh=8b2x/uSbmkYpAa5rNOgqvI0C1NRfBGXo7EPHmS+VG64=; b=GZAg+QlO0j3uUg4sgdEOppJkYJbAa0LGkmkDfaHnXByAbxv85EEiohRrNTEoj9zpK2 LYE33yNk7EiJc3oePGf9qzfvITutLnc2Wq4NLL/hNs97euZC3h2aonfqLrn6WsWNit/o gXdkBP+sMxyg0VC1BcaxdvOpwguwrxuyHekEIbrVAckM3IkPURPfQAlPY3KvTMSnwNbL Yn93o9HK+a/P2o9kD0JHdqNK2NUjXw+WxozVOHlqRB7ifDSbGNga2P8h+uPmGmG253Dw z5ylEaQSLsyqoNiXH6335vG84XLNxTc7gMKGx3NX3AUIv7vSZnKqA64t2O0vtv1pU3A9 BPBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=qLx9Spuw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nb35-20020a1709071ca300b00780e89aecd1si14920091ejc.849.2022.11.08.16.28.15; Tue, 08 Nov 2022 16:28:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=qLx9Spuw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229920AbiKHXtB (ORCPT + 92 others); Tue, 8 Nov 2022 18:49:01 -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 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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?