Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4850069pxj; Wed, 9 Jun 2021 03:30:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwWBD4klFaWoNZjZs7ftiB7rpeN1I8CRjQ5WCl8LJayh/va+lpRwKwJW9Iw2MA5SsnAntFP X-Received: by 2002:a17:906:58c4:: with SMTP id e4mr27556127ejs.41.1623234617866; Wed, 09 Jun 2021 03:30:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623234617; cv=none; d=google.com; s=arc-20160816; b=KzpOWAkTR6kjak3pbEMePIifsH1QR7I4HSwMphdR/7abOxiQDeyDtKLtfeI0jrdmeW kw5zHiESZ6Sg3+ks5xLREV7OY3GIVlhsBHN+K/+PPHWQFaxCiE+x22+JvKe6SOWpTxmK iFqktZGh3H1R7bOOB1KgInTZYXWjvaRp95Nyy2ReB/Ap9TxiBgaAtDbwtWzODErzz1Ut rsA70Y6soAojfodeCXe6YEf9yhn6HDKEzpuCbh8Selh9zY+q8xSQ9ohAa3mqOzoEyZxL INt5Bg2gpu4CisKyv8KUuSfZl4IaeUSgzKpSjTcX2tJZsvknX2uGXjvXJon+tRAUkfQv siHg== 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=Gpa8Vn5d17M4Hcyg0a34/ox7dHI7B6OCMsAzGAs/cOs=; b=dcpWg3YX7gsccSW1Sjx0rvAYR9lCR+sq7DRTcqlKpFyXiHInZphwaFolFBQ4gQ8axh 6WPHGRANYHwDHbnqmqmAGjlOEiijS9kMO+1tQl8JQehuYUxCoeJW+yjxurg3wrdC0k22 7xSteuKJ9K2D5UuXUSZbwGljOy/IIKYs7GMF2YdRtVyN0bCporClb7maRrXg+E3jBQxl MJ2HsD4QEJfLnYxTTxiJ8xJDL4gwmY4hqBR5sBHrFsvJ5gyMKAuOr+y+jT4H2SxAtSDo 7+9IRfyCpstyVhBVhB2y7i63+5JPvEYiMcvGz6paqhzEWurxtjwQDQn+xgg7hxWt3iS0 gM6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vPVjm9D9; 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 dz18si701517edb.566.2021.06.09.03.29.54; Wed, 09 Jun 2021 03:30:17 -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=vPVjm9D9; 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 S237302AbhFHTAO (ORCPT + 99 others); Tue, 8 Jun 2021 15:00:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:50126 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236299AbhFHSxH (ORCPT ); Tue, 8 Jun 2021 14:53:07 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D37716148E; Tue, 8 Jun 2021 18:40:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623177630; bh=oUJDRI9PvMCWPWvYm722dhyXrB9pkcvy4+YoyhsR/M8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vPVjm9D95/Enky+XP3w0QyrI7h6TvtLD9QLa0rkqXfuseS2IepUyvHGYmXJb5b5bT 0yImyRJCpUpNeKcSZpZikb/Dqiov2blGqG+bjcAZx6B9jv7qZB5pmchCaWvB0oSBY7 HnPq0Z4iT81yW2k4zanxvo9umTIHKlatz/QVI+Dk= 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 5.10 009/137] efi: cper: fix snprintf() use in cper_dimm_err_location() Date: Tue, 8 Jun 2021 20:25:49 +0200 Message-Id: <20210608175942.698829452@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175942.377073879@linuxfoundation.org> References: <20210608175942.377073879@linuxfoundation.org> User-Agent: quilt/0.66 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 e15d484b6a5a..ea7ca74fc173 100644 --- a/drivers/firmware/efi/cper.c +++ b/drivers/firmware/efi/cper.c @@ -276,8 +276,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); @@ -286,7 +285,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