Received: by 10.223.185.116 with SMTP id b49csp5539006wrg; Tue, 27 Feb 2018 15:25:59 -0800 (PST) X-Google-Smtp-Source: AH8x226FnAjI072+bZ6TyFbaeTQ8+yHCuHM13Jb7ULa2DRtuFwTYS6Lm+xHi+Yn3QJApV68OJzgE X-Received: by 10.101.85.204 with SMTP id k12mr12896883pgs.40.1519773959691; Tue, 27 Feb 2018 15:25:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519773959; cv=none; d=google.com; s=arc-20160816; b=xXqv955goMJjrzPgjB/Pa5vU5iDlB0awS9EUB2ED7xivSPNfbximh7lsKkb3YG6Mkv jTEyFbLIBEjiigqQ+uxvI9kUujj3y4tZi2QBrCE6l1K2Dfzh6mGm2y/LSut/PjPbbLQ/ +Tnf7uNA05+C8S2L2D+poGeScPQbBKHpTPdk1TmuhvGuyjnL0wdWokTRpn1UhTVD6Eys m2lArVhxjZwi5SoHfA6pHEPt7jWe+w5cj6/OvEI54RNuvspL1uc35MpNeCWAmSJqfE4M IxjY6KLIQlfhNpQw6+F8LNwQzpfaN+3ZLiU7C1WCx+LuEx2Va9vY4bLq1GDbsa86MQUG 2eNw== 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=oODjZXBTjEdts1nEMxxFDTBiIkueYrr/JpLPVlBLl98=; b=ZZXDt1zinGt68eWYrYRsDEu5AR1jXz25SK6Kq2q5x4ag2Bza4hScSkj/u1poKuo176 EuDSQ1hbJBy21+0wtzE4Pbofvzu5lyv0TxGHKEqPdBcDQgCfhBWuO/9dr8LlkedNGXws O60KAIm7KSVnohQSUYvEoECbIGQFFy8fJURINFKmPzJfNTlFqJnQo7J/GR9WEccIpgo7 ILHz6WJEDT2m7pm0wLUJ9JPtBSbPjTk8+SuCuEI3yGjyNk3OT1tq27+riKWsmTt4RdVE 6GYwuNULdo5J6oPym/uXEqfaSyq9wiczNFt/Sq5hwC3egNYt7oqqCFaaGdIEm8rir3la dvow== 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 x4si119914pgo.278.2018.02.27.15.25.45; Tue, 27 Feb 2018 15:25:59 -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 S1752385AbeB0XYH convert rfc822-to-8bit (ORCPT + 99 others); Tue, 27 Feb 2018 18:24:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:54492 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751979AbeB0XYD (ORCPT ); Tue, 27 Feb 2018 18:24:03 -0500 Received: from mail-io0-f175.google.com (mail-io0-f175.google.com [209.85.223.175]) (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 5DB9C217BE for ; Tue, 27 Feb 2018 23:24:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5DB9C217BE 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-io0-f175.google.com with SMTP id e7so1169391ioj.1 for ; Tue, 27 Feb 2018 15:24:02 -0800 (PST) X-Gm-Message-State: APf1xPBf6PiS/cq+/eeD79yXsUPeBzqnyXCD/FB+Sa60Sfrm5iFteB/l pQvHfpaIURBI2fPG5a2PeeRUOM1EpffiLqtFhZy0Yg== X-Received: by 10.107.188.194 with SMTP id m185mr18055059iof.21.1519773841567; Tue, 27 Feb 2018 15:24:01 -0800 (PST) MIME-Version: 1.0 Received: by 10.2.137.101 with HTTP; Tue, 27 Feb 2018 15:23:36 -0800 (PST) In-Reply-To: References: <20180227004121.3633-1-mic@digikod.net> <20180227004121.3633-9-mic@digikod.net> <0e7d0512-12a3-568d-aa55-3def4b91c6d0@digikod.net> From: Andy Lutomirski Date: Tue, 27 Feb 2018 23:23:36 +0000 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH bpf-next v8 08/11] landlock: Add ptrace restrictions To: Andy Lutomirski Cc: =?UTF-8?B?TWlja2HDq2wgU2FsYcO8bg==?= , 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 , Tycho Andersen , 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 Tue, Feb 27, 2018 at 11:02 PM, Andy Lutomirski wrote: > On Tue, Feb 27, 2018 at 10:14 PM, Mickaël Salaün wrote: >> >> On 27/02/2018 06:01, Andy Lutomirski wrote: >>> >>> >>>> On Feb 26, 2018, at 8:17 PM, Andy Lutomirski wrote: >>>> >>>>> On Tue, Feb 27, 2018 at 12:41 AM, Mickaël Salaün wrote: >>>>> A landlocked process has less privileges than a non-landlocked process >>>>> and must then be subject to additional restrictions when manipulating >>>>> processes. To be allowed to use ptrace(2) and related syscalls on a >>>>> target process, a landlocked process must have a subset of the target >>>>> process' rules. >>>>> >>>>> Signed-off-by: Mickaël Salaün >>>>> Cc: Alexei Starovoitov >>>>> Cc: Andy Lutomirski >>>>> Cc: Daniel Borkmann >>>>> Cc: David S. Miller >>>>> Cc: James Morris >>>>> Cc: Kees Cook >>>>> Cc: Serge E. Hallyn >>>>> --- >>>>> >>>>> Changes since v6: >>>>> * factor out ptrace check >>>>> * constify pointers >>>>> * cleanup headers >>>>> * use the new security_add_hooks() >>>>> --- >>>>> security/landlock/Makefile | 2 +- >>>>> security/landlock/hooks_ptrace.c | 124 +++++++++++++++++++++++++++++++++++++++ >>>>> security/landlock/hooks_ptrace.h | 11 ++++ >>>>> security/landlock/init.c | 2 + >>>>> 4 files changed, 138 insertions(+), 1 deletion(-) >>>>> create mode 100644 security/landlock/hooks_ptrace.c >>>>> create mode 100644 security/landlock/hooks_ptrace.h >>>>> >>>>> diff --git a/security/landlock/Makefile b/security/landlock/Makefile >>>>> index d0f532a93b4e..605504d852d3 100644 >>>>> --- a/security/landlock/Makefile >>>>> +++ b/security/landlock/Makefile >>>>> @@ -3,4 +3,4 @@ obj-$(CONFIG_SECURITY_LANDLOCK) := landlock.o >>>>> landlock-y := init.o chain.o task.o \ >>>>> tag.o tag_fs.o \ >>>>> enforce.o enforce_seccomp.o \ >>>>> - hooks.o hooks_cred.o hooks_fs.o >>>>> + hooks.o hooks_cred.o hooks_fs.o hooks_ptrace.o >>>>> diff --git a/security/landlock/hooks_ptrace.c b/security/landlock/hooks_ptrace.c >>>>> new file mode 100644 >>>>> index 000000000000..f1b977b9c808 >>>>> --- /dev/null >>>>> +++ b/security/landlock/hooks_ptrace.c >>>>> @@ -0,0 +1,124 @@ >>>>> +/* >>>>> + * Landlock LSM - ptrace hooks >>>>> + * >>>>> + * Copyright © 2017 Mickaël Salaün >>>>> + * >>>>> + * This program is free software; you can redistribute it and/or modify >>>>> + * it under the terms of the GNU General Public License version 2, as >>>>> + * published by the Free Software Foundation. >>>>> + */ >>>>> + >>>>> +#include >>>>> +#include >>>>> +#include /* ARRAY_SIZE */ >>>>> +#include >>>>> +#include /* struct task_struct */ >>>>> +#include >>>>> + >>>>> +#include "common.h" /* struct landlock_prog_set */ >>>>> +#include "hooks.h" /* landlocked() */ >>>>> +#include "hooks_ptrace.h" >>>>> + >>>>> +static bool progs_are_subset(const struct landlock_prog_set *parent, >>>>> + const struct landlock_prog_set *child) >>>>> +{ >>>>> + size_t i; >>>>> + >>>>> + if (!parent || !child) >>>>> + return false; >>>>> + if (parent == child) >>>>> + return true; >>>>> + >>>>> + for (i = 0; i < ARRAY_SIZE(child->programs); i++) { >>>> >>>> ARRAY_SIZE(child->programs) seems misleading. Is there no define >>>> NUM_LANDLOCK_PROG_TYPES or similar? >>>> >>>>> + struct landlock_prog_list *walker; >>>>> + bool found_parent = false; >>>>> + >>>>> + if (!parent->programs[i]) >>>>> + continue; >>>>> + for (walker = child->programs[i]; walker; >>>>> + walker = walker->prev) { >>>>> + if (walker == parent->programs[i]) { >>>>> + found_parent = true; >>>>> + break; >>>>> + } >>>>> + } >>>>> + if (!found_parent) >>>>> + return false; >>>>> + } >>>>> + return true; >>>>> +} >>>> >>>> If you used seccomp, you'd get this type of check for free, and it >>>> would be a lot easier to comprehend. AFAICT the only extra leniency >>>> you're granting is that you're agnostic to the order in which the >>>> rules associated with different program types were applied, which >>>> could easily be added to seccomp. >>> >>> On second thought, this is all way too complicated. I think the correct logic is either "if you are filtered by Landlock, you cannot ptrace anything" or to delete this patch entirely. >> >> This does not fit a lot of use cases like running a container >> constrained with some Landlock programs. We should not deny users the >> ability to debug their stuff. >> >> This patch add the minimal protection which are needed to have >> meaningful Landlock security policy. Without it, they may be easily >> bypassable, hence useless. >> > > I think you're wrong here. Any sane container trying to use Landlock > like this would also create a PID namespace. Problem solved. I still > think you should drop this patch. > >> >>> If something like Tycho's notifiers goes in, then it's not obvious that, just because you have the same set of filters, you have the same privilege. Similarly, if a feature that lets a filter query its cgroup goes in (and you proposed this once!) then the logic you implemented here is wrong. >> >> I don't get your point. Please take a look at the tests (patch 10). > > I don't know what you want me to look at. > > What I'm saying is: suppose I write a filter like this: > > bool allow_some_action(void) > { > int value_from_container_manager = call_out_to_user_notifier(); > return value_from_container_manager == 42; > } > > or > > bool allow_some_action(void) > { > return my_cgroup_is("/foo/bar"); > } > > In both of these cases, your code will do the wrong thing. > >> >>> >>> Or you could just say that it's the responsibility of a Landlock user to properly filter ptrace() just like it's the responsibility of seccomp users to filter ptrace if needed. >> >> A user should be able to enforce a security policy on ptrace as well, >> but this patch enforce a minimal set of security boundaries. It will be >> easy to add a new Landlock program type to get this kind of access control. > > It sounds like you want Landlock to be a complete container system all > by itself. I disagree with that design goal. Having actually read your series more correctly now (oops!), I still think that this patch should be dropped. I can see an argument for having a flag that one can set when adding a seccomp filter that says "prevent ptrace of any child that doesn't have this exact stack installed", but I think that could be added later and should not be part of an initial submission. For now, Landlock users can block ptrace() entirely or use PID namespaces.