Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp692370ybh; Wed, 15 Jul 2020 12:39:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQOSZiuJXaHcQrfktxP+tN/PSZudEoLx18TGmZzd6wJ8dkwu9MrN9gMDi6eQpu3U2C2ihp X-Received: by 2002:a50:b5e3:: with SMTP id a90mr1110756ede.381.1594841945236; Wed, 15 Jul 2020 12:39:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594841945; cv=none; d=google.com; s=arc-20160816; b=hnLzKpswsuE2VK+7HR8izi93NDqdgfJPg5qhWm+A0OF7zEb5l93uJKMYo/XBWkLl6E ZD8qE5Pv6w+FqbWIKuXNNwg1wiQ6QhATQVy5QovPRfKJg0ObJS78aYa3Qh9DU2tdVR6L umm3B9EvTPgRimjxyS8VbGvFunQGedQFjW/rguht7rxKS6r6VQKl9XCZPBA5bVkB+1Cr 9km3Xz6gQqv2bGog27sFuIj5lREITV7ViI61iqBfLOsSthhUVNwV0JEZvJ1gj7jbwBMw uaUgnnPnkH55/PbcAwQ2dIkMsTMdDz3mF6oqe5eqrjtKAy5RFmzwu5ok5UDLmnu0S9ND R5hg== 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=GvkmBERge76OD9EroFR1ab0FIW+Z4wHO+7dviVws/gQ=; b=00AX2CQDczd7ilnvnQpvWksiHEFfHrftvIk/JO3Wmxkegy45v4+bjfhPoc9dPkk/yd spQMqmYC1ugLoFRtk7ZtWWPdfh5yBCezxi676cLwZqTUNS16GS2syVL4zEpCGY4xgKVr YXwioddMPzD6xgZ0cF4otGKOr31aC8Ld8H4PiWAHl2XbGtc5ye9ZMWtz1hQgdswey1XV 6KujhfnNngW68Wl8bYMk/s5FlrPBUddu04FVVG8+GOSL92E6iSpHRvt68GWWaxfeBRPV Iq2e8RAVa/2nx823I/nPbTDYGF7Hyy+hQLl2LcNSc521U6+8M0rdIHAttlMYInexDIFD v+0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iUyquCbs; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p3si1961312edx.495.2020.07.15.12.38.42; Wed, 15 Jul 2020 12:39:05 -0700 (PDT) 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=@chromium.org header.s=google header.b=iUyquCbs; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726661AbgGOTgF (ORCPT + 99 others); Wed, 15 Jul 2020 15:36:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726634AbgGOTgF (ORCPT ); Wed, 15 Jul 2020 15:36:05 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEBA8C08C5CE for ; Wed, 15 Jul 2020 12:36:04 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id f16so3459235pjt.0 for ; Wed, 15 Jul 2020 12:36:04 -0700 (PDT) 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=GvkmBERge76OD9EroFR1ab0FIW+Z4wHO+7dviVws/gQ=; b=iUyquCbsUx2U5Bmvi53VPRZwo0kqbDq+f/tALn5Dx3qumSe0apG8eUSZnfhBqmq7gR WgOR/I9kPn/cCyvtSlqnHr5I0+qr4C8QpxOP/MNMmRKOQKnB6tCeS82Mt7+jJEI+bitT JJA5d+5WCEh7eWfpSQXvRJ759zt6PEjjnE7Vc= 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=GvkmBERge76OD9EroFR1ab0FIW+Z4wHO+7dviVws/gQ=; b=nSXMmAIxZ/CElRcNQL5nAWzKpJFsOO3fxw05bRExhUbs0wd+VtgQ/Aue/xA5Hfzhmo oqmAKFqVkYbsB18iKTz3bKpVLbCouUR8GhpWEnOE7dCBh97YEaeWT/GzXN5bOZ6l7qxu Mur3i3N2ctzv1O3Jc1++UZZHur15IsiRf2RHUNL7glaNBYbzYzbwVzPI/7yYrZA2VF8I 4mA9GSG0n8CiVzuHojXAvS8J4LnOT7dIDR7323SkyfDqOpRtlPg0UqJOCzyyAq84WV4Q jjfbA6tPHTvpDaaEClv4U1pnWmsoMpZWa4TmiKs4QdAPymjlatcZPfmTxwUYcpCWoCJV 778w== X-Gm-Message-State: AOAM532rKlZH+qc0IuP7QttdZZNw5ysYx56vIV4jqIextDgdWdPZexfR o9ehE7r3fEttiELgThcg1mVLpQ== X-Received: by 2002:a17:902:988b:: with SMTP id s11mr742714plp.229.1594841764231; Wed, 15 Jul 2020 12:36:04 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id n62sm3025449pjb.28.2020.07.15.12.36.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jul 2020 12:36:03 -0700 (PDT) Date: Wed, 15 Jul 2020 12:36:02 -0700 From: Kees Cook To: Jarkko Sakkinen Cc: linux-kernel@vger.kernel.org, x86@vger.kernel.org, Andi Kleen , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "H. Peter Anvin" , "Naveen N. Rao" , Anil S Keshavamurthy , "David S. Miller" , Masami Hiramatsu , Jessica Yu , Andrew Morton , "Aneesh Kumar K.V" , Will Deacon , Sami Tolvanen , Alexandre Ghiti , Masahiro Yamada , Peter Collingbourne , Frederic Weisbecker , Krzysztof Kozlowski , Arnd Bergmann , Stephen Boyd , Andy Lutomirski , Josh Poimboeuf , Miroslav Benes , Babu Moger , Omar Sandoval , Nayna Jain , Marco Elver , Brian Gerst , Jiri Kosina , Joe Lawrence , Mike Rapoport Subject: Re: [PATCH v3 1/3] kprobes: Add text_alloc() and text_free() Message-ID: <202007151232.0DA220B2@keescook> References: <20200714223239.1543716-1-jarkko.sakkinen@linux.intel.com> <20200714223239.1543716-2-jarkko.sakkinen@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200714223239.1543716-2-jarkko.sakkinen@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 15, 2020 at 01:32:27AM +0300, Jarkko Sakkinen wrote: > Introduce new API for allocating space for code generaed at run-time > leveraging from module_alloc() and module_memfree() code. Use this to > perform memory allocations in the kprobes code in order to loose the > bound between kprobes and modules subsystem. > > Initially, use this API only with arch/x86 and define a new config > flag CONFIG_ARCH_HAS_TEXT_ALLOC to promote the availability of the > new API. > [...] > diff --git a/include/linux/text.h b/include/linux/text.h > new file mode 100644 > index 000000000000..a27d4a42ecda > --- /dev/null > +++ b/include/linux/text.h > @@ -0,0 +1,17 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > + > +#ifndef _LINUX_TEXT_H > +#define _LINUX_TEXT_H > + > +/* > + * An allocator used for allocating modules, core sections and init sections. > + * Returns NULL on failure. > + */ > +void *text_alloc(unsigned long size); > + > +/* > + * Free memory returned from text_alloc(). > + */ > +void text_free(void *region); > + > +#endif /* _LINUX_TEXT_H */ > diff --git a/kernel/kprobes.c b/kernel/kprobes.c > index 2e97febeef77..fa7687eb0c0e 100644 > --- a/kernel/kprobes.c > +++ b/kernel/kprobes.c > @@ -35,6 +35,7 @@ > #include > #include > #include > +#include > > #include > #include > @@ -111,12 +112,20 @@ enum kprobe_slot_state { > > void __weak *alloc_insn_page(void) > { > +#ifdef CONFIG_ARCH_HAS_TEXT_ALLOC > + return text_alloc(PAGE_SIZE); > +#else > return module_alloc(PAGE_SIZE); > +#endif This seems like it shouldn't be needed. I think text_alloc() should always be visible. In the ARCH_HAS... case it will call the arch implementation, and without it should just call module_alloc(): For example: void *text_alloc(unsigned long size) { #ifdef CONFIG_ARCH_HAS_TEXT_ALLOC return arch_text_alloc(size); #else return module_alloc(size); #endif } -- Kees Cook