Skip to contentSkip to conversation

glibc: fix Segmentation fault in gethostid.c

PATCH Superseded [email protected] 2 participants 4 messages Sep 18, 2018 – Sep 21, 2018 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): ”[email protected]”

#1 lore raw

PATCH v2 1/1 glibc: fix Segmentation fault in gethostid.c

From: Mingli Yu <[email protected]>

When run test program hostid, it encounters
Segmentation fault as hp is NULL.

 # cat /mybuild/hostid.c
 #include <stdio.h>
 #include <unistd.h>

int
main(int argc, char *argv[])

 {
    long hostid;
    hostid = gethostid();
    printf("the hostid is %ld\n", hostid);

}

 # gcc -o /mybuild/hostid /mybuild/hostid.c
 # /mybuild/hostid
 Segmentation fault
 # gdb /mybuild/hostid
 GNU gdb (GDB) 8.2
 Copyright (C) 2018 Free Software Foundation, Inc.
 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
 This is free software: you are free to change and redistribute it.
 There is NO WARRANTY, to the extent permitted by law.
 Type "show copying" and "show warranty" for details.
 This GDB was configured as "x86_64-wrs-linux".
 Type "show configuration" for configuration details.
 For bug reporting instructions, please see:
 <http://www.gnu.org/software/gdb/bugs/>.
 Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"... Reading symbols from /mybuild/hostid...done.
(gdb) r
Starting program: /mybuild/hostid

Program received signal SIGSEGV, Segmentation fault. 0x00007ffff7f0330e in gethostid () at ../sysdeps/unix/sysv/linux/gethostid.c:125
125 memcpy (&in, hp->h_addr,
(gdb) bt
#0 0x00007ffff7f0330e in gethostid () at ../sysdeps/unix/sysv/linux/gethostid.c:125 #1 0x0000555555555159 in main ()

---
 .../0001-gethostid.c-check-the-value-of-hp.patch   | 75 ++++++++++++++++++++++
 meta/recipes-core/glibc/glibc_2.28.bb              |  1 +
 2 files changed, 76 insertions(+)
 create mode 100644 meta/recipes-core/glibc/glibc/0001-gethostid.c-check-the-value-of-hp.patch
meta/recipes-core/glibc/glibc/0001-gethostid.c-check-the-value-of-hp.patch new file +75 -0
new file mode 100644
index 0000000000..04d1662361
@@ -0,0 +1,75 @@
+From 84cc79a003cf1a29e0a45ee76b67a3800d9e412e Mon Sep 17 00:00:00 2001
+From: Mingli Yu <[email protected]>
+Date: Tue, 18 Sep 2018 07:29:27 +0000
+Subject: [PATCH] gethostid.c: check the value of hp
+
+Fix Segmentation fault in gethostid.c
+
+When run test program hostid, it encounters
+Segmentation fault as hp is NULL.
+
+  # cat /mybuild/hostid.c
+  #include <stdio.h>
+  #include <unistd.h>
+
+  int
+  main(int argc, char *argv[])
+  {
+    long hostid;
+    hostid = gethostid();
+    printf("the hostid is %ld\n", hostid);
+  }
+ 
+  # gcc -o /mybuild/hostid /mybuild/hostid.c
+  # /mybuild/hostid
+  Segmentation fault
+  # gdb /mybuild/hostid
+  GNU gdb (GDB) 8.2
+  Copyright (C) 2018 Free Software Foundation, Inc.
+  License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
+  This is free software: you are free to change and redistribute it.
+  There is NO WARRANTY, to the extent permitted by law.
+  Type "show copying" and "show warranty" for details.
+  This GDB was configured as "x86_64-wrs-linux".
+  Type "show configuration" for configuration details.
+  For bug reporting instructions, please see:
+  <http://www.gnu.org/software/gdb/bugs/>.
+  Find the GDB manual and other documentation resources online at:
+      <http://www.gnu.org/software/gdb/documentation/>.
+ 
+   For help, type "help".
+   Type "apropos word" to search for commands related to "word"...
+   Reading symbols from /mybuild/hostid...done.
+   (gdb) r
+   Starting program: /mybuild/hostid
+ 
+   Program received signal SIGSEGV, Segmentation fault.
+   0x00007ffff7f0330e in gethostid () at ../sysdeps/unix/sysv/linux/gethostid.c:125
+   125      memcpy (&in, hp->h_addr,
+   (gdb) bt
+    #0  0x00007ffff7f0330e in gethostid () at ../sysdeps/unix/sysv/linux/gethostid.c:125
+    #1  0x0000555555555159 in main ()
+
+Upstream-Status: Submitted[https://sourceware.org/bugzilla/show_bug.cgi?id=23679]
+
+Signed-off-by: Mingli Yu <[email protected]>
+---
+ sysdeps/unix/sysv/linux/gethostid.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/sysdeps/unix/sysv/linux/gethostid.c b/sysdeps/unix/sysv/linux/gethostid.c
+index 2e20f034dc..5904b61c40 100644
+--- a/sysdeps/unix/sysv/linux/gethostid.c
++++ b/sysdeps/unix/sysv/linux/gethostid.c
+@@ -102,7 +102,7 @@ gethostid (void)
+     {
+       int ret = __gethostbyname_r (hostname, &hostbuf,
+ 				   tmpbuf.data, tmpbuf.length, &hp, &herr);
+-      if (ret == 0)
++      if (ret == 0 && hp != NULL)
+ 	break;
+       else
+ 	{
+-- 
+2.13.3
+
meta/recipes-core/glibc/glibc_2.28.bb +1 -0
index 0ebbaf9610..0a8fa0c25f 100644
@@ -45,6 +45,7 @@ SRC_URI = "${GLIBC_GIT_URI};branch=${SRCBRANCH};name=glibc \
            file://0028-bits-siginfo-consts.h-enum-definition-for-TRAP_HWBKP.patch \
            file://0029-localedef-add-to-archive-uses-a-hard-coded-locale-pa.patch \
            file://0030-intl-Emit-no-lines-in-bison-generated-files.patch \
+           file://0001-gethostid.c-check-the-value-of-hp.patch \
 "
 
 NATIVESDKFIXES ?= ""
Signature · 1 line
2.13.3
author
#2 lore raw

Will send out v3 with the update from glibc upstream.

Thanks,

Quoted 149 lines · On 2018年09月18日 17:47, [email protected] wrote:

From: Mingli Yu <[email protected]>

When run test program hostid, it encounters
Segmentation fault as hp is NULL.

  # cat /mybuild/hostid.c
  #include <stdio.h>
  #include <unistd.h>
  int
  main(int argc, char *argv[])
  {
     long hostid;
     hostid = gethostid();
     printf("the hostid is %ld\n", hostid);

  }
  # gcc -o /mybuild/hostid /mybuild/hostid.c
  # /mybuild/hostid
  Segmentation fault
  # gdb /mybuild/hostid
  GNU gdb (GDB) 8.2
  Copyright (C) 2018 Free Software Foundation, Inc.
  License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
  This is free software: you are free to change and redistribute it.
  There is NO WARRANTY, to the extent permitted by law.
  Type "show copying" and "show warranty" for details.
  This GDB was configured as "x86_64-wrs-linux".
  Type "show configuration" for configuration details.
  For bug reporting instructions, please see:
  <http://www.gnu.org/software/gdb/bugs/>.
  Find the GDB manual and other documentation resources online at:
     <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"... Reading symbols from /mybuild/hostid...done.
(gdb) r
Starting program: /mybuild/hostid

Program received signal SIGSEGV, Segmentation fault. 0x00007ffff7f0330e in gethostid () at ../sysdeps/unix/sysv/linux/gethostid.c:125
125 memcpy (&in, hp->h_addr,
(gdb) bt
#0 0x00007ffff7f0330e in gethostid () at ../sysdeps/unix/sysv/linux/gethostid.c:125 #1 0x0000555555555159 in main ()

---
  .../0001-gethostid.c-check-the-value-of-hp.patch   | 75 ++++++++++++++++++++++
  meta/recipes-core/glibc/glibc_2.28.bb              |  1 +
  2 files changed, 76 insertions(+)

create mode 100644 meta/recipes-core/glibc/glibc/0001-gethostid.c-check-the-value-of-hp.patch

meta/recipes-core/glibc/glibc/0001-gethostid.c-check-the-value-of-hp.patch new file +75 -0
new file mode 100644
index 0000000000..04d1662361
@@ -0,0 +1,75 @@
+From 84cc79a003cf1a29e0a45ee76b67a3800d9e412e Mon Sep 17 00:00:00 2001
+From: Mingli Yu <[email protected]>
+Date: Tue, 18 Sep 2018 07:29:27 +0000
+Subject: [PATCH] gethostid.c: check the value of hp
+
+Fix Segmentation fault in gethostid.c
+
+When run test program hostid, it encounters
+Segmentation fault as hp is NULL.
+
+  # cat /mybuild/hostid.c
+  #include <stdio.h>
+  #include <unistd.h>
+
+  int
+  main(int argc, char *argv[])
+  {
+    long hostid;
+    hostid = gethostid();
+    printf("the hostid is %ld\n", hostid);
+  }
+
+  # gcc -o /mybuild/hostid /mybuild/hostid.c
+  # /mybuild/hostid
+  Segmentation fault
+  # gdb /mybuild/hostid
+  GNU gdb (GDB) 8.2
+  Copyright (C) 2018 Free Software Foundation, Inc.
+  License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
+  This is free software: you are free to change and redistribute it.
+  There is NO WARRANTY, to the extent permitted by law.
+  Type "show copying" and "show warranty" for details.
+  This GDB was configured as "x86_64-wrs-linux".
+  Type "show configuration" for configuration details.
+  For bug reporting instructions, please see:
+  <http://www.gnu.org/software/gdb/bugs/>.
+  Find the GDB manual and other documentation resources online at:
+      <http://www.gnu.org/software/gdb/documentation/>.
+
+   For help, type "help".
+   Type "apropos word" to search for commands related to "word"...
+   Reading symbols from /mybuild/hostid...done.
+   (gdb) r
+   Starting program: /mybuild/hostid
+
+   Program received signal SIGSEGV, Segmentation fault.
+   0x00007ffff7f0330e in gethostid () at ../sysdeps/unix/sysv/linux/gethostid.c:125
+   125      memcpy (&in, hp->h_addr,
+   (gdb) bt
+    #0  0x00007ffff7f0330e in gethostid () at ../sysdeps/unix/sysv/linux/gethostid.c:125
+    #1  0x0000555555555159 in main ()
+
+Upstream-Status: Submitted[https://sourceware.org/bugzilla/show_bug.cgi?id=23679]
+
+Signed-off-by: Mingli Yu <[email protected]>
+---
+ sysdeps/unix/sysv/linux/gethostid.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/sysdeps/unix/sysv/linux/gethostid.c b/sysdeps/unix/sysv/linux/gethostid.c
+index 2e20f034dc..5904b61c40 100644
+--- a/sysdeps/unix/sysv/linux/gethostid.c
++++ b/sysdeps/unix/sysv/linux/gethostid.c
+@@ -102,7 +102,7 @@ gethostid (void)
+     {
+       int ret = __gethostbyname_r (hostname, &hostbuf,
+ 				   tmpbuf.data, tmpbuf.length, &hp, &herr);
+-      if (ret == 0)
++      if (ret == 0 && hp != NULL)
+ 	break;
+       else
+ 	{
+--
+2.13.3
+
meta/recipes-core/glibc/glibc_2.28.bb +1 -0
index 0ebbaf9610..0a8fa0c25f 100644
@@ -45,6 +45,7 @@ SRC_URI = "${GLIBC_GIT_URI};branch=${SRCBRANCH};name=glibc \
             file://0028-bits-siginfo-consts.h-enum-definition-for-TRAP_HWBKP.patch \
             file://0029-localedef-add-to-archive-uses-a-hard-coded-locale-pa.patch \
             file://0030-intl-Emit-no-lines-in-bison-generated-files.patch \
+           file://0001-gethostid.c-check-the-value-of-hp.patch \
  "
 
  NATIVESDKFIXES ?= ""
#3 lore raw

PATCH v3 1/1 glibc: fix Segmentation fault in gethostid.c

In reply to [email protected]

From: Mingli Yu <[email protected]>

Linux gethostid: Check for NULL value from gethostbyname_r [BZ #23679]

A NULL value can happen with certain gethostbyname_r failures.

Before this patch, there is a Segmentation fault
as below:

 # /mybuild/hostid
 Segmentation fault
 # gdb /mybuild/hostid
 GNU gdb (GDB) 8.2
 Copyright (C) 2018 Free Software Foundation, Inc.
 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
 This is free software: you are free to change and redistribute it.
 There is NO WARRANTY, to the extent permitted by law.
 Type "show copying" and "show warranty" for details.
 This GDB was configured as "x86_64-wrs-linux".
 Type "show configuration" for configuration details.
 For bug reporting instructions, please see:
 <http://www.gnu.org/software/gdb/bugs/>.
 Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"... Reading symbols from /mybuild/hostid...done.
(gdb) r
Starting program: /mybuild/hostid

Program received signal SIGSEGV, Segmentation fault. 0x00007ffff7f0330e in gethostid () at ../sysdeps/unix/sysv/linux/gethostid.c:125
125 memcpy (&in, hp->h_addr,
(gdb) bt
#0 0x00007ffff7f0330e in gethostid () at ../sysdeps/unix/sysv/linux/gethostid.c:125 #1 0x0000555555555159 in main ()

 # cat /mybuild/hostid.c
 #include <stdio.h>
 #include <unistd.h>

int
main(int argc, char *argv[])

 {
    long hostid;
    hostid = gethostid();
    printf("the hostid is %ld\n", hostid);

}

---
 ...stid-Check-for-NULL-value-from-gethostbyn.patch | 38 ++++++++++++++++++++++
 meta/recipes-core/glibc/glibc_2.28.bb              |  1 +
 2 files changed, 39 insertions(+)
 create mode 100644 meta/recipes-core/glibc/glibc/0001-Linux-gethostid-Check-for-NULL-value-from-gethostbyn.patch
meta/recipes-core/glibc/glibc/0001-Linux-gethostid-Check-for-NULL-value-from-gethostbyn.patch new file +38 -0
new file mode 100644
index 0000000000..e924779ab5
@@ -0,0 +1,38 @@
+From e7d22db29cfdd2f1fb97a70a76fa53d151569945 Mon Sep 17 00:00:00 2001
+From: Mingli Yu <[email protected]>
+Date: Thu, 20 Sep 2018 12:41:13 +0200
+Subject: [PATCH] Linux gethostid: Check for NULL value from gethostbyname_r [BZ #23679]
+
+A NULL value can happen with certain gethostbyname_r failures.
+
+(cherry picked from commit 1214ba06e6771acb953a190091b0f6055c64fd25)
+
+Upstream-Status: Backport[https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=1214ba06e6771acb953a190091b0f6055c64fd25]
+
+Signed-off-by: Mingli Yu <[email protected]>
+---
+ sysdeps/unix/sysv/linux/gethostid.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/sysdeps/unix/sysv/linux/gethostid.c b/sysdeps/unix/sysv/linux/gethostid.c
+index 2e20f034dc..ee0190e7f9 100644
+--- a/sysdeps/unix/sysv/linux/gethostid.c
++++ b/sysdeps/unix/sysv/linux/gethostid.c
+@@ -102,12 +102,12 @@ gethostid (void)
+     {
+       int ret = __gethostbyname_r (hostname, &hostbuf,
+ 				   tmpbuf.data, tmpbuf.length, &hp, &herr);
+-      if (ret == 0)
++      if (ret == 0 && hp != NULL)
+ 	break;
+       else
+ 	{
+ 	  /* Enlarge the buffer on ERANGE.  */
+-	  if (herr == NETDB_INTERNAL && errno == ERANGE)
++	  if (ret != 0 && herr == NETDB_INTERNAL && errno == ERANGE)
+ 	    {
+ 	      if (!scratch_buffer_grow (&tmpbuf))
+ 		return 0;
+-- 
+2.17.1
+
meta/recipes-core/glibc/glibc_2.28.bb +1 -0
index 0ebbaf9610..1597968318 100644
@@ -45,6 +45,7 @@ SRC_URI = "${GLIBC_GIT_URI};branch=${SRCBRANCH};name=glibc \
            file://0028-bits-siginfo-consts.h-enum-definition-for-TRAP_HWBKP.patch \
            file://0029-localedef-add-to-archive-uses-a-hard-coded-locale-pa.patch \
            file://0030-intl-Emit-no-lines-in-bison-generated-files.patch \
+           file://0001-Linux-gethostid-Check-for-NULL-value-from-gethostbyn.patch \
 "
 
 NATIVESDKFIXES ?= ""
Signature · 1 line
2.13.3
#4 lore raw

✗ patchtest: failure for glibc: fix Segmentation fault in gethostid.c (rev2)

In reply to [email protected]

== Series Details ==

Series: glibc: fix Segmentation fault in gethostid.c (rev2)
Revision: 2
URL : https://patchwork.openembedded.org/series/14116/
State : failure

== Summary ==

Thank you for submitting this patch series to OpenEmbedded Core. This is an automated response. Several tests have been executed on the proposed series by patchtest resulting in the following failures:

* Issue Series does not apply on top of target branch [test_series_merge_on_head]
Suggested fix Rebase your series on top of targeted branch
Targeted branch master (currently at 957a2f95b8)

If you believe any of these test results are incorrect, please reply to the mailing list ([email protected]) raising your concerns. Otherwise we would appreciate you correcting the issues and submitting a new version of the patchset if applicable. Please ensure you add/increment the version number when sending the new version (i.e. [PATCH] -> [PATCH v2] -> [PATCH v3] -> ...).

---

Guidelines:     https://www.openembedded.org/wiki/Commit_Patch_Message_Guidelines
Test framework: http://git.yoctoproject.org/cgit/cgit.cgi/patchtest
Test suite:     http://git.yoctoproject.org/cgit/cgit.cgi/patchtest-oe