Branch: refs/heads/master
  Home:   https://github.com/tianocore/edk2-libc
  Commit: c8fa80ab2698d925c94db04f2f1d203d90b51d08
      
https://github.com/tianocore/edk2-libc/commit/c8fa80ab2698d925c94db04f2f1d203d90b51d08
  Author: Dimitry Kloper <[email protected]>
  Date:   2023-08-31 (Thu, 31 Aug 2023)

  Changed paths:
    M StdLib/EfiSocketLib/Ip4.c
    M StdLib/EfiSocketLib/Socket.c
    M StdLib/EfiSocketLib/Socket.h
    M StdLib/EfiSocketLib/Tcp4.c
    M StdLib/EfiSocketLib/Tcp6.c
    M StdLib/EfiSocketLib/Udp4.c
    M StdLib/EfiSocketLib/Udp6.c

  Log Message:
  -----------
  edk2-libc: Socket completion functions are not called on Linux Compilation

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=983

>From the bug description:
Analysis and root cause
-----------------------

After some investigation and debugging I have figured out the following:

The following function is implemented in file
edk2/StdLib/EfiSocketLib/Tcp4.c

VOID
EslTcp4ListenComplete (
  IN EFI_EVENT Event,
  IN ESL_PORT * pPort
);

The function is used in EslTcp4Listen() as a callback for connection
notification event, it is created by the following code:

Status = gBS->CreateEvent ( EVT_NOTIFY_SIGNAL,
                            TPL_SOCKETS,
                            (EFI_EVENT_NOTIFY)EslTcp4ListenComplete,
                            pPort,
                            &pTcp4->ListenToken.CompletionToken.Event );

And this actually introduces a bug:
the CreateEvent() third parameter is of type EFI_EVENT_NOTIFY
which is defined as

typedef
VOID
(EFIAPI *EFI_EVENT_NOTIFY) (
   IN EFI_EVENT Event,
   IN VOID *Context
);

That EFIAPI tag is important since it defines an ABI that is used by
compiler in order to call the callback function.
Note that EslTcp4ListenComplete() is not marked as EFIAPI.

Thus, on Linux, where gcc defaults to SYSV ABI, there will be mismatch
between arguments passed to EslTcp4ListenComplete() by the event
dispatcher. It expects function with WIN64 ABI, while its code compiled
with default SYSV ABI. It will look in wrong registers for arguments.

Specifically pPort pointer references an wrong memory location. Luckily
EslTcp4ListenComplete() performs sanity check of the pPort structure and
discovers that it is invalid. This causes discarding of all incoming
connections.

Proposed fix
---------------

The fix is trivial - mark EslTcp4ListenComplete() as EFIAPI.
This is a little more complicated, since there are additional callback
functions that suffer from the same problem. In addition fixing those
causes some compiler warnings that shall be addressed. Attached patch
fixes the problem for me.

Cc: Rebecca Cran <[email protected]>
Cc: Michael D Kinney <[email protected]>
Cc: Jayaprakash N <[email protected]>
Signed-off-by: Dimitry Kloper <[email protected]>
Reviewed-by: Jayaprakash N <[email protected]>




_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to