Received: by 10.192.245.15 with SMTP id i15csp999985imn; Sat, 10 Mar 2018 18:18:58 -0800 (PST) X-Google-Smtp-Source: AG47ELsHilQNIp2E1yM85Wj/+h+oXVuQFdxw7uXLJwlOpN2o22aNiLDwHxvjO+9CaPWhfwkasmp4 X-Received: by 2002:a17:902:47aa:: with SMTP id r39-v6mr3679878pld.72.1520734738383; Sat, 10 Mar 2018 18:18:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520734738; cv=none; d=google.com; s=arc-20160816; b=JDUMvikoRWfYEEerAvgFlJCgbe4xnD+Q7qkD3hrHqoqwPskDldpFNaYAri8c7cKumg j1s0OMmXKuEIfcdkf38uYiBdV5rH0GP9cplQGhfVpl0gz7VswkGXUHU4cqz1OeAxDOsd q5tb3O6djKiElz5TAxl8Vhw6qtlNeODOrlmiwudQ0KixxzZ37AIPHVdrECDKgoE2JszX aydllFJxHUnvfygu1+/Muv5SDav3Wx23xF7DovjuixDRa0EvvBJlGdUl7ijYOOJ9qDeK FXkPN0egQMroyVvIldd9bZ+0KUcsPc/JgCBXM6nT+wJuiISmVabz9zUWrRzOnxBrNGUR otTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dmarc-filter :arc-authentication-results; bh=i8o73ohjaDkc5pwABSW19x1B7j90Qe1sXOXnCmqFsgQ=; b=rDJxe+tG5lYHWRjN6K9cNhsS3nR4w6hjpjAx0KiJsHxL3bcIyPekj6jM7Z8ujQcM1q Fl5YrTPdVFuGNre3nX7Tw2y/OxNcYWJ3U2cZwCm1xzGik3Q6HAAQS75/yDPTb8kD4Knd eUyUljI84ZzqmjDxUqcZ0BhCxCc0R4XPPKtMN1182avTlkKCpxwQNcWkW8mQMjRxtjnH NllSZuuK5gxbq8k9lh6vRvGItssVtxhGhAueG8HuR2qEGVff9fkdKrltGkx1c9ACH/82 35qtK64yZUU1hE0AS4Y3KFj+dyyyDJ0WyBX3VIiUChihvW0Yzzp7EefKOdxYm7Il61QW VrBg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c6-v6si3851109plm.448.2018.03.10.18.18.44; Sat, 10 Mar 2018 18:18:58 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751250AbeCKCRs (ORCPT + 99 others); Sat, 10 Mar 2018 21:17:48 -0500 Received: from mail.kernel.org ([198.145.29.99]:56960 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751209AbeCKCRq (ORCPT ); Sat, 10 Mar 2018 21:17:46 -0500 Received: from mail-it0-f43.google.com (mail-it0-f43.google.com [209.85.214.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7B22521795 for ; Sun, 11 Mar 2018 02:17:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7B22521795 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=luto@kernel.org Received: by mail-it0-f43.google.com with SMTP id k79-v6so7331024ita.2 for ; Sat, 10 Mar 2018 18:17:45 -0800 (PST) X-Gm-Message-State: AElRT7HfMg5kNyvLmKWou0o1f/1fTaFgEVGX9P1IFEY0NPVd98XBair8 qeOxhz4ZsT8m4++dw9Fr8hH7XBf7JaTtjwzsmFJKIQ== X-Received: by 10.36.249.73 with SMTP id l70mr3644148ith.55.1520734664745; Sat, 10 Mar 2018 18:17:44 -0800 (PST) MIME-Version: 1.0 Received: by 10.2.137.101 with HTTP; Sat, 10 Mar 2018 18:17:24 -0800 (PST) In-Reply-To: <64a80f5e-25db-5413-ab50-fb122bc22d8c@fb.com> References: <20180309181527.GA15803@kroah.com> <74e26cc0-9e72-f03b-5396-f3480921f234@fb.com> <20180309.135550.385837861865623769.davem@davemloft.net> <64a80f5e-25db-5413-ab50-fb122bc22d8c@fb.com> From: Andy Lutomirski Date: Sun, 11 Mar 2018 02:17:24 +0000 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH net-next] modules: allow modprobe load regular elf binaries To: Alexei Starovoitov Cc: Andy Lutomirski , David Miller , Greg KH , Linus Torvalds , Kees Cook , Alexei Starovoitov , Djalal Harouni , Al Viro , Daniel Borkmann , "Luis R. Rodriguez" , Network Development , LKML , kernel-team , Linux API Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Mar 10, 2018 at 1:43 AM, Alexei Starovoitov wrote: > On 3/9/18 11:37 AM, Andy Lutomirski wrote: >> >> On Fri, Mar 9, 2018 at 6:55 PM, David Miller wrote: >>> >>> From: Alexei Starovoitov >>> Date: Fri, 9 Mar 2018 10:50:49 -0800 >>> >>>> On 3/9/18 10:23 AM, Andy Lutomirski wrote: >>>>> >>>>> It might not be totally crazy to back it by tmpfs. >>>> >>>> >>>> interesting. how do you propose to do it? >>>> Something like: >>>> - create /umh_module_tempxxx dir >>>> - mount tmpfs there >>>> - copy elf into it and exec it? >>> >>> >>> I think the idea is that it's an internal tmpfs mount that only >>> the kernel has access too. >> >> >> That's what I was imagining. There's precedent. For example, there's >> a very short piece of code that does it in >> drivers/gpu/drm/i915/i915_gemfs.c. > > > I can do "monkey see monkey do" approach which will look like: > type = get_fs_type("tmpfs"); > fs = kern_mount(type); > > /* for each request_umh("foo") */ > file = shmem_file_setup_with_mnt(fs, "umh_foo"); > do { > pagecache_write_begin(file,...); > memcpy() > pagecache_write_end(); > } while (umh_elf_size); > do_execve_file(file); > fput(file); > > while keeping fs mounted forever? > is there better way? > Nice! I'm definitely not a pagecache expert, but it looks generally sane. Once the thing is actually functional, we can bang on it, and I'm sure that linux-mm will have some suggestions to tidy it up. As for the actual lifetime of the filesystem, I think it should be mounted once and never unmounted. Whenever it gains a second user, the whole thing can be moved to mm/ or lib/ and all the users can share the same mount. Minor caveat: I would arrange the code a bit differently, like this: static (or extern) unsigned char __initdata the_blob[]; static struct file *umh_blob_file; static int __init my_module_init_function(void) { /* for each request_umh("foo") */ umh_blob_file = shmem_file_setup_with_mnt(fs, "umh_foo"); do { pagecache_write_begin(umh_file,...); memcpy() pagecache_write_end(); } while (umh_elf_size); /* the_blob is implicitly freed after this returns */ } and then actually use the struct file later on. If and when you're sure you're not going to spawn another copy, you can fput() it. This way the memory becomes swappable immediately on load. As for request_module() vs request_module_umh(), my advice would be to write the code and then see what interface makes sense. I wouldn't be surprised if it ends up making more sense to keep all of this entirely independent from the module system. P.S. I suspect that, before this hits a release, someone's going to have to fiddle with the LSM hooks in do_execve() a bit to make sure that LSM unconditionally approves this type of umh program. Otherwise there might be pointless failures on some more locked down configurations. But that can wait until it's more final and the security folks review the code.