Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp279132ima; Sat, 20 Oct 2018 07:11:52 -0700 (PDT) X-Google-Smtp-Source: ACcGV63INvJSH7o/pEAgkzF69IGstnI77z35bM2OcY0rUakcPZRY0T5T+x4Abjd9L7xzbSDm+HJa X-Received: by 2002:a63:bc12:: with SMTP id q18-v6mr35020444pge.353.1540044712289; Sat, 20 Oct 2018 07:11:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540044712; cv=none; d=google.com; s=arc-20160816; b=MEYuDFU0GUOuhCktjdpjqJa8KTyEm83ZadZhd4FUi6s3P1mNQU/fTp+eZDfdCHU0EB 9xiLui1/qILFBIiAEwGOleTPFegqlhFlgruWmbmaCjZ+28BVLkCwzQ8g7boQCc52Blk9 6s/gvV16pjqn4geZTk5qrlfbEivTK3NWTEwY4QpNnxBBjwigsnuXNluiADdMMmsWredP 8GlKoVm7O2q8mHsW1N7Ci+3VCwYyRi0dk6fVgiGYUFctViLChPoKyngS4D9aMvmEp/Lx dTlFCOW7XGdde3ysJ3wOnVGxvfAt/IhbhEPT3YWcKezyY/ag6jnC3w1TmRfwNKo2UkqF slKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature; bh=o0j3uvj8K8qMDytKl8zVEjglg8T8MozK9PVtZPejaRk=; b=vOHoAEdST/z3z3mAcm9mWPmWqN6hC83YtMRgVREQ9XLYX63BDTDzIoG53SQ+gtfZf2 DSDKDbGaUaVflFSPvMYsR/J/5MCTCAgHxkE3xq5rSnTnSjjQvVGww6xnSkctBG54AiKp +St3Kp8BNCATRNpriX7iYF6FgviiPRAsAkpkETOAKAMFvi/fgM2S/kf6D+9iWd5haqYT 5wBMD4mCdehTnR3cMYROP0q/GcxCyPmsRZxGHJD2cDLMf/wwvcuP7RvzBP3OpCMZ5ntW sIMksj6wwC4o2TGpkHsUaFL079MI+5D2LzuHN8W772LCu7UQO42nUZcwXqJbAusW9a8d iLDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=R4wcpoAY; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b10-v6si28466577pfb.89.2018.10.20.07.11.19; Sat, 20 Oct 2018 07:11:52 -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; dkim=pass header.i=@linaro.org header.s=google header.b=R4wcpoAY; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727404AbeJTWVX (ORCPT + 99 others); Sat, 20 Oct 2018 18:21:23 -0400 Received: from mail-io1-f65.google.com ([209.85.166.65]:32847 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727321AbeJTWVX (ORCPT ); Sat, 20 Oct 2018 18:21:23 -0400 Received: by mail-io1-f65.google.com with SMTP id l25-v6so24619198ioj.0 for ; Sat, 20 Oct 2018 07:10:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=o0j3uvj8K8qMDytKl8zVEjglg8T8MozK9PVtZPejaRk=; b=R4wcpoAYKA07Ny4Gzm7hVDC6VGYBpW/kh4uKwVh1/zwIoD1F4LknfjKCytm5p1HDnH S82FikszuVX/+vKC7o+KRgFJJKlRdanNar0SqIaYVEwGqXodIgDyRnOb5M2BH6Qg8OfX LMUxzLIk9KuwyAPPfW97Bwm2WTesXsdR8P+bQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=o0j3uvj8K8qMDytKl8zVEjglg8T8MozK9PVtZPejaRk=; b=L7DvHHQs2aGh5b2mYsW5sl5TUUl1BWX/AjDkKotUxBFbCewmdu5DqJHA5YWCQuvwuG JcnC9uSaUZIitJMhdAi4/y5KcES5GXG5G/pUW+qUT5hMf95Av1w3N3MEDib8Y/+S9Wah 8aciJcuM9cj58hJljDYDrQw5/+l4xpsSfz9+GOmgPUEjP7QOgshtcMCmxsea6iSRc0vQ l8jitPCGU2LmHT4dL842v/ojC1zR/aBfulwz5P84M82vfCv/VweXwLWEFt9y7+6dolgg NgYVGVcU5LTQ/EujLc/XNFwqb9re7lGTk6L/uqauMpQ0w3ClUwu3Sw0YWbhtA3fIwCeO mMNg== X-Gm-Message-State: AGRZ1gIVRhvvMjLf+koDEDCkF/I5PhGEuAYradCuFp0ftKi9cJ3OBL16 qc0WUqr1UmEvY3K+QR/janE2TJfXKa+3aDfIOZ1JNw== X-Received: by 2002:a6b:3787:: with SMTP id e129-v6mr5376703ioa.60.1540044645941; Sat, 20 Oct 2018 07:10:45 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a6b:5910:0:0:0:0:0 with HTTP; Sat, 20 Oct 2018 07:10:45 -0700 (PDT) In-Reply-To: References: <20181001140910.086E768BC7@newverein.lst.de> <20181001141652.5478C68BE1@newverein.lst.de> <20181018125820.iw54zbirq74ulknj@linux-8ccs> From: Ard Biesheuvel Date: Sat, 20 Oct 2018 22:10:45 +0800 Message-ID: Subject: Re: [PATCH v3 3/4] arm64: implement live patching To: Miroslav Benes Cc: Jessica Yu , Torsten Duwe , Will Deacon , Catalin Marinas , Julien Thierry , Steven Rostedt , Josh Poimboeuf , Ingo Molnar , Arnd Bergmann , AKASHI Takahiro , linux-arm-kernel , Linux Kernel Mailing List , live-patching@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 19 October 2018 at 23:21, Miroslav Benes wrote: > >> >> Ad relocations. I checked that everything in struct mod_arch_specific >> >> stays after the module is load. Both core and init get SHF_ALLOC set >> >> (mod->arch.core.plt->sh_flags in module_frob_arch_sections(). It is >> >> important because apply_relocate_add() may use those sections >> >> through module_emit_plt_entry() call. >> > >> > >> > Yes, it looks like the needed .plt sections will remain in module >> > memory. However, I think I found a slight issue... :/ >> > >> > In module_frob_arch_sections(), mod->arch.core.plt is set to an offset >> > within info->sechdrs: >> > >> > if (!strcmp(secstrings + sechdrs[i].sh_name, ".plt")) >> > mod->arch.core.plt = sechdrs + i; >> > >> > sechdrs is from info->sechdrs, which is freed at the end of >> > load_module() via free_copy(). So although the relevant plt section(s) >> > are in module memory, mod->arch.core.plt will point to invalid memory >> > after info is freed. In other words, the section (.plt) *is* in memory >> > but the section header (struct elf64_shdr) containing section metadata >> > like sh_addr, sh_size etc., is not. >> > >> >> Just for my understanding: this only matters for live patching, right? > > Yes. Live patching can do deferred relocations. When a module is loaded > and livepatched, the relevant symbols in the patching module are resolved. > We call apply_relocate_add(), which is arch-specific, and we must be sure > that everything used by apply_relocate_add() is preserved in the patching > module after it is loaded. > So I suppose this could get interesting in cases where modules are far away from the kernel (i.e., more than -/+ 128 MB). Fortunately, the modules themselves are always placed in a 128 MB window, but this window could be out of reach for branches into the kernel proper. If we find ourselves in the situation where we need to patch calls into the kernel proper to point into this module, this may get interesting, since the PLT entries *must* be allocated along with the module that contains the branch instruction, or the PLT entry itself may be out of range, defeating the purpose. >> The original PLT support was implemented to support loading modules >> outside of the -/+ 128 MB range of an arm64 relative branch/jump >> instruction, and was later enhanced [for the same reason] to support >> emitting a trampoline for the ftrace entrypoint. > > Regards, > Miroslav