Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp703871ybh; Wed, 15 Jul 2020 12:53:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJUzHtuBKpK3tiPfm44uB3dZj0xQO3vtB0KqeQWI9xgrAh3GTDOU5Wy3eBqVM11/uxr+Dd X-Received: by 2002:a17:907:6fc:: with SMTP id yh28mr525300ejb.267.1594842838033; Wed, 15 Jul 2020 12:53:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594842838; cv=none; d=google.com; s=arc-20160816; b=wopxfvOKu05j3m+YFUfsJmMTp17LYTThBs54n+r7jQzrdGV/IwOX/ue4mOQ9TjSXcA AcxovvBVXwaLv0N2+12nT90cWn0q4tEbCaDD30GE6ufzrqMZF5hHJ2uc4jYf34od6u5t Anl4z6K8rDP4c7Fwkg/rsiyglAC8AiQqk4Z3Ijqdi9pKl/1lGP7rO4YqlAP0SPC3J2QC s6Y/87Vrk2ugeEdgZeMq5Rr8A0Edn+3y/vmU0UC7aO7cmvL3l/QUibAU9GFwSwJXel2V vOcRiG4N2xwa6tDwEVqK6Pgy0rFvrJKm9cqt2L4KVnzKncsNAPUIG4Wcb5w5y/Yq3COF cOnQ== 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; bh=QpxjGVyBigl6zfXcS1/3tzq1O9nSe3Khh4YQEkpb59c=; b=kELr46xlPN+k1T8UWKST2nU7OJV6fz/Uv78QPYD/pJV9gpLMlsc9Z3lfFFpe0uAL2Z dKqp8hnXerhqoI1VDblJ+LK2VWa/3oowTkNbCyEvTMbtdorXpyc1M8iNF7BeHRpNsB5W 3LHrPyG1g8bG6Wr2LbDjQZpGboLMtgE2oazC97QTPIqW5Q5TT7KmC2QRYgXQrvdzhd1Q 4lL2AW295Zt6fkd8AhahbVJwJfnfzvaPXtHDpGPyRm9z/MlztFC9y1N5jh6zZTlCbjcX TtK6W2OlqBCTgF7rjOL46d9TtmjmgIDACLWWtz0ksfmO1hByoEremA5qc52owWJJQWLN 5pzw== 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=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y19si2004619eje.247.2020.07.15.12.53.34; Wed, 15 Jul 2020 12:53:58 -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=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727924AbgGOTuT (ORCPT + 99 others); Wed, 15 Jul 2020 15:50:19 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:65184 "EHLO mx0b-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726852AbgGOTuS (ORCPT ); Wed, 15 Jul 2020 15:50:18 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 06FJWwfH080464; Wed, 15 Jul 2020 15:49:44 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 32a7hmsem7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 15 Jul 2020 15:49:44 -0400 Received: from m0098417.ppops.net (m0098417.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 06FJX4wk081184; Wed, 15 Jul 2020 15:49:43 -0400 Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 32a7hmsek9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 15 Jul 2020 15:49:43 -0400 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 06FJjdho014553; Wed, 15 Jul 2020 19:49:41 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma03ams.nl.ibm.com with ESMTP id 327527vtr1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 15 Jul 2020 19:49:40 +0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 06FJncK964749592 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 15 Jul 2020 19:49:38 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1E57652051; Wed, 15 Jul 2020 19:49:38 +0000 (GMT) Received: from linux.ibm.com (unknown [9.148.203.215]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTPS id D84D25204E; Wed, 15 Jul 2020 19:49:34 +0000 (GMT) Date: Wed, 15 Jul 2020 22:49:33 +0300 From: Mike Rapoport To: Kees Cook Cc: Jarkko Sakkinen , 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 Subject: Re: [PATCH v3 1/3] kprobes: Add text_alloc() and text_free() Message-ID: <20200715194933.GC1166045@linux.ibm.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> X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-07-15_12:2020-07-15,2020-07-15 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 clxscore=1011 impostorscore=0 malwarescore=0 adultscore=0 phishscore=0 priorityscore=1501 mlxlogscore=999 bulkscore=0 suspectscore=5 lowpriorityscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007150149 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 > } This inverts the dependcy chain, IMHO, module_alloc() is a special case of text_alloc() and not vice versa. The addition of #ifdefs to alloc_insn_page() is not needed because it is anyway overriden on x86, so I don't see a point in added #ifdefs until another arch will enable ARCH_HAS_TEXT_ALLOC. > -- > Kees Cook -- Sincerely yours, Mike.