Discussion:
[edk2] GetNext of Smbios protocol not working
Shubha Ramani
2015-07-23 20:59:37 UTC
Permalink
Please see my code below. 
If you’ll notice, I’m passing

In  EFI_SMBIOS_HANDLE InSmbiosHandle = 0xFFFE;EFI_SMBIOS_TYPE  Type=160;

Which is as the header file“Smbios.h” and the protocol implementation “SmbiosDxe.c”

Instruct. According to myunderstanding, GetNext should return the address of the

First table whose Type=160. I used SmbiosView.efi and saw that indeed such a table

with Type=160 is present. I tried other valid Types too, though and the result is the same.
 
What I expect to be returned isthe EFI_STATUS of “Success” and the correct

Address for the SmbiosRecordwith type=160. I’m getting neither. I’m getting an EFI_STATUS

Code of 0xB58FBD02. At the veryleast, I would expect EFI_NOT_FOUND. According

To the protocol, this weird 0xB58FBD02should not be returned for EFI_STATUS.


I did search archives however,and it seems that others have had problems with Smbios GetNext,

With no resolution that I saw.


 
The following two paths are the Smbios Protocolimplementation in the latest EDK2 repo:


 
C:\edk2\MyWorkspace\MdeModulePkg\Universal\SmbiosDxe\SmbiosDxe.c


 
C:\edk2\MyWorkspace\MdeModulePkg\Universal\SmbiosDxe\Smbios.h


 
There is also a  shell toolC:\edk2\MyWorkspace\ShellPkg\Library\UefiShellDebug1CommandsLib\Sm

biosView which does not use the Smbios protocol at all. Itseems to use a backdoor approach of

internal data structures. I wonder why ? Is this because theSmbios protocol doesn’t work ?


 
We would like to use the Smbios Protocol because it’s simpleand provides what we need.

We would like to avoid the backdoor approach embraced bySmbiosview if possible.
 
Can someone comment on my issue ? Am I using GetNextincorrectly ?


 
EFI_STATUSEFIAPISmbiosMain (  IN EFI_HANDLE        ImageHandle,  IN EFI_SYSTEM_TABLE  *SystemTable  ){
  EFI_SMBIOS_PROTOCOL      Smb;  EFI_STATUS Status = EFI_SUCCESS;  EFI_SMBIOS_HANDLE InSmbiosHandle = 0xFFFE;  EFI_SMBIOS_TYPE  Type=160;  EFI_SMBIOS_TABLE_HEADER   *SmbiosRecord = NULL;  KNL_GENERAL_INFORMATION knl;  UINT16 size = 0;   Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **) &Smb);
  if (EFI_ERROR (Status)) {    return Status;  }
   Print(L"Status after  gBS->LocateProtocol: %r\n", Status);
  SmbiosRecord = AllocateZeroPool (sizeof(EFI_SMBIOS_TABLE_HEADER));   Status = Smb.GetNext (&Smb, &InSmbiosHandle, &Type, &SmbiosRecord, NULL);
  Print(L"Status after SmbiosProtocol->GetNext: %r\n", Status);   
    if (EFI_ERROR (Status)) {    return Status;  }

  Print(L"Smbios In Handle: %d\n", InSmbiosHandle);  Print(L"SmbiosRecord Address : 0X%llx\n", &SmbiosRecord);  Print(L"SmbiosRecord->Type : %d\n", SmbiosRecord->Type);  Print(L"SmbiosRecord->Length : %d\n\n", SmbiosRecord->Length);   Print(L"SmbiosRecord->Handle : %d\n\n", SmbiosRecord->Handle);  Print(L"Sizeof SmbiosRecord : %d\n", sizeof(SmbiosRecord));
   FreePool (SmbiosRecord);    return EFI_SUCCESS; Shubha D. ***@gmail.com
***@yahoo.com
A***@congatec.com
2015-07-23 21:08:27 UTC
Permalink
Your usage of pointers was incorrect. Please see corrected code below:


EFI_STATUS
EFIAPI
SmbiosMain (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{

EFI_SMBIOS_PROTOCOL *Smb;
EFI_STATUS Status = EFI_SUCCESS;
EFI_SMBIOS_HANDLE InSmbiosHandle = 0xFFFE;
EFI_SMBIOS_TYPE Type=160;
EFI_SMBIOS_TABLE_HEADER *SmbiosRecord = NULL;
KNL_GENERAL_INFORMATION knl;
UINT16 size = 0;

Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **)
&Smb);

if (EFI_ERROR (Status)) {
return Status;
}

Print(L"Status after gBS->LocateProtocol: %r\n", Status);

SmbiosRecord = AllocateZeroPool (sizeof(EFI_SMBIOS_TABLE_HEADER));

Status = Smb->GetNext (Smb, &InSmbiosHandle, &Type, &SmbiosRecord, NULL);

Print(L"Status after SmbiosProtocol->GetNext: %r\n", Status);



if (EFI_ERROR (Status)) {
return Status;
}


Print(L"Smbios In Handle: %d\n", InSmbiosHandle);
Print(L"SmbiosRecord Address : 0X%llx\n", &SmbiosRecord);
Print(L"SmbiosRecord->Type : %d\n", SmbiosRecord->Type);
Print(L"SmbiosRecord->Length : %d\n\n", SmbiosRecord->Length);
Print(L"SmbiosRecord->Handle : %d\n\n", SmbiosRecord->Handle);
Print(L"Sizeof SmbiosRecord : %d\n", sizeof(SmbiosRecord));


FreePool (SmbiosRecord);

return EFI_SUCCESS;


Best Personal Regards,

Aaron Pop
Senior Software Engineer

Phone: +1 858-457-2600 Ext. 318
Fax: +1 858-457-2602 | Email: ***@congatec.com


congatec, Inc. | 6262 Ferris Square | San Diego CA 92121 | USA |
www.congatec.us

Any e-mail sent from congatec may contain information which is
confidential. If you are not the intended recipient, you may not
disclose, copy or use it; please notify the sender immediately and delete
this e-mail and any copies from your systems.




From: Shubha Ramani <***@yahoo.com>
To: "edk2-***@lists.sourceforge.net"
<edk2-***@lists.sourceforge.net>,
Date: 07/23/2015 02:02 PM
Subject: [edk2] GetNext of Smbios protocol not working


Please see corrected code below:


EFI_STATUS
EFIAPI
SmbiosMain (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{

EFI_SMBIOS_PROTOCOL *Smb;
EFI_STATUS Status = EFI_SUCCESS;
EFI_SMBIOS_HANDLE InSmbiosHandle = 0xFFFE;
EFI_SMBIOS_TYPE Type=160;
EFI_SMBIOS_TABLE_HEADER *SmbiosRecord = NULL;
KNL_GENERAL_INFORMATION knl;
UINT16 size = 0;

Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **)
&Smb);

if (EFI_ERROR (Status)) {
return Status;
}

Print(L"Status after gBS->LocateProtocol: %r\n", Status);

SmbiosRecord = AllocateZeroPool (sizeof(EFI_SMBIOS_TABLE_HEADER));

Status = Smb->GetNext (&Smb, &InSmbiosHandle, &Type, &SmbiosRecord,
NULL);

Print(L"Status after SmbiosProtocol->GetNext: %r\n", Status);



if (EFI_ERROR (Status)) {
return Status;
}


Print(L"Smbios In Handle: %d\n", InSmbiosHandle);
Print(L"SmbiosRecord Address : 0X%llx\n", &SmbiosRecord);
Print(L"SmbiosRecord->Type : %d\n", SmbiosRecord->Type);
Print(L"SmbiosRecord->Length : %d\n\n", SmbiosRecord->Length);
Print(L"SmbiosRecord->Handle : %d\n\n", SmbiosRecord->Handle);
Print(L"Sizeof SmbiosRecord : %d\n", sizeof(SmbiosRecord));


FreePool (SmbiosRecord);

return EFI_SUCCESS;



Please see my code below.

If you’ll notice, I’m passing
In EFI_SMBIOS_HANDLE InSmbiosHandle = 0xFFFE; EFI_SMBIOS_TYPE Type=160;
Which is as the header file “Smbios.h” and the protocol implementation
“SmbiosDxe.c”
Instruct. According to my understanding, GetNext should return the address
of the
First table whose Type=160. I used SmbiosView.efi and saw that indeed such
a table
with Type=160 is present. I tried other valid Types too, though and the
result is the same.

What I expect to be returned is the EFI_STATUS of “Success” and the
correct
Address for the SmbiosRecord with type=160. I’m getting neither. I’m
getting an EFI_STATUS
Code of 0xB58FBD02. At the very least, I would expect EFI_NOT_FOUND.
According
To the protocol, this weird 0xB58FBD02 should not be returned for
EFI_STATUS.

I did search archives however, and it seems that others have had problems
with Smbios GetNext,
With no resolution that I saw.

The following two paths are the Smbios Protocol implementation in the
latest EDK2 repo:

C:\edk2\MyWorkspace\MdeModulePkg\Universal\SmbiosDxe\SmbiosDxe.c

C:\edk2\MyWorkspace\MdeModulePkg\Universal\SmbiosDxe\Smbios.h

There is also a shell tool
C:\edk2\MyWorkspace\ShellPkg\Library\UefiShellDebug1CommandsLib\Sm
biosView which does not use the Smbios protocol at all. It seems to use a
backdoor approach of
internal data structures. I wonder why ? Is this because the Smbios
protocol doesn’t work ?

We would like to use the Smbios Protocol because it’s simple and provides
what we need.
We would like to avoid the backdoor approach embraced by Smbiosview if
possible.

Can someone comment on my issue ? Am I using GetNext incorrectly ?

EFI_STATUS
EFIAPI
SmbiosMain (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{

EFI_SMBIOS_PROTOCOL Smb;
EFI_STATUS Status = EFI_SUCCESS;
EFI_SMBIOS_HANDLE InSmbiosHandle = 0xFFFE;
EFI_SMBIOS_TYPE Type=160;
EFI_SMBIOS_TABLE_HEADER *SmbiosRecord = NULL;
KNL_GENERAL_INFORMATION knl;
UINT16 size = 0;

Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **)
&Smb);

if (EFI_ERROR (Status)) {
return Status;
}

Print(L"Status after gBS->LocateProtocol: %r\n", Status);

SmbiosRecord = AllocateZeroPool (sizeof(EFI_SMBIOS_TABLE_HEADER));

Status = Smb.GetNext (&Smb, &InSmbiosHandle, &Type, &SmbiosRecord, NULL);

Print(L"Status after SmbiosProtocol->GetNext: %r\n", Status);



if (EFI_ERROR (Status)) {
return Status;
}


Print(L"Smbios In Handle: %d\n", InSmbiosHandle);
Print(L"SmbiosRecord Address : 0X%llx\n", &SmbiosRecord);
Print(L"SmbiosRecord->Type : %d\n", SmbiosRecord->Type);
Print(L"SmbiosRecord->Length : %d\n\n", SmbiosRecord->Length);
Print(L"SmbiosRecord->Handle : %d\n\n", SmbiosRecord->Handle);
Print(L"Sizeof SmbiosRecord : %d\n", sizeof(SmbiosRecord));


FreePool (SmbiosRecord);

return EFI_SUCCESS;

Shubha D. Ramani
***@gmail.com
***@yahoo.com
------------------------------------------------------------------------------
_______________________________________________
edk2-devel mailing list
edk2-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel
Shubha Ramani
2015-07-23 22:13:39 UTC
Permalink
Thank You ! You are right. My pointer was incorrect and your correction fixed it Aaron. Next question. I'm trying to use CopyMem.Can I do something like this ? It's not working right. Type, Length and Handle in my custom struct are exactly the same types as in (from Smbios.h)
typedef struct {  EFI_SMBIOS_TYPE   Type;  UINT8             Length;  EFI_SMBIOS_HANDLE Handle;} EFI_SMBIOS_TABLE_HEADER;

My custom struct:
#pragma pack(1)
typedef struct _GENERAL_INFORMATION{  UINT8             Type;  UINT8             Length;  UINT16            Handle;  UINT16            MemberIdentifier;  UINT8             MemberName;  UINT8            Field_A  UINT8            Field_B;  UINT8            Field_C;  UINT8            FIeld_D,  UINT8            Field_E;} GENERAL_INFORMATION; #pragma pack()
GENERAL_INFORMATION foo;
CopyMem ((VOID *)&foo, (VOID *)&SmbiosRecord, SmbiosRecord->Length);
 Shubha D. ***@gmail.com
***@yahoo.com


On Thursday, July 23, 2015 2:08 PM, "***@congatec.com" <***@congatec.com> wrote:


Your usage of pointers was incorrect. Pleasesee corrected code below:


EFI_STATUS
EFIAPI
SmbiosMain (
  IN EFI_HANDLE       ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{

  EFI_SMBIOS_PROTOCOL     *Smb;
  EFI_STATUS Status = EFI_SUCCESS;
  EFI_SMBIOS_HANDLE InSmbiosHandle =0xFFFE;
  EFI_SMBIOS_TYPE  Type=160;
  EFI_SMBIOS_TABLE_HEADER   *SmbiosRecord= NULL;
  KNL_GENERAL_INFORMATION knl;
  UINT16 size = 0;
 
  Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid,NULL, (VOID **) &Smb);

  if (EFI_ERROR (Status)) {
    return Status;
  }

   Print(L"Status after  gBS->LocateProtocol:%r\n", Status);

  SmbiosRecord = AllocateZeroPool (sizeof(EFI_SMBIOS_TABLE_HEADER));
 
 Status = Smb->GetNext (Smb, &InSmbiosHandle,&Type, &SmbiosRecord, NULL);

  Print(L"Status after SmbiosProtocol->GetNext:%r\n", Status);
   

 
  if (EFI_ERROR (Status)) {
    return Status;
  }


  Print(L"Smbios In Handle: %d\n",InSmbiosHandle);
  Print(L"SmbiosRecord Address: 0X%llx\n", &SmbiosRecord);
  Print(L"SmbiosRecord->Type: %d\n", SmbiosRecord->Type);
  Print(L"SmbiosRecord->Length: %d\n\n", SmbiosRecord->Length);
   Print(L"SmbiosRecord->Handle: %d\n\n", SmbiosRecord->Handle);
  Print(L"Sizeof SmbiosRecord :%d\n", sizeof(SmbiosRecord));

 
  FreePool (SmbiosRecord);
 
  return EFI_SUCCESS;


Best Personal Regards,

Aaron Pop
Senior Software Engineer

Phone: +1 858-457-2600 Ext. 318
Fax: +1 858-457-2602  |  Email:***@congatec.com


congatec, Inc.  |  6262Ferris Square  |  San Diego CA  92121  |  USA |  www.congatec.us

Any e-mail sent from congatecmay contain information which is confidential. If you are not the intendedrecipient, you may not
disclose, copy or useit; please notify the sender immediately and delete this e-mail and anycopies from your systems.




From:       Shubha Ramani <***@yahoo.com>
To:       "edk2-***@lists.sourceforge.net"<edk2-***@lists.sourceforge.net>,
Date:       07/23/2015 02:02 PM
Subject:       [edk2] GetNextof Smbios protocol not working


Please see corrected code below:


EFI_STATUS
EFIAPI
SmbiosMain (
  IN EFI_HANDLE       ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{

  EFI_SMBIOS_PROTOCOL     *Smb;
  EFI_STATUS Status = EFI_SUCCESS;
  EFI_SMBIOS_HANDLE InSmbiosHandle =0xFFFE;
  EFI_SMBIOS_TYPE  Type=160;
  EFI_SMBIOS_TABLE_HEADER   *SmbiosRecord= NULL;
  KNL_GENERAL_INFORMATION knl;
  UINT16 size = 0;
 
  Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid,NULL, (VOID **) &Smb);

  if (EFI_ERROR (Status)) {
    return Status;
  }

   Print(L"Status after  gBS->LocateProtocol:%r\n", Status);

  SmbiosRecord = AllocateZeroPool (sizeof(EFI_SMBIOS_TABLE_HEADER));
 
 Status = Smb->GetNext (&Smb,&InSmbiosHandle, &Type, &SmbiosRecord, NULL);

  Print(L"Status after SmbiosProtocol->GetNext:%r\n", Status);
   

 
  if (EFI_ERROR (Status)) {
    return Status;
  }


  Print(L"Smbios In Handle: %d\n",InSmbiosHandle);
  Print(L"SmbiosRecord Address: 0X%llx\n", &SmbiosRecord);
  Print(L"SmbiosRecord->Type: %d\n", SmbiosRecord->Type);
  Print(L"SmbiosRecord->Length: %d\n\n", SmbiosRecord->Length);
   Print(L"SmbiosRecord->Handle: %d\n\n", SmbiosRecord->Handle);
  Print(L"Sizeof SmbiosRecord :%d\n", sizeof(SmbiosRecord));

 
  FreePool (SmbiosRecord);
 
  return EFI_SUCCESS;



Please see my code below.

If you’ll notice, I’m passing
In  EFI_SMBIOS_HANDLEInSmbiosHandle = 0xFFFE; EFI_SMBIOS_TYPE  Type=160;
Which is as the header file “Smbios.h”and the protocol implementation “SmbiosDxe.c”
Instruct. According to my understanding,GetNext should return the address of the
First table whose Type=160. I used SmbiosView.efiand saw that indeed such a table
with Type=160 is present. I tried other validTypes too, though and the result is the same.
 
What I expect to be returned is the EFI_STATUSof “Success” and the correct
Address for the SmbiosRecord with type=160.I’m getting neither. I’m getting an EFI_STATUS
Code of 0xB58FBD02. At the very least, Iwould expect EFI_NOT_FOUND. According
To the protocol, this weird 0xB58FBD02 shouldnot be returned for EFI_STATUS.

I did search archives however, and it seemsthat others have had problems with Smbios GetNext,
With no resolution that I saw.
 
The following two paths are the Smbios Protocolimplementation in the latest EDK2 repo:
 
C:\edk2\MyWorkspace\MdeModulePkg\Universal\SmbiosDxe\SmbiosDxe.c
 
C:\edk2\MyWorkspace\MdeModulePkg\Universal\SmbiosDxe\Smbios.h
 
There is also a  shell tool C:\edk2\MyWorkspace\ShellPkg\Library\UefiShellDebug1CommandsLib\Sm
biosView which does not use the Smbios protocolat all. It seems to use a backdoor approach of
internal data structures. I wonder why ?Is this because the Smbios protocol doesn’t work ?
 
We would like to use the Smbios Protocolbecause it’s simple and provides what we need.
We would like to avoid the backdoor approachembraced by Smbiosview if possible.
 
Can someone comment on my issue ? Am I usingGetNext incorrectly ?
 
EFI_STATUS
EFIAPI
SmbiosMain (
  IN EFI_HANDLE       ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{

  EFI_SMBIOS_PROTOCOL     Smb;
  EFI_STATUS Status = EFI_SUCCESS;
  EFI_SMBIOS_HANDLE InSmbiosHandle =0xFFFE;
  EFI_SMBIOS_TYPE  Type=160;
  EFI_SMBIOS_TABLE_HEADER   *SmbiosRecord= NULL;
  KNL_GENERAL_INFORMATION knl;
  UINT16 size = 0;
 
  Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid,NULL, (VOID **) &Smb);

  if (EFI_ERROR (Status)) {
    return Status;
  }

   Print(L"Status after  gBS->LocateProtocol:%r\n", Status);

  SmbiosRecord = AllocateZeroPool (sizeof(EFI_SMBIOS_TABLE_HEADER));
 
 Status = Smb.GetNext (&Smb, &InSmbiosHandle,&Type, &SmbiosRecord, NULL);

  Print(L"Status after SmbiosProtocol->GetNext:%r\n", Status);
   

 
  if (EFI_ERROR (Status)) {
    return Status;
  }


  Print(L"Smbios In Handle: %d\n",InSmbiosHandle);
  Print(L"SmbiosRecord Address: 0X%llx\n", &SmbiosRecord);
  Print(L"SmbiosRecord->Type: %d\n", SmbiosRecord->Type);
  Print(L"SmbiosRecord->Length: %d\n\n", SmbiosRecord->Length);
   Print(L"SmbiosRecord->Handle: %d\n\n", SmbiosRecord->Handle);
  Print(L"Sizeof SmbiosRecord :%d\n", sizeof(SmbiosRecord));

 
  FreePool (SmbiosRecord);
 
  return EFI_SUCCESS;
 
Shubha D. Ramani
***@gmail.com
***@yahoo.com------------------------------------------------------------------------------
Andrew Fish
2015-07-23 22:31:03 UTC
Permalink
Post by Shubha Ramani
Thank You ! You are right. My pointer was incorrect and your correction fixed it Aaron. Next question. I'm trying to use CopyMem.
Can I do something like this ? It's not working right. Type, Length and Handle in my custom struct are exactly the same types as in (from Smbios.h)
You are probably corrupting the stack with a buffer overflow on foo.

CopyMem ((VOID *)&foo, (VOID *)&SmbiosRecord, MIN (SmbiosRecord->Length, sizeof (GENERAL_INFORMATION));

EFI_SMBIOS_TABLE_HEADER.Length is the length of the entire SMBIOS structure, not the header. If you just want the header it would we be sizeof (EFI_SMBIOS_TABLE_HEADER).

Sp just standard C bugs.

Thanks,

Andrew Fish
Post by Shubha Ramani
typedef struct {
EFI_SMBIOS_TYPE Type;
UINT8 Length;
EFI_SMBIOS_HANDLE Handle;
} EFI_SMBIOS_TABLE_HEADER;
#pragma pack(1)
typedef struct _GENERAL_INFORMATION{
UINT8 Type;
UINT8 Length;
UINT16 Handle;
UINT16 MemberIdentifier;
UINT8 MemberName;
UINT8 Field_A
UINT8 Field_B;
UINT8 Field_C;
UINT8 FIeld_D,
UINT8 Field_E;
} GENERAL_INFORMATION;
#pragma pack()
GENERAL_INFORMATION foo;
CopyMem ((VOID *)&foo, (VOID *)&SmbiosRecord, SmbiosRecord->Length);
Shubha D. Ramani
EFI_STATUS
EFIAPI
SmbiosMain (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_SMBIOS_PROTOCOL *Smb;
EFI_STATUS Status = EFI_SUCCESS;
EFI_SMBIOS_HANDLE InSmbiosHandle = 0xFFFE;
EFI_SMBIOS_TYPE Type=160;
EFI_SMBIOS_TABLE_HEADER *SmbiosRecord = NULL;
KNL_GENERAL_INFORMATION knl;
UINT16 size = 0;
Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **) &Smb);
if (EFI_ERROR (Status)) {
return Status;
}
Print(L"Status after gBS->LocateProtocol: %r\n", Status);
SmbiosRecord = AllocateZeroPool (sizeof(EFI_SMBIOS_TABLE_HEADER));
Status = Smb->GetNext (Smb, &InSmbiosHandle, &Type, &SmbiosRecord, NULL);
Print(L"Status after SmbiosProtocol->GetNext: %r\n", Status);
if (EFI_ERROR (Status)) {
return Status;
}
Print(L"Smbios In Handle: %d\n", InSmbiosHandle);
Print(L"SmbiosRecord Address : 0X%llx\n", &SmbiosRecord);
Print(L"SmbiosRecord->Type : %d\n", SmbiosRecord->Type);
Print(L"SmbiosRecord->Length : %d\n\n", SmbiosRecord->Length);
Print(L"SmbiosRecord->Handle : %d\n\n", SmbiosRecord->Handle);
Print(L"Sizeof SmbiosRecord : %d\n", sizeof(SmbiosRecord));
FreePool (SmbiosRecord);
return EFI_SUCCESS;
Best Personal Regards,
Aaron Pop
Senior Software Engineer
Phone: +1 858-457-2600 Ext. 318
<Mail Attachment.gif>
congatec, Inc. | 6262 Ferris Square | San Diego CA 92121 | USA | www.congatec.us <http://www.congatec.us/>
Any e-mail sent from congatec may contain information which is confidential. If you are not the intended recipient, you may not
disclose, copy or use it; please notify the sender immediately and delete this e-mail and any copies from your systems.
Date: 07/23/2015 02:02 PM
Subject: [edk2] GetNext of Smbios protocol not working
EFI_STATUS
EFIAPI
SmbiosMain (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_SMBIOS_PROTOCOL *Smb;
EFI_STATUS Status = EFI_SUCCESS;
EFI_SMBIOS_HANDLE InSmbiosHandle = 0xFFFE;
EFI_SMBIOS_TYPE Type=160;
EFI_SMBIOS_TABLE_HEADER *SmbiosRecord = NULL;
KNL_GENERAL_INFORMATION knl;
UINT16 size = 0;
Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **) &Smb);
if (EFI_ERROR (Status)) {
return Status;
}
Print(L"Status after gBS->LocateProtocol: %r\n", Status);
SmbiosRecord = AllocateZeroPool (sizeof(EFI_SMBIOS_TABLE_HEADER));
Status = Smb->GetNext (&Smb, &InSmbiosHandle, &Type, &SmbiosRecord, NULL);
Print(L"Status after SmbiosProtocol->GetNext: %r\n", Status);
if (EFI_ERROR (Status)) {
return Status;
}
Print(L"Smbios In Handle: %d\n", InSmbiosHandle);
Print(L"SmbiosRecord Address : 0X%llx\n", &SmbiosRecord);
Print(L"SmbiosRecord->Type : %d\n", SmbiosRecord->Type);
Print(L"SmbiosRecord->Length : %d\n\n", SmbiosRecord->Length);
Print(L"SmbiosRecord->Handle : %d\n\n", SmbiosRecord->Handle);
Print(L"Sizeof SmbiosRecord : %d\n", sizeof(SmbiosRecord));
FreePool (SmbiosRecord);
return EFI_SUCCESS;
Please see my code below.
If you’ll notice, I’m passing
In EFI_SMBIOS_HANDLE InSmbiosHandle = 0xFFFE; EFI_SMBIOS_TYPE Type=160;
Which is as the header file “Smbios.h” and the protocol implementation “SmbiosDxe.c”
Instruct. According to my understanding, GetNext should return the address of the
First table whose Type=160. I used SmbiosView.efi and saw that indeed such a table
with Type=160 is present. I tried other valid Types too, though and the result is the same.
What I expect to be returned is the EFI_STATUS of “Success” and the correct
Address for the SmbiosRecord with type=160. I’m getting neither. I’m getting an EFI_STATUS
Code of 0xB58FBD02. At the very least, I would expect EFI_NOT_FOUND. According
To the protocol, this weird 0xB58FBD02 should not be returned for EFI_STATUS.
I did search archives however, and it seems that others have had problems with Smbios GetNext,
With no resolution that I saw.
C:\edk2\MyWorkspace\MdeModulePkg\Universal\SmbiosDxe\SmbiosDxe.c
C:\edk2\MyWorkspace\MdeModulePkg\Universal\SmbiosDxe\Smbios.h
There is also a shell tool C:\edk2\MyWorkspace\ShellPkg\Library\UefiShellDebug1CommandsLib\Sm
biosView which does not use the Smbios protocol at all. It seems to use a backdoor approach of
internal data structures. I wonder why ? Is this because the Smbios protocol doesn’t work ?
We would like to use the Smbios Protocol because it’s simple and provides what we need.
We would like to avoid the backdoor approach embraced by Smbiosview if possible.
Can someone comment on my issue ? Am I using GetNext incorrectly ?
EFI_STATUS
EFIAPI
SmbiosMain (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_SMBIOS_PROTOCOL Smb;
EFI_STATUS Status = EFI_SUCCESS;
EFI_SMBIOS_HANDLE InSmbiosHandle = 0xFFFE;
EFI_SMBIOS_TYPE Type=160;
EFI_SMBIOS_TABLE_HEADER *SmbiosRecord = NULL;
KNL_GENERAL_INFORMATION knl;
UINT16 size = 0;
Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **) &Smb);
if (EFI_ERROR (Status)) {
return Status;
}
Print(L"Status after gBS->LocateProtocol: %r\n", Status);
SmbiosRecord = AllocateZeroPool (sizeof(EFI_SMBIOS_TABLE_HEADER));
Status = Smb.GetNext (&Smb, &InSmbiosHandle, &Type, &SmbiosRecord, NULL);
Print(L"Status after SmbiosProtocol->GetNext: %r\n", Status);
if (EFI_ERROR (Status)) {
return Status;
}
Print(L"Smbios In Handle: %d\n", InSmbiosHandle);
Print(L"SmbiosRecord Address : 0X%llx\n", &SmbiosRecord);
Print(L"SmbiosRecord->Type : %d\n", SmbiosRecord->Type);
Print(L"SmbiosRecord->Length : %d\n\n", SmbiosRecord->Length);
Print(L"SmbiosRecord->Handle : %d\n\n", SmbiosRecord->Handle);
Print(L"Sizeof SmbiosRecord : %d\n", sizeof(SmbiosRecord));
FreePool (SmbiosRecord);
return EFI_SUCCESS;
Shubha D. Ramani
_______________________________________________
edk2-devel mailing list
https://lists.sourceforge.net/lists/listinfo/edk2-devel <https://lists.sourceforge.net/lists/listinfo/edk2-devel>
<Mail Attachment.gif>------------------------------------------------------------------------------
_______________________________________________
edk2-devel mailing list
https://lists.sourceforge.net/lists/listinfo/edk2-devel
Shubha Ramani
2015-07-23 22:37:18 UTC
Permalink
I actually do want the size of the entire SMBIOS structure. It should match sizeof (GENERAL_INFORMATION) and it in fact does.That's why I'm confused. Maybe I need to AllocateZeroPool for foo and not create it on the stack ? I don't see how that would makea difference but I'll try it. Shubha D. ***@gmail.com
***@yahoo.com


On Thursday, July 23, 2015 3:31 PM, Andrew Fish <***@apple.com> wrote:




On Jul 23, 2015, at 3:13 PM, Shubha Ramani <***@yahoo.com> wrote:
Thank You ! You are right. My pointer was incorrect and your correction fixed it Aaron. Next question. I'm trying to use CopyMem.Can I do something like this ? It's not working right. Type, Length and Handle in my custom struct are exactly the same types as in (from Smbios.h)


You are probably corrupting the stack with a buffer overflow on foo. 
CopyMem ((VOID *)&foo, (VOID *)&SmbiosRecord, MIN (SmbiosRecord->Length, sizeof (GENERAL_INFORMATION));
EFI_SMBIOS_TABLE_HEADER.Length is the length of the entire SMBIOS structure, not the header. If you just want the header it would we be sizeof (EFI_SMBIOS_TABLE_HEADER).
Sp just standard C bugs.
Thanks,
Andrew Fish


typedef struct {  EFI_SMBIOS_TYPE   Type;  UINT8             Length;  EFI_SMBIOS_HANDLE Handle;} EFI_SMBIOS_TABLE_HEADER;

My custom struct:
#pragma pack(1)
typedef struct _GENERAL_INFORMATION{  UINT8             Type;  UINT8             Length;  UINT16            Handle;  UINT16            MemberIdentifier;  UINT8             MemberName;  UINT8            Field_A  UINT8            Field_B;  UINT8            Field_C;  UINT8            FIeld_D,  UINT8            Field_E;} GENERAL_INFORMATION; #pragma pack()
GENERAL_INFORMATION foo;
CopyMem ((VOID *)&foo, (VOID *)&SmbiosRecord, SmbiosRecord->Length);
 Shubha D. ***@gmail.com
***@yahoo.com


On Thursday, July 23, 2015 2:08 PM, "***@congatec.com" <***@congatec.com> wrote:


Your usage of pointers was incorrect. Pleasesee corrected code below:


EFI_STATUS
EFIAPI
SmbiosMain (
  IN EFI_HANDLE       ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{

  EFI_SMBIOS_PROTOCOL     *Smb;
  EFI_STATUS Status = EFI_SUCCESS;
  EFI_SMBIOS_HANDLE InSmbiosHandle =0xFFFE;
  EFI_SMBIOS_TYPE  Type=160;
  EFI_SMBIOS_TABLE_HEADER   *SmbiosRecord= NULL;
  KNL_GENERAL_INFORMATION knl;
  UINT16 size = 0;
 
  Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid,NULL, (VOID **) &Smb);

  if (EFI_ERROR (Status)) {
    return Status;
  }

   Print(L"Status after  gBS->LocateProtocol:%r\n", Status);

  SmbiosRecord = AllocateZeroPool (sizeof(EFI_SMBIOS_TABLE_HEADER));
 
 Status = Smb->GetNext (Smb, &InSmbiosHandle,&Type, &SmbiosRecord, NULL);

  Print(L"Status after SmbiosProtocol->GetNext:%r\n", Status);
   

 
  if (EFI_ERROR (Status)) {
    return Status;
  }


  Print(L"Smbios In Handle: %d\n",InSmbiosHandle);
  Print(L"SmbiosRecord Address: 0X%llx\n", &SmbiosRecord);
  Print(L"SmbiosRecord->Type: %d\n", SmbiosRecord->Type);
  Print(L"SmbiosRecord->Length: %d\n\n", SmbiosRecord->Length);
   Print(L"SmbiosRecord->Handle: %d\n\n", SmbiosRecord->Handle);
  Print(L"Sizeof SmbiosRecord :%d\n", sizeof(SmbiosRecord));

 
  FreePool (SmbiosRecord);
 
  return EFI_SUCCESS;


Best Personal Regards,

Aaron Pop
Senior Software Engineer

Phone: +1 858-457-2600 Ext. 318
Fax: +1 858-457-2602  |  Email:***@congatec.com

<Mail Attachment.gif>
congatec, Inc.  |  6262Ferris Square  |  San Diego CA  92121  |  USA |  www.congatec.us

Any e-mail sent from congatecmay contain information which is confidential. If you are not the intendedrecipient, you may not
disclose, copy or useit; please notify the sender immediately and delete this e-mail and anycopies from your systems.




From:       Shubha Ramani <***@yahoo.com>
To:       "edk2-***@lists.sourceforge.net"<edk2-***@lists.sourceforge.net>,
Date:       07/23/2015 02:02 PM
Subject:       [edk2] GetNextof Smbios protocol not working


Please see corrected code below:


EFI_STATUS
EFIAPI
SmbiosMain (
  IN EFI_HANDLE       ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{

  EFI_SMBIOS_PROTOCOL     *Smb;
  EFI_STATUS Status = EFI_SUCCESS;
  EFI_SMBIOS_HANDLE InSmbiosHandle =0xFFFE;
  EFI_SMBIOS_TYPE  Type=160;
  EFI_SMBIOS_TABLE_HEADER   *SmbiosRecord= NULL;
  KNL_GENERAL_INFORMATION knl;
  UINT16 size = 0;
 
  Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid,NULL, (VOID **) &Smb);

  if (EFI_ERROR (Status)) {
    return Status;
  }

   Print(L"Status after  gBS->LocateProtocol:%r\n", Status);

  SmbiosRecord = AllocateZeroPool (sizeof(EFI_SMBIOS_TABLE_HEADER));
 
 Status = Smb->GetNext (&Smb,&InSmbiosHandle, &Type, &SmbiosRecord, NULL);

  Print(L"Status after SmbiosProtocol->GetNext:%r\n", Status);
   

 
  if (EFI_ERROR (Status)) {
    return Status;
  }


  Print(L"Smbios In Handle: %d\n",InSmbiosHandle);
  Print(L"SmbiosRecord Address: 0X%llx\n", &SmbiosRecord);
  Print(L"SmbiosRecord->Type: %d\n", SmbiosRecord->Type);
  Print(L"SmbiosRecord->Length: %d\n\n", SmbiosRecord->Length);
   Print(L"SmbiosRecord->Handle: %d\n\n", SmbiosRecord->Handle);
  Print(L"Sizeof SmbiosRecord :%d\n", sizeof(SmbiosRecord));

 
  FreePool (SmbiosRecord);
 
  return EFI_SUCCESS;



Please see my code below.

If you’ll notice, I’m passing
In  EFI_SMBIOS_HANDLEInSmbiosHandle = 0xFFFE; EFI_SMBIOS_TYPE  Type=160;
Which is as the header file “Smbios.h”and the protocol implementation “SmbiosDxe.c”
Instruct. According to my understanding,GetNext should return the address of the
First table whose Type=160. I used SmbiosView.efiand saw that indeed such a table
with Type=160 is present. I tried other validTypes too, though and the result is the same.
 
What I expect to be returned is the EFI_STATUSof “Success” and the correct
Address for the SmbiosRecord with type=160.I’m getting neither. I’m getting an EFI_STATUS
Code of 0xB58FBD02. At the very least, Iwould expect EFI_NOT_FOUND. According
To the protocol, this weird 0xB58FBD02 shouldnot be returned for EFI_STATUS.

I did search archives however, and it seemsthat others have had problems with Smbios GetNext,
With no resolution that I saw.
 
The following two paths are the Smbios Protocolimplementation in the latest EDK2 repo:
 
C:\edk2\MyWorkspace\MdeModulePkg\Universal\SmbiosDxe\SmbiosDxe.c
 
C:\edk2\MyWorkspace\MdeModulePkg\Universal\SmbiosDxe\Smbios.h
 
There is also a  shell tool C:\edk2\MyWorkspace\ShellPkg\Library\UefiShellDebug1CommandsLib\Sm
biosView which does not use the Smbios protocolat all. It seems to use a backdoor approach of
internal data structures. I wonder why ?Is this because the Smbios protocol doesn’t work ?
 
We would like to use the Smbios Protocolbecause it’s simple and provides what we need.
We would like to avoid the backdoor approachembraced by Smbiosview if possible.
 
Can someone comment on my issue ? Am I usingGetNext incorrectly ?
 
EFI_STATUS
EFIAPI
SmbiosMain (
  IN EFI_HANDLE       ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{

  EFI_SMBIOS_PROTOCOL     Smb;
  EFI_STATUS Status = EFI_SUCCESS;
  EFI_SMBIOS_HANDLE InSmbiosHandle =0xFFFE;
  EFI_SMBIOS_TYPE  Type=160;
  EFI_SMBIOS_TABLE_HEADER   *SmbiosRecord= NULL;
  KNL_GENERAL_INFORMATION knl;
  UINT16 size = 0;
 
  Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid,NULL, (VOID **) &Smb);

  if (EFI_ERROR (Status)) {
    return Status;
  }

   Print(L"Status after  gBS->LocateProtocol:%r\n", Status);

  SmbiosRecord = AllocateZeroPool (sizeof(EFI_SMBIOS_TABLE_HEADER));
 
 Status = Smb.GetNext (&Smb, &InSmbiosHandle,&Type, &SmbiosRecord, NULL);

  Print(L"Status after SmbiosProtocol->GetNext:%r\n", Status);
   

 
  if (EFI_ERROR (Status)) {
    return Status;
  }


  Print(L"Smbios In Handle: %d\n",InSmbiosHandle);
  Print(L"SmbiosRecord Address: 0X%llx\n", &SmbiosRecord);
  Print(L"SmbiosRecord->Type: %d\n", SmbiosRecord->Type);
  Print(L"SmbiosRecord->Length: %d\n\n", SmbiosRecord->Length);
   Print(L"SmbiosRecord->Handle: %d\n\n", SmbiosRecord->Handle);
  Print(L"Sizeof SmbiosRecord :%d\n", sizeof(SmbiosRecord));

 
  FreePool (SmbiosRecord);
 
  return EFI_SUCCESS;
 
Shubha D. Ramani
***@gmail.com
***@yahoo.com------------------------------------------------------------------------------
_______________________________________________
edk2-devel mailing list
edk2-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel



<Mail Attachment.gif>------------------------------------------------------------------------------
Shubha Ramani
2015-07-23 22:49:12 UTC
Permalink
That's all it was. The stack was getting corrupted ! When I used AllocateZeroPool instead, it worked.Thanks for the tip Andrew.
Shubha Shubha D. ***@gmail.com
***@yahoo.com


On Thursday, July 23, 2015 3:37 PM, Shubha Ramani <***@yahoo.com> wrote:


I actually do want the size of the entire SMBIOS structure. It should match sizeof (GENERAL_INFORMATION) and it in fact does.That's why I'm confused. Maybe I need to AllocateZeroPool for foo and not create it on the stack ? I don't see how that would makea difference but I'll try it. Shubha D. ***@gmail.com
***@yahoo.com


On Thursday, July 23, 2015 3:31 PM, Andrew Fish <***@apple.com> wrote:




On Jul 23, 2015, at 3:13 PM, Shubha Ramani <***@yahoo.com> wrote:
Thank You ! You are right. My pointer was incorrect and your correction fixed it Aaron. Next question. I'm trying to use CopyMem.Can I do something like this ? It's not working right. Type, Length and Handle in my custom struct are exactly the same types as in (from Smbios.h)


You are probably corrupting the stack with a buffer overflow on foo. 
CopyMem ((VOID *)&foo, (VOID *)&SmbiosRecord, MIN (SmbiosRecord->Length, sizeof (GENERAL_INFORMATION));
EFI_SMBIOS_TABLE_HEADER.Length is the length of the entire SMBIOS structure, not the header. If you just want the header it would we be sizeof (EFI_SMBIOS_TABLE_HEADER).
Sp just standard C bugs.
Thanks,
Andrew Fish


typedef struct {  EFI_SMBIOS_TYPE   Type;  UINT8             Length;  EFI_SMBIOS_HANDLE Handle;} EFI_SMBIOS_TABLE_HEADER;

My custom struct:
#pragma pack(1)
typedef struct _GENERAL_INFORMATION{  UINT8             Type;  UINT8             Length;  UINT16            Handle;  UINT16            MemberIdentifier;  UINT8             MemberName;  UINT8            Field_A  UINT8            Field_B;  UINT8            Field_C;  UINT8            FIeld_D,  UINT8            Field_E;} GENERAL_INFORMATION; #pragma pack()
GENERAL_INFORMATION foo;
CopyMem ((VOID *)&foo, (VOID *)&SmbiosRecord, SmbiosRecord->Length);
 Shubha D. ***@gmail.com
***@yahoo.com


On Thursday, July 23, 2015 2:08 PM, "***@congatec.com" <***@congatec.com> wrote:


Your usage of pointers was incorrect. Pleasesee corrected code below:


EFI_STATUS
EFIAPI
SmbiosMain (
  IN EFI_HANDLE       ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{

  EFI_SMBIOS_PROTOCOL     *Smb;
  EFI_STATUS Status = EFI_SUCCESS;
  EFI_SMBIOS_HANDLE InSmbiosHandle =0xFFFE;
  EFI_SMBIOS_TYPE  Type=160;
  EFI_SMBIOS_TABLE_HEADER   *SmbiosRecord= NULL;
  KNL_GENERAL_INFORMATION knl;
  UINT16 size = 0;
 
  Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid,NULL, (VOID **) &Smb);

  if (EFI_ERROR (Status)) {
    return Status;
  }

   Print(L"Status after  gBS->LocateProtocol:%r\n", Status);

  SmbiosRecord = AllocateZeroPool (sizeof(EFI_SMBIOS_TABLE_HEADER));
 
 Status = Smb->GetNext (Smb, &InSmbiosHandle,&Type, &SmbiosRecord, NULL);

  Print(L"Status after SmbiosProtocol->GetNext:%r\n", Status);
   

 
  if (EFI_ERROR (Status)) {
    return Status;
  }


  Print(L"Smbios In Handle: %d\n",InSmbiosHandle);
  Print(L"SmbiosRecord Address: 0X%llx\n", &SmbiosRecord);
  Print(L"SmbiosRecord->Type: %d\n", SmbiosRecord->Type);
  Print(L"SmbiosRecord->Length: %d\n\n", SmbiosRecord->Length);
   Print(L"SmbiosRecord->Handle: %d\n\n", SmbiosRecord->Handle);
  Print(L"Sizeof SmbiosRecord :%d\n", sizeof(SmbiosRecord));

 
  FreePool (SmbiosRecord);
 
  return EFI_SUCCESS;


Best Personal Regards,

Aaron Pop
Senior Software Engineer

Phone: +1 858-457-2600 Ext. 318
Fax: +1 858-457-2602  |  Email:***@congatec.com

<Mail Attachment.gif>
congatec, Inc.  |  6262Ferris Square  |  San Diego CA  92121  |  USA |  www.congatec.us

Any e-mail sent from congatecmay contain information which is confidential. If you are not the intendedrecipient, you may not
disclose, copy or useit; please notify the sender immediately and delete this e-mail and anycopies from your systems.




From:       Shubha Ramani <***@yahoo.com>
To:       "edk2-***@lists.sourceforge.net"<edk2-***@lists.sourceforge.net>,
Date:       07/23/2015 02:02 PM
Subject:       [edk2] GetNextof Smbios protocol not working


Please see corrected code below:


EFI_STATUS
EFIAPI
SmbiosMain (
  IN EFI_HANDLE       ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{

  EFI_SMBIOS_PROTOCOL     *Smb;
  EFI_STATUS Status = EFI_SUCCESS;
  EFI_SMBIOS_HANDLE InSmbiosHandle =0xFFFE;
  EFI_SMBIOS_TYPE  Type=160;
  EFI_SMBIOS_TABLE_HEADER   *SmbiosRecord= NULL;
  KNL_GENERAL_INFORMATION knl;
  UINT16 size = 0;
 
  Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid,NULL, (VOID **) &Smb);

  if (EFI_ERROR (Status)) {
    return Status;
  }

   Print(L"Status after  gBS->LocateProtocol:%r\n", Status);

  SmbiosRecord = AllocateZeroPool (sizeof(EFI_SMBIOS_TABLE_HEADER));
 
 Status = Smb->GetNext (&Smb,&InSmbiosHandle, &Type, &SmbiosRecord, NULL);

  Print(L"Status after SmbiosProtocol->GetNext:%r\n", Status);
   

 
  if (EFI_ERROR (Status)) {
    return Status;
  }


  Print(L"Smbios In Handle: %d\n",InSmbiosHandle);
  Print(L"SmbiosRecord Address: 0X%llx\n", &SmbiosRecord);
  Print(L"SmbiosRecord->Type: %d\n", SmbiosRecord->Type);
  Print(L"SmbiosRecord->Length: %d\n\n", SmbiosRecord->Length);
   Print(L"SmbiosRecord->Handle: %d\n\n", SmbiosRecord->Handle);
  Print(L"Sizeof SmbiosRecord :%d\n", sizeof(SmbiosRecord));

 
  FreePool (SmbiosRecord);
 
  return EFI_SUCCESS;



Please see my code below.

If you’ll notice, I’m passing
In  EFI_SMBIOS_HANDLEInSmbiosHandle = 0xFFFE; EFI_SMBIOS_TYPE  Type=160;
Which is as the header file “Smbios.h”and the protocol implementation “SmbiosDxe.c”
Instruct. According to my understanding,GetNext should return the address of the
First table whose Type=160. I used SmbiosView.efiand saw that indeed such a table
with Type=160 is present. I tried other validTypes too, though and the result is the same.
 
What I expect to be returned is the EFI_STATUSof “Success” and the correct
Address for the SmbiosRecord with type=160.I’m getting neither. I’m getting an EFI_STATUS
Code of 0xB58FBD02. At the very least, Iwould expect EFI_NOT_FOUND. According
To the protocol, this weird 0xB58FBD02 shouldnot be returned for EFI_STATUS.

I did search archives however, and it seemsthat others have had problems with Smbios GetNext,
With no resolution that I saw.
 
The following two paths are the Smbios Protocolimplementation in the latest EDK2 repo:
 
C:\edk2\MyWorkspace\MdeModulePkg\Universal\SmbiosDxe\SmbiosDxe.c
 
C:\edk2\MyWorkspace\MdeModulePkg\Universal\SmbiosDxe\Smbios.h
 
There is also a  shell tool C:\edk2\MyWorkspace\ShellPkg\Library\UefiShellDebug1CommandsLib\Sm
biosView which does not use the Smbios protocolat all. It seems to use a backdoor approach of
internal data structures. I wonder why ?Is this because the Smbios protocol doesn’t work ?
 
We would like to use the Smbios Protocolbecause it’s simple and provides what we need.
We would like to avoid the backdoor approachembraced by Smbiosview if possible.
 
Can someone comment on my issue ? Am I usingGetNext incorrectly ?
 
EFI_STATUS
EFIAPI
SmbiosMain (
  IN EFI_HANDLE       ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{

  EFI_SMBIOS_PROTOCOL     Smb;
  EFI_STATUS Status = EFI_SUCCESS;
  EFI_SMBIOS_HANDLE InSmbiosHandle =0xFFFE;
  EFI_SMBIOS_TYPE  Type=160;
  EFI_SMBIOS_TABLE_HEADER   *SmbiosRecord= NULL;
  KNL_GENERAL_INFORMATION knl;
  UINT16 size = 0;
 
  Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid,NULL, (VOID **) &Smb);

  if (EFI_ERROR (Status)) {
    return Status;
  }

   Print(L"Status after  gBS->LocateProtocol:%r\n", Status);

  SmbiosRecord = AllocateZeroPool (sizeof(EFI_SMBIOS_TABLE_HEADER));
 
 Status = Smb.GetNext (&Smb, &InSmbiosHandle,&Type, &SmbiosRecord, NULL);

  Print(L"Status after SmbiosProtocol->GetNext:%r\n", Status);
   

 
  if (EFI_ERROR (Status)) {
    return Status;
  }


  Print(L"Smbios In Handle: %d\n",InSmbiosHandle);
  Print(L"SmbiosRecord Address: 0X%llx\n", &SmbiosRecord);
  Print(L"SmbiosRecord->Type: %d\n", SmbiosRecord->Type);
  Print(L"SmbiosRecord->Length: %d\n\n", SmbiosRecord->Length);
   Print(L"SmbiosRecord->Handle: %d\n\n", SmbiosRecord->Handle);
  Print(L"Sizeof SmbiosRecord :%d\n", sizeof(SmbiosRecord));

 
  FreePool (SmbiosRecord);
 
  return EFI_SUCCESS;
 
Shubha D. Ramani
***@gmail.com
***@yahoo.com------------------------------------------------------------------------------
_______________________________________________
edk2-devel mailing list
edk2-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel



<Mail Attachment.gif>------------------------------------------------------------------------------
Andrew Fish
2015-07-23 22:56:40 UTC
Permalink
Post by Shubha Ramani
I actually do want the size of the entire SMBIOS structure. It should match sizeof (GENERAL_INFORMATION) and it in fact does.
That's why I'm confused. Maybe I need to AllocateZeroPool for foo and not create it on the stack ? I don't see how that would make
a difference but I'll try it.
Looks like pointer corruption to me. You really should assume your code is broken 1st, and not start trying random other APIs. You may get lucky and leave a time bomb for the developer that ends up having to maintain the code in the future.

The code should be either:
SmbiosRecord, SmbiosRecord->Length
&SmbiosRecord, SmbiosRecord.Lenght

or

Just use:

https://github.com/tianocore/edk2/blob/master/MdePkg/Include/IndustryStandard/SmBios.h as it defined SMBIOS_STRUCTURE_POINTER.

All the spec based data structures already have types, that have been tested.

Thanks,

Andrew Fish
Post by Shubha Ramani
Shubha D. Ramani
Post by Shubha Ramani
Thank You ! You are right. My pointer was incorrect and your correction fixed it Aaron. Next question. I'm trying to use CopyMem.
Can I do something like this ? It's not working right. Type, Length and Handle in my custom struct are exactly the same types as in (from Smbios.h)
You are probably corrupting the stack with a buffer overflow on foo.
CopyMem ((VOID *)&foo, (VOID *)&SmbiosRecord, MIN (SmbiosRecord->Length, sizeof (GENERAL_INFORMATION));
EFI_SMBIOS_TABLE_HEADER.Length is the length of the entire SMBIOS structure, not the header. If you just want the header it would we be sizeof (EFI_SMBIOS_TABLE_HEADER).
Sp just standard C bugs.
Thanks,
Andrew Fish
Post by Shubha Ramani
typedef struct {
EFI_SMBIOS_TYPE Type;
UINT8 Length;
EFI_SMBIOS_HANDLE Handle;
} EFI_SMBIOS_TABLE_HEADER;
#pragma pack(1)
typedef struct _GENERAL_INFORMATION{
UINT8 Type;
UINT8 Length;
UINT16 Handle;
UINT16 MemberIdentifier;
UINT8 MemberName;
UINT8 Field_A
UINT8 Field_B;
UINT8 Field_C;
UINT8 FIeld_D,
UINT8 Field_E;
} GENERAL_INFORMATION;
#pragma pack()
GENERAL_INFORMATION foo;
CopyMem ((VOID *)&foo, (VOID *)&SmbiosRecord, SmbiosRecord->Length);
Shubha D. Ramani
EFI_STATUS
EFIAPI
SmbiosMain (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_SMBIOS_PROTOCOL *Smb;
EFI_STATUS Status = EFI_SUCCESS;
EFI_SMBIOS_HANDLE InSmbiosHandle = 0xFFFE;
EFI_SMBIOS_TYPE Type=160;
EFI_SMBIOS_TABLE_HEADER *SmbiosRecord = NULL;
KNL_GENERAL_INFORMATION knl;
UINT16 size = 0;
Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **) &Smb);
if (EFI_ERROR (Status)) {
return Status;
}
Print(L"Status after gBS->LocateProtocol: %r\n", Status);
SmbiosRecord = AllocateZeroPool (sizeof(EFI_SMBIOS_TABLE_HEADER));
Status = Smb->GetNext (Smb, &InSmbiosHandle, &Type, &SmbiosRecord, NULL);
Print(L"Status after SmbiosProtocol->GetNext: %r\n", Status);
if (EFI_ERROR (Status)) {
return Status;
}
Print(L"Smbios In Handle: %d\n", InSmbiosHandle);
Print(L"SmbiosRecord Address : 0X%llx\n", &SmbiosRecord);
Print(L"SmbiosRecord->Type : %d\n", SmbiosRecord->Type);
Print(L"SmbiosRecord->Length : %d\n\n", SmbiosRecord->Length);
Print(L"SmbiosRecord->Handle : %d\n\n", SmbiosRecord->Handle);
Print(L"Sizeof SmbiosRecord : %d\n", sizeof(SmbiosRecord));
FreePool (SmbiosRecord);
return EFI_SUCCESS;
Best Personal Regards,
Aaron Pop
Senior Software Engineer
Phone: +1 858-457-2600 Ext. 318
<Mail Attachment.gif>
congatec, Inc. | 6262 Ferris Square | San Diego CA 92121 | USA | www.congatec.us <http://www.congatec.us/>
Any e-mail sent from congatec may contain information which is confidential. If you are not the intended recipient, you may not
disclose, copy or use it; please notify the sender immediately and delete this e-mail and any copies from your systems.
Date: 07/23/2015 02:02 PM
Subject: [edk2] GetNext of Smbios protocol not working
EFI_STATUS
EFIAPI
SmbiosMain (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_SMBIOS_PROTOCOL *Smb;
EFI_STATUS Status = EFI_SUCCESS;
EFI_SMBIOS_HANDLE InSmbiosHandle = 0xFFFE;
EFI_SMBIOS_TYPE Type=160;
EFI_SMBIOS_TABLE_HEADER *SmbiosRecord = NULL;
KNL_GENERAL_INFORMATION knl;
UINT16 size = 0;
Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **) &Smb);
if (EFI_ERROR (Status)) {
return Status;
}
Print(L"Status after gBS->LocateProtocol: %r\n", Status);
SmbiosRecord = AllocateZeroPool (sizeof(EFI_SMBIOS_TABLE_HEADER));
Status = Smb->GetNext (&Smb, &InSmbiosHandle, &Type, &SmbiosRecord, NULL);
Print(L"Status after SmbiosProtocol->GetNext: %r\n", Status);
if (EFI_ERROR (Status)) {
return Status;
}
Print(L"Smbios In Handle: %d\n", InSmbiosHandle);
Print(L"SmbiosRecord Address : 0X%llx\n", &SmbiosRecord);
Print(L"SmbiosRecord->Type : %d\n", SmbiosRecord->Type);
Print(L"SmbiosRecord->Length : %d\n\n", SmbiosRecord->Length);
Print(L"SmbiosRecord->Handle : %d\n\n", SmbiosRecord->Handle);
Print(L"Sizeof SmbiosRecord : %d\n", sizeof(SmbiosRecord));
FreePool (SmbiosRecord);
return EFI_SUCCESS;
Please see my code below.
If you’ll notice, I’m passing
In EFI_SMBIOS_HANDLE InSmbiosHandle = 0xFFFE; EFI_SMBIOS_TYPE Type=160;
Which is as the header file “Smbios.h” and the protocol implementation “SmbiosDxe.c”
Instruct. According to my understanding, GetNext should return the address of the
First table whose Type=160. I used SmbiosView.efi and saw that indeed such a table
with Type=160 is present. I tried other valid Types too, though and the result is the same.
What I expect to be returned is the EFI_STATUS of “Success” and the correct
Address for the SmbiosRecord with type=160. I’m getting neither. I’m getting an EFI_STATUS
Code of 0xB58FBD02. At the very least, I would expect EFI_NOT_FOUND. According
To the protocol, this weird 0xB58FBD02 should not be returned for EFI_STATUS.
I did search archives however, and it seems that others have had problems with Smbios GetNext,
With no resolution that I saw.
C:\edk2\MyWorkspace\MdeModulePkg\Universal\SmbiosDxe\SmbiosDxe.c
C:\edk2\MyWorkspace\MdeModulePkg\Universal\SmbiosDxe\Smbios.h
There is also a shell tool C:\edk2\MyWorkspace\ShellPkg\Library\UefiShellDebug1CommandsLib\Sm
biosView which does not use the Smbios protocol at all. It seems to use a backdoor approach of
internal data structures. I wonder why ? Is this because the Smbios protocol doesn’t work ?
We would like to use the Smbios Protocol because it’s simple and provides what we need.
We would like to avoid the backdoor approach embraced by Smbiosview if possible.
Can someone comment on my issue ? Am I using GetNext incorrectly ?
EFI_STATUS
EFIAPI
SmbiosMain (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_SMBIOS_PROTOCOL Smb;
EFI_STATUS Status = EFI_SUCCESS;
EFI_SMBIOS_HANDLE InSmbiosHandle = 0xFFFE;
EFI_SMBIOS_TYPE Type=160;
EFI_SMBIOS_TABLE_HEADER *SmbiosRecord = NULL;
KNL_GENERAL_INFORMATION knl;
UINT16 size = 0;
Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **) &Smb);
if (EFI_ERROR (Status)) {
return Status;
}
Print(L"Status after gBS->LocateProtocol: %r\n", Status);
SmbiosRecord = AllocateZeroPool (sizeof(EFI_SMBIOS_TABLE_HEADER));
Status = Smb.GetNext (&Smb, &InSmbiosHandle, &Type, &SmbiosRecord, NULL);
Print(L"Status after SmbiosProtocol->GetNext: %r\n", Status);
if (EFI_ERROR (Status)) {
return Status;
}
Print(L"Smbios In Handle: %d\n", InSmbiosHandle);
Print(L"SmbiosRecord Address : 0X%llx\n", &SmbiosRecord);
Print(L"SmbiosRecord->Type : %d\n", SmbiosRecord->Type);
Print(L"SmbiosRecord->Length : %d\n\n", SmbiosRecord->Length);
Print(L"SmbiosRecord->Handle : %d\n\n", SmbiosRecord->Handle);
Print(L"Sizeof SmbiosRecord : %d\n", sizeof(SmbiosRecord));
FreePool (SmbiosRecord);
return EFI_SUCCESS;
Shubha D. Ramani
_______________________________________________
edk2-devel mailing list
https://lists.sourceforge.net/lists/listinfo/edk2-devel <https://lists.sourceforge.net/lists/listinfo/edk2-devel>
<Mail Attachment.gif>------------------------------------------------------------------------------
_______________________________________________
edk2-devel mailing list
https://lists.sourceforge.net/lists/listinfo/edk2-devel
Shubha Ramani
2015-07-23 23:11:48 UTC
Permalink
Andrew:
I don't understand why you're claiming pointer corruption ? I don't think so. I'm not "trying different APIs". I actually need the next SmbiosRecord->Length bytescopied into foo. Can you elaborate ? Is it because I'm using UINT8 instead of EFI_SMBIOS_TYPE in GENERAL_INFORMATION ? Why does that make a differencewhen in fact EFI_SMBIOS_TYPE is a UINT8 ? Or that I'm using UINT16 instead of EFI_SMBIOS_HANDLE ? I could make those changes in my GENERAL_INFORMATIONstruct but I don't see them making a difference. That said, I think I should use the EFI typedefs in GENERAL_INFORMATION structinstead of UINT8/UINT16 in case the underlying types might change in the future.
 Shubha D. ***@gmail.com
***@yahoo.com


On Thursday, July 23, 2015 3:56 PM, Andrew Fish <***@apple.com> wrote:




On Jul 23, 2015, at 3:37 PM, Shubha Ramani <***@yahoo.com> wrote:
I actually do want the size of the entire SMBIOS structure. It should match sizeof (GENERAL_INFORMATION) and it in fact does.That's why I'm confused. Maybe I need to AllocateZeroPool for foo and not create it on the stack ? I don't see how that would makea difference but I'll try it. 

Looks like pointer corruption to me. You really should assume your code is broken 1st, and not start trying random other APIs. You may get lucky and leave a time bomb for the developer that ends up having to maintain the code in the future. 
The code should be either:SmbiosRecord, SmbiosRecord->Length&SmbiosRecord, SmbiosRecord.Lenght
or 
Just use:
https://github.com/tianocore/edk2/blob/master/MdePkg/Include/IndustryStandard/SmBios.h as it defined SMBIOS_STRUCTURE_POINTER.
All the spec based data structures already have types, that have been tested. 
Thanks,
Andrew Fish

Shubha D. ***@gmail.com
***@yahoo.com


On Thursday, July 23, 2015 3:31 PM, Andrew Fish <***@apple.com> wrote:




On Jul 23, 2015, at 3:13 PM, Shubha Ramani <***@yahoo.com> wrote:
Thank You ! You are right. My pointer was incorrect and your correction fixed it Aaron. Next question. I'm trying to use CopyMem.Can I do something like this ? It's not working right. Type, Length and Handle in my custom struct are exactly the same types as in (from Smbios.h)


You are probably corrupting the stack with a buffer overflow on foo. 
CopyMem ((VOID *)&foo, (VOID *)&SmbiosRecord, MIN (SmbiosRecord->Length, sizeof (GENERAL_INFORMATION));
EFI_SMBIOS_TABLE_HEADER.Length is the length of the entire SMBIOS structure, not the header. If you just want the header it would we be sizeof (EFI_SMBIOS_TABLE_HEADER).
Sp just standard C bugs.
Thanks,
Andrew Fish


typedef struct {  EFI_SMBIOS_TYPE   Type;  UINT8             Length;  EFI_SMBIOS_HANDLE Handle;} EFI_SMBIOS_TABLE_HEADER;

My custom struct:
#pragma pack(1)
typedef struct _GENERAL_INFORMATION{  UINT8             Type;  UINT8             Length;  UINT16            Handle;  UINT16            MemberIdentifier;  UINT8             MemberName;  UINT8            Field_A  UINT8            Field_B;  UINT8            Field_C;  UINT8            FIeld_D,  UINT8            Field_E;} GENERAL_INFORMATION; #pragma pack()
GENERAL_INFORMATION foo;
CopyMem ((VOID *)&foo, (VOID *)&SmbiosRecord, SmbiosRecord->Length);
 Shubha D. ***@gmail.com
***@yahoo.com


On Thursday, July 23, 2015 2:08 PM, "***@congatec.com" <***@congatec.com> wrote:


Your usage of pointers was incorrect. Pleasesee corrected code below:


EFI_STATUS
EFIAPI
SmbiosMain (
  IN EFI_HANDLE       ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{

  EFI_SMBIOS_PROTOCOL     *Smb;
  EFI_STATUS Status = EFI_SUCCESS;
  EFI_SMBIOS_HANDLE InSmbiosHandle =0xFFFE;
  EFI_SMBIOS_TYPE  Type=160;
  EFI_SMBIOS_TABLE_HEADER   *SmbiosRecord= NULL;
  KNL_GENERAL_INFORMATION knl;
  UINT16 size = 0;
 
  Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid,NULL, (VOID **) &Smb);

  if (EFI_ERROR (Status)) {
    return Status;
  }

   Print(L"Status after  gBS->LocateProtocol:%r\n", Status);

  SmbiosRecord = AllocateZeroPool (sizeof(EFI_SMBIOS_TABLE_HEADER));
 
 Status = Smb->GetNext (Smb, &InSmbiosHandle,&Type, &SmbiosRecord, NULL);

  Print(L"Status after SmbiosProtocol->GetNext:%r\n", Status);
   

 
  if (EFI_ERROR (Status)) {
    return Status;
  }


  Print(L"Smbios In Handle: %d\n",InSmbiosHandle);
  Print(L"SmbiosRecord Address: 0X%llx\n", &SmbiosRecord);
  Print(L"SmbiosRecord->Type: %d\n", SmbiosRecord->Type);
  Print(L"SmbiosRecord->Length: %d\n\n", SmbiosRecord->Length);
   Print(L"SmbiosRecord->Handle: %d\n\n", SmbiosRecord->Handle);
  Print(L"Sizeof SmbiosRecord :%d\n", sizeof(SmbiosRecord));

 
  FreePool (SmbiosRecord);
 
  return EFI_SUCCESS;


Best Personal Regards,

Aaron Pop
Senior Software Engineer

Phone: +1 858-457-2600 Ext. 318
Fax: +1 858-457-2602  |  Email:***@congatec.com

<Mail Attachment.gif>
congatec, Inc.  |  6262Ferris Square  |  San Diego CA  92121  |  USA |  www.congatec.us

Any e-mail sent from congatecmay contain information which is confidential. If you are not the intendedrecipient, you may not
disclose, copy or useit; please notify the sender immediately and delete this e-mail and anycopies from your systems.




From:       Shubha Ramani <***@yahoo.com>
To:       "edk2-***@lists.sourceforge.net"<edk2-***@lists.sourceforge.net>,
Date:       07/23/2015 02:02 PM
Subject:       [edk2] GetNextof Smbios protocol not working


Please see corrected code below:


EFI_STATUS
EFIAPI
SmbiosMain (
  IN EFI_HANDLE       ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{

  EFI_SMBIOS_PROTOCOL     *Smb;
  EFI_STATUS Status = EFI_SUCCESS;
  EFI_SMBIOS_HANDLE InSmbiosHandle =0xFFFE;
  EFI_SMBIOS_TYPE  Type=160;
  EFI_SMBIOS_TABLE_HEADER   *SmbiosRecord= NULL;
  KNL_GENERAL_INFORMATION knl;
  UINT16 size = 0;
 
  Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid,NULL, (VOID **) &Smb);

  if (EFI_ERROR (Status)) {
    return Status;
  }

   Print(L"Status after  gBS->LocateProtocol:%r\n", Status);

  SmbiosRecord = AllocateZeroPool (sizeof(EFI_SMBIOS_TABLE_HEADER));
 
 Status = Smb->GetNext (&Smb,&InSmbiosHandle, &Type, &SmbiosRecord, NULL);

  Print(L"Status after SmbiosProtocol->GetNext:%r\n", Status);
   

 
  if (EFI_ERROR (Status)) {
    return Status;
  }


  Print(L"Smbios In Handle: %d\n",InSmbiosHandle);
  Print(L"SmbiosRecord Address: 0X%llx\n", &SmbiosRecord);
  Print(L"SmbiosRecord->Type: %d\n", SmbiosRecord->Type);
  Print(L"SmbiosRecord->Length: %d\n\n", SmbiosRecord->Length);
   Print(L"SmbiosRecord->Handle: %d\n\n", SmbiosRecord->Handle);
  Print(L"Sizeof SmbiosRecord :%d\n", sizeof(SmbiosRecord));

 
  FreePool (SmbiosRecord);
 
  return EFI_SUCCESS;



Please see my code below.

If you’ll notice, I’m passing
In  EFI_SMBIOS_HANDLEInSmbiosHandle = 0xFFFE; EFI_SMBIOS_TYPE  Type=160;
Which is as the header file “Smbios.h”and the protocol implementation “SmbiosDxe.c”
Instruct. According to my understanding,GetNext should return the address of the
First table whose Type=160. I used SmbiosView.efiand saw that indeed such a table
with Type=160 is present. I tried other validTypes too, though and the result is the same.
 
What I expect to be returned is the EFI_STATUSof “Success” and the correct
Address for the SmbiosRecord with type=160.I’m getting neither. I’m getting an EFI_STATUS
Code of 0xB58FBD02. At the very least, Iwould expect EFI_NOT_FOUND. According
To the protocol, this weird 0xB58FBD02 shouldnot be returned for EFI_STATUS.

I did search archives however, and it seemsthat others have had problems with Smbios GetNext,
With no resolution that I saw.
 
The following two paths are the Smbios Protocolimplementation in the latest EDK2 repo:
 
C:\edk2\MyWorkspace\MdeModulePkg\Universal\SmbiosDxe\SmbiosDxe.c
 
C:\edk2\MyWorkspace\MdeModulePkg\Universal\SmbiosDxe\Smbios.h
 
There is also a  shell tool C:\edk2\MyWorkspace\ShellPkg\Library\UefiShellDebug1CommandsLib\Sm
biosView which does not use the Smbios protocolat all. It seems to use a backdoor approach of
internal data structures. I wonder why ?Is this because the Smbios protocol doesn’t work ?
 
We would like to use the Smbios Protocolbecause it’s simple and provides what we need.
We would like to avoid the backdoor approachembraced by Smbiosview if possible.
 
Can someone comment on my issue ? Am I usingGetNext incorrectly ?
 
EFI_STATUS
EFIAPI
SmbiosMain (
  IN EFI_HANDLE       ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{

  EFI_SMBIOS_PROTOCOL     Smb;
  EFI_STATUS Status = EFI_SUCCESS;
  EFI_SMBIOS_HANDLE InSmbiosHandle =0xFFFE;
  EFI_SMBIOS_TYPE  Type=160;
  EFI_SMBIOS_TABLE_HEADER   *SmbiosRecord= NULL;
  KNL_GENERAL_INFORMATION knl;
  UINT16 size = 0;
 
  Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid,NULL, (VOID **) &Smb);

  if (EFI_ERROR (Status)) {
    return Status;
  }

   Print(L"Status after  gBS->LocateProtocol:%r\n", Status);

  SmbiosRecord = AllocateZeroPool (sizeof(EFI_SMBIOS_TABLE_HEADER));
 
 Status = Smb.GetNext (&Smb, &InSmbiosHandle,&Type, &SmbiosRecord, NULL);

  Print(L"Status after SmbiosProtocol->GetNext:%r\n", Status);
   

 
  if (EFI_ERROR (Status)) {
    return Status;
  }


  Print(L"Smbios In Handle: %d\n",InSmbiosHandle);
  Print(L"SmbiosRecord Address: 0X%llx\n", &SmbiosRecord);
  Print(L"SmbiosRecord->Type: %d\n", SmbiosRecord->Type);
  Print(L"SmbiosRecord->Length: %d\n\n", SmbiosRecord->Length);
   Print(L"SmbiosRecord->Handle: %d\n\n", SmbiosRecord->Handle);
  Print(L"Sizeof SmbiosRecord :%d\n", sizeof(SmbiosRecord));

 
  FreePool (SmbiosRecord);
 
  return EFI_SUCCESS;
 
Shubha D. Ramani
***@gmail.com
***@yahoo.com------------------------------------------------------------------------------
_______________________________________________
edk2-devel mailing list
edk2-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel



<Mail Attachment.gif>------------------------------------------------------------------------------
Shubha Ramani
2015-07-23 23:25:47 UTC
Permalink
Never mind. I see your point Andrew. Accepted. I should assume my code is broken first and you're right, it was.Thanks for pointing it out.
Shubha Shubha D. ***@gmail.com
***@yahoo.com


On Thursday, July 23, 2015 4:11 PM, Shubha Ramani <***@yahoo.com> wrote:


Andrew:
I don't understand why you're claiming pointer corruption ? I don't think so. I'm not "trying different APIs". I actually need the next SmbiosRecord->Length bytescopied into foo. Can you elaborate ? Is it because I'm using UINT8 instead of EFI_SMBIOS_TYPE in GENERAL_INFORMATION ? Why does that make a differencewhen in fact EFI_SMBIOS_TYPE is a UINT8 ? Or that I'm using UINT16 instead of EFI_SMBIOS_HANDLE ? I could make those changes in my GENERAL_INFORMATIONstruct but I don't see them making a difference. That said, I think I should use the EFI typedefs in GENERAL_INFORMATION structinstead of UINT8/UINT16 in case the underlying types might change in the future.
 Shubha D. ***@gmail.com
***@yahoo.com


On Thursday, July 23, 2015 3:56 PM, Andrew Fish <***@apple.com> wrote:




On Jul 23, 2015, at 3:37 PM, Shubha Ramani <***@yahoo.com> wrote:
I actually do want the size of the entire SMBIOS structure. It should match sizeof (GENERAL_INFORMATION) and it in fact does.That's why I'm confused. Maybe I need to AllocateZeroPool for foo and not create it on the stack ? I don't see how that would makea difference but I'll try it. 

Looks like pointer corruption to me. You really should assume your code is broken 1st, and not start trying random other APIs. You may get lucky and leave a time bomb for the developer that ends up having to maintain the code in the future. 
The code should be either:SmbiosRecord, SmbiosRecord->Length&SmbiosRecord, SmbiosRecord.Lenght
or 
Just use:
https://github.com/tianocore/edk2/blob/master/MdePkg/Include/IndustryStandard/SmBios.h as it defined SMBIOS_STRUCTURE_POINTER.
All the spec based data structures already have types, that have been tested. 
Thanks,
Andrew Fish

Shubha D. ***@gmail.com
***@yahoo.com


On Thursday, July 23, 2015 3:31 PM, Andrew Fish <***@apple.com> wrote:




On Jul 23, 2015, at 3:13 PM, Shubha Ramani <***@yahoo.com> wrote:
Thank You ! You are right. My pointer was incorrect and your correction fixed it Aaron. Next question. I'm trying to use CopyMem.Can I do something like this ? It's not working right. Type, Length and Handle in my custom struct are exactly the same types as in (from Smbios.h)


You are probably corrupting the stack with a buffer overflow on foo. 
CopyMem ((VOID *)&foo, (VOID *)&SmbiosRecord, MIN (SmbiosRecord->Length, sizeof (GENERAL_INFORMATION));
EFI_SMBIOS_TABLE_HEADER.Length is the length of the entire SMBIOS structure, not the header. If you just want the header it would we be sizeof (EFI_SMBIOS_TABLE_HEADER).
Sp just standard C bugs.
Thanks,
Andrew Fish


typedef struct {  EFI_SMBIOS_TYPE   Type;  UINT8             Length;  EFI_SMBIOS_HANDLE Handle;} EFI_SMBIOS_TABLE_HEADER;

My custom struct:
#pragma pack(1)
typedef struct _GENERAL_INFORMATION{  UINT8             Type;  UINT8             Length;  UINT16            Handle;  UINT16            MemberIdentifier;  UINT8             MemberName;  UINT8            Field_A  UINT8            Field_B;  UINT8            Field_C;  UINT8            FIeld_D,  UINT8            Field_E;} GENERAL_INFORMATION; #pragma pack()
GENERAL_INFORMATION foo;
CopyMem ((VOID *)&foo, (VOID *)&SmbiosRecord, SmbiosRecord->Length);
 Shubha D. ***@gmail.com
***@yahoo.com


On Thursday, July 23, 2015 2:08 PM, "***@congatec.com" <***@congatec.com> wrote:


Your usage of pointers was incorrect. Pleasesee corrected code below:


EFI_STATUS
EFIAPI
SmbiosMain (
  IN EFI_HANDLE       ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{

  EFI_SMBIOS_PROTOCOL     *Smb;
  EFI_STATUS Status = EFI_SUCCESS;
  EFI_SMBIOS_HANDLE InSmbiosHandle =0xFFFE;
  EFI_SMBIOS_TYPE  Type=160;
  EFI_SMBIOS_TABLE_HEADER   *SmbiosRecord= NULL;
  KNL_GENERAL_INFORMATION knl;
  UINT16 size = 0;
 
  Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid,NULL, (VOID **) &Smb);

  if (EFI_ERROR (Status)) {
    return Status;
  }

   Print(L"Status after  gBS->LocateProtocol:%r\n", Status);

  SmbiosRecord = AllocateZeroPool (sizeof(EFI_SMBIOS_TABLE_HEADER));
 
 Status = Smb->GetNext (Smb, &InSmbiosHandle,&Type, &SmbiosRecord, NULL);

  Print(L"Status after SmbiosProtocol->GetNext:%r\n", Status);
   

 
  if (EFI_ERROR (Status)) {
    return Status;
  }


  Print(L"Smbios In Handle: %d\n",InSmbiosHandle);
  Print(L"SmbiosRecord Address: 0X%llx\n", &SmbiosRecord);
  Print(L"SmbiosRecord->Type: %d\n", SmbiosRecord->Type);
  Print(L"SmbiosRecord->Length: %d\n\n", SmbiosRecord->Length);
   Print(L"SmbiosRecord->Handle: %d\n\n", SmbiosRecord->Handle);
  Print(L"Sizeof SmbiosRecord :%d\n", sizeof(SmbiosRecord));

 
  FreePool (SmbiosRecord);
 
  return EFI_SUCCESS;


Best Personal Regards,

Aaron Pop
Senior Software Engineer

Phone: +1 858-457-2600 Ext. 318
Fax: +1 858-457-2602  |  Email:***@congatec.com

<Mail Attachment.gif>
congatec, Inc.  |  6262Ferris Square  |  San Diego CA  92121  |  USA |  www.congatec.us

Any e-mail sent from congatecmay contain information which is confidential. If you are not the intendedrecipient, you may not
disclose, copy or useit; please notify the sender immediately and delete this e-mail and anycopies from your systems.




From:       Shubha Ramani <***@yahoo.com>
To:       "edk2-***@lists.sourceforge.net"<edk2-***@lists.sourceforge.net>,
Date:       07/23/2015 02:02 PM
Subject:       [edk2] GetNextof Smbios protocol not working


Please see corrected code below:


EFI_STATUS
EFIAPI
SmbiosMain (
  IN EFI_HANDLE       ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{

  EFI_SMBIOS_PROTOCOL     *Smb;
  EFI_STATUS Status = EFI_SUCCESS;
  EFI_SMBIOS_HANDLE InSmbiosHandle =0xFFFE;
  EFI_SMBIOS_TYPE  Type=160;
  EFI_SMBIOS_TABLE_HEADER   *SmbiosRecord= NULL;
  KNL_GENERAL_INFORMATION knl;
  UINT16 size = 0;
 
  Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid,NULL, (VOID **) &Smb);

  if (EFI_ERROR (Status)) {
    return Status;
  }

   Print(L"Status after  gBS->LocateProtocol:%r\n", Status);

  SmbiosRecord = AllocateZeroPool (sizeof(EFI_SMBIOS_TABLE_HEADER));
 
 Status = Smb->GetNext (&Smb,&InSmbiosHandle, &Type, &SmbiosRecord, NULL);

  Print(L"Status after SmbiosProtocol->GetNext:%r\n", Status);
   

 
  if (EFI_ERROR (Status)) {
    return Status;
  }


  Print(L"Smbios In Handle: %d\n",InSmbiosHandle);
  Print(L"SmbiosRecord Address: 0X%llx\n", &SmbiosRecord);
  Print(L"SmbiosRecord->Type: %d\n", SmbiosRecord->Type);
  Print(L"SmbiosRecord->Length: %d\n\n", SmbiosRecord->Length);
   Print(L"SmbiosRecord->Handle: %d\n\n", SmbiosRecord->Handle);
  Print(L"Sizeof SmbiosRecord :%d\n", sizeof(SmbiosRecord));

 
  FreePool (SmbiosRecord);
 
  return EFI_SUCCESS;



Please see my code below.

If you’ll notice, I’m passing
In  EFI_SMBIOS_HANDLEInSmbiosHandle = 0xFFFE; EFI_SMBIOS_TYPE  Type=160;
Which is as the header file “Smbios.h”and the protocol implementation “SmbiosDxe.c”
Instruct. According to my understanding,GetNext should return the address of the
First table whose Type=160. I used SmbiosView.efiand saw that indeed such a table
with Type=160 is present. I tried other validTypes too, though and the result is the same.
 
What I expect to be returned is the EFI_STATUSof “Success” and the correct
Address for the SmbiosRecord with type=160.I’m getting neither. I’m getting an EFI_STATUS
Code of 0xB58FBD02. At the very least, Iwould expect EFI_NOT_FOUND. According
To the protocol, this weird 0xB58FBD02 shouldnot be returned for EFI_STATUS.

I did search archives however, and it seemsthat others have had problems with Smbios GetNext,
With no resolution that I saw.
 
The following two paths are the Smbios Protocolimplementation in the latest EDK2 repo:
 
C:\edk2\MyWorkspace\MdeModulePkg\Universal\SmbiosDxe\SmbiosDxe.c
 
C:\edk2\MyWorkspace\MdeModulePkg\Universal\SmbiosDxe\Smbios.h
 
There is also a  shell tool C:\edk2\MyWorkspace\ShellPkg\Library\UefiShellDebug1CommandsLib\Sm
biosView which does not use the Smbios protocolat all. It seems to use a backdoor approach of
internal data structures. I wonder why ?Is this because the Smbios protocol doesn’t work ?
 
We would like to use the Smbios Protocolbecause it’s simple and provides what we need.
We would like to avoid the backdoor approachembraced by Smbiosview if possible.
 
Can someone comment on my issue ? Am I usingGetNext incorrectly ?
 
EFI_STATUS
EFIAPI
SmbiosMain (
  IN EFI_HANDLE       ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{

  EFI_SMBIOS_PROTOCOL     Smb;
  EFI_STATUS Status = EFI_SUCCESS;
  EFI_SMBIOS_HANDLE InSmbiosHandle =0xFFFE;
  EFI_SMBIOS_TYPE  Type=160;
  EFI_SMBIOS_TABLE_HEADER   *SmbiosRecord= NULL;
  KNL_GENERAL_INFORMATION knl;
  UINT16 size = 0;
 
  Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid,NULL, (VOID **) &Smb);

  if (EFI_ERROR (Status)) {
    return Status;
  }

   Print(L"Status after  gBS->LocateProtocol:%r\n", Status);

  SmbiosRecord = AllocateZeroPool (sizeof(EFI_SMBIOS_TABLE_HEADER));
 
 Status = Smb.GetNext (&Smb, &InSmbiosHandle,&Type, &SmbiosRecord, NULL);

  Print(L"Status after SmbiosProtocol->GetNext:%r\n", Status);
   

 
  if (EFI_ERROR (Status)) {
    return Status;
  }


  Print(L"Smbios In Handle: %d\n",InSmbiosHandle);
  Print(L"SmbiosRecord Address: 0X%llx\n", &SmbiosRecord);
  Print(L"SmbiosRecord->Type: %d\n", SmbiosRecord->Type);
  Print(L"SmbiosRecord->Length: %d\n\n", SmbiosRecord->Length);
   Print(L"SmbiosRecord->Handle: %d\n\n", SmbiosRecord->Handle);
  Print(L"Sizeof SmbiosRecord :%d\n", sizeof(SmbiosRecord));

 
  FreePool (SmbiosRecord);
 
  return EFI_SUCCESS;
 
Shubha D. Ramani
***@gmail.com
***@yahoo.com------------------------------------------------------------------------------
_______________________________________________
edk2-devel mailing list
edk2-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel



<Mail Attachment.gif>------------------------------------------------------------------------------
Loading...