From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web10.9639.1617811739838332773 for ; Wed, 07 Apr 2021 09:09:00 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YKFhxzvJ; spf=pass (domain: redhat.com, ip: 216.205.24.124, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617811739; 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=NYh6z71c4P48AJQqNqC6FcUywMc1F6UaondLbnam7t0=; b=YKFhxzvJEnp3yq3wRzvcyP+0DPX7OmM7JnFPC6mUf6CWqEAWuJPhaD4RwS0b0AAZhKjbZi S9h+GMDwdyqcSEdFz71wIp7qltd7GyaAZxS8lcdQGe36yRt/kU/L/Gp1kufwbzrrK90XIL K6rs47z6KiuOIE+dBLTuxktGRfbdcYw= 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-447-DJXjtLAXPgKvc_s6jKIFMg-1; Wed, 07 Apr 2021 12:08:55 -0400 X-MC-Unique: DJXjtLAXPgKvc_s6jKIFMg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A7093189C441; Wed, 7 Apr 2021 16:08:54 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-112-38.ams2.redhat.com [10.36.112.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6EACB5C1C4; Wed, 7 Apr 2021 16:08:53 +0000 (UTC) Subject: Re: [PATCH v1 1/1] UefiCpuPkg: PiSmmCpuDxeSmm: Check buffer size before accessing To: Kun Qin , devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar References: <20210406195254.1018-1-kuqin12@gmail.com> <20210406195254.1018-2-kuqin12@gmail.com> From: "Laszlo Ersek" Message-ID: Date: Wed, 7 Apr 2021 18:08:52 +0200 MIME-Version: 1.0 In-Reply-To: <20210406195254.1018-2-kuqin12@gmail.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 04/06/21 21:52, 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 > Reviewed-by: Ray Ni > Reviewed-by: Laszlo Ersek > --- > > Notes: > v2: > - Update return code description [Laszlo] > > UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c | 9 ++++++++- > UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 2 +- > 2 files changed, 9 insertions(+), 2 deletions(-) Thanks, looks OK. I'll let Ray or Eric merge the patch. Laszlo > > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c b/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c > index 661cc51f361a..fc418c2500a9 100644 > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmramSaveState.c > @@ -343,7 +343,7 @@ ReadSaveStateRegisterByIndex ( > > @retval EFI_SUCCESS The register was read from Save State. > @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor. > - @retval EFI_INVALID_PARAMETER This or Buffer is NULL. > + @retval EFI_INVALID_PARAMETER Buffer is NULL, or Width does not meet requirement per Register type. > > **/ > EFI_STATUS > @@ -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 > // > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h > index b8aa9e1769d3..2248a8c5ee66 100644 > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h > @@ -337,7 +337,7 @@ This function supports reading a CPU Save State register in SMBase relocation ha > > @retval EFI_SUCCESS The register was read from Save State. > @retval EFI_NOT_FOUND The register is not defined for the Save State of Processor. > -@retval EFI_INVALID_PARAMETER This or Buffer is NULL. > +@retval EFI_INVALID_PARAMETER Buffer is NULL, or Width does not meet requirement per Register type. > > **/ > EFI_STATUS >