From patchwork Thu Feb 22 23:24:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 86242 X-Patchwork-Delegate: carlos@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 465A83858425 for ; Thu, 22 Feb 2024 23:26:57 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by sourceware.org (Postfix) with ESMTPS id EC1503858416 for ; Thu, 22 Feb 2024 23:26:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EC1503858416 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EC1503858416 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::634 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708644387; cv=none; b=wTb+r4uqKQiGyQH0LFbbA5dS/Wi4faZqU0KGpLbOKEvp78UH1GmchOJd1Gm3dzPNq0277pno12/aJnYLO2aFJTqNpczPFIwyD3fdyWN0342M/cW9YUqnmZF4LI03KdnjMH5ofCLjCSYOvk0iBZIMfVsWgXLV2dhvSQRO89fB8wg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708644387; c=relaxed/simple; bh=5TQanutU2+l01aC0xu9rS4WDaRm98SAY3JUD7xikNuA=; h=DKIM-Signature:Subject:Date:Message-ID:MIME-Version:From:To; b=PXqRFYJ8vK+P3EBnA/4tgJ51wkaO9h/4GsZA0l0cN/h1WNqViORhDUusCHNItVVbZeXwJOviJRB6CQmtzkRcWYIt/vjiCB5zxAzSfxlZ4GsXhmkBdQqd/Y5M3qcY3nTz/uDx42pRn5fu18XvQ7qBbT54ZtzVyyo7jS3s/cK1CPs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1d73066880eso3308655ad.3 for ; Thu, 22 Feb 2024 15:26:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1708644383; x=1709249183; darn=sourceware.org; h=to:from:cc:content-transfer-encoding:mime-version:message-id:date :subject:from:to:cc:subject:date:message-id:reply-to; bh=obu+mND9TmEma98L9LDVlACrz2IVj93enubWg1BByY8=; b=b1vwHi0F2XbdJFVe38J1UaBntQUc0TIJBY5xXqGbGCjPMU/nEpRenSgGhCSp5U3P4s GE+OULTOnJypVJHICo9wh6rGx8+dBmZzMN1osj2pUbDoXMRI71xsZZESOQzPOKCqxNjt NOC3e0RnhowzO7DBfwVEWhtHNzl6MovzH2ZfY8RFUuVFX6VKrStX7FDLanwSSm+g+b9I S51IOM1mWKWnpkDjQeSEpQqKTovUBYkPpUZocFZcv7fByLvupoAsVawTHRQahiTdQBNl dpELa1BIhzC4nXa9Ul2rWSjzLKCaIrPIeBGAl3AIRskK5vnNneSqqlsxVj5Ko5J1Y8Uy kSgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708644383; x=1709249183; h=to:from:cc:content-transfer-encoding:mime-version:message-id:date :subject:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=obu+mND9TmEma98L9LDVlACrz2IVj93enubWg1BByY8=; b=Q+wCf2GfMupdxWY46433xDTsWuFojZQLMfsPcFXAj8uDJZuu68zBtg816DVtQpJjj3 YHxHPETjPaz/7suXwYopqz2iVlCjQR4DzHQ2I+UgbmtMo4oH5qkzSRJc1RUdZy6zWijX E9t49gtyH5/p+gXlXiXb96WmOJyy8ojceng1Aqh8wDoc+7IGQj9gAeeM4DtzKYupSCUB aW6GeK7t996CVJIdhPLcdL2Cd63dEVxVTxKUD/xUNW3QCmNsutHn51dZ+ZX0Y/yOXNr3 YBJCTHD9pcIL42+WtDG/e8ftOMqZSFfLpw9Qz6mx1fc3aZBiqv93oeQOFuhHxDLAeRAF zJlQ== X-Gm-Message-State: AOJu0YxMXNQxHchrbEA0EEBffzxYihwCc7Xe2RbdrrfHeZ3pofN2QzWB edYL85Jpmsd7Qtp7rZo2FLRuQRPmFU748q8G8RrezA5AAGAkskw19DCYNbkIen4= X-Google-Smtp-Source: AGHT+IE9QF+mR2LmTZ48L5AtOS2YG5k+IFZfb/eafkJzw0F1ZXuv0tnkV0wr9PzhwAiQqmUI6mBJvw== X-Received: by 2002:a17:902:e889:b0:1db:ccd1:415d with SMTP id w9-20020a170902e88900b001dbccd1415dmr315908plg.44.1708644383466; Thu, 22 Feb 2024 15:26:23 -0800 (PST) Received: from localhost ([50.213.54.97]) by smtp.gmail.com with ESMTPSA id v13-20020a170902f0cd00b001d8d1a2e5f2sm10532124pla.216.2024.02.22.15.26.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 15:26:23 -0800 (PST) Subject: [PATCH] RISC-V: Fix the static-PIE non-relocated object check Date: Thu, 22 Feb 2024 15:24:00 -0800 Message-ID: <20240222232400.6326-1-palmer@rivosinc.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Cc: schwab@suse.de, yanzhang.wang@intel.com, adhemerval.zanella@linaro.org, Palmer Dabbelt From: Palmer Dabbelt To: libc-alpha@sourceware.org X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, 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.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org The value of l_scope is only valid post relocation, so this original check was triggering undefined behavior. Instead just directly check to see if the object has been relocated, at which point using l_scope is safe. Reported-by: Andreas Schwab Closes: BZ #31317 Fixes: e0590f41fe ("RISC-V: Enable static-pie.") Signed-off-by: Palmer Dabbelt --- sysdeps/riscv/dl-machine.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sysdeps/riscv/dl-machine.h b/sysdeps/riscv/dl-machine.h index 0cbb476c05..b2f28697f7 100644 --- a/sysdeps/riscv/dl-machine.h +++ b/sysdeps/riscv/dl-machine.h @@ -348,7 +348,7 @@ elf_machine_runtime_setup (struct link_map *l, struct r_scope_elem *scope[], gotplt[1] = (ElfW(Addr)) l; } - if (l->l_type == lt_executable && l->l_scope != NULL) + if (l->l_type == lt_executable && l->l_relocated) { /* The __global_pointer$ may not be defined by the linker if the $gp register does not be used to access the global variable