From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.4 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4F18C3F68F for ; Fri, 17 Jan 2020 22:15:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 777C621D7D for ; Fri, 17 Jan 2020 22:15:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="NkZOrXzL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728851AbgAQWP5 (ORCPT ); Fri, 17 Jan 2020 17:15:57 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:37011 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727022AbgAQWP5 (ORCPT ); Fri, 17 Jan 2020 17:15:57 -0500 Received: by mail-pl1-f195.google.com with SMTP id c23so10409763plz.4 for ; Fri, 17 Jan 2020 14:15:57 -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=YARhjqHfu3XnvFV7m022gWlMRwz6JsfilVyY5Ay7UrY=; b=NkZOrXzLv98pN3E39cEyacMcPnPLQFK9DJqD3IiZVnfNxTXyf6WyyJxn/TLdSoFKSb liWaUbRi6oZHlC+4BpeNt7EXfzMkYZcjfMlqcxqPv7IKK9gwEEW1JTBpopjQXt7QXFgm YU9H9S2KD/uMsUPfA4T2BGx3CkGXZ8MOpAzIc= 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=YARhjqHfu3XnvFV7m022gWlMRwz6JsfilVyY5Ay7UrY=; b=rpGAMD/SImuLWktFTnwohHYLhsIRvouNSdIN7mHRMv7o+k7yDQtWgSBt0mi2lR/K00 p1e960WtKklK6802IH7ORwPTGZUkNRucLnPH1bq1+TEOWeFhj/Ocmt1p1IesKABsXv9Y fYm7XJKh73RCb5y1t9QF8ZoRzJhVLx9CHC0lqE+wuUV1+FKgJs2Za61hGDKWTdVc80e3 +B7+rRZhdSNXSHAAkB8q0+wTms4LLNcp1ESH6ePfA2lWnswJiXxAtjJqIBiMA6TkUEoG jINMuWv0XbFamVNusLMZM9LplY2f2bBveVRq539JVUiv/llNCvIhSwv+C5f5kitoWHUe tQmA== X-Gm-Message-State: APjAAAVUVymPU0hdoqlNZECNuyc+hOYMjlC9afXxcLfLKxOKaBCiBg41 Memz758p+Eb/Zs6Lmx19EhgLkg== X-Google-Smtp-Source: APXvYqxevNzacDfhqVUFU9WP0mcyHbwMOPtg3KBADlZVplAkcfA7QKZqfCvnYsEpqCMea8UV5hwyjA== X-Received: by 2002:a17:90b:3c9:: with SMTP id go9mr8410990pjb.7.1579299356657; Fri, 17 Jan 2020 14:15:56 -0800 (PST) Received: from chromium.org ([165.231.253.166]) by smtp.gmail.com with ESMTPSA id dw10sm8424303pjb.11.2020.01.17.14.15.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2020 14:15:55 -0800 (PST) From: KP Singh X-Google-Original-From: KP Singh Date: Fri, 17 Jan 2020 23:16:03 +0100 To: Andrii Nakryiko 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 , =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= , 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 Subject: Re: [PATCH bpf-next v2 08/10] tools/libbpf: Add support for BPF_PROG_TYPE_LSM Message-ID: <20200117221603.GA25978@chromium.org> References: <20200115171333.28811-1-kpsingh@chromium.org> <20200115171333.28811-9-kpsingh@chromium.org> <20200116124955.GD240584@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: On 16-Jan 11:10, Andrii Nakryiko wrote: > On Thu, Jan 16, 2020 at 4:49 AM KP Singh wrote: > > > > Thanks for the review Andrii! > > > > I will incorporate the fixes in the next revision. > > > > On 15-Jan 13:19, Andrii Nakryiko wrote: > > > On Wed, Jan 15, 2020 at 9:13 AM KP Singh wrote: > > > > > > > > From: KP Singh > > > > > > > > * Add functionality in libbpf to attach eBPF program to LSM hooks > > > > * Lookup the index of the LSM hook in security_hook_heads and pass it in > > > > attr->lsm_hook_index > > > > > > > > Signed-off-by: KP Singh > > > > --- > > > > tools/lib/bpf/bpf.c | 6 +- > > > > tools/lib/bpf/bpf.h | 1 + > > > > tools/lib/bpf/libbpf.c | 143 ++++++++++++++++++++++++++++++++++----- > > > > tools/lib/bpf/libbpf.h | 4 ++ > > > > tools/lib/bpf/libbpf.map | 3 + > > > > 5 files changed, 138 insertions(+), 19 deletions(-) > > > > > > [...] > > > > > > > > +{ > > > > + struct btf *btf = bpf_find_kernel_btf(); > > > > > > ok, it's probably time to do this right. Let's ensure we load kernel > > > BTF just once, keep it inside bpf_object while we need it and then > > > release it after successful load. We are at the point where all the > > > new types of program is loading/releasing kernel BTF for every section > > > and it starts to feel very wasteful. > > > > Sure, will give it a shot in v3. > > thanks! > > [...] > > > > > > > > + if (!strcmp(btf__name_by_offset(btf, m->name_off), name)) > > > > + return j + 1; > > > > > > I looked briefly through kernel-side patch introducing lsm_hook_index, > > > but it didn't seem to explain why this index needs to be (unnaturally) > > > 1-based. So asking here first as I'm looking through libbpf changes? > > > > The lsm_hook_idx is one-based as it makes it easy to validate the > > input. If we make it zero-based it's hard to check if the user > > intended to attach to the LSM hook at index 0 or did not set it. > > Think about providing FDs. 0 is a valid, though rarely > intended/correct value. Yet we don't make all FD arguments > artificially 1-based, right? This extra +1/-1 translation just makes > for more confusing interface, IMO. If user "accidentally" guessed type > signature of very first hook, well, so be it... If not, BPF verifier > will politely refuse. Seems like enough protection. Thanks! I see your point and will update to using the more-conventional 0-based indexing for the next revision. - KP > > > > > We are then up to the verifier to reject the loaded program which > > may or may not match the signature of the hook at lsm_hook_idx = 0. > > > > I will clarify this in the commit log as well. > > > > [...]