Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp5835201ybf; Thu, 5 Mar 2020 07:56:05 -0800 (PST) X-Google-Smtp-Source: ADFU+vuDf+R5zWCjkEujv8rEBf7zLxg3Wn6cniSmat+CCCMl2Rs9yjJXkOVZBQF4wmUxwwiB1pol X-Received: by 2002:a05:6830:1459:: with SMTP id w25mr6895011otp.246.1583423764946; Thu, 05 Mar 2020 07:56:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583423764; cv=none; d=google.com; s=arc-20160816; b=Nqs0Vu73Bfe84TBtKFQ2arXkOlWZHVnsfPfUae3poBU3wOKfmZFiqlwIAST+jrt9Cp ymcNEq1HX4jXTm5glfS2yJvxh6sSP0yYihToE4K3bJVCW4hPnxJ0CGnJa/nTb+SnCwyd ABsHYMgdbrntVaGyOEHgJQey0yJbjXTZV1pqEl/zeG5kNNLl+CJiPVrN8QQPexAX1Unp OpqMuE79iVg49bAOh4vk6lEpuIMDX2xZDFn9oVW+29swkrYalwEzXXCCsKscDwDF4FHJ iNhXFXikx6tmxzHdIPcS2nTuGVVcBmKLD5uxULM/JcW/7kF3isxYj0FllRofOy6pX6h7 H+DQ== 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-disposition:mime-version:references:message-id:subject:cc :to:date:from:dkim-signature; bh=8r3r3JLBCoT+7BHX6G7TDShJ5a1/tz8dj9KPds9gTCo=; b=bwkMJmYuPjmpIJlyYkb8NzpA6xINMw+KmNwgoOS8ugs5KOoM+gNOU1tQ5qOzb/mq8O Osdxm+OL45LbD4qkUVbtT2YcBsoMiS08dJJ4xNr3XHqG6aI8SV9R2T3CedFCgtcVVEA2 Jt/FMU2I7Np78nq6Z+w03k6AreRiguIL8zSXe5q9X/s9rpUKSnhsvnkF7Gqn0D3sqxtL Qv7l+rL6JWJ91CHjWR36tKP+t+wJn3nNrGMzSbC39cTUVNyWoDXnwzZOmbRRn0kUuwYa Syd8S9HA1JG1VuLAlD+s0zGap32kqQrGG0tGNX4YrQdUzxSs+SPTbnJZ0l35b+VpwhHh 4xAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=DEApbHTn; 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 j74si4667218otj.246.2020.03.05.07.55.53; Thu, 05 Mar 2020 07:56:04 -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=DEApbHTn; 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 S1727023AbgCEPyZ (ORCPT + 99 others); Thu, 5 Mar 2020 10:54:25 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:44380 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726676AbgCEPyZ (ORCPT ); Thu, 5 Mar 2020 10:54:25 -0500 Received: by mail-wr1-f67.google.com with SMTP id n7so7609978wrt.11 for ; Thu, 05 Mar 2020 07:54:23 -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:in-reply-to:user-agent; bh=8r3r3JLBCoT+7BHX6G7TDShJ5a1/tz8dj9KPds9gTCo=; b=DEApbHTnS0agxpfhPaqw8/MbeQWWgxQiV8dMim1J2/cDkAgUz+6XYcVbU7CosnhTLk jBo/lHQ9zWrKOYL2BbSrzLmvYHQG1LRK6ppljf+IIBlhV7O4HdXRDC/SWiQ/SAPwDHfr /YNmZkOjupuCcvGVS5w+KPzUaHKJtNrvCe1PU= 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:in-reply-to:user-agent; bh=8r3r3JLBCoT+7BHX6G7TDShJ5a1/tz8dj9KPds9gTCo=; b=LoJ6UdqPb/nx9dQvAREYVIb3xQfzJ+06GVLaGZumGQE1k1ggF0MTYd3xYxciw+IxFX H1Z4jnn7QGkzlaFqXBfUOeYzAl1KOH7Rum6se+Drx248L1JlfSAPw1OL9WbslVBv6PRO rqORTw03TWYRforQFEmvyZ/kfErCr/ajThS/3pZW5UXS4HNdWSybcrdQicpXlupJO2MR YOQrUgxzZV6L1obxL8zraJR3S1nzl2n+w10ltTqDvnExKx3IM3QDuT8/sv8ODRXXMIFA 8ARGQCJMaF1ObzFefpExGLGdAUwrZpEoWUh6FuvpgB74W56TbC5KVWLe2eIAYZn1WGsu A6iA== X-Gm-Message-State: ANhLgQ0TpjTZF9pjdDFB615Bu6OlyID3GzrbKdlKE0nA/fZcfiVPPA2H D2mEXJHIzfkAkObgAXZvGTJJLw== X-Received: by 2002:adf:d4ca:: with SMTP id w10mr10686408wrk.407.1583423663087; Thu, 05 Mar 2020 07:54:23 -0800 (PST) Received: from google.com ([2a00:79e0:42:204:8a21:ba0c:bb42:75ec]) by smtp.gmail.com with ESMTPSA id y8sm9685425wmj.22.2020.03.05.07.54.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2020 07:54:22 -0800 (PST) From: KP Singh X-Google-Original-From: KP Singh Date: Thu, 5 Mar 2020 16:54:21 +0100 To: Stephen Smalley Cc: KP Singh , 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-ca.com Subject: Re: [PATCH bpf-next v4 3/7] bpf: Introduce BPF_MODIFY_RETURN Message-ID: <20200305155421.GA209155@google.com> References: <20200304191853.1529-1-kpsingh@chromium.org> <20200304191853.1529-4-kpsingh@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.12.2 (2019-09-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05-Mar 08:51, Stephen Smalley wrote: > On Wed, Mar 4, 2020 at 2:20 PM KP Singh wrote: > > > > From: KP Singh > > > > When multiple programs are attached, each program receives the return > > value from the previous program on the stack and the last program > > provides the return value to the attached function. > > > > The fmod_ret bpf programs are run after the fentry programs and before > > the fexit programs. The original function is only called if all the > > fmod_ret programs return 0 to avoid any unintended side-effects. The > > success value, i.e. 0 is not currently configurable but can be made so > > where user-space can specify it at load time. > > > > For example: > > > > int func_to_be_attached(int a, int b) > > { <--- do_fentry > > > > do_fmod_ret: > > > > if (ret != 0) > > goto do_fexit; > > > > original_function: > > > > > > > > } <--- do_fexit > > > > The fmod_ret program attached to this function can be defined as: > > > > SEC("fmod_ret/func_to_be_attached") > > int BPF_PROG(func_name, int a, int b, int ret) > > { > > // This will skip the original function logic. > > return 1; > > } > > > > The first fmod_ret program is passed 0 in its return argument. > > > > Signed-off-by: KP Singh > > Acked-by: Andrii Nakryiko > > 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. > 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. - KP > kernel DAC checking logic, not userspace-loaded code. > And the existing checking on attachment is not sufficient for SELinux > since CAP_MAC_ADMIN is not all powerful to SELinux. > Be careful about designing your mechanisms around Smack because Smack > is not the only LSM.