Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4325236pxj; Tue, 8 Jun 2021 11:32:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+9omK+zECrGUPRJ83aleTpFZEZygSXkOGi8puGfyEnu2HF4/n466QPwQzfunazlyJWNXU X-Received: by 2002:a05:6402:510e:: with SMTP id m14mr18645210edd.225.1623177146991; Tue, 08 Jun 2021 11:32:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623177146; cv=none; d=google.com; s=arc-20160816; b=BANDTbl5Dkr7mh7yQKXTeo01gbCZC5+BKJzk1e7VVPfbWZewstyYnt2zp32UrJyc9R CpBU0+xDfJ/4XDtkr6UhfaDZvmc6+tBqrG5bnY8xXla+0jPDpFGYyDdh8bMY+PmKukW5 O45lIhOoOhiVM2UQe0UMftv3BMVC2XEIDuObiGNQ/LPKWHcv7beryg3wbHQjMXG/lmeM scqVlGA6SZ4/Q3/YGbDCi9bsSOi6m/G+s39cYOwjnhWCTeNy+Bz+QKs7YcWCAMsPNfsQ qEIcq/gIv2TQvMewYGhooJqBGzPlnf83azxXQZwPzbS4XGEfzevlIyAq0uhRt+rRycgw t1MA== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=T8oOqMHiNOpMYfLlQBE1iPkA3Q+J/DXlc+Cc2TTbZmI=; b=YeIfDpPFRqUnoWZlfEUcNG17bHXR0Y9vT7cCOvt+H/HL0Tksqk/2+fVZO1As32vkv4 YGD6uqfadcxQTW/i3K6Mqn//XCo3IPtO6LspysTbr6rAc8iQgl+8+3zYNwPPxGBtOmc0 sW5tXXb/hZpwL49tTrq4XXmFfIVgi/+ZmVrIjJ8yU9YhCrk2msU3ZnqemKjd62a5yvdR fj7IOgxjfiNdcDRgkaw9obJHZF/3hAm3kvOlg/Tpht79tiIQCFC9v1uujrRnyADq46NF oliwpUY0H8AS73qLqOw30d6FbJD8ovm6HaDSDkm9g7X1s6s8xQlzLrQHmBgPgZFXb03r GlAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="eKv/bpk4"; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b19si356064edr.225.2021.06.08.11.32.03; Tue, 08 Jun 2021 11:32:26 -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=@linuxfoundation.org header.s=korg header.b="eKv/bpk4"; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234137AbhFHSba (ORCPT + 99 others); Tue, 8 Jun 2021 14:31:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:56100 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234138AbhFHSbL (ORCPT ); Tue, 8 Jun 2021 14:31:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F0445613BC; Tue, 8 Jun 2021 18:29:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623176957; bh=wd+BPha1Nb5yGMu5F8sdBCuibHKWsfyuWB9Y2bemk3Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eKv/bpk45/PMetoWIkjxGtcCplvRjhHW9/5tyYzsFhE3e0bzaEhjQESwDV3ZOpb4T 0r7vdxrjvbG5bPLFm+cIEY9BihJccrJ1JWl6wkZ5fH+vd6r2mSC+FpEoVwYysixQ9L xWBqTGCrI00SbDwDb0xKZOykvgDMEXc2K98JG8mk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Rasmus Villemoes , Ard Biesheuvel , Sasha Levin Subject: [PATCH 4.4 01/23] efi: cper: fix snprintf() use in cper_dimm_err_location() Date: Tue, 8 Jun 2021 20:26:53 +0200 Message-Id: <20210608175926.575148730@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175926.524658689@linuxfoundation.org> References: <20210608175926.524658689@linuxfoundation.org> User-Agent: quilt/0.66 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rasmus Villemoes [ Upstream commit 942859d969de7f6f7f2659a79237a758b42782da ] snprintf() should be given the full buffer size, not one less. And it guarantees nul-termination, so doing it manually afterwards is pointless. It's even potentially harmful (though probably not in practice because CPER_REC_LEN is 256), due to the "return how much would have been written had the buffer been big enough" semantics. I.e., if the bank and/or device strings are long enough that the "DIMM location ..." output gets truncated, writing to msg[n] is a buffer overflow. Signed-off-by: Rasmus Villemoes Fixes: 3760cd20402d4 ("CPER: Adjust code flow of some functions") Signed-off-by: Ard Biesheuvel Signed-off-by: Sasha Levin --- drivers/firmware/efi/cper.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c index c0e54396f250..dc8d2603612e 100644 --- a/drivers/firmware/efi/cper.c +++ b/drivers/firmware/efi/cper.c @@ -257,8 +257,7 @@ static int cper_dimm_err_location(struct cper_mem_err_compact *mem, char *msg) if (!msg || !(mem->validation_bits & CPER_MEM_VALID_MODULE_HANDLE)) return 0; - n = 0; - len = CPER_REC_LEN - 1; + len = CPER_REC_LEN; dmi_memdev_name(mem->mem_dev_handle, &bank, &device); if (bank && device) n = snprintf(msg, len, "DIMM location: %s %s ", bank, device); @@ -267,7 +266,6 @@ static int cper_dimm_err_location(struct cper_mem_err_compact *mem, char *msg) "DIMM location: not present. DMI handle: 0x%.4x ", mem->mem_dev_handle); - msg[n] = '\0'; return n; } -- 2.30.2