linux: Fix __closefrom_fallback iterates until max int (BZ#28993)

Message ID 20220323204756.3654868-1-adhemerval.zanella@linaro.org
State Superseded
Headers
Series linux: Fix __closefrom_fallback iterates until max int (BZ#28993) |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

Adhemerval Zanella March 23, 2022, 8:47 p.m. UTC
  The __closefrom_fallback tries to get a available file descriptor
if the initial open ("/proc/self/fd/", ...) fails.  It assumes the
failure would be only if procfs is not mount (ENOENT), however if
the the proc file is not accessible (due some other kernel filtering
such apparmor) it will iterate over a potentially large file set
issuing close calls.

It should only try the close fallback if open returns EMFILE.

Checked on x86_64-linux-gnu.
---
 sysdeps/unix/sysv/linux/closefrom_fallback.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Patch

diff --git a/sysdeps/unix/sysv/linux/closefrom_fallback.c b/sysdeps/unix/sysv/linux/closefrom_fallback.c
index 60101aa3ba..505daa5a53 100644
--- a/sysdeps/unix/sysv/linux/closefrom_fallback.c
+++ b/sysdeps/unix/sysv/linux/closefrom_fallback.c
@@ -37,7 +37,7 @@  __closefrom_fallback (int from, _Bool dirfd_fallback)
   if (dirfd == -1)
     {
       /* The closefrom should work even when process can't open new files.  */
-      if (errno == ENOENT || !dirfd_fallback)
+      if (errno != EMFILE || !dirfd_fallback)
         goto err;
 
       for (int i = from; i < INT_MAX; i++)