Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp7237101ybl; Mon, 23 Dec 2019 21:51:48 -0800 (PST) X-Google-Smtp-Source: APXvYqwwsOJIny7vVegIyIb/KadKC3MTuG80S8ojYRsrEJCItPHoMkfWFkIJCZqP4ija2c7nhhQp X-Received: by 2002:a9d:6e82:: with SMTP id a2mr35815489otr.336.1577166708063; Mon, 23 Dec 2019 21:51:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577166708; cv=none; d=google.com; s=arc-20160816; b=cLIIyVHJk3oUWA9vhBCtJfKC6A7alNSvOXH48CdSBuS2pCt22jw1Mblf99dUYtjug5 KnHNrQDj204nPjxFTlWYAMMbZaCcShzfLRGkgXznc6g1bap0HC7HaLzF2zQ7WA77wwpE dTJtz7frvfLIvfRG3rDmJXVY6ihxtYJoqOIhRgkxAkF0Vrb6TJpd+5T3QPSqCUPXQzGp fKahBdDzsTOKlA5q1KD9qFOlsjFsX2FflI7dmsytAlvZNFXQIfLydnTXcvhuFxmPcDHW MKCN3v4kw5L+VT3d3Rn946TyAUWxd4oBjemLVT20sWFQvu6H9NRv3GvQz/KOUgkAChKg zANQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=chyirdOESrcyZYls0O4S3CM7+3ie23NclpnHj9Q8TZ8=; b=l4iz1SoGASIDqPJWidmQfXRIkA538s3ZMyGd5EK0DAHftIGX9nHjhuZ43U7MedxvHo 9MUjA3HJs7B/6hSMhZ2p1UPC4MKn/Wh4AKvzy7rp5gnePFm3GIyAl9ACB7xKY21cMSlJ mq+9VXgYx23KIMnI/UqdY5vXgEhpQouELgBWyrrxMsoO6fXy1ML516VrOyfWQOiB0SEh Qd4PljPYvg4BY5TyT3F9RDCbvZiOgEHPW9DHQFYLRvQfyH2YF5V79g50FZUB1Ss64UBH 5BpUwiwoFKzEuFhHgBrjdhU3XBzqO9VSIpwpgkh3cFTsafHUE727dsCS9fTa4pLgDy+y wGbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=QTatrIDi; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o13si12160324otp.27.2019.12.23.21.51.25; Mon, 23 Dec 2019 21:51:48 -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=@gmail.com header.s=20161025 header.b=QTatrIDi; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726088AbfLXFs1 (ORCPT + 99 others); Tue, 24 Dec 2019 00:48:27 -0500 Received: from mail-qv1-f67.google.com ([209.85.219.67]:35645 "EHLO mail-qv1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725934AbfLXFs1 (ORCPT ); Tue, 24 Dec 2019 00:48:27 -0500 Received: by mail-qv1-f67.google.com with SMTP id u10so7066370qvi.2; Mon, 23 Dec 2019 21:48:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=chyirdOESrcyZYls0O4S3CM7+3ie23NclpnHj9Q8TZ8=; b=QTatrIDibvsfq4PIGOcDpegqvGeyTx/uyaEzHEx87OT9YjFBlXGYfYtaSXgB63vHsr P7WkavE0s+JmgT+ohyprAJLIXh1/A4tDK7Z58DCZ1Oi/r0qlHzB+5oSEOCZLspyrj3tb w7PZTpQxl+XtGtUjxC3nemQ8Oq+U5fql2TvIkoMBtU5HpKmfH65tsV8rRWmSa5fEst0A rmM2uGFabc6Cm23pE79n7ePT3/LdX2tfKcSwtBJ7z/J2pa8meORoVjuiBGmEc4wlTSUn xLDlsapm3n8DOGqBAGIf1Ksjw0VTGJytiNfJzq5vlSL156SFmVvQvkCNY1O4i9Ch7AMG V9rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=chyirdOESrcyZYls0O4S3CM7+3ie23NclpnHj9Q8TZ8=; b=MTPEIPuREeRkyKq+IMr66NfRBYzHM3LeQ9dl8EtVBJOYfLI96TMcoLwSSj22/o4Ncs W3Y+M1BEXLMukkgVRXcNlwMZq6Er3QJ5f9HxgXrsP9cT8MFNog4VE3IkyTbIT03CTeur aVhe3HXdib+P8GUZjdY4gGX2uDz+flXgJmJU+azltsAGLBcM9pH1vjPChG3ytVyzkuq5 EVw6WMJiKoT6ktAdP4psBrEg4o5VHjijawTJorQP6xc8fcMyahzqsCF+jOVxL2t5sx+N cnTgu7bJWu9Ebf1uY1xZnlrvZbrcp3vs10zMhhCDuUpNPsixGRHtxdgVLRyk6sy01EIC pOvg== X-Gm-Message-State: APjAAAX7kUJS6Q4pZTQ0xo2GvLXvjTZg49X2WZyN16PLNPf2Em5sfsrO QEN453FS3mSE6gZoQL1NUupOxZIGWN4mNQHZofQ= X-Received: by 2002:ad4:4e34:: with SMTP id dm20mr27799530qvb.163.1577166505897; Mon, 23 Dec 2019 21:48:25 -0800 (PST) MIME-Version: 1.0 References: <20191220154208.15895-1-kpsingh@chromium.org> <20191220154208.15895-8-kpsingh@chromium.org> In-Reply-To: <20191220154208.15895-8-kpsingh@chromium.org> From: Andrii Nakryiko Date: Mon, 23 Dec 2019 21:48:14 -0800 Message-ID: Subject: Re: [PATCH bpf-next v1 07/13] bpf: lsm: Implement attach, detach and execution. To: KP Singh Cc: open list , bpf , linux-security-module@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , James Morris , Kees Cook , Thomas Garnier , Michael Halcrow , Paul Turner , Brendan Gregg , Jann Horn , Matthew Garrett , Christian Brauner , =?UTF-8?B?TWlja2HDq2wgU2FsYcO8bg==?= , Florent Revest , Brendan Jackman , Martin KaFai Lau , Song Liu , Yonghong Song , "Serge E. Hallyn" , Mauro Carvalho Chehab , "David S. Miller" , Greg Kroah-Hartman , Nicolas Ferre , Stanislav Fomichev , Quentin Monnet , Andrey Ignatov , Joe Stringer Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 20, 2019 at 7:43 AM KP Singh wrote: > > From: KP Singh > > A user space program can attach an eBPF program by: > > hook_fd = open("/sys/kernel/security/bpf/bprm_check_security", > O_RDWR|O_CLOEXEC) > prog_fd = bpf(BPF_PROG_LOAD, ...) > bpf(BPF_PROG_ATTACH, hook_fd, prog_fd) > > The following permissions are required to attach a program to a hook: > > - CAP_SYS_ADMIN to load eBPF programs > - CAP_MAC_ADMIN (to update the policy of an LSM) > - The securityfs file being a valid hook and writable (O_RDWR) > > When such an attach call is received, the attachment logic looks up the > dentry and appends the program to the bpf_prog_array. > > The BPF programs are stored in a bpf_prog_array and writes to the array > are guarded by a mutex. The eBPF programs are executed as a part of the > LSM hook they are attached to. If any of the eBPF programs return > an error (-ENOPERM) the action represented by the hook is denied. > > Signed-off-by: KP Singh > --- Acked-by: Andrii Nakryiko > MAINTAINERS | 1 + > include/linux/bpf_lsm.h | 13 ++++ > kernel/bpf/syscall.c | 5 +- > security/bpf/lsm_fs.c | 19 +++++- > security/bpf/ops.c | 134 ++++++++++++++++++++++++++++++++++++++++ > 5 files changed, 169 insertions(+), 3 deletions(-) > [...]