Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2071508pxb; Sat, 28 Aug 2021 03:40:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXADLBzcZvygr/duHi33nMaRjWG4jm8KfTD4d1L/4NWCIKcDSIGruHX960xriaMMlPnah9 X-Received: by 2002:a92:c5cf:: with SMTP id s15mr9441543ilt.62.1630147205587; Sat, 28 Aug 2021 03:40:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630147205; cv=none; d=google.com; s=arc-20160816; b=UiwhjJznezv1RO56236CeYT7hgnb15AxOiNsIAh9Hv3XsoLVEHujv31M84jTuela2Q U/dcibehD7DtF/tdeF9wQR7EmxCZH+jyQ8OVjLIlVTn73zti2WHORxD6hXUSHWHReGb8 N/FwTyc45q0UQH2cv3HhAMjz5VugR7A+UAYuRNSRI/doqPhHf6sg488bpCyKKlWWxMuc b27Vq4vJP5Eskc+9kHL5umrSs+iN9bo3tVCn3aOLWCIubF3cF3YfV/fTG33otdRaOjXf CHpbRgMja/6Hf4mMmRf+FlmwLe7J8/q35LkFSQOqWc0DV2hw95PMpkvUnW/Jvmm3+Fda l71g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:cc:subject:to:reply-to:sender:from :dkim-signature:dkim-signature:date; bh=z1MH+SPX7s30rIq5HTVkXckgHonnETEjsXmBd215+I0=; b=OiP7ZKBo5BC1yFswl9xC6S7rhAYvQnMGQomVjUKS+d2GFNVbpQqIKkZW0doTlURyps ApT+b/l4XYZRMzCWOM90AhFQaXMfJFaWG0AteGGnI9CSRiiWNKoSAbB6h4F3E7w6Ya4I VfZgLemLy2qwJdsA8u0QCHRDVH03dkeLrWYqBsaR26jlA4Bz81tdb/jDxcIKU7J/rXTk 4q/EVzdMLH+zXVQrgZHutihzlMvVwNHgRyh/jqnzoxZbSV9w0IhVsQtVMuCMkWBFT61a 3RghkGHObISbLQCCgjND5ve26HFJbPlMgfly/kmLWY9+hHT2Pm+0EZewl7lYfZMHS2yc Lj+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=QXFYQFuM; dkim=neutral (no key) header.i=@linutronix.de; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r19si8756471ioa.68.2021.08.28.03.39.53; Sat, 28 Aug 2021 03:40:05 -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; dkim=pass header.i=@linutronix.de header.s=2020 header.b=QXFYQFuM; dkim=neutral (no key) header.i=@linutronix.de; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233870AbhH1Kio (ORCPT + 99 others); Sat, 28 Aug 2021 06:38:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233807AbhH1Kih (ORCPT ); Sat, 28 Aug 2021 06:38:37 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49ECCC061756; Sat, 28 Aug 2021 03:37:47 -0700 (PDT) Date: Sat, 28 Aug 2021 10:37:44 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1630147064; h=from:from:sender:sender:reply-to: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; bh=z1MH+SPX7s30rIq5HTVkXckgHonnETEjsXmBd215+I0=; b=QXFYQFuMeE6koz+XvAuRb1x7ZGzECfb4W33kEWYqggi/VYNl1SheOCZ7IYYalxvqIrFwkb Vrs+aswMB78wIJ3RTZ0pWEVrocLsvXcNgYRqs1gaUm4R9tFoaTlq/oPTY9Qac2qkUbr3An gCHpY4p+yaTKhZyqByth3qdTXGeB9D9qiv2r1E0CQ8C+Z1IepOwcodD2y6/wg7KIGaSooc /0Sia2m82aDgpWwPeBqGla+4ih8zh0jg3Bh3p/rkH1ZNOCAzuv2Uoaz3rD7D391A8O1qKu oGv2ZbuTGasjRoM8OjgXAT7c9AQ9OBWRErXOEEW/llHyZGBWJV8+gB/lHjcXZQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1630147064; h=from:from:sender:sender:reply-to: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; bh=z1MH+SPX7s30rIq5HTVkXckgHonnETEjsXmBd215+I0=; b=3ivK08grzrRh0KlTyAV/YnQuyFYZjgxj65Z+joKwyjSBLaiEBbzf2oD8utJ6kXic2WAMfz OHpO73JrhQzd3tDw== From: "tip-bot2 for Rasmus Villemoes" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: efi/core] efi: cper: fix scnprintf() use in cper_mem_err_location() Cc: Rasmus Villemoes , Ard Biesheuvel , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <163014706409.25758.9928933953235257712.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the efi/core branch of tip: Commit-ID: 5eff88dd6b4badd664d7d3b648103d540b390248 Gitweb: https://git.kernel.org/tip/5eff88dd6b4badd664d7d3b648103d540b390248 Author: Rasmus Villemoes AuthorDate: Wed, 21 Apr 2021 21:31:46 +02:00 Committer: Ard Biesheuvel CommitterDate: Fri, 27 Aug 2021 16:01:27 +02:00 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. Signed-off-by: Rasmus Villemoes Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/cper.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c index ea7ca74..1cb7097 100644 --- 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) @@ -258,13 +258,12 @@ static int cper_mem_err_location(struct cper_mem_err_compact *mem, char *msg) n += scnprintf(msg + n, len - n, "responder_id: 0x%016llx ", mem->responder_id); if (mem->validation_bits & CPER_MEM_VALID_TARGET_ID) - scnprintf(msg + n, len - n, "target_id: 0x%016llx ", - mem->target_id); + n += scnprintf(msg + n, len - n, "target_id: 0x%016llx ", + mem->target_id); if (mem->validation_bits & CPER_MEM_VALID_CHIP_ID) - scnprintf(msg + n, len - n, "chip_id: %d ", - mem->extended >> CPER_MEM_CHIP_ID_SHIFT); + n += scnprintf(msg + n, len - n, "chip_id: %d ", + mem->extended >> CPER_MEM_CHIP_ID_SHIFT); - msg[n] = '\0'; return n; }