Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp1516000ybm; Thu, 23 May 2019 02:19:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqzZ695hDt0D+op38b8Y+1CJqke/YHGrx2hZqJ/cY0G5eFWq3tXl0f43E94CD94NNMt19ePX X-Received: by 2002:a62:cdc6:: with SMTP id o189mr75508156pfg.74.1558603180990; Thu, 23 May 2019 02:19:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558603180; cv=none; d=google.com; s=arc-20160816; b=0GoeIpnNp+zhYOFACKchNSjkLOqWYifWWjD+8ERaAwlrBsR1iMGIFp+qbFhmW4429I bX6WM9pKo4Ue3kDzU6duUbdAx7HoJem1uPrqhY7ZuFGWE1I6W8EJjc8G0FpN7gDnXnyK pIhcv5wmFr3BRuThbKBe20pjRnooT/ocAMAJWns0ZL4HQY3PQEpunvjmu98J07NyIrMV 1v1/pCLOB3fFgZcjuWfljm7UOvgFySoaWlZULfct0g2CISqJ978OKDTqunuDxBV+6l4N q9CjWLYVBcVTZiXFvz9YSWQuwDi6/jxwbM0BpF5EZH2MhlU29EiDFee6/0SyDvl9dTs4 mGtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=ZbWCPZndcAFPhzxiZWh9vA5Jp1OrEfX5pbL+pOWk74o=; b=xSbdGsEesRf7YU45aprfHcAL1DjR79MKEaA/YkEl/BsNz9rs2y+Y4mPAoYCnoc5Mme 9zKNong6TQ5e7y+Fb//6Nr2YRISXvF8xz8O1M8ntcBznwJqPnLpEWGkcD1CJn+T3OWnO zyFuPL+iEQK+QEj6yEp1xqsFAJWKe8gH/EFgzbxMKXSi/tOyaiV1OhE5A4HLQub2sIYk YmGusPdv4ixx84DhJP8PydduMz5p1X7CC1x00dlE6TjOWZxGqwOJc1p+y9327MpW1RLR JcQhVL/1dVz+hCJkcmeR5ada1/4KptfH3I82So83VqG+fLEDlk+In4zRKkq40Qq4oXAL 6b/g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h7si23221035plr.137.2019.05.23.02.19.26; Thu, 23 May 2019 02:19:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729962AbfEWJSS (ORCPT + 99 others); Thu, 23 May 2019 05:18:18 -0400 Received: from foss.arm.com ([217.140.101.70]:41126 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726429AbfEWJSS (ORCPT ); Thu, 23 May 2019 05:18:18 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 13545341; Thu, 23 May 2019 02:18:18 -0700 (PDT) Received: from fuggles.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F20363F718; Thu, 23 May 2019 02:18:15 -0700 (PDT) Date: Thu, 23 May 2019 10:18:11 +0100 From: Will Deacon To: Ard Biesheuvel Cc: linux-arm-kernel@lists.infradead.org, marc.zyngier@arm.com, james.morse@arm.com, guillaume.gardet@arm.com, mark.rutland@arm.com, mingo@kernel.org, jeyu@kernel.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, arnd@arndb.de, x86@kernel.org Subject: Re: [PATCH] module/ksymtab: use 64-bit relative reference for target symbol Message-ID: <20190523091811.GA26646@fuggles.cambridge.arm.com> References: <20190522150239.19314-1-ard.biesheuvel@arm.com> <293c9d0f-dc14-1413-e4b4-4299f0acfb9e@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.11.1+86 (6f28e57d73f2) () Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 23, 2019 at 09:41:40AM +0100, Ard Biesheuvel wrote: > > > On 5/22/19 5:28 PM, Ard Biesheuvel wrote: > > > > > > On 5/22/19 4:02 PM, Ard Biesheuvel wrote: > > > The following commit > > > > > > ?? 7290d5809571 ("module: use relative references for __ksymtab entries") > > > > > > updated the ksymtab handling of some KASLR capable architectures > > > so that ksymtab entries are emitted as pairs of 32-bit relative > > > references. This reduces the size of the entries, but more > > > importantly, it gets rid of statically assigned absolute > > > addresses, which require fixing up at boot time if the kernel > > > is self relocating (which takes a 24 byte RELA entry for each > > > member of the ksymtab struct). > > > > > > Since ksymtab entries are always part of the same module as the > > > symbol they export (or of the core kernel), it was assumed at the > > > time that a 32-bit relative reference is always sufficient to > > > capture the offset between a ksymtab entry and its target symbol. > > > > > > Unfortunately, this is not always true: in the case of per-CPU > > > variables, a per-CPU variable's base address (which usually differs > > > from the actual address of any of its per-CPU copies) could be at > > > an arbitrary offset from the ksymtab entry, and so it may be out > > > of range for a 32-bit relative reference. > > > > > (Apologies for the 3-act monologue) Exposition, development and recapitulation ;) > This turns out to be incorrect. The symbol address of per-CPU variables > exported by modules is always in the vicinity of __per_cpu_start, and so it > is simply a matter of making sure that the core kernel is in range for > module ksymtab entries containing 32-bit relative references. > > When running the arm64 with kaslr enabled, we currently randomize the module > space based on the range of ADRP/ADD instruction pairs, which have a -/+ 4 > GB range rather than the -/+ 2 GB range of 32-bit place relative data > relocations. So we can fix this by simply reducing the randomization window > to 2 GB. Makes sense. Do you see the need for an option to disable PREL relocs altogether in case somebody wants the additional randomization range? Will