From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: redhat.com, ip: 209.132.183.28, mailfrom: philmd@redhat.com) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by groups.io with SMTP; Tue, 24 Sep 2019 03:35:34 -0700 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C1B9880F91 for ; Tue, 24 Sep 2019 10:35:33 +0000 (UTC) Received: by mail-wm1-f70.google.com with SMTP id o188so740885wmo.5 for ; Tue, 24 Sep 2019 03:35:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:openpgp:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=eRJWrEnh/ZTqWduKYtkFdlP1xwfDSXyQ2kGqnTezjbI=; b=U9tE8LSS3n8BqUouMUZ/xHfmvKBR2PYKCE6GFF3pH9V5K3ThnGtohSdbCjgsLo6RJO nNpotee5i1QlamivyY2V0u0ZkWdCPXScmduXwnAcSBS+B30uEr4ECO7eiXS71MnZui7G Hb5DwsGeQGk1ryo7tKLVPv3/T2X2oZ9CGQ08mrHT137+nUzOWfFA/E5di6y3eugEmmQs c0VbDGqFPBv0GIUybnz0OtSLSWwLm9nTpBop3Da4DgeRkqqNuS74W0jAQfmYklC1t+m8 5YU0A2jTjCoOcg2UO7oT8eAMBPs+Wj5W1gB9fqv2XP3CugEJkfip9veHqB6tTMpSIpYA rxHw== X-Gm-Message-State: APjAAAX/LtOTTTHRauXxZURbxfoOqkc2nAC9CHdT0VH2BQ0Ns99YS3Pj VLMk84vxisPoZke7F6EZIVTbNMwmSZdneHRD9uuUnDUQikSbMh5/d6FJ9X2aZw/Y8B8lJR1dKYi JpPwWgrya5LQCjA== X-Received: by 2002:a1c:984b:: with SMTP id a72mr2090261wme.149.1569321332298; Tue, 24 Sep 2019 03:35:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqwxqyBwdHw5zkTUgQ/dJ32SQO+zgcl3aOr915V/xFxy4yyL+UM4Q0hBreMDuP85W1IatL0TuA== X-Received: by 2002:a1c:984b:: with SMTP id a72mr2090240wme.149.1569321332102; Tue, 24 Sep 2019 03:35:32 -0700 (PDT) Received: from [192.168.1.115] (240.red-88-21-68.staticip.rima-tde.net. [88.21.68.240]) by smtp.gmail.com with ESMTPSA id b184sm2023173wmg.47.2019.09.24.03.35.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 24 Sep 2019 03:35:31 -0700 (PDT) Subject: Re: [edk2-devel] [patch v2 2/5] MdeModulePkg/DxeCapsuleLibFmp: Unload image on EFI_SECURITY_VIOLATION To: devel@edk2.groups.io, dandan.bi@intel.com Cc: Jian J Wang , Hao A Wu , Liming Gao , Laszlo Ersek References: <20190918030557.55256-1-dandan.bi@intel.com> <20190918030557.55256-3-dandan.bi@intel.com> From: =?UTF-8?B?UGhpbGlwcGUgTWF0aGlldS1EYXVkw6k=?= Openpgp: id=89C1E78F601EE86C867495CBA2A3FD6EDEADC0DE; url=http://pgp.mit.edu/pks/lookup?op=get&search=0xA2A3FD6EDEADC0DE Message-ID: <2c1e9bb0-3555-a0be-c6a0-e30ffa40644f@redhat.com> Date: Tue, 24 Sep 2019 12:35:30 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <20190918030557.55256-3-dandan.bi@intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 9/18/19 5:05 AM, Dandan Bi wrote: > For the LoadImage() boot service, with EFI_SECURITY_VIOLATION retval, > the Image was loaded and an ImageHandle was created with a valid > EFI_LOADED_IMAGE_PROTOCOL, but the image can not be started right now. > This follows UEFI Spec. > > But if the caller of LoadImage() doesn't have the option to defer > the execution of an image, we can not treat EFI_SECURITY_VIOLATION > like any other LoadImage() error, we should unload image for the > EFI_SECURITY_VIOLATION to avoid resource leak. > > This patch is to do error handling for EFI_SECURITY_VIOLATION explicitly > for the callers in DxeCapsuleLibFmp which don't have the policy to defer > the execution of the image. > > Cc: Jian J Wang > Cc: Hao A Wu > Cc: Liming Gao > Cc: Laszlo Ersek > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1992 > Signed-off-by: Dandan Bi > --- > MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c > index 95aa9de087..5dda561a04 100644 > --- a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c > +++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c > @@ -1028,10 +1028,19 @@ StartFmpImage ( > ImageSize, > &ImageHandle > ); > DEBUG((DEBUG_INFO, "FmpCapsule: LoadImage - %r\n", Status)); > if (EFI_ERROR(Status)) { > + // > + // With EFI_SECURITY_VIOLATION retval, the Image was loaded and an ImageHandle was created > + // with a valid EFI_LOADED_IMAGE_PROTOCOL, but the image can not be started right now. > + // If the caller doesn't have the option to defer the execution of an image, we should > + // unload image for the EFI_SECURITY_VIOLATION to avoid resource leak. > + // > + if (Status == EFI_SECURITY_VIOLATION) { > + gBS->UnloadImage (ImageHandle); > + } > FreePool(DriverDevicePath); > return Status; > } > > DEBUG((DEBUG_INFO, "FmpCapsule: StartImage ...\n")); > Reviewed-by: Philippe Mathieu-Daude