public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ard Biesheuvel" <ardb@kernel.org>
To: "Kinney, Michael D" <michael.d.kinney@intel.com>
Cc: "devel@edk2.groups.io" <devel@edk2.groups.io>,
	"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:12:02 +0100	[thread overview]
Message-ID: <CAMj1kXEU2O3gDfPpVPFWJx8=t=xVdbN7jxqiZi3BWdDjFZLZug@mail.gmail.com> (raw)
In-Reply-To: <CO1PR11MB492954D850EBACE1BEE95F38D21D9@CO1PR11MB4929.namprd11.prod.outlook.com>

On Thu, 8 Dec 2022 at 20:20, Kinney, Michael D
<michael.d.kinney@intel.com> wrote:
>
> Hi Ard,
>
> Much of this code has not been updated since initially added in 2010.
>
> Looks like a bug to me that has been there the whole time.
>
> I agree it is a behavior change in the implementation.  But unless
> new code use of this API looks at the implementation, they would
> not know it is destructive and they need to make a copy.  This
> API is available to external shell apps that use the shell protocol.
>

Well, not entirely. The function takes EFI_DEVICE_PATH_PROTOCOL** not
CONST EFI_DEVICE_PATH_PROTOCOL**, and so one might argue that the
underlying object is modifiable by the callee. And similarly, that
shell code should not grab a EFI device path protocol pointer from the
database and pass it to a function that does not use a CONST qualified
EFI_DEVICE_PATH_PROTOCOL pointer to accept the argument.

> We should get the shell owners to evaluate removing the destructive
> behavior.
>

I suppose changing the prototypes is out of the question, as doing so
would require a new version of the shell protocol?

> > -----Original Message-----
> > From: Ard Biesheuvel <ardb@kernel.org>
> > Sent: Thursday, December 8, 2022 10:45 AM
> > To: Kinney, Michael D <michael.d.kinney@intel.com>
> > Cc: devel@edk2.groups.io; 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 19:28, Kinney, Michael D
> > <michael.d.kinney@intel.com> wrote:
> > >
> > > Hi Ard,
> > >
> > > From this description, it does not look like it should be modifying the
> > > contents of the device path.  Just point to the device path end node that
> > > follows the match found.
> > >
> > > /**
> > >   Gets the mapping that most closely matches the device path.
> > >
> > >   This function gets the mapping which corresponds to the device path *DevicePath. If
> > >   there is no exact match, then the mapping which most closely matches *DevicePath
> > >   is returned, and *DevicePath is updated to point to the remaining portion of the
> > >   device path. If there is an exact match, the mapping is returned and *DevicePath
> > >   points to the end-of-device-path node.
> > >
> > >   @param DevicePath             On entry, points to a device path pointer. On
> > >                                 exit, updates the pointer to point to the
> > >                                 portion of the device path after the mapping.
> > >
> > >   @retval NULL                  No mapping was found.
> > >   @return !=NULL                Pointer to NULL-terminated mapping. The buffer
> > >                                 is callee allocated and should be freed by the caller.
> > > **/
> > > CONST CHAR16 *
> > > EFIAPI
> > > EfiShellGetMapFromDevicePath (
> > >   IN OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePath
> > >   );
> > >
> > > I see this API used in many places, and it looks like it would be
> > > destructive to any multi-instance device path. Multi-instance
> > > device paths are typically used for consoles, so we may not have
> > > noticed this destructive behavior with file system mapping paths.
> > >
> > > Did you try removing the call to SetDevicePathEndNode (*DevicePath);  ?
> > >
> >
> > No, but that would be a functional change visible to all users of the
> > current API.
> >
> > And note that the calling code already has 'DevicePathCopy' variables,
> > it just doesn't bother using them, so the intent is clearly to pass a
> > copy, not the actual device path.

  reply	other threads:[~2022-12-08 20:12 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 [this message]
2022-12-08 21:15             ` Michael D Kinney
2022-12-08 21:39               ` Ard Biesheuvel
2022-12-08 21:57                 ` Michael D Kinney
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='CAMj1kXEU2O3gDfPpVPFWJx8=t=xVdbN7jxqiZi3BWdDjFZLZug@mail.gmail.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