Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5447887ybv; Tue, 11 Feb 2020 16:09:45 -0800 (PST) X-Google-Smtp-Source: APXvYqyzFAG/zu9r5C6nBVKEzX8SxQHnJYm3W35k9D3TmyZub/iln2vhsEAn0bf5LoqaffiPhPd7 X-Received: by 2002:a05:6808:618:: with SMTP id y24mr4353147oih.86.1581466185299; Tue, 11 Feb 2020 16:09:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581466185; cv=none; d=google.com; s=arc-20160816; b=IYjgzqQa1k9PK6OfJ/W1tMPPLlXqzJIo4FNL1WX3BwR/rrSQprXmRfnDe9F2PlWWvo z4i3LPftXakETl57UVKLrEmJOjZpqnhmQRH4mRcig2FPbWR8NNsOvwgiuWKbF2soa7xs 8TLkUdvxVhLWC8bC6hfzUVUVhQ2+P2A7Z1KKyBTlEHUZ7zXuzgViy/dBDz4YDRRkKDIP gBB8p+kqDAVK8CnhEls9kyrZWzC4yxU4dsdzJ61GaYrHpnfUEUulCx2eUL512521DzjS GjL/q2MNnv3OF9wm0LkVyRXqsukuhoRSIKvcxLl1G5EZoi1uBoLjVfPWUEDDD0ur3YOw b4Ng== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=g+7kC2yJfXqexoOWqV3AaDMjToHPoSZ2CdhkLHzMmd8=; b=yL+mOJVC8LN/8jSggNvwXiptpV+GKEl8+spDH5ju7EbMki5smfxXrrGZp2bzfm3oM/ u/x2S4bqW/GAjaxY96HgWfaYag4OXie/FNnPCZGi+8y5DCjjDj3gPlO9bJ1Y4yfgZgO2 GzmvaF1cFp3jOtf3Fo3sD8LApBQgir3p4hCkUHm3e3wz8RSnpbwITykNXCKor5L2Dr/T KDBK2zRQUkJx3xhUOrPadlRsmwyDm6TEFo6XLQiQR9nRSCULSK6szZMrwtXsWbYQRZBp ZV2bxikcnwyWt+laaw1EWO7p5o7c75ueSENCdTqMR61yTRG2zVWC8rb1KtNjjqWgDTwq 5SpA== 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 t25si2529319oic.183.2020.02.11.16.09.30; Tue, 11 Feb 2020 16:09:45 -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 S1728022AbgBLAJQ (ORCPT + 99 others); Tue, 11 Feb 2020 19:09:16 -0500 Received: from www62.your-server.de ([213.133.104.62]:39780 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727979AbgBLAJQ (ORCPT ); Tue, 11 Feb 2020 19:09:16 -0500 Received: from sslproxy06.your-server.de ([78.46.172.3]) by www62.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1j1faW-0007DH-Se; Wed, 12 Feb 2020 01:09:09 +0100 Received: from [85.7.42.192] (helo=pc-9.home) by sslproxy06.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j1faW-000ETx-4j; Wed, 12 Feb 2020 01:09:08 +0100 Subject: Re: BPF LSM and fexit [was: [PATCH bpf-next v3 04/10] bpf: lsm: Add mutable hooks list for the BPF LSM] To: Alexei Starovoitov , Jann Horn Cc: KP Singh , kernel list , bpf , linux-security-module , Brendan Jackman , Florent Revest , Thomas Garnier , Alexei Starovoitov , James Morris , Kees Cook , Thomas Garnier , Michael Halcrow , Paul Turner , Brendan Gregg , Matthew Garrett , Christian Brauner , =?UTF-8?Q?Micka=c3=abl_Sala=c3=bcn?= , Florent Revest , Brendan Jackman , "Serge E. Hallyn" , Mauro Carvalho Chehab , "David S. Miller" , Greg Kroah-Hartman , Kernel Team References: <20200123152440.28956-1-kpsingh@chromium.org> <20200123152440.28956-5-kpsingh@chromium.org> <20200211031208.e6osrcathampoog7@ast-mbp> <20200211124334.GA96694@google.com> <20200211175825.szxaqaepqfbd2wmg@ast-mbp> <20200211190943.sysdbz2zuz5666nq@ast-mbp> <20200211201039.om6xqoscfle7bguz@ast-mbp> <20200211213819.j4ltrjjkuywihpnv@ast-mbp> From: Daniel Borkmann Message-ID: <1cd10710-a81b-8f9b-696d-aa40b0a67225@iogearbox.net> Date: Wed, 12 Feb 2020 01:09:07 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.102.1/25720/Mon Feb 10 12:53:41 2020) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/12/20 12:26 AM, Alexei Starovoitov wrote: > On Tue, Feb 11, 2020 at 1:38 PM Alexei Starovoitov > wrote: >> >> On Tue, Feb 11, 2020 at 09:33:49PM +0100, Jann Horn wrote: >>>> >>>> Got it. Then let's whitelist them ? >>>> All error injection points are marked with ALLOW_ERROR_INJECTION(). >>>> We can do something similar here, but let's do it via BTF and avoid >>>> abusing yet another elf section for this mark. >>>> I think BTF_TYPE_EMIT() should work. Just need to pick explicit enough >>>> name and extensive comment about what is going on. >>> >>> Sounds reasonable to me. :) >> >> awesome :) > > Looks like the kernel already provides this whitelisting. > $ bpftool btf dump file /sys/kernel/btf/vmlinux |grep FUNC|grep '\ gives the list of all LSM hooks that lsm-bpf will be able to attach to. > There are two exceptions there security_add_hooks() and security_init(). > Both are '__init'. Too late for lsm-bpf to touch. > So filtering BTF funcs by 'security_' prefix will be enough. > It should be documented though. > The number of attachable funcs depends on kconfig which is > a nice property and further strengthen the point that > lsm-bpf is very much kernel specific. > We probably should blacklist security_bpf*() hooks though. One thing that is not quite clear to me wrt the fexit approach; assuming we'd whitelist something like security_inode_link(): int security_inode_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_dentry) { if (unlikely(IS_PRIVATE(d_backing_inode(old_dentry)))) return 0; return call_int_hook(inode_link, 0, old_dentry, dir, new_dentry); } Would this then mean the BPF prog needs to reimplement above check by probing old_dentry->d_inode to later ensure its verdict stays 0 there too, or that such extra code is to be moved to call-sites instead? If former, what about more complex logic? Another approach could be to have a special nop inside call_int_hook() macro which would then get patched to avoid these situations. Somewhat similar like static keys where it could be defined anywhere in text but with updating of call_int_hook()'s RC for the verdict. Thanks, Daniel