Received: by 10.213.65.68 with SMTP id h4csp2114329imn; Sun, 8 Apr 2018 20:04:33 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+zBMlxNBpD73541uOffcui7BVT3UTuFGNPjN7SVlkSHdhmUQDlWV/4EFlsSr/ojD8Do2ci X-Received: by 2002:a17:902:529:: with SMTP id 38-v6mr37289869plf.64.1523243073844; Sun, 08 Apr 2018 20:04:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243073; cv=none; d=google.com; s=arc-20160816; b=NZDpa3wJA2F3EjY4Vo95P1kayi16e9o+60LkC1aF/Pwxh/7mBfNQJ48h68Et/ctls7 yhXYEGBINeC+tI/trk2ubrvI4xCx0tgG1pNVz41wyfgZS/QTPNX48+8nez/EjsWal47P HKFDwwbO2ZcaKH2YQrD6P6GblM7Xo42p80FLqnN95WLe/Bs2Zth+LyWKrhfoPdYQ3Z+y DCZMsxR8+QhKBy6XKR5kpnHLYMRQnXGLMlMziN9OQg+jsU+6UTfYWw2pZ/xcMWET3Ab8 Cb2vU66oL9hyv+QkIgMpefB/KD5nyXb5bPu2avuyisU4g9BWBmu/LDlsLS7dYn1APUIa ewJw== 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=DTSg8iueH1onEpHLqVN56xwo+gqhReKQClqHLZXGJJE=; b=0j4JODp5UoBGEaczPD3ldVmf0I+VAtzJ6LCxTO1yKLmeCzWVedYOb9nZQBpMJQyazJ Wo3bAmnl/ky9G1yhG/qVRf48/YVeWCls3FT8reWtfvOY+nDXtYIYIE19UaNjfspJiazC +WVVoGr/u1sHgR37oPvDPLQBT25X6SYYYPb/vrF1CJngCRqn2E39os7Qf88T+soaq3yV LrvVeA2KXY25xn1ByuokuR0t2CXEX34JmuL4FupZunze/t7s0uedQGAWd0bGbfASsFOe uGT6ybFwNsEhEumny0g/5IBspG3nwinWDY4Me4y0hPy9YOfRLdKYeC4jlIrzbDnleB/k T8jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=gGKhxZVG; 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 i12si4701678pgq.322.2018.04.08.20.03.56; Sun, 08 Apr 2018 20:04:33 -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=gGKhxZVG; 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 S932464AbeDIAeZ (ORCPT + 99 others); Sun, 8 Apr 2018 20:34:25 -0400 Received: from mail-bl2nam02on0114.outbound.protection.outlook.com ([104.47.38.114]:2685 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932258AbeDIAeI (ORCPT ); Sun, 8 Apr 2018 20:34:08 -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=DTSg8iueH1onEpHLqVN56xwo+gqhReKQClqHLZXGJJE=; b=gGKhxZVG0a8hvXG954kctNENOA/I8wigB66ECIdAqXGlV4XFI53LR1e0Fo/1rkU01jhjo6V3FcQztbcxZbGXtbDXPezX+5/L56/0dKwew1n89b2PGqESj0MyW9QbO8gcZ35arp8G5+11nfn8ULgBkVqPusa6Z6ZHgHIh3eUmX8k= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0984.namprd21.prod.outlook.com (52.132.133.30) 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:34:04 +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:34:04 +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.9 269/293] firmware: dmi_scan: Fix handling of empty DMI strings Thread-Topic: [PATCH AUTOSEL for 4.9 269/293] firmware: dmi_scan: Fix handling of empty DMI strings Thread-Index: AQHTz5lkQ5Ouc7stW0iTngDXCtbEdQ== Date: Mon, 9 Apr 2018 00:26:25 +0000 Message-ID: <20180409002239.163177-269-alexander.levin@microsoft.com> References: <20180409002239.163177-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002239.163177-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;DM5PR2101MB0984;7:ab719RWbvhQRJopM0CyvOo0h73BiXSax/ShenlIinQPqfkeHVtEeK4mFuuL2IVGWzP834+UIHMk2IGwz+wqsNUnm6JGrwno4QEJa6vzRC6ybAmoXpEngYn8ijPeZvoCjtwHjxhwgInolPtORLO57DkEwpuq2hv4+EFCsWhEl6//ZgjtTPk6P9Fcby8yZjsxyDL443pkAV8eeX0V/3l0bQ/tXyAqo4YMINtdvdWjAItA5a62l8KarwHLLKqRkk9Q4;20:6h82B9/Jo7dS474Dl2ZbZfhLr58CAKVOJHiPeFObZjug30K1R8Eya/3lSyA8akhlKoDPsiVRh5iaKa4OHSX/sn9Wi4O+6wGsMZYITMa0MwJT0c4ADYKw/zyEMy7Tn8nbu8w2eIZvisuOIYaW5+pwHh5xdRTS2y71cTSKGtRkKrg= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 655eafdb-959b-41d7-3bfe-08d59db198cc x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0984; x-ms-traffictypediagnostic: DM5PR2101MB0984: 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:DM5PR2101MB0984;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0984; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(39860400002)(366004)(39380400002)(346002)(376002)(199004)(189003)(26005)(99286004)(2906002)(14454004)(97736004)(1720100001)(8676002)(81156014)(81166006)(8936002)(6512007)(106356001)(76176011)(186003)(3280700002)(10090500001)(36756003)(6506007)(66066001)(3660700001)(72206003)(478600001)(6666003)(53936002)(2900100001)(105586002)(102836004)(966005)(2501003)(110136005)(54906003)(5250100002)(486006)(1076002)(25786009)(6116002)(6436002)(11346002)(39060400002)(6486002)(22452003)(4326008)(446003)(7736002)(86362001)(305945005)(2616005)(476003)(6306002)(68736007)(3846002)(86612001)(5660300001)(10290500003)(107886003)(316002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0984;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: I5xOdUjBywkj04ln9u6C5iRogOGueiiHnwdi61bdi+pvgUkzktfl8ykZe9En19GIyGcpNNw4XcxDILCRguQ2bUZUH8iPTmPFrIzOxgS37PAgY4xmPeJSJ7i2/LD8ub9kyuRvXKb2Wu2aQ3wDEMBUePoGIW9TqNa2Ar+VX6tk8hxpydvMYwiokeaToFKQRB3FNqhdPfGEOf/DxbZZLIAZQdxv+Ey5UxkSO4bNer/jR6Di+tvoxAbo3ikWv2w2gdau6V9axD/oIP5BqncDdXqY7emTfui4b2+gWUQt7rQXLpvtfPGzKELYv2sMch/ojpa7oRIr3UQ+6+c0AvyHOK8QLgUZo36LIuZTHsuMAk/NWv02qxXvyoKwj6JT+ahClKD4BgKFckMQZtozDB6zFdKvp77gH9FH+sRpSf5Ye0ffOd8= 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: 655eafdb-959b-41d7-3bfe-08d59db198cc X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:26:25.6132 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0984 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 18afa448bb9a..659d5b29952f 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