Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4926504ybb; Tue, 24 Mar 2020 07:50:47 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsIsNfvfNwJJh2G8lUejQAd8kxoFGctR3XF60bOkBeKY66BKSctKX9Qki2QRc4EVtg4cI2K X-Received: by 2002:a9d:5882:: with SMTP id x2mr8474650otg.297.1585061447526; Tue, 24 Mar 2020 07:50:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585061447; cv=none; d=google.com; s=arc-20160816; b=d1FcQd9ya9J/cjvN9WpTmlSxaTHZkkc4yupNCHkqvXaDQnEZBJEm1EWyT8Bo1xrgXV LI+cVOIBFhssd9qAqtx9xvxNkgkvd27KBMBEbEd8tk9q4xwAHXYh1NdQU3q2oXJda9Iz FhYAEQhgm/Y/NCdOEeVJmVXz2CJBh2AxLW4L7B9gNIePHK1gCHjvR9QrpLgESd2nkGfD j+ui1GDSc8MOq5OyV45IBEtQj1Y3BClnHlHrlSedH6iLWfC7LykJ/MuNxycFS+ExDNlf O9R19zjQE+xAmV0DWZGG3tOk941gHcoqAKUgmR1d286BabZQJn+UoryKAAaeWaC3pdGc UgLg== 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=oGbi1kK4rZ5Jg0cdOf4BlknnOlqmymkgqgzxdZFk9xc=; b=wwBi7EkzC3al1bA5LltYrukANUDCFzpDQegA1pMvUltswHGHR3e0BvP775+79bKGW/ spbzT1sqmk2VMGMSMO3GWJSBzUXb9Dtt8nsP8VjsnbDVz001dbKHe5BzCueBG9XndhBY dvjW6Q1EiMnB8noi6OBSmyyl6xt2AAfwT/di6A6g7qY6V3Nf/QT6qz6eK82kXwIeAUnK VetneoWahy/tsJdUV+mjT11w9R/JTL5sec2l6mLKBepVvq3KvqCQSrABs0uDXYuVvhbG uDnAWv/i9UZ7rvOCok1KBQzcMvk7VQZLoFmZ7EzspmwWe7dVnEMvfkmiONk3m0mgQToV xyEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=A9CiRgGu; 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 c20si3913136otp.46.2020.03.24.07.50.33; Tue, 24 Mar 2020 07:50:47 -0700 (PDT) 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=A9CiRgGu; 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 S1727960AbgCXOuM (ORCPT + 99 others); Tue, 24 Mar 2020 10:50:12 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:36251 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727837AbgCXOuM (ORCPT ); Tue, 24 Mar 2020 10:50:12 -0400 Received: by mail-wr1-f65.google.com with SMTP id 31so15776124wrs.3 for ; Tue, 24 Mar 2020 07:50:11 -0700 (PDT) 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=oGbi1kK4rZ5Jg0cdOf4BlknnOlqmymkgqgzxdZFk9xc=; b=A9CiRgGuc0FzDG8Jea7fRV9it5TL0VjdcTyRfjSQ7U6FCuWl+0j9LmRVYnApg12iUa 2FrYHGgTGEObTGVfsbzvatv/yw//8Y8xyP7ubTh8hHoCVdlpsnSjckPtRjenc1x0QOhd n3PsTLkaVT6G+ohUiS6sU/8kAAkOTJj4oFtkk= 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=oGbi1kK4rZ5Jg0cdOf4BlknnOlqmymkgqgzxdZFk9xc=; b=pxFwC7KsbjMoVlVNPW9qM2wWcJpsTP4Cp+bV8PpvlQeKbO3VwRI/gOupnrOtuI+sFY WIarfteQ6KBneHh7xcap6FHicEbEsjSK7rX9Qks1+PA0DdNp8mqwCz2qw8ooz+wWMZru BnXe2IOcJQjqzL64bS6rsxLy+Bqw7sgWGFz17JukjxlIFTJu1lyxE1LoS470m3dIxI/e /VjMiIHHGCiMrIgQo4AYnlPBVPAhZWLjQPp3O8vs7WEm03EHcPDTrwhyVydMcL4UGlYR ndyyqQ+1fUBxgL4F8MqdurSpIHtJUq03BZpssqQU6P3TGSna159QV4Qg5ndtVntSaZxf QY9w== X-Gm-Message-State: ANhLgQ251ylpn9bOA3kmqlFt/74tulu7YOUueyuKxr2BhiX07Gx4YJlO AZlIZhkcM8ebAkkprwF0Q0sAcg== X-Received: by 2002:adf:f0c5:: with SMTP id x5mr10031231wro.415.1585061410761; Tue, 24 Mar 2020 07:50:10 -0700 (PDT) Received: from chromium.org (77-56-209-237.dclient.hispeed.ch. [77.56.209.237]) by smtp.gmail.com with ESMTPSA id y7sm6619108wrq.54.2020.03.24.07.50.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Mar 2020 07:50:10 -0700 (PDT) From: KP Singh X-Google-Original-From: KP Singh Date: Tue, 24 Mar 2020 15:50:03 +0100 To: Stephen Smalley Cc: linux-kernel@vger.kernel.org, bpf@vger.kernel.org, LSM List , Brendan Jackman , Florent Revest , Alexei Starovoitov , Daniel Borkmann , James Morris , Kees Cook , Paul Turner , Jann Horn , Florent Revest , Brendan Jackman , Greg Kroah-Hartman , Paul Moore Subject: Re: [PATCH bpf-next v5 4/7] bpf: lsm: Implement attach, detach and execution Message-ID: <20200324145003.GA2685@chromium.org> References: <20200323164415.12943-1-kpsingh@chromium.org> <20200323164415.12943-5-kpsingh@chromium.org> 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 24-M?r 10:35, Stephen Smalley wrote: > On Mon, Mar 23, 2020 at 12:46 PM KP Singh wrote: > > > > From: KP Singh > > > > JITed BPF programs are dynamically attached to the LSM hooks > > using BPF trampolines. The trampoline prologue generates code to handle > > conversion of the signature of the hook to the appropriate BPF context. > > > > The allocated trampoline programs are attached to the nop functions > > initialized as LSM hooks. > > > > BPF_PROG_TYPE_LSM programs must have a GPL compatible license and > > and need CAP_SYS_ADMIN (required for loading eBPF programs). > > > > Upon attachment: > > > > * A BPF fexit trampoline is used for LSM hooks with a void return type. > > * A BPF fmod_ret trampoline is used for LSM hooks which return an > > int. The attached programs can override the return value of the > > bpf LSM hook to indicate a MAC Policy decision. > > > > Signed-off-by: KP Singh > > Reviewed-by: Brendan Jackman > > Reviewed-by: Florent Revest > > --- > > > diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c > > index 530d137f7a84..2a8131b640b8 100644 > > --- a/kernel/bpf/bpf_lsm.c > > +++ b/kernel/bpf/bpf_lsm.c > > @@ -9,6 +9,9 @@ > > #include > > #include > > #include > > +#include > > +#include > > +#include > > > > /* For every LSM hook that allows attachment of BPF programs, declare a NOP > > * function where a BPF program can be attached as an fexit trampoline. > > @@ -27,6 +30,32 @@ noinline __weak void bpf_lsm_##NAME(__VA_ARGS__) {} > > #include > > #undef LSM_HOOK > > > > +#define BPF_LSM_SYM_PREFX "bpf_lsm_" > > + > > +int bpf_lsm_verify_prog(struct bpf_verifier_log *vlog, > > + const struct bpf_prog *prog) > > +{ > > + /* Only CAP_MAC_ADMIN users are allowed to make changes to LSM hooks > > + */ > > + if (!capable(CAP_MAC_ADMIN)) > > + return -EPERM; > > I had asked before, and will ask again: please provide an explicit LSM > hook for mediating whether one can make changes to the LSM hooks. > Neither CAP_MAC_ADMIN nor CAP_SYS_ADMIN suffices to check this for SELinux. What do you think about: int security_check_mutable_hooks(void) Do you have any suggestions on the signature of this hook? Does this hook need to be BPF specific? - KP