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 X-Spam-Level: X-Spam-Status: No, score=-8.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,UNPARSEABLE_RELAY autolearn=ham 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 605D3C432BE for ; Sat, 28 Aug 2021 11:22:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2725F60EBA for ; Sat, 28 Aug 2021 11:22:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233927AbhH1LX0 (ORCPT ); Sat, 28 Aug 2021 07:23:26 -0400 Received: from smtprelay0137.hostedemail.com ([216.40.44.137]:39704 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S233831AbhH1LXY (ORCPT ); Sat, 28 Aug 2021 07:23:24 -0400 Received: from omf18.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay04.hostedemail.com (Postfix) with ESMTP id BC7011809579F; Sat, 28 Aug 2021 11:22:26 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf18.hostedemail.com (Postfix) with ESMTPA id C87962EBFAA; Sat, 28 Aug 2021 11:22:25 +0000 (UTC) Message-ID: Subject: Re: [tip: efi/core] efi: cper: fix scnprintf() use in cper_mem_err_location() From: Joe Perches To: linux-kernel@vger.kernel.org, linux-tip-commits@vger.kernel.org Cc: Rasmus Villemoes , Ard Biesheuvel , x86@kernel.org Date: Sat, 28 Aug 2021 04:22:24 -0700 In-Reply-To: <163014706409.25758.9928933953235257712.tip-bot2@tip-bot2> References: <163014706409.25758.9928933953235257712.tip-bot2@tip-bot2> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.40.0-1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Stat-Signature: 7uetgy9b5emkj3oiuubiwcgypyi8eaa9 X-Rspamd-Server: rspamout02 X-Rspamd-Queue-Id: C87962EBFAA X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX18pUxn2alZBBCM1l+xnT4V9kNXDsxRmRQs= X-HE-Tag: 1630149745-356633 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 2021-08-28 at 10:37 +0000, tip-bot2 for Rasmus Villemoes wrote: > The following commit has been merged into the efi/core branch of tip: [] > efi: cper: fix scnprintf() use in cper_mem_err_location() > > The last two if-clauses fail to update n, so whatever they might have > written at &msg[n] would be cut off by the final nul-termination. > > That nul-termination is redundant; scnprintf(), just like snprintf(), > guarantees a nul-terminated output buffer, provided the buffer size is > positive. > > And there's no need to discount one byte from the initial buffer; > vsnprintf() expects to be given the full buffer size - it's not going > to write the nul-terminator one beyond the given (buffer, size) pair. [] > diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c [] > @@ -221,7 +221,7 @@ static int cper_mem_err_location(struct cper_mem_err_compact *mem, char *msg) >   return 0; >   > >   n = 0; > - len = CPER_REC_LEN - 1; > + len = CPER_REC_LEN; >   if (mem->validation_bits & CPER_MEM_VALID_NODE) >   n += scnprintf(msg + n, len - n, "node: %d ", mem->node); >   if (mem->validation_bits & CPER_MEM_VALID_CARD) [etc...] Is this always single threaded? It doesn't seem this is safe for reentry as the output buffer being written into is a single static static char rcd_decode_str[CPER_REC_LEN];