Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp9476887rwr; Thu, 11 May 2023 15:57:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4iOjfpZtKsKww0ebVGfXohYuumSk0J6AmeHwm/j9ZTCtV41w1QqyyFhSubK9GHgJrZGYPe X-Received: by 2002:a17:902:f80a:b0:1a2:749:5f1a with SMTP id ix10-20020a170902f80a00b001a207495f1amr28413605plb.26.1683845836515; Thu, 11 May 2023 15:57:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683845836; cv=none; d=google.com; s=arc-20160816; b=jxFTwsvO9Rz9ILvlEjyDLXujQGVi0l7eS489TfgqCQbDMkeKwpxvXaVVM4DrO3Bp93 VPJCsNx93m9SW2hZB8KWlMX4fCm+4U/xQpL8BlJ+OYVV9PfGEUOQQZH4aub/S1CHRLTb FxBYN5Ij1okPSJ2dH4+BG3Yg2SvLvjKX+bCIZ1pWO02oBF7Umzq1thG18kS6x9f4cyNs b/FPGQLnZWDsFxvuepUcHY4gy+OJO6JPUPUvohkOo3vL0hZpQ594yZKxwkm0/TQMhR4a e19lmbN9QbD/iUmz0lH0qX9Yr7vucNmFI/vB8km5WYLGMoHkzc4UyoCJ8X0Ebygr0lNm S4ZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=foguPMzaG5JiKYkGBK5Zqr8oTB+NWVY0GCMBbESmVbo=; b=jANKlHDCLSmOT50cPo4r25/wiwoO+lEJUT0xk5cZdvKK/7tW06NWhk3dMsVm4fB1On d2jS5RDUBlYXRIQJdEwyaX/JyRkEKAP/FRrXIUcr7N9TwB1PWecaJbffFCXa61gOVdkh JmIeS/LBR1ydO2bwrYzRcKhC/L9q+fQ3QZHxVBM3lK29MS5DVHwoOOk7BQ4+8uIREoxH C/BMheMDd+5eGW1jK2IGwy3M9+Kc+H1+R/4JbkJx3EHgSBC+4JrMgWmEo9JlFw2E9Hvz jVbiAxOp3Go9rfzlHpzGL9cTmcDYi+UwAE6/oyGkxDN1w6Gyi6NNKFTxgWvTjMSoz4sI 0R5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=fE3rVckT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id je14-20020a170903264e00b001aae1997455si7394253plb.651.2023.05.11.15.57.01; Thu, 11 May 2023 15:57:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=fE3rVckT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S239365AbjEKW2q (ORCPT + 99 others); Thu, 11 May 2023 18:28:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238866AbjEKW2n (ORCPT ); Thu, 11 May 2023 18:28:43 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AFF72738 for ; Thu, 11 May 2023 15:28:42 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-64a9335a8e7so1561984b3a.0 for ; Thu, 11 May 2023 15:28:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1683844122; x=1686436122; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=foguPMzaG5JiKYkGBK5Zqr8oTB+NWVY0GCMBbESmVbo=; b=fE3rVckTldIGJ9X79t1Tocx/fvHS8/EWaaZUWVMfpCQjD6wKu7leVkN9G5nHE7F2LC p4WBsp2m0LR3mee1GBx75i7GQ1hFNp4aJ0AeK9wRgq5DxKNNm6lsnOs+r+KExblYrhxr az+pMa5mQwMDktKT2xO108h0iA2YD2f2nwjW8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683844122; x=1686436122; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=foguPMzaG5JiKYkGBK5Zqr8oTB+NWVY0GCMBbESmVbo=; b=bGY5cOdzTAicZT9F+Y++0kDK91GaYNTTRWkbQ5o5rMzXurwUP3lH3O+6CoHNWl2hL8 M7kX1y+JS2ziN+QYSNMNGeJxLanq6zvH2XkG8VfF2ssVsDuVX6Xkc0NqF+agIjtykeEZ wOdig1KVpJ9UPDnsSwLSYRhFb8Ne22+H3aWbi5Kt2Fj/GsbQkGG+JMSWhhKZfXKRjzU5 wEC8Ms1+2C0ioAqatcjFw728AzPyRfyasvYckFKNTd7UlOVvJbkXqOAxjB70vVDxf9r2 2WuUhwyNGXaFQZ40WNvDBKuMPDM6jwpPpChqlEEzwtKn8+MmKxMIjkbEJdm9Q0CYkcIN nCTQ== X-Gm-Message-State: AC+VfDz3T21DyovMuBIgIxoNY2Ujueb+nOqdXUjVyoWHmJ/sv+6eDJBH hTtNj34dYI34MH4u0hqnGc2n7w== X-Received: by 2002:a05:6a20:8e14:b0:101:3c60:6794 with SMTP id y20-20020a056a208e1400b001013c606794mr12671176pzj.2.1683844121954; Thu, 11 May 2023 15:28:41 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id p38-20020a631e66000000b0052c766b2f52sm5515338pgm.4.2023.05.11.15.28.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 May 2023 15:28:41 -0700 (PDT) Date: Thu, 11 May 2023 15:28:40 -0700 From: Kees Cook To: Johannes Thumshirn Cc: Kent Overstreet , "linux-kernel@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-bcachefs@vger.kernel.org" , Kent Overstreet , Andrew Morton , Uladzislau Rezki , "hch@infradead.org" , "linux-mm@kvack.org" , "linux-hardening@vger.kernel.org" Subject: Re: [PATCH 07/32] mm: Bring back vmalloc_exec Message-ID: <202305111525.67001E5C4@keescook> References: <20230509165657.1735798-1-kent.overstreet@linux.dev> <20230509165657.1735798-8-kent.overstreet@linux.dev> <3508afc0-6f03-a971-e716-999a7373951f@wdc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3508afc0-6f03-a971-e716-999a7373951f@wdc.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 10, 2023 at 03:05:48PM +0000, Johannes Thumshirn wrote: > On 09.05.23 18:56, Kent Overstreet wrote: > > +/** > > + * vmalloc_exec - allocate virtually contiguous, executable memory > > + * @size: allocation size > > + * > > + * Kernel-internal function to allocate enough pages to cover @size > > + * the page level allocator and map them into contiguous and > > + * executable kernel virtual space. > > + * > > + * For tight control over page level allocator and protection flags > > + * use __vmalloc() instead. > > + * > > + * Return: pointer to the allocated memory or %NULL on error > > + */ > > +void *vmalloc_exec(unsigned long size, gfp_t gfp_mask) > > +{ > > + return __vmalloc_node_range(size, 1, VMALLOC_START, VMALLOC_END, > > + gfp_mask, PAGE_KERNEL_EXEC, VM_FLUSH_RESET_PERMS, > > + NUMA_NO_NODE, __builtin_return_address(0)); > > +} > > +EXPORT_SYMBOL_GPL(vmalloc_exec); > > Uh W+X memory reagions. > The 90s called, they want their shellcode back. Just to clarify: the kernel must never create W+X memory regions. So, no, do not reintroduce vmalloc_exec(). Dynamic code areas need to be constructed in a non-executable memory, then switched to read-only and verified to still be what was expected, and only then made executable. -- Kees Cook