Received: by 10.223.185.116 with SMTP id b49csp210997wrg; Thu, 8 Mar 2018 15:56:53 -0800 (PST) X-Google-Smtp-Source: AG47ELttmYBf0TSnr8ZsK4wnvSBQllmOiHcBKJuP9fu7BfhZmjjlyGMIL9Iktx8ZEuQKp5a9FOsy X-Received: by 10.101.92.196 with SMTP id b4mr22066433pgt.27.1520553413143; Thu, 08 Mar 2018 15:56:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520553413; cv=none; d=google.com; s=arc-20160816; b=dnbmKuw2BVCg42WN6FroHpWCIt7fW60/pAMGAcGQMEkUJLoBLB7kgeisRYk1jfaJNj pr+UUQw9gp4m4sz9NRxN5WFTHAyyJeZOXsjIB1Rhcsfk+kR7JqDwg9hgWyvS5StZ5XyH Rqg0hp5zruwTfKa4cl3NfF0zDGIr3goV4FzUy3XPXiqjxUPLJiQbzIPFKuO1TAxxMMkz EnMtQA0Cji2D3bHVw3ZGhHQCg1S+ee+Po7pkwx+H4mo0T/x8a4SQMmiDOzsz/A6wqlpe WEUn2WZa5rTH2prcbGKDLU06RUVsJdDprZ4wKexADMMBZzuwnArdngmB38HyMnS+YUNb y+fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:references:in-reply-to:mime-version :dmarc-filter:arc-authentication-results; bh=JMIehSkV1hOVYvNWqkxlE9wOERjRma5AtM78bKDzkSI=; b=ZJYcn7fy2XW59aatqY4xiwUfbAH/rUxpaZ30mbEOKMtsjyiQ9pWtSB5X0Ex2qWTjez l1xnrTpR7f4aNuVOLGF1En5Kdd2qqpWFo+/PycqF9QCsgi3Ut7lgFwm66IaOM1v4LaW8 lU/FPJuI29kqIzwkEflDhEJAASFfBrXledKDjvDovJuB8hZwNhiOlznJtPPq/s2O7r0y CxFYiUshxvRm5pr5us3LsnbgoAgSEc3zYNJv4j7nfh7UBNqcH7GaITYxg6LWTynvntlG GHQAZXSFeqGkRHBPgh7Uo/HtmEIMcars4dcsIMh0OoN1PALxV6LUx4SooaiSIjJE4rOl phZg== 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 d21si16658962pfk.328.2018.03.08.15.56.38; Thu, 08 Mar 2018 15:56:53 -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 S1751512AbeCHXyP convert rfc822-to-8bit (ORCPT + 99 others); Thu, 8 Mar 2018 18:54:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:53900 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751122AbeCHXyO (ORCPT ); Thu, 8 Mar 2018 18:54:14 -0500 Received: from mail-it0-f52.google.com (mail-it0-f52.google.com [209.85.214.52]) (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 D96F9217AD for ; Thu, 8 Mar 2018 23:54:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D96F9217AD 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-f52.google.com with SMTP id u66so713808ith.1 for ; Thu, 08 Mar 2018 15:54:13 -0800 (PST) X-Gm-Message-State: AElRT7F2I9b7gKYtqnko7izo89vL9JYgvQFMTVoAON6qd6T6bhsXjEPA INw0ncw2HRSCKD6+2EkYy5K6veRNbl+wB52TBalfzw== X-Received: by 2002:a24:5ad4:: with SMTP id v203-v6mr973943ita.150.1520553253043; Thu, 08 Mar 2018 15:54:13 -0800 (PST) MIME-Version: 1.0 Received: by 10.2.137.101 with HTTP; Thu, 8 Mar 2018 15:53:52 -0800 (PST) In-Reply-To: References: <20180227004121.3633-1-mic@digikod.net> <2e06621c-08e9-dc12-9b6e-9c09d5d8f458@digikod.net> <20180306224636.wf5z3kujtc7r5qyh@cisco> <7082be04-d6af-b853-4bb7-f331836662e2@digikod.net> From: Andy Lutomirski Date: Thu, 8 Mar 2018 23:53:52 +0000 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH bpf-next v8 00/11] Landlock LSM: Toward unprivileged sandboxing To: =?UTF-8?B?TWlja2HDq2wgU2FsYcO8bg==?= Cc: Tycho Andersen , LKML , Alexei Starovoitov , Arnaldo Carvalho de Melo , Casey Schaufler , Daniel Borkmann , David Drysdale , "David S . Miller" , "Eric W . Biederman" , James Morris , Jann Horn , Jonathan Corbet , Michael Kerrisk , Kees Cook , Paul Moore , Sargun Dhillon , "Serge E . Hallyn" , Shuah Khan , Tejun Heo , Thomas Graf , Will Drewry , Kernel Hardening , Linux API , LSM List , Network Development Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 8, 2018 at 11:51 PM, Mickaël Salaün wrote: > > On 07/03/2018 02:21, Andy Lutomirski wrote: >> On Tue, Mar 6, 2018 at 11:06 PM, Mickaël Salaün wrote: >>> >>> On 06/03/2018 23:46, Tycho Andersen wrote: >>>> On Tue, Mar 06, 2018 at 10:33:17PM +0000, Andy Lutomirski wrote: >>>>>>> Suppose I'm writing a container manager. I want to run "mount" in the >>>>>>> container, but I don't want to allow moun() in general and I want to >>>>>>> emulate certain mount() actions. I can write a filter that catches >>>>>>> mount using seccomp and calls out to the container manager for help. >>>>>>> This isn't theoretical -- Tycho wants *exactly* this use case to be >>>>>>> supported. >>>>>> >>>>>> Well, I think this use case should be handled with something like >>>>>> LD_PRELOAD and a helper library. FYI, I did something like this: >>>>>> https://github.com/stemjail/stemshim >>>>> >>>>> I doubt that will work for containers. Containers that use user >>>>> namespaces and, for example, setuid programs aren't going to honor >>>>> LD_PRELOAD. >>>> >>>> Or anything that calls syscalls directly, like go programs. >>> >>> That's why the vDSO-like approach. Enforcing an access control is not >>> the issue here, patching a buggy userland (without patching its code) is >>> the issue isn't it? >>> >>> As far as I remember, the main problem is to handle file descriptors >>> while "emulating" the kernel behavior. This can be done with a "shim" >>> code mapped in every processes. Chrome used something like this (in a >>> previous sandbox mechanism) as a kind of emulation (with the current >>> seccomp-bpf ). I think it should be doable to replace the (userland) >>> emulation code with an IPC wrapper receiving file descriptors through >>> UNIX socket. >>> >> >> Can you explain exactly what you mean by "vDSO-like"? >> >> When a 64-bit program does a syscall, it just executes the SYSCALL >> instruction. The vDSO isn't involved at all. 32-bit programs usually >> go through the vDSO, but not always. >> >> It could be possible to force-load a DSO into an entire container and >> rig up seccomp to intercept all SYSCALLs not originating from the DSO >> such that they merely redirect control to the DSO, but that seems >> quite messy. > > vDSO is a code mapped for all processes. As you said, these processes > may use it or not. What I was thinking about is to use the same concept, > i.e. map a "shim" code into each processes pertaining to a particular > hierarchy (the same way seccomp filters are inherited across processes). > With a seccomp filter matching some syscall (e.g. mount, open), it is > possible to jump back to the shim code thanks to SECCOMP_RET_TRAP. This > shim code should then be able to emulate/patch what is needed, even > faking a file opening by receiving a file descriptor through a UNIX > socket. As did the Chrome sandbox, the seccomp filter may look at the > calling address to allow the shim code to call syscalls without being > catched, if needed. However, relying on SIGSYS may not fit with > arbitrary code. Using a new SECCOMP_RET_EMULATE (?) may be used to jump > to a specific process address, to emulate the syscall in an easier way > than only relying on a {c,e}BPF program. > This could indeed be done, but I think that Tycho's approach is much cleaner and probably faster.