Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp964216ybh; Wed, 22 Jul 2020 18:43:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJSr1DVnmymQh/HasrDPUucaztgrbY6jkLLoAP/Ff6iADt6e8AB/Pb9eIc3iZ530Vxf/Q+ X-Received: by 2002:a17:906:1250:: with SMTP id u16mr2062554eja.299.1595468618326; Wed, 22 Jul 2020 18:43:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595468618; cv=none; d=google.com; s=arc-20160816; b=IoQ3ICi5S0cNu1SQKTVKhFl3p3Iwde4vgXPqaeG4t466qbWx2YjMZPvT4Y/LPGhpVU ITFY+JWwpcvvNGYARUd4fOiXbfgbbI103Oelzq3Yxsx9APaJOx9c6gb6g39pWHP+J02U 5KN3b1lDOziQRdtbRDgq560wO7f4G52NuEHZs6FCTB0VWgaPOFFnX8P20THEvY6cNUpv mWXsRySqJ6FQWuhCmhvy7asUkfhpOx+JDYi9NZvn1ac/yiI6Fr4hiib6PT/W8QQOHpZL 9VTzf0BzSWUAphecYorFx7ajzOrv36Ci8w6Rr3ynH2NUihePP7APD07cXN0fludzGC+d dhxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=l1tbIciBxf8zQ/DxiE9ei5eKAnjMi0L/0zKEQnH9gmQ=; b=Ugw9kVyYhVQSuy8KCf/R04yjoICpz0/bbvJjIWyguGzT0NM/NMP875GfUJm8dQoprf oNfjpXV+JdLgyOID/tDFPA3T9KnsPXo8fpeklQOqtB6nFDdeHeWe20NV21xrn+Bre3nd 2x24+T0VmhMaLpBN9vIsaLQbT2MC4urBtN0mXBpkzuVvrvSmUMggBUGI0+F4IHISXXBL 2UdhkLdHfqRolI7AxReL0994QDGpoC58UQqaFLgP9bPdrN1HNuGI/ZiZzAbi0LyYeOa/ HuBIb5yhlrstcXaQquRPxZSoNpqqsG/Wu5L+h/YS8XWv2rYZIzsHpOHihxMDK3VNhe5G mgVA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h27si1183828ejd.616.2020.07.22.18.43.16; Wed, 22 Jul 2020 18:43:38 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387726AbgGWBjv (ORCPT + 99 others); Wed, 22 Jul 2020 21:39:51 -0400 Received: from mga01.intel.com ([192.55.52.88]:59630 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387460AbgGWBjv (ORCPT ); Wed, 22 Jul 2020 21:39:51 -0400 IronPort-SDR: YagH8AHVp1QrPpeL06Q04iBwjU35RaZVf4Dy1JiHLf5N1sCNe9rih5CSiQxW55VUmYNSIlLlLi XP81clHh5hmQ== X-IronPort-AV: E=McAfee;i="6000,8403,9690"; a="168586203" X-IronPort-AV: E=Sophos;i="5.75,383,1589266800"; d="scan'208";a="168586203" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jul 2020 18:39:51 -0700 IronPort-SDR: U3BLgg8jTpLnq+r5fBR6CHDgFDv0LSr+n+3WtfjemhiHOy/cTLPx/6r6zZiVJ44FvorSjt5bza 9z5Lp5iJ6zjA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,383,1589266800"; d="scan'208";a="310844028" Received: from schwings-mobl.ger.corp.intel.com (HELO localhost) ([10.252.33.132]) by fmsmga004.fm.intel.com with ESMTP; 22 Jul 2020 18:39:36 -0700 Date: Thu, 23 Jul 2020 04:39:34 +0300 From: Jarkko Sakkinen To: Kees Cook 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: <20200723013934.GC45081@linux.intel.com> References: <20200714223239.1543716-1-jarkko.sakkinen@linux.intel.com> <20200714223239.1543716-2-jarkko.sakkinen@linux.intel.com> <202007151232.0DA220B2@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202007151232.0DA220B2@keescook> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo 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 12:36:02PM -0700, Kees Cook wrote: > 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 I fully agree with your comments and I posted a follow-up series where I think these should be resolved. Please check it because before I got this review, It was already posted. Thank you. /Jarkko