Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp924112ybv; Wed, 5 Feb 2020 17:18:35 -0800 (PST) X-Google-Smtp-Source: APXvYqy9tFNCjitjsJDZ5aF1dOc0I8ACRDUioRip7WlqS4pGMHa+QDqb+vtwJlWvobN8WGtNW4KJ X-Received: by 2002:a54:4003:: with SMTP id x3mr5039759oie.0.1580951915749; Wed, 05 Feb 2020 17:18:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580951915; cv=none; d=google.com; s=arc-20160816; b=rtRCp3pAp5Rd8GDuNzvPsRrkianF7nibLixKrpmw6FI/AahiWLNywFahyxPjzr8Phd XK6s2Sl5/0W+MEIfVj2T34Y3BKeh2MOlt4tqaXBFfN+Qxjhdb8cfn3bo+jm3jKanKafx u0NKt2XVsn+YBjo8gvMNUyAtruyU1E4fg8qttE4N7mubxpr6v8i0ksHeJmtl//kodbqc HjZAwV0RnyB8PhTVcwh8UCsbHJj2pvR0uffuxtDYdNnbCBqf+IMet3XdWEI6X94lvju1 FJ55W3Z/rPVSltUCBNpMTXVXz+eHXRStCI5d3UthLmUHjVmmj4Hm7fQfDPqOs2zKXK1j Vf1g== 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 :in-reply-to:references:mime-version:dkim-signature; bh=xzjugmexH7IEduqtdD7vOdbgBBFUNiLMFXSwF1u7tKY=; b=NU3W/BmMnplXjjwliCpjTjXRG6FrzrZVHv2nI2TMWBq3DlsIUdZ+pDeQ40XNE4V9p6 C+rl4uQFdLU8U2chNfedHVWPsBjk8hUVXch0pTZD4YxcO3U2kf3Y8wwqI9Jp/wPKBnFH 0+SFU+gkL0oHBkQFUlCXMzjmLR5qIhrtjs6u0P1kmQiVr7xwSj9rFYKrzgio2FVArlq7 Sb0oin1jAltQiDm1u5fH8Z3xR72MmLFYy4/j2LRm4C5ueKR8DayPZfKccNYZDeU48JJS /5VxWVHc5YLJru/bo2pXNMr9tOBLLdvEwAHAvKpCS9yLOcAaF5ufYVsKdPdCT4TSukPF ktHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nAKF0vHs; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y8si871271otg.309.2020.02.05.17.18.21; Wed, 05 Feb 2020 17:18:35 -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=@kernel.org header.s=default header.b=nAKF0vHs; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727587AbgBFBR0 (ORCPT + 99 others); Wed, 5 Feb 2020 20:17:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:60300 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727170AbgBFBR0 (ORCPT ); Wed, 5 Feb 2020 20:17:26 -0500 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B1F092192A for ; Thu, 6 Feb 2020 01:17:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580951846; bh=c/QAJGFBDVSsnDraji7Se4DitpBF5jtF8Hj48+GNKlA=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=nAKF0vHsgBcp9G2cbZP3E+LGn1TMWXmR7VCiFam5tr8l8X2UfHu6e0qDj9/YBZsCw 5iimwa9Sa4mt0kWK4TdZHgqvZpiND9iYPZxngK07Pehuvc4emoErgvDe85Eldne7Ad 6B1uEU1xgOQGTY6fYI0FavT1oPPws0iz6YcBxw9Y= Received: by mail-wm1-f53.google.com with SMTP id c84so5044356wme.4 for ; Wed, 05 Feb 2020 17:17:25 -0800 (PST) X-Gm-Message-State: APjAAAXw2o8w8g1QE8zzf86Oe1vRQXqNxEIsz1vB2/JRjL5pnyUePjuJ hAFaJT1qAkp6Ba9X5Kytb0jckeHhB1Hoto4zO8gK3A== X-Received: by 2002:a1c:3906:: with SMTP id g6mr635337wma.49.1580951844067; Wed, 05 Feb 2020 17:17:24 -0800 (PST) MIME-Version: 1.0 References: <20200205223950.1212394-1-kristen@linux.intel.com> <20200205223950.1212394-9-kristen@linux.intel.com> In-Reply-To: <20200205223950.1212394-9-kristen@linux.intel.com> From: Andy Lutomirski Date: Wed, 5 Feb 2020 17:17:11 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH 08/11] x86: Add support for finer grained KASLR To: Kristen Carlson Accardi Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Arjan van de Ven , Kees Cook , Rick Edgecombe , X86 ML , LKML , Kernel Hardening 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 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. --Andy