From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by mx.groups.io with SMTP id smtpd.web10.4147.1583244093373974117 for ; Tue, 03 Mar 2020 06:01:33 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@linaro.org header.s=google header.b=xeJi9QnZ; spf=pass (domain: linaro.org, ip: 209.85.128.66, mailfrom: ard.biesheuvel@linaro.org) Received: by mail-wm1-f66.google.com with SMTP id j1so1507965wmi.4 for ; Tue, 03 Mar 2020 06:01:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PxZ8mQCINI4KX7WtQNHu2oFvKb3OjP1BjMbD5zc3dwQ=; b=xeJi9QnZof4YxPTrNXi3euzD6WGBKgYCCcF8ciWkC/sGJIwn3HVVTCp359vKpZlASz iT3BPRKVBfghZIl7a3evlqodjtMzIZ/rIlC5MccIPT1XhT5l3VEZDpGeBXr/TKJwYc/l UKsbMOZp75qu/HbtKO0aSiOVVmVdbTcbPtqHfe577Ud1ki8uKYeXJMWbp6yxNkn+pFWR tjSaiXTXsbPnDmjpEjG+26wCdajixhRBIFV1pyfEmHFOYpWZGO4cVKz6AeepqMXtnZsS EiWD7s7OJtSFsoqKTWI/6a8RS/WPOho+L4qhvXuC0j5vgSo+sBOePvXMetAQFay+gT4I lqZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PxZ8mQCINI4KX7WtQNHu2oFvKb3OjP1BjMbD5zc3dwQ=; b=uT0L7DFJZInSokWEtTMRQnsxBkluW1o0ZOfe4RdNV1rNIQ5MmXyXqrB7/9o4iVcAEO rV9YFEuwIimnwBnPSOvpuzluRcdzVa6IG7Izg3E1narbv817S9YliA1Mk3Bc+4Waefnx fb2b0As1Tvd66FfiAgRQ+SQ5GAY3TP/fyxrZEgQ9xSzsfJhvKWMSOWqSPwHfYvlZq/lF lckWTHi5KK9sYQPICwH2eoybhMvxK0/c7gN3Iovh7XTs/vETmrewkMbUhog8sZpBy6Kh BNHrh+H9uGzMKbd7jwBQLiqgHuqNH66I0XySa6Q/pYfXle/wFRDtvDPoYqeBNsNvhXGb iAyQ== X-Gm-Message-State: ANhLgQ3Y6HU8zA7P0UHGq2VJiMdn7zdLbHhDArUwUT65lKePvUxUSXGp 7B8DE2iHx2hqGlkO+ecvVbAnvQMUlNEUZA== X-Google-Smtp-Source: ADFU+vtKO2ubeP/1gg5Zf99P2RQi+AU6SIXROoiUuw3ZiA/8tFCJFgF2k7MVFR9Hh6ONHY67DuSA7A== X-Received: by 2002:a1c:4c03:: with SMTP id z3mr4639511wmf.133.1583244091678; Tue, 03 Mar 2020 06:01:31 -0800 (PST) Return-Path: Received: from e123331-lin.home ([2a01:cb1d:112:6f00:816e:ff0d:fb69:f613]) by smtp.gmail.com with ESMTPSA id i10sm27575122wrn.53.2020.03.03.06.01.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 06:01:30 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , lersek@redhat.com, leif@nuviainc.com, Liming Gao Subject: [PATCH v4 7/7] OvmfPkg/LinuxInitrdDynamicShellCommand: bail if initrd already exists Date: Tue, 3 Mar 2020 15:01:17 +0100 Message-Id: <20200303140117.7288-8-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200303140117.7288-1-ard.biesheuvel@linaro.org> References: <20200303140117.7288-1-ard.biesheuvel@linaro.org> Before taking any actions, check if an instance of the LoadFile2 exists already on the Linux initrd media GUID device path, and whether it was provided by this command. If so, abort, since no duplicate instances of the device path should exist. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2564 Signed-off-by: Ard Biesheuvel --- OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.c | 31 ++++++++++++++++++++ OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.uni | 3 ++ 2 files changed, 34 insertions(+) diff --git a/OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.c b/OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.c index 47ed26b50d3a..ed8fbaa77069 100644 --- a/OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.c +++ b/OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.c @@ -53,6 +53,33 @@ STATIC CONST SINGLE_NODE_VENDOR_MEDIA_DEVPATH mInitrdDevicePath = { } }; +STATIC +BOOLEAN +IsOtherInitrdDevicePathAlreadyInstalled ( + VOID + ) +{ + EFI_STATUS Status; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + EFI_HANDLE Handle; + + DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)&mInitrdDevicePath; + Status = gBS->LocateDevicePath (&gEfiLoadFile2ProtocolGuid, &DevicePath, + &Handle); + if (EFI_ERROR (Status)) { + return FALSE; + } + + // + // Check whether the existing instance is one that we installed during + // a previous invocation. + // + if (Handle == mInitrdLoadFile2Handle) { + return FALSE; + } + return TRUE; +} + STATIC EFI_STATUS EFIAPI @@ -217,6 +244,10 @@ RunInitrd ( } else { ASSERT(FALSE); } + } else if (IsOtherInitrdDevicePathAlreadyInstalled ()) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_ALREADY_INSTALLED), + mLinuxInitrdShellCommandHiiHandle, L"initrd"); + ShellStatus = SHELL_UNSUPPORTED; } else { if (ShellCommandLineGetCount (Package) > 2) { ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), diff --git a/OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.uni b/OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.uni index a88fa6e3641b..4b6b1285fffd 100644 --- a/OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.uni +++ b/OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.uni @@ -18,6 +18,7 @@ #langdef en-US "english" #string STR_GEN_PROBLEM #language en-US "%H%s%N: Unknown flag - '%H%s%N'\r\n" +#string STR_GEN_ALREADY_INSTALLED #language en-US "%H%s%N: Linux initrd already provided by platform\r\n" #string STR_GEN_TOO_MANY #language en-US "%H%s%N: Too many arguments.\r\n" #string STR_GEN_TOO_FEW #language en-US "%H%s%N: Too few arguments.\r\n" #string STR_GEN_FIND_FAIL #language en-US "%H%s%N: File not found - '%H%s%N'\r\n" @@ -47,3 +48,5 @@ " Consumers of the LoadFile2 protocol on the LINUX_EFI_INITRD_MEDIA_GUID\r\n" " device path that are started via means other than the shell will be able\r\n" " to locate the protocol and invoke it.\r\n" +" 3. Exposing an initrd using this command is only supported if no initrd is\r\n" +" already being exposed by another driver on the platform.\r\n" -- 2.17.1