Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp210859pxb; Thu, 21 Jan 2021 05:29:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJxKFGKiVqFGJsJVEu82yjeRqqVaaOF26tPBCQy0QtrhG2DAZn1pIcMSlVHe632ksUQ986eY X-Received: by 2002:a17:906:3899:: with SMTP id q25mr9058412ejd.173.1611235791918; Thu, 21 Jan 2021 05:29:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611235791; cv=none; d=google.com; s=arc-20160816; b=YoDxqLBFh4axTnJhkXwoF6WYVmysXkn72A5r9k1ifrBbYwoiajdloxps6XlU+hZHi6 ynudj0rVJ80R01aT/VQeWQrxiVjbCl09fW66KdA8zu4DrMPFEu0cRzHFvpEml8CwLI17 lFt/sd78ns8v0h7BWlGNCcN4Jf6U4lFL5HSXXO15TQboMx1NFDkL7PJ6qMulV6jXD0wK 78ZxDyhE8SpqG3Uwd2WEg044/0J80S8MpmR3pnmlqHf54eknM2CmhVjwJvmbZCXyre/M Xc+Ll9+HQBG9xLxZ3XsOIPnrIWcOXH6bI/iLKM6kfqn7QA9SCCgU4TiyrU9HFAw4zXiK ciYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=cvCR/SJT7x/0z+1fK/OgzO3ZsWGWZSRqQrMopnsNWp8=; b=fD8I9MN/o0V0s17CtJZ47tzafW4wf+F1Sb1NhL+PwaWMrGak/8R1cnPAKPQ4nWCM/F 96HhFYN20Zkxv9kUd3OlB059IQqmQcHulGu9HKUXmJhFU0BG3YWev6aNKfQ3XB6Y81eT ixyq0qCQ9RqlORcZrk9Z5POzLbpctZO/jJ+b1+xMK5O82hQdY3aesWF6lSRsYwJhn/O6 ybGHDI7+Fj+TTH0rMRJvUpZe8WfiENTAe1v/DMgioJMMP6biTeEPTOIulAvJX95BSo+G YcxFaT6zJc4MKH+AYNa+G7P2U1cr6CBBtmssMWyoLuvXlFfPpHRWfEgEOsxEYYa1A1zs Lrvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=T+7BZodw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id op4si1736689ejb.545.2021.01.21.05.29.26; Thu, 21 Jan 2021 05:29:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=T+7BZodw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729582AbhAUN1k (ORCPT + 99 others); Thu, 21 Jan 2021 08:27:40 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:37809 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732205AbhAUNZ1 (ORCPT ); Thu, 21 Jan 2021 08:25:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611235438; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cvCR/SJT7x/0z+1fK/OgzO3ZsWGWZSRqQrMopnsNWp8=; b=T+7BZodwH+s5uNb6IgziWkF2rTEj8/CI9DjoNaI8nvlQ9Nqzi24xA3yXBm7B/1iPEq3KMz pojsXC6+BragRoFK4CJ75+2VQ9Ji6fo5iw8VFLrgi26OezYha8pS2imRgMqtQpOVokI8L8 4kkz/8bbL1/gt8kJRUJaxIiYlf34Xnk= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-72-eft2UYMGPSytmiLanXDPQw-1; Thu, 21 Jan 2021 08:23:56 -0500 X-MC-Unique: eft2UYMGPSytmiLanXDPQw-1 Received: by mail-wr1-f72.google.com with SMTP id v7so1010711wra.3 for ; Thu, 21 Jan 2021 05:23:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=cvCR/SJT7x/0z+1fK/OgzO3ZsWGWZSRqQrMopnsNWp8=; b=JtET2dCwHujbGz772lnLH6ap1Go61IOZFqrC3iTmUFoVjzPDz7AmFQCG6KV6bE5lbL xuE/bEkrqMynMFYEnvJUNlIalQJCIqcYy01oaljlMyM6ZSyYnwKPXXg1r3yDzNW2N+LK Vl6jGIQzgg9SDd750ItpGi4tCS+SqumhJ/y0Vn/jKQc2YyYT6KN7QBCQ0ebONJ4mOKlG UtqTbqKH5EhhBWM4aib5MD8c/9Ntpum5Jw827816b4MJZ10WbQUkf36NuZR+MMUTVFyS oKHtRaoTV4YhBkcmEhEiNKx8bOEMEE9vHImqxrxlwI5Xs2V0ptfHNXhFQ24Ny/OWlBgv UH9w== X-Gm-Message-State: AOAM533vXZ/RsswUKaMGYKPXiYlJlQFY1YC7bbRQ2Ujp2iLnvq8wuJEG EIGvJbo7R+B2p2C4SRVALtghR0zrroPGhgirbal8Qq5DvNzmXoS+EsFhlLwGpqxq2GdiIdYLeDH 4yOE/Ux6a5Qcir4F1eaCvFtd8 X-Received: by 2002:adf:c18d:: with SMTP id x13mr14020216wre.128.1611235435255; Thu, 21 Jan 2021 05:23:55 -0800 (PST) X-Received: by 2002:adf:c18d:: with SMTP id x13mr14020198wre.128.1611235435102; Thu, 21 Jan 2021 05:23:55 -0800 (PST) Received: from ?IPv6:2a01:cb14:499:3d00:cd47:f651:9d80:157a? ([2a01:cb14:499:3d00:cd47:f651:9d80:157a]) by smtp.gmail.com with ESMTPSA id d30sm9999764wrc.92.2021.01.21.05.23.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 Jan 2021 05:23:54 -0800 (PST) Subject: Re: [RFC PATCH 00/17] objtool: add base support for arm64 To: Ard Biesheuvel Cc: Linux Kernel Mailing List , Linux ARM , Catalin Marinas , Will Deacon , Masahiro Yamada , Kees Cook , Michal Marek , Josh Poimboeuf , Peter Zijlstra , Mark Rutland , Mark Brown , linux-efi , linux-hardening@vger.kernel.org References: <20210120173800.1660730-1-jthierry@redhat.com> <186bb660-6e70-6bbf-4e96-1894799c79ce@redhat.com> From: Julien Thierry Message-ID: <6e21cd51-017e-2135-ed9d-33a60f22a457@redhat.com> Date: Thu, 21 Jan 2021 14:23:53 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/21/21 12:08 PM, Ard Biesheuvel wrote: > On Thu, 21 Jan 2021 at 11:26, Julien Thierry wrote: >> >> Hi Ard, >> >> On 1/21/21 10:03 AM, Ard Biesheuvel wrote: >>> Hello Julien, >>> >>> On Wed, 20 Jan 2021 at 18:38, Julien Thierry wrote: >>>> >>>> Hi, >>>> >>>> This series enables objtool to start doing stack validation on arm64 >>>> kernel builds. >>> >>> Could we elaborate on this point, please? 'Stack validation' means >>> getting an accurate picture of all kernel code that will be executed >>> at some point in the future, due to the fact that there are stack >>> frames pointing to them. And this ability is essential in order to do >>> live patching safely? >>> >>> If this is the goal, I wonder whether this is the right approach for >>> arm64 (or for any other architecture, for that matter) >>> >>> Parsing/decoding the object code and even worse, relying on GCC >>> plugins to annotate some of the idioms as they are being generated, in >>> order to infer intent on the part of the compiler goes *way* beyond >>> what we should be comfortable with. The whole point of this exercise >>> is to guarantee that there are no false positives when it comes to >>> deciding whether the kernel is in a live patchable state, and I don't >>> see how we can ever provide such a guarantee when it is built on such >>> a fragile foundation. >>> >>> If we want to ensure that the stack contents are always an accurate >>> reflection of the real call stack, we should work with the toolchain >>> folks to identify issues that may interfere with this, and implement >>> controls over these behaviors that we can decide to use in the build. >>> In the past, I have already proposed adding a 'kernel' code model to >>> the AArch64 compiler that guarantees certain things, such as adrp/add >>> for symbol references, and no GOT indirections for position >>> independent code. Inhibiting optimizations that may impact our ability >>> to infer the real call stack from the stack contents is something we >>> might add here as well. >>> >> >> I'm not familiar with toolcahin code models, but would this approach be >> able to validate assembly code (either inline or in assembly files?) >> > > No, it would not. But those files are part of the code base, and can > be reviewed and audited. > That means that every actor maintaining their own stable version of the kernel have to do their own audit when they do backports (assuming the audit would be done for upstream) to be able to provide a safe livepatching feature in their kernel. >>> Another thing that occurred to me is that inferring which kernel code >>> is actually live in terms of pending function returns could be >>> inferred much more easily from a shadow call stack, which is a thing >>> we already implement for Clang builds. >>> >> >> I was not familiar with the shadow call stack. If I understand correctly >> that would be a stack of return addresses of function currently on the >> call stack, is that correct? >> >> That would indeed be a simpler approach, however I guess the >> instrumentation has a cost. Is the instrumentation also available with >> GCC? And is this instrumentation efficient enough to be suitable for >> production builds? >> > > I am not aware of any plans to enable this in GCC, but the Clang > implementation is definitely intended for production use (it's a CFI > feature for ROP/JOP mitigation) > I think most people interested in livepatching are using GCC built kernels, but I could be mistaken (althought in the long run, both compilers should be supported, and yes, I realize the objtool solution currently only would support GCC). I don't know how feasible it will be to get it into GCC if people decide to go with that. Also, now that I think about it, it will probably come with similar limitations as stackframes where the unwinder would need to know when/where the shadow call stack is unavailable for some reason and the stack trace is not reliable. (it might be a bit simpler to audit than stack frame setting and maybe have less limitations, but I guess there will still be cases where we can't rely on it) -- Julien Thierry