Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1293478rwd; Tue, 16 May 2023 15:04:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ742k6L6RuOidGlb8kWQSmOf0b6KwCr+AUExzofolstu7GX7SLkisPsa9RcJ8MTDKRCzobr X-Received: by 2002:a17:902:6b04:b0:1a6:87e3:db50 with SMTP id o4-20020a1709026b0400b001a687e3db50mr37288206plk.1.1684274659091; Tue, 16 May 2023 15:04:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684274659; cv=none; d=google.com; s=arc-20160816; b=kpLCTizFxzOgD7SeJMhjhX1twcHbgMSz37UidGP5/lQs/lXWfytUh+lhwcNdUjA/eJ yWujxeYWv/MImUfD7jOj+bjQbSFIZTs3LK8/5CFLNnV5mNNkEKcVnVtK1DBc6i6Swj3f PEK1NFoShOwDPC1Se+R73yXt9Srf1+aNgcl/he3snSLhEf/c4TgeMGVxEtTG3qMjAOON 2ZgObKs7J94+92e3TpH65h8nYfrAx/kRzXECk24V2zfy01VyC449F44oL+/5k1I5D4lG sMx0CgdhMBQ33B8Z/KG1uu4vctZnODtsaIbNpGmANfKv076mhuAIV9lP5a3vGU90AV6M 1bhQ== 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:dkim-signature:date; bh=rg+4VYgNan6dQhp4G+ztNtHxMTIHL0gkWBPXAeaTX8c=; b=S2XYt40t4lgateI7drOkYcRYkIhU17Kga+d9YLjsUdyXguZzlUuRkbz/rLhpjGNGHL 5VQqAsH1PYnRk3YWFZ3MM+VvnpWZlcHq7c3H9/7TN5PcldOBshlXPkAGf4J6f07Ow8XZ TpFsd1goLmJtzLYFl7TyCj230hdmRp600fQgIvjkmFaqc9lpZTVbLMq91LNJlRtLDO8O gv0aLanHSvDg6w4O9Sx9gntEQL8B/JRsOhlQD1xrWPSY80K8GFVyNwYqZ+m7krh09Ew7 WwkASiPbxk32ecBJHcv/0/i56hRyP5oCs76Wj/TLAtepjzdnxxtCAUrUwftbv+M5Yy1O Km+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=jJSE6AXl; 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=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p4-20020a170902eac400b001a6dba52e52si19174731pld.390.2023.05.16.15.04.06; Tue, 16 May 2023 15:04:19 -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=@linux.dev header.s=key1 header.b=jJSE6AXl; 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=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229678AbjEPV5m (ORCPT + 99 others); Tue, 16 May 2023 17:57:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229529AbjEPV5l (ORCPT ); Tue, 16 May 2023 17:57:41 -0400 Received: from out-38.mta1.migadu.com (out-38.mta1.migadu.com [IPv6:2001:41d0:203:375::26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED40D170E for ; Tue, 16 May 2023 14:57:39 -0700 (PDT) Date: Tue, 16 May 2023 17:57:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1684274258; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=rg+4VYgNan6dQhp4G+ztNtHxMTIHL0gkWBPXAeaTX8c=; b=jJSE6AXlg0mKNpZ3QsGHLfN984zv1y3ihtZM67UQucdGqvaeKISoBqjvubCygEtZOjn63P CgtKcnIJRmvE8tN4JU0oQdw66873QmANJIugqZktPXHNnkHuR8oAA0U6N1F3eeJ2Y1sGo5 envgWXp+n4uKqfyotbMjEdRM/d9ymyg= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kent Overstreet To: Matthew Wilcox Cc: Kees Cook , Johannes Thumshirn , "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: References: <20230509165657.1735798-1-kent.overstreet@linux.dev> <20230509165657.1735798-8-kent.overstreet@linux.dev> <3508afc0-6f03-a971-e716-999a7373951f@wdc.com> <202305111525.67001E5C4@keescook> <202305161401.F1E3ACFAC@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Tue, May 16, 2023 at 10:47:13PM +0100, Matthew Wilcox wrote: > On Tue, May 16, 2023 at 05:20:33PM -0400, Kent Overstreet wrote: > > On Tue, May 16, 2023 at 02:02:11PM -0700, Kees Cook wrote: > > > For something that small, why not use the text_poke API? > > > > This looks like it's meant for patching existing kernel text, which > > isn't what I want - I'm generating new functions on the fly, one per > > btree node. > > > > I'm working up a new allocator - a (very simple) slab allocator where > > you pass a buffer, and it gives you a copy of that buffer mapped > > executable, but not writeable. > > > > It looks like we'll be able to convert bpf, kprobes, and ftrace > > trampolines to it; it'll consolidate a fair amount of code (particularly > > in bpf), and they won't have to burn a full page per allocation anymore. > > > > bpf has a neat trick where it maps the same page in two different > > locations, one is the executable location and the other is the writeable > > location - I'm stealing that. > > How does that avoid the problem of being able to construct an arbitrary > gadget that somebody else will then execute? IOW, what bpf has done > seems like it's working around & undoing the security improvements. > > I suppose it's an improvement that only the executable address is > passed back to the caller, and not the writable address. That's my thinking; grepping around finds several uses of module_alloc() that are all doing different variations on the page permissions dance. Let's just do it once and do it right...