Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp6107610ybf; Thu, 5 Mar 2020 13:17:21 -0800 (PST) X-Google-Smtp-Source: ADFU+vv5NWqmwUyVkTZiWm2VsSDdc2tp0N5fqibixZF1OoCuUNLAY3fMJoHoYVOcE79V4mvYjYCQ X-Received: by 2002:a9d:12a3:: with SMTP id g32mr382671otg.111.1583443041792; Thu, 05 Mar 2020 13:17:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583443041; cv=none; d=google.com; s=arc-20160816; b=yjSWFiVHxF5L5FZeBf8YjeLJwqTGkiYpJlpwgaUEZ8SSSesx//wwOa9369VtRmNAMH kLock/nt2EPR1wp1huef1PbJKkjGQ0oSLim3Jja1j09dE78VesftMltsacv9RA164PQQ jCFcKY4TgyuhgnGZZAYWbD7nS9rn5Vfj5x1Ta8ijrzq5QmN+Au1d386xmp0hit9IY2Md 6Y5SFGYXP2uBo4tF9Gze5bTEhdfWrBjldCm5P9HqixwfB3yoD9EvCwI3X6AozoRbBmhr 2i+pUaXNUoOfO+cgXa3KlDKZxEF5heUorEg3GTmJ/eCrgGkwLmN3AnLXnCVhP1mPV0Z4 xtyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:date:from:dkim-signature; bh=rFYE9qU6hfZLMjbuv+Lw+SiZtkHRJmxeQZgCYrPMhQA=; b=GK8iAlxDZ2Azq9i7p4hmFQQ/OgVKQgoLvD5x7KUYkU5ChInaQQJRDGYsEcGCGBjVpo W2RxMpgLhUQ69hvKTR67vGxHVH3pUyZ0O4kkTsM2+pfvPl5Z1yOAeSJ25/TvsODL3NXC wpA+5Blkt2UFpxMDAkVpCwFaWRS8dpoN/Od9I9+JMlCUljTBzFnztGp8i79fhluaW2B4 6lnUktcvdA70figpp8uAhBM0e25G5xUiD9eNb/XcuE+u7rvqlqUfqS9uxa1djTfvQ0lU bhC3yGAzLOVdaSxOacznnZVp6uuaWUOK1WxNDBrG8QsxTJCxrvCfDzg7z3zY036Xufp5 Y07g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=isUdIXzz; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i4si95682oib.219.2020.03.05.13.17.08; Thu, 05 Mar 2020 13:17:21 -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; dkim=pass header.i=@chromium.org header.s=google header.b=isUdIXzz; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726179AbgCEVQt (ORCPT + 99 others); Thu, 5 Mar 2020 16:16:49 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:34710 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725991AbgCEVQt (ORCPT ); Thu, 5 Mar 2020 16:16:49 -0500 Received: by mail-wm1-f68.google.com with SMTP id x3so2811982wmj.1 for ; Thu, 05 Mar 2020 13:16:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=rFYE9qU6hfZLMjbuv+Lw+SiZtkHRJmxeQZgCYrPMhQA=; b=isUdIXzz1WywdtIB6ayzczG6D27adzp5OvZ+mwE5OAioulxSPjDaDutrYz88lS5//h 8gDvO0A0RNZ+xrP4i3PSqfYZQizRnLpAk1S7jcK2ysbU7KL5FXPhBQSp6wMbgWrIKgnG as59ZuFJ+uo1o9AqL2xYldyROmTL5aIFXgVSA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=rFYE9qU6hfZLMjbuv+Lw+SiZtkHRJmxeQZgCYrPMhQA=; b=MhOpyGejReFUuClNEX3Lv+lcnZkB1DsNqvTrm1D/Q56mUyMYAXTr1dYyBkDbFE7gPf By5iA8I1/dcjOpBVLqy8YgCcnSPxGHBK4GNARAPRMzKPxWd2Nfo7MRT0hIaorFiFQ0Wg zKF+Dmwb7crJkpDls8AVkJGE2FhmO5AbuzIhBKaHUYvKafTttcHGepPeEJUqHPJOunsQ O5J2ifiBNFNWOKV/avLreK+yLC/0Q78uonHFW3BDImQdqkgg9iHZ0z0qLDyIhCYpyrlS Zl0LDyuxsLlQ9gjT8OIB+zk2ZF3lkDNZWntMW0ejpagu9odrnBpcoK6BtXxCN6RvOfoE m0lg== X-Gm-Message-State: ANhLgQ1ZriyHjfGEbNFtkvJ84bzOQNRWeo0YPKoHvXL6czAN1GM2xkJz PZVQFIZwlrXpaFQ+sf/GsZTnMw== X-Received: by 2002:a05:600c:218d:: with SMTP id e13mr686605wme.127.1583443006355; Thu, 05 Mar 2020 13:16:46 -0800 (PST) Received: from chromium.org (77-56-209-237.dclient.hispeed.ch. [77.56.209.237]) by smtp.gmail.com with ESMTPSA id j5sm10577968wmi.33.2020.03.05.13.16.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2020 13:16:45 -0800 (PST) From: KP Singh X-Google-Original-From: KP Singh Date: Thu, 5 Mar 2020 22:16:43 +0100 To: Stephen Smalley Cc: linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Paul Turner , Jann Horn , Florent Revest , Brendan Jackman , jmorris@namei.org, Paul Moore , Casey Schaufler Subject: Re: [PATCH bpf-next v4 3/7] bpf: Introduce BPF_MODIFY_RETURN Message-ID: <20200305211643.GA12094@chromium.org> References: <20200304191853.1529-1-kpsingh@chromium.org> <20200304191853.1529-4-kpsingh@chromium.org> <20200305155421.GA209155@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05-M?r 14:43, Stephen Smalley wrote: > On Thu, Mar 5, 2020 at 10:54 AM KP Singh wrote: > > > > On 05-Mar 08:51, Stephen Smalley wrote: > > > IIUC you've switched from a model where the BPF program would be > > > invoked after the original function logic > > > and the BPF program is skipped if the original function logic returns > > > non-zero to a model where the BPF program is invoked first and > > > the original function logic is skipped if the BPF program returns > > > non-zero. I'm not keen on that for userspace-loaded code attached > > > > We do want to continue the KRSI series and the effort to implement a > > proper BPF LSM. In the meantime, the tracing + error injection > > solution helps us to: > > > > * Provide better debug capabilities. > > * And parallelize the effort to come up with the right helpers > > for our LSM work and work on sleepable BPF which is also essential > > for some of the helpers. > > > > As you noted, in the KRSI v4 series, we mentioned that we would like > > to have the user-space loaded BPF programs be unable to override the > > decision made by the in-kernel logic/LSMs, but this got shot down: > > > > https://lore.kernel.org/bpf/00c216e1-bcfd-b7b1-5444-2a2dfa69190b@schaufler-ca.com > > > > I would like to continue this discussion when we post the v5 series > > for KRSI as to what the correct precedence order should be for the > > BPF_PROG_TYPE_LSM and would appreciate if you also bring it up there. > > That's fine but I guess I don't see why you or anyone else would > bother with introducing a BPF_PROG_TYPE_LSM > if BPF_PROG_MODIFY_RETURN is accepted and is allowed to attach to the > LSM hooks. What's the benefit to you > if you can achieve your goals directly with MODIFY_RETURN? There is still value in being a proper LSM, as I had mentioned in KRSI v3 that not all security_* wrappers simply call the attached hooks and return their exit code. It's also okay, taking into consideration Casey's objections and Kees' suggestion, to be properly registered with the LSM framework (even if it is with LSM_ORDER_LAST) and work towards improving some of the performance bottle-necks in the framework. It would be a positive outcome for all LSMs. BPF_MODIFY_RETURN is just a first step which lays the foundation for BPF_PROG_TYPE_LSM and facilitates us to build BPF infrastructure for it. - KP > > > > to LSM hooks; it means that userspace BPF programs can run even if > > > SELinux would have denied access and SELinux hooks get > > > skipped entirely if the BPF program returns an error. I think Casey > > > may have wrongly pointed you in this direction on the grounds > > > it can already happen with the base DAC checking logic. But that's > > > > What we can do for this tracing/modify_ret series, is to remove > > the special casing for "security_" functions in the BPF code and add > > ALLOW_ERROR_INJECTION calls to the security hooks. This way, if > > someone needs to disable the BPF programs being able to modify > > security hooks, they can disable error injection. If that's okay, we > > can send a patch. > > Realistically distros tend to enable lots of developer-friendly > options including error injection, and most users don't build their > own kernels > and distros won't support them when they do. So telling users they can > just rebuild their kernel without error injection if they care about > BPF programs being able to modify security hooks isn't really viable. > The security modules need a way to veto it based on their policies. > That's why I suggested a security hook here.