Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4163007ybb; Mon, 23 Mar 2020 14:58:58 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsKXUrPHqgVghTiCVRg4ZWoiNyb6/WVwePsQ9ODf+9MDhWlrZdySj8isoM1CFw4hPcX0lXZ X-Received: by 2002:a9d:5607:: with SMTP id e7mr20426132oti.196.1585000738197; Mon, 23 Mar 2020 14:58:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585000738; cv=none; d=google.com; s=arc-20160816; b=tsdCXJ1qqxXRgOwWJGvWouDt+OI6OPI/Ze+DE5xhtGG9TeotnyknIBmAnjRslIYH85 NAckERiXueddHg5olsRbhP1c/bbePM1VjZn7Wz2SiIEgfUK3HsbSacEB90iJfwmn0rAm NKR10lXAt6JQY05HsdKrqoruUPV4Mj5R2C52ZSspKeC0O8LZxl+Da3ZA8MGUQa4e6SIe jvFZgAEfo1GfezHKaepruZx0HBfwjsLi5UQZu4th5bCutCWwqosjgNNll2KTdp7uhj8g c5Xp1qeZsJre0CipxxMRulWiSt9NqePgXulASOSuSBHJRiFczjX6/qKouIPb7Tx4yXgs gUUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:from:references:cc:to:subject:dkim-signature; bh=Zwo8zdOeFtKyfBNkeuV/UBIfJ7cavNPYnorQTSmeIYw=; b=e+n1XDfa7iT6UgxjhwrE7XtLuJrwBwzeZ8FxbjaSQ6OmmJ68t9pNuOg3x47cYBXJLu 4c4s3J30rg1pODaqIFCqfuJN0uEGc7+hBO8euoxTHtYz86PZoiMnM8mgloYOfPQrCqEL 5wC+RJEbeRujCOus3ytNNVbMkK7U8RZhrJd2+eNTjBtmWXMHkZYCT6d7rdEK6lQQL4Sw LD4sUnDCb2pRg8hPdnGlNMTdLp6SA1gE2sVXpJhb2Nkzp3nB78G+5lGIFLbDrXWBTDB5 qj2dmuhEDvh1IktMuXwFAw00DVqwBzDYqmsSsIHKgdwNVxsCI1M8v30Bes0+Se9QzFVx zxXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=gbDbj7vQ; 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 a12si1675681otr.321.2020.03.23.14.58.44; Mon, 23 Mar 2020 14:58:58 -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=@yahoo.com header.s=s2048 header.b=gbDbj7vQ; 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 S1727022AbgCWV60 (ORCPT + 99 others); Mon, 23 Mar 2020 17:58:26 -0400 Received: from sonic309-27.consmr.mail.ne1.yahoo.com ([66.163.184.153]:37964 "EHLO sonic309-27.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726991AbgCWV6Z (ORCPT ); Mon, 23 Mar 2020 17:58:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1585000703; bh=Zwo8zdOeFtKyfBNkeuV/UBIfJ7cavNPYnorQTSmeIYw=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From:Subject; b=gbDbj7vQkCy6J5i/WoaZ9EmqRof/5Hzqg12L1or+MvnkZwqVZ7D91kMA7vosAmtxxZkojn7qKRM576s6C1AokEGIsORjUwqyOJ38VXgfvTCMmMmN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V_BV2 wWnGKSYuQsz73RsI3zrdtWqepDHCWvDPL7TmztpXcaSyAy7.pshcps8rKL2dopJm3xLMFsum7XiY n7hfWZfxcVL9V95SLJYMVllu3RNA68V0lwvrgYE74ijlp6.3MUaIcptKfotEjLaPeqENpXompNgC EV6jt3NVGTG8MRo629SrcC2stUVuwxjlxwQWXVeYGpDzDP10Oz.iORinWW.MjAZDfTQw8yq2mK0O aEHhlAdwEpIdAX7QqEN6mAmNHhG_vCj.orvSLM4g8zWUrcZf_yCoNPU9GSmvurv5MFl7hMExJFdJ sKPf2RGQ3GGXgIpM1m8TEJocWRurBH77XTkdC5z2a77W8Z.YLaN10Lfx58pCiwEwauERdP7yUZXQ _oh5x5OQA9BOJHnRP.7QSVvuBrJII9JtOzeOADpjyFdNpfQECBqxNceDpPwcwvX51vRvwI2O2wp_ lVGcWzcXO5ReHb51YEgcYd6QtEDTF3rVmyGVcojQbI44phuG1b6Ut8zNPcOlwFkqt6FTJokxmx4Q UamU3gp6698fa6cZ1gP2gV3hPAicG8G2P0RfpcW9tpO38VJiojGnQQ2xBVG3ljvjNn285UhLat5n Cb.PgCsFz451p4mHkrOL_CfKyOhE- Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.ne1.yahoo.com with HTTP; Mon, 23 Mar 2020 21:58:23 +0000 Received: by smtp423.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 5f9da4f7c6a75b975e6d43dca24a7324; Mon, 23 Mar 2020 21:58:19 +0000 (UTC) Subject: Re: [PATCH bpf-next v5 5/7] bpf: lsm: Initialize the BPF LSM hooks To: Kees Cook Cc: KP Singh , linux-kernel@vger.kernel.org, Casey Schaufler , linux-security-module@vger.kernel.org, Brendan Jackman , Florent Revest , Alexei Starovoitov , Daniel Borkmann , James Morris , Paul Turner , Jann Horn , Florent Revest , Brendan Jackman , Greg Kroah-Hartman References: <20200323164415.12943-1-kpsingh@chromium.org> <20200323164415.12943-6-kpsingh@chromium.org> <202003231237.F654B379@keescook> <0655d820-4c42-cf9a-23d3-82dc4fdeeceb@schaufler-ca.com> <202003231354.1454ED92EC@keescook> From: Casey Schaufler Autocrypt: addr=casey@schaufler-ca.com; keydata= mQINBFzV9HABEAC/mmv3jeJyF7lR7QhILYg1+PeBLIMZv7KCzBSc/4ZZipoWdmr77Lel/RxQ 1PrNx0UaM5r6Hj9lJmJ9eg4s/TUBSP67mTx+tsZ1RhG78/WFf9aBe8MSXxY5cu7IUwo0J/CG vdSqACKyYPV5eoTJmnMxalu8/oVUHyPnKF3eMGgE0mKOFBUMsb2pLS/enE4QyxhcZ26jeeS6 3BaqDl1aTXGowM5BHyn7s9LEU38x/y2ffdqBjd3au2YOlvZ+XUkzoclSVfSR29bomZVVyhMB h1jTmX4Ac9QjpwsxihT8KNGvOM5CeCjQyWcW/g8LfWTzOVF9lzbx6IfEZDDoDem4+ZiPsAXC SWKBKil3npdbgb8MARPes2DpuhVm8yfkJEQQmuLYv8GPiJbwHQVLZGQAPBZSAc7IidD2zbf9 XAw1/SJGe1poxOMfuSBsfKxv9ba2i8hUR+PH7gWwkMQaQ97B1yXYxVEkpG8Y4MfE5Vd3bjJU kvQ/tOBUCw5zwyIRC9+7zr1zYi/3hk+OG8OryZ5kpILBNCo+aePeAJ44znrySarUqS69tuXd a3lMPHUJJpUpIwSKQ5UuYYkWlWwENEWSefpakFAIwY4YIBkzoJ/t+XJHE1HTaJnRk6SWpeDf CreF3+LouP4njyeLEjVIMzaEpwROsw++BX5i5vTXJB+4UApTAQARAQABtChDYXNleSBTY2hh dWZsZXIgPGNhc2V5QHNjaGF1Zmxlci1jYS5jb20+iQJUBBMBCAA+FiEEC+9tH1YyUwIQzUIe OKUVfIxDyBEFAlzV9HACGwMFCRLMAwAFCwkIBwIGFQoJCAsCBBYCAwECHgECF4AACgkQOKUV fIxDyBG6ag/6AiRl8yof47YOEVHlrmewbpnlBTaYNfJ5cZflNRKRX6t4bp1B2YV1whlDTpiL vNOwFkh+ZE0eI5M4x8G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WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <202003231354.1454ED92EC@keescook> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-Language: en-US X-Mailer: WebService/1.1.15518 hermes Apache-HttpAsyncClient/4.1.4 (Java/1.8.0_242) Content-Length: 3121 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/23/2020 2:44 PM, Kees Cook wrote: > On Mon, Mar 23, 2020 at 01:47:29PM -0700, Casey Schaufler wrote: >> On 3/23/2020 12:44 PM, Kees Cook wrote: >>> On Mon, Mar 23, 2020 at 05:44:13PM +0100, KP Singh wrote: >>>> +/* Some LSM hooks do not have 0 as their default return values. Ove= rride the >>>> + * __weak definitons generated by default for these hooks >>> If you wanted to avoid this, couldn't you make the default return val= ue >>> part of lsm_hooks.h? >>> >>> e.g.: >>> >>> LSM_HOOK(int, -EOPNOTSUPP, inode_getsecurity, struct inode *inode, >>> const char *name, void **buffer, bool alloc) >> If you're going to do that you'll have to keep lsm_hooks.h and securit= y.c >> default values in sync somehow. Note that the four functions you've ca= lled >> out won't be using call_int_hook() after the next round of stacking. I= 'm not >> nixing the idea, I just don't want the default return for the security= _ >> functions defined in two places. > Yeah, I actually went looking for this after I sent the email, realizin= g > that the defaults were also used in security.c. I've been pondering how= > to keep them from being duplicated. I'm working on some ideas. > > The four are: > > inode_getsecurity > inode_setsecurity > task_prctl > xfrm_state_pol_flow_match > > None of these are already just calling call_int_hook(), but I assume > they'll need further tweaks in the coming stacking. > > To leave things as open-code-able as possible while still benefiting > from the macro consolidation, how about something like this: > > lsm_hook_names.h: > > LSM_HOOK(int, -EOPNOTSUPP, inode_getsecurity, > struct inode *inode, const char *name, void **buffer, bool alloc) > > ... > > security.c: > > #define LSM_RET_DEFAULT_void(DEFAULT, NAME) /* */ > #define LSM_RET_DEFAULT_int(DEFAULT, NAME) > static const int NAME#_default =3D (DEFAULT); > > #define LSM_HOOK(RET, DEFAULT, NAME, ...) \ > LSM_RET_DEFAULT_#RET(DEFAULT, NAME) > #include > #undef LSM_HOOK > ... > > Then -EOPNOTSUPP is available as "inode_getsecurity_default": > > int security_inode_getsecurity(struct inode *inode, const char *name, > void **buffer, bool alloc) > { > struct security_hook_list *hp; > int rc; > > if (unlikely(IS_PRIVATE(inode))) > return inode_getsecurity_default; > /* > * Only one module will provide an attribute with a given name.= > */ > hlist_for_each_entry(hp, &security_hook_heads.inode_getsecurity= , list) { > rc =3D hp->hook.inode_getsecurity(inode, name, buffer, = alloc); > if (rc !=3D inode_getsecurity_default) > return rc; > } > return inode_getsecurity_default; > } > > > On the other hand, it's only 4 non-default return codes, so maybe the > sync burden isn't very high? That's not too terrible, I suppose. What would you be thinking for the calls that do use call_int_hook()? rc =3D call_int_hook(something, something_default, goodnesses); or embedded in the macro: rc =3D call_int_hook(something, goodnesses);