NetworkPkg/IScsiDxe/IScsiDhcp.c | 7 ++++--- NetworkPkg/IScsiDxe/IScsiDhcp6.c | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-)
After the expression,
'CopyMem (&ConfigNvData->TargetUrl, Field->Str, Field->Len);',
the '\0' should be set to TargetUrl[Field->Len] rather than
TargetUrl[Field->Len + 1].
Besides the boundary check should be more strict.
Field->Len should range from 0-254 rather than 0-255.
Cc: Siyuan Fu <siyuan.fu@intel.com>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Signed-off-by: Shenglei Zhang <shenglei.zhang@intel.com>
---
v2: Add missing ')' which causes build failure.
NetworkPkg/IScsiDxe/IScsiDhcp.c | 7 ++++---
NetworkPkg/IScsiDxe/IScsiDhcp6.c | 7 ++++---
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/NetworkPkg/IScsiDxe/IScsiDhcp.c b/NetworkPkg/IScsiDxe/IScsiDhcp.c
index d8c9fff6c65d..eac5b39991b7 100644
--- a/NetworkPkg/IScsiDxe/IScsiDhcp.c
+++ b/NetworkPkg/IScsiDxe/IScsiDhcp.c
@@ -122,11 +122,12 @@ IScsiDhcpExtractRootPath (
//
if ((!NET_IS_DIGIT (*(Field->Str))) && (*(Field->Str) != '[')) {
ConfigNvData->DnsMode = TRUE;
- if (Field->Len > sizeof (ConfigNvData->TargetUrl)) {
- return EFI_INVALID_PARAMETER;
+ if (Field->Len >= sizeof (ConfigNvData->TargetUrl)) {
+ Status = EFI_INVALID_PARAMETER;
+ goto ON_EXIT;
}
CopyMem (&ConfigNvData->TargetUrl, Field->Str, Field->Len);
- ConfigNvData->TargetUrl[Field->Len + 1] = '\0';
+ ConfigNvData->TargetUrl[Field->Len] = '\0';
} else {
ConfigNvData->DnsMode = FALSE;
ZeroMem(ConfigNvData->TargetUrl, sizeof (ConfigNvData->TargetUrl));
diff --git a/NetworkPkg/IScsiDxe/IScsiDhcp6.c b/NetworkPkg/IScsiDxe/IScsiDhcp6.c
index 86a872adeccc..be66e6684a0e 100644
--- a/NetworkPkg/IScsiDxe/IScsiDhcp6.c
+++ b/NetworkPkg/IScsiDxe/IScsiDhcp6.c
@@ -161,11 +161,12 @@ IScsiDhcp6ExtractRootPath (
// Server name is expressed as domain name, just save it.
//
if (ConfigNvData->DnsMode) {
- if (Field->Len > sizeof (ConfigNvData->TargetUrl)) {
- return EFI_INVALID_PARAMETER;
+ if (Field->Len >= sizeof (ConfigNvData->TargetUrl)) {
+ Status = EFI_INVALID_PARAMETER;
+ goto ON_EXIT;
}
CopyMem (&ConfigNvData->TargetUrl, Field->Str, Field->Len);
- ConfigNvData->TargetUrl[Field->Len + 1] = '\0';
+ ConfigNvData->TargetUrl[Field->Len] = '\0';
} else {
ZeroMem(&ConfigNvData->TargetUrl, sizeof (ConfigNvData->TargetUrl));
Status = IScsiAsciiStrToIp (Field->Str, IpMode, &Ip);
--
2.18.0.windows.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#48878): https://edk2.groups.io/g/devel/message/48878
Mute This Topic: https://groups.io/mt/34529690/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Hi Zhang, On 10/14/19 5:14 AM, Zhang, Shenglei wrote: > After the expression, > 'CopyMem (&ConfigNvData->TargetUrl, Field->Str, Field->Len);', > the '\0' should be set to TargetUrl[Field->Len] rather than > TargetUrl[Field->Len + 1]. ^ This is one change, ... > Besides the boundary check should be more strict. > Field->Len should range from 0-254 rather than 0-255. ^ ... and here we have another change. Can you split this in 2 patches? > Cc: Siyuan Fu <siyuan.fu@intel.com> > Cc: Jiaxin Wu <jiaxin.wu@intel.com> > Signed-off-by: Shenglei Zhang <shenglei.zhang@intel.com> > --- > > v2: Add missing ')' which causes build failure. > > NetworkPkg/IScsiDxe/IScsiDhcp.c | 7 ++++--- > NetworkPkg/IScsiDxe/IScsiDhcp6.c | 7 ++++--- > 2 files changed, 8 insertions(+), 6 deletions(-) > > diff --git a/NetworkPkg/IScsiDxe/IScsiDhcp.c b/NetworkPkg/IScsiDxe/IScsiDhcp.c > index d8c9fff6c65d..eac5b39991b7 100644 > --- a/NetworkPkg/IScsiDxe/IScsiDhcp.c > +++ b/NetworkPkg/IScsiDxe/IScsiDhcp.c > @@ -122,11 +122,12 @@ IScsiDhcpExtractRootPath ( > // > if ((!NET_IS_DIGIT (*(Field->Str))) && (*(Field->Str) != '[')) { > ConfigNvData->DnsMode = TRUE; > - if (Field->Len > sizeof (ConfigNvData->TargetUrl)) { > - return EFI_INVALID_PARAMETER; > + if (Field->Len >= sizeof (ConfigNvData->TargetUrl)) { > + Status = EFI_INVALID_PARAMETER; > + goto ON_EXIT; This is a change in the code flow. So now we free he allocated TmpStr. This is correct, but you did not commented that change in the description. So we currently have a memory leak. Please do not hide that kind of information in patches. > } > CopyMem (&ConfigNvData->TargetUrl, Field->Str, Field->Len); > - ConfigNvData->TargetUrl[Field->Len + 1] = '\0'; > + ConfigNvData->TargetUrl[Field->Len] = '\0'; And here we have 1 byte of memory info leak. Are you fixing a Security BZ? > } else { > ConfigNvData->DnsMode = FALSE; > ZeroMem(ConfigNvData->TargetUrl, sizeof (ConfigNvData->TargetUrl)); > diff --git a/NetworkPkg/IScsiDxe/IScsiDhcp6.c b/NetworkPkg/IScsiDxe/IScsiDhcp6.c > index 86a872adeccc..be66e6684a0e 100644 > --- a/NetworkPkg/IScsiDxe/IScsiDhcp6.c > +++ b/NetworkPkg/IScsiDxe/IScsiDhcp6.c > @@ -161,11 +161,12 @@ IScsiDhcp6ExtractRootPath ( > // Server name is expressed as domain name, just save it. > // > if (ConfigNvData->DnsMode) { > - if (Field->Len > sizeof (ConfigNvData->TargetUrl)) { > - return EFI_INVALID_PARAMETER; > + if (Field->Len >= sizeof (ConfigNvData->TargetUrl)) { > + Status = EFI_INVALID_PARAMETER; > + goto ON_EXIT; > } > CopyMem (&ConfigNvData->TargetUrl, Field->Str, Field->Len); > - ConfigNvData->TargetUrl[Field->Len + 1] = '\0'; > + ConfigNvData->TargetUrl[Field->Len] = '\0'; > } else { > ZeroMem(&ConfigNvData->TargetUrl, sizeof (ConfigNvData->TargetUrl)); > Status = IScsiAsciiStrToIp (Field->Str, IpMode, &Ip); > -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#48884): https://edk2.groups.io/g/devel/message/48884 Mute This Topic: https://groups.io/mt/34529690/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=-=-=-=-=-=-=-=-=-=-=-
Hi Philippe, > -----Original Message----- > From: Philippe Mathieu-Daudé [mailto:philmd@redhat.com] > Sent: Monday, October 14, 2019 5:35 PM > To: devel@edk2.groups.io; Zhang, Shenglei <shenglei.zhang@intel.com> > Cc: Fu, Siyuan <siyuan.fu@intel.com>; Wu, Jiaxin <jiaxin.wu@intel.com>; > Laszlo Ersek <lersek@redhat.com> > Subject: Re: [edk2-devel] [PATCH v2] NetworkPkg/IScsiDxe: Fix the index of > array TargetUrlp[] > > Hi Zhang, > > On 10/14/19 5:14 AM, Zhang, Shenglei wrote: > > After the expression, > > 'CopyMem (&ConfigNvData->TargetUrl, Field->Str, Field->Len);', > > the '\0' should be set to TargetUrl[Field->Len] rather than > > TargetUrl[Field->Len + 1]. > > ^ This is one change, ... > > > Besides the boundary check should be more strict. > > Field->Len should range from 0-254 rather than 0-255. > > ^ ... and here we have another change. > > Can you split this in 2 patches? I think these two changes should be included in one patch. They are both about the variable ' Field->Len '. If one change pushed and the other one unchanged, The logic is then wrong. > > > Cc: Siyuan Fu <siyuan.fu@intel.com> > > Cc: Jiaxin Wu <jiaxin.wu@intel.com> > > Signed-off-by: Shenglei Zhang <shenglei.zhang@intel.com> > > --- > > > > v2: Add missing ')' which causes build failure. > > > > NetworkPkg/IScsiDxe/IScsiDhcp.c | 7 ++++--- > > NetworkPkg/IScsiDxe/IScsiDhcp6.c | 7 ++++--- > > 2 files changed, 8 insertions(+), 6 deletions(-) > > > > diff --git a/NetworkPkg/IScsiDxe/IScsiDhcp.c > b/NetworkPkg/IScsiDxe/IScsiDhcp.c > > index d8c9fff6c65d..eac5b39991b7 100644 > > --- a/NetworkPkg/IScsiDxe/IScsiDhcp.c > > +++ b/NetworkPkg/IScsiDxe/IScsiDhcp.c > > @@ -122,11 +122,12 @@ IScsiDhcpExtractRootPath ( > > // > > if ((!NET_IS_DIGIT (*(Field->Str))) && (*(Field->Str) != '[')) { > > ConfigNvData->DnsMode = TRUE; > > - if (Field->Len > sizeof (ConfigNvData->TargetUrl)) { > > - return EFI_INVALID_PARAMETER; > > + if (Field->Len >= sizeof (ConfigNvData->TargetUrl)) { > > + Status = EFI_INVALID_PARAMETER; > > + goto ON_EXIT; > > This is a change in the code flow. So now we free he allocated TmpStr. > This is correct, but you did not commented that change in the > description. So we currently have a memory leak. Please do not hide that > kind of information in patches. Yes the commit message should contain this change. > > > } > > CopyMem (&ConfigNvData->TargetUrl, Field->Str, Field->Len); > > - ConfigNvData->TargetUrl[Field->Len + 1] = '\0'; > > + ConfigNvData->TargetUrl[Field->Len] = '\0'; > > And here we have 1 byte of memory info leak. > > Are you fixing a Security BZ? No, I found this issue by my local tool. There is no BZ for this. Thanks, Shenglei > > > } else { > > ConfigNvData->DnsMode = FALSE; > > ZeroMem(ConfigNvData->TargetUrl, sizeof (ConfigNvData->TargetUrl)); > > diff --git a/NetworkPkg/IScsiDxe/IScsiDhcp6.c > b/NetworkPkg/IScsiDxe/IScsiDhcp6.c > > index 86a872adeccc..be66e6684a0e 100644 > > --- a/NetworkPkg/IScsiDxe/IScsiDhcp6.c > > +++ b/NetworkPkg/IScsiDxe/IScsiDhcp6.c > > @@ -161,11 +161,12 @@ IScsiDhcp6ExtractRootPath ( > > // Server name is expressed as domain name, just save it. > > // > > if (ConfigNvData->DnsMode) { > > - if (Field->Len > sizeof (ConfigNvData->TargetUrl)) { > > - return EFI_INVALID_PARAMETER; > > + if (Field->Len >= sizeof (ConfigNvData->TargetUrl)) { > > + Status = EFI_INVALID_PARAMETER; > > + goto ON_EXIT; > > } > > CopyMem (&ConfigNvData->TargetUrl, Field->Str, Field->Len); > > - ConfigNvData->TargetUrl[Field->Len + 1] = '\0'; > > + ConfigNvData->TargetUrl[Field->Len] = '\0'; > > } else { > > ZeroMem(&ConfigNvData->TargetUrl, sizeof (ConfigNvData- > >TargetUrl)); > > Status = IScsiAsciiStrToIp (Field->Str, IpMode, &Ip); > > -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#48904): https://edk2.groups.io/g/devel/message/48904 Mute This Topic: https://groups.io/mt/34529690/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=-=-=-=-=-=-=-=-=-=-=-
© 2016 - 2024 Red Hat, Inc.