From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4864:20::442; helo=mail-wr1-x442.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 9592D21B02822 for ; Fri, 23 Nov 2018 00:44:15 -0800 (PST) Received: by mail-wr1-x442.google.com with SMTP id 96so11520172wrb.2 for ; Fri, 23 Nov 2018 00:44:15 -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=Bb0R1IDjBPOBtw/Ni+Lped4iTM7acK5mOh+cMkl4yxk=; b=aI8d3g3d5KNgwEmiy2rB5c213VvW0feiH2G76snXI9wl9YXXUazmLrQjYPgCPBPnnu lWnupMzd7uYC19K3H1SXsdOb2P15aBLUL/UVg36GwpETXfwXnqoyKyZ6o4z03q4BJae4 l156y53w3cjuFAOXsXYiYb4MQu0a0+d+oKAXI= 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=Bb0R1IDjBPOBtw/Ni+Lped4iTM7acK5mOh+cMkl4yxk=; b=eraRl97vepgE1hjYHx8voJmz8hjkyc/Gt5YvYiy0YWyheu58oSTNzW2Lsh//Sk3+wU ZeJHY8F5SiKwez1+loWsAEMnCgve6Q97A8CitwH8yvMJOLDhWvXLD5RTzPu9gYHzxMcE 1KemUWuqWGeCqbuM/2qdklMqM62aqshDbh+/C7vEs2Jw+yriGstansR8X6dc3mCyrklu rd0Fefc6IyHECNtDk4pMEwho8YGGvkbqKFbVs5ws5erchjvkmeI+cP8jTAuJYL4UqowT C8990KuMsoXnMym0njlx91Sp7o+IniF4QUgUdkcQRd23DhoL0un9Fv6E2cmLtGnrxiz5 hOpA== X-Gm-Message-State: AA+aEWbHkVlwS14/k1yxWHwBraGmRgXgIGQOoGKmNpJWQayQqTXW4ew2 aeNxvoxwTLPzK+uEqlerzK14qfv5IKcluQ== X-Google-Smtp-Source: AFSGD/WsasmnGi45HuDNl3PoHsHak1ldBlhmb/N09m26qkcR1219tRG9L9UEOXq/Kaf4goUFRI61qg== X-Received: by 2002:adf:b201:: with SMTP id u1mr4778170wra.165.1542962653711; Fri, 23 Nov 2018 00:44:13 -0800 (PST) Received: from mba13.wifi.ns.nl (33.153.69.91.rev.sfr.net. [91.69.153.33]) by smtp.gmail.com with ESMTPSA id c8sm807377wrx.42.2018.11.23.00.44.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Nov 2018 00:44:12 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Cc: leif.lindholm@linaro.org, thomas.abraham@arm.com, nariman.poushin@linaro.org, lersek@redhat.com, philmd@redhat.com, Ard Biesheuvel Date: Fri, 23 Nov 2018 09:44:06 +0100 Message-Id: <20181123084406.27192-4-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181123084406.27192-1-ard.biesheuvel@linaro.org> References: <20181123084406.27192-1-ard.biesheuvel@linaro.org> Subject: [PATCH v2 edk2-platforms 3/3] Platform/ARM/BdsLib: maintain alignment for DevicePaths X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Nov 2018 08:44:15 -0000 DevicePath node types may have any size, and so it is up to the code that manipulates them to ensure that dereferencing them only occurs when the pointer is aligned explicitly. Since BdsConnectAndUpdateDevicePath() has only two callers, one of which itself, we can simply duplicate the device path (similar to how DxeCore's CoreConnectController () does it), and free the pool allocation again on the way out. (Note that the allocation only occurs when the non-recursive path is taken and the function returns EFI_SUCCESS) Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- Platform/ARM/Library/BdsLib/BdsFilePath.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Platform/ARM/Library/BdsLib/BdsFilePath.c b/Platform/ARM/Library/BdsLib/BdsFilePath.c index 62f796e5526d..ad66b2f82718 100644 --- a/Platform/ARM/Library/BdsLib/BdsFilePath.c +++ b/Platform/ARM/Library/BdsLib/BdsFilePath.c @@ -423,8 +423,8 @@ BdsConnectAndUpdateDevicePath ( } } - if (RemainingDevicePath) { - *RemainingDevicePath = Remaining; + if (!EFI_ERROR (Status) && RemainingDevicePath != NULL) { + *RemainingDevicePath = DuplicateDevicePath (Remaining); } return Status; @@ -1314,14 +1314,18 @@ BdsLoadImageAndUpdateDevicePath ( } FileLoader = FileLoaders; + Status = EFI_UNSUPPORTED; while (FileLoader->Support != NULL) { if (FileLoader->Support (*DevicePath, Handle, RemainingDevicePath)) { - return FileLoader->LoadImage (DevicePath, Handle, RemainingDevicePath, Type, Image, FileSize); + Status = FileLoader->LoadImage (DevicePath, Handle, RemainingDevicePath, + Type, Image, FileSize); + break; } FileLoader++; } - return EFI_UNSUPPORTED; + FreePool (RemainingDevicePath); + return Status; } EFI_STATUS -- 2.17.1