diff options
| -rw-r--r-- | backport-bugfix-wrong-symlink-length-on-some-filesystems.patch | 45 | ||||
| -rw-r--r-- | backport-hardlink.patch | 151 | ||||
| -rw-r--r-- | rpm.spec | 4 |
3 files changed, 153 insertions, 47 deletions
diff --git a/backport-bugfix-wrong-symlink-length-on-some-filesystems.patch b/backport-bugfix-wrong-symlink-length-on-some-filesystems.patch deleted file mode 100644 index 5de4522..0000000 --- a/backport-bugfix-wrong-symlink-length-on-some-filesystems.patch +++ /dev/null @@ -1,45 +0,0 @@ -From 4c301883a5a94a9a186a1bb1d45d234db4db7c88 Mon Sep 17 00:00:00 2001 -From: Dominik Neudert-Schulz <dominikns@bachtechnology.com> -Date: Wed, 30 Jun 2021 14:13:46 +0200 -Subject: [PATCH] fix rpmbuild failure because of wrong symlink length on some - filesystems - ---- - build/files.c | 16 ++++++++++++++++ - 1 file changed, 16 insertions(+) - -diff --git a/build/files.c b/build/files.c -index f8153ad2b5..571b502e91 100644 ---- a/build/files.c -+++ b/build/files.c -@@ -1363,6 +1363,8 @@ static rpmRC addFile(FileList fl, const char * diskPath, - { - size_t plen = strlen(diskPath); - char buf[plen + 1]; -+ char linkPath[PATH_MAX]; -+ ssize_t linkLen; - const char *cpioPath; - struct stat statbuf; - mode_t fileMode; -@@ -1459,6 +1461,20 @@ static rpmRC addFile(FileList fl, const char * diskPath, - fileUid = statp->st_uid; - fileGid = statp->st_gid; - -+ if (S_ISLNK(fileMode)) { -+ /* stat's man page states that statp->st_size should equal the length of -+ the pointed-to path. On some filesystem a wrong size is reported. -+ So, explicitly get the length here. */ -+ linkLen = readlink(diskPath, linkPath, sizeof(linkPath)); -+ if ((linkLen < 0) || (linkLen >= sizeof(linkPath))) { -+ rpmlog(RPMLOG_ERR, -+ "Symbolic link too long or corrupt: %s\n", -+ diskPath); -+ goto exit; -+ } -+ statp->st_size = linkLen; -+ } -+ - /* Explicit %attr() always wins */ - if (fl->cur.ar.ar_fmodestr) { - if (S_ISLNK(fileMode)) { - diff --git a/backport-hardlink.patch b/backport-hardlink.patch new file mode 100644 index 0000000..646b6ae --- /dev/null +++ b/backport-hardlink.patch @@ -0,0 +1,151 @@ +From c0899e5b913b70f40b4ac4a314d18437f82ad5bc Mon Sep 17 00:00:00 2001 +From: Panu Matilainen <pmatilai@redhat.com> +Date: Mon, 14 Mar 2022 09:18:28 +0200 +Subject: [PATCH 1/2] Fix file descriptor leak regression on install (#1947) + +Commit 0e3024ca3e7450104e70ec8d213cf223e71f7c02 introduced a leak on +directory file descriptors from hardlinked sets, preventing some large +packages with many hardlinks from installing at all. + +fsmMkfile() needs to close the firstdir fd when done with it because +that's the only place that knows when it's safe to do so. However, there +could be non-hardlink entries left in the same directory, so we must not +close *that* descriptor. Dup the firstdir descriptor so we're free to +close it without worrying about the other state. + +Fixes: #1947 +--- + lib/fsm.c | 7 +++---- + 1 file changed, 3 insertions(+), 4 deletions(-) + +diff --git a/lib/fsm.c b/lib/fsm.c +index 4859d62ee6..5a74b43cd7 100644 +--- a/lib/fsm.c ++++ b/lib/fsm.c +@@ -208,7 +208,7 @@ static int fsmMkfile(int dirfd, rpmfi fi, struct filedata_s *fp, rpmfiles files, + if (fp->sb.st_nlink > 1) { + *firstlink = fp; + *firstlinkfile = fd; +- *firstdir = dirfd; ++ *firstdir = dup(dirfd); + } + } else { + /* Create hard links for others and avoid redundant metadata setting */ +@@ -227,7 +227,7 @@ static int fsmMkfile(int dirfd, rpmfi fi, struct filedata_s *fp, rpmfiles files, + fp->setmeta = 1; + *firstlink = NULL; + *firstlinkfile = -1; +- *firstdir = -1; ++ fsmClose(firstdir); + } + } + *fdp = fd; +@@ -841,8 +841,7 @@ static int onChdir(rpmfi fi, void *data) + struct diriter_s *di = data; + + if (di->dirfd >= 0) { +- if (di->dirfd != di->firstdir) +- close(di->dirfd); ++ close(di->dirfd); + di->dirfd = -1; + } + return 0; + +From 661a19f08f07fdf1e4b246f8d8bbcfc193531033 Mon Sep 17 00:00:00 2001 +From: Panu Matilainen <pmatilai@redhat.com> +Date: Mon, 14 Mar 2022 09:52:21 +0200 +Subject: [PATCH 2/2] Use fsmClose() for closing file descriptors everywhere + within fsm + +fsmClose() does all the necessary checks and resets the fd to -1 after +close, why duplicate these all over the code when we already have a +function... + +There's no difference wrt file descriptors getting closed here, but +there is a side-effect to this: if %_flush_io is enabled, they now +get fsync() on the associated directories too, which I think is a good +thing for those who care about it. +--- + lib/fsm.c | 28 +++++++++------------------- + 1 file changed, 9 insertions(+), 19 deletions(-) + +diff --git a/lib/fsm.c b/lib/fsm.c +index 5a74b43cd7..28eb9431bd 100644 +--- a/lib/fsm.c ++++ b/lib/fsm.c +@@ -66,6 +66,7 @@ struct filedata_s { + */ + static const char * fileActionString(rpmFileAction a); + static int fsmOpenat(int dirfd, const char *path, int flags, int dir); ++static int fsmClose(int *wfdp); + + /** \ingroup payload + * Build path to file from file info, optionally ornamented with suffix. +@@ -101,7 +102,7 @@ static int cap_set_fileat(int dirfd, const char *path, cap_t fcaps) + int fd = fsmOpenat(dirfd, path, O_RDONLY|O_NOFOLLOW, 0); + if (fd >= 0) { + rc = cap_set_fd(fd, fcaps); +- close(fd); ++ fsmClose(&fd); + } + return rc; + } +@@ -326,8 +327,7 @@ static int fsmOpenat(int dirfd, const char *path, int flags, int dir) + /* O_DIRECTORY equivalent */ + if (dir && fd >= 0 && fstat(fd, &sb) == 0 && !S_ISDIR(sb.st_mode)) { + errno = ENOTDIR; +- close(fd); +- fd = -1; ++ fsmClose(&fd); + } + return fd; + } +@@ -395,7 +395,7 @@ static int ensureDir(rpmPlugins plugins, const char *p, int owned, int create, + rc = fsmDoMkDir(plugins, dirfd, bn, apath, owned, mode, &fd); + } + +- close(dirfd); ++ fsmClose(&dirfd); + if (fd >= 0) { + dirfd = fd; + } else { +@@ -411,9 +411,8 @@ static int ensureDir(rpmPlugins plugins, const char *p, int owned, int create, + } + + if (rc) { +- close(fd); +- close(dirfd); +- dirfd = -1; ++ fsmClose(&fd); ++ fsmClose(&dirfd); + } else { + rc = 0; + } +@@ -840,10 +839,7 @@ static int onChdir(rpmfi fi, void *data) + { + struct diriter_s *di = data; + +- if (di->dirfd >= 0) { +- close(di->dirfd); +- di->dirfd = -1; +- } ++ fsmClose(&(di->dirfd)); + return 0; + } + +@@ -861,14 +857,8 @@ static rpmfi fsmIter(FD_t payload, rpmfiles files, rpmFileIter iter, void *data) + + static rpmfi fsmIterFini(rpmfi fi, struct diriter_s *di) + { +- if (di->dirfd >= 0) { +- close(di->dirfd); +- di->dirfd = -1; +- } +- if (di->firstdir >= 0) { +- close(di->firstdir); +- di->firstdir = -1; +- } ++ fsmClose(&(di->dirfd)); ++ fsmClose(&(di->firstdir)); + return rpmfiFree(fi); + } @@ -113,7 +113,7 @@ Patch6074: backport-Fix-possible-null-pointer-reference-in-ndb.patch Patch6075: backport-Fix-rpmDigestBundleFinal-and-Update-return-code-on-i.patch Patch6076: backport-Actually-return-an-error-in-parseScript-if-parsing-f.patch Patch6077: backport-Check-inside-root-when-querying-for-files.patch -Patch6078: backport-bugfix-wrong-symlink-length-on-some-filesystems.patch +Patch6078: backport-hardlink.patch BuildRequires: gcc autoconf automake libtool make gawk popt-devel openssl-devel readline-devel BuildRequires: zlib-devel zstd-devel >= 1.3.8 xz-devel bzip2-devel libarchive-devel ima-evm-utils-devel @@ -405,7 +405,7 @@ make check || (cat tests/rpmtests.log; exit 0) %changelog * Sun Sep 10 2023 chencheng<chenc136@chinaunicom.cn> - 4.17.0-31 -- add patch 6078 +- support _disable_auto_rebuilddb macro in posttrans * Fri Sep 08 2023 renhongxun<renhongxun@h-partners.com> - 4.17.0-30 - support _disable_auto_rebuilddb macro in posttrans |
