Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1426785ybv; Thu, 6 Feb 2020 03:59:01 -0800 (PST) X-Google-Smtp-Source: APXvYqxhXR7VKGN5QuxHV9IcYnLh4Ai7YD//dMID/EJ7uR8B5x+4wy3W9WcfrdL5EJzcPY2V81p3 X-Received: by 2002:a9d:7696:: with SMTP id j22mr31385230otl.188.1580990341825; Thu, 06 Feb 2020 03:59:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580990341; cv=none; d=google.com; s=arc-20160816; b=tU8Xwqeo4e8KSQXzUuWh4OVZwahloxzSIlLsiciaRUGIJ2TuEqq8HbhCwnOD/gBz1U +MjlL9lORH0HtLagWVIgjE47+14+JKZlcAnaJwejX9rGGh1noeqtv1CmjN3n6t/B6yn/ Py7KeDGYIixNI1CcErBTUVUvNlrGPY8gsat/aBTyx2uEHFV8n7UE6xKydA7FXJ/B1x5T aKU8pmZXJRvjMj6te976DYUPVNCU1siZTZm7rkKwwM41pmxHEAYsRXapQPOTlZFdDQMY 5vf69AnJ/MfF67peIml/OlhAUWgG3qJIIHkwDYQ9DMaIF51cZNW3tzsbPjJsBP5a0D/e OB+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=uMsAapITXkLzJOLckwG4XojxmW0d1pjkgV4d2lZV/fE=; b=BDua9HZpK6pDSMxiiph+CExPewHLg799NGDx9EQWtWIMF6TZxVb6QBlFgRSUWefKWl rc6TY1Nj1m9cW7vKMzz2kTf3qvY0/O88tRZT6ZolnZT6Z3qG5IZijsQrwgPVBc0grcVo CzMwnSHhlSgod9OuS2iV8N3rUFY9fbqkSoI94239ExFgIFfy3W9zEs/sKSSLGOvh3ihu XPAxVRZdvaCtMkgb4zCe3Y5S5ffwlV8aPC+iWodF0DAMGNarc/TyplQY0S3A9+aPvuG6 wxSr1us0iYAh42+OObhH6INg03ecN/M6LAfUjRGbs9Jqa/5TK8xLprL91ZiyYoTYJHe6 V5sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=je7nbPRU; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c4si2304006ots.107.2020.02.06.03.58.49; Thu, 06 Feb 2020 03:59:01 -0800 (PST) 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=@chromium.org header.s=google header.b=je7nbPRU; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727630AbgBFL4l (ORCPT + 99 others); Thu, 6 Feb 2020 06:56:41 -0500 Received: from mail-ot1-f66.google.com ([209.85.210.66]:46763 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727111AbgBFL4l (ORCPT ); Thu, 6 Feb 2020 06:56:41 -0500 Received: by mail-ot1-f66.google.com with SMTP id g64so5175680otb.13 for ; Thu, 06 Feb 2020 03:56:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=uMsAapITXkLzJOLckwG4XojxmW0d1pjkgV4d2lZV/fE=; b=je7nbPRUzIurBISR1NYTtbJqnOaJQ4blgePkVkAxhJOR6ulsvPl17K4jqdMdXsqHZD J+zSsq5WaLrrOawSLfzQmIhC4S8hICmpxOxLejMF+c4DojYJja4JBhGMcRsBBuqqP/g+ Onr9hXuFP7e5B+xORxzxCo3KFoIlBRUegbaUI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=uMsAapITXkLzJOLckwG4XojxmW0d1pjkgV4d2lZV/fE=; b=ZcoL8jzjVytoYGVVpOOU+yjGfwhVD3EJNhLNWn3vegx5GG/AnCYyvBk0nLbedXf4vo yY7yRWEm9nUP36K9II7FqfCwebIWmlex2qIgAaGgOq+5mHOgU429SPplMopnSTiaevSd wHvGKN3AnNSiAXzoSUgGuljLHGnCYuRy6j4aRgN2iBL9njlfpgKjNyIuRxzGs9Xa6q5B Ab88FuueyHDPn2s2vogYfLR4l+0IAmiK76snCt/OIhqKIXaXx0PVjl8jzCU4RydNIhAX AMroOcW8ew94HbKQmSeAFe65xkFNCgXc4Lu9YHfWYG3WiZT1PJmUU9IjAo/FJyB1syH0 2I7w== X-Gm-Message-State: APjAAAXydFHJ7Syykfktnwc2tgM/CfKhx5nnIdsKUMGVLxUMPIZ5x0NM pKyylL2gKdsrcK6jutQj9P8HsA== X-Received: by 2002:a9d:6f07:: with SMTP id n7mr29037601otq.112.1580990198850; Thu, 06 Feb 2020 03:56:38 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id a5sm1031776otl.45.2020.02.06.03.56.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Feb 2020 03:56:38 -0800 (PST) Date: Thu, 6 Feb 2020 03:56:36 -0800 From: Kees Cook To: Andy Lutomirski Cc: Kristen Carlson Accardi , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Arjan van de Ven , Rick Edgecombe , X86 ML , LKML , Kernel Hardening Subject: Re: [RFC PATCH 08/11] x86: Add support for finer grained KASLR Message-ID: <202002060353.A6A064A@keescook> References: <20200205223950.1212394-1-kristen@linux.intel.com> <20200205223950.1212394-9-kristen@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 05, 2020 at 05:17:11PM -0800, Andy Lutomirski wrote: > On Wed, Feb 5, 2020 at 2:39 PM Kristen Carlson Accardi > wrote: > > > > At boot time, find all the function sections that have separate .text > > sections, shuffle them, and then copy them to new locations. Adjust > > any relocations accordingly. > > > > > + sort(base, num_syms, sizeof(int), kallsyms_cmp, kallsyms_swp); > > Hah, here's a huge bottleneck. Unless you are severely > memory-constrained, never do a sort with an expensive swap function > like this. Instead allocate an array of indices that starts out as > [0, 1, 2, ...]. Sort *that* where the swap function just swaps the > indices. Then use the sorted list of indices to permute the actual > data. The result is exactly one expensive swap per item instead of > one expensive swap per swap. I think there are few places where memory-vs-speed need to be examined. I remain surprised about how much memory the entire series already uses (58MB in my local tests), but I suspect this is likely dominated by the two factors: a full copy of the decompressed kernel, and that the "allocator" in the image doesn't really implement free(): https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/decompress/mm.h#n55 -- Kees Cook