From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web12.11029.1617710974240808697 for ; Tue, 06 Apr 2021 05:09:34 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WzxH/c15; spf=pass (domain: redhat.com, ip: 170.10.133.124, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617710973; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mKVeGqxDhVhmZXugw86RKnpqrA6JtwLGGM7K+XSUBE8=; b=WzxH/c15q9HspCawIGhlgZB6cqRPjP5W4veQf7ADYY+78KT+bju/e/RYju+CmYyzXYVDlx 0sPXQvy3AFINlnwL8QixzEzLSsIaGdQnFVvux8jJR59bMYh+SYS8JB9NTsUKYtTQqnzSy1 JbBXs+/B8WR8Ekmr2WDzW3hUD0NXT2M= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-476-XryTXfhUNRyA7FL976qusg-1; Tue, 06 Apr 2021 08:09:28 -0400 X-MC-Unique: XryTXfhUNRyA7FL976qusg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 36E2083DD20; Tue, 6 Apr 2021 12:09:27 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-115-134.ams2.redhat.com [10.36.115.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id E3E745D9E3; Tue, 6 Apr 2021 12:09:25 +0000 (UTC) Subject: Re: [edk2-devel] [PATCH v1 1/1] UefiCpuPkg: PiSmmCpuDxeSmm: Check buffer size before accessing To: devel@edk2.groups.io, kuqin12@gmail.com Cc: Eric Dong , Ray Ni , Rahul Kumar References: <20210326234142.1973-1-kuqin12@gmail.com> <20210326234142.1973-2-kuqin12@gmail.com> From: "Laszlo Ersek" Message-ID: <1211a5f3-f2b5-60e5-326e-ecef11e0ccac@redhat.com> Date: Tue, 6 Apr 2021 14:09:24 +0200 MIME-Version: 1.0 In-Reply-To: <20210326234142.1973-2-kuqin12@gmail.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lersek@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 03/27/21 00:41, Kun Qin wrote: > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3283 > > Current SMM Save State routine does not check the number of bytes to be > read, when it comse to read IO_INFO, before casting the incoming buffer > to EFI_SMM_SAVE_STATE_IO_INFO. This could potentially cause memory > corruption due to extra bytes are written out of buffer boundary. > > This change adds a width check before copying IoInfo into output buffer. > > Cc: Eric Dong > Cc: Ray Ni > Cc: Laszlo Ersek > Cc: Rahul Kumar > > Signed-off-by: Kun Qin > --- > UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c b/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c > index 661cc51f361a..ec760e4c37ca 100644 > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c > @@ -418,6 +418,13 @@ ReadSaveStateRegister ( > return EFI_NOT_FOUND; > } > > + // > + // Make sure the incoming buffer is large enough to hold IoInfo before accessing > + // > + if (Width < sizeof (EFI_SMM_SAVE_STATE_IO_INFO)) { > + return EFI_INVALID_PARAMETER; > + } > + > // > // Zero the IoInfo structure that will be returned in Buffer > // > Please update the description of the EFI_INVALID_PARAMETER return code in the function's leading comment as well. With that: Reviewed-by: Laszlo Ersek Thanks Laszlo