Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp682808imu; Wed, 23 Jan 2019 03:55:35 -0800 (PST) X-Google-Smtp-Source: ALg8bN70g7zciozcT+p33FpLk9nlfsADIy6JPNE2tmqeM34c8d9oFlOJmWLSfwyYbacIKRsNk6ZD X-Received: by 2002:a63:3d49:: with SMTP id k70mr1702576pga.191.1548244535080; Wed, 23 Jan 2019 03:55:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548244535; cv=none; d=google.com; s=arc-20160816; b=ybhmb+mnYpqHvg/EgX7WHyDq/ck0Kc9A3kv+95TCqjwCHCDCxcNIgfmTlQUeHMRPJz FExGvAB9RFr69pW5V6f6mBwDe22d7FbtEo+eN74/eBxeoRhPYGohH3G95jU/px7Y/1DP 29i+o7/HmAuhF0+rfOD60BPaT9uQAQyggDtLaAeLMR20CAyNYffHVQsxyLAvv4afgfy5 UFho4BNKQd2zvqgb2Vk6A7mLUXiapL6YjqStK+A6qI/3kQm5Vi/mwwDf/r4Wra2hw/IW rTNmnSNJyc/sWUKWyTUUZV2ao4Zdk44EX6a8f1j4lchMvq9pA8U1Od/eecGSlWghsXmQ iRaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Sj/DTan/IH2RaxNYamagDLmM/z5EzjVodRYC6RBzHtM=; b=hFgKYYJFTAsNmYfweFR6BT86gBKydqT+QhAuerF0Ex4RqrP3E6LnWlsKejvZ+DZN3o FtAncfzAnzkBxv2ojwQsNdy5M7XCGsNamleOREFGL/IOdJeaqvrTUCvKn62f/7BnPwZ7 TG2Cd5uCzMfhsK9rBx3uoIKYvE/YbBGwsF7OjU6Tu9pUXRa45mF5Tw301yndEN5XhMtl PgzAGSqETIdAQlDICSr5ZSp9T0aU6oH9gXIgga89cUFg6zN368jdo7Nj7BW0Jk/493pm N6fmURwmXI6JuwR7w/h4QuUea8bUKQmINQi5RvKEC5exhPq5KqiHJBMohffBONfEqHJa tEaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=ozriKLMD; 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=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v190si18337997pfv.8.2019.01.23.03.55.18; Wed, 23 Jan 2019 03:55:35 -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; dkim=pass header.i=@alien8.de header.s=dkim header.b=ozriKLMD; 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=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726243AbfAWLyL (ORCPT + 99 others); Wed, 23 Jan 2019 06:54:11 -0500 Received: from mail.skyhub.de ([5.9.137.197]:34446 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726134AbfAWLyL (ORCPT ); Wed, 23 Jan 2019 06:54:11 -0500 Received: from zn.tnic (p200300EC2BCA6A00E10FD21FCC1A9F7B.dip0.t-ipconnect.de [IPv6:2003:ec:2bca:6a00:e10f:d21f:cc1a:9f7b]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 5CD641EC05A1; Wed, 23 Jan 2019 12:54:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1548244449; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=Sj/DTan/IH2RaxNYamagDLmM/z5EzjVodRYC6RBzHtM=; b=ozriKLMDSEjfuUTq43FHNMn1LhcoMU7bSFsyhMPoRSnVxcfbYkibJRAq/NobVyCvTzkxCU evdLmhdXubifCF5zCncEo3CQRn3sjVRiWi3qquohZ+CDid26+lxSlA3pusD/Qka+NOCski CMBEKF0cRX3gAFhA6FnACg/njapm2pY= Date: Wed, 23 Jan 2019 12:54:02 +0100 From: Borislav Petkov To: Ross Lagerwall Cc: linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-efi@vger.kernel.org, "Rafael J. Wysocki" , Len Brown , Tony Luck , Huang Ying Subject: Re: [PATCH 2/2] efi/cper: Avoid possible OOB when checking generic data block Message-ID: <20190123115402.GB3227@zn.tnic> References: <20190122160912.27312-1-ross.lagerwall@citrix.com> <20190122160912.27312-3-ross.lagerwall@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20190122160912.27312-3-ross.lagerwall@citrix.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Please write out the OOB abbreviation in your commit messages. > estatus->data_length is invalid. This relies on the fact that > struct acpi_hest_generic_data_v300 is a superset of the earlier version. > Also rework the other checks to avoid potential underflow. > > Signed-off-by: Ross Lagerwall > --- > drivers/firmware/efi/cper.c | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) > > diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c > index a7902fccdcfa..7cc18874b9d0 100644 > --- a/drivers/firmware/efi/cper.c > +++ b/drivers/firmware/efi/cper.c > @@ -546,7 +546,7 @@ EXPORT_SYMBOL_GPL(cper_estatus_check_header); > int cper_estatus_check(const struct acpi_hest_generic_status *estatus) > { > struct acpi_hest_generic_data *gdata; > - unsigned int data_len, gedata_len; > + unsigned int data_len, record_len; > int rc; > > rc = cper_estatus_check_header(estatus); > @@ -555,10 +555,12 @@ int cper_estatus_check(const struct acpi_hest_generic_status *estatus) > data_len = estatus->data_length; > > apei_estatus_for_each_section(estatus, gdata) { > - gedata_len = acpi_hest_get_error_length(gdata); > - if (gedata_len > data_len - acpi_hest_get_size(gdata)) > + if (sizeof(struct acpi_hest_generic_data) > data_len) > return -EINVAL; <---- newline here. Also, add a new line before the data_len assignment above, in the function. > - 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. > + data_len -= record_len; > } > if (data_len) > return -EINVAL; > -- Thx. -- Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply.