Received: by 10.213.65.68 with SMTP id h4csp2123181imn; Sun, 8 Apr 2018 20:16:38 -0700 (PDT) X-Google-Smtp-Source: AIpwx48uYjGK2e1bkOZYRrZttyFJCOV1Tf7wQL2lR7EI6we+JORWA2P7uZlEShWjUP8RVDRMjqmy X-Received: by 10.98.87.7 with SMTP id l7mr27711863pfb.148.1523243798252; Sun, 08 Apr 2018 20:16:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243798; cv=none; d=google.com; s=arc-20160816; b=AAEoUxg5xmKSUtDkv8huVvjK3V1lbX1971Fm2KxRIeMIiUdBLYVKvfJzAIqhB1Pg2G E0GQsqQtxwjgA56inKAZioryvyh2y2st0NziARtqhgm+vWu96RLx9v/gi/vRrU+gEQZ1 ezJ5H/D2T61NFvE8u9lm5j0DQmR5gOY5itNi0iv5mKsVMSLDiLqL3BTtKsEt+IlXxI3L XapJqni7/H1TuJxU65Q3CzWda7uHHnRDW1/jvnCXhwJYd0mo7s+s/0mayynfhUrWq+HK dLm92V7TRANaiulInt8JrRCF1e0idSXJYDCaKZD7UjCoa1yA8czH+F0PjHEYVdDK96OP Kprw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=S3QQqobTJ7hDOpzu5RgBG4MoH11YSNieTLs2xR6CnIE=; b=Df6tXJ4lWeoC/qFvq1Bc8AJVRtTbKXMUFOhzuXrDeRsInRDT8jIQIuv2zHdYwXkBAC SgR5qeK7plLEtSSPvsdqnvKhn+Xh2EE6hHMtCOuLcAtS4AAqTa+UE0KDt/ttEk+jUP1Y KkYbnAwUyT8Cv3vmIbAd20ZlDn+RZsWlhSnJWJoOcgAcHNreSdcCbB8J9Cnqs6bd592A pJIUF8bojw6FFqX0r58wOpO+5yVARBbJZVeVkc6qdQnz1yN8+NyfSaV4+/SFU6Ap2NsD jRZoiCV50e1X5/bbex7LQK8T2yjGmqfbirNuDCrQtvi2gzG664LMlrywzGAO2mohxFv4 Fj0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=Ff1zw8ed; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x6si10344348pgo.122.2018.04.08.20.16.01; Sun, 08 Apr 2018 20:16:38 -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=@microsoft.com header.s=selector1 header.b=Ff1zw8ed; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752211AbeDIDBv (ORCPT + 99 others); Sun, 8 Apr 2018 23:01:51 -0400 Received: from mail-bn3nam01on0139.outbound.protection.outlook.com ([104.47.33.139]:17920 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755156AbeDIAZ0 (ORCPT ); Sun, 8 Apr 2018 20:25:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=S3QQqobTJ7hDOpzu5RgBG4MoH11YSNieTLs2xR6CnIE=; b=Ff1zw8edFovyXMiE7dLY56uXJAsWsw7RjDMffUNtbM6wP18zmWHufrA756BcW7CMZ1Ebh+fkNkXW16EoJkFBiESpHYMfXdXz0qGVg7mOiVJFsURm44zvn7BlDzbAxyvgFMHsjZnSQmjTpq79CZGBp4T8TedZTZedhZiwvZjd2+E= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1013.namprd21.prod.outlook.com (52.132.133.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:25:24 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:25:23 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Jean Delvare , Parag Warudkar , Ingo Molnar , Thomas Gleixner , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 118/161] firmware: dmi_scan: Fix handling of empty DMI strings Thread-Topic: [PATCH AUTOSEL for 4.14 118/161] firmware: dmi_scan: Fix handling of empty DMI strings Thread-Index: AQHTz5i0NNcQ1qS7T0qWOz+1IQsXGg== Date: Mon, 9 Apr 2018 00:21:30 +0000 Message-ID: <20180409001936.162706-118-alexander.levin@microsoft.com> References: <20180409001936.162706-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001936.162706-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB1013;7:WJAHXPBTJ4gSXs8061sImDzszZ5hGlpGyL/SbG4xLpQ2i+uo2bfTiRDgn0hayx9yZTbXr1zh5r9JzSn+Y8iwB/SbQkjEIeam15hXOQEVxiciEfw0vrzgaNUxOfR0whbCZFUl2fDTr8aapldUmA2RzA/HqE6lNacjabaje3VafH24TdrXNH7oFSpkSEFVoQOCdoMq8VfXfZVX0zFjrG5W4h4by20ycYgMpQwFigWkDZ8Zz5V9ZTpiAQTk5C9RuKT8;20:6FsxHO3d/oImO2djZ4yTt7MWsuHfR2EQFqu3X5ciGUz1kjoFdJlp7eENMsoEIrBQUPQwRrmdNssKsouGg6rEySTpwlhpPwsFsEwesjhjSdraBxqkn4+P6ZzDb3b6DZnDME8g12RTpZXOPQNlLqPT8OwQwL01wYc+RhKXXEecMJ0= X-MS-Office365-Filtering-Correlation-Id: 2f323162-347a-498d-c3f7-08d59db062b9 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(3008032)(48565401081)(2017052603328)(7193020);SRVR:DM5PR2101MB1013; x-ms-traffictypediagnostic: DM5PR2101MB1013: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(85827821059158); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(3231221)(944501327)(52105095)(3002001)(93006095)(93001095)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123560045)(20161123564045)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB1013;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1013; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(366004)(376002)(396003)(39860400002)(39380400002)(189003)(199004)(3280700002)(2616005)(8936002)(7736002)(476003)(446003)(11346002)(53936002)(3660700001)(86362001)(86612001)(81156014)(2906002)(186003)(81166006)(105586002)(1076002)(8676002)(26005)(97736004)(25786009)(6306002)(6512007)(3846002)(68736007)(72206003)(106356001)(5660300001)(6486002)(6666003)(6116002)(966005)(14454004)(4326008)(305945005)(6436002)(2501003)(5250100002)(10290500003)(478600001)(2900100001)(22452003)(110136005)(39060400002)(316002)(99286004)(66066001)(10090500001)(107886003)(76176011)(102836004)(54906003)(6506007)(36756003)(486006)(1720100001)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1013;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: Fr1kSrRAo6HeJy809VVT7qxSuLuqRjzltK9k7Qd9J0RcwVTcaZpFsPqLqCmFxL51g35EaoQEtjGgQGqE0woc/Iy5/odDHXCx1KjlFwArzT62soqdGlpISV8UpkViAFrXibK9BQFGdMMuDFzKZ5JMQJP/QD0V4hvfebgac812rbj4lCqh/YYwz30HIS/el985JX5KbVJCXOr3MSVUPXvuINx9xeSrKzlU7e7Ls2fI8I2QBJzaVdZm07w3X6icc10Yuvf5oOk1YTeEu9JZMNdiUYMI3YArjGNVR9mjE3+5nDK/NvNgFU16qT7MwCl9t9PdjSQKAMvmRgM6tzveTtAfQG4iZjkSvGgBKDSjHmJuFF/Yq5PR8Zjzhe+LgMRYmr631uVyG3YnqwQ0a1YG6L2mSReV9wYLKdkqk2CWVfn6/zk= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2f323162-347a-498d-c3f7-08d59db062b9 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:21:30.2061 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1013 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/firmware/dmi_scan.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c index 783041964439..e8db9659a36b 100644 --- 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[] =3D " "; +static const char dmi_empty_string[] =3D ""; =20 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 =3D ((u8 *) dm) + dm->length; + const u8 *nsp; =20 if (s) { - s--; - while (s > 0 && *bp) { + while (--s > 0 && *bp) bp +=3D strlen(bp) + 1; - s--; - } - - if (*bp !=3D 0) { - size_t len =3D strlen(bp)+1; - size_t cmp_len =3D len > 8 ? 8 : len; =20 - if (!memcmp(bp, dmi_empty_string, cmp_len)) - return dmi_empty_string; + /* Strings containing only spaces are considered empty */ + nsp =3D bp; + while (*nsp =3D=3D ' ') + nsp++; + if (*nsp !=3D '\0') return bp; - } } =20 - return ""; + return dmi_empty_string; } =20 static const char * __init dmi_string(const struct dmi_header *dm, u8 s) --=20 2.15.1