Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2036634ybb; Thu, 26 Mar 2020 20:13:42 -0700 (PDT) X-Google-Smtp-Source: ADFU+vt1mFWux36iyP9BBh3i+zDswAxRtY76c9XY+1+gz9ZyHUjSR0oiontkmLIeJHGiikcKJbWA X-Received: by 2002:a9d:77d1:: with SMTP id w17mr8749987otl.44.1585278822317; Thu, 26 Mar 2020 20:13:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585278822; cv=none; d=google.com; s=arc-20160816; b=JV9igoDs+E47XH2YTFiAghirwRW2qkBeh2JqHdBPP9erjxag1JUA5SeflYkMts15qh 4A1kNMQcnQS+By9VQvqnGaCBYXjNzA8J/TYAjKhKxQPs0qXUjYSZ6hHoa8ustnr24gXe ixYLAyUBPT9mwWiIcKqVE/7dAcZ5wW8zWl0FQKXkQcLQu/bJsi4Bg554SqdbMWuGyrJf zDnhT9HiivxZY+dQm4v1wCr8DiCmkjjTgqkn4y9v8km2IcDqvFshXbYrATIaAlbOWjIR 6on/7f0G4SZiuICemTcaMEIU5UFMTwZXFBJQf+IRFgbt9vQipyl9e5GfU7pgWiYthODT phcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=/FAiupbq7ijBqqhfCHQ+LKr/8inE0CiEthvKJQ+FYbU=; b=ocyUAe66k7iO2/rXGom9rUNS3UwBkFkJxwARdey/UIjhy6Y9aIYuqkBWF4job9R5nX Z4LzuGC/3GPLwadMH5Ol+FKKyxUKKRqhk8T/lVjjr7nhCAVj+CYbCLf45zcbaCwvpWny K8+4N5v5JYM7Bu290uK18YRkat9WdS1V2UKleGp5buOfzT859etc5VnFuqoOSWsg8voo 8EIvw1LParKEdYqtM3thV9TcCcidl85ocX2ZB+eedMiBfZaNe+W10UQkVtCJWdCR/1SJ HH1vjs74HvzEGEL1ATStc2era/Ew9f5wdUYqppmSFS61nRsRh6HAhDLWpw6pBPkCHHac 3D5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=IFwqDYEF; 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 i21si1888740otc.183.2020.03.26.20.13.29; Thu, 26 Mar 2020 20:13:42 -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=@gmail.com header.s=20161025 header.b=IFwqDYEF; 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 S1727733AbgC0DNC (ORCPT + 99 others); Thu, 26 Mar 2020 23:13:02 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:44451 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727509AbgC0DNC (ORCPT ); Thu, 26 Mar 2020 23:13:02 -0400 Received: by mail-pg1-f193.google.com with SMTP id 142so3907806pgf.11; Thu, 26 Mar 2020 20:13:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=/FAiupbq7ijBqqhfCHQ+LKr/8inE0CiEthvKJQ+FYbU=; b=IFwqDYEFF2JE0Ho1LEZF7TRM28eNrRIXyMFmHo87Zsulf9Hpa6gYX7X0GzCDlnpzeP wCGDpPPXXkdb56RFBp3Fsf2+nlePxViNgwPpSF7Ag5LKo9dsAKKbWa3Wu2R9dBc/oZLY QcNRhcPYRxuYfCvB0+Zng+VDeLtWxj0if8iwAv3jAWGPR7/3klUajWesE/2snH+6OU2F BadX/emU+WznC/UBetWnCWLMQUpJXLIFYb2Mr1uLmdUNxj0fcplTgRMYDY5qwSJZ/P9h mdY3kqQ88iC7PjlQdO275SvUMY3Dv8rJj+LeIC+9wynVn50FxURecaMxqjKXIqEsKhvC g+vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=/FAiupbq7ijBqqhfCHQ+LKr/8inE0CiEthvKJQ+FYbU=; b=ucs5KicKfzekMxfFB28RfOzcnL0Z3cHghMnsc6B05Y7hBEqLVH5/mcV+bPSDdnrlRK soDn+8A6XLMp2AVeWDxE0+YGXf/0z3eotDSzy1CB4SGtJ64K7wXoOJPDUEvTdpVWxs+8 YObF0jF15o1UmTJ7xlHiOmShey66Po+mVFU+Qy4BECCbB4xX+WMtRP84RxN0+dWts17M smjnycm2AtjItEg430H1Oa13fBYoOYfzi/kSTFzVxASZ9F8PcZQ+wCdua/GPRVhc6htD kIsHtFsxbK9+03ZFhquaEk3MvZDDZd5MigzpoYY1IYtsY0E/EhYuaF60hgj/Iu3nkjsF 000w== X-Gm-Message-State: ANhLgQ2xfMLGgzJye3BAFZztpLjKqwKEXCusJGMLeMZCuyoT1DPFv+dF yr5nnRB5dY0hZMpTu7Eelp0= X-Received: by 2002:a63:1053:: with SMTP id 19mr11248314pgq.60.1585278780602; Thu, 26 Mar 2020 20:13:00 -0700 (PDT) Received: from ast-mbp ([2620:10d:c090:400::5:f1d9]) by smtp.gmail.com with ESMTPSA id w205sm2866343pfc.75.2020.03.26.20.12.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 20:12:59 -0700 (PDT) Date: Thu, 26 Mar 2020 20:12:56 -0700 From: Alexei Starovoitov To: KP Singh Cc: linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-security-module@vger.kernel.org, Brendan Jackman , Florent Revest , Alexei Starovoitov , Daniel Borkmann , James Morris , Kees Cook , Paul Turner , Jann Horn , Florent Revest , Brendan Jackman , Greg Kroah-Hartman Subject: Re: [PATCH bpf-next v7 4/8] bpf: lsm: Implement attach, detach and execution Message-ID: <20200327031256.vhk2luomxgex3ui4@ast-mbp> References: <20200326142823.26277-1-kpsingh@chromium.org> <20200326142823.26277-5-kpsingh@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200326142823.26277-5-kpsingh@chromium.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 26, 2020 at 03:28:19PM +0100, KP Singh wrote: > > if (arg == nr_args) { > - if (prog->expected_attach_type == BPF_TRACE_FEXIT) { > + /* BPF_LSM_MAC programs only have int and void functions they > + * can be attached to. When they are attached to a void function > + * they result in the creation of an FEXIT trampoline and when > + * to a function that returns an int, a MODIFY_RETURN > + * trampoline. > + */ > + if (prog->expected_attach_type == BPF_TRACE_FEXIT || > + prog->expected_attach_type == BPF_LSM_MAC) { > if (!t) > return true; > t = btf_type_by_id(btf, t->type); Could you add a comment here that though BPF_MODIFY_RETURN-like check if (ret_type != 'int') return -EINVAL; is _not_ done here. It is still safe, since LSM hooks have only void and int return types. > + case BPF_LSM_MAC: > + if (!prog->aux->attach_func_proto->type) > + /* The function returns void, we cannot modify its > + * return value. > + */ > + return BPF_TRAMP_FEXIT; > + else > + return BPF_TRAMP_MODIFY_RETURN; I was thinking whether it would help performance significantly enough if we add a flavor of BPF_TRAMP_FEXIT that doesn't have BPF_TRAMP_F_CALL_ORIG. That will save the cost of nop call, but I guess indirect call due to lsm infra is slow enough, so this extra few cycles won't be noticeable. So I'm fine with it as-is. When lsm hooks will get rid of indirect call we can optimize it further.