From patchwork Wed Oct 14 20:37:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 40722 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 BD9383870913; Wed, 14 Oct 2020 20:37:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BD9383870913 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1602707837; bh=XXjeNnf6HxYna0sDIFO2lfnOJWDCFWoPiLBXxiFOazA=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=x2BKS1/uD30pOrYGAcI5sWrotbIDwM6uGLvTpNoi47Aeyra4EN955iaGvzsQes4FT lFiVHeii5Pi559Zv/VeWzCJ2+4YS4pPfdTtrO/T0zHBixTmBgqdZxAJ9WWYXHYd0nu aaMBswrBajIVFCTLTWW4BjWNru9P+aMa11bXr/OE= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf44.google.com (mail-qv1-xf44.google.com [IPv6:2607:f8b0:4864:20::f44]) by sourceware.org (Postfix) with ESMTPS id 01DDE3857C55 for ; Wed, 14 Oct 2020 20:37:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 01DDE3857C55 Received: by mail-qv1-xf44.google.com with SMTP id 13so200391qvc.9 for ; Wed, 14 Oct 2020 13:37:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XXjeNnf6HxYna0sDIFO2lfnOJWDCFWoPiLBXxiFOazA=; b=VGWsW+7CTh9GPfRgPYCCLKap8xBnJJ+UtlpVI4eWGJ/C5TF5nEChgMsUHGrQ2YmbEr 1If8DCf5pVGwEiFV+zJ+RC1f8ZU1jaNkHwtfM4h8jRsRCeG98LXF+Ex7pIjzBRLB9Wah 03tr03ppokY56O8QpGgmkClZUe/LyhOuAnqjUihL7K0V4DvbjfKheiUwW4dth5yNXD3C QwMKb+FvkAttOjhUwJCOfsDWZZpKvKsWKfS7qVmH8NUuD+JLt2vo6/SORv7Lbo9TOuSU U6ECEAN+gVk7fhIrJOUkXOsCzI5A+OYY2EU3fV0CXQytk0ggySjn80z7FyFS/UjrwToO xI3Q== X-Gm-Message-State: AOAM532NGHHRTwM+mpsna49Z3gr55t86UFRnFSKRJGxOvsguaS9uDQOM JeUwLOsJo/FqrzlT8NmEgYs77tgmUnqWaQ== X-Google-Smtp-Source: ABdhPJw0CHrFFjHGsLcmnMK+CU162/UPIRvyqDiuPe4MSeZm0Zo10BHVVUHroOiJpXDg35vwDlAMMw== X-Received: by 2002:ad4:456c:: with SMTP id o12mr1190407qvu.48.1602707834326; Wed, 14 Oct 2020 13:37:14 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id d142sm341968qke.125.2020.10.14.13.37.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Oct 2020 13:37:13 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 2/3] rtld: Fix wrong errno check on open_path Date: Wed, 14 Oct 2020 17:37:06 -0300 Message-Id: <20201014203707.2394289-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201014203707.2394289-1-adhemerval.zanella@linaro.org> References: <20201014203707.2394289-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-14.2 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 autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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@sourceware.org Sender: "Libc-alpha" At open_path code: elf/dl-load.c 1982 if (here_any && (err = errno) != ENOENT && err != EACCES) 1983 /* The file exists and is readable, but something went wrong. */ 1984 return -1; This code checks the errno value without checking whether the previous function call that changed 'err' actually has failed (in this specific case the stat64 at line 1931). This due how we currently implemented the y2038 support with INLINE_SYSCALL_CALL (since a function that succeeds is allowed to change errno and it simplifies the resulting y2038 support a bit). In fact this check does not really make much sense, since either 'fd' will be different than '0' (meaning it has being opened) or the 'stat64' at line 1931 failed and 'here_any' will not be set (the stat64 at line 1951 already explicit sets errno in failure case). Also, git history does not give much information on why it was added at fist place. Checked on i686-linux-gnu, x86_64-linux-gnu, sparc64-linux-gnu, sparcv9-linux-gnu, powerpc64-linux-gnu, powerpc64le-linux-gnu, arm-linux-gnueabihf, and aarch64-linux-gnu. --- elf/dl-load.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/elf/dl-load.c b/elf/dl-load.c index f3201e7c14..e6972a6fe6 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -1878,7 +1878,6 @@ open_path (const char *name, size_t namelen, int mode, size_t cnt; char *edp; int here_any = 0; - int err; /* If we are debugging the search for libraries print the path now if it hasn't happened now. */ @@ -1979,9 +1978,6 @@ open_path (const char *name, size_t namelen, int mode, return -1; } } - if (here_any && (err = errno) != ENOENT && err != EACCES) - /* The file exists and is readable, but something went wrong. */ - return -1; /* Remember whether we found anything. */ any |= here_any; @@ -2002,6 +1998,8 @@ open_path (const char *name, size_t namelen, int mode, sps->dirs = (void *) -1; } + /* The errno is used by _dl_signal_error. */ + __set_errno (ENOENT); return -1; }