Received: by 10.213.65.68 with SMTP id h4csp2119901imn; Sun, 8 Apr 2018 20:11:49 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/C6Og1Urf3y7j+EqByKSYQJ021xZrq1Q6akqixebq9e3PpSBEG2Bmuoebv4nsmbuyT1L3k X-Received: by 10.99.117.91 with SMTP id f27mr8180572pgn.108.1523243509050; Sun, 08 Apr 2018 20:11:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243509; cv=none; d=google.com; s=arc-20160816; b=zu5tHf3SSatunFlaX38AMhvySJYKy+FL5JthvZDwdliKLn5046iJBy/lL8mgwXmcDW 857h8932kcEFwjngpJZ94f/f0ZPk8qSMyhC6m2MurCh3bj7q3AfvKy8gp3Sm4SvcbmvZ eNk8KiK/rrvJhMfeA3F84w7NDnlgkFuV7O4CnA9vwj/5sriqnzSW5RGzqBj2JzriVCHn 0QcK0wl4iNrNx9J2XKkL1h6W0yKmt/6EZaY9N6xNT+jlRsSNfki+e+rs20z/0b7dWnNQ M7DnQv/Ns1K3ZrIeXuBzNPif7dxA2GMu+9WS3tJwXRS43AWTxsn+vo8zeYQO0kClwKR3 Nhhw== 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=9HFIYvEZKNm3lDzZcgtKJVsT+pad7UJg+KgxQZsjwXo=; b=ODwK4X7r5u5ur9lenEP0KwBgI3TxsBbYTiCN8233IPlE5TsBGBLWWsTVFKnXYdcnXY WvPQIq0eUMQ4L+27dqgTbTel47NHY1TP/3vEJClVK7FvqSrdMwmvzu6S6pWCToYJ+u2K /fw0voTWR0FbVXW2DzV4SokK6VXz4wRZhly8RcsiiRzL3WfcGdSUrU0tRz0FflbRe98N 77/+txZp0j+CULJBFxqngJsYLZrXvkKHwe+dnWubnigFQ7esDRv9z3AEJZigNDUsDwh+ PxbNVlR/bK36ng5GnzuSahH83Z2xdL96CtcZLgRSnPZcD5Hl342+Hwfrnw1qqOdWICxz 2hyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=hQLJi1D0; 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 n6-v6si13535710plp.194.2018.04.08.20.11.11; Sun, 08 Apr 2018 20:11:48 -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=hQLJi1D0; 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 S1757923AbeDIC3d (ORCPT + 99 others); Sun, 8 Apr 2018 22:29:33 -0400 Received: from mail-dm3nam03on0110.outbound.protection.outlook.com ([104.47.41.110]:12595 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755870AbeDIA2g (ORCPT ); Sun, 8 Apr 2018 20:28:36 -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=9HFIYvEZKNm3lDzZcgtKJVsT+pad7UJg+KgxQZsjwXo=; b=hQLJi1D0tnPtmofXX8vmP/wvuTfGVIM6kTy2GeQX8LUSmi2hZ5fsNoV6k80wVRLO3bU1q0VXD1Ii8H5vAX2rQB4dna2X94cY1gOKMUpghALAqOgsZSaO8ULjccUvzFkD+V2u9UaSLFWS2i0A6LO/n2zwa6+lkEjr0T2lQpKQhjg= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0807.namprd21.prod.outlook.com (10.167.110.154) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.3; Mon, 9 Apr 2018 00:28:29 +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:28:29 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Jean Delvare , Dmitry Torokhov , Andy Shevchenko , Linus Walleij , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 078/293] firmware: dmi_scan: Check DMI structure length Thread-Topic: [PATCH AUTOSEL for 4.9 078/293] firmware: dmi_scan: Check DMI structure length Thread-Index: AQHTz5kLKBFqgwQbZkqWKm6/DRFLDw== Date: Mon, 9 Apr 2018 00:23:55 +0000 Message-ID: <20180409002239.163177-78-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;DM5PR2101MB0807;7:X77Mql8WxLqRd4c8E/7zAc8j4XPvbazC7BqfZ5ZZqxm2c1ECVbYoT0dtOtVE7OsRieB7Oe06J14LFdncX/NsOrcxVsqU4hpWsOBQSFiBbZzxYhEPt4x4F1PAVSauXPqr9MROeL/rg3vX2KYtLMqhUmfDcIowmIBloZiV+LPt4YbPBIJmUy1GIYzymgiyM9rfAa+XuPpYGJ53MC3FzJhoFQTlZy5ncsA5is6D4UzPA4756uhpnpuOpFuNcB1NHKuX;20:CSWxhW1nH0jdGSoGG6dG/KzwUuFrnXsOqEQrAGqvYsbZ32H0QQrUxQ0h0W/XrWzkqqui341XZnHz41LfcyZqRTjxiTISKq7BK4RVP4uS62Ip8MtEGNo/b9zOb8pstegaVkNja7YmK/6sX138wqRqPYsZEcUM0PV1H8cQHcnq5W8= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: bc6f70f8-c390-4725-9ddb-08d59db0d192 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0807; x-ms-traffictypediagnostic: DM5PR2101MB0807: 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)(228905959029699); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3231221)(944501327)(52105095)(3002001)(6055026)(61426038)(61427038)(6041310)(20161123562045)(20161123558120)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB0807;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0807; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39380400002)(39860400002)(396003)(366004)(376002)(346002)(199004)(189003)(14454004)(4326008)(54906003)(25786009)(53936002)(2900100001)(1076002)(3280700002)(6486002)(186003)(2616005)(68736007)(110136005)(11346002)(10090500001)(6116002)(107886003)(3846002)(36756003)(8676002)(72206003)(22452003)(66066001)(26005)(39060400002)(6512007)(478600001)(3660700001)(81156014)(86362001)(81166006)(86612001)(7736002)(305945005)(8936002)(10290500003)(6436002)(105586002)(6666003)(316002)(575784001)(59450400001)(76176011)(5660300001)(476003)(106356001)(2906002)(6506007)(446003)(2501003)(99286004)(5250100002)(486006)(102836004)(97736004)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0807;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: wg0ouyip/qy5abkADT8zeKvFIvemDUqaiJP0ogKyG7ymTliTI3iaCAQ8nO1nrrmqWFvf1T41x0Ox2kkcF0mn7NHwQlkLLj7EQQppMI1Ewx4FQkq37I+jxS2cvLh/XZ4TkmkN7S9NF4phg/bdXb9Y3xWUX+3NOS2FB1bLvZDQvpW77ULp0inSAcFBc6SmYxEOcyi7Ak7FwrNzxWVo6WBYWJ6nC/bvJxLyLdu3UhflknUUybB6UzFwgBapBasfCnCHVYqFIcGdt8NmZ3xCvRa/mh8oOG4l8hu4vKgrDgQARr75m3Y0+Sn2/R6AXAVj2RCG3lbjohRTaaPNF+LGirdc7DEgt5fnOyhriPhvHDuAqGltG6ENtevWc28Eg1brx28L3Jsasz7VB9MPXsoqR/rAVwmmDd6DpBufLEjiibslBhQ= 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: bc6f70f8-c390-4725-9ddb-08d59db0d192 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:23:55.1905 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0807 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jean Delvare [ Upstream commit a814c3597a6b6040e2ef9459748081a6d5b7312d ] Before accessing DMI data to record it for later, we should ensure that the DMI structures are large enough to contain the data in question. Signed-off-by: Jean Delvare Reviewed-by: Mika Westerberg Cc: Dmitry Torokhov Cc: Andy Shevchenko Cc: Linus Walleij Signed-off-by: Sasha Levin --- drivers/firmware/dmi_scan.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c index 8590f94de9dc..18afa448bb9a 100644 --- a/drivers/firmware/dmi_scan.c +++ b/drivers/firmware/dmi_scan.c @@ -178,7 +178,7 @@ static void __init dmi_save_ident(const struct dmi_head= er *dm, int slot, const char *d =3D (const char *) dm; const char *p; =20 - if (dmi_ident[slot]) + if (dmi_ident[slot] || dm->length <=3D string) return; =20 p =3D dmi_string(dm, d[string]); @@ -191,13 +191,14 @@ static void __init dmi_save_ident(const struct dmi_he= ader *dm, int slot, static void __init dmi_save_uuid(const struct dmi_header *dm, int slot, int index) { - const u8 *d =3D (u8 *) dm + index; + const u8 *d; char *s; int is_ff =3D 1, is_00 =3D 1, i; =20 - if (dmi_ident[slot]) + if (dmi_ident[slot] || dm->length <=3D index + 16) return; =20 + d =3D (u8 *) dm + index; for (i =3D 0; i < 16 && (is_ff || is_00); i++) { if (d[i] !=3D 0x00) is_00 =3D 0; @@ -228,16 +229,17 @@ static void __init dmi_save_uuid(const struct dmi_hea= der *dm, int slot, static void __init dmi_save_type(const struct dmi_header *dm, int slot, int index) { - const u8 *d =3D (u8 *) dm + index; + const u8 *d; char *s; =20 - if (dmi_ident[slot]) + if (dmi_ident[slot] || dm->length <=3D index) return; =20 s =3D dmi_alloc(4); if (!s) return; =20 + d =3D (u8 *) dm + index; sprintf(s, "%u", *d & 0x7F); dmi_ident[slot] =3D s; } @@ -278,9 +280,13 @@ static void __init dmi_save_devices(const struct dmi_h= eader *dm) =20 static void __init dmi_save_oem_strings_devices(const struct dmi_header *d= m) { - int i, count =3D *(u8 *)(dm + 1); + int i, count; struct dmi_device *dev; =20 + if (dm->length < 0x05) + return; + + count =3D *(u8 *)(dm + 1); for (i =3D 1; i <=3D count; i++) { const char *devname =3D dmi_string(dm, i); =20 @@ -353,6 +359,9 @@ static void __init dmi_save_extended_devices(const stru= ct dmi_header *dm) const char *name; const u8 *d =3D (u8 *)dm; =20 + if (dm->length < 0x0B) + return; + /* Skip disabled device */ if ((d[0x5] & 0x80) =3D=3D 0) return; @@ -387,7 +396,7 @@ static void __init save_mem_devices(const struct dmi_he= ader *dm, void *v) const char *d =3D (const char *)dm; static int nr; =20 - if (dm->type !=3D DMI_ENTRY_MEM_DEVICE) + if (dm->type !=3D DMI_ENTRY_MEM_DEVICE || dm->length < 0x12) return; if (nr >=3D dmi_memdev_nr) { pr_warn(FW_BUG "Too many DIMM entries in SMBIOS table\n"); --=20 2.15.1