commit:     6639b5025d4c120c30022cb2993832fcf0c2e928
Author:     Adrian Ratiu <adrian.ratiu <AT> collabora <DOT> com>
AuthorDate: Mon Jun 21 09:21:40 2021 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Jun 21 13:26:52 2021 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=6639b502

sys-process/lsof: backport arm sigbus crash fix

This backports an upstream fix for a crash which happens on
armv7a + glibc 2.33 due to a buffer misalignment.

Upstream issue: https://github.com/lsof-org/lsof/issues/160
Upstream commit: 21cb1dad1243f4c0a427d893babab12e48b60f0e
Bug: https://bugs.gentoo.org/797358
Closes: https://github.com/gentoo/gentoo/pull/21354
Acked-by: David Seifert <soap <AT> gentoo.org>
Signed-off-by: Adrian Ratiu <adrian.ratiu <AT> collabora.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 .../lsof/files/lsof-4.94-arm-sigbus-fix.patch      | 63 ++++++++++++++++++++++
 .../{lsof-4.94.0.ebuild => lsof-4.94.0-r1.ebuild}  |  1 +
 2 files changed, 64 insertions(+)

diff --git a/sys-process/lsof/files/lsof-4.94-arm-sigbus-fix.patch 
b/sys-process/lsof/files/lsof-4.94-arm-sigbus-fix.patch
new file mode 100644
index 00000000000..95bad206372
--- /dev/null
+++ b/sys-process/lsof/files/lsof-4.94-arm-sigbus-fix.patch
@@ -0,0 +1,63 @@
+https://bugs.gentoo.org/797358
+
+From 21cb1dad1243f4c0a427d893babab12e48b60f0e Mon Sep 17 00:00:00 2001
+From: Masatake YAMATO <yam...@redhat.com>
+Date: Sun, 20 Jun 2021 21:40:55 +0900
+Subject: [PATCH] Adjust alignment of buffer passed to stat()
+
+Close #160.
+
+The original code passes char[] buffer to stat().
+This can be cause a SIGBUS.
+
+#160 reported an actual crash on armv7a + glibc-2.33 platform.
+See also https://sourceware.org/bugzilla/show_bug.cgi?id=27993.
+
+The issue is reported by @10ne1.
+
+Signed-off-by: Masatake YAMATO <yam...@redhat.com>
+[Adrian: Backported to 4.94]
+Signed-off-by: Adrian Ratiu <adrian.ra...@collabora.com>
+--- a/misc.c
++++ b/misc.c
+@@ -293,7 +293,15 @@ doinchild(fn, fp, rbuf, rbln)
+                */
+ 
+                   int r_al, r_rbln;
+-                  char r_arg[MAXPATHLEN+1], r_rbuf[MAXPATHLEN+1];
++                  char r_arg[MAXPATHLEN+1];
++                  union {
++                          char r_rbuf[MAXPATHLEN+1];
++                          /*
++                           * This field is only for adjusting the alignment 
of r_rbuf that
++                           * can be used as an argument for stat().
++                           */
++                          struct stat _;
++                  } r;
+                   int (*r_fn)();
+               /*
+                * Close sufficient open file descriptors except Pipes[0] and
+@@ -358,16 +366,16 @@ doinchild(fn, fp, rbuf, rbln)
+                       ||  read(Pipes[0], r_arg, r_al) != r_al
+                       ||  read(Pipes[0], (char *)&r_rbln, sizeof(r_rbln))
+                           != (int)sizeof(r_rbln)
+-                      ||  r_rbln < 1 || r_rbln > (int)sizeof(r_rbuf))
++                      ||  r_rbln < 1 || r_rbln > (int)sizeof(r.r_rbuf))
+                           break;
+-                      zeromem (r_rbuf, r_rbln);
+-                      rv = r_fn(r_arg, r_rbuf, r_rbln);
++                      zeromem (r.r_rbuf, r_rbln);
++                      rv = r_fn(r_arg, r.r_rbuf, r_rbln);
+                       en = errno;
+                       if (write(Pipes[3], (char *)&rv, sizeof(rv))
+                           != sizeof(rv)
+                       ||  write(Pipes[3], (char *)&en, sizeof(en))
+                           != sizeof(en)
+-                      ||  write(Pipes[3], r_rbuf, r_rbln) != r_rbln)
++                      ||  write(Pipes[3], r.r_rbuf, r_rbln) != r_rbln)
+                           break;
+                   }
+                   (void) _exit(0);
+-- 
+2.32.0
+

diff --git a/sys-process/lsof/lsof-4.94.0.ebuild 
b/sys-process/lsof/lsof-4.94.0-r1.ebuild
similarity index 98%
rename from sys-process/lsof/lsof-4.94.0.ebuild
rename to sys-process/lsof/lsof-4.94.0-r1.ebuild
index e71171a60c4..f90987e7670 100644
--- a/sys-process/lsof/lsof-4.94.0.ebuild
+++ b/sys-process/lsof/lsof-4.94.0-r1.ebuild
@@ -28,6 +28,7 @@ RESTRICT="test"
 
 PATCHES=(
        "${FILESDIR}"/${PN}-4.85-cross.patch #432120
+       "${FILESDIR}"/${PN}-4.94-arm-sigbus-fix.patch
 )
 
 src_prepare() {

Reply via email to