From: "Michael D Kinney" <michael.d.kinney@intel.com>
To: "devel@edk2.groups.io" <devel@edk2.groups.io>,
"ardb@kernel.org" <ardb@kernel.org>,
"Kinney, Michael D" <michael.d.kinney@intel.com>
Cc: "Ni, Ray" <ray.ni@intel.com>, "Gao, Zhichao" <zhichao.gao@intel.com>
Subject: Re: [edk2-devel] [PATCH] ShellPkg: Avoid corrupting installed device path protocols
Date: Thu, 8 Dec 2022 21:57:44 +0000 [thread overview]
Message-ID: <CO1PR11MB4929FEE3299539245CC5AD5BD21D9@CO1PR11MB4929.namprd11.prod.outlook.com> (raw)
In-Reply-To: <CAMj1kXGFafNLq8HfwZuZMAQ+sQKVbcLaKPk41mA1agKDve6r=A@mail.gmail.com>
Ard,
Thank you for the correction.
If we add that CONST, then the ShellPkg build breaks with an error
c:\work\github\tianocore\edk2\ShellPkg\Application\Shell\ShellProtocol.c(297): error C2220: the following warning is treated as an error
c:\work\github\tianocore\edk2\ShellPkg\Application\Shell\ShellProtocol.c(297): warning C4090: 'function': different 'const' qualifiers
Which is exactly the line we want to remove to prevent the destructive behavior.
SetDevicePathEndNode (*DevicePath);
If I comment out that line, the ShellPkg build completes with no errors.
I agree that it would be better to update the prototype and get help
from the compiler to find incorrect implementations. Even though
CONST is not in the prototype, from reading the description of the API
it does not state that the contents are modified, so I think the
intent was no modifications.
Your suggested change is safe, but it is incomplete because there
are additional calls through the protocol that are not covered
by your patch. We also do not know how many places this API
is used in downstream projects. This side effect of a write to
a read-only page and potential corruption of a multi-instance
device path looks like a bug to me and we should fix the root
cause and not fix just some of the callers.
Mike
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Ard Biesheuvel
> Sent: Thursday, December 8, 2022 1:40 PM
> To: devel@edk2.groups.io; Kinney, Michael D <michael.d.kinney@intel.com>
> Cc: Ni, Ray <ray.ni@intel.com>; Gao, Zhichao <zhichao.gao@intel.com>
> Subject: Re: [edk2-devel] [PATCH] ShellPkg: Avoid corrupting installed device path protocols
>
> On Thu, 8 Dec 2022 at 22:15, Michael D Kinney
> <michael.d.kinney@intel.com> wrote:
> >
> > Hi Ard,
> >
> > There is a difference between returning a pointer to a device path
> > and modifying the device path contents.
> >
> > If you add CONST to the argument, then an updated pointer to a device
> > path can not be returned.
> >
>
> No, this is incorrect.
>
> The function takes a pointer (1) to a pointer(2) to a device path protocol
>
> EFI_DEVICE_PATH_PROTOCOL **
>
> So the function can dereference pointer 1 and modify pointer 2
> *unless* it is marked as CONST, i.e.
>
> EFI_DEVICE_PATH_PROTOCOL * CONST *
>
> in which case the pointer is not modifiable, but it is permitted to
> dereference that pointer to modify the underlying object.
>
> I am arguing that the prototype should be
>
> EFI_DEVICE_PATH_PROTOCOL CONST **
>
> (which is the same as putting the CONST at the beginning)
>
> where the caller's pointer can be advanced by the callee via the
> pointer-to-pointer. But that would still not permit the object to be
> modified.
>
> > The API clear describes returning an updated device path pointer, so
> > the API is declared correctly without CONST.
> >
>
> The pointer may be updated but not the object. It really comes down to
> the difference between
>
> CONST EFI_DEVICE_PATH_PROTOCOL **
> EFI_DEVICE_PATH_PROTOCOL CONST **
> EFI_DEVICE_PATH_PROTOCOL * CONST *
> EFI_DEVICE_PATH_PROTOCOL **CONST
>
> (where the first two mean the same thing0
>
> > The API does not state that the contents of the device path are modified.
> >
> > An API that uses CONST EFI_DEVICE_PATH* would indicate that the API
> > should not modify the contents of the device path. For example:
> >
> > /**
> > Returns the size of a device path in bytes.
> >
> > This function returns the size, in bytes, of the device path data structure
> > specified by DevicePath including the end of device path node.
> > If DevicePath is NULL or invalid, then 0 is returned.
> >
> > @param DevicePath A pointer to a device path data structure.
> >
> > @retval 0 If DevicePath is NULL or invalid.
> > @retval Others The size of a device path in bytes.
> >
> > **/
> > UINTN
> > EFIAPI
> > GetDevicePathSize (
> > IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
> > );
> >
>
> Yes, but this one is a pointer, not a pointer-to-pointer. Big difference.
>
>
>
>
next prev parent reply other threads:[~2022-12-08 21:57 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-07 16:12 [PATCH] ShellPkg: Avoid corrupting installed device path protocols Ard Biesheuvel
2022-12-08 16:51 ` [edk2-devel] " Michael D Kinney
2022-12-08 17:22 ` Ard Biesheuvel
2022-12-08 18:28 ` Michael D Kinney
2022-12-08 18:44 ` Ard Biesheuvel
2022-12-08 19:19 ` Michael D Kinney
2022-12-08 20:12 ` Ard Biesheuvel
2022-12-08 21:15 ` Michael D Kinney
2022-12-08 21:39 ` Ard Biesheuvel
2022-12-08 21:57 ` Michael D Kinney [this message]
2022-12-08 22:18 ` Michael D Kinney
2022-12-08 22:35 ` Ard Biesheuvel
2022-12-08 22:37 ` Ard Biesheuvel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CO1PR11MB4929FEE3299539245CC5AD5BD21D9@CO1PR11MB4929.namprd11.prod.outlook.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox