Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2433627imm; Thu, 7 Jun 2018 10:29:35 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLj69ArEGOvWJrUftFU4HQtpUkRObdapQ+wIRXA5rPKvnk60i+DIH2DRkFfIH4gjJqS5dm8 X-Received: by 2002:a63:85c8:: with SMTP id u191-v6mr2226667pgd.300.1528392575503; Thu, 07 Jun 2018 10:29:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528392575; cv=none; d=google.com; s=arc-20160816; b=R4/1U6QSjwcV2fMMjBmSggEYVYUQttOO0XjJ3UuUZ3H4tSxbl8mgdMq6RXcMxZ3fnW lElvYQYDAbsDKiOWo1d3NixN4ODg8OrEwuHDSpeJo7yWAEvNlURjepGB3aXHvTkcjd8K 1p1XOfdSOm6bTKrNThIZAswhjEgJC+o1Yac1Vlx5/8UxmDIPRC4saX+4W7MXKwSzV+hm QE7b2BrKUCPYKtkMAMFCpvfhdnb8iwoyqezCa80lanPF5b84hUM33rv2YpZAgtOoYzoR ScGfpjcGRbMBBKQKxEQ3QQVShGewpW2G9QkJ2P7onWfuTPCk8ZRF9HkbVH3w2gbEsfnI talQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=SMumloaa3zPyHm35rrbso2dzIhdPDXVi7FmwculxUJU=; b=DPUysvrHCudR8rfVNp1870g7Q1RlyqTUXhJtHc06N/3ea+6hn8rV5gsNnCuKodjWDV lESsMihuI1p2UOZXLZxzjFlviWUP4Dij8QJa2SVXtBwoHrdeccc4ldR75HWDfGTh4l0q dSupC0J8g5c7q1Kc8hrRFuz4IZGRbPivDqJzomDlGH1JptDpOkcL506LdqK0vP0VKs4K 0xPlZy3rv6y2joztdMW9eMSITEp4mYT9Y/w/srE6LLfEDtmKZrKdlLG19dQEIILD9DWp cb7VExe1+RkKVJcqCGIKZ9jSJwXJwqUJEw5cKOplKakeW8IsbDt90dXKLGsSE1wKWO5W eZZg== 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 j12-v6si19750587pgq.312.2018.06.07.10.29.21; Thu, 07 Jun 2018 10:29:35 -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 S934044AbeFGOf1 (ORCPT + 99 others); Thu, 7 Jun 2018 10:35:27 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:40385 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933817AbeFGOfX (ORCPT ); Thu, 7 Jun 2018 10:35:23 -0400 Received: from [148.252.241.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1fQvbj-0005Zw-8V; Thu, 07 Jun 2018 15:09:43 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvb5-0002yp-GE; Thu, 07 Jun 2018 15:09:03 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Parag Warudkar" , "Ingo Molnar" , "Jean Delvare" , "Thomas Gleixner" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 192/410] firmware: dmi_scan: Fix handling of empty DMI strings In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.57-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Jean Delvare commit a7770ae194569e96a93c48aceb304edded9cc648 upstream. 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: Ben Hutchings --- 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)