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::341; helo=mail-wm1-x341.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) (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 E205221194866 for ; Thu, 22 Nov 2018 09:26:55 -0800 (PST) Received: by mail-wm1-x341.google.com with SMTP id s11so9877146wmh.1 for ; Thu, 22 Nov 2018 09:26:55 -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=kkoOGjShLB/eVAtaF07dmtGTtZx7IE48RHEToeHH248=; b=fnO5Tl67PWmvBCOO6l59d9dKhthixoSBrqTcsmjyyttCo+Qyvik7B/WKMMLbSNLeAI IDELPVRlLlCbe2MdjJcz4NFc+hy/rhckUTS8dlaqoAsYaYJEwO9VGoaRWwYXPatSsPBu 3M+wOV5whZQYZJEVyDwwt3gpku+zekg97RS1Q= 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=kkoOGjShLB/eVAtaF07dmtGTtZx7IE48RHEToeHH248=; b=ff98a4D9i3dNJvktj3XrairIDfbK7LCL+9Xmi7Lav/hHj0tVelOPVjWHCOj3KIv2zD Pkk9zeT9Xn7lz2WLpeJCPLL5VVFmSMoyxvOwKBI+d4alVF8IxOXnvKhRy4D+Pvvf7THL R+X5fs3lRA3c6ig9EY87mwMSf+FikXG/pc+eYGfZ9O091/6asG1pHUgijovxB+jQTfr3 YVXwx65nU27rsHOnxV/RckLlwLGsZg5ttxusIJwM0L08v0Fvuk7G6bEUQ997/Ym+0Sws IS4X5p4r9dBKSg7XmiNdV0ZO8GBm3yhaLGzNESZgeBKSyyIOqtzk51ruQn5kmhAtMfDq MFww== X-Gm-Message-State: AGRZ1gI5qtsdOmRrGlEhZW8JJYHxELhXhvtbkSjPdOwgKlVyS6c12E2a lMmtIQJG2cznzx7DOAuQjmwKB1TV3zIi8g== X-Google-Smtp-Source: AJdET5ej+Yhhg5ve6QZzFu5SNk1Q7u5NKqu6ql3ZBE8m73T2yZjSxg0hF0MDtGa/NBaaOtXSwUQTjw== X-Received: by 2002:a1c:248b:: with SMTP id k133-v6mr10157397wmk.148.1542907614110; Thu, 22 Nov 2018 09:26:54 -0800 (PST) Received: from mba13.wifi.ns.nl ([2a01:cb1d:112:6f00:6422:2edf:11bf:f2b]) by smtp.gmail.com with ESMTPSA id v1sm8874985wrw.90.2018.11.22.09.26.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Nov 2018 09:26:53 -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: Thu, 22 Nov 2018 18:26:45 +0100 Message-Id: <20181122172645.20819-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181122172645.20819-1-ard.biesheuvel@linaro.org> References: <20181122172645.20819-1-ard.biesheuvel@linaro.org> Subject: [PATCH edk2-platforms 4/4] 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: Thu, 22 Nov 2018 17:26:56 -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) Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- Platform/ARM/Library/BdsLib/BdsFilePath.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Platform/ARM/Library/BdsLib/BdsFilePath.c b/Platform/ARM/Library/BdsLib/BdsFilePath.c index 74fdbbee773d..543ac8f83086 100644 --- a/Platform/ARM/Library/BdsLib/BdsFilePath.c +++ b/Platform/ARM/Library/BdsLib/BdsFilePath.c @@ -421,7 +421,7 @@ BdsConnectAndUpdateDevicePath ( } if (RemainingDevicePath) { - *RemainingDevicePath = Remaining; + *RemainingDevicePath = DuplicateDevicePath (Remaining); } return Status; @@ -1333,14 +1333,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