From patchwork Wed Mar 23 20:47:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 52266 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D704A388458B for ; Wed, 23 Mar 2022 20:48:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D704A388458B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1648068504; bh=zaxxn5DANYom7zdH+scls8AYGYjlsDw5aksL2L84G74=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=WJDpegkz6wKBuZcITcikGAHrd3yBoFAQyrbUE7661U+61dL1aqng/9fojpvKIdTrJ cGfydVvKPhXS1z4O5/AZLHC9LPDSEP9EIEJoTmGLUwDGpGI0Y4vmKE2xf1dynlL0zj PQT2mQf5R/beGA+OJ2U1lpFT/urwbIJKf5tGOj7A= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x22a.google.com (mail-oi1-x22a.google.com [IPv6:2607:f8b0:4864:20::22a]) by sourceware.org (Postfix) with ESMTPS id 0B4623858C2C for ; Wed, 23 Mar 2022 20:48:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0B4623858C2C Received: by mail-oi1-x22a.google.com with SMTP id e4so2910141oif.2 for ; Wed, 23 Mar 2022 13:48:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=zaxxn5DANYom7zdH+scls8AYGYjlsDw5aksL2L84G74=; b=n310liWtFsSWm916VzXQlimw/BBYgfU4ucyey6eoS9W4O1wEOawaiaK2ZxoKdZnk6r j0YqEcf9ly6pib4Cjvy7qhSi3ovfmipWo0juc4CHMVXkaHt6Rl1zhPv5fitD6bbKQWZD RF4WAQP9J1zLmvv35J9ZiVsuUDXHxUx0sw2Aw0dJE2pK3S6lmIXBlHSdDrz3qngKuXo4 eCtfeTRAojNhzMZacKWJhIvkkm7NcirprphPFygXeOmYw6MVwITjIiF1PK4O2CVJYvAF GZSSR0VgxOy9y+Df3b72Ls7BTHNnCXB+oznoUzzTJHqcO7VsKWqSK/56WCL+8UWu94rN x3tQ== X-Gm-Message-State: AOAM531wP2IYK+F5FzLcWrJ+e6PLYJMxXbtpVXuVTIRvUgKWEHdnCYGs ifkMq64yHyA2uJ7LTC0mLrj2OjNYByYM6A== X-Google-Smtp-Source: ABdhPJzu9+ngGe3in+nGljlgfmgZ7nXax8Qz/WmfW5Qw8nsa87ZL9JzwOUvJ+neJQ9f+ueOCWOcs1A== X-Received: by 2002:aca:a957:0:b0:2ec:9f63:c3d4 with SMTP id s84-20020acaa957000000b002ec9f63c3d4mr5336288oie.230.1648068480582; Wed, 23 Mar 2022 13:48:00 -0700 (PDT) Received: from birita.. ([2804:431:c7ca:2d55:7794:d006:fba1:8b8f]) by smtp.gmail.com with ESMTPSA id n124-20020aca4082000000b002ecd08d8497sm431321oia.5.2022.03.23.13.47.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Mar 2022 13:48:00 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH] linux: Fix __closefrom_fallback iterates until max int (BZ#28993) Date: Wed, 23 Mar 2022 17:47:56 -0300 Message-Id: <20220323204756.3654868-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" 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(-) 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++)