Received: by 10.213.65.68 with SMTP id h4csp2143859imn; Sun, 8 Apr 2018 20:51:01 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+PuwkNuwCIPWXH+mgr2uQLuirvTHAiyba52wOJUQwEwi3HtguGwitvHQ+bowEGhpVgjQ+b X-Received: by 10.101.67.129 with SMTP id m1mr2973173pgp.373.1523245861048; Sun, 08 Apr 2018 20:51:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523245861; cv=none; d=google.com; s=arc-20160816; b=mOkw5R0YnXsxNAIe0ogxU87CwVD+tndXZ65fchV0lE9tg6/DB2ln1wNsO//dyHR3s+ LwwKgPts4NLC+yBWq+vqWei30AfZJiN7XZKxsht5ZL23gAv89wpFG7I926lH7ELVMjMi iZidaZbZGWsK7M2OMcohdfKNDtXYnGx/jlMxDHgCx6Z1y8cH+ibCFKozQuyZCBCv1Oo/ Z0o8ceupHxuJWqW2n+fbraVMXnHJC3PfqC+kKkcZbgKZW1KYgs6WRyM5ffuRJDHVEt2h njMigJRp6Du9d6UYrgS7/3zfYFBoZjNoFby86Rq2xh4JvyAZI3Q7BaLEQCts9RwEmorL HVHA== 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=EvnYP/JS264MFQwNBBJUq4LxqO+KCo43bW95bZkrEQiq+4hCCm7DscHpCetbLZowOK 9MASPblY/xt7mSBB/LsxUY8aS69ug0p2Kk51E/tDRKUkMgOq+s7XxuMuUDxIVbMbiK0p GAUPNJgOUDgzMUKo46G1Gdw8m1OowVCgXFMSM4aj1wYdIDzzGPHAzYJJDOWtWp6nfRM7 F1+FnEyHXqL/9EyjsQxG7iQhmKXUHmvCX/vBYjpRZkTQHOLoi3/C3qFPLU5VuOPDucN2 NN7nGM7fU4aElOvVxfir2EbSRJqgXgIuh6M8Dum7JRN8wS8JYJ8IFuwFu8vwXLA+891e XUmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=lxGBGqyp; 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 s10si10742539pge.41.2018.04.08.20.50.23; Sun, 08 Apr 2018 20:51:00 -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=lxGBGqyp; 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 S1754735AbeDIDog (ORCPT + 99 others); Sun, 8 Apr 2018 23:44:36 -0400 Received: from mail-dm3nam03on0097.outbound.protection.outlook.com ([104.47.41.97]:45238 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753783AbeDIAUW (ORCPT ); Sun, 8 Apr 2018 20:20:22 -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=lxGBGqyp5t/0jwlw+sCivfGKah52PyTMW+4zcnzrZHr/FhFdYrkYbQYnEzeMJDHgwSNlqcLVhEMmCf1bP6TDJs2+wntv5apZg6cJLOP/IOGqvi3XGDBdP1XhmwBu/8Gp/Xwod5L8OkTvj0x3vlSj8d5f0RXMc3QYusVY2nCv2Qo= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0920.namprd21.prod.outlook.com (52.132.132.165) 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:20:20 +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:20:20 +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.15 142/189] firmware: dmi_scan: Fix handling of empty DMI strings Thread-Topic: [PATCH AUTOSEL for 4.15 142/189] firmware: dmi_scan: Fix handling of empty DMI strings Thread-Index: AQHTz5hQBhMhxEMTO0WPtYNVp2XM1g== Date: Mon, 9 Apr 2018 00:18:42 +0000 Message-ID: <20180409001637.162453-142-alexander.levin@microsoft.com> References: <20180409001637.162453-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001637.162453-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;DM5PR2101MB0920;7:hXDmqYKXm/2gEJHFDZbM9Dv9QQrhmJzD5EsRrAZVAMmxRLZlo9+IlgpfENTdcHP86Jb0xw8eMQZtm/+GozXEH4tEBwj+uoC6Bya4au/EXPyehjcrVC+0CDqqvkI98k9B7fY2GnZ/YoOtt8NT9dCxdmO2r66a4iH8J+yX51qA1TKfilyaxcGq6muzdIkV51dxPHPtSQ33fQ5q6X3z0iJjx0eFfp9sPozksxeJYdNKew2DG8ZkpwhyFdbOiBPBUBIC;20:ZfrXZhbZQycXLuUN27W21jO18+qwx9GmSWRr06qNNR+H8Z9KHrElDHRyzIBFlw6AuYYtqkFt6+RjQ0hVaCMdf41MH94HvAYWDWjyM13CdA2B5y62lVmoDGcXXJRPf2LL/3lyH9goQPjttS0qBXcy9saTo2o2WncInpE8qtTW8Hs= X-MS-Office365-Filtering-Correlation-Id: cdcb1e7b-634e-4b4a-baa2-08d59dafade1 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:DM5PR2101MB0920; x-ms-traffictypediagnostic: DM5PR2101MB0920: 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)(93006095)(93001095)(3231221)(944501327)(52105095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123560045)(6072148)(201708071742011);SRVR:DM5PR2101MB0920;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0920; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39860400002)(39380400002)(396003)(366004)(346002)(376002)(199004)(189003)(66066001)(86362001)(3660700001)(3280700002)(25786009)(76176011)(2900100001)(1720100001)(36756003)(6506007)(2906002)(99286004)(86612001)(6486002)(102836004)(305945005)(1076002)(7736002)(97736004)(2616005)(446003)(11346002)(476003)(486006)(26005)(39060400002)(6666003)(6512007)(4326008)(107886003)(6306002)(5660300001)(478600001)(6436002)(105586002)(10290500003)(966005)(5250100002)(22452003)(316002)(186003)(8676002)(110136005)(81166006)(54906003)(6116002)(8936002)(72206003)(53936002)(2501003)(3846002)(68736007)(14454004)(81156014)(10090500001)(106356001)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0920;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: 23lwmbXE67c6ZKGW+SGquI6nOSaDkCvtnEw2JaefsIQEgC/xj2H5dF/u0WDVaOU+YYohO2Ct1ph5IDnNQg/WDMkh6FjSgTqAZsnF2/i80C4J5ONx9fb9/Oagn12WiPNvKZEWXqy70Wa/Heei3wtij34CYYMJMVQxByEbHTuFWpxtCaThaoT0N5tMAjVpupfE+fnoSc3x3Cf3grlex/k5D19rVq1oKBsihBwQZVKg2fCj/Ghd4P88aEG6O7enzmm6JDeWmNGsGMqvqLZQVCehBpy3kBzjazNUKNLHLt7n7AUTxZBIFABClpqp4lp8D0xzZm1WJd9jUMHwU0ijM8PpSeazn50GNIb9u44fZDxApZXQHfcbvbbEYr0ALB4ZopbdZZCTZoeZoeJApaC0hdhcRoZqG80/wJ87eTW1kQlr0fM= 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: cdcb1e7b-634e-4b4a-baa2-08d59dafade1 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:18:42.7844 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0920 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