Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2094059pxb; Sat, 28 Aug 2021 04:24:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzivHIWU4xTT2e82wU7I51aQCyElnNSHj0b2VmgeB8IurCPaDhv1g9hSVrVR6dmeYn+3fvr X-Received: by 2002:a17:906:dc43:: with SMTP id yz3mr9432726ejb.467.1630149879370; Sat, 28 Aug 2021 04:24:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630149879; cv=none; d=google.com; s=arc-20160816; b=jU/qp/QBWMUg+PK087RN9J5PepoaYtByoErLqrT3qkoXDyI738SDmMHydtbJRGnJaq DdIM6ADOHVZhpZNdx1nNE8r9Q+zpIOPvu2SgXyuddqRUARzQa/QjLCVMDyDaSlSpHrmZ kME9l/Hk8XmTV6HqeJ19ZHy5v9y70dqlSfAKLdj9MMi+bvNowO8jXpw8mF1yiAGTeKy9 20m9lhJ9D8b3NEUHifY0VzDHX5+6lY2k3S6ZFxdFJGyBfUWW44tU+5GeuV86A6C8N9R4 NzyqFzVcRi223yf6NHuep7r1brl2a87OUE2hZQpi6EDRWk7+vnL9MkNqLMQ5oAonJtJ2 ALgw== 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 :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=X7YCBmYw20R3rlsNXmu4xaA+PLWV1Ljy7UzLuyOdXPE=; b=icmOSIcWvYo95CCHFI0Q7oTkNhFsoUQAY1eJvFJYOOZqkfvh2YEoCSLfvUsGt6MclO heB+oSS/c08tEl978BFZqH1HRqmIGi0d2C6iMGFhLS5Cz2u+5EetJTMYeKgc/fCIvtZG Qu+dtzSGdQLxrNxpeUCTzRlOpB24C6Zlo9g/Zfrmd1hHrWPM02OeNJeWpE86hnwtdJn5 LwYqsSsXa6ijhcUqjM8FcSbgJyTnfElhYcutXZVgvR+lMaxkPWnhXp42tDJamIwb7j4p PnjD/FRnOJ3pqQGK7BP5SiUOeVZ1Vs+bCZD5l9jw1StiN4g9Qoti5Xx0HhuPaEbmKOf1 N6AA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h19si11550957ede.498.2021.08.28.04.24.09; Sat, 28 Aug 2021 04:24:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233870AbhH1LXZ (ORCPT + 99 others); Sat, 28 Aug 2021 07:23:25 -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-Spam-Status: No, score=-0.21 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];