Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp1486642ybm; Thu, 23 May 2019 01:44:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqzsD4gHYkH+UwLqi4IZaY2Gel563H+b5/10/fwj3cOTq041rr318v79SPSH6C+lq2NxVZFr X-Received: by 2002:aa7:9a1d:: with SMTP id w29mr80348172pfj.81.1558601046029; Thu, 23 May 2019 01:44:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558601046; cv=none; d=google.com; s=arc-20160816; b=soUg8gcoYyGCVHcVsXgenX3XDw526CEyeSI0YDKYkd5w7tu/QJM+MvlqfYG5Pt5FXV bC4vLE0BYFrkHoLPMcCb5dCfdERFxu8qQN3AfbKDvV5fIzrOfhR5Ocyrp5u9ibebj8/Y dZFrmOZ7xN+hFWsfONXcSSsQ63lm124Jh0I7ora+cKAJ7DFrmAIa6Opov6NmwFHBMKBm BfVnYr00Fi3tiP15FCkwxNGrykbgnn1l5n5nDSiRI5Rs02YG1J5aPBIathZfz2F9MLuc rVmfM3tL9aKU5ocvCJwhI+gdV0My166BqpyL7F1gmHVpihoTzdLf7/6U9n20Z9Guws1p P77Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:from:subject; bh=cErTVlAMpUQpvHwmGcZrOP+Ozc/H7nBTfgDTv7/W1ck=; b=Ch7AyNpbTHlAFxFf4k5ozwEvc7AqcO8UiDIH7zhzlhPqMjHOb3eINNBzyySxfYYd5I 6yOnppHyMjgpEQ9tBqEplIUz1BoAv8dJb4NnNiFUo00zYuuuBQpwv5wsXqaserkhXtID PgHGtFUjVyojK0xk/mwgOWbIyeS40EORqvWLeo7tPbh/ySAzZeE5gkgm3y0klr1wOpXQ 1v4w5Z+TxgtxRIs0PrHoNa+dLVc38+bveNkBl95Wo0jqUJirmS8zMMT1EpXv+LMYygKw BlWa308WSECJ8HJYcDaJII7FeAD4WRG3jjr1nPxdQhxJIAp9kWIYDW+JNIFMZDisf6fI 3E4w== 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 cn12si29966960plb.349.2019.05.23.01.43.47; Thu, 23 May 2019 01:44:06 -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 S1729817AbfEWIlp (ORCPT + 99 others); Thu, 23 May 2019 04:41:45 -0400 Received: from foss.arm.com ([217.140.101.70]:40174 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726299AbfEWIlp (ORCPT ); Thu, 23 May 2019 04:41:45 -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 AF388341; Thu, 23 May 2019 01:41:44 -0700 (PDT) Received: from [10.1.39.23] (unknown [10.1.39.23]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0047B3F575; Thu, 23 May 2019 01:41:41 -0700 (PDT) Subject: Re: [PATCH] module/ksymtab: use 64-bit relative reference for target symbol From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: marc.zyngier@arm.com, james.morse@arm.com, will.deacon@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 References: <20190522150239.19314-1-ard.biesheuvel@arm.com> <293c9d0f-dc14-1413-e4b4-4299f0acfb9e@arm.com> Message-ID: Date: Thu, 23 May 2019 09:41:40 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <293c9d0f-dc14-1413-e4b4-4299f0acfb9e@arm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) 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. So please disregard this patch (and the followup one against arch/x86/tools) -- Ard.