Received: by 10.192.165.148 with SMTP id m20csp548599imm; Wed, 25 Apr 2018 04:05:26 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+ZwDl6ou5etoYAZVaA//OoiwRCuV0E7zHReplH9Q4pgiip5widaFrH4kQeES+fl/ZSqf/k X-Received: by 10.98.87.84 with SMTP id l81mr10172404pfb.56.1524654326442; Wed, 25 Apr 2018 04:05:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524654326; cv=none; d=google.com; s=arc-20160816; b=bzkxw+bAk0RknkJsYrX5TK4EhOebrWXicY6GuZD4wnCxs86pxgD3/ejIyhjOK0y+hw OiybST0NMCfahVMH5+76pDaGVLyKV8TRXV0DcjL3UgKDu651Q0nijzv5H9e3gg3dS7GQ HpLyX4m/xUqRYYgj11U8kPuJAdZ3a/1E0aV4LdopTMB/Z41kTngk7x+8w7QewPvSzy7m 2UEtOT2lnlQMyPkb/T8fEPXvKoPoIimvs0/D3810spw3byE7oczQv5WCB8cPR7BLRMrh wOCbmF+s2RiwgBttB4g7yYb7kQ8WYsdDVJoZ3D7pPwBqMharyhapnUrREy8OypzgQo4B Ezow== 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 :arc-authentication-results; bh=J1W5uDS7B8TYNOPq34YPTPIzxv1Xazls7K1gc27Ujqk=; b=1HwjQefORA3rg6uOVA5JF5vuwa5RdDSOjT5KZNBJh7Yhtk8kjIa9IEqNUfJ8AF9EmA 4M979XoqmGCmZjQVXmG/VGsKzV6KM7G6JwNqvT9gGwyQZZkm61DiTkTPmWVTxuzv48Bf ekTwCr3ajXfgcYFQQBRPv1BZtZojnuZfWeBigd88V6QIwOHqJdknExtedqpcj2iqDqmf WjC+2kDJwzlJBarI0XH2B7x/OnWxiD+qr6ROJb91AHkGCzkEPxI/bQfO4/qUH/SAlIGG NuYuYcM+i3Lae409ZfWzW0MAQKzDhdUYDaHzNiRZm/HOutVp20pqjFjKWVSA9l1bBnGn xmkg== ARC-Authentication-Results: i=1; mx.google.com; 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 h3-v6si33961plt.109.2018.04.25.04.05.12; Wed, 25 Apr 2018 04:05:26 -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; 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 S1754384AbeDYLCr (ORCPT + 99 others); Wed, 25 Apr 2018 07:02:47 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:52680 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751804AbeDYKmb (ORCPT ); Wed, 25 Apr 2018 06:42:31 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 44A68272; Wed, 25 Apr 2018 10:42:30 +0000 (UTC) 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 4.14 129/183] firmware: dmi_scan: Fix handling of empty DMI strings Date: Wed, 25 Apr 2018 12:35:49 +0200 Message-Id: <20180425103247.613786336@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180425103242.532713678@linuxfoundation.org> References: <20180425103242.532713678@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 4.14-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 @@ -18,7 +18,7 @@ EXPORT_SYMBOL_GPL(dmi_kobj); * 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 u32 dmi_ver __initdata; static u32 dmi_len; @@ -44,25 +44,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)