From patchwork Wed Aug 18 02:28:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 44687 X-Patchwork-Delegate: fweimer@redhat.com 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 D69E7388902F for ; Wed, 18 Aug 2021 02:29:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D69E7388902F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1629253759; bh=qUz5BGaYJK/jw29LYE8MuqommWCsXOiC56hgfNbDpH4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=xnJMm1SdTUwiDrCJK+uDGWciJZLsu9q0J8VPtrCcuii6JQGegOPKF3IBExog2ldEn n5GN2eZBtxtv4djrbqIMS5w33lA31xXysj6bvV0vQqeNWcFKG7h6xXcQ1UDcHz6bAJ pDwZvQnsZdu1OHJYMLGrtaZFoPdTa4/Mk/Q0YDtQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by sourceware.org (Postfix) with ESMTPS id 084243889022 for ; Wed, 18 Aug 2021 02:28:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 084243889022 Received: by mail-pg1-x52d.google.com with SMTP id k24so688048pgh.8 for ; Tue, 17 Aug 2021 19:28:49 -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:mime-version :content-transfer-encoding; bh=qUz5BGaYJK/jw29LYE8MuqommWCsXOiC56hgfNbDpH4=; b=FmGt/TLNE62FHLa0ie87xMQDgGguLzHHmSvTUn7czOsRDSFOK5Am2vfADiM7ux5MWp Hy5odnOyQLEKdlPWjhgpLZT4U/HCQtZPWxhjVU6hx7tPxRet1goItudKC4kdgXCMUzEa a1psCxWK4iH/Ggp152c1+0k8M2ClQw5k2EhPAVfAdLfTMBMDWzA7JEbsDhKo1B+TcNdE KigcwCRFskSRgncDjuOaHkgAz1Q8FcK1fg6atDvA6Z7Ig+8HfP96FryO5fgawyRCAkoy 2YWhQ1iujSWtpidV7xKIoshaRJzwMD8NKlbx9riqiJmMx9aIenz5KmwRenMIEzmJYFia LoyQ== X-Gm-Message-State: AOAM533xbgEing8kusrGj33re2Fqubvnr1RQvQlUscUT/JyW4DFrSfJx PLp7CQ6lQrPfBP9J6lEYdkO9p9FL4tY= X-Google-Smtp-Source: ABdhPJyPrNFHP25Fa1qQS9danfiu1VgDvdWXucZUlFpVfrdcfGN9CMIyUU7Htx4pqBBV+0QXsndk4g== X-Received: by 2002:a63:653:: with SMTP id 80mr6527243pgg.388.1629253728802; Tue, 17 Aug 2021 19:28:48 -0700 (PDT) Received: from gnu-cfl-2.localdomain ([172.58.38.240]) by smtp.gmail.com with ESMTPSA id ca7sm3218218pjb.11.2021.08.17.19.28.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Aug 2021 19:28:48 -0700 (PDT) Received: from gnu-cfl-2.. (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id 5D7BBC0062 for ; Tue, 17 Aug 2021 19:28:47 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH] elf: Copy l_addr/l_ld when adding ld.so to a new namespace Date: Tue, 17 Aug 2021 19:28:47 -0700 Message-Id: <20210818022847.2041537-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3033.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" When add ld.so to a new namespace, we don't actually load ld.so. We create a new link map and refers the real one for almost everything. Copy l_addr and l_ld from the real ld.so link map to avoid GDB warning: warning: .dynamic section for ".../elf/ld-linux-x86-64.so.2" is not at the expected address (wrong library or version mismatch?) when handling shared library loaded by dlmopen. Reviewed-by: Adhemerval Zanella --- elf/dl-load.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/elf/dl-load.c b/elf/dl-load.c index cb0618b7fc..aab290bea6 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -1026,6 +1026,10 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd, /* Refer to the real descriptor. */ l->l_real = &GL(dl_rtld_map); + /* Also copy l_addr and l_ld. */ + l->l_addr = l->l_real->l_addr; + l->l_ld = l->l_real->l_ld; + /* No need to bump the refcount of the real object, ld.so will never be unloaded. */ __close_nocancel (fd);