From nobody Wed Nov 13 20:10:53 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4XpZDB6fnFz5cWws for ; Wed, 13 Nov 2024 20:11:06 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "WR4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XpZDB1jsgz4H1W for ; Wed, 13 Nov 2024 20:11:06 +0000 (UTC) (envelope-from jrtc27@jrtc27.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-4315e62afe0so69415105e9.1 for ; Wed, 13 Nov 2024 12:11:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731528665; x=1732133465; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=J4oful3xxwVSUgn5woIxLr7TGyHWHAMdF0QBhQiDrcM=; b=AIcAfTcD79YPzauzZpbw0t7FKQlAUBpdu61Adp6uUwmdAswbgfz55F5ATBfLjtJLVT dD4Yfs9ZPNNLo1Sk2njfu/EnXEA7CpIypDmAtrObr6y5zCHuXjAILbYNZMPrSYyttG47 QVVWcQl4Uw4Q7NuZPe8qAlswH5qskUdIKg96zGF50HdaG14EaTfVEpCGi6mjWrMwCIRc YfJLSytEXrINjIGbd/SEyTqPaHQaSRAxLn5crUP/Xl0+yn86rpZVZ5mnm9VDbMqT3h+Z GPU/0jBYy5HUW+F5ysyk0/3sHFTOHOwSMEvu8LChWDa9dnP84pkzt0n6wdbs/vVe3TmD offA== X-Forwarded-Encrypted: i=1; AJvYcCUlCEGUl/K1C5HoiIVbZRjQ+QOllgS78zlQR+GqvOP+Fp5tyIhMPgV9GSK7XxHpJcwax48nuPu5Rh3+vPuRpb41JrEq@freebsd.org X-Gm-Message-State: AOJu0YyRbF4BL+Y+tKzUp6j3bR4oTgMW+labEElZhza5KD8Uw+1QKdxW Z+G3lo4B6kC7Hh9XK5/tMeJ7C/ssCUr4DRubnXNE0afHwp+rF7ZDz0jg/XwJJVCLOILCVNe4bTN W X-Google-Smtp-Source: AGHT+IFlwoVAeXari+vFl0aEHF+0a0so05vPqatK1i47Zpq7hUpcMDWsxLszPmHPFxCg+qODss5Chw== X-Received: by 2002:a05:600c:4f09:b0:42e:93af:61c5 with SMTP id 5b1f17b1804b1-432b7501fdemr198402575e9.14.1731528664782; Wed, 13 Nov 2024 12:11:04 -0800 (PST) Received: from smtpclient.apple ([131.111.5.201]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432d55520e5sm34373795e9.41.2024.11.13.12.11.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Nov 2024 12:11:04 -0800 (PST) Content-Type: text/plain; charset=utf-8 List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.200.121\)) Subject: Re: git: e85eaa930862 - main - Have rtld query the page size from the kernel From: Jessica Clarke In-Reply-To: <92a05dfe-683c-43d9-bd29-3110e89be275@FreeBSD.org> Date: Wed, 13 Nov 2024 20:10:53 +0000 Cc: Andrew Turner , "src-committers@freebsd.org" , "dev-commits-src-all@freebsd.org" , "dev-commits-src-main@freebsd.org" Content-Transfer-Encoding: quoted-printable Message-Id: <768D45F9-2F02-4BA1-BFB7-51685486CFCC@freebsd.org> References: <202204071438.237Ecn2A012737@gitrepo.freebsd.org> <92a05dfe-683c-43d9-bd29-3110e89be275@FreeBSD.org> To: John Baldwin X-Mailer: Apple Mail (2.3826.200.121) X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US] X-Rspamd-Queue-Id: 4XpZDB1jsgz4H1W X-Spamd-Bar: ---- On 13 Nov 2024, at 19:44, John Baldwin wrote: >=20 > On 4/7/22 07:38, Andrew Turner wrote: >> The branch main has been updated by andrew: >> URL: = https://cgit.FreeBSD.org/src/commit/?id=3De85eaa930862d5b4dc917bc31e8d7254= a693635d >> commit e85eaa930862d5b4dc917bc31e8d7254a693635d >> Author: Andrew Turner >> AuthorDate: 2022-04-04 15:05:40 +0000 >> Commit: Andrew Turner >> CommitDate: 2022-04-07 14:37:37 +0000 >> Have rtld query the page size from the kernel >> To allow for a dynamic page size on arm64 have the runtime = linker >> query the kernel for the currentl page size. >> Reviewed by: kib >> Sponsored by: The FreeBSD Foundation >> Differential Revision: https://reviews.freebsd.org/D34765 >=20 > This broke relro handling for rtld. The reason is that = init_pagesizes() is > called after parsing the program headers for rltd in init_rtld(). As = a result, > page_size is 0 when rtld_round_page() is called so the relro_size is = 0. The > RTLD_INIT_EARLY_PAGESIZES case was for ia64, and in the early case = it's probably > not safe to call sysctl? If it is safe to call sysctl, we could just = always > init pagesizes early? It looks like there are a few things going on: 1. relocate_object calls obj_enforce_relro if !obj->mainprog, so will try to enforce RELRO for RTLD itself whilst page_size is 0 2. init_rtld later calls obj_enforce_relro for obj_rtld, after page_size has been initialised 3. init_rtld is careful to avoid using global variables until it=E2=80=99s= called relocate_objects for RTLD itself, but by hiding accesses to page_size away in rtld_*_page that=E2=80=99s no longer true (definitely = not true in the case of text relocations, for example, though whether it also occurs for other cases we care more about I don=E2=80=99t know) So I think there are a couple of things to fix: 1. Stop accessing page_size prior to relocate_objects returning for RTLD itself 2. Stop enforcing RELRO twice for RTLD (e.g. add && obj !=3D rtldobj to relocate_object=E2=80=99s case) At least, that=E2=80=99s what I=E2=80=99ve inferred from reading the = code. Though, to be honest, things might be rather nicer if we just made .rtld_start responsible for relocating RTLD itself prior to calling init_rtld, that=E2=80=99s what we have to do for CHERI, as do arm, = powerpc and powerpc64, and it means you can use globals from the start in init_rtld. Jess