Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2517338imm; Mon, 28 May 2018 09:34:34 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpA0sjPABjgTtG6iqboa/A3pomn17CMHtZMKaPpA9RnCNEmkFFgAS8FPjt2tPy8lQhkJjXj X-Received: by 2002:a65:6517:: with SMTP id x23-v6mr11149811pgv.268.1527525274894; Mon, 28 May 2018 09:34:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527525274; cv=none; d=google.com; s=arc-20160816; b=anMaLXzA/gziS8IFNluiqQLgKAjAejEFF6hRzVIpNHk99MUrFr3uQrhIeebkI1Q05e Es6CjOWuPqyiFdiMsEzkMvsUUa3Zte+kNWLWGgOZh2mup+G0RpHjv9eepwjTb1bZFi4Z 8bulmJTQ7AA5jS7jK3D7WSd1chbubgAifpcMN0r9fb+B+F1GKGeB8UQa20X0nhzp50kq jrbtQxvXPcsb/s2A2Eiu7E8NuIzg/x2QphNgXJPirqGYBtRz4fvm2Zf9AN09lJFScD0l 4l8Ghx1Y/bWcDU9uFhvu5cD5Mh5RIpSAgAq1mkTYSB8vLDtR58+UCvo52HfYZdVPaHu1 ta2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=j6A7InKc+qNsuMvRTTr+dnjX/mcHHm2iGZwvpMj719w=; b=UyP+vu80BTAJ0zIroAyP094k8y45qWaCArOWyJsag0KsblhRtjj11lgSvijIWbovSV b4tsm2L1R6bZHMBpq0XNey5p87GgK+71iJ2Pfl5HIB0cGAg4Dh7XRZjIpDeV8d2mH5vn ztSY/xyCjr/88JcyaGnc/sQB8Mvh2ACfCdomqQ/BCnJvfBtCJXXuhXawkUDWVRe8EtF2 VPKIUDIG9PSzezxIvBlPml61kiM2FtdX8ZouejaJMZGNjGxAYC5hGSYW0m9ZytBzSx3a tg60083Y7E/ySIl+ZBIE8MBlKlB8e38XmZo3GSXspgabb40McuJO3B6v2RIe9EJj1KhV dYug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Y8Gig9Ak; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p14-v6si24380915pgc.216.2018.05.28.09.34.20; Mon, 28 May 2018 09:34:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Y8Gig9Ak; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S940152AbeE1Qdt (ORCPT + 99 others); Mon, 28 May 2018 12:33:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:57086 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934971AbeE1KI5 (ORCPT ); Mon, 28 May 2018 06:08:57 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3348320876; Mon, 28 May 2018 10:08:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527502136; bh=3xWL/2557+XasfP/g053OrgzdR1Sb/dDZMjulIZWKls=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y8Gig9AkEZ0GSPpEs7WDu0W9TbLWUdgCT42SZL3ZLIeZbYjHkNz4UezQkUE+LO7pj TTe6e3tRcXshKCTjLRvbhtHPAv7JSBW1WiHM6xwnXioOFZ2XOgujVSM70VXM5hB8b5 3QzBaOdw5Y2/mSjw6P2bEfJ23hyJZ0O6+bkMK22M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jean Delvare , Parag Warudkar , Ingo Molnar , Thomas Gleixner , Sasha Levin Subject: [PATCH 3.18 035/185] firmware: dmi_scan: Fix handling of empty DMI strings Date: Mon, 28 May 2018 12:01:16 +0200 Message-Id: <20180528100053.051336581@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100050.700971285@linuxfoundation.org> References: <20180528100050.700971285@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jean Delvare [ Upstream commit a7770ae194569e96a93c48aceb304edded9cc648 ] The handling of empty DMI strings looks quite broken to me: * Strings from 1 to 7 spaces are not considered empty. * True empty DMI strings (string index set to 0) are not considered empty, and result in allocating a 0-char string. * Strings with invalid index also result in allocating a 0-char string. * Strings starting with 8 spaces are all considered empty, even if non-space characters follow (sounds like a weird thing to do, but I have actually seen occurrences of this in DMI tables before.) * Strings which are considered empty are reported as 8 spaces, instead of being actually empty. Some of these issues are the result of an off-by-one error in memcmp, the rest is incorrect by design. So let's get it square: missing strings and strings made of only spaces, regardless of their length, should be treated as empty and no memory should be allocated for them. All other strings are non-empty and should be allocated. Signed-off-by: Jean Delvare Fixes: 79da4721117f ("x86: fix DMI out of memory problems") Cc: Parag Warudkar Cc: Ingo Molnar Cc: Thomas Gleixner Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/firmware/dmi_scan.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) --- a/drivers/firmware/dmi_scan.c +++ b/drivers/firmware/dmi_scan.c @@ -15,7 +15,7 @@ * of and an antecedent to, SMBIOS, which stands for System * Management BIOS. See further: http://www.dmtf.org/standards */ -static const char dmi_empty_string[] = " "; +static const char dmi_empty_string[] = ""; static u16 __initdata dmi_ver; /* @@ -36,25 +36,21 @@ static int dmi_memdev_nr; static const char * __init dmi_string_nosave(const struct dmi_header *dm, u8 s) { const u8 *bp = ((u8 *) dm) + dm->length; + const u8 *nsp; if (s) { - s--; - while (s > 0 && *bp) { + while (--s > 0 && *bp) bp += strlen(bp) + 1; - s--; - } - if (*bp != 0) { - size_t len = strlen(bp)+1; - size_t cmp_len = len > 8 ? 8 : len; - - if (!memcmp(bp, dmi_empty_string, cmp_len)) - return dmi_empty_string; + /* Strings containing only spaces are considered empty */ + nsp = bp; + while (*nsp == ' ') + nsp++; + if (*nsp != '\0') return bp; - } } - return ""; + return dmi_empty_string; } static const char * __init dmi_string(const struct dmi_header *dm, u8 s)