Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3289205imu; Mon, 28 Jan 2019 02:07:24 -0800 (PST) X-Google-Smtp-Source: ALg8bN6qXYxmYI3qD8AkZHwTU6S4Usy47+EivJbhFZT43DOHyL2BY0+ivem5Vk2WnzAvYvA0P0d7 X-Received: by 2002:a17:902:27a8:: with SMTP id d37mr21417397plb.182.1548670044700; Mon, 28 Jan 2019 02:07:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548670044; cv=none; d=google.com; s=arc-20160816; b=yRiRqKw7j1TWBKVzuTmp8G6JJVlFECB60cs4z8PUFdYKxbKqJmwuL0XyHYQodp4oaV A94tnJfSmSnrbJ5mv6sDiRsIlwVMms6yc44DTi1LbrwVSX4tYsTt6OXXaXp2ClX+6IMF axTy4TPb8yycSNThnvIvrv7kN52GG3hMEqgPN/iD5Hweqa3j4DuqYik//tcl5r+HNcli Cg72HqDKcHrEJ9lkKWK20EDxcKiLN4CwMaAKdaLO5zPfQPDn+wxDMIpgLvU7uAToxYHo ui0h5uPVmBI97E5EqvFBlv07ItEZ4sm4LmJ4ontnrWPuG4v0PsY828lPy/5cQ5NhuRj8 q50A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=dXHzD+lz59QjWxjSiO9rneys93W30DV0NQJxERsF+b4=; b=cwt46PEYNXFntvEwEhLwTdzE3oc1M5GOV/NYv72zhm4pUJmYCwvEU6Ah+NpIaV7EVO 2VMXj22bpQ9vQE2I9ByIfAgKa31vg3z/1Yp6oagCvYyzZfTzJfLFYd9E5nYsPosemvgs +diDcrhWc/odC8AEm0tiQs73US8ym5TECVpU1D1iaXhir4UgYgboD9ubGlebvCfQ8ADH ZVSSN3TTM2ylXtNJJarf+ixTki4PodJZeaL5kUr6kGtMF+3h0resqf/JY0L0WMWLeLSV xfEgRlHLpgGmTFL9156WYco9cah4DcVcaPckzuj8GQ+Ux5/ibboLrRi3j5mrr0xW1+70 WbmA== 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 10si31889139pgl.30.2019.01.28.02.07.09; Mon, 28 Jan 2019 02:07:24 -0800 (PST) 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 S1726884AbfA1KEv (ORCPT + 99 others); Mon, 28 Jan 2019 05:04:51 -0500 Received: from smtp03.citrix.com ([162.221.156.55]:28677 "EHLO SMTP03.CITRIX.COM" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726832AbfA1KEt (ORCPT ); Mon, 28 Jan 2019 05:04:49 -0500 X-IronPort-AV: E=Sophos;i="5.56,533,1539648000"; d="scan'208";a="76590264" Subject: Re: [PATCH 2/2] efi/cper: Avoid possible OOB when checking generic data block To: Borislav Petkov CC: , , , "Rafael J. Wysocki" , Len Brown , Tony Luck , Huang Ying References: <20190122160912.27312-1-ross.lagerwall@citrix.com> <20190122160912.27312-3-ross.lagerwall@citrix.com> <20190123115402.GB3227@zn.tnic> From: Ross Lagerwall Message-ID: Date: Mon, 28 Jan 2019 10:04:46 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <20190123115402.GB3227@zn.tnic> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/23/19 11:54 AM, Borislav Petkov wrote: > On Tue, Jan 22, 2019 at 04:09:12PM +0000, Ross Lagerwall wrote: >> When checking a generic status block, we iterate over all the generic >> data blocks. The loop condition only checks that the start of the >> generic data block is valid (within estatus->data_length) but not the >> whole block. Because the size of data blocks (excluding error data) may >> vary depending on the revision and the revision is contained within the >> data block, ensure that enough of the current data block is valid before >> dereferencing any members otherwise an OOB access may occur if snip >> - data_len -= acpi_hest_get_record_size(gdata); >> + record_len = acpi_hest_get_record_size(gdata); > > record_size so that it matches the function name it is used to compute > this. > > Btw, trying to grok this code is making my head spin. > >> + if (record_len > data_len) >> + return -EINVAL; > > <---- newline here. > > Btw, those checks in the loop you can abstract away into a separate > function so that you end up with something more readable like: > > apei_estatus_for_each_section(estatus, gdata) { > record_size = check_hest_record_size(gdata, data_len); > if (!record_size) > return -EINVAL; > > data_len -= record_size; > } > > for example. > There are only two if statements in the loop body -- I don't think it is necessary to abstract this into a separate function (which still requires having one if statement in the loop body). I've made the other changes you suggested and sent a V2. Thanks, -- Ross Lagerwall